CMS 3D CMS Logo

HGCalValidator.cc
Go to the documentation of this file.
2 
4 
7 
8 using namespace std;
9 using namespace edm;
10 
12  : caloGeomToken_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
13  label_lcl(pset.getParameter<edm::InputTag>("label_lcl")),
14  label_tst(pset.getParameter<std::vector<edm::InputTag>>("label_tst")),
15  label_simTS(pset.getParameter<edm::InputTag>("label_simTS")),
16  label_simTSFromCP(pset.getParameter<edm::InputTag>("label_simTSFromCP")),
17  associator_(pset.getUntrackedParameter<edm::InputTag>("associator")),
18  associatorSim_(pset.getUntrackedParameter<edm::InputTag>("associatorSim")),
19  SaveGeneralInfo_(pset.getUntrackedParameter<bool>("SaveGeneralInfo")),
20  doCaloParticlePlots_(pset.getUntrackedParameter<bool>("doCaloParticlePlots")),
21  doCaloParticleSelection_(pset.getUntrackedParameter<bool>("doCaloParticleSelection")),
22  doSimClustersPlots_(pset.getUntrackedParameter<bool>("doSimClustersPlots")),
23  label_SimClustersPlots_(pset.getParameter<edm::InputTag>("label_SimClusters")),
24  label_SimClustersLevel_(pset.getParameter<edm::InputTag>("label_SimClustersLevel")),
25  doLayerClustersPlots_(pset.getUntrackedParameter<bool>("doLayerClustersPlots")),
26  label_layerClustersPlots_(pset.getParameter<edm::InputTag>("label_layerClusterPlots")),
27  label_LCToCPLinking_(pset.getParameter<edm::InputTag>("label_LCToCPLinking")),
28  doTrackstersPlots_(pset.getUntrackedParameter<bool>("doTrackstersPlots")),
29  label_TS_(pset.getParameter<std::string>("label_TS")),
30  label_TSToCPLinking_(pset.getParameter<std::string>("label_TSToCPLinking")),
31  label_TSToSTSPR_(pset.getParameter<std::string>("label_TSToSTSPR")),
32  label_clustersmask(pset.getParameter<std::vector<edm::InputTag>>("LayerClustersInputMask")),
33  cummatbudinxo_(pset.getParameter<edm::FileInPath>("cummatbudinxo")) {
34  //In this way we can easily generalize to associations between other objects also.
35  const edm::InputTag& label_cp_effic_tag = pset.getParameter<edm::InputTag>("label_cp_effic");
36  const edm::InputTag& label_cp_fake_tag = pset.getParameter<edm::InputTag>("label_cp_fake");
37 
38  label_cp_effic = consumes<std::vector<CaloParticle>>(label_cp_effic_tag);
39  label_cp_fake = consumes<std::vector<CaloParticle>>(label_cp_fake_tag);
40 
41  simVertices_ = consumes<std::vector<SimVertex>>(pset.getParameter<edm::InputTag>("simVertices"));
42 
43  for (auto& itag : label_clustersmask) {
44  clustersMaskTokens_.push_back(consumes<std::vector<float>>(itag));
45  }
46 
47  associatorMapSimtR = consumes<hgcal::SimToRecoCollectionWithSimClusters>(associatorSim_);
48  associatorMapRtSim = consumes<hgcal::RecoToSimCollectionWithSimClusters>(associatorSim_);
49 
50  simTrackstersMap_ = consumes<std::map<uint, std::vector<uint>>>(edm::InputTag("ticlSimTracksters"));
51 
52  hitMap_ = consumes<std::unordered_map<DetId, const HGCRecHit*>>(edm::InputTag("hgcalRecHitMapProducer"));
53 
54  density_ = consumes<Density>(edm::InputTag("hgcalLayerClusters"));
55 
56  simClusters_ = consumes<std::vector<SimCluster>>(pset.getParameter<edm::InputTag>("label_scl"));
57 
58  layerclusters_ = consumes<reco::CaloClusterCollection>(label_lcl);
59 
60  for (auto& itag : label_tst) {
61  label_tstTokens.push_back(consumes<ticl::TracksterCollection>(itag));
62  }
63 
64  simTracksters_ = consumes<ticl::TracksterCollection>(label_simTS);
65  simTracksters_fromCPs_ = consumes<ticl::TracksterCollection>(label_simTSFromCP);
66 
67  associatorMapRtS = consumes<hgcal::RecoToSimCollection>(associator_);
68  associatorMapStR = consumes<hgcal::SimToRecoCollection>(associator_);
69 
70  cpSelector = CaloParticleSelector(pset.getParameter<double>("ptMinCP"),
71  pset.getParameter<double>("ptMaxCP"),
72  pset.getParameter<double>("minRapidityCP"),
73  pset.getParameter<double>("maxRapidityCP"),
74  pset.getParameter<double>("lipCP"),
75  pset.getParameter<double>("tipCP"),
76  pset.getParameter<int>("minHitCP"),
77  pset.getParameter<int>("maxSimClustersCP"),
78  pset.getParameter<bool>("signalOnlyCP"),
79  pset.getParameter<bool>("intimeOnlyCP"),
80  pset.getParameter<bool>("chargedOnlyCP"),
81  pset.getParameter<bool>("stableOnlyCP"),
82  pset.getParameter<bool>("notConvertedOnlyCP"),
83  pset.getParameter<std::vector<int>>("pdgIdCP"));
84 
85  tools_.reset(new hgcal::RecHitTools());
86 
87  particles_to_monitor_ = pset.getParameter<std::vector<int>>("pdgIdCP");
88  totallayers_to_monitor_ = pset.getParameter<int>("totallayers_to_monitor");
89  thicknesses_to_monitor_ = pset.getParameter<std::vector<int>>("thicknesses_to_monitor");
90 
91  //For the material budget file here
92  std::ifstream fmb(cummatbudinxo_.fullPath().c_str());
93  double thelay = 0.;
94  double mbg = 0.;
95  for (unsigned ilayer = 1; ilayer <= totallayers_to_monitor_; ++ilayer) {
96  fmb >> thelay >> mbg;
97  cummatbudg.insert(std::pair<double, double>(thelay, mbg));
98  }
99 
100  fmb.close();
101 
102  ParameterSet psetForHistoProducerAlgo = pset.getParameter<ParameterSet>("histoProducerAlgoBlock");
103  histoProducerAlgo_ = std::make_unique<HGVHistoProducerAlgo>(psetForHistoProducerAlgo);
104 
105  dirName_ = pset.getParameter<std::string>("dirName");
106 }
107 
109 
111  edm::Run const&,
112  edm::EventSetup const& setup,
113  Histograms& histograms) const {
114  if (SaveGeneralInfo_) {
115  ibook.cd();
116  ibook.setCurrentFolder(dirName_ + "GeneralInfo");
117  histoProducerAlgo_->bookInfo(ibook, histograms.histoProducerAlgo);
118  }
119 
120  if (doCaloParticlePlots_) {
121  ibook.cd();
122 
123  for (auto const particle : particles_to_monitor_) {
124  ibook.setCurrentFolder(dirName_ + "SelectedCaloParticles/" + std::to_string(particle));
125  histoProducerAlgo_->bookCaloParticleHistos(
126  ibook, histograms.histoProducerAlgo, particle, totallayers_to_monitor_);
127  }
128  ibook.cd();
129  ibook.setCurrentFolder(dirName_);
130  }
131 
132  //Booking histograms concerning with simClusters
133  if (doSimClustersPlots_) {
134  ibook.cd();
136  histoProducerAlgo_->bookSimClusterHistos(
137  ibook, histograms.histoProducerAlgo, totallayers_to_monitor_, thicknesses_to_monitor_);
138 
139  for (unsigned int ws = 0; ws < label_clustersmask.size(); ws++) {
140  ibook.cd();
142  string dirName = dirName_ + label_SimClustersPlots_.label() + "/";
143  if (!algo.process().empty())
144  dirName += algo.process() + "_";
145  LogDebug("HGCalValidator") << dirName << "\n";
146  if (!algo.label().empty())
147  dirName += algo.label() + "_";
148  LogDebug("HGCalValidator") << dirName << "\n";
149  if (!algo.instance().empty())
150  dirName += algo.instance() + "_";
151  LogDebug("HGCalValidator") << dirName << "\n";
152 
153  if (!dirName.empty()) {
154  dirName.resize(dirName.size() - 1);
155  }
156 
157  LogDebug("HGCalValidator") << dirName << "\n";
158 
159  ibook.setCurrentFolder(dirName);
160 
161  histoProducerAlgo_->bookSimClusterAssociationHistos(
162  ibook, histograms.histoProducerAlgo, totallayers_to_monitor_, thicknesses_to_monitor_);
163  } //end of loop over masks
164  } //if for simCluster plots
165 
166  //Booking histograms concerning with hgcal layer clusters
167  if (doLayerClustersPlots_) {
168  ibook.cd();
169  ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_.label() + "/ClusterLevel");
170  histoProducerAlgo_->bookClusterHistos_ClusterLevel(ibook,
171  histograms.histoProducerAlgo,
175  ibook.cd();
177  histoProducerAlgo_->bookClusterHistos_LCtoCP_association(
178  ibook, histograms.histoProducerAlgo, totallayers_to_monitor_);
179 
180  ibook.cd();
181  ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_.label() + "/CellLevel");
182  histoProducerAlgo_->bookClusterHistos_CellLevel(
183  ibook, histograms.histoProducerAlgo, totallayers_to_monitor_, thicknesses_to_monitor_);
184  }
185 
186  //Booking histograms for Tracksters
187  for (unsigned int www = 0; www < label_tst.size(); www++) {
188  ibook.cd();
189  InputTag algo = label_tst[www];
190  string dirName = dirName_;
191  if (!algo.process().empty())
192  dirName += algo.process() + "_";
193  LogDebug("HGCalValidator") << dirName << "\n";
194  if (!algo.label().empty())
195  dirName += algo.label() + "_";
196  LogDebug("HGCalValidator") << dirName << "\n";
197  if (!algo.instance().empty())
198  dirName += algo.instance() + "_";
199  LogDebug("HGCalValidator") << dirName << "\n";
200 
201  if (!dirName.empty()) {
202  dirName.resize(dirName.size() - 1);
203  }
204 
205  LogDebug("HGCalValidator") << dirName << "\n";
206 
207  ibook.setCurrentFolder(dirName);
208 
209  // Booking histograms concerning HGCal tracksters
210  if (doTrackstersPlots_) {
211  // Generic histos
212  ibook.setCurrentFolder(dirName + "/" + label_TS_);
213  histoProducerAlgo_->bookTracksterHistos(ibook, histograms.histoProducerAlgo, totallayers_to_monitor_);
214  // CP Linking
216  histoProducerAlgo_->bookTracksterSTSHistos(
217  ibook, histograms.histoProducerAlgo, HGVHistoProducerAlgo::validationType::Linking);
218  // SimTracksters Pattern Recognition
220  histoProducerAlgo_->bookTracksterSTSHistos(
221  ibook, histograms.histoProducerAlgo, HGVHistoProducerAlgo::validationType::PatternRecognition);
222  }
223  } //end of booking Tracksters loop
224 }
225 
227  std::vector<CaloParticle> const& cPeff,
228  std::vector<SimVertex> const& simVertices,
229  std::vector<size_t>& selected_cPeff,
230  unsigned int layers,
231  std::unordered_map<DetId, const HGCRecHit*> const& hitMap) const {
232  selected_cPeff.reserve(cPeff.size());
233 
234  size_t j = 0;
235  for (auto const& caloParticle : cPeff) {
236  int id = caloParticle.pdgId();
237 
239  selected_cPeff.push_back(j);
240  if (doCaloParticlePlots_) {
241  histoProducerAlgo_->fill_caloparticle_histos(
242  histograms.histoProducerAlgo, id, caloParticle, simVertices, layers, hitMap);
243  }
244  }
245  ++j;
246  } //end of loop over caloparticles
247 }
248 
250  const edm::EventSetup& setup,
251  const Histograms& histograms) const {
252  using namespace reco;
253 
254  LogDebug("HGCalValidator") << "\n===================================================="
255  << "\n"
256  << "Analyzing new event"
257  << "\n"
258  << "====================================================\n"
259  << "\n";
260 
261  edm::Handle<std::vector<SimVertex>> simVerticesHandle;
262  event.getByToken(simVertices_, simVerticesHandle);
263  std::vector<SimVertex> const& simVertices = *simVerticesHandle;
264 
265  edm::Handle<std::vector<CaloParticle>> caloParticleHandle;
266  event.getByToken(label_cp_effic, caloParticleHandle);
267  std::vector<CaloParticle> const& caloParticles = *caloParticleHandle;
268 
269  edm::Handle<ticl::TracksterCollection> simTracksterHandle;
270  event.getByToken(simTracksters_, simTracksterHandle);
271  ticl::TracksterCollection const& simTracksters = *simTracksterHandle;
272 
273  edm::Handle<ticl::TracksterCollection> simTracksterFromCPHandle;
274  event.getByToken(simTracksters_fromCPs_, simTracksterFromCPHandle);
275  ticl::TracksterCollection const& simTrackstersFromCPs = *simTracksterFromCPHandle;
276 
277  edm::Handle<std::map<uint, std::vector<uint>>> simTrackstersMapHandle;
278  event.getByToken(simTrackstersMap_, simTrackstersMapHandle);
279  const std::map<uint, std::vector<uint>> cpToSc_SimTrackstersMap = *simTrackstersMapHandle;
280 
282  tools_->setGeometry(*geom);
283  histoProducerAlgo_->setRecHitTools(tools_);
284 
285  edm::Handle<hgcal::SimToRecoCollection> simtorecoCollectionH;
286  event.getByToken(associatorMapStR, simtorecoCollectionH);
287  auto simRecColl = *simtorecoCollectionH;
288  edm::Handle<hgcal::RecoToSimCollection> recotosimCollectionH;
289  event.getByToken(associatorMapRtS, recotosimCollectionH);
290  auto recSimColl = *recotosimCollectionH;
291 
293  event.getByToken(hitMap_, hitMapHandle);
294  const std::unordered_map<DetId, const HGCRecHit*>* hitMap = &*hitMapHandle;
295 
296  //Some general info on layers etc.
297  if (SaveGeneralInfo_) {
298  histoProducerAlgo_->fill_info_histos(histograms.histoProducerAlgo, totallayers_to_monitor_);
299  }
300 
301  std::vector<size_t> cPIndices;
302  //Consider CaloParticles coming from the hard scatterer
303  //excluding the PU contribution and save the indices.
304  removeCPFromPU(caloParticles, cPIndices);
305 
306  // ##############################################
307  // Fill caloparticles histograms
308  // ##############################################
309  // HGCRecHit are given to select the SimHits which are also reconstructed
310  LogTrace("HGCalValidator") << "\n# of CaloParticles: " << caloParticles.size() << "\n" << std::endl;
311  std::vector<size_t> selected_cPeff;
313 
314  //get collections from the event
315  //simClusters
316  edm::Handle<std::vector<SimCluster>> simClustersHandle;
317  event.getByToken(simClusters_, simClustersHandle);
318  std::vector<SimCluster> const& simClusters = *simClustersHandle;
319 
320  //Layer clusters
322  event.getByToken(layerclusters_, clusterHandle);
323  const reco::CaloClusterCollection& clusters = *clusterHandle;
324 
325  //Density
326  edm::Handle<Density> densityHandle;
327  event.getByToken(density_, densityHandle);
328  const Density& densities = *densityHandle;
329 
330  auto nSimClusters = simClusters.size();
331  std::vector<size_t> sCIndices;
332  //There shouldn't be any SimTracks from different crossings, but maybe they will be added later.
333  //At the moment there should be one SimTrack in each SimCluster.
334  for (unsigned int scId = 0; scId < nSimClusters; ++scId) {
335  if (simClusters[scId].g4Tracks()[0].eventId().event() != 0 or
336  simClusters[scId].g4Tracks()[0].eventId().bunchCrossing() != 0) {
337  LogDebug("HGCalValidator") << "Excluding SimClusters from event: "
338  << simClusters[scId].g4Tracks()[0].eventId().event()
339  << " with BX: " << simClusters[scId].g4Tracks()[0].eventId().bunchCrossing()
340  << std::endl;
341  continue;
342  }
343  sCIndices.emplace_back(scId);
344  }
345 
346  // ##############################################
347  // Fill simCluster histograms
348  // ##############################################
349  if (doSimClustersPlots_) {
350  histoProducerAlgo_->fill_simCluster_histos(
351  histograms.histoProducerAlgo, simClusters, totallayers_to_monitor_, thicknesses_to_monitor_);
352 
353  for (unsigned int ws = 0; ws < label_clustersmask.size(); ws++) {
354  const auto& inputClusterMask = event.get(clustersMaskTokens_[ws]);
355 
357  event.getByToken(associatorMapSimtR, simtorecoCollectionH);
358  auto simRecColl = *simtorecoCollectionH;
360  event.getByToken(associatorMapRtSim, recotosimCollectionH);
361  auto recSimColl = *recotosimCollectionH;
362 
363  histoProducerAlgo_->fill_simClusterAssociation_histos(histograms.histoProducerAlgo,
364  ws,
365  clusterHandle,
366  clusters,
367  simClustersHandle,
368  simClusters,
369  sCIndices,
370  inputClusterMask,
371  *hitMap,
373  recSimColl,
374  simRecColl);
375 
376  //General Info on simClusters
377  LogTrace("HGCalValidator") << "\n# of SimClusters: " << nSimClusters
378  << ", layerClusters mask label: " << label_clustersmask[ws].label() << "\n";
379  } //end of loop overs masks
380  }
381 
382  // ##############################################
383  // Fill layercluster histograms
384  // ##############################################
385  int w = 0; //counter counting the number of sets of histograms
386  if (doLayerClustersPlots_) {
387  histoProducerAlgo_->fill_generic_cluster_histos(histograms.histoProducerAlgo,
388  w,
389  clusterHandle,
390  clusters,
391  densities,
392  caloParticleHandle,
394  cPIndices,
395  selected_cPeff,
396  *hitMap,
397  cummatbudg,
400  recSimColl,
401  simRecColl);
402 
403  for (unsigned int layerclusterIndex = 0; layerclusterIndex < clusters.size(); layerclusterIndex++) {
404  histoProducerAlgo_->fill_cluster_histos(histograms.histoProducerAlgo, w, clusters[layerclusterIndex]);
405  }
406 
407  //General Info on hgcalLayerClusters
408  LogTrace("HGCalValidator") << "\n# of layer clusters with " << label_lcl.process() << ":" << label_lcl.label()
409  << ":" << label_lcl.instance() << ": " << clusters.size() << "\n";
410  }
411 
412  // ##############################################
413  // Fill Trackster histograms
414  // ##############################################
415  for (unsigned int wml = 0; wml < label_tstTokens.size(); wml++) {
416  if (doTrackstersPlots_) {
418  event.getByToken(label_tstTokens[wml], tracksterHandle);
419  const ticl::TracksterCollection& tracksters = *tracksterHandle;
420 
421  //General Info on Tracksters
422  LogTrace("HGCalValidator") << "\n# of Tracksters from " << label_tst[wml].process() << ":"
423  << label_tst[wml].label() << ":" << label_tst[wml].instance() << ": "
424  << tracksters.size() << "\n"
425  << std::endl;
426 
427  histoProducerAlgo_->fill_trackster_histos(histograms.histoProducerAlgo,
428  wml,
429  tracksters,
430  clusters,
431  simTracksters,
432  simTrackstersFromCPs,
433  cpToSc_SimTrackstersMap,
434  simClusters,
435  caloParticleHandle.id(),
437  cPIndices,
438  selected_cPeff,
439  *hitMap,
441  }
442  } //end of loop over Trackster input labels
443 }
std::map< double, double > cummatbudg
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::EDGetTokenT< std::unordered_map< DetId, const HGCRecHit * > > hitMap_
void cpParametersAndSelection(const Histograms &histograms, std::vector< CaloParticle > const &cPeff, std::vector< SimVertex > const &simVertices, std::vector< size_t > &selected_cPeff, unsigned int layers, std::unordered_map< DetId, const HGCRecHit *> const &) const
ProductID id() const
Definition: HandleBase.cc:29
std::string fullPath() const
Definition: FileInPath.cc:161
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void dqmAnalyze(const edm::Event &, const edm::EventSetup &, const Histograms &) const override
Method called once per event.
edm::InputTag associator_
T w() const
std::string const & instance() const
Definition: InputTag.h:37
std::vector< edm::InputTag > label_tst
edm::EDGetTokenT< hgcal::SimToRecoCollectionWithSimClusters > associatorMapSimtR
std::unique_ptr< HGVHistoProducerAlgo > histoProducerAlgo_
std::string to_string(const V &value)
Definition: OMSAccess.h:71
~HGCalValidator() override
Destructor.
edm::EDGetTokenT< hgcal::RecoToSimCollectionWithSimClusters > associatorMapRtSim
CaloParticleSelector cpSelector
const bool doCaloParticlePlots_
std::string const & label() const
Definition: InputTag.h:36
unsigned totallayers_to_monitor_
std::vector< int > thicknesses_to_monitor_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, Histograms &) const override
Method called to book the DQM histograms.
edm::InputTag label_simTS
#define LogTrace(id)
const bool SaveGeneralInfo_
const bool doLayerClustersPlots_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< Density > density_
auto &__restrict__ ws
std::string label_TSToSTSPR_
cc *****************************************************cc the common blocks pinput and cwdidth are for input parameters cc these parameters needed to be interfaced to other program common pinput fmb
Definition: inclcon.h:4
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
edm::EDGetTokenT< hgcal::RecoToSimCollection > associatorMapRtS
std::string dirName_
edm::EDGetTokenT< std::vector< SimVertex > > simVertices_
edm::EDGetTokenT< std::vector< CaloParticle > > label_cp_fake
edm::EDGetTokenT< std::vector< CaloParticle > > label_cp_effic
const bool doCaloParticleSelection_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::vector< edm::EDGetTokenT< ticl::TracksterCollection > > label_tstTokens
std::shared_ptr< hgcal::RecHitTools > tools_
std::string label_TSToCPLinking_
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
edm::InputTag label_LCToCPLinking_
edm::InputTag label_simTSFromCP
edm::EDGetTokenT< reco::CaloClusterCollection > layerclusters_
HGCalValidator(const edm::ParameterSet &pset)
Constructor.
const bool doTrackstersPlots_
const edm::FileInPath cummatbudinxo_
edm::EDGetTokenT< ticl::TracksterCollection > simTracksters_
static void removeCPFromPU(const std::vector< CaloParticle > &caloParticles, std::vector< size_t > &cPIndices, bool hardScatterOnly=true)
std::vector< edm::InputTag > label_clustersmask
std::vector< edm::EDGetTokenT< std::vector< float > > > clustersMaskTokens_
edm::EDGetTokenT< std::vector< SimCluster > > simClusters_
edm::InputTag label_SimClustersPlots_
edm::InputTag label_SimClustersLevel_
std::vector< int > particles_to_monitor_
fixed size matrix
HLT enums.
edm::EDGetTokenT< hgcal::SimToRecoCollection > associatorMapStR
const bool doSimClustersPlots_
std::vector< Trackster > TracksterCollection
Definition: Trackster.h:203
edm::InputTag label_lcl
std::string const & process() const
Definition: InputTag.h:40
hgcal_clustering::Density Density
edm::EDGetTokenT< std::map< uint, std::vector< uint > > > simTrackstersMap_
edm::EDGetTokenT< ticl::TracksterCollection > simTracksters_fromCPs_
std::string label_TS_
edm::InputTag associatorSim_
Definition: event.py:1
Definition: Run.h:45
edm::InputTag label_layerClustersPlots_
#define LogDebug(id)