13 #define TRG_SHORT_NAMES
14 #define TRGCDC_SHORT_NAMES
17 #include "trg/trg/Debug.h"
18 #include "trg/cdc/Fitter3D.h"
19 #include "trg/cdc/Segment.h"
20 #include "trg/cdc/TRGCDCTrack.h"
21 #include "trg/cdc/Link.h"
24 #include <framework/dataobjects/EventMetaData.h>
25 #include "cdc/dataobjects/CDCSimHit.h"
26 #include "cdc/geometry/CDCGeometryPar.h"
27 #include "trg/trg/Time.h"
28 #include "trg/trg/Signal.h"
29 #include "trg/trg/Utilities.h"
30 #include "trg/cdc/TRGCDC.h"
31 #include "trg/cdc/Wire.h"
32 #include "trg/cdc/Layer.h"
33 #include "trg/cdc/WireHit.h"
34 #include "trg/cdc/WireHitMC.h"
35 #include "trg/cdc/SegmentHit.h"
36 #include "trg/cdc/TrackMC.h"
37 #include "trg/cdc/Relation.h"
38 #include "mdst/dataobjects/MCParticle.h"
39 #include "trg/cdc/FrontEnd.h"
40 #include "trg/cdc/Merger.h"
41 #include "trg/cdc/LUT.h"
42 #include "trg/trg/Constants.h"
43 #include "trg/cdc/Helix.h"
44 #include "trg/cdc/Fitter3DUtility.h"
45 #include "trg/cdc/EventTime.h"
46 #include "trg/cdc/JSignal.h"
47 #include "trg/cdc/JLUT.h"
48 #include "trg/cdc/JSignalData.h"
49 #include "trg/cdc/FpgaUtility.h"
50 #include "trg/cdc/HandleRoot.h"
59 TRGCDCFitter3D::TRGCDCFitter3D(
const std::string& name,
60 const std::string& rootFitter3DFile,
62 const std::map<std::string, bool>& flags)
63 : m_name(name), m_cdc(
TRGCDC),
64 m_mBool(flags), m_rootFitter3DFileName(rootFitter3DFile),
65 m_treeTrackFitter3D(), m_treeConstantsFitter3D()
85 m_mBool[
"fIsIntegerEffect"] = 1;
97 for (
unsigned iSL = 0; iSL < 9; iSL++) {
103 m_mConstV[
"nTSs2D"] = vector<double> (5);
104 for (
unsigned iAx = 0; iAx < 5; iAx++) {
108 m_mConstV[
"zToStraw"] = vector<double> (4);
109 m_mConstV[
"zToOppositeStraw"] = vector<double> (4);
110 m_mConstV[
"angleSt"] = vector<double> (4);
111 m_mConstV[
"nShift"] = vector<double> (4);
112 for (
int iSt = 0; iSt < 4; iSt++) {
124 for (
int iSt = 0; iSt < 4; iSt++)
m_mConstV[
"rr3D"][iSt] =
m_mConstV[
"rr"][iSt * 2 + 1];
126 m_mConstV[
"wirePhi2DError"] = vector<double> (5);
127 m_mConstV[
"driftPhi2DError"] = vector<double> (5);
141 m_mConstV[
"wirePhi2DError"][0] = 0.00085106;
142 m_mConstV[
"wirePhi2DError"][1] = 0.00039841;
143 m_mConstV[
"wirePhi2DError"][2] = 0.00025806;
144 m_mConstV[
"wirePhi2DError"][3] = 0.00019084;
145 m_mConstV[
"wirePhi2DError"][4] = 0.0001514;
146 m_mConstV[
"driftPhi2DError"][0] = 0.00085106;
147 m_mConstV[
"driftPhi2DError"][1] = 0.00039841;
148 m_mConstV[
"driftPhi2DError"][2] = 0.00025806;
149 m_mConstV[
"driftPhi2DError"][3] = 0.00019084;
150 m_mConstV[
"driftPhi2DError"][4] = 0.0001514;
155 m_mConstV[
"driftZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
156 m_mConstV[
"wireZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
160 for (
unsigned iSl = 0; iSl < 9; iSl++) {
161 string tableName =
"driftLengthTableSL" + to_string(iSl);
162 unsigned tableSize = 512;
163 m_mConstV[tableName] = vector<double> (tableSize);
165 for (
unsigned iTick = 0; iTick < tableSize; iTick++) {
167 double avgDriftLength = 0;
168 if (
m_mBool[
"fXtSimple"] == 1) {
171 double driftLength_0 = cdcp.
getDriftLength(t_driftTime, t_layer, 0);
172 double driftLength_1 = cdcp.
getDriftLength(t_driftTime, t_layer, 1);
173 avgDriftLength = (driftLength_0 + driftLength_1) / 2;
175 m_mConstV[tableName][iTick] = avgDriftLength;
180 cout <<
"fLRLUT: " <<
m_mBool[
"fLRLUT"] << endl;
181 cout <<
"fMc: " <<
m_mBool[
"fMc"] << endl;
182 cout <<
"fVerbose: " <<
m_mBool[
"fVerbose"] << endl;
183 if (
m_mBool[
"fMc"]) cout <<
"fmcLR: " <<
m_mBool[
"fmcLR"] << endl;
184 cout <<
"fRoot: " <<
m_mBool[
"fRootFile"] << endl;
185 cout <<
"PI: " <<
m_mConstD[
"Trg_PI"] << endl;
189 cout <<
"nWires: " << int(
m_mConstV[
"nWires"][0]) <<
" " << int(
m_mConstV[
"nWires"][1]) <<
" " << int(
198 " " <<
m_mConstV[
"wireZError"][3] << endl;
200 <<
" " <<
m_mConstV[
"driftZError"][3] << endl;
201 cout <<
"wirePhiError: " <<
m_mConstV[
"wirePhi2DError"][0] <<
" " <<
m_mConstV[
"wirePhi2DError"][1] <<
" " <<
203 cout <<
"driftPhiError: " <<
m_mConstV[
"driftPhi2DError"][0] <<
" " <<
m_mConstV[
"driftPhi2DError"][1] <<
" " <<
225 m_mDouble[
"eventNumber"] = eventMetaDataPtr->getEvent();
229 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
231 TCTrack& aTrack = * trackList[iTrack];
237 m_mDouble[
"trackId"] = aTrack.getTrackID();
242 if (fit2DResult != 0) {
244 if (
m_mBool[
"fVerbose"]) cout <<
"Exit due to 2D fit result:" << fit2DResult << endl;
252 for (
unsigned iSt = 0; iSt < 4; iSt++) {
253 const vector<TCLink*>& links = aTrack.links(iSt * 2 + 1);
254 const unsigned nSegments = links.size();
255 cout <<
"iSt:" << iSt <<
" nSegments:" << nSegments << endl;
256 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
257 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
258 cout <<
" tsId:" << t_segment->localId()
259 <<
" tdc:" << t_segment->priorityTime() <<
" lr:" << t_segment->LUT()->getValue(t_segment->lutPattern())
260 <<
" priorityPosition:" << t_segment->priorityPosition() << endl;
265 m_mVector[
"useStSl"] = vector<double> (4);
271 for (
unsigned iAx = 0; iAx < 5; iAx++)
m_mVector[
"useSl"][2 * iAx] =
m_mVector[
"useAxSl"][iAx];
272 for (
unsigned iSt = 0; iSt < 4; iSt++)
m_mVector[
"useSl"][2 * iSt + 1] =
m_mVector[
"useAxSl"][iSt];
275 for (
unsigned iSt = 0; iSt < 4; iSt++) {
277 const vector<TCLink*>& links = aTrack.links(iSt * 2 + 1);
278 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[0]->hit()->cell());
279 m_mVector[
"tsId"][iSt * 2 + 1] = t_segment->localId();
281 m_mVector[
"lutLR"][iSt * 2 + 1] = t_segment->LUT()->getValue(t_segment->lutPattern());
282 if (
m_mBool[
"fMc"])
m_mVector[
"mcLR"][iSt * 2 + 1] = t_segment->hit()->mcLR() + 1;
283 m_mVector[
"driftLength"][iSt * 2 + 1] = t_segment->hit()->drift();
284 m_mVector[
"tdc"][iSt * 2 + 1] = t_segment->priorityTime();
290 m_mVector[
"wirePhi"][iSt * 2 + 1] = 9999;
293 m_mVector[
"driftLength"][iSt * 2 + 1] = 9999;
297 else m_mVector[
"LR"][iSt * 2 + 1] = 9999;
304 for (
unsigned iSt = 0; iSt < 4; iSt++) {
308 for (
unsigned iSt = 0; iSt < 4; iSt++) {
311 string tableName =
"driftLengthTableSL" + to_string(iSt * 2 + 1);
313 if (t_driftTime < 0) t_driftTime = 0;
314 double t_driftLength =
m_mConstV[tableName][(unsigned)t_driftTime];
323 m_mVector[
"zError"] = vector<double> (4);
324 for (
unsigned iSt = 0; iSt < 4; iSt++) {
336 m_mVector[
"iZError2"] = vector<double> (4);
337 for (
unsigned iSt = 0; iSt < 4; iSt++) {
347 for (
unsigned iSt = 0; iSt < 4; iSt++) {
358 for (
unsigned iSt = 0; iSt < 4; iSt++) {
380 aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::fit3D, 1);
381 if (
m_mBool[
"fVerbose"]) cout <<
"Exit due to 3D fit cot result:" <<
m_mDouble[
"cot"] << endl;
386 if (
m_mBool[
"fVerbose"]) cout <<
"Fit was done successfully." << endl;
389 CLHEP::HepVector a(5);
390 a = aTrack.helix().a();
403 aTrack.set2DFitChi2(
m_mDouble[
"fit2DChi2"]);
405 aTrack.setHelix(helix);
418 HandleRoot::saveTrackValues(
"fitter3D",
435 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
436 TCTrack& aTrack = * trackList[iTrack];
437 if (aTrack.fitted() == 0) aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::fit3D, 1);
442 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
443 TCTrack& aTrack = *trackList[iTrack];
444 if (aTrack.fitted()) {
445 double fitZ0 = aTrack.helix().dz();
446 if (fitZ0 > 20 || fitZ0 < -20) aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::fit3D, 1);
475 m_mDouble[
"eventNumber"] = eventMetaDataPtr->getEvent();
479 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
481 TCTrack& aTrack = * trackList[iTrack];
488 m_mDouble[
"trackId"] = aTrack.getTrackID();
493 if (fit2DResult != 0) {
502 for (
unsigned iSt = 0; iSt < 4; iSt++) {
503 const vector<TCLink*>& links = aTrack.links(iSt * 2 + 1);
504 const unsigned nSegments = links.size();
505 cout <<
"iSt:" << iSt <<
" nSegments:" << nSegments << endl;
506 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
507 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
508 cout <<
" tsId:" << t_segment->localId()
509 <<
" tdc:" << t_segment->priorityTime() <<
" lr:" << t_segment->LUT()->getValue(t_segment->lutPattern())
510 <<
" priorityPosition:" << t_segment->priorityPosition() << endl;
514 m_mVector[
"useStSl"] = vector<double> (4);
520 for (
unsigned iSt = 0; iSt < 4; iSt++) {
522 const vector<TCLink*>& links = aTrack.links(iSt * 2 + 1);
523 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[0]->hit()->cell());
524 m_mVector[
"tsId"][iSt * 2 + 1] = t_segment->localId();
526 m_mVector[
"lutLR"][iSt * 2 + 1] = t_segment->LUT()->getValue(t_segment->lutPattern());
527 if (
m_mBool[
"fMc"])
m_mVector[
"mcLR"][iSt * 2 + 1] = t_segment->hit()->mcLR() + 1;
528 m_mVector[
"driftLength"][iSt * 2 + 1] = t_segment->hit()->drift();
529 m_mVector[
"tdc"][iSt * 2 + 1] = t_segment->priorityTime();
535 m_mVector[
"wirePhi"][iSt * 2 + 1] = 9999;
538 m_mVector[
"driftLength"][iSt * 2 + 1] = 9999;
542 else m_mVector[
"LR"][iSt * 2 + 1] = 9999;
555 for (
unsigned iSt = 0; iSt < 4; iSt++) {
559 for (
unsigned iSt = 0; iSt < 4; iSt++) {
561 string tableName =
"driftLengthTableSL" + to_string(iSt * 2 + 1);
563 if (t_driftTime < 0) t_driftTime = 0;
564 double t_driftLength =
m_mConstV[tableName][(unsigned)t_driftTime];
571 m_mVector[
"zError"] = vector<double> (4);
572 for (
unsigned iSt = 0; iSt < 4; iSt++) {
580 m_mVector[
"iZError2"] = vector<double> (4);
581 for (
unsigned iSt = 0; iSt < 4; iSt++) {
612 double rhoMax = 2500;
621 m_mConstD[
"driftPhiLUTOutBitSize"] = phiBitSize - 1;
623 m_mConstD[
"acosLUTOutBitSize"] = phiBitSize - 1;
634 if (t_quadrant == 1)
m_mDouble[
"relRefPhi"] = 0;
640 else if (t_quadrant == 2)
m_mDouble[
"relRefPhi"] = 0;
646 m_mVector[
"relPhi3D"] = vector<double> (4);
647 for (
unsigned iSt = 0; iSt < 4;
651 m_mVector[
"relWirePhi3D"] = vector<double> (4);
652 for (
unsigned iSt = 0; iSt < 4; iSt++) {
655 while (rangeOk == 0) {
656 if (t_relWirePhi < 0) t_relWirePhi += 2 *
m_mConstD[
"Trg_PI"];
657 else if (t_relWirePhi > 2 *
m_mConstD[
"Trg_PI"]) t_relWirePhi -= 2 *
m_mConstD[
"Trg_PI"];
660 m_mVector[
"relWirePhi3D"][iSt] = t_relWirePhi;
664 m_mVector[
"relTsId3D"] = vector<double> (4);
665 for (
unsigned iSt = 0; iSt < 4;
672 m_mDouble[
"pt"] = rhoMax * 0.3 * 1.5 * 0.01;
679 m_mVector[
"unsignedTdc"] = vector<double> (9);
680 for (
unsigned iSt = 0; iSt < 4; iSt++) {
689 vector<tuple<string, double, int, double, double, int> > t_values = {
690 make_tuple(
"phi0",
m_mDouble[
"relPhi0"], phiBitSize, phiMin, phiMax, 0),
693 make_tuple(
"charge", (
int)(
m_mDouble[
"charge2D"] == 1 ? 1 : 0), 1, 0, 1.5, 0),
694 make_tuple(
"lr_0",
m_mVector[
"lutLR"][1], 2, 0, 3.5, 0),
695 make_tuple(
"lr_1",
m_mVector[
"lutLR"][3], 2, 0, 3.5, 0),
696 make_tuple(
"lr_2",
m_mVector[
"lutLR"][5], 2, 0, 3.5, 0),
697 make_tuple(
"lr_3",
m_mVector[
"lutLR"][7], 2, 0, 3.5, 0),
698 make_tuple(
"tsId_0",
m_mVector[
"relTsId3D"][0], ceil(log(
m_mConstV[
"nTSs"][1]) / log(2)), 0, pow(2, ceil(log(
m_mConstV[
"nTSs"][1]) / log(2))) - 0.5, 0),
699 make_tuple(
"tsId_1",
m_mVector[
"relTsId3D"][1], ceil(log(
m_mConstV[
"nTSs"][3]) / log(2)), 0, pow(2, ceil(log(
m_mConstV[
"nTSs"][3]) / log(2))) - 0.5, 0),
700 make_tuple(
"tsId_2",
m_mVector[
"relTsId3D"][2], ceil(log(
m_mConstV[
"nTSs"][5]) / log(2)), 0, pow(2, ceil(log(
m_mConstV[
"nTSs"][5]) / log(2))) - 0.5, 0),
701 make_tuple(
"tsId_3",
m_mVector[
"relTsId3D"][3], ceil(log(
m_mConstV[
"nTSs"][7]) / log(2)), 0, pow(2, ceil(log(
m_mConstV[
"nTSs"][7]) / log(2))) - 0.5, 0),
707 make_tuple(
"eventTimeValid", (
int)
m_mDouble[
"eventTimeValid"], 1, 0, 1.5, 0),
719 vector<tuple<string, double, int, double, double, int> > resultValues;
721 vector<pair<string, int> > t_chooseSignals = {
722 make_pair(
"z0", 0), make_pair(
"cot", 0), make_pair(
"chi2Sum", 0)
731 (*it).second.setName((*it).first);
752 vector<pair<string, int> > chooseValues = {
753 make_pair(
"zz_0",
m_mBool[
"fIsIntegerEffect"]),
754 make_pair(
"zz_1",
m_mBool[
"fIsIntegerEffect"]),
755 make_pair(
"zz_2",
m_mBool[
"fIsIntegerEffect"]),
756 make_pair(
"zz_3",
m_mBool[
"fIsIntegerEffect"]),
757 make_pair(
"arcS_0",
m_mBool[
"fIsIntegerEffect"]),
758 make_pair(
"arcS_1",
m_mBool[
"fIsIntegerEffect"]),
759 make_pair(
"arcS_2",
m_mBool[
"fIsIntegerEffect"]),
760 make_pair(
"arcS_3",
m_mBool[
"fIsIntegerEffect"]),
761 make_pair(
"z0",
m_mBool[
"fIsIntegerEffect"]),
762 make_pair(
"cot",
m_mBool[
"fIsIntegerEffect"]),
763 make_pair(
"zChi2",
m_mBool[
"fIsIntegerEffect"])
766 vector<tuple<string, double, int, double, double, int> > outValues;
788 m_mVector[
"float_zz"] = vector<double> (4);
790 for (
unsigned iSt = 0; iSt < 4;
794 m_mVector[
"float_arcS"] = vector<double> (4);
795 for (
unsigned iSt = 0; iSt < 4;
805 for (
unsigned iSt = 0; iSt < 4; iSt++) cout <<
"float_zz[" << iSt <<
"] : " <<
m_mVector[
"float_zz"][iSt] <<
" ";
807 for (
unsigned iSt = 0; iSt < 4; iSt++) cout <<
"float_arcS[" << iSt <<
"] : " <<
m_mVector[
"float_arcS"][iSt] <<
" ";
809 cout <<
"float_z0: " <<
m_mDouble[
"float_z0"] << endl;
810 cout <<
"float_zChi2: " <<
m_mDouble[
"float_zChi2"] << endl;
824 CLHEP::HepVector a(5);
825 a = aTrack.helix().a();
838 aTrack.setHelix(helix);
839 aTrack.set2DFitChi2(
m_mDouble[
"fit2DChi2"]);
853 HandleRoot::saveTrackValues(
"fitter3D",
870 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
871 TCTrack& aTrack = * trackList[iTrack];
872 if (aTrack.fitted() == 0) aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::fit3D, 1);
877 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
878 TCTrack& aTrack = *trackList[iTrack];
879 if (aTrack.fitted()) {
880 double fitZ0 = aTrack.helix().dz();
881 if (fitZ0 > 20 || fitZ0 < -20) aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::fit3D, 1);
925 it->second->makeCOE(it->first +
".coe");
946 for (
unsigned iSt = 0; iSt < 4;
949 for (
unsigned iSt = 0; iSt < 4;
961 std::map<std::string, double>& m_mDouble_in, std::map<std::string, std::vector<double> >& m_mVector_in)
964 const TCRelation& trackRelation = aTrack->
relation();
966 const MCParticle& trackMCParticle = trackRelation.mcParticle(0);
969 TVector3 vertex = trackMCParticle.
getVertex();
970 TLorentzVector vector4 = trackMCParticle.
get4Vector();
971 TVector2 helixCenter;
972 TVector3 impactPosition;
974 m_mVector_in[
"mcVertex"] = vector<double> ({vertex.X(), vertex.Y(), vertex.Z()});
975 m_mVector_in[
"mcMomentum"] = vector<double> ({vector4.Px(), vector4.Py(), vector4.Pz()});
976 m_mVector_in[
"helixCenter"] = vector<double> ({helixCenter.X(), helixCenter.Y()});
977 m_mVector_in[
"impactPosition"] = vector<double> ({impactPosition.X(), impactPosition.Y(), impactPosition.Z()});
980 m_mDouble_in[
"mcPt"] = trackMCParticle.
getMomentum().Pt();
981 m_mDouble_in[
"mcPhi0"] = 0;
982 if (trackMCParticle.
getCharge() > 0) m_mDouble_in[
"mcPhi0"] = trackMCParticle.
getMomentum().Phi() - m_mConstD_in.at(
"Trg_PI") / 2;
983 if (trackMCParticle.
getCharge() < 0) m_mDouble_in[
"mcPhi0"] = trackMCParticle.
getMomentum().Phi() + m_mConstD_in.at(
"Trg_PI") / 2;
985 if (m_mDouble_in[
"mcPhi0"] < 0) m_mDouble_in[
"mcPhi0"] += 2 * m_mConstD_in.at(
"Trg_PI");
987 m_mDouble_in[
"mcZ0"] = impactPosition.Z();
989 m_mDouble_in[
"mcCharge"] = trackMCParticle.
getCharge();
992 TVectorD mcStatus(3);
993 m_mDouble_in[
"mcStatus"] = trackMCParticle.
getStatus();
994 m_mDouble_in[
"pdgId"] = trackMCParticle.
getPDG();
998 unsigned id = trackRelation.contributor(0);
999 vector<const TCSHit*> mcAllTSList[9];
1000 vector<const TCSHit*> mcTSList(9);
1002 const vector<const TCSHit*> hits = m_cdc_in.
segmentHits();
1003 for (
unsigned i = 0; i < hits.size(); i++) {
1004 const TCSHit& ts = * hits[i];
1005 if (! ts.signal().active())
continue;
1006 const TCWHit* wh = ts.segment().center().hit();
1008 const unsigned trackId = wh->iMCParticle();
1010 mcAllTSList[wh->wire().superLayerId()].push_back(& ts);
1013 for (
unsigned i = 0; i < 9; i++) {
1014 const TCSHit* best = 0;
1015 if (mcAllTSList[i].size() == 0) {
1016 }
else if (mcAllTSList[i].size() == 1) {
1017 best = mcAllTSList[i][0];
1019 int timeMin = 99999;
1020 for (
unsigned k = 0; k < mcAllTSList[i].size(); k++) {
1021 const TRGSignal& timing = mcAllTSList[i][k]->signal();
1022 const TRGTime& t = * timing[0];
1023 if (t.time() < timeMin) {
1025 best = mcAllTSList[i][k];
1034 m_mVector_in[
"mcPosX"] = vector<double> ({9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999});
1035 m_mVector_in[
"mcPosY"] = vector<double> ({9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999});
1036 m_mVector_in[
"mcPosZ"] = vector<double> ({9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999});
1037 for (
unsigned iSL = 0; iSL < 9; iSL++) {
1038 if (mcTSList[iSL] != 0) {
1039 TVector3 posTrack = mcTSList[iSL]->simHit()->getPosTrack();
1040 m_mVector_in[
"mcPosX"][iSL] = posTrack.X();
1041 m_mVector_in[
"mcPosY"][iSL] = posTrack.Y();
1042 m_mVector_in[
"mcPosZ"][iSL] = posTrack.Z();
1046 m_mVector_in[
"simMcLR"] = vector<double> (9);
1047 for (
unsigned iSL = 0; iSL < 9; iSL++) {
1048 if (mcTSList[iSL] != 0) {
1049 m_mVector_in[
"simMcLR"][iSL] = mcTSList[iSL]->simHit()->getPosFlag();
1071 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1073 const vector<TCLink*>& links = aTrack.
links(iAx * 2);
1074 const unsigned nSegments = links.size();
1077 bool priorityHitTS = 0;
1078 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1079 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
1080 if (t_segment->center().hit() != 0) priorityHitTS = 1;
1082 if (nSegments != 1) {
1083 if (nSegments == 0) {
1085 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isAxialTrackFull() => There are no TS." << endl;
1087 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isAxialTrackFull() => multiple TS are assigned." << endl;
1090 if (priorityHitTS == 0) {
1092 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isAxialTrackFull() => There are no priority hit TS" << endl;
1102 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1104 const vector<TCLink*>& links = aTrack.
links(iSt * 2 + 1);
1105 const unsigned nSegments = links.size();
1108 bool priorityHitTS = 0;
1109 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1110 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
1111 if (t_segment->center().hit() != 0) priorityHitTS = 1;
1113 if (nSegments != 1) {
1114 if (nSegments == 0) {
1116 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isStereoTrackFull() => There are no TS." << endl;
1118 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isStereoTrackFull() => multiple TS are assigned." << endl;
1121 if (priorityHitTS == 0) {
1123 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isStereoTrackFull() => There are no priority hit TS" << endl;
1132 useAxSl.assign(5, 1);
1133 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1135 const vector<TCLink*>& links = aTrack.
links(iAx * 2);
1136 const unsigned nSegments = links.size();
1139 bool priorityHitTS = 0;
1141 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1142 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
1143 if (t_segment->center().hit() != 0) priorityHitTS = 1;
1146 if (nSegments != 1) {
1147 if (nSegments == 0) {
1150 if (printError) cout <<
"Fitter3D::findHitAxialSuperlayers() => multiple TS are assigned." << endl;
1153 if (priorityHitTS == 0) {
1155 if (printError) cout <<
"Fitter3D::findHitAxialSuperlayers() => There are no priority hit TS" << endl;
1163 useStSl.assign(4, 1);
1164 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1166 const vector<TCLink*>& links = aTrack.
links(iSt * 2 + 1);
1167 const unsigned nSegments = links.size();
1170 bool priorityHitTS = 0;
1171 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1172 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
1173 if (t_segment->center().hit() != 0) priorityHitTS = 1;
1175 if (nSegments != 1) {
1176 if (nSegments == 0) {
1179 if (printError) cout <<
"Fitter3D::findHitStereoSuperlayers() => multiple TS are assigned." << endl;
1182 if (priorityHitTS == 0) {
1184 if (printError) cout <<
"Fitter3D::findHitStereoSuperlayers() => There are no priority hit TS" << endl;
1192 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1196 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::removeImpossibleStereoSuperlayers() => pt is too low for SL." << endl;
1203 bestTSIndex.resize(5);
1204 std::fill_n(bestTSIndex.begin(), 5, -1);
1205 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1207 const vector<TCLink*>& links = aTrack.
links(iAx * 2);
1208 const unsigned nSegments = links.size();
1211 vector<tuple<int, double> > tsCandiateInfo(nSegments);
1213 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1214 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
1215 int firstPriority = 0;
1216 if (t_segment->center().hit() != 0) firstPriority = 1;
1217 double tdc = t_segment->priorityTime();
1218 std::get<0>(tsCandiateInfo[iTS]) = firstPriority;
1219 std::get<1>(tsCandiateInfo[iTS]) = tdc;
1224 pair<int, tuple<int, double> > bestTS = make_pair(-1, make_tuple(-1, 9999));
1226 if (tsCandiateInfo.size() != 0) {
1239 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1240 if (std::get<0>(tsCandiateInfo[iTS]) == 1) {
1242 if (bestTS.first == -1) select = 1;
1243 else if (std::get<1>(bestTS.second) > std::get<1>(tsCandiateInfo[iTS])) select = 1;
1246 bestTS.second = tsCandiateInfo[iTS];
1252 bestTSIndex[iAx] = bestTS.first;
1257 const std::map<std::string, double>& m_mConstD_in,
1258 std::map<std::string, std::vector<double> >& m_mConstV_in, std::map<std::string, double>& m_mDouble_in,
1259 std::map<std::string, std::vector<double> >& m_mVector_in)
1261 m_mVector_in[
"useAxSl"] = vector<double> (5);
1265 vector<int> bestTSIndex(5);
1267 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1268 if (bestTSIndex[iAx] != -1) m_mVector_in[
"useAxSl"][iAx] = 1;
1273 m_mDouble_in[
"nHitAx"] = m_mVector_in[
"useAxSl"][0] + m_mVector_in[
"useAxSl"][1] + m_mVector_in[
"useAxSl"][2] +
1274 m_mVector_in[
"useAxSl"][3] +
1275 m_mVector_in[
"useAxSl"][4];
1276 if (m_mDouble_in[
"nHitAx"] <= 1) {
1277 if (m_mBool_in.at(
"fVerbose") == 1) cout <<
"[2DFit] Exiting because nHitAx is " << m_mDouble_in[
"nHitAx"] << endl;
1283 m_mVector_in[
"tsId"] = vector<double> (9);
1284 m_mVector_in[
"tsId2D"] = vector<double> (5);
1285 m_mVector_in[
"wirePhi"] = vector<double> (9);
1286 m_mVector_in[
"lutLR"] = vector<double> (9);
1287 m_mVector_in[
"LR"] = vector<double> (9);
1288 m_mVector_in[
"driftLength"] = vector<double> (9);
1289 m_mVector_in[
"tdc"] = vector<double> (9);
1290 if (!m_mVector_in.count(
"mcLR")) m_mVector_in[
"mcLR"] = vector<double> (9);
1291 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1292 if (m_mVector_in[
"useAxSl"][iAx] == 1) {
1293 const vector<TCLink*>& links = aTrack.
links(iAx * 2);
1295 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[bestTSIndex[iAx]]->hit()->cell());
1296 m_mVector_in[
"tsId"][iAx * 2] = t_segment->localId();
1297 m_mVector_in[
"tsId2D"][iAx] = m_mVector_in[
"tsId"][iAx * 2];
1298 m_mVector_in[
"wirePhi"][iAx * 2] = (double) t_segment->localId() / m_mConstV_in[
"nWires"][iAx * 2] * 4 * m_mConstD_in.at(
"Trg_PI");
1299 m_mVector_in[
"lutLR"][iAx * 2] = t_segment->LUT()->getValue(t_segment->lutPattern());
1301 if (m_mBool_in.at(
"fMc")) m_mVector_in[
"mcLR"][iAx * 2] = t_segment->hit()->mcLR() + 1;
1302 m_mVector_in[
"driftLength"][iAx * 2] = t_segment->hit()->drift();
1303 m_mVector_in[
"tdc"][iAx * 2] = t_segment->priorityTime();
1304 if (m_mBool_in.at(
"fmcLR") == 1) m_mVector_in[
"LR"][iAx * 2] = m_mVector_in[
"mcLR"][iAx * 2];
1305 else if (m_mBool_in.at(
"fLRLUT") == 1) m_mVector_in[
"LR"][iAx * 2] = m_mVector_in[
"lutLR"][iAx * 2];
1306 else m_mVector_in[
"LR"][iAx * 2] = 3;
1308 m_mVector_in[
"tsId"][iAx * 2] = 9999;
1309 m_mVector_in[
"wirePhi"][iAx * 2] = 9999;
1310 m_mVector_in[
"lutLR"][iAx * 2] = 0;
1312 if (m_mBool_in.at(
"fMc")) m_mVector_in[
"mcLR"][iAx * 2] = 9999;
1313 m_mVector_in[
"driftLength"][iAx * 2] = 9999;
1314 m_mVector_in[
"tdc"][iAx * 2] = 9999;
1315 if (m_mBool_in.at(
"fmcLR") == 1) m_mVector_in[
"LR"][iAx * 2] = 9999;
1316 else if (m_mBool_in.at(
"fLRLUT") == 1) m_mVector_in[
"LR"][iAx * 2] = 9999;
1317 else m_mVector_in[
"LR"][iAx * 2] = 9999;
1330 m_mDouble_in[
"phi02D"] = aTrack.
helix().
phi0();
1331 m_mDouble_in[
"pt2D"] = aTrack.
pt();
1332 if (aTrack.
charge() < 0) {
1333 m_mDouble_in[
"phi02D"] -= m_mConstD_in.at(
"Trg_PI");
1334 if (m_mDouble_in[
"phi02D"] < 0) m_mDouble_in[
"phi02D"] += 2 * m_mConstD_in.at(
"Trg_PI");
1336 m_mDouble_in[
"dr2D"] = aTrack.
helix().
dr() * 0.01;
1339 m_mDouble_in[
"charge"] = double(aTrack.
charge());
1341 m_mVector_in[
"phi2DError"] = vector<double> (5);
1342 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1343 if (m_mVector_in[
"useAxSl"][iAx] == 1) {
1345 if (m_mVector_in[
"LR"][2 * iAx] != 3) m_mVector_in[
"phi2DError"][iAx] = m_mConstV_in[
"driftPhi2DError"][iAx];
1346 else m_mVector_in[
"phi2DError"][iAx] = m_mConstV_in[
"wirePhi2DError"][iAx];
1348 if (m_mDouble_in[
"eventTime"] == 9999) m_mVector_in[
"phi2DError"][iAx] = m_mConstV_in[
"wirePhi2DError"][iAx];
1350 m_mVector_in[
"phi2DError"][iAx] = 9999;
1354 m_mVector_in[
"phi2DInvError"] = vector<double> (5);
1355 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1356 if (m_mVector_in[
"useAxSl"][iAx] == 1) {
1357 m_mVector_in[
"phi2DInvError"][iAx] = 1 / m_mVector_in[
"phi2DError"][iAx];
1359 m_mVector_in[
"phi2DInvError"][iAx] = 0;
1363 m_mVector_in[
"phi2D"] = vector<double> (5);
1364 if (m_mBool_in.at(
"f2DFitDrift") == 0 || m_mDouble_in[
"eventTime"] == 9999) {
1365 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1366 m_mVector_in[
"phi2D"][iAx] = m_mVector_in[
"wirePhi"][iAx * 2];
1369 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1370 if (m_mVector_in[
"useAxSl"][iAx] == 1) {
1372 string tableName =
"driftLengthTableSL" + to_string(iAx * 2);
1373 double t_driftTime = m_mVector_in[
"tdc"][iAx * 2] - m_mDouble_in[
"eventTime"];
1374 if (t_driftTime < 0) t_driftTime = 0;
1375 if (t_driftTime > 511) t_driftTime = 511;
1376 double t_driftLength = m_mConstV_in[tableName][(unsigned)t_driftTime];
1377 m_mVector_in[
"phi2D"][iAx] =
Fitter3DUtility::calPhi(m_mVector_in[
"wirePhi"][iAx * 2], t_driftLength, m_mConstV_in[
"rr"][iAx * 2],
1378 m_mVector_in[
"LR"][iAx * 2]);
1380 m_mVector_in[
"phi2D"][iAx] = 9999;
1385 if (m_mBool_in.at(
"f2DFit") == 0) {
1386 m_mDouble_in[
"rho"] = m_mDouble_in[
"pt2D"] / 0.01 / 1.5 / 0.299792458;
1387 m_mDouble_in[
"pt"] = 0.299792458 * 1.5 * m_mDouble_in[
"rho"] / 100;
1388 m_mDouble_in[
"phi0"] = m_mDouble_in[
"phi02D"];
1389 m_mDouble_in[
"fit2DChi2"] = 9999;
1391 m_mDouble_in[
"rho"] = 0;
1392 m_mDouble_in[
"phi0"] = 0;
1393 m_mDouble_in[
"fit2DChi2"] = 0;
1395 m_mDouble_in[
"rho"],
1396 m_mDouble_in[
"phi0"], m_mDouble_in[
"fit2DChi2"]);
1397 m_mDouble_in[
"pt"] = 0.3 * 1.5 * m_mDouble_in[
"rho"] / 100;
1402 m_mDouble_in[
"phi0"],
1403 m_mDouble_in[
"charge"], m_mDouble_in[
"charge2D"]);
1405 if (m_mBool_in.at(
"fVerbose")) {
1406 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]f2DFit: " <<
1407 m_mBool_in.at(
"f2DFit") <<
1409 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]evtTime: " <<
1410 m_mDouble_in[
"eventTime"]
1412 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]wirePhi: " <<
1413 m_mVector_in[
"wirePhi"][0]
1414 <<
" " << m_mVector_in[
"wirePhi"][1] <<
" " << m_mVector_in[
"wirePhi"][2] <<
" " << m_mVector_in[
"wirePhi"][3] <<
" " <<
1415 m_mVector_in[
"wirePhi"][4] <<
" " << m_mVector_in[
"wirePhi"][5] <<
" " << m_mVector_in[
"wirePhi"][6] <<
" " <<
1416 m_mVector_in[
"wirePhi"][7] <<
" "
1417 << m_mVector_in[
"wirePhi"][8] << endl;
1418 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]LR: " << int(
1419 m_mVector_in[
"LR"][0]) <<
" " << int(m_mVector_in[
"LR"][1]) <<
" " << int(m_mVector_in[
"LR"][2]) <<
" " << int(
1420 m_mVector_in[
"LR"][3]) <<
" " << int(m_mVector_in[
"LR"][4]) <<
" " << int(m_mVector_in[
"LR"][5]) <<
" " << int(
1421 m_mVector_in[
"LR"][6]) <<
" " << int(m_mVector_in[
"LR"][7]) <<
" " << int(m_mVector_in[
"LR"][8]) << endl;
1422 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]drift: " <<
1423 m_mVector_in[
"driftLength"][0] <<
" " << m_mVector_in[
"driftLength"][1] <<
" " << m_mVector_in[
"driftLength"][2] <<
" " <<
1424 m_mVector_in[
"driftLength"][3] <<
" " << m_mVector_in[
"driftLength"][4] <<
" " << m_mVector_in[
"driftLength"][5] <<
" " <<
1425 m_mVector_in[
"driftLength"][6] <<
" " << m_mVector_in[
"driftLength"][7] <<
" " << m_mVector_in[
"driftLength"][8] << endl;
1426 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]tdc: " <<
1427 m_mVector_in[
"tdc"][0] <<
1428 " " << m_mVector_in[
"tdc"][1] <<
" " << m_mVector_in[
"tdc"][2] <<
" " << m_mVector_in[
"tdc"][3] <<
" " << m_mVector_in[
"tdc"][4] <<
1430 m_mVector_in[
"tdc"][5] <<
" " << m_mVector_in[
"tdc"][6] <<
" " << m_mVector_in[
"tdc"][7] <<
" " << m_mVector_in[
"tdc"][8] << endl;
1431 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]rr2D: " <<
1432 m_mConstV_in[
"rr2D"][0] <<
1433 " " << m_mConstV_in[
"rr2D"][1] <<
" " << m_mConstV_in[
"rr2D"][2] <<
" " << m_mConstV_in[
"rr2D"][3] <<
" " << m_mConstV_in[
"rr2D"][4]
1435 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]Phi2D: " <<
1436 m_mVector_in[
"phi2D"][0]
1437 <<
" " << m_mVector_in[
"phi2D"][1] <<
" " << m_mVector_in[
"phi2D"][2] <<
" " << m_mVector_in[
"phi2D"][3] <<
" " <<
1438 m_mVector_in[
"phi2D"][4] <<
1440 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]Phi2DInvError: " <<
1441 m_mVector_in[
"phi2DInvError"][0] <<
" " << m_mVector_in[
"phi2DInvError"][1] <<
" " << m_mVector_in[
"phi2DInvError"][2] <<
" " <<
1442 m_mVector_in[
"phi2DInvError"][3] <<
" " << m_mVector_in[
"phi2DInvError"][4] << endl;
1443 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]charge: " << int(
1444 m_mDouble_in[
"charge"]) << endl;
1445 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]charge2D: " << int(
1446 m_mDouble_in[
"charge2D"]) << endl;
1447 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]pt: " <<
1448 m_mDouble_in[
"pt"] <<
1450 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]rho: " <<
1451 m_mDouble_in[
"rho"] <<
1453 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]phi0: " <<
1454 m_mDouble_in[
"phi0"] <<
1455 " " << m_mDouble_in[
"phi0"] / m_mConstD_in.at(
"Trg_PI") * 180 << endl;
1456 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]fit2DChi2: " <<
1457 m_mDouble_in[
"fit2DChi2"]
1459 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]useAxSl: " << int(
1460 m_mVector_in[
"useAxSl"][0]) <<
" " << int(m_mVector_in[
"useAxSl"][1]) <<
" " << int(m_mVector_in[
"useAxSl"][2]) <<
" " << int(
1461 m_mVector_in[
"useAxSl"][3]) << endl;
1464 if (std::isnan(m_mDouble_in[
"rho"]) || std::isnan(m_mDouble_in[
"phi0"])) {
1465 if (m_mBool_in.at(
"fVerbose") == 1) cout <<
"[2Dfit] Exiting because rho or phi0 is nan." << endl;
1473 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]evtTime: " <<
m_mDouble[
"eventTime"] << endl;
1474 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]wirePhi: " <<
m_mVector[
"wirePhi"][0] <<
" " <<
1478 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]LR: " << int(
m_mVector[
"LR"][0]) <<
" " << int(
1482 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]lutLR: " << int(
m_mVector[
"lutLR"][0]) <<
" " << int(
1486 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]useStSl: " << int(
m_mVector[
"useStSl"][0]) <<
" " << int(
1488 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]drift: " <<
m_mVector[
"driftLength"][0] <<
" " <<
1492 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]tdc: " <<
m_mVector[
"tdc"][0] <<
" " <<
1495 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]Phi2D: " <<
m_mVector[
"phi2D"][0] <<
" " <<
1497 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]Phi3D: " <<
m_mVector[
"phi3D"][0] <<
" " <<
1501 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]arcS: " <<
m_mVector[
"arcS"][0] <<
" " <<
1503 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]zerror: " <<
m_mVector[
"zError"][0] <<
" " <<
1505 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]izerror: " <<
m_mVector[
"iZError2"][0] <<
" " <<
1507 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]charge: " << int(
m_mDouble[
"charge"]) << endl;
1508 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]pt: " <<
m_mDouble[
"pt"] << endl;
1509 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]phi0: " <<
m_mDouble[
"phi0"] << endl;
1510 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]z0: " <<
m_mDouble[
"z0"] << endl;
1511 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]cot: " <<
m_mDouble[
"cot"] << endl;
1512 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]chi2: " <<
m_mDouble[
"zChi2"] << endl;
1514 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]mcCharge: " << int(
m_mDouble[
"mcCharge"]) << endl;
1515 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]mcPosZ: " <<
m_mVector[
"mcPosZ"][1] <<
" " <<
1517 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]mcPosZ: " <<
m_mVector[
"mcPosZ"][1] <<
" " <<
1519 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]mcLR: " << int(
m_mVector[
"mcLR"][0]) <<
" " << int(
1547 return string(
"TRGCDCFitter3D 6.0");
1557 stGeometry[
"priorityLayer"] = {10, 22, 34, 46};
1558 stGeometry[
"nWires"] = vector<double> (4);
1559 stGeometry[
"cdcRadius"] = vector<double> (4);
1560 stGeometry[
"zToStraw"] = vector<double> (4);
1561 stGeometry[
"nShift"] = vector<double> (4);
1562 stGeometry[
"angleSt"] = vector<double> (4);
1564 for (
int iSt = 0; iSt < 4; ++iSt) {
1565 stGeometry[
"nWires"][iSt] = cdc.nWiresInLayer(stGeometry[
"priorityLayer"][iSt]) * 2;
1566 stGeometry[
"cdcRadius"][iSt] = cdc.senseWireR(stGeometry[
"priorityLayer"][iSt]);
1567 stGeometry[
"zToStraw"][iSt] = cdc.senseWireBZ(stGeometry[
"priorityLayer"][iSt]);
1568 stGeometry[
"nShift"][iSt] = cdc.nShifts(stGeometry[
"priorityLayer"][iSt]);
1569 stGeometry[
"angleSt"][iSt] = 2 * stGeometry[
"cdcRadius"][iSt] * sin(M_PI * stGeometry[
"nShift"][iSt] /
1570 (stGeometry[
"nWires"][iSt])) /
1571 (cdc.senseWireFZ(stGeometry[
"priorityLayer"][iSt]) - stGeometry[
"zToStraw"][iSt]);
1577 stXts.resize(stPriorityLayer.size(), vector<double> (512));
1579 for (
unsigned iSt = 0; iSt < stPriorityLayer.size(); ++iSt) {
1580 for (
unsigned iTick = 0; iTick < stXts[iSt].size(); ++iTick) {
1581 double t = iTick * 2 * cdc.getTdcBinWidth();
1583 stXts[iSt][iTick] = cdc.getNominalDriftV() * t;
1585 double driftLength_0 = cdc.getDriftLength(t, stPriorityLayer[iSt], 0);
1586 double driftLength_1 = cdc.getDriftLength(t, stPriorityLayer[iSt], 1);
1587 stXts[iSt][iTick] = (driftLength_0 + driftLength_1) / 2;
1597 mConstD[
"Trg_PI"] = 3.141592653589793;
1598 mConstV[
"priorityLayer"] = {3, 10, 16, 22, 28, 34, 40, 46, 52};
1599 mConstV[
"rr"] = vector<double> (9);
1600 mConstV[
"nWires"] = vector<double> (9);
1601 mConstV[
"nTSs"] = vector<double> (9);
1602 for (
unsigned iSL = 0; iSL < 9; iSL++) {
1603 unsigned t_layerId = mConstV[
"priorityLayer"][iSL];
1604 mConstV[
"rr"][iSL] = cdc.senseWireR(t_layerId);
1605 mConstV[
"nWires"][iSL] = cdc.nWiresInLayer(t_layerId) * 2;
1606 mConstV[
"nTSs"][iSL] = cdc.nWiresInLayer(t_layerId);
1608 mConstV[
"nTSs2D"] = vector<double> (5);
1609 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1610 mConstV[
"nTSs2D"][iAx] = mConstV[
"nTSs"][2 * iAx];
1612 mConstV[
"zToStraw"] = vector<double> (4);
1613 mConstV[
"zToOppositeStraw"] = vector<double> (4);
1614 mConstV[
"angleSt"] = vector<double> (4);
1615 mConstV[
"nShift"] = vector<double> (4);
1616 for (
int iSt = 0; iSt < 4; iSt++) {
1617 unsigned t_layerId = mConstV[
"priorityLayer"][iSt * 2 + 1];
1618 mConstV[
"zToStraw"][iSt] = cdc.senseWireBZ(t_layerId);
1619 mConstV[
"zToOppositeStraw"][iSt] = cdc.senseWireFZ(t_layerId);
1620 mConstV[
"angleSt"][iSt] = 2 * mConstV[
"rr"][2 * iSt + 1] * sin(mConstD[
"Trg_PI"] * cdc.nShifts(t_layerId) /
1621 (2 * cdc.nWiresInLayer(t_layerId))) / (cdc.senseWireFZ(t_layerId) - cdc.senseWireBZ(t_layerId));
1622 mConstV[
"nShift"][iSt] = cdc.nShifts(t_layerId);
1625 mConstV[
"rr2D"] = vector<double> (5);
1626 mConstV[
"rr3D"] = vector<double> (4);
1627 for (
int iAx = 0; iAx < 5; iAx++) mConstV[
"rr2D"][iAx] = mConstV[
"rr"][iAx * 2];
1628 for (
int iSt = 0; iSt < 4; iSt++) mConstV[
"rr3D"][iSt] = mConstV[
"rr"][iSt * 2 + 1];
1630 mConstV[
"wirePhi2DError"] = vector<double> (5);
1631 mConstV[
"driftPhi2DError"] = vector<double> (5);
1632 mConstV[
"wirePhi2DError"][0] = 0.00085106;
1633 mConstV[
"wirePhi2DError"][1] = 0.00039841;
1634 mConstV[
"wirePhi2DError"][2] = 0.00025806;
1635 mConstV[
"wirePhi2DError"][3] = 0.00019084;
1636 mConstV[
"wirePhi2DError"][4] = 0.0001514;
1637 mConstV[
"driftPhi2DError"][0] = 0.00085106;
1638 mConstV[
"driftPhi2DError"][1] = 0.00039841;
1639 mConstV[
"driftPhi2DError"][2] = 0.00025806;
1640 mConstV[
"driftPhi2DError"][3] = 0.00019084;
1641 mConstV[
"driftPhi2DError"][4] = 0.0001514;
1642 mConstV[
"driftZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
1643 mConstV[
"wireZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
1647 for (
unsigned iSl = 0; iSl < 9; iSl++) {
1648 string tableName =
"driftLengthTableSL" + to_string(iSl);
1649 unsigned tableSize = 512;
1650 mConstV[tableName] = vector<double> (tableSize);
1651 unsigned t_layer = mConstV[
"priorityLayer"][iSl];
1652 for (
unsigned iTick = 0; iTick < tableSize; iTick++) {
1653 double t_driftTime = iTick * 2 * cdc.getTdcBinWidth();
1654 double avgDriftLength = 0;
1655 if (isXtSimple == 1) {
1656 avgDriftLength = cdc.getNominalDriftV() * t_driftTime;
1658 double driftLength_0 = cdc.getDriftLength(t_driftTime, t_layer, 0);
1659 double driftLength_1 = cdc.getDriftLength(t_driftTime, t_layer, 1);
1660 avgDriftLength = (driftLength_0 + driftLength_1) / 2;
1662 mConstV[tableName][iTick] = avgDriftLength;
1666 mConstD[
"tdcBitSize"] = 9;
1667 mConstD[
"rhoBitSize"] = 11;
1668 mConstD[
"iError2BitSize"] = 8;
1669 mConstD[
"iError2Max"] = 1 / pow(mConstV[
"wireZError"][0], 2);
1672 mConstD[
"phiMax"] = mConstD[
"Trg_PI"];
1673 mConstD[
"phiMin"] = -mConstD[
"Trg_PI"];
1674 mConstD[
"rhoMin"] = 20;
1675 mConstD[
"rhoMax"] = 2500;
1676 mConstD[
"phiBitSize"] = 13;
1677 mConstD[
"driftPhiLUTOutBitSize"] = mConstD[
"phiBitSize"] - 1;
1678 mConstD[
"driftPhiLUTInBitSize"] = mConstD[
"tdcBitSize"];
1679 mConstD[
"acosLUTOutBitSize"] = mConstD[
"phiBitSize"] - 1;
1680 mConstD[
"acosLUTInBitSize"] = mConstD[
"rhoBitSize"];
1681 mConstD[
"zLUTInBitSize"] = mConstD[
"phiBitSize"];
1682 mConstD[
"zLUTOutBitSize"] = 9;
1683 mConstD[
"iDenLUTInBitSize"] = 13;
1684 mConstD[
"iDenLUTOutBitSize"] = 11;
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.
A Class to store the Monte Carlo particle information.
TVector3 getVertex() const
Return production vertex position, shorthand for getProductionVertex().
TVector3 getMomentum() const
Return momentum.
unsigned int getStatus(unsigned short int bitmask=USHRT_MAX) const
Return status code of particle.
float getCharge() const
Return the particle charge defined in TDatabasePDG.
int getPDG() const
Return PDG code of particle.
TLorentzVector get4Vector() const
Return 4Vector of particle.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Type-safe access to single objects in the data store.
std::map< std::string, TVectorD * > m_mTVectorD
TVectorD map for saving values to root file.
std::map< std::string, std::vector< double > > m_mVector
Map to hold vector values for Fitter3D.
std::map< std::string, bool > m_mBool
Map to hold input options.
std::map< std::string, double > m_mConstD
Map to hold constant values for Fitter3D.
std::map< std::string, std::vector< signed long long > > m_mSavedSignals
Array of saved signals.
std::map< std::string, TRGCDCJLUT * > m_mLutStorage
Map to hold JLuts.
std::map< std::string, std::vector< double > > m_mConstV
Map to hold constant vectcors for Fitter3D.
std::map< std::string, double > m_mDouble
Map to hold double values for Fitter3D.
const std::string m_name
Name.
std::map< std::string, TRGCDCJSignal > m_mSignalStorage
Map to hold JSignals.
std::map< std::string, TClonesArray * > m_mTClonesArray
TClonesArray map for saving values to root file.
TFile * m_fileFitter3D
Tfile for Fitter3D root file.
TRGCDCJSignalData * m_commonData
For VHDL code.
TTree * m_treeTrackFitter3D
TTree for tracks of fitter3D.
std::map< std::string, std::vector< signed long long > > m_mSavedIoSignals
Array of I/O signals.
TTree * m_treeConstantsFitter3D
TTree for constants of fitter3D.
std::string m_rootFitter3DFileName
Members for saving.
const TRGCDC & m_cdc
CDCTRG.
TRGCDCHelix parameter class.
A class to hold common data for JSignals.
A class to represent a track segment hit in CDC.
float priorityTime(void) const
return priority time in TSHit.
A class to represent a reconstructed charged track in TRGCDC.
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 rotatePhi(double value, double refPhi)
Rotates to range [-pi, pi].
static int findQuadrant(double value)
Finds quadrant of angle. Angle is in rad.
static void rPhiFitter(double *rr, double *phi2, double *invphierror, double &rho, double &myphi0)
A circle fitter with invPhiError without fit chi2 output.
static double calZ(int charge, double anglest, double ztostraw, double rr, double phi, double rho, double phi0)
Calculates z.
static void setError(std::map< std::string, double > const &mConstD, std::map< std::string, std::vector< double > > const &mConstV, std::map< std::string, Belle2::TRGCDCJSignal > &mSignalStorage)
Sets error using JSignal class.
static double calS(double rho, double rr)
Calculates arc length.
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.
static int rotateTsId(int value, int refId, int nTSs)
Rotates to range [0, nTSs-1].
static unsigned toUnsignedTdc(int tdc, int nBits)
Changes tdc and event time to unsigned value that has # bits.
static void rSFit(double *iezz2, double *arcS, double *zz, double &z0, double &cot, double &zchi2)
3D fitter functions Fits z and arc S.
static void findImpactPosition(TVector3 *mcPosition, TLorentzVector *mcMomentum, int charge, TVector2 &helixCenter, TVector3 &impactPosition)
MC calculation functions Calculates the impact position of track.
static void constrainRPerStSl(std::map< std::string, std::vector< double > > const &mConstV, std::map< std::string, Belle2::TRGCDCJSignal > &mSignalStorage)
Constrains R for each SL differently using JSignal and multiple constants.
static void writeSignals(std::string outFilePath, std::map< std::string, std::vector< signed long long > > &data)
COE file functions.
static void multipleWriteCoe(int lutInBitsize, std::map< std::string, std::vector< signed long long > > &data, const std::string &fileDirectory)
Writes multiple signal values to a file in coe format.
const TRGCDCHelix & helix(void) const
returns helix parameter.
const TRGCDCRelation relation(void) const
returns MC information.
std::vector< const TRGCDCSegmentHit * > segmentHits(void) const
returns a list of TRGCDCSegmentHit.
const TRGCDCWire & center(void) const
returns a center wire.
void printToFile()
Utilities Function to print VHDL code.
static void findHitAxialSuperlayers(const TRGCDCTrack &aTrack, std::vector< double > &useAxSL, bool printError)
Finds which axial superlayers has TSs. useAxSL array indicating hit superlayers.
static void getStereoGeometry(std::map< std::string, std::vector< double > > &stGeometry)
Get stereo geometry.
void initialize()
Initialization.
static void valuesToMapSignals(std::vector< std::tuple< std::string, double, int, double, double, int > > const &inValues, Belle2::TRGCDCJSignalData *inCommonData, std::map< std::string, Belle2::TRGCDCJSignal > &outMap)
Values => [name, value, bitwidth, min, max, clock] Changes values to signals.
double charge(void) const
returns charge.
static double calPhi(TRGCDCSegmentHit const *segmentHit, double eventTime)
Utility functions.
bool isStereoTrackFull(const TRGCDCTrack &aTrack)
Checks if stereo track has 4 TSs. One per each superlayer.
void saveVhdlAndCoe()
Functions for saving.
bool getPrintVhdl() const
Gets the status of m_printVhdl.
int doit(std::vector< TRGCDCTrack * > &trackList)
Does track fitting.
static void getStereoXt(std::vector< double > const &stPriorityLayer, std::vector< std::vector< double > > &stXts, bool isSimple=0)
Get stereo Xt.
void removeImpossibleStereoSuperlayers(std::vector< double > &useStSL)
Removes TSs that are not possible with track Pt.
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 #)
int getValue(unsigned) const
get LUT Values
bool getPrintedToFile() const
Gets the status of m_printedToFile.
static void selectAxialTSs(const TRGCDCTrack &aTrack, std::vector< int > &bestTSIndex)
Selects priority TSs when there are multiple candidate TSs for a superlayer.
static void enterStage(const std::string &stageName)
Declare that you enter new stage.
void terminate()
Termination.
void saveIoSignals()
Saves all I/O signals for debugging.
double phi0(void) const
returns phi0.
const CLHEP::HepVector & a(void) const
returns helix parameters.
double dr(void) const
returns dr.
void print3DInformation(int iTrack)
Print's information for debugging 3D.
unsigned lutPattern(void) const
hit pattern containing bit for priority position
virtual ~TRGCDCFitter3D()
Destructor.
static void findHitStereoSuperlayers(const TRGCDCTrack &aTrack, std::vector< double > &useStSL, bool printError)
Finds which stereo superlayers has TSs. useStSL array indicating hit superlayers.
const TRGCDCSegment & segment(unsigned id) const
returns a track segment.
const TRGCDCLUT * LUT(void) const
returns LUT
int getEventTime(void) const
returns bad hits(finding invalid hits).
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,...
const HepGeom::Point3D< double > ORIGIN
Origin 3D point.
std::string name(void) const
Gets name of class.
static void leaveStage(const std::string &stageName)
Declare that you leave a stage.
void entryVhdlCode()
Function to print entry VHDL code.
static void getConstants(std::map< std::string, double > &mConstD, std::map< std::string, std::vector< double > > &mConstV, bool isXtSimple=0)
Get constants for firmwareFit.
std::string version(void) const
Gets version of class.
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.
const std::vector< TRGCDCLink * > & links(void) const
returns a vector to track segments.
const TRGCDCSegment & segment(void) const
returns a pointer to a track segment.
virtual double pt(void) const override
returns Pt.
void saveAllSignals()
Saves all signals for debugging.
void signalsVhdlCode()
Function to print definition of signal VHDL code.
void setVhdlOutputFile(const std::string &)
Sets the filename for VHDL output.
int doitComplex(std::vector< TRGCDCTrack * > &trackList)
Does track fitting using JSignals.
void buffersVhdlCode()
Function to print buffer VHDL code.
void setFitted(bool fitted)
set fit status
bool isAxialTrackFull(const TRGCDCTrack &aTrack)
Checks if axial track has 5 TSs. One per each superlayer.
void setPrintVhdl(bool)
Sets if to print VHDL output.
unsigned localId(void) const
returns local id in a layer.
static void mapSignalsToValues(std::map< std::string, Belle2::TRGCDCJSignal >const &inMap, std::vector< std::pair< std::string, int > > const &inChoose, std::vector< std::tuple< std::string, double, int, double, double, int > > &outValues)
Choose => [signalName, FpgaEffects(=1)/NoFpgaEffects(=0)] Values => [name, value, bitwidth,...
Abstract base class for different kinds of events.