CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/SLHCUpgradeSimulations/L1CaloTrigger/plugins/L1CaloTowerProducer.cc

Go to the documentation of this file.
00001 /* L1CaloTowerProducer Reads TPGs, fixes the energy scale compression and
00002    produces towers
00003 
00004    M.Bachtis,S.Dasu University of Wisconsin-Madison
00005 
00006    Modified Andrew W. Rose Imperial College, London */
00007 
00008 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00009 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00010 
00011 // Includes for the Calo Scales
00012 #include "CondFormats/DataRecord/interface/L1CaloEcalScaleRcd.h"
00013 #include "CondFormats/L1TObjects/interface/L1CaloEcalScale.h"
00014 #include "CondFormats/DataRecord/interface/L1CaloHcalScaleRcd.h"
00015 #include "CondFormats/L1TObjects/interface/L1CaloHcalScale.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 // system include files
00018 #include <memory>
00019 
00020 // user include files
00021 #include "FWCore/Framework/interface/Frameworkfwd.h"
00022 #include "FWCore/Framework/interface/EDProducer.h"
00023 #include "FWCore/Framework/interface/Event.h"
00024 #include "FWCore/Framework/interface/ESHandle.h"
00025 #include "FWCore/Framework/interface/MakerMacros.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
00028 #include "DataFormats/HcalDigi/interface/HcalTriggerPrimitiveDigi.h"
00029 
00030 #include "SimDataFormats/SLHC/interface/L1CaloTower.h"
00031 #include "SimDataFormats/SLHC/interface/L1CaloTowerFwd.h"
00032 #include "SimDataFormats/SLHC/interface/L1CaloTriggerSetup.h"
00033 #include "SimDataFormats/SLHC/interface/L1CaloTriggerSetupRcd.h"
00034 
00035 #include <map>
00036 #include <deque>
00037 
00038 
00039 class L1CaloTowerProducer:public edm::EDProducer
00040 {
00041   public:
00042         explicit L1CaloTowerProducer( const edm::ParameterSet & );
00043          ~L1CaloTowerProducer(  );
00044 
00045   private:
00046 
00047         virtual void produce( edm::Event &, const edm::EventSetup & );
00048         virtual void endJob(  );
00049 
00050         void addHcal( const int &, const int &, const int &, const bool & );
00051         void addEcal( const int &, const int &, const int &, const bool & );
00052 
00053         std::auto_ptr < l1slhc::L1CaloTowerCollection > mCaloTowers;
00054 
00055         const L1CaloTriggerSetup *mCaloTriggerSetup;
00056         const L1CaloEcalScale *mEcalScale;
00057         const L1CaloHcalScale *mHcalScale;
00058 
00059         // Calorimeter Digis
00060         edm::InputTag mEcalDigiInputTag;
00061         edm::InputTag mHcalDigiInputTag;
00062 
00063         bool mUseupgradehcal;
00064 };
00065 
00066 
00067 
00068 
00069 L1CaloTowerProducer::L1CaloTowerProducer( const edm::ParameterSet & aConfig ):
00070   mCaloTowers( NULL ),
00071   mEcalDigiInputTag( aConfig.getParameter < edm::InputTag > ( "ECALDigis" ) ),
00072   mHcalDigiInputTag( aConfig.getParameter < edm::InputTag > ( "HCALDigis" ) ),
00073   mUseupgradehcal( aConfig.getParameter < bool > ( "UseUpgradeHCAL" ) )
00074 {
00075   // Register Product
00076   produces < l1slhc::L1CaloTowerCollection > (  );
00077 }
00078 
00079 
00080 L1CaloTowerProducer::~L1CaloTowerProducer(  )
00081 {
00082 
00083 }
00084 
00085 void L1CaloTowerProducer::addHcal( const int &aCompressedEt, const int &aIeta,
00086                                                                    const int &aIphi, const bool & aFG )
00087 {
00088         if ( aCompressedEt > 0 )
00089         {
00090                 int lET = ( int )( 2 * mHcalScale->et( aCompressedEt,
00091                                                                                            abs( aIeta ),
00092                                                                                            ( aIeta > 0 ? +1 : -1 ) ) );
00093 
00094                 l1slhc::L1CaloTowerCollection::iterator lItr = mCaloTowers -> find ( aIeta, aIphi  );
00095 
00096                 if ( lItr != ( *mCaloTowers ).end(  ) )
00097                 {
00098                         if ( lET > mCaloTriggerSetup->hcalActivityThr(  ) )
00099                                 lItr->setHcal( lET, aFG );
00100                 }
00101                 else
00102                 {
00103                         l1slhc::L1CaloTower lCaloTower( aIeta, aIphi );
00104                         lCaloTower.setHcal( lET, aFG );
00105                         if ( lET > mCaloTriggerSetup->hcalActivityThr(  ) )
00106                                 mCaloTowers->insert( aIeta , aIphi , lCaloTower );
00107                 }
00108         }
00109 }
00110 
00111 void L1CaloTowerProducer::addEcal( const int &aCompressedEt, const int &aIeta,
00112                                                                    const int &aIphi, const bool & aFG )
00113 {
00114         if ( aCompressedEt > 0 )
00115         {
00116                 int lET = ( int )( 2 * mEcalScale->et( aCompressedEt,
00117                                                                                            abs( aIeta ),
00118                                                                                            ( aIeta > 0 ? +1 : -1 ) ) );
00119 
00120                 l1slhc::L1CaloTower lCaloTower( aIeta, aIphi );
00121                 lCaloTower.setEcal( lET, aFG );
00122 
00123                 if ( lET > mCaloTriggerSetup->ecalActivityThr(  ) )
00124                         mCaloTowers->insert( aIeta , aIphi , lCaloTower );
00125 
00126         }
00127 }
00128 
00129 void L1CaloTowerProducer::produce( edm::Event & aEvent,
00130                                                                    const edm::EventSetup & aSetup )
00131 {
00132 
00133         // create a new l1slhc::L1CaloTowerCollection (auto_ptr should handle deletion of the last one correctly)
00134         mCaloTowers = std::auto_ptr < l1slhc::L1CaloTowerCollection > ( new l1slhc::L1CaloTowerCollection );
00135 
00136         // Setup Calo Scales
00137         edm::ESHandle < L1CaloEcalScale > lEcalScaleHandle;
00138         aSetup.get < L1CaloEcalScaleRcd > (  ).get( lEcalScaleHandle );
00139         mEcalScale = lEcalScaleHandle.product(  );
00140 
00141         edm::ESHandle < L1CaloHcalScale > lHcalScaleHandle;
00142         aSetup.get < L1CaloHcalScaleRcd > (  ).get( lHcalScaleHandle );
00143         mHcalScale = lHcalScaleHandle.product(  );
00144 
00145         // get Tower Thresholds
00146         edm::ESHandle < L1CaloTriggerSetup > mCaloTriggerSetupHandle;
00147         aSetup.get < L1CaloTriggerSetupRcd > (  ).get( mCaloTriggerSetupHandle );
00148         mCaloTriggerSetup = mCaloTriggerSetupHandle.product(  );
00149 
00150 
00151         // Loop through the TPGs
00152         //getting data from event takes 3 orders of magnitude longer than anything else in the program : O(10-100ms) cf O(10-100us)
00153         edm::Handle < EcalTrigPrimDigiCollection > lEcalDigiHandle;
00154         aEvent.getByLabel( mEcalDigiInputTag, lEcalDigiHandle );
00155 
00156         for ( EcalTrigPrimDigiCollection::const_iterator lEcalTPItr = lEcalDigiHandle->begin(  ); lEcalTPItr != lEcalDigiHandle->end(  ); ++lEcalTPItr )
00157                 addEcal( lEcalTPItr->compressedEt(  ), lEcalTPItr->id(  ).ieta(  ), lEcalTPItr->id(  ).iphi(  ), lEcalTPItr->fineGrain(  ) );
00158 
00159         if ( !mUseupgradehcal )
00160         {
00161                 //getting data from event takes 3 orders of magnitude longer than anything else in the program : O(10-100ms) cf O(10-100us)
00162                 edm::Handle < HcalTrigPrimDigiCollection > lHcalDigiHandle;
00163                 aEvent.getByLabel( mHcalDigiInputTag, lHcalDigiHandle );
00164 
00165                 for ( HcalTrigPrimDigiCollection::const_iterator lHcalTPItr = lHcalDigiHandle->begin(  ); lHcalTPItr != lHcalDigiHandle->end(  ); ++lHcalTPItr )
00166                         addHcal( lHcalTPItr->SOI_compressedEt(  ), lHcalTPItr->id(  ).ieta(  ), lHcalTPItr->id(  ).iphi(  ), lHcalTPItr->SOI_fineGrain(  ) );
00167         }
00168         else
00169         {
00170           // Detect if the upgrade HCAL header file is included
00171 #ifdef DIGIHCAL_HCALUPGRADETRIGGERPRIMITIVEDIGI_H
00172 #warning Not really a warning: just letting you know that Im enabling upgrade HCAL digis
00173                 //getting data from event takes 3 orders of magnitude longer than anything else in the program : O(10-100ms) cf O(10-100us)
00174                 edm::Handle < HcalUpgradeTrigPrimDigiCollection > lHcalDigiHandle;
00175                 aEvent.getByLabel( mHcalDigiInputTag, lHcalDigiHandle );
00176 
00177                 for ( HcalUpgradeTrigPrimDigiCollection::const_iterator lHcalTPItr = lHcalDigiHandle->begin(  ); lHcalTPItr != lHcalDigiHandle->end(  ); ++lHcalTPItr )
00178                         addHcal( lHcalTPItr->SOI_compressedEt(  ), lHcalTPItr->id(  ).ieta(  ), lHcalTPItr->id(  ).iphi(  ), lHcalTPItr->SOI_fineGrain(  ) );
00179 #else
00180 #warning Not really a warning: just letting you know that Im NOT enabling upgrade HCAL digis
00181                 // If the user tries to specify this option, but it isn't
00182                 // available, throw an exception.
00183                 throw cms::Exception("NotImplmented") <<
00184                   "You requested to use the upgrade HCAL digis.  However the "
00185                   << "L1CaloTowerProducer.cc module was not compiled with "
00186                   << "support for them.  "
00187                   << "Please edit SLHCUpSims/L1CaloTrig/plugins/L1CaloTowerProducer.cc" << std::endl;
00188 #endif
00189         }
00190         aEvent.put( mCaloTowers );
00191 }
00192 
00193 
00194 // ------------ method called once each job just after ending the event loop
00195 // ------------
00196 void L1CaloTowerProducer::endJob(  )
00197 {
00198 
00199 }
00200 
00201 
00202 DEFINE_EDM_PLUGIN( edm::MakerPluginFactory,
00203                                    edm::WorkerMaker < L1CaloTowerProducer >,
00204                                    "L1CaloTowerProducer" );
00205 DEFINE_FWK_PSET_DESC_FILLER( L1CaloTowerProducer );