CMS 3D CMS Logo

RecHitProcessor.cc
Go to the documentation of this file.
2 
4 }
5 
7 }
8 
10  const edm::Event& iEvent,
11  const edm::EventSetup& iSetup,
12  const edm::EDGetToken& recHitToken,
13  std::vector<RecHitProcessor::CppfItem>& CppfVec1,
14  l1t::CPPFDigiCollection& cppfDigis,
15  const int MaxClusterSize
16  ) const {
17 
19  iEvent.getByToken(recHitToken, recHits);
20 
22  iSetup.get<MuonGeometryRecord>().get(rpcGeom);
23 
24 
25  std::map <std::pair<int, int>, int> chamber_repetitions;
26  chamber_repetitions.clear();
27  // The loop is over the detector container in the rpc geometry collection. We are interested in the RPDdetID (inside of RPCChamber vectors), specifically, the RPCrechits. to assignment the CPPFDigis.
28  for ( TrackingGeometry::DetContainer::const_iterator iDet = rpcGeom->dets().begin(); iDet < rpcGeom->dets().end(); iDet++ ) {
29 
30  // we do a cast over the class RPCChamber to obtain the RPCroll vectors, inside of them, the RPCRechits are found. in other words, the method ->rolls() does not exist for other kind of vector within DetContainer and we can not obtain the rpcrechits in a suitable way.
31  if (dynamic_cast<const RPCChamber*>( *iDet ) == nullptr ) continue;
32 
33  auto chamb = dynamic_cast<const RPCChamber* >( *iDet );
34 
35  std::vector<const RPCRoll*> rolls = (chamb->rolls());
36 
37  // Loop over rolls in the chamber
38  for(auto& iRoll : rolls){
39 
40  RPCDetId rpcId = (*iRoll).id();
41 
42 
43 
44  typedef std::pair<RPCRecHitCollection::const_iterator, RPCRecHitCollection::const_iterator> rangeRecHits;
45  rangeRecHits recHitCollection = recHits->get(rpcId);
46 
47  //Loop over the RPC digis
48  for (RPCRecHitCollection::const_iterator rechit_it = recHitCollection.first; rechit_it != recHitCollection.second; rechit_it++) {
49  //const RPCDetId& rpcId = rechit_it->rpcId();
50 
51  int rawId = rpcId.rawId();
52  int station = rpcId.station();
53  int ring = rpcId.ring();
54  int Bx = rechit_it->BunchX();
55  int isValid = rechit_it->isValid();
56  int firststrip = rechit_it->firstClusterStrip();
57  int clustersize = rechit_it->clusterSize();
58  LocalPoint lPos = rechit_it->localPosition();
59  const RPCRoll* roll = rpcGeom->roll(rpcId);
60  const BoundPlane& rollSurface = roll->surface();
61  GlobalPoint gPos = rollSurface.toGlobal(lPos);
62  float global_theta = emtf::rad_to_deg(gPos.theta().value());
63  float global_phi = emtf::rad_to_deg(gPos.phi().value());
64  //::::::::::::::::::::::::::::
65  //Establish the average position of the rechit
66  int rechitstrip = firststrip;
67 
68  if(clustersize > 2) {
69  int medium = 0;
70  if (clustersize % 2 == 0) medium = 0.5*(clustersize);
71  else medium = 0.5*(clustersize-1);
72  rechitstrip += medium;
73  }
74 
75  if(clustersize > MaxClusterSize) continue;
76  //This is just for test CPPFDigis with the RPC Geometry, It must be "true" in the normal runs
77  bool Geo = true;
79  //Set the EMTF Sector
80  int EMTFsector1 = 0;
81  int EMTFsector2 = 0;
82 
83  //Chamber ID
84  int nsub = 6;
85  (ring == 1 && station > 1) ? nsub = 3 : nsub = 6;
86  int chamberID = rpcId.subsector() + nsub * ( rpcId.sector() - 1);
87 
88 
89  //sector 1
90  if ((global_phi > 15.) && (global_phi <= 16.3)) {
91  EMTFsector1 = 1;
92  EMTFsector2 = 6;
93  }
94  else if ((global_phi > 16.3) && (global_phi <= 53.)) {
95  EMTFsector1 = 1;
96  EMTFsector2 = 0;
97  }
98  else if ((global_phi > 53.) && (global_phi <= 75.)) {
99  EMTFsector1 = 1;
100  EMTFsector2 = 2;
101  }
102  //sector 2
103  else if ((global_phi > 75.) && (global_phi <= 76.3)) {
104  EMTFsector1 = 1;
105  EMTFsector2 = 2;
106  }
107  else if ((global_phi > 76.3) && (global_phi <= 113.)) {
108  EMTFsector1 = 2;
109  EMTFsector2 = 0;
110  }
111  else if ((global_phi > 113.) && (global_phi <= 135.)) {
112  EMTFsector1 = 2;
113  EMTFsector2 = 3;
114  }
115  //sector 3
116  //less than 180
117  else if ((global_phi > 135.) && (global_phi <= 136.3)) {
118  EMTFsector1 = 2;
119  EMTFsector2 = 3;
120  }
121  else if ((global_phi > 136.3) && (global_phi <= 173.)) {
122  EMTFsector1 = 3;
123  EMTFsector2 = 0;
124  }
125  else if ((global_phi > 173.) && (global_phi <= 180.)) {
126  EMTFsector1 = 3;
127  EMTFsector2 = 4;
128  }
129  //Greater than -180
130  else if ((global_phi < -165.) && (global_phi >= -180.)) {
131  EMTFsector1 = 3;
132  EMTFsector2 = 4;
133  }
134  //Fourth sector
135  else if ((global_phi > -165.) && (global_phi <= -163.7)) {
136  EMTFsector1 = 3;
137  EMTFsector2 = 4;
138  }
139  else if ((global_phi > -163.7) && (global_phi <= -127.)) {
140  EMTFsector1 = 4;
141  EMTFsector2 = 0;
142  }
143  else if ((global_phi > -127.) && (global_phi <= -105.)) {
144  EMTFsector1 = 4;
145  EMTFsector2 = 5;
146  }
147  //fifth sector
148  else if ((global_phi > -105.) && (global_phi <= -103.7)) {
149  EMTFsector1 = 4;
150  EMTFsector2 = 5;
151  }
152  else if ((global_phi > -103.7) && (global_phi <= -67.)) {
153  EMTFsector1 = 5;
154  EMTFsector2 = 0;
155  }
156  else if ((global_phi > -67.) && (global_phi <= -45.)) {
157  EMTFsector1 = 5;
158  EMTFsector2 = 6;
159  }
160  //sixth sector
161  else if ((global_phi > -45.) && (global_phi <= -43.7)) {
162  EMTFsector1 = 5;
163  EMTFsector2 = 6;
164  }
165  else if ((global_phi > -43.7) && (global_phi <= -7.)) {
166  EMTFsector1 = 6;
167  EMTFsector2 = 0;
168  }
169  else if ((global_phi > -7.) && (global_phi <= 15.)) {
170  EMTFsector1 = 6;
171  EMTFsector2 = 1;
172  }
173 
174 
175  // std::vector<RecHitProcessor::CppfItem>::iterator it;
176  // for(it = CppfVec1.begin(); it != CppfVec1.end(); it++){
177  // if( (*it).rawId == rawId) if(Geo_true) std::cout << (*it).rawId << "rawid" << rawId << std::endl;
178  // }
179  //Loop over the look up table
180  double EMTFLink1 = 0.;
181  double EMTFLink2 = 0.;
182 
183  std::vector<RecHitProcessor::CppfItem>::iterator cppf1;
184  std::vector<RecHitProcessor::CppfItem>::iterator cppf;
185  for(cppf1 = CppfVec1.begin(); cppf1 != CppfVec1.end(); cppf1++){
186 
187 
188 
189  //Condition to save the CPPFDigi
190  if(((*cppf1).rawId == rawId) && ((*cppf1).strip == rechitstrip)){
191 
192  int old_strip = (*cppf1).strip;
193  int before = 0;
194  int after = 0;
195 
196  if(cppf1 != CppfVec1.begin())
197  before = (*(cppf1-2)).strip;
198 
199  else if (cppf1 == CppfVec1.begin())
200  before = (*cppf1).strip;
201 
202  if(cppf1 != CppfVec1.end())
203  after = (*(cppf1+2)).strip;
204 
205  else if (cppf1 == CppfVec1.end())
206  after = (*cppf1).strip;
207 
208  cppf = cppf1;
209 
210  if(clustersize == 2){
211 
212  if(firststrip == 1){
213  if(before < after) cppf=(cppf1-1);
214  else if (before > after) cppf=(cppf1+1);
215  }
216  else if(firststrip > 1){
217  if(before < after) cppf=(cppf1+1);
218  else if (before > after) cppf=(cppf1-1);
219  }
220 
221  }
222  //Information for save cluster (2) per chamber
223  std::pair<int, int> temporal;
224  temporal = std::make_pair (station, chamberID);
225 
226 
227  std::map<std::pair<int, int>, int>::iterator it;
228  it = chamber_repetitions.find(temporal);
229 
230  // std::cout << "Current event " << temporal.first << "," << temporal.second << std::endl;
231 
232  if(it == chamber_repetitions.end()){
233  chamber_repetitions[temporal] = 1;
234  }
235  else if((it != chamber_repetitions.end()) && (chamber_repetitions[temporal] == 1)){
236  chamber_repetitions[temporal] = 2;
237  }
238  else if((it != chamber_repetitions.end()) && (chamber_repetitions[temporal] == 2)){
239  continue;
240  }
241 
242  // for(std::map<std::pair<int, int>, int>::iterator it = chamber_repetitions.begin() ; it != chamber_repetitions.end(); it++){
243  // std::pair<int, int> temp = it->first;
244  // std::cout << temp.first << "," << temp.second << " Repetitions: " << it->second <<std::endl;
245  // }
246 
247  //Using the RPCGeometry
248  if(Geo){
249  std::shared_ptr<l1t::CPPFDigi> MainVariables1(new l1t::CPPFDigi(rpcId, Bx , (*cppf).int_phi, (*cppf).int_theta, isValid, (*cppf).lb, (*cppf).halfchannel, EMTFsector1, EMTFLink1, old_strip, clustersize, global_phi, global_theta));
250  std::shared_ptr<l1t::CPPFDigi> MainVariables2(new l1t::CPPFDigi(rpcId, Bx , (*cppf).int_phi, (*cppf).int_theta, isValid, (*cppf).lb, (*cppf).halfchannel, EMTFsector2, EMTFLink2, old_strip, clustersize, global_phi, global_theta));
251 
252  if ((EMTFsector1 > 0) && (EMTFsector2 == 0)){
253  cppfDigis.push_back(*MainVariables1.get());
254  }
255  else if ((EMTFsector1 > 0) && (EMTFsector2 > 0)){
256  cppfDigis.push_back(*MainVariables1.get());
257  cppfDigis.push_back(*MainVariables2.get());
258  }
259  else if ((EMTFsector1 == 0) && (EMTFsector2 == 0)) {
260  continue;
261  }
262  } //Geo is true
263  else {
264  global_phi = 0.;
265  global_theta = 0.;
266  std::shared_ptr<l1t::CPPFDigi> MainVariables1(new l1t::CPPFDigi(rpcId, Bx , (*cppf).int_phi, (*cppf).int_theta, isValid, (*cppf).lb, (*cppf).halfchannel, EMTFsector1, EMTFLink1, old_strip, clustersize, global_phi, global_theta));
267  std::shared_ptr<l1t::CPPFDigi> MainVariables2(new l1t::CPPFDigi(rpcId, Bx , (*cppf).int_phi, (*cppf).int_theta, isValid, (*cppf).lb, (*cppf).halfchannel, EMTFsector2, EMTFLink2, old_strip, clustersize, global_phi, global_theta));
268  if ((EMTFsector1 > 0) && (EMTFsector2 == 0)){
269  cppfDigis.push_back(*MainVariables1.get());
270  }
271  else if ((EMTFsector1 > 0) && (EMTFsector2 > 0)){
272  cppfDigis.push_back(*MainVariables1.get());
273  cppfDigis.push_back(*MainVariables2.get());
274  }
275  else if ((EMTFsector1 == 0) && (EMTFsector2 == 0)) {
276  continue;
277  }
278  }
279  } //Condition to save the CPPFDigi
280  } //Loop over the LUTVector
281  } //Loop over the recHits
282  } // End loop: for (std::vector<const RPCRoll*>::const_iterator r = rolls.begin(); r != rolls.end(); ++r)
283  } // End loop: for (TrackingGeometry::DetContainer::const_iterator iDet = rpcGeom->dets().begin(); iDet < rpcGeom->dets().end(); iDet++)
284 
285 }
286 
287 
289  const edm::Event& iEvent,
290  const edm::EventSetup& iSetup,
291  const edm::EDGetToken& recHitToken,
292  l1t::CPPFDigiCollection& cppfDigis
293  ) const {
294 
295  // Get the RPC Geometry
297  iSetup.get<MuonGeometryRecord>().get(rpcGeom);
298 
299  // Get the RecHits from the event
301  iEvent.getByToken(recHitToken, recHits);
302 
303 
304  std::map <std::pair<int, int>, int> chamber_repetitions;
305  chamber_repetitions.clear();
306  // The loop is over the detector container in the rpc geometry collection. We are interested in the RPDdetID (inside of RPCChamber vectors), specifically, the RPCrechits. to assignment the CPPFDigis.
307  for ( TrackingGeometry::DetContainer::const_iterator iDet = rpcGeom->dets().begin(); iDet < rpcGeom->dets().end(); iDet++ ) {
308 
309  // we do a cast over the class RPCChamber to obtain the RPCroll vectors, inside of them, the RPCRechits are found. in other words, the method ->rolls() does not exist for other kind of vector within DetContainer and we can not obtain the rpcrechits in a suitable way.
310  if (dynamic_cast<const RPCChamber*>( *iDet ) == nullptr ) continue;
311 
312  auto chamb = dynamic_cast<const RPCChamber* >( *iDet );
313  std::vector<const RPCRoll*> rolls = (chamb->rolls());
314 
315  // Loop over rolls in the chamber
316  for(auto& iRoll : rolls){
317 
318  RPCDetId rpcId = (*iRoll).id();
319 
320  typedef std::pair<RPCRecHitCollection::const_iterator, RPCRecHitCollection::const_iterator> rangeRecHits;
321  rangeRecHits recHitCollection = recHits->get(rpcId);
322 
323 
324  for (RPCRecHitCollection::const_iterator rechit_it = recHitCollection.first; rechit_it != recHitCollection.second; rechit_it++) {
325 
326  //const RPCDetId& rpcId = rechit_it->rpcId();
327  int station = rpcId.station();
328  int ring = rpcId.ring();
329  int region = rpcId.region();
330  int Bx = rechit_it->BunchX();
331  int isValid = rechit_it->isValid();
332  int firststrip = rechit_it->firstClusterStrip();
333  int clustersize = rechit_it->clusterSize();
334  LocalPoint lPos = rechit_it->localPosition();
335  const RPCRoll* roll = rpcGeom->roll(rpcId);
336  const BoundPlane& rollSurface = roll->surface();
337  GlobalPoint gPos = rollSurface.toGlobal(lPos);
338  float global_theta = emtf::rad_to_deg(gPos.theta().value());
339  float global_phi = emtf::rad_to_deg(gPos.phi().value());
340  //Endcap region only
341 
342  if (region != 0) {
343 
344  int int_theta = (region == -1 ? 180. * 32. / 36.5 : 0.)
345  + (float)region * global_theta * 32. / 36.5
346  - 8.5 * 32 / 36.5;
347 
348  if(region == 1) {
349  if(global_theta < 8.5) int_theta = 0;
350  if(global_theta > 45.) int_theta = 31;
351  }
352  else if(region == -1) {
353  if(global_theta < 135.) int_theta = 31;
354  if(global_theta > 171.5) int_theta = 0;
355  }
356  //Chamber ID
357  int nsub = 6;
358  (ring == 1 && station > 1) ? nsub = 3 : nsub = 6;
359  int chamberID = rpcId.subsector() + nsub * ( rpcId.sector() - 1);
360 
361  //Local EMTF
362  double local_phi = 0.;
363  int EMTFsector1 = 0;
364  int EMTFsector2 = 0;
365 
366  //sector 1
367  if ((global_phi > 15.) && (global_phi <= 16.3)) {
368  local_phi = global_phi-15.;
369  EMTFsector1 = 1;
370  EMTFsector2 = 6;
371  }
372  else if ((global_phi > 16.3) && (global_phi <= 53.)) {
373  local_phi = global_phi-15.;
374  EMTFsector1 = 1;
375  EMTFsector2 = 0;
376  }
377  else if ((global_phi > 53.) && (global_phi <= 75.)) {
378  local_phi = global_phi-15.;
379  EMTFsector1 = 1;
380  EMTFsector2 = 2;
381  }
382  //sector 2
383  else if ((global_phi > 75.) && (global_phi <= 76.3)) {
384  local_phi = global_phi-15.;
385  EMTFsector1 = 1;
386  EMTFsector2 = 2;
387  }
388  else if ((global_phi > 76.3) && (global_phi <= 113.)) {
389  local_phi = global_phi-75.;
390  EMTFsector1 = 2;
391  EMTFsector2 = 0;
392  }
393  else if ((global_phi > 113.) && (global_phi <= 135.)) {
394  local_phi = global_phi-75.;
395  EMTFsector1 = 2;
396  EMTFsector2 = 3;
397  }
398  //sector 3
399  //less than 180
400  else if ((global_phi > 135.) && (global_phi <= 136.3)) {
401  local_phi = global_phi-75.;
402  EMTFsector1 = 2;
403  EMTFsector2 = 3;
404  }
405  else if ((global_phi > 136.3) && (global_phi <= 173.)) {
406  local_phi = global_phi-135.;
407  EMTFsector1 = 3;
408  EMTFsector2 = 0;
409  }
410  else if ((global_phi > 173.) && (global_phi <= 180.)) {
411  local_phi = global_phi-135.;
412  EMTFsector1 = 3;
413  EMTFsector2 = 4;
414  }
415  //Greater than -180
416  else if ((global_phi < -165.) && (global_phi >= -180.)) {
417  local_phi = global_phi+225.;
418  EMTFsector1 = 3;
419  EMTFsector2 = 4;
420  }
421  //Fourth sector
422  else if ((global_phi > -165.) && (global_phi <= -163.7)) {
423  local_phi = global_phi+225.;
424  EMTFsector1 = 3;
425  EMTFsector2 = 4;
426  }
427  else if ((global_phi > -163.7) && (global_phi <= -127.)) {
428  local_phi = global_phi+165.;
429  EMTFsector1 = 4;
430  EMTFsector2 = 0;
431  }
432  else if ((global_phi > -127.) && (global_phi <= -105.)) {
433  local_phi = global_phi+165.;
434  EMTFsector1 = 4;
435  EMTFsector2 = 5;
436  }
437  //fifth sector
438  else if ((global_phi > -105.) && (global_phi <= -103.7)) {
439  local_phi = global_phi+165.;
440  EMTFsector1 = 4;
441  EMTFsector2 = 5;
442  }
443  else if ((global_phi > -103.7) && (global_phi <= -67.)) {
444  local_phi = global_phi+105.;
445  EMTFsector1 = 5;
446  EMTFsector2 = 0;
447  }
448  else if ((global_phi > -67.) && (global_phi <= -45.)) {
449  local_phi = global_phi+105.;
450  EMTFsector1 = 5;
451  EMTFsector2 = 6;
452  }
453  //sixth sector
454  else if ((global_phi > -45.) && (global_phi <= -43.7)) {
455  local_phi = global_phi+105.;
456  EMTFsector1 = 5;
457  EMTFsector2 = 6;
458  }
459  else if ((global_phi > -43.7) && (global_phi <= -7.)) {
460  local_phi = global_phi+45.;
461  EMTFsector1 = 6;
462  EMTFsector2 = 0;
463  }
464  else if ((global_phi > -7.) && (global_phi <= 15.)) {
465  local_phi = global_phi+45.;
466  EMTFsector1 = 6;
467  EMTFsector2 = 1;
468  }
469 
470  int int_phi = int((local_phi + 22.0 )*15. + .5);
471 
472  double EMTFLink1 = 0.;
473  double EMTFLink2 = 0.;
474  double lb = 0.;
475  double halfchannel = 0.;
476 
477  //Invalid hit
478  if (isValid == 0) int_phi = 2047;
479  //Right integers range
480  assert(0 <= int_phi && int_phi < 1250);
481  assert(0 <= int_theta && int_theta < 32);
482 
483  //Information for save cluster (2) per chamber
484  std::pair<int, int> temporal;
485  temporal = std::make_pair (station, chamberID);
486 
487 
488  std::map<std::pair<int, int>, int>::iterator it;
489  it = chamber_repetitions.find(temporal);
490 
491  if(it == chamber_repetitions.end()){
492  chamber_repetitions[temporal] = 1;
493  }
494  else if((it != chamber_repetitions.end()) && (chamber_repetitions[temporal] == 1)){
495  chamber_repetitions[temporal] = 2;
496  }
497  else if((it != chamber_repetitions.end()) && (chamber_repetitions[temporal] == 2)){
498  continue;
499  }
500 
501  std::shared_ptr<l1t::CPPFDigi> MainVariables1(new l1t::CPPFDigi(rpcId, Bx , int_phi, int_theta, isValid, lb, halfchannel, EMTFsector1, EMTFLink1, firststrip, clustersize, global_phi, global_theta));
502  std::shared_ptr<l1t::CPPFDigi> MainVariables2(new l1t::CPPFDigi(rpcId, Bx , int_phi, int_theta, isValid, lb, halfchannel, EMTFsector2, EMTFLink2, firststrip, clustersize, global_phi, global_theta));
503  if(int_theta == 31) continue;
504  if ((EMTFsector1 > 0) && (EMTFsector2 == 0)){
505  cppfDigis.push_back(*MainVariables1.get());
506  }
507  if ((EMTFsector1 > 0) && (EMTFsector2 > 0)){
508  cppfDigis.push_back(*MainVariables1.get());
509  cppfDigis.push_back(*MainVariables2.get());
510  }
511  if ((EMTFsector1 == 0) && (EMTFsector2 == 0)){
512  continue;
513  }
514  } // No barrel rechits
515 
516  } // End loop: for (RPCRecHitCollection::const_iterator recHit = recHitCollection.first; recHit != recHitCollection.second; recHit++)
517 
518  } // End loop: for (std::vector<const RPCRoll*>::const_iterator r = rolls.begin(); r != rolls.end(); ++r)
519  } // End loop: for (TrackingGeometry::DetContainer::const_iterator iDet = rpcGeom->dets().begin(); iDet < rpcGeom->dets().end(); iDet++)
520 } // End function: void RecHitProcessor::process()
521 
522 
523 
524 
525 
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
#define nullptr
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
int iEvent
Definition: GenABIO.cc:230
int ring() const
Definition: RPCDetId.h:72
CSCDetId chamberID(const CSCDetId &cscDetId)
takes layer ID, converts to chamber ID, switching ME1A to ME11
Definition: CSCDigiToRaw.cc:31
void processLook(const edm::Event &iEvent, const edm::EventSetup &iSetup, const edm::EDGetToken &recHitToken, std::vector< RecHitProcessor::CppfItem > &CppfVec1, l1t::CPPFDigiCollection &cppfDigis, const int MaxClusterSize) const
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: RPCGeometry.cc:33
const T & get() const
Definition: EventSetup.h:59
void process(const edm::Event &iEvent, const edm::EventSetup &iSetup, const edm::EDGetToken &recHitToken, l1t::CPPFDigiCollection &cppfDigis) const
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
int subsector() const
SubSector id : some sectors are divided along the phi direction in subsectors (from 1 to 4 in Barrel...
Definition: RPCDetId.h:114
double rad_to_deg(double rad)
Definition: TrackTools.h:55
std::vector< CPPFDigi > CPPFDigiCollection
Definition: CPPFDigi.h:68
const RPCRoll * roll(RPCDetId id) const
Return a roll given its id.
Definition: RPCGeometry.cc:75
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96