CbmRoot
Loading...
Searching...
No Matches
CbmStsDigitizeQa.cxx
Go to the documentation of this file.
1/* Copyright (C) 2016-2020 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Hanna Malygina [committer], Volker Friese */
4
5#include "CbmStsDigitizeQa.h"
6
7#include "CbmDigiManager.h"
8#include "CbmHistManager.h"
9#include "CbmMCDataManager.h"
10#include "CbmMatch.h"
11#include "CbmStsAddress.h"
12#include "CbmStsDigi.h"
13#include "CbmStsDigitize.h"
14#include "CbmStsElement.h"
15#include "CbmStsModule.h"
16#include "CbmStsSetup.h"
17//#include "CbmMCBuffer.h"
18#include "CbmSimulationReport.h"
20#include "CbmStsParAsic.h"
21#include "CbmStsParModule.h"
22#include "CbmStsParSetModule.h"
23#include "CbmStsParSim.h"
24
25#include "FairMCPoint.h"
26#include "FairRootManager.h"
27#include "FairRun.h"
28#include "FairRuntimeDb.h"
29#include <Logger.h>
30
31#include "TClonesArray.h"
32#include "TF1.h"
33#include "TGeoMatrix.h"
34#include "TGeoPhysicalNode.h"
35#include "TH1.h"
36#include "TH1D.h"
37#include "TH2.h"
38#include "TProfile.h"
39#include "TProfile2D.h"
40#include "TSystem.h"
41
42using std::cout;
43using std::endl;
44using std::map;
45using std::pair;
46using std::set;
47using std::string;
48using std::vector;
49
51 : FairTask("CbmStsDigitizeQa")
52 , fHM(NULL)
53 , fDigiManager(nullptr)
54 , fOutputDir(" ")
55 , fStsPoints(NULL)
56 , fSetup(NULL)
57 , fNofStation(8)
58 , fMaxScale(0)
59 , fOutFile(NULL)
60 , fnOfDigisChip()
61{
62}
63
68
70{
71 FairRuntimeDb* rtdb = FairRun::Instance()->GetRuntimeDb();
72
73 fSettings = dynamic_cast<CbmStsParSim*>(rtdb->getContainer("CbmStsParSim"));
74 fModuleParSet = dynamic_cast<CbmStsParSetModule*>(rtdb->getContainer("CbmStsParSetModule"));
75}
76
78{
80 if (!fSetup->IsInit()) fSetup->Init();
83 fHM = new CbmHistManager();
87 for (Int_t iStation = 0; iStation < fNofStation; iStation++) {
88 CbmStsElement* stat = fSetup->GetDaughter(iStation);
89 fnOfDigisChip[iStation].resize(stat->GetNofDaughters());
90 for (Int_t iLad = 0; iLad < stat->GetNofDaughters(); iLad++) {
91 CbmStsElement* ladd = stat->GetDaughter(iLad);
92 fnOfDigisChip[iStation][iLad].resize(ladd->GetNofDaughters());
93 for (Int_t iHla = 0; iHla < ladd->GetNofDaughters(); iHla++) {
94 CbmStsElement* hlad = ladd->GetDaughter(iHla);
95 fnOfDigisChip[iStation][iLad][iHla].resize(hlad->GetNofDaughters());
96 for (Int_t iMod = 0; iMod < hlad->GetNofDaughters(); iMod++) {
97 CbmStsModule* modu = static_cast<CbmStsModule*>(hlad->GetDaughter(iMod));
98 Int_t nOfChips = Int_t(modu->GetParameters()->GetNofChannels() / 128.);
99 fnOfDigisChip[iStation][iLad][iHla][iMod].resize(nOfChips);
100 for (Int_t iChip = 0; iChip < nOfChips; iChip++) {
101 fnOfDigisChip[iStation][iLad][iHla][iMod][iChip] = 0;
102 }
103 }
104 }
105 }
106 }
107
108 // Get parameters of the first ASIC in the first module. This, of course,
109 // assumes that all ASIC parameters in the setup are the same.
110 UInt_t address = fSetup->GetModule(0)->GetAddress();
111 fAsicPar = &(fModuleParSet->GetParModule(address).GetParAsic(0));
112
115
116 return kSUCCESS;
117}
118
119void CbmStsDigitizeQa::Exec(Option_t* /*opt*/)
120{
122 fHM->H1("h_EventNo_DigitizeQa")->Fill(0.5);
123}
124
126{
128 Int_t nofEvents = fHM->H1("h_EventNo_DigitizeQa")->GetEntries();
129 TString fileName = fOutputDir + "/digiRateChip";
130 fileName += nofEvents;
131 fileName += ".dat";
132 TString rmFile = "rm " + fileName;
133 gSystem->Exec(rmFile);
134 fOutFile.open(Form("%s", fileName.Data()), std::ofstream::app);
135 for (Int_t iStation = 0; iStation < fNofStation; iStation++) {
136 CbmStsElement* stat = fSetup->GetDaughter(iStation);
137 for (Int_t iLad = 0; iLad < stat->GetNofDaughters(); iLad++) {
138 CbmStsElement* ladd = stat->GetDaughter(iLad);
139 for (Int_t iHla = 0; iHla < ladd->GetNofDaughters(); iHla++) {
140 CbmStsElement* hlad = ladd->GetDaughter(iHla);
141 for (Int_t iMod = 0; iMod < hlad->GetNofDaughters(); iMod++) {
142 CbmStsModule* modu = static_cast<CbmStsModule*>(hlad->GetDaughter(iMod));
143 UInt_t nChannels = modu->GetParameters()->GetNofChannels();
144 if (nChannels != 2048) cout << "nofChannels = " << nChannels;
145 Int_t nOfChips = Int_t(nChannels / 128.);
146 for (Int_t iChip = 0; iChip < nOfChips; iChip++)
147 fOutFile << iStation << "\t" << iLad << "\t" << iHla << "\t" << iMod << "\t" << iChip << "\t"
148 << fnOfDigisChip[iStation][iLad][iHla][iMod][iChip] << endl;
149 }
150 }
151 }
152 }
153 gDirectory->mkdir("STSDigitizeQA");
154 gDirectory->cd("STSDigitizeQA");
155 fHM->WriteToFile();
156 gDirectory->cd("../");
158 report->Create(fHM, fOutputDir);
159 delete report;
160
161 /* Double_t matchedHits = 100. * (Double_t) fHM->H1("hno_NofObjects_MatchedHits_Station_" + type)->Integral() /
162 (Double_t) fHM->H1("hno_NofObjects_Hits_Station_" + type)->Integral();
163 Double_t efficiency = 100 * (Double_t) fHM->H1("hno_NofObjects_MatchedHits_Station_" + type)->Integral() /
164 (Double_t) fHM->H1("hno_NofObjects_Points_Station_" + type)->Integral();
165 Double_t ghost = 100 * ((Double_t) fHM->H1("hno_NofObjects_Hits_Station_" + type)->Integral() -
166 (Double_t) fHM->H1("hno_NofObjects_MatchedHits_Station_" + type)->Integral()) /
167 (Double_t) fHM->H1("hno_NofObjects_Points_Station_" + type)->Integral();
168
169 std::cout<<" -I- CbmStsTimeBasedQa: Hits: "<<fHM->H1("hno_NofObjects_Hits_Station_" + type)->Integral()
170 <<"\n -I- CbmStsTimeBasedQa: MatchedHits: "<<fHM->H1("hno_NofObjects_MatchedHits_Station_" + type)->Integral()
171 <<"\n -I- CbmStsTimeBasedQa: MatchedHits: "<<matchedHits<<" %"
172 <<"\n -I- CbmStsTimeBasedQa: Efficiency : "<<efficiency<<" %"
173 <<"\n -I- CbmStsTimeBasedQa: Ghost : "<<ghost<<" %";*/
174}
175
177{
178 FairRootManager* ioman = FairRootManager::Instance();
179 if (NULL == ioman) LOG(fatal) << GetName() << ": No FairRootManager!";
180
181 fStsPoints = (TClonesArray*) ioman->GetObject("StsPoint");
182 if (NULL == fStsPoints) LOG(error) << GetName() << ": No StsPoint array!";
183
185 LOG(fatal) << GetName() << ": No StsDigi branch in input!";
186 return;
187 }
188
190 LOG(fatal) << GetName() << ": No StsDigiMatch branch in input!";
191 return;
192 }
193}
194
196{
199 fHM->Create1<TH1F>("h_EventNo_DigitizeQa", "h_EventNo_DigitizeQa", 1, 0, 1.);
200}
201
203{
204 Int_t nofBins = 100;
205 Double_t minX = -0.5;
206 Double_t maxX = 49999.5;
207 string name = "h_NofObjects_";
208 fHM->Create1<TH1F>(name + "Points", name + "Points;Objects per event;Entries", nofBins, minX, maxX);
209 fHM->Create1<TH1F>(name + "Digis", name + "Digis;Objects per event;Entries", nofBins, minX, maxX);
210
211 nofBins = 8;
212 minX = -0.5;
213 maxX = 7.5;
214 fHM->Create1<TH1F>(name + "Points_Station", name + "Points_Station;Station number;Objects per event", nofBins, minX,
215 maxX);
216 fHM->Create1<TH1F>(name + "Digis_Station", name + "Digis_Station;Station number;Oblects per enent", nofBins, minX,
217 maxX);
218}
219
221{
222 Int_t nofBins = 25;
223 Double_t minX = 0.5;
224 Double_t maxX = minX + nofBins;
225 fHM->Create1<TH1F>("h_PointsInDigi", "PointsInDigi;Number of Points;Entries", nofBins, minX, maxX);
226 fHM->Create1<TH1F>("h_PointsInDigiLog", "PointsInDigi;Number of Points;Entries", nofBins, minX, maxX);
227 fHM->Create1<TH1F>("h_DigisByPoint", "DigisByPoint;Number of Digis;Entries", nofBins, minX, maxX);
228 fHM->Create1<TH1F>("h_DigisByPointLog", "DigisByPoint;Number of Digis;Entries", nofBins, minX, maxX);
229 nofBins = fAsicPar->GetNofAdc();
230 fHM->Create1<TH1F>("h_DigiCharge", "DigiCharge;Digi Charge, ADC;Entries", nofBins, 0., Double_t(nofBins));
231 for (Int_t stationId = 0; stationId < fNofStation; stationId++) {
232 fHM->Create2<TH2F>(Form("h_DigisPerChip_Station%i", stationId),
233 Form("Digis per Chip, Station %i;x, cm;y, cm", stationId), 400, -50, 50, 200, -50, 50);
234 fHM->Create2<TH2F>(Form("h_PointsMap_Station%i", stationId), Form("Points Map, Station %i;x, cm;y, cm", stationId),
235 100, -50, 50, 100, -50, 50);
236 fHM->Create2<TH2F>(Form("h_MeanAngleMap_Station%i", stationId),
237 Form("Mean Angle Map, Station %i;x, cm;y, cm", stationId), 50, -50, 50, 50, -50, 50);
238 fHM->Create2<TH2F>(Form("h_RMSAngleMap_Station%i", stationId),
239 Form("RMS Angle Map, Station %i;x, cm;y, cm", stationId), 50, -50, 50, 50, -50, 50);
240 }
241 Double_t local[3] = {0., 0., 0.};
242 Double_t global[3];
243 for (Int_t moduId = 0; moduId < fSetup->GetNofModules(); moduId++) {
244 CbmStsModule* modu = static_cast<CbmStsModule*>(fSetup->GetModule(moduId));
245 TGeoPhysicalNode* node = modu->CbmStsElement::GetDaughter(0)->CbmStsElement::GetPnode();
246 if (node) {
247 TGeoMatrix* matrix = node->GetMatrix();
248 matrix->LocalToMaster(local, global);
249 }
250 fHM->Create1<TH1F>(Form("h_ParticleAngles_%s", modu->GetName()),
251 Form("Particle Angles (%.0f cm, %.0f cm);Angle, deg;Entries", global[0], global[1]), 90, 0.,
252 90.);
253 }
254}
255
257{
258 if (fHM->Exists("h_NofObjects_Digis"))
259 fHM->H1("h_NofObjects_Digis")->Fill(fDigiManager->GetNofDigis(ECbmModuleId::kSts));
260 std::set<Double_t> pointIndexes;
261 std::map<Double_t, Int_t> stations;
262 std::map<Double_t, Int_t> digisByPoint;
263 std::map<Double_t, Int_t>::iterator map_it;
264 pointIndexes.clear();
265 Double_t local[3] = {0., 0., 0.};
266 Double_t global[3];
267 for (Int_t index = 0; index < fDigiManager->GetNofDigis(ECbmModuleId::kSts); index++) {
268 const CbmStsDigi* stsDigi = fDigiManager->Get<CbmStsDigi>(index);
269 const CbmMatch* digiMatch = fDigiManager->GetMatch(ECbmModuleId::kSts, index);
270 Int_t stationId = fSetup->GetStationNumber(stsDigi->GetAddress());
271 //Int_t iLad = CbmStsAddress::GetElementId(stsDigi->GetAddress(), kStsLadder);
272 //Int_t iHla =
273 //CbmStsAddress::GetElementId(stsDigi->GetAddress(), kStsHalfLadder);
274 //Int_t iMod = CbmStsAddress::GetElementId(stsDigi->GetAddress(), kStsModule);
275 CbmStsModule* modu = static_cast<CbmStsModule*>(fSetup->GetElement(stsDigi->GetAddress(), kStsModule));
276 Int_t nOfChannelsM = modu->GetParameters()->GetNofChannels();
277 TGeoPhysicalNode* node = modu->CbmStsElement::GetDaughter(0)->CbmStsElement::GetPnode();
278 if (node) {
279 TGeoMatrix* matrix = node->GetMatrix();
280 matrix->LocalToMaster(local, global);
281 }
282
283 Int_t iChan = stsDigi->GetChannel();
284 Int_t iChip = iChan / 128;
285
286 // TODO
287 // Sergey Gorbunov: the code crashes at this line,
288 // because iLad is sometimes out of the range,
289 // it needs to be fixed
290 //fnOfDigisChip[stationId][iLad][iHla][iMod][iChip]++;
291
292 fHM->H2(Form("h_DigisPerChip_Station%i", stationId))
293 ->Fill(global[0] + 50. / 400. * ((iChip - 8.) * 2. - 1.), global[1]);
294
295 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink++) {
296 const CbmLink link = digiMatch->GetLink(iLink);
297 Double_t index2 = (1000 * link.GetIndex()) + (link.GetFile()) + (0.0001 * link.GetEntry());
298 pointIndexes.insert(index2);
299 stations.insert(std::pair<Double_t, Int_t>(index2, stationId));
300 Int_t channel = stsDigi->GetChannel();
301
302 Int_t side = channel < Int_t(nOfChannelsM / 2.) ? 0 : 1;
303 map_it = digisByPoint.find(index2 + (side * 0.00001));
304 if (map_it != digisByPoint.end()) { map_it->second++; }
305 else {
306 digisByPoint.insert(std::pair<Double_t, Int_t>(index2 + (side * 0.00001), 1));
307 }
308 }
309 fHM->H1("h_NofObjects_Digis_Station")->Fill(stationId);
310 fHM->H1("h_PointsInDigi")->Fill(digiMatch->GetNofLinks());
311 fHM->H1("h_PointsInDigiLog")->Fill(digiMatch->GetNofLinks());
312 fHM->H1("h_DigiCharge")->Fill(stsDigi->GetCharge());
313 }
314 fHM->H1("h_NofObjects_Points")->Fill(pointIndexes.size());
315 std::set<Double_t>::iterator set_it;
316 for (set_it = pointIndexes.begin(); set_it != pointIndexes.end(); ++set_it) {
317 fHM->H1("h_NofObjects_Points_Station")->Fill(stations[*set_it]);
318 fHM->H1("h_DigisByPoint")->Fill(digisByPoint[*set_it]);
319 fHM->H1("h_DigisByPoint")->Fill(digisByPoint[*set_it + 0.00001]);
320 fHM->H1("h_DigisByPointLog")->Fill(digisByPoint[*set_it]);
321 fHM->H1("h_DigisByPointLog")->Fill(digisByPoint[*set_it + 0.00001]);
322 }
323 if (pointIndexes.size() > static_cast<size_t>(fMaxScale)) fMaxScale = pointIndexes.size();
324
325 Double_t pointX, pointY; //, pointZ;
326 Double_t pointPX, pointPZ;
327 for (Int_t iPoint = 0; iPoint < points->GetEntriesFast(); iPoint++) {
328 const FairMCPoint* stsPoint = static_cast<const FairMCPoint*>(points->At(iPoint));
329 CbmStsModule* modu = static_cast<CbmStsModule*>(fSetup->GetElement(stsPoint->GetDetectorID(), kStsModule));
330 TGeoPhysicalNode* node = modu->CbmStsElement::GetDaughter(0)->CbmStsElement::GetPnode();
331 if (node) {
332 TGeoMatrix* matrix = node->GetMatrix();
333 matrix->LocalToMaster(local, global);
334 }
335 pointX = stsPoint->GetX();
336 pointY = stsPoint->GetY();
337 // pointZ = stsPoint -> GetZ();
338 pointPX = stsPoint->GetPx();
339 pointPZ = stsPoint->GetPz();
340 Int_t stationId = fSetup->GetStationNumber(stsPoint->GetDetectorID());
341 fHM->H2(Form("h_PointsMap_Station%i", stationId))->Fill(pointX, pointY);
342 fHM->H1(Form("h_ParticleAngles_%s", modu->GetName()))
343 ->Fill(TMath::Abs(TMath::ATan(pointPX / pointPZ)) * 180. / 3.1416);
344 }
345}
346
347
349{
350 Double_t local[3] = {0., 0., 0.};
351 Double_t global[3];
352 for (Int_t iStation = 0; iStation < fNofStation; iStation++) {
353 CbmStsElement* stat = fSetup->GetDaughter(iStation);
354 for (Int_t iLad = 0; iLad < stat->GetNofDaughters(); iLad++) {
355 CbmStsElement* ladd = stat->GetDaughter(iLad);
356 for (Int_t iHla = 0; iHla < ladd->GetNofDaughters(); iHla++) {
357 CbmStsElement* hlad = ladd->GetDaughter(iHla);
358 for (Int_t iMod = 0; iMod < hlad->GetNofDaughters(); iMod++) {
359 CbmStsElement* modu = hlad->GetDaughter(iMod);
360 Double_t mean = fHM->H1(Form("h_ParticleAngles_%s", modu->GetName()))->GetMean();
361 Double_t rms = fHM->H1(Form("h_ParticleAngles_%s", modu->GetName()))->GetRMS();
362 TGeoPhysicalNode* node = modu->CbmStsElement::GetDaughter(0)->CbmStsElement::GetPnode();
363 if (node) {
364 TGeoMatrix* matrix = node->GetMatrix();
365 matrix->LocalToMaster(local, global);
366 }
367 fHM->H2(Form("h_MeanAngleMap_Station%i", iStation))->Fill(global[0], global[1], mean);
368 fHM->H2(Form("h_RMSAngleMap_Station%i", iStation))->Fill(global[0], global[1], rms);
369 }
370 }
371 }
372 }
373}
TClonesArray * points
@ kSts
Silicon Tracking System.
Histogram manager.
Base class for simulation reports.
@ kStsModule
ClassImp(CbmStsDigitizeQa)
static Int_t GetNofDigis(ECbmModuleId systemId)
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
static Bool_t IsMatchPresent(ECbmModuleId systemId)
Presence of a digi match branch.
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
const CbmMatch * GetMatch(ECbmModuleId systemId, UInt_t index) const
Get a match object.
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 WriteToFile()
Write all objects to current opened file.
Bool_t Exists(const std::string &name) const
Check existence of object in manager.
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.
Base class for simulation reports.
void Create(CbmHistManager *histManager, const std::string &outputDir)
Main function which creates report data.
Data class for a single-channel message in the STS.
Definition CbmStsDigi.h:40
XPU_D uint16_t GetChannel() const
Channel number in module @value Channel number.
Definition CbmStsDigi.h:93
XPU_D int32_t GetAddress() const
Definition CbmStsDigi.h:74
std::ofstream fOutFile
virtual void Exec(Option_t *opt)
const CbmStsParAsic * fAsicPar
std::string fOutputDir
CbmStsDigitizeQa(CbmStsDigitize *digitizer=NULL)
void ProcessDigisAndPoints(const TClonesArray *points)
const CbmStsParSim * fSettings
CbmDigiManager * fDigiManager
virtual void SetParContainers()
CbmStsParSetModule * fModuleParSet
std::vector< std::vector< std::vector< std::vector< std::vector< Int_t > > > > > fnOfDigisChip
virtual void Finish()
CbmStsSetup * fSetup
virtual InitStatus Init()
TClonesArray * fStsPoints
CbmHistManager * fHM
Task class for simulating the detector response of the STS.
Class representing an element of the STS setup.
Int_t GetAddress() const
Int_t GetNofDaughters() const
CbmStsElement * GetDaughter(Int_t index) const
Class representing an instance of a readout unit in the CBM-STS.
const CbmStsParModule * GetParameters() const
Module parameters.
uint16_t GetNofAdc() const
Number of ADC channels.
uint32_t GetNofChannels() const
Number of channels.
Parameters container for CbmStsParModule.
const CbmStsParModule & GetParModule(UInt_t address)
Get condition parameters of a sensor.
Settings for STS simulation (digitizer)
Bool_t IsModuleParsInit() const
Initialisation status for module parameters.
Bool_t Init(const char *geometryFile=nullptr)
Initialise the setup.
CbmStsModule * GetModule(Int_t index) const
Get a module from the module array.
Definition CbmStsSetup.h:72
CbmStsElement * GetElement(Int_t address, Int_t level)
Int_t GetNofStations() const
Definition CbmStsSetup.h:94
static CbmStsSetup * Instance()
UInt_t SetModuleParameters(CbmStsParSetModule *modulePars)
Set module parameters from parameter container.
Int_t GetStationNumber(Int_t address)
Int_t GetNofModules() const
Definition CbmStsSetup.h:86
Bool_t IsInit() const
Initialisation status for sensor parameters.