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

[13_1_X] Update utilities for SimBeamSpotObjects handling #41940

Merged
merged 9 commits into from
Jun 13, 2023
364 changes: 345 additions & 19 deletions CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "CondCore/Utilities/interface/PayloadInspectorModule.h"
#include "CondCore/Utilities/interface/PayloadInspector.h"
#include "CondCore/CondDB/interface/Time.h"
#include "CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h"
#include "CondCore/CondDB/interface/Time.h"
#include "CondCore/Utilities/interface/PayloadInspector.h"
#include "CondCore/Utilities/interface/PayloadInspectorModule.h"
#include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h"

#include <TStyle.h>

namespace {

using namespace BeamSpotPI;
using namespace beamSpotPI;

/************************************************
history plots
Expand Down
9 changes: 4 additions & 5 deletions CondCore/BeamSpotPlugins/plugins/BeamSpot_PayloadInspector.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include "CondCore/Utilities/interface/PayloadInspectorModule.h"
#include "CondCore/Utilities/interface/PayloadInspector.h"
#include "CondCore/CondDB/interface/Time.h"

#include "CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h"
#include "CondCore/CondDB/interface/Time.h"
#include "CondCore/Utilities/interface/PayloadInspector.h"
#include "CondCore/Utilities/interface/PayloadInspectorModule.h"
#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"

namespace {

using namespace BeamSpotPI;
using namespace beamSpotPI;

class BeamSpot_hx : public cond::payloadInspector::HistoryPlot<BeamSpotObjects, std::pair<double, double> > {
public:
Expand Down
6 changes: 6 additions & 0 deletions CondCore/BeamSpotPlugins/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
<use name="CondCore/CondDB"/>
<use name="boost_python"/>
</library>

<library file="SimBeamSpot_PayloadInspector.cc" name="SimBeamSpot_PayloadInspector">
<use name="CondCore/Utilities"/>
<use name="CondCore/CondDB"/>
<use name="boost_python"/>
</library>
32 changes: 32 additions & 0 deletions CondCore/BeamSpotPlugins/plugins/SimBeamSpot_PayloadInspector.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h"
#include "CondCore/CondDB/interface/Time.h"
#include "CondCore/Utilities/interface/PayloadInspector.h"
#include "CondCore/Utilities/interface/PayloadInspectorModule.h"
#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h"

namespace {

using namespace simBeamSpotPI;

/************************************************
Display of Sim Beam Spot parameters
*************************************************/

typedef DisplayParameters<SimBeamSpotObjects> SimBeamSpotParameters;

/************************************************
Display of Sim Beam Spot parameters Differences
*************************************************/

typedef DisplayParametersDiff<SimBeamSpotObjects, cond::payloadInspector::MULTI_IOV, 1>
SimBeamSpotParametersDiffSingleTag;
typedef DisplayParametersDiff<SimBeamSpotObjects, cond::payloadInspector::SINGLE_IOV, 2>
SimBeamSpotParametersDiffTwoTags;

} // namespace

PAYLOAD_INSPECTOR_MODULE(SimBeamSpot) {
PAYLOAD_INSPECTOR_CLASS(SimBeamSpotParameters);
PAYLOAD_INSPECTOR_CLASS(SimBeamSpotParametersDiffSingleTag);
PAYLOAD_INSPECTOR_CLASS(SimBeamSpotParametersDiffTwoTags);
}
1 change: 1 addition & 0 deletions CondCore/Utilities/plugins/Module_2XML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ PAYLOAD_2XML_MODULE(pluginUtilities_payload2xml) {
PAYLOAD_2XML_CLASS(RPFlatParams);
PAYLOAD_2XML_CLASS(RecoIdealGeometry);
PAYLOAD_2XML_CLASS(RunInfo);
PAYLOAD_2XML_CLASS(SimBeamSpotObjects);
PAYLOAD_2XML_CLASS(SiPhase2OuterTrackerLorentzAngle);
PAYLOAD_2XML_CLASS(SiPixel2DTemplateDBObject);
PAYLOAD_2XML_CLASS(SiPixelCPEGenericErrorParm);
Expand Down
1 change: 1 addition & 0 deletions CondCore/Utilities/src/CondDBFetch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ namespace cond {
FETCH_PAYLOAD_CASE(RPFlatParams)
FETCH_PAYLOAD_CASE(RecoIdealGeometry)
FETCH_PAYLOAD_CASE(RunInfo)
FETCH_PAYLOAD_CASE(SimBeamSpotObjects)
FETCH_PAYLOAD_CASE(SiPhase2OuterTrackerLorentzAngle)
FETCH_PAYLOAD_CASE(SiPixelCalibConfiguration)
FETCH_PAYLOAD_CASE(SiPixelCPEGenericErrorParm)
Expand Down
1 change: 1 addition & 0 deletions CondCore/Utilities/src/CondDBImport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ namespace cond {
IMPORT_PAYLOAD_CASE(RPFlatParams)
IMPORT_PAYLOAD_CASE(RecoIdealGeometry)
IMPORT_PAYLOAD_CASE(RunInfo)
IMPORT_PAYLOAD_CASE(SimBeamSpotObjects)
IMPORT_PAYLOAD_CASE(SiPhase2OuterTrackerLorentzAngle)
IMPORT_PAYLOAD_CASE(SiPixelCalibConfiguration)
IMPORT_PAYLOAD_CASE(SiPixelCPEGenericErrorParm)
Expand Down
1 change: 1 addition & 0 deletions CondCore/Utilities/src/CondFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "CondFormats/Alignment/interface/Alignments.h"
#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
#include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h"
#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h"
#include "CondFormats/CastorObjects/interface/CastorElectronicsMap.h"
#include "CondFormats/CastorObjects/interface/CastorSaturationCorrs.h"
#include "CondFormats/HIObjects/interface/CentralityTable.h"
Expand Down
53 changes: 50 additions & 3 deletions CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,64 @@

class SimBeamSpotObjects {
public:
SimBeamSpotObjects(){};
/// default constructor
SimBeamSpotObjects() {
fX0 = 0.0;
fY0 = 0.0;
fZ0 = 0.0;
fSigmaZ = 0.0;
fbetastar = 0.0;
femittance = 0.0;
fPhi = 0.0;
fAlpha = 0.0;
fTimeOffset = 0.0;
};

virtual ~SimBeamSpotObjects(){};

/// set X, Y, Z positions
void setX(double val) { fX0 = val; }
void setY(double val) { fY0 = val; }
void setZ(double val) { fZ0 = val; }
/// set sigmaZ
void setSigmaZ(double val) { fSigmaZ = val; }
/// set BetaStar and Emittance
void setBetaStar(double val) { fbetastar = val; }
void setEmittance(double val) { femittance = val; }
/// set Phi, Alpha and TimeOffset
void setPhi(double val) { fPhi = val; }
void setAlpha(double val) { fAlpha = val; }
void setTimeOffset(double val) { fTimeOffset = val; }

/// get X position
double x() const { return fX0; }
/// get Y position
double y() const { return fY0; }
/// get Z position
double z() const { return fZ0; }
/// get sigmaZ
double sigmaZ() const { return fSigmaZ; }
/// get BetaStar
double betaStar() const { return fbetastar; }
/// get Emittance
double emittance() const { return femittance; }
/// get Phi
double phi() const { return fPhi; }
/// get Alpha
double alpha() const { return fAlpha; }
/// get TimeOffset
double timeOffset() const { return fTimeOffset; }

/// print sim beam spot parameters
void print(std::stringstream& ss) const;

private:
double fX0, fY0, fZ0;
double fSigmaZ;
double fbetastar, femittance;
double fPhi, fAlpha;
double fTimeOffset;

void print(std::stringstream& ss) const;

COND_SERIALIZABLE;
};

Expand Down
13 changes: 12 additions & 1 deletion CondFormats/BeamSpotObjects/src/SimBeamSpotObjects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
#include <iostream>

void SimBeamSpotObjects::print(std::stringstream& ss) const {
ss << "-----------------------------------------------------\n" << fX0 << std::endl;
ss << "-----------------------------------------------------\n"
<< " Sim Beam Spot Data\n\n"
<< " X0 = " << x() << " [cm]\n"
<< " Y0 = " << y() << " [cm]\n"
<< " Z0 = " << z() << " [cm]\n"
<< " Sigma Z0 = " << sigmaZ() << " [cm]\n"
<< " Beta star = " << betaStar() << " [cm]\n"
<< " Emittance X = " << emittance() << " [cm]\n"
<< " Phi = " << phi() << " [radians]\n"
<< " Alpha = " << alpha() << " [radians]\n"
<< " TimeOffset = " << timeOffset() << " [ns]\n"
<< "-----------------------------------------------------\n\n";
}

std::ostream& operator<<(std::ostream& os, SimBeamSpotObjects beam) {
Expand Down
1 change: 1 addition & 0 deletions CondTools/BeamSpot/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<use name="CondCore/PopCon"/>
<use name="CondFormats/Common"/>
<use name="CondFormats/BeamSpotObjects"/>
<use name="clhep"/>
<export>
<lib name="1"/>
</export>
180 changes: 180 additions & 0 deletions CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
// -*- C++ -*-
//
// Package: CondTools/BeamProfile2DBReader
// Class: BeamProfile2DBReader
//
/**\class BeamProfile2DBReader BeamProfile2DBReader.cc CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc

Description: simple emd::one::EDAnalyzer to retrieve and ntuplize SimBeamSpot data from the conditions database

Implementation:
[Notes on implementation]
*/
//
// Original Author: Francesco Brivio
// Created: 11 June 2023
//

// system include files
#include <fstream>
#include <memory>
#include <sstream>

// user include files
#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h"
#include "CondFormats/DataRecord/interface/SimBeamSpotObjectsRcd.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

// For ROOT
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include <TTree.h>

//
// class declaration
//

class BeamProfile2DBReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit BeamProfile2DBReader(const edm::ParameterSet&);
~BeamProfile2DBReader() override;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
void beginJob() override;
void analyze(const edm::Event&, const edm::EventSetup&) override;

struct TheBSfromDB {
int run;
int ls;
double fX0, fY0, fZ0;
double fSigmaZ;
double fbetastar, femittance;
double fPhi, fAlpha;
double fTimeOffset;
void init();
} theBSfromDB_;

const edm::ESGetToken<SimBeamSpotObjects, SimBeamSpotObjectsRcd> beamSpotToken_;
edm::Service<TFileService> tFileService;
TTree* bstree_;

// ----------member data ---------------------------
edm::ESWatcher<SimBeamSpotObjectsRcd> watcher_;
std::unique_ptr<std::ofstream> output_;
};

//
// constructors and destructor
//
BeamProfile2DBReader::BeamProfile2DBReader(const edm::ParameterSet& iConfig)
: beamSpotToken_(esConsumes()), bstree_(nullptr) {
//now do what ever initialization is needed
usesResource("TFileService");
std::string fileName(iConfig.getUntrackedParameter<std::string>("rawFileName"));
if (!fileName.empty()) {
output_ = std::make_unique<std::ofstream>(fileName.c_str());
if (!output_->good()) {
edm::LogError("IOproblem") << "Could not open output file " << fileName << ".";
output_.reset();
}
}
}

BeamProfile2DBReader::~BeamProfile2DBReader() = default;

//
// member functions
//

void BeamProfile2DBReader::TheBSfromDB::init() {
float dummy_double = 0.0;
int dummy_int = 0;

run = dummy_int;
ls = dummy_int;
fX0 = dummy_double;
fY0 = dummy_double;
fZ0 = dummy_double;
fSigmaZ = dummy_double;
fbetastar = dummy_double;
femittance = dummy_double;
fPhi = dummy_double;
fAlpha = dummy_double;
fTimeOffset = dummy_double;
}

// ------------ method called for each event ------------
void BeamProfile2DBReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;
std::ostringstream output;

// initialize the ntuple
theBSfromDB_.init();

if (watcher_.check(iSetup)) { // check for new IOV for this run / LS

output << " for runs: " << iEvent.id().run() << " - " << iEvent.id().luminosityBlock() << std::endl;

// Get SimBeamSpot from EventSetup:
const SimBeamSpotObjects* mybeamspot = &iSetup.getData(beamSpotToken_);

theBSfromDB_.run = iEvent.id().run();
theBSfromDB_.ls = iEvent.id().luminosityBlock();
theBSfromDB_.fX0 = mybeamspot->x();
theBSfromDB_.fY0 = mybeamspot->y();
theBSfromDB_.fZ0 = mybeamspot->z();
theBSfromDB_.fSigmaZ = mybeamspot->sigmaZ();
theBSfromDB_.fbetastar = mybeamspot->betaStar();
theBSfromDB_.femittance = mybeamspot->emittance();
theBSfromDB_.fPhi = mybeamspot->phi();
theBSfromDB_.fAlpha = mybeamspot->alpha();
theBSfromDB_.fTimeOffset = mybeamspot->timeOffset();
bstree_->Fill();
output << *mybeamspot << std::endl;
}

// Final output - either message logger or output file:
if (output_.get())
*output_ << output.str();
else
edm::LogInfo("") << output.str();
}

// ------------ method called once each job just before starting event loop ------------
void BeamProfile2DBReader::beginJob() {
bstree_ = tFileService->make<TTree>("BSNtuple", "SimBeamSpot analyzer ntuple");

//Tree Branches
bstree_->Branch("run", &theBSfromDB_.run, "run/I");
bstree_->Branch("ls", &theBSfromDB_.ls, "ls/I");
bstree_->Branch("BSx0", &theBSfromDB_.fX0, "BSx0/F");
bstree_->Branch("BSy0", &theBSfromDB_.fY0, "BSy0/F");
bstree_->Branch("BSz0", &theBSfromDB_.fZ0, "BSz0/F");
bstree_->Branch("Beamsigmaz", &theBSfromDB_.fSigmaZ, "Beamsigmaz/F");
bstree_->Branch("BetaStar", &theBSfromDB_.fbetastar, "BetaStar/F");
bstree_->Branch("Emittance", &theBSfromDB_.femittance, "Emittance/F");
bstree_->Branch("Phi", &theBSfromDB_.fPhi, "Phi/F");
bstree_->Branch("Alpha", &theBSfromDB_.fAlpha, "Alpha/F");
bstree_->Branch("TimeOffset", &theBSfromDB_.fTimeOffset, "TimeOffset/F");
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void BeamProfile2DBReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
//The following says we do not know what parameters are allowed so do no validation
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
desc.setUnknown();
descriptions.addDefault(desc);
}

//define this as a plug-in
DEFINE_FWK_MODULE(BeamProfile2DBReader);
Loading