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