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