Skip to content

Commit

Permalink
update BeamSpotOnline payload inspector to include parameters added in
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed Sep 28, 2021
1 parent c1cb2f1 commit 6f551f5
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 29 deletions.
39 changes: 25 additions & 14 deletions CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h
Expand Up @@ -28,20 +28,31 @@ namespace BeamSpotPI {
}

enum parameters {
X,
Y,
Z,
sigmaX,
sigmaY,
sigmaZ,
dxdz,
dydz,
lastLumi,
lastRun,
lastFill,
nTracks,
nPVs,
creationTime,
X, // 1 regular BS methods
Y, // 2
Z, // 3
sigmaX, // 4
sigmaY, // 5
sigmaZ, // 6
dxdz, // 7
dydz, // 8
lastLumi, // 9 additional int's
lastRun, // 10
lastFill, // 11
nTracks, // 12
nPVs, // 13
nUsedEvents, // 14
maxPVs, // 15
meanPV, // 16 additional float's
meanErrorPV, // 17
rmsPV, // 18
rmsErrorPV, // 19
creationTime, // 20 additional cond::Time_t
startTimeStamp, // 21
endTimeStamp, // 22
startTime, // 23 additional std::string
endTime, // 24
lumiRange, // 25
END_OF_TYPES
};

Expand Down
126 changes: 111 additions & 15 deletions CondCore/BeamSpotPlugins/plugins/BeamSpotOnline_PayloadInspector.cc
Expand Up @@ -62,11 +62,12 @@ namespace {
public:
std::shared_ptr<TH2F> fillTheExtraHistogram() const override {
gStyle->SetHistMinimumZero();
auto h2_ExtraBSParameters = std::make_shared<TH2F>("ExtraParameters", "", 1, 0.0, 1.0, 6, 0, 6.);
auto h2_ExtraBSParameters = std::make_shared<TH2F>("ExtraParameters", "", 1, 0.0, 1.0, 14, 0, 14.);
h2_ExtraBSParameters->SetStats(false);

std::function<int(parameters)> mycutFunctor = [this](parameters my_param) {
int ret(-999.);
//_____________________________________________________________________________
std::function<int(parameters)> myIntFunctor = [this](parameters my_param) {
int ret(-999);
switch (my_param) {
case lastLumi:
return this->m_payload->GetLastAnalyzedLumi();
Expand All @@ -78,28 +79,85 @@ namespace {
return this->m_payload->GetNumTracks();
case nPVs:
return this->m_payload->GetNumPVs();
case END_OF_TYPES:
case nUsedEvents:
return this->m_payload->GetUsedEvents();
case maxPVs:
return this->m_payload->GetMaxPVs();
default:
return ret;
}
};

//_____________________________________________________________________________
std::function<float(parameters)> myFloatFunctor = [this](parameters my_param) {
float ret(-999.);
switch (my_param) {
case meanPV:
return this->m_payload->GetMeanPV();
case meanErrorPV:
return this->m_payload->GetMeanErrorPV();
case rmsPV:
return this->m_payload->GetRmsPV();
case rmsErrorPV:
return this->m_payload->GetRmsErrorPV();
default:
return ret;
}
};

//_____________________________________________________________________________
std::function<std::string(parameters)> myStringFunctor = [this](parameters my_param) {
std::string ret("");
switch (my_param) {
case startTime:
return this->m_payload->GetStartTime();
case endTime:
return this->m_payload->GetEndTime();
case lumiRange:
return this->m_payload->GetLumiRange();
default:
return ret;
}
};

unsigned int yBin = 6;
for (int foo = parameters::lastLumi; foo != parameters::END_OF_TYPES; foo++) {
//_____________________________________________________________________________
std::function<cond::Time_t(parameters)> myTimeFunctor = [this](parameters my_param) {
cond::Time_t ret(1);
switch (my_param) {
case creationTime:
return this->m_payload->GetCreationTime();
case startTimeStamp:
return this->m_payload->GetStartTimeStamp();
case endTimeStamp:
return this->m_payload->GetEndTimeStamp();
default:
return ret;
}
};

unsigned int yBin = 14;
for (int foo = parameters::lastLumi; foo != parameters::startTime; foo++) {
parameters param = static_cast<parameters>(foo);
std::string theLabel = this->getStringFromTypeEnum(param);
h2_ExtraBSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());

edm::LogInfo("BeamSpotOnline_PayloadInspector")
<< theLabel.c_str() << " : " << mycutFunctor(param) << std::endl;

if (param == BeamSpotPI::creationTime) {
h2_ExtraBSParameters->SetBinContent(1, yBin, m_payload->GetCreationTime());
} else {
h2_ExtraBSParameters->SetBinContent(1, yBin, mycutFunctor(param));
if (foo <= parameters::maxPVs) {
const auto output = try_<int, std::out_of_range>(std::bind(myIntFunctor, param), print_error);
edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
h2_ExtraBSParameters->SetBinContent(1, yBin, output);
} else if (foo <= parameters::rmsErrorPV) {
const auto output = try_<float, std::out_of_range>(std::bind(myFloatFunctor, param), print_error);
edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
h2_ExtraBSParameters->SetBinContent(1, yBin, output);
} else if (foo <= parameters::endTimeStamp) {
const auto output = try_<cond::Time_t, std::out_of_range>(std::bind(myTimeFunctor, param), print_error);
edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
h2_ExtraBSParameters->SetBinContent(1, yBin, output);
//} else if( foo <=parameters::lumiRange){
// const auto output = try_<std::string,std::out_of_range>(std::bind(myStringFunctor, param), print_error);
//edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
//h2_ExtraBSParameters->SetBinContent(1, yBin, output);
}

yBin--;
}

Expand Down Expand Up @@ -141,12 +199,50 @@ namespace {
return "# tracks";
case nPVs:
return "# PVs";
case nUsedEvents:
return "# events";
case maxPVs:
return "max PVs";
case meanPV:
return "#LT # PV #GT";
case meanErrorPV:
return "#LT PV error #GT [cm]";
case rmsPV:
return "rms PV [cm]";
case rmsErrorPV:
return "rms PV error [cm]";
case creationTime:
return "time";
return "creation time";
case startTimeStamp:
return "start timestamp";
case endTimeStamp:
return "end timestamp";
case startTime:
return "startTime";
case endTime:
return "endTime";
case lumiRange:
return "lumiRange";
default:
return "should never be here";
}
}

//slightly better error handler
static void print_error(const std::exception& e) { edm::LogError("BeamSpotOnlineParameters") << e.what() << '\n'; }

// method to catch exceptions
template <typename T, class Except, class Func, class Response>
T try_(Func f, Response r) const {
try {
std::cout << "I have tried" << std::endl;
return f();
} catch (Except& e) {
std::cout << "I have caught!" << std::endl;
r(e);
return static_cast<T>(-999);
}
}
};

} // namespace
Expand Down

0 comments on commit 6f551f5

Please sign in to comment.