CMS 3D CMS Logo

HcalCollapseAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-//
2 // Package: Hcal
3 // Class: HcalCollapseAnalyzer
4 //
13 //
14 // Original Author: Sunanda Banerjee
15 // Created: Thu Dec 26 18:52:02 CST 2017
16 //
17 //
18 
19 // system include files
20 #include <string>
21 #include <vector>
22 
23 // Root objects
24 #include "TH1.h"
25 
26 // user include files
29 
33 
44 
47 
49 public:
50  explicit HcalCollapseAnalyzer(const edm::ParameterSet &);
51  ~HcalCollapseAnalyzer() override {}
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
54 
55 private:
56  void analyze(edm::Event const &, edm::EventSetup const &) override;
57  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
58 
59  // ----------member data ---------------------------
61  const int verbosity_;
63  const bool doHE_, doHB_;
64 
67 
70 };
71 
73  : topFolderName_(iConfig.getParameter<std::string>("topFolderName")),
74  verbosity_(iConfig.getUntrackedParameter<int>("verbosity", 0)),
75  recHitHBHE_(iConfig.getUntrackedParameter<edm::InputTag>("recHitHBHE", edm::InputTag("hbhereco"))),
76  preRecHitHBHE_(iConfig.getUntrackedParameter<edm::InputTag>("preRecHitHBHE", edm::InputTag("hbheprereco"))),
77  doHE_(iConfig.getUntrackedParameter<bool>("doHE", true)),
78  doHB_(iConfig.getUntrackedParameter<bool>("doHB", false)) {
79  // define tokens for access
80  tok_hbhe_ = consumes<HBHERecHitCollection>(recHitHBHE_);
81  tok_prehbhe_ = consumes<HBHERecHitCollection>(preRecHitHBHE_);
82 
83  edm::LogVerbatim("Collapse") << "Verbosity " << verbosity_ << " with tags " << recHitHBHE_ << " and "
84  << preRecHitHBHE_ << " and Do " << doHB_ << ":" << doHE_;
85 }
86 
89  desc.add<std::string>("topFolderName", "HcalCollapse");
90  desc.addUntracked<int>("verbosity", 0);
91  desc.addUntracked<edm::InputTag>("recHitHBHE", edm::InputTag("hbhereco"));
92  desc.addUntracked<edm::InputTag>("preRecHitHBHE", edm::InputTag("hbheprereco"));
93  desc.addUntracked<bool>("doHE", true);
94  desc.addUntracked<bool>("doHB", false);
95  descriptions.add("hcalCollapseAnalyzer", desc);
96 }
97 
99  if (verbosity_ > 0)
100  edm::LogVerbatim("Collapse") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event()
101  << " starts ==============";
102 
104  iSetup.get<HcalRecNumberingRecord>().get(htopo);
105  const HcalTopology *theHBHETopology = htopo.product();
106 
108  iEvent.getByToken(tok_hbhe_, hbhereco);
110  iEvent.getByToken(tok_prehbhe_, hbheprereco);
111  if (verbosity_ > 0) {
112  edm::LogVerbatim("Collapse") << "Handle Reco " << hbhereco << " Size " << hbhereco->size();
113  edm::LogVerbatim("Collapse") << "Handle PreReco " << hbheprereco << " Size " << hbheprereco->size();
114  }
115  if (hbhereco.isValid() && hbheprereco.isValid()) {
116  const HBHERecHitCollection *recohbhe = hbhereco.product();
117  const HBHERecHitCollection *prerecohbhe = hbheprereco.product();
118  if (verbosity_ > 0)
119  edm::LogVerbatim("Collapse") << "Size of hbhereco: " << recohbhe->size()
120  << " and hbheprereco: " << prerecohbhe->size();
121  double sfrac = (prerecohbhe->empty()) ? 1 : ((double)(recohbhe->size())) / ((double)(prerecohbhe->size()));
122  h_sfrac->Fill(sfrac);
123  h_size->Fill(recohbhe->size());
124  for (const auto &hit : (*recohbhe)) {
125  HcalDetId id = hit.id();
126  if (((id.subdet() == HcalEndcap) && doHE_) || ((id.subdet() == HcalBarrel) && doHB_)) {
127  h_depth->Fill(id.depth());
128  std::vector<HcalDetId> ids;
129  theHBHETopology->unmergeDepthDetId(id, ids);
130  if (verbosity_ > 0) {
131  edm::LogVerbatim("Collapse") << id << " is derived from " << ids.size() << " components";
132  for (unsigned int k = 0; k < ids.size(); ++k)
133  edm::LogVerbatim("Collapse") << "[" << k << "] " << ids[k];
134  }
135  h_merge->Fill(ids.size());
136  double energy = hit.energy();
137  double etot(0);
138  unsigned int k(0);
139  for (const auto phit : (*prerecohbhe)) {
140  if (std::find(ids.begin(), ids.end(), phit.id()) != ids.end()) {
141  etot += phit.energy();
142  double frac = (energy > 0) ? phit.energy() / energy : 1.0;
143  h_frac->Fill(frac);
144  if (verbosity_ > 0)
145  edm::LogVerbatim("Collapse") << "Frac[" << k << "] " << frac << " for " << phit.id();
146  ++k;
147  }
148  }
149  double frac = (energy > 0) ? etot / energy : 1.0;
150  h_balance->Fill(frac);
151  if (verbosity_ > 0)
152  edm::LogVerbatim("Collapse") << "Total energy " << energy << ":" << etot << ":" << frac;
153  }
154  }
155  }
156 }
157 
159  // Book histograms
161  h_merge = ibooker.book1D("h_merge", "Number of hits merged", 10, 0.0, 10.0);
162  h_size = ibooker.book1D("h_size", "Size of the RecHit collection", 100, 500.0, 1500.0);
163  h_depth = ibooker.book1D("h_depth", "Depth of the Id's used", 10, 0.0, 10.0);
164  h_sfrac = ibooker.book1D("h_sfrac", "Ratio of sizes of preRecHit and RecHit collections", 150, 0.0, 1.5);
165  h_frac = ibooker.book1D("h_frac", "Fraction of energy before collapse", 150, 0.0, 1.5);
166  h_balance = ibooker.book1D("h_balance", "Balance of energy between pre- and post-collapse", 100, 0.5, 1.5);
167 }
168 
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
const edm::InputTag preRecHitHBHE_
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
void analyze(edm::Event const &, edm::EventSetup const &) override
void unmergeDepthDetId(const HcalDetId &id, std::vector< HcalDetId > &ids) const
Definition: HcalTopology.h:172
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
int k[5][pyjets_maxn]
unsigned int id
HcalCollapseAnalyzer(const edm::ParameterSet &)
T const * product() const
Definition: Handle.h:74
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< HBHERecHitCollection > tok_prehbhe_
const edm::InputTag recHitHBHE_
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:71
const std::string topFolderName_
MonitorElement * h_balance
T const * product() const
Definition: ESHandle.h:86
Definition: Run.h:45
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_