FairRoot/PandaRoot
PndPidIdealAssociatorTask.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="PidAlgoIdealNeutral";
26  fChargedBranchName="PidAlgoIdealCharged";
28  fPidChargedProb = new TClonesArray("PndPidProbability");
29  fPidNeutralProb = new TClonesArray("PndPidProbability");
30 }
31 
32 //___________________________________________________________
34 :FairTask(name) {
35  //---
36  fNeutralBranchName="PidAlgoIdealNeutral";
37  fChargedBranchName="PidAlgoIdealCharged";
39  fPidChargedProb = new TClonesArray("PndPidProbability");
40  fPidNeutralProb = new TClonesArray("PndPidProbability");
41  SetTitle(title);
42 }
43 
45 {
46  fNeutralBranchName="PidNeutralProbability";
47  fChargedBranchName="PidChargedProbability";
48 }
49 
50 
51 //___________________________________________________________
53 
54  // cout << "InitStatus PndPidIdealAssociatorTask::Init()" << endl;
55 
56  FairRootManager *fManager =FairRootManager::Instance();
57 
58  // TODO: Am I allowed to write in these Arrays?
59  fPidChargedCand = (TClonesArray *)fManager->GetObject("PidChargedCand"+fTrackBranchNamePidHypo);
60  if ( ! fPidChargedCand) {
61  std::cout << "-I- PndPidIdealAssociatorTask::Init: No PndPidCandidate array PidChargedCand there!" << std::endl;
62  return kERROR;
63  }
64 
65  fPidNeutralCand = (TClonesArray *)fManager->GetObject("PidNeutralCand"+fTrackBranchNamePidHypo);
66  if ( ! fPidNeutralCand) {
67  std::cout << "-I- PndPidIdealAssociatorTask::Init: No PndPidCandidate array PidNeutralCand there!" << std::endl;
68  return kERROR;
69  }
70 
71  fMCTrack = (TClonesArray*) fManager->GetObject("MCTrack");
72  if ( ! fMCTrack) {
73  std::cout << "-I- PndPidIdealAssociatorTask::Init: No MC Track array there!" << std::endl;
74  return kERROR;
75  }
76 
77  Register();
78 
79  std::cout << "-I- PndPidIdealAssociatorTask::Init: Success!" << std::endl;
80 
81  return kSUCCESS;
82 }
83 
84 //______________________________________________________
86  //--
87 }
88 //______________________________________________________
90  // CAUTION We use Monte-Carlo info here!
91 
92  if(fVerbose>1) std::cout << "-I- Start PndPidIdealAssociatorTask. "<<std::endl;
93  if (fPidChargedProb->GetEntriesFast() != 0) fPidChargedProb->Clear();
94  if (fPidNeutralProb->GetEntriesFast() != 0) fPidNeutralProb->Clear();
95  // Get the Candidates
96  for(Int_t i=0; i<fPidChargedCand->GetEntriesFast(); i++){
98  PndPidProbability* prob = new((*fPidChargedProb)[i]) PndPidProbability(0.2,0.2,0.2,0.2,0.2,i);// initializes with equal probability
99  if(fVerbose>1) std::cout<<"-I- PndPidIdealAssociatorTask Charged BEFORE "<< pidcand->GetLorentzVector().M()<<std::endl;;
100  DoPidMatch(pidcand,prob);
101  if(fVerbose>1) std::cout<<"-I- PndPidIdealAssociatorTask Charged AFTER "<< pidcand->GetLorentzVector().M()<<std::endl;;
102  }
103  for(Int_t i=0; i<fPidNeutralCand->GetEntriesFast(); i++){
104  //PndPidCandidate* pidcand = (PndPidCandidate*)fPidNeutralCand->At(i); //[R.K. 01/2017] unused variable
105  new((*fPidNeutralProb)[i]) PndPidProbability(0.2,0.2,0.2,0.2,0.2,i);// initializes flat //PndPidProbability* prob = //[R.K.03/2017] unused variable
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(0.2);
175  prob->SetKaonPdf(0.2);
176  prob->SetPionPdf(0.2);
177  prob->SetMuonPdf(0.2);
178  prob->SetElectronPdf(0.2);
179  break;
180  }
181 
182 }
183 
184 
185 
186 
187 //_________________________________________________________________
189  //---
190  FairRootManager::Instance()->
192  FairRootManager::Instance()->
194 }
195 
196 //_________________________________________________________________
198  //---
199  // FairRootManager* ioman = FairRootManager::Instance();
200  // ioman->W
201 }
202 //_________________________________________________________________
204  //---
205 }
206 
207 
PndMCTrack * mctrack
int fVerbose
Definition: poormantracks.C:24
TClonesArray * fPidNeutralProb
PndPidProbability TCA for charged particles.
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)
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}")
virtual void Exec(Option_t *option)
TClonesArray * fPidChargedProb
PndPidCandidate TCA for neutral particles.
TString name
int mcpdg
void SetProtonPdf(Double_t val)
TClonesArray * fPidNeutralCand
PndPidCandidate TCA for charged particles.
TClonesArray * fMCTrack
PndPidProbability TCA for neutral particles.
ClassImp(PndAnaContFact)
void DoPidMatch(PndPidCandidate *pidcand, PndPidProbability *prob)
Monte-Carlo Truth track TCA.