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;
140 << __FILE__ <<
" " << __LINE__ <<
" Number of stublists and tracks don't match up! ";
151 std::vector<std::pair<int, int>> stubidslist =
inputtrackfits_[
i]->getStubidslist(
j);
159 unsigned int curSeed = aTrack->
seedIndex();
160 std::vector<int> ranks{1, 5, 2, 7, 4, 3, 8, 6};
162 seedRank.push_back(9);
164 seedRank.push_back(ranks[curSeed]);
166 if (stublist.size() != stubidslist.size())
168 << __FILE__ <<
" " << __LINE__ <<
" Number of stubs and stubids don't match up! ";
170 trackInfo.emplace_back(
i,
false);
171 trackBinInfo.emplace_back(
false);
182 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
188 vector<vector<bool>> dupMap(numStublists, vector<bool>(numStublists,
false));
191 vector<bool> noMerge(numStublists,
false);
195 for (
unsigned int itrk = 0; itrk < numStublists - 1; itrk++) {
196 for (
unsigned int jtrk = itrk + 1; jtrk < numStublists; jtrk++) {
206 unsigned int nShareLay = 0;
209 for (
auto&
i : layerArr) {
212 for (
const auto& st1 : stubsTrk1) {
213 for (
const auto& st2 : stubsTrk2) {
214 if (st1.first == st2.first && st1.second == st2.second) {
218 bool endcapA = (
i > 10);
219 bool endcapB = (
i < 0);
220 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
221 if (!layerArr[lay]) {
223 layerArr[lay] =
true;
233 int layStubidsTrk1[16];
234 int layStubidsTrk2[16];
235 for (
int i = 0;
i < 16;
i++) {
236 layStubidsTrk1[
i] = -1;
237 layStubidsTrk2[
i] = -1;
240 for (
unsigned int stcount = 0; stcount < stubsTrk1.size(); stcount++) {
241 int i = stubsTrk1[stcount].first;
243 bool endcapA = (
i > 10);
244 bool endcapB = (
i < 0);
245 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
248 if (layStubidsTrk1[lay] != -1)
250 if (layStubidsTrk1[lay] == -1 || nres < ores) {
251 layStubidsTrk1[lay] = stcount;
255 for (
unsigned int stcount = 0; stcount < stubsTrk2.size(); stcount++) {
256 int i = stubsTrk2[stcount].first;
258 bool endcapA = (
i > 10);
259 bool endcapB = (
i < 0);
260 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
263 if (layStubidsTrk2[lay] != -1)
265 if (layStubidsTrk2[lay] == -1 || nres < ores) {
266 layStubidsTrk2[lay] = stcount;
270 for (
int i = 0;
i < 16;
i++) {
271 int t1i = layStubidsTrk1[
i];
272 int t2i = layStubidsTrk2[
i];
273 if (t1i != -1 && t2i != -1 && stubsTrk1[t1i].
first == stubsTrk2[t2i].
first &&
281 dupMap.at(itrk).at(jtrk) =
true;
282 dupMap.at(jtrk).at(itrk) =
true;
288 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
289 for (
unsigned int jtrk = 0; jtrk < numStublists; jtrk++) {
290 if (dupMap.at(itrk).at(jtrk)) {
291 noMerge.at(itrk) =
true;
297 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
298 if (!noMerge.at(itrk)) {
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.at(itrk).at(jtrk)) {
315 if (seedRank[itrk] < seedRank[jtrk]) {
328 trackBinInfo[preftrk] =
true;
329 trackBinInfo[rejetrk] =
true;
332 std::vector<const Stub*> newStubList;
335 std::vector<unsigned int> stubsTrk1indices;
336 std::vector<unsigned int> stubsTrk2indices;
337 for (
unsigned int stub1it = 0; stub1it < stubsTrk1.size(); stub1it++) {
338 stubsTrk1indices.push_back(stubsTrk1[stub1it]->l1tstub()->
uniqueIndex());
340 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
341 stubsTrk2indices.push_back(stubsTrk2[stub2it]->l1tstub()->
uniqueIndex());
343 newStubList = stubsTrk1;
344 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
345 if (
find(stubsTrk1indices.begin(), stubsTrk1indices.end(), stubsTrk2indices[stub2it]) ==
346 stubsTrk1indices.end()) {
347 newStubList.push_back(stubsTrk2[stub2it]);
353 std::vector<std::pair<int, int>> newStubidsList;
356 newStubidsList = stubidsTrk1;
358 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
359 if (
find(stubsTrk1indices.begin(), stubsTrk1indices.end(), stubsTrk2indices[stub2it]) ==
360 stubsTrk1indices.end()) {
361 newStubidsList.push_back(stubidsTrk2[stub2it]);
368 trackInfo[rejetrk].second =
true;
374 for (
unsigned int ktrk = 0; ktrk < numStublists; ktrk++) {
375 if ((trackInfo[ktrk].
second !=
true) && (trackBinInfo[ktrk] !=
true)) {
376 prefTracks.push_back(ktrk);
377 prefTrackFit.push_back(trackInfo[ktrk].
first);
388 trackBinInfo.clear();
397 for (
unsigned int itrk = 0; itrk < prefTracks.size(); itrk++) {
398 Tracklet* tracklet = inputtrackletsall[itrk];
399 std::vector<const Stub*> trackstublist = inputstublistsall[itrk];
403 hybridFitter.
Fit(tracklet, trackstublist);
406 if (tracklet->
fit()) {
416 outputtracks.push_back(*outtrack);
429 return lhs->
ichisq() / lhs->
stubID().size() < rhs->ichisq() / rhs->stubID().size();
431 bool grid[35][40] = {{
false}};
433 for (
unsigned int itrk = 0; itrk < numTrk; itrk++) {
435 edm::LogPrint(
"Tracklet") <<
"WARNING: Track already tagged as duplicate!!";
450 if (phiTest < -2 *
M_PI / 27)
452 if (phiTest > 2 * 2 *
M_PI / 27)
461 for (
unsigned int itrk = 0; itrk < numTrk - 1; itrk++) {
467 unsigned int nStubP = 0;
468 vector<unsigned int> nStubS(numTrk);
469 vector<unsigned int> nShare(numTrk);
471 std::map<int, int> stubsTrk1 =
inputtracks_[itrk]->stubID();
472 nStubP = stubsTrk1.size();
474 for (
unsigned int jtrk = itrk + 1; jtrk < numTrk; jtrk++) {
480 std::map<int, int> stubsTrk2 =
inputtracks_[jtrk]->stubID();
481 nStubS[jtrk] = stubsTrk2.size();
484 for (
auto& st : stubsTrk1) {
485 if (stubsTrk2.find(st.first) != stubsTrk2.end()) {
486 if (st.second == stubsTrk2[st.first])
493 for (
unsigned int jtrk = itrk + 1; jtrk < numTrk; jtrk++) {
509 edm::LogVerbatim(
"Tracklet") <<
"Error: Didn't tag either track in duplicate pair.";
518 }
else if ((nStubS[jtrk] - nShare[jtrk] <
settings_.
minIndStubs()) && (nStubS[jtrk] <= nStubP)) {
521 edm::LogVerbatim(
"Tracklet") <<
"Error: Didn't tag either track in duplicate pair.";
537 ofstream
fout(
"seeds.txt", ofstream::app);
538 fout << __FILE__ <<
":" << __LINE__ <<
" " <<
name_ <<
"_" << iSector <<
" " 567 int seedindex = curTracklet->
seedIndex();
576 phires =
std::abs(stubphi - phiproj);
581 if ((seedindex == 0 && (
Layer == 1 ||
Layer == 2)) || (seedindex == 1 && (
Layer == 2 ||
Layer == 3)) ||
582 (seedindex == 2 && (
Layer == 3 ||
Layer == 4)) || (seedindex == 3 && (
Layer == 5 ||
Layer == 6)) ||
596 std::pair<int, int> layer_disk;
598 if (layer_disk.first >
N_LAYER) {
599 layer_disk.first = 0;
602 if (layer_disk.second < 0) {
603 layer_disk.second = 0;
609 std::string thestr = Form(
"\t %s stub info: r/z/phi:\t%f\t%f\t%f\t%d\t%f\t%d",
626 double stub_phi = -99;
630 double tracklet_rinv = tracklet->
rinv();
634 stub_phi = tracklet->
phi0() - std::asin(stub_r * tracklet_rinv / 2);
637 stub_z = tracklet->
z0() + 2 * tracklet->
t() * 1 / tracklet_rinv * std::asin(stub_r * tracklet_rinv / 2);
640 stub_phi = tracklet->
phi0() - (stub_z - tracklet->
z0()) * tracklet_rinv / 2 / tracklet->
t();
643 stub_r = 2 / tracklet_rinv *
std::sin((stub_z - tracklet->
z0()) * tracklet_rinv / 2 / tracklet->
t());
646 std::vector<double> invented_coords{stub_r, stub_z, stub_phi};
647 return invented_coords;
656 double stub_phi = -99;
660 double rho = 1 / tracklet->
rinv();
661 double rho_minus_d0 = rho + tracklet->
d0();
667 double sin_val = (stub_r * stub_r + rho_minus_d0 * rho_minus_d0 - rho * rho) / (2 * stub_r * rho_minus_d0);
668 stub_phi = tracklet->
phi0() - std::asin(sin_val);
672 double beta = std::acos((rho * rho + rho_minus_d0 * rho_minus_d0 - stub_r * stub_r) / (2 * rho * rho_minus_d0));
677 double beta = (stub_z - tracklet->
z0()) / (tracklet->
t() *
std::abs(rho));
678 double r_square = -2 * rho * rho_minus_d0 *
std::cos(
beta) + rho * rho + rho_minus_d0 * rho_minus_d0;
679 stub_r =
sqrt(r_square);
681 double sin_val = (stub_r * stub_r + rho_minus_d0 * rho_minus_d0 - rho * rho) / (2 * stub_r * rho_minus_d0);
682 stub_phi = tracklet->
phi0() - std::asin(sin_val);
690 if ((
seed == 8 && stubLayer == 4) || (
seed == 9 && stubLayer == 5) || (
seed == 10 && stubLayer == 3) ||
691 (
seed == 11 &&
abs(stubDisk) == 1)) {
697 std::vector<double> invented_coords{stub_r, stub_z, stub_phi};
698 return invented_coords;
702 unsigned int iSector,
const Tracklet* tracklet,
const std::vector<const Stub*>& originalStubsList)
const {
703 std::vector<const Stub*> newStubList;
705 for (
unsigned int stubit = 0; stubit < originalStubsList.size(); stubit++) {
706 const Stub* thisStub = originalStubsList[stubit];
710 std::vector<double> inv_r_z_phi;
716 double stub_x_invent = inv_r_z_phi[0] *
std::cos(inv_r_z_phi[2]);
717 double stub_y_invent = inv_r_z_phi[0] *
std::sin(inv_r_z_phi[2]);
718 double stub_z_invent = inv_r_z_phi[1];
720 Stub* invent_stub_ptr =
new Stub(*thisStub);
722 L1TStub invent_l1stub = *l1stub;
723 invent_l1stub.
setCoords(stub_x_invent, stub_y_invent, stub_z_invent);
729 newStubList.push_back(invent_stub_ptr);
732 newStubList.push_back(thisStub);
751 return rinvBins.size() - 2;
752 else if (
bins == rinvBins.begin())
763 double phi0 = trk->
phi0();
766 double phi = phi0 - asin(0.5 *
rinv * rcrit);
788 std::vector<unsigned int> chosenBins;
789 for (
long unsigned int i = 0;
i < rinvBins.size() - 1;
i++) {
790 if ((
rinv < rinvBins[
i + 1] + rinvOverlapSize) && (
rinv > rinvBins[
i] - rinvOverlapSize)) {
791 chosenBins.push_back(
i);
799 double phi0 = trk->
phi0();
802 double phi = phi0 - asin(0.5 *
rinv * rcrit);
807 std::vector<unsigned int> chosenBins;
808 for (
long unsigned int i = 0;
i <
phiBins.size() - 1;
i++) {
809 if ((phi <
phiBins[
i + 1] + phiOverlapSize) && (phi >
phiBins[
i] - phiOverlapSize)) {
810 chosenBins.push_back(
i);
Log< level::Info, true > LogVerbatim
unsigned int seedIndex() const
unsigned int maxStep(std::string module) const
constexpr T reduceRange(T x)
double rinvOverlapSize() const
std::vector< std::vector< std::pair< int, int > > > inputstubidslists_
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_
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_
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
const std::vector< double > & phiBins() const
std::vector< double > getInventedCoordsExtended(unsigned int, const Stub *, const Tracklet *) const
std::vector< unsigned int > findOverlapPhiBins(const Tracklet *trk) const
double dphisector() const
double rmean(unsigned int iLayer) const
unsigned int findPhiBin(const Tracklet *trk) const
double phiOverlapSize() const
Cos< T >::type cos(const T &t)
void execute(std::vector< Track > &outputtracks, unsigned int iSector)
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)
std::vector< unsigned int > findOverlapRinvBins(const Tracklet *trk) const
double rinv(double phi1, double phi2, double r1, double r2)
void addInput(MemoryBase *memory, std::string input) override
void setCoords(double x, double y, double z)
unsigned int findRinvBin(const Tracklet *trk) const
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)
const std::vector< double > & rinvBins() const
std::string l1tinfo(const L1TStub *, std::string) const
bool isSeedingStub(int, int, int) 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