Belle II Software  release-05-01-25
WireHitCreator.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/findlets/minimal/WireHitCreator.h>
11 
12 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
13 #include <tracking/trackFindingCDC/eventdata/utils/FlightTimeEstimator.h>
14 
15 #include <tracking/trackFindingCDC/findlets/minimal/EPreferredDirection.h>
16 
17 #include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
18 
19 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
20 
21 #include <cdc/translators/RealisticTDCCountTranslator.h>
22 #include <cdc/translators/LinearGlobalADCCountTranslator.h>
23 #include <cdc/geometry/CDCGeometryPar.h>
24 
25 #include <cdc/dataobjects/CDCHit.h>
26 
27 #include <framework/datastore/StoreArray.h>
28 #include <framework/core/ModuleParamList.templateDetails.h>
29 
30 #include <mdst/dataobjects/MCParticle.h>
31 
32 using namespace Belle2;
33 using namespace TrackFindingCDC;
34 
37 
39 {
40  return "Combines the geometrical information and the raw hit information into wire hits, "
41  "which can be used from all modules after that";
42 }
43 
44 void WireHitCreator::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
45 {
46  moduleParamList->addParameter(prefixed(prefix, "wirePosition"),
48  "Set of geometry parameters to be used in the track finding. "
49  "Either 'base', 'misaligned' or 'aligned'.",
51 
52  moduleParamList->addParameter(prefixed(prefix, "ignoreWireSag"),
54  "Assume a wire sag coefficient of zero "
55  "such that the wires appear to be straight for "
56  "the track finders",
58 
59  moduleParamList->addParameter(prefixed(prefix, "flightTimeEstimation"),
61  "Option which flight direction should be assumed for "
62  "an initial time of flight estimation. Options are: "
63  "'none' (no TOF correction), "
64  "'outwards', "
65  "'downwards'.",
67 
68  moduleParamList->addParameter(prefixed(prefix, "triggerPoint"),
70  "Point relative to which the flight times are calculated",
72 
73  moduleParamList->addParameter(prefixed(prefix, "useSuperLayers"),
75  "List of super layers to be used - mostly for debugging",
77 
78  moduleParamList->addParameter(prefixed(prefix, "useSecondHits"),
80  "Use the second hit information in the track finding.",
82 
83  moduleParamList->addParameter(prefixed(prefix, "useBadWires"),
85  "Also create the hits that are on bad wires.",
87 
88  moduleParamList->addParameter(prefixed(prefix, "useDegreeSector"),
90  "To angles in degrees for which hits should be created - mostly for debugging",
92 
93  moduleParamList->addParameter(prefixed(prefix, "useMCParticleIds"),
95  "Ids of the MC particles to use. Default does not look at the MCParticles - most for debugging",
97 }
98 
100 {
101  StoreArray<CDCHit> hits;
102  hits.isRequired();
103 
104  // Create the wires and layers once during initialisation
106 
107  if (m_param_wirePosition == "base") {
108  m_wirePosition = EWirePosition::c_Base;
109  } else if (m_param_wirePosition == "misaligned") {
110  m_wirePosition = EWirePosition::c_Misaligned;
111  } else if (m_param_wirePosition == "aligned") {
112  m_wirePosition = EWirePosition::c_Aligned;
113  } else {
114  B2ERROR("Received unknown wirePosition " << m_param_wirePosition);
115  }
116 
119 
120  if (m_param_flightTimeEstimation != std::string("")) {
121  try {
122  m_flightTimeEstimation = getPreferredDirection(m_param_flightTimeEstimation);
123  } catch (std::invalid_argument& e) {
124  B2ERROR("Unexpected 'flightTimeEstimation' parameter : '" << m_param_flightTimeEstimation);
125  }
126  }
127 
129  std::get<1>(m_param_triggerPoint),
130  std::get<2>(m_param_triggerPoint));
131 
132  if (m_flightTimeEstimation == EPreferredDirection::c_Symmetric) {
133  B2ERROR("Unexpected 'flightTimeEstimation' parameter : '" << m_param_flightTimeEstimation);
134  } else if (m_flightTimeEstimation == EPreferredDirection::c_Downwards) {
135  FlightTimeEstimator::instance(std::make_unique<CosmicRayFlightTimeEstimator>(m_triggerPoint));
136  } else if (m_flightTimeEstimation == EPreferredDirection::c_Outwards) {
137  FlightTimeEstimator::instance(std::make_unique<BeamEventFlightTimeEstimator>());
138  }
139 
140  if (not m_param_useSuperLayers.empty()) {
141  for (const ISuperLayer& iSL : m_param_useSuperLayers) {
142  m_useSuperLayers.at(iSL) = true;
143  }
144  } else {
145  m_useSuperLayers.fill(true);
146  }
147 
148  if (std::isfinite(std::get<0>(m_param_useDegreeSector))) {
151  }
152 
154 }
155 
157 {
158  Super::beginRun();
161 }
162 
163 void WireHitCreator::apply(std::vector<CDCWireHit>& outputWireHits)
164 {
165  // Wire hits have been created before
166  if (not outputWireHits.empty()) return;
167 
168  const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
169  CDC::TDCCountTranslatorBase& tdcCountTranslator = *m_tdcCountTranslator;
170  CDC::ADCCountTranslatorBase& adcCountTranslator = *m_adcCountTranslator;
172 
173  // Create the wire hits into a vector
174  StoreArray<CDCHit> hits;
175  std::size_t nHits = hits.getEntries();
176  if (nHits == 0) {
177  B2WARNING("Event with no hits");
178  outputWireHits.clear();
179  }
180 
181  std::map<int, size_t> nHitsByMCParticleId;
182 
183  outputWireHits.reserve(nHits);
184  for (const CDCHit& hit : hits) {
185 
186  // ignore this hit if it contains the information of a 2nd hit
187  if (!m_param_useSecondHits && hit.is2ndHit()) {
188  continue;
189  }
190 
191  // Only use some MCParticles if request - mostly for debug
192  if (not m_param_useMCParticleIds.empty()) {
193  MCParticle* mcParticle = hit.getRelated<MCParticle>();
194  int mcParticleId = mcParticle->getArrayIndex();
195  if (mcParticle) {
196  nHitsByMCParticleId[mcParticleId]++;
197  }
198  bool useMCParticleId = std::count(m_param_useMCParticleIds.begin(),
200  mcParticleId);
201  if (not useMCParticleId) continue;
202  }
203 
204  WireID wireID(hit.getID());
205  if (not wireTopology.isValidWireID(wireID)) {
206  B2WARNING("Skip invalid wire id " << hit.getID());
207  continue;
208  }
209 
210  // ignore hit if it is on a bad wire
211  if (not m_param_useBadWires and geometryPar.isBadWire(wireID)) {
212  continue;
213  }
214 
215  ISuperLayer iSL = wireID.getISuperLayer();
216  if (not m_useSuperLayers[iSL]) continue;
217 
218  const CDCWire& wire = wireTopology.getWire(wireID);
219 
220  const Vector2D& pos2D = wire.getRefPos2D();
221 
222  // Check whether the position is outside the selected sector
223  if (pos2D.isBetween(m_useSector[1], m_useSector[0])) continue;
224 
225  // Only use some MCParticles if request - mostly for debug
226  if (not m_param_useMCParticleIds.empty()) {
227  MCParticle* mcParticle = hit.getRelated<MCParticle>();
228  int mcParticleId = mcParticle->getArrayIndex();
229  if (mcParticle) {
230  nHitsByMCParticleId[mcParticleId]++;
231  }
232  bool useMCParticleId = std::count(m_param_useMCParticleIds.begin(),
234  mcParticleId);
235  if (not useMCParticleId) continue;
236  }
237 
238 
239 
240  // Consider the particle as incoming in the top part of the CDC for a downwards flight direction
241  bool isIncoming = m_flightTimeEstimation == EPreferredDirection::c_Downwards and pos2D.y() > 0;
242  const double alpha = isIncoming ? M_PI : 0;
243  const double beta = 1;
244  const double flightTimeEstimate =
245  FlightTimeEstimator::instance().getFlightTime2D(pos2D, alpha, beta);
246 
247  const double driftTime = tdcCountTranslator.getDriftTime(hit.getTDCCount(),
248  wire.getWireID(),
249  flightTimeEstimate,
250  wire.getRefZ(),
251  hit.getADCCount());
252  const bool left = false;
253  const bool right = true;
254  const double theta = M_PI / 2;
255 
256  const double leftRefDriftLength =
257  tdcCountTranslator.getDriftLength(hit.getTDCCount(),
258  wire.getWireID(),
259  flightTimeEstimate,
260  left,
261  wire.getRefZ(),
262  alpha,
263  theta);
264 
265  const double rightRefDriftLength =
266  tdcCountTranslator.getDriftLength(hit.getTDCCount(),
267  wire.getWireID(),
268  flightTimeEstimate,
269  right,
270  wire.getRefZ(),
271  alpha,
272  theta);
273 
274  const double refDriftLength =
275  (leftRefDriftLength + rightRefDriftLength) / 2.0;
276 
277  const double leftRefDriftLengthVariance =
278  tdcCountTranslator.getDriftLengthResolution(refDriftLength,
279  wire.getWireID(),
280  left,
281  wire.getRefZ(),
282  alpha,
283  theta);
284 
285  const double rightRefDriftLengthVariance =
286  tdcCountTranslator.getDriftLengthResolution(refDriftLength,
287  wire.getWireID(),
288  right,
289  wire.getRefZ(),
290  alpha,
291  theta);
292 
293  const double refDriftLengthVariance =
294  (leftRefDriftLengthVariance + rightRefDriftLengthVariance) / 2.0;
295 
296  const double leftRefChargeDeposit =
297  adcCountTranslator.getCharge(hit.getADCCount(),
298  wire.getWireID(),
299  left,
300  wire.getRefZ(),
301  theta);
302 
303  const double rightRefChargeDeposit =
304  adcCountTranslator.getCharge(hit.getADCCount(),
305  wire.getWireID(),
306  right,
307  wire.getRefZ(),
308  theta);
309 
310  const double refChargeDeposit =
311  (leftRefChargeDeposit + rightRefChargeDeposit) / 2.0;
312 
313  outputWireHits.emplace_back(&hit, refDriftLength, refDriftLengthVariance, refChargeDeposit, driftTime);
314  }
315 
316  std::sort(outputWireHits.begin(), outputWireHits.end());
317 
318  if (not m_param_useMCParticleIds.empty()) {
319  for (const std::pair<int, size_t> nHitsForMCParticleId : nHitsByMCParticleId) {
320  B2DEBUG(100,
321  "MC particle " << nHitsForMCParticleId.first << " #hits "
322  << nHitsForMCParticleId.second);
323  }
324  }
325 }
Belle2::CDC::TDCCountTranslatorBase
Base class for translation of Drift Time into Drift Length.
Definition: TDCCountTranslatorBase.h:36
Belle2::CDC::ADCCountTranslatorBase::getCharge
virtual float getCharge(unsigned short adcCount=0, const WireID &wireID=WireID(), bool ambiguityDiscrimiator=false, float z=0, float theta=static_cast< float >(TMath::Pi()/2.))=0
Function, for which this actually was meant.
Belle2::WireID
Class to identify a wire inside the CDC.
Definition: WireID.h:44
Belle2::Vector3D
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition: Cell.h:35
Belle2::TrackFindingCDC::WireHitCreator::m_param_useDegreeSector
std::tuple< double, double > m_param_useDegreeSector
Parameter : Angular range in degrees for which hits should be unpacked.
Definition: WireHitCreator.h:100
Belle2::TrackFindingCDC::WireHitCreator::m_flightTimeEstimation
EPreferredDirection m_flightTimeEstimation
Method for the initial time of flight estimation.
Definition: WireHitCreator.h:110
Belle2::TrackFindingCDC::WireHitCreator::exposeParameters
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
Definition: WireHitCreator.cc:44
Belle2::TrackFindingCDC::Vector2D
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:37
Belle2::TrackFindingCDC::WireHitCreator::WireHitCreator
WireHitCreator()
Default constructor.
Belle2::TrackFindingCDC::FlightTimeEstimator::getFlightTime2D
virtual double getFlightTime2D(const Vector2D &, double, double=1) const
Default estimator for the flight time.
Definition: FlightTimeEstimator.h:45
Belle2::CDC::RealisticTDCCountTranslator
Translator mirroring the realistic Digitization.
Definition: RealisticTDCCountTranslator.h:36
Belle2::TrackFindingCDC::CDCWire::getRefPos2D
const Vector2D & getRefPos2D() const
Getter for the wire reference position for 2D tracking Gives the wire's reference position projected ...
Definition: CDCWire.h:231
Belle2::TrackFindingCDC::Vector2D::y
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:619
Belle2::TrackFindingCDC::Vector2D::isBetween
bool isBetween(const Vector2D &lower, const Vector2D &upper) const
Checks if this vector is between two other vectors Between means here that when rotating the lower ve...
Definition: Vector2D.h:539
Belle2::CDCHit
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:51
Belle2::CDC::LinearGlobalADCCountTranslator
This class simply assumes a linear translation through (0,0)
Definition: LinearGlobalADCCountTranslator.h:31
Belle2::TrackFindingCDC::CDCWire::getRefZ
double getRefZ() const
Getter for the wire reference z coordinate Gives the wire's reference z coordinate.
Definition: CDCWire.h:238
Belle2::TrackFindingCDC::WireHitCreator::getDescription
std::string getDescription() final
Short description of the findlet.
Definition: WireHitCreator.cc:38
Belle2::TrackFindingCDC::CDCWireTopology::getInstance
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
Definition: CDCWireTopology.cc:22
Belle2::WireID::getISuperLayer
unsigned short getISuperLayer() const
Getter for Super-Layer.
Definition: WireID.h:140
Belle2::CDC::TDCCountTranslatorBase::getDriftLength
virtual double getDriftLength(unsigned short tdcCount=0, const WireID &wireID=WireID(), double timeOfFlightEstimator=0., bool ambiguityDiscrimiator=false, double z=0, double alpha=0, double theta=static_cast< double >(TMath::Pi()/2.), unsigned short adcCount=0)=0
Function for getting a drift length estimation.
Belle2::TrackFindingCDC::WireHitCreator::initialize
void initialize() final
Signals the beginning of the event processing.
Definition: WireHitCreator.cc:99
Belle2::TrackFindingCDC::CDCWireTopology::isValidWireID
bool isValidWireID(const WireID &wireID) const
Checks the validity of a wireID convinience object.
Definition: CDCWireTopology.h:100
Belle2::MCParticle::getArrayIndex
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:255
Belle2::CDC::TDCCountTranslatorBase::getDriftLengthResolution
virtual double getDriftLengthResolution(double driftLength=0., const WireID &wireID=WireID(), bool ambiguityDiscrimiator=false, double z=0, double alpha=0, double theta=static_cast< double >(TMath::Pi()/2.))=0
Uncertainty corresponding to drift length from getDriftLength of this class.
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::initialize
void initialize() override
Receive and dispatch signal before the start of the event processing.
Definition: CompositeProcessingSignalListener.cc:17
Belle2::CDC::TDCCountTranslatorBase::getDriftTime
virtual double getDriftTime(unsigned short tdcCount, const WireID &wireID, double timeOfFlightEstimator, double z, unsigned short adcCount)=0
Get Drift time.
Belle2::TrackFindingCDC::CDCWireTopology::getWire
const CDCWire & getWire(const WireID &wireId) const
Getter for wire getter by wireID object.
Definition: CDCWireTopology.h:112
Belle2::TrackFindingCDC::WireHitCreator::m_useSector
std::array< Vector2D, 2 > m_useSector
Unit vectors denoting the sector for which hits should be created.
Definition: WireHitCreator.h:119
Belle2::TrackFindingCDC::WireHitCreator::m_param_useSuperLayers
std::vector< int > m_param_useSuperLayers
Parameter : List of super layers to be used - mostly for debugging.
Definition: WireHitCreator.h:91
Belle2::CDC::CDCGeometryPar
The Class for CDC Geometry Parameters.
Definition: CDCGeometryPar.h:75
Belle2::TrackFindingCDC::Vector2D::Phi
static Vector2D Phi(const double phi)
Constucts a unit vector with azimuth angle equal to phi.
Definition: Vector2D.h:73
Belle2::CDC::CDCGeometryPar::isBadWire
bool isBadWire(const WireID &wid)
Inquire if the wire is totally-dead.
Definition: CDCGeometryPar.h:840
Belle2::TrackFindingCDC::WireHitCreator::m_param_flightTimeEstimation
std::string m_param_flightTimeEstimation
Parameter : Method for the initial time of flight estimation as string.
Definition: WireHitCreator.h:85
Belle2::ModuleParamList::addParameter
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Definition: ModuleParamList.templateDetails.h:38
Belle2::CDC::CDCGeometryPar::Instance
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
Definition: CDCGeometryPar.cc:41
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::beginRun
void beginRun() override
Receive and dispatch signal for the beginning of a new run.
Definition: CompositeProcessingSignalListener.cc:25
Belle2::TrackFindingCDC::WireHitCreator::m_param_ignoreWireSag
bool m_param_ignoreWireSag
Parameter : Switch to deactivate the sag of the wires for the concerns of the track finders.
Definition: WireHitCreator.h:82
Belle2::TrackFindingCDC::WireHitCreator::m_param_useSecondHits
bool m_param_useSecondHits
Parameter : If true, the second hit information will be used to create Wire Hits.
Definition: WireHitCreator.h:94
Belle2::TrackFindingCDC::WireHitCreator::m_param_triggerPoint
std::tuple< double, double, double > m_param_triggerPoint
Parameter : Location of the flight time zero.
Definition: WireHitCreator.h:88
Belle2::Unit::deg
static const double deg
degree to radians
Definition: Unit.h:119
Belle2::TrackFindingCDC::WireHitCreator::m_useSuperLayers
std::array< bool, ISuperLayerUtil::c_N > m_useSuperLayers
Bits for the used super layers.
Definition: WireHitCreator.h:116
Belle2::TrackFindingCDC::CDCWire::getWireID
const WireID & getWireID() const
Getter for the wire id.
Definition: CDCWire.h:124
Belle2::TrackFindingCDC::WireHitCreator::m_triggerPoint
Vector3D m_triggerPoint
Central location of the flight time zero position. Usually the location of the trigger.
Definition: WireHitCreator.h:113
Belle2::TrackFindingCDC::CDCWireTopology::reinitialize
void reinitialize(EWirePosition wirePosition, bool ignoreWireSag)
Reload all geometry parameters form the CDCGeometryPar to adjust to changes in geometry.
Definition: CDCWireTopology.cc:64
Belle2::TrackFindingCDC::FlightTimeEstimator::instance
static const FlightTimeEstimator & instance(std::unique_ptr< FlightTimeEstimator > replacement=nullptr)
Getter for the instance.
Definition: FlightTimeEstimator.cc:23
Belle2::CDC::ADCCountTranslatorBase
Abstract Base class for the ADC count translator.
Definition: ADCCountTranslatorBase.h:33
Belle2::TrackFindingCDC::CDCWire
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:60
Belle2::TrackFindingCDC::WireHitCreator::m_param_wirePosition
std::string m_param_wirePosition
Parameter : Geometry set to be used. Either "base", "misalign" or " aligned".
Definition: WireHitCreator.h:79
Belle2::TrackFindingCDC::WireHitCreator::beginRun
void beginRun() final
Signal the beginning of a new run.
Definition: WireHitCreator.cc:156
Belle2::TrackFindingCDC::WireHitCreator::m_wirePosition
EWirePosition m_wirePosition
Geometry set to be used.
Definition: WireHitCreator.h:107
Belle2::TrackFindingCDC::WireHitCreator::m_tdcCountTranslator
std::unique_ptr< CDC::TDCCountTranslatorBase > m_tdcCountTranslator
TDC Count translator to be used to calculate the initial dirft length estiamtes.
Definition: WireHitCreator.h:123
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::ModuleParamList
The Module parameter list class.
Definition: ModuleParamList.h:46
Belle2::TrackFindingCDC::WireHitCreator::m_param_useBadWires
bool m_param_useBadWires
Parameter : If true, the hits on bad wires are not ignored.
Definition: WireHitCreator.h:97
Belle2::TrackFindingCDC::WireHitCreator::apply
void apply(std::vector< CDCWireHit > &outputWireHits) final
Main algorithm creating the wire hits.
Definition: WireHitCreator.cc:163
Belle2::TrackFindingCDC::WireHitCreator::m_param_useMCParticleIds
std::vector< int > m_param_useMCParticleIds
Parameter : Indices of the Monte Carlo particles for which hits should be used.
Definition: WireHitCreator.h:103
Belle2::TrackFindingCDC::CDCWireTopology
Class representating the sense wire arrangement in the whole of the central drift chamber.
Definition: CDCWireTopology.h:54
Belle2::TrackFindingCDC::WireHitCreator::~WireHitCreator
~WireHitCreator()
Default destructor.
Belle2::TrackFindingCDC::WireHitCreator::m_adcCountTranslator
std::unique_ptr< CDC::ADCCountTranslatorBase > m_adcCountTranslator
ADC Count translator to be used to calculate the charge deposit in the drift cell.
Definition: WireHitCreator.h:126