1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // Pre-Trigger simulation
22 // Authors: F. Reidt (Felix.Reidt@cern.ch)
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
29 ////////////////////////////////////////////////////////////////////////////
31 #include <TClonesArray.h>
33 #include "AliRunLoader.h"
36 #include "../VZERO/AliVZEROdigit.h"
37 #include "../VZERO/AliVZEROCalibData.h"
38 #include "../T0/AliT0digit.h"
40 #include "AliTRDptrgParam.h"
41 #include "AliTRDptrgLUT.h"
42 #include "AliTRDptrgFEB.h"
44 ClassImp(AliTRDptrgFEB)
46 //______________________________________________________________________________
47 AliTRDptrgFEB::AliTRDptrgFEB(AliRunLoader *rl)
53 fOperatingMode(kDigits),
54 fInputChannelCount(0),
59 // default constructor
60 AliError("default ctor - not recommended");
63 //______________________________________________________________________________
64 AliTRDptrgFEB::AliTRDptrgFEB(AliRunLoader *rl, AliTRDptrgFEBType_t febType,
65 AliTRDptrgOperatingMode_t operatingMode,
66 AliTRDptrgFEBPosition_t position, Int_t id,
67 AliTRDptrgParam *param)
73 fOperatingMode(operatingMode),
74 fInputChannelCount(0),
79 // prefered constructor
81 this->LoadParams(); // load configuration parameters
85 //______________________________________________________________________________
86 AliTRDptrgFEB::~AliTRDptrgFEB()
89 if (this->fParam == 0x0) {
90 if (this->fThreshold != 0x0) {
91 delete[] this->fThreshold;
92 this->fThreshold = 0x0;
96 this->fLUTArray.Delete();
99 //______________________________________________________________________________
100 Int_t AliTRDptrgFEB::LoadDigits()
102 // loads T0 or V0 digits and discriminates them automatically
104 if (this->fType == kVZERO) {
105 // load V0's digits --------------------------------------------------------
106 // behavior adapted for AliVZERODigitizer.cxx 40613 2010-04-22 09:57:15Z
109 AliLoader* loader = this->fRunLoader->GetLoader( "VZEROLoader" );
112 AliError("Cannot get VZERO loader");
115 loader->LoadDigits("READ");
116 TTree* vzeroDigitsTree = loader->TreeD();
118 if (!vzeroDigitsTree) {
119 AliError("Cannot get the VZERO digit tree");
124 TClonesArray* vzeroDigits = NULL;
125 TBranch* digitBranch = vzeroDigitsTree->GetBranch("VZERODigit");
126 digitBranch->SetAddress(&vzeroDigits);
127 vzeroDigitsTree->GetEvent(0);
130 Int_t nDigits = vzeroDigits->GetEntriesFast(); // get digit count
132 AliDebug(5, Form("Found a whole of %d digits", nDigits));
134 Int_t inputVector = 0x0; // Vector which is feed into the LUT
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);
141 Int_t pmNumber = digit->PMNumber();
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
146 Int_t channel = pmNumber % 8;
149 if ((pmNumber >= 32) && (pmNumber <= 63)) { // V0-A (matched v40613)
152 else if ((pmNumber >= 0) && (pmNumber <= 31)) { // V0-C (matched v40613)
157 Form("pmNumber: %d; feeBoard: %d; board: %d; channel: %d; position %d",
158 pmNumber, feeBoard, board, channel, position));
160 if (position == -1) {
161 AliError("Wrong VZERO pmt position found");
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");
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;
176 Form("Threshold exceeded in channel %d, new inputVector 0x%x",
177 channel, inputVector));
182 AliDebug(5, Form("inputVector: 0x%x", inputVector));
186 else if (this->fType == kTZERO) {
187 // load T0's digits --------------------------------------------------------
188 AliLoader * fT0Loader = this->fRunLoader->GetLoader("T0Loader");
189 // AliT0digit *fDigits;
191 AliError("Cannot get T0 loader");
195 fT0Loader->LoadDigits("READ");
196 // Creating T0 data container
198 TTree* treeD = fT0Loader->TreeD();
200 AliError("no digits tree");
203 AliT0digit* digits = new AliT0digit();
204 TBranch *brDigits = treeD->GetBranch("T0");
207 brDigits->SetAddress(&digits);
210 AliError("Branch T0 DIGIT not found");
213 brDigits->GetEntry(0);
215 TArrayI qtc0(24); // Array must have 24 entries!
216 TArrayI qtc1(24); // Array must have 24 entries!
218 digits->GetQT0(qtc0); // baseline (reference level)
219 digits->GetQT1(qtc1); // measurement value
221 Int_t inputVector = 0x0; // vector to be fed into the look up table
226 // positions according to AliT0Digitizer.cxx Revision 37491
228 if (this->fPosition == kC) { // C
231 else if (this->fPosition == kA) { // A
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));
240 Int_t value = qtc1[i] - qtc0[i]; // calculate correct measurement value
242 if (value > (Int_t)this->fThreshold[i - nStart]) {
243 inputVector |= channelBitMask; // Add bit
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));
249 channelBitMask <<= 1; // go on to the next channel
258 //______________________________________________________________________________
259 Int_t AliTRDptrgFEB::LoadAndProcessHits()
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) {
267 else if (this->fType == kTZERO) {
273 //______________________________________________________________________________
274 Bool_t AliTRDptrgFEB::LoadParams()
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++) {
284 this->fThreshold[i] = 10;
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++ ) {
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
302 lut->InitTable(8, 8, initData, kTRUE);
305 // initialize threshold
306 this->fThreshold = new UInt_t[12];
307 for (Int_t i = 0; i < 12; i++) {
308 this->fThreshold[i] = 10;
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++ ) {
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
327 lut->InitTable(12, 12, initData, kTRUE); // make a copy of the table
333 // load parameters from object
334 if (this->fType == kVZERO) {
337 this->fParam->GetFEBV0Thresholds(this->fPosition, (this->fID - 1));
341 AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
342 LUT->InitTable(8, 8, this->fParam->GetFEBV0LUT(this->fPosition,
345 // do not make a copy of the table due to performance reasons
346 this->fLUTArray.AddLast(LUT);
349 LUT = new AliTRDptrgLUT();
350 LUT->InitTable(8, 8, this->fParam->GetFEBV0LUT(this->fPosition,
353 // do not make a copy of the table due to performance reasons
354 this->fLUTArray.AddLast(LUT);
359 this->fParam->GetFEBT0Thresholds(this->fPosition);
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);
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);
380 //______________________________________________________________________________
381 Int_t* AliTRDptrgFEB::Simulate()
383 // simulates the FEB behavior and returns a 2 bit ouput
384 // (least significant bits)
386 Int_t *result = new Int_t;
388 if (this->fOperatingMode == kDigits) {
389 Int_t inputVector = this->LoadDigits();
390 delete result; // delete error return value
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));
402 dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[iLUT])->LookUp(inputVector);
403 AliDebug(4, Form("FEB result[%d] = 0x%x",(iLUT + 1),result[iLUT + 1]));
406 else if (this->fOperatingMode == kHits) {