19 #include <unordered_set> 33 unordered_set<string>
outputs = {
"trackout",
51 throw cms::Exception(
"BadConfig") << __FILE__ <<
" " << __LINE__ <<
" could not find output: " <<
output;
59 unordered_set<string>
inputs = {
"trackin",
78 throw cms::Exception(
"BadConfig") << __FILE__ <<
" " << __LINE__ <<
" could not find input: " <<
input;
91 if (inputtrackfit->nTracks() == 0)
93 for (
unsigned int j = 0;
j < inputtrackfit->nTracks();
j++) {
94 Track* aTrack = inputtrackfit->getTrack(
j)->getTrack();
112 std::vector<std::pair<int, bool>> trackInfo;
114 std::vector<bool> trackBinInfo;
116 std::vector<int> seedRank;
119 std::vector<std::vector<const Stub*>> inputstublistsall;
121 std::vector<std::vector<std::pair<int, int>>> mergedstubidslistsall;
122 std::vector<std::vector<std::pair<int, int>>> inputstubidslistsall;
123 std::vector<Tracklet*> inputtrackletsall;
125 std::vector<unsigned int> prefTracks;
126 std::vector<int> prefTrackFit;
138 throw "Number of stublists and tracks don't match up!";
147 std::vector<std::pair<int, int>> stubidslist =
inputtrackfits_[
i]->getStubidslist(
j);
155 unsigned int curSeed = aTrack->
seedIndex();
156 std::vector<int> ranks{1, 5, 2, 7, 4, 3, 8, 6};
158 seedRank.push_back(9);
160 seedRank.push_back(ranks[curSeed]);
162 if (stublist.size() != stubidslist.size())
163 throw "Number of stubs and stubids don't match up!";
165 trackInfo.emplace_back(
i,
false);
166 trackBinInfo.emplace_back(
false);
177 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
183 bool dupMap[numStublists][numStublists];
184 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
185 for (
unsigned int jtrk = 0; jtrk < numStublists; jtrk++) {
186 dupMap[itrk][jtrk] =
false;
191 bool noMerge[numStublists];
192 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
193 noMerge[itrk] =
false;
198 for (
unsigned int itrk = 0; itrk < numStublists - 1; itrk++) {
199 for (
unsigned int jtrk = itrk + 1; jtrk < numStublists; jtrk++) {
209 unsigned int nShareLay = 0;
212 for (
auto&
i : layerArr) {
215 for (
const auto& st1 : stubsTrk1) {
216 for (
const auto& st2 : stubsTrk2) {
217 if (st1.first == st2.first && st1.second == st2.second) {
221 bool endcapA = (
i > 10);
222 bool endcapB = (
i < 0);
223 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
224 if (!layerArr[lay]) {
226 layerArr[lay] =
true;
236 int layStubidsTrk1[16];
237 int layStubidsTrk2[16];
238 for (
int i = 0;
i < 16;
i++) {
239 layStubidsTrk1[
i] = -1;
240 layStubidsTrk2[
i] = -1;
243 for (
unsigned int stcount = 0; stcount < stubsTrk1.size(); stcount++) {
244 int i = stubsTrk1[stcount].first;
246 bool endcapA = (
i > 10);
247 bool endcapB = (
i < 0);
248 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
251 if (layStubidsTrk1[lay] != -1)
253 if (layStubidsTrk1[lay] == -1 || nres < ores) {
254 layStubidsTrk1[lay] = stcount;
258 for (
unsigned int stcount = 0; stcount < stubsTrk2.size(); stcount++) {
259 int i = stubsTrk2[stcount].first;
261 bool endcapA = (
i > 10);
262 bool endcapB = (
i < 0);
263 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
266 if (layStubidsTrk2[lay] != -1)
268 if (layStubidsTrk2[lay] == -1 || nres < ores) {
269 layStubidsTrk2[lay] = stcount;
273 for (
int i = 0;
i < 16;
i++) {
274 int t1i = layStubidsTrk1[
i];
275 int t2i = layStubidsTrk2[
i];
276 if (t1i != -1 && t2i != -1 && stubsTrk1[t1i].
first == stubsTrk2[t2i].
first &&
283 dupMap[itrk][jtrk] =
true;
284 dupMap[jtrk][itrk] =
true;
290 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
291 for (
unsigned int jtrk = 0; jtrk < numStublists; jtrk++) {
292 if (dupMap[itrk][jtrk]) {
293 noMerge[itrk] =
true;
299 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
300 if (noMerge[itrk] ==
false) {
303 trackInfo[itrk].second =
true;
308 for (
unsigned int itrk = 0; itrk < numStublists - 1; itrk++) {
309 for (
unsigned int jtrk = itrk + 1; jtrk < numStublists; jtrk++) {
311 if (dupMap[itrk][jtrk]) {
315 if (seedRank[itrk] < seedRank[jtrk]) {
326 trackBinInfo[preftrk] =
true;
327 trackBinInfo[rejetrk] =
true;
330 std::vector<const Stub*> newStubList;
333 std::vector<unsigned int> stubsTrk1indices;
334 std::vector<unsigned int> stubsTrk2indices;
335 for (
unsigned int stub1it = 0; stub1it < stubsTrk1.size(); stub1it++) {
336 stubsTrk1indices.push_back(stubsTrk1[stub1it]->l1tstub()->
uniqueIndex());
338 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
339 stubsTrk2indices.push_back(stubsTrk2[stub2it]->l1tstub()->
uniqueIndex());
341 newStubList = stubsTrk1;
342 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
343 if (
find(stubsTrk1indices.begin(), stubsTrk1indices.end(), stubsTrk2indices[stub2it]) ==
344 stubsTrk1indices.end()) {
345 newStubList.push_back(stubsTrk2[stub2it]);
351 std::vector<std::pair<int, int>> newStubidsList;
354 newStubidsList = stubidsTrk1;
356 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
357 if (
find(stubsTrk1indices.begin(), stubsTrk1indices.end(), stubsTrk2indices[stub2it]) ==
358 stubsTrk1indices.end()) {
359 newStubidsList.push_back(stubidsTrk2[stub2it]);
366 trackInfo[rejetrk].second =
true;
372 for (
unsigned int ktrk = 0; ktrk < numStublists; ktrk++) {
373 if ((trackInfo[ktrk].
second !=
true) && (trackBinInfo[ktrk] !=
true)) {
374 prefTracks.push_back(ktrk);
375 prefTrackFit.push_back(trackInfo[ktrk].
first);
386 trackBinInfo.clear();
394 for (
unsigned int itrk = 0; itrk < prefTracks.size(); itrk++) {
395 Tracklet* tracklet = inputtrackletsall[itrk];
396 std::vector<const Stub*> trackstublist = inputstublistsall[itrk];
400 hybridFitter.
Fit(tracklet, trackstublist);
403 if (tracklet->
fit()) {
413 outputtracks_.push_back(*outtrack);
426 return lhs->
ichisq() / lhs->
stubID().size() < rhs->ichisq() / rhs->stubID().size();
428 bool grid[35][40] = {{
false}};
430 for (
unsigned int itrk = 0; itrk < numTrk; itrk++) {
432 edm::LogPrint(
"Tracklet") <<
"WARNING: Track already tagged as duplicate!!";
447 if (phiTest < -2 *
M_PI / 27)
449 if (phiTest > 2 * 2 *
M_PI / 27)
458 for (
unsigned int itrk = 0; itrk < numTrk - 1; itrk++) {
464 unsigned int nStubP = 0;
465 vector<unsigned int> nStubS(numTrk);
466 vector<unsigned int> nShare(numTrk);
468 std::map<int, int> stubsTrk1 =
inputtracks_[itrk]->stubID();
469 nStubP = stubsTrk1.size();
471 for (
unsigned int jtrk = itrk + 1; jtrk < numTrk; jtrk++) {
477 std::map<int, int> stubsTrk2 =
inputtracks_[jtrk]->stubID();
478 nStubS[jtrk] = stubsTrk2.size();
481 for (
auto& st : stubsTrk1) {
482 if (stubsTrk2.find(st.first) != stubsTrk2.end()) {
483 if (st.second == stubsTrk2[st.first])
490 for (
unsigned int jtrk = itrk + 1; jtrk < numTrk; jtrk++) {
506 edm::LogVerbatim(
"Tracklet") <<
"Error: Didn't tag either track in duplicate pair.";
515 }
else if ((nStubS[jtrk] - nShare[jtrk] <
settings_.
minIndStubs()) && (nStubS[jtrk] <= nStubP)) {
518 edm::LogVerbatim(
"Tracklet") <<
"Error: Didn't tag either track in duplicate pair.";
534 ofstream
fout(
"seeds.txt", ofstream::app);
535 fout << __FILE__ <<
":" << __LINE__ <<
" " <<
name_ <<
"_" << iSector <<
" " 564 int seedindex = curTracklet->
seedIndex();
573 phires =
std::abs(stubphi - phiproj);
578 if ((seedindex == 0 && (
Layer == 1 ||
Layer == 2)) || (seedindex == 1 && (
Layer == 2 ||
Layer == 3)) ||
579 (seedindex == 2 && (
Layer == 3 ||
Layer == 4)) || (seedindex == 3 && (
Layer == 5 ||
Layer == 6)) ||
593 std::pair<int, int> layer_disk;
595 if (layer_disk.first >
N_LAYER) {
596 layer_disk.first = 0;
599 if (layer_disk.second < 0) {
600 layer_disk.second = 0;
606 std::string thestr = Form(
"\t %s stub info: r/z/phi:\t%f\t%f\t%f\t%d\t%f\t%d",
623 double stub_phi = -99;
627 double tracklet_rinv = tracklet->
rinv();
631 stub_phi = tracklet->
phi0() - std::asin(stub_r * tracklet_rinv / 2);
634 stub_z = tracklet->
z0() + 2 * tracklet->
t() * 1 / tracklet_rinv * std::asin(stub_r * tracklet_rinv / 2);
637 stub_phi = tracklet->
phi0() - (stub_z - tracklet->
z0()) * tracklet_rinv / 2 / tracklet->
t();
640 stub_r = 2 / tracklet_rinv *
std::sin((stub_z - tracklet->
z0()) * tracklet_rinv / 2 / tracklet->
t());
643 std::vector invented_coords{stub_r, stub_z, stub_phi};
644 return invented_coords;
653 double stub_phi = -99;
657 double rho = 1 / tracklet->
rinv();
658 double rho_minus_d0 = rho + tracklet->
d0();
664 double sin_val = (stub_r * stub_r + rho_minus_d0 * rho_minus_d0 - rho * rho) / (2 * stub_r * rho_minus_d0);
665 stub_phi = tracklet->
phi0() - std::asin(sin_val);
669 double beta = std::acos((rho * rho + rho_minus_d0 * rho_minus_d0 - stub_r * stub_r) / (2 * rho * rho_minus_d0));
674 double beta = (stub_z - tracklet->
z0()) / (tracklet->
t() *
std::abs(rho));
675 double r_square = -2 * rho * rho_minus_d0 *
std::cos(
beta) + rho * rho + rho_minus_d0 * rho_minus_d0;
676 stub_r =
sqrt(r_square);
678 double sin_val = (stub_r * stub_r + rho_minus_d0 * rho_minus_d0 - rho * rho) / (2 * stub_r * rho_minus_d0);
679 stub_phi = tracklet->
phi0() - std::asin(sin_val);
687 if ((
seed == 8 && stubLayer == 4) || (
seed == 9 && stubLayer == 5) || (
seed == 10 && stubLayer == 3) ||
688 (
seed == 11 &&
abs(stubDisk) == 1)) {
694 std::vector invented_coords{stub_r, stub_z, stub_phi};
695 return invented_coords;
699 unsigned int iSector,
const Tracklet* tracklet,
const std::vector<const Stub*>& originalStubsList)
const {
700 std::vector<const Stub*> newStubList;
702 for (
unsigned int stubit = 0; stubit < originalStubsList.size(); stubit++) {
703 const Stub* thisStub = originalStubsList[stubit];
707 std::vector<double> inv_r_z_phi;
713 double stub_x_invent = inv_r_z_phi[0] *
std::cos(inv_r_z_phi[2]);
714 double stub_y_invent = inv_r_z_phi[0] *
std::sin(inv_r_z_phi[2]);
715 double stub_z_invent = inv_r_z_phi[1];
717 Stub* invent_stub_ptr =
new Stub(*thisStub);
719 L1TStub invent_l1stub = *l1stub;
720 invent_l1stub.
setCoords(stub_x_invent, stub_y_invent, stub_z_invent);
726 newStubList.push_back(invent_stub_ptr);
729 newStubList.push_back(thisStub);
740 double rInv = trk->
rinv();
748 return rInvBins.size() - 2;
749 else if (
bins == rInvBins.begin())
757 double rInv = trk->
rinv();
760 std::vector<unsigned int> chosenBins;
761 for (
long unsigned int i = 0;
i < varRInvBins.size() - 1;
i++) {
762 if ((rInv < varRInvBins[
i + 1] + overlapSize) && (rInv > varRInvBins[
i] - overlapSize)) {
763 chosenBins.push_back(
i);
Log< level::Info, true > LogVerbatim
unsigned int seedIndex() const
double overlapSize() const
unsigned int maxStep(std::string module) const
constexpr T reduceRange(T x)
std::vector< std::vector< std::pair< int, int > > > inputstubidslists_
void execute(std::vector< Track > &outputtracks_, unsigned int iSector)
double dphisectorHG() const
Sin< T >::type sin(const T &t)
void Fit(Tracklet *tracklet, std::vector< const Stub *> &trackstublist)
Projection & proj(int layerdisk)
Settings const & settings_
double getPhiRes(Tracklet *curTracklet, const Stub *curStub) const
std::vector< CleanTrackMemory * > outputtracklets_
std::vector< unsigned int > findOverlapRInvBins(const Tracklet *trk) const
unsigned int minIndStubs() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< Track * > inputtracks_
unsigned int findVarRInvBin(const Tracklet *trk) const
static std::string const input
SeedingLayerSetsHits::SeedingLayer Layer
U second(std::pair< T, U > const &p)
std::vector< double > getInventedCoords(unsigned int, const Stub *, const Tracklet *) const
std::vector< double > getInventedCoordsExtended(unsigned int, const Stub *, const Tracklet *) const
double dphisector() const
double rmean(unsigned int iLayer) const
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
unsigned int numTracksComparedPerBin() const
std::string removalType() const
std::vector< TrackFitMemory * > inputtrackfits_
bool writeMonitorData(std::string module) const
unsigned int layerdisk() const
void setUniqueIndex(unsigned int index)
double zmean(unsigned int iDisk) const
unsigned int allStubIndex() const
bool isTrackInBin(const std::vector< unsigned int > &vec, unsigned int num) const
std::pair< int, int > findLayerDisk(const Stub *) const
static const TrackGhostTrackState * getTrack(const BasicGhostTrackState *basic)
void addInput(MemoryBase *memory, std::string input) override
void setCoords(double x, double y, double z)
std::vector< Tracklet * > inputtracklets_
std::vector< std::vector< std::pair< int, int > > > mergedstubidslists_
std::string mergeComparison() const
void addOutput(MemoryBase *memory, std::string output) override
std::vector< const Stub * > getInventedSeedingStub(unsigned int, const Tracklet *, const std::vector< const Stub *> &) const
void setl1tstub(L1TStub *l1tstub)
void setAllStubIndex(unsigned int index)
std::vector< std::vector< const Stub * > > inputstublists_
unsigned int iphi() const
int uniqueIndex(int eta, int phi)
std::string l1tinfo(const L1TStub *, std::string) const
bool isSeedingStub(int, int, int) const
const std::vector< double > varRInvBins() const
void setStubIDprefit(std::vector< std::pair< int, int >> stubIDprefit)
const std::map< int, int > & stubID() const
void setStubIDpremerge(std::vector< std::pair< int, int >> stubIDpremerge)
unsigned int uniqueIndex() const