CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoTBCalo/EcalTBTDCReconstructor/src/EcalTBTDCRecInfoAlgo.cc

Go to the documentation of this file.
00001 #include "RecoTBCalo/EcalTBTDCReconstructor/interface/EcalTBTDCRecInfoAlgo.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 
00004 #include <list>
00005 #include <iostream>
00006 
00007 EcalTBTDCRecInfoAlgo::EcalTBTDCRecInfoAlgo(const std::vector<EcalTBTDCRanges>& tdcRanges) :
00008   tdcRanges_(tdcRanges), tdcRangeErrorMessageAlreadyDisplayed_(false), actualRun_(-1) , actualRange_(-1)
00009 {
00010   
00011 }
00012 
00013 EcalTBTDCRecInfo EcalTBTDCRecInfoAlgo::reconstruct(const EcalTBTDCRawInfo& TDCRawInfo,const EcalTBEventHeader& eventHeader, bool use2004OffsetConvention) const 
00014 {
00015   if (actualRun_ != eventHeader.runNumber() )
00016     {
00017       actualRun_ = eventHeader.runNumber();
00018       actualRange_ = -1;
00019       for (unsigned int i=0; i<tdcRanges_.size();i++)
00020         if ( eventHeader.runNumber() <= tdcRanges_[i].runRanges.second && eventHeader.runNumber() >= tdcRanges_[i].runRanges.first )
00021           actualRange_ = i;
00022       
00023       if (actualRange_ == -1)
00024         {
00025           edm::LogError("TDCRange not found") << "TDC range not found";
00026           return EcalTBTDCRecInfo(-1);
00027         }
00028     }
00029   
00030   int eventType;
00031   eventType=( (eventHeader.dbEventType() == 0) ? 0 : (eventHeader.dbEventType()-1));
00032 
00033   int tdcd = TDCRawInfo[0].tdcValue();
00034 
00035   if( !tdcRangeErrorMessageAlreadyDisplayed_ 
00036       && (tdcd < tdcRanges_[actualRange_].tdcMin[eventType] || tdcd > tdcRanges_[actualRange_].tdcMax[eventType]) ){
00037     std::cout << " ============================" <<std::endl;
00038     std::cout << " Event type: " << eventType << std::endl;
00039     std::cout << " TDC values not correctly set Raw TDC = "<< tdcd 
00040               << " (Min/Max = "<< tdcRanges_[actualRange_].tdcMin[eventType] << "/" << tdcRanges_[actualRange_].tdcMax[eventType]
00041               << std::endl;
00042     std::cout << " ============================" <<std::endl;
00043     tdcRangeErrorMessageAlreadyDisplayed_ = true;
00044   }
00045 
00046   double offset = ( (double)tdcd - (double)tdcRanges_[actualRange_].tdcMin[eventType] )
00047     / ((double)tdcRanges_[actualRange_].tdcMax[eventType]-(double)tdcRanges_[actualRange_].tdcMin[eventType]);
00048   if (use2004OffsetConvention)
00049     offset = (1. - offset) ;
00050   return EcalTBTDCRecInfo(offset); 
00051 }
00052