16 #include "FairLogger.h"
17 #include "FairRootManager.h"
18 #include "FairRunAna.h"
19 #include "FairRuntimeDb.h"
22 #include "TClonesArray.h"
25 #include "TDirectory.h"
27 #include "TGeoManager.h"
38 #include "TStopwatch.h"
54 using std::setiosflags;
55 using std::setprecision;
65 Double_t ScaleCentral2mBias)
66 : FairTask(
"CbmTrdHitDensityQa", 1)
73 , h1OptLinksModule(NULL)
74 , fNeighbourTrigger(true)
76 , fRatioTwoFiles(false)
86 , fTriggerThreshold(TriggerThreshold)
87 , fEventRate(EventRate)
88 , fScaleCentral2mBias(ScaleCentral2mBias)
93 , fModuleHitASICMapIt() {}
109 FairRunAna* ana = FairRunAna::Instance();
110 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
111 cout <<
" * CbmTrdHitDensityQa * :: SetParContainers()" << endl;
118 cout <<
" * CbmTrdHitDensityQa * :: ReInit()" << endl;
128 cout <<
" * CbmTrdHitDensityQa * :: Init()" << endl;
129 FairRootManager* ioman = FairRootManager::Instance();
135 fClusters = (TClonesArray*) ioman->GetObject(
"TrdCluster");
137 cout <<
"-W CbmTrdHitDensityQa::Init: No TrdCluster array!" << endl;
138 cout <<
" Task will be inactive" << endl;
170 printf(
"\nCbmTrdHitDensityQa::Init: NeighbourTrigger %i\n\n",
173 fEventCounter =
new TH1I(
"fEventCounter",
"fEventCounter", 1, -0.5, 0.5);
198 printf(
"=================CbmTrdHitDensityQa====================\n");
212 printf(
"\n Event: %i\n\n", (Int_t)
fEventCounter->GetEntries());
217 Int_t nCluster =
fClusters->GetEntries();
218 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
223 for (Int_t iDigi = 0; iDigi < nDigisInCluster; iDigi++) {
236 title.Form(
"hd_Module_%i", moduleAddress);
240 title, title, nCols, -0.5, nCols - 0.5, nRows, -0.5, nRows - 0.5);
247 title.Form(
"hd_Module_%i_ASIC", moduleAddress);
261 Int_t iRow = fModuleDigi->
GetModuleRow(iSec, local_Row);
274 for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
287 title.Form(
"hd_Module_%i", moduleAddress);
291 title, title, nCols, -0.5, nCols - 0.5, nRows, -0.5, nRows - 0.5);
298 title.Form(
"hd_Module_%i_ASIC", moduleAddress);
312 Int_t iRow = fModuleDigi->
GetModuleRow(iSec, local_Row);
361 cout <<
" * CbmTrdHitDensityQa * :: Register()" << endl;
368 std::map<Int_t, std::pair<Int_t, TH2D*>> AsicTriggerMap;
369 std::map<Int_t, std::pair<Int_t, TH2D*>>::iterator AsicTriggerMapIt;
373 Int_t nTotalAsics = 0;
374 Int_t nTotalOptLinks = 0;
375 Double_t trdTotalDataRate = 0.;
376 Double_t ratePerModule = 0;
379 outfile.Form(
"hits_per_asic.%i:%i:%i_%i.%i.%i.txt",
395 std::vector<Int_t> fColors;
396 std::vector<Double_t> fZLevel;
397 for (Int_t
i = 0;
i < TColor::GetNumberOfColors();
i++) {
398 fColors.push_back(TColor::GetColorPalette(
i));
400 fZLevel.push_back(
fmin
403 / Double_t(TColor::GetNumberOfColors())
407 fmin + ((
fmax -
fmin) / Double_t(TColor::GetNumberOfColors()) *
i));
410 std::map<Int_t, TCanvas*> LayerMap;
411 std::map<Int_t, TCanvas*>::iterator LayerMapIt;
412 TString origpath = gDirectory->GetPath();
413 printf(
"\n%s\n", origpath.Data());
414 TString newpath = origpath;
417 newpath =
"data/result.root";
419 newpath.ReplaceAll(
"eds",
"hd_qa");
420 newpath.ReplaceAll(
":/",
"");
422 printf(
"\n%s\n", newpath.Data());
423 TFile* tempFile = NULL;
424 TFile* tempFileNumerator = NULL;
425 TFile* tempFileDenominator = NULL;
427 tempFile =
new TFile(newpath,
"update");
429 tempFileNumerator =
new TFile(
"data/result_Numerator.root",
"read");
430 if (NULL == tempFileNumerator)
432 <<
"CbmTrdHitRateFastQa:: data/result_Numerator.root not found";
433 tempFileDenominator =
new TFile(
"data/result_Denominator.root",
"read");
434 if (NULL == tempFileDenominator)
436 <<
"CbmTrdHitRateFastQa:: data/result_Denominator.root not found";
439 tempFile =
new TFile(newpath,
"recreate");
440 gDirectory = tempFile->CurrentDirectory();
447 if (!gDirectory->Cd(
"TrdHitDensityQa")) gDirectory->mkdir(
"TrdHitDensityQa");
448 gDirectory->Cd(
"TrdHitDensityQa");
449 if (!gDirectory->Cd(
"Module")) gDirectory->mkdir(
"Module");
450 gDirectory->Cd(
"Module");
453 Int_t moduleAddress = -1;
462 (TH2I*) tempFileNumerator->Get(
"TrdHitDensityQa/Module/" + histName)
463 ->Clone(histName +
"_numerator");
469 (TH2I*) tempFileDenominator->Get(
"TrdHitDensityQa/Module/" + histName)
470 ->Clone(histName +
"_denominator"));
478 cout << histName <<
" "
487 (TH2I*) tempFile->Get(
"TrdHitDensityQa/Module/" + histName);
499 if (LayerMap.find(LayerId) == LayerMap.end()) {
504 LayerMap[LayerId] =
new TCanvas(name, title, 1000, 900);
507 TH2I* Layer =
new TH2I(name, title, 1, -4000, 4000, 1, -3500, 3500);
508 Layer->SetContour(99);
509 Layer->SetXTitle(
"x-Coordinate [mm]");
510 Layer->SetYTitle(
"y-Coordinate [mm]");
511 Layer->SetZTitle(
"Trigger/Channel [kHz]");
513 Layer->SetStats(kFALSE);
514 Layer->GetXaxis()->SetLabelSize(0.02);
515 Layer->GetYaxis()->SetLabelSize(0.02);
516 Layer->GetZaxis()->SetLabelSize(0.02);
517 Layer->GetXaxis()->SetTitleSize(0.02);
518 Layer->GetXaxis()->SetTitleOffset(1.5);
519 Layer->GetYaxis()->SetTitleSize(0.02);
520 Layer->GetYaxis()->SetTitleOffset(2);
521 Layer->GetZaxis()->SetTitleSize(0.02);
522 Layer->GetZaxis()->SetTitleOffset(-2);
523 Layer->GetZaxis()->SetRangeUser(
fmin / 1000,
fmax / 1000);
525 LayerMap[LayerId]->cd()->SetLogz(
flogScale);
526 Layer->Fill(0., 0., 0);
534 gGeoManager->FindNode(
535 fModuleGeo->
GetX(), fModuleGeo->
GetY(), fModuleGeo->
GetZ());
538 std::vector<Int_t> AsicAddresses;
542 if (AsicTriggerMap.find(nofAsics) == AsicTriggerMap.end()) {
543 name.Form(
"hd_ASICs%03i", nofAsics);
544 title.Form(
"hd_ASICs%03d_%4.1fcmx%4.1fcm_%03dx%03dpads",
550 AsicTriggerMap[nofAsics] = std::make_pair(1,
559 AsicTriggerMap[nofAsics].second->SetContour(99);
560 AsicTriggerMap[nofAsics].second->SetXTitle(
"ASIC Id");
561 AsicTriggerMap[nofAsics].second->SetYTitle(
"module count");
562 AsicTriggerMap[nofAsics].second->SetZTitle(
"trigger per ASIC");
564 AsicTriggerMap[nofAsics].first += 1;
570 nTotalAsics += nofAsics;
571 std::map<Int_t, Double_t> ratePerAsicMap;
572 for (Int_t iAsic = 0; iAsic < nofAsics; iAsic++) {
573 ratePerAsicMap[AsicAddresses[iAsic]] = 0.;
576 Int_t global_Row = 0;
582 for (Int_t s = 0; s < nSec; s++) {
585 for (Int_t r = 0; r < nRow; r++) {
586 for (Int_t c = 0; c < nCol; c++) {
592 Int_t channelAddress =
598 Double_t local_min[3] = {padPos[0] - 0.5 * padSize[0],
599 padPos[1] - 0.5 * padSize[1],
601 Double_t local_max[3] = {padPos[0] + 0.5 * padSize[0],
602 padPos[1] + 0.5 * padSize[1],
608 local_min[0] = padPos[0] - 0.5 * padSize[1];
609 local_min[1] = padPos[1] - 0.5 * padSize[0];
610 local_max[0] = padPos[0] + 0.5 * padSize[1];
611 local_max[1] = padPos[1] + 0.5 * padSize[0];
613 for (Int_t
i = 0;
i < 3;
i++) {
622 ratePerModule += rate;
624 ratePerAsicMap[AsicAddress] += rate;
627 <<
"CbmTrdHitRateFastQa::ScanModulePlane: Channel address:"
628 << channelAddress <<
" is not initialized in module "
629 << moduleAddress <<
"(s:" << s <<
", r:" << r <<
", c:" << c
633 new TBox(local_min[0], local_min[1], local_max[0], local_max[1]);
635 pad->SetLineColor(0);
636 pad->SetLineWidth(0);
641 while ((rate > fZLevel[j]) && (j < (Int_t) fZLevel.size())) {
646 pad->SetFillColor(fColors[j]);
647 if (j == (Int_t) fZLevel.size()) pad->SetFillColor(12);
648 if (rate <
fmin) pad->SetFillColor(17);
650 LayerMap[LayerId]->cd();
657 module =
new TBox(fModuleGeo->
GetX() * 10 - fModuleDigi->
GetSizeX() * 10,
660 fModuleGeo->
GetY() * 10 + fModuleDigi->
GetSizeY() * 10);
661 module->SetFillStyle(0);
662 LayerMap[LayerId]->cd();
663 module->Draw(
"same");
665 for (Int_t iAsic = 0; iAsic < nofAsics; iAsic++) {
670 if (ratePerAsicMap[AsicAddresses[0]]
671 > ratePerAsicMap[AsicAddresses[nofAsics - 1]])
672 AsicTriggerMap[nofAsics].second->SetBinContent(
674 AsicTriggerMap[nofAsics].
first,
677 AsicTriggerMap[nofAsics].second->SetBinContent(
679 AsicTriggerMap[nofAsics].
first,
684 myfile << setfill(
' ') << setw(5) << moduleAddress <<
" "
685 << setfill(
' ') << setw(2)
688 <<
" " << setfill(
'0') << setw(2) << iAsic <<
" "
689 << setiosflags(ios::fixed) << setprecision(0) << setfill(
' ')
690 << setw(8) << ratePerAsicMap[AsicAddresses[iAsic]] << endl;
706 Int_t nOptLinks = (Int_t)(
714 nTotalOptLinks += nOptLinks;
715 trdTotalDataRate += dataPerModule;
717 printf(
" --------------------------\n");
718 printf(
" total number of ASICs : %d\n", nTotalAsics);
719 printf(
" total number of optical links: %d\n", nTotalOptLinks);
720 printf(
" total TRD data rate : %.2f (Gbit/s)\n",
721 trdTotalDataRate * 1e-3);
722 printf(
" --------------------------\n");
723 printf(
" --------------------------\n");
732 gDirectory->Cd(
"..");
733 if (!gDirectory->Cd(
"ASIC")) gDirectory->mkdir(
"ASIC");
734 gDirectory->Cd(
"ASIC");
736 for (AsicTriggerMapIt = AsicTriggerMap.begin();
737 AsicTriggerMapIt != AsicTriggerMap.end();
738 ++AsicTriggerMapIt) {
739 AsicTriggerMapIt->second.second->GetYaxis()->SetRangeUser(
740 -0.5, AsicTriggerMapIt->second.first - 1.5);
741 AsicTriggerMapIt->second.second->GetZaxis()->SetRangeUser(0, 8.0E6);
742 AsicTriggerMapIt->second.second->Write(
"", TObject::kOverwrite);
745 gDirectory->Cd(
"..");
746 for (LayerMapIt = LayerMap.begin(); LayerMapIt != LayerMap.end();
748 LayerMapIt->second->Write(
"", TObject::kOverwrite);
749 fStation = LayerMapIt->first / 4 + 1;
750 fLayer = LayerMapIt->first % 4 + 1;
752 name.Form(
"pics/CbmTrdHitDensityQaFinal_S%i_L%i.png",
fStation,
fLayer);
754 name.Form(
"pics/CbmTrdHitDensityQaRatio_S%i_L%i.png",
fStation,
fLayer);
756 name.Form(
"pics/CbmTrdHitDensityQa_S%i_L%i.png",
fStation,
fLayer);
757 LayerMapIt->second->SaveAs(name);
758 name.ReplaceAll(
"png",
"pdf");
759 LayerMapIt->second->SaveAs(name);
762 gDirectory->Cd(
"..");
764 gDirectory->Cd(origpath);