Bug fix
[u/mrichter/AliRoot.git] / TOF / AliTOFTrigger.cxx
CommitLineData
cd82ed2f 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/////////////////////////////////////////////////////////////////////
ee51d470 19//
cd82ed2f 20// Class performing TOF Trigger
21// Cosmic_Multi_muon: Cosmic Multi-Muonic Event Trigger (L0)
22// ppMB: p-p Minimum Bias Event Trigger (L0)
23// UltraPer_Coll: Ultra-Peripheral Collision Event Trigger (L0)
24// High_Mult: High Multiplicity Event Trigger (L0)
25// Jet: Events with Jet Topology Trigger (L1)
26//
ee51d470 27// A.Silenzi: added CTTM map,
28// method to fill LTM matrix from raw data,
29// method to retrieve the TOF pre-trigger for TRD detector
30//
31//
cd82ed2f 32/////////////////////////////////////////////////////////////////////
33
7ca4655f 34#include <TClonesArray.h>
35
cd82ed2f 36#include "AliLoader.h"
0e46b9ae 37#include "AliLog.h"
cd82ed2f 38#include "AliRunLoader.h"
0e46b9ae 39#include "AliRun.h"
cd82ed2f 40#include "AliTriggerInput.h"
ee51d470 41#include "AliRawReader.h"
0e46b9ae 42
ee51d470 43#include "AliTOFRawStream.h"
44#include "AliTOFrawData.h"
cd82ed2f 45#include "AliTOFdigit.h"
ee51d470 46#include "AliTOFGeometry.h"
0e46b9ae 47#include "AliTOFTrigger.h"
cd82ed2f 48
0e46b9ae 49extern AliRun* gAlice;
cd82ed2f 50
51//-------------------------------------------------------------------------
52ClassImp(AliTOFTrigger)
53
54//----------------------------------------------------------------------
ee51d470 55 AliTOFTrigger::AliTOFTrigger() :
56 AliTriggerDetector(),
cd82ed2f 57 fHighMultTh(1000),
58 fppMBTh(4),
59 fMultiMuonTh(2),
60 fUPTh(2),
61 fdeltaminpsi(150),
62 fdeltamaxpsi(170),
63 fdeltaminro(70),
64 fdeltamaxro(110),
65 fstripWindow(2)
66{
67 //main ctor
68 for (Int_t i=0;i<kNLTM;i++){
69 for (Int_t j=0;j<kNLTMchannels;j++){
70 fLTMmatrix[i][j]=kFALSE;
71 }
72 if (i<kNCTTM){
73 for (Int_t j=0;j<kNCTTMchannels;j++){
74 fCTTMmatrixFront[i][j]=kFALSE;
75 fCTTMmatrixBack[i][j]=kFALSE;
76 }
77 }
78 }
79 SetName("TOF");
80 CreateInputs();
81}
ee51d470 82
cd82ed2f 83//----------------------------------------------------------------------
ee51d470 84
85AliTOFTrigger::AliTOFTrigger(Int_t HighMultTh, Int_t ppMBTh, Int_t MultiMuonTh, Int_t UPTh, Float_t deltaminpsi, Float_t deltamaxpsi, Float_t deltaminro, Float_t deltamaxro, Int_t stripWindow) :
86 AliTriggerDetector(),
655e379f 87 fHighMultTh(HighMultTh),
88 fppMBTh(ppMBTh),
89 fMultiMuonTh(MultiMuonTh),
90 fUPTh(UPTh),
91 fdeltaminpsi(deltaminpsi),
92 fdeltamaxpsi(deltamaxpsi),
93 fdeltaminro(deltaminro),
94 fdeltamaxro(deltamaxro),
95 fstripWindow(stripWindow)
96
cd82ed2f 97{
98 //ctor with thresholds for triggers
cd82ed2f 99 for (Int_t i=0;i<kNLTM;i++){
100 for (Int_t j=0;j<kNLTMchannels;j++){
101 fLTMmatrix[i][j]=kFALSE;
102 }
103 if (i<kNCTTM){
104 for (Int_t j=0;j<kNCTTMchannels;j++){
105 fCTTMmatrixFront[i][j]=kFALSE;
106 fCTTMmatrixBack[i][j]=kFALSE;
107 }
108 }
109 }
110 SetName("TOF");
111 CreateInputs();
112}
113
ee51d470 114//____________________________________________________________________________
cd82ed2f 115
655e379f 116AliTOFTrigger::AliTOFTrigger(const AliTOFTrigger & tr):
8a190ba2 117 AliTriggerDetector(tr),
118 fHighMultTh(tr.fHighMultTh),
119 fppMBTh(tr.fppMBTh),
120 fMultiMuonTh(tr.fMultiMuonTh),
121 fUPTh(tr.fUPTh),
122 fdeltaminpsi(tr.fdeltaminpsi),
123 fdeltamaxpsi(tr.fdeltamaxpsi),
124 fdeltaminro(tr.fdeltaminro),
125 fdeltamaxro(tr.fdeltamaxro),
126 fstripWindow(tr.fstripWindow)
cd82ed2f 127{
128 //copy ctor
cd82ed2f 129 for (Int_t i=0;i<kNLTM;i++){
130 for (Int_t j=0;j<kNLTMchannels;j++){
131 fLTMmatrix[i][j]=tr.fLTMmatrix[i][j];
132 }
133 if (i<kNCTTM){
134 for (Int_t j=0;j<kNCTTMchannels;j++){
ee51d470 135 fCTTMmatrixFront[i][j]=tr.fCTTMmatrixFront[i][j];
136 fCTTMmatrixBack[i][j]=tr.fCTTMmatrixBack[i][j];
cd82ed2f 137 }
138 }
139 }
140 SetName(tr.GetName());
141 CreateInputs();
ee51d470 142 //fInputs=&(tr.GetInputs());
cd82ed2f 143}
144
145//----------------------------------------------------------------------
146
147void AliTOFTrigger::CreateInputs()
148{
ee51d470 149 // creating inputs
cd82ed2f 150 // Do not create inputs again!!
ee51d470 151 if( fInputs.GetEntriesFast() > 0 ) return;
152
153 fInputs.AddLast(new AliTriggerInput("TOF_Cosmic_MultiMuon_L0","TOF",0));
154 fInputs.AddLast(new AliTriggerInput("0OIN","TOF",0)); // was "TOF_pp_MB_L0"
155 fInputs.AddLast(new AliTriggerInput("0OX1","TOF",0)); // was "TOF_UltraPer_Coll_L0"
156
157 fInputs.AddLast(new AliTriggerInput("0OHM","TOF",0)); // was "TOF_High_Mult_L0"
158 fInputs.AddLast(new AliTriggerInput("TOF_Jet_L1","TOF",0));
159
cd82ed2f 160}
161
162//----------------------------------------------------------------------
ee51d470 163void AliTOFTrigger::Trigger() {
cd82ed2f 164 //triggering method
c6eeb5c9 165
cd82ed2f 166 CreateLTMMatrix();
167 Int_t nchonFront = 0;
168 Int_t nchonBack = 0;
169 Int_t nchonTot = 0;
170 Int_t nchonFrontBack = 0;
171 Int_t nchonFront1 = 0;
172 Int_t nchonBack1 = 0;
173 Int_t nchonFrontBack1 = 0;
174 Int_t mindeltapsi = (Int_t)fdeltaminpsi/10;
175 Int_t maxdeltapsi = (Int_t)fdeltamaxpsi/10;
176 Int_t mindeltaro = (Int_t)fdeltaminro/10;
177 Int_t maxdeltaro = (Int_t)fdeltamaxro/10;
ee51d470 178
cd82ed2f 179 for (Int_t i=0;i<kNCTTM;i++){
180 for (Int_t j=0;j<kNCTTMchannels;j++){
ee51d470 181 if (fCTTMmatrixFront[i][j]) nchonFront++;
cd82ed2f 182 }
183 }
184
185 for (Int_t i=kNCTTM;i<(kNCTTM*2);i++){
186 for (Int_t j=0;j<kNCTTMchannels;j++){
ee51d470 187 if (fCTTMmatrixBack[i-kNCTTM][j]) nchonBack++;
cd82ed2f 188 }
189 }
190
191 nchonTot = nchonFront + nchonBack;
192
193 //pp Minimum Bias Trigger
194 if (nchonTot >= fppMBTh) {
c6eeb5c9 195 SetInput("0OIN");
cd82ed2f 196 }
197
198 //High Multiplicity Trigger
199 if (nchonTot >= fHighMultTh) {
c6eeb5c9 200 SetInput("0OHM");
cd82ed2f 201 }
202
ee51d470 203
cd82ed2f 204 //MultiMuon Trigger
205 nchonFront = 0;
206 nchonBack = 0;
207 nchonFrontBack = 0;
208
209 Bool_t boolCTTMor = kFALSE;
210
211 for (Int_t i=0;i<(kNCTTM/2);i++){
212 Int_t iopp = i+kNCTTM/2;
213 for (Int_t j=0;j<kNCTTMchannels;j++){
214 if (fCTTMmatrixFront[i][j]){
215 Int_t minj = j-fstripWindow;
216 Int_t maxj = j+fstripWindow;
217 if (minj<0) minj =0;
218 if (maxj>=kNCTTMchannels) maxj = kNCTTMchannels-1;
219 boolCTTMor = kFALSE;
220 for (Int_t k = minj;k<=maxj;k++){
221 boolCTTMor |= fCTTMmatrixFront[iopp][k];
ee51d470 222 }
cd82ed2f 223 if (boolCTTMor) {
224 nchonFront++;
225 }
226 }
ee51d470 227
cd82ed2f 228 if (fCTTMmatrixBack[i][j]){
229 Int_t minj = j-fstripWindow;
230 Int_t maxj = j+fstripWindow;
231 if (minj<0) minj =0;
232 if (maxj>=kNCTTMchannels) maxj =kNCTTMchannels-1;
233 boolCTTMor = kFALSE;
234 for (Int_t k = minj;k<=maxj;k++){
235 boolCTTMor |= fCTTMmatrixBack[iopp][k];
236 }
237 if (boolCTTMor) {
238 nchonBack++;
239 }
240 }
241 }
242 }
243
244 nchonFrontBack = nchonFront+nchonBack;
245
246 nchonFront1 = 0;
247 nchonBack1 = 0;
248 nchonFrontBack1 = 0;
249
250 boolCTTMor = kFALSE;
251 for (Int_t i=0;i<(kNCTTM/2);i++){
252 Int_t i2max = (kNCTTM-1)-i+1;
253 Int_t i2min = (kNCTTM-1)-i-1;
254 if (i2max >=kNCTTM) i2max = kNCTTM-1;
255 if (i2min==i) i2min = kNCTTM-1-i;
256 for (Int_t j=0;j<kNCTTMchannels;j++){
257 Int_t j2min = j-fstripWindow;
258 Int_t j2max = j+fstripWindow;
259 if (j2min<0) j2min =0;
260 if (j2max>=kNCTTMchannels) j2max =kNCTTMchannels-1;
261 if (fCTTMmatrixFront[i][j]){
262 boolCTTMor = kFALSE;
263 for (Int_t i2=i2min;i2<=i2max;i2++){
264 for (Int_t j2 = j2min;j2<=j2max;j2++){
265 boolCTTMor |= fCTTMmatrixFront[i2][j2];
ee51d470 266 }
cd82ed2f 267 if (boolCTTMor) {
268 nchonFront++;
269 }
270 }
271 }
272 if (fCTTMmatrixBack[i][j]){
273 boolCTTMor = kFALSE;
274 for (Int_t i2=i2min;i2<=i2max;i2++){
275 for (Int_t j2 = j2min;j2<=j2max;j2++){
276 boolCTTMor |= fCTTMmatrixBack[i2][j2];
277 }
278 }
279 if (boolCTTMor) {
280 nchonBack++;
281 }
282 }
283 }
284 }
285
286 nchonFrontBack1 = nchonFront1+nchonBack1;
287
288 if (nchonFrontBack >= fMultiMuonTh || nchonFrontBack1 >= fMultiMuonTh) {
289 SetInput("TOF_Cosmic_MultiMuon_L0");
290 }
291
292 //Ultra-Peripheral collision Trigger
293 Bool_t boolpsi = kFALSE;
294 Bool_t boolro = kFALSE;
295 if (nchonTot == fUPTh){
296 for (Int_t i=0;i<kNCTTM;i++){
297 for (Int_t j=0;j<kNCTTMchannels;j++){
298 Int_t minipsi = i+mindeltapsi;
299 Int_t maxipsi = i+maxdeltapsi;
300 if (minipsi>=kNCTTM) minipsi = mindeltapsi-((kNCTTM-1)-i)-1;
301 if (maxipsi>=kNCTTM) maxipsi = maxdeltapsi-((kNCTTM-1)-i)-1;
302 Int_t miniro = i+mindeltaro;
303 Int_t maxiro = i+maxdeltaro;
304 if (miniro>=kNCTTM) miniro = mindeltaro-((kNCTTM-1)-i)-1;
305 if (maxiro>=kNCTTM) maxiro = maxdeltaro-((kNCTTM-1)-i)-1;
306 Int_t j2min = j-fstripWindow;
307 Int_t j2max = j+fstripWindow;
308 if (j2min<0) j2min =0;
309 if (j2max>=kNCTTMchannels) j2max =kNCTTMchannels-1;
310 if (fCTTMmatrixFront[i][j]){
311 for (Int_t i2=minipsi;i2<=maxipsi;i2++){
312 for (Int_t j2 = j2min;j2<=j2max;j2++){
313 if (fCTTMmatrixFront[i2][j2]) {
c6eeb5c9 314 SetInput("0OX1");
cd82ed2f 315 boolpsi = kTRUE;
316 //exiting loops
317 j2 = j2max+1;
318 i2 = maxipsi+1;
319 j=kNCTTMchannels;
320 i=kNCTTM;
321 }
322 }
323 }
324 if (!boolpsi){
325 for (Int_t i2=miniro;i2<=maxiro;i2++){
326 for (Int_t j2 = j2min;j2<=j2max;j2++){
327 if (fCTTMmatrixFront[i2][j2]) {
c6eeb5c9 328 SetInput("0OX1");
cd82ed2f 329 boolro = kTRUE;
330 //exiting loops
331 j2 = j2max+1;
332 i2 = maxiro+1;
333 j=kNCTTMchannels;
334 i=kNCTTM;
335 }
336 }
337 }
338 }
339 }
ee51d470 340
cd82ed2f 341 else if (fCTTMmatrixBack[i][j]){
342 for (Int_t i2=minipsi;i2<=maxipsi;i2++){
343 for (Int_t j2 = j2min;j2<=j2max;j2++){
344 if (fCTTMmatrixBack[i2][j2]) {
c6eeb5c9 345 SetInput("0OX1");
cd82ed2f 346 boolpsi = kTRUE;
347 //exiting loops
348 j2 = j2max+1;
349 i2 = maxipsi+1;
350 j=kNCTTMchannels;
351 i=kNCTTM;
352 }
353 }
354 }
355 if (!boolpsi){
356 for (Int_t i2=miniro;i2<=maxiro;i2++){
357 for (Int_t j2 = j2min;j2<=j2max;j2++){
358 if (fCTTMmatrixBack[i2][j2]) {
c6eeb5c9 359 SetInput("0OX1");
cd82ed2f 360 boolro = kTRUE;
361 //exiting loops
362 j2 = j2max+1;
363 i2 = maxiro+1;
364 j=kNCTTMchannels;
365 i=kNCTTM;
366 }
367 }
368 }
369 }
370 }
371 }
372 }
373 }
ee51d470 374
cd82ed2f 375}
ee51d470 376
cd82ed2f 377//-----------------------------------------------------------------------------
ee51d470 378void AliTOFTrigger::CreateLTMMatrix() {
cd82ed2f 379 //creating LTMMatrix
380 //initialization
ee51d470 381 CreateLTMMatrixFromDigits();
382}
383
384//-------------------------------------------------------------------------
385
386void AliTOFTrigger::CreateLTMMatrixFromDigits() {
387 //
388 // Create LTM matrix by TOF digits
389 //
390
391 //initialization
cd82ed2f 392 for (Int_t i=0;i<kNLTM;i++){
393 for (Int_t j=0;j<kNLTMchannels;j++){
394 fLTMmatrix[i][j]=kFALSE;
395 }
396 }
397 AliRunLoader *rl;
33c3c91a 398 rl = AliRunLoader::Instance();
ee51d470 399
cd82ed2f 400 Int_t ncurrevent = rl->GetEventNumber();
401 rl->GetEvent(ncurrevent);
ee51d470 402
cd82ed2f 403 AliLoader * tofLoader = rl->GetLoader("TOFLoader");
ee51d470 404
cd82ed2f 405 tofLoader->LoadDigits("read");
406 TTree *treeD = tofLoader->TreeD();
407 if (treeD == 0x0)
408 {
409 AliFatal("AliTOFTrigger: Can not get TreeD");
410 }
ee51d470 411
cd82ed2f 412 TBranch *branch = treeD->GetBranch("TOF");
ee51d470 413 if (!branch) {
cd82ed2f 414 AliError("can't get the branch with the TOF digits !");
415 return;
416 }
417 TClonesArray *tofDigits =new TClonesArray("AliTOFdigit", 1000);
418 branch->SetAddress(&tofDigits);
419 treeD->GetEvent(0);
420 Int_t ndigits = tofDigits->GetEntriesFast();
421 Int_t detind[5]; //detector indexes: 0 -> sector
422 // 1 -> plate
423 // 2 -> strip
424 // 3 -> padz
425 // 4 -> padx
ee51d470 426
cd82ed2f 427 for (Int_t i=0;i<ndigits;i++){
428 AliTOFdigit * digit = (AliTOFdigit*)tofDigits->UncheckedAt(i);
429 detind[0] = digit->GetSector();
430 detind[1] = digit->GetPlate();
431 detind[2] = digit->GetStrip();
432 detind[3] = digit->GetPadz();
433 detind[4] = digit->GetPadx();
ee51d470 434
cd82ed2f 435 Int_t indexLTM[2] = {-1,-1};
436 GetLTMIndex(detind,indexLTM);
437
438 fLTMmatrix[indexLTM[0]][indexLTM[1]] = kTRUE;
439 }
440
28751b82 441 tofLoader->UnloadDigits();
ee51d470 442 // rl->UnloadgAlice();
443 CreateCTTMMatrix();
444
cd82ed2f 445}
ee51d470 446
cd82ed2f 447//-----------------------------------------------------------------------------
ee51d470 448
449void AliTOFTrigger::CreateLTMMatrixFromRaw(AliRawReader *fRawReader) {
450 //
451 // Create LTM matrix by TOF raw data
452 //
453
454 //initialization
455 for (Int_t i=0;i<kNLTM;i++){
456 for (Int_t j=0;j<kNLTMchannels;j++){
457 fLTMmatrix[i][j]=kFALSE;
458 }
459 }
460
461 if(fRawReader){
462 AliTOFRawStream * tofRawStream = new AliTOFRawStream();
463
464 Int_t inholes = 0;
465
466 //if(!GetLoader()->TreeS()) {MakeTree("S"); MakeBranch("S");}
467
468 Clear();
469 tofRawStream->SetRawReader(fRawReader);
470
471 //ofstream ftxt;
472 //if (fVerbose==2) ftxt.open("TOFsdigitsRead.txt",ios::app);
473
474 TClonesArray staticRawData("AliTOFrawData",10000);
475 staticRawData.Clear();
476 TClonesArray * clonesRawData = &staticRawData;
477
478 Int_t dummy = -1;
479 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
480 Int_t digit[2];
481 //Int_t track = -1;
482 //Int_t last = -1;
483
484 Int_t indexDDL = 0;
485 Int_t iRawData = 0;
486 AliTOFrawData *tofRawDatum = 0;
487 for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
488
489 fRawReader->Reset();
490 tofRawStream->LoadRawData(indexDDL);
491
492 clonesRawData = tofRawStream->GetRawData();
493 if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
494 for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
495
496 tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
497
498 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
499 if (tofRawDatum->GetTOF()==-1) continue;
500
501 SetBit(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
502 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel());
503
504 dummy = detectorIndex[3];
505 detectorIndex[3] = detectorIndex[4];//padz
506 detectorIndex[4] = dummy;//padx
507
508 digit[0] = tofRawDatum->GetTOF();
509 digit[1] = tofRawDatum->GetTOT();
510
511 dummy = detectorIndex[3];
512 detectorIndex[3] = detectorIndex[4];//padx
513 detectorIndex[4] = dummy;//padz
514
515 // Do not reconstruct anything in the holes
516 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
517 if (detectorIndex[1]==2) { // plate with holes
518 inholes++;
519 continue;
520 }
521 }
522
523 tofRawDatum = 0;
524 } // while loop
525
526 clonesRawData->Clear();
527
528 } // DDL Loop
529
530 //if (fVerbose==2) ftxt.close();
531
532 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
533
534 }
535
536}
537
538//-----------------------------------------------------------------------------
42e171ac 539void AliTOFTrigger::GetLTMIndex(const Int_t * const detind, Int_t *indexLTM) {
ee51d470 540 //
541 // getting LTMmatrix indexes for current digit
542 //
543
cd82ed2f 544 if (detind[1]==0 || detind[1]==1 || (detind[1]==2 && detind[2]<=7)) {
545 if (detind[4]<24){
546 indexLTM[0] = detind[0]*2;
547 }
548 else {
549 indexLTM[0] = detind[0]*2+1;
550 }
551 }
552 else {
553 if (detind[4]<24){
554 indexLTM[0] = detind[0]*2+36;
555 }
556 else {
557 indexLTM[0] = (detind[0]*2+1)+36;
558 }
559 }
560
ee51d470 561 if (indexLTM[0]<36) {
cd82ed2f 562 if (detind[1] ==0){
563 indexLTM[1] = detind[2];
564 }
565 else if (detind[1] ==1){
566 indexLTM[1] = detind[2]+19;
567 }
568 else if (detind[1] ==2){
2901911a 569 indexLTM[1] = detind[2]+19*2;
cd82ed2f 570 }
571 else{
572 AliError("Smth Wrong!!!");
573 }
574 }
575 else {
576 if (detind[1] ==2){
577 indexLTM[1] = detind[2]-8;
578 }
579 else if (detind[1] ==3){
580 indexLTM[1] = detind[2]+7;
581 }
582 else if (detind[1] ==4){
583 indexLTM[1] = detind[2]+26;
584 }
585 else{
586 AliError("Smth Wrong!!!");
587 }
588 }
ee51d470 589
590}
591//-------------------------------------------------------------------------
592/*
593// to be checked because of warning problems
594void AliTOFTrigger::PrintMap()
595{
596 //
597 //
598 //
599
600 for(Int_t i = 0; i<kNLTM;i++) {
601 if(i<36) {
602 printf("| %d | %d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |\n",
603 (fCTTMmatrixFront[i][0])?1:0,(fCTTMmatrixFront[i][1])?1:0,(fCTTMmatrixFront[i][2])?1:0, \
604 (fCTTMmatrixFront[i][3])?1:0,(fCTTMmatrixFront[i][4])?1:0,(fCTTMmatrixFront[i][5])?1:0, \
605 (fCTTMmatrixFront[i][6])?1:0,(fCTTMmatrixFront[i][7])?1:0,(fCTTMmatrixFront[i][8])?1:0, \
606 (fCTTMmatrixFront[i][9])?1:0,(fCTTMmatrixFront[i][10])?1:0,(fCTTMmatrixFront[i][11])?1:0, \
607 (fCTTMmatrixFront[i][12])?1:0,(fCTTMmatrixFront[i][13])?1:0,(fCTTMmatrixFront[i][14])?1:0, \
608 (fCTTMmatrixFront[i][15])?1:0,(fCTTMmatrixFront[i][16])?1:0,(fCTTMmatrixFront[i][17])?1:0, \
609 (fCTTMmatrixFront[i][18])?1:0,(fCTTMmatrixFront[i][19])?1:0,(fCTTMmatrixFront[i][20])?1:0, \
610 (fCTTMmatrixFront[i][21])?1:0,(fCTTMmatrixFront[i][22])?1:0,(fCTTMmatrixFront[i][23])?1:0);
611 } else {
612 printf("| %d | %d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |\n",
613 (fCTTMmatrixBack[i][0])?1:0,(fCTTMmatrixBack[i][1])?1:0,(fCTTMmatrixBack[i][2])?1:0, \
614 (fCTTMmatrixBack[i][3])?1:0,(fCTTMmatrixBack[i][4])?1:0,(fCTTMmatrixBack[i][5])?1:0, \
615 (fCTTMmatrixBack[i][6])?1:0,(fCTTMmatrixBack[i][7])?1:0,(fCTTMmatrixBack[i][8])?1:0, \
616 (fCTTMmatrixBack[i][9])?1:0,(fCTTMmatrixBack[i][10])?1:0,(fCTTMmatrixBack[i][11])?1:0, \
617 (fCTTMmatrixBack[i][12])?1:0,(fCTTMmatrixBack[i][13])?1:0,(fCTTMmatrixBack[i][14])?1:0, \
618 (fCTTMmatrixBack[i][15])?1:0,(fCTTMmatrixBack[i][16])?1:0,(fCTTMmatrixBack[i][17])?1:0, \
619 (fCTTMmatrixBack[i][18])?1:0,(fCTTMmatrixBack[i][19])?1:0,(fCTTMmatrixBack[i][20])?1:0, \
620 (fCTTMmatrixBack[i][21])?1:0,(fCTTMmatrixBack[i][22])?1:0,(fCTTMmatrixBack[i][23])?1:0);
621 }
622 }
623
624}
625*/
626//-------------------------------------------------------------------------
627
42e171ac 628void AliTOFTrigger::GetMap(Bool_t **map) const
ee51d470 629{
630 //
42e171ac 631 // Returns CTTM map
ee51d470 632 //
633
634 for(Int_t i = 0; i<kNLTM;i++)
635 for(Int_t j = 0; j<kNCTTMchannels;j++)
8b5e4dc5 636 map[i][j]=(i<36)?fCTTMmatrixFront[i][j]:fCTTMmatrixBack[i-36][j];
ee51d470 637
638}
639
640//-------------------------------------------------------------------------
42e171ac 641void AliTOFTrigger::GetTRDmap(Bool_t **map) const
ee51d470 642{
643 //
644 // Retriev the bit map sent to the TRD detector
645 //
646
647 for(int i = 0; i<kNLTM;i++)
648 for(int j = 0; j<kNLTMtoTRDchannels;j++)
649 map[i][j]=kFALSE;
650
651 for(int i = 0; i<kNLTM/2;i++)
652 for(int j = 0; j<AliTOFTrigger::kNCTTMchannels;j++){
42e171ac 653 UInt_t uTRDbit=j/3;
654 if(fCTTMmatrixFront[i][j]) map[i][uTRDbit]=kTRUE;
ee51d470 655 }
656 for(int i = kNLTM/2; i<kNLTM;i++)
657 for(int j = 0; j<AliTOFTrigger::kNCTTMchannels;j++){
42e171ac 658 UInt_t uTRDbit=j/3;
8b5e4dc5 659 if(fCTTMmatrixBack[i - kNLTM/2][j]) map[i][uTRDbit]=kTRUE;
ee51d470 660 }
661}
662
663//-------------------------------------------------------------------------
664void AliTOFTrigger::SetBit(Int_t *detind)
665{
666 //
42e171ac 667 // Sets CTTM map element corresponding to detector element 'detind'
ee51d470 668 //
669
670 Int_t index[2];
671 GetCTTMIndex(detind,index);
672 if(index[0]<36)
673 fCTTMmatrixFront[index[0]][index[1]]=kTRUE;
674 else
4492324e 675 fCTTMmatrixBack[index[0]-36][index[1]]=kTRUE;
ee51d470 676
677}
678
679//-------------------------------------------------------------------------
680void AliTOFTrigger::SetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
681 Int_t iTDC, Int_t iCH)
682{
683 //
42e171ac 684 // Sets CTTM map element corresponding to equipment ID
685 // labelled by number nDDL, nTRM, iChain, iTDC, iCH
ee51d470 686 //
687
688 if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1){ // DDL number to LTM number mapping
689 Int_t iLTMindex=-1;
690 Int_t iChannelIndex=-1;
691 switch(nDDL%AliTOFGeometry::NDDL()){
692 case 1:
693 iLTMindex=1;
694 break;
695 case 3:
696 iLTMindex=36;
697 break;
698 default:
699 AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
700 break;
701 }
702 iLTMindex+=2*(Int_t)(nDDL/AliTOFGeometry::NDDL());
703 if(iChain==0 && nDDL<36)
704 iLTMindex--;
705 if(iChain==0 && nDDL>=36)
706 iLTMindex++;
707 iChannelIndex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
708 Int_t index[2]={iLTMindex,iChannelIndex};
709 if (index[0]<36)
710 fCTTMmatrixFront[index[0]][index[1]]=kTRUE;
711 else
4492324e 712 fCTTMmatrixBack[index[0]-36][index[1]]=kTRUE; // AdC
ee51d470 713 }
714 else
715 AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
716
717}
718//-------------------------------------------------------------------------
719
720void AliTOFTrigger::ResetBit(Int_t *detind)
721{
722 //
42e171ac 723 // Sets CTTM map element corresponding to detector element 'detind'
ee51d470 724 //
725
726 Int_t index[2];
727 GetCTTMIndex(detind,index);
728 if(index[0]<36)
729 fCTTMmatrixFront[index[0]][index[1]]=kFALSE;
730 else
4492324e 731 fCTTMmatrixBack[index[0]-36][index[1]]=kFALSE; // AdC
ee51d470 732
733}
734
735//-------------------------------------------------------------------------
736void AliTOFTrigger::ResetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
737 Int_t iTDC, Int_t iCH)
738{
739 //
42e171ac 740 // Sets CTTM map element corresponding to equipment ID
741 // labelled by number nDDL, nTRM, iChain, iTDC, iCH
ee51d470 742 //
743
744 if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1){ // DDL number to LTM number mapping
745 Int_t iLTMindex=-1;
746 Int_t iChannelIndex=-1;
747 switch(nDDL%AliTOFGeometry::NDDL()){
748 case 1:
749 iLTMindex=1;
750 break;
751 case 3:
752 iLTMindex=36;
753 break;
754 default:
755 AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
756 break;
757 }
758 iLTMindex+=2*(Int_t)(nDDL/AliTOFGeometry::NDDL());
759 if(iChain==0 && nDDL<36)
760 iLTMindex--;
761 if(iChain==0 && nDDL>=36)
762 iLTMindex++;
763 iChannelIndex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
764 Int_t index[2]={iLTMindex,iChannelIndex};
765 if (index[0]<36)
766 fCTTMmatrixFront[index[0]][index[1]]=kFALSE;
767 else
4492324e 768 fCTTMmatrixBack[index[0]-36][index[1]]=kFALSE; // AdC
ee51d470 769 }
770 else
771 AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
772
773}
774//-------------------------------------------------------------------------
775
776Bool_t AliTOFTrigger::GetBit(Int_t *detind)
777{
778 //
42e171ac 779 // Returns CTTM map element corresponding to detector element 'detind'
ee51d470 780 //
781
782 Int_t index[2];
783 GetCTTMIndex(detind,index);
4492324e 784 return (index[0]<36)?fCTTMmatrixFront[index[0]][index[1]]:fCTTMmatrixBack[index[0]-36][index[1]]; // AdC
ee51d470 785
786}
787
788//-------------------------------------------------------------------------
789Bool_t AliTOFTrigger::GetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
790 Int_t iTDC, Int_t iCH)
791{
792 //
42e171ac 793 // Returns CTTM map element corresponding to equipment ID
794 // labelled by number nDDL, nTRM, iChain, iTDC, iCH
ee51d470 795 //
796
797 if ( !(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ) {
798 AliWarning("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14) ");
799 return kFALSE;
800 }
801 //if (nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) { // DDL number to LTM number mapping
802
803 UInt_t iLTMindex=0;
804 UInt_t iChannelindex=0;
805 switch(nDDL%AliTOFGeometry::NDDL()) {
806 case 1:
807 iLTMindex=1;
808 break;
809 case 3:
810 iLTMindex=36;
811 break;
812 default:
813 AliError("something wrong");
814 break;
815 }
816 iLTMindex+=2*(Int_t)(nDDL/AliTOFGeometry::NDDL());
817
818 if (iChain==1) return kFALSE; // AdC
819
820 if (nDDL<36)
821 iLTMindex--;
822 if (nDDL>=36)
823 iLTMindex++;
824 iChannelindex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
825 Int_t index[2]={iLTMindex,iChannelindex};
4492324e 826 return (index[0]<36)?fCTTMmatrixFront[index[0]][index[1]]:fCTTMmatrixBack[index[0]-36][index[1]]; // AdC
ee51d470 827
828}
829
830//-------------------------------------------------------------------------
831
832void AliTOFTrigger::CreateCTTMMatrix() {
833 //
834 // Create CTTM bit map
835 //
836
837 for(Int_t i = 0; i<kNLTM;i++){
838 if(i<kNCTTM){
839 for(Int_t j = 0; j<kNCTTMchannels;j++)
840 fCTTMmatrixFront[i][j]=fLTMmatrix[i][2*j]||fLTMmatrix[i][2*j+1];
841 }
842 else{
843 for(Int_t j = 0; j<kNCTTMchannels;j++)
844 fCTTMmatrixBack[i-kNCTTM][j]=fLTMmatrix[i][2*j]||fLTMmatrix[i][2*j+1];;
845 }
846 }
847}
848//-----------------------------------------------------------------------------
849
850void AliTOFTrigger::GetCTTMIndex(Int_t *detind, Int_t *indexCTTM) {
851 //
42e171ac 852 // Returns CTTM index corresponding to the detector element detind
ee51d470 853 //
854
855 GetLTMIndex(detind,indexCTTM);
856 indexCTTM[1]/=2;
857
cd82ed2f 858}