Belle II Software  release-08-01-10
TOPTBCComparatorModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
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"
16 #include "TString.h"
17 #include "TFile.h"
18 #include <boost/format.hpp>
19 #include <fstream>
20 
21 using namespace std;
22 using boost::format;
23 
24 namespace Belle2 {
29  using namespace TOP;
30 
31  //-----------------------------------------------------------------
33  //-----------------------------------------------------------------
34 
35  REG_MODULE(TOPTBCComparator);
36 
37  //-----------------------------------------------------------------
38  // Implementation
39  //-----------------------------------------------------------------
40 
41  TOPTBCComparatorModule::TOPTBCComparatorModule() : HistoModule()
42  {
43  setDescription("TOP Time Base Correction monitor module ");
44 
45  addParam("inputDirectorList", m_inputDirectoryList,
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 ",
47  string(" "));
48  addParam("compareToPreviousSet", m_compareToPreviousSet,
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",
50  bool(true));
51  addParam("outputFile", m_outputFile,
52  "output file containing the monitoring plots", string("TBCComparisonResults.root"));
53  addParam("minCalPulses", m_minCalPulses,
54  "minimum number of calibration pulses need to flag a sample as non-empty", short(200));
55  addParam("numSamples", m_numSamples,
56  "number of samples that have been calibrated", short(256));
57 
58  }
59 
60 
62  {
63  // opens the file contining the list of directories and the labels
64  ifstream inputDirectoryListFile(m_inputDirectoryList.c_str());
65 
66  // checks the input file
67  if (!inputDirectoryListFile) {
68  B2ERROR("Unable to open the input file with the list of CalSets to analyze");
69  return;
70  }
71 
72  B2INFO("Initializing histograms");
73 
74 
75  std::string inputString;
76 
77  // reads the Input file line by-line to initialize the correct number of histogram sets, and reads the labels..
78  // This is effectively a loop over all the calsets.
79  while (std::getline(inputDirectoryListFile, inputString)) {
80 
81  // This initializes m_calSetDirectory and m_calSetLabel, even if now only m_calSetLabel will be used
82  parseInputDirectoryLine(inputString);
83 
84  B2INFO("Initializing histograms for Calibration set located at " << m_calSetDirectory << " with label " << m_calSetLabel);
85 
86  // To be used to initialize the histograms in the following
87  std::string name;
88  std::string title;
89 
90 
91  // ------
92  // Calset-by-calset histograms.
93  // initialize here all the histograms that appear once per calibration set, and not slot-by-slot
94  // ------
95 
96  // Average DeltaT across the whole detector
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.));
100 
101  // St.dev. of Delta T across the whole detector
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.));
105 
106  // Average occupancy agross the whole detector
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);
109  m_topSampleOccupancy.push_back(new TH1F(name.c_str(), title.c_str(), 512 * 16, 0., 512 * 16.));
110 
111 
112  // Ratio of the average DeltaT across the whole detector
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);
115  m_topAverageDeltaTComparison.push_back(new TH1F(name.c_str(), title.c_str(), 512 * 16, 0., 512 * 16.));
116 
117  // Ratio of the st.dev on DeltaT across the whole detector
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") %
120  m_calSetLabel);
121  m_topSigmaDeltaTComparison.push_back(new TH1F(name.c_str(), title.c_str(), 512 * 16, 0., 512 * 16.));
122 
123  // Ratio of the average number of calpulses across the whole detector
124  name = str(format("TOPSampleOccupancyComparison_CalSet_%1%") % m_calSetLabel);
125  title = str(
126  format("Ratio of the average number of calpulses per sample in CalSet %1% over the previous one, over the whole detector") %
127  m_calSetLabel);
128  m_topSampleOccupancyComparison.push_back(new TH1F(name.c_str(), title.c_str(), 512 * 16, 0., 512 * 16.));
129 
130 
131  // ------
132  // Slot-by-slot histograms.
133  // Use this loop to initialize all the histograms that appear once per calibration set and per each slot
134  // ------
135  for (int iSlot = 0; iSlot < 16; iSlot ++) {
136 
137  // Average DeltaT stuff
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.));
141 
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.));
145 
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);
148  m_slotAverageDeltaTMap[iSlot].push_back(new TH2F(name.c_str(), title.c_str(), 64, 0., 64., 8, 0., 8.));
149 
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.));
153 
154 
155  // Occupancy stuff
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);
158  m_slotSampleOccupancy[iSlot].push_back(new TH1F(name.c_str(), title.c_str(), 512, 0., 512.));
159 
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%") %
162  (iSlot) % m_calSetLabel % m_minCalPulses);
163  m_slotEmptySamples[iSlot].push_back(new TH1F(name.c_str(), title.c_str(), 512, 0., 512.));
164 
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%") %
167  (iSlot) % m_calSetLabel);
168  m_slotSampleOccupancyMap[iSlot].push_back(new TH2F(name.c_str(), title.c_str(), 64, 0., 64., 8, 0., 8.));
169 
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%") %
172  (iSlot) % m_calSetLabel % m_minCalPulses);
173  m_slotEmptySamplesMap[iSlot].push_back(new TH2F(name.c_str(), title.c_str(), 64, 0., 64., 8, 0., 8.));
174 
175 
176 
177  // Ratios
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);
180  m_slotAverageDeltaTComparison[iSlot].push_back(new TH1F(name.c_str(), title.c_str(), 512, 0., 512.));
181 
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);
184  m_slotSigmaDeltaTComparison[iSlot].push_back(new TH1F(name.c_str(), title.c_str(), 512, 0., 512.));
185 
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%") %
188  (iSlot) % m_calSetLabel);
189  m_slotAverageDeltaTMapComparison[iSlot].push_back(new TH2F(name.c_str(), title.c_str(), 64, 0., 64., 8, 0., 8.));
190 
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%") %
193  (iSlot) % m_calSetLabel);
194  m_slotSigmaDeltaTMapComparison[iSlot].push_back(new TH2F(name.c_str(), title.c_str(), 64, 0., 64., 8, 0., 8.));
195 
196  }
197 
198  //counts how many sets are there. To be used when doing the ratios
199  m_totCalSets++;
200  }
201  B2INFO("Initialization of the histograms for " << m_totCalSets << " CalSets done.");
202  return;
203  }
204 
205 
206 
208  {
209  // Here the histograms are filled
210  // WARNING! What root calls "RMS" is actually a standard deviation
211 
212  // Sanity check on the parsed parameters
213  if (m_slotID < 0 || m_boardstackID < 0 || m_scrodID < 0) {
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");
215  return 0;
216  }
217 
218  // Loop over all the histograms that should be found in the file
219  for (short iChannel = 0; iChannel < 128; iChannel++) {
220 
221  // Pics up one histogram just to check that the channel iChannel was actually used to calculate the calibrations
222  if (!m_calSetFile->Get(str(format("timeDiff_ch%1%") % (iChannel)).c_str())) {
223  continue;
224  }
225 
226 
227  // ---------
228  // 1) Define some channel numbering quantities
229  // Watchout: m_slotID is in [1..16] so slot m_slotID is on the element m_slotID-1 of the array
230  // ---------
231 
232  short hardwareChannel = iChannel + 128 * m_boardstackID; // 0-511 across the whole module, BS by BS
233  auto& chMapper = TOP::TOPGeometryPar::Instance()->getChannelMapper();
234  short pixelID = chMapper.getPixelID(hardwareChannel); // 1-512 across the whole module, in rows
235  short colNum = (pixelID - 1) % 64 + 1; // 1- 64 column ID (right to left looking from the quartz to the PMTs)
236  short rowNum = (pixelID - 1) / 64 + 1 ; // 1- 8 row ID (bottom to top looking from the quartz to the PMTs)
237  short globalChannel = hardwareChannel + 512 * (m_slotID -
238  1); // channel number across the whole detector, 0-8191. Used for cal monitorin only
239 
240 
241  // ---------
242  // 2) Channel-by-channel DeltaT summaries (average on the 256 samples of each set)
243  // ---------
244 
245  // Checks that the histogram needed here is not corrupted before using it
246  if (!m_calSetFile->Get(str(format("timeDiffcal_ch%1%") % (iChannel)).c_str())) {
247  B2WARNING("Error opening " << str(format("timeDiffcal_ch%1%") % (iChannel)));
248  } else {
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); // full projection
251 
252  m_slotAverageDeltaT[m_slotID - 1][m_calSetID]->SetBinContent(hardwareChannel + 1, h_projection->GetMean());
253  m_slotAverageDeltaT[m_slotID - 1][m_calSetID]->SetBinError(hardwareChannel + 1,
254  h_projection->GetMeanError()); // Do we trust root on this?
255  m_slotSigmaDeltaT[m_slotID - 1][m_calSetID]->SetBinContent(hardwareChannel + 1,
256  h_projection->GetRMS()); // WARNING! What root calls "RMS" is actually a standard deviation
257  m_slotSigmaDeltaT[m_slotID - 1][m_calSetID]->SetBinError(hardwareChannel + 1,
258  h_projection->GetRMSError()); // WARNING! What root calls "RMS" is actually a standard deviation
259 
260  m_slotAverageDeltaTMap[m_slotID - 1][m_calSetID]->SetBinContent(colNum, rowNum, h_projection->GetMean());
261  m_slotSigmaDeltaTMap[m_slotID - 1][m_calSetID]->SetBinContent(colNum, rowNum,
262  h_projection->GetRMS());
263 
264  m_topAverageDeltaT[m_calSetID]->SetBinContent(globalChannel + 1, h_projection->GetMean());
265  m_topSigmaDeltaT[m_calSetID]->SetBinContent(globalChannel + 1, h_projection->GetRMS());
266  }
267 
268  // ---------
269  // 3) Channel-by-channel average occupancy
270  // ---------
271 
272  // Checks that the histogram needed here is not corrupted before using it
273  if (!m_calSetFile->Get(str(format("sampleOccup_ch%1%") % (iChannel)).c_str())) {
274  B2WARNING("Error opening " << str(format("sampleOccup_ch%1%") % (iChannel)));
275  } else {
276  TH1F* h_sampleOccup = (TH1F*)m_calSetFile->Get(str(format("sampleOccup_ch%1%") % (iChannel)).c_str());
277 
278  // reads the occupancy histogram bin-by-by to look for (almost) empty samples
279  int nEmpty = 0;
280  for (int iSample = 1; iSample < m_numSamples + 1 ; iSample++) {
281  if (h_sampleOccup->GetBinContent(iSample) < m_minCalPulses) nEmpty++;
282  }
283 
284  m_slotSampleOccupancy[m_slotID - 1][m_calSetID]->SetBinContent(hardwareChannel + 1, h_sampleOccup->Integral() / m_numSamples);
285  m_slotEmptySamples[m_slotID - 1][m_calSetID]->SetBinContent(hardwareChannel + 1, nEmpty);
286 
287  m_slotSampleOccupancyMap[m_slotID - 1][m_calSetID]->SetBinContent(colNum, rowNum, h_sampleOccup->Integral() / m_numSamples);
288  m_slotEmptySamplesMap[m_slotID - 1][m_calSetID]->SetBinContent(colNum, rowNum, nEmpty);
289 
290  m_topSampleOccupancy[m_calSetID]->SetBinContent(globalChannel + 1, h_sampleOccup->Integral() / m_numSamples);
291 
292  }
293 
294 
295 
296  }
297  return 1;
298  }
299 
300 
302  {
303  // Set to compare with
304  short refSet = 0;
305  B2INFO("Making comparisons for " << m_totCalSets << " sets.");
306 
307  // Loop over the sets. Do not make the comparison for the set #0
308  for (int iSet = 1; iSet < m_totCalSets; iSet++) {
309  if (m_compareToPreviousSet) refSet = iSet - 1;
310 
312  m_topAverageDeltaT[refSet]);
314  m_topSigmaDeltaT[refSet]);
316  m_topSampleOccupancy[refSet]);
317 
318  // Loop over the sets. Do not make the comparison for the set #0
319  for (int iSlot = 0; iSlot < 16; iSlot++) {
321  m_slotAverageDeltaT[iSlot][iSet], m_slotAverageDeltaT[iSlot][refSet]);
323  m_slotAverageDeltaTMap[iSlot][iSet], m_slotAverageDeltaTMap[iSlot][refSet]);
325  m_slotSigmaDeltaT[iSlot][iSet], m_slotSigmaDeltaT[iSlot][refSet]);
327  m_slotSigmaDeltaTMap[iSlot][iSet], m_slotSigmaDeltaTMap[iSlot][refSet]);
328  }
329  }
330  B2INFO("Comparisons done");
331 
332  return 1;
333  }
334 
335 
337  {
338  REG_HISTOGRAM;
339  }
340 
342  {
343  return;
344  }
345 
346 
348  {
349  return;
350  }
351 
352 
353 
354  // This function takes care of looping over the root files. Unless the directory structure is changed, you should
355  // not have to touch this part
357  {
358  // opens the file containing the list of directories and the labels
359  ifstream inputDirectoryListFile(m_inputDirectoryList.c_str());
360 
361  // checsk the input file
362  if (!inputDirectoryListFile) {
363  B2ERROR("Unable to open the input file with the list of CalSets to analyze");
364  return;
365  }
366 
367  std::string inputString;
368  // reads the Input file line by-line
369  while (std::getline(inputDirectoryListFile, inputString)) {
370  // This initializes m_calSetDirectory and m_calSetLabel
371 
372  parseInputDirectoryLine(inputString);
373 
374  B2INFO("Processing the calibration set located in " << m_calSetDirectory << " and labelled " << m_calSetLabel);
375  TSystemDirectory calSetDir(m_calSetDirectory.c_str(), (m_calSetDirectory).c_str());
376 
377  // lists the content of the directory
378  TList* calSetDirContent = calSetDir.GetListOfFiles();
379  if (calSetDirContent) {
380  TSystemFile* entry;
381  TIter next(calSetDirContent);
382  while ((entry = (TSystemFile*)next())) {
383 
384  // gets the name of the entry in the list of the content of m_calSetDirectory
385  std::string entryName = entry->GetName();
386 
387  // Case 1: the entry is already a root file
388  if (!entry->IsDirectory() && TString(entryName.c_str()).EndsWith(".root")) {
389  // Initializes the file name
390  m_calSetFile = new TFile((m_calSetDirectory + entryName).c_str(), " ");
391  // Finds out the Slot and BS ID
392  int parserStatus = parseSlotAndScrodIDfromFileName(entryName);
393  // Fills the histograms
394  if (parserStatus == 1)
395  analyzeCalFile();
396  // Closes the file
397  m_calSetFile->Close();
398  }
399 
400  // Case 2: the entry is a sub-foder, containing the rootfiles
401  // The default direcotry structure is
402  // calSetDirectory/tbc_chxx/*.root,
403  // so this should be the normal case
404  if (entry->IsDirectory() && entryName != "." && entryName != "..") {
405  entryName += "/";
406  // resets the directory where to look for root files
407  TSystemDirectory calSetSubDir((m_calSetDirectory + entryName).c_str(), (m_calSetDirectory + entryName).c_str());
408 
409  // lists the content of the directory
410  TList* calSetSubDirContent = calSetSubDir.GetListOfFiles();
411  if (calSetSubDirContent) {
412  TSystemFile* file;
413  TIter nextSub(calSetSubDirContent);
414  while ((file = (TSystemFile*)nextSub())) {
415  // gets the name of the entry in the list of the content of m_calSetDirectory
416  std::string fileName = file->GetName();
417 
418  if (!file->IsDirectory() && TString(fileName.c_str()).EndsWith(".root")) {
419  // Initializes the file name
420  m_calSetFile = new TFile((m_calSetDirectory + entryName + fileName).c_str(), " ");
421  // Finds out the Slot and BS ID
422  int parserStatus = parseSlotAndScrodIDfromFileName(fileName);
423  // Fills the histograms
424  if (parserStatus == 1)
425  analyzeCalFile();
426  // Closes the file
427  m_calSetFile->Close();
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 ");
431  continue;
432  }
433 
434  }
435  }
436  }
437  }
438  } else {
439  B2WARNING("Error in creating the TList form the directory " << m_calSetDirectory);
440  continue;
441  }
442  m_calSetID++; // jump to the next directory (i.e. the next calset)
443  }
444  B2INFO("Analisys concluded.");
445 
446  makeComparisons();
447 
448  return;
449  }
450 
451 
452  // Here the histograms are saved
454  {
455  // writes the histos
456  B2INFO("Creating output file " << m_outputFile);
457  TFile outfile(m_outputFile.c_str(), "recreate");
458 
459  B2INFO("Writing histograms ");
460 
461  // opens the input list to retrive, one last time, the labels
462  ifstream inputDirectoryListFile(m_inputDirectoryList.c_str());
463  std::string inputString;
464  int iSet = 0;
465 
466  while (std::getline(inputDirectoryListFile, inputString)) {
467  parseInputDirectoryLine(inputString);
468  TDirectory* dirSet = outfile.mkdir(m_calSetLabel.c_str());
469  dirSet->cd();
470 
471  m_topAverageDeltaT[iSet]->Write();
472  m_topSigmaDeltaT[iSet]->Write();
473  m_topSampleOccupancy[iSet]->Write();
474  m_topAverageDeltaTComparison[iSet]->Write();
475  m_topSigmaDeltaTComparison[iSet]->Write();
476  m_topSampleOccupancyComparison[iSet]->Write();
477 
478  for (int iSlot = 0; iSlot < 16; iSlot ++) {
479  TDirectory* dirSlot = dirSet->mkdir(str(format("slot%1%") % (iSlot + 1)).c_str());
480  dirSlot->cd();
481 
482  m_slotAverageDeltaT[iSlot][iSet]->Write();
483  m_slotSigmaDeltaT[iSlot][iSet]->Write();
484  m_slotAverageDeltaTMap[iSlot][iSet]->Write();
485  m_slotSigmaDeltaTMap[iSlot][iSet]->Write();
486  m_slotSampleOccupancy[iSlot][iSet]->Write();
487  m_slotEmptySamples[iSlot][iSet]->Write();
488  m_slotSampleOccupancyMap[iSlot][iSet]->Write();
489  m_slotEmptySamplesMap[iSlot][iSet]->Write();
490 
491  m_slotAverageDeltaTComparison[iSlot][iSet]->Write();
492  m_slotSigmaDeltaTComparison[iSlot][iSet]->Write();
493  m_slotAverageDeltaTMapComparison[iSlot][iSet]->Write();
494  m_slotSigmaDeltaTMapComparison[iSlot][iSet]->Write();
495  }
496  dirSet->cd();
497  iSet++;
498  }
499  }
500 
501 
502 
503 
504  // -------------------------------
505  //
506  // UTILITIES
507  //
508  // -------------------------------
510  {
511  // resets the strings
512  m_calSetDirectory.clear();
513  m_calSetLabel.clear();
514 
515  // reads the string char by char to break it up in m_calSetDirectory and m_calSetLabel
516  bool isDirectoryNameChar = true;
517  bool isAtBeginning = true;
518 
519  for (std::string::size_type i = 0; i < inputString.size(); ++i) {
520  char c = inputString[i];
521  // The following ifs should catch all the possible cases
522  if (c == ' ' && isAtBeginning) continue; // and empty space at the beginning of the line
523  if (c == ' ' && !isAtBeginning) { // an empty space between the two parts
524  isDirectoryNameChar = false;
525  isAtBeginning = false;
526  continue;
527  }
528  if (c != ' ' && isDirectoryNameChar) { // a good char belonging to the first part of the string
529  m_calSetDirectory += c;
530  isAtBeginning = false;
531  continue;
532  }
533  if (c != ' ' && !isDirectoryNameChar) { // a good char belonging to the second part of the string
534  m_calSetLabel += c;
535  isAtBeginning = false;
536  continue;
537  }
538  B2WARNING("Uncaught exception in parsing the input string. Ending the parsing."); // I should never reach thispoint
539  return 0;
540  }
541 
542  return 1;
543  }
544 
545 
546 
548  {
549  // resets the IDs
550  m_slotID = -1;
551  m_boardstackID = -1;
552  m_scrodID = -1;
553 
554  // reads the string char by char to break it up in m_calSetDirectory and m_calSetLabel
555 
556 
557  std::string stringSlot = "";
558  std::string stringBS = "";
559  std::string stringScrod = "";
560 
561 
562  // We may eventually implement a more clever parsere that is not so sensitive to the file name...
563  //
564  // tbcSlotXX_Y-scrodZZZ.root
565  // tbcSlotXX_Y-scrodZZ.root
566  // 012345678901234567890
567  //
568 
569  if (!(inputString[0] == 't' && inputString[1] == 'b' && inputString[2] == 'c')) {
570  B2WARNING(inputString << " is not a valid TBC file. Skipping it.");
571  return 0;
572  }
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];
580 
581 
582  m_slotID = std::stoi(stringSlot);
583  m_scrodID = std::stoi(stringScrod);
584  m_boardstackID = std::stoi(stringBS);
585 
586  return 1;
587  }
588 
589 
590 
591  TH1F* TOPTBCComparatorModule::calculateHistoRatio(TH1F* hRatio, TH1F* hNum, TH1F* hDen)
592  {
593  // Saves the name and titple of the output histogram, as defined in defineHisto
594  const char* name = hRatio->GetName();
595  const char* title = hRatio->GetTitle();
596 
597  const char* xAxisTitle = hRatio->GetXaxis()->GetTitle();
598  const char* yAxisTitle = hRatio->GetYaxis()->GetTitle();
599 
600  // clone the numerator histogram into the output one
601  hRatio = (TH1F*)hNum->Clone();
602 
603 
604  // makes the ratio
605  hRatio->Divide(hDen);
606 
607  //ri-sets name, title and axis labels
608  hRatio->SetName(name);
609  hRatio->SetTitle(title);
610  hRatio->GetXaxis()->SetTitle(xAxisTitle);
611  hRatio->GetYaxis()->SetTitle(yAxisTitle);
612  return hRatio;
613  }
614 
615  TH2F* TOPTBCComparatorModule::calculateHistoRatio(TH2F* hRatio, TH2F* hNum, TH2F* hDen)
616  {
617  // Saves the name and titple of the output histogram, as defined in defineHisto
618  const char* name = hRatio->GetName();
619  const char* title = hRatio->GetTitle();
620 
621  const char* xAxisTitle = hRatio->GetXaxis()->GetTitle();
622  const char* yAxisTitle = hRatio->GetYaxis()->GetTitle();
623 
624  // clone the numerator histogram into the output one
625  hRatio = (TH2F*)hNum->Clone();
626 
627 
628  // makes the ratio
629  hRatio->Divide(hDen);
630 
631  //ri-sets name, title and axis labels
632  hRatio->SetName(name);
633  hRatio->SetTitle(title);
634  hRatio->GetXaxis()->SetTitle(xAxisTitle);
635  hRatio->GetYaxis()->SetTitle(yAxisTitle);
636  return hRatio;
637  }
638 
639 
641 } // end Belle2 namespace
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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)
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
const ChannelMapper & getChannelMapper() const
Returns default channel mapper (mapping of channels to pixels)
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
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...
void defineHisto() override
Defining the histograms.
Abstract base class for different kinds of events.