CMS 3D CMS Logo

EcalTrigPrimProducer.cc

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

Generated on Tue Jun 9 17:46:22 2009 for CMSSW by  doxygen 1.5.4