Obsolete classes removed.
[u/mrichter/AliRoot.git] / TRD / AliTRDptrgTLMU.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////////////////////////////////////////////////////////////////////////////
25
26#include "TFile.h"
27#include "TROOT.h"
28
29#include "TClonesArray.h"
30
31#include "AliRun.h"
32#include "AliRunLoader.h"
33
34#include "../TOF/AliTOFdigit.h"
35#include "../RAW/AliRawReader.h" // needed for AliTOFTrigger's raw digit support
36#include "../TOF/AliTOFTrigger.h"
37
38#include "AliTRDptrgParam.h"
39
40#include "AliTRDptrgTLMU.h"
41
42ClassImp(AliTRDptrgTLMU)
43
44//______________________________________________________________________________
45AliTRDptrgTLMU::AliTRDptrgTLMU(AliRunLoader *rl)
46 : TObject(),
47 fRunLoader(rl),
48 fParam(0x0),
49 fOperatingMode(kDigits),
50 fInputMask(0x0),
51 fCMatrices(0x0),
52 fMultiplicity(0x0),
53 fOutput(0x0)
54{
55 // default ctor
56
57 for (Int_t i = 0; i < 18; i++) {
58 this->fInputTOFinputBits[i] = 0;
59 }
60}
61
62//______________________________________________________________________________
63AliTRDptrgTLMU::AliTRDptrgTLMU(AliRunLoader *rl, AliTRDptrgParam *param,
64 AliTRDptrgOperatingMode_t operatingMode)
65 : TObject(),
66 fRunLoader(rl),
67 fParam(param),
68 fOperatingMode(operatingMode),
69 fInputMask(0x0),
70 fCMatrices(0x0),
71 fMultiplicity(0x0),
72 fOutput(0x0)
73{
74 // recommended ctor
75
76 for (Int_t i = 0; i < 18; i++) {
77 this->fInputTOFinputBits[i] = 0;
78 }
79
80 this->LoadParams();
81}
82
83//______________________________________________________________________________
84AliTRDptrgTLMU::~AliTRDptrgTLMU()
85{
86 // destructor
87
88 this->fCMatrices = 0x0;
89 this->fMultiplicity = 0x0;
90 this->fOutput = 0x0;
91}
92
93//______________________________________________________________________________
94Int_t* AliTRDptrgTLMU::Simulate()
95{
96 // starts a simulation
97
98 if (this->fOperatingMode == kDigits) {
99 this->LoadDigits();
100 }
101 else if (this->fOperatingMode == kHits) {
102 return 0x0; // TODO
103 }
104
105 // which super modules are active? - needed for fast coincidence processing:
106 // M(sm | coincidence condition)>=2
107 UInt_t temp = 0x1;
108 UInt_t sm = 0x0;
109 for (Int_t iSM = 0; iSM < 18; iSM++) {
110 if (this->Or(iSM)) {
111 sm |= temp;
112 }
113 temp <<= 1;
114 }
115 AliDebug(4, Form("Active supermodules: 0x%x", sm));
116
117 // get multiplicity
118 UInt_t multiplicity = this->GetMultiplicitySum();
119 AliDebug(4, Form("TOF/TLMU multiplicity: %d", multiplicity));
120
121 Int_t* result = new Int_t[9];
122 result[0] = 8;
123 for (Int_t iResult = 0; iResult < 8; iResult++) {
124 result[iResult + 1] = 0;
125
126 // coincidence matrix
127 if (this->fOutput[iResult][0] != -1) {
128 for (Int_t iLine = 0; iLine < 18; iLine++) {
129 if (this->GetBitVectorMultiplicity(
130 sm | this->fCMatrices[this->fOutput[iResult][0]][iLine]) > 1) {
131 result[iResult + 1] = 1;
132 break;
133 }
134 }
135 }
136
137 // multiplicity conditions
138 if (this->fOutput[iResult][1] != -1) {
139 AliDebug(5, Form("Entry %d, slice: %d", iResult,
140 this->fOutput[iResult][1]));
141 if ((this->fMultiplicity[this->fOutput[iResult][1]][0] < multiplicity) &&
142 (this->fMultiplicity[this->fOutput[iResult][1]][1] >= multiplicity)) {
143 result[iResult + 1] = 1;
144 }
145 }
146 AliDebug(4, Form("TLMU result[%d] = %d", iResult, result[iResult + 1]));
147 }
148
149 return result;
150}
151
152//______________________________________________________________________________
153Int_t AliTRDptrgTLMU::LoadDigits()
154{
155 // loads Digits (for usage with aquired data)
156 this->GetInputBits(); // get bits from AliTOFTrigger
157 return 0;
158}
159
160
161//______________________________________________________________________________
162Bool_t AliTRDptrgTLMU::LoadParams()
163{
164 // load AliTRDprtgParam content
165
166 if (this->fParam == 0x0) {
167 // no parameter object assigned
168 AliWarning("no parameter object assigned - using default settings!");
169
170 AliError("no default settings available!");
171 // TODO
172 }
173 else {
174 // parameter object assigned
175
176 this->fInputMask = this->fParam->GetTLMUInputMask();
177 // input mask for TOF-bits (18x32=576)
178
179 this->fCMatrices = this->fParam->GetTLMUcmatrices();
180 // get coincidence matrices
181
182 this->fMultiplicity = this->fParam->GetTLMUmultiplicity();
183 // get multiplicity slices
184
185 this->fOutput = this->fParam->GetTLMUoutput();
186 // get output signal assignment
187 }
188
189 return false;
190}
191
192//______________________________________________________________________________
193void AliTRDptrgTLMU::GetInputBits() {
194 // Gets TOF-to-TRD input bits from AliTOFTrigger as Bool_t array
195
196 AliTOFTrigger *toftrig = new AliTOFTrigger(); // create AliTOFTrigger
197 toftrig->CreateLTMMatrixFromDigits(); // Generate LTMMatrix from AliTOFdigits
198
199 // prepare map
200 Bool_t** map = 0x0;
201 map = new Bool_t*[72];
202 for (Int_t i=0; i < 72; i++)
203 map[i] = new Bool_t[8];
204
205 // initialise map
206 for (Int_t i=0; i < 72; i++)
207 for (Int_t j=0; j < 8; j++)
208 map[i][j] = 0;
209
210 // get 576 TOF-to-TRD bits
211 toftrig->GetTRDmap(map);
212
213 /* DEBUG output
214 // used to determine the correct bit assignment
215 for (Int_t i=0; i < 72; i++) {
216 AliDebug(5, Form("%d ", i));
217 for (Int_t j=7; j >= 0; j--) {
218 AliDebug(5, Form("%d", map[i][j]));
219 }
220 }
221 //*/ // end of DEBUG output
222
223
224 // transform Bool_t array to UInt_t bitvectors according to
225 // http://www.physi.uni-heidelberg.de/~schicker/cbtof/cbtof_docu.pdf
226 // chapter 1.4 and 2.1 to a supermodule based structured
227 // integer (bit) array
228 Int_t supermodule = -1;
229 UInt_t tempA = 0x00000001;
230 UInt_t tempC = 0x00010000;
231 for (Int_t iLTM = 0; iLTM < (kNLTM / 2); iLTM++) {
232 if (!(iLTM % 2)) { // renew temp vectors, update supermodule
233 tempA = 0x00000001;
234 tempC = 0x00010000;
235 supermodule++;
236 }
237 AliDebug(5, Form("(%2d,0x%8x,0x%8x)", iLTM, tempA, tempC));
238 for (Int_t iLTMchan = 0; iLTMchan < 8; iLTMchan++) {
239 // A-side
240 if (map[iLTM][iLTMchan]) {
241 this->fInputTOFinputBits[supermodule] |= tempA;
242 }
243 // C-side
244 if (map[iLTM + 36][iLTMchan]) {
245 this->fInputTOFinputBits[supermodule] |= tempC;
246 }
247 // change temp vectors
248 tempA <<= 1;
249 tempC <<= 1;
250 }
251 }
252
253 // handle input mask
254 for (Int_t iSM = 0; iSM < 18; iSM++) {
255 AliDebug(5, Form("fInputTOFinputBits[%d]=0x%x", iSM,
256 this->fInputTOFinputBits[iSM]));
257 this->fInputTOFinputBits[iSM] &= this->fInputMask[iSM];
258 }
259}
260
261
262//______________________________________________________________________________
263Int_t AliTRDptrgTLMU::BackToBack(Int_t iSM, Int_t range) {
264 // Check whether there is an back-to-back particle trace
265
266 // get the counterpart of supermodule iSM
267 Int_t counterPart = -1;
268 if (iSM >= 9) {
269 counterPart = iSM - 9;
270 }
271 else {
272 counterPart = iSM + 9;
273 }
274
275 if (this->Or(iSM)) { // is there are active bits in supermodule iSM
276 Int_t result = 0;
277 for (Int_t i = counterPart - range; i <= counterPart + range; i++) {
278 // TODO WARNING: There are possible Errors with sm0 +-range!
279 // check whether there are active bits in supermodule i (counterParts)
280 if ((i >= 0) && (i < 18)) {
281 if (Or(i)) {
282 result++;
283 }
284 }
285 else {
286 if (i < 0) {
287 if (Or(17 - i)) {
288 result++;
289 }
290 }
291 if (i > 17) {
292 if (Or(i - 18)) {
293 result++;
294 }
295 }
296 }
297 }
298 AliDebug(5, Form("BackToBack of %d and %d+-%d\n: %d", iSM, counterPart,
299 range, result));
300 return result; // return whether there was a possible back-to-back trace
301 }
302 else {
303 AliDebug(5, Form("BackToBack unsuccessful, not hit in sm%d", iSM));
304 return 0; // iSM did not recognize anything
305 }
306}
307
308//______________________________________________________________________________
309Int_t AliTRDptrgTLMU::Coincidence(Int_t iSM1, Int_t iSM2) {
310 // checks whether there is an coincidence in iSM1 and iSM2
311
312 if (this->Or(iSM1) && this->Or(iSM2)) {
313 return 1;
314 }
315 else
316 return 0;
317}
318
319//______________________________________________________________________________
320inline Int_t AliTRDptrgTLMU::Or(Int_t iSM) {
321 // returns 1 if one or more bits are active in supermodule iSM
322
323 if ((iSM >= 0) && (iSM < 18)) {
324 if (this->fInputTOFinputBits[iSM] > 0)
325 return 1;
326 else
327 return 0;
328 }
329 else {
330 return -1;
331 }
332}
333
334//______________________________________________________________________________
335Int_t AliTRDptrgTLMU::GetMultiplicity(Int_t iSM) {
336 // counts how many bits equal one are in class member fInputTOFinputBits[iSM]
337 // (32bits from TOF to TRD of supermodule iSM)
338
339 UInt_t temp = this->fInputTOFinputBits[iSM];
340 UInt_t mask = 0x01;
341 Int_t multiplicity = 0;
342
343 // TODO maybe there is a more efficient way to do that?
344 for (int iBit = 0; iBit < 32; iBit++) {
345 if ((mask & temp) != 0x0) { // is the bit equal one?
346 multiplicity++;
347 }
348 mask <<= 1; // rotate mask to the left after each iteration
349 }
350 AliDebug(5, Form("Multiplicity of supermodule %d: %d", iSM, multiplicity));
351 return multiplicity;
352}
353
354//______________________________________________________________________________
355Int_t AliTRDptrgTLMU::GetMultiplicitySum() {
356 // returns the multiplicity of the whole detector (all 576bit TOF to TRD bits)
357 Int_t sum = 0;
358
359 for (Int_t i = 0; i < 18; i++) {
360 sum += this->GetMultiplicity(i);
361 }
362 AliDebug(5, Form("Whole multiplicity: %d", sum));
363 return sum;
364}
365
366//______________________________________________________________________________
367UInt_t AliTRDptrgTLMU::GetBitVectorMultiplicity(UInt_t BitVector) {
368 // returns the multiplicity of a given bit vector
369
370 UInt_t result = 0;
371 UInt_t temp = 0x01;
372 for (UInt_t iBit = 0; iBit < 32; iBit++) {
373 if (BitVector & temp) {
374 result++;
375 }
376 temp <<= 1;
377 }
378
379 return result;
380}