]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFTrigger.cxx
3be35e6fcbbbce4cd87c50cb722fb46d1db0bf86
[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 /////////////////////////////////////////////////////////////////////
28
29 #include "AliLoader.h"
30 #include "AliLog.h"
31 #include "AliRunLoader.h"
32 #include "AliRun.h"
33 #include "AliTriggerInput.h"
34
35 #include "AliTOFdigit.h"
36 #include "AliTOFTrigger.h"
37
38 extern AliRun* gAlice;
39
40 //-------------------------------------------------------------------------
41 ClassImp(AliTOFTrigger)
42
43 //----------------------------------------------------------------------
44   AliTOFTrigger::AliTOFTrigger() : 
45     AliTriggerDetector(), 
46     fHighMultTh(1000),
47     fppMBTh(4),
48     fMultiMuonTh(2),
49     fUPTh(2),
50     fdeltaminpsi(150),
51     fdeltamaxpsi(170),
52     fdeltaminro(70),
53     fdeltamaxro(110),
54     fstripWindow(2)
55 {
56   //main ctor
57   for (Int_t i=0;i<kNLTM;i++){
58     for (Int_t j=0;j<kNLTMchannels;j++){
59       fLTMmatrix[i][j]=kFALSE;
60     }
61     if (i<kNCTTM){
62       for (Int_t j=0;j<kNCTTMchannels;j++){
63         fCTTMmatrixFront[i][j]=kFALSE;
64         fCTTMmatrixBack[i][j]=kFALSE;
65       }
66     }
67   }
68   SetName("TOF");
69   CreateInputs();
70 }
71 //----------------------------------------------------------------------
72 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) : AliTriggerDetector() 
73 {
74   //ctor with thresholds for triggers
75   fHighMultTh=HighMultTh;
76   fppMBTh=ppMBTh;
77   fMultiMuonTh=MultiMuonTh;
78   fUPTh=UPTh;
79   fdeltaminpsi = deltaminpsi;
80   fdeltamaxpsi = deltamaxpsi;
81   fdeltaminro = deltaminro;
82   fdeltamaxro = deltamaxro;
83   fstripWindow = stripWindow;
84   for (Int_t i=0;i<kNLTM;i++){
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   SetName("TOF");
96   CreateInputs();
97 }
98
99 //____________________________________________________________________________ 
100
101 AliTOFTrigger::AliTOFTrigger(const AliTOFTrigger & tr):AliTriggerDetector()
102 {
103   //copy ctor
104   fHighMultTh=tr.fHighMultTh;
105   fppMBTh=tr.fppMBTh;
106   fMultiMuonTh=tr.fMultiMuonTh;
107   fUPTh=tr.fUPTh;
108   fdeltaminpsi = tr.fdeltaminpsi;
109   fdeltamaxpsi = tr.fdeltamaxpsi;
110   fdeltaminro = tr.fdeltaminro;
111   fdeltamaxro = tr.fdeltamaxro;
112   fstripWindow = tr.fstripWindow;
113   for (Int_t i=0;i<kNLTM;i++){
114     for (Int_t j=0;j<kNLTMchannels;j++){
115       fLTMmatrix[i][j]=tr.fLTMmatrix[i][j];
116     }
117     if (i<kNCTTM){
118       for (Int_t j=0;j<kNCTTMchannels;j++){
119       fCTTMmatrixFront[i][j]=tr.fCTTMmatrixFront[i][j];
120       fCTTMmatrixBack[i][j]=tr.fCTTMmatrixBack[i][j];
121       }
122     }
123   }
124   SetName(tr.GetName());
125   CreateInputs();
126     //fInputs=&(tr.GetInputs());
127 }
128
129 //----------------------------------------------------------------------
130
131 void AliTOFTrigger::CreateInputs()
132 {
133   // creating inputs 
134   // Do not create inputs again!!
135    if( fInputs.GetEntriesFast() > 0 ) return;
136    
137    fInputs.AddLast(new AliTriggerInput("TOF_Cosmic_MultiMuon_L0","Cosmic Multimuon Topology",0x01));
138    fInputs.AddLast(new AliTriggerInput("TOF_pp_MB_L0","pp Minimum Bias",0x02));
139    fInputs.AddLast(new AliTriggerInput("TOF_UltraPer_Coll_L0","Ultra Peripheral Collisions",0x04));
140
141    fInputs.AddLast(new AliTriggerInput("TOF_High_Mult_L0","High Multiplicity",0x08));
142    fInputs.AddLast(new AliTriggerInput("TOF_Jet_L1","Jet Search",0x10));
143 }
144
145 //----------------------------------------------------------------------
146 void AliTOFTrigger::Trigger(){
147   //triggering method
148   CreateLTMMatrix();
149   Int_t nchonFront = 0;
150   Int_t nchonBack = 0;
151   Int_t nchonTot = 0;
152   Int_t nchonFrontBack = 0;
153   Int_t nchonFront1 = 0;
154   Int_t nchonBack1 = 0;
155   Int_t nchonFrontBack1 = 0;
156   Int_t mindeltapsi = (Int_t)fdeltaminpsi/10;
157   Int_t maxdeltapsi = (Int_t)fdeltamaxpsi/10;
158   Int_t mindeltaro = (Int_t)fdeltaminro/10;
159   Int_t maxdeltaro = (Int_t)fdeltamaxro/10;
160   for (Int_t i=0;i<kNCTTM;i++){
161     for (Int_t j=0;j<kNCTTMchannels;j++){
162       fCTTMmatrixFront[i][j]=kFALSE;
163       fCTTMmatrixBack[i][j]=kFALSE;
164     }
165   }
166   for (Int_t i=0;i<kNCTTM;i++){
167     for (Int_t j=0;j<kNCTTMchannels;j++){
168       fCTTMmatrixFront[i][j] = (fLTMmatrix[i][j*2] || fLTMmatrix[i][j*2+1]);
169       if (fCTTMmatrixFront[i][j]) nchonFront++; 
170     }
171   }
172
173   for (Int_t i=kNCTTM;i<(kNCTTM*2);i++){
174     for (Int_t j=0;j<kNCTTMchannels;j++){
175       fCTTMmatrixBack[i-kNCTTM][j] = (fLTMmatrix[i][j*2] || fLTMmatrix[i][j*2+1]);
176       if (fCTTMmatrixBack[i-kNCTTM][j]) nchonBack++; 
177     }
178   }
179
180   nchonTot = nchonFront + nchonBack;
181
182   //pp Minimum Bias Trigger
183   if (nchonTot >= fppMBTh) {
184     SetInput("TOF_pp_MB_L0");
185   }
186
187   //High Multiplicity Trigger
188   if (nchonTot >= fHighMultTh) {
189     SetInput("TOF_High_Mult_L0");
190   }
191
192   
193   //MultiMuon Trigger
194   nchonFront = 0;
195   nchonBack = 0;
196   nchonFrontBack = 0;
197
198   Bool_t boolCTTMor = kFALSE;
199
200   for (Int_t i=0;i<(kNCTTM/2);i++){
201     Int_t iopp = i+kNCTTM/2;
202     for (Int_t j=0;j<kNCTTMchannels;j++){
203       if (fCTTMmatrixFront[i][j]){
204         Int_t minj = j-fstripWindow;
205         Int_t maxj = j+fstripWindow;
206         if (minj<0) minj =0;
207         if (maxj>=kNCTTMchannels) maxj = kNCTTMchannels-1;
208         boolCTTMor = kFALSE;
209         for (Int_t k = minj;k<=maxj;k++){
210           boolCTTMor |= fCTTMmatrixFront[iopp][k];
211         } 
212         if (boolCTTMor) {
213           nchonFront++;
214         }
215       }
216     
217       if (fCTTMmatrixBack[i][j]){
218         Int_t minj = j-fstripWindow;
219         Int_t maxj = j+fstripWindow;
220         if (minj<0) minj =0;
221         if (maxj>=kNCTTMchannels) maxj =kNCTTMchannels-1;
222         boolCTTMor = kFALSE;
223         for (Int_t k = minj;k<=maxj;k++){
224           boolCTTMor |= fCTTMmatrixBack[iopp][k];
225         }
226         if (boolCTTMor) {
227           nchonBack++;
228         }
229       }
230     }
231   }
232
233   nchonFrontBack = nchonFront+nchonBack;
234
235   nchonFront1 = 0;
236   nchonBack1 = 0;
237   nchonFrontBack1 = 0;
238
239   boolCTTMor = kFALSE;
240   for (Int_t i=0;i<(kNCTTM/2);i++){
241     Int_t i2max = (kNCTTM-1)-i+1;
242     Int_t i2min = (kNCTTM-1)-i-1;
243     if (i2max >=kNCTTM) i2max = kNCTTM-1;
244     if (i2min==i) i2min = kNCTTM-1-i;
245     for (Int_t j=0;j<kNCTTMchannels;j++){
246       Int_t j2min = j-fstripWindow;
247       Int_t j2max = j+fstripWindow;
248       if (j2min<0) j2min =0;
249       if (j2max>=kNCTTMchannels) j2max =kNCTTMchannels-1;
250       if (fCTTMmatrixFront[i][j]){
251         boolCTTMor = kFALSE;
252         for (Int_t i2=i2min;i2<=i2max;i2++){
253           for (Int_t j2 = j2min;j2<=j2max;j2++){
254             boolCTTMor |= fCTTMmatrixFront[i2][j2];
255           } 
256           if (boolCTTMor) {
257             nchonFront++;
258           }
259         }
260       }
261       if (fCTTMmatrixBack[i][j]){
262         boolCTTMor = kFALSE;
263         for (Int_t i2=i2min;i2<=i2max;i2++){
264           for (Int_t j2 = j2min;j2<=j2max;j2++){
265             boolCTTMor |= fCTTMmatrixBack[i2][j2];
266           }
267         }
268         if (boolCTTMor) {
269           nchonBack++;
270         }
271       }
272     }
273   }
274
275   nchonFrontBack1 = nchonFront1+nchonBack1;
276
277   if (nchonFrontBack >= fMultiMuonTh || nchonFrontBack1 >= fMultiMuonTh) {
278     SetInput("TOF_Cosmic_MultiMuon_L0");
279   }
280
281   //Ultra-Peripheral collision Trigger
282   Bool_t boolpsi = kFALSE;
283   Bool_t boolro = kFALSE;
284   if (nchonTot == fUPTh){
285     for (Int_t i=0;i<kNCTTM;i++){
286       for (Int_t j=0;j<kNCTTMchannels;j++){
287         Int_t minipsi = i+mindeltapsi;
288         Int_t maxipsi = i+maxdeltapsi;
289         if (minipsi>=kNCTTM) minipsi = mindeltapsi-((kNCTTM-1)-i)-1;
290         if (maxipsi>=kNCTTM) maxipsi = maxdeltapsi-((kNCTTM-1)-i)-1;
291         Int_t miniro = i+mindeltaro;
292         Int_t maxiro = i+maxdeltaro;
293         if (miniro>=kNCTTM) miniro = mindeltaro-((kNCTTM-1)-i)-1;
294         if (maxiro>=kNCTTM) maxiro = maxdeltaro-((kNCTTM-1)-i)-1;
295         Int_t j2min = j-fstripWindow;
296         Int_t j2max = j+fstripWindow;
297         if (j2min<0) j2min =0;
298         if (j2max>=kNCTTMchannels) j2max =kNCTTMchannels-1;
299         if (fCTTMmatrixFront[i][j]){
300           for (Int_t i2=minipsi;i2<=maxipsi;i2++){
301             for (Int_t j2 = j2min;j2<=j2max;j2++){
302               if (fCTTMmatrixFront[i2][j2]) {
303                 SetInput("TOF_UltraPer_Coll_L0");
304                 boolpsi = kTRUE;
305                 //exiting loops
306                 j2 = j2max+1;
307                 i2 = maxipsi+1;
308                 j=kNCTTMchannels;
309                 i=kNCTTM;
310               }
311             }
312           }
313           if (!boolpsi){
314             for (Int_t i2=miniro;i2<=maxiro;i2++){
315               for (Int_t j2 = j2min;j2<=j2max;j2++){
316                 if (fCTTMmatrixFront[i2][j2]) {
317                   SetInput("TOF_UltraPer_Coll_L0");
318                   boolro = kTRUE;
319                   //exiting loops
320                   j2 = j2max+1;
321                   i2 = maxiro+1;
322                   j=kNCTTMchannels;
323                   i=kNCTTM;
324                 }
325               }
326             }
327           }
328         }
329           
330         else if (fCTTMmatrixBack[i][j]){
331           for (Int_t i2=minipsi;i2<=maxipsi;i2++){
332             for (Int_t j2 = j2min;j2<=j2max;j2++){
333               if (fCTTMmatrixBack[i2][j2]) {
334                 SetInput("TOF_UltraPer_Coll_L0");
335                 boolpsi = kTRUE;
336                 //exiting loops
337                 j2 = j2max+1;
338                 i2 = maxipsi+1;
339                 j=kNCTTMchannels;
340                 i=kNCTTM;
341               }
342             }
343           }
344           if (!boolpsi){
345             for (Int_t i2=miniro;i2<=maxiro;i2++){
346               for (Int_t j2 = j2min;j2<=j2max;j2++){
347                 if (fCTTMmatrixBack[i2][j2]) {
348                   SetInput("TOF_UltraPer_Coll_L0");
349                   boolro = kTRUE;
350                   //exiting loops
351                   j2 = j2max+1;
352                   i2 = maxiro+1;
353                   j=kNCTTMchannels;
354                   i=kNCTTM;
355                 }
356               }
357             }
358           } 
359         }
360       }
361     }
362   }
363 }
364 //-----------------------------------------------------------------------------
365 void AliTOFTrigger::CreateLTMMatrix(){
366   //creating LTMMatrix
367   //initialization
368   for (Int_t i=0;i<kNLTM;i++){
369     for (Int_t j=0;j<kNLTMchannels;j++){
370       fLTMmatrix[i][j]=kFALSE;
371     }
372   }
373   AliRunLoader *rl;
374   rl = gAlice->GetRunLoader();
375   
376   Int_t ncurrevent = rl->GetEventNumber();
377   rl->GetEvent(ncurrevent);
378   
379   AliLoader * tofLoader = rl->GetLoader("TOFLoader");
380   
381   tofLoader->LoadDigits("read");
382   TTree *treeD = tofLoader->TreeD();
383   if (treeD == 0x0)
384     {
385       AliFatal("AliTOFTrigger: Can not get TreeD");
386     }
387   
388   TBranch *branch = treeD->GetBranch("TOF");
389   if (!branch) { 
390     AliError("can't get the branch with the TOF digits !");
391     return;
392   }
393   TClonesArray *tofDigits =new TClonesArray("AliTOFdigit",  1000);
394   branch->SetAddress(&tofDigits);
395   treeD->GetEvent(0);
396   Int_t ndigits = tofDigits->GetEntriesFast();
397   Int_t detind[5]; //detector indexes: 0 -> sector
398   //                                   1 -> plate
399   //                                   2 -> strip
400   //                                   3 -> padz
401   //                                   4 -> padx
402   
403   for (Int_t i=0;i<ndigits;i++){
404     AliTOFdigit * digit = (AliTOFdigit*)tofDigits->UncheckedAt(i);
405     detind[0] = digit->GetSector();
406     detind[1] = digit->GetPlate();
407     detind[2] = digit->GetStrip();
408     detind[3] = digit->GetPadz();
409     detind[4] = digit->GetPadx();
410     
411     Int_t indexLTM[2] = {-1,-1};
412     GetLTMIndex(detind,indexLTM);
413
414     fLTMmatrix[indexLTM[0]][indexLTM[1]] = kTRUE;
415   }
416
417   tofLoader->UnloadDigits();
418 //   rl->UnloadgAlice();
419 }
420 //-----------------------------------------------------------------------------
421 void AliTOFTrigger::GetLTMIndex(Int_t *detind, Int_t *indexLTM){
422   //getting LTMmatrix indexes for current digit
423   if (detind[1]==0 || detind[1]==1 || (detind[1]==2 && detind[2]<=7)) {
424     if (detind[4]<24){
425       indexLTM[0] = detind[0]*2;
426     }
427     else {
428       indexLTM[0] = detind[0]*2+1;
429     }
430   }
431   else {
432     if (detind[4]<24){
433       indexLTM[0] = detind[0]*2+36;
434     }
435     else {
436       indexLTM[0] = (detind[0]*2+1)+36;
437     }
438   }
439
440   if (indexLTM[0]<36){ 
441     if (detind[1] ==0){
442       indexLTM[1] = detind[2];
443     }
444     else if (detind[1] ==1){
445       indexLTM[1] = detind[2]+19;
446     }
447     else if (detind[1] ==2){
448       indexLTM[1] = detind[2]+19*2;
449     }
450     else{
451       AliError("Smth Wrong!!!");
452     }
453   }
454   else {
455     if (detind[1] ==2){
456       indexLTM[1] = detind[2]-8;
457     }
458     else if (detind[1] ==3){
459       indexLTM[1] = detind[2]+7;
460     }
461     else if (detind[1] ==4){
462       indexLTM[1] = detind[2]+26;
463     }
464     else{
465       AliError("Smth Wrong!!!");
466     }
467   }
468 }
469