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 (std::deque< std::string > &streamTrackRaw, std::vector< std::deque< StubStreamData >> &stubStream, 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 19 of file FitTrack.h.

Constructor & Destructor Documentation

◆ FitTrack()

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

Definition at line 16 of file FitTrack.cc.

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

◆ ~FitTrack()

trklet::FitTrack::~FitTrack ( )
overridedefault

Member Function Documentation

◆ addInput()

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

Implements trklet::ProcessBase.

Definition at line 34 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().

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

◆ addOutput()

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

Implements trklet::ProcessBase.

Definition at line 19 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().

19  {
20  if (settings_.writetrace()) {
21  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
22  << output;
23  }
24  if (output == "trackout") {
25  TrackFitMemory* tmp = dynamic_cast<TrackFitMemory*>(memory);
26  assert(tmp != nullptr);
27  trackfit_ = tmp;
28  return;
29  }
30 
31  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " addOutput, output = " << output << " not known";
32 }
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:195
assert(be >=bs)
TrackFitMemory * trackfit_
Definition: FitTrack.h:58
Definition: output.py:1
tmp
align.sh
Definition: createJobs.py:716

◆ execute()

void FitTrack::execute ( std::deque< std::string > &  streamTrackRaw,
std::vector< std::deque< StubStreamData >> &  stubStream,
unsigned int  iSector 
)

Definition at line 876 of file FitTrack.cc.

References trklet::TrackFitMemory::addStubidsList(), trklet::TrackFitMemory::addStubList(), trklet::TrackFitMemory::addTrack(), cms::cuda::assert(), ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), trklet::Settings::debugTracklet(), trklet::L1TStub::disk(), trklet::Settings::fakefit(), trklet::Tracklet::fit(), groupFilesInBlocks::fout, trklet::Tracklet::fpgaphi0(), trklet::Residual::fpgaphiresid(), trklet::Tracklet::fpgarinv(), trklet::Residual::fpgarzresid(), trklet::Residual::fpgastubid(), trklet::Tracklet::fpgat(), trklet::Tracklet::fpgaz0(), fullmatch1_, fullmatch2_, fullmatch3_, fullmatch4_, trklet::Tracklet::getISeed(), trklet::ProcessBase::getName(), trklet::ProcessBase::globals_, mps_fire::i, trklet::Tracklet::innerFPGAStub(), createfilelist::int, iSector_, trklet::L1TStub::isPSmodule(), trklet::Stub::l1tstub(), trklet::Tracklet::match(), trklet::Settings::maxStep(), trklet::N_DISK, trklet::N_LAYER, trklet::N_SEED_PROMPT, trklet::ProcessBase::name_, trklet::Settings::nbitsseed(), trklet::TrackFitMemory::nTracks(), trklet::Globals::ofstream(), orderedMatches(), trklet::Tracklet::outerFPGAStub(), trklet::Stub::r(), trklet::Settings::removalType(), trklet::Tracklet::resid(), trklet::rinv(), fileCollector::seed, trklet::ProcessBase::settings_, trklet::Tracklet::setTrackIndex(), trklet::Settings::storeTrackBuilderOutput(), trklet::FPGAWord::str(), str, cms::cuda::stream, AlCaHLTBitMon_QueryRunRegistry::string, trklet::Stub::stubindex(), trklet::Residual::stubptr(), trklet::Tracklet::t(), submitPVValidationJobs::t, trklet::Tracklet::TCID(), trackfit_, trackFitChisq(), trackFitFake(), trackFitKF(), validateGeometry_cfg::valid, and trklet::Settings::writeMonitorData().

878  {
879  // merge
880  const std::vector<Tracklet*>& matches1 = orderedMatches(fullmatch1_);
881  const std::vector<Tracklet*>& matches2 = orderedMatches(fullmatch2_);
882  const std::vector<Tracklet*>& matches3 = orderedMatches(fullmatch3_);
883  const std::vector<Tracklet*>& matches4 = orderedMatches(fullmatch4_);
884 
885  iSector_ = iSector;
886 
887  if (settings_.debugTracklet() && (matches1.size() + matches2.size() + matches3.size() + matches4.size()) > 0) {
888  for (auto& imatch : fullmatch1_) {
889  edm::LogVerbatim("Tracklet") << imatch->getName() << " " << imatch->nMatches();
890  }
891  edm::LogVerbatim("Tracklet") << getName() << " matches : " << matches1.size() << " " << matches2.size() << " "
892  << matches3.size() << " " << matches4.size();
893  }
894 
895  unsigned int indexArray[4];
896  for (unsigned int i = 0; i < 4; i++) {
897  indexArray[i] = 0;
898  }
899 
900  unsigned int countAll = 0;
901  unsigned int countFit = 0;
902 
903  Tracklet* bestTracklet = nullptr;
904  do {
905  countAll++;
906  bestTracklet = nullptr;
907 
908  if (indexArray[0] < matches1.size()) {
909  if (bestTracklet == nullptr) {
910  bestTracklet = matches1[indexArray[0]];
911  } else {
912  if (matches1[indexArray[0]]->TCID() < bestTracklet->TCID())
913  bestTracklet = matches1[indexArray[0]];
914  }
915  }
916 
917  if (indexArray[1] < matches2.size()) {
918  if (bestTracklet == nullptr) {
919  bestTracklet = matches2[indexArray[1]];
920  } else {
921  if (matches2[indexArray[1]]->TCID() < bestTracklet->TCID())
922  bestTracklet = matches2[indexArray[1]];
923  }
924  }
925 
926  if (indexArray[2] < matches3.size()) {
927  if (bestTracklet == nullptr) {
928  bestTracklet = matches3[indexArray[2]];
929  } else {
930  if (matches3[indexArray[2]]->TCID() < bestTracklet->TCID())
931  bestTracklet = matches3[indexArray[2]];
932  }
933  }
934 
935  if (indexArray[3] < matches4.size()) {
936  if (bestTracklet == nullptr) {
937  bestTracklet = matches4[indexArray[3]];
938  } else {
939  if (matches4[indexArray[3]]->TCID() < bestTracklet->TCID())
940  bestTracklet = matches4[indexArray[3]];
941  }
942  }
943 
944  if (bestTracklet == nullptr)
945  break;
946 
947  //Counts total number of matched hits
948  int nMatches = 0;
949 
950  //Counts unique hits in each layer
951  int nMatchesUniq = 0;
952  bool match = false;
953 
954  while (indexArray[0] < matches1.size() && matches1[indexArray[0]] == bestTracklet) {
955  indexArray[0]++;
956  nMatches++;
957  match = true;
958  }
959 
960  if (match)
961  nMatchesUniq++;
962  match = false;
963 
964  while (indexArray[1] < matches2.size() && matches2[indexArray[1]] == bestTracklet) {
965  indexArray[1]++;
966  nMatches++;
967  match = true;
968  }
969 
970  if (match)
971  nMatchesUniq++;
972  match = false;
973 
974  while (indexArray[2] < matches3.size() && matches3[indexArray[2]] == bestTracklet) {
975  indexArray[2]++;
976  nMatches++;
977  match = true;
978  }
979 
980  if (match)
981  nMatchesUniq++;
982  match = false;
983 
984  while (indexArray[3] < matches4.size() && matches4[indexArray[3]] == bestTracklet) {
985  indexArray[3]++;
986  nMatches++;
987  match = true;
988  }
989 
990  if (match)
991  nMatchesUniq++;
992 
993  if (settings_.debugTracklet()) {
994  edm::LogVerbatim("Tracklet") << getName() << " : nMatches = " << nMatches << " nMatchesUniq = " << nMatchesUniq
995  << " " << asinh(bestTracklet->t());
996  }
997 
998  std::vector<const Stub*> trackstublist;
999  std::vector<std::pair<int, int>> stubidslist;
1000  // Track Builder cut of >= 4 layers with stubs.
1001  if ((bestTracklet->getISeed() >= (int)N_SEED_PROMPT && nMatchesUniq >= 1) ||
1002  nMatchesUniq >= 2) { //For seeds index >=8 (triplet seeds), there are three stubs associated from start.
1003  countFit++;
1004 
1005 #ifdef USEHYBRID
1006  if (settings_.fakefit()) {
1007  trackFitFake(bestTracklet, trackstublist, stubidslist);
1008  } else {
1009  trackFitKF(bestTracklet, trackstublist, stubidslist);
1010  }
1011 #else
1012  if (settings_.fakefit()) {
1013  trackFitFake(bestTracklet, trackstublist, stubidslist);
1014  } else {
1015  trackFitChisq(bestTracklet, trackstublist, stubidslist);
1016  }
1017 #endif
1018 
1019  if (settings_.removalType() == "merge") {
1020  trackfit_->addStubList(trackstublist);
1021  trackfit_->addStubidsList(stubidslist);
1022  bestTracklet->setTrackIndex(trackfit_->nTracks());
1023  trackfit_->addTrack(bestTracklet);
1024  } else if (bestTracklet->fit()) {
1025  assert(trackfit_ != nullptr);
1026  if (settings_.writeMonitorData("Seeds")) {
1027  ofstream fout("seeds.txt", ofstream::app);
1028  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_"
1029  << " " << bestTracklet->getISeed() << endl;
1030  fout.close();
1031  }
1032  bestTracklet->setTrackIndex(trackfit_->nTracks());
1033  trackfit_->addTrack(bestTracklet);
1034  }
1035  }
1036 
1037  // store bit and clock accurate TB output
1038  if (settings_.storeTrackBuilderOutput() && bestTracklet) {
1039  // add gap if TrackBuilder rejected track (due to too few stub layers).
1040  if (!bestTracklet->fit()) {
1041  static const string invalid = "0";
1042  streamTrackRaw.emplace_back(invalid);
1043  for (auto& stream : streamsStubRaw)
1044  stream.emplace_back(StubStreamData());
1045  continue;
1046  }
1047  // convert Track word
1048  const string rinv = bestTracklet->fpgarinv().str();
1049  const string phi0 = bestTracklet->fpgaphi0().str();
1050  const string z0 = bestTracklet->fpgaz0().str();
1051  const string t = bestTracklet->fpgat().str();
1052  const int seedType = bestTracklet->getISeed();
1053  const string seed = TTBV(seedType, settings_.nbitsseed()).str();
1054  const string valid("1");
1055  streamTrackRaw.emplace_back(valid + seed + rinv + phi0 + z0 + t);
1056 
1057  // convert projected stubs
1058  unsigned int ihit(0);
1059  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
1060  if (bestTracklet->match(ilayer)) {
1061  const Residual& resid = bestTracklet->resid(ilayer);
1062  // create bit accurate 64 bit word
1063  string r = resid.stubptr()->r().str();
1064  const string& phi = resid.fpgaphiresid().str();
1065  const string& rz = resid.fpgarzresid().str();
1066  const L1TStub* stub = resid.stubptr()->l1tstub();
1067  static constexpr int widthDisk2Sidentifier = 8;
1068  bool disk2S = (stub->disk() != 0) && (stub->isPSmodule() == 0);
1069  if (disk2S)
1070  r = string(widthDisk2Sidentifier, '0') + r;
1071  const string& stubId = resid.fpgastubid().str();
1072  // store seed, L1TStub, and bit accurate 64 bit word in clock accurate output
1073  streamsStubRaw[ihit++].emplace_back(seedType, *stub, valid + stubId + r + phi + rz);
1074  }
1075  }
1076  // convert seed stubs
1077  const string& stubId0 = bestTracklet->innerFPGAStub()->stubindex().str();
1078  const L1TStub* stub0 = bestTracklet->innerFPGAStub()->l1tstub();
1079  streamsStubRaw[ihit++].emplace_back(seedType, *stub0, valid + stubId0);
1080  const string& stubId1 = bestTracklet->outerFPGAStub()->stubindex().str();
1081  const L1TStub* stub1 = bestTracklet->outerFPGAStub()->l1tstub();
1082  streamsStubRaw[ihit++].emplace_back(seedType, *stub1, valid + stubId1);
1083  // fill all layers that have no stubs with gaps
1084  while (ihit < streamsStubRaw.size()) {
1085  streamsStubRaw[ihit++].emplace_back();
1086  }
1087  }
1088 
1089  } while (bestTracklet != nullptr && countAll < settings_.maxStep("TB"));
1090 
1091  if (settings_.writeMonitorData("FT")) {
1092  globals_->ofstream("fittrack.txt") << getName() << " " << countAll << " " << countFit << endl;
1093  }
1094 }
Log< level::Info, true > LogVerbatim
const FPGAWord & fpgarinv() const
Definition: Tracklet.h:132
double t() const
Definition: Tracklet.h:123
constexpr int N_DISK
Definition: Settings.h:26
unsigned int maxStep(std::string module) const
Definition: Settings.h:125
const FPGAWord & r() const
Definition: Stub.h:65
std::string name_
Definition: ProcessBase.h:38
const Residual & resid(unsigned int layerdisk)
Definition: Tracklet.h:110
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:20
const FPGAWord & fpgastubid() const
Definition: Residual.h:42
void addTrack(Tracklet *tracklet)
const FPGAWord & fpgaphiresid() const
Definition: Residual.h:32
const FPGAWord & fpgaz0() const
Definition: Tracklet.h:136
unsigned int nbitsseed() const
Definition: Settings.h:313
const FPGAWord & fpgaphi0() const
Definition: Tracklet.h:133
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:141
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
const FPGAWord & fpgat() const
Definition: Tracklet.h:135
void setTrackIndex(int index)
Definition: Tracklet.cc:832
assert(be >=bs)
int TCID() const
Definition: Tracklet.h:214
void addStubList(std::vector< const Stub *> stublist)
unsigned int isPSmodule() const
Definition: L1TStub.h:103
TrackFitMemory * trackfit_
Definition: FitTrack.h:58
std::vector< Tracklet * > orderedMatches(std::vector< FullMatchMemory *> &fullmatch)
Definition: FitTrack.cc:817
bool fit() const
Definition: Tracklet.h:197
std::vector< FullMatchMemory * > fullmatch4_
Definition: FitTrack.h:54
const FPGAWord & fpgarzresid() const
Definition: Residual.h:37
const Stub * outerFPGAStub() const
Definition: Tracklet.h:65
unsigned int nTracks() const
std::string removalType() const
Definition: Settings.h:251
bool fakefit() const
Definition: Settings.h:255
unsigned int iSector_
Definition: FitTrack.h:56
L1TStub * l1tstub()
Definition: Stub.h:83
int disk() const
Definition: L1TStub.h:46
bool writeMonitorData(std::string module) const
Definition: Settings.h:118
const FPGAWord & stubindex() const
Definition: Stub.h:72
std::vector< FullMatchMemory * > fullmatch1_
Definition: FitTrack.h:51
bool debugTracklet() const
Definition: Settings.h:194
std::vector< FullMatchMemory * > fullmatch2_
Definition: FitTrack.h:52
bool storeTrackBuilderOutput() const
Definition: Settings.h:257
double rinv(double phi1, double phi2, double r1, double r2)
Definition: Util.h:66
int getISeed() const
Definition: Tracklet.cc:820
const Stub * stubptr() const
Definition: Residual.h:67
bool match(unsigned int layerdisk)
Definition: Tracklet.h:105
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:791
#define str(s)
std::string const & getName() const
Definition: ProcessBase.h:22
std::vector< FullMatchMemory * > fullmatch3_
Definition: FitTrack.h:53
std::string str() const
Definition: FPGAWord.cc:54
constexpr unsigned int N_SEED_PROMPT
Definition: Settings.h:29
constexpr int N_LAYER
Definition: Settings.h:25
const Stub * innerFPGAStub() const
Definition: Tracklet.h:61

◆ orderedMatches()

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

Definition at line 817 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().

817  {
818  std::vector<Tracklet*> tmp;
819 
820  std::vector<unsigned int> indexArray;
821  for (auto& imatch : fullmatch) {
822  //check that we have correct order
823  if (imatch->nMatches() > 1) {
824  for (unsigned int j = 0; j < imatch->nMatches() - 1; j++) {
825  assert(imatch->getTracklet(j)->TCID() <= imatch->getTracklet(j + 1)->TCID());
826  }
827  }
828 
829  if (settings_.debugTracklet() && imatch->nMatches() != 0) {
830  edm::LogVerbatim("Tracklet") << "orderedMatches: " << imatch->getName() << " " << imatch->nMatches();
831  }
832 
833  indexArray.push_back(0);
834  }
835 
836  int bestIndex = -1;
837  do {
838  int bestTCID = -1;
839  bestIndex = -1;
840  for (unsigned int i = 0; i < fullmatch.size(); i++) {
841  if (indexArray[i] >= fullmatch[i]->nMatches()) {
842  //skip as we were at the end
843  continue;
844  }
845  int TCID = fullmatch[i]->getTracklet(indexArray[i])->TCID();
846  if (TCID < bestTCID || bestTCID < 0) {
847  bestTCID = TCID;
848  bestIndex = i;
849  }
850  }
851  if (bestIndex != -1) {
852  tmp.push_back(fullmatch[bestIndex]->getTracklet(indexArray[bestIndex]));
853  indexArray[bestIndex]++;
854  }
855  } while (bestIndex != -1);
856 
857  for (unsigned int i = 0; i < tmp.size(); i++) {
858  if (i > 0) {
859  //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.
860  //The algorithm will pick up the first hit and drop the second.
861  if (tmp[i - 1]->TCID() > tmp[i]->TCID()) {
862  edm::LogVerbatim("Tracklet") << "Wrong TCID ordering in " << getName() << " : " << tmp[i - 1]->TCID() << " "
863  << tmp[i]->TCID();
864  }
865  }
866  }
867 
868  return tmp;
869 }
Log< level::Info, true > LogVerbatim
Settings const & settings_
Definition: ProcessBase.h:40
assert(be >=bs)
bool debugTracklet() const
Definition: Settings.h:194
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 141 of file FitTrack.cc.

References funct::abs(), trklet::Stub::alpha(), trklet::L1TStub::alpha(), isotrackApplyRegressor::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, 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, isotrackApplyRegressor::k, runTheMatrix::keep, kfactor, trklet::Settings::kphi(), trklet::Settings::kr(), trklet::Settings::krinvpars(), trklet::Settings::ktpars(), MainPageGenerator::l, trklet::Stub::l1tstub(), trklet::Tracklet::layer(), hgcalTBTopologyTester_cfi::layers, trklet::Tracklet::match(), VarParsing::mult, create_idmaps::n, trklet::N_DISK, trklet::N_FITPARAM, trklet::N_FITSTUB, trklet::N_LAYER, trklet::FPGAWord::nbits(), 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(), cms::alpakatools::detail::power(), trklet::L1TStub::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, 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().

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

◆ trackFitFake()

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

Definition at line 791 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().

791  {
792  tracklet->setFitPars(tracklet->rinvapprox(),
793  tracklet->phi0approx(),
794  tracklet->d0approx(),
795  tracklet->tapprox(),
796  tracklet->z0approx(),
797  0.0,
798  0.0,
799  tracklet->rinv(),
800  tracklet->phi0(),
801  tracklet->d0(),
802  tracklet->t(),
803  tracklet->z0(),
804  0.0,
805  0.0,
806  tracklet->fpgarinv().value(),
807  tracklet->fpgaphi0().value(),
808  tracklet->fpgad0().value(),
809  tracklet->fpgat().value(),
810  tracklet->fpgaz0().value(),
811  0,
812  0,
813  0);
814  return;
815 }
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:523

◆ 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 51 of file FitTrack.h.

Referenced by addInput(), and execute().

◆ fullmatch2_

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

Definition at line 52 of file FitTrack.h.

Referenced by addInput(), and execute().

◆ fullmatch3_

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

Definition at line 53 of file FitTrack.h.

Referenced by addInput(), and execute().

◆ fullmatch4_

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

Definition at line 54 of file FitTrack.h.

Referenced by addInput(), and execute().

◆ iSector_

unsigned int trklet::FitTrack::iSector_
private

Definition at line 56 of file FitTrack.h.

Referenced by execute().

◆ seedtracklet_

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

Definition at line 50 of file FitTrack.h.

Referenced by addInput().

◆ trackfit_

TrackFitMemory* trklet::FitTrack::trackfit_
private

Definition at line 58 of file FitTrack.h.

Referenced by addOutput(), and execute().