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 
7 
8 
9 
27 
32 
33 #include <numeric>
34 #include <math.h>
35 #include <TMath.h>
36 #include <iostream>
37 #include <TStyle.h>
38 
39 using namespace std;
40 using namespace edm;
41 
42 
43 #define buffTime (23)
44 
45 //
46 // constructors and destructor
47 //
49  Ntracks_(0), fitNLumi_(0), ALARM_ON_(false), BeamSpotStatus_(0), BeamSpotFromDB_(0){
50 
51  parameters_ = ps;
52  monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","YourSubsystemName");
53  nCosmicTrk_ = parameters_.getUntrackedParameter<int>("nCosmicTrk");
54  dcsStatus_ = consumes<DcsStatusCollection>(
56  scalertag_ = consumes<BeamSpotOnlineCollection>(
57  parameters_.getUntrackedParameter<InputTag>("scalarBSCollection"));
58  trkSrc_ = consumes<reco::TrackCollection>(
60  intervalInSec_ = parameters_.getUntrackedParameter<int>("timeInterval",920);//40 LS X 23"
61  debug_ = parameters_.getUntrackedParameter<bool>("Debug");
62  onlineMode_ = parameters_.getUntrackedParameter<bool>("OnlineMode");
63  alarmONThreshold_ = parameters_.getUntrackedParameter<int>("AlarmONThreshold");
64  alarmOFFThreshold_= parameters_.getUntrackedParameter<int>("AlarmOFFThreshold");
65  doTest_ =parameters_.getUntrackedParameter<bool>("doTest");
66 
68  if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
69 
70 
71  if (fitNLumi_ <= 0) fitNLumi_ = 1;
72  lastlumi_ = 0;
73  nextlumi_ = 0;
74  processed_ = false;
75 }
76 
77 
79 }
80 
81 
82 //--------------------------------------------------------
84 
85 
86  // create and cd into new folder
87  dbe_->setCurrentFolder(monitorName_+"FitFromScalars");
88 
89  /* S.Dutta : Commenting out these variables are not used and giving error with "-Werror=unused-variable" option
90  int nbins = alarmOFFThreshold_;
91  double hiRange = (alarmOFFThreshold_+0.5);*/
92 
93  const int nvar_ = 1;
94  string coord[nvar_] = {"BeamSpotStatus"};
95  /* S.Dutta : Commenting out these variables are not used and giving error with "-Werror=unused-variable" option
96  string label[nvar_] = {"BeamSpotStatus "};*/
97 
98  for (int i = 0; i < 1; i++) {
99  dbe_->setCurrentFolder(monitorName_+"FitFromScalars");
100  for (int ic=0; ic<nvar_; ++ic) {
101  TString histName(coord[ic]);
102  TString histTitle(coord[ic]);
103  string ytitle("Problem (-1) / OK (1)");
104  string xtitle("");
105  string options("E1");
106  bool createHisto = true;
107  switch(i){
108 
109  case 0:
110  histName += "_lumi";
111  xtitle = "Lumisection";
112 
113  if (createHisto) {
114  hs[histName] = dbe_->book1D(histName,histTitle,40,0.5,40.5);
115  hs[histName]->setAxisTitle(xtitle,1);
116  hs[histName]->setAxisTitle(ytitle,2);
117 
118  histName += "_all";
119  histTitle += " all";
120  hs[histName] = dbe_->book1D(histName,histTitle,40,0.5,40.5);
121  hs[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
122  hs[histName]->setAxisTitle(xtitle,1);
123  hs[histName]->setAxisTitle(ytitle,2);
124 
125  }//create histo
126  }
127  }
128  }
129 
130  BeamSpotError = dbe_->book1D("BeamSpotError","ERROR: Beamspot missing from scalars",20,0.5,20.5);
131  BeamSpotError->setAxisTitle("# of consecutive LSs with problem",1);
132  BeamSpotError->setAxisTitle("Problem with scalar BeamSpot",2);
133 
134 
135  dbe_->setCurrentFolder(monitorName_+"FitFromScalars");
136 
137 
138 
139 }
140 
141 //--------------------------------------------------------
143 
144 
145  if (debug_) {
146  edm::LogInfo("BeamSpotProblemMonitor") << "TimeOffset = ";
147  }
148 
149 }
150 
151 //--------------------------------------------------------
153  const EventSetup& context) {
154  int nthlumi = lumiSeg.luminosityBlock();
155 
156 
157  if (onlineMode_) {
158  if (nthlumi > nextlumi_) {
159  FillPlots(lumiSeg,lastlumi_,nextlumi_,nthlumi);
160  nextlumi_ = nthlumi;
161  edm::LogInfo("BeamSpotProblemMonitor") << "beginLuminosityBlock:: Next Lumi to Fit: " << nextlumi_ << endl;
162  }
163  }
164  else{
165  if (processed_) FillPlots(lumiSeg,lastlumi_,nextlumi_,nthlumi);
166  nextlumi_ = nthlumi;
167  edm::LogInfo("BeamSpotProblemMonitor") << " beginLuminosityBlock:: Next Lumi to Fit: " << nextlumi_ << endl;
168  }
169 
170  if (processed_) processed_ = false;
171  edm::LogInfo("BeamSpotProblemMonitor") << " beginLuminosityBlock:: Begin of Lumi: " << nthlumi << endl;
172 }
173 
174 
175 
176 
177 // ----------------------------------------------------------
179  const EventSetup& iSetup ) {
180  const int nthlumi = iEvent.luminosityBlock();
181 
182 
183  if (onlineMode_ && (nthlumi < nextlumi_)) {
184  edm::LogInfo("BeamSpotProblemMonitor") << "analyze:: Spilt event from previous lumi section!" << std::endl;
185  return;
186  }
187  if (onlineMode_ && (nthlumi > nextlumi_)) {
188  edm::LogInfo("BeamSpotProblemMonitor") << "analyze:: Spilt event from next lumi section!!!" << std::endl;
189  return;
190  }
191 
192  BeamSpotStatus_ = 0.;
193 
194 
195  // Checking TK status
196  Handle<DcsStatusCollection> dcsStatus;
197  iEvent.getByToken(dcsStatus_, dcsStatus);
198  for (int i=0;i<6;i++) dcsTk[i]=true;
199  for (DcsStatusCollection::const_iterator dcsStatusItr = dcsStatus->begin();
200  dcsStatusItr != dcsStatus->end(); ++dcsStatusItr) {
201  if (!dcsStatusItr->ready(DcsStatus::BPIX)) dcsTk[0]=false;
202  if (!dcsStatusItr->ready(DcsStatus::FPIX)) dcsTk[1]=false;
203  if (!dcsStatusItr->ready(DcsStatus::TIBTID)) dcsTk[2]=false;
204  if (!dcsStatusItr->ready(DcsStatus::TOB)) dcsTk[3]=false;
205  if (!dcsStatusItr->ready(DcsStatus::TECp)) dcsTk[4]=false;
206  if (!dcsStatusItr->ready(DcsStatus::TECm)) dcsTk[5]=false;
207  }
208 
209  bool AllTkOn = true;
210  for (int i=0; i<5; i++)
211  {
212  if (!dcsTk[i]) {
213  AllTkOn = false;
214 
215  }
216  }
217 
218 
219  //If tracker is ON and collision is going on then must be few track ther
221  iEvent.getByToken(trkSrc_, TrackCollection);
222  const reco::TrackCollection *tracks = TrackCollection.product();
223  for ( reco::TrackCollection::const_iterator track = tracks->begin();track != tracks->end();++track )
224  {
225  if(track->pt() > 1.0)Ntracks_++;
226  if(Ntracks_> 200) break;
227  }
228 
229 
230 
231  // get scalar collection and BeamSpot
233  iEvent.getByToken( scalertag_, handleScaler);
234 
235  // beam spot scalar object
236  BeamSpotOnline spotOnline;
237 
238  bool fallBackToDB=false;
239  ALARM_ON_ = false;
240 
241 
242  if (handleScaler->size()!=0)
243  {
244  spotOnline = * ( handleScaler->begin() );
245 
246  // check if we have a valid beam spot fit result from online DQM thrugh scalars
247  if ( spotOnline.x() == 0. &&
248  spotOnline.y() == 0. &&
249  spotOnline.z() == 0. &&
250  spotOnline.width_x() == 0. &&
251  spotOnline.width_y() == 0. )
252  {
253  fallBackToDB=true;
254  }
255  }
256 
257 
258  //For testing set it false for every LSs
259  if(doTest_)fallBackToDB= true;
260 
261  //based on last event of this lumi only as it overwrite it
262  if(AllTkOn && fallBackToDB){BeamSpotStatus_ = -1.;} //i.e,from DB
263  if(AllTkOn && (!fallBackToDB)){BeamSpotStatus_ = 1.;} //i.e,from online DQM
264 
265 
266  //when collision at least few tracks should be there otherwise it give false ALARM
267  if(AllTkOn && Ntracks_ < nCosmicTrk_)BeamSpotStatus_ = 0.;
268 
269 
270  dbe_->setCurrentFolder(monitorName_+"FitFromScalars/");
271 
272 
273  processed_ = true;
274 
275 }
276 
277 //--------------------------------------------------------
278 void BeamSpotProblemMonitor::FillPlots(const LuminosityBlock& lumiSeg,int &lastlumi,int &nextlumi,int &nthlumi){
279 
280  if (onlineMode_ && (nthlumi <= nextlumi)) return;
281 
282  int currentlumi = nextlumi;
283  lastlumi = currentlumi;
284 
285  //Chcek status and if lumi are in succession when fall to DB
286  if(BeamSpotStatus_== -1. && (lastlumi+1) == nthlumi)
287  {BeamSpotFromDB_++;
288  }
289  else{
290  BeamSpotFromDB_=0;} //if not in succesion or status is ok then set zero
291 
292 
293  if(BeamSpotFromDB_ >= alarmONThreshold_ ){ ALARM_ON_ =true; //set the audio alarm true after N successive LSs
294  }
295 
296  if(BeamSpotFromDB_ > alarmOFFThreshold_ ){ ALARM_ON_ =false; //set the audio alarm true after 10 successive LSs
297  BeamSpotFromDB_=0; //reset it for new incident
298  }
299 
300 
301 
302  if (onlineMode_)
303  { // filling LS gap For status plot
304  const int countLS_bs = hs["BeamSpotStatus_lumi"]->getTH1()->GetEntries();
305  int LSgap_bs = currentlumi/fitNLumi_ - countLS_bs;
306  if (currentlumi%fitNLumi_ == 0)LSgap_bs--;
307 
308 
309  // filling previous fits if LS gap ever exists
310  for (int ig = 0; ig < LSgap_bs; ig++) {
311  hs["BeamSpotStatus_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );//x0 , x0err, fitNLumi_; see DQMCore....
312  }
313 
314  hs["BeamSpotStatus_lumi"]->ShiftFillLast( BeamSpotStatus_, 0. , fitNLumi_ ); //BeamSpotStatus_ =>0. (no collision, no tracks); =>1 (OK from scaler), =>-1 (No scalar results)
315  hs["BeamSpotStatus_lumi_all"]->setBinContent( currentlumi, BeamSpotStatus_);
316 
317 
318  }//onlineMode_
319  else {
320  hs["BeamSpotStatus_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
321  }
322 
323  //Reset it here for next lumi
324  BeamSpotError->Reset();
326 
327 
328  //Get quality report
329  MonitorElement* myQReport = dbe_->get(monitorName_+"FitFromScalars/BeamSpotError");
330 
331  const QReport * BeamSpotQReport = myQReport->getQReport("BeamSpotOnlineTest");
332 
333  if(BeamSpotQReport){
334  /* S.Dutta : Commenting out these variables are not used and giving error with "-Werror=unused-variable" option
335  float qtresult = BeamSpotQReport->getQTresult();
336  int qtstatus = BeamSpotQReport->getStatus() ; // get QT status value (see table below) */
337  std::string qtmessage = BeamSpotQReport->getMessage() ; // get the whole QT result message
338  }
339 
340 
341  Ntracks_= 0;
342 
343 }
344 
345 //--------------------------------------------------------
347  const EventSetup& iSetup) {
348  int nthlumi = lumiSeg.id().luminosityBlock();
349  edm::LogInfo("BeamSpotProblemMonitor") << "endLuminosityBlock:: Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
350 
351  if (onlineMode_ && nthlumi < nextlumi_) return;
352 
353 }
354 //-------------------------------------------------------
355 
356 void BeamSpotProblemMonitor::endRun(const Run& r, const EventSetup& context){
357 
358 if(debug_)edm::LogInfo("BeamSpotProblemMonitor") << "endRun:: Clearing all the Maps "<<endl;
359  //Reset it end of job
360  BeamSpotError->Reset();
361 }
362 
363 //--------------------------------------------------------
365  const EventSetup& iSetup){
366  if (!onlineMode_) endLuminosityBlock(lumiSeg, iSetup);
367  //Reset it end of job
368  BeamSpotError->Reset();
369 }
370 
372 
373 // Local Variables:
374 // show-trailing-whitespace: t
375 // truncate-lines: t
376 // End:
LuminosityBlockID id() const
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
T getUntrackedParameter(std::string const &, T const &) const
const QReport * getQReport(const std::string &qtname) const
get QReport corresponding to <qtname> (null pointer if QReport does not exist)
edm::EDGetTokenT< DcsStatusCollection > dcsStatus_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
float y() const
float x() const
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
std::map< TString, MonitorElement * > hs
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
float z() const
float width_y() const
const std::string & getMessage(void) const
get message attached to test
Definition: QReport.h:24
void Fill(long long x)
LuminosityBlockNumber_t luminosityBlock() const
edm::EDGetTokenT< BeamSpotOnlineCollection > scalertag_
int iEvent
Definition: GenABIO.cc:230
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
BeamSpotProblemMonitor(const edm::ParameterSet &)
void analyze(const edm::Event &e, const edm::EventSetup &c) override
virtual void endJob()
Definition: EDAnalyzer.h:80
void endRun(const edm::Run &r, const edm::EventSetup &c) override
T const * product() const
Definition: Handle.h:81
LuminosityBlockNumber_t luminosityBlock() const
HLT enums.
float width_x() const
edm::EDGetTokenT< reco::TrackCollection > trkSrc_
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
Definition: Run.h:42
void FillPlots(const edm::LuminosityBlock &lumiSeg, int &, int &, int &)