BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcBbEmcEff.cxx
Go to the documentation of this file.
2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/SmartDataPtr.h"
6#include "Identifier/MdcID.h"
11#include "CLHEP/Units/PhysicalConstants.h"
12
13
14#ifndef ENABLE_BACKWARDS_COMPATIBILITY
15// backwards compatblty wll be enabled ONLY n CLHEP 1.9
17#endif
18
19// MDC reconstructed data
22
23// Ntuple
24#include "GaudiKernel/INTupleSvc.h"
25#include "GaudiKernel/NTuple.h"
26
27typedef std::vector<HepLorentzVector> Vp4;
28using namespace std;
29using namespace Event;
30
31MdcBbEmcEff::MdcBbEmcEff(const std::string& name, ISvcLocator* pSvcLocator) :
32 Algorithm(name, pSvcLocator) {
33 declareProperty("hist", m_hist = false);
34 declareProperty("debug", m_debug= 0);
35 //Good Emc shower selection cut
36 declareProperty("emcEneCutLow", m_emcEneCutLow=1.44);
37 declareProperty("emcEneCutHigh", m_emcEneCutHigh=1.88);
38 declareProperty("emcEneCutTot", m_emcEneCutTot=3.16);
39 declareProperty("emcDangCutLow", m_emcDangCutLow=2.94);
40 declareProperty("emcDangCutHigh",m_emcDangCutHigh=3.08);
41 //Mdc track cut
42 declareProperty("dPhi", m_dPhiCut= 0.2);
43 declareProperty("dCosTheta", m_dCosThetaCut= 0.2);
44 declareProperty("d0", m_d0Cut= 1.);
45 declareProperty("z0", m_z0Cut= 5.);
46 //Barrel and Endcap cut
47 declareProperty("barrelCut", m_barrelCut = 0.8);
48 declareProperty("endcapCut", m_endcapCutLow = 0.83);
49 declareProperty("endcapCutHigh", m_endcapCutHigh = 0.93);
50 }
51
52// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
53
55 MsgStream log(msgSvc(), name());
56 StatusCode sc;
57 m_evtIndex = 0;
58
59 m_effAllN1 = 0;
60 m_effAllN2 = 0;
61
62 for (int i=0;i<3;i++){
63 m_effN1[i] = 0;
64 m_effN2[i] = 0;
65 }
66
67 if(m_hist) {
68 if(bookNTuple()<0) sc = StatusCode::FAILURE;
69 }
70
71 return StatusCode::SUCCESS;
72}
73
74// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
76 MsgStream log(msgSvc(), name());
77 StatusCode sc = StatusCode::SUCCESS;
78
79 setFilterPassed(false);
80
81 // Get eventNo, t0
82 if(getEventInfo()<0) return StatusCode::FAILURE;
83
84 // Select Bhabha by Emc shower
85 if(selectBbByEmcShower()<0) return StatusCode::SUCCESS;
86
87 // Select Good track
88 if(bbEmcMdcTrackingEff()<0) return StatusCode::SUCCESS;
89
90 return StatusCode::SUCCESS;
91}
92
93// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
95 MsgStream log(msgSvc(), name());
96 log << MSG::INFO << "in finalize()" << endreq;
97 if((m_effAllN1+m_effAllN2)>0)std::cout<<" MdcBbEmcEff efficiency = N2/(N1+N2) = "
98 << m_effAllN2<<"/("<<m_effAllN1<<"+"<<m_effAllN2<<") = "
99 << (m_effAllN2)/((float)(m_effAllN1+m_effAllN2))<<std::endl;
100 for(int i=0;i<3;i++){
101 string pos;
102 if (0==i) pos="barrel";
103 if (1==i) pos="gap";
104 if (2==i) pos="endcap";
105 if((m_effN1[i]+m_effN2[i])>0){
106 std::cout<<" MdcBbEmcEff of "<<pos <<" N2/(N1+N2) = "
107 << m_effN2[i]<<"/("<<m_effN1[i]<<"+"<<m_effN2[i]<<") = "
108 << (m_effN2[i])/((float)(m_effN1[i]+m_effN2[i]))<<std::endl;
109 }
110 }
111 return StatusCode::SUCCESS;
112}
113
114// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
115int MdcBbEmcEff::bookNTuple(){
116 MsgStream log(msgSvc(), name());
117 StatusCode sc;
118 NTuplePtr nt1(ntupleSvc(), "MdcBbEmcEff/evt");
119 if ( nt1 ) { m_tuple1 = nt1;}
120 else {
121 m_tuple1 = ntupleSvc()->book ("MdcBbEmcEff/evt", CLID_ColumnWiseTuple, "event");
122 if ( m_tuple1 ) {
123 //event info
124 sc = m_tuple1->addItem ("runNo", m_runNo);
125 sc = m_tuple1->addItem ("evtNo", m_evtNo);
126 sc = m_tuple1->addItem ("t0", m_t0);
127 sc = m_tuple1->addItem ("t0Stat", m_t0Stat);
128
129 //Emc shower
130 sc = m_tuple1->addItem ("index", m_index,0,2);
131 sc = m_tuple1->addIndexedItem ("emcTheta",m_index, m_emcTheta);
132 sc = m_tuple1->addIndexedItem ("emcPhi", m_index, m_emcPhi);
133 sc = m_tuple1->addIndexedItem ("emcEne", m_index, m_emcEne);
134 sc = m_tuple1->addItem ("emcDang", m_emcDang);
135
136 //Mdc track
137 sc = m_tuple1->addItem ("dCosTheta", m_dCosTheta);
138 sc = m_tuple1->addItem ("dPhi", m_dPhi);
139 sc = m_tuple1->addItem ("nTk", m_nTk,0,2);
140 sc = m_tuple1->addIndexedItem ("phi", m_nTk,m_phi);
141 sc = m_tuple1->addIndexedItem ("cosTheta",m_nTk,m_cosTheta);
142 sc = m_tuple1->addIndexedItem ("d0", m_nTk,m_d0);
143 sc = m_tuple1->addIndexedItem ("z0", m_nTk,m_z0);
144 sc = m_tuple1->addIndexedItem ("p", m_nTk,m_p);
145 sc = m_tuple1->addIndexedItem ("pt", m_nTk,m_pt);
146 } else {
147 log << MSG::ERROR << "Cannot book tuple MdcBbEmcEff/evt" << endmsg;
148 return -1;
149 }
150 }
151 return 1;
152}
153
154int MdcBbEmcEff::getEventInfo(){
155 MsgStream log(msgSvc(), name());
156
157 // Get event header
158 SmartDataPtr<Event::EventHeader> evtHead(eventSvc(),"/Event/EventHeader");
159 if (evtHead) {
160 t_runNo = evtHead->runNumber();
161 t_evtNo = evtHead->eventNumber();
162 }else{
163 log << MSG::WARNING<< "Could not retreve event header" << endreq;
164 }
165
166 std::cout<<m_evtIndex <<"------------evtNo:"<<t_evtNo << std::endl;//yzhang debug
167 m_evtIndex++;
168
169 //Get event start tme
170 t_t0 = -1;
171 t_t0Stat = -1;
172 SmartDataPtr<RecEsTimeCol> aevtmeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
173 if ((!aevtmeCol)||(aevtmeCol->size()==0)) {
174 log << MSG::WARNING << "Could not fnd RecEsTimeCol" << endreq;
175 }else{
176 RecEsTimeCol::iterator iter_evt = aevtmeCol->begin();
177 t_t0 = (*iter_evt)->getTest();
178 t_t0Stat = (*iter_evt)->getStat();
179 }
180 return 1;
181}
182
183int MdcBbEmcEff::selectBbByEmcShower(){
184 MsgStream log(msgSvc(), name());
185
186 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(), "/Event/EvtRec/EvtRecEvent");
187 log << MSG::DEBUG <<"ncharg, nneu, tottks = "
188 << evtRecEvent->totalCharged() << " , "
189 << evtRecEvent->totalNeutral() << " , "
190 << evtRecEvent->totalTracks() <<endreq;
191 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(), "/Event/EvtRec/EvtRecTrackCol");
192
193 Vp4 vGood;
194 HepLorentzVector m_lv_ele;
195 for(int i=0; i<evtRecEvent->totalTracks(); i++){
196 if(i>=evtRecTrkCol->size()) return -1;
197
198 EvtRecTrackIterator itTrk =evtRecTrkCol->begin() + i;
199 if(!(*itTrk)->isEmcShowerValid()) {
200 if(m_debug>1)std::cout<<"EmcShower NOT Valid "<<std::endl;
201 continue;
202 }
203 RecEmcShower *emcTrk = (*itTrk)->emcShower();
204 if((emcTrk->energy()>m_emcEneCutHigh)||(emcTrk->energy()<m_emcEneCutLow)){
205 if(m_debug>1)std::cout<<"Cut by EmcEnergy: "<<emcTrk->energy()<<std::endl;
206 continue;
207 }
208 Hep3Vector emcpos(emcTrk->x(), emcTrk->y(), emcTrk->z());
209 m_lv_ele.setVect(emcpos);
210 m_lv_ele.setE(emcTrk->energy());
211
212 vGood.push_back(m_lv_ele);
213 }
214
215 if(m_debug>1)std::cout<<"vGood.size = "<<vGood.size()<<std::endl;
216 if(vGood.size()!=2){
217 if (m_debug>0) std::cout<<"Cut by vGood.size: "<<vGood.size()<<std::endl;
218 return -2;//num of good showers==2
219 }
220
221
222 //Barrel or endcap
223 //if one shower in endcap , then this event in endcap
224 for(int i=0; i<2; i++){
225 double cosEmcTheta = cos(vGood[i].vect().theta());
226 if( fabs(cosEmcTheta) <= m_barrelCut ){
227 m_posFlag = BARREL;
228 }else if((cosEmcTheta>=m_endcapCutLow)&&(cosEmcTheta<=m_endcapCutHigh)){
229 m_posFlag = ENDCAP;
230 break;
231 }else if((cosEmcTheta>m_barrelCut)&&(cosEmcTheta<m_endcapCutLow)){
232 m_posFlag = GAP;
233 }else{
234 m_posFlag = OUT;
235 }
236 if(m_debug>1) std::cout<<"Emc cos(theta)="<<cosEmcTheta
237 <<"Track in "<<m_posFlag<<std::endl;
238 }
239 if(m_posFlag == OUT) return -5;
240
241 double dang = vGood[0].vect().angle(vGood[1].vect());
242 if(vGood[0].e() > vGood[1].e()) swap(vGood[0],vGood[1]);
243 double emcTheta[2],emcEne[2]; //emcPhi[2]
244 for(int index=0; index<2; index++){
245 emcTheta[index] = vGood[index].vect().theta();
246 t_emcPhi[index] = vGood[index].vect().phi();
247 emcEne[index] = vGood[index].e();
248 }
249
250 if(m_hist){
251 m_index = 2;
252 for (int index=0;index<2;index++){
253 m_emcTheta[index] = emcTheta[index];
254 m_emcPhi[index] = t_emcPhi[index];
255 m_emcEne[index] = emcEne[index];
256 }
257 m_emcDang = dang;
258 }
259 if(m_debug>1) std::cout<<" dang "<<dang<<std::endl;
260 if(m_debug>1) std::cout<<" energy "<<emcEne[0]<<" "<<emcEne[1]<<std::endl;
261 //delta(angle) cut
262 if(dang<=m_emcDangCutLow || dang>=m_emcDangCutHigh ) {
263 if(m_debug>0) std::cout<<"Cut by emcDang "<<dang<<std::endl;
264 return -3;
265 }
266 //cut by shower energy
267 if(emcEne[0]<=m_emcEneCutLow || emcEne[1]>=m_emcEneCutHigh){
268 if(m_debug>0) std::cout<<"Cut by emc energy low or high "
269 <<emcEne[0]<<" "<<emcEne[1]<<std::endl;
270 return -4;
271 }
272 if( (emcEne[0] + emcEne[1])<=m_emcEneCutTot){
273 if(m_debug>0) std::cout<<"Cut by emc total energy:"
274 <<emcEne[0]<<" "<<emcEne[1]<<" tot:"<<emcEne[0]+emcEne[1]<<std::endl;
275 return StatusCode::FAILURE;
276 }
277
278 return 1;
279}
280
281int MdcBbEmcEff::bbEmcMdcTrackingEff(){
282 MsgStream log(msgSvc(), name());
283
284 // Get RecMdcTrackCol and RecMdcHitCol
285 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(), "/Event/Recon/RecMdcTrackCol");
286 if (!recMdcTrackCol){
287 log << MSG::WARNING<< " Unable to retrieve recMdcTrackCol" << endreq;
288 return -1;
289 }
290
291 //1.Take track number ==1 or ==2
292 t_nTk = recMdcTrackCol->size();
293 if((t_nTk>2) || (0==t_nTk)) {
294 if(m_debug>1)std::cout<<name()<<"Cut by nTk "<<t_nTk<<std::endl;
295 return -2;
296 }
297
298 // Get RecMdcTrack info
299 double d0[2],z0[2],cosTheta[2],phi[2],p[2],pt[2];
300 RecMdcTrackCol::iterator it = recMdcTrackCol->begin();
301 for(int iTk=0 ; it != recMdcTrackCol->end(); it++,iTk++ ) {
302 RecMdcTrack* tk = (*it);
303 d0[iTk] = tk->helix(0);
304 z0[iTk] = tk->helix(3);
305 if ((fabs(d0[iTk])>m_d0Cut) || (fabs(z0[iTk])>m_z0Cut)){
306 if(m_debug>0) std::cout<<"Cut by d0 "
307 <<d0[iTk]<<" z0 "<<z0[iTk]<<std::endl;
308 return -3;
309 }
310 cosTheta[iTk] = cos(tk->theta());
311 phi[iTk] = tk->phi();
312 p[iTk] = tk->p();
313 pt[iTk] = tk->pxy();
314 }
315
316 double dCosTheta = cosTheta[0]+cosTheta[1];
317 double dPhi = phi[0] - phi[1] + CLHEP::pi;
318 if(dPhi > CLHEP::pi) dPhi-=CLHEP::twopi;
319
320 //hist Mdc track info
321 if (m_hist){
322 m_runNo = t_runNo;
323 m_evtNo = t_evtNo;
324 m_t0 = t_t0;
325 m_t0Stat= t_t0Stat;
326
327 for(int i=0;i<2;i++){
328 m_cosTheta[i]=cosTheta[i];
329 m_phi[i]=phi[i];
330 m_d0[i]=d0[i];
331 m_z0[i]=z0[i];
332 m_p[i]=p[i];
333 m_pt[i]=pt[i];
334 }
335 m_nTk = t_nTk;
336 m_dCosTheta= dCosTheta;
337 m_dPhi = dPhi;
338
339 m_nTk = t_nTk;
340 m_tuple1->write();
341 }
342
343 //4.Angle cut of 2 track event: delta(theta)<0.1 and delta(phi)<0.1
344 if(2==t_nTk){
345 if((fabs(dCosTheta)>m_dCosThetaCut) || (fabs(dPhi)>m_dPhiCut)){
346 if(m_debug>0) {
347 if (fabs(dCosTheta)>m_dCosThetaCut){
348 std::cout<<"Cut by dCosTheta "<<dCosTheta<<std::endl;
349 }else{
350 std::cout<<"Cut by dPhi "<<dPhi<<std::endl;
351 }
352 }
353 return -4;
354 }
355 m_effAllN2++;
356 m_effN2[m_posFlag]++;
357 }else{
358 m_effAllN1++;
359 m_effN1[m_posFlag]++;
360 }
361
362
363 if ((1==t_nTk)&&(m_posFlag==BARREL)) setFilterPassed(true);
364 return 1;
365}
double cos(const BesAngle a)
Definition: BesAngle.h:213
EvtRecTrackCol::iterator EvtRecTrackIterator
Definition: EvtRecTrack.h:111
std::vector< HepLorentzVector > Vp4
Definition: Gam4pikp.cxx:53
HepGeom::Point3D< double > HepPoint3D
Definition: MdcBbEmcEff.cxx:16
std::vector< HepLorentzVector > Vp4
Definition: MdcBbEmcEff.cxx:27
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
double x() const
Definition: DstEmcShower.h:35
double z() const
Definition: DstEmcShower.h:37
double energy() const
Definition: DstEmcShower.h:45
double y() const
Definition: DstEmcShower.h:36
const double theta() const
Definition: DstMdcTrack.h:59
const double phi() const
Definition: DstMdcTrack.h:60
const double pxy() const
Definition: DstMdcTrack.h:54
const HepVector helix() const
......
const double p() const
Definition: DstMdcTrack.h:58
StatusCode finalize()
Definition: MdcBbEmcEff.cxx:94
StatusCode initialize()
Definition: MdcBbEmcEff.cxx:54
StatusCode execute()
Definition: MdcBbEmcEff.cxx:75
MdcBbEmcEff(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MdcBbEmcEff.cxx:31
Definition: Event.h:21