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 "../T0/AliT0digit.h"
39 #include "AliTRDptrgParam.h"
40 #include "AliTRDptrgLUT.h"
41 #include "AliTRDptrgFEB.h"
43 ClassImp(AliTRDptrgFEB)
45 //______________________________________________________________________________
46 AliTRDptrgFEB::AliTRDptrgFEB(AliRunLoader *rl)
52 fOperatingMode(kDigits),
53 fInputChannelCount(0),
58 // default constructor
59 AliError("default ctor - not recommended");
62 //______________________________________________________________________________
63 AliTRDptrgFEB::AliTRDptrgFEB(AliRunLoader *rl, AliTRDptrgFEBType_t febType,
64 AliTRDptrgOperatingMode_t operatingMode,
65 AliTRDptrgFEBPosition_t position, Int_t id,
66 AliTRDptrgParam *param)
72 fOperatingMode(operatingMode),
73 fInputChannelCount(0),
78 // prefered constructor
80 this->LoadParams(); // load configuration parameters
84 //______________________________________________________________________________
85 AliTRDptrgFEB::~AliTRDptrgFEB()
88 if (this->fParam == 0x0) {
89 if (this->fThreshold != 0x0) {
90 delete[] this->fThreshold;
91 this->fThreshold = 0x0;
95 this->fLUTArray.Delete();
98 //______________________________________________________________________________
99 Int_t AliTRDptrgFEB::LoadDigits()
101 // loads T0 or V0 digits and discriminates them automatically
103 if (this->fType == kVZERO) {
104 // load V0's digits --------------------------------------------------------
107 AliLoader* loader = this->fRunLoader->GetLoader( "VZEROLoader" );
110 AliError("Can not get VZERO loader");
113 loader->LoadDigits("READ");
114 TTree* vzeroDigitsTree = loader->TreeD();
116 if (!vzeroDigitsTree) {
117 AliError("Can not get the VZERO digit tree");
122 TClonesArray* vzeroDigits = NULL;
123 TBranch* digitBranch = vzeroDigitsTree->GetBranch("VZERODigit");
124 digitBranch->SetAddress(&vzeroDigits);
125 vzeroDigitsTree->GetEvent(0);
128 Int_t nDigits = vzeroDigits->GetEntriesFast(); // get digit count
130 AliDebug(5, Form("Found a whole of %d digits", nDigits));
132 Int_t inputVector = 0x0; // Vector which is feed into the LUT
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);
139 Int_t pmNumber = digit->PMNumber();
140 Int_t board = pmNumber / 8;
141 Int_t channel = pmNumber % 8;
142 Int_t position = pmNumber / 32 + 1;
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");
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;
155 Form("Threshold exceeded in channel %d, new inputVector 0x%x",
156 channel, inputVector));
161 AliDebug(5, Form("inputVector: 0x%x", inputVector));
165 else if (this->fType == kTZERO) {
166 // load T0's digits --------------------------------------------------------
167 AliLoader * fT0Loader = this->fRunLoader->GetLoader("T0Loader");
168 // AliT0digit *fDigits;
169 fT0Loader->LoadDigits("READ");
170 // Creating T0 data container
172 TTree* treeD = fT0Loader->TreeD();
174 AliError("no digits tree");
177 AliT0digit* digits = new AliT0digit();
178 TBranch *brDigits = treeD->GetBranch("T0");
181 brDigits->SetAddress(&digits);
184 AliError("Branch T0 DIGIT not found");
187 brDigits->GetEntry(0);
189 TArrayI qtc0(24); // Array must have 24 entries!
190 TArrayI qtc1(24); // Array must have 24 entries!
192 digits->GetQT0(qtc0); // baseline (reference level)
193 digits->GetQT1(qtc1); // measurement value
195 Int_t inputVector = 0x0; // vector to be fed into the look up table
200 // positions according to AliT0Digitizer.cxx Revision 37491
202 if (this->fPosition == kC) { // C
205 else if (this->fPosition == kA) { // A
209 Int_t channelBitMask = 0x01;
210 for (Int_t i = 0 + nStart; i < nStart + 12; i++) {
211 //Int_t channelBitMask = 0x01;
212 AliDebug(5, Form("channel: %d", i));
214 Int_t value = qtc1[i] - qtc0[i]; // calculate correct measurement value
216 if (value > (Int_t)this->fThreshold[i - nStart]) {
217 inputVector |= channelBitMask; // Add bit
219 AliDebug(5, Form("Threshold exceeded in channel %d,", i));
220 AliDebug(5, Form("new inputVector 0x%x", inputVector));
221 AliDebug(5, Form("channelBitMask 0x%x", channelBitMask));
223 channelBitMask <<= 1; // go on to the next channel
232 //______________________________________________________________________________
233 Int_t AliTRDptrgFEB::LoadAndProcessHits()
235 // loads TO or VO hits and converts them to digits optimized for ptrg
236 // afterwards the digits will be discriminated
237 AliError("LoadAndProcessHits() - not yet implemented!\n");
238 if (this->fType == kVZERO) {
241 else if (this->fType == kTZERO) {
247 //______________________________________________________________________________
248 Bool_t AliTRDptrgFEB::LoadParams()
252 if (this->fParam == 0x0) {
253 AliWarning("No paramater object specified - start loading defaults\n");
254 if (this->fType == kVZERO) {
255 // initialize threshold
256 this->fThreshold = new UInt_t[8];
257 for (Int_t i = 0; i < 8; i++) {
258 this->fThreshold[i] = 10;
260 // initialize LUTsoutputWidth=<value optimized out>
261 AliTRDptrgLUT* lut = new AliTRDptrgLUT();
262 this->fLUTArray.AddLast(lut);
263 lut = new AliTRDptrgLUT();
264 this->fLUTArray.AddLast(lut);
265 // the following lines are only needed for test reasons
266 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
267 Int_t* initData = new Int_t[256]; // 2^8
268 for (Int_t i = 0; i < 256; i++ ) {
271 lut->InitTable(8, 8, initData, kTRUE); // make copy of initData
272 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
273 for (Int_t i = 255; i >= 0; i--) {
274 initData[255 - i] = i; // inverse ramp
276 lut->InitTable(8, 8, initData, kTRUE);
279 // initialize threshold
280 this->fThreshold = new UInt_t[12];
281 for (Int_t i = 0; i < 12; i++) {
282 this->fThreshold[i] = 10;
285 // initialize LUTsoutputWidth=<value optimized out>
286 AliTRDptrgLUT* lut = new AliTRDptrgLUT();
287 this->fLUTArray.AddLast(lut);
288 lut = new AliTRDptrgLUT(); // this->fRunLoader
289 this->fLUTArray.AddLast(lut);
290 // the following lines are only needed for test reasons
291 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
292 Int_t* initData = new Int_t[4096]; // 2^12
293 for (Int_t i = 0; i < 4096; i++ ) {
296 lut->InitTable(12, 12, initData, kTRUE); // make a copy of the table
297 lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
298 for (Int_t i = 4095; i >= 0; i--) {
299 initData[4096 - i] = i; // inverse ramp
301 lut->InitTable(12, 12, initData, kTRUE); // make a copy of the table
307 // load parameters from object
308 if (this->fType == kVZERO) {
311 this->fParam->GetFEBV0Thresholds(this->fPosition, (this->fID - 1));
315 AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
316 LUT->InitTable(8, 8, this->fParam->GetFEBV0LUT(this->fPosition,
319 // do not make a copy of the table due to performance reasons
320 this->fLUTArray.AddLast(LUT);
323 LUT = new AliTRDptrgLUT();
324 LUT->InitTable(8, 8, this->fParam->GetFEBV0LUT(this->fPosition,
327 // do not make a copy of the table due to performance reasons
328 this->fLUTArray.AddLast(LUT);
333 this->fParam->GetFEBT0Thresholds(this->fPosition);
337 AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
338 LUT->InitTable(12, 12, fParam->GetFEBT0LUT(this->fPosition, 0), kFALSE);
339 // do not make a copy of the table due to performance reasosn
340 this->fLUTArray.AddLast(LUT);
343 LUT = new AliTRDptrgLUT();
344 LUT->InitTable(12, 12, fParam->GetFEBT0LUT(this->fPosition, 1), kFALSE);
345 // do not make a copy of the table due to performance reasosn
346 this->fLUTArray.AddLast(LUT);
354 //______________________________________________________________________________
355 Int_t* AliTRDptrgFEB::Simulate()
357 // simulates the FEB behavior and returns a 2 bit ouput
358 // (least significant bits)
360 Int_t *result = new Int_t;
362 if (this->fOperatingMode == kDigits) {
363 Int_t inputVector = this->LoadDigits();
364 delete result; // delete error return value
367 Int_t nLUTs = this->fLUTArray.GetEntriesFast(); // get LUT count
368 result = new Int_t[nLUTs + 1]; // generate new return array
369 result[0] = nLUTs; // storage array length in the first array value
370 for (Int_t iLUT = 0; iLUT < nLUTs; iLUT++) {
371 // process the return value for each LUT and store the result in the array
372 AliDebug(4, Form("FEB: (pos=%d,id=%d,lut=%d,vector=0x%x)",
373 this->fPosition, this->fID, iLUT, inputVector));
376 dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[iLUT])->LookUp(inputVector);
377 AliDebug(4, Form("FEB result[%d] = 0x%x",(iLUT + 1),result[iLUT + 1]));
380 else if (this->fOperatingMode == kHits) {