CMS 3D CMS Logo

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