FairRoot/PandaRoot
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PndAnaPidCombiner Class Reference

#include <PndAnaPidCombiner.h>

Inheritance diagram for PndAnaPidCombiner:

Public Member Functions

 PndAnaPidCombiner (const char *name="PndAnaPidCombiner", TString tcanames="")
 
 ~PndAnaPidCombiner ()
 
void SetTcaNames (TString &names, TString postfix="")
 
void SetDefaults ()
 
void ClearNames ()
 
void Init ()
 
void ApplyFlat (RhoCandidate *tc)
 
Bool_t Apply (RhoCandidate *tc)
 
Bool_t Apply (RhoCandList &tcl)
 

Private Member Functions

TClonesArray * ReadTCA (const TString &tcaname)
 

Private Attributes

FairRootManager * fRootManager
 
std::map< TString, TClonesArray * > fPidArrays
 
std::vector< TStringfCurrentPidArrays
 pid data map, full More...
 
PndPidProbabilityfPidResult
 pid data current request More...
 
Bool_t fInitialized
 

Detailed Description

Definition at line 23 of file PndAnaPidCombiner.h.

Constructor & Destructor Documentation

PndAnaPidCombiner::PndAnaPidCombiner ( const char *  name = "PndAnaPidCombiner",
TString  tcanames = "" 
)

Definition at line 30 of file PndAnaPidCombiner.cxx.

30  :
31  TNamed ( name,"Panda PID Combiner" ) ,
32  fRootManager ( 0 ),
33  fPidArrays(),//FIXME: What should the initializing constructor contain here?
34  fPidResult ( 0 ),
35  fInitialized ( kFALSE )
36 {
37  // std::cout<< "PndAnaPidCombiner created with tcanames: "<<tcanames.Data()<<std::endl;
38  if ( tcanames=="" ) {
39  SetDefaults();
40  } else {
41  SetTcaNames ( tcanames );
42  }
43 
44  fRootManager=FairRootManager::Instance();
45 
47 }
void SetTcaNames(TString &names, TString postfix="")
std::map< TString, TClonesArray * > fPidArrays
TString name
FairRootManager * fRootManager
PndPidProbability * fPidResult
pid data current request
PndAnaPidCombiner::~PndAnaPidCombiner ( )
inline

Definition at line 30 of file PndAnaPidCombiner.h.

30 {/*empty*/};

Member Function Documentation

Bool_t PndAnaPidCombiner::Apply ( RhoCandidate tc)

Definition at line 60 of file PndAnaPidCombiner.cxx.

References ApplyFlat(), Bool_t, fCurrentPidArrays, fPidArrays, fPidResult, PndPidProbability::GetElectronPidProb(), PndPidProbability::GetIndex(), PndPidProbability::GetKaonPidProb(), PndPidProbability::GetMuonPidProb(), PndPidProbability::GetPionPidProb(), PndPidProbability::GetProtonPidProb(), PndPidProbability::GetSumProb(), RhoCandidate::GetTrackNumber(), PndPidProbability::Reset(), PndPidProbability::SetIndex(), and RhoCandidate::SetPidInfo().

Referenced by Apply(), and PndAnalysis::FillList().

61 {
62  // Apply the multiplied pdf's to the RhoCandidate
63  // If on of the pdf's is not available, it is skipped
64  Bool_t check=kTRUE;
65 
66  //TODO: Merge PID info now.
67  fPidResult->Reset();
68  // combine algorithms
69  TClonesArray* aTca=0;
70  PndPidProbability* aProb=0;
71  Int_t trackIndex = tc->GetTrackNumber();
72  //std::cout<<"PidCombiner: Try RhoCandidate uid:"<<tc->Uid()<<" trknr:"<<trackIndex<<std::endl;
73  //std::cout<<tc<<std::endl;
74  fPidResult->SetIndex(trackIndex);
75  if ( fCurrentPidArrays.size()==0 || trackIndex<0 ) {
76  ApplyFlat ( tc );
77  return kFALSE;
78  }
79 
80  for ( std::vector<TString>::iterator iter=fCurrentPidArrays.begin();
81  iter!=fCurrentPidArrays.end(); iter++ ) {
82  aTca=fPidArrays[*iter];
83  //Info ( "Apply","try tca %s at %p",*iter.Data(),aTca );
84 
85  if ( 0==aTca ) {
86  Error ( "Apply", "PID Probability array not found, skip setting pid for candidate %i.",trackIndex );
87  check=kFALSE;
88  continue;
89  }
90 
91  if ( 0==aTca->GetEntriesFast() ) {
92  Error ( "Apply", "PID Probability array '%s' at %p of size zero, skip setting pid for candidate %i.", aTca->GetName(), aTca, trackIndex );
93  continue;
94  check=kFALSE;
95  }
96 
97  if ( trackIndex>=aTca->GetEntriesFast() ) {
98  Error ( "Apply", "Index out of '%s' array (%p) bounds, skip setting pid for candidate %i.",aTca->GetName(),aTca,trackIndex );
99  continue;
100  check=kFALSE;
101  }
102 
103  aProb= ( PndPidProbability* ) aTca->At ( trackIndex );
104 
105  if ( aProb == 0 ) {
106  Error ( "Apply", "PID Probability object in array '%s' at %p not found, skip setting pid for candidate %i.",aTca->GetName(),aTca,trackIndex );
107  continue;
108  check=kFALSE;
109  }
110 
111  if ( trackIndex!=aProb->GetIndex() ) {
112  Error ( "Apply", "PID Probability object index (%i) is not the track index (%i). Is that bad?",aProb->GetIndex(),trackIndex );
113  continue;
114  check=kFALSE;
115  }
116 
117  // catch Zeros to avoid NAN from Div/Zero
118  if ( aProb->GetSumProb() == 0 ) {
119  continue;
120  }
121 
122  // avoid numerics with low numbers
123  //aProb->NormalizeTo(1.);
124  //now multiply
125  *fPidResult *= *aProb;
126  }
127  //std::cout<<"PndAnaPidCombiner: "; fPidResult->Print();
128  //TODO renormalizing is done in the Pid object upon request ???
129  //fPidResult->NormalizeTo(1.);
130  //std::cout<<"PndAnaPisCombiner: scaled = "; fPidResult->Print();
131  // numbering see PndPidListMaker
132  // No flux implemented! To come for each Detector!
134  tc->SetPidInfo ( 1,fPidResult->GetMuonPidProb() );
135  tc->SetPidInfo ( 2,fPidResult->GetPionPidProb() );
136  tc->SetPidInfo ( 3,fPidResult->GetKaonPidProb() );
138  //std::cout<<"PndAnaPidCombiner: "<<tc<<std::endl;
139 
140  return check;
141 }
Double_t GetProtonPidProb(PndPidProbability *flux=NULL) const
Int_t GetTrackNumber() const
Definition: RhoCandidate.h:417
Double_t GetKaonPidProb(PndPidProbability *flux=NULL) const
void ApplyFlat(RhoCandidate *tc)
Int_t GetIndex() const
void SetPidInfo(double *pidinfo=0)
Double_t GetSumProb(PndPidProbability *flux=NULL) const
Double_t GetMuonPidProb(PndPidProbability *flux=NULL) const
std::map< TString, TClonesArray * > fPidArrays
std::vector< TString > fCurrentPidArrays
pid data map, full
Double_t GetElectronPidProb(PndPidProbability *flux=NULL) const
Double_t GetPionPidProb(PndPidProbability *flux=NULL) const
PndPidProbability * fPidResult
pid data current request
void SetIndex(Int_t idx)
Bool_t PndAnaPidCombiner::Apply ( RhoCandList tcl)

Definition at line 49 of file PndAnaPidCombiner.cxx.

References Apply(), Bool_t, and RhoCandList::GetLength().

50 {
51  Bool_t check = kTRUE;
52  Bool_t chack = kTRUE;
53  for ( int j=0; j<tcl.GetLength(); j++ ) {
54  chack = Apply( tcl[j] );
55  check = check && chack;
56  }
57  return check;
58 }
Bool_t Apply(RhoCandidate *tc)
Int_t GetLength() const
Definition: RhoCandList.h:46
void PndAnaPidCombiner::ApplyFlat ( RhoCandidate tc)

Definition at line 143 of file PndAnaPidCombiner.cxx.

References RhoCandidate::SetPidInfo().

Referenced by Apply().

144 {
145  tc->SetPidInfo ( 0,0.2 );
146  tc->SetPidInfo ( 1,0.2 );
147  tc->SetPidInfo ( 2,0.2 );
148  tc->SetPidInfo ( 3,0.2 );
149  tc->SetPidInfo ( 4,0.2 );
150  return;
151 }
void SetPidInfo(double *pidinfo=0)
void PndAnaPidCombiner::ClearNames ( )
inline

Definition at line 34 of file PndAnaPidCombiner.h.

References fPidArrays.

34 {fPidArrays.clear(); };
std::map< TString, TClonesArray * > fPidArrays
void PndAnaPidCombiner::Init ( )
TClonesArray * PndAnaPidCombiner::ReadTCA ( const TString tcaname)
private

Definition at line 220 of file PndAnaPidCombiner.cxx.

References fRootManager.

Referenced by SetTcaNames().

221 {
222  // Fetch a TCLonesArray from the framework by its root name
223  if (tcaname == "") {
224  Warning ( "PndAnaPidCombiner::ReadTCA()","Empty TCA name." );
225  return NULL;
226  }
227  //std::cout<<" -I- PndAnaPidCombiner::ReadTCA(): Try fetching branch "<<tcaname.Data()<<" rootmanager="<<fRootManager<<std::endl;
228  TClonesArray* tca = ( TClonesArray* ) fRootManager->GetObject ( tcaname.Data() );
229 
230  if ( ! tca ) { // this information is already provoded by the RootManager
231  //Warning ( "PndAnaPidCombiner::ReadTCA()","No \"%s\" array found.",tcaname.Data() );
232  return NULL;
233  }
234 
235  return tca;
236 }
FairRootManager * fRootManager
void PndAnaPidCombiner::SetDefaults ( )

Definition at line 153 of file PndAnaPidCombiner.cxx.

References SetTcaNames(), and TString.

Referenced by PndAnalysis::FillList().

154 {
155  // Set list of names and weights to the default PANDA
156  //TString names = "PidAlgoMvd;PidAlgoStt;PidAlgoEmcBayes;PidAlgoDrc;PidAlgoDisc;PidAlgoMdtHardCuts;";
157  //TString names = "PidAlgoIdealCharged";
158  //TString names = "PidMvaChargedProbability";
159  //SetTcaNames ( names );
160 
161  TString dummy("");
162  SetTcaNames(dummy,dummy);
163  return;
164 }
void SetTcaNames(TString &names, TString postfix="")
void PndAnaPidCombiner::SetTcaNames ( TString names,
TString  postfix = "" 
)

Definition at line 166 of file PndAnaPidCombiner.cxx.

References fCurrentPidArrays, fPidArrays, fRootManager, full(), ReadTCA(), and TString.

Referenced by PndAnalysis::FillList(), and SetDefaults().

167 {
168  fCurrentPidArrays.clear();
169  // Tokenizer, cool thingy!
170  TStringToken list ( names,";" );
171  //use TString class part (inherited, Tokenizer stores data there)
172  while ( list.NextToken() )
173  {
174  TString branch=(TString)list;
175  if (branch == "") continue;
176  TString full=branch+postfix;
177  if (!fPidArrays[full])
178  {
179  //std::cout<<" -I- PndAnaPidCombiner::SetTcaNames(): try finding \""<<full.Data()<<"\""<<std::endl;
180  TClonesArray * tmpar = ReadTCA(full.Data());
181  if(tmpar) {
182  fPidArrays[full]=tmpar;
183  fRootManager->ReadBranchEvent(full.Data());
184  // we have the branch now, lets use it
185  fCurrentPidArrays.push_back (full);
186  //std::cout<<" -I- PndAnaPidCombiner::SetTcaNames(): \""<<branch.Data()<<"\" + \""<<postfix.Data()<<"\" = \""<<full.Data()<<"\""<<std::endl;
187  } else {
188  // now there is no branch with the full name, let's try without the PID postfix
189  // TODO here we would need to select one other branch, if available, before going to fallback
190  // Users may use Multikalman for protons and pions only, but want to reconstruct muons
191  if (!fPidArrays[branch])
192  {
193  TClonesArray * tmpar2 = ReadTCA(branch.Data());
194  if(tmpar2)
195  {
196  fPidArrays[branch]=tmpar;
197  fRootManager->ReadBranchEvent(branch.Data());
198  // we have the backup branch now, lets use it
199  fCurrentPidArrays.push_back (branch);
200  std::cout<<" WARNING TO ANALYST: PndAnaPidCombiner::Init() could not find "<< full.Data()<<" we use a backup branch: "<<branch.Data()<<std::endl;
201  } else {
202  // now we even don't have a backup
203  std::cout<<" WARNING TO ANALYST: PndAnaPidCombiner::Init() could not find "<< full.Data()<<" nor a backup branch "<<branch.Data()<<std::endl;
204  }
205  } else {
206  // we have the backup branch already loaded, lets use it
207  fCurrentPidArrays.push_back (branch);
208  }
209  }
210  } else {
211  //std::cout<<" -I- PndAnaPidCombiner::SetTcaNames(): we have alreasy a cached TClonesArray named \""<<full.Data()<<"\""<<std::endl;
212  // we have the branch already loaded, lets use it
213  fCurrentPidArrays.push_back(full);
214  }
215  }
216 
217  //std::cout<<"PidCombiner initialized."<<std::endl;
218 }
int full(TString simdatei="sim_emc.root", TString fulldatei="full_emc.root", TString param="simparam.root")
Definition: full.C:1
std::map< TString, TClonesArray * > fPidArrays
FairRootManager * fRootManager
std::vector< TString > fCurrentPidArrays
pid data map, full
TClonesArray * ReadTCA(const TString &tcaname)

Member Data Documentation

std::vector<TString> PndAnaPidCombiner::fCurrentPidArrays
private

pid data map, full

Definition at line 45 of file PndAnaPidCombiner.h.

Referenced by Apply(), and SetTcaNames().

Bool_t PndAnaPidCombiner::fInitialized
private

Definition at line 47 of file PndAnaPidCombiner.h.

std::map<TString,TClonesArray*> PndAnaPidCombiner::fPidArrays
private

Definition at line 44 of file PndAnaPidCombiner.h.

Referenced by Apply(), ClearNames(), and SetTcaNames().

PndPidProbability* PndAnaPidCombiner::fPidResult
private

pid data current request

Definition at line 46 of file PndAnaPidCombiner.h.

Referenced by Apply().

FairRootManager* PndAnaPidCombiner::fRootManager
private

Definition at line 43 of file PndAnaPidCombiner.h.

Referenced by ReadTCA(), and SetTcaNames().


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