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"
9#include "EventModel/EventModel.h"
10#include "EventModel/Event.h"
11#include "EventModel/EventHeader.h"
12#include "EvtRecEvent/EvtRecEvent.h"
13#include "EvtRecEvent/EvtRecTrack.h"
14#include "DstEvent/TofHitStatus.h"
15#include "McTruth/McParticle.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"
26#include "VertexFit/KinematicFit.h"
27#include "VertexFit/VertexFit.h"
28#include "ParticleID/ParticleID.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;
33#include "DiGamAlg/DiGam.h"
35#include "DiGamAlg/Parameter.h"
37const double pai=3.1415926;
40 Algorithm(name, pSvcLocator) {
41 declareProperty(
"jpsiCrossSection",jpsiCrossSection=249.7);
42 declareProperty(
"jpsiMCEff",jpsiMCEff=0.07145);
43 declareProperty(
"jpsiMCEffBoost",jpsiMCEffBoost=0.07099);
45 declareProperty(
"psi2sCrossSection",psi2sCrossSection=180.8);
46 declareProperty(
"psi2sMCEff",psi2sMCEff=0.07159);
47 declareProperty(
"psi2sMCEffBoost",psi2sMCEffBoost=0.07123);
49 declareProperty(
"psi3770CrossSection",psi3770CrossSection=173.4);
50 declareProperty(
"psi3770MCEff",psi3770MCEff=0.071725);
51 declareProperty(
"psi3770MCEffBoost",psi3770MCEffBoost=0.0713125);
53 declareProperty(
"CrossSection",CrossSection);
54 declareProperty(
"MCEff",MCEff);
55 declareProperty(
"MCEffBoost",MCEffBoost);
57 declareProperty(
"boostPhimin", boostPhimin=2.5);
58 declareProperty(
"boostPhimax",boostPhimax=5);
59 declareProperty(
"boostMinEmin",boostMinEmin);
60 declareProperty(
"boostMinEmax",boostMinEmax);
62 declareProperty(
"RunModel",RunModel=2000);
63 declareProperty(
"dPhiMin",dPhiMin=-7);
64 declareProperty(
"dPhiMax",dPhiMax=5);
65 declareProperty(
"dPhiMinSig",dPhiMinSig=-4);
66 declareProperty(
"dPhiMaxSig",dPhiMaxSig=2);
68 declareProperty(
"flag",
flag=
true);
69 declareProperty(
"E_cms",E_cms);
73 MsgStream log(
msgSvc(), name());
74 log << MSG::INFO <<
"in initialize()" << endmsg;
77 CrossSection=jpsiCrossSection;
79 MCEffBoost=jpsiMCEffBoost;
86 CrossSection=psi2sCrossSection;
88 MCEffBoost=psi2sMCEffBoost;
95 CrossSection=psi3770CrossSection;
97 MCEffBoost=psi3770MCEffBoost;
108 StatusCode ssc=service(
"THistSvc", m_thsvc);
109 if(ssc.isFailure()) {
110 log << MSG::FATAL <<
"DiGamAlg:Couldn't get THistSvc" << endreq;
113 h_lum=
new TH1F(
"lum",
"lum",4,0.5,4.5);
115 StatusCode scBeamEnergy=service(
"BeamEnergySvc", m_BeamEnergySvc);
117 if( scBeamEnergy.isFailure() ){
118 log << MSG::FATAL <<
"can not use BeamEnergySvc" << endreq;
124 NTuplePtr nt2(
ntupleSvc(),
"DQAFILE/zhsDiGam");
127 m_tuple2=
ntupleSvc()->book(
"DQAFILE/zhsDiGam",CLID_ColumnWiseTuple,
"ks N-Tuple example");
129 status=m_tuple2->addItem(
"ETol",m_tot);
130 status=m_tuple2->addItem(
"maxE",m_maxE);
131 status=m_tuple2->addItem(
"minE",m_minE);
132 status=m_tuple2->addItem(
"maxTheta",m_maxTheta);
133 status=m_tuple2->addItem(
"minTheta",m_minTheta);
134 status=m_tuple2->addItem(
"maxPhi",m_maxPhi);
135 status=m_tuple2->addItem(
"minPhi",m_minPhi);
136 status=m_tuple2->addItem(
"delTheta",m_delTheta);
137 status=m_tuple2->addItem(
"delPhi",m_delPhi);
138 status=m_tuple2->addItem(
"angle",m_angle);
139 status=m_tuple2->addItem(
"boostAngle",m_boostAngle);
140 status=m_tuple2->addItem(
"boostMaxE",m_boostMaxE);
141 status=m_tuple2->addItem(
"boostMinE",m_boostMinE);
142 status=m_tuple2->addItem(
"boostDelPhi",m_boostDelPhi);
143 status=m_tuple2->addItem(
"boostDelTheta",m_boostDelTheta);
144 status=m_tuple2->addItem(
"boostM",m_boostM);
145 status=m_tuple2->addItem(
"boostIM",m_boostIM);
146 status=m_tuple2->addItem(
"m",m_m);
147 status=m_tuple2->addItem(
"IM",m_IM);
149 status=m_tuple2->addItem (
"run",m_run );
150 status=m_tuple2->addItem (
"rec",m_rec );
151 status=m_tuple2->addItem(
"indexmc", m_idxmc, 0, 100);
152 status=m_tuple2->addIndexedItem(
"pdgid", m_idxmc, m_pdgid);
153 status=m_tuple2->addIndexedItem(
"motheridx", m_idxmc, m_motheridx);
157 log<<MSG::FATAL<<
"Cannot book N-tuple:"<<long(m_tuple2)<<endmsg;
158 return StatusCode::FAILURE;
162 return StatusCode::SUCCESS;
166 MsgStream log(
msgSvc(), name());
167 log << MSG::INFO <<
"in execute()" << endreq;
169 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
170 runNo=eventHeader->runNumber();
171 int event=eventHeader->eventNumber();
172 log<<MSG::INFO<<
"run,evtnum="<<runNo<<
","<<
event<<endreq;
173 m_run = eventHeader->runNumber();
174 m_rec = eventHeader->eventNumber();
179 log << MSG::DEBUG <<
"setting parameter" << endreq;
182 if ( ! m_BeamEnergySvc->
isRunValid() )
return StatusCode::FAILURE;
183 E_cms = 2*m_BeamEnergySvc->
getbeamE();
184 log << MSG::DEBUG <<
"cms energy is " << E_cms << endreq;
197 log<<MSG::INFO<<
"ncharg,nneu,tottks="
198 <<evtRecEvent->totalCharged()<<
","
199 <<evtRecEvent->totalNeutral()<<
","
200 <<evtRecEvent->totalTracks()<<endreq;
202 std::vector<int> iGam;
205 for(
int i=evtRecEvent->totalCharged();i< evtRecEvent->totalTracks();i++){
207 if(!(*itTrk)->isEmcShowerValid())
continue;
209 if(emcTrk->
energy()<0.6)
continue;
210 if(fabs(
cos(emcTrk->
theta()))>0.83)
continue;
211 iGam.push_back((*itTrk)->trackId());
213 if(iGam.size()<2)
return StatusCode::SUCCESS;
219 for(
int i=0;i<iGam.size();i++){
223 if(emcTrk->
energy()>energy1){
229 else if(emcTrk->
energy()>energy2){
234 if(gam1==-9999 || gam2==-9999)
return StatusCode::SUCCESS;
236 m_tot=energy1+energy2;
237 RecEmcShower* maxEmc=(*(evtRecTrkCol->begin()+gam1))->emcShower();
238 RecEmcShower* minEmc=(*(evtRecTrkCol->begin()+gam2))->emcShower();
241 m_maxTheta=maxEmc->
theta();
242 m_minTheta=minEmc->
theta();
243 m_maxPhi=maxEmc->
phi();
244 m_minPhi=minEmc->
phi();
245 m_delPhi=(fabs(m_maxPhi-m_minPhi)-
pai)*180./
pai;
246 m_delTheta=(fabs(m_maxTheta+m_minTheta)-
pai)*180./
pai;
249 max.setPx(m_maxE*
sin(m_maxTheta)*
cos(m_maxPhi));
250 max.setPy(m_maxE*
sin(m_maxTheta)*
sin(m_maxPhi));
251 max.setPz(m_maxE*
cos(m_maxTheta));
253 min.setPx(m_minE*
sin(m_minTheta)*
cos(m_minPhi));
254 min.setPy(m_minE*
sin(m_minTheta)*
sin(m_minPhi));
255 min.setPz(m_minE*
cos(m_minTheta));
259 m_IM=
max.invariantMass(
min);
261 if(m_minE>=boostMinEmin && m_delPhi>dPhiMin && m_delPhi<dPhiMax && m_minE<=boostMinEmax)tot++;
262 if(m_minE>=boostMinEmin && m_delPhi>dPhiMinSig && m_delPhi<dPhiMaxSig && m_minE<=boostMinEmax)signal++;
266 HepLorentzVector boost1=
max.boost(-0.011,0,0);
267 HepLorentzVector boost2=
min.boost(-0.011,0,0);
268 m_boostAngle=boost1.angle(boost2.vect())*180./
pai;
269 m_boostMaxE=boost1.e();
270 m_boostMinE=boost2.e();
271 m_boostDelPhi=(fabs(boost1.phi()-boost2.phi())-
pai)*180./
pai;
272 m_boostDelTheta=(fabs(boost1.theta()+boost2.theta())-
pai)*180./
pai;
273 m_boostM=(boost1+boost2).m();
274 m_boostIM=boost1.invariantMass(boost2);
275 log << MSG::INFO <<
"num Good Photon " << iGam.size()<<endreq;
276 if(m_boostMinE>=boostMinEmin && m_boostMinE<=boostMinEmax && fabs(m_boostDelPhi)<=boostPhimin)boost_signal++;
277 if(m_boostMinE>=boostMinEmin && m_boostMinE<=boostMinEmax && fabs(m_boostDelPhi)<=boostPhimax)boost_tot++;
279 if (eventHeader->runNumber()<0)
281 SmartDataPtr<Event::McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
282 int m_numParticle = 0;
286 return StatusCode::FAILURE;
290 bool jpsipDecay =
false;
292 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
293 for (; iter_mc != mcParticleCol->end(); iter_mc++)
295 if ((*iter_mc)->primaryParticle())
continue;
296 if (!(*iter_mc)->decayFromGenerator())
continue;
298 if ((*iter_mc)->particleProperty()==443)
301 rootIndex = (*iter_mc)->trackIndex();
303 if (!jpsipDecay)
continue;
304 int mcidx = ((*iter_mc)->mother()).trackIndex() - rootIndex;
305 int pdgid = (*iter_mc)->particleProperty();
306 m_pdgid[m_numParticle] = pdgid;
307 m_motheridx[m_numParticle] = mcidx;
311 m_idxmc = m_numParticle;
315 return StatusCode::SUCCESS;
319 MsgStream log(
msgSvc(), name());
320 log << MSG::INFO <<
"in finalize()" << endmsg;
326 if(CrossSection*MCEff==0||CrossSection*MCEffBoost==0){
327 log << MSG::FATAL<<
"DiGam Error: cross_section or MC_eff is not correct!"<<endreq;
330 ssg=(signal-(tot-signal))*1.0;
332 lum=(ssg)/(CrossSection*MCEff);
334 boost_ssg=(boost_signal-(boost_tot-boost_signal))*1.0;
336 boost_lum=(boost_ssg)/(CrossSection*MCEffBoost);
339 std::cout<<
"E_cms = "<<E_cms<<std::endl;
341 std::cout<<
"N0 = "<<
N0<<std::endl;
342 std::cout<<
"minE, phi in:"<<boostMinEmin<<
" ~ "<<boostMinEmax<<
", "<<boostPhimin<<
" ~ "<<boostPhimax<<std::endl;
343 std::cout<<
"sigma, eff = "<<CrossSection<<
","<<MCEff<<std::endl;
344 std::cout<<
"sigma, effBoost = "<<CrossSection<<
", "<<MCEffBoost<<std::endl;
345 std::cout<<
"Nsignal, lum, Nsig_boost, boost_lum = "<<ssg<<
", "<<
lum<<
", "<<boost_ssg<<
", "<<boost_lum<<std::endl;
346 h_lum->SetBinContent(1,
lum);
347 h_lum->SetBinContent(2,ssg);
348 h_lum->SetBinContent(3,boost_lum);
349 h_lum->SetBinContent(4,boost_ssg);
350 if(m_thsvc->regHist(
"/DQAHist/zhsLUM/lum", h_lum).isFailure()){
351 log << MSG::FATAL<<
"DiGam Error:can't write data to LUM!"<<endreq;
354 return StatusCode::SUCCESS;
std::vector< HepLorentzVector > Vp4
EvtRecTrackCol::iterator EvtRecTrackIterator
double sin(const BesAngle a)
double cos(const BesAngle a)
DiGam(const std::string &name, ISvcLocator *pSvcLocator)
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