CMS 3D CMS Logo

AlcaBeamSpotProducer.cc
Go to the documentation of this file.
1 
13 // C++ standard
14 #include <string>
15 // CMS
19 
23 
28 
30 #include "TMath.h"
31 
32 //--------------------------------------------------------------------------------------------------
34  // get parameter
35  write2DB_ = iConfig.getParameter<edm::ParameterSet>("AlcaBeamSpotProducerParameters").getParameter<bool>("WriteToDB");
37  iConfig.getParameter<edm::ParameterSet>("AlcaBeamSpotProducerParameters").getParameter<bool>("RunAllFitters");
38  fitNLumi_ = iConfig.getParameter<edm::ParameterSet>("AlcaBeamSpotProducerParameters")
39  .getUntrackedParameter<int>("fitEveryNLumi", -1);
40  resetFitNLumi_ = iConfig.getParameter<edm::ParameterSet>("AlcaBeamSpotProducerParameters")
41  .getUntrackedParameter<int>("resetEveryNLumi", -1);
43  iConfig.getParameter<edm::ParameterSet>("AlcaBeamSpotProducerParameters").getParameter<bool>("RunBeamWidthFit");
44 
45  theBeamFitter = new BeamFitter(iConfig, consumesCollector());
51 
52  ftotalevents = 0;
53  ftmprun0 = ftmprun = -1;
54  countLumi_ = 0;
56 
57  produces<reco::BeamSpot, edm::Transition::EndLuminosityBlock>("alcaBeamSpot");
58 }
59 
60 //--------------------------------------------------------------------------------------------------
62 
63 //--------------------------------------------------------------------------------------------------
65  ftotalevents++;
67  ftmprun = iEvent.id().run();
68 }
69 
70 //--------------------------------------------------------------------------------------------------
72  const edm::TimeValue_t fbegintimestamp = lumiSeg.beginTime().value();
73  const std::time_t ftmptime = fbegintimestamp >> 32;
74 
75  if (countLumi_ == 0 || (resetFitNLumi_ > 0 && countLumi_ % resetFitNLumi_ == 0)) {
76  ftmprun0 = lumiSeg.run();
77  ftmprun = ftmprun0;
79  refBStime[0] = ftmptime;
80  }
81 
82  countLumi_++;
83 }
84 
85 //--------------------------------------------------------------------------------------------------
87 
88 //--------------------------------------------------------------------------------------------------
90  const edm::TimeValue_t fendtimestamp = lumiSeg.endTime().value();
91  const std::time_t fendtime = fendtimestamp >> 32;
92  refBStime[1] = fendtime;
93 
94  endLumiOfBSFit_ = lumiSeg.luminosityBlock();
95 
96  if (fitNLumi_ == -1 && resetFitNLumi_ == -1)
97  return;
98 
99  if (fitNLumi_ > 0 && countLumi_ % fitNLumi_ != 0)
100  return;
101 
105 
106  std::pair<int, int> LSRange = theBeamFitter->getFitLSRange();
107 
111  edm::LogInfo("AlcaBeamSpotProducer") << "\n RESULTS OF DEFAULT FIT " << std::endl
112  << " for runs: " << ftmprun0 << " - " << ftmprun << std::endl
113  << " for lumi blocks : " << LSRange.first << " - " << LSRange.second
114  << std::endl
115  << " lumi counter # " << countLumi_ << std::endl
116  << bs << std::endl
117  << "fit done. \n"
118  << std::endl;
119  } else { // Fill in empty beam spot if beamfit fails
120  bs.setType(reco::BeamSpot::Fake);
121  edm::LogInfo("AlcaBeamSpotProducer") << "\n Empty Beam spot fit" << std::endl
122  << " for runs: " << ftmprun0 << " - " << ftmprun << std::endl
123  << " for lumi blocks : " << LSRange.first << " - " << LSRange.second
124  << std::endl
125  << " lumi counter # " << countLumi_ << std::endl
126  << bs << std::endl
127  << "fit failed \n"
128  << std::endl;
129  }
130 
131  auto result = std::make_unique<reco::BeamSpot>();
132  *result = bs;
133  lumiSeg.put(std::move(result), std::string("alcaBeamSpot"));
134 
135  if (resetFitNLumi_ > 0 && countLumi_ % resetFitNLumi_ == 0) {
136  std::vector<BSTrkParameters> theBSvector = theBeamFitter->getBSvector();
137  edm::LogInfo("AlcaBeamSpotProducer") << "Total number of tracks accumulated = " << theBSvector.size() << std::endl
138  << "Reset track collection for beam fit" << std::endl;
144  countLumi_ = 0;
145  }
146 }
147 
AlcaBeamSpotProducer::refBStime
std::time_t refBStime[2]
Definition: AlcaBeamSpotProducer.h:44
BeamFitter::runPVandTrkFitter
bool runPVandTrkFitter()
Definition: BeamFitter.cc:449
AlcaBeamSpotProducer::~AlcaBeamSpotProducer
~AlcaBeamSpotProducer() override
Definition: AlcaBeamSpotProducer.cc:61
BeamFitter::resetRefTime
void resetRefTime()
Definition: BeamFitter.h:61
BeamFitter::resetPVFitter
void resetPVFitter()
Definition: BeamFitter.h:72
BeamFitter::resetTrkVector
void resetTrkVector()
Definition: BeamFitter.h:58
MessageLogger.h
AlcaBeamMonitor_cfi.BeamFitter
BeamFitter
Definition: AlcaBeamMonitor_cfi.py:11
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
LuminosityBlock.h
AlcaBeamSpotProducer::beginLumiOfBSFit_
int beginLumiOfBSFit_
Definition: AlcaBeamSpotProducer.h:42
AlcaBeamSpotProducer::theBeamFitter
BeamFitter * theBeamFitter
Definition: AlcaBeamSpotProducer.h:51
AlcaBeamSpotProducer::endLumiOfBSFit_
int endLumiOfBSFit_
Definition: AlcaBeamSpotProducer.h:43
edm::LuminosityBlockBase::beginTime
Timestamp const & beginTime() const
Definition: LuminosityBlockBase.h:46
AlcaBeamSpotProducer::fitNLumi_
int fitNLumi_
Definition: AlcaBeamSpotProducer.h:37
BeamFitter::readEvent
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:261
edm::EDConsumerBase::consumesCollector
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Definition: EDConsumerBase.cc:47
AlcaBeamSpotProducer::resetFitNLumi_
int resetFitNLumi_
Definition: AlcaBeamSpotProducer.h:38
edm::Timestamp::value
TimeValue_t value() const
Definition: Timestamp.h:45
edm::LuminosityBlockBase::run
RunNumber_t run() const
Definition: LuminosityBlockBase.h:42
AlcaBeamSpotProducer::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &iSetup) final
Definition: AlcaBeamSpotProducer.cc:71
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
MakerMacros.h
BeamSpotObjects.h
cms::cuda::bs
bs
Definition: HistoContainer.h:76
AlcaBeamSpotProducer::ftotalevents
int ftotalevents
Definition: AlcaBeamSpotProducer.h:36
BeamSpotObjectsRcd.h
edm::LuminosityBlockBase::endTime
Timestamp const & endTime() const
Definition: LuminosityBlockBase.h:47
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
edm::LuminosityBlockBase::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockBase.h:40
reco::BeamSpot
Definition: BeamSpot.h:21
reco::BeamSpot::Fake
Definition: BeamSpot.h:24
AlcaBeamSpotProducer
Definition: AlcaBeamSpotProducer.h:24
BeamFitter::getBeamSpot
reco::BeamSpot getBeamSpot()
Definition: BeamFitter.h:93
BeamFitter::setRun
void setRun(int run)
Definition: BeamFitter.h:119
BeamFitter::setRefTime
void setRefTime(time_t t0, time_t t1)
Definition: BeamFitter.h:62
AlcaBeamSpotProducer::write2DB_
bool write2DB_
Definition: AlcaBeamSpotProducer.h:46
AlcaBeamSpotProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) final
Definition: AlcaBeamSpotProducer.cc:64
edm::ParameterSet
Definition: ParameterSet.h:47
AlcaBeamSpotProducer::AlcaBeamSpotProducer
AlcaBeamSpotProducer(const edm::ParameterSet &)
Definition: AlcaBeamSpotProducer.cc:33
AlcaBeamSpotProducer::countLumi_
int countLumi_
Definition: AlcaBeamSpotProducer.h:40
AlcaBeamSpotProducer::ftmprun0
int ftmprun0
Definition: AlcaBeamSpotProducer.h:41
AlcaBeamSpotProducer.h
iEvent
int iEvent
Definition: GenABIO.cc:224
BeamFitter::resetLSRange
void resetLSRange()
Definition: BeamFitter.h:60
edm::EventSetup
Definition: EventSetup.h:58
edm::LuminosityBlock::put
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: LuminosityBlock.h:116
BeamFitter::resetCutFlow
void resetCutFlow()
Definition: BeamFitter.h:104
AlcaBeamSpotProducer::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &iSetup) final
Definition: AlcaBeamSpotProducer.cc:86
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
BeamFitter::setFitLSRange
void setFitLSRange(int ls0, int ls1)
Definition: BeamFitter.h:115
eostools.move
def move(src, dest)
Definition: eostools.py:511
BeamFitter::getFitLSRange
std::pair< int, int > getFitLSRange()
Definition: BeamFitter.h:114
AlcaBeamSpotProducer::runbeamwidthfit_
bool runbeamwidthfit_
Definition: AlcaBeamSpotProducer.h:47
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
mps_fire.result
result
Definition: mps_fire.py:311
ConsumesCollector.h
AlcaBeamSpotProducer::runallfitters_
bool runallfitters_
Definition: AlcaBeamSpotProducer.h:48
AlcaBeamSpotProducer::ftmprun
int ftmprun
Definition: AlcaBeamSpotProducer.h:41
BSFitter.h
edm::Event
Definition: Event.h:73
BeamFitter::getBSvector
std::vector< BSTrkParameters > getBSvector()
Definition: BeamFitter.h:95
edm::TimeValue_t
unsigned long long TimeValue_t
Definition: Timestamp.h:28
AlcaBeamSpotProducer::endLuminosityBlockProduce
void endLuminosityBlockProduce(edm::LuminosityBlock &lumiSeg, const edm::EventSetup &iSetup) final
Definition: AlcaBeamSpotProducer.cc:89