CMS 3D CMS Logo

ROITempAssociator.h
Go to the documentation of this file.
1 #ifndef PHASE2GMT_TEMPORARY_ASSOCIATOR
2 #define PHASE2GMT_TEMPORARY_ASSOCIATOR
3 
4 #include "ap_int.h"
5 #include "MuonROI.h"
8 
9 namespace Phase2L1GMT {
10 
12  public:
15 
16  std::vector<MuonROI> associate(int bx,
18  const l1t::MuonStubRefVector& stubs) {
19  std::vector<MuonROI> out;
20  l1t::MuonStubRefVector usedStubs;
21 
22  if (muons.size() > 0) {
23  for (unsigned int i = 0; i < muons.size(bx); ++i) {
24  const l1t::RegionalMuonCandRef& mu = muons.at(bx, i);
25  uint pt = mu->hwPt();
26  uint charge = mu->hwSign();
27 
28  float eta = mu->hwEta() * 0.010875;
29 
30  int globalPhi = 0;
31  if (mu->trackFinderType() == l1t::bmtf) {
32  globalPhi = mu->processor() * 48 + mu->hwPhi() - 24;
33  } else {
34  globalPhi = mu->processor() * 96 + mu->hwPhi() + 24;
35  }
36 
37  float phi = globalPhi * 2 * M_PI / 576.0;
38  if (phi > (M_PI))
39  phi = phi - 2 * M_PI;
40  else if (phi < (-M_PI))
41  phi = phi + 2 * M_PI;
42 
43  MuonROI roi(bx, charge, pt, 1);
44  roi.setMuonRef(mu);
45  l1t::MuonStubRefVector cleanedStubs = clean(stubs, usedStubs);
46 
47  for (unsigned int layer = 0; layer <= 4; ++layer) {
48  l1t::MuonStubRefVector selectedStubs = selectLayerBX(cleanedStubs, bx, layer);
49  int bestStubINT = -1;
50  float dPhi = 1000.0;
51 
52  for (uint i = 0; i < selectedStubs.size(); ++i) {
53  const l1t::MuonStubRef& stub = selectedStubs[i];
54  float deltaPhi = (stub->quality() & 0x1) ? stub->offline_coord1() - phi : stub->offline_coord2() - phi;
55  if (deltaPhi > M_PI)
56  deltaPhi = deltaPhi - 2 * M_PI;
57  else if (deltaPhi < -M_PI)
58  deltaPhi = deltaPhi + 2 * M_PI;
59  deltaPhi = fabs(deltaPhi);
60  float deltaEta = (stub->etaQuality() == 0 || (stub->etaQuality() & 0x1))
61  ? fabs(stub->offline_eta1() - eta)
62  : fabs(stub->offline_eta2() - eta);
63  if (deltaPhi < (M_PI / 6.0) && deltaEta < 0.3 && deltaPhi < dPhi) {
64  dPhi = deltaPhi;
65  bestStubINT = i;
66  }
67  }
68  if (bestStubINT >= 0) {
69  roi.addStub(selectedStubs[bestStubINT]);
70  usedStubs.push_back(selectedStubs[bestStubINT]);
71  }
72  }
73  if (out.size() < 16 && !roi.stubs().empty())
74  out.push_back(roi);
75  }
76  }
77  //Now the stubs only . Find per layer
78 
79  l1t::MuonStubRefVector cleanedStubs = clean(stubs, usedStubs);
80 
81  while (!cleanedStubs.empty()) {
82  MuonROI roi(bx, 0, 0, 0);
83  roi.addStub(cleanedStubs[0]);
84  usedStubs.push_back(cleanedStubs[0]);
85  for (unsigned int layer = 0; layer <= 4; ++layer) {
86  if (layer == cleanedStubs[0]->tfLayer())
87  continue;
88  l1t::MuonStubRefVector selectedStubs = selectLayerBX(cleanedStubs, bx, layer);
89  if (!selectedStubs.empty()) {
90  roi.addStub(selectedStubs[0]);
91  usedStubs.push_back(selectedStubs[0]);
92  }
93  }
94  if (!roi.stubs().empty())
95  if (out.size() < 16)
96  out.push_back(roi);
97  cleanedStubs = clean(cleanedStubs, usedStubs);
98  }
99  return out;
100  }
101 
102  private:
105  for (const auto& stub : all) {
106  if (stub->bxNum() == bx && stub->tfLayer() == layer)
107  out.push_back(stub);
108  }
109  return out;
110  }
111 
114  for (const auto& stub : all) {
115  bool keep = true;
116  for (const auto& st : used) {
117  if (st == stub) {
118  keep = false;
119  break;
120  }
121  }
122  if (keep)
123  out.push_back(stub);
124  }
125  return out;
126  }
127  };
128 } // namespace Phase2L1GMT
129 
130 #endif
l1t::MuonStubRefVector selectLayerBX(const l1t::MuonStubRefVector &all, int bx, uint layer)
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
std::vector< MuonROI > associate(int bx, const l1t::ObjectRefBxCollection< l1t::RegionalMuonCand > &muons, const l1t::MuonStubRefVector &stubs)
static const double deltaEta
Definition: CaloConstants.h:8
std::vector< edm::Ref< MuonStubCollection > > MuonStubRefVector
Definition: MuonStub.h:44
l1t::MuonStubRefVector clean(const l1t::MuonStubRefVector &all, const l1t::MuonStubRefVector &used)
ROITempAssociator(const edm::ParameterSet &iConfig)
#define M_PI
const l1t::MuonStubRefVector & stubs() const
Definition: MuonROI.h:51
void addStub(const l1t::MuonStubRef &stub)
Definition: MuonROI.h:29
void setMuonRef(const l1t::RegionalMuonCandRef &ref)
Definition: MuonROI.h:31