CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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++;
66  theBeamFitter->readEvent(iEvent);
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 
110  bs = theBeamFitter->getBeamSpot();
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
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 
RunNumber_t run() const
Definition: EventID.h:38
bool runPVandTrkFitter()
Definition: BeamFitter.cc:449
void setRun(int run)
Definition: BeamFitter.h:119
std::vector< BSTrkParameters > getBSvector()
Definition: BeamFitter.h:95
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void resetTrkVector()
Definition: BeamFitter.h:58
Timestamp const & beginTime() const
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:261
tuple result
Definition: mps_fire.py:311
void setType(BeamType type)
set beam type
Definition: BeamSpot.h:124
LuminosityBlockNumber_t luminosityBlock() const
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.
Timestamp const & endTime() const
def move
Definition: eostools.py:511
RunNumber_t run() const
void setFitLSRange(int ls0, int ls1)
Definition: BeamFitter.h:115
void resetLSRange()
Definition: BeamFitter.h:60
unsigned long long TimeValue_t
Definition: Timestamp.h:28
Log< level::Info, false > LogInfo
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void endLuminosityBlockProduce(edm::LuminosityBlock &lumiSeg, const edm::EventSetup &iSetup) final
edm::EventID id() const
Definition: EventBase.h:59
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
TimeValue_t value() const
Definition: Timestamp.h:45
reco::BeamSpot getBeamSpot()
Definition: BeamFitter.h:93
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