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