1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/StatusCode.h"
3#include "GaudiKernel/INTupleSvc.h"
4#include "GaudiKernel/SmartDataPtr.h"
6#include "EventModel/EventHeader.h"
7#include "EvTimeEvent/RecEsTime.h"
8#include "MdcRecEvent/RecMdcHit.h"
9#include "MdcRecEvent/RecMdcTrack.h"
10#include "MdcRecEvent/RecMdcKalTrack.h"
11#include "MdcRecEvent/RecMdcKalHelixSeg.h"
12#include "MdcRecEvent/RecMdcDedx.h"
13#include "MdcRecEvent/RecMdcDedxHit.h"
14#include "Identifier/Identifier.h"
15#include "Identifier/MdcID.h"
17#include "EventModel/EventModel.h"
18#include "EventModel/Event.h"
19#include "EvtRecEvent/EvtRecEvent.h"
20#include "EvtRecEvent/EvtRecTrack.h"
24#include "DedxCalibAlg/DedxCalibEvent.h"
26typedef std::vector<int>
Vint;
29using CLHEP::HepVector;
34 declareProperty(
"CutWire",
cut_wire=-1);
35 declareProperty(
"Count",
m_count=1000000);
36 declareProperty(
"Gap",
m_gap=1);
42 MsgStream log(
msgSvc(), name());
43 log << MSG::INFO <<
"DedxCalibEvent::initializing()" << endreq;
46 NTuplePtr nt1(
ntupleSvc(),
"FILE100/n103");
51 m_nt1=
ntupleSvc()->book(
"FILE100/n103",CLID_ColumnWiseTuple,
"dEdx per track");
54 status = m_nt1->addItem(
"ptrk",m_ptrk);
55 status = m_nt1->addItem(
"ptrk_t",m_ptrk_t);
56 status = m_nt1->addItem(
"sintheta",m_sintheta);
57 status = m_nt1->addItem(
"costheta",m_costheta);
58 status = m_nt1->addItem(
"charge",m_charge);
59 status = m_nt1->addItem(
"runNO",m_runNO);
60 status = m_nt1->addItem(
"runFlag",m_runFlag);
61 status = m_nt1->addItem(
"evtNO",m_evtNO);
62 status = m_nt1->addItem(
"t0",m_t0);
63 status = m_nt1->addItem(
"trackId",m_trackId);
64 status = m_nt1->addItem(
"poca_x",m_poca_x);
65 status = m_nt1->addItem(
"poca_y",m_poca_y);
66 status = m_nt1->addItem(
"poca_z",m_poca_z);
67 status = m_nt1->addItem(
"recalg",m_recalg);
68 status = m_nt1->addItem(
"nhit",m_nhit);
69 status = m_nt1->addItem(
"nhits",m_nhits);
70 status = m_nt1->addItem(
"usedhit",m_usedhit);
72 status = m_nt1->addItem(
"ndedxhit",m_nphlisthit,0,100);
73 status = m_nt1->addIndexedItem(
"dEdx_hit",m_nphlisthit,m_dEdx_hit);
74 status = m_nt1->addIndexedItem(
"pathlength_hit",m_nphlisthit,m_pathlength_hit);
75 status = m_nt1->addIndexedItem(
"wid_hit",m_nphlisthit,m_wid_hit);
76 status = m_nt1->addIndexedItem(
"layid_hit",m_nphlisthit,m_layid_hit);
77 status = m_nt1->addIndexedItem(
"dd_in_hit",m_nphlisthit,m_dd_in_hit);
78 status = m_nt1->addIndexedItem(
"eangle_hit",m_nphlisthit,m_eangle_hit);
79 status = m_nt1->addIndexedItem(
"zhit_hit",m_nphlisthit,m_zhit_hit);
82 status = m_nt1->addItem(
"dEdx_meas", m_dEdx_meas);
86 status = m_nt1->addItem(
"type",m_parttype);
87 status = m_nt1->addItem(
"chidedx_e",m_chidedxe);
88 status = m_nt1->addItem(
"chidedx_mu",m_chidedxmu);
89 status = m_nt1->addItem(
"chidedx_pi",m_chidedxpi);
90 status = m_nt1->addItem(
"chidedx_k",m_chidedxk);
91 status = m_nt1->addItem(
"chidedx_p",m_chidedxp);
92 status = m_nt1->addItem(
"partid",5,m_probpid);
93 status = m_nt1->addItem(
"expectid",5,m_expectid);
94 status = m_nt1->addItem(
"sigmaid",5,m_sigmaid);
98 NTuplePtr nt2(
ntupleSvc(),
"FILE100/n102");
99 if ( nt2 ) m_nt2 = nt2;
102 m_nt2=
ntupleSvc()->book(
"FILE100/n102",CLID_RowWiseTuple,
"dE/dx per hit");
105 status = m_nt2->addItem(
"charge",m_charge1);
106 status = m_nt2->addItem(
"adc_raw",m_phraw);
107 status = m_nt2->addItem(
"exraw",m_exraw);
108 status = m_nt2->addItem(
"runNO",m_runNO1);
109 status = m_nt2->addItem(
"evtNO",m_evtNO1);
110 status = m_nt2->addItem(
"runFlag",m_runFlag1);
111 status = m_nt2->addItem(
"wire",m_wire);
112 status = m_nt2->addItem(
"doca_in",m_doca_in);
113 status = m_nt2->addItem(
"doca_ex",m_doca_ex);
114 status = m_nt2->addItem(
"driftdist",m_driftdist);
115 status = m_nt2->addItem(
"eangle",m_eangle);
116 status = m_nt2->addItem(
"zhit",m_zhit);
117 status = m_nt2->addItem(
"costheta1",m_costheta1);
118 status = m_nt2->addItem(
"path_rphi",m_pathL);
119 status = m_nt2->addItem(
"layer",m_layer);
120 status = m_nt2->addItem(
"ptrk1",m_ptrk1);
121 status = m_nt2->addItem(
"ptrk_hit",m_ptrk_hit);
122 status = m_nt2->addItem(
"t01",m_t01);
123 status = m_nt2->addItem(
"tdc_raw",m_tdc_raw);
124 status = m_nt2->addItem(
"driftT",m_driftT);
125 status = m_nt2->addItem(
"localwid",m_localwid);
126 status = m_nt2->addItem(
"trackId1",m_trackId1);
133 MsgStream log(
msgSvc(), name());
134 log << MSG::INFO <<
"DedxCalibEvent::genNtuple()" << endreq;
136 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
139 log << MSG::INFO <<
"Could not find Event Header" << endreq;
142 int eventNO = eventHeader->eventNumber();
143 int runNO = eventHeader->runNumber();
155 log << MSG::INFO <<
"now begin the event: runNO= "<<runNO<<
" eventNO= "<< eventNO<< endreq;
158 if(runNO<
RUN0) runFlag =0;
159 if(runNO>=
RUN1 && runNO<
RUN2) runFlag =1;
160 if(runNO>=
RUN2 && runNO<
RUN3) runFlag =2;
161 if(runNO>=
RUN3 && runNO<
RUN4) runFlag =3;
162 if(runNO>=
RUN4 && runNO<
RUN5) runFlag =4;
163 if(runNO>=
RUN5 && runNO<
RUN6) runFlag =5;
164 if(runNO>=
RUN6 && runNO<
RUN7) runFlag =6;
165 if(runNO>=
RUN7) runFlag =7;
169 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
170 if( (!aevtimeCol) || (aevtimeCol->size()==0) ){
174 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
175 for(; iter_evt!=aevtimeCol->end(); iter_evt++){
176 tes = (*iter_evt)->getTest();
177 esTimeflag = (*iter_evt)->getStat();
180 if(runFlag ==2) {
if( tes>1000 )
return;}
181 else if(runFlag ==3 ){
if (tes>700 )
return;}
182 else {
if (tes>1400 )
return;}
184 SmartDataPtr<EvtRecEvent>evtRecEvent(eventSvc(),
"/Event/EvtRec/EvtRecEvent");
186 log << MSG::ERROR <<
"EvtRecEvent not found" << endreq;
190 SmartDataPtr<EvtRecTrackCol>
191 evtRecTrkCol(eventSvc(),
"/Event/EvtRec/EvtRecTrackCol");
193 log << MSG::ERROR <<
"EvtRecTrackCol" << endreq;
201 double db=0,dz=0,pt0=0,charge0=0;
202 for(
int i = 0; i < evtRecEvent->totalCharged(); i++){
210 if((*itTrk)->isMdcKalTrackValid())
221 else if((*itTrk)->isMdcTrackValid())
229 pt0 = fabs(1.0/a[2]);
230 charge0 = ( a[2] > 0 )? 1 : -1;
233 if(fabs(dz) >=
VZ0CUT)
continue;
234 if(db >=
VR0CUT)
continue;
237 iGood.push_back(it->
trackId());
242 double poca_x=0,poca_y=0,poca_z=0;
244 int Nhit=0,usedhit=0,Nhits=0,Nphlisthit=0;
245 double dEdx_meas_hit=0,
dEdx_meas=0,dEdx_meas_esat=0,dEdx_meas_norun=0;
246 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};
250 for(
int i = 0; i < evtRecEvent->totalCharged(); i++){
255 for(
unsigned int i = 0; i < iGood.size(); i++)
259 if(
flag==
false)
continue;
263 if((*itTrk)->isMdcKalTrackValid())
282 else if((*itTrk)->isMdcTrackValid())
294 sintheta =
sin(M_PI_2 - atan(a[4]));
296 ptrk_t = 1.0/fabs( a[2] );
297 ptrk = ptrk_t*sqrt(1 + a[4]*a[4]);
298 charge = ( a[2] > 0 )? 1 : -1;
303 trk_recalg = it->
status();
308 if(runFlag ==3 &&(
ptrk>1.88 ||
ptrk<1.80))
continue;
309 if(runFlag ==4 &&(
ptrk>1.72 ||
ptrk<1.45))
continue;
310 if(runFlag ==5 &&(
ptrk>2.00 ||
ptrk<1.70))
continue;
311 if(runFlag ==6 &&(
ptrk>1.90 ||
ptrk<1.00))
continue;
312 if(runFlag ==7 &&(
ptrk>1.90 ||
ptrk<0.90))
continue;
315 if(Nhit<20)
continue;
316 if(usedhit<6)
continue;
320 int layid=0,localwid=0,w0id=0,wid=0,lr=0;
321 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;
322 double ph=0,pathlength=0,rphi_path=0;
326 DedxHitRefVec::iterator it_gothit = gothits.begin();
327 for(;it_gothit!=gothits.end(); it_gothit++)
329 if((*it_gothit)->isMdcHitValid())
331 RecMdcHit* itor = (*it_gothit)->getMdcHit();
336 wid = w0id + localwid;
342 if(lr == 2) cout<<
"lr = "<<lr<<endl;
345 driftd =
abs(driftD);
348 if(lr == 0 || lr == 2 ) {dd_in = -
abs(dd_in);dd_ex = -
abs(dd_ex);}
349 if(lr == 1 ) {dd_in =
abs(dd_in);dd_ex =
abs(dd_ex);}
352 eangle = eangle/
M_PI;
354 else if((*it_gothit)->isMdcKalHelixSegValid())
358 p_hit = 1.0/fabs(a_hit_in(3))*sqrt(1+a_hit_in(5)*a_hit_in(5));
364 wid = w0id + localwid;
370 if(lr == 2) cout<<
"lr = "<<lr<<endl;
371 driftD = itor->
getDD();
372 driftd =
abs(driftD);
373 driftT = itor->
getDT();
376 if(lr==-1 || lr == 2) {dd_in = dd_in; dd_ex = dd_ex;}
377 else if(lr ==1) {dd_in = -dd_in; dd_ex = -dd_ex;}
379 eangle = eangle/
M_PI;
383 pathlength=(*it_gothit)->getPathLength();
384 rphi_path=pathlength*sintheta;
385 ph = (*it_gothit)->getDedx();
389 pathlength_hit[k]=pathlength;
393 eangle_hit[k]=eangle;
406 m_localwid = localwid;
410 m_runFlag1 = runFlag;
413 m_driftdist = driftD;
417 m_pathL = pathlength;
421 m_trackId1 = trackId;
424 else status = m_nt2->write();
425 if ( status.isFailure() )
426 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
449 m_recalg = trk_recalg;
453 m_nphlisthit=Nphlisthit;
455 for(
int j=0; j<Nphlisthit; j++)
458 m_pathlength_hit[j]=pathlength_hit[j];
459 m_wid_hit[j]=wid_hit[j];
460 m_layid_hit[j]=layid_hit[j];
461 m_dd_in_hit[j]=dd_in_hit[j];
462 m_eangle_hit[j]=eangle_hit[j];
463 m_zhit_hit[j]=zhit_hit[j];
472 m_chidedxe=it->
chiE();
473 m_chidedxmu=it->
chiMu();
474 m_chidedxpi=it->
chiPi();
475 m_chidedxk=it->
chiK();
476 m_chidedxp=it->
chiP();
484 if(
cut_wire<0) status = m_nt1->write();
485 if ( status.isFailure() )
487 log << MSG::ERROR <<
"Cannot fill Ntuple n103" << endreq;
static int evt_threshold(0)
EvtRecTrackCol::iterator EvtRecTrackIterator
double sin(const BesAngle a)
double cos(const BesAngle a)
SmartRefVector< RecMdcDedxHit > DedxHitRefVec
DedxCalibEvent(const std::string &name, ISvcLocator *pSvcLocator)
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