13#define TRG_SHORT_NAMES
14#define TRGCDC_SHORT_NAMES
19#include "trg/trg/Debug.h"
20#include "trg/cdc/Fitter3D.h"
21#include "trg/cdc/Segment.h"
22#include "trg/cdc/TRGCDCTrack.h"
23#include "trg/cdc/Link.h"
24#include "trg/trg/Time.h"
25#include "trg/trg/Signal.h"
26#include "trg/trg/Utilities.h"
27#include "trg/cdc/TRGCDC.h"
28#include "trg/cdc/Wire.h"
29#include "trg/cdc/Layer.h"
30#include "trg/cdc/WireHit.h"
31#include "trg/cdc/WireHitMC.h"
32#include "trg/cdc/SegmentHit.h"
33#include "trg/cdc/TrackMC.h"
34#include "trg/cdc/Relation.h"
35#include "trg/cdc/FrontEnd.h"
36#include "trg/cdc/Merger.h"
37#include "trg/cdc/LUT.h"
38#include "trg/trg/Constants.h"
39#include "trg/cdc/Helix.h"
40#include "trg/cdc/Fitter3DUtility.h"
41#include "trg/cdc/EventTime.h"
42#include "trg/cdc/JSignal.h"
43#include "trg/cdc/JLUT.h"
44#include "trg/cdc/JSignalData.h"
45#include "trg/cdc/FpgaUtility.h"
46#include "trg/cdc/HandleRoot.h"
48#include "cdc/dataobjects/CDCSimHit.h"
49#include "cdc/geometry/CDCGeometryPar.h"
50#include <framework/dataobjects/EventMetaData.h>
51#include <framework/geometry/B2Vector3.h>
52#include "mdst/dataobjects/MCParticle.h"
63 const std::string& rootFitter3DFile,
65 const std::map<std::string, bool>& flags)
66 : m_name(name), m_cdc(
TRGCDC),
67 m_mBool(flags), m_rootFitter3DFileName(rootFitter3DFile),
68 m_treeTrackFitter3D(), m_treeConstantsFitter3D()
88 m_mBool[
"fIsIntegerEffect"] = 1;
100 for (
unsigned iSL = 0; iSL < 9; iSL++) {
106 m_mConstV[
"nTSs2D"] = vector<double> (5);
107 for (
unsigned iAx = 0; iAx < 5; iAx++) {
111 m_mConstV[
"zToStraw"] = vector<double> (4);
112 m_mConstV[
"zToOppositeStraw"] = vector<double> (4);
113 m_mConstV[
"angleSt"] = vector<double> (4);
114 m_mConstV[
"nShift"] = vector<double> (4);
115 for (
int iSt = 0; iSt < 4; iSt++) {
127 for (
int iSt = 0; iSt < 4; iSt++)
m_mConstV[
"rr3D"][iSt] =
m_mConstV[
"rr"][iSt * 2 + 1];
129 m_mConstV[
"wirePhi2DError"] = vector<double> (5);
130 m_mConstV[
"driftPhi2DError"] = vector<double> (5);
144 m_mConstV[
"wirePhi2DError"][0] = 0.00085106;
145 m_mConstV[
"wirePhi2DError"][1] = 0.00039841;
146 m_mConstV[
"wirePhi2DError"][2] = 0.00025806;
147 m_mConstV[
"wirePhi2DError"][3] = 0.00019084;
148 m_mConstV[
"wirePhi2DError"][4] = 0.0001514;
149 m_mConstV[
"driftPhi2DError"][0] = 0.00085106;
150 m_mConstV[
"driftPhi2DError"][1] = 0.00039841;
151 m_mConstV[
"driftPhi2DError"][2] = 0.00025806;
152 m_mConstV[
"driftPhi2DError"][3] = 0.00019084;
153 m_mConstV[
"driftPhi2DError"][4] = 0.0001514;
158 m_mConstV[
"driftZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
159 m_mConstV[
"wireZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
163 for (
unsigned iSl = 0; iSl < 9; iSl++) {
164 string tableName =
"driftLengthTableSL" + to_string(iSl);
165 unsigned tableSize = 512;
166 m_mConstV[tableName] = vector<double> (tableSize);
168 for (
unsigned iTick = 0; iTick < tableSize; iTick++) {
170 double avgDriftLength = 0;
171 if (
m_mBool[
"fXtSimple"] == 1) {
174 double driftLength_0 = cdcp.
getDriftLength(t_driftTime, t_layer, 0);
175 double driftLength_1 = cdcp.
getDriftLength(t_driftTime, t_layer, 1);
176 avgDriftLength = (driftLength_0 + driftLength_1) / 2;
178 m_mConstV[tableName][iTick] = avgDriftLength;
183 cout <<
"fLRLUT: " <<
m_mBool[
"fLRLUT"] << endl;
184 cout <<
"fMc: " <<
m_mBool[
"fMc"] << endl;
185 cout <<
"fVerbose: " <<
m_mBool[
"fVerbose"] << endl;
186 if (
m_mBool[
"fMc"]) cout <<
"fmcLR: " <<
m_mBool[
"fmcLR"] << endl;
187 cout <<
"fRoot: " <<
m_mBool[
"fRootFile"] << endl;
188 cout <<
"PI: " <<
m_mConstD[
"Trg_PI"] << endl;
192 cout <<
"nWires: " << int(
m_mConstV[
"nWires"][0]) <<
" " << int(
m_mConstV[
"nWires"][1]) <<
" " << int(
201 " " <<
m_mConstV[
"wireZError"][3] << endl;
203 <<
" " <<
m_mConstV[
"driftZError"][3] << endl;
204 cout <<
"wirePhiError: " <<
m_mConstV[
"wirePhi2DError"][0] <<
" " <<
m_mConstV[
"wirePhi2DError"][1] <<
" " <<
206 cout <<
"driftPhiError: " <<
m_mConstV[
"driftPhi2DError"][0] <<
" " <<
m_mConstV[
"driftPhi2DError"][1] <<
" " <<
228 m_mDouble[
"eventNumber"] = eventMetaDataPtr->getEvent();
232 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
234 TCTrack& aTrack = * trackList[iTrack];
240 m_mDouble[
"trackId"] = aTrack.getTrackID();
245 if (fit2DResult != 0) {
247 if (
m_mBool[
"fVerbose"]) cout <<
"Exit due to 2D fit result:" << fit2DResult << endl;
255 for (
unsigned iSt = 0; iSt < 4; iSt++) {
256 const vector<TCLink*>& links = aTrack.links(iSt * 2 + 1);
257 const unsigned nSegments = links.size();
258 cout <<
"iSt:" << iSt <<
" nSegments:" << nSegments << endl;
259 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
260 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
261 cout <<
" tsId:" << t_segment->localId()
262 <<
" tdc:" << t_segment->priorityTime() <<
" lr:" << t_segment->LUT()->getValue(t_segment->lutPattern())
263 <<
" priorityPosition:" << t_segment->priorityPosition() << endl;
268 m_mVector[
"useStSl"] = vector<double> (4);
274 for (
unsigned iAx = 0; iAx < 5; iAx++)
m_mVector[
"useSl"][2 * iAx] =
m_mVector[
"useAxSl"][iAx];
275 for (
unsigned iSt = 0; iSt < 4; iSt++)
m_mVector[
"useSl"][2 * iSt + 1] =
m_mVector[
"useAxSl"][iSt];
278 for (
unsigned iSt = 0; iSt < 4; iSt++) {
280 const vector<TCLink*>& links = aTrack.links(iSt * 2 + 1);
281 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[0]->hit()->cell());
282 m_mVector[
"tsId"][iSt * 2 + 1] = t_segment->localId();
284 m_mVector[
"lutLR"][iSt * 2 + 1] = t_segment->LUT()->getValue(t_segment->lutPattern());
285 if (
m_mBool[
"fMc"])
m_mVector[
"mcLR"][iSt * 2 + 1] = t_segment->hit()->mcLR() + 1;
286 m_mVector[
"driftLength"][iSt * 2 + 1] = t_segment->hit()->drift();
287 m_mVector[
"tdc"][iSt * 2 + 1] = t_segment->priorityTime();
293 m_mVector[
"wirePhi"][iSt * 2 + 1] = 9999;
296 m_mVector[
"driftLength"][iSt * 2 + 1] = 9999;
300 else m_mVector[
"LR"][iSt * 2 + 1] = 9999;
307 for (
unsigned iSt = 0; iSt < 4; iSt++) {
311 for (
unsigned iSt = 0; iSt < 4; iSt++) {
314 string tableName =
"driftLengthTableSL" + to_string(iSt * 2 + 1);
316 if (t_driftTime < 0) t_driftTime = 0;
317 double t_driftLength =
m_mConstV[tableName][(unsigned)t_driftTime];
326 m_mVector[
"zError"] = vector<double> (4);
327 for (
unsigned iSt = 0; iSt < 4; iSt++) {
339 m_mVector[
"iZError2"] = vector<double> (4);
340 for (
unsigned iSt = 0; iSt < 4; iSt++) {
350 for (
unsigned iSt = 0; iSt < 4; iSt++) {
361 for (
unsigned iSt = 0; iSt < 4; iSt++) {
383 aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::fit3D, 1);
384 if (
m_mBool[
"fVerbose"]) cout <<
"Exit due to 3D fit cot result:" <<
m_mDouble[
"cot"] << endl;
389 if (
m_mBool[
"fVerbose"]) cout <<
"Fit was done successfully." << endl;
392 CLHEP::HepVector a(5);
393 a = aTrack.helix().a();
406 aTrack.set2DFitChi2(
m_mDouble[
"fit2DChi2"]);
408 aTrack.setHelix(helix);
421 HandleRoot::saveTrackValues(
"fitter3D",
438 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
439 TCTrack& aTrack = * trackList[iTrack];
440 if (aTrack.fitted() == 0) aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::fit3D, 1);
445 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
446 TCTrack& aTrack = *trackList[iTrack];
447 if (aTrack.fitted()) {
448 double fitZ0 = aTrack.helix().dz();
449 if (fitZ0 > 20 || fitZ0 < -20) aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::fit3D, 1);
478 m_mDouble[
"eventNumber"] = eventMetaDataPtr->getEvent();
482 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
484 TCTrack& aTrack = * trackList[iTrack];
491 m_mDouble[
"trackId"] = aTrack.getTrackID();
496 if (fit2DResult != 0) {
505 for (
unsigned iSt = 0; iSt < 4; iSt++) {
506 const vector<TCLink*>& links = aTrack.links(iSt * 2 + 1);
507 const unsigned nSegments = links.size();
508 cout <<
"iSt:" << iSt <<
" nSegments:" << nSegments << endl;
509 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
510 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
511 cout <<
" tsId:" << t_segment->localId()
512 <<
" tdc:" << t_segment->priorityTime() <<
" lr:" << t_segment->LUT()->getValue(t_segment->lutPattern())
513 <<
" priorityPosition:" << t_segment->priorityPosition() << endl;
517 m_mVector[
"useStSl"] = vector<double> (4);
523 for (
unsigned iSt = 0; iSt < 4; iSt++) {
525 const vector<TCLink*>& links = aTrack.links(iSt * 2 + 1);
526 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[0]->hit()->cell());
527 m_mVector[
"tsId"][iSt * 2 + 1] = t_segment->localId();
529 m_mVector[
"lutLR"][iSt * 2 + 1] = t_segment->LUT()->getValue(t_segment->lutPattern());
530 if (
m_mBool[
"fMc"])
m_mVector[
"mcLR"][iSt * 2 + 1] = t_segment->hit()->mcLR() + 1;
531 m_mVector[
"driftLength"][iSt * 2 + 1] = t_segment->hit()->drift();
532 m_mVector[
"tdc"][iSt * 2 + 1] = t_segment->priorityTime();
538 m_mVector[
"wirePhi"][iSt * 2 + 1] = 9999;
541 m_mVector[
"driftLength"][iSt * 2 + 1] = 9999;
545 else m_mVector[
"LR"][iSt * 2 + 1] = 9999;
558 for (
unsigned iSt = 0; iSt < 4; iSt++) {
562 for (
unsigned iSt = 0; iSt < 4; iSt++) {
564 string tableName =
"driftLengthTableSL" + to_string(iSt * 2 + 1);
566 if (t_driftTime < 0) t_driftTime = 0;
567 double t_driftLength =
m_mConstV[tableName][(unsigned)t_driftTime];
574 m_mVector[
"zError"] = vector<double> (4);
575 for (
unsigned iSt = 0; iSt < 4; iSt++) {
583 m_mVector[
"iZError2"] = vector<double> (4);
584 for (
unsigned iSt = 0; iSt < 4; iSt++) {
615 double rhoMax = 2500;
624 m_mConstD[
"driftPhiLUTOutBitSize"] = phiBitSize - 1;
626 m_mConstD[
"acosLUTOutBitSize"] = phiBitSize - 1;
637 if (t_quadrant == 1)
m_mDouble[
"relRefPhi"] = 0;
643 else if (t_quadrant == 2)
m_mDouble[
"relRefPhi"] = 0;
649 m_mVector[
"relPhi3D"] = vector<double> (4);
650 for (
unsigned iSt = 0; iSt < 4;
654 m_mVector[
"relWirePhi3D"] = vector<double> (4);
655 for (
unsigned iSt = 0; iSt < 4; iSt++) {
658 while (rangeOk == 0) {
659 if (t_relWirePhi < 0) t_relWirePhi += 2 *
m_mConstD[
"Trg_PI"];
660 else if (t_relWirePhi > 2 *
m_mConstD[
"Trg_PI"]) t_relWirePhi -= 2 *
m_mConstD[
"Trg_PI"];
663 m_mVector[
"relWirePhi3D"][iSt] = t_relWirePhi;
667 m_mVector[
"relTsId3D"] = vector<double> (4);
668 for (
unsigned iSt = 0; iSt < 4;
675 m_mDouble[
"pt"] = rhoMax * 0.3 * 1.5 * 0.01;
682 m_mVector[
"unsignedTdc"] = vector<double> (9);
683 for (
unsigned iSt = 0; iSt < 4; iSt++) {
692 vector<tuple<string, double, int, double, double, int> > t_values = {
693 make_tuple(
"phi0",
m_mDouble[
"relPhi0"], phiBitSize, phiMin, phiMax, 0),
696 make_tuple(
"charge", (
int)(
m_mDouble[
"charge2D"] == 1 ? 1 : 0), 1, 0, 1.5, 0),
697 make_tuple(
"lr_0",
m_mVector[
"lutLR"][1], 2, 0, 3.5, 0),
698 make_tuple(
"lr_1",
m_mVector[
"lutLR"][3], 2, 0, 3.5, 0),
699 make_tuple(
"lr_2",
m_mVector[
"lutLR"][5], 2, 0, 3.5, 0),
700 make_tuple(
"lr_3",
m_mVector[
"lutLR"][7], 2, 0, 3.5, 0),
701 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),
702 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),
703 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),
704 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),
710 make_tuple(
"eventTimeValid", (
int)
m_mDouble[
"eventTimeValid"], 1, 0, 1.5, 0),
722 vector<tuple<string, double, int, double, double, int> > resultValues;
724 vector<pair<string, int> > t_chooseSignals = {
725 make_pair(
"z0", 0), make_pair(
"cot", 0), make_pair(
"chi2Sum", 0)
734 (*it).second.setName((*it).first);
755 vector<pair<string, int> > chooseValues = {
756 make_pair(
"zz_0",
m_mBool[
"fIsIntegerEffect"]),
757 make_pair(
"zz_1",
m_mBool[
"fIsIntegerEffect"]),
758 make_pair(
"zz_2",
m_mBool[
"fIsIntegerEffect"]),
759 make_pair(
"zz_3",
m_mBool[
"fIsIntegerEffect"]),
760 make_pair(
"arcS_0",
m_mBool[
"fIsIntegerEffect"]),
761 make_pair(
"arcS_1",
m_mBool[
"fIsIntegerEffect"]),
762 make_pair(
"arcS_2",
m_mBool[
"fIsIntegerEffect"]),
763 make_pair(
"arcS_3",
m_mBool[
"fIsIntegerEffect"]),
764 make_pair(
"z0",
m_mBool[
"fIsIntegerEffect"]),
765 make_pair(
"cot",
m_mBool[
"fIsIntegerEffect"]),
766 make_pair(
"zChi2",
m_mBool[
"fIsIntegerEffect"])
769 vector<tuple<string, double, int, double, double, int> > outValues;
791 m_mVector[
"float_zz"] = vector<double> (4);
793 for (
unsigned iSt = 0; iSt < 4;
797 m_mVector[
"float_arcS"] = vector<double> (4);
798 for (
unsigned iSt = 0; iSt < 4;
808 for (
unsigned iSt = 0; iSt < 4; iSt++) cout <<
"float_zz[" << iSt <<
"] : " <<
m_mVector[
"float_zz"][iSt] <<
" ";
810 for (
unsigned iSt = 0; iSt < 4; iSt++) cout <<
"float_arcS[" << iSt <<
"] : " <<
m_mVector[
"float_arcS"][iSt] <<
" ";
812 cout <<
"float_z0: " <<
m_mDouble[
"float_z0"] << endl;
813 cout <<
"float_zChi2: " <<
m_mDouble[
"float_zChi2"] << endl;
827 CLHEP::HepVector a(5);
828 a = aTrack.helix().a();
841 aTrack.setHelix(helix);
842 aTrack.set2DFitChi2(
m_mDouble[
"fit2DChi2"]);
856 HandleRoot::saveTrackValues(
"fitter3D",
873 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
874 TCTrack& aTrack = * trackList[iTrack];
875 if (aTrack.fitted() == 0) aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::fit3D, 1);
880 for (
unsigned iTrack = 0; iTrack < trackList.size(); iTrack++) {
881 TCTrack& aTrack = *trackList[iTrack];
882 if (aTrack.fitted()) {
883 double fitZ0 = aTrack.helix().dz();
884 if (fitZ0 > 20 || fitZ0 < -20) aTrack.setDebugValue(TRGCDCTrack::EDebugValueType::fit3D, 1);
928 it->second->makeCOE(it->first +
".coe");
949 for (
unsigned iSt = 0; iSt < 4;
952 for (
unsigned iSt = 0; iSt < 4;
964 std::map<std::string, double>& m_mDouble_in, std::map<std::string, std::vector<double> >& m_mVector_in)
967 const TCRelation& trackRelation = aTrack->
relation();
969 const MCParticle& trackMCParticle = trackRelation.mcParticle(0);
972 ROOT::Math::XYZVector vertex = trackMCParticle.
getVertex();
973 ROOT::Math::PxPyPzEVector vector4 = trackMCParticle.
get4Vector();
974 ROOT::Math::XYVector helixCenter;
975 ROOT::Math::XYZVector impactPosition;
977 m_mVector_in[
"mcVertex"] = vector<double> ({vertex.X(), vertex.Y(), vertex.Z()});
978 m_mVector_in[
"mcMomentum"] = vector<double> ({vector4.Px(), vector4.Py(), vector4.Pz()});
979 m_mVector_in[
"helixCenter"] = vector<double> ({helixCenter.X(), helixCenter.Y()});
980 m_mVector_in[
"impactPosition"] = vector<double> ({impactPosition.X(), impactPosition.Y(), impactPosition.Z()});
983 m_mDouble_in[
"mcPt"] = trackMCParticle.
getMomentum().Rho();
984 m_mDouble_in[
"mcPhi0"] = 0;
985 if (trackMCParticle.
getCharge() > 0) m_mDouble_in[
"mcPhi0"] = trackMCParticle.
getMomentum().Phi() - m_mConstD_in.at(
"Trg_PI") / 2;
986 if (trackMCParticle.
getCharge() < 0) m_mDouble_in[
"mcPhi0"] = trackMCParticle.
getMomentum().Phi() + m_mConstD_in.at(
"Trg_PI") / 2;
988 if (m_mDouble_in[
"mcPhi0"] < 0) m_mDouble_in[
"mcPhi0"] += 2 * m_mConstD_in.at(
"Trg_PI");
990 m_mDouble_in[
"mcZ0"] = impactPosition.Z();
992 m_mDouble_in[
"mcCharge"] = trackMCParticle.
getCharge();
995 TVectorD mcStatus(3);
996 m_mDouble_in[
"mcStatus"] = trackMCParticle.
getStatus();
997 m_mDouble_in[
"pdgId"] = trackMCParticle.
getPDG();
1001 unsigned id = trackRelation.contributor(0);
1002 vector<const TCSHit*> mcAllTSList[9];
1003 vector<const TCSHit*> mcTSList(9);
1005 const vector<const TCSHit*> hits = m_cdc_in.
segmentHits();
1006 for (
unsigned i = 0; i < hits.size(); i++) {
1007 const TCSHit& ts = * hits[i];
1008 if (! ts.signal().active())
continue;
1009 const TCWHit* wh = ts.segment().center().hit();
1011 const unsigned trackId = wh->iMCParticle();
1013 mcAllTSList[wh->wire().superLayerId()].push_back(& ts);
1016 for (
unsigned i = 0; i < 9; i++) {
1017 const TCSHit* best = 0;
1018 if (mcAllTSList[i].size() == 0) {
1019 }
else if (mcAllTSList[i].size() == 1) {
1020 best = mcAllTSList[i][0];
1022 int timeMin = 99999;
1023 for (
unsigned k = 0; k < mcAllTSList[i].size(); k++) {
1024 const TRGSignal& timing = mcAllTSList[i][k]->signal();
1025 const TRGTime& t = * timing[0];
1026 if (t.time() < timeMin) {
1028 best = mcAllTSList[i][k];
1037 m_mVector_in[
"mcPosX"] = vector<double> ({9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999});
1038 m_mVector_in[
"mcPosY"] = vector<double> ({9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999});
1039 m_mVector_in[
"mcPosZ"] = vector<double> ({9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999});
1040 for (
unsigned iSL = 0; iSL < 9; iSL++) {
1041 if (mcTSList[iSL] != 0) {
1042 ROOT::Math::XYZVector posTrack = mcTSList[iSL]->simHit()->getPosTrack();
1043 m_mVector_in[
"mcPosX"][iSL] = posTrack.X();
1044 m_mVector_in[
"mcPosY"][iSL] = posTrack.Y();
1045 m_mVector_in[
"mcPosZ"][iSL] = posTrack.Z();
1049 m_mVector_in[
"simMcLR"] = vector<double> (9);
1050 for (
unsigned iSL = 0; iSL < 9; iSL++) {
1051 if (mcTSList[iSL] != 0) {
1052 m_mVector_in[
"simMcLR"][iSL] = mcTSList[iSL]->simHit()->getPosFlag();
1074 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1076 const vector<TCLink*>& links = aTrack.
links(iAx * 2);
1077 const unsigned nSegments = links.size();
1080 bool priorityHitTS = 0;
1081 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1082 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
1083 if (t_segment->center().hit() != 0) priorityHitTS = 1;
1085 if (nSegments != 1) {
1086 if (nSegments == 0) {
1088 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isAxialTrackFull() => There are no TS." << endl;
1090 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isAxialTrackFull() => multiple TS are assigned." << endl;
1093 if (priorityHitTS == 0) {
1095 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isAxialTrackFull() => There are no priority hit TS" << endl;
1105 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1107 const vector<TCLink*>& links = aTrack.
links(iSt * 2 + 1);
1108 const unsigned nSegments = links.size();
1111 bool priorityHitTS = 0;
1112 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1113 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
1114 if (t_segment->center().hit() != 0) priorityHitTS = 1;
1116 if (nSegments != 1) {
1117 if (nSegments == 0) {
1119 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isStereoTrackFull() => There are no TS." << endl;
1121 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isStereoTrackFull() => multiple TS are assigned." << endl;
1124 if (priorityHitTS == 0) {
1126 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::isStereoTrackFull() => There are no priority hit TS" << endl;
1135 useAxSl.assign(5, 1);
1136 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1138 const vector<TCLink*>& links = aTrack.
links(iAx * 2);
1139 const unsigned nSegments = links.size();
1142 bool priorityHitTS = 0;
1144 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1145 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
1146 if (t_segment->center().hit() != 0) priorityHitTS = 1;
1149 if (nSegments != 1) {
1150 if (nSegments == 0) {
1153 if (printError) cout <<
"Fitter3D::findHitAxialSuperlayers() => multiple TS are assigned." << endl;
1156 if (priorityHitTS == 0) {
1158 if (printError) cout <<
"Fitter3D::findHitAxialSuperlayers() => There are no priority hit TS" << endl;
1166 useStSl.assign(4, 1);
1167 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1169 const vector<TCLink*>& links = aTrack.
links(iSt * 2 + 1);
1170 const unsigned nSegments = links.size();
1173 bool priorityHitTS = 0;
1174 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1175 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
1176 if (t_segment->center().hit() != 0) priorityHitTS = 1;
1178 if (nSegments != 1) {
1179 if (nSegments == 0) {
1182 if (printError) cout <<
"Fitter3D::findHitStereoSuperlayers() => multiple TS are assigned." << endl;
1185 if (priorityHitTS == 0) {
1187 if (printError) cout <<
"Fitter3D::findHitStereoSuperlayers() => There are no priority hit TS" << endl;
1195 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1199 if (
m_mBool[
"fIsPrintError"]) cout <<
"Fitter3D::removeImpossibleStereoSuperlayers() => pt is too low for SL." << endl;
1206 bestTSIndex.resize(5);
1207 std::fill_n(bestTSIndex.begin(), 5, -1);
1208 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1210 const vector<TCLink*>& links = aTrack.
links(iAx * 2);
1211 const unsigned nSegments = links.size();
1214 vector<tuple<int, double> > tsCandiateInfo(nSegments);
1216 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1217 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[iTS]->hit()->cell());
1218 int firstPriority = 0;
1219 if (t_segment->center().hit() != 0) firstPriority = 1;
1220 double tdc = t_segment->priorityTime();
1221 std::get<0>(tsCandiateInfo[iTS]) = firstPriority;
1222 std::get<1>(tsCandiateInfo[iTS]) = tdc;
1227 pair<int, tuple<int, double> > bestTS = make_pair(-1, make_tuple(-1, 9999));
1229 if (tsCandiateInfo.size() != 0) {
1242 for (
unsigned iTS = 0; iTS < nSegments; iTS++) {
1243 if (std::get<0>(tsCandiateInfo[iTS]) == 1) {
1245 if (bestTS.first == -1) select = 1;
1246 else if (std::get<1>(bestTS.second) > std::get<1>(tsCandiateInfo[iTS])) select = 1;
1249 bestTS.second = tsCandiateInfo[iTS];
1255 bestTSIndex[iAx] = bestTS.first;
1260 const std::map<std::string, double>& m_mConstD_in,
1261 std::map<std::string, std::vector<double> >& m_mConstV_in, std::map<std::string, double>& m_mDouble_in,
1262 std::map<std::string, std::vector<double> >& m_mVector_in)
1264 m_mVector_in[
"useAxSl"] = vector<double> (5);
1268 vector<int> bestTSIndex(5);
1270 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1271 if (bestTSIndex[iAx] != -1) m_mVector_in[
"useAxSl"][iAx] = 1;
1276 m_mDouble_in[
"nHitAx"] = m_mVector_in[
"useAxSl"][0] + m_mVector_in[
"useAxSl"][1] + m_mVector_in[
"useAxSl"][2] +
1277 m_mVector_in[
"useAxSl"][3] +
1278 m_mVector_in[
"useAxSl"][4];
1279 if (m_mDouble_in[
"nHitAx"] <= 1) {
1280 if (m_mBool_in.at(
"fVerbose") == 1) cout <<
"[2DFit] Exiting because nHitAx is " << m_mDouble_in[
"nHitAx"] << endl;
1286 m_mVector_in[
"tsId"] = vector<double> (9);
1287 m_mVector_in[
"tsId2D"] = vector<double> (5);
1288 m_mVector_in[
"wirePhi"] = vector<double> (9);
1289 m_mVector_in[
"lutLR"] = vector<double> (9);
1290 m_mVector_in[
"LR"] = vector<double> (9);
1291 m_mVector_in[
"driftLength"] = vector<double> (9);
1292 m_mVector_in[
"tdc"] = vector<double> (9);
1293 if (!m_mVector_in.count(
"mcLR")) m_mVector_in[
"mcLR"] = vector<double> (9);
1294 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1295 if (m_mVector_in[
"useAxSl"][iAx] == 1) {
1296 const vector<TCLink*>& links = aTrack.
links(iAx * 2);
1298 const TCSegment* t_segment =
dynamic_cast<const TCSegment*
>(& links[bestTSIndex[iAx]]->hit()->cell());
1299 m_mVector_in[
"tsId"][iAx * 2] = t_segment->localId();
1300 m_mVector_in[
"tsId2D"][iAx] = m_mVector_in[
"tsId"][iAx * 2];
1301 m_mVector_in[
"wirePhi"][iAx * 2] = (double) t_segment->localId() / m_mConstV_in[
"nWires"][iAx * 2] * 4 * m_mConstD_in.at(
"Trg_PI");
1302 m_mVector_in[
"lutLR"][iAx * 2] = t_segment->LUT()->getValue(t_segment->lutPattern());
1304 if (m_mBool_in.at(
"fMc")) m_mVector_in[
"mcLR"][iAx * 2] = t_segment->hit()->mcLR() + 1;
1305 m_mVector_in[
"driftLength"][iAx * 2] = t_segment->hit()->drift();
1306 m_mVector_in[
"tdc"][iAx * 2] = t_segment->priorityTime();
1307 if (m_mBool_in.at(
"fmcLR") == 1) m_mVector_in[
"LR"][iAx * 2] = m_mVector_in[
"mcLR"][iAx * 2];
1308 else if (m_mBool_in.at(
"fLRLUT") == 1) m_mVector_in[
"LR"][iAx * 2] = m_mVector_in[
"lutLR"][iAx * 2];
1309 else m_mVector_in[
"LR"][iAx * 2] = 3;
1311 m_mVector_in[
"tsId"][iAx * 2] = 9999;
1312 m_mVector_in[
"wirePhi"][iAx * 2] = 9999;
1313 m_mVector_in[
"lutLR"][iAx * 2] = 0;
1315 if (m_mBool_in.at(
"fMc")) m_mVector_in[
"mcLR"][iAx * 2] = 9999;
1316 m_mVector_in[
"driftLength"][iAx * 2] = 9999;
1317 m_mVector_in[
"tdc"][iAx * 2] = 9999;
1318 if (m_mBool_in.at(
"fmcLR") == 1) m_mVector_in[
"LR"][iAx * 2] = 9999;
1319 else if (m_mBool_in.at(
"fLRLUT") == 1) m_mVector_in[
"LR"][iAx * 2] = 9999;
1320 else m_mVector_in[
"LR"][iAx * 2] = 9999;
1333 m_mDouble_in[
"phi02D"] = aTrack.
helix().
phi0();
1334 m_mDouble_in[
"pt2D"] = aTrack.
pt();
1335 if (aTrack.
charge() < 0) {
1336 m_mDouble_in[
"phi02D"] -= m_mConstD_in.at(
"Trg_PI");
1337 if (m_mDouble_in[
"phi02D"] < 0) m_mDouble_in[
"phi02D"] += 2 * m_mConstD_in.at(
"Trg_PI");
1339 m_mDouble_in[
"dr2D"] = aTrack.
helix().
dr() * 0.01;
1342 m_mDouble_in[
"charge"] = double(aTrack.
charge());
1344 m_mVector_in[
"phi2DError"] = vector<double> (5);
1345 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1346 if (m_mVector_in[
"useAxSl"][iAx] == 1) {
1348 if (m_mVector_in[
"LR"][2 * iAx] != 3) m_mVector_in[
"phi2DError"][iAx] = m_mConstV_in[
"driftPhi2DError"][iAx];
1349 else m_mVector_in[
"phi2DError"][iAx] = m_mConstV_in[
"wirePhi2DError"][iAx];
1351 if (m_mDouble_in[
"eventTime"] == 9999) m_mVector_in[
"phi2DError"][iAx] = m_mConstV_in[
"wirePhi2DError"][iAx];
1353 m_mVector_in[
"phi2DError"][iAx] = 9999;
1357 m_mVector_in[
"phi2DInvError"] = vector<double> (5);
1358 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1359 if (m_mVector_in[
"useAxSl"][iAx] == 1) {
1360 m_mVector_in[
"phi2DInvError"][iAx] = 1 / m_mVector_in[
"phi2DError"][iAx];
1362 m_mVector_in[
"phi2DInvError"][iAx] = 0;
1366 m_mVector_in[
"phi2D"] = vector<double> (5);
1367 if (m_mBool_in.at(
"f2DFitDrift") == 0 || m_mDouble_in[
"eventTime"] == 9999) {
1368 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1369 m_mVector_in[
"phi2D"][iAx] = m_mVector_in[
"wirePhi"][iAx * 2];
1372 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1373 if (m_mVector_in[
"useAxSl"][iAx] == 1) {
1375 string tableName =
"driftLengthTableSL" + to_string(iAx * 2);
1376 double t_driftTime = m_mVector_in[
"tdc"][iAx * 2] - m_mDouble_in[
"eventTime"];
1377 if (t_driftTime < 0) t_driftTime = 0;
1378 if (t_driftTime > 511) t_driftTime = 511;
1379 double t_driftLength = m_mConstV_in[tableName][(unsigned)t_driftTime];
1380 m_mVector_in[
"phi2D"][iAx] =
Fitter3DUtility::calPhi(m_mVector_in[
"wirePhi"][iAx * 2], t_driftLength, m_mConstV_in[
"rr"][iAx * 2],
1381 m_mVector_in[
"LR"][iAx * 2]);
1383 m_mVector_in[
"phi2D"][iAx] = 9999;
1388 if (m_mBool_in.at(
"f2DFit") == 0) {
1389 m_mDouble_in[
"rho"] = m_mDouble_in[
"pt2D"] / 0.01 / 1.5 / 0.299792458;
1390 m_mDouble_in[
"pt"] = 0.299792458 * 1.5 * m_mDouble_in[
"rho"] / 100;
1391 m_mDouble_in[
"phi0"] = m_mDouble_in[
"phi02D"];
1392 m_mDouble_in[
"fit2DChi2"] = 9999;
1394 m_mDouble_in[
"rho"] = 0;
1395 m_mDouble_in[
"phi0"] = 0;
1396 m_mDouble_in[
"fit2DChi2"] = 0;
1398 m_mDouble_in[
"rho"],
1399 m_mDouble_in[
"phi0"], m_mDouble_in[
"fit2DChi2"]);
1400 m_mDouble_in[
"pt"] = 0.3 * 1.5 * m_mDouble_in[
"rho"] / 100;
1405 m_mDouble_in[
"phi0"],
1406 m_mDouble_in[
"charge"], m_mDouble_in[
"charge2D"]);
1408 if (m_mBool_in.at(
"fVerbose")) {
1409 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]f2DFit: " <<
1410 m_mBool_in.at(
"f2DFit") <<
1412 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]evtTime: " <<
1413 m_mDouble_in[
"eventTime"]
1415 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]wirePhi: " <<
1416 m_mVector_in[
"wirePhi"][0]
1417 <<
" " << m_mVector_in[
"wirePhi"][1] <<
" " << m_mVector_in[
"wirePhi"][2] <<
" " << m_mVector_in[
"wirePhi"][3] <<
" " <<
1418 m_mVector_in[
"wirePhi"][4] <<
" " << m_mVector_in[
"wirePhi"][5] <<
" " << m_mVector_in[
"wirePhi"][6] <<
" " <<
1419 m_mVector_in[
"wirePhi"][7] <<
" "
1420 << m_mVector_in[
"wirePhi"][8] << endl;
1421 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]LR: " << int(
1422 m_mVector_in[
"LR"][0]) <<
" " << int(m_mVector_in[
"LR"][1]) <<
" " << int(m_mVector_in[
"LR"][2]) <<
" " << int(
1423 m_mVector_in[
"LR"][3]) <<
" " << int(m_mVector_in[
"LR"][4]) <<
" " << int(m_mVector_in[
"LR"][5]) <<
" " << int(
1424 m_mVector_in[
"LR"][6]) <<
" " << int(m_mVector_in[
"LR"][7]) <<
" " << int(m_mVector_in[
"LR"][8]) << endl;
1425 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]drift: " <<
1426 m_mVector_in[
"driftLength"][0] <<
" " << m_mVector_in[
"driftLength"][1] <<
" " << m_mVector_in[
"driftLength"][2] <<
" " <<
1427 m_mVector_in[
"driftLength"][3] <<
" " << m_mVector_in[
"driftLength"][4] <<
" " << m_mVector_in[
"driftLength"][5] <<
" " <<
1428 m_mVector_in[
"driftLength"][6] <<
" " << m_mVector_in[
"driftLength"][7] <<
" " << m_mVector_in[
"driftLength"][8] << endl;
1429 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]tdc: " <<
1430 m_mVector_in[
"tdc"][0] <<
1431 " " << m_mVector_in[
"tdc"][1] <<
" " << m_mVector_in[
"tdc"][2] <<
" " << m_mVector_in[
"tdc"][3] <<
" " << m_mVector_in[
"tdc"][4] <<
1433 m_mVector_in[
"tdc"][5] <<
" " << m_mVector_in[
"tdc"][6] <<
" " << m_mVector_in[
"tdc"][7] <<
" " << m_mVector_in[
"tdc"][8] << endl;
1434 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]rr2D: " <<
1435 m_mConstV_in[
"rr2D"][0] <<
1436 " " << m_mConstV_in[
"rr2D"][1] <<
" " << m_mConstV_in[
"rr2D"][2] <<
" " << m_mConstV_in[
"rr2D"][3] <<
" " << m_mConstV_in[
"rr2D"][4]
1438 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]Phi2D: " <<
1439 m_mVector_in[
"phi2D"][0]
1440 <<
" " << m_mVector_in[
"phi2D"][1] <<
" " << m_mVector_in[
"phi2D"][2] <<
" " << m_mVector_in[
"phi2D"][3] <<
" " <<
1441 m_mVector_in[
"phi2D"][4] <<
1443 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]Phi2DInvError: " <<
1444 m_mVector_in[
"phi2DInvError"][0] <<
" " << m_mVector_in[
"phi2DInvError"][1] <<
" " << m_mVector_in[
"phi2DInvError"][2] <<
" " <<
1445 m_mVector_in[
"phi2DInvError"][3] <<
" " << m_mVector_in[
"phi2DInvError"][4] << endl;
1446 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]charge: " << int(
1447 m_mDouble_in[
"charge"]) << endl;
1448 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]charge2D: " << int(
1449 m_mDouble_in[
"charge2D"]) << endl;
1450 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]pt: " <<
1451 m_mDouble_in[
"pt"] <<
1453 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]rho: " <<
1454 m_mDouble_in[
"rho"] <<
1456 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]phi0: " <<
1457 m_mDouble_in[
"phi0"] <<
1458 " " << m_mDouble_in[
"phi0"] / m_mConstD_in.at(
"Trg_PI") * 180 << endl;
1459 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]fit2DChi2: " <<
1460 m_mDouble_in[
"fit2DChi2"]
1462 cout <<
"[E" << int(m_mDouble_in[
"eventNumber"]) <<
"][T" << int(m_mDouble_in[
"trackId"]) <<
"]useAxSl: " << int(
1463 m_mVector_in[
"useAxSl"][0]) <<
" " << int(m_mVector_in[
"useAxSl"][1]) <<
" " << int(m_mVector_in[
"useAxSl"][2]) <<
" " << int(
1464 m_mVector_in[
"useAxSl"][3]) << endl;
1467 if (std::isnan(m_mDouble_in[
"rho"]) || std::isnan(m_mDouble_in[
"phi0"])) {
1468 if (m_mBool_in.at(
"fVerbose") == 1) cout <<
"[2Dfit] Exiting because rho or phi0 is nan." << endl;
1476 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]evtTime: " <<
m_mDouble[
"eventTime"] << endl;
1477 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]wirePhi: " <<
m_mVector[
"wirePhi"][0] <<
" " <<
1481 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]LR: " << int(
m_mVector[
"LR"][0]) <<
" " << int(
1485 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]lutLR: " << int(
m_mVector[
"lutLR"][0]) <<
" " << int(
1489 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]useStSl: " << int(
m_mVector[
"useStSl"][0]) <<
" " << int(
1491 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]drift: " <<
m_mVector[
"driftLength"][0] <<
" " <<
1495 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]tdc: " <<
m_mVector[
"tdc"][0] <<
" " <<
1498 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]Phi2D: " <<
m_mVector[
"phi2D"][0] <<
" " <<
1500 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]Phi3D: " <<
m_mVector[
"phi3D"][0] <<
" " <<
1504 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]arcS: " <<
m_mVector[
"arcS"][0] <<
" " <<
1506 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]zerror: " <<
m_mVector[
"zError"][0] <<
" " <<
1508 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]izerror: " <<
m_mVector[
"iZError2"][0] <<
" " <<
1510 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]charge: " << int(
m_mDouble[
"charge"]) << endl;
1511 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]pt: " <<
m_mDouble[
"pt"] << endl;
1512 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]phi0: " <<
m_mDouble[
"phi0"] << endl;
1513 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]z0: " <<
m_mDouble[
"z0"] << endl;
1514 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]cot: " <<
m_mDouble[
"cot"] << endl;
1515 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]chi2: " <<
m_mDouble[
"zChi2"] << endl;
1517 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]mcCharge: " << int(
m_mDouble[
"mcCharge"]) << endl;
1518 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]mcPosZ: " <<
m_mVector[
"mcPosZ"][1] <<
" " <<
1520 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]mcPosZ: " <<
m_mVector[
"mcPosZ"][1] <<
" " <<
1522 cout <<
"[E" << int(
m_mDouble[
"eventNumber"]) <<
"][T" << iTrack <<
"]mcLR: " << int(
m_mVector[
"mcLR"][0]) <<
" " << int(
1550 return string(
"TRGCDCFitter3D 6.0");
1560 stGeometry[
"priorityLayer"] = {10, 22, 34, 46};
1561 stGeometry[
"nWires"] = vector<double> (4);
1562 stGeometry[
"cdcRadius"] = vector<double> (4);
1563 stGeometry[
"zToStraw"] = vector<double> (4);
1564 stGeometry[
"nShift"] = vector<double> (4);
1565 stGeometry[
"angleSt"] = vector<double> (4);
1567 for (
int iSt = 0; iSt < 4; ++iSt) {
1568 stGeometry[
"nWires"][iSt] = cdc.nWiresInLayer(stGeometry[
"priorityLayer"][iSt]) * 2;
1569 stGeometry[
"cdcRadius"][iSt] = cdc.senseWireR(stGeometry[
"priorityLayer"][iSt]);
1570 stGeometry[
"zToStraw"][iSt] = cdc.senseWireBZ(stGeometry[
"priorityLayer"][iSt]);
1571 stGeometry[
"nShift"][iSt] = cdc.nShifts(stGeometry[
"priorityLayer"][iSt]);
1572 stGeometry[
"angleSt"][iSt] = 2 * stGeometry[
"cdcRadius"][iSt] * sin(M_PI * stGeometry[
"nShift"][iSt] /
1573 (stGeometry[
"nWires"][iSt])) /
1574 (cdc.senseWireFZ(stGeometry[
"priorityLayer"][iSt]) - stGeometry[
"zToStraw"][iSt]);
1580 stXts.resize(stPriorityLayer.size(), vector<double> (512));
1582 for (
unsigned iSt = 0; iSt < stPriorityLayer.size(); ++iSt) {
1583 for (
unsigned iTick = 0; iTick < stXts[iSt].size(); ++iTick) {
1584 double t = iTick * 2 * cdc.getTdcBinWidth();
1586 stXts[iSt][iTick] = cdc.getNominalDriftV() * t;
1588 double driftLength_0 = cdc.getDriftLength(t, stPriorityLayer[iSt], 0);
1589 double driftLength_1 = cdc.getDriftLength(t, stPriorityLayer[iSt], 1);
1590 stXts[iSt][iTick] = (driftLength_0 + driftLength_1) / 2;
1600 mConstD[
"Trg_PI"] = M_PI;
1601 mConstV[
"priorityLayer"] = {3, 10, 16, 22, 28, 34, 40, 46, 52};
1602 mConstV[
"rr"] = vector<double> (9);
1603 mConstV[
"nWires"] = vector<double> (9);
1604 mConstV[
"nTSs"] = vector<double> (9);
1605 for (
unsigned iSL = 0; iSL < 9; iSL++) {
1606 unsigned t_layerId = mConstV[
"priorityLayer"][iSL];
1607 mConstV[
"rr"][iSL] = cdc.senseWireR(t_layerId);
1608 mConstV[
"nWires"][iSL] = cdc.nWiresInLayer(t_layerId) * 2;
1609 mConstV[
"nTSs"][iSL] = cdc.nWiresInLayer(t_layerId);
1611 mConstV[
"nTSs2D"] = vector<double> (5);
1612 for (
unsigned iAx = 0; iAx < 5; iAx++) {
1613 mConstV[
"nTSs2D"][iAx] = mConstV[
"nTSs"][2 * iAx];
1615 mConstV[
"zToStraw"] = vector<double> (4);
1616 mConstV[
"zToOppositeStraw"] = vector<double> (4);
1617 mConstV[
"angleSt"] = vector<double> (4);
1618 mConstV[
"nShift"] = vector<double> (4);
1619 for (
int iSt = 0; iSt < 4; iSt++) {
1620 unsigned t_layerId = mConstV[
"priorityLayer"][iSt * 2 + 1];
1621 mConstV[
"zToStraw"][iSt] = cdc.senseWireBZ(t_layerId);
1622 mConstV[
"zToOppositeStraw"][iSt] = cdc.senseWireFZ(t_layerId);
1623 mConstV[
"angleSt"][iSt] = 2 * mConstV[
"rr"][2 * iSt + 1] * sin(mConstD[
"Trg_PI"] * cdc.nShifts(t_layerId) /
1624 (2 * cdc.nWiresInLayer(t_layerId))) / (cdc.senseWireFZ(t_layerId) - cdc.senseWireBZ(t_layerId));
1625 mConstV[
"nShift"][iSt] = cdc.nShifts(t_layerId);
1628 mConstV[
"rr2D"] = vector<double> (5);
1629 mConstV[
"rr3D"] = vector<double> (4);
1630 for (
int iAx = 0; iAx < 5; iAx++) mConstV[
"rr2D"][iAx] = mConstV[
"rr"][iAx * 2];
1631 for (
int iSt = 0; iSt < 4; iSt++) mConstV[
"rr3D"][iSt] = mConstV[
"rr"][iSt * 2 + 1];
1633 mConstV[
"wirePhi2DError"] = vector<double> (5);
1634 mConstV[
"driftPhi2DError"] = vector<double> (5);
1635 mConstV[
"wirePhi2DError"][0] = 0.00085106;
1636 mConstV[
"wirePhi2DError"][1] = 0.00039841;
1637 mConstV[
"wirePhi2DError"][2] = 0.00025806;
1638 mConstV[
"wirePhi2DError"][3] = 0.00019084;
1639 mConstV[
"wirePhi2DError"][4] = 0.0001514;
1640 mConstV[
"driftPhi2DError"][0] = 0.00085106;
1641 mConstV[
"driftPhi2DError"][1] = 0.00039841;
1642 mConstV[
"driftPhi2DError"][2] = 0.00025806;
1643 mConstV[
"driftPhi2DError"][3] = 0.00019084;
1644 mConstV[
"driftPhi2DError"][4] = 0.0001514;
1645 mConstV[
"driftZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
1646 mConstV[
"wireZError"] = vector<double> ({0.7676, 0.9753, 1.029, 1.372});
1650 for (
unsigned iSl = 0; iSl < 9; iSl++) {
1651 string tableName =
"driftLengthTableSL" + to_string(iSl);
1652 unsigned tableSize = 512;
1653 mConstV[tableName] = vector<double> (tableSize);
1654 unsigned t_layer = mConstV[
"priorityLayer"][iSl];
1655 for (
unsigned iTick = 0; iTick < tableSize; iTick++) {
1656 double t_driftTime = iTick * 2 * cdc.getTdcBinWidth();
1657 double avgDriftLength = 0;
1658 if (isXtSimple == 1) {
1659 avgDriftLength = cdc.getNominalDriftV() * t_driftTime;
1661 double driftLength_0 = cdc.getDriftLength(t_driftTime, t_layer, 0);
1662 double driftLength_1 = cdc.getDriftLength(t_driftTime, t_layer, 1);
1663 avgDriftLength = (driftLength_0 + driftLength_1) / 2;
1665 mConstV[tableName][iTick] = avgDriftLength;
1669 mConstD[
"tdcBitSize"] = 9;
1670 mConstD[
"rhoBitSize"] = 11;
1671 mConstD[
"iError2BitSize"] = 8;
1672 mConstD[
"iError2Max"] = 1 / pow(mConstV[
"wireZError"][0], 2);
1675 mConstD[
"phiMax"] = mConstD[
"Trg_PI"];
1676 mConstD[
"phiMin"] = -mConstD[
"Trg_PI"];
1677 mConstD[
"rhoMin"] = 20;
1678 mConstD[
"rhoMax"] = 2500;
1679 mConstD[
"phiBitSize"] = 13;
1680 mConstD[
"driftPhiLUTOutBitSize"] = mConstD[
"phiBitSize"] - 1;
1681 mConstD[
"driftPhiLUTInBitSize"] = mConstD[
"tdcBitSize"];
1682 mConstD[
"acosLUTOutBitSize"] = mConstD[
"phiBitSize"] - 1;
1683 mConstD[
"acosLUTInBitSize"] = mConstD[
"rhoBitSize"];
1684 mConstD[
"zLUTInBitSize"] = mConstD[
"phiBitSize"];
1685 mConstD[
"zLUTOutBitSize"] = 9;
1686 mConstD[
"iDenLUTInBitSize"] = 13;
1687 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.
ROOT::Math::XYZVector getVertex() const
Return production vertex position, shorthand for getProductionVertex().
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.
ROOT::Math::PxPyPzEVector get4Vector() const
Return 4Vector of particle.
int getPDG() const
Return PDG code of particle.
ROOT::Math::XYZVector getMomentum() const
Return momentum.
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.
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 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 findImpactPosition(ROOT::Math::XYZVector *mcPosition, ROOT::Math::PxPyPzEVector *mcMomentum, int charge, ROOT::Math::XYVector &helixCenter, ROOT::Math::XYZVector &impactPosition)
MC calculation functions Calculates the impact position of track.
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.
double atan(double a)
atan for double
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.
TRGCDCFitter3D(const std::string &name, const std::string &rootFitter3DFile, const TRGCDC &, const std::map< std::string, bool > &flags)
Constructor.
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,...
std::string name(void) const
Gets name of class.
float priorityTime(void) const
return priority time in TSHit.
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.
const HepGeom::Point3D< double > ORIGIN
Origin 3D point.
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.