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