CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DataFormats/EcalRecHit/src/EcalRecHit.cc

Go to the documentation of this file.
00001 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00002 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00003 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00004 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include <cassert>
00007 #include <math.h>
00008 
00009 EcalRecHit::EcalRecHit() : CaloRecHit(), flagBits_(0) {
00010 }
00011 
00012 EcalRecHit::EcalRecHit(const DetId& id, float energy, float time, uint32_t flags, uint32_t flagBits) :
00013   CaloRecHit(id,energy,time,flags),
00014   flagBits_(flagBits)
00015 {
00016 }
00017 
00018 bool EcalRecHit::isRecovered() const {
00019 
00020   return (    checkFlag(kLeadingEdgeRecovered) || 
00021               checkFlag(kNeighboursRecovered)  ||
00022               checkFlag(kTowerRecovered) 
00023           );
00024 }
00025 
00026 float EcalRecHit::chi2() const
00027 {
00028         uint32_t rawChi2 = 0x7F & (flags()>>4);
00029         return (float)rawChi2 / (float)((1<<7)-1) * 64.;
00030 }
00031 
00032 
00033 
00034 float EcalRecHit::outOfTimeChi2() const
00035 {
00036         uint32_t rawChi2Prob = 0x7F & (flags()>>24);
00037         return (float)rawChi2Prob / (float)((1<<7)-1) * 64.;
00038 }
00039 
00040 float EcalRecHit::outOfTimeEnergy() const
00041 {
00042         uint32_t rawEnergy = (0x1FFF & flags()>>11);
00043         uint16_t exponent = rawEnergy>>10;
00044         uint16_t significand = ~(0xE<<9) & rawEnergy;
00045         return (float) significand*pow(10,exponent-5);
00046 }
00047 
00048 
00049 
00050 
00051 
00052 void EcalRecHit::setChi2( float chi2 )
00053 {
00054         // bound the max value of the chi2
00055         if ( chi2 > 64 ) chi2 = 64;
00056         // use 7 bits
00057         uint32_t rawChi2 = lround( chi2 / 64. * ((1<<7)-1) );
00058         // shift by 4 bits (recoFlag)
00059         setFlags( (~(0x7F<<4) & flags()) | ((rawChi2 & 0x7F)<<4) );
00060 }
00061 
00062 void EcalRecHit::setOutOfTimeEnergy( float energy )
00063 {
00064         if ( energy > 0.001 ) {
00065                 uint16_t exponent = lround(floor(log10(energy)))+3;
00066                 uint16_t significand = lround(energy/pow(10,exponent-5));
00067                 // use 13 bits (3 exponent, 10 significand)
00068                 uint32_t rawEnergy = exponent<<10 | significand;
00069                 // shift by 11 bits (recoFlag + chi2)
00070                 setFlags( ( ~(0x1FFF<<11) & flags()) | ((rawEnergy & 0x1FFF)<<11) );
00071         }
00072 }
00073 
00074 
00075 
00076 
00077 void EcalRecHit::setOutOfTimeChi2( float chi2 )
00078 {
00079         // bound the max value of chi2
00080         if ( chi2 > 64 ) chi2 = 64;
00081         // use 7 bits
00082         uint32_t rawChi2 = lround( chi2 / 64. * ((1<<7)-1) );
00083         // shift by 24 bits (recoFlag + chi2 + outOfTimeEnergy)
00084         setFlags( (~(0x7F<<24) & flags()) | ((rawChi2 & 0x7F)<<24) );
00085 }
00086 
00087 
00088 void EcalRecHit::setTimeError( uint8_t timeErrBits )
00089 {
00090         // take the bits and put them in the right spot
00091         setAux( (~0xFF & aux()) | timeErrBits );
00092 }
00093 
00094 
00095 float EcalRecHit::timeError() const
00096 {
00097         uint32_t timeErrorBits = 0xFF & aux();
00098         // all bits off --> time reco bailed out (return negative value)
00099         if( (0xFF & timeErrorBits) == 0x00 )
00100                 return -1;
00101         // all bits on  --> time error over 5 ns (return large value)
00102         if( (0xFF & timeErrorBits) == 0xFF )
00103                 return 10000;
00104 
00105         float LSB = 1.26008;
00106         uint8_t exponent = timeErrorBits>>5;
00107         uint8_t significand = timeErrorBits & ~(0x7<<5);
00108         return pow(2.,exponent)*significand*LSB/1000.;
00109 }
00110 
00111 
00112 bool EcalRecHit::isTimeValid() const
00113 {
00114         if(timeError() <= 0)
00115           return false;
00116         else
00117           return true;
00118 }
00119 
00120 
00121 bool EcalRecHit::isTimeErrorValid() const
00122 {
00123         if(!isTimeValid())
00124           return false;
00125         if(timeError() >= 10000)
00126           return false;
00127 
00128         return true;
00129 }
00130 
00131 
00133 EcalRecHit::Flags EcalRecHit::recoFlag() const {
00134   for (int i=kUnknown; ; --i){
00135     if (checkFlag(i)) return Flags(i);
00136     if (i==0) break;
00137   }
00138   // no flag assigned, assume good
00139   return kGood;
00140 }
00141 
00142 
00143 
00144 std::ostream& operator<<(std::ostream& s, const EcalRecHit& hit) {
00145   if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalBarrel) 
00146     return s << EBDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
00147   else if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalEndcap) 
00148     return s << EEDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
00149   else if (hit.detid().det() == DetId::Ecal && hit.detid().subdetId() == EcalPreshower) 
00150     return s << ESDetId(hit.detid()) << ": " << hit.energy() << " GeV, " << hit.time() << " ns";
00151   else
00152     return s << "EcalRecHit undefined subdetector" ;
00153 }
00154 
00155