FairRoot/PandaRoot
PndPidIdealFwdOnlyAssociatorTask.cxx
Go to the documentation of this file.
1 #include "PndDetectorList.h"
3 #include "PndPidCandidate.h"
4 #include "PndPidProbability.h"
5 #include "PndMCTrack.h"
6 
7 #include "FairRootManager.h"
8 
9 #include "TDatabasePDG.h"
10 
11 
12 #include <cmath>
13 
14 
15 //___________________________________________________________
17  //
18  FairRootManager *fManager =FairRootManager::Instance();
19  fManager->Write();
20 }
21 
22 //___________________________________________________________
24  //---
25  fNeutralBranchName="PidAlgoIdealFwdOnlyNeutral";
26  fChargedBranchName="PidAlgoIdealFwdOnlyCharged";
27  fPidChargedProb = new TClonesArray("PndPidProbability");
28  fPidNeutralProb = new TClonesArray("PndPidProbability");
29 }
30 
31 //___________________________________________________________
33 :FairTask(name) {
34  //---
35  fNeutralBranchName="PidAlgoIdealFwdOnlyNeutral";
36  fChargedBranchName="PidAlgoIdealFwdOnlyCharged";
37  fPidChargedProb = new TClonesArray("PndPidProbability");
38  fPidNeutralProb = new TClonesArray("PndPidProbability");
39  SetTitle(title);
40 }
41 
43 {
44  fNeutralBranchName="PidNeutralProbability";
45  fChargedBranchName="PidChargedProbability";
46 }
47 
48 
49 //___________________________________________________________
51 
52  // cout << "InitStatus PndPidIdealFwdOnlyAssociatorTask::Init()" << endl;
53 
54  FairRootManager *fManager =FairRootManager::Instance();
55 
56  // TODO: Am I allowed to write in these Arrays?
57  fPidChargedCand = (TClonesArray *)fManager->GetObject("PidChargedCand");
58  if ( ! fPidChargedCand) {
59  std::cout << "-I- PndPidIdealFwdOnlyAssociatorTask::Init: No PndPidCandidate array PidChargedCand there!" << std::endl;
60  return kERROR;
61  }
62 
63  fPidNeutralCand = (TClonesArray *)fManager->GetObject("PidNeutralCand");
64  if ( ! fPidNeutralCand) {
65  std::cout << "-I- PndPidIdealFwdOnlyAssociatorTask::Init: No PndPidCandidate array PidNeutralCand there!" << std::endl;
66  return kERROR;
67  }
68 
69  fMCTrack = (TClonesArray*) fManager->GetObject("MCTrack");
70  if ( ! fMCTrack) {
71  std::cout << "-I- PndPidIdealFwdOnlyAssociatorTask::Init: No MC Track array there!" << std::endl;
72  return kERROR;
73  }
74 
75  Register();
76 
77  std::cout << "-I- PndPidIdealFwdOnlyAssociatorTask::Init: Success!" << std::endl;
78 
79  return kSUCCESS;
80 }
81 
82 //______________________________________________________
84  //--
85 }
86 //______________________________________________________
88  // CAUTION We use Monte-Carlo info here!
89 
90  if(fVerbose>1) std::cout << "-I- Start PndPidIdealFwdOnlyAssociatorTask. "<<std::endl;
91  if (fPidChargedProb->GetEntriesFast() != 0) fPidChargedProb->Clear();
92  if (fPidNeutralProb->GetEntriesFast() != 0) fPidNeutralProb->Clear();
93  // Get the Candidates
94  for(Int_t i=0; i<fPidChargedCand->GetEntriesFast(); i++){
96  PndPidProbability* prob = new((*fPidChargedProb)[i]) PndPidProbability(1.,1.,1.,1.,1.,i);// initializes with equal probability
97  if(fVerbose>1) std::cout<<"-I- PndPidIdealFwdOnlyAssociatorTask Charged BEFORE "<< pidcand->GetLorentzVector().M()<<std::endl;;
98  if(! IsForward(pidcand) ) continue;
99  DoPidMatch(pidcand,prob);
100  if(fVerbose>1) std::cout<<"-I- PndPidIdealFwdOnlyAssociatorTask Charged AFTER "<< pidcand->GetLorentzVector().M()<<std::endl;;
101  }
102  for(Int_t i=0; i<fPidNeutralCand->GetEntriesFast(); i++){
103  //PndPidCandidate* pidcand = (PndPidCandidate*)fPidNeutralCand->At(i); //[R.K. 01/2017] unused variable
104  new((*fPidNeutralProb)[i]) PndPidProbability(1.,1.,1.,1.,1.,i);//PndPidProbability* prob = //[R.K.03/2017] unused variable
105  // initializes with eqaual pdf (no preference)
106  //DoPidMatch(pidcand,prob); //TODO match idealy neutral cands, esp. when we have pi0s
107  }
108 
109 }
110 
112 {
113  // Cheating for each Pid Candidate.
114 
115  Int_t mcid = pidcand->GetMcIndex();
116  if(mcid<0) return; // no specified MC id... do nothing
117  PndMCTrack *mctrack = (PndMCTrack*)fMCTrack->At(mcid);
118  if( 0==mctrack) return; // better do nothing on a null pointer
119  Int_t mcpdg = mctrack->GetPdgCode();
120 
121  // TLorentzVector lv = pidcand->GetLorentzVector();
122  // Double_t mass = TDatabasePDG::Instance()->GetParticle(mcpdg)->Mass();
123  // lv.SetXYZM(lv.X(), lv.Y(), lv.Z(), mass);
124  // pidcand->SetLorentzVector(lv);
125 
126  // chaet around with the probabilities...
127  switch(mcpdg) {
128  case -11: //positron
129  case 11: //electron
130  prob->SetProtonPdf(0.);
131  prob->SetKaonPdf(0.);
132  prob->SetPionPdf(0.);
133  prob->SetMuonPdf(0.);
134  prob->SetElectronPdf(1.);
135  break;
136 
137  case -13: //muon+
138  case 13: //muon-
139  prob->SetProtonPdf(0.);
140  prob->SetKaonPdf(0.);
141  prob->SetPionPdf(0.);
142  prob->SetMuonPdf(1.);
143  prob->SetElectronPdf(0.);
144  break;
145 
146  case 211: //pion+
147  case -211: //pion-
148  prob->SetProtonPdf(0.);
149  prob->SetKaonPdf(0.);
150  prob->SetPionPdf(1.);
151  prob->SetMuonPdf(0.);
152  prob->SetElectronPdf(0.);
153  break;
154 
155  case -321: //Kaon+
156  case 321: //Kaon-
157  prob->SetProtonPdf(0.);
158  prob->SetKaonPdf(1.);
159  prob->SetPionPdf(0.);
160  prob->SetMuonPdf(0.);
161  prob->SetElectronPdf(0.);
162  break;
163 
164  case -2212: //antiproton
165  case 2212: //proton
166  prob->SetProtonPdf(1.);
167  prob->SetKaonPdf(0.);
168  prob->SetPionPdf(0.);
169  prob->SetMuonPdf(0.);
170  prob->SetElectronPdf(0.);
171  break;
172 
173  default:
174  prob->SetProtonPdf(1.);
175  prob->SetKaonPdf(1.);
176  prob->SetPionPdf(1.);
177  prob->SetMuonPdf(1.);
178  prob->SetElectronPdf(1.);
179  break;
180  }
181 
182 }
183 
184 
185 //_________________________________________________________________
187  //---
188  // Checks if the track is in 5-10 degree in y and x respectively
189  // tan(10˚) and tan(5˚) in numbers, don't call trig. functions too often.
190  TVector3 vec = cand->GetMomentum();
191  if( 0.08748866 * vec.y() > vec.z()) return kFALSE;
192  if( 0.17632698 * vec.x() > vec.z()) return kFALSE;
193  return kTRUE;
194 }
195 
196 
197 
198 
199 //_________________________________________________________________
201  //---
202  FairRootManager::Instance()->
204  FairRootManager::Instance()->
206 }
207 
208 //_________________________________________________________________
210  //---
211  // FairRootManager* ioman = FairRootManager::Instance();
212  // ioman->W
213 }
214 //_________________________________________________________________
216  //---
217 }
218 
219 
PndMCTrack * mctrack
int fVerbose
Definition: poormantracks.C:24
Int_t i
Definition: run_full.C:25
void SetPionPdf(Double_t val)
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
TLorentzVector GetLorentzVector() const
void SetKaonPdf(Double_t val)
TClonesArray * fPidChargedProb
PndPidCandidate TCA for neutral particles.
void SetElectronPdf(Double_t val)
Int_t GetMcIndex() const
void SetMuonPdf(Double_t val)
h_MC_angle SetTitle("MC truth: opening angle of #pi^{0}")
TClonesArray * fPidNeutralProb
PndPidProbability TCA for charged particles.
TString name
int mcpdg
void SetProtonPdf(Double_t val)
void DoPidMatch(PndPidCandidate *pidcand, PndPidProbability *prob)
Monte-Carlo Truth track TCA.
ClassImp(PndAnaContFact)
TClonesArray * fPidNeutralCand
PndPidCandidate TCA for charged particles.
TVector3 GetMomentum() const
dble_vec_t vec[12]
Definition: ranlxd.cxx:380
TClonesArray * fMCTrack
PndPidProbability TCA for neutral particles.