CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/DataFormats/EcalRecHit/src/EcalUncalibratedRecHit.cc

Go to the documentation of this file.
00001 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include <math.h>
00004 
00005 EcalUncalibratedRecHit::EcalUncalibratedRecHit() :
00006      amplitude_(0.), pedestal_(0.), jitter_(0.), chi2_(10000.), OOTamplitude_(0.), OOTchi2_(10000.), flags_(0), aux_(0) { }
00007 
00008 EcalUncalibratedRecHit::EcalUncalibratedRecHit(const DetId& id, float ampl, float ped,
00009                           float jit, float chi2, uint32_t flags, uint32_t aux) :
00010      amplitude_(ampl), pedestal_(ped), jitter_(jit), chi2_(chi2), OOTamplitude_(0.), OOTchi2_(10000.), flags_(flags), aux_(aux), id_(id) { }
00011 
00012 EcalUncalibratedRecHit::~EcalUncalibratedRecHit() {
00013 }
00014 
00015 bool EcalUncalibratedRecHit::isSaturated() const {
00016   return EcalUncalibratedRecHit::checkFlag(kSaturated);
00017 }
00018 
00019 
00020 float EcalUncalibratedRecHit::jitterError() const
00021 {
00022         // stored in ps, but return BXs to match with jitter units
00023         uint32_t jitterErrorBits = 0xFF & aux_;
00024         // all bits off --> time reco bailed out (return negative value)
00025         if( (0xFF & jitterErrorBits) == 0x00)
00026                 return -1;
00027         // all bits on  --> time error over 5 ns (return large value)
00028         if( (0xFF & jitterErrorBits) == 0xFF)
00029                 return 10000;
00030 
00031         float LSB = 1.26008;
00032         uint8_t exponent = jitterErrorBits>>5;
00033         uint8_t significand = jitterErrorBits & ~(0x7<<5);
00034         return (float)(pow(2.,exponent)*significand*LSB)/(25.*1000);
00035 }
00036 
00037 void EcalUncalibratedRecHit::setJitterError( float jitterErr )
00038 {
00039         // use 8 bits (3 exp, 5 mant) and store in ps
00040         // has range of 5 ps - 5000 ps
00041         // expect input in BX units
00042         // all bits off --> time reco bailed out
00043         if(jitterErr < 0)
00044         {
00045                 aux_ = (~0xFF & aux_);
00046                 return;
00047         }
00048         // all bits on  --> time error over 5 ns
00049         if(25*jitterErr >= 5)
00050         {
00051                 aux_ = (0xFF | aux_);
00052                 return;
00053         }
00054 
00055         float LSB = 1.26008;
00056         float quantityInLSB = (1000*25*jitterErr)/LSB;
00057         int log2OfQuantity = (int) (log2( quantityInLSB ));
00058         int exponentTmp = log2OfQuantity - 4;
00059         uint8_t exponent=0;
00060         if (exponentTmp>0) exponent = exponentTmp;
00061         uint8_t significand = (int) ( lround( quantityInLSB / pow(2.,exponent) )   );
00062         uint32_t jitterErrorBits = exponent<<5 | significand;
00063   
00064         if( (0xFF & jitterErrorBits) == 0xFF)
00065           jitterErrorBits = 0xFE;
00066         if( (0xFF & jitterErrorBits) == 0x00)
00067           jitterErrorBits = 0x01;
00068 
00069         aux_ = (~0xFF & aux_) | (jitterErrorBits & 0xFF);
00070 
00071 }
00072 
00073 bool EcalUncalibratedRecHit::isJitterValid() const
00074 {
00075         if(jitterError() <= 0)
00076           return false;
00077         else
00078           return true;
00079 }
00080 
00081 bool EcalUncalibratedRecHit::isJitterErrorValid() const
00082 {
00083         if(!isJitterValid())
00084           return false;
00085         if(jitterError() >= 10000)
00086           return false;
00087 
00088         return true;
00089 }
00090 
00091 uint8_t EcalUncalibratedRecHit::jitterErrorBits() const
00092 {
00093         uint8_t jitterErrorBits = 0xFF & aux_;
00094         return jitterErrorBits;
00095 }
00096 
00097 
00098 void EcalUncalibratedRecHit::setFlagBit(EcalUncalibratedRecHit::Flags flag){
00099 
00100        if  (flag == kGood) {
00101           //then set all bits to zero;
00102           flags_  = 0;
00103           return;
00104       }
00105      // else set the flagbit
00106      flags_|= 0x1 <<  flag;  
00107 }
00108 
00109 
00110 bool EcalUncalibratedRecHit::checkFlag(EcalUncalibratedRecHit::Flags flag) const {
00111        if(flag == kGood){ if ( ! flags_ ) return true;else return false;} // if all flags are unset, then hit is good
00112        return  flags_ & ( 0x1<<flag);
00113 }
00114