CMS 3D CMS Logo

BeamSpotOnlineHLTRcdReader.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondTools/BeamSpot
4 // Class: BeamSpotOnlineHLTRcdReader
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 BeamSpotOnlineHLTRcdReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
50 public:
52  ~BeamSpotOnlineHLTRcdReader() override;
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<BeamSpotOnlineHLTObjectsRcd>().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
BeamSpotOnlineHLTRcdReader::theBSOfromDB
Definition: BeamSpotOnlineHLTRcdReader.cc:61
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
BeamSpotOnlineHLTObjectsRcd
Definition: BeamSpotOnlineHLTObjectsRcd.h:24
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
EDAnalyzer.h
BeamSpotOnlineHLTRcdReader::theBSOfromDB::ls
int ls
Definition: BeamSpotOnlineHLTRcdReader.cc:62
edm::ESWatcher< BeamSpotOnlineHLTObjectsRcd >
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
BeamSpotObjects::GetZ
double GetZ() const
get Z beam position
Definition: BeamSpotObjects.h:71
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
BeamSpotOnlineHLTRcdReader::bstree_
TTree * bstree_
Definition: BeamSpotOnlineHLTRcdReader.cc:78
BeamSpotOnlineHLTRcdReader::tFileService
edm::Service< TFileService > tFileService
Definition: BeamSpotOnlineHLTRcdReader.cc:77
BeamSpotOnlineHLTRcdReader::theBSOfromDB_
struct BeamSpotOnlineHLTRcdReader::theBSOfromDB theBSOfromDB_
BeamSpotOnlineHLTRcdReader::theBSOfromDB::Beamsigmaz_
float Beamsigmaz_
Definition: BeamSpotOnlineHLTRcdReader.cc:67
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
MakerMacros.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
BeamSpotOnlineHLTRcdReader::theBSOfromDB::BSy0_
float BSy0_
Definition: BeamSpotOnlineHLTRcdReader.cc:65
BeamSpotOnlineHLTRcdReader::~BeamSpotOnlineHLTRcdReader
~BeamSpotOnlineHLTRcdReader() override
Definition: BeamSpotOnlineHLTRcdReader.cc:101
edm::ESHandle
Definition: DTSurvey.h:22
BeamSpotOnlineHLTRcdReader::theBSOfromDB::BeamWidthX_
float BeamWidthX_
Definition: BeamSpotOnlineHLTRcdReader.cc:69
BeamSpotOnlineHLTRcdReader::watcher_
edm::ESWatcher< BeamSpotOnlineHLTObjectsRcd > watcher_
Definition: BeamSpotOnlineHLTRcdReader.cc:81
BeamSpotOnlineObjects::GetLastAnalyzedLumi
int GetLastAnalyzedLumi() const
Getters Methods.
Definition: BeamSpotOnlineObjects.h:63
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
BeamSpotOnlineHLTRcdReader::theBSOfromDB::BSz0_
float BSz0_
Definition: BeamSpotOnlineHLTRcdReader.cc:66
TFileService.h
BeamSpotOnlineHLTRcdReader::output_
std::unique_ptr< std::ofstream > output_
Definition: BeamSpotOnlineHLTRcdReader.cc:82
edm::ParameterSet
Definition: ParameterSet.h:47
BeamSpotObjects::GetY
double GetY() const
get Y beam position
Definition: BeamSpotObjects.h:69
Event.h
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
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
BeamSpotOnlineHLTRcdReader::theBSOfromDB::init
void init()
Definition: BeamSpotOnlineHLTRcdReader.cc:110
BeamSpotObjects::GetBeamWidthX
double GetBeamWidthX() const
get average transverse beam width
Definition: BeamSpotObjects.h:75
BeamSpotOnlineHLTRcdReader::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: BeamSpotOnlineHLTRcdReader.cc:129
BeamSpotOnlineHLTObjectsRcd.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
BeamSpotOnlineHLTRcdReader::beginJob
void beginJob() override
Definition: BeamSpotOnlineHLTRcdReader.cc:171
BeamSpotOnlineHLTRcdReader::theBSOfromDB::lastAnalyzedRun_
int lastAnalyzedRun_
Definition: BeamSpotOnlineHLTRcdReader.cc:72
Frameworkfwd.h
ESWatcher.h
BeamSpotOnlineObjects
Definition: BeamSpotOnlineObjects.h:25
BeamSpotOnlineHLTRcdReader::theBSOfromDB::BSx0_
float BSx0_
Definition: BeamSpotOnlineHLTRcdReader.cc:64
BeamSpotOnlineHLTRcdReader::theBSOfromDB::Beamdxdz_
float Beamdxdz_
Definition: BeamSpotOnlineHLTRcdReader.cc:68
EventSetup.h
BeamSpotOnlineHLTRcdReader
Definition: BeamSpotOnlineHLTRcdReader.cc:49
BeamSpotOnlineHLTRcdReader::theBSOfromDB::lastAnalyzedFill_
int lastAnalyzedFill_
Definition: BeamSpotOnlineHLTRcdReader.cc:73
BeamSpotOnlineObjects.h
BeamSpotOnlineHLTRcdReader::theBSOfromDB::run
int run
Definition: BeamSpotOnlineHLTRcdReader.cc:63
ParameterSet.h
BeamSpotOnlineHLTRcdReader::endJob
void endJob() override
Definition: BeamSpotOnlineHLTRcdReader.cc:190
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
BeamSpotObjects::GetX
double GetX() const
get X beam position
Definition: BeamSpotObjects.h:67
BeamSpotOnlineHLTRcdReader::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: BeamSpotOnlineHLTRcdReader.cc:193
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
BeamSpotOnlineHLTRcdReader::theBSOfromDB::lastAnalyzedLumi_
int lastAnalyzedLumi_
Definition: BeamSpotOnlineHLTRcdReader.cc:71
BeamSpotOnlineHLTRcdReader::BeamSpotOnlineHLTRcdReader
BeamSpotOnlineHLTRcdReader(const edm::ParameterSet &)
Definition: BeamSpotOnlineHLTRcdReader.cc:88
BeamSpotOnlineHLTRcdReader::theBSOfromDB::BeamWidthY_
float BeamWidthY_
Definition: BeamSpotOnlineHLTRcdReader.cc:70