1111//
1212
1313// for string manipulations
14+ #include < algorithm>
1415#include < fmt/printf.h>
1516#include " DataFormats/Common/interface/Handle.h"
1617#include " DataFormats/Math/interface/deltaR.h"
@@ -94,6 +95,9 @@ class SiPixelCompareTracks : public DQMEDAnalyzer {
9495 MonitorElement* hnTracks_;
9596 MonitorElement* hnLooseAndAboveTracks_;
9697 MonitorElement* hnLooseAndAboveTracks_matched_;
98+ MonitorElement* hDeltaNTracks_;
99+ MonitorElement* hDeltaNLooseAndAboveTracks_;
100+ MonitorElement* hDeltaNLooseAndAboveTracks_matched_;
97101 MonitorElement* hnHits_;
98102 MonitorElement* hnHitsVsPhi_;
99103 MonitorElement* hnHitsVsEta_;
@@ -253,9 +257,23 @@ void SiPixelCompareTracks<T>::analyzeSeparate(U tokenRef, V tokenTar, const edm:
253257 hpt_eta_tkAllRefMatched_->Fill (etaRef, tsoaRef.view ()[it].pt ()); // matched to gpu
254258 hphi_z_tkAllRefMatched_->Fill (etaRef, zipRef);
255259 }
256- hnTracks_->Fill (nTracksRef, nTracksTar);
257- hnLooseAndAboveTracks_->Fill (nLooseAndAboveTracksRef, nLooseAndAboveTracksTar);
258- hnLooseAndAboveTracks_matched_->Fill (nLooseAndAboveTracksRef, nLooseAndAboveTracksRef_matchedTar);
260+
261+ // Define a lambda function for filling the histograms
262+ auto fillHistogram = [](auto & histogram, auto xValue, auto yValue) { histogram->Fill (xValue, yValue); };
263+
264+ // Define a lambda for filling delta histograms
265+ auto fillDeltaHistogram = [](auto & histogram, int cpuValue, int gpuValue) {
266+ histogram->Fill (std::min (cpuValue, 1000 ), std::clamp (gpuValue - cpuValue, -100 , 100 ));
267+ };
268+
269+ // Fill the histograms
270+ fillHistogram (hnTracks_, nTracksRef, nTracksTar);
271+ fillHistogram (hnLooseAndAboveTracks_, nLooseAndAboveTracksRef, nLooseAndAboveTracksTar);
272+ fillHistogram (hnLooseAndAboveTracks_matched_, nLooseAndAboveTracksRef, nLooseAndAboveTracksRef_matchedTar);
273+
274+ fillDeltaHistogram (hDeltaNTracks_, nTracksRef, nTracksTar);
275+ fillDeltaHistogram (hDeltaNLooseAndAboveTracks_, nLooseAndAboveTracksRef, nLooseAndAboveTracksTar);
276+ fillDeltaHistogram (hDeltaNLooseAndAboveTracks_matched_, nLooseAndAboveTracksRef, nLooseAndAboveTracksRef_matchedTar);
259277}
260278
261279//
@@ -278,13 +296,44 @@ void SiPixelCompareTracks<T>::bookHistograms(DQMStore::IBooker& iBook,
278296 iBook.cd ();
279297 iBook.setCurrentFolder (topFolderName_);
280298
281- // clang-format off
299+ // Define a helper function for booking histograms
282300 std::string toRep = " Number of tracks" ;
301+ auto bookTracksTH2I = [&](const std::string& name,
302+ const std::string& title,
303+ int xBins,
304+ double xMin,
305+ double xMax,
306+ int yBins,
307+ double yMin,
308+ double yMax) {
309+ return iBook.book2I (name, fmt::sprintf (title, toRep), xBins, xMin, xMax, yBins, yMin, yMax);
310+ };
311+
312+ // Define common parameters for different histogram types
313+ constexpr int xBins = 501 ;
314+ constexpr double xMin = -0.5 ;
315+ constexpr double xMax = 1001.5 ;
316+
317+ constexpr int dXBins = 1001 ;
318+ constexpr double dXMin = -0.5 ;
319+ constexpr double dXMax = 1000.5 ;
320+
321+ constexpr int dYBins = 201 ;
322+ constexpr double dYMin = -100.5 ;
323+ constexpr double dYMax = 100.5 ;
324+
283325 // FIXME: all the 2D correlation plots are quite heavy in terms of memory consumption, so a as soon as DQM supports THnSparse
284326 // these should be moved to a less resource consuming format
285- hnTracks_ = iBook.book2I (" nTracks" , fmt::sprintf (" %s per event; Reference; Target" ,toRep), 501 , -0.5 , 500.5 , 501 , -0.5 , 500.5 );
286- hnLooseAndAboveTracks_ = iBook.book2I (" nLooseAndAboveTracks" , fmt::sprintf (" %s (quality #geq loose) per event; Reference; Target" ,toRep), 501 , -0.5 , 500.5 , 501 , -0.5 , 500.5 );
287- hnLooseAndAboveTracks_matched_ = iBook.book2I (" nLooseAndAboveTracks_matched" , fmt::sprintf (" %s (quality #geq loose) per event; Reference; Target" ,toRep), 501 , -0.5 , 500.5 , 501 , -0.5 , 500.5 );
327+
328+ // Book histograms using the helper function
329+ // clang-format off
330+ hnTracks_ = bookTracksTH2I (" nTracks" , " %s per event; Reference; Target" , xBins, xMin, xMax, xBins, xMin, xMax);
331+ hnLooseAndAboveTracks_ = bookTracksTH2I (" nLooseAndAboveTracks" , " %s (quality #geq loose) per event; Reference; Target" , xBins, xMin, xMax, xBins, xMin, xMax);
332+ hnLooseAndAboveTracks_matched_ = bookTracksTH2I (" nLooseAndAboveTracks_matched" , " %s (quality #geq loose) per event; Reference; Target" , xBins, xMin, xMax, xBins, xMin, xMax);
333+
334+ hDeltaNTracks_ = bookTracksTH2I (" deltaNTracks" , " %s per event; Reference; Target - Reference" , dXBins, dXMin, dXMax, dYBins, dYMin, dYMax);
335+ hDeltaNLooseAndAboveTracks_ = bookTracksTH2I (" deltaNLooseAndAboveTracks" , " %s (quality #geq loose) per event; Reference; Target - Reference" , dXBins, dXMin, dXMax, dYBins, dYMin, dYMax);
336+ hDeltaNLooseAndAboveTracks_matched_ = bookTracksTH2I (" deltaNLooseAndAboveTracks_matched" , " %s (quality #geq loose) per event; Reference; Target - Reference" , dXBins, dXMin, dXMax, dYBins, dYMin, dYMax);
288337
289338 toRep = " Number of all RecHits per track (quality #geq loose)" ;
290339 hnHits_ = iBook.book2I (" nRecHits" , fmt::sprintf (" %s;Reference;Target" ,toRep), 15 , -0.5 , 14.5 , 15 , -0.5 , 14.5 );
0 commit comments