Belle II Software development
RealisticTDCCountTranslator.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 <cdc/translators/RealisticTDCCountTranslator.h>
10#include <framework/core/Environment.h>
11#include <framework/geometry/B2Vector3.h>
12
13using namespace std;
14using namespace Belle2;
15using namespace CDC;
16
17RealisticTDCCountTranslator::RealisticTDCCountTranslator(bool useInWirePropagationDelay, bool fromTrackCreator) :
18 m_useInWirePropagationDelay(useInWirePropagationDelay), m_fromTrackCreator(fromTrackCreator),
19 m_gcp(CDCGeoControlPar::getInstance()),
20 m_scp(CDCSimControlPar::getInstance()), m_cdcp(CDCGeometryPar::Instance()),
21 m_tdcBinWidth(m_cdcp.getTdcBinWidth())
22{
24 if (m_realData) {
25 m_fudgeFactor = m_cdcp.getFudgeFactorForSigma(0);
26 } else {
27 m_fudgeFactor = m_cdcp.getFudgeFactorForSigma(1);
28 }
29}
30
31
32double RealisticTDCCountTranslator::getDriftTime(unsigned short tdcCount,
33 const WireID& wireID,
34 double timeOfFlightEstimator,
35 double z,
36 unsigned short adcCount)
37{
38 // translate TDC Count into time information:
39 // N.B. No correction (+ or -0.5 count) is needed in the translation since no bias is in the real TDC count on average (info. from KEK electronics division).
40 double driftTime = m_cdcp.getT0(wireID) - tdcCount * m_tdcBinWidth;
41
42 unsigned short layer = wireID.getICLayer();
43
44 // Need to undo everything the digitization does in reverse order.
45 // First: Undo propagation in wire, if it was used:
47 const B2Vector3D& backWirePos = m_cdcp.wireBackwardPosition(wireID, CDCGeometryPar::c_Aligned);
48 const B2Vector3D& diffWirePos = m_cdcp.wireForwardPosition(wireID, CDCGeometryPar::c_Aligned) - backWirePos;
49 // subtract distance divided by speed of electric signal in the wire from the drift time.
50 double propLength = z - backWirePos.Z();
51 double dZ = diffWirePos.Z();
52 if (dZ != 0.) {
53 propLength *= diffWirePos.Mag() / dZ;
54 }
55 if (m_gcp.getSenseWireZposMode() == 1) {
56 propLength += m_cdcp.getBwdDeltaZ(layer);
57 }
58 driftTime -= propLength * m_cdcp.getPropSpeedInv(layer);
59 }
60
61 // Second: correct for event time. If this wasn't simulated, m_eventTime can just be set to 0.
62 // Use SVD temporary T0 preferentially, falling back to CDC T0, then getEventT0().
63 // SVD and CDC temporary entries are set before any TrackCreator runs and remain stable across
64 // multiple fitting passes, unlike getEventT0() which can change when EventT0Combiner runs between
65 // passes. The fallback to getEventT0() is there in case neither SVD nor CDC proved event T0.
66 if (m_eventTimeStoreObject.isValid() && m_eventTimeStoreObject->hasEventT0()) {
67 driftTime -= m_eventTimeStoreObject->getEventT0(m_fromTrackCreator);
68 }
69
70 //Third: If time of flight was simulated, this has to be undone, too. If it wasn't timeOfFlightEstimator should be taken as 0.
71 driftTime -= timeOfFlightEstimator;
72
73 //Forth: Time-walk correction
74 if (m_realData) { //for data, always correct
75 driftTime -= m_cdcp.getTimeWalk(wireID, adcCount);
76 } else if (m_scp.getTimeWalk()) { //for MC, ccorrect if the flag is on
77 driftTime -= m_cdcp.getTimeWalk(wireID, adcCount);
78 }
79 return driftTime;
80}
81
82
83double RealisticTDCCountTranslator::getDriftLength(unsigned short tdcCount,
84 const WireID& wireID,
85 double timeOfFlightEstimator,
86 bool leftRight,
87 double z,
88 double alpha,
89 double theta,
90 unsigned short adcCount)
91{
92 const double driftTime = getDriftTime(tdcCount, wireID, timeOfFlightEstimator, z, adcCount);
93
94 unsigned short layer = wireID.getICLayer();
95
96 // Now we have an estimate for the time it took from the ionisation to the hitting of the wire.
97 // Need to reverse calculate the relation between drift length and drift time.
98 double driftL = m_cdcp.getDriftLength(driftTime, layer, leftRight, alpha, theta);
99
100 return driftL;
101}
102
103
105double RealisticTDCCountTranslator::getDriftLengthResolution(double driftLength, const WireID& wireID, bool leftRight, double z,
106 double alpha, double theta)
107{
108 static_cast<void>(z); //just to suppress warning of unused
109 double resol = m_fudgeFactor * m_cdcp.getSigma(driftLength, wireID.getICLayer(), leftRight, alpha, theta);
110
111 return resol * resol;;
112}
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition B2Vector3.h:435
DataType Mag() const
The magnitude (rho in spherical coordinate system).
Definition B2Vector3.h:159
The Class for CDC Geometry Control Parameters.
The Class for CDC Geometry Parameters.
The Class for CDC Simulation Control Parameters.
StoreObjPtr< EventT0 > m_eventTimeStoreObject
Event timing.
double getDriftLength(unsigned short tdcCount, const WireID &wireID=WireID(), double timeOfFlightEstimator=0, bool leftRight=false, double z=0, double alpha=0, double theta=static_cast< double >(TMath::Pi()/2.), unsigned short adcCount=0) override
Get Drift length.
const double m_tdcBinWidth
Hit timing offset value.
double m_fudgeFactor
Cached fudge factor for space resol.
const CDCSimControlPar & m_scp
Cached reference to CDC SimControlPar object.
const CDCGeometryPar & m_cdcp
Cached reference to CDC GeometryPar object.
bool m_fromTrackCreator
Flag to use EventT0 from SVD and CDC with higher priority.
RealisticTDCCountTranslator(bool useInWirePropagationDelay=false, bool fromTrackCreator=false)
Constructor, with the additional information, if propagation in the wire shall be considered.
double getDriftLengthResolution(double driftLength, const WireID &wireID=WireID(), bool leftRight=false, double z=0, double alpha=0, double=static_cast< double >(TMath::Pi()/2.)) override
Get position resolution^2 corresponding to the drift length from getDriftLength of this class.
bool m_useInWirePropagationDelay
Flag to activate the propagation delay of the sense wire.
const CDCGeoControlPar & m_gcp
Cached reference to CDC GeoControlPar object.
double getDriftTime(unsigned short tdcCount, const WireID &wireID, double timeOfFlightEstimator, double z, unsigned short adcCount) override
Get Drift time.
bool isMC() const
Do we have generated, not real data?
static Environment & Instance()
Static method to get a reference to the Environment instance.
Class to identify a wire inside the CDC.
Definition WireID.h:34
unsigned short getICLayer() const
Getter for continuous layer numbering.
Definition WireID.cc:24
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition B2Vector3.h:516
Abstract base class for different kinds of events.
STL namespace.