StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSstDaqMaker.cxx
1 
6 /***************************************************************************
7  *
8  * $Id: StSstDaqMaker.cxx,v 1.16 2017/11/09 16:23:57 smirnovd Exp $
9  *
10  * Author: Long Zhou, Nov 2013
11  ***************************************************************************
12  *
13  * Description:
14  * Read ssd strip info from daq format.
15  *
16  *
17  ***************************************************************************
18  *
19  * $Log: StSstDaqMaker.cxx,v $
20  * Revision 1.16 2017/11/09 16:23:57 smirnovd
21  * StSstDaqMaker: Corrected path to included header file
22  *
23  * Revision 1.15 2017/04/26 14:56:42 perev
24  * Remove GetData() commited by accidant
25  *
26  * Revision 1.13 2016/07/01 18:30:52 bouchet
27  * COVERITY : STACK_USE, UNINIT_CTOR fixed
28  *
29  * Revision 1.12 2016/06/23 20:23:34 bouchet
30  * sstBadStrips table decoding and use ; COVERITY : DIVIDE_BY_ZERO, NO_EFFECT fixed
31  *
32  * Revision 1.11 2016/05/25 15:47:38 smirnovd
33  * StSstDaqMaker: Removed commented-out code destined to rot
34  *
35  * Revision 1.10 2016/05/25 15:47:30 smirnovd
36  * StSstDaqMaker: Initializing variable once is enough
37  *
38  * Revision 1.9 2016/05/25 15:47:23 smirnovd
39  * StSstDaqMaker: Got rid of unused local variable
40  *
41  * Revision 1.8 2016/05/25 15:47:15 smirnovd
42  * StSstDaqMaker: Refactored how output file name is formed
43  *
44  * Memory leak fixed. Note different width for time field for values less < 999
45  *
46  * Revision 1.7 2016/02/03 15:50:20 zhoulong
47  * Added some protection to avoid chain crash when there is no available calibration table
48  *
49  * Revision 1.6 2015/12/14 14:33:42 zhoulong
50  * fixed CMN failed chip rejection error
51  *
52  * Revision 1.5 2015/11/05 21:56:44 zhoulong
53  * Add pedestal subtraction and CMN suppression algorithm and did some clearence
54  *
55  * Revision 1.4 2015/07/06 18:38:19 bouchet
56  * initialization of variables and pointers (Thanks Yuri)
57  *
58  * Revision 1.3 2015/06/24 20:58:11 bouchet
59  * added codes for using sstChipCorrect and sstMaskChip tables ; replaced StSsdConfig by StSstConfig
60  *
61  * Revision 1.2 2015/06/24 20:37:59 smirnovd
62  * Use explicit comparison in order to disable compiler warning
63  *
64  * Revision 1.1 2015/06/09 18:32:00 jeromel
65  * Clean check-in vrsion of long time ago reviewed SST daq code
66  *
67  * Revision 1.11 2015/02/02 22:58:31 zhoulong
68  * Corrected the default ordering issue
69  *
70  * Revision 1.10 2015/01/10 20:18:18 zhoulong
71  * 1>remove constant shift. 2>fixed delete pedestal table issue
72  *
73  * Revision 1.9 2015/01/05 22:07:31 smirnovd
74  * StSstDaqMaker: Use STAR framework return codes
75  *
76  * In this case we better return an error code
77  *
78  * Revision 1.8 2015/01/05 22:07:23 smirnovd
79  * StSstDaqMaker: Removed quite pointless overriding methods
80  *
81  * Revision 1.7 2015/01/05 21:58:48 smirnovd
82  * StSstDaqMaker/: Updated style with astyle -s3 -p -H -A3 -k3 -O -o -y -Y -f
83  *
84  * Revision 1.6 2014/11/10 14:46:37 zhoulong
85  * Fixed delete spa_strip table issue
86  *
87  * Revision 1.5 2014/09/30 18:00:10 zhoulong
88  * Fixed alot of issue, and remove histograms, ntuple.
89  *
90  * Revision 1.4 2014/06/05 14:55:23 zhoulong
91  * Added some code to compatible Thorsten's LC FPGA and correct readout channel shift in old LC FPGA
92  *
93  *
94  ***************************************************************************
95  * StSstDaqMaker.cxx v 1.1
96  * Revision 1.1 2014/1/23 11:18:00 Long Zhou
97  * <1>Change Sector to Rdo
98  * <2>change the main structure(depend on test DAQ data sample.)
99  *
100  * StsstDaqMaker.cxx,v 1.0
101  * Revision 1.0 2014/1/21 10:46:00 Long Zhou
102  * Initial version
103  ****************************************************************************/
104 #include "StSstDaqMaker.h"
105 #include "St_base/StMessMgr.h"
106 #include "RTS/src/DAQ_SST/daq_sst.h"
107 #include "RTS/src/DAQ_READER/daq_dta.h"
108 #include "RTS/src/DAQ_READER/daqReader.h"
109 #include "StEventTypes.h"
110 #include "StMessMgr.h"
111 #include "StRtsTable.h"
112 #include "StSsdDbMaker/StSsdDbMaker.h"
113 #include "StSsdDbMaker/StSstDbMaker.h"
114 #include "tables/St_spa_strip_Table.h"
115 #include "tables/St_sstConfiguration_Table.h"
116 #include "tables/St_sstStripCalib_Table.h"
117 #include "StSstUtil/StSstConfig.hh"
118 #include "StIOMaker/StIOMaker.h"
119 #include "tables/St_sstChipCorrect_Table.h"
120 #include "tables/St_sstNoise_Table.h"
121 #include "tables/St_sstBadStrips_Table.h"
122 #include <map>
123 #include <vector>
124 using std::vector;
125 ClassImp(StSstDaqMaker)
126 
127 //-----------------------------------------------
128 //Ladder cards number in each RDO channel.
129 const Int_t StSstDaqMaker::RDO2LADDER[5][8] = { {1, 2, 3, 4, 5, 6, 7, 8},
130  {9, 10, 11, 12, 13, 14, 15, 16},
131  {17, 18, 19, 20, 1, 2, 3, 4},
132  {5, 6, 7, 8, 9, 10, 11, 12},
133  {13, 14, 15, 16, 17, 18, 19, 20}
134 };
135 
136 //silicon strip number ordered by ALICE128 readout order
137 const Int_t StSstDaqMaker::ReadOutMap[128] = {
138  97, 96, 98, 95, 99, 94, 100, 93,
139  101, 92, 102, 91, 103, 90, 104, 89,
140  105, 88, 106, 87, 107, 86, 108, 85,
141  109, 84, 110, 83, 111, 82, 112, 81,
142  113, 80, 114, 79, 115, 78, 116, 77,
143  117, 76, 118, 75, 119, 74, 120, 73,
144  121, 72, 122, 71, 123, 70, 124, 69,
145  125, 68, 126, 67, 127, 66, 128, 65,
146  1, 64, 2, 63, 3, 62, 4, 61,
147  5, 60, 6, 59, 7, 58, 8, 57,
148  9, 56, 10, 55, 11, 54, 12, 53,
149  13, 52, 14, 51, 15, 50, 16, 49,
150  17, 48, 18, 47, 19, 46, 20, 45,
151  21, 44, 22, 43, 23, 42, 24, 41,
152  25, 40, 26, 39, 27, 38, 28, 37,
153  29, 36, 30, 35, 31, 34, 32, 33
154 };
155 //-------------------------------------------------
156 //table of ALICE128 readout order ordered by silicon strip number
157 const Int_t StSstDaqMaker::Rev_ReadOutMap[128] = {
158  65, 67, 69, 71, 73, 75, 77, 79,
159  81, 83, 85, 87, 89, 91, 93, 95,
160  97, 99, 101, 103, 105, 107, 109, 111,
161  113, 115, 117, 119, 121, 123, 125, 127,
162  128, 126, 124, 122, 120, 118, 116, 114,
163  112, 110, 108, 106, 104, 102, 100, 98,
164  96, 94, 92, 90, 88, 86, 84, 82,
165  80, 78, 76, 74, 72, 70, 68, 66,
166  64, 62, 60, 58, 56, 54, 52, 50,
167  48, 46, 44, 42, 40, 38, 36, 34,
168  32, 30, 28, 26, 24, 22, 20, 18,
169  16, 14, 12, 10, 8, 6, 4, 2,
170  1, 3, 5, 7, 9, 11, 13, 15,
171  17, 19, 21, 23, 25, 27, 29, 31,
172  33, 35, 37, 39, 41, 43, 45, 47,
173  49, 51, 53, 55, 57, 59, 61, 63
174 };
175 //-----------------------------------------------
176 StSstDaqMaker::StSstDaqMaker(const Char_t *name)
177  : StRTSBaseMaker("sst", name),mMode(1)
178 {
179  mConfig=0;
180  mConfigTable=0;
181  spa_strip=0;
182  stripCal=0;
183  mRdoData=0;
184  mRdoDataLength=0;
185  mHeaderData=0;
186  mTrailerData=0;
187  mTrailerDataLength=0;
188  mMode=0;
189  mRdoFlag=0;
190  mTrigger=0;
191  mSec=0;
192  mFiber=0;
193  mPed=0;
194  mRms=0;
195  mRDO=0;
196  mEventnumber=0;
197  mEventrunumber=0;
198  mEventTime=0;
199  mPEventTime=0;
200  mRunNum=0;
201  for(int i=0;i<8;i++){
202  mAdc[i] = 0;
203  mAdcHeader[i] = 0;
204  mAdcLength[i] = 0;
205  mFiberFlag[i] = 0;
206  mFlag[i] = 0;
207  mChannel[i] = 0;
208  mDataMode[i] = 0;
209  }
210 }
211 //-----------------------------------------------
212 StSstDaqMaker::~StSstDaqMaker()
213 {
214 }
215 //-----------------------------------------------
216 Int_t StSstDaqMaker::InitRun(Int_t runumber)
217 {
218  mEventrunumber = runumber;
219 
220  LOG_INFO << "InitRun(Int_t runumber) - Read now Databases" << endm;
221  mRunNum = (runumber / 1000000) - 1;
222  stripCal = new St_sstStripCalib("sstStripCalib",1);
223 
224  if (mRunNum >= 14) { // For Run14,15,16 Raw Data Mode
225  St_sstStripCalib *mStripCalib = (St_sstStripCalib*)GetDataBase("Calibrations/sst/sstStripCalib");
226  if (mStripCalib) {
227  LOG_INFO << "sst readout pedestal table found ... initialize" << endm;
228  FillReadOutPedTable(mStripCalib->GetTable());}
229  else {
230  LOG_WARN << "InitRun : No access to sstStripCalib table - we will use the default pedestal values( ped = 0)." << endm;
231  FillDefaultReadOutPedTable();
232  }
233 
234  St_sstNoise *mNoise = (St_sstNoise*)GetDataBase("Calibrations/sst/sstNoise");
235  if (mNoise) {
236  LOG_INFO << "sst noise table found ... initialize" << endm;
237  FillNoiseTable(mNoise->GetTable());}
238  else {
239  LOG_WARN << "InitRun : No access to ssdNoise - will use the default noise(rms in all channel will be 0 adc )" << endm;
240  FillDefaultNoiseTable();
241  }
242  }
243  else { // we will not save any data when use default tabls
244  LOG_WARN << "InitRun : Unsupported data - we will not save any information )" << endm;
245  FillDefaultReadOutPedTable();
246  FillDefaultNoiseTable();
247  }
248 
249  if (mRunNum >= 14 && mRunNum <= 15) { // Only for Run14 , 15 ZS data mode
250  St_sstChipCorrect *mChipCorrect = (St_sstChipCorrect*)GetDataBase("Calibrations/sst/sstChipCorrect");
251  if (mChipCorrect) {
252  LOG_INFO << "sst mask chips table found ... initialize" << endm;
253  FillChipNoiseTable(mChipCorrect->GetTable());}
254  else {
255  LOG_WARN << " no sst masking chips table " << endm;
256  FillDefaultChipNoiseTable();
257  }
258  }
259  else {
260  // For Run16, we will not use this table. defaults value will not touch the real data.
261  LOG_WARN << "InitRun : We will not use ChipCorrection Table any more )" << endm;
262  FillDefaultChipNoiseTable();
263  }
264 
265  if (mRunNum >= 16) { // Only for Run16
266  LOG_DEBUG << " searching for a bad Strip table" << endm;
267  St_sstBadStrips *mBadStrip = (St_sstBadStrips*)GetDataBase("Calibrations/sst/sstBadStrips");
268  if (mBadStrip) {
269  LOG_DEBUG << "sst bad strips table found ... initialize" << endm;
270  FillBadStripsTable(mBadStrip->GetTable());
271  }
272  }
273 
274  St_sstConfiguration *configTable = (St_sstConfiguration *) GetInputDB("Geometry/sst/sstConfiguration");
275 
276  if (!configTable) {
277  LOG_ERROR << "InitRun: No relevant entry found in 'Geometry/sst/sstConfiguration' table" << endm;
278  return kStFatal;
279  }
280 
281  mConfigTable = (sstConfiguration_st *) configTable->GetTable() ;
282  mConfig = new StSstConfig();
283 
284  Int_t totLadderPresent = 0;
285 
286  for (Int_t ladder = 1; ladder <= mConfigTable->nMaxLadders; ladder++) {
287  if (mConfigTable->ladderIsPresent[ladder - 1] != 0)
288  totLadderPresent++;
289 
290  mConfig->setLadderIsActive(ladder, mConfigTable->ladderIsPresent[ladder - 1]);
291  }
292 
293  PrintConfiguration(mRunNum, mConfigTable);
294  mConfig->setNumberOfLadders(totLadderPresent);
295  mConfig->setNumberOfWafers(mConfigTable->nMaxWafers / mConfigTable->nMaxLadders);
296  mConfig->setNumberOfHybrids(2);
297  mConfig->setTotalNumberOfHybrids(nSstSide * nSstWaferPerLadder * totLadderPresent);
298  mConfig->setTotalNumberOfLadders(mConfigTable->nMaxLadders);
299  mConfig->setNumberOfStrips(nSstStripsPerWafer);
300  mConfig->setConfiguration();
301  mEventnumber = 0;
302 
303  LOG_INFO << "_____________________________" << endm;
304  LOG_INFO << " Via Datababase......." << endm;
305  LOG_INFO << ".......numberOfSectors = " << mConfigTable->nMaxSectors << endm;
306  LOG_INFO << ".......numberOfLadders = " << totLadderPresent << endm;
307  LOG_INFO << " .numberOfWafersPerLadder = " << mConfigTable->nMaxWafers / mConfigTable->nMaxLadders << endm;
308  LOG_INFO << "_____________________________" << endm;
309  LOG_INFO << " InitRun() - Done " << endm;
310  LOG_INFO << "StSstDaqMaker initialization." << endm;
311  return kStOK;
312 }
313 
314 
315 //-------------------------------------------------
317 {
318  LOG_INFO << "StSstDaqMaker Start Make..." << endm;
319  StRtsTable *rts_table = 0;
320  mEventnumber++;
321 
322  //raw data mode
323  while ( (rts_table = GetNextDaqElement("sst/raw")) != 0 ) {
324  //each DAQ element record one RDO data
325  //one event will loop all the 5 RDOs
326  mMode = 0;//0-physic run,1-pedestal run
327  mRdoData = (UInt_t *)rts_table->At(0);
328  mRdoDataLength = rts_table->GetNRows();
329  LOG_INFO << "Found sst Physics Run data at " << hex << mRdoData << dec << " , length in byte: "
330  << mRdoDataLength << " in UInt_t: " << mRdoDataLength / sizeof(UInt_t) << endm;
331  DecodeRdoData();
332  DecodeHitsData();
333  }
334 
335  //pedestal mode
336  sstStripCalib_st *noise_strip = new sstStripCalib_st();
337  memset(noise_strip,0,491520*(sizeof(Short_t) + sizeof(Char_t)));
338  while ( (rts_table = GetNextDaqElement("sst/pedrms")) != 0 ) {
339  mMode = 1;
340  mRdoData = (UInt_t *)rts_table->At(0);
341  mRdoDataLength = rts_table->GetNRows();
342  LOG_INFO << "Found sst Pedestal Run data at " << hex << mRdoData
343  << dec << " , length in byte: " << mRdoDataLength << endm;
344  Int_t flag = 0;
345  Int_t id_side, ladder;
346  Int_t ladderCountN[20] = {0};
347  Int_t ladderCountP[20] = {0};
348  Int_t c_correct;
349  Int_t channelindex = 0;
350  mSec = rts_table->Sector();
351  mRDO = rts_table->Rdo();
352  mFiber = rts_table->Pad();
353 
354  if (mSec != 1) mRDO = mRDO + 3;//sector 2
355 
356  if (mRDO < 1 || mRDO > 5) flag = 1;
357 
358  if (mSec < 1 || mSec > 3) flag = 1;
359 
360  if (mFiber < 0 || mFiber > 7) flag = 1;
361 
362  if (flag == 1) {
363  LOG_WARN << "BAD pedestal data. Sector: " << mSec << " RDO: "
364  << mRDO << " fiber: " << mFiber << endm;
365  continue;
366  }
367 
368  FindLadderSide(mRDO, mFiber, ladder, id_side);
369  for (StRtsTable::iterator it = rts_table->begin(); it != rts_table->end(); ++it) {
371 
372  for (Int_t c = 0; c < nSstStripsPerWafer; c++) {
373  //channel
374  c_correct = (Int_t)c;
375 
376  if (!Shift(mEventrunumber, c_correct)) {
377  LOG_INFO << "First readout channel in old LC FPGA is not usable." << endm;
378  continue;
379  }
380 
381  for (Int_t h = 0; h < nSstWaferPerLadder; h++) {
382  //wafer
383  Int_t s = c_correct;
384  FindStripNumber(s);
385  mPed = (short)(f->ped[h][c_correct] - 375); // Pedestal from data have a constant shift (375)
386  mRms = (short)(f->rms[h][c_correct]); // rms = 16 * raw_rms --> Save as hight precision.
387  channelindex = id_side*nSstLadder*nSstWaferPerLadder*nSstStripsPerWafer
388  + ladder*nSstWaferPerLadder*nSstStripsPerWafer
389  + h*nSstStripsPerWafer
390  + c_correct; // + s;
391  noise_strip->rms[channelindex] = mRms;
392  noise_strip->pedestals[channelindex] = mPed;
393  // cout<<"--->Channel is : "<<channelindex<<endl;
394  if (id_side == 0) ladderCountP[ladder]++;
395  else ladderCountN[ladder]++;
396  }
397  }
398  }
399 
400  if (StMaker::GetDebug()) {
401  LOG_DEBUG << "Make()/Counts (p-side): ";
402 
403  for (Int_t i = 0; i < nSstLadder; i++) {
404  LOG_DEBUG.width(5);
405  LOG_DEBUG << ladderCountP[i] << " ";
406  }
407 
408  LOG_DEBUG << endm;
409  LOG_DEBUG << "Make()/Counts (n-side): ";
410 
411  for (Int_t i = 0; i < nSstLadder; i++) {
412  LOG_DEBUG.width(5);
413  LOG_DEBUG << ladderCountN[i] << " ";
414  }
415 
416  LOG_DEBUG << endm;
417 
418  }
419  }
420 
421  if (stripCal && stripCal->GetNRows() != 0) {
422  LOG_DEBUG << "Make()/ Read Pedestal & Noise" << endm;
423  LOG_DEBUG << "Make()/stripCal->NRows= " << stripCal->GetNRows() << endm;
424  }
425 
426  // Directly write sstStripCalib table in strip ordering.
427  if(mMode == 1) {
428  char name[50];
429  sprintf(name, "sstStripCalib.%d.%06d.root", GetDate(), GetTime());
430 
431  TFile f1(name,"RECREATE","SSD ped and noise file",9);
432  stripCal->AddAt(noise_strip);
433  stripCal->Print();
434  stripCal->Write();
435  f1.Close();
436  }
437 
438  delete noise_strip;
439  return kStOk;
440 }
441 //-------------------------------------------------
442 void StSstDaqMaker::DecodeRdoData()
443 {
444  Int_t index = 0;
445  mRDO = 0;
446  mTrigger = 0;
447  mHeaderData = 0;
448  mTrailerData = 0;
449  mTrailerDataLength = 0;
450  mRdoFlag = 1;
451  mEventTime = 0;
452  mPEventTime = 0;
453 
454  for (Int_t f = 0; f < 8; f++) mFiberFlag[f] = 1; //flag=0-->bad, flag=1-->good
455 
456  if (mRdoDataLength == 0 || !mRdoData) {
457  LOG_WARN << "NO RDO OUTPUT DATA!" << endm;
458  mRdoFlag = 0;
459  return;
460  }
461 
462  if (mRdoData[0] != HEADER_TOKEN) {
463  LOG_WARN << "SST DAQ DATA HEADER_TOKEN is not correct!!" << endm;
464  mRdoFlag = 0;
465  return;
466  }
467  else {
468  LOG_DEBUG << "SST DAQ DATA HEADER_TOKEN correct: 0x" << hex << mRdoData[0] << dec << endm;
469  }
470 
471  mEventTime = mRdoData[2];
472  mPEventTime = mRdoData[4];
473 
474  mHeaderData = mRdoData + index;
475 
476  if (StMaker::GetDebug()) {
477  for (UInt_t h = 0; h < HEADER_LENGTH; h++) {
478  if (h == 0) LOG_DEBUG << "Start Print Event HEADER info... " << endm;
479 
480  LOG_DEBUG << "0x" << hex << mHeaderData[h] << dec << endm;
481  }
482  }
483 
484  mTrigger = Mid(TRIG_START, TRIG_END, mRdoData[1]);
485  LOG_DEBUG << "Current Event Trigger words is " << mTrigger << endm;
486  mRDO = Mid(RDO_START, RDO_END, mRdoData[3]);
487 
488  if (mRDO == 6) mRDO = 1; //20140311,luis chenged this serial number
489 
490  LOG_DEBUG << "Current RDO number is :" << mRDO << endm;
491 
492  if (mRDO < 1 || mRDO > nSstRdo) {
493  LOG_WARN << "RDO number is BAD number(<1 || >5), reject this RDO" << endm;
494  mRdoFlag = 0;
495  return;
496  }
497 
498  index += HEADER_LENGTH;
499 
500  for (Int_t i = 0; i < 8; i++) {
501  if (i == 0) {
502  mAdcHeader[i] = (mRdoData + index);
503  mAdc[i] = mAdcHeader[i] + FIBER_HEADER_LENGTH;
504  }
505  else {
506  mAdc[i] = mAdc[i - 1] + mAdcLength[i - 1];
507  mAdcHeader[i] = (mAdcHeader[i - 1] + mAdcLength[i - 1]);
508  }
509 
510  mAdcLength[i] = Mid(ADC_START, ADC_END, mAdcHeader[i][1]);
511  mDataMode[i] = Mid(DATAMODE_START, DATAMODE_END, mAdcHeader[i][1]);
512  mChannel[i] = Mid(FIBER_START, FIBER_END, mAdcHeader[i][2]);
513  mFlag[i] = Mid(FLAG_START, FLAG_END, mAdcHeader[i][1]);
514 
515  if (mAdcHeader[i][0] == FIBER_LINK_TOKEN) {
516  LOG_DEBUG << "Fiber [" << mChannel[i] << "]: link Token correct : 0x"
517  << hex << mAdcHeader[i][0] << dec << endm;
518  }
519  else {
520  LOG_WARN << "Fiber [" << mChannel[i] << "]: Link Token wrong :0x"
521  << hex << mAdcHeader[i][0] << dec << endm;
522  mFiberFlag[i] = 0;
523  continue;
524  }
525 
526  if (mDataMode[i] == RAWMODE) {
527  LOG_DEBUG << "Fiber [" << mChannel[i] << "]:Data mode is RAW data. ADC Length "
528  << mAdcLength[i] << endm;
529  }
530  else if (mDataMode[i] == COMPRESSEDMODE) {
531  LOG_DEBUG << "Fiber [" << mChannel[i] << "]:Data mode is COMPRESSED data. ADC Length "
532  << mAdcLength[i] << endm;
533  }
534  else if (mDataMode[i] == CMNSMODE) {
535  LOG_DEBUG << "Fiber [" << mChannel[i] << "]:Data mode is CMN suppressed data. ADC Length "
536  << mAdcLength[i] << endm;
537  }
538  else {
539  LOG_WARN << "Fiber [" << mChannel[i] << "]: DO not have this data mode; error data mode = "
540  << mDataMode[i] << endm;
541  mFiberFlag[i] = 0;
542  continue;
543  }
544 
545  if (mFlag[i] == NODATA) {
546  LOG_DEBUG << "Fiber [" << mChannel[i] << "] Flag:NO DATA FLAG,reject this fiber data" << endm;
547 
548  if (mAdcLength[i] == FIBER_HEADER_LENGTH)
549  LOG_DEBUG << "Fiber [" << mChannel[i] << "] Flag and adc length is consistent! let's look at next fiber.." << endm;
550 
551  if (mAdcLength[i] != FIBER_HEADER_LENGTH) {
552  LOG_WARN << "Fiber [" << mChannel[i] << "] Flag and adc length is not consistent,Stop !" << endm;
553  mFiberFlag[i] = 0;
554  continue;
555  }
556  }
557 
558  if (mFlag[i] == OVERFLOWFLAG) {
559  LOG_WARN << "Fiber [" << mChannel[i] << "] Flag:Over Flow" << endm;
560  mFiberFlag[i] = 0;
561  continue;
562  }
563 
564  if (mFlag[i] == EARLY_ABORT) {
565  LOG_WARN << "Fiber [" << mChannel[i] << "] Flag:Abort Early!" << endm;
566  mFiberFlag[i] = 0;
567  continue;
568  }
569 
570  if (mFlag[i] == WRONG_PIPE_MODE) {
571  LOG_WARN << "FIBER [" << mChannel[i] << "] Flag:Wrong pipe mode!" << endm;
572  mFiberFlag[i] = 0;
573  continue;
574  }
575 
576  LOG_DEBUG << "Fiber [" << mChannel[i] << "]: ADC Length = " << mAdcLength[i] << endm;
577  }
578 
579  //check the end token,TCD end token TCD header
580  if (mRdoData[mRdoDataLength / sizeof(UInt_t) - 1] == END_TOKEN) {
581  LOG_DEBUG << "End Token Correct: 0x" << hex << mRdoData[mRdoDataLength / sizeof(UInt_t) - 1] << dec << endm;
582  }
583  else {
584  LOG_WARN << "End Token Wrong : 0x" << hex << mRdoData[mRdoDataLength / sizeof(UInt_t) - 1] << dec << endm;
585  mRdoFlag = 0;
586  return;
587  }
588 
589  //tcd end token
590  if (mRdoData[mRdoDataLength / sizeof(UInt_t) - 3] == TCD_END_TOKEN) {
591  LOG_DEBUG << "TCD End Token Correct: 0x" << hex << mRdoData[mRdoDataLength / sizeof(UInt_t) - 3] << dec << endm;
592  }
593  else {
594  LOG_WARN << "TCD End Token Wrong : 0x" << hex << mRdoData[mRdoDataLength / sizeof(UInt_t) - 3] << dec << endm;
595  mRdoFlag = 0;
596  return;
597  }
598 
599  //tcd token
600  mTrailerData = mAdcHeader[7] + mAdcLength[7];
601 
602  if (mTrailerData[0] == TCD_TOKEN) {
603  LOG_DEBUG << "TCD Token Correct: 0x" << hex << mTrailerData[0] << dec << endm;
604  }
605  else {
606  LOG_WARN << "TCD Token Wrong : 0x" << hex << mTrailerData[0] << dec << endm;
607  mRdoFlag = 0;
608  return;
609  }
610 
611  if (StMaker::GetDebug()) {
612  for (Int_t t = 0; t < 10; t++) {
613  if (t == 0) LOG_DEBUG << "Start Print Trailer info... " << endm;
614 
615  LOG_DEBUG << "0x" << hex << mTrailerData[t] << dec << endm;
616 
617  if (mTrailerData[t] == END_TOKEN) break;
618  }
619  }
620 }
621 //-------------------------------------------------
622 Int_t StSstDaqMaker::GetHitsDataLength(Int_t FiberNumber)
623 {
624  return mAdcLength[FiberNumber];
625 }
626 //------------------------------------------------
627 void StSstDaqMaker::DecodeHitsData()
628 {
629  if (mRdoFlag != 1) return;
630 
631  LOG_DEBUG << "START Decoding RDO [" << mRDO << "] data, rdo flag is " << mRdoFlag << endm;
632 
633  for (Int_t j = 0; j < 8; j++) {
634  if (mFiberFlag[j] != 1) continue;
635 
636  if (mChannel[j] < 0 || mChannel[j] > (nSstFiberPerRdo - 1)) {
637  LOG_WARN << "Fiber number is BAD (<0 || >7), reject this Fiber" << endm;
638  continue;
639  }
640 
641  Int_t temp = mAdcLength[j] - FIBER_HEADER_LENGTH;
642 
643  if (temp == 0 || !mAdc[j]) {
644  LOG_WARN << "Fiber [" << mChannel[j] << "]: do not have any data..." << endm;
645  continue;
646  }
647 
648  if (mFlag[j] != NORMAL) {
649  LOG_WARN << "Fiber[" << mChannel[j] << "]: data flag is not normal, reject this fiber" << endm;
650  continue;
651  }
652 
653  if (mDataMode[j] == RAWMODE) {
654  // DecodeRawWords(mAdc[j], temp, mChannel[j]);
655  DecodeRawWords_r15(mAdc[j], temp, mChannel[j]);
656  }
657 
658  if ((mDataMode[j] == COMPRESSEDMODE) || (mDataMode[j] == CMNSMODE))
659  DecodeCompressedWords(mAdc[j], temp, mChannel[j]);
660  }
661 }
662 //-------------------------------------------------
663 void StSstDaqMaker::DecodeRawWords(UInt_t *val, Int_t vallength, Int_t channel)
664 {
665  Int_t strip_number[3] = {0};
666  Int_t id_wafer[3] = {0};
667  Int_t ladderCountN[20] = {0};
668  Int_t ladderCountP[20] = {0};
669  Int_t data[3] = {0};
670  Int_t wafer[3] = {0};
671  Int_t hybrid[3] = {0};
672  Int_t strip[3] = {0};
673  Int_t readout[3] = {0};
674  Int_t readout_correct[3] = {0};
675  Int_t ladder = 0;
676  Int_t id_side = 0;
677  Int_t count = 1;
678 
679  //initialize St_spa_strip and St_ssdPedStrip table.
680  spa_strip = dynamic_cast<St_spa_strip *>( m_DataSet->Find("spa_strip"));
681 
682  if (!spa_strip) {
683  spa_strip = new St_spa_strip("spa_strip", vallength);
684  m_DataSet->Add(spa_strip);
685  }
686 
687  spa_strip_st out_strip;
688  LOG_DEBUG << "DECODING RAW MODE data....." << endm;
689  //grab ladder and side
690  FindLadderSide(mRDO, channel, ladder, id_side);
691 
692  //RAW data format
693  //Each 32-bit word will record 3 ADC words.
694  //Data store structure:
695  //
696  // 32-bit word 3 ADCs bit 9-0:readout 0; hybrid 0
697  // bit 19-10:readout 0; hybrid 1
698  // bit 29-20:readout 0; hybrid 2
699  // .
700  // .
701  // 32-bit word 3 ADCs bit 9-0:readout 0; hybrid 15
702  // bit 19-10:readout 1; hybrid 0
703  // bit 29-20:readout 1; hybrid 1
704 
705  for (Int_t i = 0; i < vallength; i++) {
706  if (i == 0) hybrid[0] = 0;
707  else hybrid[0] = hybrid[2] + 1;
708 
709  if (hybrid[0] >= 16) hybrid[0] = hybrid[0] % 16;
710 
711  hybrid[1] = hybrid[0] + 1;
712 
713  if (hybrid[1] >= 16) hybrid[1] = hybrid[1] % 16;
714 
715  hybrid[2] = hybrid[0] + 2;
716 
717  if (hybrid[2] >= 16) hybrid[2] = hybrid[2] % 16;
718 
719  LOG_DEBUG << "Three hybrid number in current word is :"
720  << hybrid[0] << "," << hybrid[1] << "," << hybrid[2] << endm;
721 
722  if (i != 0) {
723  if (hybrid[0] == 0) readout[0] = readout[0] + 1;
724 
725  if (readout[2] > readout[0]) readout[0] = readout[2];
726 
727  if (hybrid[1] == 0) readout[1] = readout[1] + 1;
728 
729  if (readout[0] > readout[1]) readout[1] = readout[0];
730 
731  if (hybrid[2] == 0) readout[2] = readout[2] + 1;
732 
733  if (readout[1] > readout[2]) readout[2] = readout[1];
734  }
735 
736  LOG_DEBUG << "[adc_pointer,readout_0,hybrid_0] = [" << i << ","
737  << readout[0] << "," << hybrid[0] << "]" << endm;
738  LOG_DEBUG << "[adc_pointer,readout_1,hybrid_1] = [" << i << ","
739  << readout[1] << "," << hybrid[1] << "]" << endm;
740  LOG_DEBUG << "[adc_pointer,readout_2,hybrid_2] = [" << i << ","
741  << readout[2] << "," << hybrid[2] << "]" << endm;
742 
743  data[0] = Mid(HYBRID_ONE_START, HYBRID_ONE_END, val[i]);
744  data[1] = Mid(HYBRID_TWO_START, HYBRID_TWO_END, val[i]);
745  data[2] = Mid(HYBRID_THREE_START, HYBRID_THREE_END, val[i]);
746 
747  for (Int_t n = 0; n < 3; n++) {
748  readout_correct[n] = readout[n];
749 
750  if (!Shift(mEventrunumber, readout_correct[n])) {
751  LOG_DEBUG << "First readout channel in old LC FPGA is not usable." << endm;
752  continue;
753  }
754 
755  strip[n] = readout[n];
756  wafer[n] = hybrid[n];
757  FindStripNumber(strip[n]);
758 
759  if (id_side == 0) {
760  id_wafer[n] = 7000 + 100 * (nSstWaferPerLadder - wafer[n]) + ladder + 1;
761  strip_number[n] = strip[n] + 1; //strip[n]+1 . in mapping, strip[1-128];
762  }
763  else {
764  id_wafer[n] = 7000 + 100 * ((wafer[n]) + 1) + ladder + 1;
765  strip_number[n] = nSstStripsPerWafer - strip[n];
766  }
767 
768  if( mRunNum >= 14 && mRunNum <=15) {
769  if (gStSstDbMaker->maskChip(id_side, ladder, wafer[n], strip[n] / 128)) continue;
770  }
771 
772  out_strip.id = count;
773  out_strip.adc_count = data[n];
774  out_strip.id_strip = 10000 * (10 * strip_number[n] + id_side) + id_wafer[n]; //id_side:0-->p,1-->N
775  out_strip.id_mchit[0] = 0 ;
776  out_strip.id_mchit[1] = 0 ;
777  out_strip.id_mchit[2] = 0 ;
778  out_strip.id_mchit[3] = 0 ;
779  out_strip.id_mchit[4] = 0 ;
780 
781  spa_strip->AddAt(&out_strip);
782 
783  if (id_side == 0) {
784  ladderCountP[ladder]++;
785  }
786  else {
787  ladderCountN[ladder]++;
788  }
789 
790  count = count + 1;
791  }
792  }
793 
794  LOG_DEBUG << "Last readout number: [readout[0] , readout[1] , readout[2]] = [" << readout[0] << ","
795  << readout[1] << "," << readout[2] << "]" << endm;
796 
797  if (readout[0] > nSstStripsPerWafer || readout[1] > nSstStripsPerWafer || readout[2] > nSstStripsPerWafer) {
798  LOG_WARN << "Strip number is larger than 768." << endm;
799  return;
800  }
801 
802  if (StMaker::GetDebug()) {
803  LOG_DEBUG << "Make()/Counts (p-side): ";
804 
805  for (Int_t i = 0; i < nSstLadder; i++) {
806  LOG_DEBUG.width(5);
807  LOG_DEBUG << ladderCountP[i] << " ";
808  }
809 
810  LOG_DEBUG << endm;
811  LOG_DEBUG << "Make()/Counts (n-side): ";
812 
813  for (Int_t i = 0; i < nSstLadder; i++) {
814  LOG_DEBUG.width(5);
815  LOG_DEBUG << ladderCountN[i] << " ";
816  }
817 
818  LOG_DEBUG << endm;
819 
820  if (spa_strip->GetNRows() != 0) {
821  LOG_DEBUG << "Make()/ Read Signal from Physics Run" << endm;
822  LOG_DEBUG << "Make()/ spa_strip->NRows= " << spa_strip->GetNRows() << endm;
823  }
824  }
825 }
826 //-------------------------------------------------
827 void StSstDaqMaker::DecodeRawWords_r15(UInt_t *val, Int_t vallength, Int_t channel)
828 {
829  vector<vector<int> > vadc(16, vector<int>(768)); //2-D Vector
830  vector<vector<float> > vcmnoise(16, vector<float>(6)); //Save CM Noise
831  vector<int> vtemp(128);
832 
833  for (int i = 0; i < 16; i++) {
834  vadc[i].resize(768);
835  vcmnoise[i].resize(6);
836  }
837 
838  Int_t data[3] = {0};
839  Int_t wafer[3] = {0};
840  Int_t hybrid[3] = {0};
841  Int_t strip[3] = {0};
842  Int_t readout[3] = {0};
843  Int_t readout_correct[3] = {0};
844  Int_t ladder = 0;
845  Int_t id_side = 0;
846  Int_t readoutindex = 0;
847 
848  LOG_DEBUG << "DECODING RAW MODE data....." << endm;
849  //grab ladder and side
850  FindLadderSide(mRDO, channel, ladder, id_side);
851 
852  for (Int_t i = 0; i < vallength; i++) {
853  if (i == 0) hybrid[0] = 0;
854  else hybrid[0] = hybrid[2] + 1;
855 
856  if (hybrid[0] >= 16) hybrid[0] = hybrid[0] % 16;
857 
858  hybrid[1] = hybrid[0] + 1;
859 
860  if (hybrid[1] >= 16) hybrid[1] = hybrid[1] % 16;
861 
862  hybrid[2] = hybrid[0] + 2;
863 
864  if (hybrid[2] >= 16) hybrid[2] = hybrid[2] % 16;
865 
866  LOG_DEBUG << "Three hybrid number in current word is :"
867  << hybrid[0] << "," << hybrid[1] << "," << hybrid[2] << endm;
868 
869  if (i != 0) {
870  if (hybrid[0] == 0) readout[0] = readout[0] + 1;
871 
872  if (readout[2] > readout[0]) readout[0] = readout[2];
873 
874  if (hybrid[1] == 0) readout[1] = readout[1] + 1;
875 
876  if (readout[0] > readout[1]) readout[1] = readout[0];
877 
878  if (hybrid[2] == 0) readout[2] = readout[2] + 1;
879 
880  if (readout[1] > readout[2]) readout[2] = readout[1];
881  }
882 
883  LOG_DEBUG << "[adc_pointer,readout_0,hybrid_0] = [" << i << ","
884  << readout[0] << "," << hybrid[0] << "]" << endm;
885  LOG_DEBUG << "[adc_pointer,readout_1,hybrid_1] = [" << i << ","
886  << readout[1] << "," << hybrid[1] << "]" << endm;
887  LOG_DEBUG << "[adc_pointer,readout_2,hybrid_2] = [" << i << ","
888  << readout[2] << "," << hybrid[2] << "]" << endm;
889 
890  data[0] = Mid(HYBRID_ONE_START, HYBRID_ONE_END, val[i]);
891  data[1] = Mid(HYBRID_TWO_START, HYBRID_TWO_END, val[i]);
892  data[2] = Mid(HYBRID_THREE_START, HYBRID_THREE_END, val[i]);
893 
894  for (Int_t n = 0; n < 3; n++) {
895  readout_correct[n] = readout[n];
896 
897  if (!Shift(mEventrunumber, readout_correct[n])) {
898  LOG_DEBUG << "First readout channel in old LC FPGA is not usable." << endm;
899  continue;
900  }
901 
902  strip[n] = readout_correct[n];
903  wafer[n] = hybrid[n];
904  readoutindex = id_side * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer
905  + ladder * nSstWaferPerLadder * nSstStripsPerWafer
906  + wafer[n] * nSstStripsPerWafer
907  + strip[n];
908 
909  // wrap-around correction
910  data[n] = data[n] + 375;
911  if(data[n]>1024) data[n] = data[n] - 1024;
912 
913 
914  data[n] = data[n] - 375 - mReadOutPed[readoutindex];
915  vadc[wafer[n]][strip[n]] = data[n];
916  }
917  }
918 
919  for (int i = 0; i < 16; i++) {
920  for (int j = 0; j < 768; j++) {
921  vtemp[j % 128] = vadc[i][j];
922 
923  if ((j + 1) % 128 == 0) {
924  vcmnoise[i][j / 128] = CalculateCommonModeNoiseSimple(vtemp);
925  }
926  }
927  }
928 
929  FillData(vadc, vcmnoise, id_side, ladder, vallength);
930 
931  LOG_DEBUG << "Last readout number: [readout[0] , readout[1] , readout[2]] = [" << strip[0] << ","
932  << strip[1] << "," << strip[2] << "]" << endm;
933 
934  if (strip[0] > nSstStripsPerWafer || strip[1] > nSstStripsPerWafer || strip[2] > nSstStripsPerWafer) {
935  LOG_WARN << "Strip number is larger than 768." << endm;
936  return;
937  }
938 
939  vadc.clear();
940  vcmnoise.clear();
941  vtemp.clear();
942 }
943 //-------------------------------------------------
944 void StSstDaqMaker::DecodeCompressedWords(UInt_t *val, Int_t vallength, Int_t channel)
945 {
946  Int_t ladderCountN[20] = {0};
947  Int_t ladderCountP[20] = {0};
948  Int_t strip_number = 0;
949  Int_t id_side = 0;
950  Int_t id_wafer = 0;
951  Int_t count = 1;
952  Int_t data = 0;
953  Int_t wafer = 0;
954  Int_t strip = 0;
955  Int_t readout = 0;
956  Int_t ladder = 0;
957  Int_t chip = 0;
958  Int_t chipIndex = 0;
959  Int_t oldchip = 0;
960  Int_t chipflag = 0; // CMN algorithm faild flag.
961  UInt_t errorcode = 0; // CMN algorithm error code.
962  int wafDecodeBadStrip = 0; // used for bad strip table
963  int stripDecodeBadStrip = 0;// used for decoding bad strip table
964  int indexDecodeBadStrip = 0; // used for bad strip table
965 
966  LOG_DEBUG << "Current Event data length : " << vallength << endm;
967  spa_strip = dynamic_cast<St_spa_strip *>( m_DataSet->Find("spa_strip"));
968 
969  if (!spa_strip) {
970  spa_strip = new St_spa_strip("spa_strip", vallength);
971  m_DataSet->Add(spa_strip);
972  }
973 
974  spa_strip_st out_strip;
975  //grab ladder and side
976  FindLadderSide(mRDO, channel, ladder, id_side); //convert channel to real Ladder number and side
977 
978  for (Int_t i = 0; i < vallength; i++) {
979  wafer = Mid(HYBRID_START, HYBRID_END, val[i]);
980  strip = Mid(STRIP_START, STRIP_END, val[i]);
981  data = Mid(COM_ADC_START, COM_ADC_END, val[i]);
982  errorcode = Mid(ERROR_START,ERROR_END,val[i]);
983  chip = strip/nSstStripsPerChip;
984  chipIndex = ladder*nSstWaferPerLadder*nSstChipPerWafer + wafer*nSstChipPerWafer + chip;
985 
986  // Mask out CMN failed chips
987  if(oldchip!=chipIndex) chipflag = 0;
988  if(strip%nSstStripsPerChip==0 && errorcode==CMNERRORCODE) chipflag = 1;
989  if(chipflag) continue;
990 
991  if (!Shift(mEventrunumber, strip)) {
992  LOG_INFO << "First readout channel in old LC FPGA is not usable." << endm;
993  continue;
994  }
995 
996  //chipCorrect table
997  if(data<mNoiseCut[chipIndex][id_side]) data = 0; //remove noise.
998  else data = data - mCorrectFactor[chipIndex][id_side]; //data correction.
999 
1000  readout = strip;
1001 
1002  FindStripNumber(strip);//convert to physic strip number
1003 
1004  if (id_side == 0) {
1005  id_wafer = 7000 + 100 * (nSstWaferPerLadder - wafer) + ladder + 1;
1006  strip_number = strip + 1;
1007  }
1008  else {
1009  id_wafer = 7000 + 100 * ((wafer) + 1) + ladder + 1;
1010  strip_number = nSstStripsPerWafer - strip;
1011  }
1012  //chipMask table
1013  if( mRunNum >= 14 && mRunNum <=15) {
1014  if (gStSstDbMaker->maskChip(id_side, ladder, wafer, chip)) continue;
1015  }
1016 
1017  if(mRunNum >= 16){
1018  if(id_side == 0){
1019  wafDecodeBadStrip = nSstWaferPerLadder - wafer - 1;
1020  stripDecodeBadStrip = strip + 1;
1021  }
1022  else {
1023  wafDecodeBadStrip = wafer + 1 - 1;
1024  stripDecodeBadStrip = nSstStripsPerWafer - strip;
1025  }
1026 
1027  indexDecodeBadStrip = id_side * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer
1028  + ladder * nSstWaferPerLadder * nSstStripsPerWafer
1029  + wafDecodeBadStrip * nSstStripsPerWafer
1030  + stripDecodeBadStrip -1;
1031  if(mBadStrip[indexDecodeBadStrip]!=0) continue;
1032  }
1033 
1034  //save only strips with data>0, otherwise it increases the datastrip volume for nothing
1035  if(data>0){
1036  out_strip.id = count;
1037  out_strip.adc_count = data;
1038  out_strip.id_strip = 10000 * (10 * strip_number + id_side) + id_wafer;
1039  out_strip.id_mchit[0] = 0 ;
1040  out_strip.id_mchit[1] = 0 ;
1041  out_strip.id_mchit[2] = 0 ;
1042  out_strip.id_mchit[3] = 0 ;
1043  out_strip.id_mchit[4] = 0 ;
1044  spa_strip->AddAt(&out_strip);
1045 
1046  if (id_side == 0) {
1047  ladderCountP[ladder]++;
1048  }
1049  else {
1050  ladderCountN[ladder]++;
1051  }
1052 
1053  count = count + 1;
1054  }
1055  oldchip = chipIndex;
1056  }
1057 
1058  if (readout > nSstStripsPerWafer) {
1059  LOG_WARN << "Strip number is larger than 768, ERROR" << endm;
1060  return;
1061  }
1062 
1063  if (StMaker::GetDebug()) {
1064  LOG_DEBUG << "Make()/Counts (p-side): ";
1065 
1066  for (Int_t i = 0; i < nSstLadder; i++) {
1067  LOG_DEBUG.width(5);
1068  LOG_DEBUG << ladderCountP[i] << " ";
1069  }
1070 
1071  LOG_DEBUG << endm;
1072  LOG_DEBUG << "Make()/Counts (n-side): ";
1073 
1074  for (Int_t i = 0; i < nSstLadder; i++) {
1075  LOG_DEBUG.width(5);
1076  LOG_DEBUG << ladderCountN[i] << " ";
1077  }
1078 
1079  LOG_DEBUG << endm;
1080 
1081  if (spa_strip->GetNRows() != 0) {
1082  LOG_DEBUG << "Make()/ Read Signal from Physics Run" << endm;
1083  LOG_DEBUG << "Make()/ spa_strip->NRows= " << spa_strip->GetNRows() << endm;
1084  }
1085  }
1086 }
1087 
1088 //-------------------------------------------------
1089 Int_t StSstDaqMaker::Shift(Int_t runnumber, Int_t &channel)
1090 {
1091  if (runnumber < 15150058) {
1092  if (channel == 0) return 0;
1093  else {
1094  channel = channel - 1;
1095  return 1;
1096  }
1097  }
1098  else {
1099  return 1;
1100  }
1101 }
1102 //-------------------------------------------------
1103 UInt_t StSstDaqMaker::Mid(Int_t start, Int_t end, UInt_t input)
1104 {
1105  UInt_t buf;
1106  buf = input << (32 - end);
1107  buf = buf >> (32 - end);
1108  return buf >> start;
1109 }
1110 
1111 //--------------------------------------------------
1112 void StSstDaqMaker::FindLadderSide(Int_t RDO, Int_t channel, Int_t &ladder, Int_t &side)
1113 {
1114  ladder = RDO2LADDER[RDO - 1][channel] - 1; //ladder [0-19];
1115 
1116  if (ladder > 20) LOG_WARN << "Ladder >20. RDO Number is" << RDO << ", channel number :" << channel << endm;
1117 
1118  if (RDO < 3) side = 1;
1119  else if (RDO > 3) side = 0;
1120  else if (channel < 4) side = 1;
1121  else side = 0;
1122 }
1123 //--------------------------------------------------
1124 void StSstDaqMaker::FindStripNumber(Int_t &strip)
1125 {
1126  Int_t temp = (strip / 128) * 128 + ReadOutMap[strip % 128];
1127  strip = temp - 1;
1128 }
1129 //--------------------------------------------------
1130 void StSstDaqMaker::FindChannelNumber(Int_t &channel)
1131 {
1132  Int_t temp = (channel / 128) * 128 + Rev_ReadOutMap[channel % 128];
1133  channel = temp - 1;
1134 }
1135 //--------------------------------------------------
1136 
1137 void StSstDaqMaker::PrintConfiguration(Int_t runumber, sstConfiguration_st *config)
1138 {
1139  switch (runumber) {
1140  case 4 : {
1141  LOG_INFO << "Configuration of ladders for run IV" << endm;
1142  break;
1143  }
1144 
1145  case 5 : {
1146  LOG_INFO << "Configuration of ladders for run V" << endm;
1147  break;
1148  }
1149 
1150  case 6 : {
1151  LOG_INFO << "Configuration of ladders for run VI" << endm;
1152  break;
1153  }
1154 
1155  case 7 : {
1156  LOG_INFO << "Configuration of ladders for run VII" << endm;
1157  break;
1158  }
1159  }
1160 
1161  Int_t i = 0;
1162  Int_t totladderPresent = 0;
1163  LOG_INFO << "PrintLadderSummary:ladder id :";
1164 
1165  for (i = 1; i <= config->nMaxLadders; i++) {
1166  LOG_INFO.width(3);
1167  LOG_INFO << i;
1168  }
1169 
1170  LOG_INFO << endm;
1171  LOG_INFO << "PrintLadderSummary:Active Ladders on sectors: ";
1172 
1173  for (i = 1; i <= config->nMaxLadders; i++) {
1174  LOG_INFO.width(3);
1175  LOG_INFO << mConfig->getLadderIsActive(i);
1176 
1177  if (mConfig->getLadderIsActive(i) > 0)totladderPresent++;
1178 
1179  }
1180 
1181  LOG_INFO << endm;
1182  LOG_INFO << "totLadderActive = " << totladderPresent << endm;
1183 }
1184 //------------------------------------------------
1185 void StSstDaqMaker::Clear(const Option_t *)
1186 {
1187  if (spa_strip) {
1188  delete spa_strip;
1189  spa_strip = 0;
1190  }
1191 
1192  if (stripCal) {
1193  delete stripCal;
1194  stripCal = 0;
1195  }
1196 
1197  return StMaker::Clear();
1198 }
1199 //------------------------------------------------
1200 void StSstDaqMaker::FillReadOutPedTable(sstStripCalib_st *noise)
1201 {
1202  LOG_INFO << "InirTun : New Table(sstStripCalib) is used ! " << endm;
1203 
1204  //coding: id = (491520)*side[0-1]/2 + ladder[0-19]*12288 + wafer[0-15]*768 + strip[0-767]
1205  int totStripSst = nSstSide*nSstLadder*nSstWaferPerLadder*nSstStripsPerWafer;
1206  for (Int_t i = 0 ; i < totStripSst ; i++)
1207  mReadOutPed[i] = (Int_t)noise[0].pedestals[i];
1208 }
1209 //------------------------------------------------
1210 void StSstDaqMaker::FillDefaultReadOutPedTable()
1211 {
1212  Int_t size = nSstSide * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer;
1213 
1214  for (Int_t i = 0; i < size; i++) {
1215  mReadOutPed[i] = 0; // mean value for all channels
1216  }
1217 }
1218 //------------------------------------------------
1219 void StSstDaqMaker::FillNoiseTable(sstNoise_st *noise)
1220 {
1221  // Table entries are coded by readout ordering.
1222  LOG_INFO << "InitRun for real data : new Table(ssdNoise) is used" << endm;
1223  Int_t size = nSstSide * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer;
1224 
1225  for (Int_t i = 0 ; i < size ; i++)
1226  mIntrinsicRms[i] = (Int_t)noise[0].rms[i]/10.0; // 10*rms in table
1227 }
1228 //------------------------------------------------
1229 void StSstDaqMaker::FillDefaultNoiseTable()
1230 {
1231  Int_t size = nSstSide * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer;
1232 
1233  for (Int_t i = 0; i < size; i++) {
1234  mIntrinsicRms[i] = nRmsCut; // if not rms table or pedestal table can be found, then SST will not have any output.
1235  }
1236 }
1237 //------------------------------------------------
1238 void StSstDaqMaker::FillChipNoiseTable(sstChipCorrect_st *chipCorrectTable){
1239  int side=0,ladder=0,wafer=0,chip=0;
1240  LOG_DEBUG<<"New ChipNoiseTable was used! "<<endm;
1241  int totChipSst = nSstSide*nSstLadder*nSstWaferPerLadder*nSstChipPerWafer;
1242  int totChipSstSide = nSstLadder*nSstWaferPerLadder*nSstChipPerWafer;
1243  int totChipSstLadder = nSstWaferPerLadder*nSstChipPerWafer;
1244 
1245  for(Int_t i=0; i<totChipSst;i++){
1246  side = i/totChipSstSide;
1247  ladder = (i - side*totChipSstSide)/totChipSstLadder;
1248  wafer = (i - side*totChipSstSide - ladder*totChipSstLadder)/nSstChipPerWafer;
1249  chip = (i - side*totChipSstSide - ladder*totChipSstLadder - wafer*nSstChipPerWafer);
1250 
1251  LOG_DEBUG <<" i/side/ladder/wafer/chip/correct/CutPos : "
1252  <<i << " "
1253  <<side << " "
1254  <<ladder << " "
1255  <<wafer << " "
1256  <<chip << " "
1257  <<chipCorrectTable[0].nCorrect[i] << " "
1258  <<chipCorrectTable[0].nCutPos[i] << " " <<endm;
1259 
1260  mCorrectFactor[ladder*totChipSstLadder+wafer*nSstChipPerWafer+chip][side] = chipCorrectTable[0].nCorrect[i];
1261  mNoiseCut[ladder*totChipSstLadder+wafer*nSstChipPerWafer+chip][side] = chipCorrectTable[0].nCutPos[i];
1262  }
1263 }
1264 //------------------------------------------------
1265 void StSstDaqMaker::FillDefaultChipNoiseTable(){
1266  LOG_DEBUG <<" Default is no any correction ." << endm;
1267  Int_t size = nSstLadder*nSstWaferPerLadder*nSstChipPerWafer;
1268  for(Int_t s=0;s<nSstSide;s++) {
1269  for(Int_t i=0;i<size;i++) {
1270  mCorrectFactor[i][s] = 0;
1271  mNoiseCut[i][s] = 0;
1272  }
1273  }
1274 }
1275 //------------------------------------------------
1276 void StSstDaqMaker::FillBadStripsTable(sstBadStrips_st* badStripTable){
1277  int totChipSst = nSstSide*nSstLadder*nSstWaferPerLadder*nSstStripsPerWafer;
1278  for(Int_t i=0; i<totChipSst;i++){
1279  mBadStrip[i] = badStripTable[0].status[i];
1280  }
1281 }
1282 //------------------------------------------------
1283 Float_t StSstDaqMaker::CalculateCommonModeNoiseSimple(vector<int> vadc) //Simplify algorithm
1284 {
1285  Float_t preSum = 0;
1286  Float_t preMean = 0;
1287  Float_t sum = 0;
1288  Float_t devcut = 20; //deviation cut, default is 10 ADC
1289  Int_t counter = 0;
1290 
1291  TH1I *hadc = new TH1I("hadc", "adc in each chip", 768, -512, 1024);
1292  Float_t chipRms = 0;
1293 
1294  for (int i = 1; i < 128; i++) { //index start from 1 is to avoid the edge effect.
1295  hadc->Fill(vadc[i]);
1296  }
1297 
1298  chipRms = hadc->GetRMS();
1299 
1300  if (chipRms > 15) {
1301  hadc->Delete();
1302  return 0.; //if Raw signal in one chip have very large RMS, we will mark it to bad
1303  }
1304 
1305  hadc->Delete();
1306  //------------------------------
1307  //upgraded Fix Threshold method.
1308  for (int i = 1; i < 128; i++) {
1309  preSum += vadc[i];
1310  }
1311 
1312  preMean = preSum / 127.;
1313 
1314  Float_t thresholdhig = preMean + devcut;
1315  Float_t thresholdlow = preMean - devcut;
1316 
1317  for (int i = 1; i < 128; i++) {
1318  if (vadc[i] < thresholdlow || vadc[i] > thresholdhig) continue;
1319 
1320  sum += vadc[i];
1321  counter = counter + 1;
1322  }
1323 
1324  return (counter>0)?(sum/counter):0;
1325 }
1326 //------------------------------------------------
1327 void StSstDaqMaker::FillData(vector<vector<int> > vadc, vector<vector<float> > vcmnoise, Int_t id_side, Int_t ladder, Int_t vallength)
1328 {
1329  Int_t id_wafer = 0;
1330  Int_t strip_number = 0;
1331  Int_t count = 1;
1332  Int_t ladderCountN[20] = {0};
1333  Int_t ladderCountP[20] = {0};
1334  Float_t adc = 0;
1335  Float_t cmnoise = 0;
1336  Float_t intrinsicnoise = 0;
1337  Int_t stripindex = 0;
1338 
1339  const Float_t Epsinon = 0.00001;
1340  spa_strip = (St_spa_strip *) m_DataSet->Find("spa_strip");
1341 
1342  if (!spa_strip) {
1343  spa_strip = new St_spa_strip("spa_strip", vallength);
1344  m_DataSet->Add(spa_strip);
1345  }
1346 
1347  spa_strip_st out_strip;
1348 
1349  for (int i = 0; i < 16; i++) {
1350  for (int j = 0; j < 768; j++) {
1351  Int_t s = j;
1352  adc = (Float_t)vadc[i][j];
1353  cmnoise = vcmnoise[i][j / 128];
1354 
1355  //----------------
1356  //Temporary masking
1357 
1358  if ((cmnoise >= -Epsinon) && (cmnoise <= Epsinon)) adc = 0;
1359  else {
1360  adc = adc - cmnoise;
1361  }
1362 
1363  if (j % 128 == 0) adc = 0; //first channel is not useable.
1364 
1365  if (id_side == 1) adc = -1 * adc; //Reverse N-side Signal Charge Sign.
1366 
1367  FindStripNumber(s);
1368 
1369  //---------------
1370  //hotchip masking
1371  if( mRunNum >= 14 && mRunNum <=15) {
1372  if (gStSstDbMaker->maskChip(id_side, ladder, i, j / 128)) continue;
1373  }
1374 
1375  if (id_side == 0) {
1376  id_wafer = 7000 + 100 * (nSstWaferPerLadder - i) + ladder + 1;
1377  strip_number = s + 1;
1378  }
1379  else {
1380  id_wafer = 7000 + 100 * (i + 1) + ladder + 1;
1381  strip_number = nSstStripsPerWafer - s;
1382  }
1383 
1384  //-------------------------
1385  //Offline Zero-Suppression
1386  stripindex = id_side * nSstLadder * nSstWaferPerLadder * nSstStripsPerWafer
1387  + ladder * nSstWaferPerLadder * nSstStripsPerWafer
1388  + i * nSstStripsPerWafer
1389  + j; // readout ordering
1390 
1391  intrinsicnoise = mIntrinsicRms[stripindex]; // readout ordering
1392  if(intrinsicnoise<std::numeric_limits<float>::epsilon()) intrinsicnoise = std::numeric_limits<unsigned short>::max(); // if the noise is 0, then reject this channel.
1393 
1394  if (adc < nSigmaCut * intrinsicnoise) continue;
1395  if (adc <=0) continue;
1396  if (mReadOutPed[stripindex] == 0) continue; // reject channel with bad pedestal.
1397  //mask bad strips., default is 10 Adc
1398  if(intrinsicnoise>=nRmsCut) continue;
1399 
1400  out_strip.id = count;
1401  out_strip.adc_count = adc; //Minus the Common mode noise
1402  out_strip.id_strip = 10000 * (10 * strip_number + id_side) + id_wafer; //id_side:0-->p,1-->N
1403  out_strip.id_mchit[0] = 0 ;
1404  out_strip.id_mchit[1] = 0 ;
1405  out_strip.id_mchit[2] = 0 ;
1406  out_strip.id_mchit[3] = 0 ;
1407  out_strip.id_mchit[4] = 0 ;
1408 
1409  spa_strip->AddAt(&out_strip);
1410 
1411  if (id_side == 0) {
1412  ladderCountP[ladder]++;
1413  }
1414  else {
1415  ladderCountN[ladder]++;
1416  }
1417  }
1418  }
1419 
1420  if (StMaker::GetDebug()) {
1421  LOG_DEBUG << "Make()/Counts (p-side): ";
1422 
1423  for (Int_t i = 0; i < nSstLadder; i++) {
1424  LOG_DEBUG.width(5);
1425  LOG_DEBUG << ladderCountP[i] << " ";
1426  }
1427 
1428  LOG_DEBUG << endm;
1429  LOG_DEBUG << "Make()/Counts (n-side): ";
1430 
1431  for (Int_t i = 0; i < nSstLadder; i++) {
1432  LOG_DEBUG.width(5);
1433  LOG_DEBUG << ladderCountN[i] << " ";
1434  }
1435 
1436  LOG_DEBUG << endm;
1437 
1438  if (spa_strip->GetNRows() != 0) {
1439  LOG_DEBUG << "Make()/ Read Signal from Physics Run" << endm;
1440  LOG_DEBUG << "Make()/ spa_strip->NRows= " << spa_strip->GetNRows() << endm;
1441  }
1442  }
1443 }
StRtsTable * GetNextDaqElement(const char *elementPath)
Query the STAR production chain for the DAQ data.
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
virtual Int_t Make()
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1388
Definition: Stypes.h:40
const void * At(Int_t i) const
Returns a pointer to the i-th row of the table.
Definition: TTable.cxx:303
Definition: Stypes.h:41
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362