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