78 #include "StTpcRawData.h"
79 #include "Riostream.h"
82 #include "StDaqLib/TPC/trans_table.hh"
83 #include "StDetectorDbMaker/St_tpcPadPlanesC.h"
84 #include "StDetectorDbMaker/St_tpcPadConfigC.h"
86 StTpcDigitalSector::StTpcDigitalSector(
void *db) : mSector(20)
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);
95 mData.push_back(padRow);
100 StTpcDigitalSector::StTpcDigitalSector(
int sector) : mSector(sector)
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);
109 mData.push_back(padRow);
114 void StTpcDigitalSector::clear() {
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();
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();
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();
141 if (numberOfEmptyPads == mData[iRow].size()) {
147 if (numberOfEmptyRows==mData.size())
return 1;
151 Int_t StTpcDigitalSector::getSequences(Int_t row, Int_t pad, Int_t *nSeq,
StSequence** Seq, UShort_t ***Ids) {
153 if (Ids) *Ids=0;*nSeq=0;
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;
163 static UChar_t ADCs[__MaxNumberOfTimeBins__];
164 static UShort_t IDTs[__MaxNumberOfTimeBins__];
165 getTimeAdc(row,pad,ADCs, IDTs);
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]);
175 *nSeq = mSequence.size();
176 *Seq = &mSequence[0];
177 if (Ids) *Ids = &mIds[0];
181 Int_t StTpcDigitalSector::getPadList(Int_t row, UChar_t **padList) {
183 assert( row>=1 && row <=mNoRows);
185 for(Int_t ii = 1; ii <= numberOfPadsAtRow(row); ii++) {
186 if (numberOfTimeBins(row,ii) > 0) {
187 mPadList.push_back(ii);
190 *padList = &mPadList[0];
191 return mPadList.size();
194 Int_t StTpcDigitalSector::putTimeAdc(Int_t row, Int_t pad, Short_t *ADCs, UShort_t *IDTs) {
196 StDigitalTimeBins digPadData;
198 for (Int_t tb = 0; tb < __MaxNumberOfTimeBins__; tb++) {
199 if (! ADCs[tb])
continue;
202 if (IDTs) digPadData.back().add(ADCs[tb],IDTs[tb]);
203 else digPadData.back().add(ADCs[tb]);
206 if (ntimebins) assignTimeBins(row,pad,&digPadData);
210 Int_t StTpcDigitalSector::putTimeAdc(Int_t row, Int_t pad, UChar_t *ADCs, UShort_t *IDTs) {
212 StDigitalTimeBins digPadData;
214 for (Int_t tb = 0; tb < __MaxNumberOfTimeBins__; tb++) {
215 if (! ADCs[tb])
continue;
218 Short_t adc = log8to10_table[ADCs[tb]];
219 if (IDTs) digPadData.back().add(adc,IDTs[tb]);
220 else digPadData.back().add(adc);
223 assignTimeBins(row,pad,&digPadData);
227 Int_t StTpcDigitalSector::getTimeAdc(Int_t row, Int_t pad,
228 Short_t ADCs[__MaxNumberOfTimeBins__],
229 UShort_t IDTs[__MaxNumberOfTimeBins__]) {
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++) {
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];
252 Int_t StTpcDigitalSector::getTimeAdc(Int_t row, Int_t pad,
253 UChar_t ADCs[__MaxNumberOfTimeBins__],
254 UShort_t IDTs[__MaxNumberOfTimeBins__]) {
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++) {
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];
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++) {
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;
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);
310 StDigitalTimeBins tbins2 = *v.timeBinsOfRowAndPad(row,pad);
311 assignTimeBins(row,pad,&tbins2);
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];
320 putTimeAdc(row, pad, ADCs1, IDTs1);
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);
341 void StTpcDigitalSector::Print(
const Option_t *opt)
const {
343 for (Int_t row = 1; row <= mNoRows; row++) {
345 Int_t npads = numberOfPadsInRow(row);
346 for (Int_t pad = 1; pad <= npads; pad++) {
348 Int_t ntb = numberOfTimeBins(row,pad);
350 cout <<
"sector/row/pad = " << mSector <<
"/" << row <<
"/" << pad <<
" = " << ntb <<
" time sequences" << endl;
351 if (Opt.Contains(
"all",TString::kIgnoreCase)) PrintTimeAdc(row,pad);
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;
364 void StTpcRawData::Clear(
const Option_t*) {
365 for (UInt_t ii=0; ii<mSectors.size(); ii++) {SafeDelete(mSectors[ii]);}
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) {
372 static Short_t ADCs[__MaxNumberOfTimeBins__];
373 static UShort_t IDTs[__MaxNumberOfTimeBins__];
374 Int_t npads = s->numberOfPadsInRow(row);
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);
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));
392 return pixels.size();
395 void StTpcRawData::Print(
const Option_t *opt)
const {
397 for (Int_t i = 0; i < N; i++) {
399 if (sector) sector->Print(opt);
404 for (Int_t sec = 1; sec <= 24; sec++) {