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