Skip to content

Commit 1265850

Browse files
committed
simplify fillIPMonitor and throw in case of bad axes ranges
1 parent 2f8cebb commit 1265850

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

Alignment/OfflineValidation/plugins/GeneralPurposeVertexAnalyzer.cc

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ class GeneralPurposeVertexAnalyzer : public edm::one::EDAnalyzer<edm::one::Share
125125

126126
void bookIPMonitor(const edm::ParameterSet &, const edm::Service<TFileService> fs);
127127
void fillIPMonitor(const edm::RefToBase<reco::Track> &tk, const math::XYZPoint &pv);
128-
void print();
129128
};
130129

131130
const edm::ParameterSet conf_;
@@ -190,23 +189,35 @@ class GeneralPurposeVertexAnalyzer : public edm::one::EDAnalyzer<edm::one::Share
190189

191190
void GeneralPurposeVertexAnalyzer::IPMonitoring::bookIPMonitor(const edm::ParameterSet &config,
192191
const edm::Service<TFileService> fs) {
192+
// Lambda for range validation
193+
auto checkRange = [](const std::string &name, double min, double max) {
194+
if (min >= max) {
195+
throw cms::Exception("IPMonitoring")
196+
<< "Invalid range for " << name << ": min (" << min << ") >= max (" << max << ")";
197+
}
198+
};
199+
193200
int VarBin = config.getParameter<int>(fmt::format("D{}Bin", varname_));
194201
double VarMin = config.getParameter<double>(fmt::format("D{}Min", varname_));
195202
double VarMax = config.getParameter<double>(fmt::format("D{}Max", varname_));
203+
checkRange(fmt::format("D{}", varname_), VarMin, VarMax);
196204

197205
int PhiBin = config.getParameter<int>("PhiBin");
198206
int PhiBin2D = config.getParameter<int>("PhiBin2D");
199207
double PhiMin = config.getParameter<double>("PhiMin");
200208
double PhiMax = config.getParameter<double>("PhiMax");
209+
checkRange("Phi", PhiMin, PhiMax);
201210

202211
int EtaBin = config.getParameter<int>("EtaBin");
203212
int EtaBin2D = config.getParameter<int>("EtaBin2D");
204213
double EtaMin = config.getParameter<double>("EtaMin");
205214
double EtaMax = config.getParameter<double>("EtaMax");
215+
checkRange("Eta", EtaMin, EtaMax);
206216

207217
int PtBin = config.getParameter<int>("PtBin");
208218
double PtMin = config.getParameter<double>("PtMin") * pTcut_;
209219
double PtMax = config.getParameter<double>("PtMax") * pTcut_;
220+
checkRange("Pt", PtMin, PtMax);
210221

211222
IP_ = fs->make<TH1D>(fmt::format("d{}_pt{}", varname_, pTcut_).c_str(),
212223
fmt::format("PV tracks (p_{{T}} > {} GeV) d_{{{}}} (#mum)", pTcut_, varname_).c_str(),
@@ -341,44 +352,34 @@ void GeneralPurposeVertexAnalyzer::IPMonitoring::bookIPMonitor(const edm::Parame
341352

342353
void GeneralPurposeVertexAnalyzer::IPMonitoring::fillIPMonitor(const edm::RefToBase<reco::Track> &tk,
343354
const math::XYZPoint &pv) {
344-
const float eta = tk->eta();
345-
const float phi = tk->phi();
346-
const float pt = tk->pt();
347-
348-
const float Dxy = tk->dxy(pv) * cmToUm;
349-
const float DxyErr = tk->dxyError() * cmToUm;
350-
351-
const float Dz = tk->dz(pv) * cmToUm;
352-
const float DzErr = tk->dzError() * cmToUm;
355+
float value = 999.f, error = 9999.f;
353356

354357
if (varname_ == "xy") {
355-
IP_->Fill(Dxy);
356-
IPVsPhi_->Fill(phi, Dxy);
357-
IPVsEta_->Fill(eta, Dxy);
358-
IPVsPt_->Fill(pt, Dxy);
359-
IPVsEtaVsPhi_->Fill(eta, phi, Dxy);
360-
361-
IPErr_->Fill(DxyErr);
362-
IPPull_->Fill(Dxy / DxyErr);
363-
IPErrVsPhi_->Fill(phi, DxyErr);
364-
IPErrVsEta_->Fill(eta, DxyErr);
365-
IPErrVsPt_->Fill(pt, DxyErr);
366-
IPErrVsEtaVsPhi_->Fill(eta, phi, DxyErr);
358+
value = tk->dxy(pv) * cmToUm;
359+
error = tk->dxyError() * cmToUm;
367360
} else if (varname_ == "z") {
368-
IP_->Fill(Dz);
369-
IPVsPhi_->Fill(phi, Dz);
370-
IPVsEta_->Fill(eta, Dz);
371-
IPVsPt_->Fill(pt, Dz);
372-
IPVsEtaVsPhi_->Fill(eta, phi, Dz);
373-
374-
IPErr_->Fill(DzErr);
375-
IPPull_->Fill(Dz / DzErr);
376-
IPErrVsPhi_->Fill(phi, DzErr);
377-
IPErrVsEta_->Fill(eta, DzErr);
378-
IPErrVsPt_->Fill(pt, DzErr);
379-
IPErrVsEtaVsPhi_->Fill(eta, phi, DzErr);
361+
value = tk->dz(pv) * cmToUm;
362+
error = tk->dzError() * cmToUm;
363+
} else {
364+
throw cms::Exception("IPMonitoring") << "Unknown varname: " << varname_ << ". Expected 'xy' or 'z\'.";
380365
}
381-
return;
366+
367+
const float eta = tk->eta();
368+
const float phi = tk->phi();
369+
const float pt = tk->pt();
370+
371+
IP_->Fill(value);
372+
IPVsPhi_->Fill(phi, value);
373+
IPVsEta_->Fill(eta, value);
374+
IPVsPt_->Fill(pt, value);
375+
IPVsEtaVsPhi_->Fill(eta, phi, value);
376+
377+
IPErr_->Fill(error);
378+
IPPull_->Fill(value / error);
379+
IPErrVsPhi_->Fill(phi, error);
380+
IPErrVsEta_->Fill(eta, error);
381+
IPErrVsPt_->Fill(pt, error);
382+
IPErrVsEtaVsPhi_->Fill(eta, phi, error);
382383
}
383384

384385
//

0 commit comments

Comments
 (0)