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