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