CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HGCalHitCheck.cc
Go to the documentation of this file.
11 
14 
17 
20 
25 
26 #include <map>
27 #include <string>
28 #include <vector>
29 #include <TH1D.h>
30 
32 public:
34  ~HGcalHitCheck() override {}
35  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
36 
37 protected:
38  void analyze(edm::Event const&, edm::EventSetup const&) override;
39  void beginJob() override;
40  void endJob() override {}
41 
42 private:
44  const int layers_, verbosity_;
47  bool histos_;
48  TH1D *h_hits_, *h_hit1_, *h_hit2_;
49  std::vector<TH1D*> h_hitL_, h_hitF_, h_hitP_;
50 };
51 
53  : g4Label_(ps.getParameter<std::string>("moduleLabel")),
54  caloHitSource_(ps.getParameter<std::string>("caloHitSource")),
55  nameSense_(ps.getParameter<std::string>("nameSense")),
56  nameDetector_(ps.getParameter<std::string>("tag")),
57  tag_(ps.getParameter<std::string>("nameDevice")),
58  layers_(ps.getParameter<int>("layers")),
59  verbosity_(ps.getParameter<int>("verbosity")),
60  tok_calo_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, caloHitSource_))),
62  histos_(false) {
63  edm::LogVerbatim("HitStudy") << "Test Hit ID for " << nameDetector_ << " using SimHits for " << nameSense_
64  << " with module Label: " << g4Label_ << " Hits: " << caloHitSource_;
65 }
66 
69  desc.add<std::string>("moduleLabel", "g4SimHits");
70  desc.add<std::string>("caloHitSource", "HGCHitsEE");
71  desc.add<std::string>("nameSense", "HGCalEESensitive");
72  desc.add<std::string>("nameDevice", "HGCal EE");
73  desc.add<std::string>("tag", "DDD");
74  desc.add<int>("layers", 26);
75  desc.add<int>("verbosity", 0);
76  descriptions.add("hgcalHitCheckEE", desc);
77 }
78 
81  if (!fs.isAvailable()) {
82  edm::LogVerbatim("HitStudy") << "TFileService unavailable: no histograms";
83  } else {
84  histos_ = true;
85  char name[100], title[200];
86  sprintf(name, "HitsL");
87  sprintf(title, "Number of hits in %s for %s", nameSense_.c_str(), tag_.c_str());
88  h_hits_ = fs->make<TH1D>(name, title, 1000, 0, 5000.);
89  h_hits_->GetXaxis()->SetTitle(title);
90  h_hits_->GetYaxis()->SetTitle("Hits");
91  h_hits_->Sumw2();
92  sprintf(name, "HitsF");
93  sprintf(title, "Number of hits in %s for %s in Full Wafers or SiPM 2", nameSense_.c_str(), tag_.c_str());
94  h_hit1_ = fs->make<TH1D>(name, title, 1000, 0, 5000.);
95  h_hit1_->GetXaxis()->SetTitle(title);
96  h_hit1_->GetYaxis()->SetTitle("Hits");
97  h_hit1_->Sumw2();
98  sprintf(name, "HitsP");
99  sprintf(title, "Number of hits in %s for %s in Partial Wafers or SiPM 4", nameSense_.c_str(), tag_.c_str());
100  h_hit2_ = fs->make<TH1D>(name, title, 1000, 0, 5000.);
101  h_hit2_->GetXaxis()->SetTitle(title);
102  h_hit2_->GetYaxis()->SetTitle("Hits");
103  h_hit2_->Sumw2();
104  for (int k = 0; k < layers_; ++k) {
105  sprintf(name, "HitsL%d", k + 1);
106  sprintf(title, "Number of hits in %s for %s in Layer %d", nameSense_.c_str(), tag_.c_str(), k + 1);
107  h_hitL_.emplace_back(fs->make<TH1D>(name, title, 1000, 0, 5000.));
108  h_hitL_.back()->GetXaxis()->SetTitle(title);
109  h_hitL_.back()->GetYaxis()->SetTitle("Hits");
110  h_hitL_.back()->Sumw2();
111  sprintf(name, "HitsF%d", k + 1);
112  sprintf(title,
113  "Number of hits in %s for %s in Full Wafers or SiPM 2 of Layer %d",
114  nameSense_.c_str(),
115  tag_.c_str(),
116  k + 1);
117  h_hitF_.emplace_back(fs->make<TH1D>(name, title, 1000, 0, 5000.));
118  h_hitF_.back()->GetXaxis()->SetTitle(title);
119  h_hitF_.back()->GetYaxis()->SetTitle("Hits");
120  h_hitF_.back()->Sumw2();
121  sprintf(name, "HitsP%d", k + 1);
122  sprintf(title,
123  "Number of hits in %s for %s in Partial Wafers or SiPM 4 of Layer %d",
124  nameSense_.c_str(),
125  tag_.c_str(),
126  k + 1);
127  h_hitP_.emplace_back(fs->make<TH1D>(name, title, 1000, 0, 5000.));
128  h_hitP_.back()->GetXaxis()->SetTitle(title);
129  h_hitP_.back()->GetYaxis()->SetTitle("Hits");
130  h_hitP_.back()->Sumw2();
131  }
132  }
133 }
134 
136  if (verbosity_ > 0)
137  edm::LogVerbatim("HitStudy") << "Run = " << e.id().run() << " Event = " << e.id().event();
138 
139  // get hcalGeometry
140  const HGCalGeometry* geom = &iS.getData(geomToken_);
141  const HGCalDDDConstants& hgc = geom->topology().dddConstants();
142  const std::vector<DetId>& validIds = geom->getValidDetIds();
143  edm::LogVerbatim("HitStudy") << "Detector " << nameSense_ << " with " << validIds.size() << " valid cells";
144 
145  const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(tok_calo_);
146  bool getHits = (hitsCalo.isValid());
147  uint32_t nhits = (getHits) ? hitsCalo->size() : 0;
148  uint32_t wafer(0), tiles(0);
149  if (verbosity_ > 1)
150  edm::LogVerbatim("HitStudy") << "HGcalHitCheck: Input flags Hits " << getHits << " with " << nhits << " hits";
151  if (histos_)
152  h_hits_->Fill(nhits);
153 
154  if (getHits) {
155  std::vector<PCaloHit> hits;
156  hits.insert(hits.end(), hitsCalo->begin(), hitsCalo->end());
157  if (!hits.empty()) {
158  for (auto hit : hits) {
159  if (histos_) {
160  if ((nameSense_ == "HGCalEESensitive") || (nameSense_ == "HGCalHESiliconSensitive")) {
161  ++wafer;
163  int lay = id.layer();
164  h_hitL_[lay - 1]->Fill(nhits);
165  HGCalParameters::waferInfo info = hgc.waferInfo(lay, id.waferU(), id.waferV());
166  if (info.part == HGCalTypes::WaferFull) {
167  h_hit1_->Fill(nhits);
168  h_hitF_[lay - 1]->Fill(nhits);
169  } else {
170  h_hit2_->Fill(nhits);
171  h_hitP_[lay - 1]->Fill(nhits);
172  }
173  } else {
174  ++tiles;
176  int lay = id.layer();
177  h_hitL_[lay - 1]->Fill(nhits);
178  int sipm = id.sipm();
179  if (sipm == 1) {
180  h_hit2_->Fill(nhits);
181  h_hitP_[lay - 1]->Fill(nhits);
182  } else {
183  h_hit1_->Fill(nhits);
184  h_hitF_[lay - 1]->Fill(nhits);
185  }
186  }
187  }
188  }
189  }
190  }
191  edm::LogVerbatim("HitStudy") << "Total hits = " << nhits << " Wafer DetIds = " << wafer << " Tile DetIds = " << tiles;
192 }
193 
194 //define this as a plug-in
Log< level::Info, true > LogVerbatim
void analyze(edm::Event const &, edm::EventSetup const &) override
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< PCaloHit > PCaloHitContainer
static const TGPicture * info(bool iBackgroundIsBlack)
const std::string nameSense_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const int verbosity_
int32_t waferU(const int32_t index)
std::vector< TH1D * > h_hitP_
const int layers_
static constexpr int32_t WaferFull
Definition: HGCalTypes.h:35
std::vector< TH1D * > h_hitF_
const std::string tag_
const std::string nameDetector_
std::vector< TH1D * > h_hitL_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int id
const std::string g4Label_
void endJob() override
const std::string caloHitSource_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool isValid() const
Definition: HandleBase.h:70
HGcalHitCheck(const edm::ParameterSet &ps)
void beginJob() override
HLT enums.
~HGcalHitCheck() override
int32_t waferV(const int32_t index)
const edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geomToken_
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_calo_