CbmRoot
Loading...
Searching...
No Matches
CbmTrdMCQa.cxx
Go to the documentation of this file.
1/* Copyright (C) 2017-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
5#include "CbmTrdMCQa.h"
6
7#include "CbmHistManager.h"
9#include "CbmTrdAddress.h"
10#include "CbmTrdPoint.h"
11//#include "CbmTrdMCQaReport.h"
12
13#include "FairRootManager.h"
14#include <Logger.h>
15
16#include "TClonesArray.h"
17#include "TF1.h"
18#include "TH1.h"
19#include "TH1D.h"
20#include "TH2.h"
21#include "TProfile.h"
22#include "TProfile2D.h"
23
24#include <map>
25#include <string>
26#include <vector>
27
28using std::map;
29using std::string;
30using std::vector;
31
32CbmTrdMCQa::CbmTrdMCQa() : FairTask(), fHM(new CbmHistManager()), fTrdPoints(NULL), fMCTracks(NULL), fNofStation(10) {}
33
35{
36 if (fHM) delete fHM;
37}
38
39InitStatus CbmTrdMCQa::Init()
40{
41 LOG(info) << "Trd Setup consist of " << fNofStation << " stations.";
42
45 return kSUCCESS;
46}
47
49{
50 FairRootManager* ioman = FairRootManager::Instance();
51 if (NULL == ioman) LOG(fatal) << "No FairRootManager!";
52
53 fTrdPoints = dynamic_cast<TClonesArray*>(ioman->GetObject("TrdPoint"));
54 if (NULL == fTrdPoints) LOG(error) << "No TrdPoint array!";
55
56 fMCTracks = dynamic_cast<TClonesArray*>(ioman->GetObject("MCTrack"));
57 if (NULL == fMCTracks) LOG(error) << "No MCTrack array!";
58}
59
61{
64 fHM->Create1<TH1F>("h_trd_EventNo_MCQa", "h_trd_EventNo_MCQa", 1, 0, 1.);
65}
66
68{
69
70 Int_t nofBins = 100;
71 Double_t minX = -0.5;
72 Double_t maxX = 99.5;
73 string name = "h_trd_NofObjects_";
74 fHM->Create1<TH1F>(name + "Points", name + "Points;Objects per event;Entries", nofBins, minX, 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", name + "Points_Station;Station number;Objects per event", nofBins, minX,
80 maxX);
81}
82
84{
85 for (Int_t stationId = 0; stationId < fNofStation; stationId++) {
86 Int_t nofBins = 100;
87 Double_t minX = -0.5;
88 Double_t maxX = 99.5;
89 fHM->Create1<TH1F>(Form("h_trd_MultPoints_Station%i", stationId),
90 Form("Mult, Station %i;Objects per event;Entries", stationId), nofBins, minX, maxX);
91
92 fHM->Create2<TH2F>(Form("h_trd_PointsMap_Station%i", stationId),
93 Form("TrdPoint, Station %i;x, cm;y, cm", stationId), 120, -60., 60., 120, -60., 60.);
94 fHM->Create2<TH2F>(Form("h_trd_PointsMapEvent_Station%i", stationId),
95 Form("TrdPoint/cm^{2}, Station %i;x, cm;y, cm", stationId), 120, -60., 60., 120, -60., 60.);
96 fHM->Create2<TH2F>(Form("h_trd_PointsMapRate_Station%i", stationId),
97 Form("TrdPoint/cm^{2}/s, Station %i;x, cm;y, cm", stationId), 120, -60., 60., 120, -60., 60.);
98 fHM->Create1<TH1F>(Form("h_trd_XPos_Station%i", stationId), "X position;x, cm; Entries", 1200, -60., 60.);
99 fHM->Create1<TH1F>(Form("h_trd_YPos_Station%i", stationId), "Y position;y, cm; Entries", 1200, -60., 60.);
100 }
101 fHM->Create1<TH1F>("h_trd_XPos", "X position;x, cm; Entries", 1200, -60., 60.);
102 fHM->Create1<TH1F>("h_trd_YPos", "Y position;y, cm; Entries", 1200, -60., 60.);
103}
104
105void CbmTrdMCQa::Exec(Option_t*)
106{
108 fHM->H1("h_trd_EventNo_MCQa")->Fill(0.5);
109}
110
111void CbmTrdMCQa::ProcessPoints(const TClonesArray* points)
112{
113
114 fHM->H1("h_trd_NofObjects_Points")->Fill(points->GetEntriesFast());
115
116 Double_t pointX = 0.;
117 Double_t pointY = 0.;
118 // Double_t pointZ=0.;
119
120 std::map<Int_t, vector<Int_t>> used_map;
121
122 for (Int_t iPoint = 0; iPoint < points->GetEntriesFast(); iPoint++) {
123 const CbmTrdPoint* trdPoint = static_cast<const CbmTrdPoint*>(points->At(iPoint));
124 Int_t stationId = CbmTrdAddress::GetLayerId(trdPoint->GetModuleAddress());
125 ;
126 fHM->H1("h_trd_NofObjects_Points_Station")->Fill(stationId);
127
128 pointX = trdPoint->GetXIn();
129 pointY = trdPoint->GetYIn();
130 // pointZ = trdPoint -> GetZIn();
131
132 fHM->H1(Form("h_trd_XPos_Station%i", stationId))->Fill(pointX);
133 fHM->H1(Form("h_trd_YPos_Station%i", stationId))->Fill(pointY);
134
135 fHM->H2(Form("h_trd_PointsMap_Station%i", stationId))->Fill(pointX, pointY);
136 fHM->H2(Form("h_trd_PointsMapEvent_Station%i", stationId))->Fill(pointX, pointY);
137 fHM->H2(Form("h_trd_PointsMapRate_Station%i", stationId))->Fill(pointX, pointY);
138 fHM->H1("h_trd_XPos")->Fill(pointX);
139 fHM->H1("h_trd_YPos")->Fill(pointY);
140
141 Int_t mcTrackID = trdPoint->GetTrackID();
142
143 if (std::find(used_map[stationId].begin(), used_map[stationId].end(), mcTrackID) == used_map[stationId].end()) {
144 used_map[stationId].push_back(mcTrackID);
145 }
146 }
147 fHM->H1(Form("h_trd_MultPoints_Station%i", 0))->Fill(used_map[0].size());
148 fHM->H1(Form("h_trd_MultPoints_Station%i", 1))->Fill(used_map[1].size());
149 fHM->H1(Form("h_trd_MultPoints_Station%i", 2))->Fill(used_map[2].size());
150 fHM->H1(Form("h_trd_MultPoints_Station%i", 3))->Fill(used_map[3].size());
151}
152
154{
155
156 Int_t nofEvents = fHM->H1("h_trd_EventNo_MCQa")->GetEntries();
157 // Do here some scaling of the histograms to have MCPoint per cm^2
158
159 Int_t xbins = (fHM->H2("h_trd_PointsMap_Station0"))->GetXaxis()->GetNbins();
160 Float_t xmax = fHM->H2("h_trd_PointsMap_Station0")->GetXaxis()->GetXmax();
161 Float_t xmin = fHM->H2("h_trd_PointsMap_Station0")->GetXaxis()->GetXmin();
162 Float_t scaleX = static_cast<Float_t>(xbins) / (xmax - xmin);
163
164 Int_t ybins = fHM->H2("h_trd_PointsMap_Station0")->GetYaxis()->GetNbins();
165 Int_t ymax = fHM->H2("h_trd_PointsMap_Station0")->GetYaxis()->GetXmax();
166 Int_t ymin = fHM->H2("h_trd_PointsMap_Station0")->GetYaxis()->GetXmin();
167 Float_t scaleY = static_cast<Float_t>(ybins) / (ymax - ymin);
168
169 Float_t scale = scaleX * scaleY;
170 scale = 1.;
171
172 for (Int_t i = 0; i < fNofStation; ++i) {
173 fHM->Scale(Form("h_trd_PointsMapEvent_Station%i", i), scale / nofEvents);
174 fHM->Scale(Form("h_trd_PointsMapRate_Station%i", i), 10000000. * scale / nofEvents);
175 }
176
177 gDirectory->mkdir("TrdMcQA");
178 gDirectory->cd("TrdMcQA");
179 fHM->WriteToFile();
180 gDirectory->cd("..");
181 // CbmSimulationReport* report = new CbmTrdMCQaReport(fSetup, fDigitizer);
182 // report -> Create(fHM, fOutputDir);
183 // delete report;
184
185 // Compare results with defined benchmark results and raise an ERROR if there are differences
186 // Either get default histogramms from a benchmark qa file or as parameters from the parameter container
187}
188
TClonesArray * points
Histogram manager.
Base class for simulation reports.
Helper class to convert unique channel ID back and forth.
ClassImp(CbmTrdMCQa)
static constexpr size_t size()
Definition KfSimdPseudo.h:2
Histogram manager.
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
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...
void Scale(const std::string &histName, Double_t scale)
Scale histogram.
void WriteToFile()
Write all objects to current opened file.
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...
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
static uint32_t GetLayerId(uint32_t address)
Return layer ID from address.
void ReadDataBranches()
void CreateNofObjectsHistograms()
void CreateHistograms()
TClonesArray * fTrdPoints
Definition CbmTrdMCQa.h:39
virtual void Exec(Option_t *)
Int_t fNofStation
Definition CbmTrdMCQa.h:41
virtual InitStatus Init()
virtual ~CbmTrdMCQa()
void CreatePointHistograms()
TClonesArray * fMCTracks
Definition CbmTrdMCQa.h:40
void ProcessPoints(const TClonesArray *)
CbmHistManager * fHM
Definition CbmTrdMCQa.h:38
virtual void Finish()
double GetXIn() const
Definition CbmTrdPoint.h:65
int32_t GetModuleAddress() const
Definition CbmTrdPoint.h:78
double GetYIn() const
Definition CbmTrdPoint.h:66