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