32 MsgStream log(
msgSvc(), name());
33 log << MSG::INFO <<
"DedxCalibEvent::initializing()" << endreq;
36 NTuplePtr nt1(
ntupleSvc(),
"FILE100/n103");
41 m_nt1=
ntupleSvc()->book(
"FILE100/n103",CLID_ColumnWiseTuple,
"dEdx per track");
44 status = m_nt1->addItem(
"ptrk",m_ptrk);
45 status = m_nt1->addItem(
"ptrk_t",m_ptrk_t);
46 status = m_nt1->addItem(
"sintheta",m_sintheta);
47 status = m_nt1->addItem(
"costheta",m_costheta);
48 status = m_nt1->addItem(
"charge",m_charge);
49 status = m_nt1->addItem(
"runNO",m_runNO);
50 status = m_nt1->addItem(
"runFlag",m_runFlag);
51 status = m_nt1->addItem(
"evtNO",m_evtNO);
52 status = m_nt1->addItem(
"t0",m_t0);
53 status = m_nt1->addItem(
"trackId",m_trackId);
54 status = m_nt1->addItem(
"poca_x",m_poca_x);
55 status = m_nt1->addItem(
"poca_y",m_poca_y);
56 status = m_nt1->addItem(
"poca_z",m_poca_z);
57 status = m_nt1->addItem(
"recalg",m_recalg);
58 status = m_nt1->addItem(
"nhit",m_nhit);
59 status = m_nt1->addItem(
"nhits",m_nhits);
60 status = m_nt1->addItem(
"usedhit",m_usedhit);
62 status = m_nt1->addItem(
"ndedxhit",m_nphlisthit,0,100);
63 status = m_nt1->addIndexedItem(
"dEdx_hit",m_nphlisthit,m_dEdx_hit);
64 status = m_nt1->addIndexedItem(
"pathlength_hit",m_nphlisthit,m_pathlength_hit);
65 status = m_nt1->addIndexedItem(
"wid_hit",m_nphlisthit,m_wid_hit);
66 status = m_nt1->addIndexedItem(
"layid_hit",m_nphlisthit,m_layid_hit);
67 status = m_nt1->addIndexedItem(
"dd_in_hit",m_nphlisthit,m_dd_in_hit);
68 status = m_nt1->addIndexedItem(
"eangle_hit",m_nphlisthit,m_eangle_hit);
69 status = m_nt1->addIndexedItem(
"zhit_hit",m_nphlisthit,m_zhit_hit);
72 status = m_nt1->addItem(
"dEdx_meas", m_dEdx_meas);
76 status = m_nt1->addItem(
"type",m_parttype);
77 status = m_nt1->addItem(
"chidedx_e",m_chidedxe);
78 status = m_nt1->addItem(
"chidedx_mu",m_chidedxmu);
79 status = m_nt1->addItem(
"chidedx_pi",m_chidedxpi);
80 status = m_nt1->addItem(
"chidedx_k",m_chidedxk);
81 status = m_nt1->addItem(
"chidedx_p",m_chidedxp);
82 status = m_nt1->addItem(
"partid",5,m_probpid);
83 status = m_nt1->addItem(
"expectid",5,m_expectid);
84 status = m_nt1->addItem(
"sigmaid",5,m_sigmaid);
88 NTuplePtr nt2(
ntupleSvc(),
"FILE100/n102");
89 if ( nt2 ) m_nt2 = nt2;
92 m_nt2=
ntupleSvc()->book(
"FILE100/n102",CLID_RowWiseTuple,
"dE/dx per hit");
95 status = m_nt2->addItem(
"charge",m_charge1);
96 status = m_nt2->addItem(
"adc_raw",m_phraw);
97 status = m_nt2->addItem(
"exraw",m_exraw);
98 status = m_nt2->addItem(
"runNO",m_runNO1);
99 status = m_nt2->addItem(
"runFlag",m_runFlag1);
100 status = m_nt2->addItem(
"wire",m_wire);
101 status = m_nt2->addItem(
"doca_in",m_doca_in);
102 status = m_nt2->addItem(
"doca_ex",m_doca_ex);
103 status = m_nt2->addItem(
"driftdist",m_driftdist);
104 status = m_nt2->addItem(
"eangle",m_eangle);
105 status = m_nt2->addItem(
"zhit",m_zhit);
106 status = m_nt2->addItem(
"costheta1",m_costheta1);
107 status = m_nt2->addItem(
"path_rphi",m_pathL);
108 status = m_nt2->addItem(
"layer",m_layer);
109 status = m_nt2->addItem(
"ptrk1",m_ptrk1);
110 status = m_nt2->addItem(
"ptrk_hit",m_ptrk_hit);
111 status = m_nt2->addItem(
"t01",m_t01);
112 status = m_nt2->addItem(
"tdc_raw",m_tdc_raw);
113 status = m_nt2->addItem(
"driftT",m_driftT);
114 status = m_nt2->addItem(
"localwid",m_localwid);
115 status = m_nt2->addItem(
"trackId1",m_trackId1);
122 MsgStream log(
msgSvc(), name());
123 log << MSG::INFO <<
"DedxCalibEvent::genNtuple()" << endreq;
125 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
128 log << MSG::INFO <<
"Could not find Event Header" << endreq;
131 int eventNO = eventHeader->eventNumber();
132 int runNO = eventHeader->runNumber();
133 log << MSG::INFO <<
"now begin the event: runNO= "<<runNO<<
" eventNO= "<< eventNO<< endreq;
136 if(runNO<
RUN0) runFlag =0;
137 if(runNO>=
RUN1 && runNO<
RUN2) runFlag =1;
138 if(runNO>=
RUN2 && runNO<
RUN3) runFlag =2;
139 if(runNO>=
RUN3 && runNO<
RUN4) runFlag =3;
140 if(runNO>=
RUN4 && runNO<
RUN5) runFlag =4;
141 if(runNO>=
RUN5 && runNO<
RUN6) runFlag =5;
142 if(runNO>=
RUN6 && runNO<
RUN7) runFlag =6;
143 if(runNO>=
RUN7) runFlag =7;
147 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
148 if( (!aevtimeCol) || (aevtimeCol->size()==0) ){
152 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
153 for(; iter_evt!=aevtimeCol->end(); iter_evt++){
154 tes = (*iter_evt)->getTest();
155 esTimeflag = (*iter_evt)->getStat();
158 if(runFlag ==2) {
if( tes>1000 )
return;}
159 else if(runFlag ==3 ){
if (tes>700 )
return;}
160 else {
if (tes>1400 )
return;}
162 SmartDataPtr<RecMdcDedxCol> newexCol(eventSvc(),
"/Event/Recon/RecMdcDedxCol");
165 log << MSG::FATAL <<
"Could not find RecMdcDedxCol" << endreq;
172 double db=0,dz=0,pt0=0,charge0=0;
173 for(RecMdcDedxCol::iterator it = newexCol->begin(); it != newexCol->end(); it++)
176 if((*it)->getMdcKalTrack())
187 else if((*it)->getMdcTrack())
195 pt0 = fabs(1.0/a[2]);
196 charge0 = ( a[2] > 0 )? 1 : -1;
199 if(fabs(dz) >=
VZ0CUT)
continue;
200 if(db >=
VR0CUT)
continue;
203 iGood.push_back((*it)->trackId());
209 if(iGood.size()!=2 || nCharge!=0 )
return;
214 double poca_x=0,poca_y=0,poca_z=0;
215 float sintheta=0,costheta=0,ptrk=0,ptrk_t=0,charge=0,trackId=0;
216 int Nhit=0,usedhit=0,Nhits=0,Nphlisthit=0;
217 double dEdx_meas_hit=0, dEdx_meas=0,dEdx_meas_esat=0,dEdx_meas_norun=0;
218 double dEdx_hit[100]={0},pathlength_hit[100]={0},wid_hit[100]={0},layid_hit[100]={0},dd_in_hit[100]={0},eangle_hit[100]={0},zhit_hit[100]={0};
222 for(RecMdcDedxCol::iterator it = newexCol->begin(); it != newexCol->end(); it++)
226 for(
int i = 0; i < iGood.size(); i++)
228 if((*it)->trackId()==iGood[i]) flag=
true;
230 if(flag==
false)
continue;
234 if((*it)->getMdcKalTrack())
237 poca_x = (*it)->getMdcKalTrack()->x();
238 poca_y = (*it)->getMdcKalTrack()->y();
239 poca_z = (*it)->getMdcKalTrack()->z();
255 else if((*it)->getMdcTrack())
257 poca_x = (*it)->getMdcTrack()->x();
258 poca_y = (*it)->getMdcTrack()->y();
259 poca_z = (*it)->getMdcTrack()->z();
267 sintheta =
sin(M_PI_2 - atan(a[4]));
268 costheta =
cos(M_PI_2 - atan(a[4]));
269 ptrk_t = 1.0/fabs( a[2] );
270 ptrk = ptrk_t*sqrt(1 + a[4]*a[4]);
271 charge = ( a[2] > 0 )? 1 : -1;
273 Nhit = (*it)->numTotalHits();
274 Nhits = ((*it)->getVecDedxHits()).size();
275 usedhit = (*it)->numGoodHits();
276 trk_recalg = (*it)->status();
277 trackId = (*it)->trackId();
281 if(runFlag ==3 &&(ptrk>1.88 || ptrk<1.80))
continue;
282 if(runFlag ==4 &&(ptrk>1.72 || ptrk<1.45))
continue;
283 if(runFlag ==5 &&(ptrk>2.00 || ptrk<1.70))
continue;
284 if(runFlag ==6 &&(ptrk>1.90 || ptrk<1.00))
continue;
285 if(runFlag ==7 &&(ptrk>1.90 || ptrk<1.40))
continue;
286 if(
abs(costheta)>0.9)
continue;
288 if(Nhit<20)
continue;
289 if(usedhit<6)
continue;
293 int layid=0,localwid=0,w0id=0,wid=0,lr=0;
294 double p_hit=0,adc_raw=0,tdc_raw=0,zhit=0,driftd=0,driftD=0,driftT=0,dd_in=0,dd_ex=0,eangle=0;
295 double ph=0,pathlength=0,rphi_path=0;
299 DedxHitRefVec::iterator it_gothit = gothits.begin();
300 for(;it_gothit!=gothits.end(); it_gothit++)
303 if((*it_gothit)->isMdcHitValid())
305 RecMdcHit* itor = (*it_gothit)->getMdcHit();
310 wid = w0id + localwid;
316 if(lr == 2) cout<<
"lr = "<<lr<<endl;
319 driftd =
abs(driftD);
322 if(lr == 0 || lr == 2 ) {dd_in = -
abs(dd_in);dd_ex = -
abs(dd_ex);}
323 if(lr == 1 ) {dd_in =
abs(dd_in);dd_ex =
abs(dd_ex);}
326 eangle = eangle/
M_PI;
328 else if((*it_gothit)->isMdcKalHelixSegValid())
332 p_hit = 1.0/fabs(a_hit_in(3))*sqrt(1+a_hit_in(5)*a_hit_in(5));
338 wid = w0id + localwid;
344 if(lr == 2) cout<<
"lr = "<<lr<<endl;
345 driftD = itor->
getDD();
346 driftd =
abs(driftD);
347 driftT = itor->
getDT();
350 if(lr==-1 || lr == 2) {dd_in = dd_in; dd_ex = dd_ex;}
351 else if(lr ==1) {dd_in = -dd_in; dd_ex = -dd_ex;}
353 eangle = eangle/
M_PI;
357 pathlength=(*it_gothit)->getPathLength();
358 rphi_path=pathlength*sintheta;
359 ph = (*it_gothit)->getDedx();
363 pathlength_hit[k]=pathlength;
367 eangle_hit[k]=eangle;
380 m_localwid = localwid;
383 m_runFlag1 = runFlag;
386 m_driftdist = driftD;
389 m_costheta1 = costheta;
390 m_pathL = pathlength;
394 m_trackId1 = trackId;
396 StatusCode status = m_nt2->write();
397 if ( status.isFailure() )
398 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
402 dEdx_meas = (*it)->probPH();
404 dEdx_meas_esat = (*it)->getDedxEsat();
405 dEdx_meas_norun = (*it)->getDedxNoRun();
406 dEdx_meas_hit = (*it)->getDedxHit();
423 m_recalg = trk_recalg;
427 m_nphlisthit=Nphlisthit;
429 for(
int j=0; j<Nphlisthit; j++)
431 m_dEdx_hit[j]=dEdx_hit[j];
432 m_pathlength_hit[j]=pathlength_hit[j];
433 m_wid_hit[j]=wid_hit[j];
434 m_layid_hit[j]=layid_hit[j];
435 m_dd_in_hit[j]=dd_in_hit[j];
436 m_eangle_hit[j]=eangle_hit[j];
437 m_zhit_hit[j]=zhit_hit[j];
441 m_dEdx_meas = dEdx_meas;
445 m_parttype = (*it)->particleId();
446 m_chidedxe=(*it)->chiE();
447 m_chidedxmu=(*it)->chiMu();
448 m_chidedxpi=(*it)->chiPi();
449 m_chidedxk=(*it)->chiK();
450 m_chidedxp=(*it)->chiP();
453 m_probpid[i]= (*it)->getPidProb(i);
454 m_expectid[i]= (*it)->getDedxExpect(i);
455 m_sigmaid[i]= (*it)->getSigmaDedx(i);
457 StatusCode status = m_nt1->write();
458 if ( status.isFailure() )
460 log << MSG::ERROR <<
"Cannot fill Ntuple n103" << endreq;