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