CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SimCalorimetry/HcalSimAlgos/interface/HcalSignalGenerator.h

Go to the documentation of this file.
00001 #ifndef HcalSimAlgos_HcalSignalGenerator_h
00002 #define HcalSimAlgos_HcalSignalGenerator_h
00003 
00004 #include "SimCalorimetry/HcalSimAlgos/interface/HcalBaseSignalGenerator.h"
00005 #include "FWCore/Framework/interface/Selector.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
00010 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
00011 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00012 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00013 #include "SimCalorimetry/HcalSimAlgos/interface/HcalElectronicsSim.h"
00014 #include "SimCalorimetry/HcalSimAlgos/interface/HcalDigitizerTraits.h"
00015 #include "DataFormats/Common/interface/Handle.h"
00016 
00021 #include <iostream>
00022 
00023 template<class HCALDIGITIZERTRAITS>
00024 class HcalSignalGenerator : public HcalBaseSignalGenerator
00025 {
00026 public:
00027   typedef typename HCALDIGITIZERTRAITS::Digi DIGI;
00028   typedef typename HCALDIGITIZERTRAITS::DigiCollection COLLECTION;
00029 
00030   HcalSignalGenerator(const edm::InputTag & inputTag)
00031   : HcalBaseSignalGenerator(), theEvent(0), theEventPrincipal(0), theShape(0),  theInputTag(inputTag) {}
00032 
00033   virtual ~HcalSignalGenerator() {}
00034 
00035   void initializeEvent(const edm::Event * event, const edm::EventSetup * eventSetup)
00036   {
00037     theEvent = event;
00038     eventSetup->get<HcalDbRecord>().get(theConditions);
00039     theShape = theConditions->getHcalShape (); // this one is generic
00040     theParameterMap->setDbService(theConditions.product());
00041   }
00042 
00044   void initializeEvent(const edm::EventPrincipal * eventPrincipal, const edm::EventSetup * eventSetup)
00045   {
00046     theEventPrincipal = eventPrincipal;
00047     eventSetup->get<HcalDbRecord>().get(theConditions);
00048     theShape = theConditions->getHcalShape (); // this one is generic
00049     theParameterMap->setDbService(theConditions.product());
00050   }
00051 
00052   virtual void fill()
00053   {
00054     theNoiseSignals.clear();
00055     edm::Handle<COLLECTION> pDigis;
00056     const COLLECTION *  digis = 0;
00057     // try accessing by whatever is set, Event or EventPrincipal
00058     if(theEvent) 
00059      {
00060       if( theEvent->getByLabel(theInputTag, pDigis) ) {
00061         digis = pDigis.product(); // get a ptr to the product
00062         LogTrace("HcalSignalGenerator") << "total # digis  for "  << theInputTag << " " <<  digis->size();
00063       }
00064       else
00065       {
00066         throw cms::Exception("HcalSignalGenerator") << "Cannot find input data " << theInputTag;
00067       }
00068     }
00069     else if(theEventPrincipal)
00070     {
00071        boost::shared_ptr<edm::Wrapper<COLLECTION>  const> digisPTR =
00072           edm::getProductByTag<COLLECTION>(*theEventPrincipal, theInputTag );
00073        if(digisPTR) {
00074           digis = digisPTR->product();
00075        }
00076     }
00077     else
00078     {
00079       throw cms::Exception("HcalSignalGenerator") << "No Event or EventPrincipal was set";
00080     }
00081 
00082     if (digis)
00083     {
00084       // loop over digis, adding these to the existing maps
00085       for(typename COLLECTION::const_iterator it  = digis->begin();
00086           it != digis->end(); ++it) 
00087       {
00088         // for the first signal, set the starting cap id
00089         if((it == digis->begin()) && theElectronicsSim)
00090         {
00091           int startingCapId = (*it)[0].capid();
00092           theElectronicsSim->setStartingCapId(startingCapId);
00093           theParameterMap->setFrameSize(it->id(), it->size());
00094         }
00095 
00096         theNoiseSignals.push_back(samplesInPE(*it));
00097       }
00098     }
00099   }
00100 
00101 private:
00102 
00103   CaloSamples samplesInPE(const DIGI & digi)
00104   {
00105     // calibration, for future reference:  (same block for all Hcal types)
00106     HcalDetId cell = digi.id();
00107     //         const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
00108     const HcalQIECoder* channelCoder = theConditions->getHcalCoder (cell);
00109     HcalCoderDb coder (*channelCoder, *theShape);
00110     CaloSamples result;
00111     coder.adc2fC(digi, result);
00112     fC2pe(result);
00113     return result;
00114   }
00115 
00116     
00118   const edm::Event * theEvent;
00119   const edm::EventPrincipal * theEventPrincipal;
00120   edm::ESHandle<HcalDbService> theConditions;
00121   const HcalQIEShape* theShape;
00123   edm::InputTag theInputTag;
00124 };
00125 
00126 typedef HcalSignalGenerator<HBHEDigitizerTraits> HBHESignalGenerator;
00127 typedef HcalSignalGenerator<HODigitizerTraits>   HOSignalGenerator;
00128 typedef HcalSignalGenerator<HFDigitizerTraits>   HFSignalGenerator;
00129 typedef HcalSignalGenerator<ZDCDigitizerTraits>  ZDCSignalGenerator;
00130 
00131 #endif
00132