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