CbmRoot
Loading...
Searching...
No Matches
CbmTrdHitDensityQa.cxx
Go to the documentation of this file.
1/* Copyright (C) 2011-2021 Institut fuer Kernphysik, Westfaelische Wilhelms-Universitaet Muenster, Muenster
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Cyrano Bergmann [committer], Florian Uhlig */
4
6
7#include "CbmDigiManager.h"
8#include "CbmTrdCluster.h"
9#include "CbmTrdDigi.h"
10#include "CbmTrdGeoHandler.h"
11#include "CbmTrdHit.h"
12#include "CbmTrdParModAsic.h"
13#include "CbmTrdParModDigi.h"
14#include "CbmTrdParModGeo.h"
15#include "CbmTrdParSetAsic.h"
16#include "CbmTrdParSetDigi.h"
17#include "CbmTrdParSetGeo.h"
18#include "CbmTrdPoint.h"
19#include "CbmTrdUtils.h"
20#include "FairRootManager.h"
21#include "FairRunAna.h"
22#include "FairRuntimeDb.h"
23#include "TArray.h"
24#include "TCanvas.h"
25#include "TClonesArray.h"
26#include "TColor.h"
27#include "TDatime.h"
28#include "TDirectory.h"
29#include "TF1.h"
30#include "TGeoManager.h"
31#include "TH2D.h"
32#include "TH2F.h"
33#include "TH2I.h"
34#include "TImage.h"
35#include "TLegend.h"
36#include "TLine.h"
37#include "TMath.h"
38#include "TProfile.h"
39#include "TStopwatch.h"
40
41#include <Logger.h>
42
43#include <TFile.h>
44
45//#include <map>
46#include <cmath>
47#include <iomanip>
48#include <iostream>
49
50// #include "CbmTrdDigitizer.h"
51// #include "CbmTrdClusterFinder.h"
52// #include "CbmTrdHitProducer.h"
53
54using std::cout;
55using std::endl;
56using std::ios;
57using std::setfill;
58using std::setiosflags;
59using std::setprecision;
60using std::setw;
61
62// ---- Default constructor -------------------------------------------
64 : CbmTrdHitDensityQa(1e-6, 1e7, 1.0 /*used only for minBias events*/
65 /*(1./4.)used only for central events*/)
66{
67}
68
69CbmTrdHitDensityQa::CbmTrdHitDensityQa(Double_t TriggerThreshold, Double_t EventRate, Double_t ScaleCentral2mBias)
70 : FairTask("CbmTrdHitDensityQa", 1)
71 , myfile()
72 , fmin(1E3)
73 , fmax(2.5E5)
74 , flogScale(false)
75 , fBitPerHit(1.)
76 , h1DataModule(NULL)
77 , h1OptLinksModule(NULL)
78 , fNeighbourTrigger(true)
79 , fPlotResults(false)
80 , fRatioTwoFiles(false)
81 , fClusters(NULL)
82 , fAsicPar(NULL)
83 , fDigiPar(NULL)
84 , fGeoPar(NULL)
85 , fGeoHandler(new CbmTrdGeoHandler())
86 , fStation(-1)
87 , fLayer(-1)
88 , fModuleID(-1)
89 , fEventCounter(NULL)
90 , fTriggerThreshold(TriggerThreshold)
91 , fEventRate(EventRate)
92 , fScaleCentral2mBias(ScaleCentral2mBias)
93 , fUsedDigiMap()
94 , fModuleHitMap()
95 , fModuleHitMapIt()
96 , fModuleHitASICMap()
97 , fModuleHitASICMapIt()
98{
99}
100
101// ---- Destructor ----------------------------------------------------
103{
104 if (fClusters) {
105 fClusters->Delete();
106 delete fClusters;
107 }
108 // if(fAsicPar) delete fDigiPar;
109 // if(fDigiPar) delete fDigiPar;
110 // if(fGeoPar) delete fDigiPar;
111}
112
113// ---- Initialisation ----------------------------------------------
115{
116 // Get Base Container
117 FairRunAna* ana = FairRunAna::Instance();
118 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
119 cout << " * CbmTrdHitDensityQa * :: SetParContainers()" << endl;
120 fAsicPar = (CbmTrdParSetAsic*) (rtdb->getContainer("CbmTrdParSetAsic"));
121 fDigiPar = (CbmTrdParSetDigi*) (rtdb->getContainer("CbmTrdParSetDigi"));
122 fGeoPar = (CbmTrdParSetGeo*) (rtdb->getContainer("CbmTrdParSetGeo"));
123}
124// ---- ReInit -------------------------------------------------------
126{
127 cout << " * CbmTrdHitDensityQa * :: ReInit()" << endl;
128 //FairRunAna* ana = FairRunAna::Instance();
129 //FairRuntimeDb* rtdb=ana->GetRuntimeDb();
130
131 //fDigiPar = (CbmTrdDigiPar*)(rtdb->getContainer("CbmTrdDigiPar"));
132
133 return kSUCCESS;
134}
135// ---- Init ----------------------------------------------------------
137{
138 cout << " * CbmTrdHitDensityQa * :: Init()" << endl;
139 FairRootManager* ioman = FairRootManager::Instance();
140
142 if (!CbmDigiManager::Instance()->IsPresent(ECbmModuleId::kTrd)) LOG(fatal) << GetName() << "Missing Trd digi branch.";
143
144
145 fClusters = (TClonesArray*) ioman->GetObject("TrdCluster");
146 if (!fClusters) {
147 cout << "-W CbmTrdHitDensityQa::Init: No TrdCluster array!" << endl;
148 cout << " Task will be inactive" << endl;
149 //return kERROR;
150 }
151 /*
152 TString origpath = gDirectory->GetPath();
153 printf ("\n%s\n",origpath.Data());
154 TString newpath = origpath;
155 TFile *results = NULL;
156 results->Open("data/result.root","read");
157 *//*
158 if (gSystem->AccessPathName("/data/result.root")){//results->IsOpen()){
159 //gDirectory = results.CurrentDirectory();
160 //gDirectory->pwd();
161 fPlotResults = true;
162 //results.Close();
163 } else {
164 fPlotResults = false;
165 }
166 */
167 //gDirectory->Cd(origpath);
168 //gDirectory->pwd();
169 // Extract information about the number of TRD stations and
170 // the number of layers per TRD station from the geomanager.
171 // Store the information about the number of layers at the entrance
172 // of subsequent stations in a vector.
173 // This allows to calculate the layer number starting with 1 for the
174 // first layer of the first station at a later stage by only adding
175 // the layer number in the station to the number of layers in
176 // previous stations
177
178 fGeoHandler->Init();
179
180 printf("\nCbmTrdHitDensityQa::Init: NeighbourTrigger %i\n\n", fNeighbourTrigger);
181
182 fEventCounter = new TH1I("fEventCounter", "fEventCounter", 1, -0.5, 0.5);
183
184 return kSUCCESS;
185}
187void CbmTrdHitDensityQa::SetPlotResults(Bool_t plotResults) { fPlotResults = plotResults; }
191void CbmTrdHitDensityQa::SetLogScale(Bool_t logScale) { flogScale = logScale; }
192
194{
195 fRatioTwoFiles = ratioPlot;
196 fPlotResults = true;
197}
198
200{
201
202
203 printf("=================CbmTrdHitDensityQa====================\n");
204 TString title;
205 TStopwatch timer;
206 timer.Start();
207
208
209 fBitPerHit = 112 * 1.5; // (112 + 4*16) * 10 / 8.; // 6 time samples, 8b/10b encoding, CBMnet header
210 // fBitPerHit = 220; // (112 + 4*16) * 10 / 8.; // 6 time samples, 8b/10b encoding, CBMnet header
211 // fBitPerHit = 112; // 6 time samples 3 + (9 * 6 + 3) / 15 = 7 words = 7 * 16 bit = 112 bits
212
213
214 fEventCounter->Fill(0);
215 printf("\n Event: %i\n\n", (Int_t) fEventCounter->GetEntries());
216 //fNeighbourTrigger = CbmTrdClusterFinderFast::GetTriggerThreshold();
217 const CbmTrdDigi* digi = NULL;
218 CbmTrdCluster* cluster = NULL;
219 if (NULL != fClusters && fNeighbourTrigger == true) {
220 Int_t nCluster = fClusters->GetEntriesFast();
221 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
222 //cout << iCluster << endl;
223 cluster = (CbmTrdCluster*) fClusters->At(iCluster); //pointer to the acvit cluster
224 Int_t nDigisInCluster = cluster->GetNofDigis();
225 for (Int_t iDigi = 0; iDigi < nDigisInCluster; iDigi++) {
226 digi = CbmDigiManager::Instance()->Get<CbmTrdDigi>(cluster->GetDigi(iDigi));
227 //digi = (CbmTrdDigi*)fDigis->At(cluster->GetDigi(iDigi));
228 Int_t digiAddress = digi->GetAddress();
229 Int_t moduleAddress = CbmTrdAddress::GetModuleAddress(digiAddress);
230 // Int_t moduleId = CbmTrdAddress::GetModuleId(moduleAddress);// TODO
231 fLayer = CbmTrdAddress::GetLayerId(moduleAddress);
232 CbmTrdParModAsic* fModuleAsic = (CbmTrdParModAsic*) fAsicPar->GetModulePar(moduleAddress);
233 CbmTrdParModDigi* fModuleDigi = (CbmTrdParModDigi*) fDigiPar->GetModulePar(moduleAddress);
234 if (fModuleHitMap.find(moduleAddress) == fModuleHitMap.end()) {
235 title.Form("hd_Module_%i", moduleAddress);
236 Int_t nRows = fModuleDigi->GetNofRows();
237 Int_t nCols = fModuleDigi->GetNofColumns();
238 fModuleHitMap[moduleAddress] = new TH2I(title, title, nCols, -0.5, nCols - 0.5, nRows, -0.5, nRows - 0.5);
239 fModuleHitMap[moduleAddress]->SetContour(99);
240 fModuleHitMap[moduleAddress]->SetXTitle("Column Id");
241 fModuleHitMap[moduleAddress]->SetYTitle("Row Id");
242 fModuleHitMap[moduleAddress]->SetZTitle("Trigger counter");
243 }
244 if (fModuleHitASICMap.find(moduleAddress) == fModuleHitASICMap.end()) {
245 title.Form("hd_Module_%i_ASIC", moduleAddress);
246 fModuleHitASICMap[moduleAddress] =
247 new TH1D(title, title, fModuleAsic->GetNofAsics(), -0.5, fModuleAsic->GetNofAsics() - 0.5);
248 fModuleHitASICMap[moduleAddress]->SetXTitle("ASIC Address");
249 fModuleHitASICMap[moduleAddress]->SetYTitle("Trigger counter");
250 }
251 if (!fPlotResults) {
252 Int_t iCol(CbmTrdAddress::GetColumnId(digiAddress)), local_Row(CbmTrdAddress::GetRowId(digiAddress)),
253 iSec(CbmTrdAddress::GetSectorId(digiAddress));
254 Int_t iRow = fModuleDigi->GetModuleRow(iSec, local_Row);
255 if (
256 fUsedDigiMap.find(digiAddress)
257 == fUsedDigiMap
258 .end()) { // Cluster include already neighbour trigger read-out. Two clusters can share associated neighbour digis, therefore test if digi is already used
259 fModuleHitMap[moduleAddress]->Fill(iCol, iRow);
260 fUsedDigiMap[digiAddress] = iDigi;
261 }
262 }
263 }
264 }
265 }
266 else {
268 for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
269 digi = CbmDigiManager::Instance()->Get<CbmTrdDigi>(iDigi);
270 //digi = (CbmTrdDigi*) fDigis->At(iDigi);
271 Int_t digiAddress = digi->GetAddress();
272 Int_t moduleAddress = CbmTrdAddress::GetModuleAddress(digiAddress);
273 // Int_t moduleId = CbmTrdAddress::GetModuleId(moduleAddress);// TODO
274 fLayer = CbmTrdAddress::GetLayerId(moduleAddress);
275 CbmTrdParModDigi* fModuleDigi = (CbmTrdParModDigi*) fDigiPar->GetModulePar(moduleAddress);
276 CbmTrdParModAsic* fModuleAsic = (CbmTrdParModAsic*) fAsicPar->GetModulePar(moduleAddress);
277 if (digi->GetCharge() > fTriggerThreshold) {
278 if (fModuleHitMap.find(moduleAddress) == fModuleHitMap.end()) {
279 title.Form("hd_Module_%i", moduleAddress);
280 Int_t nRows = fModuleDigi->GetNofRows();
281 Int_t nCols = fModuleDigi->GetNofColumns();
282 fModuleHitMap[moduleAddress] = new TH2I(title, title, nCols, -0.5, nCols - 0.5, nRows, -0.5, nRows - 0.5);
283 fModuleHitMap[moduleAddress]->SetContour(99);
284 fModuleHitMap[moduleAddress]->SetXTitle("Column Id");
285 fModuleHitMap[moduleAddress]->SetYTitle("Row Id");
286 fModuleHitMap[moduleAddress]->SetZTitle("Trigger counter");
287 }
288 if (fModuleHitASICMap.find(moduleAddress) == fModuleHitASICMap.end()) {
289 title.Form("hd_Module_%i_ASIC", moduleAddress);
290 fModuleHitASICMap[moduleAddress] =
291 new TH1D(title, title, fModuleAsic->GetNofAsics(), -0.5, fModuleAsic->GetNofAsics() - 0.5);
292 fModuleHitASICMap[moduleAddress]->SetXTitle("ASIC Address");
293 fModuleHitASICMap[moduleAddress]->SetYTitle("Trigger counter");
294 }
295 if (!fPlotResults) {
296 Int_t iCol(CbmTrdAddress::GetColumnId(digiAddress)), local_Row(CbmTrdAddress::GetRowId(digiAddress)),
297 iSec(CbmTrdAddress::GetSectorId(digiAddress));
298 Int_t iRow = fModuleDigi->GetModuleRow(iSec, local_Row);
299 if (fUsedDigiMap.find(digiAddress) == fUsedDigiMap.end()) {
300 fModuleHitMap[moduleAddress]->Fill(iCol, iRow);
301 fUsedDigiMap[digiAddress] = iDigi;
302 }
303 }
304 /*
305 Int_t neighbourAddress = 0;
306 if (iRow > 0){
307 if (local_Row > 0)
308 neighbourAddress = CbmTrdAddress::GetAddress(fLayer, CbmTrdAddress::GetModuleId(moduleAddress), iSec, local_Row-1, iCol);
309 else if (iSec > 0)
310 neighbourAddress = CbmTrdAddress::GetAddress(fLayer, CbmTrdAddress::GetModuleId(moduleAddress), iSec-1, fModuleDigi->GetNofRowsInSector(iSec-1)-1, iCol);
311 if (fUsedDigiMap.find(neighbourAddress) == fUsedDigiMap.end()){
312 fModuleHitMap[moduleAddress]->Fill(iCol, iRow-1);
313 fUsedDigiMap[neighbourAddress] = iDigi;
314 }
315 }
316 if (iRow < fModuleDigi->GetNofRows()-1){ // Only cross like neighbour trigger
317 if (local_Row+1 > fModuleDigi->GetNofRowsInSector(iSec)-1)
318 neighbourAddress = CbmTrdAddress::GetAddress(fLayer, CbmTrdAddress::GetModuleId(moduleAddress), iSec+1, 0, iCol);
319 else
320 neighbourAddress = CbmTrdAddress::GetAddress(fLayer, CbmTrdAddress::GetModuleId(moduleAddress), iSec, local_Row+1, iCol);
321 if (fUsedDigiMap.find(neighbourAddress) == fUsedDigiMap.end()){
322 fModuleHitMap[moduleAddress]->Fill(iCol, iRow+1);
323 fUsedDigiMap[neighbourAddress] = iDigi;
324 }
325 }
326 if (iCol > 0){
327 neighbourAddress = CbmTrdAddress::GetAddress(fLayer, CbmTrdAddress::GetModuleId(moduleAddress), iSec, local_Row, iCol-1);
328 if (fUsedDigiMap.find(neighbourAddress) == fUsedDigiMap.end()){
329 fModuleHitMap[moduleAddress]->Fill(iCol-1, iRow);
330 fUsedDigiMap[neighbourAddress] = iDigi;
331 }
332 }
333 if (iCol < fModuleDigi->GetNofColumns()-1){
334 neighbourAddress = CbmTrdAddress::GetAddress(fLayer, CbmTrdAddress::GetModuleId(moduleAddress), iSec, local_Row, iCol+1);
335 if (fUsedDigiMap.find(neighbourAddress) == fUsedDigiMap.end()){
336 fModuleHitMap[moduleAddress]->Fill(iCol+1, iRow);
337 fUsedDigiMap[neighbourAddress] = iDigi;
338 }
339 }
340 */
341 }
342 }
343 }
344}
345// ---- Register ------------------------------------------------------
346void CbmTrdHitDensityQa::Register() { cout << " * CbmTrdHitDensityQa * :: Register()" << endl; }
347// --------------------------------------------------------------------
348
349
350// ---- Finish --------------------------------------------------------
352{
353 std::map<Int_t, std::pair<Int_t, TH2D*>> AsicTriggerMap;
354 std::map<Int_t, std::pair<Int_t, TH2D*>>::iterator AsicTriggerMapIt;
355 CbmTrdUtils* util = new CbmTrdUtils();
356
357 //Bool_t logScale = false;
358 Int_t nTotalAsics = 0;
359 Int_t nTotalOptLinks = 0;
360 Double_t trdTotalDataRate = 0.;
361 Double_t ratePerModule = 0;
362 TDatime time;
363 TString outfile;
364 outfile.Form("hits_per_asic.%i:%i:%i_%i.%i.%i.txt", time.GetHour(), time.GetMinute(), time.GetSecond(), time.GetDay(),
365 time.GetMonth(), time.GetYear());
366 if (fPlotResults) myfile.open(outfile, std::fstream::out);
367 //myfile << "#" << endl;
368 //myfile << "## TRD data per ASIC" << endl;
369 //myfile << "#" << endl;
370 //myfile << "#" << endl;
371 //myfile << "#--------------------------" << endl;
372
373 //Double_t min(1E3), max(max = 6E5); // Is not scaled from central to minbias
374 //if (fPlotResults) {min = 1E3; max = 2.5E5;} // scaling parameter is applied
375 std::vector<Int_t> fColors;
376 std::vector<Double_t> fZLevel;
377 for (Int_t i = 0; i < TColor::GetNumberOfColors(); i++) {
378 fColors.push_back(TColor::GetColorPalette(i));
379 if (flogScale)
380 fZLevel.push_back(fmin + TMath::Power(10, TMath::Log10(fmax - fmin) / Double_t(TColor::GetNumberOfColors()) * i));
381 else
382 fZLevel.push_back(fmin + ((fmax - fmin) / Double_t(TColor::GetNumberOfColors()) * i));
383 }
384 TString title, name;
385 std::map<Int_t, TCanvas*> LayerMap;
386 std::map<Int_t, TCanvas*>::iterator LayerMapIt;
387
389 TFile* oldFile = gFile;
390 TString origpath = gDirectory->GetPath();
391 printf("\n%s\n", origpath.Data());
392
393 TString newpath = origpath;
394 printf("fPlotResults: %i\n", (Int_t) fPlotResults);
395 if (fPlotResults) {
396 newpath = "data/result.root";
397 }
398 else {
399 newpath.ReplaceAll("eds", "hd_qa");
400 newpath.ReplaceAll(":/", "");
401 }
402 printf("\n%s\n", newpath.Data());
403 TFile* tempFile = NULL;
404 TFile* tempFileNumerator = NULL;
405 TFile* tempFileDenominator = NULL;
406 if (fPlotResults) {
407 tempFile = new TFile(newpath, "update");
408 if (fRatioTwoFiles) {
409 tempFileNumerator = new TFile("data/result_Numerator.root", "read");
410 if (NULL == tempFileNumerator) LOG(error) << "CbmTrdHitRateFastQa:: data/result_Numerator.root not found";
411 tempFileDenominator = new TFile("data/result_Denominator.root", "read");
412 if (NULL == tempFileDenominator) LOG(error) << "CbmTrdHitRateFastQa:: data/result_Denominator.root not found";
413 }
414 }
415 else
416 tempFile = new TFile(newpath, "recreate");
417 gDirectory->pwd();
418
419 if (fPlotResults)
420 fEventCounter = tempFile->Get<TH1I>("fEventCounter");
421 else
422 fEventCounter->Write("", TObject::kOverwrite);
423 if (!gDirectory->Cd("TrdHitDensityQa")) gDirectory->mkdir("TrdHitDensityQa");
424 gDirectory->Cd("TrdHitDensityQa");
425 if (!gDirectory->Cd("Module")) gDirectory->mkdir("Module");
426 gDirectory->Cd("Module");
427
428
429 Int_t moduleAddress = -1;
431 TString histName = fModuleHitMapIt->second->GetName();
432 //cout << histName << endl;
433 if (fPlotResults) {
434 if (fRatioTwoFiles) {
435 fModuleHitMapIt->second = static_cast<TH2I*>(
436 tempFileNumerator->Get<TH2I>("TrdHitDensityQa/Module/" + histName)->Clone(histName + "_numerator"));
437 // if (NULL == fModuleHitMapIt->second)
438 // LOG(error) << "CbmTrdHitRateFastQa:: data/result_Numerator.root " << histName.Data() << " not found";
439 fModuleHitMapIt->second->Scale(100);
440 // // fModuleHitMapIt->second->Scale(2);
441 fModuleHitMapIt->second->Divide(static_cast<TH2I*>(
442 tempFileDenominator->Get<TH2I>("TrdHitDensityQa/Module/" + histName)->Clone(histName + "_denominator")));
443
444 // fModuleHitMapIt->second->Divide(
445 // tempFileNumerator->Get<TH2I>("TrdHitDensityQa/Module/" + histName)->Clone(histName+"_numerator"),
446 // tempFileDenominator->Get<TH2I>("TrdHitDensityQa/Module/" + histName)->Clone(histName+"_denominator"),
447 // 1.,1.); // need to be in the kHz range, therefore 100 * 1000
448 // 1000.,1.); // need to be in the kHz range, therefore 100 * 1000
449
450 cout << histName << " " << fModuleHitMapIt->second->GetBinContent(fModuleHitMapIt->second->GetMaximumBin())
451 << endl;
452
453 // if (NULL == fModuleHitMapIt->second)
454 // LOG(error) << "CbmTrdHitRateFastQa:: data/result_Denominator.root " << histName.Data() << " not found";
455 }
456 else
457 fModuleHitMapIt->second = tempFile->Get<TH2I>("TrdHitDensityQa/Module/" + histName);
458 }
459 else
460 fModuleHitMapIt->second->Write("", TObject::kOverwrite);
461 moduleAddress = fModuleHitMapIt->first;
462 //printf("# ModuleAddress: %8i",moduleAddress);
463 //myfile << "# ModuleAddress: " << moduleAddress << endl;
464 //if (fPlotResults){
465 //util = new CbmTrdUtils();
466 //myfile << CbmTrdAddress::GetModuleId(moduleAddress) << " " << util->GetModuleType(moduleAddress,fModuleDigi,fDigiPar) << " ";
467 // }
468 ratePerModule = 0.;
469 Int_t LayerId = CbmTrdAddress::GetLayerId(moduleAddress);
470 if (LayerMap.find(LayerId) == LayerMap.end()) {
471 fStation = LayerId / 4 + 1; // OK for SIS100 and SIS300
472 fLayer = LayerId % 4 + 1; //
473 name.Form("hd_S%d_L%d", fStation, fLayer);
474 title.Form("hd Station %d, Layer %d", fStation, fLayer);
475 LayerMap[LayerId] = new TCanvas(name, title, 1000, 900);
476 name.Form("hdH_S%d_L%d", fStation, fLayer);
477 title.Form("hdH Station %d, Layer %d", fStation, fLayer);
478 TH2I* Layer = new TH2I(name, title, 1, -4000, 4000, 1, -3500, 3500);
479 Layer->SetContour(99);
480 Layer->SetXTitle("x-Coordinate [mm]");
481 Layer->SetYTitle("y-Coordinate [mm]");
482 Layer->SetZTitle("Trigger/Channel [kHz]");
483 if (fRatioTwoFiles) Layer->SetZTitle("Trigger ratio [%]");
484 Layer->SetStats(kFALSE);
485 Layer->GetXaxis()->SetLabelSize(0.02);
486 Layer->GetYaxis()->SetLabelSize(0.02);
487 Layer->GetZaxis()->SetLabelSize(0.02);
488 Layer->GetXaxis()->SetTitleSize(0.02);
489 Layer->GetXaxis()->SetTitleOffset(1.5);
490 Layer->GetYaxis()->SetTitleSize(0.02);
491 Layer->GetYaxis()->SetTitleOffset(2);
492 Layer->GetZaxis()->SetTitleSize(0.02);
493 Layer->GetZaxis()->SetTitleOffset(-2);
494 Layer->GetZaxis()->SetRangeUser(fmin / 1000, fmax / 1000);
495 if (fRatioTwoFiles) Layer->GetZaxis()->SetRangeUser(fmin, fmax);
496 LayerMap[LayerId]->cd()->SetLogz(flogScale);
497 Layer->Fill(0., 0., 0);
498 Layer->Draw("colz");
499 }
500 const Int_t nModules = fDigiPar->GetNrOfModules();
503 gGeoManager->FindNode(fModuleGeo->GetX(), fModuleGeo->GetY(), fModuleGeo->GetZ());
505 std::vector<Int_t> AsicAddresses;
506 fModuleAsic->GetAsicAddresses(&AsicAddresses);
507 Int_t nofAsics = fModuleAsic->GetNofAsics();
508 if (fPlotResults) {
509 if (AsicTriggerMap.find(nofAsics) == AsicTriggerMap.end()) {
510 name.Form("hd_ASICs%03i", nofAsics);
511 title.Form("hd_ASICs%03d_%4.1fcmx%4.1fcm_%03dx%03dpads", nofAsics, 2 * fModuleDigi->GetSizeX(),
512 2 * fModuleDigi->GetSizeY(), fModuleDigi->GetNofRows(), fModuleDigi->GetNofColumns());
513 AsicTriggerMap[nofAsics] =
514 std::make_pair(1, new TH2D(name, title, nofAsics, -0.5, nofAsics - 0.5, nModules, -0.5, nModules - 0.5));
515 AsicTriggerMap[nofAsics].second->SetContour(99);
516 AsicTriggerMap[nofAsics].second->SetXTitle("ASIC Id");
517 AsicTriggerMap[nofAsics].second->SetYTitle("module count");
518 AsicTriggerMap[nofAsics].second->SetZTitle("trigger per ASIC");
519 }
520 else {
521 AsicTriggerMap[nofAsics].first += 1;
522 }
523 }
524 //printf(" NofAsics: %3i\n",nofAsics);
525 //myfile << "# NofAsics : " << nofAsics << endl;
526 //myfile << "# moduleAddress / Asic ID / hits per 32ch Asic per second" << endl;
527 nTotalAsics += nofAsics;
528 std::map<Int_t, Double_t> ratePerAsicMap;
529 for (Int_t iAsic = 0; iAsic < nofAsics; iAsic++) {
530 ratePerAsicMap[AsicAddresses[iAsic]] = 0.;
531 }
532 const Int_t nSec = fModuleDigi->GetNofSectors();
533 Int_t global_Row = 0;
534 TVector3 padPos;
535 TVector3 padSize;
536 TBox* pad = NULL;
537 TBox* module = NULL;
538 //printf("Module: %6i Maximum Trigger Rate: %EHz/Channel\n",fModuleHitMapIt->first,fModuleHitMapIt->second->GetBinContent(fModuleHitMapIt->second->GetMaximumBin()) / Double_t(fEventCounter->GetEntries()) * fEventRate);
539 for (Int_t s = 0; s < nSec; s++) {
540 const Int_t nRow = fModuleDigi->GetNofRowsInSector(s);
541 const Int_t nCol = fModuleDigi->GetNofColumnsInSector(s);
542 for (Int_t r = 0; r < nRow; r++) {
543 for (Int_t c = 0; c < nCol; c++) {
544 fModuleDigi->GetPosition(/*fModuleHitMapIt->first, */ s, c, r, padPos,
545 padSize); // padPos local or global???
546 Int_t channelAddress = CbmTrdAddress::GetAddress(CbmTrdAddress::GetLayerId(moduleAddress),
547 CbmTrdAddress::GetModuleId(moduleAddress), s, r, c);
548 Double_t local_min[3] = {padPos[0] - 0.5 * padSize[0], padPos[1] - 0.5 * padSize[1], padPos[2]};
549 Double_t local_max[3] = {padPos[0] + 0.5 * padSize[0], padPos[1] + 0.5 * padSize[1], padPos[2]};
550 if (fModuleDigi->GetOrientation() == 1
551 || fModuleDigi->GetOrientation()
552 == 3) { // Pad size is in local coordinate system where position is in global coordinate system
553 local_min[0] = padPos[0] - 0.5 * padSize[1];
554 local_min[1] = padPos[1] - 0.5 * padSize[0];
555 local_max[0] = padPos[0] + 0.5 * padSize[1];
556 local_max[1] = padPos[1] + 0.5 * padSize[0];
557 }
558 for (Int_t i = 0; i < 3; i++) {
559 //global_min[i] *= 10.;
560 //global_max[i] *= 10.;
561 local_min[i] *= 10.;
562 local_max[i] *= 10.;
563 }
564 //Double_t rate = Double_t(fModuleHitMapIt->second->GetBinContent(c+1,global_Row+1)) / Double_t(fEventCounter->GetEntries()) * fEventRate;// *
565 Double_t rate =
566 TriggerCount2TriggerRate(Double_t(fModuleHitMapIt->second->GetBinContent(c + 1, global_Row + 1)));
567 ratePerModule += rate;
568 Int_t AsicAddress = fModuleAsic->GetAsicAddress(channelAddress);
569 ratePerAsicMap[AsicAddress] += rate;
570 if (AsicAddress < 0)
571 LOG(error) << "CbmTrdHitRateFastQa::ScanModulePlane: Channel address:" << channelAddress
572 << " is not initialized in module " << moduleAddress << "(s:" << s << ", r:" << r << ", c:" << c
573 << ")";
574
575 pad = new TBox(local_min[0], local_min[1], local_max[0], local_max[1]);
576 //printf(" %i %i %i (%f, %f) (%f, %f) %f\n",s,r,c,local_min[0],local_min[1],global_min[0],global_min[1],rate);
577 pad->SetLineColor(0);
578 pad->SetLineWidth(0);
579 // Int_t color(0), j(0);
580 Int_t j(0);
581 rate *= fScaleCentral2mBias;
582 //if (rate > min && rate <= max){
583 while ((rate > fZLevel[j]) && (j < (Int_t) fZLevel.size())) {
584 //printf (" %i<%i %i %E <= %E\n",j,(Int_t)fZLevel.size(),fColors[j], rate, fZLevel[j]);
585 j++;
586 }
587 //printf ("%i<%i %i %E <= %E\n\n",j,(Int_t)fZLevel.size(),fColors[j], rate, fZLevel[j]);
588 pad->SetFillColor(fColors[j]);
589 if (j == (Int_t) fZLevel.size()) pad->SetFillColor(12);
590 if (rate < fmin) pad->SetFillColor(17);
591
592 LayerMap[LayerId]->cd();
593 pad->Draw("same");
594 }
595 global_Row++;
596 }
597 }
598
599 module = new TBox(
600 fModuleGeo->GetX() * 10 - fModuleDigi->GetSizeX() * 10, fModuleGeo->GetY() * 10 - fModuleDigi->GetSizeY() * 10,
601 fModuleGeo->GetX() * 10 + fModuleDigi->GetSizeX() * 10, fModuleGeo->GetY() * 10 + fModuleDigi->GetSizeY() * 10);
602 module->SetFillStyle(0);
603 LayerMap[LayerId]->cd();
604 module->Draw("same");
605 delete fModuleHitMapIt->second;
606 for (Int_t iAsic = 0; iAsic < nofAsics; iAsic++) {
607 //fModuleHitASICMap[moduleAddress]->Fill(iAsic, ratePerAsicMap[AsicAddresses[iAsic]] * Double_t(fEventCounter->GetEntries()) / fEventRate);
608 fModuleHitASICMap[moduleAddress]->Fill(iAsic, TriggerRate2TriggerCount(ratePerAsicMap[AsicAddresses[iAsic]]));
609 if (fPlotResults) {
610 if (ratePerAsicMap[AsicAddresses[0]] > ratePerAsicMap[AsicAddresses[nofAsics - 1]])
611 AsicTriggerMap[nofAsics].second->SetBinContent(iAsic + 1, AsicTriggerMap[nofAsics].first,
612 ratePerAsicMap[AsicAddresses[iAsic]] * fScaleCentral2mBias);
613 else
614 AsicTriggerMap[nofAsics].second->SetBinContent(nofAsics - iAsic, AsicTriggerMap[nofAsics].first,
615 ratePerAsicMap[AsicAddresses[iAsic]] * fScaleCentral2mBias);
616 }
617 if (fPlotResults) {
618 util = new CbmTrdUtils();
619 myfile << setfill(' ') << setw(5) << moduleAddress << " " << setfill(' ') << setw(2)
620 << CbmTrdAddress::GetModuleId(moduleAddress) << " "
621 << util->GetModuleType(moduleAddress, fModuleDigi, fDigiPar) << " " << setfill('0') << setw(2) << iAsic
622 << " " << setiosflags(ios::fixed) << setprecision(0) << setfill(' ') << setw(8)
623 << ratePerAsicMap[AsicAddresses[iAsic]] << endl;
624 }
625 //Double_t dataPerAsic = ratePerAsicMap[AsicAddresses[iAsic]] * 1e-6 * fBitPerHit; // Mbit, incl. neighbor
626 //TriggerRate2DataRate(ratePerAsicMap[AsicAddresses[iAsic]]) * 1e-6; // Mbit, incl. neighbor // to be used in a later patch
627 //Double_t dataPerAsic = TriggerRate2DataRate(ratePerAsicMap[AsicAddresses[iAsic]]) * 1e-6; // Mbit, incl. neighbor
628 //HitAsic->Fill(dataPerAsic);
629 }
630 //if (fPlotResults)
631 //AsicTriggerMap[nofAsics].first +=1;
632 if (!fPlotResults) fModuleHitASICMap[moduleAddress]->Write("", TObject::kOverwrite);
633 delete fModuleHitASICMap[moduleAddress];
634 }
635 //Double_t dataPerModule = ratePerModule * 1e-6 * fBitPerHit * fScaleCentral2mBias; // Mbit, incl. neighbor
636 Double_t dataPerModule = TriggerRate2DataRate(ratePerModule) * 1e-6 * fScaleCentral2mBias; // Mbit, incl. neighbor
637 Int_t nOptLinks =
638 (Int_t)(1 + dataPerModule / 4000.); // 5000.; // 1 link plus 1 for each 4 Gbps (fill links to 80% max)
639 //h1DataModule->Fill(dataPerModule);
640 //h1OptLinksModule->Fill(nOptLinks);
641
642 // global statistics
643 nTotalOptLinks += nOptLinks;
644 trdTotalDataRate += dataPerModule;
645
646 printf(" --------------------------\n");
647 printf(" total number of ASICs : %d\n", nTotalAsics);
648 printf(" total number of optical links: %d\n", nTotalOptLinks);
649 printf(" total TRD data rate : %.2f (Gbit/s)\n", trdTotalDataRate * 1e-3);
650 printf(" --------------------------\n");
651 printf(" --------------------------\n");
652 /*
653 myfile << "# total number of ASICs: " << nTotalAsics << endl;
654 myfile << "#--------------------------" << endl;
655 myfile << "#--------------------------" << endl;
656 */
657 if (fPlotResults) myfile.close();
658 fModuleHitASICMap.clear();
659 fModuleHitMap.clear();
660 gDirectory->Cd("..");
661 if (!gDirectory->Cd("ASIC")) gDirectory->mkdir("ASIC");
662 gDirectory->Cd("ASIC");
663 if (fPlotResults) {
664 for (AsicTriggerMapIt = AsicTriggerMap.begin(); AsicTriggerMapIt != AsicTriggerMap.end(); ++AsicTriggerMapIt) {
665 AsicTriggerMapIt->second.second->GetYaxis()->SetRangeUser(-0.5, AsicTriggerMapIt->second.first - 1.5);
666 AsicTriggerMapIt->second.second->GetZaxis()->SetRangeUser(0, 8.0E6);
667 AsicTriggerMapIt->second.second->Write("", TObject::kOverwrite);
668 }
669 }
670 gDirectory->Cd("..");
671 for (LayerMapIt = LayerMap.begin(); LayerMapIt != LayerMap.end(); ++LayerMapIt) {
672 LayerMapIt->second->Write("", TObject::kOverwrite);
673 fStation = LayerMapIt->first / 4 + 1; // OK for SIS100 and SIS300
674 fLayer = LayerMapIt->first % 4 + 1; //
675 if (fPlotResults) {
676 name.Form("pics/CbmTrdHitDensityQaFinal_S%i_L%i.png", fStation, fLayer);
677 if (fRatioTwoFiles) name.Form("pics/CbmTrdHitDensityQaRatio_S%i_L%i.png", fStation, fLayer);
678 }
679 else
680 name.Form("pics/CbmTrdHitDensityQa_S%i_L%i.png", fStation, fLayer);
681 LayerMapIt->second->SaveAs(name);
682 name.ReplaceAll("png", "pdf");
683 LayerMapIt->second->SaveAs(name);
684 }
685
686 gDirectory->Cd("..");
687 tempFile->Close();
688
690 gFile = oldFile;
691 gDirectory->Cd(origpath);
692 gDirectory->pwd();
693 delete util;
694}
695
696// ----- Public method EndOfEvent --------------------------------------
698{
699 if (fClusters) {
700 fClusters->Clear("C");
701 fClusters->Delete();
702 }
703 fUsedDigiMap.clear();
704}
705// -------------------------------------------------------------------------
706
707void CbmTrdHitDensityQa::SetTriggerThreshold(Double_t triggerthreshold) { fTriggerThreshold = triggerthreshold; }
708
709Double_t CbmTrdHitDensityQa::TriggerRate2DataRate(Double_t triggerrate) { return triggerrate * fBitPerHit; }
710Double_t CbmTrdHitDensityQa::DataRate2TriggerRate(Double_t datarate) { return datarate / fBitPerHit; }
712{
713 // if (fRatioTwoFiles)
714 // return count / Double_t(fEventCounter->GetEntries());
715 return count / Double_t(fEventCounter->GetEntries()) * fEventRate;
716}
718{
719 return rate * Double_t(fEventCounter->GetEntries()) / fEventRate;
720}
ClassImp(CbmConverterManager)
@ kTrd
Transition Radiation Detector.
Data Container for TRD clusters.
Helper class to extract information from the GeoManager.
Class for hits in TRD detector.
friend fscal max(fscal x, fscal y)
friend fscal min(fscal x, fscal y)
bool first
int32_t GetDigi(int32_t index) const
Get digi at position index.
Definition CbmCluster.h:76
int32_t GetNofDigis() const
Number of digis in cluster.
Definition CbmCluster.h:69
static Int_t GetNofDigis(ECbmModuleId systemId)
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
static uint32_t GetModuleId(uint32_t address)
Return module ID from address.
static uint32_t GetSectorId(uint32_t address)
Return sector ID from address.
static uint32_t GetColumnId(uint32_t address)
Return column ID from address.
static uint32_t GetLayerId(uint32_t address)
Return layer ID from address.
static uint32_t GetModuleAddress(uint32_t address)
Return unique module ID from address.
static uint32_t GetAddress(int32_t layerId, int32_t moduleId, int32_t sectorId, int32_t rowId, int32_t columnId)
Return address from system ID, layer, module, sector, column and row IDs.
static uint32_t GetRowId(uint32_t address)
Return row ID from address.
Data Container for TRD clusters.
int32_t GetAddress() const
Address getter for module in the format defined by CbmTrdDigi (format of CbmTrdAddress can be accesse...
Definition CbmTrdDigi.h:112
double GetCharge() const
Common purpose charge getter.
void Init(Bool_t isSimulation=kFALSE)
void SetNeighbourTrigger(Bool_t trigger)
void SetRatioTwoFiles(Bool_t ratioPlot)
CbmTrdParSetGeo * fGeoPar
Double_t TriggerRate2TriggerCount(Double_t rate)
std::map< Int_t, Int_t > fUsedDigiMap
virtual void Exec(Option_t *option)
CbmTrdParSetDigi * fDigiPar
void SetTriggerMinScale(Double_t min)
CbmTrdGeoHandler * fGeoHandler
TClonesArray * fClusters
void SetPlotResults(Bool_t plotResults)
CbmTrdParSetAsic * fAsicPar
Double_t TriggerCount2TriggerRate(Double_t count)
void SetTriggerThreshold(Double_t triggerthreshold)
std::map< Int_t, TH2I * >::iterator fModuleHitMapIt
void SetLogScale(Bool_t logScale)
Double_t DataRate2TriggerRate(Double_t datarate)
std::map< Int_t, TH1D * > fModuleHitASICMap
virtual InitStatus Init()
std::map< Int_t, TH2I * > fModuleHitMap
virtual InitStatus ReInit()
void SetTriggerMaxScale(Double_t max)
Double_t TriggerRate2DataRate(Double_t triggerrate)
void SetScaleCentral2mBias(Double_t scaling)
virtual void SetParContainers()
Describe TRD module ASIC settings (electronic gain, delays, etc)
virtual void GetAsicAddresses(std::vector< Int_t > *a) const
Query the ASICs in the module for their DAQ address. It applies to the list of ASICs....
virtual int GetNofAsics() const
Returns the DEFAULT number of ASICs for the current module.
virtual Int_t GetAsicAddress(Int_t chAddress) const
Look for the ASIC which operates on a specific channel It applies to the list of ASICs.
Definition of chamber gain conversion for one TRD module.
Int_t GetNofSectors() const
void GetPosition(Int_t sectorId, Int_t columnId, Int_t rowId, TVector3 &padPos, TVector3 &padSize) const
Double_t GetSizeY() const
Int_t GetNofColumnsInSector(Int_t i) const
Int_t GetOrientation() const
Int_t GetNofRows() const
Int_t GetNofRowsInSector(Int_t i) const
Int_t GetNofColumns() const
Double_t GetSizeX() const
Int_t GetModuleRow(Int_t &sectorId, Int_t &rowId) const
Definition of geometry for one TRD module.
virtual Double_t GetZ() const
virtual Double_t GetY() const
virtual Double_t GetX() const
Describe TRD module ASIC settings (electronic gain, delays, etc)
virtual Int_t GetNrOfModules() const
virtual const CbmTrdParMod * GetModulePar(Int_t detId) const
Int_t GetModuleType(Int_t moduleAddress, CbmTrdParModDigi *fModuleInfo, CbmTrdParSetDigi *fDigiPar)