StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSvtHybridStat2.cc
1  /***************************************************************************
2  *
3  * $Id: StSvtHybridStat2.cc,v 1.3 2003/09/02 17:59:06 perev Exp $
4  *
5  * Author: Marcelo Munhoz
6  ***************************************************************************
7  *
8  * Description: SVT Hybrid Pixel Statistic class used to calculate 2nd order pedestal correction
9  *
10  ***************************************************************************
11  *
12  * $Log: StSvtHybridStat2.cc,v $
13  * Revision 1.3 2003/09/02 17:59:06 perev
14  * gcc 3.2 updates + WarnOff
15  *
16  * Revision 1.2 2000/07/03 02:07:54 perev
17  * StEvent: vector<TObject*>
18  *
19  * Revision 1.1.1.1 2000/03/10 14:26:21 munhoz
20  * SVT Class Library
21  *
22  **************************************************************************/
24 // //
25 // Used to calculate the statistics (mean and RMS) of pixel quantities //
26 // given a SCA capacitor number. //
27 // It is used to calculate the 2nd order pedestals correction of a hybrid.//
28 // //
30 
31 #include <math.h>
32 #include "StArray.h"
33 #include "StSvtHybridPixels.hh"
34 #include "StSvtHybridStat2.hh"
35 
36 ClassImp(StSvtHybridStat2)
37 
38 StSvtHybridStat2::StSvtHybridStat2(int barrel, int ladder, int wafer, int hybrid) :
39  StSvtHybridObject(barrel, ladder, wafer, hybrid)
40 {
41  // The same as StSvtHybrid. Set number of capacitors to 128.
42 
43  mNumberOfCapacitors = 128;
44 
45  StSvtHybridPixels *m0PerCapacitor;
46  StSvtHybridPixels *m1PerCapacitor;
47  StSvtHybridPixels *m2PerCapacitor;
48 
49  m0 = new StObjArray(mNumberOfCapacitors);
50  m1 = new StObjArray(mNumberOfCapacitors);
51  m2 = new StObjArray(mNumberOfCapacitors);
52 
53  for (int i = 0; i < mNumberOfCapacitors; i++) {
54 
55  m0PerCapacitor = new StSvtHybridPixels(barrel, ladder, wafer, hybrid);
56  m1PerCapacitor = new StSvtHybridPixels(barrel, ladder, wafer, hybrid);
57  m2PerCapacitor = new StSvtHybridPixels(barrel, ladder, wafer, hybrid);
58 
59  m0->push_back(m0PerCapacitor);
60  m1->push_back(m1PerCapacitor);
61  m2->push_back(m2PerCapacitor);
62  }
63 }
64 
65 StSvtHybridStat2::~StSvtHybridStat2()
66 {
67  delete m0;
68  delete m1;
69  delete m2;
70 }
71 
72 StSvtHybridStat2& StSvtHybridStat2::operator = (const StSvtHybridStat2& h)
73 {
74  m0 = h.m0;
75  m1 = h.m1;
76  m2 = h.m2;
77  return *this;
78 }
79 
80 float StSvtHybridStat2::getMean(int anode, int time, int capacitor)
81 {
82  // Returns the mean value for pixel (anode,time) and capacitor
83 
84  StSvtHybridPixels* m0PerCapacitor = (StSvtHybridPixels*)m0->at(capacitor);
85  StSvtHybridPixels* m1PerCapacitor = (StSvtHybridPixels*)m1->at(capacitor);
86 
87  int index = m0PerCapacitor->getPixelIndex(anode,time);
88  int n = (int)m0PerCapacitor->At(index);
89  int sum = (int)m1PerCapacitor->At(index);
90 
91  float mean;
92 
93  if (n)
94  mean = (float)sum/(float)n;
95  else
96  return 0;
97 
98  return mean;
99 }
100 
101 float StSvtHybridStat2::getRMS(int anode, int time, int capacitor)
102 {
103  // Returns the RMS for pixel (anode,time) and capacitor
104 
105  StSvtHybridPixels* m0PerCapacitor = (StSvtHybridPixels*)m0->at(capacitor);
106  StSvtHybridPixels* m1PerCapacitor = (StSvtHybridPixels*)m1->at(capacitor);
107  StSvtHybridPixels* m2PerCapacitor = (StSvtHybridPixels*)m2->at(capacitor);
108 
109  int index = m0PerCapacitor->getPixelIndex(anode,time);
110  int n = (int)m0PerCapacitor->At(index);
111  int sum = (int)m1PerCapacitor->At(index);
112  int sumSQ = (int)m2PerCapacitor->At(index);
113 
114  float mean;
115  float meanSQ;
116 
117  if (n) {
118  mean = (float)sum/(float)n;
119  meanSQ = (float)sumSQ/(float)n;
120  }
121  else
122  return 0;
123 
124  float rms = ::sqrt(meanSQ - mean*mean);
125 
126  return rms;
127 }
128 
129 void StSvtHybridStat2::fillMom(int x, int anode, int time, int capacitor)
130 {
131  // Fills the 0th, 1st and 2nd order momenta of pixel (anode,time) and capacitor with the value x
132 
133  StSvtHybridPixels* m0PerCapacitor = (StSvtHybridPixels*)m0->at(capacitor);
134  StSvtHybridPixels* m1PerCapacitor = (StSvtHybridPixels*)m1->at(capacitor);
135  StSvtHybridPixels* m2PerCapacitor = (StSvtHybridPixels*)m2->at(capacitor);
136 
137  int previousValue;
138  int index = m0PerCapacitor->getPixelIndex(anode,time);
139 
140  previousValue = (int)m0PerCapacitor->At(index);
141  m0PerCapacitor->AddAt(1+previousValue,index);
142 
143  previousValue = (int)m1PerCapacitor->At(index);
144  m1PerCapacitor->AddAt(x+previousValue,index);
145 
146  previousValue = (int)m2PerCapacitor->At(index);
147  m2PerCapacitor->AddAt(x*x+previousValue,index);
148 }
149 
150 void StSvtHybridStat2::reset()
151 {
152  m0 = NULL;
153  m1 = NULL;
154  m2 = NULL;
155 }