CMS 3D CMS Logo

TPedValues Class Reference

#include <CalibCalorimetry/EcalPedestalOffsets/interface/TPedValues.h>

List of all members.

Public Member Functions

int checkEntries (const int &DACstart=0, const int &DACend=256) const
 check whether the scan was complete in the range
int getCrystalNumber (int xtal) const
 return the index from the table
void insert (const int gainId, const int crystal, const int DAC, const int pedestal, const int endcapIndex)
 add a single value
int makePlots (TFile *rootFile, const std::string &dirName, const double maxSlopeAllowed, const double minSlopeAllowed, const double maxChi2OverNDF) const
 create a plot of the DAC pedestal trend
TPedResult terminate (const int &DACstart=0, const int &DACend=256) const
 calculate the offset values for all the containers
 TPedValues (const TPedValues &orig)
 copy ctor
 TPedValues (double RMSmax=2, int bestPedestal=200)
 ctor
 ~TPedValues ()
 dtor

Private Attributes

int endcapCrystalNumbers [1700]
int m_bestPedestal
TSinglePedEntry m_entries [3][1700][256]
double m_RMSmax


Detailed Description

Definition at line 19 of file TPedValues.h.


Constructor & Destructor Documentation

TPedValues::TPedValues ( double  RMSmax = 2,
int  bestPedestal = 200 
)

ctor

Definition at line 17 of file TPedValues.cc.

References endcapCrystalNumbers, i, and LogDebug.

00017                                                        :
00018   m_bestPedestal (bestPedestal) ,
00019   m_RMSmax (RMSmax) 
00020 {
00021   LogDebug ("EcalPedOffset") << "entering TPedValues ctor ..." ;
00022   for(int i=0; i<1700;++i)
00023     endcapCrystalNumbers[i] = 0;
00024 }

TPedValues::TPedValues ( const TPedValues orig  ) 

copy ctor

Definition at line 27 of file TPedValues.cc.

References endcapCrystalNumbers, i, LogDebug, m_bestPedestal, m_entries, and m_RMSmax.

00028 {
00029   LogDebug ("EcalPedOffset") << "entering TPedValues copyctor ..." ;
00030   m_bestPedestal = orig.m_bestPedestal ;
00031   m_RMSmax = orig.m_RMSmax ;
00032 
00033   for (int gain = 0 ; gain < 3 ; ++gain)
00034     for (int crystal = 0 ; crystal < 1700 ; ++crystal)
00035         for (int DAC = 0 ; DAC < 256 ; ++DAC)
00036           m_entries[gain][crystal][DAC] = orig.m_entries[gain][crystal][DAC] ;
00037 
00038   for(int i=0; i<1700;++i)
00039     endcapCrystalNumbers[i] = orig.endcapCrystalNumbers[i];
00040 }

TPedValues::~TPedValues (  ) 

dtor

Definition at line 44 of file TPedValues.cc.

00044 {}


Member Function Documentation

int TPedValues::checkEntries ( const int DACstart = 0,
const int DACend = 256 
) const

check whether the scan was complete in the range

loop over gains

loop over crystals

loop over DAC values

do something!

loop over DAC values

Definition at line 135 of file TPedValues.cc.

References TSinglePedEntry::average(), average(), ecalMGPA::gainId(), and m_entries.

00136 {
00137   assert (DACstart >= 0) ;
00138   assert (DACend <= 256) ;
00139   int returnCode = 0 ;
00141   for (int gainId = 1 ; gainId < 4 ; ++gainId)
00142     {
00144       for (int crystal = 0 ; crystal < 1700 ; ++crystal)
00145         {
00147           for (int DAC = DACstart ; DAC < DACend ; ++DAC)
00148             {
00149               double average = m_entries[gainId-1][crystal][DAC].average () ;
00150               if (average == -1) 
00151                 {
00152                   ++returnCode ;
00154 /*
00155                   std::cerr << "[TPedValues][checkEntries] WARNING!"
00156                             << "\tgainId " << gainId
00157                             << "\tcrystal " << crystal+1
00158                             << "\tDAC " << DAC
00159                             << " : pedestal measurement missing" 
00160                             << std::endl ;
00161 */
00162                 }
00163 /*
00164               std::cout << "[pietro][RMS]: " << m_entries[gainId-1][crystal][DAC].RMS ()     //FIXME
00165                         << "\t" << m_entries[gainId-1][crystal][DAC].RMSSq () //FIXME
00166                         << "\t" << DAC //FIXME
00167                         << "\t" << gainId //FIXME
00168                         << "\t" << crystal << std::endl ; //FIXME
00169 */              
00170             } 
00171         } // loop over crystals
00172     } // loop over gains
00173   return returnCode ;
00174 }

int TPedValues::getCrystalNumber ( int  xtal  )  const

return the index from the table

Definition at line 277 of file TPedValues.cc.

References endcapCrystalNumbers.

00278 {
00279   return endcapCrystalNumbers[xtal];
00280 }

void TPedValues::insert ( const int  gainId,
const int  crystal,
const int  DAC,
const int  pedestal,
const int  endcapIndex 
)

add a single value

Definition at line 47 of file TPedValues.cc.

References endcapCrystalNumbers, TSinglePedEntry::insert(), and m_entries.

00052 {
00053 //  assert (gainId > 0) ;
00054 //  assert (gainId < 4) ;
00055   if (gainId <= 0 || gainId >= 4)
00056     {
00057       edm::LogWarning ("EcalPedOffset") << "WARNING : TPedValues : gainId " << gainId
00058                                         << " does not exist, entry skipped" ;
00059       return ;    
00060     }
00061 //  assert (crystal > 0) ;
00062 //  assert (crystal <= 1700) ;
00063   if (crystal <= 0 || crystal > 1700)
00064     {
00065       edm::LogWarning ("EcalPedOffset") << "WARNING : TPedValues : crystal " << crystal
00066                                         << " does not exist, entry skipped" ;
00067       return ;    
00068     }
00069 //  assert (DAC >= 0) ; 
00070 //  assert (DAC < 256) ;
00071   if (DAC < 0 || DAC >= 256)
00072     {
00073       edm::LogWarning ("EcalPedOffset") << "WARNING : TPedValues : DAC value " << DAC
00074                                         << " is out range, entry skipped" ;
00075       return ;    
00076     }
00077   m_entries[gainId-1][crystal-1][DAC].insert (pedestal) ;
00078   endcapCrystalNumbers[crystal-1] = endcapIndex;
00079   return ;
00080 }

int TPedValues::makePlots ( TFile *  rootFile,
const std::string &  dirName,
const double  maxSlopeAllowed,
const double  minSlopeAllowed,
const double  maxChi2OverNDF 
) const

create a plot of the DAC pedestal trend

Definition at line 178 of file TPedValues.cc.

References TSinglePedEntry::average(), average(), endcapCrystalNumbers, int, m_entries, name, TSinglePedEntry::RMS(), and std.

00180 {
00181   using namespace std;
00182   // prepare the ROOT file
00183   if (!rootFile->cd (dirName.c_str ())) 
00184     {
00185       rootFile->mkdir (dirName.c_str ()) ;
00186       rootFile->cd (dirName.c_str ()) ;
00187     }
00188   
00189   // loop over the crystals
00190   for (int xtl=0 ; xtl<1700 ; ++xtl)
00191   {
00192     // loop over the gains
00193     for (int gain=0 ; gain<3 ; ++gain)
00194       {
00195         vector<double> asseX;
00196         vector<double> sigmaX;
00197         vector<double> asseY;
00198         vector<double> sigmaY;
00199         asseX.reserve(256);
00200         sigmaX.reserve(256);
00201         asseY.reserve(256);
00202         sigmaY.reserve(256);
00203         // loop over DAC values
00204         for (int dac=0 ; dac<256 ; ++dac)
00205           {
00206             double average = m_entries[gain][xtl][dac].average();
00207             if(average > -1)
00208             {
00209               double rms = m_entries[gain][xtl][dac].RMS();
00210               asseX.push_back(dac);
00211               sigmaX.push_back(0);
00212               asseY.push_back(average);
00213               sigmaY.push_back(rms);
00214             }
00215           } // loop over DAC values
00216         if(asseX.size() > 0)
00217         {
00218           int lastBin = 0;
00219           while(lastBin<(int)asseX.size()-1 && asseY[lastBin+1]>0
00220               && (asseY[lastBin+1]-asseY[lastBin+2])!=0)
00221             lastBin++;
00222           
00223           int fitRangeEnd = (int)asseX[lastBin];
00224           int kinkPt = 64;
00225           if(fitRangeEnd < 66)
00226             kinkPt = fitRangeEnd-4;
00227           TGraphErrors graph(asseX.size(),&(*asseX.begin()),&(*asseY.begin()),
00228               &(*sigmaX.begin()),&(*sigmaY.begin()));
00229           char funct[120];
00230           sprintf(funct,"(x<%d)*([0]*x+[1])+(x>=%d)*([2]*x+[3])",kinkPt,kinkPt);
00231           TF1 fitFunction("fitFunction",funct,asseX[0],fitRangeEnd);
00232           fitFunction.SetLineColor(2);
00233           
00234           char name[120] ;
00235           int gainHuman;
00236           if      (gain ==0) gainHuman =12;
00237           else if (gain ==1) gainHuman =6;
00238           else if (gain ==2) gainHuman =1;
00239           else               gainHuman =-1;
00240           sprintf (name,"XTL%04d_GAIN%02d",endcapCrystalNumbers[xtl],gainHuman) ;
00241           graph.GetXaxis()->SetTitle("DAC value");
00242           graph.GetYaxis()->SetTitle("Average pedestal ADC");
00243           graph.Fit("fitFunction","RWQ");
00244           graph.Write (name);
00245           
00246           double slope1 = fitFunction.GetParameter(0);
00247           double slope2 = fitFunction.GetParameter(2);
00248 
00249           if(fitFunction.GetChisquare()/fitFunction.GetNDF()>maxChi2OverNDF ||
00250               fitFunction.GetChisquare()/fitFunction.GetNDF()<0 ||
00251               slope1>0 || slope2>0 ||
00252               ((slope1<-29 || slope1>-18) && slope1<0) || 
00253               ((slope2<-29 || slope2>-18) && slope2<0))
00254           {
00255             edm::LogError("EcalPedOffset") << "TPedValues : TGraph for channel:" << 
00256               endcapCrystalNumbers[xtl] << 
00257               " gain:" << gainHuman << " is not linear;" << "  slope of line1:" << 
00258               fitFunction.GetParameter(0) << " slope of line2:" << 
00259               fitFunction.GetParameter(2) << " reduced chi-squared:" << 
00260               fitFunction.GetChisquare()/fitFunction.GetNDF();
00261           }
00262           //LogDebug("EcalPedOffset") << "TPedValues : TGraph for channel:" << xtl+1 << " gain:"
00263           //  << gainHuman << " has " << asseX.size() << " points...back is:" << asseX.back() 
00264           //  << " and front+1 is:" << asseX.front()+1;
00265           if((asseX.back()-asseX.front()+1)!=asseX.size())
00266             edm::LogError("EcalPedOffset") << "TPedValues : Pedestal average not found " <<
00267               "for all DAC values scanned in channel:" << endcapCrystalNumbers[xtl]
00268               << " gain:" << gainHuman;
00269         }
00270       } // loop over the gains
00271   }     // (loop over the crystals)
00272   
00273   return 0 ;
00274 }

TPedResult TPedValues::terminate ( const int DACstart = 0,
const int DACend = 256 
) const

calculate the offset values for all the containers

loop over gains

loop over crystals

find the DAC value with the average pedestal nearest to 200

loop over DAC values

loop over DAC values

Definition at line 83 of file TPedValues.cc.

References TSinglePedEntry::average(), average(), endcapCrystalNumbers, ecalMGPA::gainId(), m_bestPedestal, TPedResult::m_DACvalue, m_entries, and m_RMSmax.

00084 {
00085   assert (DACstart >= 0) ;
00086   assert (DACend <= 256) ;
00087 //  checkEntries (DACstart, DACend) ;
00088 
00089   TPedResult bestDAC ;
00091   for (int gainId = 1 ; gainId < 4 ; ++gainId)
00092     {
00094       for (int crystal = 0 ; crystal < 1700 ; ++crystal)
00095         {
00097           double delta = 1000 ;
00098           int dummyBestDAC = -1 ;
00099           bool hasDigis = false;
00101           for (int DAC = DACstart ; DAC < DACend ; ++DAC)
00102             {
00103               double average = m_entries[gainId-1][crystal][DAC].average () ;
00104               if (average == -1) continue ;
00105               hasDigis = true;
00106               if (m_entries[gainId-1][crystal][DAC].RMSSq () > m_RMSmax * m_RMSmax) continue ;
00107               if (fabs (average - m_bestPedestal) < delta &&   average>1 ) 
00108                 {
00109                   delta = fabs (average - m_bestPedestal) ;
00110                   dummyBestDAC = DAC ;
00111                 }
00112             } 
00113 
00114           bestDAC.m_DACvalue[gainId-1][crystal] = dummyBestDAC ;
00115           
00116           if ((dummyBestDAC == (DACend-1) || dummyBestDAC == -1) && hasDigis)
00117           {
00118             int gainHuman;
00119             if      (gainId ==1) gainHuman =12;
00120             else if (gainId ==2) gainHuman =6;
00121             else if (gainId ==3) gainHuman =1;
00122             else                 gainHuman =-1;
00123             edm::LogError("EcalPedOffset")
00124               << " TPedValues :  cannot find best DAC value for channel: "
00125               << endcapCrystalNumbers[crystal]
00126               << " gain: " << gainHuman;
00127           }
00128           
00129         } // loop over crystals
00130     } // loop over gains
00131   return bestDAC ;
00132 }


Member Data Documentation

int TPedValues::endcapCrystalNumbers[1700] [private]

Definition at line 59 of file TPedValues.h.

Referenced by getCrystalNumber(), insert(), makePlots(), terminate(), and TPedValues().

int TPedValues::m_bestPedestal [private]

Definition at line 56 of file TPedValues.h.

Referenced by terminate(), and TPedValues().

TSinglePedEntry TPedValues::m_entries[3][1700][256] [private]

Definition at line 54 of file TPedValues.h.

Referenced by checkEntries(), insert(), makePlots(), terminate(), and TPedValues().

double TPedValues::m_RMSmax [private]

Definition at line 57 of file TPedValues.h.

Referenced by terminate(), and TPedValues().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:33:52 2009 for CMSSW by  doxygen 1.5.4