]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDptrgFEB.cxx
TRD pretrigger simulation based on digits of T0, V0 and TOF, simulation control is...
[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"
37#include "../T0/AliT0digit.h"
38
39#include "AliTRDptrgParam.h"
40#include "AliTRDptrgLUT.h"
41#include "AliTRDptrgFEB.h"
42
43ClassImp(AliTRDptrgFEB)
44
45//______________________________________________________________________________
46AliTRDptrgFEB::AliTRDptrgFEB(AliRunLoader *rl)
47 : TObject(),
48 fRunLoader(rl),
49 fParam(0),
50 fLUTArray(0),
51 fType(kUndefined),
52 fOperatingMode(kDigits),
53 fInputChannelCount(0),
54 fPosition(kUnknown),
55 fID(0),
56 fThreshold(0)
57{
58 // default constructor
59 AliWarning("default ctor - not recommended");
60}
61
62//______________________________________________________________________________
63AliTRDptrgFEB::AliTRDptrgFEB(AliRunLoader *rl, AliTRDptrgFEBType_t febType,
64 AliTRDptrgOperatingMode_t operatingMode,
65 AliTRDptrgFEBPosition_t position, Int_t id,
66 AliTRDptrgParam *param)
67 : TObject(),
68 fRunLoader(rl),
69 fParam(param),
70 fLUTArray(0),
71 fType(febType),
72 fOperatingMode(operatingMode),
73 fInputChannelCount(0),
74 fPosition(position),
75 fID(id),
76 fThreshold(0x0)
77{
78 // prefered constructor
79
80 this->LoadParams(); // load configuration parameters
81
82}
83
84//______________________________________________________________________________
85AliTRDptrgFEB::~AliTRDptrgFEB()
86{
87 // destructor
88 if (this->fParam == 0x0) {
89 if (this->fThreshold != 0x0) {
90 delete[] this->fThreshold;
91 this->fThreshold = 0x0;
92 }
93 }
94 // delete LUTArray
95 this->fLUTArray.Delete();
96}
97
98//______________________________________________________________________________
99Int_t AliTRDptrgFEB::LoadDigits()
100{
101 // loads T0 or V0 digits and discriminates them automatically
102
103 if (this->fType == kVZERO) {
104 // load V0's digits --------------------------------------------------------
105
106 // get V0 run loader
107 AliLoader* loader = fRunLoader->GetLoader( "VZEROLoader" );
108
109 if (!loader) {
110 AliError("Can not get VZERO loader");
111 return -1;
112 }
113 loader->LoadDigits("READ");
114 TTree* vzeroDigitsTree = loader->TreeD();
115
116 if (!vzeroDigitsTree) {
117 AliError("Can not get the VZERO digit tree");
118 return -1;
119 }
120
121
122 TClonesArray* vzeroDigits = NULL;
123 TBranch* digitBranch = vzeroDigitsTree->GetBranch("VZERODigit");
124 digitBranch->SetAddress(&vzeroDigits);
125 vzeroDigitsTree->GetEvent(0);
126 //digitBranch->GetEvent(event);
127
128 AliDebug(5, Form("Number of Events: %d",
129 this->fRunLoader->GetNumberOfEvents()));
130
131
132 Int_t nDigits = vzeroDigits->GetEntriesFast(); // get digit count
133
134 AliDebug(5, Form("Found a whole of %d digits", nDigits));
135
136 Int_t inputVector = 0x0; // Vector which is feed into the LUT
137
138 for (Int_t iDigit=0; iDigit<nDigits; iDigit++) {
139 // loop over all digits
140 AliDebug(5, "Looping over digit");
141 AliVZEROdigit* digit = (AliVZEROdigit*)vzeroDigits->At(iDigit);
142
143 Int_t pmNumber = digit->PMNumber();
144 // TODO check the assignment of the photomultipliers to the FEBs
145 Int_t board = pmNumber / 8;\r
146 Int_t channel = pmNumber % 8;
147 Int_t position = pmNumber / 32 + 1;
148
149 // check whether the digits belongs to the current FEB, otherwise omit it
150 if ((position == this->fPosition) && (board == this->fID)) {
151 AliDebug(5, "Found an digit corresponding to the current FEB");
152 //if in timing window? // TODO
153 Float_t value = digit->ADC();
154 AliDebug(5, Form("ADC value: %f\n", value));
155 Int_t channelBitMask = 0x01;
156 // channel0 => 0x01; channel1=> 0x02; 2^(channel number)
157 channelBitMask <<= channel;
158 if (value >= this->fThreshold[channel]) {
159 inputVector |= channelBitMask;
160 AliDebug(5,
161 Form("Threshold exceeded in channel %d, new inputVector 0x%x",
162 channel, inputVector));
163 }
164 }
165 }
166
167 AliDebug(5, Form("inputVector: 0x%x", inputVector));
168
169 return inputVector;
170 }
171 else if (this->fType == kTZERO) {
172 // load T0's digits --------------------------------------------------------
173 AliLoader * fT0Loader = this->fRunLoader->GetLoader("T0Loader");
174 // AliT0digit *fDigits;
175 fT0Loader->LoadDigits("READ");
176 // Creating T0 data container
177
178 TTree* treeD = fT0Loader->TreeD();
179 if (!treeD) {
180 AliError("no digits tree");
181 return -1;
182 }
183 AliT0digit* digits = new AliT0digit();
184 TBranch *brDigits = treeD->GetBranch("T0");
185
186 if (brDigits) {
187 brDigits->SetAddress(&digits);
188 }
189 else {
190 AliError("Branch T0 DIGIT not found");
191 return -1;
192 }
193 brDigits->GetEntry(0);
194
195 TArrayI qtc0(24); // Array must have 24 entries!
196 TArrayI qtc1(24); // Array must have 24 entries!
197
198 digits->GetQT0(qtc0); // baseline (reference level)
199 digits->GetQT1(qtc1); // measurement value
200
201 Int_t inputVector = 0x0; // vector to be fed into the look up table
202
203 // PMT Positions
204 // C: 0 to 11
205 // A: 12 to 23
206 // positions according to AliT0Digitizer.cxx Revision 37491
207 Int_t nStart = 0;
208 if (this->fPosition == kC) { // C
209 nStart = 0;
210 }
211 else if (this->fPosition == kA) { // A
212 nStart = 12;
213 }
214
215 Int_t channelBitMask = 0x01;
216 for (Int_t i = 0 + nStart; i < nStart + 12; i++) {
217 //Int_t channelBitMask = 0x01;
218 AliDebug(5, Form("channel: %d", i));
219
220 Int_t value = qtc1[i] - qtc0[i]; // calculate correct measurement value
221
222 if (value > (Int_t)this->fThreshold[i - nStart]) {
223 // channelBitMask <<= 1; //(i - nStart); // 2^(i - nStart) ERROR? TODO
224 inputVector |= channelBitMask; // Add bit
225
226 AliDebug(5, Form("Threshold exceeded in channel %d,", i));
227 AliDebug(5, Form("new inputVector 0x%x", inputVector));
228 AliDebug(5, Form("channelBitMask 0x%x", channelBitMask));
229 }
230 channelBitMask <<= 1; // go on to the next channel
231 }
232
233 // TODO check whether it is correct to delete the digit
234 delete digits;
235 return inputVector;
236 }
237 return -1;
238}
239
240//______________________________________________________________________________
241Int_t AliTRDptrgFEB::LoadAndProcessHits()
242{
243 // loads TO or VO hits and converts them to digits optimized for ptrg
244 // afterwards the digits will be discriminated
245 AliError("LoadAndProcessHits() - not yet implemented!\n");
246 if (this->fType == kVZERO) {
247 return 0;
248 }
249 else if (this->fType == kTZERO) {
250 return 0;
251 }
252 return -1;
253}
254
255//______________________________________________________________________________
256Bool_t AliTRDptrgFEB::LoadParams()
257{
258 // Load Parameters
259
260 if (this->fParam == 0x0) {
261 AliWarning("No paramater object specified - start loading defaults\n");
262 if (this->fType == kVZERO) {
263 // initialize threshold
264 this->fThreshold = new UInt_t[8];
265 for (Int_t i = 0; i < 8; i++) {
266 this->fThreshold[i] = 10; // TODO choose a correct value
267 }
268 // initialize LUTsoutputWidth=<value optimized out>
269 AliTRDptrgLUT* lut = new AliTRDptrgLUT();
270 this->fLUTArray.AddLast(lut);
271 lut = new AliTRDptrgLUT();
272 this->fLUTArray.AddLast(lut);
273 // the following lines are only needed for test reasons
274 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
275 Int_t* initData = new Int_t[256]; // 2^8
276 for (Int_t i = 0; i < 256; i++ ) {
277 initData[i] = i;
278 }
279 lut->InitTable(8, 8, initData, kTRUE); // make copy of initData
280 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
281 for (Int_t i = 255; i >= 0; i--) {
282 initData[255 - i] = i; // inverse ramp
283 }
284 lut->InitTable(8, 8, initData, kTRUE);
285 }
286 else {
287 // initialize threshold
288 this->fThreshold = new UInt_t[12];
289 for (Int_t i = 0; i < 12; i++) {
290 this->fThreshold[i] = 10; // TODO choose a correct value
291 }
292
293 // initialize LUTsoutputWidth=<value optimized out>
294 AliTRDptrgLUT* lut = new AliTRDptrgLUT();
295 this->fLUTArray.AddLast(lut);
296 lut = new AliTRDptrgLUT(); // this->fRunLoader
297 this->fLUTArray.AddLast(lut);
298 // the following lines are only needed for test reasons
299 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
300 Int_t* initData = new Int_t[4096]; // 2^12
301 for (Int_t i = 0; i < 4096; i++ ) {
302 initData[i] = i;
303 }
304 lut->InitTable(12, 12, initData, kTRUE); // make a copy of the table
305 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
306 for (Int_t i = 4095; i >= 0; i--) {
307 initData[4096 - i] = i; // inverse ramp
308 }
309 lut->InitTable(12, 12, initData, kTRUE); // make a copy of the table
310 delete[] initData;
311 }
312 return false;
313 }
314 else {
315 // load parameters from object
316 if (this->fType == kVZERO) {
317 // threshold
318 this->fThreshold =
319 this->fParam->GetFEBV0Thresholds(this->fPosition, (this->fID - 1));
320
321 // look up tables
322 // 1
323 AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
324 LUT->InitTable(8, 8, this->fParam->GetFEBV0LUT(this->fPosition,
325 (this->fID - 1),
326 0), kFALSE);
327 // do not make a copy of the table due to performance reasons
328 this->fLUTArray.AddLast(LUT);
329
330 // 2
331 LUT = new AliTRDptrgLUT();
332 LUT->InitTable(8, 8, this->fParam->GetFEBV0LUT(this->fPosition,
333 (this->fID - 1),
334 1), kFALSE);
335 // do not make a copy of the table due to performance reasons
336 this->fLUTArray.AddLast(LUT);
337 }
338 else {
339 // threshold
340 this->fThreshold =
341 this->fParam->GetFEBT0Thresholds(this->fPosition);
342
343 // look up tables
344 // 1
345 AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
346 LUT->InitTable(12, 12, fParam->GetFEBT0LUT(this->fPosition, 0), kFALSE);
347 // do not make a copy of the table due to performance reasosn
348 this->fLUTArray.AddLast(LUT);
349
350 // 2
351 LUT = new AliTRDptrgLUT();
352 LUT->InitTable(12, 12, fParam->GetFEBT0LUT(this->fPosition, 1), kFALSE);
353 // do not make a copy of the table due to performance reasosn
354 this->fLUTArray.AddLast(LUT);
355 }
356 return true;
357 }
358
359 return false;
360}
361
362//______________________________________________________________________________
363Int_t* AliTRDptrgFEB::Simulate()
364{
365 // simulates the FEB behavior and returns a 2 bit ouput
366 // (least significant bits)
367
368 Int_t *result = new Int_t;
369 (*result) = -1;
370 if (this->fOperatingMode == kDigits) {
371 Int_t inputVector = this->LoadDigits();
372 delete result; // delete error return value
373
374 // perform look up
375 Int_t nLUTs = this->fLUTArray.GetEntriesFast(); // get LUT count
376 result = new Int_t[nLUTs + 1]; // generate new return array
377 result[0] = nLUTs; // storage array length in the first array value
378 for (Int_t iLUT = 0; iLUT < nLUTs; iLUT++) {
379 // process the return value for each LUT and store the result in the array
380 AliDebug(4, Form("FEB: (pos=%d,id=%d,lut=%d,vector=0x%x)",
381 this->fPosition, this->fID, iLUT, inputVector));
382
383 result[iLUT + 1] =
384 dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[iLUT])->LookUp(inputVector);
385 AliDebug(4, Form("FEB result[%d] = 0x%x",(iLUT + 1),result[iLUT + 1]));
386 }
387 }
388 else if (this->fOperatingMode == kHits) {
389 return result;
390 }
391 return result;
392}