improving IO
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerDecision.cxx
CommitLineData
a9e2aefa 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
e6738866 3 * *
a9e2aefa 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 **************************************************************************/
d72f68af 15
88cb7938 16/* $Id$ */
a9e2aefa 17
ecfa008b 18#include "AliMUONTriggerCircuit.h"
a9e2aefa 19#include "AliMUONTriggerDecision.h"
20#include "AliMUONTriggerLut.h"
21#include "AliMUONHitMapA1.h"
22#include "AliRun.h"
23#include "AliMUON.h"
88cb7938 24#include "AliRunLoader.h"
25#include "AliLoader.h"
a30a000f 26#include "AliSegmentation.h"
a9e2aefa 27#include "AliMUONResponse.h"
28#include "AliMUONChamber.h"
29#include "AliMUONDigit.h"
30
31
32#include <TF1.h>
33#include <TTree.h>
34#include <TCanvas.h>
35#include <TH1.h>
36#include <TPad.h>
37#include <TGraph.h>
38#include <TPostScript.h>
39#include <TMinuit.h>
70479d0e 40#include <Riostream.h>
a9e2aefa 41
42//----------------------------------------------------------------------
43ClassImp(AliMUONTriggerDecision)
44
45//----------------------------------------------------------------------
46AliMUONTriggerDecision::AliMUONTriggerDecision(Int_t iprint)
47{
48// Constructor
ecfa008b 49 fDebug = iprint; // print option
a9e2aefa 50// iprint = 0 : don't print anything
51// iprint = 1 : print Global Trigger Output
52// iprint = 2 : print Local and Global Trigger Outputs
53// iprint = 3 : iprint = 2 + detailed info on X strips
54// iprint = 4 : iprint = 2 + detailed info on Y strip
55// iprint = 5 : iprint = 2 + detailed info on X and Y strips
56// Note : with iprint>2, the strips detailed info is given for all circuits
57
58// Global Trigger information
e6738866 59 Int_t i;
60 Int_t icirc;
61 Int_t istrip;
62
63 for (i=0; i<3; i++) { // [0] : Low pt, [1] : High pt, [2] : All pt
a9e2aefa 64 fGlobalSinglePlus[i]=0; // tot num of single plus
65 fGlobalSingleMinus[i]=0; // tot num of single minus
66 fGlobalSingleUndef[i]=0; // tot num of single undefined
67 fGlobalPairUnlike[i]=0; // tot num of unlike-sign pairs
68 fGlobalPairLike[i]=0; // tot num of like-sign pairs
69 }
70 // Local Trigger information
e6738866 71 for (icirc=0; icirc<234; icirc++){
ecfa008b 72 fTrigger[icirc]=0; // trigger or not
a9e2aefa 73 fStripX11[icirc]=0; // X strip in MC11 which triggers
ecfa008b 74 fDev[icirc]=0; // deviation which triggers
a9e2aefa 75 fStripY11[icirc]=0; // Y strip in MC11 which triggers
e6738866 76 for (i=0; i<2; i++) { // pt information via LuT
a9e2aefa 77 fLutLpt[icirc][i]=fLutHpt[icirc][i]=fLutApt[icirc][i]=0;
78 }
79 }
80 // bit pattern
e6738866 81 for (icirc=0; icirc<234; icirc++) {
82 for (istrip=0; istrip<16; istrip++) {
a9e2aefa 83 fXbit11[icirc][istrip]=fXbit12[icirc][istrip]=0;
84 fYbit11[icirc][istrip]=fYbit12[icirc][istrip]=0;
85 fYbit21[icirc][istrip]=fYbit22[icirc][istrip]=0;
86 fYbit21U[icirc][istrip]=fYbit22U[icirc][istrip]=0;
87 fYbit21D[icirc][istrip]=fYbit22D[icirc][istrip]=0;
88 }
e6738866 89 for (istrip=0; istrip<32; istrip++) {
a9e2aefa 90 fXbit21[icirc][istrip]=fXbit22[icirc][istrip]=0;
91 }
92 }
93}
94
95//----------------------------------------------------------------------
96AliMUONTriggerDecision::~AliMUONTriggerDecision()
97{
98// Destructor
99}
100
101//----------------------------------------------------------------------
102void AliMUONTriggerDecision::Trigger(){
103// main method of the class which calls the overall Trigger procedure
a9e2aefa 104
105 ResetBit();
106 SetBit();
107 SetBitUpDownY();
108
109 Int_t coinc44=0, resetMid=0; // initialize coincidence
110
111 AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
112 AliMUONTriggerCircuit* triggerCircuit;
113
114 for (Int_t icirc=0; icirc<234; icirc++) { // loop on circuits
115 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
116 // Int_t idCircuit=triggerCircuit->GetIdCircuit();
117
118 Int_t minDevStrip[5], minDev[5], coordY[5];
119 for (Int_t i=0; i<5; i++) {
120 minDevStrip[i]=minDev[i]=coordY[i]=0;
121 }
122 Int_t x2m=triggerCircuit->GetX2m();
123 Int_t x2ud=triggerCircuit->GetX2ud();
124 Int_t orMud[2]={0,0};
125 triggerCircuit->GetOrMud(orMud);
126
127// call triggerX
128 TrigX(fXbit11[icirc],fXbit12[icirc],fXbit21[icirc],fXbit22[icirc],
129 coinc44, minDevStrip, minDev);
130// call triggerY
131 TrigY(fYbit11[icirc],fYbit12[icirc],fYbit21[icirc],fYbit22[icirc],
132 fYbit21U[icirc],fYbit21D[icirc],fYbit22U[icirc],fYbit22D[icirc],
133 x2m,x2ud,orMud,resetMid,coinc44,coordY);
134// call LocalTrigger
135 Int_t iTrigger=0;
136 LocalTrigger(icirc, minDevStrip, minDev, coordY, iTrigger);
137
ecfa008b 138 if (iTrigger==1&&fDebug>1) {
a9e2aefa 139 PrintBitPatXInput(icirc);
140 PrintBitPatYInput(icirc);
141 PrintLocalOutput(minDevStrip, minDev, coordY);
142 }
143 } // end loop on circuits
144
145// call Global Trigger
146 GlobalTrigger();
a9e2aefa 147}
148
149//----------------------------------------------------------------------
150void AliMUONTriggerDecision::ResetBit(){
151// reset bit pattern, global and local trigger output tables to 0
152
e6738866 153 Int_t i;
154 Int_t icirc;
155 Int_t istrip;
156
157 for (icirc=0; icirc<234; icirc++) {
158 for (istrip=0; istrip<16; istrip++) {
a9e2aefa 159 fXbit11[icirc][istrip]=fXbit12[icirc][istrip]=0;
160 fYbit11[icirc][istrip]=fYbit12[icirc][istrip]=0;
161 fYbit21[icirc][istrip]=fYbit22[icirc][istrip]=0;
162 fYbit21U[icirc][istrip]=fYbit22U[icirc][istrip]=0;
163 fYbit21D[icirc][istrip]=fYbit22D[icirc][istrip]=0;
164 }
e6738866 165 for (istrip=0; istrip<32; istrip++) {
a9e2aefa 166 fXbit21[icirc][istrip]=fXbit22[icirc][istrip]=0;
167 }
168 }
e6738866 169 for (i=0; i<3; i++) {
a9e2aefa 170 fGlobalSinglePlus[i]=0;
171 fGlobalSingleMinus[i]=0;
172 fGlobalSingleUndef[i]=0;
173 fGlobalPairLike[i]=0;
174 fGlobalPairLike[i]=0;
175 }
e6738866 176 for (icirc=0; icirc<234; icirc++){
ecfa008b 177 fTrigger[icirc]=0;
a9e2aefa 178 fStripX11[icirc]=0;
ecfa008b 179 fDev[icirc]=0;
a9e2aefa 180 fStripY11[icirc]=0;
e6738866 181 for (i=0; i<2; i++) {
a9e2aefa 182 fLutLpt[icirc][i]=fLutHpt[icirc][i]=fLutApt[icirc][i]=0;
183 }
184 }
185}
186
187//----------------------------------------------------------------------
188void AliMUONTriggerDecision::SetBit(){
189// 1) loop over chambers and cathodes
190// 2) load digits
191// 3) remove soft background
192// 4) set the bit patterns
193
88cb7938 194
195 AliMUON *pMUON = (AliMUON*)gAlice->GetDetector("MUON");
a9e2aefa 196 AliMUONTriggerCircuit* triggerCircuit;
88cb7938 197 AliRunLoader * rl = AliRunLoader::GetRunLoader();
198 AliLoader * gime = rl->GetLoader("MUONLoader");
a9e2aefa 199
200 for (Int_t chamber=11; chamber<15; chamber++){
201 for (Int_t cathode=1; cathode<3; cathode++){
202
88cb7938 203 AliMUONChamber* iChamber = &(pMUON->Chamber(chamber-1));
a30a000f 204 AliSegmentation* segmentation;
88cb7938 205 gime->TreeD()->GetEvent(cathode-1);
1a1cdff8 206 TClonesArray *muonDigits = pMUON->GetMUONData()->Digits(chamber-1);
a9e2aefa 207 Int_t ndigits = muonDigits->GetEntriesFast();
bf17dbfd 208 printf("\n 1 Found %d digits in %p %d \n ", ndigits, muonDigits,chamber-1);
88cb7938 209// if (ndigits == 0) return;
a9e2aefa 210
88cb7938 211// iChamber = &(pMUON->Chamber(chamber-1));
a9e2aefa 212 segmentation=iChamber->SegmentationModel(cathode);
213 AliMUONDigit *mdig;
214
215 for (Int_t digit=0; digit<ndigits; digit++) {
216 mdig = (AliMUONDigit*)muonDigits->UncheckedAt(digit);
217// get the center of the pad Id
2ae08086 218 Int_t ix=mdig->PadX();
219 Int_t iy=mdig->PadY();
bf17dbfd 220 printf("digits %d ix %d iy %d \n",digit,ix,iy);
88cb7938 221
a9e2aefa 222// get the sum of the coded charge
223// see coding convention in AliMUONChamberTrigger::DisIntegration
224 Int_t sumCharge=0;
225 for (Int_t icharge=0; icharge<10; icharge++) {
2ae08086 226 sumCharge=sumCharge+mdig->TrackCharge(icharge);
a9e2aefa 227 }
228// apply condition on soft background
88cb7938 229 Int_t testCharge=sumCharge-(Int_t(sumCharge/10))*10;
a9e2aefa 230 if(sumCharge<=10||testCharge>0) {
231// code pad
232 Int_t code=TMath::Abs(ix)*100+iy;
233 if (ix<0) { code=-code; }
e6738866 234
235 Int_t icirc;
236 Int_t istrip;
237 Int_t nStrip;
a9e2aefa 238
239 if (cathode==1) {
240 switch (chamber)
241 {
242 case 11:
e6738866 243 for (icirc=0; icirc<234; icirc++) {
a9e2aefa 244 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
e6738866 245 for (istrip=0; istrip<16; istrip++) {
a9e2aefa 246 if (triggerCircuit->GetXcode(0,istrip)==code)
247 fXbit11[icirc][istrip]=1;
248 }
249 }
250 break;
251 case 12:
e6738866 252 for (icirc=0; icirc<234; icirc++) {
a9e2aefa 253 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
e6738866 254 for (istrip=0; istrip<16; istrip++) {
a9e2aefa 255 if (triggerCircuit->GetXcode(1,istrip)==code)
256 fXbit12[icirc][istrip]=1;
257 }
258 }
259 break;
260 case 13:
e6738866 261 for (icirc=0; icirc<234; icirc++) {
a9e2aefa 262 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
e6738866 263 for (istrip=0; istrip<32; istrip++) {
a9e2aefa 264 if (triggerCircuit->GetXcode(2,istrip)==code)
265 fXbit21[icirc][istrip]=1;
266 }
267 }
268 break;
269 case 14:
e6738866 270 for (icirc=0; icirc<234; icirc++) {
a9e2aefa 271 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
e6738866 272 for (istrip=0; istrip<32; istrip++) {
a9e2aefa 273 if (triggerCircuit->GetXcode(3,istrip)==code)
274 fXbit22[icirc][istrip]=1;
275 }
276 }
277 break;
278 }
279
280 } else { // Y plane
281 switch (chamber)
282 {
283 case 11:
e6738866 284 for (icirc=0; icirc<234; icirc++) {
a9e2aefa 285 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
e6738866 286 nStrip=triggerCircuit->GetNstripY();
287 for (istrip=0; istrip<nStrip; istrip++) {
a9e2aefa 288 if (triggerCircuit->GetYcode(0,istrip)==code)
289 fYbit11[icirc][istrip]=1;
290 }
291 }
292 break;
293 case 12:
e6738866 294 for (icirc=0; icirc<234; icirc++) {
a9e2aefa 295 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
e6738866 296 nStrip=triggerCircuit->GetNstripY();
297 for (istrip=0; istrip<nStrip; istrip++) {
a9e2aefa 298 if (triggerCircuit->GetYcode(1,istrip)==code)
299 fYbit12[icirc][istrip]=1;
300 }
301 }
302 break;
303 case 13:
e6738866 304 for (icirc=0; icirc<234; icirc++) {
a9e2aefa 305 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
e6738866 306 nStrip=triggerCircuit->GetNstripY();
307 for (istrip=0; istrip<nStrip; istrip++) {
a9e2aefa 308 if (triggerCircuit->GetYcode(2,istrip)==code)
309 fYbit21[icirc][istrip]=1;
310 }
311 }
312 break;
313 case 14:
e6738866 314 for (icirc=0; icirc<234; icirc++) {
a9e2aefa 315 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
e6738866 316 nStrip=triggerCircuit->GetNstripY();
317 for (istrip=0; istrip<nStrip; istrip++) {
a9e2aefa 318 if (triggerCircuit->GetYcode(3,istrip)==code)
319 fYbit22[icirc][istrip]=1;
320 }
321 }
322 break;
323 }
324 } // if cathode
325 } // remove soft background
326 } // end loop on digit
bf17dbfd 327 pMUON->GetMUONData()->ResetDigits();
a9e2aefa 328 } // end loop on cathode
329 } // end loop on chamber
330}
331
332//----------------------------------------------------------------------
333void AliMUONTriggerDecision::SetBitUpDownY(){
334// Set Y bit for up and down parts of circuits
335 Int_t idModule, nStripX, nStripY, iPosCircuit;
336
337 AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
338
339 for (Int_t icirc=0; icirc<234; icirc++) {
340
341 AliMUONTriggerCircuit* circuit; // current circuit
342 AliMUONTriggerCircuit* circuitD; // circuit Down
343 AliMUONTriggerCircuit* circuitU; // circuit Up
344
345 circuit = &(pMUON->TriggerCircuit(icirc));
346 idModule=circuit->GetIdModule(); // corresponding module Id.
347 nStripX=circuit->GetNstripX(); // number of X strips
348 nStripY=circuit->GetNstripY(); // number of Y strips
349 iPosCircuit=circuit->GetPosCircuit(); // position of circuit in module
350
351// fill lower part
352 if (iPosCircuit==1) { // need to scan lower module
353 if(idModule<91&&TMath::Abs(idModule)!=41&&idModule>-91) {
354 Int_t icircD=circuit->GetICircuitD();
355 circuitD = &(pMUON->TriggerCircuit(icircD));
356 Int_t nStripD=circuitD->GetNstripY();
357
358 if (TMath::Abs(idModule)==42) { // shift of +8 bits
359 for (Int_t istrip=0; istrip<nStripD; istrip++) {
360 fYbit21D[icirc][istrip+8]=fYbit21[icircD][istrip];
361 fYbit22D[icirc][istrip+8]=fYbit22[icircD][istrip];
362 }
363 } else if (TMath::Abs(idModule)==52) { // shift of -8 bits
364 for (Int_t istrip=0; istrip<nStripD; istrip++) {
365 fYbit21D[icirc][istrip]=fYbit21[icircD][istrip+8];
366 fYbit22D[icirc][istrip]=fYbit22[icircD][istrip+8];
367 }
368 } else {
369 for (Int_t istrip=0; istrip<nStripD; istrip++) {
370 fYbit21D[icirc][istrip]=fYbit21[icircD][istrip];
371 fYbit22D[icirc][istrip]=fYbit22[icircD][istrip];
372 }
373 }
374 }
375 } else { // lower strips within same module
376 for (Int_t istrip=0; istrip<nStripY; istrip++) {
377 fYbit21D[icirc][istrip]=fYbit21[icirc][istrip];
378 fYbit22D[icirc][istrip]=fYbit22[icirc][istrip];
379 }
380 }
381
382// fill upper part
383 if ((iPosCircuit==1&&nStripX==16)||(iPosCircuit==2&&nStripX==32)||
384 (iPosCircuit==3&&nStripX==48)||(iPosCircuit==4&&nStripX==64)) {
385 if ((idModule>17||idModule<-17)&&TMath::Abs(idModule)!=61) {
386 Int_t icircU=circuit->GetICircuitU();
387 circuitU = &(pMUON->TriggerCircuit(icircU));
388 Int_t nStripU=circuitU->GetNstripY();
389
390 if (TMath::Abs(idModule)==62) { // shift of +8 bits
391 for (Int_t istrip=0; istrip<nStripU; istrip++) {
392 fYbit21U[icirc][istrip+8]=fYbit21[icircU][istrip];
393 fYbit22U[icirc][istrip+8]=fYbit22[icircU][istrip];
394 }
395 } else if (TMath::Abs(idModule)==52) { // shift of -8 bits
396 for (Int_t istrip=0; istrip<nStripU; istrip++) {
397 fYbit21U[icirc][istrip]=fYbit21[icircU][istrip+8];
398 fYbit22U[icirc][istrip]=fYbit22[icircU][istrip+8];
399 }
400 } else {
401 for (Int_t istrip=0; istrip<nStripU; istrip++) {
402 fYbit21U[icirc][istrip]=fYbit21[icircU][istrip];
403 fYbit22U[icirc][istrip]=fYbit22[icircU][istrip];
404 }
405 }
406 }
407 } else { // upper strips within same module
408 for (Int_t istrip=0; istrip<nStripY; istrip++) {
409 fYbit21U[icirc][istrip]=fYbit21[icirc][istrip];
410 fYbit22U[icirc][istrip]=fYbit22[icirc][istrip];
411 }
412 }
413 } // loop on circuit
414}
415
416//----------------------------------------------------------------------
417// x part of trigger Algo
418//----------------------------------------------------------------------
419//----------------------------------------------------------------------
420void AliMUONTriggerDecision::TrigX(Int_t ch1q[16], Int_t ch2q[16],
421 Int_t ch3q[32], Int_t ch4q[32],
422 Int_t coinc44, Int_t minDevStrip[5],
423 Int_t minDev[5]){
424// note : coinc44 = flag 0 or 1 (0 coincidence -> 3/4, 1 coincidence -> 4/4)
425//---------------------------------------------------------
426// step # 1 : declustering, reduction DS, calculate sgle & dble
427//---------------------------------------------------------
428 Int_t ch1e[19], ch2e[20], ch3e[35], ch4e[36];
429 Int_t sgleHit1[31], sgleHit2[63];
430 Int_t dbleHit1[31], dbleHit2[63];
431
e6738866 432 Int_t i;
433 Int_t j;
434 Int_t istrip;
435
436 for (i=0; i<31; i++) {
a9e2aefa 437 sgleHit1[i]=0;
438 dbleHit1[i]=0;
439 }
e6738866 440 for (i=0; i<63; i++) {
a9e2aefa 441 sgleHit2[i]=0;
442 dbleHit2[i]=0;
443 }
444
445//--- inititialize che using chq
e6738866 446 for (i=0; i<19; i++) {
a9e2aefa 447 if (i<1||i>16) ch1e[i]=0;
448 else ch1e[i]=ch1q[i-1];
449 }
e6738866 450 for (i=0; i<20; i++) {
a9e2aefa 451 if (i<2||i>17) ch2e[i]=0;
452 else ch2e[i]=ch2q[i-2];
453 }
e6738866 454 for (i=0; i<35; i++) {
a9e2aefa 455 if (i<1||i>32) ch3e[i]=0;
456 else ch3e[i]=ch3q[i-1];
457 }
e6738866 458 for (i=0; i<36; i++) {
a9e2aefa 459 if (i<2||i>33) ch4e[i]=0;
460 else ch4e[i]=ch4q[i-2];
461 }
462
463
464//--- calculate dble & sgle first station
e6738866 465 for (i=0; i<=15; i++) {
a9e2aefa 466 sgleHit1[2*i] = (!ch1e[i+1]|(ch1e[i]^ch1e[i+2])) &
467 (!ch2e[i+2] | (ch2e[i+1]^ch2e[i+3]));
468
469 dbleHit1[2*i] = ch1e[i+1]&!(ch1e[i+2]^ch1e[i]) &
470 (ch2e[i+2] | (!ch2e[i]&ch2e[i+1]) | (ch2e[i+3]&!ch2e[i+4]));
471 }
472
e6738866 473 for (i=0; i<=14; i++) {
a9e2aefa 474 sgleHit1[2*i+1] = (!ch1e[i+1]|!ch1e[i+2]|(ch1e[i]^ch1e[i+3])) &
475 (!ch2e[i+2] | !ch2e[i+3] | (ch2e[i+1]^ch2e[i+4]));
476 dbleHit1[2*i+1] = ch1e[i+1]&ch1e[i+2]&!(ch1e[i]^ch1e[i+3]) &
477 (ch2e[i+2]&(!ch2e[i+1]|!ch2e[i]) |
478 ch2e[i+3]&(ch2e[i+2]|!ch2e[i+4]|!ch2e[i+5]));
479 }
480
481//--- calculate dble & sgle second station
e6738866 482 for (i=0; i<=31; i++) {
a9e2aefa 483 sgleHit2[2*i] = (!ch3e[i+1]|(ch3e[i]^ch3e[i+2])) &
484 (!ch4e[i+2] | (ch4e[i+1]^ch4e[i+3]));
485 dbleHit2[2*i] = ch3e[i+1]&!(ch3e[i+2]^ch3e[i]) &
486 (ch4e[i+2] | (!ch4e[i]&ch4e[i+1]) | (ch4e[i+3]&!ch4e[i+4]));
487 }
488
e6738866 489 for (i=0; i<=30; i++) {
a9e2aefa 490 sgleHit2[2*i+1] = (!ch3e[i+1]|!ch3e[i+2]|(ch3e[i]^ch3e[i+3])) &
491 (!ch4e[i+2] | !ch4e[i+3] | (ch4e[i+1]^ch4e[i+4]));
492 dbleHit2[2*i+1] = ch3e[i+1]&ch3e[i+2]&!(ch3e[i]^ch3e[i+3]) &
493 (ch4e[i+2]&(!ch4e[i+1]|!ch4e[i]) |
494 ch4e[i+3]&(ch4e[i+2]|!ch4e[i+4]|!ch4e[i+5]));
495 }
496
497//---
ecfa008b 498 if(fDebug==3||fDebug==5) {
cbc57deb 499 printf("===============================================================\n");
500 printf(" X plane after sgle and dble \n");
501 printf(" 0987654321098765432109876543210");
502 printf("\n SGLE1 ");
503 for (istrip=30; istrip>=0; istrip--) printf("%i",(!sgleHit1[istrip]));
504 printf("\n DBLE1 ");
505 for (istrip=30; istrip>=0; istrip--) printf("%i",dbleHit1[istrip]);
506 printf("\n SGLE2 ");
507 for (istrip=62; istrip>=0; istrip--) printf("%i",(!sgleHit2[istrip]));
508 printf("\n DBLE2 ");
509 for (istrip=62; istrip>=0; istrip--) printf("%i",dbleHit2[istrip]);
510 printf("\n 210987654321098765432109876543210987654321098765432109876543210\n");
a9e2aefa 511 }
512
513//---------------------------------------------------------
514// step # 2 : coincidence 3/4
515//---------------------------------------------------------
516 Int_t rearImage[31][31];
e6738866 517 for (i=0; i<31; i++) {
518 for (j=0; j<31; j++) {
a9e2aefa 519 rearImage[i][j]=0;
520 }
521 }
522
523 Int_t notOr1=!dbleHit1[30] & !dbleHit1[29] & !dbleHit1[28] & !dbleHit1[27] &
524 !dbleHit1[26] & !dbleHit1[25] & !dbleHit1[24] & !dbleHit1[23] &
525 !dbleHit1[22] & !dbleHit1[21] & !dbleHit1[20] & !dbleHit1[19] &
526 !dbleHit1[18] & !dbleHit1[17] & !dbleHit1[16] & !dbleHit1[15] &
527 !dbleHit1[14] & !dbleHit1[13] & !dbleHit1[12] & !dbleHit1[11] &
528 !dbleHit1[10] & !dbleHit1[9] & !dbleHit1[8] & !dbleHit1[7] &
529 !dbleHit1[6] & !dbleHit1[5] & !dbleHit1[4] & !dbleHit1[3] &
530 !dbleHit1[2] & !dbleHit1[1] & !dbleHit1[0] & !coinc44;
531
532 Int_t notOr2= !dbleHit2[62] & !dbleHit2[61] & !dbleHit2[60] & !dbleHit2[59] &
533 !dbleHit2[58] & !dbleHit2[57] & !dbleHit2[56] & !dbleHit2[55] &
534 !dbleHit2[54] & !dbleHit2[53] & !dbleHit2[52] & !dbleHit2[51] &
535 !dbleHit2[50] & !dbleHit2[49] & !dbleHit2[48] & !dbleHit2[47] &
536 !dbleHit2[46] & !dbleHit2[45] & !dbleHit2[44] & !dbleHit2[43] &
537 !dbleHit2[42] & !dbleHit2[41] & !dbleHit2[40] & !dbleHit2[39] &
538 !dbleHit2[38] & !dbleHit2[37] & !dbleHit2[36] & !dbleHit2[35] &
539 !dbleHit2[34] & !dbleHit2[33] & !dbleHit2[32] & !dbleHit2[31] &
540 !dbleHit2[30] & !dbleHit2[29] & !dbleHit2[28] & !dbleHit2[27] &
541 !dbleHit2[26] & !dbleHit2[25] & !dbleHit2[24] & !dbleHit2[23] &
542 !dbleHit2[22] & !dbleHit2[21] & !dbleHit2[20] & !dbleHit2[19] &
543 !dbleHit2[18] & !dbleHit2[17] & !dbleHit2[16] & !dbleHit2[15] &
544 !dbleHit2[14] & !dbleHit2[13] & !dbleHit2[12] & !dbleHit2[11] &
545 !dbleHit2[10] & !dbleHit2[9] & !dbleHit2[8] & !dbleHit2[7] &
546 !dbleHit2[6] & !dbleHit2[5] & !dbleHit2[4] & !dbleHit2[3] &
547 !dbleHit2[2] & !dbleHit2[1] & !dbleHit2[0] & !coinc44;
548
549// DS reduction
e6738866 550 for (i=0; i<31; i++) {
a9e2aefa 551 sgleHit1[i] = !sgleHit1[i]&notOr1;
552 }
e6738866 553 for (i=0; i<63; i++) {
a9e2aefa 554 sgleHit2[i] = !sgleHit2[i]&notOr2;
555 }
556
557// extract rearImage
e6738866 558 for (i=0; i<31; i++){
a9e2aefa 559 Int_t tmpSgleHit2[31];
560 Int_t tmpDbleHit2[31];
e6738866 561 for (j=0; j<31; j++){
a9e2aefa 562 tmpSgleHit2[j] = sgleHit2[i+j+1];
563 tmpDbleHit2[j] = dbleHit2[i+j+1];
564 }
565
566 for (Int_t k=0; k<31; k++) {
567 rearImage[i][k]=(sgleHit1[i]&tmpDbleHit2[k])|
568 (dbleHit1[i]&(tmpSgleHit2[k]|tmpDbleHit2[k]));
569 }
570 }
571
572 //-----------
ecfa008b 573 if(fDebug==3||fDebug==5) {
cbc57deb 574 printf("===============================================================\n");
e6738866 575 for (i=30; i>=0; i--) {
cbc57deb 576 printf("%i \t",i);
577 for (istrip=31; istrip>=0; istrip--) printf("%i",rearImage[i][istrip]);
578 printf("\n");
a9e2aefa 579 }
580 }
a9e2aefa 581
582//---------------------------------------------------------
583// step # 3 : calculate deviation
584//---------------------------------------------------------
585 Int_t dev[31][6];
e6738866 586 for (i=0; i<31; i++) {
587 for (j=0; j<6; j++) {
a9e2aefa 588 dev[i][j]=0;
589 }
590 }
591
e6738866 592 for (i=0; i<31; i++){
a9e2aefa 593 Int_t leftDev[5], rightDev[5];
594 Int_t orL1, andL1, andL2, orR1, orR2, andR1, andR2, andR3;
595
596// calculate Left deviation
597 orL1=rearImage[i][16]|rearImage[i][18]|rearImage[i][20]|rearImage[i][22];
598 andL1=!rearImage[i][17]&!rearImage[i][19]&!rearImage[i][21] & !orL1;
599 andL2=!rearImage[i][23]&!rearImage[i][24]&!rearImage[i][25]&!rearImage[i][26];
600
601 leftDev[0] = (rearImage[i][16]|!rearImage[i][17]) &
602 (rearImage[i][16]|rearImage[i][18]|!rearImage[i][19]&
603 (rearImage[i][20]|!rearImage[i][21])) &
604 (orL1|!rearImage[i][23]&(rearImage[i][24]|!rearImage[i][25])) &
605 (orL1|rearImage[i][24]|rearImage[i][26]|!rearImage[i][27]&
606 (rearImage[i][28]|!rearImage[i][29]));
607
608 leftDev[1] = !rearImage[i][16] &
609 !(!rearImage[i][17]&!rearImage[i][18]&!rearImage[i][21]&!rearImage[i][22] &
610 (!rearImage[i][25]&!rearImage[i][26]&(rearImage[i][27]|rearImage[i][28]))) &
611 (rearImage[i][17]|rearImage[i][18] | !rearImage[i][19]&!rearImage[i][20]) &
612 (rearImage[i][17]|rearImage[i][18]|rearImage[i][21]|rearImage[i][22] |
613 !rearImage[i][23]&!rearImage[i][24]);
614
615 leftDev[2] = (!rearImage[i][16]&!rearImage[i][17]&!rearImage[i][18]) &
616 (rearImage[i][19]|rearImage[i][20]|rearImage[i][21]|rearImage[i][22] | andL2);
617
618 leftDev[3] = andL1;
619
620 leftDev[4] =
621 !rearImage[i][27]&!rearImage[i][28]&!rearImage[i][29]&!rearImage[i][30] &
622 andL1 & andL2;
623
624 // calculate Right deviation
625 orR1=rearImage[i][8]|rearImage[i][10]|rearImage[i][12]|rearImage[i][14];
626 orR2=rearImage[i][8]|rearImage[i][9]|rearImage[i][10]|rearImage[i][11];
627 andR1=!rearImage[i][12]&!rearImage[i][13]&!rearImage[i][14]&!rearImage[i][15];
628 andR2=
629 !rearImage[i][8]&!rearImage[i][9]&!rearImage[i][10]&!rearImage[i][11] & andR1;
630 andR3=!rearImage[i][4]&!rearImage[i][5]&!rearImage[i][6]&!rearImage[i][7];
631
632 rightDev[0] = !rearImage[i][15]&(rearImage[i][14]|!rearImage[i][13]) &
633 ((rearImage[i][12]|rearImage[i][14]|!rearImage[i][11]&
634 (rearImage[i][10]|!rearImage[i][9])) &
635 ((orR1|!rearImage[i][7]&(rearImage[i][6]|!rearImage[i][5])) &
636 (orR1|rearImage[i][4]|rearImage[i][6]|!rearImage[i][3]&(rearImage[i][2]|
637 !rearImage[i][1]))));
638
639 rightDev[1] = !rearImage[i][15]&!rearImage[i][14] &
640 !(!rearImage[i][4]&!rearImage[i][5]&!rearImage[i][8]&!rearImage[i][9] &
641 (!rearImage[i][12]&!rearImage[i][13]&(rearImage[i][2]|rearImage[i][3]))) &
642 (rearImage[i][12]|rearImage[i][13] | !rearImage[i][10]&!rearImage[i][11]) &
643 (rearImage[i][8]|rearImage[i][9]|rearImage[i][12]|rearImage[i][13] |
644 !rearImage[i][6]&!rearImage[i][7]);
645
646 rightDev[2] = andR1 & (orR2 | andR3);
647 rightDev[3] = andR2;
648 rightDev[4] =
649 !rearImage[i][0]&!rearImage[i][1]&!rearImage[i][2]&!rearImage[i][3] &
650 andR2 & andR3 ;
651
652 // compare Left & Right deviations
653 Int_t tmpLeftDev=0, tmpRightDev=0;
e6738866 654 for (j=0; j<5; j++){
655 tmpLeftDev = tmpLeftDev + Int_t(leftDev[j]*TMath::Power(2,j));
656 tmpRightDev = tmpRightDev + Int_t(rightDev[j]*TMath::Power(2,j));
a9e2aefa 657 }
658
659 // assign mimimum deviation do dev[][]
660 if (tmpLeftDev < tmpRightDev ){
e6738866 661 for (j=0; j<5; j++){ dev[i][j]=leftDev[j];}
a9e2aefa 662 dev[i][5]=1;
663 } else {
e6738866 664 for (j=0; j<5; j++){ dev[i][j]=rightDev[j];}
a9e2aefa 665 dev[i][5]=0;
666 }
667 }
668
669//---
cbc57deb 670 if(fDebug==3||fDebug==5) {
671 printf("===============================================================\n");
672 for (i=30; i>=0; i--) {
673 printf("%i \t",i);
674 for (istrip=5; istrip>=0; istrip--) printf("%i",dev[i][istrip]);
675 printf(" \n");
676 }
677 }
a9e2aefa 678
679//---------------------------------------------------------
680// step # 4 : sort deviation
681//---------------------------------------------------------
682 Int_t bga1[16], bga2[8], bga3[4], bga4[2], bga5;
683 Int_t tmpbga1[16][6], tmpbga2[8][6], tmpbga3[4][6], tmpbga4[2][6], tmpbga5[6];
684 Int_t tmpMax[6]={1,1,1,1,1,0};
685
e6738866 686 for (i=0; i<15; i++) {
a9e2aefa 687 Sort2x5(dev[2*i],dev[2*i+1],tmpbga1[i],bga1[i]);
688 }
689 Sort2x5(dev[30],tmpMax,tmpbga1[15],bga1[15]);
690
691//--
ecfa008b 692 if(fDebug==3||fDebug==5) {
cbc57deb 693 printf("===============================================================\n");
694 printf(" sorting : 1st level \n");
e6738866 695 for (i=15; i>=0; i--) {
cbc57deb 696 printf("\t %i \t",bga1[i]);
697 for (j=5; j>=0; j--) printf("%i",tmpbga1[i][j]);
698 printf(" \n");
a9e2aefa 699 }
700 }
701
e6738866 702 for (i=0; i<8; i++) {
a9e2aefa 703 Sort2x5(tmpbga1[2*i],tmpbga1[2*i+1],tmpbga2[i],bga2[i]);
704 }
705
706//--
ecfa008b 707 if(fDebug==3||fDebug==5) {
cbc57deb 708 printf("===============================================================\n");
709 printf(" sorting : 2nd level \n");
e6738866 710 for (i=7; i>=0; i--) {
cbc57deb 711 printf("\t %i \t",bga2[i]);
712 for (j=5; j>=0; j--) printf("%i",tmpbga1[i][j]);
713 printf(" \n");
a9e2aefa 714 }
715 }
cbc57deb 716
e6738866 717 for (i=0; i<4; i++) {
a9e2aefa 718 Sort2x5(tmpbga2[2*i],tmpbga2[2*i+1],tmpbga3[i],bga3[i]);
719 }
720
721//--
ecfa008b 722 if(fDebug==3||fDebug==5) {
cbc57deb 723 printf("===============================================================\n");
724 printf(" sorting : 3rd level \n");
e6738866 725 for (i=3; i>=0; i--) {
cbc57deb 726 printf("\t %i \t",bga3[i]);
727 for (j=5; j>=0; j--) printf("%i",tmpbga3[i][j]);
728 printf(" \n");
a9e2aefa 729 }
730 }
731
e6738866 732 for (i=0; i<2; i++) {
a9e2aefa 733 Sort2x5(tmpbga3[2*i],tmpbga3[2*i+1],tmpbga4[i],bga4[i]);
734 }
735
736//--
ecfa008b 737 if(fDebug==3||fDebug==5) {
cbc57deb 738 printf("===============================================================\n");
739 printf(" sorting : 4th level \n");
e6738866 740 for (i=1; i>=0; i--) {
cbc57deb 741 printf("\t %i \t",bga4[i]);
742 for (j=5; j>=0; j--) printf("%i",tmpbga4[i][j]);
743 printf(" \n");
a9e2aefa 744 }
745 }
746
747 Sort2x5(tmpbga4[0],tmpbga4[1],tmpbga5,bga5);
748
749 // coding from 6 to 5 bits
750 minDev[4] = tmpbga5[5] | tmpbga5[4];
e6738866 751 for (i=0; i<4; i++) {
a9e2aefa 752 minDev[i]=tmpbga5[i] & !tmpbga5[4];
753 }
754
755 // find address of strip with minimum deviation
756 minDevStrip[4]=bga5;
757 if (bga5<=1) minDevStrip[3]=bga4[bga5];
758
759 Int_t tmpAd=minDevStrip[3]+minDevStrip[4]*2;
760 if (tmpAd<=3) minDevStrip[2]=bga3[tmpAd];
761
762 tmpAd=minDevStrip[2]+minDevStrip[3]*2+minDevStrip[4]*4;
763 if (tmpAd<=7) minDevStrip[1]=bga2[tmpAd];
764
765 tmpAd=minDevStrip[1]+minDevStrip[2]*2+minDevStrip[3]*4+minDevStrip[4]*8;
766 if (tmpAd<=15) minDevStrip[0]=bga1[tmpAd];
767
cbc57deb 768 if(fDebug==3||fDebug==5) {
769 printf("===============================================================\n");
770 printf("minDevStrip = ");
771 for (i=4; i>=0; i--) printf("%i",minDevStrip[i]);
772 printf(" minDev = ");
773 for (i=4; i>=0; i--) printf("%i",minDev[i]);
774 printf(" \n");
775 printf("===============================================================\n");
a9e2aefa 776 }
777
778}
779
780//---------------------------------------------
781void AliMUONTriggerDecision::Sort2x5(Int_t dev1[6], Int_t dev2[6],
782 Int_t minDev[6], Int_t &dev1GTdev2){
783// returns minimun between dev1 and dev2
784 Int_t tmpDev1=0, tmpDev2=0;
785 for (Int_t j=0; j<5; j++){
e6738866 786 tmpDev1 = tmpDev1 + Int_t(dev1[j]*TMath::Power(2,j));
787 tmpDev2 = tmpDev2 + Int_t(dev2[j]*TMath::Power(2,j));
a9e2aefa 788 }
789 if (tmpDev1 <= tmpDev2 ){
790 for (Int_t j=0; j<=5; j++) { minDev[j]=dev1[j];}
791 dev1GTdev2=0;
792 } else {
793 for (Int_t j=0; j<=5; j++) { minDev[j]=dev2[j];}
794 dev1GTdev2=1;
795 }
796}
797
798//----------------------------------------------------------------------
799// y part of trigger Algo
800//----------------------------------------------------------------------
801//----------------------------------------------------------------------
802void AliMUONTriggerDecision::TrigY(Int_t y1[16], Int_t y2[16],
803 Int_t y3[16], Int_t y4[16],
804 Int_t y3u[16], Int_t y3d[16],
805 Int_t y4u[16], Int_t y4d[16],
806 Int_t x2m, Int_t x2ud, Int_t orMud[2],
807 Int_t resetMid, Int_t coinc44,
808 Int_t coordY[5]){
809// note : resMid = 1 -> cancel
810//---------------------------------------------------------
811// step # 1 : prehandling Y
812//---------------------------------------------------------
e6738866 813 Int_t i;
814 Int_t istrip;
815
816 for (i=0; i<16; i++){
a9e2aefa 817 y3[i]=y3[i]&!resetMid;
818 y4[i]=y4[i]&!resetMid;
819 }
820
821 Int_t ch1[16], ch2[16], ch3[16], ch4[16];
822
823 Int_t tmpy3to16[16], tmpy4to16[16];
824 Int_t tmpy3uto16[16], tmpy3dto16[16], tmpy4uto16[16], tmpy4dto16[16];
e6738866 825 for (i=0; i<8; i++){
a9e2aefa 826 ch1[2*i] = y1[i]&x2m | y1[2*i]&!x2m;
827 ch1[2*i+1] = y1[i]&x2m | y1[2*i+1]&!x2m;
828
829 ch2[2*i] = y2[i]&x2m | y2[2*i]&!x2m;
830 ch2[2*i+1] = y2[i]&x2m | y2[2*i+1]&!x2m;
831
832 tmpy3to16[2*i] = y3[i]&x2m | y3[2*i]&!x2m;
833 tmpy3to16[2*i+1] = y3[i]&x2m | y3[2*i+1]&!x2m;
834
835 tmpy4to16[2*i] = y4[i]&x2m | y4[2*i]&!x2m;
836 tmpy4to16[2*i+1] = y4[i]&x2m | y4[2*i+1]&!x2m;
837
838 tmpy3uto16[2*i] = y3u[i]&x2ud | y3u[2*i]&!x2ud;
839 tmpy3uto16[2*i+1] = y3u[i]&x2ud | y3u[2*i+1]&!x2ud;
840
841 tmpy4uto16[2*i] = y4u[i]&x2ud | y4u[2*i]&!x2ud;
842 tmpy4uto16[2*i+1] = y4u[i]&x2ud | y4u[2*i+1]&!x2ud;
843
844 tmpy3dto16[2*i] = y3d[i]&x2ud | y3d[2*i]&!x2ud;
845 tmpy3dto16[2*i+1] = y3d[i]&x2ud | y3d[2*i+1]&!x2ud;
846
847 tmpy4dto16[2*i] = y4d[i]&x2ud | y4d[2*i]&!x2ud;
848 tmpy4dto16[2*i+1] = y4d[i]&x2ud | y4d[2*i+1]&!x2ud;
849 }
850
851 if (orMud[0]==0&&orMud[1]==0){
e6738866 852 for (i=0; i<16; i++){
a9e2aefa 853 ch3[i] = tmpy3to16[i];
854 ch4[i] = tmpy4to16[i];
855 }
856 }
857 if (orMud[0]==0&&orMud[1]==1){
e6738866 858 for (i=0; i<16; i++){
a9e2aefa 859 ch3[i] = tmpy3uto16[i]|tmpy3to16[i];
860 ch4[i] = tmpy4uto16[i]|tmpy4to16[i];
861 }
862 }
863 if (orMud[0]==1&&orMud[1]==0){
e6738866 864 for (i=0; i<16; i++){
a9e2aefa 865 ch3[i] = tmpy3dto16[i]|tmpy3to16[i];
866 ch4[i] = tmpy4dto16[i]|tmpy4to16[i];
867 }
868 }
869 if (orMud[0]==1&&orMud[1]==1){
e6738866 870 for (i=0; i<16; i++){
a9e2aefa 871 ch3[i] = tmpy3dto16[i]|tmpy3to16[i]|tmpy3uto16[i];
872 ch4[i] = tmpy4dto16[i]|tmpy4to16[i]|tmpy4uto16[i];
873 }
874 }
875
876// debug
ecfa008b 877 if(fDebug==4||fDebug==5) {
cbc57deb 878 printf("===============================================================\n");
879 printf(" Y plane after PreHandling x2m x2ud orMud %i %i %i %i \n",
880 x2m,x2ud,orMud[0],orMud[1]);
881 printf(" ");
e6738866 882 for (istrip=15; istrip>=0; istrip--) {
cbc57deb 883 if (istrip>9) printf("%i",istrip-10*Int_t(istrip/10));
884 if (istrip<10) printf("%i",istrip);
a9e2aefa 885 }
cbc57deb 886 printf("\n YMC11 ");
887 for (istrip=15; istrip>=0; istrip--) printf("%i",ch1[istrip]);
888 printf("\n YMC12 ");
889 for (istrip=15; istrip>=0; istrip--) printf("%i",ch2[istrip]);
890 printf("\n YMC21 ");
891 for (istrip=15; istrip>=0; istrip--) printf("%i",ch3[istrip]);
892 printf("\n YMC22 ");
893 for (istrip=15; istrip>=0; istrip--) printf("%i",ch4[istrip]);
894 printf(" \n");
a9e2aefa 895 }
896//debug
897
898//---------------------------------------------------------
899// step # 2 : calculate sgle and dble, apply DS reduction
900//---------------------------------------------------------
901 Int_t sgle1[16], dble1[16];
902 Int_t sgle2[16], dble2[16];
903
904 // Calculate simple and double hits
e6738866 905 for (i=0; i<16; i++) {
a9e2aefa 906 dble1[i] = ch1[i] & ch2[i];
907 dble2[i] = ch3[i] & ch4[i];
908
909 sgle1[i] = (ch1[i]|ch2[i]);
910 sgle2[i] = (ch3[i]|ch4[i]);
911 }
912
913 //debug
ecfa008b 914 if(fDebug==4||fDebug==5) {
cbc57deb 915 printf("===============================================================\n");
916 printf(" Y plane after sgle dble \n");
917 printf(" ");
e6738866 918 for (istrip=15; istrip>=0; istrip--) {
cbc57deb 919 if (istrip>9) printf("%i",istrip-10*Int_t(istrip/10));
920 if (istrip<10) printf("%i",istrip);
a9e2aefa 921 }
cbc57deb 922 printf("\n SGLE1 ");
923 for (istrip=15; istrip>=0; istrip--) printf("%i",sgle1[istrip]);
924 printf("\n DBLE1 ");
925 for (istrip=15; istrip>=0; istrip--) printf("%i",dble1[istrip]);
926 printf("\n SGLE2 ");
927 for (istrip=15; istrip>=0; istrip--) printf("%i",sgle2[istrip]);
928 printf("\n DBLE2 ");
929 for (istrip=15; istrip>=0; istrip--) printf("%i",dble2[istrip]);
930 printf(" \n");
a9e2aefa 931 }
932 //debug
933
934 // DS Reduction
935 Int_t notOr1, notOr2;
936
937 notOr1=!dble1[15] & !dble1[14] & !dble1[13] & !dble1[12] &
938 !dble1[11] & !dble1[10] & !dble1[9] & !dble1[8] &
939 !dble1[7] & !dble1[6] & !dble1[5] & !dble1[4] &
940 !dble1[3] & !dble1[2] & !dble1[1] & !dble1[0];
941
942 notOr2=!dble2[15] & !dble2[14] & !dble2[13] & !dble2[12] &
943 !dble2[11] & !dble2[10] & !dble2[9] & !dble2[8] &
944 !dble2[7] & !dble2[6] & !dble2[5] & !dble2[4] &
945 !dble2[3] & !dble2[2] & !dble2[1] & !dble2[0];
946
e6738866 947 for (i=0; i<16; i++) {
a9e2aefa 948 sgle1[i] = sgle1[i] & notOr1 & !coinc44;
949 sgle2[i] = sgle2[i] & notOr2 & !coinc44;
950 }
951
952//---------------------------------------------------------
953// step # 3 : 3/4 coincidence
954//---------------------------------------------------------
955 Int_t frontImage[16];
956
e6738866 957 for (i=1; i<15; i++) {
a9e2aefa 958 frontImage[i] = (dble1[i] | sgle1[i]) &
959 (dble2[i+1] | dble2[i] | dble2[i-1]) |
960 dble1[i] & (sgle2[i+1] | sgle2[i] | sgle2[i-1]);
961 }
962 frontImage[0] = (dble1[0] | sgle1[0]) &
963 (dble2[1] | dble2[0]) | dble1[0] & (sgle2[1] | sgle2[0]);
964
965 frontImage[15] = (dble1[15] | sgle1[15]) &
966 (dble2[15] | dble2[14]) | dble1[15] & (sgle2[15] | sgle2[14]);
967
968
969//debug
ecfa008b 970 if(fDebug==4||fDebug==5) {
cbc57deb 971 printf("===============================================================\n");
972 printf(" Y plane frontImage\n");
973 printf(" ");
e6738866 974 for (istrip=15; istrip>=0; istrip--) {
cbc57deb 975 if (istrip>9) printf("%i",istrip-10*Int_t(istrip/10));
976 if (istrip<10) printf("%i",istrip);
a9e2aefa 977 }
cbc57deb 978 printf("\n ");
979 for (istrip=15; istrip>=0; istrip--) printf("%i",frontImage[istrip]);
980 printf("\n");
a9e2aefa 981 }
982//debug
983
984//---------------------------------------------------------
985// step # 4 : Y position
986//---------------------------------------------------------
987 Int_t or1, or2, and1, and2, and3;
988
989 or1 = frontImage[7]|frontImage[5]|frontImage[3]|frontImage[1];
990 or2 = frontImage[7]|frontImage[6]|frontImage[5]|frontImage[4];
991 and1 = !frontImage[3]&!frontImage[2]&!frontImage[1]&!frontImage[0];
992 and2 = !frontImage[7]&!frontImage[6]&!frontImage[5]&!frontImage[4] & and1;
993 and3 = !frontImage[11]&!frontImage[10]&!frontImage[9]&!frontImage[8];
994
995 coordY[0] = !frontImage[0]&(frontImage[1]|!frontImage[2]) &
996(frontImage[3]|frontImage[1]|!frontImage[4]&(frontImage[5]|!frontImage[6])) &
997(or1|!frontImage[8]&(frontImage[9]|!frontImage[10])) &
998(or1|frontImage[11]|frontImage[9]|!frontImage[12]&(frontImage[13]|!frontImage[14]));
999
1000 coordY[1] = !frontImage[0]&!frontImage[1] &
1001!(!frontImage[11]&!frontImage[10]&!frontImage[7]&!frontImage[6] &
1002 !frontImage[3]&!frontImage[2]&(frontImage[13]|frontImage[12])) &
1003 (frontImage[3]|frontImage[2] | !frontImage[5]&!frontImage[4]) &
1004 (frontImage[7]|frontImage[6]|frontImage[3]|frontImage[2] |
1005!frontImage[9]&!frontImage[8]);
1006
1007 coordY[2] = and1 & (or2 | and3);
1008
1009 coordY[3] = and2;
1010
1011 coordY[4] = !frontImage[15]&!frontImage[14]&!frontImage[13]&!frontImage[12] &
1012 and2 & and3 ;
1013
1014}
1015//----------------------------------------------------------------------
1016// end of trigger Algo
1017//----------------------------------------------------------------------
1018
1019//----------------------------------------------------------------------
1020void AliMUONTriggerDecision::LocalTrigger(Int_t icirc,
1021 Int_t minDevStrip[5],
1022 Int_t minDev[5], Int_t coordY[5],
1023 Int_t &iTrigger){
1024// returns local trigger answer for circuit icirc
e6738866 1025 Int_t i;
1026
a9e2aefa 1027 AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
1028 AliMUONTriggerCircuit* triggerCircuit;
1029 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
1030 Int_t idCircuit=triggerCircuit->GetIdCircuit();
1031
1032 Int_t signDev=minDev[4];
1033 Int_t deviation=0;
e6738866 1034 for (i=0; i<4; i++) { // extract deviation
1035 deviation = deviation+Int_t(minDev[i]*TMath::Power(2,i));
a9e2aefa 1036 }
1037
1038 Int_t istripX1Circ=0;
e6738866 1039 for (i=0; i<5; i++) { // extract X1 strip fired
1040 istripX1Circ = istripX1Circ+Int_t(minDevStrip[i]*TMath::Power(2,i));
a9e2aefa 1041 }
1042
1043 Int_t iStripY=0;
e6738866 1044 for (i=0; i<4; i++) { // extract Y strip fired
1045 iStripY = iStripY+Int_t(coordY[i]*TMath::Power(2,i));
a9e2aefa 1046 }
1047
1048// trigger or not
1049 if (signDev==1&&deviation==0) { // something in X ?
1050 iTrigger=0;
1051 } else {
1052 if (coordY[4]==1&&iStripY==15) { // something in Y ?
1053 iTrigger=0;
1054 } else {
1055 iTrigger=1;
1056 }
1057 }
1058
1059 if (iTrigger==1) {
ecfa008b 1060// fill fTrigger fStripX11 fStripY11
1061 fTrigger[icirc] = 1;
a9e2aefa 1062 fStripX11[icirc] = istripX1Circ;
1063 fStripY11[icirc] = iStripY;
1064
1065// calculate deviation in [0+30]
1066 Int_t sign=0;
1067 if (signDev==0&&deviation!=0) sign=-1;
1068 if (signDev==0&&deviation==0) sign=0;
1069 if (signDev==1) sign=1;
ecfa008b 1070 fDev[icirc] = sign * deviation + 15; // fill fDev
a9e2aefa 1071
1072// get Lut output for circuit/istripX/idev/istripY
1073 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
1074 // lut->StartEvent();
ecfa008b 1075 lut->GetLutOutput(icirc,fStripX11[icirc],fDev[icirc],fStripY11[icirc],
a9e2aefa 1076 fLutLpt[icirc],fLutHpt[icirc],fLutApt[icirc]);
1077 // lut->FinishEvent();
1078 delete lut;
1079
ecfa008b 1080 if (fDebug>1) {
a9e2aefa 1081 Float_t pt= // get ptCal corresponding to istripX1Circ/idev/iStripY
ecfa008b 1082 triggerCircuit->PtCal(fStripX11[icirc],fDev[icirc],fStripY11[icirc]);
cbc57deb 1083 printf("-------------------------------------------\n");
1084 printf(" Local Trigger info for circuit Id %i (number %i ) \n",
1085 idCircuit,icirc);
1086 printf(" istripX1 signDev deviation istripY = %i %i %i %i \n",
1087 istripX1Circ,signDev,deviation,iStripY);
1088 printf(" pt = %f (GeV/c) \n",pt);
1089 printf("-------------------------------------------\n");
1090 printf(" Local Trigger Lut Output = Lpt : ");
1091 for (i=1; i>=0; i--) printf("%i",fLutLpt[icirc][i]);
1092 printf(" Hpt : ");
1093 for (i=1; i>=0; i--) printf("%i",fLutHpt[icirc][i]);
1094 printf(" Apt : ");
1095 for (i=1; i>=0; i--) printf("%i",fLutApt[icirc][i]);
1096 printf("\n");
1097 printf("-------------------------------------------\n");
ecfa008b 1098 } // fDebug > 1
a9e2aefa 1099 } // local trigger = 1
1100}
1101
1102//----------------------------------------------------------------------
1103void AliMUONTriggerDecision::GlobalTrigger(){
1104// loop on Lut[icirc] and give Global Trigger output
e6738866 1105 Int_t i;
a9e2aefa 1106
1107 for (Int_t icirc=0; icirc<234; icirc++){
1108 if (fLutLpt[icirc][0]==1&&fLutLpt[icirc][1]==1)
1109 fGlobalSingleUndef[0] = fGlobalSingleUndef[0] + 1;
1110 if (fLutHpt[icirc][0]==1&&fLutHpt[icirc][1]==1)
1111 fGlobalSingleUndef[1] = fGlobalSingleUndef[1] + 1;
1112 if (fLutApt[icirc][0]==1&&fLutApt[icirc][1]==1)
1113 fGlobalSingleUndef[2] = fGlobalSingleUndef[2] + 1;
1114
1115 if (fLutLpt[icirc][0]==0&&fLutLpt[icirc][1]==1)
1116 fGlobalSinglePlus[0] = fGlobalSinglePlus[0] + 1;
1117 if (fLutHpt[icirc][0]==0&&fLutHpt[icirc][1]==1)
1118 fGlobalSinglePlus[1] = fGlobalSinglePlus[1] + 1;
1119 if (fLutApt[icirc][0]==0&&fLutApt[icirc][1]==1)
1120 fGlobalSinglePlus[2] = fGlobalSinglePlus[2] + 1;
1121
1122 if (fLutLpt[icirc][0]==1&&fLutLpt[icirc][1]==0)
1123 fGlobalSingleMinus[0] = fGlobalSingleMinus[0] + 1;
1124 if (fLutHpt[icirc][0]==1&&fLutHpt[icirc][1]==0)
1125 fGlobalSingleMinus[1] = fGlobalSingleMinus[1] + 1;
1126 if (fLutApt[icirc][0]==1&&fLutApt[icirc][1]==0)
1127 fGlobalSingleMinus[2] = fGlobalSingleMinus[2] + 1;
1128 }
1129
1130 // like sign low, high and all pt
e6738866 1131 for (i=0; i<3; i++) {
a9e2aefa 1132 fGlobalPairLike[i]=fGlobalSingleMinus[i]*(fGlobalSingleMinus[i]-1)/2 +
1133 fGlobalSinglePlus[i]*(fGlobalSinglePlus[i]-1)/2 +
1134 fGlobalSingleUndef[i]*(fGlobalSingleUndef[i]-1)/2 +
1135 fGlobalSingleUndef[i]*fGlobalSinglePlus[i] +
1136 fGlobalSingleUndef[i]*fGlobalSingleMinus[i];
1137 }
1138
1139 // unlike sign low, high and all pt
e6738866 1140 for (i=0; i<3; i++) {
a9e2aefa 1141 fGlobalPairUnlike[i]=fGlobalSingleMinus[i]*fGlobalSinglePlus[i] +
1142 fGlobalSingleUndef[i]*(fGlobalSingleUndef[i]-1)/2 +
1143 fGlobalSingleUndef[i]*fGlobalSinglePlus[i] +
1144 fGlobalSingleUndef[i]*fGlobalSingleMinus[i];
1145 }
1146
ecfa008b 1147 if (fDebug>=1) {
cbc57deb 1148 printf("\n");
1149 printf("===================================================\n");
1150 printf(" Global Trigger output Low pt High pt All\n");
1151 printf(" number of Single Plus :\t");
1152 for (i=0; i<3; i++) printf("%i\t",fGlobalSinglePlus[i]);
1153 printf("\n");
1154 printf(" number of Single Minus :\t");
1155 for (i=0; i<3; i++) printf("%i\t",fGlobalSingleMinus[i]);
1156 printf("\n");
1157 printf(" number of Single Undefined :\t");
1158 for (i=0; i<3; i++) printf("%i\t",fGlobalSingleUndef[i]);
1159 printf("\n");
1160 printf(" number of UnlikeSign pair :\t");
1161 for (i=0; i<3; i++) printf("%i\t",fGlobalPairUnlike[i]);
1162 printf("\n");
1163 printf(" number of LikeSign pair :\t");
1164 for (i=0; i<3; i++) printf("%i\t",fGlobalPairLike[i]);
1165 printf("\n");
1166 printf("===================================================\n");
a9e2aefa 1167 }
1168}
1169
1170//----------------------------------------------------------------------
1171void AliMUONTriggerDecision::PrintBitPatXInput(Int_t icirc){
1172// print bit pattern for X strips
e6738866 1173
1174 Int_t istrip;
1175
cbc57deb 1176 printf("-------- TRIGGER INPUT ---------\n");
1177 printf("===============================================================\n");
1178 printf(" 5432109876543210");
1179 printf("\n XMC11 ");
1180 for (istrip=15; istrip>=0; istrip--) printf("%i",fXbit11[icirc][istrip]);
1181 printf("\n XMC12 ");
1182 for (istrip=15; istrip>=0; istrip--) printf("%i",fXbit12[icirc][istrip]);
1183 printf("\n XMC21 ");
1184 for (istrip=31; istrip>=0; istrip--) printf("%i",fXbit21[icirc][istrip]);
1185 printf("\n XMC22 ");
1186 for (istrip=31; istrip>=0; istrip--) printf("%i",fXbit22[icirc][istrip]);
1187 printf("\n ");
1188 printf("10987654321098765432109876543210\n");
a9e2aefa 1189}
1190
1191//----------------------------------------------------------------------
1192void AliMUONTriggerDecision::PrintBitPatYInput(Int_t icirc){
1193// print bit pattern for Y strips
e6738866 1194
1195 Int_t istrip;
1196
a9e2aefa 1197 AliMUON *pMUON = (AliMUON*)gAlice->GetModule("MUON");
1198 AliMUONTriggerCircuit* triggerCircuit;
1199 triggerCircuit = &(pMUON->TriggerCircuit(icirc));
1200 Int_t idCircuit=triggerCircuit->GetIdCircuit();
1201 Int_t nStrip=triggerCircuit->GetNstripY();
1202
cbc57deb 1203 printf("---------------------------------------------------------------\n");
1204 printf(" ");
e6738866 1205 for (istrip=nStrip-1; istrip>=0; istrip--) {
cbc57deb 1206 if (istrip>9) printf("%i",istrip-10*Int_t(istrip/10));
1207 if (istrip<10) printf("%i",istrip);
a9e2aefa 1208 }
cbc57deb 1209 printf("\n YMC11 ");
1210 for (istrip=nStrip-1; istrip>=0; istrip--)
1211 printf("%i",fYbit11[icirc][istrip]);
1212 printf("\n YMC12 ");
1213 for (istrip=nStrip-1; istrip>=0; istrip--)
1214 printf("%i",fYbit12[icirc][istrip]);
1215 printf("\n YMC21 ");
1216 for (istrip=nStrip-1; istrip>=0; istrip--)
1217 printf("%i",fYbit21[icirc][istrip]);
1218 printf("\n YMC22 ");
1219 for (istrip=nStrip-1; istrip>=0; istrip--)
1220 printf("%i",fYbit22[icirc][istrip]);
1221 printf("\n");
a9e2aefa 1222// tmp
cbc57deb 1223 printf("---------------------------------------------------------------");
1224 printf("\n upper part of circuit %i",idCircuit);
1225 printf("\n UMC21 ");
1226 for (istrip=15; istrip>=0; istrip--) printf("%i",fYbit21U[icirc][istrip]);
1227 printf("\n UMC22 ");
1228 for (istrip=15; istrip>=0; istrip--) printf("%i", fYbit22U[icirc][istrip]);
1229
1230 printf("\n lower part of circuit %i",idCircuit);
1231 printf("\n LMC21 ");
1232 for (istrip=15; istrip>=0; istrip--) printf("%i",fYbit21D[icirc][istrip]);
1233 printf("\n LMC22 ");
1234 for (istrip=15; istrip>=0; istrip--) printf("%i",fYbit22D[icirc][istrip]);
1235 printf("\n");
1236 printf("===============================================================\n");
a9e2aefa 1237}
1238//----------------------------------------------------------------------
1239void AliMUONTriggerDecision::PrintLocalOutput(Int_t minDevStrip[5],
1240 Int_t minDev[5],
1241 Int_t coordY[5]){
1242// print Local trigger output before the LuT step
e6738866 1243
1244 Int_t i;
1245
cbc57deb 1246 printf("===============================================================\n");
1247 printf("-------- TRIGGER OUTPUT --------\n");
1248 printf("minDevStrip = ");
1249 for (i=4; i>=0; i--) printf("%i",minDevStrip[i]);
1250 printf(" minDev = ");
1251 for (i=4; i>=0; i--) printf("%i",minDev[i]);
1252 printf(" coordY = ");
1253 for (i=4; i>=0; i--) printf("%i",coordY[i]);
1254 printf(" \n");
a9e2aefa 1255}
1256
1257//----------------------------------------------------------------------
1258//--- methods which return member data related info
1259//----------------------------------------------------------------------
1260Int_t AliMUONTriggerDecision::GetITrigger(Int_t icirc){
1261// returns Local Trigger Status
ecfa008b 1262 return fTrigger[icirc];
a9e2aefa 1263}
1264//----------------------------------------------------------------------
1265Int_t AliMUONTriggerDecision::GetStripX11(Int_t icirc){
1266// returns fStripX11
1267 return fStripX11[icirc];
1268}
1269//----------------------------------------------------------------------
1270Int_t AliMUONTriggerDecision::GetDev(Int_t icirc){
1271// returns idev
ecfa008b 1272 return fDev[icirc];
a9e2aefa 1273}
1274//----------------------------------------------------------------------
1275Int_t AliMUONTriggerDecision::GetStripY11(Int_t icirc){
1276// returns fStripY11;
1277 return fStripY11[icirc];
1278}
1279//----------------------------------------------------------------------
1280void AliMUONTriggerDecision::GetLutOutput(Int_t icirc, Int_t lpt[2],
1281 Int_t hpt[2], Int_t apt[2]){
1282// returns Look up Table output
1283 for (Int_t i=0; i<2; i++) {
1284 lpt[i]=fLutLpt[icirc][i];
1285 hpt[i]=fLutHpt[icirc][i];
1286 apt[i]=fLutApt[icirc][i];
1287 }
1288}
1289//----------------------------------------------------------------------
1290void AliMUONTriggerDecision::GetGlobalTrigger(Int_t singlePlus[3],
1291 Int_t singleMinus[3],
1292 Int_t singleUndef[3],
1293 Int_t pairUnlike[3],
1294 Int_t pairLike[3]){
1295// returns Global Trigger information (0,1,2 : Lpt,Hpt,Apt)
1296 for (Int_t i=0; i<3; i++) {
1297 singlePlus[i] = fGlobalSinglePlus[i];
1298 singleMinus[i] = fGlobalSingleMinus[i];
1299 singleUndef[i] = fGlobalSingleUndef[i];
1300 pairUnlike[i] = fGlobalPairUnlike[i];
1301 pairLike[i] = fGlobalPairLike[i];
1302 }
1303}
1304//----------------------------------------------------------------------
1305//--- end of methods which return member data related info
1306//----------------------------------------------------------------------
1307//----------------------------------------------------------------------
1308/*
1309void AliMUONTriggerDecision::AddLocalTrigger(const AliMUONLocalTrigger c){
1310// Add a Local Trigger copy to the list
1311 AliMUON *MUON=(AliMUON*)gAlice->GetModule("MUON");
1312 MUON->AddLocalTrigger(c);
1313 fNLocalTriggers++;
1314}
1315*/