CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/SLHCUpgradeSimulations/L1CaloTrigger/plugins/L1TowerJetProducer.cc

Go to the documentation of this file.
00001 
00002 #include "SLHCUpgradeSimulations/L1CaloTrigger/interface/L1CaloAlgoBase.h"
00003 
00004 #include "SimDataFormats/SLHC/interface/L1TowerJet.h"
00005 #include "SimDataFormats/SLHC/interface/L1TowerJetFwd.h"
00006 #include "SimDataFormats/SLHC/interface/L1CaloTower.h"
00007 #include "SimDataFormats/SLHC/interface/L1CaloTowerFwd.h"
00008 
00009 #include <algorithm> 
00010 #include <string> 
00011 #include <vector>
00012  
00013 
00014 class L1TowerJetProducer:
00015 public L1CaloAlgoBase < l1slhc::L1CaloTowerCollection, l1slhc::L1TowerJetCollection >
00016 {
00017   public:
00018         L1TowerJetProducer( const edm::ParameterSet & );
00019          ~L1TowerJetProducer(  );
00020 
00021         // void initialize( );
00022 
00023         void algorithm( const int &, const int & );
00024 
00025   private:
00026         void calculateJetPosition( l1slhc::L1TowerJet & lJet );
00027         //some helpful members
00028         int mJetDiameter;
00029         l1slhc::L1TowerJet::tJetShape mJetShape;
00030 
00031         std::vector< std::pair< int , int > > mJetShapeMap;
00032 
00033 };
00034 
00035 L1TowerJetProducer::L1TowerJetProducer( const edm::ParameterSet & aConfig ):L1CaloAlgoBase < l1slhc::L1CaloTowerCollection, l1slhc::L1TowerJetCollection > ( aConfig )
00036 {
00037         mJetDiameter = aConfig.getParameter<unsigned>("JetDiameter");
00038         mPhiOffset = 0;
00039 
00040     //note: this mEtaOffset works when read in setupHF.xml in SLHCUpgradeSimulations/L1CaloTrigger/python/SLHCCaloTrigger_cfi.py
00041     //must be used with aEta>4 in algorithm() function below
00042 //      mEtaOffset = -(mJetDiameter+4);
00043 
00044     //if use with setup.xml where don't read in HF wires use
00045     mEtaOffset = -(mJetDiameter);       
00046     //and don't need aEta>4 condition
00047 
00048     // mPhiIncrement = 1;
00049         // mEtaIncrement = 1;
00050 
00051         mJetShapeMap.reserve(256); //jets will never be 16x16 but it is a nice round number
00052 
00053         std::string lJetShape = aConfig.getParameter< std::string >("JetShape");
00054         std::transform( lJetShape.begin() , lJetShape.end() , lJetShape.begin() , ::toupper ); //do the comparison in upper case so config file can read "Circle", "circle", "CIRCLE", "cIrClE", etc. and give the same result.
00055 
00056         std::cout << "Creating JetShapeMap:" << std::endl;
00057 
00058         if ( lJetShape == "CIRCLE" ){
00059                 mJetShape = l1slhc::L1TowerJet::circle;
00060 
00061 
00062                 double lCentre( (mJetDiameter-1) / 2.0 );
00063                 double lDelta;
00064 
00065                 std::vector<double> lDeltaSquare;
00066                 for( int i = 0 ; i != mJetDiameter ; ++i ){
00067                         lDelta = double(i) - lCentre;
00068                         lDeltaSquare.push_back( lDelta*lDelta );
00069                 }
00070 
00071                 double lDeltaRSquare;
00072                 double lDeltaRSquareMax( (mJetDiameter*mJetDiameter) / 4.0 );
00073 
00074                 for( int x = 0 ; x != mJetDiameter ; ++x ){
00075                         for( int y = 0 ; y != mJetDiameter ; ++y ){
00076                                 lDeltaRSquare = lDeltaSquare[x] + lDeltaSquare[y];
00077                                 if( lDeltaRSquare <= lDeltaRSquareMax ){
00078                                         mJetShapeMap.push_back( std::make_pair( x , y ) );
00079                                         //std::cout << "#" << std::flush;
00080                                 }else{
00081                                         //std::cout << "-" << std::flush;
00082                                 }
00083                         }
00084                         //std::cout << std::endl;
00085                 }
00086 
00087         }else{
00088 
00089                 mJetShape = l1slhc::L1TowerJet::square;
00090 
00091                 for( int x = 0 ; x != mJetDiameter ; ++x ){
00092                         for( int y = 0 ; y != mJetDiameter ; ++y ){
00093                                 mJetShapeMap.push_back( std::make_pair( x , y ) );
00094                         }
00095                 }
00096         }
00097 
00098         std::cout << "JetShapeMap includes " << mJetShapeMap.size() << " towers." << std::endl;
00099     std::cout<<" Eta offset is "<< mEtaOffset << std::endl;
00100 }
00101 
00102 L1TowerJetProducer::~L1TowerJetProducer(  )
00103 {
00104 }
00105 
00106 /* 
00107    void L1TowerJetProducer::initialize( ) { }
00108 */
00109 
00110 void L1TowerJetProducer::algorithm( const int &aEta, const int &aPhi )
00111 {
00112 //  if(aEta>4){   
00113       
00114   int lTowerIndex = mCaloTriggerSetup->getBin( aEta, aPhi );
00115   std::pair < int, int > lTowerEtaPhi = mCaloTriggerSetup->getTowerEtaPhi( lTowerIndex );
00116   
00117   l1slhc::L1TowerJet lJet( mJetDiameter, mJetShape , mJetShapeMap.size() , lTowerEtaPhi.first , lTowerEtaPhi.second  );
00118 
00119   
00120   for ( std::vector< std::pair< int , int > >::const_iterator lJetShapeMapIt = mJetShapeMap.begin() ; lJetShapeMapIt != mJetShapeMap.end() ; ++lJetShapeMapIt )
00121   {
00122     int lPhi = aPhi+(lJetShapeMapIt->second);
00123     if ( lPhi > mCaloTriggerSetup->phiMax(  ) ) lPhi -= 72; //mCaloTriggerSetup->phiMax(  );
00124   
00125     l1slhc::L1CaloTowerCollection::const_iterator lTowerItr = fetch( aEta+(lJetShapeMapIt->first) , lPhi );
00126 
00127     if ( lTowerItr != mInputCollection->end(  ) )
00128     {
00129       l1slhc::L1CaloTowerRef lRef( mInputCollection, lTowerItr - mInputCollection->begin(  ) );
00130       lJet.addConstituent( lRef );
00131 
00132         lJet.CalcWeightediEta();
00133     lJet.CalcWeightediPhi();
00134     }
00135   }
00136   
00137   if ( lJet.E(  ) > 0 )
00138   {
00139     calculateJetPosition( lJet );
00140     
00141     lJet.calculateWeightedEta();lJet.calculateWeightedPhi();
00142     mOutputCollection->insert( lTowerEtaPhi.first, lTowerEtaPhi.second, lJet );
00143 
00144   }
00145 //}
00146 }
00147 
00148 
00149 
00150 void L1TowerJetProducer::calculateJetPosition( l1slhc::L1TowerJet & lJet )
00151 {
00152 
00153   double tmpeta(9999);
00154   double halfTowerOffset = 0.0435;
00155   const double endcapEta[8] = { 0.09, 0.1, 0.113, 0.129, 0.15, 0.178, 0.15, 0.35 };
00156 
00157   double JetSize = double(lJet.JetSize()) / 2.0;
00158   //std::cout<<" jet ieta: "<< lJet.iEta(  );
00159   int abs_eta = lJet.iEta(  ) + int(JetSize) ;
00160   //std::cout<<" centre of jet: "<<abs_eta ;
00161   //account for the fact there is no zero create a zero
00162   if( abs_eta>=0 && lJet.iEta(  )<0 ) abs_eta += 1;
00163  
00164   //std::cout<<" account for no zero: "<<abs_eta<<std::endl;
00165   abs_eta = fabs( abs_eta);//fabs( lJet.iEta(  ) + int(JetSize) );
00166 
00167 
00168   if ( abs_eta < 21 )
00169   {
00170     tmpeta = ( abs_eta * 0.0870 - halfTowerOffset);
00171     
00172     if( lJet.JetSize() % 2 == 1 )      tmpeta += halfTowerOffset;
00173 
00174   }
00175   else
00176   {
00177     abs_eta -= 21;
00178 
00179     tmpeta = 1.74;
00180 
00181     for ( int i = 0; i != int(abs_eta); ++i )
00182     {
00183       tmpeta += endcapEta[i];
00184     }
00185 
00186 
00187     if( lJet.JetSize() % 2 == 0 )   tmpeta += endcapEta[abs_eta] / 2.; 
00188     else      tmpeta += endcapEta[abs_eta];
00189 
00190   }
00191 
00192   if(( lJet.iEta(  ) + int(JetSize)  )<0) tmpeta = (-1)*tmpeta;
00193   //if (lJet.iEta()>0) tmpeta-=0.087;
00194 
00195   // std::cout<<"jet ieta: "<<lJet.iEta()<<" jet centre "<< abs_eta <<" to eta "<<tmpeta<<std::endl;
00196 
00197   double phi = ( ( lJet.iPhi(  ) + JetSize ) * 0.087 );
00198   //Need this because 72*0.087 != 2pi: else get uneven phi dist
00199   phi -= 0.087;
00200   double pi=(72*0.087)/2;
00201   if(phi>pi) phi-=2*pi; 
00202   
00203   double Et = double( lJet.E(  ) ) / 2.;
00204 
00205   lJet.setP4( math::PtEtaPhiMLorentzVector( Et, tmpeta, phi, 0. ) );
00206 
00207 } 
00208 
00209 
00210 
00211 DEFINE_EDM_PLUGIN( edm::MakerPluginFactory, edm::WorkerMaker < L1TowerJetProducer >, "L1TowerJetProducer" );
00212 DEFINE_FWK_PSET_DESC_FILLER( L1TowerJetProducer );