FairRoot/PandaRoot
PndAnaPidSelector.cxx
Go to the documentation of this file.
1 //
2 // PndAnaPidSelector.cxx
3 // PANDAROOT
4 //
5 // Created by Ralf Kliemt on 12/16/11.
6 //
7 // This class does charged PID selection on RhoCandList objects.
8 // The cut parameters are taken from the RTDB
9 //
10 //
11 //
12 
13 #include <math.h>
14 #include "TDatabasePDG.h"
15 
16 #include "PndAnaPidSelector.h"
17 
18 #include "RhoBase/RhoCandidate.h"
19 #include "PndPidCandidate.h"
20 
21 #include "FairRun.h"
22 #include "FairRuntimeDb.h"
23 
24 #include "PndAnaContFact.h"
25 #include "PndAnaSelectorPar.h"
26 //#include "PndAnaFluxPar.h"
27 
28 #include "TString.h"
29 #include "TList.h"
30 
31 
33 
34 TBuffer& operator>> ( TBuffer& buf,PndAnaPidSelector *&obj )
35 {
36  obj = ( PndAnaPidSelector* ) buf.ReadObject ( PndAnaPidSelector::Class() );
37  return buf;
38 }
39 
40 PndAnaPidSelector::PndAnaPidSelector ( const char* name, const char* type, const char* ) : // paramid //[R.K.03/2017] unused variable(s)
41  RhoParticleSelectorBase ( name,type ) ,
42  fChargeCrit ( 0.0 ),
43  fPidSelect ( 99 ) // some silly default number here
44 
45 {
46  // reading parameters from RTDB
47  FairRun* ana = FairRun::Instance();
48  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
49  fSelectPar = ( PndAnaSelectorPar* ) ( rtdb->getContainer ( "ANAPidSelections" ) );
50 
51  if ( ! fSelectPar ) {
52  Fatal ( "PndAnaPidSelector","No ANAPidSelections* parameter found: %s","ANAPidSelections" );
53  }
54 
55  // PndAnaFluxPar* fFluxPar = (PndAnaFluxPar*)(rtdb->getContainer("ANAPidSelectionFlux"));
56  // if ( ! fFluxPar ) Fatal("SetParContainers","No ANAPidFlux parameter found: %s",parsetname.Data());
57  // }
58 
59  // Caution: The Parameter Set is not filled from the DB IO, yet.
60  Int_t runID = ana->GetRunId();
61 
62  // actually fill the containers.
63  //We might want to do that at another point, because multiple
64  //instnces will multiply call the RTDB init. That's bad in a loop!
65  rtdb->initContainers ( runID );
66 }
67 
69 {
70  //Default setting for criterion
72  TString critcopy(crit);
73 
74  // parse criterion string to criteria flags...
75 
76  if ( crit.Contains ( "VeryLoose" ) ) {
78  critcopy.ReplaceAll("VeryLoose","");
79  } else if ( crit.Contains ( "Loose" ) ) {
81  critcopy.ReplaceAll("Loose","");
82  } else if ( crit.Contains ( "VeryTight" ) ) {
84  critcopy.ReplaceAll("VeryTight","");
85  } else if ( crit.Contains ( "Tight" ) ) {
87  critcopy.ReplaceAll("Tight","");
88  } else if ( crit.Contains ( "Variable" ) ) {
90  critcopy.ReplaceAll("Variable","");
91  } else if ( crit.Contains ( "Best" ) ) {
93  critcopy.ReplaceAll("Best","");
94  } else if ( crit.Contains ( "All" ) ) {
96  critcopy.ReplaceAll("All","");
97  } // well, that's default anyway
98 
99  //TODO: make a 2d array of the criterion numbers for faster access
100 
101  fTypePlus=0;
102 
103  fTypeMinus=0;
104 
105  // Name convention for TDatabsePDG found at $ROOTSYS/etc/pdg_table.txt
106  fPidSelect=99;// some silly number here
107 
108  if ( crit.Contains ( "Proton" ) ) {
109  fTypePlus=TDatabasePDG::Instance()->GetParticle ( "p+" );
110  if ( 0==fTypePlus ) {
111  fTypePlus=TDatabasePDG::Instance()->GetParticle ( "proton" );
112  }
113  if ( 0==fTypePlus ) {
114  fTypePlus=TDatabasePDG::Instance()->GetParticle (2212);
115  }
116  fPidSelect=4;
117  critcopy.ReplaceAll("Proton","");
118  } else if ( crit.Contains ( "Kaon" ) ) {
119  fTypePlus=TDatabasePDG::Instance()->GetParticle ( "K+" );
120  if ( 0==fTypePlus ) {
121  fTypePlus=TDatabasePDG::Instance()->GetParticle (321);
122  }
123  fPidSelect=3;
124  critcopy.ReplaceAll("Kaon","");
125  } else if ( crit.Contains ( "Pion" ) ) {
126  fTypePlus=TDatabasePDG::Instance()->GetParticle ( "pi+" );
127  if ( 0==fTypePlus ) {
128  fTypePlus=TDatabasePDG::Instance()->GetParticle (211);
129  }
130  fPidSelect=2;
131  critcopy.ReplaceAll("Pion","");
132  } else if ( crit.Contains ( "Muon" ) ) {
133  fTypePlus=TDatabasePDG::Instance()->GetParticle ( "mu+" );
134  if ( 0==fTypePlus ) {
135  fTypePlus=TDatabasePDG::Instance()->GetParticle (-13);
136  }
137  fPidSelect=1;
138  critcopy.ReplaceAll("Muon","");
139  } else if ( crit.Contains ( "Electron" ) ) {
140  fTypePlus=TDatabasePDG::Instance()->GetParticle ( "e+" );
141  if ( 0==fTypePlus ) {
142  fTypePlus=TDatabasePDG::Instance()->GetParticle (-11);
143  }
144  fPidSelect=0;
145  critcopy.ReplaceAll("Electron","");
146  }
147 
148 //std::cout<<"PndAnaPidSelector: fPidSelect="<<fPidSelect<<std::endl;
149 
150  if ( fTypePlus!=0 ) {
152  }
153 
154  if ( crit.Contains ( "Plus" ) ) {
155  fChargeCrit=1.;
156  critcopy.ReplaceAll("Plus","");
157  } else if ( crit.Contains ( "Minus" ) ) {
158  fChargeCrit=-1.;
159  critcopy.ReplaceAll("Minus","");
160  } else {
161  fChargeCrit=0;
162  }
163 
164  if(critcopy.Length()>0){
165  std::cout<<"Analysis PID selection criteria setting failed. "<<std::endl;
166  std::cout<<"Selection String: \""<<crit.Data()<<"\""<<std::endl;
167  std::cout<<"Invalid piece: \""<<critcopy.Data()<<"\""<<std::endl;
168  std::cout<<"Viable optios are:"<<std::endl;
169  std::cout<<"\tProton,Kaon,Pion,Muon,Electron"<<std::endl;
170  std::cout<<"\tVeryLoose,Loose,Tight,VeryTight,Variable,Best,All"<<std::endl;
171  std::cout<<"\tPlus,Minus,Charged,Neutral,(All)"<<std::endl;
172  Error("SetSelection()","Invalid selection string.");
173  return kFALSE;
174  }
175 
176  return kTRUE;
177 }
178 
179 
181 {
182  // Accept or reject one candidate based on it's PID hypothesis, the pid
183  // pdf values and the selection criterion.
184  // This might be not performant, since each time we access an object to
185  // read the criterion value. Is a field of values faster?
186 
187  if ( b == 0 ) {
188  Error ( "PndAnaPidSelector::Accept","Candiate missing." ); return kFALSE;
189  }
190  //Info("PndAnaPidSelector::Accept","Request: Q=%g pid=%i crit=%i",fChargeCrit,fPidSelect,fCriterion);
191  // too stringent on charge with +-1. ??
192  if ( fChargeCrit!=0 && fChargeCrit!=b->GetCharge() ) {
193  //std::cout<<"PndAnaPidSelector::Accept: charge reject. fChargeCrit="<<fChargeCrit<<" b.GetCharge()"<<b.GetCharge() <<std::endl;
194  return kFALSE;
195  }
196 
197  if ( fPidSelect==99 ) {
198  return kTRUE;
199  } // no PID requested? Fine!
200 
201  // if e, mu, pi, k or p (but no + or -) is requested we reject neutrals
202  if ( fPidSelect!=99 && fabs ( b->GetCharge() ) <0.001 ) {
203  return kFALSE;
204  }
205 
206  SetTypeAndMass ( b );
207 
208  double Lcheck = b->GetPidInfo ( fPidSelect );
209  //std::cout<<"PndAnaPidSelector::Accept: Lcheck="<<Lcheck<<" fPidSelect="<<fPidSelect<<std::endl;
210 
211  if ( fCriterion == veryLoose ) {
212  if ( Lcheck<fSelectPar->GetVeryLooseCrit ( fPidSelect ) ) {
213  return kFALSE;
214  }
215  } else if ( fCriterion == loose ) {
216  if ( Lcheck<fSelectPar->GetLooseCrit ( fPidSelect ) ) {
217  return kFALSE;
218  }
219  } else if ( fCriterion == tight ) {
220  if ( Lcheck<fSelectPar->GetTightCrit ( fPidSelect ) ) {
221  return kFALSE;
222  }
223  } else if ( fCriterion == veryTight ) {
224  if ( Lcheck<fSelectPar->GetVeryTightCrit ( fPidSelect ) ) {
225  return kFALSE;
226  }
227  } else if ( fCriterion == variable ) {
228  if ( Lcheck<fSelectPar->GetVariableCrit ( fPidSelect ) ) {
229  return kFALSE;
230  }
231  } else if ( fCriterion == all ) {
232  return kTRUE;
233  } else if ( fCriterion == best ) {
234  double Le = b->GetPidInfo ( 0 );
235  double Lmu = b->GetPidInfo ( 1 );
236  double Lpi = b->GetPidInfo ( 2 );
237  double Lk = b->GetPidInfo ( 3 );
238  double Lp = b->GetPidInfo ( 4 );
239 
240  if ( Lcheck<Le || Lcheck<Lmu || Lcheck<Lpi || Lcheck<Lk || Lcheck<Lp ) {
241  return kFALSE;
242  }
243  }
244 
245  return kTRUE;
246 }
247 
249 {
250  Warning ( "PndAnaPidSelector::Accept(VAbsMicroCandidate&)","No implementation for this. Please use PndAnaPidSelector::Accept(RhoCandidate&)" );
251  return kFALSE;
252 }
253 
254 
255 
Double_t fChargeCrit
Pointer to the current parameter object.
Bool_t SetSelection(TString &crit)
PndAnaSelectorPar * fSelectPar
Double_t GetCharge() const
Definition: RhoCandidate.h:183
TTree * b
PndAnaPidSelector(const char *name="PndAnaPidSelector", const char *type="", const char *paramid="Default")
criterion fCriterion
Particle type to accept.
TParticlePDG * fTypeMinus
Particle type to accept.
TParticlePDG * CPConjugate(TParticlePDG *aPart)
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
void SetTypeAndMass(RhoCandidate *b)
TString name
virtual Bool_t Accept(RhoCandidate *b)
virtual void SetCriterion(const char *crit)
ClassImp(PndAnaPidSelector) TBuffer &operator>>(TBuffer &buf
return buf
PndAnaPidSelector *& obj
double GetPidInfo(int hypo)