CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
BeamMonitorBx Class Reference

#include <BeamMonitorBx.h>

Inheritance diagram for BeamMonitorBx:
edm::EDAnalyzer edm::EDConsumerBase

Public Types

typedef std::map< BxNum, reco::BeamSpotBeamSpotMapBx
 
typedef int BxNum
 
- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Public Member Functions

 BeamMonitorBx (const edm::ParameterSet &)
 
 ~BeamMonitorBx () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Protected Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c) override
 
void beginJob () override
 
void beginLuminosityBlock (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
 
void beginRun (const edm::Run &r, const edm::EventSetup &c) override
 
void endJob (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
 
void endLuminosityBlock (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
 
void endRun (const edm::Run &r, const edm::EventSetup &c) override
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Private Member Functions

void BookTables (int, std::map< std::string, std::string > &, std::string)
 
void BookTrendHistos (bool, int, std::map< std::string, std::string > &, std::string, const TString &, const TString &)
 
void FillTables (int, int, std::map< std::string, std::string > &, reco::BeamSpot &, std::string)
 
void FillTrendHistos (int, int, std::map< std::string, std::string > &, reco::BeamSpot &, const TString &)
 
void FitAndFill (const edm::LuminosityBlock &lumiSeg, int &, int &, int &)
 
void formatFitTime (char *, const std::time_t &)
 
void weight (BeamSpotMapBx &, const BeamSpotMapBx &)
 
void weight (double &mean, double &meanError, const double &val, const double &valError)
 

Private Attributes

int beginLumiOfBSFit_
 
edm::InputTag bsSrc_
 
unsigned int countBx_
 
int countEvt_
 
int countGoodFit_
 
int countLumi_
 
DQMStoredbe_
 
bool debug_
 
int endLumiOfBSFit_
 
BeamSpotMapBx fbspotMap
 
int firstlumi_
 
int fitNLumi_
 
edm::TimeValue_t ftimestamp
 
std::map< TString, MonitorElement * > hs
 
std::map< TString, MonitorElement * > hst
 
int lastlumi_
 
std::string monitorName_
 
int nextlumi_
 
edm::ParameterSet parameters_
 
bool processed_
 
std::time_t refBStime [2]
 
std::time_t refTime
 
int resetFitNLumi_
 
bool resetHistos_
 
std::time_t startTime
 
BeamFittertheBeamFitter
 
std::time_t tmpTime
 
std::map< std::string, std::string > varMap
 
std::map< std::string, std::string > varMap1
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 

Detailed Description

Definition at line 27 of file BeamMonitorBx.h.

Member Typedef Documentation

Definition at line 33 of file BeamMonitorBx.h.

typedef int BeamMonitorBx::BxNum

Definition at line 32 of file BeamMonitorBx.h.

Constructor & Destructor Documentation

BeamMonitorBx::BeamMonitorBx ( const edm::ParameterSet ps)

Definition at line 45 of file BeamMonitorBx.cc.

References d0_phi_analyzer_cff::BeamFitter, beginLumiOfBSFit_, bsSrc_, edm::EDConsumerBase::consumesCollector(), countGoodFit_, dbe_, endLumiOfBSFit_, firstlumi_, fitNLumi_, edm::ParameterSet::getUntrackedParameter(), lastlumi_, monitorName_, nextlumi_, Utilities::operator, parameters_, processed_, refBStime, resetFitNLumi_, BeamFitter::resetLSRange(), BeamFitter::resetPVFitter(), BeamFitter::resetRefTime(), BeamFitter::resetTrkVector(), and theBeamFitter.

45  :
46  countBx_(0),countEvt_(0),countLumi_(0),resetHistos_(false) {
47 
48  parameters_ = ps;
49  monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","YourSubsystemName");
51  fitNLumi_ = parameters_.getUntrackedParameter<int>("fitEveryNLumi",-1);
52  resetFitNLumi_ = parameters_.getUntrackedParameter<int>("resetEveryNLumi",-1);
53 
55 
56  if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
57 
63 
64  if (fitNLumi_ <= 0) fitNLumi_ = 1;
66  refBStime[0] = refBStime[1] = 0;
67  lastlumi_ = 0;
68  nextlumi_ = 0;
69  firstlumi_ = 0;
70  processed_ = false;
71  countGoodFit_ = 0;
72 }
edm::ParameterSet parameters_
Definition: BeamMonitorBx.h:69
T getUntrackedParameter(std::string const &, T const &) const
void resetTrkVector()
Definition: BeamFitter.h:53
unsigned int countBx_
Definition: BeamMonitorBx.h:80
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::string monitorName_
Definition: BeamMonitorBx.h:70
void resetLSRange()
Definition: BeamFitter.h:55
BeamFitter * theBeamFitter
Definition: BeamMonitorBx.h:78
std::time_t refBStime[2]
Definition: BeamMonitorBx.h:89
edm::InputTag bsSrc_
Definition: BeamMonitorBx.h:71
void resetPVFitter()
Definition: BeamFitter.h:69
DQMStore * dbe_
Definition: BeamMonitorBx.h:77
void resetRefTime()
Definition: BeamFitter.h:56
BeamMonitorBx::~BeamMonitorBx ( )
override

Definition at line 75 of file BeamMonitorBx.cc.

References theBeamFitter.

75  {
76  delete theBeamFitter;
77 }
BeamFitter * theBeamFitter
Definition: BeamMonitorBx.h:78

Member Function Documentation

void BeamMonitorBx::analyze ( const edm::Event e,
const edm::EventSetup c 
)
overrideprotected

Definition at line 152 of file BeamMonitorBx.cc.

References countEvt_, edm::EventBase::luminosityBlock(), nextlumi_, processed_, BeamFitter::readEvent(), and theBeamFitter.

153  {
154  bool readEvent_ = true;
155  const int nthlumi = iEvent.luminosityBlock();
156  if (nthlumi < nextlumi_) {
157  readEvent_ = false;
158  edm::LogWarning("BX|BeamMonitorBx") << "Spilt event from previous lumi section!" << endl;
159  }
160  if (nthlumi > nextlumi_) {
161  readEvent_ = false;
162  edm::LogWarning("BX|BeamMonitorBx") << "Spilt event from next lumi section!!!" << endl;
163  }
164 
165  if (readEvent_) {
166  countEvt_++;
168  processed_ = true;
169  }
170 
171 }
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:216
int iEvent
Definition: GenABIO.cc:230
BeamFitter * theBeamFitter
Definition: BeamMonitorBx.h:78
void BeamMonitorBx::beginJob ( void  )
overrideprotectedvirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 81 of file BeamMonitorBx.cc.

References BookTables(), dbe_, monitorName_, varMap, and varMap1.

81  {
82  varMap["x0_bx"] = "X_{0}";
83  varMap["y0_bx"] = "Y_{0}";
84  varMap["z0_bx"] = "Z_{0}";
85  varMap["sigmaX_bx"] = "#sigma_{X}";
86  varMap["sigmaY_bx"] = "#sigma_{Y}";
87  varMap["sigmaZ_bx"] = "#sigma_{Z}";
88 
89  varMap1["x"] = "X_{0} [cm]";
90  varMap1["y"] = "Y_{0} [cm]";
91  varMap1["z"] = "Z_{0} [cm]";
92  varMap1["sigmaX"] = "#sigma_{X} [cm]";
93  varMap1["sigmaY"] = "#sigma_{Y} [cm]";
94  varMap1["sigmaZ"] = "#sigma_{Z} [cm]";
95 
96  // create and cd into new folder
97  dbe_->setCurrentFolder(monitorName_+"FitBx");
98  // Results of good fit:
99  BookTables(1,varMap,"");
100  //if (resetFitNLumi_ > 0) BookTables(1,varMap,"all");
101 
102  // create and cd into new folders
103  for (std::map<std::string,std::string>::const_iterator varName = varMap1.begin();
104  varName != varMap1.end(); ++varName) {
105  string subDir_ = "FitBx";
106  subDir_ += "/";
107  subDir_ += "All_";
108  subDir_ += varName->first;
109  dbe_->setCurrentFolder(monitorName_+subDir_);
110  }
111  dbe_->setCurrentFolder(monitorName_+"FitBx/All_nPVs");
112 }
std::string monitorName_
Definition: BeamMonitorBx.h:70
void BookTables(int, std::map< std::string, std::string > &, std::string)
DQMStore * dbe_
Definition: BeamMonitorBx.h:77
std::map< std::string, std::string > varMap
Definition: BeamMonitorBx.h:95
std::map< std::string, std::string > varMap1
Definition: BeamMonitorBx.h:96
void BeamMonitorBx::beginLuminosityBlock ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup context 
)
overrideprotected

Definition at line 124 of file BeamMonitorBx.cc.

References beginLumiOfBSFit_, edm::LuminosityBlockBase::beginTime(), countLumi_, FitAndFill(), lastlumi_, edm::LuminosityBlockBase::luminosityBlock(), nextlumi_, processed_, refBStime, and edm::Timestamp::value().

125  {
126  int nthlumi = lumiSeg.luminosityBlock();
127  const edm::TimeValue_t fbegintimestamp = lumiSeg.beginTime().value();
128  const std::time_t ftmptime = fbegintimestamp >> 32;
129 
130  if (countLumi_ == 0) {
131  beginLumiOfBSFit_ = nthlumi;
132  refBStime[0] = ftmptime;
133  }
135 
136  if (nthlumi < nextlumi_) return;
137 
138  if (nthlumi > nextlumi_) {
139  if (countLumi_ != 0 && processed_) {
140  FitAndFill(lumiSeg,lastlumi_,nextlumi_,nthlumi);
141  }
142  nextlumi_ = nthlumi;
143  edm::LogInfo("LS|BX|BeamMonitorBx") << "Next Lumi to Fit: " << nextlumi_ << endl;
144  if (refBStime[0] == 0) refBStime[0] = ftmptime;
145  }
146  countLumi_++;
147  if (processed_) processed_ = false;
148  edm::LogInfo("LS|BX|BeamMonitorBx") << "Begin of Lumi: " << nthlumi << endl;
149 }
void FitAndFill(const edm::LuminosityBlock &lumiSeg, int &, int &, int &)
Timestamp const & beginTime() const
LuminosityBlockNumber_t luminosityBlock() const
unsigned long long TimeValue_t
Definition: Timestamp.h:28
std::time_t refBStime[2]
Definition: BeamMonitorBx.h:89
TimeValue_t value() const
Definition: Timestamp.h:56
void BeamMonitorBx::beginRun ( const edm::Run r,
const edm::EventSetup c 
)
overrideprotected

Definition at line 115 of file BeamMonitorBx.cc.

References edm::RunBase::beginTime(), ftimestamp, refTime, startTime, tmpTime, and edm::Timestamp::value().

115  {
116 
117  ftimestamp = r.beginTime().value();
118  tmpTime = ftimestamp >> 32;
120 
121 }
std::time_t startTime
edm::TimeValue_t ftimestamp
std::time_t tmpTime
std::time_t refTime
Timestamp const & beginTime() const
Definition: RunBase.h:41
TimeValue_t value() const
Definition: Timestamp.h:56
void BeamMonitorBx::BookTables ( int  ,
std::map< std::string, std::string > &  ,
std::string   
)
private

Definition at line 188 of file BeamMonitorBx.cc.

References dbe_, hs, mps_fire::i, and monitorName_.

Referenced by beginJob(), and FitAndFill().

188  {
189  // to rebin histograms when number of bx increases
190  dbe_->cd(monitorName_+"FitBx");
191 
192  for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
193  varName != vMap.end(); ++varName) {
194  string tmpName = varName->first;
195  if (!suffix_.empty()) {
196  tmpName += "_";
197  tmpName += suffix_;
198  }
199  if (dbe_->get(monitorName_+"FitBx/"+tmpName)) {
200  edm::LogInfo("BX|BeamMonitorBx") << "Rebinning " << tmpName << endl;
201  dbe_->removeElement(tmpName);
202  }
203 
204  hs[tmpName]=dbe_->book2D(tmpName,varName->second,3,0,3,nBx,0,nBx);
205  hs[tmpName]->setBinLabel(1,"bx",1);
206  hs[tmpName]->setBinLabel(2,varName->second,1);
207  hs[tmpName]->setBinLabel(3,"#Delta "+varName->second,1);
208  for (int i=0;i<nBx;i++) {
209  hs[tmpName]->setBinLabel(i+1," ",2);
210  }
211  hs[tmpName]->getTH1()->SetOption("text");
212  hs[tmpName]->Reset();
213  }
214 }
std::map< TString, MonitorElement * > hs
Definition: BeamMonitorBx.h:98
std::string monitorName_
Definition: BeamMonitorBx.h:70
DQMStore * dbe_
Definition: BeamMonitorBx.h:77
void BeamMonitorBx::BookTrendHistos ( bool  ,
int  ,
std::map< std::string, std::string > &  ,
std::string  ,
const TString &  ,
const TString &   
)
private

Definition at line 217 of file BeamMonitorBx.cc.

References pyrootRender::da, dbe_, debug_, formatFitTime(), hst, mps_fire::i, monitorName_, AlcaSiPixelAliHarvester0T_cff::options, startTime, trackingPlots::xtitle, and trackingPlots::ytitle.

Referenced by FitAndFill().

218  {
219  int nType_ = 2;
220  if (plotPV) nType_ = 4;
221  std::ostringstream ss;
222  std::ostringstream ss1;
223  ss << setfill ('0') << setw (5) << nBx;
224  ss1 << nBx;
225 
226  for (int i = 0; i < nType_; i++) {
227  for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
228  varName != vMap.end(); ++varName) {
229  string tmpDir_ = subDir_ + "/All_" + varName->first;
230  dbe_->cd(monitorName_+tmpDir_);
231  TString histTitle(varName->first);
232  TString tmpName;
233  if (prefix_ != "") tmpName = prefix_ + "_" + varName->first;
234  if (suffix_ != "") tmpName = tmpName + "_" + suffix_;
235  tmpName = tmpName + "_" + ss.str();
236 
237  TString histName(tmpName);
238  string ytitle(varName->second);
239  string xtitle("");
240  string options("E1");
241  bool createHisto = true;
242  switch(i) {
243  case 1: // BS vs time
244  histName.Insert(histName.Index("_bx_",4),"_time");
245  xtitle = "Time [UTC] [Bx# " + ss1.str() + "]";
246  if (ytitle.find("sigma") == string::npos)
247  histTitle += " coordinate of beam spot vs time (Fit)";
248  else
249  histTitle = histTitle.Insert(5," ") + " of beam spot vs time (Fit)";
250  break;
251  case 2: // PV +/- sigmaPV vs lumi
252  if (ytitle.find("sigma") == string::npos) {
253  histName.Insert(0,"PV");
254  histName.Insert(histName.Index("_bx_",4),"_lumi");
255  histTitle.Insert(0,"Avg. ");
256  histTitle += " position of primary vtx vs lumi";
257  xtitle = "Lumisection [Bx# " + ss1.str() + "]";
258  ytitle.insert(0,"PV");
259  ytitle += " #pm #sigma_{PV";
260  ytitle += varName->first;
261  ytitle += "} (cm)";
262  }
263  else createHisto = false;
264  break;
265  case 3: // PV +/- sigmaPV vs time
266  if (ytitle.find("sigma") == string::npos) {
267  histName.Insert(0,"PV");
268  histName.Insert(histName.Index("_bx_",4),"_time");
269  histTitle.Insert(0,"Avg. ");
270  histTitle += " position of primary vtx vs time";
271  xtitle = "Time [UTC] [Bx# " + ss1.str() + "]";
272  ytitle.insert(0,"PV");
273  ytitle += " #pm #sigma_{PV";
274  ytitle += varName->first;
275  ytitle += "} (cm)";
276  }
277  else createHisto = false;
278  break;
279  default: // BS vs lumi
280  histName.Insert(histName.Index("_bx_",4),"_lumi");
281  xtitle = "Lumisection [Bx# " + ss1.str() + "]";
282  if (ytitle.find("sigma") == string::npos)
283  histTitle += " coordinate of beam spot vs lumi (Fit)";
284  else
285  histTitle = histTitle.Insert(5," ") + " of beam spot vs lumi (Fit)";
286  break;
287  }
288  // check if already exist
289  if (dbe_->get(monitorName_+tmpDir_+"/"+string(histName.Data()))) continue;
290 
291  if (createHisto) {
292  edm::LogInfo("BX|BeamMonitorBx") << "histName = " << histName << "; histTitle = " << histTitle << std::endl;
293  hst[histName] = dbe_->book1D(histName,histTitle,40,0.5,40.5);
294  hst[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
295  hst[histName]->setAxisTitle(xtitle,1);
296  hst[histName]->setAxisTitle(ytitle,2);
297  hst[histName]->getTH1()->SetOption("E1");
298  if (histName.Contains("time")) {
299  hst[histName]->getTH1()->SetBins(3600,0.5,3600+0.5);
300  hst[histName]->setAxisTimeDisplay(1);
301  hst[histName]->setAxisTimeFormat("%H:%M:%S",1);
302 
303  char eventTime[64];
304  formatFitTime(eventTime, startTime);
305  TDatime da(eventTime);
306  if (debug_) {
307  edm::LogInfo("BX|BeamMonitorBx") << "TimeOffset = ";
308  da.Print();
309  }
310  hst[histName]->getTH1()->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
311  }
312  }
313  }//End of variable loop
314  }// End of type loop (lumi, time)
315 
316  // num of PVs(#Bx) per LS
317  dbe_->cd(monitorName_+subDir_ + "/All_nPVs");
318  TString histName = "Trending_nPVs_lumi_bx_" + ss.str();
319  string xtitle = "Lumisection [Bx# " + ss1.str() + "]";
320 
321  hst[histName] = dbe_->book1D(histName,"Number of Good Reconstructed Vertices",40,0.5,40.5);
322  hst[histName]->setAxisTitle(xtitle,1);
323  hst[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
324  hst[histName]->getTH1()->SetOption("E1");
325 
326 }
std::time_t startTime
std::string monitorName_
Definition: BeamMonitorBx.h:70
DQMStore * dbe_
Definition: BeamMonitorBx.h:77
std::map< TString, MonitorElement * > hst
Definition: BeamMonitorBx.h:99
void formatFitTime(char *, const std::time_t &)
void BeamMonitorBx::endJob ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup c 
)
protected

Definition at line 566 of file BeamMonitorBx.cc.

References DEFINE_FWK_MODULE.

567  {
568 }
void BeamMonitorBx::endLuminosityBlock ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup c 
)
overrideprotected

Definition at line 175 of file BeamMonitorBx.cc.

References edm::LuminosityBlockBase::endTime(), edm::LuminosityBlockBase::id(), edm::LuminosityBlockID::luminosityBlock(), nextlumi_, refBStime, tmpTime, and edm::Timestamp::value().

176  {
177  int nthlumi = lumiSeg.id().luminosityBlock();
178  edm::LogInfo("LS|BX|BeamMonitorBx") << "Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
179 
180  if (nthlumi < nextlumi_) return;
181  const edm::TimeValue_t fendtimestamp = lumiSeg.endTime().value();
182  const std::time_t fendtime = fendtimestamp >> 32;
183  tmpTime = refBStime[1] = fendtime;
184 }
LuminosityBlockID id() const
Timestamp const & endTime() const
unsigned long long TimeValue_t
Definition: Timestamp.h:28
std::time_t refBStime[2]
Definition: BeamMonitorBx.h:89
std::time_t tmpTime
LuminosityBlockNumber_t luminosityBlock() const
TimeValue_t value() const
Definition: Timestamp.h:56
void BeamMonitorBx::endRun ( const edm::Run r,
const edm::EventSetup c 
)
overrideprotected

Definition at line 561 of file BeamMonitorBx.cc.

561  {
562 
563 }
void BeamMonitorBx::FillTables ( int  ,
int  ,
std::map< std::string, std::string > &  ,
reco::BeamSpot ,
std::string   
)
private

Definition at line 445 of file BeamMonitorBx.cc.

References reco::BeamSpot::BeamWidthX(), reco::BeamSpot::BeamWidthXError(), reco::BeamSpot::BeamWidthY(), reco::BeamSpot::BeamWidthYError(), hs, reco::BeamSpot::sigmaZ(), reco::BeamSpot::sigmaZ0Error(), reco::BeamSpot::x0(), reco::BeamSpot::x0Error(), reco::BeamSpot::y0(), reco::BeamSpot::y0Error(), reco::BeamSpot::z0(), and reco::BeamSpot::z0Error().

Referenced by FitAndFill().

447  {
448  map<string,pair<double,double> > val_;
449  val_["x0_bx"] = pair<double,double>(bs_.x0(),bs_.x0Error());
450  val_["y0_bx"] = pair<double,double>(bs_.y0(),bs_.y0Error());
451  val_["z0_bx"] = pair<double,double>(bs_.z0(),bs_.z0Error());
452  val_["sigmaX_bx"] = pair<double,double>(bs_.BeamWidthX(),bs_.BeamWidthXError());
453  val_["sigmaY_bx"] = pair<double,double>(bs_.BeamWidthY(),bs_.BeamWidthYError());
454  val_["sigmaZ_bx"] = pair<double,double>(bs_.sigmaZ(),bs_.sigmaZ0Error());
455 
456  for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
457  varName != vMap.end(); ++varName) {
458  TString tmpName = varName->first;
459  if (suffix_ != "") tmpName += TString("_"+suffix_);
460  hs[tmpName]->setBinContent(1,nthbin_,nthbx);
461  hs[tmpName]->setBinContent(2,nthbin_,val_[varName->first].first);
462  hs[tmpName]->setBinContent(3,nthbin_,val_[varName->first].second);
463  }
464 }
std::map< TString, MonitorElement * > hs
Definition: BeamMonitorBx.h:98
void BeamMonitorBx::FillTrendHistos ( int  ,
int  ,
std::map< std::string, std::string > &  ,
reco::BeamSpot ,
const TString &   
)
private

Definition at line 467 of file BeamMonitorBx.cc.

References reco::BeamSpot::BeamWidthX(), reco::BeamSpot::BeamWidthXError(), reco::BeamSpot::BeamWidthY(), reco::BeamSpot::BeamWidthYError(), endLumiOfBSFit_, hst, training_settings::idx, reco::BeamSpot::sigmaZ(), reco::BeamSpot::sigmaZ0Error(), startTime, tmpTime, reco::BeamSpot::x0(), reco::BeamSpot::x0Error(), reco::BeamSpot::y0(), reco::BeamSpot::y0Error(), reco::BeamSpot::z0(), and reco::BeamSpot::z0Error().

Referenced by FitAndFill().

468  {
469  map<TString,pair<double,double> > val_;
470  val_[TString(prefix_+"_x")] = pair<double,double>(bs_.x0(),bs_.x0Error());
471  val_[TString(prefix_+"_y")] = pair<double,double>(bs_.y0(),bs_.y0Error());
472  val_[TString(prefix_+"_z")] = pair<double,double>(bs_.z0(),bs_.z0Error());
473  val_[TString(prefix_+"_sigmaX")] = pair<double,double>(bs_.BeamWidthX(),bs_.BeamWidthXError());
474  val_[TString(prefix_+"_sigmaY")] = pair<double,double>(bs_.BeamWidthY(),bs_.BeamWidthYError());
475  val_[TString(prefix_+"_sigmaZ")] = pair<double,double>(bs_.sigmaZ(),bs_.sigmaZ0Error());
476 
477  std::ostringstream ss;
478  ss << setfill ('0') << setw (5) << nthBx;
479  int ntbin_ = tmpTime - startTime;
480  for (map<TString,MonitorElement*>::iterator itHst = hst.begin();
481  itHst != hst.end(); ++itHst) {
482  if (!(itHst->first.Contains(ss.str()))) continue;
483  if (itHst->first.Contains("nPVs")) continue;
484  edm::LogInfo("BX|BeamMonitorBx") << "Filling histogram: " << itHst->first << endl;
485  if (itHst->first.Contains("time")) {
486  int idx = itHst->first.Index("_time",5);
487  itHst->second->setBinContent(ntbin_,val_[itHst->first(0,idx)].first);
488  itHst->second->setBinError(ntbin_,val_[itHst->first(0,idx)].second);
489  }
490  if (itHst->first.Contains("lumi")) {
491  int idx = itHst->first.Index("_lumi",5);
492  itHst->second->setBinContent(endLumiOfBSFit_,val_[itHst->first(0,idx)].first);
493  itHst->second->setBinError(endLumiOfBSFit_,val_[itHst->first(0,idx)].second);
494  }
495  }
496  TString histName = "Trending_nPVs_lumi_bx_" + ss.str();
497  if (hst[histName])
498  hst[histName]->setBinContent(endLumiOfBSFit_,nPVs_);
499 }
std::time_t startTime
std::time_t tmpTime
std::map< TString, MonitorElement * > hst
Definition: BeamMonitorBx.h:99
void BeamMonitorBx::FitAndFill ( const edm::LuminosityBlock lumiSeg,
int &  lastlumi,
int &  nextlumi,
int &  nthlumi 
)
private

Definition at line 329 of file BeamMonitorBx.cc.

References beginLumiOfBSFit_, BookTables(), BookTrendHistos(), countBx_, countGoodFit_, endLumiOfBSFit_, fbspotMap, FillTables(), FillTrendHistos(), firstlumi_, fitNLumi_, BeamFitter::getBeamSpotMap(), BeamFitter::getFitLSRange(), BeamFitter::getNPVsperBX(), hs, refBStime, refTime, BeamFitter::resetCutFlow(), resetFitNLumi_, resetHistos_, BeamFitter::resetLSRange(), BeamFitter::resetPVFitter(), BeamFitter::resetRefTime(), BeamFitter::resetTrkVector(), BeamFitter::runPVandTrkFitter(), theBeamFitter, tmpTime, varMap, varMap1, and weight().

Referenced by beginLuminosityBlock().

330  {
331  if (nthlumi <= nextlumi) return;
332 
333  int currentlumi = nextlumi;
334  edm::LogInfo("LS|BX|BeamMonitorBx") << "Lumi of the current fit: " << currentlumi << endl;
335  lastlumi = currentlumi;
336  endLumiOfBSFit_ = currentlumi;
337 
338  edm::LogInfo("BX|BeamMonitorBx") << "Time lapsed = " << tmpTime - refTime << std:: endl;
339 
340  if (resetHistos_) {
341  edm::LogInfo("BX|BeamMonitorBx") << "Resetting Histograms" << endl;
343  resetHistos_ = false;
344  }
345 
346  if (fitNLumi_ > 0)
347  if (currentlumi%fitNLumi_!=0) return;
348 
349  std::pair<int,int> fitLS = theBeamFitter->getFitLSRange();
350  edm::LogInfo("LS|BX|BeamMonitorBx") << " [Fitter] Do BeamSpot Fit for LS = " << fitLS.first
351  << " to " << fitLS.second << endl;
352  edm::LogInfo("LS|BX|BeamMonitorBx") << " [BX] Do BeamSpot Fit for LS = " << beginLumiOfBSFit_
353  << " to " << endLumiOfBSFit_ << endl;
354 
355  edm::LogInfo("BX|BeamMonitorBx") << " [BxDebugTime] refBStime[0] = " << refBStime[0]
356  << "; address = " << &refBStime[0] << std::endl;
357  edm::LogInfo("BX|BeamMonitorBx") << " [BxDebugTime] refBStime[1] = " << refBStime[1]
358  << "; address = " << &refBStime[1] << std::endl;
359 
361  countGoodFit_++;
362  edm::LogInfo("BX|BeamMonitorBx") << "Number of good fit = " << countGoodFit_ << endl;
364  std::map<int,int> npvsmap = theBeamFitter->getNPVsperBX();
365  edm::LogInfo("BX|BeamMonitorBx") << "Number of bx = " << bsmap.size() << endl;
366  if (bsmap.empty()) return;
367  if (countBx_ < bsmap.size()) {
368  countBx_ = bsmap.size();
370  BookTables(countBx_,varMap,"all");
371  for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
372  abspot!= bsmap.end(); ++abspot) {
373  int bx = abspot->first;
374  BookTrendHistos(false,bx,varMap1,"FitBx","Trending","bx");
375  }
376  }
377 
378  std::pair<int,int> LSRange = theBeamFitter->getFitLSRange();
379  char tmpTitle[50];
380  sprintf(tmpTitle,"%s %i %s %i %s"," [cm] (LS: ",LSRange.first," to ",LSRange.second,")");
381  for (std::map<std::string,std::string>::const_iterator varName = varMap.begin();
382  varName != varMap.end(); ++varName) {
383  hs[varName->first]->setTitle(varName->second + " " + tmpTitle);
384  hs[varName->first]->Reset();
385  }
386 
387  if (countGoodFit_ == 1)
388  firstlumi_ = LSRange.first;
389 
390  if (resetFitNLumi_ > 0 ) {
391  char tmpTitle1[60];
392  if ( countGoodFit_ > 1)
393  snprintf(tmpTitle1,sizeof(tmpTitle1),"%s %i %s %i %s"," [cm] (LS: ",firstlumi_," to ",LSRange.second,") [weighted average]");
394  else
395  snprintf(tmpTitle1,sizeof(tmpTitle1),"%s","Need at least two fits to calculate weighted average");
396  for (std::map<std::string,std::string>::const_iterator varName = varMap.begin();
397  varName != varMap.end(); ++varName) {
398  TString tmpName = varName->first + "_all";
399  hs[tmpName]->setTitle(varName->second + " " + tmpTitle1);
400  hs[tmpName]->Reset();
401  }
402  }
403 
404  int nthBin = countBx_;
405  for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
406  abspot!= bsmap.end(); ++abspot,nthBin--) {
407  reco::BeamSpot bs = abspot->second;
408  int bx = abspot->first;
409  int nPVs = npvsmap.find(bx)->second;
410  edm::LogInfo("BeamMonitorBx") << "Number of PVs of bx#[" << bx << "] = " << nPVs << endl;
411  // Tables
412  FillTables(bx,nthBin,varMap,bs,"");
413  // Histograms
414  FillTrendHistos(bx,nPVs,varMap1,bs,"Trending");
415  }
416  // Calculate weighted beam spots
417  weight(fbspotMap,bsmap);
418  // Fill the results
419  nthBin = countBx_;
420  if (resetFitNLumi_ > 0 && countGoodFit_ > 1) {
421  for (BeamSpotMapBx::const_iterator abspot = fbspotMap.begin();
422  abspot!= fbspotMap.end(); ++abspot,nthBin--) {
423  reco::BeamSpot bs = abspot->second;
424  int bx = abspot->first;
425  FillTables(bx,nthBin,varMap,bs,"all");
426  }
427  }
428  }
429  // else
430  // edm::LogInfo("BeamMonitorBx") << "Bad Fit!!!" << endl;
431 
432  if (resetFitNLumi_ > 0 && currentlumi%resetFitNLumi_ == 0) {
433  edm::LogInfo("LS|BX|BeamMonitorBx") << "Reset track collection for beam fit!!!" <<endl;
434  resetHistos_ = true;
439  beginLumiOfBSFit_ = 0;
440  refBStime[0] = 0;
441  }
442 }
void FillTrendHistos(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, const TString &)
const std::map< int, int > & getNPVsperBX()
Definition: BeamFitter.h:132
void FillTables(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, std::string)
bool runPVandTrkFitter()
Definition: BeamFitter.cc:398
void resetTrkVector()
Definition: BeamFitter.h:53
std::map< TString, MonitorElement * > hs
Definition: BeamMonitorBx.h:98
BeamSpotMapBx fbspotMap
Definition: BeamMonitorBx.h:94
std::map< int, reco::BeamSpot > getBeamSpotMap()
Definition: BeamFitter.h:95
unsigned int countBx_
Definition: BeamMonitorBx.h:80
void resetLSRange()
Definition: BeamFitter.h:55
BeamFitter * theBeamFitter
Definition: BeamMonitorBx.h:78
std::time_t refBStime[2]
Definition: BeamMonitorBx.h:89
std::time_t tmpTime
void weight(BeamSpotMapBx &, const BeamSpotMapBx &)
std::time_t refTime
void BookTables(int, std::map< std::string, std::string > &, std::string)
void resetPVFitter()
Definition: BeamFitter.h:69
void resetCutFlow()
Definition: BeamFitter.h:105
std::map< std::string, std::string > varMap
Definition: BeamMonitorBx.h:95
void BookTrendHistos(bool, int, std::map< std::string, std::string > &, std::string, const TString &, const TString &)
std::map< std::string, std::string > varMap1
Definition: BeamMonitorBx.h:96
std::pair< int, int > getFitLSRange()
Definition: BeamFitter.h:117
std::map< BxNum, reco::BeamSpot > BeamSpotMapBx
Definition: BeamMonitorBx.h:33
void resetRefTime()
Definition: BeamFitter.h:56
void BeamMonitorBx::formatFitTime ( char *  ,
const std::time_t &   
)
private

Definition at line 28 of file BeamMonitorBx.cc.

References b, CEST, and plotBeamSpotDB::ptm.

Referenced by BookTrendHistos().

28  {
29 #define CET (+1)
30 #define CEST (+2)
31 
32  tm * ptm;
33  ptm = gmtime ( &t );
34  sprintf( ts, "%4d-%02d-%02d %02d:%02d:%02d", ptm->tm_year,ptm->tm_mon+1,ptm->tm_mday,(ptm->tm_hour+CEST)%24, ptm->tm_min, ptm->tm_sec);
35 
36 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE
37  unsigned int b = strlen(ts);
38  while (ts[--b] == ' ') {ts[b] = 0;}
39 #endif
40 }
#define CEST
double b
Definition: hdecay.h:120
void BeamMonitorBx::weight ( BeamSpotMapBx weightedMap_,
const BeamSpotMapBx newMap_ 
)
private

Definition at line 502 of file BeamMonitorBx.cc.

References reco::BeamSpot::BeamWidthX(), reco::BeamSpot::BeamWidthXError(), reco::BeamSpot::BeamWidthY(), reco::BeamSpot::BeamWidthYError(), reco::BeamSpot::dxdz(), reco::BeamSpot::dxdzError(), reco::BeamSpot::dydz(), reco::BeamSpot::dydzError(), relativeConstraints::error, mps_fire::i, reco::BeamSpot::setBeamWidthY(), reco::BeamSpot::sigmaZ(), reco::BeamSpot::sigmaZ0Error(), reco::BeamSpot::Tracker, reco::BeamSpot::Unknown, reco::BeamSpot::x0(), reco::BeamSpot::x0Error(), reco::BeamSpot::y0(), reco::BeamSpot::y0Error(), reco::BeamSpot::z0(), and reco::BeamSpot::z0Error().

Referenced by FitAndFill().

502  {
503  for (BeamSpotMapBx::const_iterator it = newMap_.begin();
504  it != newMap_.end(); ++it) {
505  if (weightedMap_.find(it->first) == weightedMap_.end() || (it->second.type() != 2)) {
506  weightedMap_[it->first] = it->second;
507  continue;
508  }
509 
510  BeamSpot obs = weightedMap_[it->first];
511  double val_[8] = { obs.x0(),obs.y0(),obs.z0(),obs.sigmaZ(),
512  obs.dxdz(),obs.dydz(),obs.BeamWidthX(),obs.BeamWidthY()};
513  double valErr_[8] = { obs.x0Error(),obs.y0Error(),obs.z0Error(),
514  obs.sigmaZ0Error(),obs.dxdzError(),obs.dydzError(),
515  obs.BeamWidthXError(),obs.BeamWidthYError()};
516 
518  weight(val_[0], valErr_[0], it->second.x0() , it->second.x0Error());
519  weight(val_[1], valErr_[1], it->second.y0() , it->second.y0Error());
520  weight(val_[2], valErr_[2], it->second.z0() , it->second.z0Error());
521  weight(val_[3], valErr_[3], it->second.sigmaZ() , it->second.sigmaZ0Error());
522  weight(val_[4], valErr_[4], it->second.dxdz() , it->second.dxdzError());
523  weight(val_[5], valErr_[5], it->second.dydz() , it->second.dydzError());
524  weight(val_[6], valErr_[6], it->second.BeamWidthX(), it->second.BeamWidthXError());
525  weight(val_[7], valErr_[7], it->second.BeamWidthY(), it->second.BeamWidthYError());
526  if(it->second.type() == reco::BeamSpot::Tracker){
528  }
529 
530  reco::BeamSpot::Point bsPosition(val_[0],val_[1],val_[2]);
532  for (int i=0;i<7;++i) {
533  error(i,i) = valErr_[i]*valErr_[i];
534  }
535  reco::BeamSpot weightedBeamSpot(bsPosition,val_[3],val_[4],val_[5],val_[6],error,type);
536  weightedBeamSpot.setBeamWidthY(val_[7]);
537  LogInfo("BX|BeamMonitorBx")
538  << weightedBeamSpot
539  << endl;
540  weightedMap_.erase(it->first);
541  weightedMap_[it->first] = weightedBeamSpot;
542  }
543 }
type
Definition: HCALResponse.h:21
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:31
double z0() const
z coordinate
Definition: BeamSpot.h:68
BeamType
beam spot flags
Definition: BeamSpot.h:26
double sigmaZ0Error() const
error on sigma z
Definition: BeamSpot.h:96
double dydzError() const
error on dydz
Definition: BeamSpot.h:100
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
double dydz() const
dydz slope
Definition: BeamSpot.h:84
double dxdzError() const
error on dxdz
Definition: BeamSpot.h:98
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
Definition: BeamSpot.h:105
double BeamWidthXError() const
error on beam width X, assume error in X = Y
Definition: BeamSpot.h:103
double z0Error() const
error on z
Definition: BeamSpot.h:94
double dxdz() const
dxdz slope
Definition: BeamSpot.h:82
double x0Error() const
error on x
Definition: BeamSpot.h:90
double y0Error() const
error on y
Definition: BeamSpot.h:92
void weight(BeamSpotMapBx &, const BeamSpotMapBx &)
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
double y0() const
y coordinate
Definition: BeamSpot.h:66
double x0() const
x coordinate
Definition: BeamSpot.h:64
void BeamMonitorBx::weight ( double &  mean,
double &  meanError,
const double &  val,
const double &  valError 
)
private

Definition at line 546 of file BeamMonitorBx.cc.

References MillePedeFileConverter_cfg::e, and mathSSE::sqrt().

546  {
547  double tmpError = 0;
548  if (meanError < 1e-8){
549  tmpError = 1/(valError*valError);
550  mean = val*tmpError;
551  }
552  else{
553  tmpError = 1/(meanError*meanError) + 1/(valError*valError);
554  mean = mean/(meanError*meanError) + val/(valError*valError);
555  }
556  mean = mean/tmpError;
557  meanError = std::sqrt(1/tmpError);
558 }
T sqrt(T t)
Definition: SSEVec.h:18

Member Data Documentation

int BeamMonitorBx::beginLumiOfBSFit_
private

Definition at line 83 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), beginLuminosityBlock(), and FitAndFill().

edm::InputTag BeamMonitorBx::bsSrc_
private

Definition at line 71 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx().

unsigned int BeamMonitorBx::countBx_
private

Definition at line 80 of file BeamMonitorBx.h.

Referenced by FitAndFill().

int BeamMonitorBx::countEvt_
private

Definition at line 81 of file BeamMonitorBx.h.

Referenced by analyze().

int BeamMonitorBx::countGoodFit_
private

Definition at line 88 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), and FitAndFill().

int BeamMonitorBx::countLumi_
private

Definition at line 82 of file BeamMonitorBx.h.

Referenced by beginLuminosityBlock().

DQMStore* BeamMonitorBx::dbe_
private

Definition at line 77 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), beginJob(), BookTables(), and BookTrendHistos().

bool BeamMonitorBx::debug_
private

Definition at line 75 of file BeamMonitorBx.h.

Referenced by BookTrendHistos().

int BeamMonitorBx::endLumiOfBSFit_
private

Definition at line 84 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), FillTrendHistos(), and FitAndFill().

BeamSpotMapBx BeamMonitorBx::fbspotMap
private

Definition at line 94 of file BeamMonitorBx.h.

Referenced by FitAndFill().

int BeamMonitorBx::firstlumi_
private

Definition at line 87 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), and FitAndFill().

int BeamMonitorBx::fitNLumi_
private

Definition at line 73 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), and FitAndFill().

edm::TimeValue_t BeamMonitorBx::ftimestamp
private

Definition at line 108 of file BeamMonitorBx.h.

Referenced by beginRun().

std::map<TString, MonitorElement*> BeamMonitorBx::hs
private

Definition at line 98 of file BeamMonitorBx.h.

Referenced by BookTables(), FillTables(), and FitAndFill().

std::map<TString, MonitorElement*> BeamMonitorBx::hst
private

Definition at line 99 of file BeamMonitorBx.h.

Referenced by BookTrendHistos(), and FillTrendHistos().

int BeamMonitorBx::lastlumi_
private

Definition at line 85 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), and beginLuminosityBlock().

std::string BeamMonitorBx::monitorName_
private

Definition at line 70 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), beginJob(), BookTables(), and BookTrendHistos().

int BeamMonitorBx::nextlumi_
private

Definition at line 86 of file BeamMonitorBx.h.

Referenced by analyze(), BeamMonitorBx(), beginLuminosityBlock(), and endLuminosityBlock().

edm::ParameterSet BeamMonitorBx::parameters_
private
bool BeamMonitorBx::processed_
private

Definition at line 92 of file BeamMonitorBx.h.

Referenced by analyze(), BeamMonitorBx(), and beginLuminosityBlock().

std::time_t BeamMonitorBx::refBStime[2]
private
std::time_t BeamMonitorBx::refTime
private

Definition at line 106 of file BeamMonitorBx.h.

Referenced by beginRun(), and FitAndFill().

int BeamMonitorBx::resetFitNLumi_
private

Definition at line 74 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), and FitAndFill().

bool BeamMonitorBx::resetHistos_
private

Definition at line 91 of file BeamMonitorBx.h.

Referenced by FitAndFill().

std::time_t BeamMonitorBx::startTime
private

Definition at line 107 of file BeamMonitorBx.h.

Referenced by beginRun(), BookTrendHistos(), and FillTrendHistos().

BeamFitter* BeamMonitorBx::theBeamFitter
private

Definition at line 78 of file BeamMonitorBx.h.

Referenced by analyze(), BeamMonitorBx(), FitAndFill(), and ~BeamMonitorBx().

std::time_t BeamMonitorBx::tmpTime
private

Definition at line 105 of file BeamMonitorBx.h.

Referenced by beginRun(), endLuminosityBlock(), FillTrendHistos(), and FitAndFill().

std::map<std::string, std::string> BeamMonitorBx::varMap
private

Definition at line 95 of file BeamMonitorBx.h.

Referenced by beginJob(), and FitAndFill().

std::map<std::string, std::string> BeamMonitorBx::varMap1
private

Definition at line 96 of file BeamMonitorBx.h.

Referenced by beginJob(), and FitAndFill().