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