Belle II Software  release-05-01-25
TOPLaserCalibratorCollectorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Umberto Tamponi (tamponi@to.infn.it) *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <top/modules/TOPLaserCalibratorCollector/TOPLaserCalibratorCollectorModule.h>
12 
13 //ROOT
14 #include <TTree.h>
15 #include <TMath.h>
16 
17 //TOP
18 #include <top/dataobjects/TOPDigit.h>
19 #include <top/dataobjects/TOPRawDigit.h>
20 #include <top/dataobjects/TOPSimHit.h>
21 
22 #include <algorithm>
23 #include <vector>
24 
25 using namespace Belle2;
26 
27 REG_MODULE(TOPLaserCalibratorCollector)
28 
30 {
31  // Set module properties
32  setDescription("Collector module for the TOP ChannelT0 calibration and the quality monitoring using laser and pulser data");
33  setPropertyFlags(c_ParallelProcessingCertified);
34 
35  addParam("useReferencePulse", m_useReferencePulse, "Use the pulser as reference", bool(false));
36  addParam("refChannel", m_refChannel, "Channel to be used as reference");
37  addParam("refSlot", m_refSlot, "Slot to be used as reference");
38  addParam("pulserDeltaT", m_pulserDeltaT, "Approximate time difference between the two calpulses, in ns", float(21.8));
39  addParam("pulserDeltaTTolerance", m_pulserDeltaTTolerance, "Window around the nominal deltaT used to select a double pulse, in ns ",
40  float(2.));
41  addParam("storeMCTruth", m_storeMCTruth, " Store the TOPSimHits information instead of the TOPDigit one. \
42  If this option is used, useReferencePulse will be automatically set to false.");
43 
44 }
45 
46 
47 
49 {
50 
51  // Create the output trees
52 
53  auto hitTree = new TTree("hitTree", "hitTree");
54  hitTree->Branch<short>("channel", &m_channel);
55  hitTree->Branch<short>("slot", &m_slot);
56  hitTree->Branch<float>("hitTime", &m_hitTime);
57  hitTree->Branch<float>("dVdt", &m_dVdt);
58  hitTree->Branch<float>("refTime", &m_refTime);
59  hitTree->Branch<float>("amplitude", &m_amplitude);
60  hitTree->Branch<float>("width", &m_width);
61  hitTree->Branch<short>("sample", &m_sample);
62  hitTree->Branch<short>("window", &m_window);
63  hitTree->Branch<int>("event", &m_event);
64  hitTree->Branch<bool>("refTimeValid", &m_refTimeValid);
65 
66  registerObject<TTree>("hitTree", hitTree);
67 
68  m_TOPDigitArray.isRequired();
69 
70  if (m_storeMCTruth)
71  m_useReferencePulse = false;
72 
73  m_event = 0;
74 }
75 
76 
80 {
81  float refTimes[16] = {0.}; // Reference time for each slot
82  std::vector<bool> refTimesValid(16, true);
83 
84  // first loop over TOPDigits to find all the pairs of digits that satisfy the double-pulse conditions
85  if (m_useReferencePulse) {
86 
87  std::vector<float> calPulseTimes[16];
88  for (const auto& digit : m_TOPDigitArray) {
89  if (digit.getHitQuality() != TOPDigit::c_CalPulse or digit.getChannel() != m_refChannel)
90  continue; // remove photons and everything not on the ref channel
91  calPulseTimes[digit.getModuleID() - 1].push_back(digit.getTime());
92  }
93 
94  for (int i = 0; i < 16; i++) {
95  refTimesValid[i] = false;
96  auto& calTimes = calPulseTimes[i];
97  if (calTimes.size() < 2) continue;
98  std::sort(calTimes.begin(), calTimes.end());
99  for (unsigned k = 0; k < calTimes.size() - 1; k++) {
100  auto t1 = calTimes[k];
101  auto t2 = calTimes[k + 1];
102  if (fabs(fabs(t2 - t1) - m_pulserDeltaT) < m_pulserDeltaTTolerance) {
103  refTimes[i] = t1;
104  refTimesValid[i] = true;
105  break;
106  }
107  }
108  }
109 
110  }
111 
112  TTree* hitTree = getObjectPtr<TTree>("hitTree");
113 
114  // then fill the tree with good digits (photons and cal pulses)
115  for (const auto& digit : m_TOPDigitArray) {
116  if (digit.getHitQuality() == TOPDigit::c_Junk) continue; // remove the bad hits
117  m_channel = digit.getChannel();
118  m_slot = digit.getModuleID(); // this is 1-based
119  m_dVdt = 0.5 * TMath::Sqrt(-2.*TMath::Log(0.5)) * digit.getPulseHeight() / digit.getPulseWidth();
120 
121  if (m_refSlot > 0) {
122  m_refTime = refTimes[m_refSlot - 1];
123  m_refTimeValid = refTimesValid[m_refSlot - 1];
124  } else {
125  m_refTime = refTimes[m_slot - 1];
126  m_refTimeValid = refTimesValid[m_slot - 1];
127  }
128 
129  m_amplitude = digit.getPulseHeight() ;
130  m_width = digit.getPulseWidth();
131 
132  if (m_storeMCTruth) {
133  const auto* simHit = digit.getRelated<TOPSimHit>();
134  if (not simHit) continue; // no tree entry if MC truth doesn't exist
135  m_hitTime = simHit->getTime();
136  } else {
137  m_hitTime = digit.getTime() - m_refTime;
138  }
139 
140  m_window = -1;
141  const auto* rawDigit = digit.getRelated<TOPRawDigit>();
142  if (rawDigit) m_window = rawDigit->getASICWindow(); // window from which the feature is extracted
143  m_sample = digit.getModulo256Sample(); // sample number refered in TBC
144  hitTree->Fill();
145  }
146  m_event++;
147 }
Belle2::TOPLaserCalibratorCollectorModule::m_storeMCTruth
bool m_storeMCTruth
Store the TOPSimHits information instead of the TOPDigit one.
Definition: TOPLaserCalibratorCollectorModule.h:71
Belle2::TOPLaserCalibratorCollectorModule::collect
void collect() override
Main mathod, called for each event.
Definition: TOPLaserCalibratorCollectorModule.cc:79
Belle2::TOPLaserCalibratorCollectorModule::m_refTime
float m_refTime
Time of the reference pulse (ns)
Definition: TOPLaserCalibratorCollectorModule.h:85
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::TOPSimHit
Class to store simulated hits of Cherenkov photons on PMT's input for digitization module (TOPDigitiz...
Definition: TOPSimHit.h:37
Belle2::TOPLaserCalibratorCollectorModule::m_sample
short m_sample
Sample number (0-???)
Definition: TOPLaserCalibratorCollectorModule.h:79
Belle2::TOPLaserCalibratorCollectorModule::m_window
short m_window
Window number (0-???)
Definition: TOPLaserCalibratorCollectorModule.h:78
Belle2::TOPLaserCalibratorCollectorModule::m_useReferencePulse
bool m_useReferencePulse
Use the electronic pulser as reference.
Definition: TOPLaserCalibratorCollectorModule.h:66
Belle2::TOPLaserCalibratorCollectorModule::m_pulserDeltaT
float m_pulserDeltaT
Approximate time difference between the two calpulses, in ns.
Definition: TOPLaserCalibratorCollectorModule.h:69
Belle2::TOPLaserCalibratorCollectorModule::m_refSlot
int m_refSlot
Reference slot (1-16).
Definition: TOPLaserCalibratorCollectorModule.h:68
Belle2::TOPLaserCalibratorCollectorModule
Collector module for the TOP channelT0 calibration and, more in general, for the time resolution stud...
Definition: TOPLaserCalibratorCollectorModule.h:39
Belle2::TOPLaserCalibratorCollectorModule::m_width
float m_width
Hit pulse width (ns)
Definition: TOPLaserCalibratorCollectorModule.h:84
Belle2::TOPLaserCalibratorCollectorModule::m_amplitude
float m_amplitude
Hit pulse amplitude (ADC)
Definition: TOPLaserCalibratorCollectorModule.h:83
Belle2::TOPLaserCalibratorCollectorModule::m_refChannel
unsigned m_refChannel
Reference channel.
Definition: TOPLaserCalibratorCollectorModule.h:67
Belle2::TOPRawDigit
Class to store unpacked raw data (hits in feature-extraction format) It provides also calculation of ...
Definition: TOPRawDigit.h:34
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TOPLaserCalibratorCollectorModule::m_event
int m_event
Consecutive event count.
Definition: TOPLaserCalibratorCollectorModule.h:86
Belle2::TOPLaserCalibratorCollectorModule::m_TOPDigitArray
StoreArray< TOPDigit > m_TOPDigitArray
Required input array of TOPDigits.
Definition: TOPLaserCalibratorCollectorModule.h:74
Belle2::TOPLaserCalibratorCollectorModule::m_pulserDeltaTTolerance
float m_pulserDeltaTTolerance
Window around the nominal deltaT used to select a double pulse, in ns.
Definition: TOPLaserCalibratorCollectorModule.h:70
Belle2::TOPLaserCalibratorCollectorModule::m_dVdt
float m_dVdt
Approximate dV/dt (ADC/ns)
Definition: TOPLaserCalibratorCollectorModule.h:82
Belle2::TOPLaserCalibratorCollectorModule::m_hitTime
float m_hitTime
Hit time with respect to the reference pulse (ns)
Definition: TOPLaserCalibratorCollectorModule.h:81
Belle2::TOPLaserCalibratorCollectorModule::prepare
void prepare() override
Define histograms.
Definition: TOPLaserCalibratorCollectorModule.cc:48
Belle2::TOPLaserCalibratorCollectorModule::m_slot
short m_slot
Slot number (1-16)
Definition: TOPLaserCalibratorCollectorModule.h:80
Belle2::TOPLaserCalibratorCollectorModule::m_refTimeValid
bool m_refTimeValid
true when the time of the reference pulse is valid
Definition: TOPLaserCalibratorCollectorModule.h:87
Belle2::TOPLaserCalibratorCollectorModule::m_channel
short m_channel
Channel number (0-511)
Definition: TOPLaserCalibratorCollectorModule.h:77