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 =
static_cast<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 =
static_cast<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");
349 if (!inputDirectoryListFile) {
350 B2ERROR(
"Unable to open the input file with the list of CalSets to analyze");
354 std::string inputString;
356 while (std::getline(inputDirectoryListFile, inputString)) {
365 TList* calSetDirContent = calSetDir.GetListOfFiles();
366 if (calSetDirContent) {
368 TIter next(calSetDirContent);
369 while ((entry =
static_cast<TSystemFile*
>(next()))) {
372 std::string entryName = entry->GetName();
375 if (!entry->IsDirectory() && TString(entryName.c_str()).EndsWith(
".root")) {
381 if (parserStatus == 1)
391 if (entry->IsDirectory() && entryName !=
"." && entryName !=
"..") {
397 TList* calSetSubDirContent = calSetSubDir.GetListOfFiles();
398 if (calSetSubDirContent) {
400 TIter nextSub(calSetSubDirContent);
401 while ((file =
static_cast<TSystemFile*
>(nextSub()))) {
403 std::string fileName = file->GetName();
405 if (!file->IsDirectory() && TString(fileName.c_str()).EndsWith(
".root")) {
411 if (parserStatus == 1)
415 }
else if (file->IsDirectory() && fileName !=
"." && fileName !=
"..") {
416 B2WARNING(
"Additional subdirectory " << fileName <<
" found in " <<
m_calSetDirectory + entryName <<
417 ", where only .root and .log files are expected ");
426 B2WARNING(
"Error in creating the TList form the directory " <<
m_calSetDirectory);
431 B2INFO(
"Analysis concluded.");
446 B2INFO(
"Writing histograms ");
450 std::string inputString;
453 while (std::getline(inputDirectoryListFile, inputString)) {
465 for (
int iSlot = 0; iSlot < 16; iSlot ++) {
466 TDirectory* dirSlot = dirSet->mkdir(str(format(
"slot%1%") % (iSlot + 1)).c_str());
503 bool isDirectoryNameChar =
true;
504 bool isAtBeginning =
true;
506 for (std::string::size_type i = 0; i < inputString.size(); ++i) {
507 char c = inputString[i];
509 if (c ==
' ' && isAtBeginning)
continue;
510 if (c ==
' ' && !isAtBeginning) {
511 isDirectoryNameChar =
false;
512 isAtBeginning =
false;
515 if (c !=
' ' && isDirectoryNameChar) {
517 isAtBeginning =
false;
520 if (c !=
' ' && !isDirectoryNameChar) {
522 isAtBeginning =
false;
525 B2WARNING(
"Uncaught exception in parsing the input string. Ending the parsing.");
544 std::string stringSlot =
"";
545 std::string stringBS =
"";
546 std::string stringScrod =
"";
556 if (!(inputString[0] ==
't' && inputString[1] ==
'b' && inputString[2] ==
'c')) {
557 B2WARNING(inputString <<
" is not a valid TBC file. Skipping it.");
560 stringSlot += inputString[7];
561 stringSlot += inputString[8];
562 stringBS += inputString[10];
563 stringScrod += inputString[17];
564 stringScrod += inputString[18];
565 if (inputString[19] !=
'.')
566 stringScrod += inputString[19];
581 const char* name = hRatio->GetName();
582 const char* title = hRatio->GetTitle();
584 const char* xAxisTitle = hRatio->GetXaxis()->GetTitle();
585 const char* yAxisTitle = hRatio->GetYaxis()->GetTitle();
588 hRatio =
static_cast<TH1F*
>(hNum->Clone());
592 hRatio->Divide(hDen);
595 hRatio->SetName(name);
596 hRatio->SetTitle(title);
597 hRatio->GetXaxis()->SetTitle(xAxisTitle);
598 hRatio->GetYaxis()->SetTitle(yAxisTitle);
605 const char* name = hRatio->GetName();
606 const char* title = hRatio->GetTitle();
608 const char* xAxisTitle = hRatio->GetXaxis()->GetTitle();
609 const char* yAxisTitle = hRatio->GetYaxis()->GetTitle();
612 hRatio =
static_cast<TH2F*
>(hNum->Clone());
616 hRatio->Divide(hDen);
619 hRatio->SetName(name);
620 hRatio->SetTitle(title);
621 hRatio->GetXaxis()->SetTitle(xAxisTitle);
622 hRatio->GetYaxis()->SetTitle(yAxisTitle);
HistoModule()
Constructor.
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 calibration 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 calibration 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 calibration pulses) distribution,...
std::vector< TH1F * > m_topSigmaDeltaT
Standard deviation of the DeltaT (time difference petween the calibration pulses) distribution,...
std::vector< TH2F * > m_slotAverageDeltaTMap[16]
Map of the average of the DeltaT (time difference petween the calibration 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 calibration 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 calibration 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 calibration 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 calibration 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 calibration pulses) distribution,...
std::vector< TH2F * > m_slotSigmaDeltaTMap[16]
Map of the Standard deviation of the DeltaT (time difference petween the calibration pulses) distribu...
std::vector< TH1F * > m_topAverageDeltaT
Average of the DeltaT (time difference petween the calibration 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 makeComparisons()
Last function to be called, compared the histograms of different datasets filled by analyzeCalFile() ...
void initialize() override
Initialize the module.
int parseInputDirectoryLine(const std::string &)
Utility function to get the directory name and the label from a line of the m_inputDirectoryList file...
void endRun() override
End-of-run action.
void terminate() override
Termination action.
int analyzeCalFile()
Analyzes the calibrations stored in the file m_calSetFile.
TH1F * calculateHistoRatio(TH1F *, TH1F *, TH1F *)
Utility function to take the ratio of two histograms using TH1::Divide(), without overwriting the out...
TOPTBCComparatorModule()
Constructor.
int parseSlotAndScrodIDfromFileName(const std::string &)
Utility function to parse the slot and BS id from the calibration file names.
void defineHisto() override
Defining the histograms.
Abstract base class for different kinds of events.