CMS 3D CMS Logo

ZDCSimHitStudy.cc
Go to the documentation of this file.
3 
7 
11 
14 
18 
19 #include <CLHEP/Units/GlobalPhysicalConstants.h>
20 #include <CLHEP/Units/SystemOfUnits.h>
21 
22 #include <TH1F.h>
23 
24 #include <string>
25 #include <vector>
26 
27 class ZDCSimHitStudy : public edm::one::EDAnalyzer<edm::one::SharedResources> {
28 public:
30  ~ZDCSimHitStudy() override = default;
31  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
32 
33 protected:
34  void beginJob() override;
35  void endJob() override {}
36  void analyze(const edm::Event &e, const edm::EventSetup &c) override;
37 
38  void analyzeHits(const std::vector<PCaloHit> &);
39 
40 private:
43  const double maxEnergy_, tCut_;
44  const bool verbose_;
46  TH1F *hit_, *eTot_, *eTotT_, *edep_, *time_, *indx_;
47 };
48 
50  : g4Label_(ps.getParameter<std::string>("ModuleLabel")),
51  hitLab_(ps.getParameter<std::string>("HitCollection")),
52  maxEnergy_(ps.getParameter<double>("MaxEnergy")),
53  tCut_(ps.getParameter<double>("TimeCut")),
54  verbose_(ps.getParameter<bool>("Verbose")),
55  toks_calo_(consumes<edm::PCaloHitContainer>(edm::InputTag{g4Label_, hitLab_})) {
56  usesResource(TFileService::kSharedResource);
57 
58  edm::LogVerbatim("HitStudy") << "HOSimHitStudy::Module Label: " << g4Label_ << " Hits: " << hitLab_
59  << " MaxEnergy: " << maxEnergy_ << " time Cut " << tCut_;
60 }
61 
64  desc.add<std::string>("ModuleLabel", "g4SimHits");
65  desc.add<std::string>("HitCollection", "ZDCHITS");
66  desc.add<double>("MaxEnergy", 50.0);
67  desc.add<double>("TimeCut", 2000.0);
68  desc.add<bool>("Verbose", false);
69  descriptions.add("zdcSimHitStudy", desc);
70 }
71 
74 
75  if (!tfile.isAvailable())
76  throw cms::Exception("BadConfig") << "TFileService unavailable: "
77  << "please add it to config file";
78  double ymax = maxEnergy_;
79  hit_ = tfile->make<TH1F>("Hits", "Number of Hits", 100, 0., 100);
80  edep_ = tfile->make<TH1F>("Edep", "Deposited Energy (GeV)", 1000, 0., ymax);
81  eTot_ = tfile->make<TH1F>("ETot", "Total Energy in a time window (GeV)", 1000, 0., ymax);
82  eTotT_ = tfile->make<TH1F>("ETotT", "Total Energy (GeV)", 1000, 0., ymax);
83  time_ = tfile->make<TH1F>("Time", "Hit Time (ns)", 2000, 0., 2000);
84  indx_ = tfile->make<TH1F>("Indx", "Hit ID", 100, 0., 100);
85 }
86 
88  edm::LogVerbatim("HitStudy") << "ZDCSimHitStudy::Run = " << e.id().run() << " Event = " << e.id().event();
89 
90  const edm::Handle<edm::PCaloHitContainer> &hitsCalo = e.getHandle(toks_calo_);
91  bool getHits = (hitsCalo.isValid());
92  edm::LogVerbatim("HitStudy") << "HOSimHitStudy::Input flag " << hitLab_ << " getHits flag " << getHits;
93 
94  std::vector<PCaloHit> zdcHits;
95  if (getHits) {
96  zdcHits.insert(zdcHits.end(), hitsCalo->begin(), hitsCalo->end());
97  unsigned int isiz = zdcHits.size();
98  edm::LogVerbatim("HitStudy") << "ZDCSimHitStudy:: Hit buffer for " << hitLab_ << " has " << isiz << " hits";
99  }
100  analyzeHits(zdcHits);
101 }
102 
103 void ZDCSimHitStudy::analyzeHits(const std::vector<PCaloHit> &zdcHits) {
104  //initialize
105  double etot(0), etotT(0);
106  int nHit = zdcHits.size();
107  for (int i = 0; i < nHit; i++) {
108  double edep = zdcHits[i].energy();
109  double time = zdcHits[i].time();
110  uint32_t id = zdcHits[i].id();
111  int indx = (id & 0xFF);
112  etotT += edep;
113  if (time < tCut_)
114  etot += edep;
115  if (verbose_)
116  edm::LogVerbatim("HitStudy") << "ZDCSimHitStudy:: Hit " << i << " Section:" << HcalZDCDetId(id).section()
117  << " zside:" << HcalZDCDetId(id).zside() << " depth:" << HcalZDCDetId(id).depth()
118  << " channel:" << HcalZDCDetId(id).channel()
119  << " dense:" << HcalZDCDetId(id).denseIndex() << " edep:" << edep
120  << " time:" << time;
121  time_->Fill(time);
122  edep_->Fill(edep);
123  indx_->Fill(indx);
124  }
125  eTot_->Fill(etot);
126  eTotT_->Fill(etotT);
127  hit_->Fill(nHit);
128 
129  if (verbose_)
130  edm::LogVerbatim("HitStudy") << "ZDCSimHitStudy::analyzeHits: Hits in ZDC " << nHit << " Energy deposits " << etot
131  << ":" << etotT;
132 }
133 
134 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
const std::string hitLab_
std::vector< PCaloHit > PCaloHitContainer
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr uint32_t denseIndex() const
Definition: HcalZDCDetId.h:134
~ZDCSimHitStudy() override=default
void analyzeHits(const std::vector< PCaloHit > &)
void beginJob() override
constexpr int32_t depth() const
get the depth (1 for EM, channel + 1 for HAD, 2 for RPD, not sure yet for LUM, leave as default) ...
Definition: HcalZDCDetId.h:100
Definition: tfile.py:1
void analyze(const edm::Event &e, const edm::EventSetup &c) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const bool verbose_
const double maxEnergy_
const edm::EDGetTokenT< edm::PCaloHitContainer > toks_calo_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
constexpr Section section() const
get the section
Definition: HcalZDCDetId.h:92
void endJob() override
HLT enums.
constexpr int32_t channel() const
get the channel
Definition: HcalZDCDetId.h:112
constexpr int32_t zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:90
const std::string g4Label_
ZDCSimHitStudy(const edm::ParameterSet &ps)
const double tCut_