CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  gemgeom_{nullptr},
36  cscgeom_{nullptr} {
37  edm::LogVerbatim("GEMCSCSegmentBuilder")
38  << "[GEMCSCSegmentBuilder :: ctor] algorithm name: " << ps.getParameter<std::string>("algo_name");
39 }
40 
42  edm::LogVerbatim("GEMCSCSegmentBuilder") << "[GEMCSCSegmentBuilder :: dstor] deleted the algorithm";
43 }
44 
46  for (TrackingGeometry::DetContainer::const_iterator it = gemGeo->dets().begin(); it < gemGeo->dets().end(); it++) {
47  const GEMChamber* ch = dynamic_cast<const GEMChamber*>(*it);
48  if (ch != nullptr) {
49  std::vector<const GEMEtaPartition*> rolls = (ch->etaPartitions());
50  for (std::vector<const GEMEtaPartition*>::const_iterator r = rolls.begin(); r != rolls.end(); ++r) {
51  GEMDetId gemId = (*r)->id();
52  int region = gemId.region();
53  if (region != 0) {
54  int station = gemId.station();
55  int ring = gemId.ring();
56  int gemchamber = gemId.chamber();
57  int layer = gemId.layer();
58  int cscring = ring;
59  int cscstation = station;
60  int cscchamber = gemchamber;
61  int csclayer = layer;
62  CSCStationIndex ind(region, cscstation, cscring, cscchamber, csclayer);
63  std::set<GEMDetId> myrolls;
64  if (rollstoreCSC.find(ind) != rollstoreCSC.end())
65  myrolls = rollstoreCSC[ind];
66  myrolls.insert(gemId);
67  rollstoreCSC[ind] = myrolls;
68  }
69  }
70  }
71  }
72 
73  // edm::LogVerbatim to print details of std::map< CSCIndex, std::set<GEMRolls> >
74  for (std::map<CSCStationIndex, std::set<GEMDetId> >::iterator mapit = rollstoreCSC.begin();
75  mapit != rollstoreCSC.end();
76  ++mapit) {
77  CSCStationIndex map_first = mapit->first;
78  std::set<GEMDetId> map_secnd = mapit->second;
79  std::stringstream GEMRollsstream;
80  for (std::set<GEMDetId>::iterator setit = map_secnd.begin(); setit != map_secnd.end(); ++setit) {
81  GEMRollsstream << "[ GEM Id: " << setit->rawId() << " (" << *setit << ")"
82  << "]," << std::endl;
83  }
84  std::string GEMRollsstr = GEMRollsstream.str();
85  edm::LogVerbatim("GEMCSCSegmentBuilder")
86  << "[GEMCSCSegmentBuilder :: LinkGEMRollsToCSCChamberIndex] CSC Station Index :: [" << map_first.region() << ","
87  << map_first.station() << "," << map_first.ring() << "," << map_first.chamber() << "," << map_first.layer()
88  << "] has following GEM rolls: [" << GEMRollsstr << "]" << std::endl;
89  }
90 }
91 
93  const CSCSegmentCollection* cscsegments,
95  edm::LogVerbatim("GEMCSCSegmentBuilder")
96  << "[GEMCSCSegmentBuilder :: build] Total number of GEM rechits in this event: " << recHits->size()
97  << " Total number of CSC segments in this event: " << cscsegments->size();
98 
99  // Structure of the build function:
100  // --------------------------------
101  // The build function is called once per Event
102  // It loops over CSC Segment Collection and
103  // - identifies the CSC Chambers with segments
104  // - searches for rechits in GEM rolls associared
105  // - creates CSC segment collection with GEM RecHits associated (1)
106  // - creates CSC segment collection without GEM RecHits associated (2)
107  // then
108  // - passes CSC segment collection (1) and GEM rechits to segment builder
109  // - makes a copy of CSC segment collection (2) and push it in the GEMCSC Segment collection
110 
111  // GEM Roll can contain more than one rechit --> therefore create map <detId, vector<GEMRecHit> >
112  // CSC Chamber can contain more than one segment --> therefore create map <detId, vector<CSCSegment> >
113  std::map<uint32_t, std::vector<GEMRecHit*> > gemRecHitCollection;
114  std::map<uint32_t, std::vector<const CSCSegment*> > cscSegColl_GEM11;
115  std::map<uint32_t, std::vector<const CSCSegment*> > cscSegColl_noGEM;
116 
117  // === Loop over CSC Segment Collection ===
118  // ========================================
119  for (CSCSegmentCollection::const_iterator segmIt = cscsegments->begin(); segmIt != cscsegments->end(); ++segmIt) {
120  CSCDetId CSCId = segmIt->cscDetId();
121 
122  // Search for Matches between GEM Roll and CSC Chamber
123  // - only matches between ME1/1(a&b) and GE1/1
124  // - notation: CSC ring 1 = ME1/1b; CSC ring 4 = ME1/1a
125 
126  // Case A :: ME1/1 Segments can have GEM Rechits associated to them
127  // ================================================================
128  if (CSCId.station() == 1 && (CSCId.ring() == 1 || CSCId.ring() == 4)) {
129  edm::LogVerbatim("GEMCSCSegmentBuilder")
130  << "[GEMCSCSegmentBuilder :: build] Found ME1/1 Segment in " << CSCId.rawId() << " = " << CSCId << std::endl;
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
218 
219  // Case B :: all other CSC Chambers have no GEM Chamber associated
220  // ===============================================================
221  else if (!(CSCId.station() == 1 && (CSCId.ring() == 1 || CSCId.ring() == 4))) {
222  edm::LogVerbatim("GEMCSCSegmentBuilder") << "[GEMCSCSegmentBuilder :: build] Found non-ME1/1 Segment in "
223  << CSCId.rawId() << " = " << CSCId << std::endl;
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 
234  else {
235  } // no other option
236 
237  } // end Loop over csc segments
238 
239  // === Now pass CSC Segments and GEM RecHits to the Segment Algorithm ===
240  // ======================================================================
241 
242  // Here we do the first modification to the code of Raffaella
243  //
244  // Raffaella's code loops over the CSC Segments and assign GEM Rechits to them
245  // Then it loops over the GemRechits and does the segmentbuilding using the
246  // GEM Rechits and the assigned CSC segment. Now this relationship is not a one-to-one relationship (bijection)
247  // In case there are more than 1 segment in the CSC, we have no control that the right supersegment is built
248  //
249  // Now we have a particular case where two muons passed through ME1/1,
250  // resulting in 4 segments (2 real ones and 2 ghosts)
251  // In this case the gemrechits are assigned to all 4 CSC segments
252  // but the supersegment is only constructed once, instead of 4 trials,
253  // resulting in 2 supersegments
254  //
255  // This is something I will change in the GEMCSCSegAlgoRR
256  // In GEMCSCSegmentBuilder we just give all CSC segments and all GEM Rechits
257  // belonging to one CSC chamber to the GEMCSC Segment Algo
258 
259  // case A :: Look for GEM Rechits associated to CSC Segments
260  // =========================================================
261  edm::LogVerbatim("GEMCSCSegmentBuilder")
262  << "[GEMCSCSegmentBuilder :: build] Run over the gemRecHitCollection (size = " << gemRecHitCollection.size()
263  << ") and build GEMCSC Segments";
264  for (auto gemHitIt = gemRecHitCollection.begin(); gemHitIt != gemRecHitCollection.end(); ++gemHitIt) {
265  CSCDetId cscId(gemHitIt->first);
266 
267  // hits
268  std::vector<const CSCSegment*> cscSegments = cscSegColl_GEM11[cscId.rawId()];
269  std::vector<const GEMRecHit*> gemRecHits;
270  // dets
271  std::map<uint32_t, const CSCLayer*> cscLayers;
272  std::map<uint32_t, const GEMEtaPartition*> gemEtaPartitions;
273 
274  // fill dets for CSC
275  std::vector<const CSCLayer*> cscLayerVector = cscgeom_->chamber(cscId.rawId())->layers();
276  for (std::vector<const CSCLayer*>::const_iterator layIt = cscLayerVector.begin(); layIt != cscLayerVector.end();
277  ++layIt) {
278  cscLayers[(*layIt)->id()] = cscgeom_->layer((*layIt)->id());
279  }
280 
281  // fill dets & hits for GEM
282  for (auto rechit = gemHitIt->second.begin(); rechit != gemHitIt->second.end(); ++rechit) {
283  GEMDetId gemid = (*rechit)->gemId();
284  gemRecHits.push_back(*rechit);
285  gemEtaPartitions[gemid.rawId()] = gemgeom_->etaPartition(gemid.rawId());
286  }
287 
288  // LogDebug
289  edm::LogVerbatim("GEMCSCSegmentBuilder")
290  << "[GEMCSCSegmentBuilder :: build] ask SegmentAlgo to be run :: CSC DetId " << cscId.rawId() << " = " << cscId
291  << " with " << cscSegments.size() << " CSC segments and " << gemRecHits.size() << " GEM rechits";
292 
293  // Ask the Segment Algorithm to build a GEMCSC Segment
294  std::vector<GEMCSCSegment> segmentvector = algo->run(cscLayers, gemEtaPartitions, cscSegments, gemRecHits);
295 
296  // --- LogDebug --------------------------------------------------------
297  edm::LogVerbatim("GEMCSCSegmentBuilder") << "[GEMCSCSegmentBuilder :: build] SegmentAlgo ran, now trying to add "
298  "the segments from the returned GEMCSCSegment vector (with size = "
299  << segmentvector.size() << ") to the master collection";
300  std::stringstream segmentvectorss;
301  segmentvectorss << "[GEMCSCSegmentBuilder :: build] :: GEMCSC segmentvector :: elements [" << std::endl;
302  for (std::vector<GEMCSCSegment>::const_iterator segIt = segmentvector.begin(); segIt != segmentvector.end();
303  ++segIt) {
304  segmentvectorss << "[GEMCSC Segment details: \n" << *segIt << "]," << std::endl;
305  }
306  segmentvectorss << "]";
307  std::string segmentvectorstr = segmentvectorss.str();
308  edm::LogVerbatim("GEMCSCSegmentBuilder") << segmentvectorstr;
309  // --- End LogDebug ----------------------------------------------------
310 
311  // Add the segments to master collection
312  edm::LogVerbatim("GEMCSCSegmentBuilder")
313  << "[GEMCSCSegmentBuilder :: build] |--> GEMCSC Segments created, now try to add to the collection :: CSC "
314  "DetId: "
315  << cscId.rawId() << " = " << cscId << " added " << segmentvector.size() << " GEMCSC Segments";
316  oc.put(cscId, segmentvector.begin(), segmentvector.end());
317  edm::LogVerbatim("GEMCSCSegmentBuilder")
318  << "[GEMCSCSegmentBuilder :: build] |--> GEMCSC Segments added to the collection";
319  }
320 
321  // Case B :: push CSC segments without GEM rechits
322  // associated to them into the GEMCSC Segment Collection
323  // =====================================================
324  // Also for the case where no GEM chamber is associated to the CSC chambers
325  // fill also GEMCSC segment, but this is basically a copy of the CSC segment
326  // this will allow us to use only the GEMCSC segment collection in STA Mu Reco
327  edm::LogVerbatim("GEMCSCSegmentBuilder")
328  << "[GEMCSCSegmentBuilder :: build] Run over the CSC Segment collection without GEM (size = "
329  << cscSegColl_noGEM.size() << " CSC chambers with segments) and wrap GEMCSC Segments";
330  for (auto cscSegIt = cscSegColl_noGEM.begin(); cscSegIt != cscSegColl_noGEM.end(); ++cscSegIt) {
331  CSCDetId cscId(cscSegIt->first);
332 
333  std::vector<const GEMRecHit*> gemRecHits_noGEM; // make empty gem rechits vector
334  std::vector<const CSCSegment*> cscSegments_noGEM = cscSegColl_noGEM[cscSegIt->first];
335  std::vector<GEMCSCSegment> segmentvector;
336 
337  edm::LogVerbatim("GEMCSCSegmentBuilder")
338  << "[GEMCSCSegmentBuilder :: build] |--> Run over the CSC Segment vector without GEM (size = "
339  << cscSegments_noGEM.size() << " CSC segments) and wrap GEMCSC Segments";
340  for (std::vector<const CSCSegment*>::iterator it = cscSegments_noGEM.begin(); it != cscSegments_noGEM.end(); ++it) {
341  // wrap the CSC segment in the GEMCSC segment class
342  GEMCSCSegment tmp(*it,
343  gemRecHits_noGEM,
344  (*it)->localPosition(),
345  (*it)->localDirection(),
346  (*it)->parametersError(),
347  (*it)->chi2());
348  segmentvector.push_back(tmp);
349  }
350 
351  // add the segments to the master collection
352  edm::LogVerbatim("GEMCSCSegmentBuilder")
353  << "[GEMCSCSegmentBuilder :: build] |--> CSC Segments wrapped, now try to add to the collection :: CSC DetId: "
354  << cscId.rawId() << " = " << cscId << " added " << segmentvector.size() << " GEMCSC Segments";
355  oc.put(cscId, segmentvector.begin(), segmentvector.end());
356  edm::LogVerbatim("GEMCSCSegmentBuilder")
357  << "[GEMCSCSegmentBuilder :: build] |--> CSC Segments added to the collection";
358  }
359 
360  edm::LogVerbatim("GEMCSCSegmentBuilder") << "[GEMCSCSegmentBuilder :: build] job done !!!";
361 }
362 
363 void GEMCSCSegmentBuilder::setGeometry(const GEMGeometry* gemgeom, const CSCGeometry* cscgeom) {
364  gemgeom_ = gemgeom;
365  cscgeom_ = cscgeom;
366 }
int chamber() const
Definition: CSCDetId.h:62
Log< level::Info, true > LogVerbatim
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:57
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: GEMGeometry.cc:17
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:77
constexpr std::array< uint8_t, layerIndexSize > layer
int endcap() const
Definition: CSCDetId.h:85
std::unique_ptr< GEMCSCSegmentAlgorithm > algo
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
GEMCSCSegmentBuilder(const edm::ParameterSet &)
constexpr int region() const
Definition: GEMDetId.h:171
std::map< CSCStationIndex, std::set< GEMDetId > > rollstoreCSC
const std::vector< const GEMEtaPartition * > & etaPartitions() const
Return the eta partitions.
Definition: GEMChamber.cc:29
void build(const GEMRecHitCollection *rechits, const CSCSegmentCollection *cscsegments, GEMCSCSegmentCollection &oc)
int ring() const
Definition: CSCDetId.h:68
constexpr int chamber() const
Definition: GEMDetId.h:183
constexpr int ring() const
Definition: GEMDetId.h:176
constexpr int layer() const
Definition: GEMDetId.h:190
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:100
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
constexpr int station() const
Definition: GEMDetId.h:179
const GEMGeometry * gemgeom_
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to given DetId.
Definition: CSCGeometry.cc:105
void setGeometry(const GEMGeometry *gemgeom, const CSCGeometry *cscgeom)
int station() const
Definition: CSCDetId.h:79
#define get
tmp
align.sh
Definition: createJobs.py:716