CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
trklet::FitTrack Class Reference

#include <FitTrack.h>

Inheritance diagram for trklet::FitTrack:
trklet::ProcessBase

Public Member Functions

void addInput (MemoryBase *memory, std::string input) override
 
void addOutput (MemoryBase *memory, std::string output) override
 
void execute (unsigned int iSector)
 
 FitTrack (std::string name, Settings const &settings, Globals *global)
 
std::vector< Tracklet * > orderedMatches (std::vector< FullMatchMemory *> &fullmatch)
 
void trackFitChisq (Tracklet *tracklet, std::vector< const Stub *> &, std::vector< std::pair< int, int >> &)
 
void trackFitFake (Tracklet *tracklet, std::vector< const Stub *> &, std::vector< std::pair< int, int >> &)
 
void trackFitKF (Tracklet *tracklet, std::vector< const Stub *> &trackstublist, std::vector< std::pair< int, int >> &stubidslist)
 
 ~FitTrack () override=default
 
- Public Member Functions inherited from trklet::ProcessBase
unsigned int getISeed (const std::string &name)
 
std::string const & getName () const
 
void initLayerDisk (unsigned int pos, int &layer, int &disk)
 
void initLayerDisk (unsigned int pos, int &layer, int &disk, int &layerdisk)
 
unsigned int initLayerDisk (unsigned int pos)
 
void initLayerDisksandISeed (unsigned int &layerdisk1, unsigned int &layerdisk2, unsigned int &iSeed)
 
unsigned int nbits (unsigned int power)
 
 ProcessBase (std::string name, Settings const &settings, Globals *global)
 
virtual ~ProcessBase ()=default
 

Private Attributes

std::vector< FullMatchMemory * > fullmatch1_
 
std::vector< FullMatchMemory * > fullmatch2_
 
std::vector< FullMatchMemory * > fullmatch3_
 
std::vector< FullMatchMemory * > fullmatch4_
 
unsigned int iSector_
 
std::vector< TrackletParametersMemory * > seedtracklet_
 
TrackFitMemorytrackfit_
 

Additional Inherited Members

- Protected Attributes inherited from trklet::ProcessBase
Globalsglobals_
 
std::string name_
 
Settings const & settings_
 

Detailed Description

Definition at line 18 of file FitTrack.h.

Constructor & Destructor Documentation

◆ FitTrack()

FitTrack::FitTrack ( std::string  name,
Settings const &  settings,
Globals global 
)

Definition at line 14 of file FitTrack.cc.

15  : ProcessBase(name, settings, global), trackfit_(nullptr) {}
ProcessBase(std::string name, Settings const &settings, Globals *global)
Definition: ProcessBase.cc:14
TrackFitMemory * trackfit_
Definition: FitTrack.h:52

◆ ~FitTrack()

trklet::FitTrack::~FitTrack ( )
overridedefault

Member Function Documentation

◆ addInput()

void FitTrack::addInput ( MemoryBase memory,
std::string  input 
)
overridevirtual

Implements trklet::ProcessBase.

Definition at line 32 of file FitTrack.cc.

References cms::cuda::assert(), Exception, fullmatch1_, fullmatch2_, fullmatch3_, fullmatch4_, input, mps_setup::memory, trklet::ProcessBase::name_, seedtracklet_, trklet::ProcessBase::settings_, createJobs::tmp, and trklet::Settings::writetrace().

32  {
33  if (settings_.writetrace()) {
34  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
35  << input;
36  }
37  if (input.substr(0, 4) == "tpar") {
38  auto* tmp = dynamic_cast<TrackletParametersMemory*>(memory);
39  assert(tmp != nullptr);
40  seedtracklet_.push_back(tmp);
41  return;
42  }
43  if (input.substr(0, 10) == "fullmatch1") {
44  auto* tmp = dynamic_cast<FullMatchMemory*>(memory);
45  assert(tmp != nullptr);
46  fullmatch1_.push_back(tmp);
47  return;
48  }
49  if (input.substr(0, 10) == "fullmatch2") {
50  auto* tmp = dynamic_cast<FullMatchMemory*>(memory);
51  assert(tmp != nullptr);
52  fullmatch2_.push_back(tmp);
53  return;
54  }
55  if (input.substr(0, 10) == "fullmatch3") {
56  auto* tmp = dynamic_cast<FullMatchMemory*>(memory);
57  assert(tmp != nullptr);
58  fullmatch3_.push_back(tmp);
59  return;
60  }
61  if (input.substr(0, 10) == "fullmatch4") {
62  auto* tmp = dynamic_cast<FullMatchMemory*>(memory);
63  assert(tmp != nullptr);
64  fullmatch4_.push_back(tmp);
65  return;
66  }
67 
68  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " input = " << input << " not found";
69 }
Log< level::Info, true > LogVerbatim
std::string name_
Definition: ProcessBase.h:38
std::vector< TrackletParametersMemory * > seedtracklet_
Definition: FitTrack.h:44
Settings const & settings_
Definition: ProcessBase.h:40
bool writetrace() const
Definition: Settings.h:183
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:47
std::vector< FullMatchMemory * > fullmatch4_
Definition: FitTrack.h:48
std::vector< FullMatchMemory * > fullmatch1_
Definition: FitTrack.h:45
std::vector< FullMatchMemory * > fullmatch2_
Definition: FitTrack.h:46
tmp
align.sh
Definition: createJobs.py:716
std::vector< FullMatchMemory * > fullmatch3_
Definition: FitTrack.h:47

◆ addOutput()

void FitTrack::addOutput ( MemoryBase memory,
std::string  output 
)
overridevirtual

Implements trklet::ProcessBase.

Definition at line 17 of file FitTrack.cc.

References cms::cuda::assert(), Exception, mps_setup::memory, trklet::ProcessBase::name_, convertSQLitetoXML_cfg::output, trklet::ProcessBase::settings_, createJobs::tmp, trackfit_, and trklet::Settings::writetrace().

17  {
18  if (settings_.writetrace()) {
19  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
20  << output;
21  }
22  if (output == "trackout") {
23  TrackFitMemory* tmp = dynamic_cast<TrackFitMemory*>(memory);
24  assert(tmp != nullptr);
25  trackfit_ = tmp;
26  return;
27  }
28 
29  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " addOutput, output = " << output << " not known";
30 }
Log< level::Info, true > LogVerbatim
std::string name_
Definition: ProcessBase.h:38
Settings const & settings_
Definition: ProcessBase.h:40
bool writetrace() const
Definition: Settings.h:183
assert(be >=bs)
TrackFitMemory * trackfit_
Definition: FitTrack.h:52
tmp
align.sh
Definition: createJobs.py:716

◆ execute()

void FitTrack::execute ( unsigned int  iSector)

Definition at line 870 of file FitTrack.cc.

References trklet::TrackFitMemory::addStubidsList(), trklet::TrackFitMemory::addStubList(), trklet::TrackFitMemory::addTrack(), cms::cuda::assert(), trklet::Settings::debugTracklet(), trklet::Settings::fakefit(), trklet::Tracklet::fit(), groupFilesInBlocks::fout, fullmatch1_, fullmatch2_, fullmatch3_, fullmatch4_, trklet::Tracklet::getISeed(), trklet::ProcessBase::getName(), trklet::ProcessBase::globals_, mps_fire::i, createfilelist::int, iSector_, match(), trklet::N_SEED_PROMPT, trklet::ProcessBase::name_, trklet::TrackFitMemory::nTracks(), trklet::Globals::ofstream(), orderedMatches(), trklet::Settings::removalType(), trklet::ProcessBase::settings_, trklet::Tracklet::setTrackIndex(), trklet::Tracklet::t(), trklet::Tracklet::TCID(), trackfit_, trackFitChisq(), trackFitFake(), trackFitKF(), and trklet::Settings::writeMonitorData().

870  {
871  // merge
872  const std::vector<Tracklet*>& matches1 = orderedMatches(fullmatch1_);
873  const std::vector<Tracklet*>& matches2 = orderedMatches(fullmatch2_);
874  const std::vector<Tracklet*>& matches3 = orderedMatches(fullmatch3_);
875  const std::vector<Tracklet*>& matches4 = orderedMatches(fullmatch4_);
876 
877  iSector_ = iSector;
878 
879  if (settings_.debugTracklet() && (matches1.size() + matches2.size() + matches3.size() + matches4.size()) > 0) {
880  for (auto& imatch : fullmatch1_) {
881  edm::LogVerbatim("Tracklet") << imatch->getName() << " " << imatch->nMatches();
882  }
883  edm::LogVerbatim("Tracklet") << getName() << " matches : " << matches1.size() << " " << matches2.size() << " "
884  << matches3.size() << " " << matches4.size();
885  }
886 
887  unsigned int indexArray[4];
888  for (unsigned int i = 0; i < 4; i++) {
889  indexArray[i] = 0;
890  }
891 
892  int countAll = 0;
893  int countFit = 0;
894 
895  Tracklet* bestTracklet = nullptr;
896  do {
897  countAll++;
898  bestTracklet = nullptr;
899 
900  if (indexArray[0] < matches1.size()) {
901  if (bestTracklet == nullptr) {
902  bestTracklet = matches1[indexArray[0]];
903  } else {
904  if (matches1[indexArray[0]]->TCID() < bestTracklet->TCID())
905  bestTracklet = matches1[indexArray[0]];
906  }
907  }
908 
909  if (indexArray[1] < matches2.size()) {
910  if (bestTracklet == nullptr) {
911  bestTracklet = matches2[indexArray[1]];
912  } else {
913  if (matches2[indexArray[1]]->TCID() < bestTracklet->TCID())
914  bestTracklet = matches2[indexArray[1]];
915  }
916  }
917 
918  if (indexArray[2] < matches3.size()) {
919  if (bestTracklet == nullptr) {
920  bestTracklet = matches3[indexArray[2]];
921  } else {
922  if (matches3[indexArray[2]]->TCID() < bestTracklet->TCID())
923  bestTracklet = matches3[indexArray[2]];
924  }
925  }
926 
927  if (indexArray[3] < matches4.size()) {
928  if (bestTracklet == nullptr) {
929  bestTracklet = matches4[indexArray[3]];
930  } else {
931  if (matches4[indexArray[3]]->TCID() < bestTracklet->TCID())
932  bestTracklet = matches4[indexArray[3]];
933  }
934  }
935 
936  if (bestTracklet == nullptr)
937  break;
938 
939  //Counts total number of matched hits
940  int nMatches = 0;
941 
942  //Counts unique hits in each layer
943  int nMatchesUniq = 0;
944  bool match = false;
945 
946  while (indexArray[0] < matches1.size() && matches1[indexArray[0]] == bestTracklet) {
947  indexArray[0]++;
948  nMatches++;
949  match = true;
950  }
951 
952  if (match)
953  nMatchesUniq++;
954  match = false;
955 
956  while (indexArray[1] < matches2.size() && matches2[indexArray[1]] == bestTracklet) {
957  indexArray[1]++;
958  nMatches++;
959  match = true;
960  }
961 
962  if (match)
963  nMatchesUniq++;
964  match = false;
965 
966  while (indexArray[2] < matches3.size() && matches3[indexArray[2]] == bestTracklet) {
967  indexArray[2]++;
968  nMatches++;
969  match = true;
970  }
971 
972  if (match)
973  nMatchesUniq++;
974  match = false;
975 
976  while (indexArray[3] < matches4.size() && matches4[indexArray[3]] == bestTracklet) {
977  indexArray[3]++;
978  nMatches++;
979  match = true;
980  }
981 
982  if (match)
983  nMatchesUniq++;
984 
985  if (settings_.debugTracklet()) {
986  edm::LogVerbatim("Tracklet") << getName() << " : nMatches = " << nMatches << " nMatchesUniq = " << nMatchesUniq
987  << " " << asinh(bestTracklet->t());
988  }
989 
990  std::vector<const Stub*> trackstublist;
991  std::vector<std::pair<int, int>> stubidslist;
992  if ((bestTracklet->getISeed() >= (int)N_SEED_PROMPT && nMatchesUniq >= 1) ||
993  nMatchesUniq >= 2) { //For seeds index >=8 (triplet seeds), there are three stubs associated from start.
994  countFit++;
995 
996 #ifdef USEHYBRID
997  trackFitKF(bestTracklet, trackstublist, stubidslist);
998 #else
999  if (settings_.fakefit()) {
1000  trackFitFake(bestTracklet, trackstublist, stubidslist);
1001  } else {
1002  trackFitChisq(bestTracklet, trackstublist, stubidslist);
1003  }
1004 #endif
1005 
1006  if (settings_.removalType() == "merge") {
1007  trackfit_->addStubList(trackstublist);
1008  trackfit_->addStubidsList(stubidslist);
1009  bestTracklet->setTrackIndex(trackfit_->nTracks());
1010  trackfit_->addTrack(bestTracklet);
1011  } else if (bestTracklet->fit()) {
1012  assert(trackfit_ != nullptr);
1013  if (settings_.writeMonitorData("Seeds")) {
1014  ofstream fout("seeds.txt", ofstream::app);
1015  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_"
1016  << " " << bestTracklet->getISeed() << endl;
1017  fout.close();
1018  }
1019  bestTracklet->setTrackIndex(trackfit_->nTracks());
1020  trackfit_->addTrack(bestTracklet);
1021  }
1022  }
1023 
1024  } while (bestTracklet != nullptr);
1025 
1026  if (settings_.writeMonitorData("FT")) {
1027  globals_->ofstream("fittrack.txt") << getName() << " " << countAll << " " << countFit << endl;
1028  }
1029 }
Log< level::Info, true > LogVerbatim
double t() const
Definition: Tracklet.h:123
std::string name_
Definition: ProcessBase.h:38
void addTrack(Tracklet *tracklet)
Settings const & settings_
Definition: ProcessBase.h:40
Globals * globals_
Definition: ProcessBase.h:41
void trackFitKF(Tracklet *tracklet, std::vector< const Stub *> &trackstublist, std::vector< std::pair< int, int >> &stubidslist)
void trackFitChisq(Tracklet *tracklet, std::vector< const Stub *> &, std::vector< std::pair< int, int >> &)
Definition: FitTrack.cc:138
void setTrackIndex(int index)
Definition: Tracklet.cc:810
assert(be >=bs)
int TCID() const
Definition: Tracklet.h:212
void addStubList(std::vector< const Stub *> stublist)
TrackFitMemory * trackfit_
Definition: FitTrack.h:52
std::vector< Tracklet * > orderedMatches(std::vector< FullMatchMemory *> &fullmatch)
Definition: FitTrack.cc:816
bool fit() const
Definition: Tracklet.h:195
std::vector< FullMatchMemory * > fullmatch4_
Definition: FitTrack.h:48
unsigned int nTracks() const
std::string removalType() const
Definition: Settings.h:238
bool fakefit() const
Definition: Settings.h:242
unsigned int iSector_
Definition: FitTrack.h:50
bool writeMonitorData(std::string module) const
Definition: Settings.h:109
std::vector< FullMatchMemory * > fullmatch1_
Definition: FitTrack.h:45
bool debugTracklet() const
Definition: Settings.h:182
std::vector< FullMatchMemory * > fullmatch2_
Definition: FitTrack.h:46
int getISeed() const
Definition: Tracklet.cc:798
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
void addStubidsList(std::vector< std::pair< int, int >> stubidslist)
void trackFitFake(Tracklet *tracklet, std::vector< const Stub *> &, std::vector< std::pair< int, int >> &)
Definition: FitTrack.cc:790
std::string const & getName() const
Definition: ProcessBase.h:22
std::vector< FullMatchMemory * > fullmatch3_
Definition: FitTrack.h:47
constexpr unsigned int N_SEED_PROMPT
Definition: Settings.h:25

◆ orderedMatches()

std::vector< Tracklet * > FitTrack::orderedMatches ( std::vector< FullMatchMemory *> &  fullmatch)

Definition at line 816 of file FitTrack.cc.

References cms::cuda::assert(), trklet::Settings::debugTracklet(), trklet::ProcessBase::getName(), mps_fire::i, dqmiolumiharvest::j, trklet::ProcessBase::settings_, and createJobs::tmp.

Referenced by execute().

816  {
817  std::vector<Tracklet*> tmp;
818 
819  std::vector<unsigned int> indexArray;
820  for (auto& imatch : fullmatch) {
821  //check that we have correct order
822  if (imatch->nMatches() > 1) {
823  for (unsigned int j = 0; j < imatch->nMatches() - 1; j++) {
824  assert(imatch->getTracklet(j)->TCID() <= imatch->getTracklet(j + 1)->TCID());
825  }
826  }
827 
828  if (settings_.debugTracklet() && imatch->nMatches() != 0) {
829  edm::LogVerbatim("Tracklet") << "orderedMatches: " << imatch->getName() << " " << imatch->nMatches();
830  }
831 
832  indexArray.push_back(0);
833  }
834 
835  int bestIndex = -1;
836  do {
837  int bestTCID = -1;
838  bestIndex = -1;
839  for (unsigned int i = 0; i < fullmatch.size(); i++) {
840  if (indexArray[i] >= fullmatch[i]->nMatches()) {
841  //skip as we were at the end
842  continue;
843  }
844  int TCID = fullmatch[i]->getTracklet(indexArray[i])->TCID();
845  if (TCID < bestTCID || bestTCID < 0) {
846  bestTCID = TCID;
847  bestIndex = i;
848  }
849  }
850  if (bestIndex != -1) {
851  tmp.push_back(fullmatch[bestIndex]->getTracklet(indexArray[bestIndex]));
852  indexArray[bestIndex]++;
853  }
854  } while (bestIndex != -1);
855 
856  for (unsigned int i = 0; i < tmp.size(); i++) {
857  if (i > 0) {
858  //This allows for equal TCIDs. This means that we can e.g. have a track seeded in L1L2 that projects to both L3 and D4.
859  //The algorithm will pick up the first hit and drop the second.
860  if (tmp[i - 1]->TCID() > tmp[i]->TCID()) {
861  edm::LogVerbatim("Tracklet") << "Wrong TCID ordering in " << getName() << " : " << tmp[i - 1]->TCID() << " "
862  << tmp[i]->TCID();
863  }
864  }
865  }
866 
867  return tmp;
868 }
Log< level::Info, true > LogVerbatim
Settings const & settings_
Definition: ProcessBase.h:40
assert(be >=bs)
bool debugTracklet() const
Definition: Settings.h:182
tmp
align.sh
Definition: createJobs.py:716
std::string const & getName() const
Definition: ProcessBase.h:22

◆ trackFitChisq()

void FitTrack::trackFitChisq ( Tracklet tracklet,
std::vector< const Stub *> &  ,
std::vector< std::pair< int, int >> &   
)

Definition at line 138 of file FitTrack.cc.

References funct::abs(), trklet::Stub::alpha(), trklet::L1TStub::alpha(), alpha, trklet::Settings::alphaBitsTable(), cms::cuda::assert(), trklet::TrackDerTable::calculateDerivatives(), trklet::Settings::chisqphifactbits(), trklet::Settings::chisqzfactbits(), ztail::d, d1, trklet::Settings::debugTracklet(), dumpMFGeometry_cfg::delta, trklet::Tracklet::disk(), alignBH_cfg::disks, flavorHistoryFilter_cfi::dr, dt, MillePedeFileConverter_cfg::e, trklet::Settings::exactderivatives(), trklet::Settings::exactderivativesforfloating(), trklet::TrackDer::fill(), trklet::TrackDerTable::fillTable(), trklet::Settings::fitPatternFile(), trklet::Settings::fitphi0bitshift(), trklet::Settings::fitrinvbitshift(), trklet::Settings::fittbitshift(), trklet::Settings::fitz0bitshift(), trklet::Tracklet::fpgaphi0(), trklet::Residual::fpgaphiresid(), trklet::Tracklet::fpgarinv(), trklet::Residual::fpgarzresid(), trklet::Tracklet::fpgat(), trklet::Tracklet::fpgaz0(), trklet::TrackDerTable::getDerivatives(), trklet::TrackDerTable::getEntries(), trklet::ProcessBase::getName(), trklet::ProcessBase::globals_, mps_fire::i, cuy::ii, trklet::Tracklet::innerFPGAStub(), createfilelist::int, trklet::Tracklet::isBarrel(), trklet::Tracklet::isDisk(), trklet::Tracklet::isOverlap(), trklet::L1TStub::isPSmodule(), trklet::TrackDer::itdzcorr(), trklet::TrackDer::iz0dzcorr(), dqmiolumiharvest::j, dqmdumpme::k, runTheMatrix::keep, kfactor, trklet::Settings::kphi(), trklet::Settings::kr(), trklet::Settings::krinvpars(), trklet::Settings::ktpars(), MainPageGenerator::l, trklet::Stub::l1tstub(), trklet::Tracklet::layer(), hgcalTopologyTester_cfi::layers, trklet::Tracklet::match(), VarParsing::mult, dqmiodumpmetadata::n, trklet::N_DISK, trklet::N_FITPARAM, trklet::N_FITSTUB, trklet::N_LAYER, trklet::FPGAWord::nbits(), nlayers, trklet::Settings::nrinvBitsTable(), trklet::Globals::ofstream(), trklet::Tracklet::outerFPGAStub(), trklet::Tracklet::phi0(), trklet::Tracklet::phi0approx(), trklet::Settings::phicritmax(), trklet::Settings::phicritmin(), trklet::Residual::phiresid(), trklet::Residual::phiresidapprox(), trklet::L1TStub::r(), alignCSCRings::r, trklet::Settings::rcorrbits(), trklet::Settings::rcrit(), trklet::TrackDerTable::readPatternFile(), trklet::Tracklet::resid(), trklet::rinv(), trklet::Tracklet::rinv(), trklet::Tracklet::rinvapprox(), trklet::Settings::rinvmax(), trklet::Settings::rmean(), trklet::Settings::rPS2S(), trklet::Residual::rzresid(), trklet::Residual::rzresidapprox(), trklet::FPGAWord::set(), trklet::Tracklet::setFitPars(), trklet::ProcessBase::settings_, Validation_hcalonly_cfi::sign, trklet::FPGAWord::str(), AlCaHLTBitMon_QueryRunRegistry::string, trklet::Settings::stripPitch(), trklet::Residual::stubptr(), trklet::Tracklet::t(), submitPVValidationJobs::t, trklet::Tracklet::tapprox(), trklet::TrackDer::tdzcorr(), createJobs::tmp, callgraph::tmpl, cond::impl::to_string(), trklet::TrackDerTable::tpar(), trklet::Globals::trackDerTable(), parallelization::uint, trklet::FPGAWord::value(), trklet::Settings::warnNoDer(), trklet::Settings::writeMonitorData(), trklet::Tracklet::z0(), trklet::Tracklet::z0approx(), trklet::TrackDer::z0dzcorr(), and trklet::Settings::zmean().

Referenced by execute().

138  {
139  if (globals_->trackDerTable() == nullptr) {
140  TrackDerTable* derTablePtr = new TrackDerTable(settings_);
141 
142  derTablePtr->readPatternFile(settings_.fitPatternFile());
143  derTablePtr->fillTable();
144  if (settings_.debugTracklet()) {
145  edm::LogVerbatim("Tracklet") << "Number of entries in derivative table: " << derTablePtr->getEntries();
146  }
147  assert(derTablePtr->getEntries() != 0);
148 
149  globals_->trackDerTable() = derTablePtr;
150  }
151 
152  const TrackDerTable& derTable = *globals_->trackDerTable();
153 
154  //First step is to build list of layers and disks.
155  int layers[N_LAYER];
156  double r[N_LAYER];
157  unsigned int nlayers = 0; // layers with found stub-projections
158  int disks[N_DISK];
159  double z[N_DISK];
160  unsigned int ndisks = 0; // disks with found stub-projections
161 
162  // residuals for each stub
163  double phiresid[N_FITSTUB];
164  double zresid[N_FITSTUB];
165  double phiresidexact[N_FITSTUB];
166  double zresidexact[N_FITSTUB];
167  int iphiresid[N_FITSTUB];
168  int izresid[N_FITSTUB];
169  double alpha[N_FITSTUB];
170 
171  for (unsigned int i = 0; i < N_FITSTUB; i++) {
172  iphiresid[i] = 0;
173  izresid[i] = 0;
174  alpha[i] = 0.0;
175 
176  phiresid[i] = 0.0;
177  zresid[i] = 0.0;
178  phiresidexact[i] = 0.0;
179  zresidexact[i] = 0.0;
180  }
181 
182  std::bitset<N_LAYER> lmatches; //layer matches
183  std::bitset<N_DISK * 2> dmatches; //disk matches (2 per disk to separate 2S from PS)
184 
185  int mult = 1;
186 
187  unsigned int layermask = 0;
188  unsigned int diskmask = 0;
189  unsigned int alphaindex = 0;
190  unsigned int power = 1;
191 
192  double t = tracklet->t();
193  double rinv = tracklet->rinv();
194 
195  if (tracklet->isBarrel()) {
196  for (unsigned int l = 1; l <= N_LAYER; l++) {
197  if (l == (unsigned int)tracklet->layer() || l == (unsigned int)tracklet->layer() + 1) {
198  lmatches.set(N_LAYER - l);
199  layermask |= (1 << (N_LAYER - l));
200  layers[nlayers++] = l;
201  continue;
202  }
203  if (tracklet->match(l - 1)) {
204  const Residual& resid = tracklet->resid(l - 1);
205  lmatches.set(N_LAYER - l);
206  layermask |= (1 << (N_LAYER - l));
207  phiresid[nlayers] = resid.phiresidapprox();
208  zresid[nlayers] = resid.rzresidapprox();
209  phiresidexact[nlayers] = resid.phiresid();
210  zresidexact[nlayers] = resid.rzresid();
211  iphiresid[nlayers] = resid.fpgaphiresid().value();
212  izresid[nlayers] = resid.fpgarzresid().value();
213 
214  layers[nlayers++] = l;
215  }
216  }
217 
218  for (unsigned int d = 1; d <= N_DISK; d++) {
219  if (layermask & (1 << (d - 1)))
220  continue;
221 
222  if (mult == 1 << (3 * settings_.alphaBitsTable()))
223  continue;
224 
225  if (ndisks + nlayers >= N_FITSTUB)
226  continue;
227  if (tracklet->match(N_LAYER + d - 1)) {
228  const Residual& resid = tracklet->resid(N_LAYER + d - 1);
229  double pitch = settings_.stripPitch(resid.stubptr()->l1tstub()->isPSmodule());
230  if (std::abs(resid.stubptr()->l1tstub()->alpha(pitch)) < 1e-20) {
231  dmatches.set(2 * d - 1);
232  diskmask |= (1 << (2 * (N_DISK - d) + 1));
233  } else {
234  int ialpha = resid.stubptr()->alpha().value();
235  int nalpha = resid.stubptr()->alpha().nbits();
236  nalpha = nalpha - settings_.alphaBitsTable();
237  ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha);
238 
239  alphaindex += ialpha * power;
240  power = power << settings_.alphaBitsTable();
241  dmatches.set(2 * (N_DISK - d));
242  diskmask |= (1 << (2 * (N_DISK - d)));
244  }
245  alpha[ndisks] = resid.stubptr()->l1tstub()->alpha(pitch);
246  phiresid[nlayers + ndisks] = resid.phiresidapprox();
247  zresid[nlayers + ndisks] = resid.rzresidapprox();
248  phiresidexact[nlayers + ndisks] = resid.phiresid();
249  zresidexact[nlayers + ndisks] = resid.rzresid();
250  iphiresid[nlayers + ndisks] = resid.fpgaphiresid().value();
251  izresid[nlayers + ndisks] = resid.fpgarzresid().value();
252 
253  disks[ndisks++] = d;
254  }
255  }
256 
257  if (settings_.writeMonitorData("HitPattern")) {
258  if (mult <= 1 << (3 * settings_.alphaBitsTable())) {
259  globals_->ofstream("hitpattern.txt")
260  << lmatches.to_string() << " " << dmatches.to_string() << " " << mult << endl;
261  }
262  }
263  }
264 
265  if (tracklet->isDisk()) {
266  for (unsigned int l = 1; l <= 2; l++) {
267  if (tracklet->match(l - 1)) {
268  lmatches.set(N_LAYER - l);
269 
270  layermask |= (1 << (N_LAYER - l));
271  const Residual& resid = tracklet->resid(l - 1);
272  phiresid[nlayers] = resid.phiresidapprox();
273  zresid[nlayers] = resid.rzresidapprox();
274  phiresidexact[nlayers] = resid.phiresid();
275  zresidexact[nlayers] = resid.rzresid();
276  iphiresid[nlayers] = resid.fpgaphiresid().value();
277  izresid[nlayers] = resid.fpgarzresid().value();
278 
279  layers[nlayers++] = l;
280  }
281  }
282 
283  for (int d1 = 1; d1 <= N_DISK; d1++) {
284  int d = d1;
285 
286  // skip F/B5 if there's already a L2 match
287  if (d == 5 and layermask & (1 << 4))
288  continue;
289 
290  if (tracklet->fpgat().value() < 0.0)
291  d = -d1;
292  if (d1 == abs(tracklet->disk()) || d1 == abs(tracklet->disk()) + 1) {
293  dmatches.set(2 * d1 - 1);
294  diskmask |= (1 << (2 * (N_DISK - d1) + 1));
295  alpha[ndisks] = 0.0;
296  disks[ndisks++] = d;
297  continue;
298  }
299 
300  if (ndisks + nlayers >= N_FITSTUB)
301  continue;
302  if (tracklet->match(N_LAYER + abs(d) - 1)) {
303  const Residual& resid = tracklet->resid(N_LAYER + abs(d) - 1);
304  double pitch = settings_.stripPitch(resid.stubptr()->l1tstub()->isPSmodule());
305  if (std::abs(resid.stubptr()->l1tstub()->alpha(pitch)) < 1e-20) {
306  dmatches.set(2 * d1 - 1);
307  diskmask |= (1 << (2 * (N_DISK - d1) + 1));
308  } else {
309  int ialpha = resid.stubptr()->alpha().value();
310  int nalpha = resid.stubptr()->alpha().nbits();
311  nalpha = nalpha - settings_.alphaBitsTable();
312  ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha);
313 
314  alphaindex += ialpha * power;
315  power = power << settings_.alphaBitsTable();
316  dmatches.set(2 * (N_DISK - d1));
317  diskmask |= (1 << (2 * (N_DISK - d1)));
319  }
320 
321  alpha[ndisks] = resid.stubptr()->l1tstub()->alpha(pitch);
322  assert(std::abs(resid.phiresidapprox()) < 0.2);
323  phiresid[nlayers + ndisks] = resid.phiresidapprox();
324  zresid[nlayers + ndisks] = resid.rzresidapprox();
325  assert(std::abs(resid.phiresid()) < 0.2);
326  phiresidexact[nlayers + ndisks] = resid.phiresid();
327  zresidexact[nlayers + ndisks] = resid.rzresid();
328  iphiresid[nlayers + ndisks] = resid.fpgaphiresid().value();
329  izresid[nlayers + ndisks] = resid.fpgarzresid().value();
330 
331  disks[ndisks++] = d;
332  }
333  }
334  }
335 
336  if (tracklet->isOverlap()) {
337  for (unsigned int l = 1; l <= 2; l++) {
338  if (l == (unsigned int)tracklet->layer()) {
339  lmatches.set(N_LAYER - l);
340  layermask |= (1 << (N_LAYER - l));
341  layers[nlayers++] = l;
342  continue;
343  }
344  if (tracklet->match(l - 1)) {
345  lmatches.set(N_LAYER - l);
346  layermask |= (1 << (N_LAYER - l));
347  const Residual& resid = tracklet->resid(l - 1);
348  assert(std::abs(resid.phiresidapprox()) < 0.2);
349  phiresid[nlayers] = resid.phiresidapprox();
350  zresid[nlayers] = resid.rzresidapprox();
351  assert(std::abs(resid.phiresid()) < 0.2);
352  phiresidexact[nlayers] = resid.phiresid();
353  zresidexact[nlayers] = resid.rzresid();
354  iphiresid[nlayers] = resid.fpgaphiresid().value();
355  izresid[nlayers] = resid.fpgarzresid().value();
356 
357  layers[nlayers++] = l;
358  }
359  }
360 
361  for (unsigned int d1 = 1; d1 <= N_DISK; d1++) {
362  if (mult == 1 << (3 * settings_.alphaBitsTable()))
363  continue;
364  int d = d1;
365  if (tracklet->fpgat().value() < 0.0)
366  d = -d1;
367  if (d == tracklet->disk()) { //All seeds in PS modules
368  disks[ndisks] = tracklet->disk();
369  dmatches.set(2 * d1 - 1);
370  diskmask |= (1 << (2 * (N_DISK - d1) + 1));
371  ndisks++;
372  continue;
373  }
374 
375  if (ndisks + nlayers >= N_FITSTUB)
376  continue;
377  if (tracklet->match(N_LAYER + abs(d) - 1)) {
378  const Residual& resid = tracklet->resid(N_LAYER + abs(d) - 1);
379  double pitch = settings_.stripPitch(resid.stubptr()->l1tstub()->isPSmodule());
380  if (std::abs(resid.stubptr()->l1tstub()->alpha(pitch)) < 1e-20) {
381  dmatches.set(2 * (N_DISK - d1));
382  diskmask |= (1 << (2 * (N_DISK - d1) + 1));
383  FPGAWord tmp;
384  tmp.set(diskmask, 10);
385  } else {
386  int ialpha = resid.stubptr()->alpha().value();
387  int nalpha = resid.stubptr()->alpha().nbits();
388  nalpha = nalpha - settings_.alphaBitsTable();
389  ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha);
390 
391  alphaindex += ialpha * power;
392  power = power << settings_.alphaBitsTable();
393  dmatches.set(2 * (N_DISK - d1));
394  diskmask |= (1 << (2 * (N_DISK - d1)));
395  FPGAWord tmp;
396  tmp.set(diskmask, 10);
398  }
399 
400  alpha[ndisks] = resid.stubptr()->l1tstub()->alpha(pitch);
401  assert(std::abs(resid.phiresidapprox()) < 0.2);
402  phiresid[nlayers + ndisks] = resid.phiresidapprox();
403  zresid[nlayers + ndisks] = resid.rzresidapprox();
404  assert(std::abs(resid.phiresid()) < 0.2);
405  phiresidexact[nlayers + ndisks] = resid.phiresid();
406  zresidexact[nlayers + ndisks] = resid.rzresid();
407  iphiresid[nlayers + ndisks] = resid.fpgaphiresid().value();
408  izresid[nlayers + ndisks] = resid.fpgarzresid().value();
409 
410  disks[ndisks++] = d;
411  }
412  }
413  }
414 
415  int rinvindex =
416  (1 << (settings_.nrinvBitsTable() - 1)) * rinv / settings_.rinvmax() + (1 << (settings_.nrinvBitsTable() - 1));
417  if (rinvindex < 0)
418  rinvindex = 0;
419  if (rinvindex >= (1 << settings_.nrinvBitsTable()))
420  rinvindex = (1 << settings_.nrinvBitsTable()) - 1;
421 
422  const TrackDer* derivatives = derTable.getDerivatives(layermask, diskmask, alphaindex, rinvindex);
423 
424  if (derivatives == nullptr) {
425  if (settings_.warnNoDer()) {
426  FPGAWord tmpl, tmpd;
427  tmpl.set(layermask, 6);
428  tmpd.set(diskmask, 10);
429  edm::LogVerbatim("Tracklet") << "No derivative for layermask, diskmask : " << layermask << " " << tmpl.str()
430  << " " << diskmask << " " << tmpd.str() << " eta = " << asinh(t);
431  }
432  return;
433  }
434 
435  double ttabi = TrackDerTable::tpar(settings_, diskmask, layermask);
436  if (t < 0.0)
437  ttabi = -ttabi;
438  double ttab = ttabi;
439 
440  if (settings_.debugTracklet()) {
441  edm::LogVerbatim("Tracklet") << "Doing trackfit in " << getName();
442  }
443 
444  int sign = 1;
445  if (t < 0.0)
446  sign = -1;
447 
448  double rstub[6];
449 
450  double realrstub[3];
451  realrstub[0] = -1.0;
452  realrstub[1] = -1.0;
453  realrstub[2] = -1.0;
454 
455  for (unsigned i = 0; i < nlayers; i++) {
456  r[i] = settings_.rmean(layers[i] - 1);
457  if (layers[i] == tracklet->layer()) {
458  if (tracklet->isOverlap()) {
459  realrstub[i] = tracklet->outerFPGAStub()->l1tstub()->r();
460  } else {
461  realrstub[i] = tracklet->innerFPGAStub()->l1tstub()->r();
462  }
463  }
464  if (layers[i] == tracklet->layer() + 1) {
465  realrstub[i] = tracklet->outerFPGAStub()->l1tstub()->r();
466  }
467  if (tracklet->match(layers[i] - 1) && layers[i] < 4) {
468  const Stub* stubptr = tracklet->resid(layers[i] - 1).stubptr();
469  realrstub[i] = stubptr->l1tstub()->r();
470  assert(std::abs(realrstub[i] - r[i]) < 5.0);
471  }
472  rstub[i] = r[i];
473  }
474  for (unsigned i = 0; i < ndisks; i++) {
475  z[i] = sign * settings_.zmean(abs(disks[i]) - 1);
476  rstub[i + nlayers] = z[i] / ttabi;
477  }
478 
479  double D[N_FITPARAM][N_FITSTUB * 2];
480  double MinvDt[N_FITPARAM][N_FITSTUB * 2];
481  int iD[N_FITPARAM][N_FITSTUB * 2];
482  int iMinvDt[N_FITPARAM][N_FITSTUB * 2];
483  double sigma[N_FITSTUB * 2];
484  double kfactor[N_FITSTUB * 2];
485 
486  unsigned int n = nlayers + ndisks;
487 
488  if (settings_.exactderivatives()) {
490  settings_, nlayers, r, ndisks, z, alpha, t, rinv, D, iD, MinvDt, iMinvDt, sigma, kfactor);
491  ttabi = t;
492  ttab = t;
493  } else {
496  settings_, nlayers, r, ndisks, z, alpha, t, rinv, D, iD, MinvDt, iMinvDt, sigma, kfactor);
497 
498  double MinvDtDummy[N_FITPARAM][N_FITSTUB * 2];
499  derivatives->fill(tracklet->fpgat().value(), MinvDtDummy, iMinvDt);
500  ttab = t;
501  } else {
502  derivatives->fill(tracklet->fpgat().value(), MinvDt, iMinvDt);
503  }
504  }
505 
506  if (!settings_.exactderivatives()) {
507  for (unsigned int i = 0; i < nlayers; i++) {
508  if (r[i] > settings_.rPS2S())
509  continue;
510  for (unsigned int ii = 0; ii < nlayers; ii++) {
511  if (r[ii] > settings_.rPS2S())
512  continue;
513 
514  double tder = derivatives->tdzcorr(i, ii);
515  double zder = derivatives->z0dzcorr(i, ii);
516 
517  double dr = realrstub[i] - r[i];
518 
519  MinvDt[2][2 * ii + 1] += dr * tder;
520  MinvDt[3][2 * ii + 1] += dr * zder;
521 
522  int itder = derivatives->itdzcorr(i, ii);
523  int izder = derivatives->iz0dzcorr(i, ii);
524 
525  int idr = dr / settings_.kr();
526 
527  iMinvDt[2][2 * ii + 1] += ((idr * itder) >> settings_.rcorrbits());
528  iMinvDt[3][2 * ii + 1] += ((idr * izder) >> settings_.rcorrbits());
529  }
530  }
531  }
532 
533  double rinvseed = tracklet->rinvapprox();
534  double phi0seed = tracklet->phi0approx();
535  double tseed = tracklet->tapprox();
536  double z0seed = tracklet->z0approx();
537 
538  double rinvseedexact = tracklet->rinv();
539  double phi0seedexact = tracklet->phi0();
540  double tseedexact = tracklet->t();
541  double z0seedexact = tracklet->z0();
542 
543  double chisqseed = 0.0;
544  double chisqseedexact = 0.0;
545 
546  double delta[2 * N_FITSTUB];
547  double deltaexact[2 * N_FITSTUB];
548  int idelta[2 * N_FITSTUB];
549 
550  for (unsigned int i = 0; i < 2 * N_FITSTUB; i++) {
551  delta[i] = 0.0;
552  deltaexact[i] = 0.0;
553  idelta[i] = 0;
554  }
555 
556  int j = 0;
557 
558  for (unsigned int i = 0; i < n; i++) {
559  if (i >= nlayers) {
560  iphiresid[i] *= (t / ttabi);
561  phiresid[i] *= (t / ttab);
562  phiresidexact[i] *= (t / ttab);
563  }
564 
565  idelta[j] = iphiresid[i];
566  delta[j] = phiresid[i];
567  if (std::abs(phiresid[i]) > 0.2) {
568  edm::LogWarning("Tracklet") << getName() << " WARNING too large phiresid: " << phiresid[i] << " "
569  << phiresidexact[i];
570  }
571  assert(std::abs(phiresid[i]) < 1.0);
572  assert(std::abs(phiresidexact[i]) < 1.0);
573  deltaexact[j++] = phiresidexact[i];
574 
575  idelta[j] = izresid[i];
576  delta[j] = zresid[i];
577  deltaexact[j++] = zresidexact[i];
578 
579  chisqseed += (delta[j - 2] * delta[j - 2] + delta[j - 1] * delta[j - 1]);
580  chisqseedexact += (deltaexact[j - 2] * deltaexact[j - 2] + deltaexact[j - 1] * deltaexact[j - 1]);
581  }
582  assert(j <= 12);
583 
584  double drinv = 0.0;
585  double dphi0 = 0.0;
586  double dt = 0.0;
587  double dz0 = 0.0;
588 
589  double drinvexact = 0.0;
590  double dphi0exact = 0.0;
591  double dtexact = 0.0;
592  double dz0exact = 0.0;
593 
594  int idrinv = 0;
595  int idphi0 = 0;
596  int idt = 0;
597  int idz0 = 0;
598 
599  double drinv_cov = 0.0;
600  double dphi0_cov = 0.0;
601  double dt_cov = 0.0;
602  double dz0_cov = 0.0;
603 
604  double drinv_covexact = 0.0;
605  double dphi0_covexact = 0.0;
606  double dt_covexact = 0.0;
607  double dz0_covexact = 0.0;
608 
609  for (unsigned int j = 0; j < 2 * n; j++) {
610  drinv -= MinvDt[0][j] * delta[j];
611  dphi0 -= MinvDt[1][j] * delta[j];
612  dt -= MinvDt[2][j] * delta[j];
613  dz0 -= MinvDt[3][j] * delta[j];
614 
615  drinv_cov += D[0][j] * delta[j];
616  dphi0_cov += D[1][j] * delta[j];
617  dt_cov += D[2][j] * delta[j];
618  dz0_cov += D[3][j] * delta[j];
619 
620  drinvexact -= MinvDt[0][j] * deltaexact[j];
621  dphi0exact -= MinvDt[1][j] * deltaexact[j];
622  dtexact -= MinvDt[2][j] * deltaexact[j];
623  dz0exact -= MinvDt[3][j] * deltaexact[j];
624 
625  drinv_covexact += D[0][j] * deltaexact[j];
626  dphi0_covexact += D[1][j] * deltaexact[j];
627  dt_covexact += D[2][j] * deltaexact[j];
628  dz0_covexact += D[3][j] * deltaexact[j];
629 
630  idrinv += ((iMinvDt[0][j] * idelta[j]));
631  idphi0 += ((iMinvDt[1][j] * idelta[j]));
632  idt += ((iMinvDt[2][j] * idelta[j]));
633  idz0 += ((iMinvDt[3][j] * idelta[j]));
634 
635  if (false && j % 2 == 0) {
636  edm::LogVerbatim("Tracklet") << "DEBUG CHI2FIT " << j << " " << rinvseed << " + " << MinvDt[0][j] * delta[j]
637  << " " << MinvDt[0][j] << " " << delta[j] * rstub[j / 2] * 10000 << " \n"
638  << j << " " << tracklet->fpgarinv().value() * settings_.krinvpars() << " + "
639  << ((iMinvDt[0][j] * idelta[j])) * settings_.krinvpars() / 1024.0 << " "
640  << iMinvDt[0][j] * settings_.krinvpars() / settings_.kphi() / 1024.0 << " "
641  << idelta[j] * settings_.kphi() * rstub[j / 2] * 10000 << " " << idelta[j];
642  }
643  }
644 
645  double deltaChisqexact =
646  drinvexact * drinv_covexact + dphi0exact * dphi0_covexact + dtexact * dt_covexact + dz0exact * dz0_covexact;
647 
648  int irinvseed = tracklet->fpgarinv().value();
649  int iphi0seed = tracklet->fpgaphi0().value();
650 
651  int itseed = tracklet->fpgat().value();
652  int iz0seed = tracklet->fpgaz0().value();
653 
654  int irinvfit = irinvseed + ((idrinv + (1 << settings_.fitrinvbitshift())) >> settings_.fitrinvbitshift());
655 
656  int iphi0fit = iphi0seed + (idphi0 >> settings_.fitphi0bitshift());
657  int itfit = itseed + (idt >> settings_.fittbitshift());
658 
659  int iz0fit = iz0seed + (idz0 >> settings_.fitz0bitshift());
660 
661  double rinvfit = rinvseed - drinv;
662  double phi0fit = phi0seed - dphi0;
663 
664  double tfit = tseed - dt;
665  double z0fit = z0seed - dz0;
666 
667  double rinvfitexact = rinvseedexact - drinvexact;
668  double phi0fitexact = phi0seedexact - dphi0exact;
669 
670  double tfitexact = tseedexact - dtexact;
671  double z0fitexact = z0seedexact - dz0exact;
672 
673  double chisqfitexact = chisqseedexact + deltaChisqexact;
674 
676  bool NewChisqDebug = false;
677  double chisqfit = 0.0;
678  uint ichisqfit = 0;
679 
680  double phifactor;
681  double rzfactor;
682  double iphifactor;
683  double irzfactor;
684  int k = 0; // column index of D matrix
685 
686  if (NewChisqDebug) {
687  edm::LogVerbatim("Tracklet") << "OG chisq: \n"
688  << "drinv/cov = " << drinv << "/" << drinv_cov << " \n"
689  << "dphi0/cov = " << drinv << "/" << dphi0_cov << " \n"
690  << "dt/cov = " << drinv << "/" << dt_cov << " \n"
691  << "dz0/cov = " << drinv << "/" << dz0_cov << "\n";
692  std::string myout = "D[0][k]= ";
693  for (unsigned int i = 0; i < 2 * n; i++) {
694  myout += std::to_string(D[0][i]);
695  myout += ", ";
696  }
697  edm::LogVerbatim("Tracklet") << myout;
698  }
699 
700  for (unsigned int i = 0; i < n; i++) { // loop over stubs
701 
702  phifactor = rstub[k / 2] * delta[k] / sigma[k] + D[0][k] * drinv + D[1][k] * dphi0 + D[2][k] * dt + D[3][k] * dz0;
703  iphifactor = kfactor[k] * rstub[k / 2] * idelta[k] * (1 << settings_.chisqphifactbits()) / sigma[k] -
704  iD[0][k] * idrinv - iD[1][k] * idphi0 - iD[2][k] * idt - iD[3][k] * idz0;
705 
706  if (NewChisqDebug) {
707  edm::LogVerbatim("Tracklet") << "delta[k]/sigma = " << delta[k] / sigma[k] << " delta[k] = " << delta[k] << "\n"
708  << "sum = " << phifactor - delta[k] / sigma[k] << " drinvterm = " << D[0][k] * drinv
709  << " dphi0term = " << D[1][k] * dphi0 << " dtterm = " << D[2][k] * dt
710  << " dz0term = " << D[3][k] * dz0 << "\n phifactor = " << phifactor;
711  }
712 
713  chisqfit += phifactor * phifactor;
714  ichisqfit += iphifactor * iphifactor / (1 << (2 * settings_.chisqphifactbits() - 4));
715 
716  k++;
717 
718  rzfactor = delta[k] / sigma[k] + D[0][k] * drinv + D[1][k] * dphi0 + D[2][k] * dt + D[3][k] * dz0;
719  irzfactor = kfactor[k] * idelta[k] * (1 << settings_.chisqzfactbits()) / sigma[k] - iD[0][k] * idrinv -
720  iD[1][k] * idphi0 - iD[2][k] * idt - iD[3][k] * idz0;
721 
722  if (NewChisqDebug) {
723  edm::LogVerbatim("Tracklet") << "delta[k]/sigma = " << delta[k] / sigma[k] << " delta[k] = " << delta[k] << "\n"
724  << "sum = " << rzfactor - delta[k] / sigma[k] << " drinvterm = " << D[0][k] * drinv
725  << " dphi0term = " << D[1][k] * dphi0 << " dtterm = " << D[2][k] * dt
726  << " dz0term = " << D[3][k] * dz0 << "\n rzfactor = " << rzfactor;
727  }
728 
729  chisqfit += rzfactor * rzfactor;
730  ichisqfit += irzfactor * irzfactor / (1 << (2 * settings_.chisqzfactbits() - 4));
731 
732  k++;
733  }
734 
735  if (settings_.writeMonitorData("ChiSq")) {
736  globals_->ofstream("chisq.txt") << asinh(itfit * settings_.ktpars()) << " " << chisqfit << " " << ichisqfit / 16.0
737  << endl;
738  }
739 
740  // Chisquare per DOF capped out at 11 bits, so 15 is an educated guess
741  if (ichisqfit >= (1 << 15)) {
742  if (NewChisqDebug) {
743  edm::LogVerbatim("Tracklet") << "CHISQUARE (" << ichisqfit << ") LARGER THAN 11 BITS!";
744  }
745  ichisqfit = (1 << 15) - 1;
746  }
747 
748  // Eliminate lower bits to fit in 8 bits
749  ichisqfit = ichisqfit >> 7;
750  // Probably redundant... enforce 8 bit cap
751  if (ichisqfit >= (1 << 8))
752  ichisqfit = (1 << 8) - 1;
753 
754  double phicrit = phi0fit - asin(0.5 * settings_.rcrit() * rinvfit);
755  bool keep = (phicrit > settings_.phicritmin()) && (phicrit < settings_.phicritmax());
756 
757  if (!keep) {
758  return;
759  }
760 
761  // NOTE: setFitPars in Tracklet.h now accepts chi2 r-phi and chi2 r-z values. This class only has access
762  // to the composite chi2. When setting fit parameters on a tracklet, this places all of the chi2 into the
763  // r-phi fit, and sets the r-z fit value to zero.
764  //
765  // This is also true for the call to setFitPars in trackFitFake.
766  tracklet->setFitPars(rinvfit,
767  phi0fit,
768  0.0,
769  tfit,
770  z0fit,
771  chisqfit,
772  0.0,
773  rinvfitexact,
774  phi0fitexact,
775  0.0,
776  tfitexact,
777  z0fitexact,
778  chisqfitexact,
779  0.0,
780  irinvfit,
781  iphi0fit,
782  0,
783  itfit,
784  iz0fit,
785  ichisqfit,
786  0,
787  0);
788 }
Log< level::Info, true > LogVerbatim
float dt
Definition: AMPTWrapper.h:136
const FPGAWord & fpgarinv() const
Definition: Tracklet.h:132
int chisqzfactbits() const
Definition: Settings.h:381
double t() const
Definition: Tracklet.h:123
double phiresid() const
Definition: Residual.h:47
double tdzcorr(int i, int j) const
Definition: TrackDer.h:66
float alpha
Definition: AMPTWrapper.h:105
const Stub * innerFPGAStub()
Definition: Tracklet.h:61
int nrinvBitsTable() const
Definition: Settings.h:219
constexpr int N_DISK
Definition: Settings.h:22
double z0dzcorr(int i, int j) const
Definition: TrackDer.h:67
double rPS2S() const
Definition: Settings.h:322
const Residual & resid(unsigned int layerdisk)
Definition: Tracklet.h:110
static void calculateDerivatives(Settings const &settings, unsigned int nlayers, double r[N_LAYER], unsigned int ndisks, double z[N_DISK], double alpha[N_DISK], double t, double rinv, double D[N_FITPARAM][N_FITSTUB *2], int iD[N_FITPARAM][N_FITSTUB *2], double MinvDt[N_FITPARAM][N_FITSTUB *2], int iMinvDt[N_FITPARAM][N_FITSTUB *2], double sigma[N_FITSTUB *2], double kfactor[N_FITSTUB *2])
const Stub * outerFPGAStub()
Definition: Tracklet.h:65
int disk() const
Definition: Tracklet.cc:779
bool isOverlap() const
Definition: Tracklet.h:201
int alphaBitsTable() const
Definition: Settings.h:218
tuple disks
Definition: alignBH_cfg.py:13
double rzresid() const
Definition: Residual.h:52
const FPGAWord & fpgaphiresid() const
Definition: Residual.h:32
int getEntries() const
Definition: TrackDerTable.h:37
const FPGAWord & fpgaz0() const
Definition: Tracklet.h:136
double rinvmax() const
Definition: Settings.h:214
const FPGAWord & fpgaphi0() const
Definition: Tracklet.h:133
Settings const & settings_
Definition: ProcessBase.h:40
double phi0() const
Definition: Tracklet.h:121
Globals * globals_
Definition: ProcessBase.h:41
std::string to_string(const V &value)
Definition: OMSAccess.h:71
bool exactderivatives() const
Definition: Settings.h:232
bool exactderivativesforfloating() const
Definition: Settings.h:233
double ktpars() const
Definition: Settings.h:389
double krinvpars() const
Definition: Settings.h:384
const FPGAWord & fpgat() const
Definition: Tracklet.h:135
assert(be >=bs)
int itdzcorr(int i, int j) const
Definition: TrackDer.h:78
int fittbitshift() const
Definition: Settings.h:374
int fitz0bitshift() const
Definition: Settings.h:375
unsigned int isPSmodule() const
Definition: L1TStub.h:94
int rcorrbits() const
Definition: Settings.h:378
const FPGAWord & fpgarzresid() const
Definition: Residual.h:37
double phi0approx() const
Definition: Tracklet.h:127
static double tpar(Settings const &settings, int diskmask, int layermask)
double rmean(unsigned int iLayer) const
Definition: Settings.h:164
double rinv() const
Definition: Tracklet.h:120
double phicritmin() const
Definition: Settings.h:292
double stripPitch(bool isPSmodule) const
Definition: Settings.h:260
void fill(int t, double MinvDt[N_FITPARAM][N_FITSTUB *2], int iMinvDt[N_FITPARAM][N_FITSTUB *2]) const
Definition: TrackDer.cc:42
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int value() const
Definition: FPGAWord.h:24
double tapprox() const
Definition: Tracklet.h:129
L1TStub * l1tstub()
Definition: Stub.h:77
const TrackDer * getDerivatives(int index) const
Definition: TrackDerTable.h:24
std::string const & fitPatternFile() const
Definition: Settings.h:66
bool writeMonitorData(std::string module) const
Definition: Settings.h:109
bool isBarrel() const
Definition: Tracklet.h:200
double phiresidapprox() const
Definition: Residual.h:57
d
Definition: ztail.py:151
double zmean(unsigned int iDisk) const
Definition: Settings.h:167
ii
Definition: cuy.py:589
double alpha(double pitch) const
Definition: L1TStub.cc:73
bool debugTracklet() const
Definition: Settings.h:182
double rzresidapprox() const
Definition: Residual.h:62
double rinvapprox() const
Definition: Tracklet.h:126
double kr() const
Definition: Settings.h:304
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
double z0approx() const
Definition: Tracklet.h:130
int nbits() const
Definition: FPGAWord.h:25
double rinv(double phi1, double phi2, double r1, double r2)
Definition: Util.h:49
int iz0dzcorr(int i, int j) const
Definition: TrackDer.h:79
void set(int value, int nbits, bool positive=true, int line=-1, const char *file=nullptr)
Definition: FPGAWord.cc:14
constexpr unsigned int N_FITPARAM
Definition: Settings.h:900
void readPatternFile(std::string fileName)
const Stub * stubptr() const
Definition: Residual.h:67
double z0() const
Definition: Tracklet.h:124
const FPGAWord & alpha() const
Definition: Stub.h:64
double r() const
Definition: L1TStub.h:58
bool match(unsigned int layerdisk)
Definition: Tracklet.h:105
int isDisk() const
Definition: Tracklet.h:202
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
constexpr unsigned int N_FITSTUB
Definition: Settings.h:901
int fitrinvbitshift() const
Definition: Settings.h:372
void setFitPars(double rinvfit, double phi0fit, double d0fit, double tfit, double z0fit, double chisqrphifit, double chisqrzfit, double rinvfitexact, double phi0fitexact, double d0fitexact, double tfitexact, double z0fitexact, double chisqrphifitexact, double chisqrzfitexact, int irinvfit, int iphi0fit, int id0fit, int itfit, int iz0fit, int ichisqrphifit, int ichisqrzfit, int hitpattern, const std::vector< const L1TStub *> &l1stubs=std::vector< const L1TStub *>())
Definition: Tracklet.cc:515
double phicritmax() const
Definition: Settings.h:293
int chisqphifactbits() const
Definition: Settings.h:380
TrackDerTable *& trackDerTable()
Definition: Globals.h:40
Log< level::Warning, false > LogWarning
const unsigned int kfactor
int layer() const
Definition: Tracklet.cc:770
static constexpr float d1
double kphi() const
Definition: Settings.h:298
tmp
align.sh
Definition: createJobs.py:716
int fitphi0bitshift() const
Definition: Settings.h:373
std::string const & getName() const
Definition: ProcessBase.h:22
std::string str() const
Definition: FPGAWord.cc:54
bool warnNoDer() const
Definition: Settings.h:186
constexpr int N_LAYER
Definition: Settings.h:21
double rcrit() const
Definition: Settings.h:288

◆ trackFitFake()

void FitTrack::trackFitFake ( Tracklet tracklet,
std::vector< const Stub *> &  ,
std::vector< std::pair< int, int >> &   
)

Definition at line 790 of file FitTrack.cc.

References trklet::Tracklet::d0(), trklet::Tracklet::d0approx(), trklet::Tracklet::fpgad0(), trklet::Tracklet::fpgaphi0(), trklet::Tracklet::fpgarinv(), trklet::Tracklet::fpgat(), trklet::Tracklet::fpgaz0(), trklet::Tracklet::phi0(), trklet::Tracklet::phi0approx(), trklet::Tracklet::rinv(), trklet::Tracklet::rinvapprox(), trklet::Tracklet::setFitPars(), trklet::Tracklet::t(), trklet::Tracklet::tapprox(), trklet::FPGAWord::value(), trklet::Tracklet::z0(), and trklet::Tracklet::z0approx().

Referenced by execute().

790  {
791  tracklet->setFitPars(tracklet->rinvapprox(),
792  tracklet->phi0approx(),
793  tracklet->d0approx(),
794  tracklet->tapprox(),
795  tracklet->z0approx(),
796  0.0,
797  0.0,
798  tracklet->rinv(),
799  tracklet->phi0(),
800  tracklet->d0(),
801  tracklet->t(),
802  tracklet->z0(),
803  0.0,
804  0.0,
805  tracklet->fpgarinv().value(),
806  tracklet->fpgaphi0().value(),
807  tracklet->fpgad0().value(),
808  tracklet->fpgat().value(),
809  tracklet->fpgaz0().value(),
810  0,
811  0,
812  0);
813  return;
814 }
const FPGAWord & fpgarinv() const
Definition: Tracklet.h:132
double t() const
Definition: Tracklet.h:123
const FPGAWord & fpgaz0() const
Definition: Tracklet.h:136
const FPGAWord & fpgaphi0() const
Definition: Tracklet.h:133
double phi0() const
Definition: Tracklet.h:121
const FPGAWord & fpgat() const
Definition: Tracklet.h:135
double phi0approx() const
Definition: Tracklet.h:127
double rinv() const
Definition: Tracklet.h:120
int value() const
Definition: FPGAWord.h:24
double tapprox() const
Definition: Tracklet.h:129
const FPGAWord & fpgad0() const
Definition: Tracklet.h:134
double rinvapprox() const
Definition: Tracklet.h:126
double d0() const
Definition: Tracklet.h:122
double z0approx() const
Definition: Tracklet.h:130
double d0approx() const
Definition: Tracklet.h:128
double z0() const
Definition: Tracklet.h:124
void setFitPars(double rinvfit, double phi0fit, double d0fit, double tfit, double z0fit, double chisqrphifit, double chisqrzfit, double rinvfitexact, double phi0fitexact, double d0fitexact, double tfitexact, double z0fitexact, double chisqrphifitexact, double chisqrzfitexact, int irinvfit, int iphi0fit, int id0fit, int itfit, int iz0fit, int ichisqrphifit, int ichisqrzfit, int hitpattern, const std::vector< const L1TStub *> &l1stubs=std::vector< const L1TStub *>())
Definition: Tracklet.cc:515

◆ trackFitKF()

void trklet::FitTrack::trackFitKF ( Tracklet tracklet,
std::vector< const Stub *> &  trackstublist,
std::vector< std::pair< int, int >> &  stubidslist 
)

Referenced by execute().

Member Data Documentation

◆ fullmatch1_

std::vector<FullMatchMemory*> trklet::FitTrack::fullmatch1_
private

Definition at line 45 of file FitTrack.h.

Referenced by addInput(), and execute().

◆ fullmatch2_

std::vector<FullMatchMemory*> trklet::FitTrack::fullmatch2_
private

Definition at line 46 of file FitTrack.h.

Referenced by addInput(), and execute().

◆ fullmatch3_

std::vector<FullMatchMemory*> trklet::FitTrack::fullmatch3_
private

Definition at line 47 of file FitTrack.h.

Referenced by addInput(), and execute().

◆ fullmatch4_

std::vector<FullMatchMemory*> trklet::FitTrack::fullmatch4_
private

Definition at line 48 of file FitTrack.h.

Referenced by addInput(), and execute().

◆ iSector_

unsigned int trklet::FitTrack::iSector_
private

Definition at line 50 of file FitTrack.h.

Referenced by execute().

◆ seedtracklet_

std::vector<TrackletParametersMemory*> trklet::FitTrack::seedtracklet_
private

Definition at line 44 of file FitTrack.h.

Referenced by addInput().

◆ trackfit_

TrackFitMemory* trklet::FitTrack::trackfit_
private

Definition at line 52 of file FitTrack.h.

Referenced by addOutput(), and execute().