CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/SLHCUpgradeSimulations/L1CaloTrigger/plugins/L1RingSubtractionProducer.cc

Go to the documentation of this file.
00001 /* L1RingSubtractionProducer Reads TPGs, fixes the energy scale compression and
00002    produces towers
00003 
00004    Andrew W. Rose Imperial College, London */
00005 
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 // system include files
00008 #include <memory>
00009 
00010 // user include files
00011 #include "FWCore/Framework/interface/Frameworkfwd.h"
00012 #include "FWCore/Framework/interface/EDProducer.h"
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "FWCore/Framework/interface/MakerMacros.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 
00018 
00019 #include "SimDataFormats/SLHC/interface/L1CaloTriggerSetup.h"
00020 #include "SimDataFormats/SLHC/interface/L1CaloTriggerSetupRcd.h"
00021 
00022 #include "SimDataFormats/SLHC/interface/L1CaloTower.h"
00023 #include "SimDataFormats/SLHC/interface/L1CaloTowerFwd.h"
00024 
00025 #include <algorithm> 
00026 #include <string> 
00027 
00028 
00029 class L1RingSubtractionProducer:public edm::EDProducer
00030 {
00031   public:
00032         explicit L1RingSubtractionProducer( const edm::ParameterSet & );
00033          ~L1RingSubtractionProducer(  );
00034 
00035   private:
00036 
00037         virtual void produce( edm::Event &, const edm::EventSetup & );
00038         virtual void endJob(  );
00039 
00040         edm::ESHandle < L1CaloTriggerSetup >  mCaloTriggerSetup;
00041 
00042         edm::InputTag mInputCollectionTag;
00043         edm::Handle < l1slhc::L1CaloTowerCollection > mInputCollection;
00044         std::auto_ptr < l1slhc::L1CaloTowerCollection > mOutputCollection;
00045 
00046 
00047         double getEcalConstant( int& iEta  );
00048         double getHcalConstant( int& iEta );
00049 
00050 
00051         enum{
00052                 constant,
00053                 mean,
00054                 median
00055         }
00056         mRingSubtractionType;
00057 
00058 
00059 };
00060 
00061 
00062 
00063 
00064 L1RingSubtractionProducer::L1RingSubtractionProducer( const edm::ParameterSet & aConfig ):
00065 mInputCollectionTag( aConfig.getParameter < edm::InputTag > ( "src" ) ),
00066 mOutputCollection( NULL )
00067 {
00068         
00069         std::string lRingSubtractionType = aConfig.getParameter< std::string >("RingSubtractionType");
00070         std::transform( lRingSubtractionType.begin() , lRingSubtractionType.end() , lRingSubtractionType.begin() , ::toupper ); //do the comparison in upper case so config file can read "Mean", "mean", "MEAN", "mEaN", etc. and give the same result.
00071 
00072         if( lRingSubtractionType == "MEAN" ){
00073                 mRingSubtractionType = mean;
00074         }else if( lRingSubtractionType == "MEDIAN" ){ 
00075                 mRingSubtractionType = median;
00076         }else{
00077                 mRingSubtractionType = constant;
00078         }
00079 
00080         // Register Product
00081         produces < l1slhc::L1CaloTowerCollection > (  );
00082 }
00083 
00084 
00085 L1RingSubtractionProducer::~L1RingSubtractionProducer(  )
00086 {}
00087 
00088 
00089 
00090 
00091 
00092 void L1RingSubtractionProducer::produce( edm::Event & aEvent,
00093                                                                    const edm::EventSetup & aSetup )
00094 {
00095 
00096         if( mRingSubtractionType == constant ){
00097                 std::cout << "!!! WARNING !!! Constant ring subtraction is yet not implemented. A constant of 0 will be assumed !!! WARNING !!!\n" << std::endl;
00098         }
00099 
00100         aSetup.get < L1CaloTriggerSetupRcd > (  ).get( mCaloTriggerSetup );
00101 
00102         aEvent.getByLabel( mInputCollectionTag, mInputCollection );
00103 
00104         // create a new l1slhc::L1CaloTowerCollection (auto_ptr should handle deletion of the last one correctly)
00105         mOutputCollection = std::auto_ptr < l1slhc::L1CaloTowerCollection > ( new l1slhc::L1CaloTowerCollection );
00106 
00107         if( mRingSubtractionType  == mean ){
00108 
00109                 std::map< int , double > lMeanEcal , lMeanHcal;
00110 
00111                 for( l1slhc::L1CaloTowerCollection::const_iterator lInputIt = mInputCollection->begin() ; lInputIt != mInputCollection->end() ; ++lInputIt ){
00112                         lMeanEcal[ lInputIt->iEta() ] += double(lInputIt->E());
00113                         lMeanHcal[ lInputIt->iEta() ] += double(lInputIt->H());
00114                 }
00115 
00116                 //Empty towers are assumed to have zero energy contribution, so we divide by all towers
00117                 for( std::map< int , double >::iterator lIt = lMeanEcal.begin() ; lIt != lMeanEcal.end() ; ++lIt ){
00118                         lIt->second /= 72;
00119                 }
00120 
00121                 //Empty towers are assumed to have zero energy contribution, so we divide by all towers
00122                 for( std::map< int , double >::iterator lIt = lMeanHcal.begin() ; lIt != lMeanHcal.end() ; ++lIt ){
00123                         lIt->second /= 72;
00124                 }
00125 
00126                 for( l1slhc::L1CaloTowerCollection::const_iterator lInputIt = mInputCollection->begin() ; lInputIt != mInputCollection->end() ; ++lInputIt ){
00127                         int lEta =      lInputIt->iEta();               
00128                         int lPhi =      lInputIt->iPhi();               
00129 
00130                         int lEcal = int( double(lInputIt->E()) - lMeanEcal[ lEta ] );
00131                         int lHcal = int( double(lInputIt->H()) - lMeanHcal[ lEta ] );
00132 
00133                         l1slhc::L1CaloTower lCaloTower( lEta , lPhi );
00134                         lCaloTower.setEcal( lEcal , lInputIt->EcalFG() );
00135                         lCaloTower.setHcal( lHcal , lInputIt->HcalFG() );
00136         
00137                         mOutputCollection->insert( lEta , lPhi , lCaloTower );
00138                 }
00139 
00140 
00141         } else if( mRingSubtractionType  == median ){
00142 
00143                 std::map< int , std::deque<int> > lEcals , lHcals;
00144 
00145                 for( l1slhc::L1CaloTowerCollection::const_iterator lInputIt = mInputCollection->begin() ; lInputIt != mInputCollection->end() ; ++lInputIt ){
00146                         lEcals[ lInputIt->iEta() ].push_back( lInputIt->E() );
00147                         lHcals[ lInputIt->iEta() ].push_back( lInputIt->H() );
00148 
00149                         //std::cout<<"ECal energy: "<<lInputIt->E()<<std::endl;
00150                         //std::cout<<"HCal energy: "<<lInputIt->H()<<std::endl;
00151                 }
00152 
00153                 std::map< int , double > lMedianEcal , lMedianHcal;
00154 
00155                 //Empty towers are assumed to have zero energy contribution
00156                 for( std::map< int , std::deque<int> >::iterator lIt = lEcals.begin() ; lIt != lEcals.end() ; ++lIt ){
00157                         lIt->second.resize( 72 , 0 );
00158                         std::sort( lIt->second.begin() , lIt->second.end() );
00159                         lMedianEcal[ lIt->first ] = (lIt->second.at( 35 ) + lIt->second.at( 36 )) / 2.0;                
00160         }
00161 
00162 
00163                 //Empty towers are assumed to have zero energy contribution
00164                 for( std::map< int , std::deque<int> >::iterator lIt = lHcals.begin() ; lIt != lHcals.end() ; ++lIt ){
00165                         lIt->second.resize( 72 , 0 );
00166                         std::sort( lIt->second.begin() , lIt->second.end() );
00167                         lMedianHcal[ lIt->first ] = (lIt->second.at( 35 ) + lIt->second.at( 36 )) / 2.0;
00168         
00169         }
00170 
00171 
00172                 for( l1slhc::L1CaloTowerCollection::const_iterator lInputIt = mInputCollection->begin() ; lInputIt != mInputCollection->end() ; ++lInputIt ){
00173                         int lEta =      lInputIt->iEta();               
00174                         int lPhi =      lInputIt->iPhi();               
00175 
00176                         int lEcal = int( double(lInputIt->E()) - lMedianEcal[ lEta ] );
00177                         int lHcal = int( double(lInputIt->H()) - lMedianHcal[ lEta ] );
00178 
00179                         l1slhc::L1CaloTower lCaloTower( lEta , lPhi );
00180                         lCaloTower.setEcal( lEcal , lInputIt->EcalFG() );
00181                         lCaloTower.setHcal( lHcal , lInputIt->HcalFG() );
00182         
00183                         mOutputCollection->insert( lEta , lPhi , lCaloTower );
00184                 }
00185 
00186         }else{
00187 
00188 
00189                 for( l1slhc::L1CaloTowerCollection::const_iterator lInputIt = mInputCollection->begin() ; lInputIt != mInputCollection->end() ; ++lInputIt ){
00190                         int lEta =      lInputIt->iEta();               
00191                         int lPhi =      lInputIt->iPhi();               
00192 
00193                         int lEcal = int( double(lInputIt->E()) - getEcalConstant( lEta ) );
00194                         int lHcal = int( double(lInputIt->H()) - getHcalConstant( lEta ) );
00195 
00196                         l1slhc::L1CaloTower lCaloTower( lEta , lPhi );
00197                         lCaloTower.setEcal( lEcal , lInputIt->EcalFG() );
00198                         lCaloTower.setHcal( lHcal , lInputIt->HcalFG() );
00199         
00200                         mOutputCollection->insert( lEta , lPhi , lCaloTower );
00201                 }
00202 
00203 
00204         }
00205         
00206         
00207         
00208         
00209 
00210         
00211         aEvent.put( mOutputCollection );
00212 }
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 double L1RingSubtractionProducer::getEcalConstant( int& iEta ){
00225         //can use mCaloTriggerSetup member object to retrieve a look-up table from EventSetup
00226         //std::cout << "Function " << __PRETTY_FUNCTION__ << " not implemented. Returning 0 for subtraction." << std::endl;
00227         return 0;
00228 }
00229 
00230 
00231 double L1RingSubtractionProducer::getHcalConstant( int& iEta ){
00232         //can use mCaloTriggerSetup member object to retrieve a look-up table from EventSetup
00233         //std::cout << "Function " << __PRETTY_FUNCTION__ << " not implemented. Returning 0 for subtraction." << std::endl;
00234         return 0;
00235 }
00236 
00237 
00238 
00239 
00240 // ------------ method called once each job just after ending the event loop
00241 // ------------
00242 void L1RingSubtractionProducer::endJob(  )
00243 {
00244 }
00245 
00246 
00247 DEFINE_EDM_PLUGIN( edm::MakerPluginFactory,
00248                                    edm::WorkerMaker < L1RingSubtractionProducer >,
00249                                    "L1RingSubtractionProducer" );
00250 DEFINE_FWK_PSET_DESC_FILLER( L1RingSubtractionProducer );