1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/StatusCode.h"
3#include "GaudiKernel/INTupleSvc.h"
4#include "GaudiKernel/SmartDataPtr.h"
30using CLHEP::HepVector;
35 declareProperty(
"CutWire", cut_wire=-1);
36 declareProperty(
"Count", m_count=1000000);
37 declareProperty(
"Gap", m_gap=1);
43 MsgStream log(
msgSvc(), name());
44 log << MSG::INFO <<
"DedxCalibEvent::initializing()" << endreq;
47 NTuplePtr nt1(
ntupleSvc(),
"FILE100/n103");
52 m_nt1=
ntupleSvc()->book(
"FILE100/n103",CLID_ColumnWiseTuple,
"dEdx per track");
55 status = m_nt1->addItem(
"ptrk",m_ptrk);
56 status = m_nt1->addItem(
"ptrk_t",m_ptrk_t);
57 status = m_nt1->addItem(
"sintheta",m_sintheta);
58 status = m_nt1->addItem(
"costheta",m_costheta);
59 status = m_nt1->addItem(
"charge",m_charge);
60 status = m_nt1->addItem(
"runNO",m_runNO);
61 status = m_nt1->addItem(
"runFlag",m_runFlag);
62 status = m_nt1->addItem(
"evtNO",m_evtNO);
63 status = m_nt1->addItem(
"t0",m_t0);
64 status = m_nt1->addItem(
"trackId",m_trackId);
65 status = m_nt1->addItem(
"poca_x",m_poca_x);
66 status = m_nt1->addItem(
"poca_y",m_poca_y);
67 status = m_nt1->addItem(
"poca_z",m_poca_z);
68 status = m_nt1->addItem(
"recalg",m_recalg);
69 status = m_nt1->addItem(
"nhit",m_nhit);
70 status = m_nt1->addItem(
"nhits",m_nhits);
71 status = m_nt1->addItem(
"usedhit",m_usedhit);
73 status = m_nt1->addItem(
"ndedxhit",m_nphlisthit,0,100);
74 status = m_nt1->addIndexedItem(
"dEdx_hit",m_nphlisthit,m_dEdx_hit);
75 status = m_nt1->addIndexedItem(
"pathlength_hit",m_nphlisthit,m_pathlength_hit);
76 status = m_nt1->addIndexedItem(
"wid_hit",m_nphlisthit,m_wid_hit);
77 status = m_nt1->addIndexedItem(
"layid_hit",m_nphlisthit,m_layid_hit);
78 status = m_nt1->addIndexedItem(
"dd_in_hit",m_nphlisthit,m_dd_in_hit);
79 status = m_nt1->addIndexedItem(
"eangle_hit",m_nphlisthit,m_eangle_hit);
80 status = m_nt1->addIndexedItem(
"zhit_hit",m_nphlisthit,m_zhit_hit);
83 status = m_nt1->addItem(
"dEdx_meas", m_dEdx_meas);
87 status = m_nt1->addItem(
"type",m_parttype);
88 status = m_nt1->addItem(
"chidedx_e",m_chidedxe);
89 status = m_nt1->addItem(
"chidedx_mu",m_chidedxmu);
90 status = m_nt1->addItem(
"chidedx_pi",m_chidedxpi);
91 status = m_nt1->addItem(
"chidedx_k",m_chidedxk);
92 status = m_nt1->addItem(
"chidedx_p",m_chidedxp);
93 status = m_nt1->addItem(
"partid",5,m_probpid);
94 status = m_nt1->addItem(
"expectid",5,m_expectid);
95 status = m_nt1->addItem(
"sigmaid",5,m_sigmaid);
99 NTuplePtr nt2(
ntupleSvc(),
"FILE100/n102");
100 if ( nt2 ) m_nt2 = nt2;
103 m_nt2=
ntupleSvc()->book(
"FILE100/n102",CLID_RowWiseTuple,
"dE/dx per hit");
106 status = m_nt2->addItem(
"charge",m_charge1);
107 status = m_nt2->addItem(
"adc_raw",m_phraw);
108 status = m_nt2->addItem(
"exraw",m_exraw);
109 status = m_nt2->addItem(
"runNO",m_runNO1);
110 status = m_nt2->addItem(
"evtNO",m_evtNO1);
111 status = m_nt2->addItem(
"runFlag",m_runFlag1);
112 status = m_nt2->addItem(
"wire",m_wire);
113 status = m_nt2->addItem(
"doca_in",m_doca_in);
114 status = m_nt2->addItem(
"doca_ex",m_doca_ex);
115 status = m_nt2->addItem(
"driftdist",m_driftdist);
116 status = m_nt2->addItem(
"eangle",m_eangle);
117 status = m_nt2->addItem(
"zhit",m_zhit);
118 status = m_nt2->addItem(
"costheta1",m_costheta1);
119 status = m_nt2->addItem(
"path_rphi",m_pathL);
120 status = m_nt2->addItem(
"layer",m_layer);
121 status = m_nt2->addItem(
"ptrk1",m_ptrk1);
122 status = m_nt2->addItem(
"ptrk_hit",m_ptrk_hit);
123 status = m_nt2->addItem(
"t01",m_t01);
124 status = m_nt2->addItem(
"tdc_raw",m_tdc_raw);
125 status = m_nt2->addItem(
"driftT",m_driftT);
126 status = m_nt2->addItem(
"localwid",m_localwid);
127 status = m_nt2->addItem(
"trackId1",m_trackId1);
134 MsgStream log(
msgSvc(), name());
135 log << MSG::INFO <<
"DedxCalibEvent::genNtuple()" << endreq;
137 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
140 log << MSG::INFO <<
"Could not find Event Header" << endreq;
143 int eventNO = eventHeader->eventNumber();
144 int runNO = eventHeader->runNumber();
156 log << MSG::INFO <<
"now begin the event: runNO= "<<runNO<<
" eventNO= "<< eventNO<< endreq;
159 if(runNO<
RUN0) runFlag =0;
160 if(runNO>=
RUN1 && runNO<
RUN2) runFlag =1;
161 if(runNO>=
RUN2 && runNO<
RUN3) runFlag =2;
162 if(runNO>=
RUN3 && runNO<
RUN4) runFlag =3;
163 if(runNO>=
RUN4 && runNO<
RUN5) runFlag =4;
164 if(runNO>=
RUN5 && runNO<
RUN6) runFlag =5;
165 if(runNO>=
RUN6 && runNO<
RUN7) runFlag =6;
166 if(runNO>=
RUN7) runFlag =7;
170 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
171 if( (!aevtimeCol) || (aevtimeCol->size()==0) ){
175 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
176 for(; iter_evt!=aevtimeCol->end(); iter_evt++){
177 tes = (*iter_evt)->getTest();
178 esTimeflag = (*iter_evt)->getStat();
181 if(runFlag ==2) {
if( tes>1000 )
return;}
182 else if(runFlag ==3 ){
if (tes>700 )
return;}
183 else {
if (tes>1400 )
return;}
185 SmartDataPtr<EvtRecEvent>evtRecEvent(eventSvc(),
"/Event/EvtRec/EvtRecEvent");
187 log << MSG::ERROR <<
"EvtRecEvent not found" << endreq;
191 SmartDataPtr<EvtRecTrackCol>
192 evtRecTrkCol(eventSvc(),
"/Event/EvtRec/EvtRecTrackCol");
194 log << MSG::ERROR <<
"EvtRecTrackCol" << endreq;
202 double db=0,dz=0,pt0=0,charge0=0;
203 for(
int i = 0; i < evtRecEvent->totalCharged(); i++){
211 if((*itTrk)->isMdcKalTrackValid())
222 else if((*itTrk)->isMdcTrackValid())
230 pt0 = fabs(1.0/a[2]);
231 charge0 = ( a[2] > 0 )? 1 : -1;
234 if(fabs(dz) >=
VZ0CUT)
continue;
235 if(db >=
VR0CUT)
continue;
238 iGood.push_back(it->
trackId());
243 double poca_x=0,poca_y=0,poca_z=0;
245 int Nhit=0,usedhit=0,Nhits=0,Nphlisthit=0;
246 double dEdx_meas_hit=0,
dEdx_meas=0,dEdx_meas_esat=0,dEdx_meas_norun=0;
247 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};
251 for(
int i = 0; i < evtRecEvent->totalCharged(); i++){
256 for(
unsigned int i = 0; i < iGood.size(); i++)
260 if(
flag==
false)
continue;
264 if((*itTrk)->isMdcKalTrackValid())
283 else if((*itTrk)->isMdcTrackValid())
295 sintheta =
sin(M_PI_2 - atan(a[4]));
297 ptrk_t = 1.0/fabs( a[2] );
298 ptrk = ptrk_t*sqrt(1 + a[4]*a[4]);
299 charge = ( a[2] > 0 )? 1 : -1;
304 trk_recalg = it->
status();
309 if(runFlag ==3 &&(
ptrk>1.88 ||
ptrk<1.80))
continue;
310 if(runFlag ==4 &&(
ptrk>1.72 ||
ptrk<1.45))
continue;
311 if(runFlag ==5 &&(
ptrk>2.00 ||
ptrk<1.70))
continue;
312 if(runFlag ==6 &&(
ptrk>1.90 ||
ptrk<1.00))
continue;
313 if(runFlag ==7 &&(
ptrk>1.90 ||
ptrk<0.90))
continue;
316 if(Nhit<20)
continue;
317 if(usedhit<6)
continue;
321 int layid=0,localwid=0,w0id=0,wid=0,lr=0;
322 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;
323 double ph=0,pathlength=0,rphi_path=0;
327 DedxHitRefVec::iterator it_gothit = gothits.begin();
328 for(;it_gothit!=gothits.end(); it_gothit++)
330 if((*it_gothit)->isMdcHitValid())
332 RecMdcHit* itor = (*it_gothit)->getMdcHit();
337 wid = w0id + localwid;
343 if(lr == 2) cout<<
"lr = "<<lr<<endl;
346 driftd =
abs(driftD);
349 if(lr == 0 || lr == 2 ) {dd_in = -
abs(dd_in);dd_ex = -
abs(dd_ex);}
350 if(lr == 1 ) {dd_in =
abs(dd_in);dd_ex =
abs(dd_ex);}
353 eangle = eangle/
M_PI;
355 else if((*it_gothit)->isMdcKalHelixSegValid())
359 p_hit = 1.0/fabs(a_hit_in(3))*sqrt(1+a_hit_in(5)*a_hit_in(5));
365 wid = w0id + localwid;
371 if(lr == 2) cout<<
"lr = "<<lr<<endl;
372 driftD = itor->
getDD();
373 driftd =
abs(driftD);
374 driftT = itor->
getDT();
377 if(lr==-1 || lr == 2) {dd_in = dd_in; dd_ex = dd_ex;}
378 else if(lr ==1) {dd_in = -dd_in; dd_ex = -dd_ex;}
380 eangle = eangle/
M_PI;
384 pathlength=(*it_gothit)->getPathLength();
385 rphi_path=pathlength*sintheta;
386 ph = (*it_gothit)->getDedx();
390 pathlength_hit[k]=pathlength;
394 eangle_hit[k]=eangle;
407 m_localwid = localwid;
411 m_runFlag1 = runFlag;
414 m_driftdist = driftD;
418 m_pathL = pathlength;
422 m_trackId1 = trackId;
425 else status = m_nt2->write();
426 if ( status.isFailure() )
427 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
450 m_recalg = trk_recalg;
454 m_nphlisthit=Nphlisthit;
456 for(
int j=0; j<Nphlisthit; j++)
459 m_pathlength_hit[j]=pathlength_hit[j];
460 m_wid_hit[j]=wid_hit[j];
461 m_layid_hit[j]=layid_hit[j];
462 m_dd_in_hit[j]=dd_in_hit[j];
463 m_eangle_hit[j]=eangle_hit[j];
464 m_zhit_hit[j]=zhit_hit[j];
473 m_chidedxe=it->
chiE();
474 m_chidedxmu=it->
chiMu();
475 m_chidedxpi=it->
chiPi();
476 m_chidedxk=it->
chiK();
477 m_chidedxp=it->
chiP();
485 if(
cut_wire<0) status = m_nt1->write();
486 if ( status.isFailure() )
488 log << MSG::ERROR <<
"Cannot fill Ntuple n103" << endreq;
double sin(const BesAngle a)
double cos(const BesAngle a)
static int evt_threshold(0)
EvtRecTrackCol::iterator EvtRecTrackIterator
SmartRefVector< RecMdcDedxHit > DedxHitRefVec
const HepVector & getZHelix(const int pid) const
const HepSymMatrix & getFError(const int pid) const
const HepVector & getFHelix(const int pid) const
const HepSymMatrix err() const
const HepVector helix() const
......
virtual const MdcGeoLayer *const Layer(unsigned id)=0
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
RecMdcKalTrack * getMdcKalTrack(void)
double getDedxNoRun(void)
DedxHitRefVec getVecDedxHits() const
double getPidProb(int pid) const
RecMdcTrack * getMdcTrack(void)
double getSigmaDedx(int pid) const
double getDedxExpect(int pid) const
const int getFlagLR(void) const
const double getZhit(void) const
const double getAdc(void) const
const Identifier getMdcId(void) const
const double getTdc(void) const
const double getDriftDistRight(void) const
const double getDriftT(void) const
const double getEntra(void) const
const double getDriftDistLeft(void) const
const double getDoca(void) const
Identifier getMdcId(void) const
int getFlagLR(void) const
HepVector & getHelixIncl(void)
double getEntra(void) const
double getDocaIncl(void) const
double getDocaExcl(void) const
double getTdc(void) const
double getZhit(void) const
double getAdc(void) const
const HepVector & getZHelix() const
const HepSymMatrix & getFError() const
const HepVector & getFHelix() const