]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOF.cxx
Added function GetModuleType to return the detector type for a specific module.
[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
16/*
17$Log$
517b7f8f 18Revision 1.25 2001/09/07 08:37:40 hristov
19Pointers initialised to 0 in the default constructor
20
519351ab 21Revision 1.24 2001/09/05 16:31:00 hristov
22The deletion of TOF folders temporarily commented out
23
5839f074 24Revision 1.23 2001/08/29 12:59:01 vicinanz
25Minor changes to the Digitizer procedure
26
0efc163f 27Revision 1.22 2001/08/28 08:45:58 vicinanz
28TTask and TFolder structures implemented
29
68861244 30Revision 1.21 2001/05/16 14:57:24 alibrary
31New files for folders and Stack
32
9e1a0ddb 33Revision 1.20 2001/05/04 10:09:47 vicinanz
34Major upgrades to the strip structure
35
b94fa26c 36Revision 1.19 2001/03/12 17:47:25 hristov
37Changes needed on Sun with CC 5.0
38
5cf7bbad 39Revision 1.18 2001/01/26 19:57:42 hristov
40Major upgrade of AliRoot code
41
2ab0c725 42Revision 1.17 2000/10/19 09:58:14 vicinanz
43Updated Hits2Digit procedure
44
c2af3d73 45Revision 1.16 2000/10/02 21:28:17 fca
46Removal of useless dependecies via forward declarations
47
94de3818 48Revision 1.15 2000/05/18 14:33:01 vicinanz
49Modified to be full HP compliant
50
f5489efc 51Revision 1.14 2000/05/15 19:32:36 fca
52Add AddHitList !!
53
c8bd506f 54Revision 1.13 2000/05/10 16:52:18 vicinanz
55New TOF version with holes for PHOS/RICH
56
2cef3cb2 57Revision 1.11.2.1 2000/05/10 09:37:15 vicinanz
58New version with Holes for PHOS/RICH
59
1cedd08a 60Revision 1.11 1999/11/05 22:39:06 fca
61New hits structure
62
826b71ec 63Revision 1.10 1999/11/01 20:41:57 fca
64Added protections against using the wrong version of FRAME
65
ab76897d 66Revision 1.9 1999/10/15 15:35:19 fca
67New version for frame1099 with and without holes
68
937fe4a4 69Revision 1.9 1999/09/29 09:24:33 fca
70Introduction of the Copyright and cvs Log
4c039060 71
937fe4a4 72*/
68861244 73
fe4da5cc 74///////////////////////////////////////////////////////////////////////////////
75// //
68861244 76// Time Of Flight //
fe4da5cc 77// This class contains the basic functions for the Time Of Flight //
78// detector. Functions specific to one particular geometry are //
79// contained in the derived classes //
937fe4a4 80//
81// VERSIONE WITH 5 SYMMETRIC MODULES ALONG Z AXIS
82// ==============================================
83//
84// VERSION WITH HOLES FOR PHOS AND TRD IN SPACEFRAME WITH HOLES
85//
86// Volume sensibile : FPAD
87//
88//
89//
90// Begin_Html
fe4da5cc 91/*
1439f98e 92<img src="picts/AliTOFClass.gif">
fe4da5cc 93*/
94//End_Html
937fe4a4 95//
96//
fe4da5cc 97// //
98///////////////////////////////////////////////////////////////////////////////
99
826b71ec 100#include <iostream.h>
68861244 101#include <strstream.h>
517b7f8f 102#include <fstream.h>
103#include <stdlib.h>
826b71ec 104
fe4da5cc 105#include "AliTOF.h"
68861244 106#include "AliTOFhit.h"
107#include "AliTOFdigit.h"
108#include "AliTOFRawSector.h"
109#include "AliTOFRoc.h"
110#include "AliTOFRawDigit.h"
111
112#include "TROOT.h"
826b71ec 113#include "TBRIK.h"
2cef3cb2 114#include "TNode.h"
115#include "TObject.h"
0efc163f 116#include "TSystem.h"
94de3818 117#include "TTree.h"
2ab0c725 118#include "TFile.h"
68861244 119#include "TFolder.h"
120#include "TTask.h"
94de3818 121
fe4da5cc 122#include "AliRun.h"
94de3818 123#include "AliMC.h"
124#include "AliMagF.h"
fe4da5cc 125#include "AliConst.h"
2cef3cb2 126
fe4da5cc 127
128ClassImp(AliTOF)
129
130//_____________________________________________________________________________
131AliTOF::AliTOF()
132{
133 //
134 // Default constructor
135 //
519351ab 136 fFGeom = 0;
137 fDTask = 0;
138 fReTask = 0;
fe4da5cc 139 fIshunt = 0;
68861244 140 fSDigits = 0 ;
141 fDigits = 0 ;
142 fName="TOF";
517b7f8f 143/* fp
68861244 144 CreateTOFFolders();
517b7f8f 145*/
fe4da5cc 146}
147
148//_____________________________________________________________________________
149AliTOF::AliTOF(const char *name, const char *title)
150 : AliDetector(name,title)
151{
152 //
153 // AliTOF standard constructor
154 //
2cef3cb2 155 // Here are fixed some important parameters
156 //
157
68861244 158 // Initialization of hits, sdigits and digits array
2cef3cb2 159 //
517b7f8f 160 fHits = new TClonesArray("AliTOFhit", 1000);
c8bd506f 161 gAlice->AddHitList(fHits);
2cef3cb2 162 fIshunt = 0;
517b7f8f 163 fSDigits = new TClonesArray("AliTOFdigit", 1000);
164 fDigits = new TClonesArray("AliTOFdigit", 1000);
2cef3cb2 165 //
166 // Digitization parameters
fe4da5cc 167 //
2cef3cb2 168 // (Transfer Functions to be inserted here)
fe4da5cc 169 //
170 SetMarkerColor(7);
171 SetMarkerStyle(2);
172 SetMarkerSize(0.4);
2cef3cb2 173
174// General Geometrical Parameters
b94fa26c 175 fNTof = 18; // number of sectors
176 fRmax = 399.0;//cm
2cef3cb2 177 fRmin = 370.0;//cm
b94fa26c 178 fZlenC = 177.5;//cm length of module C
179 fZlenB = 141.0;//cm length of module B
180 fZlenA = 106.0;//cm length of module A
517b7f8f 181 fZtof = 371.5;//cm total semi-length of TOF detector
2cef3cb2 182
183// Strip Parameters
184 fStripLn = 122.0;//cm Strip Length
185 fSpace = 5.5;//cm Space Beetween the strip and the bottom of the plate
186 fDeadBndZ= 1.5;//cm Dead Boundaries of a Strip along Z direction (width)
187 fDeadBndX= 1.0;//cm Dead Boundaries of a Strip along X direction (length)
188 fXpad = 2.5;//cm X size of a pad
189 fZpad = 3.5;//cm Z size of a pad
190 fGapA = 4.; //cm Gap beetween tilted strip in A-type plate
191 fGapB = 6.; //cm Gap beetween tilted strip in B-type plate
192 fOverSpc = 15.3;//cm Space available for sensitive layers in radial direction
193 fNpadX = 48; // Number of pads in a strip along the X direction
194 fNpadZ = 2; // Number of pads in a strip along the Z direction
195 fPadXStr = fNpadX*fNpadZ; //Number of pads per strip
b94fa26c 196 fNStripA = 15; // number of strips in A type module
197 fNStripB = 19; // number of strips in B type module
198 fNStripC = 20; // number of strips in C type module
2cef3cb2 199
200// Physical performances
201 fTimeRes = 100.;//ps
202 fChrgRes = 100.;//pC
203
204// DAQ characteristics
68861244 205// cfr. TOF-TDR pag. 105 for Glossary
206// TARODA : TOF-ALICE Read Out and Data Acquisition system
207 fPadXSector = 8928; // number of pad per sector -with no holes-
208 // ((15+2*19+2*20)*(48*2))
209 fNRoc = 14; // number of Roc (Read Out Controller) (TARODA)
210 fNFec = 32; // number of Fec (Front-End electronic Card)
211 // (TARODA)
212 fNTdc = 32; // number of Tdc (Time to Digital Converter)
213 fNPadXRoc = (Int_t)fPadXSector/fNRoc; // number of pads for each ROC
517b7f8f 214 /* fp 25 Sept 2001
68861244 215 // Create TOF Folder Structure
517b7f8f 216 CreateTOFFolders();
217 */
68861244 218}
219
220//_____________________________________________________________________________
221void AliTOF::CreateTOFFolders()
222{
223 // create the ALICE TFolder
224 // create the ALICE TTasks
225 // create the ALICE main TFolder
226 // to be done by AliRun
227
228 TFolder * alice = new TFolder();
229 alice->SetNameTitle("FPAlice", "Alice Folder") ;
230 gROOT->GetListOfBrowsables()->Add(alice) ;
231
232 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
233 // make it the owner of the objects that it contains
234 aliceF->SetOwner() ;
235 // geometry folder
236 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
237 TFolder * aliceT = alice->AddFolder("tasks", "Alice tasks Folder") ;
238 // make it the owner of the objects that it contains
239 aliceT->SetOwner() ;
240
241 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
242 aliceT->Add(aliceDi);
243
244 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
245 aliceT->Add(aliceRe);
246
247 char * tempo = new char[80] ;
248
249 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
250 sprintf(tempo, "%sDigitizers container",GetName() ) ;
251 fDTask = new TTask(GetName(), tempo);
252 aliceDi->Add(fDTask) ;
253
254 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
255 sprintf(tempo, "%sReconstructioner container",GetName() ) ;
256 fReTask = new TTask(GetName(), tempo);
257 aliceRe->Add(fReTask) ;
258
259 delete tempo ;
260
261 // creates the TOF geometry folder
262 geomF->AddFolder("TOF", "Geometry for TOF") ;
263}
264
265//_____________________________________________________________________________
266AliTOF::~AliTOF()
267{
517b7f8f 268 // dtor:
269 // it remove also the alice folder
68861244 270 // and task that TOF creates instead of AliRun
5839f074 271 /* PH Temporarily commented because of problems
68861244 272 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
273 delete alice;
274 alice = 0;
5839f074 275 */
517b7f8f 276 if (fHits)
277 {
278 fHits->Delete ();
279 delete fHits;
280 fHits = 0;
281 }
282 if (fDigits)
283 {
284 fDigits->Delete ();
285 delete fDigits;
286 fDigits = 0;
287 }
288 if (fSDigits)
289 {
290 fSDigits->Delete ();
291 delete fSDigits;
292 fSDigits = 0;
293 }
294 if (fReconParticles)
295 {
296 fReconParticles->Delete ();
297 delete fReconParticles;
298 fReconParticles = 0;
299 }
300
fe4da5cc 301}
302
303//_____________________________________________________________________________
2cef3cb2 304void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
fe4da5cc 305{
306 //
307 // Add a TOF hit
68861244 308 // new with placement used
fe4da5cc 309 //
310 TClonesArray &lhits = *fHits;
2cef3cb2 311 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
fe4da5cc 312}
313
314//_____________________________________________________________________________
2cef3cb2 315void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Float_t *digits)
fe4da5cc 316{
317 //
2cef3cb2 318 // Add a TOF digit
68861244 319 // new with placement used
2cef3cb2 320 //
321 TClonesArray &ldigits = *fDigits;
322 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
fe4da5cc 323}
324
517b7f8f 325//___________________________________________
326void AliTOF::AddSDigit(Int_t *tracks, Int_t *vol, Float_t *digits)
327{
328
329//
330// Add a TOF sdigit
331//
332
333 TClonesArray &lSDigits = *fSDigits;
334 new(lSDigits[fNSDigits++]) AliTOFdigit(tracks, vol, digits);
335}
336
337//_____________________________________________________________________________
338void AliTOF::SetTreeAddress ()
339{
340 // Set branch address for the Hits and Digits Tree.
341 char branchname[30];
342 AliDetector::SetTreeAddress ();
343
344 TBranch *branch;
345 TTree *treeD = gAlice->TreeD ();
346
347
348 if (treeD)
349 {
350 if (fDigits)
351 {
352 branch = treeD->GetBranch (branchname);
353 if (branch)
354 branch->SetAddress (&fDigits);
355 }
356
357 }
358 if (fSDigits)
359 // fSDigits->Clear ();
360
361 if (gAlice->TreeS () && fSDigits)
362 {
363 branch = gAlice->TreeS ()->GetBranch ("TOF");
364 if (branch)
365 branch->SetAddress (&fSDigits);
366 }
367
368 if (gAlice->TreeR() && fReconParticles)
369 {
370 branch = gAlice->TreeR()->GetBranch("TOF");
371 if (branch) branch->SetAddress(&fReconParticles) ;
372 }
373}
2cef3cb2 374
fe4da5cc 375//_____________________________________________________________________________
376void AliTOF::CreateGeometry()
377{
378 //
3fe3a833 379 // Common geometry code
fe4da5cc 380 //
381 //Begin_Html
382 /*
1439f98e 383 <img src="picts/AliTOFv23.gif">
fe4da5cc 384 */
385 //End_Html
386 //
fe4da5cc 387 const Double_t kPi=TMath::Pi();
2cef3cb2 388 const Double_t kDegrad=kPi/180.;
fe4da5cc 389 //
b94fa26c 390 Float_t xTof, yTof, wall;
937fe4a4 391
3fe3a833 392 // frame inbetween TOF modules
b94fa26c 393 wall = 4.;//cm
3fe3a833 394
2cef3cb2 395 // Sizes of TOF module with its support etc..
b94fa26c 396 xTof = 2.*(fRmin*TMath::Tan(10*kDegrad)-wall/2-.5);
2cef3cb2 397 yTof = fRmax-fRmin;
3fe3a833 398
937fe4a4 399// TOF module internal definitions
2cef3cb2 400 TOFpc(xTof, yTof, fZlenC, fZlenB, fZlenA, fZtof);
fe4da5cc 401}
402
403//_____________________________________________________________________________
68861244 404void AliTOF::DrawModule() const
fe4da5cc 405{
406 //
407 // Draw a shaded view of the common part of the TOF geometry
fe4da5cc 408 //
409
3fe3a833 410 cout << " Drawing of AliTOF"<< endl;
fe4da5cc 411 // Set everything unseen
cfce8870 412 gMC->Gsatt("*", "seen", -1);
fe4da5cc 413 //
414 // Set ALIC mother transparent
cfce8870 415 gMC->Gsatt("ALIC","SEEN",0);
fe4da5cc 416 //
417 // Set the volumes visible
2cef3cb2 418 gMC->Gsatt("FTOA","SEEN",1);
419 gMC->Gsatt("FTOB","SEEN",1);
420 gMC->Gsatt("FTOC","SEEN",1);
421 gMC->Gsatt("FLTA","SEEN",1);
422 gMC->Gsatt("FLTB","SEEN",1);
423 gMC->Gsatt("FLTC","SEEN",1);
424 gMC->Gsatt("FSTR","SEEN",1);
cfce8870 425 //
426 gMC->Gdopt("hide", "on");
427 gMC->Gdopt("shad", "on");
428 gMC->Gsatt("*", "fill", 7);
429 gMC->SetClipBox(".");
430 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
431 gMC->DefaultRange();
432 gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
433 gMC->Gdhead(1111, "Time Of Flight");
434 gMC->Gdman(18, 4, "MAN");
435 gMC->Gdopt("hide","off");
fe4da5cc 436}
437
438//_____________________________________________________________________________
439void AliTOF::CreateMaterials()
440{
441 //
442 // Defines TOF materials for all versions
2cef3cb2 443 // Authors : Maxim Martemianov, Boris Zagreev (ITEP)
444 // 18/09/98
b94fa26c 445 // Revision: F. Pierella 5-3-2001
446 // Bologna University
fe4da5cc 447 //
b94fa26c 448 Int_t isxfld = gAlice->Field()->Integ();
449 Float_t sxmgmx = gAlice->Field()->Max();
fe4da5cc 450 //
3fe3a833 451 //--- Quartz (SiO2)
452 Float_t aq[2] = { 28.0855,15.9994 };
453 Float_t zq[2] = { 14.,8. };
454 Float_t wq[2] = { 1.,2. };
455 Float_t dq = 2.20;
456 Int_t nq = -2;
b94fa26c 457 // --- Freon C2F4H2 (TOF-TDR pagg.)
458 // Geant Manual CONS110-1, pag. 43 (Geant, Detector Description and Simulation Tool)
459 Float_t afre[3] = {12.011,18.998,1.007};
460 Float_t zfre[3] = { 6., 9., 1.};
461 Float_t wfre[3] = { 2., 4., 2.};
462 Float_t densfre = 0.00375;
463// http://www.fi.infn.it/sezione/prevprot/gas/freon.html
464 Int_t nfre = -3;
465/*
466 //-- Isobutane quencher C4H10 (5% in the sensitive mixture)
467 Float_t aiso[2] = {12.011,1.007};
468 Float_t ziso[2] = { 6., 1.};
469 Float_t wiso[2] = { 4., 10.};
470 Float_t densiso = .......; // (g/cm3) density
471 Int_t nfre = -2; // < 0 i.e. proportion by number of atoms of each kind
472 //-- SF6 (5% in the sensitive mixture)
473 Float_t asf[3] = {32.066,18.998};
474 Float_t zsf[3] = { 16., 9.};
475 Float_t wsf[3] = { 1., 6.};
476 Float_t denssf = .....; // (g/cm3) density
477 Int_t nfre = -2; // < 0 i.e. proportion by number of atoms of each kind
478*/
3fe3a833 479 // --- CO2
2cef3cb2 480 Float_t ac[2] = {12.,16.};
481 Float_t zc[2] = { 6., 8.};
482 Float_t wc[2] = { 1., 2.};
3fe3a833 483 Float_t dc = .001977;
484 Int_t nc = -2;
485 // For mylar (C5H4O2)
486 Float_t amy[3] = { 12., 1., 16. };
487 Float_t zmy[3] = { 6., 1., 8. };
488 Float_t wmy[3] = { 5., 4., 2. };
489 Float_t dmy = 1.39;
490 Int_t nmy = -3;
b94fa26c 491 // For polyethilene (CH2) - honeycomb -
3fe3a833 492 Float_t ape[2] = { 12., 1. };
493 Float_t zpe[2] = { 6., 1. };
494 Float_t wpe[2] = { 1., 2. };
495 Float_t dpe = 0.935*0.479; //To have 1%X0 for 1cm as for honeycomb
496 Int_t npe = -2;
497 // --- G10
fe4da5cc 498 Float_t ag10[4] = { 12.,1.,16.,28. };
2cef3cb2 499 Float_t zg10[4] = { 6.,1., 8.,14. };
fe4da5cc 500 Float_t wmatg10[4] = { .259,.288,.248,.205 };
3fe3a833 501 Float_t densg10 = 1.7;
502 Int_t nlmatg10 = -4;
503 // --- DME
fe4da5cc 504 Float_t adme[5] = { 12.,1.,16.,19.,79. };
2cef3cb2 505 Float_t zdme[5] = { 6.,1., 8., 9.,35. };
fe4da5cc 506 Float_t wmatdme[5] = { .4056,.0961,.2562,.1014,.1407 };
3fe3a833 507 Float_t densdme = .00205;
508 Int_t nlmatdme = 5;
509 // ---- ALUMINA (AL203)
2cef3cb2 510 Float_t aal[2] = { 27.,16.};
511 Float_t zal[2] = { 13., 8.};
fe4da5cc 512 Float_t wmatal[2] = { 2.,3. };
3fe3a833 513 Float_t densal = 2.3;
514 Int_t nlmatal = -2;
515 // -- Water
516 Float_t awa[2] = { 1., 16. };
517 Float_t zwa[2] = { 1., 8. };
518 Float_t wwa[2] = { 2., 1. };
519 Float_t dwa = 1.0;
520 Int_t nwa = -2;
fe4da5cc 521 //
3fe3a833 522 //AliMaterial(0, "Vacuum$", 1e-16, 1e-16, 1e-16, 1e16, 1e16);
2cef3cb2 523 AliMaterial( 1, "Air$",14.61,7.3,0.001205,30423.24,67500.);
524 AliMaterial( 2, "Cu $", 63.54, 29.0, 8.96, 1.43, 14.8);
525 AliMaterial( 3, "C $", 12.01, 6.0, 2.265,18.8, 74.4);
526 AliMixture ( 4, "Polyethilene$", ape, zpe, dpe, npe, wpe);
527 AliMixture ( 5, "G10$", ag10, zg10, densg10, nlmatg10, wmatg10);
528 AliMixture ( 6, "DME ", adme, zdme, densdme, nlmatdme, wmatdme);
529 AliMixture ( 7, "CO2$", ac, zc, dc, nc, wc);
530 AliMixture ( 8, "ALUMINA$", aal, zal, densal, nlmatal, wmatal);
531 AliMaterial( 9, "Al $", 26.98, 13., 2.7, 8.9, 37.2);
3fe3a833 532 AliMaterial(10, "C-TRD$", 12.01, 6., 2.265*18.8/69.282*15./100, 18.8, 74.4); // for 15%
2cef3cb2 533 AliMixture (11, "Mylar$", amy, zmy, dmy, nmy, wmy);
534 AliMixture (12, "Freon$", afre, zfre, densfre, nfre, wfre);
535 AliMixture (13, "Quartz$", aq, zq, dq, nq, wq);
536 AliMixture (14, "Water$", awa, zwa, dwa, nwa, wwa);
3fe3a833 537
538 Float_t epsil, stmin, deemax, stemax;
2cef3cb2 539
540 // Previous data
fe4da5cc 541 // EPSIL = 0.1 ! Tracking precision,
542 // STEMAX = 0.1 ! Maximum displacement for multiple scattering
543 // DEEMAX = 0.1 ! Maximum fractional energy loss, DLS
544 // STMIN = 0.1
2cef3cb2 545 //
546 // New data
547 epsil = .001; // Tracking precision,
548 stemax = -1.; // Maximum displacement for multiple scattering
549 deemax = -.3; // Maximum fractional energy loss, DLS
fe4da5cc 550 stmin = -.8;
937fe4a4 551
b94fa26c 552 AliMedium( 1, "Air$" , 1, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
553 AliMedium( 2, "Cu $" , 2, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
554 AliMedium( 3, "C $" , 3, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
555 AliMedium( 4, "Pol$" , 4, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
556 AliMedium( 5, "G10$" , 5, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
557 AliMedium( 6, "DME$" , 6, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
558 AliMedium( 7, "CO2$" , 7, 0, isxfld, sxmgmx, 10., -.01, -.1, .01, -.01);
559 AliMedium( 8,"ALUMINA$", 8, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
560 AliMedium( 9,"Al Frame$",9, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
561 AliMedium(10, "DME-S$", 6, 1, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
562 AliMedium(11, "C-TRD$", 10, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
563 AliMedium(12, "Myl$" , 11, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
564 AliMedium(13, "Fre$" , 12, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
565 AliMedium(14, "Fre-S$", 12, 1, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
566 AliMedium(15, "Glass$", 13, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
567 AliMedium(16, "Water$", 14, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
fe4da5cc 568}
569
570//_____________________________________________________________________________
68861244 571Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t ) const
fe4da5cc 572{
573 //
574 // Returns distance from mouse pointer to detector, default version
575 //
576 return 9999;
577}
517b7f8f 578
579//___________________________________________
580void AliTOF::ResetHits ()
581{
582 // Reset number of clusters and the cluster array for this detector
583 AliDetector::ResetHits ();
584}
585
586//____________________________________________
587void AliTOF::ResetDigits ()
588{
589 //
590 // Reset number of digits and the digits array for this detector
591 AliDetector::ResetDigits ();
592 //
593}
fe4da5cc 594//_____________________________________________________________________________
595void AliTOF::Init()
596{
597 //
598 // Initialise TOF detector after it has been built
599 //
fe4da5cc 600 // Set id of TOF sensitive volume
937fe4a4 601 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
fe4da5cc 602 //
fe4da5cc 603}
604
2cef3cb2 605//____________________________________________________________________________
9e1a0ddb 606void AliTOF::MakeBranch(Option_t* option, const char *file)
2cef3cb2 607{
b94fa26c 608 //
609 // Initializes the Branches of the TOF inside the
610 // trees written for each event.
517b7f8f 611 // AliDetector::MakeBranch initializes just the
68861244 612 // Branch inside TreeH. Here we add the branches in
517b7f8f 613 // TreeD, TreeS and TreeR.
b94fa26c 614 //
2ab0c725 615 AliDetector::MakeBranch(option,file);
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
625 if (oD)
626 //
627 // one branch for TOF digits
628 //
629
2cef3cb2 630
68861244 631 if (fDigits && gAlice->TreeD() && oD){
632 MakeBranchInTree(gAlice->TreeD(),
2ab0c725 633 branchname, &fDigits,buffersize, file) ;
2cef3cb2 634 }
68861244 635
636 if (oS)
637 //
638 // one branch for TOF sdigits
639 //
640
641
642 if (fSDigits && gAlice->TreeS() && oS){
643 MakeBranchInTree(gAlice->TreeS(),
644 branchname, &fSDigits,buffersize, file) ;
645 }
646
517b7f8f 647 if (oR)
648 //
649 // one branch for TOF reconstructed particles
650 //
651
652
653 if (fReconParticles && gAlice->TreeR() && oR){
654 MakeBranchInTree(gAlice->TreeR(),
655 branchname, &fReconParticles,buffersize, file) ;
656 }
657
68861244 658}
659
660//____________________________________________________________________________
661void AliTOF::Makehits(Bool_t hits)
662{
663// default argument used, see AliTOF.h
664// Enable/Disable the writing of the TOF-hits branch
665// on TreeH
666// by default : enabled for TOFv1, v2, v3, v4
667// disabled for TOFv0
668//
669 if (hits && (IsVersion()!=0))
670 fIdSens = gMC->VolId("FPAD");
671 else
672 cout << "Option for writing the TOF-hits branch on TreeH: disabled" << endl;
2cef3cb2 673}
674
675//____________________________________________________________________________
676void AliTOF::FinishEvent()
677{
68861244 678// do nothing
2cef3cb2 679}
680
2ab0c725 681//___________________________________________
682void AliTOF::SDigits2Digits()
683{
684//
517b7f8f 685// Generate digits performing merging
2ab0c725 686//
517b7f8f 687 /*
2ab0c725 688 int nparticles = gAlice->GetNtrack();
689 cout << "Particles :" <<nparticles<<endl;
690 if (nparticles > 0 ) {
517b7f8f 691
68861244 692 AliTOF::Hits2Digits();
517b7f8f 693
2ab0c725 694 }
517b7f8f 695 */
696 cout<<"AliTOF::SDigits2Digits"<<endl;
697 if (fMerger) {
698 fMerger->Init();
699 cout<<"AliTOF::SDigits2Digits Init"<<endl;
700 fMerger->Digitise();
701 cout<<"AliTOF::SDigits2Digits Digitise() "<<endl;
702 }
703}
704
705//---------------------------------------------------------------------
706void AliTOF::SetMerger(AliTOFMerger* merger)
707{
708// Set pointer to merger
709 fMerger = merger;
710}
711
712//---------------------------------------------------------------------
713AliTOFMerger* AliTOF::Merger()
714{
715// Return pointer to merger
716 return fMerger;
2ab0c725 717}
2cef3cb2 718
719//____________________________________________________________________________
517b7f8f 720void AliTOF::TOFHits2SDigits()
b94fa26c 721{
2cef3cb2 722//
68861244 723// Starting from the Hits Tree (TreeH), this
517b7f8f 724// function writes the TOF SDigits Branch in the TreeS storing
2cef3cb2 725// the digits informations.
68861244 726// It has to be called just at the end of an event or
2cef3cb2 727// at the end of a whole run.
68861244 728// It could also be called by AliTOF::Finish Event()
2cef3cb2 729// Just for MC events.
730//
517b7f8f 731// Called by the ROOT script Hits2SDigits.C
2cef3cb2 732//
68861244 733// Simulation of detector response.
b94fa26c 734
68861244 735 Int_t ver = this->IsVersion();
517b7f8f 736 if(ver==0) return; // no sdigits for AliTOFv0
737
738 AliTOF *TOF = (AliTOF *) gAlice->GetDetector ("TOF");
739
740 if (fNevents == 0)
741 fNevents = (Int_t) gAlice->TreeE ()->GetEntries ();
742
743 cout << "nevents found on file " << fNevents << endl;
744 // Start Event ------------------------- LOOP
745
746 for (Int_t ievent = 0; ievent < fNevents; ievent++)
747 {
748 gAlice->GetEvent (ievent);
749 if (gAlice->TreeH () == 0)
750 return; // no hits stored
751 if (gAlice->TreeS () == 0)
752 gAlice->MakeTree ("S");
753
754
755 Int_t nSdigits = 0;
756
757 //Make branches
758 char branchname[20];
759 sprintf (branchname, "%s", TOF->GetName ());
760 //Make branch for TOF sdigits
761 TOF->MakeBranch ("S");
762
763 Int_t tracks[3]; // track info
764 Int_t vol[5]; // location for a digit
765 Float_t digit[2]; // TOF digit variables
766 Int_t hit, nbytes;
767 TParticle *particle;
768 AliTOFhit *tofHit;
769 TClonesArray *TOFhits = TOF->Hits();
770
771
772 if (TOF)
773 {
774 TOFhits = TOF->Hits(); // pointer to the TClonesArray of TOF hits
775 TTree *TH = gAlice->TreeH(); // pointer to the current TreeH
776 Stat_t ntracks = TH->GetEntries(); // number of tracks for the current event
777 for (Int_t track = 0; track < ntracks; track++)
778 {
779 gAlice->ResetHits ();
780 nbytes += TH->GetEvent(track);
781 particle = gAlice->Particle(track);
782 Int_t nhits = TOFhits->GetEntriesFast(); // number of hits for the current track
783
784 for (hit = 0; hit < nhits; hit++)
785 {
786 tofHit = (AliTOFhit*) TOFhits->UncheckedAt(hit);
787 vol[0] = tofHit->GetSector();
788 vol[1] = tofHit->GetPlate();
789 vol[2] = tofHit->GetPadx();
790 vol[3] = tofHit->GetPadz();
791 vol[4] = tofHit->GetStrip();
792
793 // 95% of efficiency to be inserted here
794 // edge effect to be inserted here
795 // cross talk to be inserted here
796
797 Float_t idealtime = tofHit->GetTof(); // unit s
798 idealtime *= 1.E+12; // conversion from s to ps
799 // fTimeRes is given usually in ps
800 Float_t tdctime = gRandom->Gaus(idealtime, fTimeRes);
801 digit[0] = tdctime;
2cef3cb2 802
517b7f8f 803 // typical Landau Distribution to be inserted here
804 // instead of Gaussian Distribution
805 Float_t idealcharge = tofHit->GetEdep();
806 Float_t adccharge = gRandom->Gaus(idealcharge, fChrgRes);
807 digit[1] = adccharge;
808 Int_t tracknum = tofHit->GetTrack();
809 tracks[0] = tracknum;
810 tracks[1] = 0;
811 tracks[2] = 0;
2cef3cb2 812
517b7f8f 813 // check if two digit are on the same pad; in that case we sum
814 // the two or more digits
815 Bool_t overlap = CheckOverlap(vol, digit, tracknum);
816 if(!overlap)
817 new ((*fSDigits)[nSdigits++]) AliTOFdigit(tracks, vol, digit);
818 //cout << "nSdigits" << endl;
819 } // end loop on hits for the current track
68861244 820
517b7f8f 821 } // end loop on ntracks
68861244 822
517b7f8f 823 } // close if TOF switched ON
68861244 824
517b7f8f 825 gAlice->TreeS()->Fill();
826 gAlice->TreeS()->Print();
68861244 827
517b7f8f 828 } //event loop
68861244 829
517b7f8f 830}
68861244 831
517b7f8f 832//---------------------------------------------------------------------
2cef3cb2 833
517b7f8f 834void AliTOF::Hits2SDigits()
835{
836//
837// Use the TOF SDigitizer to make TOF SDigits
838//
839//
840 //#ifdef DEBUG
841 cout<<"ALiTOF::Hits2SDigits> start...\n";
842 //#endif
68861244 843
517b7f8f 844 char * fileSDigits = 0 ;
845 char * fileHeader = 0;
846 AliTOFSDigitizer * sd = new AliTOFSDigitizer(fileHeader,fileSDigits) ;
68861244 847
517b7f8f 848 sd->Exec("") ;
849 sd->Print("");
68861244 850
517b7f8f 851 delete sd ;
68861244 852
2cef3cb2 853}
2cef3cb2 854//___________________________________________________________________________
855Bool_t AliTOF::CheckOverlap(Int_t* vol, Float_t* digit,Int_t Track)
b94fa26c 856{
2cef3cb2 857//
858// Checks if 2 or more hits belong to the same pad.
859// In this case the data assigned to the digit object
860// are the ones of the first hit in order of Time.
517b7f8f 861// 2 hits from the same track on the same pad are collected.
862// Called only by Hits2SDigits.
863// This procedure has to be optimized in the next TOF release.
2cef3cb2 864//
b94fa26c 865
517b7f8f 866// Bool_t overlap = 0;
867 Bool_t overlap = kFALSE;
2cef3cb2 868 Int_t vol2[5];
869
517b7f8f 870 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
871 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
2cef3cb2 872 currentDigit->GetLocation(vol2);
517b7f8f 873// Bool_t idem=1;
874 Bool_t idem= kTRUE;
875 // check on digit volume
2cef3cb2 876 for (Int_t i=0;i<=4;i++){
517b7f8f 877 if (!idem) break;
878 if (vol[i]!=vol2[i]) idem=kFALSE;}
879
880 if (idem){ // same pad fired
b94fa26c 881 Float_t tdc2 = digit[0];
882 Float_t tdc1 = currentDigit->GetTdc();
517b7f8f 883
884 // we separate two digits on the same pad if
885 // they are separated in time by at least 25 ns
886 // remember that tdc time is given in ps
887
888 if (TMath::Abs(tdc1-tdc2)<25000){
889 // in case of overlap we take the earliest
890 if (tdc1>tdc2){
891 currentDigit->SetTdc(tdc2);
892 currentDigit->SetAdc(digit[1]);
893 }
894 else {
895 currentDigit->SetTdc(tdc1);
896 currentDigit->SetAdc(digit[1]);
897 }
898 currentDigit->AddTrack(Track); // add track number in the track array
899// cout << "found overlap" << endl;
900// overlap = 1;
901 overlap = kTRUE;
902
903 } // if (TMath:: ...)
904
905 } // close if (idem) -> two digits on the same TOF pad
906
907 } // end loop on existing sdigits
908
b94fa26c 909 return overlap;
2cef3cb2 910}
911
912
913//____________________________________________________________________________
914void AliTOF::Digits2Raw(Int_t evNumber)
b94fa26c 915{
2cef3cb2 916//
917// Starting from digits, writes the
918// Raw Data objects, i.e. a
919// TClonesArray of 18 AliTOFRawSector objects
920//
921
b94fa26c 922 TTree* tD;
2cef3cb2 923
68861244 924 // do nothing if no particles
2cef3cb2 925 Int_t nparticles = gAlice->GetEvent(evNumber);
926 if (nparticles <= 0) return;
927
b94fa26c 928 tD = gAlice->TreeD();
2cef3cb2 929
b94fa26c 930 TClonesArray* tofdigits = this->Digits();
931 Int_t ndigits = tofdigits->GetEntriesFast();
2cef3cb2 932
b94fa26c 933 TClonesArray* rawsectors = new TClonesArray("AliTOFRawSector",fNTof+2);
2cef3cb2 934
935 for (Int_t isect=1;isect<=fNTof;isect++){
b94fa26c 936 AliTOFRawSector* currentSector = (AliTOFRawSector*)rawsectors->UncheckedAt(isect);
937 TClonesArray* rocData = (TClonesArray*)currentSector->GetRocData();
2cef3cb2 938
939 for (Int_t digit=0; digit<ndigits; digit++){
b94fa26c 940 AliTOFdigit* currentDigit = (AliTOFdigit*)tofdigits->UncheckedAt(digit);
2cef3cb2 941 Int_t sector = currentDigit->GetSector();
942 if (sector==isect){
b94fa26c 943 Int_t pad = currentDigit -> GetTotPad();
944 Int_t roc = (Int_t)(pad/fNPadXRoc)-1;
945 if (roc>=fNRoc) printf("Wrong n. of ROC ! Roc = %i",roc);
946 Int_t padRoc = (Int_t) pad%fNPadXRoc;
947 Int_t fec = (Int_t)(padRoc/fNFec)-1;
948 Int_t tdc = (Int_t)(padRoc%fNFec)-1;
949 Float_t time = currentDigit->GetTdc();
950 Float_t charge = currentDigit->GetAdc();
951 AliTOFRoc* currentROC = (AliTOFRoc*)rocData->UncheckedAt(roc);
952 Int_t error = 0;
953 currentROC->AddItem(fec, tdc, error, charge, time);
68861244 954 } // close if (sector==isect) i.e. end loop on digits for the current sector
955 } // end loop on TOF digits
2cef3cb2 956
b94fa26c 957 UInt_t totSize=16,rocSize=0;
958 UInt_t rocHead[14],rocChek[14];
959 UInt_t globalCheckSum=0;
2cef3cb2 960
961 for (UInt_t iRoc = 1; iRoc<(UInt_t)fNRoc; iRoc++){
b94fa26c 962 AliTOFRoc* currentRoc = (AliTOFRoc*)rocData->UncheckedAt(iRoc);
963 rocSize = currentRoc->GetItems()*2+1;
964 totSize += rocSize*4;
965 if (rocSize>=TMath::Power(2,16)) rocSize=0;
966 rocHead[iRoc] = iRoc<<28;
967 rocHead[iRoc] += rocSize;
968 rocChek[iRoc] = currentRoc->GetCheckSum();
969 Int_t headCheck = currentRoc->BitCount(rocHead[iRoc]);
970 globalCheckSum += headCheck;
971 globalCheckSum += rocChek[iRoc];
2cef3cb2 972 }
973
b94fa26c 974 AliTOFRoc* dummyRoc = new AliTOFRoc();
975 totSize *= 4;
976 if (totSize>=TMath::Power(2,24)) totSize=0;
977 UInt_t header = totSize;
978 UInt_t sectId = ((UInt_t)isect)<<24;
979 header += sectId;
980 globalCheckSum += dummyRoc->BitCount(header);
981 currentSector->SetGlobalCS(globalCheckSum);
982 currentSector->SetHeader(header);
2cef3cb2 983 }
984}
985
986//____________________________________________________________________________
987void AliTOF::Raw2Digits(Int_t evNumber)
b94fa26c 988{
2cef3cb2 989//
990// Converts Raw Data objects into digits objects.
991// We schematize the raw data with a
992// TClonesArray of 18 AliTOFRawSector objects
993//
b94fa26c 994
995 TTree *tD;
2cef3cb2 996 Int_t vol[5];
997 Int_t tracks[3];
998 Float_t digit[2];
999
1000 tracks[0]=0;
1001 tracks[1]=0;
1002 tracks[2]=0;
fe4da5cc 1003
2cef3cb2 1004 Int_t nparticles = gAlice->GetEvent(evNumber);
1005 if (nparticles <= 0) return;
1006
b94fa26c 1007 tD = gAlice->TreeD();
2cef3cb2 1008
b94fa26c 1009 TClonesArray* rawsectors = new TClonesArray("AliTOFRawSector",fNTof+2);
2cef3cb2 1010
1011 for(Int_t nSec=1; nSec<=fNTof; nSec++){
b94fa26c 1012 AliTOFRawSector* currentSector = (AliTOFRawSector*)rawsectors->UncheckedAt(nSec);
1013 TClonesArray* rocData = (TClonesArray*)currentSector->GetRocData();
2cef3cb2 1014 for(Int_t nRoc=1; nRoc<=14; nRoc++){
b94fa26c 1015 AliTOFRoc* currentRoc = (AliTOFRoc*)rocData->UncheckedAt(nRoc);
2cef3cb2 1016 Int_t currentItems = currentRoc->GetItems();
1017 for(Int_t item=1; item<currentItems; item++){
1018 Int_t nPad = currentRoc->GetTotPad(item);
1019 vol[0] = nSec;
1020 Int_t nStrip = (Int_t)(nPad/fPadXStr)+1;
1021 Int_t nPlate = 5;
1022 if (nStrip<=fNStripC+2*fNStripB+fNStripA) nPlate = 4;
1023 if (nStrip<=fNStripC+fNStripB+fNStripA) nPlate = 3;
1024 if (nStrip<=fNStripC+fNStripB) nPlate = 2;
1025 if (nStrip<=fNStripC) nPlate=1;
1026 vol[1] = nPlate;
1027 switch (nPlate){
1028 case 1: break;
1029 case 2: nStrip -= (fNStripC);
1030 break;
1031 case 3: nStrip -= (fNStripC+fNStripB);
1032 break;
1033 case 4: nStrip -= (fNStripC+fNStripB+fNStripA);
1034 break;
1035 case 5: nStrip -= (fNStripC+2*fNStripB+fNStripA);
1036 break;
1037 }
1038 vol[2] = nStrip;
b94fa26c 1039 Int_t pad = nPad%fPadXStr;
1040 if (pad==0) pad=fPadXStr;
2cef3cb2 1041 Int_t nPadX=0, nPadZ=0;
b94fa26c 1042 (pad>fNpadX)? nPadX -= fNpadX : nPadX = pad ;
2cef3cb2 1043 vol[3] = nPadX;
b94fa26c 1044 (pad>fNpadX)? nPadZ = 2 : nPadZ = 1 ;
2cef3cb2 1045 vol[4] = nPadZ;
1046 UInt_t error=0;
b94fa26c 1047 Float_t tdc = currentRoc->GetTime(item,error);
1048 if (!error) digit[0]=tdc;
2cef3cb2 1049 digit[1] = currentRoc->GetCharge(item);
1050 AddDigit(tracks,vol,digit);
1051 }
1052 }
1053 }
b94fa26c 1054 tD->Fill();
68861244 1055 tD->Write(0,TObject::kOverwrite);
2cef3cb2 1056}
1057