Belle II Software prerelease-11-00-00a
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 // B2INFO("RealisticTDCCountTranslator:: m_fudgeFactor= " << m_fudgeFactor);
30
31#if defined(CDC_DEBUG)
32 cout << " " << endl;
33 cout << "RealisticTDCCountTranslator constructor" << endl;
34 cout << "m_cdcp=" << &m_cdcp << endl;
35 cout << "m_tdcBinWidth=" << m_tdcBinWidth << endl;
36#endif
37}
38
39
40double RealisticTDCCountTranslator::getDriftTime(unsigned short tdcCount,
41 const WireID& wireID,
42 double timeOfFlightEstimator,
43 double z,
44 unsigned short adcCount)
45{
46 // translate TDC Count into time information:
47 // 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).
48 double driftTime = m_cdcp.getT0(wireID) - tdcCount * m_tdcBinWidth;
49 // std::cout << "t0,tdcbinw= " << m_cdcp.getT0(wireID) <<" "<< m_tdcBinWidth << std::endl;
50
51 unsigned short layer = wireID.getICLayer();
52
53 // Need to undo everything the digitization does in reverse order.
54 // First: Undo propagation in wire, if it was used:
56 const B2Vector3D& backWirePos = m_cdcp.wireBackwardPosition(wireID, CDCGeometryPar::c_Aligned);
57 const B2Vector3D& diffWirePos = m_cdcp.wireForwardPosition(wireID, CDCGeometryPar::c_Aligned) - backWirePos;
58 //subtract distance divided by speed of electric signal in the wire from the drift time.
59 // std::cout << layer <<" "<< diffWirePos.Z() <<" "<< stereoAngleFactor << std::endl;
60 double propLength = z - backWirePos.Z();
61 double dZ = diffWirePos.Z();
62 if (dZ != 0.) {
63 propLength *= diffWirePos.Mag() / dZ;
64 }
65 if (m_gcp.getSenseWireZposMode() == 1) {
66 // std::cout <<"layer,zb,dzb,zf,dzf= "<< layer <<" "<< zb <<" "<< m_cdcp.getBwdDeltaZ(layer) <<" "<< m_cdcp.wireForwardPosition(wireID, CDCGeometryPar::c_Aligned).Z() <<" "<< m_cdcp.getFwdDeltaZ(layer) << std::endl;
67 propLength += m_cdcp.getBwdDeltaZ(layer);
68 }
69 driftTime -= propLength * m_cdcp.getPropSpeedInv(layer);
70 }
71
72 // Second: correct for event time. If this wasn't simulated, m_eventTime can just be set to 0.
73 // Use SVD temporary T0 preferentially, falling back to CDC T0, then getEventT0().
74 // SVD and CDC temporary entries are set before any TrackCreator runs and remain stable across
75 // multiple fitting passes, unlike getEventT0() which can change when EventT0Combiner runs between
76 // passes. The fallback to getEventT0() is there in case neither SVD nor CDC proved event T0.
77 if (m_eventTimeStoreObject.isValid() && m_eventTimeStoreObject->hasEventT0()) {
78 driftTime -= m_eventTimeStoreObject->getEventT0(m_fromTrackCreator);
79 }
80
81 //Third: If time of flight was simulated, this has to be undone, too. If it wasn't timeOfFlightEstimator should be taken as 0.
82 driftTime -= timeOfFlightEstimator;
83
84 //Forth: Time-walk correction
85 if (m_realData) { //for data, always correct
86 driftTime -= m_cdcp.getTimeWalk(wireID, adcCount);
87 // B2INFO("RealisticTDCCountTranslator:: time-walk corr. done.");
88 } else if (m_scp.getTimeWalk()) { //for MC, ccorrect if the flag is on
89 driftTime -= m_cdcp.getTimeWalk(wireID, adcCount);
90 // B2INFO("RealisticTDCCountTranslator:: time-walk corr. done for MC.");
91 }
92
93 return driftTime;
94}
95
96
97double RealisticTDCCountTranslator::getDriftLength(unsigned short tdcCount,
98 const WireID& wireID,
99 double timeOfFlightEstimator,
100 bool leftRight,
101 double z,
102 double alpha,
103 double theta,
104 unsigned short adcCount)
105{
106 const double driftTime = getDriftTime(tdcCount, wireID, timeOfFlightEstimator, z, adcCount);
107
108 unsigned short layer = wireID.getICLayer();
109
110 //Now we have an estimate for the time it took from the ionisation to the hitting of the wire.
111 //Need to reverse calculate the relation between drift length and drift time.
112 // double driftL = std::copysign(m_cdcp.getDriftLength(fabs(driftTime), layer, leftRight, alpha, theta), driftTime);
113 //Note: The above treatment for negative drifttime is now done in m_cdcp.getDriftLength, so the line is commented out
114 double driftL = m_cdcp.getDriftLength(driftTime, layer, leftRight, alpha, theta);
115
116#if defined(CDC_DEBUG)
117 cout << " " << endl;
118 cout << "RealisticTDCCountTranslator::getDriftLength" << endl;
119 cout << "driftTime=" << driftTime << endl;
120 cout << "layer=" << layer << endl;
121 cout << "leftright=" << leftRight << endl;
122 cout << "driftL= " << driftL << endl;
123#endif
124
125 return driftL;
126}
127
128
130
131double RealisticTDCCountTranslator::getDriftLengthResolution(double driftLength, const WireID& wireID, bool leftRight, double z,
132 double alpha, double theta)
133{
134 static_cast<void>(z); //just to suppress warning of unused
135 double resol = m_fudgeFactor * m_cdcp.getSigma(driftLength, wireID.getICLayer(), leftRight, alpha, theta);
136 // B2DEBUG(29, "fudgeFactor in TDCTranslator= " << m_fudgeFactor);
137
138#if defined(CDC_DEBUG)
139 cout << " " << endl;
140 cout << "RealisticTDCCountTranslator::getDriftLengthResolution" << endl;
141 cout << "spaceResol= " << resol << endl;
142#endif
143
144 return resol * resol;;
145}
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.