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++;
67  theBeamFitter->readEvent(iEvent);
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 
109  reco::BeamSpot bs;
111  bs = theBeamFitter->getBeamSpot();
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
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 
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
bool runPVandTrkFitter()
Definition: BeamFitter.cc:398
void setRun(int run)
Definition: BeamFitter.h:124
std::vector< BSTrkParameters > getBSvector()
Definition: BeamFitter.h:96
void resetTrkVector()
Definition: BeamFitter.h:53
Timestamp const & beginTime() const
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:216
void setType(BeamType type)
set beam type
Definition: BeamSpot.h:131
LuminosityBlockNumber_t luminosityBlock() const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
AlcaBeamSpotProducer(const edm::ParameterSet &)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void put(std::unique_ptr< PROD > product)
Put a new product.
Timestamp const & endTime() const
RunNumber_t run() const
void setFitLSRange(int ls0, int ls1)
Definition: BeamFitter.h:120
void resetLSRange()
Definition: BeamFitter.h:55
unsigned long long TimeValue_t
Definition: Timestamp.h:28
void endLuminosityBlockProduce(edm::LuminosityBlock &lumiSeg, const edm::EventSetup &iSetup) final
edm::EventID id() const
Definition: EventBase.h:59
void resetPVFitter()
Definition: BeamFitter.h:69
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) final
void resetCutFlow()
Definition: BeamFitter.h:105
void setRefTime(time_t t0, time_t t1)
Definition: BeamFitter.h:57
std::pair< int, int > getFitLSRange()
Definition: BeamFitter.h:117
TimeValue_t value() const
Definition: Timestamp.h:56
reco::BeamSpot getBeamSpot()
Definition: BeamFitter.h:94
def move(src, dest)
Definition: eostools.py:511
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &iSetup) final
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &iSetup) final
void resetRefTime()
Definition: BeamFitter.h:56