CMS 3D CMS Logo

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