1#include "CgemMdcCombAlg/CgemMdcCombAlg.h"
2#include "GaudiKernel/IDataManagerSvc.h"
3#include "GaudiKernel/SmartDataPtr.h"
4#include "GaudiKernel/IDataProviderSvc.h"
5#include "GaudiKernel/IPartPropSvc.h"
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/AlgFactory.h"
8#include "GaudiKernel/ISvcLocator.h"
9#include "GaudiKernel/DataSvc.h"
10#include "GaudiKernel/PropertyMgr.h"
11#include "GaudiKernel/Bootstrap.h"
12#include "GaudiKernel/INTupleSvc.h"
15#include "EventModel/EventHeader.h"
16#include "CLHEP/Units/PhysicalConstants.h"
18#include "HepPDT/ParticleDataTable.hh"
19#include "HepPDT/ParticleData.hh"
21#include "EventModel/Event.h"
22#include "EvTimeEvent/RecEsTime.h"
23#include "EvtRecEvent/EvtRecEvent.h"
24#include "EvtRecEvent/EvtRecTrack.h"
25#include "Identifier/Identifier.h"
26#include "RawDataProviderSvc/IRawDataProviderSvc.h"
27#include "RawDataProviderSvc/MdcRawDataProvider.h"
28#include "RawDataProviderSvc/RawDataProviderSvc.h"
29#include "CLHEP/Vector/ThreeVector.h"
30#include "CLHEP/Matrix/Vector.h"
31#include "CLHEP/Matrix/SymMatrix.h"
32#include "CLHEP/Geometry/Point3D.h"
33#include "CLHEP/Vector/LorentzVector.h"
37#include "KalFitAlg/helix/Helix.h"
39#include "CLHEP/Matrix/Matrix.h"
41#include "CgemGeomSvc/CgemGeomSvc.h"
42#include "CgemRecEvent/RecCgemCluster.h"
43#include "CgemRecEvent/RecCgemSegment.h"
44#include "CgemMdcCombAlg/CgemMdcCombAlg.h"
45#include "McTruth/CgemMcHit.h"
47#include "MdcRecEvent/RecMdcTrack.h"
48#include "MdcRecEvent/RecMdcHit.h"
68 Algorithm(name, pSvcLocator)
70 declareProperty(
"debug", m_debug = 0);
71 declareProperty(
"prodNT", m_prodNT = 0);
72 declareProperty(
"dropHot", m_dropHot= 1);
73 declareProperty(
"combineTracking",m_combineTracking=0);
74 declareProperty(
"keepBadTdc",m_keepBadTdc=0);
75 declareProperty(
"keepUnmatch",m_keepUnmatch=1);
76 declareProperty(
"dr_par",m_dr_par);
77 declareProperty(
"phi0_par",m_phi0_par);
78 declareProperty(
"kappa_par",m_kappa_par);
79 declareProperty(
"dz_par",m_dz_par);
80 declareProperty(
"tanl_par",m_tanl_par);
81 declareProperty(
"Pt",m_Pt);
82 declareProperty(
"w_dr",m_w_dr);
83 declareProperty(
"w_phi0",m_w_phi0);
84 declareProperty(
"w_kappa",m_w_kappa);
85 declareProperty(
"w_dz",m_w_dz);
86 declareProperty(
"w_tanl",m_w_tanl);
88 declareProperty(
"P_T", mv_Pt);
89 declareProperty(
"mean_dr", mv_mean_dr);
90 declareProperty(
"mean_phi0", mv_mean_phi0);
91 declareProperty(
"mean_kappa",mv_mean_kappa);
92 declareProperty(
"mean_dz", mv_mean_dz);
93 declareProperty(
"mean_tanL", mv_mean_tanL);
94 declareProperty(
"sig_dr", mv_sig_dr);
95 declareProperty(
"sig_phi0", mv_sig_phi0);
96 declareProperty(
"sig_kappa", mv_sig_kappa);
97 declareProperty(
"sig_dz", mv_sig_dz);
98 declareProperty(
"sig_tanL", mv_sig_tanL);
100 declareProperty(
"matchChi2Cut", mv_matchChi2Cut);
107 MsgStream log(
msgSvc(), name());
108 log << MSG::INFO <<
"in initialize()" << endreq;
113 StatusCode sc = service(
"NTupleSvc",
ntupleSvc);
114 NTuplePtr mt(
ntupleSvc,
"FILE199/CgemMdcComb");
115 if ( mt ) match_ntuple = mt;
117 match_ntuple =
ntupleSvc->book(
"FILE199/CgemMdcComb", CLID_ColumnWiseTuple,
"match");
120 status = match_ntuple->addItem(
"run", run);
121 status = match_ntuple->addItem(
"evt", evt);
122 status = match_ntuple->addItem(
"costhetaMC", costhetaMC);
123 status = match_ntuple->addItem(
"phiMC", phiMC);
124 status = match_ntuple->addItem(
"pdgMC", pdgMC);
125 status = match_ntuple->addItem(
"truth_dr", truth_dr);
126 status = match_ntuple->addItem(
"truth_dz", truth_dz);
127 status = match_ntuple->addItem(
"truth_phi0", truth_phi0);
128 status = match_ntuple->addItem(
"truth_kappa", truth_kappa);
129 status = match_ntuple->addItem(
"truth_tanl", truth_tanl);
130 status = match_ntuple->addItem(
"track_size",track_size,0,1000);
131 status = match_ntuple->addIndexedItem(
"matched", track_size, CgemSegMatched);
132 status = match_ntuple->addIndexedItem(
"dr_avg", track_size, dr_avg);
133 status = match_ntuple->addIndexedItem(
"dz_avg", track_size, dz_avg);
134 status = match_ntuple->addIndexedItem(
"tanL_avg", track_size, tanL_avg);
135 status = match_ntuple->addItem(
"segment_size",segment_size,0,1000);
136 status = match_ntuple->addIndexedItem(
"fit_failed", segment_size , match_failed);
137 status = match_ntuple->addItem(
"nMatch",match_nsegment,0,1000);
138 status = match_ntuple->addIndexedItem(
"chisq_dr", match_nsegment , match_dr_chisq);
139 status = match_ntuple->addIndexedItem(
"chisq_phi0", match_nsegment , match_phi0_chisq);
140 status = match_ntuple->addIndexedItem(
"chisq_kappa", match_nsegment , match_kappa_chisq);
141 status = match_ntuple->addIndexedItem(
"chisq_tanl", match_nsegment , match_tanl_chisq);
142 status = match_ntuple->addIndexedItem(
"chisq_dz", match_nsegment , match_dz_chisq);
143 status = match_ntuple->addIndexedItem(
"IsTruth", match_nsegment , match_IsTruth);
144 status = match_ntuple->addIndexedItem(
"track_dr", match_nsegment , track_dr);
145 status = match_ntuple->addIndexedItem(
"track_phi0", match_nsegment , track_phi0);
146 status = match_ntuple->addIndexedItem(
"track_kappa", match_nsegment , track_kappa);
147 status = match_ntuple->addIndexedItem(
"track_tanl", match_nsegment , track_tanl);
148 status = match_ntuple->addIndexedItem(
"track_dz", match_nsegment , track_dz);
149 status = match_ntuple->addIndexedItem(
"track_dr_err", match_nsegment , track_dr_err);
150 status = match_ntuple->addIndexedItem(
"track_phi0_err", match_nsegment , track_phi0_err);
151 status = match_ntuple->addIndexedItem(
"track_kappa_err", match_nsegment , track_kappa_err);
152 status = match_ntuple->addIndexedItem(
"track_tanl_err", match_nsegment , track_tanl_err);
153 status = match_ntuple->addIndexedItem(
"track_dz_err", match_nsegment , track_dz_err);
154 status = match_ntuple->addIndexedItem(
"seg_dr", match_nsegment , seg_dr);
155 status = match_ntuple->addIndexedItem(
"seg_phi0", match_nsegment , seg_phi0);
156 status = match_ntuple->addIndexedItem(
"seg_kappa", match_nsegment , seg_kappa);
157 status = match_ntuple->addIndexedItem(
"seg_tanl", match_nsegment , seg_tanl);
158 status = match_ntuple->addIndexedItem(
"seg_dz", match_nsegment , seg_dz);
159 status = match_ntuple->addIndexedItem(
"seg_dr_err", match_nsegment , seg_dr_err);
160 status = match_ntuple->addIndexedItem(
"seg_phi0_err", match_nsegment , seg_phi0_err);
161 status = match_ntuple->addIndexedItem(
"seg_kappa_err", match_nsegment , seg_kappa_err);
162 status = match_ntuple->addIndexedItem(
"seg_tanl_err", match_nsegment , seg_tanl_err);
163 status = match_ntuple->addIndexedItem(
"seg_dz_err", match_nsegment , seg_dz_err);
185 cout<<
"mv_Pt.size="<<mv_Pt.size()<<endl;
186 m_nPt = mv_Pt.size();
187 cout<<
"pt[0]="<<mv_Pt[0]<<
", pt[npt-1]="<<mv_Pt[m_nPt-1]<<endl;
188 if(mv_mean_dr.size()==m_nPt) mg_mean_dr =
new TGraph(m_nPt, &mv_Pt[0], &mv_mean_dr[0]);
189 else cout<<
"size of mean_dr != size of PT !"<<endl;
191 if(mv_mean_phi0.size()==m_nPt) mg_mean_phi0 =
new TGraph(m_nPt, &mv_Pt[0], &mv_mean_phi0[0]);
192 else cout<<
"size of mean_phi0 != size of PT !"<<endl;
194 if(mv_mean_kappa.size()==m_nPt)mg_mean_kappa=
new TGraph(m_nPt, &mv_Pt[0], &mv_mean_kappa[0]);
195 else cout<<
"size of mean_kappa != size of PT !"<<endl;
197 if(mv_mean_dz.size()==m_nPt) mg_mean_dz =
new TGraph(m_nPt, &mv_Pt[0], &mv_mean_dz[0]);
198 else cout<<
"size of mean_dz != size of PT !"<<endl;
200 if(mv_mean_tanL.size()==m_nPt) mg_mean_tanL =
new TGraph(m_nPt, &mv_Pt[0], &mv_mean_tanL[0]);
201 else cout<<
"size of mean_tanL != size of PT !"<<endl;
203 if(mv_sig_dr.size()==m_nPt) mg_sig_dr =
new TGraph(m_nPt, &mv_Pt[0], &mv_sig_dr[0]);
204 else cout<<
"size of sig_dr != size of PT !"<<endl;
206 if(mv_sig_phi0.size()==m_nPt) mg_sig_phi0 =
new TGraph(m_nPt, &mv_Pt[0], &mv_sig_phi0[0]);
207 else cout<<
"size of sig_phi0 != size of PT !"<<endl;
209 if(mv_sig_kappa.size()==m_nPt) mg_sig_kappa =
new TGraph(m_nPt, &mv_Pt[0], &mv_sig_kappa[0]);
210 else cout<<
"size of sig_kappa != size of PT !"<<endl;
212 if(mv_sig_dz.size()==m_nPt) mg_sig_dz =
new TGraph(m_nPt, &mv_Pt[0], &mv_sig_dz[0]);
213 else cout<<
"size of sig_dz != size of PT !"<<endl;
215 if(mv_sig_tanL.size()==m_nPt) mg_sig_tanL =
new TGraph(m_nPt, &mv_Pt[0], &mv_sig_tanL[0]);
216 else cout<<
"size of sig_tanL != size of PT !"<<endl;
219 return StatusCode::SUCCESS;
227 return StatusCode::SUCCESS;
230void CgemMdcCombAlg::getMcPar() {
231 MsgStream log(
msgSvc(), name());
232 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
233 if (!mcParticleCol) {
234 log << MSG::ERROR<<
"Could not find McParticle" << endreq;
236 if(m_debug==1) cout<<
"size_mcParticleCol "<<mcParticleCol->size()<< endl;
237 McParticleCol::iterator iter_mc = mcParticleCol->begin();
238 for (;iter_mc != mcParticleCol->end(); iter_mc++ ) {
240 int pdg=(*iter_mc)->particleProperty();
244 if(!findJpsi)
continue;
247 if(pdg<0)mc_charge = 1.;
249 double truth_x = (*iter_mc)->initialPosition().x();
250 double truth_y = (*iter_mc)->initialPosition().y();
251 double truth_z = (*iter_mc)->initialPosition().z();
253 double px = (*iter_mc)->initialFourMomentum().px();
254 double py = (*iter_mc)->initialFourMomentum().py();
255 double pz = (*iter_mc)->initialFourMomentum().pz();
257 HepPoint3D truth_position(truth_x, truth_y, truth_z);
258 Hep3Vector p3(px, py, pz);
261 tmp_helix->
pivot(tmp_pivot);
264 truth_dr = tmp_helix->
dr();
265 truth_dz = tmp_helix->
dz();
266 truth_phi0 = tmp_helix->
phi0();
267 truth_kappa = tmp_helix->
kappa();
268 truth_tanl = tmp_helix->
tanl();
270 costhetaMC = pz/sqrt(pow(px,2)+pow(py,2)+pow(pz,2));
279StatusCode CgemMdcCombAlg::exe_v1()
281 MsgStream log(
msgSvc(), name());
282 log << MSG::INFO <<
"in excute()" << endreq;
285 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
287 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
288 return StatusCode::FAILURE;
290 evt = eventHeader->eventNumber();
292 SmartDataPtr<RecCgemSegmentCol> recCgemSegmentCol(eventSvc(),
"/Event/Recon/RecCgemSegmentCol");
293 if (!recCgemSegmentCol){
294 log << MSG::WARNING <<
"Could not retrieve Cgem segment list" << endreq;
296 return StatusCode::SUCCESS;
301 StatusCode sc = service (
"RawDataProviderSvc", irawDataProviderSvc);
303 if ( sc.isFailure() ){
304 log << MSG::FATAL <<
"Could not load RawDataProviderSvc!" << endreq;
305 return StatusCode::FAILURE;
308 uint32_t getDigiFlag = 0;
313 if (0 == mdcDigiVec.size()){
314 log << MSG::WARNING <<
" No hits in MdcDigiVec" << endreq;
318 MdcDigiVec::iterator itDigi = mdcDigiVec.begin();
321 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
322 if (!recMdcTrackCol){
323 log << MSG::WARNING <<
"Could not find RecMdcTrackCol" << endreq;
325 return StatusCode::SUCCESS;
328 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
329 if (!mcParticleCol) {
330 log << MSG::ERROR<<
"Could not find McParticle" << endreq;
332 if(m_debug==1) cout<<
"size_mcParticleCol "<<mcParticleCol->size()<< endl;
333 McParticleCol::iterator iter_mc = mcParticleCol->begin();
334 for (;iter_mc != mcParticleCol->end(); iter_mc++ ) {
336 int pdg=(*iter_mc)->particleProperty();
340 if(!findJpsi)
continue;
343 if(pdg<0)mc_charge = 1.;
345 double truth_x = (*iter_mc)->initialPosition().x();
346 double truth_y = (*iter_mc)->initialPosition().y();
347 double truth_z = (*iter_mc)->initialPosition().z();
349 double px = (*iter_mc)->initialFourMomentum().px();
350 double py = (*iter_mc)->initialFourMomentum().py();
351 double pz = (*iter_mc)->initialFourMomentum().pz();
353 HepPoint3D truth_position(truth_x, truth_y, truth_z);
354 Hep3Vector p3(px, py, pz);
357 tmp_helix->
pivot(tmp_pivot);
358 truth_dr = tmp_helix->
dr();
359 truth_dz = tmp_helix->
dz();
360 truth_phi0 = tmp_helix->
phi0();
361 truth_kappa = tmp_helix->
kappa();
362 truth_tanl = tmp_helix->
tanl();
364 costhetaMC = pz/sqrt(pow(px,2)+pow(py,2)+pow(pz,2));
374 for(;itDigi != mdcDigiVec.end(); itDigi++){
381 RecCgemSegmentCol::iterator itSeg = recCgemSegmentCol->begin();
382 for(match_nsegment = 0, segment_size = 0;itSeg != recCgemSegmentCol->end(); itSeg++, segment_size++){
383 RecMdcTrackCol::iterator itTrk = recMdcTrackCol->begin();
384 if((*itSeg)->gethelix(1) < -900) match_failed[segment_size] = 0;
385 else match_failed[segment_size] = 1;
386 for(track_size = 0;itTrk != recMdcTrackCol->end(); itTrk++, track_size++, match_nsegment++){
388 match_dr_chisq[match_nsegment] = GetSigChisq((*itSeg)->gethelix(0), (*itTrk)->helix(0), (*itSeg)->gethelix_err(0) + (*itTrk)->err(0));
389 match_phi0_chisq[match_nsegment] = GetSigChisq((*itSeg)->gethelix(1), (*itTrk)->helix(1), (*itSeg)->gethelix_err(5) + (*itTrk)->err(5));
390 match_kappa_chisq[match_nsegment] = GetSigChisq((*itSeg)->gethelix(2), (*itTrk)->helix(2), (*itSeg)->gethelix_err(9) + (*itTrk)->err(9));
391 match_dz_chisq[match_nsegment] = GetSigChisq((*itSeg)->gethelix(3), (*itTrk)->helix(3), (*itSeg)->gethelix_err(12) + (*itTrk)->err(12));
392 match_tanl_chisq[match_nsegment] = GetSigChisq((*itSeg)->gethelix(4), (*itTrk)->helix(4), (*itSeg)->gethelix_err(14) + (*itTrk)->err(14));
394 double cut[5];
double pt_tmp;
395 if((*itTrk)->helix(2) != 0) pt_tmp = 1./(*itTrk)->helix(2);
397 log << MSG::FATAL <<
"The p_t of track is 0!!!" << endreq;
398 return StatusCode::FAILURE;
400 cut[0] = GetWindowChisq(pt_tmp, m_Pt, m_w_dr);
401 cut[1] = GetWindowChisq(pt_tmp, m_Pt, m_w_phi0);
402 cut[2] = GetWindowChisq(pt_tmp, m_Pt, m_w_kappa);
403 cut[3] = GetWindowChisq(pt_tmp, m_Pt, m_w_dz);
404 cut[4] = GetWindowChisq(pt_tmp, m_Pt, m_w_tanl);
417 if(match_dr_chisq[match_nsegment]>
cut[0]||
418 match_phi0_chisq[match_nsegment]>
cut[1]||
419 match_kappa_chisq[match_nsegment]>
cut[2]||
420 match_dz_chisq[match_nsegment]>
cut[3]||
421 match_tanl_chisq[match_nsegment]>
cut[4])EvOutWindow++;
424 match_IsTruth[match_nsegment] = (*itSeg)->getmatch();
426 track_dr[match_nsegment] = (*itTrk)->helix(0);
427 track_phi0[match_nsegment] = (*itTrk)->helix(1);
428 track_kappa[match_nsegment] = (*itTrk)->helix(2);
429 track_dz[match_nsegment] = (*itTrk)->helix(3);
430 track_tanl[match_nsegment] = (*itTrk)->helix(4);
431 track_dr_err[match_nsegment] = (*itTrk)->err(0);
432 track_phi0_err[match_nsegment] = (*itTrk)->err(5);
433 track_kappa_err[match_nsegment] = (*itTrk)->err(9);
434 track_dz_err[match_nsegment] = (*itTrk)->err(12);
435 track_tanl_err[match_nsegment] = (*itTrk)->err(14);
436 seg_dr[match_nsegment] = (*itSeg)->gethelix(0);
437 seg_phi0[match_nsegment] = (*itSeg)->gethelix(1);
438 seg_kappa[match_nsegment] = (*itSeg)->gethelix(2);
439 seg_dz[match_nsegment] = (*itSeg)->gethelix(3);
440 seg_tanl[match_nsegment] = (*itSeg)->gethelix(4);
441 seg_dr_err[match_nsegment] = (*itSeg)->gethelix_err(0);
442 seg_phi0_err[match_nsegment] = (*itSeg)->gethelix_err(5);
443 seg_kappa_err[match_nsegment] = (*itSeg)->gethelix_err(9);
444 seg_dz_err[match_nsegment] = (*itSeg)->gethelix_err(12);
445 seg_tanl_err[match_nsegment] = (*itSeg)->gethelix_err(14);
458 match_ntuple->write();
460 return StatusCode::SUCCESS;
464StatusCode CgemMdcCombAlg::exe_v2()
466 MsgStream log(
msgSvc(), name());
467 log << MSG::INFO <<
"in excute()" << endreq;
468 if(m_debug) cout<<
"--- CgemMdcCombAlg::exe ---"<<endl;
470 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
472 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
473 return StatusCode::FAILURE;
475 m_run = eventHeader->runNumber();
476 if(m_run<0&&m_prodNT) getMcPar();
477 m_evt = eventHeader->eventNumber();
479 SmartDataPtr<RecCgemClusterCol> recCgemClusterCol(eventSvc(),
"/Event/Recon/RecCgemClusterCol");
480 if (!recCgemClusterCol){
481 log << MSG::WARNING <<
"Could not retrieve Cgem Cluster list" << endreq;
484 SmartDataPtr<RecCgemSegmentCol> recCgemSegmentCol(eventSvc(),
"/Event/Recon/RecCgemSegmentCol");
486 if (recCgemSegmentCol){
487 nCgemSeg = recCgemSegmentCol->size();
490 log << MSG::WARNING <<
"Could not retrieve Cgem segment list" << endreq;
491 return StatusCode::SUCCESS;
493 if(m_debug) cout<<
"nCgemSeg = "<<nCgemSeg<<endl;
495 RecCgemSegmentCol::iterator itCgemSeg = recCgemSegmentCol->begin();
497 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
500 nMDCTrk = recMdcTrackCol->size();
503 log << MSG::WARNING <<
"Could not find RecMdcTrackCol" << endreq;
504 return StatusCode::SUCCESS;
506 if(m_debug) cout<<
"nMDCTrk = "<<nMDCTrk<<endl;
518 if(m_prodNT) {match_nsegment=0;}
521 RecMdcTrackCol::iterator itTrk = recMdcTrackCol->begin();
523 for(;itTrk != recMdcTrackCol->end(); itTrk++, i_ODC++)
525 RecCgemSegmentCol::iterator itCgemSegMatched;
526 RecCgemSegmentCol::iterator itCgemSeg = recCgemSegmentCol->begin();
527 for(; itCgemSeg!=recCgemSegmentCol->end(); itCgemSeg++)
531 if((*itTrk)->helix(2) != 0) pt=1./(*itTrk)->helix(2);
533 bool matched[5]={
true,
true,
true,
true,
true};
534 bool matchSig =
true;
535 bool matchedSig[5]={
true,
true,
true,
true,
true};
536 double totChi2(0), totChi2InXY(0), totChi2PhiTheta(0), totChi2PhiThetaKappa(0);
537 double chi2_Sig[5] = {9999, 9999, 9999, 9999, 9999};
538 for(
int i=0; i<5; i++)
541 double parSeg = (*itCgemSeg)->gethelix(i);
542 double parTrk = (*itTrk)->helix(i);
544 double delta=parSeg-parTrk;
546 while(delta> CLHEP::pi) delta-=CLHEP::twopi;
547 while(delta<-CLHEP::pi) delta+=CLHEP::twopi;
549 double chi2_new = Chi2Match(delta, pt, i);
550 chi2_Sig[i]=chi2_new;
551 if(chi2_new>mv_matchChi2Cut[i])
556 if(i==1||i==4||i==2) totChi2PhiThetaKappa+=chi2_new;
557 double errSqTot = (*itCgemSeg)->gethelix_err(i_err)+(*itTrk)->err(i_err);
558 double chi2Match = GetSigChisq(parSeg, parTrk, errSqTot);
560 if(i<3) totChi2InXY+=chi2Match;
561 if(i==1||i==4) totChi2PhiTheta+=chi2Match;
562 double cut = GetWindowChisq(pt, i);
568 if(m_debug) cout<<
"i, seg, trk, chi2Match = "<<i<<
", "<<parSeg<<
", "<<parTrk<<
", "<<chi2Match<<endl;
570 if(m_prodNT&&match_nsegment<1000) {
573 match_dr_chisq[match_nsegment]=chi2Match;
574 track_dr[match_nsegment]=parTrk;
575 seg_dr[match_nsegment]=parSeg;
578 match_phi0_chisq[match_nsegment]=chi2Match;
579 track_phi0[match_nsegment]=parTrk;
580 seg_phi0[match_nsegment]=parSeg;
583 match_kappa_chisq[match_nsegment]=chi2Match;
584 track_kappa[match_nsegment]=parTrk;
585 seg_kappa[match_nsegment]=parSeg;
588 match_dz_chisq[match_nsegment]=chi2Match;
589 track_dz[match_nsegment]=parTrk;
590 seg_dz[match_nsegment]=parSeg;
593 match_tanl_chisq[match_nsegment]=chi2Match;
594 track_tanl[match_nsegment]=parTrk;
595 seg_tanl[match_nsegment]=parSeg;
602 if(m_prodNT&&match_nsegment<1000) match_nsegment++;
603 bool matchedInXY = matched[0]*matched[1]*matched[2];
604 bool matchPhiTheta = matched[1]*matched[4];
606 cout<<
"matched "<<match<<endl;
607 cout<<
"matched only in r-phi: "<<matchedInXY<<endl;
608 cout<<
"matched only in phi-theta: "<<matchPhiTheta<<endl;
609 cout<<
"match with sigma "<<matchSig<<endl;
610 cout<<
"match with sigma [] "<<matchedSig[0]<<matchedSig[1]<<matchedSig[2]<<matchedSig[3]<<matchedSig[4]<<endl;
611 cout<<
"chi2 match with sigma [] "<<chi2_Sig[0]<<
", "<<chi2_Sig[1]<<
", "<<chi2_Sig[2]<<
", "<<chi2_Sig[3]<<
", "<<chi2_Sig[4]<<endl;
613 bool matchFlag = matchSig;
614 double matchChi2 = totChi2PhiThetaKappa;
617 if(m_prodNT) CgemSegMatched[i_ODC]=1;
619 if( (*itTrk)->getNcluster() == 0 ||
620 ((*itTrk)->getNcluster()!= 0 && (*itTrk)->getMatchChi2()>matchChi2) )
623 RecCgemClusterCol::iterator itClusterBegin = recCgemClusterCol->begin();
624 int trkid = (*itTrk)->trackId();
625 (*(itClusterBegin+(*itCgemSeg)->getclusterid_1()))->setTrkId(trkid);
626 (*(itClusterBegin+(*itCgemSeg)->getclusterid_2()))->setTrkId(trkid);
627 (*(itClusterBegin+(*itCgemSeg)->getclusterid_3()))->setTrkId(trkid);
628 vecclusters.push_back(*(itClusterBegin+(*itCgemSeg)->getclusterid_1()));
629 vecclusters.push_back(*(itClusterBegin+(*itCgemSeg)->getclusterid_2()));
630 vecclusters.push_back(*(itClusterBegin+(*itCgemSeg)->getclusterid_3()));
631 (*itTrk)->setVecClusters(vecclusters);
632 (*itTrk)->setNcluster(vecclusters.size());
633 (*itTrk)->setMatchChi2(matchChi2);
634 (*itTrk)->setNdof( (*itTrk)->ndof() + vecclusters.size() );
635 (*itTrk)->setNster( (*itTrk)->nster() + vecclusters.size() );
636 (*itTrk)->setFirstLayer(0);
637 (*itTrk)->setNlayer( (*itTrk)->nlayer() + vecclusters.size() );
638 (*itTrk)->setNCgemXCluster(vecclusters.size());
639 (*itTrk)->setNCgemVCluster(vecclusters.size());
640 itCgemSegMatched = itCgemSeg;
646 if((*itTrk)->getNcluster()!= 0)
648 HepVector a_trk = (*itTrk)->helix();
649 int iPar[3]={0, 3, 4};
650 HepSymMatrix parTrkErMat = (*itTrk)->err();
652 for(
int i=0; i<3; i++)
655 double parSeg = (*itCgemSegMatched)->gethelix(j);
656 double parSegEr = (*itCgemSegMatched)->gethelix_err(j*(11-j)/2);
657 double parTrk = (*itTrk)->helix(j);
658 double parTrkEr = parTrkErMat(j+1,j+1);
660 double parAverage = (parSeg/parSegEr+parTrk/parTrkEr)/(1./parSegEr+1./parTrkEr);
665 if(i==0) dr_avg[i_ODC]=parAverage;
666 if(i==1) dz_avg[i_ODC]=parAverage;
667 if(i==2) tanL_avg[i_ODC]=parAverage;
670 (*itTrk)->setHelix(a_trk);
675 dr_avg[i_ODC]=(*itTrk)->helix(0);
676 dz_avg[i_ODC]=(*itTrk)->helix(3);
677 tanL_avg[i_ODC]=(*itTrk)->helix(4);
686 cout<<
"After match:"<<endl;
694 segment_size=nCgemSeg;
695 match_ntuple->write();
698 return StatusCode::SUCCESS;
701double CgemMdcCombAlg::GetSigChisq(
double x,
double y,
double err) {
702 return pow(x -y, 2)/err;
705double CgemMdcCombAlg::GetWindowChisq(
double pt,
double a0,
double a1,
double a2,
double a3) {
706 return a0+a1*pt+a2*pt*pt+a3*pt*pt*pt;
709double CgemMdcCombAlg::GetWindowChisq(
double pt, vector<double> Pt, vector<double> w_p) {
711 double tmp_pt[
n];
double tmp_p[
n];
713 for(
int mm = 0; mm!=
n; mm++){
717 TGraph *tmp_w =
new TGraph(
n,tmp_pt,tmp_p);
718 double y = tmp_w->Eval(fabs(pt));
724double CgemMdcCombAlg::GetWindowChisq(
double pt,
int i_par)
726 vector<double> w_par;
746 cout<<
"CgemMdcCombAlg::GetWindowChisq() wrong i_par! "<<endl;
751 return GetWindowChisq(pt, m_Pt, w_par);
756double CgemMdcCombAlg::GetTotChisq(
double seg[5],
double trk[5],
double err[15]) {
757 HepMatrix delta_Par(5,1);
758 HepSymMatrix ParErr(5);
760 for(
int i = 0;i<5;i++){
761 delta_Par(i+1,1) = seg[i] - trk[i];
762 for(
int j = i; j<5;j++){
763 ParErr(i+1,j+1) = err[m];
764 if(i!=j)ParErr(j+1,i+1) = ParErr(i+1,j+1);
770 double chisq = (ParErr.similarityT(delta_Par)).determinant();
771 if(!ierr)
return chisq;
775double CgemMdcCombAlg::Chi2Match(
double delta,
double pt,
int iPar)
779 if(pt>mv_Pt[m_nPt-1]) pt=mv_Pt[m_nPt-1];
790 g_mean = mg_mean_phi0;
794 g_mean = mg_mean_kappa;
795 g_sig = mg_sig_kappa;
802 g_mean = mg_mean_tanL;
807 cout<<
"CgemMdcCombAlg::Chi2Match() wrong iPar! "<<endl;
811 double mean = g_mean->Eval(pt);
812 double sigma = g_sig->Eval(pt);
813 double chi2 = pow((delta-mean)/sigma,2.0);
822 MsgStream log(
msgSvc(), name());
823 log << MSG::INFO <<
"in finalize()" << endreq;
831 if(m_nPt)
delete mg_mean_dr;
832 if(mg_mean_phi0)
delete mg_mean_phi0;
833 delete mg_mean_kappa;
842 return StatusCode::SUCCESS;
845void CgemMdcCombAlg::printMdcTrk()
847 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
849 if (!recMdcTrackCol){
850 cout<<
"printMdcTrk() can not find RecMdcTrackCol"<<endl;
854 int nMDCTrk = recMdcTrackCol->size();
855 RecMdcTrackCol::iterator itTrk = recMdcTrackCol->begin();
858 for(;itTrk != recMdcTrackCol->end(); itTrk++, i_ODC++)
860 int ndof = (*itTrk)->ndof();
861 int nster = (*itTrk)->nster();
862 int nlayer = (*itTrk)->nlayer();
863 int firstLayerId = (*itTrk)->firstLayer();
864 int lastLayerId = (*itTrk)->lastLayer();
865 int nClu2D = (*itTrk)->getNcluster();
866 int nCgemCluX = (*itTrk)->nCgemXCluster();
867 int nCgemCluV = (*itTrk)->nCgemVCluster();
869 cout <<setw(15)<<
"ndof"<<setw(15)<<
"nster"<<setw(15)<<
"nlayer"<<setw(15)<<
"firstLayerId"<<setw(15)<<
"lastLayerId"
871 <<setw(15)<<
"nCgemCluX"<<setw(15)<<
"nCgemCluV"<<endl;
872 cout<<setw(15)<<ndof<<setw(15)<<nster<<setw(15)<<nlayer<<setw(15)<<firstLayerId<<setw(15)<<lastLayerId
874 <<setw(15)<<nCgemCluX<<setw(15)<<nCgemCluV<<endl;
std::vector< MdcDigi * > MdcDigiVec
double abs(const EvtComplex &c)
SmartRefVector< RecCgemCluster > ClusterRefVec
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared cut
CgemMdcCombAlg(const std::string &name, ISvcLocator *pSvcLocator)
double dr(void) const
returns an element of parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
MdcDigiVec & getMdcDigiVec(uint32_t control=0)