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