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