CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/CondTools/Ecal/src/EcalChannelStatusHandler.cc

Go to the documentation of this file.
00001 // 
00002 //
00003 // still missing: * check crystals with occupancy zero - to be cross-checked with what was masked in the DAQ
00004 //                * info about what is in/out of daq 
00005 //
00006 // ------------------------------------------------------------
00007 
00008 
00009 // analyses:
00010 // pedestal runs -> PEDESTAL analysis only (occupancy not available from DB):
00011 // laser runs    -> LASER analysis only
00012 // physics runs  -> PEDESTAL ONLINE + PEDESTAL (from calib sequence) + OCCUPANCY + LASER (from calib sequence) analysis
00013 
00014 
00015 // pedestal / pedestal online analysis:
00016 // a) if one crystal is dead or noisy at least in one gain is recorded
00017 // b) cuts: * pedestal value within 100-300 
00018 //          * pedestal RMS above 2 (EB) or 2.5 (EE)
00019 //          * pedestal RMS not zero
00020 //          * channel working at all gains [in local pedestal runs]
00021 //          * channel not stuck at G0 [ stuck = at gain zero in more than 1000 events ]
00022 
00023 
00024 // laser analysis:
00025 // a) a light module is ON if at least TWO crystals have amplitude>100. The analysis is done on light modules which are on.
00026 // b) cuts: * APD > 400 in EB
00027 //          * APD > 100 in EE
00028 
00029 
00030 // occupancy analysis:
00031 // cuts:
00032 // a) a channel in EB (EE) is noisy if it has > 1 permill of total events above high threshold in EB (EE)  
00033 
00034 
00035 
00036 // cosmics/physics runs analysis: combine pedestal online + laser + occupancy analyses
00037 
00038 
00039 
00040 
00041 
00042 
00043 #include "CondTools/Ecal/interface/EcalLaserHandler.h"
00044 
00045 #include "CondTools/Ecal/interface/EcalChannelStatusHandler.h"
00046 
00047 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00048 
00049 #include "TProfile2D.h"
00050 #include "TTree.h"
00051 #include "TFile.h"
00052 #include "TLine.h"
00053 #include "TStyle.h"
00054 #include "TCanvas.h"
00055 #include "TGaxis.h"
00056 #include "TColor.h"
00057 
00058 
00059 popcon::EcalChannelStatusHandler::EcalChannelStatusHandler(const edm::ParameterSet & ps) {
00060 
00061   std::cout << "EcalChannelStatus Source handler constructor\n" << std::endl;
00062 
00063   m_firstRun       = static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
00064   m_lastRun        = static_cast<unsigned int>(atoi( ps.getParameter<std::string>("lastRun").c_str()));
00065   m_sid            = ps.getParameter<std::string>("OnlineDBSID");
00066   m_user           = ps.getParameter<std::string>("OnlineDBUser");
00067   m_pass           = ps.getParameter<std::string>("OnlineDBPassword");
00068   m_locationsource = ps.getParameter<std::string>("LocationSource");
00069   m_location       = ps.getParameter<std::string>("Location");
00070   m_gentag         = ps.getParameter<std::string>("GenTag");
00071   m_runtype        = ps.getParameter<std::string>("RunType");  
00072   m_name           = ps.getUntrackedParameter<std::string>("name","EcalChannelStatusHandler");
00073   
00074   std::cout << m_sid << "/" << m_user << "/" << m_pass << "/" << m_location << "/" << m_gentag << std::endl;
00075 }
00076 
00077 
00078 popcon::EcalChannelStatusHandler::~EcalChannelStatusHandler() { }
00079 
00080 
00081 
00082 
00083 // ------------------------------------------------
00084 // START PEDESTALS ROUTINES
00085 
00086 // return pedestal values at gain 12 
00087 float popcon::EcalChannelStatusHandler::checkPedestalValueGain12( EcalPedestals::Item* item ) {
00088   float result = item->mean_x12;
00089   return result;
00090 }
00091 
00092 // return pedestal values at gain 6 - pedestal runs
00093 float popcon::EcalChannelStatusHandler::checkPedestalValueGain6( EcalPedestals::Item* item ) {
00094   float result = item->mean_x6;
00095   return result;
00096 }
00097 
00098 // return pedestal values at gain 1 - pedestal runs
00099 float popcon::EcalChannelStatusHandler::checkPedestalValueGain1( EcalPedestals::Item* item ) {
00100   float result = item->mean_x1;
00101   return result;
00102 }
00103 
00104 // return pedestal RMS at gain 12
00105 float popcon::EcalChannelStatusHandler::checkPedestalRMSGain12( EcalPedestals::Item* item ) {
00106   float result = item->rms_x12;
00107   return result;
00108 }
00109 
00110 // return pedestal RMS at gain 6 - pedestal runs
00111 float popcon::EcalChannelStatusHandler::checkPedestalRMSGain6( EcalPedestals::Item* item ) {
00112   float result = item->rms_x6;
00113   return result;
00114 }
00115 
00116 // return pedestal RMS at gain 1 - pedestal runs
00117 float popcon::EcalChannelStatusHandler::checkPedestalRMSGain1( EcalPedestals::Item* item ) {
00118   float result = item->rms_x1;
00119   return result;
00120 }
00121 
00122 
00123 
00124 
00125 
00126 // ------------------------------------------------
00127 // START LASER ROUTINES 
00128 
00129 // choose 'good' EB and EE light modules. Based on DQM infos 
00130 void popcon::EcalChannelStatusHandler::nBadLaserModules( std::map<EcalLogicID, MonLaserBlueDat> dataset_mon ) {
00131   
00132   // NB: EcalLogicId, sm_num = ecid_xt.getID1() --> for barrel is 1->18 = EB+; 19->36 = EB-  
00133   // NB: EcalLogicId, sm_num = ecid_xt.getID1() --> for endcap is 1=Z+, -1=Z- ;              
00134 
00135   // good and bad light modules and reference crystals in EB
00136   // theLM=0 -> L-shaped            ( TTs: 1,2,3,4; 7-8; 11-12 ... )
00137   // theLM=1 -> not L-shaped        ( TTs: 5-6,9-10 ... ) 
00138   for (int theSm=0; theSm<36; theSm++){
00139     for (int theLM=0; theLM<2; theLM++){
00140       isEBRef1[theSm][theLM]        = false;
00141       isEBRef2[theSm][theLM]        = false;
00142       isGoodLaserEBSm[theSm][theLM] = false;
00143     }}
00144   
00145   // good and bad light modules and reference crystals in EE [NB: only in EE-5 and EE+5 we need 2 LM... redundant]
00146   // theLM=0 -> light module A (ix<=50)
00147   // theLM=1 -> light module B (ix>50)
00148   for (int theSector=0; theSector<18; theSector++){
00149     for (int theLM=0; theLM<2; theLM++){
00150       isEERef1[theSector][theLM]        = false;
00151       isEERef2[theSector][theLM]        = false;
00152       isGoodLaserEESm[theSector][theLM] = false;
00153     }}
00154 
00155   
00156   typedef std::map<EcalLogicID, MonLaserBlueDat>::const_iterator CImon;
00157   EcalLogicID ecid_xt;
00158   MonLaserBlueDat rd_blue;
00159 
00160   for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
00161 
00162     ecid_xt = p->first;
00163     int sm_num = ecid_xt.getID1();
00164     int xt_num = ecid_xt.getID2();
00165     int yt_num = ecid_xt.getID3();
00166 
00167     // in which Fed/triggerTower/sectorSide I am
00168     int theFed =-100;
00169     int theTT  =-100; 
00170     int theIx  =-100;
00171     if(ecid_xt.getName()=="EB_crystal_number") {
00172       EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);
00173       EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
00174       theFed = 600+elecId.dccId();
00175       theTT  = elecId.towerId();   
00176     }
00177     if(ecid_xt.getName()=="EE_crystal_number") {
00178       if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00179         EEDetId eedetid(xt_num,yt_num,sm_num);
00180         EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
00181         theFed = 600+elecId.dccId();
00182         theIx  = eedetid.ix(); 
00183       }
00184     }
00185 
00186     // to have numbers from 0 to 17 for the EE feds and 0-36 for EB                                             
00187     //  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;         
00188     //  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              
00189     //  0 = EB-1 --> 17 = EB-18; 18 = EB+1 --> 35 = EB+18                                                                               
00190     int thisFed=-100;
00191     if (ecid_xt.getName()=="EE_crystal_number") {
00192       if (theFed>600 && theFed<610) thisFed = theFed -601;
00193       if (theFed>645 && theFed<655) thisFed = theFed -646 + 9;
00194     }
00195     if (ecid_xt.getName()=="EB_crystal_number") { thisFed = theFed - 610; }
00196 
00197 
00198     // in which light module I am
00199     int theTTieta=-100;
00200     int theTTiphi=-100;
00201     int theLM=-100;
00202     if(ecid_xt.getName()=="EB_crystal_number") {
00203       theTTieta = (theTT-1)/4 +1;                 
00204       theTTiphi = (theTT-1)%4 +1;
00205       if (theTTieta==1 ||  theTTiphi==3 || theTTiphi==4)  theLM=0;     // L-shaped
00206       if (theTTieta>1  && (theTTiphi==1 || theTTiphi==2)) theLM=1;     // not L-shaped
00207     }
00208     if( (ecid_xt.getName()=="EE_crystal_number") && (thisFed==7 || thisFed==16) ) {   
00209       if (theIx<=50) theLM=0;
00210       if (theIx>50)  theLM=1;
00211     }
00212 
00213     
00214     // taking laser infos
00215     rd_blue = p->second;
00216     float myApdMean = rd_blue.getAPDMean();
00217     
00218     // barrel: is there at least one crystal on in this LM?
00219     if (ecid_xt.getName()=="EB_crystal_number") {
00220       EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);
00221       if ( !isEBRef1[thisFed][theLM] && !isEBRef2[thisFed][theLM] && myApdMean>100 ) isEBRef1[thisFed][theLM] = true;
00222       if (  isEBRef1[thisFed][theLM] && !isEBRef2[thisFed][theLM] && myApdMean>100 ) isEBRef2[thisFed][theLM] = true;
00223     }
00224     
00225     // endcap: is there at least one crystal on in this LM?
00226     if (ecid_xt.getName()=="EE_crystal_number") {
00227       EEDetId eedetid(xt_num,yt_num,sm_num);
00228 
00229       // just 1 LM per Fed
00230       if (thisFed!=7 && thisFed!=16) {
00231         if ( !isEERef1[thisFed][0] && !isEERef2[thisFed][0] && myApdMean>100 ) { isEERef1[thisFed][0] = true; isEERef1[thisFed][1] = true; }
00232         if (  isEERef1[thisFed][0] && !isEERef2[thisFed][0] && myApdMean>100 ) { isEERef2[thisFed][0] = true; isEERef2[thisFed][1] = true; }
00233       }
00234       
00235       // 2 LMs per Fed
00236       if (thisFed==7 || thisFed==16) {
00237         if ( !isEERef1[thisFed][theLM] && !isEERef2[thisFed][theLM] && myApdMean>100 ) isEERef1[thisFed][theLM] = true;
00238         if (  isEERef1[thisFed][theLM] && !isEERef2[thisFed][theLM] && myApdMean>100 ) isEERef2[thisFed][theLM] = true;
00239       }
00240     }
00241   }
00242   
00243   // check if the light module is on: at least two crystals must be on
00244   for (int theSm=0; theSm<36; theSm++){
00245     for (int theLM=0; theLM<2; theLM++){
00246       if (isEBRef1[theSm][theLM] && isEBRef2[theSm][theLM]) isGoodLaserEBSm[theSm][theLM] = true; 
00247       // std::cout << "Barrel: SM " << theSm << ", LM " << theLM << ": good = " << isGoodLaserEBSm[theSm][theLM] << std::endl;
00248     }}
00249   
00250   for (int theSector=0; theSector<18; theSector++){
00251     for (int theLM=0; theLM<2; theLM++){
00252       if (isEERef1[theSector][theLM] && isEERef2[theSector][theLM]) isGoodLaserEESm[theSector][theLM] = true; 
00253       // std::cout << "Endcap: SM " << theSector << ", LM " << theLM << ": good = " << isGoodLaserEESm[theSector][theLM] << std::endl;
00254     }}
00255 }
00256 
00257 
00258 
00259 // ----------------------------------------------------------
00260 // START MASKING ROUTINES
00261 void popcon::EcalChannelStatusHandler::pedOnlineMasking() {
00262 
00263   uint64_t bits03 = 0;
00264   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_MEAN_WARNING");
00265   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_RMS_WARNING");
00266   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR");
00267   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR");
00268   
00269   std::map<EcalLogicID, RunCrystalErrorsDat> theMask;
00270   EcalErrorMask::fetchDataSet(&theMask);
00271   
00272   if ( theMask.size()!=0 ) {
00273 
00274     std::map<EcalLogicID, RunCrystalErrorsDat>::const_iterator m;
00275     for (m=theMask.begin(); m!=theMask.end(); m++) {
00276       
00277       EcalLogicID ecid_xt = m->first;
00278       int sm_num = ecid_xt.getID1();
00279       int xt_num = ecid_xt.getID2(); 
00280       int yt_num = ecid_xt.getID3(); 
00281 
00282       if ( (m->second).getErrorBits() & bits03 ) {
00283 
00284         if(ecid_xt.getName()=="EB_crystal_number") {
00285           EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);              
00286           maskedOnlinePedEB.insert(std::pair<DetId, float>(ebdetid, 9999.));
00287         } else {
00288           if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00289             EEDetId eedetid(xt_num,yt_num,sm_num);
00290             maskedOnlinePedEE.insert(std::pair<DetId, float>(eedetid, 9999.));
00291           }}}
00292     }
00293   }
00294 }
00295 
00296 
00297 void popcon::EcalChannelStatusHandler::pedMasking() {
00298 
00299   uint64_t bits03 = 0;
00300   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_LOW_GAIN_MEAN_WARNING");
00301   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_MIDDLE_GAIN_MEAN_WARNING");
00302   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_HIGH_GAIN_MEAN_WARNING");
00303   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_LOW_GAIN_MEAN_ERROR");
00304   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_MIDDLE_GAIN_MEAN_ERROR");
00305   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_HIGH_GAIN_MEAN_ERROR");
00306   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_LOW_GAIN_RMS_WARNING");
00307   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_MIDDLE_GAIN_RMS_WARNING");
00308   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_HIGH_GAIN_RMS_WARNING");
00309   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_LOW_GAIN_RMS_ERROR");
00310   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_MIDDLE_GAIN_RMS_ERROR");
00311   bits03 |= EcalErrorDictionary::getMask("PEDESTAL_HIGH_GAIN_RMS_ERROR");  
00312 
00313   std::map<EcalLogicID, RunCrystalErrorsDat> theMask;
00314   EcalErrorMask::fetchDataSet(&theMask);
00315   
00316   if ( theMask.size()!=0 ) {
00317 
00318     std::map<EcalLogicID, RunCrystalErrorsDat>::const_iterator m;
00319     for (m=theMask.begin(); m!=theMask.end(); m++) {
00320       
00321       EcalLogicID ecid_xt = m->first;
00322       int sm_num = ecid_xt.getID1();
00323       int xt_num = ecid_xt.getID2(); 
00324       int yt_num = ecid_xt.getID3(); 
00325 
00326       if ( (m->second).getErrorBits() & bits03 ) {
00327 
00328         if(ecid_xt.getName()=="EB_crystal_number") {
00329           EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);              
00330           maskedPedEB.insert(std::pair<DetId, float>(ebdetid, 9999.));
00331         } else {
00332           if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00333             EEDetId eedetid(xt_num,yt_num,sm_num);
00334             maskedPedEE.insert(std::pair<DetId, float>(eedetid, 9999.));
00335           }}}
00336     }
00337   }
00338 }
00339 
00340 
00341 void popcon::EcalChannelStatusHandler::laserMasking() {
00342 
00343   uint64_t bits03 = 0;
00344   bits03 |= EcalErrorDictionary::getMask("LASER_MEAN_WARNING");
00345   bits03 |= EcalErrorDictionary::getMask("LASER_RMS_WARNING");
00346   bits03 |= EcalErrorDictionary::getMask("LASER_MEAN_OVER_PN_WARNING");
00347   bits03 |= EcalErrorDictionary::getMask("LASER_RMS_OVER_PN_WARNING");
00348   bits03 |= EcalErrorDictionary::getMask("LASER_MEAN_TIMING_WARNING");
00349   bits03 |= EcalErrorDictionary::getMask("LASER_RMS_TIMING_WARNING");
00350 
00351   std::map<EcalLogicID, RunCrystalErrorsDat> theMask;
00352   EcalErrorMask::fetchDataSet(&theMask);
00353   
00354   if ( theMask.size()!=0 ) {
00355 
00356     std::map<EcalLogicID, RunCrystalErrorsDat>::const_iterator m;
00357     for (m=theMask.begin(); m!=theMask.end(); m++) {
00358       
00359       EcalLogicID ecid_xt = m->first;
00360       int sm_num = ecid_xt.getID1();
00361       int xt_num = ecid_xt.getID2(); 
00362       int yt_num = ecid_xt.getID3(); 
00363 
00364       if ( (m->second).getErrorBits() & bits03 ) {
00365 
00366         if(ecid_xt.getName()=="EB_crystal_number") {
00367           EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);              
00368           maskedLaserEB.insert(std::pair<DetId, float>(ebdetid, 9999.));
00369         } else {
00370           if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00371             EEDetId eedetid(xt_num,yt_num,sm_num);
00372             maskedLaserEE.insert(std::pair<DetId, float>(eedetid, 9999.));
00373           }}}
00374     }
00375   }
00376 }
00377 
00378 
00379 void popcon::EcalChannelStatusHandler::physicsMasking() {
00380 
00381   uint64_t bits03 = 0;
00382   bits03 |= EcalErrorDictionary::getMask("PHYSICS_BAD_CHANNEL_WARNING");
00383   bits03 |= EcalErrorDictionary::getMask("PHYSICS_BAD_CHANNEL_ERROR");
00384 
00385   std::map<EcalLogicID, RunCrystalErrorsDat> theMask;
00386   EcalErrorMask::fetchDataSet(&theMask);
00387   
00388   if ( theMask.size()!=0 ) {
00389 
00390     std::map<EcalLogicID, RunCrystalErrorsDat>::const_iterator m;
00391     for (m=theMask.begin(); m!=theMask.end(); m++) {
00392       
00393       EcalLogicID ecid_xt = m->first;
00394       int sm_num = ecid_xt.getID1();
00395       int xt_num = ecid_xt.getID2(); 
00396       int yt_num = ecid_xt.getID3(); 
00397 
00398       if ( (m->second).getErrorBits() & bits03 ) {
00399 
00400         if(ecid_xt.getName()=="EB_crystal_number") {
00401           EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);              
00402           maskedPhysicsEB.insert(std::pair<DetId, float>(ebdetid, 9999.));
00403         } else {
00404           if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00405             EEDetId eedetid(xt_num,yt_num,sm_num);
00406             maskedPhysicsEE.insert(std::pair<DetId, float>(eedetid, 9999.));
00407           }}}
00408     }
00409   }
00410 }
00411 
00412 
00413 // ----------------------------------------------------------
00414 // START DAQ EXCLUDED FEDs ROUTINES
00415 void popcon::EcalChannelStatusHandler::daqOut(RunIOV myRun) {
00416   
00417   std::map<EcalLogicID, RunFEConfigDat> feconfig;
00418   econn->fetchDataSet(&feconfig, &myRun);
00419   
00420   typedef std::map<EcalLogicID, RunFEConfigDat>::const_iterator feConfIter;
00421   EcalLogicID ecid_xt;
00422   RunFEConfigDat rd_fe;
00423   
00424   int fe_conf_id=0;
00425   for (feConfIter p=feconfig.begin(); p!=feconfig.end(); p++) {
00426     ecid_xt = p->first;
00427     rd_fe   = p->second;
00428     fe_conf_id=rd_fe.getConfigId();
00429   }
00430         
00431   // reading this configuration
00432   ODFEDAQConfig myconfig;
00433   myconfig.setId(fe_conf_id);
00434   econn->fetchConfigSet(&myconfig);
00435   
00436   // list of bad channels
00437   int myTT=myconfig.getBadTTId();
00438   ODBadTTInfo mybadTT;
00439   mybadTT.setId(myTT);
00440   econn->fetchConfigSet(&mybadTT);
00441   
00442   std::vector< ODBadTTDat > badTT_dat;
00443   econn->fetchConfigDataSet(&badTT_dat, &mybadTT);
00444   
00445   for(size_t iTT=0; iTT<badTT_dat.size(); iTT++){
00446     int fed_id = badTT_dat[iTT].getFedId();
00447     int tt_id  = badTT_dat[iTT].getTTId();
00448     if (tt_id<69) *daqFile << fed_id << " " << tt_id << std::endl;
00449     
00450     // taking the channel list for towers out of daq
00451     if((fed_id<=609 || fed_id>=646) && tt_id<69) { // endcap    
00452       
00453       // moving from cms fed to db fed convention
00454       //int db_fedId = -999;
00455       //if (fed_id>=604 && fed_id<=609) db_fedId = fed_id - 603 + 9;  
00456       //if (fed_id>=601 && fed_id<=603) db_fedId = fed_id - 600 + 15;  
00457       //if (fed_id>=649 && fed_id<=654) db_fedId = fed_id - 648;
00458       //if (fed_id>=646 && fed_id<=648) db_fedId = fed_id - 645 + 6;        
00459       // db_fedId = fed_id;    // fixme: do we need 1-18 or 6XX?
00460       
00461       std::vector<EcalLogicID> badCrystals;
00462       badCrystals=econn->getEcalLogicIDSet("EE_readout_tower",fed_id, fed_id, tt_id, tt_id, EcalLogicID::NULLID,EcalLogicID::NULLID, "EE_crystal_number");    
00463  
00464       for(size_t mycrys=0; mycrys<badCrystals.size(); mycrys++){
00465         EcalLogicID ecid_xt = badCrystals[mycrys];
00466         int zSide = 999;
00467         int log_id = ecid_xt.getLogicID();
00468         int yt2    = log_id%1000;                                     //  EE_crystal_number:   2010100060 -> z=-1, x=100, y=60
00469         int xt2    = (log_id%1000000)/1000;                           //  EE_crystal_number:   2012020085 -> z=+1, x=20,  y=85
00470         int zt2    = (log_id/1000000)%10;
00471         if (zt2==0) zSide = -1;
00472         if (zt2==2) zSide = 1;
00473         *daqFile2 << xt2 << " " << yt2 << " " << zSide << std::endl;
00474       }
00475     }
00476     
00477     if(fed_id>=610 && fed_id<=645 && tt_id<69) { // barrel
00478       
00479       // moving from cms fed to db fed convention           
00480       int db_fedId = -999;
00481       if (fed_id>=610 && fed_id<=627) db_fedId = fed_id - 609 + 18;
00482       if (fed_id>=628 && fed_id<=645) db_fedId = fed_id - 627;
00483       
00484       std::vector<EcalLogicID> badCrystals;   
00485       badCrystals=econn->getEcalLogicIDSet("EB_trigger_tower",db_fedId, db_fedId, tt_id, tt_id, EcalLogicID::NULLID, EcalLogicID::NULLID, "EB_crystal_number");
00486       
00487       for(size_t mycrys=0; mycrys<badCrystals.size(); mycrys++){
00488         EcalLogicID ecid_xt = badCrystals[mycrys];
00489         int sm_num  = ecid_xt.getID1();
00490         int log_id  = ecid_xt.getLogicID();
00491         int xt2_num = log_id%10000;
00492         EBDetId ebdetid(sm_num,xt2_num,EBDetId::SMCRYSTALMODE);
00493         *daqFile2 << ebdetid.hashedIndex() << std::endl;
00494       } 
00495     }
00496   }
00497 }
00498 
00499 
00500 // ----------------------------------------------------------
00501 //
00502 // ANALYSIS
00503 //
00504 // ----------------------------------------------------------
00505 
00506 
00507 // ----------------------------------------------------------
00508 // LOCAL pedestal runs  
00509 
00510 void popcon::EcalChannelStatusHandler::pedAnalysis( std::map<EcalLogicID, MonPedestalsDat> dataset_mon, std::map<EcalLogicID, MonCrystalConsistencyDat> wrongGain_mon ) {
00511 
00512   // to take the list of masked crystals
00513   pedMasking();
00514 
00515   // to iterate
00516   std::map<DetId,float>::const_iterator theIter;
00517   
00518   // logic id
00519   EcalLogicID ecid_xt;
00520   
00521   // to check all problems except gain zero
00522   typedef std::map<EcalLogicID, MonPedestalsDat>::const_iterator CImon;
00523   MonPedestalsDat rd_ped;
00524   
00525   for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
00526 
00527     uint16_t status_now = 0;
00528     ecid_xt    = p->first;
00529     rd_ped     = p->second;
00530     int sm_num = ecid_xt.getID1();
00531     int xt_num = ecid_xt.getID2(); 
00532     int yt_num = ecid_xt.getID3(); 
00533     
00534     EcalPedestals::Item ped_item;
00535     ped_item.mean_x1  = rd_ped.getPedMeanG1() ;
00536     ped_item.mean_x6  = rd_ped.getPedMeanG6();
00537     ped_item.mean_x12 = rd_ped.getPedMeanG12();
00538     ped_item.rms_x1   = rd_ped.getPedRMSG1();
00539     ped_item.rms_x6   = rd_ped.getPedRMSG6() ;
00540     ped_item.rms_x12  = rd_ped.getPedRMSG12();
00541 
00542     // check if pedestal RMS is bad at least at 1 gain -> noisy or very noisy channel
00543     float lowerCut = 999.;
00544     if(ecid_xt.getName()=="EB_crystal_number") { lowerCut = 2.0; }
00545     if(ecid_xt.getName()=="EE_crystal_number") { lowerCut = 2.5; }
00546     if ( (checkPedestalRMSGain12(&ped_item)>lowerCut) || (checkPedestalRMSGain6(&ped_item)>lowerCut) || (checkPedestalRMSGain1(&ped_item)>lowerCut) ) status_now = 3;   
00547       
00548     // check if pedestal value is bad at least at 1 gain -> problem in dac settings
00549     if ( 
00550         ( checkPedestalValueGain12(&ped_item)>300 || checkPedestalValueGain12(&ped_item)<100 ) ||  
00551         ( checkPedestalValueGain6(&ped_item)>300  || checkPedestalValueGain6(&ped_item)<100  ) ||  
00552         ( checkPedestalValueGain1(&ped_item)>300  || checkPedestalValueGain1(&ped_item)<100  ) 
00553         )  status_now = 1;   
00554     
00555     // check if pedestal rms is zero at least at 1 gain -> dead at that channel  
00556     if ( checkPedestalRMSGain12(&ped_item)==0 || checkPedestalRMSGain6(&ped_item)==0 || checkPedestalRMSGain1(&ped_item)==0 ) status_now = 11;
00557     
00558     // check if the channel is fixed at G1
00559     if ( checkPedestalValueGain12(&ped_item)<0 && checkPedestalValueGain6(&ped_item)<0 && checkPedestalValueGain1(&ped_item)>0 ) status_now = 9;
00560 
00561     // check if the channel is fixed at G6
00562     if ( checkPedestalValueGain12(&ped_item)<0 && checkPedestalValueGain6(&ped_item)>0 && checkPedestalValueGain1(&ped_item)<0 ) status_now = 8;
00563     
00564     // check if the channel is not working at G12
00565     if ( checkPedestalValueGain12(&ped_item)<0 && checkPedestalValueGain6(&ped_item)>0 && checkPedestalValueGain1(&ped_item)>0 ) status_now = 8;
00566     
00567 
00568     // output in case of problems:
00569     if(status_now>0) {    
00570       if(ecid_xt.getName()=="EB_crystal_number") {
00571         EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);        
00572         EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
00573         int thisFed = 600+elecId.dccId();       
00574 
00575         *ResFileEB << thisFed           << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t" 
00576                    << ped_item.mean_x12 << "\t\t" << ped_item.rms_x12 << "\t\t"
00577                    << ped_item.mean_x6  << "\t\t" << ped_item.rms_x6  << "\t\t"
00578                    << ped_item.mean_x1  << "\t\t" << ped_item.rms_x1  << std::endl;
00579 
00580         
00581         // file with new problems only
00582         bool isOld=false;
00583         for(theIter=maskedPedEB.begin(); theIter!=maskedPedEB.end(); ++theIter) {
00584           if ((*theIter).first==ebdetid) isOld=true;
00585         }
00586         if (!isOld) { 
00587           *ResFileNewEB << thisFed           << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t" 
00588                         << ped_item.mean_x12 << "\t\t" << ped_item.rms_x12 << "\t\t"
00589                         << ped_item.mean_x6  << "\t\t" << ped_item.rms_x6  << "\t\t"
00590                         << ped_item.mean_x1  << "\t\t" << ped_item.rms_x1  << std::endl;
00591         }
00592         
00593       } else {      
00594         if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00595           EEDetId eedetid(xt_num,yt_num,sm_num);
00596           EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
00597           int thisFed = 600+elecId.dccId();
00598           *ResFileEE << thisFed           << "\t\t" 
00599                      << eedetid.ix()      << "\t\t" << eedetid.iy()     << "\t\t" 
00600                      << eedetid.zside()   << "\t\t" << eedetid.hashedIndex()  << "\t\t"                      
00601                      << ped_item.mean_x12 << "\t\t" << ped_item.rms_x12 << "\t\t"
00602                      << ped_item.mean_x6  << "\t\t" << ped_item.rms_x6  << "\t\t"
00603                      << ped_item.mean_x1  << "\t\t" << ped_item.rms_x1  << std::endl;
00604           
00605           bool isOld=false;
00606           for(theIter=maskedPedEE.begin(); theIter!=maskedPedEE.end(); ++theIter) {
00607             if ((*theIter).first==eedetid) isOld=true;
00608           }
00609           if (!isOld) { 
00610             *ResFileNewEE << thisFed           << "\t\t" 
00611                           << eedetid.ix()      << "\t\t" << eedetid.iy()     << "\t\t" 
00612                           << eedetid.zside()   << "\t\t" << eedetid.hashedIndex()  << "\t\t"                 
00613                           << ped_item.mean_x12 << "\t\t" << ped_item.rms_x12 << "\t\t"
00614                           << ped_item.mean_x6  << "\t\t" << ped_item.rms_x6  << "\t\t"
00615                           << ped_item.mean_x1  << "\t\t" << ped_item.rms_x1  << std::endl;
00616           }
00617         }
00618       }
00619     }
00620   }
00621 
00622   
00623   
00624   // to check if a crystal is at gain zero in at least 1000 events (which is not the best! fixme)   
00625   typedef std::map<EcalLogicID, MonCrystalConsistencyDat>::const_iterator WGmonIter;
00626   MonCrystalConsistencyDat rd_wgain;
00627   
00628   for (WGmonIter p = wrongGain_mon.begin(); p != wrongGain_mon.end(); p++) {
00629     ecid_xt    = p->first;
00630     rd_wgain   = p->second;
00631     int sm_num = ecid_xt.getID1();
00632     int xt_num = ecid_xt.getID2(); 
00633     int yt_num = ecid_xt.getID3(); 
00634     
00635     // output if problematic
00636     if (rd_wgain.getProblemsGainZero() > 1000) { 
00637       if(ecid_xt.getName()=="EB_crystal_number") {
00638         EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);
00639         EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
00640         int thisFed = 600+elecId.dccId();       
00641         *ResFileEB << thisFed  << "\t\t"  << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << "at gain zero"  << std::endl;                    
00642                    
00643         // file with new problems only
00644         bool isOld=false;
00645         for(theIter=maskedPedEB.begin(); theIter!=maskedPedEB.end(); ++theIter) {
00646           if ((*theIter).first==ebdetid) isOld=true;
00647         }
00648         if (!isOld) { 
00649           *ResFileNewEB << thisFed << "\t\t"  << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << "at gain zero"  << std::endl;                
00650         }
00651 
00652       } else {      
00653         if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00654           EEDetId eedetid(xt_num,yt_num,sm_num);
00655           EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
00656           int thisFed = 600+elecId.dccId();     
00657           *ResFileEE << thisFed                << "\t\t" << eedetid.ix()    << "\t\t" 
00658                      << eedetid.iy()           << "\t\t" << eedetid.zside() << "\t\t"                
00659                      << eedetid.hashedIndex()  << "\t\t"                      
00660                      << "at gain zero"    << std::endl; 
00661 
00662           bool isOld=false;
00663           for(theIter=maskedPedEE.begin(); theIter!=maskedPedEE.end(); ++theIter) {
00664             if ((*theIter).first==eedetid) isOld=true;
00665           }
00666           if (!isOld) { 
00667             *ResFileNewEE << thisFed                << "\t\t" << eedetid.ix()    << "\t\t" 
00668                           << eedetid.iy()           << "\t\t" << eedetid.zside() << "\t\t"                   
00669                           << eedetid.hashedIndex()  << "\t\t"                 
00670                           << "at gain zero"    << std::endl; 
00671           }
00672         }
00673       }   
00674     }
00675   }
00676 
00677 }
00678 
00679 
00680 // ------------------------------------------------------------
00681 //
00682 // LOCAL laser runs
00683 
00684 void popcon::EcalChannelStatusHandler::laserAnalysis( std::map<EcalLogicID, MonLaserBlueDat> dataset_mon ) { 
00685   
00686   // to take the list of masked crystals
00687   laserMasking();
00688 
00689   // to iterate
00690   std::map<DetId,float>::const_iterator theIter;
00691 
00692   typedef std::map<EcalLogicID, MonLaserBlueDat>::const_iterator CImon;
00693   EcalLogicID ecid_xt;
00694   MonLaserBlueDat rd_blue;
00695   
00696   for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
00697     ecid_xt    = p->first;
00698     int sm_num = ecid_xt.getID1();
00699     int xt_num = ecid_xt.getID2(); 
00700     int yt_num = ecid_xt.getID3(); 
00701     
00702     // in which Fed/triggerTower/sectorSide I am
00703     int theFed = -100;
00704     int theTT  = -100; 
00705     int theIx  = -100;
00706     if(ecid_xt.getName()=="EB_crystal_number") {
00707       EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);          
00708       EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
00709       theFed = 600+elecId.dccId();
00710       theTT  = elecId.towerId();   
00711     }   
00712     if(ecid_xt.getName()=="EE_crystal_number") {   
00713       if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00714         EEDetId eedetid(xt_num,yt_num,sm_num);
00715         EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
00716         theFed = 600+elecId.dccId();
00717         theIx  = eedetid.ix(); 
00718       }
00719     }
00720     
00721     // to have numbers from 0 to 17 for the EE feds and 0-36 for EB 
00722     int thisFed=-100;
00723     if (ecid_xt.getName()=="EE_crystal_number") {
00724       if (theFed>600 && theFed<610) thisFed = theFed -601;    
00725       if (theFed>645 && theFed<655) thisFed = theFed -646 + 9;    
00726     }
00727     if (ecid_xt.getName()=="EB_crystal_number") { thisFed = theFed - 610; }
00728 
00729     // in which light module I am
00730     int theTTieta =-100;
00731     int theTTiphi =-100;
00732     int theLM     =-100;
00733     if(ecid_xt.getName()=="EB_crystal_number") {
00734       theTTieta = (theTT-1)/4 +1;                
00735       theTTiphi = (theTT-1)%4 +1;
00736       if (theTTieta==1 ||  theTTiphi==3 || theTTiphi==4)  theLM=0;     // L-shaped
00737       if (theTTieta>1  && (theTTiphi==1 || theTTiphi==2)) theLM=1;     // not L-shaped
00738     }
00739     if( (ecid_xt.getName()=="EE_crystal_number") && (thisFed==7 || thisFed==16) ) {   
00740       if (theIx<=50) theLM=0;  
00741       if (theIx>50)  theLM=1;
00742     }
00743 
00744     // check if APD mean is bad
00745     uint16_t status_now = 0;
00746     rd_blue = p->second;
00747     float myApdMean = rd_blue.getAPDMean();
00748     
00749     if(ecid_xt.getName()=="EB_crystal_number") {
00750       if ( (myApdMean < 400) && isGoodLaserEBSm[thisFed][theLM] ) status_now = 2;      
00751     }    
00752 
00753     if(ecid_xt.getName()=="EE_crystal_number") {
00754       if ( myApdMean<100 ) {
00755         if (  thisFed!=7 && thisFed!=16  && isGoodLaserEESm[thisFed][0] )     status_now = 2;   
00756         if ( (thisFed==7 || thisFed==16) && isGoodLaserEESm[thisFed][theLM] ) status_now = 2;   
00757       }    
00758     }
00759 
00760     // output if problematic
00761     if (status_now>0) { 
00762       if(ecid_xt.getName()=="EB_crystal_number") {
00763         EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);        
00764         *ResFileEB << theFed  << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << myApdMean << std::endl;            
00765         
00766         // file with new problems only
00767         bool isOld=false;
00768         for(theIter=maskedLaserEB.begin(); theIter!=maskedLaserEB.end(); ++theIter) {
00769           if ((*theIter).first==ebdetid) isOld=true;
00770         }
00771         if (!isOld) { *ResFileNewEB << thisFed << "\t\t" << ebdetid.ic() << "\t\t" << ebdetid.hashedIndex() << "\t\t" << myApdMean << std::endl; }
00772         
00773       } else {      
00774         if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00775           EEDetId eedetid(xt_num,yt_num,sm_num);
00776           *ResFileEE << theFed        << "\t\t" << eedetid.ix()        << "\t\t" 
00777                      << eedetid.iy()  << "\t\t" << eedetid.zside()     << "\t\t" 
00778                      << eedetid.hashedIndex()   << "\t\t" << myApdMean << std::endl;
00779           
00780           // file with new problems only
00781           bool isOld=false;
00782           for(theIter=maskedLaserEE.begin(); theIter!=maskedLaserEE.end(); ++theIter) {
00783             if ((*theIter).first==eedetid) isOld=true;
00784           }
00785           if (!isOld) {
00786             *ResFileEE << theFed        << "\t\t" << eedetid.ix()        << "\t\t" 
00787                        << eedetid.iy()  << "\t\t" << eedetid.zside()     << "\t\t" 
00788                        << eedetid.hashedIndex()   << "\t\t" << myApdMean << std::endl; 
00789           }
00790         }       
00791       }      
00792     }
00793   }
00794 }
00795 
00796 
00797 
00798 // ------------------------------------------------------------
00799 //
00800 // COSMICS/PHYSICS ANALYSIS: infos from pedestal online, laser and occupancy analysis
00801 
00802 void popcon::EcalChannelStatusHandler::cosmicsAnalysis( std::map<EcalLogicID, MonPedestalsOnlineDat> pedestalO_mon, 
00803                                                         std::map<EcalLogicID, MonCrystalConsistencyDat> wrongGain_mon, 
00804                                                         std::map<EcalLogicID, MonLaserBlueDat> laser_mon, 
00805                                                         std::map<EcalLogicID, MonOccupancyDat> occupancy_mon ) { 
00806 
00807   // to take the list of masked crystals for the diffrent analyses
00808   pedOnlineMasking();
00809   laserMasking();
00810   physicsMasking();
00811   
00812   std::map<DetId,float>::const_iterator theIter;
00813   std::map<DetId, float> badPedOnEB,        badPedOnEE;
00814   std::map<DetId, float> badPedOnRmsEB,     badPedOnRmsEE;
00815   std::map<DetId, float> badGainEB,         badGainEE;
00816   std::map<DetId, float> badLaserEB,        badLaserEE;  
00817   std::map<DetId, float> badOccHighEB,      badOccHighEE;  
00818 
00819   typedef std::map<EcalLogicID, MonPedestalsOnlineDat>::const_iterator CImonPedO;  
00820   typedef std::map<EcalLogicID, MonCrystalConsistencyDat>::const_iterator CImonCons;
00821   typedef std::map<EcalLogicID, MonOccupancyDat>::const_iterator CImonOcc;
00822   typedef std::map<EcalLogicID, MonLaserBlueDat>::const_iterator CImonLaser;
00823   MonPedestalsOnlineDat    rd_ped0;  
00824   MonCrystalConsistencyDat rd_wgain;
00825   MonOccupancyDat          rd_occ;
00826   MonLaserBlueDat          rd_blue;
00827 
00828   // logic id
00829   EcalLogicID ecid_xt;
00830   
00831   // to be used after: total number of entries above high threshold 
00832   float totEntriesAboveHighThrEB=0.; 
00833   float totEntriesAboveHighThrEE=0.; 
00834   for (CImonOcc p=occupancy_mon.begin(); p!=occupancy_mon.end(); p++) {
00835     ecid_xt = p->first;
00836     rd_occ  = p->second;
00837     float highOcc=rd_occ.getEventsOverHighThreshold();
00838     if (ecid_xt.getName()=="EB_crystal_number" && highOcc>-1) totEntriesAboveHighThrEB = totEntriesAboveHighThrEB + highOcc;
00839     if (ecid_xt.getName()=="EE_crystal_number" && highOcc>-1) totEntriesAboveHighThrEE = totEntriesAboveHighThrEE + highOcc;
00840   }
00841 
00842 
00843   // A) creating the list of all bad channels: searching for problems based on pedestal online except gain zero
00844   for (CImonPedO p = pedestalO_mon.begin(); p != pedestalO_mon.end(); p++) {
00845     
00846     bool isWrong = false;
00847     ecid_xt = p->first;
00848     rd_ped0 = p->second;
00849     int sm_num=ecid_xt.getID1();
00850     int xt_num=ecid_xt.getID2(); 
00851     int yt_num=ecid_xt.getID3(); 
00852     
00853     EcalPedestals::Item ped_item;
00854     ped_item.mean_x12 = rd_ped0.getADCMeanG12();
00855     ped_item.rms_x12  = rd_ped0.getADCRMSG12();
00856     
00857     float lowerCut=999.;
00858     if(ecid_xt.getName()=="EB_crystal_number") { lowerCut = 2.0; }
00859     if(ecid_xt.getName()=="EE_crystal_number") { lowerCut = 2.5; }
00860     if ( checkPedestalRMSGain12(&ped_item)>lowerCut ) isWrong = true;
00861     if ( checkPedestalValueGain12(&ped_item)>300 )    isWrong = true;   
00862     if ( checkPedestalValueGain12(&ped_item)<100 )    isWrong = true;
00863     if ( checkPedestalRMSGain12(&ped_item)==0 )       isWrong = true;      
00864 
00865     // is this channel already in the list?
00866     if (isWrong) { 
00867       if(ecid_xt.getName()=="EB_crystal_number") {
00868         EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);        
00869         theIter = badPedOnEB.find(ebdetid);
00870         if (theIter==badPedOnEB.end()) {
00871           badPedOnEB.insert   (std::pair<DetId, float>(ebdetid, rd_ped0.getADCMeanG12()));
00872           badPedOnRmsEB.insert(std::pair<DetId, float>(ebdetid, rd_ped0.getADCRMSG12()));         
00873         }
00874       } else {      
00875         if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00876           EEDetId eedetid(xt_num,yt_num,sm_num);
00877           theIter = badPedOnEE.find(eedetid);
00878           if (theIter==badPedOnEE.end()) {   
00879             badPedOnEE.insert   (std::pair<DetId, float>(eedetid, rd_ped0.getADCMeanG12()));
00880             badPedOnRmsEE.insert(std::pair<DetId, float>(eedetid, rd_ped0.getADCRMSG12()));       
00881           }
00882         }
00883       }    
00884     }
00885   }
00886 
00887 
00888   // B) creating the list of all bad channels: searching for channels at gain zero at least in 100 events
00889   for (CImonCons p = wrongGain_mon.begin(); p != wrongGain_mon.end(); p++) {
00890     
00891     bool isWrong = false;
00892     ecid_xt    = p->first;
00893     rd_wgain   = p->second;
00894     int sm_num = ecid_xt.getID1();
00895     int xt_num = ecid_xt.getID2(); 
00896     int yt_num = ecid_xt.getID3(); 
00897     
00898     if (rd_wgain.getProblemsGainZero() > 1000) {isWrong = true; }
00899     
00900     if (isWrong) { 
00901       if(ecid_xt.getName()=="EB_crystal_number") {
00902         EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);        
00903         theIter = badGainEB.find(ebdetid);
00904         if (theIter==badGainEB.end()) badGainEB.insert(std::pair<DetId, float>(ebdetid, 999.));
00905       } else {      
00906         if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00907           EEDetId eedetid(xt_num,yt_num,sm_num);
00908           theIter = badGainEE.find(eedetid);
00909           if (theIter==badGainEE.end()) badGainEE.insert(std::pair<DetId, float>(eedetid, 999.));         
00910         }    
00911       }
00912     }
00913   }
00914 
00915 
00916   // C) creating the list of all bad channels: searching for channels with bad occupancy [ too high ]
00917   for (CImonOcc p=occupancy_mon.begin(); p!=occupancy_mon.end(); p++) {
00918     
00919     // logic id
00920     ecid_xt = p->first;
00921     int sm_num = ecid_xt.getID1();
00922     int xt_num = ecid_xt.getID2(); 
00923     int yt_num = ecid_xt.getID3(); 
00924 
00925     // occupancy
00926     rd_occ = p->second;    
00927 
00928     bool isWrong = false;
00929     float occAvg = -999.;
00930     if ( ecid_xt.getName()=="EB_crystal_number" ) { 
00931       occAvg = rd_occ.getEventsOverHighThreshold()/totEntriesAboveHighThrEB;
00932       if (occAvg>0.001) isWrong=true;  
00933     }
00934     if ( ecid_xt.getName()=="EE_crystal_number" ) { 
00935       occAvg = rd_occ.getEventsOverHighThreshold()/totEntriesAboveHighThrEE;
00936       if (occAvg>0.001) isWrong=true;  
00937     }
00938 
00939     if (isWrong) { 
00940       if(ecid_xt.getName()=="EB_crystal_number") {
00941         EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);        
00942         theIter = badOccHighEB.find(ebdetid);
00943         if (theIter==badOccHighEB.end()) badOccHighEB.insert(std::pair<DetId, float>(ebdetid, occAvg));
00944       } else {      
00945         if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00946           EEDetId eedetid(xt_num,yt_num,sm_num);
00947           theIter = badOccHighEE.find(eedetid);
00948           if (theIter==badOccHighEE.end()) badOccHighEE.insert(std::pair<DetId, float>(eedetid, occAvg));
00949         }
00950       }    
00951     }
00952   }
00953 
00954 
00955   // D) creating the list of all bad channels: searching for channels with bad laser amplitude [among those covered by the calibration sequence]
00956   for (CImonLaser p=laser_mon.begin(); p!=laser_mon.end(); p++) {
00957 
00958     // logic id
00959     ecid_xt    = p->first;
00960     int sm_num = ecid_xt.getID1();
00961     int xt_num = ecid_xt.getID2(); 
00962     int yt_num = ecid_xt.getID3(); 
00963     
00964     // in which Fed/triggerTower/sectorSide I am
00965     int theFed = -100;
00966     int theTT  = -100; 
00967     int theIx  = -100;
00968     if(ecid_xt.getName()=="EB_crystal_number") {
00969       EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);          
00970       EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
00971       theFed = 600+elecId.dccId();
00972       theTT  = elecId.towerId();   
00973     }   
00974     if(ecid_xt.getName()=="EE_crystal_number") {   
00975       if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
00976         EEDetId eedetid(xt_num,yt_num,sm_num);
00977         EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
00978         theFed = 600+elecId.dccId();
00979         theIx  = eedetid.ix(); 
00980       }
00981     }
00982     
00983     // to have numbers from 0 to 17 for the EE feds and 0-36 for EB 
00984     int thisFed=-100;
00985     if (ecid_xt.getName()=="EE_crystal_number") {
00986       if (theFed>600 && theFed<610) thisFed = theFed -601;    
00987       if (theFed>645 && theFed<655) thisFed = theFed -646 + 9;    
00988     }
00989     if (ecid_xt.getName()=="EB_crystal_number") { thisFed = theFed - 610; }
00990 
00991     // in which light module I am
00992     int theTTieta =-100;
00993     int theTTiphi =-100;
00994     int theLM     =-100;
00995     if(ecid_xt.getName()=="EB_crystal_number") {
00996       theTTieta = (theTT-1)/4 +1;              
00997       theTTiphi = (theTT-1)%4 +1;
00998       if (theTTieta==1 ||  theTTiphi==3 || theTTiphi==4)  theLM=0;     // L-shaped
00999       if (theTTieta>1  && (theTTiphi==1 || theTTiphi==2)) theLM=1;     // not L-shaped
01000     }
01001     if( (ecid_xt.getName()=="EE_crystal_number") && (thisFed==7 || thisFed==16) ) {   
01002       if (theIx<=50) theLM=0;  
01003       if (theIx>50)  theLM=1;
01004     }
01005     
01006     // APD mean value
01007     rd_blue = p->second;
01008     float myApdMean = rd_blue.getAPDMean();
01009     
01010     bool isWrong = false;
01011     if(ecid_xt.getName()=="EB_crystal_number") {
01012       if ( (myApdMean < 400) && isGoodLaserEBSm[thisFed][theLM] ) isWrong=true;
01013     }        
01014     if(ecid_xt.getName()=="EE_crystal_number") {
01015       if ( myApdMean<100 ) {
01016         if (  thisFed!=7 && thisFed!=16  && isGoodLaserEESm[thisFed][0] )     isWrong=true;
01017         if ( (thisFed==7 || thisFed==16) && isGoodLaserEESm[thisFed][theLM] ) isWrong=true;
01018       }    
01019     }
01020     
01021     if (isWrong) { 
01022       if(ecid_xt.getName()=="EB_crystal_number") {
01023         EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);        
01024         theIter = badLaserEB.find(ebdetid);
01025         if (theIter==badLaserEB.end()) badLaserEB.insert(std::pair<DetId, float>(ebdetid, myApdMean));
01026       } else {      
01027         if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
01028           EEDetId eedetid(xt_num,yt_num,sm_num);
01029           theIter = badLaserEE.find(eedetid);
01030           if (theIter==badLaserEE.end()) badLaserEE.insert(std::pair<DetId, float>(eedetid, myApdMean));
01031         }
01032       }    
01033     } 
01034   }
01035 
01036 
01037   // check if the crystal is in the vector and fill the summary file
01038   std::map<DetId, float>::const_iterator theIterPedOn;
01039   std::map<DetId, float>::const_iterator theIterPedOnRms;
01040   std::map<DetId, float>::const_iterator theIterGain;
01041   std::map<DetId, float>::const_iterator theIterLaser;
01042   std::map<DetId, float>::const_iterator theIterOccHigh;
01043 
01044 
01045   // EB, first check - loop over pedestal online
01046   for(theIterPedOn=badPedOnEB.begin(); theIterPedOn!=badPedOnEB.end(); ++theIterPedOn) {
01047     float thePedOn    = (*theIterPedOn).second;
01048     float thePedOnRms = 9999.;
01049     float theGain     = 9999.;
01050     float theLaser    = 9999.;
01051     float theOccHigh  = 9999.;
01052 
01053     theIterPedOnRms = badPedOnRmsEB.find((*theIterPedOn).first);
01054     theIterGain     = badGainEB.find    ((*theIterPedOn).first);
01055     theIterLaser    = badLaserEB.find   ((*theIterPedOn).first);
01056     theIterOccHigh  = badOccHighEB.find ((*theIterPedOn).first);
01057 
01058     if (theIterPedOnRms!=badPedOnRmsEB.end()) thePedOnRms = (*theIterPedOnRms).second;
01059     if (theIterLaser!=badLaserEB.end())       theLaser    = (*theIterLaser).second;
01060     if (theIterOccHigh!=badOccHighEB.end())   theOccHigh  = (*theIterOccHigh).second;
01061     
01062     int thisFed=-100;
01063     EBDetId ebdetid((*theIterPedOn).first);
01064     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
01065     thisFed = 600+elecId.dccId();
01066 
01067     // new problems only
01068     bool isNew=false;
01069     bool isNewPed=true;
01070     bool isNewLaser=true;
01071     bool isNewPhysics=true;
01072     for(theIter=maskedOnlinePedEB.begin(); theIter!=maskedOnlinePedEB.end(); ++theIter) { if ((*theIter).first==ebdetid) isNewPed=false; }
01073 
01074     for(theIter=maskedLaserEB.begin();     theIter!=maskedLaserEB.end(); ++theIter)     { if ((*theIter).first==ebdetid) isNewLaser=false; }
01075 
01076     for(theIter=maskedPhysicsEB.begin();   theIter!=maskedPhysicsEB.end(); ++theIter)   { if ((*theIter).first==ebdetid) isNewPhysics=false; }
01077 
01078     if ( isNewPed || (theLaser!=9999 && isNewLaser) || (theOccHigh!=9999 && isNewPhysics) ) isNew=true;
01079       
01080     if (theIterGain!=badGainEB.end()) {
01081       *ResFileEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"               
01082                  << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01083                  << "gainZero"  << "\t\t" << theLaser         << "\t\t" 
01084                  << theOccHigh  << std::endl;
01085       
01086       if (isNew) { 
01087         *ResFileNewEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"                  
01088                       << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01089                       << "gainZero"  << "\t\t" << theLaser         << "\t\t" 
01090                       << theOccHigh  << std::endl;
01091         
01092         float thisEtaFill=float(0);
01093         if (ebdetid.ieta()>0) thisEtaFill = ebdetid.ieta() - 0.5;
01094         if (ebdetid.ieta()<0) thisEtaFill = ebdetid.ieta();
01095         newBadEB_ -> Fill( (ebdetid.iphi()-0.5), thisEtaFill, 2);
01096       }
01097     } else {
01098       *ResFileEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"               
01099                  << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01100                  << theGain     << "\t\t" << theLaser         << "\t\t" 
01101                  << theOccHigh  << std::endl;
01102       
01103       if (isNew) { 
01104         *ResFileNewEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"                  
01105                       << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01106                       << theGain     << "\t\t" << theLaser         << "\t\t" 
01107                       << theOccHigh  << std::endl;
01108 
01109         float thisEtaFill=float(0);
01110         if (ebdetid.ieta()>0) thisEtaFill = ebdetid.ieta() - 0.5;
01111         if (ebdetid.ieta()<0) thisEtaFill = ebdetid.ieta();
01112         newBadEB_ -> Fill( (ebdetid.iphi()-0.5), thisEtaFill, 2);
01113       } 
01114     }
01115   }
01116   
01117 
01118 
01119   // EB, second check - loop over laser
01120   for(theIterLaser=badLaserEB.begin(); theIterLaser!=badLaserEB.end(); ++theIterLaser) {
01121 
01122     // remove already included channels
01123     theIterPedOnRms = badPedOnRmsEB.find((*theIterLaser).first);
01124     if (theIterPedOnRms!=badPedOnRmsEB.end()) continue; 
01125 
01126     float thePedOn    = 9999.;
01127     float thePedOnRms = 9999.;
01128     float theGain     = 9999.;
01129     float theLaser    = (*theIterLaser).second;
01130     float theOccHigh  = 9999.;
01131     
01132     theIterGain     = badGainEB.find    ((*theIterLaser).first);
01133     theIterOccHigh  = badOccHighEB.find ((*theIterLaser).first);
01134     if (theIterOccHigh!=badOccHighEB.end()) theOccHigh = (*theIterOccHigh).second;
01135     
01136     int thisFed=-100;
01137     EBDetId ebdetid((*theIterLaser).first);
01138     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
01139     thisFed = 600+elecId.dccId();
01140 
01141     // new problems only
01142     bool isNew=false;
01143     bool isNewPed=true;
01144     bool isNewLaser=true;
01145     bool isNewPhysics=true;
01146     for(theIter=maskedOnlinePedEB.begin(); theIter!=maskedOnlinePedEB.end(); ++theIter) { if ((*theIter).first==ebdetid) isNewPed=false; }
01147 
01148     for(theIter=maskedLaserEB.begin();     theIter!=maskedLaserEB.end();     ++theIter) { if ((*theIter).first==ebdetid) isNewLaser=false; }
01149 
01150     for(theIter=maskedPhysicsEB.begin();   theIter!=maskedPhysicsEB.end();   ++theIter) { if ((*theIter).first==ebdetid) isNewPhysics=false; }
01151 
01152     if ( (isNewPed && theIterGain!=badGainEB.end() ) || (isNewLaser) || (theOccHigh!=9999 && isNewPhysics) ) isNew=true;
01153         
01154     if (theIterGain!=badGainEB.end()) {
01155       *ResFileEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"               
01156                  << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01157                  << "gainZero"  << "\t\t" << theLaser         << "\t\t" 
01158                  << theOccHigh  << std::endl;
01159 
01160       if (isNew) { 
01161         *ResFileNewEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"                  
01162                       << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01163                       << "gainZero"  << "\t\t" << theLaser         << "\t\t" 
01164                       << theOccHigh  << std::endl;
01165 
01166         float thisEtaFill=float(0);
01167         if (ebdetid.ieta()>0) thisEtaFill = ebdetid.ieta() - 0.5;
01168         if (ebdetid.ieta()<0) thisEtaFill = ebdetid.ieta();
01169         newBadEB_ -> Fill( (ebdetid.iphi()-0.5), thisEtaFill, 2);
01170       }
01171     } else {
01172       *ResFileEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"               
01173                  << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01174                  << theGain     << "\t\t" << theLaser         << "\t\t" 
01175                  << theOccHigh  << std::endl;
01176       
01177       if (isNew) { 
01178         *ResFileNewEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"                  
01179                       << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01180                       << theGain     << "\t\t" << theLaser         << "\t\t" 
01181                       << theOccHigh  << std::endl;
01182 
01183         float thisEtaFill=float(0);
01184         if (ebdetid.ieta()>0) thisEtaFill = ebdetid.ieta() - 0.5;
01185         if (ebdetid.ieta()<0) thisEtaFill = ebdetid.ieta();
01186         newBadEB_ -> Fill( (ebdetid.iphi()-0.5), thisEtaFill, 2);
01187       }
01188     } 
01189   }
01190   
01191 
01192   // EB, third check: loop over occupancy
01193   for(theIterOccHigh = badOccHighEB.begin(); theIterOccHigh != badOccHighEB.end(); ++theIterOccHigh) {
01194 
01195     // remove already included  channels
01196     theIterPedOnRms = badPedOnRmsEB.find((*theIterOccHigh).first);
01197     theIterLaser    = badLaserEB.find   ((*theIterOccHigh).first);
01198     if (theIterPedOnRms!=badPedOnRmsEB.end()) continue; 
01199     if (theIterLaser!=badLaserEB.end())       continue; 
01200 
01201     float thePedOn    = 9999.;
01202     float thePedOnRms = 9999.;
01203     float theGain     = 9999.;
01204     float theLaser    = 9999.;
01205     float theOccHigh  = (*theIterOccHigh).second;
01206     theIterGain   = badGainEB.find  ((*theIterOccHigh).first);
01207     
01208     int thisFed=-100;
01209     EBDetId ebdetid((*theIterOccHigh).first);
01210     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
01211     thisFed = 600+elecId.dccId();
01212     
01213     // new problems only
01214     bool isNew=false;
01215     bool isNewPed=true;
01216     bool isNewPhysics=true;
01217     for(theIter=maskedOnlinePedEB.begin(); theIter!=maskedOnlinePedEB.end(); ++theIter) { if ((*theIter).first==ebdetid) isNewPed=false; }
01218 
01219     for(theIter=maskedPhysicsEB.begin();   theIter!=maskedPhysicsEB.end();   ++theIter) { if ((*theIter).first==ebdetid) isNewPhysics=false; }
01220 
01221     if ( (isNewPed && theIterGain!=badGainEB.end() ) || (isNewPhysics) ) isNew=true;
01222     
01223     if (theIterGain!=badGainEB.end()) {
01224       *ResFileEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"               
01225                  << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01226                  << "gainZero"  << "\t\t" << theLaser         << "\t\t" 
01227                  << theOccHigh  << std::endl;
01228       
01229       if (isNew) { 
01230         *ResFileNewEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"                  
01231                       << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01232                       << "gainZero"  << "\t\t" << theLaser         << "\t\t" 
01233                       << theOccHigh  << std::endl;
01234 
01235         float thisEtaFill=float(0);
01236         if (ebdetid.ieta()>0) thisEtaFill = ebdetid.ieta() - 0.5;
01237         if (ebdetid.ieta()<0) thisEtaFill = ebdetid.ieta();
01238         newBadEB_ -> Fill( (ebdetid.iphi()-0.5), thisEtaFill, 2);
01239       }
01240     } else {
01241       *ResFileEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"               
01242                  << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01243                  << theGain     << "\t\t" << theLaser         << "\t\t" 
01244                  << theOccHigh  << std::endl;
01245       
01246       if (isNew) { 
01247         *ResFileNewEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"                  
01248                       << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01249                       << theGain     << "\t\t" << theLaser         << "\t\t" 
01250                       << theOccHigh  << std::endl;
01251 
01252         float thisEtaFill=float(0);
01253         if (ebdetid.ieta()>0) thisEtaFill = ebdetid.ieta() - 0.5;
01254         if (ebdetid.ieta()<0) thisEtaFill = ebdetid.ieta();
01255         newBadEB_ -> Fill( (ebdetid.iphi()-0.5), thisEtaFill, 2);
01256       } 
01257     }
01258   }
01259   
01260   // EB, fourth check: loop over consistency
01261   for(theIterGain = badGainEB.begin(); theIterGain != badGainEB.end(); ++theIterGain) {
01262     
01263     // remove already included  channels
01264     theIterPedOnRms = badPedOnRmsEB.find((*theIterGain).first);
01265     theIterLaser    = badLaserEB.find   ((*theIterGain).first);
01266     theIterOccHigh  = badOccHighEB.find ((*theIterGain).first);
01267     if (theIterPedOnRms!=badPedOnRmsEB.end()) continue; 
01268     if (theIterLaser!=badLaserEB.end())       continue; 
01269     if (theIterOccHigh!=badOccHighEB.end())   continue;
01270     
01271     float thePedOn    = 9999.;
01272     float thePedOnRms = 9999.;
01273     float theLaser    = 9999.;
01274     float theOccHigh  = 9999.;
01275     
01276     int thisFed=-100;
01277     EBDetId ebdetid((*theIterGain).first);
01278     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(ebdetid);
01279     thisFed = 600+elecId.dccId();
01280 
01281     // new problems only
01282     bool isNew=false;
01283     bool isNewPed=true;
01284     for(theIter=maskedOnlinePedEB.begin(); theIter!=maskedOnlinePedEB.end(); ++theIter) { if ((*theIter).first==ebdetid) isNewPed=false; }
01285 
01286     if ( isNewPed && theIterGain!=badGainEB.end() ) isNew=true;
01287     
01288     *ResFileEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"                 
01289                << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01290                << "gainZero"  << "\t\t" << theLaser         << "\t\t" 
01291                << theOccHigh  << std::endl;
01292     
01293     if (isNew) { 
01294       *ResFileNewEB << thisFed     << "\t\t" << ebdetid.ic()     << "\t\t" << ebdetid.hashedIndex() << "\t\t"            
01295                     << thePedOn    << "\t\t" << thePedOnRms      << "\t\t" 
01296                     << "gainZero"  << "\t\t" << theLaser         << "\t\t" 
01297                     << theOccHigh  << std::endl;
01298 
01299       float thisEtaFill=float(0);
01300       if (ebdetid.ieta()>0) thisEtaFill = ebdetid.ieta() - 0.5;
01301       if (ebdetid.ieta()<0) thisEtaFill = ebdetid.ieta();
01302       newBadEB_ -> Fill( (ebdetid.iphi()-0.5), thisEtaFill, 2);
01303     }
01304   } 
01305 
01306   
01307   // EE, first check: loop over pedestal online
01308   for(theIterPedOn = badPedOnEE.begin(); theIterPedOn != badPedOnEE.end(); ++theIterPedOn) {
01309 
01310     float thePedOn    = (*theIterPedOn).second;
01311     float thePedOnRms = 9999.;
01312     float theGain     = 9999.;
01313     float theLaser    = 9999.;
01314     float theOccHigh  = 9999.;
01315 
01316     theIterPedOnRms = badPedOnRmsEE.find((*theIterPedOn).first);
01317     theIterGain     = badGainEE.find    ((*theIterPedOn).first);
01318     theIterLaser    = badLaserEE.find   ((*theIterPedOn).first);
01319     theIterOccHigh  = badOccHighEE.find ((*theIterPedOn).first);
01320 
01321     if (theIterPedOnRms!=badPedOnRmsEE.end()) thePedOnRms = (*theIterPedOnRms).second;
01322     if (theIterLaser   !=badLaserEE.end())    theLaser    = (*theIterLaser).second;
01323     if (theIterOccHigh !=badOccHighEE.end())  theOccHigh  = (*theIterOccHigh).second;
01324     
01325     int thisFed=-100;
01326     EEDetId eedetid((*theIterPedOn).first);
01327     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
01328     thisFed = 600+elecId.dccId();
01329 
01330     // new problems only
01331     bool isNew=false;
01332     bool isNewPed=true;
01333     bool isNewLaser=true;
01334     bool isNewPhysics=true;
01335     for(theIter=maskedOnlinePedEE.begin(); theIter!=maskedOnlinePedEE.end(); ++theIter) { if ((*theIter).first==eedetid) isNewPed=false; }
01336 
01337     for(theIter=maskedLaserEE.begin();     theIter!=maskedLaserEE.end();     ++theIter) { if ((*theIter).first==eedetid) isNewLaser=false; }
01338       
01339     for(theIter=maskedPhysicsEE.begin();   theIter!=maskedPhysicsEE.end();   ++theIter) { if ((*theIter).first==eedetid) isNewPhysics=false; }
01340       
01341     if ( isNewPed || (theLaser!=9999 && isNewLaser) || (theOccHigh!=9999 && isNewPhysics) ) isNew=true;
01342     
01343     if (theIterGain!=badGainEE.end()) {
01344       *ResFileEE << thisFed                << "\t\t" << eedetid.ix()     << "\t\t" 
01345                  << eedetid.iy()           << "\t\t" << eedetid.zside()  << "\t\t" 
01346                  << eedetid.hashedIndex()  << "\t\t"                 
01347                  << thePedOn               << "\t\t" << thePedOnRms      << "\t\t" 
01348                  << "gainZero"             << "\t\t" << theLaser         << "\t\t" 
01349                  << theOccHigh             << std::endl;
01350 
01351       if (isNew) {
01352         *ResFileNewEE << thisFed                << "\t\t" << eedetid.ix()     << "\t\t" 
01353                       << eedetid.iy()           << "\t\t" << eedetid.zside()  << "\t\t" 
01354                       << eedetid.hashedIndex()  << "\t\t"                    
01355                       << thePedOn               << "\t\t" << thePedOnRms      << "\t\t" 
01356                       << "gainZero"             << "\t\t" << theLaser         << "\t\t" 
01357                       << theOccHigh             << std::endl;
01358 
01359         if (eedetid.zside()>0) newBadEEP_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01360         if (eedetid.zside()<0) newBadEEM_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01361       }
01362     } else {
01363       *ResFileEE << thisFed                << "\t\t" << eedetid.ix()     << "\t\t" 
01364                  << eedetid.iy()           << "\t\t" << eedetid.zside()  << "\t\t" 
01365                  << eedetid.hashedIndex()  << "\t\t"                 
01366                  << thePedOn               << "\t\t" << thePedOnRms      << "\t\t" 
01367                  << theGain                << "\t\t" << theLaser         << "\t\t" 
01368                  << theOccHigh             << std::endl;
01369 
01370       if (isNew) {
01371         *ResFileNewEE << thisFed                << "\t\t" << eedetid.ix()     << "\t\t" 
01372                       << eedetid.iy()           << "\t\t" << eedetid.zside()  << "\t\t" 
01373                       << eedetid.hashedIndex()  << "\t\t"                    
01374                       << thePedOn               << "\t\t" << thePedOnRms      << "\t\t" 
01375                       << theGain                << "\t\t" << theLaser         << "\t\t" 
01376                       << theOccHigh             << std::endl;
01377         
01378         if (eedetid.zside()>0) newBadEEP_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01379         if (eedetid.zside()<0) newBadEEM_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01380       }
01381     } 
01382   }
01383   
01384   
01385   // EE, second check: loop over laser
01386   for(theIterLaser = badLaserEE.begin(); theIterLaser != badLaserEE.end(); ++theIterLaser) {
01387 
01388     // remove already included  channels
01389     theIterPedOnRms = badPedOnRmsEE.find((*theIterLaser).first);
01390     if (theIterPedOnRms!=badPedOnRmsEE.end()) continue; 
01391 
01392     float thePedOn    = 9999.;
01393     float thePedOnRms = 9999.;
01394     float theGain     = 9999.;
01395     float theLaser    = (*theIterLaser).second;
01396     float theOccHigh  = 9999.;
01397     
01398     theIterGain     = badGainEE.find    ((*theIterLaser).first);
01399     theIterOccHigh  = badOccHighEE.find ((*theIterLaser).first);
01400     if (theIterOccHigh!=badOccHighEE.end()) theOccHigh = (*theIterOccHigh).second;
01401     
01402     int thisFed=-100;
01403     EEDetId eedetid((*theIterLaser).first);
01404     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
01405     thisFed = 600+elecId.dccId();
01406     
01407     // new problems only
01408     bool isNew=false;
01409     bool isNewPed=true;
01410     bool isNewLaser=true;
01411     bool isNewPhysics=true;
01412     for(theIter=maskedOnlinePedEE.begin(); theIter!=maskedOnlinePedEE.end(); ++theIter) { if ((*theIter).first==eedetid) isNewPed=false; }
01413       
01414     for(theIter=maskedLaserEE.begin();     theIter!=maskedLaserEE.end();     ++theIter) { if ((*theIter).first==eedetid) isNewLaser=false; }
01415       
01416     for(theIter=maskedPhysicsEE.begin();   theIter!=maskedPhysicsEE.end();   ++theIter) { if ((*theIter).first==eedetid) isNewPhysics=false; }
01417 
01418     if ( (isNewPed && theIterGain!=badGainEE.end() ) || (isNewLaser) || (theOccHigh!=9999 && isNewPhysics) ) isNew=true;
01419     
01420     if (theIterGain!=badGainEE.end()) {
01421       *ResFileEE << thisFed      << "\t\t" << eedetid.ix()     << "\t\t"    
01422                  << eedetid.iy() << "\t\t" << eedetid.zside()  << "\t\t"       
01423                  << eedetid.hashedIndex()  << "\t\t"             
01424                  << thePedOn     << "\t\t" << thePedOnRms      << "\t\t" 
01425                  << "gainZero"   << "\t\t" << theLaser         << "\t\t" 
01426                  << theOccHigh   << std::endl;
01427 
01428       if (isNew) { 
01429         *ResFileNewEE << thisFed      << "\t\t" << eedetid.ix()     << "\t\t"    
01430                       << eedetid.iy() << "\t\t" << eedetid.zside()  << "\t\t"       
01431                       << eedetid.hashedIndex()  << "\t\t"                
01432                       << thePedOn     << "\t\t" << thePedOnRms      << "\t\t" 
01433                       << "gainZero"   << "\t\t" << theLaser         << "\t\t" 
01434                       << theOccHigh   << std::endl;
01435 
01436         if (eedetid.zside()>0) newBadEEP_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01437         if (eedetid.zside()<0) newBadEEM_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01438       }
01439     } else {
01440       *ResFileEE << thisFed      << "\t\t" << eedetid.ix()     << "\t\t"    
01441                  << eedetid.iy() << "\t\t" << eedetid.zside()  << "\t\t"       
01442                  << eedetid.hashedIndex()  << "\t\t"             
01443                  << thePedOn     << "\t\t" << thePedOnRms      << "\t\t" 
01444                  << theGain      << "\t\t" << theLaser         << "\t\t" 
01445                  << theOccHigh   << std::endl;
01446 
01447       if (isNew) { 
01448         *ResFileNewEE << thisFed      << "\t\t" << eedetid.ix()     << "\t\t"    
01449                       << eedetid.iy() << "\t\t" << eedetid.zside()  << "\t\t"       
01450                       << eedetid.hashedIndex()  << "\t\t"                
01451                       << thePedOn     << "\t\t" << thePedOnRms      << "\t\t" 
01452                       << theGain      << "\t\t" << theLaser         << "\t\t" 
01453                       << theOccHigh   << std::endl;
01454 
01455         if (eedetid.zside()>0) newBadEEP_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01456         if (eedetid.zside()<0) newBadEEM_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01457       }
01458     } 
01459   }
01460 
01461 
01462   // third check: loop over occupancy
01463   for(theIterOccHigh = badOccHighEE.begin(); theIterOccHigh != badOccHighEE.end(); ++theIterOccHigh) {
01464 
01465     // remove already included  channels
01466     theIterPedOnRms = badPedOnRmsEE.find((*theIterOccHigh).first);
01467     theIterLaser    = badLaserEE.find   ((*theIterOccHigh).first);
01468     if (theIterPedOnRms!=badPedOnRmsEE.end()) continue; 
01469     if (theIterLaser!=badLaserEE.end())       continue; 
01470 
01471     float thePedOn    = 9999.;
01472     float thePedOnRms = 9999.;
01473     float theGain     = 9999.;
01474     float theLaser    = 9999.;
01475     float theOccHigh  = (*theIterOccHigh).second;
01476     theIterGain    = badGainEE.find  ((*theIterOccHigh).first);
01477     
01478     int thisFed=-100;
01479     EEDetId eedetid((*theIterOccHigh).first);
01480     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
01481     thisFed = 600+elecId.dccId();
01482     
01483     // new problems only
01484     bool isNew=false;
01485     bool isNewPed=true;
01486     bool isNewPhysics=true;
01487     for(theIter=maskedOnlinePedEE.begin(); theIter!=maskedOnlinePedEE.end(); ++theIter) { if ((*theIter).first==eedetid) isNewPed=false; }
01488 
01489     for(theIter=maskedPhysicsEE.begin();   theIter!=maskedPhysicsEE.end();   ++theIter) { if ((*theIter).first==eedetid) isNewPhysics=false; }
01490       
01491     if ( (isNewPed && theIterGain!=badGainEE.end() ) || (isNewPhysics) ) isNew=true;
01492 
01493     if (theIterGain!=badGainEE.end()) {
01494       *ResFileEE << thisFed      << "\t\t" << eedetid.ix()     << "\t\t"    
01495                  << eedetid.iy() << "\t\t" << eedetid.zside()  << "\t\t"       
01496                  << eedetid.hashedIndex()  << "\t\t"             
01497                  << thePedOn     << "\t\t" << thePedOnRms      << "\t\t" 
01498                  << "gainZero"   << "\t\t" << theLaser         << "\t\t" 
01499                  << theOccHigh   << std::endl;
01500 
01501       if (isNew) { 
01502         *ResFileNewEE << thisFed      << "\t\t" << eedetid.ix()     << "\t\t"    
01503                       << eedetid.iy() << "\t\t" << eedetid.zside()  << "\t\t"       
01504                       << eedetid.hashedIndex()  << "\t\t"                
01505                       << thePedOn     << "\t\t" << thePedOnRms      << "\t\t" 
01506                       << "gainZero"   << "\t\t" << theLaser         << "\t\t" 
01507                       << theOccHigh   << std::endl;
01508 
01509         if (eedetid.zside()>0) newBadEEP_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01510         if (eedetid.zside()<0) newBadEEM_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01511       }
01512     } else {
01513       *ResFileEE << thisFed      << "\t\t" << eedetid.ix()     << "\t\t"    
01514                  << eedetid.iy() << "\t\t" << eedetid.zside()  << "\t\t"       
01515                  << eedetid.hashedIndex()  << "\t\t"             
01516                  << thePedOn     << "\t\t" << thePedOnRms      << "\t\t" 
01517                  << theGain      << "\t\t" << theLaser         << "\t\t" 
01518                  << theOccHigh   << std::endl;
01519       
01520       if (isNew) { 
01521         *ResFileNewEE << thisFed      << "\t\t" << eedetid.ix()     << "\t\t"    
01522                       << eedetid.iy() << "\t\t" << eedetid.zside()  << "\t\t"       
01523                       << eedetid.hashedIndex()  << "\t\t"                
01524                       << thePedOn     << "\t\t" << thePedOnRms      << "\t\t" 
01525                       << theGain      << "\t\t" << theLaser         << "\t\t" 
01526                       << theOccHigh   << std::endl;
01527         
01528         if (eedetid.zside()>0) newBadEEP_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01529         if (eedetid.zside()<0) newBadEEM_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01530       } 
01531     }
01532   }
01533 
01534   // EE, fourth check: loop over consistency
01535   for(theIterGain = badGainEE.begin(); theIterGain != badGainEE.end(); ++theIterGain) {
01536     
01537     // remove already included  channels
01538     theIterPedOnRms = badPedOnRmsEE.find((*theIterGain).first);
01539     theIterLaser    = badLaserEE.find   ((*theIterGain).first);
01540     theIterOccHigh  = badOccHighEE.find ((*theIterGain).first);
01541     if (theIterPedOnRms!=badPedOnRmsEE.end()) continue; 
01542     if (theIterLaser!=badLaserEE.end())       continue; 
01543     if (theIterOccHigh!=badOccHighEE.end())   continue;    
01544     float thePedOn    = 9999.;
01545     float thePedOnRms = 9999.;
01546     float theLaser    = 9999.;
01547     float theOccHigh  = 9999.;
01548     
01549     int thisFed=-100;
01550     EEDetId eedetid((*theIterGain).first);
01551     EcalElectronicsId elecId = ecalElectronicsMap_.getElectronicsId(eedetid);
01552     thisFed = 600+elecId.dccId();
01553     
01554     // new problems only
01555     bool isNew=false;
01556     bool isNewPed=true;
01557     for(theIter=maskedOnlinePedEE.begin(); theIter!=maskedOnlinePedEE.end(); ++theIter) { if ((*theIter).first==eedetid) isNewPed=false; }
01558       
01559     if ( isNewPed && theIterGain!=badGainEE.end() ) isNew=true;
01560     
01561     *ResFileEE << thisFed      << "\t\t" << eedetid.ix()     << "\t\t"    
01562                << eedetid.iy() << "\t\t" << eedetid.zside()  << "\t\t"       
01563                << eedetid.hashedIndex()  << "\t\t"               
01564                << thePedOn     << "\t\t" << thePedOnRms      << "\t\t" 
01565                << "gainZero"   << "\t\t" << theLaser         << "\t\t" 
01566                << theOccHigh   << std::endl;
01567     
01568     if (isNew) { 
01569       *ResFileNewEE << thisFed      << "\t\t" << eedetid.ix()     << "\t\t"    
01570                     << eedetid.iy() << "\t\t" << eedetid.zside()  << "\t\t"       
01571                     << eedetid.hashedIndex()  << "\t\t"                  
01572                     << thePedOn     << "\t\t" << thePedOnRms      << "\t\t" 
01573                     << "gainZero"   << "\t\t" << theLaser         << "\t\t" 
01574                     << theOccHigh   << std::endl;
01575 
01576       if (eedetid.zside()>0) newBadEEP_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01577       if (eedetid.zside()<0) newBadEEM_ -> Fill( (eedetid.ix()-0.5), (eedetid.iy()-0.5), 4);
01578     }
01579   } 
01580 }
01581 
01582 
01583 
01584 
01585 // core of the work = analyzing runs
01586 void popcon::EcalChannelStatusHandler::getNewObjects() {
01587   
01588   std::ostringstream ss; 
01589   ss << "ECAL ";
01590 
01591   // here we retrieve all the runs of a given type after the last from online DB   
01592   unsigned int max_since=0;
01593   max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
01594   std::cout << "max_since : "  << max_since << std::endl;
01595 
01596   std::cout << "Retrieving run list from ONLINE DB ... " << std::endl;
01597   econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
01598   std::cout << "Connection done" << std::endl;
01599   
01600   if (!econn) { 
01601     std::cout << " Problem with OMDS: connection parameters " << m_sid << "/" << m_user << "/" << m_pass << std::endl;
01602     throw cms::Exception("OMDS not available");
01603   } 
01604 
01605   // histos
01606   newBadEB_  = new TProfile2D("newBadEB_",  "new bad channels, EB",  360, 0., 360., 170, -85.,  85.);
01607   newBadEEP_ = new TProfile2D("newBad_EEP_","new bad channels, EE+", 100, 0., 100., 100,   0., 100.);
01608   newBadEEM_ = new TProfile2D("newBad_EEM_","new bad channels, EE-", 100, 0., 100., 100,   0., 100.);
01609   
01610   // these are the online conditions DB classes 
01611   RunList my_runlist ;
01612   RunTag  my_runtag;
01613   LocationDef my_locdef;
01614   RunTypeDef my_rundef;
01615   my_locdef.setLocation(m_location);
01616   my_rundef.setRunType(m_runtype);  
01617   my_runtag.setLocationDef(my_locdef);
01618   my_runtag.setRunTypeDef(my_rundef);
01619   my_runtag.setGeneralTag(m_gentag);   
01620   
01621 
01622   // range of validity
01623   unsigned int min_run=0;
01624   if(m_firstRun<max_since) {
01625     min_run=max_since+1;    // we have to add 1 to the last transferred one
01626   } else { min_run=m_firstRun; }
01627   unsigned int max_run=m_lastRun;
01628 
01629   
01630   // here we retrieve the Monitoring run records  
01631   MonVersionDef monverdef;
01632   monverdef.setMonitoringVersion("test01");
01633   MonRunTag mon_tag;
01634   // if (m_runtype=="PEDESTAL") mon_tag.setGeneralTag("CMSSW");        
01635   // if (m_runtype=="LASER")    mon_tag.setGeneralTag("CMSSW");        
01636   // if (m_runtype=="COSMIC" || m_runtype=="BEAM" || m_runtype=="PHYSICS" || m_runtype=="HALO" || m_runtype=="GLOBAL_COSMICS" ) mon_tag.setGeneralTag("CMSSW-online");        
01637   if (m_runtype=="PEDESTAL") mon_tag.setGeneralTag("CMSSW-offline-private");        
01638   if (m_runtype=="LASER")    mon_tag.setGeneralTag("CMSSW-offline-private");        
01639   if (m_runtype=="COSMIC" || m_runtype=="BEAM" || m_runtype=="PHYSICS" || m_runtype=="HALO" || m_runtype=="GLOBAL_COSMICS" ) mon_tag.setGeneralTag("CMSSW-online-private");        
01640   mon_tag.setMonVersionDef(monverdef);
01641   MonRunList mon_list;
01642   mon_list.setMonRunTag(mon_tag);
01643   mon_list.setRunTag(my_runtag);
01644   mon_list = econn->fetchMonRunList(my_runtag, mon_tag, min_run, max_run );
01645   
01646 
01647 
01648   // ----------------------------------------------------------------
01649   // preparing the output files
01650   char outfile[800];
01651   sprintf(outfile,"BadChannelsEB_run%d.txt",min_run);
01652   ResFileEB    = new ofstream(outfile,std::ios::out);
01653   sprintf(outfile,"BadChannelsEE_run%d.txt",min_run);
01654   ResFileEE    = new ofstream(outfile,std::ios::out);
01655   sprintf(outfile,"BadNewChannelsEB_run%d.txt",min_run);
01656   ResFileNewEB = new ofstream(outfile,std::ios::out);
01657   sprintf(outfile,"BadNewChannelsEE_run%d.txt",min_run);
01658   ResFileNewEE = new ofstream(outfile,std::ios::out);
01659   sprintf(outfile,"DaqConfig_run%d.txt",min_run);
01660   daqFile = new ofstream(outfile,std::ios::out);
01661   sprintf(outfile,"DaqConfig_channels_run%d.txt",min_run);
01662   daqFile2 = new ofstream(outfile,std::ios::out);
01663 
01664   *daqFile  << "fed" << "\t\t" << "tower" << std::endl; 
01665 
01666   if (m_runtype=="PEDESTAL") { 
01667     *ResFileEB << "Fed"         << "\t\t"   << "Ic"     << "\t\t" << "hIndex"   << "\t\t"              
01668                << "MeanG12"     << "\t\t"   << "RmsG12" << "\t\t" 
01669                << "MeanG6"      << "\t\t"   << "RmsG6"  << "\t\t" 
01670                << "MeanG1"      << "\t\t"   << "RmsG1"  << std::endl;
01671 
01672     *ResFileEE << "Fed"         << "\t\t"   << "Ix"     << "\t\t" 
01673                << "Iy"          << "\t\t"   << "Iz"     << "\t\t" << "hIndex"   << "\t\t"
01674                << "MeanG12"     << "\t\t"   << "RmsG12" << "\t\t" 
01675                << "MeanG6"      << "\t\t"   << "RmsG6"  << "\t\t" 
01676                << "MeanG1"      << "\t\t"   << "RmsG1"  << std::endl;
01677 
01678     *ResFileNewEB << "Fed"         << "\t\t"   << "Ic"     << "\t\t" << "hIndex"   << "\t\t"           
01679                   << "MeanG12"     << "\t\t"   << "RmsG12" << "\t\t" 
01680                   << "MeanG6"      << "\t\t"   << "RmsG6"  << "\t\t" 
01681                   << "MeanG1"      << "\t\t"   << "RmsG1"  << std::endl;
01682 
01683     *ResFileNewEE << "Fed"         << "\t\t"   << "Ix"     << "\t\t" 
01684                   << "Iy"          << "\t\t"   << "Iz"     << "\t\t" << "hIndex"   << "\t\t"
01685                   << "MeanG12"     << "\t\t"   << "RmsG12" << "\t\t" 
01686                   << "MeanG6"      << "\t\t"   << "RmsG6"  << "\t\t" 
01687                   << "MeanG1"      << "\t\t"   << "RmsG1"  << std::endl;
01688   }
01689   
01690 
01691   if (m_runtype=="LASER") {   
01692     *ResFileEB    << "Fed" << "\t\t" << "Ic" << "\t\t" << "hIndex" << "\t\t" << "apd" << std::endl;
01693     *ResFileEE    << "Fed" << "\t\t" << "Ix" << "\t\t" << "Iy"     << "\t\t" << "Iz"  << "\t\t" << "hIndex" << "\t\t" << "apd"  << std::endl;          
01694     *ResFileNewEB << "Fed" << "\t\t" << "Ic" << "\t\t" << "hIndex" << "\t\t" << "apd" << std::endl;
01695     *ResFileNewEE << "Fed" << "\t\t" << "Ix" << "\t\t" << "Iy"     << "\t\t" << "Iz"  << "\t\t" << "hIndex" << "\t\t" << "apd"  << std::endl;          
01696   }
01697 
01698 
01699   if (m_runtype=="COSMIC" || m_runtype=="BEAM" || m_runtype=="PHYSICS" || m_runtype=="HALO" || m_runtype=="GLOBAL_COSMICS" ) {
01700     
01701     *ResFileEB << "Fed"             << "\t\t"   << "Ic"            << "\t\t" << "hIndex"   << "\t\t"   
01702                << "pedOnline"       << "\t\t"   << "pedOnlineRMS " << "\t\t" 
01703                << "gain0"           << "\t\t"   << "apd"           << "\t\t" 
01704                << "highThrOcc"      << "\t\t"   << std::endl;
01705 
01706     *ResFileEE << "Fed"             << "\t\t"   << "Ix" 
01707                << "Iy"              << "\t\t"   << "Iz"            << "\t\t" << "hIndex"   << "\t\t"
01708                << "pedOnline"       << "\t\t"   << "pedOnlineRMS " << "\t\t" 
01709                << "gain0"           << "\t\t"   << "apd"           << "\t\t" 
01710                << "highThrOcc"      << "\t\t"   << std::endl;
01711 
01712     *ResFileNewEB << "Fed"             << "\t\t"   << "Ic"            << "\t\t" << "hIndex"   << "\t\t"   
01713                   << "pedOnline"       << "\t\t"   << "pedOnlineRMS " << "\t\t" 
01714                   << "gain0"           << "\t\t"   << "apd"           << "\t\t" 
01715                   << "highThrOcc"      << "\t\t"   << std::endl;
01716     
01717     *ResFileNewEE << "Fed"             << "\t\t"   << "Ix" 
01718                   << "Iy"              << "\t\t"   << "Iz"            << "\t\t" << "hIndex"   << "\t\t"
01719                   << "pedOnline"       << "\t\t"   << "pedOnlineRMS " << "\t\t" 
01720                   << "gain0"           << "\t\t"   << "apd"           << "\t\t" 
01721                   << "highThrOcc"      << "\t\t"   << std::endl;
01722   }
01723 
01724 
01725 
01726 
01727 
01728   // -------------------------------------------------------------------
01729   // analysis for the wanted runs
01730   std::vector<MonRunIOV> mon_run_vec = mon_list.getRuns();
01731   int mon_runs = mon_run_vec.size();
01732   std::cout << "number of Mon runs is " << mon_runs << std::endl;
01733   if(mon_runs==0) std::cout << "PROBLEM! 0 runs analyzed by DQM" << std::endl;
01734   if(mon_runs==0) ss   << "PROBLEM! 0 runs analyzed by DQM" << std::endl;
01735 
01736   // initialize std::maps with masked channels
01737   maskedOnlinePedEB.clear();
01738   maskedOnlinePedEE.clear();
01739   maskedPedEB.clear();
01740   maskedPedEE.clear();
01741   maskedLaserEB.clear();
01742   maskedLaserEE.clear();
01743   maskedPhysicsEB.clear();
01744   maskedPhysicsEE.clear();
01745 
01746     // to iterate
01747   std::map<DetId,float>::const_iterator theIter;
01748   
01749   // using db info written by DQM
01750   if(mon_runs>0){   
01751     
01752     for(int dqmRun=0; dqmRun<mon_runs; dqmRun++){
01753       
01754       unsigned long iDqmRun=(unsigned long) mon_run_vec[dqmRun].getRunIOV().getRunNumber();  
01755       
01756       std::cout << "retrieve the DQM data for run number: " << iDqmRun << ", subrun number: " << mon_run_vec[dqmRun].getSubRunNumber() << std::endl;
01757 
01758       
01759       if (mon_run_vec[dqmRun].getSubRunNumber()==mon_runs){      // fixme: check it still works after DMQ soft reset modifications
01760         
01761         // retrieve daq configuration for this run
01762         RunIOV myRun;
01763         myRun=mon_run_vec[dqmRun].getRunIOV();
01764         daqOut(myRun);
01765 
01766 
01767         // retrieve the data for a given run
01768         RunIOV runiov_prime = mon_run_vec[dqmRun].getRunIOV();
01769         
01770 
01771         // here we read the list of masked channel in the DB for this run and create masked channels std::maps
01772         std::cout << "Fetching masked channels from DB" << std::endl;
01773         EcalErrorMask::readDB(econn, &runiov_prime);
01774 
01775 
01776 
01777         
01778         // -----------------------------------------------------------------------------------
01779         // here we do all the different types of analyses
01780 
01781         
01782         // PEDESTAL ANALYSIS for local runs: check pedestals only
01783         if (m_runtype=="PEDESTAL") {   
01784 
01785           // retrieve the pedestals from OMDS for this run 
01786           std::map<EcalLogicID, MonPedestalsDat> dataset_mon;    
01787           econn->fetchDataSet(&dataset_mon, &mon_run_vec[dqmRun]);
01788           std::cout << "running pedestal analysis" << std::endl;
01789           std::cout << "OMDS record for pedestals, run " << iDqmRun << " is made of " << dataset_mon.size() << " entries" << std::endl;
01790 
01791           // retrieve the crystal consistency from OMDS for this run 
01792           std::map<EcalLogicID, MonCrystalConsistencyDat> wrongGain_mon;
01793           econn->fetchDataSet(&wrongGain_mon, &mon_run_vec[dqmRun]);
01794           std::cout << "OMDS record for consistency, run " << iDqmRun << " is made of " << wrongGain_mon.size() << " entries" << std::endl;
01795 
01796           // check if enough data and perform analysis
01797           if (dataset_mon.size()>0) { 
01798             pedAnalysis( dataset_mon, wrongGain_mon );
01799           } else {
01800             std::cout << "Not enought data for pedestal analysis" << std::endl;
01801             ss   << "Not enought data for pedestal analysis" << std::endl;
01802           }       
01803         }
01804         
01805         
01806         
01807         // LASER ANALYSIS for local runs: check APD values only
01808         if (m_runtype=="LASER") {   
01809             
01810           // retrieve the APD / PNs from OMDS for this run 
01811           std::map<EcalLogicID, MonLaserBlueDat > dataset_mon;
01812           econn->fetchDataSet(&dataset_mon, &mon_run_vec[dqmRun]);
01813           std::cout << "running the laser analysis based on DQM data" << std::endl;
01814           std::cout << "OMDS record for run " << iDqmRun << " is made of " << dataset_mon.size() << " records" << std::endl;          
01815           
01816           // check if enough data and select good light modules / perform analysis
01817           if (dataset_mon.size()>0) { 
01818             nBadLaserModules( dataset_mon );
01819             laserAnalysis( dataset_mon );
01820           } else {
01821             std::cout << "Not enought data for dqm-based laser analysis" << std::endl;
01822             ss   << "Not enought data for dqm-based laser analysis" << std::endl;
01823           }
01824         }
01825         
01826         
01827         
01828         // global analysis for global runs
01829         if (m_runtype=="COSMIC" || m_runtype=="BEAM" || m_runtype=="PHYSICS" || m_runtype=="HALO" || m_runtype=="GLOBAL_COSMICS" ) {   
01830 
01831           // retrieve the pedestal online from OMDS for this run 
01832           std::map<EcalLogicID, MonPedestalsOnlineDat> pedonline_mon;    
01833           econn->fetchDataSet(&pedonline_mon, &mon_run_vec[dqmRun]);
01834           std::cout << "running pedestal online analysis" << std::endl;
01835           std::cout << "OMDS record for pedestals, run " << iDqmRun << " is made of " << pedonline_mon.size() << std::endl;
01836 
01837           // retrieve the crystal consistency from OMDS for this run 
01838           std::map<EcalLogicID, MonCrystalConsistencyDat> wrongGain_mon;
01839           econn->fetchDataSet(&wrongGain_mon, &mon_run_vec[dqmRun]);
01840           std::cout << "OMDS record for consistency, run " << iDqmRun << " is made of " << wrongGain_mon.size() << " entries" << std::endl;
01841           
01842           // retrieve the occupancy info from OMDS for this run 
01843           std::map<EcalLogicID, MonOccupancyDat> occupancy_mon;
01844           econn->fetchDataSet(&occupancy_mon, &mon_run_vec[dqmRun]);
01845           std::cout << "OMDS record for occupancy, run " << iDqmRun << " is made of " << occupancy_mon.size() << std::endl;
01846 
01847           // retrieve the APD / PNs from OMDS for this run 
01848           std::map<EcalLogicID, MonLaserBlueDat > laser_mon;
01849           econn->fetchDataSet(&laser_mon, &mon_run_vec[dqmRun]);
01850           std::cout << "running laser analysis" << std::endl;
01851           std::cout << "OMDS record for laser, run " << iDqmRun << " is made of " << laser_mon.size() << " records" << std::endl;            
01852 
01853 
01854           // check if enough data in all the categories and do the analysis
01855           if (pedonline_mon.size()<=0) { 
01856             std::cout << "Not enought data for pedestal online analysis" << std::endl; 
01857             ss   << "Not enought data for pedestal online analysis" << std::endl; 
01858           }
01859           if (occupancy_mon.size()<=0) { 
01860             std::cout << "Not enought data for occupancy analysis" << std::endl;       
01861             ss   << "Not enought data for occupancy analysis" << std::endl; 
01862           }
01863           if (laser_mon.size()<=0) { 
01864             std::cout << "Not enought data for laser analysis" << std::endl;
01865             ss   << "Not enought data for laser analysis" << std::endl;
01866           }
01867           if ( pedonline_mon.size()>0 || occupancy_mon.size()>0 || wrongGain_mon.size()>0 || laser_mon.size()>0 ) {
01868             nBadLaserModules( laser_mon );
01869             cosmicsAnalysis( pedonline_mon, wrongGain_mon, laser_mon, occupancy_mon );
01870           }
01871 
01872 
01873           // plotting histos with new bad channels
01874           int iLineEB=0;
01875           TLine lEB;
01876           gStyle->SetPalette(1);
01877           gStyle->SetOptStat(0);
01878           TCanvas c("c","c",1);
01879           newBadEB_ -> SetMaximum(11);
01880           newBadEB_ -> Draw("colz");
01881           iLineEB=0;
01882           lEB.DrawLine(0,0,360,0);
01883           while (iLineEB<18) { lEB.DrawLine (iLineEB*20, -85, iLineEB*20, 85);  iLineEB++; }
01884           c.SaveAs("newBadEB_.png");
01885           
01886           TLine lEE;
01887           lEE.SetLineWidth(1);
01888           int ixSectorsEE[202] = {61, 61, 60, 60, 59, 59, 58, 58, 57, 57, 55, 55, 45, 45, 43, 43, 42, 42, 41, 41, 40, 40, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 45, 45, 55, 55, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 0,100,100, 97, 97, 95, 95, 92, 92, 87, 87, 85, 85, 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,  0,  0,  3,  3,  5,  5,  8,  8, 13, 13, 15, 15, 20, 20, 25, 25, 35, 35, 40, 40, 60, 60, 65, 65, 75, 75, 80, 80, 85, 85, 87, 87, 92, 92, 95, 95, 97, 97,100,100,  0, 61, 65, 65, 70, 70, 80, 80, 90, 90, 92,  0, 61, 65, 65, 90, 90, 97,  0, 57, 60, 60, 65, 65, 70, 70, 75, 75, 80, 80,  0, 50, 50,  0, 43, 40, 40, 35, 35, 30, 30, 25, 25, 20, 20, 0, 39, 35, 35, 10, 10,  3,  0, 39, 35, 35, 30, 30, 20, 20, 10, 10,  8,  0, 45, 45, 40, 40, 35, 35,  0, 55, 55, 60, 60, 65, 65};
01889           int iySectorsEE[202] = {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, 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, 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, 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,  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, 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, 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, 35, 35, 30, 30, 25, 25,  0, 39, 30, 30, 15, 15,  5,  0, 39, 30, 30, 15, 15,  5};
01890           
01891           newBadEEP_ -> SetMaximum(11);
01892           newBadEEP_ -> Draw("colz");
01893           for ( int iLineEEP=0; iLineEEP<201; iLineEEP=iLineEEP+1 ) {
01894             if ( (ixSectorsEE[iLineEEP]!=0 || iySectorsEE[iLineEEP]!=0) && (ixSectorsEE[iLineEEP+1]!=0 || iySectorsEE[iLineEEP+1]!=0) ) {
01895               lEE.DrawLine(ixSectorsEE[iLineEEP], iySectorsEE[iLineEEP], ixSectorsEE[iLineEEP+1], iySectorsEE[iLineEEP+1]);
01896             }}
01897           c.SaveAs("newBadEEP_.png");
01898 
01899           newBadEEM_  -> SetMaximum(11);
01900           newBadEEM_ -> Draw("colz");
01901           for ( int iLineEEP=0; iLineEEP<201; iLineEEP=iLineEEP+1 ) {
01902             if ( (ixSectorsEE[iLineEEP]!=0 || iySectorsEE[iLineEEP]!=0) && (ixSectorsEE[iLineEEP+1]!=0 || iySectorsEE[iLineEEP+1]!=0) ) {
01903               lEE.DrawLine(ixSectorsEE[iLineEEP], iySectorsEE[iLineEEP], ixSectorsEE[iLineEEP+1], iySectorsEE[iLineEEP+1]);
01904             }}
01905           c.SaveAs("newBadEEM_.png");
01906           
01907         } // cosmics analysis
01908         
01909       } // subruns 
01910     }   // runs loop
01911   }     // we have the DQM info 
01912   
01913   delete econn;
01914   std::cout << "Ecal - > end of getNewObjects -----------\n";   
01915 }
01916 
01917 
01918 void popcon::EcalChannelStatusHandler::setElectronicsMap(const EcalElectronicsMapping* theEcalElectronicsMap) {
01919 
01920   ecalElectronicsMap_ = (*theEcalElectronicsMap);
01921 }
01922 
01923