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);
36 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE
37 unsigned int b = strlen(ts);
38 while (ts[--b] ==
' ') {ts[
b] = 0;}
46 countBx_(0),countEvt_(0),countLumi_(0),resetHistos_(
false) {
64 if (fitNLumi_ <= 0) fitNLumi_ = 1;
85 varMap[
"sigmaX_bx"] =
"#sigma_{X}";
86 varMap[
"sigmaY_bx"] =
"#sigma_{Y}";
87 varMap[
"sigmaZ_bx"] =
"#sigma_{Z}";
92 varMap1[
"sigmaX"] =
"#sigma_{X} [cm]";
93 varMap1[
"sigmaY"] =
"#sigma_{Y} [cm]";
94 varMap1[
"sigmaZ"] =
"#sigma_{Z} [cm]";
103 for (std::map<std::string,std::string>::const_iterator varName =
varMap1.begin();
104 varName !=
varMap1.end(); ++varName) {
105 string subDir_ =
"FitBx";
108 subDir_ += varName->first;
128 const std::time_t ftmptime = fbegintimestamp >> 32;
148 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Begin of Lumi: " << nthlumi << endl;
154 bool readEvent_ =
true;
158 edm::LogWarning(
"BX|BeamMonitorBx") <<
"Spilt event from previous lumi section!" << endl;
162 edm::LogWarning(
"BX|BeamMonitorBx") <<
"Spilt event from next lumi section!!!" << endl;
178 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
182 const std::time_t fendtime = fendtimestamp >> 32;
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()) {
200 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Rebinning " << tmpName << endl;
201 dbe_->removeElement(tmpName);
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);
211 hs[tmpName]->getTH1()->SetOption(
"text");
212 hs[tmpName]->Reset();
218 string subDir_,
const TString& prefix_,
const TString& suffix_) {
220 if (plotPV) nType_ = 4;
221 std::ostringstream
ss;
222 std::ostringstream ss1;
223 ss << setfill (
'0') << setw (5) << nBx;
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;
231 TString histTitle(varName->first);
233 if (prefix_ !=
"") tmpName = prefix_ +
"_" + varName->first;
234 if (suffix_ !=
"") tmpName = tmpName +
"_" + suffix_;
235 tmpName = tmpName +
"_" + ss.str();
237 TString histName(tmpName);
238 string ytitle(varName->second);
241 bool createHisto =
true;
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)";
249 histTitle = histTitle.Insert(5,
" ") +
" of beam spot vs time (Fit)";
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;
263 else createHisto =
false;
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;
277 else createHisto =
false;
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)";
285 histTitle = histTitle.Insert(5,
" ") +
" of beam spot vs lumi (Fit)";
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);
305 TDatime
da(eventTime);
310 hst[histName]->getTH1()->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
318 TString histName =
"Trending_nPVs_lumi_bx_" + ss.str();
319 string xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
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");
330 int &lastlumi,
int &nextlumi,
int &nthlumi){
331 if (nthlumi <= nextlumi)
return;
333 int currentlumi = nextlumi;
334 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Lumi of the current fit: " << currentlumi << endl;
335 lastlumi = currentlumi;
341 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Resetting Histograms" << endl;
350 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
" [Fitter] Do BeamSpot Fit for LS = " << fitLS.first
351 <<
" to " << fitLS.second << endl;
356 <<
"; address = " << &
refBStime[0] << std::endl;
358 <<
"; address = " << &
refBStime[1] << std::endl;
365 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Number of bx = " << bsmap.size() << endl;
366 if (bsmap.size() == 0)
return;
371 for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
372 abspot!= bsmap.end(); ++abspot) {
373 int bx = abspot->first;
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();
393 sprintf(tmpTitle1,
"%s %i %s %i %s",
" [cm] (LS: ",
firstlumi_,
" to ",LSRange.second,
") [weighted average]");
395 sprintf(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();
405 for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
406 abspot!= bsmap.end(); ++abspot,nthBin--) {
408 int bx = abspot->first;
409 int nPVs = npvsmap.find(bx)->second;
410 edm::LogInfo(
"BeamMonitorBx") <<
"Number of PVs of bx#[" << bx <<
"] = " << nPVs << endl;
421 for (BeamSpotMapBx::const_iterator abspot =
fbspotMap.begin();
422 abspot!=
fbspotMap.end(); ++abspot,nthBin--) {
424 int bx = abspot->first;
433 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Reset track collection for beam fit!!!" <<endl;
446 map<string,string>&vMap,
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());
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);
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());
475 val_[TString(prefix_+
"_sigmaZ")] = pair<double,double>(bs_.
sigmaZ(),bs_.
sigmaZ0Error());
477 std::ostringstream
ss;
478 ss << setfill (
'0') << setw (5) << nthBx;
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);
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);
496 TString histName =
"Trending_nPVs_lumi_bx_" + ss.str();
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;
510 BeamSpot obs = weightedMap_[it->first];
511 double val_[8] = { obs.
x0(),obs.
y0(),obs.
z0(),obs.
sigmaZ(),
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());
532 for (
int i=0;
i<7;++
i) {
535 reco::BeamSpot weightedBeamSpot(bsPosition,val_[3],val_[4],val_[5],val_[6],error,type);
540 weightedMap_.erase(it->first);
541 weightedMap_[it->first] = weightedBeamSpot;
548 if (meanError < 1
e-8){
549 tmpError = 1/(valError*valError);
553 tmpError = 1/(meanError*meanError) + 1/(valError*valError);
554 mean = mean/(meanError*meanError) + val/(valError*valError);
556 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
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 &)
double dydzError() const
error on dydz
#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
double BeamWidthX() const
beam width X
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
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
void formatFitTime(char *, const std::time_t &)
volatile std::atomic< bool > shutdown_flag false
std::pair< int, int > getFitLSRange()
TimeValue_t value() const
void analyze(const edm::Event &e, const edm::EventSetup &c)
std::map< BxNum, reco::BeamSpot > BeamSpotMapBx
double x0() const
x coordinate