Belle II Software  release-05-01-25
RealisticTDCCountTranslator.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2012 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: CDC group *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <cdc/translators/RealisticTDCCountTranslator.h>
12 #include <framework/dataobjects/FileMetaData.h>
13 #include <framework/datastore/StoreArray.h>
14 #include <mdst/dataobjects/MCParticle.h>
15 #include <TVector3.h>
16 
17 using namespace std;
18 using namespace Belle2;
19 using namespace CDC;
20 
21 RealisticTDCCountTranslator::RealisticTDCCountTranslator(bool useInWirePropagationDelay) :
22  m_useInWirePropagationDelay(useInWirePropagationDelay), m_gcp(CDCGeoControlPar::getInstance()),
23  m_scp(CDCSimControlPar::getInstance()), m_cdcp(CDCGeometryPar::Instance()),
24  m_tdcBinWidth(m_cdcp.getTdcBinWidth())
25 {
27  if (filPtr) {
28  if (filPtr->getMcEvents() == 0) m_realData = true;
29  // B2INFO("RealisticTDCCountTranslator:: judge from FileMetaData.");
30  } else { //judge from MCParticle
32  if (!mcp) m_realData = true;
33  // B2INFO("RealisticTDCCountTranslator:: judge from MCParticle.");
34  }
35  // B2INFO("RealisticTDCCountTranslator:: m_realData= " << m_realData);
36 
37  if (m_realData) {
39  } else {
41  }
42  // B2INFO("RealisticTDCCountTranslator:: m_fudgeFactor= " << m_fudgeFactor);
43 
44 #if defined(CDC_DEBUG)
45  cout << " " << endl;
46  cout << "RealisticTDCCountTranslator constructor" << endl;
47  cout << "m_cdcp=" << &m_cdcp << endl;
48  cout << "m_tdcBinWidth=" << m_tdcBinWidth << endl;
49 #endif
50 }
51 
52 
53 double RealisticTDCCountTranslator::getDriftTime(unsigned short tdcCount,
54  const WireID& wireID,
55  double timeOfFlightEstimator,
56  double z,
57  unsigned short adcCount)
58 {
59  // translate TDC Count into time information:
60  // 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).
61  double driftTime = m_cdcp.getT0(wireID) - tdcCount * m_tdcBinWidth;
62  // std::cout << "t0,tdcbinw= " << m_cdcp.getT0(wireID) <<" "<< m_tdcBinWidth << std::endl;
63 
64  unsigned short layer = wireID.getICLayer();
65 
66  // Need to undo everything the digitization does in reverse order.
67  // First: Undo propagation in wire, if it was used:
69  const TVector3& backWirePos = m_cdcp.wireBackwardPosition(wireID, CDCGeometryPar::c_Aligned);
70  const TVector3& diffWirePos = m_cdcp.wireForwardPosition(wireID, CDCGeometryPar::c_Aligned) - backWirePos;
71  //subtract distance divided by speed of electric signal in the wire from the drift time.
72  // std::cout << layer <<" "<< diffWirePos.Z() <<" "<< stereoAngleFactor << std::endl;
73  double propLength = z - backWirePos.Z();
74  double dZ = diffWirePos.Z();
75  if (dZ != 0.) {
76  propLength *= diffWirePos.Mag() / dZ;
77  }
78  if (m_gcp.getSenseWireZposMode() == 1) {
79  // 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;
80  propLength += m_cdcp.getBwdDeltaZ(layer);
81  }
82  driftTime -= propLength * m_cdcp.getPropSpeedInv(layer);
83  }
84 
85  // Second: correct for event time. If this wasn't simulated, m_eventTime can just be set to 0.
86  if (m_eventTimeStoreObject.isValid() && m_eventTimeStoreObject->hasEventT0()) {
87  driftTime -= m_eventTimeStoreObject->getEventT0();
88  }
89 
90  //Third: If time of flight was simulated, this has to be undone, too. If it wasn't timeOfFlightEstimator should be taken as 0.
91  driftTime -= timeOfFlightEstimator;
92 
93  //Forth: Time-walk correction
94  if (m_realData) { //for data, always correct
95  driftTime -= m_cdcp.getTimeWalk(wireID, adcCount);
96  // B2INFO("RealisticTDCCountTranslator:: time-walk corr. done.");
97  } else if (m_scp.getTimeWalk()) { //for MC, ccorrect if the flag is on
98  driftTime -= m_cdcp.getTimeWalk(wireID, adcCount);
99  // B2INFO("RealisticTDCCountTranslator:: time-walk corr. done for MC.");
100  }
101 
102  return driftTime;
103 }
104 
105 
106 double RealisticTDCCountTranslator::getDriftLength(unsigned short tdcCount,
107  const WireID& wireID,
108  double timeOfFlightEstimator,
109  bool leftRight,
110  double z,
111  double alpha,
112  double theta,
113  unsigned short adcCount)
114 {
115  const double driftTime = getDriftTime(tdcCount, wireID, timeOfFlightEstimator, z, adcCount);
116 
117  unsigned short layer = wireID.getICLayer();
118 
119  //Now we have an estimate for the time it took from the ionisation to the hitting of the wire.
120  //Need to reverse calculate the relation between drift lenght and drift time.
121  // double driftL = std::copysign(m_cdcp.getDriftLength(fabs(driftTime), layer, leftRight, alpha, theta), driftTime);
122  //Note: The above treatment for negative drifttime is now done in m_cdcp.getDriftLength, so the line is commented out
123  double driftL = m_cdcp.getDriftLength(driftTime, layer, leftRight, alpha, theta);
124 
125 #if defined(CDC_DEBUG)
126  cout << " " << endl;
127  cout << "RealisticTDCCountTranslator::getDriftLength" << endl;
128  cout << "driftTime=" << driftTime << endl;
129  cout << "layer=" << layer << endl;
130  cout << "leftright=" << leftRight << endl;
131  cout << "driftL= " << driftL << endl;
132 #endif
133 
134  return driftL;
135 }
136 
137 
140 double RealisticTDCCountTranslator::getDriftLengthResolution(double driftLength, const WireID& wireID, bool leftRight, double z,
141  double alpha, double theta)
142 {
143  static_cast<void>(z); //just to suppress warning of unused
144  double resol = m_fudgeFactor * m_cdcp.getSigma(driftLength, wireID.getICLayer(), leftRight, alpha, theta);
145  // B2DEBUG(29, "fudgeFactor in TDCTranslator= " << m_fudgeFactor);
146 
147 #if defined(CDC_DEBUG)
148  cout << " " << endl;
149  cout << "RealisticTDCCountTranslator::getDriftLengthResolution" << endl;
150  cout << "spaceResol= " << resol << endl;
151 #endif
152 
153  return resol * resol;;
154 }
Belle2::WireID
Class to identify a wire inside the CDC.
Definition: WireID.h:44
Belle2::CDC::RealisticTDCCountTranslator::getDriftLengthResolution
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.
Definition: RealisticTDCCountTranslator.cc:140
Belle2::CDC::CDCGeometryPar::getPropSpeedInv
double getPropSpeedInv(const unsigned int layerID) const
Get the inversel of propagation speed in the sense wire.
Definition: CDCGeometryPar.h:832
Belle2::CDC::CDCGeometryPar::wireForwardPosition
const TVector3 wireForwardPosition(int layerId, int cellId, EWirePosition set=c_Base) const
Returns the forward position of the input sense wire.
Definition: CDCGeometryPar.cc:1625
Belle2::CDC::CDCGeometryPar::getSigma
double getSigma(double dist, unsigned short layer, unsigned short lr, double alpha=0., double theta=0.5 *M_PI) const
Return the basic resolution of drift length (cm).
Definition: CDCGeometryPar.cc:2509
Belle2::CDC::RealisticTDCCountTranslator::m_fudgeFactor
double m_fudgeFactor
Cached fudge factor for space resol.
Definition: RealisticTDCCountTranslator.h:159
Belle2::CDC::RealisticTDCCountTranslator::m_eventTimeStoreObject
StoreObjPtr< EventT0 > m_eventTimeStoreObject
Event timing.
Definition: RealisticTDCCountTranslator.h:128
Belle2::CDC::RealisticTDCCountTranslator::m_cdcp
const CDCGeometryPar & m_cdcp
Cached reference to CDC GeometryPar object.
Definition: RealisticTDCCountTranslator.h:143
Belle2::CDC::RealisticTDCCountTranslator::m_gcp
const CDCGeoControlPar & m_gcp
Cached reference to CDC GeoControlPar object.
Definition: RealisticTDCCountTranslator.h:133
Belle2::CDC::CDCGeometryPar::getDriftLength
double getDriftLength(double dt, unsigned short layer, unsigned short lr, double alpha=0., double theta=0.5 *M_PI, bool calculateMinTime=true, double minTime=0.) const
Return the drift dength to the sense wire.
Definition: CDCGeometryPar.cc:2168
Belle2::CDC::CDCGeometryPar
The Class for CDC Geometry Parameters.
Definition: CDCGeometryPar.h:75
Belle2::CDC::CDCGeometryPar::wireBackwardPosition
const TVector3 wireBackwardPosition(int layerId, int cellId, EWirePosition set=c_Base) const
Returns the backward position of the input sense wire.
Definition: CDCGeometryPar.cc:1662
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDC::CDCSimControlPar
The Class for CDC Simulation Control Parameters.
Definition: CDCSimControlPar.h:31
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::CDC::RealisticTDCCountTranslator::getDriftLength
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.
Definition: RealisticTDCCountTranslator.cc:106
Belle2::CDC::CDCGeometryPar::getT0
float getT0(const WireID &wireID) const
Returns t0 parameter of the specified sense wire.
Definition: CDCGeometryPar.h:565
Belle2::CDC::RealisticTDCCountTranslator::getDriftTime
double getDriftTime(unsigned short tdcCount, const WireID &wireID, double timeOfFlightEstimator, double z, unsigned short adcCount) override
Get Drift time.
Definition: RealisticTDCCountTranslator.cc:53
Belle2::CDC::RealisticTDCCountTranslator::m_scp
const CDCSimControlPar & m_scp
Cached reference to CDC SimControlPar object.
Definition: RealisticTDCCountTranslator.h:138
Belle2::DataStore::c_Persistent
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:62
Belle2::CDC::CDCGeoControlPar::getSenseWireZposMode
int getSenseWireZposMode() const
Get sense wire z position mode.
Definition: CDCGeoControlPar.h:362
Belle2::CDC::RealisticTDCCountTranslator::m_useInWirePropagationDelay
bool m_useInWirePropagationDelay
Flag to activate the propagation delay of the sense wire.
Definition: RealisticTDCCountTranslator.h:118
Belle2::StoreArray< MCParticle >
Belle2::CDC::CDCGeometryPar::getTimeWalk
double getTimeWalk(const WireID &wID, unsigned short adcCount) const
Returns time-walk.
Definition: CDCGeometryPar.h:612
Belle2::CDC::CDCGeometryPar::getBwdDeltaZ
double getBwdDeltaZ(unsigned short layerID) const
Return backward 'deltaZ'.
Definition: CDCGeometryPar.h:800
Belle2::CDC::RealisticTDCCountTranslator::m_realData
bool m_realData
Flag to distinguish betw.
Definition: RealisticTDCCountTranslator.h:123
Belle2::WireID::getICLayer
unsigned short getICLayer() const
Getter for continuous layer numbering.
Definition: WireID.cc:26
Belle2::CDC::CDCGeoControlPar
The Class for CDC Geometry Control Parameters.
Definition: CDCGeoControlPar.h:33
Belle2::CDC::CDCGeometryPar::getFudgeFactorForSigma
double getFudgeFactorForSigma(unsigned short target) const
Return the fuge factor for space resol.
Definition: CDCGeometryPar.h:953
Belle2::CDC::RealisticTDCCountTranslator::m_tdcBinWidth
const double m_tdcBinWidth
Cached TDC bin width (ns).
Definition: RealisticTDCCountTranslator.h:154
Belle2::CDC::CDCSimControlPar::getTimeWalk
bool getTimeWalk() const
Get time-walk flag.
Definition: CDCSimControlPar.h:95