8#include "trg/cdc/modules/fitting/CDCTrigger2DFitterModule.h"
10#include <framework/datastore/RelationVector.h>
12#include <cdc/geometry/CDCGeometryPar.h>
13#include <trg/cdc/Fitter3DUtility.h>
25 "The 2D fitter module of the CDC trigger.\n"
26 "Performs a circle fit on a given set of axial CDCTriggerSegmentHits.\n"
27 "Requires a preceding track finder to sort hits to tracks.\n"
31 "Name of the input StoreArray of CDCTriggerSegmentHits.",
34 "Name of the event time object.",
37 "Name of the StoreArray holding the input tracks from the track finder.",
38 string(
"TRGCDC2DFinderTracks"));
40 "Name of the StoreArray holding the fitted output tracks.",
41 string(
"TRGCDC2DFitterTracks"));
43 "Minimal number of hits required for the fitting.",
46 "If true, use nominal drift velocity, otherwise use table "
50 "If true, use drift time, otherwise only wire position.",
72 vector<unsigned> iL = {3, 16, 28, 40, 52};
73 for (
int iAx = 0; iAx < 5; ++iAx) {
74 nWires.push_back(cdc.nWiresInLayer(iL[iAx]));
75 rr.push_back(cdc.senseWireR(iL[iAx]));
76 vector<double> xt(512);
77 for (
unsigned iTick = 0; iTick < xt.size(); ++iTick) {
78 double t = iTick * 2 * cdc.getTdcBinWidth();
80 xt[iTick] = cdc.getNominalDriftV() * t;
82 double driftLength_0 = cdc.getDriftLength(t, iL[iAx], 0);
83 double driftLength_1 = cdc.getDriftLength(t, iL[iAx], 1);
84 xt[iTick] = (driftLength_0 + driftLength_1) / 2;
98 vector<double> wirePhi2DError({0.00085106,
104 vector<double> driftPhi2DError({0.00085106,
116 vector<double> tsId(5, -1.);
117 vector<double> wirePhi(5, 0.);
118 vector<int> driftTime(5, 0);
119 vector<double> driftLength(5, 0.);
120 vector<unsigned> LR(5, 0);
121 vector<int> hitIds(5, -1);
122 vector<double> useSL(5, 0.);
123 for (
unsigned ihit = 0; ihit < hits.size(); ++ihit) {
124 if (hits.weight(ihit) > 0) {
126 if (hits[ihit]->getPriorityPosition() != 3)
continue;
127 unsigned iSL = hits[ihit]->getISuperLayer();
129 if (iSL % 2)
continue;
132 if (hitIds[iSL / 2] != -1) {
133 B2WARNING(
"got multiple hits for SL " << iSL);
134 if (hits[ihit]->priorityTime() >= driftTime[iSL / 2])
140 hitIds[iSL / 2] = ihit;
141 tsId[iSL / 2] = hits[ihit]->getIWire();
142 wirePhi[iSL / 2] = hits[ihit]->getIWire() * 2. * M_PI /
nWires[iSL / 2];
143 LR[iSL / 2] = hits[ihit]->getLeftRight();
144 driftTime[iSL / 2] = hits[ihit]->priorityTime();
145 int t = hits[ihit]->priorityTime() - T0;
147 if (t > 511) t = 511;
148 driftLength[iSL / 2] =
xtTables[iSL / 2][t];
152 B2DEBUG(20,
"Not enough hits to do 2D fit (" <<
m_minHits <<
" needed, got " << nHits <<
")");
157 vector<double> phi2DInvError(5, 0.);
158 for (
unsigned iAx = 0; iAx < 5; ++iAx) {
159 if (LR[iAx] == 0)
continue;
160 if (LR[iAx] != 3 && T0 != 9999)
161 phi2DInvError[iAx] = 1. / driftPhi2DError[iAx];
163 phi2DInvError[iAx] = 1. / wirePhi2DError[iAx];
166 vector<double> phi2D(5, 0.);
167 for (
unsigned iAx = 0; iAx < 5; ++iAx) {
168 if (hitIds[iAx] < 0)
continue;
170 phi2D[iAx] = wirePhi[iAx];
180 double chargeFit = 0;
183 double omega = chargeFit / rho;
192 for (
unsigned iAx = 0; iAx < 5; ++iAx) {
193 if (hitIds[iAx] >= 0)
194 fittedTrack->addRelationTo(hits[hitIds[iAx]]);
bool hasBinnedEventT0(const Const::EDetector detector) const
Check if one of the detectors in the given set has a binned t0 estimation.
int getBinnedEventT0(const Const::EDetector detector) const
Return the stored binned event t0 for the given detector or 0 if nothing stored.
std::string m_EventTimeName
name of the event time StoreObjPtr
virtual void initialize() override
Initialize the module and register DataStore arrays.
virtual void event() override
Run the 2D fitter for an event.
CDCTrigger2DFitterModule()
Constructor, for setting module description and parameters.
std::string m_outputCollectionName
Name of the StoreArray containing the resulting fitted tracks.
StoreArray< CDCTriggerTrack > m_finderTracks
list of input tracks from finder
std::string m_inputCollectionName
Name of the StoreArray containing the input tracks from the finder.
std::vector< std::vector< double > > xtTables
geometry constants: drift length - drift time relation
bool m_xtSimple
Switch between nominal drift velocity and xt table.
bool m_useDriftTime
Switch between drift time and wire position for phi.
StoreArray< CDCTriggerTrack > m_fitterTracks
list of output tracks from fitter
unsigned m_minHits
Minimal number of hits required for fitting.
StoreObjPtr< BinnedEventT0 > m_eventTime
StoreObjPtr contraining the event time.
std::vector< double > nWires
geometry constants: number of wires per super layer
std::vector< double > rr
geometry constants: radius of priority layers
std::string m_hitCollectionName
Name of the StoreArray containing the input track segment hits.
Combination of several CDCHits to a track segment hit for the trigger.
Track created by the CDC trigger.
The Class for CDC Geometry Parameters.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Class for type safe access to objects that are referred to in relations.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
bool requireRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, const std::string &namedRelation="") const
Produce error if no relation from this array to 'toArray' has been registered.
T * appendNew()
Construct a new T object at the end of the array.
int getEntries() const
Get the number of objects in the array.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
static void rPhiFitter(double *rr, double *phi2, double *invphierror, double &rho, double &myphi0)
A circle fitter with invPhiError without fit chi2 output.
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.
static void chargeFinder(double *nTSs, double *tsIds, double *tsHitmap, double phi0, double inCharge, double &outCharge)
Charge finder using circle fitter output and axial TSs.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.