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 
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
bool runPVandTrkFitter()
Definition: BeamFitter.cc:449
void setRun(int run)
Definition: BeamFitter.h:119
std::vector< BSTrkParameters > getBSvector()
Definition: BeamFitter.h:95
void resetTrkVector()
Definition: BeamFitter.h:58
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:261
int iEvent
Definition: GenABIO.cc:224
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.
void setFitLSRange(int ls0, int ls1)
Definition: BeamFitter.h:115
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void resetLSRange()
Definition: BeamFitter.h:60
unsigned long long TimeValue_t
Definition: Timestamp.h:21
Log< level::Info, false > LogInfo
TimeValue_t value() const
Definition: Timestamp.h:38
Timestamp const & beginTime() const
Timestamp const & endTime() const
void endLuminosityBlockProduce(edm::LuminosityBlock &lumiSeg, const edm::EventSetup &iSetup) final
void resetPVFitter()
Definition: BeamFitter.h:72
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) final
void resetCutFlow()
Definition: BeamFitter.h:104
std::pair< int, int > getFitLSRange()
Definition: BeamFitter.h:114
void setRefTime(time_t t0, time_t t1)
Definition: BeamFitter.h:62
LuminosityBlockNumber_t luminosityBlock() const
reco::BeamSpot getBeamSpot()
Definition: BeamFitter.h:93
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:61