11#include "GaudiKernel/MsgStream.h"
12#include "GaudiKernel/AlgFactory.h"
13#include "GaudiKernel/ISvcLocator.h"
14#include "GaudiKernel/SmartDataPtr.h"
15#include "GaudiKernel/IDataProviderSvc.h"
16#include "GaudiKernel/IDataManagerSvc.h"
17#include "GaudiKernel/PropertyMgr.h"
18#include "GaudiKernel/IHistogramSvc.h"
19#include "AIDA/IHistogramFactory.h"
20#include "GaudiKernel/INTupleSvc.h"
41using CLHEP::HepVector;
43extern "C" {
float prob_ (
float *,
int*);}
67 declareProperty(
"CalibFlag",calib_flag);
68 declareProperty(
"NTupleFlag",ntpFlag);
69 declareProperty(
"RecAlg",recalg);
70 declareProperty(
"ParticleType",ParticleFlag);
71 declareProperty(
"dEdxMethod",m_alg);
72 declareProperty(
"TruncRate",truncate);
73 declareProperty(
"RootFile",m_rootfile = std::string(
"no rootfile"));
79 MsgStream log(
msgSvc(), name());
80 log << MSG::INFO <<
"in initialize()" << endreq;
82 log << MSG::INFO <<
"--------------------< MdcDedxRecon V2.1 >---------------------"<< endreq;
83 log << MSG::INFO <<
"####### correction for the wire current dependence #######"<< endreq;
84 log << MSG::INFO <<
"####### correction for the new z dependence #######"<< endreq;
85 log << MSG::INFO <<
"-------------------------------------------------------------"<< endreq;
86 log << MSG::INFO <<
"++++++++++++++++++++[ initialization ]+++++++++++++++++++++"<< endreq;
87 log << MSG::INFO <<
"MdcDedxRecon has been initialized with calib_flag: "<< calib_flag <<endreq;
88 log << MSG::INFO <<
"MdcDedxRecon has been initialized with landau: "<< landau << endreq;
89 if( landau == 0 ) {truncate = 0.7;}
90 log << MSG::INFO <<
"MdcDedxRecon has been initialized with ntpFlag: "<< ntpFlag << endreq;
91 log << MSG::INFO <<
"MdcDedxRecon has been initialized with recalg: "<< recalg << endreq;
92 log << MSG::INFO <<
"MdcDedxRecon has been initialized with dE/dx cal method m_alg: "<< m_alg << endreq;
93 log << MSG::INFO <<
"MdcDedxRecon has been initialized with truncate: "<< truncate <<endreq;
94 log << MSG::INFO <<
"MdcDedxRecon has been initialized with doNewGlobal: "<<doNewGlobal<<endreq;
95 log << MSG::DEBUG <<
"+++++++++++ MdcDedxRecon initialization end ++++++++++++ "<< endreq;
96 if( truncate <= 0.0 || 1.0 < truncate )
98 log << MSG::FATAL <<
" Initialization ERROR of truncate = "<<truncate<< endreq;
99 log << MSG::FATAL <<
" truncate must be within 0.0 to 1.0 ! "<< endreq;
100 log << MSG::FATAL <<
" Please stop exec. "<< endreq;
102 log << MSG::DEBUG <<
"-------------------------------------------------------------"<< endreq;
103 log << MSG::DEBUG <<
"MdcDedxRecon init 2nd part!!!"<< endreq;
105 StatusCode scex = service(
"DedxCorrecSvc", exsvc);
106 if (scex == StatusCode::SUCCESS)
108 log << MSG::INFO <<
"Hi, DedxCorrectSvc is running"<<endreq;
112 log << MSG::ERROR <<
"DedxCorrectSvc is failed"<<endreq;
113 return StatusCode::SUCCESS;
117 StatusCode cursvc = service(
"DedxCurSvc", dedxcursvc);
118 if (cursvc == StatusCode::SUCCESS)
120 log << MSG::INFO <<
"DedxCurSvc is running"<<endreq;
124 log << MSG::ERROR <<
"DedxCurSvc is failed"<<endreq;
125 return StatusCode::SUCCESS;
135 if(m_rootfile!=
"no rootfile")
137 const char* preDir = gDirectory->GetPath();
138 m_hlist =
new TObjArray(0);
139 m_hitlevel =
new TFolder(
"dedx_hitlevel",
"hitlevel");
140 m_hlist ->
Add(m_hitlevel);
141 m_hitNo_wire =
new TH1F(
"dedx_HitNo_wire",
"dedx hitNo vs wire",6797, -0.5, 6796.5);
142 m_hitlevel ->
Add(m_hitNo_wire);
143 gDirectory->cd(preDir);
150 NTuplePtr nt1(
ntupleSvc(),
"FILE103/n103");
155 m_nt1=
ntupleSvc()->book(
"FILE103/n103",CLID_ColumnWiseTuple,
"dEdx vs momentum");
158 status = m_nt1->addItem(
"phtm",m_phtm);
166 status = m_nt1->addItem(
"dEdx_meas", m_dEdx_meas);
168 status = m_nt1->addItem(
"ptrk",m_ptrk);
169 status = m_nt1->addItem(
"sintheta",m_sintheta);
170 status = m_nt1->addItem(
"costheta",m_costheta);
171 status = m_nt1->addItem(
"charge",m_charge);
172 status = m_nt1->addItem(
"runNO",m_runNO);
173 status = m_nt1->addItem(
"evtNO",m_evtNO);
174 status = m_nt1->addItem(
"t0",m_t0);
175 status = m_nt1->addItem(
"trackId",m_trackId);
176 status = m_nt1->addItem(
"poca_x",m_poca_x);
177 status = m_nt1->addItem(
"poca_y",m_poca_y);
178 status = m_nt1->addItem(
"poca_z",m_poca_z);
179 status = m_nt1->addItem(
"recalg",m_recalg);
181 status = m_nt1->addItem(
"nhit",m_nhit);
182 status = m_nt1->addItem(
"usedhit",m_usedhit);
183 status = m_nt1->addItem(
"ndedxhit",m_nphlisthit,0,100);
184 status = m_nt1->addIndexedItem(
"dEdx_hit",m_nphlisthit,m_dEdx_hit);
186 status = m_nt1->addItem(
"type",m_parttype);
187 status = m_nt1->addItem(
"prob",m_prob);
188 status = m_nt1->addItem(
"expect",m_expect);
189 status = m_nt1->addItem(
"sigma",m_sigma);
190 status = m_nt1->addItem(
"chidedx",m_chidedx);
191 status = m_nt1->addItem(
"chidedx_e",m_chidedxe);
192 status = m_nt1->addItem(
"chidedx_mu",m_chidedxmu);
193 status = m_nt1->addItem(
"chidedx_pi",m_chidedxpi);
194 status = m_nt1->addItem(
"chidedx_k",m_chidedxk);
195 status = m_nt1->addItem(
"chidedx_p",m_chidedxp);
196 status = m_nt1->addItem(
"partid",5,m_probpid);
197 status = m_nt1->addItem(
"expectid",5,m_expectid);
198 status = m_nt1->addItem(
"sigmaid",5,m_sigmaid);
202 NTuplePtr nt2(
ntupleSvc(),
"FILE103/n102");
203 if ( nt2 ) m_nt2 = nt2;
206 m_nt2=
ntupleSvc()->book(
"FILE103/n102",CLID_RowWiseTuple,
"pulae height raw");
209 status = m_nt2->addItem(
"charge",m_charge1);
210 status = m_nt2->addItem(
"adc_raw",m_phraw);
211 status = m_nt2->addItem(
"exraw",m_exraw);
212 status = m_nt2->addItem(
"runNO1",m_runNO1);
213 status = m_nt2->addItem(
"evtNO1",m_evtNO1);
214 status = m_nt2->addItem(
"nhit_hit", m_nhit_hit);
215 status = m_nt2->addItem(
"wire",m_wire);
217 status = m_nt2->addItem(
"doca_in",m_doca_in);
218 status = m_nt2->addItem(
"doca_ex",m_doca_ex);
219 status = m_nt2->addItem(
"driftdist",m_driftdist);
220 status = m_nt2->addItem(
"eangle",m_eangle);
221 status = m_nt2->addItem(
"costheta1",m_costheta1);
222 status = m_nt2->addItem(
"path_rphi",m_pathL);
223 status = m_nt2->addItem(
"layer",m_layer);
224 status = m_nt2->addItem(
"ptrk1",m_ptrk1);
225 status = m_nt2->addItem(
"ptrk_hit",m_ptrk_hit);
226 status = m_nt2->addItem(
"t01",m_t01);
227 status = m_nt2->addItem(
"tdc_raw",m_tdc_raw);
228 status = m_nt2->addItem(
"driftT",m_driftT);
229 status = m_nt2->addItem(
"localwid",m_localwid);
230 status = m_nt2->addItem(
"trackId1",m_trackId1);
235 return StatusCode::SUCCESS;
241 MsgStream log(
msgSvc(), name());
242 log << MSG::DEBUG <<
"in MdcDedxRecon::beginrun()!!!"<< endreq;
244 StatusCode gesc = service(
"MdcGeomSvc", geosvc);
245 if (gesc == StatusCode::SUCCESS)
247 log << MSG::INFO <<
"MdcGeomSvc is running"<<endreq;
251 log << MSG::ERROR <<
"MdcGeomSvc is failed"<<endreq;
252 return StatusCode::SUCCESS;
255 return StatusCode::SUCCESS;
261 MsgStream log(
msgSvc(), name());
262 log << MSG::INFO <<
"in finalize()" << endreq;
267 if(m_rootfile !=
"no rootfile")
269 TFile *
f1 =
new TFile(m_rootfile.c_str(),
"recreate");
279 cout<<
"total event number is : "<<
eventNo<<endl;
280 cout<<
"total track number is : "<<
trackNO1
281 <<
" RecMdcTrack number is : "<<
trackNO2
282 <<
" RecMdcKalTrack number is :"<<
trackNO3<<endl;
283 log << MSG::DEBUG <<
"MdcDedxRecon terminated!!!"<< endreq;
284 return StatusCode::SUCCESS;
290 MsgStream log(
msgSvc(), name());
291 log << MSG::INFO <<
"in execute()" << endreq;
293 vector<double> Curve_Para, Sigma_Para;
298 if(i==0) vFlag[0] = (int) dedxcursvc->
getCurve(i);
299 else Curve_Para.push_back( dedxcursvc->
getCurve(i) );
303 if(i==0) vFlag[1] = (int) dedxcursvc->
getSigma(i);
304 else Sigma_Para.push_back( dedxcursvc->
getSigma(i) );
308 if(vFlag[0] ==1 && Curve_Para.size() != 5)
309 cout<<
" size of dedx curve paramters for version 1 is not right!"<<endl;
310 if(vFlag[0] ==2 && Curve_Para.size() != 16)
311 cout<<
" size of dedx curve paramters for version 2 is not right!"<<endl;
313 if(vFlag[1] ==1 && Sigma_Para.size() != 14)
314 cout<<
" size of dedx sigma paramters for version 1 is not right!"<<endl;
315 if(vFlag[1] ==2 && Sigma_Para.size() != 21)
316 cout<<
" size of dedx sigma paramters for version 2 is not right!"<<endl;
317 if(vFlag[1] ==3 && Sigma_Para.size() != 18)
318 cout<<
" size of dedx sigma paramters for version 3 is not right!"<<endl;
319 if(vFlag[1] ==4 && Sigma_Para.size() != 19)
320 cout<<
" size of dedx sigma paramters for version 4 is not right!"<<endl;
321 if(vFlag[1] ==5 && Sigma_Para.size() != 22)
322 cout<<
" size of dedx sigma paramters for version 5 is not right!"<<endl;
326 DataObject *aReconEvent;
327 eventSvc()->findObject(
"/Event/Recon",aReconEvent);
328 if(aReconEvent==
NULL)
331 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon",aReconEvent);
332 if(sc!=StatusCode::SUCCESS)
334 log << MSG::FATAL <<
"Could not register ReconEvent" <<endreq;
335 return( StatusCode::FAILURE);
339 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
341 DataObject *aDedxcol;
342 eventSvc()->findObject(
"/Event/Recon/RecMdcDedxCol",aDedxcol);
345 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcDedxCol");
346 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcDedxCol");
351 if(!dedxsc.isSuccess())
353 log << MSG::FATAL <<
" Could not register Mdc dedx collection" <<endreq;
354 return ( StatusCode::FAILURE);
357 DataObject *aDedxhitcol;
358 eventSvc()->findObject(
"/Event/Recon/RecMdcDedxHitCol",aDedxhitcol);
359 if(aDedxhitcol !=
NULL)
361 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcDedxHitCol");
362 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcDedxHitCol");
365 StatusCode dedxhitsc;
367 if(!dedxhitsc.isSuccess())
369 log << MSG::FATAL <<
" Could not register Mdc dedx collection" <<endreq;
370 return ( StatusCode::FAILURE);
373 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
376 log << MSG::INFO <<
"Could not find Event Header" << endreq;
377 return( StatusCode::FAILURE);
379 int eventNO = eventHeader->eventNumber();
380 int runNO = eventHeader->runNumber();
381 log << MSG::INFO <<
"now begin the event: runNO= "<<runNO<<
" eventNO= "<< eventNO<< endreq;
397 if(runNO < 0) vFlag[2]=1;
402 SmartDataPtr<RecEsTimeCol> estimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
405 log << MSG::WARNING <<
"Could not find EvTimeCol" << endreq;
409 RecEsTimeCol::iterator iter_evt = estimeCol->begin();
410 for(; iter_evt!=estimeCol->end(); iter_evt++)
412 tes = (*iter_evt)->getTest();
413 esTimeflag = (*iter_evt)->getStat();
425 log << MSG::DEBUG <<
"recalg: "<<recalg<<endreq;
431 SmartDataPtr<RecMdcKalTrackCol> newtrkCol(eventSvc(),
"/Event/Recon/RecMdcKalTrackCol");
434 log << MSG::WARNING <<
"Could not find RecMdcKalTrackCol" << endreq;
435 return StatusCode::SUCCESS;
438 ntrk = newtrkCol->size();
439 log << MSG::DEBUG <<
"track collection size: " << newtrkCol->size() <<endreq;
441 RecMdcKalTrackCol::iterator trk = newtrkCol->begin();
443 for( ; trk != newtrkCol->end(); trk++)
449 if(gothits.size()==0)
452 int trkid=(*trk)->trackId();
458 if(gothits.size()<2)
continue;
459 kaltrackrec(trk, mdcid, tes, runNO, eventNO, runFlag, log );
470 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
473 log << MSG::WARNING <<
"Could not find RecMdcTrackCol" << endreq;
474 return StatusCode::SUCCESS;
477 ntrk = newtrkCol->size();
478 log << MSG::DEBUG <<
"track collection size: " << newtrkCol->size() <<endreq;
480 vector<double> phlist;
481 vector<double> phlist_hit;
482 double m_d0E=0,m_phi0E=0,m_cpaE=0,m_z0E=0,phi0=0,
costheta=0,sintheta=0,m_Pt=0,m_P=0;
483 int charge=0,layid=0,localwid=0,w0id=0,wid=0,lr=-2;
484 double adc_raw=0,tdc_raw=0,zhit=0,driftd=0,driftD=0,driftT=0,dd=0,eangle=0;
486 double ph=0,ph_hit=0,pathlength=0,rphi_path=0;
488 RecMdcTrackCol::iterator trk = newtrkCol->begin();
489 for( ; trk != newtrkCol->end(); trk++)
494 log << MSG::DEBUG <<
" %%%%% trk id = "<<trk_ex.
trk_id() <<endreq;
495 log << MSG::DEBUG <<
" %%%%% initial id = "<<(*trk)->trackId() <<endreq;
497 HepVector a = (*trk)->helix();
498 HepSymMatrix tkErrM = (*trk)->err();
499 m_d0E = tkErrM[0][0];
500 m_phi0E = tkErrM[1][1];
501 m_cpaE = tkErrM[2][2];
502 m_z0E = tkErrM[3][3];
506 log << MSG::DEBUG <<
"MDC Helix 5 parameters: "<<a[0]<<
" "<<a[1]<<
" "<<a[2]<<
" "<<a[3]<<
" "<<a[4]<<endreq;
511 sintheta =
sin(M_PI_2-atan(a[4]));
512 m_Pt = 1.0/fabs( a[2] );
513 m_P = m_Pt*sqrt(1 + a[4]*a[4]);
514 charge = ( a[2] > 0 )? 1 : -1;
520 Nhits = gothits.size();
521 log << MSG::DEBUG <<
"hits size = " <<gothits.size()<<endreq;
524 delete dedxhitrefvec;
530 HitRefVec::iterator it_gothit = gothits.begin();
531 for( ; it_gothit != gothits.end(); it_gothit++)
533 mdcid = (*it_gothit)->getMdcId();
537 wid = w0id + localwid;
538 adc_raw = (*it_gothit)->getAdc();
539 tdc_raw = (*it_gothit)->getTdc();
540 log << MSG::INFO <<
"hit layer id " <<layid<<
" wire id: " <<localwid<<
" adc_raw: " <<adc_raw<<
" tdc_raw: "<<tdc_raw<<endreq;
541 zhit = (*it_gothit)->getZhit();
542 lr = (*it_gothit)->getFlagLR();
543 if(lr == 2) cout<<
"lr = "<<lr<<endl;
544 if(lr == 0 || lr == 2) driftD = (*it_gothit)->getDriftDistLeft();
545 else driftD = (*it_gothit)->getDriftDistRight();
547 driftd =
abs(driftD);
548 dd = (*it_gothit)->getDoca();
549 if(lr == 0 || lr == 2 ) dd = -
abs(dd);
550 if(lr == 1 ) dd =
abs(dd);
551 driftT = (*it_gothit)->getDriftT();
553 eangle = (*it_gothit)->getEntra();
554 eangle = eangle/
M_PI;
555 pathlength=exsvc->
PathL( ntpFlag, exhel, layid, localwid, zhit);
556 rphi_path=pathlength * sintheta;
559 ph=exsvc->
StandardHitCorrec(0,runFlag,ntpFlag,runNO,eventNO,pathlength,wid,layid,adc_raw,dd,eangle,
costheta);
564 if(runNO<=5911 && runNO>=5854 && layid ==14)
continue;
589 if (ph<0.0||ph==0)
continue;
603 if(m_rootfile!=
"no rootfile")
605 m_hitNo_wire->Fill(wid);
611 m_charge1 = (*trk)->charge();
617 m_localwid = localwid;
624 m_driftdist = driftD;
627 m_pathL = pathlength;
631 m_trackId1 = trk_ex.
trk_id();
632 StatusCode status2 = m_nt2->write();
633 if ( status2.isFailure() )
634 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
638 phlist.push_back(ph);
639 phlist_hit.push_back(ph_hit);
642 dedxhitList->push_back( dedxhit );
643 dedxhitrefvec->push_back( dedxhit );
648 ex_trks.push_back(trk_ex );
649 m_trkalgs.push_back(m_trkalg);
651 delete dedxhitrefvec;
656 log << MSG::DEBUG <<
"size in processing: " << ex_trks.size() <<endreq;
665 SmartDataPtr<RecMdcKalTrackCol> newtrkCol(eventSvc(),
"/Event/Recon/RecMdcKalTrackCol");
668 log << MSG::WARNING <<
"Could not find RecMdcKalTrackCol" << endreq;
669 return StatusCode::SUCCESS;
672 ntrk = newtrkCol->size();
673 log << MSG::DEBUG <<
"track collection size: " << newtrkCol->size() <<endreq;
675 vector<double> phlist;
676 vector<double> phlist_hit;
677 double m_d0E=0,m_phi0E=0,m_cpaE=0,m_z0E=0,phi0=0,
costheta=0,sintheta=0,m_Pt=0,m_P=0;
678 int charge=0,layid=0,localwid=0,w0id=0,wid=0,lr=-2;
679 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;
681 double ph=0,ph_hit=0,pathlength=0,rphi_path=0;
684 RecMdcKalTrackCol::iterator trk = newtrkCol->begin();
685 for( ; trk != newtrkCol->end(); trk++)
690 log << MSG::DEBUG <<
" %%%%% trk id = "<<trk_ex.
trk_id() <<endreq;
691 log << MSG::DEBUG <<
" %%%%% initial id = "<<(*trk)->trackId() <<endreq;
695 if(ParticleFlag>-1&&ParticleFlag<5)
699 tkErrM = dstTrk->
getFError(ParticleFlag);
703 a = (*trk)->getFHelix();
704 tkErrM = (*trk)->getFError();
707 log << MSG::DEBUG <<
"FHelix 5 parameters: "<<a[0]<<
" "<<a[1] <<
" "<<a[2]<<
" "<<a[3]<<
" "<<a[4]<<endreq;
709 m_d0E = tkErrM[0][0];
710 m_phi0E = tkErrM[1][1];
711 m_cpaE = tkErrM[2][2];
712 m_z0E = tkErrM[3][3];
717 sintheta =
sin(M_PI_2-atan(a[4]));
718 m_Pt = 1.0/fabs( a[2] );
719 m_P = m_Pt*sqrt(1 + a[4]*a[4]);
721 charge = ( a[2] > 0 )? 1 : -1;
729 Nhits = gothits.size();
730 log << MSG::DEBUG <<
"hits size = " <<gothits.size()<<endreq;
733 delete dedxhitrefvec;
739 HelixSegRefVec::iterator it_gothit = gothits.begin();
740 for( ; it_gothit != gothits.end(); it_gothit++)
742 HepVector a_hit_in = (*it_gothit)->getHelixIncl();
747 p_hit = 1.0/fabs(a_hit_in(3))*sqrt(1+a_hit_in(5)*a_hit_in(5));
750 mdcid = (*it_gothit)->getMdcId();
754 wid = w0id + localwid;
755 adc_raw = (*it_gothit)->getAdc();
756 tdc_raw = (*it_gothit)->getTdc();
757 log << MSG::INFO <<
"hit layer id " <<layid<<
" wire id: " <<localwid<<
" adc_raw: " <<adc_raw<<
" tdc_raw: "<<tdc_raw<<endreq;
758 zhit = (*it_gothit)->getZhit();
759 lr = (*it_gothit)->getFlagLR();
760 if(lr == 2) cout<<
"lr = "<<lr<<endl;
761 driftD = (*it_gothit)->getDD();
762 driftd =
abs(driftD);
763 driftT = (*it_gothit)->getDT();
764 dd_in = (*it_gothit)->getDocaIncl();
765 dd_ex = (*it_gothit)->getDocaExcl();
767 if(lr==-1 || lr == 2) {dd_in = dd_in; dd_ex = dd_ex;}
768 else if(lr ==1) {dd_in = -dd_in; dd_ex = -dd_ex;}
772 eangle = (*it_gothit)->getEntra();
773 eangle = eangle/
M_PI;
774 pathlength=exsvc->
PathL( ntpFlag, exhel_hit_in, layid, localwid, zhit);
775 rphi_path=pathlength * sintheta;
777 ph=exsvc->
StandardHitCorrec(0,runFlag,ntpFlag,runNO,eventNO,pathlength,wid,layid,adc_raw,dd_in,eangle,
costheta);
782 if(runNO<=5911 && runNO>=5854 && layid ==14)
continue;
807 if (ph<0.0||ph==0)
continue;
821 if(m_rootfile!=
"no rootfile")
823 m_hitNo_wire->Fill(wid);
829 m_charge1 = (*trk)->charge();
835 m_localwid = localwid;
842 m_driftdist = driftD;
845 m_pathL = pathlength;
850 m_trackId1 = trk_ex.
trk_id();
851 StatusCode status2 = m_nt2->write();
852 if ( status2.isFailure() )
853 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
857 phlist.push_back(ph);
858 phlist_hit.push_back(ph_hit);
861 dedxhitList->push_back( dedxhit );
862 dedxhitrefvec->push_back( dedxhit );
867 ex_trks.push_back(trk_ex );
868 m_trkalgs.push_back(m_trkalg);
870 delete dedxhitrefvec;
875 log << MSG::DEBUG <<
"size in processing: " << ex_trks.size() <<endreq;
880 if( ntrk != ex_trks.size())
881 log << MSG::DEBUG <<
"ntrkCol size: "<<ntrk<<
" dedxtrk size: "<<ex_trks.size()<< endreq;
883 double poca_x=0,poca_y=0,poca_z=0;
885 int Nhit=0,Nphlisthit=0;
887 double phtm=0,median=0,geometric=0,geometric_trunc=0,harmonic=0,harmonic_trunc=0,transform=0,logtrunc=0;
890 float probpid_temp=-0.01,expect_temp=-0.01,sigma_temp=-0.01,chidedx_temp=-0.01;
892 double dEdx_meas_hit=0;
893 double dEdx_meas=0,dEdx_meas_esat=0,dEdx_meas_norun=0;
897 for(std::vector<MdcDedxTrk>::iterator it = ex_trks.begin(); it != ex_trks.end(); it++, idedxid++ )
899 log << MSG::DEBUG <<
"-------------------------------------------------------"<< endreq;
900 log << MSG::DEBUG <<
" trk id ="<< it->trk_id()<<
" : P ="<<it->P() <<
" Pt ="<<it->Pt()<<
" : theta ="<<it->theta() <<
" : phi ="<<it->phi()<<
" : charge = "<<it->charge()<<endreq;
901 log << MSG::DEBUG <<
"all hits on track: "<<it->nsample()<<
" phlist size: "<<it->get_phlist().size()<<endreq;
903 if(it->trk_ptr_kal()!=0)
905 poca_x = it->trk_ptr_kal()->x();
906 poca_y = it->trk_ptr_kal()->y();
907 poca_z = it->trk_ptr_kal()->z();
909 else if(it->trk_ptr()!=0)
911 poca_x = it->trk_ptr()->x();
912 poca_y = it->trk_ptr()->y();
913 poca_z = it->trk_ptr()->z();
917 sintheta =
sin(it->theta());
921 Nhit = it->nsample();
922 Nphlisthit = it->get_phlist_hit().size();
926 phtm = it->cal_dedx( truncate );
936 if(m_alg==1) dEdx_meas_hit = it->cal_dedx_bitrunc(truncate, 0, usedhit);
937 else if(m_alg==2) dEdx_meas_hit = it-> cal_dedx_transform(1);
938 else if(m_alg==3) dEdx_meas_hit = it->cal_dedx_log(1.0, 1);
939 else cout<<
"-------------Truncate Algorithm Error!!!------------------------"<<endl;
940 if(m_alg==1 && usedhit==0)
942 cout<<
"***************bad extrk with no hits!!!!!******************"<<endl;
946 usedhit = (int)(Nphlisthit*truncate);
950 dEdx_meas_esat = exsvc->
StandardTrackCorrec(1,runFlag, ntpFlag, runNO, eventNO, dEdx_meas_hit,
cos(it->theta()), tes );
951 dEdx_meas_norun = exsvc->
StandardTrackCorrec(2,runFlag, ntpFlag, runNO, eventNO, dEdx_meas_hit,
cos(it->theta()), tes );
952 log << MSG::INFO <<
"===================== " << endreq << endreq;
953 log << MSG::DEBUG <<
"dEdx_meas_hit: "<<dEdx_meas_hit<<
" dEdx_meas: "<<
dEdx_meas<<
" dEdx_meas_esat: "<<dEdx_meas_esat<<
" dEdx_meas_norun: "<<dEdx_meas_norun<<
" ptrk: "<<it->P()<<endreq;
954 log << MSG::INFO <<
"ptrk " <<
ptrk <<
" costhe " <<
costheta <<
" runno " << runNO <<
" evtno " << eventNO << endreq;
957 trk_recalg = m_trkalgs[idedxid];
960 it->set_dEdx( landau ,
dEdx_meas, trk_recalg, runFlag, vFlag , tes, Curve_Para, Sigma_Para, ex_calib);
968 if(it->pprob()[i]>probpid_temp)
971 probpid_temp = it->pprob()[i];
972 expect_temp = it->pexpect()[i];
973 sigma_temp = it->pexp_sigma()[i];
974 chidedx_temp = it->pchi_dedx()[i];
977 log<< MSG::INFO<<
"expect dE/dx: type: "<<parType_temp<<
" probpid: "<<probpid_temp<<
" expect: "<<expect_temp<<
" sigma: "<<sigma_temp<<
" chidedx: "<<chidedx_temp<<endreq;
992 resdedx->
setChi( it->pchi_dedx() );
1024 m_sintheta=sintheta;
1031 m_trackId = it->trk_id();
1032 m_recalg = trk_recalg;
1035 m_nphlisthit=Nphlisthit;
1037 for(
int i=0; i<Nphlisthit; i++) m_dEdx_hit[i] = it->get_phlist_hit()[i];
1039 m_parttype = parType_temp;
1040 m_prob = probpid_temp;
1041 m_expect = expect_temp;
1042 m_sigma = sigma_temp;
1043 m_chidedx = chidedx_temp;
1044 m_chidedxe=it->pchi_dedx()[0];
1045 m_chidedxmu=it->pchi_dedx()[1];
1046 m_chidedxpi=it->pchi_dedx()[2];
1047 m_chidedxk=it->pchi_dedx()[3];
1048 m_chidedxp=it->pchi_dedx()[4];
1049 for(
int i=0;i<5;i++)
1051 m_probpid[i]= it->pprob()[i];
1052 m_expectid[i]= it->pexpect()[i];
1053 m_sigmaid[i]= it->pexp_sigma()[i];
1056 StatusCode status = m_nt1->write();
1057 if ( status.isFailure() )
1059 log << MSG::ERROR <<
"Cannot fill Ntuple n103" << endreq;
1063 log<< MSG::INFO<<
"-----------------Summary of this ExTrack----------------"<<endreq
1064 <<
"dEdx_mean: "<<
dEdx_meas<<
" type: "<<parType_temp<<
" probpid: "<<probpid_temp
1065 <<
" expect: "<<expect_temp<<
" sigma: "<<sigma_temp<<
" chidedx: "<<chidedx_temp<<endreq<<endreq;
1067 dedxList->push_back( resdedx );
1073 SmartDataPtr<RecMdcDedxCol> newexCol(eventSvc(),
"/Event/Recon/RecMdcDedxCol");
1076 log << MSG::FATAL <<
"Could not find RecMdcDedxCol" << endreq;
1077 return( StatusCode::SUCCESS);
1079 log << MSG::DEBUG <<
"----------------Begin to check RecMdcDedxCol-----------------"<<endreq;
1080 RecMdcDedxCol::iterator it_dedx = newexCol->begin();
1081 for( ; it_dedx != newexCol->end(); it_dedx++)
1083 log << MSG::INFO <<
"retrieved MDC dE/dx:" << endreq
1084 <<
"dEdx Id: " << (*it_dedx)->trackId()
1085 <<
" part Id: " << (*it_dedx)->particleType()
1086 <<
" measured dEdx: " << (*it_dedx)->probPH()
1087 <<
" dEdx std: " << (*it_dedx)->normPH() << endreq
1088 <<
"hits on track: "<<(*it_dedx)->numTotalHits()
1089 <<
" usedhits: " << (*it_dedx)->numGoodHits() << endreq
1090 <<
"Electron: expect: " << (*it_dedx)->getDedxExpect(0)
1091 <<
" sigma: " << (*it_dedx)->getSigmaDedx(0)
1092 <<
" chi: " << (*it_dedx)->chi(0)
1093 <<
" prob: " << (*it_dedx)->getPidProb(0) << endreq
1094 <<
"Muon: expect: " << (*it_dedx)->getDedxExpect(1)
1095 <<
" sigma: " << (*it_dedx)->getSigmaDedx(1)
1096 <<
" chi: " << (*it_dedx)->chi(1)
1097 <<
" prob: " << (*it_dedx)->getPidProb(1) << endreq
1098 <<
"Pion: expect: " << (*it_dedx)->getDedxExpect(2)
1099 <<
" sigma: " << (*it_dedx)->getSigmaDedx(2)
1100 <<
" chi: " << (*it_dedx)->chi(2)
1101 <<
" prob: " << (*it_dedx)->getPidProb(2) << endreq
1102 <<
"Kaon: expect: " << (*it_dedx)->getDedxExpect(3)
1103 <<
" sigma: " << (*it_dedx)->getSigmaDedx(3)
1104 <<
" chi: " << (*it_dedx)->chi(3)
1105 <<
" prob: " << (*it_dedx)->getPidProb(3) << endreq
1106 <<
"Proton: expect: " << (*it_dedx)->getDedxExpect(4)
1107 <<
" sigma: " << (*it_dedx)->getSigmaDedx(4)
1108 <<
" chi: " << (*it_dedx)->chi(4)
1109 <<
" prob: " << (*it_dedx)->getPidProb(4) << endreq;
1111 return StatusCode::SUCCESS;
1123 vector<double> phlist;
1124 vector<double> phlist_hit;
1125 double m_d0E=0,m_phi0E=0,m_cpaE=0,m_z0E=0,phi0=0,
costheta=0,sintheta=0,m_Pt=0,m_P=0;
1126 int charge=0,layid=0,localwid=0,w0id=0,wid=0,lr=-2;
1127 double adc_raw=0,tdc_raw=0,zhit=0,driftd=0,driftD=0,driftT=0,dd=0,eangle=0;
1129 double ph=0,ph_hit=0,pathlength=0,rphi_path=0;
1132 log << MSG::DEBUG <<
" %%%%% trk id = "<<trk_ex.
trk_id() <<endreq;
1133 log << MSG::DEBUG <<
" %%%%% initial id = "<<(*trk)->trackId() <<endreq;
1135 HepVector a = (*trk)->helix();
1136 HepSymMatrix tkErrM = (*trk)->err();
1137 m_d0E = tkErrM[0][0];
1138 m_phi0E = tkErrM[1][1];
1139 m_cpaE = tkErrM[2][2];
1140 m_z0E = tkErrM[3][3];
1144 log << MSG::DEBUG <<
"MDC Helix 5 parameters: "<<a[0]<<
" "<<a[1]<<
" "<<a[2]<<
" "<<a[3]<<
" "<<a[4]<<endreq;
1149 sintheta =
sin(M_PI_2-atan(a[4]));
1150 m_Pt = 1.0/fabs( a[2] );
1151 m_P = m_Pt*sqrt(1 + a[4]*a[4]);
1152 charge = ( a[2] > 0 )? 1 : -1;
1157 HitRefVec gothits= (*trk)->getVecHits();
1158 Nhits = gothits.size();
1159 log << MSG::DEBUG <<
"hits size = " <<gothits.size()<<endreq;
1163 HitRefVec::iterator it_gothit = gothits.begin();
1164 for( ; it_gothit != gothits.end(); it_gothit++)
1166 mdcid = (*it_gothit)->getMdcId();
1170 wid = w0id + localwid;
1171 adc_raw = (*it_gothit)->getAdc();
1172 tdc_raw = (*it_gothit)->getTdc();
1173 log << MSG::INFO <<
"hit layer id " <<layid<<
" wire id: " <<localwid<<
" adc_raw: " <<adc_raw<<
" tdc_raw: "<<tdc_raw<<endreq;
1174 zhit = (*it_gothit)->getZhit();
1175 lr = (*it_gothit)->getFlagLR();
1176 if(lr == 2) cout<<
"lr = "<<lr<<endl;
1177 if(lr == 0 || lr == 2) driftD = (*it_gothit)->getDriftDistLeft();
1178 else driftD = (*it_gothit)->getDriftDistRight();
1180 driftd =
abs(driftD);
1181 dd = (*it_gothit)->getDoca();
1182 if(lr == 0 || lr == 2 ) dd = -
abs(dd);
1183 if(lr == 1 ) dd =
abs(dd);
1184 driftT = (*it_gothit)->getDriftT();
1186 eangle = (*it_gothit)->getEntra();
1187 eangle = eangle/
M_PI;
1188 pathlength=exsvc->
PathL( ntpFlag, exhel, layid, localwid, zhit);
1189 rphi_path=pathlength * sintheta;
1192 ph=exsvc->
StandardHitCorrec(0,runFlag,ntpFlag,runNO,eventNO,pathlength,wid,layid,adc_raw,dd,eangle,
costheta);
1197 if(runNO<=5911 && runNO>=5854 && layid ==14)
continue;
1222 if (ph<0.0||ph==0)
continue;
1236 if(m_rootfile!=
"no rootfile")
1238 m_hitNo_wire->Fill(wid);
1244 m_charge1 = (*trk)->charge();
1247 m_tdc_raw = tdc_raw;
1250 m_localwid = localwid;
1257 m_driftdist = driftD;
1260 m_pathL = pathlength;
1264 m_trackId1 = trk_ex.
trk_id();
1265 StatusCode status2 = m_nt2->write();
1266 if ( status2.isFailure() )
1267 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
1271 phlist.push_back(ph);
1272 phlist_hit.push_back(ph_hit);
1275 dedxhitList->push_back( dedxhit );
1276 dedxhitrefvec->push_back( dedxhit );
1281 ex_trks.push_back(trk_ex );
1282 m_trkalgs.push_back(m_trkalg);
1284 delete dedxhitrefvec;
1293 vector<double> phlist;
1294 vector<double> phlist_hit;
1295 double m_d0E=0,m_phi0E=0,m_cpaE=0,m_z0E=0,phi0=0,
costheta=0,sintheta=0,m_Pt=0,m_P=0;
1296 int charge=0,layid=0,localwid=0,w0id=0,wid=0,lr=-2;
1297 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;
1299 double ph=0,ph_hit=0,pathlength=0,rphi_path=0;
1302 log << MSG::DEBUG <<
" %%%%% trk id = "<<trk_ex.
trk_id() <<endreq;
1303 log << MSG::DEBUG <<
" %%%%% initial id = "<<(*trk)->trackId() <<endreq;
1306 HepSymMatrix tkErrM;
1307 if(ParticleFlag>-1&&ParticleFlag<5)
1311 tkErrM = dstTrk->
getFError(ParticleFlag);
1315 a = (*trk)->getFHelix();
1316 tkErrM = (*trk)->getFError();
1318 log << MSG::DEBUG <<
"FHelix 5 parameters: "<<a[0]<<
" "<<a[1] <<
" "<<a[2]<<
" "<<a[3]<<
" "<<a[4]<<endreq;
1321 m_d0E = tkErrM[0][0];
1322 m_phi0E = tkErrM[1][1];
1323 m_cpaE = tkErrM[2][2];
1324 m_z0E = tkErrM[3][3];
1329 sintheta =
sin(M_PI_2-atan(a[4]));
1330 m_Pt = 1.0/fabs( a[2] );
1331 m_P = m_Pt*sqrt(1 + a[4]*a[4]);
1333 charge = ( a[2] > 0 )? 1 : -1;
1341 Nhits = gothits.size();
1342 log << MSG::DEBUG <<
"hits size = " <<gothits.size()<<endreq;
1346 HelixSegRefVec::iterator it_gothit = gothits.begin();
1347 for( ; it_gothit != gothits.end(); it_gothit++)
1349 HepVector a_hit_in = (*it_gothit)->getHelixIncl();
1354 p_hit = 1.0/fabs(a_hit_in(3))*sqrt(1+a_hit_in(5)*a_hit_in(5));
1357 mdcid = (*it_gothit)->getMdcId();
1361 wid = w0id + localwid;
1362 adc_raw = (*it_gothit)->getAdc();
1363 tdc_raw = (*it_gothit)->getTdc();
1364 log << MSG::INFO <<
"hit layer id " <<layid<<
" wire id: " <<localwid<<
" adc_raw: " <<adc_raw<<
" tdc_raw: "<<tdc_raw<<endreq;
1365 zhit = (*it_gothit)->getZhit();
1366 lr = (*it_gothit)->getFlagLR();
1367 if(lr == 2) cout<<
"lr = "<<lr<<endl;
1368 driftD = (*it_gothit)->getDD();
1369 driftd =
abs(driftD);
1370 driftT = (*it_gothit)->getDT();
1371 dd_in = (*it_gothit)->getDocaIncl();
1372 dd_ex = (*it_gothit)->getDocaExcl();
1374 if(lr==-1 || lr == 2) {dd_in = dd_in; dd_ex = dd_ex;}
1375 else if(lr ==1) {dd_in = -dd_in; dd_ex = -dd_ex;}
1379 eangle = (*it_gothit)->getEntra();
1380 eangle = eangle/
M_PI;
1381 pathlength=exsvc->
PathL( ntpFlag, exhel_hit_in, layid, localwid, zhit);
1382 rphi_path=pathlength * sintheta;
1385 ph=exsvc->
StandardHitCorrec(0,runFlag,ntpFlag,runNO,eventNO,pathlength,wid,layid,adc_raw,dd_in,eangle,
costheta);
1393 if(runNO<=5911 && runNO>=5854 && layid ==14)
continue;
1418 if (ph<0.0||ph==0)
continue;
1432 if(m_rootfile!=
"no rootfile")
1434 m_hitNo_wire->Fill(wid);
1440 m_charge1 = (*trk)->charge();
1443 m_tdc_raw = tdc_raw;
1446 m_localwid = localwid;
1453 m_driftdist = driftD;
1456 m_pathL = pathlength;
1461 m_trackId1 = trk_ex.
trk_id();
1462 StatusCode status2 = m_nt2->write();
1463 if ( status2.isFailure() )
1464 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
1468 phlist.push_back(ph);
1469 phlist_hit.push_back(ph_hit);
1472 dedxhitList->push_back( dedxhit );
1473 dedxhitrefvec->push_back( dedxhit );
1478 ex_trks.push_back(trk_ex );
1479 m_trkalgs.push_back(m_trkalg);
1481 delete dedxhitrefvec;
1490 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
1493 log << MSG::WARNING <<
"Could not find RecMdcTrackCol in switchtomdctrack" << endreq;
1497 RecMdcTrackCol::iterator trk = newtrkCol->begin();
1498 for( ; trk != newtrkCol->end(); trk++)
1500 if( (*trk)->trackId()==trkid)
1502 HitRefVec gothits= (*trk)->getVecHits();
1503 if(gothits.size()>=2)
1504 mdctrackrec(trk,mdcid,tes,runNO,eventNO,runFlag,log);
double sin(const BesAngle a)
double cos(const BesAngle a)
#define Iner_DriftDistCut
float prob_(float *, int *)
ObjectVector< RecMdcDedxHit > RecMdcDedxHitCol
SmartRefVector< RecMdcDedxHit > DedxHitRefVec
ObjectVector< RecMdcDedx > RecMdcDedxCol
SmartRefVector< RecMdcKalHelixSeg > HelixSegRefVec
SmartRefVector< RecMdcHit > HitRefVec
void setTruncAlg(int trunc_alg)
void setStatus(int status)
void setNumGoodHits(int numGoodHits)
void setProbPH(double probPH)
void setNormPH(double normPH)
void setParticleId(int particleId)
void setTrackId(int trackId)
void setNumTotalHits(int numTotalHits)
const HepSymMatrix & getFError(const int pid) const
const HepVector & getFHelix(const int pid) const
virtual void set_flag(int calib_F)=0
virtual double StandardHitCorrec(int calib_rec_Flag, int runFlag, int ntpFlag, int runNO, int evtNO, double pathl, int wid, int layid, double adc, double dd, double eangle, double costheta) const =0
virtual double PathL(int ntpFlag, const Dedx_Helix &hel, int layer, int cellid, double z) const =0
virtual double StandardTrackCorrec(int calib_rec_Flag, int typFlag, int ntpFlag, int runNO, int evtNO, double ex, double costheta, double t0) const =0
virtual const int getSigmaSize()=0
virtual const int getCurveSize()=0
virtual const double getCurve(int i)=0
virtual const double getSigma(int i)=0
virtual const MdcGeoLayer *const Layer(unsigned id)=0
void mdctrackrec(RecMdcTrackCol::iterator trk, Identifier mdcid, double tes, int RunNO, int eventNO, int runFlag, MsgStream log)
void switchtomdctrack(int trkid, Identifier mdcid, double tes, int RunNO, int eventNO, int runFlag, MsgStream log)
const std::vector< MdcDedxTrk > & tracks(void) const
void kaltrackrec(RecMdcKalTrackCol::iterator trk, Identifier mdcid, double tes, int RunNO, int eventNO, int runFlag, MsgStream log)
void setVecDedxHits(const DedxHitRefVec &vecdedxhit)
void set_phlist_hit(const vector< double > &phlist)
void set_phlist(const vector< double > &phlist)
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
void setMdcId(Identifier mdcid)
void setDedx(double dedx)
void setMdcKalHelixSeg(const RecMdcKalHelixSeg *mdcKalHelixSeg)
void setMdcHit(const RecMdcHit *mdcHit)
void setPathLength(double pathlength)
void setMdcTrack(RecMdcTrack *trk)
void setVecDedxHits(const DedxHitRefVec &vecdedxhit)
void setDedxNoRun(double dedx_norun)
void setMdcKalTrack(RecMdcKalTrack *trk)
void setDedxMoment(double dedx_momentum)
void setDedxExpect(double *dedx_exp)
void setSigmaDedx(double *sigma_dedx)
void setDedxEsat(double dedx_esat)
void setDedxHit(double dedx_hit)
void setPidProb(double *pid_prob)
_EXTERN_ std::string RecMdcDedxCol
_EXTERN_ std::string RecMdcDedxHitCol