13#define TRG_SHORT_NAMES
14#define TRGCDC_SHORT_NAMES
19#include <framework/dataobjects/EventMetaData.h>
20#include "framework/datastore/StoreArray.h"
21#include "framework/datastore/RelationArray.h"
22#include "cdc/dataobjects/CDCHit.h"
23#include "cdc/dataobjects/CDCSimHit.h"
24#include "cdc/geometry/CDCGeometryPar.h"
25#include "trg/trg/Debug.h"
26#include "trg/trg/Utilities.h"
27#include "trg/cdc/TRGCDC.h"
28#include "trg/cdc/Layer.h"
29#include "trg/cdc/Cell.h"
30#include "trg/cdc/Wire.h"
31#include "trg/cdc/WireHit.h"
32#include "trg/cdc/Hough3DFinder.h"
33#include "trg/cdc/Segment.h"
34#include "trg/cdc/SegmentHit.h"
35#include "trg/cdc/Circle.h"
36#include "trg/cdc/TRGCDCTrack.h"
37#include "trg/cdc/Link.h"
38#include "trg/cdc/Relation.h"
39#include "trg/cdc/Fitter3DUtility.h"
40#include "trg/cdc/Fitter3D.h"
41#include "trg/cdc/HandleRoot.h"
52 : _cdc(
TRGCDC), m_makeRootFile(makeRootFile), m_finderMode(finderMode)
62 m_mBool[
"fIsIntegerEffect"] = 1;
78 for (
unsigned iSL = 0; iSL < 9; iSL++) {
85 for (
unsigned iAx = 0; iAx < 5; iAx++) {
89 m_mConstV[
"zToStraw"] = vector<double> (4);
90 m_mConstV[
"zToOppositeStraw"] = vector<double> (4);
91 m_mConstV[
"angleSt"] = vector<double> (4);
93 for (
int iSt = 0; iSt < 4; iSt++) {
104 for (
int iSt = 0; iSt < 4; iSt++)
m_mConstV[
"rr3D"][iSt] =
m_mConstV[
"rr"][iSt * 2 + 1];
105 m_mConstV[
"wirePhi2DError"] = vector<double> (5);
106 m_mConstV[
"driftPhi2DError"] = vector<double> (5);
120 m_mConstV[
"wirePhi2DError"][0] = 0.00085106;
121 m_mConstV[
"wirePhi2DError"][1] = 0.00039841;
122 m_mConstV[
"wirePhi2DError"][2] = 0.00025806;
123 m_mConstV[
"wirePhi2DError"][3] = 0.00019084;
124 m_mConstV[
"wirePhi2DError"][4] = 0.0001514;
125 m_mConstV[
"driftPhi2DError"][0] = 0.00085106;
126 m_mConstV[
"driftPhi2DError"][1] = 0.00039841;
127 m_mConstV[
"driftPhi2DError"][2] = 0.00025806;
128 m_mConstV[
"driftPhi2DError"][3] = 0.00019084;
129 m_mConstV[
"driftPhi2DError"][4] = 0.0001514;
148 m_mConstV[
"driftZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
149 m_mConstV[
"wireZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
153 for (
unsigned iSl = 0; iSl < 9; iSl++) {
154 string tableName =
"driftLengthTableSL" + to_string(iSl);
155 unsigned tableSize = 512;
156 m_mConstV[tableName] = vector<double> (tableSize);
158 for (
unsigned iTick = 0; iTick < tableSize; iTick++) {
160 double avgDriftLength = 0;
161 if (
m_mBool[
"fXtSimple"] == 1) {
164 double driftLength_0 = cdcp.
getDriftLength(t_driftTime, t_layer, 0);
165 double driftLength_1 = cdcp.
getDriftLength(t_driftTime, t_layer, 1);
166 avgDriftLength = (driftLength_0 + driftLength_1) / 2;
168 m_mConstV[tableName][iTick] = avgDriftLength;
173 TVectorD geometryHough3D(16);
174 for (
int i = 0; i < 4; i++) {
175 geometryHough3D[i] =
m_mConstV[
"rr"][2 * i + 1] / 100;
176 geometryHough3D[i + 4] =
m_mConstV[
"angleSt"][i];
177 geometryHough3D[i + 8] =
m_mConstV[
"zToStraw"][i] / 100;
178 geometryHough3D[i + 12] =
m_mConstV[
"nWires"][2 * i + 1];
190 float tempInitVariables[] = { -3, 3, -2, 2, 1001, 1001};
191 vector<float > initVariables(tempInitVariables, tempInitVariables +
sizeof(tempInitVariables) /
sizeof(tempInitVariables[0]));
196 m_mConstV[
"initVariablesHough3D"] = vector<double> (6);
197 m_mConstV[
"initVariablesHough3D"][0] = tempInitVariables[0];
198 m_mConstV[
"initVariablesHough3D"][1] = tempInitVariables[1];
199 m_mConstV[
"initVariablesHough3D"][2] = tempInitVariables[2];
200 m_mConstV[
"initVariablesHough3D"][3] = tempInitVariables[3];
201 m_mConstV[
"initVariablesHough3D"][4] = tempInitVariables[4];
202 m_mConstV[
"initVariablesHough3D"][5] = tempInitVariables[5];
223 for (
unsigned int iTrack = 0; iTrack < trackList2D.size(); iTrack++) {
224 TCTrack& aTrack = *
new TCTrack(* trackList2D[iTrack]);
225 trackList3D.push_back(& aTrack);
234 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
235 TCTrack& aTrack = *trackList[iTrack];
236 aTrack.setTrackID(iTrack + 1);
257 m_mDouble[
"eventNumber"] = eventMetaDataPtr->getEvent();;
260 vector<vector<double> > stTSs(4);
261 vector<vector<int> > stTSDrift(4);
262 vector<vector<const TCSHit*> > p_stTSs(4);
263 for (
unsigned iSL = 0; iSL < 4; iSL++) {
266 string slName =
"st" + to_string(iSL);
267 m_mEventV[slName +
"_hit"] = vector<double> ();
268 m_mEventV[slName +
"_driftHit"] = vector<double> ();
269 stTSs[iSL] = vector<double> ();
270 stTSDrift[iSL] = vector<int> ();
271 p_stTSs[iSL] = vector<const TCSHit*> ();
273 for (
unsigned iHit = 0; iHit < hits.size(); iHit++) {
274 if (hits[iHit] == 0)
continue;
280 double t_wirePhi = ((double)hits[iHit]->cell().localId()) /
m_mConstV[
"nWires"][2 * iSL + 1] * 4 *
m_mConstD[
"Trg_PI"];
281 m_mEventV[slName +
"_hit"].push_back(t_wirePhi);
283 int t_tdc = hits[iHit]->segment().priorityTime();
284 int t_lr = hits[iHit]->segment().LUT()->getValue(hits[iHit]->segment().lutPattern());;
285 int t_priorityPosition = hits[iHit]->segment().priorityPosition();
286 int t_driftInfo = (t_tdc << 4) + (t_lr << 2) + t_priorityPosition;
287 stTSs[iSL].push_back(t_wirePhi);
288 p_stTSs[iSL].push_back(hits[iHit]);
289 stTSDrift[iSL].push_back(t_driftInfo);
296 map<unsigned, unsigned> numberTSsForParticle;
301 for (
unsigned iTrack = 0; iTrack <
m_mEventD[
"nTracks"]; iTrack++) {
303 TCTrack& aTrack = * trackList[iTrack];
309 m_mDouble[
"trackId"] = aTrack.getTrackID();
313 if (fit2DResult != 0)
continue;
324 const TCSHit* p_bestTS[4] = {0, 0, 0, 0};
325 for (
int iSt = 0; iSt < 4; iSt++) {
326 if (
m_mVector[
"bestTSIndex"][iSt] == 999) p_bestTS[iSt] = 0;
327 else p_bestTS[iSt] = p_stTSs[iSt][(int)
m_mVector[
"bestTSIndex"][iSt]];
331 for (
unsigned iSt = 0; iSt < 4; iSt++) {
332 if (
m_mVector[
"bestTS"][iSt] != 999) aTrack.append(
new TCLink(0, p_bestTS[iSt], p_bestTS[iSt]->cell().xyPosition()));
362 const TCRelation& trackRelation3D = aTrack.relation3D();
363 m_mDouble[
"purity"] = trackRelation3D.purity3D(aTrack.relation2D().contributor(0));
364 m_mDouble[
"efficiency"] = trackRelation3D.efficiency3D(aTrack.relation2D().contributor(0), numberTSsForParticle);
366 m_mVector[
"mcTSs"] = vector<double> (4, 999);
367 vector<const TCSHit*> mcTSList;
369 for (
unsigned iTS = 0; iTS < mcTSList.size(); iTS++) {
370 int iSuperLayer = (int)(
double(mcTSList[iTS]->cell().superLayerId()) - 1) / 2;
371 m_mVector[
"mcTSs"][iSuperLayer] = (double)mcTSList[iTS]->cell().localId() /
m_mConstV[
"nWires"][2 * iSuperLayer + 1] * 4 *
375 m_mVector[
"mcTSsX"] = vector<double> (4);
376 m_mVector[
"mcTSsY"] = vector<double> (4);
377 for (
unsigned iTS = 0; iTS < mcTSList.size(); iTS++) {
378 unsigned iCDCSimHit = mcTSList[iTS]->iCDCSimHit();
379 CDCSimHit* aCDCSimHit = SimHits[iCDCSimHit];
385 m_mVector[
"perfectWireDiff"] = vector<double> (4);
386 m_mVector[
"perfectCalZ"] = vector<double> (4);
387 for (
unsigned iSt = 0; iSt < 4; iSt++) {
401 unsigned int mcParticleId = aTrack.relation2D().contributor(0);
402 for (
unsigned iSt = 0; iSt < 4; iSt++) {
403 string mcTsName =
"mcTsSt" + to_string(iSt);
407 for (
unsigned iTS = 0; iTS < hits.size(); iTS++) {
408 if (hits[iTS]->iMCParticle() == mcParticleId)
m_mVector[mcTsName].push_back((
double)hits[iTS]->cell().localId() /
435 HandleRoot::saveTrackValues(
"hough3D",
444 HandleRoot::saveEventValues(
"hough3D",
452 if (
m_mBool[
"debugEfficiency"]) {
454 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
456 TCTrack& aTrack = * trackList[iTrack];
458 int nPriorityHitSL = 0;
459 for (
unsigned iSt = 0; iSt < 4; iSt++) {
460 int priorityHitSL = 0;
461 for (
unsigned iTS = 0; iTS < stTSDrift[iSt].size(); iTS++) {
462 int t_priorityPosition = (stTSDrift[iSt][iTS] & 3);
463 if (t_priorityPosition == 3) priorityHitSL = 1;
466 if (priorityHitSL) nPriorityHitSL++;
471 if (
m_mDouble[
"efficiency"] != nPriorityHitSL * 1. / 4) {
472 aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::find3D, 1);
479 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
480 unsigned nHitStSl = 0;
481 for (
unsigned iSt = 0; iSt < 4; iSt++) {
482 if (trackList[iTrack]->links(2 * iSt + 1).size() != 0) nHitStSl++;
484 if (nHitStSl < 2) trackList[iTrack]->setDebugValue(TRGCDCTrack::EDebugValueType::find3D, 1);
501 unsigned id = trackList[j]->relation().contributor(0);
502 vector<const TCSHit*> tsList[9];
507 for (
unsigned i = 0; i < hits.size(); i++) {
508 const TCSHit& ts = * hits[i];
509 if (ts.segment().axial())
continue;
510 if (! ts.signal().active())
continue;
511 const TCWHit* wh = ts.segment().center().hit();
513 const unsigned trackId = wh->iMCParticle();
524 tsList[wh->wire().superLayerId()].push_back(& ts);
528 for (
unsigned k = 0; k < 9; k++) {
531 for (
unsigned l = 0; l < tsList[k].size(); l++) {
534 cout << tsList[k][l]->cell().name();
542 for (
unsigned i = 0; i < 9; i++) {
543 const TCSHit* best = 0;
544 if (tsList[i].size() == 0) {
546 }
else if (tsList[i].size() == 1) {
550 for (
unsigned k = 0; k < tsList[i].size(); k++) {
551 const TRGSignal& timing = tsList[i][k]->signal();
552 const TRGTime& t = * timing[0];
553 if (t.time() < timeMin) {
559 mcTSList.push_back(best);
570 cout <<
TRGDebug::tab() <<
"givenTrk#=" << trackList.size() << endl;
574 for (
unsigned j = 0; j < trackList.size(); j++) {
576 TCTrack* trk = trackList[j];
578 vector<const TCSHit*> mcTSList;
580 for (
unsigned iTS = 0; iTS < mcTSList.size(); iTS++) {
581 trk->append(
new TCLink(0, mcTSList[iTS], mcTSList[iTS]->cell().xyPosition()));
594 map<unsigned, unsigned>& numberTSsForParticle)
596 vector<unsigned> mcParticleList;
597 for (
unsigned iLayer = 0; iLayer < 4; iLayer++) {
599 mcParticleList.clear();
600 for (
unsigned iTS = 0; iTS < p_stTSs[iLayer].size(); iTS++) {
601 unsigned iMCParticle = p_stTSs[iLayer][iTS]->iMCParticle();
602 if (find(mcParticleList.begin(), mcParticleList.end(), iMCParticle) == mcParticleList.end()) {
603 mcParticleList.push_back(iMCParticle);
607 for (
unsigned iMCPart = 0; iMCPart < mcParticleList.size(); iMCPart++) {
608 map<unsigned, unsigned>::iterator it = numberTSsForParticle.find(mcParticleList[iMCPart]);
609 if (it != numberTSsForParticle.end()) ++it->second;
610 else numberTSsForParticle[mcParticleList[iMCPart]] = 1;
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
B2Vector3D getPosWire() const
The method to get position on wire.
The Class for CDC Geometry Parameters.
int nShifts(int layerId) const
Returns number shift.
double getTdcBinWidth() const
Return TDC bin width (nsec).
double senseWireBZ(int layerId) const
Returns backward z position of sense wire in each layer.
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
double senseWireFZ(int layerId) const
Returns forward z position of sense wire in each layer.
double getNominalDriftV() const
Return the nominal drift velocity of He-ethane gas (default: 4.0x10^-3 cm/nsec).
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.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
double senseWireR(int layerId) const
Returns radius of sense wire in each layer.
Low-level class to create/modify relations between StoreArrays.
Accessor to arrays stored in the data store.
Type-safe access to single objects in the data store.
std::map< std::string, std::vector< double > > m_mVector
Map to hold track vector values for Fitter3D.
std::map< std::string, TVectorD * > m_mEventTVectorD
TVectorD map for saving event values to root file.
std::map< std::string, bool > m_mBool
Map to hold input options.
std::map< std::string, double > m_mConstD
Map to hold run values for Fitter3D.
bool m_makeRootFile
Choose whether to save root file.
const TRGCDC & _cdc
Members.
std::map< std::string, std::vector< double > > m_mConstV
Map to hold run vectcors for Fitter3D.
std::map< std::string, double > m_mDouble
Map to hold track double values for Fitter3D.
std::map< std::string, double > m_mEventD
Map to hold event values for Fitter3D.
std::map< std::string, TClonesArray * > m_mTClonesArray
TClonesArray map for saving track values to root file.
TTree * m_treeConstantsFinder3D
TTree for constants of Hough3D.
int m_finderMode
0: perfect finder, 1: Hough3DFinder, 2: GeoFinder, 3: VHDL GeoFinder Choose what finder to use.
Hough3DFinder * m_Hough3DFinder
Hough Variables.
TFile * m_fileFinder3D
Tfile for Hough3D root file.
TTree * m_treeTrackFinder3D
TTree for tracks of Hough3D.
std::map< std::string, std::vector< double > > m_mEventV
Map to hold event vectcors for Fitter3D.
std::map< std::string, TVectorD * > m_mRunTVectorD
TVectorD map for saving run values to root file.
The instance of TRGCDC is a singleton.
A class to represent a digitized signal. Unit is nano second.
A class to represent a signal timing in the trigger system.
static double calZ(int charge, double anglest, double ztostraw, double rr, double phi, double rho, double phi0)
Calculates z.
static double calDeltaPhi(int charge, double anglest, double ztostraw, double rr, double phi, double rho, double phi0)
Calculates the phi difference between fitted axial phi and stereo phi.
A class to finded stereo TS hits related to 2D tracks.
void initialize(const TVectorD &geometryVariables, std::vector< float > &initVariables)
Geometry variables.
void setInputFileName(const std::string &inputFileName)
Sets the config file for the GeoFinder.
int getMode(void)
Gets which 3D finder is used.
void setMode(int mode)
Sets which 3D finder to use.
void runFinder(const std::vector< double > &trackVariables, std::vector< std::vector< double > > &stTSs, const std::vector< std::vector< int > > &stTSDrift)
Track variables.
void getValues(const std::string &input, std::vector< double > &result)
Gets results from the 3D finder.
void destruct(void)
Destructs the 3D finder.
std::vector< const TRGCDCSegmentHit * > segmentHits(void) const
returns a list of TRGCDCSegmentHit.
static std::string tab(void)
returns tab spaces.
const TRGCDCWire & center(void) const
returns a center wire.
static double calPhi(TRGCDCSegmentHit const *segmentHit, double eventTime)
Utility functions.
std::vector< const TRGCDCSegmentHit * > stereoSegmentHits(unsigned) const
returns a list of TRGCDCSegmentHit in a stereo super layer N.
unsigned layerId(void) const
returns layer id.
const TRGCDCSegment & stereoSegment(unsigned lyrId, unsigned id) const
returns a track segment in stereo layers. (lyrId is stereo #)
void terminate(void)
Termination method.
static void enterStage(const std::string &stageName)
Declare that you enter new stage.
~TRGCDCHough3DFinder()
Destructor.
void findNumberOfHitSuperlayersForMcParticles(std::vector< std::vector< const TRGCDCSegmentHit * > > &p_stTSs, std::map< unsigned, unsigned > &numberTSsForParticle)
Finds number of hit superlayers for each mc particle.
void perfectFinder(std::vector< TRGCDCTrack * > &trackList, unsigned j, std::vector< const TRGCDCSegmentHit * > &mcTSList)
Perfect 3D finder for a track.
const TRGCDCSegment & segment(unsigned id) const
returns a track segment.
int getEventTime(void) const
returns bad hits(finding invalid hits).
TRGCDCHough3DFinder(const TRGCDC &, bool makeRootFile, int finderMode)
Contructor.
void doitPerfectly(std::vector< TRGCDCTrack * > &trackList)
Perfect 3D finder for a tracklist.
static int do2DFit(TRGCDCTrack &aTrack, const std::map< std::string, bool > &m_mBool_in, const std::map< std::string, double > &m_mConstD_in, std::map< std::string, std::vector< double > > &m_mConstV_in, std::map< std::string, double > &m_mDouble_in, std::map< std::string, std::vector< double > > &m_mVector_in)
Does 2D fit. Returns 0 if fit is done successfully. m_mBool should have fIsPrintError,...
static int level(void)
returns the debug level.
static void leaveStage(const std::string &stageName)
Declare that you leave a stage.
void doitFind(std::vector< TRGCDCTrack * > &trackList)
Finds tracks using tracklist.
static void getMCValues(const TRGCDC &m_cdc_in, TRGCDCTrack *aTrack, const std::map< std::string, double > &m_mConstD_in, std::map< std::string, double > &m_mDouble_in, std::map< std::string, std::vector< double > > &m_mVector_in)
Function for mc debugging.
void doit(std::vector< TRGCDCTrack * > const &trackList2D, std::vector< TRGCDCTrack * > &trackList3D)
Member functions.
Abstract base class for different kinds of events.