-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35236 from mmusich/modernizeRecoVertexBeamSpotPro…
…ducer modernize `RecoVertex/BeamSpotProducer`
- Loading branch information
Showing
6 changed files
with
182 additions
and
248 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1 @@ | ||
#ifndef BeamSpotProducer_BeamSpotFromDB_h | ||
#define BeamSpotProducer_BeamSpotFromDB_h | ||
|
||
/**_________________________________________________________________ | ||
class: BeamSpotFromDB.h | ||
package: RecoVertex/BeamSpotProducer | ||
author: Francisco Yumiceva, Fermilab ([email protected]) | ||
________________________________________________________________**/ | ||
|
||
// C++ standard | ||
#include <string> | ||
// CMS | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/EDAnalyzer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/Utilities/interface/ESGetToken.h" | ||
|
||
#include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h" | ||
#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h" | ||
|
||
class BeamSpotFromDB : public edm::EDAnalyzer { | ||
public: | ||
explicit BeamSpotFromDB(const edm::ParameterSet&); | ||
~BeamSpotFromDB() override; | ||
|
||
private: | ||
void beginJob() override; | ||
void analyze(const edm::Event&, const edm::EventSetup&) override; | ||
void endJob() override; | ||
edm::ESGetToken<BeamSpotObjects, BeamSpotObjectsRcd> m_beamToken; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1 @@ | ||
#ifndef BeamSpotProducer_BeamSpotWrite2DB_h | ||
#define BeamSpotProducer_BeamSpotWrite2DB_h | ||
|
||
/**_________________________________________________________________ | ||
class: BeamSpotWrite2DB.h | ||
package: RecoVertex/BeamSpotProducer | ||
author: Francisco Yumiceva, Fermilab ([email protected]) | ||
________________________________________________________________**/ | ||
|
||
// C++ standard | ||
#include <string> | ||
// CMS | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/EDAnalyzer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "RecoVertex/BeamSpotProducer/interface/BSTrkParameters.h" | ||
|
||
// ROOT | ||
#include "TFile.h" | ||
#include "TTree.h" | ||
|
||
#include <fstream> | ||
|
||
class BeamSpotWrite2DB : public edm::EDAnalyzer { | ||
public: | ||
explicit BeamSpotWrite2DB(const edm::ParameterSet&); | ||
~BeamSpotWrite2DB() override; | ||
|
||
private: | ||
void beginJob() override; | ||
void analyze(const edm::Event&, const edm::EventSetup&) override; | ||
void endJob() override; | ||
|
||
std::ifstream fasciiFile; | ||
std::string fasciiFileName; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,60 @@ | |
class: BeamSpotAnalyzer.cc | ||
package: RecoVertex/BeamSpotProducer | ||
author: Francisco Yumiceva, Fermilab ([email protected]) | ||
Geng-Yuan Jeng, UC Riverside ([email protected]) | ||
________________________________________________________________**/ | ||
|
||
// C++ standard | ||
#include <string> | ||
#include <string> | ||
|
||
// CMS | ||
#include "DataFormats/BeamSpot/interface/BeamSpot.h" | ||
#include "RecoVertex/BeamSpotProducer/interface/BeamSpotAnalyzer.h" | ||
#include "RecoVertex/BeamSpotProducer/interface/BSFitter.h" | ||
|
||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "FWCore/Framework/interface/ConsumesCollector.h" | ||
#include "FWCore/Framework/interface/one/EDAnalyzer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/LuminosityBlock.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/Framework/interface/ConsumesCollector.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "RecoVertex/BeamSpotProducer/interface/BeamFitter.h" | ||
|
||
#include "TMath.h" | ||
|
||
class BeamSpotAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchLuminosityBlocks> { | ||
public: | ||
explicit BeamSpotAnalyzer(const edm::ParameterSet&); | ||
~BeamSpotAnalyzer() override; | ||
static void fillDescriptions(edm::ConfigurationDescriptions&); | ||
|
||
private: | ||
void analyze(const edm::Event&, const edm::EventSetup&) override; | ||
void endJob() override; | ||
void beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& context) override; | ||
void endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c) override; | ||
|
||
int ftotalevents; | ||
int fitNLumi_; | ||
int resetFitNLumi_; | ||
int countLumi_; //counter | ||
int org_resetFitNLumi_; | ||
int previousLumi_; | ||
int previousRun_; | ||
int ftmprun0, ftmprun; | ||
int beginLumiOfBSFit_; | ||
int endLumiOfBSFit_; | ||
std::time_t refBStime[2]; | ||
|
||
bool write2DB_; | ||
bool runbeamwidthfit_; | ||
bool runallfitters_; | ||
|
||
BeamFitter* theBeamFitter; | ||
}; | ||
|
||
BeamSpotAnalyzer::BeamSpotAnalyzer(const edm::ParameterSet& iConfig) { | ||
// get parameter | ||
write2DB_ = iConfig.getParameter<edm::ParameterSet>("BSAnalyzerParameters").getParameter<bool>("WriteToDB"); | ||
|
@@ -47,7 +79,7 @@ BeamSpotAnalyzer::BeamSpotAnalyzer(const edm::ParameterSet& iConfig) { | |
countLumi_ = 0; | ||
beginLumiOfBSFit_ = endLumiOfBSFit_ = -1; | ||
previousLumi_ = previousRun_ = 0; | ||
Org_resetFitNLumi_ = resetFitNLumi_; | ||
org_resetFitNLumi_ = resetFitNLumi_; | ||
} | ||
|
||
BeamSpotAnalyzer::~BeamSpotAnalyzer() { delete theBeamFitter; } | ||
|
@@ -58,8 +90,6 @@ void BeamSpotAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& | |
ftmprun = iEvent.id().run(); | ||
} | ||
|
||
void BeamSpotAnalyzer::beginJob() {} | ||
|
||
//-------------------------------------------------------- | ||
void BeamSpotAnalyzer::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& context) { | ||
const edm::TimeValue_t fbegintimestamp = lumiSeg.beginTime().value(); | ||
|
@@ -73,7 +103,6 @@ void BeamSpotAnalyzer::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg, | |
} | ||
|
||
countLumi_++; | ||
//std::cout << "Lumi # " << countLumi_ << std::endl; | ||
if (ftmprun == previousRun_) { | ||
if ((previousLumi_ + 1) != int(lumiSeg.luminosityBlock())) | ||
edm::LogWarning("BeamSpotAnalyzer") << "LUMI SECTIONS ARE NOT SORTED!"; | ||
|
@@ -82,12 +111,10 @@ void BeamSpotAnalyzer::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg, | |
|
||
//-------------------------------------------------------- | ||
void BeamSpotAnalyzer::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& iSetup) { | ||
//LogDebug("BeamSpotAnalyzer") << | ||
std::cout << "for lumis " << beginLumiOfBSFit_ << " - " << endLumiOfBSFit_ << std::endl | ||
<< "number of selected tracks = " << theBeamFitter->getNTracks() << std::endl; | ||
std::cout << "number of selected PVs = " << theBeamFitter->getNPVs() << std::endl; | ||
//std::cout << "number of selected PVs per bx: " << std::endl; | ||
//theBeamFitter->getNPVsperBX(); | ||
edm::LogPrint("BeamSpotAnalyzer") << "for lumis " << beginLumiOfBSFit_ << " - " << endLumiOfBSFit_ << std::endl | ||
<< "number of selected tracks = " << theBeamFitter->getNTracks(); | ||
edm::LogPrint("BeamSpotAnalyzer") << "number of selected PVs = " << theBeamFitter->getNPVs(); | ||
//edm::LogPrint("BeamSpotAnalyzer") << "number of selected PVs per bx: " << theBeamFitter->getNPVsperBX() std::endl; | ||
|
||
const edm::TimeValue_t fendtimestamp = lumiSeg.endTime().value(); | ||
const std::time_t fendtime = fendtimestamp >> 32; | ||
|
@@ -110,61 +137,61 @@ void BeamSpotAnalyzer::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, c | |
|
||
if (theBeamFitter->runPVandTrkFitter()) { | ||
reco::BeamSpot bs = theBeamFitter->getBeamSpot(); | ||
std::cout << "\n RESULTS OF DEFAULT FIT " << std::endl; | ||
std::cout << " for runs: " << ftmprun0 << " - " << ftmprun << std::endl; | ||
std::cout << " for lumi blocks : " << LSRange.first << " - " << LSRange.second << std::endl; | ||
std::cout << " lumi counter # " << countLumi_ << std::endl; | ||
std::cout << bs << std::endl; | ||
std::cout << "[BeamFitter] fit done. \n" << std::endl; | ||
edm::LogPrint("BeamSpotAnalyzer") << "\n RESULTS OF DEFAULT FIT "; | ||
edm::LogPrint("BeamSpotAnalyzer") << " for runs: " << ftmprun0 << " - " << ftmprun; | ||
edm::LogPrint("BeamSpotAnalyzer") << " for lumi blocks : " << LSRange.first << " - " << LSRange.second; | ||
edm::LogPrint("BeamSpotAnalyzer") << " lumi counter # " << countLumi_; | ||
edm::LogPrint("BeamSpotAnalyzer") << bs; | ||
edm::LogPrint("BeamSpotAnalyzer") << "[BeamFitter] fit done. \n"; | ||
} else { // Fill in empty beam spot if beamfit fails | ||
reco::BeamSpot bs; | ||
bs.setType(reco::BeamSpot::Fake); | ||
std::cout << "\n Empty Beam spot fit" << std::endl; | ||
std::cout << " for runs: " << ftmprun0 << " - " << ftmprun << std::endl; | ||
std::cout << " for lumi blocks : " << LSRange.first << " - " << LSRange.second << std::endl; | ||
std::cout << " lumi counter # " << countLumi_ << std::endl; | ||
std::cout << bs << std::endl; | ||
std::cout << "[BeamFitter] fit failed \n" << std::endl; | ||
//accumulate more events | ||
// dissable this for the moment | ||
edm::LogPrint("BeamSpotAnalyzer") << "\n Empty Beam spot fit"; | ||
edm::LogPrint("BeamSpotAnalyzer") << " for runs: " << ftmprun0 << " - " << ftmprun; | ||
edm::LogPrint("BeamSpotAnalyzer") << " for lumi blocks : " << LSRange.first << " - " << LSRange.second; | ||
edm::LogPrint("BeamSpotAnalyzer") << " lumi counter # " << countLumi_; | ||
edm::LogPrint("BeamSpotAnalyzer") << bs; | ||
edm::LogPrint("BeamSpotAnalyzer") << "[BeamFitter] fit failed \n"; | ||
// accumulate more events | ||
// disable this for the moment | ||
//resetFitNLumi_ += 1; | ||
//std::cout << "reset fitNLumi " << resetFitNLumi_ << std::endl; | ||
//edm::LogPrint("BeamSpotAnalyzer") << "reset fitNLumi " << resetFitNLumi_ ; | ||
} | ||
|
||
if (resetFitNLumi_ > 0 && countLumi_ % resetFitNLumi_ == 0) { | ||
std::vector<BSTrkParameters> theBSvector = theBeamFitter->getBSvector(); | ||
std::cout << "Total number of tracks accumulated = " << theBSvector.size() << std::endl; | ||
std::cout << "Reset track collection for beam fit" << std::endl; | ||
edm::LogPrint("BeamSpotAnalyzer") << "Total number of tracks accumulated = " << theBSvector.size(); | ||
edm::LogPrint("BeamSpotAnalyzer") << "Reset track collection for beam fit"; | ||
theBeamFitter->resetTrkVector(); | ||
theBeamFitter->resetLSRange(); | ||
theBeamFitter->resetCutFlow(); | ||
theBeamFitter->resetRefTime(); | ||
theBeamFitter->resetPVFitter(); | ||
countLumi_ = 0; | ||
// reset counter to orginal | ||
resetFitNLumi_ = Org_resetFitNLumi_; | ||
resetFitNLumi_ = org_resetFitNLumi_; | ||
} | ||
} | ||
|
||
void BeamSpotAnalyzer::endJob() { | ||
std::cout << "\n-------------------------------------\n" << std::endl; | ||
std::cout << "\n Total number of events processed: " << ftotalevents << std::endl; | ||
std::cout << "\n-------------------------------------\n\n" << std::endl; | ||
edm::LogPrint("BeamSpotAnalyzer") << "\n-------------------------------------\n"; | ||
edm::LogPrint("BeamSpotAnalyzer") << "\n Total number of events processed: " << ftotalevents; | ||
edm::LogPrint("BeamSpotAnalyzer") << "\n-------------------------------------\n\n"; | ||
|
||
if (fitNLumi_ == -1 && resetFitNLumi_ == -1) { | ||
if (theBeamFitter->runPVandTrkFitter()) { | ||
reco::BeamSpot beam_default = theBeamFitter->getBeamSpot(); | ||
std::pair<int, int> LSRange = theBeamFitter->getFitLSRange(); | ||
|
||
std::cout << "\n RESULTS OF DEFAULT FIT:" << std::endl; | ||
std::cout << " for runs: " << ftmprun0 << " - " << ftmprun << std::endl; | ||
std::cout << " for lumi blocks : " << LSRange.first << " - " << LSRange.second << std::endl; | ||
std::cout << " lumi counter # " << countLumi_ << std::endl; | ||
std::cout << beam_default << std::endl; | ||
edm::LogPrint("BeamSpotAnalyzer") << "\n RESULTS OF DEFAULT FIT:"; | ||
edm::LogPrint("BeamSpotAnalyzer") << " for runs: " << ftmprun0 << " - " << ftmprun; | ||
edm::LogPrint("BeamSpotAnalyzer") << " for lumi blocks : " << LSRange.first << " - " << LSRange.second; | ||
edm::LogPrint("BeamSpotAnalyzer") << " lumi counter # " << countLumi_; | ||
edm::LogPrint("BeamSpotAnalyzer") << beam_default; | ||
|
||
if (write2DB_) { | ||
std::cout << "\n-------------------------------------\n\n" << std::endl; | ||
std::cout << " write results to DB..." << std::endl; | ||
edm::LogPrint("BeamSpotAnalyzer") << "\n-------------------------------------\n\n"; | ||
edm::LogPrint("BeamSpotAnalyzer") << " write results to DB..."; | ||
theBeamFitter->write2DB(); | ||
} | ||
|
||
|
@@ -175,14 +202,28 @@ void BeamSpotAnalyzer::endJob() { | |
if ((runbeamwidthfit_)) { | ||
theBeamFitter->runBeamWidthFitter(); | ||
reco::BeamSpot beam_width = theBeamFitter->getBeamWidth(); | ||
std::cout << beam_width << std::endl; | ||
edm::LogPrint("BeamSpotAnalyzer") << beam_width; | ||
} else { | ||
edm::LogPrint("BeamSpotAnalyzer") << "[BeamSpotAnalyzer] beamfit fails !!!"; | ||
} | ||
|
||
else | ||
std::cout << "[BeamSpotAnalyzer] beamfit fails !!!" << std::endl; | ||
} | ||
|
||
std::cout << "[BeamSpotAnalyzer] endJob done \n" << std::endl; | ||
edm::LogPrint("BeamSpotAnalyzer") << "[BeamSpotAnalyzer] endJob done \n"; | ||
} | ||
|
||
void BeamSpotAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.setComment("Analyzer of BeamSpot Objects"); | ||
|
||
edm::ParameterSetDescription bsAnalyzerParamsDesc; | ||
std::vector<edm::ParameterSet> bsAnaDefaults(1); | ||
bsAnaDefaults[0].addParameter("WriteToDB", false); | ||
bsAnaDefaults[0].addParameter("RunAllFitters", false); | ||
bsAnaDefaults[0].addUntrackedParameter("fitEveryNLumi", -1); | ||
bsAnaDefaults[0].addUntrackedParameter("resetEveryNLumi", -1); | ||
bsAnaDefaults[0].addParameter("RunBeamWidthFit", false); | ||
desc.addVPSet("BSAnalyzerParameters", bsAnalyzerParamsDesc, bsAnaDefaults); | ||
descriptions.addWithDefaultLabel(desc); | ||
} | ||
|
||
//define this as a plug-in | ||
|
Oops, something went wrong.