21 #include <unordered_set> 35 unordered_set<string>
outputs = {
"trackout",
53 throw cms::Exception(
"BadConfig") << __FILE__ <<
" " << __LINE__ <<
" could not find output: " <<
output;
61 unordered_set<string>
inputs = {
"trackin",
80 throw cms::Exception(
"BadConfig") << __FILE__ <<
" " << __LINE__ <<
" could not find input: " <<
input;
93 if (inputtrackfit->nTracks() == 0)
95 for (
unsigned int j = 0;
j < inputtrackfit->nTracks();
j++) {
96 Track* aTrack = inputtrackfit->getTrack(
j)->getTrack();
114 std::vector<std::pair<int, bool>> trackInfo;
116 std::vector<bool> trackBinInfo;
118 std::vector<int> seedRank;
121 std::vector<std::vector<const Stub*>> inputstublistsall;
123 std::vector<std::vector<std::pair<int, int>>> mergedstubidslistsall;
124 std::vector<std::vector<std::pair<int, int>>> inputstubidslistsall;
125 std::vector<Tracklet*> inputtrackletsall;
127 std::vector<unsigned int> prefTracks;
128 std::vector<int> prefTrackFit;
142 << __FILE__ <<
" " << __LINE__ <<
" Number of stublists and tracks don't match up! ";
153 std::vector<std::pair<int, int>> stubidslist =
inputtrackfits_[
i]->getStubidslist(
j);
161 const unsigned int curSeed = aTrack->
seedIndex();
162 static const std::vector<int> ranks{1, 5, 2, 7, 4, 3, 8, 6};
163 if (curSeed < ranks.size()) {
164 seedRank.push_back(ranks[curSeed]);
166 seedRank.push_back(9);
168 throw cms::Exception(
"LogError") << __FILE__ <<
" " << __LINE__ <<
" Seed type " << curSeed
169 <<
" not found in list, and settings->extended() not set.";
172 if (stublist.size() != stubidslist.size())
174 << __FILE__ <<
" " << __LINE__ <<
" Number of stubs and stubids don't match up! ";
176 trackInfo.emplace_back(
i,
false);
177 trackBinInfo.emplace_back(
false);
188 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
194 vector<vector<bool>> dupMap(numStublists, vector<bool>(numStublists,
false));
197 vector<bool> noMerge(numStublists,
false);
201 for (
unsigned int itrk = 0; itrk < numStublists - 1; itrk++) {
202 for (
unsigned int jtrk = itrk + 1; jtrk < numStublists; jtrk++) {
212 unsigned int nShareLay = 0;
215 for (
auto&
i : layerArr) {
218 for (
const auto& st1 : stubsTrk1) {
219 for (
const auto& st2 : stubsTrk2) {
220 if (st1.first == st2.first && st1.second == st2.second) {
224 bool endcapA = (
i > 10);
225 bool endcapB = (
i < 0);
226 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
227 if (!layerArr[lay]) {
229 layerArr[lay] =
true;
239 int layStubidsTrk1[16];
240 int layStubidsTrk2[16];
241 for (
int i = 0;
i < 16;
i++) {
242 layStubidsTrk1[
i] = -1;
243 layStubidsTrk2[
i] = -1;
246 for (
unsigned int stcount = 0; stcount < stubsTrk1.size(); stcount++) {
247 int i = stubsTrk1[stcount].first;
249 bool endcapA = (
i > 10);
250 bool endcapB = (
i < 0);
251 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
254 if (layStubidsTrk1[lay] != -1)
256 if (layStubidsTrk1[lay] == -1 || nres < ores) {
257 layStubidsTrk1[lay] = stcount;
261 for (
unsigned int stcount = 0; stcount < stubsTrk2.size(); stcount++) {
262 int i = stubsTrk2[stcount].first;
264 bool endcapA = (
i > 10);
265 bool endcapB = (
i < 0);
266 int lay =
barrel * (
i - 1) + endcapA * (
i - 5) - endcapB *
i;
269 if (layStubidsTrk2[lay] != -1)
271 if (layStubidsTrk2[lay] == -1 || nres < ores) {
272 layStubidsTrk2[lay] = stcount;
276 for (
int i = 0;
i < 16;
i++) {
277 int t1i = layStubidsTrk1[
i];
278 int t2i = layStubidsTrk2[
i];
279 if (t1i != -1 && t2i != -1 && stubsTrk1[t1i].
first == stubsTrk2[t2i].
first &&
287 dupMap.at(itrk).at(jtrk) =
true;
288 dupMap.at(jtrk).at(itrk) =
true;
294 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
295 for (
unsigned int jtrk = 0; jtrk < numStublists; jtrk++) {
296 if (dupMap.at(itrk).at(jtrk)) {
297 noMerge.at(itrk) =
true;
303 for (
unsigned int itrk = 0; itrk < numStublists; itrk++) {
304 if (!noMerge.at(itrk)) {
309 trackInfo[itrk].second =
true;
314 for (
unsigned int itrk = 0; itrk < numStublists - 1; itrk++) {
315 for (
unsigned int jtrk = itrk + 1; jtrk < numStublists; jtrk++) {
317 if (dupMap.at(itrk).at(jtrk)) {
321 if (seedRank[itrk] < seedRank[jtrk]) {
334 trackBinInfo[preftrk] =
true;
335 trackBinInfo[rejetrk] =
true;
338 std::vector<const Stub*> newStubList;
341 std::vector<unsigned int> stubsTrk1indices;
342 std::vector<unsigned int> stubsTrk2indices;
343 for (
unsigned int stub1it = 0; stub1it < stubsTrk1.size(); stub1it++) {
344 stubsTrk1indices.push_back(stubsTrk1[stub1it]->l1tstub()->
uniqueIndex());
346 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
347 stubsTrk2indices.push_back(stubsTrk2[stub2it]->l1tstub()->
uniqueIndex());
349 newStubList = stubsTrk1;
350 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
351 if (
find(stubsTrk1indices.begin(), stubsTrk1indices.end(), stubsTrk2indices[stub2it]) ==
352 stubsTrk1indices.end()) {
353 newStubList.push_back(stubsTrk2[stub2it]);
359 std::vector<std::pair<int, int>> newStubidsList;
362 newStubidsList = stubidsTrk1;
364 for (
unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) {
365 if (
find(stubsTrk1indices.begin(), stubsTrk1indices.end(), stubsTrk2indices[stub2it]) ==
366 stubsTrk1indices.end()) {
367 newStubidsList.push_back(stubidsTrk2[stub2it]);
374 trackInfo[rejetrk].second =
true;
380 for (
unsigned int ktrk = 0; ktrk < numStublists; ktrk++) {
381 if ((trackInfo[ktrk].
second !=
true) && (trackBinInfo[ktrk] !=
true)) {
382 prefTracks.push_back(ktrk);
383 prefTrackFit.push_back(trackInfo[ktrk].
first);
394 trackBinInfo.clear();
403 for (
unsigned int itrk = 0; itrk < prefTracks.size(); itrk++) {
404 Tracklet* tracklet = inputtrackletsall[itrk];
405 std::vector<const Stub*> trackstublist = inputstublistsall[itrk];
409 hybridFitter.
Fit(tracklet, trackstublist);
412 if (tracklet->
fit()) {
422 outputtracks.push_back(*outtrack);
435 return lhs->
ichisq() / lhs->
stubID().size() < rhs->ichisq() / rhs->stubID().size();
437 bool grid[35][40] = {{
false}};
439 for (
unsigned int itrk = 0; itrk < numTrk; itrk++) {
441 edm::LogPrint(
"Tracklet") <<
"WARNING: Track already tagged as duplicate!!";
456 if (phiTest < -2 *
M_PI / 27)
458 if (phiTest > 2 * 2 *
M_PI / 27)
467 for (
unsigned int itrk = 0; itrk < numTrk - 1; itrk++) {
473 unsigned int nStubP = 0;
474 vector<unsigned int> nStubS(numTrk);
475 vector<unsigned int> nShare(numTrk);
477 std::map<int, int> stubsTrk1 =
inputtracks_[itrk]->stubID();
478 nStubP = stubsTrk1.size();
480 for (
unsigned int jtrk = itrk + 1; jtrk < numTrk; jtrk++) {
486 std::map<int, int> stubsTrk2 =
inputtracks_[jtrk]->stubID();
487 nStubS[jtrk] = stubsTrk2.size();
490 for (
auto& st : stubsTrk1) {
491 if (stubsTrk2.find(st.first) != stubsTrk2.end()) {
492 if (st.second == stubsTrk2[st.first])
499 for (
unsigned int jtrk = itrk + 1; jtrk < numTrk; jtrk++) {
515 edm::LogVerbatim(
"Tracklet") <<
"Error: Didn't tag either track in duplicate pair.";
524 }
else if ((nStubS[jtrk] - nShare[jtrk] <
settings_.
minIndStubs()) && (nStubS[jtrk] <= nStubP)) {
527 edm::LogVerbatim(
"Tracklet") <<
"Error: Didn't tag either track in duplicate pair.";
543 ofstream
fout(
"seeds.txt", ofstream::app);
544 fout << __FILE__ <<
":" << __LINE__ <<
" " <<
name_ <<
"_" << iSector <<
" " 573 int seedindex = curTracklet->
seedIndex();
582 phires =
std::abs(stubphi - phiproj);
587 if ((seedindex == 0 && (
Layer == 1 ||
Layer == 2)) || (seedindex == 1 && (
Layer == 2 ||
Layer == 3)) ||
588 (seedindex == 2 && (
Layer == 3 ||
Layer == 4)) || (seedindex == 3 && (
Layer == 5 ||
Layer == 6)) ||
602 std::pair<int, int> layer_disk;
604 if (layer_disk.first >
N_LAYER) {
605 layer_disk.first = 0;
608 if (layer_disk.second < 0) {
609 layer_disk.second = 0;
616 std::string thestr = Form(
"\t %s stub info: r/z/phi:\t%f\t%f\t%f\t%d\t%f\t%d",
633 double stub_phi = -99;
637 double tracklet_rinv = tracklet->
rinv();
641 stub_phi = tracklet->
phi0() - std::asin(stub_r * tracklet_rinv / 2);
644 stub_z = tracklet->
z0() + 2 * tracklet->
t() * 1 / tracklet_rinv * std::asin(stub_r * tracklet_rinv / 2);
647 stub_phi = tracklet->
phi0() - (stub_z - tracklet->
z0()) * tracklet_rinv / 2 / tracklet->
t();
650 stub_r = 2 / tracklet_rinv *
std::sin((stub_z - tracklet->
z0()) * tracklet_rinv / 2 / tracklet->
t());
653 std::vector<double> invented_coords{stub_r, stub_z, stub_phi};
654 return invented_coords;
663 double stub_phi = -99;
667 const double rho = 1 / tracklet->
rinv();
668 const double rho_minus_d0 = rho + tracklet->
d0();
688 0.5 * (stub_r / rho_minus_d0) + 0.5 * (rho_minus_d0 / stub_r) - 0.5 * ((rho * rho) / (rho_minus_d0 * stub_r));
690 stub_phi = tracklet->
phi0() - std::asin(sin_val);
698 0.5 * (rho / rho_minus_d0) + 0.5 * (rho_minus_d0 / rho) - 0.5 * ((stub_r * stub_r) / (rho * rho_minus_d0));
700 double beta = std::acos(cos_val);
705 double beta = (stub_z - tracklet->
z0()) / (tracklet->
t() *
std::abs(rho));
706 double r_square = -2 * rho * rho_minus_d0 *
std::cos(
beta) + rho * rho + rho_minus_d0 * rho_minus_d0;
707 stub_r =
sqrt(r_square);
713 0.5 * (stub_r / rho_minus_d0) + 0.5 * (rho_minus_d0 / stub_r) - 0.5 * ((rho * rho) / (rho_minus_d0 * stub_r));
715 stub_phi = tracklet->
phi0() - std::asin(sin_val);
721 std::vector<double> invented_coords{stub_r, stub_z, stub_phi};
722 return invented_coords;
726 unsigned int iSector,
const Tracklet* tracklet,
const std::vector<const Stub*>& originalStubsList)
const {
727 std::vector<const Stub*> newStubList;
729 for (
unsigned int stubit = 0; stubit < originalStubsList.size(); stubit++) {
730 const Stub* thisStub = originalStubsList[stubit];
734 std::vector<double> inv_r_z_phi;
740 double stub_x_invent = inv_r_z_phi[0] *
std::cos(inv_r_z_phi[2]);
741 double stub_y_invent = inv_r_z_phi[0] *
std::sin(inv_r_z_phi[2]);
742 double stub_z_invent = inv_r_z_phi[1];
744 Stub* invent_stub_ptr =
new Stub(*thisStub);
746 L1TStub invent_l1stub = *l1stub;
747 invent_l1stub.
setCoords(stub_x_invent, stub_y_invent, stub_z_invent);
753 newStubList.push_back(invent_stub_ptr);
756 newStubList.push_back(thisStub);
775 return rinvBins.size() - 2;
776 else if (
bins == rinvBins.begin())
787 double phi0 = trk->
phi0();
790 double phi = phi0 - asin(0.5 *
rinv * rcrit);
812 std::vector<unsigned int> chosenBins;
813 for (
long unsigned int i = 0;
i < rinvBins.size() - 1;
i++) {
814 if ((
rinv < rinvBins[
i + 1] + rinvOverlapSize) && (
rinv > rinvBins[
i] - rinvOverlapSize)) {
815 chosenBins.push_back(
i);
823 double phi0 = trk->
phi0();
826 double phi = phi0 - asin(0.5 *
rinv * rcrit);
831 std::vector<unsigned int> chosenBins;
832 for (
long unsigned int i = 0;
i <
phiBins.size() - 1;
i++) {
833 if ((phi <
phiBins[
i + 1] + phiOverlapSize) && (phi >
phiBins[
i] - phiOverlapSize)) {
834 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