33 static char ts[] =
"yyyy-Mm-dd hh:mm:ss";
36 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);
38 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE
39 unsigned int b = strlen(ts);
40 while (ts[--b] ==
' ') {ts[
b] = 0;}
50 countBx_(0),countEvt_(0),countLumi_(0),resetHistos_(
false) {
68 if (fitNLumi_ <= 0) fitNLumi_ = 1;
89 varMap[
"sigmaX_bx"] =
"#sigma_{X}";
90 varMap[
"sigmaY_bx"] =
"#sigma_{Y}";
91 varMap[
"sigmaZ_bx"] =
"#sigma_{Z}";
96 varMap1[
"sigmaX"] =
"#sigma_{X} [cm]";
97 varMap1[
"sigmaY"] =
"#sigma_{Y} [cm]";
98 varMap1[
"sigmaZ"] =
"#sigma_{Z} [cm]";
107 for (std::map<std::string,std::string>::const_iterator varName =
varMap1.begin();
108 varName !=
varMap1.end(); ++varName) {
109 string subDir_ =
"FitBx";
112 subDir_ += varName->first;
132 const std::time_t ftmptime = fbegintimestamp >> 32;
152 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Begin of Lumi: " << nthlumi << endl;
158 bool readEvent_ =
true;
162 edm::LogWarning(
"BX|BeamMonitorBx") <<
"Spilt event from previous lumi section!" << endl;
166 edm::LogWarning(
"BX|BeamMonitorBx") <<
"Spilt event from next lumi section!!!" << endl;
182 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
186 const std::time_t fendtime = fendtimestamp >> 32;
196 for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
197 varName != vMap.end(); ++varName) {
198 string tmpName = varName->first;
199 if (!suffix_.empty()) {
204 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Rebinning " << tmpName << endl;
208 hs[tmpName]=
dbe_->
book2D(tmpName,varName->second,3,0,3,nBx,0,nBx);
209 hs[tmpName]->setBinLabel(1,
"bx",1);
210 hs[tmpName]->setBinLabel(2,varName->second,1);
211 hs[tmpName]->setBinLabel(3,
"#Delta "+varName->second,1);
212 for (
int i=0;
i<nBx;
i++) {
213 hs[tmpName]->setBinLabel(
i+1,
" ",2);
215 hs[tmpName]->getTH1()->SetOption(
"text");
216 hs[tmpName]->Reset();
222 string subDir_, TString prefix_, TString suffix_) {
224 if (plotPV) nType_ = 4;
225 std::ostringstream ss;
226 std::ostringstream ss1;
227 ss << setfill (
'0') << setw (5) << nBx;
230 for (
int i = 0;
i < nType_;
i++) {
231 for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
232 varName != vMap.end(); ++varName) {
233 string tmpDir_ = subDir_ +
"/All_" + varName->first;
235 TString histTitle(varName->first);
237 if (prefix_ !=
"") tmpName = prefix_ +
"_" + varName->first;
238 if (suffix_ !=
"") tmpName = tmpName +
"_" + suffix_;
239 tmpName = tmpName +
"_" + ss.str();
241 TString histName(tmpName);
242 string ytitle(varName->second);
245 bool createHisto =
true;
248 histName.Insert(histName.Index(
"_bx_",4),
"_time");
249 xtitle =
"Time [UTC] [Bx# " + ss1.str() +
"]";
250 if (ytitle.find(
"sigma") == string::npos)
251 histTitle +=
" coordinate of beam spot vs time (Fit)";
253 histTitle = histTitle.Insert(5,
" ") +
" of beam spot vs time (Fit)";
256 if (ytitle.find(
"sigma") == string::npos) {
257 histName.Insert(0,
"PV");
258 histName.Insert(histName.Index(
"_bx_",4),
"_lumi");
259 histTitle.Insert(0,
"Avg. ");
260 histTitle +=
" position of primary vtx vs lumi";
261 xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
262 ytitle.insert(0,
"PV");
263 ytitle +=
" #pm #sigma_{PV";
264 ytitle += varName->first;
267 else createHisto =
false;
270 if (ytitle.find(
"sigma") == string::npos) {
271 histName.Insert(0,
"PV");
272 histName.Insert(histName.Index(
"_bx_",4),
"_time");
273 histTitle.Insert(0,
"Avg. ");
274 histTitle +=
" position of primary vtx vs time";
275 xtitle =
"Time [UTC] [Bx# " + ss1.str() +
"]";
276 ytitle.insert(0,
"PV");
277 ytitle +=
" #pm #sigma_{PV";
278 ytitle += varName->first;
281 else createHisto =
false;
284 histName.Insert(histName.Index(
"_bx_",4),
"_lumi");
285 xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
286 if (ytitle.find(
"sigma") == string::npos)
287 histTitle +=
" coordinate of beam spot vs lumi (Fit)";
289 histTitle = histTitle.Insert(5,
" ") +
" of beam spot vs lumi (Fit)";
296 edm::LogInfo(
"BX|BeamMonitorBx") <<
"histName = " << histName <<
"; histTitle = " << histTitle << std::endl;
297 hst[histName] =
dbe_->
book1D(histName,histTitle,40,0.5,40.5);
298 hst[histName]->getTH1()->SetBit(TH1::kCanRebin);
299 hst[histName]->setAxisTitle(xtitle,1);
300 hst[histName]->setAxisTitle(ytitle,2);
301 hst[histName]->getTH1()->SetOption(
"E1");
302 if (histName.Contains(
"time")) {
303 hst[histName]->getTH1()->SetBins(3600,0.5,3600+0.5);
304 hst[histName]->setAxisTimeDisplay(1);
305 hst[histName]->setAxisTimeFormat(
"%H:%M:%S",1);
307 TDatime
da(eventTime);
312 hst[histName]->getTH1()->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
320 TString histName =
"Trending_nPVs_lumi_bx_" + ss.str();
321 string xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
323 hst[histName] =
dbe_->
book1D(histName,
"Number of Good Reconstructed Vertices",40,0.5,40.5);
324 hst[histName]->setAxisTitle(xtitle,1);
325 hst[histName]->getTH1()->SetBit(TH1::kCanRebin);
326 hst[histName]->getTH1()->SetOption(
"E1");
332 int &lastlumi,
int &nextlumi,
int &nthlumi){
333 if (nthlumi <= nextlumi)
return;
335 int currentlumi = nextlumi;
336 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Lumi of the current fit: " << currentlumi << endl;
337 lastlumi = currentlumi;
343 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Resetting Histograms" << endl;
352 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
" [Fitter] Do BeamSpot Fit for LS = " << fitLS.first
353 <<
" to " << fitLS.second << endl;
358 <<
"; address = " << &
refBStime[0] << std::endl;
360 <<
"; address = " << &
refBStime[1] << std::endl;
367 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Number of bx = " << bsmap.size() << endl;
368 if (bsmap.size() == 0)
return;
373 for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
374 abspot!= bsmap.end(); ++abspot) {
375 int bx = abspot->first;
382 sprintf(tmpTitle,
"%s %i %s %i %s",
" [cm] (LS: ",LSRange.first,
" to ",LSRange.second,
")");
383 for (std::map<std::string,std::string>::const_iterator varName =
varMap.begin();
384 varName !=
varMap.end(); ++varName) {
385 hs[varName->first]->setTitle(varName->second +
" " + tmpTitle);
386 hs[varName->first]->Reset();
395 sprintf(tmpTitle1,
"%s %i %s %i %s",
" [cm] (LS: ",
firstlumi_,
" to ",LSRange.second,
") [weighted average]");
397 sprintf(tmpTitle1,
"%s",
"Need at least two fits to calculate weighted average");
398 for (std::map<std::string,std::string>::const_iterator varName =
varMap.begin();
399 varName !=
varMap.end(); ++varName) {
400 TString tmpName = varName->first +
"_all";
401 hs[tmpName]->setTitle(varName->second +
" " + tmpTitle1);
402 hs[tmpName]->Reset();
407 for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
408 abspot!= bsmap.end(); ++abspot,nthBin--) {
410 int bx = abspot->first;
411 int nPVs = npvsmap.find(bx)->second;
412 edm::LogInfo(
"BeamMonitorBx") <<
"Number of PVs of bx#[" << bx <<
"] = " << nPVs << endl;
423 for (BeamSpotMapBx::const_iterator abspot =
fbspotMap.begin();
424 abspot!=
fbspotMap.end(); ++abspot,nthBin--) {
426 int bx = abspot->first;
435 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Reset track collection for beam fit!!!" <<endl;
448 map<string,string>&vMap,
450 map<string,pair<double,double> > val_;
451 val_[
"x0_bx"] = pair<double,double>(bs_.
x0(),bs_.
x0Error());
452 val_[
"y0_bx"] = pair<double,double>(bs_.
y0(),bs_.
y0Error());
453 val_[
"z0_bx"] = pair<double,double>(bs_.
z0(),bs_.
z0Error());
458 for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
459 varName != vMap.end(); ++varName) {
460 TString tmpName = varName->first;
461 if (suffix_ !=
"") tmpName += TString(
"_"+suffix_);
462 hs[tmpName]->setBinContent(1,nthbin_,nthbx);
463 hs[tmpName]->setBinContent(2,nthbin_,val_[varName->first].first);
464 hs[tmpName]->setBinContent(3,nthbin_,val_[varName->first].second);
471 map<TString,pair<double,double> > val_;
472 val_[TString(prefix_+
"_x")] = pair<double,double>(bs_.
x0(),bs_.
x0Error());
473 val_[TString(prefix_+
"_y")] = pair<double,double>(bs_.
y0(),bs_.
y0Error());
474 val_[TString(prefix_+
"_z")] = pair<double,double>(bs_.
z0(),bs_.
z0Error());
477 val_[TString(prefix_+
"_sigmaZ")] = pair<double,double>(bs_.
sigmaZ(),bs_.
sigmaZ0Error());
479 std::ostringstream ss;
480 ss << setfill (
'0') << setw (5) << nthBx;
482 for (map<TString,MonitorElement*>::iterator itHst =
hst.begin();
483 itHst !=
hst.end(); ++itHst) {
484 if (!(itHst->first.Contains(ss.str())))
continue;
485 if (itHst->first.Contains(
"nPVs"))
continue;
486 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Filling histogram: " << itHst->first << endl;
487 if (itHst->first.Contains(
"time")) {
488 int idx = itHst->first.Index(
"_time",5);
489 itHst->second->setBinContent(ntbin_,val_[itHst->first(0,idx)].first);
490 itHst->second->setBinError(ntbin_,val_[itHst->first(0,idx)].second);
492 if (itHst->first.Contains(
"lumi")) {
493 int idx = itHst->first.Index(
"_lumi",5);
494 itHst->second->setBinContent(
endLumiOfBSFit_,val_[itHst->first(0,idx)].first);
495 itHst->second->setBinError(
endLumiOfBSFit_,val_[itHst->first(0,idx)].second);
498 TString histName =
"Trending_nPVs_lumi_bx_" + ss.str();
505 for (BeamSpotMapBx::const_iterator it = newMap_.begin();
506 it != newMap_.end(); ++it) {
507 if (weightedMap_.find(it->first) == weightedMap_.end() || (it->second.type() != 2)) {
508 weightedMap_[it->first] = it->second;
512 BeamSpot obs = weightedMap_[it->first];
513 double val_[8] = { obs.
x0(),obs.
y0(),obs.
z0(),obs.
sigmaZ(),
520 weight(val_[0], valErr_[0], it->second.x0() , it->second.x0Error());
521 weight(val_[1], valErr_[1], it->second.y0() , it->second.y0Error());
522 weight(val_[2], valErr_[2], it->second.z0() , it->second.z0Error());
523 weight(val_[3], valErr_[3], it->second.sigmaZ() , it->second.sigmaZ0Error());
524 weight(val_[4], valErr_[4], it->second.dxdz() , it->second.dxdzError());
525 weight(val_[5], valErr_[5], it->second.dydz() , it->second.dydzError());
526 weight(val_[6], valErr_[6], it->second.BeamWidthX(), it->second.BeamWidthXError());
527 weight(val_[7], valErr_[7], it->second.BeamWidthY(), it->second.BeamWidthYError());
534 for (
int i=0;
i<7;++
i) {
537 reco::BeamSpot weightedBeamSpot(bsPosition,val_[3],val_[4],val_[5],val_[6],error,type);
542 weightedMap_.erase(it->first);
543 weightedMap_[it->first] = weightedBeamSpot;
550 if (meanError < 1
e-8){
551 tmpError = 1/(valError*valError);
555 tmpError = 1/(meanError*meanError) + 1/(valError*valError);
556 mean = mean/(meanError*meanError) + val/(valError*valError);
558 mean = mean/tmpError;
void beginRun(const edm::Run &r, const edm::EventSetup &c)
edm::ParameterSet parameters_
LuminosityBlockID id() const
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
void FillTrendHistos(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, TString)
math::XYZPoint Point
point in the space
void BookTrendHistos(bool, int, std::map< std::string, std::string > &, std::string, TString, TString)
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
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
TimeValue_t value() const
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
std::map< std::string, std::string > varMap1
std::map< TString, MonitorElement * > hst
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()
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