CMS 3D CMS Logo

GEMCSCSegAlgoRR.cc
Go to the documentation of this file.
1 
10 #include "GEMCSCSegAlgoRR.h"
11 #include "GEMCSCSegFit.h"
12 
15 
20 
21 #include <algorithm>
22 #include <cmath>
23 #include <string>
24 #include <iostream>
25 #include <sstream>
26 
27 
28 
32 GEMCSCSegAlgoRR::GEMCSCSegAlgoRR(const edm::ParameterSet& ps) : GEMCSCSegmentAlgorithm(ps), myName("GEMCSCSegAlgoRR"), sfit_(nullptr)
33 {
34  debug = ps.getUntrackedParameter<bool>("GEMCSCDebug");
35  minHitsPerSegment = ps.getParameter<unsigned int>("minHitsPerSegment");
36  preClustering = ps.getParameter<bool>("preClustering");
37  dXclusBoxMax = ps.getParameter<double>("dXclusBoxMax");
38  dYclusBoxMax = ps.getParameter<double>("dYclusBoxMax");
39  preClustering_useChaining = ps.getParameter<bool>("preClusteringUseChaining");
40  dPhiChainBoxMax = ps.getParameter<double>("dPhiChainBoxMax");
41  dThetaChainBoxMax = ps.getParameter<double>("dThetaChainBoxMax");
42  dRChainBoxMax = ps.getParameter<double>("dRChainBoxMax");
43  maxRecHitsInCluster = ps.getParameter<int>("maxRecHitsInCluster");
44 }
45 
46 
47 
52 
53 
54 
58 std::vector<GEMCSCSegment> GEMCSCSegAlgoRR::run( const std::map<uint32_t, const CSCLayer*>& csclayermap, const std::map<uint32_t, const GEMEtaPartition*>& gemrollmap,
59  const std::vector<const CSCSegment*>& cscsegments, const std::vector<const GEMRecHit*>& gemrechits)
60 {
61 
62  // This function is called for each CSC Chamber (ME1/1) associated with a GEM chamber in which GEM Rechits were found
63  // This means that the csc segment vector can contain more than one segment and that all combinations with the gemrechits have to be tried
64 
65 
66  // assign the maps < detid, geometry object > to the class variables
67  theCSCLayers_ = csclayermap;
68  theGEMEtaParts_ = gemrollmap;
69 
70 
71  // LogDebug info about reading of CSC Chamber map and GEM Eta Partition map
72  edm::LogVerbatim("GEMCSCSegAlgoRR") << "[GEMCSCSegAlgoRR::run] cached the csclayermap and the gemrollmap";
73 
74  // --- LogDebug for CSC Layer map -----------------------------------------
75  std::stringstream csclayermapss; csclayermapss<<"[GEMCSCSegAlgoRR::run] :: csclayermap :: elements ["<<std::endl;
76  for(std::map<uint32_t, const CSCLayer*>::const_iterator mapIt = theCSCLayers_.begin(); mapIt != theCSCLayers_.end(); ++mapIt)
77  {
78  csclayermapss<<"[CSC DetId "<<mapIt->first<<" ="<<CSCDetId(mapIt->first)<<", CSC Layer "<<mapIt->second<<" ="<<(mapIt->second)->id()<<"],"<<std::endl;
79  }
80  csclayermapss<<"]"<<std::endl;
81  std::string csclayermapstr = csclayermapss.str();
82  edm::LogVerbatim("GEMCSCSegAlgoRR") << csclayermapstr;
83  // --- End LogDebug -------------------------------------------------------
84 
85  // --- LogDebug for GEM Eta Partition map ---------------------------------
86  std::stringstream gemetapartmapss; gemetapartmapss<<"[GEMCSCSegAlgoRR::run] :: gemetapartmap :: elements ["<<std::endl;
87  for(std::map<uint32_t, const GEMEtaPartition*>::const_iterator mapIt = theGEMEtaParts_.begin(); mapIt != theGEMEtaParts_.end(); ++mapIt)
88  {
89  gemetapartmapss<<"[GEM DetId "<<mapIt->first<<" ="<<GEMDetId(mapIt->first)<<", GEM EtaPart "<<mapIt->second<<"],"<<std::endl;
90  }
91  gemetapartmapss<<"]"<<std::endl;
92  std::string gemetapartmapstr = gemetapartmapss.str();
93  edm::LogVerbatim("GEMCSCSegAlgoRR") << gemetapartmapstr;
94  // --- End LogDebug -------------------------------------------------------
95 
96 
97  std::vector<GEMCSCSegment> segmentvectorfinal;
98  std::vector<GEMCSCSegment> segmentvectorchamber;
99  std::vector<GEMCSCSegment> segmentvectorfromfit;
100  std::vector<const TrackingRecHit*> chainedRecHits;
101 
102 
103  // From the GEMCSCSegmentBuilder we get
104  // - a collection of CSC Segments belonging all to the same chamber
105  // - a collection of GEM RecHits belonging to GEM Eta-Partitions close to this CSC
106  //
107  // Now we have to loop over all CSC Segments
108  // and see to which CSC segments we can match the GEM rechits
109  // if matching fails we will still keep those segments in the GEMCSC segment collection
110  // but we will assign -1 to the matched parameter --> 2B implemented in the DataFormat
111  // 1 for matched, 0 for no GEM chamber available and -1 for not matched
112 
113  // empty the temporary gemcsc segments vector
114  // segmentvectortmp.clear();
115 
116  for(std::vector<const CSCSegment*>::const_iterator cscSegIt = cscsegments.begin(); cscSegIt != cscsegments.end(); ++cscSegIt)
117  {
118 
119  // chain hits :: make a vector of TrackingRecHits
120  // that contains the CSC and GEM rechits
121  // and that can be given to the fitter
122  chainedRecHits = this->chainHitsToSegm(*cscSegIt, gemrechits);
123 
124  // if gemrechits are associated, run the buildSegments step
125  if(chainedRecHits.size() > (*cscSegIt)->specificRecHits().size())
126  {
127  segmentvectorfromfit = this->buildSegments(*cscSegIt, chainedRecHits);
128  }
129 
130  // if no gemrechits are associated, wrap the existing CSCSegment in a GEMCSCSegment class
131  else
132  {
133  std::vector<const GEMRecHit*> gemRecHits_noGEMrh; // empty GEMRecHit vector
134  GEMCSCSegment tmp(*cscSegIt, gemRecHits_noGEMrh, (*cscSegIt)->localPosition(), (*cscSegIt)->localDirection(), (*cscSegIt)->parametersError(), (*cscSegIt)->chi2());
135  segmentvectorfromfit.push_back(tmp);
136  }
137 
138  segmentvectorchamber.insert( segmentvectorchamber.end(), segmentvectorfromfit.begin(), segmentvectorfromfit.end() );
139  segmentvectorfromfit.clear();
140  }
141 
142  // add the found gemcsc segments to the collection of all gemcsc segments and return
143  segmentvectorfinal.insert( segmentvectorfinal.end(), segmentvectorchamber.begin(), segmentvectorchamber.end() );
144  segmentvectorchamber.clear();
145  edm::LogVerbatim("GEMCSCSegAlgoRR") << "[GEMCSCSegAlgoRR::run] GEMCSC Segments fitted or wrapped, size of vector = "<<segmentvectorfinal.size();
146  return segmentvectorfinal;
147 }
148 
149 
157 std::vector<const TrackingRecHit*> GEMCSCSegAlgoRR::chainHitsToSegm(const CSCSegment* cscsegment, const std::vector<const GEMRecHit*>& gemrechits)
158 {
159 
160  std::vector<const TrackingRecHit*> chainedRecHits;
161 
162  // working with layers makes it here a bit more difficult:
163  // the CSC segment points to the chamber, which we cannot ask from the map
164  // the CSC rechits point to the layers, from which we can ask the chamber
165 
166  auto segLP = cscsegment->localPosition();
167  auto segLD = cscsegment->localDirection();
168  auto cscrhs = cscsegment->specificRecHits();
169 
170  // Loop over the CSC Segment rechits
171  // and save a copy in the chainedRecHits vector
172  for (auto crh = cscrhs.begin(); crh!= cscrhs.end(); crh++)
173  {
174  chainedRecHits.push_back(crh->clone());
175  }
176 
177  // now ask the layer id of the first CSC rechit
178  std::vector<const TrackingRecHit*>::const_iterator trhIt = chainedRecHits.begin();
179  // make sure pointer is valid
180  if(trhIt == chainedRecHits.end()) {
181  edm::LogVerbatim("GEMCSCSegFit") << "[GEMCSCSegFit::chainHitsToSegm] CSC segment has zero rechits ... end function here";
182  return chainedRecHits;
183  }
184  const CSCLayer * cscLayer = theCSCLayers_.find((*trhIt)->rawId())->second;
185  // now ask the chamber id of the first CSC rechit
186  if(!cscLayer) {
187  edm::LogVerbatim("GEMCSCSegFit") << "[GEMCSCSegFit::chainHitsToSegm] CSC rechit ID was not found back in the CSCLayerMap ... end function here";
188  return chainedRecHits;
189  }
190  const CSCChamber* cscChamber = cscLayer->chamber();
191 
192  // For non-empty GEM rechit vector
193  if(!gemrechits.empty())
194  {
195  float Dphi_min_l1 = 999;
196  float Dphi_min_l2 = 999;
197  float Dtheta_min_l1 = 999;
198  float Dtheta_min_l2 = 999;
199 
200  std::vector<const GEMRecHit*>::const_iterator grhIt = gemrechits.begin();
201 
202  const GEMRecHit* gemrh_min_l1= *grhIt;
203  const GEMRecHit* gemrh_min_l2= *grhIt;
204 
205  // Loop over GEM rechits from the EnsembleGEMHitContainer
206  for(grhIt = gemrechits.begin(); grhIt != gemrechits.end(); ++grhIt)
207  {
208  // get GEM Rechit Local & Global Position
209  auto rhLP = (*grhIt)->localPosition();
210  const GEMEtaPartition* rhRef = theGEMEtaParts_.find((*grhIt)->gemId())->second;
211  auto rhGP = rhRef->toGlobal(rhLP);
212  // get GEM Rechit Local position w.r.t. the CSC Chamber
213  // --> we are interessed in the z-coordinate
214  auto rhLP_inSegmRef = cscChamber->toLocal(rhGP);
215  // calculate the extrapolation of the CSC segment to the GEM plane (z-coord)
216  // to get x- and y- coordinate
217  float xe = 0.0, ye = 0.0, ze = 0.0;
218  if(segLD.z() != 0)
219  {
220  xe = segLP.x()+segLD.x()*rhLP_inSegmRef.z()/segLD.z();
221  ye = segLP.y()+segLD.y()*rhLP_inSegmRef.z()/segLD.z();
222  ze = rhLP_inSegmRef.z();
223  }
224  // 3D extrapolated point in the GEM plane
225  LocalPoint extrPoint(xe,ye,ze);
226 
227  // get GEM Rechit Global Position, but obtained from CSC Chamber
228  // --> this should be the same as rhGP = rhRef->toGlobal(rhLP);
229  auto rhGP_fromSegmRef = cscChamber->toGlobal(rhLP_inSegmRef);
230  float phi_rh = rhGP_fromSegmRef.phi();
231  float theta_rh = rhGP_fromSegmRef.theta();
232  // get Extrapolat Global Position, also obtained from CSC Chamber
233  auto extrPoinGP_fromSegmRef = cscChamber->toGlobal(extrPoint);
234  float phi_ext = extrPoinGP_fromSegmRef.phi();
235  float theta_ext = extrPoinGP_fromSegmRef.theta();
236 
237  // GEM 1st Layer :: Search for GEM Rechit with smallest Delta Eta and Delta Phi
238  // and save it inside gemrh_min_l1
239  if ((*grhIt)->gemId().layer()==1)
240  {
241  float Dphi_l1 = fabs(phi_ext-phi_rh);
242  float Dtheta_l1 = fabs(theta_ext-theta_rh);
243  if (Dphi_l1 <= Dphi_min_l1)
244  {
245  Dphi_min_l1 = Dphi_l1;
246  Dtheta_min_l1 = Dtheta_l1;
247  gemrh_min_l1 = *grhIt;
248  }
249  }
250  // GEM 2nd Layer :: Search for GEM Rechit with smallest Delta Eta and Delta Phi
251  // and save it inside gemrh_min_l2
252  if ((*grhIt)->gemId().layer()==2)
253  {
254  float Dphi_l2 = fabs(phi_ext-phi_rh);
255  float Dtheta_l2 = fabs(theta_ext-theta_rh);
256  if (Dphi_l2 <= Dphi_min_l2)
257  {
258  Dphi_min_l2 = Dphi_l2;
259  Dtheta_min_l2 = Dtheta_l2;
260  gemrh_min_l2 = *grhIt;
261  }
262  }
263 
264  } // end loop over GEM Rechits
265 
266  // Check whether GEM rechit with smallest delta eta and delta phi
267  // w.r.t. the extrapolation of the CSC segment is within the
268  // maxima given by the configuration of the algorithm
269  bool phiRequirementOK_l1 = Dphi_min_l1 < dPhiChainBoxMax;
270  bool thetaRequirementOK_l1 = Dtheta_min_l1 < dThetaChainBoxMax;
271  if(phiRequirementOK_l1 && thetaRequirementOK_l1 && gemrh_min_l1!=nullptr)
272  {
273  chainedRecHits.push_back(gemrh_min_l1->clone());
274  }
275  bool phiRequirementOK_l2 = Dphi_min_l2 < dPhiChainBoxMax;
276  bool thetaRequirementOK_l2 = Dtheta_min_l2 < dThetaChainBoxMax;
277  if(phiRequirementOK_l2 && thetaRequirementOK_l2 && gemrh_min_l2!=nullptr)
278  {
279  chainedRecHits.push_back(gemrh_min_l2->clone());
280  }
281  } // End check > 0 GEM rechits
282 
283  return chainedRecHits;
284 }
285 
286 
287 
293 std::vector<GEMCSCSegment> GEMCSCSegAlgoRR::buildSegments(const CSCSegment* cscsegment, const std::vector<const TrackingRecHit*>& rechits)
294 {
295 
296  std::vector<GEMCSCSegment> gemcscsegmentvector;
297  std::vector<const GEMRecHit*> gemrechits;
298 
299  // Leave the function if the amount of rechits in the EnsembleHitContainer < min required
300  if (rechits.size() < minHitsPerSegment)
301  {
302  return gemcscsegmentvector;
303  }
304 
305  // Extract the GEMRecHits from the TrackingRecHit vector
306  for(std::vector<const TrackingRecHit*>::const_iterator trhIt = rechits.begin(); trhIt!=rechits.end(); ++trhIt)
307  {
308  if (DetId((*trhIt)->rawId()).subdetId() == MuonSubdetId::GEM) { gemrechits.push_back( ((const GEMRecHit*)*trhIt) ); }
309  }
310 
311  // The actual fit on all hits of the vector of the selected Tracking RecHits:
312  delete sfit_;
314  sfit_->fit();
315 
316  // obtain all information necessary to make the segment:
317  LocalPoint protoIntercept = sfit_->intercept();
318  LocalVector protoDirection = sfit_->localdir();
319  AlgebraicSymMatrix protoErrors = sfit_->covarianceMatrix();
320  double protoChi2 = sfit_->chi2();
321 
322  edm::LogVerbatim("GEMCSCSegAlgoRR") << "[GEMCSCSegAlgoRR::buildSegments] fit done, will now try to make GEMCSC Segment from CSC Segment in "<<cscsegment->cscDetId()
323  << " made of "<<cscsegment->specificRecHits().size()<<" rechits and with chi2 = "<<cscsegment->chi2()<<" and with "<<gemrechits.size()<<" GEM RecHits";
324 
325  // save all information inside GEMCSCSegment
326  GEMCSCSegment tmp(cscsegment, gemrechits, protoIntercept, protoDirection, protoErrors, protoChi2);
327 
328  edm::LogVerbatim("GEMCSCSegAlgoRR") << "[GEMCSCSegAlgoRR::buildSegments] GEMCSC Segment made";
329  gemcscsegmentvector.push_back(tmp);
330  return gemcscsegmentvector;
331 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
bool preClustering_useChaining
static constexpr int GEM
Definition: MuonSubdetId.h:15
CSCDetId cscDetId() const
Definition: CSCSegment.h:69
LocalVector localDirection() const override
Local direction.
Definition: CSCSegment.h:41
GEMCSCSegFit * sfit_
LocalPoint localPosition() const override
Return the 3-dimensional local position.
Definition: GEMRecHit.h:53
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
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) override
~GEMCSCSegAlgoRR() override
Destructor.
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
unsigned int minHitsPerSegment
void fit(void)
Definition: GEMCSCSegFit.cc:20
#define nullptr
LocalVector localdir() const
Definition: GEMCSCSegFit.h:129
AlgebraicSymMatrix covarianceMatrix(void)
U second(std::pair< T, U > const &p)
std::vector< GEMCSCSegment > buildSegments(const CSCSegment *cscsegment, const std::vector< const TrackingRecHit * > &rechits)
LocalPoint localPosition() const override
Definition: CSCSegment.h:38
std::map< uint32_t, const GEMEtaPartition * > theGEMEtaParts_
const std::vector< CSCRecHit2D > & specificRecHits() const
Definition: CSCSegment.h:65
Definition: DetId.h:18
std::vector< const TrackingRecHit * > chainHitsToSegm(const CSCSegment *cscsegment, const std::vector< const GEMRecHit * > &gemrechits)
Utility functions.
GEMRecHit * clone() const override
Definition: GEMRecHit.cc:64
bool debug
Configuration parameters.
GEMCSCSegAlgoRR(const edm::ParameterSet &ps)
Constructor.
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double chi2(void) const
Definition: GEMCSCSegFit.h:126
std::map< uint32_t, const CSCLayer * > theCSCLayers_
CLHEP::HepSymMatrix AlgebraicSymMatrix
double chi2() const override
Chi2 of the segment fit.
Definition: CSCSegment.h:57
double dThetaChainBoxMax
T x() const
Definition: PV3DBase.h:62
LocalPoint intercept() const
Definition: GEMCSCSegFit.h:128
const CSCChamber * chamber() const
Definition: CSCLayer.h:52