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