Belle II Software  release-05-02-19
CDCTrigger2DFitterModule.cc
1 #include "trg/cdc/modules/fitting/CDCTrigger2DFitterModule.h"
2 
3 #include <framework/datastore/RelationVector.h>
4 
5 #include <cdc/geometry/CDCGeometryPar.h>
6 #include <trg/cdc/Fitter3DUtility.h>
7 
8 using namespace std;
9 using namespace Belle2;
10 
11 //this line registers the module with the framework and actually makes it available
12 //in steering files or the the module list (basf2 -m).
13 REG_MODULE(CDCTrigger2DFitter);
14 
15 CDCTrigger2DFitterModule::CDCTrigger2DFitterModule() : Module::Module()
16 {
18  "The 2D fitter module of the CDC trigger.\n"
19  "Performs a circle fit on a given set of axial CDCTriggerSegmentHits.\n"
20  "Requires a preceding track finder to sort hits to tracks.\n"
21  );
23  addParam("hitCollectionName", m_hitCollectionName,
24  "Name of the input StoreArray of CDCTriggerSegmentHits.",
25  string(""));
26  addParam("EventTimeName", m_EventTimeName,
27  "Name of the event time object.",
28  string(""));
29  addParam("inputCollectionName", m_inputCollectionName,
30  "Name of the StoreArray holding the input tracks from the track finder.",
31  string("TRGCDC2DFinderTracks"));
32  addParam("outputCollectionName", m_outputCollectionName,
33  "Name of the StoreArray holding the fitted output tracks.",
34  string("TRGCDC2DFitterTracks"));
35  addParam("minHits", m_minHits,
36  "Minimal number of hits required for the fitting.",
37  unsigned(2));
38  addParam("xtSimple", m_xtSimple,
39  "If true, use nominal drift velocity, otherwise use table "
40  "for non-linear xt.",
41  false);
42  addParam("useDriftTime", m_useDriftTime,
43  "If true, use drift time, otherwise only wire position.",
44  true);
45 }
46 
47 void
49 {
50  // register DataStore elements
52  m_fitterTracks.registerInDataStore(m_outputCollectionName);
54  segmentHits.isRequired(m_hitCollectionName);
55  if (m_useDriftTime)
56  m_eventTime.isRequired(m_EventTimeName);
57  // register relations
58  m_finderTracks.registerRelationTo(m_fitterTracks);
59  m_finderTracks.requireRelationTo(segmentHits);
60  m_fitterTracks.registerRelationTo(segmentHits);
61 
62  // get geometry constants for first priority layers
64  // TODO: avoid hard coding the priority layers here
65  vector<unsigned> iL = {3, 16, 28, 40, 52};
66  for (int iAx = 0; iAx < 5; ++iAx) {
67  nWires.push_back(cdc.nWiresInLayer(iL[iAx]));
68  rr.push_back(cdc.senseWireR(iL[iAx]));
69  vector<double> xt(512);
70  for (unsigned iTick = 0; iTick < xt.size(); ++iTick) {
71  double t = iTick * 2 * cdc.getTdcBinWidth();
72  if (m_xtSimple) {
73  xt[iTick] = cdc.getNominalDriftV() * t;
74  } else {
75  double driftLength_0 = cdc.getDriftLength(t, iL[iAx], 0);
76  double driftLength_1 = cdc.getDriftLength(t, iL[iAx], 1);
77  xt[iTick] = (driftLength_0 + driftLength_1) / 2;
78  }
79  }
80  xtTables.push_back(xt);
81  }
82 }
83 
84 void
86 {
87  int T0 = (m_eventTime->hasBinnedEventT0(Const::CDC))
88  ? m_eventTime->getBinnedEventT0(Const::CDC)
89  : 9999;
90 
91  vector<double> wirePhi2DError({0.00085106,
92  0.00039841,
93  0.00025806,
94  0.00019084,
95  0.0001514
96  });
97  vector<double> driftPhi2DError({0.00085106,
98  0.00039841,
99  0.00025806,
100  0.00019084,
101  0.0001514
102  });
103 
104  for (int itrack = 0; itrack < m_finderTracks.getEntries(); ++itrack) {
105  // get selected hits (positive relation weight)
107  m_finderTracks[itrack]->getRelationsTo<CDCTriggerSegmentHit>(m_hitCollectionName);
108  unsigned nHits = 0;
109  vector<double> tsId(5, -1.);
110  vector<double> wirePhi(5, 0.);
111  vector<int> driftTime(5, 0);
112  vector<double> driftLength(5, 0.);
113  vector<unsigned> LR(5, 0);
114  vector<int> hitIds(5, -1);
115  vector<double> useSL(5, 0.);
116  for (unsigned ihit = 0; ihit < hits.size(); ++ihit) {
117  if (hits.weight(ihit) > 0) {
118  // use only first priority hits
119  if (hits[ihit]->getPriorityPosition() != 3) continue;
120  unsigned iSL = hits[ihit]->getISuperLayer();
121  // skip stereo hits (should not be related, but check anyway)
122  if (iSL % 2) continue;
123  // the track finder should have selected a single hit per super layer
124  // if that is not the case, select the fastest hit
125  if (hitIds[iSL / 2] != -1) {
126  B2WARNING("got multiple hits for SL " << iSL);
127  if (hits[ihit]->priorityTime() >= driftTime[iSL / 2])
128  continue;
129  } else {
130  nHits += 1;
131  }
132  useSL[iSL / 2] = 1.;
133  hitIds[iSL / 2] = ihit;
134  tsId[iSL / 2] = hits[ihit]->getIWire();
135  wirePhi[iSL / 2] = hits[ihit]->getIWire() * 2. * M_PI / nWires[iSL / 2];
136  LR[iSL / 2] = hits[ihit]->getLeftRight();
137  driftTime[iSL / 2] = hits[ihit]->priorityTime();
138  int t = hits[ihit]->priorityTime() - T0;
139  if (t < 0) t = 0;
140  if (t > 511) t = 511;
141  driftLength[iSL / 2] = xtTables[iSL / 2][t];
142  }
143  }
144  if (nHits < m_minHits) {
145  B2DEBUG(20, "Not enough hits to do 2D fit (" << m_minHits << " needed, got " << nHits << ")");
146  continue;
147  }
148 
149  // Set phi2DError for 2D fit
150  vector<double> phi2DInvError(5, 0.);
151  for (unsigned iAx = 0; iAx < 5; ++iAx) {
152  if (LR[iAx] == 0) continue;
153  if (LR[iAx] != 3 && T0 != 9999)
154  phi2DInvError[iAx] = 1. / driftPhi2DError[iAx];
155  else
156  phi2DInvError[iAx] = 1. / wirePhi2DError[iAx];
157  }
158  // Calculate phi2D using driftLength.
159  vector<double> phi2D(5, 0.);
160  for (unsigned iAx = 0; iAx < 5; ++iAx) {
161  if (hitIds[iAx] < 0) continue;
162  if (T0 == 9999 || !m_useDriftTime)
163  phi2D[iAx] = wirePhi[iAx];
164  else
165  phi2D[iAx] = Fitter3DUtility::calPhi(wirePhi[iAx], driftLength[iAx], rr[iAx], LR[iAx]);
166  }
167  // Fit2D
168  double rho = 0;
169  double phi0 = 0;
170  double chi2 = 0;
171  Fitter3DUtility::rPhiFitter(&rr[0], &phi2D[0], &phi2DInvError[0], rho, phi0, chi2);
172  double charge = m_finderTracks[itrack]->getChargeSign();
173  double chargeFit = 0;
174  Fitter3DUtility::chargeFinder(&nWires[0], &tsId[0], &useSL[0], phi0,
175  charge, chargeFit);
176  double omega = chargeFit / rho;
177 
178  // save track
179  CDCTriggerTrack* fittedTrack =
180  m_fitterTracks.appendNew(remainder(phi0 + chargeFit * M_PI_2, 2. * M_PI),
181  omega, chi2);
182  // make relation to finder track
183  m_finderTracks[itrack]->addRelationTo(fittedTrack);
184  // make relation to hits
185  for (unsigned iAx = 0; iAx < 5; ++iAx) {
186  if (hitIds[iAx] >= 0)
187  fittedTrack->addRelationTo(hits[hitIds[iAx]]);
188  }
189  }
190 }
Belle2::CDCTrigger2DFitterModule::initialize
virtual void initialize() override
Initialize the module and register DataStore arrays.
Definition: CDCTrigger2DFitterModule.cc:48
Belle2::CDCTrigger2DFitterModule::m_useDriftTime
bool m_useDriftTime
Switch between drift time and wire position for phi.
Definition: CDCTrigger2DFitterModule.h:51
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
Belle2::CDCTrigger2DFitterModule::rr
std::vector< double > rr
geometry constants: radius of priority layers
Definition: CDCTrigger2DFitterModule.h:57
Belle2::CDCTrigger2DFitterModule::m_inputCollectionName
std::string m_inputCollectionName
Name of the StoreArray containing the input tracks from the finder.
Definition: CDCTrigger2DFitterModule.h:43
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module::c_ParallelProcessingCertified
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:82
Belle2::CDCTrigger2DFitterModule::m_EventTimeName
std::string m_EventTimeName
name of the event time StoreObjPtr
Definition: CDCTrigger2DFitterModule.h:41
Belle2::CDCTriggerTrack
Track created by the CDC trigger.
Definition: CDCTriggerTrack.h:15
Belle2::CDCTrigger2DFitterModule::m_eventTime
StoreObjPtr< BinnedEventT0 > m_eventTime
StoreObjPtr contraining the event time.
Definition: CDCTrigger2DFitterModule.h:66
Belle2::CDCTrigger2DFitterModule::m_outputCollectionName
std::string m_outputCollectionName
Name of the StoreArray containing the resulting fitted tracks.
Definition: CDCTrigger2DFitterModule.h:45
Belle2::CDCTrigger2DFitterModule::m_xtSimple
bool m_xtSimple
Switch between nominal drift velocity and xt table.
Definition: CDCTrigger2DFitterModule.h:49
Belle2::CDCTrigger2DFitterModule::event
virtual void event() override
Run the 2D fitter for an event.
Definition: CDCTrigger2DFitterModule.cc:85
Belle2::CDCTrigger2DFitterModule::m_hitCollectionName
std::string m_hitCollectionName
Name of the StoreArray containing the input track segment hits.
Definition: CDCTrigger2DFitterModule.h:39
Belle2::CDCTrigger2DFitterModule::xtTables
std::vector< std::vector< double > > xtTables
geometry constants: drift length - drift time relation
Definition: CDCTrigger2DFitterModule.h:59
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::Module::setPropertyFlags
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:210
Belle2::CDC::CDCGeometryPar
The Class for CDC Geometry Parameters.
Definition: CDCGeometryPar.h:75
Fitter3DUtility::rPhiFitter
static void rPhiFitter(double *rr, double *phi2, double *invphierror, double &rho, double &myphi0)
A circle fitter with invPhiError without fit chi2 output.
Definition: Fitter3DUtility.cc:69
Fitter3DUtility::calPhi
static double calPhi(double wirePhi, double driftLength, double rr, int lr)
Pre 3D fitter functions. rr is in cm scale. driftLength is in cm scale.
Definition: Fitter3DUtility.cc:239
Belle2::RelationVector
Class for type safe access to objects that are referred to in relations.
Definition: DataStore.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::CDCTrigger2DFitterModule::m_finderTracks
StoreArray< CDCTriggerTrack > m_finderTracks
list of input tracks from finder
Definition: CDCTrigger2DFitterModule.h:62
Belle2::CDCTrigger2DFitterModule::m_fitterTracks
StoreArray< CDCTriggerTrack > m_fitterTracks
list of output tracks from fitter
Definition: CDCTrigger2DFitterModule.h:64
Belle2::Module::addParam
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:562
Belle2::CDCTrigger2DFitterModule::m_minHits
unsigned m_minHits
Minimal number of hits required for fitting.
Definition: CDCTrigger2DFitterModule.h:47
Belle2::CDCTrigger2DFitterModule::nWires
std::vector< double > nWires
geometry constants: number of wires per super layer
Definition: CDCTrigger2DFitterModule.h:55
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Fitter3DUtility::chargeFinder
static void chargeFinder(double *nTSs, double *tsIds, double *tsHitmap, double phi0, double inCharge, double &outCharge)
Charge finder using circle fitter output and axial TSs.
Definition: Fitter3DUtility.cc:140
Belle2::CDCTriggerSegmentHit
Combination of several CDCHits to a track segment hit for the trigger.
Definition: CDCTriggerSegmentHit.h:16