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