14 #define TRG_SHORT_NAMES
15 #define TRGCDC_SHORT_NAMES
20 #include <framework/dataobjects/EventMetaData.h>
21 #include "framework/datastore/StoreArray.h"
22 #include "framework/datastore/RelationArray.h"
23 #include "cdc/dataobjects/CDCHit.h"
24 #include "cdc/dataobjects/CDCSimHit.h"
25 #include "cdc/geometry/CDCGeometryPar.h"
26 #include "trg/trg/Debug.h"
27 #include "trg/trg/Utilities.h"
28 #include "trg/cdc/TRGCDC.h"
29 #include "trg/cdc/Layer.h"
30 #include "trg/cdc/Cell.h"
31 #include "trg/cdc/Wire.h"
32 #include "trg/cdc/WireHit.h"
33 #include "trg/cdc/Hough3DFinder.h"
34 #include "trg/cdc/Segment.h"
35 #include "trg/cdc/SegmentHit.h"
36 #include "trg/cdc/Circle.h"
37 #include "trg/cdc/Track.h"
38 #include "trg/cdc/Link.h"
39 #include "trg/cdc/Relation.h"
40 #include "trg/cdc/Fitter3DUtility.h"
41 #include "trg/cdc/Fitter3D.h"
42 #include "trg/cdc/HandleRoot.h"
52 TRGCDCHough3DFinder::TRGCDCHough3DFinder(
const TRGCDC&
TRGCDC,
bool makeRootFile,
int finderMode)
53 : _cdc(
TRGCDC), m_makeRootFile(makeRootFile) , m_finderMode(finderMode)
63 m_mBool[
"fIsIntegerEffect"] = 1;
79 for (
unsigned iSL = 0; iSL < 9; iSL++) {
86 for (
unsigned iAx = 0; iAx < 5; iAx++) {
90 m_mConstV[
"zToStraw"] = vector<double> (4);
91 m_mConstV[
"zToOppositeStraw"] = vector<double> (4);
92 m_mConstV[
"angleSt"] = vector<double> (4);
94 for (
int iSt = 0; iSt < 4; iSt++) {
105 for (
int iSt = 0; iSt < 4; iSt++)
m_mConstV[
"rr3D"][iSt] =
m_mConstV[
"rr"][iSt * 2 + 1];
106 m_mConstV[
"wirePhi2DError"] = vector<double> (5);
107 m_mConstV[
"driftPhi2DError"] = vector<double> (5);
121 m_mConstV[
"wirePhi2DError"][0] = 0.00085106;
122 m_mConstV[
"wirePhi2DError"][1] = 0.00039841;
123 m_mConstV[
"wirePhi2DError"][2] = 0.00025806;
124 m_mConstV[
"wirePhi2DError"][3] = 0.00019084;
125 m_mConstV[
"wirePhi2DError"][4] = 0.0001514;
126 m_mConstV[
"driftPhi2DError"][0] = 0.00085106;
127 m_mConstV[
"driftPhi2DError"][1] = 0.00039841;
128 m_mConstV[
"driftPhi2DError"][2] = 0.00025806;
129 m_mConstV[
"driftPhi2DError"][3] = 0.00019084;
130 m_mConstV[
"driftPhi2DError"][4] = 0.0001514;
149 m_mConstV[
"driftZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
150 m_mConstV[
"wireZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
154 for (
unsigned iSl = 0; iSl < 9; iSl++) {
155 string tableName =
"driftLengthTableSL" + to_string(iSl);
156 unsigned tableSize = 512;
157 m_mConstV[tableName] = vector<double> (tableSize);
159 for (
unsigned iTick = 0; iTick < tableSize; iTick++) {
161 double avgDriftLength = 0;
162 if (
m_mBool[
"fXtSimple"] == 1) {
165 double driftLength_0 = cdcp.
getDriftLength(t_driftTime, t_layer, 0);
166 double driftLength_1 = cdcp.
getDriftLength(t_driftTime, t_layer, 1);
167 avgDriftLength = (driftLength_0 + driftLength_1) / 2;
169 m_mConstV[tableName][iTick] = avgDriftLength;
174 TVectorD geometryHough3D(16);
175 for (
int i = 0; i < 4; i++) {
176 geometryHough3D[i] =
m_mConstV[
"rr"][2 * i + 1] / 100;
177 geometryHough3D[i + 4] =
m_mConstV[
"angleSt"][i];
178 geometryHough3D[i + 8] =
m_mConstV[
"zToStraw"][i] / 100;
179 geometryHough3D[i + 12] =
m_mConstV[
"nWires"][2 * i + 1];
191 float tempInitVariables[] = { -3, 3, -2, 2, 1001, 1001};
192 vector<float > initVariables(tempInitVariables, tempInitVariables +
sizeof(tempInitVariables) /
sizeof(tempInitVariables[0]));
197 m_mConstV[
"initVariablesHough3D"] = vector<double> (6);
198 m_mConstV[
"initVariablesHough3D"][0] = tempInitVariables[0];
199 m_mConstV[
"initVariablesHough3D"][1] = tempInitVariables[1];
200 m_mConstV[
"initVariablesHough3D"][2] = tempInitVariables[2];
201 m_mConstV[
"initVariablesHough3D"][3] = tempInitVariables[3];
202 m_mConstV[
"initVariablesHough3D"][4] = tempInitVariables[4];
203 m_mConstV[
"initVariablesHough3D"][5] = tempInitVariables[5];
224 for (
unsigned int iTrack = 0; iTrack < trackList2D.size(); iTrack++) {
225 TCTrack& aTrack = *
new TCTrack(* trackList2D[iTrack]);
226 trackList3D.push_back(& aTrack);
235 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
236 TCTrack& aTrack = *trackList[iTrack];
237 aTrack.setTrackID(iTrack + 1);
256 m_mDouble[
"eventNumber"] = eventMetaDataPtr->getEvent();;
259 vector<vector<double> > stTSs(4);
260 vector<vector<int> > stTSDrift(4);
261 vector<vector<const TCSHit*> > p_stTSs(4);
262 for (
unsigned iSL = 0; iSL < 4; iSL++) {
265 string slName =
"st" + to_string(iSL);
266 m_mEventV[slName +
"_hit"] = vector<double> ();
267 m_mEventV[slName +
"_driftHit"] = vector<double> ();
268 stTSs[iSL] = vector<double> ();
269 stTSDrift[iSL] = vector<int> ();
270 p_stTSs[iSL] = vector<const TCSHit*> ();
272 for (
unsigned iHit = 0; iHit < hits.size(); iHit++) {
273 if (hits[iHit] == 0)
continue;
279 double t_wirePhi = ((double)hits[iHit]->cell().localId()) /
m_mConstV[
"nWires"][2 * iSL + 1] * 4 *
m_mConstD[
"Trg_PI"];
280 m_mEventV[slName +
"_hit"].push_back(t_wirePhi);
282 int t_tdc = hits[iHit]->segment().priorityTime();
283 int t_lr = hits[iHit]->segment().LUT()->getValue(hits[iHit]->segment().lutPattern());;
284 int t_priorityPosition = hits[iHit]->segment().priorityPosition();
285 int t_driftInfo = (t_tdc << 4) + (t_lr << 2) + t_priorityPosition;
286 stTSs[iSL].push_back(t_wirePhi);
287 p_stTSs[iSL].push_back(hits[iHit]);
288 stTSDrift[iSL].push_back(t_driftInfo);
295 map<unsigned, unsigned> numberTSsForParticle;
300 for (
unsigned iTrack = 0; iTrack <
m_mEventD[
"nTracks"]; iTrack++) {
302 TCTrack& aTrack = * trackList[iTrack];
308 m_mDouble[
"trackId"] = aTrack.getTrackID();
312 if (fit2DResult != 0)
continue;
323 const TCSHit* p_bestTS[4] = {0, 0, 0, 0};
324 for (
int iSt = 0; iSt < 4; iSt++) {
325 if (
m_mVector[
"bestTSIndex"][iSt] == 999) p_bestTS[iSt] = 0;
326 else p_bestTS[iSt] = p_stTSs[iSt][(int)
m_mVector[
"bestTSIndex"][iSt]];
330 for (
unsigned iSt = 0; iSt < 4; iSt++) {
331 if (
m_mVector[
"bestTS"][iSt] != 999) aTrack.append(
new TCLink(0, p_bestTS[iSt], p_bestTS[iSt]->cell().xyPosition()));
361 const TCRelation& trackRelation3D = aTrack.relation3D();
362 m_mDouble[
"purity"] = trackRelation3D.purity3D(aTrack.relation2D().contributor(0));
363 m_mDouble[
"efficiency"] = trackRelation3D.efficiency3D(aTrack.relation2D().contributor(0), numberTSsForParticle);
365 m_mVector[
"mcTSs"] = vector<double> (4, 999);
366 vector<const TCSHit*> mcTSList;
368 for (
unsigned iTS = 0; iTS < mcTSList.size(); iTS++) {
369 int iSuperLayer = (int)(
double(mcTSList[iTS]->cell().superLayerId()) - 1) / 2;
370 m_mVector[
"mcTSs"][iSuperLayer] = (double)mcTSList[iTS]->cell().localId() /
m_mConstV[
"nWires"][2 * iSuperLayer + 1] * 4 *
374 m_mVector[
"mcTSsX"] = vector<double> (4);
375 m_mVector[
"mcTSsY"] = vector<double> (4);
376 for (
unsigned iTS = 0; iTS < mcTSList.size(); iTS++) {
377 unsigned iCDCSimHit = mcTSList[iTS]->iCDCSimHit();
378 CDCSimHit* aCDCSimHit = SimHits[iCDCSimHit];
384 m_mVector[
"perfectWireDiff"] = vector<double> (4);
385 m_mVector[
"perfectCalZ"] = vector<double> (4);
386 for (
unsigned iSt = 0; iSt < 4; iSt++) {
400 unsigned int mcParticleId = aTrack.relation2D().contributor(0);
401 for (
unsigned iSt = 0; iSt < 4; iSt++) {
402 string mcTsName =
"mcTsSt" + to_string(iSt);
406 for (
unsigned iTS = 0; iTS < hits.size(); iTS++) {
407 if (hits[iTS]->iMCParticle() == mcParticleId)
m_mVector[mcTsName].push_back((
double)hits[iTS]->cell().localId() /
434 HandleRoot::saveTrackValues(
"hough3D",
443 HandleRoot::saveEventValues(
"hough3D",
451 if (
m_mBool[
"debugEfficiency"]) {
453 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
455 TCTrack& aTrack = * trackList[iTrack];
457 int nPriorityHitSL = 0;
458 for (
unsigned iSt = 0; iSt < 4; iSt++) {
459 int priorityHitSL = 0;
460 for (
unsigned iTS = 0; iTS < stTSDrift[iSt].size(); iTS++) {
461 int t_priorityPosition = (stTSDrift[iSt][iTS] & 3);
462 if (t_priorityPosition == 3) priorityHitSL = 1;
465 if (priorityHitSL) nPriorityHitSL++;
470 if (
m_mDouble[
"efficiency"] != nPriorityHitSL * 1. / 4) {
471 aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::find3D, 1);
478 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
479 unsigned nHitStSl = 0;
480 for (
unsigned iSt = 0; iSt < 4; iSt++) {
481 if (trackList[iTrack]->links(2 * iSt + 1).size() != 0) nHitStSl++;
483 if (nHitStSl < 2) trackList[iTrack]->setDebugValue(TRGCDCTrack::EDebugValueType::find3D, 1);
500 unsigned id = trackList[j]->relation().contributor(0);
501 vector<const TCSHit*> tsList[9];
506 for (
unsigned i = 0; i < hits.size(); i++) {
507 const TCSHit& ts = * hits[i];
508 if (ts.segment().axial())
continue;
509 if (! ts.signal().active())
continue;
510 const TCWHit* wh = ts.segment().center().hit();
512 const unsigned trackId = wh->iMCParticle();
523 tsList[wh->wire().superLayerId()].push_back(& ts);
527 for (
unsigned k = 0; k < 9; k++) {
530 for (
unsigned l = 0; l < tsList[k].size(); l++) {
533 cout << tsList[k][l]->cell().name();
541 for (
unsigned i = 0; i < 9; i++) {
542 const TCSHit* best = 0;
543 if (tsList[i].size() == 0) {
545 }
else if (tsList[i].size() == 1) {
549 for (
unsigned k = 0; k < tsList[i].size(); k++) {
550 const TRGSignal& timing = tsList[i][k]->signal();
551 const TRGTime& t = * timing[0];
552 if (t.time() < timeMin) {
558 mcTSList.push_back(best);
569 cout <<
TRGDebug::tab() <<
"givenTrk#=" << trackList.size() << endl;
573 for (
unsigned j = 0; j < trackList.size(); j++) {
575 TCTrack* trk = trackList[j];
577 vector<const TCSHit*> mcTSList;
579 for (
unsigned iTS = 0; iTS < mcTSList.size(); iTS++) {
580 trk->append(
new TCLink(0, mcTSList[iTS], mcTSList[iTS]->cell().xyPosition()));
593 map<unsigned, unsigned>& numberTSsForParticle)
595 vector<unsigned> mcParticleList;
596 for (
unsigned iLayer = 0; iLayer < 4; iLayer++) {
598 mcParticleList.clear();
599 for (
unsigned iTS = 0; iTS < p_stTSs[iLayer].size(); iTS++) {
600 unsigned iMCParticle = p_stTSs[iLayer][iTS]->iMCParticle();
601 if (find(mcParticleList.begin(), mcParticleList.end(), iMCParticle) == mcParticleList.end()) {
602 mcParticleList.push_back(iMCParticle);
606 for (
unsigned iMCPart = 0; iMCPart < mcParticleList.size(); iMCPart++) {
607 map<unsigned, unsigned>::iterator it = numberTSsForParticle.find(mcParticleList[iMCPart]);
608 if (it != numberTSsForParticle.end()) ++it->second;
609 else numberTSsForParticle[mcParticleList[iMCPart]] = 1;