CMS 3D CMS Logo

BeamSpotOnlineLegacyRcdReader.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondTools/BeamSpot
4 // Class: BeamSpotOnlineLegacyRcdReader
5 //
13 //
14 // Original Author: Francesco Brivio
15 // Created: Tue, 11 Feb 2020 08:39:14 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <sstream>
22 #include <fstream>
23 
24 // user include files
27 
30 
36 
39 
40 // For ROOT
43 #include <TTree.h>
44 
45 //
46 // class declaration
47 //
48 
49 class BeamSpotOnlineLegacyRcdReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
50 public:
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  void beginJob() override;
58  void analyze(const edm::Event&, const edm::EventSetup&) override;
59  void endJob() override;
60 
61  struct theBSOfromDB {
62  int ls;
63  int run;
64  float BSx0_;
65  float BSy0_;
66  float BSz0_;
67  float Beamsigmaz_;
68  float Beamdxdz_;
69  float BeamWidthX_;
70  float BeamWidthY_;
74  void init();
75  } theBSOfromDB_;
76 
78  TTree* bstree_;
79 
80  // ----------member data ---------------------------
82  std::unique_ptr<std::ofstream> output_;
83 };
84 
85 //
86 // constructors and destructor
87 //
89  //now do what ever initialization is needed
90  usesResource("TFileService");
91  std::string fileName(iConfig.getUntrackedParameter<std::string>("rawFileName"));
92  if (!fileName.empty()) {
93  output_.reset(new std::ofstream(fileName.c_str()));
94  if (!output_->good()) {
95  edm::LogError("IOproblem") << "Could not open output file " << fileName << ".";
96  output_.reset();
97  }
98  }
99 }
100 
102  // do anything here that needs to be done at desctruction time
103  // (e.g. close files, deallocate resources etc.)
104 }
105 
106 //
107 // member functions
108 //
109 
111  float dummy_float = -999.0;
112  int dummy_int = -999;
113 
114  run = dummy_int;
115  ls = dummy_int;
116  BSx0_ = dummy_float;
117  BSy0_ = dummy_float;
118  BSz0_ = dummy_float;
119  Beamsigmaz_ = dummy_float;
120  Beamdxdz_ = dummy_float;
121  BeamWidthX_ = dummy_float;
122  BeamWidthY_ = dummy_float;
123  lastAnalyzedLumi_ = dummy_int;
124  lastAnalyzedRun_ = dummy_int;
125  lastAnalyzedFill_ = dummy_int;
126 }
127 
128 // ------------ method called for each event ------------
130  using namespace edm;
131  std::ostringstream output;
132 
133  // initialize the ntuple
135 
136  if (watcher_.check(iSetup)) { // check for new IOV for this run / LS
137 
138  output << " for runs: " << iEvent.id().run() << " - " << iEvent.id().luminosityBlock() << std::endl;
139 
140  // Get BeamSpot from EventSetup:
142  iSetup.get<BeamSpotOnlineLegacyObjectsRcd>().get(beamhandle);
143  const BeamSpotOnlineObjects* mybeamspot = beamhandle.product();
144 
145  theBSOfromDB_.run = iEvent.id().run();
146  theBSOfromDB_.ls = iEvent.id().luminosityBlock();
147  theBSOfromDB_.BSx0_ = mybeamspot->GetX();
148  theBSOfromDB_.BSy0_ = mybeamspot->GetY();
149  theBSOfromDB_.BSz0_ = mybeamspot->GetZ();
150  theBSOfromDB_.Beamsigmaz_ = mybeamspot->GetSigmaZ();
151  theBSOfromDB_.Beamdxdz_ = mybeamspot->Getdxdz();
152  theBSOfromDB_.BeamWidthX_ = mybeamspot->GetBeamWidthX();
153  theBSOfromDB_.BeamWidthY_ = mybeamspot->GetBeamWidthY();
157 
158  bstree_->Fill();
159 
160  output << *mybeamspot << std::endl;
161  }
162 
163  // Final output - either message logger or output file:
164  if (output_.get())
165  *output_ << output.str();
166  else
167  edm::LogInfo("") << output.str();
168 }
169 
170 // ------------ method called once each job just before starting event loop ------------
172  bstree_ = tFileService->make<TTree>("BSONtuple", "BeamSpotOnline analyzer ntuple");
173 
174  //Tree Branches
175  bstree_->Branch("run", &theBSOfromDB_.run, "run/I");
176  bstree_->Branch("ls", &theBSOfromDB_.ls, "ls/I");
177  bstree_->Branch("BSx0", &theBSOfromDB_.BSx0_, "BSx0/F");
178  bstree_->Branch("BSy0", &theBSOfromDB_.BSy0_, "BSy0/F");
179  bstree_->Branch("BSz0", &theBSOfromDB_.BSz0_, "BSz0/F");
180  bstree_->Branch("Beamsigmaz", &theBSOfromDB_.Beamsigmaz_, "Beamsigmaz/F");
181  bstree_->Branch("Beamdxdz", &theBSOfromDB_.Beamdxdz_, "Beamdxdz/F");
182  bstree_->Branch("BeamWidthX", &theBSOfromDB_.BeamWidthX_, "BeamWidthX/F");
183  bstree_->Branch("BeamWidthY", &theBSOfromDB_.BeamWidthY_, "BeamWidthY/F");
184  bstree_->Branch("LastAnalyzedLumi", &theBSOfromDB_.lastAnalyzedLumi_, "LastAnalyzedLumi/I");
185  bstree_->Branch("LastAnalyzedRun", &theBSOfromDB_.lastAnalyzedRun_, "LastAnalyzedRun/I");
186  bstree_->Branch("LastAnalyzedFill", &theBSOfromDB_.lastAnalyzedFill_, "LastAnalyzedFill/I");
187 }
188 
189 // ------------ method called once each job just after ending the event loop ------------
191 
192 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
194  //The following says we do not know what parameters are allowed so do no validation
195  // Please change this to state exactly what you do use, even if it is no parameters
197  desc.setUnknown();
198  descriptions.addDefault(desc);
199 }
200 
201 //define this as a plug-in
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::init
void init()
Definition: BeamSpotOnlineLegacyRcdReader.cc:110
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
BeamSpotObjects::GetBeamWidthY
double GetBeamWidthY() const
get average transverse beam width
Definition: BeamSpotObjects.h:77
BeamSpotObjects::Getdxdz
double Getdxdz() const
get dxdz slope, crossing angle in XZ
Definition: BeamSpotObjects.h:79
BeamSpotOnlineLegacyRcdReader::bstree_
TTree * bstree_
Definition: BeamSpotOnlineLegacyRcdReader.cc:78
BeamSpotOnlineLegacyRcdReader::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: BeamSpotOnlineLegacyRcdReader.cc:193
EDAnalyzer.h
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::lastAnalyzedLumi_
int lastAnalyzedLumi_
Definition: BeamSpotOnlineLegacyRcdReader.cc:71
BeamSpotOnlineLegacyRcdReader::theBSOfromDB
Definition: BeamSpotOnlineLegacyRcdReader.cc:61
edm::ESWatcher< BeamSpotOnlineLegacyObjectsRcd >
BeamSpotOnlineLegacyRcdReader::output_
std::unique_ptr< std::ofstream > output_
Definition: BeamSpotOnlineLegacyRcdReader.cc:82
ESHandle.h
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
BeamSpotObjects::GetSigmaZ
double GetSigmaZ() const
get sigma Z, RMS bunch length
Definition: BeamSpotObjects.h:73
edm
HLT enums.
Definition: AlignableModifier.h:19
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::lastAnalyzedFill_
int lastAnalyzedFill_
Definition: BeamSpotOnlineLegacyRcdReader.cc:73
BeamSpotOnlineLegacyRcdReader::beginJob
void beginJob() override
Definition: BeamSpotOnlineLegacyRcdReader.cc:171
BeamSpotObjects::GetZ
double GetZ() const
get Z beam position
Definition: BeamSpotObjects.h:71
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::Beamsigmaz_
float Beamsigmaz_
Definition: BeamSpotOnlineLegacyRcdReader.cc:67
BeamSpotOnlineLegacyObjectsRcd.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
BeamSpotOnlineLegacyRcdReader::~BeamSpotOnlineLegacyRcdReader
~BeamSpotOnlineLegacyRcdReader() override
Definition: BeamSpotOnlineLegacyRcdReader.cc:101
MakerMacros.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::BSz0_
float BSz0_
Definition: BeamSpotOnlineLegacyRcdReader.cc:66
edm::ESHandle
Definition: DTSurvey.h:22
BeamSpotOnlineLegacyObjectsRcd
Definition: BeamSpotOnlineLegacyObjectsRcd.h:24
BeamSpotOnlineObjects::GetLastAnalyzedLumi
int GetLastAnalyzedLumi() const
Getters Methods.
Definition: BeamSpotOnlineObjects.h:63
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::BeamWidthX_
float BeamWidthX_
Definition: BeamSpotOnlineLegacyRcdReader.cc:69
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TFileService.h
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::BSx0_
float BSx0_
Definition: BeamSpotOnlineLegacyRcdReader.cc:64
edm::ParameterSet
Definition: ParameterSet.h:47
BeamSpotObjects::GetY
double GetY() const
get Y beam position
Definition: BeamSpotObjects.h:69
Event.h
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::BSy0_
float BSy0_
Definition: BeamSpotOnlineLegacyRcdReader.cc:65
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::Beamdxdz_
float Beamdxdz_
Definition: BeamSpotOnlineLegacyRcdReader.cc:68
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
BeamSpotOnlineLegacyRcdReader::endJob
void endJob() override
Definition: BeamSpotOnlineLegacyRcdReader.cc:190
BeamSpotOnlineLegacyRcdReader::BeamSpotOnlineLegacyRcdReader
BeamSpotOnlineLegacyRcdReader(const edm::ParameterSet &)
Definition: BeamSpotOnlineLegacyRcdReader.cc:88
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::ls
int ls
Definition: BeamSpotOnlineLegacyRcdReader.cc:62
BeamSpotOnlineLegacyRcdReader::theBSOfromDB_
struct BeamSpotOnlineLegacyRcdReader::theBSOfromDB theBSOfromDB_
edm::EventSetup
Definition: EventSetup.h:57
BeamSpotOnlineLegacyRcdReader
Definition: BeamSpotOnlineLegacyRcdReader.cc:49
BeamSpotOnlineObjects::GetLastAnalyzedRun
int GetLastAnalyzedRun() const
Definition: BeamSpotOnlineObjects.h:66
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
InputTag.h
BeamSpotOnlineLegacyRcdReader::tFileService
edm::Service< TFileService > tFileService
Definition: BeamSpotOnlineLegacyRcdReader.cc:77
BeamSpotObjects::GetBeamWidthX
double GetBeamWidthX() const
get average transverse beam width
Definition: BeamSpotObjects.h:75
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::lastAnalyzedRun_
int lastAnalyzedRun_
Definition: BeamSpotOnlineLegacyRcdReader.cc:72
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
Frameworkfwd.h
ESWatcher.h
BeamSpotOnlineObjects
Definition: BeamSpotOnlineObjects.h:25
EventSetup.h
BeamSpotOnlineObjects.h
BeamSpotOnlineLegacyRcdReader::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: BeamSpotOnlineLegacyRcdReader.cc:129
ParameterSet.h
edm::Event
Definition: Event.h:73
BeamSpotOnlineObjects::GetLastAnalyzedFill
int GetLastAnalyzedFill() const
Definition: BeamSpotOnlineObjects.h:69
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
BeamSpotOnlineLegacyRcdReader::watcher_
edm::ESWatcher< BeamSpotOnlineLegacyObjectsRcd > watcher_
Definition: BeamSpotOnlineLegacyRcdReader.cc:81
BeamSpotObjects::GetX
double GetX() const
get X beam position
Definition: BeamSpotObjects.h:67
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::BeamWidthY_
float BeamWidthY_
Definition: BeamSpotOnlineLegacyRcdReader.cc:70
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
BeamSpotOnlineLegacyRcdReader::theBSOfromDB::run
int run
Definition: BeamSpotOnlineLegacyRcdReader.cc:63