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