Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-02 03:39:01

0001 //
0002 //
0003 // still missing: * check crystals with occupancy zero - to be cross-checked with what was masked in the DAQ
0004 //                * info about what is in/out of daq
0005 //
0006 // ------------------------------------------------------------
0007 
0008 // analyses:
0009 // pedestal runs -> PEDESTAL analysis only (occupancy not available from DB):
0010 // laser runs    -> LASER analysis only
0011 // physics runs  -> PEDESTAL ONLINE + PEDESTAL (from calib sequence) + OCCUPANCY + LASER (from calib sequence) analysis
0012 
0013 // pedestal / pedestal online analysis:
0014 // a) if one crystal is dead or noisy at least in one gain is recorded
0015 // b) cuts: * pedestal value within 100-300
0016 //          * pedestal RMS above 2 (EB) or 2.5 (EE)
0017 //          * pedestal RMS not zero
0018 //          * channel working at all gains [in local pedestal runs]
0019 //          * channel not stuck at G0 [ stuck = at gain zero in more than 1000 events ]
0020 
0021 // laser analysis:
0022 // a) a light module is ON if at least TWO crystals have amplitude>100. The analysis is done on light modules which are on.
0023 // b) cuts: * APD > 400 in EB
0024 //          * APD > 100 in EE
0025 
0026 // occupancy analysis:
0027 // cuts:
0028 // a) a channel in EB (EE) is noisy if it has > 1 permill of total events above high threshold in EB (EE)
0029 
0030 // cosmics/physics runs analysis: combine pedestal online + laser + occupancy analyses
0031 
0032 #include "CondTools/Ecal/interface/EcalLaserHandler.h"
0033 
0034 #include "CondTools/Ecal/interface/EcalChannelStatusHandler.h"
0035 
0036 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0037 
0038 #include "TProfile2D.h"
0039 #include "TTree.h"
0040 #include "TFile.h"
0041 #include "TLine.h"
0042 #include "TStyle.h"
0043 #include "TCanvas.h"
0044 #include "TGaxis.h"
0045 #include "TColor.h"
0046 
0047 popcon::EcalChannelStatusHandler::EcalChannelStatusHandler(const edm::ParameterSet& ps) {
0048   std::cout << "EcalChannelStatus Source handler constructor\n" << std::endl;
0049 
0050   m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
0051   m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
0052   m_sid = ps.getParameter<std::string>("OnlineDBSID");
0053   m_user = ps.getParameter<std::string>("OnlineDBUser");
0054   m_pass = ps.getParameter<std::string>("OnlineDBPassword");
0055   m_locationsource = ps.getParameter<std::string>("LocationSource");
0056   m_location = ps.getParameter<std::string>("Location");
0057   m_gentag = ps.getParameter<std::string>("GenTag");
0058   m_runtype = ps.getParameter<std::string>("RunType");
0059   m_name = ps.getUntrackedParameter<std::string>("name", "EcalChannelStatusHandler");
0060 
0061   std::cout << m_sid << "/" << m_user << "/" << m_pass << "/" << m_location << "/" << m_gentag << std::endl;
0062 }
0063 
0064 popcon::EcalChannelStatusHandler::~EcalChannelStatusHandler() {}
0065 
0066 // ------------------------------------------------
0067 // START PEDESTALS ROUTINES
0068 
0069 // return pedestal values at gain 12
0070 float popcon::EcalChannelStatusHandler::checkPedestalValueGain12(EcalPedestals::Item* item) {
0071   float result = item->mean_x12;
0072   return result;
0073 }
0074 
0075 // return pedestal values at gain 6 - pedestal runs
0076 float popcon::EcalChannelStatusHandler::checkPedestalValueGain6(EcalPedestals::Item* item) {
0077   float result = item->mean_x6;
0078   return result;
0079 }
0080 
0081 // return pedestal values at gain 1 - pedestal runs
0082 float popcon::EcalChannelStatusHandler::checkPedestalValueGain1(EcalPedestals::Item* item) {
0083   float result = item->mean_x1;
0084   return result;
0085 }
0086 
0087 // return pedestal RMS at gain 12
0088 float popcon::EcalChannelStatusHandler::checkPedestalRMSGain12(EcalPedestals::Item* item) {
0089   float result = item->rms_x12;
0090   return result;
0091 }
0092 
0093 // return pedestal RMS at gain 6 - pedestal runs
0094 float popcon::EcalChannelStatusHandler::checkPedestalRMSGain6(EcalPedestals::Item* item) {
0095   float result = item->rms_x6;
0096   return result;
0097 }
0098 
0099 // return pedestal RMS at gain 1 - pedestal runs
0100 float popcon::EcalChannelStatusHandler::checkPedestalRMSGain1(EcalPedestals::Item* item) {
0101   float result = item->rms_x1;
0102   return result;
0103 }
0104 
0105 // ------------------------------------------------
0106 // START LASER ROUTINES
0107 
0108 // choose 'good' EB and EE light modules. Based on DQM infos
0109 void popcon::EcalChannelStatusHandler::nBadLaserModules(std::map<EcalLogicID, MonLaserBlueDat> dataset_mon) {
0110   // NB: EcalLogicId, sm_num = ecid_xt.getID1() --> for barrel is 1->18 = EB+; 19->36 = EB-
0111   // NB: EcalLogicId, sm_num = ecid_xt.getID1() --> for endcap is 1=Z+, -1=Z- ;
0112 
0113   // good and bad light modules and reference crystals in EB
0114   // theLM=0 -> L-shaped            ( TTs: 1,2,3,4; 7-8; 11-12 ... )
0115   // theLM=1 -> not L-shaped        ( TTs: 5-6,9-10 ... )
0116   for (int theSm = 0; theSm < 36; theSm++) {
0117     for (int theLM = 0; theLM < 2; theLM++) {
0118       isEBRef1[theSm][theLM] = false;
0119       isEBRef2[theSm][theLM] = false;
0120       isGoodLaserEBSm[theSm][theLM] = false;
0121     }
0122   }
0123 
0124   // good and bad light modules and reference crystals in EE [NB: only in EE-5 and EE+5 we need 2 LM... redundant]
0125   // theLM=0 -> light module A (ix<=50)
0126   // theLM=1 -> light module B (ix>50)
0127   for (int theSector = 0; theSector < 18; theSector++) {
0128     for (int theLM = 0; theLM < 2; theLM++) {
0129       isEERef1[theSector][theLM] = false;
0130       isEERef2[theSector][theLM] = false;
0131       isGoodLaserEESm[theSector][theLM] = false;
0132     }
0133   }
0134 
0135   typedef std::map<EcalLogicID, MonLaserBlueDat>::const_iterator CImon;
0136   EcalLogicID ecid_xt;
0137   MonLaserBlueDat rd_blue;
0138 
0139   for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
0140     ecid_xt = p->first;
0141     int sm_num = ecid_xt.getID1();
0142     int xt_num = ecid_xt.getID2();
0143     int yt_num = ecid_xt.getID3();
0144 
0145     // in which Fed/triggerTower/sectorSide I am
0146     int theFed = -100;
0147     int theTT = -100;
0148     int theIx = -100;
0149     if (ecid_xt.getName() == "EB_crystal_number") {
0150       EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0151       EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
0152       theFed = 600 + elecId.dccId();
0153       theTT = elecId.towerId();
0154     }
0155     if (ecid_xt.getName() == "EE_crystal_number") {
0156       if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0157         EEDetId eedetid(xt_num, yt_num, sm_num);
0158         EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
0159         theFed = 600 + elecId.dccId();
0160         theIx = eedetid.ix();
0161       }
0162     }
0163 
0164     // to have numbers from 0 to 17 for the EE feds and 0-36 for EB
0165     //  0 = EE-7;  1 = EE-8;  2 = EE-9;  3 = EE-1;  4 = EE-2;  5 = EE-3;  6 = EE-4;  7 = EE-5;  8 = EE-6;
0166     //  9 = EE+7; 10 = EE+8; 11 = EE+9; 12 = EE+1; 13 = EE+2; 14 = EE+3; 15 = EE+4; 16 = EE+5; 17 = EE+6
0167     //  0 = EB-1 --> 17 = EB-18; 18 = EB+1 --> 35 = EB+18
0168     int thisFed = -100;
0169     if (ecid_xt.getName() == "EE_crystal_number") {
0170       if (theFed > 600 && theFed < 610)
0171         thisFed = theFed - 601;
0172       if (theFed > 645 && theFed < 655)
0173         thisFed = theFed - 646 + 9;
0174     }
0175     if (ecid_xt.getName() == "EB_crystal_number") {
0176       thisFed = theFed - 610;
0177     }
0178 
0179     // in which light module I am
0180     int theTTieta = -100;
0181     int theTTiphi = -100;
0182     int theLM = -100;
0183     if (ecid_xt.getName() == "EB_crystal_number") {
0184       theTTieta = (theTT - 1) / 4 + 1;
0185       theTTiphi = (theTT - 1) % 4 + 1;
0186       if (theTTieta == 1 || theTTiphi == 3 || theTTiphi == 4)
0187         theLM = 0;  // L-shaped
0188       if (theTTieta > 1 && (theTTiphi == 1 || theTTiphi == 2))
0189         theLM = 1;  // not L-shaped
0190     }
0191     if ((ecid_xt.getName() == "EE_crystal_number") && (thisFed == 7 || thisFed == 16)) {
0192       if (theIx <= 50)
0193         theLM = 0;
0194       if (theIx > 50)
0195         theLM = 1;
0196     }
0197 
0198     // taking laser infos
0199     rd_blue = p->second;
0200     float myApdMean = rd_blue.getAPDMean();
0201 
0202     // barrel: is there at least one crystal on in this LM?
0203     if (ecid_xt.getName() == "EB_crystal_number") {
0204       EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0205       if (!isEBRef1[thisFed][theLM] && !isEBRef2[thisFed][theLM] && myApdMean > 100)
0206         isEBRef1[thisFed][theLM] = true;
0207       if (isEBRef1[thisFed][theLM] && !isEBRef2[thisFed][theLM] && myApdMean > 100)
0208         isEBRef2[thisFed][theLM] = true;
0209     }
0210 
0211     // endcap: is there at least one crystal on in this LM?
0212     if (ecid_xt.getName() == "EE_crystal_number") {
0213       EEDetId eedetid(xt_num, yt_num, sm_num);
0214 
0215       // just 1 LM per Fed
0216       if (thisFed != 7 && thisFed != 16) {
0217         if (!isEERef1[thisFed][0] && !isEERef2[thisFed][0] && myApdMean > 100) {
0218           isEERef1[thisFed][0] = true;
0219           isEERef1[thisFed][1] = true;
0220         }
0221         if (isEERef1[thisFed][0] && !isEERef2[thisFed][0] && myApdMean > 100) {
0222           isEERef2[thisFed][0] = true;
0223           isEERef2[thisFed][1] = true;
0224         }
0225       }
0226 
0227       // 2 LMs per Fed
0228       if (thisFed == 7 || thisFed == 16) {
0229         if (!isEERef1[thisFed][theLM] && !isEERef2[thisFed][theLM] && myApdMean > 100)
0230           isEERef1[thisFed][theLM] = true;
0231         if (isEERef1[thisFed][theLM] && !isEERef2[thisFed][theLM] && myApdMean > 100)
0232           isEERef2[thisFed][theLM] = true;
0233       }
0234     }
0235   }
0236 
0237   // check if the light module is on: at least two crystals must be on
0238   for (int theSm = 0; theSm < 36; theSm++) {
0239     for (int theLM = 0; theLM < 2; theLM++) {
0240       if (isEBRef1[theSm][theLM] && isEBRef2[theSm][theLM])
0241         isGoodLaserEBSm[theSm][theLM] = true;
0242       // std::cout << "Barrel: SM " << theSm << ", LM " << theLM << ": good = " << isGoodLaserEBSm[theSm][theLM] << std::endl;
0243     }
0244   }
0245 
0246   for (int theSector = 0; theSector < 18; theSector++) {
0247     for (int theLM = 0; theLM < 2; theLM++) {
0248       if (isEERef1[theSector][theLM] && isEERef2[theSector][theLM])
0249         isGoodLaserEESm[theSector][theLM] = true;
0250       // std::cout << "Endcap: SM " << theSector << ", LM " << theLM << ": good = " << isGoodLaserEESm[theSector][theLM] << std::endl;
0251     }
0252   }
0253 }
0254 
0255 // ----------------------------------------------------------
0256 // START MASKING ROUTINES
0257 void popcon::EcalChannelStatusHandler::pedOnlineMasking() {
0258   uint64_t bits03 = 0;
0259   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_MEAN_WARNING");
0260   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_RMS_WARNING");
0261   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR");
0262   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR");
0263 
0264   std::map<EcalLogicID, RunCrystalErrorsDat> theMask;
0265   ecalErrorMask_.fetchDataSet(&theMask);
0266 
0267   if (!theMask.empty()) {
0268     std::map<EcalLogicID, RunCrystalErrorsDat>::const_iterator m;
0269     for (m = theMask.begin(); m != theMask.end(); m++) {
0270       EcalLogicID ecid_xt = m->first;
0271       int sm_num = ecid_xt.getID1();
0272       int xt_num = ecid_xt.getID2();
0273       int yt_num = ecid_xt.getID3();
0274 
0275       if ((m->second).getErrorBits() & bits03) {
0276         if (ecid_xt.getName() == "EB_crystal_number") {
0277           EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0278           maskedOnlinePedEB.insert(std::pair<DetId, float>(ebdetid, 9999.));
0279         } else {
0280           if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0281             EEDetId eedetid(xt_num, yt_num, sm_num);
0282             maskedOnlinePedEE.insert(std::pair<DetId, float>(eedetid, 9999.));
0283           }
0284         }
0285       }
0286     }
0287   }
0288 }
0289 
0290 void popcon::EcalChannelStatusHandler::pedMasking() {
0291   uint64_t bits03 = 0;
0292   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_LOW_GAIN_MEAN_WARNING");
0293   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_MIDDLE_GAIN_MEAN_WARNING");
0294   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_HIGH_GAIN_MEAN_WARNING");
0295   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_LOW_GAIN_MEAN_ERROR");
0296   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_MIDDLE_GAIN_MEAN_ERROR");
0297   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_HIGH_GAIN_MEAN_ERROR");
0298   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_LOW_GAIN_RMS_WARNING");
0299   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_MIDDLE_GAIN_RMS_WARNING");
0300   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_HIGH_GAIN_RMS_WARNING");
0301   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_LOW_GAIN_RMS_ERROR");
0302   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_MIDDLE_GAIN_RMS_ERROR");
0303   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_HIGH_GAIN_RMS_ERROR");
0304 
0305   std::map<EcalLogicID, RunCrystalErrorsDat> theMask;
0306   ecalErrorMask_.fetchDataSet(&theMask);
0307 
0308   if (!theMask.empty()) {
0309     std::map<EcalLogicID, RunCrystalErrorsDat>::const_iterator m;
0310     for (m = theMask.begin(); m != theMask.end(); m++) {
0311       EcalLogicID ecid_xt = m->first;
0312       int sm_num = ecid_xt.getID1();
0313       int xt_num = ecid_xt.getID2();
0314       int yt_num = ecid_xt.getID3();
0315 
0316       if ((m->second).getErrorBits() & bits03) {
0317         if (ecid_xt.getName() == "EB_crystal_number") {
0318           EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0319           maskedPedEB.insert(std::pair<DetId, float>(ebdetid, 9999.));
0320         } else {
0321           if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0322             EEDetId eedetid(xt_num, yt_num, sm_num);
0323             maskedPedEE.insert(std::pair<DetId, float>(eedetid, 9999.));
0324           }
0325         }
0326       }
0327     }
0328   }
0329 }
0330 
0331 void popcon::EcalChannelStatusHandler::laserMasking() {
0332   uint64_t bits03 = 0;
0333   bits03 |= EcalErrorDictionary::getMask("LASER_MEAN_WARNING");
0334   bits03 |= EcalErrorDictionary::getMask("LASER_RMS_WARNING");
0335   bits03 |= EcalErrorDictionary::getMask("LASER_MEAN_OVER_PN_WARNING");
0336   bits03 |= EcalErrorDictionary::getMask("LASER_RMS_OVER_PN_WARNING");
0337   bits03 |= EcalErrorDictionary::getMask("LASER_MEAN_TIMING_WARNING");
0338   bits03 |= EcalErrorDictionary::getMask("LASER_RMS_TIMING_WARNING");
0339 
0340   std::map<EcalLogicID, RunCrystalErrorsDat> theMask;
0341   ecalErrorMask_.fetchDataSet(&theMask);
0342 
0343   if (!theMask.empty()) {
0344     std::map<EcalLogicID, RunCrystalErrorsDat>::const_iterator m;
0345     for (m = theMask.begin(); m != theMask.end(); m++) {
0346       EcalLogicID ecid_xt = m->first;
0347       int sm_num = ecid_xt.getID1();
0348       int xt_num = ecid_xt.getID2();
0349       int yt_num = ecid_xt.getID3();
0350 
0351       if ((m->second).getErrorBits() & bits03) {
0352         if (ecid_xt.getName() == "EB_crystal_number") {
0353           EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0354           maskedLaserEB.insert(std::pair<DetId, float>(ebdetid, 9999.));
0355         } else {
0356           if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0357             EEDetId eedetid(xt_num, yt_num, sm_num);
0358             maskedLaserEE.insert(std::pair<DetId, float>(eedetid, 9999.));
0359           }
0360         }
0361       }
0362     }
0363   }
0364 }
0365 
0366 void popcon::EcalChannelStatusHandler::physicsMasking() {
0367   uint64_t bits03 = 0;
0368   bits03 |= EcalErrorDictionary::getMask("PHYSICS_BAD_CHANNEL_WARNING");
0369   bits03 |= EcalErrorDictionary::getMask("PHYSICS_BAD_CHANNEL_ERROR");
0370 
0371   std::map<EcalLogicID, RunCrystalErrorsDat> theMask;
0372   ecalErrorMask_.fetchDataSet(&theMask);
0373 
0374   if (!theMask.empty()) {
0375     std::map<EcalLogicID, RunCrystalErrorsDat>::const_iterator m;
0376     for (m = theMask.begin(); m != theMask.end(); m++) {
0377       EcalLogicID ecid_xt = m->first;
0378       int sm_num = ecid_xt.getID1();
0379       int xt_num = ecid_xt.getID2();
0380       int yt_num = ecid_xt.getID3();
0381 
0382       if ((m->second).getErrorBits() & bits03) {
0383         if (ecid_xt.getName() == "EB_crystal_number") {
0384           EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0385           maskedPhysicsEB.insert(std::pair<DetId, float>(ebdetid, 9999.));
0386         } else {
0387           if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0388             EEDetId eedetid(xt_num, yt_num, sm_num);
0389             maskedPhysicsEE.insert(std::pair<DetId, float>(eedetid, 9999.));
0390           }
0391         }
0392       }
0393     }
0394   }
0395 }
0396 
0397 // ----------------------------------------------------------
0398 // START DAQ EXCLUDED FEDs ROUTINES
0399 void popcon::EcalChannelStatusHandler::daqOut(const RunIOV& _myRun) {
0400   RunIOV myRun = _myRun;
0401   std::map<EcalLogicID, RunFEConfigDat> feconfig;
0402   econn->fetchDataSet(&feconfig, &myRun);
0403 
0404   typedef std::map<EcalLogicID, RunFEConfigDat>::const_iterator feConfIter;
0405   EcalLogicID ecid_xt;
0406   RunFEConfigDat rd_fe;
0407 
0408   int fe_conf_id = 0;
0409   for (feConfIter p = feconfig.begin(); p != feconfig.end(); p++) {
0410     ecid_xt = p->first;
0411     rd_fe = p->second;
0412     fe_conf_id = rd_fe.getConfigId();
0413   }
0414 
0415   // reading this configuration
0416   ODFEDAQConfig myconfig;
0417   myconfig.setId(fe_conf_id);
0418   econn->fetchConfigSet(&myconfig);
0419 
0420   // list of bad channels
0421   int myTT = myconfig.getBadTTId();
0422   ODBadTTInfo mybadTT;
0423   mybadTT.setId(myTT);
0424   econn->fetchConfigSet(&mybadTT);
0425 
0426   std::vector<ODBadTTDat> badTT_dat;
0427   econn->fetchConfigDataSet(&badTT_dat, &mybadTT);
0428 
0429   for (size_t iTT = 0; iTT < badTT_dat.size(); iTT++) {
0430     int fed_id = badTT_dat[iTT].getFedId();
0431     int tt_id = badTT_dat[iTT].getTTId();
0432     if (tt_id < 69)
0433       *daqFile << fed_id << " " << tt_id << std::endl;
0434 
0435     // taking the channel list for towers out of daq
0436     if ((fed_id <= 609 || fed_id >= 646) && tt_id < 69) {  // endcap
0437 
0438       // moving from cms fed to db fed convention
0439       //int db_fedId = -999;
0440       //if (fed_id>=604 && fed_id<=609) db_fedId = fed_id - 603 + 9;
0441       //if (fed_id>=601 && fed_id<=603) db_fedId = fed_id - 600 + 15;
0442       //if (fed_id>=649 && fed_id<=654) db_fedId = fed_id - 648;
0443       //if (fed_id>=646 && fed_id<=648) db_fedId = fed_id - 645 + 6;
0444       // db_fedId = fed_id;    // fixme: do we need 1-18 or 6XX?
0445 
0446       std::vector<EcalLogicID> badCrystals;
0447       badCrystals = econn->getEcalLogicIDSet("EE_readout_tower",
0448                                              fed_id,
0449                                              fed_id,
0450                                              tt_id,
0451                                              tt_id,
0452                                              EcalLogicID::NULLID,
0453                                              EcalLogicID::NULLID,
0454                                              "EE_crystal_number");
0455 
0456       for (size_t mycrys = 0; mycrys < badCrystals.size(); mycrys++) {
0457         EcalLogicID ecid_xt = badCrystals[mycrys];
0458         int zSide = 999;
0459         int log_id = ecid_xt.getLogicID();
0460         int yt2 = log_id % 1000;              //  EE_crystal_number:   2010100060 -> z=-1, x=100, y=60
0461         int xt2 = (log_id % 1000000) / 1000;  //  EE_crystal_number:   2012020085 -> z=+1, x=20,  y=85
0462         int zt2 = (log_id / 1000000) % 10;
0463         if (zt2 == 0)
0464           zSide = -1;
0465         if (zt2 == 2)
0466           zSide = 1;
0467         *daqFile2 << xt2 << " " << yt2 << " " << zSide << std::endl;
0468       }
0469     }
0470 
0471     if (fed_id >= 610 && fed_id <= 645 && tt_id < 69) {  // barrel
0472 
0473       // moving from cms fed to db fed convention
0474       int db_fedId = -999;
0475       if (fed_id >= 610 && fed_id <= 627)
0476         db_fedId = fed_id - 609 + 18;
0477       if (fed_id >= 628 && fed_id <= 645)
0478         db_fedId = fed_id - 627;
0479 
0480       std::vector<EcalLogicID> badCrystals;
0481       badCrystals = econn->getEcalLogicIDSet("EB_trigger_tower",
0482                                              db_fedId,
0483                                              db_fedId,
0484                                              tt_id,
0485                                              tt_id,
0486                                              EcalLogicID::NULLID,
0487                                              EcalLogicID::NULLID,
0488                                              "EB_crystal_number");
0489 
0490       for (size_t mycrys = 0; mycrys < badCrystals.size(); mycrys++) {
0491         EcalLogicID ecid_xt = badCrystals[mycrys];
0492         int sm_num = ecid_xt.getID1();
0493         int log_id = ecid_xt.getLogicID();
0494         int xt2_num = log_id % 10000;
0495         EBDetId ebdetid(sm_num, xt2_num, EBDetId::SMCRYSTALMODE);
0496         *daqFile2 << ebdetid.hashedIndex() << std::endl;
0497       }
0498     }
0499   }
0500 }
0501 
0502 // ----------------------------------------------------------
0503 //
0504 // ANALYSIS
0505 //
0506 // ----------------------------------------------------------
0507 
0508 // ----------------------------------------------------------
0509 // LOCAL pedestal runs
0510 
0511 void popcon::EcalChannelStatusHandler::pedAnalysis(std::map<EcalLogicID, MonPedestalsDat> dataset_mon,
0512                                                    std::map<EcalLogicID, MonCrystalConsistencyDat> wrongGain_mon) {
0513   // to take the list of masked crystals
0514   pedMasking();
0515 
0516   // to iterate
0517   std::map<DetId, float>::const_iterator theIter;
0518 
0519   // logic id
0520   EcalLogicID ecid_xt;
0521 
0522   // to check all problems except gain zero
0523   typedef std::map<EcalLogicID, MonPedestalsDat>::const_iterator CImon;
0524   MonPedestalsDat rd_ped;
0525 
0526   for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
0527     uint16_t status_now = 0;
0528     ecid_xt = p->first;
0529     rd_ped = p->second;
0530     int sm_num = ecid_xt.getID1();
0531     int xt_num = ecid_xt.getID2();
0532     int yt_num = ecid_xt.getID3();
0533 
0534     EcalPedestals::Item ped_item;
0535     ped_item.mean_x1 = rd_ped.getPedMeanG1();
0536     ped_item.mean_x6 = rd_ped.getPedMeanG6();
0537     ped_item.mean_x12 = rd_ped.getPedMeanG12();
0538     ped_item.rms_x1 = rd_ped.getPedRMSG1();
0539     ped_item.rms_x6 = rd_ped.getPedRMSG6();
0540     ped_item.rms_x12 = rd_ped.getPedRMSG12();
0541 
0542     // check if pedestal RMS is bad at least at 1 gain -> noisy or very noisy channel
0543     float lowerCut = 999.;
0544     if (ecid_xt.getName() == "EB_crystal_number") {
0545       lowerCut = 2.0;
0546     }
0547     if (ecid_xt.getName() == "EE_crystal_number") {
0548       lowerCut = 2.5;
0549     }
0550     if ((checkPedestalRMSGain12(&ped_item) > lowerCut) || (checkPedestalRMSGain6(&ped_item) > lowerCut) ||
0551         (checkPedestalRMSGain1(&ped_item) > lowerCut))
0552       status_now = 3;
0553 
0554     // check if pedestal value is bad at least at 1 gain -> problem in dac settings
0555     if ((checkPedestalValueGain12(&ped_item) > 300 || checkPedestalValueGain12(&ped_item) < 100) ||
0556         (checkPedestalValueGain6(&ped_item) > 300 || checkPedestalValueGain6(&ped_item) < 100) ||
0557         (checkPedestalValueGain1(&ped_item) > 300 || checkPedestalValueGain1(&ped_item) < 100))
0558       status_now = 1;
0559 
0560     // check if pedestal rms is zero at least at 1 gain -> dead at that channel
0561     if (checkPedestalRMSGain12(&ped_item) == 0 || checkPedestalRMSGain6(&ped_item) == 0 ||
0562         checkPedestalRMSGain1(&ped_item) == 0)
0563       status_now = 11;
0564 
0565     // check if the channel is fixed at G1
0566     if (checkPedestalValueGain12(&ped_item) < 0 && checkPedestalValueGain6(&ped_item) < 0 &&
0567         checkPedestalValueGain1(&ped_item) > 0)
0568       status_now = 9;
0569 
0570     // check if the channel is fixed at G6
0571     if (checkPedestalValueGain12(&ped_item) < 0 && checkPedestalValueGain6(&ped_item) > 0 &&
0572         checkPedestalValueGain1(&ped_item) < 0)
0573       status_now = 8;
0574 
0575     // check if the channel is not working at G12
0576     if (checkPedestalValueGain12(&ped_item) < 0 && checkPedestalValueGain6(&ped_item) > 0 &&
0577         checkPedestalValueGain1(&ped_item) > 0)
0578       status_now = 8;
0579 
0580     // output in case of problems:
0581     if (status_now > 0) {
0582       if (ecid_xt.getName() == "EB_crystal_number") {
0583         EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0584         EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
0585         int thisFed = 600 + elecId.dccId();
0586 
0587         *ResFileEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t"
0588                    << ped_item.mean_x12 << "\t\t" << ped_item.rms_x12 << "\t\t" << ped_item.mean_x6 << "\t\t"
0589                    << ped_item.rms_x6 << "\t\t" << ped_item.mean_x1 << "\t\t" << ped_item.rms_x1 << std::endl;
0590 
0591         // file with new problems only
0592         bool isOld = false;
0593         for (theIter = maskedPedEB.begin(); theIter != maskedPedEB.end(); ++theIter) {
0594           if ((*theIter).first == ebdetid)
0595             isOld = true;
0596         }
0597         if (!isOld) {
0598           *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t"
0599                         << ped_item.mean_x12 << "\t\t" << ped_item.rms_x12 << "\t\t" << ped_item.mean_x6 << "\t\t"
0600                         << ped_item.rms_x6 << "\t\t" << ped_item.mean_x1 << "\t\t" << ped_item.rms_x1 << std::endl;
0601         }
0602 
0603       } else {
0604         if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0605           EEDetId eedetid(xt_num, yt_num, sm_num);
0606           EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
0607           int thisFed = 600 + elecId.dccId();
0608           *ResFileEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
0609                      << "\t\t" << eedetid.hashedIndex() << "\t\t" << ped_item.mean_x12 << "\t\t" << ped_item.rms_x12
0610                      << "\t\t" << ped_item.mean_x6 << "\t\t" << ped_item.rms_x6 << "\t\t" << ped_item.mean_x1 << "\t\t"
0611                      << ped_item.rms_x1 << std::endl;
0612 
0613           bool isOld = false;
0614           for (theIter = maskedPedEE.begin(); theIter != maskedPedEE.end(); ++theIter) {
0615             if ((*theIter).first == eedetid)
0616               isOld = true;
0617           }
0618           if (!isOld) {
0619             *ResFileNewEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
0620                           << "\t\t" << eedetid.hashedIndex() << "\t\t" << ped_item.mean_x12 << "\t\t"
0621                           << ped_item.rms_x12 << "\t\t" << ped_item.mean_x6 << "\t\t" << ped_item.rms_x6 << "\t\t"
0622                           << ped_item.mean_x1 << "\t\t" << ped_item.rms_x1 << std::endl;
0623           }
0624         }
0625       }
0626     }
0627   }
0628 
0629   // to check if a crystal is at gain zero in at least 1000 events (which is not the best! fixme)
0630   typedef std::map<EcalLogicID, MonCrystalConsistencyDat>::const_iterator WGmonIter;
0631   MonCrystalConsistencyDat rd_wgain;
0632 
0633   for (WGmonIter p = wrongGain_mon.begin(); p != wrongGain_mon.end(); p++) {
0634     ecid_xt = p->first;
0635     rd_wgain = p->second;
0636     int sm_num = ecid_xt.getID1();
0637     int xt_num = ecid_xt.getID2();
0638     int yt_num = ecid_xt.getID3();
0639 
0640     // output if problematic
0641     if (rd_wgain.getProblemsGainZero() > 1000) {
0642       if (ecid_xt.getName() == "EB_crystal_number") {
0643         EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0644         EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
0645         int thisFed = 600 + elecId.dccId();
0646         *ResFileEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t"
0647                    << "at gain zero" << std::endl;
0648 
0649         // file with new problems only
0650         bool isOld = false;
0651         for (theIter = maskedPedEB.begin(); theIter != maskedPedEB.end(); ++theIter) {
0652           if ((*theIter).first == ebdetid)
0653             isOld = true;
0654         }
0655         if (!isOld) {
0656           *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t"
0657                         << "at gain zero" << std::endl;
0658         }
0659 
0660       } else {
0661         if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0662           EEDetId eedetid(xt_num, yt_num, sm_num);
0663           EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
0664           int thisFed = 600 + elecId.dccId();
0665           *ResFileEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
0666                      << "\t\t" << eedetid.hashedIndex() << "\t\t"
0667                      << "at gain zero" << std::endl;
0668 
0669           bool isOld = false;
0670           for (theIter = maskedPedEE.begin(); theIter != maskedPedEE.end(); ++theIter) {
0671             if ((*theIter).first == eedetid)
0672               isOld = true;
0673           }
0674           if (!isOld) {
0675             *ResFileNewEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
0676                           << "\t\t" << eedetid.hashedIndex() << "\t\t"
0677                           << "at gain zero" << std::endl;
0678           }
0679         }
0680       }
0681     }
0682   }
0683 }
0684 
0685 // ------------------------------------------------------------
0686 //
0687 // LOCAL laser runs
0688 
0689 void popcon::EcalChannelStatusHandler::laserAnalysis(std::map<EcalLogicID, MonLaserBlueDat> dataset_mon) {
0690   // to take the list of masked crystals
0691   laserMasking();
0692 
0693   // to iterate
0694   std::map<DetId, float>::const_iterator theIter;
0695 
0696   typedef std::map<EcalLogicID, MonLaserBlueDat>::const_iterator CImon;
0697   EcalLogicID ecid_xt;
0698   MonLaserBlueDat rd_blue;
0699 
0700   for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
0701     ecid_xt = p->first;
0702     int sm_num = ecid_xt.getID1();
0703     int xt_num = ecid_xt.getID2();
0704     int yt_num = ecid_xt.getID3();
0705 
0706     // in which Fed/triggerTower/sectorSide I am
0707     int theFed = -100;
0708     int theTT = -100;
0709     int theIx = -100;
0710     if (ecid_xt.getName() == "EB_crystal_number") {
0711       EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0712       EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
0713       theFed = 600 + elecId.dccId();
0714       theTT = elecId.towerId();
0715     }
0716     if (ecid_xt.getName() == "EE_crystal_number") {
0717       if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0718         EEDetId eedetid(xt_num, yt_num, sm_num);
0719         EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
0720         theFed = 600 + elecId.dccId();
0721         theIx = eedetid.ix();
0722       }
0723     }
0724 
0725     // to have numbers from 0 to 17 for the EE feds and 0-36 for EB
0726     int thisFed = -100;
0727     if (ecid_xt.getName() == "EE_crystal_number") {
0728       if (theFed > 600 && theFed < 610)
0729         thisFed = theFed - 601;
0730       if (theFed > 645 && theFed < 655)
0731         thisFed = theFed - 646 + 9;
0732     }
0733     if (ecid_xt.getName() == "EB_crystal_number") {
0734       thisFed = theFed - 610;
0735     }
0736 
0737     // in which light module I am
0738     int theTTieta = -100;
0739     int theTTiphi = -100;
0740     int theLM = -100;
0741     if (ecid_xt.getName() == "EB_crystal_number") {
0742       theTTieta = (theTT - 1) / 4 + 1;
0743       theTTiphi = (theTT - 1) % 4 + 1;
0744       if (theTTieta == 1 || theTTiphi == 3 || theTTiphi == 4)
0745         theLM = 0;  // L-shaped
0746       if (theTTieta > 1 && (theTTiphi == 1 || theTTiphi == 2))
0747         theLM = 1;  // not L-shaped
0748     }
0749     if ((ecid_xt.getName() == "EE_crystal_number") && (thisFed == 7 || thisFed == 16)) {
0750       if (theIx <= 50)
0751         theLM = 0;
0752       if (theIx > 50)
0753         theLM = 1;
0754     }
0755 
0756     // check if APD mean is bad
0757     uint16_t status_now = 0;
0758     rd_blue = p->second;
0759     float myApdMean = rd_blue.getAPDMean();
0760 
0761     if (ecid_xt.getName() == "EB_crystal_number") {
0762       if ((myApdMean < 400) && isGoodLaserEBSm[thisFed][theLM])
0763         status_now = 2;
0764     }
0765 
0766     if (ecid_xt.getName() == "EE_crystal_number") {
0767       if (myApdMean < 100) {
0768         if (thisFed != 7 && thisFed != 16 && isGoodLaserEESm[thisFed][0])
0769           status_now = 2;
0770         if ((thisFed == 7 || thisFed == 16) && isGoodLaserEESm[thisFed][theLM])
0771           status_now = 2;
0772       }
0773     }
0774 
0775     // output if problematic
0776     if (status_now > 0) {
0777       if (ecid_xt.getName() == "EB_crystal_number") {
0778         EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0779         *ResFileEB << theFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << myApdMean
0780                    << std::endl;
0781 
0782         // file with new problems only
0783         bool isOld = false;
0784         for (theIter = maskedLaserEB.begin(); theIter != maskedLaserEB.end(); ++theIter) {
0785           if ((*theIter).first == ebdetid)
0786             isOld = true;
0787         }
0788         if (!isOld) {
0789           *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << myApdMean
0790                         << std::endl;
0791         }
0792 
0793       } else {
0794         if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0795           EEDetId eedetid(xt_num, yt_num, sm_num);
0796           *ResFileEE << theFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
0797                      << "\t\t" << eedetid.hashedIndex() << "\t\t" << myApdMean << std::endl;
0798 
0799           // file with new problems only
0800           bool isOld = false;
0801           for (theIter = maskedLaserEE.begin(); theIter != maskedLaserEE.end(); ++theIter) {
0802             if ((*theIter).first == eedetid)
0803               isOld = true;
0804           }
0805           if (!isOld) {
0806             *ResFileEE << theFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
0807                        << "\t\t" << eedetid.hashedIndex() << "\t\t" << myApdMean << std::endl;
0808           }
0809         }
0810       }
0811     }
0812   }
0813 }
0814 
0815 // ------------------------------------------------------------
0816 //
0817 // COSMICS/PHYSICS ANALYSIS: infos from pedestal online, laser and occupancy analysis
0818 
0819 void popcon::EcalChannelStatusHandler::cosmicsAnalysis(std::map<EcalLogicID, MonPedestalsOnlineDat> pedestalO_mon,
0820                                                        std::map<EcalLogicID, MonCrystalConsistencyDat> wrongGain_mon,
0821                                                        std::map<EcalLogicID, MonLaserBlueDat> laser_mon,
0822                                                        std::map<EcalLogicID, MonOccupancyDat> occupancy_mon) {
0823   // to take the list of masked crystals for the diffrent analyses
0824   pedOnlineMasking();
0825   laserMasking();
0826   physicsMasking();
0827 
0828   std::map<DetId, float>::const_iterator theIter;
0829   std::map<DetId, float> badPedOnEB, badPedOnEE;
0830   std::map<DetId, float> badPedOnRmsEB, badPedOnRmsEE;
0831   std::map<DetId, float> badGainEB, badGainEE;
0832   std::map<DetId, float> badLaserEB, badLaserEE;
0833   std::map<DetId, float> badOccHighEB, badOccHighEE;
0834 
0835   typedef std::map<EcalLogicID, MonPedestalsOnlineDat>::const_iterator CImonPedO;
0836   typedef std::map<EcalLogicID, MonCrystalConsistencyDat>::const_iterator CImonCons;
0837   typedef std::map<EcalLogicID, MonOccupancyDat>::const_iterator CImonOcc;
0838   typedef std::map<EcalLogicID, MonLaserBlueDat>::const_iterator CImonLaser;
0839   MonPedestalsOnlineDat rd_ped0;
0840   MonCrystalConsistencyDat rd_wgain;
0841   MonOccupancyDat rd_occ;
0842   MonLaserBlueDat rd_blue;
0843 
0844   // logic id
0845   EcalLogicID ecid_xt;
0846 
0847   // to be used after: total number of entries above high threshold
0848   float totEntriesAboveHighThrEB = 0.;
0849   float totEntriesAboveHighThrEE = 0.;
0850   for (CImonOcc p = occupancy_mon.begin(); p != occupancy_mon.end(); p++) {
0851     ecid_xt = p->first;
0852     rd_occ = p->second;
0853     float highOcc = rd_occ.getEventsOverHighThreshold();
0854     if (ecid_xt.getName() == "EB_crystal_number" && highOcc > -1)
0855       totEntriesAboveHighThrEB = totEntriesAboveHighThrEB + highOcc;
0856     if (ecid_xt.getName() == "EE_crystal_number" && highOcc > -1)
0857       totEntriesAboveHighThrEE = totEntriesAboveHighThrEE + highOcc;
0858   }
0859 
0860   // A) creating the list of all bad channels: searching for problems based on pedestal online except gain zero
0861   for (CImonPedO p = pedestalO_mon.begin(); p != pedestalO_mon.end(); p++) {
0862     bool isWrong = false;
0863     ecid_xt = p->first;
0864     rd_ped0 = p->second;
0865     int sm_num = ecid_xt.getID1();
0866     int xt_num = ecid_xt.getID2();
0867     int yt_num = ecid_xt.getID3();
0868 
0869     EcalPedestals::Item ped_item;
0870     ped_item.mean_x12 = rd_ped0.getADCMeanG12();
0871     ped_item.rms_x12 = rd_ped0.getADCRMSG12();
0872 
0873     float lowerCut = 999.;
0874     if (ecid_xt.getName() == "EB_crystal_number") {
0875       lowerCut = 2.0;
0876     }
0877     if (ecid_xt.getName() == "EE_crystal_number") {
0878       lowerCut = 2.5;
0879     }
0880     if (checkPedestalRMSGain12(&ped_item) > lowerCut)
0881       isWrong = true;
0882     if (checkPedestalValueGain12(&ped_item) > 300)
0883       isWrong = true;
0884     if (checkPedestalValueGain12(&ped_item) < 100)
0885       isWrong = true;
0886     if (checkPedestalRMSGain12(&ped_item) == 0)
0887       isWrong = true;
0888 
0889     // is this channel already in the list?
0890     if (isWrong) {
0891       if (ecid_xt.getName() == "EB_crystal_number") {
0892         EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0893         theIter = badPedOnEB.find(ebdetid);
0894         if (theIter == badPedOnEB.end()) {
0895           badPedOnEB.insert(std::pair<DetId, float>(ebdetid, rd_ped0.getADCMeanG12()));
0896           badPedOnRmsEB.insert(std::pair<DetId, float>(ebdetid, rd_ped0.getADCRMSG12()));
0897         }
0898       } else {
0899         if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0900           EEDetId eedetid(xt_num, yt_num, sm_num);
0901           theIter = badPedOnEE.find(eedetid);
0902           if (theIter == badPedOnEE.end()) {
0903             badPedOnEE.insert(std::pair<DetId, float>(eedetid, rd_ped0.getADCMeanG12()));
0904             badPedOnRmsEE.insert(std::pair<DetId, float>(eedetid, rd_ped0.getADCRMSG12()));
0905           }
0906         }
0907       }
0908     }
0909   }
0910 
0911   // B) creating the list of all bad channels: searching for channels at gain zero at least in 100 events
0912   for (CImonCons p = wrongGain_mon.begin(); p != wrongGain_mon.end(); p++) {
0913     bool isWrong = false;
0914     ecid_xt = p->first;
0915     rd_wgain = p->second;
0916     int sm_num = ecid_xt.getID1();
0917     int xt_num = ecid_xt.getID2();
0918     int yt_num = ecid_xt.getID3();
0919 
0920     if (rd_wgain.getProblemsGainZero() > 1000) {
0921       isWrong = true;
0922     }
0923 
0924     if (isWrong) {
0925       if (ecid_xt.getName() == "EB_crystal_number") {
0926         EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0927         theIter = badGainEB.find(ebdetid);
0928         if (theIter == badGainEB.end())
0929           badGainEB.insert(std::pair<DetId, float>(ebdetid, 999.));
0930       } else {
0931         if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0932           EEDetId eedetid(xt_num, yt_num, sm_num);
0933           theIter = badGainEE.find(eedetid);
0934           if (theIter == badGainEE.end())
0935             badGainEE.insert(std::pair<DetId, float>(eedetid, 999.));
0936         }
0937       }
0938     }
0939   }
0940 
0941   // C) creating the list of all bad channels: searching for channels with bad occupancy [ too high ]
0942   for (CImonOcc p = occupancy_mon.begin(); p != occupancy_mon.end(); p++) {
0943     // logic id
0944     ecid_xt = p->first;
0945     int sm_num = ecid_xt.getID1();
0946     int xt_num = ecid_xt.getID2();
0947     int yt_num = ecid_xt.getID3();
0948 
0949     // occupancy
0950     rd_occ = p->second;
0951 
0952     bool isWrong = false;
0953     float occAvg = -999.;
0954     if (ecid_xt.getName() == "EB_crystal_number") {
0955       occAvg = rd_occ.getEventsOverHighThreshold() / totEntriesAboveHighThrEB;
0956       if (occAvg > 0.001)
0957         isWrong = true;
0958     }
0959     if (ecid_xt.getName() == "EE_crystal_number") {
0960       occAvg = rd_occ.getEventsOverHighThreshold() / totEntriesAboveHighThrEE;
0961       if (occAvg > 0.001)
0962         isWrong = true;
0963     }
0964 
0965     if (isWrong) {
0966       if (ecid_xt.getName() == "EB_crystal_number") {
0967         EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0968         theIter = badOccHighEB.find(ebdetid);
0969         if (theIter == badOccHighEB.end())
0970           badOccHighEB.insert(std::pair<DetId, float>(ebdetid, occAvg));
0971       } else {
0972         if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
0973           EEDetId eedetid(xt_num, yt_num, sm_num);
0974           theIter = badOccHighEE.find(eedetid);
0975           if (theIter == badOccHighEE.end())
0976             badOccHighEE.insert(std::pair<DetId, float>(eedetid, occAvg));
0977         }
0978       }
0979     }
0980   }
0981 
0982   // D) creating the list of all bad channels: searching for channels with bad laser amplitude [among those covered by the calibration sequence]
0983   for (CImonLaser p = laser_mon.begin(); p != laser_mon.end(); p++) {
0984     // logic id
0985     ecid_xt = p->first;
0986     int sm_num = ecid_xt.getID1();
0987     int xt_num = ecid_xt.getID2();
0988     int yt_num = ecid_xt.getID3();
0989 
0990     // in which Fed/triggerTower/sectorSide I am
0991     int theFed = -100;
0992     int theTT = -100;
0993     int theIx = -100;
0994     if (ecid_xt.getName() == "EB_crystal_number") {
0995       EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
0996       EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
0997       theFed = 600 + elecId.dccId();
0998       theTT = elecId.towerId();
0999     }
1000     if (ecid_xt.getName() == "EE_crystal_number") {
1001       if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
1002         EEDetId eedetid(xt_num, yt_num, sm_num);
1003         EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
1004         theFed = 600 + elecId.dccId();
1005         theIx = eedetid.ix();
1006       }
1007     }
1008 
1009     // to have numbers from 0 to 17 for the EE feds and 0-36 for EB
1010     int thisFed = -100;
1011     if (ecid_xt.getName() == "EE_crystal_number") {
1012       if (theFed > 600 && theFed < 610)
1013         thisFed = theFed - 601;
1014       if (theFed > 645 && theFed < 655)
1015         thisFed = theFed - 646 + 9;
1016     }
1017     if (ecid_xt.getName() == "EB_crystal_number") {
1018       thisFed = theFed - 610;
1019     }
1020 
1021     // in which light module I am
1022     int theTTieta = -100;
1023     int theTTiphi = -100;
1024     int theLM = -100;
1025     if (ecid_xt.getName() == "EB_crystal_number") {
1026       theTTieta = (theTT - 1) / 4 + 1;
1027       theTTiphi = (theTT - 1) % 4 + 1;
1028       if (theTTieta == 1 || theTTiphi == 3 || theTTiphi == 4)
1029         theLM = 0;  // L-shaped
1030       if (theTTieta > 1 && (theTTiphi == 1 || theTTiphi == 2))
1031         theLM = 1;  // not L-shaped
1032     }
1033     if ((ecid_xt.getName() == "EE_crystal_number") && (thisFed == 7 || thisFed == 16)) {
1034       if (theIx <= 50)
1035         theLM = 0;
1036       if (theIx > 50)
1037         theLM = 1;
1038     }
1039 
1040     // APD mean value
1041     rd_blue = p->second;
1042     float myApdMean = rd_blue.getAPDMean();
1043 
1044     bool isWrong = false;
1045     if (ecid_xt.getName() == "EB_crystal_number") {
1046       if ((myApdMean < 400) && isGoodLaserEBSm[thisFed][theLM])
1047         isWrong = true;
1048     }
1049     if (ecid_xt.getName() == "EE_crystal_number") {
1050       if (myApdMean < 100) {
1051         if (thisFed != 7 && thisFed != 16 && isGoodLaserEESm[thisFed][0])
1052           isWrong = true;
1053         if ((thisFed == 7 || thisFed == 16) && isGoodLaserEESm[thisFed][theLM])
1054           isWrong = true;
1055       }
1056     }
1057 
1058     if (isWrong) {
1059       if (ecid_xt.getName() == "EB_crystal_number") {
1060         EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
1061         theIter = badLaserEB.find(ebdetid);
1062         if (theIter == badLaserEB.end())
1063           badLaserEB.insert(std::pair<DetId, float>(ebdetid, myApdMean));
1064       } else {
1065         if (EEDetId::validDetId(xt_num, yt_num, sm_num)) {
1066           EEDetId eedetid(xt_num, yt_num, sm_num);
1067           theIter = badLaserEE.find(eedetid);
1068           if (theIter == badLaserEE.end())
1069             badLaserEE.insert(std::pair<DetId, float>(eedetid, myApdMean));
1070         }
1071       }
1072     }
1073   }
1074 
1075   // check if the crystal is in the vector and fill the summary file
1076   std::map<DetId, float>::const_iterator theIterPedOn;
1077   std::map<DetId, float>::const_iterator theIterPedOnRms;
1078   std::map<DetId, float>::const_iterator theIterGain;
1079   std::map<DetId, float>::const_iterator theIterLaser;
1080   std::map<DetId, float>::const_iterator theIterOccHigh;
1081 
1082   // EB, first check - loop over pedestal online
1083   for (theIterPedOn = badPedOnEB.begin(); theIterPedOn != badPedOnEB.end(); ++theIterPedOn) {
1084     float thePedOn = (*theIterPedOn).second;
1085     float thePedOnRms = 9999.;
1086     float theGain = 9999.;
1087     float theLaser = 9999.;
1088     float theOccHigh = 9999.;
1089 
1090     theIterPedOnRms = badPedOnRmsEB.find((*theIterPedOn).first);
1091     theIterGain = badGainEB.find((*theIterPedOn).first);
1092     theIterLaser = badLaserEB.find((*theIterPedOn).first);
1093     theIterOccHigh = badOccHighEB.find((*theIterPedOn).first);
1094 
1095     if (theIterPedOnRms != badPedOnRmsEB.end())
1096       thePedOnRms = (*theIterPedOnRms).second;
1097     if (theIterLaser != badLaserEB.end())
1098       theLaser = (*theIterLaser).second;
1099     if (theIterOccHigh != badOccHighEB.end())
1100       theOccHigh = (*theIterOccHigh).second;
1101 
1102     int thisFed = -100;
1103     EBDetId ebdetid((*theIterPedOn).first);
1104     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
1105     thisFed = 600 + elecId.dccId();
1106 
1107     // new problems only
1108     bool isNew = false;
1109     bool isNewPed = true;
1110     bool isNewLaser = true;
1111     bool isNewPhysics = true;
1112     for (theIter = maskedOnlinePedEB.begin(); theIter != maskedOnlinePedEB.end(); ++theIter) {
1113       if ((*theIter).first == ebdetid)
1114         isNewPed = false;
1115     }
1116 
1117     for (theIter = maskedLaserEB.begin(); theIter != maskedLaserEB.end(); ++theIter) {
1118       if ((*theIter).first == ebdetid)
1119         isNewLaser = false;
1120     }
1121 
1122     for (theIter = maskedPhysicsEB.begin(); theIter != maskedPhysicsEB.end(); ++theIter) {
1123       if ((*theIter).first == ebdetid)
1124         isNewPhysics = false;
1125     }
1126 
1127     if (isNewPed || (theLaser != 9999 && isNewLaser) || (theOccHigh != 9999 && isNewPhysics))
1128       isNew = true;
1129 
1130     if (theIterGain != badGainEB.end()) {
1131       *ResFileEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn << "\t\t"
1132                  << thePedOnRms << "\t\t"
1133                  << "gainZero"
1134                  << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1135 
1136       if (isNew) {
1137         *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn
1138                       << "\t\t" << thePedOnRms << "\t\t"
1139                       << "gainZero"
1140                       << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1141 
1142         float thisEtaFill = float(0);
1143         if (ebdetid.ieta() > 0)
1144           thisEtaFill = ebdetid.ieta() - 0.5;
1145         if (ebdetid.ieta() < 0)
1146           thisEtaFill = ebdetid.ieta();
1147         newBadEB_->Fill((ebdetid.iphi() - 0.5), thisEtaFill, 2);
1148       }
1149     } else {
1150       *ResFileEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn << "\t\t"
1151                  << thePedOnRms << "\t\t" << theGain << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1152 
1153       if (isNew) {
1154         *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn
1155                       << "\t\t" << thePedOnRms << "\t\t" << theGain << "\t\t" << theLaser << "\t\t" << theOccHigh
1156                       << std::endl;
1157 
1158         float thisEtaFill = float(0);
1159         if (ebdetid.ieta() > 0)
1160           thisEtaFill = ebdetid.ieta() - 0.5;
1161         if (ebdetid.ieta() < 0)
1162           thisEtaFill = ebdetid.ieta();
1163         newBadEB_->Fill((ebdetid.iphi() - 0.5), thisEtaFill, 2);
1164       }
1165     }
1166   }
1167 
1168   // EB, second check - loop over laser
1169   for (theIterLaser = badLaserEB.begin(); theIterLaser != badLaserEB.end(); ++theIterLaser) {
1170     // remove already included channels
1171     theIterPedOnRms = badPedOnRmsEB.find((*theIterLaser).first);
1172     if (theIterPedOnRms != badPedOnRmsEB.end())
1173       continue;
1174 
1175     float thePedOn = 9999.;
1176     float thePedOnRms = 9999.;
1177     float theGain = 9999.;
1178     float theLaser = (*theIterLaser).second;
1179     float theOccHigh = 9999.;
1180 
1181     theIterGain = badGainEB.find((*theIterLaser).first);
1182     theIterOccHigh = badOccHighEB.find((*theIterLaser).first);
1183     if (theIterOccHigh != badOccHighEB.end())
1184       theOccHigh = (*theIterOccHigh).second;
1185 
1186     int thisFed = -100;
1187     EBDetId ebdetid((*theIterLaser).first);
1188     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
1189     thisFed = 600 + elecId.dccId();
1190 
1191     // new problems only
1192     bool isNew = false;
1193     bool isNewPed = true;
1194     bool isNewLaser = true;
1195     bool isNewPhysics = true;
1196     for (theIter = maskedOnlinePedEB.begin(); theIter != maskedOnlinePedEB.end(); ++theIter) {
1197       if ((*theIter).first == ebdetid)
1198         isNewPed = false;
1199     }
1200 
1201     for (theIter = maskedLaserEB.begin(); theIter != maskedLaserEB.end(); ++theIter) {
1202       if ((*theIter).first == ebdetid)
1203         isNewLaser = false;
1204     }
1205 
1206     for (theIter = maskedPhysicsEB.begin(); theIter != maskedPhysicsEB.end(); ++theIter) {
1207       if ((*theIter).first == ebdetid)
1208         isNewPhysics = false;
1209     }
1210 
1211     if ((isNewPed && theIterGain != badGainEB.end()) || (isNewLaser) || (theOccHigh != 9999 && isNewPhysics))
1212       isNew = true;
1213 
1214     if (theIterGain != badGainEB.end()) {
1215       *ResFileEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn << "\t\t"
1216                  << thePedOnRms << "\t\t"
1217                  << "gainZero"
1218                  << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1219 
1220       if (isNew) {
1221         *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn
1222                       << "\t\t" << thePedOnRms << "\t\t"
1223                       << "gainZero"
1224                       << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1225 
1226         float thisEtaFill = float(0);
1227         if (ebdetid.ieta() > 0)
1228           thisEtaFill = ebdetid.ieta() - 0.5;
1229         if (ebdetid.ieta() < 0)
1230           thisEtaFill = ebdetid.ieta();
1231         newBadEB_->Fill((ebdetid.iphi() - 0.5), thisEtaFill, 2);
1232       }
1233     } else {
1234       *ResFileEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn << "\t\t"
1235                  << thePedOnRms << "\t\t" << theGain << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1236 
1237       if (isNew) {
1238         *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn
1239                       << "\t\t" << thePedOnRms << "\t\t" << theGain << "\t\t" << theLaser << "\t\t" << theOccHigh
1240                       << std::endl;
1241 
1242         float thisEtaFill = float(0);
1243         if (ebdetid.ieta() > 0)
1244           thisEtaFill = ebdetid.ieta() - 0.5;
1245         if (ebdetid.ieta() < 0)
1246           thisEtaFill = ebdetid.ieta();
1247         newBadEB_->Fill((ebdetid.iphi() - 0.5), thisEtaFill, 2);
1248       }
1249     }
1250   }
1251 
1252   // EB, third check: loop over occupancy
1253   for (theIterOccHigh = badOccHighEB.begin(); theIterOccHigh != badOccHighEB.end(); ++theIterOccHigh) {
1254     // remove already included  channels
1255     theIterPedOnRms = badPedOnRmsEB.find((*theIterOccHigh).first);
1256     theIterLaser = badLaserEB.find((*theIterOccHigh).first);
1257     if (theIterPedOnRms != badPedOnRmsEB.end())
1258       continue;
1259     if (theIterLaser != badLaserEB.end())
1260       continue;
1261 
1262     float thePedOn = 9999.;
1263     float thePedOnRms = 9999.;
1264     float theGain = 9999.;
1265     float theLaser = 9999.;
1266     float theOccHigh = (*theIterOccHigh).second;
1267     theIterGain = badGainEB.find((*theIterOccHigh).first);
1268 
1269     int thisFed = -100;
1270     EBDetId ebdetid((*theIterOccHigh).first);
1271     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
1272     thisFed = 600 + elecId.dccId();
1273 
1274     // new problems only
1275     bool isNew = false;
1276     bool isNewPed = true;
1277     bool isNewPhysics = true;
1278     for (theIter = maskedOnlinePedEB.begin(); theIter != maskedOnlinePedEB.end(); ++theIter) {
1279       if ((*theIter).first == ebdetid)
1280         isNewPed = false;
1281     }
1282 
1283     for (theIter = maskedPhysicsEB.begin(); theIter != maskedPhysicsEB.end(); ++theIter) {
1284       if ((*theIter).first == ebdetid)
1285         isNewPhysics = false;
1286     }
1287 
1288     if ((isNewPed && theIterGain != badGainEB.end()) || (isNewPhysics))
1289       isNew = true;
1290 
1291     if (theIterGain != badGainEB.end()) {
1292       *ResFileEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn << "\t\t"
1293                  << thePedOnRms << "\t\t"
1294                  << "gainZero"
1295                  << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1296 
1297       if (isNew) {
1298         *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn
1299                       << "\t\t" << thePedOnRms << "\t\t"
1300                       << "gainZero"
1301                       << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1302 
1303         float thisEtaFill = float(0);
1304         if (ebdetid.ieta() > 0)
1305           thisEtaFill = ebdetid.ieta() - 0.5;
1306         if (ebdetid.ieta() < 0)
1307           thisEtaFill = ebdetid.ieta();
1308         newBadEB_->Fill((ebdetid.iphi() - 0.5), thisEtaFill, 2);
1309       }
1310     } else {
1311       *ResFileEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn << "\t\t"
1312                  << thePedOnRms << "\t\t" << theGain << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1313 
1314       if (isNew) {
1315         *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn
1316                       << "\t\t" << thePedOnRms << "\t\t" << theGain << "\t\t" << theLaser << "\t\t" << theOccHigh
1317                       << std::endl;
1318 
1319         float thisEtaFill = float(0);
1320         if (ebdetid.ieta() > 0)
1321           thisEtaFill = ebdetid.ieta() - 0.5;
1322         if (ebdetid.ieta() < 0)
1323           thisEtaFill = ebdetid.ieta();
1324         newBadEB_->Fill((ebdetid.iphi() - 0.5), thisEtaFill, 2);
1325       }
1326     }
1327   }
1328 
1329   // EB, fourth check: loop over consistency
1330   for (theIterGain = badGainEB.begin(); theIterGain != badGainEB.end(); ++theIterGain) {
1331     // remove already included  channels
1332     theIterPedOnRms = badPedOnRmsEB.find((*theIterGain).first);
1333     theIterLaser = badLaserEB.find((*theIterGain).first);
1334     theIterOccHigh = badOccHighEB.find((*theIterGain).first);
1335     if (theIterPedOnRms != badPedOnRmsEB.end())
1336       continue;
1337     if (theIterLaser != badLaserEB.end())
1338       continue;
1339     if (theIterOccHigh != badOccHighEB.end())
1340       continue;
1341 
1342     float thePedOn = 9999.;
1343     float thePedOnRms = 9999.;
1344     float theLaser = 9999.;
1345     float theOccHigh = 9999.;
1346 
1347     int thisFed = -100;
1348     EBDetId ebdetid((*theIterGain).first);
1349     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
1350     thisFed = 600 + elecId.dccId();
1351 
1352     // new problems only
1353     bool isNew = false;
1354     bool isNewPed = true;
1355     for (theIter = maskedOnlinePedEB.begin(); theIter != maskedOnlinePedEB.end(); ++theIter) {
1356       if ((*theIter).first == ebdetid)
1357         isNewPed = false;
1358     }
1359 
1360     if (isNewPed && theIterGain != badGainEB.end())
1361       isNew = true;
1362 
1363     *ResFileEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn << "\t\t"
1364                << thePedOnRms << "\t\t"
1365                << "gainZero"
1366                << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1367 
1368     if (isNew) {
1369       *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << thePedOn
1370                     << "\t\t" << thePedOnRms << "\t\t"
1371                     << "gainZero"
1372                     << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1373 
1374       float thisEtaFill = float(0);
1375       if (ebdetid.ieta() > 0)
1376         thisEtaFill = ebdetid.ieta() - 0.5;
1377       if (ebdetid.ieta() < 0)
1378         thisEtaFill = ebdetid.ieta();
1379       newBadEB_->Fill((ebdetid.iphi() - 0.5), thisEtaFill, 2);
1380     }
1381   }
1382 
1383   // EE, first check: loop over pedestal online
1384   for (theIterPedOn = badPedOnEE.begin(); theIterPedOn != badPedOnEE.end(); ++theIterPedOn) {
1385     float thePedOn = (*theIterPedOn).second;
1386     float thePedOnRms = 9999.;
1387     float theGain = 9999.;
1388     float theLaser = 9999.;
1389     float theOccHigh = 9999.;
1390 
1391     theIterPedOnRms = badPedOnRmsEE.find((*theIterPedOn).first);
1392     theIterGain = badGainEE.find((*theIterPedOn).first);
1393     theIterLaser = badLaserEE.find((*theIterPedOn).first);
1394     theIterOccHigh = badOccHighEE.find((*theIterPedOn).first);
1395 
1396     if (theIterPedOnRms != badPedOnRmsEE.end())
1397       thePedOnRms = (*theIterPedOnRms).second;
1398     if (theIterLaser != badLaserEE.end())
1399       theLaser = (*theIterLaser).second;
1400     if (theIterOccHigh != badOccHighEE.end())
1401       theOccHigh = (*theIterOccHigh).second;
1402 
1403     int thisFed = -100;
1404     EEDetId eedetid((*theIterPedOn).first);
1405     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
1406     thisFed = 600 + elecId.dccId();
1407 
1408     // new problems only
1409     bool isNew = false;
1410     bool isNewPed = true;
1411     bool isNewLaser = true;
1412     bool isNewPhysics = true;
1413     for (theIter = maskedOnlinePedEE.begin(); theIter != maskedOnlinePedEE.end(); ++theIter) {
1414       if ((*theIter).first == eedetid)
1415         isNewPed = false;
1416     }
1417 
1418     for (theIter = maskedLaserEE.begin(); theIter != maskedLaserEE.end(); ++theIter) {
1419       if ((*theIter).first == eedetid)
1420         isNewLaser = false;
1421     }
1422 
1423     for (theIter = maskedPhysicsEE.begin(); theIter != maskedPhysicsEE.end(); ++theIter) {
1424       if ((*theIter).first == eedetid)
1425         isNewPhysics = false;
1426     }
1427 
1428     if (isNewPed || (theLaser != 9999 && isNewLaser) || (theOccHigh != 9999 && isNewPhysics))
1429       isNew = true;
1430 
1431     if (theIterGain != badGainEE.end()) {
1432       *ResFileEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside() << "\t\t"
1433                  << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1434                  << "gainZero"
1435                  << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1436 
1437       if (isNew) {
1438         *ResFileNewEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
1439                       << "\t\t" << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1440                       << "gainZero"
1441                       << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1442 
1443         if (eedetid.zside() > 0)
1444           newBadEEP_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1445         if (eedetid.zside() < 0)
1446           newBadEEM_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1447       }
1448     } else {
1449       *ResFileEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside() << "\t\t"
1450                  << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t" << theGain << "\t\t"
1451                  << theLaser << "\t\t" << theOccHigh << std::endl;
1452 
1453       if (isNew) {
1454         *ResFileNewEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
1455                       << "\t\t" << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1456                       << theGain << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1457 
1458         if (eedetid.zside() > 0)
1459           newBadEEP_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1460         if (eedetid.zside() < 0)
1461           newBadEEM_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1462       }
1463     }
1464   }
1465 
1466   // EE, second check: loop over laser
1467   for (theIterLaser = badLaserEE.begin(); theIterLaser != badLaserEE.end(); ++theIterLaser) {
1468     // remove already included  channels
1469     theIterPedOnRms = badPedOnRmsEE.find((*theIterLaser).first);
1470     if (theIterPedOnRms != badPedOnRmsEE.end())
1471       continue;
1472 
1473     float thePedOn = 9999.;
1474     float thePedOnRms = 9999.;
1475     float theGain = 9999.;
1476     float theLaser = (*theIterLaser).second;
1477     float theOccHigh = 9999.;
1478 
1479     theIterGain = badGainEE.find((*theIterLaser).first);
1480     theIterOccHigh = badOccHighEE.find((*theIterLaser).first);
1481     if (theIterOccHigh != badOccHighEE.end())
1482       theOccHigh = (*theIterOccHigh).second;
1483 
1484     int thisFed = -100;
1485     EEDetId eedetid((*theIterLaser).first);
1486     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
1487     thisFed = 600 + elecId.dccId();
1488 
1489     // new problems only
1490     bool isNew = false;
1491     bool isNewPed = true;
1492     bool isNewLaser = true;
1493     bool isNewPhysics = true;
1494     for (theIter = maskedOnlinePedEE.begin(); theIter != maskedOnlinePedEE.end(); ++theIter) {
1495       if ((*theIter).first == eedetid)
1496         isNewPed = false;
1497     }
1498 
1499     for (theIter = maskedLaserEE.begin(); theIter != maskedLaserEE.end(); ++theIter) {
1500       if ((*theIter).first == eedetid)
1501         isNewLaser = false;
1502     }
1503 
1504     for (theIter = maskedPhysicsEE.begin(); theIter != maskedPhysicsEE.end(); ++theIter) {
1505       if ((*theIter).first == eedetid)
1506         isNewPhysics = false;
1507     }
1508 
1509     if ((isNewPed && theIterGain != badGainEE.end()) || (isNewLaser) || (theOccHigh != 9999 && isNewPhysics))
1510       isNew = true;
1511 
1512     if (theIterGain != badGainEE.end()) {
1513       *ResFileEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside() << "\t\t"
1514                  << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1515                  << "gainZero"
1516                  << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1517 
1518       if (isNew) {
1519         *ResFileNewEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
1520                       << "\t\t" << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1521                       << "gainZero"
1522                       << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1523 
1524         if (eedetid.zside() > 0)
1525           newBadEEP_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1526         if (eedetid.zside() < 0)
1527           newBadEEM_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1528       }
1529     } else {
1530       *ResFileEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside() << "\t\t"
1531                  << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t" << theGain << "\t\t"
1532                  << theLaser << "\t\t" << theOccHigh << std::endl;
1533 
1534       if (isNew) {
1535         *ResFileNewEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
1536                       << "\t\t" << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1537                       << theGain << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1538 
1539         if (eedetid.zside() > 0)
1540           newBadEEP_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1541         if (eedetid.zside() < 0)
1542           newBadEEM_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1543       }
1544     }
1545   }
1546 
1547   // third check: loop over occupancy
1548   for (theIterOccHigh = badOccHighEE.begin(); theIterOccHigh != badOccHighEE.end(); ++theIterOccHigh) {
1549     // remove already included  channels
1550     theIterPedOnRms = badPedOnRmsEE.find((*theIterOccHigh).first);
1551     theIterLaser = badLaserEE.find((*theIterOccHigh).first);
1552     if (theIterPedOnRms != badPedOnRmsEE.end())
1553       continue;
1554     if (theIterLaser != badLaserEE.end())
1555       continue;
1556 
1557     float thePedOn = 9999.;
1558     float thePedOnRms = 9999.;
1559     float theGain = 9999.;
1560     float theLaser = 9999.;
1561     float theOccHigh = (*theIterOccHigh).second;
1562     theIterGain = badGainEE.find((*theIterOccHigh).first);
1563 
1564     int thisFed = -100;
1565     EEDetId eedetid((*theIterOccHigh).first);
1566     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
1567     thisFed = 600 + elecId.dccId();
1568 
1569     // new problems only
1570     bool isNew = false;
1571     bool isNewPed = true;
1572     bool isNewPhysics = true;
1573     for (theIter = maskedOnlinePedEE.begin(); theIter != maskedOnlinePedEE.end(); ++theIter) {
1574       if ((*theIter).first == eedetid)
1575         isNewPed = false;
1576     }
1577 
1578     for (theIter = maskedPhysicsEE.begin(); theIter != maskedPhysicsEE.end(); ++theIter) {
1579       if ((*theIter).first == eedetid)
1580         isNewPhysics = false;
1581     }
1582 
1583     if ((isNewPed && theIterGain != badGainEE.end()) || (isNewPhysics))
1584       isNew = true;
1585 
1586     if (theIterGain != badGainEE.end()) {
1587       *ResFileEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside() << "\t\t"
1588                  << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1589                  << "gainZero"
1590                  << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1591 
1592       if (isNew) {
1593         *ResFileNewEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
1594                       << "\t\t" << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1595                       << "gainZero"
1596                       << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1597 
1598         if (eedetid.zside() > 0)
1599           newBadEEP_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1600         if (eedetid.zside() < 0)
1601           newBadEEM_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1602       }
1603     } else {
1604       *ResFileEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside() << "\t\t"
1605                  << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t" << theGain << "\t\t"
1606                  << theLaser << "\t\t" << theOccHigh << std::endl;
1607 
1608       if (isNew) {
1609         *ResFileNewEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
1610                       << "\t\t" << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1611                       << theGain << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1612 
1613         if (eedetid.zside() > 0)
1614           newBadEEP_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1615         if (eedetid.zside() < 0)
1616           newBadEEM_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1617       }
1618     }
1619   }
1620 
1621   // EE, fourth check: loop over consistency
1622   for (theIterGain = badGainEE.begin(); theIterGain != badGainEE.end(); ++theIterGain) {
1623     // remove already included  channels
1624     theIterPedOnRms = badPedOnRmsEE.find((*theIterGain).first);
1625     theIterLaser = badLaserEE.find((*theIterGain).first);
1626     theIterOccHigh = badOccHighEE.find((*theIterGain).first);
1627     if (theIterPedOnRms != badPedOnRmsEE.end())
1628       continue;
1629     if (theIterLaser != badLaserEE.end())
1630       continue;
1631     if (theIterOccHigh != badOccHighEE.end())
1632       continue;
1633     float thePedOn = 9999.;
1634     float thePedOnRms = 9999.;
1635     float theLaser = 9999.;
1636     float theOccHigh = 9999.;
1637 
1638     int thisFed = -100;
1639     EEDetId eedetid((*theIterGain).first);
1640     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
1641     thisFed = 600 + elecId.dccId();
1642 
1643     // new problems only
1644     bool isNew = false;
1645     bool isNewPed = true;
1646     for (theIter = maskedOnlinePedEE.begin(); theIter != maskedOnlinePedEE.end(); ++theIter) {
1647       if ((*theIter).first == eedetid)
1648         isNewPed = false;
1649     }
1650 
1651     if (isNewPed && theIterGain != badGainEE.end())
1652       isNew = true;
1653 
1654     *ResFileEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside() << "\t\t"
1655                << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1656                << "gainZero"
1657                << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1658 
1659     if (isNew) {
1660       *ResFileNewEE << thisFed << "\t\t" << eedetid.ix() << "\t\t" << eedetid.iy() << "\t\t" << eedetid.zside()
1661                     << "\t\t" << eedetid.hashedIndex() << "\t\t" << thePedOn << "\t\t" << thePedOnRms << "\t\t"
1662                     << "gainZero"
1663                     << "\t\t" << theLaser << "\t\t" << theOccHigh << std::endl;
1664 
1665       if (eedetid.zside() > 0)
1666         newBadEEP_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1667       if (eedetid.zside() < 0)
1668         newBadEEM_->Fill((eedetid.ix() - 0.5), (eedetid.iy() - 0.5), 4);
1669     }
1670   }
1671 }
1672 
1673 // core of the work = analyzing runs
1674 void popcon::EcalChannelStatusHandler::getNewObjects() {
1675   std::ostringstream ss;
1676   ss << "ECAL ";
1677 
1678   // here we retrieve all the runs of a given type after the last from online DB
1679   unsigned int max_since = 0;
1680   max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
1681   std::cout << "max_since : " << max_since << std::endl;
1682 
1683   std::cout << "Retrieving run list from ONLINE DB ... " << std::endl;
1684   econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
1685   std::cout << "Connection done" << std::endl;
1686 
1687   if (!econn) {
1688     std::cout << " Problem with OMDS: connection parameters " << m_sid << "/" << m_user << "/" << m_pass << std::endl;
1689     throw cms::Exception("OMDS not available");
1690   }
1691 
1692   // histos
1693   newBadEB_ = new TProfile2D("newBadEB_", "new bad channels, EB", 360, 0., 360., 170, -85., 85.);
1694   newBadEEP_ = new TProfile2D("newBad_EEP_", "new bad channels, EE+", 100, 0., 100., 100, 0., 100.);
1695   newBadEEM_ = new TProfile2D("newBad_EEM_", "new bad channels, EE-", 100, 0., 100., 100, 0., 100.);
1696 
1697   // these are the online conditions DB classes
1698   RunList my_runlist;
1699   RunTag my_runtag;
1700   LocationDef my_locdef;
1701   RunTypeDef my_rundef;
1702   my_locdef.setLocation(m_location);
1703   my_rundef.setRunType(m_runtype);
1704   my_runtag.setLocationDef(my_locdef);
1705   my_runtag.setRunTypeDef(my_rundef);
1706   my_runtag.setGeneralTag(m_gentag);
1707 
1708   // range of validity
1709   unsigned int min_run = 0;
1710   if (m_firstRun < max_since) {
1711     min_run = max_since + 1;  // we have to add 1 to the last transferred one
1712   } else {
1713     min_run = m_firstRun;
1714   }
1715   unsigned int max_run = m_lastRun;
1716 
1717   // here we retrieve the Monitoring run records
1718   MonVersionDef monverdef;
1719   monverdef.setMonitoringVersion("test01");
1720   MonRunTag mon_tag;
1721   // if (m_runtype=="PEDESTAL") mon_tag.setGeneralTag("CMSSW");
1722   // if (m_runtype=="LASER")    mon_tag.setGeneralTag("CMSSW");
1723   // if (m_runtype=="COSMIC" || m_runtype=="BEAM" || m_runtype=="PHYSICS" || m_runtype=="HALO" || m_runtype=="GLOBAL_COSMICS" ) mon_tag.setGeneralTag("CMSSW-online");
1724   if (m_runtype == "PEDESTAL")
1725     mon_tag.setGeneralTag("CMSSW-offline-private");
1726   if (m_runtype == "LASER")
1727     mon_tag.setGeneralTag("CMSSW-offline-private");
1728   if (m_runtype == "COSMIC" || m_runtype == "BEAM" || m_runtype == "PHYSICS" || m_runtype == "HALO" ||
1729       m_runtype == "GLOBAL_COSMICS")
1730     mon_tag.setGeneralTag("CMSSW-online-private");
1731   mon_tag.setMonVersionDef(monverdef);
1732   MonRunList mon_list;
1733   mon_list.setMonRunTag(mon_tag);
1734   mon_list.setRunTag(my_runtag);
1735   mon_list = econn->fetchMonRunList(my_runtag, mon_tag, min_run, max_run);
1736 
1737   // ----------------------------------------------------------------
1738   // preparing the output files
1739   char outfile[800];
1740   sprintf(outfile, "BadChannelsEB_run%d.txt", min_run);
1741   ResFileEB = new std::ofstream(outfile, std::ios::out);
1742   sprintf(outfile, "BadChannelsEE_run%d.txt", min_run);
1743   ResFileEE = new std::ofstream(outfile, std::ios::out);
1744   sprintf(outfile, "BadNewChannelsEB_run%d.txt", min_run);
1745   ResFileNewEB = new std::ofstream(outfile, std::ios::out);
1746   sprintf(outfile, "BadNewChannelsEE_run%d.txt", min_run);
1747   ResFileNewEE = new std::ofstream(outfile, std::ios::out);
1748   sprintf(outfile, "DaqConfig_run%d.txt", min_run);
1749   daqFile = new std::ofstream(outfile, std::ios::out);
1750   sprintf(outfile, "DaqConfig_channels_run%d.txt", min_run);
1751   daqFile2 = new std::ofstream(outfile, std::ios::out);
1752 
1753   *daqFile << "fed"
1754            << "\t\t"
1755            << "tower" << std::endl;
1756 
1757   if (m_runtype == "PEDESTAL") {
1758     *ResFileEB << "Fed"
1759                << "\t\t"
1760                << "Ic"
1761                << "\t\t"
1762                << "hIndex"
1763                << "\t\t"
1764                << "MeanG12"
1765                << "\t\t"
1766                << "RmsG12"
1767                << "\t\t"
1768                << "MeanG6"
1769                << "\t\t"
1770                << "RmsG6"
1771                << "\t\t"
1772                << "MeanG1"
1773                << "\t\t"
1774                << "RmsG1" << std::endl;
1775 
1776     *ResFileEE << "Fed"
1777                << "\t\t"
1778                << "Ix"
1779                << "\t\t"
1780                << "Iy"
1781                << "\t\t"
1782                << "Iz"
1783                << "\t\t"
1784                << "hIndex"
1785                << "\t\t"
1786                << "MeanG12"
1787                << "\t\t"
1788                << "RmsG12"
1789                << "\t\t"
1790                << "MeanG6"
1791                << "\t\t"
1792                << "RmsG6"
1793                << "\t\t"
1794                << "MeanG1"
1795                << "\t\t"
1796                << "RmsG1" << std::endl;
1797 
1798     *ResFileNewEB << "Fed"
1799                   << "\t\t"
1800                   << "Ic"
1801                   << "\t\t"
1802                   << "hIndex"
1803                   << "\t\t"
1804                   << "MeanG12"
1805                   << "\t\t"
1806                   << "RmsG12"
1807                   << "\t\t"
1808                   << "MeanG6"
1809                   << "\t\t"
1810                   << "RmsG6"
1811                   << "\t\t"
1812                   << "MeanG1"
1813                   << "\t\t"
1814                   << "RmsG1" << std::endl;
1815 
1816     *ResFileNewEE << "Fed"
1817                   << "\t\t"
1818                   << "Ix"
1819                   << "\t\t"
1820                   << "Iy"
1821                   << "\t\t"
1822                   << "Iz"
1823                   << "\t\t"
1824                   << "hIndex"
1825                   << "\t\t"
1826                   << "MeanG12"
1827                   << "\t\t"
1828                   << "RmsG12"
1829                   << "\t\t"
1830                   << "MeanG6"
1831                   << "\t\t"
1832                   << "RmsG6"
1833                   << "\t\t"
1834                   << "MeanG1"
1835                   << "\t\t"
1836                   << "RmsG1" << std::endl;
1837   }
1838 
1839   if (m_runtype == "LASER") {
1840     *ResFileEB << "Fed"
1841                << "\t\t"
1842                << "Ic"
1843                << "\t\t"
1844                << "hIndex"
1845                << "\t\t"
1846                << "apd" << std::endl;
1847     *ResFileEE << "Fed"
1848                << "\t\t"
1849                << "Ix"
1850                << "\t\t"
1851                << "Iy"
1852                << "\t\t"
1853                << "Iz"
1854                << "\t\t"
1855                << "hIndex"
1856                << "\t\t"
1857                << "apd" << std::endl;
1858     *ResFileNewEB << "Fed"
1859                   << "\t\t"
1860                   << "Ic"
1861                   << "\t\t"
1862                   << "hIndex"
1863                   << "\t\t"
1864                   << "apd" << std::endl;
1865     *ResFileNewEE << "Fed"
1866                   << "\t\t"
1867                   << "Ix"
1868                   << "\t\t"
1869                   << "Iy"
1870                   << "\t\t"
1871                   << "Iz"
1872                   << "\t\t"
1873                   << "hIndex"
1874                   << "\t\t"
1875                   << "apd" << std::endl;
1876   }
1877 
1878   if (m_runtype == "COSMIC" || m_runtype == "BEAM" || m_runtype == "PHYSICS" || m_runtype == "HALO" ||
1879       m_runtype == "GLOBAL_COSMICS") {
1880     *ResFileEB << "Fed"
1881                << "\t\t"
1882                << "Ic"
1883                << "\t\t"
1884                << "hIndex"
1885                << "\t\t"
1886                << "pedOnline"
1887                << "\t\t"
1888                << "pedOnlineRMS "
1889                << "\t\t"
1890                << "gain0"
1891                << "\t\t"
1892                << "apd"
1893                << "\t\t"
1894                << "highThrOcc"
1895                << "\t\t" << std::endl;
1896 
1897     *ResFileEE << "Fed"
1898                << "\t\t"
1899                << "Ix"
1900                << "Iy"
1901                << "\t\t"
1902                << "Iz"
1903                << "\t\t"
1904                << "hIndex"
1905                << "\t\t"
1906                << "pedOnline"
1907                << "\t\t"
1908                << "pedOnlineRMS "
1909                << "\t\t"
1910                << "gain0"
1911                << "\t\t"
1912                << "apd"
1913                << "\t\t"
1914                << "highThrOcc"
1915                << "\t\t" << std::endl;
1916 
1917     *ResFileNewEB << "Fed"
1918                   << "\t\t"
1919                   << "Ic"
1920                   << "\t\t"
1921                   << "hIndex"
1922                   << "\t\t"
1923                   << "pedOnline"
1924                   << "\t\t"
1925                   << "pedOnlineRMS "
1926                   << "\t\t"
1927                   << "gain0"
1928                   << "\t\t"
1929                   << "apd"
1930                   << "\t\t"
1931                   << "highThrOcc"
1932                   << "\t\t" << std::endl;
1933 
1934     *ResFileNewEE << "Fed"
1935                   << "\t\t"
1936                   << "Ix"
1937                   << "Iy"
1938                   << "\t\t"
1939                   << "Iz"
1940                   << "\t\t"
1941                   << "hIndex"
1942                   << "\t\t"
1943                   << "pedOnline"
1944                   << "\t\t"
1945                   << "pedOnlineRMS "
1946                   << "\t\t"
1947                   << "gain0"
1948                   << "\t\t"
1949                   << "apd"
1950                   << "\t\t"
1951                   << "highThrOcc"
1952                   << "\t\t" << std::endl;
1953   }
1954 
1955   // -------------------------------------------------------------------
1956   // analysis for the wanted runs
1957   std::vector<MonRunIOV> mon_run_vec = mon_list.getRuns();
1958   int mon_runs = mon_run_vec.size();
1959   std::cout << "number of Mon runs is " << mon_runs << std::endl;
1960   if (mon_runs == 0)
1961     std::cout << "PROBLEM! 0 runs analyzed by DQM" << std::endl;
1962   if (mon_runs == 0)
1963     ss << "PROBLEM! 0 runs analyzed by DQM" << std::endl;
1964 
1965   // initialize std::maps with masked channels
1966   maskedOnlinePedEB.clear();
1967   maskedOnlinePedEE.clear();
1968   maskedPedEB.clear();
1969   maskedPedEE.clear();
1970   maskedLaserEB.clear();
1971   maskedLaserEE.clear();
1972   maskedPhysicsEB.clear();
1973   maskedPhysicsEE.clear();
1974 
1975   // to iterate
1976   std::map<DetId, float>::const_iterator theIter;
1977 
1978   // using db info written by DQM
1979   if (mon_runs > 0) {
1980     for (int dqmRun = 0; dqmRun < mon_runs; dqmRun++) {
1981       unsigned long iDqmRun = (unsigned long)mon_run_vec[dqmRun].getRunIOV().getRunNumber();
1982 
1983       std::cout << "retrieve the DQM data for run number: " << iDqmRun
1984                 << ", subrun number: " << mon_run_vec[dqmRun].getSubRunNumber() << std::endl;
1985 
1986       if (mon_run_vec[dqmRun].getSubRunNumber() ==
1987           mon_runs) {  // fixme: check it still works after DMQ soft reset modifications
1988 
1989         // retrieve daq configuration for this run
1990         RunIOV myRun;
1991         myRun = mon_run_vec[dqmRun].getRunIOV();
1992         daqOut(myRun);
1993 
1994         // retrieve the data for a given run
1995         RunIOV runiov_prime = mon_run_vec[dqmRun].getRunIOV();
1996 
1997         // here we read the list of masked channel in the DB for this run and create masked channels std::maps
1998         std::cout << "Fetching masked channels from DB" << std::endl;
1999         ecalErrorMask_.readDB(econn, &runiov_prime);
2000 
2001         // -----------------------------------------------------------------------------------
2002         // here we do all the different types of analyses
2003 
2004         // PEDESTAL ANALYSIS for local runs: check pedestals only
2005         if (m_runtype == "PEDESTAL") {
2006           // retrieve the pedestals from OMDS for this run
2007           std::map<EcalLogicID, MonPedestalsDat> dataset_mon;
2008           econn->fetchDataSet(&dataset_mon, &mon_run_vec[dqmRun]);
2009           std::cout << "running pedestal analysis" << std::endl;
2010           std::cout << "OMDS record for pedestals, run " << iDqmRun << " is made of " << dataset_mon.size()
2011                     << " entries" << std::endl;
2012 
2013           // retrieve the crystal consistency from OMDS for this run
2014           std::map<EcalLogicID, MonCrystalConsistencyDat> wrongGain_mon;
2015           econn->fetchDataSet(&wrongGain_mon, &mon_run_vec[dqmRun]);
2016           std::cout << "OMDS record for consistency, run " << iDqmRun << " is made of " << wrongGain_mon.size()
2017                     << " entries" << std::endl;
2018 
2019           // check if enough data and perform analysis
2020           if (!dataset_mon.empty()) {
2021             pedAnalysis(dataset_mon, wrongGain_mon);
2022           } else {
2023             std::cout << "Not enought data for pedestal analysis" << std::endl;
2024             ss << "Not enought data for pedestal analysis" << std::endl;
2025           }
2026         }
2027 
2028         // LASER ANALYSIS for local runs: check APD values only
2029         if (m_runtype == "LASER") {
2030           // retrieve the APD / PNs from OMDS for this run
2031           std::map<EcalLogicID, MonLaserBlueDat> dataset_mon;
2032           econn->fetchDataSet(&dataset_mon, &mon_run_vec[dqmRun]);
2033           std::cout << "running the laser analysis based on DQM data" << std::endl;
2034           std::cout << "OMDS record for run " << iDqmRun << " is made of " << dataset_mon.size() << " records"
2035                     << std::endl;
2036 
2037           // check if enough data and select good light modules / perform analysis
2038           if (!dataset_mon.empty()) {
2039             nBadLaserModules(dataset_mon);
2040             laserAnalysis(dataset_mon);
2041           } else {
2042             std::cout << "Not enought data for dqm-based laser analysis" << std::endl;
2043             ss << "Not enought data for dqm-based laser analysis" << std::endl;
2044           }
2045         }
2046 
2047         // global analysis for global runs
2048         if (m_runtype == "COSMIC" || m_runtype == "BEAM" || m_runtype == "PHYSICS" || m_runtype == "HALO" ||
2049             m_runtype == "GLOBAL_COSMICS") {
2050           // retrieve the pedestal online from OMDS for this run
2051           std::map<EcalLogicID, MonPedestalsOnlineDat> pedonline_mon;
2052           econn->fetchDataSet(&pedonline_mon, &mon_run_vec[dqmRun]);
2053           std::cout << "running pedestal online analysis" << std::endl;
2054           std::cout << "OMDS record for pedestals, run " << iDqmRun << " is made of " << pedonline_mon.size()
2055                     << std::endl;
2056 
2057           // retrieve the crystal consistency from OMDS for this run
2058           std::map<EcalLogicID, MonCrystalConsistencyDat> wrongGain_mon;
2059           econn->fetchDataSet(&wrongGain_mon, &mon_run_vec[dqmRun]);
2060           std::cout << "OMDS record for consistency, run " << iDqmRun << " is made of " << wrongGain_mon.size()
2061                     << " entries" << std::endl;
2062 
2063           // retrieve the occupancy info from OMDS for this run
2064           std::map<EcalLogicID, MonOccupancyDat> occupancy_mon;
2065           econn->fetchDataSet(&occupancy_mon, &mon_run_vec[dqmRun]);
2066           std::cout << "OMDS record for occupancy, run " << iDqmRun << " is made of " << occupancy_mon.size()
2067                     << std::endl;
2068 
2069           // retrieve the APD / PNs from OMDS for this run
2070           std::map<EcalLogicID, MonLaserBlueDat> laser_mon;
2071           econn->fetchDataSet(&laser_mon, &mon_run_vec[dqmRun]);
2072           std::cout << "running laser analysis" << std::endl;
2073           std::cout << "OMDS record for laser, run " << iDqmRun << " is made of " << laser_mon.size() << " records"
2074                     << std::endl;
2075 
2076           // check if enough data in all the categories and do the analysis
2077           if (pedonline_mon.empty()) {
2078             std::cout << "Not enought data for pedestal online analysis" << std::endl;
2079             ss << "Not enought data for pedestal online analysis" << std::endl;
2080           }
2081           if (occupancy_mon.empty()) {
2082             std::cout << "Not enought data for occupancy analysis" << std::endl;
2083             ss << "Not enought data for occupancy analysis" << std::endl;
2084           }
2085           if (laser_mon.empty()) {
2086             std::cout << "Not enought data for laser analysis" << std::endl;
2087             ss << "Not enought data for laser analysis" << std::endl;
2088           }
2089           if (!pedonline_mon.empty() || !occupancy_mon.empty() || !wrongGain_mon.empty() || !laser_mon.empty()) {
2090             nBadLaserModules(laser_mon);
2091             cosmicsAnalysis(pedonline_mon, wrongGain_mon, laser_mon, occupancy_mon);
2092           }
2093 
2094           // plotting histos with new bad channels
2095           int iLineEB = 0;
2096           TLine lEB;
2097           gStyle->SetPalette(1);
2098           gStyle->SetOptStat(0);
2099           TCanvas c("c", "c", 1);
2100           newBadEB_->SetMaximum(11);
2101           newBadEB_->Draw("colz");
2102           iLineEB = 0;
2103           lEB.DrawLine(0, 0, 360, 0);
2104           while (iLineEB < 18) {
2105             lEB.DrawLine(iLineEB * 20, -85, iLineEB * 20, 85);
2106             iLineEB++;
2107           }
2108           c.SaveAs("newBadEB_.png");
2109 
2110           TLine lEE;
2111           lEE.SetLineWidth(1);
2112           int ixSectorsEE[202] = {
2113               61, 61,  60,  60, 59, 59, 58, 58, 57,  57,  55, 55, 45, 45, 43, 43, 42, 42, 41, 41, 40, 40, 39,
2114               39, 40,  40,  41, 41, 42, 42, 43, 43,  45,  45, 55, 55, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61,
2115               0,  100, 100, 97, 97, 95, 95, 92, 92,  87,  87, 85, 85, 80, 80, 75, 75, 65, 65, 60, 60, 40, 40,
2116               35, 35,  25,  25, 20, 20, 15, 15, 13,  13,  8,  8,  5,  5,  3,  3,  0,  0,  3,  3,  5,  5,  8,
2117               8,  13,  13,  15, 15, 20, 20, 25, 25,  35,  35, 40, 40, 60, 60, 65, 65, 75, 75, 80, 80, 85, 85,
2118               87, 87,  92,  92, 95, 95, 97, 97, 100, 100, 0,  61, 65, 65, 70, 70, 80, 80, 90, 90, 92, 0,  61,
2119               65, 65,  90,  90, 97, 0,  57, 60, 60,  65,  65, 70, 70, 75, 75, 80, 80, 0,  50, 50, 0,  43, 40,
2120               40, 35,  35,  30, 30, 25, 25, 20, 20,  0,   39, 35, 35, 10, 10, 3,  0,  39, 35, 35, 30, 30, 20,
2121               20, 10,  10,  8,  0,  45, 45, 40, 40,  35,  35, 0,  55, 55, 60, 60, 65, 65};
2122           int iySectorsEE[202] = {
2123               50, 55,  55, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 60, 60,  59,  59, 58, 58, 57, 57, 55, 55, 45, 45, 43,
2124               43, 42,  42, 41, 41, 40, 40, 39, 39, 40, 40, 41, 41, 42, 42,  43,  43, 45, 45, 50, 0,  50, 60, 60, 65, 65,
2125               75, 75,  80, 80, 85, 85, 87, 87, 92, 92, 95, 95, 97, 97, 100, 100, 97, 97, 95, 95, 92, 92, 87, 87, 85, 85,
2126               80, 80,  75, 75, 65, 65, 60, 60, 40, 40, 35, 35, 25, 25, 20,  20,  15, 15, 13, 13, 8,  8,  5,  5,  3,  3,
2127               0,  0,   3,  3,  5,  5,  8,  8,  13, 13, 15, 15, 20, 20, 25,  25,  35, 35, 40, 40, 50, 0,  45, 45, 40, 40,
2128               35, 35,  30, 30, 25, 25, 0,  50, 50, 55, 55, 60, 60, 0,  60,  60,  65, 65, 70, 70, 75, 75, 85, 85, 87, 0,
2129               61, 100, 0,  60, 60, 65, 65, 70, 70, 75, 75, 85, 85, 87, 0,   50,  50, 55, 55, 60, 60, 0,  45, 45, 40, 40,
2130               35, 35,  30, 30, 25, 25, 0,  39, 30, 30, 15, 15, 5,  0,  39,  30,  30, 15, 15, 5};
2131 
2132           newBadEEP_->SetMaximum(11);
2133           newBadEEP_->Draw("colz");
2134           for (int iLineEEP = 0; iLineEEP < 201; iLineEEP = iLineEEP + 1) {
2135             if ((ixSectorsEE[iLineEEP] != 0 || iySectorsEE[iLineEEP] != 0) &&
2136                 (ixSectorsEE[iLineEEP + 1] != 0 || iySectorsEE[iLineEEP + 1] != 0)) {
2137               lEE.DrawLine(
2138                   ixSectorsEE[iLineEEP], iySectorsEE[iLineEEP], ixSectorsEE[iLineEEP + 1], iySectorsEE[iLineEEP + 1]);
2139             }
2140           }
2141           c.SaveAs("newBadEEP_.png");
2142 
2143           newBadEEM_->SetMaximum(11);
2144           newBadEEM_->Draw("colz");
2145           for (int iLineEEP = 0; iLineEEP < 201; iLineEEP = iLineEEP + 1) {
2146             if ((ixSectorsEE[iLineEEP] != 0 || iySectorsEE[iLineEEP] != 0) &&
2147                 (ixSectorsEE[iLineEEP + 1] != 0 || iySectorsEE[iLineEEP + 1] != 0)) {
2148               lEE.DrawLine(
2149                   ixSectorsEE[iLineEEP], iySectorsEE[iLineEEP], ixSectorsEE[iLineEEP + 1], iySectorsEE[iLineEEP + 1]);
2150             }
2151           }
2152           c.SaveAs("newBadEEM_.png");
2153 
2154         }  // cosmics analysis
2155 
2156       }  // subruns
2157     }    // runs loop
2158   }      // we have the DQM info
2159 
2160   delete econn;
2161   std::cout << "Ecal - > end of getNewObjects -----------\n";
2162 }
2163 
2164 void popcon::EcalChannelStatusHandler::setElectronicsMap(const EcalElectronicsMapping* theEcalElectronicsMap) {
2165   ecalElectronicsMap_ = (*theEcalElectronicsMap);
2166 }