CMS 3D CMS Logo

AlcaBeamMonitor.cc
Go to the documentation of this file.
1 /*
2  * \file AlcaBeamMonitor.cc
3  * \author Lorenzo Uplegger/FNAL
4  * modified by Simone Gennai INFN/Bicocca
5  */
6 
12 //#include "DataFormats/Scalers/interface/BeamSpotOnline.h"
22 #include <memory>
23 
24 #include <numeric>
25 
26 using namespace std;
27 using namespace edm;
28 using namespace reco;
29 
30 //----------------------------------------------------------------------------------------------------------------------
32  : monitorName_(ps.getUntrackedParameter<string>("MonitorName")),
33  primaryVertexLabel_(consumes<VertexCollection>(ps.getUntrackedParameter<InputTag>("PrimaryVertexLabel"))),
34  trackLabel_(consumes<reco::TrackCollection>(ps.getUntrackedParameter<InputTag>("TrackLabel"))),
35  scalerLabel_(consumes<BeamSpot>(ps.getUntrackedParameter<InputTag>("ScalerLabel"))),
36  beamSpotToken_(esConsumes<edm::Transition::BeginLuminosityBlock>()),
37  numberOfValuesToSave_(0) {
38  if (!monitorName_.empty())
39  monitorName_ = monitorName_ + "/";
40 
41  theBeamFitter_ = std::make_unique<BeamFitter>(ps, consumesCollector());
42  theBeamFitter_->resetTrkVector();
43  theBeamFitter_->resetLSRange();
44  theBeamFitter_->resetRefTime();
45  theBeamFitter_->resetPVFitter();
46 
47  thePVFitter_ = std::make_unique<PVFitter>(ps, consumesCollector());
48 
49  processedLumis_.clear();
50 
51  varNamesV_.push_back("x");
52  varNamesV_.push_back("y");
53  varNamesV_.push_back("z");
54  varNamesV_.push_back("sigmaX");
55  varNamesV_.push_back("sigmaY");
56  varNamesV_.push_back("sigmaZ");
57 
58  histoByCategoryNames_.insert(pair<string, string>("run", "Coordinate"));
59  histoByCategoryNames_.insert(pair<string, string>("run", "PrimaryVertex fit-DataBase"));
60  histoByCategoryNames_.insert(pair<string, string>("run", "PrimaryVertex fit-BeamFit"));
61  histoByCategoryNames_.insert(pair<string, string>("run", "PrimaryVertex fit-Scalers"));
62  histoByCategoryNames_.insert(pair<string, string>("run", "PrimaryVertex-DataBase"));
63  histoByCategoryNames_.insert(pair<string, string>("run", "PrimaryVertex-BeamFit"));
64  histoByCategoryNames_.insert(pair<string, string>("run", "PrimaryVertex-Scalers"));
65 
66  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased BeamSpotFit"));
67  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased PrimaryVertex"));
68  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased DataBase"));
69  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased Scalers"));
70  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased PrimaryVertex-DataBase fit"));
71  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased PrimaryVertex-Scalers fit"));
72  histoByCategoryNames_.insert(pair<string, string>("validation", "Lumibased Scalers-DataBase fit"));
73  histoByCategoryNames_.insert(pair<string, string>("validation", "Lumibased PrimaryVertex-DataBase"));
74  histoByCategoryNames_.insert(pair<string, string>("validation", "Lumibased PrimaryVertex-Scalers"));
75 
76  for (vector<string>::iterator itV = varNamesV_.begin(); itV != varNamesV_.end(); itV++) {
77  for (multimap<string, string>::iterator itM = histoByCategoryNames_.begin(); itM != histoByCategoryNames_.end();
78  itM++) {
79  histosMap_[*itV][itM->first][itM->second] = nullptr;
80  }
81  }
82 }
83 
86 
87  ps.addUntracked<std::string>("MonitorName", "YourSubsystemName");
88  ps.addUntracked<edm::InputTag>("PrimaryVertexLabel");
89  ps.addUntracked<edm::InputTag>("TrackLabel");
90  ps.addUntracked<edm::InputTag>("ScalerLabel");
91 
94 
95  iDesc.addDefault(ps);
96 }
97 
98 //----------------------------------------------------------------------------------------------------------------------
99 void AlcaBeamMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
100  string name;
101  string title;
102  int firstLumi = 1;
103  int lastLumi = 3000;
104  for (HistosContainer::iterator itM = histosMap_.begin(); itM != histosMap_.end(); itM++) {
105  ibooker.setCurrentFolder(monitorName_ + "Debug");
106  for (map<string, MonitorElement*>::iterator itMM = itM->second["run"].begin(); itMM != itM->second["run"].end();
107  itMM++) {
108  name = string("h") + itM->first + itMM->first;
109  title = itM->first + "_{0} " + itMM->first;
110  if (itM->first == "x" || itM->first == "y") {
111  if (itMM->first == "Coordinate") {
112  itMM->second = ibooker.book1D(name, title, 1001, -0.2525, 0.2525);
113  } else if (itMM->first == "PrimaryVertex fit-DataBase" || itMM->first == "PrimaryVertex fit-BeamFit" ||
114  itMM->first == "PrimaryVertex fit-Scalers" || itMM->first == "PrimaryVertex-DataBase" ||
115  itMM->first == "PrimaryVertex-BeamFit" || itMM->first == "PrimaryVertex-Scalers") {
116  itMM->second = ibooker.book1D(name, title, 1001, -0.02525, 0.02525);
117  } else {
118  //assert(0);
119  }
120  } else if (itM->first == "z") {
121  if (itMM->first == "Coordinate") {
122  itMM->second = ibooker.book1D(name, title, 101, -5.05, 5.05);
123  } else if (itMM->first == "PrimaryVertex fit-DataBase" || itMM->first == "PrimaryVertex fit-BeamFit" ||
124  itMM->first == "PrimaryVertex fit-Scalers") {
125  itMM->second = ibooker.book1D(name, title, 101, -0.505, 0.505);
126  } else if (itMM->first == "PrimaryVertex-DataBase" || itMM->first == "PrimaryVertex-BeamFit" ||
127  itMM->first == "PrimaryVertex-Scalers") {
128  itMM->second = ibooker.book1D(name, title, 1001, -5.005, 5.005);
129  } else {
130  //assert(0);
131  }
132  } else if (itM->first == "sigmaX" || itM->first == "sigmaY") {
133  if (itMM->first == "Coordinate") {
134  itMM->second = ibooker.book1D(name, title, 100, 0, 0.015);
135  } else if (itMM->first == "PrimaryVertex fit-DataBase" || itMM->first == "PrimaryVertex fit-BeamFit" ||
136  itMM->first == "PrimaryVertex fit-Scalers" || itMM->first == "PrimaryVertex-DataBase" ||
137  itMM->first == "PrimaryVertex-BeamFit" || itMM->first == "PrimaryVertex-Scalers") {
138  itMM->second = nullptr;
139  } else {
140  //assert(0);
141  }
142  } else if (itM->first == "sigmaZ") {
143  if (itMM->first == "Coordinate") {
144  itMM->second = ibooker.book1D(name, title, 110, 0, 11);
145  } else if (itMM->first == "PrimaryVertex fit-DataBase" || itMM->first == "PrimaryVertex fit-BeamFit" ||
146  itMM->first == "PrimaryVertex fit-Scalers" || itMM->first == "PrimaryVertex-DataBase" ||
147  itMM->first == "PrimaryVertex-BeamFit" || itMM->first == "PrimaryVertex-Scalers") {
148  itMM->second = ibooker.book1D(name, title, 101, -5.05, 5.05);
149  } else {
150  //assert(0);
151  }
152  } else {
153  //assert(0);
154  }
155  if (itMM->second != nullptr) {
156  if (itMM->first == "Coordinate") {
157  itMM->second->setAxisTitle(itM->first + "_{0} (cm)", 1);
158  } else if (itMM->first == "PrimaryVertex fit-DataBase" || itMM->first == "PrimaryVertex fit-BeamFit" ||
159  itMM->first == "PrimaryVertex fit-Scalers" || itMM->first == "PrimaryVertex-DataBase" ||
160  itMM->first == "PrimaryVertex-BeamFit" || itMM->first == "PrimaryVertex-Scalers") {
161  itMM->second->setAxisTitle(itMM->first + " " + itM->first + "_{0} (cm)", 1);
162  }
163  itMM->second->setAxisTitle("Entries", 2);
164  }
165  }
166 
167  //Making histos per Lumi
168  // x,y,z,sigmaX,sigmaY,sigmaZ
169  for (map<string, map<string, MonitorElement*> >::iterator itMM = itM->second.begin(); itMM != itM->second.end();
170  itMM++) {
171  if (itMM->first != "run") {
172  for (map<string, MonitorElement*>::iterator itMMM = itMM->second.begin(); itMMM != itMM->second.end();
173  itMMM++) {
174  name = string("h") + itM->first + itMMM->first;
175  title = itM->first + "_{0} " + itMMM->first;
176  if (itMM->first == "lumi") {
177  ibooker.setCurrentFolder(monitorName_ + "Debug");
178  itMMM->second = ibooker.book1D(name, title, lastLumi - firstLumi + 1, firstLumi - 0.5, lastLumi + 0.5);
179  itMMM->second->setEfficiencyFlag();
180  } else if (itMM->first == "validation" && itMMM->first == "Lumibased Scalers-DataBase fit") {
181  ibooker.setCurrentFolder(monitorName_ + "Validation");
182  itMMM->second = ibooker.book1D(name, title, lastLumi - firstLumi + 1, firstLumi - 0.5, lastLumi + 0.5);
183  itMMM->second->setEfficiencyFlag();
184  } else if (itMM->first == "validation" && itMMM->first != "Lumibased Scalers-DataBase fit" &&
185  (itM->first == "x" || itM->first == "y" || itM->first == "z")) {
186  ibooker.setCurrentFolder(monitorName_ + "Validation");
187  itMMM->second = ibooker.book1D(name, title, lastLumi - firstLumi + 1, firstLumi - 0.5, lastLumi + 0.5);
188  itMMM->second->setEfficiencyFlag();
189  } else if (itMM->first == "validation" &&
190  (itM->first == "sigmaX" || itM->first == "sigmaY" || itM->first == "sigmaZ")) {
191  ibooker.setCurrentFolder(monitorName_ + "Validation");
192  itMMM->second = nullptr;
193  } else {
194  LogInfo("AlcaBeamMonitorClient") << "Unrecognized category " << itMM->first;
195  // assert(0);
196  }
197  if (itMMM->second != nullptr) {
198  if (itMMM->first.find('-') != string::npos) {
199  itMMM->second->setAxisTitle(string("#Delta ") + itM->first + "_{0} (cm)", 2);
200  } else {
201  itMMM->second->setAxisTitle(itM->first + "_{0} (cm)", 2);
202  }
203  itMMM->second->setAxisTitle("Lumisection", 1);
204  }
205  }
206  }
207  }
208  }
209 
210  // create and cd into new folder
211  ibooker.setCurrentFolder(monitorName_ + "Validation");
212  //Book histograms
213  hD0Phi0_ = ibooker.bookProfile("hD0Phi0", "d_{0} vs. #phi_{0} (All Tracks)", 63, -3.15, 3.15, 100, -0.5, 0.5, "");
214  hD0Phi0_->setAxisTitle("#phi_{0} (rad)", 1);
215  hD0Phi0_->setAxisTitle("d_{0} (cm)", 2);
216 
217  ibooker.setCurrentFolder(monitorName_ + "Debug");
218  hDxyBS_ = ibooker.book1D("hDxyBS", "dxy_{0} w.r.t. Beam spot (All Tracks)", 100, -0.1, 0.1);
219  hDxyBS_->setAxisTitle("dxy_{0} w.r.t. Beam spot (cm)", 1);
220 }
221 
222 //----------------------------------------------------------------------------------------------------------------------
223 std::shared_ptr<alcabeammonitor::NoCache> AlcaBeamMonitor::globalBeginLuminosityBlock(const LuminosityBlock& iLumi,
224  const EventSetup& iSetup) const {
225  // Always create a beamspot group for each lumi weather we have results or not! Each Beamspot will be of unknown type!
226 
227  vertices_.clear();
228  beamSpotsMap_.clear();
229  processedLumis_.push_back(iLumi.id().luminosityBlock());
230  //Read BeamSpot from DB
231  ESHandle<BeamSpotObjects> bsDBHandle;
232  try {
233  bsDBHandle = iSetup.getHandle(beamSpotToken_);
234  } catch (cms::Exception& exception) {
235  LogError("AlcaBeamMonitor") << exception.what();
236  return nullptr;
237  }
238  if (bsDBHandle.isValid()) { // check the product
239  const BeamSpotObjects* spotDB = bsDBHandle.product();
240 
241  // translate from BeamSpotObjects to reco::BeamSpot
242  BeamSpot::Point apoint(spotDB->GetX(), spotDB->GetY(), spotDB->GetZ());
243 
245  for (int i = 0; i < 7; ++i) {
246  for (int j = 0; j < 7; ++j) {
247  matrix(i, j) = spotDB->GetCovariance(i, j);
248  }
249  }
250 
251  beamSpotsMap_["DB"] =
252  BeamSpot(apoint, spotDB->GetSigmaZ(), spotDB->Getdxdz(), spotDB->Getdydz(), spotDB->GetBeamWidthX(), matrix);
253 
254  BeamSpot* aSpot = &(beamSpotsMap_["DB"]);
255 
256  aSpot->setBeamWidthY(spotDB->GetBeamWidthY());
257  aSpot->setEmittanceX(spotDB->GetEmittanceX());
258  aSpot->setEmittanceY(spotDB->GetEmittanceY());
259  aSpot->setbetaStar(spotDB->GetBetaStar());
260 
261  if (spotDB->GetBeamType() == 2) {
262  aSpot->setType(reco::BeamSpot::Tracker);
263  } else {
264  aSpot->setType(reco::BeamSpot::Fake);
265  }
266  //LogInfo("AlcaBeamMonitor")
267  // << *aSpot << std::endl;
268  } else {
269  LogInfo("AlcaBeamMonitor") << "Database BeamSpot is not valid at lumi: " << iLumi.id().luminosityBlock();
270  }
271  return nullptr;
272 }
273 
274 //----------------------------------------------------------------------------------------------------------------------
275 void AlcaBeamMonitor::analyze(const Event& iEvent, const EventSetup& iSetup) {
276  //------ BeamFitter
277  theBeamFitter_->readEvent(iEvent);
278  //------ PVFitter
279  thePVFitter_->readEvent(iEvent);
280 
281  if (beamSpotsMap_.find("DB") != beamSpotsMap_.end()) {
282  //------ Tracks
284  iEvent.getByToken(trackLabel_, TrackCollection);
285  const reco::TrackCollection* tracks = TrackCollection.product();
286  for (reco::TrackCollection::const_iterator track = tracks->begin(); track != tracks->end(); ++track) {
287  hD0Phi0_->Fill(track->phi(), -1 * track->dxy());
288  hDxyBS_->Fill(-1 * track->dxy(beamSpotsMap_["DB"].position()));
289  }
290  }
291 
292  //------ Primary Vertices
294  if (iEvent.getByToken(primaryVertexLabel_, PVCollection)) {
295  vertices_.push_back(*PVCollection.product());
296  }
297 
298  if (beamSpotsMap_.find("SC") == beamSpotsMap_.end()) {
299  //BeamSpot from file for this stream is = to the scalar BeamSpot
300  Handle<BeamSpot> recoBeamSpotHandle;
301  try {
302  iEvent.getByToken(scalerLabel_, recoBeamSpotHandle);
303  } catch (cms::Exception& exception) {
304  LogInfo("AlcaBeamMonitor") << exception.what();
305  return;
306  }
307  beamSpotsMap_["SC"] = *recoBeamSpotHandle;
308  if (beamSpotsMap_["SC"].BeamWidthX() != 0) {
309  beamSpotsMap_["SC"].setType(reco::BeamSpot::Tracker);
310  } else {
311  beamSpotsMap_["SC"].setType(reco::BeamSpot::Fake);
312  }
313  }
314 }
315 
316 //----------------------------------------------------------------------------------------------------------------------
318  if (theBeamFitter_->runPVandTrkFitter()) {
319  beamSpotsMap_["BF"] = theBeamFitter_->getBeamSpot();
320  }
321  theBeamFitter_->resetTrkVector();
322  theBeamFitter_->resetLSRange();
323  theBeamFitter_->resetRefTime();
324  theBeamFitter_->resetPVFitter();
325 
326  if (thePVFitter_->runFitter()) {
327  beamSpotsMap_["PV"] = thePVFitter_->getBeamSpot();
328  }
329  thePVFitter_->resetAll();
330 
331  // "PV,BF..." Value,Error
332  map<std::string, pair<double, double> > resultsMap;
333  vector<pair<double, double> > vertexResults;
334  MonitorElement* histo = nullptr;
335  for (vector<string>::iterator itV = varNamesV_.begin(); itV != varNamesV_.end(); itV++) {
336  resultsMap.clear();
337  for (BeamSpotContainer::iterator itBS = beamSpotsMap_.begin(); itBS != beamSpotsMap_.end(); itBS++) {
338  if (itBS->second.type() == BeamSpot::Tracker) {
339  if (*itV == "x") {
340  resultsMap[itBS->first] = pair<double, double>(itBS->second.x0(), itBS->second.x0Error());
341  } else if (*itV == "y") {
342  resultsMap[itBS->first] = pair<double, double>(itBS->second.y0(), itBS->second.y0Error());
343  } else if (*itV == "z") {
344  resultsMap[itBS->first] = pair<double, double>(itBS->second.z0(), itBS->second.z0Error());
345  } else if (*itV == "sigmaX") {
346  resultsMap[itBS->first] = pair<double, double>(itBS->second.BeamWidthX(), itBS->second.BeamWidthXError());
347  } else if (*itV == "sigmaY") {
348  resultsMap[itBS->first] = pair<double, double>(itBS->second.BeamWidthY(), itBS->second.BeamWidthYError());
349  } else if (*itV == "sigmaZ") {
350  resultsMap[itBS->first] = pair<double, double>(itBS->second.sigmaZ(), itBS->second.sigmaZ0Error());
351  } else {
352  LogInfo("AlcaBeamMonitor") << "The histosMap_ has been built with the name " << *itV
353  << " that I can't recognize!";
354  //assert(0);
355  }
356  }
357  }
358  vertexResults.clear();
359  for (vector<VertexCollection>::iterator itPV = vertices_.begin(); itPV != vertices_.end(); itPV++) {
360  if (!itPV->empty()) {
361  for (VertexCollection::const_iterator pv = itPV->begin(); pv != itPV->end(); pv++) {
362  if (pv->isFake() || pv->tracksSize() < 10)
363  continue;
364  if (*itV == "x") {
365  vertexResults.push_back(pair<double, double>(pv->x(), pv->xError()));
366  } else if (*itV == "y") {
367  vertexResults.push_back(pair<double, double>(pv->y(), pv->yError()));
368  } else if (*itV == "z") {
369  vertexResults.push_back(pair<double, double>(pv->z(), pv->zError()));
370  } else if (*itV != "sigmaX" && *itV != "sigmaY" && *itV != "sigmaZ") {
371  LogInfo("AlcaBeamMonitor") << "The histosMap_ has been built with the name " << *itV
372  << " that I can't recognize!";
373  //assert(0);
374  }
375  }
376  }
377  }
378 
379  for (multimap<string, string>::iterator itM = histoByCategoryNames_.begin(); itM != histoByCategoryNames_.end();
380  itM++) {
381  if ((histo = histosMap_[*itV][itM->first][itM->second]) == nullptr)
382  continue;
383  if (itM->second == "Coordinate") {
384  if (beamSpotsMap_.find("DB") != beamSpotsMap_.end()) {
385  histo->Fill(resultsMap["DB"].first);
386  }
387  } else if (itM->second == "PrimaryVertex fit-DataBase") {
388  if (resultsMap.find("PV") != resultsMap.end() && resultsMap.find("DB") != resultsMap.end()) {
389  histo->Fill(resultsMap["PV"].first - resultsMap["DB"].first);
390  }
391  } else if (itM->second == "PrimaryVertex fit-BeamFit") {
392  if (resultsMap.find("PV") != resultsMap.end() && resultsMap.find("BF") != resultsMap.end()) {
393  histo->Fill(resultsMap["PV"].first - resultsMap["BF"].first);
394  }
395  } else if (itM->second == "PrimaryVertex fit-Scalers") {
396  if (resultsMap.find("PV") != resultsMap.end() && resultsMap.find("SC") != resultsMap.end()) {
397  histo->Fill(resultsMap["PV"].first - resultsMap["SC"].first);
398  }
399  } else if (itM->second == "PrimaryVertex-DataBase") {
400  if (resultsMap.find("PV") != resultsMap.end() && resultsMap.find("DB") != resultsMap.end()) {
401  for (vector<pair<double, double> >::iterator itPV = vertexResults.begin(); itPV != vertexResults.end();
402  itPV++) {
403  histo->Fill(itPV->first - resultsMap["DB"].first);
404  }
405  }
406  } else if (itM->second == "PrimaryVertex-BeamFit") {
407  if (resultsMap.find("PV") != resultsMap.end() && resultsMap.find("BF") != resultsMap.end()) {
408  for (vector<pair<double, double> >::iterator itPV = vertexResults.begin(); itPV != vertexResults.end();
409  itPV++) {
410  histo->Fill(itPV->first - resultsMap["BF"].first);
411  }
412  }
413  } else if (itM->second == "PrimaryVertex-Scalers") {
414  if (resultsMap.find("PV") != resultsMap.end() && resultsMap.find("SC") != resultsMap.end()) {
415  for (vector<pair<double, double> >::iterator itPV = vertexResults.begin(); itPV != vertexResults.end();
416  itPV++) {
417  histo->Fill(itPV->first - resultsMap["SC"].first);
418  }
419  }
420  } else if (itM->second == "Lumibased BeamSpotFit") {
421  if (resultsMap.find("BF") != resultsMap.end()) {
422  histo->setBinContent(iLumi.id().luminosityBlock(), resultsMap["BF"].first);
423  histo->setBinError(iLumi.id().luminosityBlock(), resultsMap["BF"].second);
424  }
425  } else if (itM->second == "Lumibased PrimaryVertex") {
426  if (resultsMap.find("PV") != resultsMap.end()) {
427  histo->setBinContent(iLumi.id().luminosityBlock(), resultsMap["PV"].first);
428  histo->setBinError(iLumi.id().luminosityBlock(), resultsMap["PV"].second);
429  }
430  } else if (itM->second == "Lumibased DataBase") {
431  if (resultsMap.find("DB") != resultsMap.end()) {
432  histo->setBinContent(iLumi.id().luminosityBlock(), resultsMap["DB"].first);
433  histo->setBinError(iLumi.id().luminosityBlock(), resultsMap["DB"].second);
434  }
435  } else if (itM->second == "Lumibased Scalers") {
436  if (resultsMap.find("SC") != resultsMap.end()) {
437  histo->setBinContent(iLumi.id().luminosityBlock(), resultsMap["SC"].first);
438  histo->setBinError(iLumi.id().luminosityBlock(), resultsMap["SC"].second);
439  }
440  } else if (itM->second == "Lumibased PrimaryVertex-DataBase fit") {
441  if (resultsMap.find("PV") != resultsMap.end() && resultsMap.find("DB") != resultsMap.end()) {
442  histo->setBinContent(iLumi.id().luminosityBlock(), resultsMap["PV"].first - resultsMap["DB"].first);
443  histo->setBinError(iLumi.id().luminosityBlock(),
444  std::sqrt(std::pow(resultsMap["PV"].second, 2) + std::pow(resultsMap["DB"].second, 2)));
445  }
446  } else if (itM->second == "Lumibased PrimaryVertex-Scalers fit") {
447  if (resultsMap.find("PV") != resultsMap.end() && resultsMap.find("SC") != resultsMap.end()) {
448  histo->setBinContent(iLumi.id().luminosityBlock(), resultsMap["PV"].first - resultsMap["SC"].first);
449  histo->setBinError(iLumi.id().luminosityBlock(),
450  std::sqrt(std::pow(resultsMap["PV"].second, 2) + std::pow(resultsMap["SC"].second, 2)));
451  }
452  } else if (itM->second == "Lumibased Scalers-DataBase fit") {
453  if (resultsMap.find("SC") != resultsMap.end() && resultsMap.find("DB") != resultsMap.end()) {
454  histo->setBinContent(iLumi.id().luminosityBlock(), resultsMap["SC"].first - resultsMap["DB"].first);
455  histo->setBinError(iLumi.id().luminosityBlock(),
456  std::sqrt(std::pow(resultsMap["SC"].second, 2) + std::pow(resultsMap["DB"].second, 2)));
457  }
458  } else if (itM->second == "Lumibased PrimaryVertex-DataBase") {
459  if (resultsMap.find("DB") != resultsMap.end() && !vertexResults.empty()) {
460  for (vector<pair<double, double> >::iterator itPV = vertexResults.begin(); itPV != vertexResults.end();
461  itPV++) {
462  histo->setBinContent(iLumi.id().luminosityBlock(), (*itPV).first - resultsMap["DB"].first);
463  histo->setBinError(iLumi.id().luminosityBlock(),
464  std::sqrt(std::pow((*itPV).second, 2) + std::pow(resultsMap["DB"].second, 2)));
465  }
466  }
467  } else if (itM->second == "Lumibased PrimaryVertex-Scalers") {
468  if (resultsMap.find("SC") != resultsMap.end() && !vertexResults.empty()) {
469  for (vector<pair<double, double> >::iterator itPV = vertexResults.begin(); itPV != vertexResults.end();
470  itPV++) {
471  histo->setBinContent(iLumi.id().luminosityBlock(), (*itPV).first - resultsMap["SC"].first);
472  histo->setBinError(iLumi.id().luminosityBlock(),
473  std::sqrt(std::pow((*itPV).second, 2) + std::pow(resultsMap["SC"].second, 2)));
474  }
475  }
476  }
477  // else if(itM->second == "Lumibased Scalers-DataBase"){
478  // if(resultsMap.find("SC") != resultsMap.end() && resultsMap.find("DB") != resultsMap.end()){
479  // itHHH->second->Fill(bin,resultsMap["SC"].first-resultsMap["DB"].first);
480  // }
481  // }
482  else {
483  LogInfo("AlcaBeamMonitor") << "The histosMap_ have a histogram named " << itM->second
484  << " that I can't recognize in this loop!";
485  //assert(0);
486  }
487  }
488  }
489 }
490 
492  if (processedLumis_.empty()) {
493  return;
494  }
495 
496  const double bigNumber = 1000000.;
497  std::sort(processedLumis_.begin(), processedLumis_.end());
498  int firstLumi = *processedLumis_.begin();
499  int lastLumi = *(--processedLumis_.end());
500 
501  for (HistosContainer::iterator itH = histosMap_.begin(); itH != histosMap_.end(); itH++) {
502  for (map<string, map<string, MonitorElement*> >::iterator itHH = itH->second.begin(); itHH != itH->second.end();
503  itHH++) {
504  double min = bigNumber;
505  double max = -bigNumber;
506  double minDelta = bigNumber;
507  double maxDelta = -bigNumber;
508  // double minDeltaProf = bigNumber;
509  // double maxDeltaProf = -bigNumber;
510  if (itHH->first != "run") {
511  for (map<string, MonitorElement*>::iterator itHHH = itHH->second.begin(); itHHH != itHH->second.end();
512  itHHH++) {
513  if (itHHH->second != nullptr) {
514  for (int bin = 1; bin <= itHHH->second->getTH1()->GetNbinsX(); bin++) {
515  if (itHHH->second->getTH1()->GetBinError(bin) != 0 || itHHH->second->getTH1()->GetBinContent(bin) != 0) {
516  if (itHHH->first == "Lumibased BeamSpotFit" || itHHH->first == "Lumibased PrimaryVertex" ||
517  itHHH->first == "Lumibased DataBase" || itHHH->first == "Lumibased Scalers") {
518  if (min > itHHH->second->getTH1()->GetBinContent(bin)) {
519  min = itHHH->second->getTH1()->GetBinContent(bin);
520  }
521  if (max < itHHH->second->getTH1()->GetBinContent(bin)) {
522  max = itHHH->second->getTH1()->GetBinContent(bin);
523  }
524  } else if (itHHH->first == "Lumibased PrimaryVertex-DataBase fit" ||
525  itHHH->first == "Lumibased PrimaryVertex-Scalers fit" ||
526  itHHH->first == "Lumibased Scalers-DataBase fit" ||
527  itHHH->first == "Lumibased PrimaryVertex-DataBase" ||
528  itHHH->first == "Lumibased PrimaryVertex-Scalers") {
529  if (minDelta > itHHH->second->getTH1()->GetBinContent(bin)) {
530  minDelta = itHHH->second->getTH1()->GetBinContent(bin);
531  }
532  if (maxDelta < itHHH->second->getTH1()->GetBinContent(bin)) {
533  maxDelta = itHHH->second->getTH1()->GetBinContent(bin);
534  }
535  } else {
536  LogInfo("AlcaBeamMonitorClient") << "The histosMap_ have a histogram named " << itHHH->first
537  << " that I can't recognize in this loop!";
538  // assert(0);
539  }
540  }
541  }
542  }
543  }
544  for (map<string, MonitorElement*>::iterator itHHH = itHH->second.begin(); itHHH != itHH->second.end();
545  itHHH++) {
546  if (itHHH->second != nullptr) {
547  if (itHHH->first == "Lumibased BeamSpotFit" || itHHH->first == "Lumibased PrimaryVertex" ||
548  itHHH->first == "Lumibased DataBase" || itHHH->first == "Lumibased Scalers") {
549  if ((max == -bigNumber && min == bigNumber) || max - min == 0) {
550  itHHH->second->getTH1()->SetMinimum(itHHH->second->getTH1()->GetMinimum() - 0.01);
551  itHHH->second->getTH1()->SetMaximum(itHHH->second->getTH1()->GetMaximum() + 0.01);
552  } else {
553  itHHH->second->getTH1()->SetMinimum(min - 0.1 * (max - min));
554  itHHH->second->getTH1()->SetMaximum(max + 0.1 * (max - min));
555  }
556  } else if (itHHH->first == "Lumibased PrimaryVertex-DataBase fit" ||
557  itHHH->first == "Lumibased PrimaryVertex-Scalers fit" ||
558  itHHH->first == "Lumibased Scalers-DataBase fit" ||
559  itHHH->first == "Lumibased PrimaryVertex-DataBase" ||
560  itHHH->first == "Lumibased PrimaryVertex-Scalers") {
561  if ((maxDelta == -bigNumber && minDelta == bigNumber) || maxDelta - minDelta == 0) {
562  itHHH->second->getTH1()->SetMinimum(itHHH->second->getTH1()->GetMinimum() - 0.01);
563  itHHH->second->getTH1()->SetMaximum(itHHH->second->getTH1()->GetMaximum() + 0.01);
564  } else {
565  itHHH->second->getTH1()->SetMinimum(minDelta - 2 * (maxDelta - minDelta));
566  itHHH->second->getTH1()->SetMaximum(maxDelta + 2 * (maxDelta - minDelta));
567  }
568  } else {
569  LogInfo("AlcaBeamMonitorClient") << "The histosMap_ have a histogram named " << itHHH->first
570  << " that I can't recognize in this loop!";
571  }
572  itHHH->second->getTH1()->GetXaxis()->SetRangeUser(firstLumi - 0.5, lastLumi + 0.5);
573  }
574  }
575  }
576  }
577  }
578 }
PVFitter.h
AlcaBeamMonitor::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: AlcaBeamMonitor.cc:99
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
BeamSpotObjects::GetBeamWidthY
double GetBeamWidthY() const
get average transverse beam width
Definition: BeamSpotObjects.h:77
BeamSpotObjects::Getdxdz
double Getdxdz() const
get dxdz slope, crossing angle in XZ
Definition: BeamSpotObjects.h:79
dqm::impl::MonitorElement
Definition: MonitorElement.h:98
Handle.h
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
mps_fire.i
i
Definition: mps_fire.py:428
reco::BeamSpot::setBeamWidthY
void setBeamWidthY(double v)
Definition: BeamSpot.h:105
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
MessageLogger.h
makeMuonMisalignmentScenario.matrix
list matrix
Definition: makeMuonMisalignmentScenario.py:141
ESHandle.h
align::BeamSpot
Definition: StructureType.h:89
AlcaBeamMonitor::vertices_
std::vector< reco::VertexCollection > vertices_
Definition: AlcaBeamMonitor.h:81
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
min
T min(T a, T b)
Definition: MathUtil.h:58
BeamSpotObjects::GetSigmaZ
double GetSigmaZ() const
get sigma Z, RMS bunch length
Definition: BeamSpotObjects.h:73
LuminosityBlock.h
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
dqm::impl::MonitorElement::setEfficiencyFlag
void setEfficiencyFlag()
Definition: MonitorElement.h:267
BeamSpotObjects::GetBeamType
int GetBeamType() const
get beam type
Definition: BeamSpotObjects.h:101
BeamSpotObjects::GetZ
double GetZ() const
get Z beam position
Definition: BeamSpotObjects.h:71
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
timingPdfMaker.histo
histo
Definition: timingPdfMaker.py:279
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
edm::EDConsumerBase::consumesCollector
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Definition: EDConsumerBase.cc:46
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
AlcaBeamMonitor
Definition: AlcaBeamMonitor.h:34
AlcaBeamMonitor::globalEndLuminosityBlock
void globalEndLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &iSetup) override
Definition: AlcaBeamMonitor.cc:317
allConversions_cfi.maxDelta
maxDelta
Definition: allConversions_cfi.py:44
edm::Handle< reco::TrackCollection >
AlcaBeamMonitor::monitorName_
std::string monitorName_
Definition: AlcaBeamMonitor.h:57
dqmdumpme.first
first
Definition: dqmdumpme.py:55
AlcaBeamMonitor.h
BeamSpotPI::lastLumi
Definition: BeamSpotPayloadInspectorHelper.h:38
align::Tracker
Definition: StructureType.h:70
AlcaBeamMonitor::varNamesV_
std::vector< std::string > varNamesV_
Definition: AlcaBeamMonitor.h:79
MakerMacros.h
PVFitter::fillDescription
static void fillDescription(edm::ParameterSetDescription &)
Definition: PVFitter.cc:97
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
Service.h
AlcaBeamMonitor::beamSpotsMap_
BeamSpotContainer beamSpotsMap_
Definition: AlcaBeamMonitor.h:76
L1TEGammaOffline_cfi.PVCollection
PVCollection
Definition: L1TEGammaOffline_cfi.py:34
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
BeamFitter::fillDescription
static void fillDescription(edm::ParameterSetDescription &)
Definition: BeamFitter.cc:224
reco::BeamSpot
Definition: BeamSpot.h:21
reco::BeamSpot::Tracker
Definition: BeamSpot.h:24
Run.h
edm::ESHandle
Definition: DTSurvey.h:22
dqm::implementation::IBooker::bookProfile
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:322
BeamSpotObjects::GetCovariance
double GetCovariance(int i, int j) const
get i,j element of the full covariance matrix 7x7
Definition: BeamSpotObjects.h:83
reco::BeamSpot::Fake
Definition: BeamSpot.h:24
edm::Transition::BeginLuminosityBlock
AlcaBeamMonitor::dqmEndRun
void dqmEndRun(edm::Run const &, edm::EventSetup const &) override
Definition: AlcaBeamMonitor.cc:491
AlcaBeamMonitor::globalBeginLuminosityBlock
std::shared_ptr< alcabeammonitor::NoCache > globalBeginLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &iSetup) const override
Definition: AlcaBeamMonitor.cc:223
AlcaBeamMonitor::AlcaBeamMonitor
AlcaBeamMonitor(const edm::ParameterSet &)
Definition: AlcaBeamMonitor.cc:31
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
AlcaBeamMonitor::hD0Phi0_
MonitorElement * hD0Phi0_
Definition: AlcaBeamMonitor.h:71
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
BeamSpotObjects::GetBetaStar
double GetBetaStar() const
get beta star
Definition: BeamSpotObjects.h:107
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
BeamSpotObjects::GetEmittanceX
double GetEmittanceX() const
get emittance
Definition: BeamSpotObjects.h:103
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
BeamSpotObjects::GetY
double GetY() const
get Y beam position
Definition: BeamSpotObjects.h:69
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
AlcaBeamMonitor::primaryVertexLabel_
const edm::EDGetTokenT< reco::VertexCollection > primaryVertexLabel_
Definition: AlcaBeamMonitor.h:58
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::LuminosityBlockID::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockID.h:42
edm::LuminosityBlockBase::id
LuminosityBlockID id() const
Definition: LuminosityBlockBase.h:44
AlcaBeamMonitor::processedLumis_
std::vector< int > processedLumis_
Definition: AlcaBeamMonitor.h:68
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:148
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
BeamSpotObjects
Definition: BeamSpotObjects.h:20
edm::EventSetup
Definition: EventSetup.h:57
reco::BeamSpot::CovarianceMatrix
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:29
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
AlcaBeamMonitor::scalerLabel_
const edm::EDGetTokenT< reco::BeamSpot > scalerLabel_
Definition: AlcaBeamMonitor.h:60
edm::ESHandleBase::isValid
bool isValid() const
Definition: ESHandle.h:44
AlcaBeamMonitor::histoByCategoryNames_
std::multimap< std::string, std::string > histoByCategoryNames_
Definition: AlcaBeamMonitor.h:80
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
BeamSpotObjects::GetBeamWidthX
double GetBeamWidthX() const
get average transverse beam width
Definition: BeamSpotObjects.h:75
AlcaBeamMonitor::analyze
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: AlcaBeamMonitor.cc:275
AlcaBeamMonitor::thePVFitter_
std::unique_ptr< PVFitter > thePVFitter_
Definition: AlcaBeamMonitor.h:66
AlcaBeamMonitor::theBeamFitter_
std::unique_ptr< BeamFitter > theBeamFitter_
Definition: AlcaBeamMonitor.h:65
AlcaBeamMonitor::trackLabel_
const edm::EDGetTokenT< reco::TrackCollection > trackLabel_
Definition: AlcaBeamMonitor.h:59
std
Definition: JetResolutionObject.h:76
BeamSpotObjects::GetEmittanceY
double GetEmittanceY() const
get emittance
Definition: BeamSpotObjects.h:105
BeamSpotObjects::Getdydz
double Getdydz() const
get dydz slope, crossing angle in YZ
Definition: BeamSpotObjects.h:81
AlcaBeamMonitor::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: AlcaBeamMonitor.cc:84
AlcaBeamMonitor::histosMap_
HistosContainer histosMap_
Definition: AlcaBeamMonitor.h:77
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
dqm::implementation::IBooker
Definition: DQMStore.h:43
BeamFitter.h
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
ConsumesCollector.h
cms::Exception
Definition: Exception.h:70
reco::BeamSpot::Point
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:27
genParticles_cff.map
map
Definition: genParticles_cff.py:11
View.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
AlcaBeamMonitor::beamSpotToken_
const edm::ESGetToken< BeamSpotObjects, BeamSpotObjectsRcd > beamSpotToken_
Definition: AlcaBeamMonitor.h:61
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
AlcaBeamMonitor::hDxyBS_
MonitorElement * hDxyBS_
Definition: AlcaBeamMonitor.h:72
BeamSpotObjects::GetX
double GetX() const
get X beam position
Definition: BeamSpotObjects.h:67
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:800
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
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