CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalSimHitDump.cc
Go to the documentation of this file.
3 
7 
13 
21 
23 
24 #include <memory>
25 #include <iostream>
26 #include <fstream>
27 #include <vector>
28 #include <map>
29 #include <string>
30 
32 public:
34  ~HcalSimHitDump() override {}
35  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
36 
37 protected:
38  void beginJob() override {}
39  void endJob() override {}
40  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
41 
42  void analyzeHits(std::vector<PCaloHit>&);
43 
44 private:
46  const int maxEvent_;
47  const bool testNumber_;
49  int nevt_;
50 };
51 
53  : g4Label_(ps.getParameter<std::string>("ModuleLabel")),
54  hitLab_(ps.getParameter<std::string>("HCCollection")),
55  maxEvent_(ps.getParameter<int>("MaxEvent")),
56  testNumber_(ps.getParameter<bool>("TestNumber")),
57  nevt_(0) {
58  // register for data access
59  toks_calo_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hitLab_));
60 
61  edm::LogVerbatim("HitStudy") << "HcalSimHitDump::Module Label: " << g4Label_ << " Hits: " << hitLab_ << " MaxEvent "
62  << maxEvent_ << " TestNumbering " << testNumber_;
63 }
64 
67  desc.add<std::string>("ModuleLabel", "g4SimHits");
68  desc.add<std::string>("HCCollection", "HcalHits");
69  desc.add<int>("MaxEvent", 10);
70  desc.add<bool>("TestNumber", true);
71  descriptions.add("hcalSimHitDump", desc);
72 }
73 
75  ++nevt_;
76  edm::LogVerbatim("HitStudy") << "HcalSimHitDump::Serial # " << nevt_ << " Run # " << e.id().run() << " Event # "
77  << e.id().event();
78 
79  if (nevt_ <= maxEvent_) {
80  std::vector<PCaloHit> hcHits;
82  e.getByToken(toks_calo_, hitsCalo);
83  if (hitsCalo.isValid()) {
84  edm::LogVerbatim("HitStudy") << "HcalValidation: get valid hist for Hcal";
85  std::vector<PCaloHit> caloHits;
86  caloHits.insert(caloHits.end(), hitsCalo->begin(), hitsCalo->end());
87  edm::LogVerbatim("HitStudy") << "HcalValidation: Hit buffer " << caloHits.size();
88  analyzeHits(caloHits);
89  }
90  }
91 }
92 
93 void HcalSimHitDump::analyzeHits(std::vector<PCaloHit>& hits) {
94  //Now the dump
95  for (unsigned int i = 0; i < hits.size(); i++) {
96  double edep = hits[i].energy();
97  double time = hits[i].time();
98  unsigned int id_ = hits[i].id();
99  if (testNumber_) {
100  int det, z, depth, eta, phi, lay;
101  HcalTestNumbering::unpackHcalIndex(id_, det, z, depth, eta, phi, lay);
102  std::string sub("HX");
103  if (det == 1)
104  sub = "HB";
105  else if (det == 2)
106  sub = "HE";
107  else if (det == 3)
108  sub = "HO";
109  else if (det == 4)
110  sub = "HF";
111  else if (det == 5)
112  sub = "HT";
113  int side = (z == 0) ? (-1) : (1);
114  edm::LogVerbatim("HitStudy") << "[" << i << "] (" << sub << " " << side * eta << "," << phi << "," << depth << ","
115  << lay << ") E " << edep << " T " << time;
116  } else {
117  edm::LogVerbatim("HitStudy") << "[" << i << "] " << HcalDetId(id_) << " E " << edep << " T " << time;
118  }
119  }
120 }
121 
122 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:38
Log< level::Info, true > LogVerbatim
EventNumber_t event() const
Definition: EventID.h:40
const edm::EventSetup & c
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
const std::string g4Label_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
maxEvent_(ps.getParameter< int >("MaxEvent"))
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void endJob() override
const bool testNumber_
const std::string hitLab_
void beginJob() override
edm::EDGetTokenT< edm::PCaloHitContainer > toks_calo_
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
void analyzeHits(std::vector< PCaloHit > &)
~HcalSimHitDump() override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:70
const int maxEvent_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EventID id() const
Definition: EventBase.h:59
void analyze(const edm::Event &e, const edm::EventSetup &c) override
HcalSimHitDump(const edm::ParameterSet &ps)