CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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.), flags_(0), aux_(0) { }
00007 
00008 EcalUncalibratedRecHit::EcalUncalibratedRecHit(const DetId& id, double ampl, double ped,
00009                           double jit, double chi2, uint32_t flags, uint32_t aux) :
00010      amplitude_(ampl), pedestal_(ped), jitter_(jit), chi2_(chi2), flags_(flags), aux_(aux), id_(id) { }
00011 
00012 EcalUncalibratedRecHit::~EcalUncalibratedRecHit() {
00013 }
00014 
00015 bool EcalUncalibratedRecHit::isSaturated() const {
00016   return ( recoFlag() == kSaturated );
00017 }
00018 
00019 float EcalUncalibratedRecHit::outOfTimeEnergy() const
00020 {
00021         uint32_t rawEnergy = (0x1FFF & flags_>>4);
00022         uint16_t exponent = rawEnergy>>10;
00023         uint16_t significand = ~(0xE<<9) & rawEnergy;
00024         return (float) significand*pow(10,exponent-5);
00025 }
00026 
00027 void EcalUncalibratedRecHit::setRecoFlag( uint32_t flag )
00028 {
00029         flags_ = (~0xF & flags_) | (flag & 0xF);
00030 }
00031 
00032 void EcalUncalibratedRecHit::setOutOfTimeEnergy( float energy )
00033 {
00034         if ( energy > 0.001 ) {
00035                 uint16_t exponent = lround(floor(log10(energy)))+3;
00036                 uint16_t significand = lround(energy/pow(10,exponent-5));
00037                 uint32_t rawEnergy = exponent<<10 | significand;
00038                 setFlags( ( ~(0x1FFF<<4) & flags_) | ((rawEnergy & 0x1FFF)<<4) );
00039         }
00040 }
00041 
00042 void EcalUncalibratedRecHit::setOutOfTimeChi2( float chi2 )
00043 {
00044         // use 7 bits
00045         if ( chi2 > 64. ) chi2 = 64.;
00046         uint32_t rawChi2 = lround( chi2 / 64. * ((1<<7)-1) );
00047         // shift by 17 bits (recoFlag + outOfTimeEnergy)
00048         setFlags( (~(0x7F<<17) & flags_) | ((rawChi2 & 0x7F)<<17) );
00049 }
00050 
00051 float EcalUncalibratedRecHit::outOfTimeChi2() const
00052 {
00053         uint32_t rawChi2 = 0x7F & (flags_>>17);
00054         return (float)rawChi2 / (float)((1<<7)-1) * 64.;
00055 }
00056 
00057 float EcalUncalibratedRecHit::jitterError() const
00058 {
00059         // stored in ps, but return BXs to match with jitter units
00060         uint32_t jitterErrorBits = 0xFF & aux_;
00061         // all bits off --> time reco bailed out (return negative value)
00062         if( (0xFF & jitterErrorBits) == 0x00)
00063                 return -1;
00064         // all bits on  --> time error over 5 ns (return large value)
00065         if( (0xFF & jitterErrorBits) == 0xFF)
00066                 return 10000;
00067 
00068         float LSB = 1.26008;
00069         uint8_t exponent = jitterErrorBits>>5;
00070         uint8_t significand = jitterErrorBits & ~(0x7<<5);
00071         return (float)(pow(2.,exponent)*significand*LSB)/(25.*1000);
00072 }
00073 
00074 void EcalUncalibratedRecHit::setJitterError( float jitterErr )
00075 {
00076         // use 8 bits (3 exp, 5 mant) and store in ps
00077         // has range of 5 ps - 5000 ps
00078         // expect input in BX units
00079         // all bits off --> time reco bailed out
00080         if(jitterErr < 0)
00081         {
00082                 aux_ = (~0xFF & aux_);
00083                 return;
00084         }
00085         // all bits on  --> time error over 5 ns
00086         if(25*jitterErr >= 5)
00087         {
00088                 aux_ = (0xFF | aux_);
00089                 return;
00090         }
00091 
00092         float LSB = 1.26008;
00093         float quantityInLSB = (1000*25*jitterErr)/LSB;
00094         int log2OfQuantity = (int) (log2( quantityInLSB ));
00095         int exponentTmp = log2OfQuantity - 4;
00096         uint8_t exponent=0;
00097         if (exponentTmp>0) exponent = exponentTmp;
00098         uint8_t significand = (int) ( lround( quantityInLSB / pow(2.,exponent) )   );
00099         uint32_t jitterErrorBits = exponent<<5 | significand;
00100   
00101         if( (0xFF & jitterErrorBits) == 0xFF)
00102           jitterErrorBits = 0xFE;
00103         if( (0xFF & jitterErrorBits) == 0x00)
00104           jitterErrorBits = 0x01;
00105 
00106         aux_ = (~0xFF & aux_) | (jitterErrorBits & 0xFF);
00107 
00108 }
00109 
00110 bool EcalUncalibratedRecHit::isJitterValid() const
00111 {
00112         if(jitterError() <= 0)
00113           return false;
00114         else
00115           return true;
00116 }
00117 
00118 bool EcalUncalibratedRecHit::isJitterErrorValid() const
00119 {
00120         if(!isJitterValid())
00121           return false;
00122         if(jitterError() >= 10000)
00123           return false;
00124 
00125         return true;
00126 }
00127 
00128 uint8_t EcalUncalibratedRecHit::jitterErrorBits() const
00129 {
00130         uint8_t jitterErrorBits = 0xFF & aux_;
00131         return jitterErrorBits;
00132 }