File indexing completed on 2024-04-06 12:07:02
0001 #include "DQM/DataScouting/interface/ScoutingAnalyzerBase.h"
0002 #include "DQMServices/Core/interface/DQMStore.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include <iostream>
0007 #include <sstream>
0008
0009 ScoutingAnalyzerBase::ScoutingAnalyzerBase(const edm::ParameterSet &conf) {
0010 m_MEsPath = conf.getUntrackedParameter<std::string>("rootPath", "DataScouting");
0011 m_modulePath = conf.getUntrackedParameter<std::string>("modulePath", "DataScouting");
0012 m_verbosityLevel = conf.getUntrackedParameter<unsigned int>("verbosityLevel", 0);
0013 if (!m_modulePath.empty()) {
0014 m_MEsPath += "/" + m_modulePath;
0015 }
0016 }
0017
0018 ScoutingAnalyzerBase::~ScoutingAnalyzerBase() {}
0019
0020 inline std::string ScoutingAnalyzerBase::newName(const std::string &name) {
0021
0022 return name;
0023 }
0024
0025 void ScoutingAnalyzerBase::prepareBooking(DQMStore::IBooker &iBooker) { iBooker.setCurrentFolder(m_MEsPath); }
0026
0027 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::bookH1(DQMStore::IBooker &iBooker,
0028 const std::string &name,
0029 const std::string &title,
0030 int nchX,
0031 double lowX,
0032 double highX,
0033 const std::string &titleX,
0034 const std::string &titleY,
0035 Option_t *option) {
0036 MonitorElement *me = iBooker.book1DD(newName(name), title, nchX, lowX, highX);
0037 if (!titleX.empty()) {
0038 me->getTH1()->GetXaxis()->SetTitle(titleX.c_str());
0039 }
0040 if (!titleY.empty()) {
0041 me->getTH1()->GetYaxis()->SetTitle(titleY.c_str());
0042 }
0043 if (TString(option) != "") {
0044 me->getTH1()->SetOption(option);
0045 }
0046 return me;
0047 }
0048
0049 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::bookH1withSumw2(DQMStore::IBooker &iBooker,
0050 const std::string &name,
0051 const std::string &title,
0052 int nchX,
0053 double lowX,
0054 double highX,
0055 const std::string &titleX,
0056 const std::string &titleY,
0057 Option_t *option) {
0058 std::cout << newName(name) << std::endl;
0059 MonitorElement *me = iBooker.book1DD(newName(name), title, nchX, lowX, highX);
0060 me->getTH1()->Sumw2();
0061 if (!titleX.empty()) {
0062 me->getTH1()->GetXaxis()->SetTitle(titleX.c_str());
0063 }
0064 if (!titleY.empty()) {
0065 me->getTH1()->GetYaxis()->SetTitle(titleY.c_str());
0066 }
0067 if (TString(option) != "") {
0068 me->getTH1()->SetOption(option);
0069 }
0070 return me;
0071 }
0072
0073 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::bookH1BinArray(DQMStore::IBooker &iBooker,
0074 const std::string &name,
0075 const std::string &title,
0076 int nchX,
0077 float *xbinsize,
0078 const std::string &titleX,
0079 const std::string &titleY,
0080 Option_t *option) {
0081 MonitorElement *me = iBooker.book1D(newName(name), title, nchX, xbinsize);
0082
0083 if (!titleX.empty()) {
0084 me->getTH1()->GetXaxis()->SetTitle(titleX.c_str());
0085 }
0086 if (!titleY.empty()) {
0087 me->getTH1()->GetYaxis()->SetTitle(titleY.c_str());
0088 }
0089 if (TString(option) != "") {
0090 me->getTH1()->SetOption(option);
0091 }
0092 return me;
0093 }
0094
0095 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::bookH1withSumw2BinArray(DQMStore::IBooker &iBooker,
0096 const std::string &name,
0097 const std::string &title,
0098 int nchX,
0099 float *xbinsize,
0100 const std::string &titleX,
0101 const std::string &titleY,
0102 Option_t *option) {
0103 std::cout << newName(name) << std::endl;
0104 MonitorElement *me = iBooker.book1D(newName(name), title, nchX, xbinsize);
0105
0106 me->getTH1()->Sumw2();
0107 if (!titleX.empty()) {
0108 me->getTH1()->GetXaxis()->SetTitle(titleX.c_str());
0109 }
0110 if (!titleY.empty()) {
0111 me->getTH1()->GetYaxis()->SetTitle(titleY.c_str());
0112 }
0113 if (TString(option) != "") {
0114 me->getTH1()->SetOption(option);
0115 }
0116 return me;
0117 }
0118
0119 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::bookH2(DQMStore::IBooker &iBooker,
0120 const std::string &name,
0121 const std::string &title,
0122 int nchX,
0123 double lowX,
0124 double highX,
0125 int nchY,
0126 double lowY,
0127 double highY,
0128 const std::string &titleX,
0129 const std::string &titleY,
0130 Option_t *option) {
0131 MonitorElement *me = iBooker.book2DD(newName(name), title, nchX, lowX, highX, nchY, lowY, highY);
0132 if (!titleX.empty()) {
0133 me->getTH1()->GetXaxis()->SetTitle(titleX.c_str());
0134 }
0135 if (!titleY.empty()) {
0136 me->getTH1()->GetYaxis()->SetTitle(titleY.c_str());
0137 }
0138 if (TString(option) != "") {
0139 me->getTH1()->SetOption(option);
0140 }
0141 return me;
0142 }
0143
0144 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::bookH2withSumw2(DQMStore::IBooker &iBooker,
0145 const std::string &name,
0146 const std::string &title,
0147 int nchX,
0148 double lowX,
0149 double highX,
0150 int nchY,
0151 double lowY,
0152 double highY,
0153 const std::string &titleX,
0154 const std::string &titleY,
0155 Option_t *option) {
0156 MonitorElement *me = iBooker.book2DD(newName(name), title, nchX, lowX, highX, nchY, lowY, highY);
0157 me->getTH1()->Sumw2();
0158 if (!titleX.empty()) {
0159 me->getTH1()->GetXaxis()->SetTitle(titleX.c_str());
0160 }
0161 if (!titleY.empty()) {
0162 me->getTH1()->GetYaxis()->SetTitle(titleY.c_str());
0163 }
0164 if (TString(option) != "") {
0165 me->getTH1()->SetOption(option);
0166 }
0167 return me;
0168 }
0169
0170 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::bookP1(DQMStore::IBooker &iBooker,
0171 const std::string &name,
0172 const std::string &title,
0173 int nchX,
0174 double lowX,
0175 double highX,
0176 double lowY,
0177 double highY,
0178 const std::string &titleX,
0179 const std::string &titleY,
0180 Option_t *option) {
0181 MonitorElement *me = iBooker.bookProfile(newName(name), title, nchX, lowX, highX, lowY, highY, " ");
0182 if (!titleX.empty()) {
0183 me->getTProfile()->GetXaxis()->SetTitle(titleX.c_str());
0184 }
0185 if (!titleY.empty()) {
0186 me->getTProfile()->GetYaxis()->SetTitle(titleY.c_str());
0187 }
0188 if (TString(option) != "") {
0189 me->getTProfile()->SetOption(option);
0190 }
0191 return me;
0192 }
0193
0194 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::bookH1andDivide(DQMStore::IBooker &iBooker,
0195 const std::string &name,
0196 MonitorElement *num,
0197 MonitorElement *denom,
0198 const std::string &titleX,
0199 const std::string &titleY,
0200 const std::string &title) {
0201 std::string name2 = newName(name);
0202 TH1D *h_temp = dynamic_cast<TH1D *>(num->getTH1()->Clone(name2.c_str()));
0203 h_temp->Reset();
0204 h_temp->Divide(num->getTH1(), denom->getTH1(), 1, 1, "b");
0205 h_temp->GetXaxis()->SetTitle(titleX.c_str());
0206 h_temp->GetYaxis()->SetTitle(titleY.c_str());
0207 if (!title.empty()) {
0208 h_temp->SetTitle(title.c_str());
0209 }
0210 if (m_verbosityLevel > 0) {
0211 h_temp->Print();
0212 }
0213 MonitorElement *me = iBooker.book1DD(name2, h_temp);
0214 delete h_temp;
0215 return me;
0216 }
0217
0218 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::bookH2andDivide(DQMStore::IBooker &iBooker,
0219 const std::string &name,
0220 MonitorElement *num,
0221 MonitorElement *denom,
0222 const std::string &titleX,
0223 const std::string &titleY,
0224 const std::string &title) {
0225 std::string name2 = newName(name);
0226 TH2D *h_temp = dynamic_cast<TH2D *>(num->getTH1()->Clone(name2.c_str()));
0227 h_temp->Reset();
0228 h_temp->Divide(num->getTH1(), denom->getTH1(), 1, 1, "b");
0229 h_temp->GetXaxis()->SetTitle(titleX.c_str());
0230 h_temp->GetYaxis()->SetTitle(titleY.c_str());
0231 if (!title.empty()) {
0232 h_temp->SetTitle(title.c_str());
0233 }
0234 if (m_verbosityLevel > 0) {
0235 h_temp->Print();
0236 }
0237 MonitorElement *me = iBooker.book2DD(name2, h_temp);
0238 delete h_temp;
0239 return me;
0240 }
0241
0242 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::profileX(DQMStore::IBooker &iBooker,
0243 MonitorElement *me2d,
0244 const std::string &title,
0245 const std::string &titleX,
0246 const std::string &titleY,
0247 Double_t minimum,
0248 Double_t maximum) {
0249 std::string name2 = me2d->getName() + "_pfx";
0250 TProfile *p1_temp = me2d->getTH2D()->ProfileX();
0251 if (!title.empty()) {
0252 p1_temp->SetTitle(title.c_str());
0253 }
0254 if (!titleX.empty()) {
0255 p1_temp->GetXaxis()->SetTitle(titleX.c_str());
0256 }
0257 if (!titleY.empty()) {
0258 p1_temp->GetYaxis()->SetTitle(titleY.c_str());
0259 }
0260 if (minimum != -1111) {
0261 p1_temp->SetMinimum(minimum);
0262 }
0263 if (maximum != -1111) {
0264 p1_temp->SetMaximum(maximum);
0265 }
0266 MonitorElement *me = iBooker.bookProfile(name2, p1_temp);
0267 delete p1_temp;
0268 return me;
0269 }
0270
0271 ScoutingAnalyzerBase::MonitorElement *ScoutingAnalyzerBase::profileY(DQMStore::IBooker &iBooker,
0272 MonitorElement *me2d,
0273 const std::string &title,
0274 const std::string &titleX,
0275 const std::string &titleY,
0276 Double_t minimum,
0277 Double_t maximum) {
0278 std::string name2 = me2d->getName() + "_pfy";
0279 TProfile *p1_temp = me2d->getTH2D()->ProfileY();
0280 if (!title.empty()) {
0281 p1_temp->SetTitle(title.c_str());
0282 }
0283 if (!titleX.empty()) {
0284 p1_temp->GetXaxis()->SetTitle(titleX.c_str());
0285 }
0286 if (!titleY.empty()) {
0287 p1_temp->GetYaxis()->SetTitle(titleY.c_str());
0288 }
0289 if (minimum != -1111) {
0290 p1_temp->SetMinimum(minimum);
0291 }
0292 if (maximum != -1111) {
0293 p1_temp->SetMaximum(maximum);
0294 }
0295 MonitorElement *me = iBooker.bookProfile(name2, p1_temp);
0296 delete p1_temp;
0297 return me;
0298 }