FairRoot/PandaRoot
PndPidTestTask.cxx
Go to the documentation of this file.
1 // ************************************************************************
2 //
3 // psi(2S) -> J/psi (-> mu+ mu-) pi+ pi- Analysis Example Task
4 //
5 // for the Rho Tutorial, see
6 // http://panda-wiki.gsi.de/cgi-bin/viewauth/Computing/PandaRootRhoTutorial
7 //
8 // K.Goetzen 7/2013
9 // ************************************************************************
10 
11 
12 // The header file
13 #include "PndPidTestTask.h"
14 
15 // C++ headers
16 #include <string>
17 #include <iostream>
18 #include <iomanip>
19 #include <numeric>
20 
21 // FAIR headers
22 #include "FairRootManager.h"
23 #include "FairRunAna.h"
24 #include "FairRuntimeDb.h"
25 #include "FairRun.h"
26 #include "FairRuntimeDb.h"
27 
28 // ROOT headers
29 #include "TClonesArray.h"
30 #include "TVector3.h"
31 #include "TH1F.h"
32 #include "TH2F.h"
33 
34 // RHO headers
35 #include "RhoCandidate.h"
36 #include "RhoCandList.h"
37 #include "RhoHistogram/RhoTuple.h"
38 #include "RhoFactory.h"
39 
40 // Analysis headers
41 #include "PndAnalysis.h"
42 
43 
44 using std::cout;
45 using std::endl;
46 
47 
48 // ----- Default constructor -------------------------------------------
50  FairTask("Panda Pid Test Task") {
51 
52  fPdgIndex[11] = 0;
53  fPdgIndex[13] = 1;
54  fPdgIndex[211] = 2;
55  fPdgIndex[321] = 3;
56  fPdgIndex[2212] = 4;
57  fPdgIndex[-11] = 5;
58  fPdgIndex[-13] = 6;
59  fPdgIndex[-211] = 7;
60  fPdgIndex[-321] = 8;
61  fPdgIndex[-2212] = 9;
62 
63  fParticleNames.push_back("Electron");
64  fParticleNames.push_back("Muon");
65  fParticleNames.push_back("Pion");
66  fParticleNames.push_back("Kaon");
67  fParticleNames.push_back("Proton");
68 
69 
70  std::cout << "fPdgIndex.size()1 = " << fPdgIndex.size() << std::endl;
71 
72  for (int i = 0; i < fPdgIndex.size(); i++){
73  std::vector<int> vec(fPdgIndex.size(), 0);
74  fConfusionMatrix.push_back(vec);
75  }
76 
77  // *** RhoCandLists for the analysis
78  for (int i = 0; i < fPdgIndex.size(); i++){
79  fCandLists.push_back(new RhoCandList());
80  }
81 }
82 // -------------------------------------------------------------------------
83 
84 
85 // ----- Destructor ----------------------------------------------------
87 // -------------------------------------------------------------------------
88 
89 
90 
91 
92 // ----- Public method Init --------------------------------------------
94 {
95  // initialize analysis object
96  fAnalysis = new PndAnalysis();
97 
98  // reset the event counter
99  fEvtCount = 0;
100 
101  return kSUCCESS;
102 }
103 
104 // -------------------------------------------------------------------------
105 
107 {
108  // Get run and runtime database
109  FairRun* run = FairRun::Instance();
110  if ( ! run ) Fatal("SetParContainers", "No analysis run");
111 }
112 
113 // -------------------------------------------------------------------------
114 
115 
116 // ----- Public method Exec --------------------------------------------
117 void PndPidTestTask::Exec(Option_t*)
118 {
119  // *** some variables
120  int j=0;
121 
122  // necessary to read the next event
124 
125  if (!(++fEvtCount%100)) cout << "evt "<<fEvtCount<<endl;
126 
127 
128 
129 
140 
141  int candListIndex = 0;
142  for (auto candidates : fCandLists){
143  if (fVerbose > 1) std::cout << "CandList " << candListIndex++ << " Entries: " << candidates->GetLength() << std::endl;
144  for (int candInd = 0; candInd < candidates->GetLength(); candInd++){
145  RhoCandidate* cand = (*candidates)[candInd];
146  if (fVerbose > 1) cand->PrintOn(std::cout);
147  if (fVerbose > 1) std::cout << std::endl;
148  RhoCandidate* mccand = cand->GetMcTruth();
149  if (fVerbose > 1) std::cout << candInd << " Cand: " << cand->PdgCode() << " MCCand " << mccand->PdgCode() << std::endl;
150  if (fVerbose > 1) std::cout << *(FairMultiLinkedData_Interface*)mccand << std::endl;
151  if (fPdgIndex.count(cand->PdgCode()) > 0 && fPdgIndex.count(mccand->PdgCode()) > 0){
152  fConfusionMatrix[fPdgIndex[mccand->PdgCode()]][fPdgIndex[cand->PdgCode()]]++;
153  } else {
154  std::cout << "-W- PndPidTestTask::Exec Wrong PDG Codes: Cand: " << cand->PdgCode() << " MCCand: " << mccand->PdgCode() << std::endl;
155  }
156  }
157  }
158 
159 }
160 
162  for (int i = 0; i < fPdgIndex.size(); i++){
163  std::cout << i << " : " << std::setw(15) << fParticleNames[i%fParticleNames.size()] + ((i < fParticleNames.size()) ? "Plus" : "Minus") << " : ";
164  for (int j = 0; j < fPdgIndex.size(); j++){
165  if (relative == false)
166  std::cout << std::setw(5) << fConfusionMatrix[i][j] << " ";
167  else {
168  std::cout << std::setw(5);
169  int entryCount = std::accumulate(fConfusionMatrix[i].begin(), fConfusionMatrix[i].end(), 0);
170  if (entryCount > 0)
171  std::cout << std::fixed << std::setprecision(2) << fConfusionMatrix[i][j] / (double)entryCount << " ";
172  else
173  std::cout << std::fixed << std::setprecision(2) << 0.0 << " ";
174  }
175  }
176  std::cout << std::endl;
177  }
178 }
179 
180 
182 {
183  PrintConfusionMatrix(false);
184  PrintConfusionMatrix(true);
185 
186 }
187 
int fVerbose
Definition: poormantracks.C:24
virtual InitStatus Init()
Int_t run
Definition: autocutx.C:47
void PrintConfusionMatrix(bool relative=false)
Int_t i
Definition: run_full.C:25
PndAnalysis * fAnalysis
Bool_t FillList(RhoCandList &l, TString listkey="All", TString pidTcaNames="", int trackHypothesis=-1)
std::vector< RhoCandList * > fCandLists
virtual void SetParContainers()
void GetEventInTask()
std::map< int, int > fPdgIndex
void PrintOn(std::ostream &o=std::cout) const
std::vector< std::string > fParticleNames
RhoCandidate * GetMcTruth() const
Definition: RhoCandidate.h:437
virtual void Finish()
ClassImp(PndAnaContFact)
TString fClassifier
virtual void Exec(Option_t *opt)
dble_vec_t vec[12]
Definition: ranlxd.cxx:380
std::vector< std::vector< int > > fConfusionMatrix