CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1TMuonBarrelKalmanRegionModule.cc
Go to the documentation of this file.
2 
4  int wheel,
5  int sector)
6  : verbose_(iConfig.getParameter<int>("verbose")), sector_(sector), wheel_(wheel) {
7  if (sector == 11) {
8  nextSector_ = 0;
9  previousSector_ = 10;
10  } else if (sector == 0) {
11  nextSector_ = 1;
12  previousSector_ = 11;
13  } else {
14  nextSector_ = sector + 1;
15  previousSector_ = sector - 1;
16  }
17 
18  switch (wheel) {
19  case -2:
20  nextWheel_ = -1;
21  break;
22 
23  case -1:
24  nextWheel_ = 0;
25  break;
26 
27  case 0:
28  nextWheel_ = 999;
29  break;
30 
31  case 1:
32  nextWheel_ = 0;
33  break;
34 
35  case 2:
36  nextWheel_ = 1;
37  break;
38 
39  default:
40  nextWheel_ = 999;
41  break;
42  }
43 }
44 
46 
48  const L1MuKBMTCombinedStubRefVector& stubsAll,
49  int bx) {
52  L1MuKBMTrackCollection pretracks2;
53  L1MuKBMTrackCollection pretracks3;
54  L1MuKBMTrackCollection pretracks4;
55  for (const auto& stub : stubsAll) {
56  if (stub->bxNum() != bx)
57  continue;
58 
59  if ((stub->scNum() == nextSector_ && stub->phi() >= -112) ||
60  (stub->scNum() == previousSector_ && stub->phi() <= 111))
61  continue;
62 
63  if (stub->whNum() == wheel_ && stub->scNum() == sector_) {
64  seeds.push_back(stub);
65  stubs.push_back(stub);
66  } else if (stub->whNum() == wheel_ && (stub->scNum() == nextSector_ || stub->scNum() == previousSector_)) {
67  stubs.push_back(stub);
68  } else if (stub->whNum() == nextWheel_ &&
69  (stub->scNum() == nextSector_ || stub->scNum() == previousSector_ || stub->scNum() == sector_)) {
70  stubs.push_back(stub);
71  }
72  }
73 
74  //Sort the seeds by tag so that the emulator is aligned like the firmware
75 
77  if (seeds.size() > 1) {
78  std::sort(seeds.begin(), seeds.end(), sorter);
79  }
80 
81  for (const auto& seed : seeds) {
82  std::pair<bool, L1MuKBMTrack> trackInfo = trackMaker->chain(seed, stubs);
83  //printf("Kalman Track %d valid=%d tag=%d rank=%d charge=%d pt=%f eta=%f phi=%f curvature=%d curvature STA =%d stubs=%d chi2=%d pts=%f %f pattern=%d\n",seed->stNum(),trackInfo.first, trackInfo.second.stubs()[0]->tag(),trackInfo.second.rank(),trackInfo.second.charge(),trackInfo.second.pt(),trackInfo.second.eta(),trackInfo.second.phi(),trackInfo.second.curvatureAtVertex(),trackInfo.second.curvatureAtMuon(),int(trackInfo.second.stubs().size()),trackInfo.second.approxChi2(),trackInfo.second.pt(),trackInfo.second.ptUnconstrained(),trackInfo.second.hitPattern());
84 
85  L1MuKBMTrack nullTrack(seed, seed->phi(), 8 * seed->phiB());
86  nullTrack.setPtEtaPhi(0, 0, 0);
87  nullTrack.setRank(0);
88  if (trackInfo.first) {
89  if (seed->stNum() == 2)
90  pretracks2.push_back(trackInfo.second);
91  if (seed->stNum() == 3)
92  pretracks3.push_back(trackInfo.second);
93  if (seed->stNum() == 4)
94  pretracks4.push_back(trackInfo.second);
95  } else {
96  if (seed->stNum() == 2)
97  pretracks2.push_back(nullTrack);
98  if (seed->stNum() == 3)
99  pretracks3.push_back(nullTrack);
100  if (seed->stNum() == 4)
101  pretracks4.push_back(nullTrack);
102  }
103  }
104  L1MuKBMTrack nullTrack;
105  nullTrack.setPtEtaPhi(0, 0, 0);
106  nullTrack.setRank(0);
107  // All pretracks must have trackL and trackH like firmware
108  // Swap trackH and trackL for seeds 2/3 to mimic firmware
109  if (pretracks2.size() < 2) {
110  if (pretracks2.empty()) { // if no tracks, set trackH and trackL to null
111  pretracks2.push_back(nullTrack);
112  pretracks2.push_back(nullTrack);
113  } else { // otherwise add nulltrack for trackH or trackL
114  if (pretracks2[0].stubs()[0]->tag() == 0)
115  pretracks2.push_back(nullTrack);
116  else
117  pretracks2.insert(pretracks2.begin(), nullTrack);
118  }
119  }
120  std::swap(pretracks2[0], pretracks2[1]);
121 
122  if (pretracks3.size() < 2) {
123  if (pretracks3.empty()) {
124  pretracks3.push_back(nullTrack);
125  pretracks3.push_back(nullTrack);
126  } else {
127  if (pretracks3[0].stubs()[0]->tag() == 0)
128  pretracks3.push_back(nullTrack);
129  else
130  pretracks3.insert(pretracks3.begin(), nullTrack);
131  }
132  }
133  std::swap(pretracks3[0], pretracks3[1]);
134 
135  if (pretracks4.size() < 2) {
136  if (pretracks4.empty()) {
137  pretracks4.push_back(nullTrack);
138  pretracks4.push_back(nullTrack);
139  } else {
140  if (pretracks4[0].stubs()[0]->tag() == 0)
141  pretracks4.push_back(nullTrack);
142  else
143  pretracks4.insert(pretracks4.begin(), nullTrack);
144  }
145  }
146 
147  /*
148  printf("SEED 2\n");
149  for (const auto& track1 :pretracks2){
150  printf(" Kalman Track rank=%d charge=%d pt=%f eta=%f phi=%f curvature=%d curvature STA =%d stubs=%d chi2=%d pts=%f %f pattern=%d\n",track1.rank(),track1.charge(),track1.pt(),track1.eta(),track1.phi(),track1.curvatureAtVertex(),track1.curvatureAtMuon(),int(track1.stubs().size()),track1.approxChi2(),track1.pt(),track1.ptUnconstrained(),track1.hitPattern());
151  }
152  printf("SEED 3\n");
153  for (const auto& track1 :pretracks3){
154  printf(" Kalman Track rank=%d charge=%d pt=%f eta=%f phi=%f curvature=%d curvature STA =%d stubs=%d chi2=%d pts=%f %f pattern=%d\n",track1.rank(),track1.charge(),track1.pt(),track1.eta(),track1.phi(),track1.curvatureAtVertex(),track1.curvatureAtMuon(),int(track1.stubs().size()),track1.approxChi2(),track1.pt(),track1.ptUnconstrained(),track1.hitPattern());
155  }
156  printf("SEED 4\n");
157  for (const auto& track1 :pretracks4){
158  printf(" Kalman Track rank=%d charge=%d pt=%f eta=%f phi=%f curvature=%d curvature STA =%d stubs=%d chi2=%d pts=%f %f pattern=%d\n",track1.rank(),track1.charge(),track1.pt(),track1.eta(),track1.phi(),track1.curvatureAtVertex(),track1.curvatureAtMuon(),int(track1.stubs().size()),track1.approxChi2(),track1.pt(),track1.ptUnconstrained(),track1.hitPattern());
159  }
160  */
161 
162  L1MuKBMTrackCollection out = cleanRegion(pretracks2, pretracks3, pretracks4);
163  if (verbose_) {
164  printf(" -----Sector Processor Kalman Tracks-----\n");
165  for (const auto& track1 : out)
166  printf("Kalman Track charge=%d pt=%f eta=%f phi=%f curvature=%d curvature STA =%d stubs=%d chi2=%d pts=%f %f\n",
167  track1.charge(),
168  track1.pt(),
169  track1.eta(),
170  track1.phi(),
171  track1.curvatureAtVertex(),
172  track1.curvatureAtMuon(),
173  int(track1.stubs().size()),
174  track1.approxChi2(),
175  track1.pt(),
176  track1.ptUnconstrained());
177  }
178 
179  return out;
180 }
181 
184 
185  for (uint i = 0; i < tracks.size(); ++i) {
186  //bool keep = true;
187  L1MuKBMTrack temp = tracks[i];
188  for (uint j = 0; j < tracks.size(); ++j) {
189  if (i == j)
190  continue;
191 
192  if (tracks[i].overlapTrack(tracks[j])) {
193  if (tracks[i].rank() < tracks[j].rank()) {
194  //keep = false;
195  temp.setPtEtaPhi(0, 0, 0);
196  temp.setRank(0);
197  } else if (tracks[i].rank() == tracks[j].rank()) { //if same rank prefer seed that is high
198  if (!tracks[j].stubs()[0]->tag()) {
199  //keep = false;
200  temp.setPtEtaPhi(0, 0, 0);
201  temp.setRank(0);
202  }
203  }
204  }
205  }
206  out.push_back(temp);
207  //if (keep)
208  //out.push_back(tracks[i]);
209  }
210 
211  return out;
212 }
213 
215  const L1MuKBMTrackCollection& tracks2) {
217 
218  for (uint i = 0; i < tracks1.size(); ++i) {
219  //bool keep = true;
220  L1MuKBMTrack temp = tracks1[i];
221  for (uint j = 0; j < tracks2.size(); ++j) {
222  if (tracks1[i].overlapTrack(tracks2[j])) {
223  if (tracks1[i].rank() <= tracks2[j].rank()) {
224  //keep = false;
225  temp.setPtEtaPhi(0, 0, 0);
226  temp.setRank(0);
227  }
228  }
229  }
230  out.push_back(temp);
231  //if (keep)
232  // out.push_back(tracks1[i]);
233  }
234 
235  return out;
236 }
237 
239  const L1MuKBMTrackCollection& tracks2) {
241 
242  for (uint i = 0; i < tracks1.size(); ++i) {
243  //bool keep = true;
244  L1MuKBMTrack temp = tracks1[i];
245  for (uint j = 0; j < tracks2.size(); ++j) {
246  if (tracks1[i].overlapTrack(tracks2[j])) {
247  if (tracks1[i].rank() < tracks2[j].rank()) {
248  //keep = false;
249  temp.setPtEtaPhi(0, 0, 0);
250  temp.setRank(0);
251  }
252  }
253  }
254  out.push_back(temp);
255  //if (keep)
256  // out.push_back(tracks1[i]);
257  }
258 
259  return out;
260 }
261 
264  //partial sort like in firmwarE (bitonic)
265 
266  if (in.size() <= 2)
267  return in;
268  else if (in.size() == 3) {
269  //Step 1
270  L1MuKBMTrack s2_1;
271  L1MuKBMTrack s2_3;
272  if (in[2].pt() >= in[0].pt()) {
273  s2_1 = in[2];
274  s2_3 = in[0];
275  } else {
276  s2_1 = in[0];
277  s2_3 = in[2];
278  }
279 
280  L1MuKBMTrack s2_2 = in[1];
281  //Step 2;
282  L1MuKBMTrack s3_1 = s2_1;
283  L1MuKBMTrack s3_2;
284  L1MuKBMTrack s3_3;
285 
286  if (s2_3.pt() >= s2_2.pt()) {
287  s3_2 = s2_3;
288  s3_3 = s2_2;
289  } else {
290  s3_2 = s2_2;
291  s3_3 = s2_3;
292  }
293 
294  out.push_back(s3_1);
295  out.push_back(s3_2);
296 
297  } else {
298  //Step 1
299  L1MuKBMTrack s2_1;
300  L1MuKBMTrack s2_2;
301  L1MuKBMTrack s2_3;
302  L1MuKBMTrack s2_4;
303 
304  if (in[2].pt() >= in[0].pt()) {
305  s2_1 = in[2];
306  s2_3 = in[0];
307  } else {
308  s2_1 = in[0];
309  s2_3 = in[2];
310  }
311  if (in[3].pt() >= in[1].pt()) {
312  s2_2 = in[3];
313  s2_4 = in[1];
314  } else {
315  s2_2 = in[1];
316  s2_4 = in[3];
317  }
318  //Step 2
319  L1MuKBMTrack s3_1;
320  L1MuKBMTrack s3_2;
321  L1MuKBMTrack s3_3;
322  L1MuKBMTrack s3_4;
323 
324  if (s2_4.pt() >= s2_1.pt()) {
325  s3_1 = s2_4;
326  s3_4 = s2_1;
327  } else {
328  s3_1 = s2_1;
329  s3_4 = s2_4;
330  }
331 
332  if (s2_3.pt() >= s2_2.pt()) {
333  s3_2 = s2_3;
334  s3_3 = s2_2;
335  } else {
336  s3_2 = s2_2;
337  s3_3 = s2_3;
338  }
339 
340  out.push_back(s3_1);
341  out.push_back(s3_2);
342  }
343  return out;
344 }
345 
347  const L1MuKBMTrackCollection& tracks3,
348  const L1MuKBMTrackCollection& tracks4) {
349  L1MuKBMTrackCollection cleaned2 = selfClean(tracks2);
350  L1MuKBMTrackCollection cleaned3 = selfClean(tracks3);
351 
352  L1MuKBMTrackCollection cleaned23 = cleanHigher(cleaned2, tracks3);
353  L1MuKBMTrackCollection cleaned32 = cleanLower(cleaned3, tracks2);
354 
355  //merge 2,3
357  if (!cleaned23.empty())
358  step1.insert(step1.end(), cleaned23.begin(), cleaned23.end());
359  if (!cleaned32.empty())
360  step1.insert(step1.end(), cleaned32.begin(), cleaned32.end());
361 
362  //take the best 2
363  L1MuKBMTrackCollection sorted23 = sort4(step1);
364 
365  //Now clean the tracks 4 between them
366  L1MuKBMTrackCollection cleaned4 = selfClean(tracks4);
367 
368  //Now clean the 23 tracks from tracks4
369  L1MuKBMTrackCollection cleanedSorted23 = cleanHigher(sorted23, tracks4);
370 
371  //Now clean the tracks4 from sorted 23
372  L1MuKBMTrackCollection cleanedSorted4 = cleanLower(cleaned4, sorted23);
373 
374  //Now merge all of those
376 
377  if (!cleanedSorted4.empty())
378  step2.insert(step2.end(), cleanedSorted4.begin(), cleanedSorted4.end());
379  if (!cleanedSorted23.empty())
380  step2.insert(step2.end(), cleanedSorted23.begin(), cleanedSorted23.end());
381 
383  // Verbose statements:
384  /*
385  printf("tracks 1-4\n");
386  for (const auto& track1 :step1)
387  printf(" rank=%d charge=%d pt=%f eta=%f phi=%f curvature=%d curvature STA =%d stubs=%d chi2=%d pts=%f %f pattern=%d\n",track1.rank(),track1.charge(),track1.pt(),track1.eta(),track1.phi(),track1.curvatureAtVertex(),track1.curvatureAtMuon(),int(track1.stubs().size()),track1.approxChi2(),track1.pt(),track1.ptUnconstrained(),track1.hitPattern());
388 
389  printf("sorted1\n");
390  for (const auto& track1 :sorted23)
391  printf(" rank=%d charge=%d pt=%f eta=%f phi=%f curvature=%d curvature STA =%d stubs=%d chi2=%d pts=%f %f pattern=%d\n",track1.rank(),track1.charge(),track1.pt(),track1.eta(),track1.phi(),track1.curvatureAtVertex(),track1.curvatureAtMuon(),int(track1.stubs().size()),track1.approxChi2(),track1.pt(),track1.ptUnconstrained(),track1.hitPattern());
392 
393  printf("track 5-8\n");
394  for (const auto& track1 :step2)
395  printf(" rank=%d charge=%d pt=%f eta=%f phi=%f curvature=%d curvature STA =%d stubs=%d chi2=%d pts=%f %f pattern=%d\n",track1.rank(),track1.charge(),track1.pt(),track1.eta(),track1.phi(),track1.curvatureAtVertex(),track1.curvatureAtMuon(),int(track1.stubs().size()),track1.approxChi2(),track1.pt(),track1.ptUnconstrained(),track1.hitPattern());
396 
397  printf("OUTPUT\n");
398  for (const auto& track1 :out)
399  printf(" rank=%d charge=%d pt=%f eta=%f phi=%f curvature=%d curvature STA =%d stubs=%d chi2=%d pts=%f %f pattern=%d\n",track1.rank(),track1.charge(),track1.pt(),track1.eta(),track1.phi(),track1.curvatureAtVertex(),track1.curvatureAtMuon(),int(track1.stubs().size()),track1.approxChi2(),track1.pt(),track1.ptUnconstrained(),track1.hitPattern());
400  */
401  return out;
402 }
L1MuKBMTrackCollection cleanLower(const L1MuKBMTrackCollection &tracks1, const L1MuKBMTrackCollection &tracks2)
double pt() const final
transverse momentum
auto const & tracks
cannot be loose
std::vector< edm::Ref< L1MuKBMTCombinedStubCollection > > L1MuKBMTCombinedStubRefVector
void setRank(int)
void setPtEtaPhi(double, double, double)
Definition: L1MuKBMTrack.cc:93
L1MuKBMTrackCollection cleanHigher(const L1MuKBMTrackCollection &tracks1, const L1MuKBMTrackCollection &tracks2)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
L1MuKBMTrackCollection process(L1TMuonBarrelKalmanAlgo *, const L1MuKBMTCombinedStubRefVector &stubs, int bx)
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
L1MuKBMTrackCollection cleanRegion(const L1MuKBMTrackCollection &, const L1MuKBMTrackCollection &, const L1MuKBMTrackCollection &)
std::pair< bool, L1MuKBMTrack > chain(const L1MuKBMTCombinedStubRef &, const L1MuKBMTCombinedStubRefVector &)
L1MuKBMTrackCollection sort4(const L1MuKBMTrackCollection &in)
std::vector< L1MuKBMTrack > L1MuKBMTrackCollection
Definition: L1MuKBMTrack.h:15
L1MuKBMTrackCollection selfClean(const L1MuKBMTrackCollection &tracks)
L1TMuonBarrelKalmanRegionModule(const edm::ParameterSet &, int wheel, int sector)