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