PandaRoot
PndEventBuilderAnaTask.h
Go to the documentation of this file.
1 #ifndef PndEventBuilderAnaTask_H_
2 #define PndEventBuilderAnaTask_H_
3 
4 #include "TClonesArray.h"
5 #include "TH2D.h"
6 //#include "PndSdsHit.h"
7 
8 #include "FairLink.h"
9 #include "FairLogger.h"
10 #include "FairRootManager.h"
11 
12 #include "PndPersistencyTask.h"
13 
14 #include <vector>
15 #include <set>
16 
17 struct MCPoint {
18  MCPoint() : isFound(false), isPrimary(false){};
19  FairLink link;
20  bool isFound;
21  bool isPrimary;
22  friend std::ostream &operator<<(std::ostream &os, const MCPoint data)
23  {
24  os << data.link << " : isPrimary " << data.isPrimary << " isFound " << data.isFound << std::endl;
25  return os;
26  }
27 };
28 
29 struct MCEvent {
30  std::vector<FairLink> fMCTracks;
31  std::map<int, std::vector<MCPoint>> fMCPoints;
32  // std::map<int, std::vector<bool> > fPointFound;
33 
34  // void ResetFoundPoints(){
35  // for (auto & mcpoints : fMCPoints){
36  // std::cout << "-I- MCEvent::ResetFoundPoints "<< mcpoints.first << " / " << mcpoints.second.size() << std::endl;
37  // fPointFound[mcpoints.first].clear();
38  // fPointFound[mcpoints.first].resize(mcpoints.second.size(), false);
39  //
40  // }
41  // }
42 
43  friend std::ostream &operator<<(std::ostream &os, const MCEvent data)
44  {
45  os << "MCTracks: ";
46  for (auto track : data.fMCTracks) {
47  os << track << " ";
48  }
49  os << std::endl;
50  for (auto branch : data.fMCPoints) {
51  os << FairRootManager::Instance()->GetBranchName(branch.first) << std::endl;
52  for (auto link : branch.second) {
53  os << link << " ";
54  }
55  os << std::endl;
56  // int branchId = branch.first;
57  // std::map<int, std::vector<bool> > foundMap = data.fPointFound;
58  // std::vector<bool> foundArray = foundMap[branchId];
59  // if (foundArray.size() == branch.second.size()){
60  // for (auto found : foundArray){
61  // std::cout << found << " ";
62  // }
63  // os << std::endl;
64  // }
65  }
66  // std::cout << "PointsFoundMap: " << std::endl;
67  // for (auto pointFound : data.fPointFound){
68  // os << pointFound.first << "/" << pointFound.second.size() << std::endl;
69  // }
70  // os << std::endl;
71  return os;
72  }
73 };
74 
75 struct BranchInfo {
76  std::map<int, double> fPercentageMCPoints;
77  std::map<int, int> fNumberOfFoundMCPoints;
78  std::map<int, int> fTotalNumberOfPoints;
79  std::map<int, double> fPercentagePrimaryMCPoints;
80  std::map<int, int> fNumberOfFoundPrimaryMCPoints;
81  std::map<int, int> fTotalNumberOfPrimaryPoints;
83  friend std::ostream &operator<<(std::ostream &os, const BranchInfo data)
84  {
85  os << "Found Points: " << std::endl;
86  for (auto value : data.fNumberOfFoundMCPoints) {
87  std::map<int, double> percentageMap = data.fPercentageMCPoints;
88  std::map<int, int> totalNumbersMap = data.fTotalNumberOfPoints;
89 
90  os << value.first << " : " << value.second << "/" << totalNumbersMap[value.first] << " = " << percentageMap[value.first] * 100 << " %" << std::endl;
91  }
92  os << "Found Primary Points: " << std::endl;
93  for (auto value : data.fNumberOfFoundPrimaryMCPoints) {
94  std::map<int, double> percentageMap = data.fPercentagePrimaryMCPoints;
95  std::map<int, int> totalNumbersMap = data.fTotalNumberOfPrimaryPoints;
96 
97  os << value.first << " : " << value.second << "/" << totalNumbersMap[value.first] << " = " << percentageMap[value.first] * 100 << " %" << std::endl;
98  }
99  os << "Additional hits: " << data.fNumberOfPointsOutsideMC << std::endl;
100  return os;
101  }
102 };
103 
104 struct EventInfo {
105  std::map<int, MCEvent> fMCEvents;
106  std::map<int, BranchInfo> fBranchInfo;
107  void CalculateBranchInfo();
108  friend std::ostream &operator<<(std::ostream &os, const EventInfo data)
109  {
110  for (auto branch : data.fBranchInfo) {
111  LOG(info) << " EventInfo for branch: " << FairRootManager::Instance()->GetBranchName(branch.first);
112  os << branch.second;
113  os << std::endl;
114  }
115  return os;
116  }
117 };
118 
119 struct BranchHistos {
120  BranchHistos(TString branchName, int nEvents, int nMCEvents)
121  {
122  fAbsoluteHits = new TH2D("AbsoluteHits" + branchName, "AbsoluteHits" + branchName, nEvents + 1, -0.5, nEvents + 0.5, nMCEvents + 1, -0.5, nMCEvents + 0.5);
123  fRelativeHits = new TH2D("RelativeHits" + branchName, "RelativeHits" + branchName, nEvents + 1, -0.5, nEvents + 0.5, nMCEvents + 1, -0.5, nMCEvents + 0.5);
124  fAbsolutePrimaryHits = new TH2D("AbsolutePrimaryHits" + branchName, "AbsolutePrimaryHits" + branchName, nEvents + 1, -0.5, nEvents + 0.5, nMCEvents + 1, -0.5, nMCEvents + 0.5);
125  fRelativePrimaryHits = new TH2D("RelativePrimaryHits" + branchName, "RelativePrimaryHits" + branchName, nEvents + 1, -0.5, nEvents + 0.5, nMCEvents + 1, -0.5, nMCEvents + 0.5);
126  fOutsideMC = new TH1D("OutsideMC" + branchName, "OutsideMC" + branchName, nEvents + 1, -0.5, nEvents + 0.5);
127  fOutsideMCHisto = new TH1D("OutsideMCHisto" + branchName, "OutsideMCHisto" + branchName, 1000, 0, 10000);
128  fAbsoluteHitsHisto = new TH1D("AbsoluteHitsHisto" + branchName, "AbsoluteHitsHisto" + branchName, 1000, 0, 1000);
129  fAbsolutePrimaryHitsHisto = new TH1D("AbsolutePrimaryHitsHisto" + branchName, "AbsolutePrimaryHitsHisto" + branchName, 1000, 0, 1000);
130  fRelativeHitsHisto = new TH1D("RelatvieHitsHisto" + branchName, "RelatvieHitsHisto" + branchName, 100, 0, 2.0);
131  fRelativePrimaryHitsHisto = new TH1D("RelatviePrimaryHitsHisto" + branchName, "RelatviePrimaryHitsHisto" + branchName, 100, 0, 2.0);
132  fEventOverlap = new TH1D("EventOverlap" + branchName, "EventOverlap" + branchName, 100, 0, 100);
133  };
134 
135  void WriteHistos()
136  {
137  fAbsoluteHits->Write();
138  fAbsoluteHitsHisto->Write();
139  fRelativeHits->Write();
140  fRelativeHitsHisto->Write();
141  fAbsolutePrimaryHits->Write();
142  fAbsolutePrimaryHitsHisto->Write();
143  fRelativePrimaryHits->Write();
144  fRelativePrimaryHitsHisto->Write();
145  fOutsideMC->Write();
146  fOutsideMCHisto->Write();
147  fEventOverlap->Write();
148  }
149 
158  TH1D *fOutsideMC;
161 };
162 
164  public:
166  virtual ~PndEventBuilderAnaTask();
167 
169  virtual void SetParContainers();
170  virtual InitStatus Init();
171  virtual InitStatus ReInit();
172 
174  virtual void Exec(Option_t *opt);
175  virtual void FinishEvent();
176  virtual void FinishTask();
177 
178  void SetBranchName(TString name)
179  {
180  fMainBranchName = name;
181  fAddHitArray[name] = nullptr;
182  };
183 
184  void AddAdditionalBranches(TString branchName) { fAddHitArray[branchName] = nullptr; }
185 
186  protected:
187  std::set<int> GetMCEventIDs(TClonesArray *array);
188  void AssignHitsToPoints(TString branchName, TClonesArray *hitArray);
189  MCEvent GetMCInfo(int entryNr);
190 
191  void FillHistos();
192 
193  TString GetPointBranch(TString hitbranch)
194  {
195  if (hitbranch.Contains("STT"))
196  return "STTPoint";
197  if (hitbranch.Contains("MVD"))
198  return "MVDPoint";
199  if (hitbranch.Contains("GEM"))
200  return "GEMPoint";
201  if (hitbranch.Contains("SciT"))
202  return "SciTPoint";
203  if (hitbranch.Contains("EMC"))
204  return "EmcHit";
205  if (hitbranch.Contains("FTS"))
206  return "FTSPoint";
207  if (hitbranch.Contains("Ftof"))
208  return "FtofPoint";
209  return "";
210  }
211 
212  private:
213  TString fMainBranchName;
214  // TClonesArray* fMainHitArray;
215 
216  std::map<TString, TClonesArray *> fAddHitArray;
217  std::map<TString, BranchHistos *> fBranchHistos;
218 
219  TClonesArray *fMCArray;
220  std::map<int, TClonesArray *> fMCPointArrays;
221  std::map<int, MCEvent> fMCEvents;
222  std::vector<EventInfo> fEventInfo;
223  int fEntryNr;
224 
225  Bool_t fInitDone;
226 
227  void Register();
228  void Reset();
229  void ProduceHits();
230 
231  ClassDef(PndEventBuilderAnaTask, 1);
232 };
233 
234 #endif /*PndEventBuilderAnaTask_H_*/
BranchHistos(TString branchName, int nEvents, int nMCEvents)
TString GetPointBranch(TString hitbranch)
std::map< int, int > fTotalNumberOfPrimaryPoints
number of MCPoints per MCEvent
friend std::ostream & operator<<(std::ostream &os, const BranchInfo data)
std::map< int, std::vector< MCPoint > > fMCPoints
MCPoints for BranchID.
std::map< int, BranchInfo > fBranchInfo
map<Branch, BranchInfo>
friend std::ostream & operator<<(std::ostream &os, const MCPoint data)
std::map< int, MCEvent > fMCEvents
map<MCEventNumber, MCEvents>
void SetBranchName(TString name)
void AddAdditionalBranches(TString branchName)
friend std::ostream & operator<<(std::ostream &os, const MCEvent data)
std::vector< FairLink > fMCTracks
std::map< int, double > fPercentagePrimaryMCPoints
percentage of found MCPoints per MCEvent
std::map< int, int > fNumberOfFoundPrimaryMCPoints
number of found MCPoint per MCEvent
std::map< int, int > fTotalNumberOfPoints
number of MCPoints per MCEvent
std::map< int, double > fPercentageMCPoints
percentage of found MCPoints per MCEvent
friend std::ostream & operator<<(std::ostream &os, const EventInfo data)
std::map< int, int > fNumberOfFoundMCPoints
number of found MCPoint per MCEvent