CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoLocalCalo/Castor/src/CastorTowerProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    Castor
00004 // Class:      CastorTowerProducer
00005 // 
00006 
00013 //
00014 // Original Author:  Hans Van Haevermaet, Benoit Roland
00015 //         Created:  Wed Jul  9 14:00:40 CEST 2008
00016 // $Id: CastorTowerProducer.cc,v 1.8 2010/07/06 16:46:04 hvanhaev Exp $
00017 //
00018 //
00019 
00020 
00021 // system include 
00022 #include <memory>
00023 #include <vector>
00024 #include <iostream>
00025 #include <TMath.h>
00026 #include <TRandom3.h>
00027 
00028 // user include 
00029 #include "FWCore/Framework/interface/Frameworkfwd.h"
00030 #include "FWCore/Framework/interface/EDProducer.h"
00031 #include "FWCore/Framework/interface/Event.h"
00032 #include "FWCore/Framework/interface/MakerMacros.h"
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 #include "DataFormats/Math/interface/Point3D.h"
00035 
00036 // Castor Object include
00037 #include "DataFormats/CastorReco/interface/CastorCell.h"
00038 #include "DataFormats/CastorReco/interface/CastorTower.h"
00039 
00040 //
00041 // class declaration
00042 //
00043 
00044 class CastorTowerProducer : public edm::EDProducer {
00045    public:
00046       explicit CastorTowerProducer(const edm::ParameterSet&);
00047       ~CastorTowerProducer();
00048 
00049    private:
00050       virtual void beginJob() ;
00051       virtual void produce(edm::Event&, const edm::EventSetup&);
00052       virtual void endJob() ;
00053       virtual void ComputeTowerVariable(const reco::CastorCellRefVector& usedCells, double&  Ehot, double& depth);
00054       
00055       // member data
00056       typedef math::XYZPointD Point;
00057       typedef ROOT::Math::RhoEtaPhiPoint TowerPoint;
00058       typedef ROOT::Math::RhoZPhiPoint CellPoint;
00059       typedef std::vector<reco::CastorCell> CastorCellCollection;
00060       typedef std::vector<reco::CastorTower> CastorTowerCollection;
00061       typedef edm::RefVector<CastorCellCollection>  CastorCellRefVector;
00062       std::string input_;
00063       double towercut_;
00064 };
00065 
00066 //
00067 // constants, enums and typedefs
00068 //
00069 
00070 const double MYR2D = 180/M_PI;
00071 
00072 //
00073 // static data member definitions
00074 //
00075 
00076 //
00077 // constructor and destructor
00078 //
00079 
00080 CastorTowerProducer::CastorTowerProducer(const edm::ParameterSet& iConfig) :
00081   input_(iConfig.getUntrackedParameter<std::string>("inputprocess","CastorCellReco")),
00082   towercut_(iConfig.getUntrackedParameter<double>("towercut",1.))
00083 {
00084   //register your products
00085   produces<CastorTowerCollection>();
00086   //now do what ever other initialization is needed
00087 }
00088 
00089 
00090 CastorTowerProducer::~CastorTowerProducer()
00091 {
00092    // do anything here that needs to be done at desctruction time
00093    // (e.g. close files, deallocate resources etc.)
00094 }
00095 
00096 
00097 //
00098 // member functions
00099 //
00100 
00101 // ------------ method called to produce the data  ------------
00102 void CastorTowerProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00103 
00104   using namespace edm;
00105   using namespace reco;
00106   using namespace TMath;
00107   
00108   // Produce CastorTowers from CastorCells
00109   
00110   edm::Handle<CastorCellCollection> InputCells;
00111   iEvent.getByLabel(input_,InputCells);
00112 
00113   std::auto_ptr<CastorTowerCollection> OutputTowers (new CastorTowerCollection);
00114    
00115   // get and check input size
00116   int nCells = InputCells->size();
00117 
00118   LogDebug("CastorTowerProducer")
00119     <<"2. entering CastorTowerProducer"<<std::endl;
00120 
00121   if (nCells==0)
00122     LogDebug("CastorTowerProducer") <<"Warning: You are trying to run the Tower algorithm with 0 input cells.";
00123   
00124   // declare castor array
00125   // (0,x): Energies - (1,x): emEnergies - (2,x): hadEnergies - (3,x): phi position
00126   
00127   double poscastortowerarray[4][16]; 
00128   double negcastortowerarray[4][16];
00129 
00130   CastorCellRefVector poscastorusedcells[16];
00131   CastorCellRefVector negcastorusedcells[16];
00132 
00133   // set phi values and everything else to zero
00134   for (int j = 0; j < 16; j++) {
00135     poscastortowerarray[3][j] = -2.94524 + j*0.3927;
00136     poscastortowerarray[0][j] = 0.;
00137     poscastortowerarray[1][j] = 0.;
00138     poscastortowerarray[2][j] = 0.;
00139 
00140     negcastortowerarray[3][j] = -2.94524 + j*0.3927;
00141     negcastortowerarray[0][j] = 0.;
00142     negcastortowerarray[1][j] = 0.;
00143     negcastortowerarray[2][j] = 0.;
00144   }
00145 
00146   // loop over cells to build castortowerarray[4][16] and castorusedcells[16] 
00147   for (unsigned int i = 0; i < InputCells->size(); i++) {
00148     
00149     reco::CastorCellRef cell_p = reco::CastorCellRef(InputCells, i);
00150     
00151     double Ecell = cell_p->energy();
00152     double zcell = cell_p->z();
00153     double phicell = cell_p->phi();
00154 
00155     // loop over the 16 towers possibilities
00156     for ( int j=0;j<16;j++) {
00157       
00158       // phi matching condition
00159       if (TMath::Abs(phicell - poscastortowerarray[3][j]) < 0.0001) {
00160 
00161         // condition over cell z value
00162         if (zcell > 0.) {
00163           poscastortowerarray[0][j]+=Ecell;
00164           if (TMath::Abs(zcell) < 14488) poscastortowerarray[1][j]+=Ecell;  
00165           else poscastortowerarray[2][j]+=Ecell;
00166           poscastorusedcells[j].push_back(cell_p);
00167         }
00168       
00169         else {
00170           negcastortowerarray[0][j]+=Ecell;
00171           if (TMath::Abs(zcell) < 14488) negcastortowerarray[1][j]+=Ecell;  
00172           else negcastortowerarray[2][j]+=Ecell;
00173           negcastorusedcells[j].push_back(cell_p);
00174         } // end condition over cell z value
00175 
00176       } // end phi matching condition
00177     } // end loop over the 16 towers possibilities
00178   } // end loop over cells to build castortowerarray[4][16] and castorusedcells[16]
00179   
00180   // make towers of the arrays
00181 
00182   double fem, Ehot, depth;
00183   double rhoTower = 88.5;
00184 
00185   // loop over the 16 towers possibilities
00186   for (int k=0;k<16;k++) {
00187     
00188     fem = 0;
00189     Ehot = 0;
00190     depth = 0;
00191 
00192     // select the positive towers with E > Ecut
00193     if (poscastortowerarray[0][k] > towercut_) {
00194       
00195       fem = poscastortowerarray[1][k]/poscastortowerarray[0][k];
00196       CastorCellRefVector usedCells = poscastorusedcells[k];
00197       ComputeTowerVariable(usedCells,Ehot,depth);
00198 
00199       LogDebug("CastorTowerProducer")
00200         <<"tower "<<k+1<<": fem = "<<fem<<" ,depth = "<<depth<<" ,Ehot = "<<Ehot<<std::endl;
00201 
00202       TowerPoint temptowerposition(rhoTower,5.9,poscastortowerarray[3][k]);
00203       Point towerposition(temptowerposition);
00204 
00205       CastorTower newtower(poscastortowerarray[0][k],towerposition,poscastortowerarray[1][k],poscastortowerarray[2][k],fem,depth,Ehot,
00206                            poscastorusedcells[k]);
00207       OutputTowers->push_back(newtower);
00208     } // end select the positive towers with E > Ecut
00209     
00210     // select the negative towers with E > Ecut
00211     if (negcastortowerarray[0][k] > towercut_) {
00212       
00213       fem = negcastortowerarray[1][k]/negcastortowerarray[0][k];
00214       CastorCellRefVector usedCells = negcastorusedcells[k];
00215       ComputeTowerVariable(usedCells,Ehot,depth);
00216 
00217       LogDebug("CastorTowerProducer")
00218         <<"tower "<<k+1<<": fem = "<<fem<<" ,depth = "<<depth<<" ,Ehot = "<<Ehot<<std::endl;
00219 
00220       TowerPoint temptowerposition(rhoTower,-5.9,negcastortowerarray[3][k]);
00221       Point towerposition(temptowerposition);
00222 
00223       CastorTower newtower(negcastortowerarray[0][k],towerposition,negcastortowerarray[1][k],negcastortowerarray[2][k],fem,depth,Ehot,
00224                            negcastorusedcells[k]);
00225       OutputTowers->push_back(newtower);
00226     } // end select the negative towers with E > Ecut
00227     
00228   } // end loop over the 16 towers possibilities
00229   
00230   iEvent.put(OutputTowers);
00231 } 
00232 
00233 
00234 // ------------ method called once each job just before starting event loop  ------------
00235 void CastorTowerProducer::beginJob() {
00236   LogDebug("CastorTowerProducer")
00237     <<"Starting CastorTowerProducer";
00238 }
00239 
00240 // ------------ method called once each job just after ending the event loop  ------------
00241 void CastorTowerProducer::endJob() {
00242   LogDebug("CastorTowerProducer")
00243     <<"Ending CastorTowerProducer";
00244 }
00245 
00246 void CastorTowerProducer::ComputeTowerVariable(const reco::CastorCellRefVector& usedCells, double&  Ehot, double& depth) {
00247 
00248   using namespace reco;
00249 
00250   double Etot = 0;
00251 
00252   // loop over the cells used in the tower k
00253   for (CastorCell_iterator it = usedCells.begin(); it != usedCells.end(); it++) {
00254     reco::CastorCellRef cell_p = *it;
00255 
00256     double Ecell = cell_p->energy();
00257     double zcell = cell_p->z();
00258 
00259     if(Ecell > Ehot) Ehot = Ecell;
00260     depth+=Ecell*zcell;
00261     Etot+=Ecell;
00262   }
00263 
00264   depth/=Etot;
00265   Ehot/=Etot;
00266 }
00267 
00268 //define this as a plug-in
00269 DEFINE_FWK_MODULE(CastorTowerProducer);