First version of the trigger classes (E. Lopez Torres)
[u/mrichter/AliRoot.git] / ITS / AliITSTrigger.cxx
CommitLineData
e628c711 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//
21// ITS SPD Trigger Detector Class
22//
23// Several Fast-OR Algoritm are implemented
24//
25// Ref: ALICE-INT-2005-025
26// (J. Conrad, J. G. Contreras and C. E. Jorgensen)
27//
28//////////////////////////////////////////////////////////////////////
29
30
31#include "AliLog.h"
32#include "AliRun.h"
33#include "AliRunLoader.h"
34#include "AliITSLoader.h"
35#include "AliITSgeom.h"
36#include "AliITSdigitSPD.h"
37
38#include "AliTriggerInput.h"
39#include "AliITSTrigger.h"
40
41//______________________________________________________________________
42ClassImp(AliITSTrigger)
43
44//______________________________________________________________________
45AliITSTrigger::AliITSTrigger()
46 : AliTriggerDetector()
47{
48 SetName("ITS");
49 CreateInputs();
50}
51
52//______________________________________________________________________
53void AliITSTrigger::CreateInputs()
54{
55 // inputs
56
57 // Do not create inputs again!!
58 if( fInputs.GetEntriesFast() > 0 ) return;
59
60 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_GFO_L0", "Global, Fast OR all detectors", 0x01 ) );
61 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_LAYER_L0", "Layer, hit in each layer", 0x02 ) );
62 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_SECTOR_L0", "Sector, hit coincidence in one sector", 0x04 ) );
63 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_HSECTOR_L0", "Half Sector, hit coincidence in one half sector", 0x08 ) );
64 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_SW1_L0", "Sliding Window 1, hit coincidence on phi windows", 0x10 ) );
65 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_SW2_L0", "Sliding Window 2, hit coincidence on phi windows", 0x20 ) );
66 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_VERTEX_L0", "Vertex, hit coincidence on theta windows", 0x40 ) );
67 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_SVERTEX_L0", "Sector+Vertex, hit coincidence on one sector and theta windows", 0x80 ) );
68 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_HSVERTEX_L0","Half Sector+Vertex, hit coincidence on one half sector and theta windows", 0x100 ) );
69 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_SWVERTEX_L0","Sliding Window+Vertex, hit coincidence on phi windows and theta windows", 0x200 ) );
70 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_LUCUT_L0", "Layer+Upper Cut, hit in each layer and FO occupancy cut", 0x400 ) );
71 // Not yet implemented
72 fInputs.AddLast( new AliTriggerInput( "ITS_SPD_HMULT_L0", "High Multiplicity, to be defined!!", 0x600 ) );
73
74}
75
76//______________________________________________________________________
77void AliITSTrigger::Trigger()
78{
79
80 // ********** Get run loader for the current event **********
81 AliRunLoader* runLoader = gAlice->GetRunLoader();
82
83 AliITSLoader * loader = (AliITSLoader* )runLoader->GetLoader( "ITSLoader" );
84 AliITSgeom* geom = loader->GetITSgeom();
85 loader->LoadDigits("READ");
86 TTree *treeD = loader->TreeD();
87
88 TObjArray *digDet = 0;
89 digDet = new TObjArray(3);
90
91 Int_t startSPD = geom->GetStartSPD();
92 Int_t lastSPD = geom->GetLastSPD();
93
94 // Cut on Signal In the Pixel Detector
95 TBranch * br = treeD->GetBranch( "ITSDigitsSPD" );
96 br->SetAddress( &((*digDet)[0]) );
97 ((TClonesArray*)(digDet->At(0)))->Clear();
98
99 Int_t ndig = 0;
100 Int_t ndigfo = 0;
101 Int_t singhitthreshold = 1; // single hit threshold
102 Int_t threshold = 1;
103
104// const Int_t nlay = 2; // not used
105// const Int_t nlad = 240; // not used
106// const Int_t nstave = 40; // not used
107// const Int_t ndet = 4; // not used
108// const Int_t nchip = 5; // not used
109// const Int_t ntotal = 1200;
110
111 Int_t ndigA[5];
112 Int_t iFOperlayer[2];
113 Int_t iFOperladder[240];
114 Int_t iFOperstave[40][2];
115// Int_t iFOperchip[ntotal]; // not used
116 Int_t iFOperChipinStave[20][40][2];
117
118 for (Int_t m=startSPD;m<lastSPD;m++) {
119 iFOperladder[m] = 0;
120 }
121
122 for (Int_t k = 0;k<2;k++){
123 iFOperlayer[k] = 0;
124 for (Int_t o=0; o<40; o++) {
125 iFOperstave[o][k] = 0;
126 for (Int_t ich=0; ich<20; ich++) {
127 iFOperChipinStave[ich][o][k] = 0;
128 }
129 }
130 }
131
132 // nFO = 0.0;
133 Int_t mInStaveCounter = 0;
134 Int_t checkStave = 0;
135
136 for (Int_t m=startSPD; m<lastSPD; m++) {
137 treeD->GetEvent( m );
138 TClonesArray* digits = (TClonesArray*) (digDet->At(0)); // SPD only.
139 Int_t lay, stav, det;
140 geom->GetModuleId(m,lay,stav,det);
141 ndig = digits->GetEntriesFast();
142 for( Int_t l=0; l<5; l++ ) {
143 ndigA[l] = 0 ;
144 }
145 for( Int_t dig=0; dig<ndig; dig++) {
146 AliITSdigitSPD* dp = (AliITSdigitSPD*) digits->At(dig);
147 Int_t column = dp->GetCoord1();
148 // Int_t row = dp->GetCoord2();
149 Int_t chip = Int_t(column/32.);
150 ndigA[chip]++;
151 }
152
153 if (checkStave != stav) {
154 mInStaveCounter = 0;
155 } else {
156 mInStaveCounter += 1;
157 }
158
159 // m 0,.., 239
160 // stav 1,..,40
161 // mInStave 0,..,3
162 // chipInStave 0,..,19
163
164
165 for (Int_t ichip=0; ichip<5; ichip++) {
166 //Int_t seq = (m*5+ichip);
167 Int_t chipInStave = (mInStaveCounter *5) + ichip;
168
169 if (ndigA[ichip] >= 1) {
170 iFOperladder[m]++;
171 iFOperlayer[lay-1]++;
172 iFOperstave[stav-1][lay-1]++;
173 //iFOperHstave[hstav-1][lay-1]++;
174 iFOperChipinStave[chipInStave][stav-1][lay-1]++;
175 // nFO++;
176 }
177 }
178 // SIMPLE FO ---> ANY HIT TRIGGERS
179 ndigfo += ndig;
180 checkStave = stav;
181 } // endl loop over SPD's
182
183
184 //Int_t bit1 = 0;
185 Int_t upper_cut = 120;
186
187 if ( ndigfo >= singhitthreshold ) {
188 // Set input GLOBAL FO
189 SetInput( "ITS_SPD_GFO_L0" );
190 // or SetInput( "0x01" );
191 // or ((AliTriggerInput*)fInputs.At(0))->Set();
192 // bit1 |= (1 << 1);
193 }
194
195 // if ( ndigfo <= upper_cut) { bit1 |= (1 << 10); }
196
197 if (iFOperlayer[0] >= threshold && iFOperlayer[1] >=threshold) {
198 // Set input LAYER
199 //bit1 |= (1 << 2);
200 SetInput( "ITS_SPD_LAYER_L0" );
201 if ( ndigfo <= upper_cut) {
202 //bit1 |= (1 << 10);
203 // LAYER and UPPER CUT
204 SetInput( "ITS_SPD_LUCUT_L0" );
205 }
206 }
207
208 // Sector coincidence
209
210 // Int_t nsec = 0;
211 Int_t finstav = 0;
212 Int_t istav;
213 Int_t jstav;
214
215 // staves layer 1 1-20
216 // staves layer 2: 0-39
217 for (istav=1; istav<21; istav++) {
218 for (jstav = finstav; jstav<finstav+4; jstav++) {
219 if ((iFOperstave[istav-1][0] >= threshold) &&
220 (iFOperstave[jstav][1] >= threshold)) {
221 // Set input SECTOR
222 //bit1 |= (1 << 3);
223 SetInput( "ITS_SPD_SECTOR_L0" );
224 if ( RequireZ10cm( iFOperChipinStave, istav-1, jstav ) == kTRUE ) {
225 // Set input SECTOR & VERTEX
226 // bit1 |= (1 << 7);
227 SetInput( "ITS_SPD_SVERTEX_L0" );
228 }
229 }
230
231 }
232 if (TMath::Even(istav)) {
233 finstav = jstav;
234 }
235
236 }
237
238 // half sector coincidence
239
240 finstav = 0;
241 for (istav=1; istav<21; istav++){
242 for (jstav = finstav; jstav<finstav+2; jstav++) {
243 if (iFOperstave[istav-1][0] >= threshold && iFOperstave[jstav][1] >= threshold) {
244 // Set input HALF SECTOR
245 //bit1 |= (1 << 4);
246 SetInput( "ITS_SPD_HSECTOR_L0" );
247 if (RequireZ10cm(iFOperChipinStave,istav-1,jstav) == kTRUE) {
248 // Set input HALF SECTOR & VERTEX
249 SetInput( "ITS_SPD_HSVERTEX_L0" );
250 //bit1 |= (1 << 8);
251 }
252 }
253 }
254 finstav = jstav;
255 }
256
257 finstav = 0;
258 for (istav=1; istav<21; istav++) {
259 for (jstav = finstav-1; jstav<finstav+3; jstav++) {
260 Int_t probe_stav = jstav;
261 if (jstav == -1) probe_stav = 39;
262 if (jstav == 40) probe_stav = 0;
263 if (iFOperstave[istav-1][0] >= threshold && iFOperstave[probe_stav][1] >= threshold) {
264 // Set input SLIDING WINDOW1
265 SetInput( "ITS_SPD_SW1_L0" );
266 //bit1 |= (1 << 5);
267 }
268 }
269 finstav = jstav-1;
270 }
271
272 // sliding window coincidence (symmetric): 1 (layer 1), 5 (layer 2)
273
274 finstav = 0;
275 for (istav=1;istav<21; istav++) {
276 for (jstav = finstav-2; jstav<finstav+3; jstav++) {
277 Int_t probe_stav = jstav;
278 if (jstav == -2) probe_stav = 38;
279 if (jstav == -1) probe_stav = 39;
280 if (jstav == 40) probe_stav = 0;
281 if (jstav == 41) probe_stav = 1;
282
283 if ((iFOperstave[istav-1][0] >= threshold) && (iFOperstave[probe_stav][1] >= threshold)) {
284 // Set input SLIDING WINDOW 2
285 SetInput( "ITS_SPD_SW2_L0" );
286 // bit1 |= (1 << 6);
287 if (RequireZ10cm(iFOperChipinStave,istav-1,probe_stav) == kTRUE) {
288 // Set input SLIDING WINDOW & VERTEX
289 SetInput( "ITS_SPD_SWVERTEX_L0" );
290 //bit1 |= (1 << 9);
291 }
292 }
293 }
294 finstav = jstav-1;
295 }
296
297}
298
299
300
301//______________________________________________________________________
302Bool_t AliITSTrigger::RequireZ10cm(Int_t iFOperChipinStave[][40][2], Int_t stave1, Int_t stave2)
303{
304 // z sliding window
305 // Bool_t zFlag = kFALSE;
306
307 Int_t threshold = 1;
308 Int_t start1 = 1;
309 Int_t start2 = 3;
310 Int_t start3 = 6;
311 Int_t start4 = 7;
312 // Int_t i = 1;
313
314 for (Int_t ic=0; ic<=19; ic++) {
315 if (ic <= 5) {
316 for (Int_t jc=0;jc<=ic-1;jc++) {
317 if (iFOperChipinStave[ic][stave1][0] >=threshold) {
318 if (iFOperChipinStave[jc][stave2][1] >= threshold){
319 return kTRUE; // zFlag = kTRUE;
320 }
321 }
322 }
323 }
324 if (ic >= 6 && ic <= 8) {
325 for (Int_t jc=(2*start1-1);jc<=(2*start1-1)+5;jc++) {
326 if (iFOperChipinStave[ic][stave1][0] >=threshold) {
327 if (iFOperChipinStave[jc][stave2][1] >= threshold) {
328 return kTRUE; // zFlag = kTRUE;
329 }
330 }
331 }
332 start1++;
333 }
334 if (ic >= 9 && ic <= 11) {
335 for (Int_t jc=(2*start2); jc<=(2*start2+5); jc++) {
336 if (iFOperChipinStave[ic][stave1][0] >= threshold) {
337 if (iFOperChipinStave[jc][stave2][1] >= threshold) {
338 return kTRUE; // zFlag = kTRUE;
339 }
340 }
341 }
342 start2++;
343 }
344 if (ic >= 12 && ic <= 13) {
345 for (Int_t jc=(2*start3-1);jc<=(2*start3-1)+5;jc++) {
346 if (iFOperChipinStave[ic][stave1][0] >= threshold) {
347 if (iFOperChipinStave[jc][stave2][1] >= threshold){
348 return kTRUE; // zFlag = kTRUE;
349 }
350 }
351 }
352 start3++;
353 }
354 if (ic >= 14) {
355 for (Int_t jc=(2*start4);jc<=19;jc++) {
356 if (iFOperChipinStave[ic][stave1][0] >= threshold) {
357 if (iFOperChipinStave[jc][stave2][1] >= threshold){
358 return kTRUE; // zFlag = kTRUE;
359 }
360 }
361 }
362 start4++;
363 }
364 }
365
366 return kFALSE; // zFlag;
367}
368
369