CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/SimCalorimetry/EcalTrigPrimProducers/plugins/EcalTPCondAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Class:      EcalTPDBAnalyzer
00004 //
00010 //
00011 //
00012 // Original Author:  Ursula Berthon
00013 //         Created:  Wed Oct 15  11:38:38 CEST 2008
00014 // $Id: EcalTPCondAnalyzer.cc,v 1.2 2009/10/28 00:09:26 ebecheva Exp $
00015 //
00016 //
00017 //
00018 
00019 
00020 // system include files
00021 #include <memory>
00022 #include <utility>
00023 #include <iostream>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030 
00031 #include "CondFormats/DataRecord/interface/EcalTPGPhysicsConstRcd.h"
00032 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBGroupRcd.h"
00033 #include "CondFormats/DataRecord/interface/EcalTPGLutGroupRcd.h"
00034 #include "CondFormats/DataRecord/interface/EcalTPGLutIdMapRcd.h"
00035 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBIdMapRcd.h"
00036 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainTowerEERcd.h"
00037 #include "CondFormats/DataRecord/interface/EcalTPGLinearizationConstRcd.h"
00038 #include "CondFormats/DataRecord/interface/EcalTPGPedestalsRcd.h"
00039 #include "CondFormats/DataRecord/interface/EcalTPGSlidingWindowRcd.h"
00040 #include "CondFormats/DataRecord/interface/EcalTPGWeightIdMapRcd.h"
00041 #include "CondFormats/DataRecord/interface/EcalTPGWeightGroupRcd.h"
00042 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainStripEERcd.h"
00043 
00044 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00045 #include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h"
00046 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00047 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00048 
00049 #include "SimCalorimetry/EcalTrigPrimProducers/plugins/EcalTPCondAnalyzer.h"
00050 
00051 EcalTPCondAnalyzer::EcalTPCondAnalyzer(const edm::ParameterSet&  iConfig)
00052 
00053 {}
00054 
00055 void EcalTPCondAnalyzer::beginRun(const edm::Run & run, edm::EventSetup const& evtSetup){
00056  // get geometry
00057   
00058   edm::ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle, theBarrelGeometry_handle;
00059   evtSetup.get<EcalEndcapGeometryRecord>().get("EcalEndcap",theEndcapGeometry_handle);
00060   evtSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel",theBarrelGeometry_handle);
00061   theEndcapGeometry_ = &(*theEndcapGeometry_handle);
00062   theBarrelGeometry_ = &(*theBarrelGeometry_handle);
00063 
00064   cacheID_=this->getRecords(evtSetup);
00065 }
00066 
00067 void EcalTPCondAnalyzer::beginJob() 
00068 {}
00069 
00070 
00071 EcalTPCondAnalyzer::~EcalTPCondAnalyzer() {
00072 }
00073 
00074 unsigned long long  EcalTPCondAnalyzer::getRecords(edm::EventSetup const& setup) {
00075   //
00076   // get Eventsetup records and print them
00077   //
00078    printComment();
00079 
00080    edm::ESHandle<EcalTPGPhysicsConst> theEcalTPGPhysConst_handle;
00081   setup.get<EcalTPGPhysicsConstRcd>().get(theEcalTPGPhysConst_handle);
00082   const EcalTPGPhysicsConst * ecaltpPhysConst = theEcalTPGPhysConst_handle.product();
00083   printEcalTPGPhysicsConst(ecaltpPhysConst);
00084   // for EcalFenixStrip...
00085 
00086   // get parameter records for xtals
00087   edm::ESHandle<EcalTPGLinearizationConst> theEcalTPGLinearization_handle;
00088   setup.get<EcalTPGLinearizationConstRcd>().get(theEcalTPGLinearization_handle);
00089   const EcalTPGLinearizationConst * ecaltpLin = theEcalTPGLinearization_handle.product();
00090 
00091   edm::ESHandle<EcalTPGPedestals> theEcalTPGPedestals_handle;
00092   setup.get<EcalTPGPedestalsRcd>().get(theEcalTPGPedestals_handle);
00093   const EcalTPGPedestals * ecaltpPed = theEcalTPGPedestals_handle.product();
00094   printCRYSTAL(ecaltpPed,ecaltpLin );
00095 
00096 
00097   //weight
00098   edm::ESHandle<EcalTPGWeightIdMap> theEcalTPGWEightIdMap_handle;
00099   setup.get<EcalTPGWeightIdMapRcd>().get(theEcalTPGWEightIdMap_handle);
00100   const EcalTPGWeightIdMap * ecaltpgWeightMap = theEcalTPGWEightIdMap_handle.product();
00101   printWEIGHT(ecaltpgWeightMap);
00102 
00103    // .. and for EcalFenixTcp
00104 
00105   edm::ESHandle<EcalTPGFineGrainEBIdMap> theEcalTPGFineGrainEBIdMap_handle;
00106   setup.get<EcalTPGFineGrainEBIdMapRcd>().get(theEcalTPGFineGrainEBIdMap_handle);
00107   const EcalTPGFineGrainEBIdMap * ecaltpgFineGrainEB = theEcalTPGFineGrainEBIdMap_handle.product();
00108   printEcalTPGFineGrainEBIdMap(ecaltpgFineGrainEB);
00109 
00110 
00111   edm::ESHandle<EcalTPGLutIdMap> theEcalTPGLutIdMap_handle;
00112   setup.get<EcalTPGLutIdMapRcd>().get(theEcalTPGLutIdMap_handle);
00113   const EcalTPGLutIdMap * ecaltpgLut = theEcalTPGLutIdMap_handle.product();
00114   printEcalTPGLutIdMap(ecaltpgLut);
00115 
00116   //for strips
00117   edm::ESHandle<EcalTPGSlidingWindow> theEcalTPGSlidingWindow_handle;
00118   setup.get<EcalTPGSlidingWindowRcd>().get(theEcalTPGSlidingWindow_handle);
00119   const EcalTPGSlidingWindow * ecaltpgSlidW = theEcalTPGSlidingWindow_handle.product();
00120   edm::ESHandle<EcalTPGFineGrainStripEE> theEcalTPGFineGrainStripEE_handle;
00121   setup.get<EcalTPGFineGrainStripEERcd>().get(theEcalTPGFineGrainStripEE_handle);
00122   const EcalTPGFineGrainStripEE * ecaltpgFgStripEE = theEcalTPGFineGrainStripEE_handle.product();     
00123   edm::ESHandle<EcalTPGWeightGroup> theEcalTPGWEightGroup_handle;
00124   setup.get<EcalTPGWeightGroupRcd>().get(theEcalTPGWEightGroup_handle);
00125   const EcalTPGWeightGroup * ecaltpgWeightGroup = theEcalTPGWEightGroup_handle.product();
00126   printSTRIP(ecaltpgSlidW,ecaltpgWeightGroup,ecaltpgFgStripEE);
00127 
00128   // get parameter records for towers
00129   edm::ESHandle<EcalTPGLutGroup> theEcalTPGLutGroup_handle;
00130   setup.get<EcalTPGLutGroupRcd>().get(theEcalTPGLutGroup_handle);
00131   const EcalTPGLutGroup * ecaltpgLutGroup = theEcalTPGLutGroup_handle.product();
00132 
00133   edm::ESHandle<EcalTPGFineGrainEBGroup> theEcalTPGFineGrainEBGroup_handle;
00134   setup.get<EcalTPGFineGrainEBGroupRcd>().get(theEcalTPGFineGrainEBGroup_handle);
00135   const EcalTPGFineGrainEBGroup * ecaltpgFgEBGroup = theEcalTPGFineGrainEBGroup_handle.product();
00136   printTOWEREB(ecaltpgFgEBGroup,ecaltpgLutGroup);
00137   edm::ESHandle<EcalTPGFineGrainTowerEE> theEcalTPGFineGrainTowerEE_handle;
00138   setup.get<EcalTPGFineGrainTowerEERcd>().get(theEcalTPGFineGrainTowerEE_handle);
00139   const EcalTPGFineGrainTowerEE * ecaltpgFineGrainTowerEE = theEcalTPGFineGrainTowerEE_handle.product();
00140   printTOWEREE(ecaltpgFineGrainTowerEE,ecaltpgLutGroup);
00141 
00142   std::cout<<"EOF"<<std::endl;
00143 
00144   return setup.get<EcalTPGFineGrainTowerEERcd>().cacheIdentifier();
00145 }
00146 
00147 // ------------ method called to analyze the data  ------------
00148 void
00149 EcalTPCondAnalyzer::analyze(const edm::Event& iEvent, const  edm::EventSetup & iSetup){
00150 }
00151 
00152 void
00153 EcalTPCondAnalyzer::endJob(){
00154 }
00155 
00156 void EcalTPCondAnalyzer::printEcalTPGPhysicsConst(const EcalTPGPhysicsConst *ecaltpgPhysConst) const {
00157   EcalTPGPhysicsConstMapIterator it;
00158   const EcalTPGPhysicsConstMap mymap=ecaltpgPhysConst->getMap();
00159   for (it=mymap.begin();it!=mymap.end();++it) {
00160     if (it==mymap.begin()) {
00161       std::cout<<"\nPHYSICS_EB "<<(*it).first<<std::endl;
00162     } else {
00163       std::cout<<"\nPHYSICS_EE "<<(*it).first<<std::endl;
00164     }
00165     std::cout<<(*it).second.EtSat<<" "<<(*it).second.ttf_threshold_Low<<" "<<(*it).second.ttf_threshold_High<<std::endl;
00166     std::cout<<(*it).second.FG_lowThreshold<<" "<<(*it).second.FG_highThreshold<<" "<<(*it).second.FG_lowRatio<<" "<<(*it).second.FG_highRatio<<std::endl;
00167   }
00168 }
00169 
00170 void  EcalTPCondAnalyzer::printSTRIP(const EcalTPGSlidingWindow *slWin,const EcalTPGWeightGroup *ecaltpgWeightGroup,const EcalTPGFineGrainStripEE * ecaltpgFgStripEE) const {
00171   // print STRIP information
00172   const EcalTPGSlidingWindowMap &slwinmap = slWin -> getMap();
00173   const EcalTPGFineGrainStripEEMap &fgstripEEmap= ecaltpgFgStripEE->getMap();
00174   EcalTPGSlidingWindowMapIterator it;
00175   const EcalTPGGroups::EcalTPGGroupsMap &gMap=ecaltpgWeightGroup->getMap();
00176   EcalTPGGroups::EcalTPGGroupsMapItr groupId;
00177 
00178   std::cout<<std::endl;
00179   for (int mysub=1;mysub<=2;++mysub) {
00180     std::cout<<std::endl;
00181     for (it=slwinmap.begin();it!=slwinmap.end();++it) {
00182       EcalTriggerElectronicsId elid((*it).first);
00183       groupId=gMap.find((*it).first);
00184       int subdet =elid.subdet();
00185       if (subdet==mysub) {
00186         if (subdet==1) {
00187           std::cout<<"STRIP_EB "<<std::dec<<(*it).first<<std::endl;
00188           std::cout << std::hex << "0x" <<(*it).second<<std::endl ;
00189           std::cout  <<" " <<(*groupId).second<< std::endl ; //weightgroupid
00190         }else if (subdet==2) {
00191           std::cout<<"STRIP_EE "<<std::dec<<(*it).first<<std::endl;
00192           std::cout << std::hex << "0x" <<(*it).second<<std::endl ;
00193           std::cout <<" " <<(*groupId).second<<std::endl ;//weightgroupid
00194           EcalTPGFineGrainStripEEMapIterator it2=fgstripEEmap.find((*it).first);
00195           if (it2==fgstripEEmap.end()) {
00196             edm::LogWarning("EcalTPGCondAnalyzer") <<" could not find strip Id "<<(*it).first<<", given in sliding window, inside the EcalTPGFineGranStripEEMap!!!";
00197           } else {
00198             EcalTPGFineGrainStripEE::Item item=(*it2).second;
00199             std::cout<<std::hex<<"0x"<<item.threshold<<" 0x"<<item.lut<<std::endl ;  
00200           }
00201         }
00202       }
00203     }
00204   }
00205 }
00206 
00207 void EcalTPCondAnalyzer::printWEIGHT(const EcalTPGWeightIdMap * ecaltpgWeightIdMap) const {
00208     
00209   std::cout<<std::endl;
00210     EcalTPGWeightIdMap::EcalTPGWeightMapItr it;
00211     uint32_t w0,w1,w2,w3,w4;
00212     const EcalTPGWeightIdMap::EcalTPGWeightMap map=ecaltpgWeightIdMap->getMap();
00213     for (it=map.begin();it!=map.end();++it) {
00214       std::cout <<"WEIGHT "<<(*it).first<<std::endl;
00215       (*it).second.getValues(w0,w1,w2,w3,w4);
00216       std::cout <<std::hex<<"0x"<<w0<<" 0x"<<w1<<" 0x"<<w2<<" 0x"<<w3<<" 0x"<<w4<<" "<<std::endl;
00217     }
00218 }
00219 
00220 void  EcalTPCondAnalyzer::printEcalTPGFineGrainEBIdMap(const EcalTPGFineGrainEBIdMap *ecaltpgFineGrainEB) const {
00221     EcalTPGFineGrainEBIdMap::EcalTPGFineGrainEBMapItr it;
00222     const EcalTPGFineGrainEBIdMap::EcalTPGFineGrainEBMap map=ecaltpgFineGrainEB->getMap();
00223     uint32_t ThresholdETLow, ThresholdETHigh, RatioLow, RatioHigh, LUT;
00224 
00225     std::cout<<std::endl;
00226     for (it=map.begin();it!=map.end();++it) {
00227       std::cout <<"FG "<<(*it).first<<std::endl;
00228       (*it).second.getValues(ThresholdETLow, ThresholdETHigh, RatioLow, RatioHigh, LUT);
00229       std::cout <<std::hex<<"0x"<<ThresholdETLow<<" 0x"<<ThresholdETHigh<<" 0x"<<RatioLow<<" 0x"<<RatioHigh<<" 0x"<<LUT<<std::endl;
00230     }
00231 }
00232 
00233 
00234 void EcalTPCondAnalyzer::printEcalTPGLutIdMap(const EcalTPGLutIdMap *ecaltpgLut) const {
00235     EcalTPGLutIdMap::EcalTPGLutMapItr it;
00236     const EcalTPGLutIdMap::EcalTPGLutMap map=ecaltpgLut->getMap();
00237 
00238     std::cout<<std::endl;
00239     for (it=map.begin();it!=map.end();++it) {
00240       std::cout <<"LUT "<<(*it).first<<std::endl;
00241       const unsigned int * lut=(*it).second.getLut();
00242       for (unsigned int i=0;i<1024;++i)  std::cout <<std::hex<<"0x"<<*lut++<<std::endl;
00243     }
00244 }
00245 
00246 void EcalTPCondAnalyzer::printCRYSTAL(const EcalTPGPedestals * ecaltpPed, const EcalTPGLinearizationConst * ecaltpLin ) {
00247 
00248   std::cout<<std::endl;
00249   const EcalTPGPedestalsMap pedMap=ecaltpPed->getMap();
00250   const EcalTPGLinearizationConstMap linMap=ecaltpLin->getMap();
00251 
00252   const std::vector<DetId> & ebCells = theBarrelGeometry_->getValidDetIds(DetId::Ecal, EcalBarrel);
00253 
00254   std::cout<<"COMMENT ====== barrel crystals ====== "<<std::endl; 
00255   for (std::vector<DetId>::const_iterator it = ebCells.begin(); it != ebCells.end(); ++it) {
00256     EBDetId id(*it) ;
00257     std::cout <<"CRYSTAL "<<std::dec<<id.rawId()<<std::endl;
00258     const EcalTPGPedestal &ped=pedMap[id.rawId()];
00259     const EcalTPGLinearizationConstant &lin=linMap[id.rawId()];
00260     std::cout<<std::hex<<" 0x"<<ped.mean_x12<<" 0x"<<lin.mult_x12<<" 0x"<<lin.shift_x12<<std::endl;
00261     std::cout<<std::hex<<" 0x"<<ped.mean_x6 <<" 0x"<<lin.mult_x6 <<" 0x"<<lin.shift_x6<<std::endl;
00262     std::cout<<std::hex<<" 0x"<<ped.mean_x1 <<" 0x"<<lin.mult_x1 <<" 0x"<<lin.shift_x1<<std::endl;
00263   }
00264 
00265   const std::vector<DetId> & eeCells = theEndcapGeometry_->getValidDetIds(DetId::Ecal, EcalEndcap);
00266   std::cout<<"COMMENT ====== endcap crystals ====== "<<std::endl; 
00267   for (std::vector<DetId>::const_iterator it = eeCells.begin(); it != eeCells.end(); ++it) {
00268     EEDetId id(*it) ;
00269     std::cout <<"CRYSTAL "<<std::dec<<id.rawId()<<std::endl;
00270     const EcalTPGPedestal &ped=pedMap[id.rawId()];
00271     const EcalTPGLinearizationConstant &lin=linMap[id.rawId()];
00272     std::cout<<std::hex<<" 0x"<<ped.mean_x12<<" 0x"<<lin.mult_x12<<" 0x"<<lin.shift_x12<<std::endl;
00273     std::cout<<std::hex<<" 0x"<<ped.mean_x6 <<" 0x"<<lin.mult_x6 <<" 0x"<<lin.shift_x6<<std::endl;
00274     std::cout<<std::hex<<" 0x"<<ped.mean_x1 <<" 0x"<<lin.mult_x1 <<" 0x"<<lin.shift_x1<<std::endl;
00275   }
00276 }
00277 void EcalTPCondAnalyzer::printComment() const {
00278   std::cout<<"COMMENT put your comments here\n"<<
00279   "COMMENT =================================\n"<<
00280   "COMMENT           physics EB structure\n"<<
00281   "COMMENT\n"<<
00282   "COMMENT  EtSaturation (GeV), ttf_threshold_Low (GeV), ttf_threshold_High (GeV)\n"<<
00283   "COMMENT  FG_lowThreshold (GeV), FG_highThreshold (GeV), FG_lowRatio, FG_highRatio\n"<<
00284   "COMMENT =================================\n"<<
00285   "COMMENT\n"<<
00286   "COMMENT =================================\n"<<
00287   "COMMENT           physics EE structure\n"<<
00288   "COMMENT\n"<<
00289   "COMMENT  EtSaturation (GeV), ttf_threshold_Low (GeV), ttf_threshold_High (GeV)\n"<<
00290   "COMMENT  FG_Threshold (GeV), dummy, dummy, dummy\n"<<
00291   "COMMENT =================================\n"<<
00292   "COMMENT\n"<<
00293   "COMMENT =================================\n"<<
00294   "COMMENT           crystal structure (same for EB and EE)\n"<<
00295   "COMMENT\n"<<
00296   "COMMENT  ped, mult, shift [gain12]\n"<<
00297   "COMMENT  ped, mult, shift [gain6]\n"<<
00298   "COMMENT  ped, mult, shift [gain1]\n"<<
00299   "COMMENT =================================\n"<<
00300   "COMMENT\n"<<
00301   "COMMENT =================================\n"<<
00302   "COMMENT           strip EB structure\n"<<
00303   "COMMENT\n"<<
00304   "COMMENT  sliding_window\n"<<
00305   "COMMENT  weightGroupId\n"<<
00306   "COMMENT =================================\n"<<
00307   "COMMENT\n"<<
00308   "COMMENT =================================\n"<<
00309   "COMMENT           strip EE structure\n"<<
00310   "COMMENT\n"<<
00311   "COMMENT  sliding_window\n"<<
00312   "COMMENT  weightGroupId\n"<<
00313   "COMMENT  threshold_fg strip_lut_fg\n"<<
00314   "COMMENT =================================\n"<<
00315   "COMMENT\n"<<
00316   "COMMENT =================================\n"<<
00317   "COMMENT           tower EB structure\n"<<
00318   "COMMENT\n"<<
00319   "COMMENT  LUTGroupId\n"<<
00320   "COMMENT  FgGroupId\n"<<
00321   "COMMENT =================================\n"<<
00322   "COMMENT\n"<<
00323   "COMMENT =================================\n"<<
00324   "COMMENT           tower EE structure\n"<<
00325   "COMMENT\n"<<
00326   "COMMENT  LUTGroupId\n"<<
00327   "COMMENT  tower_lut_fg\n"<<
00328   "COMMENT =================================\n"<<
00329   "COMMENT\n"<<
00330   "COMMENT =================================\n"<<
00331   "COMMENT           Weight structure\n"<<
00332   "COMMENT\n"<<
00333   "COMMENT  weightGroupId\n"<<
00334   "COMMENT  w0, w1, w2, w3, w4\n"<<
00335   "COMMENT =================================\n"<<
00336   "COMMENT\n"<<
00337   "COMMENT =================================\n"<<
00338   "COMMENT           lut structure\n"<<
00339   "COMMENT\n"<<
00340   "COMMENT  LUTGroupId\n"<<
00341   "COMMENT  LUT[1-1024]\n"<<
00342   "COMMENT =================================\n"<<
00343   "COMMENT\n"<<
00344   "COMMENT =================================\n"<<
00345   "COMMENT           fg EB structure\n"<<
00346   "COMMENT\n"<<
00347   "COMMENT  FgGroupId\n"<<
00348   "COMMENT  el, eh, tl, th, lut_fg\n"<<
00349   "COMMENT =================================\n"<<
00350   "COMMENT"<<std::endl;
00351 }
00352 
00353 void EcalTPCondAnalyzer::printTOWEREB(const EcalTPGFineGrainEBGroup *ecaltpgFgEBGroup,const EcalTPGLutGroup *ecaltpgLutGroup) const {
00354 
00355     const EcalTPGGroups::EcalTPGGroupsMap &lutMap=ecaltpgLutGroup->getMap();
00356     EcalTPGGroups::EcalTPGGroupsMapItr lutGroupId;
00357     const EcalTPGGroups::EcalTPGGroupsMap &fgMap=ecaltpgFgEBGroup->getMap();
00358     EcalTPGGroups::EcalTPGGroupsMapItr it;
00359 
00360     std::cout<<std::endl;
00361     for (it=fgMap.begin();it!=fgMap.end();++it) {
00362       std::cout <<"TOWER_EB "<<std::dec<<(*it).first<<std::endl;
00363       lutGroupId=lutMap.find((*it).first);
00364       std::cout <<" "<<(*it).second<<std::endl;
00365       std::cout <<" "<<(*lutGroupId).second<<std::endl;
00366     }
00367 }
00368 
00369 void EcalTPCondAnalyzer::printTOWEREE(const EcalTPGFineGrainTowerEE *ecaltpgFineGrainTowerEE,const EcalTPGLutGroup *ecaltpgLutGroup) const {
00370 
00371     EcalTPGFineGrainTowerEEMapIterator it;
00372     const EcalTPGFineGrainTowerEEMap map=ecaltpgFineGrainTowerEE->getMap();
00373     const EcalTPGGroups::EcalTPGGroupsMap &lutMap=ecaltpgLutGroup->getMap();
00374     EcalTPGGroups::EcalTPGGroupsMapItr lutGroupId;
00375 
00376     std::cout<<std::endl;
00377     for (it=map.begin();it!=map.end();++it) {
00378       std::cout <<"TOWER_EE "<<std::dec<<(*it).first<<std::endl;
00379       lutGroupId=lutMap.find((*it).first);
00380       std::cout <<" "<<(*lutGroupId).second<<std::endl;
00381       std::cout <<std::hex<<"0x"<<(*it).second<<std::endl;
00382     }
00383 }