FairRoot/PandaRoot
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PndPidEmcBayesAssociatorTask Class Reference

#include <PndPidEmcBayesAssociatorTask.h>

Inheritance diagram for PndPidEmcBayesAssociatorTask:

Public Member Functions

virtual void Exec (Option_t *option)
 
virtual InitStatus Init ()
 
void SetupEnvironment (char *filename)
 
void Register ()
 
void Reset ()
 
 PndPidEmcBayesAssociatorTask (const char *name, const char *title="Pnd Task")
 
 PndPidEmcBayesAssociatorTask ()
 
virtual ~PndPidEmcBayesAssociatorTask ()
 
void SetVerbose (Bool_t verb)
 
virtual void SetParContainers ()
 
virtual void Finish ()
 
void SetOutputBranch (TString branch)
 

Protected Member Functions

void DoPidMatch (PndPidCandidate *pidcand, PndPidProbability *prob)
 
void GetPdf (Double_t pp1, Double_t th1, Double_t ph1, Double_t z20, Double_t z53, Double_t LAT, Double_t EP1, Int_t charge, Double_t *proba)
 

Protected Attributes

TClonesArray * fPidChargedCand
 
TClonesArray * fPidChargedProb
 PndPidCandidate TCA for charged particles. More...
 
TString fTrackBranchNamePidHypo
 PndPidProbability TCA for charged particles. More...
 
Int_t fNvar [6]
 
Int_t fNbins
 
TH2D * fBayesEP [10]
 
TH2D * fBayesTH [10]
 
TH2D * fBayesZZ [10]
 
TString fDirectory [10]
 
Int_t fevcounter
 

Detailed Description

Definition at line 23 of file PndPidEmcBayesAssociatorTask.h.

Constructor & Destructor Documentation

PndPidEmcBayesAssociatorTask::PndPidEmcBayesAssociatorTask ( const char *  name,
const char *  title = "Pnd Task" 
)

Definition at line 26 of file PndPidEmcBayesAssociatorTask.cxx.

References fPidChargedProb, fTrackBranchNamePidHypo, and SetTitle().

26  :FairTask(name)
27 {
28  //---
29  fPidChargedProb = new TClonesArray("PndPidProbability");
31  SetTitle(title);
32 }
TClonesArray * fPidChargedProb
PndPidCandidate TCA for charged particles.
h_MC_angle SetTitle("MC truth: opening angle of #pi^{0}")
TString fTrackBranchNamePidHypo
PndPidProbability TCA for charged particles.
TString name
PndPidEmcBayesAssociatorTask::PndPidEmcBayesAssociatorTask ( )

Definition at line 19 of file PndPidEmcBayesAssociatorTask.cxx.

References fPidChargedProb, and fTrackBranchNamePidHypo.

19  {
20  //---
21  fPidChargedProb = new TClonesArray("PndPidProbability");
23 }
TClonesArray * fPidChargedProb
PndPidCandidate TCA for charged particles.
TString fTrackBranchNamePidHypo
PndPidProbability TCA for charged particles.
PndPidEmcBayesAssociatorTask::~PndPidEmcBayesAssociatorTask ( )
virtual

Definition at line 12 of file PndPidEmcBayesAssociatorTask.cxx.

12  {
13  //
14  FairRootManager *fManager =FairRootManager::Instance();
15  fManager->Write();
16 }

Member Function Documentation

void PndPidEmcBayesAssociatorTask::DoPidMatch ( PndPidCandidate pidcand,
PndPidProbability prob 
)
protected

Definition at line 132 of file PndPidEmcBayesAssociatorTask.cxx.

References Double_t, emc(), EP, fVerbose, PndPidCandidate::GetEmcClusterLat(), PndPidCandidate::GetEmcClusterZ20(), PndPidCandidate::GetEmcClusterZ53(), PndPidCandidate::GetEmcRawEnergy(), PndPidCandidate::GetLorentzVector(), GetPdf(), PndPidProbability::SetElectronPdf(), PndPidProbability::SetKaonPdf(), PndPidProbability::SetMuonPdf(), PndPidProbability::SetPionPdf(), PndPidProbability::SetProtonPdf(), and CAMath::Sqrt().

Referenced by Exec().

133 {
134 // Double_t mom = pidcand->GetMomentum().Mag();
135  Double_t radeg=57.29578;
136 
137  Int_t Charge = pidcand-> GetCharge();
138  Double_t emc = pidcand->GetEmcRawEnergy();
139  Double_t z20 = pidcand->GetEmcClusterZ20();
140  Double_t z53 = pidcand->GetEmcClusterZ53();
141  Double_t lat = pidcand->GetEmcClusterLat();
142  TLorentzVector pidTrack = pidcand->GetLorentzVector();
143  Double_t pidx = pidTrack.Px();
144  Double_t pidy = pidTrack.Py();
145  Double_t pidz = pidTrack.Pz();
146  Double_t pidth = radeg*pidTrack.Theta();
147  Double_t pidph = radeg*pidTrack.Phi();
148 
149  Double_t pidp = TMath::Sqrt(pidx*pidx+pidy*pidy+pidz*pidz);
150  Double_t EP = emc/pidp;
151 
152 // Get the probabilities
153  Double_t proba[5];
154  GetPdf(pidp,pidth,pidph,z20,z53,lat,EP,Charge,proba);
155  if(fVerbose>1) {
156  std::cout <<" proba in Pidmatch: " << proba[0] << " ";
157  std::cout << proba[1] << " " << proba[2] << " ";
158  std::cout << proba[3] << " " << proba[4] << std::endl;
159  }
160 
161 // And store them
162  // electron
163  {
164  prob->SetElectronPdf(proba[0]);
165  }
166 
167  // muon
168  {
169  prob->SetMuonPdf(proba[1]);
170  }
171 
172  // pion
173  {
174  prob->SetPionPdf(proba[2]);
175  }
176 
177  // kaon
178  {
179  prob->SetKaonPdf(proba[3]);
180  }
181 
182  // proton
183  {
184  prob->SetProtonPdf(proba[4]);
185  }
186 }
int fVerbose
Definition: poormantracks.C:24
Float_t GetEmcRawEnergy() const
void SetPionPdf(Double_t val)
void emc(Int_t nEvents=10, Char_t part[]="e-", Double_t momentum_min=1.0, Double_t momentum_max=1.0, Double_t theta_min=0, Double_t theta_max=180, Double_t phi_min=0, Double_t phi_max=360, Char_t OutputSimFile[]="sim_emc.root", Char_t OutputDatabaseFile[]="simparams.root", Char_t TransportModel[]="TGeant3", UInt_t seed=0, Bool_t savepoints=kFALSE, Bool_t savehits=kFALSE, Bool_t savewaves=kFALSE, Bool_t savedigis=kFALSE, Bool_t saveclusters=kTRUE, Bool_t savebumps=kTRUE)
Definition: emc.C:1
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
TLorentzVector GetLorentzVector() const
void SetKaonPdf(Double_t val)
void GetPdf(Double_t pp1, Double_t th1, Double_t ph1, Double_t z20, Double_t z53, Double_t LAT, Double_t EP1, Int_t charge, Double_t *proba)
void SetElectronPdf(Double_t val)
void SetMuonPdf(Double_t val)
Double_t
Double_t GetEmcClusterZ53() const
Double_t GetEmcClusterLat() const
float EP[1000]
Double_t GetEmcClusterZ20() const
void SetProtonPdf(Double_t val)
void PndPidEmcBayesAssociatorTask::Exec ( Option_t *  option)
virtual

Definition at line 113 of file PndPidEmcBayesAssociatorTask.cxx.

References DoPidMatch(), fevcounter, fPidChargedCand, fPidChargedProb, fVerbose, PndPidCandidate::GetEmcIndex(), i, and PndPidProbability::SetIndex().

113  {
114  if (fPidChargedProb->GetEntriesFast() != 0) fPidChargedProb->Clear();
115  if(fVerbose>1) std::cout << "-I- Start PndPidEmcBayesAssociatorTask. "<<std::endl;
116  if(fVerbose>1) std::cout << "-I- counter: "<< fevcounter <<std::endl;
117  fevcounter++;
118 
119  // Get the Candidates
120  for(Int_t i=0; i<fPidChargedCand->GetEntriesFast(); i++)
121  {
123  TClonesArray& pidRef = *fPidChargedProb;
124  PndPidProbability* prob = new(pidRef[i]) PndPidProbability();// initializes with zeros
125  prob->SetIndex(i);
126  if (pidcand->GetEmcIndex()==-1) continue;
127  DoPidMatch(pidcand,prob);
128  }
129 
130 }
int fVerbose
Definition: poormantracks.C:24
Int_t i
Definition: run_full.C:25
TClonesArray * fPidChargedProb
PndPidCandidate TCA for charged particles.
Int_t GetEmcIndex() const
void DoPidMatch(PndPidCandidate *pidcand, PndPidProbability *prob)
void SetIndex(Int_t idx)
void PndPidEmcBayesAssociatorTask::Finish ( )
virtual

Definition at line 297 of file PndPidEmcBayesAssociatorTask.cxx.

297  {
298 }
void PndPidEmcBayesAssociatorTask::GetPdf ( Double_t  pp1,
Double_t  th1,
Double_t  ph1,
Double_t  z20,
Double_t  z53,
Double_t  LAT,
Double_t  EP1,
Int_t  charge,
Double_t proba 
)
protected

Definition at line 188 of file PndPidEmcBayesAssociatorTask.cxx.

References Double_t, EP, fBayesEP, fBayesTH, fBayesZZ, fVerbose, and CAMath::Log10().

Referenced by DoPidMatch().

191 {
192 // variables: pp,th,ph, z20, z53, LAT, E/P
193  Double_t lRange[7]={0.2, 5,-180, 0, 0, 0, 0};
194  Double_t uRange[7]={10 ,140, 180, 4, 5, 6, 2};
195  //Int_t nRange[7] ={14 , 7, 1, 1, 1,120}; //[R.K. 01/2017] unused variable
196  Double_t rangePconst0= 4.2318; // Two constants to ajust the momenta
197  Double_t rangePconst1= 5.7682; // calculated from the nominal range
198 
199  Double_t pp = ppin;
200  Double_t th = thin;
201  Double_t ph = phin;
202  Double_t Z20 = z20in;
203  Double_t Z53 = z53in;
204  Double_t LAT = LATin;
205  Double_t EP = EPin;
206  if(fVerbose>1) std::cout << "ppin: " << pp << std::endl;
207 
208 // trafo that spreads out the parameters
209  if( ppin<0.000001) ppin=0.000001;
210  if(z20in>0.999999) z20in=0.999999;
211  if(z53in<0.000001) z53in=0.000001;
212  if(LATin<0.000001) LATin=0.000001;
213 
214  pp = rangePconst0 + rangePconst1 * TMath::Log10(ppin);
215  Z20 = -TMath::Log10(1-z20in);
216  Z53 = -TMath::Log10(z53in);
217  LAT = -TMath::Log10(LATin);
218  if(fVerbose>1) std::cout << "pp: " << pp << std::endl;
219 
220 // if the values are outside the range, get them back in
221  Double_t pplook=ppin;
222 
223  if(pplook<lRange[0]) pplook=1.0001*lRange[0];
224  if(pplook>uRange[0]) pplook=0.9999*uRange[0];
225  if(th <lRange[1]) th =1.0001*lRange[1];
226  if(th >uRange[1]) th =0.9999*uRange[1];
227  if(ph <lRange[2]) ph =1.0001*lRange[2];
228  if(ph >uRange[2]) ph =0.9999*uRange[2];
229  if(Z20 <lRange[3]) Z20 =1.0001*lRange[3];
230  if(Z20 >uRange[3]) Z20 =0.9999*uRange[3];
231  if(Z53 <lRange[4]) Z53 =1.0001*lRange[4];
232  if(Z53 >uRange[4]) Z53 =0.9999*uRange[4];
233  if(LAT <lRange[5]) LAT =1.0001*lRange[5];
234  if(LAT >uRange[5]) LAT =0.9999*uRange[5];
235  if(EP <lRange[6]) EP =1.0001*lRange[6];
236  if(EP >uRange[6]) EP =0.9999*uRange[6];
237  if(fVerbose>1) std::cout << "pplook: " << pplook << std::endl;
238 
239 // Get the bins in the histograms
240  Int_t binxP = (fBayesEP[0]->GetXaxis())->FindBin(pplook);
241  Int_t binyP = (fBayesEP[0]->GetYaxis())->FindBin(EP);
242  Int_t binxT = (fBayesTH[0]->GetXaxis())->FindBin(pplook);
243  Int_t binyT = (fBayesTH[0]->GetYaxis())->FindBin(LAT);
244  Int_t binxZ = (fBayesZZ[0]->GetXaxis())->FindBin(pplook);
245  Int_t binyZ = (fBayesZZ[0]->GetYaxis())->FindBin(Z53);
246  Double_t PBayesE[5];
247  Double_t PBayesL[5];
248  Double_t PBayesZ[5];
249  Double_t PBayesB[5];
250 
251  if(fVerbose>1) {
252  std::cout << "pp: " << pp << " EP " << EP << std::endl;
253  std::cout << "probas: ";
254  }
255 
256 
257  Double_t probasum=0; // used for normalisation
258 
259  for (Int_t k=0; k<5; k++){
260  if(charge>0) {
261  PBayesE[k]=fBayesEP[k]->GetBinContent(binxP,binyP);
262  PBayesL[k]=fBayesTH[k]->GetBinContent(binxT,binyT);
263  PBayesZ[k]=fBayesZZ[k]->GetBinContent(binxZ,binyZ);
264  PBayesB[k]=PBayesE[k]*PBayesL[k]*PBayesZ[k];
265  probasum+=PBayesB[k];
266  } else {
267  PBayesE[k]=fBayesEP[k+5]->GetBinContent(binxP,binyP);
268  PBayesL[k]=fBayesTH[k+5]->GetBinContent(binxT,binyT);
269  PBayesZ[k]=fBayesZZ[k+5]->GetBinContent(binxZ,binyZ);
270  PBayesB[k]=PBayesE[k]*PBayesL[k]*PBayesZ[k];
271  probasum+=PBayesB[k];
272  }
273  PBayesB[k]=PBayesE[k]*PBayesL[k]*PBayesZ[k]/
274  (1-PBayesE[k])*(1-PBayesL[k])*(1-PBayesZ[k]);
275  if(fVerbose>1) std::cout << PBayesZ[k] << " ";
276  }
277 
278 
279 // Normalise the probabilities to one
280  for (Int_t k=0; k<5 ; k++){
281  if(probasum>0) {
282  proba[k]=PBayesB[k]/(1+PBayesB[k]);
283  } else {
284  proba[k]=1.;
285  }
286  }
287 }
int fVerbose
Definition: poormantracks.C:24
static T Log10(const T &x)
Definition: PndCAMath.h:41
Double_t
float EP[1000]
InitStatus PndPidEmcBayesAssociatorTask::Init ( )
virtual

Definition at line 35 of file PndPidEmcBayesAssociatorTask.cxx.

References fevcounter, fPidChargedCand, fTrackBranchNamePidHypo, Register(), and SetupEnvironment().

35  {
36 
37  std::cout << "InitStatus PndPidEmcBayesAssociatorTask::Init()" << std::endl;
38 
39  FairRootManager *fManager =FairRootManager::Instance();
40 
41  fPidChargedCand = (TClonesArray *)fManager->GetObject("PidChargedCand"+fTrackBranchNamePidHypo);
42  if ( ! fPidChargedCand) {
43  std::cout << "-I- PndPidEmcBayesAssociatorTask::Init: No PndPidCandidate array PidChargedCand there!" << std::endl;
44  return kERROR;
45  }
46 
47  Register();
48 
49  fevcounter=0;
50 
51  SetupEnvironment((char *)"BayesEMC.root"); // read back of the files
52  std::cout << "-I- PndPidEmcBayesAssociatorTask::Init: Success!!" << std::endl;
53 
54  return kSUCCESS;
55 }
TString fTrackBranchNamePidHypo
PndPidProbability TCA for charged particles.
void PndPidEmcBayesAssociatorTask::Register ( )

Definition at line 290 of file PndPidEmcBayesAssociatorTask.cxx.

References fPidChargedProb, and fTrackBranchNamePidHypo.

Referenced by Init().

290  {
291  //---
292  FairRootManager::Instance()->
293  Register("PidAlgoEmcBayes"+fTrackBranchNamePidHypo,"Pid", fPidChargedProb, kTRUE);
294 }
TClonesArray * fPidChargedProb
PndPidCandidate TCA for charged particles.
TString fTrackBranchNamePidHypo
PndPidProbability TCA for charged particles.
void PndPidEmcBayesAssociatorTask::Reset ( )

Definition at line 301 of file PndPidEmcBayesAssociatorTask.cxx.

301  {
302  //---
303 }
void PndPidEmcBayesAssociatorTask::SetOutputBranch ( TString  branch)
inline

Definition at line 70 of file PndPidEmcBayesAssociatorTask.h.

References fTrackBranchNamePidHypo.

Referenced by PndMasterMultiPidTask::PndMasterMultiPidTask().

70 { fTrackBranchNamePidHypo = branch; };
TString fTrackBranchNamePidHypo
PndPidProbability TCA for charged particles.
void PndPidEmcBayesAssociatorTask::SetParContainers ( )
virtual

Get parameter containers

Definition at line 109 of file PndPidEmcBayesAssociatorTask.cxx.

109  {
110  //--
111 }
void PndPidEmcBayesAssociatorTask::SetupEnvironment ( char *  filename)

Definition at line 58 of file PndPidEmcBayesAssociatorTask.cxx.

References fBayesEP, fBayesTH, fBayesZZ, filename, printf(), and TString.

Referenced by Init().

58  {
59 // read in all pdf files and store
60  TString fPath = getenv("VMCWORKDIR");
61  fPath += "/macro/params/";
62  TString fullName = fPath + filename;
63  printf("-I- PndPidEmcBayesAssociatorTask::SetupEnvironment:File used=%s",filename);
64  TFile* hfile1 = new TFile (fullName);
65 
66  fBayesEP[0] = (TH2D*)hfile1->Get("p.v.EP_proba_elecSpos");
67  fBayesTH[0] = (TH2D*)hfile1->Get("p.v.LAT_proba_elecSpos");
68  fBayesZZ[0] = (TH2D*)hfile1->Get("p.v.Z53_proba_elecSpos");
69 
70  fBayesEP[1] = (TH2D*)hfile1->Get("p.v.EP_proba_muonSpos");
71  fBayesTH[1] = (TH2D*)hfile1->Get("p.v.LAT_proba_muonSpos");
72  fBayesZZ[1] = (TH2D*)hfile1->Get("p.v.Z53_proba_muonSpos");
73 
74  fBayesEP[2] = (TH2D*)hfile1->Get("p.v.EP_proba_pionSpos");
75  fBayesTH[2] = (TH2D*)hfile1->Get("p.v.LAT_proba_pionSpos");
76  fBayesZZ[2] = (TH2D*)hfile1->Get("p.v.Z53_proba_pionSpos");
77 
78  fBayesEP[3] = (TH2D*)hfile1->Get("p.v.EP_proba_kaonSpos");
79  fBayesTH[3] = (TH2D*)hfile1->Get("p.v.LAT_proba_kaonSpos");
80  fBayesZZ[3] = (TH2D*)hfile1->Get("p.v.Z53_proba_kaonSpos");
81 
82  fBayesEP[4] = (TH2D*)hfile1->Get("p.v.EP_proba_protSpos");
83  fBayesTH[4] = (TH2D*)hfile1->Get("p.v.LAT_proba_protSpos");
84  fBayesZZ[4] = (TH2D*)hfile1->Get("p.v.Z53_proba_protSpos");
85 
86  fBayesEP[5] = (TH2D*)hfile1->Get("p.v.EP_proba_elecSneg");
87  fBayesTH[5] = (TH2D*)hfile1->Get("p.v.LAT_proba_elecSneg");
88  fBayesZZ[5] = (TH2D*)hfile1->Get("p.v.Z53_proba_elecSneg");
89 
90  fBayesEP[6] = (TH2D*)hfile1->Get("p.v.EP_proba_muonSneg");
91  fBayesTH[6] = (TH2D*)hfile1->Get("p.v.LAT_proba_muonSneg");
92  fBayesZZ[6] = (TH2D*)hfile1->Get("p.v.Z53_proba_muonSneg");
93 
94  fBayesEP[7] = (TH2D*)hfile1->Get("p.v.EP_proba_pionSneg");
95  fBayesTH[7] = (TH2D*)hfile1->Get("p.v.LAT_proba_pionSneg");
96  fBayesZZ[7] = (TH2D*)hfile1->Get("p.v.Z53_proba_pionSneg");
97 
98  fBayesEP[8] = (TH2D*)hfile1->Get("p.v.EP_proba_kaonSneg");
99  fBayesTH[8] = (TH2D*)hfile1->Get("p.v.LAT_proba_kaonSneg");
100  fBayesZZ[8] = (TH2D*)hfile1->Get("p.v.Z53_proba_kaonSneg");
101 
102  fBayesEP[9] = (TH2D*)hfile1->Get("p.v.EP_proba_protSneg");
103  fBayesTH[9] = (TH2D*)hfile1->Get("p.v.LAT_proba_protSneg");
104  fBayesZZ[9] = (TH2D*)hfile1->Get("p.v.Z53_proba_protSneg");
105 
106 
107 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
const string filename
void PndPidEmcBayesAssociatorTask::SetVerbose ( Bool_t  verb)
inline

Definition at line 64 of file PndPidEmcBayesAssociatorTask.h.

References fVerbose.

64 { fVerbose = verb ;};
int fVerbose
Definition: poormantracks.C:24

Member Data Documentation

TH2D* PndPidEmcBayesAssociatorTask::fBayesEP[10]
protected

Definition at line 43 of file PndPidEmcBayesAssociatorTask.h.

Referenced by GetPdf(), and SetupEnvironment().

TH2D* PndPidEmcBayesAssociatorTask::fBayesTH[10]
protected

Definition at line 44 of file PndPidEmcBayesAssociatorTask.h.

Referenced by GetPdf(), and SetupEnvironment().

TH2D* PndPidEmcBayesAssociatorTask::fBayesZZ[10]
protected

Definition at line 45 of file PndPidEmcBayesAssociatorTask.h.

Referenced by GetPdf(), and SetupEnvironment().

TString PndPidEmcBayesAssociatorTask::fDirectory[10]
protected

Definition at line 46 of file PndPidEmcBayesAssociatorTask.h.

Int_t PndPidEmcBayesAssociatorTask::fevcounter
protected

Definition at line 48 of file PndPidEmcBayesAssociatorTask.h.

Referenced by Exec(), and Init().

Int_t PndPidEmcBayesAssociatorTask::fNbins
protected

Definition at line 42 of file PndPidEmcBayesAssociatorTask.h.

Int_t PndPidEmcBayesAssociatorTask::fNvar[6]
protected

Definition at line 41 of file PndPidEmcBayesAssociatorTask.h.

TClonesArray* PndPidEmcBayesAssociatorTask::fPidChargedCand
protected

Definition at line 27 of file PndPidEmcBayesAssociatorTask.h.

Referenced by Exec(), and Init().

TClonesArray* PndPidEmcBayesAssociatorTask::fPidChargedProb
protected

PndPidCandidate TCA for charged particles.

Definition at line 28 of file PndPidEmcBayesAssociatorTask.h.

Referenced by Exec(), PndPidEmcBayesAssociatorTask(), and Register().

TString PndPidEmcBayesAssociatorTask::fTrackBranchNamePidHypo
protected

PndPidProbability TCA for charged particles.

Definition at line 30 of file PndPidEmcBayesAssociatorTask.h.

Referenced by Init(), PndPidEmcBayesAssociatorTask(), Register(), and SetOutputBranch().


The documentation for this class was generated from the following files: