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 bool dupMap[numStublists][numStublists];
189 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
190 for (
unsigned int jtrk = 0; jtrk < numStublists; jtrk++) {
191 dupMap[itrk][jtrk] =
false;
196 bool noMerge[numStublists];
197 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
198 noMerge[itrk] =
false;
203 for (
unsigned int itrk = 0; itrk < numStublists - 1; itrk++) {
204 for (
unsigned int jtrk = itrk + 1; jtrk < numStublists; jtrk++) {
214 unsigned int nShareLay = 0;
217 for (
auto&
i : layerArr) {
220 for (
const auto& st1 : stubsTrk1) {
221 for (
const auto& st2 : stubsTrk2) {
222 if (st1.first == st2.first && st1.second == st2.second) {
226 bool endcapA = (
i > 10);
227 bool endcapB = (
i < 0);
228 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
229 if (!layerArr[lay]) {
231 layerArr[lay] =
true;
241 int layStubidsTrk1[16];
242 int layStubidsTrk2[16];
243 for (
int i = 0;
i < 16;
i++) {
244 layStubidsTrk1[
i] = -1;
245 layStubidsTrk2[
i] = -1;
248 for (
unsigned int stcount = 0; stcount < stubsTrk1.size(); stcount++) {
249 int i = stubsTrk1[stcount].first;
251 bool endcapA = (
i > 10);
252 bool endcapB = (
i < 0);
253 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
256 if (layStubidsTrk1[lay] != -1)
258 if (layStubidsTrk1[lay] == -1 || nres < ores) {
259 layStubidsTrk1[lay] = stcount;
263 for (
unsigned int stcount = 0; stcount < stubsTrk2.size(); stcount++) {
264 int i = stubsTrk2[stcount].first;
266 bool endcapA = (
i > 10);
267 bool endcapB = (
i < 0);
268 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
271 if (layStubidsTrk2[lay] != -1)
273 if (layStubidsTrk2[lay] == -1 || nres < ores) {
274 layStubidsTrk2[lay] = stcount;
278 for (
int i = 0;
i < 16;
i++) {
279 int t1i = layStubidsTrk1[
i];
280 int t2i = layStubidsTrk2[
i];
281 if (t1i != -1 && t2i != -1 && stubsTrk1[t1i].
first == stubsTrk2[t2i].
first &&
289 dupMap[itrk][jtrk] =
true;
290 dupMap[jtrk][itrk] =
true;
296 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
297 for (
unsigned int jtrk = 0; jtrk < numStublists; jtrk++) {
298 if (dupMap[itrk][jtrk]) {
299 noMerge[itrk] =
true;
305 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
306 if (noMerge[itrk] ==
false) {
311 trackInfo[itrk].second =
true;
316 for (
unsigned int itrk = 0; itrk < numStublists - 1; itrk++) {
317 for (
unsigned int jtrk = itrk + 1; jtrk < numStublists; jtrk++) {
319 if (dupMap[itrk][jtrk]) {
323 if (seedRank[itrk] < seedRank[jtrk]) {
336 trackBinInfo[preftrk] =
true;
337 trackBinInfo[rejetrk] =
true;
340 std::vector<const Stub*> newStubList;
343 std::vector<unsigned int> stubsTrk1indices;
344 std::vector<unsigned int> stubsTrk2indices;
345 for (
unsigned int stub1it = 0; stub1it < stubsTrk1.size(); stub1it++) {
346 stubsTrk1indices.push_back(stubsTrk1[stub1it]->l1tstub()->
uniqueIndex());
348 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
349 stubsTrk2indices.push_back(stubsTrk2[stub2it]->l1tstub()->
uniqueIndex());
351 newStubList = stubsTrk1;
352 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
353 if (
find(stubsTrk1indices.begin(), stubsTrk1indices.end(), stubsTrk2indices[stub2it]) ==
354 stubsTrk1indices.end()) {
355 newStubList.push_back(stubsTrk2[stub2it]);
361 std::vector<std::pair<int, int>> newStubidsList;
364 newStubidsList = stubidsTrk1;
366 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
367 if (
find(stubsTrk1indices.begin(), stubsTrk1indices.end(), stubsTrk2indices[stub2it]) ==
368 stubsTrk1indices.end()) {
369 newStubidsList.push_back(stubidsTrk2[stub2it]);
376 trackInfo[rejetrk].second =
true;
382 for (
unsigned int ktrk = 0; ktrk < numStublists; ktrk++) {
383 if ((trackInfo[ktrk].
second !=
true) && (trackBinInfo[ktrk] !=
true)) {
384 prefTracks.push_back(ktrk);
385 prefTrackFit.push_back(trackInfo[ktrk].
first);
396 trackBinInfo.clear();
405 for (
unsigned int itrk = 0; itrk < prefTracks.size(); itrk++) {
406 Tracklet* tracklet = inputtrackletsall[itrk];
407 std::vector<const Stub*> trackstublist = inputstublistsall[itrk];
411 hybridFitter.
Fit(tracklet, trackstublist);
414 if (tracklet->
fit()) {
424 outputtracks.push_back(*outtrack);
437 return lhs->
ichisq() / lhs->
stubID().size() < rhs->ichisq() / rhs->stubID().size();
439 bool grid[35][40] = {{
false}};
441 for (
unsigned int itrk = 0; itrk < numTrk; itrk++) {
443 edm::LogPrint(
"Tracklet") <<
"WARNING: Track already tagged as duplicate!!";
458 if (phiTest < -2 *
M_PI / 27)
460 if (phiTest > 2 * 2 *
M_PI / 27)
469 for (
unsigned int itrk = 0; itrk < numTrk - 1; itrk++) {
475 unsigned int nStubP = 0;
476 vector<unsigned int> nStubS(numTrk);
477 vector<unsigned int> nShare(numTrk);
479 std::map<int, int> stubsTrk1 =
inputtracks_[itrk]->stubID();
480 nStubP = stubsTrk1.size();
482 for (
unsigned int jtrk = itrk + 1; jtrk < numTrk; jtrk++) {
488 std::map<int, int> stubsTrk2 =
inputtracks_[jtrk]->stubID();
489 nStubS[jtrk] = stubsTrk2.size();
492 for (
auto& st : stubsTrk1) {
493 if (stubsTrk2.find(st.first) != stubsTrk2.end()) {
494 if (st.second == stubsTrk2[st.first])
501 for (
unsigned int jtrk = itrk + 1; jtrk < numTrk; jtrk++) {
517 edm::LogVerbatim(
"Tracklet") <<
"Error: Didn't tag either track in duplicate pair.";
526 }
else if ((nStubS[jtrk] - nShare[jtrk] <
settings_.
minIndStubs()) && (nStubS[jtrk] <= nStubP)) {
529 edm::LogVerbatim(
"Tracklet") <<
"Error: Didn't tag either track in duplicate pair.";
545 ofstream
fout(
"seeds.txt", ofstream::app);
546 fout << __FILE__ <<
":" << __LINE__ <<
" " <<
name_ <<
"_" << iSector <<
" " 575 int seedindex = curTracklet->
seedIndex();
584 phires =
std::abs(stubphi - phiproj);
589 if ((seedindex == 0 && (
Layer == 1 ||
Layer == 2)) || (seedindex == 1 && (
Layer == 2 ||
Layer == 3)) ||
590 (seedindex == 2 && (
Layer == 3 ||
Layer == 4)) || (seedindex == 3 && (
Layer == 5 ||
Layer == 6)) ||
604 std::pair<int, int> layer_disk;
606 if (layer_disk.first >
N_LAYER) {
607 layer_disk.first = 0;
610 if (layer_disk.second < 0) {
611 layer_disk.second = 0;
617 std::string thestr = Form(
"\t %s stub info: r/z/phi:\t%f\t%f\t%f\t%d\t%f\t%d",
634 double stub_phi = -99;
638 double tracklet_rinv = tracklet->
rinv();
642 stub_phi = tracklet->
phi0() - std::asin(stub_r * tracklet_rinv / 2);
645 stub_z = tracklet->
z0() + 2 * tracklet->
t() * 1 / tracklet_rinv * std::asin(stub_r * tracklet_rinv / 2);
648 stub_phi = tracklet->
phi0() - (stub_z - tracklet->
z0()) * tracklet_rinv / 2 / tracklet->
t();
651 stub_r = 2 / tracklet_rinv *
std::sin((stub_z - tracklet->
z0()) * tracklet_rinv / 2 / tracklet->
t());
654 std::vector<double> invented_coords{stub_r, stub_z, stub_phi};
655 return invented_coords;
664 double stub_phi = -99;
668 double rho = 1 / tracklet->
rinv();
669 double rho_minus_d0 = rho + tracklet->
d0();
675 double sin_val = (stub_r * stub_r + rho_minus_d0 * rho_minus_d0 - rho * rho) / (2 * stub_r * rho_minus_d0);
676 stub_phi = tracklet->
phi0() - std::asin(sin_val);
680 double beta = std::acos((rho * rho + rho_minus_d0 * rho_minus_d0 - stub_r * stub_r) / (2 * rho * rho_minus_d0));
685 double beta = (stub_z - tracklet->
z0()) / (tracklet->
t() *
std::abs(rho));
686 double r_square = -2 * rho * rho_minus_d0 *
std::cos(
beta) + rho * rho + rho_minus_d0 * rho_minus_d0;
687 stub_r =
sqrt(r_square);
689 double sin_val = (stub_r * stub_r + rho_minus_d0 * rho_minus_d0 - rho * rho) / (2 * stub_r * rho_minus_d0);
690 stub_phi = tracklet->
phi0() - std::asin(sin_val);
698 if ((
seed == 8 && stubLayer == 4) || (
seed == 9 && stubLayer == 5) || (
seed == 10 && stubLayer == 3) ||
699 (
seed == 11 &&
abs(stubDisk) == 1)) {
705 std::vector<double> invented_coords{stub_r, stub_z, stub_phi};
706 return invented_coords;
710 unsigned int iSector,
const Tracklet* tracklet,
const std::vector<const Stub*>& originalStubsList)
const {
711 std::vector<const Stub*> newStubList;
713 for (
unsigned int stubit = 0; stubit < originalStubsList.size(); stubit++) {
714 const Stub* thisStub = originalStubsList[stubit];
718 std::vector<double> inv_r_z_phi;
724 double stub_x_invent = inv_r_z_phi[0] *
std::cos(inv_r_z_phi[2]);
725 double stub_y_invent = inv_r_z_phi[0] *
std::sin(inv_r_z_phi[2]);
726 double stub_z_invent = inv_r_z_phi[1];
728 Stub* invent_stub_ptr =
new Stub(*thisStub);
730 L1TStub invent_l1stub = *l1stub;
731 invent_l1stub.
setCoords(stub_x_invent, stub_y_invent, stub_z_invent);
737 newStubList.push_back(invent_stub_ptr);
740 newStubList.push_back(thisStub);
759 return rinvBins.size() - 2;
760 else if (
bins == rinvBins.begin())
771 double phi0 = trk->
phi0();
774 double phi = phi0 - asin(0.5 *
rinv * rcrit);
796 std::vector<unsigned int> chosenBins;
797 for (
long unsigned int i = 0;
i < rinvBins.size() - 1;
i++) {
798 if ((
rinv < rinvBins[
i + 1] + rinvOverlapSize) && (
rinv > rinvBins[
i] - rinvOverlapSize)) {
799 chosenBins.push_back(
i);
807 double phi0 = trk->
phi0();
810 double phi = phi0 - asin(0.5 *
rinv * rcrit);
815 std::vector<unsigned int> chosenBins;
816 for (
long unsigned int i = 0;
i <
phiBins.size() - 1;
i++) {
817 if ((phi <
phiBins[
i + 1] + phiOverlapSize) && (phi >
phiBins[
i] - phiOverlapSize)) {
818 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