StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTpcRawData.cxx
1 /***************************************************************************
2  *
3  * $Id: StTpcRawData.cxx,v 2.18 2018/04/10 11:32:08 smirnovd Exp $
4  *
5  * Author: Yuri Fisyak, Mar 2008
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StTpcRawData.cxx,v $
13  * Revision 2.18 2018/04/10 11:32:08 smirnovd
14  * Minor corrections across multiple files
15  *
16  * - Remove ClassImp macro
17  * - Change white space
18  * - Correct windows newlines to unix
19  * - Remove unused debugging
20  * - Correct StTpcRTSHitMaker header guard
21  * - Remove unused preprocessor directives in StiCA
22  * - Minor changes in status and debug print out
23  * - Remove using std namespace from StiKalmanTrackFinder
24  * - Remove includes for unused headers
25  *
26  * Revision 2.17 2018/04/07 03:32:06 smirnovd
27  * Set default sector id to 20
28  *
29  * Is should not matter which sector to use for past data but 20 is the one with
30  * iTPC in 2018
31  *
32  * Revision 2.16 2018/04/05 03:16:20 smirnovd
33  * Make StTpcDigitalSector compatible with iTPC
34  *
35  * Revision 2.15 2018/02/18 23:04:49 perev
36  * Put back iTPC update
37  *
38  * Revision 2.13 2012/10/23 20:15:57 fisyak
39  * Don't add empty ADC
40  *
41  * Revision 2.12 2012/05/16 21:35:03 fisyak
42  * replace StDigitalPair by its reference
43  *
44  * Revision 2.11 2012/05/07 14:41:59 fisyak
45  * Remove hardcoded separation between Inner and Outer Sectors
46  *
47  * Revision 2.10 2011/03/31 19:27:47 fisyak
48  * Add more safety for work with pixel data
49  *
50  * Revision 2.9 2009/11/23 22:20:51 ullrich
51  * Minor cleanup performed, fixed compiler warnings.
52  *
53  * Revision 2.8 2009/11/23 16:34:07 fisyak
54  * Cleanup, remove dependence on dst tables, clean up software monitors
55  *
56  * Revision 2.7 2009/10/12 23:52:32 fisyak
57  * Fix relation npad from pad row
58  *
59  * Revision 2.6 2008/07/31 20:47:26 fisyak
60  * Modify operator += and =
61  *
62  * Revision 2.5 2008/06/23 19:16:19 fisyak
63  * fix memset size
64  *
65  * Revision 2.4 2008/06/20 14:56:34 fisyak
66  * Add protection for pad no.
67  *
68  * Revision 2.3 2008/05/27 14:40:03 fisyak
69  * keep pixel raw data as short istead of uchar
70  *
71  * Revision 2.2 2008/04/24 16:06:25 fisyak
72  * Clean up before next move
73  *
74  * Revision 2.1 2008/03/13 16:42:24 ullrich
75  * Initial Revision
76  *
77  **************************************************************************/
78 #include "StTpcRawData.h"
79 #include "Riostream.h"
80 #include <assert.h>
81 #include "TMath.h"
82 #include "StDaqLib/TPC/trans_table.hh"
83 #include "StDetectorDbMaker/St_tpcPadPlanesC.h"
84 #include "StDetectorDbMaker/St_tpcPadConfigC.h"
85 //________________________________________________________________________________
86 StTpcDigitalSector::StTpcDigitalSector(void *db) : mSector(20)
87 {
88  StDigitalTimeBins timeBins;
89  mNoRows = St_tpcPadPlanesC::instance()->padRows();
90  for(Int_t row=1; row <= mNoRows; row++) {
91  StDigitalPadRow padRow;
92  for (Int_t pad = 0; pad < numberOfPadsAtRow(row); pad++) {
93  padRow.push_back( timeBins);
94  }
95  mData.push_back(padRow);
96  }
97 }
98 
99 
100 StTpcDigitalSector::StTpcDigitalSector(int sector) : mSector(sector)
101 {
102  StDigitalTimeBins timeBins;
103  mNoRows = St_tpcPadConfigC::instance()->padRows(sector);
104  for(Int_t row=1; row <= mNoRows; row++) {
105  StDigitalPadRow padRow;
106  for (Int_t pad = 0; pad < numberOfPadsAtRow(row); pad++) {
107  padRow.push_back( timeBins);
108  }
109  mData.push_back(padRow);
110  }
111 }
112 
113 //________________________________________________________________________________
114 void StTpcDigitalSector::clear() {// clears only the time bins
115  for(UInt_t row=0; row<mData.size(); row++) {
116  for(UInt_t ipad=0; ipad<mData[row].size(); ipad++) {
117  mData[row][ipad].clear();
118  }
119  }
120 }
121 //________________________________________________________________________________
122 void StTpcDigitalSector::assignTimeBins(Int_t rowN, Int_t padN, StDigitalTimeBins* tbins) {
123  assert( (rowN >= 1 && rowN <= mNoRows ) ||
124  (padN >= 1 && padN <= numberOfPadsAtRow(rowN)));
125  StDigitalPadRow &Row = mData[(rowN-1)];
126  StDigitalTimeBins &Pad = Row[(padN-1)];
127  if (Pad.size() > 0) Pad.clear();
128  Pad.swap(*tbins);
129 }
130 //________________________________________________________________________________
131 Int_t StTpcDigitalSector::cleanup() {
132  UInt_t numberOfEmptyRows=0;
133  for (UInt_t iRow=0; iRow<mData.size(); iRow++) {
134  UInt_t numberOfEmptyPads=0;
135  for (UInt_t iPad=0; iPad<mData[iRow].size(); iPad++) {
136  if (mData[iRow][iPad].size()<7) {
137  mData[iRow][iPad].clear();
138  numberOfEmptyPads++;
139  }
140  } // Pads are now clean
141  if (numberOfEmptyPads == mData[iRow].size()) {
142  mData[iRow].clear();
143  numberOfEmptyRows++;
144  }
145  } // Rows are now clean
146  //cout << "This sector had " << numberOfEmptyRows << " empty rows." << endl;
147  if (numberOfEmptyRows==mData.size()) return 1;
148  else return 0;
149 }
150 //________________________________________________________________________________
151 Int_t StTpcDigitalSector::getSequences(Int_t row, Int_t pad, Int_t *nSeq, StSequence** Seq, UShort_t ***Ids) {
152  *Seq=0;
153  if (Ids) *Ids=0;*nSeq=0;
154  mSequence.clear();
155  mIds.clear();
156  StDigitalTimeBins* TrsPadData = timeBinsOfRowAndPad(row,pad);
157  if (!TrsPadData) return 1;
158  StDigitalTimeBins &trsPadData = *TrsPadData;
159  Int_t nTimeBins = trsPadData.size();
160  if (!nTimeBins) return 2;
161  // Construct the sequences:
162  StSequence aSequence;
163  static UChar_t ADCs[__MaxNumberOfTimeBins__];
164  static UShort_t IDTs[__MaxNumberOfTimeBins__];
165  getTimeAdc(row,pad,ADCs, IDTs);
166 
167  for (Int_t ibin=0;ibin<nTimeBins;ibin++) {
168  aSequence.length = trsPadData[ibin].size();
169  if (aSequence.length > 31) aSequence.length = 31;
170  aSequence.startTimeBin = trsPadData[ibin].time();
171  aSequence.firstAdc = &ADCs[aSequence.startTimeBin];
172  mSequence.push_back(aSequence);
173  mIds.push_back(&IDTs[aSequence.startTimeBin]);
174  }
175  *nSeq = mSequence.size();
176  *Seq = &mSequence[0];
177  if (Ids) *Ids = &mIds[0];
178  return 0;
179 }
180 //________________________________________________________________________________
181 Int_t StTpcDigitalSector::getPadList(Int_t row, UChar_t **padList) {
182  mPadList.clear();
183  assert( row>=1 && row <=mNoRows);
184  // Loop over all the pads:
185  for(Int_t ii = 1; ii <= numberOfPadsAtRow(row); ii++) {
186  if (numberOfTimeBins(row,ii) > 0) {
187  mPadList.push_back(ii);
188  }
189  }
190  *padList = &mPadList[0];
191  return mPadList.size();
192 }
193 //________________________________________________________________________________
194 Int_t StTpcDigitalSector::putTimeAdc(Int_t row, Int_t pad, Short_t *ADCs, UShort_t *IDTs) {// 10 -> 8 conversion
195  Int_t ntimebins = 0;
196  StDigitalTimeBins digPadData;
197  Int_t tbC = -999;
198  for (Int_t tb = 0; tb < __MaxNumberOfTimeBins__; tb++) {
199  if (! ADCs[tb]) continue;
200  if (tb != tbC+1) digPadData.push_back(StDigitalPair(tb));
201  tbC = tb;
202  if (IDTs) digPadData.back().add(ADCs[tb],IDTs[tb]);
203  else digPadData.back().add(ADCs[tb]);
204  ntimebins++;
205  }
206  if (ntimebins) assignTimeBins(row,pad,&digPadData);
207  return ntimebins;
208 }
209 //________________________________________________________________________________
210 Int_t StTpcDigitalSector::putTimeAdc(Int_t row, Int_t pad, UChar_t *ADCs, UShort_t *IDTs) {// no conversion
211  Int_t ntimebins = 0;
212  StDigitalTimeBins digPadData;
213  Int_t tbC = -999;
214  for (Int_t tb = 0; tb < __MaxNumberOfTimeBins__; tb++) {
215  if (! ADCs[tb]) continue;
216  if (tb != tbC+1) digPadData.push_back(StDigitalPair(tb));
217  tbC = tb;
218  Short_t adc = log8to10_table[ADCs[tb]];
219  if (IDTs) digPadData.back().add(adc,IDTs[tb]);
220  else digPadData.back().add(adc);
221  ntimebins++;
222  }
223  assignTimeBins(row,pad,&digPadData);
224  return ntimebins;
225 }
226 //________________________________________________________________________________
227 Int_t StTpcDigitalSector::getTimeAdc(Int_t row, Int_t pad,
228  Short_t ADCs[__MaxNumberOfTimeBins__],
229  UShort_t IDTs[__MaxNumberOfTimeBins__]) {
230  // no conversion
231  UInt_t nTimeSeqs = 0;
232  memset (ADCs, 0, __MaxNumberOfTimeBins__*sizeof(Short_t));
233  memset (IDTs, 0, __MaxNumberOfTimeBins__*sizeof(UShort_t));
234  StDigitalTimeBins* TrsPadData = timeBinsOfRowAndPad(row,pad);
235  if (! TrsPadData) return nTimeSeqs;
236  StDigitalTimeBins &trsPadData = *TrsPadData;
237  nTimeSeqs = trsPadData.size();
238  if (! nTimeSeqs) return nTimeSeqs;
239  for (UInt_t i = 0; i < nTimeSeqs; i++) {
240  StDigitalPair &digPair = trsPadData[i];
241  UInt_t ntbk = digPair.size();
242  UInt_t tb = digPair.time();
243  UInt_t isIdt= digPair.isIdt();
244  for (UInt_t j = 0; j < ntbk; j++, tb++) {
245  ADCs[tb] = digPair.adc()[j];
246  if (isIdt) IDTs[tb] = digPair.idt()[j];
247  }
248  }
249  return nTimeSeqs;
250 }
251 //________________________________________________________________________________
252 Int_t StTpcDigitalSector::getTimeAdc(Int_t row, Int_t pad,
253  UChar_t ADCs[__MaxNumberOfTimeBins__],
254  UShort_t IDTs[__MaxNumberOfTimeBins__]) {
255  // 10-> 8 conversion
256  // no conversion
257  UInt_t nTimeSeqs = 0;
258  memset (ADCs, 0, __MaxNumberOfTimeBins__*sizeof(UChar_t));
259  memset (IDTs, 0, __MaxNumberOfTimeBins__*sizeof(UShort_t));
260  StDigitalTimeBins* TrsPadData = timeBinsOfRowAndPad(row,pad);
261  if (! TrsPadData) return nTimeSeqs;
262  StDigitalTimeBins &trsPadData = *TrsPadData;
263  nTimeSeqs = trsPadData.size();
264  if (! nTimeSeqs) return nTimeSeqs;
265  for (UInt_t i = 0; i < nTimeSeqs; i++) {
266  StDigitalPair &digPair = trsPadData[i];
267  UInt_t ntbk = digPair.size();
268  UInt_t tb = digPair.time();
269  UInt_t isIdt= digPair.isIdt();
270  for (UInt_t j = 0; j < ntbk; j++, tb++) {
271  if (digPair.adc()[j] <= 0) continue;
272  ADCs[tb] = log10to8_table[digPair.adc()[j]];
273  if (isIdt) IDTs[tb] = digPair.idt()[j];
274  }
275  }
276  return nTimeSeqs;
277  }
278 //________________________________________________________________________________
279 Int_t StTpcDigitalSector::PrintTimeAdc(Int_t row, Int_t pad) const {
280  UInt_t nTimeSeqs = 0;
281  const StDigitalTimeBins* TrsPadData = timeBinsOfRowAndPad(row,pad);
282  if (! TrsPadData) return nTimeSeqs;
283  const StDigitalTimeBins &trsPadData = *TrsPadData;
284  nTimeSeqs = trsPadData.size();
285  if (! nTimeSeqs) return nTimeSeqs;
286  cout << "Time/Adc/IdTruth for row " << row << "\tpad " << pad << endl;
287  for (UInt_t i = 0; i < nTimeSeqs; i++) {
288  StDigitalPair digPair = trsPadData[i];
289  UInt_t ntbk = digPair.size();
290  UInt_t tb = digPair.time();
291  for (UInt_t j = 0; j < ntbk; j++, tb++) {
292  if (digPair.adc()[j] <= 0) continue;
293  cout << "\t" << tb << "\t" << digPair.adc()[j] << "\t" << digPair.idt()[j] << endl;
294  }
295  }
296  return nTimeSeqs;
297  }
298 //________________________________________________________________________________
299 StTpcDigitalSector &StTpcDigitalSector::operator+= (StTpcDigitalSector& v) {
300  static Short_t ADCs1[__MaxNumberOfTimeBins__], ADCs2[__MaxNumberOfTimeBins__];
301  static UShort_t IDTs1[__MaxNumberOfTimeBins__], IDTs2[__MaxNumberOfTimeBins__];
302  for (Int_t row = 1; row <= mNoRows; row++) {
303  Int_t npad2 = v.numberOfPadsInRow(row);
304  if (! npad2) continue;
305  for (Int_t pad = 1; pad <= numberOfPadsAtRow(row); pad++) {
306  Int_t ntb2 = v.numberOfTimeBins(row,pad);
307  if (! ntb2) continue;
308  Int_t ntb1 = numberOfTimeBins(row,pad);
309  if (! ntb1) {
310  StDigitalTimeBins tbins2 = *v.timeBinsOfRowAndPad(row,pad);
311  assignTimeBins(row,pad,&tbins2);
312  continue;
313  }
314  getTimeAdc(row,pad,ADCs1,IDTs1);
315  v.getTimeAdc(row,pad,ADCs2,IDTs2);
316  for (Int_t i = 0; i < __MaxNumberOfTimeBins__; i++) {
317  if ((IDTs1[i] || IDTs2[i]) && ADCs1[i] < ADCs2[i]) IDTs1[i] = IDTs2[i];
318  ADCs1[i] += ADCs2[i];
319  }
320  putTimeAdc(row, pad, ADCs1, IDTs1);
321  }
322  }
323  return *this;
324 }
325 //________________________________________________________________________________
326 StTpcDigitalSector &StTpcDigitalSector::operator= (const StTpcDigitalSector& v) {
327  for (Int_t row = 1; row <= mNoRows; row++) {
328  Int_t npad2 = v.numberOfPadsInRow(row);
329  if (! npad2) continue;
330  for (Int_t pad = 1; pad <= numberOfPadsAtRow(row); pad++) {
331  Int_t ntb2 = v.numberOfTimeBins(row,pad);
332  if (! ntb2) continue;
333  StDigitalTimeBins tbins2 = *v.timeBinsOfRowAndPad(row,pad);
334  assignTimeBins(row,pad,&tbins2);
335  continue;
336  }
337  }
338  return *this;
339 }
340 //________________________________________________________________________________
341 void StTpcDigitalSector::Print(const Option_t *opt) const {
342  TString Opt(opt);
343  for (Int_t row = 1; row <= mNoRows; row++) {
344  // cout << "sector/row " << mSector << "/" << row << endl;
345  Int_t npads = numberOfPadsInRow(row);
346  for (Int_t pad = 1; pad <= npads; pad++) {
347  // cout << "sector/row/pad = " << mSector << "/" << row << "/" << pad << endl;
348  Int_t ntb = numberOfTimeBins(row,pad);
349  if (! ntb) continue;
350  cout << "sector/row/pad = " << mSector << "/" << row << "/" << pad << " = " << ntb << " time sequences" << endl;
351  if (Opt.Contains("all",TString::kIgnoreCase)) PrintTimeAdc(row,pad);
352  }
353  }
354 }
355 //________________________________________________________________________________
356 void StTpcRawData::setSector(UInt_t sector, StTpcDigitalSector* digitSector) {
357  if (sector > 0 && sector <= mSectors.size()) {
358  if (mSectors[sector-1]) delete mSectors[sector-1];
359  digitSector->setSector(sector);
360  mSectors[sector-1] = digitSector;
361  }
362 }
363 //________________________________________________________________________________
364 void StTpcRawData::Clear(const Option_t*) {
365  for (UInt_t ii=0; ii<mSectors.size(); ii++) {SafeDelete(mSectors[ii]);}
366 }
367 //________________________________________________________________________________
368 Int_t StTpcRawData::getVecOfPixels(StVectPixel &pixels, Int_t sector, Int_t row, Int_t padMin, Int_t padMax, Int_t tMin, Int_t tMax) {
369  pixels.clear();
370  StTpcDigitalSector *s = GetSector(sector);
371  if (s) {
372  static Short_t ADCs[__MaxNumberOfTimeBins__];
373  static UShort_t IDTs[__MaxNumberOfTimeBins__];
374  Int_t npads = s->numberOfPadsInRow(row);
375  if (npads) {
376  if (padMin < 1) padMin = 1;
377  if (padMax < padMin) padMax = s->numberOfPadsAtRow(row);
378  if (tMin < 0) tMin = 0;
379  if (tMax < tMin) tMax = __MaxNumberOfTimeBins__ - 1;
380  tMax = TMath::Min(tMax, __MaxNumberOfTimeBins__ - 1);
381  for (Int_t pad = padMin; pad <= padMax; pad++) {
382  Int_t ntbs = s->numberOfTimeBins(row,pad);
383  if (ntbs) {
384  s->getTimeAdc(row,pad,ADCs,IDTs);
385  for (Int_t tb = tMin; tb <= tMax; tb++) {
386  if (ADCs[tb]) pixels.push_back(StTpcPixel(kTpcId,sector,row,pad,tb,ADCs[tb],IDTs[tb],0));
387  }
388  }
389  }
390  }
391  }
392  return pixels.size();
393 }
394 //________________________________________________________________________________
395 void StTpcRawData::Print(const Option_t *opt) const {
396  Int_t N = ((StTpcRawData *) this)->size();
397  for (Int_t i = 0; i < N; i++) {
398  StTpcDigitalSector *sector = ((StTpcDigitalSector* )mSectors[i]);
399  if (sector) sector->Print(opt);
400  }
401 }
402 //________________________________________________________________________________
403 StTpcRawData &StTpcRawData::operator+= (StTpcRawData& v) {
404  for (Int_t sec = 1; sec <= 24; sec++) {
405  StTpcDigitalSector *a = getSector(sec);
406  StTpcDigitalSector *b = v.getSector(sec);
407  if (!b ) continue;
408  if (!a) {
409  a = new StTpcDigitalSector();
410  *a = *b;
411  setSector(sec, a);
412  continue;
413  }
414  *a += *b;
415  }
416  return *this;
417 }