CMS 3D CMS Logo

GEMCSCSegmentBuilder.cc
Go to the documentation of this file.
1 
9 
10 
14 
21 
31 
32 
34  // Ask factory to build this algorithm, giving it appropriate ParameterSet
36  ps.getParameter<edm::ParameterSet>("algo_psets"))},
37  gemgeom_{nullptr}, cscgeom_{nullptr}
38 {
39  edm::LogVerbatim("GEMCSCSegmentBuilder")<< "[GEMCSCSegmentBuilder :: ctor] algorithm name: " << ps.getParameter<std::string>("algo_name");
40 }
41 
43 {
44  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: dstor] deleted the algorithm";
45 }
46 
48 {
49 
50  for (TrackingGeometry::DetContainer::const_iterator it=gemGeo->dets().begin();it<gemGeo->dets().end();it++)
51  {
52  const GEMChamber* ch = dynamic_cast< const GEMChamber* >( *it );
53  if(ch != nullptr )
54  {
55  std::vector< const GEMEtaPartition*> rolls = (ch->etaPartitions());
56  for(std::vector<const GEMEtaPartition*>::const_iterator r = rolls.begin(); r != rolls.end(); ++r)
57  {
58  GEMDetId gemId = (*r)->id();
59  int region=gemId.region();
60  if(region!=0)
61  {
62  int station = gemId.station();
63  int ring = gemId.ring();
64  int gemchamber = gemId.chamber();
65  int layer = gemId.layer();
66  int cscring = ring;
67  int cscstation = station;
68  int cscchamber = gemchamber;
69  int csclayer = layer;
70  CSCStationIndex ind(region,cscstation,cscring,cscchamber,csclayer);
71  std::set<GEMDetId> myrolls;
72  if (rollstoreCSC.find(ind)!=rollstoreCSC.end()) myrolls=rollstoreCSC[ind];
73  myrolls.insert(gemId);
74  rollstoreCSC[ind]=myrolls;
75  }
76  }
77  }
78  }
79 
80  // edm::LogVerbatim to print details of std::map< CSCIndex, std::set<GEMRolls> >
81  for(std::map<CSCStationIndex,std::set<GEMDetId> >::iterator mapit = rollstoreCSC.begin();
82  mapit != rollstoreCSC.end(); ++mapit)
83  {
84  CSCStationIndex map_first = mapit->first;
85  std::set<GEMDetId> map_secnd = mapit->second;
86  std::stringstream GEMRollsstream;
87  for(std::set<GEMDetId>::iterator setit=map_secnd.begin(); setit!=map_secnd.end(); ++setit)
88  {
89  GEMRollsstream<<"[ GEM Id: "<<setit->rawId()<<" ("<<*setit<<")"<<"],"<<std::endl;
90  }
91  std::string GEMRollsstr = GEMRollsstream.str();
92  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: LinkGEMRollsToCSCChamberIndex] CSC Station Index :: ["
93  <<map_first.region()<<","<<map_first.station()<<","<<map_first.ring()<<","<<map_first.chamber()<<","<<map_first.layer()
94  <<"] has following GEM rolls: ["<<GEMRollsstr<<"]"<<std::endl;
95  }
96 }
97 
99 {
100 
101  edm::LogVerbatim("GEMCSCSegmentBuilder")<< "[GEMCSCSegmentBuilder :: build] Total number of GEM rechits in this event: " << recHits->size()
102  << " Total number of CSC segments in this event: " << cscsegments->size();
103 
104  // Structure of the build function:
105  // --------------------------------
106  // The build function is called once per Event
107  // It loops over CSC Segment Collection and
108  // - identifies the CSC Chambers with segments
109  // - searches for rechits in GEM rolls associared
110  // - creates CSC segment collection with GEM RecHits associated (1)
111  // - creates CSC segment collection without GEM RecHits associated (2)
112  // then
113  // - passes CSC segment collection (1) and GEM rechits to segment builder
114  // - makes a copy of CSC segment collection (2) and push it in the GEMCSC Segment collection
115 
116 
117  // GEM Roll can contain more than one rechit --> therefore create map <detId, vector<GEMRecHit> >
118  // CSC Chamber can contain more than one segment --> therefore create map <detId, vector<CSCSegment> >
119  std::map<uint32_t, std::vector<GEMRecHit*> > gemRecHitCollection;
120  std::map<uint32_t, std::vector<const CSCSegment*> > cscSegColl_GEM11;
121  std::map<uint32_t, std::vector<const CSCSegment*> > cscSegColl_noGEM;
122 
123 
124 
125  // === Loop over CSC Segment Collection ===
126  // ========================================
127  for(CSCSegmentCollection::const_iterator segmIt = cscsegments->begin(); segmIt != cscsegments->end(); ++segmIt)
128  {
129  CSCDetId CSCId = segmIt->cscDetId();
130 
131  // Search for Matches between GEM Roll and CSC Chamber
132  // - only matches between ME1/1(a&b) and GE1/1
133  // - notation: CSC ring 1 = ME1/1b; CSC ring 4 = ME1/1a
134 
135 
136  // Case A :: ME1/1 Segments can have GEM Rechits associated to them
137  // ================================================================
138  if(CSCId.station()==1 && (CSCId.ring()==1 || CSCId.ring()==4))
139  {
140 
141  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] Found ME1/1 Segment in "<<CSCId.rawId()<<" = "<<CSCId<<std::endl;
142 
143  // 1) Save the CSC Segment in CSC segment collection
144  // -------------------------------------------------
145  // get CSC segment vector associated to this CSCDetId
146  // if no vector is associated yet to this CSCDetId, create empty vector
147  // then add the segment to the vector
148  // and assign the vector again to the CSCDetId
149  std::vector<const CSCSegment* > cscsegmentvector = cscSegColl_GEM11[CSCId.rawId()];
150  cscsegmentvector.push_back(segmIt->clone());
151  cscSegColl_GEM11[CSCId.rawId()]=cscsegmentvector;
152 
153  // 2) Make a vector of GEM DetIds associated to this CSC chamber of the segment
154  // ----------------------------------------------------------------------------
155  std::vector<GEMDetId> rollsForThisCSCvector;
156 
157  int cscRegion = CSCId.endcap();
158  int cscStation = CSCId.station();
159  int cscChamber = CSCId.chamber();
160  int gemRegion = 1; if(cscRegion==2) gemRegion= -1; // CSC Endcaps are numbered 1,2; GEM Endcaps are numbered +1, -1
161  int gemRing = 1; // this we can hardcode, only GEMs in Ring 1
162  int gemStation = cscStation;
163 
164  int gem1stChamber = cscChamber;
165  // Just adding also neighbouring chambers here is not enough to get the GEM-CSC segment looking at overlapping chambers
166  // Need to disentangle the use of the CSC chamber and GEM roll in the GEMCSCSegFit class
167  // For now just ignore the neighbouring chambers and keep code commented out ... at later point we will include it again
168  // int gem2ndChamber = gem1stChamber+1; if(gem2ndChamber>36) gem2ndChamber-=36; // neighbouring GEM chamber X+1
169  // int gem3rdChamber = gem1stChamber-1; if(gem2ndChamber<1) gem2ndChamber+=36; // neighbouring GEM chamber X-1
170 
171  std::vector<CSCStationIndex> indexvector;
172  CSCStationIndex index11(gemRegion,gemStation,gemRing,gem1stChamber,1); // GEM Chamber Layer 1
173  CSCStationIndex index12(gemRegion,gemStation,gemRing,gem1stChamber,2); // GEM Chamber Layer 2
174  indexvector.push_back(index11); indexvector.push_back(index12);
175  // for now not inserting neighbouring chambers and keep code commented out ... at later point we will include it again
176  // CSCStationIndex index21(gemRegion,gemStation,gemRing,gem2ndChamber,1); CSCStationIndex index22(gemRegion,gemStation,gemRing,gem2ndChamber,2);
177  // CSCStationIndex index31(gemRegion,gemStation,gemRing,gem3rdChamber,1); CSCStationIndex index32(gemRegion,gemStation,gemRing,gem3rdChamber,2);
178  // indexvector.push_back(index21); indexvector.push_back(index22);
179  // indexvector.push_back(index31); indexvector.push_back(index32);
180 
181  for(std::vector<CSCStationIndex>::iterator cscIndexIt=indexvector.begin(); cscIndexIt!=indexvector.end(); ++cscIndexIt)
182  {
183  std::set<GEMDetId> rollsForThisCSC = rollstoreCSC[*cscIndexIt];
184  for (std::set<GEMDetId>::iterator gemRollIt = rollsForThisCSC.begin(); gemRollIt != rollsForThisCSC.end(); ++gemRollIt)
185  {
186  rollsForThisCSCvector.push_back(*gemRollIt);
187  }
188  }
189 
190 
191  // 3) Loop over GEM Rechits
192  // ------------------------
193  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] Start Loop over GEM Rechits :: size = "<<recHits->size()
194  <<" and number of Rolls for this CSC :: "<<rollsForThisCSCvector.size()<<std::endl;
195  for(GEMRecHitCollection::const_iterator hitIt = recHits->begin(); hitIt != recHits->end(); ++hitIt)
196  {
197  GEMDetId gemIdfromHit = hitIt->gemId();
198 
199  // Loop over GEM rolls being pointed by a CSC segment and look for a match
200  for (std::vector<GEMDetId>::iterator gemRollIt = rollsForThisCSCvector.begin(); gemRollIt != rollsForThisCSCvector.end(); ++gemRollIt)
201  {
202 
203  GEMDetId gemIdfromCSC(*gemRollIt);
204  if(gemIdfromHit == gemIdfromCSC.rawId())
205  {
206  // get GEM RecHit vector associated to this CSC DetId
207  // if no vector is associated yet to this CSC DetId, create empty vector
208  // then add the rechits to the vector
209  // and assign the vector again to the CSC DetId
210  std::vector<GEMRecHit* > gemrechitvector = gemRecHitCollection[CSCId.rawId()];
211  // check whether this hit was already filled in the gemrechit vector
212  bool hitfound = false;
213  for(std::vector<GEMRecHit*>::const_iterator it=gemrechitvector.begin(); it!=gemrechitvector.end(); ++it)
214  {
215  if(hitIt->gemId()==(*it)->gemId() && hitIt->localPosition()==(*it)->localPosition()) hitfound=true;
216  }
217  if(!hitfound) gemrechitvector.push_back(hitIt->clone());
218  gemRecHitCollection[CSCId.rawId()]=gemrechitvector;
219  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] GEM Rechit in "<<hitIt->gemId()<< "["<<hitIt->gemId().rawId()
220  <<"] added to CSC segment found in "<<CSCId<<" ["<<CSCId.rawId()<<"]"<<std::endl;
221  }
222  } // end Loop over GEM Rolls
223  } // end Loop over GEM RecHits
224  } // end requirement of CSC segment in ME1/1
225 
226 
227  // Case B :: all other CSC Chambers have no GEM Chamber associated
228  // ===============================================================
229  else if(!(CSCId.station()==1 && (CSCId.ring()==1 || CSCId.ring()==4)))
230  {
231 
232  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] Found non-ME1/1 Segment in "<<CSCId.rawId()<<" = "<<CSCId<<std::endl;
233 
234  // get CSC segment vector associated to this CSCDetId
235  // if no vector is associated yet to this CSCDetId, create empty vector
236  // then add the segment to the vector
237  // and assign the vector again to the CSCDetId
238  std::vector<const CSCSegment* > cscsegmentvector_noGEM = cscSegColl_noGEM[CSCId.rawId()];
239  cscsegmentvector_noGEM.push_back(segmIt->clone());
240  cscSegColl_noGEM[CSCId.rawId()]=cscsegmentvector_noGEM;
241  }
242 
243  else {} // no other option
244 
245  } // end Loop over csc segments
246 
247 
248 
249  // === Now pass CSC Segments and GEM RecHits to the Segment Algorithm ===
250  // ======================================================================
251 
252  // Here we do the first modification to the code of Raffaella
253  //
254  // Raffaella's code loops over the CSC Segments and assign GEM Rechits to them
255  // Then it loops over the GemRechits and does the segmentbuilding using the
256  // GEM Rechits and the assigned CSC segment. Now this relationship is not a one-to-one relationship (bijection)
257  // In case there are more than 1 segment in the CSC, we have no control that the right supersegment is built
258  //
259  // Now we have a particular case where two muons passed through ME1/1,
260  // resulting in 4 segments (2 real ones and 2 ghosts)
261  // In this case the gemrechits are assigned to all 4 CSC segments
262  // but the supersegment is only constructed once, instead of 4 trials,
263  // resulting in 2 supersegments
264  //
265  // This is something I will change in the GEMCSCSegAlgoRR
266  // In GEMCSCSegmentBuilder we just give all CSC segments and all GEM Rechits
267  // belonging to one CSC chamber to the GEMCSC Segment Algo
268 
269  // case A :: Look for GEM Rechits associated to CSC Segments
270  // =========================================================
271  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] Run over the gemRecHitCollection (size = "<<gemRecHitCollection.size()<<") and build GEMCSC Segments";
272  for(auto gemHitIt=gemRecHitCollection.begin(); gemHitIt != gemRecHitCollection.end(); ++gemHitIt)
273  {
274 
275  CSCDetId cscId(gemHitIt->first);
276 
277  // hits
278  std::vector<const CSCSegment*> cscSegments = cscSegColl_GEM11[cscId.rawId()];
279  std::vector<const GEMRecHit*> gemRecHits;
280  // dets
281  std::map<uint32_t, const CSCLayer* > cscLayers;
282  std::map<uint32_t, const GEMEtaPartition* > gemEtaPartitions;
283 
284  // fill dets for CSC
285  std::vector<const CSCLayer*> cscLayerVector = cscgeom_->chamber(cscId.rawId())->layers();
286  for(std::vector<const CSCLayer*>::const_iterator layIt = cscLayerVector.begin(); layIt != cscLayerVector.end(); ++layIt)
287  {
288  cscLayers[(*layIt)->id()] = cscgeom_->layer((*layIt)->id());
289  }
290 
291  // fill dets & hits for GEM
292  for(auto rechit = gemHitIt->second.begin(); rechit != gemHitIt->second.end(); ++rechit)
293  {
294  GEMDetId gemid = (*rechit)->gemId();
295  gemRecHits.push_back(*rechit);
296  gemEtaPartitions[gemid.rawId()] = gemgeom_->etaPartition(gemid.rawId());
297  }
298 
299  // LogDebug
300  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] ask SegmentAlgo to be run :: CSC DetId "<<cscId.rawId()<<" = "<<cscId
301  <<" with "<<cscSegments.size()<<" CSC segments and "<<gemRecHits.size()<<" GEM rechits";
302 
303  // Ask the Segment Algorithm to build a GEMCSC Segment
304  std::vector<GEMCSCSegment> segmentvector = algo->run(cscLayers, gemEtaPartitions, cscSegments, gemRecHits);
305 
306  // --- LogDebug --------------------------------------------------------
307  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] SegmentAlgo ran, now trying to add the segments from the returned GEMCSCSegment vector (with size = "
308  <<segmentvector.size()<<") to the master collection";
309  std::stringstream segmentvectorss; segmentvectorss<<"[GEMCSCSegmentBuilder :: build] :: GEMCSC segmentvector :: elements ["<<std::endl;
310  for(std::vector<GEMCSCSegment>::const_iterator segIt = segmentvector.begin(); segIt != segmentvector.end(); ++segIt)
311  {
312  segmentvectorss<<"[GEMCSC Segment details: \n"<<*segIt<<"],"<<std::endl;
313  }
314  segmentvectorss<<"]";
315  std::string segmentvectorstr = segmentvectorss.str();
316  edm::LogVerbatim("GEMCSCSegmentBuilder") << segmentvectorstr;
317  // --- End LogDebug ----------------------------------------------------
318 
319 
320  // Add the segments to master collection
321  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] |--> GEMCSC Segments created, now try to add to the collection :: CSC DetId: "<<cscId.rawId()<<" = "<<cscId
322  <<" added "<<segmentvector.size()<<" GEMCSC Segments";
323  oc.put(cscId, segmentvector.begin(), segmentvector.end());
324  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] |--> GEMCSC Segments added to the collection";
325  }
326 
327 
328  // Case B :: push CSC segments without GEM rechits
329  // associated to them into the GEMCSC Segment Collection
330  // =====================================================
331  // Also for the case where no GEM chamber is associated to the CSC chambers
332  // fill also GEMCSC segment, but this is basically a copy of the CSC segment
333  // this will allow us to use only the GEMCSC segment collection in STA Mu Reco
334  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] Run over the CSC Segment collection without GEM (size = "<<cscSegColl_noGEM.size()
335  <<" CSC chambers with segments) and wrap GEMCSC Segments";
336  for(auto cscSegIt=cscSegColl_noGEM.begin(); cscSegIt != cscSegColl_noGEM.end(); ++cscSegIt)
337  {
338 
339  CSCDetId cscId(cscSegIt->first);
340 
341  std::vector<const GEMRecHit*> gemRecHits_noGEM; // make empty gem rechits vector
342  std::vector<const CSCSegment*> cscSegments_noGEM = cscSegColl_noGEM[cscSegIt->first];
343  std::vector<GEMCSCSegment> segmentvector;
344 
345  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] |--> Run over the CSC Segment vector without GEM (size = "<<cscSegments_noGEM.size()
346  <<" CSC segments) and wrap GEMCSC Segments";
347  for (std::vector<const CSCSegment*>::iterator it=cscSegments_noGEM.begin(); it!=cscSegments_noGEM.end(); ++it)
348  {
349  // wrap the CSC segment in the GEMCSC segment class
350  GEMCSCSegment tmp(*it, gemRecHits_noGEM, (*it)->localPosition(), (*it)->localDirection(), (*it)->parametersError(), (*it)->chi2());
351  segmentvector.push_back(tmp);
352  }
353 
354  // add the segments to the master collection
355  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] |--> CSC Segments wrapped, now try to add to the collection :: CSC DetId: "<<cscId.rawId()<<" = "<<cscId
356  <<" added "<<segmentvector.size()<<" GEMCSC Segments";
357  oc.put(cscId, segmentvector.begin(), segmentvector.end());
358  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] |--> CSC Segments added to the collection";
359  }
360 
361  edm::LogVerbatim("GEMCSCSegmentBuilder")<<"[GEMCSCSegmentBuilder :: build] job done !!!";
362 }
363 
364 
365 void GEMCSCSegmentBuilder::setGeometry(const GEMGeometry* gemgeom, const CSCGeometry* cscgeom)
366 {
367  gemgeom_ = gemgeom;
368  cscgeom_ = cscgeom;
369 }
370 
371 
int chamber() const
Definition: CSCDetId.h:68
T getParameter(std::string const &) const
int chamber() const
Definition: RPCEfficiency.h:74
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
void LinkGEMRollsToCSCChamberIndex(const GEMGeometry *gemgeom, const CSCGeometry *cscgeom)
const CSCGeometry * cscgeom_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
int ring() const
Definition: GEMDetId.h:59
int chamber() const
Chamber id: it identifies a chamber in a ring it goes from 1 to 36.
Definition: GEMDetId.h:74
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:99
int station() const
Definition: RPCEfficiency.h:72
int endcap() const
Definition: CSCDetId.h:93
std::unique_ptr< GEMCSCSegmentAlgorithm > algo
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
GEMCSCSegmentBuilder(const edm::ParameterSet &)
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: GEMGeometry.cc:21
int layer() const
Layer id: each station have two layers of chambers: layer 1 is the inner chamber and layer 2 is the o...
Definition: GEMDetId.h:69
int ring() const
Definition: RPCEfficiency.h:73
int station() const
Station id : the station is the pair of chambers at same disk.
Definition: GEMDetId.h:64
std::map< CSCStationIndex, std::set< GEMDetId > > rollstoreCSC
const std::vector< const GEMEtaPartition * > & etaPartitions() const
Return the eta partitions.
Definition: GEMChamber.cc:39
void build(const GEMRecHitCollection *rechits, const CSCSegmentCollection *cscsegments, GEMCSCSegmentCollection &oc)
int region() const
Region id: 0 for Barrel Not in use, +/-1 For +/- Endcap.
Definition: GEMDetId.h:53
int ring() const
Definition: CSCDetId.h:75
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:133
const GEMGeometry * gemgeom_
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to given DetId.
Definition: CSCGeometry.cc:139
void setGeometry(const GEMGeometry *gemgeom, const CSCGeometry *cscgeom)
int region() const
Definition: RPCEfficiency.h:71
int station() const
Definition: CSCDetId.h:86
T get(const Candidate &c)
Definition: component.h:55