CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SimCalorimetry/EcalTrigPrimProducers/plugins/EcalTrigPrimProducer.cc

Go to the documentation of this file.
00001 
00016 #include "FWCore/Framework/interface/Frameworkfwd.h"
00017 
00018 #include "FWCore/Framework/interface/Event.h"
00019 #include "FWCore/Framework/interface/MakerMacros.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "FWCore/Framework/interface/ConstProductRegistry.h"
00023 #include "FWCore/ServiceRegistry/interface/Service.h"
00024 
00025 #include "DataFormats/Provenance/interface/ProductID.h"
00026 #include "DataFormats/Provenance/interface/ParameterSetID.h"
00027 #include "DataFormats/Provenance/interface/Provenance.h"
00028 #include "DataFormats/Provenance/interface/BranchDescription.h"
00029 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00030 
00031 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBGroupRcd.h"
00032 #include "CondFormats/DataRecord/interface/EcalTPGLutGroupRcd.h"
00033 #include "CondFormats/DataRecord/interface/EcalTPGLutIdMapRcd.h"
00034 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBIdMapRcd.h"
00035 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainTowerEERcd.h"
00036 #include "CondFormats/DataRecord/interface/EcalTPGCrystalStatusRcd.h"
00037 #include "CondFormats/DataRecord/interface/EcalTPGTowerStatusRcd.h"
00038 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBGroup.h"
00039 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
00040 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
00041 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBIdMap.h"
00042 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainTowerEE.h"
00043 #include "CondFormats/DataRecord/interface/EcalTPGLinearizationConstRcd.h"
00044 #include "CondFormats/DataRecord/interface/EcalTPGPedestalsRcd.h"
00045 #include "CondFormats/DataRecord/interface/EcalTPGSlidingWindowRcd.h"
00046 #include "CondFormats/DataRecord/interface/EcalTPGWeightIdMapRcd.h"
00047 #include "CondFormats/DataRecord/interface/EcalTPGWeightGroupRcd.h"
00048 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainStripEERcd.h"
00049 #include "CondFormats/EcalObjects/interface/EcalTPGLinearizationConst.h"
00050 #include "CondFormats/EcalObjects/interface/EcalTPGPedestals.h"
00051 #include "CondFormats/EcalObjects/interface/EcalTPGSlidingWindow.h"
00052 #include "CondFormats/EcalObjects/interface/EcalTPGWeightIdMap.h"
00053 #include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h"
00054 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainStripEE.h"
00055 #include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h"
00056 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
00057 
00058 #include "EcalTrigPrimProducer.h"
00059 #include "SimCalorimetry/EcalTrigPrimAlgos/interface/EcalTrigPrimFunctionalAlgo.h"
00060 
00061 EcalTrigPrimProducer::EcalTrigPrimProducer(const edm::ParameterSet&  iConfig):
00062   barrelOnly_(iConfig.getParameter<bool>("BarrelOnly")),
00063   tcpFormat_(iConfig.getParameter<bool>("TcpOutput")),
00064   debug_(iConfig.getParameter<bool>("Debug")),ps_(iConfig)
00065 {  
00066   //register your products
00067   produces <EcalTrigPrimDigiCollection >();
00068   if (tcpFormat_) produces <EcalTrigPrimDigiCollection >("formatTCP");
00069 
00070   label_= iConfig.getParameter<std::string>("Label");
00071   instanceNameEB_ = iConfig.getParameter<std::string>("InstanceEB");;
00072   instanceNameEE_ = iConfig.getParameter<std::string>("InstanceEE");;
00073   algo_=NULL;
00074 }
00075 
00076 void EcalTrigPrimProducer::beginRun(edm::Run & run,edm::EventSetup const& setup) {
00077   bool famos = ps_.getParameter<bool>("Famos");
00078 
00079   algo_ = new EcalTrigPrimFunctionalAlgo(setup,binOfMaximum_,tcpFormat_,barrelOnly_,debug_,famos);
00080 
00081   // get a first version of the records
00082   cacheID_=this->getRecords(setup);
00083 }
00084 
00085 void EcalTrigPrimProducer::endRun(edm::Run & run,edm::EventSetup const& setup) {
00086   delete algo_;
00087 }
00088 
00089 void EcalTrigPrimProducer::beginJob() {
00090   
00091   //  get  binOfMax
00092   //  try first in cfg, then in ProductRegistry
00093   //  =6 is default (1-10 possible values)
00094   binOfMaximum_=0;  //starts at 1!
00095   bool found=false;
00096   std::vector<std::string> names = ps_.getParameterNames();
00097   if (find(names.begin(), names.end(), std::string("binOfMaximum"))
00098       != names.end()) {
00099     binOfMaximum_=ps_.getParameter<int>("binOfMaximum");
00100     edm::LogInfo("EcalTPG") <<"EcalTrigPrimProducer is using binOfMaximum found in cfg file :  "<<binOfMaximum_;
00101     found = true;
00102   }
00103   
00104   edm::Service<edm::ConstProductRegistry> reg;
00105   // Loop over provenance of products in registry.
00106   for (edm::ProductRegistry::ProductList::const_iterator it =  reg->productList().begin();
00107        it != reg->productList().end(); ++it) {
00108     edm::BranchDescription desc = it->second;
00109     if (desc.friendlyClassName().find("EBDigiCollection")==0  &&
00110         desc.moduleLabel()=="ecalUnsuppressedDigis") {
00111       edm::ParameterSet result = getParameterSet(desc.psetID());
00112       if (found ) {
00113         if ( result.getParameter<int>("binOfMaximum")!=binOfMaximum_)edm:: LogWarning("EcalTPG")<< "binofMaximum given in configuration (="<<binOfMaximum_<<") is different from the one found in ProductRegistration(="<<result.getParameter<int>("binOfMaximum")<<")!!!";
00114       }else {
00115         binOfMaximum_=result.getParameter<int>("binOfMaximum");
00116         edm::LogInfo("EcalTPG") <<"EcalTrigPrimProducer is using binOfMaximum found in ProductRegistry :  "<<binOfMaximum_;
00117         break;
00118       }
00119     }
00120   }
00121 
00122 
00123   if (binOfMaximum_==0) {
00124     binOfMaximum_=6;
00125     edm::LogWarning("EcalTPG")<<"Could not find product registry of EBDigiCollection (label ecalUnsuppressedDigis), had to set the following parameters by Hand:  binOfMaximum="<<binOfMaximum_;
00126   }
00127 }
00128 
00129 unsigned long long  EcalTrigPrimProducer::getRecords(edm::EventSetup const& setup) {
00130   // get Eventsetup records
00131 
00132   // for EcalFenixStrip...
00133   // get parameter records for xtals
00134   edm::ESHandle<EcalTPGLinearizationConst> theEcalTPGLinearization_handle;
00135   setup.get<EcalTPGLinearizationConstRcd>().get(theEcalTPGLinearization_handle);
00136   const EcalTPGLinearizationConst * ecaltpLin = theEcalTPGLinearization_handle.product();
00137   edm::ESHandle<EcalTPGPedestals> theEcalTPGPedestals_handle;
00138   setup.get<EcalTPGPedestalsRcd>().get(theEcalTPGPedestals_handle);
00139   const EcalTPGPedestals * ecaltpPed = theEcalTPGPedestals_handle.product();
00140   edm::ESHandle<EcalTPGCrystalStatus> theEcalTPGCrystalStatus_handle;
00141   setup.get<EcalTPGCrystalStatusRcd>().get(theEcalTPGCrystalStatus_handle);
00142   const EcalTPGCrystalStatus * ecaltpgBadX = theEcalTPGCrystalStatus_handle.product();
00143 
00144 
00145   //for strips
00146   edm::ESHandle<EcalTPGSlidingWindow> theEcalTPGSlidingWindow_handle;
00147   setup.get<EcalTPGSlidingWindowRcd>().get(theEcalTPGSlidingWindow_handle);
00148   const EcalTPGSlidingWindow * ecaltpgSlidW = theEcalTPGSlidingWindow_handle.product();
00149   edm::ESHandle<EcalTPGWeightIdMap> theEcalTPGWEightIdMap_handle;
00150   setup.get<EcalTPGWeightIdMapRcd>().get(theEcalTPGWEightIdMap_handle);
00151   const EcalTPGWeightIdMap * ecaltpgWeightMap = theEcalTPGWEightIdMap_handle.product();
00152   edm::ESHandle<EcalTPGWeightGroup> theEcalTPGWEightGroup_handle;
00153   setup.get<EcalTPGWeightGroupRcd>().get(theEcalTPGWEightGroup_handle);
00154   const EcalTPGWeightGroup * ecaltpgWeightGroup = theEcalTPGWEightGroup_handle.product();
00155   edm::ESHandle<EcalTPGFineGrainStripEE> theEcalTPGFineGrainStripEE_handle;
00156   setup.get<EcalTPGFineGrainStripEERcd>().get(theEcalTPGFineGrainStripEE_handle);
00157   const EcalTPGFineGrainStripEE * ecaltpgFgStripEE = theEcalTPGFineGrainStripEE_handle.product();     
00158  
00159   algo_->setPointers(ecaltpLin,ecaltpPed,ecaltpgSlidW,ecaltpgWeightMap,ecaltpgWeightGroup,ecaltpgFgStripEE,ecaltpgBadX);
00160 
00161   // .. and for EcalFenixTcp
00162   // get parameter records for towers
00163   edm::ESHandle<EcalTPGFineGrainEBGroup> theEcalTPGFineGrainEBGroup_handle;
00164   setup.get<EcalTPGFineGrainEBGroupRcd>().get(theEcalTPGFineGrainEBGroup_handle);
00165   const EcalTPGFineGrainEBGroup * ecaltpgFgEBGroup = theEcalTPGFineGrainEBGroup_handle.product();
00166 
00167   edm::ESHandle<EcalTPGLutGroup> theEcalTPGLutGroup_handle;
00168   setup.get<EcalTPGLutGroupRcd>().get(theEcalTPGLutGroup_handle);
00169   const EcalTPGLutGroup * ecaltpgLutGroup = theEcalTPGLutGroup_handle.product();
00170 
00171   edm::ESHandle<EcalTPGLutIdMap> theEcalTPGLutIdMap_handle;
00172   setup.get<EcalTPGLutIdMapRcd>().get(theEcalTPGLutIdMap_handle);
00173   const EcalTPGLutIdMap * ecaltpgLut = theEcalTPGLutIdMap_handle.product();
00174 
00175   edm::ESHandle<EcalTPGFineGrainEBIdMap> theEcalTPGFineGrainEBIdMap_handle;
00176   setup.get<EcalTPGFineGrainEBIdMapRcd>().get(theEcalTPGFineGrainEBIdMap_handle);
00177   const EcalTPGFineGrainEBIdMap * ecaltpgFineGrainEB = theEcalTPGFineGrainEBIdMap_handle.product();
00178 
00179   edm::ESHandle<EcalTPGFineGrainTowerEE> theEcalTPGFineGrainTowerEE_handle;
00180   setup.get<EcalTPGFineGrainTowerEERcd>().get(theEcalTPGFineGrainTowerEE_handle);
00181   const EcalTPGFineGrainTowerEE * ecaltpgFineGrainTowerEE = theEcalTPGFineGrainTowerEE_handle.product();
00182 
00183   edm::ESHandle<EcalTPGTowerStatus> theEcalTPGTowerStatus_handle;
00184   setup.get<EcalTPGTowerStatusRcd>().get(theEcalTPGTowerStatus_handle);
00185   const EcalTPGTowerStatus * ecaltpgBadTT = theEcalTPGTowerStatus_handle.product();
00186 
00187 
00188   algo_->setPointers2(ecaltpgFgEBGroup,ecaltpgLutGroup,ecaltpgLut,ecaltpgFineGrainEB,ecaltpgFineGrainTowerEE,ecaltpgBadTT);
00189 
00190   // we will suppose that everything is to be updated if the EcalTPGLinearizationConstRcd has changed
00191   return setup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier();
00192 }
00193 
00194 EcalTrigPrimProducer::~EcalTrigPrimProducer()
00195 {}
00196 
00197 
00198 // ------------ method called to produce the data  ------------
00199 void
00200 EcalTrigPrimProducer::produce(edm::Event& e, const edm::EventSetup&  iSetup)
00201 {
00202 
00203   // update constants if necessary
00204   if (iSetup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier()!=cacheID_) cacheID_=this->getRecords(iSetup);
00205 
00206   // get input collections
00207 
00208   edm::Handle<EBDigiCollection> ebDigis;
00209   edm::Handle<EEDigiCollection> eeDigis;
00210   bool barrel=true;
00211   bool endcap=true;
00212   if (barrelOnly_) endcap=false;
00213 
00214   if (!e.getByLabel(label_,instanceNameEB_,ebDigis)) {
00215     barrel=false;
00216     edm::LogWarning("EcalTPG") <<" Couldnt find Barrel dataframes with producer "<<label_<<" and label "<<instanceNameEB_<<"!!!";
00217   }
00218   if (!barrelOnly_) {
00219     if (!e.getByLabel(label_,instanceNameEE_,eeDigis)) {
00220       endcap=false;
00221       edm::LogWarning("EcalTPG") <<" Couldnt find Endcap dataframes with producer "<<label_<<" and label "<<instanceNameEE_<<"!!!";
00222     }
00223   }
00224   if (!barrel && !endcap) {
00225     throw cms::Exception(" ProductNotFound") <<"No EBDataFrames(EEDataFrames) with producer "<<label_<<" and label "<<instanceNameEB_<<" found in input!!\n";
00226   }
00227 
00228   if (!barrelOnly_)   LogDebug("EcalTPG") <<" =================> Treating event  "<<e.id()<<", Number of EBDataFrames "<<ebDigis.product()->size()<<", Number of EEDataFrames "<<eeDigis.product()->size() ;
00229   else  LogDebug("EcalTPG") <<" =================> Treating event  "<<e.id()<<", Number of EBDataFrames "<<ebDigis.product()->size();
00230 
00231   std::auto_ptr<EcalTrigPrimDigiCollection> pOut(new  EcalTrigPrimDigiCollection);
00232   std::auto_ptr<EcalTrigPrimDigiCollection> pOutTcp(new  EcalTrigPrimDigiCollection);
00233  
00234 
00235   // invoke algorithm 
00236 
00237   const EBDigiCollection *ebdc=NULL;
00238   const EEDigiCollection *eedc=NULL;
00239   if (barrel) {
00240     ebdc=ebDigis.product();
00241     algo_->run(iSetup,ebdc,*pOut,*pOutTcp);
00242   }
00243 
00244   if (endcap) {
00245     eedc=eeDigis.product();
00246     algo_->run(iSetup,eedc,*pOut,*pOutTcp);
00247   }
00248 
00249   edm::LogInfo("produce") <<"For Barrel + Endcap, "<<pOut->size()<<" TP  Digis were produced";
00250 
00251   //  debug prints if TP >0
00252 
00253   for (unsigned int i=0;i<pOut->size();++i) {
00254     bool print=false;
00255     for (int isam=0;isam<(*pOut)[i].size();++isam) {
00256       if ((*pOut)[i][isam].raw()) print=true;
00257     }
00258     if (print) LogDebug("EcalTPG") <<" For tower  "<<(((*pOut)[i])).id()<<", TP is "<<(*pOut)[i];
00259   }
00260   if (barrelOnly_)  LogDebug("EcalTPG") <<"\n =================> For Barrel , "<<pOut->size()<<" TP  Digis were produced (including zero ones)";
00261   else      LogDebug("EcalTPG") <<"\n =================> For Barrel + Endcap, "<<pOut->size()<<" TP  Digis were produced (including zero ones)";
00262 
00263   // put result into the Event
00264 
00265   e.put(pOut);
00266   if (tcpFormat_) e.put(pOutTcp,"formatTCP");
00267 }