]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFTrigger.cxx
minor change in macro
[u/mrichter/AliRoot.git] / TOF / AliTOFTrigger.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 //       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 //
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 //
32 /////////////////////////////////////////////////////////////////////
33
34 #include <TClonesArray.h>
35
36 #include "AliLoader.h"
37 #include "AliLog.h"
38 #include "AliRunLoader.h"
39 #include "AliRun.h"
40 #include "AliTriggerInput.h"
41 #include "AliRawReader.h"
42
43 #include "AliTOFRawStream.h"
44 #include "AliTOFrawData.h"
45 #include "AliTOFdigit.h"
46 #include "AliTOFGeometry.h"
47 #include "AliTOFTrigger.h"
48
49 extern AliRun* gAlice;
50
51 //-------------------------------------------------------------------------
52 ClassImp(AliTOFTrigger)
53
54 //----------------------------------------------------------------------
55   AliTOFTrigger::AliTOFTrigger() :
56     AliTriggerDetector(),
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 }
82
83 //----------------------------------------------------------------------
84
85 AliTOFTrigger::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(),
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
97 {
98   //ctor with thresholds for triggers
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
114 //____________________________________________________________________________
115
116 AliTOFTrigger::AliTOFTrigger(const AliTOFTrigger & tr):
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)
127 {
128   //copy ctor
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++){
135         fCTTMmatrixFront[i][j]=tr.fCTTMmatrixFront[i][j];
136         fCTTMmatrixBack[i][j]=tr.fCTTMmatrixBack[i][j];
137       }
138     }
139   }
140   SetName(tr.GetName());
141   CreateInputs();
142   //fInputs=&(tr.GetInputs());
143 }
144
145 //----------------------------------------------------------------------
146
147 void AliTOFTrigger::CreateInputs()
148 {
149   // creating inputs
150   // Do not create inputs again!!
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
160 }
161
162 //----------------------------------------------------------------------
163 void AliTOFTrigger::Trigger() {
164   //triggering method
165
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;
178
179   for (Int_t i=0;i<kNCTTM;i++){
180     for (Int_t j=0;j<kNCTTMchannels;j++){
181       if (fCTTMmatrixFront[i][j]) nchonFront++;
182     }
183   }
184
185   for (Int_t i=kNCTTM;i<(kNCTTM*2);i++){
186     for (Int_t j=0;j<kNCTTMchannels;j++){
187       if (fCTTMmatrixBack[i-kNCTTM][j]) nchonBack++;
188     }
189   }
190
191   nchonTot = nchonFront + nchonBack;
192
193   //pp Minimum Bias Trigger
194   if (nchonTot >= fppMBTh) {
195     SetInput("0OIN");
196   }
197
198   //High Multiplicity Trigger
199   if (nchonTot >= fHighMultTh) {
200     SetInput("0OHM");
201   }
202
203
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];
222         }
223         if (boolCTTMor) {
224           nchonFront++;
225         }
226       }
227
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];
266           }
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]) {
314                 SetInput("0OX1");
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]) {
328                   SetInput("0OX1");
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         }
340
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]) {
345                 SetInput("0OX1");
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]) {
359                   SetInput("0OX1");
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   }
374
375 }
376
377 //-----------------------------------------------------------------------------
378 void AliTOFTrigger::CreateLTMMatrix() {
379   //creating LTMMatrix
380   //initialization
381   CreateLTMMatrixFromDigits();
382 }
383
384 //-------------------------------------------------------------------------
385
386 void AliTOFTrigger::CreateLTMMatrixFromDigits() {
387   //
388   // Create LTM matrix by TOF digits
389   //
390
391   //initialization
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;
398   rl = AliRunLoader::Instance();
399
400   Int_t ncurrevent = rl->GetEventNumber();
401   rl->GetEvent(ncurrevent);
402
403   AliLoader * tofLoader = rl->GetLoader("TOFLoader");
404
405   tofLoader->LoadDigits("read");
406   TTree *treeD = tofLoader->TreeD();
407   if (treeD == 0x0)
408     {
409       AliFatal("AliTOFTrigger: Can not get TreeD");
410     }
411
412   TBranch *branch = treeD->GetBranch("TOF");
413   if (!branch) {
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
426
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();
434
435     Int_t indexLTM[2] = {-1,-1};
436     GetLTMIndex(detind,indexLTM);
437
438     fLTMmatrix[indexLTM[0]][indexLTM[1]] = kTRUE;
439   }
440
441   tofLoader->UnloadDigits();
442   //   rl->UnloadgAlice();
443   CreateCTTMMatrix();
444
445 }
446
447 //-----------------------------------------------------------------------------
448
449 void 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 //-----------------------------------------------------------------------------
539 void AliTOFTrigger::GetLTMIndex(const Int_t * const detind, Int_t *indexLTM) {
540   //
541   // getting LTMmatrix indexes for current digit
542   //
543
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
561   if (indexLTM[0]<36) {
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){
569       indexLTM[1] = detind[2]+19*2;
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   }
589
590 }
591 //-------------------------------------------------------------------------
592 /*
593 // to be checked because of warning problems
594 void 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
628 void AliTOFTrigger::GetMap(Bool_t **map) const
629 {
630   //
631   // Returns CTTM map
632   //
633
634   for(Int_t i = 0; i<kNLTM;i++)
635     for(Int_t j = 0; j<kNCTTMchannels;j++)
636       map[i][j]=(i<36)?fCTTMmatrixFront[i][j]:fCTTMmatrixBack[i-36][j];
637
638 }
639
640 //-------------------------------------------------------------------------
641 void AliTOFTrigger::GetTRDmap(Bool_t **map) const
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++){
653       UInt_t uTRDbit=j/3;
654       if(fCTTMmatrixFront[i][j]) map[i][uTRDbit]=kTRUE;
655     }
656   for(int i = kNLTM/2; i<kNLTM;i++)
657     for(int j = 0; j<AliTOFTrigger::kNCTTMchannels;j++){
658       UInt_t uTRDbit=j/3;
659       if(fCTTMmatrixBack[i - kNLTM/2][j]) map[i][uTRDbit]=kTRUE;
660     }
661 }
662
663 //-------------------------------------------------------------------------
664 void AliTOFTrigger::SetBit(Int_t *detind)
665 {
666   //
667   // Sets CTTM map element corresponding to detector element 'detind'
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
675     fCTTMmatrixBack[index[0]][index[1]]=kTRUE;
676
677 }
678
679 //-------------------------------------------------------------------------
680 void AliTOFTrigger::SetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
681                            Int_t iTDC, Int_t iCH)
682 {
683   //
684   // Sets CTTM map element corresponding to equipment ID
685   // labelled by number nDDL, nTRM, iChain, iTDC, iCH
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
712       fCTTMmatrixBack[index[0]][index[1]]=kTRUE;
713   }
714   else
715     AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
716
717 }
718 //-------------------------------------------------------------------------
719
720 void AliTOFTrigger::ResetBit(Int_t *detind)
721 {
722   //
723   // Sets CTTM map element corresponding to detector element 'detind'
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
731     fCTTMmatrixBack[index[0]][index[1]]=kFALSE;
732
733 }
734
735 //-------------------------------------------------------------------------
736 void AliTOFTrigger::ResetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
737                              Int_t iTDC, Int_t iCH)
738 {
739   //
740   // Sets CTTM map element corresponding to equipment ID
741   // labelled by number nDDL, nTRM, iChain, iTDC, iCH
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
768       fCTTMmatrixBack[index[0]][index[1]]=kFALSE;
769   }
770   else
771     AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
772
773 }
774 //-------------------------------------------------------------------------
775
776 Bool_t AliTOFTrigger::GetBit(Int_t *detind)
777 {
778   //
779   // Returns CTTM map element corresponding to detector element 'detind'
780   //
781
782   Int_t index[2];
783   GetCTTMIndex(detind,index);
784   return (index[0]<36)?fCTTMmatrixFront[index[0]][index[1]]:fCTTMmatrixBack[index[0]][index[1]];
785
786 }
787
788 //-------------------------------------------------------------------------
789 Bool_t AliTOFTrigger::GetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
790                              Int_t iTDC, Int_t iCH)
791 {
792   //
793   // Returns CTTM map element corresponding to equipment ID
794   // labelled by number nDDL, nTRM, iChain, iTDC, iCH
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};
826   return (index[0]<36)?fCTTMmatrixFront[index[0]][index[1]]:fCTTMmatrixBack[index[0]][index[1]];
827
828 }
829
830 //-------------------------------------------------------------------------
831
832 void 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
850 void AliTOFTrigger::GetCTTMIndex(Int_t *detind, Int_t *indexCTTM) {
851   //
852   // Returns CTTM index corresponding to the detector element detind
853   //
854
855   GetLTMIndex(detind,indexCTTM);
856   indexCTTM[1]/=2;
857
858 }