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