]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDptrgTLMU.cxx
remove the setting of the maximum number of super modules from the class, recover...
[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
c93255fe 34#include "AliTOFdigit.h"
35#include "AliRawReader.h" // needed for AliTOFTrigger's raw digit support
36#include "AliTOFTrigger.h"
f9720615 37
38#include "AliTRDptrgParam.h"
39
40#include "AliTRDptrgTLMU.h"
c93255fe 41#include "AliLog.h"
f9720615 42
43ClassImp(AliTRDptrgTLMU)
44
45//______________________________________________________________________________
46AliTRDptrgTLMU::AliTRDptrgTLMU(AliRunLoader *rl)
47 : TObject(),
48 fRunLoader(rl),
49 fParam(0x0),
50 fOperatingMode(kDigits),
51 fInputMask(0x0),
52 fCMatrices(0x0),
53 fMultiplicity(0x0),
54 fOutput(0x0)
55{
56 // default ctor
57
58 for (Int_t i = 0; i < 18; i++) {
e51605d9 59 this->fTOFinputBits[i] = 0;
f9720615 60 }
e51605d9 61
62 this->LoadParams();
f9720615 63}
64
65//______________________________________________________________________________
66AliTRDptrgTLMU::AliTRDptrgTLMU(AliRunLoader *rl, AliTRDptrgParam *param,
67 AliTRDptrgOperatingMode_t operatingMode)
68 : TObject(),
69 fRunLoader(rl),
70 fParam(param),
71 fOperatingMode(operatingMode),
72 fInputMask(0x0),
73 fCMatrices(0x0),
74 fMultiplicity(0x0),
75 fOutput(0x0)
76{
77 // recommended ctor
78
79 for (Int_t i = 0; i < 18; i++) {
e51605d9 80 this->fTOFinputBits[i] = 0;
f9720615 81 }
82
83 this->LoadParams();
84}
85
86//______________________________________________________________________________
87AliTRDptrgTLMU::~AliTRDptrgTLMU()
88{
89 // destructor
90
91 this->fCMatrices = 0x0;
92 this->fMultiplicity = 0x0;
93 this->fOutput = 0x0;
94}
95
96//______________________________________________________________________________
97Int_t* AliTRDptrgTLMU::Simulate()
98{
99 // starts a simulation
100
101 if (this->fOperatingMode == kDigits) {
102 this->LoadDigits();
103 }
104 else if (this->fOperatingMode == kHits) {
105 return 0x0; // TODO
106 }
107
108 // which super modules are active? - needed for fast coincidence processing:
109 // M(sm | coincidence condition)>=2
110 UInt_t temp = 0x1;
111 UInt_t sm = 0x0;
112 for (Int_t iSM = 0; iSM < 18; iSM++) {
113 if (this->Or(iSM)) {
114 sm |= temp;
115 }
116 temp <<= 1;
117 }
118 AliDebug(4, Form("Active supermodules: 0x%x", sm));
119
120 // get multiplicity
121 UInt_t multiplicity = this->GetMultiplicitySum();
122 AliDebug(4, Form("TOF/TLMU multiplicity: %d", multiplicity));
123
124 Int_t* result = new Int_t[9];
125 result[0] = 8;
126 for (Int_t iResult = 0; iResult < 8; iResult++) {
127 result[iResult + 1] = 0;
128
129 // coincidence matrix
130 if (this->fOutput[iResult][0] != -1) {
131 for (Int_t iLine = 0; iLine < 18; iLine++) {
e51605d9 132 AliDebug(5, Form("Entry: %d, matrix: %d, line: %d, output: 0x%x",
133 iResult, this->fOutput[iResult][0], iLine, sm &
134 this->fCMatrices[this->fOutput[iResult][0]][iLine]));
f9720615 135 if (this->GetBitVectorMultiplicity(
e51605d9 136 sm & this->fCMatrices[this->fOutput[iResult][0]][iLine]) > 1) {
f9720615 137 result[iResult + 1] = 1;
138 break;
139 }
140 }
141 }
142
143 // multiplicity conditions
144 if (this->fOutput[iResult][1] != -1) {
e51605d9 145 AliDebug(5, Form("Entry: %d, slice: %d", iResult,
f9720615 146 this->fOutput[iResult][1]));
147 if ((this->fMultiplicity[this->fOutput[iResult][1]][0] < multiplicity) &&
148 (this->fMultiplicity[this->fOutput[iResult][1]][1] >= multiplicity)) {
149 result[iResult + 1] = 1;
150 }
151 }
152 AliDebug(4, Form("TLMU result[%d] = %d", iResult, result[iResult + 1]));
153 }
154
155 return result;
156}
157
158//______________________________________________________________________________
159Int_t AliTRDptrgTLMU::LoadDigits()
160{
161 // loads Digits (for usage with aquired data)
162 this->GetInputBits(); // get bits from AliTOFTrigger
163 return 0;
164}
165
166
167//______________________________________________________________________________
168Bool_t AliTRDptrgTLMU::LoadParams()
169{
170 // load AliTRDprtgParam content
171
172 if (this->fParam == 0x0) {
173 // no parameter object assigned
174 AliWarning("no parameter object assigned - using default settings!");
175
e51605d9 176 UInt_t* imask = 0x0;
177 imask = new UInt_t[18];
178 for (Int_t i = 0; i < 18; i++) {
179 imask[i] = 0xFFFFFFFF;
180 }
181
182 this->fInputMask = imask;
183
184 // TLMU Coincidence Matrices
185 this->fCMatrices = new UInt_t*[3];
186 this->fCMatrices[0] = new UInt_t[18];
187 this->fCMatrices[1] = new UInt_t[18];
188 this->fCMatrices[2] = new UInt_t[18];
189
190 // Matrix 0: Back-To-Back
191 // Matrix 1: Back-To-Back +/-1
192 // Matrix 2: Back-To-Back +/-2
193 for (UInt_t iMatrix = 0; iMatrix < 3; iMatrix++) {
194 for (UInt_t iSlice = 0; iSlice < 18; iSlice++) {
195 if (iMatrix == 0) {
196 if (iSlice < 9) {
197 this->fCMatrices[iMatrix][iSlice] = 0x201 << iSlice;
198 // Back-To-Back
199 AliDebug(5, Form("fCMatrices[%d][%d]=0x%x",iMatrix,iSlice,
200 this->fCMatrices[iMatrix][iSlice]));
201 }
202 // because of symmetrie the other slices are not necessary
203 }
204 else if (iMatrix == 1) {
205 // Back-To-Back +/- 1
206 if (iSlice < 8) {
207 this->fCMatrices[iMatrix][iSlice] = 0x381 << iSlice;
208 }
209 else if (iSlice == 8) {
210 this->fCMatrices[iMatrix][iSlice] = 0x30101;
211 }
212 else if (iSlice == 9) {
213 this->fCMatrices[iMatrix][iSlice] = 0x20203;
214 }
215 else {
216 this->fCMatrices[iMatrix][iSlice] = 0x407 << (iSlice - 10);
217 }
218 AliDebug(5, Form("fCMatrices[%d][%d]=0x%x",iMatrix,iSlice,
219 this->fCMatrices[iMatrix][iSlice]));
220 }
221 else if (iMatrix == 2) {
222 // Back-To-Back +/-2
223 if (iSlice < 7 ) {
224 this->fCMatrices[iMatrix][iSlice] = 0xF81 << iSlice;
225 }
226 else if (iSlice == 7) {
227 this->fCMatrices[iMatrix][iSlice] = 0x3C081;
228 }
229 else if (iSlice == 8) {
230 this->fCMatrices[iMatrix][iSlice] = 0x38103;
231 }
232 else if (iSlice == 9) {
233 this->fCMatrices[iMatrix][iSlice] = 0x30207;
234 }
235 else if (iSlice == 10) {
236 this->fCMatrices[iMatrix][iSlice] = 0x2040F;
237 }
238 else {
239 this->fCMatrices[iMatrix][iSlice] = 0x81F << (iSlice - 11);
240 }
241 AliDebug(5, Form("fCMatrices[%d][%d]=0x%x",iMatrix,iSlice,
242 this->fCMatrices[iMatrix][iSlice]));
243 }
244 }
245 }
246
247 // Mulitplicity
248 this->fMultiplicity = new UInt_t*[9];
249 for (Int_t i = 0; i < 9; i++) {
250 this->fMultiplicity[i] = new UInt_t[2];
251 }
252 this->fMultiplicity[0][0] = 0;
253 this->fMultiplicity[0][1] = 10;
254 this->fMultiplicity[1][0] = 10;
255 this->fMultiplicity[1][1] = 25;
256 this->fMultiplicity[2][0] = 25;
257 this->fMultiplicity[2][1] = 50;
258 this->fMultiplicity[3][0] = 50;
259 this->fMultiplicity[3][1] = 100;
260 this->fMultiplicity[4][0] = 100;
261 this->fMultiplicity[4][1] = 200;
262 this->fMultiplicity[5][0] = 200;
263 this->fMultiplicity[5][1] = 350;
264 this->fMultiplicity[6][0] = 350;
265 this->fMultiplicity[6][1] = 400;
266 this->fMultiplicity[7][0] = 400;
267 this->fMultiplicity[7][1] = 576;
268 this->fMultiplicity[8][0] = 100;
269 this->fMultiplicity[8][1] = 576;
270
271 // TLMU output
272 this->fOutput = new Int_t*[8];
273 for (Int_t i = 0; i < 9; i++) {
274 this->fOutput[i] = new Int_t[2];
275 this->fOutput[i][0] = -1;
276 this->fOutput[i][1] = -1;
277 }
278 this->fOutput[0][0] = 0;
279 this->fOutput[1][0] = 1;
280 this->fOutput[2][0] = 2;
281 this->fOutput[3][1] = 0;
282 this->fOutput[4][1] = 1;
283 this->fOutput[5][1] = 2;
284 this->fOutput[6][1] = 3;
285 this->fOutput[7][1] = 8;
286
287
f9720615 288 }
289 else {
290 // parameter object assigned
291
292 this->fInputMask = this->fParam->GetTLMUInputMask();
293 // input mask for TOF-bits (18x32=576)
294
295 this->fCMatrices = this->fParam->GetTLMUcmatrices();
296 // get coincidence matrices
297
298 this->fMultiplicity = this->fParam->GetTLMUmultiplicity();
299 // get multiplicity slices
300
301 this->fOutput = this->fParam->GetTLMUoutput();
302 // get output signal assignment
303 }
304
305 return false;
306}
307
308//______________________________________________________________________________
309void AliTRDptrgTLMU::GetInputBits() {
310 // Gets TOF-to-TRD input bits from AliTOFTrigger as Bool_t array
311
312 AliTOFTrigger *toftrig = new AliTOFTrigger(); // create AliTOFTrigger
b5d772e9 313 toftrig->CreateLTMMatrix(); // Generate LTMMatrix from AliTOFdigits
f9720615 314
315 // prepare map
316 Bool_t** map = 0x0;
317 map = new Bool_t*[72];
318 for (Int_t i=0; i < 72; i++)
319 map[i] = new Bool_t[8];
320
321 // initialise map
322 for (Int_t i=0; i < 72; i++)
323 for (Int_t j=0; j < 8; j++)
e51605d9 324 map[i][j] = kFALSE;
f9720615 325
326 // get 576 TOF-to-TRD bits
327 toftrig->GetTRDmap(map);
328
e51605d9 329 //* DEBUG output
f9720615 330 // used to determine the correct bit assignment
e51605d9 331 AliDebug(5, "AliTOFTrigger->GetTRDmap(map):");
f9720615 332 for (Int_t i=0; i < 72; i++) {
e51605d9 333 AliDebug(5, Form("%d %d%d%d%d%d%d%d%d", i, map[i][0], map[i][1], map[i][2],
334 map[i][3], map[i][4], map[i][5], map[i][6], map[i][7]));
f9720615 335 }
336 //*/ // end of DEBUG output
e51605d9 337
338 // initialise fTOFinputBits
339 for (Int_t i=0; i < 18; i++) {
340 this->fTOFinputBits[i] = 0;
341 }
342
f9720615 343
344 // transform Bool_t array to UInt_t bitvectors according to
345 // http://www.physi.uni-heidelberg.de/~schicker/cbtof/cbtof_docu.pdf
346 // chapter 1.4 and 2.1 to a supermodule based structured
347 // integer (bit) array
348 Int_t supermodule = -1;
349 UInt_t tempA = 0x00000001;
350 UInt_t tempC = 0x00010000;
351 for (Int_t iLTM = 0; iLTM < (kNLTM / 2); iLTM++) {
352 if (!(iLTM % 2)) { // renew temp vectors, update supermodule
353 tempA = 0x00000001;
354 tempC = 0x00010000;
355 supermodule++;
356 }
e51605d9 357 // AliDebug(5, Form("(%2d,0x%8x,0x%8x)", iLTM, tempA, tempC));
f9720615 358 for (Int_t iLTMchan = 0; iLTMchan < 8; iLTMchan++) {
359 // A-side
360 if (map[iLTM][iLTMchan]) {
e51605d9 361 this->fTOFinputBits[supermodule] |= tempA;
f9720615 362 }
363 // C-side
364 if (map[iLTM + 36][iLTMchan]) {
e51605d9 365 this->fTOFinputBits[supermodule] |= tempC;
f9720615 366 }
367 // change temp vectors
368 tempA <<= 1;
369 tempC <<= 1;
370 }
371 }
372
373 // handle input mask
374 for (Int_t iSM = 0; iSM < 18; iSM++) {
375 AliDebug(5, Form("fInputTOFinputBits[%d]=0x%x", iSM,
e51605d9 376 this->fTOFinputBits[iSM]));
377 this->fTOFinputBits[iSM] &= this->fInputMask[iSM];
f9720615 378 }
379}
380
381
382//______________________________________________________________________________
383Int_t AliTRDptrgTLMU::BackToBack(Int_t iSM, Int_t range) {
384 // Check whether there is an back-to-back particle trace
385
386 // get the counterpart of supermodule iSM
387 Int_t counterPart = -1;
388 if (iSM >= 9) {
389 counterPart = iSM - 9;
390 }
391 else {
392 counterPart = iSM + 9;
393 }
394
395 if (this->Or(iSM)) { // is there are active bits in supermodule iSM
396 Int_t result = 0;
397 for (Int_t i = counterPart - range; i <= counterPart + range; i++) {
f9720615 398 // check whether there are active bits in supermodule i (counterParts)
399 if ((i >= 0) && (i < 18)) {
400 if (Or(i)) {
401 result++;
402 }
403 }
404 else {
405 if (i < 0) {
406 if (Or(17 - i)) {
407 result++;
408 }
409 }
410 if (i > 17) {
411 if (Or(i - 18)) {
412 result++;
413 }
414 }
415 }
416 }
417 AliDebug(5, Form("BackToBack of %d and %d+-%d\n: %d", iSM, counterPart,
418 range, result));
419 return result; // return whether there was a possible back-to-back trace
420 }
421 else {
422 AliDebug(5, Form("BackToBack unsuccessful, not hit in sm%d", iSM));
423 return 0; // iSM did not recognize anything
424 }
425}
426
427//______________________________________________________________________________
428Int_t AliTRDptrgTLMU::Coincidence(Int_t iSM1, Int_t iSM2) {
429 // checks whether there is an coincidence in iSM1 and iSM2
430
431 if (this->Or(iSM1) && this->Or(iSM2)) {
432 return 1;
433 }
434 else
435 return 0;
436}
437
438//______________________________________________________________________________
439inline Int_t AliTRDptrgTLMU::Or(Int_t iSM) {
440 // returns 1 if one or more bits are active in supermodule iSM
441
442 if ((iSM >= 0) && (iSM < 18)) {
e51605d9 443 if (this->fTOFinputBits[iSM] > 0)
f9720615 444 return 1;
445 else
446 return 0;
447 }
448 else {
449 return -1;
450 }
451}
452
453//______________________________________________________________________________
454Int_t AliTRDptrgTLMU::GetMultiplicity(Int_t iSM) {
e51605d9 455 // counts how many bits equal one are in class member fTOFinputBits[iSM]
f9720615 456 // (32bits from TOF to TRD of supermodule iSM)
457
e51605d9 458 UInt_t temp = this->fTOFinputBits[iSM];
f9720615 459 UInt_t mask = 0x01;
460 Int_t multiplicity = 0;
461
f9720615 462 for (int iBit = 0; iBit < 32; iBit++) {
463 if ((mask & temp) != 0x0) { // is the bit equal one?
464 multiplicity++;
465 }
466 mask <<= 1; // rotate mask to the left after each iteration
467 }
468 AliDebug(5, Form("Multiplicity of supermodule %d: %d", iSM, multiplicity));
469 return multiplicity;
470}
471
472//______________________________________________________________________________
473Int_t AliTRDptrgTLMU::GetMultiplicitySum() {
474 // returns the multiplicity of the whole detector (all 576bit TOF to TRD bits)
475 Int_t sum = 0;
476
477 for (Int_t i = 0; i < 18; i++) {
478 sum += this->GetMultiplicity(i);
479 }
480 AliDebug(5, Form("Whole multiplicity: %d", sum));
481 return sum;
482}
483
484//______________________________________________________________________________
485UInt_t AliTRDptrgTLMU::GetBitVectorMultiplicity(UInt_t BitVector) {
486 // returns the multiplicity of a given bit vector
487
488 UInt_t result = 0;
489 UInt_t temp = 0x01;
490 for (UInt_t iBit = 0; iBit < 32; iBit++) {
491 if (BitVector & temp) {
492 result++;
493 }
494 temp <<= 1;
495 }
496
497 return result;
498}