StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSvtHybridPixelsC.cc
1  /***************************************************************************
2  *
3  * $Id: StSvtHybridPixelsC.cc,v 1.3 2003/09/02 17:59:06 perev Exp $
4  *
5  * Author: Marcelo Munhoz
6  ***************************************************************************
7  *
8  * Description: SVT Hybrid PixelsC class
9  *
10  ***************************************************************************
11  *
12  * $Log: StSvtHybridPixelsC.cc,v $
13  * Revision 1.3 2003/09/02 17:59:06 perev
14  * gcc 3.2 updates + WarnOff
15  *
16  * Revision 1.2 2002/02/12 23:09:50 munhoz
17  * fixing problems for new compiler
18  *
19  * Revision 1.1 2001/08/16 21:02:04 munhoz
20  * changing StObjArray to StStrArray. StSvtConfig reestructured. New classes for geometry DB
21  *
22  * Revision 1.3 2000/11/30 20:39:12 caines
23  * Changed to allow us of database
24  *
25  * Revision 1.1.1.1 2000/03/10 14:26:21 munhoz
26  * SVT Class Library
27  *
28  **************************************************************************/
30 // //
31 // It is an array of 240 X 128 floats. //
32 // It can be used to store any pixel data from one hybrid. //
33 // For instance, the pedestals can be defined as a StSvtHybridPixelsC. //
34 // //
36 
37 #include <Stiostream.h>
38 #include "StSvtHybridPixelsC.hh"
39 
40 ClassImp(StSvtHybridPixelsC)
41 
43  StSvtHybridObject(), TArrayC()
44 {
45  // Default Constructor
46 
47  mNumberOfAnodes = 0;
48  mNumberOfTimeBins = 0;
49 
50  mTotalNumberOfPixels = 0;
51 
52  mPedOffset = 0;
53 }
54 
55 StSvtHybridPixelsC::StSvtHybridPixelsC(int barrel, int ladder, int wafer, int hybrid, int size, unsigned char* x) :
56  StSvtHybridObject(barrel, ladder, wafer, hybrid), TArrayC()
57 {
58  // The same as StSvtHybridObject.
59 
60  mNumberOfAnodes = 240;
61  mNumberOfTimeBins = 128;
62 
63  mTotalNumberOfPixels = mNumberOfAnodes*mNumberOfTimeBins;
64 
65  mPedOffset = 0;
66 
67  if (size)
68  if (x)
69  Set(mTotalNumberOfPixels,(char*)x);
70  else
71  Set(size);
72  else
73  Set(mTotalNumberOfPixels);
74 }
75 
76 StSvtHybridPixelsC::~StSvtHybridPixelsC()
77 {}
78 
79 StSvtHybridPixelsC& StSvtHybridPixelsC::operator = (StSvtHybridPixelsC& h)
80 {
81  float x;
82 
83  for (int i=0;i<mTotalNumberOfPixels;i++) {
84  x = h.At(i);
85  AddAt((char)x,i);
86  }
87  return *this;
88 }
89 
90 StSvtHybridPixelsC& StSvtHybridPixelsC::operator + (StSvtHybridPixelsC& h)
91 {
92  float x1, x2;
93 
94  for (int i=0;i<mTotalNumberOfPixels;i++) {
95  x1 = (float)At(i);
96  x2 = (float)h.At(i);
97 
98  if ((x1+x2) < 255)
99  AddAt((char)(x1+x2),i);
100  else
101  AddAt(255,i);
102  }
103  return *this;
104 }
105 
106 unsigned char StSvtHybridPixelsC::getPixelContent(int anode, int time)
107 {
108  // Returns the pixel content based on the anode and time bin numbers
109  int index = getPixelIndex(anode, time);
110 
111  return (unsigned char)At(index);
112 }
113 
114 void StSvtHybridPixelsC::addToPixel(int anode, int time, unsigned char x)
115 {
116  int index = getPixelIndex(anode, time);
117  addToPixel(index, x);
118 }
119 
120 void StSvtHybridPixelsC::addToPixel(int index, unsigned char x)
121 {
122  int x1, sum;
123 
124  x1 = (int)At(index);
125 
126  sum = x1 + (int)x;
127 
128  if (sum < 255)
129  AddAt((unsigned char)sum,index);
130  else
131  AddAt((unsigned char)255,index);
132 }
133 
134 void StSvtHybridPixelsC::addToPixel(int anode, int time, int x)
135 {
136  int index = getPixelIndex(anode, time);
137  addToPixel(index, x);
138 }
139 
140 void StSvtHybridPixelsC::addToPixel(int index, int x)
141 {
142  int x1, sum;
143 
144  x1 = (int)At(index);
145 
146  sum = x1 + x;
147 
148  if (sum >=0 && sum < 255)
149  AddAt((unsigned char)sum,index);
150  else if (sum < 0)
151  AddAt((unsigned char)0,index);
152  else if (sum > 255)
153  AddAt((unsigned char)255,index);
154 }
155 
156 void StSvtHybridPixelsC::addToPixel(int anode, int time, double x)
157 {
158  int index = getPixelIndex(anode, time);
159  addToPixel(index, x);
160 }
161 
162 void StSvtHybridPixelsC::addToPixel(int index, double x)
163 {
164  double x1, sum;
165 
166  x1 = (double)At(index);
167 
168  sum = x1 + x;
169 
170  if (sum >=0 && sum < 255)
171  AddAt((unsigned char)sum,index);
172  else if (sum < 0)
173  AddAt((unsigned char)0,index);
174  else if (sum > 255)
175  AddAt((unsigned char)255,index);
176 }
177 
178 int StSvtHybridPixelsC::getPixelIndex(int anode, int time)
179 {
180  // Returns an internal index for pixel (anode,time).
181  // It should be used to store or retrieve a pixel value from this object.
182 
183  int index;
184 
185  index = mNumberOfTimeBins*(anode-1) + time;
186 
187  return index;
188 }
189 
190 void StSvtHybridPixelsC::reset()
191 {
192  for (int i=0;i<mTotalNumberOfPixels;i++)
193  AddAt(0,i);
194 }