32 static char ts[] =
"yyyy-Mm-dd hh:mm:ss";
35 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);
37 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE
38 unsigned int b = strlen(ts);
39 while (ts[--b] ==
' ') {ts[
b] = 0;}
49 countBx_(0),countEvt_(0),countLumi_(0),resetHistos_(
false) {
67 if (fitNLumi_ <= 0) fitNLumi_ = 1;
88 varMap[
"sigmaX_bx"] =
"#sigma_{X}";
89 varMap[
"sigmaY_bx"] =
"#sigma_{Y}";
90 varMap[
"sigmaZ_bx"] =
"#sigma_{Z}";
95 varMap1[
"sigmaX"] =
"#sigma_{X} [cm]";
96 varMap1[
"sigmaY"] =
"#sigma_{Y} [cm]";
97 varMap1[
"sigmaZ"] =
"#sigma_{Z} [cm]";
106 for (std::map<std::string,std::string>::const_iterator varName =
varMap1.begin();
107 varName !=
varMap1.end(); ++varName) {
108 string subDir_ =
"FitBx";
111 subDir_ += varName->first;
131 const std::time_t ftmptime = fbegintimestamp >> 32;
151 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Begin of Lumi: " << nthlumi << endl;
157 bool readEvent_ =
true;
161 edm::LogWarning(
"BX|BeamMonitorBx") <<
"Spilt event from previous lumi section!" << endl;
165 edm::LogWarning(
"BX|BeamMonitorBx") <<
"Spilt event from next lumi section!!!" << endl;
181 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
185 const std::time_t fendtime = fendtimestamp >> 32;
195 for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
196 varName != vMap.end(); ++varName) {
197 string tmpName = varName->first;
198 if (!suffix_.empty()) {
203 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Rebinning " << tmpName << endl;
207 hs[tmpName]=
dbe_->
book2D(tmpName,varName->second,3,0,3,nBx,0,nBx);
208 hs[tmpName]->setBinLabel(1,
"bx",1);
209 hs[tmpName]->setBinLabel(2,varName->second,1);
210 hs[tmpName]->setBinLabel(3,
"#Delta "+varName->second,1);
211 for (
int i=0;
i<nBx;
i++) {
212 hs[tmpName]->setBinLabel(
i+1,
" ",2);
214 hs[tmpName]->getTH1()->SetOption(
"text");
215 hs[tmpName]->Reset();
221 string subDir_,
const TString& prefix_,
const TString& suffix_) {
223 if (plotPV) nType_ = 4;
224 std::ostringstream ss;
225 std::ostringstream ss1;
226 ss << setfill (
'0') << setw (5) << nBx;
229 for (
int i = 0;
i < nType_;
i++) {
230 for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
231 varName != vMap.end(); ++varName) {
232 string tmpDir_ = subDir_ +
"/All_" + varName->first;
234 TString histTitle(varName->first);
236 if (prefix_ !=
"") tmpName = prefix_ +
"_" + varName->first;
237 if (suffix_ !=
"") tmpName = tmpName +
"_" + suffix_;
238 tmpName = tmpName +
"_" + ss.str();
240 TString histName(tmpName);
241 string ytitle(varName->second);
244 bool createHisto =
true;
247 histName.Insert(histName.Index(
"_bx_",4),
"_time");
248 xtitle =
"Time [UTC] [Bx# " + ss1.str() +
"]";
249 if (ytitle.find(
"sigma") == string::npos)
250 histTitle +=
" coordinate of beam spot vs time (Fit)";
252 histTitle = histTitle.Insert(5,
" ") +
" of beam spot vs time (Fit)";
255 if (ytitle.find(
"sigma") == string::npos) {
256 histName.Insert(0,
"PV");
257 histName.Insert(histName.Index(
"_bx_",4),
"_lumi");
258 histTitle.Insert(0,
"Avg. ");
259 histTitle +=
" position of primary vtx vs lumi";
260 xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
261 ytitle.insert(0,
"PV");
262 ytitle +=
" #pm #sigma_{PV";
263 ytitle += varName->first;
266 else createHisto =
false;
269 if (ytitle.find(
"sigma") == string::npos) {
270 histName.Insert(0,
"PV");
271 histName.Insert(histName.Index(
"_bx_",4),
"_time");
272 histTitle.Insert(0,
"Avg. ");
273 histTitle +=
" position of primary vtx vs time";
274 xtitle =
"Time [UTC] [Bx# " + ss1.str() +
"]";
275 ytitle.insert(0,
"PV");
276 ytitle +=
" #pm #sigma_{PV";
277 ytitle += varName->first;
280 else createHisto =
false;
283 histName.Insert(histName.Index(
"_bx_",4),
"_lumi");
284 xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
285 if (ytitle.find(
"sigma") == string::npos)
286 histTitle +=
" coordinate of beam spot vs lumi (Fit)";
288 histTitle = histTitle.Insert(5,
" ") +
" of beam spot vs lumi (Fit)";
295 edm::LogInfo(
"BX|BeamMonitorBx") <<
"histName = " << histName <<
"; histTitle = " << histTitle << std::endl;
296 hst[histName] =
dbe_->
book1D(histName,histTitle,40,0.5,40.5);
297 hst[histName]->getTH1()->SetBit(TH1::kCanRebin);
298 hst[histName]->setAxisTitle(xtitle,1);
299 hst[histName]->setAxisTitle(ytitle,2);
300 hst[histName]->getTH1()->SetOption(
"E1");
301 if (histName.Contains(
"time")) {
302 hst[histName]->getTH1()->SetBins(3600,0.5,3600+0.5);
303 hst[histName]->setAxisTimeDisplay(1);
304 hst[histName]->setAxisTimeFormat(
"%H:%M:%S",1);
306 TDatime
da(eventTime);
311 hst[histName]->getTH1()->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
319 TString histName =
"Trending_nPVs_lumi_bx_" + ss.str();
320 string xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
322 hst[histName] =
dbe_->
book1D(histName,
"Number of Good Reconstructed Vertices",40,0.5,40.5);
323 hst[histName]->setAxisTitle(xtitle,1);
324 hst[histName]->getTH1()->SetBit(TH1::kCanRebin);
325 hst[histName]->getTH1()->SetOption(
"E1");
331 int &lastlumi,
int &nextlumi,
int &nthlumi){
332 if (nthlumi <= nextlumi)
return;
334 int currentlumi = nextlumi;
335 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Lumi of the current fit: " << currentlumi << endl;
336 lastlumi = currentlumi;
342 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Resetting Histograms" << endl;
351 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
" [Fitter] Do BeamSpot Fit for LS = " << fitLS.first
352 <<
" to " << fitLS.second << endl;
357 <<
"; address = " << &
refBStime[0] << std::endl;
359 <<
"; address = " << &
refBStime[1] << std::endl;
366 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Number of bx = " << bsmap.size() << endl;
367 if (bsmap.size() == 0)
return;
372 for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
373 abspot!= bsmap.end(); ++abspot) {
374 int bx = abspot->first;
381 sprintf(tmpTitle,
"%s %i %s %i %s",
" [cm] (LS: ",LSRange.first,
" to ",LSRange.second,
")");
382 for (std::map<std::string,std::string>::const_iterator varName =
varMap.begin();
383 varName !=
varMap.end(); ++varName) {
384 hs[varName->first]->setTitle(varName->second +
" " + tmpTitle);
385 hs[varName->first]->Reset();
394 sprintf(tmpTitle1,
"%s %i %s %i %s",
" [cm] (LS: ",
firstlumi_,
" to ",LSRange.second,
") [weighted average]");
396 sprintf(tmpTitle1,
"%s",
"Need at least two fits to calculate weighted average");
397 for (std::map<std::string,std::string>::const_iterator varName =
varMap.begin();
398 varName !=
varMap.end(); ++varName) {
399 TString tmpName = varName->first +
"_all";
400 hs[tmpName]->setTitle(varName->second +
" " + tmpTitle1);
401 hs[tmpName]->Reset();
406 for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
407 abspot!= bsmap.end(); ++abspot,nthBin--) {
409 int bx = abspot->first;
410 int nPVs = npvsmap.find(bx)->second;
411 edm::LogInfo(
"BeamMonitorBx") <<
"Number of PVs of bx#[" << bx <<
"] = " << nPVs << endl;
422 for (BeamSpotMapBx::const_iterator abspot =
fbspotMap.begin();
423 abspot!=
fbspotMap.end(); ++abspot,nthBin--) {
425 int bx = abspot->first;
434 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Reset track collection for beam fit!!!" <<endl;
447 map<string,string>&vMap,
449 map<string,pair<double,double> > val_;
450 val_[
"x0_bx"] = pair<double,double>(bs_.
x0(),bs_.
x0Error());
451 val_[
"y0_bx"] = pair<double,double>(bs_.
y0(),bs_.
y0Error());
452 val_[
"z0_bx"] = pair<double,double>(bs_.
z0(),bs_.
z0Error());
457 for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
458 varName != vMap.end(); ++varName) {
459 TString tmpName = varName->first;
460 if (suffix_ !=
"") tmpName += TString(
"_"+suffix_);
461 hs[tmpName]->setBinContent(1,nthbin_,nthbx);
462 hs[tmpName]->setBinContent(2,nthbin_,val_[varName->first].first);
463 hs[tmpName]->setBinContent(3,nthbin_,val_[varName->first].second);
470 map<TString,pair<double,double> > val_;
471 val_[TString(prefix_+
"_x")] = pair<double,double>(bs_.
x0(),bs_.
x0Error());
472 val_[TString(prefix_+
"_y")] = pair<double,double>(bs_.
y0(),bs_.
y0Error());
473 val_[TString(prefix_+
"_z")] = pair<double,double>(bs_.
z0(),bs_.
z0Error());
476 val_[TString(prefix_+
"_sigmaZ")] = pair<double,double>(bs_.
sigmaZ(),bs_.
sigmaZ0Error());
478 std::ostringstream ss;
479 ss << setfill (
'0') << setw (5) << nthBx;
481 for (map<TString,MonitorElement*>::iterator itHst =
hst.begin();
482 itHst !=
hst.end(); ++itHst) {
483 if (!(itHst->first.Contains(ss.str())))
continue;
484 if (itHst->first.Contains(
"nPVs"))
continue;
485 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Filling histogram: " << itHst->first << endl;
486 if (itHst->first.Contains(
"time")) {
487 int idx = itHst->first.Index(
"_time",5);
488 itHst->second->setBinContent(ntbin_,val_[itHst->first(0,idx)].first);
489 itHst->second->setBinError(ntbin_,val_[itHst->first(0,idx)].second);
491 if (itHst->first.Contains(
"lumi")) {
492 int idx = itHst->first.Index(
"_lumi",5);
493 itHst->second->setBinContent(
endLumiOfBSFit_,val_[itHst->first(0,idx)].first);
494 itHst->second->setBinError(
endLumiOfBSFit_,val_[itHst->first(0,idx)].second);
497 TString histName =
"Trending_nPVs_lumi_bx_" + ss.str();
504 for (BeamSpotMapBx::const_iterator it = newMap_.begin();
505 it != newMap_.end(); ++it) {
506 if (weightedMap_.find(it->first) == weightedMap_.end() || (it->second.type() != 2)) {
507 weightedMap_[it->first] = it->second;
511 BeamSpot obs = weightedMap_[it->first];
512 double val_[8] = { obs.
x0(),obs.
y0(),obs.
z0(),obs.
sigmaZ(),
519 weight(val_[0], valErr_[0], it->second.x0() , it->second.x0Error());
520 weight(val_[1], valErr_[1], it->second.y0() , it->second.y0Error());
521 weight(val_[2], valErr_[2], it->second.z0() , it->second.z0Error());
522 weight(val_[3], valErr_[3], it->second.sigmaZ() , it->second.sigmaZ0Error());
523 weight(val_[4], valErr_[4], it->second.dxdz() , it->second.dxdzError());
524 weight(val_[5], valErr_[5], it->second.dydz() , it->second.dydzError());
525 weight(val_[6], valErr_[6], it->second.BeamWidthX(), it->second.BeamWidthXError());
526 weight(val_[7], valErr_[7], it->second.BeamWidthY(), it->second.BeamWidthYError());
533 for (
int i=0;
i<7;++
i) {
536 reco::BeamSpot weightedBeamSpot(bsPosition,val_[3],val_[4],val_[5],val_[6],error,type);
541 weightedMap_.erase(it->first);
542 weightedMap_[it->first] = weightedBeamSpot;
549 if (meanError < 1
e-8){
550 tmpError = 1/(valError*valError);
554 tmpError = 1/(meanError*meanError) + 1/(valError*valError);
555 mean = mean/(meanError*meanError) + val/(valError*valError);
557 mean = mean/tmpError;
void beginRun(const edm::Run &r, const edm::EventSetup &c)
edm::ParameterSet parameters_
LuminosityBlockID id() const
void FillTrendHistos(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, const TString &)
math::Error< dimension >::type CovarianceMatrix
const char * formatFitTime(const std::time_t &)
double z0() const
z coordinate
T getUntrackedParameter(std::string const &, T const &) const
const std::map< int, int > & getNPVsperBX()
void FillTables(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, std::string)
double sigmaZ0Error() const
error on sigma z
BeamMonitorBx(const edm::ParameterSet &)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
double dydzError() const
error on dydz
void cd(void)
go to top directory (ie. root)
#define DEFINE_FWK_MODULE(type)
void FitAndFill(const edm::LuminosityBlock &lumiSeg, int &, int &, int &)
edm::LuminosityBlockNumber_t luminosityBlock() const
math::XYZPoint Point
point in the space
Timestamp const & beginTime() const
std::map< TString, MonitorElement * > hs
void readEvent(const edm::Event &iEvent)
LuminosityBlockNumber_t luminosityBlock() const
std::map< int, reco::BeamSpot > getBeamSpotMap()
double dydz() const
dydz slope
void endRun(const edm::Run &r, const edm::EventSetup &c)
void setBeamWidthY(double v)
double dxdzError() const
error on dxdz
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
edm::TimeValue_t ftimestamp
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Timestamp const & endTime() const
void removeElement(const std::string &name)
double BeamWidthX() const
beam width X
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
double BeamWidthXError() const
error on beam width X, assume error in X = Y
BeamFitter * theBeamFitter
double z0Error() const
error on z
unsigned long long TimeValue_t
double dxdz() const
dxdz slope
double x0Error() const
error on x
double y0Error() const
error on y
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
void weight(BeamSpotMapBx &, const BeamSpotMapBx &)
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
double sigmaZ() const
sigma z
double BeamWidthY() const
beam width Y
LuminosityBlockNumber_t luminosityBlock() const
Timestamp const & beginTime() const
void BookTables(int, std::map< std::string, std::string > &, std::string)
double y0() const
y coordinate
std::map< std::string, std::string > varMap
void BookTrendHistos(bool, int, std::map< std::string, std::string > &, std::string, const TString &, const TString &)
std::map< std::string, std::string > varMap1
std::map< TString, MonitorElement * > hst
volatile std::atomic< bool > shutdown_flag false
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
std::pair< int, int > getFitLSRange()
TimeValue_t value() const
void analyze(const edm::Event &e, const edm::EventSetup &c)
void setCurrentFolder(const std::string &fullpath)
std::map< BxNum, reco::BeamSpot > BeamSpotMapBx
double x0() const
x coordinate