24 if (
output ==
"trackout") {
31 throw cms::Exception(
"BadConfig") << __FILE__ <<
" " << __LINE__ <<
" addOutput, output = " <<
output <<
" not known";
39 if (
input.substr(0, 4) ==
"tpar") {
45 if (
input.substr(0, 10) ==
"fullmatch1") {
51 if (
input.substr(0, 10) ==
"fullmatch2") {
57 if (
input.substr(0, 10) ==
"fullmatch3") {
63 if (
input.substr(0, 10) ==
"fullmatch4") {
70 throw cms::Exception(
"BadConfig") << __FILE__ <<
" " << __LINE__ <<
" input = " <<
input <<
" not found";
75 std::vector<const Stub*>& trackstublist,
88 for (
unsigned int j = 0;
j <
i->nMatches();
j++) {
89 if (
i->getTracklet(
j)->TCID() == tracklet->
TCID()) {
90 trackstublist.push_back(
i->getMatch(
j).second);
96 for (
unsigned int j = 0;
j <
i->nMatches();
j++) {
97 if (
i->getTracklet(
j)->TCID() == tracklet->
TCID()) {
98 trackstublist.push_back(
i->getMatch(
j).second);
104 for (
unsigned int j = 0;
j <
i->nMatches();
j++) {
105 if (
i->getTracklet(
j)->TCID() == tracklet->
TCID()) {
106 trackstublist.push_back(
i->getMatch(
j).second);
112 for (
unsigned int j = 0;
j <
i->nMatches();
j++) {
113 if (
i->getTracklet(
j)->TCID() == tracklet->
TCID()) {
114 trackstublist.push_back(
i->getMatch(
j).second);
121 for (
const auto&
it : trackstublist) {
122 int layer =
it->layer().value() + 1;
123 if (
it->layer().value() < 0) {
124 layer =
it->disk().value() + 10 *
it->disk().value() /
abs(
it->disk().value());
126 stubidslist.push_back(std::make_pair(layer,
it->phiregionaddress()));
135 hybridFitter.Fit(tracklet, trackstublist);
140 #else // Code for pure Tracklet algo. 161 unsigned int nlayers = 0;
164 unsigned int ndisks = 0;
182 phiresidexact[
i] = 0.0;
183 zresidexact[
i] = 0.0;
186 std::bitset<N_LAYER> lmatches;
187 std::bitset<N_DISK * 2> dmatches;
191 unsigned int layermask = 0;
192 unsigned int diskmask = 0;
193 unsigned int alphaindex = 0;
194 unsigned int power = 1;
196 double t = tracklet->
t();
201 if (
l == (
unsigned int)tracklet->
layer() ||
l == (
unsigned int)tracklet->
layer() + 1) {
207 if (tracklet->
match(
l - 1)) {
213 phiresidexact[nlayers] = resid.
phiresid();
214 zresidexact[nlayers] = resid.
rzresid();
222 for (
unsigned int d = 1;
d <=
N_DISK;
d++) {
223 if (layermask & (1 << (
d - 1)))
235 dmatches.set(2 *
d - 1);
236 diskmask |= (1 << (2 * (
N_DISK -
d) + 1));
243 alphaindex += ialpha *
power;
245 dmatches.set(2 * (
N_DISK -
d));
246 diskmask |= (1 << (2 * (
N_DISK -
d)));
252 phiresidexact[nlayers + ndisks] = resid.
phiresid();
253 zresidexact[nlayers + ndisks] = resid.
rzresid();
264 << lmatches.to_string() <<
" " << dmatches.to_string() <<
" " <<
mult << endl;
270 for (
unsigned int l = 1;
l <= 2;
l++) {
271 if (tracklet->
match(
l - 1)) {
278 phiresidexact[nlayers] = resid.
phiresid();
279 zresidexact[nlayers] = resid.
rzresid();
291 if (
d == 5 and layermask & (1 << 4))
297 dmatches.set(2 *
d1 - 1);
298 diskmask |= (1 << (2 * (
N_DISK -
d1) + 1));
310 dmatches.set(2 *
d1 - 1);
311 diskmask |= (1 << (2 * (
N_DISK -
d1) + 1));
318 alphaindex += ialpha *
power;
321 diskmask |= (1 << (2 * (
N_DISK -
d1)));
330 phiresidexact[nlayers + ndisks] = resid.
phiresid();
331 zresidexact[nlayers + ndisks] = resid.
rzresid();
341 for (
unsigned int l = 1;
l <= 2;
l++) {
342 if (
l == (
unsigned int)tracklet->
layer()) {
348 if (tracklet->
match(
l - 1)) {
356 phiresidexact[nlayers] = resid.
phiresid();
357 zresidexact[nlayers] = resid.
rzresid();
371 if (
d == tracklet->
disk()) {
373 dmatches.set(2 *
d1 - 1);
374 diskmask |= (1 << (2 * (
N_DISK -
d1) + 1));
386 diskmask |= (1 << (2 * (
N_DISK -
d1) + 1));
388 tmp.set(diskmask, 10);
395 alphaindex += ialpha *
power;
398 diskmask |= (1 << (2 * (
N_DISK -
d1)));
400 tmp.set(diskmask, 10);
409 phiresidexact[nlayers + ndisks] = resid.
phiresid();
410 zresidexact[nlayers + ndisks] = resid.
rzresid();
428 if (derivatives ==
nullptr) {
431 tmpl.set(layermask, 6);
432 tmpd.
set(diskmask, 10);
433 edm::LogVerbatim(
"Tracklet") <<
"No derivative for layermask, diskmask : " << layermask <<
" " <<
tmpl.str()
434 <<
" " << diskmask <<
" " << tmpd.
str() <<
" eta = " << asinh(
t);
459 for (
unsigned i = 0;
i < nlayers;
i++) {
478 for (
unsigned i = 0;
i < ndisks;
i++) {
480 rstub[
i + nlayers] = z[
i] / ttabi;
490 unsigned int n = nlayers + ndisks;
494 settings_, nlayers, r, ndisks, z,
alpha,
t,
rinv,
D, iD, MinvDt, iMinvDt, sigma,
kfactor);
500 settings_, nlayers, r, ndisks, z,
alpha,
t,
rinv,
D, iD, MinvDt, iMinvDt, sigma,
kfactor);
503 derivatives->
fill(tracklet->
fpgat().
value(), MinvDtDummy, iMinvDt);
511 for (
unsigned int i = 0;
i < nlayers;
i++) {
514 for (
unsigned int ii = 0;
ii < nlayers;
ii++) {
521 double dr = realrstub[
i] - r[
i];
523 MinvDt[2][2 *
ii + 1] += dr * tder;
524 MinvDt[3][2 *
ii + 1] += dr * zder;
539 double tseed = tracklet->
tapprox();
540 double z0seed = tracklet->
z0approx();
542 double rinvseedexact = tracklet->
rinv();
543 double phi0seedexact = tracklet->
phi0();
544 double tseedexact = tracklet->
t();
545 double z0seedexact = tracklet->
z0();
547 double chisqseedexact = 0.0;
561 for (
unsigned int i = 0;
i <
n;
i++) {
563 iphiresid[
i] *= (
t / ttabi);
564 phiresid[
i] *= (
t / ttab);
565 phiresidexact[
i] *= (
t / ttab);
568 idelta[
j] = iphiresid[
i];
576 deltaexact[
j++] = phiresidexact[
i];
578 idelta[
j] = izresid[
i];
580 deltaexact[
j++] = zresidexact[
i];
582 chisqseedexact += (deltaexact[
j - 2] * deltaexact[
j - 2] + deltaexact[
j - 1] * deltaexact[
j - 1]);
591 double drinvexact = 0.0;
592 double dphi0exact = 0.0;
593 double dtexact = 0.0;
594 double dz0exact = 0.0;
601 double drinv_cov = 0.0;
602 double dphi0_cov = 0.0;
604 double dz0_cov = 0.0;
606 double drinv_covexact = 0.0;
607 double dphi0_covexact = 0.0;
608 double dt_covexact = 0.0;
609 double dz0_covexact = 0.0;
611 for (
unsigned int j = 0;
j < 2 *
n;
j++) {
612 drinv -= MinvDt[0][
j] *
delta[
j];
613 dphi0 -= MinvDt[1][
j] *
delta[
j];
615 dz0 -= MinvDt[3][
j] *
delta[
j];
622 drinvexact -= MinvDt[0][
j] * deltaexact[
j];
623 dphi0exact -= MinvDt[1][
j] * deltaexact[
j];
624 dtexact -= MinvDt[2][
j] * deltaexact[
j];
625 dz0exact -= MinvDt[3][
j] * deltaexact[
j];
627 drinv_covexact +=
D[0][
j] * deltaexact[
j];
628 dphi0_covexact +=
D[1][
j] * deltaexact[
j];
629 dt_covexact +=
D[2][
j] * deltaexact[
j];
630 dz0_covexact +=
D[3][
j] * deltaexact[
j];
632 idrinv += ((iMinvDt[0][
j] * idelta[
j]));
633 idphi0 += ((iMinvDt[1][
j] * idelta[
j]));
634 idt += ((iMinvDt[2][
j] * idelta[
j]));
635 idz0 += ((iMinvDt[3][
j] * idelta[
j]));
637 if (
false &&
j % 2 == 0) {
639 <<
" " << MinvDt[0][
j] <<
" " <<
delta[
j] * rstub[
j / 2] * 10000 <<
" \n" 647 double deltaChisqexact =
648 drinvexact * drinv_covexact + dphi0exact * dphi0_covexact + dtexact * dt_covexact + dz0exact * dz0_covexact;
663 double rinvfit = rinvseed - drinv;
664 double phi0fit = phi0seed - dphi0;
666 double tfit = tseed -
dt;
667 double z0fit = z0seed - dz0;
669 double rinvfitexact = rinvseedexact - drinvexact;
670 double phi0fitexact = phi0seedexact - dphi0exact;
672 double tfitexact = tseedexact - dtexact;
673 double z0fitexact = z0seedexact - dz0exact;
675 double chisqfitexact = chisqseedexact + deltaChisqexact;
678 bool NewChisqDebug =
false;
679 double chisqfit = 0.0;
690 <<
"drinv/cov = " << drinv <<
"/" << drinv_cov <<
" \n" 691 <<
"dphi0/cov = " << drinv <<
"/" << dphi0_cov <<
" \n" 692 <<
"dt/cov = " << drinv <<
"/" << dt_cov <<
" \n" 693 <<
"dz0/cov = " << drinv <<
"/" << dz0_cov <<
"\n";
695 for (
unsigned int i = 0;
i < 2 *
n;
i++) {
702 for (
unsigned int i = 0;
i <
n;
i++) {
704 phifactor = rstub[
k / 2] *
delta[
k] / sigma[
k] +
D[0][
k] * drinv +
D[1][
k] * dphi0 +
D[2][
k] *
dt +
D[3][
k] * dz0;
706 iD[0][
k] * idrinv - iD[1][
k] * idphi0 - iD[2][
k] * idt - iD[3][
k] * idz0;
710 <<
"sum = " << phifactor -
delta[
k] / sigma[
k] <<
" drinvterm = " <<
D[0][
k] * drinv
711 <<
" dphi0term = " <<
D[1][
k] * dphi0 <<
" dtterm = " <<
D[2][
k] *
dt 712 <<
" dz0term = " <<
D[3][
k] * dz0 <<
"\n phifactor = " << phifactor;
715 chisqfit += phifactor * phifactor;
720 rzfactor =
delta[
k] / sigma[
k] +
D[0][
k] * drinv +
D[1][
k] * dphi0 +
D[2][
k] *
dt +
D[3][
k] * dz0;
722 iD[1][
k] * idphi0 - iD[2][
k] * idt - iD[3][
k] * idz0;
726 <<
"sum = " << rzfactor -
delta[
k] / sigma[
k] <<
" drinvterm = " <<
D[0][
k] * drinv
727 <<
" dphi0term = " <<
D[1][
k] * dphi0 <<
" dtterm = " <<
D[2][
k] *
dt 728 <<
" dz0term = " <<
D[3][
k] * dz0 <<
"\n rzfactor = " << rzfactor;
731 chisqfit += rzfactor * rzfactor;
743 if (ichisqfit >= (1 << 15)) {
745 edm::LogVerbatim(
"Tracklet") <<
"CHISQUARE (" << ichisqfit <<
") LARGER THAN 11 BITS!";
747 ichisqfit = (1 << 15) - 1;
751 ichisqfit = ichisqfit >> 7;
753 if (ichisqfit >= (1 << 8))
754 ichisqfit = (1 << 8) - 1;
756 double phicrit = phi0fit - asin(0.5 *
settings_.
rcrit() * rinvfit);
821 std::vector<Tracklet*>
tmp;
823 std::vector<unsigned int> indexArray;
824 for (
auto& imatch : fullmatch) {
826 if (imatch->nMatches() > 1) {
827 for (
unsigned int j = 0;
j < imatch->nMatches() - 1;
j++) {
828 assert(imatch->getTracklet(
j)->TCID() <= imatch->getTracklet(
j + 1)->TCID());
833 edm::LogVerbatim(
"Tracklet") <<
"orderedMatches: " << imatch->getName() <<
" " << imatch->nMatches();
836 indexArray.push_back(0);
843 for (
unsigned int i = 0;
i < fullmatch.size();
i++) {
844 if (indexArray[
i] >= fullmatch[
i]->nMatches()) {
848 int TCID = fullmatch[
i]->getTracklet(indexArray[
i])->TCID();
849 if (TCID < bestTCID || bestTCID < 0) {
854 if (bestIndex != -1) {
855 tmp.push_back(fullmatch[bestIndex]->getTracklet(indexArray[bestIndex]));
856 indexArray[bestIndex]++;
858 }
while (bestIndex != -1);
860 for (
unsigned int i = 0;
i <
tmp.size();
i++) {
864 if (
tmp[
i - 1]->TCID() >
tmp[
i]->TCID()) {
880 vector<deque<StubStreamData>>& streamsStubRaw,
881 unsigned int iSector) {
890 if (
settings_.
debugTracklet() && (matches1.size() + matches2.size() + matches3.size() + matches4.size()) > 0) {
892 edm::LogVerbatim(
"Tracklet") << imatch->getName() <<
" " << imatch->nMatches();
895 << matches3.size() <<
" " << matches4.size();
898 unsigned int indexArray[4];
899 for (
unsigned int i = 0;
i < 4;
i++) {
903 unsigned int countAll = 0;
904 unsigned int countFit = 0;
909 bestTracklet =
nullptr;
911 if (indexArray[0] < matches1.size()) {
912 if (bestTracklet ==
nullptr) {
913 bestTracklet = matches1[indexArray[0]];
915 if (matches1[indexArray[0]]->TCID() < bestTracklet->
TCID())
916 bestTracklet = matches1[indexArray[0]];
920 if (indexArray[1] < matches2.size()) {
921 if (bestTracklet ==
nullptr) {
922 bestTracklet = matches2[indexArray[1]];
924 if (matches2[indexArray[1]]->TCID() < bestTracklet->
TCID())
925 bestTracklet = matches2[indexArray[1]];
929 if (indexArray[2] < matches3.size()) {
930 if (bestTracklet ==
nullptr) {
931 bestTracklet = matches3[indexArray[2]];
933 if (matches3[indexArray[2]]->TCID() < bestTracklet->
TCID())
934 bestTracklet = matches3[indexArray[2]];
938 if (indexArray[3] < matches4.size()) {
939 if (bestTracklet ==
nullptr) {
940 bestTracklet = matches4[indexArray[3]];
942 if (matches4[indexArray[3]]->TCID() < bestTracklet->
TCID())
943 bestTracklet = matches4[indexArray[3]];
947 if (bestTracklet ==
nullptr)
954 int nMatchesUniq = 0;
957 while (indexArray[0] < matches1.size() && matches1[indexArray[0]] == bestTracklet) {
967 while (indexArray[1] < matches2.size() && matches2[indexArray[1]] == bestTracklet) {
977 while (indexArray[2] < matches3.size() && matches3[indexArray[2]] == bestTracklet) {
987 while (indexArray[3] < matches4.size() && matches4[indexArray[3]] == bestTracklet) {
997 edm::LogVerbatim(
"Tracklet") <<
getName() <<
" : nMatches = " << nMatches <<
" nMatchesUniq = " << nMatchesUniq
998 <<
" " << asinh(bestTracklet->
t());
1001 std::vector<const Stub*> trackstublist;
1002 std::vector<std::pair<int, int>> stubidslist;
1005 nMatchesUniq >= 2) {
1010 trackFitFake(bestTracklet, trackstublist, stubidslist);
1012 trackFitKF(bestTracklet, trackstublist, stubidslist);
1016 trackFitFake(bestTracklet, trackstublist, stubidslist);
1027 }
else if (bestTracklet->
fit()) {
1030 ofstream
fout(
"seeds.txt", ofstream::app);
1031 fout << __FILE__ <<
":" << __LINE__ <<
" " <<
name_ <<
"_" 1032 <<
" " << bestTracklet->
getISeed() << endl;
1043 if (!bestTracklet->
fit()) {
1044 static const string invalid =
"0";
1045 streamTrackRaw.emplace_back(invalid);
1046 for (
auto&
stream : streamsStubRaw)
1052 const string phi0 = bestTracklet->
fpgaphi0().
str();
1053 const string z0 = bestTracklet->
fpgaz0().
str();
1054 const string t = bestTracklet->
fpgat().
str();
1055 const int seedType = bestTracklet->
getISeed();
1057 const string valid(
"1");
1058 streamTrackRaw.emplace_back(
valid +
seed +
rinv + phi0 + z0 +
t);
1061 unsigned int ihit(0);
1062 for (
unsigned int ilayer = 0; ilayer <
N_LAYER +
N_DISK; ilayer++) {
1063 if (bestTracklet->
match(ilayer)) {
1070 static constexpr int widthDisk2Sidentifier = 8;
1073 r =
string(widthDisk2Sidentifier,
'0') + r;
1076 streamsStubRaw[ihit++].emplace_back(seedType, *stub,
valid + stubId + r + phi + rz);
1082 streamsStubRaw[ihit++].emplace_back(seedType, *stub0,
valid + stubId0);
1085 streamsStubRaw[ihit++].emplace_back(seedType, *stub1,
valid + stubId1);
1087 while (ihit < streamsStubRaw.size()) {
1088 streamsStubRaw[ihit++].emplace_back();
Log< level::Info, true > LogVerbatim
const FPGAWord & fpgarinv() const
int chisqzfactbits() const
double tdzcorr(int i, int j) const
int nrinvBitsTable() const
unsigned int maxStep(std::string module) const
double z0dzcorr(int i, int j) const
const FPGAWord & r() const
const Residual & resid(unsigned int layerdisk)
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 alphaBitsTable() const
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
const FPGAWord & fpgastubid() const
void addTrack(Tracklet *tracklet)
std::vector< TrackletParametersMemory * > seedtracklet_
const FPGAWord & fpgaphiresid() const
const FPGAWord & fpgaz0() const
unsigned int nbitsseed() const
const FPGAWord & fpgaphi0() const
Settings const & settings_
bool exactderivatives() const
bool exactderivativesforfloating() const
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 >> &)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
const FPGAWord & fpgat() const
void setTrackIndex(int index)
void addOutput(MemoryBase *memory, std::string output) override
int itdzcorr(int i, int j) const
void addStubList(std::vector< const Stub *> stublist)
static std::string to_string(const XMLCh *ch)
int fitz0bitshift() const
static std::string const input
unsigned int isPSmodule() const
TrackFitMemory * trackfit_
std::vector< Tracklet * > orderedMatches(std::vector< FullMatchMemory *> &fullmatch)
std::vector< FullMatchMemory * > fullmatch4_
const FPGAWord & fpgarzresid() const
double phi0approx() const
static double tpar(Settings const &settings, int diskmask, int layermask)
double rmean(unsigned int iLayer) const
double phicritmin() const
const Stub * outerFPGAStub() const
constexpr unsigned int N_TRKLSEED
double stripPitch(bool isPSmodule) const
void addInput(MemoryBase *memory, std::string input) override
void fill(int t, double MinvDt[N_FITPARAM][N_FITSTUB *2], int iMinvDt[N_FITPARAM][N_FITSTUB *2]) const
Abs< T >::type abs(const T &t)
unsigned int nTracks() const
const Stub * middleFPGAStub() const
std::string removalType() const
const TrackDer * getDerivatives(int index) const
std::string const & fitPatternFile() const
const FPGAWord & fpgad0() const
bool writeMonitorData(std::string module) const
double phiresidapprox() const
double zmean(unsigned int iDisk) const
const FPGAWord & stubindex() const
std::vector< FullMatchMemory * > fullmatch1_
double alpha(double pitch) const
bool debugTracklet() const
double rzresidapprox() const
double rinvapprox() const
std::vector< FullMatchMemory * > fullmatch2_
DecomposeProduct< arg, typename Div::arg > D
bool storeTrackBuilderOutput() const
void execute(std::deque< std::string > &streamTrackRaw, std::vector< std::deque< StubStreamData >> &stubStream, unsigned int iSector)
double rinv(double phi1, double phi2, double r1, double r2)
int iz0dzcorr(int i, int j) const
void set(int value, int nbits, bool positive=true, int line=-1, const char *file=nullptr)
constexpr unsigned int N_FITPARAM
void readPatternFile(std::string fileName)
const Stub * stubptr() const
const FPGAWord & alpha() const
bool match(unsigned int layerdisk)
std::ofstream & ofstream(std::string fname)
constexpr unsigned int N_FITSTUB
int fitrinvbitshift() const
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 *>())
double phicritmax() const
int chisqphifactbits() const
TrackDerTable *& trackDerTable()
void addStubidsList(std::vector< std::pair< int, int >> stubidslist)
Log< level::Warning, false > LogWarning
const unsigned int kfactor
void trackFitFake(Tracklet *tracklet, std::vector< const Stub *> &, std::vector< std::pair< int, int >> &)
static constexpr float d1
int fitphi0bitshift() const
std::string const & getName() const
std::vector< FullMatchMemory * > fullmatch3_
constexpr unsigned int N_SEED_PROMPT
const Stub * innerFPGAStub() const