CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/SimCalorimetry/EcalTestBeam/src/EcalTBDigiProducer.cc

Go to the documentation of this file.
00001 
00002 #include "SimCalorimetry/EcalTestBeam/interface/EcalTBDigiProducer.h"
00003 #include "SimDataFormats/EcalTestBeam/interface/PEcalTBInfo.h"
00004 #include "FWCore/Framework/interface/EDProducer.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "DataFormats/Common/interface/Handle.h"
00008 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00009 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00010 #include "SimCalorimetry/EcalSimAlgos/interface/EcalSimParameterMap.h"
00011 #include "SimCalorimetry/EcalSimAlgos/interface/EBHitResponse.h"
00012 #include "SimCalorimetry/EcalSimAlgos/interface/EEHitResponse.h"
00013 
00014 EcalTBDigiProducer::EcalTBDigiProducer( const edm::ParameterSet& params, edm::EDProducer& mixMod ) :
00015    EcalDigiProducer( params, mixMod )
00016 {
00017    std::string const instance("simEcalUnsuppressedDigis");
00018    m_EBdigiFinalTag = params.getParameter<std::string>( "EBdigiFinalCollection" ) ;
00019    m_EBdigiTempTag  = params.getParameter<std::string>( "EBdigiCollection");
00020 
00021    mixMod.produces<EBDigiCollection>(instance + m_EBdigiFinalTag) ; // after selective readout
00022    mixMod.produces<EcalTBTDCRawInfo>(instance) ;
00023 
00024    const bool syncPhase ( params.getParameter<bool>("syncPhase") ) ;
00025 
00026    // possible phase shift for asynchronous trigger (e.g. test-beam)
00027 
00028    m_doPhaseShift = !syncPhase ;
00029    m_thisPhaseShift = 1. ;
00030 
00031    typedef std::vector< edm::ParameterSet > Parameters;
00032    Parameters ranges=params.getParameter<Parameters>( "tdcRanges" ) ;
00033    for( Parameters::iterator itRanges = ranges.begin(); 
00034         itRanges != ranges.end(); ++itRanges )
00035    {
00036       EcalTBTDCRecInfoAlgo::EcalTBTDCRanges aRange;
00037       aRange.runRanges.first = itRanges->getParameter<int>("startRun");
00038       aRange.runRanges.second = itRanges->getParameter<int>("endRun");
00039       aRange.tdcMin = itRanges->getParameter< std::vector<double> >("tdcMin");
00040       aRange.tdcMax = itRanges->getParameter< std::vector<double> >("tdcMax");
00041       m_tdcRanges.push_back(std::move(aRange));
00042    }
00043 
00044    m_use2004OffsetConvention = 
00045       params.getUntrackedParameter< bool >("use2004OffsetConvention",
00046                                            false ) ;
00047 
00048    m_ecalTBInfoLabel =
00049       params.getUntrackedParameter<std::string>( "EcalTBInfoLabel" ,
00050                                                  "SimEcalTBG4Object" ) ;
00051 
00052    m_doReadout = params.getParameter<bool>( "doReadout" ) ;
00053 
00054    m_theTBReadout = new EcalTBReadout( m_ecalTBInfoLabel ) ;
00055 
00056    m_tunePhaseShift =  params.getParameter<double>( "tunePhaseShift" ) ;
00057 }
00058 
00059 EcalTBDigiProducer::~EcalTBDigiProducer()
00060 {
00061 }
00062 
00063 void EcalTBDigiProducer::initializeEvent(edm::Event const& event, edm::EventSetup const& eventSetup) {
00064   std::cout<<"====****Entering EcalTBDigiProducer produce()"<<std::endl ;
00065    edm::ESHandle<CaloGeometry>               hGeometry ;
00066    eventSetup.get<CaloGeometryRecord>().get( hGeometry ) ;
00067    const std::vector<DetId>& theBarrelDets (
00068       hGeometry->getValidDetIds(DetId::Ecal, EcalBarrel) ) ;
00069 
00070    m_theTBReadout->setDetIds( theBarrelDets ) ;
00071 
00072    m_TDCproduct.reset( new EcalTBTDCRawInfo(1) ) ;
00073    if( m_doPhaseShift ) 
00074    {
00075       edm::Handle<PEcalTBInfo>             theEcalTBInfo   ;
00076       event.getByLabel( m_ecalTBInfoLabel, theEcalTBInfo ) ;
00077       m_thisPhaseShift = theEcalTBInfo->phaseShift() ;
00078 
00079       DetId detId( DetId::Ecal, 1 ) ;
00080       setPhaseShift( detId ) ;
00081 
00082       fillTBTDCRawInfo( *m_TDCproduct ) ; // fill the TDC info in the event    
00083    }
00084    EcalDigiProducer::initializeEvent( event, eventSetup ) ;
00085 }
00086 
00087 void EcalTBDigiProducer::finalizeEvent( edm::Event& event, const edm::EventSetup& eventSetup ) {
00088    m_ebDigis.reset( new EBDigiCollection ) ;
00089 
00090    EcalDigiProducer::finalizeEvent( event, eventSetup ) ;
00091 
00092    const EBDigiCollection* barrelResult ( &*m_ebDigis ) ;
00093 
00094    std::auto_ptr<EBDigiCollection> barrelReadout( new EBDigiCollection() ) ;
00095    if( m_doReadout ) 
00096    {
00097       m_theTBReadout->performReadout( event,
00098                                       m_theTTmap,
00099                                       *barrelResult,
00100                                       *barrelReadout ) ;
00101    }
00102    else 
00103    {
00104       *barrelReadout = *barrelResult ;
00105    }
00106 
00107    std::cout<< "===**** EcalTBDigiProducer: number of barrel digis = "
00108             << barrelReadout->size()<<std::endl ;
00109 
00110    std::string const instance("simEcalUnsuppressedDigis");
00111    event.put(barrelReadout, instance + m_EBdigiFinalTag) ;
00112    event.put(m_TDCproduct, instance) ;
00113 
00114    m_ebDigis.reset(); // release memory
00115    m_eeDigis.reset(); // release memory
00116 }
00117 
00118 void 
00119 EcalTBDigiProducer::setPhaseShift( const DetId& detId ) 
00120 {  
00121    const CaloSimParameters& parameters ( 
00122       EcalDigiProducer::m_ParameterMap->simParameters( detId ) ) ;
00123 
00124    if ( !parameters.syncPhase() ) 
00125    {
00126       const int myDet ( detId.subdetId() ) ;
00127 
00128       LogDebug("EcalDigi") << "Setting the phase shift " 
00129                            << m_thisPhaseShift 
00130                            << " and the offset " 
00131                            << m_tunePhaseShift 
00132                            << " for the subdetector " 
00133                            << myDet;
00134 
00135       if( myDet == 1 ) 
00136       {
00137          double passPhaseShift ( m_thisPhaseShift + m_tunePhaseShift ) ;
00138          if( m_use2004OffsetConvention ) passPhaseShift = 1. - passPhaseShift ;
00139          EcalDigiProducer::m_EBResponse->setPhaseShift( passPhaseShift ) ;
00140          EcalDigiProducer::m_EEResponse->setPhaseShift( passPhaseShift ) ;
00141       }
00142    }
00143 }
00144 
00145 void 
00146 EcalTBDigiProducer::fillTBTDCRawInfo( EcalTBTDCRawInfo& theTBTDCRawInfo ) 
00147 {
00148    const unsigned int thisChannel ( 1 ) ;
00149   
00150    const unsigned int thisCount ( 
00151       (unsigned int)( m_thisPhaseShift*( m_tdcRanges[0].tdcMax[0]
00152                                          - m_tdcRanges[0].tdcMin[0] ) 
00153                       + m_tdcRanges[0].tdcMin[0] ) ) ;
00154 
00155    EcalTBTDCSample theTBTDCSample ( thisChannel, thisCount ) ;
00156 
00157    const unsigned int sampleIndex ( 0 ) ;
00158    theTBTDCRawInfo.setSample( sampleIndex, theTBTDCSample ) ;
00159 
00160    LogDebug("EcalDigi") << theTBTDCSample << "\n" << theTBTDCRawInfo ;
00161 }
00162 
00163 void 
00164 EcalTBDigiProducer::cacheEBDigis( const EBDigiCollection* ebDigiPtr ) const
00165 {
00166    m_ebDigis.reset( new EBDigiCollection ) ;
00167    *m_ebDigis = *ebDigiPtr ;
00168 }
00169 
00170 void 
00171 EcalTBDigiProducer::cacheEEDigis( const EEDigiCollection* eeDigiPtr ) const
00172 {
00173    std::cout<< "===**** EcalTBDigiProducer: number of endcap digis = "
00174             << eeDigiPtr->size()<<std::endl ;
00175 }