CMS 3D CMS Logo

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