Belle II Software  release-08-01-10
SVDEventT0EstimatorModule.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 <tracking/modules/eventTimeExtractor/SVDEventT0EstimatorModule.h>
10 #include <framework/datastore/RelationArray.h>
11 #include <framework/geometry/B2Vector3.h>
12 #include <tracking/dataobjects/RecoTrack.h>
13 
14 #include <cmath>
15 
16 
17 using namespace Belle2;
18 
19 //-----------------------------------------------------------------
20 // Register the Module
21 //-----------------------------------------------------------------
22 REG_MODULE(SVDEventT0Estimator);
23 
24 //-----------------------------------------------------------------
25 // Implementation
26 //-----------------------------------------------------------------
27 
29 {
30  setDescription("This module estimates the EventT0 as the average of cluster time of SVD clusters associated to tracks. The EventT0 is set to NaN if there are not RecoTracks or there are not SVD clusters associated to tracks or RecoTrack pt < ptMin OR RecoTrack pz < pzMin. The EventT0 estimated is added to the temporaryEventT0s to the StoreObjPtr as EventT0Component that cointains: eventT0, eventT0_error, detector=SVD, algorithm, quality.");
32 
33  //* Definition of input parameters */
34  addParam("RecoTracks", m_recoTracksName, "Name of the StoreArray with the input RecoTracks", std::string(""));
35  addParam("EventT0", m_eventT0Name, "Name of the StoreObjPtr with the input EventT0", std::string(""));
36  addParam("ptMinSelection", m_ptSelection, "Cut on minimum transverse momentum pt for RecoTrack selection", m_ptSelection);
37  addParam("absPzMinSelection", m_absPzSelection,
38  "Cut on minimum absolute value of the longitudinal momentum, abs(pz), for RecoTrack selection",
40 }
41 
42 
44 {
45 }
46 
47 
49 {
50  B2DEBUG(20, "RecoTracks: " << m_recoTracksName);
51  B2DEBUG(20, "EventT0: " << m_eventT0Name);
52 
54  m_eventT0.registerInDataStore();
56 }
57 
58 
60 {
61 
62  double evtT0 = std::numeric_limits<double>::quiet_NaN();
63  double evtT0Err = std::numeric_limits<double>::quiet_NaN();
64  double armTimeSum = 0;
65  double armTimeErrSum = 0;
66  double quality = std::numeric_limits<double>::quiet_NaN();
67  int numberOfSVDClusters = 0;
68  int numberOfRecoTracksUsed = 0;
69  float outgoingArmTime = 0;
70  float ingoingArmTime = 0;
71  float outgoingArmTimeError = 0;
72  float ingoingArmTimeError = 0;
73 
74  // loop on recotracks
75  for (auto& recoTrack : m_recoTracks) {
76  const B2Vector3D& p = recoTrack.getMomentumSeed();
77 
78  // selection on recoTracks
79  if (p.Perp() < m_ptSelection || std::fabs(p.Z()) < m_absPzSelection) continue;
80 
81  // use outgoing/ingoing arm time to compute SVD EventT0
82  // if both outgoing and ingoing are estimated we take the smallest one
83  // else if only outgoing or only ingoing is computed we use the only one available
84  // the probability that the ingoing arm is an outgoing arm wrongly classified is higher than the probability that it is a real ingoing arm
85  outgoingArmTime = recoTrack.getOutgoingArmTime();
86  ingoingArmTime = recoTrack.getIngoingArmTime();
87  outgoingArmTimeError = recoTrack.getOutgoingArmTimeError();
88  ingoingArmTimeError = recoTrack.getIngoingArmTimeError();
89  bool hasOutgoingArm = recoTrack.hasOutgoingArmTime();
90  bool hasIngoingArm = recoTrack.hasIngoingArmTime();
91 
92  // check if it has both ingoing and outgoing arms
93  if (hasOutgoingArm && hasIngoingArm) {
94  // consider the smallest arm time
95  if (outgoingArmTime <= ingoingArmTime) {
96  armTimeSum += outgoingArmTime * recoTrack.getNSVDHitsOfOutgoingArm();
97  armTimeErrSum += outgoingArmTimeError * outgoingArmTimeError * recoTrack.getNSVDHitsOfOutgoingArm() *
98  (recoTrack.getNSVDHitsOfOutgoingArm() - 1);
99  numberOfSVDClusters += recoTrack.getNSVDHitsOfOutgoingArm();
100  } else {
101  armTimeSum += ingoingArmTime * recoTrack.getNSVDHitsOfIngoingArm();
102  armTimeErrSum += ingoingArmTimeError * ingoingArmTimeError * recoTrack.getNSVDHitsOfIngoingArm() *
103  (recoTrack.getNSVDHitsOfIngoingArm() - 1);
104  numberOfSVDClusters += recoTrack.getNSVDHitsOfIngoingArm();
105  }
106  numberOfRecoTracksUsed += 1;
107  } else if (hasOutgoingArm && !hasIngoingArm) { // check if it has only outgoing arm
108  armTimeSum += outgoingArmTime * recoTrack.getNSVDHitsOfOutgoingArm();
109  armTimeErrSum += outgoingArmTimeError * outgoingArmTimeError * recoTrack.getNSVDHitsOfOutgoingArm() *
110  (recoTrack.getNSVDHitsOfOutgoingArm() - 1);
111  numberOfSVDClusters += recoTrack.getNSVDHitsOfOutgoingArm();
112  numberOfRecoTracksUsed += 1;
113  } else if (!hasOutgoingArm && hasIngoingArm) { // check if it has only ingoing arm
114  armTimeSum += ingoingArmTime * recoTrack.getNSVDHitsOfIngoingArm();
115  armTimeErrSum += ingoingArmTimeError * ingoingArmTimeError * recoTrack.getNSVDHitsOfIngoingArm() *
116  (recoTrack.getNSVDHitsOfIngoingArm() - 1);
117  numberOfSVDClusters += recoTrack.getNSVDHitsOfIngoingArm();
118  numberOfRecoTracksUsed += 1;
119  } else continue;
120  }
121 
122 
123  // do nothing if no recoTracks are used (no outgoing/ingoing arm time exists = no SVD clusters associated to tracks exist), or if EventT0 is not valid
124  if ((numberOfRecoTracksUsed == 0) || !(m_eventT0.isValid())) return;
125 
126  // otherwise, eventT0 is the average of outgoing/ingoing arm time
127  // that are estimated using SVD clusters associated to recoTracks
128  evtT0 = armTimeSum / numberOfSVDClusters;
129  quality = numberOfSVDClusters;
130 
131  // now compute the error
132  if (numberOfSVDClusters > 1)
133  evtT0Err = std::sqrt(armTimeErrSum / (numberOfSVDClusters * (numberOfSVDClusters - 1)));
134  else
135  evtT0Err = std::sqrt(armTimeErrSum);
136 
137  // and finally set a temporary EventT0
138  EventT0::EventT0Component evtT0Component(evtT0, evtT0Err, Const::SVD, m_algorithm, quality);
139  m_eventT0->addTemporaryEventT0(evtT0Component);
140  m_eventT0->setEventT0(evtT0Component);
141 
142 }
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
double m_absPzSelection
Cut on abs(pz) for RecoTrack selection.
StoreObjPtr< EventT0 > m_eventT0
EventT0 StoreObjPtr.
virtual void initialize() override
Initialize the SVDEventT0Estimator.
std::string m_algorithm
name of the algorithm used to evaluate SVD-eventT0
virtual void event() override
This method is the core of the SVDEventT0Estimator.
std::string m_recoTracksName
name of RecoTracks StoreArray
double m_ptSelection
Cut on pt for RecoTrack selection.
std::string m_eventT0Name
name of StoreObj EventT0
StoreArray< RecoTrack > m_recoTracks
RecoTracks StoreArray.
virtual ~SVDEventT0EstimatorModule()
default destructor
SVDEventT0EstimatorModule()
Constructor defining the parameters.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
REG_MODULE(arichBtest)
Register the Module.
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
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.
Structure for storing the extracted event t0s together with its detector and its uncertainty.
Definition: EventT0.h:33