Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run3-hcx198 Put protections in validation codes #26759

Merged
merged 1 commit into from May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Validation/HcalHits/src/HcalSimHitStudy.cc
Expand Up @@ -48,7 +48,7 @@ void HcalSimHitStudy::bookHistograms(DQMStore::IBooker &ib, edm::Run const &run,
iphi_bins = (int)(iphi_max - iphi_min);

int iEtaHBMax = hcons->getEtaRange(0).second;
int iEtaHEMax = hcons->getEtaRange(1).second;
int iEtaHEMax = std::max(hcons->getEtaRange(1).second,1);
int iEtaHFMax = hcons->getEtaRange(2).second;
int iEtaHOMax = hcons->getEtaRange(3).second;

Expand Down
4 changes: 2 additions & 2 deletions Validation/HcalHits/src/HcalSimHitsValidation.cc
Expand Up @@ -58,7 +58,7 @@ void HcalSimHitsValidation::bookHistograms(DQMStore::IBooker &ib, edm::Run const
// int iphi_bins = (int) (iphi_max - iphi_min);

int iEtaHBMax = hcons->getEtaRange(0).second;
int iEtaHEMax = hcons->getEtaRange(1).second;
int iEtaHEMax = std::max(hcons->getEtaRange(1).second,1);
int iEtaHFMax = hcons->getEtaRange(2).second;
int iEtaHOMax = hcons->getEtaRange(3).second;

Expand Down Expand Up @@ -392,7 +392,7 @@ void HcalSimHitsValidation::analyze(edm::Event const &ev, edm::EventSetup const
occupancy_vs_ieta_HB[depth]->Fill(double(ieta));
}
// HE
if (sub == 2) {
if (sub == 2 && maxDepthHE_ > 0) {
meSimHitsEnergyHE[0]->Fill(en);
meSimHitsEnergyHE[depth]->Fill(en);

Expand Down
61 changes: 33 additions & 28 deletions Validation/HcalHits/src/SimG4HcalValidation.cc
Expand Up @@ -11,6 +11,7 @@

// to retreive hits
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
#include "DataFormats/Math/interface/GeantUnits.h"
#include "DataFormats/Math/interface/Point3D.h"
#include "SimG4CMS/Calo/interface/CaloG4Hit.h"
#include "SimG4CMS/Calo/interface/CaloG4HitCollection.h"
Expand All @@ -24,16 +25,13 @@
#include "Geometry/HcalCommonData/interface/HcalDDDSimConstants.h"
#include "Geometry/Records/interface/HcalSimNumberingRecord.h"

#include "CLHEP/Units/GlobalPhysicalConstants.h"
#include "CLHEP/Units/GlobalSystemOfUnits.h"
#include "G4HCofThisEvent.hh"
#include "G4SDManager.hh"
#include "G4Step.hh"
#include "G4Track.hh"
#include "G4VProcess.hh"
#include <cmath>
#include <iomanip>
#include <iostream>

using namespace geant_units::operators;

SimG4HcalValidation::SimG4HcalValidation(const edm::ParameterSet &p)
: jetf(nullptr), numberingFromDDD(nullptr), org(nullptr) {
Expand All @@ -60,29 +58,33 @@ SimG4HcalValidation::SimG4HcalValidation(const edm::ParameterSet &p)
if (infolevel > 1)
produces<PHcalValidInfoJets>(labelJets);

edm::LogInfo("ValidHcal") << "HcalTestAnalysis:: Initialised as observer of "
<< "begin/end events and of G4step with Parameter "
<< "values: \n\tInfoLevel = " << infolevel << "\n\thcalOnly = " << hcalOnly
<< "\n\tapplySampling = " << applySampling << "\n\tconeSize = " << coneSize
<< "\n\tehitThreshold = " << ehitThreshold << "\n\thhitThreshold = " << hhitThreshold
<< "\n\tttimeLowlim = " << timeLowlim << "\n\tttimeUplim = " << timeUplim
<< "\n\teta0 = " << eta0 << "\n\tphi0 = " << phi0
<< "\nLabels (Layer): " << labelLayer << " (NxN): " << labelNxN << " (Jets): " << labelJets;
edm::LogVerbatim("ValidHcal")
<< "HcalTestAnalysis:: Initialised as observer of begin/end events and "
<< "of G4step with Parameter values: \n\tInfoLevel = " << infolevel
<< "\n\thcalOnly = " << hcalOnly << "\n\tapplySampling = "
<< applySampling << "\n\tconeSize = " << coneSize
<< "\n\tehitThreshold = " << ehitThreshold << "\n\thhitThreshold = "
<< hhitThreshold << "\n\tttimeLowlim = " << timeLowlim
<< "\n\tttimeUplim = " << timeUplim << "\n\teta0 = " << eta0
<< "\n\tphi0 = " << phi0 << "\nLabels (Layer): " << labelLayer
<< " (NxN): " << labelNxN << " (Jets): " << labelJets;

init();
}

SimG4HcalValidation::~SimG4HcalValidation() {
edm::LogInfo("ValidHcal") << "\n --------> Total number of selected entries"
<< " : " << count << "\nPointers:: JettFinder " << jetf << ", Numbering Scheme " << org
<< " and FromDDD " << numberingFromDDD;
edm::LogVerbatim("ValidHcal")
<< "\n --------> Total number of selected entries"
<< " : " << count << "\nPointers:: JettFinder " << jetf
<< ", Numbering Scheme " << org
<< " and FromDDD " << numberingFromDDD;
if (jetf) {
edm::LogInfo("ValidHcal") << "Delete Jetfinder";
edm::LogVerbatim("ValidHcal") << "Delete Jetfinder";
delete jetf;
jetf = nullptr;
}
if (numberingFromDDD) {
edm::LogInfo("ValidHcal") << "Delete HcalNumberingFromDDD";
edm::LogVerbatim("ValidHcal") << "Delete HcalNumberingFromDDD";
delete numberingFromDDD;
numberingFromDDD = nullptr;
}
Expand Down Expand Up @@ -144,8 +146,8 @@ void SimG4HcalValidation::update(const BeginOfJob *job) {
edm::ESHandle<HcalDDDSimConstants> hdc;
(*job)()->get<HcalSimNumberingRecord>().get(hdc);
const HcalDDDSimConstants *hcons = hdc.product();
edm::LogInfo("ValidHcal") << "HcalTestAnalysis:: Initialise "
<< "HcalNumberingFromDDD";
edm::LogVerbatim("ValidHcal") << "HcalTestAnalysis:: Initialise "
<< "HcalNumberingFromDDD";
numberingFromDDD = new HcalNumberingFromDDD(hcons);

// Numbering scheme
Expand All @@ -155,7 +157,7 @@ void SimG4HcalValidation::update(const BeginOfJob *job) {
void SimG4HcalValidation::update(const BeginOfRun *run) {
int irun = (*run)()->GetRunID();

edm::LogInfo("ValidHcal") << " =====> Begin of Run = " << irun;
edm::LogVerbatim("ValidHcal") << " =====> Begin of Run = " << irun;

std::string sdname = names[0];
G4SDManager *sd = G4SDManager::GetSDMpointerIfExist();
Expand All @@ -167,12 +169,13 @@ void SimG4HcalValidation::update(const BeginOfRun *run) {
<< "Setup";
} else {
HCalSD *theCaloSD = dynamic_cast<HCalSD *>(aSD);
edm::LogInfo("ValidHcal") << "SimG4HcalValidation::beginOfRun: Finds SD"
<< "with name " << theCaloSD->GetName() << " in this Setup";
edm::LogVerbatim("ValidHcal")
<< "SimG4HcalValidation::beginOfRun: Finds SD with name "
<< theCaloSD->GetName() << " in this Setup";
if (org) {
theCaloSD->setNumberingScheme(org);
edm::LogInfo("ValidHcal") << "SimG4HcalValidation::beginOfRun: set a "
<< "new numbering scheme";
edm::LogVerbatim("ValidHcal")
<< "SimG4HcalValidation::beginOfRun: set a new numbering scheme";
}
}
} else {
Expand Down Expand Up @@ -309,9 +312,11 @@ void SimG4HcalValidation::fill(const EndOfEvent *evt) {
else if (layer == 0)
vhitec += e;
else
edm::LogInfo("ValidHcal") << "SimG4HcalValidation::HitPMT " << subdet << " " << (2 * zside - 1) * etaIndex
<< " " << phiIndex << " " << layer + 1 << " R " << pos.rho() << " Phi " << phi / deg
<< " Edep " << e << " Time " << time;
edm::LogVerbatim("ValidHcal")
<< "SimG4HcalValidation::HitPMT " << subdet << " "
<< (2*zside-1)*etaIndex << " " << phiIndex << " " << layer + 1
<< " R " << pos.rho() << " Phi " << convertRadToDeg(phi)
<< " Edep " << e << " Time " << time;
} else if (subdet == static_cast<int>(HcalEndcap)) {
if (etaIndex <= 20) {
det = "HES";
Expand Down
57 changes: 33 additions & 24 deletions Validation/HcalHits/src/SimHitsValidationHcal.cc
Expand Up @@ -3,7 +3,7 @@
#include "Geometry/Records/interface/HcalRecNumberingRecord.h"
#include "Validation/HcalHits/interface/SimHitsValidationHcal.h"

#define DebugLog
//#define DebugLog

SimHitsValidationHcal::SimHitsValidationHcal(const edm::ParameterSet &ps) {
g4Label_ = ps.getParameter<std::string>("ModuleLabel");
Expand All @@ -13,8 +13,9 @@ SimHitsValidationHcal::SimHitsValidationHcal(const edm::ParameterSet &ps) {

tok_hits_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hcalHits_));

edm::LogInfo("HitsValidationHcal") << "Module Label: " << g4Label_ << " Hits: " << hcalHits_ << " TestNumbering "
<< testNumber_;
edm::LogVerbatim("HitsValidationHcal")
<< "Module Label: " << g4Label_ << " Hits: " << hcalHits_
<< " TestNumbering " << testNumber_;
}

SimHitsValidationHcal::~SimHitsValidationHcal() {}
Expand Down Expand Up @@ -43,7 +44,7 @@ void SimHitsValidationHcal::bookHistograms(DQMStore::IBooker &ib, edm::Run const
int iphi_bins = (int)(iphi_max - iphi_min);

int iEtaHBMax = hcons->getEtaRange(0).second;
int iEtaHEMax = hcons->getEtaRange(1).second;
int iEtaHEMax = std::max(hcons->getEtaRange(1).second,1);
int iEtaHFMax = hcons->getEtaRange(2).second;
int iEtaHOMax = hcons->getEtaRange(3).second;

Expand Down Expand Up @@ -77,12 +78,13 @@ void SimHitsValidationHcal::bookHistograms(DQMStore::IBooker &ib, edm::Run const
// int ieta_bins_HO = (int) (ieta_max_HO - ieta_min_HO);

#ifdef DebugLog
edm::LogInfo("HitsValidationHcal") << " Maximum Depths HB:" << maxDepthHB_ << " HE:" << maxDepthHE_
<< " HO:" << maxDepthHO_ << " HF:" << maxDepthHF_;
edm::LogVerbatim("HitsValidationHcal")
<< " Maximum Depths HB:" << maxDepthHB_ << " HE:" << maxDepthHE_
<< " HO:" << maxDepthHO_ << " HF:" << maxDepthHF_;
#endif
std::vector<std::pair<std::string, std::string>> divisions = getHistogramTypes();

edm::LogInfo("HitsValidationHcal") << "Booking the Histograms";
edm::LogVerbatim("HitsValidationHcal") << "Booking the Histograms";
ib.setCurrentFolder("HcalHitsV/SimHitsValidationHcal");

// Histograms for Hits
Expand Down Expand Up @@ -149,7 +151,8 @@ void SimHitsValidationHcal::bookHistograms(DQMStore::IBooker &ib, edm::Run const

void SimHitsValidationHcal::analyze(const edm::Event &e, const edm::EventSetup &) {
#ifdef DebugLog
edm::LogInfo("HitsValidationHcal") << "Run = " << e.id().run() << " Event = " << e.id().event();
edm::LogVerbatim("HitsValidationHcal")
<< "Run = " << e.id().run() << " Event = " << e.id().event();
#endif
std::vector<PCaloHit> caloHits;
edm::Handle<edm::PCaloHitContainer> hitsHcal;
Expand All @@ -159,25 +162,27 @@ void SimHitsValidationHcal::analyze(const edm::Event &e, const edm::EventSetup &
if (hitsHcal.isValid())
getHits = true;
#ifdef DebugLog
edm::LogInfo("HitsValidationHcal") << "HitsValidationHcal.: Input flags Hits " << getHits;
edm::LogVerbatim("HitsValidationHcal")
<< "HitsValidationHcal.: Input flags Hits " << getHits;
#endif
if (getHits) {
caloHits.insert(caloHits.end(), hitsHcal->begin(), hitsHcal->end());
#ifdef DebugLog
edm::LogInfo("HitsValidationHcal") << "testNumber_:" << testNumber_;
edm::LogVerbatim("HitsValidationHcal") << "testNumber_:" << testNumber_;
#endif
if (testNumber_) {
for (unsigned int i = 0; i < caloHits.size(); ++i) {
unsigned int id_ = caloHits[i].id();
HcalDetId hid = HcalHitRelabeller::relabel(id_, hcons);
caloHits[i].setID(hid.rawId());
#ifdef DebugLog
edm::LogInfo("HitsValidationHcal") << "Hit[" << i << "] " << hid;
edm::LogVerbatim("HitsValidationHcal") << "Hit[" << i << "] " << hid;
#endif
}
}
#ifdef DebugLog
edm::LogInfo("HitsValidationHcal") << "HitsValidationHcal: Hit buffer " << caloHits.size();
edm::LogVerbatim("HitsValidationHcal")
<< "HitsValidationHcal: Hit buffer " << caloHits.size();
#endif
analyzeHits(caloHits);
}
Expand Down Expand Up @@ -240,10 +245,11 @@ void SimHitsValidationHcal::analyzeHits(std::vector<PCaloHit> &hits) {
map_try[id0] = ensum;

#ifdef DebugLog
edm::LogInfo("HitsValidationHcal") << "Hit[" << i << "] ID " << std::dec << " " << id << std::dec << " Det "
<< id.det() << " Sub " << subdet << " depth " << depth << " depthX " << dep
<< " Eta " << eta << " Phi " << id.iphi() << " E " << energy << " time " << time
<< " type " << types.first << " " << types.second;
edm::LogVerbatim("HitsValidationHcal")
<< "Hit[" << i << "] ID " << std::dec << " " << id << std::dec << " Det "
<< id.det() << " Sub " << subdet << " depth " << depth << " depthX " << dep
<< " Eta " << eta << " Phi " << id.iphi() << " E " << energy << " time " << time
<< " type " << types.first << " " << types.second;
#endif

double etax = eta - 0.5;
Expand Down Expand Up @@ -296,11 +302,12 @@ void SimHitsValidationHcal::analyzeHits(std::vector<PCaloHit> &hits) {
}

#ifdef DebugLog
edm::LogInfo("HitsValidationHcal") << " energy of tower =" << (*itr).first.first
<< " in time 25ns is == " << (*itr).second.e25
<< " in time 25-50ns == " << (*itr).second.e50
<< " in time 50-100ns == " << (*itr).second.e100
<< " in time 100-250 ns == " << (*itr).second.e250;
edm::LogVerbatim("HitsValidationHcal")
<< " energy of tower =" << (*itr).first.first
<< " in time 25ns is == " << (*itr).second.e25
<< " in time 25-50ns == " << (*itr).second.e50
<< " in time 50-100ns == " << (*itr).second.e100
<< " in time 100-250 ns == " << (*itr).second.e250;
#endif
}
}
Expand Down Expand Up @@ -346,9 +353,11 @@ SimHitsValidationHcal::etaRange SimHitsValidationHcal::getLimits(idType type) {
high = 41;
}
#ifdef DebugLog
edm::LogInfo("HitsValidationHcal") << "Subdetector:" << type.subdet << " z:" << type.z
<< " range.first:" << range.first << " and second:" << range.second;
edm::LogInfo("HitsValidationHcal") << "bins: " << bins << " low:" << low << " high:" << high;
edm::LogVerbatim("HitsValidationHcal")
<< "Subdetector:" << type.subdet << " z:" << type.z
<< " range.first:" << range.first << " and second:" << range.second;
edm::LogVerbatim("HitsValidationHcal")
<< "bins: " << bins << " low:" << low << " high:" << high;
#endif
return SimHitsValidationHcal::etaRange(bins, low, high);
}
Expand Down
1 change: 0 additions & 1 deletion Validation/HcalHits/src/ZdcSimHitStudy.cc
Expand Up @@ -28,7 +28,6 @@
#include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
#include "Validation/HcalHits/interface/ZdcSimHitStudy.h"

#include "CLHEP/Units/GlobalSystemOfUnits.h"
#include "FWCore/Utilities/interface/Exception.h"

ZdcSimHitStudy::ZdcSimHitStudy(const edm::ParameterSet &ps) {
Expand Down