Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-17 23:10:38

0001 //#define printing false
0002 //#define occupancyprinting false
0003 
0004 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
0005 #include "DQM/SiPixelMonitorClient/interface/ANSIColors.h"
0006 #include "DQM/SiPixelMonitorClient/interface/SiPixelActionExecutor.h"
0007 #include "DQM/SiPixelMonitorClient/interface/SiPixelInformationExtractor.h"
0008 #include "DQM/SiPixelMonitorClient/interface/SiPixelUtility.h"
0009 #include "DQMServices/Core/interface/DQMStore.h"
0010 #include "DataFormats/DetId/interface/DetId.h"
0011 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0012 #include "DataFormats/SiPixelDetId/interface/PixelBarrelNameUpgrade.h"
0013 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0014 #include "DataFormats/SiPixelDetId/interface/PixelEndcapNameUpgrade.h"
0015 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/FileInPath.h"
0018 
0019 #include <cmath>
0020 
0021 #include <iostream>
0022 using namespace std;
0023 //=============================================================================================================
0024 //
0025 // -- Constructor
0026 //
0027 SiPixelActionExecutor::SiPixelActionExecutor(bool offlineXMLfile, bool Tier0Flag)
0028     : offlineXMLfile_(offlineXMLfile), Tier0Flag_(Tier0Flag) {
0029   edm::LogInfo("SiPixelActionExecutor") << " Creating SiPixelActionExecutor "
0030                                         << "\n";
0031   configParser_ = nullptr;
0032   configWriter_ = nullptr;
0033   ndet_ = 0;
0034   // collationDone = false;
0035 }
0036 //=============================================================================================================
0037 //
0038 // --  Destructor
0039 //
0040 SiPixelActionExecutor::~SiPixelActionExecutor() {
0041   edm::LogInfo("SiPixelActionExecutor") << " Deleting SiPixelActionExecutor "
0042                                         << "\n";
0043   if (configParser_)
0044     delete configParser_;
0045   if (configWriter_)
0046     delete configWriter_;
0047 }
0048 //=============================================================================================================
0049 //
0050 // -- Read Configuration File
0051 //
0052 void SiPixelActionExecutor::readConfiguration() {
0053   string localPath;
0054   if (offlineXMLfile_)
0055     localPath = string("DQM/SiPixelMonitorClient/test/sipixel_tier0_config.xml");
0056   else
0057     localPath = string("DQM/SiPixelMonitorClient/test/sipixel_monitorelement_config.xml");
0058   if (configParser_ == nullptr) {
0059     configParser_ = new SiPixelConfigParser();
0060     configParser_->getDocument(edm::FileInPath(localPath).fullPath());
0061   }
0062 }
0063 //=============================================================================================================
0064 //
0065 // -- Read Configuration File
0066 //
0067 bool SiPixelActionExecutor::readConfiguration(int &tkmap_freq,
0068                                               int &sum_barrel_freq,
0069                                               int &sum_endcap_freq,
0070                                               int &sum_grandbarrel_freq,
0071                                               int &sum_grandendcap_freq,
0072                                               int &message_limit_,
0073                                               int &source_type_,
0074                                               int &calib_type_) {
0075   // printing cout<<"Entering
0076   // SiPixelActionExecutor::readConfiguration..."<<endl;
0077   string localPath;
0078   if (offlineXMLfile_)
0079     localPath = string("DQM/SiPixelMonitorClient/test/sipixel_tier0_config.xml");
0080   else
0081     localPath = string("DQM/SiPixelMonitorClient/test/sipixel_monitorelement_config.xml");
0082   if (configParser_ == nullptr) {
0083     configParser_ = new SiPixelConfigParser();
0084     configParser_->getDocument(edm::FileInPath(localPath).fullPath());
0085   }
0086 
0087   if (!configParser_->getFrequencyForTrackerMap(tkmap_freq)) {
0088     cout << "SiPixelActionExecutor::readConfiguration: Failed to read "
0089             "TrackerMap configuration parameters!! ";
0090     return false;
0091   }
0092   if (!configParser_->getFrequencyForBarrelSummary(sum_barrel_freq)) {
0093     edm::LogInfo("SiPixelActionExecutor") << "Failed to read Barrel Summary configuration parameters!! "
0094                                           << "\n";
0095     return false;
0096   }
0097   if (!configParser_->getFrequencyForEndcapSummary(sum_endcap_freq)) {
0098     edm::LogInfo("SiPixelActionExecutor") << "Failed to read Endcap Summary configuration parameters!! "
0099                                           << "\n";
0100     return false;
0101   }
0102   if (!configParser_->getFrequencyForGrandBarrelSummary(sum_grandbarrel_freq)) {
0103     edm::LogInfo("SiPixelActionExecutor") << "Failed to read Grand Barrel Summary configuration parameters!! "
0104                                           << "\n";
0105     return false;
0106   }
0107   if (!configParser_->getFrequencyForGrandEndcapSummary(sum_grandendcap_freq)) {
0108     edm::LogInfo("SiPixelActionExecutor") << "Failed to read Grand Endcap Summary configuration parameters!! "
0109                                           << "\n";
0110     return false;
0111   }
0112   if (!configParser_->getMessageLimitForQTests(message_limit_)) {
0113     edm::LogInfo("SiPixelActionExecutor") << "Failed to read QTest Message Limit"
0114                                           << "\n";
0115     return false;
0116   }
0117   if (!configParser_->getSourceType(source_type_)) {
0118     edm::LogInfo("SiPixelActionExecutor") << "Failed to read Source Type"
0119                                           << "\n";
0120     return false;
0121   }
0122   if (!configParser_->getCalibType(calib_type_)) {
0123     edm::LogInfo("SiPixelActionExecutor") << "Failed to read Calib Type"
0124                                           << "\n";
0125     return false;
0126   }
0127   // printing cout<<"...leaving
0128   // SiPixelActionExecutor::readConfiguration..."<<endl;
0129   return true;
0130 }
0131 //=============================================================================================================
0132 bool SiPixelActionExecutor::readConfiguration(int &tkmap_freq, int &summary_freq) {
0133   // printing cout<<"Entering
0134   // SiPixelActionExecutor::readConfiguration..."<<endl;
0135   string localPath;
0136   if (offlineXMLfile_)
0137     localPath = string("DQM/SiPixelMonitorClient/test/sipixel_tier0_config.xml");
0138   else
0139     localPath = string("DQM/SiPixelMonitorClient/test/sipixel_monitorelement_config.xml");
0140   if (configParser_ == nullptr) {
0141     configParser_ = new SiPixelConfigParser();
0142     configParser_->getDocument(edm::FileInPath(localPath).fullPath());
0143   }
0144 
0145   if (!configParser_->getFrequencyForTrackerMap(tkmap_freq)) {
0146     cout << "SiPixelActionExecutor::readConfiguration: Failed to read "
0147             "TrackerMap configuration parameters!! ";
0148     return false;
0149   }
0150   if (!configParser_->getFrequencyForBarrelSummary(summary_freq)) {
0151     edm::LogInfo("SiPixelActionExecutor") << "Failed to read Summary configuration parameters!! "
0152                                           << "\n";
0153     return false;
0154   }
0155   // printing cout<<"...leaving
0156   // SiPixelActionExecutor::readConfiguration..."<<endl;
0157   return true;
0158 }
0159 
0160 //=============================================================================================================
0161 void SiPixelActionExecutor::createSummary(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, bool isUpgrade) {
0162   // To be majorly overhauled and split into two, I guess.
0163 
0164   // cout<<"entering SiPixelActionExecutor::createSummary..."<<endl;
0165   string barrel_structure_name;
0166   vector<string> barrel_me_names;
0167   string localPath;
0168   if (offlineXMLfile_)
0169     localPath = string("DQM/SiPixelMonitorClient/test/sipixel_tier0_config.xml");
0170   else
0171     localPath = string("DQM/SiPixelMonitorClient/test/sipixel_monitorelement_config.xml");
0172   //  cout<<"*********************ATTENTION! LOCALPATH= "<<localPath<<endl;
0173   if (configParser_ == nullptr) {
0174     configParser_ = new SiPixelConfigParser();
0175     configParser_->getDocument(edm::FileInPath(localPath).fullPath());
0176   }
0177   if (!configParser_->getMENamesForBarrelSummary(barrel_structure_name, barrel_me_names)) {
0178     cout << "SiPixelActionExecutor::createSummary: Failed to read Barrel "
0179             "Summary configuration parameters!! ";
0180     return;
0181   }
0182   configParser_->getSourceType(source_type_);
0183 
0184   iBooker.setCurrentFolder("Pixel/");
0185   iGetter.setCurrentFolder("Pixel/");
0186   fillSummary(iBooker, iGetter, barrel_structure_name, barrel_me_names, true,
0187               isUpgrade);  // Barrel
0188   iBooker.setCurrentFolder("Pixel/");
0189   iGetter.setCurrentFolder("Pixel/");
0190   string endcap_structure_name;
0191   vector<string> endcap_me_names;
0192   if (!configParser_->getMENamesForEndcapSummary(endcap_structure_name, endcap_me_names)) {
0193     edm::LogInfo("SiPixelActionExecutor") << "Failed to read Endcap Summary configuration parameters!! "
0194                                           << "\n";
0195     return;
0196   }
0197 
0198   //  cout << "--- Processing endcap" << endl;
0199 
0200   iBooker.setCurrentFolder("Pixel/");
0201   iGetter.setCurrentFolder("Pixel/");
0202 
0203   fillSummary(iBooker, iGetter, endcap_structure_name, endcap_me_names, false,
0204               isUpgrade);  // Endcap
0205   iBooker.setCurrentFolder("Pixel/");
0206   iGetter.setCurrentFolder("Pixel/");
0207 
0208   if (source_type_ == 0 || source_type_ == 5 || source_type_ == 20) {  // do this only if RawData source is present
0209     string federror_structure_name;
0210     vector<string> federror_me_names;
0211     if (!configParser_->getMENamesForFEDErrorSummary(federror_structure_name, federror_me_names)) {
0212       cout << "SiPixelActionExecutor::createSummary: Failed to read FED Error "
0213               "Summary configuration parameters!! ";
0214       return;
0215     }
0216     iBooker.setCurrentFolder("Pixel/");
0217     iGetter.setCurrentFolder("Pixel/");
0218 
0219     fillFEDErrorSummary(iBooker, iGetter, federror_structure_name, federror_me_names);
0220     iBooker.setCurrentFolder("Pixel/");
0221     iGetter.setCurrentFolder("Pixel/");
0222   }
0223   if (configWriter_)
0224     delete configWriter_;
0225   configWriter_ = nullptr;
0226   //  cout<<"leaving SiPixelActionExecutor::createSummary..."<<endl;
0227 }
0228 
0229 //=============================================================================================================
0230 void SiPixelActionExecutor::bookDeviations(DQMStore::IBooker &iBooker, bool isUpgrade) {
0231   int nBPixModules;
0232   if (isUpgrade) {
0233     nBPixModules = 1184;
0234   } else {
0235     nBPixModules = 768;
0236   }
0237 
0238   iBooker.cd();
0239   iBooker.setCurrentFolder("Pixel/Barrel");
0240   DEV_adc_Barrel = iBooker.book1D(
0241       "DEV_adc_Barrel", "Deviation from reference;Module;<adc_ref>-<adc>", nBPixModules, 0., nBPixModules);
0242   DEV_ndigis_Barrel = iBooker.book1D(
0243       "DEV_ndigis_Barrel", "Deviation from reference;Module;<ndigis_ref>-<ndigis>", nBPixModules, 0., nBPixModules);
0244   DEV_charge_Barrel = iBooker.book1D(
0245       "DEV_charge_Barrel", "Deviation from reference;Module;<charge_ref>-<charge>", nBPixModules, 0., nBPixModules);
0246   DEV_nclusters_Barrel = iBooker.book1D("DEV_nclusters_Barrel",
0247                                         "Deviation from reference;Module;<nclusters_ref>-<nclusters>",
0248                                         nBPixModules,
0249                                         0.,
0250                                         nBPixModules);
0251   DEV_size_Barrel = iBooker.book1D(
0252       "DEV_size_Barrel", "Deviation from reference;Module;<size_ref>-<size>", nBPixModules, 0., nBPixModules);
0253   iBooker.cd();
0254   iBooker.setCurrentFolder("Pixel/Endcap");
0255   DEV_adc_Endcap = iBooker.book1D("DEV_adc_Endcap", "Deviation from reference;Module;<adc_ref>-<adc>", 672, 0., 672.);
0256   DEV_ndigis_Endcap =
0257       iBooker.book1D("DEV_ndigis_Endcap", "Deviation from reference;Module;<ndigis_ref>-<ndigis>", 672, 0., 672.);
0258   DEV_charge_Endcap =
0259       iBooker.book1D("DEV_charge_Endcap", "Deviation from reference;Module;<charge_ref>-<charge>", 672, 0., 672.);
0260   DEV_nclusters_Endcap = iBooker.book1D(
0261       "DEV_nclusters_Endcap", "Deviation from reference;Module;<nclusters_ref>-<nclusters>", 672, 0., 672.);
0262   DEV_size_Endcap =
0263       iBooker.book1D("DEV_size_Endcap", "Deviation from reference;Module;<size_ref>-<size>", 672, 0., 672.);
0264   iBooker.cd();
0265 }
0266 
0267 //=============================================================================================================
0268 
0269 void SiPixelActionExecutor::GetBladeSubdirs(DQMStore::IBooker &iBooker,
0270                                             DQMStore::IGetter &iGetter,
0271                                             vector<string> &blade_subdirs) {
0272   blade_subdirs.clear();
0273   vector<string> panels = iGetter.getSubdirs();
0274   vector<string> modules;
0275   for (vector<string>::const_iterator it = panels.begin(); it != panels.end(); it++) {
0276     iGetter.cd(*it);
0277     iBooker.cd(*it);
0278     modules = iGetter.getSubdirs();
0279     for (vector<string>::const_iterator m_it = modules.begin(); m_it != modules.end(); m_it++) {
0280       blade_subdirs.push_back(*m_it);
0281     }
0282   }
0283 }
0284 
0285 //=============================================================================================================
0286 
0287 void SiPixelActionExecutor::fillSummary(DQMStore::IBooker &iBooker,
0288                                         DQMStore::IGetter &iGetter,
0289                                         string dir_name,
0290                                         vector<string> &me_names,
0291                                         bool isbarrel,
0292                                         bool isUpgrade) {
0293   // cout<<"entering SiPixelActionExecutor::fillSummary..."<<endl;
0294   string currDir = iBooker.pwd();
0295   string prefix;
0296   if (source_type_ == 0)
0297     prefix = "SUMRAW";
0298   else if (source_type_ == 1)
0299     prefix = "SUMDIG";
0300   else if (source_type_ == 2)
0301     prefix = "SUMCLU";
0302   else if (source_type_ == 3)
0303     prefix = "SUMTRK";
0304   else if (source_type_ == 4)
0305     prefix = "SUMHIT";
0306   else if (source_type_ >= 7 && source_type_ < 20)
0307     prefix = "SUMCAL";
0308   else if (source_type_ == 20)
0309     prefix = "SUMOFF";
0310   if (currDir.find(dir_name) != string::npos) {
0311     vector<MonitorElement *> sum_mes;
0312     for (vector<string>::const_iterator iv = me_names.begin(); iv != me_names.end(); iv++) {
0313       if (source_type_ == 5 || source_type_ == 6) {
0314         if ((*iv) == "errorType" || (*iv) == "NErrors" || (*iv) == "fullType" || (*iv) == "chanNmbr" ||
0315             (*iv) == "TBMType" || (*iv) == "EvtNbr" || (*iv) == "evtSize" || (*iv) == "linkId" || (*iv) == "ROCId" ||
0316             (*iv) == "DCOLId" || (*iv) == "PXId" || (*iv) == "ROCNmbr" || (*iv) == "TBMMessage" ||
0317             (*iv) == "Type36Hitmap")
0318           prefix = "SUMRAW";
0319         else if ((*iv) == "ndigis" || (*iv) == "adc")
0320           prefix = "SUMDIG";
0321         else if ((*iv) == "nclusters" || (*iv) == "x" || (*iv) == "y" || (*iv) == "charge" || (*iv) == "size" ||
0322                  (*iv) == "sizeX" || (*iv) == "sizeY" || (*iv) == "minrow" || (*iv) == "maxrow" || (*iv) == "mincol" ||
0323                  (*iv) == "maxcol")
0324           prefix = "SUMCLU";
0325         if (currDir.find("Track") != string::npos)
0326           prefix = "SUMTRK";
0327         else if ((*iv) == "residualX" || (*iv) == "residualY")
0328           prefix = "SUMTRK";
0329         else if ((*iv) == "ClustX" || (*iv) == "ClustY" || (*iv) == "nRecHits" || (*iv) == "ErrorX" ||
0330                  (*iv) == "ErrorY")
0331           prefix = "SUMHIT";
0332         else if ((*iv) == "Gain1d" || (*iv) == "GainChi2NDF1d" || (*iv) == "GainChi2Prob1d" || (*iv) == "Pedestal1d" ||
0333                  (*iv) == "GainNPoints1d" || (*iv) == "GainHighPoint1d" || (*iv) == "GainLowPoint1d" ||
0334                  (*iv) == "GainEndPoint1d" || (*iv) == "GainFitResult2d" || (*iv) == "GainDynamicRange2d" ||
0335                  (*iv) == "GainSaturate2d" || (*iv) == "ScurveChi2ProbSummary" || (*iv) == "ScurveFitResultSummary" ||
0336                  (*iv) == "ScurveSigmasSummary" || (*iv) == "ScurveThresholdSummary" || (*iv) == "pixelAliveSummary" ||
0337                  (*iv) == "SiPixelErrorsCalibDigis")
0338           prefix = "SUMCAL";
0339       }
0340       MonitorElement *temp;
0341       string tag;
0342       if ((*iv).find("residual") != string::npos) {  // track residuals
0343         tag = prefix + "_" + (*iv) + "_mean_" + currDir.substr(currDir.find(dir_name));
0344         temp = getSummaryME(iBooker, iGetter, tag, isUpgrade);
0345         sum_mes.push_back(temp);
0346         tag = prefix + "_" + (*iv) + "_RMS_" + currDir.substr(currDir.find(dir_name));
0347         temp = getSummaryME(iBooker, iGetter, tag, isUpgrade);
0348         sum_mes.push_back(temp);
0349       } else if (prefix == "SUMCAL") {  // calibrations
0350         if ((*iv) == "Gain1d" || (*iv) == "GainChi2NDF1d" || (*iv) == "GainChi2Prob1d" || (*iv) == "GainNPoints1d" ||
0351             (*iv) == "GainHighPoint1d" || (*iv) == "GainLowPoint1d" || (*iv) == "GainEndPoint1d" ||
0352             (*iv) == "GainDynamicRange2d" || (*iv) == "GainSaturate2d" || (*iv) == "Pedestal1d" ||
0353             (*iv) == "ScurveChi2ProbSummary" || (*iv) == "ScurveFitResultSummary" || (*iv) == "ScurveSigmasSummary" ||
0354             (*iv) == "ScurveThresholdSummary") {
0355           tag = prefix + "_" + (*iv) + "_mean_" + currDir.substr(currDir.find(dir_name));
0356           temp = getSummaryME(iBooker, iGetter, tag, isUpgrade);
0357           sum_mes.push_back(temp);
0358           tag = prefix + "_" + (*iv) + "_RMS_" + currDir.substr(currDir.find(dir_name));
0359           temp = getSummaryME(iBooker, iGetter, tag, isUpgrade);
0360           sum_mes.push_back(temp);
0361         } else if ((*iv) == "SiPixelErrorsCalibDigis") {
0362           tag = prefix + "_" + (*iv) + "_NCalibErrors_" + currDir.substr(currDir.find(dir_name));
0363           temp = getSummaryME(iBooker, iGetter, tag, isUpgrade);
0364           sum_mes.push_back(temp);
0365         } else if ((*iv) == "GainFitResult2d") {
0366           tag = prefix + "_" + (*iv) + "_NNegativeFits_" + currDir.substr(currDir.find(dir_name));
0367           temp = getSummaryME(iBooker, iGetter, tag, isUpgrade);
0368           sum_mes.push_back(temp);
0369         } else if ((*iv) == "pixelAliveSummary") {
0370           tag = prefix + "_" + (*iv) + "_FracOfPerfectPix_" + currDir.substr(currDir.find(dir_name));
0371           temp = getSummaryME(iBooker, iGetter, tag, isUpgrade);
0372           sum_mes.push_back(temp);
0373           tag = prefix + "_" + (*iv) + "_mean_" + currDir.substr(currDir.find(dir_name));
0374           temp = getSummaryME(iBooker, iGetter, tag, isUpgrade);
0375           sum_mes.push_back(temp);
0376         }
0377       } else {
0378         tag = prefix + "_" + (*iv) + "_" + currDir.substr(currDir.find(dir_name));
0379         temp = getSummaryME(iBooker, iGetter, tag, isUpgrade);
0380         sum_mes.push_back(temp);
0381         if ((*iv) == "ndigis") {
0382           tag = prefix + "_" + (*iv) + "FREQ_" + currDir.substr(currDir.find(dir_name));
0383           temp = getSummaryME(iBooker, iGetter, tag, isUpgrade);
0384           sum_mes.push_back(temp);
0385         }
0386         if (prefix == "SUMDIG" && (*iv) == "adc") {
0387           tag = "ALLMODS_" + (*iv) + "COMB_" + currDir.substr(currDir.find(dir_name));
0388           temp = nullptr;
0389           string fullpathname = iBooker.pwd() + "/" + tag;
0390           temp = iGetter.get(fullpathname);
0391           if (temp) {
0392             temp->Reset();
0393           } else {
0394             temp = iBooker.book1D(tag.c_str(), tag.c_str(), 128, 0., 256.);
0395           }
0396           sum_mes.push_back(temp);
0397         }
0398         if (prefix == "SUMCLU" && (*iv) == "charge") {
0399           tag = "ALLMODS_" + (*iv) + "COMB_" + currDir.substr(currDir.find(dir_name));
0400           temp = nullptr;
0401           string fullpathname = iBooker.pwd() + "/" + tag;
0402           temp = iGetter.get(fullpathname);
0403           if (temp) {
0404             temp->Reset();
0405           } else {
0406             temp = iBooker.book1D(tag.c_str(), tag.c_str(), 100, 0.,
0407                                   200.);  // To look to get the size automatically
0408           }
0409           sum_mes.push_back(temp);
0410         }
0411       }
0412     }
0413     if (sum_mes.empty()) {
0414       edm::LogInfo("SiPixelActionExecutor") << " Summary MEs can not be created"
0415                                             << "\n";
0416       return;
0417     }
0418     vector<string> subdirs = iGetter.getSubdirs();
0419     // Blade
0420     if (dir_name.find("Blade_") == 0)
0421       GetBladeSubdirs(iBooker, iGetter, subdirs);
0422 
0423     int ndet = 0;
0424     for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
0425       if (prefix != "SUMOFF" && (*it).find("Module_") == string::npos)
0426         continue;
0427       if (prefix == "SUMOFF" && (*it).find(isbarrel ? "Layer_" : "Disk_") == string::npos)
0428         continue;
0429       iBooker.cd(*it);
0430       iGetter.cd(*it);
0431       ndet++;
0432 
0433       vector<string> contents = iGetter.getMEs();
0434 
0435       for (vector<MonitorElement *>::const_iterator isum = sum_mes.begin(); isum != sum_mes.end(); isum++) {
0436         for (vector<string>::const_iterator im = contents.begin(); im != contents.end(); im++) {
0437           string sname = ((*isum)->getName());
0438           string tname = " ";
0439           tname = sname.substr(7, (sname.find('_', 7) - 6));
0440           if (sname.find("ALLMODS_adcCOMB_") != string::npos)
0441             tname = "adc_";
0442           if (sname.find("ALLMODS_chargeCOMB_") != string::npos)
0443             tname = "charge_";
0444           if (sname.find("_charge_") != string::npos && sname.find("Track_") == string::npos)
0445             tname = "charge_";
0446           if (sname.find("_nclusters_") != string::npos && sname.find("Track_") == string::npos)
0447             tname = "nclusters_";
0448           if (sname.find("_size_") != string::npos && sname.find("Track_") == string::npos)
0449             tname = "size_";
0450           if (sname.find("_charge_OffTrack_") != string::npos)
0451             tname = "charge_OffTrack_";
0452           if (sname.find("_nclusters_OffTrack_") != string::npos)
0453             tname = "nclusters_OffTrack_";
0454           if (sname.find("_size_OffTrack_") != string::npos)
0455             tname = "size_OffTrack_";
0456           if (sname.find("_sizeX_OffTrack_") != string::npos)
0457             tname = "sizeX_OffTrack_";
0458           if (sname.find("_sizeY_OffTrack_") != string::npos)
0459             tname = "sizeY_OffTrack_";
0460           if (sname.find("_charge_OnTrack_") != string::npos)
0461             tname = "charge_OnTrack_";
0462           if (sname.find("_nclusters_OnTrack_") != string::npos)
0463             tname = "nclusters_OnTrack_";
0464           if (sname.find("_size_OnTrack_") != string::npos)
0465             tname = "size_OnTrack_";
0466           if (sname.find("_sizeX_OnTrack_") != string::npos)
0467             tname = "sizeX_OnTrack_";
0468           if (sname.find("_sizeY_OnTrack_") != string::npos)
0469             tname = "sizeY_OnTrack_";
0470           if (tname.find("FREQ") != string::npos)
0471             tname = "ndigis_";
0472           if (((*im)).find(tname) == 0) {
0473             string fullpathname = iBooker.pwd() + "/" + (*im);
0474             MonitorElement *me = iGetter.get(fullpathname);
0475 
0476             if (me) {
0477               if (sname.find("_charge") != string::npos && sname.find("Track_") == string::npos &&
0478                   me->getName().find("Track_") != string::npos)
0479                 continue;
0480               if (sname.find("_nclusters_") != string::npos && sname.find("Track_") == string::npos &&
0481                   me->getName().find("Track_") != string::npos)
0482                 continue;
0483               if (sname.find("_size") != string::npos && sname.find("Track_") == string::npos &&
0484                   me->getName().find("Track_") != string::npos)
0485                 continue;
0486               // fill summary histos:
0487               if (sname.find("_RMS_") != string::npos && sname.find("GainDynamicRange2d") == string::npos &&
0488                   sname.find("GainSaturate2d") == string::npos) {
0489                 (*isum)->Fill(ndet, me->getRMS());
0490               } else if (sname.find("GainDynamicRange2d") != string::npos ||
0491                          sname.find("GainSaturate2d") != string::npos) {
0492                 float SumOfEntries = 0.;
0493                 float SumOfSquaredEntries = 0.;
0494                 int SumOfPixels = 0;
0495                 for (int cols = 1; cols != me->getNbinsX() + 1; cols++)
0496                   for (int rows = 1; rows != me->getNbinsY() + 1; rows++) {
0497                     SumOfEntries += me->getBinContent(cols, rows);
0498                     SumOfSquaredEntries += (me->getBinContent(cols, rows)) * (me->getBinContent(cols, rows));
0499                     SumOfPixels++;
0500                   }
0501 
0502                 float MeanInZ = SumOfEntries / float(SumOfPixels);
0503                 float RMSInZ = sqrt(SumOfSquaredEntries / float(SumOfPixels));
0504                 if (sname.find("_mean_") != string::npos)
0505                   (*isum)->Fill(ndet, MeanInZ);
0506                 if (sname.find("_RMS_") != string::npos)
0507                   (*isum)->Fill(ndet, RMSInZ);
0508               } else if (sname.find("_FracOfPerfectPix_") != string::npos) {
0509                 float nlast = me->getBinContent(me->getNbinsX());
0510                 float nall = (me->getTH1F())->Integral(1, 11);
0511                 (*isum)->Fill(ndet, nlast / nall);
0512               } else if (sname.find("_NCalibErrors_") != string::npos || sname.find("FREQ_") != string::npos) {
0513                 float nall = me->getEntries();
0514                 (*isum)->Fill(ndet, nall);
0515               } else if (sname.find("GainFitResult2d") != string::npos) {
0516                 int NegFitPixels = 0;
0517                 for (int cols = 1; cols != me->getNbinsX() + 1; cols++)
0518                   for (int rows = 1; rows != me->getNbinsY() + 1; rows++) {
0519                     if (me->getBinContent(cols, rows) < 0.)
0520                       NegFitPixels++;
0521                   }
0522                 (*isum)->Fill(ndet, float(NegFitPixels));
0523               } else if (sname.find("ALLMODS_adcCOMB_") != string::npos ||
0524                          (sname.find("ALLMODS_chargeCOMB_") != string::npos &&
0525                           me->getName().find("Track_") == string::npos)) {
0526                 (*isum)->getTH1F()->Add(me->getTH1F());
0527               } else if (sname.find("_NErrors_") != string::npos) {
0528                 string path1 = fullpathname;
0529                 path1 = path1.replace(path1.find("NErrors"), 7, "errorType");
0530                 MonitorElement *me1 = iGetter.get(path1);
0531                 bool notReset = true;
0532                 if (me1) {
0533                   for (int jj = 1; jj < 16; jj++) {
0534                     if (me1->getBinContent(jj) > 0.) {
0535                       if (jj == 6) {  // errorType=30 (reset)
0536                         string path2 = path1;
0537                         path2 = path2.replace(path2.find("errorType"), 9, "TBMMessage");
0538                         MonitorElement *me2 = iGetter.get(path2);
0539                         if (me2)
0540                           if (me2->getBinContent(6) > 0. || me2->getBinContent(7) > 0.)
0541                             notReset = false;
0542                       }
0543                     }
0544                   }
0545                 }
0546                 if (notReset)
0547                   (*isum)->Fill(ndet, me1->getEntries());
0548               } else if ((sname.find("_charge_") != string::npos && sname.find("Track_") == string::npos &&
0549                           me->getName().find("Track_") == string::npos) ||
0550                          (sname.find("_charge_") != string::npos && sname.find("_OnTrack_") != string::npos &&
0551                           me->getName().find("_OnTrack_") != string::npos) ||
0552                          (sname.find("_charge_") != string::npos && sname.find("_OffTrack_") != string::npos &&
0553                           me->getName().find("_OffTrack_") != string::npos) ||
0554                          (sname.find("_nclusters_") != string::npos && sname.find("Track_") == string::npos &&
0555                           me->getName().find("Track_") == string::npos) ||
0556                          (sname.find("_nclusters_") != string::npos && sname.find("_OnTrack_") != string::npos &&
0557                           me->getName().find("_OnTrack_") != string::npos) ||
0558                          (sname.find("_nclusters_") != string::npos && sname.find("_OffTrack_") != string::npos &&
0559                           me->getName().find("_OffTrack_") != string::npos) ||
0560                          (sname.find("_size") != string::npos && sname.find("Track_") == string::npos &&
0561                           me->getName().find("Track_") == string::npos) ||
0562                          (sname.find("_size") != string::npos && sname.find("_OnTrack_") != string::npos &&
0563                           me->getName().find("_OnTrack_") != string::npos) ||
0564                          (sname.find("_size") != string::npos && sname.find("_OffTrack_") != string::npos &&
0565                           me->getName().find("_OffTrack_") != string::npos)) {
0566                 (*isum)->Fill(ndet, me->getMean());
0567               } else if (sname.find("_charge_") == string::npos && sname.find("_nclusters_") == string::npos &&
0568                          sname.find("_size") == string::npos) {
0569                 (*isum)->Fill(ndet, me->getMean());
0570               }
0571 
0572               // set titles:
0573               if (prefix == "SUMOFF") {
0574                 (*isum)->setAxisTitle(isbarrel ? "Ladders" : "Blades", 1);
0575               } else if (sname.find("ALLMODS_adcCOMB_") != string::npos) {
0576                 (*isum)->setAxisTitle("Digi charge [ADC]", 1);
0577               } else if (sname.find("ALLMODS_chargeCOMB_") != string::npos) {
0578                 (*isum)->setAxisTitle("Cluster charge [kilo electrons]", 1);
0579               } else {
0580                 (*isum)->setAxisTitle("Modules", 1);
0581               }
0582               string title = " ";
0583               if (sname.find("_RMS_") != string::npos) {
0584                 title = "RMS of " + sname.substr(7, (sname.find('_', 7) - 7)) + " per module";
0585               } else if (sname.find("_FracOfPerfectPix_") != string::npos) {
0586                 title = "FracOfPerfectPix " + sname.substr(7, (sname.find('_', 7) - 7)) + " per module";
0587               } else if (sname.find("_NCalibErrors_") != string::npos) {
0588                 title = "Number of CalibErrors " + sname.substr(7, (sname.find('_', 7) - 7)) + " per module";
0589               } else if (sname.find("_NNegativeFits_") != string::npos) {
0590                 title = "Number of pixels with neg. fit result " + sname.substr(7, (sname.find('_', 7) - 7)) +
0591                         " per module";
0592               } else if (sname.find("FREQ_") != string::npos) {
0593                 title = "NEvents with digis per module";
0594               } else if (sname.find("ALLMODS_adcCOMB_") != string::npos) {
0595                 title = "NDigis";
0596               } else if (sname.find("ALLMODS_chargeCOMB_") != string::npos) {
0597                 title = "NClusters";
0598               } else if (sname.find("_NErrors_") != string::npos) {
0599                 if (prefix == "SUMOFF" && isbarrel)
0600                   title = "Total number of errors per Ladder";
0601                 else if (prefix == "SUMOFF" && !isbarrel)
0602                   title = "Total number of errors per Blade";
0603                 else
0604                   title = "Total number of errors per Module";
0605               } else {
0606                 if (prefix == "SUMOFF")
0607                   title =
0608                       "Mean " + sname.substr(7, (sname.find('_', 7) - 7)) + (isbarrel ? " per Ladder" : " per Blade");
0609                 else
0610                   title = "Mean " + sname.substr(7, (sname.find('_', 7) - 7)) + " per Module";
0611               }
0612               (*isum)->setAxisTitle(title, 2);
0613             }
0614             break;
0615           }
0616         }
0617       }
0618       iBooker.goUp();
0619       iGetter.setCurrentFolder(iBooker.pwd());
0620       if (dir_name.find("Blade") == 0) {
0621         iBooker.goUp();  // Going up a second time if we are processing the Blade
0622         iGetter.setCurrentFolder(iBooker.pwd());
0623       }
0624     }  // end for it (subdirs)
0625   } else {
0626     vector<string> subdirs = iGetter.getSubdirs();
0627     // printing cout << "#\t" << iBooker.pwd() << endl;
0628     if (isbarrel) {
0629       for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
0630         //               cout << "##\t" << iBooker.pwd() << "\t"
0631         //<<
0632         //(*it) << endl;
0633         if ((iBooker.pwd()).find("Endcap") != string::npos ||
0634             (iBooker.pwd()).find("AdditionalPixelErrors") != string::npos) {
0635           iBooker.goUp();
0636           iGetter.setCurrentFolder(iBooker.pwd());
0637         }
0638         iBooker.cd(*it);
0639         iGetter.cd(*it);
0640         if ((*it).find("Endcap") != string::npos || (*it).find("AdditionalPixelErrors") != string::npos)
0641           continue;
0642         fillSummary(iBooker, iGetter, dir_name, me_names, true,
0643                     isUpgrade);  // Barrel
0644         iBooker.goUp();
0645         iGetter.setCurrentFolder(iBooker.pwd());
0646       }
0647       string grandbarrel_structure_name;
0648       vector<string> grandbarrel_me_names;
0649       if (!configParser_->getMENamesForGrandBarrelSummary(grandbarrel_structure_name, grandbarrel_me_names)) {
0650         cout << "SiPixelActionExecutor::createSummary: Failed to read Grand "
0651                 "Barrel Summary configuration parameters!! ";
0652         return;
0653       }
0654       fillGrandBarrelSummaryHistos(iBooker, iGetter, grandbarrel_me_names, isUpgrade);
0655 
0656     } else  // Endcap
0657     {
0658       for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
0659         if ((iBooker.pwd()).find("Barrel") != string::npos ||
0660             (iBooker.pwd()).find("AdditionalPixelErrors") != string::npos) {
0661           iBooker.goUp();
0662           iGetter.setCurrentFolder(iBooker.pwd());
0663         }
0664         iBooker.cd(*it);
0665         iGetter.cd(*it);
0666         if ((*it).find("Barrel") != string::npos || (*it).find("AdditionalPixelErrors") != string::npos)
0667           continue;
0668         fillSummary(iBooker, iGetter, dir_name, me_names, false,
0669                     isUpgrade);  // Endcap
0670         iBooker.goUp();
0671         iGetter.setCurrentFolder(iBooker.pwd());
0672       }
0673       string grandendcap_structure_name;
0674       vector<string> grandendcap_me_names;
0675       if (!configParser_->getMENamesForGrandEndcapSummary(grandendcap_structure_name, grandendcap_me_names)) {
0676         cout << "SiPixelActionExecutor::createSummary: Failed to read Grand "
0677                 "Endcap Summary configuration parameters!! ";
0678         return;
0679       }
0680       fillGrandEndcapSummaryHistos(iBooker, iGetter, grandendcap_me_names, isUpgrade);
0681     }
0682   }
0683   //  cout<<"...leaving SiPixelActionExecutor::fillSummary!"<<endl;
0684 }
0685 
0686 //=============================================================================================================
0687 void SiPixelActionExecutor::fillFEDErrorSummary(DQMStore::IBooker &iBooker,
0688                                                 DQMStore::IGetter &iGetter,
0689                                                 string dir_name,
0690                                                 vector<string> &me_names) {
0691   // printing cout<<"entering
0692   // SiPixelActionExecutor::fillFEDErrorSummary..."<<endl;
0693   string currDir = iBooker.pwd();
0694   string prefix;
0695   if (source_type_ == 0)
0696     prefix = "SUMRAW";
0697   else if (source_type_ == 20)
0698     prefix = "SUMOFF";
0699 
0700   if (currDir.find(dir_name) != string::npos) {
0701     vector<MonitorElement *> sum_mes;
0702     for (vector<string>::const_iterator iv = me_names.begin(); iv != me_names.end(); iv++) {
0703       bool isBooked = false;
0704       vector<string> contents = iGetter.getMEs();
0705       for (vector<string>::const_iterator im = contents.begin(); im != contents.end(); im++)
0706         if ((*im).find(*iv) != string::npos)
0707           isBooked = true;
0708       if (source_type_ == 5 || source_type_ == 6) {
0709         if ((*iv) == "errorType" || (*iv) == "NErrors" || (*iv) == "fullType" || (*iv) == "chanNmbr" ||
0710             (*iv) == "TBMType" || (*iv) == "EvtNbr" || (*iv) == "evtSize" || (*iv) == "linkId" || (*iv) == "ROCId" ||
0711             (*iv) == "DCOLId" || (*iv) == "PXId" || (*iv) == "ROCNmbr" || (*iv) == "TBMMessage" ||
0712             (*iv) == "Type36Hitmap" || (*iv) == "FedChLErr" || (*iv) == "FedChNErr" || (*iv) == "FedETypeNErr")
0713           prefix = "SUMRAW";
0714       }
0715       if ((*iv) == "errorType" || (*iv) == "NErrors" || (*iv) == "fullType" || (*iv) == "chanNmbr" ||
0716           (*iv) == "TBMType" || (*iv) == "EvtNbr" || (*iv) == "evtSize" || (*iv) == "linkId" || (*iv) == "ROCId" ||
0717           (*iv) == "DCOLId" || (*iv) == "PXId" || (*iv) == "ROCNmbr" || (*iv) == "TBMMessage" ||
0718           (*iv) == "Type36Hitmap") {
0719         string tag = prefix + "_" + (*iv) + "_FEDErrors";
0720         MonitorElement *temp = getFEDSummaryME(iBooker, iGetter, tag);
0721         sum_mes.push_back(temp);
0722       } else if ((*iv) == "FedChLErr" || (*iv) == "FedChNErr" || (*iv) == "FedETypeNErr") {
0723         string tag = prefix + "_" + (*iv);
0724         MonitorElement *temp;
0725         if ((*iv) == "FedChLErr") {
0726           if (!isBooked)
0727             temp = iBooker.book2D("FedChLErr", "Type of last error", 40, -0.5, 39.5, 37, 0., 37.);
0728           else {
0729             string fullpathname = iBooker.pwd() + "/" + (*iv);
0730             temp = iGetter.get(fullpathname);
0731             temp->Reset();
0732           }
0733         }  // If I don't reset this one, then I instead start adding error
0734         // codes..
0735         if ((*iv) == "FedChNErr") {
0736           if (!isBooked)
0737             temp = iBooker.book2D("FedChNErr", "Total number of errors", 40, -0.5, 39.5, 37, 0., 37.);
0738           else {
0739             string fullpathname = iBooker.pwd() + "/" + (*iv);
0740             temp = iGetter.get(fullpathname);
0741             temp->Reset();
0742           }
0743         }  // If I don't reset this one, then I instead start adding error
0744         // codes..
0745         if ((*iv) == "FedETypeNErr") {
0746           if (!isBooked) {
0747             temp = iBooker.book2D("FedETypeNErr", "Number of each error type", 40, -0.5, 39.5, 21, 0., 21.);
0748             temp->setBinLabel(1, "ROC of 25", 2);
0749             temp->setBinLabel(2, "Gap word", 2);
0750             temp->setBinLabel(3, "Dummy word", 2);
0751             temp->setBinLabel(4, "FIFO full", 2);
0752             temp->setBinLabel(5, "Timeout", 2);
0753             temp->setBinLabel(6, "Stack full", 2);
0754             temp->setBinLabel(7, "Pre-cal issued", 2);
0755             temp->setBinLabel(8, "Trigger clear or sync", 2);
0756             temp->setBinLabel(9, "No token bit", 2);
0757             temp->setBinLabel(10, "Overflow", 2);
0758             temp->setBinLabel(11, "FSM error", 2);
0759             temp->setBinLabel(12, "Invalid #ROCs", 2);
0760             temp->setBinLabel(13, "Event number", 2);
0761             temp->setBinLabel(14, "Slink header", 2);
0762             temp->setBinLabel(15, "Slink trailer", 2);
0763             temp->setBinLabel(16, "Event size", 2);
0764             temp->setBinLabel(17, "Invalid channel#", 2);
0765             temp->setBinLabel(18, "ROC value", 2);
0766             temp->setBinLabel(19, "Dcol or pixel value", 2);
0767             temp->setBinLabel(20, "Readout order", 2);
0768             temp->setBinLabel(21, "CRC error", 2);
0769           } else {
0770             string fullpathname = iBooker.pwd() + "/" + (*iv);
0771             temp = iGetter.get(fullpathname);
0772             temp->Reset();
0773           }  // If I don't reset this one, then I instead start adding error
0774              // codes..
0775         }
0776         sum_mes.push_back(temp);
0777       }
0778     }
0779     if (sum_mes.empty()) {
0780       edm::LogInfo("SiPixelActionExecutor") << " Summary MEs can not be created"
0781                                             << "\n";
0782       return;
0783     }
0784     vector<string> subdirs = iGetter.getSubdirs();
0785     int ndet = 0;
0786     for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
0787       if ((*it).find("FED_") == string::npos)
0788         continue;
0789       iBooker.cd(*it);
0790       iGetter.cd(*it);
0791       string fedid = (*it).substr((*it).find("_") + 1);
0792       std::istringstream isst;
0793       isst.str(fedid);
0794       isst >> ndet;
0795       ndet++;
0796       vector<string> contents = iGetter.getMEs();
0797 
0798       for (vector<MonitorElement *>::const_iterator isum = sum_mes.begin(); isum != sum_mes.end(); isum++) {
0799         for (vector<string>::const_iterator im = contents.begin(); im != contents.end(); im++) {
0800           if (((*im).find("FedChNErr") != std::string::npos &&
0801                (*isum)->getName().find("FedChNErr") != std::string::npos) ||
0802               ((*im).find("FedChLErr") != std::string::npos &&
0803                (*isum)->getName().find("FedChLErr") != std::string::npos) ||
0804               ((*im).find("FedETypeNErr") != std::string::npos &&
0805                (*isum)->getName().find("FedETypeNErr") != std::string::npos)) {
0806             string fullpathname = iBooker.pwd() + "/" + (*im);
0807             MonitorElement *me = iGetter.get(fullpathname);
0808             if (me) {
0809               for (int i = 0; i != 37; i++) {
0810                 if ((*im).find("FedETypeNErr") != std::string::npos && i < 21)
0811                   (*isum)->Fill(ndet - 1, i, me->getBinContent(i + 1));
0812                 else
0813                   (*isum)->Fill(ndet - 1, i, me->getBinContent(i + 1));
0814               }
0815             }
0816           }
0817           string sname = ((*isum)->getName());
0818           string tname = " ";
0819           tname = sname.substr(7, (sname.find('_', 7) - 6));
0820           if (((*im)).find(tname) == 0) {
0821             string fullpathname = iBooker.pwd() + "/" + (*im);
0822             MonitorElement *me = iGetter.get(fullpathname);
0823 
0824             if (me) {
0825               if (me->getMean() > 0.) {
0826                 if (sname.find("_NErrors_") != string::npos) {
0827                   string path1 = fullpathname;
0828                   path1 = path1.replace(path1.find("NErrors"), 7, "errorType");
0829                   MonitorElement *me1 = iGetter.get(path1);
0830                   bool notReset = true;
0831                   if (me1) {
0832                     for (int jj = 1; jj < 16; jj++) {
0833                       if (me1->getBinContent(jj) > 0.) {
0834                         if (jj == 6) {  // errorType=30 (reset)
0835                           string path2 = path1;
0836                           path2 = path2.replace(path2.find("errorType"), 9, "TBMMessage");
0837                           MonitorElement *me2 = iGetter.get(path2);
0838                           if (me2)
0839                             if (me2->getBinContent(6) > 0. || me2->getBinContent(7) > 0.)
0840                               notReset = false;
0841                         }
0842                       }
0843                     }
0844                   }
0845                   if (notReset)
0846                     (*isum)->setBinContent(ndet, (*isum)->getBinContent(ndet) + me1->getEntries());
0847                 } else
0848                   (*isum)->setBinContent(ndet, (*isum)->getBinContent(ndet) + me->getEntries());
0849               }
0850               (*isum)->setAxisTitle("FED #", 1);
0851               string title = " ";
0852               title = sname.substr(7, (sname.find('_', 7) - 7)) + " per FED";
0853               (*isum)->setAxisTitle(title, 2);
0854             }
0855             break;
0856           }
0857         }
0858       }
0859       iBooker.goUp();
0860       iGetter.setCurrentFolder(iBooker.pwd());
0861     }
0862   } else {
0863     vector<string> subdirs = iGetter.getSubdirs();
0864     for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
0865       if ((*it).find("Endcap") != string::npos || (*it).find("Barrel") != string::npos)
0866         continue;
0867       iBooker.cd(*it);
0868       iGetter.cd(*it);
0869       fillFEDErrorSummary(iBooker, iGetter, dir_name, me_names);
0870       iBooker.goUp();
0871       iGetter.setCurrentFolder(iBooker.pwd());
0872     }
0873   }
0874   // printing cout<<"...leaving
0875   // SiPixelActionExecutor::fillFEDErrorSummary!"<<endl;
0876 }
0877 
0878 //=============================================================================================================
0879 void SiPixelActionExecutor::fillGrandBarrelSummaryHistos(DQMStore::IBooker &iBooker,
0880                                                          DQMStore::IGetter &iGetter,
0881                                                          vector<string> &me_names,
0882                                                          bool isUpgrade) {
0883   //  cout<<"Entering
0884   //  SiPixelActionExecutor::fillGrandBarrelSummaryHistos...:"<<me_names.size()<<endl;
0885   vector<MonitorElement *> gsum_mes;
0886   string currDir = iBooker.pwd();
0887   string path_name = iBooker.pwd();
0888   string dir_name = path_name.substr(path_name.find_last_of('/') + 1);
0889   if ((dir_name.find("DQMData") == 0) || (dir_name.find("Pixel") == 0) ||
0890       (dir_name.find("AdditionalPixelErrors") == 0) || (dir_name.find("Endcap") == 0) ||
0891       (dir_name.find("HalfCylinder") == 0) || (dir_name.find("Disk") == 0) || (dir_name.find("Blade") == 0) ||
0892       (dir_name.find("Panel") == 0))
0893     return;
0894   vector<string> subdirs = iGetter.getSubdirs();
0895   int nDirs = subdirs.size();
0896   int iDir = 0;
0897   int nbin = 0;
0898   int nbin_i = 0;
0899   int nbin_subdir = 0;
0900   int cnt = 0;
0901   bool first_subdir = true;
0902   for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
0903     cnt++;
0904     iBooker.cd(*it);
0905     iGetter.cd(*it);
0906     vector<string> contents = iGetter.getMEs();
0907 
0908     iBooker.goUp();
0909     iGetter.setCurrentFolder(iBooker.pwd());
0910 
0911     string prefix;
0912     if (source_type_ == 0)
0913       prefix = "SUMRAW";
0914     else if (source_type_ == 1)
0915       prefix = "SUMDIG";
0916     else if (source_type_ == 2)
0917       prefix = "SUMCLU";
0918     else if (source_type_ == 3)
0919       prefix = "SUMTRK";
0920     else if (source_type_ == 4)
0921       prefix = "SUMHIT";
0922     else if (source_type_ >= 7 && source_type_ < 20)
0923       prefix = "SUMCAL";
0924     else if (source_type_ == 20)
0925       prefix = "SUMOFF";
0926 
0927     for (vector<string>::const_iterator im = contents.begin(); im != contents.end(); im++) {
0928       for (vector<string>::const_iterator iv = me_names.begin(); iv != me_names.end(); iv++) {
0929         string var = "_" + (*iv) + "_";
0930         if ((*im).find(var) != string::npos) {
0931           if ((var == "_charge_" || var == "_nclusters_" || var == "_size_" || var == "_sizeX_" || var == "_sizeY_") &&
0932               (*im).find("Track_") != string::npos)
0933             continue;
0934           string full_path = (*it) + "/" + (*im);
0935           MonitorElement *me = iGetter.get(full_path);
0936           if (!me)
0937             continue;
0938           if (source_type_ == 5 || source_type_ == 6) {
0939             if ((*iv) == "errorType" || (*iv) == "NErrors" || (*iv) == "fullType" || (*iv) == "chanNmbr" ||
0940                 (*iv) == "TBMType" || (*iv) == "EvtNbr" || (*iv) == "evtSize" || (*iv) == "linkId" ||
0941                 (*iv) == "ROCId" || (*iv) == "DCOLId" || (*iv) == "PXId" || (*iv) == "ROCNmbr" ||
0942                 (*iv) == "TBMMessage" || (*iv) == "Type36Hitmap")
0943               prefix = "SUMRAW";
0944             else if ((*iv) == "ndigis" || (*iv) == "adc" || (*iv) == "ndigisFREQ" || (*iv) == "adcCOMB")
0945               prefix = "SUMDIG";
0946             else if ((*iv) == "nclusters" || (*iv) == "x" || (*iv) == "y" || (*iv) == "charge" ||
0947                      (*iv) == "chargeCOMB" || (*iv) == "size" || (*iv) == "sizeX" || (*iv) == "sizeY" ||
0948                      (*iv) == "minrow" || (*iv) == "maxrow" || (*iv) == "mincol" || (*iv) == "maxcol")
0949               prefix = "SUMCLU";
0950             if (currDir.find("Track") != string::npos)
0951               prefix = "SUMTRK";
0952             else if ((*iv) == "residualX_mean" || (*iv) == "residualY_mean" || (*iv) == "residualX_RMS" ||
0953                      (*iv) == "residualY_RMS")
0954               prefix = "SUMTRK";
0955             else if ((*iv) == "ClustX" || (*iv) == "ClustY" || (*iv) == "nRecHits" || (*iv) == "ErrorX" ||
0956                      (*iv) == "ErrorY")
0957               prefix = "SUMHIT";
0958             else if ((*iv) == "Gain1d_mean" || (*iv) == "GainChi2NDF1d_mean" || (*iv) == "GainChi2Prob1d_mean" ||
0959                      (*iv) == "Pedestal1d_mean" || (*iv) == "ScurveChi2ProbSummary_mean" ||
0960                      (*iv) == "ScurveFitResultSummary_mean" || (*iv) == "ScurveSigmasSummary_mean" ||
0961                      (*iv) == "ScurveThresholdSummary_mean" || (*iv) == "Gain1d_RMS" || (*iv) == "GainChi2NDF1d_RMS" ||
0962                      (*iv) == "GainChi2Prob1d_RMS" || (*iv) == "Pedestal1d_RMS" || (*iv) == "GainNPoints1d_mean" ||
0963                      (*iv) == "GainNPoints1d_RMS" || (*iv) == "GainHighPoint1d_mean" ||
0964                      (*iv) == "GainHighPoint1d_RMS" || (*iv) == "GainLowPoint1d_mean" ||
0965                      (*iv) == "GainLowPoint1d_RMS" || (*iv) == "GainEndPoint1d_mean" || (*iv) == "GainEndPoint1d_RMS" ||
0966                      (*iv) == "GainFitResult2d_mean" || (*iv) == "GainFitResult2d_RMS" ||
0967                      (*iv) == "GainDynamicRange2d_mean" || (*iv) == "GainDynamicRange2d_RMS" ||
0968                      (*iv) == "GainSaturate2d_mean" || (*iv) == "GainSaturate2d_RMS" ||
0969                      (*iv) == "ScurveChi2ProbSummary_RMS" || (*iv) == "ScurveFitResultSummary_RMS" ||
0970                      (*iv) == "ScurveSigmasSummary_RMS" || (*iv) == "ScurveThresholdSummary_RMS" ||
0971                      (*iv) == "pixelAliveSummary_mean" || (*iv) == "pixelAliveSummary_FracOfPerfectPix" ||
0972                      (*iv) == "SiPixelErrorsCalibDigis_NCalibErrors")
0973               prefix = "SUMCAL";
0974           }  // end source_type if
0975 
0976           if (first_subdir && !isUpgrade) {
0977             nbin = me->getTH1F()->GetNbinsX();
0978             string me_name = prefix + "_" + (*iv) + "_" + dir_name;
0979             if ((*iv) == "adcCOMB" || (*iv) == "chargeCOMB")
0980               me_name = "ALLMODS_" + (*iv) + "_" + dir_name;
0981             else if (prefix == "SUMOFF" && dir_name == "Barrel")
0982               nbin = 192;
0983             else if ((*iv) == "adcCOMB")
0984               nbin = 256;
0985             else if (dir_name == "Barrel")
0986               nbin = 768;
0987             else if (prefix == "SUMOFF" && dir_name.find("Shell") != string::npos)
0988               nbin = 48;
0989             else if (dir_name.find("Shell") != string::npos)
0990               nbin = 192;
0991             else
0992               nbin = nbin * nDirs;
0993 
0994             getGrandSummaryME(iBooker, iGetter, nbin, me_name, gsum_mes);
0995           } else if (first_subdir && isUpgrade) {
0996             nbin = me->getTH1F()->GetNbinsX();
0997             string me_name = prefix + "_" + (*iv) + "_" + dir_name;
0998             if ((*iv) == "adcCOMB" || (*iv) == "chargeCOMB")
0999               me_name = "ALLMODS_" + (*iv) + "_" + dir_name;
1000             else if (prefix == "SUMOFF" && dir_name == "Barrel")
1001               nbin = 296;
1002             else if ((*iv) == "adcCOMB")
1003               nbin = 256;
1004             else if (dir_name == "Barrel")
1005               nbin = 1184;
1006             else if (prefix == "SUMOFF" && dir_name.find("Shell") != string::npos)
1007               nbin = 74;
1008             else if (dir_name.find("Shell") != string::npos)
1009               nbin = 296;
1010             else
1011               nbin = nbin * nDirs;
1012 
1013             getGrandSummaryME(iBooker, iGetter, nbin, me_name, gsum_mes);
1014           }
1015 
1016           for (vector<MonitorElement *>::const_iterator igm = gsum_mes.begin(); igm != gsum_mes.end(); igm++) {
1017             if ((*igm)->getName().find(var) != string::npos) {
1018               if (prefix == "SUMOFF")
1019                 (*igm)->setAxisTitle("Ladders", 1);
1020               else if ((*igm)->getName().find("adcCOMB_") != string::npos)
1021                 (*igm)->setAxisTitle("Digi charge [ADC]", 1);
1022               else if ((*igm)->getName().find("chargeCOMB_") != string::npos)
1023                 (*igm)->setAxisTitle("Cluster charge [kilo electrons]", 1);
1024               else
1025                 (*igm)->setAxisTitle("Modules", 1);
1026 
1027               // Setting title
1028 
1029               string title = "";
1030               if ((*igm)->getName().find("NErrors_") != string::npos && prefix == "SUMOFF")
1031                 title = "Total number of errors per Ladder";
1032               else if ((*igm)->getName().find("NErrors_") != string::npos && prefix == "SUMRAW")
1033                 title = "Total number of errors per Module";
1034               else if (prefix == "SUMOFF")
1035                 title = "mean " + (*iv) + " per Ladder";
1036               else if ((*igm)->getName().find("FREQ_") != string::npos && prefix != "SUMOFF")
1037                 title = "NEvents with digis per Module";
1038               else if ((*igm)->getName().find("FREQ_") != string::npos && prefix == "SUMOFF")
1039                 title = "NEvents with digis per Ladder/Blade";
1040               else if ((*igm)->getName().find("adcCOMB_") != string::npos)
1041                 title = "NDigis";
1042               else if ((*igm)->getName().find("chargeCOMB_") != string::npos)
1043                 title = "NClusters";
1044               else
1045                 title = "mean " + (*iv) + " per Module";
1046               (*igm)->setAxisTitle(title, 2);
1047 
1048               // Setting binning
1049               if (!isUpgrade) {
1050                 if ((*igm)->getName().find("ALLMODS_adcCOMB_") != string::npos) {
1051                   nbin_subdir = 128;
1052                 } else if ((*igm)->getName().find("ALLMODS_chargeCOMB_") != string::npos) {
1053                   nbin_subdir = 100;
1054                 } else if ((*igm)->getName().find("Ladder") != string::npos) {
1055                   nbin_i = 0;
1056                   nbin_subdir = 4;
1057                 } else if ((*igm)->getName().find("Layer") != string::npos) {
1058                   nbin_i = (cnt - 1) * 4;
1059                   nbin_subdir = 4;
1060                 } else if ((*igm)->getName().find("Shell") != string::npos) {
1061                   if (prefix != "SUMOFF") {
1062                     if (iDir == 0) {
1063                       nbin_i = 0;
1064                       nbin_subdir = 40;
1065                     } else if (iDir == 1) {
1066                       nbin_i = 40;
1067                       nbin_subdir = 64;
1068                     } else if (iDir == 2) {
1069                       nbin_i = 104;
1070                       nbin_subdir = 88;
1071                     }
1072                   } else {
1073                     if (iDir == 0) {
1074                       nbin_i = 0;
1075                       nbin_subdir = 10;
1076                     } else if (iDir == 1) {
1077                       nbin_i = 10;
1078                       nbin_subdir = 16;
1079                     } else if (iDir == 2) {
1080                       nbin_i = 26;
1081                       nbin_subdir = 22;
1082                     }
1083                   }
1084                 } else if ((*igm)->getName().find("Barrel") != string::npos) {
1085                   if (prefix != "SUMOFF") {
1086                     if (iDir == 0) {
1087                       nbin_i = 0;
1088                       nbin_subdir = 192;
1089                     } else if (iDir == 1) {
1090                       nbin_i = 192;
1091                       nbin_subdir = 192;
1092                     } else if (iDir == 2) {
1093                       nbin_i = 384;
1094                       nbin_subdir = 192;
1095                     } else if (iDir == 3) {
1096                       nbin_i = 576;
1097                       nbin_subdir = 192;
1098                     }
1099                   } else {
1100                     if (iDir == 0) {
1101                       nbin_i = 0;
1102                       nbin_subdir = 48;
1103                     } else if (iDir == 1) {
1104                       nbin_i = 48;
1105                       nbin_subdir = 48;
1106                     } else if (iDir == 2) {
1107                       nbin_i = 96;
1108                       nbin_subdir = 48;
1109                     } else if (iDir == 3) {
1110                       nbin_i = 144;
1111                       nbin_subdir = 48;
1112                     }
1113                   }
1114                 }
1115               } else if (isUpgrade) {
1116                 if ((*igm)->getName().find("ALLMODS_adcCOMB_") != string::npos) {
1117                   nbin_subdir = 128;
1118                 } else if ((*igm)->getName().find("ALLMODS_chargeCOMB_") != string::npos) {
1119                   nbin_subdir = 100;
1120                 } else if ((*igm)->getName().find("Ladder") != string::npos) {
1121                   nbin_i = 0;
1122                   nbin_subdir = 4;
1123                 } else if ((*igm)->getName().find("Layer") != string::npos) {
1124                   nbin_i = (cnt - 1) * 4;
1125                   nbin_subdir = 4;
1126                 } else if ((*igm)->getName().find("Shell") != string::npos) {
1127                   if (prefix != "SUMOFF") {
1128                     if (iDir == 0) {
1129                       nbin_i = 0;
1130                       nbin_subdir = 24;
1131                     }  // 40(2*20)-->24(2*12)
1132                     else if (iDir == 1) {
1133                       nbin_i = 24;
1134                       nbin_subdir = 56;
1135                     }  // 64(32*2)-->56(2*28)
1136                     else if (iDir == 2) {
1137                       nbin_i = 80;
1138                       nbin_subdir = 88;
1139                     }  // 88(44*2)-->same88(44*2)
1140                     else if (iDir == 3) {
1141                       nbin_i = 168;
1142                       nbin_subdir = 128;
1143                     }
1144                   } else {
1145                     if (iDir == 0) {
1146                       nbin_i = 0;
1147                       nbin_subdir = 6;
1148                     }  // 10-->6
1149                     else if (iDir == 1) {
1150                       nbin_i = 6;
1151                       nbin_subdir = 14;
1152                     }  // 16-->14
1153                     else if (iDir == 2) {
1154                       nbin_i = 20;
1155                       nbin_subdir = 22;
1156                     }  // 22-->same22
1157                     else if (iDir == 3) {
1158                       nbin_i = 42;
1159                       nbin_subdir = 32;
1160                     }
1161                   }
1162                 } else if ((*igm)->getName().find("Barrel") != string::npos) {
1163                   if (prefix != "SUMOFF") {
1164                     if (iDir == 0) {
1165                       nbin_i = 0;
1166                       nbin_subdir = 296;
1167                     }  // 192=76 8/4-->296=1184/4
1168                     else if (iDir == 1) {
1169                       nbin_i = 296;
1170                       nbin_subdir = 296;
1171                     }  // 296*2,*3,*4=1184
1172                     else if (iDir == 2) {
1173                       nbin_i = 592;
1174                       nbin_subdir = 296;
1175                     } else if (iDir == 3) {
1176                       nbin_i = 888;
1177                       nbin_subdir = 296;
1178                     } else if (iDir == 4) {
1179                       nbin_i = 1184;
1180                       nbin_subdir = 296;
1181                     }
1182                   } else {
1183                     if (iDir == 0) {
1184                       nbin_i = 0;
1185                       nbin_subdir = 74;
1186                     }  // 48=192/4-->74=296/4
1187                     else if (iDir == 1) {
1188                       nbin_i = 74;
1189                       nbin_subdir = 74;
1190                     }  // 74*2,...*4=296
1191                     else if (iDir == 2) {
1192                       nbin_i = 148;
1193                       nbin_subdir = 74;
1194                     } else if (iDir == 3) {
1195                       nbin_i = 222;
1196                       nbin_subdir = 74;
1197                     } else if (iDir == 4) {
1198                       nbin_i = 296;
1199                       nbin_subdir = 74;
1200                     }
1201                   }
1202                 }
1203               }
1204 
1205               if ((*igm)->getName().find("ndigisFREQ") == string::npos) {
1206                 if (((*igm)->getName().find("adcCOMB") != string::npos &&
1207                      me->getName().find("adcCOMB") != string::npos) ||
1208                     ((*igm)->getName().find("chargeCOMB") != string::npos &&
1209                      me->getName().find("chargeCOMB") != string::npos)) {
1210                   (*igm)->getTH1F()->Add(me->getTH1F());
1211                 } else if (((*igm)->getName().find("charge_") != string::npos &&
1212                             (*igm)->getName().find("Track_") == string::npos &&
1213                             me->getName().find("charge_") != string::npos &&
1214                             me->getName().find("Track_") == string::npos) ||
1215                            ((*igm)->getName().find("nclusters_") != string::npos &&
1216                             (*igm)->getName().find("Track_") == string::npos &&
1217                             me->getName().find("nclusters_") != string::npos &&
1218                             me->getName().find("Track_") == string::npos) ||
1219                            ((*igm)->getName().find("size_") != string::npos &&
1220                             (*igm)->getName().find("Track_") == string::npos &&
1221                             me->getName().find("size_") != string::npos &&
1222                             me->getName().find("Track_") == string::npos) ||
1223                            ((*igm)->getName().find("charge_OffTrack_") != string::npos &&
1224                             me->getName().find("charge_OffTrack_") != string::npos) ||
1225                            ((*igm)->getName().find("nclusters_OffTrack_") != string::npos &&
1226                             me->getName().find("nclusters_OffTrack_") != string::npos) ||
1227                            ((*igm)->getName().find("size_OffTrack_") != string::npos &&
1228                             me->getName().find("size_OffTrack_") != string::npos) ||
1229                            ((*igm)->getName().find("charge_OnTrack_") != string::npos &&
1230                             me->getName().find("charge_OnTrack_") != string::npos) ||
1231                            ((*igm)->getName().find("nclusters_OnTrack_") != string::npos &&
1232                             me->getName().find("nclusters_OnTrack_") != string::npos) ||
1233                            ((*igm)->getName().find("size_OnTrack_") != string::npos &&
1234                             me->getName().find("size_OnTrack_") != string::npos) ||
1235                            ((*igm)->getName().find("charge_") == string::npos &&
1236                             (*igm)->getName().find("nclusters_") == string::npos &&
1237                             (*igm)->getName().find("size_") == string::npos)) {
1238                   for (int k = 1; k < nbin_subdir + 1; k++)
1239                     if (me->getBinContent(k) > 0)
1240                       (*igm)->setBinContent(k + nbin_i, me->getBinContent(k));
1241                 }
1242               } else if (me->getName().find("ndigisFREQ") != string::npos) {
1243                 for (int k = 1; k < nbin_subdir + 1; k++)
1244                   if (me->getBinContent(k) > 0)
1245                     (*igm)->setBinContent(k + nbin_i, me->getBinContent(k));
1246               }
1247             }  // end var in igm (gsum_mes)
1248           }    // end igm loop
1249         }      // end var in im (contents)
1250       }        // end of iv loop
1251     }          // end of im loop
1252     iDir++;
1253     first_subdir = false;  // We are done processing the first directory, we
1254                            // don't add any new MEs in the future passes.
1255   }                        // end of it loop (subdirs)
1256   //  cout<<"...leaving
1257   //  SiPixelActionExecutor::fillGrandBarrelSummaryHistos!"<<endl;
1258 }
1259 
1260 //=============================================================================================================
1261 void SiPixelActionExecutor::fillGrandEndcapSummaryHistos(DQMStore::IBooker &iBooker,
1262                                                          DQMStore::IGetter &iGetter,
1263                                                          vector<string> &me_names,
1264                                                          bool isUpgrade) {
1265   // printing cout<<"Entering
1266   // SiPixelActionExecutor::fillGrandEndcapSummaryHistos..."<<endl;
1267   vector<MonitorElement *> gsum_mes;
1268   string currDir = iBooker.pwd();
1269   string path_name = iBooker.pwd();
1270   string dir_name = path_name.substr(path_name.find_last_of('/') + 1);
1271   if ((dir_name.find("DQMData") == 0) || (dir_name.find("Pixel") == 0) ||
1272       (dir_name.find("AdditionalPixelErrors") == 0) || (dir_name.find("Barrel") == 0) ||
1273       (dir_name.find("Shell") == 0) || (dir_name.find("Layer") == 0) || (dir_name.find("Ladder") == 0))
1274     return;
1275   vector<string> subdirs = iGetter.getSubdirs();
1276   int iDir = 0;
1277   int nbin = 0;
1278   int nbin_i = 0;
1279   int nbin_subdir = 0;
1280   int cnt = 0;
1281   bool first_subdir = true;
1282   for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
1283     cnt++;
1284     iBooker.cd(*it);
1285     iGetter.cd(*it);
1286     vector<string> contents = iGetter.getMEs();
1287     iBooker.goUp();
1288     iGetter.setCurrentFolder(iBooker.pwd());
1289 
1290     string prefix;
1291     if (source_type_ == 0)
1292       prefix = "SUMRAW";
1293     else if (source_type_ == 1)
1294       prefix = "SUMDIG";
1295     else if (source_type_ == 2)
1296       prefix = "SUMCLU";
1297     else if (source_type_ == 3)
1298       prefix = "SUMTRK";
1299     else if (source_type_ == 4)
1300       prefix = "SUMHIT";
1301     else if (source_type_ >= 7 && source_type_ < 20)
1302       prefix = "SUMCAL";
1303     else if (source_type_ == 20)
1304       prefix = "SUMOFF";
1305 
1306     for (vector<string>::const_iterator im = contents.begin(); im != contents.end(); im++) {
1307       for (vector<string>::const_iterator iv = me_names.begin(); iv != me_names.end(); iv++) {
1308         string var = "_" + (*iv) + "_";
1309         if ((*im).find(var) != string::npos) {
1310           if ((var == "_charge_" || var == "_nclusters_" || var == "_size_" || var == "_sizeX_" || var == "_sizeY_") &&
1311               (*im).find("Track_") != string::npos)
1312             continue;
1313           string full_path = (*it) + "/" + (*im);
1314           MonitorElement *me = iGetter.get(full_path);
1315           if (!me)
1316             continue;
1317           if (source_type_ == 5 || source_type_ == 6) {
1318             if ((*iv) == "errorType" || (*iv) == "NErrors" || (*iv) == "fullType" || (*iv) == "chanNmbr" ||
1319                 (*iv) == "TBMType" || (*iv) == "EvtNbr" || (*iv) == "evtSize" || (*iv) == "linkId" ||
1320                 (*iv) == "ROCId" || (*iv) == "DCOLId" || (*iv) == "PXId" || (*iv) == "ROCNmbr" ||
1321                 (*iv) == "TBMMessage" || (*iv) == "Type36Hitmap")
1322               prefix = "SUMRAW";
1323             else if ((*iv) == "ndigis" || (*iv) == "adc" || (*iv) == "ndigisFREQ" || (*iv) == "adcCOMB")
1324               prefix = "SUMDIG";
1325             else if ((*iv) == "nclusters" || (*iv) == "x" || (*iv) == "y" || (*iv) == "charge" ||
1326                      (*iv) == "chargeCOMB" || (*iv) == "size" || (*iv) == "sizeX" || (*iv) == "sizeY" ||
1327                      (*iv) == "minrow" || (*iv) == "maxrow" || (*iv) == "mincol" || (*iv) == "maxcol")
1328               prefix = "SUMCLU";
1329             if (currDir.find("Track") != string::npos)
1330               prefix = "SUMTRK";
1331             else if ((*iv) == "residualX_mean" || (*iv) == "residualY_mean" || (*iv) == "residualX_RMS" ||
1332                      (*iv) == "residualY_RMS")
1333               prefix = "SUMTRK";
1334             else if ((*iv) == "ClustX" || (*iv) == "ClustY" || (*iv) == "nRecHits" || (*iv) == "ErrorX" ||
1335                      (*iv) == "ErrorY")
1336               prefix = "SUMHIT";
1337             else if ((*iv) == "Gain1d_mean" || (*iv) == "GainChi2NDF1d_mean" || (*iv) == "GainChi2Prob1d_mean" ||
1338                      (*iv) == "Pedestal1d_mean" || (*iv) == "ScurveChi2ProbSummary_mean" ||
1339                      (*iv) == "ScurveFitResultSummary_mean" || (*iv) == "ScurveSigmasSummary_mean" ||
1340                      (*iv) == "ScurveThresholdSummary_mean" || (*iv) == "Gain1d_RMS" || (*iv) == "GainChi2NDF1d_RMS" ||
1341                      (*iv) == "GainChi2Prob1d_RMS" || (*iv) == "Pedestal1d_RMS" || (*iv) == "GainNPoints1d_mean" ||
1342                      (*iv) == "GainNPoints1d_RMS" || (*iv) == "GainHighPoint1d_mean" ||
1343                      (*iv) == "GainHighPoint1d_RMS" || (*iv) == "GainLowPoint1d_mean" ||
1344                      (*iv) == "GainLowPoint1d_RMS" || (*iv) == "GainEndPoint1d_mean" || (*iv) == "GainEndPoint1d_RMS" ||
1345                      (*iv) == "GainFitResult2d_mean" || (*iv) == "GainFitResult2d_RMS" ||
1346                      (*iv) == "GainDynamicRange2d_mean" || (*iv) == "GainDynamicRange2d_RMS" ||
1347                      (*iv) == "GainSaturate2d_mean" || (*iv) == "GainSaturate2d_RMS" ||
1348                      (*iv) == "ScurveChi2ProbSummary_RMS" || (*iv) == "ScurveFitResultSummary_RMS" ||
1349                      (*iv) == "ScurveSigmasSummary_RMS" || (*iv) == "ScurveThresholdSummary_RMS" ||
1350                      (*iv) == "pixelAliveSummary_mean" || (*iv) == "pixelAliveSummary_FracOfPerfectPix" ||
1351                      (*iv) == "SiPixelErrorsCalibDigis_NCalibErrors")
1352               prefix = "SUMCAL";
1353           }
1354 
1355           if (first_subdir && !isUpgrade) {
1356             nbin = me->getTH1F()->GetNbinsX();
1357             string me_name = prefix + "_" + (*iv) + "_" + dir_name;
1358             if ((*iv) == "adcCOMB" || (*iv) == "chargeCOMB")
1359               me_name = "ALLMODS_" + (*iv) + "_" + dir_name;
1360             else if (prefix == "SUMOFF" && dir_name == "Endcap")
1361               nbin = 96;
1362             else if (dir_name == "Endcap")
1363               nbin = 672;
1364             else if (prefix == "SUMOFF" && dir_name.find("HalfCylinder") != string::npos)
1365               nbin = 24;
1366             else if (dir_name.find("HalfCylinder") != string::npos)
1367               nbin = 168;
1368             else if (prefix == "SUMOFF" && dir_name.find("Disk") != string::npos)
1369               nbin = 12;
1370             else if (dir_name.find("Disk") != string::npos)
1371               nbin = 84;
1372             else if (dir_name.find("Blade") != string::npos)
1373               nbin = 7;
1374             getGrandSummaryME(iBooker, iGetter, nbin, me_name, gsum_mes);
1375           } else if (first_subdir && isUpgrade) {
1376             nbin = me->getTH1F()->GetNbinsX();
1377             string me_name = prefix + "_" + (*iv) + "_" + dir_name;
1378             if ((*iv) == "adcCOMB" || (*iv) == "chargeCOMB")
1379               me_name = "ALLMODS_" + (*iv) + "_" + dir_name;
1380             else if (prefix == "SUMOFF" && dir_name == "Endcap")
1381               nbin = 336;
1382             else if (dir_name == "Endcap")
1383               nbin = 672;
1384             else if (prefix == "SUMOFF" && dir_name.find("HalfCylinder") != string::npos)
1385               nbin = 84;
1386             else if (dir_name.find("HalfCylinder") != string::npos)
1387               nbin = 168;
1388             else if (prefix == "SUMOFF" && dir_name.find("Disk") != string::npos)
1389               nbin = 28;
1390             else if (dir_name.find("Disk") != string::npos)
1391               nbin = 56;
1392             else if (dir_name.find("Blade") != string::npos)
1393               nbin = 2;
1394             getGrandSummaryME(iBooker, iGetter, nbin, me_name, gsum_mes);
1395           }
1396 
1397           for (vector<MonitorElement *>::const_iterator igm = gsum_mes.begin(); igm != gsum_mes.end(); igm++) {
1398             if ((*igm)->getName().find(var) != string::npos) {
1399               if (prefix == "SUMOFF")
1400                 (*igm)->setAxisTitle("Blades", 1);
1401               else if ((*igm)->getName().find("adcCOMB_") != string::npos)
1402                 (*igm)->setAxisTitle("Digi charge [ADC]", 1);
1403               else if ((*igm)->getName().find("chargeCOMB_") != string::npos)
1404                 (*igm)->setAxisTitle("Cluster charge [kilo electrons]", 1);
1405               else
1406                 (*igm)->setAxisTitle("Modules", 1);
1407               string title = "";
1408               if ((*igm)->getName().find("NErrors_") != string::npos && prefix == "SUMOFF")
1409                 title = "Total number of errors per Blade";
1410               else if ((*igm)->getName().find("NErrors_") != string::npos && prefix == "SUMRAW")
1411                 title = "Total number of errors per Module";
1412               else if (prefix == "SUMOFF")
1413                 title = "mean " + (*iv) + " per Blade";
1414               else if ((*igm)->getName().find("FREQ_") != string::npos)
1415                 title = "NEvents with digis per Module";
1416               else if ((*igm)->getName().find("adcCOMB_") != string::npos)
1417                 title = "NDigis";
1418               else if ((*igm)->getName().find("chargeCOMB_") != string::npos)
1419                 title = "NClusters";
1420               else
1421                 title = "mean " + (*iv) + " per Module";
1422               (*igm)->setAxisTitle(title, 2);
1423               nbin_i = 0;
1424               if (!isUpgrade) {
1425                 if ((*igm)->getName().find("ALLMODS_adcCOMB_") != string::npos) {
1426                   nbin_subdir = 128;
1427                 } else if ((*igm)->getName().find("ALLMODS_chargeCOMB_") != string::npos) {
1428                   nbin_subdir = 100;
1429                 } else if ((*igm)->getName().find("Panel_") != string::npos) {
1430                   nbin_subdir = 7;
1431                 } else if ((*igm)->getName().find("Blade") != string::npos) {
1432                   if ((*im).find("_1") != string::npos)
1433                     nbin_subdir = 4;
1434                   if ((*im).find("_2") != string::npos) {
1435                     nbin_i = 4;
1436                     nbin_subdir = 3;
1437                   }
1438                 } else if ((*igm)->getName().find("Disk") != string::npos) {
1439                   nbin_i = ((cnt - 1) % 12) * 7;
1440                   nbin_subdir = 7;
1441                 } else if ((*igm)->getName().find("HalfCylinder") != string::npos) {
1442                   if (prefix != "SUMOFF") {
1443                     nbin_subdir = 84;
1444                     if ((*im).find("_2") != string::npos)
1445                       nbin_i = 84;
1446                   } else {
1447                     nbin_subdir = 12;
1448                     if ((*im).find("_2") != string::npos)
1449                       nbin_i = 12;
1450                   }
1451                 } else if ((*igm)->getName().find("Endcap") != string::npos) {
1452                   if (prefix != "SUMOFF") {
1453                     nbin_subdir = 168;
1454                     if ((*im).find("_mO") != string::npos)
1455                       nbin_i = 168;
1456                     if ((*im).find("_pI") != string::npos)
1457                       nbin_i = 336;
1458                     if ((*im).find("_pO") != string::npos)
1459                       nbin_i = 504;
1460                   } else {
1461                     nbin_subdir = 24;
1462                     if ((*im).find("_mO") != string::npos)
1463                       nbin_i = 24;
1464                     if ((*im).find("_pI") != string::npos)
1465                       nbin_i = 48;
1466                     if ((*im).find("_pO") != string::npos)
1467                       nbin_i = 72;
1468                   }
1469                 }
1470               } else if (isUpgrade) {
1471                 if ((*igm)->getName().find("ALLMODS_adcCOMB_") != string::npos) {
1472                   nbin_subdir = 128;
1473                 } else if ((*igm)->getName().find("ALLMODS_chargeCOMB_") != string::npos) {
1474                   nbin_subdir = 100;
1475                 } else if ((*igm)->getName().find("Panel_") != string::npos) {
1476                   nbin_subdir = 2;
1477                 } else if ((*igm)->getName().find("Blade") != string::npos) {
1478                   if ((*im).find("_1") != string::npos)
1479                     nbin_subdir = 1;
1480                   if ((*im).find("_2") != string::npos) {
1481                     nbin_i = 1;
1482                     nbin_subdir = 1;
1483                   }
1484                 } else if ((*igm)->getName().find("Disk") != string::npos) {
1485                   nbin_i = ((cnt - 1) % 28) * 2;
1486                   nbin_subdir = 2;
1487                 } else if ((*igm)->getName().find("HalfCylinder") != string::npos) {
1488                   if (prefix != "SUMOFF") {
1489                     nbin_subdir = 56;
1490                     if ((*im).find("_2") != string::npos)
1491                       nbin_i = 56;
1492                     if ((*im).find("_3") != string::npos)
1493                       nbin_i = 112;
1494                   } else {
1495                     nbin_subdir = 28;
1496                     if ((*im).find("_2") != string::npos)
1497                       nbin_i = 28;
1498                     if ((*im).find("_3") != string::npos)
1499                       nbin_i = 56;
1500                   }
1501                 } else if ((*igm)->getName().find("Endcap") != string::npos) {
1502                   if (prefix != "SUMOFF") {
1503                     nbin_subdir = 168;
1504                     if ((*im).find("_mO") != string::npos)
1505                       nbin_i = 168;
1506                     if ((*im).find("_pI") != string::npos)
1507                       nbin_i = 336;
1508                     if ((*im).find("_pO") != string::npos)
1509                       nbin_i = 504;
1510                   } else {
1511                     nbin_subdir = 84;
1512                     if ((*im).find("_mO") != string::npos)
1513                       nbin_i = 84;
1514                     if ((*im).find("_pI") != string::npos)
1515                       nbin_i = 168;
1516                     if ((*im).find("_pO") != string::npos)
1517                       nbin_i = 252;
1518                   }
1519                 }
1520               }
1521 
1522               if ((*igm)->getName().find("ndigisFREQ") == string::npos) {
1523                 if (((*igm)->getName().find("adcCOMB") != string::npos &&
1524                      me->getName().find("adcCOMB") != string::npos) ||
1525                     ((*igm)->getName().find("chargeCOMB") != string::npos &&
1526                      me->getName().find("chargeCOMB") != string::npos)) {
1527                   (*igm)->getTH1F()->Add(me->getTH1F());
1528                 } else if (((*igm)->getName().find("charge_") != string::npos &&
1529                             (*igm)->getName().find("Track_") == string::npos &&
1530                             me->getName().find("charge_") != string::npos &&
1531                             me->getName().find("Track_") == string::npos) ||
1532                            ((*igm)->getName().find("nclusters_") != string::npos &&
1533                             (*igm)->getName().find("Track_") == string::npos &&
1534                             me->getName().find("nclusters_") != string::npos &&
1535                             me->getName().find("Track_") == string::npos) ||
1536                            ((*igm)->getName().find("size_") != string::npos &&
1537                             (*igm)->getName().find("Track_") == string::npos &&
1538                             me->getName().find("size_") != string::npos &&
1539                             me->getName().find("Track_") == string::npos) ||
1540                            ((*igm)->getName().find("charge_OffTrack_") != string::npos &&
1541                             me->getName().find("charge_OffTrack_") != string::npos) ||
1542                            ((*igm)->getName().find("nclusters_OffTrack_") != string::npos &&
1543                             me->getName().find("nclusters_OffTrack_") != string::npos) ||
1544                            ((*igm)->getName().find("size_OffTrack_") != string::npos &&
1545                             me->getName().find("size_OffTrack_") != string::npos) ||
1546                            ((*igm)->getName().find("charge_OnTrack_") != string::npos &&
1547                             me->getName().find("charge_OnTrack_") != string::npos) ||
1548                            ((*igm)->getName().find("nclusters_OnTrack_") != string::npos &&
1549                             me->getName().find("nclusters_OnTrack_") != string::npos) ||
1550                            ((*igm)->getName().find("size_OnTrack_") != string::npos &&
1551                             me->getName().find("size_OnTrack_") != string::npos) ||
1552                            ((*igm)->getName().find("charge_") == string::npos &&
1553                             (*igm)->getName().find("nclusters_") == string::npos &&
1554                             (*igm)->getName().find("size_") == string::npos)) {
1555                   for (int k = 1; k < nbin_subdir + 1; k++)
1556                     if (me->getBinContent(k) > 0)
1557                       (*igm)->setBinContent(k + nbin_i, me->getBinContent(k));
1558                 }
1559               } else if (me->getName().find("ndigisFREQ") != string::npos) {
1560                 for (int k = 1; k < nbin_subdir + 1; k++)
1561                   if (me->getBinContent(k) > 0)
1562                     (*igm)->setBinContent(k + nbin_i, me->getBinContent(k));
1563               }
1564               //           }// for
1565             }
1566           }
1567         }
1568       }
1569     }
1570 
1571     iDir++;
1572     first_subdir = false;  // We are done processing the first directory, we
1573                            // don't add any new MEs in the future passes.
1574   }                        // end for it (subdirs)
1575 }
1576 //=============================================================================================================
1577 //
1578 // -- Get Summary ME
1579 //
1580 void SiPixelActionExecutor::getGrandSummaryME(
1581     DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, int nbin, string &me_name, vector<MonitorElement *> &mes) {
1582   // printing cout<<"Entering SiPixelActionExecutor::getGrandSummaryME for:
1583   // "<<me_name<<endl;
1584   if ((iBooker.pwd()).find("Pixel") == string::npos)
1585     return;  // If one doesn't find pixel
1586   vector<string> contents = iGetter.getMEs();
1587 
1588   for (vector<string>::const_iterator it = contents.begin(); it != contents.end(); it++) {
1589     // printing cout<<"in grand summary me: "<<me_name<<","<<(*it)<<endl;
1590     if ((*it).find(me_name) == 0) {
1591       string fullpathname = iBooker.pwd() + "/" + me_name;
1592       MonitorElement *me = iGetter.get(fullpathname);
1593 
1594       if (me) {
1595         me->Reset();
1596         mes.push_back(me);
1597         return;
1598       }
1599     }
1600   }
1601 
1602   MonitorElement *temp_me(nullptr);
1603   if (me_name.find("ALLMODS_adcCOMB_") != string::npos)
1604     temp_me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 128, 0, 256);
1605   else if (me_name.find("ALLMODS_chargeCOMB_") != string::npos)
1606     temp_me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 100, 0, 200);
1607   else
1608     temp_me = iBooker.book1D(me_name.c_str(), me_name.c_str(), nbin, 1., nbin + 1.);
1609   if (temp_me)
1610     mes.push_back(temp_me);
1611 
1612   //  if(temp_me) cout<<"finally found grand ME: "<<me_name<<endl;
1613 }
1614 
1615 //=============================================================================================================
1616 //
1617 // -- Get Summary ME
1618 //
1619 SiPixelActionExecutor::MonitorElement *SiPixelActionExecutor::getSummaryME(DQMStore::IBooker &iBooker,
1620                                                                            DQMStore::IGetter &iGetter,
1621                                                                            string me_name,
1622                                                                            bool isUpgrade) {
1623   // printing cout<<"Entering SiPixelActionExecutor::getSummaryME for:
1624   // "<<me_name<<endl;
1625   MonitorElement *me = nullptr;
1626   if ((iBooker.pwd()).find("Pixel") == string::npos)
1627     return me;
1628   vector<string> contents = iGetter.getMEs();
1629 
1630   for (vector<string>::const_iterator it = contents.begin(); it != contents.end(); it++) {
1631     if ((*it).find(me_name) == 0) {
1632       string fullpathname = iBooker.pwd() + "/" + (*it);
1633       me = iGetter.get(fullpathname);
1634       if (me) {
1635         me->Reset();
1636         return me;
1637       }
1638     }
1639   }
1640   contents.clear();
1641   if (!isUpgrade) {
1642     if (me_name.find("SUMOFF") == string::npos) {
1643       if (me_name.find("Blade_") != string::npos)
1644         me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 7, 1., 8.);
1645       else
1646         me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 4, 1., 5.);
1647     } else if (me_name.find("Layer_1") != string::npos) {
1648       me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 10, 1., 11.);
1649     } else if (me_name.find("Layer_2") != string::npos) {
1650       me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 16, 1., 17.);
1651     } else if (me_name.find("Layer_3") != string::npos) {
1652       me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 22, 1., 23.);
1653     } else if (me_name.find("Disk_") != string::npos) {
1654       me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 12, 1., 13.);
1655     }
1656   }  // endifNOTUpgrade
1657   else if (isUpgrade) {
1658     if (me_name.find("SUMOFF") == string::npos) {
1659       if (me_name.find("Blade_") != string::npos)
1660         me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 2, 1., 3.);
1661       else
1662         me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 1, 1., 2.);
1663     } else if (me_name.find("Layer_1") != string::npos) {
1664       me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 6, 1., 7.);
1665     } else if (me_name.find("Layer_2") != string::npos) {
1666       me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 14, 1., 15.);
1667     } else if (me_name.find("Layer_3") != string::npos) {
1668       me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 22, 1., 23.);
1669     } else if (me_name.find("Layer_4") != string::npos) {
1670       me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 32, 1., 33.);
1671     } else if (me_name.find("Disk_") != string::npos) {
1672       me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 28, 1., 29.);
1673     }
1674   }  // endifUpgrade
1675 
1676   return me;
1677 }
1678 
1679 //=============================================================================================================
1680 SiPixelActionExecutor::MonitorElement *SiPixelActionExecutor::getFEDSummaryME(DQMStore::IBooker &iBooker,
1681                                                                               DQMStore::IGetter &iGetter,
1682                                                                               string me_name) {
1683   // printing cout<<"Entering SiPixelActionExecutor::getFEDSummaryME..."<<endl;
1684   MonitorElement *me = nullptr;
1685   if ((iBooker.pwd()).find("Pixel") == string::npos)
1686     return me;
1687   vector<string> contents = iGetter.getMEs();
1688 
1689   for (vector<string>::const_iterator it = contents.begin(); it != contents.end(); it++) {
1690     if ((*it).find(me_name) == 0) {
1691       string fullpathname = iBooker.pwd() + "/" + (*it);
1692 
1693       me = iGetter.get(fullpathname);
1694 
1695       if (me) {
1696         me->Reset();
1697         return me;
1698       }
1699     }
1700   }
1701   contents.clear();
1702   me = iBooker.book1D(me_name.c_str(), me_name.c_str(), 40, -0.5, 39.5);
1703 
1704   return me;
1705 }
1706 
1707 //=============================================================================================================
1708 void SiPixelActionExecutor::bookOccupancyPlots(DQMStore::IBooker &iBooker,
1709                                                DQMStore::IGetter &iGetter,
1710                                                bool hiRes,
1711                                                bool isbarrel)  // Polymorphism
1712 {
1713   if (Tier0Flag_)
1714     return;
1715   vector<string> subdirs = iGetter.getSubdirs();
1716   for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
1717     if (isbarrel && (*it).find("Barrel") == string::npos)
1718       continue;
1719     if (!isbarrel && (*it).find("Endcap") == string::npos)
1720       continue;
1721 
1722     if ((*it).find("Module_") != string::npos)
1723       continue;
1724     if ((*it).find("Panel_") != string::npos)
1725       continue;
1726     if ((*it).find("Ladder_") != string::npos)
1727       continue;
1728     if ((*it).find("Blade_") != string::npos)
1729       continue;
1730     if ((*it).find("Layer_") != string::npos)
1731       continue;
1732     if ((*it).find("Disk_") != string::npos)
1733       continue;
1734     iBooker.cd(*it);
1735     iGetter.cd(*it);
1736     bookOccupancyPlots(iBooker, iGetter, hiRes, isbarrel);
1737     if (!hiRes) {
1738       // occupancyprinting cout<<"booking low res barrel occ plot now!"<<endl;
1739       OccupancyMap = iBooker.book2D((isbarrel ? "barrelOccupancyMap" : "endcapOccupancyMap"),
1740                                     "Barrel Digi Occupancy Map (4 pix per bin)",
1741                                     isbarrel ? 208 : 130,
1742                                     0.,
1743                                     isbarrel ? 416. : 260.,
1744                                     80,
1745                                     0.,
1746                                     160.);
1747     } else {
1748       // occupancyprinting cout<<"booking high res barrel occ plot now!"<<endl;
1749       OccupancyMap = iBooker.book2D((isbarrel ? "barrelOccupancyMap" : "endcapOccupancyMap"),
1750                                     "Barrel Digi Occupancy Map (1 pix per bin)",
1751                                     isbarrel ? 416 : 260,
1752                                     0.,
1753                                     isbarrel ? 416. : 260.,
1754                                     160,
1755                                     0.,
1756                                     160.);
1757     }
1758     OccupancyMap->setAxisTitle("Columns", 1);
1759     OccupancyMap->setAxisTitle("Rows", 2);
1760 
1761     iBooker.goUp();
1762     iGetter.setCurrentFolder(iBooker.pwd());
1763   }
1764 }
1765 //=============================================================================================================
1766 void SiPixelActionExecutor::bookOccupancyPlots(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, bool hiRes) {
1767   if (Tier0Flag_)
1768     return;
1769   // Barrel
1770   iGetter.cd();
1771   iBooker.cd();
1772   iGetter.setCurrentFolder("Pixel");
1773   iBooker.setCurrentFolder("Pixel");
1774   this->bookOccupancyPlots(iBooker, iGetter, hiRes, true);
1775 
1776   // Endcap
1777   iGetter.cd();
1778   iBooker.cd();
1779   iGetter.setCurrentFolder("Pixel");
1780   iBooker.setCurrentFolder("Pixel");
1781   this->bookOccupancyPlots(iBooker, iGetter, hiRes, false);
1782 }
1783 
1784 void SiPixelActionExecutor::createOccupancy(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter) {
1785   // std::cout<<"entering SiPixelActionExecutor::createOccupancy..."<<std::endl;
1786   if (Tier0Flag_)
1787     return;
1788   iBooker.cd();
1789   iGetter.cd();
1790   fillOccupancy(iBooker, iGetter, true);
1791   iBooker.cd();
1792   iGetter.cd();
1793   fillOccupancy(iBooker, iGetter, false);
1794   iBooker.cd();
1795   iGetter.cd();
1796 
1797   // std::cout<<"leaving SiPixelActionExecutor::createOccupancy..."<<std::endl;
1798 }
1799 
1800 //=============================================================================================================
1801 
1802 void SiPixelActionExecutor::fillOccupancy(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, bool isbarrel) {
1803   // occupancyprinting cout<<"entering
1804   // SiPixelActionExecutor::fillOccupancy..."<<std::endl;
1805   if (Tier0Flag_)
1806     return;
1807   string currDir = iBooker.pwd();
1808   string dname = currDir.substr(currDir.find_last_of('/') + 1);
1809 
1810   if (dname.find("Layer_") != string::npos || dname.find("Disk_") != string::npos) {
1811     vector<string> meVec = iGetter.getMEs();
1812     for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
1813       string full_path = currDir + "/" + (*it);
1814       if (full_path.find("hitmap_siPixelDigis") != string::npos) {  // If we have the hitmap ME
1815         MonitorElement *me = iGetter.get(full_path);
1816         if (!me)
1817           continue;
1818         string path = full_path;
1819         while (path.find_last_of('/') != 5)  // Stop before Pixel/
1820         {
1821           path = path.substr(0, path.find_last_of('/'));
1822           //                            cout << "\t" <<
1823           // path
1824           //<< endl;
1825           OccupancyMap = iGetter.get(path + "/" + (isbarrel ? "barrel" : "endcap") + "OccupancyMap");
1826 
1827           if (OccupancyMap) {
1828             for (int i = 1; i != me->getNbinsX() + 1; i++)
1829               for (int j = 1; j != me->getNbinsY() + 1; j++) {
1830                 float previous = OccupancyMap->getBinContent(i, j);
1831                 OccupancyMap->setBinContent(i, j, previous + me->getBinContent(i, j));
1832               }
1833             OccupancyMap->getTH2F()->SetEntries(OccupancyMap->getTH2F()->Integral());
1834           }
1835         }
1836       }
1837     }
1838   } else {
1839     vector<string> subdirs = iGetter.getSubdirs();
1840     for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
1841       iGetter.cd(*it);
1842       iBooker.cd(*it);
1843       if (*it != "Pixel" &&
1844           ((isbarrel && (*it).find("Barrel") == string::npos) || (!isbarrel && (*it).find("Endcap") == string::npos)))
1845         continue;
1846       fillOccupancy(iBooker, iGetter, isbarrel);
1847       iBooker.goUp();
1848       iGetter.setCurrentFolder(iBooker.pwd());
1849     }
1850   }
1851 
1852   // occupancyprinting cout<<"leaving
1853   // SiPixelActionExecutor::fillOccupancy..."<<std::endl;
1854 }
1855 
1856 //=============================================================================================================
1857 
1858 void SiPixelActionExecutor::normaliseAvDigiOcc(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter) {
1859   // occupancyprinting cout<<"entering
1860   // SiPixelActionExecutor::normaliseAvDigiOcc..."<<std::endl;
1861 
1862   iGetter.cd();
1863 
1864   MonitorElement *roccupancyPlot = iGetter.get("Pixel/averageDigiOccupancy");
1865 
1866   float totalDigisBPIX = 0.;
1867   float totalDigisFPIX = 0.;
1868   for (int i = 1; i != 41; i++) {
1869     if (i < 33)
1870       totalDigisBPIX += roccupancyPlot->getBinContent(i);
1871     else
1872       totalDigisFPIX += roccupancyPlot->getBinContent(i);
1873   }
1874   float averageBPIXOcc = totalDigisBPIX / 32.;
1875   float averageFPIXOcc = totalDigisFPIX / 8.;
1876   for (int i = 1; i != 41; i++) {
1877     if (i < 33)
1878       roccupancyPlot->setBinContent(i, averageBPIXOcc != 0. ? roccupancyPlot->getBinContent(i) / averageBPIXOcc : 0.);
1879     else
1880       roccupancyPlot->setBinContent(i, averageFPIXOcc != 0. ? roccupancyPlot->getBinContent(i) / averageFPIXOcc : 0.);
1881   }
1882 
1883   iGetter.setCurrentFolder(iBooker.pwd());
1884 }
1885 
1886 //=============================================================================================================
1887 
1888 void SiPixelActionExecutor::normaliseAvDigiOccVsLumi(DQMStore::IBooker &iBooker,
1889                                                      DQMStore::IGetter &iGetter,
1890                                                      int lumisec) {
1891   iGetter.cd();
1892 
1893   MonitorElement *avgfedDigiOccvsLumi = iGetter.get("Pixel/avgfedDigiOccvsLumi");
1894 
1895   float totalDigisBPIX = 0.;
1896   float totalDigisFPIX = 0.;
1897   for (int i = 1; i != 41; i++) {
1898     if (i < 33)
1899       totalDigisBPIX += avgfedDigiOccvsLumi->getBinContent(lumisec, i);
1900     else
1901       totalDigisFPIX += avgfedDigiOccvsLumi->getBinContent(lumisec, i);
1902   }
1903   float averageBPIXOcc = totalDigisBPIX / 32.;
1904   float averageFPIXOcc = totalDigisFPIX / 8.;
1905   for (int i = 1; i != 41; i++) {
1906     if (i < 33) {
1907       avgfedDigiOccvsLumi->setBinContent(
1908           lumisec, i, averageBPIXOcc != 0. ? avgfedDigiOccvsLumi->getBinContent(lumisec, i) / averageBPIXOcc : 0.);
1909     } else {
1910       avgfedDigiOccvsLumi->setBinContent(
1911           lumisec, i, averageFPIXOcc != 0. ? avgfedDigiOccvsLumi->getBinContent(lumisec, i) / averageFPIXOcc : 0.);
1912     }
1913   }
1914 
1915   iGetter.setCurrentFolder(iBooker.pwd());
1916 }
1917 
1918 //=============================================================================================================
1919 
1920 void SiPixelActionExecutor::bookEfficiency(DQMStore::IBooker &iBooker, bool isUpgrade) {
1921   // Barrel
1922   iBooker.cd();
1923   iBooker.setCurrentFolder("Pixel/Barrel");
1924   if (!isUpgrade) {
1925     if (Tier0Flag_) {
1926       HitEfficiency_L1 = iBooker.book2D(
1927           "HitEfficiency_L1", "Hit Efficiency in Barrel_Layer1;Module;Ladder", 9, -4.5, 4.5, 21, -10.5, 10.5);
1928       HitEfficiency_L2 = iBooker.book2D(
1929           "HitEfficiency_L2", "Hit Efficiency in Barrel_Layer2;Module;Ladder", 9, -4.5, 4.5, 33, -16.5, 16.5);
1930       HitEfficiency_L3 = iBooker.book2D(
1931           "HitEfficiency_L3", "Hit Efficiency in Barrel_Layer3;Module;Ladder", 9, -4.5, 4.5, 45, -22.5, 22.5);
1932     } else {
1933       HitEfficiency_L1 = iBooker.book2D(
1934           "HitEfficiency_L1", "Hit Efficiency in Barrel_Layer1;Module;Ladder", 9, -4.5, 4.5, 21, -10.5, 10.5);
1935       HitEfficiency_L2 = iBooker.book2D(
1936           "HitEfficiency_L2", "Hit Efficiency in Barrel_Layer2;Module;Ladder", 9, -4.5, 4.5, 33, -16.5, 16.5);
1937       HitEfficiency_L3 = iBooker.book2D(
1938           "HitEfficiency_L3", "Hit Efficiency in Barrel_Layer3;Module;Ladder", 9, -4.5, 4.5, 45, -22.5, 22.5);
1939     }
1940   }  // endifNOTUpgrade
1941   else if (isUpgrade) {
1942     if (Tier0Flag_) {
1943       HitEfficiency_L1 =
1944           iBooker.book2D("HitEfficiency_L1", "Hit Efficiency in Barrel_Layer1;z-side;Ladder", 2, -1., 1., 12, -6., 6.);
1945       HitEfficiency_L2 = iBooker.book2D(
1946           "HitEfficiency_L2", "Hit Efficiency in Barrel_Layer2;z-side;Ladder", 2, -1., 1., 28, -14., 14.);
1947       HitEfficiency_L3 = iBooker.book2D(
1948           "HitEfficiency_L3", "Hit Efficiency in Barrel_Layer3;z-side;Ladder", 2, -1., 1., 44, -22., 22.);
1949       HitEfficiency_L4 = iBooker.book2D(
1950           "HitEfficiency_L4", "Hit Efficiency in Barrel_Layer4;z-side;Ladder", 2, -1., 1., 64, -32., 32.);
1951     } else {
1952       HitEfficiency_L1 =
1953           iBooker.book2D("HitEfficiency_L1", "Hit Efficiency in Barrel_Layer1;Module;Ladder", 8, -4., 4., 12, -6., 6.);
1954       HitEfficiency_L2 = iBooker.book2D(
1955           "HitEfficiency_L2", "Hit Efficiency in Barrel_Layer2;Module;Ladder", 8, -4., 4., 28, -14., 14.);
1956       HitEfficiency_L3 = iBooker.book2D(
1957           "HitEfficiency_L3", "Hit Efficiency in Barrel_Layer3;Module;Ladder", 8, -4., 4., 44, -22., 22.);
1958       HitEfficiency_L4 = iBooker.book2D(
1959           "HitEfficiency_L4", "Hit Efficiency in Barrel_Layer4;Module;Ladder", 8, -4., 4., 64, -32., 32.);
1960     }
1961   }  // endifUpgrade
1962   // Endcap
1963   iBooker.cd();
1964   iBooker.setCurrentFolder("Pixel/Endcap");
1965   if (!isUpgrade) {
1966     if (Tier0Flag_) {
1967       HitEfficiency_Dp1 = iBooker.book2D(
1968           "HitEfficiency_Dp1", "Hit Efficiency in Endcap_Disk_p1;Blade;Panel", 26, -13., 13., 2, 0.5, 2.5);
1969       HitEfficiency_Dp2 = iBooker.book2D(
1970           "HitEfficiency_Dp2", "Hit Efficiency in Endcap_Disk_p2;Blade;Panel", 26, -13., 13., 2, 0.5, 2.5);
1971       HitEfficiency_Dm1 = iBooker.book2D(
1972           "HitEfficiency_Dm1", "Hit Efficiency in Endcap_Disk_m1;Blade;Panel", 26, -13., 13., 2, 0.5, 2.5);
1973       HitEfficiency_Dm2 = iBooker.book2D(
1974           "HitEfficiency_Dm2", "Hit Efficiency in Endcap_Disk_m2;;Blade;Panel", 26, -13., 13., 2, 0.5, 2.5);
1975     } else {
1976       HitEfficiency_Dp1 = iBooker.book2D(
1977           "HitEfficiency_Dp1", "Hit Efficiency in Endcap_Disk_p1;Blades;Modules", 24, -12., 12., 7, 1., 8.);
1978       HitEfficiency_Dp2 = iBooker.book2D(
1979           "HitEfficiency_Dp2", "Hit Efficiency in Endcap_Disk_p2;Blades;Modules", 24, -12., 12., 7, 1., 8.);
1980       HitEfficiency_Dm1 = iBooker.book2D(
1981           "HitEfficiency_Dm1", "Hit Efficiency in Endcap_Disk_m1;Blades;Modules", 24, -12., 12., 7, 1., 8.);
1982       HitEfficiency_Dm2 = iBooker.book2D(
1983           "HitEfficiency_Dm2", "Hit Efficiency in Endcap_Disk_m2;Blades;Modules", 24, -12., 12., 7, 1., 8.);
1984     }
1985   } else if (isUpgrade) {
1986     if (Tier0Flag_) {
1987       HitEfficiency_Dp1 =
1988           iBooker.book2D("HitEfficiency_Dp1", "Hit Efficiency in Endcap_Disk_p1;Blades;", 28, -17., 11., 1, 0., 1.);
1989       HitEfficiency_Dp2 =
1990           iBooker.book2D("HitEfficiency_Dp2", "Hit Efficiency in Endcap_Disk_p2;Blades;", 28, -17., 11., 1, 0., 1.);
1991       HitEfficiency_Dp3 =
1992           iBooker.book2D("HitEfficiency_Dp3", "Hit Efficiency in Endcap_Disk_p3;Blades;", 28, -17., 11., 1, 0., 1.);
1993       HitEfficiency_Dm1 =
1994           iBooker.book2D("HitEfficiency_Dm1", "Hit Efficiency in Endcap_Disk_m1;Blades;", 28, -17., 11., 1, 0., 1.);
1995       HitEfficiency_Dm2 =
1996           iBooker.book2D("HitEfficiency_Dm2", "Hit Efficiency in Endcap_Disk_m2;Blades;", 28, -17., 11., 1, 0., 1.);
1997       HitEfficiency_Dm3 =
1998           iBooker.book2D("HitEfficiency_Dm3", "Hit Efficiency in Endcap_Disk_m3;Blades;", 28, -17., 11., 1, 0., 1.);
1999     } else {
2000       HitEfficiency_Dp1 = iBooker.book2D(
2001           "HitEfficiency_Dp1", "Hit Efficiency in Endcap_Disk_p1;Blades;Modules", 28, -17., 11., 2, 1., 3.);
2002       HitEfficiency_Dp2 = iBooker.book2D(
2003           "HitEfficiency_Dp2", "Hit Efficiency in Endcap_Disk_p2;Blades;Modules", 28, -17., 11., 2, 1., 3.);
2004       HitEfficiency_Dp3 = iBooker.book2D(
2005           "HitEfficiency_Dp3", "Hit Efficiency in Endcap_Disk_p3;Blades;Modules", 28, -17., 11., 2, 1., 3.);
2006       HitEfficiency_Dm1 = iBooker.book2D(
2007           "HitEfficiency_Dm1", "Hit Efficiency in Endcap_Disk_m1;Blades;Modules", 28, -17., 11., 2, 1., 3.);
2008       HitEfficiency_Dm2 = iBooker.book2D(
2009           "HitEfficiency_Dm2", "Hit Efficiency in Endcap_Disk_m2;Blades;Modules", 28, -17., 11., 2, 1., 3.);
2010       HitEfficiency_Dm3 = iBooker.book2D(
2011           "HitEfficiency_Dm3", "Hit Efficiency in Endcap_Disk_m3;Blades;Modules", 28, -17., 11., 2, 1., 3.);
2012     }
2013   }  // endif(isUpgrade)
2014   iBooker.cd();
2015   iBooker.cd("Pixel/");
2016   string bins[] = {"Layer1", "Layer2", "Layer3", "Disk1+", "Disk2+", "Disk1-", "Disk2-"};
2017   HitEfficiencySummary = iBooker.book1D("HitEfficiencySummary", "Hit efficiency per sub detector", 7, 0, 7);
2018   HitEfficiencySummary->setAxisTitle("Sub Detector", 1);
2019   HitEfficiencySummary->setAxisTitle("Efficiency (%)", 2);
2020   for (int i = 1; i < 8; i++) {
2021     HitEfficiencySummary->setBinLabel(i, bins[i - 1]);
2022   }
2023 }
2024 
2025 //=============================================================================================================
2026 
2027 void SiPixelActionExecutor::createEfficiency(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, bool isUpgrade) {
2028   // std::cout<<"entering
2029   // SiPixelActionExecutor::createEfficiency..."<<std::endl;
2030   iGetter.cd();
2031   iBooker.cd();
2032   fillEfficiency(iBooker, iGetter, true, isUpgrade);  // Barrel
2033   iGetter.cd();
2034   iBooker.cd();
2035   fillEfficiency(iBooker, iGetter, false, isUpgrade);  // Endcap
2036   iGetter.cd();
2037   iBooker.cd();
2038   // std::cout<<"leaving SiPixelActionExecutor::createEfficiency..."<<std::endl;
2039 }
2040 
2041 //=============================================================================================================
2042 
2043 int SiPixelActionExecutor::getLadder(const std::string &dname_) {
2044   int biny_ = 0;
2045   string lad = dname_.substr(dname_.find("Ladder_") + 7, 2);
2046   if (dname_.find(lad) != string::npos) {
2047     biny_ = atoi(lad.c_str());
2048   }
2049   return biny_;
2050 }
2051 
2052 //=============================================================================================================
2053 
2054 int SiPixelActionExecutor::getBlade(const std::string &dname_) {
2055   int binx_ = 0;
2056   string blad = dname_.substr(dname_.find("Blade_") + 6, 2);
2057   if (dname_.find(blad) != string::npos) {
2058     binx_ = atoi(blad.c_str());
2059   }
2060   return binx_;
2061 }
2062 
2063 //=============================================================================================================
2064 
2065 void SiPixelActionExecutor::fillEfficiency(DQMStore::IBooker &iBooker,
2066                                            DQMStore::IGetter &iGetter,
2067                                            bool isbarrel,
2068                                            bool isUpgrade) {
2069   // cout<<"entering SiPixelActionExecutor::fillEfficiency..."<<std::endl;
2070   string currDir = iBooker.pwd();
2071   string dname = currDir.substr(currDir.find_last_of('/') + 1);
2072   // cout<<"currDir= "<<currDir<< " , dname= "<<dname<<std::endl;
2073 
2074   if (Tier0Flag_) {  // Offline
2075     if (isbarrel && dname.find("Ladder_") != string::npos) {
2076       if (!isUpgrade) {
2077         vector<string> meVec = iGetter.getMEs();
2078         for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
2079           string full_path = currDir + "/" + (*it);
2080 
2081           if (full_path.find("missingMod_") != string::npos) {  // If we have missing hits ME
2082 
2083             // Get the MEs that contain missing and valid hits
2084             MonitorElement *missing = iGetter.get(full_path);
2085             if (!missing)
2086               continue;
2087             string new_path = full_path.replace(full_path.find("missing"), 7, "valid");
2088             MonitorElement *valid = iGetter.get(new_path);
2089             if (!valid)
2090               continue;
2091             int binx = 0;
2092             int biny = 0;
2093             // get the ladder number
2094             biny = getLadder(dname);  // Current
2095             if (currDir.find("Shell_mO") != string::npos || currDir.find("Shell_pO") != string::npos) {
2096               biny = -biny;
2097             }
2098             const int nMod = 4;
2099             for (int i = 1; i < nMod + 1; i++) {
2100               float hitEfficiency = -1.0;
2101               float missingHits = 0;
2102               float validHits = 0;
2103               binx = i;  // Module
2104               if (currDir.find("Shell_m") != string::npos)
2105                 binx = -binx;
2106 
2107               missingHits = missing->getBinContent(i);
2108               validHits = valid->getBinContent(i);
2109               if (validHits + missingHits > 0.)
2110                 hitEfficiency = validHits / (validHits + missingHits);
2111 
2112               if (currDir.find("Layer_1") != string::npos) {
2113                 HitEfficiency_L1 = iGetter.get("Pixel/Barrel/HitEfficiency_L1");
2114                 if (HitEfficiency_L1)
2115                   HitEfficiency_L1->setBinContent(HitEfficiency_L1->getTH2F()->FindBin(binx, biny),
2116                                                   (float)hitEfficiency);
2117               } else if (currDir.find("Layer_2") != string::npos) {
2118                 HitEfficiency_L2 = iGetter.get("Pixel/Barrel/HitEfficiency_L2");
2119                 if (HitEfficiency_L2)
2120                   HitEfficiency_L2->setBinContent(HitEfficiency_L2->getTH2F()->FindBin(binx, biny),
2121                                                   (float)hitEfficiency);
2122               } else if (currDir.find("Layer_3") != string::npos) {
2123                 HitEfficiency_L3 = iGetter.get("Pixel/Barrel/HitEfficiency_L3");
2124                 if (HitEfficiency_L3)
2125                   HitEfficiency_L3->setBinContent(HitEfficiency_L3->getTH2F()->FindBin(binx, biny),
2126                                                   (float)hitEfficiency);
2127               }
2128             }
2129           }
2130         }
2131       }  // endifNOTUpgradeInBPix
2132       else if (isUpgrade) {
2133         vector<string> meVec = iGetter.getMEs();
2134         for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
2135           string full_path = currDir + "/" + (*it);
2136           if (full_path.find("missing_") != string::npos) {  // If we have missing hits ME
2137             MonitorElement *me = iGetter.get(full_path);
2138             if (!me)
2139               continue;
2140             float missingHits = me->getEntries();
2141             string new_path = full_path.replace(full_path.find("missing"), 7, "valid");
2142             me = iGetter.get(new_path);
2143             if (!me)
2144               continue;
2145             float validHits = me->getEntries();
2146             float hitEfficiency = -1.;
2147             if (validHits + missingHits > 0.)
2148               hitEfficiency = validHits / (validHits + missingHits);
2149             int binx = 0;
2150             int biny = 0;
2151             biny = getLadder(dname);
2152             if (currDir.find("Shell_mO") != string::npos || currDir.find("Shell_pO") != string::npos) {
2153               biny = -biny;
2154             }
2155             if (currDir.find("Shell_m") != string::npos) {
2156               binx = 1;
2157             } else {
2158               binx = 2;
2159             }  // x-axis: z-side
2160             if (currDir.find("Layer_1") != string::npos) {
2161               HitEfficiency_L1 = iGetter.get("Pixel/Barrel/HitEfficiency_L1");
2162               if (HitEfficiency_L1)
2163                 HitEfficiency_L1->setBinContent(binx, biny, (float)hitEfficiency);
2164             } else if (currDir.find("Layer_2") != string::npos) {
2165               HitEfficiency_L2 = iGetter.get("Pixel/Barrel/HitEfficiency_L2");
2166               if (HitEfficiency_L2)
2167                 HitEfficiency_L2->setBinContent(binx, biny, (float)hitEfficiency);
2168             } else if (currDir.find("Layer_3") != string::npos) {
2169               HitEfficiency_L3 = iGetter.get("Pixel/Barrel/HitEfficiency_L3");
2170               if (HitEfficiency_L3)
2171                 HitEfficiency_L3->setBinContent(binx, biny, (float)hitEfficiency);
2172             } else if (currDir.find("Layer_4") != string::npos) {
2173               HitEfficiency_L4 = iGetter.get("Pixel/Barrel/HitEfficiency_L4");
2174               if (HitEfficiency_L4)
2175                 HitEfficiency_L4->setBinContent(binx, biny, (float)hitEfficiency);
2176             }
2177           }
2178         }
2179       }  // endifUpgradeInBPix
2180     } else if (!isbarrel && dname.find("Blade_") != string::npos && !isUpgrade) {
2181       vector<string> meVec = iGetter.getMEs();
2182       for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
2183         string full_path = currDir + "/" + (*it);
2184         if (full_path.find("missing_") != string::npos) {  // If we have missing hits ME
2185           MonitorElement *missing = iGetter.get(full_path);
2186           if (!missing)
2187             continue;
2188           // float missingHits = missing->getEntries();
2189           string new_path = full_path.replace(full_path.find("missing"), 7, "valid");
2190           MonitorElement *valid = iGetter.get(new_path);
2191           if (!valid)
2192             continue;
2193           // float validHits = valid->getEntries();
2194           int binx = 0;
2195           int biny = 0;
2196           binx = getBlade(dname);
2197           if (currDir.find("HalfCylinder_mI") != string::npos || currDir.find("HalfCylinder_pI") != string::npos) {
2198             binx = binx + 14;
2199           } else {
2200             binx = 13 - binx;
2201           }
2202           const int nPanel = 2;
2203           for (int i = 1; i < nPanel + 1; i++) {
2204             float hitEfficiency = -1.;
2205             float missingHits = 0;
2206             float validHits = 0;
2207             biny = i;
2208             missingHits = missing->getBinContent(i);
2209             validHits = valid->getBinContent(i);
2210             if (validHits + missingHits > 0.)
2211               hitEfficiency = validHits / (validHits + missingHits);
2212             if (currDir.find("Disk_1") != string::npos && currDir.find("HalfCylinder_m") != string::npos) {
2213               HitEfficiency_Dm1 = iGetter.get("Pixel/Endcap/HitEfficiency_Dm1");
2214               if (HitEfficiency_Dm1)
2215                 HitEfficiency_Dm1->setBinContent(binx, biny, (float)hitEfficiency);
2216             } else if (currDir.find("Disk_2") != string::npos && currDir.find("HalfCylinder_m") != string::npos) {
2217               HitEfficiency_Dm2 = iGetter.get("Pixel/Endcap/HitEfficiency_Dm2");
2218               if (HitEfficiency_Dm2)
2219                 HitEfficiency_Dm2->setBinContent(binx, biny, (float)hitEfficiency);
2220             } else if (currDir.find("Disk_1") != string::npos && currDir.find("HalfCylinder_p") != string::npos) {
2221               HitEfficiency_Dp1 = iGetter.get("Pixel/Endcap/HitEfficiency_Dp1");
2222               if (HitEfficiency_Dp1)
2223                 HitEfficiency_Dp1->setBinContent(binx, biny, (float)hitEfficiency);
2224             } else if (currDir.find("Disk_2") != string::npos && currDir.find("HalfCylinder_p") != string::npos) {
2225               HitEfficiency_Dp2 = iGetter.get("Pixel/Endcap/HitEfficiency_Dp2");
2226               if (HitEfficiency_Dp2)
2227                 HitEfficiency_Dp2->setBinContent(binx, biny, (float)hitEfficiency);
2228             }
2229           }  // EndOfFor
2230         }
2231       }
2232     } else if (!isbarrel && dname.find("Blade_") != string::npos && isUpgrade) {
2233       vector<string> meVec = iGetter.getMEs();
2234       for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
2235         string full_path = currDir + "/" + (*it);
2236         if (full_path.find("missing_") != string::npos) {  // If we have missing hits ME
2237           MonitorElement *me = iGetter.get(full_path);
2238           if (!me)
2239             continue;
2240           float missingHits = me->getEntries();
2241           string new_path = full_path.replace(full_path.find("missing"), 7, "valid");
2242           me = iGetter.get(new_path);
2243           if (!me)
2244             continue;
2245           float validHits = me->getEntries();
2246           float hitEfficiency = -1.;
2247           if (validHits + missingHits > 0.)
2248             hitEfficiency = validHits / (validHits + missingHits);
2249           int binx = 0;
2250           int biny = 1;
2251           binx = getBlade(dname);
2252           if (currDir.find("HalfCylinder_mI") != string::npos || currDir.find("HalfCylinder_pI") != string::npos) {
2253             binx = binx + 12;
2254           } else {
2255             if (binx == 1)
2256               binx = 17;
2257             else if (binx == 2)
2258               binx = 16;
2259             else if (binx == 3)
2260               binx = 15;
2261             else if (binx == 4)
2262               binx = 14;
2263             else if (binx == 5)
2264               binx = 13;
2265             else if (binx == 6)
2266               binx = 12;
2267             else if (binx == 7)
2268               binx = 11;
2269             else if (binx == 8)
2270               binx = 10;
2271             else if (binx == 9)
2272               binx = 9;
2273             else if (binx == 10)
2274               binx = 8;
2275             else if (binx == 11)
2276               binx = 7;
2277             else if (binx == 12)
2278               binx = 6;
2279             else if (binx == 13)
2280               binx = 5;
2281             else if (binx == 14)
2282               binx = 4;
2283             else if (binx == 15)
2284               binx = 3;
2285             else if (binx == 16)
2286               binx = 2;
2287             else if (binx == 17)
2288               binx = 1;
2289           }
2290           if (currDir.find("Disk_1") != string::npos && currDir.find("HalfCylinder_m") != string::npos) {
2291             HitEfficiency_Dm1 = iGetter.get("Pixel/Endcap/HitEfficiency_Dm1");
2292             if (HitEfficiency_Dm1)
2293               HitEfficiency_Dm1->setBinContent(binx, biny, (float)hitEfficiency);
2294           } else if (currDir.find("Disk_2") != string::npos && currDir.find("HalfCylinder_m") != string::npos) {
2295             HitEfficiency_Dm2 = iGetter.get("Pixel/Endcap/HitEfficiency_Dm2");
2296             if (HitEfficiency_Dm2)
2297               HitEfficiency_Dm2->setBinContent(binx, biny, (float)hitEfficiency);
2298           } else if (currDir.find("Disk_3") != string::npos && currDir.find("HalfCylinder_m") != string::npos) {
2299             HitEfficiency_Dm3 = iGetter.get("Pixel/Endcap/HitEfficiency_Dm3");
2300             if (HitEfficiency_Dm3)
2301               HitEfficiency_Dm3->setBinContent(binx, biny, (float)hitEfficiency);
2302           } else if (currDir.find("Disk_1") != string::npos && currDir.find("HalfCylinder_p") != string::npos) {
2303             HitEfficiency_Dp1 = iGetter.get("Pixel/Endcap/HitEfficiency_Dp1");
2304             if (HitEfficiency_Dp1)
2305               HitEfficiency_Dp1->setBinContent(binx, biny, (float)hitEfficiency);
2306           } else if (currDir.find("Disk_2") != string::npos && currDir.find("HalfCylinder_p") != string::npos) {
2307             HitEfficiency_Dp2 = iGetter.get("Pixel/Endcap/HitEfficiency_Dp2");
2308             if (HitEfficiency_Dp2)
2309               HitEfficiency_Dp2->setBinContent(binx, biny, (float)hitEfficiency);
2310           } else if (currDir.find("Disk_3") != string::npos && currDir.find("HalfCylinder_p") != string::npos) {
2311             HitEfficiency_Dp3 = iGetter.get("Pixel/Endcap/HitEfficiency_Dp3");
2312             if (HitEfficiency_Dp3)
2313               HitEfficiency_Dp3->setBinContent(binx, biny, (float)hitEfficiency);
2314           }
2315           // std::cout<<"EFFI: "<<currDir<<" , x: "<<binx<<" , y:
2316           // "<<biny<<std::endl;
2317         }
2318       }
2319     } else {
2320       vector<string> subdirs = iGetter.getSubdirs();
2321       for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
2322         iBooker.cd(*it);
2323         iGetter.cd(*it);
2324         if (*it != "Pixel" &&
2325             ((isbarrel && (*it).find("Barrel") == string::npos) || (!isbarrel && (*it).find("Endcap") == string::npos)))
2326           continue;
2327         fillEfficiency(iBooker, iGetter, isbarrel, isUpgrade);
2328         iBooker.goUp();
2329         iGetter.setCurrentFolder(iBooker.pwd());
2330       }
2331     }
2332   } else {  // Online
2333     if (dname.find("Module_") != string::npos) {
2334       vector<string> meVec = iGetter.getMEs();
2335       for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
2336         string full_path = currDir + "/" + (*it);
2337         if (full_path.find("missing_") != string::npos) {  // If we have missing hits ME
2338           MonitorElement *me = iGetter.get(full_path);
2339           if (!me)
2340             continue;
2341           float missingHits = me->getEntries();
2342           string new_path = full_path.replace(full_path.find("missing"), 7, "valid");
2343           me = iGetter.get(new_path);
2344           if (!me)
2345             continue;
2346           float validHits = me->getEntries();
2347           float hitEfficiency = -1.;
2348           if (validHits + missingHits > 0.)
2349             hitEfficiency = validHits / (validHits + missingHits);
2350           int binx = 0;
2351           int biny = 0;
2352           if (isbarrel) {
2353             if (currDir.find("Shell_m") != string::npos) {
2354               if (currDir.find("Module_4") != string::npos) {
2355                 binx = 1;
2356               } else if (currDir.find("Module_3") != string::npos) {
2357                 binx = 2;
2358               }
2359               if (currDir.find("Module_2") != string::npos) {
2360                 binx = 3;
2361               } else if (currDir.find("Module_1") != string::npos) {
2362                 binx = 4;
2363               }
2364             } else if (currDir.find("Shell_p") != string::npos) {
2365               if (currDir.find("Module_1") != string::npos) {
2366                 binx = 5;
2367               } else if (currDir.find("Module_2") != string::npos) {
2368                 binx = 6;
2369               }
2370               if (currDir.find("Module_3") != string::npos) {
2371                 binx = 7;
2372               } else if (currDir.find("Module_4") != string::npos) {
2373                 binx = 8;
2374               }
2375             }
2376             if (!isUpgrade) {
2377               if (currDir.find("01") != string::npos) {
2378                 biny = 1;
2379               } else if (currDir.find("02") != string::npos) {
2380                 biny = 2;
2381               } else if (currDir.find("03") != string::npos) {
2382                 biny = 3;
2383               } else if (currDir.find("04") != string::npos) {
2384                 biny = 4;
2385               } else if (currDir.find("05") != string::npos) {
2386                 biny = 5;
2387               } else if (currDir.find("06") != string::npos) {
2388                 biny = 6;
2389               } else if (currDir.find("07") != string::npos) {
2390                 biny = 7;
2391               } else if (currDir.find("08") != string::npos) {
2392                 biny = 8;
2393               } else if (currDir.find("09") != string::npos) {
2394                 biny = 9;
2395               } else if (currDir.find("10") != string::npos) {
2396                 biny = 10;
2397               } else if (currDir.find("11") != string::npos) {
2398                 biny = 11;
2399               } else if (currDir.find("12") != string::npos) {
2400                 biny = 12;
2401               } else if (currDir.find("13") != string::npos) {
2402                 biny = 13;
2403               } else if (currDir.find("14") != string::npos) {
2404                 biny = 14;
2405               } else if (currDir.find("15") != string::npos) {
2406                 biny = 15;
2407               } else if (currDir.find("16") != string::npos) {
2408                 biny = 16;
2409               } else if (currDir.find("17") != string::npos) {
2410                 biny = 17;
2411               } else if (currDir.find("18") != string::npos) {
2412                 biny = 18;
2413               } else if (currDir.find("19") != string::npos) {
2414                 biny = 19;
2415               } else if (currDir.find("20") != string::npos) {
2416                 biny = 20;
2417               } else if (currDir.find("21") != string::npos) {
2418                 biny = 21;
2419               } else if (currDir.find("22") != string::npos) {
2420                 biny = 22;
2421               }
2422               if (currDir.find("Shell_mO") != string::npos || currDir.find("Shell_pO") != string::npos) {
2423                 if (currDir.find("Layer_1") != string::npos) {
2424                   biny = biny + 10;
2425                 } else if (currDir.find("Layer_2") != string::npos) {
2426                   biny = biny + 16;
2427                 } else if (currDir.find("Layer_3") != string::npos) {
2428                   biny = biny + 22;
2429                 }
2430               }
2431             } else if (isUpgrade) {
2432               if (currDir.find("01") != string::npos) {
2433                 biny = 1;
2434               } else if (currDir.find("02") != string::npos) {
2435                 biny = 2;
2436               } else if (currDir.find("03") != string::npos) {
2437                 biny = 3;
2438               } else if (currDir.find("04") != string::npos) {
2439                 biny = 4;
2440               } else if (currDir.find("05") != string::npos) {
2441                 biny = 5;
2442               } else if (currDir.find("06") != string::npos) {
2443                 biny = 6;
2444               } else if (currDir.find("07") != string::npos) {
2445                 biny = 7;
2446               } else if (currDir.find("08") != string::npos) {
2447                 biny = 8;
2448               } else if (currDir.find("09") != string::npos) {
2449                 biny = 9;
2450               } else if (currDir.find("10") != string::npos) {
2451                 biny = 10;
2452               } else if (currDir.find("11") != string::npos) {
2453                 biny = 11;
2454               } else if (currDir.find("12") != string::npos) {
2455                 biny = 12;
2456               } else if (currDir.find("13") != string::npos) {
2457                 biny = 13;
2458               } else if (currDir.find("14") != string::npos) {
2459                 biny = 14;
2460               } else if (currDir.find("15") != string::npos) {
2461                 biny = 15;
2462               } else if (currDir.find("16") != string::npos) {
2463                 biny = 16;
2464               } else if (currDir.find("17") != string::npos) {
2465                 biny = 17;
2466               } else if (currDir.find("18") != string::npos) {
2467                 biny = 18;
2468               } else if (currDir.find("19") != string::npos) {
2469                 biny = 19;
2470               } else if (currDir.find("20") != string::npos) {
2471                 biny = 20;
2472               } else if (currDir.find("21") != string::npos) {
2473                 biny = 21;
2474               } else if (currDir.find("22") != string::npos) {
2475                 biny = 22;
2476               } else if (currDir.find("23") != string::npos) {
2477                 biny = 23;
2478               } else if (currDir.find("24") != string::npos) {
2479                 biny = 24;
2480               } else if (currDir.find("25") != string::npos) {
2481                 biny = 25;
2482               } else if (currDir.find("25") != string::npos) {
2483                 biny = 25;
2484               } else if (currDir.find("26") != string::npos) {
2485                 biny = 26;
2486               } else if (currDir.find("27") != string::npos) {
2487                 biny = 27;
2488               } else if (currDir.find("28") != string::npos) {
2489                 biny = 28;
2490               } else if (currDir.find("29") != string::npos) {
2491                 biny = 29;
2492               } else if (currDir.find("30") != string::npos) {
2493                 biny = 30;
2494               } else if (currDir.find("31") != string::npos) {
2495                 biny = 31;
2496               } else if (currDir.find("32") != string::npos) {
2497                 biny = 32;
2498               }
2499               if (currDir.find("Shell_mO") != string::npos || currDir.find("Shell_pO") != string::npos) {
2500                 if (currDir.find("Layer_1") != string::npos) {
2501                   biny = biny + 6;
2502                 } else if (currDir.find("Layer_2") != string::npos) {
2503                   biny = biny + 14;
2504                 } else if (currDir.find("Layer_3") != string::npos) {
2505                   biny = biny + 22;
2506                 } else if (currDir.find("Layer_4") != string::npos) {
2507                   biny = biny + 32;
2508                 }
2509               }
2510             }
2511           } else {  // endcap
2512             if (!isUpgrade) {
2513               if (currDir.find("01") != string::npos) {
2514                 binx = 1;
2515               } else if (currDir.find("02") != string::npos) {
2516                 binx = 2;
2517               } else if (currDir.find("03") != string::npos) {
2518                 binx = 3;
2519               } else if (currDir.find("04") != string::npos) {
2520                 binx = 4;
2521               } else if (currDir.find("05") != string::npos) {
2522                 binx = 5;
2523               } else if (currDir.find("06") != string::npos) {
2524                 binx = 6;
2525               } else if (currDir.find("07") != string::npos) {
2526                 binx = 7;
2527               } else if (currDir.find("08") != string::npos) {
2528                 binx = 8;
2529               } else if (currDir.find("09") != string::npos) {
2530                 binx = 9;
2531               } else if (currDir.find("10") != string::npos) {
2532                 binx = 10;
2533               } else if (currDir.find("11") != string::npos) {
2534                 binx = 11;
2535               } else if (currDir.find("12") != string::npos) {
2536                 binx = 12;
2537               }
2538               if (currDir.find("HalfCylinder_mO") != string::npos || currDir.find("HalfCylinder_pO") != string::npos) {
2539                 binx = binx + 12;
2540               }
2541               if (currDir.find("Panel_1/Module_1") != string::npos) {
2542                 biny = 1;
2543               } else if (currDir.find("Panel_2/Module_1") != string::npos) {
2544                 biny = 2;
2545               } else if (currDir.find("Panel_1/Module_2") != string::npos) {
2546                 biny = 3;
2547               } else if (currDir.find("Panel_2/Module_2") != string::npos) {
2548                 biny = 4;
2549               } else if (currDir.find("Panel_1/Module_3") != string::npos) {
2550                 biny = 5;
2551               } else if (currDir.find("Panel_2/Module_3") != string::npos) {
2552                 biny = 6;
2553               } else if (currDir.find("Panel_1/Module_4") != string::npos) {
2554                 biny = 7;
2555               }
2556             } else if (isUpgrade) {
2557               if (currDir.find("01") != string::npos) {
2558                 binx = 1;
2559               } else if (currDir.find("02") != string::npos) {
2560                 binx = 2;
2561               } else if (currDir.find("03") != string::npos) {
2562                 binx = 3;
2563               } else if (currDir.find("04") != string::npos) {
2564                 binx = 4;
2565               } else if (currDir.find("05") != string::npos) {
2566                 binx = 5;
2567               } else if (currDir.find("06") != string::npos) {
2568                 binx = 6;
2569               } else if (currDir.find("07") != string::npos) {
2570                 binx = 7;
2571               } else if (currDir.find("08") != string::npos) {
2572                 binx = 8;
2573               } else if (currDir.find("09") != string::npos) {
2574                 binx = 9;
2575               } else if (currDir.find("10") != string::npos) {
2576                 binx = 10;
2577               } else if (currDir.find("11") != string::npos) {
2578                 binx = 11;
2579               } else if (currDir.find("12") != string::npos) {
2580                 binx = 12;
2581               } else if (currDir.find("13") != string::npos) {
2582                 binx = 13;
2583               } else if (currDir.find("14") != string::npos) {
2584                 binx = 14;
2585               } else if (currDir.find("15") != string::npos) {
2586                 binx = 15;
2587               } else if (currDir.find("16") != string::npos) {
2588                 binx = 16;
2589               } else if (currDir.find("17") != string::npos) {
2590                 binx = 17;
2591               }
2592               if (currDir.find("HalfCylinder_mO") != string::npos || currDir.find("HalfCylinder_pO") != string::npos) {
2593                 binx = binx + 17;
2594               }
2595               if (currDir.find("Panel_1/Module_1") != string::npos) {
2596                 biny = 1;
2597               } else if (currDir.find("Panel_2/Module_1") != string::npos) {
2598                 biny = 2;
2599               }
2600             }  // endif(isUpgrade)
2601           }
2602 
2603           if (currDir.find("Layer_1") != string::npos) {
2604             HitEfficiency_L1 = iGetter.get("Pixel/Barrel/HitEfficiency_L1");
2605             if (HitEfficiency_L1)
2606               HitEfficiency_L1->setBinContent(binx, biny, (float)hitEfficiency);
2607           } else if (currDir.find("Layer_2") != string::npos) {
2608             HitEfficiency_L2 = iGetter.get("Pixel/Barrel/HitEfficiency_L2");
2609             if (HitEfficiency_L2)
2610               HitEfficiency_L2->setBinContent(binx, biny, (float)hitEfficiency);
2611           } else if (currDir.find("Layer_3") != string::npos) {
2612             HitEfficiency_L3 = iGetter.get("Pixel/Barrel/HitEfficiency_L3");
2613             if (HitEfficiency_L3)
2614               HitEfficiency_L3->setBinContent(binx, biny, (float)hitEfficiency);
2615           } else if (isUpgrade && (currDir.find("Layer_4") != string::npos)) {
2616             HitEfficiency_L4 = iGetter.get("Pixel/Barrel/HitEfficiency_L4");
2617             if (HitEfficiency_L4)
2618               HitEfficiency_L4->setBinContent(binx, biny, (float)hitEfficiency);
2619           } else if (currDir.find("Disk_1") != string::npos && currDir.find("HalfCylinder_m") != string::npos) {
2620             HitEfficiency_Dm1 = iGetter.get("Pixel/Endcap/HitEfficiency_Dm1");
2621             if (HitEfficiency_Dm1)
2622               HitEfficiency_Dm1->setBinContent(binx, biny, (float)hitEfficiency);
2623           } else if (currDir.find("Disk_2") != string::npos && currDir.find("HalfCylinder_m") != string::npos) {
2624             HitEfficiency_Dm2 = iGetter.get("Pixel/Endcap/HitEfficiency_Dm2");
2625             if (HitEfficiency_Dm2)
2626               HitEfficiency_Dm2->setBinContent(binx, biny, (float)hitEfficiency);
2627           } else if (currDir.find("Disk_3") != string::npos && currDir.find("HalfCylinder_m") != string::npos) {
2628             HitEfficiency_Dm3 = iGetter.get("Pixel/Endcap/HitEfficiency_Dm3");
2629             if (HitEfficiency_Dm3)
2630               HitEfficiency_Dm3->setBinContent(binx, biny, (float)hitEfficiency);
2631           } else if (currDir.find("Disk_1") != string::npos && currDir.find("HalfCylinder_p") != string::npos) {
2632             HitEfficiency_Dp1 = iGetter.get("Pixel/Endcap/HitEfficiency_Dp1");
2633             if (HitEfficiency_Dp1)
2634               HitEfficiency_Dp1->setBinContent(binx, biny, (float)hitEfficiency);
2635           } else if (currDir.find("Disk_2") != string::npos && currDir.find("HalfCylinder_p") != string::npos) {
2636             HitEfficiency_Dp2 = iGetter.get("Pixel/Endcap/HitEfficiency_Dp2");
2637             if (HitEfficiency_Dp2)
2638               HitEfficiency_Dp2->setBinContent(binx, biny, (float)hitEfficiency);
2639           } else if (currDir.find("Disk_3") != string::npos && currDir.find("HalfCylinder_p") != string::npos) {
2640             HitEfficiency_Dp3 = iGetter.get("Pixel/Endcap/HitEfficiency_Dp3");
2641             if (HitEfficiency_Dp3)
2642               HitEfficiency_Dp3->setBinContent(binx, biny, (float)hitEfficiency);
2643           }
2644         }
2645       }
2646     } else {
2647       // cout<<"finding subdirs now"<<std::endl;
2648       vector<string> subdirs = iGetter.getSubdirs();
2649       for (vector<string>::const_iterator it = subdirs.begin(); it != subdirs.end(); it++) {
2650         iBooker.cd(*it);
2651         iGetter.cd(*it);
2652         if (*it != "Pixel" &&
2653             ((isbarrel && (*it).find("Barrel") == string::npos) || (!isbarrel && (*it).find("Endcap") == string::npos)))
2654           continue;
2655         fillEfficiency(iBooker, iGetter, isbarrel, isUpgrade);
2656         iBooker.goUp();
2657         iGetter.setCurrentFolder(iBooker.pwd());
2658       }
2659     }
2660   }  // end online/offline
2661   // cout<<"leaving SiPixelActionExecutor::fillEfficiency..."<<std::endl;
2662 }
2663 
2664 //=============================================================================================================
2665 
2666 void SiPixelActionExecutor::fillEfficiencySummary(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter) {
2667   // cout<<"entering
2668   // SiPixelActionExecutor::fillEfficiencySummary..."<<std::endl; First we get
2669   // the summary plot"
2670   if (!Tier0Flag_)
2671     return;
2672   HitEfficiencySummary = iGetter.get("Pixel/HitEfficiencySummary");
2673   // Now we will loop over the hit efficiency plots and fill it"
2674   string hitEfficiencyPostfix[] = {"L1", "L2", "L3", "Dp1", "Dp2", "Dm1", "Dm2"};
2675   std::vector<std::vector<float>> ignoreXBins = {
2676       {-4, 2}, {4, 4, -1, -3, 3, -4, -3, -2, -1, -4, -3, -2, -1, 1, -4}, {1, -4, 1}, {}, {}, {}, {}};
2677   std::vector<std::vector<float>> ignoreYBins = {
2678       {-9, -3}, {1, 16, 1, -13, -13, -5, -5, -5, -5, -6, -6, -6, -6, -8, -8}, {3, 14, 6}, {}, {}, {}, {}};
2679 
2680   for (int i = 0; i < 7; i++) {
2681     string subdetName = "Endcap/";
2682     if (i < 3)
2683       subdetName = "Barrel/";
2684     char meName[50];
2685     sprintf(meName, "Pixel/%sHitEfficiency_%s", subdetName.c_str(), hitEfficiencyPostfix[i].c_str());
2686     MonitorElement *tempHitEffMap = iGetter.get(meName);
2687     float totalEff = 0.;
2688     int totalBins = 0;
2689     TH1 *hitEffMap = tempHitEffMap->getTH1();
2690     for (int xBin = 1; xBin < tempHitEffMap->getNbinsX() + 1; xBin++) {
2691       if (fabs(hitEffMap->GetXaxis()->GetBinCenter(xBin)) < 1.)
2692         continue;
2693       for (int yBin = 1; yBin < tempHitEffMap->getNbinsY() + 1; yBin++) {
2694         if (fabs(hitEffMap->GetYaxis()->GetBinCenter(yBin)) < 0.5)
2695           continue;
2696         bool ignoreBin = false;
2697         for (unsigned int j = 0; j < ignoreXBins[i].size(); j++) {
2698           if (hitEffMap->GetXaxis()->GetBinCenter(xBin) == ignoreXBins[i][j] &&
2699               hitEffMap->GetYaxis()->GetBinCenter(yBin) == ignoreYBins[i][j]) {
2700             ignoreBin = true;
2701             break;
2702           }
2703         }
2704         if (ignoreBin)
2705           continue;
2706         if (!(tempHitEffMap->getBinContent(xBin, yBin) < 0.))
2707           totalEff += tempHitEffMap->getBinContent(xBin, yBin);
2708         totalBins++;
2709       }
2710     }
2711     float overalEff = 0.;
2712     //    std::cout << i << " " << totalEff << " " << totalBins << std::endl;
2713     if (totalBins > 0)
2714       overalEff = totalEff / float(totalBins);
2715     HitEfficiencySummary->setBinContent(i + 1, overalEff);
2716   }
2717 }