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