File indexing completed on 2023-05-14 22:52:32
0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0003
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 #include "FWCore/Utilities/interface/transform.h"
0013
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0016
0017 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0018 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0019 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0020 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0021 #include "DataFormats/HcalDetId/interface/HcalTestNumbering.h"
0022
0023 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0024 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0025 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0026 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0027
0028 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0029 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
0030 #include "SimDataFormats/CaloHit/interface/PassiveHit.h"
0031 #include "SimG4CMS/Calo/interface/CaloHitID.h"
0032
0033 #include <TH1F.h>
0034 #include <TH2F.h>
0035
0036 #include <memory>
0037 #include <iostream>
0038 #include <fstream>
0039 #include <vector>
0040 #include <map>
0041 #include <string>
0042
0043
0044
0045 class CaloSimHitAnalysis : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
0046 public:
0047 CaloSimHitAnalysis(const edm::ParameterSet& ps);
0048 ~CaloSimHitAnalysis() override {}
0049 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0050
0051 protected:
0052 void beginJob() override {}
0053 void analyze(edm::Event const&, edm::EventSetup const&) override;
0054 void beginRun(edm::Run const&, edm::EventSetup const&) override {}
0055 void endRun(edm::Run const&, edm::EventSetup const&) override {}
0056
0057 void analyzeHits(std::vector<PCaloHit>&, int);
0058 void analyzePassiveHits(std::vector<PassiveHit>& hits);
0059
0060 private:
0061 const std::string g4Label_;
0062 const std::vector<std::string> hitLab_;
0063 const std::vector<double> timeSliceUnit_;
0064 const double maxEnergy_, maxTime_, tMax_, tScale_, tCut_;
0065 const bool testNumber_, passive_;
0066 const int allSteps_;
0067 const std::vector<std::string> detNames_;
0068 const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tokGeom_;
0069 const std::vector<edm::EDGetTokenT<edm::PCaloHitContainer> > toks_calo_;
0070 const edm::EDGetTokenT<edm::PassiveHitContainer> tok_passive_;
0071
0072 const CaloGeometry* caloGeometry_;
0073 const HcalGeometry* hcalGeom_;
0074
0075 static constexpr int nCalo_ = 6;
0076 TH1F *h_hit_[nCalo_], *h_time_[nCalo_], *h_edep_[nCalo_], *h_edepT_[nCalo_];
0077 TH1F *h_timeT_[nCalo_], *h_edep1_[nCalo_], *h_edepT1_[nCalo_];
0078 TH1F *h_edepEM_[nCalo_], *h_edepHad_[nCalo_], *h_rr_[nCalo_], *h_zz_[nCalo_];
0079 TH1F *h_eta_[nCalo_], *h_phi_[nCalo_], *h_etot_[nCalo_], *h_etotg_[nCalo_];
0080 TH2F *h_rz_, *h_rz1_, *h_etaphi_;
0081 TH1F *h_hitp_, *h_trackp_, *h_edepp_, *h_timep_, *h_stepp_;
0082 std::vector<TH1F*> h_edepTk_, h_timeTk_;
0083 std::vector<TH2F*> h_rzH_;
0084 std::map<int, unsigned int> etaDepth_;
0085 };
0086
0087 CaloSimHitAnalysis::CaloSimHitAnalysis(const edm::ParameterSet& ps)
0088 : g4Label_(ps.getUntrackedParameter<std::string>("moduleLabel", "g4SimHits")),
0089 hitLab_(ps.getParameter<std::vector<std::string> >("hitCollection")),
0090 timeSliceUnit_(ps.getParameter<std::vector<double> >("timeSliceUnit")),
0091 maxEnergy_(ps.getUntrackedParameter<double>("maxEnergy", 250.0)),
0092 maxTime_(ps.getUntrackedParameter<double>("maxTime", 1000.0)),
0093 tMax_(ps.getUntrackedParameter<double>("timeCut", 100.0)),
0094 tScale_(ps.getUntrackedParameter<double>("timeScale", 1.0)),
0095 tCut_(ps.getUntrackedParameter<double>("timeThreshold", 15.0)),
0096 testNumber_(ps.getUntrackedParameter<bool>("testNumbering", false)),
0097 passive_(ps.getUntrackedParameter<bool>("passiveHits", false)),
0098 allSteps_(ps.getUntrackedParameter<int>("allSteps", 100)),
0099 detNames_(ps.getUntrackedParameter<std::vector<std::string> >("detNames")),
0100 tokGeom_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
0101 toks_calo_{edm::vector_transform(hitLab_,
0102 [this](const std::string& name) {
0103 return consumes<edm::PCaloHitContainer>(edm::InputTag{g4Label_, name});
0104 })},
0105 tok_passive_(consumes<edm::PassiveHitContainer>(edm::InputTag(g4Label_, "AllPassiveHits"))) {
0106 usesResource(TFileService::kSharedResource);
0107
0108 edm::LogVerbatim("HitStudy") << "Module Label: " << g4Label_ << " Hits|timeSliceUnit:";
0109 for (unsigned int i = 0; i < hitLab_.size(); i++)
0110 edm::LogVerbatim("HitStudy") << "[" << i << "] " << hitLab_[i] << " " << timeSliceUnit_[i];
0111 edm::LogVerbatim("HitStudy") << "Passive Hits " << passive_ << " from AllPassiveHits";
0112 edm::LogVerbatim("HitStudy") << "maxEnergy: " << maxEnergy_ << " maxTime: " << maxTime_ << " tMax: " << tMax_;
0113 for (unsigned int k = 0; k < detNames_.size(); ++k)
0114 edm::LogVerbatim("HitStudy") << "Detector[" << k << "] " << detNames_[k];
0115
0116 edm::Service<TFileService> tfile;
0117 if (!tfile.isAvailable())
0118 throw cms::Exception("BadConfig") << "TFileService unavailable: "
0119 << "please add it to config file";
0120 char name[29], title[120];
0121 std::string dets[nCalo_] = {"EB", "EE", "HB", "HE", "HO", "HF"};
0122 for (int i = 0; i < nCalo_; i++) {
0123 sprintf(name, "Hit%d", i);
0124 sprintf(title, "Number of hits in %s", dets[i].c_str());
0125 h_hit_[i] = tfile->make<TH1F>(name, title, 100, 0., 20000.);
0126 h_hit_[i]->GetXaxis()->SetTitle(title);
0127 h_hit_[i]->GetYaxis()->SetTitle("Events");
0128 sprintf(name, "Time%d", i);
0129 sprintf(title, "Time of the hit (ns) in %s", dets[i].c_str());
0130 h_time_[i] = tfile->make<TH1F>(name, title, 100, 0., 200.);
0131 h_time_[i]->GetXaxis()->SetTitle(title);
0132 h_time_[i]->GetYaxis()->SetTitle("Hits");
0133 sprintf(name, "TimeT%d", i);
0134 sprintf(title, "Time of each hit (ns) in %s", dets[i].c_str());
0135 h_timeT_[i] = tfile->make<TH1F>(name, title, 100, 0., 200.);
0136 h_timeT_[i]->GetXaxis()->SetTitle(title);
0137 h_timeT_[i]->GetYaxis()->SetTitle("Hits");
0138 double ymax = (i > 1) ? 0.01 : 0.1;
0139 double ymx0 = (i > 1) ? 0.0025 : 0.025;
0140 sprintf(name, "Edep%d", i);
0141 sprintf(title, "Energy deposit (GeV) in %s", dets[i].c_str());
0142 h_edep_[i] = tfile->make<TH1F>(name, title, 100, 0., ymax);
0143 h_edep_[i]->GetXaxis()->SetTitle(title);
0144 h_edep_[i]->GetYaxis()->SetTitle("Hits");
0145 sprintf(name, "EdepT%d", i);
0146 sprintf(title, "Energy deposit (GeV) of each hit in %s", dets[i].c_str());
0147 h_edepT_[i] = tfile->make<TH1F>(name, title, 100, 0., ymx0);
0148 h_edepT_[i]->GetXaxis()->SetTitle(title);
0149 h_edepT_[i]->GetYaxis()->SetTitle("Hits");
0150 sprintf(name, "EdepEM%d", i);
0151 sprintf(title, "Energy deposit (GeV) by EM particles in %s", dets[i].c_str());
0152 h_edepEM_[i] = tfile->make<TH1F>(name, title, 100, 0., ymx0);
0153 h_edepEM_[i]->GetXaxis()->SetTitle(title);
0154 h_edepEM_[i]->GetYaxis()->SetTitle("Hits");
0155 sprintf(name, "EdepHad%d", i);
0156 sprintf(title, "Energy deposit (GeV) by hadrons in %s", dets[i].c_str());
0157 h_edepHad_[i] = tfile->make<TH1F>(name, title, 100, 0., ymx0);
0158 h_edepHad_[i]->GetXaxis()->SetTitle(title);
0159 h_edepHad_[i]->GetYaxis()->SetTitle("Hits");
0160 sprintf(name, "Edep15%d", i);
0161 sprintf(title, "Energy deposit (GeV) for T > %4.0f ns in %s", tCut_, dets[i].c_str());
0162 h_edep1_[i] = tfile->make<TH1F>(name, title, 100, 0., ymax);
0163 h_edep1_[i]->GetXaxis()->SetTitle(title);
0164 h_edep1_[i]->GetYaxis()->SetTitle("Hits");
0165 sprintf(name, "EdepT15%d", i);
0166 sprintf(title, "Energy deposit (GeV) of each hit for T > %4.0f in %s", tCut_, dets[i].c_str());
0167 h_edepT1_[i] = tfile->make<TH1F>(name, title, 100, 0., ymx0);
0168 h_edepT1_[i]->GetXaxis()->SetTitle(title);
0169 h_edepT1_[i]->GetYaxis()->SetTitle("Hits");
0170 ymax = (i > 1) ? 1.0 : maxEnergy_;
0171 sprintf(name, "Etot%d", i);
0172 sprintf(title, "Total energy deposit (GeV) in %s", dets[i].c_str());
0173 h_etot_[i] = tfile->make<TH1F>(name, title, 50, 0., ymax);
0174 h_etot_[i]->GetXaxis()->SetTitle(title);
0175 h_etot_[i]->GetYaxis()->SetTitle("Events");
0176 sprintf(name, "EtotG%d", i);
0177 sprintf(title, "Total energy deposit (GeV) in %s (t < 100 ns)", dets[i].c_str());
0178 h_etotg_[i] = tfile->make<TH1F>(name, title, 50, 0., ymax);
0179 h_etotg_[i]->GetXaxis()->SetTitle(title);
0180 h_etotg_[i]->GetYaxis()->SetTitle("Events");
0181 sprintf(name, "rr%d", i);
0182 sprintf(title, "R of hit point (cm) in %s", dets[i].c_str());
0183 h_rr_[i] = tfile->make<TH1F>(name, title, 100, 0., 250.);
0184 h_rr_[i]->GetXaxis()->SetTitle(title);
0185 h_rr_[i]->GetYaxis()->SetTitle("Hits");
0186 sprintf(name, "zz%d", i);
0187 sprintf(title, "z of hit point (cm) in %s", dets[i].c_str());
0188 h_zz_[i] = tfile->make<TH1F>(name, title, 240, -600., 600.);
0189 h_zz_[i]->GetXaxis()->SetTitle(title);
0190 h_zz_[i]->GetYaxis()->SetTitle("Hits");
0191 sprintf(name, "eta%d", i);
0192 sprintf(title, "#eta of hit point in %s", dets[i].c_str());
0193 h_eta_[i] = tfile->make<TH1F>(name, title, 100, -5.0, 5.0);
0194 h_eta_[i]->GetXaxis()->SetTitle(title);
0195 h_eta_[i]->GetYaxis()->SetTitle("Hits");
0196 sprintf(name, "phi%d", i);
0197 sprintf(title, "#phi of hit point in %s", dets[i].c_str());
0198 h_phi_[i] = tfile->make<TH1F>(name, title, 100, -M_PI, M_PI);
0199 h_phi_[i]->GetXaxis()->SetTitle(title);
0200 h_phi_[i]->GetYaxis()->SetTitle("Hits");
0201 }
0202 sprintf(title, "R vs Z of hit point");
0203 h_rz_ = tfile->make<TH2F>("rz", title, 120, 0., 600., 100, 0., 250.);
0204 h_rz_->GetXaxis()->SetTitle("z (cm)");
0205 h_rz_->GetYaxis()->SetTitle("R (cm)");
0206 sprintf(title, "R vs Z of hit point for hits with T > %4.0f ns", tCut_);
0207 h_rz1_ = tfile->make<TH2F>("rz2", title, 120, 0., 600., 100, 0., 250.);
0208 h_rz1_->GetXaxis()->SetTitle("z (cm)");
0209 h_rz1_->GetYaxis()->SetTitle("R (cm)");
0210 sprintf(title, "#phi vs #eta of hit point");
0211 h_etaphi_ = tfile->make<TH2F>("etaphi", title, 100, 0., 5., 100, 0., M_PI);
0212 h_etaphi_->GetXaxis()->SetTitle("#eta");
0213 h_etaphi_->GetYaxis()->SetTitle("#phi");
0214
0215 if (passive_) {
0216 h_hitp_ = tfile->make<TH1F>("hitp", "All Steps", 100, 0.0, 20000.0);
0217 h_hitp_->GetXaxis()->SetTitle("Hits");
0218 h_hitp_->GetYaxis()->SetTitle("Events");
0219 h_trackp_ = tfile->make<TH1F>("trackp", "All Steps", 100, 0.0, 200000.0);
0220 h_hitp_->GetXaxis()->SetTitle("Tracks");
0221 h_hitp_->GetYaxis()->SetTitle("Events");
0222 h_edepp_ = tfile->make<TH1F>("edepp", "All Steps", 100, 0.0, 50.0);
0223 h_edepp_->GetXaxis()->SetTitle("Energy Deposit (MeV)");
0224 h_edepp_->GetYaxis()->SetTitle("Hits");
0225 h_timep_ = tfile->make<TH1F>("timep", "All Steps", 100, 0.0, 100.0);
0226 h_timep_->GetXaxis()->SetTitle("Hits");
0227 h_timep_->GetYaxis()->SetTitle("Hit Time (ns)");
0228 h_stepp_ = tfile->make<TH1F>("stepp", "All Steps", 1000, 0.0, 100.0);
0229 h_stepp_->GetXaxis()->SetTitle("Hits");
0230 h_stepp_->GetYaxis()->SetTitle("Step length (cm)");
0231 for (unsigned int k = 0; k < detNames_.size(); ++k) {
0232 sprintf(name, "edept%d", k);
0233 sprintf(title, "Energy Deposit (MeV) in %s", detNames_[k].c_str());
0234 h_edepTk_.emplace_back(tfile->make<TH1F>(name, title, 100, 0.0, 1.0));
0235 h_edepTk_.back()->GetYaxis()->SetTitle("Hits");
0236 h_edepTk_.back()->GetXaxis()->SetTitle(title);
0237 sprintf(name, "timet%d", k);
0238 sprintf(title, "Hit Time (ns) in %s", detNames_[k].c_str());
0239 h_timeTk_.emplace_back(tfile->make<TH1F>(name, title, 100, 0.0, 100.0));
0240 h_timeTk_.back()->GetYaxis()->SetTitle("Hits");
0241 h_timeTk_.back()->GetXaxis()->SetTitle(title);
0242 }
0243 if ((allSteps_ / 100) % 10 > 0) {
0244 for (int eta = 1; eta <= 29; ++eta) {
0245 int dmax = (eta < 16) ? 4 : 7;
0246 for (int depth = 1; depth <= dmax; ++depth) {
0247 sprintf(name, "Eta%dDepth%d", eta, depth);
0248 sprintf(title, "R vs Z (#eta = %d, depth = %d)", eta, depth);
0249 etaDepth_[eta * 100 + depth] = h_rzH_.size();
0250 h_rzH_.emplace_back(tfile->make<TH2F>(name, title, 120, 0., 600., 100, 0., 250.));
0251 h_rzH_.back()->GetXaxis()->SetTitle("z (cm)");
0252 h_rzH_.back()->GetYaxis()->SetTitle("R (cm)");
0253 }
0254 }
0255 }
0256 }
0257 }
0258
0259 void CaloSimHitAnalysis::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0260 edm::ParameterSetDescription desc;
0261 std::vector<std::string> labels = {"EcalHitsEB1", "EcalHitsEE1", "HcalHits1"};
0262 std::vector<double> times = {1, 1, 1};
0263 desc.addUntracked<std::string>("moduleLabel", "g4SimHits");
0264 desc.add<std::vector<std::string> >("hitCollection", labels);
0265 desc.add<std::vector<double> >("timeSliceUnit", times);
0266 desc.addUntracked<double>("maxEnergy", 250.0);
0267 desc.addUntracked<double>("maxTime", 1000.0);
0268 desc.addUntracked<double>("timeCut", 100.0);
0269 desc.addUntracked<double>("timeScale", 1.0);
0270 desc.addUntracked<double>("timeThreshold", 15.0);
0271 desc.addUntracked<bool>("testNumbering", false);
0272 desc.addUntracked<bool>("passiveHits", false);
0273 std::vector<std::string> names = {"PixelBarrel", "PixelForward", "TIB", "TID", "TOB", "TEC"};
0274 desc.addUntracked<std::vector<std::string> >("detNames", names);
0275 desc.addUntracked<int>("allStep", 100);
0276 descriptions.add("caloSimHitAnalysis", desc);
0277 }
0278
0279 void CaloSimHitAnalysis::analyze(edm::Event const& e, edm::EventSetup const& set) {
0280 edm::LogVerbatim("HitStudy") << "CaloSimHitAnalysis:Run = " << e.id().run() << " Event = " << e.id().event();
0281
0282 caloGeometry_ = &set.getData(tokGeom_);
0283 hcalGeom_ = static_cast<const HcalGeometry*>(caloGeometry_->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
0284
0285 for (unsigned int i = 0; i < toks_calo_.size(); i++) {
0286 const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(toks_calo_[i]);
0287 bool getHits = (hitsCalo.isValid());
0288 #ifdef EDM_ML_DEBUG
0289 edm::LogVerbatim("HitStudy") << "CaloSimHitAnalysis: Input flags Hits[" << i << "]: " << getHits;
0290 #endif
0291 if (getHits) {
0292 std::vector<PCaloHit> caloHits;
0293 caloHits.insert(caloHits.end(), hitsCalo->begin(), hitsCalo->end());
0294 #ifdef EDM_ML_DEBUG
0295 edm::LogVerbatim("HitStudy") << "CaloSimHitAnalysis: Hit buffer [" << i << "] " << caloHits.size();
0296 #endif
0297 analyzeHits(caloHits, i);
0298 }
0299 }
0300
0301 if (passive_) {
0302 const edm::Handle<edm::PassiveHitContainer>& hitsPassive = e.getHandle(tok_passive_);
0303 bool getHits = (hitsPassive.isValid());
0304 #ifdef EDM_ML_DEBUG
0305 edm::LogVerbatim("HitStudy") << "CaloSimHitAnalysis: Passive: " << getHits;
0306 #endif
0307 if (getHits) {
0308 std::vector<PassiveHit> passiveHits;
0309 passiveHits.insert(passiveHits.end(), hitsPassive->begin(), hitsPassive->end());
0310 #ifdef EDM_ML_DEBUG
0311 edm::LogVerbatim("HitStudy") << "CaloSimHitAnalysis: Passive Hit buffer " << passiveHits.size();
0312 #endif
0313 analyzePassiveHits(passiveHits);
0314 }
0315 }
0316 }
0317
0318 void CaloSimHitAnalysis::analyzeHits(std::vector<PCaloHit>& hits, int indx) {
0319 int nHit = hits.size();
0320 int nHB = 0, nHE = 0, nHO = 0, nHF = 0, nEB = 0, nEE = 0, nBad = 0;
0321 #ifdef EDM_ML_DEBUG
0322 int iHit = 0;
0323 #endif
0324
0325 std::map<CaloHitID, std::pair<double, double> > hitMap;
0326 double etot[nCalo_], etotG[nCalo_];
0327 for (unsigned int k = 0; k < nCalo_; ++k) {
0328 etot[k] = etotG[k] = 0;
0329 }
0330 for (const auto& hit : hits) {
0331 double edep = hit.energy();
0332 double time = tScale_ * hit.time();
0333 uint32_t id = hit.id();
0334 int itra = hit.geantTrackId();
0335 double edepEM = hit.energyEM();
0336 double edepHad = hit.energyHad();
0337 int idx(-1);
0338 if (indx != 2) {
0339 idx = indx;
0340 if (indx == 0)
0341 ++nEB;
0342 else
0343 ++nEE;
0344 } else {
0345 int subdet(0);
0346 if (testNumber_) {
0347 int ieta(0), phi(0), z(0), lay(0), depth(0);
0348 HcalTestNumbering::unpackHcalIndex(id, subdet, z, depth, ieta, phi, lay);
0349 id = HcalDetId(static_cast<HcalSubdetector>(subdet), z * ieta, phi, depth).rawId();
0350 } else {
0351 subdet = HcalDetId(id).subdet();
0352 }
0353 if (subdet == static_cast<int>(HcalBarrel)) {
0354 idx = indx;
0355 nHB++;
0356 } else if (subdet == static_cast<int>(HcalEndcap)) {
0357 idx = indx + 1;
0358 nHE++;
0359 } else if (subdet == static_cast<int>(HcalOuter)) {
0360 idx = indx + 2;
0361 nHO++;
0362 } else if (subdet == static_cast<int>(HcalForward)) {
0363 idx = indx + 3;
0364 nHF++;
0365 }
0366 }
0367 #ifdef EDM_ML_DEBUG
0368 edm::LogVerbatim("HitStudy") << "Hit[" << iHit << ":" << nHit << ":" << idx << "] E " << edep << ":" << edepEM
0369 << ":" << edepHad << " T " << time << " itra " << itra << " ID " << std::hex << id
0370 << std::dec;
0371 ++iHit;
0372 #endif
0373 if (idx >= 0) {
0374 CaloHitID hid(id, time, itra, 0, timeSliceUnit_[indx]);
0375 auto itr = hitMap.find(hid);
0376 if (itr == hitMap.end())
0377 hitMap[hid] = std::make_pair(time, edep);
0378 else
0379 ((itr->second).second) += edep;
0380 h_edepT_[idx]->Fill(edep);
0381 h_timeT_[idx]->Fill(time);
0382 if (edepEM > 0)
0383 h_edepEM_[idx]->Fill(edepEM);
0384 if (edepHad > 0)
0385 h_edepHad_[idx]->Fill(edepHad);
0386 if (time > tCut_)
0387 h_edepT1_[idx]->Fill(edep);
0388 } else {
0389 ++nBad;
0390 }
0391 }
0392
0393
0394 for (auto itr = hitMap.begin(); itr != hitMap.end(); ++itr) {
0395 int idx = -1;
0396 GlobalPoint point;
0397 DetId id((itr->first).unitID());
0398 #ifdef EDM_ML_DEBUG
0399 edm::LogVerbatim("HitStudy") << "Index " << indx << " Geom " << caloGeometry_ << ":" << hcalGeom_ << " "
0400 << std::hex << id.rawId() << std::dec;
0401 #endif
0402 if (indx != 2) {
0403 idx = indx;
0404 point = caloGeometry_->getPosition(id);
0405 } else {
0406 int subdet = id.subdetId();
0407 if (subdet == static_cast<int>(HcalBarrel)) {
0408 idx = indx;
0409 } else if (subdet == static_cast<int>(HcalEndcap)) {
0410 idx = indx + 1;
0411 } else if (subdet == static_cast<int>(HcalOuter)) {
0412 idx = indx + 2;
0413 } else if (subdet == static_cast<int>(HcalForward)) {
0414 idx = indx + 3;
0415 }
0416 point = hcalGeom_->getPosition(id);
0417 }
0418 double edep = (itr->second).second;
0419 double time = (itr->second).first;
0420 #ifdef EDM_ML_DEBUG
0421 edm::LogVerbatim("HitStudy") << "Index " << idx << ":" << nCalo_ << " Point " << point << " E " << edep << " T "
0422 << time;
0423 #endif
0424 if (idx >= 0) {
0425 h_time_[idx]->Fill(time);
0426 h_edep_[idx]->Fill(edep);
0427 h_rr_[idx]->Fill(point.perp());
0428 h_zz_[idx]->Fill(point.z());
0429 h_eta_[idx]->Fill(point.eta());
0430 h_phi_[idx]->Fill(point.phi());
0431 h_rz_->Fill(std::abs(point.z()), point.perp());
0432 h_etaphi_->Fill(std::abs(point.eta()), std::abs(point.phi()));
0433 etot[idx] += edep;
0434 if (time < tMax_)
0435 etotG[idx] += edep;
0436 if (time > tCut_) {
0437 h_edep1_[idx]->Fill(edep);
0438 h_rz1_->Fill(std::abs(point.z()), point.perp());
0439 }
0440 }
0441 }
0442
0443 if (indx < 2) {
0444 h_etot_[indx]->Fill(etot[indx]);
0445 h_etotg_[indx]->Fill(etotG[indx]);
0446 if (indx == 0)
0447 h_hit_[indx]->Fill(double(nEB));
0448 else
0449 h_hit_[indx]->Fill(double(nEE));
0450 } else {
0451 h_hit_[2]->Fill(double(nHB));
0452 h_hit_[3]->Fill(double(nHE));
0453 h_hit_[4]->Fill(double(nHO));
0454 h_hit_[5]->Fill(double(nHF));
0455 for (int idx = 2; idx < nCalo_; idx++) {
0456 h_etot_[idx]->Fill(etot[idx]);
0457 h_etotg_[idx]->Fill(etotG[idx]);
0458 }
0459 }
0460
0461 edm::LogVerbatim("HitStudy") << "CaloSimHitAnalysis::analyzeHits: EB " << nEB << " EE " << nEE << " HB " << nHB
0462 << " HE " << nHE << " HO " << nHO << " HF " << nHF << " Bad " << nBad << " All " << nHit
0463 << " Reduced " << hitMap.size();
0464 }
0465
0466 void CaloSimHitAnalysis::analyzePassiveHits(std::vector<PassiveHit>& hits) {
0467 const std::string active = "Active";
0468 const std::string sensor = "Sensor";
0469 std::map<std::pair<std::string, uint32_t>, int> hitx;
0470 std::map<int, int> tracks;
0471 unsigned int passive1(0), passive2(0);
0472 for (auto& hit : hits) {
0473 std::string name = hit.vname();
0474 std::pair<std::string, uint32_t> volume = std::make_pair(name, (hit.id() % 1000000));
0475 auto itr = hitx.find(volume);
0476 if (itr == hitx.end())
0477 hitx[volume] = 1;
0478 else
0479 ++(itr->second);
0480 auto ktr = tracks.find(hit.trackId());
0481 if (ktr == tracks.end())
0482 tracks[hit.trackId()] = 1;
0483 else
0484 ++(ktr->second);
0485 h_edepp_->Fill(hit.energy());
0486 h_timep_->Fill(hit.time());
0487 h_stepp_->Fill(hit.stepLength());
0488 if ((name.find(active) != std::string::npos) || (name.find(sensor) != std::string::npos)) {
0489 unsigned idet = detNames_.size();
0490 for (unsigned int k = 0; k < detNames_.size(); ++k) {
0491 if (name.find(detNames_[k]) != std::string::npos) {
0492 idet = k;
0493 break;
0494 }
0495 }
0496 if (idet < detNames_.size()) {
0497 h_edepTk_[idet]->Fill(hit.energy());
0498 h_timeTk_[idet]->Fill(hit.time());
0499 }
0500 }
0501
0502 if ((allSteps_ / 100) % 10 > 0) {
0503 uint32_t id = hit.id();
0504 if (DetId(id).det() == DetId::Hcal) {
0505 HcalDetId hid = HcalDetId(id);
0506 int indx = (100 * hid.ietaAbs() + hid.depth());
0507 auto itr = etaDepth_.find(indx);
0508 #ifdef EDM_ML_DEBUG
0509 edm::LogVerbatim("HitStudy") << "CaloSimHitAnalysis::ID: " << hid << " Index " << indx << " Iterator "
0510 << (itr != etaDepth_.end());
0511 #endif
0512 ++passive1;
0513 if (itr != etaDepth_.end()) {
0514 uint32_t ipos = itr->second;
0515 double rr = std::sqrt(hit.x() * hit.x() + hit.y() * hit.y());
0516 if (ipos < h_rzH_.size()) {
0517 h_rzH_[ipos]->Fill(hit.z(), rr);
0518 ++passive2;
0519 }
0520 }
0521 }
0522 }
0523 }
0524 h_hitp_->Fill(hitx.size());
0525 h_trackp_->Fill(tracks.size());
0526 edm::LogVerbatim("HitStudy") << "CaloSimHitAnalysis::analyzPassiveHits: Total " << hits.size() << " Cells "
0527 << hitx.size() << " Tracks " << tracks.size() << " Passive " << passive1 << ":"
0528 << passive2;
0529 }
0530
0531
0532 DEFINE_FWK_MODULE(CaloSimHitAnalysis);