CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoJets/JetProducers/src/CastorJetIDHelper.cc

Go to the documentation of this file.
00001 #include "RecoJets/JetProducers/interface/CastorJetIDHelper.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "DataFormats/CastorReco/interface/CastorTower.h"
00005 #include "DataFormats/CastorReco/interface/CastorCell.h"
00006 
00007 #include "TMath.h"
00008 #include <vector>
00009 #include <numeric>
00010 #include <iostream>
00011 
00012 
00013 reco::helper::CastorJetIDHelper::CastorJetIDHelper()
00014 {
00015  
00016   initValues();
00017 }
00018   
00019 void reco::helper::CastorJetIDHelper::initValues()
00020 {
00021       emEnergy_ = 0.0;
00022       hadEnergy_ = 0.0; 
00023       fem_ = 0.0;
00024       width_ = 0.0;
00025       depth_ = 0.0;
00026       fhot_ = 0.0;
00027       sigmaz_ = 0.0;
00028       nTowers_ = 0;
00029 }
00030 
00031 
00032 void reco::helper::CastorJetIDHelper::calculate( const edm::Event& event, const reco::BasicJet &jet )
00033 {
00034   initValues();
00035   
00036   // calculate Castor JetID properties
00037  
00038                 double zmean = 0.;
00039                 double z2mean = 0.;
00040         
00041                 std::vector<CandidatePtr> ccp = jet.getJetConstituents();
00042                 std::vector<CandidatePtr>::const_iterator itParticle;
00043                 for (itParticle=ccp.begin();itParticle!=ccp.end();++itParticle){            
00044                         const CastorTower* castorcand = dynamic_cast<const CastorTower*>(itParticle->get());
00045                         emEnergy_ += castorcand->emEnergy();
00046                         hadEnergy_ += castorcand->hadEnergy();
00047                         depth_ += castorcand->depth()*castorcand->energy();
00048                         width_ += pow(phiangle(castorcand->phi() - jet.phi()),2)*castorcand->energy();
00049                         fhot_ += castorcand->fhot()*castorcand->energy();
00050                         
00051                         // loop over cells
00052                         for (CastorCell_iterator it = castorcand->cellsBegin(); it != castorcand->cellsEnd(); it++) {
00053                                 CastorCellRef cell_p = *it;
00054                                 math::XYZPointD rcell = cell_p->position();
00055                                 double Ecell = cell_p->energy();
00056                                 zmean += Ecell*cell_p->z();
00057                                 z2mean += Ecell*cell_p->z()*cell_p->z();
00058                         } // end loop over cells
00059                         
00060                         nTowers_++;
00061                 }
00062                 //cout << "" << endl;
00063                 
00064                 depth_ = depth_/jet.energy();
00065                 width_ = sqrt(width_/jet.energy());
00066                 fhot_ = fhot_/jet.energy();
00067                 fem_ = emEnergy_/jet.energy();
00068                 
00069                 zmean = zmean/jet.energy();
00070                 z2mean = z2mean/jet.energy();
00071                 double sigmaz2 = z2mean - zmean*zmean;
00072                 if(sigmaz2 > 0) sigmaz_ = sqrt(sigmaz2);
00073 
00074   
00075 }
00076 
00077 // help function to calculate phi within [-pi,+pi]
00078 double reco::helper::CastorJetIDHelper::phiangle (double testphi) {
00079   double phi = testphi;
00080   while (phi>M_PI) phi -= (2*M_PI);
00081   while (phi<-M_PI) phi += (2*M_PI);
00082   return phi;
00083 }
00084 
00085 
00086