EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PndPidCorrelator.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PndPidCorrelator.cxx
1 #include <iostream>
2 using namespace std;
3 
4 #include "PndDetectorList.h"
5 #include "PndPidCorrelator.h"
6 #include "PndTrackID.h"
7 #include "PndMCTrack.h"
8 
9 //#include <EicIdealTrackingCode.h>
10 
11 #if _TODAY_
12 #include "PndTrack.h"
13 
14 #include "PndSciTPoint.h"
15 #include "PndSciTHit.h"
16 #include "PndEmcBump.h"
17 #include "PndEmcDigi.h"
18 #include "PndEmcStructure.h"
19 #include "PndEmcXtal.h"
20 #include "PndEmcErrorMatrix.h"
21 #include "PndEmcClusterCalibrator.h"
22 #include "PndEmcClusterEnergySums.h"
23 #include "PndMdtPoint.h"
24 #include "PndMdtHit.h"
25 #include "PndMdtTrk.h"
26 #include "PndDrcBarPoint.h"
27 #include "PndDrcHit.h"
28 #include "PndDskParticle.h"
29 #include "FairTrackParH.h"
30 #include "FairMCApplication.h"
31 #include "FairRunAna.h"
32 #include "FairRootManager.h"
33 #include "FairRuntimeDb.h"
34 
35 #include "TObjArray.h"
36 #include "TVector3.h"
37 #include "TGeoMatrix.h"
38 #include "TGeoManager.h"
39 #include "TSystem.h"
40 
41 #include <cmath>
42 #endif
43 
44 // ----------------------------------------------------------
45 // --- Interface with PidMaker and output ---
46 
47 //___________________________________________________________
49 {
50  //
52  fManager->Write();
53 #if _TODAY_
54  delete fEmcErrorMatrix;
55 #endif
56 }
57 
58 //___________________________________________________________
59 PndPidCorrelator::PndPidCorrelator(/*EicIdealTrackingCode *ideal*/) :
60  FairTask(),
61  fTrackBranch("EicIdealGenTrack"),
62  fTrackIDBranch("EicIdealGenTrackID"),
63  fTrack(new TClonesArray()),
64  fTrackOutBranch(""),
65  fIdealHyp(kFALSE),
66  fCorrErrorProp(kTRUE),
67  fGeanePro(kTRUE),
68  fMcTrack(new TClonesArray()),
69  fPidHyp(0)/*,
70  fIdeal(ideal)*/
71 
72 
73 #if _TODAY_
74 , ,, fTrackID(new TClonesArray()), fTrack2(new TClonesArray()), fTrackID2(new TClonesArray()), fPidChargedCand(new TClonesArray()), fPidNeutralCand(new TClonesArray()), fMdtTrack(new TClonesArray()), fMvdHitsStrip(new TClonesArray()), fMvdHitsPixel(new TClonesArray()), fTofHit(new TClonesArray()), fTofPoint(new TClonesArray()), fFtofHit(new TClonesArray()), fFtofPoint(new TClonesArray()), fEmcCluster(new TClonesArray()), fEmcBump(new TClonesArray()), fEmcDigi(new TClonesArray()), fMdtPoint(new TClonesArray()), fMdtHit(new TClonesArray()), fMdtTrk(new TClonesArray()), fDrcPoint(new TClonesArray()), fDrcHit(new TClonesArray()), fDskParticle(new TClonesArray()), fSttHit(new TClonesArray()), fFtsHit(new TClonesArray()),
75  fCorrPar(new PndPidCorrPar()), fEmcGeoPar(new PndEmcGeoPar()), fEmcErrorMatrixPar(new PndEmcErrorMatrixPar()), fEmcErrorMatrix(new PndEmcErrorMatrix()), fSttParameters(new PndGeoSttPar()), fEmcCalibrator(NULL), fEmcClstCount(0), fFscClstCount(0),
76  fDebugMode(kFALSE),
77  fMdtRefit(kFALSE),
78  fMvdMode(-1),
79  fSttMode(-1),
80  fFtsMode(-1),
81  fTofMode(-1),
82  fFtofMode(-1),
83  fEmcMode(-1),
84  fMdtMode(-1),
85  fDrcMode(-1),
86  fDskMode(-1),
87  fMixMode(kFALSE),
88  fFast(kFALSE),
89  fSimulation(kFALSE),
90  fIdeal(kFALSE),
91  tofCorr(0),
92  emcCorr(0),
93  fscCorr(0),
94  drcCorr(0),
95  dskCorr(0),
96  fTrackBranch2(""),
97  fTrackIDBranch2(""),
98  sDir(""),
99  sFile(""),
100  fGeoH(NULL),
101  fClusterList(),
102  fClusterQ(),
103  mapMdtBarrel(),
104  mapMdtEndcap(),
105  mapMdtForward()
106 #endif
107 {
108  fPidChargedCand = new TClonesArray("PndPidCandidate");
109  sDir = "./";
110  sFile = "./pidcorrelator.root";
112 
113 #if _TODAY_
114  //---
115  fPidNeutralCand = new TClonesArray("PndPidCandidate");
116 
117  // Resetting MDT geometry parameters
118  for (Int_t mm=0; mm<3; mm++)
119  for (Int_t ll=0; ll<20;ll++)
120  {
121  mdtLayerPos[mm][ll] = -1;
122  mdtIronThickness[mm][ll] = -1;
123  }
124 
125 #endif
126 
127  Reset();
128 }
129 
130 #if _TODAY_
131 //___________________________________________________________
132 PndPidCorrelator::PndPidCorrelator(const char *name, const char *title) :
133  FairTask(name),
134  fMcTrack(new TClonesArray()), fTrack(new TClonesArray()), fTrackID(new TClonesArray()), fTrack2(new TClonesArray()), fTrackID2(new TClonesArray()), fPidChargedCand(new TClonesArray()), fPidNeutralCand(new TClonesArray()), fMdtTrack(new TClonesArray()), fMvdHitsStrip(new TClonesArray()), fMvdHitsPixel(new TClonesArray()), fTofHit(new TClonesArray()), fTofPoint(new TClonesArray()), fFtofHit(new TClonesArray()), fFtofPoint(new TClonesArray()), fEmcCluster(new TClonesArray()), fEmcBump(new TClonesArray()), fEmcDigi(new TClonesArray()), fMdtPoint(new TClonesArray()), fMdtHit(new TClonesArray()), fMdtTrk(new TClonesArray()), fDrcPoint(new TClonesArray()), fDrcHit(new TClonesArray()), fDskParticle(new TClonesArray()), fSttHit(new TClonesArray()), fFtsHit(new TClonesArray()),
135  fCorrPar(new PndPidCorrPar()), fEmcGeoPar(new PndEmcGeoPar()), fEmcErrorMatrixPar(new PndEmcErrorMatrixPar()), fEmcErrorMatrix(new PndEmcErrorMatrix()), fSttParameters(new PndGeoSttPar()), fEmcCalibrator(NULL), fEmcClstCount(0), fFscClstCount(0),
136  fDebugMode(kFALSE),
137  fGeanePro(kTRUE),
138  fMdtRefit(kFALSE),
139  fMvdMode(-1),
140  fSttMode(-1),
141  fFtsMode(-1),
142  fTofMode(-1),
143  fFtofMode(-1),
144  fEmcMode(-1),
145  fMdtMode(-1),
146  fDrcMode(-1),
147  fDskMode(-1),
148  fMixMode(kFALSE),
149  fPidHyp(0),
150  fIdealHyp(kFALSE),
151  fFast(kFALSE),
152  fSimulation(kFALSE),
153  fIdeal(kFALSE),
154  fCorrErrorProp(kTRUE),
155  tofCorr(0),
156  emcCorr(0),
157  fscCorr(0),
158  drcCorr(0),
159  dskCorr(0),
160  fTrackBranch(""),
161  fTrackIDBranch(""),
162  fTrackBranch2(""),
163  fTrackIDBranch2(""),
164  fTrackOutBranch(""),
165  sDir(""),
166  sFile(""),
167  fGeoH(NULL),
168  fClusterList(),
169  fClusterQ(),
170  mapMdtBarrel(),
171  mapMdtEndcap(),
172  mapMdtForward()
173 {
174  //---
175  fPidChargedCand = new TClonesArray("PndPidCandidate");
176  fPidNeutralCand = new TClonesArray("PndPidCandidate");
177  sDir = "./";
178  sFile = "./pidcorrelator.root";
180 
181  // Resetting MDT geometry parameters
182  for (Int_t mm=0; mm<3; mm++)
183  for (Int_t ll=0; ll<20;ll++)
184  {
185  mdtLayerPos[mm][ll] = -1;
186  mdtIronThickness[mm][ll] = -1;
187  }
188 
189  Reset();
190 }
191 #endif
192 
193 //___________________________________________________________
195  // cout << "InitStatus PndPidCorrelator::Init()" << endl;
196 
198 
199  fTrack = (TClonesArray *)fManager->GetObject(fTrackBranch);
200  if ( ! fTrack ) {
201  cout << "-I- PndPidCorrelator::Init: No PndTrack array!" << endl;
202  return kERROR;
203  }
204 
205  if (fTrackIDBranch!="")
206  {
207  fTrackID = (TClonesArray *)fManager->GetObject(fTrackIDBranch);
208  if ( ! fTrackID ) {
209  cout << "-I- PndPidCorrelator::Init: No PndTrackID array! Switching MC propagation OFF" << endl;
210  fTrackIDBranch = "";
211  }
212  }
213 
214 #if _TODAY_
215  if (fTrackBranch2!="")
216  {
217  fTrack2 = (TClonesArray *)fManager->GetObject(fTrackBranch2);
218  if ( ! fTrack2 ) {
219  cout << "-I- PndPidCorrelator::Init: No 2nd PndTrack array!" << endl;
220  return kERROR;
221  }
222  }
223 
224  if (fTrackIDBranch2!="")
225  {
226  fTrackID2 = (TClonesArray *)fManager->GetObject(fTrackIDBranch2);
227  if ( ! fTrackID2 ) {
228  cout << "-I- PndPidCorrelator::Init: No 2nd PndTrackID array! Switching MC propagation OFF" << endl;
229  fTrackIDBranch2 = "";
230  }
231  }
232 
233  // *** STT ***
234  if (fSttMode)
235  {
236  if (fMixMode==kFALSE)
237  {
238  fSttHit = (TClonesArray*) fManager->GetObject("STTHit");
239  if ( fSttHit )
240  {
241  cout << "-I- PndPidCorrelator::Init: Using STTHit" << endl;
242  fSttMode = 2;
243  }
244  else
245  {
246  cout << "-W- PndPidCorrelator::Init: No STT hits array! Switching STT OFF" << endl;
247  fSttMode = 0;
248  }
249  }
250  else
251  {
252  fSttHit = (TClonesArray*) fManager->GetObject("STTHitMix");
253  if ( fSttHit )
254  {
255  cout << "-I- PndPidCorrelator::Init: Using STTHitMix" << endl;
256  fSttMode = 2;
257  }
258  else
259  {
260  cout << "-W- PndPidCorrelator::Init: No STT hits mix array! Switching STT OFF" << endl;
261  fSttMode = 0;
262  }
263  }
264  }
265 
266  // *** FTS ***
267  if (fFtsMode)
268  {
269  if (fMixMode==kFALSE)
270  {
271  fFtsHit = (TClonesArray*) fManager->GetObject("FTSHit");
272  if ( fFtsHit )
273  {
274  cout << "-I- PndPidCorrelator::Init: Using FTSHit" << endl;
275  fFtsMode = 2;
276  }
277  else
278  {
279  cout << "-W- PndPidCorrelator::Init: No FTS hits array! Switching FTS OFF" << endl;
280  fFtsMode = 0;
281  }
282  }
283  else
284  {
285  fFtsHit = (TClonesArray*) fManager->GetObject("FTSHitMix");
286  if ( fFtsHit )
287  {
288  cout << "-I- PndPidCorrelator::Init: Using FTSHitMix" << endl;
289  fFtsMode = 2;
290  }
291  else
292  {
293  cout << "-W- PndPidCorrelator::Init: No FTS hits mix array! Switching FTS OFF" << endl;
294  fFtsMode = 0;
295  }
296  }
297  }
298 
299  // *** MVD ***
300  if (fMvdMode)
301  {
302  if (fMixMode==kFALSE)
303  {
304  fMvdHitsStrip = (TClonesArray*) fManager->GetObject("MVDHitsStrip");
305  if ( ! fMvdHitsStrip )
306  {
307  cout << "-W- PndPidCorrelator::Init: No MVDHitsStrip array!" << endl;
308  }
309  else fMvdMode = 2;
310 
311  fMvdHitsPixel = (TClonesArray*) fManager->GetObject("MVDHitsPixel");
312  if ( ! fMvdHitsPixel )
313  {
314  cout << "-W- PndPidCorrelator::Init: No MVDHitsPixel array!" << endl;
315  }
316  else fMvdMode = 2;
317  }
318  else
319  {
320  fMvdHitsStrip = (TClonesArray*) fManager->GetObject("MVDHitsStripMix");
321  if ( ! fMvdHitsStrip )
322  {
323  cout << "-W- PndPidCorrelator::Init: No MVDHitsStripMix array!" << endl;
324  }
325  else fMvdMode = 2;
326 
327  fMvdHitsPixel = (TClonesArray*) fManager->GetObject("MVDHitsPixelMix");
328  if ( ! fMvdHitsPixel )
329  {
330  cout << "-W- PndPidCorrelator::Init: No MVDHitsPixelMix array!" << endl;
331  }
332  else fMvdMode = 2;
333  }
334 
335  if (( ! fMvdHitsStrip ) && ( ! fMvdHitsPixel ))
336  {
337  cout << "-W- PndPidCorrelator::Init: No MVD hits array! Switching MVD OFF" << endl;
338  fMvdMode = 0;
339  }
340  else
341  {
342  cout << "-I- PndPidCorrelator::Init: Using MVDHit" << endl;
343  }
344  }
345 
346  // *** TOF ***
347  if (fTofMode)
348  {
349  fTofHit = (TClonesArray*) fManager->GetObject("SciTHit");
350  if ( ! fTofHit )
351  {
352  cout << "-W- PndPidCorrelator::Init: No SciTHit array!" << endl;
353  fTofMode = 0;
354  }
355  else
356  {
357  cout << "-I- PndPidCorrelator::Init: Using SciTHit" << endl;
358  fTofMode = 2;
359  }
360  if (fIdeal)
361  {
362  fTofPoint = (TClonesArray*) fManager->GetObject("SciTPoint");
363  if ( ! fTofPoint )
364  {
365  cout << "-W- PndPidCorrelator::Init: No SciTPoint array!" << endl;
366  fTofMode = 0;
367  }
368  }
369  }
370 
371  // *** FTOF ***
372  if (fFtofMode)
373  {
374  fFtofHit = (TClonesArray*) fManager->GetObject("FtofHit");
375  if ( ! fFtofHit )
376  {
377  cout << "-W- PndPidCorrelator::Init: No FtofHit array!" << endl;
378  fFtofMode = 0;
379  }
380  else
381  {
382  cout << "-I- PndPidCorrelator::Init: Using FtofHit" << endl;
383  fFtofMode = 2;
384  }
385  if (fIdeal)
386  {
387  fFtofPoint = (TClonesArray*) fManager->GetObject("FtofPoint");
388  if ( ! fFtofPoint )
389  {
390  cout << "-W- PndPidCorrelator::Init: No FtofPoint array!" << endl;
391  fFtofMode = 0;
392  }
393  }
394  }
395 
396  // *** EMC ***
397  if (fEmcMode)
398  {
399  fEmcCluster = (TClonesArray*) fManager->GetObject("EmcCluster");
400  if ( ! fEmcCluster )
401  {
402  cout << "-W- PndPidCorrelator::Init: No EmcCluster array!" << endl;
403  fEmcMode = 0;
404  }
405  else
406  {
407  cout << "-I- PndPidCorrelator::Init: Using EmcCluster" << endl;
408  fEmcMode = 2;
409  }
410 
411  fEmcBump = (TClonesArray*) fManager->GetObject("EmcBump");
412  if ( ! fEmcBump )
413  {
414  cout << "-W- PndPidCorrelator::Init: No EmcBump array!" << endl;
415  }
416  else
417  {
418  cout << "-I- PndPidCorrelator::Init: Using EmcBump" << endl;
419  fEmcMode = 3;
420  }
421 
422  fEmcDigi = (TClonesArray*) fManager->GetObject("EmcDigi");
423  if ( ! fEmcDigi)
424  {
425  cout << "-W- PndPidCorrelator::Init: No EmcDigi array! No EMC E1/E9/E25 information is propagated!" << endl;
426  }
427  }
428 
429  // *** DRC ***
430  if (fDrcMode)
431  {
432  fDrcHit = (TClonesArray*) fManager->GetObject("DrcHit");
433  if ( ! fDrcHit )
434  {
435  cout << "-W- PndPidCorrelator::Init: No DrcHit array!" << endl;
436  fDrcMode = 0;
437  }
438  else
439  {
440  cout << "-I- PndPidCorrelator::Init: Using DrcHit" << endl;
441  fDrcMode = 2;
442  }
443  }
444 
445  // *** DSK ***
446  if (fDskMode)
447  {
448  fDskParticle = (TClonesArray*) fManager->GetObject("DskParticle");
449  if ( ! fDskParticle )
450  {
451  cout << "-W- PndPidCorrelator::Init: No DskParticle array!" << endl;
452  fDskMode = 0;
453  }
454  else
455  {
456  cout << "-I- PndPidCorrelator::Init: Using DskParticle" << endl;
457  fDskMode = 2;
458  }
459  }
460 
461  // *** MDT ***
462  if (fMdtMode)
463  {
464  fMdtHit = (TClonesArray*) fManager->GetObject("MdtHit");
465  if ( ! fMdtHit )
466  {
467  cout << "-W- PndPidCorrelator::Init: No MdtHit array!" << endl;
468  fMdtMode = 0;
469  }
470  else
471  {
472  cout << "-I- PndPidCorrelator::Init: Using MdtHit" << endl;
473  fMdtMode = 2;
474  }
475  fMdtTrk = (TClonesArray*) fManager->GetObject("MdtTrk");
476  if ( ! fMdtTrk )
477  {
478  cout << "-W- PndPidCorrelator::Init: No MdtTrk array!" << endl;
479  }
480  else
481  {
482  cout << "-I- PndPidCorrelator::Init: Using MdtTrk" << endl;
483  fMdtMode = 3;
484  }
485  }
486 
487  if (fIdeal)
488  {
489  cout << "-I- PndPidCorrelator::Init: Using MonteCarlo correlation" << endl;
490  fTofPoint = (TClonesArray*) fManager->GetObject("TofPoint");
491  if ( ! fTofPoint )
492  {
493  cout << "-W- PndPidCorrelator::Init: No TofPoint array!" << endl;
494  fTofMode = 0;
495  }
496  else
497  {
498  cout << "-I- PndPidCorrelator::Init: Using TofPoint" << endl;
499  }
500  fDrcPoint = (TClonesArray*) fManager->GetObject("DrcBarPoint");
501  if ( ! fDrcPoint )
502  {
503  cout << "-W- PndPidCorrelator::Init: No DrcBarPoint array!" << endl;
504  fDrcMode = 0;
505  }
506  else
507  {
508  cout << "-I- PndPidCorrelator::Init: Using DrcPoint" << endl;
509  }
510  fMdtPoint = (TClonesArray*) fManager->GetObject("MdtPoint");
511  if ( ! fMdtPoint )
512  {
513  cout << "-W- PndPidCorrelator::Init: No MdtPoint array!" << endl;
514  fMdtMode = 0;
515  }
516  else
517  {
518  cout << "-I- PndPidCorrelator::Init: Using MdtPoint" << endl;
519  }
520  }
521 #endif
522 
523  Register();
524 
525 #if _TODAY_
526  fCorrPar->printParams();
527 #endif
528 
529  if (fGeanePro)
530  {
531  cout << "-I- PndPidCorrelator::Init: Using Geane for Track propagation" << endl;
532  if (!fCorrErrorProp)
533  {
534  cout << "-I- PndPidCorrelator::Init: Switching OFF Geane error propagation" << endl;
535  }
536  if (fIdealHyp)
537  {
538  fMcTrack = (TClonesArray *)fManager->GetObject("MCTrack");
539  if ( ! fMcTrack ) {
540  cout << "-I- PndPidCorrelator::Init: No PndMcTrack array! No ideal pid hypothesis is possible!" << endl;
541  return kERROR;
542  }
543  if (fTrackIDBranch=="") {
544  cout << "-I- PndPidCorrelator::Init: No TrackID Branch name! No ideal pid hypothesis is possible!" << endl;
545  return kERROR;
546  }
547  }
548  else
549  {
550  switch (abs(fPidHyp))
551  {
552  case 0:
553  cout << "-I- PndPidCorrelator::Init: No PID set -> Using default PION hypothesis" << endl;
554  fPidHyp = 211;
555  break;
556 
557  case 11:
558  cout << "-I- PndPidCorrelator::Init: Using ELECTRON hypothesis" << endl;
559  fPidHyp = -11;
560  break;
561 
562  case 13:
563  cout << "-I- PndPidCorrelator::Init: Using MUON hypothesis" << endl;
564  fPidHyp = -13;
565  break;
566 
567  case 211:
568  cout << "-I- PndPidCorrelator::Init: Using PION hypothesis" << endl;
569  fPidHyp = 211;
570  break;
571 
572  case 321:
573  cout << "-I- PndPidCorrelator::Init: Using KAON hypothesis" << endl;
574  fPidHyp = 321;
575  break;
576 
577  case 2212:
578  cout << "-I- PndPidCorrelator::Init: Using PROTON hypothesis" << endl;
579  fPidHyp = 2212;
580  break;
581 
582  default:
583  cout << "-I- PndPidCorrelator::Init: Not recognised PID set -> Using default PION hypothesis" << endl;
584  fPidHyp = 211;
585  break;
586  }
587  }
588  }
589  else
590  {
591  return kFATAL;
592  }
593 
594 #if _TODAY_
595  if (fMdtMode>0)
596  {
597  if (!MdtGeometry())
598  {
599  cout << "-W- PndPidCorrelator::Init: No MDT geometry ???" << endl;
600  fMdtMode = 0;
601  }
602  }
603 
604  if (fMdtRefit)
605  {
606  fFitter = new PndRecoKalmanFit();
607  fFitter->SetGeane(fGeanePro);
608  fFitter->SetNumIterations(1);
609  if (!fFitter->Init()) return kFATAL;
610  }
611 
612  if (fDebugMode)
613  {
614  r = TFile::Open(sDir+sFile,"RECREATE");
615 
616  tofCorr = new TNtuple("tofCorr","TRACK-TOF Correlation",
617  "track_x:track_y:track_z:track_phi:track_p:track_charge:track_theta:track_z0:tof_x:tof_y:tof_z:tof_phi:chi2:dphi:len:glen");
618  ftofCorr = new TNtuple("ftofCorr","TRACK-FTOF Correlation",
619  "track_x:track_y:track_z:ver_x:ver_y:ver_z:ver_px:ver_py:ver_pz:track_p:track_charge:track_theta:track_z0:tof_x:tof_y:tof_z:chi2:len:glen:tlen");
620  emcCorr = new TNtuple("emcCorr","TRACK-EMC Correlation",
621  "track_x:track_y:track_z:track_phi:track_p:track_charge:track_theta:track_z0:emc_x:emc_y:emc_z:emc_phi:chi2:dphi:emc_ene:glen:emc_mod");
622  fscCorr = new TNtuple("fscCorr","TRACK-FSC Correlation",
623  "track_x:track_y:track_z:track_phi:track_p:track_charge:track_theta:track_z0:emc_x:emc_y:emc_z:emc_phi:chi2:dphi:emc_ene:glen:emc_mod");
624  mdtCorr = new TNtuple("mdtCorr","TRACK-MDT Correlation",
625  "track_x:track_y:track_z:track_dx:track_dy:track_dz:track_phi:track_p:track_charge:track_theta:track_z0:mdt_x:mdt_y:mdt_z:mdt_phi:mdt_p:chi2:mdt_mod:dphi:glen:mdt_count:nhits");
626  drcCorr = new TNtuple("drcCorr","TRACK-DRC Correlation",
627  "track_x:track_y:track_z:track_phi:track_p:track_charge:track_theta:track_z0:drc_x:drc_y:drc_phi:chi2:drc_thetac:drc_nphot:dphi:glen:flag");
628  dskCorr = new TNtuple("dskCorr","TRACK-DSK Correlation",
629  "track_x:track_y:track_z:track_phi:track_p:track_charge:track_theta:track_z0:dsk_x:dsk_y:dsk_z:dsk_phi:chi2:dsk_thetac:dsk_nphot:dphi:glen:track_lx:track_ly:track_lz:track_xp:flag");
630  cout << "-I- PndPidCorrelator::Init: Filling Debug histograms" << endl;
631 
632  }
633 
634  // Set Parameters for Emc error matrix
635  if (fEmcMode>0)
636  {
637  if (fEmcErrorMatrixPar->IsValid())
638  {
639  fEmcErrorMatrix->Init(fEmcErrorMatrixPar->GetParObject());
640  //std::cout<<"PndPidCorrelator: Emc error matrix is read from RTDB"<<std::endl;
641  } else
642  {
643  Int_t emcGeomVersion=fEmcGeoPar->GetGeometryVersion();
644  fEmcErrorMatrix->InitFromFile(emcGeomVersion);
645  fEmcErrorMatrixPar->SetErrorMatrixObject(fEmcErrorMatrix->GetParObject());
646  //std::cout<<"PndPidCorrelator: Emc error matrix is read from file"<<std::endl;
647  }
648  fEmcCalibrator= PndEmcClusterCalibrator::MakeEmcClusterCalibrator(2, 1);
649  }
650 
651  if (fFast) cout << "-W- PndPidCorrelator::Init: Using fast correlator!!" << endl;
652 #endif
653 
654  cout << "-I- PndPidCorrelator::Init: Success!" << endl;
655  fEventCounter = 1;
656 
657  return kSUCCESS;
658 }
659 
660 //______________________________________________________
662 #if _TODAY_
663  // Get run and runtime database
665  if ( ! run ) Fatal("PndPidCorrelator:: SetParContainers", "No analysis run");
666 
667  FairRuntimeDb* db = run->GetRuntimeDb();
668  if ( ! db ) Fatal("PndPidCorrelator:: SetParContainers", "No runtime database");
669 
670  // Get PID Correlation parameter container
671  fCorrPar = (PndPidCorrPar*) db->getContainer("PndPidCorrPar");
672 
673  // Get Emc geometry parameter container
674  fEmcGeoPar = (PndEmcGeoPar*) db->getContainer("PndEmcGeoPar");
675 
676  // Get Emc error matrix parameter container
677  fEmcErrorMatrixPar = (PndEmcErrorMatrixPar*) db->getContainer("PndEmcErrorMatrixPar");
678 
679  // Get Stt parameter
680  fSttParameters = (PndGeoSttPar*) db->getContainer("PndGeoSttPar");
681  fFtsParameters = (PndGeoFtsPar*) db->getContainer("PndGeoFtsPar");
682 #endif
683 }
684 
685 //______________________________________________________
686 void PndPidCorrelator::Exec(Option_t * option) {
687  //-
688  Reset();
689  cout << " ===== PndPidCorrelator - Event: " << fEventCounter;
690  Int_t nTracksTot=0;
691  if (fTrack)
692  {
693  nTracksTot += fTrack->GetEntriesFast();
694  }
695 #if _TODAY_
696  if (fTrack2)
697  {
698  nTracksTot += fTrack2->GetEntriesFast();
699  }
700 #endif
701 
702  cout << " - Number of tracks for pid " << nTracksTot;
703 #if _TODAY_
704  if (fEmcMode>0)
705  {
706  PndEmcCluster *tmp_cluster;
707  for(Int_t i=0; i < fEmcCluster->GetEntriesFast();i++)
708  {
709  tmp_cluster = (PndEmcCluster*)fEmcCluster->At(i);
710  if(tmp_cluster->GetModule() < 5 && tmp_cluster->GetModule() >0)
711  {
712  fEmcClstCount++;
713  }
714  if(tmp_cluster->GetModule() == 5)
715  {
716  fFscClstCount++;
717  }
718  }
719  ResetEmcQ();
720  cout << " - Number of Clusters for pid: ";
721  cout << " EMC: " << fEmcClstCount;
722  cout << " FSC: " << fFscClstCount;
723  }
724 #endif
725  cout<<endl;
726 
728 #if _TODAY_
729  if ((fEmcMode>0) && (!fFast)) ConstructNeutralCandidate();
730 #endif
731  fEventCounter++;
732 }
733 
734 //______________________________________________________
736  //-
737  //FIXME: Use Clear() to save time.
738  //Call Delete() only for too busy events to save Memory
739  fPidChargedCand->Delete();
740 #if _TODAY_
741  if (fMdtRefit) fMdtTrack->Delete();
742  if (fMdtMode>0) MdtMapping();
743 #endif
744 
745  Int_t nTracks = fTrack->GetEntriesFast();
746  for (Int_t i = 0; i < nTracks; i++) {
747  PndTrack* track = (PndTrack*) fTrack->At(i);
748 
749  Int_t ierr = 0;
750  FairTrackParP par = track->GetParamLast();
751  cout << par.GetMomentum().Mag() << endl;
752  if ((par.GetMomentum().Mag()<0.1) /*|| (par.GetMomentum().Mag()>100.)*/ )continue;
753  FairTrackParH *helix = new FairTrackParH(&par, ierr);
754 
755  PndPidCandidate* pidCand = new PndPidCandidate();
756 
757  //for(unsigned iq=0; iq<track->mSmoothedValues.size(); iq++)
758  //pidCand->mSmoothedValues.push_back(track->mSmoothedValues[iq]);
759 
760  if (fTrackIDBranch!="")
761  {
762  PndTrackID* trackID = (PndTrackID*) fTrackID->At(i);
763  if (trackID->GetNCorrTrackId()>0)
764  {
765  pidCand->SetMcIndex(trackID->GetCorrTrackID());
766  if (fIdealHyp)
767  {
768  PndMCTrack *mcTrack = (PndMCTrack*)fMcTrack->At(trackID->GetCorrTrackID());
769  if ( ! mcTrack )
770  {
771  fPidHyp = 211;
772  cout << "-I- PndPidCorrelator::ConstructChargedCandidate: PndMCTrack does not exist!! (why?) -> let's try with pion hyp " << endl;
773  }
774  else
775  {
776  fPidHyp = abs(mcTrack->GetPdgCode());
777  }
778  if (fPidHyp>=100000000)
779  {
780  fPidHyp = 211;
781  std::cout << "-I- PndPidCorrelator::ConstructChargedCandidate: Track is an ion (PDGCode>100000000) -> let's try with pion hyp" << std::endl;
782  }
783 
784  if ( abs(fPidHyp)==13 ) fPidHyp = -13;
785  if ( abs(fPidHyp)==11 ) fPidHyp = -11;
786  }
787  }
788  } else { // added for PndAnalysis, TODO: remove after Fairlinks work with Associators
789  PndTrackCand trackCand = track->GetTrackCand();
790  pidCand->SetMcIndex(trackCand.getMcTrackId());
791  }
792  pidCand->SetTrackIndex(i);
793  pidCand->SetTrackBranch(FairRootManager::Instance()->GetBranchId(fTrackBranch));
794  pidCand->AddLink(FairLink(fTrackBranch, i));
795  if (!GetTrackInfo(track, pidCand)) continue;
796 #if _TODAY_
797  if ( (fMvdMode==2) && ((fMvdHitsStrip->GetEntriesFast()+fMvdHitsPixel->GetEntriesFast())>0) ) GetMvdInfo(track, pidCand);
798  if ( (fSttMode == 2) && (fSttHit ->GetEntriesFast()>0) ) GetSttInfo(track, pidCand);
799  GetGemInfo(track, pidCand);
800  if (!fFast)
801  {
802  if ( (fTofMode==2) && (fTofHit ->GetEntriesFast()>0) ) GetTofInfo(helix, pidCand);
803  if ( (fEmcMode>0) && (fEmcClstCount>0) ) GetEmcInfo(helix, pidCand);
804  if ( (fMdtMode>0) && (fMdtHit ->GetEntriesFast()>0) ) GetMdtInfo(track, pidCand);
805  if ( (fDrcMode>0) && (fDrcHit ->GetEntriesFast()>0) ) GetDrcInfo(helix, pidCand);
806  if ( (fDskMode>0) && (fDskParticle->GetEntriesFast()>0)) GetDskInfo(helix, pidCand);
807  }
808 #endif
809 
810  // Add charged track candidate and copy over parameterizations at the hit locations;
811  PndPidCandidate *cand = AddChargedCandidate(pidCand);
812  cand->mParameterizations = track->mParameterizations;
813  }
814 
815 #if _TODAY_
816  if (fTrackBranch2!="")
817  {
818  Int_t nTracks2 = fTrack2->GetEntriesFast();
819  for (Int_t i = 0; i < nTracks2; i++) {
820  PndTrack* track = (PndTrack*) fTrack2->At(i);
821  Int_t ierr = 0;
822  FairTrackParP par = track->GetParamLast();
823  if ((par.GetMomentum().Mag()<0.1) || (par.GetMomentum().Mag()>20.) )continue;
824  FairTrackParH *helix = new FairTrackParH(&par, ierr);
825 
826  PndPidCandidate* pidCand = new PndPidCandidate();
827  if (fTrackIDBranch2!="")
828  {
829  PndTrackID* trackID = (PndTrackID*) fTrackID2->At(i);
830  if (trackID->GetNCorrTrackId()>0)
831  {
832  pidCand->SetMcIndex(trackID->GetCorrTrackID());
833  if (fIdealHyp)
834  {
835  PndMCTrack *mcTrack = (PndMCTrack*)fMcTrack->At(trackID->GetCorrTrackID());
836  if ( ! mcTrack )
837  {
838  fPidHyp = 211;
839  cout << "-I- PndPidCorrelator::ConstructChargedCandidate: PndMCTrack does not exist!! (why?) -> let's try with pion hyp " << endl;
840  }
841  else
842  {
843  fPidHyp = abs(mcTrack->GetPdgCode());
844  }
845  if (fPidHyp>=100000000)
846  {
847  fPidHyp = 211;
848  std::cout << "-I- PndPidCorrelator::ConstructChargedCandidate: Track is an ion (PDGCode>100000000) -> let's try with pion hyp" << std::endl;
849  }
850 
851  if ( abs(fPidHyp)==13 ) fPidHyp = -13;
852  if ( abs(fPidHyp)==11 ) fPidHyp = -11;
853  }
854  }
855  } else { // added for PndAnalysis, TODO: remove after Fairlinks work with Associators
856  PndTrackCand trackCand = track->GetTrackCand();
857  pidCand->SetMcIndex(trackCand.getMcTrackId());
858  }
859  pidCand->SetTrackIndex(i);
860  pidCand->SetTrackBranch(FairRootManager::Instance()->GetBranchId(fTrackBranch2));
861  pidCand->AddLink(FairLink("PndTrack", i));
862  if (!GetTrackInfo(track, pidCand)) continue;
863  if ( (fMvdMode==2) && ((fMvdHitsStrip->GetEntriesFast()+fMvdHitsPixel->GetEntriesFast())>0) ) GetMvdInfo(track, pidCand);
864  if ( (fFtsMode == 2) && (fFtsHit ->GetEntriesFast()>0) ) GetFtsInfo(track, pidCand);
865  GetGemInfo(track, pidCand);
866  if (!fFast)
867  {
868  if ( (fFtofMode==2) && (fFtofHit->GetEntriesFast()>0) ) GetFtofInfo(helix, pidCand);
869  if ( (fEmcMode>0) && (fFscClstCount>0) ) GetFscInfo(helix, pidCand);
870  //if ( (fMdtMode>0) && (fMdtHit ->GetEntriesFast()>0) ) GetMdtInfo(track, pidCand);
871  if (mapMdtForward.size()>0) GetFMdtInfo(&par, pidCand);
872  } // end of fast mode
873  AddChargedCandidate(pidCand);
874  }
875  }
876 #endif
877 }
878 
879 #if _TODAY_
880 //______________________________________________________
881 void PndPidCorrelator::ConstructNeutralCandidate() {
882  //-
883  fPidNeutralCand->Delete();
884  TString emcType;
885 
886  Int_t nBumps = 0;
887  if (fEmcMode == 2)
888  {
889  nBumps = fEmcCluster->GetEntriesFast();
890  emcType = "EmcCluster";
891  }
892  else if(fEmcMode == 3)
893  {
894  nBumps = fEmcBump->GetEntriesFast();
895  emcType = "EmcBump";
896  }
897 
898  for (Int_t i = 0; i < nBumps; i++)
899  {
900  PndEmcBump* bump;
901  PndEmcCluster *clu;
902  Float_t quality = -1.;
903  if (fEmcMode==2)
904  {
905  if (fClusterList[i]) continue;
906  bump = (PndEmcBump*) fEmcCluster->At(i);
907  clu = (PndEmcBump*) fEmcCluster->At(i);
908  quality = fClusterQ[i];
909  }
910  else if(fEmcMode == 3)
911  {
912  bump = (PndEmcBump*) fEmcBump->At(i);
913  if (fClusterList[bump->GetClusterIndex()]) continue; // skip correlated clusters
914  clu = (PndEmcCluster*)fEmcCluster->At(bump->GetClusterIndex());
915  quality = fClusterQ[bump->GetClusterIndex()];
916  }
917 
918  TVector3 vtx(0,0,0);
919  TVector3 v1=bump->where();
920  TVector3 p3;
921  p3.SetMagThetaPhi(fEmcCalibrator->Energy(bump), v1.Theta(), v1.Phi());
922  TLorentzVector lv(p3,p3.Mag());
923  TMatrixD covP4=fEmcErrorMatrix->Get4MomentumErrorMatrix(*clu);
924 
925  PndPidCandidate* pidCand = new PndPidCandidate(0, vtx, lv);
926  pidCand->SetP4Cov(covP4);
927  pidCand->SetEmcRawEnergy(bump->energy());
928  pidCand->SetEmcCalEnergy(fEmcCalibrator->Energy(bump));
929  pidCand->SetEmcIndex(i);
930  pidCand->SetEmcModule(bump->GetModule());
931  pidCand->SetEmcNumberOfCrystals(bump->NumberOfDigis());
932  pidCand->SetEmcNumberOfBumps(clu->NBumps());
933  pidCand->SetEmcQuality(quality);
934 
935  pidCand->SetEmcClusterZ20(bump->Z20());
936  pidCand->SetEmcClusterZ53(bump->Z53());
937  pidCand->SetEmcClusterLat(bump->LatMom());
938  if (fEmcDigi)
939  {
940  PndEmcClusterEnergySums esum(*clu, fEmcDigi);
941  pidCand->SetEmcClusterE1(esum.E1());
942  pidCand->SetEmcClusterE9(esum.E9());
943  pidCand->SetEmcClusterE25(esum.E25());
944  }
945  pidCand->SetLink(FairLink(emcType, i));
946 
947  std::vector<Int_t> mclist = clu->GetMcList();
948  if (mclist.size()>0)
949  {
950  pidCand->SetMcIndex(mclist[0]);
951  }
952  AddNeutralCandidate(pidCand);
953  }
954 }
955 
956 //_________________________________________________________________
957 Bool_t PndPidCorrelator::GetTofInfo(FairTrackParH* helix, PndPidCandidate* pidCand) {
958 
959  if (!fIdeal)
960  {
961  if ((helix->GetMomentum().Theta()*TMath::RadToDeg())<20.) return kFALSE;
962  if ((helix->GetMomentum().Theta()*TMath::RadToDeg())>150.) return kFALSE;
963  }
964  FairGeanePro *fProTof = new FairGeanePro();
965  if (!fCorrErrorProp) fProTof->PropagateOnlyParameters();
966  FairGeanePro *fProVertex = new FairGeanePro();
967  if (!fCorrErrorProp) fProVertex->PropagateOnlyParameters();
968  //---
969  PndSciTHit *tofHit = NULL;
970  Int_t tofEntries = fTofHit->GetEntriesFast();
971  Int_t tofIndex = -1;
972  Float_t tofTof = 0., tofLength = -1000, tofGLength = -1000, tofLengthTemp = -1000;
973  Float_t tofQuality = 1000000;
974 
975  Float_t chi2 = 0;
976  TVector3 vertex(0., 0., 0.);
977  TVector3 tofPos(0., 0., 0.);
978  TVector3 momentum(0., 0., 0.);
979  for (Int_t tt = 0; tt<tofEntries; tt++)
980  {
981  tofHit = (PndSciTHit*)fTofHit->At(tt);
982  if ( fIdeal && ( ((PndSciTPoint*)fTofPoint->At(tofHit->GetRefIndex()))->GetTrackID() !=pidCand->GetMcIndex()) ) continue;
983  tofHit->Position(tofPos);
984 
985  if (fGeanePro) // Overwrites vertex if Geane is used
986  {
987 
988  fProTof->SetPoint(tofPos);
989  fProTof->PropagateToPCA(1, 1);
990  FairTrackParH *fRes= new FairTrackParH();
991  Bool_t rc = fProTof->Propagate(helix, fRes, fPidHyp*pidCand->GetCharge());
992  if (!rc) continue;
993 
994  vertex.SetXYZ(fRes->GetX(), fRes->GetY(), fRes->GetZ());
995 
996  fProVertex->SetPoint(TVector3(0,0,0));
997  fProVertex->PropagateToPCA(1, -1);
998  FairTrackParH *fRes2= new FairTrackParH();
999  Bool_t rc2 = fProVertex->Propagate(fRes, fRes2, fPidHyp*pidCand->GetCharge());
1000  if (rc2) tofLengthTemp = fProVertex->GetLengthAtPCA();
1001  }
1002 
1003  Float_t dist = (tofPos-vertex).Mag2();
1004 
1005  if ( tofQuality > dist)
1006  {
1007  tofIndex = tt;
1008  tofQuality = dist;
1009  tofTof = tofHit->GetTime();
1010  tofLength = tofLengthTemp; // abs(phi * track->GetRadius() / TMath::Sin(track->GetMomentum().Theta()));
1011  }
1012  if (fDebugMode)
1013  {
1014  Float_t ntuple[] = {vertex.X(), vertex.Y(), vertex.Z(), vertex.Phi(),
1015  helix->GetMomentum().Mag(), helix->GetQ(), helix->GetMomentum().Theta(), helix->GetZ(),
1016  tofPos.X(), tofPos.Y(), tofPos.Z(), tofPos.Phi(),
1017  dist, vertex.DeltaPhi(tofPos), tofLength, tofGLength};
1018  tofCorr->Fill(ntuple);
1019  }
1020  }
1021 
1022  if ( (tofQuality<fCorrPar->GetTofCut()) || (fIdeal && tofIndex!=-1) )
1023  {
1024  pidCand->SetTofQuality(tofQuality);
1025  pidCand->SetTofStopTime(tofTof);
1026  pidCand->SetTofTrackLength(tofLength);
1027  pidCand->SetTofIndex(tofIndex);
1028  if (tofLength>0.)
1029  {
1030  // mass^2 = p^2 * ( 1/beta^2 - 1 )
1031  Float_t mass2 = helix->GetMomentum().Mag()*helix->GetMomentum().Mag()*(30.*30.*tofTof*tofTof/tofLength/tofLength-1.);
1032  pidCand->SetTofM2(mass2);
1033  }
1034  }
1035 
1036  return kTRUE;
1037 }
1038 
1039 void PndPidCorrelator::ResetEmcQ()
1040 {
1041  // Fuction to reset all the quality values for emc-track correlation to -1
1042  fClusterQ.clear();
1043  fClusterList.clear();
1044  for (Int_t ii=0; ii<fEmcCluster->GetEntriesFast(); ii++)
1045  {
1046  fClusterQ[ii] = -1;
1047  fClusterList[ii] = kFALSE;
1048  }
1049 }
1050 
1051 //_________________________________________________________________
1052 Bool_t PndPidCorrelator::GetEmcInfo(FairTrackParH* helix, PndPidCandidate* pidCand) {
1053  if(! helix){
1054  std::cerr << "<Error> PndPidCorrelator EMCINFO: FairTrackParH NULL pointer parameter."
1055  <<std::endl;
1056  return kFALSE;
1057  }
1058  if(! pidCand){
1059  std::cerr << "<Error> PndPidCorrelator EMCINFO: pidCand NULL pointer parameter."
1060  <<std::endl;
1061  return kFALSE;
1062  }
1063  FairGeanePro *fProEmc = new FairGeanePro();
1064  if (!fCorrErrorProp) fProEmc->PropagateOnlyParameters();
1065  //---
1066  Float_t trackTheta = helix->GetMomentum().Theta()*TMath::RadToDeg();
1067 
1068  Int_t emcEntries = fEmcCluster->GetEntriesFast();
1069  Int_t emcIndex = -1, emcModuleCorr = -1, emcNCrystals = -1, emcNBumps = -1;
1070  Float_t emcEloss = 0., emcElossCorr = 0., emcGLength = -1000;
1071  Float_t emcQuality = 1000000;
1072  Float_t chi2 = 0;
1073  TVector3 vertex(0., 0., 0.); TVector3 emcPos(0., 0., 0.);// TVector3 momentum(0., 0., 0.);
1074 
1075  // Cluster zenike moments
1076  Double_t Z20 = 0.0, Z53 = 0.0, secLatM = 0.00, E1 = 0., E9 = 0., E25 = 0.;
1077 
1078  for (Int_t ee = 0; ee<emcEntries; ee++)
1079  {
1080  PndEmcCluster *emcHit = (PndEmcCluster*)fEmcCluster->At(ee);
1081 
1082  if ( fIdeal )
1083  {
1084  std::vector<Int_t> mclist = emcHit->GetMcList();
1085  if (mclist.size()==0) continue;
1086  if (mclist[0]!=pidCand->GetMcIndex()) continue;
1087  }
1088 
1089  if (emcHit->energy() < fCorrPar->GetEmc12Thr()) continue;
1090  Int_t emcModule = emcHit->GetModule();
1091  if (emcModule>4) continue;
1092 
1093  emcPos = emcHit->where();
1094  if (fGeanePro)
1095  { // Overwrites vertex if Geane is used
1096  fProEmc->SetPoint(emcPos);
1097  fProEmc->PropagateToPCA(1, 1);
1098  vertex.SetXYZ(-10000, -10000, -10000); // reset vertex
1099  FairTrackParH *fRes= new FairTrackParH();
1100  Bool_t rc = fProEmc->Propagate(helix, fRes, fPidHyp*pidCand->GetCharge()); // First propagation at module
1101  if (!rc) continue;
1102 
1103  emcGLength = fProEmc->GetLengthAtPCA();
1104  vertex.SetXYZ(fRes->GetX(), fRes->GetY(), fRes->GetZ());
1105  //std::map<PndEmcTwoCoordIndex*, PndEmcXtal*> tciXtalMap=PndEmcStructure::Instance()->GetTciXtalMap();
1106  //PndEmcDigi *lDigi= (PndEmcDigi*)emcHit->Maxima();
1107  //PndEmcXtal* xtal = tciXtalMap[lDigi->GetTCI()];
1108  //emcPos = xtal->frontCentre();
1109  }
1110 
1111  Float_t dist = (emcPos-vertex).Mag2();
1112  if ( emcQuality > dist )
1113  {
1114  emcIndex = ee;
1115  emcQuality = dist;
1116  emcEloss = emcHit->energy();
1117  emcElossCorr = fEmcCalibrator->Energy(emcHit);
1118  emcModuleCorr = emcModule;
1119  emcNCrystals = emcHit->NumberOfDigis();
1120  emcNBumps = emcHit->NBumps();
1121  Z20 = emcHit->Z20();// Z_{n = 2}^{m = 0}
1122  Z53 = emcHit->Z53();// Z_{n = 5}^{m = 3}
1123  secLatM = emcHit->LatMom();
1124  if (fEmcDigi)
1125  {
1126  PndEmcClusterEnergySums esum(*emcHit, fEmcDigi);
1127  E1 = esum.E1();
1128  E9 = esum.E9();
1129  E25 = esum.E25();
1130  }
1131  }
1132 
1133  if ( (fClusterQ[ee]<0) || (dist < fClusterQ[ee]))
1134  // If the track-emc distance is less than the previous stored value (or still not initialized)
1135  {
1136  fClusterQ[ee] = dist; // update the param
1137  }
1138 
1139  if (fDebugMode){
1140  Float_t ntuple[] = {vertex.X(), vertex.Y(), vertex.Z(), vertex.Phi(),
1141  helix->GetMomentum().Mag(), helix->GetQ(), helix->GetMomentum().Theta(), helix->GetZ(),
1142  emcPos.X(), emcPos.Y(), emcPos.Z(), emcPos.Phi(),
1143  dist, vertex.DeltaPhi(emcPos), emcHit->energy(), emcGLength, emcModule};
1144  emcCorr->Fill(ntuple);
1145  }
1146  }// End for(ee = 0;)
1147 
1148  if ( (emcQuality < fCorrPar->GetEmc12Cut()) || ( fIdeal && emcIndex!=-1) ){
1149  fClusterList[emcIndex] = kTRUE;
1150  pidCand->SetEmcQuality(emcQuality);
1151  pidCand->SetEmcRawEnergy(emcEloss);
1152  pidCand->SetEmcCalEnergy(emcElossCorr);
1153  pidCand->SetEmcIndex(emcIndex);
1154  pidCand->SetEmcModule(emcModuleCorr);
1155  pidCand->SetEmcNumberOfCrystals(emcNCrystals);
1156  pidCand->SetEmcNumberOfBumps(emcNBumps);
1157  //=======
1158  pidCand->SetEmcClusterZ20(Z20);
1159  pidCand->SetEmcClusterZ53(Z53);
1160  pidCand->SetEmcClusterLat(secLatM);
1161  pidCand->SetEmcClusterE1(E1);
1162  pidCand->SetEmcClusterE9(E9);
1163  pidCand->SetEmcClusterE25(E25);
1164  //=====
1165  }
1166 
1167  return kTRUE;
1168 }
1169 
1170 //_________________________________________________________________
1171 Bool_t PndPidCorrelator::GetMdtInfo(PndTrack* track, PndPidCandidate* pidCand) {
1172  //---
1173  FairTrackParP par = track->GetParamLast();
1174  Int_t ierr = 0;
1175  FairTrackParH *helix = new FairTrackParH(&par, ierr);
1176 
1177  map<Int_t, Int_t>mapMdtTrk;
1178  FairGeanePro *fProMdt = new FairGeanePro();
1179  if (!fCorrErrorProp) fProMdt->PropagateOnlyParameters();
1180 
1181  if (fMdtMode == 3)
1182  {
1183  for (Int_t tt = 0; tt<fMdtTrk->GetEntriesFast(); tt++)
1184  {
1185  PndMdtTrk *mdtTrk = (PndMdtTrk*)fMdtTrk->At(tt);
1186  mapMdtTrk[mdtTrk->GetHitIndex(0)] = tt;
1187  }
1188  }
1189  PndMdtHit *mdtHit = NULL;
1190  Int_t mdtEntries = fMdtHit->GetEntriesFast();
1191  Int_t mdtIndex = -1, mdtMod = 0, mdtLayer = 0, mdtHits = 0;
1192  Float_t mdtGLength = -1000;
1193  Float_t mdtQuality = 1000000;
1194  Float_t mdtIron = 0., mdtMom = 0, mdtTempMom = 0;
1195 
1196  Float_t chi2 = 0;
1197  TVector3 vertex(0., 0., 0.);
1198  TVector3 vertexD(0., 0., 0.);
1199  TVector3 mdtPos(0., 0., 0.);
1200  TVector3 momentum(0., 0., 0.);
1201  for (Int_t mm = 0; mm<mdtEntries; mm++)
1202  {
1203  mdtHit = (PndMdtHit*)fMdtHit->At(mm);
1204  if ( fIdeal && ( ((PndMdtPoint*)fMdtPoint->At(mdtHit->GetRefIndex()))->GetTrackID() !=pidCand->GetMcIndex()) ) continue;
1205  if (mdtHit->GetLayerID()!=0) continue;
1206  if (mdtHit->GetModule()>2) continue;
1207  mdtHit->Position(mdtPos);
1208  if (fGeanePro) // Overwrites vertex if Geane is used
1209  {
1210 
1211  fProMdt->SetPoint(mdtPos);
1212  fProMdt->PropagateToPCA(1, 1);
1213  vertex.SetXYZ(-10000, -10000, -10000); // reset vertex
1214  vertexD.SetXYZ(-10000, -10000, -10000); // reset vertex
1215  FairTrackParH *fRes= new FairTrackParH();
1216  Bool_t rc = fProMdt->Propagate(helix, fRes, fPidHyp*pidCand->GetCharge());
1217  if (!rc) continue;
1218  mdtTempMom = fRes->GetMomentum().Mag();
1219  vertex.SetXYZ(fRes->GetX(), fRes->GetY(), fRes->GetZ());
1220  vertexD.SetXYZ(fRes->GetDX(), fRes->GetDY(), fRes->GetDZ());
1221  mdtGLength = fProMdt->GetLengthAtPCA();
1222  }
1223 
1224  Float_t dist;
1225  if (mdtHit->GetModule()==1)
1226  {
1227  dist = (mdtPos-vertex).Mag2();
1228  }
1229  else
1230  {
1231  dist = (vertex.X()-mdtPos.X())*(vertex.X()-mdtPos.X())+(vertex.Y()-mdtPos.Y())*(vertex.Y()-mdtPos.Y());
1232  }
1233 
1234  if ( mdtQuality > dist)
1235  {
1236  mdtIndex = mm;
1237  mdtQuality = dist;
1238  mdtMod = mdtHit->GetModule();
1239  mdtMom = mdtTempMom;
1240  mdtLayer = 1;
1241  if (fMdtMode==3)
1242  {
1243  PndMdtTrk *mdtTrk = (PndMdtTrk*)fMdtTrk->At(mapMdtTrk[mdtIndex]);
1244  mdtIndex = mapMdtTrk[mm];
1245  mdtLayer = mdtTrk->GetLayerCount();
1246  mdtIron = mdtTrk->GetIronDist();
1247  mdtMod = mdtTrk->GetModule();
1248  mdtHits = 0;
1249  for (Int_t iLayer=0; iLayer<mdtLayer; iLayer++)
1250  {
1251  mdtHits = mdtHits + mdtTrk->GetHitMult(iLayer);
1252  //std::cout << iLayer << "\t" << mdtTrk->GetHitMult(iLayer) << "\t" << mdtHits << std::endl;
1253  }
1254  }
1255  }
1256  if (fDebugMode)
1257  {
1258  Float_t ntuple[] = {vertex.X(), vertex.Y(), vertex.Z(),
1259  vertexD.X(), vertexD.Y(), vertexD.Z(), vertex.Phi(),
1260  helix->GetMomentum().Mag(), helix->GetQ(), helix->GetMomentum().Theta(), helix->GetZ(),
1261  mdtPos.X(), mdtPos.Y(), mdtPos.Z(), mdtPos.Phi(), mdtTempMom,
1262  dist, mdtHit->GetModule(), vertex.DeltaPhi(mdtPos), mdtGLength, mdtLayer, mdtHits};
1263  mdtCorr->Fill(ntuple);
1264  }
1265  }
1266 
1267  if ((mdtQuality<fCorrPar->GetMdtCut()) || ( fIdeal && mdtIndex!=-1))
1268  {
1269  pidCand->SetMuoIndex(mdtIndex);
1270  pidCand->SetMuoQuality(mdtQuality);
1271  pidCand->SetMuoIron(mdtIron);
1272  pidCand->SetMuoMomentumIn(mdtMom);
1273  pidCand->SetMuoModule(mdtMod);
1274  pidCand->SetMuoNumberOfLayers(mdtLayer);
1275  pidCand->SetMuoHits(mdtHits);
1276  }
1277 
1278  if (fMdtRefit && (mdtIndex!=-1) && (mdtMom>0.) )
1279  {
1280  PndMdtTrk *mdtTrk = (PndMdtTrk*)fMdtTrk->At(mdtIndex);
1281  PndTrack *mdtTrack = new PndTrack(*track);
1282  PndTrackCand *oldCand = track->GetTrackCandPtr();
1283  PndTrackCand *newCand = mdtTrk->AddTrackCand(oldCand);
1284  mdtTrack->SetTrackCand(*newCand);
1285  Int_t fCharge= mdtTrack->GetParamFirst().GetQ();
1286  Int_t PDGCode = fPidHyp*fCharge;
1287 
1288  PndTrack *fitTrack = new PndTrack();
1289  fitTrack = fFitter->Fit(mdtTrack, PDGCode);
1290  PndTrack* pndTrack = new PndTrack(fitTrack->GetParamFirst(), fitTrack->GetParamLast(), fitTrack->GetTrackCand(),
1291  fitTrack->GetFlag(), fitTrack->GetChi2(), fitTrack->GetNDF(), fitTrack->GetPidHypo(), fitTrack->GetRefIndex(), kLheTrack);
1292  AddMdtTrack(pndTrack);
1293  }
1294  return kTRUE;
1295 }
1296 
1297 //_________________________________________________________________
1298 Bool_t PndPidCorrelator::GetDrcInfo(FairTrackParH* helix, PndPidCandidate* pidCand) {
1299  if (helix->GetZ()>120.) return kFALSE; // cut fwd endcap tracks
1300  FairGeanePro *fProDrc = new FairGeanePro();
1301  if (!fCorrErrorProp) fProDrc->PropagateOnlyParameters();
1302  //---
1303  PndDrcHit *drcHit = NULL;
1304  Int_t drcEntries = fDrcHit->GetEntriesFast();
1305  Int_t drcIndex = -1, drcPhot = 0;
1306  Float_t drcThetaC = -1000, drcThetaCErr = 0, drcGLength = -1000;
1307  Float_t drcQuality = 1000000;
1308 
1309  TVector3 vertex(0., 0., 0.);
1310  Float_t vertex_z = -1000;
1311  TVector3 drcPos(0., 0., 0.);
1312  TVector3 momentum(0., 0., 0.);
1313 
1314  if (fGeanePro) // Overwrites vertex if Geane is used
1315  {
1316  fProDrc->PropagateToVolume("BarrelDIRC",0,1);
1317  vertex.SetXYZ(-10000, -10000, -10000); // reset vertex
1318  FairTrackParH *fRes= new FairTrackParH();
1319  Bool_t rc = fProDrc->Propagate(helix, fRes, fPidHyp*pidCand->GetCharge());
1320  if (!rc) return kFALSE;
1321  vertex.SetXYZ(fRes->GetX(), fRes->GetY(), 0.);
1322  vertex_z = fRes->GetZ();
1323  drcGLength = fProDrc->GetLengthAtPCA();
1324  if (drcGLength<25.) return kFALSE; // additional cut on extrapolation distance to avoid fake correlations
1325  }
1326 
1327  for (Int_t dd = 0; dd<drcEntries; dd++)
1328  {
1329  drcHit = (PndDrcHit*)fDrcHit->At(dd);
1330  if ( fIdeal && ( ((PndDrcBarPoint*)fDrcPoint->At(drcHit->GetRefIndex()))->GetTrackID() !=pidCand->GetMcIndex()) ) continue;
1331  drcHit->Position(drcPos);
1332 
1333  Float_t dphi = vertex.DeltaPhi(drcPos);
1334  Float_t dist = dphi * dphi;
1335  if (drcQuality > dist)
1336  {
1337  drcIndex = dd;
1338  drcQuality = dist;
1339  drcThetaC = drcHit->GetThetaC();
1340  drcThetaCErr = drcHit->GetErrThetaC();
1341  drcPhot = 0; // ** to be filled **
1342  }
1343  if (fDebugMode)
1344  {
1345  Float_t ntuple[] = {vertex.X(), vertex.Y(), vertex_z, vertex.Phi(),
1346  helix->GetMomentum().Mag(), helix->GetQ(), helix->GetMomentum().Theta(), helix->GetZ(),
1347  drcPos.X(), drcPos.Y(), drcPos.Phi(), dist, drcHit->GetThetaC(), 0., vertex.DeltaPhi(drcPos), drcGLength,
1348  pidCand->GetFitStatus()
1349  };
1350  drcCorr->Fill(ntuple);
1351  }
1352  }
1353 
1354  if ((drcQuality<fCorrPar->GetDrcCut()) || (fIdeal && drcIndex!=-1))
1355  {
1356  pidCand->SetDrcQuality(drcQuality);
1357  pidCand->SetDrcThetaC(drcThetaC);
1358  pidCand->SetDrcThetaCErr(drcThetaCErr);
1359  pidCand->SetDrcNumberOfPhotons(drcPhot);
1360  pidCand->SetDrcIndex(drcIndex);
1361  }
1362  return kTRUE;
1363 }
1364 
1365 //_________________________________________________________________
1366 Bool_t PndPidCorrelator::GetDskInfo(FairTrackParH* helix, PndPidCandidate* pidCand) {
1367  if (helix->GetZ()<180.) return kFALSE; // consider tracks only from last gem plane
1368 
1369  FairGeanePro *fProDsk = new FairGeanePro();
1370  if (!fCorrErrorProp) fProDsk->PropagateOnlyParameters();
1371  //---
1372  PndDskParticle *dskParticle = NULL;
1373  Int_t dskEntries = fDskParticle->GetEntriesFast();
1374  Int_t dskIndex = -1, dskPhot = 0;
1375  Float_t dskThetaC = -1000, dskThetaCErr = 0, dskGLength = -1000;
1376  Float_t dskQuality = 1000000;
1377  Float_t x_p = -1000;
1378 
1379  TVector3 vertex(0., 0., 0.);
1380  TVector3 dskPos(0., 0., 0.);
1381  TVector3 momentum(0., 0., 0.);
1382 
1383  if (fGeanePro) // Overwrites vertex if Geane is used
1384  {
1385  fProDsk->PropagateToVolume("Plate",0,1);
1386  vertex.SetXYZ(-10000, -10000, -10000); // reset vertex
1387  FairTrackParH *fRes= new FairTrackParH();
1388  Bool_t rc = fProDsk->Propagate(helix, fRes, fPidHyp*pidCand->GetCharge());
1389  if (!rc) return kFALSE;
1390  vertex.SetXYZ(fRes->GetX(), fRes->GetY(), fRes->GetZ());
1391  dskGLength = fProDsk->GetLengthAtPCA();
1392  x_p = fRes->GetMomentum().Mag();
1393  }
1394 
1395  for (Int_t dd = 0; dd<dskEntries; dd++)
1396  {
1397  dskParticle = (PndDskParticle*)fDskParticle->At(dd);
1398  if ( fIdeal && (dskParticle->GetTrackID() !=pidCand->GetMcIndex()) ) continue;
1399  dskParticle->Position(dskPos);
1400 
1401  Float_t dist = (vertex-dskPos).Mag2();
1402  if ( dskQuality > dist)
1403  {
1404  dskIndex = dd;
1405  dskQuality = dist;
1406  dskThetaC = dskParticle->GetThetaC();
1407  //dskThetaCErr = dskParticle->GetErrThetaC();
1408  dskPhot = 0; // ** to be filled **
1409  }
1410  if (fDebugMode)
1411  {
1412  Float_t ntuple[] = {vertex.X(), vertex.Y(), vertex.Z(), vertex.Phi(),
1413  helix->GetMomentum().Mag(), helix->GetQ(), helix->GetMomentum().Theta(), helix->GetZ(),
1414  dskPos.X(), dskPos.Y(), dskPos.Z(), dskPos.Phi(), dist, dskParticle->GetThetaC(), 0., vertex.DeltaPhi(dskPos), dskGLength,
1415  helix->GetX(), helix->GetY(), helix->GetZ(), x_p, pidCand->GetFitStatus()
1416 };
1417  dskCorr->Fill(ntuple);
1418  }
1419  }
1420 
1421  if ((dskQuality<fCorrPar->GetDskCut()) || (fIdeal && dskIndex!=-1))
1422  {
1423  pidCand->SetDiscQuality(dskQuality);
1424  pidCand->SetDiscThetaC(dskThetaC);
1425  //pidCand->SetDskThetaCErr(dskThetaCErr);
1426  pidCand->SetDiscNumberOfPhotons(dskPhot);
1427  pidCand->SetDiscIndex(dskIndex);
1428  }
1429  return kTRUE;
1430 }
1431 #endif
1432 
1433 //_________________________________________________________________
1435  //---
1436  TString chargName = "PidChargedCand" + fTrackOutBranch;
1437  FairRootManager::Instance()->Register(chargName,"Pid", fPidChargedCand, kTRUE);
1438 
1439 #if _TODAY_
1441  Register("PidNeutralCand","Pid", fPidNeutralCand, kTRUE);
1442  if (fMdtRefit)
1443  {
1445  Register("MdtTrack","Pid", fMdtTrack, kTRUE);
1446  }
1447 #endif
1448 }
1449 
1450 //_________________________________________________________________
1452 #if _TODAY_
1453  //---
1454  if (fDebugMode)
1455  {
1456  //TFile *r = TFile::Open(sDir+sFile,"RECREATE");
1457  r->cd();
1458  tofCorr->Write();
1459  ftofCorr->Write();
1460  emcCorr->Write();
1461  fscCorr->Write();
1462  mdtCorr->Write();
1463  drcCorr->Write();
1464  dskCorr->Write();
1465 
1466  r->Save();
1467 
1468  tofCorr->Delete();
1469  ftofCorr->Delete();
1470  emcCorr->Delete();
1471  fscCorr->Delete();
1472  mdtCorr->Delete();
1473  drcCorr->Delete();
1474  dskCorr->Delete();
1475 
1476  tofCorr = 0;
1477  ftofCorr = 0;
1478  emcCorr = 0;
1479  fscCorr = 0;
1480  mdtCorr = 0;
1481  drcCorr = 0;
1482  dskCorr = 0;
1483 
1484  r->Close();
1485  r->Delete();
1486  }
1487 #endif
1488 }
1489 //_________________________________________________________________
1491 #if _TODAY_
1492  //---
1493  fMvdPath = 0.;
1494  fMvdELoss = 0.;
1495  fMvdHitCount = 0;
1496  fEmcClstCount = 0;
1497  fFscClstCount = 0;
1498  fClusterList.clear();
1499  fClusterQ.clear();
1500  mapMdtBarrel.clear();
1501  mapMdtEndcap.clear();
1502  mapMdtForward.clear();
1503 #endif
1504 }
1505 
1506 //_________________________________________________________________
1508  // Creates a new hit in the TClonesArray.
1509  TClonesArray& pidRef = *fPidChargedCand;
1510  Int_t size = pidRef.GetEntriesFast();
1511  return new(pidRef[size]) PndPidCandidate(*cand);
1512 }
1513 
1514 #if _TODAY_
1515 //_________________________________________________________________
1516 PndPidCandidate* PndPidCorrelator::AddNeutralCandidate(PndPidCandidate* cand) {
1517  // Creates a new hit in the TClonesArray.
1518 
1519  TClonesArray& pidRef = *fPidNeutralCand;
1520  Int_t size = pidRef.GetEntriesFast();
1521  return new(pidRef[size]) PndPidCandidate(*cand);
1522 }
1523 
1524 //_________________________________________________________________
1525 PndTrack* PndPidCorrelator::AddMdtTrack(PndTrack* track) {
1526  // Creates a new hit in the TClonesArray.
1527 
1528  TClonesArray& pidRef = *fMdtTrack;
1529  Int_t size = pidRef.GetEntriesFast();
1530  return new(pidRef[size]) PndTrack(*track);
1531 }
1532 #endif
1533