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