CMS 3D CMS Logo

AlcaBeamMonitorClient.cc
Go to the documentation of this file.
1 /*
2  * \file AlcaBeamMonitorClient.cc
3  * \author Lorenzo Uplegger/FNAL
4  *
5  */
6 
8 #include <numeric>
16 //#include <iostream>
17 
18 using namespace std;
19 using namespace edm;
20 // using namespace reco;
21 
22 //----------------------------------------------------------------------------------------------------------------------
24  : parameters_(ps),
25  monitorName_(parameters_.getUntrackedParameter<string>("MonitorName", "YourSubsystemName")),
26  numberOfValuesToSave_(0) {
27  dbe_ = Service<DQMStore>().operator->();
28 
29  if (!monitorName_.empty())
30  monitorName_ = monitorName_ + "/";
31 
32  varNamesV_.push_back("x");
33  varNamesV_.push_back("y");
34  varNamesV_.push_back("z");
35  varNamesV_.push_back("sigmaX");
36  varNamesV_.push_back("sigmaY");
37  varNamesV_.push_back("sigmaZ");
38 
39  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased BeamSpotFit"));
40  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased PrimaryVertex"));
41  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased DataBase"));
42  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased Scalers"));
43  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased PrimaryVertex-DataBase fit"));
44  histoByCategoryNames_.insert(pair<string, string>("lumi", "Lumibased PrimaryVertex-Scalers fit"));
45  histoByCategoryNames_.insert(pair<string, string>("validation", "Lumibased Scalers-DataBase fit"));
46  histoByCategoryNames_.insert(pair<string, string>("validation", "Lumibased PrimaryVertex-DataBase"));
47  histoByCategoryNames_.insert(pair<string, string>("validation", "Lumibased PrimaryVertex-Scalers"));
48 
49  for (vector<string>::iterator itV = varNamesV_.begin(); itV != varNamesV_.end(); itV++) {
50  for (multimap<string, string>::iterator itM = histoByCategoryNames_.begin(); itM != histoByCategoryNames_.end();
51  itM++) {
52  histosMap_[*itV][itM->first][itM->second] = nullptr;
53  positionsMap_[*itV][itM->first][itM->second] = 3 * numberOfValuesToSave_; // value, error, ok
55  }
56  }
57 }
58 
60 
61 //----------------------------------------------------------------------------------------------------------------------
63 
64 //----------------------------------------------------------------------------------------------------------------------
65 void AlcaBeamMonitorClient::beginRun(const edm::Run& r, const EventSetup& context) {}
66 
67 //----------------------------------------------------------------------------------------------------------------------
68 
69 //----------------------------------------------------------------------------------------------------------------------
70 void AlcaBeamMonitorClient::analyze(const Event& iEvent, const EventSetup& iSetup) {}
71 
72 //----------------------------------------------------------------------------------------------------------------------
74  MonitorElement* tmp = nullptr;
75  tmp = dbe_->get(monitorName_ + "Service/hHistoLumiValues");
76  if (!tmp) {
77  return;
78  }
79  valuesMap_[iLumi.id().luminosityBlock()] = vector<double>();
80  for (int i = 0; i < 3 * numberOfValuesToSave_; i++) {
81  valuesMap_[iLumi.id().luminosityBlock()].push_back(tmp->getTProfile()->GetBinContent(i + 1));
82  }
83 }
84 
85 //----------------------------------------------------------------------------------------------------------------------
86 void AlcaBeamMonitorClient::endRun(const Run& iRun, const EventSetup& context) {
87  // use this in case any LS is missing.
88  if (valuesMap_.empty()) {
89  LogInfo("AlcaBeamMonitorClient") << "The histogram "
90  << monitorName_ +
91  "Service/hHistoLumiValues which contains all the values has not "
92  "been found in any lumi!";
93  return;
94  }
95  int lastLumi = (--valuesMap_.end())->first;
96  int firstLumi = valuesMap_.begin()->first;
97 
98  // create and cd into new folder
99  dbe_->setCurrentFolder(monitorName_ + "Validation");
100 
101  LogInfo("AlcaBeamMonitorClient") << "End of run " << iRun.id().run() << "(" << firstLumi << "-" << lastLumi << ")";
102 
103  string name;
104  string title;
105  // x,y,z,sigmaX,sigmaY,sigmaZ
106  for (HistosContainer::iterator itM = histosMap_.begin(); itM != histosMap_.end(); itM++) {
107  for (map<string, map<string, MonitorElement*> >::iterator itMM = itM->second.begin(); itMM != itM->second.end();
108  itMM++) {
109  if (itMM->first != "run") {
110  for (map<string, MonitorElement*>::iterator itMMM = itMM->second.begin(); itMMM != itMM->second.end();
111  itMMM++) {
112  name = string("h") + itM->first + itMMM->first;
113  title = itM->first + "_{0} " + itMMM->first;
114  if (itMM->first == "lumi") {
115  dbe_->setCurrentFolder(monitorName_ + "Debug");
116  itMMM->second = dbe_->book1D(name, title, lastLumi - firstLumi + 1, firstLumi - 0.5, lastLumi + 0.5);
117  itMMM->second->setEfficiencyFlag();
118  } else if (itMM->first == "validation" && itMMM->first == "Lumibased Scalers-DataBase fit") {
119  dbe_->setCurrentFolder(monitorName_ + "Validation");
120  itMMM->second = dbe_->book1D(name, title, lastLumi - firstLumi + 1, firstLumi - 0.5, lastLumi + 0.5);
121  itMMM->second->setEfficiencyFlag();
122  } else if (itMM->first == "validation" && itMMM->first != "Lumibased Scalers-DataBase fit" &&
123  (itM->first == "x" || itM->first == "y" || itM->first == "z")) {
124  dbe_->setCurrentFolder(monitorName_ + "Validation");
125  itMMM->second = dbe_->book1D(name, title, lastLumi - firstLumi + 1, firstLumi - 0.5, lastLumi + 0.5);
126  itMMM->second->setEfficiencyFlag();
127  } else if (itMM->first == "validation" &&
128  (itM->first == "sigmaX" || itM->first == "sigmaY" || itM->first == "sigmaZ")) {
129  dbe_->setCurrentFolder(monitorName_ + "Validation");
130  itMMM->second = nullptr;
131  } else {
132  LogInfo("AlcaBeamMonitorClient") << "Unrecognized category " << itMM->first;
133  // assert(0);
134  }
135  if (itMMM->second != nullptr) {
136  if (itMMM->first.find('-') != string::npos) {
137  itMMM->second->setAxisTitle(string("#Delta ") + itM->first + "_{0} (cm)", 2);
138  } else {
139  itMMM->second->setAxisTitle(itM->first + "_{0} (cm)", 2);
140  }
141  itMMM->second->setAxisTitle("Lumisection", 1);
142  }
143  }
144  }
145  }
146  }
147 
148  unsigned int bin = 0;
149  for (HistosContainer::iterator itH = histosMap_.begin(); itH != histosMap_.end(); itH++) {
150  for (map<string, map<string, MonitorElement*> >::iterator itHH = itH->second.begin(); itHH != itH->second.end();
151  itHH++) {
152  for (map<string, MonitorElement*>::iterator itHHH = itHH->second.begin(); itHHH != itHH->second.end(); itHHH++) {
153  for (map<LuminosityBlockNumber_t, vector<double> >::iterator itVal = valuesMap_.begin();
154  itVal != valuesMap_.end();
155  itVal++) {
156  if (itHHH->second != nullptr) {
157  // cout << positionsMap_[itH->first][itHH->first][itHHH->first]
158  //<< endl;
159  if (itVal->second[positionsMap_[itH->first][itHH->first][itHHH->first] + 2] == 1) {
160  bin = itHHH->second->getTH1()->FindBin(itVal->first);
161  itHHH->second->setBinContent(bin, itVal->second[positionsMap_[itH->first][itHH->first][itHHH->first]]);
162  itHHH->second->setBinError(bin, itVal->second[positionsMap_[itH->first][itHH->first][itHHH->first] + 1]);
163  }
164  }
165  }
166  }
167  }
168  }
169 
170 
171  const double bigNumber = 1000000.;
172  for (HistosContainer::iterator itH = histosMap_.begin(); itH != histosMap_.end(); itH++) {
173  for (map<string, map<string, MonitorElement*> >::iterator itHH = itH->second.begin(); itHH != itH->second.end();
174  itHH++) {
175  double min = bigNumber;
176  double max = -bigNumber;
177  double minDelta = bigNumber;
178  double maxDelta = -bigNumber;
179  // double minDeltaProf = bigNumber;
180  // double maxDeltaProf = -bigNumber;
181  if (itHH->first != "run") {
182  for (map<string, MonitorElement*>::iterator itHHH = itHH->second.begin(); itHHH != itHH->second.end();
183  itHHH++) {
184  if (itHHH->second != nullptr) {
185  for (int bin = 1; bin <= itHHH->second->getTH1()->GetNbinsX(); bin++) {
186  if (itHHH->second->getTH1()->GetBinError(bin) != 0 || itHHH->second->getTH1()->GetBinContent(bin) != 0) {
187  if (itHHH->first == "Lumibased BeamSpotFit" || itHHH->first == "Lumibased PrimaryVertex" ||
188  itHHH->first == "Lumibased DataBase" || itHHH->first == "Lumibased Scalers") {
189  if (min > itHHH->second->getTH1()->GetBinContent(bin)) {
190  min = itHHH->second->getTH1()->GetBinContent(bin);
191  }
192  if (max < itHHH->second->getTH1()->GetBinContent(bin)) {
193  max = itHHH->second->getTH1()->GetBinContent(bin);
194  }
195  } else if (itHHH->first == "Lumibased PrimaryVertex-DataBase fit" ||
196  itHHH->first == "Lumibased PrimaryVertex-Scalers fit" ||
197  itHHH->first == "Lumibased Scalers-DataBase fit" ||
198  itHHH->first == "Lumibased PrimaryVertex-DataBase" ||
199  itHHH->first == "Lumibased PrimaryVertex-Scalers") {
200  if (minDelta > itHHH->second->getTH1()->GetBinContent(bin)) {
201  minDelta = itHHH->second->getTH1()->GetBinContent(bin);
202  }
203  if (maxDelta < itHHH->second->getTH1()->GetBinContent(bin)) {
204  maxDelta = itHHH->second->getTH1()->GetBinContent(bin);
205  }
206  } else {
207  LogInfo("AlcaBeamMonitorClient") << "The histosMap_ have a histogram named " << itHHH->first
208  << " that I can't recognize in this loop!";
209  // assert(0);
210  }
211  }
212  }
213  }
214  }
215  for (map<string, MonitorElement*>::iterator itHHH = itHH->second.begin(); itHHH != itHH->second.end();
216  itHHH++) {
217  if (itHHH->second != nullptr) {
218  if (itHHH->first == "Lumibased BeamSpotFit" || itHHH->first == "Lumibased PrimaryVertex" ||
219  itHHH->first == "Lumibased DataBase" || itHHH->first == "Lumibased Scalers") {
220  if ((max == -bigNumber && min == bigNumber) || max - min == 0) {
221  itHHH->second->getTH1()->SetMinimum(itHHH->second->getTH1()->GetMinimum() - 0.01);
222  itHHH->second->getTH1()->SetMaximum(itHHH->second->getTH1()->GetMaximum() + 0.01);
223  } else {
224  itHHH->second->getTH1()->SetMinimum(min - 0.1 * (max - min));
225  itHHH->second->getTH1()->SetMaximum(max + 0.1 * (max - min));
226  }
227  } else if (itHHH->first == "Lumibased PrimaryVertex-DataBase fit" ||
228  itHHH->first == "Lumibased PrimaryVertex-Scalers fit" ||
229  itHHH->first == "Lumibased Scalers-DataBase fit" ||
230  itHHH->first == "Lumibased PrimaryVertex-DataBase" ||
231  itHHH->first == "Lumibased PrimaryVertex-Scalers") {
232  if ((maxDelta == -bigNumber && minDelta == bigNumber) || maxDelta - minDelta == 0) {
233  itHHH->second->getTH1()->SetMinimum(itHHH->second->getTH1()->GetMinimum() - 0.01);
234  itHHH->second->getTH1()->SetMaximum(itHHH->second->getTH1()->GetMaximum() + 0.01);
235  } else {
236  itHHH->second->getTH1()->SetMinimum(minDelta - 2 * (maxDelta - minDelta));
237  itHHH->second->getTH1()->SetMaximum(maxDelta + 2 * (maxDelta - minDelta));
238  }
239  } else {
240  LogInfo("AlcaBeamMonitorClient") << "The histosMap_ have a histogram named " << itHHH->first
241  << " that I can't recognize in this loop!";
242  }
243  }
244  }
245  }
246  }
247  }
248 
249 }
250 
AlcaBeamMonitorClient::positionsMap_
PositionContainer positionsMap_
Definition: AlcaBeamMonitorClient.h:58
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
mps_fire.i
i
Definition: mps_fire.py:428
AlcaBeamMonitorClient::histosMap_
HistosContainer histosMap_
Definition: AlcaBeamMonitorClient.h:54
MessageLogger.h
ESHandle.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::RunID::run
RunNumber_t run() const
Definition: RunID.h:36
edm::Run
Definition: Run.h:45
min
T min(T a, T b)
Definition: MathUtil.h:58
AlcaBeamMonitorClient
Definition: AlcaBeamMonitorClient.h:23
LuminosityBlock.h
edm
HLT enums.
Definition: AlignableModifier.h:19
dqm::impl::MonitorElement::setEfficiencyFlag
void setEfficiencyFlag()
Definition: MonitorElement.h:267
AlcaBeamMonitorClient::~AlcaBeamMonitorClient
~AlcaBeamMonitorClient() override
Definition: AlcaBeamMonitorClient.cc:59
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
AlcaBeamMonitorClient::numberOfValuesToSave_
int numberOfValuesToSave_
Definition: AlcaBeamMonitorClient.h:50
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
AlcaBeamMonitorClient::AlcaBeamMonitorClient
AlcaBeamMonitorClient(const edm::ParameterSet &)
Definition: AlcaBeamMonitorClient.cc:23
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
allConversions_cfi.maxDelta
maxDelta
Definition: allConversions_cfi.py:44
edm::LuminosityBlockNumber_t
unsigned int LuminosityBlockNumber_t
Definition: RunLumiEventNumber.h:13
AlcaBeamMonitorClient::analyze
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: AlcaBeamMonitorClient.cc:70
BeamSpotPI::lastLumi
Definition: BeamSpotPayloadInspectorHelper.h:39
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
Run.h
AlcaBeamMonitorClient::endLuminosityBlock
void endLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &iSetup) override
Definition: AlcaBeamMonitorClient.cc:73
dqm::implementation::DQMStore::setCurrentFolder
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:569
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
AlcaBeamMonitorClient::varNamesV_
std::vector< std::string > varNamesV_
Definition: AlcaBeamMonitorClient.h:55
AlcaBeamMonitorClient::beginJob
void beginJob(void) override
Definition: AlcaBeamMonitorClient.cc:62
edm::ParameterSet
Definition: ParameterSet.h:47
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
AlcaBeamMonitorClient::endRun
void endRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
Definition: AlcaBeamMonitorClient.cc:86
AlcaBeamMonitorClient::monitorName_
std::string monitorName_
Definition: AlcaBeamMonitorClient.h:47
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
AlcaBeamMonitorClient::histoByCategoryNames_
std::multimap< std::string, std::string > histoByCategoryNames_
Definition: AlcaBeamMonitorClient.h:56
edm::LuminosityBlockID::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockID.h:42
edm::LuminosityBlockBase::id
LuminosityBlockID id() const
Definition: LuminosityBlockBase.h:44
edm::EventSetup
Definition: EventSetup.h:58
alignCSCRings.r
r
Definition: alignCSCRings.py:93
AlcaBeamMonitorClient.h
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
std
Definition: JetResolutionObject.h:76
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:651
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
AlcaBeamMonitorClient::valuesMap_
std::map< edm::LuminosityBlockNumber_t, std::vector< double > > valuesMap_
Definition: AlcaBeamMonitorClient.h:57
genParticles_cff.map
map
Definition: genParticles_cff.py:11
edm::Event
Definition: Event.h:73
AlcaBeamMonitorClient::dbe_
DQMStore * dbe_
Definition: AlcaBeamMonitorClient.h:51
AlcaBeamMonitorClient::beginRun
void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
Definition: AlcaBeamMonitorClient.cc:65
edm::RunBase::id
RunID const & id() const
Definition: RunBase.h:39
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