9#include <framework/core/HistoModule.h>
10#include <top/modules/TOPTBCComparator/TOPTBCComparatorModule.h>
11#include <top/geometry/TOPGeometryPar.h>
12#include <top/geometry/FrontEndMapper.h>
13#include "TDirectory.h"
14#include "TSystemDirectory.h"
15#include "TSystemFile.h"
18#include <boost/format.hpp>
46 "List of the directories (one per IOV) in which the files with the calibration constants of the SCODS are stored. The format of each line must be: folderpath/ label ",
49 "If true, each CalSet is compared to the previous one in the order determined by the inputDirectorList file. If false, the reference CalSet is the first of the list",
52 "output file containing the monitoring plots",
string(
"TBCComparisonResults.root"));
54 "minimum number of calibration pulses need to flag a sample as non-empty",
short(200));
56 "number of samples that have been calibrated",
short(256));
67 if (!inputDirectoryListFile) {
68 B2ERROR(
"Unable to open the input file with the list of CalSets to analyze");
72 B2INFO(
"Initializing histograms");
75 std::string inputString;
79 while (std::getline(inputDirectoryListFile, inputString)) {
97 name = str(format(
"TOPAverageDeltaT_CalSet_%1%") %
m_calSetLabel);
98 title = str(format(
"Average value of #Delta T VS global channel number. CalSet %1%") %
m_calSetLabel);
99 m_topAverageDeltaT.push_back(
new TH1F(name.c_str(), title.c_str(), 512 * 16, 0., 512 * 16.));
102 name = str(format(
"TOPSigmaDeltaT_CalSet_%1%") %
m_calSetLabel);
103 title = str(format(
"Sigma value of #Delta T VS global channel number. CalSet %1%") %
m_calSetLabel);
104 m_topSigmaDeltaT.push_back(
new TH1F(name.c_str(), title.c_str(), 512 * 16, 0., 512 * 16.));
107 name = str(format(
"TOPSampleOccupancy_CalSet_%1%") %
m_calSetLabel);
108 title = str(format(
"Average number of calpulses per sample VS global channel number. CalSet %1%") %
m_calSetLabel);
113 name = str(format(
"TOPAverageDeltaTComparison_CalSet_%1%") %
m_calSetLabel);
114 title = str(format(
"Ratio of the average #Delta T in CalSet %1% over the previous one, over the whole detector") %
m_calSetLabel);
118 name = str(format(
"TOPSigmaDeltaTComparison_CalSet_%1%") %
m_calSetLabel);
119 title = str(format(
"Ratio of the st. dev. of #Delta T in CalSet %1% over the previous one, , over the whole detector") %
124 name = str(format(
"TOPSampleOccupancyComparison_CalSet_%1%") %
m_calSetLabel);
126 format(
"Ratio of the average number of calpulses per sample in CalSet %1% over the previous one, over the whole detector") %
135 for (
int iSlot = 0; iSlot < 16; iSlot ++) {
138 name = str(format(
"SlotAverageDeltaT_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
139 title = str(format(
"Average value of #Delta T VS Channel number. Slot %1%, CalSet %2%") % (iSlot) %
m_calSetLabel);
140 m_slotAverageDeltaT[iSlot].push_back(
new TH1F(name.c_str(), title.c_str(), 512, 0., 512.));
142 name = str(format(
"SlotSigmaDeltaT_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
143 title = str(format(
"Standard deviation of #Delta T VS Channel number. Slot %1%, CalSet %2%") % (iSlot) %
m_calSetLabel);
144 m_slotSigmaDeltaT[iSlot].push_back(
new TH1F(name.c_str(), title.c_str(), 512, 0., 512.));
146 name = str(format(
"SlotAverageDeltaTMap_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
147 title = str(format(
"Map of the average value of #Delta T on the 256 samples. Slot %1%, CalSet %2%") % (iSlot) %
m_calSetLabel);
150 name = str(format(
"SlotSigmaDeltaTMap_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
151 title = str(format(
"Map of the RMS of #Delta T on the 256 samples . Slot %1%, CalSet %2%") % (iSlot) %
m_calSetLabel);
152 m_slotSigmaDeltaTMap[iSlot].push_back(
new TH2F(name.c_str(), title.c_str(), 64, 0., 64., 8, 0., 8.));
156 name = str(format(
"SlotSampleOccupancy_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
157 title = str(format(
"Average occupancy per sample. Slot %1%, CalSet %2%") % (iSlot) %
m_calSetLabel);
160 name = str(format(
"SlotEmptySamples_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
161 title = str(format(
"Number samples with less than %3% calpulses per each slot channel. Slot %1%, CalSet %2%") %
163 m_slotEmptySamples[iSlot].push_back(
new TH1F(name.c_str(), title.c_str(), 512, 0., 512.));
165 name = str(format(
"SlotSampleOccupancyMap_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
166 title = str(format(
"Map of the average occupancy per sample. Slot %1%, CalSet %2%") %
170 name = str(format(
"SlotEmptySamplesMap_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
171 title = str(format(
"Map of the number samples with less than %3% calpulses per each. Slot %1%, CalSet %2%") %
173 m_slotEmptySamplesMap[iSlot].push_back(
new TH2F(name.c_str(), title.c_str(), 64, 0., 64., 8, 0., 8.));
178 name = str(format(
"SlotAverageDeltaTComparison_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
179 title = str(format(
"Ratio of the average #Delta T in CalSet %2% over the previous one. Slot %1%") % (iSlot) %
m_calSetLabel);
182 name = str(format(
"SlotRMSDeltaTComparison_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
183 title = str(format(
"Ratio of the RMS of #Delta T in CalSet %2% over the previous one. Slot %1%") % (iSlot) %
m_calSetLabel);
186 name = str(format(
"SlotAverageDeltaTMapComparison_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
187 title = str(format(
"Map of the ratio of the average #Delta T in CalSet %2% over the previous one. Slot %1%") %
191 name = str(format(
"SlotRMSDeltaTMapComparison_Slot%1%_CalSet_%2%") % (iSlot) %
m_calSetLabel);
192 title = str(format(
"Map of the ratio of the RMS of #Delta T in CalSet %2% over the previous one. Slot %1%") %
201 B2INFO(
"Initialization of the histograms for " <<
m_totCalSets <<
" CalSets done.");
214 B2WARNING(
"Negative slot, BS or scrod ID found while calling analyzeCalFile(). Looks like they have not been initialized, or that a function re-initialized them");
219 for (
short iChannel = 0; iChannel < 128; iChannel++) {
222 if (!
m_calSetFile->Get(str(format(
"timeDiff_ch%1%") % (iChannel)).c_str())) {
234 short pixelID = chMapper.
getPixelID(hardwareChannel);
235 short colNum = (pixelID - 1) % 64 + 1;
236 short rowNum = (pixelID - 1) / 64 + 1 ;
237 short globalChannel = hardwareChannel + 512 * (
m_slotID -
246 if (!
m_calSetFile->Get(str(format(
"timeDiffcal_ch%1%") % (iChannel)).c_str())) {
247 B2WARNING(
"Error opening " << str(format(
"timeDiffcal_ch%1%") % (iChannel)));
249 TH2F* h_timeDiffcal = (TH2F*)
m_calSetFile->Get(str(format(
"timeDiffcal_ch%1%") % (iChannel)).c_str());
250 TH1D* h_projection = h_timeDiffcal->ProjectionY(
"h_projection", 1,
m_numSamples);
254 h_projection->GetMeanError());
256 h_projection->GetRMS());
258 h_projection->GetRMSError());
262 h_projection->GetRMS());
273 if (!
m_calSetFile->Get(str(format(
"sampleOccup_ch%1%") % (iChannel)).c_str())) {
274 B2WARNING(
"Error opening " << str(format(
"sampleOccup_ch%1%") % (iChannel)));
276 TH1F* h_sampleOccup = (TH1F*)
m_calSetFile->Get(str(format(
"sampleOccup_ch%1%") % (iChannel)).c_str());
280 for (
int iSample = 1; iSample <
m_numSamples + 1 ; iSample++) {
281 if (h_sampleOccup->GetBinContent(iSample) <
m_minCalPulses) nEmpty++;
305 B2INFO(
"Making comparisons for " <<
m_totCalSets <<
" sets.");
319 for (
int iSlot = 0; iSlot < 16; iSlot++) {
330 B2INFO(
"Comparisons done");
362 if (!inputDirectoryListFile) {
363 B2ERROR(
"Unable to open the input file with the list of CalSets to analyze");
367 std::string inputString;
369 while (std::getline(inputDirectoryListFile, inputString)) {
378 TList* calSetDirContent = calSetDir.GetListOfFiles();
379 if (calSetDirContent) {
381 TIter next(calSetDirContent);
382 while ((entry = (TSystemFile*)next())) {
385 std::string entryName = entry->GetName();
388 if (!entry->IsDirectory() && TString(entryName.c_str()).EndsWith(
".root")) {
394 if (parserStatus == 1)
404 if (entry->IsDirectory() && entryName !=
"." && entryName !=
"..") {
410 TList* calSetSubDirContent = calSetSubDir.GetListOfFiles();
411 if (calSetSubDirContent) {
413 TIter nextSub(calSetSubDirContent);
414 while ((file = (TSystemFile*)nextSub())) {
416 std::string fileName = file->GetName();
418 if (!file->IsDirectory() && TString(fileName.c_str()).EndsWith(
".root")) {
424 if (parserStatus == 1)
428 }
else if (file->IsDirectory() && fileName !=
"." && fileName !=
"..") {
429 B2WARNING(
"Additional subdirectory " << fileName <<
" found in " <<
m_calSetDirectory + entryName <<
430 ", where only .root and .log files are expected ");
439 B2WARNING(
"Error in creating the TList form the directory " <<
m_calSetDirectory);
444 B2INFO(
"Analisys concluded.");
459 B2INFO(
"Writing histograms ");
463 std::string inputString;
466 while (std::getline(inputDirectoryListFile, inputString)) {
478 for (
int iSlot = 0; iSlot < 16; iSlot ++) {
479 TDirectory* dirSlot = dirSet->mkdir(str(format(
"slot%1%") % (iSlot + 1)).c_str());
516 bool isDirectoryNameChar =
true;
517 bool isAtBeginning =
true;
519 for (std::string::size_type i = 0; i < inputString.size(); ++i) {
520 char c = inputString[i];
522 if (c ==
' ' && isAtBeginning)
continue;
523 if (c ==
' ' && !isAtBeginning) {
524 isDirectoryNameChar =
false;
525 isAtBeginning =
false;
528 if (c !=
' ' && isDirectoryNameChar) {
530 isAtBeginning =
false;
533 if (c !=
' ' && !isDirectoryNameChar) {
535 isAtBeginning =
false;
538 B2WARNING(
"Uncaught exception in parsing the input string. Ending the parsing.");
557 std::string stringSlot =
"";
558 std::string stringBS =
"";
559 std::string stringScrod =
"";
569 if (!(inputString[0] ==
't' && inputString[1] ==
'b' && inputString[2] ==
'c')) {
570 B2WARNING(inputString <<
" is not a valid TBC file. Skipping it.");
573 stringSlot += inputString[7];
574 stringSlot += inputString[8];
575 stringBS += inputString[10];
576 stringScrod += inputString[17];
577 stringScrod += inputString[18];
578 if (inputString[19] !=
'.')
579 stringScrod += inputString[19];
594 const char* name = hRatio->GetName();
595 const char* title = hRatio->GetTitle();
597 const char* xAxisTitle = hRatio->GetXaxis()->GetTitle();
598 const char* yAxisTitle = hRatio->GetYaxis()->GetTitle();
601 hRatio = (TH1F*)hNum->Clone();
605 hRatio->Divide(hDen);
608 hRatio->SetName(name);
609 hRatio->SetTitle(title);
610 hRatio->GetXaxis()->SetTitle(xAxisTitle);
611 hRatio->GetYaxis()->SetTitle(yAxisTitle);
618 const char* name = hRatio->GetName();
619 const char* title = hRatio->GetTitle();
621 const char* xAxisTitle = hRatio->GetXaxis()->GetTitle();
622 const char* yAxisTitle = hRatio->GetYaxis()->GetTitle();
625 hRatio = (TH2F*)hNum->Clone();
629 hRatio->Divide(hDen);
632 hRatio->SetName(name);
633 hRatio->SetTitle(title);
634 hRatio->GetXaxis()->SetTitle(xAxisTitle);
635 hRatio->GetYaxis()->SetTitle(yAxisTitle);
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
void setDescription(const std::string &description)
Sets the description of the module.
short m_boardstackID
ID of the slot whose calibrations are being analyzed.
std::vector< TH1F * > m_topAverageDeltaTComparison
Average of the DeltaT (time difference petween the calibraiton pulses) distribution,...
std::string m_inputDirectoryList
List of the directories (one per IOV) in which the files with the calibration constants of the SCODS ...
std::vector< TH1F * > m_slotSigmaDeltaT[16]
Standard deviation of the DeltaT (time difference petween the calibraiton pulses) distribution,...
short m_totCalSets
Total number of calibration sets, as counted int defineHistos.
std::vector< TH1F * > m_slotSampleOccupancy[16]
Average number of calpulses per sample used in the minimization, as function of the channel number.
short m_numSamples
Number of samples that have been calibrated.
std::string m_outputFile
File in which the output histograms are stored.
std::vector< TH1F * > m_topSigmaDeltaTComparison
Standard deviation of the DeltaT (time difference petween the calibraiton pulses) distribution,...
std::vector< TH1F * > m_topSigmaDeltaT
Standard deviation of the DeltaT (time difference petween the calibraiton pulses) distribution,...
std::vector< TH2F * > m_slotAverageDeltaTMap[16]
Map of the average of the DeltaT (time difference petween the calibraiton pulses) distribution.
std::string m_calSetDirectory
Label to be used to indetify the histograms of a the calibration set.
std::vector< TH2F * > m_slotAverageDeltaTMapComparison[16]
Map of the Ratio of the average DeltaT (time difference petween the calibraiton pulses)
bool m_compareToPreviousSet
Determines if the reverence set for the ratio is the first CalSet of the list (if false) or if each C...
std::vector< TH1F * > m_topSampleOccupancy
Average number of calpulses per sample used in the minimization, as function of the channel number on...
short m_calSetID
Internal ID of the calibration set that is being analyzed.
std::vector< TH2F * > m_slotSigmaDeltaTMapComparison[16]
Map of Ratio of the Standard deviation on DeltaT (time difference petween the calibraiton pulses)
TFile * m_calSetFile
File containing the calibration constants of the SCROD being analyzed.
std::vector< TH1F * > m_slotEmptySamples[16]
Number of (semi-)empty samples in each channel.
short m_slotID
ID of the slot whose calibrations are being analyzed.
short m_minCalPulses
Minimum number of calpulses to declare a sample as non-empty.
std::vector< TH1F * > m_slotSigmaDeltaTComparison[16]
Ratio of the Standard deviation of the DeltaT (time difference petween the calibraiton pulses) distri...
std::vector< TH1F * > m_topSampleOccupancyComparison
Ratios of the average sample occupancy on the whole detector.
std::string m_calSetLabel
Label to be used to identify the histograms of a the calibration set.
std::vector< TH1F * > m_slotAverageDeltaT[16]
Average of the DeltaT (time difference petween the calibraiton pulses) distribution,...
short m_scrodID
ID of the scrod whose calibrations are being analyzed.
std::vector< TH2F * > m_slotEmptySamplesMap[16]
Map of the number of (semi-)empty samples.
std::vector< TH1F * > m_slotAverageDeltaTComparison[16]
Ratio of the average of the DeltaT (time difference petween the calibraiton pulses) distribution,...
std::vector< TH2F * > m_slotSigmaDeltaTMap[16]
Map of the Standard deviation of the DeltaT (time difference petween the calibraiton pulses) distribu...
std::vector< TH1F * > m_topAverageDeltaT
Average of the DeltaT (time difference petween the calibraiton pulses) distribution,...
std::vector< TH2F * > m_slotSampleOccupancyMap[16]
Map of the average number of calpulses per sample used in the minimizat on.
int getPixelID(unsigned channel) const
Converts hardware channel number to pixel ID (1-based)
const ChannelMapper & getChannelMapper() const
Returns default channel mapper (mapping of channels to pixels)
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
int parseInputDirectoryLine(std::string)
Utility function to get the directory name and the label from a line of the m_inputDirectoryList file...
int makeComparisons()
Last function to be called, compared the histograms of different datasets filled by analyzeCalFile() ...
int parseSlotAndScrodIDfromFileName(std::string)
Utility function to parse the slot and BS id from the calibration file names.
void initialize() override
Initialize the module.
void event() override
Event processor.
void endRun() override
End-of-run action.
void terminate() override
Termination action.
int analyzeCalFile()
Analyzes the calibrations stored in the file m_calSetFile.
void beginRun() override
Called when entering a new run.
TH1F * calculateHistoRatio(TH1F *, TH1F *, TH1F *)
Utility function to take the ratio of two histograms using TH1::Divide(), without overwriting the out...
TOPTBCComparatorModule()
Constructor.
void defineHisto() override
Defining the histograms.
Abstract base class for different kinds of events.