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*);}
66 declareProperty(
"CalibFlag",calib_flag);
67 declareProperty(
"NTupleFlag",ntpFlag);
68 declareProperty(
"RecAlg",recalg);
69 declareProperty(
"ParticleType",ParticleFlag);
70 declareProperty(
"dEdxMethod",m_alg);
71 declareProperty(
"TruncRate",truncate);
72 declareProperty(
"RootFile",m_rootfile = std::string(
"no rootfile"));
78 MsgStream log(
msgSvc(), name());
79 log << MSG::INFO <<
"in initialize()" << endreq;
81 log << MSG::INFO <<
"--------------------< MdcDedxRecon V2.1 >---------------------"<< endreq;
82 log << MSG::INFO <<
"####### correction for the wire current dependence #######"<< endreq;
83 log << MSG::INFO <<
"####### correction for the new z dependence #######"<< endreq;
84 log << MSG::INFO <<
"-------------------------------------------------------------"<< endreq;
85 log << MSG::INFO <<
"++++++++++++++++++++[ initialization ]+++++++++++++++++++++"<< endreq;
86 log << MSG::INFO <<
"MdcDedxRecon has been initialized with calib_flag: "<< calib_flag <<endreq;
87 log << MSG::INFO <<
"MdcDedxRecon has been initialized with landau: "<< landau << endreq;
88 if( landau == 0 ) {truncate = 0.7;}
89 log << MSG::INFO <<
"MdcDedxRecon has been initialized with ntpFlag: "<< ntpFlag << endreq;
90 log << MSG::INFO <<
"MdcDedxRecon has been initialized with recalg: "<< recalg << endreq;
91 log << MSG::INFO <<
"MdcDedxRecon has been initialized with dE/dx cal method m_alg: "<< m_alg << endreq;
92 log << MSG::INFO <<
"MdcDedxRecon has been initialized with truncate: "<< truncate <<endreq;
93 log << MSG::INFO <<
"MdcDedxRecon has been initialized with doNewGlobal: "<<doNewGlobal<<endreq;
94 log << MSG::DEBUG <<
"+++++++++++ MdcDedxRecon initialization end ++++++++++++ "<< endreq;
95 if( truncate <= 0.0 || 1.0 < truncate )
97 log << MSG::FATAL <<
" Initialization ERROR of truncate = "<<truncate<< endreq;
98 log << MSG::FATAL <<
" truncate must be within 0.0 to 1.0 ! "<< endreq;
99 log << MSG::FATAL <<
" Please stop exec. "<< endreq;
101 log << MSG::DEBUG <<
"-------------------------------------------------------------"<< endreq;
102 log << MSG::DEBUG <<
"MdcDedxRecon init 2nd part!!!"<< endreq;
104 StatusCode scex = service(
"DedxCorrecSvc", exsvc);
105 if (scex == StatusCode::SUCCESS)
107 log << MSG::INFO <<
"Hi, DedxCorrectSvc is running"<<endreq;
111 log << MSG::ERROR <<
"DedxCorrectSvc is failed"<<endreq;
112 return StatusCode::SUCCESS;
116 StatusCode cursvc = service(
"DedxCurSvc", dedxcursvc);
117 if (cursvc == StatusCode::SUCCESS)
119 log << MSG::INFO <<
"DedxCurSvc is running"<<endreq;
123 log << MSG::ERROR <<
"DedxCurSvc is failed"<<endreq;
124 return StatusCode::SUCCESS;
134 if(m_rootfile!=
"no rootfile")
136 const char* preDir = gDirectory->GetPath();
137 m_hlist =
new TObjArray(0);
138 m_hitlevel =
new TFolder(
"dedx_hitlevel",
"hitlevel");
139 m_hlist ->
Add(m_hitlevel);
140 m_hitNo_wire =
new TH1F(
"dedx_HitNo_wire",
"dedx hitNo vs wire",6797, -0.5, 6796.5);
141 m_hitlevel ->
Add(m_hitNo_wire);
142 gDirectory->cd(preDir);
149 NTuplePtr nt1(
ntupleSvc(),
"FILE103/n103");
154 m_nt1=
ntupleSvc()->book(
"FILE103/n103",CLID_ColumnWiseTuple,
"dEdx vs momentum");
157 status = m_nt1->addItem(
"phtm",m_phtm);
165 status = m_nt1->addItem(
"dEdx_meas", m_dEdx_meas);
167 status = m_nt1->addItem(
"ptrk",m_ptrk);
168 status = m_nt1->addItem(
"sintheta",m_sintheta);
169 status = m_nt1->addItem(
"costheta",m_costheta);
170 status = m_nt1->addItem(
"charge",m_charge);
171 status = m_nt1->addItem(
"runNO",m_runNO);
172 status = m_nt1->addItem(
"evtNO",m_evtNO);
173 status = m_nt1->addItem(
"t0",m_t0);
174 status = m_nt1->addItem(
"trackId",m_trackId);
175 status = m_nt1->addItem(
"poca_x",m_poca_x);
176 status = m_nt1->addItem(
"poca_y",m_poca_y);
177 status = m_nt1->addItem(
"poca_z",m_poca_z);
178 status = m_nt1->addItem(
"recalg",m_recalg);
180 status = m_nt1->addItem(
"nhit",m_nhit);
181 status = m_nt1->addItem(
"usedhit",m_usedhit);
182 status = m_nt1->addItem(
"ndedxhit",m_nphlisthit,0,100);
183 status = m_nt1->addIndexedItem(
"dEdx_hit",m_nphlisthit,m_dEdx_hit);
185 status = m_nt1->addItem(
"type",m_parttype);
186 status = m_nt1->addItem(
"prob",m_prob);
187 status = m_nt1->addItem(
"expect",m_expect);
188 status = m_nt1->addItem(
"sigma",m_sigma);
189 status = m_nt1->addItem(
"chidedx",m_chidedx);
190 status = m_nt1->addItem(
"chidedx_e",m_chidedxe);
191 status = m_nt1->addItem(
"chidedx_mu",m_chidedxmu);
192 status = m_nt1->addItem(
"chidedx_pi",m_chidedxpi);
193 status = m_nt1->addItem(
"chidedx_k",m_chidedxk);
194 status = m_nt1->addItem(
"chidedx_p",m_chidedxp);
195 status = m_nt1->addItem(
"partid",5,m_probpid);
196 status = m_nt1->addItem(
"expectid",5,m_expectid);
197 status = m_nt1->addItem(
"sigmaid",5,m_sigmaid);
201 NTuplePtr nt2(
ntupleSvc(),
"FILE103/n102");
202 if ( nt2 ) m_nt2 = nt2;
205 m_nt2=
ntupleSvc()->book(
"FILE103/n102",CLID_RowWiseTuple,
"pulae height raw");
208 status = m_nt2->addItem(
"charge",m_charge1);
209 status = m_nt2->addItem(
"adc_raw",m_phraw);
210 status = m_nt2->addItem(
"exraw",m_exraw);
211 status = m_nt2->addItem(
"runNO1",m_runNO1);
212 status = m_nt2->addItem(
"nhit_hit", m_nhit_hit);
213 status = m_nt2->addItem(
"wire",m_wire);
215 status = m_nt2->addItem(
"doca_in",m_doca_in);
216 status = m_nt2->addItem(
"doca_ex",m_doca_ex);
217 status = m_nt2->addItem(
"driftdist",m_driftdist);
218 status = m_nt2->addItem(
"eangle",m_eangle);
219 status = m_nt2->addItem(
"costheta1",m_costheta1);
220 status = m_nt2->addItem(
"path_rphi",m_pathL);
221 status = m_nt2->addItem(
"layer",m_layer);
222 status = m_nt2->addItem(
"ptrk1",m_ptrk1);
223 status = m_nt2->addItem(
"ptrk_hit",m_ptrk_hit);
224 status = m_nt2->addItem(
"t01",m_t01);
225 status = m_nt2->addItem(
"tdc_raw",m_tdc_raw);
226 status = m_nt2->addItem(
"driftT",m_driftT);
227 status = m_nt2->addItem(
"localwid",m_localwid);
228 status = m_nt2->addItem(
"trackId1",m_trackId1);
233 return StatusCode::SUCCESS;
239 MsgStream log(
msgSvc(), name());
240 log << MSG::DEBUG <<
"in MdcDedxRecon::beginrun()!!!"<< endreq;
242 StatusCode gesc = service(
"MdcGeomSvc", geosvc);
243 if (gesc == StatusCode::SUCCESS)
245 log << MSG::INFO <<
"MdcGeomSvc is running"<<endreq;
249 log << MSG::ERROR <<
"MdcGeomSvc is failed"<<endreq;
250 return StatusCode::SUCCESS;
253 return StatusCode::SUCCESS;
259 MsgStream log(
msgSvc(), name());
260 log << MSG::INFO <<
"in finalize()" << endreq;
265 if(m_rootfile !=
"no rootfile")
267 TFile *
f1 =
new TFile(m_rootfile.c_str(),
"recreate");
277 cout<<
"total event number is : "<<
eventNo<<endl;
278 cout<<
"total track number is : "<<
trackNO1
279 <<
" RecMdcTrack number is : "<<
trackNO2
280 <<
" RecMdcKalTrack number is :"<<
trackNO3<<endl;
281 log << MSG::DEBUG <<
"MdcDedxRecon terminated!!!"<< endreq;
282 return StatusCode::SUCCESS;
288 MsgStream log(
msgSvc(), name());
289 log << MSG::INFO <<
"in execute()" << endreq;
291 vector<double> Curve_Para, Sigma_Para;
296 if(i==0) vFlag[0] = (int) dedxcursvc->
getCurve(i);
297 else Curve_Para.push_back( dedxcursvc->
getCurve(i) );
301 if(i==0) vFlag[1] = (int) dedxcursvc->
getSigma(i);
302 else Sigma_Para.push_back( dedxcursvc->
getSigma(i) );
306 if(vFlag[0] ==1 && Curve_Para.size() != 5)
307 cout<<
" size of dedx curve paramters for version 1 is not right!"<<endl;
308 if(vFlag[0] ==2 && Curve_Para.size() != 16)
309 cout<<
" size of dedx curve paramters for version 2 is not right!"<<endl;
311 if(vFlag[1] ==1 && Sigma_Para.size() != 14)
312 cout<<
" size of dedx sigma paramters for version 1 is not right!"<<endl;
313 if(vFlag[1] ==2 && Sigma_Para.size() != 21)
314 cout<<
" size of dedx sigma paramters for version 2 is not right!"<<endl;
315 if(vFlag[1] ==3 && Sigma_Para.size() != 18)
316 cout<<
" size of dedx sigma paramters for version 3 is not right!"<<endl;
317 if(vFlag[1] ==4 && Sigma_Para.size() != 19)
318 cout<<
" size of dedx sigma paramters for version 4 is not right!"<<endl;
319 if(vFlag[1] ==5 && Sigma_Para.size() != 22)
320 cout<<
" size of dedx sigma paramters for version 5 is not right!"<<endl;
324 DataObject *aReconEvent;
325 eventSvc()->findObject(
"/Event/Recon",aReconEvent);
326 if(aReconEvent==
NULL)
329 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon",aReconEvent);
330 if(sc!=StatusCode::SUCCESS)
332 log << MSG::FATAL <<
"Could not register ReconEvent" <<endreq;
333 return( StatusCode::FAILURE);
337 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
339 DataObject *aDedxcol;
340 eventSvc()->findObject(
"/Event/Recon/RecMdcDedxCol",aDedxcol);
343 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcDedxCol");
344 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcDedxCol");
349 if(!dedxsc.isSuccess())
351 log << MSG::FATAL <<
" Could not register Mdc dedx collection" <<endreq;
352 return ( StatusCode::FAILURE);
355 DataObject *aDedxhitcol;
356 eventSvc()->findObject(
"/Event/Recon/RecMdcDedxHitCol",aDedxhitcol);
357 if(aDedxhitcol !=
NULL)
359 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcDedxHitCol");
360 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcDedxHitCol");
363 StatusCode dedxhitsc;
365 if(!dedxhitsc.isSuccess())
367 log << MSG::FATAL <<
" Could not register Mdc dedx collection" <<endreq;
368 return ( StatusCode::FAILURE);
371 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
374 log << MSG::INFO <<
"Could not find Event Header" << endreq;
375 return( StatusCode::FAILURE);
377 int eventNO = eventHeader->eventNumber();
378 int runNO = eventHeader->runNumber();
379 log << MSG::INFO <<
"now begin the event: runNO= "<<runNO<<
" eventNO= "<< eventNO<< endreq;
395 if(runNO < 0) vFlag[2]=1;
400 SmartDataPtr<RecEsTimeCol> estimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
403 log << MSG::WARNING <<
"Could not find EvTimeCol" << endreq;
407 RecEsTimeCol::iterator iter_evt = estimeCol->begin();
408 for(; iter_evt!=estimeCol->end(); iter_evt++)
410 tes = (*iter_evt)->getTest();
411 esTimeflag = (*iter_evt)->getStat();
423 log << MSG::DEBUG <<
"recalg: "<<recalg<<endreq;
429 SmartDataPtr<RecMdcKalTrackCol> newtrkCol(eventSvc(),
"/Event/Recon/RecMdcKalTrackCol");
432 log << MSG::WARNING <<
"Could not find RecMdcKalTrackCol" << endreq;
433 return StatusCode::SUCCESS;
436 ntrk = newtrkCol->size();
437 log << MSG::DEBUG <<
"track collection size: " << newtrkCol->size() <<endreq;
439 RecMdcKalTrackCol::iterator trk = newtrkCol->begin();
441 for( ; trk != newtrkCol->end(); trk++)
447 if(gothits.size()==0)
450 int trkid=(*trk)->trackId();
456 if(gothits.size()<2)
continue;
457 kaltrackrec(trk, mdcid, tes, runNO, eventNO, runFlag, log );
468 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
471 log << MSG::WARNING <<
"Could not find RecMdcTrackCol" << endreq;
472 return StatusCode::SUCCESS;
475 ntrk = newtrkCol->size();
476 log << MSG::DEBUG <<
"track collection size: " << newtrkCol->size() <<endreq;
478 vector<double> phlist;
479 vector<double> phlist_hit;
480 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;
481 int charge=0,layid=0,localwid=0,w0id=0,wid=0,lr=-2;
482 double adc_raw=0,tdc_raw=0,zhit=0,driftd=0,driftD=0,driftT=0,dd=0,eangle=0;
484 double ph=0,ph_hit=0,pathlength=0,rphi_path=0;
486 RecMdcTrackCol::iterator trk = newtrkCol->begin();
487 for( ; trk != newtrkCol->end(); trk++)
492 log << MSG::DEBUG <<
" %%%%% trk id = "<<trk_ex.
trk_id() <<endreq;
493 log << MSG::DEBUG <<
" %%%%% initial id = "<<(*trk)->trackId() <<endreq;
495 HepVector a = (*trk)->helix();
496 HepSymMatrix tkErrM = (*trk)->err();
497 m_d0E = tkErrM[0][0];
498 m_phi0E = tkErrM[1][1];
499 m_cpaE = tkErrM[2][2];
500 m_z0E = tkErrM[3][3];
504 log << MSG::DEBUG <<
"MDC Helix 5 parameters: "<<a[0]<<
" "<<a[1]<<
" "<<a[2]<<
" "<<a[3]<<
" "<<a[4]<<endreq;
509 sintheta =
sin(M_PI_2-atan(a[4]));
510 m_Pt = 1.0/fabs( a[2] );
511 m_P = m_Pt*sqrt(1 + a[4]*a[4]);
512 charge = ( a[2] > 0 )? 1 : -1;
518 Nhits = gothits.size();
519 log << MSG::DEBUG <<
"hits size = " <<gothits.size()<<endreq;
522 delete dedxhitrefvec;
528 HitRefVec::iterator it_gothit = gothits.begin();
529 for( ; it_gothit != gothits.end(); it_gothit++)
531 mdcid = (*it_gothit)->getMdcId();
535 wid = w0id + localwid;
536 adc_raw = (*it_gothit)->getAdc();
537 tdc_raw = (*it_gothit)->getTdc();
538 log << MSG::INFO <<
"hit layer id " <<layid<<
" wire id: " <<localwid<<
" adc_raw: " <<adc_raw<<
" tdc_raw: "<<tdc_raw<<endreq;
539 zhit = (*it_gothit)->getZhit();
540 lr = (*it_gothit)->getFlagLR();
541 if(lr == 2) cout<<
"lr = "<<lr<<endl;
542 if(lr == 0 || lr == 2) driftD = (*it_gothit)->getDriftDistLeft();
543 else driftD = (*it_gothit)->getDriftDistRight();
545 driftd =
abs(driftD);
546 dd = (*it_gothit)->getDoca();
547 if(lr == 0 || lr == 2 ) dd = -
abs(dd);
548 if(lr == 1 ) dd =
abs(dd);
549 driftT = (*it_gothit)->getDriftT();
551 eangle = (*it_gothit)->getEntra();
552 eangle = eangle/
M_PI;
553 pathlength=exsvc->
PathL( ntpFlag, exhel, layid, localwid, zhit);
554 rphi_path=pathlength * sintheta;
557 ph=exsvc->
StandardHitCorrec(0,runFlag,ntpFlag,runNO,eventNO,pathlength,wid,layid,adc_raw,dd,eangle,
costheta);
562 if(runNO<=5911 && runNO>=5854 && layid ==14)
continue;
587 if (ph<0.0||ph==0)
continue;
601 if(m_rootfile!=
"no rootfile")
603 m_hitNo_wire->Fill(wid);
609 m_charge1 = (*trk)->charge();
615 m_localwid = localwid;
621 m_driftdist = driftD;
624 m_pathL = pathlength;
628 m_trackId1 = trk_ex.
trk_id();
629 StatusCode status2 = m_nt2->write();
630 if ( status2.isFailure() )
631 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
635 phlist.push_back(ph);
636 phlist_hit.push_back(ph_hit);
639 dedxhitList->push_back( dedxhit );
640 dedxhitrefvec->push_back( dedxhit );
645 ex_trks.push_back(trk_ex );
646 m_trkalgs.push_back(m_trkalg);
648 delete dedxhitrefvec;
653 log << MSG::DEBUG <<
"size in processing: " << ex_trks.size() <<endreq;
662 SmartDataPtr<RecMdcKalTrackCol> newtrkCol(eventSvc(),
"/Event/Recon/RecMdcKalTrackCol");
665 log << MSG::WARNING <<
"Could not find RecMdcKalTrackCol" << endreq;
666 return StatusCode::SUCCESS;
669 ntrk = newtrkCol->size();
670 log << MSG::DEBUG <<
"track collection size: " << newtrkCol->size() <<endreq;
672 vector<double> phlist;
673 vector<double> phlist_hit;
674 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;
675 int charge=0,layid=0,localwid=0,w0id=0,wid=0,lr=-2;
676 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;
678 double ph=0,ph_hit=0,pathlength=0,rphi_path=0;
681 RecMdcKalTrackCol::iterator trk = newtrkCol->begin();
682 for( ; trk != newtrkCol->end(); trk++)
687 log << MSG::DEBUG <<
" %%%%% trk id = "<<trk_ex.
trk_id() <<endreq;
688 log << MSG::DEBUG <<
" %%%%% initial id = "<<(*trk)->trackId() <<endreq;
692 if(ParticleFlag>-1&&ParticleFlag<5)
696 tkErrM = dstTrk->
getFError(ParticleFlag);
700 a = (*trk)->getFHelix();
701 tkErrM = (*trk)->getFError();
704 log << MSG::DEBUG <<
"FHelix 5 parameters: "<<a[0]<<
" "<<a[1] <<
" "<<a[2]<<
" "<<a[3]<<
" "<<a[4]<<endreq;
706 m_d0E = tkErrM[0][0];
707 m_phi0E = tkErrM[1][1];
708 m_cpaE = tkErrM[2][2];
709 m_z0E = tkErrM[3][3];
714 sintheta =
sin(M_PI_2-atan(a[4]));
715 m_Pt = 1.0/fabs( a[2] );
716 m_P = m_Pt*sqrt(1 + a[4]*a[4]);
718 charge = ( a[2] > 0 )? 1 : -1;
726 Nhits = gothits.size();
727 log << MSG::DEBUG <<
"hits size = " <<gothits.size()<<endreq;
730 delete dedxhitrefvec;
736 HelixSegRefVec::iterator it_gothit = gothits.begin();
737 for( ; it_gothit != gothits.end(); it_gothit++)
739 HepVector a_hit_in = (*it_gothit)->getHelixIncl();
744 p_hit = 1.0/fabs(a_hit_in(3))*sqrt(1+a_hit_in(5)*a_hit_in(5));
747 mdcid = (*it_gothit)->getMdcId();
751 wid = w0id + localwid;
752 adc_raw = (*it_gothit)->getAdc();
753 tdc_raw = (*it_gothit)->getTdc();
754 log << MSG::INFO <<
"hit layer id " <<layid<<
" wire id: " <<localwid<<
" adc_raw: " <<adc_raw<<
" tdc_raw: "<<tdc_raw<<endreq;
755 zhit = (*it_gothit)->getZhit();
756 lr = (*it_gothit)->getFlagLR();
757 if(lr == 2) cout<<
"lr = "<<lr<<endl;
758 driftD = (*it_gothit)->getDD();
759 driftd =
abs(driftD);
760 driftT = (*it_gothit)->getDT();
761 dd_in = (*it_gothit)->getDocaIncl();
762 dd_ex = (*it_gothit)->getDocaExcl();
764 if(lr==-1 || lr == 2) {dd_in = dd_in; dd_ex = dd_ex;}
765 else if(lr ==1) {dd_in = -dd_in; dd_ex = -dd_ex;}
769 eangle = (*it_gothit)->getEntra();
770 eangle = eangle/
M_PI;
771 pathlength=exsvc->
PathL( ntpFlag, exhel_hit_in, layid, localwid, zhit);
772 rphi_path=pathlength * sintheta;
774 ph=exsvc->
StandardHitCorrec(0,runFlag,ntpFlag,runNO,eventNO,pathlength,wid,layid,adc_raw,dd_in,eangle,
costheta);
779 if(runNO<=5911 && runNO>=5854 && layid ==14)
continue;
804 if (ph<0.0||ph==0)
continue;
818 if(m_rootfile!=
"no rootfile")
820 m_hitNo_wire->Fill(wid);
826 m_charge1 = (*trk)->charge();
832 m_localwid = localwid;
838 m_driftdist = driftD;
841 m_pathL = pathlength;
846 m_trackId1 = trk_ex.
trk_id();
847 StatusCode status2 = m_nt2->write();
848 if ( status2.isFailure() )
849 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
853 phlist.push_back(ph);
854 phlist_hit.push_back(ph_hit);
857 dedxhitList->push_back( dedxhit );
858 dedxhitrefvec->push_back( dedxhit );
863 ex_trks.push_back(trk_ex );
864 m_trkalgs.push_back(m_trkalg);
866 delete dedxhitrefvec;
871 log << MSG::DEBUG <<
"size in processing: " << ex_trks.size() <<endreq;
876 if( ntrk != ex_trks.size())
877 log << MSG::DEBUG <<
"ntrkCol size: "<<ntrk<<
" dedxtrk size: "<<ex_trks.size()<< endreq;
879 double poca_x=0,poca_y=0,poca_z=0;
881 int Nhit=0,Nphlisthit=0;
883 double phtm=0,median=0,geometric=0,geometric_trunc=0,harmonic=0,harmonic_trunc=0,transform=0,logtrunc=0;
886 float probpid_temp=-0.01,expect_temp=-0.01,sigma_temp=-0.01,chidedx_temp=-0.01;
888 double dEdx_meas_hit=0;
889 double dEdx_meas=0,dEdx_meas_esat=0,dEdx_meas_norun=0;
893 for(std::vector<MdcDedxTrk>::iterator it = ex_trks.begin(); it != ex_trks.end(); it++, idedxid++ )
895 log << MSG::DEBUG <<
"-------------------------------------------------------"<< endreq;
896 log << MSG::DEBUG <<
" trk id ="<< it->trk_id()<<
" : P ="<<it->P() <<
" Pt ="<<it->Pt()<<
" : theta ="<<it->theta() <<
" : phi ="<<it->phi()<<
" : charge = "<<it->charge()<<endreq;
897 log << MSG::DEBUG <<
"all hits on track: "<<it->nsample()<<
" phlist size: "<<it->get_phlist().size()<<endreq;
899 if(it->trk_ptr_kal()!=0)
901 poca_x = it->trk_ptr_kal()->x();
902 poca_y = it->trk_ptr_kal()->y();
903 poca_z = it->trk_ptr_kal()->z();
905 else if(it->trk_ptr()!=0)
907 poca_x = it->trk_ptr()->x();
908 poca_y = it->trk_ptr()->y();
909 poca_z = it->trk_ptr()->z();
913 sintheta =
sin(it->theta());
917 Nhit = it->nsample();
918 Nphlisthit = it->get_phlist_hit().size();
922 phtm = it->cal_dedx( truncate );
932 if(m_alg==1) dEdx_meas_hit = it->cal_dedx_bitrunc(truncate, 0, usedhit);
933 else if(m_alg==2) dEdx_meas_hit = it-> cal_dedx_transform(1);
934 else if(m_alg==3) dEdx_meas_hit = it->cal_dedx_log(1.0, 1);
935 else cout<<
"-------------Truncate Algorithm Error!!!------------------------"<<endl;
936 if(m_alg==1 && usedhit==0)
938 cout<<
"***************bad extrk with no hits!!!!!******************"<<endl;
942 usedhit = (int)(Nphlisthit*truncate);
946 dEdx_meas_esat = exsvc->
StandardTrackCorrec(1,runFlag, ntpFlag, runNO, eventNO, dEdx_meas_hit,
cos(it->theta()), tes );
947 dEdx_meas_norun = exsvc->
StandardTrackCorrec(2,runFlag, ntpFlag, runNO, eventNO, dEdx_meas_hit,
cos(it->theta()), tes );
948 log << MSG::INFO <<
"===================== " << endreq << endreq;
949 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;
950 log << MSG::INFO <<
"ptrk " <<
ptrk <<
" costhe " <<
costheta <<
" runno " << runNO <<
" evtno " << eventNO << endreq;
953 trk_recalg = m_trkalgs[idedxid];
956 it->set_dEdx( landau ,
dEdx_meas, trk_recalg, runFlag, vFlag , tes, Curve_Para, Sigma_Para, ex_calib);
964 if(it->pprob()[i]>probpid_temp)
967 probpid_temp = it->pprob()[i];
968 expect_temp = it->pexpect()[i];
969 sigma_temp = it->pexp_sigma()[i];
970 chidedx_temp = it->pchi_dedx()[i];
973 log<< MSG::INFO<<
"expect dE/dx: type: "<<parType_temp<<
" probpid: "<<probpid_temp<<
" expect: "<<expect_temp<<
" sigma: "<<sigma_temp<<
" chidedx: "<<chidedx_temp<<endreq;
988 resdedx->
setChi( it->pchi_dedx() );
1020 m_sintheta=sintheta;
1027 m_trackId = it->trk_id();
1028 m_recalg = trk_recalg;
1031 m_nphlisthit=Nphlisthit;
1033 for(
int i=0; i<Nphlisthit; i++) m_dEdx_hit[i] = it->get_phlist_hit()[i];
1035 m_parttype = parType_temp;
1036 m_prob = probpid_temp;
1037 m_expect = expect_temp;
1038 m_sigma = sigma_temp;
1039 m_chidedx = chidedx_temp;
1040 m_chidedxe=it->pchi_dedx()[0];
1041 m_chidedxmu=it->pchi_dedx()[1];
1042 m_chidedxpi=it->pchi_dedx()[2];
1043 m_chidedxk=it->pchi_dedx()[3];
1044 m_chidedxp=it->pchi_dedx()[4];
1045 for(
int i=0;i<5;i++)
1047 m_probpid[i]= it->pprob()[i];
1048 m_expectid[i]= it->pexpect()[i];
1049 m_sigmaid[i]= it->pexp_sigma()[i];
1052 StatusCode status = m_nt1->write();
1053 if ( status.isFailure() )
1055 log << MSG::ERROR <<
"Cannot fill Ntuple n103" << endreq;
1059 log<< MSG::INFO<<
"-----------------Summary of this ExTrack----------------"<<endreq
1060 <<
"dEdx_mean: "<<
dEdx_meas<<
" type: "<<parType_temp<<
" probpid: "<<probpid_temp
1061 <<
" expect: "<<expect_temp<<
" sigma: "<<sigma_temp<<
" chidedx: "<<chidedx_temp<<endreq<<endreq;
1063 dedxList->push_back( resdedx );
1069 SmartDataPtr<RecMdcDedxCol> newexCol(eventSvc(),
"/Event/Recon/RecMdcDedxCol");
1072 log << MSG::FATAL <<
"Could not find RecMdcDedxCol" << endreq;
1073 return( StatusCode::SUCCESS);
1075 log << MSG::DEBUG <<
"----------------Begin to check RecMdcDedxCol-----------------"<<endreq;
1076 RecMdcDedxCol::iterator it_dedx = newexCol->begin();
1077 for( ; it_dedx != newexCol->end(); it_dedx++)
1079 log << MSG::INFO <<
"retrieved MDC dE/dx:" << endreq
1080 <<
"dEdx Id: " << (*it_dedx)->trackId()
1081 <<
" part Id: " << (*it_dedx)->particleType()
1082 <<
" measured dEdx: " << (*it_dedx)->probPH()
1083 <<
" dEdx std: " << (*it_dedx)->normPH() << endreq
1084 <<
"hits on track: "<<(*it_dedx)->numTotalHits()
1085 <<
" usedhits: " << (*it_dedx)->numGoodHits() << endreq
1086 <<
"Electron: expect: " << (*it_dedx)->getDedxExpect(0)
1087 <<
" sigma: " << (*it_dedx)->getSigmaDedx(0)
1088 <<
" chi: " << (*it_dedx)->chi(0)
1089 <<
" prob: " << (*it_dedx)->getPidProb(0) << endreq
1090 <<
"Muon: expect: " << (*it_dedx)->getDedxExpect(1)
1091 <<
" sigma: " << (*it_dedx)->getSigmaDedx(1)
1092 <<
" chi: " << (*it_dedx)->chi(1)
1093 <<
" prob: " << (*it_dedx)->getPidProb(1) << endreq
1094 <<
"Pion: expect: " << (*it_dedx)->getDedxExpect(2)
1095 <<
" sigma: " << (*it_dedx)->getSigmaDedx(2)
1096 <<
" chi: " << (*it_dedx)->chi(2)
1097 <<
" prob: " << (*it_dedx)->getPidProb(2) << endreq
1098 <<
"Kaon: expect: " << (*it_dedx)->getDedxExpect(3)
1099 <<
" sigma: " << (*it_dedx)->getSigmaDedx(3)
1100 <<
" chi: " << (*it_dedx)->chi(3)
1101 <<
" prob: " << (*it_dedx)->getPidProb(3) << endreq
1102 <<
"Proton: expect: " << (*it_dedx)->getDedxExpect(4)
1103 <<
" sigma: " << (*it_dedx)->getSigmaDedx(4)
1104 <<
" chi: " << (*it_dedx)->chi(4)
1105 <<
" prob: " << (*it_dedx)->getPidProb(4) << endreq;
1107 return StatusCode::SUCCESS;
1119 vector<double> phlist;
1120 vector<double> phlist_hit;
1121 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;
1122 int charge=0,layid=0,localwid=0,w0id=0,wid=0,lr=-2;
1123 double adc_raw=0,tdc_raw=0,zhit=0,driftd=0,driftD=0,driftT=0,dd=0,eangle=0;
1125 double ph=0,ph_hit=0,pathlength=0,rphi_path=0;
1128 log << MSG::DEBUG <<
" %%%%% trk id = "<<trk_ex.
trk_id() <<endreq;
1129 log << MSG::DEBUG <<
" %%%%% initial id = "<<(*trk)->trackId() <<endreq;
1131 HepVector a = (*trk)->helix();
1132 HepSymMatrix tkErrM = (*trk)->err();
1133 m_d0E = tkErrM[0][0];
1134 m_phi0E = tkErrM[1][1];
1135 m_cpaE = tkErrM[2][2];
1136 m_z0E = tkErrM[3][3];
1140 log << MSG::DEBUG <<
"MDC Helix 5 parameters: "<<a[0]<<
" "<<a[1]<<
" "<<a[2]<<
" "<<a[3]<<
" "<<a[4]<<endreq;
1145 sintheta =
sin(M_PI_2-atan(a[4]));
1146 m_Pt = 1.0/fabs( a[2] );
1147 m_P = m_Pt*sqrt(1 + a[4]*a[4]);
1148 charge = ( a[2] > 0 )? 1 : -1;
1153 HitRefVec gothits= (*trk)->getVecHits();
1154 Nhits = gothits.size();
1155 log << MSG::DEBUG <<
"hits size = " <<gothits.size()<<endreq;
1159 HitRefVec::iterator it_gothit = gothits.begin();
1160 for( ; it_gothit != gothits.end(); it_gothit++)
1162 mdcid = (*it_gothit)->getMdcId();
1166 wid = w0id + localwid;
1167 adc_raw = (*it_gothit)->getAdc();
1168 tdc_raw = (*it_gothit)->getTdc();
1169 log << MSG::INFO <<
"hit layer id " <<layid<<
" wire id: " <<localwid<<
" adc_raw: " <<adc_raw<<
" tdc_raw: "<<tdc_raw<<endreq;
1170 zhit = (*it_gothit)->getZhit();
1171 lr = (*it_gothit)->getFlagLR();
1172 if(lr == 2) cout<<
"lr = "<<lr<<endl;
1173 if(lr == 0 || lr == 2) driftD = (*it_gothit)->getDriftDistLeft();
1174 else driftD = (*it_gothit)->getDriftDistRight();
1176 driftd =
abs(driftD);
1177 dd = (*it_gothit)->getDoca();
1178 if(lr == 0 || lr == 2 ) dd = -
abs(dd);
1179 if(lr == 1 ) dd =
abs(dd);
1180 driftT = (*it_gothit)->getDriftT();
1182 eangle = (*it_gothit)->getEntra();
1183 eangle = eangle/
M_PI;
1184 pathlength=exsvc->
PathL( ntpFlag, exhel, layid, localwid, zhit);
1185 rphi_path=pathlength * sintheta;
1188 ph=exsvc->
StandardHitCorrec(0,runFlag,ntpFlag,runNO,eventNO,pathlength,wid,layid,adc_raw,dd,eangle,
costheta);
1193 if(runNO<=5911 && runNO>=5854 && layid ==14)
continue;
1218 if (ph<0.0||ph==0)
continue;
1232 if(m_rootfile!=
"no rootfile")
1234 m_hitNo_wire->Fill(wid);
1240 m_charge1 = (*trk)->charge();
1243 m_tdc_raw = tdc_raw;
1246 m_localwid = localwid;
1252 m_driftdist = driftD;
1255 m_pathL = pathlength;
1259 m_trackId1 = trk_ex.
trk_id();
1260 StatusCode status2 = m_nt2->write();
1261 if ( status2.isFailure() )
1262 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
1266 phlist.push_back(ph);
1267 phlist_hit.push_back(ph_hit);
1270 dedxhitList->push_back( dedxhit );
1271 dedxhitrefvec->push_back( dedxhit );
1276 ex_trks.push_back(trk_ex );
1277 m_trkalgs.push_back(m_trkalg);
1279 delete dedxhitrefvec;
1288 vector<double> phlist;
1289 vector<double> phlist_hit;
1290 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;
1291 int charge=0,layid=0,localwid=0,w0id=0,wid=0,lr=-2;
1292 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;
1294 double ph=0,ph_hit=0,pathlength=0,rphi_path=0;
1297 log << MSG::DEBUG <<
" %%%%% trk id = "<<trk_ex.
trk_id() <<endreq;
1298 log << MSG::DEBUG <<
" %%%%% initial id = "<<(*trk)->trackId() <<endreq;
1301 HepSymMatrix tkErrM;
1302 if(ParticleFlag>-1&&ParticleFlag<5)
1306 tkErrM = dstTrk->
getFError(ParticleFlag);
1310 a = (*trk)->getFHelix();
1311 tkErrM = (*trk)->getFError();
1313 log << MSG::DEBUG <<
"FHelix 5 parameters: "<<a[0]<<
" "<<a[1] <<
" "<<a[2]<<
" "<<a[3]<<
" "<<a[4]<<endreq;
1316 m_d0E = tkErrM[0][0];
1317 m_phi0E = tkErrM[1][1];
1318 m_cpaE = tkErrM[2][2];
1319 m_z0E = tkErrM[3][3];
1324 sintheta =
sin(M_PI_2-atan(a[4]));
1325 m_Pt = 1.0/fabs( a[2] );
1326 m_P = m_Pt*sqrt(1 + a[4]*a[4]);
1328 charge = ( a[2] > 0 )? 1 : -1;
1336 Nhits = gothits.size();
1337 log << MSG::DEBUG <<
"hits size = " <<gothits.size()<<endreq;
1341 HelixSegRefVec::iterator it_gothit = gothits.begin();
1342 for( ; it_gothit != gothits.end(); it_gothit++)
1344 HepVector a_hit_in = (*it_gothit)->getHelixIncl();
1349 p_hit = 1.0/fabs(a_hit_in(3))*sqrt(1+a_hit_in(5)*a_hit_in(5));
1352 mdcid = (*it_gothit)->getMdcId();
1356 wid = w0id + localwid;
1357 adc_raw = (*it_gothit)->getAdc();
1358 tdc_raw = (*it_gothit)->getTdc();
1359 log << MSG::INFO <<
"hit layer id " <<layid<<
" wire id: " <<localwid<<
" adc_raw: " <<adc_raw<<
" tdc_raw: "<<tdc_raw<<endreq;
1360 zhit = (*it_gothit)->getZhit();
1361 lr = (*it_gothit)->getFlagLR();
1362 if(lr == 2) cout<<
"lr = "<<lr<<endl;
1363 driftD = (*it_gothit)->getDD();
1364 driftd =
abs(driftD);
1365 driftT = (*it_gothit)->getDT();
1366 dd_in = (*it_gothit)->getDocaIncl();
1367 dd_ex = (*it_gothit)->getDocaExcl();
1369 if(lr==-1 || lr == 2) {dd_in = dd_in; dd_ex = dd_ex;}
1370 else if(lr ==1) {dd_in = -dd_in; dd_ex = -dd_ex;}
1374 eangle = (*it_gothit)->getEntra();
1375 eangle = eangle/
M_PI;
1376 pathlength=exsvc->
PathL( ntpFlag, exhel_hit_in, layid, localwid, zhit);
1377 rphi_path=pathlength * sintheta;
1380 ph=exsvc->
StandardHitCorrec(0,runFlag,ntpFlag,runNO,eventNO,pathlength,wid,layid,adc_raw,dd_in,eangle,
costheta);
1388 if(runNO<=5911 && runNO>=5854 && layid ==14)
continue;
1413 if (ph<0.0||ph==0)
continue;
1427 if(m_rootfile!=
"no rootfile")
1429 m_hitNo_wire->Fill(wid);
1435 m_charge1 = (*trk)->charge();
1438 m_tdc_raw = tdc_raw;
1441 m_localwid = localwid;
1447 m_driftdist = driftD;
1450 m_pathL = pathlength;
1455 m_trackId1 = trk_ex.
trk_id();
1456 StatusCode status2 = m_nt2->write();
1457 if ( status2.isFailure() )
1458 log << MSG::ERROR <<
"Cannot fill Ntuple n102" << endreq;
1462 phlist.push_back(ph);
1463 phlist_hit.push_back(ph_hit);
1466 dedxhitList->push_back( dedxhit );
1467 dedxhitrefvec->push_back( dedxhit );
1472 ex_trks.push_back(trk_ex );
1473 m_trkalgs.push_back(m_trkalg);
1475 delete dedxhitrefvec;
1484 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
1487 log << MSG::WARNING <<
"Could not find RecMdcTrackCol in switchtomdctrack" << endreq;
1491 RecMdcTrackCol::iterator trk = newtrkCol->begin();
1492 for( ; trk != newtrkCol->end(); trk++)
1494 if( (*trk)->trackId()==trkid)
1496 HitRefVec gothits= (*trk)->getVecHits();
1497 if(gothits.size()>=2)
1498 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
MdcDedxRecon(const std::string &name, ISvcLocator *pSvcLocator)
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