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