CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
TPedValues Class Reference

#include <TPedValues.h>

Public Member Functions

int checkEntries (const int &DACstart=0, const int &DACend=256) const
 check whether the scan was complete in the range More...
 
int getCrystalNumber (int xtal) const
 return the index from the table More...
 
void insert (const int gainId, const int crystal, const int DAC, const int pedestal, const int endcapIndex)
 add a single value More...
 
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 More...
 
TPedResult terminate (const int &DACstart=0, const int &DACend=256) const
 calculate the offset values for all the containers More...
 
 TPedValues (double RMSmax=2, int bestPedestal=200)
 ctor More...
 
 TPedValues (const TPedValues &orig)
 copy ctor More...
 
 ~TPedValues ()
 dtor More...
 

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, mps_fire::i, and LogDebug.

17  :
18  m_bestPedestal (bestPedestal) ,
19  m_RMSmax (RMSmax)
20 {
21  LogDebug ("EcalPedOffset") << "entering TPedValues ctor ..." ;
22  for(int i=0; i<1700;++i)
24 }
#define LogDebug(id)
int m_bestPedestal
Definition: TPedValues.h:56
double m_RMSmax
Definition: TPedValues.h:57
int endcapCrystalNumbers[1700]
Definition: TPedValues.h:59
TPedValues::TPedValues ( const TPedValues orig)

copy ctor

Definition at line 27 of file TPedValues.cc.

References endcapCrystalNumbers, muonCSCDigis_cfi::gain, mps_fire::i, LogDebug, m_bestPedestal, m_entries, and m_RMSmax.

28 {
29  LogDebug ("EcalPedOffset") << "entering TPedValues copyctor ..." ;
31  m_RMSmax = orig.m_RMSmax ;
32 
33  for (int gain = 0 ; gain < 3 ; ++gain)
34  for (int crystal = 0 ; crystal < 1700 ; ++crystal)
35  for (int DAC = 0 ; DAC < 256 ; ++DAC)
36  m_entries[gain][crystal][DAC] = orig.m_entries[gain][crystal][DAC] ;
37 
38  for(int i=0; i<1700;++i)
40 }
#define LogDebug(id)
TSinglePedEntry m_entries[3][1700][256]
Definition: TPedValues.h:54
int m_bestPedestal
Definition: TPedValues.h:56
double m_RMSmax
Definition: TPedValues.h:57
int endcapCrystalNumbers[1700]
Definition: TPedValues.h:59
TPedValues::~TPedValues ( )

dtor

Definition at line 44 of file TPedValues.cc.

44 {}

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(), ecalMGPA::gainId(), m_entries, and runEdmFileComparison::returnCode.

136 {
137  assert (DACstart >= 0) ;
138  assert (DACend <= 256) ;
139  int returnCode = 0 ;
141  for (int gainId = 1 ; gainId < 4 ; ++gainId)
142  {
144  for (int crystal = 0 ; crystal < 1700 ; ++crystal)
145  {
147  for (int DAC = DACstart ; DAC < DACend ; ++DAC)
148  {
149  double average = m_entries[gainId-1][crystal][DAC].average () ;
150  if (average == -1)
151  {
152  ++returnCode ;
154 /*
155  std::cerr << "[TPedValues][checkEntries] WARNING!"
156  << "\tgainId " << gainId
157  << "\tcrystal " << crystal+1
158  << "\tDAC " << DAC
159  << " : pedestal measurement missing"
160  << std::endl ;
161 */
162  }
163 /*
164  std::cout << "[pietro][RMS]: " << m_entries[gainId-1][crystal][DAC].RMS () //FIXME
165  << "\t" << m_entries[gainId-1][crystal][DAC].RMSSq () //FIXME
166  << "\t" << DAC //FIXME
167  << "\t" << gainId //FIXME
168  << "\t" << crystal << std::endl ; //FIXME
169 */
170  }
171  } // loop over crystals
172  } // loop over gains
173  return returnCode ;
174 }
TSinglePedEntry m_entries[3][1700][256]
Definition: TPedValues.h:54
int gainId(sample_type sample)
get the gainId (2 bits)
double average() const
get the average of the inserted values
int TPedValues::getCrystalNumber ( int  xtal) const

return the index from the table

Definition at line 277 of file TPedValues.cc.

References endcapCrystalNumbers.

278 {
279  return endcapCrystalNumbers[xtal];
280 }
int endcapCrystalNumbers[1700]
Definition: TPedValues.h:59
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(), m_entries, and reco::return().

Referenced by BeautifulSoup.PageElement::append().

52 {
53 // assert (gainId > 0) ;
54 // assert (gainId < 4) ;
55  if (gainId <= 0 || gainId >= 4)
56  {
57  edm::LogWarning ("EcalPedOffset") << "WARNING : TPedValues : gainId " << gainId
58  << " does not exist, entry skipped" ;
59  return ;
60  }
61 // assert (crystal > 0) ;
62 // assert (crystal <= 1700) ;
63  if (crystal <= 0 || crystal > 1700)
64  {
65  edm::LogWarning ("EcalPedOffset") << "WARNING : TPedValues : crystal " << crystal
66  << " does not exist, entry skipped" ;
67  return ;
68  }
69 // assert (DAC >= 0) ;
70 // assert (DAC < 256) ;
71  if (DAC < 0 || DAC >= 256)
72  {
73  edm::LogWarning ("EcalPedOffset") << "WARNING : TPedValues : DAC value " << DAC
74  << " is out range, entry skipped" ;
75  return ;
76  }
77  m_entries[gainId-1][crystal-1][DAC].insert (pedestal) ;
78  endcapCrystalNumbers[crystal-1] = endcapIndex;
79  return ;
80 }
TSinglePedEntry m_entries[3][1700][256]
Definition: TPedValues.h:54
int gainId(sample_type sample)
get the gainId (2 bits)
return(e1-e2)*(e1-e2)+dp *dp
int endcapCrystalNumbers[1700]
Definition: TPedValues.h:59
void insert(const int &pedestal)
add a single value
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(), endcapCrystalNumbers, muonCSCDigis_cfi::gain, createfilelist::int, m_entries, dataset::name, RecoTauDiscriminantConfiguration::rms, TSinglePedEntry::RMS(), fftjetvertexadder_cfi::sigmaX, and fftjetvertexadder_cfi::sigmaY.

180 {
181  using namespace std;
182  // prepare the ROOT file
183  if (!rootFile->cd (dirName.c_str ()))
184  {
185  rootFile->mkdir (dirName.c_str ()) ;
186  rootFile->cd (dirName.c_str ()) ;
187  }
188 
189  // loop over the crystals
190  for (int xtl=0 ; xtl<1700 ; ++xtl)
191  {
192  // loop over the gains
193  for (int gain=0 ; gain<3 ; ++gain)
194  {
195  vector<double> asseX;
196  vector<double> sigmaX;
197  vector<double> asseY;
198  vector<double> sigmaY;
199  asseX.reserve(256);
200  sigmaX.reserve(256);
201  asseY.reserve(256);
202  sigmaY.reserve(256);
203  // loop over DAC values
204  for (int dac=0 ; dac<256 ; ++dac)
205  {
206  double average = m_entries[gain][xtl][dac].average();
207  if(average > -1)
208  {
209  double rms = m_entries[gain][xtl][dac].RMS();
210  asseX.push_back(dac);
211  sigmaX.push_back(0);
212  asseY.push_back(average);
213  sigmaY.push_back(rms);
214  }
215  } // loop over DAC values
216  if(asseX.size() > 0)
217  {
218  int lastBin = 0;
219  while(lastBin<(int)asseX.size()-1 && asseY[lastBin+1]>0
220  && (asseY[lastBin+1]-asseY[lastBin+2])!=0)
221  lastBin++;
222 
223  int fitRangeEnd = (int)asseX[lastBin];
224  int kinkPt = 64;
225  if(fitRangeEnd < 66)
226  kinkPt = fitRangeEnd-4;
227  TGraphErrors graph(asseX.size(),&(*asseX.begin()),&(*asseY.begin()),
228  &(*sigmaX.begin()),&(*sigmaY.begin()));
229  char funct[120];
230  sprintf(funct,"(x<%d)*([0]*x+[1])+(x>=%d)*([2]*x+[3])",kinkPt,kinkPt);
231  TF1 fitFunction("fitFunction",funct,asseX[0],fitRangeEnd);
232  fitFunction.SetLineColor(2);
233 
234  char name[120] ;
235  int gainHuman;
236  if (gain ==0) gainHuman =12;
237  else if (gain ==1) gainHuman =6;
238  else if (gain ==2) gainHuman =1;
239  else gainHuman =-1;
240  sprintf (name,"XTL%04d_GAIN%02d",endcapCrystalNumbers[xtl],gainHuman) ;
241  graph.GetXaxis()->SetTitle("DAC value");
242  graph.GetYaxis()->SetTitle("Average pedestal ADC");
243  graph.Fit(&fitFunction,"RWQ");
244  graph.Write (name);
245 
246  double slope1 = fitFunction.GetParameter(0);
247  double slope2 = fitFunction.GetParameter(2);
248 
249  if(fitFunction.GetChisquare()/fitFunction.GetNDF()>maxChi2OverNDF ||
250  fitFunction.GetChisquare()/fitFunction.GetNDF()<0 ||
251  slope1>0 || slope2>0 ||
252  ((slope1<-29 || slope1>-18) && slope1<0) ||
253  ((slope2<-29 || slope2>-18) && slope2<0))
254  {
255  edm::LogError("EcalPedOffset") << "TPedValues : TGraph for channel:" <<
256  endcapCrystalNumbers[xtl] <<
257  " gain:" << gainHuman << " is not linear;" << " slope of line1:" <<
258  fitFunction.GetParameter(0) << " slope of line2:" <<
259  fitFunction.GetParameter(2) << " reduced chi-squared:" <<
260  fitFunction.GetChisquare()/fitFunction.GetNDF();
261  }
262  //LogDebug("EcalPedOffset") << "TPedValues : TGraph for channel:" << xtl+1 << " gain:"
263  // << gainHuman << " has " << asseX.size() << " points...back is:" << asseX.back()
264  // << " and front+1 is:" << asseX.front()+1;
265  if((asseX.back()-asseX.front()+1)!=asseX.size())
266  edm::LogError("EcalPedOffset") << "TPedValues : Pedestal average not found " <<
267  "for all DAC values scanned in channel:" << endcapCrystalNumbers[xtl]
268  << " gain:" << gainHuman;
269  }
270  } // loop over the gains
271  } // (loop over the crystals)
272 
273  return 0 ;
274 }
TSinglePedEntry m_entries[3][1700][256]
Definition: TPedValues.h:54
Definition: Abs.h:5
double RMS() const
get the RMS of the inserted values
double average() const
get the average of the inserted values
Definition: adjgraph.h:12
int endcapCrystalNumbers[1700]
Definition: TPedValues.h:59
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(), delta, endcapCrystalNumbers, ecalMGPA::gainId(), m_bestPedestal, TPedResult::m_DACvalue, m_entries, and m_RMSmax.

84 {
85  assert (DACstart >= 0) ;
86  assert (DACend <= 256) ;
87 // checkEntries (DACstart, DACend) ;
88 
89  TPedResult bestDAC ;
91  for (int gainId = 1 ; gainId < 4 ; ++gainId)
92  {
94  for (int crystal = 0 ; crystal < 1700 ; ++crystal)
95  {
97  double delta = 1000 ;
98  int dummyBestDAC = -1 ;
99  bool hasDigis = false;
101  for (int DAC = DACstart ; DAC < DACend ; ++DAC)
102  {
103  double average = m_entries[gainId-1][crystal][DAC].average () ;
104  if (average == -1) continue ;
105  hasDigis = true;
106  if (m_entries[gainId-1][crystal][DAC].RMSSq () > m_RMSmax * m_RMSmax) continue ;
107  if (fabs (average - m_bestPedestal) < delta && average>1 )
108  {
109  delta = fabs (average - m_bestPedestal) ;
110  dummyBestDAC = DAC ;
111  }
112  }
113 
114  bestDAC.m_DACvalue[gainId-1][crystal] = dummyBestDAC ;
115 
116  if ((dummyBestDAC == (DACend-1) || dummyBestDAC == -1) && hasDigis)
117  {
118  int gainHuman;
119  if (gainId ==1) gainHuman =12;
120  else if (gainId ==2) gainHuman =6;
121  else if (gainId ==3) gainHuman =1;
122  else gainHuman =-1;
123  edm::LogError("EcalPedOffset")
124  << " TPedValues : cannot find best DAC value for channel: "
125  << endcapCrystalNumbers[crystal]
126  << " gain: " << gainHuman;
127  }
128 
129  } // loop over crystals
130  } // loop over gains
131  return bestDAC ;
132 }
dbl * delta
Definition: mlp_gen.cc:36
TSinglePedEntry m_entries[3][1700][256]
Definition: TPedValues.h:54
int gainId(sample_type sample)
get the gainId (2 bits)
int m_DACvalue[3][1700]
Definition: TPedResult.h:28
int m_bestPedestal
Definition: TPedValues.h:56
double average() const
get the average of the inserted values
double m_RMSmax
Definition: TPedValues.h:57
int endcapCrystalNumbers[1700]
Definition: TPedValues.h:59

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().