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
18 m_useInWirePropagationDelay(useInWirePropagationDelay), m_gcp(CDCGeoControlPar::getInstance()),
19 m_scp(CDCSimControlPar::getInstance()), m_cdcp(CDCGeometryPar::Instance()),
20 m_tdcBinWidth(m_cdcp.getTdcBinWidth())
21{
23 if (m_realData) {
24 m_fudgeFactor = m_cdcp.getFudgeFactorForSigma(0);
25 } else {
26 m_fudgeFactor = m_cdcp.getFudgeFactorForSigma(1);
27 }
28 // B2INFO("RealisticTDCCountTranslator:: m_fudgeFactor= " << m_fudgeFactor);
29
30#if defined(CDC_DEBUG)
31 cout << " " << endl;
32 cout << "RealisticTDCCountTranslator constructor" << endl;
33 cout << "m_cdcp=" << &m_cdcp << endl;
34 cout << "m_tdcBinWidth=" << m_tdcBinWidth << endl;
35#endif
36}
37
38
39double RealisticTDCCountTranslator::getDriftTime(unsigned short tdcCount,
40 const WireID& wireID,
41 double timeOfFlightEstimator,
42 double z,
43 unsigned short adcCount)
44{
45 // translate TDC Count into time information:
46 // 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).
47 double driftTime = m_cdcp.getT0(wireID) - tdcCount * m_tdcBinWidth;
48 // std::cout << "t0,tdcbinw= " << m_cdcp.getT0(wireID) <<" "<< m_tdcBinWidth << std::endl;
49
50 unsigned short layer = wireID.getICLayer();
51
52 // Need to undo everything the digitization does in reverse order.
53 // First: Undo propagation in wire, if it was used:
55 const B2Vector3D& backWirePos = m_cdcp.wireBackwardPosition(wireID, CDCGeometryPar::c_Aligned);
56 const B2Vector3D& diffWirePos = m_cdcp.wireForwardPosition(wireID, CDCGeometryPar::c_Aligned) - backWirePos;
57 //subtract distance divided by speed of electric signal in the wire from the drift time.
58 // std::cout << layer <<" "<< diffWirePos.Z() <<" "<< stereoAngleFactor << std::endl;
59 double propLength = z - backWirePos.Z();
60 double dZ = diffWirePos.Z();
61 if (dZ != 0.) {
62 propLength *= diffWirePos.Mag() / dZ;
63 }
64 if (m_gcp.getSenseWireZposMode() == 1) {
65 // 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;
66 propLength += m_cdcp.getBwdDeltaZ(layer);
67 }
68 driftTime -= propLength * m_cdcp.getPropSpeedInv(layer);
69 }
70
71 // Second: correct for event time. If this wasn't simulated, m_eventTime can just be set to 0.
72 if (m_eventTimeStoreObject.isValid() && m_eventTimeStoreObject->hasEventT0()) {
73 driftTime -= m_eventTimeStoreObject->getEventT0();
74 }
75
76 //Third: If time of flight was simulated, this has to be undone, too. If it wasn't timeOfFlightEstimator should be taken as 0.
77 driftTime -= timeOfFlightEstimator;
78
79 //Forth: Time-walk correction
80 if (m_realData) { //for data, always correct
81 driftTime -= m_cdcp.getTimeWalk(wireID, adcCount);
82 // B2INFO("RealisticTDCCountTranslator:: time-walk corr. done.");
83 } else if (m_scp.getTimeWalk()) { //for MC, ccorrect if the flag is on
84 driftTime -= m_cdcp.getTimeWalk(wireID, adcCount);
85 // B2INFO("RealisticTDCCountTranslator:: time-walk corr. done for MC.");
86 }
87
88 return driftTime;
89}
90
91
92double RealisticTDCCountTranslator::getDriftLength(unsigned short tdcCount,
93 const WireID& wireID,
94 double timeOfFlightEstimator,
95 bool leftRight,
96 double z,
97 double alpha,
98 double theta,
99 unsigned short adcCount)
100{
101 const double driftTime = getDriftTime(tdcCount, wireID, timeOfFlightEstimator, z, adcCount);
102
103 unsigned short layer = wireID.getICLayer();
104
105 //Now we have an estimate for the time it took from the ionisation to the hitting of the wire.
106 //Need to reverse calculate the relation between drift length and drift time.
107 // double driftL = std::copysign(m_cdcp.getDriftLength(fabs(driftTime), layer, leftRight, alpha, theta), driftTime);
108 //Note: The above treatment for negative drifttime is now done in m_cdcp.getDriftLength, so the line is commented out
109 double driftL = m_cdcp.getDriftLength(driftTime, layer, leftRight, alpha, theta);
110
111#if defined(CDC_DEBUG)
112 cout << " " << endl;
113 cout << "RealisticTDCCountTranslator::getDriftLength" << endl;
114 cout << "driftTime=" << driftTime << endl;
115 cout << "layer=" << layer << endl;
116 cout << "leftright=" << leftRight << endl;
117 cout << "driftL= " << driftL << endl;
118#endif
119
120 return driftL;
121}
122
123
125
126double RealisticTDCCountTranslator::getDriftLengthResolution(double driftLength, const WireID& wireID, bool leftRight, double z,
127 double alpha, double theta)
128{
129 static_cast<void>(z); //just to suppress warning of unused
130 double resol = m_fudgeFactor * m_cdcp.getSigma(driftLength, wireID.getICLayer(), leftRight, alpha, theta);
131 // B2DEBUG(29, "fudgeFactor in TDCTranslator= " << m_fudgeFactor);
132
133#if defined(CDC_DEBUG)
134 cout << " " << endl;
135 cout << "RealisticTDCCountTranslator::getDriftLengthResolution" << endl;
136 cout << "spaceResol= " << resol << endl;
137#endif
138
139 return resol * resol;;
140}
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.
RealisticTDCCountTranslator(bool useInWirePropagationDelay=false)
Constructor, with the additional information, if propagation in the wire shall be considered.
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.
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.