CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HGCalValidator.cc
Go to the documentation of this file.
2 
4 
7 
8 using namespace std;
9 using namespace edm;
10 
13  label_lcl(pset.getParameter<edm::InputTag>("label_lcl")),
14  label_tst(pset.getParameter<std::vector<edm::InputTag>>("label_tst")),
15  label_simTSFromCP(pset.getParameter<edm::InputTag>("label_simTSFromCP")),
16  associator_(pset.getUntrackedParameter<edm::InputTag>("associator")),
17  associatorSim_(pset.getUntrackedParameter<edm::InputTag>("associatorSim")),
18  SaveGeneralInfo_(pset.getUntrackedParameter<bool>("SaveGeneralInfo")),
19  doCaloParticlePlots_(pset.getUntrackedParameter<bool>("doCaloParticlePlots")),
20  doCaloParticleSelection_(pset.getUntrackedParameter<bool>("doCaloParticleSelection")),
21  doSimClustersPlots_(pset.getUntrackedParameter<bool>("doSimClustersPlots")),
22  label_SimClustersPlots_(pset.getParameter<edm::InputTag>("label_SimClusters")),
23  label_SimClustersLevel_(pset.getParameter<edm::InputTag>("label_SimClustersLevel")),
24  doLayerClustersPlots_(pset.getUntrackedParameter<bool>("doLayerClustersPlots")),
25  label_layerClustersPlots_(pset.getParameter<edm::InputTag>("label_layerClusterPlots")),
26  label_LCToCPLinking_(pset.getParameter<edm::InputTag>("label_LCToCPLinking")),
27  doTrackstersPlots_(pset.getUntrackedParameter<bool>("doTrackstersPlots")),
28  label_TSToCPLinking_(pset.getParameter<edm::InputTag>("label_TSToCPLinking")),
29  label_clustersmask(pset.getParameter<std::vector<edm::InputTag>>("LayerClustersInputMask")),
30  cummatbudinxo_(pset.getParameter<edm::FileInPath>("cummatbudinxo")) {
31  //In this way we can easily generalize to associations between other objects also.
32  const edm::InputTag& label_cp_effic_tag = pset.getParameter<edm::InputTag>("label_cp_effic");
33  const edm::InputTag& label_cp_fake_tag = pset.getParameter<edm::InputTag>("label_cp_fake");
34 
35  label_cp_effic = consumes<std::vector<CaloParticle>>(label_cp_effic_tag);
36  label_cp_fake = consumes<std::vector<CaloParticle>>(label_cp_fake_tag);
37 
38  simVertices_ = consumes<std::vector<SimVertex>>(pset.getParameter<edm::InputTag>("simVertices"));
39 
40  for (auto& itag : label_clustersmask) {
41  clustersMaskTokens_.push_back(consumes<std::vector<float>>(itag));
42  }
43 
44  associatorMapSimtR = consumes<hgcal::SimToRecoCollectionWithSimClusters>(associatorSim_);
45  associatorMapRtSim = consumes<hgcal::RecoToSimCollectionWithSimClusters>(associatorSim_);
46 
47  hitMap_ = consumes<std::unordered_map<DetId, const HGCRecHit*>>(edm::InputTag("hgcalRecHitMapProducer"));
48 
49  density_ = consumes<Density>(edm::InputTag("hgcalLayerClusters"));
50 
51  simClusters_ = consumes<std::vector<SimCluster>>(pset.getParameter<edm::InputTag>("label_scl"));
52 
53  layerclusters_ = consumes<reco::CaloClusterCollection>(label_lcl);
54 
55  for (auto& itag : label_tst) {
56  label_tstTokens.push_back(consumes<ticl::TracksterCollection>(itag));
57  }
58 
59  simTrackstersFromCPs_ = consumes<ticl::TracksterCollection>(label_simTSFromCP);
60 
61  associatorMapRtS = consumes<hgcal::RecoToSimCollection>(associator_);
62  associatorMapStR = consumes<hgcal::SimToRecoCollection>(associator_);
63 
64  cpSelector = CaloParticleSelector(pset.getParameter<double>("ptMinCP"),
65  pset.getParameter<double>("ptMaxCP"),
66  pset.getParameter<double>("minRapidityCP"),
67  pset.getParameter<double>("maxRapidityCP"),
68  pset.getParameter<double>("lipCP"),
69  pset.getParameter<double>("tipCP"),
70  pset.getParameter<int>("minHitCP"),
71  pset.getParameter<int>("maxSimClustersCP"),
72  pset.getParameter<bool>("signalOnlyCP"),
73  pset.getParameter<bool>("intimeOnlyCP"),
74  pset.getParameter<bool>("chargedOnlyCP"),
75  pset.getParameter<bool>("stableOnlyCP"),
76  pset.getParameter<bool>("notConvertedOnlyCP"),
77  pset.getParameter<std::vector<int>>("pdgIdCP"));
78 
79  tools_.reset(new hgcal::RecHitTools());
80 
81  particles_to_monitor_ = pset.getParameter<std::vector<int>>("pdgIdCP");
82  totallayers_to_monitor_ = pset.getParameter<int>("totallayers_to_monitor");
83  thicknesses_to_monitor_ = pset.getParameter<std::vector<int>>("thicknesses_to_monitor");
84 
85  //For the material budget file here
86  std::ifstream fmb(cummatbudinxo_.fullPath().c_str());
87  double thelay = 0.;
88  double mbg = 0.;
89  for (unsigned ilayer = 1; ilayer <= totallayers_to_monitor_; ++ilayer) {
90  fmb >> thelay >> mbg;
91  cummatbudg.insert(std::pair<double, double>(thelay, mbg));
92  }
93 
94  fmb.close();
95 
96  ParameterSet psetForHistoProducerAlgo = pset.getParameter<ParameterSet>("histoProducerAlgoBlock");
97  histoProducerAlgo_ = std::make_unique<HGVHistoProducerAlgo>(psetForHistoProducerAlgo);
98 
99  dirName_ = pset.getParameter<std::string>("dirName");
100 }
101 
103 
105  edm::Run const&,
106  edm::EventSetup const& setup,
107  Histograms& histograms) const {
108  if (SaveGeneralInfo_) {
109  ibook.cd();
110  ibook.setCurrentFolder(dirName_ + "GeneralInfo");
111  histoProducerAlgo_->bookInfo(ibook, histograms.histoProducerAlgo);
112  }
113 
114  if (doCaloParticlePlots_) {
115  ibook.cd();
116 
117  for (auto const particle : particles_to_monitor_) {
118  ibook.setCurrentFolder(dirName_ + "SelectedCaloParticles/" + std::to_string(particle));
119  histoProducerAlgo_->bookCaloParticleHistos(
120  ibook, histograms.histoProducerAlgo, particle, totallayers_to_monitor_);
121  }
122  ibook.cd();
123  ibook.setCurrentFolder(dirName_);
124  }
125 
126  //Booking histograms concerning with simClusters
127  if (doSimClustersPlots_) {
128  ibook.cd();
130  histoProducerAlgo_->bookSimClusterHistos(
132 
133  for (unsigned int ws = 0; ws < label_clustersmask.size(); ws++) {
134  ibook.cd();
136  string dirName = dirName_ + label_SimClustersPlots_.label() + "/";
137  if (!algo.process().empty())
138  dirName += algo.process() + "_";
139  LogDebug("HGCalValidator") << dirName << "\n";
140  if (!algo.label().empty())
141  dirName += algo.label() + "_";
142  LogDebug("HGCalValidator") << dirName << "\n";
143  if (!algo.instance().empty())
144  dirName += algo.instance() + "_";
145  LogDebug("HGCalValidator") << dirName << "\n";
146 
147  if (!dirName.empty()) {
148  dirName.resize(dirName.size() - 1);
149  }
150 
151  LogDebug("HGCalValidator") << dirName << "\n";
152 
153  ibook.setCurrentFolder(dirName);
154 
155  histoProducerAlgo_->bookSimClusterAssociationHistos(
157  } //end of loop over masks
158  } //if for simCluster plots
159 
160  //Booking histograms concerning with hgcal layer clusters
161  if (doLayerClustersPlots_) {
162  ibook.cd();
163  ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_.label() + "/ClusterLevel");
164  histoProducerAlgo_->bookClusterHistos_ClusterLevel(ibook,
165  histograms.histoProducerAlgo,
169  ibook.cd();
171  histoProducerAlgo_->bookClusterHistos_LCtoCP_association(
172  ibook, histograms.histoProducerAlgo, totallayers_to_monitor_);
173 
174  ibook.cd();
175  ibook.setCurrentFolder(dirName_ + label_layerClustersPlots_.label() + "/CellLevel");
176  histoProducerAlgo_->bookClusterHistos_CellLevel(
178  }
179 
180  //Booking histograms for Tracksters
181  for (unsigned int www = 0; www < label_tst.size(); www++) {
182  ibook.cd();
183  InputTag algo = label_tst[www];
184  string dirName = dirName_;
185  if (!algo.process().empty())
186  dirName += algo.process() + "_";
187  LogDebug("HGCalValidator") << dirName << "\n";
188  if (!algo.label().empty())
189  dirName += algo.label() + "_";
190  LogDebug("HGCalValidator") << dirName << "\n";
191  if (!algo.instance().empty())
192  dirName += algo.instance() + "_";
193  LogDebug("HGCalValidator") << dirName << "\n";
194 
195  if (!dirName.empty()) {
196  dirName.resize(dirName.size() - 1);
197  }
198 
199  LogDebug("HGCalValidator") << dirName << "\n";
200 
201  ibook.setCurrentFolder(dirName);
202 
203  //Booking histograms concerning HGCal tracksters
204  if (doTrackstersPlots_) {
205  histoProducerAlgo_->bookTracksterHistos(ibook, histograms.histoProducerAlgo, totallayers_to_monitor_);
206  ibook.setCurrentFolder(dirName + "/" + label_TSToCPLinking_.label());
207  histoProducerAlgo_->bookTracksterCPLinkingHistos(ibook, histograms.histoProducerAlgo);
208  }
209  } //end of booking Tracksters loop
210 }
211 
213  std::vector<CaloParticle> const& cPeff,
214  std::vector<SimVertex> const& simVertices,
215  std::vector<size_t>& selected_cPeff,
216  unsigned int layers,
217  std::unordered_map<DetId, const HGCRecHit*> const& hitMap) const {
218  selected_cPeff.reserve(cPeff.size());
219 
220  size_t j = 0;
221  for (auto const& caloParticle : cPeff) {
222  int id = caloParticle.pdgId();
223 
224  if (!doCaloParticleSelection_ || (doCaloParticleSelection_ && cpSelector(caloParticle, simVertices))) {
225  selected_cPeff.push_back(j);
226  if (doCaloParticlePlots_) {
227  histoProducerAlgo_->fill_caloparticle_histos(
228  histograms.histoProducerAlgo, id, caloParticle, simVertices, layers, hitMap);
229  }
230  }
231  ++j;
232  } //end of loop over caloparticles
233 }
234 
236  const edm::EventSetup& setup,
237  const Histograms& histograms) const {
238  using namespace reco;
239 
240  LogDebug("HGCalValidator") << "\n===================================================="
241  << "\n"
242  << "Analyzing new event"
243  << "\n"
244  << "====================================================\n"
245  << "\n";
246 
247  edm::Handle<std::vector<SimVertex>> simVerticesHandle;
248  event.getByToken(simVertices_, simVerticesHandle);
249  std::vector<SimVertex> const& simVertices = *simVerticesHandle;
250 
251  edm::Handle<std::vector<CaloParticle>> caloParticleHandle;
252  event.getByToken(label_cp_effic, caloParticleHandle);
253  std::vector<CaloParticle> const& caloParticles = *caloParticleHandle;
254 
255  edm::Handle<ticl::TracksterCollection> simTracksterFromCPHandle;
256  event.getByToken(simTrackstersFromCPs_, simTracksterFromCPHandle);
257  ticl::TracksterCollection const& simTrackstersFromCPs = *simTracksterFromCPHandle;
258 
260  tools_->setGeometry(*geom);
261  histoProducerAlgo_->setRecHitTools(tools_);
262 
263  edm::Handle<hgcal::SimToRecoCollection> simtorecoCollectionH;
264  event.getByToken(associatorMapStR, simtorecoCollectionH);
265  auto simRecColl = *simtorecoCollectionH;
266  edm::Handle<hgcal::RecoToSimCollection> recotosimCollectionH;
267  event.getByToken(associatorMapRtS, recotosimCollectionH);
268  auto recSimColl = *recotosimCollectionH;
269 
271  event.getByToken(hitMap_, hitMapHandle);
272  const std::unordered_map<DetId, const HGCRecHit*>* hitMap = &*hitMapHandle;
273 
274  //Some general info on layers etc.
275  if (SaveGeneralInfo_) {
276  histoProducerAlgo_->fill_info_histos(histograms.histoProducerAlgo, totallayers_to_monitor_);
277  }
278 
279  std::vector<size_t> cPIndices;
280  //Consider CaloParticles coming from the hard scatterer
281  //excluding the PU contribution and save the indices.
282  removeCPFromPU(caloParticles, cPIndices);
283 
284  // ##############################################
285  // fill caloparticles histograms
286  // ##############################################
287  // HGCRecHit are given to select the SimHits which are also reconstructed
288  LogTrace("HGCalValidator") << "\n# of CaloParticles: " << caloParticles.size() << "\n" << std::endl;
289  std::vector<size_t> selected_cPeff;
290  cpParametersAndSelection(histograms, caloParticles, simVertices, selected_cPeff, totallayers_to_monitor_, *hitMap);
291 
292  //get collections from the event
293  //simClusters
294  edm::Handle<std::vector<SimCluster>> simClustersHandle;
295  event.getByToken(simClusters_, simClustersHandle);
296  std::vector<SimCluster> const& simClusters = *simClustersHandle;
297 
298  //Layer clusters
300  event.getByToken(layerclusters_, clusterHandle);
301  const reco::CaloClusterCollection& clusters = *clusterHandle;
302 
303  //Density
304  edm::Handle<Density> densityHandle;
305  event.getByToken(density_, densityHandle);
306  const Density& densities = *densityHandle;
307 
308  auto nSimClusters = simClusters.size();
309  std::vector<size_t> sCIndices;
310  //There shouldn't be any SimTracks from different crossings, but maybe they will be added later.
311  //At the moment there should be one SimTrack in each SimCluster.
312  for (unsigned int scId = 0; scId < nSimClusters; ++scId) {
313  if (simClusters[scId].g4Tracks()[0].eventId().event() != 0 or
314  simClusters[scId].g4Tracks()[0].eventId().bunchCrossing() != 0) {
315  LogDebug("HGCalValidator") << "Excluding SimClusters from event: "
316  << simClusters[scId].g4Tracks()[0].eventId().event()
317  << " with BX: " << simClusters[scId].g4Tracks()[0].eventId().bunchCrossing()
318  << std::endl;
319  continue;
320  }
321  sCIndices.emplace_back(scId);
322  }
323 
324  // ##############################################
325  // fill simCluster histograms
326  // ##############################################
327  if (doSimClustersPlots_) {
328  histoProducerAlgo_->fill_simCluster_histos(
330 
331  for (unsigned int ws = 0; ws < label_clustersmask.size(); ws++) {
332  const auto& inputClusterMask = event.get(clustersMaskTokens_[ws]);
333 
335  event.getByToken(associatorMapSimtR, simtorecoCollectionH);
336  auto simRecColl = *simtorecoCollectionH;
338  event.getByToken(associatorMapRtSim, recotosimCollectionH);
339  auto recSimColl = *recotosimCollectionH;
340 
341  histoProducerAlgo_->fill_simClusterAssociation_histos(histograms.histoProducerAlgo,
342  ws,
343  clusterHandle,
344  clusters,
345  simClustersHandle,
346  simClusters,
347  sCIndices,
348  inputClusterMask,
349  *hitMap,
351  recSimColl,
352  simRecColl);
353 
354  //General Info on simClusters
355  LogTrace("HGCalValidator") << "\n# of SimClusters: " << nSimClusters
356  << ", layerClusters mask label: " << label_clustersmask[ws].label() << "\n";
357  } //end of loop overs masks
358  }
359 
360  // ##############################################
361  // fill layercluster histograms
362  // ##############################################
363  int w = 0; //counter counting the number of sets of histograms
364  if (doLayerClustersPlots_) {
365  histoProducerAlgo_->fill_generic_cluster_histos(histograms.histoProducerAlgo,
366  w,
367  clusterHandle,
368  clusters,
369  densities,
370  caloParticleHandle,
372  cPIndices,
373  selected_cPeff,
374  *hitMap,
375  cummatbudg,
378  recSimColl,
379  simRecColl);
380 
381  for (unsigned int layerclusterIndex = 0; layerclusterIndex < clusters.size(); layerclusterIndex++) {
382  histoProducerAlgo_->fill_cluster_histos(histograms.histoProducerAlgo, w, clusters[layerclusterIndex]);
383  }
384 
385  //General Info on hgcalLayerClusters
386  LogTrace("HGCalValidator") << "\n# of layer clusters with " << label_lcl.process() << ":" << label_lcl.label()
387  << ":" << label_lcl.instance() << ": " << clusters.size() << "\n";
388  }
389 
390  // ##############################################
391  // fill Trackster histograms
392  // ##############################################
393  for (unsigned int wml = 0; wml < label_tstTokens.size(); wml++) {
394  if (doTrackstersPlots_) {
396  event.getByToken(label_tstTokens[wml], tracksterHandle);
397  const ticl::TracksterCollection& tracksters = *tracksterHandle;
398 
399  histoProducerAlgo_->fill_trackster_histos(histograms.histoProducerAlgo,
400  wml,
401  tracksters,
402  clusters,
403  simTrackstersFromCPs,
405  cPIndices,
406  selected_cPeff,
407  *hitMap,
409 
410  //General Info on Tracksters
411  LogTrace("HGCalValidator") << "\n# of Tracksters with " << label_tst[wml].process() << ":"
412  << label_tst[wml].label() << ":" << label_tst[wml].instance() << ": "
413  << tracksters.size() << "\n"
414  << std::endl;
415  }
416  } //end of loop over Trackster input labels
417 }
std::map< double, double > cummatbudg
edm::EDGetTokenT< std::unordered_map< DetId, const HGCRecHit * > > hitMap_
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
const double w
Definition: UKUtility.cc:23
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
void dqmAnalyze(const edm::Event &, const edm::EventSetup &, const Histograms &) const override
Method called once per event.
edm::InputTag associator_
std::vector< edm::InputTag > label_tst
edm::EDGetTokenT< hgcal::SimToRecoCollectionWithSimClusters > associatorMapSimtR
std::unique_ptr< HGVHistoProducerAlgo > histoProducerAlgo_
~HGCalValidator() override
Destructor.
edm::EDGetTokenT< hgcal::RecoToSimCollectionWithSimClusters > associatorMapRtSim
CaloParticleSelector cpSelector
edm::InputTag label_TSToCPLinking_
const bool doCaloParticlePlots_
edm::EDGetTokenT< ticl::TracksterCollection > simTrackstersFromCPs_
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.
#define LogTrace(id)
const bool SaveGeneralInfo_
const bool doLayerClustersPlots_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< Density > density_
auto &__restrict__ ws
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_
HGVHistoProducerAlgoHistograms histoProducerAlgo
edm::EDGetTokenT< std::vector< SimVertex > > simVertices_
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
edm::EDGetTokenT< std::vector< CaloParticle > > label_cp_fake
edm::EDGetTokenT< std::vector< CaloParticle > > label_cp_effic
const bool doCaloParticleSelection_
std::vector< edm::EDGetTokenT< ticl::TracksterCollection > > label_tstTokens
std::shared_ptr< hgcal::RecHitTools > tools_
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_
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_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::InputTag label_SimClustersPlots_
std::string const & label() const
Definition: InputTag.h:36
edm::InputTag label_SimClustersLevel_
std::string const & process() const
Definition: InputTag.h:40
std::vector< int > particles_to_monitor_
edm::EDGetTokenT< hgcal::SimToRecoCollection > associatorMapStR
const bool doSimClustersPlots_
std::vector< Trackster > TracksterCollection
Definition: Trackster.h:203
std::string fullPath() const
Definition: FileInPath.cc:161
edm::InputTag label_lcl
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
hgcal_clustering::Density Density
std::string const & instance() const
Definition: InputTag.h:37
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::InputTag associatorSim_
Definition: Run.h:45
edm::InputTag label_layerClustersPlots_
#define LogDebug(id)