CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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/HcalRecHit/interface/CastorRecHit.h"
00006 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00007 
00008 #include "TMath.h"
00009 #include <vector>
00010 #include <numeric>
00011 #include <iostream>
00012 
00013 
00014 reco::helper::CastorJetIDHelper::CastorJetIDHelper()
00015 {
00016  
00017   initValues();
00018 }
00019   
00020 void reco::helper::CastorJetIDHelper::initValues()
00021 {
00022       emEnergy_ = 0.0;
00023       hadEnergy_ = 0.0; 
00024       fem_ = 0.0;
00025       width_ = 0.0;
00026       depth_ = 0.0;
00027       fhot_ = 0.0;
00028       sigmaz_ = 0.0;
00029       nTowers_ = 0;
00030 }
00031 
00032 
00033 void reco::helper::CastorJetIDHelper::calculate( const edm::Event& event, const reco::BasicJet &jet )
00034 {
00035   initValues();
00036   
00037   // calculate Castor JetID properties
00038  
00039                 double zmean = 0.;
00040                 double z2mean = 0.;
00041         
00042                 std::vector<CandidatePtr> ccp = jet.getJetConstituents();
00043                 std::vector<CandidatePtr>::const_iterator itParticle;
00044                 for (itParticle=ccp.begin();itParticle!=ccp.end();++itParticle){            
00045                         const CastorTower* castorcand = dynamic_cast<const CastorTower*>(itParticle->get());
00046                         emEnergy_ += castorcand->emEnergy();
00047                         hadEnergy_ += castorcand->hadEnergy();
00048                         depth_ += castorcand->depth()*castorcand->energy();
00049                         width_ += pow(phiangle(castorcand->phi() - jet.phi()),2)*castorcand->energy();
00050                         fhot_ += castorcand->fhot()*castorcand->energy();
00051                         
00052                         // loop over rechits
00053                         for (edm::RefVector<edm::SortedCollection<CastorRecHit> >::iterator it = castorcand->rechitsBegin(); it != castorcand->rechitsEnd(); it++) {
00054                                  edm::Ref<edm::SortedCollection<CastorRecHit> > rechit_p = *it;                         
00055                                  double Erechit = rechit_p->energy();
00056                                  HcalCastorDetId id = rechit_p->id();
00057                                  int module = id.module();                                      
00058                                  double zrechit = 0;     
00059                                  if (module < 3) zrechit = -14390 - 24.75 - 49.5*(module-1);     
00060                                  if (module > 2) zrechit = -14390 - 99 - 49.5 - 99*(module-3);   
00061                                  zmean += Erechit*zrechit;       
00062                                  z2mean += Erechit*zrechit*zrechit;
00063                         } // end loop over rechits
00064                         
00065                         nTowers_++;
00066                 }
00067                 //cout << "" << endl;
00068                 
00069                 depth_ = depth_/jet.energy();
00070                 width_ = sqrt(width_/jet.energy());
00071                 fhot_ = fhot_/jet.energy();
00072                 fem_ = emEnergy_/jet.energy();
00073                 
00074                 zmean = zmean/jet.energy();
00075                 z2mean = z2mean/jet.energy();
00076                 double sigmaz2 = z2mean - zmean*zmean;
00077                 if(sigmaz2 > 0) sigmaz_ = sqrt(sigmaz2);
00078 
00079   
00080 }
00081 
00082 // help function to calculate phi within [-pi,+pi]
00083 double reco::helper::CastorJetIDHelper::phiangle (double testphi) {
00084   double phi = testphi;
00085   while (phi>M_PI) phi -= (2*M_PI);
00086   while (phi<-M_PI) phi += (2*M_PI);
00087   return phi;
00088 }
00089 
00090 
00091