1 #include "trg/cdc/modules/fitting/CDCTrigger3DFitterModule.h"
3 #include <framework/datastore/RelationVector.h>
5 #include <cdc/geometry/CDCGeometryPar.h>
6 #include <trg/cdc/Fitter3DUtility.h>
7 #include <trg/cdc/Fitter3D.h>
8 #include <trg/cdc/JSignal.h>
9 #include <trg/cdc/JSignalData.h>
18 CDCTrigger3DFitterModule::CDCTrigger3DFitterModule() :
Module::
Module()
21 "The 3D fitter module of the CDC trigger.\n"
22 "Selects stereo hits around a given 2D track and performs a linear fit "
23 "in the s-z plane (s: 2D arclength).\n"
27 "Name of the input StoreArray of CDCTriggerSegmentHits.",
30 "Name of the event time object.",
33 "Name of the StoreArray holding the input tracks from the 2D fitter.",
34 string(
"TRGCDC2DFitterTracks"));
36 "Name of the StoreArray holding the 3D output tracks.",
37 string(
"TRGCDC3DFitterTracks"));
39 "Fitter mode: 1: fast, 2: firmware",
42 "Minimal number of hits required for the fitting.",
45 "If true, use nominal drift velocity, otherwise use table "
49 "If true, prints detail information.",
78 vector<unsigned> iL = {10, 22, 34, 46};
79 for (
int iSt = 0; iSt < 4; ++iSt) {
80 nWires.push_back(cdc.nWiresInLayer(iL[iSt]));
81 rr.push_back(cdc.senseWireR(iL[iSt]));
82 zToStraw.push_back(cdc.senseWireBZ(iL[iSt]));
83 nShift.push_back(cdc.nShifts(iL[iSt]));
85 (cdc.senseWireFZ(iL[iSt]) -
zToStraw.back()));
86 vector<double> xt(512);
87 for (
unsigned iTick = 0; iTick < xt.size(); ++iTick) {
88 double t = iTick * 2 * cdc.getTdcBinWidth();
90 xt[iTick] = cdc.getNominalDriftV() * t;
92 double driftLength_0 = cdc.getDriftLength(t, iL[iSt], 0);
93 double driftLength_1 = cdc.getDriftLength(t, iL[iSt], 1);
94 xt[iTick] = (driftLength_0 + driftLength_1) / 2;
108 cout <<
"Event" << endl;
110 cout <<
"----Stereo TS----" << endl;
111 for (
int iHit = 0; iHit <
m_hits.getEntries(); ++iHit) {
112 if (
m_hits[iHit]->getISuperLayer() % 2 != 0)
113 cout <<
"sl-iWire:" <<
m_hits[iHit]->getISuperLayer() <<
"-" <<
m_hits[iHit]->getIWire() <<
" pr:" <<
114 m_hits[iHit]->getPriorityPosition() <<
" lr:" <<
m_hits[iHit]->getLeftRight() <<
" rt:" <<
m_hits[iHit]->getTDCCount() <<
" dt:" <<
115 m_hits[iHit]->priorityTime() << endl;
117 cout <<
"----Stereo TS----" << endl;
118 cout <<
"----EventTime----" << endl;
120 cout <<
"eventTimeValid: " <<
m_eventTime->hasBinnedEventT0(Const::CDC);
121 if (
m_eventTime->hasBinnedEventT0(Const::CDC)) cout <<
" eventTime: " <<
m_eventTime->getBinnedEventT0(Const::CDC);
123 cout <<
"----EventTime----" << endl;
124 cout <<
"----2D----" << endl;
126 for (
int iTrack = 0; iTrack <
m_tracks2D.getEntries(); ++iTrack) {
127 cout <<
"2D charge: " <<
m_tracks2D[iTrack]->getChargeSign() <<
" pt: " << 1. / abs(
m_tracks2D[iTrack]->getOmega()) * 1.5 * 0.3 *
128 0.01 <<
" phi0_i: " <<
m_tracks2D[iTrack]->getPhi0() << endl;
130 cout <<
"----2D----" << endl;
133 for (
int itrack = 0; itrack <
m_tracks2D.getEntries(); ++itrack) {
134 int charge =
m_tracks2D[itrack]->getChargeSign();
135 double rho = 1. / abs(
m_tracks2D[itrack]->getOmega());
136 double phi =
m_tracks2D[itrack]->getPhi0() - charge * M_PI_2;
139 vector<int> bestTSIndex(4, -1);
140 vector<double> bestTSPhi(4, 9999);
141 finder(charge, rho, phi, bestTSIndex, bestTSPhi);
144 cout <<
"----Found Stereo TS----" << endl;
145 for (
unsigned iSt = 0; iSt < 4; ++iSt) {
146 if (bestTSIndex[iSt] == -1)
continue;
147 cout <<
"sl-iWire:" << iSt * 2 + 1 <<
"-" <<
m_hits[bestTSIndex[iSt]]->getIWire() <<
" pr:" <<
148 m_hits[bestTSIndex[iSt]]->getPriorityPosition() <<
" lr:" <<
m_hits[bestTSIndex[iSt]]->getLeftRight() <<
" rt:" <<
149 m_hits[bestTSIndex[iSt]]->getTDCCount() <<
" dt:" <<
m_hits[bestTSIndex[iSt]]->priorityTime() << endl;
151 cout <<
"----Found Stereo TS----" << endl;
152 cout <<
"----2D----" << endl;
153 cout <<
"charge: " << charge <<
" radius: " << rho <<
" phi0_c: " << phi << endl;
154 cout <<
"----2D----" << endl;
159 for (
unsigned iSt = 0; iSt < 4; ++iSt) {
160 if (bestTSIndex[iSt] != -1) {
165 B2DEBUG(100,
"Not enough hits to do 3D fit (" <<
m_minHits <<
" needed, got " << nHits <<
")");
173 fitter(bestTSIndex, bestTSPhi, charge, rho, phi, z0, cot, chi2);
178 if (isnan(z0) || isnan(cot) || isnan(chi2)) {
179 B2DEBUG(100,
"3D fit failed");
189 m_tracks2D[itrack]->addRelationTo(fittedTrack);
191 for (
unsigned iSt = 0; iSt < 4; ++iSt) {
192 if (bestTSIndex[iSt] != -1)
193 fittedTrack->addRelationTo(
m_hits[bestTSIndex[iSt]]);
198 for (
unsigned ihit = 0; ihit < axialHits.
size(); ++ihit) {
199 fittedTrack->addRelationTo(axialHits[ihit]);
206 vector<int>& bestTSIndex, vector<double>& bestTSPhi)
208 vector<double> stAxPhi(4);
209 for (
int iSt = 0; iSt < 4; ++iSt) {
214 vector<vector<int>> candidatesIndex(4, vector<int>());
215 vector<vector<double>> candidatesPhi(4, vector<double>());
216 vector<vector<double>> candidatesDiffStWires(4, vector<double>());
217 for (
int ihit = 0; ihit <
m_hits.getEntries(); ++ihit) {
222 if (
m_hits[ihit]->getPriorityPosition() != 3)
continue;
224 unsigned iSL =
m_hits[ihit]->getISuperLayer();
225 if (iSL % 2 == 0)
continue;
227 if (2 * rho <
rr[iSL / 2])
continue;
229 double wirePhi =
m_hits[ihit]->getIWire() * 2. * M_PI /
nWires[iSL / 2];
230 double tsDiffSt = stAxPhi[iSL / 2] - wirePhi;
231 if (tsDiffSt > M_PI) tsDiffSt -= 2 * M_PI;
232 if (tsDiffSt < -M_PI) tsDiffSt += 2 * M_PI;
233 tsDiffSt = tsDiffSt / 2 / M_PI *
nWires[iSL / 2];
235 if ((iSL / 2) % 2 == 0) {
236 if (tsDiffSt > 0 && tsDiffSt <= 10) {
237 candidatesIndex[iSL / 2].push_back(ihit);
238 candidatesPhi[iSL / 2].push_back(wirePhi);
239 candidatesDiffStWires[iSL / 2].push_back(tsDiffSt);
242 if (tsDiffSt < 0 && tsDiffSt >= -10) {
243 candidatesIndex[iSL / 2].push_back(ihit);
244 candidatesPhi[iSL / 2].push_back(wirePhi);
245 candidatesDiffStWires[iSL / 2].push_back(tsDiffSt);
252 double meanWireDiff[4] = { 3.68186, 3.3542, 3.9099, 4.48263 };
253 for (
int iSt = 0; iSt < 4; ++iSt) {
256 double bestDiff = 9999;
257 for (
int iTS = 0; iTS < int(candidatesIndex[iSt].size()); ++iTS) {
258 double diff = abs(abs(candidatesDiffStWires[iSt][iTS]) - meanWireDiff[iSt]);
260 if (diff < bestDiff) {
262 bestTSPhi[iSt] = candidatesPhi[iSt][iTS];
263 bestTSIndex[iSt] = candidatesIndex[iSt][iTS];
279 int charge,
double rho,
double phi,
280 double& z0,
double& cot,
double& chi2)
286 vector<vector<int> > rawStTSs(4, vector<int> (3));
287 for (
unsigned iSt = 0; iSt < 4; ++iSt) {
288 if (bestTSIndex[iSt] == -1)
continue;
289 rawStTSs[iSt][0] =
m_hits[bestTSIndex[iSt]]->getIWire();
290 rawStTSs[iSt][1] =
m_hits[bestTSIndex[iSt]]->getLeftRight();
291 rawStTSs[iSt][2] =
m_hits[bestTSIndex[iSt]]->priorityTime();
293 int eventTimeValid = 0;
297 eventTime =
m_eventTime->getBinnedEventT0(Const::CDC);
302 if (phi_c > M_PI) phi_c -= 2 * M_PI;
303 if (phi_c < -M_PI) phi_c += 2 * M_PI;
305 vector<double> arcS(4, 0);
306 vector<double> zz(4, 0);
307 vector<double> invZError2(4, 0);
311 z0, cot, chi2, arcS, zz, invZError2);
319 for (
int iSt = 0; iSt < 4; iSt++) {
320 invZError2[iSt] =
m_mSignalStorage[
"iZError2_" + to_string(iSt)].getRealInt();
327 cout <<
"----3D----" << endl;
328 cout <<
"arcS [0]: " << arcS[0] <<
" [1]: " << arcS[1] <<
" [2]: " << arcS[2] <<
" [3]: " << arcS[3] << endl;
329 cout <<
"zz [0]: " << zz[0] <<
" [1]: " << zz[1] <<
" [2]: " << zz[2] <<
" [3]: " << zz[3] << endl;
330 cout <<
"invZError2 [0]: " << invZError2[0] <<
" [1]: " << invZError2[1] <<
" [2]: " << invZError2[2] <<
" [3]: " << invZError2[3]
332 cout <<
"z0: " << z0 <<
" cot: " << cot <<
" chi2: " << chi2 << endl;
333 cout <<
"----3D----" << endl;