39 static char ts[] =
"yyyy-Mm-dd hh:mm:ss";
42 int year = ptm->tm_year;
44 edm::LogError(
"BadTimeStamp") <<
"year reported is " << year <<
"!! resetting to 2010..." << std::endl;
47 sprintf( ts,
"%4d-%02d-%02d %02d:%02d:%02d", 2010,ptm->tm_mon+1,ptm->tm_mday,(ptm->tm_hour+
CEST)%24, ptm->tm_min, ptm->tm_sec);
49 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE
50 unsigned int b = strlen(ts);
51 while (ts[--b] ==
' ') {ts[
b] = 0;}
63 countEvt_(0),countLumi_(0),nthBSTrk_(0),nFitElements_(3),resetHistos_(
false) {
94 if (fitNLumi_ <= 0) fitNLumi_ = 1;
136 h_d0_phi0 =
dbe_->
bookProfile(
"d0_phi0",
"d_{0} vs. #phi_{0} (Selected Tracks)",phiBin,phiMin,phiMax,dxBin,dxMin,dxMax,
"");
140 h_vx_vy =
dbe_->
book2D(
"trk_vx_vy",
"Vertex (PCA) position of selected tracks",vxBin,vxMin,vxMax,vxBin,vxMin,vxMax);
146 TDatime *
da =
new TDatime();
147 gStyle->SetTimeOffset(da->Convert(kTRUE));
150 string coord[nvar_] = {
"x",
"y",
"z",
"sigmaX",
"sigmaY",
"sigmaZ"};
151 string label[nvar_] = {
"x_{0} (cm)",
"y_{0} (cm)",
"z_{0} (cm)",
152 "#sigma_{X_{0}} (cm)",
"#sigma_{Y_{0}} (cm)",
"#sigma_{Z_{0}} (cm)"};
153 for (
int i = 0;
i < 4;
i++) {
155 for (
int ic=0; ic<nvar_; ++ic) {
156 TString histName(coord[ic]);
157 TString histTitle(coord[ic]);
158 string ytitle(label[ic]);
161 bool createHisto =
true;
164 histName +=
"0_time";
165 xtitle =
"Time [UTC]";
167 histTitle +=
" coordinate of beam spot vs time (Fit)";
169 histTitle = histTitle.Insert(5,
" ") +
" of beam spot vs time (Fit)";
174 histName.Insert(0,
"PV");
176 histTitle.Insert(0,
"Avg. ");
177 histTitle +=
" position of primary vtx vs lumi";
178 xtitle =
"Lumisection";
179 ytitle.insert(0,
"PV");
180 ytitle +=
" #pm #sigma_{PV";
184 else createHisto =
false;
189 histName.Insert(0,
"PV");
191 histTitle.Insert(0,
"Avg. ");
192 histTitle +=
" position of primary vtx vs time";
193 xtitle =
"Time [UTC]";
194 ytitle.insert(0,
"PV");
195 ytitle +=
" #pm #sigma_{PV";
199 else createHisto =
false;
202 histName +=
"0_lumi";
203 xtitle =
"Lumisection";
205 histTitle +=
" coordinate of beam spot vs lumi (Fit)";
207 histTitle = histTitle.Insert(5,
" ") +
" of beam spot vs lumi (Fit)";
211 edm::LogInfo(
"BeamMonitor") <<
"hitsName = " << histName <<
"; histTitle = " << histTitle << std::endl;
212 hs[histName] =
dbe_->
book1D(histName,histTitle,40,0.5,40.5);
213 hs[histName]->setAxisTitle(xtitle,1);
214 hs[histName]->setAxisTitle(ytitle,2);
215 hs[histName]->getTH1()->SetOption(
"E1");
216 if (histName.Contains(
"time")) {
219 hs[histName]->setAxisTimeDisplay(1);
220 hs[histName]->setAxisTimeFormat(
"%H:%M:%S",1);
224 hs[histName] =
dbe_->
book1D(histName,histTitle,40,0.5,40.5);
225 hs[histName]->getTH1()->SetBit(TH1::kCanRebin);
226 hs[histName]->setAxisTitle(xtitle,1);
227 hs[histName]->setAxisTitle(ytitle,2);
228 hs[histName]->getTH1()->SetOption(
"E1");
229 if (histName.Contains(
"time")) {
232 hs[histName]->setAxisTimeDisplay(1);
233 hs[histName]->setAxisTimeFormat(
"%H:%M:%S",1);
243 h_vx_dz =
dbe_->
bookProfile(
"vx_dz",
"v_{x} vs. dz of selected tracks",dzBin,dzMin,dzMax,dxBin,dxMin,dxMax,
"");
247 h_vy_dz =
dbe_->
bookProfile(
"vy_dz",
"v_{y} vs. dz of selected tracks",dzBin,dzMin,dzMax,dxBin,dxMin,dxMax,
"");
251 h_x0 =
dbe_->
book1D(
"BeamMonitorFeedBack_x0",
"x coordinate of beam spot (Fit)",100,-0.01,0.01);
255 h_y0 =
dbe_->
book1D(
"BeamMonitorFeedBack_y0",
"y coordinate of beam spot (Fit)",100,-0.01,0.01);
259 h_z0 =
dbe_->
book1D(
"BeamMonitorFeedBack_z0",
"z coordinate of beam spot (Fit)",dzBin,dzMin,dzMax);
263 h_sigmaX0 =
dbe_->
book1D(
"BeamMonitorFeedBack_sigmaX0",
"sigma x0 of beam spot (Fit)",100,0,0.05);
267 h_sigmaY0 =
dbe_->
book1D(
"BeamMonitorFeedBack_sigmaY0",
"sigma y0 of beam spot (Fit)",100,0,0.05);
271 h_sigmaZ0 =
dbe_->
book1D(
"BeamMonitorFeedBack_sigmaZ0",
"sigma z0 of beam spot (Fit)",100,0,10);
276 h_trkPt=
dbe_->
book1D(
"trkPt",
"p_{T} of all reco'd tracks (no selection)",200,0.,50.);
279 h_trkVz=
dbe_->
book1D(
"trkVz",
"Z coordinate of PCA of all reco'd tracks (no selection)",dzBin,dzMin,dzMax);
302 h_nVtx =
dbe_->
book1D(
"vtxNbr",
"Reconstructed Vertices in Event",20,-0.5,19.5);
306 h_PVx[0] =
dbe_->
book1D(
"PVX",
"x coordinate of Primary Vtx",50,-0.01,0.01);
310 h_PVy[0] =
dbe_->
book1D(
"PVY",
"y coordinate of Primary Vtx",50,-0.01,0.01);
314 h_PVz[0] =
dbe_->
book1D(
"PVZ",
"z coordinate of Primary Vtx",dzBin,dzMin,dzMax);
317 h_PVx[1] =
dbe_->
book1D(
"PVXFit",
"x coordinate of Primary Vtx (Last Fit)",50,-0.01,0.01);
321 h_PVy[1] =
dbe_->
book1D(
"PVYFit",
"y coordinate of Primary Vtx (Last Fit)",50,-0.01,0.01);
325 h_PVz[1] =
dbe_->
book1D(
"PVZFit",
"z coordinate of Primary Vtx (Last Fit)",dzBin,dzMin,dzMax);
361 case 0 : sprintf(histo,
"x0_status");
break;
362 case 1 : sprintf(histo,
"y0_status");
break;
363 case 2 : sprintf(histo,
"z0_status");
break;
397 std::cout <<
"TimeOffset = " << eventTime << std::endl;
398 TDatime
da(eventTime);
403 for (std::map<TString,MonitorElement*>::iterator it =
hs.begin();
404 it !=
hs.end(); ++it) {
405 if ((*it).first.Contains(
"time"))
406 (*it).second->getTH1()->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
415 const std::time_t ftmptime = fbegintimestamp >> 32;
444 edm::LogInfo(
"BeamMonitor") <<
"Begin of Lumi: " << nthlumi << endl;
450 bool readEvent_ =
true;
454 edm::LogInfo(
"BeamMonitor") <<
"Spilt event from previous lumi section!" << std::endl;
458 edm::LogInfo(
"BeamMonitor") <<
"Spilt event from next lumi section!!!" << std::endl;
466 refBS = *recoBeamSpotHandle;
473 cutFlowTable->
getTH1()->SetBins(tmphisto->GetNbinsX(),tmphisto->GetXaxis()->GetXmin(),tmphisto->GetXaxis()->GetXmax());
475 for(
int n=0;
n < tmphisto->GetNbinsX();
n++)
483 for ( reco::TrackCollection::const_iterator
track = tracks->begin();
494 for (reco::VertexCollection::const_iterator pv = PVCollection->begin(); pv != PVCollection->end(); ++pv) {
496 if (pv->isFake() || pv->tracksSize()==0)
continue;
517 edm::LogInfo(
"BeamMonitor") <<
"Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
521 const std::time_t fendtime = fendtimestamp >> 32;
529 int currentlumi = nextlumi;
530 edm::LogInfo(
"BeamMonitor") <<
"Lumi of the current fit: " << currentlumi << endl;
531 lastlumi = currentlumi;
537 const int countLS_bs =
hs[
"x0_lumi"]->getTH1()->GetEntries();
538 const int countLS_pv =
hs[
"PVx_lumi"]->getTH1()->GetEntries();
539 edm::LogInfo(
"BeamMonitor") <<
"countLS_bs = " << countLS_bs <<
" ; countLS_pv = " << countLS_pv << std::endl;
540 int LSgap_bs = currentlumi/
fitNLumi_ - countLS_bs;
541 int LSgap_pv = currentlumi/
fitPVNLumi_ - countLS_pv;
546 edm::LogInfo(
"BeamMonitor") <<
"LSgap_bs = " << LSgap_bs <<
" ; LSgap_pv = " << LSgap_pv << std::endl;
548 for (
int ig = 0; ig < LSgap_bs; ig++) {
552 hs[
"sigmaX0_lumi"]->ShiftFillLast( 0., 0.,
fitNLumi_ );
553 hs[
"sigmaY0_lumi"]->ShiftFillLast( 0., 0.,
fitNLumi_ );
554 hs[
"sigmaZ0_lumi"]->ShiftFillLast( 0., 0.,
fitNLumi_ );
556 for (
int ig = 0; ig < LSgap_pv; ig++) {
562 for (
int i=1;
i < (currentlumi - previousLS);
i++)
580 bool doPVFit =
false;
604 TF1 *fgaus =
new TF1(
"fgaus",
"gaus");
606 fgaus->SetLineColor(4);
608 mean = fgaus->GetParameter(1);
609 width = fgaus->GetParameter(2);
610 meanErr = fgaus->GetParError(1);
611 widthErr = fgaus->GetParError(2);
613 hs[
"PVx_lumi_all"]->setBinContent(currentlumi,mean);
614 hs[
"PVx_lumi_all"]->setBinError(currentlumi,width);
617 edm::LogInfo(
"BeamMonitor") <<
"Event time outside current range of time histograms!" << std::endl;
619 hs[
"PVx_time"]->setBinContent(nthBin,mean);
620 hs[
"PVx_time"]->setBinError(nthBin,width);
624 hs[
"PVx_time_all"]->setBinContent(jthBin,mean);
625 hs[
"PVx_time_all"]->setBinError(jthBin,width);
637 tmphisto =
static_cast<TH1D *
>((
h_PVx[0]->
getTH1())->Clone(
"tmphisto"));
638 h_PVx[1]->
getTH1()->SetBins(tmphisto->GetNbinsX(),tmphisto->GetXaxis()->GetXmin(),tmphisto->GetXaxis()->GetXmax());
644 mean = fgaus->GetParameter(1);
645 width = fgaus->GetParameter(2);
646 meanErr = fgaus->GetParError(1);
647 widthErr = fgaus->GetParError(2);
649 hs[
"PVy_lumi_all"]->setBinContent(currentlumi,mean);
650 hs[
"PVy_lumi_all"]->setBinError(currentlumi,width);
652 hs[
"PVy_time"]->setBinContent(nthBin,mean);
653 hs[
"PVy_time"]->setBinError(nthBin,width);
656 hs[
"PVy_time_all"]->setBinContent(jthBin,mean);
657 hs[
"PVy_time_all"]->setBinError(jthBin,width);
665 tmphisto =
static_cast<TH1D *
>((
h_PVy[0]->
getTH1())->Clone(
"tmphisto"));
666 h_PVy[1]->
getTH1()->SetBins(tmphisto->GetNbinsX(),tmphisto->GetXaxis()->GetXmin(),tmphisto->GetXaxis()->GetXmax());
673 mean = fgaus->GetParameter(1);
674 width = fgaus->GetParameter(2);
675 meanErr = fgaus->GetParError(1);
676 widthErr = fgaus->GetParError(2);
678 hs[
"PVz_lumi_all"]->setBinContent(currentlumi,mean);
679 hs[
"PVz_lumi_all"]->setBinError(currentlumi,width);
681 hs[
"PVz_time"]->setBinContent(nthBin,mean);
682 hs[
"PVz_time"]->setBinError(nthBin,width);
685 hs[
"PVz_time_all"]->setBinContent(jthBin,mean);
686 hs[
"PVz_time_all"]->setBinError(jthBin,width);
694 tmphisto =
static_cast<TH1D *
>((
h_PVz[0]->
getTH1())->Clone(
"tmphisto"));
695 h_PVz[1]->
getTH1()->SetBins(tmphisto->GetNbinsX(),tmphisto->GetXaxis()->GetXmin(),tmphisto->GetXaxis()->GetXmax());
717 bool countFitting =
false;
723 edm::LogInfo(
"BeamMonitor") <<
"Resetting Histograms" << endl;
733 edm::LogInfo(
"BeamMonitor") <<
"Fill histos, start from " <<
nthBSTrk_ + 1 <<
"th record of selected tracks" << endl;
734 unsigned int itrk = 0;
735 for (vector<BSTrkParameters>::const_iterator BSTrk = theBSvector.begin();
736 BSTrk != theBSvector.end();
740 double vx = BSTrk->vx();
741 double vy = BSTrk->vy();
742 double z0 = BSTrk->z0();
770 <<
"; address = " << &
refBStime[0] << std::endl;
772 <<
"; address = " << &
refBStime[1] << std::endl;
777 edm::LogInfo(
"BeamMonitor") <<
"[BeamFitter] Do BeamSpot Fit for LS = " << fitLS[0] <<
" to " << fitLS[1] << std::endl;
783 edm::LogInfo(
"BeamMonitor") <<
"\n RESULTS OF DEFAULT FIT:" << endl;
785 edm::LogInfo(
"BeamMonitor") <<
"[BeamFitter] fitting done \n" << endl;
793 hs[
"x0_lumi_all"]->setBinContent(currentlumi,bs.
x0());
794 hs[
"x0_lumi_all"]->setBinError(currentlumi,bs.
x0Error());
795 hs[
"y0_lumi_all"]->setBinContent(currentlumi,bs.
y0());
796 hs[
"y0_lumi_all"]->setBinError(currentlumi,bs.
y0Error());
797 hs[
"z0_lumi_all"]->setBinContent(currentlumi,bs.
z0());
798 hs[
"z0_lumi_all"]->setBinError(currentlumi,bs.
z0Error());
799 hs[
"sigmaX0_lumi_all"]->setBinContent(currentlumi, bs.
BeamWidthX());
801 hs[
"sigmaY0_lumi_all"]->setBinContent(currentlumi, bs.
BeamWidthY());
803 hs[
"sigmaZ0_lumi_all"]->setBinContent(currentlumi, bs.
sigmaZ());
804 hs[
"sigmaZ0_lumi_all"]->setBinError(currentlumi, bs.
sigmaZ0Error());
808 hs[
"x0_time"]->setBinContent(nthBin, bs.
x0());
809 hs[
"y0_time"]->setBinContent(nthBin, bs.
y0());
810 hs[
"z0_time"]->setBinContent(nthBin, bs.
z0());
811 hs[
"sigmaX0_time"]->setBinContent(nthBin, bs.
BeamWidthX());
812 hs[
"sigmaY0_time"]->setBinContent(nthBin, bs.
BeamWidthY());
813 hs[
"sigmaZ0_time"]->setBinContent(nthBin, bs.
sigmaZ());
814 hs[
"x0_time"]->setBinError(nthBin, bs.
x0Error());
815 hs[
"y0_time"]->setBinError(nthBin, bs.
y0Error());
816 hs[
"z0_time"]->setBinError(nthBin, bs.
z0Error());
824 hs[
"x0_time_all"]->setBinContent(jthBin, bs.
x0());
825 hs[
"y0_time_all"]->setBinContent(jthBin, bs.
y0());
826 hs[
"z0_time_all"]->setBinContent(jthBin, bs.
z0());
827 hs[
"sigmaX0_time_all"]->setBinContent(jthBin, bs.
BeamWidthX());
828 hs[
"sigmaY0_time_all"]->setBinContent(jthBin, bs.
BeamWidthY());
829 hs[
"sigmaZ0_time_all"]->setBinContent(jthBin, bs.
sigmaZ());
830 hs[
"x0_time_all"]->setBinError(jthBin, bs.
x0Error());
831 hs[
"y0_time_all"]->setBinError(jthBin, bs.
y0Error());
832 hs[
"z0_time_all"]->setBinError(jthBin, bs.
z0Error());
849 double alpha = std::atan2(bs.
y0(),bs.
x0());
850 TF1 *
f1 =
new TF1(
"f1",
"[0]*sin(x-[1])",-3.14,3.14);
851 f1->SetParameters(amp,alpha);
852 f1->SetParLimits(1,amp-0.1,amp+0.1);
853 f1->SetParLimits(2,alpha-0.577,alpha+0.577);
859 TF1 *fgaus =
new TF1(
"fgaus",
"gaus");
860 fgaus->SetParameters(mean,width);
861 fgaus->SetLineColor(4);
862 h_trk_z0->
getTH1()->Fit(
"fgaus",
"QLRM",
"",mean-3*width,mean+3*width);
868 sprintf(tmpTitle,
"%s %i %s %i",
"Fitted Beam Spot (cm) of LS: ",LSRange[0],
" to ",LSRange[1]);
913 edm::LogInfo(
"BeamMonitor") <<
"[BeamMonitor] Beam fit fails!!! \n" << endl;
914 edm::LogInfo(
"BeamMonitor") <<
"[BeamMonitor] Output beam spot for DIP \n" << endl;
931 edm::LogInfo(
"BeamMonitor") <<
"[BeamMonitor] No fitting \n" << endl;
932 edm::LogInfo(
"BeamMonitor") <<
"[BeamMonitor] Output fake beam spot for DIP \n" << endl;
964 edm::LogInfo(
"BeamMonitor") <<
"Reset track collection for beam fit!!!" <<endl;
990 TDatime
da(offsetTime);
992 double val = h->GetBinContent(
lastNZbin);
993 double valErr = h->GetBinError(
lastNZbin);
995 h->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
997 h->SetBinContent(bin,val);
998 h->SetBinError(bin,valErr);
1002 h->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
1009 bool scroll_ =
false;
1012 edm::LogInfo(
"BeamMonitor") <<
"Reset Time Offset" << std::endl;
1015 if (
hs[
"x0_time"]->getBinContent(
bin) > 0) {
1022 edm::LogInfo(
"BeamMonitor") <<
"Time difference too large since last readout" << std::endl;
1027 edm::LogInfo(
"BeamMonitor") <<
"Offset to last record" << std::endl;
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
LuminosityBlockID id() const
const char * formatFitTime(const std::time_t &)
T getParameter(std::string const &) const
BeamMonitor(const edm::ParameterSet &)
double z0() const
z coordinate
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
unsigned int minNrVertices_
void setBinContent(int binx, double content)
set content of bin (1-D)
double sigmaZ0Error() const
error on sigma z
MonitorElement * reportSummary
void analyze(const edm::Event &e, const edm::EventSetup &c)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
MonitorElement * cutFlowTable
double dydzError() const
error on dydz
MonitorElement * h_PVz[2]
bool testScroll(std::time_t &, std::time_t &)
std::vector< BSTrkParameters > getBSvector()
#define DEFINE_FWK_MODULE(type)
std::vector< Track > TrackCollection
collection of Tracks
void setRefTime(std::time_t t0, std::time_t t1)
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
edm::TimeValue_t ftimestamp
edm::LuminosityBlockNumber_t luminosityBlock() const
void update(void)
Mark the object updated.
Timestamp const & beginTime() const
MonitorElement * h_sigmaZ0
MonitorElement * h_nTrk_lumi
MonitorElement * fitResults
void readEvent(const edm::Event &iEvent)
MonitorElement * h_sigmaY0
MonitorElement * bookFloat(const char *name)
Book float.
LuminosityBlockNumber_t luminosityBlock() const
double dydz() const
dydz slope
void ShiftFillLast(double y, double ye=0., int32_t xscale=1)
double dxdzError() const
error on dxdz
Timestamp const & endTime() const
void removeElement(const std::string &name)
void beginRun(const edm::Run &r, const edm::EventSetup &c)
MonitorElement * pvResults
double BeamWidthX() const
beam width X
void setFitLSRange(int ls0, int ls1)
TH1F * getTH1F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
unsigned int offset(bool)
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
double z0Error() const
error on z
unsigned long long TimeValue_t
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
double dxdz() const
dxdz slope
double x0Error() const
error on x
double y0Error() const
error on y
TimeValue_t value() const
void FitAndFill(const edm::LuminosityBlock &lumiSeg, int &, int &, int &)
Float_t summaryContent_[3]
MonitorElement * h_sigmaX0
MonitorElement * h_PVy[2]
MonitorElement * reportSummaryContents[3]
double sigmaZ() const
sigma z
double BeamWidthY() const
beam width Y
LuminosityBlockNumber_t luminosityBlock() const
MonitorElement * h_trk_z0
T const * product() const
Timestamp const & beginTime() const
edm::ParameterSet parameters_
TProfile * getTProfile(void) const
double y0() const
y coordinate
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
TH2F * getTH2F(void) const
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
BeamFitter * theBeamFitter
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
MonitorElement * h_PVx[2]
void Reset(void)
reset ME (ie. contents, errors, etc)
void endRun(const edm::Run &r, const edm::EventSetup &c)
MonitorElement * h_d0_phi0
edm::InputTag tracksLabel_
reco::BeamSpot getBeamSpot()
void setCurrentFolder(const std::string &fullpath)
void scrollTH1(TH1 *, std::time_t)
BeamType type() const
return beam type
MonitorElement * reportSummaryMap
double x0() const
x coordinate
std::map< TString, MonitorElement * > hs