CMS 3D CMS Logo

CaloParticleValidation.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: CaloParticleValidation
4 // Original Author: Marco Rovere
5 // Created: Thu, 18 Jan 2018 15:54:55 GMT
6 //
7 //
8 
9 #include <string>
10 #include <unordered_map>
11 
12 // user include files
15 
18 
20 
28 
29 //
30 // class declaration
31 //
32 
40  selfEnergy_; // this is the sum of the energy associated to all recHits linked to all SimClusters
41  dqm::reco::MonitorElement* energyDifference_; // This contains (energy-selfEnergy)/energy
51  dqm::reco::MonitorElement* pfcandidate_vect_sum_pt_; // This is indeed a cumulative istogram
52 };
53 
54 using Histograms_CaloParticleValidation = std::unordered_map<int, Histogram_CaloParticleSingle>;
55 
56 class CaloParticleValidation : public DQMGlobalEDAnalyzer<Histograms_CaloParticleValidation> {
57 public:
59  ~CaloParticleValidation() override;
60 
61  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
62 
63 private:
65  edm::Run const&,
66  edm::EventSetup const&,
67  Histograms_CaloParticleValidation&) const override;
68 
69  void dqmAnalyze(edm::Event const&, edm::EventSetup const&, Histograms_CaloParticleValidation const&) const override;
70 
71  // ----------member data ---------------------------
73  std::vector<int> particles_to_monitor_;
74 
82 };
83 
84 //
85 // constants, enums and typedefs
86 //
87 
88 //
89 // static data member definitions
90 //
91 
92 //
93 // constructors and destructor
94 //
96  : folder_(iConfig.getParameter<std::string>("folder")),
97  particles_to_monitor_(iConfig.getParameter<std::vector<int>>("particles_to_monitor")),
98  simVertices_(consumes<std::vector<SimVertex>>(iConfig.getParameter<edm::InputTag>("simVertices"))),
99  caloParticles_(consumes<std::vector<CaloParticle>>(iConfig.getParameter<edm::InputTag>("caloParticles"))),
100  simPFClusters_(consumes<std::vector<reco::SuperCluster>>(iConfig.getParameter<edm::InputTag>("simPFClusters"))),
101  simPFCandidates_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("simPFCandidates"))),
102  recHitsEE_(consumes<HGCRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEE"))),
103  recHitsFH_(consumes<HGCRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsFH"))),
104  recHitsBH_(consumes<HGCRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsBH"))) {
105  //now do what ever initialization is needed
106 }
107 
109  // do anything here that needs to be done at desctruction time
110  // (e.g. close files, deallocate resources etc.)
111 }
112 
113 //
114 // member functions
115 //
116 
117 // ------------ method called for each event ------------
118 
120  edm::EventSetup const& iSetup,
122  using namespace edm;
123 
124  Handle<HGCRecHitCollection> recHitHandleEE;
125  Handle<HGCRecHitCollection> recHitHandleFH;
126  Handle<HGCRecHitCollection> recHitHandleBH;
127  // make a map detid-rechit
128 
129  iEvent.getByToken(recHitsEE_, recHitHandleEE);
130  iEvent.getByToken(recHitsFH_, recHitHandleFH);
131  iEvent.getByToken(recHitsBH_, recHitHandleBH);
132  const auto& rechitsEE = *recHitHandleEE;
133  const auto& rechitsFH = *recHitHandleFH;
134  const auto& rechitsBH = *recHitHandleBH;
135  std::map<DetId, const HGCRecHit*> hitmap;
136  for (unsigned int i = 0; i < rechitsEE.size(); ++i) {
137  hitmap[rechitsEE[i].detid()] = &rechitsEE[i];
138  }
139  for (unsigned int i = 0; i < rechitsFH.size(); ++i) {
140  hitmap[rechitsFH[i].detid()] = &rechitsFH[i];
141  }
142  for (unsigned int i = 0; i < rechitsBH.size(); ++i) {
143  hitmap[rechitsBH[i].detid()] = &rechitsBH[i];
144  }
145 
146  Handle<std::vector<SimVertex>> simVerticesHandle;
147  iEvent.getByToken(simVertices_, simVerticesHandle);
148  std::vector<SimVertex> const& simVertices = *simVerticesHandle;
149 
150  Handle<std::vector<CaloParticle>> caloParticleHandle;
151  iEvent.getByToken(caloParticles_, caloParticleHandle);
152  std::vector<CaloParticle> const& caloParticles = *caloParticleHandle;
153 
154  Handle<std::vector<reco::SuperCluster>> simPFClustersHandle;
155  iEvent.getByToken(simPFClusters_, simPFClustersHandle);
156  std::vector<reco::SuperCluster> const& simPFClusters = *simPFClustersHandle;
157 
158  Handle<reco::PFCandidateCollection> simPFCandidatesHandle;
159  iEvent.getByToken(simPFCandidates_, simPFCandidatesHandle);
160  reco::PFCandidateCollection const& simPFCandidates = *simPFCandidatesHandle;
161 
162  for (auto const& caloParticle : caloParticles) {
163  if (caloParticle.g4Tracks()[0].eventId().event() != 0 or
164  caloParticle.g4Tracks()[0].eventId().bunchCrossing() != 0) {
165  LogDebug("CaloParticleValidation") << "Excluding CaloParticles from event: "
166  << caloParticle.g4Tracks()[0].eventId().event()
167  << " with BX: " << caloParticle.g4Tracks()[0].eventId().bunchCrossing()
168  << std::endl;
169  continue;
170  }
171  int id = caloParticle.pdgId();
172  if (histos.count(id)) {
173  auto& histo = histos.at(id);
174  histo.eta_->Fill(caloParticle.eta());
175  histo.pt_->Fill(caloParticle.pt());
176  histo.energy_->Fill(caloParticle.energy());
177  histo.nSimClusters_->Fill(caloParticle.simClusters().size());
178  // Find the corresponding vertex.
179  histo.eta_Zorigin_map_->Fill(simVertices.at(caloParticle.g4Tracks()[0].vertIndex()).position().z(),
180  caloParticle.eta());
181  int simHits = 0;
182  float energy = 0.;
183  for (auto const sc : caloParticle.simClusters()) {
184  simHits += sc->hits_and_fractions().size();
185  for (auto const& h_and_f : sc->hits_and_fractions()) {
186  if (hitmap.count(h_and_f.first))
187  energy += hitmap[h_and_f.first]->energy() * h_and_f.second;
188  }
189  }
190  histo.nHitInSimClusters_->Fill((float)simHits);
191  histo.selfEnergy_->Fill(energy);
192  histo.energyDifference_->Fill(1. - energy / caloParticle.energy());
193  }
194  }
195 
196  // simPFSuperClusters
197  for (auto const& sc : simPFClusters) {
198  histos.at(0).simPFSuperClusterSize_->Fill((float)sc.clustersSize());
199  histos.at(0).simPFSuperClusterEnergy_->Fill(sc.rawEnergy());
200  }
201 
202  // simPFCandidates
203  int offset = 100000;
204  double ptx_tot = 0.;
205  double pty_tot = 0.;
206  for (auto const& pfc : simPFCandidates) {
207  size_t type = offset + pfc.particleId();
208  ptx_tot += pfc.px();
209  pty_tot += pfc.py();
210  histos.at(offset).pfcandidateType_->Fill(type - offset);
211  auto& histo = histos.at(type);
212  histo.pfcandidateEnergy_->Fill(pfc.energy());
213  histo.pfcandidatePt_->Fill(pfc.pt());
214  histo.pfcandidateEta_->Fill(pfc.eta());
215  histo.pfcandidatePhi_->Fill(pfc.phi());
216  histo.pfcandidateElementsInBlocks_->Fill(pfc.elementsInBlocks().size());
217  }
218  auto& histo = histos.at(offset);
219  histo.pfcandidate_vect_sum_pt_->Fill(std::sqrt(ptx_tot * ptx_tot + pty_tot * pty_tot));
220 }
221 
223  edm::Run const& run,
224  edm::EventSetup const& iSetup,
226  for (auto const particle : particles_to_monitor_) {
227  ibook.setCurrentFolder(folder_ + "CaloParticles/" + std::to_string(particle));
228  auto& histo = histos[particle];
229  histo.eta_ = ibook.book1D("Eta", "Eta", 80, -4., 4.);
230  histo.energy_ = ibook.book1D("Energy", "Energy", 250, 0., 500.);
231  histo.pt_ = ibook.book1D("Pt", "Pt", 100, 0., 100.);
232  histo.nSimClusters_ = ibook.book1D("NSimClusters", "NSimClusters", 100, 0., 100.);
233  histo.nHitInSimClusters_ = ibook.book1D("NHitInSimClusters", "NHitInSimClusters", 100, 0., 100.);
234  histo.selfEnergy_ = ibook.book1D("SelfEnergy", "SelfEnergy", 250, 0., 500.);
235  histo.energyDifference_ = ibook.book1D("EnergyDifference", "(Energy-SelfEnergy)/Energy", 300, -5., 1.);
236  histo.eta_Zorigin_map_ = ibook.book2D("Eta vs Zorigin", "Eta vs Zorigin", 80, -4., 4., 1100, -550., 550.);
237  }
238  int offset = 100000;
239  ibook.setCurrentFolder(folder_ + "PFCandidates");
240  histos[offset].pfcandidateType_ = ibook.book1D("PFCandidateType", "PFCandidateType", 10, 0, 10);
241  histos[offset].pfcandidate_vect_sum_pt_ = ibook.book1D("PFCandidatePtVectSum", "PFCandidatePtVectSum", 200, 0., 200.);
243  ibook.setCurrentFolder(folder_ + "PFCandidates/" + std::to_string(type));
244  auto& histo = histos[offset + type];
245  histo.pfcandidateEnergy_ = ibook.book1D("PFCandidateEnergy", "PFCandidateEnergy", 250, 0., 250.);
246  histo.pfcandidatePt_ = ibook.book1D("PFCandidatePt", "PFCandidatePt", 250, 0., 250.);
247  histo.pfcandidateEta_ = ibook.book1D("PFCandidateEta", "PFCandidateEta", 100, -5., 5.);
248  histo.pfcandidatePhi_ = ibook.book1D("PFCandidatePhi", "PFCandidatePhi", 100, -4., 4.);
249  histo.pfcandidateElementsInBlocks_ = ibook.book1D("PFCandidateElements", "PFCandidateElements", 20, 0., 20.);
250  }
251  // Folder '0' is meant to be cumulative, with no connection to pdgId
252  ibook.setCurrentFolder(folder_ + std::to_string(0));
253  histos[0].simPFSuperClusterSize_ = ibook.book1D("SimPFSuperClusterSize", "SimPFSuperClusterSize", 40, 0., 40.);
254  histos[0].simPFSuperClusterEnergy_ =
255  ibook.book1D("SimPFSuperClusterEnergy", "SimPFSuperClusterEnergy", 250, 0., 500.);
256 }
257 
258 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
260  //The following says we do not know what parameters are allowed so do no validation
261  // Please change this to state exactly what you do use, even if it is no parameters
263  desc.add<std::string>("folder", "HGCAL/"); // Please keep the trailing '/'
264  desc.add<std::vector<int>>("particles_to_monitor", {11, -11, 13, -13, 22, 111, 211, -211, 321, -321});
265  desc.add<edm::InputTag>("simVertices", edm::InputTag("g4SimHits"));
266  desc.add<edm::InputTag>("caloParticles", edm::InputTag("mix", "MergedCaloTruth"));
267  desc.add<edm::InputTag>("simPFClusters", edm::InputTag("simPFProducer", "perfect"));
268  desc.add<edm::InputTag>("simPFCandidates", edm::InputTag("simPFProducer"));
269  desc.add<edm::InputTag>("recHitsEE", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
270  desc.add<edm::InputTag>("recHitsFH", edm::InputTag("HGCalRecHit", "HGCHEFRecHits"));
271  desc.add<edm::InputTag>("recHitsBH", edm::InputTag("HGCalRecHit", "HGCHEBRecHits"));
272  descriptions.add("caloparticlevalidationDefault", desc);
273 }
274 
275 //define this as a plug-in
Histogram_CaloParticleSingle::simPFSuperClusterSize_
dqm::reco::MonitorElement * simPFSuperClusterSize_
Definition: CaloParticleValidation.cc:43
dqm::impl::MonitorElement
Definition: MonitorElement.h:98
CaloParticleValidation::caloParticles_
edm::EDGetTokenT< std::vector< CaloParticle > > caloParticles_
Definition: CaloParticleValidation.cc:76
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
Histogram_CaloParticleSingle::pfcandidateElementsInBlocks_
dqm::reco::MonitorElement * pfcandidateElementsInBlocks_
Definition: CaloParticleValidation.cc:50
SimVertex
Definition: SimVertex.h:5
CaloParticleValidation::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, Histograms_CaloParticleValidation &) const override
Definition: CaloParticleValidation.cc:222
Histogram_CaloParticleSingle::energyDifference_
dqm::reco::MonitorElement * energyDifference_
Definition: CaloParticleValidation.cc:41
PFCandidate.h
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
CaloParticleValidation::recHitsFH_
edm::EDGetTokenT< HGCRecHitCollection > recHitsFH_
Definition: CaloParticleValidation.cc:80
Histogram_CaloParticleSingle::pfcandidateEta_
dqm::reco::MonitorElement * pfcandidateEta_
Definition: CaloParticleValidation.cc:48
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
reco::PFCandidate::h
Definition: PFCandidate.h:45
CaloParticleValidation::folder_
std::string folder_
Definition: CaloParticleValidation.cc:72
timingPdfMaker.histo
histo
Definition: timingPdfMaker.py:279
FastTrackerRecHitCombiner_cfi.simHits
simHits
Definition: FastTrackerRecHitCombiner_cfi.py:5
edm::SortedCollection
Definition: SortedCollection.h:49
Histogram_CaloParticleSingle::selfEnergy_
dqm::reco::MonitorElement * selfEnergy_
Definition: CaloParticleValidation.cc:40
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
Histogram_CaloParticleSingle::nSimClusters_
dqm::reco::MonitorElement * nSimClusters_
Definition: CaloParticleValidation.cc:37
Histogram_CaloParticleSingle::pt_
dqm::reco::MonitorElement * pt_
Definition: CaloParticleValidation.cc:35
MakerMacros.h
Histogram_CaloParticleSingle::nHitInSimClusters_
dqm::reco::MonitorElement * nHitInSimClusters_
Definition: CaloParticleValidation.cc:38
SimCluster.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
Histogram_CaloParticleSingle::eta_Zorigin_map_
dqm::reco::MonitorElement * eta_Zorigin_map_
Definition: CaloParticleValidation.cc:42
Histograms_CaloParticleValidation
std::unordered_map< int, Histogram_CaloParticleSingle > Histograms_CaloParticleValidation
Definition: CaloParticleValidation.cc:54
caloTruthCellsProducer_cfi.caloParticles
caloParticles
Definition: caloTruthCellsProducer_cfi.py:6
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
SimVertex.h
CaloParticleValidation::recHitsBH_
edm::EDGetTokenT< HGCRecHitCollection > recHitsBH_
Definition: CaloParticleValidation.cc:81
CaloParticleValidation::particles_to_monitor_
std::vector< int > particles_to_monitor_
Definition: CaloParticleValidation.cc:73
Histogram_CaloParticleSingle::pfcandidate_vect_sum_pt_
dqm::reco::MonitorElement * pfcandidate_vect_sum_pt_
Definition: CaloParticleValidation.cc:51
Histogram_CaloParticleSingle::eta_
dqm::reco::MonitorElement * eta_
Definition: CaloParticleValidation.cc:34
CaloParticleValidation::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: CaloParticleValidation.cc:259
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
Histogram_CaloParticleSingle::pfcandidatePt_
dqm::reco::MonitorElement * pfcandidatePt_
Definition: CaloParticleValidation.cc:47
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
folder_
std::string folder_
Definition: DQMEDAnalyzer.cc:60
CaloParticleValidation::CaloParticleValidation
CaloParticleValidation(const edm::ParameterSet &)
Definition: CaloParticleValidation.cc:95
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
HGCRecHitCollections.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
CaloParticle
Definition: CaloParticle.h:16
Histogram_CaloParticleSingle::pfcandidateEnergy_
dqm::reco::MonitorElement * pfcandidateEnergy_
Definition: CaloParticleValidation.cc:46
Event.h
CaloParticle.h
reco::PFCandidate::egamma_HF
Definition: PFCandidate.h:51
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
CaloParticleValidation
Definition: CaloParticleValidation.cc:56
CaloParticleValidation::recHitsEE_
edm::EDGetTokenT< HGCRecHitCollection > recHitsEE_
Definition: CaloParticleValidation.cc:79
edm::EventSetup
Definition: EventSetup.h:57
l1t::PFCandidateCollection
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
combine.histos
histos
Definition: combine.py:4
type
type
Definition: HCALResponse.h:21
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
CaloParticleValidation::simPFClusters_
edm::EDGetTokenT< std::vector< reco::SuperCluster > > simPFClusters_
Definition: CaloParticleValidation.cc:77
Frameworkfwd.h
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
Histogram_CaloParticleSingle::pfcandidateType_
dqm::reco::MonitorElement * pfcandidateType_
Definition: CaloParticleValidation.cc:45
SuperCluster.h
reco::PFCandidateCollection
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Definition: PFCandidateFwd.h:12
Histogram_CaloParticleSingle::simPFSuperClusterEnergy_
dqm::reco::MonitorElement * simPFSuperClusterEnergy_
Definition: CaloParticleValidation.cc:44
or
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
CaloParticleValidation::dqmAnalyze
void dqmAnalyze(edm::Event const &, edm::EventSetup const &, Histograms_CaloParticleValidation const &) const override
Definition: CaloParticleValidation.cc:119
dqm::implementation::IBooker
Definition: DQMStore.h:43
CaloParticleValidation::~CaloParticleValidation
~CaloParticleValidation() override
Definition: CaloParticleValidation.cc:108
Histogram_CaloParticleSingle
Definition: CaloParticleValidation.cc:33
DQMGlobalEDAnalyzer
Definition: DQMGlobalEDAnalyzer.h:13
CaloParticleValidation::simPFCandidates_
edm::EDGetTokenT< reco::PFCandidateCollection > simPFCandidates_
Definition: CaloParticleValidation.cc:78
HGCalValidator_cfi.simVertices
simVertices
Definition: HGCalValidator_cfi.py:43
ParameterSet.h
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:78
edm::Event
Definition: Event.h:73
CaloParticleValidation::simVertices_
edm::EDGetTokenT< std::vector< SimVertex > > simVertices_
Definition: CaloParticleValidation.cc:75
Histogram_CaloParticleSingle::energy_
dqm::reco::MonitorElement * energy_
Definition: CaloParticleValidation.cc:36
Histogram_CaloParticleSingle::pfcandidatePhi_
dqm::reco::MonitorElement * pfcandidatePhi_
Definition: CaloParticleValidation.cc:49
edm::InputTag
Definition: InputTag.h:15
PFCandidateFwd.h
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
DQMGlobalEDAnalyzer.h