CMS 3D CMS Logo

BeamSpotProblemMonitor.cc
Go to the documentation of this file.
1 /*
2  * \file BeamSpotProblemMonitor.cc
3  * \author Sushil S. Chauhan/UC Davis
4  *
5  */
6 
16 
19 
20 #include <numeric>
21 #include <cmath>
22 
23 using namespace std;
24 using namespace edm;
25 
26 //
27 // constructors and destructor
28 //
30  : dcsStatus_{consumes<DcsStatusCollection>(ps.getUntrackedParameter<InputTag>("DCSStatus"))},
31  scalertag_{consumes<BeamSpotOnlineCollection>(ps.getUntrackedParameter<InputTag>("scalarBSCollection"))},
32  trkSrc_{consumes<reco::TrackCollection>(ps.getUntrackedParameter<InputTag>("pixelTracks"))},
33  nTracks_{0},
34  nCosmicTrk_{ps.getUntrackedParameter<int>("nCosmicTrk")},
35  fitNLumi_{1},
36  debug_{ps.getUntrackedParameter<bool>("Debug")},
37  onlineMode_{ps.getUntrackedParameter<bool>("OnlineMode")},
38  doTest_{ps.getUntrackedParameter<bool>("doTest")},
39  alarmONThreshold_{ps.getUntrackedParameter<int>("AlarmONThreshold")},
40  alarmOFFThreshold_{ps.getUntrackedParameter<int>("AlarmOFFThreshold")},
41  lastlumi_{0},
42  nextlumi_{0},
43  processed_{false},
44  alarmOn_{false},
45  beamSpotStatus_{0},
46  beamSpotFromDB_{0} {
47  monitorName_ = ps.getUntrackedParameter<string>("monitorName");
48 
49  if (not monitorName_.empty())
50  monitorName_ += "/";
51 }
52 
55  desc.addUntracked<string>("monitorName", "BeamSpotProblemMonitor");
56  desc.addUntracked<InputTag>("DCSStatus", edm::InputTag("scalersRawToDigi"));
57  desc.addUntracked<InputTag>("scalarBSCollection", edm::InputTag("scalersRawToDigi"));
58  desc.addUntracked<InputTag>("pixelTracks", edm::InputTag("pixelTracks"));
59  desc.addUntracked<int>("nCosmicTrk", 10);
60  desc.addUntracked<bool>("Debug", false);
61  desc.addUntracked<bool>("OnlineMode", true);
62  desc.addUntracked<bool>("doTest", false);
63  desc.addUntracked<int>("AlarmONThreshold", 10);
64  desc.addUntracked<int>("AlarmOFFThreshold", 40);
65 
66  oDesc.add("dqmBeamSpotProblemMonitor", desc);
67 }
68 
69 //--------------------------------------------------------
71  // create and cd into new folder
72  iB.setCurrentFolder(monitorName_ + "FitFromScalars");
73 
74  const string coord{"BeamSpotStatus"};
75 
76  string histName(coord + "_lumi");
77  string histTitle(coord);
78  const string ytitle("Problem (-1) / OK (1)");
79  const string xtitle("Lumisection");
80 
81  beamSpotStatusLumi_ = iB.book1D(histName, histTitle, 40, 0.5, 40.5);
84 
85  histName += "_all";
86  histTitle += " all";
87  beamSpotStatusLumiAll_ = iB.book1D(histName, histTitle, 40, 0.5, 40.5);
88  beamSpotStatusLumiAll_->getTH1()->SetCanExtend(TH1::kAllAxes);
91 
92  //NOTE: This in principal should be a Lumi only histogram since it gets reset at every
93  // dqmBeginLuminosityBlock call. However, it is also filled at that time and the DQMStore
94  // clears all lumi histograms at postGlobalBeginLuminosityBlock!
95  beamSpotError_ = iB.book1D("BeamSpotError", "ERROR: Beamspot missing from scalars", 20, 0.5, 20.5);
96  beamSpotError_->setAxisTitle("# of consecutive LSs with problem", 1);
97  beamSpotError_->setAxisTitle("Problem with scalar BeamSpot", 2);
98 }
99 
100 //--------------------------------------------------------
102  const int nthlumi = lumiSeg.luminosityBlock();
103 
104  if (onlineMode_) {
105  if (nthlumi > nextlumi_) {
106  fillPlots(lastlumi_, nextlumi_, nthlumi);
107  nextlumi_ = nthlumi;
108  edm::LogInfo("BeamSpotProblemMonitor") << "dqmBeginLuminosityBlock:: Next Lumi to Fit: " << nextlumi_ << endl;
109  }
110  } else {
111  if (processed_)
112  fillPlots(lastlumi_, nextlumi_, nthlumi);
113  nextlumi_ = nthlumi;
114  edm::LogInfo("BeamSpotProblemMonitor") << " dqmBeginLuminosityBlock:: Next Lumi to Fit: " << nextlumi_ << endl;
115  }
116 
117  if (processed_)
118  processed_ = false;
119  edm::LogInfo("BeamSpotProblemMonitor") << " dqmBeginLuminosityBlock:: Begin of Lumi: " << nthlumi << endl;
120 }
121 
122 // ----------------------------------------------------------
124  const int nthlumi = iEvent.luminosityBlock();
125 
126  if (onlineMode_ && (nthlumi < nextlumi_)) {
127  edm::LogInfo("BeamSpotProblemMonitor") << "analyze:: Spilt event from previous lumi section!" << std::endl;
128  return;
129  }
130  if (onlineMode_ && (nthlumi > nextlumi_)) {
131  edm::LogInfo("BeamSpotProblemMonitor") << "analyze:: Spilt event from next lumi section!!!" << std::endl;
132  return;
133  }
134 
135  beamSpotStatus_ = 0.;
136 
137  // Checking TK status
138  Handle<DcsStatusCollection> dcsStatus;
139  iEvent.getByToken(dcsStatus_, dcsStatus);
140  std::array<bool, 6> dcsTk;
141  for (auto& e : dcsTk) {
142  e = true;
143  }
144  for (auto const& status : *dcsStatus) {
145  if (!status.ready(DcsStatus::BPIX))
146  dcsTk[0] = false;
147  if (!status.ready(DcsStatus::FPIX))
148  dcsTk[1] = false;
149  if (!status.ready(DcsStatus::TIBTID))
150  dcsTk[2] = false;
151  if (!status.ready(DcsStatus::TOB))
152  dcsTk[3] = false;
153  if (!status.ready(DcsStatus::TECp))
154  dcsTk[4] = false;
155  if (!status.ready(DcsStatus::TECm))
156  dcsTk[5] = false;
157  }
158 
159  bool allTkOn = true;
160  for (auto status : dcsTk) {
161  if (!status) {
162  allTkOn = false;
163  break;
164  }
165  }
166 
167  //If tracker is ON and collision is going on then must be few track ther
169  iEvent.getByToken(trkSrc_, trackCollection);
170  for (auto const& track : *trackCollection) {
171  if (track.pt() > 1.0)
172  nTracks_++;
173  if (nTracks_ > 200)
174  break;
175  }
176 
177  // get scalar collection and BeamSpot
179  iEvent.getByToken(scalertag_, handleScaler);
180 
181  // beam spot scalar object
182  BeamSpotOnline spotOnline;
183 
184  bool fallBackToDB = false;
185  alarmOn_ = false;
186 
187  if (!handleScaler->empty()) {
188  spotOnline = *(handleScaler->begin());
189 
190  // check if we have a valid beam spot fit result from online DQM thrugh scalars
191  if (spotOnline.x() == 0. && spotOnline.y() == 0. && spotOnline.z() == 0. && spotOnline.width_x() == 0. &&
192  spotOnline.width_y() == 0.) {
193  fallBackToDB = true;
194  }
195  }
196 
197  //For testing set it false for every LSs
198  if (doTest_)
199  fallBackToDB = true;
200 
201  //based on last event of this lumi only as it overwrite it
202  if (allTkOn && fallBackToDB) {
203  beamSpotStatus_ = -1.;
204  } //i.e,from DB
205  if (allTkOn && (!fallBackToDB)) {
206  beamSpotStatus_ = 1.;
207  } //i.e,from online DQM
208 
209  //when collision at least few tracks should be there otherwise it give false ALARM
210  if (allTkOn && nTracks_ < nCosmicTrk_)
211  beamSpotStatus_ = 0.;
212 
213  processed_ = true;
214 }
215 
216 //--------------------------------------------------------
217 void BeamSpotProblemMonitor::fillPlots(int& lastlumi, int& nextlumi, int nthlumi) {
218  if (onlineMode_ && (nthlumi <= nextlumi))
219  return;
220 
221  int currentlumi = nextlumi;
222  lastlumi = currentlumi;
223 
224  //Chcek status and if lumi are in succession when fall to DB
225  if (beamSpotStatus_ == -1. && (lastlumi + 1) == nthlumi) {
226  beamSpotFromDB_++;
227  } else {
228  beamSpotFromDB_ = 0; //if not in succesion or status is ok then set zero
229  }
230 
232  alarmOn_ = true; //set the audio alarm true after N successive LSs
233  }
234 
236  alarmOn_ = false; //set the audio alarm true after 10 successive LSs
237  beamSpotFromDB_ = 0; //reset it for new incident
238  }
239 
240  if (onlineMode_) { // filling LS gap For status plot
241 
242  const int countLS_bs = beamSpotStatusLumi_->getTH1()->GetEntries();
243  int LSgap_bs = currentlumi / fitNLumi_ - countLS_bs;
244  if (currentlumi % fitNLumi_ == 0)
245  LSgap_bs--;
246 
247  // filling previous fits if LS gap ever exists
248  for (int ig = 0; ig < LSgap_bs; ig++) {
249  beamSpotStatusLumi_->ShiftFillLast(0., 0., fitNLumi_); //x0 , x0err, fitNLumi_; see DQMCore....
250  }
251 
254  0.,
255  fitNLumi_); //beamSpotStatus_ =>0. (no collision, no tracks); =>1 (OK from scaler), =>-1 (No scalar results)
257 
258  } else {
260  } //onlineMode_
261 
262  //Reset it here for next lumi
264  if (alarmOn_)
266 
267  //Get quality report
268  const QReport* beamSpotQReport = beamSpotError_->getQReport("BeamSpotOnlineTest");
269 
270  if (beamSpotQReport) {
271  /* S.Dutta : Commenting out these variables are not used and giving error with "-Werror=unused-variable" option
272  float qtresult = BeamSpotQReport->getQTresult();
273  int qtstatus = BeamSpotQReport->getStatus() ; // get QT status value (see table below) */
274  }
275 
276  nTracks_ = 0;
277 }
278 
279 //--------------------------------------------------------
281  const int nthlumi = lumiSeg.id().luminosityBlock();
282  edm::LogInfo("BeamSpotProblemMonitor")
283  << "dqmEndLuminosityBlock:: Lumi of the last event before dqmEndLuminosityBlock: " << nthlumi << endl;
284 }
285 //-------------------------------------------------------
286 
288  if (debug_)
289  edm::LogInfo("BeamSpotProblemMonitor") << "dqmEndRun:: Clearing all the Maps " << endl;
290  //Reset it end of job
292 }
293 
295 
296 // Local Variables:
297 // show-trailing-whitespace: t
298 // truncate-lines: t
299 // End:
ConfigurationDescriptions.h
BeamSpotOnline::x
float x() const
Definition: BeamSpotOnline.h:48
BeamSpotProblemMonitor::monitorName_
std::string monitorName_
Definition: BeamSpotProblemMonitor.h:44
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
BeamSpotProblemMonitor::BeamSpotProblemMonitor
BeamSpotProblemMonitor(const edm::ParameterSet &)
Definition: BeamSpotProblemMonitor.cc:29
MessageLogger.h
TrackCandidateCollection.h
DcsStatus::BPIX
Definition: DcsStatus.h:55
BeamSpotProblemMonitor::doTest_
const bool doTest_
Definition: BeamSpotProblemMonitor.h:54
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
BeamSpotProblemMonitor::beamSpotStatus_
double beamSpotStatus_
Definition: BeamSpotProblemMonitor.h:64
mps_update.status
status
Definition: mps_update.py:68
DcsStatus::TIBTID
Definition: DcsStatus.h:51
BeamSpotOnline::y
float y() const
Definition: BeamSpotOnline.h:49
edm::Run
Definition: Run.h:45
LuminosityBlock.h
edm
HLT enums.
Definition: AlignableModifier.h:19
BeamSpotProblemMonitor::fitNLumi_
const int fitNLumi_
Definition: BeamSpotProblemMonitor.h:51
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
BeamSpotProblemMonitor::trkSrc_
const edm::EDGetTokenT< reco::TrackCollection > trkSrc_
Definition: BeamSpotProblemMonitor.h:47
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
BeamSpotOnline::width_x
float width_x() const
Definition: BeamSpotOnline.h:58
BeamSpotProblemMonitor::processed_
bool processed_
Definition: BeamSpotProblemMonitor.h:60
edm::Handle
Definition: AssociativeIterator.h:50
BeamSpotProblemMonitor::beamSpotFromDB_
int beamSpotFromDB_
Definition: BeamSpotProblemMonitor.h:65
BeamSpotProblemMonitor::dqmBeginLuminosityBlock
void dqmBeginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
Definition: BeamSpotProblemMonitor.cc:101
BeamSpotProblemMonitor
Definition: BeamSpotProblemMonitor.h:26
BeamSpotProblemMonitor::nextlumi_
int nextlumi_
Definition: BeamSpotProblemMonitor.h:59
BeamSpotProblemMonitor::dcsStatus_
const edm::EDGetTokenT< DcsStatusCollection > dcsStatus_
Definition: BeamSpotProblemMonitor.h:45
visDQMUpload.context
context
Definition: visDQMUpload.py:37
MakerMacros.h
BeamSpotObjects.h
BeamSpotProblemMonitor::nCosmicTrk_
const int nCosmicTrk_
Definition: BeamSpotProblemMonitor.h:50
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::LuminosityBlockBase::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockBase.h:40
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
BeamSpotProblemMonitor::alarmOFFThreshold_
const int alarmOFFThreshold_
Definition: BeamSpotProblemMonitor.h:56
dqm::impl::MonitorElement::Reset
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
Definition: MonitorElement.cc:345
dqm::impl::MonitorElement::ShiftFillLast
DQM_DEPRECATED void ShiftFillLast(double y, double ye=0., int32_t xscale=1)
Definition: MonitorElement.cc:247
BeamSpotProblemMonitor::beamSpotError_
MonitorElement * beamSpotError_
Definition: BeamSpotProblemMonitor.h:70
BeamSpotProblemMonitor::lastlumi_
int lastlumi_
Definition: BeamSpotProblemMonitor.h:58
DcsStatus::TOB
Definition: DcsStatus.h:52
hgcalPlots.xtitle
xtitle
Definition: hgcalPlots.py:93
BeamSpotProblemMonitor::dqmEndLuminosityBlock
void dqmEndLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
Definition: BeamSpotProblemMonitor.cc:280
dqm::impl::MonitorElement::getTH1
virtual TH1 * getTH1()
Definition: MonitorElement.cc:972
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
dqm::impl::MonitorElement::getQReport
const MonitorElementData::QReport * getQReport(const std::string &qtname) const
get QReport corresponding to <qtname> (null pointer if QReport does not exist)
Definition: MonitorElement.cc:472
BeamSpotProblemMonitor::scalertag_
const edm::EDGetTokenT< BeamSpotOnlineCollection > scalertag_
Definition: BeamSpotProblemMonitor.h:46
BeamSpotProblemMonitor::dqmEndRun
void dqmEndRun(const edm::Run &r, const edm::EventSetup &c) override
Definition: BeamSpotProblemMonitor.cc:287
edm::ParameterSet
Definition: ParameterSet.h:47
BeamSpotProblemMonitor::beamSpotStatusLumi_
MonitorElement * beamSpotStatusLumi_
Definition: BeamSpotProblemMonitor.h:68
duplicaterechits_cfi.trackCollection
trackCollection
Definition: duplicaterechits_cfi.py:4
DcsStatus::TECm
Definition: DcsStatus.h:54
Event.h
B2GTnPMonitor_cfi.histTitle
histTitle
Definition: B2GTnPMonitor_cfi.py:112
BeamSpotProblemMonitor.h
MonitorElementData::QReport
Definition: MonitorElementCollection.h:55
iEvent
int iEvent
Definition: GenABIO.cc:224
BeamSpotProblemMonitor::debug_
const bool debug_
Definition: BeamSpotProblemMonitor.h:52
BeamSpotProblemMonitor::nTracks_
int nTracks_
Definition: BeamSpotProblemMonitor.h:49
edm::LuminosityBlockID::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockID.h:42
DcsStatus::FPIX
Definition: DcsStatus.h:56
edm::LuminosityBlockBase::id
LuminosityBlockID id() const
Definition: LuminosityBlockBase.h:44
edm::EventSetup
Definition: EventSetup.h:58
BeamSpotOnline
Definition: BeamSpotOnline.h:28
alignCSCRings.r
r
Definition: alignCSCRings.py:93
BeamSpotProblemMonitor::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: BeamSpotProblemMonitor.cc:53
dqm::impl::MonitorElement::setBinContent
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
Definition: MonitorElement.cc:682
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
BeamSpotOnline::width_y
float width_y() const
Definition: BeamSpotOnline.h:59
BeamSpotProblemMonitor::beamSpotStatusLumiAll_
MonitorElement * beamSpotStatusLumiAll_
Definition: BeamSpotProblemMonitor.h:69
BeamSpotProblemMonitor::fillPlots
void fillPlots(int &, int &, int)
Definition: BeamSpotProblemMonitor.cc:217
dqm::implementation::IBooker
Definition: DQMStore.h:43
BeamSpotProblemMonitor::onlineMode_
const bool onlineMode_
Definition: BeamSpotProblemMonitor.h:53
DcsStatus::TECp
Definition: DcsStatus.h:53
TrackCandidate.h
BeamSpotOnline::z
float z() const
Definition: BeamSpotOnline.h:50
edm::Event
Definition: Event.h:73
dqm::impl::MonitorElement::setAxisTitle
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
Definition: MonitorElement.cc:791
edm::InputTag
Definition: InputTag.h:15
BeamSpotProblemMonitor::alarmONThreshold_
const int alarmONThreshold_
Definition: BeamSpotProblemMonitor.h:55
BeamSpotProblemMonitor::bookHistograms
void bookHistograms(DQMStore::IBooker &i, const edm::Run &r, const edm::EventSetup &c) override
Definition: BeamSpotProblemMonitor.cc:70
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
BeamSpotProblemMonitor::alarmOn_
bool alarmOn_
Definition: BeamSpotProblemMonitor.h:63
hgcalPlots.ytitle
ytitle
Definition: hgcalPlots.py:1109
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
BeamSpotProblemMonitor::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: BeamSpotProblemMonitor.cc:123