]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDptrgFEB.cxx
OCDB viewer implementation (Ionut)
[u/mrichter/AliRoot.git] / TRD / AliTRDptrgFEB.cxx
CommitLineData
f9720615 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18////////////////////////////////////////////////////////////////////////////
19//
20// Pre-Trigger simulation
21//
22// Authors: F. Reidt (Felix.Reidt@cern.ch)
23//
24// This class is used to simulate the front end box behavior of the
25// pretrigger system. Digits of T0 and V0 are used as input. A threshold
26// discrimination, masking and first processing with look up tables is
27// done during the simulation process
28//
29////////////////////////////////////////////////////////////////////////////
30
31#include <TClonesArray.h>
32
33#include "AliRunLoader.h"
34#include "AliLog.h"
35
36#include "../VZERO/AliVZEROdigit.h"
ce9fb876 37#include "../VZERO/AliVZEROCalibData.h"
f9720615 38#include "../T0/AliT0digit.h"
39
40#include "AliTRDptrgParam.h"
41#include "AliTRDptrgLUT.h"
42#include "AliTRDptrgFEB.h"
43
44ClassImp(AliTRDptrgFEB)
45
46//______________________________________________________________________________
47AliTRDptrgFEB::AliTRDptrgFEB(AliRunLoader *rl)
48 : TObject(),
49 fRunLoader(rl),
50 fParam(0),
51 fLUTArray(0),
52 fType(kUndefined),
53 fOperatingMode(kDigits),
54 fInputChannelCount(0),
55 fPosition(kUnknown),
56 fID(0),
57 fThreshold(0)
58{
59 // default constructor
e51605d9 60 AliError("default ctor - not recommended");
f9720615 61}
62
63//______________________________________________________________________________
64AliTRDptrgFEB::AliTRDptrgFEB(AliRunLoader *rl, AliTRDptrgFEBType_t febType,
65 AliTRDptrgOperatingMode_t operatingMode,
66 AliTRDptrgFEBPosition_t position, Int_t id,
67 AliTRDptrgParam *param)
68 : TObject(),
69 fRunLoader(rl),
70 fParam(param),
71 fLUTArray(0),
72 fType(febType),
73 fOperatingMode(operatingMode),
74 fInputChannelCount(0),
75 fPosition(position),
76 fID(id),
77 fThreshold(0x0)
78{
79 // prefered constructor
80
81 this->LoadParams(); // load configuration parameters
82
83}
84
85//______________________________________________________________________________
86AliTRDptrgFEB::~AliTRDptrgFEB()
87{
88 // destructor
89 if (this->fParam == 0x0) {
90 if (this->fThreshold != 0x0) {
91 delete[] this->fThreshold;
92 this->fThreshold = 0x0;
93 }
94 }
95 // delete LUTArray
96 this->fLUTArray.Delete();
97}
98
99//______________________________________________________________________________
100Int_t AliTRDptrgFEB::LoadDigits()
101{
102 // loads T0 or V0 digits and discriminates them automatically
103
104 if (this->fType == kVZERO) {
105 // load V0's digits --------------------------------------------------------
ce9fb876 106 // behavior adapted for AliVZERODigitizer.cxx 40613 2010-04-22 09:57:15Z
107
f9720615 108 // get V0 run loader
e51605d9 109 AliLoader* loader = this->fRunLoader->GetLoader( "VZEROLoader" );
f9720615 110
111 if (!loader) {
dcf1edef 112 AliError("Cannot get VZERO loader");
f9720615 113 return -1;
114 }
115 loader->LoadDigits("READ");
116 TTree* vzeroDigitsTree = loader->TreeD();
117
118 if (!vzeroDigitsTree) {
dcf1edef 119 AliError("Cannot get the VZERO digit tree");
f9720615 120 return -1;
121 }
122
123
124 TClonesArray* vzeroDigits = NULL;
125 TBranch* digitBranch = vzeroDigitsTree->GetBranch("VZERODigit");
126 digitBranch->SetAddress(&vzeroDigits);
127 vzeroDigitsTree->GetEvent(0);
e51605d9 128
129
f9720615 130 Int_t nDigits = vzeroDigits->GetEntriesFast(); // get digit count
131
132 AliDebug(5, Form("Found a whole of %d digits", nDigits));
133
134 Int_t inputVector = 0x0; // Vector which is feed into the LUT
135
136 for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {
137 // loop over all digits
138 AliDebug(5, "Looping over digit");
139 AliVZEROdigit* digit = (AliVZEROdigit*)vzeroDigits->At(iDigit);
140
141 Int_t pmNumber = digit->PMNumber();
ce9fb876 142 // Int_t board = pmNumber / 8; // changed in Version 40613
143 Int_t feeBoard = AliVZEROCalibData::GetBoardNumber(pmNumber);
144 Int_t board = feeBoard % 4; // feeBoard V0-A: 1-4; V0-C: 5-8 => board: 1-4
145
f9720615 146 Int_t channel = pmNumber % 8;
ce9fb876 147
148 Int_t position = -1;
149 if ((pmNumber >= 32) && (pmNumber <= 63)) { // V0-A (matched v40613)
150 position = 1; // kA
151 }
152 else if ((pmNumber >= 0) && (pmNumber <= 31)) { // V0-C (matched v40613)
153 position = 2; // kB
154 }
155
156 AliDebug(5,
157 Form("pmNumber: %d; feeBoard: %d; board: %d; channel: %d; position %d",
158 pmNumber, feeBoard, board, channel, position));
159
160 if (position == -1) {
161 AliError("Wrong VZERO pmt position found");
162 return -1;
163 }
f9720615 164
165 // check whether the digits belongs to the current FEB, otherwise omit it
166 if ((position == this->fPosition) && (board == this->fID)) {
167 AliDebug(5, "Found an digit corresponding to the current FEB");
f9720615 168 Float_t value = digit->ADC();
169 AliDebug(5, Form("ADC value: %f\n", value));
170 Int_t channelBitMask = 0x01;
171 // channel0 => 0x01; channel1=> 0x02; 2^(channel number)
172 channelBitMask <<= channel;
173 if (value >= this->fThreshold[channel]) {
174 inputVector |= channelBitMask;
175 AliDebug(5,
176 Form("Threshold exceeded in channel %d, new inputVector 0x%x",
177 channel, inputVector));
178 }
179 }
180 }
181
182 AliDebug(5, Form("inputVector: 0x%x", inputVector));
183
184 return inputVector;
185 }
186 else if (this->fType == kTZERO) {
187 // load T0's digits --------------------------------------------------------
188 AliLoader * fT0Loader = this->fRunLoader->GetLoader("T0Loader");
189 // AliT0digit *fDigits;
dcf1edef 190 if (!fT0Loader) {
191 AliError("Cannot get T0 loader");
192 return -1;
193 }
194
f9720615 195 fT0Loader->LoadDigits("READ");
196 // Creating T0 data container
197
198 TTree* treeD = fT0Loader->TreeD();
199 if (!treeD) {
200 AliError("no digits tree");
201 return -1;
202 }
203 AliT0digit* digits = new AliT0digit();
204 TBranch *brDigits = treeD->GetBranch("T0");
205
206 if (brDigits) {
207 brDigits->SetAddress(&digits);
208 }
209 else {
210 AliError("Branch T0 DIGIT not found");
211 return -1;
212 }
213 brDigits->GetEntry(0);
214
215 TArrayI qtc0(24); // Array must have 24 entries!
216 TArrayI qtc1(24); // Array must have 24 entries!
217
218 digits->GetQT0(qtc0); // baseline (reference level)
219 digits->GetQT1(qtc1); // measurement value
220
221 Int_t inputVector = 0x0; // vector to be fed into the look up table
222
223 // PMT Positions
224 // C: 0 to 11
225 // A: 12 to 23
226 // positions according to AliT0Digitizer.cxx Revision 37491
227 Int_t nStart = 0;
228 if (this->fPosition == kC) { // C
229 nStart = 0;
230 }
231 else if (this->fPosition == kA) { // A
232 nStart = 12;
233 }
234
235 Int_t channelBitMask = 0x01;
236 for (Int_t i = 0 + nStart; i < nStart + 12; i++) {
237 //Int_t channelBitMask = 0x01;
238 AliDebug(5, Form("channel: %d", i));
239
240 Int_t value = qtc1[i] - qtc0[i]; // calculate correct measurement value
241
242 if (value > (Int_t)this->fThreshold[i - nStart]) {
f9720615 243 inputVector |= channelBitMask; // Add bit
244
245 AliDebug(5, Form("Threshold exceeded in channel %d,", i));
246 AliDebug(5, Form("new inputVector 0x%x", inputVector));
247 AliDebug(5, Form("channelBitMask 0x%x", channelBitMask));
248 }
249 channelBitMask <<= 1; // go on to the next channel
250 }
251
f9720615 252 delete digits;
253 return inputVector;
254 }
255 return -1;
256}
257
258//______________________________________________________________________________
259Int_t AliTRDptrgFEB::LoadAndProcessHits()
260{
261 // loads TO or VO hits and converts them to digits optimized for ptrg
262 // afterwards the digits will be discriminated
263 AliError("LoadAndProcessHits() - not yet implemented!\n");
264 if (this->fType == kVZERO) {
265 return 0;
266 }
267 else if (this->fType == kTZERO) {
268 return 0;
269 }
270 return -1;
271}
272
273//______________________________________________________________________________
274Bool_t AliTRDptrgFEB::LoadParams()
275{
276 // Load Parameters
277
278 if (this->fParam == 0x0) {
279 AliWarning("No paramater object specified - start loading defaults\n");
280 if (this->fType == kVZERO) {
281 // initialize threshold
282 this->fThreshold = new UInt_t[8];
283 for (Int_t i = 0; i < 8; i++) {
e51605d9 284 this->fThreshold[i] = 10;
f9720615 285 }
286 // initialize LUTsoutputWidth=<value optimized out>
287 AliTRDptrgLUT* lut = new AliTRDptrgLUT();
288 this->fLUTArray.AddLast(lut);
289 lut = new AliTRDptrgLUT();
290 this->fLUTArray.AddLast(lut);
291 // the following lines are only needed for test reasons
292 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
293 Int_t* initData = new Int_t[256]; // 2^8
294 for (Int_t i = 0; i < 256; i++ ) {
295 initData[i] = i;
296 }
297 lut->InitTable(8, 8, initData, kTRUE); // make copy of initData
298 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
299 for (Int_t i = 255; i >= 0; i--) {
300 initData[255 - i] = i; // inverse ramp
301 }
302 lut->InitTable(8, 8, initData, kTRUE);
303 }
304 else {
305 // initialize threshold
306 this->fThreshold = new UInt_t[12];
307 for (Int_t i = 0; i < 12; i++) {
e51605d9 308 this->fThreshold[i] = 10;
f9720615 309 }
310
311 // initialize LUTsoutputWidth=<value optimized out>
312 AliTRDptrgLUT* lut = new AliTRDptrgLUT();
313 this->fLUTArray.AddLast(lut);
314 lut = new AliTRDptrgLUT(); // this->fRunLoader
315 this->fLUTArray.AddLast(lut);
316 // the following lines are only needed for test reasons
317 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
318 Int_t* initData = new Int_t[4096]; // 2^12
319 for (Int_t i = 0; i < 4096; i++ ) {
320 initData[i] = i;
321 }
322 lut->InitTable(12, 12, initData, kTRUE); // make a copy of the table
323 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
324 for (Int_t i = 4095; i >= 0; i--) {
325 initData[4096 - i] = i; // inverse ramp
326 }
327 lut->InitTable(12, 12, initData, kTRUE); // make a copy of the table
328 delete[] initData;
329 }
330 return false;
331 }
332 else {
333 // load parameters from object
334 if (this->fType == kVZERO) {
335 // threshold
336 this->fThreshold =
337 this->fParam->GetFEBV0Thresholds(this->fPosition, (this->fID - 1));
338
339 // look up tables
340 // 1
341 AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
342 LUT->InitTable(8, 8, this->fParam->GetFEBV0LUT(this->fPosition,
343 (this->fID - 1),
344 0), kFALSE);
345 // do not make a copy of the table due to performance reasons
346 this->fLUTArray.AddLast(LUT);
347
348 // 2
349 LUT = new AliTRDptrgLUT();
350 LUT->InitTable(8, 8, this->fParam->GetFEBV0LUT(this->fPosition,
351 (this->fID - 1),
352 1), kFALSE);
353 // do not make a copy of the table due to performance reasons
354 this->fLUTArray.AddLast(LUT);
355 }
356 else {
357 // threshold
358 this->fThreshold =
359 this->fParam->GetFEBT0Thresholds(this->fPosition);
360
361 // look up tables
362 // 1
363 AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
364 LUT->InitTable(12, 12, fParam->GetFEBT0LUT(this->fPosition, 0), kFALSE);
365 // do not make a copy of the table due to performance reasosn
366 this->fLUTArray.AddLast(LUT);
367
368 // 2
369 LUT = new AliTRDptrgLUT();
370 LUT->InitTable(12, 12, fParam->GetFEBT0LUT(this->fPosition, 1), kFALSE);
371 // do not make a copy of the table due to performance reasosn
372 this->fLUTArray.AddLast(LUT);
373 }
374 return true;
375 }
376
377 return false;
378}
379
380//______________________________________________________________________________
381Int_t* AliTRDptrgFEB::Simulate()
382{
383 // simulates the FEB behavior and returns a 2 bit ouput
384 // (least significant bits)
385
386 Int_t *result = new Int_t;
387 (*result) = -1;
388 if (this->fOperatingMode == kDigits) {
389 Int_t inputVector = this->LoadDigits();
390 delete result; // delete error return value
391
392 // perform look up
393 Int_t nLUTs = this->fLUTArray.GetEntriesFast(); // get LUT count
394 result = new Int_t[nLUTs + 1]; // generate new return array
395 result[0] = nLUTs; // storage array length in the first array value
396 for (Int_t iLUT = 0; iLUT < nLUTs; iLUT++) {
397 // process the return value for each LUT and store the result in the array
398 AliDebug(4, Form("FEB: (pos=%d,id=%d,lut=%d,vector=0x%x)",
399 this->fPosition, this->fID, iLUT, inputVector));
400
401 result[iLUT + 1] =
402 dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[iLUT])->LookUp(inputVector);
403 AliDebug(4, Form("FEB result[%d] = 0x%x",(iLUT + 1),result[iLUT + 1]));
404 }
405 }
406 else if (this->fOperatingMode == kHits) {
407 return result;
408 }
409 return result;
410}