CMS 3D CMS Logo

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