]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDptrgCBB.cxx
re-activate contrib code
[u/mrichter/AliRoot.git] / TRD / AliTRDptrgCBB.cxx
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 Control-Box bottom class                                  //
21 //                                                                        //
22 //  Authors: F. Reidt (Felix.Reidt@cern.ch)                               //
23 //                                                                        //
24 ////////////////////////////////////////////////////////////////////////////
25
26
27 #include "TROOT.h"
28
29 #include "AliRun.h"
30 #include "AliRunLoader.h"
31
32 #include "AliTRDptrgLUT.h"
33 #include "AliTRDptrgParam.h"
34 #include "AliTRDptrgCBAC.h"
35 #include "AliTRDptrgTLMU.h"
36 #include "AliTRDptrgCBB.h"
37 #include "AliLog.h"
38 ClassImp(AliTRDptrgCBB)
39
40 AliTRDptrgCBB::AliTRDptrgCBB(AliRunLoader *rl) 
41   : TObject(),
42   fRunLoader(rl),
43   fParam(0),
44   fOperatingMode(AliTRDptrgParam::kDigits),
45   fCBA(0),
46   fCBC(0),
47   fTLMU(0),
48   fLUTArray(0),
49   fPTmasks(0x0)
50 {
51   // default ctor
52   AliError("default ctor - usage not recommended\n");
53 }
54
55
56 AliTRDptrgCBB::AliTRDptrgCBB(AliRunLoader *rl, AliTRDptrgParam* param, 
57                              AliTRDptrgParam::AliTRDptrgOperatingMode_t operatingMode)
58   : TObject(),
59   fRunLoader(rl),
60   fParam(param),
61   fOperatingMode(operatingMode),
62   fCBA(0),
63   fCBC(0),
64   fTLMU(0),
65   fLUTArray(0),
66   fPTmasks(0x0) 
67 {
68   // recommended ctor
69   this->fCBA = new AliTRDptrgCBAC(rl, AliTRDptrgParam::kA, operatingMode, param);
70   this->fCBC = new AliTRDptrgCBAC(rl, AliTRDptrgParam::kC, operatingMode, param);
71   this->fTLMU = new AliTRDptrgTLMU(rl, param, operatingMode);
72
73   this->LoadParams();
74 }
75
76 AliTRDptrgCBB::~AliTRDptrgCBB() 
77 {
78   // destructor
79
80   if (this->fCBA != 0x0) {
81     delete this->fCBA;
82     this->fCBA = 0x0;
83   }
84
85   if (this->fCBC != 0x0) {
86     delete this->fCBC;
87     this->fCBC = 0x0;
88   }
89
90   if (this->fTLMU != 0x0) {
91     delete this->fTLMU;
92     this->fTLMU = 0x0;
93   }
94
95   this->fLUTArray.Delete();
96 }
97
98
99 //______________________________________________________________________________
100 Bool_t AliTRDptrgCBB::LoadParams() 
101 {
102   // load configuration parameters
103
104   if (this->fParam != 0x0) {
105     // read AliTRDptrgParam
106     
107     // get LUTs
108     // 0
109     AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
110     LUT->InitTable(12, 12, this->fParam->GetCBLUT(0, 0), kFALSE);
111     // get CB-B_0 and do not copy lut content
112     this->fLUTArray.AddLast(LUT);
113  
114     // 1
115     LUT = new AliTRDptrgLUT();
116     LUT->InitTable(12, 12, this->fParam->GetCBLUT(0, 1), kFALSE);
117     // get CB-B_1 and do not copy lut content
118     this->fLUTArray.AddLast(LUT);
119
120     // 2
121     LUT = new AliTRDptrgLUT();
122     LUT->InitTable(12, 12, this->fParam->GetCBLUT(0, 2), kFALSE);
123     // get CB-B_2 and do not copy lut content
124     this->fLUTArray.AddLast(LUT);
125
126     // masks
127     this->fPTmasks = this->fParam->GetPTmasks();
128   }
129   else {
130     // load default parameters 
131     // initialize LUTsoutputWidth=<value optimized out>
132     AliTRDptrgLUT* lut = new AliTRDptrgLUT();
133     this->fLUTArray.AddLast(lut);
134     lut = new AliTRDptrgLUT(); // this->fRunLoader
135     this->fLUTArray.AddLast(lut);
136     lut = new AliTRDptrgLUT(); // this->fRunLoader
137     this->fLUTArray.AddLast(lut);
138     // the following lines are only needed for test reasons
139     Int_t* initData = new Int_t[4096]; // 2^12
140     lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
141     if (lut) {
142       for (Int_t i = 0; i < 4096; i++ ) {
143         initData[i] = i;
144       }
145       lut->InitTable(12, 12, initData, kTRUE); // make a copy
146     }
147     lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
148     if (lut) {
149       for (Int_t i = 0; i < 4096; i++ ) {
150         initData[i] = i;
151       }
152       lut->InitTable(12, 12, initData, kTRUE); // make a copy
153     }
154     lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
155     if (lut) {
156       //for (Int_t i = 4096; i >= 0; i--) {
157       for (Int_t i = 4096; i > 0; i--) {
158         initData[4096 - i] = i;  // inverse ramp
159       }
160       lut->InitTable(12, 12, initData, kTRUE); // make a copy 
161     }
162     delete [] initData;
163
164     AliTRDptrgParam::AliTRDptrgPTmasks* masks = 
165       new AliTRDptrgParam::AliTRDptrgPTmasks();  
166     masks->fLUTs[0] = kTRUE;
167     masks->fLUTs[1] = kTRUE;
168     masks->fLUTs[2] = kTRUE;
169     this->fPTmasks = masks;
170   }  
171   return false;
172 }
173
174 //______________________________________________________________________________
175 Int_t* AliTRDptrgCBB::Simulate()
176
177   // Simulate the CBB behavior of event
178   //
179   // returns array containing:
180   // 0: array element count
181   // 1..count-2: LUT results
182   // count-1: pretrigger decision
183
184   Int_t nLUTs = this->fLUTArray.GetEntries();
185
186   Int_t inputVector = 0x0;
187   // initialize partResults
188   Int_t** partResults = 0x0;  
189   partResults = new Int_t* [3]; // CB-A, CB-C, TLMU
190  
191   // get partResults
192   partResults[0] = this->fCBA->Simulate(); // CB-A
193   partResults[1] = this->fCBC->Simulate(); // CB-C
194   partResults[2] = this->fTLMU->Simulate(); // TLMU
195   
196   // combine partResults and create inputVectors  
197   Int_t mask = 0x1;
198   for (Int_t i = 0; i < 3 ; i++) {
199     for (Int_t j = 1; j <= partResults[i][0]; j++) {
200       if (partResults[i][j] > 0) {
201         inputVector |= mask; // Add bit to the  inputVector
202       }
203       mask <<= 1;
204     }
205   }
206   
207   AliDebug(5, Form("Inputvectors: 0x%x", inputVector));
208     
209   // perform look up
210   Int_t* result = new Int_t[nLUTs + 2]; // generate new return array
211   result[0] = nLUTs + 1; // storage array length in the first array value
212   for (Int_t iLUT = 0; iLUT < nLUTs; iLUT++) { 
213     // process the return value for each LUT and store the result in the array
214     AliTRDptrgLUT *lutTmp = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[iLUT]);
215     if (lutTmp) {
216       result[iLUT + 1] = lutTmp->LookUp(inputVector);
217     }
218     AliDebug(4, Form("CBB result[%d] = 0x%x\n",(iLUT + 1),result[iLUT + 1])); 
219   }
220   
221   // evaluate PT decision
222   // stored in result[nLUTs + 1]
223   result[nLUTs + 1] = 0;
224
225   for (Int_t i = 0; i < 2; i++) {
226     // CB-A
227     if (this->fPTmasks->fCBA[i] && partResults[0][i + 1]) {
228       result[nLUTs + 1]++;
229     }
230     // CB-C
231     if (this->fPTmasks->fCBC[i] && partResults[1][i + 1]) {
232       result[nLUTs + 1]++;
233     }
234     // CB-B (own LUTs)
235     if (this->fPTmasks->fLUTs[i] && result[i + 1]) {
236       result[nLUTs + 1]++;
237     }       
238   }
239   if (this->fPTmasks->fLUTs[2] && result[3]) { // CB-B (third own LUT)
240     result[nLUTs + 1]++;
241   }
242
243   // TLMU
244   for (Int_t i = 0; i < 8; i++) {
245     if (this->fPTmasks->fTLMU[i] && partResults[2][i + 1]) {
246       result[nLUTs + 1]++;
247     }
248   }
249   AliDebug(4, Form("CBB TRD Wake up result = %d", result[nLUTs + 1]));
250
251   delete [] partResults;
252
253   return result;
254
255 }
256
257 //______________________________________________________________________________
258 Bool_t AliTRDptrgCBB::GetPT() {
259   // evaluates the pre trigger decision
260
261   Int_t* LUTresults = this->Simulate();
262   if (LUTresults[(LUTresults[0] - 1)]) {
263     delete[] LUTresults;
264     return kTRUE;
265   }
266   else {
267     delete[] LUTresults;
268     return kFALSE;
269   }
270 }