CbmRoot
CbmTrdMCQa.cxx
Go to the documentation of this file.
1 #include "CbmTrdMCQa.h"
2 
3 #include "CbmHistManager.h"
4 #include "CbmSimulationReport.h"
5 #include "CbmTrdAddress.h"
6 #include "CbmTrdPoint.h"
7 //#include "CbmTrdMCQaReport.h"
8 
9 #include "FairLogger.h"
10 #include "FairRootManager.h"
11 
12 #include "TClonesArray.h"
13 #include "TF1.h"
14 #include "TH1.h"
15 #include "TH1D.h"
16 #include "TH2.h"
17 #include "TProfile.h"
18 #include "TProfile2D.h"
19 
20 #include <map>
21 #include <string>
22 #include <vector>
23 
24 using std::map;
25 using std::string;
26 using std::vector;
27 
29  : FairTask()
30  , fHM(new CbmHistManager())
31  , fTrdPoints(NULL)
32  , fMCTracks(NULL)
33  , fNofStation(10) {}
34 
36  if (fHM) delete fHM;
37 }
38 
39 InitStatus CbmTrdMCQa::Init() {
40  LOG(info) << "Trd Setup consist of " << fNofStation << " stations.";
41 
44  return kSUCCESS;
45 }
46 
48  FairRootManager* ioman = FairRootManager::Instance();
49  if (NULL == ioman) LOG(fatal) << "No FairRootManager!";
50 
51  fTrdPoints = dynamic_cast<TClonesArray*>(ioman->GetObject("TrdPoint"));
52  if (NULL == fTrdPoints) LOG(error) << "No TrdPoint array!";
53 
54  fMCTracks = dynamic_cast<TClonesArray*>(ioman->GetObject("MCTrack"));
55  if (NULL == fMCTracks) LOG(error) << "No MCTrack array!";
56 }
57 
61  fHM->Create1<TH1F>("h_trd_EventNo_MCQa", "h_trd_EventNo_MCQa", 1, 0, 1.);
62 }
63 
65 
66  Int_t nofBins = 100;
67  Double_t minX = -0.5;
68  Double_t maxX = 99.5;
69  string name = "h_trd_NofObjects_";
70  fHM->Create1<TH1F>(name + "Points",
71  name + "Points;Objects per event;Entries",
72  nofBins,
73  minX,
74  maxX);
75 
76  nofBins = fNofStation;
77  minX = -0.5;
78  maxX = static_cast<Float_t>(fNofStation) - 0.5;
79  fHM->Create1<TH1F>(name + "Points_Station",
80  name + "Points_Station;Station number;Objects per event",
81  nofBins,
82  minX,
83  maxX);
84 }
85 
87  for (Int_t stationId = 0; stationId < fNofStation; stationId++) {
88  Int_t nofBins = 100;
89  Double_t minX = -0.5;
90  Double_t maxX = 99.5;
91  fHM->Create1<TH1F>(
92  Form("h_trd_MultPoints_Station%i", stationId),
93  Form("Mult, Station %i;Objects per event;Entries", stationId),
94  nofBins,
95  minX,
96  maxX);
97 
98  fHM->Create2<TH2F>(Form("h_trd_PointsMap_Station%i", stationId),
99  Form("TrdPoint, Station %i;x, cm;y, cm", stationId),
100  120,
101  -60.,
102  60.,
103  120,
104  -60.,
105  60.);
106  fHM->Create2<TH2F>(
107  Form("h_trd_PointsMapEvent_Station%i", stationId),
108  Form("TrdPoint/cm^{2}, Station %i;x, cm;y, cm", stationId),
109  120,
110  -60.,
111  60.,
112  120,
113  -60.,
114  60.);
115  fHM->Create2<TH2F>(
116  Form("h_trd_PointsMapRate_Station%i", stationId),
117  Form("TrdPoint/cm^{2}/s, Station %i;x, cm;y, cm", stationId),
118  120,
119  -60.,
120  60.,
121  120,
122  -60.,
123  60.);
124  fHM->Create1<TH1F>(Form("h_trd_XPos_Station%i", stationId),
125  "X position;x, cm; Entries",
126  1200,
127  -60.,
128  60.);
129  fHM->Create1<TH1F>(Form("h_trd_YPos_Station%i", stationId),
130  "Y position;y, cm; Entries",
131  1200,
132  -60.,
133  60.);
134  }
135  fHM->Create1<TH1F>(
136  "h_trd_XPos", "X position;x, cm; Entries", 1200, -60., 60.);
137  fHM->Create1<TH1F>(
138  "h_trd_YPos", "Y position;y, cm; Entries", 1200, -60., 60.);
139 }
140 
141 void CbmTrdMCQa::Exec(Option_t*) {
143  fHM->H1("h_trd_EventNo_MCQa")->Fill(0.5);
144 }
145 
146 void CbmTrdMCQa::ProcessPoints(const TClonesArray* points) {
147 
148  fHM->H1("h_trd_NofObjects_Points")->Fill(points->GetEntriesFast());
149 
150  Double_t pointX = 0.;
151  Double_t pointY = 0.;
152  // Double_t pointZ=0.;
153 
154  std::map<Int_t, vector<Int_t>> used_map;
155 
156  for (Int_t iPoint = 0; iPoint < points->GetEntriesFast(); iPoint++) {
157  const CbmTrdPoint* trdPoint =
158  static_cast<const CbmTrdPoint*>(points->At(iPoint));
159  Int_t stationId = CbmTrdAddress::GetLayerId(trdPoint->GetModuleAddress());
160  ;
161  fHM->H1("h_trd_NofObjects_Points_Station")->Fill(stationId);
162 
163  pointX = trdPoint->GetXIn();
164  pointY = trdPoint->GetYIn();
165  // pointZ = trdPoint -> GetZIn();
166 
167  fHM->H1(Form("h_trd_XPos_Station%i", stationId))->Fill(pointX);
168  fHM->H1(Form("h_trd_YPos_Station%i", stationId))->Fill(pointY);
169 
170  fHM->H2(Form("h_trd_PointsMap_Station%i", stationId))->Fill(pointX, pointY);
171  fHM->H2(Form("h_trd_PointsMapEvent_Station%i", stationId))
172  ->Fill(pointX, pointY);
173  fHM->H2(Form("h_trd_PointsMapRate_Station%i", stationId))
174  ->Fill(pointX, pointY);
175  fHM->H1("h_trd_XPos")->Fill(pointX);
176  fHM->H1("h_trd_YPos")->Fill(pointY);
177 
178  Int_t mcTrackID = trdPoint->GetTrackID();
179 
180  if (std::find(
181  used_map[stationId].begin(), used_map[stationId].end(), mcTrackID)
182  == used_map[stationId].end()) {
183  used_map[stationId].push_back(mcTrackID);
184  }
185  }
186  fHM->H1(Form("h_trd_MultPoints_Station%i", 0))->Fill(used_map[0].size());
187  fHM->H1(Form("h_trd_MultPoints_Station%i", 1))->Fill(used_map[1].size());
188  fHM->H1(Form("h_trd_MultPoints_Station%i", 2))->Fill(used_map[2].size());
189  fHM->H1(Form("h_trd_MultPoints_Station%i", 3))->Fill(used_map[3].size());
190 }
191 
193 
194  Int_t nofEvents = fHM->H1("h_trd_EventNo_MCQa")->GetEntries();
195  // Do here some scaling of the histograms to have MCPoint per cm^2
196 
197  Int_t xbins = (fHM->H2("h_trd_PointsMap_Station0"))->GetXaxis()->GetNbins();
198  Float_t xmax = fHM->H2("h_trd_PointsMap_Station0")->GetXaxis()->GetXmax();
199  Float_t xmin = fHM->H2("h_trd_PointsMap_Station0")->GetXaxis()->GetXmin();
200  Float_t scaleX = static_cast<Float_t>(xbins) / (xmax - xmin);
201 
202  Int_t ybins = fHM->H2("h_trd_PointsMap_Station0")->GetYaxis()->GetNbins();
203  Int_t ymax = fHM->H2("h_trd_PointsMap_Station0")->GetYaxis()->GetXmax();
204  Int_t ymin = fHM->H2("h_trd_PointsMap_Station0")->GetYaxis()->GetXmin();
205  Float_t scaleY = static_cast<Float_t>(ybins) / (ymax - ymin);
206 
207  Float_t scale = scaleX * scaleY;
208  scale = 1.;
209 
210  for (Int_t i = 0; i < fNofStation; ++i) {
211  fHM->Scale(Form("h_trd_PointsMapEvent_Station%i", i), scale / nofEvents);
212  fHM->Scale(Form("h_trd_PointsMapRate_Station%i", i),
213  10000000. * scale / nofEvents);
214  }
215 
216  gDirectory->mkdir("QA/TrdMCQa");
217  gDirectory->cd("QA/TrdMCQa");
218  fHM->WriteToFile();
219  gDirectory->cd("../..");
220  // CbmSimulationReport* report = new CbmTrdMCQaReport(fSetup, fDigitizer);
221  // report -> Create(fHM, fOutputDir);
222  // delete report;
223 
224  // Compare results with defined benchmark results and raise an ERROR if there are differences
225  // Either get default histogramms from a benchmark qa file or as parameters from the parameter container
226 }
227 
CbmTrdMCQa::ReadDataBranches
void ReadDataBranches()
Definition: CbmTrdMCQa.cxx:47
CbmHistManager::WriteToFile
void WriteToFile()
Write all histograms to current opened file.
Definition: core/base/CbmHistManager.cxx:103
CbmTrdAddress.h
Helper class to convert unique channel ID back and forth.
CbmTrdMCQa::fHM
CbmHistManager * fHM
Definition: CbmTrdMCQa.h:34
CbmTrdMCQa::Init
virtual InitStatus Init()
Definition: CbmTrdMCQa.cxx:39
CbmTrdMCQa.h
CbmHistManager::Create2
void Create2(const std::string &name, const std::string &title, Int_t nofBinsX, Double_t minBinX, Double_t maxBinX, Int_t nofBinsY, Double_t minBinY, Double_t maxBinY)
Helper function for creation of 2-dimensional histograms and profiles. Template argument is a real ob...
Definition: CbmHistManager.h:104
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmTrdMCQa::Finish
virtual void Finish()
Definition: CbmTrdMCQa.cxx:192
CbmHistManager::H2
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
Definition: CbmHistManager.h:190
ClassImp
ClassImp(CbmTrdMCQa)
CbmTrdAddress::GetLayerId
static UInt_t GetLayerId(UInt_t address)
Return layer ID from address.
Definition: CbmTrdAddress.h:69
CbmTrdMCQa::CreateHistograms
void CreateHistograms()
Definition: CbmTrdMCQa.cxx:58
CbmTrdMCQa::fMCTracks
TClonesArray * fMCTracks
Definition: CbmTrdMCQa.h:36
CbmHistManager.h
Histogram manager.
CbmTrdMCQa::ProcessPoints
void ProcessPoints(const TClonesArray *)
Definition: CbmTrdMCQa.cxx:146
CbmTrdMCQa::CbmTrdMCQa
CbmTrdMCQa()
Definition: CbmTrdMCQa.cxx:28
CbmHistManager
Histogram manager.
Definition: CbmHistManager.h:41
CbmTrdMCQa::fTrdPoints
TClonesArray * fTrdPoints
Definition: CbmTrdMCQa.h:35
CbmHistManager::Create1
void Create1(const std::string &name, const std::string &title, Int_t nofBins, Double_t minBin, Double_t maxBin)
Helper function for creation of 1-dimensional histograms and profiles. Template argument is a real ob...
Definition: CbmHistManager.h:81
CbmTrdMCQa
Definition: CbmTrdMCQa.h:11
CbmHistManager::H1
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
Definition: CbmHistManager.h:170
CbmTrdMCQa::~CbmTrdMCQa
virtual ~CbmTrdMCQa()
Definition: CbmTrdMCQa.cxx:35
CbmTrdPoint
Definition: CbmTrdPoint.h:23
points
TClonesArray * points
Definition: Analyze_matching.h:18
CbmTrdPoint::GetXIn
Double_t GetXIn() const
Definition: CbmTrdPoint.h:63
CbmTrdPoint::GetModuleAddress
Int_t GetModuleAddress() const
Definition: CbmTrdPoint.h:76
CbmTrdPoint.h
CbmSimulationReport.h
Base class for simulation reports.
CbmTrdMCQa::Exec
virtual void Exec(Option_t *)
Definition: CbmTrdMCQa.cxx:141
CbmTrdMCQa::CreatePointHistograms
void CreatePointHistograms()
Definition: CbmTrdMCQa.cxx:86
CbmTrdMCQa::CreateNofObjectsHistograms
void CreateNofObjectsHistograms()
Definition: CbmTrdMCQa.cxx:64
CbmTrdMCQa::fNofStation
Int_t fNofStation
Definition: CbmTrdMCQa.h:37
CbmTrdPoint::GetYIn
Double_t GetYIn() const
Definition: CbmTrdPoint.h:64
CbmHistManager::Scale
void Scale(const std::string &histName, Double_t scale)
Scale histogram.
Definition: core/base/CbmHistManager.cxx:217