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