]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFTrigger.cxx
small fix
[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 #include <TTree.h>
36 #include <TMath.h>
37
38 #include "AliLoader.h"
39 #include "AliLog.h"
40 #include "AliRunLoader.h"
41 #include "AliRun.h"
42 #include "AliTriggerInput.h"
43 #include "AliRawReader.h"
44
45 #include "AliTOFRawStream.h"
46 #include "AliTOFrawData.h"
47 #include "AliTOFdigit.h"
48 #include "AliTOFGeometry.h"
49 #include "AliTOFTrigger.h"
50 #include "AliTOFTriggerMask.h"
51
52 #include "AliCDBManager.h"
53 #include "AliCDBEntry.h"
54
55
56 extern AliRun* gAlice;
57
58 AliTOFTriggerMask* AliTOFTrigger:: fTOFTrigMap=NULL;
59 AliTOFTriggerMask* AliTOFTrigger:: fTOFTrigMask=NULL;
60 //-------------------------------------------------------------------------
61 ClassImp(AliTOFTrigger)
62
63 //----------------------------------------------------------------------
64   AliTOFTrigger::AliTOFTrigger() :
65     AliTriggerDetector(),
66     fHighMultTh(1000),
67     fppMBTh(4),//4:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
68     fMultiMuonTh(4),
69     fUPTh(2),
70     fdeltaminpsi(150), //150
71     fdeltamaxpsi(170), //170
72     fdeltaminro(70),
73     fdeltamaxro(110),
74     fstripWindow(2),
75     fSel1(0),
76     fSel2(0),
77     fSel3(0),
78     fSel4(0),
79     fNCrateOn(0),
80     fNMaxipadOn(0),
81     fNMaxipadOnAll(0),
82     fStartTimeHit(0.0),
83     fTimeWidthTrigger(25.0)
84
85 {
86   //main ctor
87   for (Int_t i=0;i<kNCTTM;i++) fLTMarray[i] = kFALSE;
88
89   for (Int_t i=0;i<kNLTM;i++){
90
91     for (Int_t j=0;j<kNLTMchannels;j++){
92       fLTMmatrix[i][j]=kFALSE;
93     }
94     if (i<kNCTTM){
95       for (Int_t j=0;j<kNCTTMchannels;j++){
96         fCTTMmatrixFront[i][j]=kFALSE;
97         fCTTMmatrixBack[i][j]=kFALSE;
98       }
99     }
100   }
101
102   fPowerMask[0] = 1;
103   for(Int_t i=1;i <= kNCTTMchannels;i++){
104       fPowerMask[i] = fPowerMask[i-1]*2;
105   }
106
107   SetName("TOF");
108   CreateInputs();
109
110   if(!fTOFTrigMap) fTOFTrigMap = new AliTOFTriggerMask();
111
112 }
113
114 //----------------------------------------------------------------------
115
116 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,Float_t startTimeWindow,Float_t widthTimeWindow) :
117   AliTriggerDetector(),
118   fHighMultTh(HighMultTh),
119   fppMBTh(ppMBTh),
120   fMultiMuonTh(MultiMuonTh),
121   fUPTh(UPTh),
122   fdeltaminpsi(deltaminpsi),
123   fdeltamaxpsi(deltamaxpsi),
124   fdeltaminro(deltaminro),
125   fdeltamaxro(deltamaxro),
126   fstripWindow(stripWindow),
127   fSel1(0),
128   fSel2(0),
129   fSel3(0),
130   fSel4(0),
131   fNCrateOn(0),
132   fNMaxipadOn(0),
133   fNMaxipadOnAll(0),
134   fStartTimeHit(startTimeWindow),
135   fTimeWidthTrigger(widthTimeWindow)
136 {
137   //ctor with thresholds for triggers
138   for (Int_t i=0;i<kNCTTM;i++) fLTMarray[i] = kFALSE;
139   for (Int_t i=0;i<kNLTM;i++){
140     for (Int_t j=0;j<kNLTMchannels;j++){
141       fLTMmatrix[i][j]=kFALSE;
142     }
143     if (i<kNCTTM){
144       for (Int_t j=0;j<kNCTTMchannels;j++){
145         fCTTMmatrixFront[i][j]=kFALSE;
146         fCTTMmatrixBack[i][j]=kFALSE;
147       }
148     }
149   }
150
151   fPowerMask[0] = 1;
152   for(Int_t i=1;i <= kNCTTMchannels;i++){
153       fPowerMask[i] = fPowerMask[i-1]*2;
154   }
155
156   SetName("TOF");
157   CreateInputs();
158
159   if(!fTOFTrigMap) fTOFTrigMap = new AliTOFTriggerMask();
160 }
161
162
163 #if 0 /*** COPY CONSTRUCTOR SUPPRESSED **/
164 //____________________________________________________________________________
165
166 AliTOFTrigger::AliTOFTrigger(const AliTOFTrigger & tr):
167   AliTriggerDetector(tr),
168   fHighMultTh(tr.fHighMultTh),
169   fppMBTh(tr.fppMBTh),
170   fMultiMuonTh(tr.fMultiMuonTh),
171   fUPTh(tr.fUPTh),
172   fdeltaminpsi(tr.fdeltaminpsi),
173   fdeltamaxpsi(tr.fdeltamaxpsi),
174   fdeltaminro(tr.fdeltaminro),
175   fdeltamaxro(tr.fdeltamaxro),
176   fstripWindow(tr.fstripWindow),
177   fSel1(tr.fSel1),
178   fSel2(tr.fSel2),
179   fSel3(tr.fSel3),
180   fSel4(tr.fSel4),
181   fNCrateOn(tr.fNCrateOn),
182   fNMaxipadOn(tr.fNMaxipadOn),
183   fNMaxipadOnAll(tr.fNMaxipadOnAll)
184 {
185   //copy ctor
186   for (Int_t i=0;i<kNCTTM;i++) fLTMarray[i] = kFALSE;
187   for (Int_t i=0;i<kNLTM;i++){
188     for (Int_t j=0;j<kNLTMchannels;j++){
189       fLTMmatrix[i][j]=tr.fLTMmatrix[i][j];
190     }
191     if (i<kNCTTM){
192       for (Int_t j=0;j<kNCTTMchannels;j++){
193         fCTTMmatrixFront[i][j]=tr.fCTTMmatrixFront[i][j];
194         fCTTMmatrixBack[i][j]=tr.fCTTMmatrixBack[i][j];
195       }
196     }
197   }
198
199   fPowerMask[0] = 1;
200   for(Int_t i=1;i <= kNCTTMchannels;i++){
201       fPowerMask[i] = fPowerMask[i-1]*2;
202   }
203
204   SetName(tr.GetName());
205   //fInputs=&(tr.GetInputs());
206   CreateInputs();
207
208 }
209 #endif /*** COPY CONTRUCTOR SUPPRESSED ***/
210
211 //----------------------------------------------------------------------
212
213 void AliTOFTrigger::CreateInputs()
214 {
215   // creating inputs
216   // Do not create inputs again!!
217   if( fInputs.GetEntriesFast() > 0 ) return;
218
219   //LoadActiveMask();
220
221   fInputs.AddLast(new AliTriggerInput("TOF_Cosmic_MultiMuon_L0","TOF",0));
222   fInputs.AddLast(new AliTriggerInput("0OIN","TOF",0)); // was "TOF_pp_MB_L0"
223   fInputs.AddLast(new AliTriggerInput("0OM2","TOF",0)); // was "TOF_PbPb_MB2_L0"
224   fInputs.AddLast(new AliTriggerInput("0OM3","TOF",0)); // was "TOF_PbPb_MB3_L0"
225   fInputs.AddLast(new AliTriggerInput("0OUP","TOF",0)); // was "TOF_UltraPer_Coll_L0"
226   fInputs.AddLast(new AliTriggerInput("0OMU","TOF",0)); // new trigger (150 < DeltaPhi < 180) and 2 <= N_pad <= 6
227
228   fInputs.AddLast(new AliTriggerInput("0OHM","TOF",0)); // was "TOF_High_Mult_L0"
229   fInputs.AddLast(new AliTriggerInput("TOF_Jet_L1","TOF",0));
230
231 }
232
233 //----------------------------------------------------------------------
234 void AliTOFTrigger::Trigger() {
235   fTOFTrigMap->ResetMask();
236   if(!fTOFTrigMask) LoadActiveMask();
237
238   //triggering method
239   fSel1=0;
240   fSel2=0;
241   fSel3=0;
242   fSel4=0;
243
244   CreateLTMMatrix();
245
246   Int_t nchonFront = 0;
247   Int_t nchonBack = 0;
248   Int_t nchonTot = 0;
249   Int_t nSectOn = 0; // Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°
250   Int_t DeSlots = -1;// Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°
251   Int_t AntiDeSlots = -1;// Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°
252   Int_t nchonFrontBack = 0;
253   Int_t nchonFront1 = 0;
254   Int_t nchonBack1 = 0;
255   Int_t nchonFrontBack1 = 0;
256   Int_t mindeltapsi = (Int_t)fdeltaminpsi/10;
257   Int_t maxdeltapsi = (Int_t)fdeltamaxpsi/10;
258   Int_t mindeltaro = (Int_t)fdeltaminro/10;
259   Int_t maxdeltaro = (Int_t)fdeltamaxro/10;
260
261   for (Int_t i=0;i<kNCTTM;i++){
262     for (Int_t j=0;j<kNCTTMchannels;j++){
263       if (fCTTMmatrixFront[i][j]){
264         nchonFront++;
265         fTOFTrigMap->SetON(i,j);
266       }
267     }
268   }
269
270   for (Int_t i=kNCTTM;i<(kNCTTM*2);i++){
271     for (Int_t j=0;j<kNCTTMchannels;j++){
272       if (fCTTMmatrixBack[i-kNCTTM][j]){
273         nchonBack++;
274         fTOFTrigMap->SetON(i,j);
275       }
276     }
277   }
278
279   nchonTot = nchonFront + nchonBack;
280 //  fNMaxipadOn = nchonTot;
281   for(Int_t i=0;i<kNCTTM;i++) { if(fLTMarray[i]) nSectOn++; } 
282
283   //pp Minimum Bias Trigger
284   if (nchonTot >= fppMBTh) {
285     SetInput("0OIN");
286     fSel1=1;
287     //printf("0OIN - MB\n");
288   }
289
290   // PbPb MB
291   if (nchonTot >= 2) {
292     SetInput("0OM2");
293     fSel2=1;
294   }
295   if (nchonTot >= 3) {
296     SetInput("0OM3");
297     fSel3=1;
298   }
299
300   //High Multiplicity Trigger
301   if (nchonTot >= fHighMultTh) {
302     SetInput("0OHM");
303     //printf("0OHM - High Mult\n");
304   }
305
306
307   //MultiMuon Trigger
308   nchonFront = 0;
309   nchonBack = 0;
310   nchonFrontBack = 0;
311
312   Bool_t boolCTTMor = kFALSE;
313
314   for (Int_t i=0;i<(kNCTTM/2);i++){
315     Int_t iopp = i+kNCTTM/2;
316     for (Int_t j=0;j<kNCTTMchannels;j++){
317       if (fCTTMmatrixFront[i][j]){
318         Int_t minj = j-fstripWindow;
319         Int_t maxj = j+fstripWindow;
320         if (minj<0) minj =0;
321         if (maxj>=kNCTTMchannels) maxj = kNCTTMchannels-1;
322         boolCTTMor = kFALSE;
323         for (Int_t k = minj;k<=maxj;k++){
324           boolCTTMor |= fCTTMmatrixFront[iopp][k];
325         }
326         if (boolCTTMor) {
327           nchonFront++;
328         }
329       }
330
331       if (fCTTMmatrixBack[i][j]){
332         Int_t minj = j-fstripWindow;
333         Int_t maxj = j+fstripWindow;
334         if (minj<0) minj =0;
335         if (maxj>=kNCTTMchannels) maxj =kNCTTMchannels-1;
336         boolCTTMor = kFALSE;
337         for (Int_t k = minj;k<=maxj;k++){
338           boolCTTMor |= fCTTMmatrixBack[iopp][k];
339         }
340         if (boolCTTMor) {
341           nchonBack++;
342         }
343       }
344     }
345   }
346
347   nchonFrontBack = nchonFront+nchonBack;
348
349   nchonFront1 = 0;
350   nchonBack1 = 0;
351   nchonFrontBack1 = 0;
352
353   boolCTTMor = kFALSE;
354   for (Int_t i=0;i<(kNCTTM/2);i++){
355     Int_t i2max = (kNCTTM-1)-i+1;
356     Int_t i2min = (kNCTTM-1)-i-1;
357     if (i2max >=kNCTTM) i2max = kNCTTM-1;
358     if (i2min==i) i2min = kNCTTM-1-i;
359     for (Int_t j=0;j<kNCTTMchannels;j++){
360       Int_t j2min = j-fstripWindow;
361       Int_t j2max = j+fstripWindow;
362       if (j2min<0) j2min =0;
363       if (j2max>=kNCTTMchannels) j2max =kNCTTMchannels-1;
364       if (fCTTMmatrixFront[i][j]){
365         boolCTTMor = kFALSE;
366         for (Int_t i2=i2min;i2<=i2max;i2++){
367           for (Int_t j2 = j2min;j2<=j2max;j2++){
368             boolCTTMor |= fCTTMmatrixFront[i2][j2];
369           }
370           if (boolCTTMor) {
371             nchonFront++;
372           }
373         }
374       }
375       if (fCTTMmatrixBack[i][j]){
376           boolCTTMor = kFALSE;
377           for (Int_t i2=i2min;i2<=i2max;i2++){
378               for (Int_t j2 = j2min;j2<=j2max;j2++){
379                   boolCTTMor |= fCTTMmatrixBack[i2][j2];
380               }
381           }
382           if (boolCTTMor) {
383               nchonBack++;
384           }
385       }
386     }
387   }
388   
389   nchonFrontBack1 = nchonFront1+nchonBack1;
390   
391   if (nchonFrontBack >= fMultiMuonTh || nchonFrontBack1 >= fMultiMuonTh) {
392       SetInput("TOF_Cosmic_MultiMuon_L0");
393   }
394   
395   //Ultra-Peripheral collision Trigger
396   
397   // Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°Â°
398   // DeSlots = (k+1)_Array Element - k_Array Element
399   // AntiDeSlots = kNCTTM - DeSlots
400   
401   if((!fSel1))// && nchonFront < 4 && nchonBack < 4)
402   {  
403       // printf("nHitMaxipad CLASSE: %i \n",fNMaxipadOn);
404       // printf("Total Number per event of Switched-On sectors : %i \n", nSectOn);
405       // printf("mindeltapsi %i \n", mindeltapsi);
406       //printf("maxdeltapsi %i \n", maxdeltapsi); 
407       for(Int_t i = 0; i < kNCTTM; i++){    
408           if(fLTMarray[i]){
409               // printf(" i-sect On:  %i\n",i);
410               for(Int_t j = i+1; j < kNCTTM; j++){
411                   if(fLTMarray[j]) {
412                       //  printf(" j-sect On:  %i\n",j);
413                       DeSlots = j-i;
414                       AntiDeSlots = kNCTTM - DeSlots;
415                       //printf("DeSlots = %i \n",DeSlots);
416                       //printf("AntiDeSlots = %i \n",AntiDeSlots);
417                       if(DeSlots >= mindeltapsi && DeSlots <= maxdeltapsi){
418                           fSel4=1;
419                           SetInput("0OUP");
420                           //printf("trigger On with DeSlot \n");
421                       }
422                       if(AntiDeSlots >= mindeltapsi && AntiDeSlots <= maxdeltapsi){
423                           fSel4=1;
424                           SetInput("0OUP");
425                           //printf("trigger On with AntiDeSlot \n");
426                       }
427                       
428                       
429                       if(DeSlots >= mindeltaro && DeSlots <= maxdeltaro){
430                           fSel4=1;
431                           SetInput("0OUP");
432                           //printf("trigger On with DeSlot \n");
433                       }
434                       if(AntiDeSlots >= mindeltaro && AntiDeSlots <= maxdeltaro){
435                           fSel4=1;
436                           SetInput("0OUP");
437                           //printf("trigger On with AntiDeSlot \n");
438                       } 
439                       
440                       if(nchonTot >= 2 && nchonTot <= 6){
441                         if(DeSlots >= 15 && DeSlots <= 18){
442                           SetInput("0OMU");
443                         }
444                         else if(AntiDeSlots >= 15 && AntiDeSlots <= 18){
445                           SetInput("0OMU");
446                         }       
447                       }               
448                   }
449               }    
450           }
451       }
452   } 
453 }
454
455 //-----------------------------------------------------------------------------
456 void AliTOFTrigger::CreateLTMMatrix() {
457   //creating LTMMatrix
458   //initialization
459   CreateLTMMatrixFromDigits();
460   CreateCTTMMatrix();
461 }
462
463 //-------------------------------------------------------------------------
464
465 void AliTOFTrigger::CreateLTMMatrixFromDigits() {
466   //
467   // Create LTM matrix by TOF digits
468   //
469
470   //initialization
471   for (Int_t i=0;i<kNCTTM;i++) fLTMarray[i]= kFALSE;
472   for (Int_t i=0;i<kNLTM;i++){
473     for (Int_t j=0;j<kNLTMchannels;j++){
474       fLTMmatrix[i][j]=kFALSE;
475     }
476   }
477   for (Int_t i=0;i<kNCTTM;i++){
478       for (Int_t j=0;j<kNCTTMchannels;j++){
479           fCTTMmatrixFront[i][j]=kFALSE;
480           fCTTMmatrixBack[i][j]=kFALSE;
481       }
482   }
483
484
485   AliRunLoader *rl;
486   rl = AliRunLoader::Instance();
487
488   Int_t ncurrevent = rl->GetEventNumber();
489   rl->GetEvent(ncurrevent);
490
491   AliLoader * tofLoader = rl->GetLoader("TOFLoader");
492
493   tofLoader->LoadDigits("read");
494   TTree *treeD = tofLoader->TreeD();
495   if (treeD == 0x0) {
496     AliFatal("AliTOFTrigger: Can not get TreeD");
497     return;
498   }
499
500   TBranch *branch = treeD->GetBranch("TOF");
501   if (!branch) {
502     AliError("can't get the branch with the TOF digits !");
503     return;
504   }
505   TClonesArray *tofDigits =new TClonesArray("AliTOFdigit",  1000);
506   branch->SetAddress(&tofDigits);
507   treeD->GetEvent(0);
508   Int_t ndigits = tofDigits->GetEntriesFast();
509   Int_t detind[5]; //detector indexes: 0 -> sector
510   //                                   1 -> plate(modulo)
511   //                                   2 -> strip
512   //                                   3 -> padz
513   //                                   4 -> padx
514
515   for (Int_t i=0;i<ndigits;i++){
516     AliTOFdigit * digit = (AliTOFdigit*)tofDigits->UncheckedAt(i);
517     detind[0] = digit->GetSector();
518     detind[1] = digit->GetPlate();
519     detind[2] = digit->GetStrip();
520     detind[3] = digit->GetPadz();
521     detind[4] = digit->GetPadx();
522
523     Int_t indexLTM[2] = {-1,-1};
524     GetLTMIndex(detind,indexLTM);
525
526     //Float_t timedigit = digit->GetTdc()*AliTOFGeometry::TdcBinWidth()*1E-3; // decalibrated time digit in ns
527     Float_t timedigit = digit->GetTdcND()*AliTOFGeometry::TdcBinWidth()*1E-3; // time digit in ns
528
529     Float_t pos[3];
530     AliTOFGeometry::GetPosPar(detind, pos);
531     Float_t length = 0.;
532     for (Int_t ic = 0; ic < 3; ic++) length += pos[ic] * pos[ic];
533     length = TMath::Sqrt(length);
534     timedigit -= length * 0.0333564095198152043; // subtract the minimal time in ns for the current channel
535
536     if(timedigit > fStartTimeHit - 0.5 && timedigit < fStartTimeHit + fTimeWidthTrigger - 0.5)
537       fLTMmatrix[indexLTM[0]][indexLTM[1]] = kTRUE;
538
539 //    fLTMarray[indexLTM[0]%36] = kTRUE; //dimensione MAX array 36 = kNCTTM 
540   }
541
542
543   tofLoader->UnloadDigits();
544   //   rl->UnloadgAlice();
545
546 }
547
548 //-----------------------------------------------------------------------------
549
550 void AliTOFTrigger::CreateLTMMatrixFromRaw(AliRawReader *fRawReader) {
551   //
552   // Create LTM matrix by TOF raw data
553   //
554   fTOFTrigMap->ResetMask();
555
556   //initialization
557   for (Int_t i=0;i<kNLTM;i++){
558     for (Int_t j=0;j<kNLTMchannels;j++){
559       fLTMmatrix[i][j]=kFALSE;
560     }
561   }
562   for (Int_t i=0;i<kNCTTM;i++){
563       for (Int_t j=0;j<kNCTTMchannels;j++){
564           fCTTMmatrixFront[i][j]=kFALSE;
565           fCTTMmatrixBack[i][j]=kFALSE;
566       }
567   }
568
569   if(fRawReader){
570     AliTOFRawStream * tofRawStream = new AliTOFRawStream();
571
572     Int_t inholes = 0;
573
574     //if(!GetLoader()->TreeS()) {MakeTree("S");  MakeBranch("S");}
575     
576     Clear();
577     tofRawStream->SetRawReader(fRawReader);
578     
579     //ofstream ftxt;
580     //if (fVerbose==2) ftxt.open("TOFsdigitsRead.txt",ios::app);
581     
582     TClonesArray staticRawData("AliTOFrawData",10000);
583     staticRawData.Clear();
584     TClonesArray * clonesRawData = &staticRawData;
585     
586     Int_t dummy = -1;
587     Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
588     
589     Int_t indexDDL = 0;
590     Int_t iRawData = 0;
591     AliTOFrawData *tofRawDatum = 0;
592     for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
593       
594       fRawReader->Reset();
595       tofRawStream->LoadRawDataBuffersV2(indexDDL);
596       
597       clonesRawData = tofRawStream->GetRawData();
598       if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
599       for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
600         
601         tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
602         
603         //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
604         if (tofRawDatum->GetTOF()==-1) continue;
605         
606         SetBit(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
607                tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel());
608
609         dummy = detectorIndex[3];
610         detectorIndex[3] = detectorIndex[4];//padz
611         detectorIndex[4] = dummy;//padx
612
613         dummy = detectorIndex[3];
614         detectorIndex[3] = detectorIndex[4];//padx
615         detectorIndex[4] = dummy;//padz
616
617         // Do not reconstruct anything in the holes
618         if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
619           if (detectorIndex[1]==2) { // plate with holes
620             inholes++;
621             continue;
622           }
623         }
624
625         tofRawDatum = 0;
626       } // while loop
627
628       clonesRawData->Clear();
629
630     } // DDL Loop
631
632     //if (fVerbose==2) ftxt.close();
633
634     if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
635     delete tofRawStream;
636     tofRawStream = NULL;
637
638   }
639
640 }
641 //-----------------------------------------------------------------------------
642 void AliTOFTrigger::PrepareTOFMapFromRaw(AliRawReader *fRawReader,Int_t deltaBC) {
643   //
644   // Create LTM matrix by TOF raw data
645   //
646   if(!fTOFTrigMap) fTOFTrigMap = new AliTOFTriggerMask();
647   fTOFTrigMap->ResetMask();
648   LoadActiveMask();
649
650   if(fRawReader){
651     AliTOFRawStream * tofRawStream = new AliTOFRawStream();
652
653     tofRawStream->SetRawReader(fRawReader);
654         
655     TClonesArray staticRawData("AliTOFrawData",10000);
656     staticRawData.Clear();
657     TClonesArray * clonesRawData = &staticRawData;
658     
659     Int_t indexDDL = 0;
660     Int_t iRawData = 0;
661     AliTOFrawData *tofRawDatum = 0;
662     for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
663       
664       fRawReader->Reset();
665       tofRawStream->LoadRawDataBuffersV2(indexDDL);
666       
667       clonesRawData = tofRawStream->GetRawData();
668       for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
669         
670         tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
671         
672         //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
673         if (tofRawDatum->GetTOF()==-1) continue;
674
675         Int_t nTRM = tofRawDatum->GetTRM();
676         Int_t iChain = tofRawDatum->GetTRMchain();
677         Int_t iTDC = tofRawDatum->GetTDC();
678         Int_t iCH=tofRawDatum->GetTDCchannel();
679
680         if(nTRM==3 && iTDC>=12 && iTDC<=14 && indexDDL%2==1){ // DDL number to LTM number mapping
681           Int_t iLTMindex=-1;
682           Int_t iChannelIndex=-1;
683           switch(indexDDL%AliTOFGeometry::NDDL()){
684           case 1:
685             iLTMindex=1;
686             break;
687           case 3:
688             iLTMindex=36;
689             break;
690           default:
691             break;
692           }
693           iLTMindex+=2*(Int_t)(indexDDL/AliTOFGeometry::NDDL());
694           if(iChain==0 && indexDDL<36)
695             iLTMindex--;
696           if(iChain==0 && indexDDL>=36)
697             iLTMindex++;
698           iChannelIndex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
699           Int_t index[2]={iLTMindex,iChannelIndex};
700           
701           
702           if(fTOFTrigMask->IsON(index[0],index[1]) && TMath::Abs(tofRawDatum->GetTOF()-deltaBC) < 400) fTOFTrigMap->SetON(index[0],index[1]);
703         }
704         
705         tofRawDatum = 0;
706       } // while loop
707
708       clonesRawData->Clear();
709
710     } // DDL Loop
711
712
713     delete tofRawStream;
714     tofRawStream = NULL;
715
716   }
717
718 }
719 //-----------------------------------------------------------------------------
720 void AliTOFTrigger::PrepareTOFMapFromDigit(TTree *treeD) {
721   if(!fTOFTrigMap) fTOFTrigMap = new AliTOFTriggerMask();
722   LoadActiveMask();
723
724   fTOFTrigMap->ResetMask();
725   if (treeD == 0x0) {
726     return;
727   }
728
729   TBranch *branch = treeD->GetBranch("TOF");
730   if (!branch) {
731     return;
732   }
733   TClonesArray *tofDigits =new TClonesArray("AliTOFdigit",  1000);
734   branch->SetAddress(&tofDigits);
735   treeD->GetEvent(0);
736   Int_t ndigits = tofDigits->GetEntriesFast();
737   Int_t detind[5]; //detector indexes: 0 -> sector
738   //                                   1 -> plate(modulo)
739   //                                   2 -> strip
740   //                                   3 -> padz
741   //                                   4 -> padx
742
743   for (Int_t i=0;i<ndigits;i++){
744     AliTOFdigit * digit = (AliTOFdigit*)tofDigits->UncheckedAt(i);
745     detind[0] = digit->GetSector();
746     detind[1] = digit->GetPlate();
747     detind[2] = digit->GetStrip();
748     detind[3] = digit->GetPadz();
749     detind[4] = digit->GetPadx();
750
751     Int_t indexLTM[2] = {-1,-1};
752     GetLTMIndex(detind,indexLTM);
753
754     if(fTOFTrigMask->IsON(indexLTM[0],indexLTM[1])) fTOFTrigMap->SetON(indexLTM[0],indexLTM[1]);
755   }
756
757 }
758 //-----------------------------------------------------------------------------
759 void AliTOFTrigger::GetLTMIndex(const Int_t * const detind, Int_t *indexLTM) {
760   //
761   // getting LTMmatrix indexes for current digit
762   //
763
764   if (detind[1]==0 || detind[1]==1 || (detind[1]==2 && detind[2]<=7)) {
765     if (detind[4]<24){
766       indexLTM[0] = detind[0]*2;
767     }
768     else {
769       indexLTM[0] = detind[0]*2+1;
770     }
771   }
772   else {
773     if (detind[4]<24){
774       indexLTM[0] = detind[0]*2+36;
775     }
776     else {
777       indexLTM[0] = (detind[0]*2+1)+36;
778     }
779   }
780
781   if (indexLTM[0]<36) {
782     if (detind[1] ==0){
783       indexLTM[1] = detind[2];
784     }
785     else if (detind[1] ==1){
786       indexLTM[1] = detind[2]+19;
787     }
788     else if (detind[1] ==2){
789       indexLTM[1] = detind[2]+19*2;
790     }
791     else{
792       //      AliError("Smth Wrong!!!");
793     }
794   }
795   else {
796     if (detind[1] ==2){
797       indexLTM[1] = detind[2]-8;
798     }
799     else if (detind[1] ==3){
800       indexLTM[1] = detind[2]+7;
801     }
802     else if (detind[1] ==4){
803       indexLTM[1] = detind[2]+26;
804     }
805     else{
806       //      AliError("Smth Wrong!!!");
807     }
808   }
809
810 }
811 //-------------------------------------------------------------------------
812 /*
813 // to be checked because of warning problems
814 void AliTOFTrigger::PrintMap()
815 {
816   //
817   //
818   //
819
820   for(Int_t i = 0; i<kNLTM;i++) {
821     if(i<36) {
822       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",
823              (fCTTMmatrixFront[i][0])?1:0,(fCTTMmatrixFront[i][1])?1:0,(fCTTMmatrixFront[i][2])?1:0, \
824              (fCTTMmatrixFront[i][3])?1:0,(fCTTMmatrixFront[i][4])?1:0,(fCTTMmatrixFront[i][5])?1:0, \
825              (fCTTMmatrixFront[i][6])?1:0,(fCTTMmatrixFront[i][7])?1:0,(fCTTMmatrixFront[i][8])?1:0, \
826              (fCTTMmatrixFront[i][9])?1:0,(fCTTMmatrixFront[i][10])?1:0,(fCTTMmatrixFront[i][11])?1:0, \
827              (fCTTMmatrixFront[i][12])?1:0,(fCTTMmatrixFront[i][13])?1:0,(fCTTMmatrixFront[i][14])?1:0, \
828              (fCTTMmatrixFront[i][15])?1:0,(fCTTMmatrixFront[i][16])?1:0,(fCTTMmatrixFront[i][17])?1:0, \
829              (fCTTMmatrixFront[i][18])?1:0,(fCTTMmatrixFront[i][19])?1:0,(fCTTMmatrixFront[i][20])?1:0, \
830              (fCTTMmatrixFront[i][21])?1:0,(fCTTMmatrixFront[i][22])?1:0,(fCTTMmatrixFront[i][23])?1:0);
831     } else {
832       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",
833              (fCTTMmatrixBack[i][0])?1:0,(fCTTMmatrixBack[i][1])?1:0,(fCTTMmatrixBack[i][2])?1:0, \
834              (fCTTMmatrixBack[i][3])?1:0,(fCTTMmatrixBack[i][4])?1:0,(fCTTMmatrixBack[i][5])?1:0, \
835              (fCTTMmatrixBack[i][6])?1:0,(fCTTMmatrixBack[i][7])?1:0,(fCTTMmatrixBack[i][8])?1:0, \
836              (fCTTMmatrixBack[i][9])?1:0,(fCTTMmatrixBack[i][10])?1:0,(fCTTMmatrixBack[i][11])?1:0, \
837              (fCTTMmatrixBack[i][12])?1:0,(fCTTMmatrixBack[i][13])?1:0,(fCTTMmatrixBack[i][14])?1:0, \
838              (fCTTMmatrixBack[i][15])?1:0,(fCTTMmatrixBack[i][16])?1:0,(fCTTMmatrixBack[i][17])?1:0, \
839              (fCTTMmatrixBack[i][18])?1:0,(fCTTMmatrixBack[i][19])?1:0,(fCTTMmatrixBack[i][20])?1:0, \
840              (fCTTMmatrixBack[i][21])?1:0,(fCTTMmatrixBack[i][22])?1:0,(fCTTMmatrixBack[i][23])?1:0);
841     }
842   }
843
844 }
845 */
846 //-------------------------------------------------------------------------
847
848 void AliTOFTrigger::GetMapMatrix(Bool_t map[][24]) const
849 {
850   //
851   // Returns CTTM map
852   //
853
854   for(Int_t i = 0; i<kNLTM;i++)
855     for(Int_t j = 0; j<kNCTTMchannels;j++)
856       map[i][j]=(i<36)?fCTTMmatrixFront[i][j]:fCTTMmatrixBack[i-36][j];
857
858 }
859 //-------------------------------------------------------------------------
860
861 void AliTOFTrigger::GetMap(Bool_t **map) const
862 {
863   //
864   // Returns CTTM map
865   //
866
867   for(Int_t i = 0; i<kNLTM;i++)
868     for(Int_t j = 0; j<kNCTTMchannels;j++)
869       map[i][j]=(i<36)?fCTTMmatrixFront[i][j]:fCTTMmatrixBack[i-36][j];
870
871 }
872
873
874 //-------------------------------------------------------------------------
875 void AliTOFTrigger::GetTRDmap(Bool_t **map) const
876 {
877   //
878   // Retriev the bit map sent to the TRD detector
879   //
880     
881     for(int i = 0; i<kNLTM;i++)
882         for(int j = 0; j<kNLTMtoTRDchannels;j++){
883             map[i][j]=kFALSE;
884         }
885
886     for(int i = 0; i<kNLTM/2;i++)
887     for(int j = 0; j<AliTOFTrigger::kNCTTMchannels;j++){
888         UInt_t uTRDbit=j/3;
889         if(fCTTMmatrixFront[i][j]) map[i][uTRDbit]=kTRUE;
890     }
891   for(int i = kNLTM/2; i<kNLTM;i++)
892       for(int j = 0; j<AliTOFTrigger::kNCTTMchannels;j++){
893           UInt_t uTRDbit=j/3;
894           if(fCTTMmatrixBack[i-kNLTM/2][j]) map[i][uTRDbit]=kTRUE;
895     }
896   
897 }
898 //-------------------------------------------------------------------------
899 void AliTOFTrigger::GetTRDmapMatrix(Bool_t map[][8]) const
900 {
901   //
902   // Retriev the bit map sent to the TRD detector
903   //
904     
905     for(int i = 0; i<kNLTM;i++)
906         for(int j = 0; j<kNLTMtoTRDchannels;j++){
907             map[i][j]=kFALSE;
908         }
909
910     for(int i = 0; i<kNLTM/2;i++)
911     for(int j = 0; j<AliTOFTrigger::kNCTTMchannels;j++){
912         UInt_t uTRDbit=j/3;
913         if(fCTTMmatrixFront[i][j]) map[i][uTRDbit]=kTRUE;
914     }
915   for(int i = kNLTM/2; i<kNLTM;i++)
916       for(int j = 0; j<AliTOFTrigger::kNCTTMchannels;j++){
917           UInt_t uTRDbit=j/3;
918           if(fCTTMmatrixBack[i-kNLTM/2][j]) map[i][uTRDbit]=kTRUE;
919     }
920   
921 }
922
923 //-------------------------------------------------------------------------
924 void AliTOFTrigger::SetBit(Int_t *detind)
925 {
926   //
927   // Sets CTTM map element corresponding to detector element 'detind'
928   //
929
930   Int_t index[2];
931   GetCTTMIndex(detind,index);
932   if(index[0]<36)
933     fCTTMmatrixFront[index[0]][index[1]]=kTRUE;
934   else
935     fCTTMmatrixBack[index[0]-36][index[1]]=kTRUE;
936
937 }
938
939 //-------------------------------------------------------------------------
940 void AliTOFTrigger::SetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
941                            Int_t iTDC, Int_t iCH)
942 {
943   //
944   // Sets CTTM map element corresponding to equipment ID
945   // labelled by number nDDL, nTRM, iChain, iTDC, iCH
946   //
947
948     if(nTRM==3 && iTDC>=12 && iTDC<=14 && nDDL%2==1){ // DDL number to LTM number mapping
949 //       getchar();
950     Int_t iLTMindex=-1;
951     Int_t iChannelIndex=-1;
952     switch(nDDL%AliTOFGeometry::NDDL()){
953     case 1:
954       iLTMindex=1;
955       break;
956     case 3:
957       iLTMindex=36;
958       break;
959     default:
960       AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
961       break;
962     }
963     iLTMindex+=2*(Int_t)(nDDL/AliTOFGeometry::NDDL());
964     if(iChain==0 && nDDL<36)
965       iLTMindex--;
966     if(iChain==0 && nDDL>=36)
967       iLTMindex++;
968     iChannelIndex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
969     Int_t index[2]={iLTMindex,iChannelIndex};
970     if (index[0]<36){
971       fCTTMmatrixFront[index[0]][index[1]]=kTRUE;
972       fLTMmatrix[index[0]][index[1]*2]=kTRUE;
973     }
974     else{
975         fCTTMmatrixBack[index[0]-36][index[1]]=kTRUE;
976         fLTMmatrix[index[0]][index[1]*2]=kTRUE;
977     }
978     }
979
980 }
981 //-------------------------------------------------------------------------
982
983 void AliTOFTrigger::ResetBit(Int_t *detind)
984 {
985   //
986   // Sets CTTM map element corresponding to detector element 'detind'
987   //
988
989   Int_t index[2];
990   GetCTTMIndex(detind,index);
991   if(index[0]<36)
992     fCTTMmatrixFront[index[0]][index[1]]=kFALSE;
993   else
994     fCTTMmatrixBack[index[0]-36][index[1]]=kFALSE;
995
996 }
997
998 //-------------------------------------------------------------------------
999 void AliTOFTrigger::ResetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
1000                              Int_t iTDC, Int_t iCH)
1001 {
1002   //
1003   // Sets CTTM map element corresponding to equipment ID
1004   // labelled by number nDDL, nTRM, iChain, iTDC, iCH
1005   //
1006
1007   if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1){ // DDL number to LTM number mapping
1008     Int_t iLTMindex=-1;
1009     Int_t iChannelIndex=-1;
1010     switch(nDDL%AliTOFGeometry::NDDL()){
1011     case 1:
1012       iLTMindex=1;
1013       break;
1014     case 3:
1015       iLTMindex=36;
1016       break;
1017     default:
1018       AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
1019       break;
1020     }
1021     iLTMindex+=2*(Int_t)(nDDL/AliTOFGeometry::NDDL());
1022     if(iChain==0 && nDDL<36)
1023       iLTMindex--;
1024     if(iChain==0 && nDDL>=36)
1025       iLTMindex++;
1026     iChannelIndex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
1027     Int_t index[2]={iLTMindex,iChannelIndex};
1028     if (index[0]<36){
1029       fCTTMmatrixFront[index[0]][index[1]]=kFALSE;
1030     }
1031     else{
1032       fCTTMmatrixBack[index[0]-36][index[1]]=kFALSE;
1033     }
1034   }
1035   else
1036     AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
1037
1038 }
1039 //-------------------------------------------------------------------------
1040
1041 Bool_t AliTOFTrigger::GetBit(Int_t *detind)
1042 {
1043   //
1044   // Returns CTTM map element corresponding to detector element 'detind'
1045   //
1046
1047   Int_t index[2];
1048   GetCTTMIndex(detind,index);
1049   return (index[0]<36)?fCTTMmatrixFront[index[0]][index[1]]:fCTTMmatrixBack[index[0]-36][index[1]];
1050
1051 }
1052
1053 //-------------------------------------------------------------------------
1054 Bool_t AliTOFTrigger::GetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
1055                              Int_t iTDC, Int_t iCH)
1056 {
1057   //
1058   // Returns CTTM map element corresponding to equipment ID
1059   // labelled by number nDDL, nTRM, iChain, iTDC, iCH
1060   //
1061
1062   if ( !(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ) {
1063     AliWarning("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14) ");
1064     return kFALSE;
1065   }
1066   //if (nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) { // DDL number to LTM number mapping
1067
1068   UInt_t iLTMindex=0;
1069   UInt_t iChannelindex=0;
1070   switch(nDDL%AliTOFGeometry::NDDL()) {
1071   case 1:
1072     iLTMindex=1;
1073     break;
1074   case 3:
1075     iLTMindex=36;
1076     break;
1077   default:
1078     AliError("something wrong");
1079     break;
1080   }
1081   iLTMindex+=2*(Int_t)(nDDL/AliTOFGeometry::NDDL());
1082
1083   if (iChain==1) return kFALSE; // AdC
1084
1085   if (nDDL<36)
1086     iLTMindex--;
1087   if (nDDL>=36)
1088     iLTMindex++;
1089   iChannelindex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
1090   Int_t index[2]={static_cast<Int_t>(iLTMindex),static_cast<Int_t>(iChannelindex)};
1091   return (index[0]<36)?fCTTMmatrixFront[index[0]][index[1]]:fCTTMmatrixBack[index[0]-36][index[1]];
1092
1093 }
1094
1095 //-------------------------------------------------------------------------
1096
1097 void AliTOFTrigger::CreateCTTMMatrix() {
1098   //
1099   // Create CTTM bit map
1100   //
1101
1102   LoadActiveMask();
1103
1104     Int_t fromTriggertoDCS[72] = {0,1,4,5,8,9,12,13,16,17,20,21,24,25,28,29,32,33,36,37,40,41,44,45,48,49,52,53,56,57,60,61,64,65,68,69,3,
1105                                   2,7,6,11,10,15,14,19,18,23,22,27,26,31,30,35,34,39,38,43,42,47,46,51,50,55,54,59,58,63,62,67,66,71,70};
1106
1107
1108     fNMaxipadOnAll=0;
1109     fNMaxipadOn=0;
1110
1111     for(Int_t i = 0; i<kNLTM;i++){
1112         UInt_t currentMask = fPowerMask[kNCTTMchannels]-1;
1113         if(fTOFTrigMask) currentMask=fTOFTrigMask->GetTriggerMask(fromTriggertoDCS[i]);
1114         if(i<kNCTTM){
1115             for(Int_t j = 0; j<kNCTTMchannels;j++){
1116                 fCTTMmatrixFront[i][j]=fLTMmatrix[i][2*j]||fLTMmatrix[i][2*j+1];
1117                 if(fCTTMmatrixFront[i][j]) fNMaxipadOnAll++;
1118                 if(!(currentMask & fPowerMask[j])) fCTTMmatrixFront[i][j]=0;
1119                 if(fCTTMmatrixFront[i][j]){
1120                     fNMaxipadOn++;
1121                     fLTMarray[i] = kTRUE;
1122                 }
1123             }
1124         }
1125         else{
1126             for(Int_t j = 0; j<kNCTTMchannels;j++){
1127                 fCTTMmatrixBack[i-kNCTTM][j]=fLTMmatrix[i][2*j]||fLTMmatrix[i][2*j+1];;
1128                 if(fCTTMmatrixBack[i-kNCTTM][j]) fNMaxipadOnAll++;
1129                 if(!(currentMask & fPowerMask[j])) fCTTMmatrixBack[i-kNCTTM][j]=0;
1130                 if(fCTTMmatrixBack[i-kNCTTM][j]){
1131                     fNMaxipadOn++;
1132                     fLTMarray[i-kNCTTM] = kTRUE;
1133                 }
1134             }
1135         }
1136     }
1137   
1138     fNCrateOn = 0; 
1139     for(Int_t j=0; j < kNCTTM; j++) {if(fLTMarray[j]) fNCrateOn++;}
1140
1141 }     
1142 //-----------------------------------------------------------------------------
1143
1144 void AliTOFTrigger::GetCTTMIndex(Int_t *detind, Int_t *indexCTTM) {
1145   //
1146   // Returns CTTM index corresponding to the detector element detind
1147   //
1148
1149   GetLTMIndex(detind,indexCTTM);
1150   indexCTTM[1]/=2;
1151
1152 }
1153 //-----------------------------------------------------------------------------
1154 void AliTOFTrigger::LoadActiveMask(){
1155 //
1156 // Load OCDB current mask
1157 //
1158
1159     AliCDBManager *cdb = AliCDBManager::Instance();
1160     if(cdb->GetRun() < 0 || !(cdb->GetDefaultStorage())){
1161         if(!(cdb->GetDefaultStorage())){
1162             cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
1163             printf("AliTOFTrigger (WARNING): probably CDB first instance - Default Sorage set to \"local://$ALICE_ROOT/OCDB\"\n");
1164         }
1165         if(cdb->GetRun() < 0){
1166             cdb->SetRun(0);
1167          printf("AliTOFTrigger (WARNING): probably CDB first instance - number of run set to 0\n");
1168         }
1169     }
1170
1171     AliCDBEntry *cdbe = cdb->Get("TRIGGER/TOF/TriggerMask");
1172     if(!cdbe) return;
1173     fTOFTrigMask= (AliTOFTriggerMask *)cdbe->GetObject();
1174     
1175 //     UInt_t maskArray[kNLTM];
1176 //     if(fTOFTrigMask == NULL) fTOFTrigMask = new AliTOFTriggerMask();
1177 //     for (Int_t k = 0; k < kNLTM ; k++) maskArray[k] = fPowerMask[kNCTTMchannels]-1;
1178 //     //for (Int_t k = 0; k < kNLTM ; k+=2) maskArray[k] = 0;
1179     
1180 //     fTOFTrigMask->SetTriggerMaskArray(maskArray);
1181 }
1182
1183
1184 //-----------------------------------------------------------------------------
1185 AliTOFTrigger::~AliTOFTrigger()
1186 {
1187   // dtor
1188
1189 }
1190
1191 //-----------------------------------------------------------------------------
1192 AliTOFTrigger& AliTOFTrigger::operator=(const AliTOFTrigger &/*source*/)
1193 {
1194   // ass. op.
1195   return *this;
1196
1197 }
1198