1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/AlgFactory.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include "GaudiKernel/IDataProviderSvc.h"
6#include "GaudiKernel/PropertyMgr.h"
7#include "GaudiKernel/ITHistSvc.h"
17#include "GaudiKernel/NTuple.h"
18#include "GaudiKernel/Bootstrap.h"
19#include "CLHEP/Vector/ThreeVector.h"
20#include "CLHEP/Vector/LorentzVector.h"
21#include "CLHEP/Vector/TwoVector.h"
22using CLHEP::Hep3Vector;
23using CLHEP::Hep2Vector;
24using CLHEP::HepLorentzVector;
25#include "CLHEP/Geometry/Point3D.h"
29const double xmass[5] = {0.000511, 0.105658, 0.139570,0.493677, 0.938272};
30const double velc = 299.792458;
31typedef std::vector<int>
Vint;
32typedef std::vector<HepLorentzVector>
Vp4;
37const double pai=3.1415926;
39DECLARE_COMPONENT(
DiGam)
41 Algorithm(name, pSvcLocator) {
42 declareProperty(
"jpsiCrossSection",jpsiCrossSection=249.7);
43 declareProperty(
"jpsiMCEff",jpsiMCEff=0.07145);
44 declareProperty(
"jpsiMCEffBoost",jpsiMCEffBoost=0.07099);
46 declareProperty(
"psi2sCrossSection",psi2sCrossSection=180.8);
47 declareProperty(
"psi2sMCEff",psi2sMCEff=0.07159);
48 declareProperty(
"psi2sMCEffBoost",psi2sMCEffBoost=0.07123);
50 declareProperty(
"psi3770CrossSection",psi3770CrossSection=173.4);
51 declareProperty(
"psi3770MCEff",psi3770MCEff=0.071725);
52 declareProperty(
"psi3770MCEffBoost",psi3770MCEffBoost=0.0713125);
54 declareProperty(
"CrossSection",CrossSection);
55 declareProperty(
"MCEff",MCEff);
56 declareProperty(
"MCEffBoost",MCEffBoost);
58 declareProperty(
"boostPhimin", boostPhimin=2.5);
59 declareProperty(
"boostPhimax",boostPhimax=5);
60 declareProperty(
"boostMinEmin",boostMinEmin);
61 declareProperty(
"boostMinEmax",boostMinEmax);
63 declareProperty(
"RunModel",RunModel=2000);
64 declareProperty(
"dPhiMin",dPhiMin=-7);
65 declareProperty(
"dPhiMax",dPhiMax=5);
66 declareProperty(
"dPhiMinSig",dPhiMinSig=-4);
67 declareProperty(
"dPhiMaxSig",dPhiMaxSig=2);
69 declareProperty(
"flag",
flag=
true);
70 declareProperty(
"E_cms",E_cms);
74 MsgStream log(
msgSvc(), name());
75 log << MSG::INFO <<
"in initialize()" << endmsg;
78 CrossSection=jpsiCrossSection;
80 MCEffBoost=jpsiMCEffBoost;
87 CrossSection=psi2sCrossSection;
89 MCEffBoost=psi2sMCEffBoost;
96 CrossSection=psi3770CrossSection;
98 MCEffBoost=psi3770MCEffBoost;
109 StatusCode ssc=service(
"THistSvc", m_thsvc);
110 if(ssc.isFailure()) {
111 log << MSG::FATAL <<
"DiGamAlg:Couldn't get THistSvc" << endreq;
114 h_lum=
new TH1F(
"lum",
"lum",4,0.5,4.5);
116 StatusCode scBeamEnergy=service(
"BeamEnergySvc", m_BeamEnergySvc);
118 if( scBeamEnergy.isFailure() ){
119 log << MSG::FATAL <<
"can not use BeamEnergySvc" << endreq;
125 NTuplePtr nt2(
ntupleSvc(),
"DQAFILE/zhsDiGam");
128 m_tuple2=
ntupleSvc()->book(
"DQAFILE/zhsDiGam",CLID_ColumnWiseTuple,
"ks N-Tuple example");
130 status=m_tuple2->addItem(
"ETol",m_tot);
131 status=m_tuple2->addItem(
"maxE",m_maxE);
132 status=m_tuple2->addItem(
"minE",m_minE);
133 status=m_tuple2->addItem(
"maxTheta",m_maxTheta);
134 status=m_tuple2->addItem(
"minTheta",m_minTheta);
135 status=m_tuple2->addItem(
"maxPhi",m_maxPhi);
136 status=m_tuple2->addItem(
"minPhi",m_minPhi);
137 status=m_tuple2->addItem(
"delTheta",m_delTheta);
138 status=m_tuple2->addItem(
"delPhi",m_delPhi);
139 status=m_tuple2->addItem(
"angle",m_angle);
140 status=m_tuple2->addItem(
"boostAngle",m_boostAngle);
141 status=m_tuple2->addItem(
"boostMaxE",m_boostMaxE);
142 status=m_tuple2->addItem(
"boostMinE",m_boostMinE);
143 status=m_tuple2->addItem(
"boostDelPhi",m_boostDelPhi);
144 status=m_tuple2->addItem(
"boostDelTheta",m_boostDelTheta);
145 status=m_tuple2->addItem(
"boostM",m_boostM);
146 status=m_tuple2->addItem(
"boostIM",m_boostIM);
147 status=m_tuple2->addItem(
"m",m_m);
148 status=m_tuple2->addItem(
"IM",m_IM);
150 status=m_tuple2->addItem (
"run",m_run );
151 status=m_tuple2->addItem (
"rec",m_rec );
152 status=m_tuple2->addItem(
"indexmc", m_idxmc, 0, 100);
153 status=m_tuple2->addIndexedItem(
"pdgid", m_idxmc, m_pdgid);
154 status=m_tuple2->addIndexedItem(
"motheridx", m_idxmc, m_motheridx);
158 log<<MSG::FATAL<<
"Cannot book N-tuple:"<<long(m_tuple2)<<endmsg;
159 return StatusCode::FAILURE;
163 return StatusCode::SUCCESS;
167 MsgStream log(
msgSvc(), name());
168 log << MSG::INFO <<
"in execute()" << endreq;
170 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
171 runNo=eventHeader->runNumber();
172 int event=eventHeader->eventNumber();
173 log<<MSG::INFO<<
"run,evtnum="<<runNo<<
","<<
event<<endreq;
174 m_run = eventHeader->runNumber();
175 m_rec = eventHeader->eventNumber();
180 log << MSG::DEBUG <<
"setting parameter" << endreq;
183 if ( ! m_BeamEnergySvc->
isRunValid() )
return StatusCode::FAILURE;
184 E_cms = 2*m_BeamEnergySvc->
getbeamE();
185 log << MSG::DEBUG <<
"cms energy is " << E_cms << endreq;
198 log<<MSG::INFO<<
"ncharg,nneu,tottks="
199 <<evtRecEvent->totalCharged()<<
","
200 <<evtRecEvent->totalNeutral()<<
","
201 <<evtRecEvent->totalTracks()<<endreq;
203 std::vector<int> iGam;
206 for(
int i=evtRecEvent->totalCharged();i< evtRecEvent->totalTracks();i++){
208 if(!(*itTrk)->isEmcShowerValid())
continue;
210 if(emcTrk->
energy()<0.6)
continue;
211 if(fabs(
cos(emcTrk->
theta()))>0.83)
continue;
212 iGam.push_back((*itTrk)->trackId());
214 if(iGam.size()<2)
return StatusCode::SUCCESS;
220 for(
int i=0;i<iGam.size();i++){
224 if(emcTrk->
energy()>energy1){
230 else if(emcTrk->
energy()>energy2){
235 if(gam1==-9999 || gam2==-9999)
return StatusCode::SUCCESS;
237 m_tot=energy1+energy2;
238 RecEmcShower* maxEmc=(*(evtRecTrkCol->begin()+gam1))->emcShower();
239 RecEmcShower* minEmc=(*(evtRecTrkCol->begin()+gam2))->emcShower();
242 m_maxTheta=maxEmc->
theta();
243 m_minTheta=minEmc->
theta();
244 m_maxPhi=maxEmc->
phi();
245 m_minPhi=minEmc->
phi();
246 m_delPhi=(fabs(m_maxPhi-m_minPhi)-
pai)*180./
pai;
247 m_delTheta=(fabs(m_maxTheta+m_minTheta)-
pai)*180./
pai;
250 max.setPx(m_maxE*
sin(m_maxTheta)*
cos(m_maxPhi));
251 max.setPy(m_maxE*
sin(m_maxTheta)*
sin(m_maxPhi));
252 max.setPz(m_maxE*
cos(m_maxTheta));
254 min.setPx(m_minE*
sin(m_minTheta)*
cos(m_minPhi));
255 min.setPy(m_minE*
sin(m_minTheta)*
sin(m_minPhi));
256 min.setPz(m_minE*
cos(m_minTheta));
260 m_IM=
max.invariantMass(
min);
262 if(m_minE>=boostMinEmin && m_delPhi>dPhiMin && m_delPhi<dPhiMax && m_minE<=boostMinEmax)tot++;
263 if(m_minE>=boostMinEmin && m_delPhi>dPhiMinSig && m_delPhi<dPhiMaxSig && m_minE<=boostMinEmax)signal++;
267 HepLorentzVector boost1=
max.boost(-0.011,0,0);
268 HepLorentzVector boost2=
min.boost(-0.011,0,0);
269 m_boostAngle=boost1.angle(boost2.vect())*180./
pai;
270 m_boostMaxE=boost1.e();
271 m_boostMinE=boost2.e();
272 m_boostDelPhi=(fabs(boost1.phi()-boost2.phi())-
pai)*180./
pai;
273 m_boostDelTheta=(fabs(boost1.theta()+boost2.theta())-
pai)*180./
pai;
274 m_boostM=(boost1+boost2).m();
275 m_boostIM=boost1.invariantMass(boost2);
276 log << MSG::INFO <<
"num Good Photon " << iGam.size()<<endreq;
277 if(m_boostMinE>=boostMinEmin && m_boostMinE<=boostMinEmax && fabs(m_boostDelPhi)<=boostPhimin)boost_signal++;
278 if(m_boostMinE>=boostMinEmin && m_boostMinE<=boostMinEmax && fabs(m_boostDelPhi)<=boostPhimax)boost_tot++;
280 if (eventHeader->runNumber()<0)
282 SmartDataPtr<Event::McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
283 int m_numParticle = 0;
287 return StatusCode::FAILURE;
291 bool jpsipDecay =
false;
293 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
294 for (; iter_mc != mcParticleCol->end(); iter_mc++)
296 if ((*iter_mc)->primaryParticle())
continue;
297 if (!(*iter_mc)->decayFromGenerator())
continue;
299 if ((*iter_mc)->particleProperty()==443)
302 rootIndex = (*iter_mc)->trackIndex();
304 if (!jpsipDecay)
continue;
305 int mcidx = ((*iter_mc)->mother()).trackIndex() - rootIndex;
306 int pdgid = (*iter_mc)->particleProperty();
307 m_pdgid[m_numParticle] = pdgid;
308 m_motheridx[m_numParticle] = mcidx;
312 m_idxmc = m_numParticle;
316 return StatusCode::SUCCESS;
320 MsgStream log(
msgSvc(), name());
321 log << MSG::INFO <<
"in finalize()" << endmsg;
328 if(
flag ==
false && ( CrossSection*MCEff==0||CrossSection*MCEffBoost==0)){
329 log << MSG::FATAL<<
"DiGam Error: cross_section or MC_eff is not correct!"<<endreq;
333 ssg=(signal-(tot-signal))*1.0;
335 lum=(ssg)/(CrossSection*MCEff);
337 boost_ssg=(boost_signal-(boost_tot-boost_signal))*1.0;
339 boost_lum=(boost_ssg)/(CrossSection*MCEffBoost);
343 log << MSG::DEBUG <<
"E_cms = "<<E_cms<<endreq;
345 log << MSG::DEBUG <<
"N0 = "<<
N0<<endreq;
346 log << MSG::DEBUG <<
"minE, phi in:"<<boostMinEmin<<
" ~ "<<boostMinEmax<<
", "<<boostPhimin<<
" ~ "<<boostPhimax<<endreq;
347 log << MSG::DEBUG <<
"sigma, eff = "<<CrossSection<<
","<<MCEff<<endreq;
348 log << MSG::DEBUG <<
"sigma, effBoost = "<<CrossSection<<
", "<<MCEffBoost<<endreq;
349 log << MSG::DEBUG <<
"Nsignal, lum, Nsig_boost, boost_lum = "<<ssg<<
", "<<
lum<<
", "<<boost_ssg<<
", "<<boost_lum<<endreq;
350 h_lum->SetBinContent(1,
lum);
351 h_lum->SetBinContent(2,ssg);
352 h_lum->SetBinContent(3,boost_lum);
353 h_lum->SetBinContent(4,boost_ssg);
354 if(m_thsvc->regHist(
"/DQAHist/zhsLUM/lum", h_lum).isFailure()){
355 log << MSG::FATAL<<
"DiGam Error:can't write data to LUM!"<<endreq;
358 return StatusCode::SUCCESS;
double sin(const BesAngle a)
double cos(const BesAngle a)
std::vector< HepLorentzVector > Vp4
EvtRecTrackCol::iterator EvtRecTrackIterator
virtual bool isRunValid()=0
virtual double getbeamE()=0
virtual void getBeamEnergyInfo()=0
void parameters(double E_cms)
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol