CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEcal/EgammaCoreTools/src/EcalTools.cc

Go to the documentation of this file.
00001 // $Id: EcalTools.cc,v 1.1 2011/01/12 14:46:27 argiro Exp $
00002 
00003 #include "RecoEcal/EgammaCoreTools/interface/EcalTools.h"
00004 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00005 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00006 
00007 float EcalTools::swissCross( const DetId& id, 
00008                              const EcalRecHitCollection & recHits, 
00009                              float recHitThreshold , 
00010                              bool avoidIeta85){
00011   // compute swissCross
00012   if ( id.subdetId() == EcalBarrel ) {
00013     EBDetId ebId( id );
00014     // avoid recHits at |eta|=85 where one side of the neighbours is missing
00015     // (may improve considering also eta module borders, but no
00016     // evidence for the time being that there the performance is
00017     // different)
00018     if ( abs(ebId.ieta())==85 && avoidIeta85) return 0;
00019     // select recHits with Et above recHitThreshold
00020     if ( recHitApproxEt( id, recHits ) < recHitThreshold ) return 0;
00021     float s4 = 0;
00022     float e1 = recHitE( id, recHits );
00023     // protect against nan (if 0 threshold is given above)
00024     if ( e1 == 0 ) return 0;
00025     s4 += recHitE( id, recHits,  1,  0 );
00026     s4 += recHitE( id, recHits, -1,  0 );
00027     s4 += recHitE( id, recHits,  0,  1 );
00028     s4 += recHitE( id, recHits,  0, -1 );
00029     return 1 - s4 / e1;
00030   } else if ( id.subdetId() == EcalEndcap ) {
00031     EEDetId eeId( id );
00032     // select recHits with E above recHitThreshold
00033     float e1 = recHitE( id, recHits );
00034     if ( e1 < recHitThreshold ) return 0;
00035     float s4 = 0;
00036     // protect against nan (if 0 threshold is given above)
00037     if ( e1 == 0 ) return 0;
00038     s4 += recHitE( id, recHits,  1,  0 );
00039     s4 += recHitE( id, recHits, -1,  0 );
00040     s4 += recHitE( id, recHits,  0,  1 );
00041     s4 += recHitE( id, recHits,  0, -1 );
00042     return 1 - s4 / e1;
00043   }
00044   return 0;
00045 }
00046 
00047 
00048 float EcalTools::recHitE( const DetId id, 
00049                           const EcalRecHitCollection & recHits,
00050                           int di, int dj )
00051 {
00052   // in the barrel:   di = dEta   dj = dPhi
00053   // in the endcap:   di = dX     dj = dY
00054   
00055   DetId nid;
00056   if( id.subdetId() == EcalBarrel) nid = EBDetId::offsetBy( id, di, dj );
00057   else if( id.subdetId() == EcalEndcap) nid = EEDetId::offsetBy( id, di, dj );
00058   
00059   return ( nid == DetId(0) ? 0 : recHitE( nid, recHits ) );
00060 }
00061 
00062 float EcalTools::recHitE( const DetId id, const EcalRecHitCollection &recHits ){
00063   if ( id == DetId(0) ) {
00064     return 0;
00065   } else {
00066     EcalRecHitCollection::const_iterator it = recHits.find( id );
00067     if ( it != recHits.end() ) return (*it).energy();
00068   }
00069   return 0;
00070 }
00071 
00072 float EcalTools::recHitApproxEt( const DetId id, const EcalRecHitCollection &recHits ){
00073   // for the time being works only for the barrel
00074   if ( id.subdetId() == EcalBarrel ) {
00075     return recHitE( id, recHits ) / cosh( EBDetId::approxEta( id ) );
00076   }
00077   return 0;
00078 }