FairRoot/PandaRoot
PndPidFtofAssociatorTask.cxx
Go to the documentation of this file.
2 #include "PndPidCandidate.h"
3 #include "PndPidProbability.h"
4 #include "PndPidCorrPar.h"
5 #include "FairRootManager.h"
6 #include "FairRun.h"
7 #include "FairRuntimeDb.h"
8 
9 #include "TMath.h"
10 #include "TF1.h"
11 #include "Riostream.h"
12 
13 
14 //___________________________________________________________
16  //
17  FairRootManager *fManager =FairRootManager::Instance();
18  fManager->Write();
19 }
20 
21 //___________________________________________________________
23  //---
24  fPidChargedProb = new TClonesArray("PndPidProbability");
26 }
27 
28 //___________________________________________________________
29 PndPidFtofAssociatorTask::PndPidFtofAssociatorTask(const char *name, const char *title):FairTask(name), fCorrPar()
30 {
31  //---
32  fPidChargedProb = new TClonesArray("PndPidProbability");
34  SetTitle(title);
35 }
36 
37 //___________________________________________________________
39 
40  std::cout << "InitStatus PndPidFtofAssociatorTask::Init()" << std::endl;
41 
42  FairRootManager *fManager =FairRootManager::Instance();
43 
44  fPidChargedCand = (TClonesArray *)fManager->GetObject("PidChargedCand"+fTrackBranchNamePidHypo);
45  if ( ! fPidChargedCand) {
46  std::cout << "-I- PndPidFtofAssociatorTask::Init: No PndPidCandidate array PidChargedCand there!" << std::endl;
47  return kERROR;
48  }
49 
50  Register();
51 
52  std::cout << "-I- PndPidFtofAssociatorTask::Init: Success!" << std::endl;
53 
54  return kSUCCESS;
55 }
56 
57 //______________________________________________________
59  //--
60  // Get run and runtime database
61  FairRun* run = FairRun::Instance();
62  if ( ! run ) Fatal("PndPidFtofAssociatorTask:: SetParContainers", "No analysis run");
63 
64  FairRuntimeDb* db = run->GetRuntimeDb();
65  if ( ! db ) Fatal("PndPidFtofAssociatorTask:: SetParContainers", "No runtime database");
66 
67  // Get PID Correlation parameter container
68  fCorrPar = (PndPidCorrPar*) db->getContainer("PndPidCorrPar");
69 
70 }
71 //______________________________________________________
73  if (fPidChargedProb->GetEntriesFast() != 0) fPidChargedProb->Clear();
74  if(fVerbose>1) std::cout << "-I- Start PndPidFtofAssociatorTask. "<<std::endl;
75 
76  // Get the Candidates
77  for(Int_t i=0; i<fPidChargedCand->GetEntriesFast(); i++)
78  {
80  TClonesArray& pidRef = *fPidChargedProb;
81  PndPidProbability* prob = new(pidRef[i]) PndPidProbability();// initializes with zeros
82  prob->SetIndex(i);
83  if (pidcand->GetTofIndex()==-1) continue;
84  if (pidcand->GetLastHit().Z() < fCorrPar->GetZLastPlane()) continue; // runs ftof pid only for forward tracks
85  DoPidMatch(pidcand,prob);
86  }
87 
88 }
89 
91 {
92 
93  Double_t mom = pidcand->GetMomentum().Mag();
94 
95  // electron
96  {
97  Double_t mass = 0.0005;
98  Double_t center = mom / TMath::Sqrt(mom*mom + mass*mass);
99  if (mom > 1) center = center - 0.; //electron OK
100  Double_t sigma = 0.004;
101  prob->SetElectronPdf(GetPdf(pidcand->GetTofM2(),pidcand->GetMomentum().Mag(),center, sigma));
102  }
103 
104  // muon
105  {
106  Double_t mass = 0.106;
107  Double_t center = mom / TMath::Sqrt(mom*mom + mass*mass);
108  if (mom > 1) center = center - 0.1 + 0.1*mom; //tracking bug, later remove
109  Double_t sigma = 0.004 + 0.64*exp(-mom/0.11);
110  prob->SetMuonPdf(GetPdf(pidcand->GetTofM2(),pidcand->GetMomentum().Mag(),center, sigma));
111  }
112 
113  // pion
114  {
115  Double_t mass = 0.140;
116  Double_t center = mom / TMath::Sqrt(mom*mom + mass*mass);
117  if (mom > 1) center = center - 0.1 + 0.1*mom; //tracking bug, later remove
118  Double_t sigma = 0.004 + 0.64*exp(-mom/0.11);
119  prob->SetPionPdf(GetPdf(pidcand->GetTofM2(),pidcand->GetMomentum().Mag(),center, sigma));
120  }
121 
122  // kaon
123  {
124  Double_t mass = 0.494;
125  Double_t center = mom / TMath::Sqrt(mom*mom + mass*mass);
126  if (mom > 1) center = center - 0.39 + 0.37*mom; //tracking bug, later remove
127  Double_t sigma = 0.004 + 0.62*exp(-mom/0.21);
128  prob->SetKaonPdf(GetPdf(pidcand->GetTofM2(),pidcand->GetMomentum().Mag(),center, sigma));
129  }
130 
131  // proton
132  {
133  Double_t mass = 0.938;
134  Double_t center = mom / TMath::Sqrt(mom*mom + mass*mass);
135  if (mom > 1) center = center - 0.12 + 0.12*mom; //tracking bug, later remove
136  Double_t sigma = 0.004 + 0.5*exp(-mom/0.13);
137  prob->SetProtonPdf(GetPdf(pidcand->GetTofM2(),pidcand->GetMomentum().Mag(),center, sigma));
138  }
139 }
140 
142 {
143 
144  Double_t beta_c = mom / TMath::Sqrt(mom*mom + mass2);
145  if (beta_c>0.)
146  {
147  TF1 *gausPdf = new TF1("gausPdf","gausn",0,1);
148  gausPdf->SetParameter(0,1);
149  gausPdf->SetParameter(1,center);
150  gausPdf->SetParameter(2,sigma);
151  Double_t val = gausPdf->Eval(beta_c);
152  delete gausPdf;
153  return val;
154  }
155  else
156  {
157  // FIXME: Don't write zeros to that pdf!
158  return 0.;
159  }
160 }
161 
162 //_________________________________________________________________
164  //---
165  FairRootManager::Instance()->
166  Register("PidAlgoFtof"+fTrackBranchNamePidHypo,"Pid", fPidChargedProb, kTRUE);
167 }
168 
169 //_________________________________________________________________
171 }
172 
173 //_________________________________________________________________
175  //---
176 }
177 
178 
virtual void Exec(Option_t *option)
int fVerbose
Definition: poormantracks.C:24
Int_t run
Definition: autocutx.C:47
friend F32vec4 exp(const F32vec4 &a)
Definition: P4_F32vec4.h:109
Int_t i
Definition: run_full.C:25
void SetPionPdf(Double_t val)
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
void SetKaonPdf(Double_t val)
Double_t sigma[nsteps]
Definition: dedx_bands.C:65
TString fTrackBranchNamePidHypo
PndPidProbability TCA for charged particles.
Double_t mom
Definition: plot_dirc.C:14
void SetElectronPdf(Double_t val)
void SetMuonPdf(Double_t val)
h_MC_angle SetTitle("MC truth: opening angle of #pi^{0}")
Int_t GetTofIndex() const
Double_t
void DoPidMatch(PndPidCandidate *pidcand, PndPidProbability *prob)
TVector3 GetLastHit() const
TString name
void SetProtonPdf(Double_t val)
Double_t GetPdf(Double_t mass2, Double_t mom, Double_t mass, Double_t sigma)
ClassImp(PndAnaContFact)
TClonesArray * fPidChargedProb
PndPidCandidate TCA for charged particles.
TVector3 GetMomentum() const
Float_t GetTofM2() const
void SetIndex(Int_t idx)
Float_t GetZLastPlane()
Definition: PndPidCorrPar.h:22