CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CalibCalorimetry/EcalTrivialCondModules/src/EcalTrivialObjectAnalyzer.cc

Go to the documentation of this file.
00001 //
00002 // $Id: EcalTrivialObjectAnalyzer.cc,v 1.24 2011/11/02 09:38:53 fay Exp $
00003 // Created: 2 Mar 2006
00004 //          Shahram Rahatlou, University of Rome & INFN
00005 //
00006 #include "CalibCalorimetry/EcalTrivialCondModules/interface/EcalTrivialObjectAnalyzer.h"
00007 
00008 #include <stdexcept>
00009 #include <string>
00010 #include <iostream>
00011 #include <iomanip>
00012 #include <map>
00013 #include <vector>
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 
00016 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00017 
00018 #include "CondFormats/EcalObjects/interface/EcalPedestals.h"
00019 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
00020 
00021 #include "CondFormats/EcalObjects/interface/EcalXtalGroupId.h"
00022 #include "CondFormats/EcalObjects/interface/EcalWeightXtalGroups.h"
00023 #include "CondFormats/DataRecord/interface/EcalWeightXtalGroupsRcd.h"
00024 
00025 #include "CondFormats/EcalObjects/interface/EcalWeightSet.h"
00026 #include "CondFormats/EcalObjects/interface/EcalTBWeights.h"
00027 #include "CondFormats/DataRecord/interface/EcalTBWeightsRcd.h"
00028 
00029 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
00030 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
00031 
00032 #include "CondFormats/EcalObjects/interface/EcalIntercalibErrors.h"
00033 #include "CondFormats/DataRecord/interface/EcalIntercalibErrorsRcd.h"
00034 
00035 #include "CondFormats/EcalObjects/interface/EcalTimeCalibConstants.h"
00036 #include "CondFormats/DataRecord/interface/EcalTimeCalibConstantsRcd.h"
00037 
00038 #include "CondFormats/EcalObjects/interface/EcalTimeCalibErrors.h"
00039 #include "CondFormats/DataRecord/interface/EcalTimeCalibErrorsRcd.h"
00040 
00041 #include "CondFormats/EcalObjects/interface/EcalTimeOffsetConstant.h"
00042 #include "CondFormats/DataRecord/interface/EcalTimeOffsetConstantRcd.h"
00043 
00044 #include "CondFormats/EcalObjects/interface/EcalMGPAGainRatio.h"
00045 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
00046 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
00047 
00048 #include "CondFormats/EcalObjects/interface/EcalADCToGeVConstant.h"
00049 #include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h"
00050 
00051 #include "CondFormats/EcalObjects/interface/EcalLaserAlphas.h"
00052 #include "CondFormats/DataRecord/interface/EcalLaserAlphasRcd.h"
00053  
00054 #include "CondFormats/EcalObjects/interface/EcalLaserAPDPNRatiosRef.h"
00055 #include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosRefRcd.h"
00056  
00057 #include "CondFormats/EcalObjects/interface/EcalLaserAPDPNRatios.h"
00058 #include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosRcd.h"
00059 
00060 #include "CondFormats/EcalObjects/interface/EcalClusterLocalContCorrParameters.h"
00061 #include "CondFormats/DataRecord/interface/EcalClusterLocalContCorrParametersRcd.h"
00062 #include "CondFormats/EcalObjects/interface/EcalClusterCrackCorrParameters.h"
00063 #include "CondFormats/DataRecord/interface/EcalClusterCrackCorrParametersRcd.h"
00064 #include "CondFormats/EcalObjects/interface/EcalClusterEnergyCorrectionParameters.h"
00065 #include "CondFormats/DataRecord/interface/EcalClusterEnergyCorrectionParametersRcd.h"
00066 #include "CondFormats/EcalObjects/interface/EcalClusterEnergyUncertaintyParameters.h"
00067 #include "CondFormats/DataRecord/interface/EcalClusterEnergyUncertaintyParametersRcd.h"
00068 #include "CondFormats/EcalObjects/interface/EcalClusterEnergyCorrectionObjectSpecificParameters.h"
00069 #include "CondFormats/DataRecord/interface/EcalClusterEnergyCorrectionObjectSpecificParametersRcd.h"
00070 
00071 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00072 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00073 
00074 #include "CLHEP/Matrix/Matrix.h"
00075 
00076 using namespace std;
00077 
00078 void EcalTrivialObjectAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context)
00079 {
00080     using namespace edm::eventsetup;
00081     // Context is not used.
00082     std::cout <<">>> EcalTrivialObjectAnalyzer: processing run "<<e.id().run() << " event: " << e.id().event() << std::endl;
00083 
00084     edm::ESHandle<EcalPedestals> pPeds;
00085     context.get<EcalPedestalsRcd>().get(pPeds);
00086 
00087     // ADC -> GeV Scale
00088     edm::ESHandle<EcalADCToGeVConstant> pAgc;
00089     context.get<EcalADCToGeVConstantRcd>().get(pAgc);
00090     const EcalADCToGeVConstant* agc = pAgc.product();
00091     std::cout << "Global ADC->GeV scale: EB " << std::setprecision(6) << agc->getEBValue() << " GeV/ADC count" 
00092               " EE " << std::setprecision(6) << agc->getEEValue() << " GeV/ADC count" << std::endl;
00093 
00094     // use a channel to fetch values from DB
00095     double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00096     int ieta =  int( 1 + r1*85 );
00097     r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00098     int iphi =  int( 1 + r1*20 );
00099 
00100     EBDetId ebid(ieta,iphi); //eta,phi
00101     std::cout << "EcalTrivialObjectAnalyzer: using EBDetId: " << ebid << std::endl;
00102 
00103     const EcalPedestals* myped=pPeds.product();
00104     EcalPedestals::const_iterator it = myped->find(ebid.rawId());
00105     if( it!=myped->end() ){
00106       std::cout << "EcalPedestal: "
00107                 << "  mean_x1:  " << std::setprecision(8) << (*it).mean_x1 << " rms_x1: " << (*it).rms_x1
00108                 << "  mean_x6:  " <<(*it).mean_x6 << " rms_x6: " << (*it).rms_x6
00109                 << "  mean_x12: " <<(*it).mean_x12 << " rms_x12: " << (*it).rms_x12
00110                 << std::endl;
00111     } else {
00112      std::cout << "No pedestal found for this xtal! something wrong with EcalPedestals in your DB? "
00113                << std::endl;
00114     }
00115 
00116     // fetch map of groups of xtals
00117     edm::ESHandle<EcalWeightXtalGroups> pGrp;
00118     context.get<EcalWeightXtalGroupsRcd>().get(pGrp);
00119     const EcalWeightXtalGroups* grp = pGrp.product();
00120 
00121     EcalXtalGroupsMap::const_iterator git = grp->getMap().find( ebid.rawId() );
00122     EcalXtalGroupId gid;
00123     if( git != grp->getMap().end() ) {
00124       std::cout << "XtalGroupId.id() = " << std::setprecision(3) << (*git).id() << std:: endl;
00125       gid = (*git);
00126     } else {
00127       std::cout << "No group id found for this crystal. something wrong with EcalWeightXtalGroups in your DB?"
00128                 << std::endl;
00129    }
00130 
00131     // Gain Ratios
00132     edm::ESHandle<EcalGainRatios> pRatio;
00133     context.get<EcalGainRatiosRcd>().get(pRatio);
00134     const EcalGainRatios* gr = pRatio.product();
00135 
00136     EcalGainRatioMap::const_iterator grit=gr->getMap().find(ebid.rawId());
00137     EcalMGPAGainRatio mgpa;
00138     if( grit!=gr->getMap().end() ){
00139       mgpa = (*grit);
00140 
00141       std::cout << "EcalMGPAGainRatio: "
00142                 << "gain 12/6 :  " << std::setprecision(4) << mgpa.gain12Over6() << " gain 6/1: " << mgpa.gain6Over1()
00143                 << std::endl;
00144     } else {
00145      std::cout << "No MGPA Gain Ratio found for this xtal! something wrong with EcalGainRatios in your DB? "
00146                << std::endl;
00147     }
00148 
00149     // Intercalib constants
00150     edm::ESHandle<EcalIntercalibConstants> pIcal;
00151     context.get<EcalIntercalibConstantsRcd>().get(pIcal);
00152     const EcalIntercalibConstants* ical = pIcal.product();
00153 
00154     EcalIntercalibConstantMap::const_iterator icalit=ical->getMap().find(ebid.rawId());
00155     EcalIntercalibConstant icalconst;
00156     if( icalit!=ical->getMap().end() ){
00157       icalconst = (*icalit);
00158 
00159       std::cout << "EcalIntercalibConstant: "
00160                 <<std::setprecision(6)
00161                 << icalconst
00162                 << std::endl;
00163     } else {
00164      std::cout << "No intercalib const found for this xtal! something wrong with EcalIntercalibConstants in your DB? "
00165                << std::endl;
00166     }
00167 
00168     // Intercalib errors
00169     edm::ESHandle<EcalIntercalibErrors> pIcalErr;
00170     context.get<EcalIntercalibErrorsRcd>().get(pIcalErr);
00171     const EcalIntercalibErrors* icalErr = pIcalErr.product();
00172 
00173     EcalIntercalibErrorMap::const_iterator icalitErr=icalErr->getMap().find(ebid.rawId());
00174     EcalIntercalibError icalconstErr;
00175     if( icalitErr!=icalErr->getMap().end() ){
00176       icalconstErr = (*icalitErr);
00177 
00178       std::cout << "EcalIntercalibError: "
00179                 <<std::setprecision(6)
00180                 << icalconstErr
00181                 << std::endl;
00182     } else {
00183      std::cout << "No intercalib const found for this xtal! something wrong with EcalIntercalibErrors in your DB? "
00184                << std::endl;
00185     }
00186 
00187 
00188 
00189     { // quick and dirty for cut and paste ;) it is a test program...
00190             // TimeCalib constants
00191             edm::ESHandle<EcalTimeCalibConstants> pIcal;
00192             context.get<EcalTimeCalibConstantsRcd>().get(pIcal);
00193             const EcalTimeCalibConstants* ical = pIcal.product();
00194 
00195             EcalTimeCalibConstantMap::const_iterator icalit=ical->getMap().find(ebid.rawId());
00196             EcalTimeCalibConstant icalconst;
00197             if( icalit!=ical->getMap().end() ){
00198                     icalconst = (*icalit);
00199 
00200                     std::cout << "EcalTimeCalibConstant: "
00201                             <<std::setprecision(6)
00202                             << icalconst
00203                             << std::endl;
00204             } else {
00205                     std::cout << "No intercalib const found for this xtal! something wrong with EcalTimeCalibConstants in your DB? "
00206                             << std::endl;
00207             }
00208 
00209             // TimeCalib errors
00210             edm::ESHandle<EcalTimeCalibErrors> pIcalErr;
00211             context.get<EcalTimeCalibErrorsRcd>().get(pIcalErr);
00212             const EcalTimeCalibErrors* icalErr = pIcalErr.product();
00213 
00214             EcalTimeCalibErrorMap::const_iterator icalitErr=icalErr->getMap().find(ebid.rawId());
00215             EcalTimeCalibError icalconstErr;
00216             if( icalitErr!=icalErr->getMap().end() ){
00217                     icalconstErr = (*icalitErr);
00218 
00219                     std::cout << "EcalTimeCalibError: "
00220                             <<std::setprecision(6)
00221                             << icalconstErr
00222                             << std::endl;
00223             } else {
00224                     std::cout << "No intercalib const found for this xtal! something wrong with EcalTimeCalibErrors in your DB? "
00225                             << std::endl;
00226             }
00227     }
00228 
00229    // fetch Time Offset
00230    //std::cout <<"Fetching TimeOffsetConstant from DB " << std::endl;
00231 
00232    // Time Offset constants
00233    edm::ESHandle<EcalTimeOffsetConstant> pTOff;
00234    context.get<EcalTimeOffsetConstantRcd>().get(pTOff);
00235    const EcalTimeOffsetConstant* TOff = pTOff.product();
00236 
00237    std::cout << "EcalTimeOffsetConstant: "
00238              << " EB " << TOff->getEBValue()
00239              << " EE " << TOff->getEEValue()
00240              << std::endl;
00241 
00242    // fetch TB weights
00243    std::cout <<"Fetching EcalTBWeights from DB " << std::endl;
00244    edm::ESHandle<EcalTBWeights> pWgts;
00245    context.get<EcalTBWeightsRcd>().get(pWgts);
00246    const EcalTBWeights* wgts = pWgts.product();
00247    std::cout << "EcalTBWeightMap.size(): " << std::setprecision(3) << wgts->getMap().size() << std::endl;
00248 
00249 
00250    // look up the correct weights for this  xtal
00251    //EcalXtalGroupId gid( (*git) );
00252    EcalTBWeights::EcalTDCId tdcid(1);
00253 
00254    std::cout << "Lookup EcalWeightSet for groupid: " << std::setprecision(3) 
00255              << gid.id() << " and TDC id " << tdcid << std::endl;
00256    EcalTBWeights::EcalTBWeightMap::const_iterator wit = wgts->getMap().find( std::make_pair(gid,tdcid) );
00257    EcalWeightSet  wset;
00258    if( wit != wgts->getMap().end() ) {
00259       wset = wit->second;
00260       std::cout << "check size of data members in EcalWeightSet" << std::endl;
00261       //wit->second.print(std::cout);
00262 
00263 
00264       //typedef std::vector< std::vector<EcalWeight> > EcalWeightMatrix;
00265       const EcalWeightSet::EcalWeightMatrix& mat1 = wit->second.getWeightsBeforeGainSwitch();
00266       const EcalWeightSet::EcalWeightMatrix& mat2 = wit->second.getWeightsAfterGainSwitch();
00267 
00268 //       std::cout << "WeightsBeforeGainSwitch.size: " << mat1.size()
00269 //                 << ", WeightsAfterGainSwitch.size: " << mat2.size() << std::endl;
00270 
00271 
00272       CLHEP::HepMatrix clmat1(3,10,0);
00273       CLHEP::HepMatrix clmat2(3,10,0);
00274       for(int irow=0; irow<3; irow++) {
00275        for(int icol=0; icol<10; icol++) {
00276          clmat1[irow][icol] = mat1(irow,icol);
00277          clmat2[irow][icol] = mat2(irow,icol);
00278        }
00279      }
00280      std::cout << "weight matrix before gain switch:" << std::endl;
00281      std::cout << clmat1 << std::endl;
00282      std::cout << "weight matrix after gain switch:" << std::endl;
00283      std::cout << clmat2 << std::endl;
00284 
00285    } else {
00286      std::cout << "No weights found for EcalGroupId: " << gid.id() << " and  EcalTDCId: " << tdcid << std::endl;
00287   }
00288 
00289    // cluster functions/corrections
00290    edm::ESHandle<EcalClusterLocalContCorrParameters> pLocalCont;
00291    context.get<EcalClusterLocalContCorrParametersRcd>().get(pLocalCont);
00292    const EcalClusterLocalContCorrParameters* paramLocalCont = pLocalCont.product();
00293    std::cout << "LocalContCorrParameters:";
00294    for ( EcalFunctionParameters::const_iterator it = paramLocalCont->params().begin(); it != paramLocalCont->params().end(); ++it ) {
00295            std::cout << " " << *it;
00296    }
00297    std::cout << "\n";
00298    edm::ESHandle<EcalClusterCrackCorrParameters> pCrack;
00299    context.get<EcalClusterCrackCorrParametersRcd>().get(pCrack);
00300    const EcalClusterCrackCorrParameters* paramCrack = pCrack.product();
00301    std::cout << "CrackCorrParameters:";
00302    for ( EcalFunctionParameters::const_iterator it = paramCrack->params().begin(); it != paramCrack->params().end(); ++it ) {
00303            std::cout << " " << *it;
00304    }
00305    std::cout << "\n";
00306    edm::ESHandle<EcalClusterEnergyCorrectionParameters> pEnergyCorrection;
00307    context.get<EcalClusterEnergyCorrectionParametersRcd>().get(pEnergyCorrection);
00308    const EcalClusterEnergyCorrectionParameters* paramEnergyCorrection = pEnergyCorrection.product();
00309    std::cout << "EnergyCorrectionParameters:";
00310    for ( EcalFunctionParameters::const_iterator it = paramEnergyCorrection->params().begin(); it != paramEnergyCorrection->params().end(); ++it ) {
00311            std::cout << " " << *it;
00312    }
00313    std::cout << "\n";
00314    edm::ESHandle<EcalClusterEnergyUncertaintyParameters> pEnergyUncertainty;
00315    context.get<EcalClusterEnergyUncertaintyParametersRcd>().get(pEnergyUncertainty);
00316    const EcalClusterEnergyUncertaintyParameters* paramEnergyUncertainty = pEnergyUncertainty.product();
00317    std::cout << "EnergyCorrectionParameters:";
00318    for ( EcalFunctionParameters::const_iterator it = paramEnergyUncertainty->params().begin(); it != paramEnergyUncertainty->params().end(); ++it ) {
00319            std::cout << " " << *it;
00320    }
00321    std::cout << "\n";
00322    edm::ESHandle<EcalClusterEnergyCorrectionObjectSpecificParameters> pEnergyCorrectionObjectSpecific;
00323    context.get<EcalClusterEnergyCorrectionObjectSpecificParametersRcd>().get(pEnergyCorrectionObjectSpecific);
00324    const EcalClusterEnergyCorrectionObjectSpecificParameters* paramEnergyCorrectionObjectSpecific = pEnergyCorrectionObjectSpecific.product();
00325    std::cout << "EnergyCorrectionObjectSpecificParameters:";
00326    for ( EcalFunctionParameters::const_iterator it = paramEnergyCorrectionObjectSpecific->params().begin(); it != paramEnergyCorrectionObjectSpecific->params().end(); ++it ) {
00327      std::cout << " " << *it;
00328    }
00329    std::cout << "\n";
00330 
00331 
00332    // laser correction
00333    
00334    // laser alphas
00335    edm::ESHandle<EcalLaserAlphas> pAlpha; 
00336    context.get<EcalLaserAlphasRcd>().get(pAlpha);
00337    const EcalLaserAlphas* lalpha = pAlpha.product();
00338    
00339    EcalLaserAlphaMap::const_iterator lalphait;
00340    lalphait = lalpha->getMap().find(ebid.rawId());
00341    if( lalphait!=lalpha->getMap().end() ){
00342      std::cout << "EcalLaserAlpha: "
00343                <<std::setprecision(6)
00344                << (*lalphait)
00345                << std::endl;
00346    } else {
00347      std::cout << "No laser alpha found for this xtal! something wrong with EcalLaserAlphas in your DB? "
00348                << std::endl;
00349    }
00350 
00351    // laser apdpnref
00352    edm::ESHandle<EcalLaserAPDPNRatiosRef> pAPDPNRatiosRef;          
00353    context.get<EcalLaserAPDPNRatiosRefRcd>().get(pAPDPNRatiosRef);  
00354    const EcalLaserAPDPNRatiosRef* lref = pAPDPNRatiosRef.product(); 
00355    
00356    EcalLaserAPDPNRatiosRef::const_iterator lrefit;
00357    lrefit = lref->getMap().find(ebid.rawId());
00358    if( lrefit!=lref->getMap().end() ){
00359      std::cout << "EcalLaserAPDPNRatiosRef: "
00360                <<std::setprecision(6)
00361                << (*lrefit)
00362                << std::endl;
00363    } else {
00364      std::cout << "No laser apd/pn ref found for this xtal! something wrong with EcalLaserAPDPNRatiosRef in your DB? "
00365                << std::endl;
00366    }
00367 
00368    // laser apdpn ratios 
00369    edm::ESHandle<EcalLaserAPDPNRatios> pAPDPNRatios;          
00370    context.get<EcalLaserAPDPNRatiosRcd>().get(pAPDPNRatios);  
00371    const EcalLaserAPDPNRatios* lratio = pAPDPNRatios.product();
00372 
00373    EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap::const_iterator lratioit; 
00374    lratioit = lratio->getLaserMap().find(ebid.rawId());
00375    EcalLaserAPDPNRatios::EcalLaserAPDPNpair lratioconst;
00376    
00377    if( lratioit!=lratio->getLaserMap().end() ){
00378      lratioconst = (*lratioit);
00379      
00380      std::cout << "EcalLaserAPDPNRatios: "
00381        //              <<e.id().run() << " " << e.id().event() << " " 
00382                << std::setprecision(6)
00383                << lratioconst.p1 << " " << lratioconst.p2
00384                << std::endl;
00385    } else {
00386      std::cout << "No laser apd/pn ratio found for this xtal! something wrong with EcalLaserAPDPNRatios in your DB? "
00387                << std::endl;
00388    }
00389 
00390    // laser timestamps
00391    EcalLaserAPDPNRatios::EcalLaserTimeStamp ltimestamp;
00392    EcalLaserAPDPNRatios::EcalLaserTimeStampMap::const_iterator ltimeit;
00393    for (int i=1; i<=92; i++) {     
00394      ltimestamp = lratio->getTimeMap()[i];
00395      std::cout << "i = " << std::setprecision(6) << i
00396              << ltimestamp.t1.value() << " " << ltimestamp.t2.value() << " : " ;
00397    }
00398    std::cout << "Tests finihed." << std::endl;
00399 
00400    // channel status
00401    edm::ESHandle<EcalChannelStatus> pChannelStatus;
00402    context.get<EcalChannelStatusRcd>().get(pChannelStatus);
00403    const EcalChannelStatus *ch_status = pChannelStatus.product();
00404 
00405    EcalChannelStatusMap::const_iterator chit;
00406    chit = ch_status->getMap().find(ebid.rawId());
00407    if( chit != ch_status->getMap().end() ){
00408            EcalChannelStatusCode ch_code = (*chit);
00409            std::cout << "EcalChannelStatus: "
00410                    <<std::setprecision(6)
00411                    << ch_code.getStatusCode()
00412                    << std::endl;
00413    } else {
00414            std::cout << "No channel status found for this xtal! something wrong with EcalChannelStatus in your DB? "
00415                    << std::endl;
00416    }
00417 
00418 
00419    // laser transparency correction
00420    
00421 
00422 /*
00423     std::cout << "make CLHEP matrices from vector<vector<Ecalweight>>" << std::endl;
00424     CLHEP::HepMatrix clmat1(3,8,0);
00425     CLHEP::HepMatrix clmat2(3,8,0);
00426     for(int irow=0; irow<3; irow++) {
00427      for(int icol=0; icol<8; icol++) {
00428        clmat1[irow][icol] = (mat1[irow])[icol]();
00429        clmat2[irow][icol] = (mat2[irow])[icol]();
00430      }
00431    }
00432    std::cout << clmat1 << std::endl;
00433    std::cout << clmat2 << std::endl;
00434 */
00435 
00436 } //end of ::Analyze()
00437   //DEFINE_FWK_MODULE(EcalTrivialObjectAnalyzer);