Integrated New Rule Checker with the CMake Build
[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/////////////////////////////////////////////////////////////////////
ee51d470 19//
cd82ed2f 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//
ee51d470 27// A.Silenzi: added CTTM map,
28// method to fill LTM matrix from raw data,
29// method to retrieve the TOF pre-trigger for TRD detector
30//
31//
cd82ed2f 32/////////////////////////////////////////////////////////////////////
33
7ca4655f 34#include <TClonesArray.h>
35
cd82ed2f 36#include "AliLoader.h"
0e46b9ae 37#include "AliLog.h"
cd82ed2f 38#include "AliRunLoader.h"
0e46b9ae 39#include "AliRun.h"
cd82ed2f 40#include "AliTriggerInput.h"
ee51d470 41#include "AliRawReader.h"
0e46b9ae 42
ee51d470 43#include "AliTOFRawStream.h"
44#include "AliTOFrawData.h"
cd82ed2f 45#include "AliTOFdigit.h"
ee51d470 46#include "AliTOFGeometry.h"
0e46b9ae 47#include "AliTOFTrigger.h"
c06f660b 48#include "AliTOFTriggerMask.h"
cd82ed2f 49
0e46b9ae 50extern AliRun* gAlice;
cd82ed2f 51
52//-------------------------------------------------------------------------
53ClassImp(AliTOFTrigger)
54
55//----------------------------------------------------------------------
ee51d470 56 AliTOFTrigger::AliTOFTrigger() :
57 AliTriggerDetector(),
cd82ed2f 58 fHighMultTh(1000),
c06f660b 59 fppMBTh(4),//4:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
60 fMultiMuonTh(4),
cd82ed2f 61 fUPTh(2),
c06f660b 62 fdeltaminpsi(150), //150
63 fdeltamaxpsi(170), //170
cd82ed2f 64 fdeltaminro(70),
65 fdeltamaxro(110),
c06f660b 66 fstripWindow(2),
67 fSel1(0),
68 fSel2(0),
69 fSel3(0),
70 fSel4(0),
71 fNCrateOn(0),
72 fNMaxipadOn(0),
73 fNMaxipadOnAll(0),
74 fTOFTrigMask(0)
cd82ed2f 75{
76 //main ctor
77 for (Int_t i=0;i<kNLTM;i++){
c06f660b 78 fLTMarray[i] = kFALSE; //*******************************************************************************************************
cd82ed2f 79 for (Int_t j=0;j<kNLTMchannels;j++){
80 fLTMmatrix[i][j]=kFALSE;
81 }
82 if (i<kNCTTM){
83 for (Int_t j=0;j<kNCTTMchannels;j++){
84 fCTTMmatrixFront[i][j]=kFALSE;
85 fCTTMmatrixBack[i][j]=kFALSE;
86 }
87 }
88 }
c06f660b 89
90 fPowerMask[0] = 1;
91 for(Int_t i=1;i <= kNCTTMchannels;i++){
92 fPowerMask[i] = fPowerMask[i-1]*2;
93 }
94
cd82ed2f 95 SetName("TOF");
96 CreateInputs();
c06f660b 97
cd82ed2f 98}
ee51d470 99
cd82ed2f 100//----------------------------------------------------------------------
ee51d470 101
102AliTOFTrigger::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) :
103 AliTriggerDetector(),
655e379f 104 fHighMultTh(HighMultTh),
105 fppMBTh(ppMBTh),
106 fMultiMuonTh(MultiMuonTh),
107 fUPTh(UPTh),
108 fdeltaminpsi(deltaminpsi),
109 fdeltamaxpsi(deltamaxpsi),
110 fdeltaminro(deltaminro),
111 fdeltamaxro(deltamaxro),
c06f660b 112 fstripWindow(stripWindow),
113 fSel1(0),
114 fSel2(0),
115 fSel3(0),
116 fSel4(0),
117 fNCrateOn(0),
118 fNMaxipadOn(0),
119 fNMaxipadOnAll(0),
120 fTOFTrigMask(0)
cd82ed2f 121{
122 //ctor with thresholds for triggers
cd82ed2f 123 for (Int_t i=0;i<kNLTM;i++){
c06f660b 124 fLTMarray[i] = kFALSE; //*******************************************************************************************************
cd82ed2f 125 for (Int_t j=0;j<kNLTMchannels;j++){
126 fLTMmatrix[i][j]=kFALSE;
127 }
128 if (i<kNCTTM){
129 for (Int_t j=0;j<kNCTTMchannels;j++){
130 fCTTMmatrixFront[i][j]=kFALSE;
131 fCTTMmatrixBack[i][j]=kFALSE;
132 }
133 }
134 }
c06f660b 135
136 fPowerMask[0] = 1;
137 for(Int_t i=1;i <= kNCTTMchannels;i++){
138 fPowerMask[i] = fPowerMask[i-1]*2;
139 }
140
cd82ed2f 141 SetName("TOF");
142 CreateInputs();
143}
144
ee51d470 145//____________________________________________________________________________
cd82ed2f 146
655e379f 147AliTOFTrigger::AliTOFTrigger(const AliTOFTrigger & tr):
8a190ba2 148 AliTriggerDetector(tr),
149 fHighMultTh(tr.fHighMultTh),
150 fppMBTh(tr.fppMBTh),
151 fMultiMuonTh(tr.fMultiMuonTh),
152 fUPTh(tr.fUPTh),
153 fdeltaminpsi(tr.fdeltaminpsi),
154 fdeltamaxpsi(tr.fdeltamaxpsi),
155 fdeltaminro(tr.fdeltaminro),
156 fdeltamaxro(tr.fdeltamaxro),
c06f660b 157 fstripWindow(tr.fstripWindow),
158 fSel1(tr.fSel1),
159 fSel2(tr.fSel2),
160 fSel3(tr.fSel3),
161 fSel4(tr.fSel4),
162 fNCrateOn(tr.fNCrateOn),
163 fNMaxipadOn(tr.fNMaxipadOn),
164 fNMaxipadOnAll(tr.fNMaxipadOnAll),
165 fTOFTrigMask(0)
cd82ed2f 166{
167 //copy ctor
cd82ed2f 168 for (Int_t i=0;i<kNLTM;i++){
c06f660b 169 fLTMarray[i] = tr.fLTMarray[i];
cd82ed2f 170 for (Int_t j=0;j<kNLTMchannels;j++){
171 fLTMmatrix[i][j]=tr.fLTMmatrix[i][j];
172 }
173 if (i<kNCTTM){
174 for (Int_t j=0;j<kNCTTMchannels;j++){
ee51d470 175 fCTTMmatrixFront[i][j]=tr.fCTTMmatrixFront[i][j];
176 fCTTMmatrixBack[i][j]=tr.fCTTMmatrixBack[i][j];
cd82ed2f 177 }
178 }
179 }
c06f660b 180
181 fPowerMask[0] = 1;
182 for(Int_t i=1;i <= kNCTTMchannels;i++){
183 fPowerMask[i] = fPowerMask[i-1]*2;
184 }
185
186 if(tr.fTOFTrigMask){
187 fTOFTrigMask = new AliTOFTriggerMask();
188 fTOFTrigMask->SetTriggerMaskArray(tr.fTOFTrigMask->GetTriggerMaskArray());
189 }
190
cd82ed2f 191 SetName(tr.GetName());
ee51d470 192 //fInputs=&(tr.GetInputs());
c06f660b 193 CreateInputs();
194
cd82ed2f 195}
196
197//----------------------------------------------------------------------
198
199void AliTOFTrigger::CreateInputs()
200{
ee51d470 201 // creating inputs
cd82ed2f 202 // Do not create inputs again!!
ee51d470 203 if( fInputs.GetEntriesFast() > 0 ) return;
204
c06f660b 205 LoadActiveMask();
206
ee51d470 207 fInputs.AddLast(new AliTriggerInput("TOF_Cosmic_MultiMuon_L0","TOF",0));
208 fInputs.AddLast(new AliTriggerInput("0OIN","TOF",0)); // was "TOF_pp_MB_L0"
c06f660b 209 fInputs.AddLast(new AliTriggerInput("0OM2","TOF",0)); // was "TOF_PbPb_MB2_L0"
210 fInputs.AddLast(new AliTriggerInput("0OM3","TOF",0)); // was "TOF_PbPb_MB3_L0"
211 fInputs.AddLast(new AliTriggerInput("0OUP","TOF",0)); // was "TOF_UltraPer_Coll_L0"
ee51d470 212
213 fInputs.AddLast(new AliTriggerInput("0OHM","TOF",0)); // was "TOF_High_Mult_L0"
214 fInputs.AddLast(new AliTriggerInput("TOF_Jet_L1","TOF",0));
215
cd82ed2f 216}
217
218//----------------------------------------------------------------------
ee51d470 219void AliTOFTrigger::Trigger() {
cd82ed2f 220 //triggering method
c06f660b 221 fSel1=0;
222 fSel2=0;
223 fSel3=0;
224 fSel4=0;
c6eeb5c9 225
cd82ed2f 226 CreateLTMMatrix();
227 Int_t nchonFront = 0;
228 Int_t nchonBack = 0;
229 Int_t nchonTot = 0;
c06f660b 230 Int_t nSectOn = 0; // °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
231 Int_t DeSlots = -1;// °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
232 Int_t AntiDeSlots = -1;// °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
cd82ed2f 233 Int_t nchonFrontBack = 0;
234 Int_t nchonFront1 = 0;
235 Int_t nchonBack1 = 0;
236 Int_t nchonFrontBack1 = 0;
237 Int_t mindeltapsi = (Int_t)fdeltaminpsi/10;
238 Int_t maxdeltapsi = (Int_t)fdeltamaxpsi/10;
239 Int_t mindeltaro = (Int_t)fdeltaminro/10;
240 Int_t maxdeltaro = (Int_t)fdeltamaxro/10;
ee51d470 241
cd82ed2f 242 for (Int_t i=0;i<kNCTTM;i++){
243 for (Int_t j=0;j<kNCTTMchannels;j++){
ee51d470 244 if (fCTTMmatrixFront[i][j]) nchonFront++;
cd82ed2f 245 }
246 }
247
248 for (Int_t i=kNCTTM;i<(kNCTTM*2);i++){
249 for (Int_t j=0;j<kNCTTMchannels;j++){
ee51d470 250 if (fCTTMmatrixBack[i-kNCTTM][j]) nchonBack++;
cd82ed2f 251 }
252 }
253
254 nchonTot = nchonFront + nchonBack;
c06f660b 255// fNMaxipadOn = nchonTot;
256 for(Int_t i=0;i<kNCTTM;i++) { if(fLTMarray[i]) nSectOn++; }
cd82ed2f 257
258 //pp Minimum Bias Trigger
259 if (nchonTot >= fppMBTh) {
c6eeb5c9 260 SetInput("0OIN");
c06f660b 261 fSel1=1;
262 //printf("0OIN - MB\n");
263 }
264
265 // PbPb MB
266 if (nchonTot >= 2) {
267 SetInput("0OM2");
268 fSel2=1;
269 }
270 if (nchonTot >= 3) {
271 SetInput("0OM3");
272 fSel3=1;
cd82ed2f 273 }
274
275 //High Multiplicity Trigger
276 if (nchonTot >= fHighMultTh) {
c6eeb5c9 277 SetInput("0OHM");
c06f660b 278 //printf("0OHM - High Mult\n");
cd82ed2f 279 }
280
ee51d470 281
cd82ed2f 282 //MultiMuon Trigger
283 nchonFront = 0;
284 nchonBack = 0;
285 nchonFrontBack = 0;
286
287 Bool_t boolCTTMor = kFALSE;
288
289 for (Int_t i=0;i<(kNCTTM/2);i++){
290 Int_t iopp = i+kNCTTM/2;
291 for (Int_t j=0;j<kNCTTMchannels;j++){
292 if (fCTTMmatrixFront[i][j]){
293 Int_t minj = j-fstripWindow;
294 Int_t maxj = j+fstripWindow;
295 if (minj<0) minj =0;
296 if (maxj>=kNCTTMchannels) maxj = kNCTTMchannels-1;
297 boolCTTMor = kFALSE;
298 for (Int_t k = minj;k<=maxj;k++){
299 boolCTTMor |= fCTTMmatrixFront[iopp][k];
ee51d470 300 }
cd82ed2f 301 if (boolCTTMor) {
302 nchonFront++;
303 }
304 }
ee51d470 305
cd82ed2f 306 if (fCTTMmatrixBack[i][j]){
307 Int_t minj = j-fstripWindow;
308 Int_t maxj = j+fstripWindow;
309 if (minj<0) minj =0;
310 if (maxj>=kNCTTMchannels) maxj =kNCTTMchannels-1;
311 boolCTTMor = kFALSE;
312 for (Int_t k = minj;k<=maxj;k++){
313 boolCTTMor |= fCTTMmatrixBack[iopp][k];
314 }
315 if (boolCTTMor) {
316 nchonBack++;
317 }
318 }
319 }
320 }
321
322 nchonFrontBack = nchonFront+nchonBack;
323
324 nchonFront1 = 0;
325 nchonBack1 = 0;
326 nchonFrontBack1 = 0;
327
328 boolCTTMor = kFALSE;
329 for (Int_t i=0;i<(kNCTTM/2);i++){
330 Int_t i2max = (kNCTTM-1)-i+1;
331 Int_t i2min = (kNCTTM-1)-i-1;
332 if (i2max >=kNCTTM) i2max = kNCTTM-1;
333 if (i2min==i) i2min = kNCTTM-1-i;
334 for (Int_t j=0;j<kNCTTMchannels;j++){
335 Int_t j2min = j-fstripWindow;
336 Int_t j2max = j+fstripWindow;
337 if (j2min<0) j2min =0;
338 if (j2max>=kNCTTMchannels) j2max =kNCTTMchannels-1;
339 if (fCTTMmatrixFront[i][j]){
340 boolCTTMor = kFALSE;
341 for (Int_t i2=i2min;i2<=i2max;i2++){
342 for (Int_t j2 = j2min;j2<=j2max;j2++){
343 boolCTTMor |= fCTTMmatrixFront[i2][j2];
ee51d470 344 }
cd82ed2f 345 if (boolCTTMor) {
346 nchonFront++;
347 }
348 }
349 }
350 if (fCTTMmatrixBack[i][j]){
c06f660b 351 boolCTTMor = kFALSE;
352 for (Int_t i2=i2min;i2<=i2max;i2++){
353 for (Int_t j2 = j2min;j2<=j2max;j2++){
354 boolCTTMor |= fCTTMmatrixBack[i2][j2];
355 }
356 }
357 if (boolCTTMor) {
358 nchonBack++;
cd82ed2f 359 }
cd82ed2f 360 }
361 }
362 }
c06f660b 363
cd82ed2f 364 nchonFrontBack1 = nchonFront1+nchonBack1;
c06f660b 365
cd82ed2f 366 if (nchonFrontBack >= fMultiMuonTh || nchonFrontBack1 >= fMultiMuonTh) {
c06f660b 367 SetInput("TOF_Cosmic_MultiMuon_L0");
cd82ed2f 368 }
c06f660b 369
cd82ed2f 370 //Ultra-Peripheral collision Trigger
c06f660b 371
372 // °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
373 // DeSlots = (k+1)_Array Element - k_Array Element
374 // AntiDeSlots = kNCTTM - DeSlots
375
376 if((!fSel1))// && nchonFront < 4 && nchonBack < 4)
377 {
378 // printf("nHitMaxipad CLASSE: %i \n",fNMaxipadOn);
379 // printf("Total Number per event of Switched-On sectors : %i \n", nSectOn);
380 // printf("mindeltapsi %i \n", mindeltapsi);
381 //printf("maxdeltapsi %i \n", maxdeltapsi);
382 for(Int_t i = 0; i < kNCTTM; i++){
383 if(fLTMarray[i]){
384 // printf(" i-sect On: %i\n",i);
385 for(Int_t j = i+1; j < kNCTTM; j++){
386 if(fLTMarray[j]) {
387 // printf(" j-sect On: %i\n",j);
388 DeSlots = j-i;
389 AntiDeSlots = kNCTTM - DeSlots;
390 //printf("DeSlots = %i \n",DeSlots);
391 //printf("AntiDeSlots = %i \n",AntiDeSlots);
392 if(DeSlots >= mindeltapsi && DeSlots <= maxdeltapsi){
393 fSel4=1;
394 SetInput("0OUP");
395 //printf("trigger On with DeSlot \n");
396 }
397 if(AntiDeSlots >= mindeltapsi && AntiDeSlots <= maxdeltapsi){
398 fSel4=1;
399 SetInput("0OUP");
400 //printf("trigger On with AntiDeSlot \n");
401 }
402
403
404 if(DeSlots >= mindeltaro && DeSlots <= maxdeltaro){
405 fSel4=1;
406 SetInput("0OUP");
407 //printf("trigger On with DeSlot \n");
408 }
409 if(AntiDeSlots >= mindeltaro && AntiDeSlots <= maxdeltaro){
410 fSel4=1;
411 SetInput("0OUP");
412 //printf("trigger On with AntiDeSlot \n");
413 }
414
415 }
416
417 }
cd82ed2f 418 }
cd82ed2f 419 }
c06f660b 420 }
cd82ed2f 421}
ee51d470 422
cd82ed2f 423//-----------------------------------------------------------------------------
ee51d470 424void AliTOFTrigger::CreateLTMMatrix() {
cd82ed2f 425 //creating LTMMatrix
426 //initialization
ee51d470 427 CreateLTMMatrixFromDigits();
428}
429
430//-------------------------------------------------------------------------
431
432void AliTOFTrigger::CreateLTMMatrixFromDigits() {
433 //
434 // Create LTM matrix by TOF digits
435 //
436
437 //initialization
cd82ed2f 438 for (Int_t i=0;i<kNLTM;i++){
c06f660b 439 fLTMarray[i]= kFALSE;
cd82ed2f 440 for (Int_t j=0;j<kNLTMchannels;j++){
441 fLTMmatrix[i][j]=kFALSE;
442 }
443 }
444 AliRunLoader *rl;
33c3c91a 445 rl = AliRunLoader::Instance();
ee51d470 446
cd82ed2f 447 Int_t ncurrevent = rl->GetEventNumber();
448 rl->GetEvent(ncurrevent);
ee51d470 449
cd82ed2f 450 AliLoader * tofLoader = rl->GetLoader("TOFLoader");
ee51d470 451
cd82ed2f 452 tofLoader->LoadDigits("read");
453 TTree *treeD = tofLoader->TreeD();
454 if (treeD == 0x0)
455 {
456 AliFatal("AliTOFTrigger: Can not get TreeD");
457 }
ee51d470 458
cd82ed2f 459 TBranch *branch = treeD->GetBranch("TOF");
ee51d470 460 if (!branch) {
cd82ed2f 461 AliError("can't get the branch with the TOF digits !");
462 return;
463 }
464 TClonesArray *tofDigits =new TClonesArray("AliTOFdigit", 1000);
465 branch->SetAddress(&tofDigits);
466 treeD->GetEvent(0);
467 Int_t ndigits = tofDigits->GetEntriesFast();
468 Int_t detind[5]; //detector indexes: 0 -> sector
c06f660b 469 // 1 -> plate(modulo)
cd82ed2f 470 // 2 -> strip
471 // 3 -> padz
472 // 4 -> padx
ee51d470 473
cd82ed2f 474 for (Int_t i=0;i<ndigits;i++){
475 AliTOFdigit * digit = (AliTOFdigit*)tofDigits->UncheckedAt(i);
476 detind[0] = digit->GetSector();
477 detind[1] = digit->GetPlate();
478 detind[2] = digit->GetStrip();
479 detind[3] = digit->GetPadz();
480 detind[4] = digit->GetPadx();
ee51d470 481
cd82ed2f 482 Int_t indexLTM[2] = {-1,-1};
483 GetLTMIndex(detind,indexLTM);
484
485 fLTMmatrix[indexLTM[0]][indexLTM[1]] = kTRUE;
c06f660b 486 fLTMarray[indexLTM[0]%36] = kTRUE; //dimensione MAX array 36 = kNCTTM
487 }
488 fNCrateOn = 0;
489 for(Int_t j=0; j < kNCTTM; j++) {if(fLTMarray[j]) fNCrateOn++;}
490
cd82ed2f 491
28751b82 492 tofLoader->UnloadDigits();
ee51d470 493 // rl->UnloadgAlice();
494 CreateCTTMMatrix();
495
cd82ed2f 496}
ee51d470 497
cd82ed2f 498//-----------------------------------------------------------------------------
ee51d470 499
500void AliTOFTrigger::CreateLTMMatrixFromRaw(AliRawReader *fRawReader) {
501 //
502 // Create LTM matrix by TOF raw data
503 //
504
505 //initialization
506 for (Int_t i=0;i<kNLTM;i++){
507 for (Int_t j=0;j<kNLTMchannels;j++){
508 fLTMmatrix[i][j]=kFALSE;
509 }
510 }
511
512 if(fRawReader){
513 AliTOFRawStream * tofRawStream = new AliTOFRawStream();
514
515 Int_t inholes = 0;
516
517 //if(!GetLoader()->TreeS()) {MakeTree("S"); MakeBranch("S");}
518
519 Clear();
520 tofRawStream->SetRawReader(fRawReader);
521
522 //ofstream ftxt;
523 //if (fVerbose==2) ftxt.open("TOFsdigitsRead.txt",ios::app);
524
525 TClonesArray staticRawData("AliTOFrawData",10000);
526 staticRawData.Clear();
527 TClonesArray * clonesRawData = &staticRawData;
528
529 Int_t dummy = -1;
530 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
531 Int_t digit[2];
532 //Int_t track = -1;
533 //Int_t last = -1;
534
535 Int_t indexDDL = 0;
536 Int_t iRawData = 0;
537 AliTOFrawData *tofRawDatum = 0;
538 for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
539
540 fRawReader->Reset();
541 tofRawStream->LoadRawData(indexDDL);
542
543 clonesRawData = tofRawStream->GetRawData();
544 if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
545 for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
546
547 tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
548
549 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
550 if (tofRawDatum->GetTOF()==-1) continue;
551
552 SetBit(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
553 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel());
554
555 dummy = detectorIndex[3];
556 detectorIndex[3] = detectorIndex[4];//padz
557 detectorIndex[4] = dummy;//padx
558
559 digit[0] = tofRawDatum->GetTOF();
560 digit[1] = tofRawDatum->GetTOT();
561
562 dummy = detectorIndex[3];
563 detectorIndex[3] = detectorIndex[4];//padx
564 detectorIndex[4] = dummy;//padz
565
566 // Do not reconstruct anything in the holes
567 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
568 if (detectorIndex[1]==2) { // plate with holes
569 inholes++;
570 continue;
571 }
572 }
573
574 tofRawDatum = 0;
575 } // while loop
576
577 clonesRawData->Clear();
578
579 } // DDL Loop
580
581 //if (fVerbose==2) ftxt.close();
582
583 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
584
585 }
586
587}
588
589//-----------------------------------------------------------------------------
42e171ac 590void AliTOFTrigger::GetLTMIndex(const Int_t * const detind, Int_t *indexLTM) {
ee51d470 591 //
592 // getting LTMmatrix indexes for current digit
593 //
594
cd82ed2f 595 if (detind[1]==0 || detind[1]==1 || (detind[1]==2 && detind[2]<=7)) {
596 if (detind[4]<24){
597 indexLTM[0] = detind[0]*2;
598 }
599 else {
600 indexLTM[0] = detind[0]*2+1;
601 }
602 }
603 else {
604 if (detind[4]<24){
605 indexLTM[0] = detind[0]*2+36;
606 }
607 else {
608 indexLTM[0] = (detind[0]*2+1)+36;
609 }
610 }
611
ee51d470 612 if (indexLTM[0]<36) {
cd82ed2f 613 if (detind[1] ==0){
614 indexLTM[1] = detind[2];
615 }
616 else if (detind[1] ==1){
617 indexLTM[1] = detind[2]+19;
618 }
619 else if (detind[1] ==2){
2901911a 620 indexLTM[1] = detind[2]+19*2;
cd82ed2f 621 }
622 else{
623 AliError("Smth Wrong!!!");
624 }
625 }
626 else {
627 if (detind[1] ==2){
628 indexLTM[1] = detind[2]-8;
629 }
630 else if (detind[1] ==3){
631 indexLTM[1] = detind[2]+7;
632 }
633 else if (detind[1] ==4){
634 indexLTM[1] = detind[2]+26;
635 }
636 else{
637 AliError("Smth Wrong!!!");
638 }
639 }
ee51d470 640
641}
642//-------------------------------------------------------------------------
643/*
644// to be checked because of warning problems
645void AliTOFTrigger::PrintMap()
646{
647 //
648 //
649 //
650
651 for(Int_t i = 0; i<kNLTM;i++) {
652 if(i<36) {
653 printf("| %d | %d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |\n",
654 (fCTTMmatrixFront[i][0])?1:0,(fCTTMmatrixFront[i][1])?1:0,(fCTTMmatrixFront[i][2])?1:0, \
655 (fCTTMmatrixFront[i][3])?1:0,(fCTTMmatrixFront[i][4])?1:0,(fCTTMmatrixFront[i][5])?1:0, \
656 (fCTTMmatrixFront[i][6])?1:0,(fCTTMmatrixFront[i][7])?1:0,(fCTTMmatrixFront[i][8])?1:0, \
657 (fCTTMmatrixFront[i][9])?1:0,(fCTTMmatrixFront[i][10])?1:0,(fCTTMmatrixFront[i][11])?1:0, \
658 (fCTTMmatrixFront[i][12])?1:0,(fCTTMmatrixFront[i][13])?1:0,(fCTTMmatrixFront[i][14])?1:0, \
659 (fCTTMmatrixFront[i][15])?1:0,(fCTTMmatrixFront[i][16])?1:0,(fCTTMmatrixFront[i][17])?1:0, \
660 (fCTTMmatrixFront[i][18])?1:0,(fCTTMmatrixFront[i][19])?1:0,(fCTTMmatrixFront[i][20])?1:0, \
661 (fCTTMmatrixFront[i][21])?1:0,(fCTTMmatrixFront[i][22])?1:0,(fCTTMmatrixFront[i][23])?1:0);
662 } else {
663 printf("| %d | %d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |%d |\n",
664 (fCTTMmatrixBack[i][0])?1:0,(fCTTMmatrixBack[i][1])?1:0,(fCTTMmatrixBack[i][2])?1:0, \
665 (fCTTMmatrixBack[i][3])?1:0,(fCTTMmatrixBack[i][4])?1:0,(fCTTMmatrixBack[i][5])?1:0, \
666 (fCTTMmatrixBack[i][6])?1:0,(fCTTMmatrixBack[i][7])?1:0,(fCTTMmatrixBack[i][8])?1:0, \
667 (fCTTMmatrixBack[i][9])?1:0,(fCTTMmatrixBack[i][10])?1:0,(fCTTMmatrixBack[i][11])?1:0, \
668 (fCTTMmatrixBack[i][12])?1:0,(fCTTMmatrixBack[i][13])?1:0,(fCTTMmatrixBack[i][14])?1:0, \
669 (fCTTMmatrixBack[i][15])?1:0,(fCTTMmatrixBack[i][16])?1:0,(fCTTMmatrixBack[i][17])?1:0, \
670 (fCTTMmatrixBack[i][18])?1:0,(fCTTMmatrixBack[i][19])?1:0,(fCTTMmatrixBack[i][20])?1:0, \
671 (fCTTMmatrixBack[i][21])?1:0,(fCTTMmatrixBack[i][22])?1:0,(fCTTMmatrixBack[i][23])?1:0);
672 }
673 }
674
675}
676*/
677//-------------------------------------------------------------------------
678
42e171ac 679void AliTOFTrigger::GetMap(Bool_t **map) const
ee51d470 680{
681 //
42e171ac 682 // Returns CTTM map
ee51d470 683 //
684
685 for(Int_t i = 0; i<kNLTM;i++)
686 for(Int_t j = 0; j<kNCTTMchannels;j++)
c06f660b 687 map[i][j]=(i<36)?fCTTMmatrixFront[i][j]:fCTTMmatrixBack[i][j];
ee51d470 688
689}
690
691//-------------------------------------------------------------------------
42e171ac 692void AliTOFTrigger::GetTRDmap(Bool_t **map) const
ee51d470 693{
694 //
695 // Retriev the bit map sent to the TRD detector
696 //
697
698 for(int i = 0; i<kNLTM;i++)
699 for(int j = 0; j<kNLTMtoTRDchannels;j++)
700 map[i][j]=kFALSE;
701
702 for(int i = 0; i<kNLTM/2;i++)
703 for(int j = 0; j<AliTOFTrigger::kNCTTMchannels;j++){
42e171ac 704 UInt_t uTRDbit=j/3;
705 if(fCTTMmatrixFront[i][j]) map[i][uTRDbit]=kTRUE;
ee51d470 706 }
707 for(int i = kNLTM/2; i<kNLTM;i++)
708 for(int j = 0; j<AliTOFTrigger::kNCTTMchannels;j++){
42e171ac 709 UInt_t uTRDbit=j/3;
c06f660b 710 if(fCTTMmatrixBack[i][j]) map[i][uTRDbit]=kTRUE;
ee51d470 711 }
712}
713
714//-------------------------------------------------------------------------
715void AliTOFTrigger::SetBit(Int_t *detind)
716{
717 //
42e171ac 718 // Sets CTTM map element corresponding to detector element 'detind'
ee51d470 719 //
720
721 Int_t index[2];
722 GetCTTMIndex(detind,index);
723 if(index[0]<36)
724 fCTTMmatrixFront[index[0]][index[1]]=kTRUE;
725 else
c06f660b 726 fCTTMmatrixBack[index[0]][index[1]]=kTRUE;
ee51d470 727
728}
729
730//-------------------------------------------------------------------------
731void AliTOFTrigger::SetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
732 Int_t iTDC, Int_t iCH)
733{
734 //
42e171ac 735 // Sets CTTM map element corresponding to equipment ID
736 // labelled by number nDDL, nTRM, iChain, iTDC, iCH
ee51d470 737 //
738
739 if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1){ // DDL number to LTM number mapping
740 Int_t iLTMindex=-1;
741 Int_t iChannelIndex=-1;
742 switch(nDDL%AliTOFGeometry::NDDL()){
743 case 1:
744 iLTMindex=1;
745 break;
746 case 3:
747 iLTMindex=36;
748 break;
749 default:
750 AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
751 break;
752 }
753 iLTMindex+=2*(Int_t)(nDDL/AliTOFGeometry::NDDL());
754 if(iChain==0 && nDDL<36)
755 iLTMindex--;
756 if(iChain==0 && nDDL>=36)
757 iLTMindex++;
758 iChannelIndex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
759 Int_t index[2]={iLTMindex,iChannelIndex};
760 if (index[0]<36)
761 fCTTMmatrixFront[index[0]][index[1]]=kTRUE;
762 else
c06f660b 763 fCTTMmatrixBack[index[0]][index[1]]=kTRUE;
ee51d470 764 }
765 else
766 AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
767
768}
769//-------------------------------------------------------------------------
770
771void AliTOFTrigger::ResetBit(Int_t *detind)
772{
773 //
42e171ac 774 // Sets CTTM map element corresponding to detector element 'detind'
ee51d470 775 //
776
777 Int_t index[2];
778 GetCTTMIndex(detind,index);
779 if(index[0]<36)
780 fCTTMmatrixFront[index[0]][index[1]]=kFALSE;
781 else
c06f660b 782 fCTTMmatrixBack[index[0]][index[1]]=kFALSE;
ee51d470 783
784}
785
786//-------------------------------------------------------------------------
787void AliTOFTrigger::ResetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
788 Int_t iTDC, Int_t iCH)
789{
790 //
42e171ac 791 // Sets CTTM map element corresponding to equipment ID
792 // labelled by number nDDL, nTRM, iChain, iTDC, iCH
ee51d470 793 //
794
795 if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1){ // DDL number to LTM number mapping
796 Int_t iLTMindex=-1;
797 Int_t iChannelIndex=-1;
798 switch(nDDL%AliTOFGeometry::NDDL()){
799 case 1:
800 iLTMindex=1;
801 break;
802 case 3:
803 iLTMindex=36;
804 break;
805 default:
806 AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
807 break;
808 }
809 iLTMindex+=2*(Int_t)(nDDL/AliTOFGeometry::NDDL());
810 if(iChain==0 && nDDL<36)
811 iLTMindex--;
812 if(iChain==0 && nDDL>=36)
813 iLTMindex++;
814 iChannelIndex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
815 Int_t index[2]={iLTMindex,iChannelIndex};
816 if (index[0]<36)
817 fCTTMmatrixFront[index[0]][index[1]]=kFALSE;
818 else
c06f660b 819 fCTTMmatrixBack[index[0]][index[1]]=kFALSE;
ee51d470 820 }
821 else
822 AliError("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ");
823
824}
825//-------------------------------------------------------------------------
826
827Bool_t AliTOFTrigger::GetBit(Int_t *detind)
828{
829 //
42e171ac 830 // Returns CTTM map element corresponding to detector element 'detind'
ee51d470 831 //
832
833 Int_t index[2];
834 GetCTTMIndex(detind,index);
c06f660b 835 return (index[0]<36)?fCTTMmatrixFront[index[0]][index[1]]:fCTTMmatrixBack[index[0]][index[1]];
ee51d470 836
837}
838
839//-------------------------------------------------------------------------
840Bool_t AliTOFTrigger::GetBit(Int_t nDDL, Int_t nTRM, Int_t iChain,
841 Int_t iTDC, Int_t iCH)
842{
843 //
42e171ac 844 // Returns CTTM map element corresponding to equipment ID
845 // labelled by number nDDL, nTRM, iChain, iTDC, iCH
ee51d470 846 //
847
848 if ( !(nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) ) {
849 AliWarning("Call this function only if(nTRM==3 && iTDC>12 && iTDC<14) ");
850 return kFALSE;
851 }
852 //if (nTRM==3 && iTDC>12 && iTDC<14 && nDDL%2==1) { // DDL number to LTM number mapping
853
854 UInt_t iLTMindex=0;
855 UInt_t iChannelindex=0;
856 switch(nDDL%AliTOFGeometry::NDDL()) {
857 case 1:
858 iLTMindex=1;
859 break;
860 case 3:
861 iLTMindex=36;
862 break;
863 default:
864 AliError("something wrong");
865 break;
866 }
867 iLTMindex+=2*(Int_t)(nDDL/AliTOFGeometry::NDDL());
868
869 if (iChain==1) return kFALSE; // AdC
870
871 if (nDDL<36)
872 iLTMindex--;
873 if (nDDL>=36)
874 iLTMindex++;
875 iChannelindex=iCH+iTDC*AliTOFGeometry::NCh()-12*AliTOFGeometry::NCh();
876 Int_t index[2]={iLTMindex,iChannelindex};
c06f660b 877 return (index[0]<36)?fCTTMmatrixFront[index[0]][index[1]]:fCTTMmatrixBack[index[0]][index[1]];
ee51d470 878
879}
880
881//-------------------------------------------------------------------------
882
883void AliTOFTrigger::CreateCTTMMatrix() {
884 //
885 // Create CTTM bit map
886 //
c06f660b 887 fNMaxipadOnAll=0;
888 fNMaxipadOn=0;
889
890 for(Int_t i = 0; i<kNLTM;i++){
891 UInt_t currentMask = fPowerMask[kNCTTMchannels]-1;
892 if(fTOFTrigMask) currentMask=fTOFTrigMask->GetTriggerMask(i);
893 if(i<kNCTTM){
894 for(Int_t j = 0; j<kNCTTMchannels;j++){
895 fCTTMmatrixFront[i][j]=fLTMmatrix[i][2*j]||fLTMmatrix[i][2*j+1];
896 if(fCTTMmatrixFront[i][j]) fNMaxipadOnAll++;
897 if(!(currentMask & fPowerMask[j])) fCTTMmatrixFront[i][j]=0;
898 if(fCTTMmatrixFront[i][j]) fNMaxipadOn++;
899 }
900 }
901 else{
902 for(Int_t j = 0; j<kNCTTMchannels;j++){
903 fCTTMmatrixBack[i-kNCTTM][j]=fLTMmatrix[i][2*j]||fLTMmatrix[i][2*j+1];;
904 if(fCTTMmatrixBack[i-kNCTTM][j]) fNMaxipadOnAll++;
905 if(!(currentMask & fPowerMask[j])) fCTTMmatrixBack[i-kNCTTM][j]=0;
906 if(fCTTMmatrixBack[i-kNCTTM][j]) fNMaxipadOn++;
907 }
908 }
ee51d470 909 }
ee51d470 910}
911//-----------------------------------------------------------------------------
912
913void AliTOFTrigger::GetCTTMIndex(Int_t *detind, Int_t *indexCTTM) {
914 //
42e171ac 915 // Returns CTTM index corresponding to the detector element detind
ee51d470 916 //
917
918 GetLTMIndex(detind,indexCTTM);
919 indexCTTM[1]/=2;
920
cd82ed2f 921}
c06f660b 922//-----------------------------------------------------------------------------
923void AliTOFTrigger::LoadActiveMask(){
924//
925// Load OCDB current mask
926//
927 UInt_t maskArray[kNLTM];
928 if(fTOFTrigMask == NULL) fTOFTrigMask = new AliTOFTriggerMask();
929 for (Int_t k = 0; k < kNLTM ; k++) maskArray[k] = fPowerMask[kNCTTMchannels]-1;
afde0bb4 930 //for (Int_t k = 0; k < kNLTM ; k+=2) maskArray[k] = 0;
c06f660b 931
932 fTOFTrigMask->SetTriggerMaskArray(maskArray);
933}
934
935
936//-----------------------------------------------------------------------------
937AliTOFTrigger::~AliTOFTrigger()
938{
939 // dtor
940
941 if (fTOFTrigMask) delete fTOFTrigMask;
942
943}
944
945//-----------------------------------------------------------------------------
946AliTOFTrigger& AliTOFTrigger::operator=(const AliTOFTrigger &/*source*/)
947{
948 // ass. op.
949 return *this;
950
951}