CMS 3D CMS Logo

AlcaBeamSpotProducer.cc
Go to the documentation of this file.
1 
13 // C++ standard
14 #include <string>
15 // CMS
19 
23 
29 
31 #include "TMath.h"
32 
33 //--------------------------------------------------------------------------------------------------
35  // get parameter
36  write2DB_ = iConfig.getParameter<edm::ParameterSet>("AlcaBeamSpotProducerParameters").getParameter<bool>("WriteToDB");
38  iConfig.getParameter<edm::ParameterSet>("AlcaBeamSpotProducerParameters").getParameter<bool>("RunAllFitters");
39  fitNLumi_ = iConfig.getParameter<edm::ParameterSet>("AlcaBeamSpotProducerParameters")
40  .getUntrackedParameter<int>("fitEveryNLumi", -1);
41  resetFitNLumi_ = iConfig.getParameter<edm::ParameterSet>("AlcaBeamSpotProducerParameters")
42  .getUntrackedParameter<int>("resetEveryNLumi", -1);
44  iConfig.getParameter<edm::ParameterSet>("AlcaBeamSpotProducerParameters").getParameter<bool>("RunBeamWidthFit");
45 
46  theBeamFitter = new BeamFitter(iConfig, consumesCollector());
52 
53  ftotalevents = 0;
54  ftmprun0 = ftmprun = -1;
55  countLumi_ = 0;
57 
58  produces<reco::BeamSpot, edm::Transition::EndLuminosityBlock>("alcaBeamSpot");
59 }
60 
61 //--------------------------------------------------------------------------------------------------
63 
64 //--------------------------------------------------------------------------------------------------
66  ftotalevents++;
68  ftmprun = iEvent.id().run();
69 }
70 
71 //--------------------------------------------------------------------------------------------------
73  const edm::TimeValue_t fbegintimestamp = lumiSeg.beginTime().value();
74  const std::time_t ftmptime = fbegintimestamp >> 32;
75 
76  if (countLumi_ == 0 || (resetFitNLumi_ > 0 && countLumi_ % resetFitNLumi_ == 0)) {
77  ftmprun0 = lumiSeg.run();
78  ftmprun = ftmprun0;
80  refBStime[0] = ftmptime;
81  }
82 
83  countLumi_++;
84 }
85 
86 //--------------------------------------------------------------------------------------------------
88 
89 //--------------------------------------------------------------------------------------------------
91  const edm::TimeValue_t fendtimestamp = lumiSeg.endTime().value();
92  const std::time_t fendtime = fendtimestamp >> 32;
93  refBStime[1] = fendtime;
94 
95  endLumiOfBSFit_ = lumiSeg.luminosityBlock();
96 
97  if (fitNLumi_ == -1 && resetFitNLumi_ == -1)
98  return;
99 
100  if (fitNLumi_ > 0 && countLumi_ % fitNLumi_ != 0)
101  return;
102 
106 
107  std::pair<int, int> LSRange = theBeamFitter->getFitLSRange();
108 
112  edm::LogInfo("AlcaBeamSpotProducer") << "\n RESULTS OF DEFAULT FIT " << std::endl
113  << " for runs: " << ftmprun0 << " - " << ftmprun << std::endl
114  << " for lumi blocks : " << LSRange.first << " - " << LSRange.second
115  << std::endl
116  << " lumi counter # " << countLumi_ << std::endl
117  << bs << std::endl
118  << "fit done. \n"
119  << std::endl;
120  } else { // Fill in empty beam spot if beamfit fails
121  bs.setType(reco::BeamSpot::Fake);
122  edm::LogInfo("AlcaBeamSpotProducer") << "\n Empty Beam spot fit" << std::endl
123  << " for runs: " << ftmprun0 << " - " << ftmprun << std::endl
124  << " for lumi blocks : " << LSRange.first << " - " << LSRange.second
125  << std::endl
126  << " lumi counter # " << countLumi_ << std::endl
127  << bs << std::endl
128  << "fit failed \n"
129  << std::endl;
130  }
131 
132  auto result = std::make_unique<reco::BeamSpot>();
133  *result = bs;
134  lumiSeg.put(std::move(result), std::string("alcaBeamSpot"));
135 
136  if (resetFitNLumi_ > 0 && countLumi_ % resetFitNLumi_ == 0) {
137  std::vector<BSTrkParameters> theBSvector = theBeamFitter->getBSvector();
138  edm::LogInfo("AlcaBeamSpotProducer") << "Total number of tracks accumulated = " << theBSvector.size() << std::endl
139  << "Reset track collection for beam fit" << std::endl;
145  countLumi_ = 0;
146  }
147 }
148 
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:62
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:10
ESHandle.h
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:46
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:72
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
MakerMacros.h
BeamSpotObjects.h
cms::cuda::bs
bs
Definition: HistoContainer.h:127
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
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:65
edm::ParameterSet
Definition: ParameterSet.h:47
AlcaBeamSpotProducer::AlcaBeamSpotProducer
AlcaBeamSpotProducer(const edm::ParameterSet &)
Definition: AlcaBeamSpotProducer.cc:34
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:57
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:87
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:90