CMS 3D CMS Logo

SiPixelCalSingleMuonAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DQMOffline/CalibTracker
4 // Class: SiPixelCalSingleMuonAnalyzer
5 //
10 //
11 // Original Author: Marco Musich
12 // Created: Tue, 30 Mar 2021 09:22:07 GMT
13 //
14 //
15 
16 // system include files
17 #include <memory>
18 
19 // user include files
46 
47 //
48 // class declaration
49 //
51 public:
53  ~SiPixelCalSingleMuonAnalyzer() override = default;
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
58  void analyze(const edm::Event&, const edm::EventSetup&) override;
59  void countClusters(const edm::Handle<SiPixelClusterCollectionNew>& handle, unsigned int& nClusGlobal);
60  const bool detidIsOnPixel(const DetId& detid);
61 
64  const PixelClusterParameterEstimator* pixelCPE_,
65  const TrackerGeometry* trackerGeometry_,
66  uint32_t rawId,
67  float traj_lx,
68  float traj_ly);
69 
70  // ----------member data ---------------------------
75 
81 
84 
92  bool phase_;
93 };
94 
95 //
96 // constructors and destructor
97 //
99  : geomEsToken_(esConsumes()),
100  pixelCPEEsToken_(esConsumes(edm::ESInputTag("", "PixelCPEGeneric"))),
101  geomEsTokenBR_(esConsumes<edm::Transition::BeginRun>()),
102  topoEsTokenBR_(esConsumes<edm::Transition::BeginRun>()),
103  clustersToken_(consumes<SiPixelClusterCollectionNew>(iConfig.getParameter<edm::InputTag>("clusterCollection"))),
104  nearByClustersToken_(
105  consumes<SiPixelClusterCollectionNew>(iConfig.getParameter<edm::InputTag>("nearByClusterCollection"))),
106  trajTrackCollectionToken_(
107  consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("trajectoryInput"))),
108  distanceToken_(consumes<edm::ValueMap<std::vector<float>>>(iConfig.getParameter<edm::InputTag>("distToTrack"))),
109  muonTracksToken_(consumes<edm::View<reco::Track>>(iConfig.getParameter<edm::InputTag>("muonTracks"))),
110  dqm_path_(iConfig.getParameter<std::string>("dqmPath")),
111  reader_(edm::FileInPath(iConfig.getParameter<std::string>("skimmedGeometryPath")).fullPath()) {}
112 
113 //
114 // member functions
115 //
116 
117 // ------------ method called for each event ------------
119  using namespace edm;
120 
121  // get the Tracker geometry from event setup
122  const TrackerGeometry* trackerGeometry_ = &iSetup.getData(geomEsToken_);
123 
124  // get the Pixel CPE from event setup
125  const PixelClusterParameterEstimator* pixelCPE_ = &iSetup.getData(pixelCPEEsToken_);
126 
127  // get the muon track collection
128  const auto& muonTrackCollectionHandle = iEvent.getHandle(muonTracksToken_);
129  auto const& muonTracks = *muonTrackCollectionHandle;
130 
131  // get the track distances
132  const auto& distancesToTrack = iEvent.getHandle(distanceToken_);
133 
134  unsigned int nMuons = muonTracks.size();
135  for (unsigned int ij = 0; ij < nMuons; ij++) {
136  auto muon = muonTrackCollectionHandle->ptrAt(ij);
137  edm::RefToBase<reco::Track> trackRef = muonTrackCollectionHandle->refAt(ij);
138  const auto& distances = (*distancesToTrack)[trackRef];
139 
140  LogDebug("SiPixelCalSingleMuonAnalyzer") << "distances size: " << distances.size() << std::endl;
141 
142  unsigned counter = 0;
143  double closestDR = 999.;
144  for (const auto& distance : distances) {
145  counter++;
146  LogDebug("SiPixelCalSingleMuonAnalyzer")
147  << "track: " << counter << " distance:" << std::sqrt(distance) << std::endl;
148  if (distance < closestDR && distance > 0) {
149  closestDR = distance;
150  }
151  }
152 
153  h_distClosestTrack->Fill(std::sqrt(closestDR));
154  }
155 
156  // Get cluster collection
157  const auto& clusterCollectionHandle = iEvent.getHandle(clustersToken_);
158 
159  unsigned int nClusGlobal = 0;
160  countClusters(clusterCollectionHandle, nClusGlobal);
161 
162  h_nALCARECOClusters->Fill(nClusGlobal);
163  LogTrace("SiPixelCalSingleMuonAnalyzer") << "total ALCARECO clusters: " << nClusGlobal << std::endl;
164 
165  // Get nearby cluster collection
166  const auto& nearByClusterCollectionHandle = iEvent.getHandle(nearByClustersToken_);
167 
168  unsigned int nNearByClusGlobal = 0;
169  countClusters(nearByClusterCollectionHandle, nNearByClusGlobal);
170 
171  h_nCloseByClusters->Fill(nNearByClusGlobal);
172  LogTrace("SiPixelCalSingleMuonAnalyzer") << "total close-by clusters: " << nNearByClusGlobal << std::endl;
173 
174  // Get Traj-Track Collection
175  const auto& trajTrackCollectionHandle = iEvent.getHandle(trajTrackCollectionToken_);
176 
177  if (!trajTrackCollectionHandle.isValid())
178  return;
179 
180  for (const auto& pair : *trajTrackCollectionHandle) {
181  const edm::Ref<std::vector<Trajectory>> traj = pair.key;
182  const reco::TrackRef track = pair.val;
183 
184  for (const TrajectoryMeasurement& measurement : traj->measurements()) {
185  if (!measurement.updatedState().isValid())
186  return;
187 
188  const TransientTrackingRecHit::ConstRecHitPointer& recHit = measurement.recHit();
189 
190  // Only looking for pixel hits
191  DetId r_rawId = recHit->geographicalId();
192 
193  if (!this->detidIsOnPixel(r_rawId))
194  continue;
195 
196  // Skipping hits with undeterminable positions
197  TrajectoryStateOnSurface trajStateOnSurface = this->getTrajectoryStateOnSurface(measurement);
198 
199  if (!(trajStateOnSurface.isValid()))
200  continue;
201 
202  // Position measurements
203  // Looking for valid and missing hits
204  LocalPoint localPosition = trajStateOnSurface.localPosition();
205 
206  const auto& traj_lx = localPosition.x();
207  const auto& traj_ly = localPosition.y();
208 
209  const auto loc = this->findClosestCluster(
210  nearByClusterCollectionHandle, pixelCPE_, trackerGeometry_, r_rawId.rawId(), traj_lx, traj_ly);
211 
212  float dist = (loc.first != -999.) ? std::sqrt(loc.first * loc.first + loc.second * loc.second) : -0.1;
213 
214  if (recHit->getType() == TrackingRecHit::valid) {
215  LogTrace("SiPixelCalSingleMuonAnalyzer")
216  << "RawID:" << r_rawId.rawId() << " (valid hit), distance: " << dist << std::endl;
217  h_distClosestValid->Fill(dist);
218  }
219 
220  if (recHit->getType() == TrackingRecHit::missing) {
221  LogTrace("SiPixelCalSingleMuonAnalyzer")
222  << "RawID:" << r_rawId.rawId() << " (missing hit), distance: " << dist << std::endl;
223  h_distClosestMissing->Fill(dist);
224  }
225 
226  if (recHit->getType() == TrackingRecHit::inactive) {
227  LogTrace("SiPixelCalSingleMuonAnalyzer")
228  << "RawID:" << r_rawId.rawId() << " (inactive hit), distance: " << dist << std::endl;
230  }
231  }
232  }
233 }
234 
235 // ------------ method called once each job just before starting event loop ------------
237  // book the overall event count and event types histograms
238  iBooker.setCurrentFolder(dqm_path_ + "/ClusterCounts");
239  h_nALCARECOClusters = iBooker.book1I(
240  "h_nALCARECOClusters", "Number of Pixel clusters per event (ALCARECO) ;N_{clusters};events", 20, 0, 20);
241  h_nCloseByClusters = iBooker.book1I(
242  "h_nCloseByClusters", "Number of Pixel clusters per event (close-by) ;N_{clusters};events", 20, 0, 20);
243 
244  iBooker.setCurrentFolder(dqm_path_ + "/TrajDistance");
246  iBooker.book1D("h_distClosestValid",
247  "Distance of Closest cluster to trajectory (valid);distance (cm); valid trajectory measurements",
248  110,
249  -0.105,
250  0.995);
251  h_distClosestMissing = iBooker.book1D(
252  "h_distClosestMissing",
253  "Distance of Closest cluster to trajectory (missing);distance (cm);missing trajectory measurements",
254  110,
255  -0.105,
256  0.995);
257  h_distClosestInactive = iBooker.book1D(
258  "h_distClosestInactive",
259  "Distance of Closest cluster to trajectory (inactive);distance (cm);inactive trajectory measurements",
260  110,
261  -0.105,
262  0.995);
263 
264  iBooker.setCurrentFolder(dqm_path_ + "/OtherTrackDistance");
266  iBooker.book1D("h_distClosestTrack",
267  "#DeltaR Distance of Closest track to the muon trajectory;#DeltaR distance; muon trajectories",
268  100,
269  0.,
270  5.);
271 }
272 
273 /*--------------------------------------------------------------------*/
275 /*--------------------------------------------------------------------*/
276 {
277  if (detid.det() != DetId::Tracker)
278  return false;
280  return true;
282  return true;
283  return false;
284 }
285 
286 /*--------------------------------------------------------------------*/
288  const TrajectoryMeasurement& measurement)
289 /*--------------------------------------------------------------------*/
290 {
291  const static TrajectoryStateCombiner trajStateCombiner;
292 
293  const auto& forwardPredictedState = measurement.forwardPredictedState();
294  const auto& backwardPredictedState = measurement.backwardPredictedState();
295 
296  if (forwardPredictedState.isValid() && backwardPredictedState.isValid())
297  return trajStateCombiner(forwardPredictedState, backwardPredictedState);
298 
299  else if (backwardPredictedState.isValid())
300  return backwardPredictedState;
301 
302  else if (forwardPredictedState.isValid())
303  return forwardPredictedState;
304 
305  edm::LogError("NearbyPixelClusterProducer") << "Error saving traj. measurement data."
306  << " Trajectory state on surface cannot be determined." << std::endl;
307 
308  return TrajectoryStateOnSurface();
309 }
310 
311 /*--------------------------------------------------------------------*/
313  //const TrackerGeometry* tkGeom_,
314  unsigned int& nClusGlobal)
315 /*--------------------------------------------------------------------*/
316 {
317  for (const auto& DSVItr : *handle) {
318  uint32_t rawid(DSVItr.detId());
319  DetId detId(rawid);
320  LogDebug("SiPixelCalSingleMuonAnalyzer") << "DetId: " << detId.rawId() << " size: " << DSVItr.size() << std::endl;
321  nClusGlobal += DSVItr.size();
322  }
323 }
324 
325 /*--------------------------------------------------------------------*/
328  const PixelClusterParameterEstimator* pixelCPE_,
329  const TrackerGeometry* trackerGeometry_,
330  uint32_t rawId,
331  float traj_lx,
332  float traj_ly)
333 /*--------------------------------------------------------------------*/
334 {
337 
338  float minD = 10e7;
339 
340  auto loc = std::make_pair(-999., -999.);
341 
342  for (; itClusterSet != clusterCollection.end(); itClusterSet++) {
343  DetId detId(itClusterSet->id());
344  if (detId.rawId() != rawId)
345  continue;
346 
347  unsigned int subDetId = detId.subdetId();
349  edm::LogError("NearByPixelClustersAnalyzer")
350  << "ERROR: not a pixel cluster!!!" << std::endl; // should not happen
351  continue;
352  }
353 
354  const PixelGeomDetUnit* pixdet = (const PixelGeomDetUnit*)trackerGeometry_->idToDetUnit(detId);
355  edmNew::DetSet<SiPixelCluster>::const_iterator itCluster = itClusterSet->begin();
356  for (; itCluster != itClusterSet->end(); ++itCluster) {
357  LocalPoint lp(itCluster->x(), itCluster->y(), 0.);
358  PixelClusterParameterEstimator::ReturnType params = pixelCPE_->getParameters(*itCluster, *pixdet);
359  lp = std::get<0>(params);
360 
361  float D = (lp.x() - traj_lx) * (lp.x() - traj_lx) + (lp.y() - traj_ly) * (lp.y() - traj_ly);
362  if (D < minD) {
363  minD = D;
364  loc.first = (lp.x() - traj_lx);
365  loc.second = (lp.y() - traj_ly);
366  }
367  } // loop on cluster sets
368  }
369  return loc;
370 }
371 
372 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
375  desc.setComment("Analysis of the closebyPixelClusters collections");
376  desc.add<edm::InputTag>("clusterCollection", edm::InputTag("ALCARECOSiPixelCalSingleMuonTight"));
377  desc.add<edm::InputTag>("nearByClusterCollection", edm::InputTag("closebyPixelClusters"));
378  desc.add<edm::InputTag>("trajectoryInput", edm::InputTag("refittedTracks"));
379  desc.add<edm::InputTag>("muonTracks", edm::InputTag("ALCARECOSiPixelCalSingleMuonTight"));
380  desc.add<edm::InputTag>("distToTrack", edm::InputTag("trackDistances"));
381  desc.add<std::string>("dqmPath", "SiPixelCalSingleMuonTight");
382  desc.add<std::string>("skimmedGeometryPath",
383  "SLHCUpgradeSimulations/Geometry/data/PhaseI/PixelSkimmedGeometry_phase1.txt");
384  descriptions.addWithDefaultLabel(desc);
385 }
386 
387 //define this as a plug-in
~SiPixelCalSingleMuonAnalyzer() override=default
const edm::EDGetTokenT< edm::View< reco::Track > > muonTracksToken_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::EDGetTokenT< SiPixelClusterCollectionNew > nearByClustersToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
MonitorElement * book1I(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
SiPixelCalSingleMuonAnalyzer(const edm::ParameterSet &)
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
constexpr unsigned int subDetId[21]
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
data_type const * const_iterator
Definition: DetSetNew.h:31
Log< level::Error, false > LogError
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
const edm::EDGetTokenT< TrajTrackAssociationCollection > trajTrackCollectionToken_
key_type key() const
Accessor for product key.
Definition: Ref.h:250
#define LogTrace(id)
const edm::EDGetTokenT< edm::ValueMap< std::vector< float > > > distanceToken_
virtual ReturnType getParameters(const SiPixelCluster &cl, const GeomDetUnit &det) const =0
void Fill(long long x)
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int iEvent
Definition: GenABIO.cc:224
dqm::reco::MonitorElement MonitorElement
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
T sqrt(T t)
Definition: SSEVec.h:19
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomEsTokenBR_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomEsToken_
const edm::ESGetToken< PixelClusterParameterEstimator, TkPixelCPERecord > pixelCPEEsToken_
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void analyze(const edm::Event &, const edm::EventSetup &) override
std::pair< float, float > findClosestCluster(const edm::Handle< SiPixelClusterCollectionNew > &handle, const PixelClusterParameterEstimator *pixelCPE_, const TrackerGeometry *trackerGeometry_, uint32_t rawId, float traj_lx, float traj_ly)
fixed size matrix
HLT enums.
iterator end()
Definition: DetSetNew.h:56
void countClusters(const edm::Handle< SiPixelClusterCollectionNew > &handle, unsigned int &nClusGlobal)
const bool detidIsOnPixel(const DetId &detid)
TrajectoryStateOnSurface getTrajectoryStateOnSurface(const TrajectoryMeasurement &measurement)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::tuple< LocalPoint, LocalError, SiPixelRecHitQuality::QualWordType > ReturnType
Definition: Run.h:45
const edm::EDGetTokenT< SiPixelClusterCollectionNew > clustersToken_
#define LogDebug(id)
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenBR_