Corrected digit's branch name
[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 **************************************************************************/
15
88cb7938 16/* $Id$ */
68861244 17
fe4da5cc 18///////////////////////////////////////////////////////////////////////////////
19// //
68861244 20// Time Of Flight //
fe4da5cc 21// This class contains the basic functions for the Time Of Flight //
22// detector. Functions specific to one particular geometry are //
23// contained in the derived classes //
937fe4a4 24//
25// VERSIONE WITH 5 SYMMETRIC MODULES ALONG Z AXIS
26// ==============================================
27//
28// VERSION WITH HOLES FOR PHOS AND TRD IN SPACEFRAME WITH HOLES
29//
30// Volume sensibile : FPAD
31//
32//
33//
34// Begin_Html
fe4da5cc 35/*
1439f98e 36<img src="picts/AliTOFClass.gif">
fe4da5cc 37*/
38//End_Html
937fe4a4 39//
40//
fe4da5cc 41// //
42///////////////////////////////////////////////////////////////////////////////
43
88cb7938 44
f8014e68 45#include <Riostream.h>
46#include <Rstrstream.h>
517b7f8f 47#include <stdlib.h>
826b71ec 48
88cb7938 49#include <TBRIK.h>
50#include <TFile.h>
51#include <TFolder.h>
52#include <TNode.h>
53#include <TObject.h>
54#include <TROOT.h>
55#include <TSystem.h>
56#include <TTask.h>
57#include <TTree.h>
58#include <TVirtualMC.h>
59
7e6dce66 60#include "AliConfig.h"
61#include "AliHeader.h"
88cb7938 62#include "AliConst.h"
63#include "AliLoader.h"
64#include "AliMagF.h"
65#include "AliRun.h"
fe4da5cc 66#include "AliTOF.h"
7e6dce66 67#include "AliTOFGeometry.h"
88cb7938 68#include "AliTOFSDigit.h"
69#include "AliTOFdigit.h"
70#include "AliTOFhit.h"
71#include "AliTOFhitT0.h"
5d12ce38 72#include "AliMC.h"
85a5290f 73#include "AliTOFDigitizer.h"
7e6dce66 74#include "AliTOFDDLRawData.h"
fe4da5cc 75
76ClassImp(AliTOF)
77
78//_____________________________________________________________________________
79AliTOF::AliTOF()
80{
81 //
82 // Default constructor
83 //
7e6dce66 84 fFGeom = 0x0;
85 fDTask = 0x0;
00711221 86 fReTask = 0x0;
fe4da5cc 87 fIshunt = 0;
7e6dce66 88 fSDigits = 0 ;
8e72349e 89 fNSDigits = 0;
7e6dce66 90 fDigits = 0 ;
00711221 91 fReconParticles = 0x0;
68861244 92 fName="TOF";
00711221 93 fMerger = 0x0;
7e6dce66 94 fTZero = kFALSE;
0f4a7374 95 fTOFGeometry = 0;
fe4da5cc 96}
97
98//_____________________________________________________________________________
792995c1 99AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
fe4da5cc 100 : AliDetector(name,title)
101{
102 //
103 // AliTOF standard constructor
104 //
2cef3cb2 105 // Here are fixed some important parameters
106 //
107
68861244 108 // Initialization of hits, sdigits and digits array
d599d913 109 // added option for time zero analysis
7e6dce66 110 fFGeom = 0x0; //skowron
111 fDTask = 0x0;
112 fReTask = 0x0;
88cb7938 113 fReconParticles= 0x0;
114 fMerger = 0x0;
0f4a7374 115 fTOFGeometry = 0;
88cb7938 116
d599d913 117 if (strstr(option,"tzero")){
118 fHits = new TClonesArray("AliTOFhitT0", 1000);
88cb7938 119 fTZero = kTRUE;
d599d913 120 cout << "tzero option requires AliTOFv4T0 as TOF version (check Your Config.C)" << endl;
121 }else{
122 fHits = new TClonesArray("AliTOFhit", 1000);
88cb7938 123 fTZero = kFALSE;
d599d913 124 }
c630aafd 125 if (gAlice==0) {
126 Fatal("AliTOF","gAlice==0 !");
127 }
5d12ce38 128 if (gAlice->GetMCApp()->GetHitLists())
129 gAlice->GetMCApp()->AddHitList(fHits);
c630aafd 130 else Error("AliTOF","gAlice->GetHitLists()==0");
131
2cef3cb2 132 fIshunt = 0;
7e6dce66 133 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
134 fDigits = new TClonesArray("AliTOFdigit", 1000);
8e72349e 135 fNSDigits = 0;
00711221 136
137 fFGeom = 0x0;
138 fDTask = 0x0;
139 fReTask = 0x0;
140 fReconParticles = 0x0;
141 fMerger = 0x0;
142
2cef3cb2 143 //
144 // Digitization parameters
fe4da5cc 145 //
2cef3cb2 146 // (Transfer Functions to be inserted here)
fe4da5cc 147 //
148 SetMarkerColor(7);
149 SetMarkerStyle(2);
150 SetMarkerSize(0.4);
2cef3cb2 151
2cef3cb2 152// Strip Parameters
7e6dce66 153 //fGapA = 4.; //cm Gap beetween tilted strip in A-type plate
154 //fGapB = 6.; //cm Gap beetween tilted strip in B-type plate
155
156 // Physical performances
157 //fTimeRes = 100.;//ps
158 //fChrgRes = 100.;//pC
159
68861244 160}
161
162//_____________________________________________________________________________
163void AliTOF::CreateTOFFolders()
164{
165 // create the ALICE TFolder
166 // create the ALICE TTasks
167 // create the ALICE main TFolder
168 // to be done by AliRun
169
170 TFolder * alice = new TFolder();
171 alice->SetNameTitle("FPAlice", "Alice Folder") ;
172 gROOT->GetListOfBrowsables()->Add(alice) ;
173
174 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
175 // make it the owner of the objects that it contains
176 aliceF->SetOwner() ;
177 // geometry folder
178 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
179 TFolder * aliceT = alice->AddFolder("tasks", "Alice tasks Folder") ;
180 // make it the owner of the objects that it contains
181 aliceT->SetOwner() ;
182
183 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
184 aliceT->Add(aliceDi);
185
186 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
187 aliceT->Add(aliceRe);
188
189 char * tempo = new char[80] ;
190
191 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
192 sprintf(tempo, "%sDigitizers container",GetName() ) ;
193 fDTask = new TTask(GetName(), tempo);
194 aliceDi->Add(fDTask) ;
195
196 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
197 sprintf(tempo, "%sReconstructioner container",GetName() ) ;
198 fReTask = new TTask(GetName(), tempo);
199 aliceRe->Add(fReTask) ;
200
3ff0c331 201 delete [] tempo ;
68861244 202
203 // creates the TOF geometry folder
204 geomF->AddFolder("TOF", "Geometry for TOF") ;
205}
206
207//_____________________________________________________________________________
208AliTOF::~AliTOF()
209{
517b7f8f 210 // dtor:
211 // it remove also the alice folder
68861244 212 // and task that TOF creates instead of AliRun
5839f074 213 /* PH Temporarily commented because of problems
68861244 214 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
215 delete alice;
216 alice = 0;
5839f074 217 */
517b7f8f 218 if (fHits)
219 {
220 fHits->Delete ();
221 delete fHits;
222 fHits = 0;
223 }
224 if (fDigits)
225 {
226 fDigits->Delete ();
227 delete fDigits;
228 fDigits = 0;
229 }
230 if (fSDigits)
231 {
88cb7938 232 fSDigits->Delete();
517b7f8f 233 delete fSDigits;
234 fSDigits = 0;
235 }
236 if (fReconParticles)
237 {
238 fReconParticles->Delete ();
239 delete fReconParticles;
240 fReconParticles = 0;
241 }
242
fe4da5cc 243}
244
245//_____________________________________________________________________________
2cef3cb2 246void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
fe4da5cc 247{
248 //
249 // Add a TOF hit
68861244 250 // new with placement used
fe4da5cc 251 //
252 TClonesArray &lhits = *fHits;
2cef3cb2 253 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
fe4da5cc 254}
d599d913 255
256//_____________________________________________________________________________
257void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
258{
259 //
260 // Add a TOF hit
261 // new with placement used
262 //
263 TClonesArray &lhits = *fHits;
264 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
265}
266
fe4da5cc 267//_____________________________________________________________________________
2cef3cb2 268void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Float_t *digits)
fe4da5cc 269{
270 //
2cef3cb2 271 // Add a TOF digit
68861244 272 // new with placement used
2cef3cb2 273 //
274 TClonesArray &ldigits = *fDigits;
275 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
fe4da5cc 276}
277
517b7f8f 278//___________________________________________
5919c40c 279void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Float_t *digits)
517b7f8f 280{
281
282//
283// Add a TOF sdigit
284//
285
286 TClonesArray &lSDigits = *fSDigits;
5919c40c 287 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
517b7f8f 288}
289
290//_____________________________________________________________________________
291void AliTOF::SetTreeAddress ()
292{
293 // Set branch address for the Hits and Digits Tree.
88cb7938 294
295 if (fLoader->TreeH())
296 {
297 if (fHits == 0x0)
298 {
299 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
300 else fHits = new TClonesArray("AliTOFhit", 1000);
301 }
302 }
517b7f8f 303 AliDetector::SetTreeAddress ();
304
305 TBranch *branch;
88cb7938 306 TTree *treeD = fLoader->TreeD();
517b7f8f 307
308 if (treeD)
309 {
83e46a80 310 branch = treeD->GetBranch ("TOF");
88cb7938 311 if (branch)
312 {
313 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
314 branch->SetAddress (&fDigits);
315 }
517b7f8f 316 }
517b7f8f 317
88cb7938 318 if (fLoader->TreeS () )
517b7f8f 319 {
88cb7938 320 branch = fLoader->TreeS ()->GetBranch ("TOF");
321 if (branch) {
322 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
323 branch->SetAddress (&fSDigits);
324 }
517b7f8f 325 }
326
88cb7938 327 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
517b7f8f 328 {
88cb7938 329 branch = fLoader->TreeR()->GetBranch("TOF");
330 if (branch)
331 {
332 branch->SetAddress(&fReconParticles) ;
333 }
517b7f8f 334 }
335}
2cef3cb2 336
fe4da5cc 337//_____________________________________________________________________________
338void AliTOF::CreateGeometry()
339{
340 //
3fe3a833 341 // Common geometry code
fe4da5cc 342 //
343 //Begin_Html
344 /*
1439f98e 345 <img src="picts/AliTOFv23.gif">
fe4da5cc 346 */
347 //End_Html
348 //
fe4da5cc 349 const Double_t kPi=TMath::Pi();
2cef3cb2 350 const Double_t kDegrad=kPi/180.;
fe4da5cc 351 //
b94fa26c 352 Float_t xTof, yTof, wall;
937fe4a4 353
3fe3a833 354 // frame inbetween TOF modules
b94fa26c 355 wall = 4.;//cm
3fe3a833 356
2cef3cb2 357 // Sizes of TOF module with its support etc..
7e6dce66 358 xTof = 2.*(AliTOFGeometry::Rmin()*TMath::Tan(10*kDegrad)-wall/2-.5);
359 yTof = AliTOFGeometry::Rmax()-AliTOFGeometry::Rmin();
3fe3a833 360
937fe4a4 361// TOF module internal definitions
7e6dce66 362 //TOFpc(xTof, yTof, fZlenC, fZlenB, fZlenA, AliTOFGeometry::MaxhZtof());
363 TOFpc(xTof, yTof, AliTOFGeometry::ZlenC(), AliTOFGeometry::ZlenB(), AliTOFGeometry::ZlenA(), AliTOFGeometry::MaxhZtof());
fe4da5cc 364}
365
366//_____________________________________________________________________________
68861244 367void AliTOF::DrawModule() const
fe4da5cc 368{
369 //
370 // Draw a shaded view of the common part of the TOF geometry
fe4da5cc 371 //
372
3fe3a833 373 cout << " Drawing of AliTOF"<< endl;
fe4da5cc 374 // Set everything unseen
cfce8870 375 gMC->Gsatt("*", "seen", -1);
fe4da5cc 376 //
377 // Set ALIC mother transparent
cfce8870 378 gMC->Gsatt("ALIC","SEEN",0);
fe4da5cc 379 //
380 // Set the volumes visible
2cef3cb2 381 gMC->Gsatt("FTOA","SEEN",1);
382 gMC->Gsatt("FTOB","SEEN",1);
383 gMC->Gsatt("FTOC","SEEN",1);
384 gMC->Gsatt("FLTA","SEEN",1);
385 gMC->Gsatt("FLTB","SEEN",1);
386 gMC->Gsatt("FLTC","SEEN",1);
387 gMC->Gsatt("FSTR","SEEN",1);
cfce8870 388 //
389 gMC->Gdopt("hide", "on");
390 gMC->Gdopt("shad", "on");
391 gMC->Gsatt("*", "fill", 7);
392 gMC->SetClipBox(".");
393 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
394 gMC->DefaultRange();
395 gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
396 gMC->Gdhead(1111, "Time Of Flight");
397 gMC->Gdman(18, 4, "MAN");
398 gMC->Gdopt("hide","off");
fe4da5cc 399}
400
401//_____________________________________________________________________________
402void AliTOF::CreateMaterials()
403{
404 //
405 // Defines TOF materials for all versions
43808676 406 // Revision: F. Pierella 18-VI-2002
fe4da5cc 407 //
43808676 408
b94fa26c 409 Int_t isxfld = gAlice->Field()->Integ();
410 Float_t sxmgmx = gAlice->Field()->Max();
fe4da5cc 411 //
43808676 412 //--- Quartz (SiO2) to simulate float glass
413 // density tuned to have correct float glass
414 // radiation length
3fe3a833 415 Float_t aq[2] = { 28.0855,15.9994 };
416 Float_t zq[2] = { 14.,8. };
417 Float_t wq[2] = { 1.,2. };
43808676 418 Float_t dq = 2.55; // std value: 2.2
3fe3a833 419 Int_t nq = -2;
43808676 420
b94fa26c 421 // --- Freon C2F4H2 (TOF-TDR pagg.)
422 // Geant Manual CONS110-1, pag. 43 (Geant, Detector Description and Simulation Tool)
423 Float_t afre[3] = {12.011,18.998,1.007};
424 Float_t zfre[3] = { 6., 9., 1.};
425 Float_t wfre[3] = { 2., 4., 2.};
426 Float_t densfre = 0.00375;
427// http://www.fi.infn.it/sezione/prevprot/gas/freon.html
428 Int_t nfre = -3;
429/*
430 //-- Isobutane quencher C4H10 (5% in the sensitive mixture)
431 Float_t aiso[2] = {12.011,1.007};
432 Float_t ziso[2] = { 6., 1.};
433 Float_t wiso[2] = { 4., 10.};
434 Float_t densiso = .......; // (g/cm3) density
435 Int_t nfre = -2; // < 0 i.e. proportion by number of atoms of each kind
436 //-- SF6 (5% in the sensitive mixture)
437 Float_t asf[3] = {32.066,18.998};
438 Float_t zsf[3] = { 16., 9.};
439 Float_t wsf[3] = { 1., 6.};
440 Float_t denssf = .....; // (g/cm3) density
441 Int_t nfre = -2; // < 0 i.e. proportion by number of atoms of each kind
442*/
3fe3a833 443 // --- CO2
2cef3cb2 444 Float_t ac[2] = {12.,16.};
445 Float_t zc[2] = { 6., 8.};
446 Float_t wc[2] = { 1., 2.};
3fe3a833 447 Float_t dc = .001977;
448 Int_t nc = -2;
449 // For mylar (C5H4O2)
450 Float_t amy[3] = { 12., 1., 16. };
451 Float_t zmy[3] = { 6., 1., 8. };
452 Float_t wmy[3] = { 5., 4., 2. };
453 Float_t dmy = 1.39;
454 Int_t nmy = -3;
b94fa26c 455 // For polyethilene (CH2) - honeycomb -
3fe3a833 456 Float_t ape[2] = { 12., 1. };
457 Float_t zpe[2] = { 6., 1. };
458 Float_t wpe[2] = { 1., 2. };
459 Float_t dpe = 0.935*0.479; //To have 1%X0 for 1cm as for honeycomb
460 Int_t npe = -2;
461 // --- G10
fe4da5cc 462 Float_t ag10[4] = { 12.,1.,16.,28. };
2cef3cb2 463 Float_t zg10[4] = { 6.,1., 8.,14. };
fe4da5cc 464 Float_t wmatg10[4] = { .259,.288,.248,.205 };
3fe3a833 465 Float_t densg10 = 1.7;
466 Int_t nlmatg10 = -4;
43808676 467
468 // plexiglass CH2=C(CH3)CO2CH3
469 Float_t aplex[3] = { 12.,1.,16.};
470 Float_t zplex[3] = { 6.,1., 8.};
471 Float_t wmatplex[3] = {5.,8.,2.};
472 Float_t densplex =1.16;
473 Int_t nplex = -3;
474
3fe3a833 475 // ---- ALUMINA (AL203)
2cef3cb2 476 Float_t aal[2] = { 27.,16.};
477 Float_t zal[2] = { 13., 8.};
fe4da5cc 478 Float_t wmatal[2] = { 2.,3. };
3fe3a833 479 Float_t densal = 2.3;
480 Int_t nlmatal = -2;
481 // -- Water
482 Float_t awa[2] = { 1., 16. };
483 Float_t zwa[2] = { 1., 8. };
484 Float_t wwa[2] = { 2., 1. };
485 Float_t dwa = 1.0;
486 Int_t nwa = -2;
d599d913 487
488// stainless steel
489 Float_t asteel[4] = { 55.847,51.9961,58.6934,28.0855 };
490 Float_t zsteel[4] = { 26.,24.,28.,14. };
491 Float_t wsteel[4] = { .715,.18,.1,.005 };
492
3fe3a833 493 //AliMaterial(0, "Vacuum$", 1e-16, 1e-16, 1e-16, 1e16, 1e16);
849bff36 494
495 // AIR
496 Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
497 Float_t zAir[4]={6.,7.,8.,18.};
498 Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
499 Float_t dAir = 1.20479E-3;
500
501 AliMixture( 1, "Air$", aAir, zAir, dAir, 4, wAir);
502
2cef3cb2 503 AliMaterial( 2, "Cu $", 63.54, 29.0, 8.96, 1.43, 14.8);
504 AliMaterial( 3, "C $", 12.01, 6.0, 2.265,18.8, 74.4);
505 AliMixture ( 4, "Polyethilene$", ape, zpe, dpe, npe, wpe);
506 AliMixture ( 5, "G10$", ag10, zg10, densg10, nlmatg10, wmatg10);
43808676 507 AliMixture ( 6, "PLE$", aplex, zplex, densplex, nplex, wmatplex);
2cef3cb2 508 AliMixture ( 7, "CO2$", ac, zc, dc, nc, wc);
509 AliMixture ( 8, "ALUMINA$", aal, zal, densal, nlmatal, wmatal);
510 AliMaterial( 9, "Al $", 26.98, 13., 2.7, 8.9, 37.2);
3fe3a833 511 AliMaterial(10, "C-TRD$", 12.01, 6., 2.265*18.8/69.282*15./100, 18.8, 74.4); // for 15%
2cef3cb2 512 AliMixture (11, "Mylar$", amy, zmy, dmy, nmy, wmy);
513 AliMixture (12, "Freon$", afre, zfre, densfre, nfre, wfre);
43808676 514 AliMixture (13, "Glass$", aq, zq, dq, nq, wq);
2cef3cb2 515 AliMixture (14, "Water$", awa, zwa, dwa, nwa, wwa);
d599d913 516 AliMixture (15, "STAINLESS STEEL$", asteel, zsteel, 7.88, 4, wsteel);
3fe3a833 517
518 Float_t epsil, stmin, deemax, stemax;
2cef3cb2 519
520 // Previous data
fe4da5cc 521 // EPSIL = 0.1 ! Tracking precision,
522 // STEMAX = 0.1 ! Maximum displacement for multiple scattering
523 // DEEMAX = 0.1 ! Maximum fractional energy loss, DLS
524 // STMIN = 0.1
2cef3cb2 525 //
526 // New data
527 epsil = .001; // Tracking precision,
528 stemax = -1.; // Maximum displacement for multiple scattering
529 deemax = -.3; // Maximum fractional energy loss, DLS
fe4da5cc 530 stmin = -.8;
937fe4a4 531
b94fa26c 532 AliMedium( 1, "Air$" , 1, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
533 AliMedium( 2, "Cu $" , 2, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
534 AliMedium( 3, "C $" , 3, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
535 AliMedium( 4, "Pol$" , 4, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
536 AliMedium( 5, "G10$" , 5, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
43808676 537 AliMedium( 6, "PLE$" , 6, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
b94fa26c 538 AliMedium( 7, "CO2$" , 7, 0, isxfld, sxmgmx, 10., -.01, -.1, .01, -.01);
539 AliMedium( 8,"ALUMINA$", 8, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
540 AliMedium( 9,"Al Frame$",9, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
541 AliMedium(10, "DME-S$", 6, 1, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
542 AliMedium(11, "C-TRD$", 10, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
543 AliMedium(12, "Myl$" , 11, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
544 AliMedium(13, "Fre$" , 12, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
545 AliMedium(14, "Fre-S$", 12, 1, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
546 AliMedium(15, "Glass$", 13, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
547 AliMedium(16, "Water$", 14, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
d599d913 548 AliMedium(17, "STEEL$", 15, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
fe4da5cc 549}
550
551//_____________________________________________________________________________
68861244 552Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t ) const
fe4da5cc 553{
554 //
555 // Returns distance from mouse pointer to detector, default version
556 //
557 return 9999;
558}
517b7f8f 559
560//___________________________________________
561void AliTOF::ResetHits ()
562{
563 // Reset number of clusters and the cluster array for this detector
564 AliDetector::ResetHits ();
565}
566
567//____________________________________________
568void AliTOF::ResetDigits ()
569{
570 //
571 // Reset number of digits and the digits array for this detector
572 AliDetector::ResetDigits ();
573 //
574}
d61f73d9 575//____________________________________________
576void AliTOF::ResetSDigits ()
577{
578 //
579 // Reset number of sdigits and the sdigits array for this detector
580 fNSDigits = 0;
e615b5b5 581 //fSDigits = 0x0;
d61f73d9 582 //
583}
fe4da5cc 584//_____________________________________________________________________________
585void AliTOF::Init()
586{
587 //
588 // Initialise TOF detector after it has been built
589 //
fe4da5cc 590 // Set id of TOF sensitive volume
937fe4a4 591 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
fe4da5cc 592 //
fe4da5cc 593}
594
2cef3cb2 595//____________________________________________________________________________
88cb7938 596void AliTOF::MakeBranch(Option_t* option)
2cef3cb2 597{
b94fa26c 598 //
599 // Initializes the Branches of the TOF inside the
600 // trees written for each event.
517b7f8f 601 // AliDetector::MakeBranch initializes just the
68861244 602 // Branch inside TreeH. Here we add the branches in
517b7f8f 603 // TreeD, TreeS and TreeR.
b94fa26c 604 //
88cb7938 605 const char *oH = strstr(option,"H");
606 if (fLoader->TreeH() && oH)
607 {
608 if (fHits == 0x0)
609 {
610 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
611 else fHits = new TClonesArray("AliTOFhit", 1000);
612 }
613 }
614
615 AliDetector::MakeBranch(option);
2cef3cb2 616
617 Int_t buffersize = 4000;
618 Char_t branchname[10];
619 sprintf(branchname,"%s",GetName());
2ab0c725 620
68861244 621 const char *oD = strstr(option,"D");
622 const char *oS = strstr(option,"S");
517b7f8f 623 const char *oR = strstr(option,"R");
68861244 624
88cb7938 625 if (fLoader->TreeD() && oD){
626 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
627 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
2cef3cb2 628 }
68861244 629
88cb7938 630 if (fLoader->TreeS() && oS){
631 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
632 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
68861244 633 }
634
88cb7938 635 if (fReconParticles && fLoader->TreeR() && oR){
636 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
517b7f8f 637 }
68861244 638}
639
640//____________________________________________________________________________
641void AliTOF::Makehits(Bool_t hits)
642{
643// default argument used, see AliTOF.h
644// Enable/Disable the writing of the TOF-hits branch
645// on TreeH
646// by default : enabled for TOFv1, v2, v3, v4
647// disabled for TOFv0
648//
649 if (hits && (IsVersion()!=0))
650 fIdSens = gMC->VolId("FPAD");
651 else
652 cout << "Option for writing the TOF-hits branch on TreeH: disabled" << endl;
2cef3cb2 653}
654
655//____________________________________________________________________________
656void AliTOF::FinishEvent()
657{
68861244 658// do nothing
2cef3cb2 659}
660
2ab0c725 661//___________________________________________
662void AliTOF::SDigits2Digits()
663{
664//
517b7f8f 665// Generate digits performing merging
2ab0c725 666//
517b7f8f 667 /*
2ab0c725 668 int nparticles = gAlice->GetNtrack();
669 cout << "Particles :" <<nparticles<<endl;
670 if (nparticles > 0 ) {
517b7f8f 671
68861244 672 AliTOF::Hits2Digits();
517b7f8f 673
2ab0c725 674 }
517b7f8f 675 */
676 cout<<"AliTOF::SDigits2Digits"<<endl;
677 if (fMerger) {
678 fMerger->Init();
679 cout<<"AliTOF::SDigits2Digits Init"<<endl;
680 fMerger->Digitise();
681 cout<<"AliTOF::SDigits2Digits Digitise() "<<endl;
682 }
683}
684
685//---------------------------------------------------------------------
686void AliTOF::SetMerger(AliTOFMerger* merger)
687{
688// Set pointer to merger
689 fMerger = merger;
690}
691
692//---------------------------------------------------------------------
693AliTOFMerger* AliTOF::Merger()
694{
695// Return pointer to merger
696 return fMerger;
2ab0c725 697}
2cef3cb2 698
517b7f8f 699//---------------------------------------------------------------------
517b7f8f 700void AliTOF::Hits2SDigits()
701{
702//
703// Use the TOF SDigitizer to make TOF SDigits
704//
d61f73d9 705
f540341d 706// cout<<"AliTOF::Hits2SDigits> start...\n";
68861244 707
be385a87 708 AliRunLoader * rl = fLoader->GetRunLoader();
709 AliTOFSDigitizer sd((rl->GetFileName()).Data());
f540341d 710 if (GetDebug()) sd.Print("");
68861244 711
be385a87 712 sd.Exec("") ;
d61f73d9 713
714}
715
716//---------------------------------------------------------------------
717void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
718{
719//
720// Use the TOF SDigitizer to make TOF SDigits
721//
722
723 if ((evNumber2-evNumber1)==1)
724 cout << "<AliTOF::Hits2SDigits>: I am making sdigits for the " << evNumber1 << "th event \n";
725 else if ((evNumber2-evNumber1)>1)
726 cout << "<AliTOF::Hits2SDigits>: I am making sdigits for the events from the "
727 << evNumber1 << "th to the " << evNumber2-1 << "th \n";
728
be385a87 729 AliRunLoader * rl = fLoader->GetRunLoader();
730 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
f540341d 731 if (GetDebug()) sd.Print("");
68861244 732
be385a87 733 sd.Exec("") ;
d61f73d9 734
2cef3cb2 735}
d61f73d9 736
2cef3cb2 737//___________________________________________________________________________
c92eb8ad 738AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 739{
740 return new AliTOFDigitizer(manager);
741}
742
743//___________________________________________________________________________
2cef3cb2 744Bool_t AliTOF::CheckOverlap(Int_t* vol, Float_t* digit,Int_t Track)
b94fa26c 745{
2cef3cb2 746//
747// Checks if 2 or more hits belong to the same pad.
748// In this case the data assigned to the digit object
749// are the ones of the first hit in order of Time.
517b7f8f 750// 2 hits from the same track on the same pad are collected.
751// Called only by Hits2SDigits.
752// This procedure has to be optimized in the next TOF release.
2cef3cb2 753//
b94fa26c 754
517b7f8f 755 Bool_t overlap = kFALSE;
2cef3cb2 756 Int_t vol2[5];
757
517b7f8f 758 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
759 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
2cef3cb2 760 currentDigit->GetLocation(vol2);
517b7f8f 761 Bool_t idem= kTRUE;
762 // check on digit volume
2cef3cb2 763 for (Int_t i=0;i<=4;i++){
517b7f8f 764 if (!idem) break;
765 if (vol[i]!=vol2[i]) idem=kFALSE;}
766
767 if (idem){ // same pad fired
b94fa26c 768 Float_t tdc2 = digit[0];
769 Float_t tdc1 = currentDigit->GetTdc();
517b7f8f 770
771 // we separate two digits on the same pad if
772 // they are separated in time by at least 25 ns
773 // remember that tdc time is given in ps
774
775 if (TMath::Abs(tdc1-tdc2)<25000){
776 // in case of overlap we take the earliest
777 if (tdc1>tdc2){
778 currentDigit->SetTdc(tdc2);
779 currentDigit->SetAdc(digit[1]);
780 }
781 else {
782 currentDigit->SetTdc(tdc1);
783 currentDigit->SetAdc(digit[1]);
784 }
785 currentDigit->AddTrack(Track); // add track number in the track array
517b7f8f 786 overlap = kTRUE;
f3de6e9e 787 return overlap;
788 } else
789 overlap= kFALSE;
517b7f8f 790
791 } // close if (idem) -> two digits on the same TOF pad
792
793 } // end loop on existing sdigits
794
b94fa26c 795 return overlap;
2cef3cb2 796}
797
798
799//____________________________________________________________________________
7e6dce66 800void AliTOF::Digits2Raw()
b94fa26c 801{
2cef3cb2 802//
7e6dce66 803// Starting from the TOF digits, writes the Raw Data objects
2cef3cb2 804//
805
7e6dce66 806 fLoader->LoadDigits();
2cef3cb2 807
7e6dce66 808 TTree* digits = fLoader->TreeD();
809 if (!digits) {
810 Error("Digits2Raw", "no digits tree");
811 return;
812 }
2cef3cb2 813
7e6dce66 814 AliTOFDDLRawData rawWriter;
815 rawWriter.SetVerbose(0);
2cef3cb2 816
7e6dce66 817 Info("Digits2Raw", "Formatting raw data for TOF");
818 digits->GetEvent(0);
819 rawWriter.RawDataTOF(digits->GetBranch("TOF"));
2cef3cb2 820
7e6dce66 821 fLoader->UnloadDigits();
822
823}
55991c8b 824////////////////////////////////////////////////////////////////////////
825void AliTOF::RecreateSDigitsArray() {
826//
827// delete TClonesArray fSDigits and create it again
828// needed for backward compatability with PPR test production
829//
830 delete fSDigits;
831 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
832}
833////////////////////////////////////////////////////////////////////////
834void AliTOF::CreateSDigitsArray() {
835//
836// create TClonesArray fSDigits
837// needed for backward compatability with PPR test production
838//
839 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
840}
596a855f 841