CMS 3D CMS Logo

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