BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
DiGam.cxx
Go to the documentation of this file.
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"
8
10#include "EventModel/Event.h"
15#include "McTruth/McParticle.h"
16#include "TMath.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"
27#include "VertexFit/VertexFit.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"
34#include <vector>
35#include "DiGamAlg/Parameter.h"
36
37const double pai=3.1415926;
38int N0;int N1;int N2;int N3;int N4;
39DiGam::DiGam(const std::string& name, ISvcLocator* pSvcLocator) :
40 Algorithm(name, pSvcLocator) {
41 declareProperty("jpsiCrossSection",jpsiCrossSection=249.7);
42 declareProperty("jpsiMCEff",jpsiMCEff=0.07145);
43 declareProperty("jpsiMCEffBoost",jpsiMCEffBoost=0.07099);
44
45 declareProperty("psi2sCrossSection",psi2sCrossSection=180.8);
46 declareProperty("psi2sMCEff",psi2sMCEff=0.07159);
47 declareProperty("psi2sMCEffBoost",psi2sMCEffBoost=0.07123);
48
49 declareProperty("psi3770CrossSection",psi3770CrossSection=173.4);
50 declareProperty("psi3770MCEff",psi3770MCEff=0.071725);
51 declareProperty("psi3770MCEffBoost",psi3770MCEffBoost=0.0713125);
52
53 declareProperty("CrossSection",CrossSection);
54 declareProperty("MCEff",MCEff);
55 declareProperty("MCEffBoost",MCEffBoost);
56
57 declareProperty("boostPhimin", boostPhimin=2.5);
58 declareProperty("boostPhimax",boostPhimax=5);
59 declareProperty("boostMinEmin",boostMinEmin);
60 declareProperty("boostMinEmax",boostMinEmax);
61
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);
67
68 declareProperty("flag",flag=true);
69 declareProperty("E_cms",E_cms);
70 }
71//***************************************************************************************
72StatusCode DiGam::initialize(){
73 MsgStream log(msgSvc(), name());
74 log << MSG::INFO << "in initialize()" << endmsg;
75
76 if(RunModel==1){//jpsi
77 CrossSection=jpsiCrossSection;
78 MCEff=jpsiMCEff;
79 MCEffBoost=jpsiMCEffBoost;
80 boostPhimin=2.5;
81 boostPhimax=5;
82 boostMinEmin=1.2;
83 boostMinEmax=1.6;
84 }
85 else if(RunModel==2){//psi2s
86 CrossSection=psi2sCrossSection;
87 MCEff=psi2sMCEff;
88 MCEffBoost=psi2sMCEffBoost;
89 boostPhimin=2.5;
90 boostPhimax=5;
91 boostMinEmin=1.4;
92 boostMinEmax=1.9;
93 }
94 else if(RunModel==3){//psi3770
95 CrossSection=psi3770CrossSection;
96 MCEff=psi3770MCEff;
97 MCEffBoost=psi3770MCEffBoost;
98 boostPhimin=2.5;
99 boostPhimax=5;
100 boostMinEmin=1.4;
101 boostMinEmax=2;
102 }
103
104 tot=0;
105 signal=0;
106 boost_signal=0;
107 boost_tot=0;
108 StatusCode ssc=service("THistSvc", m_thsvc);
109 if(ssc.isFailure()) {
110 log << MSG::FATAL << "DiGamAlg:Couldn't get THistSvc" << endreq;
111 return ssc;
112 }
113 h_lum=new TH1F("lum","lum",4,0.5,4.5);
114
115 StatusCode scBeamEnergy=service("BeamEnergySvc", m_BeamEnergySvc);
116
117 if( scBeamEnergy.isFailure() ){
118 log << MSG::FATAL << "can not use BeamEnergySvc" << endreq;
119 return scBeamEnergy;
120 }
121
122 StatusCode status;
123
124 NTuplePtr nt2(ntupleSvc(),"DQAFILE/zhsDiGam");
125 if(nt2)m_tuple2=nt2;
126 else{
127 m_tuple2=ntupleSvc()->book("DQAFILE/zhsDiGam",CLID_ColumnWiseTuple,"ks N-Tuple example");
128 if(m_tuple2){
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);
148
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);
154
155 }
156 else {
157 log<<MSG::FATAL<<"Cannot book N-tuple:"<<long(m_tuple2)<<endmsg;
158 return StatusCode::FAILURE;
159 }
160 }
161
162 return StatusCode::SUCCESS;
163}
164//******************************************************************************
165StatusCode DiGam::execute() {
166 MsgStream log(msgSvc(), name());
167 log << MSG::INFO << "in execute()" << endreq;
168 N0++;
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();
175
176 if(flag == true)
177 {
178 flag = false;
179 log << MSG::DEBUG << "setting parameter" << endreq;
180
181 m_BeamEnergySvc->getBeamEnergyInfo();
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;
185
186 Parameter *func = new Parameter();
187 func->parameters(E_cms);
188
189 CrossSection=func->m_CrossSection;
190 MCEff=func->m_MCEff;
191 MCEffBoost=func->m_MCEffBoost;
192 boostMinEmin=func->m_boostMinEmin;
193 boostMinEmax=func->m_boostMinEmax;
194 }
195
196 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(), EventModel::EvtRec::EvtRecEvent);
197 log<<MSG::INFO<<"ncharg,nneu,tottks="
198 <<evtRecEvent->totalCharged()<<","
199 <<evtRecEvent->totalNeutral()<<","
200 <<evtRecEvent->totalTracks()<<endreq;
201 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(), EventModel::EvtRec::EvtRecTrackCol);
202 std::vector<int> iGam;
203 iGam.clear();
204 N1++;
205 for(int i=evtRecEvent->totalCharged();i< evtRecEvent->totalTracks();i++){
206 EvtRecTrackIterator itTrk=evtRecTrkCol->begin() + i;
207 if(!(*itTrk)->isEmcShowerValid()) continue;
208 RecEmcShower *emcTrk = (*itTrk)->emcShower();
209 if(emcTrk->energy()<0.6)continue;
210 if(fabs(cos(emcTrk->theta()))>0.83)continue;
211 iGam.push_back((*itTrk)->trackId());
212 }
213 if(iGam.size()<2)return StatusCode::SUCCESS;
214 N2++;
215 double energy1=0.5;
216 double energy2=0.5;
217 int gam1=-9999;
218 int gam2=-9999;
219 for(int i=0;i<iGam.size();i++){
220 EvtRecTrackIterator itTrk=evtRecTrkCol->begin() + iGam[i];
221 RecEmcShower *emcTrk = (*itTrk)->emcShower();
222 //std::cout<<emcTrk->energy()<<std::endl;
223 if(emcTrk->energy()>energy1){ //max emc
224 energy2=energy1;
225 gam2=gam1;
226 energy1=emcTrk->energy();
227 gam1=iGam[i];
228 }
229 else if(emcTrk->energy()>energy2){ //second max emc
230 energy2=emcTrk->energy();
231 gam2=iGam[i];
232 }
233 }
234 if(gam1==-9999 || gam2==-9999)return StatusCode::SUCCESS;
235 N3++;
236 m_tot=energy1+energy2;
237 RecEmcShower* maxEmc=(*(evtRecTrkCol->begin()+gam1))->emcShower();
238 RecEmcShower* minEmc=(*(evtRecTrkCol->begin()+gam2))->emcShower();
239 m_maxE=maxEmc->energy();
240 m_minE=minEmc->energy();
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;
247
248 HepLorentzVector max,min;
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));
252 max.setE(m_maxE);
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));
256 min.setE(m_minE);
257 m_angle=max.angle(min.vect())*180./pai;
258 m_m=(max+min).m();
259 m_IM=max.invariantMass(min);
260 //select signal and sideband to get lum;
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++;
263
264 //boost
265 //HepLorentzVector p_cms(0.034067,0.0,0.0,3.097);
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++;
278 //mcTruth
279 if (eventHeader->runNumber()<0)
280 {
281 SmartDataPtr<Event::McParticleCol> mcParticleCol(eventSvc(), "/Event/MC/McParticleCol");
282 int m_numParticle = 0;
283 if (!mcParticleCol)
284 {
285 //std::cout << "Could not retrieve McParticelCol" << std::endl;
286 return StatusCode::FAILURE;
287 }
288 else
289 {
290 bool jpsipDecay = false;
291 int rootIndex = -1;
292 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
293 for (; iter_mc != mcParticleCol->end(); iter_mc++)
294 {
295 if ((*iter_mc)->primaryParticle()) continue;
296 if (!(*iter_mc)->decayFromGenerator()) continue;
297
298 if ((*iter_mc)->particleProperty()==443)
299 {
300 jpsipDecay = true;
301 rootIndex = (*iter_mc)->trackIndex();
302 }
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;
308 m_numParticle += 1;
309 }
310 }
311 m_idxmc = m_numParticle;
312 }
313 N4++;
314 m_tuple2->write();
315 return StatusCode::SUCCESS;
316}
317// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
318StatusCode DiGam::finalize() {
319 MsgStream log(msgSvc(), name());
320 log << MSG::INFO << "in finalize()" << endmsg;
321 //get intLumEndcapEE
322 double ssg=0.;
323 double lum=0.;
324 double boost_ssg=0.;
325 double boost_lum=0.;
326 // protection if execute() is not executed
327 if(flag == false && ( CrossSection*MCEff==0||CrossSection*MCEffBoost==0)){
328 log << MSG::FATAL<<"DiGam Error: cross_section or MC_eff is not correct!"<<endreq;
329 exit(1);
330 }
331 if (flag == false) {
332 ssg=(signal-(tot-signal))*1.0;
333 //boss 650 mc:7.135%
334 lum=(ssg)/(CrossSection*MCEff);
335 //boost LUM
336 boost_ssg=(boost_signal-(boost_tot-boost_signal))*1.0;
337 //boost 650 mc:7.097%
338 boost_lum=(boost_ssg)/(CrossSection*MCEffBoost);
339 }
340
341 // std::cout<<"flag = "<<flag<<std::endl;
342 log << MSG::DEBUG <<"E_cms = "<<E_cms<<endreq;
343
344 log << MSG::DEBUG <<"N0 = "<<N0<<endreq;
345 log << MSG::DEBUG <<"minE, phi in:"<<boostMinEmin<<" ~ "<<boostMinEmax<<", "<<boostPhimin<<" ~ "<<boostPhimax<<endreq;
346 log << MSG::DEBUG <<"sigma, eff = "<<CrossSection<<","<<MCEff<<endreq;
347 log << MSG::DEBUG <<"sigma, effBoost = "<<CrossSection<<", "<<MCEffBoost<<endreq;
348 log << MSG::DEBUG <<"Nsignal, lum, Nsig_boost, boost_lum = "<<ssg<<", "<<lum<<", "<<boost_ssg<<", "<<boost_lum<<endreq;
349 h_lum->SetBinContent(1,lum);
350 h_lum->SetBinContent(2,ssg);
351 h_lum->SetBinContent(3,boost_lum);
352 h_lum->SetBinContent(4,boost_ssg);
353 if(m_thsvc->regHist("/DQAHist/zhsLUM/lum", h_lum).isFailure()){
354 log << MSG::FATAL<<"DiGam Error:can't write data to LUM!"<<endreq;
355 exit(1);
356 }
357 return StatusCode::SUCCESS;
358}
const double pai
Definition: BbEmc.cxx:48
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
int N0
Definition: DiGam.cxx:38
int N3
Definition: DiGam.cxx:38
int N1
Definition: DiGam.cxx:38
std::vector< HepLorentzVector > Vp4
Definition: DiGam.cxx:32
int N4
Definition: DiGam.cxx:38
const double xmass[5]
Definition: DiGam.cxx:29
const double pai
Definition: DiGam.cxx:37
const double velc
Definition: DiGam.cxx:30
int N2
Definition: DiGam.cxx:38
std::vector< int > Vint
Definition: DiGam.cxx:31
EvtRecTrackCol::iterator EvtRecTrackIterator
Definition: EvtRecTrack.h:111
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
StatusCode execute()
Definition: DiGam.cxx:165
DiGam(const std::string &name, ISvcLocator *pSvcLocator)
Definition: DiGam.cxx:39
StatusCode finalize()
Definition: DiGam.cxx:318
StatusCode initialize()
Definition: DiGam.cxx:72
double theta() const
Definition: DstEmcShower.h:38
double phi() const
Definition: DstEmcShower.h:39
double energy() const
Definition: DstEmcShower.h:45
virtual bool isRunValid()=0
virtual double getbeamE()=0
virtual void getBeamEnergyInfo()=0
double m_MCEffBoost
Definition: Parameter.h:12
double m_boostMinEmax
Definition: Parameter.h:14
void parameters(double E_cms)
Definition: Parameter.cxx:8
double m_boostMinEmin
Definition: Parameter.h:13
double m_MCEff
Definition: Parameter.h:11
double m_CrossSection
Definition: Parameter.h:10
_EXTERN_ std::string EvtRecEvent
Definition: EventModel.h:116
_EXTERN_ std::string EvtRecTrackCol
Definition: EventModel.h:117