AliTPCTransform.h - removing warning visible in
[u/mrichter/AliRoot.git] / TOF / AliTOF.cxx
CommitLineData
4c039060 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 **************************************************************************/
88cb7938 15/* $Id$ */
68861244 16
fe4da5cc 17///////////////////////////////////////////////////////////////////////////////
18// //
68861244 19// Time Of Flight //
fe4da5cc 20// This class contains the basic functions for the Time Of Flight //
21// detector. Functions specific to one particular geometry are //
22// contained in the derived classes //
d3c7bfac 23// //
24// VERSIONE WITH 5 SYMMETRIC MODULES ALONG Z AXIS //
25// ============================================================ //
26// //
27// VERSION WITH HOLES FOR PHOS AND TRD IN SPACEFRAME WITH HOLES //
28// //
29// Volume sensibile : FPAD //
30// //
31// //
32// //
33// //
34///////////////////////////////////////////////////////////////////////////////
937fe4a4 35// Begin_Html
fe4da5cc 36/*
1439f98e 37<img src="picts/AliTOFClass.gif">
fe4da5cc 38*/
39//End_Html
d3c7bfac 40
7ca4655f 41#include <TClonesArray.h>
42#include <TFile.h>
43#include <TFolder.h>
44#include <TROOT.h>
45#include <TTask.h>
46#include <TTree.h>
47#include <TVirtualMC.h>
515faf5d 48#include <TStopwatch.h>
fe4da5cc 49
88cb7938 50#include "AliConst.h"
51#include "AliLoader.h"
0e46b9ae 52#include "AliLog.h"
53#include "AliMC.h"
88cb7938 54#include "AliRun.h"
f472295e 55#include "AliDAQ.h"
56#include "AliRawReader.h"
0e46b9ae 57
ed70db17 58//#include "AliTOFDDLRawData.h"
0e46b9ae 59#include "AliTOFDigitizer.h"
88cb7938 60#include "AliTOFdigit.h"
88cb7938 61#include "AliTOFhitT0.h"
0e46b9ae 62#include "AliTOFhit.h"
63#include "AliTOFGeometry.h"
64#include "AliTOFSDigitizer.h"
65#include "AliTOFSDigit.h"
66#include "AliTOF.h"
f472295e 67#include "AliTOFrawData.h"
68#include "AliTOFRawStream.h"
0e46b9ae 69
70class AliTOFcluster;
71
72extern TFile *gFile;
73extern TROOT *gROOT;
74extern TVirtualMC *gMC;
75
76extern AliRun *gAlice;
77
fe4da5cc 78ClassImp(AliTOF)
6e4ef37b 79
fe4da5cc 80//_____________________________________________________________________________
655e379f 81AliTOF::AliTOF():
82 fFGeom(0x0),
83 fDTask(0x0),
84 fReTask(0x0),
85 fSDigits(0x0),
86 fNSDigits(0),
87 fReconParticles(0x0),
88 fIdSens(-1),
89 fTZero(kFALSE),
4f283355 90 fTOFHoles(kTRUE),
ed70db17 91 fTOFGeometry(0x0),
92 fTOFRawWriter(AliTOFDDLRawData())
fe4da5cc 93{
94 //
95 // Default constructor
96 //
0e9dd0cf 97
98 //by default all sectors switched on
99 for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
100
655e379f 101 fDigits = 0;
fe4da5cc 102 fIshunt = 0;
655e379f 103 fName = "TOF";
6e4ef37b 104
fe4da5cc 105}
106
107//_____________________________________________________________________________
792995c1 108AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
655e379f 109 :
110 AliDetector(name,title),
111 fFGeom(0x0),
112 fDTask(0x0),
113 fReTask(0x0),
114 fSDigits(0x0),
115 fNSDigits(0),
116 fReconParticles(0x0),
117 fIdSens(-1),
118 fTZero(kFALSE),
4f283355 119 fTOFHoles(kTRUE),
ed70db17 120 fTOFGeometry(0x0),
121 fTOFRawWriter(AliTOFDDLRawData())
fe4da5cc 122{
123 //
124 // AliTOF standard constructor
125 //
2cef3cb2 126 // Here are fixed some important parameters
127 //
128
68861244 129 // Initialization of hits, sdigits and digits array
d599d913 130 // added option for time zero analysis
655e379f 131 //skowron
d3c7bfac 132 fTOFGeometry = new AliTOFGeometry();
88cb7938 133
0e9dd0cf 134 //by default all sectors switched on
135 for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
136
d599d913 137 if (strstr(option,"tzero")){
138 fHits = new TClonesArray("AliTOFhitT0", 1000);
88cb7938 139 fTZero = kTRUE;
655e379f 140 // AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
d599d913 141 }else{
142 fHits = new TClonesArray("AliTOFhit", 1000);
88cb7938 143 fTZero = kFALSE;
d599d913 144 }
c630aafd 145 if (gAlice==0) {
d076c8d5 146 AliFatal("gAlice==0 !");
c630aafd 147 }
0e46b9ae 148
149 AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
150
151 if (mcApplication->GetHitLists())
152 mcApplication->AddHitList(fHits);
d076c8d5 153 else AliError("gAlice->GetHitLists()==0");
c630aafd 154
2cef3cb2 155 fIshunt = 0;
7e6dce66 156 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
157 fDigits = new TClonesArray("AliTOFdigit", 1000);
00711221 158
2cef3cb2 159 //
160 // Digitization parameters
fe4da5cc 161 //
2cef3cb2 162 // (Transfer Functions to be inserted here)
fe4da5cc 163 //
e939a978 164 //PH SetMarkerColor(7);
165 //PH SetMarkerStyle(2);
166 //PH SetMarkerSize(0.4);
2cef3cb2 167
2cef3cb2 168// Strip Parameters
7e6dce66 169 //fGapA = 4.; //cm Gap beetween tilted strip in A-type plate
170 //fGapB = 6.; //cm Gap beetween tilted strip in B-type plate
171
172 // Physical performances
173 //fTimeRes = 100.;//ps
174 //fChrgRes = 100.;//pC
175
68861244 176}
177
06e24a91 178//____________________________________________________________________________
d0eb8f39 179void AliTOF::SetTOFSectors(Int_t *sectors)
180{
181 // Setter for partial/full TOF configuration
182
06e24a91 183 for(Int_t isec=0;isec<18;isec++){
184 fTOFSectors[isec]=sectors[isec];
185 }
186}
187//____________________________________________________________________________
d0eb8f39 188void AliTOF::GetTOFSectors(Int_t *sectors) const
189{
190 // Getter for partial/full TOF configuration
06e24a91 191
192 for(Int_t isec=0;isec<18;isec++){
193 sectors[isec]=fTOFSectors[isec];
194 }
195}
7aeeaf38 196
197//_____________________________________________________________________________
68861244 198void AliTOF::CreateTOFFolders()
199{
200 // create the ALICE TFolder
201 // create the ALICE TTasks
202 // create the ALICE main TFolder
203 // to be done by AliRun
204
205 TFolder * alice = new TFolder();
206 alice->SetNameTitle("FPAlice", "Alice Folder") ;
207 gROOT->GetListOfBrowsables()->Add(alice) ;
208
209 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
210 // make it the owner of the objects that it contains
211 aliceF->SetOwner() ;
212 // geometry folder
213 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
214 TFolder * aliceT = alice->AddFolder("tasks", "Alice tasks Folder") ;
215 // make it the owner of the objects that it contains
216 aliceT->SetOwner() ;
217
218 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
219 aliceT->Add(aliceDi);
220
221 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
222 aliceT->Add(aliceRe);
223
224 char * tempo = new char[80] ;
225
226 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
227 sprintf(tempo, "%sDigitizers container",GetName() ) ;
228 fDTask = new TTask(GetName(), tempo);
229 aliceDi->Add(fDTask) ;
230
231 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
232 sprintf(tempo, "%sReconstructioner container",GetName() ) ;
233 fReTask = new TTask(GetName(), tempo);
234 aliceRe->Add(fReTask) ;
235
3ff0c331 236 delete [] tempo ;
68861244 237
238 // creates the TOF geometry folder
239 geomF->AddFolder("TOF", "Geometry for TOF") ;
240}
241
242//_____________________________________________________________________________
243AliTOF::~AliTOF()
244{
517b7f8f 245 // dtor:
246 // it remove also the alice folder
68861244 247 // and task that TOF creates instead of AliRun
5839f074 248 /* PH Temporarily commented because of problems
68861244 249 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
250 delete alice;
251 alice = 0;
5839f074 252 */
517b7f8f 253 if (fHits)
254 {
255 fHits->Delete ();
256 delete fHits;
257 fHits = 0;
258 }
259 if (fDigits)
260 {
261 fDigits->Delete ();
262 delete fDigits;
263 fDigits = 0;
264 }
265 if (fSDigits)
266 {
88cb7938 267 fSDigits->Delete();
517b7f8f 268 delete fSDigits;
269 fSDigits = 0;
270 }
571dda3d 271
517b7f8f 272 if (fReconParticles)
273 {
274 fReconParticles->Delete ();
275 delete fReconParticles;
276 fReconParticles = 0;
277 }
278
fe4da5cc 279}
280
281//_____________________________________________________________________________
2cef3cb2 282void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
fe4da5cc 283{
284 //
285 // Add a TOF hit
68861244 286 // new with placement used
fe4da5cc 287 //
288 TClonesArray &lhits = *fHits;
2cef3cb2 289 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
fe4da5cc 290}
d599d913 291
292//_____________________________________________________________________________
293void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
294{
295 //
296 // Add a TOF hit
297 // new with placement used
298 //
299 TClonesArray &lhits = *fHits;
300 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
301}
302
fe4da5cc 303//_____________________________________________________________________________
bf33f8f0 304void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Int_t *digits)
fe4da5cc 305{
306 //
2cef3cb2 307 // Add a TOF digit
68861244 308 // new with placement used
2cef3cb2 309 //
310 TClonesArray &ldigits = *fDigits;
311 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
fe4da5cc 312}
313
d3c7bfac 314//_____________________________________________________________________________
bf33f8f0 315void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Int_t *digits)
517b7f8f 316{
317
318//
319// Add a TOF sdigit
320//
321
322 TClonesArray &lSDigits = *fSDigits;
5919c40c 323 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
517b7f8f 324}
325
326//_____________________________________________________________________________
327void AliTOF::SetTreeAddress ()
328{
329 // Set branch address for the Hits and Digits Tree.
88cb7938 330
331 if (fLoader->TreeH())
332 {
333 if (fHits == 0x0)
334 {
335 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
336 else fHits = new TClonesArray("AliTOFhit", 1000);
337 }
338 }
517b7f8f 339 AliDetector::SetTreeAddress ();
340
341 TBranch *branch;
517b7f8f 342
88cb7938 343 if (fLoader->TreeS () )
517b7f8f 344 {
88cb7938 345 branch = fLoader->TreeS ()->GetBranch ("TOF");
346 if (branch) {
347 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
348 branch->SetAddress (&fSDigits);
349 }
517b7f8f 350 }
351
571dda3d 352 if (fLoader->TreeR() )
353 {
354 branch = fLoader->TreeR()->GetBranch("TOF");
355 if (branch)
356 {
357 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
358 branch->SetAddress(&fReconParticles);
359 }
360 }
361
362 /*
88cb7938 363 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
517b7f8f 364 {
88cb7938 365 branch = fLoader->TreeR()->GetBranch("TOF");
366 if (branch)
367 {
368 branch->SetAddress(&fReconParticles) ;
369 }
571dda3d 370 }
371 */
517b7f8f 372}
2cef3cb2 373
fe4da5cc 374//_____________________________________________________________________________
375void AliTOF::CreateGeometry()
376{
377 //
3fe3a833 378 // Common geometry code
fe4da5cc 379 //
380 //Begin_Html
381 /*
1439f98e 382 <img src="picts/AliTOFv23.gif">
fe4da5cc 383 */
384 //End_Html
385 //
937fe4a4 386
d3c7bfac 387 Float_t xTof, yTof;
388
dfef1a15 389 if (IsVersion()==8) {
390
391 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
392 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
393 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
394
395 // TOF module internal definitions
396 TOFpc(xTof, yTof, zTof);
397
398 } else if (IsVersion()==7) {
d3c7bfac 399
1ac1b685 400 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
d3c7bfac 401 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
402 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
403
404 // TOF module internal definitions
405 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
3fe3a833 406
d3c7bfac 407 } else {
408
409 Float_t wall = 4.;//cm // frame inbetween TOF modules
410
411 // Sizes of TOF module with its support etc..
412 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
413 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
414
415 // TOF module internal definitions
416 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
417 }
3fe3a833 418
fe4da5cc 419}
420
421//_____________________________________________________________________________
ba380e33 422void AliTOF::DrawModule() const
fe4da5cc 423{
424 //
425 // Draw a shaded view of the common part of the TOF geometry
fe4da5cc 426 //
427
d076c8d5 428 AliInfo(" Drawing of AliTOF");
fe4da5cc 429 // Set everything unseen
cfce8870 430 gMC->Gsatt("*", "seen", -1);
fe4da5cc 431 //
432 // Set ALIC mother transparent
cfce8870 433 gMC->Gsatt("ALIC","SEEN",0);
fe4da5cc 434 //
435 // Set the volumes visible
2cef3cb2 436 gMC->Gsatt("FTOA","SEEN",1);
437 gMC->Gsatt("FTOB","SEEN",1);
438 gMC->Gsatt("FTOC","SEEN",1);
439 gMC->Gsatt("FLTA","SEEN",1);
440 gMC->Gsatt("FLTB","SEEN",1);
441 gMC->Gsatt("FLTC","SEEN",1);
442 gMC->Gsatt("FSTR","SEEN",1);
cfce8870 443 //
444 gMC->Gdopt("hide", "on");
445 gMC->Gdopt("shad", "on");
446 gMC->Gsatt("*", "fill", 7);
447 gMC->SetClipBox(".");
448 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
449 gMC->DefaultRange();
450 gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
451 gMC->Gdhead(1111, "Time Of Flight");
452 gMC->Gdman(18, 4, "MAN");
453 gMC->Gdopt("hide","off");
fe4da5cc 454}
455
517b7f8f 456//___________________________________________
457void AliTOF::ResetHits ()
458{
459 // Reset number of clusters and the cluster array for this detector
460 AliDetector::ResetHits ();
461}
462
463//____________________________________________
464void AliTOF::ResetDigits ()
465{
466 //
467 // Reset number of digits and the digits array for this detector
468 AliDetector::ResetDigits ();
469 //
470}
d61f73d9 471//____________________________________________
472void AliTOF::ResetSDigits ()
473{
474 //
475 // Reset number of sdigits and the sdigits array for this detector
476 fNSDigits = 0;
e615b5b5 477 //fSDigits = 0x0;
d61f73d9 478 //
479}
fe4da5cc 480//_____________________________________________________________________________
481void AliTOF::Init()
482{
483 //
484 // Initialise TOF detector after it has been built
485 //
fe4da5cc 486 // Set id of TOF sensitive volume
937fe4a4 487 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
d3c7bfac 488
489 /*
d076c8d5 490 // Save the geometry
491 TDirectory* saveDir = gDirectory;
33c3c91a 492 AliRunLoader::Instance()->CdGAFile();
d076c8d5 493 fTOFGeometry->Write("TOFGeometry");
494 saveDir->cd();
d3c7bfac 495 */
fe4da5cc 496}
497
2cef3cb2 498//____________________________________________________________________________
88cb7938 499void AliTOF::MakeBranch(Option_t* option)
2cef3cb2 500{
b94fa26c 501 //
502 // Initializes the Branches of the TOF inside the
503 // trees written for each event.
517b7f8f 504 // AliDetector::MakeBranch initializes just the
68861244 505 // Branch inside TreeH. Here we add the branches in
517b7f8f 506 // TreeD, TreeS and TreeR.
b94fa26c 507 //
88cb7938 508 const char *oH = strstr(option,"H");
509 if (fLoader->TreeH() && oH)
510 {
511 if (fHits == 0x0)
512 {
513 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
514 else fHits = new TClonesArray("AliTOFhit", 1000);
515 }
516 }
517
518 AliDetector::MakeBranch(option);
2cef3cb2 519
520 Int_t buffersize = 4000;
521 Char_t branchname[10];
522 sprintf(branchname,"%s",GetName());
2ab0c725 523
68861244 524 const char *oD = strstr(option,"D");
525 const char *oS = strstr(option,"S");
517b7f8f 526 const char *oR = strstr(option,"R");
68861244 527
88cb7938 528 if (fLoader->TreeD() && oD){
529 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
530 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
2cef3cb2 531 }
68861244 532
88cb7938 533 if (fLoader->TreeS() && oS){
534 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
535 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
68861244 536 }
537
571dda3d 538 if (fLoader->TreeR() && oR){
539 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
540 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
541 }
542
543 /*
88cb7938 544 if (fReconParticles && fLoader->TreeR() && oR){
545 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
517b7f8f 546 }
571dda3d 547 */
68861244 548}
549
550//____________________________________________________________________________
551void AliTOF::Makehits(Bool_t hits)
552{
553// default argument used, see AliTOF.h
554// Enable/Disable the writing of the TOF-hits branch
555// on TreeH
d3c7bfac 556// by default : enabled for TOFv1, v2, v3, v4, v5
68861244 557// disabled for TOFv0
558//
559 if (hits && (IsVersion()!=0))
560 fIdSens = gMC->VolId("FPAD");
561 else
d076c8d5 562 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
2cef3cb2 563}
564
565//____________________________________________________________________________
566void AliTOF::FinishEvent()
567{
68861244 568// do nothing
2cef3cb2 569}
570
d3c7bfac 571//____________________________________________________________________________
517b7f8f 572void AliTOF::Hits2SDigits()
573{
574//
575// Use the TOF SDigitizer to make TOF SDigits
576//
d61f73d9 577
0e46b9ae 578// AliInfo("Start...");
68861244 579
be385a87 580 AliRunLoader * rl = fLoader->GetRunLoader();
f472295e 581 AliInfo("Initialized runLoader");
be385a87 582 AliTOFSDigitizer sd((rl->GetFileName()).Data());
f472295e 583 AliInfo("Initialized TOF sdigitizer");
584 //ToAliDebug(1, sd.Print(""));
585 AliInfo("ToAliDebug");
68861244 586
f472295e 587 sd.Exec("all") ;
588
589 AliInfo("I am sorting from AliTOF class");
d61f73d9 590
591}
592
d3c7bfac 593//____________________________________________________________________________
d61f73d9 594void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
595{
596//
597// Use the TOF SDigitizer to make TOF SDigits
598//
599
600 if ((evNumber2-evNumber1)==1)
96f8ea5a 601 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
602 if ((evNumber2-evNumber1)>1)
603 AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
d61f73d9 604
be385a87 605 AliRunLoader * rl = fLoader->GetRunLoader();
606 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
d076c8d5 607 ToAliDebug(1, sd.Print(""));
68861244 608
be385a87 609 sd.Exec("") ;
d61f73d9 610
2cef3cb2 611}
d61f73d9 612
2cef3cb2 613//___________________________________________________________________________
c92eb8ad 614AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 615{
f472295e 616 AliInfo("I am in the AliTOF::CreateDigitizer)");
85a5290f 617 return new AliTOFDigitizer(manager);
618}
619
620//___________________________________________________________________________
bf33f8f0 621Bool_t AliTOF::CheckOverlap(Int_t* vol, Int_t* digit,Int_t Track)
b94fa26c 622{
2cef3cb2 623//
624// Checks if 2 or more hits belong to the same pad.
625// In this case the data assigned to the digit object
626// are the ones of the first hit in order of Time.
517b7f8f 627// 2 hits from the same track on the same pad are collected.
628// Called only by Hits2SDigits.
629// This procedure has to be optimized in the next TOF release.
2cef3cb2 630//
b94fa26c 631
d3c7bfac 632 Bool_t overlap = kFALSE;
633 Int_t vol2[5];
634
635 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
636 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
637 currentDigit->GetLocation(vol2);
638 Bool_t idem= kTRUE;
639 // check on digit volume
640 for (Int_t i=0;i<=4;i++){
641 if (!idem) break;
642 if (vol[i]!=vol2[i]) idem=kFALSE;}
643
644 if (idem){ // same pad fired
bf33f8f0 645 Int_t tdc2 = digit[0];
646 Int_t tdc1 = currentDigit->GetTdc();
d3c7bfac 647
648 // we separate two digits on the same pad if
649 // they are separated in time by at least 25 ns
650 // remember that tdc time is given in ps
651
652 if (TMath::Abs(tdc1-tdc2)<25000){
653 // in case of overlap we take the earliest
654 if (tdc1>tdc2){
655 currentDigit->SetTdc(tdc2);
656 currentDigit->SetAdc(digit[1]);
657 }
658 else {
659 currentDigit->SetTdc(tdc1);
660 currentDigit->SetAdc(digit[1]);
661 }
662 currentDigit->AddTrack(Track); // add track number in the track array
663 overlap = kTRUE;
664 return overlap;
665 } else
bf33f8f0 666 overlap= kFALSE;
517b7f8f 667
d3c7bfac 668 } // close if (idem) -> two digits on the same TOF pad
517b7f8f 669
d3c7bfac 670 } // end loop on existing sdigits
517b7f8f 671
d3c7bfac 672 return overlap;
2cef3cb2 673}
2cef3cb2 674//____________________________________________________________________________
7e6dce66 675void AliTOF::Digits2Raw()
b94fa26c 676{
2cef3cb2 677//
7e6dce66 678// Starting from the TOF digits, writes the Raw Data objects
2cef3cb2 679//
680
515faf5d 681 TStopwatch stopwatch;
682 stopwatch.Start();
683
7e6dce66 684 fLoader->LoadDigits();
2cef3cb2 685
7e6dce66 686 TTree* digits = fLoader->TreeD();
687 if (!digits) {
d076c8d5 688 AliError("no digits tree");
7e6dce66 689 return;
690 }
2cef3cb2 691
ed70db17 692 //AliTOFDDLRawData rawWriter;
693 fTOFRawWriter.Clear();
694 fTOFRawWriter.SetVerbose(0);
695 if (fTOFRawWriter.GetPackedAcquisitionMode()) {
696 if(fTOFRawWriter.GetMatchingWindow()>8192)
dfef1a15 697 AliWarning(Form("You are running in packing mode and the matching window is %.2f ns, i.e. greater than 199.8848 ns",
ed70db17 698 fTOFRawWriter.GetMatchingWindow()*AliTOFGeometry::TdcBinWidth()*1.e-03));
515faf5d 699 }
2cef3cb2 700
ba795372 701 AliDebug(1,"Formatting raw data for TOF");
7e6dce66 702 digits->GetEvent(0);
ed70db17 703 fTOFRawWriter.RawDataTOF(digits->GetBranch("TOF"));
2cef3cb2 704
7e6dce66 705 fLoader->UnloadDigits();
706
515faf5d 707 AliDebug(1, Form("Execution time to write TOF raw data : R:%.2fs C:%.2fs",
708 stopwatch.RealTime(),stopwatch.CpuTime()));
709
7e6dce66 710}
d3c7bfac 711
712//____________________________________________________________________________
55991c8b 713void AliTOF::RecreateSDigitsArray() {
714//
715// delete TClonesArray fSDigits and create it again
716// needed for backward compatability with PPR test production
717//
858b6b16 718 fSDigits->Clear();
55991c8b 719}
d3c7bfac 720//____________________________________________________________________________
55991c8b 721void AliTOF::CreateSDigitsArray() {
722//
723// create TClonesArray fSDigits
724// needed for backward compatability with PPR test production
725//
726 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
727}
f472295e 728//____________________________________________________________________________
729Bool_t AliTOF::Raw2SDigits(AliRawReader* rawReader)
730{
731 //
732 // Converts raw data to sdigits for TOF
733 //
734
735 TStopwatch stopwatch;
736 stopwatch.Start();
737
738 if(!GetLoader()->TreeS()) {MakeTree("S"); MakeBranch("S");}
739 //TClonesArray &aSDigits = *fSDigits;
740
741 AliTOFRawStream tofRawStream = AliTOFRawStream();
742 tofRawStream.Raw2SDigits(rawReader, fSDigits);
743
744 /*
745 //ofstream ftxt;
746 //if (fVerbose==2) ftxt.open("TOFsdigitsRead.txt",ios::app);
747 Int_t inholes = 0;
748
749 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
750
751 TClonesArray staticRawData("AliTOFrawData",10000);
752 staticRawData.Clear();
753 TClonesArray * clonesRawData = &staticRawData;
754
755 Int_t dummy = -1;
756 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
757 Int_t digit[2];
758 Int_t track = -1;
759 Int_t last = -1;
760
761 Int_t indexDDL = 0;
762 Int_t iRawData = 0;
763 for (indexDDL=0; indexDDL<kDDL; indexDDL++) {
764
765 rawReader->Reset();
766 //if (fDecoderVersion) {
767 //AliInfo("Using New Decoder \n");
768 //fTOFRawStream.LoadRawDataBuffers(indexDDL, 0);
769 //}
770 //else
771 fTOFRawStream.LoadRawData(indexDDL);
772
773 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
774 if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
775 for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
776
777 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
778
779 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
780 if (tofRawDatum->GetTOF()==-1) continue;
781
782 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
783 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
784
785 dummy = detectorIndex[3];
786 detectorIndex[3] = detectorIndex[4];//padz
787 detectorIndex[4] = dummy;//padx
788
789 digit[0] = tofRawDatum->GetTOF();
790 digit[1] = tofRawDatum->GetTOT();
791
792 dummy = detectorIndex[3];
793 detectorIndex[3] = detectorIndex[4];//padx
794 detectorIndex[4] = dummy;//padz
795
796 // Do not reconstruct anything in the holes
797 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
798 if (detectorIndex[1]==2) { // plate with holes
799 inholes++;
800 continue;
801 }
802 }
803
804 last = fSDigits->GetEntriesFast();
805 new (aSDigits[last]) AliTOFSDigit(track, detectorIndex, digit);
806 //
807 if (fVerbose==2) {
808 if (indexDDL<10) ftxt << " " << indexDDL;
809 else ftxt << " " << indexDDL;
810 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
811 else ftxt << " " << tofRawDatum->GetTRM();
812 ftxt << " " << tofRawDatum->GetTRMchain();
813 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
814 else ftxt << " " << tofRawDatum->GetTDC();
815 ftxt << " " << tofRawDatum->GetTDCchannel();
816
817 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
818 else ftxt << " -> " << detectorIndex[0];
819 ftxt << " " << detectorIndex[1];
820 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
821 else ftxt << " " << detectorIndex[2];
822 ftxt << " " << detectorIndex[4];
823 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[3];
824 else ftxt << " " << detectorIndex[3];
825
826 if (digit[1]<10)ftxt << " " << digit[1];
827 else if (digit[1]>=10 && digit[1]<100) ftxt << " " << digit[1];
828 else ftxt << " " << digit[1];
829 if (digit[0]<10) ftxt << " " << digit[0] << endl;
830 else if (digit[0]>=10 && digit[0]<100) ftxt << " " << digit[0] << endl;
831 else if (digit[0]>=100 && digit[0]<1000) ftxt << " " << digit[0] << endl;
832 else ftxt << " " << digit[3] << endl;
833 }
834 //
835 AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d, %d)",
836 last,
837 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[4], detectorIndex[3],
838 digit[0], digit[1], digit[3]));
839
840 } // while loop
841
842 clonesRawData->Clear();
843
844 } // DDL Loop
845
846 //if (fVerbose==2) ftxt.close();
847
848 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
849
850 */
851 GetLoader()->TreeS()->Fill(); GetLoader()->WriteSDigits("OVERWRITE");//write out sdigits
852 Int_t nSDigits = fSDigits->GetEntries();
853
854 ResetSDigits();
855
856 AliDebug(1, Form("Got %d TOF sdigits", nSDigits));
857 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF sdigit tree : R:%.2fs C:%.2fs",
858 stopwatch.RealTime(),stopwatch.CpuTime()));
859
860 return kTRUE;
861
862}
863
864//____________________________________________________________________________
865void AliTOF::Raw2Digits(AliRawReader* rawReader)
866{
867 //
868 // Converts raw data to digits for TOF
869 //
870
871 TStopwatch stopwatch;
872 stopwatch.Start();
873
874 if(!GetLoader()->TreeD()) {MakeTree("D"); MakeBranch("D");}
875 //TClonesArray &aDigits = *fDigits;
876
877 AliTOFRawStream tofRawStream = AliTOFRawStream();
878 tofRawStream.Raw2Digits(rawReader, fDigits);
879
880 /*
881 Int_t inholes = 0;
882
883 const Int_t kMaxNumberOfTracksPerDigit = 3;
884 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
885
886 AliTOFRawStream fTOFRawStream = AliTOFRawStream();
887 fTOFRawStream.Clear();
888 fTOFRawStream.SetRawReader(rawReader);
889
890 //ofstream ftxt;
891 //if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
892
893 TClonesArray staticRawData("AliTOFrawData",10000);
894 staticRawData.Clear();
895 TClonesArray * clonesRawData = &staticRawData;
896
897 Int_t dummy = -1;
898 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
899 Int_t digit[4];
900 Int_t tracks[kMaxNumberOfTracksPerDigit];
901 for (Int_t ii=0; ii<kMaxNumberOfTracksPerDigit; ii++)
902 tracks[ii] = -1;
903 Int_t last = -1;
904
905 Int_t indexDDL = 0;
906 Int_t iRawData = 0;
907 for (indexDDL=0; indexDDL<kDDL; indexDDL++) {
908
909 rawReader->Reset();
910 //if (fDecoderVersion) {
911 //AliInfo("Using New Decoder \n");
912 //fTOFRawStream.LoadRawDataBuffers(indexDDL, 0);
913 //}
914 //else
915 fTOFRawStream.LoadRawData(indexDDL);
916
917 clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
918 if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
919 for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
920
921 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
922
923 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
924 if (tofRawDatum->GetTOF()==-1) continue;
925
926 fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
927 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
928
929 dummy = detectorIndex[3];
930 detectorIndex[3] = detectorIndex[4];//padz
931 detectorIndex[4] = dummy;//padx
932
933 digit[0] = tofRawDatum->GetTOF();
934 digit[1] = tofRawDatum->GetTOT();
935 digit[2] = tofRawDatum->GetTOT();
936 digit[3] = -1;//tofRawDatum->GetTOF(); //tofND
937
938 dummy = detectorIndex[3];
939 detectorIndex[3] = detectorIndex[4];//padx
940 detectorIndex[4] = dummy;//padz
941
942 // Do not reconstruct anything in the holes
943 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
944 if (detectorIndex[1]==2) { // plate with holes
945 inholes++;
946 continue;
947 }
948 }
949
950 last = fDigits->GetEntriesFast();
951 new (aDigits[last]) AliTOFdigit(tracks, detectorIndex, digit);
952 //
953 if (fVerbose==2) {
954 if (indexDDL<10) ftxt << " " << indexDDL;
955 else ftxt << " " << indexDDL;
956 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
957 else ftxt << " " << tofRawDatum->GetTRM();
958 ftxt << " " << tofRawDatum->GetTRMchain();
959 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
960 else ftxt << " " << tofRawDatum->GetTDC();
961 ftxt << " " << tofRawDatum->GetTDCchannel();
962
963 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
964 else ftxt << " -> " << detectorIndex[0];
965 ftxt << " " << detectorIndex[1];
966 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
967 else ftxt << " " << detectorIndex[2];
968 ftxt << " " << detectorIndex[4];
969 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[3];
970 else ftxt << " " << detectorIndex[3];
971
972 if (digit[1]<10)ftxt << " " << digit[1];
973 else if (digit[1]>=10 && digit[1]<100) ftxt << " " << digit[1];
974 else ftxt << " " << digit[1];
975 if (digit[0]<10) ftxt << " " << digit[0] << endl;
976 else if (digit[0]>=10 && digit[0]<100) ftxt << " " << digit[0] << endl;
977 else if (digit[0]>=100 && digit[0]<1000) ftxt << " " << digit[0] << endl;
978 else ftxt << " " << digit[3] << endl;
979 }
980 //
981 AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d, %d)",
982 last,
983 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[4], detectorIndex[3],
984 digit[0], digit[1], digit[3]));
985
986 } // while loop
987
988 clonesRawData->Clear();
989
990 } // DDL Loop
991
992 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
993
994 //if (fVerbose==2) ftxt.close();
995 */
996
997 GetLoader()->TreeD()->Fill(); GetLoader()->WriteDigits("OVERWRITE");//write out digits
998 Int_t nDigits = fDigits->GetEntries();
999
1000 ResetDigits();
1001
1002 AliDebug(1, Form("Got %d TOF digits", nDigits));
1003 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
1004 stopwatch.RealTime(),stopwatch.CpuTime()));
1005
1006}