CMS 3D CMS Logo

HcalSimHitDump.cc
Go to the documentation of this file.
3 
8 
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 
36 protected:
37  void beginJob() override {}
38  void endJob() override {}
39  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
40 
41  void analyzeHits(std::vector<PCaloHit>&);
42 
43 private:
47 };
48 
50  g4Label_ = ps.getUntrackedParameter<std::string>("ModuleLabel", "g4SimHits");
51  hitLab_ = ps.getUntrackedParameter<std::string>("HCCollection", "HcalHits");
52  maxEvent_ = ps.getUntrackedParameter<int>("MaxEvent", 10);
53 
54  // register for data access
55  toks_calo_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hitLab_));
56 
57  edm::LogVerbatim("HitStudy") << "HcalSimHitDump::Module Label: " << g4Label_ << " Hits: " << hitLab_ << " MaxEvent "
58  << maxEvent_;
59 }
60 
62  ++nevt_;
63  edm::LogVerbatim("HitStudy") << "HcalSimHitDump::Serial # " << nevt_ << " Run # " << e.id().run() << " Event # "
64  << e.id().event();
65 
66  if (nevt_ <= maxEvent_) {
67  std::vector<PCaloHit> hcHits;
69  e.getByToken(toks_calo_, hitsCalo);
70  if (hitsCalo.isValid()) {
71  edm::LogVerbatim("HitStudy") << "HcalValidation: get valid hist for Hcal";
72  std::vector<PCaloHit> caloHits;
73  caloHits.insert(caloHits.end(), hitsCalo->begin(), hitsCalo->end());
74  edm::LogVerbatim("HitStudy") << "HcalValidation: Hit buffer " << caloHits.size();
75  analyzeHits(caloHits);
76  }
77  }
78 }
79 
80 void HcalSimHitDump::analyzeHits(std::vector<PCaloHit>& hits) {
81  bool testN(false);
82  for (unsigned int k = 1; k < hits.size(); ++k) {
83  int det = (((hits[k].id()) >> 28) & 0xF);
84  if (det != 4) {
85  testN = true;
86  break;
87  }
88  }
89  edm::LogVerbatim("HitStudy") << "Hit ID uses numbering scheme " << testN << " (0 normal; 1 test)";
90 
91  //Now the dump
92  for (unsigned int i = 0; i < hits.size(); i++) {
93  double edep = hits[i].energy();
94  double time = hits[i].time();
95  unsigned int id_ = hits[i].id();
96  if (testN) {
97  int det, z, depth, eta, phi, lay;
98  HcalTestNumbering::unpackHcalIndex(id_, det, z, depth, eta, phi, lay);
99  std::string sub("HX");
100  if (det == 1)
101  sub = "HB";
102  else if (det == 2)
103  sub = "HE";
104  else if (det == 3)
105  sub = "HO";
106  else if (det == 4)
107  sub = "HF";
108  else if (det == 5)
109  sub = "HT";
110  int side = (z == 0) ? (-1) : (1);
111  edm::LogVerbatim("HitStudy") << "[" << i << "] (" << sub << " " << side * eta << "," << phi << "," << depth << ","
112  << lay << ") E " << edep << " T " << time;
113  } else {
114  edm::LogVerbatim("HitStudy") << "[" << i << "] " << HcalDetId(id_) << " E " << edep << " T " << time;
115  }
116  }
117 }
118 
119 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:38
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginJob() override
std::string g4Label_
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
std::string hitLab_
bool isValid() const
Definition: HandleBase.h:70
edm::EventID id() const
Definition: EventBase.h:59
void analyze(const edm::Event &e, const edm::EventSetup &c) override
HcalSimHitDump(const edm::ParameterSet &ps)