CMS 3D CMS Logo

SiStripMonitorApproximateCluster.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DQM/SiStripMonitorApproximateCluster
4 // Class: SiStripMonitorApproximateCluster
5 //
11 //
12 // Original Author: Marco Musich
13 // Created: Thu, 08 Dec 2022 20:51:10 GMT
14 //
15 //
16 
17 #include <string>
18 // for string manipulations
19 #include <fmt/printf.h>
20 
21 // user include files
37 
38 //
39 // class declaration
40 //
41 
42 namespace siStripRawPrime {
44  public:
46  : h_barycenter_{nullptr}, h_width_{nullptr}, h_avgCharge_{nullptr}, h_isSaturated_{nullptr}, isBooked_{false} {}
47 
48  void fill(const SiStripApproximateCluster& cluster) {
49  h_barycenter_->Fill(cluster.barycenter());
50  h_width_->Fill(cluster.width());
51  h_avgCharge_->Fill(cluster.avgCharge());
52  h_isSaturated_->Fill(cluster.isSaturated() ? 1 : -1);
53  }
54 
56  ibook.setCurrentFolder(folder);
58  ibook.book1D("clusterBarycenter", "cluster barycenter;cluster barycenter;#clusters", 7680., 0., 7680.);
59  h_width_ = ibook.book1D("clusterWidth", "cluster width;cluster width;#clusters", 128, -0.5, 127.5);
60  h_avgCharge_ =
61  ibook.book1D("clusterAvgCharge", "average strip charge;average strip charge;#clusters", 256, -0.5, 255.5);
62  h_isSaturated_ = ibook.book1D("clusterSaturation", "cluster saturation;is saturated?;#clusters", 3, -1.5, 1.5);
63  h_isSaturated_->getTH1F()->GetXaxis()->SetBinLabel(1, "Not saturated");
64  h_isSaturated_->getTH1F()->GetXaxis()->SetBinLabel(3, "Saturated");
65  isBooked_ = true;
66  }
67 
68  bool isBooked() { return isBooked_; }
69 
70  private:
75  bool isBooked_;
76  };
77 } // namespace siStripRawPrime
78 
80 public:
82  ~SiStripMonitorApproximateCluster() override = default;
83 
84  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
85 
86 private:
87  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
88 
89  void analyze(const edm::Event&, const edm::EventSetup&) override;
90 
91  // ------------ member data ------------
95 
99 
100  // for comparisons
107 
113 
114  // Event Data
118 
119  // Event Setup Data
121 };
122 
123 //
124 // constructors and destructor
125 //
127  : folder_(iConfig.getParameter<std::string>("folder")),
128  compareClusters_(iConfig.getParameter<bool>("compareClusters")),
129  // Poducer name of input StripClusterCollection
130  approxClustersToken_(consumes<SiStripApproximateClusterCollection>(
131  iConfig.getParameter<edm::InputTag>("ApproxClustersProducer"))) {
133  if (compareClusters_) {
135  consumes<edmNew::DetSetVector<SiStripCluster>>(iConfig.getParameter<edm::InputTag>("ClustersProducer"));
136  }
137  stripClusterCollection_ = nullptr;
138 }
139 
140 //
141 // member functions
142 //
143 
144 // ------------ method called for each event ------------
146  using namespace edm;
147 
148  const auto& tkGeom = &iSetup.getData(tkGeomToken_);
149  const auto tkDets = tkGeom->dets();
150 
151  // get collection of DetSetVector of clusters from Event
152  edm::Handle<SiStripApproximateClusterCollection> approx_cluster_detsetvector;
153  iEvent.getByToken(approxClustersToken_, approx_cluster_detsetvector);
154  if (!approx_cluster_detsetvector.isValid()) {
155  edm::LogError("SiStripMonitorApproximateCluster")
156  << "SiStripApproximate cluster collection is not valid!" << std::endl;
157 
158  // if approximate clusters collection not available, then early return
159  return;
160  }
161 
162  // if requested to perform the comparison
163  if (compareClusters_) {
164  // get collection of DetSetVector of clusters from Event
166  iEvent.getByToken(stripClustersToken_, cluster_detsetvector);
167  if (!cluster_detsetvector.isValid()) {
168  edm::LogError("SiStripMonitorApproximateCluster")
169  << "Requested to perform comparison, but regular SiStrip cluster collection is not valid!" << std::endl;
170  return;
171  } else {
172  stripClusterCollection_ = cluster_detsetvector.product();
173  }
174  }
175 
176  int nApproxClusters{0};
177  const SiStripApproximateClusterCollection* clusterCollection = approx_cluster_detsetvector.product();
178 
179  for (const auto& detClusters : *clusterCollection) {
180  edmNew::DetSet<SiStripCluster> strip_clusters_detset;
181  const auto& detid = detClusters.id(); // get the detid of the current detset
182 
183  // starts here comaparison with regular clusters
184  if (compareClusters_) {
186  stripClusterCollection_->find(detid); // search clusters of same detid
187  strip_clusters_detset = (*isearch);
188  }
189 
190  for (const auto& cluster : detClusters) {
191  nApproxClusters++;
192 
193  // fill the full cluster collection
194  allClusters.fill(cluster);
195 
196  if (compareClusters_ && !strip_clusters_detset.empty()) {
197  // build the converted cluster for the matching
198  uint16_t nStrips{0};
199  auto det = std::find_if(tkDets.begin(), tkDets.end(), [detid](auto& elem) -> bool {
200  return (elem->geographicalId().rawId() == detid);
201  });
202  const StripTopology& p = dynamic_cast<const StripGeomDetUnit*>(*det)->specificTopology();
203  nStrips = p.nstrips() - 1;
204 
205  const auto convertedCluster = SiStripCluster(cluster, nStrips);
206 
207  float distance{9999.};
208  const SiStripCluster* closestCluster{nullptr};
209  for (const auto& stripCluster : strip_clusters_detset) {
210  // by construction the approximated cluster width has same
211  // size as the original cluster
212 
213  if (cluster.width() != stripCluster.size()) {
214  continue;
215  }
216 
217  float deltaBarycenter = convertedCluster.barycenter() - stripCluster.barycenter();
218  if (std::abs(deltaBarycenter) < distance) {
219  closestCluster = &stripCluster;
220  distance = std::abs(deltaBarycenter);
221  }
222  }
223 
224  // Matching criteria:
225  // - if exists a closest cluster in the DetId
226  // - the size coincides with the original one
227  if (closestCluster) {
228  // comparisong plots
229  h_deltaBarycenter_->Fill(closestCluster->barycenter() - convertedCluster.barycenter());
230  h_deltaSize_->Fill(closestCluster->size() - convertedCluster.size());
231  h_deltaCharge_->Fill(closestCluster->charge() - convertedCluster.charge());
232  h_deltaFirstStrip_->Fill(closestCluster->firstStrip() - convertedCluster.firstStrip());
233  h_deltaEndStrip_->Fill(closestCluster->endStrip() - convertedCluster.endStrip());
234 
235  h2_CompareBarycenter_->Fill(closestCluster->barycenter(), convertedCluster.barycenter());
236  h2_CompareSize_->Fill(closestCluster->size(), convertedCluster.size());
237  h2_CompareCharge_->Fill(closestCluster->charge(), convertedCluster.charge());
238  h2_CompareFirstStrip_->Fill(closestCluster->firstStrip(), convertedCluster.firstStrip());
239  h2_CompareEndStrip_->Fill(closestCluster->endStrip(), convertedCluster.endStrip());
240 
241  // monitoring plots
242  matchedClusters.fill(cluster);
243  h_isMatched_->Fill(1);
244  } else {
245  // monitoring plots
246  unMatchedClusters.fill(cluster);
247  h_isMatched_->Fill(-1);
248  }
249  } // if we're doing the comparison cluster by cluster
250 
251  } // loop on clusters in a detset
252  } // loop on the detset vector
253 
254  h_nclusters_->Fill(nApproxClusters);
255 }
256 
258  edm::Run const& run,
259  edm::EventSetup const& iSetup) {
260  ibook.setCurrentFolder(folder_);
261  h_nclusters_ = ibook.book1D("numberOfClusters", "total N. of clusters;N. of clusters;#clusters", 500., 0., 500000.);
262  allClusters.book(ibook, folder_);
263 
264  // for comparisons
265  if (compareClusters_) {
266  // book monitoring for matche and unmatched clusters separately
267  matchedClusters.book(ibook, fmt::format("{}/MatchedClusters", folder_));
268  unMatchedClusters.book(ibook, fmt::format("{}/UnmatchedClusters", folder_));
269 
270  // 1D histograms
271  ibook.setCurrentFolder(fmt::format("{}/ClusterComparisons", folder_));
273  ibook.book1D("deltaBarycenter", "#Delta barycenter;#Delta barycenter;cluster pairs", 101, -50.5, 50.5);
274  h_deltaSize_ = ibook.book1D("deltaSize", "#Delta size;#Delta size;cluster pairs", 201, -100.5, 100.5);
275  h_deltaCharge_ = ibook.book1D("deltaCharge", "#Delta charge;#Delta charge;cluster pairs", 401, -200.5, 200.5);
276 
278  ibook.book1D("deltaFirstStrip", "#Delta FirstStrip; #Delta firstStrip;cluster pairs", 101, -50.5, 50.5);
280  ibook.book1D("deltaEndStrip", "#Delta EndStrip; #Delta endStrip; cluster pairs", 101, -50.5, 50.5);
281 
282  // geometric constants
283  constexpr int maxNStrips = 6 * sistrip::STRIPS_PER_APV;
284  constexpr float minStrip = -0.5f;
285  constexpr float maxStrip = maxNStrips - 0.5f;
286 
287  // cluster constants
288  constexpr float maxCluSize = 50;
289  constexpr float maxCluCharge = 700;
290 
291  // 2D histograms (use TH2I for counts to limit memory allocation)
292  std::string toRep = "SiStrip Cluster Barycenter";
293  h2_CompareBarycenter_ = ibook.book2I("compareBarycenter",
294  fmt::sprintf("; %s;Approx %s", toRep, toRep),
295  maxNStrips,
296  minStrip,
297  maxStrip,
298  maxNStrips,
299  minStrip,
300  maxStrip);
301 
302  toRep = "SiStrip Cluster Size";
303  h2_CompareSize_ = ibook.book2I("compareSize",
304  fmt::sprintf("; %s;Approx %s", toRep, toRep),
305  maxCluSize,
306  -0.5f,
307  maxCluSize - 0.5f,
308  maxCluSize,
309  -0.5f,
310  maxCluSize - 0.5f);
311 
312  toRep = "SiStrip Cluster Charge";
313  h2_CompareCharge_ = ibook.book2I("compareCharge",
314  fmt::sprintf("; %s;Approx %s", toRep, toRep),
315  maxCluCharge,
316  -0.5f,
317  maxCluCharge - 0.5f,
318  maxCluCharge,
319  -0.5f,
320  maxCluCharge - 0.5f);
321 
322  toRep = "SiStrip Cluster First Strip number";
323  h2_CompareFirstStrip_ = ibook.book2I("compareFirstStrip",
324  fmt::sprintf("; %s;Approx %s", toRep, toRep),
325  maxNStrips,
326  minStrip,
327  maxStrip,
328  maxNStrips,
329  minStrip,
330  maxStrip);
331 
332  toRep = "SiStrip Cluster Last Strip number";
333  h2_CompareEndStrip_ = ibook.book2I("compareLastStrip",
334  fmt::sprintf("; %s;Approx %s", toRep, toRep),
335  maxNStrips,
336  minStrip,
337  maxStrip,
338  maxNStrips,
339  minStrip,
340  maxStrip);
341 
342  h_isMatched_ = ibook.book1D("isClusterMatched", "cluster matching;is matched?;#clusters", 3, -1.5, 1.5);
343  h_isMatched_->getTH1F()->GetXaxis()->SetBinLabel(1, "Not matched");
344  h_isMatched_->getTH1F()->GetXaxis()->SetBinLabel(3, "Matched");
345  }
346 }
347 
348 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
351  desc.setComment("Monitor SiStripApproximateCluster collection and compare with regular SiStrip clusters");
352  desc.add<bool>("compareClusters", false)->setComment("if true, will compare with regualr Strip clusters");
353  desc.add<edm::InputTag>("ApproxClustersProducer", edm::InputTag("hltSiStripClusters2ApproxClusters"))
354  ->setComment("approxmate clusters collection");
355  desc.add<edm::InputTag>("ClustersProducer", edm::InputTag("hltSiStripClusterizerForRawPrime"))
356  ->setComment("regular clusters collection");
357  desc.add<std::string>("folder", "SiStripApproximateClusters")->setComment("Top Level Folder");
358  descriptions.addWithDefaultLabel(desc);
359 }
360 
361 // define this as a plug-in
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
id_type id() const
Definition: DetSetNew.h:61
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
siStripRawPrime::monitorApproxCluster unMatchedClusters
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::string folder_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
T const * product() const
Definition: Handle.h:70
Log< level::Error, false > LogError
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool empty() const
Definition: DetSetNew.h:67
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
void Fill(long long x)
void fill(const SiStripApproximateCluster &cluster)
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< SiStripApproximateClusterCollection > approxClustersToken_
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > stripClustersToken_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
SiStripMonitorApproximateCluster(const edm::ParameterSet &)
~SiStripMonitorApproximateCluster() override=default
siStripRawPrime::monitorApproxCluster allClusters
Constants and enumerated types for FED/FEC systems.
const edmNew::DetSetVector< SiStripCluster > * stripClusterCollection_
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
const_iterator find(id_type i, bool update=false) const
static const uint16_t STRIPS_PER_APV
float barycenter() const
void analyze(const edm::Event &, const edm::EventSetup &) override
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MonitorElement * book2I(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:296
void book(dqm::implementation::DQMStore::IBooker &ibook, const std::string &folder)
Definition: Run.h:45
siStripRawPrime::monitorApproxCluster matchedClusters