CGEM BOSS 6.6.5.g
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>
36const double pai=3.1415926;
37int N0;int N1;int N2;int N3;int N4;
38DiGam::DiGam(const std::string& name, ISvcLocator* pSvcLocator) :
39 Algorithm(name, pSvcLocator) {
40 declareProperty("jpsiCrossSection",jpsiCrossSection);
41 declareProperty("jpsiMCEff",jpsiMCEff);
42 declareProperty("jpsiMCEffBoost",jpsiMCEffBoost);
43
44 declareProperty("psi2sCrossSection",psi2sCrossSection);
45 declareProperty("psi2sMCEff",psi2sMCEff);
46 declareProperty("psi2sMCEffBoost",psi2sMCEffBoost);
47
48 declareProperty("psi3770CrossSection",psi3770CrossSection);
49 declareProperty("psi3770MCEff",psi3770MCEff);
50 declareProperty("psi3770MCEffBoost",psi3770MCEffBoost);
51
52 declareProperty("CrossSection",CrossSection);
53 declareProperty("MCEff",MCEff);
54 declareProperty("MCEffBoost",MCEffBoost);
55
56 declareProperty("boostPhimin", boostPhimin=2.5);
57 declareProperty("boostPhimax",boostPhimax=5);
58 declareProperty("boostMinEmin",boostMinEmin=1.2);
59 declareProperty("boostMinEmax",boostMinEmax=1.6);
60
61 declareProperty("RunModel",RunModel=1);
62 declareProperty("dPhiMin",dPhiMin);
63 declareProperty("dPhiMax",dPhiMax);
64 declareProperty("dPhiMinSig",dPhiMinSig);
65 declareProperty("dPhiMaxSig",dPhiMaxSig);
66 }
67//***************************************************************************************
68StatusCode DiGam::initialize(){
69 MsgStream log(msgSvc(), name());
70 log << MSG::INFO << "in initialize()" << endmsg;
71
72 if(RunModel==1){//jpsi
73 CrossSection=jpsiCrossSection;
74 MCEff=jpsiMCEff;
75 MCEffBoost=jpsiMCEffBoost;
76 boostPhimin=2.5;
77 boostPhimax=5;
78 boostMinEmin=1.2;
79 boostMinEmax=1.6;
80 }
81 else if(RunModel==2){//psi2s
82 CrossSection=psi2sCrossSection;
83 MCEff=psi2sMCEff;
84 MCEffBoost=psi2sMCEffBoost;
85 boostPhimin=2.5;
86 boostPhimax=5;
87 boostMinEmin=1.4;
88 boostMinEmax=1.9;
89 }
90 else if(RunModel==3){//psi3770
91 CrossSection=psi3770CrossSection;
92 MCEff=psi3770MCEff;
93 MCEffBoost=psi3770MCEffBoost;
94 boostPhimin=2.5;
95 boostPhimax=5;
96 boostMinEmin=1.4;
97 boostMinEmax=2;
98 }
99
100 tot=0;
101 signal=0;
102 boost_signal=0;
103 boost_tot=0;
104 StatusCode ssc=service("THistSvc", m_thsvc);
105 if(ssc.isFailure()) {
106 log << MSG::FATAL << "DiGamAlg:Couldn't get THistSvc" << endreq;
107 exit(1);
108 }
109 h_lum=new TH1F("lum","lum",4,0.5,4.5);
110 StatusCode status;
111 NTuplePtr nt2(ntupleSvc(),"DQAFILE/zhsDiGam");
112 if(nt2)m_tuple2=nt2;
113 else{
114 m_tuple2=ntupleSvc()->book("DQAFILE/zhsDiGam",CLID_ColumnWiseTuple,"ks N-Tuple example");
115 if(m_tuple2){
116 status=m_tuple2->addItem("ETol",m_tot);
117 status=m_tuple2->addItem("maxE",m_maxE);
118 status=m_tuple2->addItem("minE",m_minE);
119 status=m_tuple2->addItem("maxTheta",m_maxTheta);
120 status=m_tuple2->addItem("minTheta",m_minTheta);
121 status=m_tuple2->addItem("maxPhi",m_maxPhi);
122 status=m_tuple2->addItem("minPhi",m_minPhi);
123 status=m_tuple2->addItem("delTheta",m_delTheta);
124 status=m_tuple2->addItem("delPhi",m_delPhi);
125 status=m_tuple2->addItem("angle",m_angle);
126 status=m_tuple2->addItem("boostAngle",m_boostAngle);
127 status=m_tuple2->addItem("boostMaxE",m_boostMaxE);
128 status=m_tuple2->addItem("boostMinE",m_boostMinE);
129 status=m_tuple2->addItem("boostDelPhi",m_boostDelPhi);
130 status=m_tuple2->addItem("boostDelTheta",m_boostDelTheta);
131 status=m_tuple2->addItem("boostM",m_boostM);
132 status=m_tuple2->addItem("boostIM",m_boostIM);
133 status=m_tuple2->addItem("m",m_m);
134 status=m_tuple2->addItem("IM",m_IM);
135
136 status=m_tuple2->addItem ("run",m_run );
137 status=m_tuple2->addItem ("rec",m_rec );
138 status=m_tuple2->addItem("indexmc", m_idxmc, 0, 100);
139 status=m_tuple2->addIndexedItem("pdgid", m_idxmc, m_pdgid);
140 status=m_tuple2->addIndexedItem("motheridx", m_idxmc, m_motheridx);
141
142 }
143 else {
144 log<<MSG::FATAL<<"Cannot book N-tuple:"<<long(m_tuple2)<<endmsg;
145 return StatusCode::FAILURE;
146 }
147 }
148
149 return StatusCode::SUCCESS;
150}
151//******************************************************************************
152StatusCode DiGam::execute() {
153 MsgStream log(msgSvc(), name());
154 log << MSG::INFO << "in execute()" << endreq;
155 N0++;
156 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
157 runNo=eventHeader->runNumber();
158 int event=eventHeader->eventNumber();
159 log<<MSG::INFO<<"run,evtnum="<<runNo<<","<<event<<endreq;
160 m_run = eventHeader->runNumber();
161 m_rec = eventHeader->eventNumber();
162
163 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(), EventModel::EvtRec::EvtRecEvent);
164 log<<MSG::INFO<<"ncharg,nneu,tottks="
165 <<evtRecEvent->totalCharged()<<","
166 <<evtRecEvent->totalNeutral()<<","
167 <<evtRecEvent->totalTracks()<<endreq;
168 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(), EventModel::EvtRec::EvtRecTrackCol);
169 std::vector<int> iGam;
170 iGam.clear();
171 N1++;
172 for(int i=evtRecEvent->totalCharged();i< evtRecEvent->totalTracks();i++){
173 EvtRecTrackIterator itTrk=evtRecTrkCol->begin() + i;
174 if(!(*itTrk)->isEmcShowerValid()) continue;
175 RecEmcShower *emcTrk = (*itTrk)->emcShower();
176 if(emcTrk->energy()<0.6)continue;
177 if(fabs(cos(emcTrk->theta()))>0.83)continue;
178 iGam.push_back((*itTrk)->trackId());
179 }
180 if(iGam.size()<2)return StatusCode::SUCCESS;
181 N2++;
182 double energy1=0.5;
183 double energy2=0.5;
184 int gam1=-9999;
185 int gam2=-9999;
186 for(int i=0;i<iGam.size();i++){
187 EvtRecTrackIterator itTrk=evtRecTrkCol->begin() + iGam[i];
188 RecEmcShower *emcTrk = (*itTrk)->emcShower();
189 //std::cout<<emcTrk->energy()<<std::endl;
190 if(emcTrk->energy()>energy1){ //max emc
191 energy2=energy1;
192 gam2=gam1;
193 energy1=emcTrk->energy();
194 gam1=iGam[i];
195 }
196 else if(emcTrk->energy()>energy2){ //second max emc
197 energy2=emcTrk->energy();
198 gam2=iGam[i];
199 }
200 }
201 if(gam1==-9999 || gam2==-9999)return StatusCode::SUCCESS;
202 N3++;
203 m_tot=energy1+energy2;
204 RecEmcShower* maxEmc=(*(evtRecTrkCol->begin()+gam1))->emcShower();
205 RecEmcShower* minEmc=(*(evtRecTrkCol->begin()+gam2))->emcShower();
206 m_maxE=maxEmc->energy();
207 m_minE=minEmc->energy();
208 m_maxTheta=maxEmc->theta();
209 m_minTheta=minEmc->theta();
210 m_maxPhi=maxEmc->phi();
211 m_minPhi=minEmc->phi();
212 m_delPhi=(fabs(m_maxPhi-m_minPhi)-pai)*180./pai;
213 m_delTheta=(fabs(m_maxTheta+m_minTheta)-pai)*180./pai;
214
215 HepLorentzVector max,min;
216 max.setPx(m_maxE*sin(m_maxTheta)*cos(m_maxPhi));
217 max.setPy(m_maxE*sin(m_maxTheta)*sin(m_maxPhi));
218 max.setPz(m_maxE*cos(m_maxTheta));
219 max.setE(m_maxE);
220 min.setPx(m_minE*sin(m_minTheta)*cos(m_minPhi));
221 min.setPy(m_minE*sin(m_minTheta)*sin(m_minPhi));
222 min.setPz(m_minE*cos(m_minTheta));
223 min.setE(m_minE);
224 m_angle=max.angle(min.vect())*180./pai;
225 m_m=(max+min).m();
226 m_IM=max.invariantMass(min);
227 //select signal and sideband to get lum;
228 if(m_minE>=boostMinEmin && m_delPhi>dPhiMin && m_delPhi<dPhiMax && m_minE<=boostMinEmax)tot++;
229 if(m_minE>=boostMinEmin && m_delPhi>dPhiMinSig && m_delPhi<dPhiMaxSig && m_minE<=boostMinEmax)signal++;
230
231 //boost
232 //HepLorentzVector p_cms(0.034067,0.0,0.0,3.097);
233 HepLorentzVector boost1=max.boost(-0.011,0,0);
234 HepLorentzVector boost2=min.boost(-0.011,0,0);
235 m_boostAngle=boost1.angle(boost2.vect())*180./pai;
236 m_boostMaxE=boost1.e();
237 m_boostMinE=boost2.e();
238 m_boostDelPhi=(fabs(boost1.phi()-boost2.phi())-pai)*180./pai;
239 m_boostDelTheta=(fabs(boost1.theta()+boost2.theta())-pai)*180./pai;
240 m_boostM=(boost1+boost2).m();
241 m_boostIM=boost1.invariantMass(boost2);
242 log << MSG::INFO << "num Good Photon " << iGam.size()<<endreq;
243 if(m_boostMinE>=boostMinEmin && m_boostMinE<=boostMinEmax && fabs(m_boostDelPhi)<=boostPhimin)boost_signal++;
244 if(m_boostMinE>=boostMinEmin && m_boostMinE<=boostMinEmax && fabs(m_boostDelPhi)<=boostPhimax)boost_tot++;
245 //mcTruth
246 if (eventHeader->runNumber()<0)
247 {
248 SmartDataPtr<Event::McParticleCol> mcParticleCol(eventSvc(), "/Event/MC/McParticleCol");
249 int m_numParticle = 0;
250 if (!mcParticleCol)
251 {
252 //std::cout << "Could not retrieve McParticelCol" << std::endl;
253 return StatusCode::FAILURE;
254 }
255 else
256 {
257 bool jpsipDecay = false;
258 int rootIndex = -1;
259 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
260 for (; iter_mc != mcParticleCol->end(); iter_mc++)
261 {
262 if ((*iter_mc)->primaryParticle()) continue;
263 if (!(*iter_mc)->decayFromGenerator()) continue;
264
265 if ((*iter_mc)->particleProperty()==443)
266 {
267 jpsipDecay = true;
268 rootIndex = (*iter_mc)->trackIndex();
269 }
270 if (!jpsipDecay) continue;
271 int mcidx = ((*iter_mc)->mother()).trackIndex() - rootIndex;
272 int pdgid = (*iter_mc)->particleProperty();
273 m_pdgid[m_numParticle] = pdgid;
274 m_motheridx[m_numParticle] = mcidx;
275 m_numParticle += 1;
276 }
277 }
278 m_idxmc = m_numParticle;
279 }
280 N4++;
281 m_tuple2->write();
282 return StatusCode::SUCCESS;
283}
284// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
285StatusCode DiGam::finalize() {
286 MsgStream log(msgSvc(), name());
287 log << MSG::INFO << "in finalize()" << endmsg;
288 //get intLumEndcapEE
289 double ssg=0.;
290 double lum=0.;
291 double boost_ssg=0.;
292 double boost_lum=0.;
293 if(CrossSection*MCEff==0||CrossSection*MCEffBoost==0){
294 log << MSG::FATAL<<"DiGam Error: cross_section or MC_eff is not correct!"<<endreq;
295 exit(1);
296 }
297 ssg=(signal-(tot-signal))*1.0;
298 //boss 650 mc:7.135%
299 lum=(ssg)/(CrossSection*MCEff);
300 //boost LUM
301 boost_ssg=(boost_signal-(boost_tot-boost_signal))*1.0;
302 //boost 650 mc:7.097%
303 boost_lum=(boost_ssg)/(CrossSection*MCEffBoost);
304
305 std::cout<<"N0 = "<<N0<<std::endl;
306 std::cout<<"minE, phi in:"<<boostMinEmin<<" ~ "<<boostMinEmax<<", "<<boostPhimin<<" ~ "<<boostPhimax<<std::endl;
307 std::cout<<"sigma, eff = "<<CrossSection<<","<<MCEff<<std::endl;
308 std::cout<<"sigma, effBoost = "<<CrossSection<<", "<<MCEffBoost<<std::endl;
309 std::cout<<"Nsignal, lum, Nsig_boost, boost_lum = "<<ssg<<", "<<lum<<", "<<boost_ssg<<", "<<boost_lum<<std::endl;
310 h_lum->SetBinContent(1,lum);
311 h_lum->SetBinContent(2,ssg);
312 h_lum->SetBinContent(3,boost_lum);
313 h_lum->SetBinContent(4,boost_ssg);
314 if(m_thsvc->regHist("/DQAHist/zhsLUM/lum", h_lum).isFailure()){
315 log << MSG::FATAL<<"DiGam Error:can't write data to LUM!"<<endreq;
316 exit(1);
317 }
318 return StatusCode::SUCCESS;
319}
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
Double_t lum[10]
int N0
Definition: DiGam.cxx:37
int N3
Definition: DiGam.cxx:37
int N1
Definition: DiGam.cxx:37
std::vector< HepLorentzVector > Vp4
Definition: DiGam.cxx:32
int N4
Definition: DiGam.cxx:37
const double xmass[5]
Definition: DiGam.cxx:29
const double pai
Definition: DiGam.cxx:36
const double velc
Definition: DiGam.cxx:30
int N2
Definition: DiGam.cxx:37
std::vector< int > Vint
Definition: DiGam.cxx:31
EvtRecTrackCol::iterator EvtRecTrackIterator
Definition: EvtRecTrack.h:131
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
StatusCode execute()
Definition: DiGam.cxx:152
DiGam(const std::string &name, ISvcLocator *pSvcLocator)
Definition: DiGam.cxx:38
StatusCode finalize()
Definition: DiGam.cxx:285
StatusCode initialize()
Definition: DiGam.cxx:68
double theta() const
Definition: DstEmcShower.h:38
double phi() const
Definition: DstEmcShower.h:39
double energy() const
Definition: DstEmcShower.h:45
_EXTERN_ std::string EvtRecEvent
Definition: EventModel.h:134
_EXTERN_ std::string EvtRecTrackCol
Definition: EventModel.h:135