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 
80 };
81 
82 //
83 // constants, enums and typedefs
84 //
85 
86 //
87 // static data member definitions
88 //
89 
90 //
91 // constructors and destructor
92 //
94  : folder_(iConfig.getParameter<std::string>("folder")),
95  particles_to_monitor_(iConfig.getParameter<std::vector<int>>("particles_to_monitor")),
96  simVertices_(consumes<std::vector<SimVertex>>(iConfig.getParameter<edm::InputTag>("simVertices"))),
97  caloParticles_(consumes<std::vector<CaloParticle>>(iConfig.getParameter<edm::InputTag>("caloParticles"))),
98  simPFClusters_(consumes<std::vector<reco::SuperCluster>>(iConfig.getParameter<edm::InputTag>("simPFClusters"))),
99  simPFCandidates_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("simPFCandidates"))),
100  hitMap_(consumes<std::unordered_map<DetId, const HGCRecHit*>>(iConfig.getParameter<edm::InputTag>("hitMapTag"))) {
101  //now do what ever initialization is needed
102 }
103 
105  // do anything here that needs to be done at desctruction time
106  // (e.g. close files, deallocate resources etc.)
107 }
108 
109 //
110 // member functions
111 //
112 
113 // ------------ method called for each event ------------
114 
116  edm::EventSetup const& iSetup,
118  using namespace edm;
119 
121  iEvent.getByToken(hitMap_, hitMapHandle);
122  const auto hitmap = *hitMapHandle;
123 
124  Handle<std::vector<SimVertex>> simVerticesHandle;
125  iEvent.getByToken(simVertices_, simVerticesHandle);
126  std::vector<SimVertex> const& simVertices = *simVerticesHandle;
127 
128  Handle<std::vector<CaloParticle>> caloParticleHandle;
129  iEvent.getByToken(caloParticles_, caloParticleHandle);
130  std::vector<CaloParticle> const& caloParticles = *caloParticleHandle;
131 
132  Handle<std::vector<reco::SuperCluster>> simPFClustersHandle;
133  iEvent.getByToken(simPFClusters_, simPFClustersHandle);
134  std::vector<reco::SuperCluster> const& simPFClusters = *simPFClustersHandle;
135 
136  Handle<reco::PFCandidateCollection> simPFCandidatesHandle;
137  iEvent.getByToken(simPFCandidates_, simPFCandidatesHandle);
138  reco::PFCandidateCollection const& simPFCandidates = *simPFCandidatesHandle;
139 
140  for (auto const& caloParticle : caloParticles) {
141  if (caloParticle.g4Tracks()[0].eventId().event() != 0 or
142  caloParticle.g4Tracks()[0].eventId().bunchCrossing() != 0) {
143  LogDebug("CaloParticleValidation") << "Excluding CaloParticles from event: "
144  << caloParticle.g4Tracks()[0].eventId().event()
145  << " with BX: " << caloParticle.g4Tracks()[0].eventId().bunchCrossing()
146  << std::endl;
147  continue;
148  }
149  int id = caloParticle.pdgId();
150  if (histos.count(id)) {
151  auto& histo = histos.at(id);
152  histo.eta_->Fill(caloParticle.eta());
153  histo.pt_->Fill(caloParticle.pt());
154  histo.energy_->Fill(caloParticle.energy());
155  histo.nSimClusters_->Fill(caloParticle.simClusters().size());
156  // Find the corresponding vertex.
157  histo.eta_Zorigin_map_->Fill(simVertices.at(caloParticle.g4Tracks()[0].vertIndex()).position().z(),
158  caloParticle.eta());
159  int simHits = 0;
160  float energy = 0.;
161  for (auto const& sc : caloParticle.simClusters()) {
162  simHits += sc->hits_and_fractions().size();
163  for (auto const& h_and_f : sc->hits_and_fractions()) {
164  if (hitmap.count(h_and_f.first))
165  energy += hitmap.at(h_and_f.first)->energy() * h_and_f.second;
166  }
167  }
168  histo.nHitInSimClusters_->Fill((float)simHits);
169  histo.selfEnergy_->Fill(energy);
170  histo.energyDifference_->Fill(1. - energy / caloParticle.energy());
171  }
172  }
173 
174  // simPFSuperClusters
175  for (auto const& sc : simPFClusters) {
176  histos.at(0).simPFSuperClusterSize_->Fill((float)sc.clustersSize());
177  histos.at(0).simPFSuperClusterEnergy_->Fill(sc.rawEnergy());
178  }
179 
180  // simPFCandidates
181  int offset = 100000;
182  double ptx_tot = 0.;
183  double pty_tot = 0.;
184  for (auto const& pfc : simPFCandidates) {
185  size_t type = offset + pfc.particleId();
186  ptx_tot += pfc.px();
187  pty_tot += pfc.py();
188  histos.at(offset).pfcandidateType_->Fill(type - offset);
189  auto& histo = histos.at(type);
190  histo.pfcandidateEnergy_->Fill(pfc.energy());
191  histo.pfcandidatePt_->Fill(pfc.pt());
192  histo.pfcandidateEta_->Fill(pfc.eta());
193  histo.pfcandidatePhi_->Fill(pfc.phi());
194  histo.pfcandidateElementsInBlocks_->Fill(pfc.elementsInBlocks().size());
195  }
196  auto& histo = histos.at(offset);
197  histo.pfcandidate_vect_sum_pt_->Fill(std::sqrt(ptx_tot * ptx_tot + pty_tot * pty_tot));
198 }
199 
201  edm::Run const& run,
202  edm::EventSetup const& iSetup,
204  for (auto const particle : particles_to_monitor_) {
205  ibook.setCurrentFolder(folder_ + "CaloParticles/" + std::to_string(particle));
206  auto& histo = histos[particle];
207  histo.eta_ = ibook.book1D("Eta", "Eta", 80, -4., 4.);
208  histo.energy_ = ibook.book1D("Energy", "Energy", 250, 0., 500.);
209  histo.pt_ = ibook.book1D("Pt", "Pt", 100, 0., 100.);
210  histo.nSimClusters_ = ibook.book1D("NSimClusters", "NSimClusters", 100, 0., 100.);
211  histo.nHitInSimClusters_ = ibook.book1D("NHitInSimClusters", "NHitInSimClusters", 100, 0., 100.);
212  histo.selfEnergy_ = ibook.book1D("SelfEnergy", "SelfEnergy", 250, 0., 500.);
213  histo.energyDifference_ = ibook.book1D("EnergyDifference", "(Energy-SelfEnergy)/Energy", 300, -5., 1.);
214  histo.eta_Zorigin_map_ = ibook.book2D("Eta vs Zorigin", "Eta vs Zorigin", 80, -4., 4., 1100, -550., 550.);
215  }
216  int offset = 100000;
217  ibook.setCurrentFolder(folder_ + "PFCandidates");
218  histos[offset].pfcandidateType_ = ibook.book1D("PFCandidateType", "PFCandidateType", 10, 0, 10);
219  histos[offset].pfcandidate_vect_sum_pt_ = ibook.book1D("PFCandidatePtVectSum", "PFCandidatePtVectSum", 200, 0., 200.);
221  ibook.setCurrentFolder(folder_ + "PFCandidates/" + std::to_string(type));
222  auto& histo = histos[offset + type];
223  histo.pfcandidateEnergy_ = ibook.book1D("PFCandidateEnergy", "PFCandidateEnergy", 250, 0., 250.);
224  histo.pfcandidatePt_ = ibook.book1D("PFCandidatePt", "PFCandidatePt", 250, 0., 250.);
225  histo.pfcandidateEta_ = ibook.book1D("PFCandidateEta", "PFCandidateEta", 100, -5., 5.);
226  histo.pfcandidatePhi_ = ibook.book1D("PFCandidatePhi", "PFCandidatePhi", 100, -4., 4.);
227  histo.pfcandidateElementsInBlocks_ = ibook.book1D("PFCandidateElements", "PFCandidateElements", 20, 0., 20.);
228  }
229  // Folder '0' is meant to be cumulative, with no connection to pdgId
230  ibook.setCurrentFolder(folder_ + std::to_string(0));
231  histos[0].simPFSuperClusterSize_ = ibook.book1D("SimPFSuperClusterSize", "SimPFSuperClusterSize", 40, 0., 40.);
232  histos[0].simPFSuperClusterEnergy_ =
233  ibook.book1D("SimPFSuperClusterEnergy", "SimPFSuperClusterEnergy", 250, 0., 500.);
234 }
235 
236 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
238  //The following says we do not know what parameters are allowed so do no validation
239  // Please change this to state exactly what you do use, even if it is no parameters
241  desc.add<std::string>("folder", "HGCAL/"); // Please keep the trailing '/'
242  desc.add<std::vector<int>>("particles_to_monitor", {11, -11, 13, -13, 22, 111, 211, -211, 321, -321});
243  desc.add<edm::InputTag>("simVertices", edm::InputTag("g4SimHits"));
244  desc.add<edm::InputTag>("caloParticles", edm::InputTag("mix", "MergedCaloTruth"));
245  desc.add<edm::InputTag>("simPFClusters", edm::InputTag("simPFProducer", "perfect"));
246  desc.add<edm::InputTag>("simPFCandidates", edm::InputTag("simPFProducer"));
247  desc.add<edm::InputTag>("hitMapTag", edm::InputTag("hgcalRecHitMapProducer"));
248  descriptions.add("caloparticlevalidationDefault", desc);
249 }
250 
251 //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
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:200
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
Histogram_CaloParticleSingle::pfcandidateEta_
dqm::reco::MonitorElement * pfcandidateEta_
Definition: CaloParticleValidation.cc:48
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
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:46
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
Histogram_CaloParticleSingle::selfEnergy_
dqm::reco::MonitorElement * selfEnergy_
Definition: CaloParticleValidation.cc:40
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
watchdog.const
const
Definition: watchdog.py:83
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
DetId
Definition: DetId.h:17
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::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:237
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
HGCRecHit
Definition: HGCRecHit.h:14
folder_
std::string folder_
Definition: DQMEDAnalyzer.cc:60
CaloParticleValidation::CaloParticleValidation
CaloParticleValidation(const edm::ParameterSet &)
Definition: CaloParticleValidation.cc:93
HGCRecHitCollections.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
CaloParticle
Definition: CaloParticle.h:16
Histogram_CaloParticleSingle::pfcandidateEnergy_
dqm::reco::MonitorElement * pfcandidateEnergy_
Definition: CaloParticleValidation.cc:46
Event.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
CaloParticle.h
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:39
reco::PFCandidate::egamma_HF
Definition: PFCandidate.h:52
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
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:57
l1t::PFCandidateCollection
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
combine.histos
histos
Definition: combine.py:4
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
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:115
dqm::implementation::IBooker
Definition: DQMStore.h:43
CaloParticleValidation::~CaloParticleValidation
~CaloParticleValidation() override
Definition: CaloParticleValidation.cc:104
Histogram_CaloParticleSingle
Definition: CaloParticleValidation.cc:33
DQMGlobalEDAnalyzer
Definition: DQMGlobalEDAnalyzer.h:76
CaloParticleValidation::simPFCandidates_
edm::EDGetTokenT< reco::PFCandidateCollection > simPFCandidates_
Definition: CaloParticleValidation.cc:78
CaloParticleValidation::hitMap_
const edm::EDGetTokenT< std::unordered_map< DetId, const HGCRecHit * > > hitMap_
Definition: CaloParticleValidation.cc:79
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:82
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