CMS 3D CMS Logo

HGCalHitIdCheck.cc
Go to the documentation of this file.
3 
7 
13 
16 
19 
23 
24 #include <map>
25 #include <string>
26 #include <vector>
27 
29 public:
31  ~HGcalHitIdCheck() override {}
32  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
33 
34 protected:
35  void analyze(edm::Event const&, edm::EventSetup const&) override;
36  void beginJob() override {}
37  void endJob() override {}
38 
39 private:
41  const int verbosity_;
44 };
45 
47  : g4Label_(ps.getParameter<std::string>("moduleLabel")),
48  caloHitSource_(ps.getParameter<std::string>("caloHitSource")),
49  nameSense_(ps.getParameter<std::string>("nameSense")),
50  nameDetector_(ps.getParameter<std::string>("nameDevice")),
51  verbosity_(ps.getParameter<int>("Verbosity")),
52  tok_calo_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, caloHitSource_))),
54  edm::LogVerbatim("HitStudy") << "Test Hit ID for " << nameDetector_ << " using SimHits for " << nameSense_
55  << " with module Label: " << g4Label_ << " Hits: " << caloHitSource_;
56 }
57 
60  desc.add<std::string>("moduleLabel", "g4SimHits");
61  desc.add<std::string>("caloHitSource", "HGCHitsEE");
62  desc.add<std::string>("nameSense", "HGCalEESensitive");
63  desc.add<std::string>("nameDevice", "HGCal EE");
64  desc.add<int>("Verbosity", 0);
65  descriptions.add("hgcalHitIdCheckEE", desc);
66 }
67 
69  if (verbosity_ > 0)
70  edm::LogVerbatim("HitStudy") << "Run = " << e.id().run() << " Event = " << e.id().event();
71 
72  // get hcalGeometry
73  const HGCalGeometry* geom = &iS.getData(geomToken_);
74  const std::vector<DetId>& validIds = geom->getValidDetIds();
75 
76  const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(tok_calo_);
77  bool getHits = (hitsCalo.isValid());
78  uint32_t nhits = (getHits) ? hitsCalo->size() : 0;
79  uint32_t good(0), all(0);
80  if (verbosity_ > 1)
81  edm::LogVerbatim("HitStudy") << "HGcalHitIdCheck: Input flags Hits " << getHits << " with " << nhits << " hits";
82 
83  if (getHits) {
84  std::vector<PCaloHit> hits;
85  hits.insert(hits.end(), hitsCalo->begin(), hitsCalo->end());
86  if (!hits.empty()) {
87  for (auto hit : hits) {
88  ++all;
89  DetId id(hit.id());
90  if (std::find(validIds.begin(), validIds.end(), id) != validIds.end()) {
91  ++good;
92  if (verbosity_ > 2) {
93  if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
94  edm::LogVerbatim("HitStudy") << "Hit[" << all << ":" << good << "]" << HGCSiliconDetId(id);
95  } else if (id.det() == DetId::HGCalHSc) {
96  edm::LogVerbatim("HitStudy") << "Hit[" << all << ":" << good << "]" << HGCScintillatorDetId(id);
97  } else {
98  edm::LogVerbatim("HitStudy") << "Hit[" << all << ":" << good << "]" << std::hex << id.rawId() << std::dec;
99  }
100  }
101  } else {
102  if (verbosity_ > 0) {
103  if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
104  edm::LogVerbatim("HitStudy")
105  << "Hit[" << all << ":" << good << "]" << HGCSiliconDetId(id) << " not valid *****";
106  } else if (id.det() == DetId::HGCalHSc) {
107  HGCScintillatorDetId hid1(id);
108  HGCScintillatorDetId hid2(hid1.type(), hid1.layer(), hid1.ring(), hid1.iphi(), false, 0);
109  bool ok = (std::find(validIds.begin(), validIds.end(), DetId(hid2)) != validIds.end());
110  edm::LogVerbatim("HitStudy") << "Hit[" << all << ":" << good << "]" << hid1 << " not valid ***** but "
111  << hid2 << " in list " << ok;
112  } else {
113  edm::LogVerbatim("HitStudy")
114  << "Hit[" << all << ":" << good << "]" << std::hex << id.rawId() << std::dec << " not valid *****";
115  }
116  }
117  }
118  }
119  }
120  }
121  edm::LogVerbatim("HitStudy") << "Total hits = " << all << ":" << nhits << " Good DetIds = " << good
122  << " Invalid DetIds = " << (all - good);
123 }
124 
125 //define this as a plug-in
void beginJob() override
void endJob() override
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< PCaloHit > PCaloHitContainer
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
void analyze(edm::Event const &, edm::EventSetup const &) override
const int verbosity_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int type() const
get/set the type
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
int iphi() const
get the phi index
const std::string nameSense_
int layer() const
get the layer #
const std::string nameDetector_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~HGcalHitIdCheck() override
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_calo_
unsigned int id
int ring() const
get the eta index
const std::string caloHitSource_
Definition: DetId.h:17
const edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geomToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HGcalHitIdCheck(const edm::ParameterSet &ps)
bool isValid() const
Definition: HandleBase.h:70
const std::string g4Label_
HLT enums.