]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOF.cxx
TOF raw data: preliminary implementation and style changes
[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 "AliConfig.h"
61 #include "AliHeader.h"
62 #include "AliConst.h"
63 #include "AliLoader.h"
64 #include "AliMagF.h"
65 #include "AliRun.h"
66 #include "AliTOF.h"
67 #include "AliTOFGeometry.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 #include "AliTOFDDLRawData.h"
75  
76 ClassImp(AliTOF)
77  
78 //_____________________________________________________________________________
79 AliTOF::AliTOF()
80 {
81   //
82   // Default constructor
83   //
84   fFGeom  = 0x0;
85   fDTask  = 0x0;
86   fReTask = 0x0;
87   fIshunt   = 0;
88   fSDigits  = 0 ;
89   fNSDigits = 0;
90   fDigits   = 0 ;
91   fReconParticles = 0x0;
92   fName="TOF";
93   fMerger = 0x0;
94   fTZero  = kFALSE;
95   fTOFGeometry = 0;
96 }
97  
98 //_____________________________________________________________________________
99 AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
100        : AliDetector(name,title)
101 {
102   //
103   // AliTOF standard constructor
104   // 
105   // Here are fixed some important parameters
106   //
107
108   // Initialization of hits, sdigits and digits array
109   // added option for time zero analysis
110   fFGeom  = 0x0; //skowron
111   fDTask  = 0x0;
112   fReTask = 0x0;
113   fReconParticles= 0x0;
114   fMerger = 0x0;
115   fTOFGeometry = 0;
116
117   if (strstr(option,"tzero")){
118     fHits   = new TClonesArray("AliTOFhitT0",  1000);
119     fTZero = kTRUE;
120     cout << "tzero option requires AliTOFv4T0 as TOF version (check Your Config.C)" << endl;
121   }else{
122     fHits   = new TClonesArray("AliTOFhit",  1000);
123     fTZero = kFALSE;
124   }
125   if (gAlice==0) {
126      Fatal("AliTOF","gAlice==0 !");
127   }
128   if (gAlice->GetMCApp()->GetHitLists())
129      gAlice->GetMCApp()->AddHitList(fHits);
130   else Error("AliTOF","gAlice->GetHitLists()==0");
131
132   fIshunt  = 0;
133   fSDigits = new TClonesArray("AliTOFSDigit", 1000);
134   fDigits  = new TClonesArray("AliTOFdigit",  1000);
135   fNSDigits = 0;
136
137   fFGeom = 0x0;
138   fDTask = 0x0;
139   fReTask = 0x0;
140   fReconParticles = 0x0;
141   fMerger = 0x0;
142
143   //
144   // Digitization parameters
145   //
146   // (Transfer Functions to be inserted here)
147   //
148   SetMarkerColor(7);
149   SetMarkerStyle(2);
150   SetMarkerSize(0.4);
151
152 // Strip Parameters
153   //fGapA    =   4.; //cm  Gap beetween tilted strip in A-type plate
154   //fGapB    =   6.; //cm  Gap beetween tilted strip in B-type plate
155
156   // Physical performances
157   //fTimeRes = 100.;//ps
158   //fChrgRes = 100.;//pC
159
160 }
161
162 //_____________________________________________________________________________
163 void AliTOF::CreateTOFFolders()
164 {
165   // create the ALICE TFolder
166   // create the ALICE TTasks
167   // create the ALICE main TFolder
168   // to be done by AliRun
169
170   TFolder * alice = new TFolder();
171   alice->SetNameTitle("FPAlice", "Alice Folder") ;
172   gROOT->GetListOfBrowsables()->Add(alice) ;
173
174   TFolder * aliceF  = alice->AddFolder("folders", "Alice memory Folder") ;
175   //  make it the owner of the objects that it contains
176   aliceF->SetOwner() ;
177   // geometry folder
178   TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
179   TFolder * aliceT  = alice->AddFolder("tasks", "Alice tasks Folder") ;   
180   //  make it the owner of the objects that it contains
181   aliceT->SetOwner() ;
182
183   TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
184   aliceT->Add(aliceDi);
185
186   TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
187   aliceT->Add(aliceRe);
188
189   char * tempo = new char[80] ;
190
191   // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
192   sprintf(tempo, "%sDigitizers container",GetName() ) ;
193   fDTask = new TTask(GetName(), tempo);
194   aliceDi->Add(fDTask) ;
195
196   // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
197   sprintf(tempo, "%sReconstructioner container",GetName() ) ;
198   fReTask = new TTask(GetName(), tempo);
199   aliceRe->Add(fReTask) ;
200
201   delete [] tempo ;
202  
203   // creates the TOF geometry  folder
204   geomF->AddFolder("TOF", "Geometry for TOF") ;
205 }
206
207 //_____________________________________________________________________________
208 AliTOF::~AliTOF()
209 {
210   // dtor:
211   // it remove also the alice folder 
212   // and task that TOF creates instead of AliRun
213   /* PH Temporarily commented because of problems
214   TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
215   delete alice;
216   alice = 0;
217   */
218   if (fHits)
219     {
220       fHits->Delete ();
221       delete fHits;
222       fHits = 0;
223     }
224   if (fDigits)
225     {
226       fDigits->Delete ();
227       delete fDigits;
228       fDigits = 0;
229     }
230   if (fSDigits)
231     {
232       fSDigits->Delete();
233       delete fSDigits;
234       fSDigits = 0;
235     }
236   if (fReconParticles)
237     {
238       fReconParticles->Delete ();
239       delete fReconParticles;
240       fReconParticles = 0;
241     }
242
243 }
244
245 //_____________________________________________________________________________
246 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
247 {
248   //
249   // Add a TOF hit
250   // new with placement used
251   //
252   TClonesArray &lhits = *fHits;
253   new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
254 }
255
256 //_____________________________________________________________________________
257 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
258 {
259   //
260   // Add a TOF hit
261   // new with placement used
262   //
263   TClonesArray &lhits = *fHits;
264   new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
265 }
266
267 //_____________________________________________________________________________
268 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Float_t *digits)
269 {
270   //
271   // Add a TOF digit
272   // new with placement used
273   //
274   TClonesArray &ldigits = *fDigits;
275   new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
276 }
277
278 //___________________________________________
279 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Float_t *digits)
280 {
281      
282 //
283 // Add a TOF sdigit
284 //
285         
286   TClonesArray &lSDigits = *fSDigits;   
287   new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
288 }
289
290 //_____________________________________________________________________________
291 void AliTOF::SetTreeAddress ()
292 {
293   // Set branch address for the Hits and Digits Tree.
294   char branchname[30];
295   
296   if (fLoader->TreeH())
297    {
298      if (fHits == 0x0)
299       {
300         if (fTZero) fHits   = new TClonesArray("AliTOFhitT0", 1000);
301         else fHits   = new TClonesArray("AliTOFhit", 1000);
302       }
303    }
304   AliDetector::SetTreeAddress ();
305
306   TBranch *branch;
307   TTree *treeD = fLoader->TreeD();
308
309   if (treeD)
310     {
311       branch = treeD->GetBranch (branchname);
312       if (branch)
313        {
314          if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit",  1000); 
315          branch->SetAddress (&fDigits);
316        }
317     }
318
319   if (fLoader->TreeS () )
320     {
321       branch = fLoader->TreeS ()->GetBranch ("TOF");
322       if (branch) {
323         if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit",  1000);
324         branch->SetAddress (&fSDigits);
325       }
326     }
327
328   if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
329     {
330       branch = fLoader->TreeR()->GetBranch("TOF"); 
331       if (branch) 
332        {
333          branch->SetAddress(&fReconParticles) ;
334        }
335     }   
336 }
337
338 //_____________________________________________________________________________
339 void AliTOF::CreateGeometry()
340 {
341   //
342   // Common geometry code 
343   //
344   //Begin_Html
345   /*
346     <img src="picts/AliTOFv23.gif">
347   */
348   //End_Html
349   //
350   const Double_t kPi=TMath::Pi();
351   const Double_t kDegrad=kPi/180.;
352   //
353   Float_t xTof, yTof, wall;
354
355   // frame inbetween TOF modules
356   wall = 4.;//cm
357
358   // Sizes of TOF module with its support etc..
359   xTof = 2.*(AliTOFGeometry::Rmin()*TMath::Tan(10*kDegrad)-wall/2-.5);
360   yTof = AliTOFGeometry::Rmax()-AliTOFGeometry::Rmin();
361
362 //  TOF module internal definitions 
363   //TOFpc(xTof, yTof, fZlenC, fZlenB, fZlenA, AliTOFGeometry::MaxhZtof());
364   TOFpc(xTof, yTof, AliTOFGeometry::ZlenC(), AliTOFGeometry::ZlenB(), AliTOFGeometry::ZlenA(), AliTOFGeometry::MaxhZtof());
365 }
366
367 //_____________________________________________________________________________
368 void AliTOF::DrawModule() const
369 {
370   //
371   // Draw a shaded view of the common part of the TOF geometry
372   //
373
374    cout << " Drawing of AliTOF"<< endl; 
375   // Set everything unseen
376   gMC->Gsatt("*", "seen", -1);
377   // 
378   // Set ALIC mother transparent
379   gMC->Gsatt("ALIC","SEEN",0);
380   //
381   // Set the volumes visible
382   gMC->Gsatt("FTOA","SEEN",1);
383   gMC->Gsatt("FTOB","SEEN",1);
384   gMC->Gsatt("FTOC","SEEN",1);
385   gMC->Gsatt("FLTA","SEEN",1);
386   gMC->Gsatt("FLTB","SEEN",1);
387   gMC->Gsatt("FLTC","SEEN",1);
388   gMC->Gsatt("FSTR","SEEN",1);
389   //
390   gMC->Gdopt("hide", "on");
391   gMC->Gdopt("shad", "on");
392   gMC->Gsatt("*", "fill", 7);
393   gMC->SetClipBox(".");
394   gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
395   gMC->DefaultRange();
396   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
397   gMC->Gdhead(1111, "Time Of Flight");
398   gMC->Gdman(18, 4, "MAN");
399   gMC->Gdopt("hide","off");
400 }
401
402 //_____________________________________________________________________________
403 void AliTOF::CreateMaterials()
404 {
405   //
406   // Defines TOF materials for all versions
407   // Revision: F. Pierella 18-VI-2002
408   //
409
410   Int_t   isxfld = gAlice->Field()->Integ();
411   Float_t sxmgmx = gAlice->Field()->Max();
412   //
413   //--- Quartz (SiO2) to simulate float glass
414   //    density tuned to have correct float glass 
415   //    radiation length
416   Float_t   aq[2] = { 28.0855,15.9994 };
417   Float_t   zq[2] = { 14.,8. };
418   Float_t   wq[2] = { 1.,2. };
419   Float_t   dq = 2.55; // std value: 2.2
420   Int_t nq = -2;
421
422   // --- Freon C2F4H2 (TOF-TDR pagg.)
423   // Geant Manual CONS110-1, pag. 43 (Geant, Detector Description and Simulation Tool)
424   Float_t afre[3]  = {12.011,18.998,1.007};
425   Float_t zfre[3]  = { 6., 9., 1.}; 
426   Float_t wfre[3]  = { 2., 4., 2.};
427   Float_t densfre  = 0.00375;   
428 // http://www.fi.infn.it/sezione/prevprot/gas/freon.html
429   Int_t nfre = -3; 
430 /*
431   //-- Isobutane quencher C4H10 (5% in the sensitive mixture)
432   Float_t aiso[2]  = {12.011,1.007};
433   Float_t ziso[2]  = { 6.,  1.};
434   Float_t wiso[2]  = { 4., 10.};
435   Float_t densiso  = .......;  // (g/cm3) density
436   Int_t nfre = -2; // < 0 i.e. proportion by number of atoms of each kind
437   //-- SF6 (5% in the sensitive mixture)
438   Float_t asf[3]  = {32.066,18.998};
439   Float_t zsf[3]  = { 16., 9.};
440   Float_t wsf[3]  = {  1., 6.}; 
441   Float_t denssf  = .....;   // (g/cm3) density
442   Int_t nfre = -2; // < 0 i.e. proportion by number of atoms of each kind
443 */
444   // --- CO2 
445   Float_t ac[2]   = {12.,16.};
446   Float_t zc[2]   = { 6., 8.};
447   Float_t wc[2]   = { 1., 2.};
448   Float_t dc = .001977;
449   Int_t nc = -2;
450    // For mylar (C5H4O2) 
451   Float_t amy[3] = { 12., 1., 16. };
452   Float_t zmy[3] = {  6., 1.,  8. };
453   Float_t wmy[3] = {  5., 4.,  2. };
454   Float_t dmy    = 1.39;
455   Int_t nmy = -3;
456  // For polyethilene (CH2) - honeycomb -
457   Float_t ape[2] = { 12., 1. };
458   Float_t zpe[2] = {  6., 1. };
459   Float_t wpe[2] = {  1., 2. };
460   Float_t dpe    = 0.935*0.479; //To have 1%X0 for 1cm as for honeycomb
461   Int_t npe = -2;
462   // --- G10 
463   Float_t ag10[4] = { 12.,1.,16.,28. };
464   Float_t zg10[4] = {  6.,1., 8.,14. };
465   Float_t wmatg10[4] = { .259,.288,.248,.205 };
466   Float_t densg10  = 1.7;
467   Int_t nlmatg10 = -4;
468
469   // plexiglass CH2=C(CH3)CO2CH3
470   Float_t aplex[3] = { 12.,1.,16.};
471   Float_t zplex[3] = {  6.,1., 8.};
472   Float_t wmatplex[3] = {5.,8.,2.};
473   Float_t densplex  =1.16;
474   Int_t nplex = -3;
475
476   // ---- ALUMINA (AL203) 
477   Float_t aal[2] = { 27.,16.};
478   Float_t zal[2] = { 13., 8.};
479   Float_t wmatal[2] = { 2.,3. };
480   Float_t densal  = 2.3;
481   Int_t nlmatal = -2;
482   // -- Water
483   Float_t awa[2] = {  1., 16. };
484   Float_t zwa[2] = {  1.,  8. };
485   Float_t wwa[2] = {  2.,  1. };
486   Float_t dwa    = 1.0;
487   Int_t nwa = -2;
488
489 // stainless steel
490   Float_t asteel[4] = { 55.847,51.9961,58.6934,28.0855 };
491   Float_t zsteel[4] = { 26.,24.,28.,14. };
492   Float_t wsteel[4] = { .715,.18,.1,.005 };
493
494   //
495   //AliMaterial(0, "Vacuum$", 1e-16, 1e-16, 1e-16, 1e16, 1e16);
496   AliMaterial( 1, "Air$",14.61,7.3,0.001205,30423.24,67500.);
497   AliMaterial( 2, "Cu $",  63.54, 29.0, 8.96, 1.43, 14.8);
498   AliMaterial( 3, "C  $",  12.01,  6.0, 2.265,18.8, 74.4);
499   AliMixture ( 4, "Polyethilene$", ape, zpe, dpe, npe, wpe);
500   AliMixture ( 5, "G10$", ag10, zg10, densg10, nlmatg10, wmatg10);
501   AliMixture ( 6, "PLE$", aplex, zplex, densplex, nplex, wmatplex);
502   AliMixture ( 7, "CO2$", ac, zc, dc, nc, wc);
503   AliMixture ( 8, "ALUMINA$", aal, zal, densal, nlmatal, wmatal);
504   AliMaterial( 9, "Al $", 26.98, 13., 2.7, 8.9, 37.2);
505   AliMaterial(10, "C-TRD$", 12.01, 6., 2.265*18.8/69.282*15./100, 18.8, 74.4); // for 15%
506   AliMixture (11, "Mylar$",  amy, zmy, dmy, nmy, wmy);
507   AliMixture (12, "Freon$",  afre, zfre, densfre, nfre, wfre);
508   AliMixture (13, "Glass$", aq, zq, dq, nq, wq);
509   AliMixture (14, "Water$",  awa, zwa, dwa, nwa, wwa);
510   AliMixture (15, "STAINLESS STEEL$", asteel, zsteel, 7.88, 4, wsteel);
511
512   Float_t epsil, stmin, deemax, stemax;
513  
514   //   Previous data
515   //       EPSIL  =  0.1   ! Tracking precision, 
516   //       STEMAX = 0.1      ! Maximum displacement for multiple scattering
517   //       DEEMAX = 0.1    ! Maximum fractional energy loss, DLS 
518   //       STMIN  = 0.1 
519   //
520   //   New data  
521   epsil  = .001;  // Tracking precision,
522   stemax = -1.;   // Maximum displacement for multiple scattering
523   deemax = -.3;   // Maximum fractional energy loss, DLS
524   stmin  = -.8;
525
526   AliMedium( 1, "Air$"  ,  1, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
527   AliMedium( 2, "Cu $"  ,  2, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
528   AliMedium( 3, "C  $"  ,  3, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
529   AliMedium( 4, "Pol$"  ,  4, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
530   AliMedium( 5, "G10$"  ,  5, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
531   AliMedium( 6, "PLE$"  ,  6, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
532   AliMedium( 7, "CO2$"  ,  7, 0, isxfld, sxmgmx, 10., -.01, -.1, .01, -.01);
533   AliMedium( 8,"ALUMINA$", 8, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
534   AliMedium( 9,"Al Frame$",9, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
535   AliMedium(10, "DME-S$",  6, 1, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
536   AliMedium(11, "C-TRD$", 10, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
537   AliMedium(12, "Myl$"  , 11, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
538   AliMedium(13, "Fre$"  , 12, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
539   AliMedium(14, "Fre-S$", 12, 1, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
540   AliMedium(15, "Glass$", 13, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
541   AliMedium(16, "Water$", 14, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
542   AliMedium(17, "STEEL$", 15, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
543 }
544
545 //_____________________________________________________________________________
546 Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t ) const
547 {
548   //
549   // Returns distance from mouse pointer to detector, default version
550   //
551   return 9999;
552 }
553
554 //___________________________________________
555 void AliTOF::ResetHits ()
556 {
557   // Reset number of clusters and the cluster array for this detector
558   AliDetector::ResetHits ();
559 }
560
561 //____________________________________________
562 void AliTOF::ResetDigits ()
563 {
564   //
565   // Reset number of digits and the digits array for this detector
566   AliDetector::ResetDigits ();
567   //
568
569 //____________________________________________
570 void AliTOF::ResetSDigits ()
571 {
572   //
573   // Reset number of sdigits and the sdigits array for this detector
574   fNSDigits = 0;
575   //fSDigits = 0x0;
576   //
577
578 //_____________________________________________________________________________
579 void AliTOF::Init()
580 {
581   //
582   // Initialise TOF detector after it has been built
583   //
584   // Set id of TOF sensitive volume
585   if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
586   //
587 }
588
589 //____________________________________________________________________________
590 void AliTOF::MakeBranch(Option_t* option)
591 {
592  //
593  // Initializes the Branches of the TOF inside the 
594  // trees written for each event. 
595  // AliDetector::MakeBranch initializes just the 
596  // Branch inside TreeH. Here we add the branches in 
597  // TreeD, TreeS and TreeR.
598  //
599   const char *oH = strstr(option,"H");
600   if (fLoader->TreeH() && oH)
601    {
602      if (fHits == 0x0)
603       {
604         if (fTZero) fHits   = new TClonesArray("AliTOFhitT0", 1000);
605         else fHits   = new TClonesArray("AliTOFhit", 1000);
606       }
607    }
608   
609   AliDetector::MakeBranch(option);
610
611   Int_t buffersize = 4000;
612   Char_t branchname[10];
613   sprintf(branchname,"%s",GetName());
614   
615   const char *oD = strstr(option,"D");
616   const char *oS = strstr(option,"S");
617   const char *oR = strstr(option,"R");
618
619   if (fLoader->TreeD() && oD){
620     if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit",  1000); 
621     MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
622   }
623
624   if (fLoader->TreeS() && oS){
625     if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit",  1000);
626     MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
627   }
628
629   if (fReconParticles && fLoader->TreeR() && oR){
630     MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
631   }
632 }
633
634 //____________________________________________________________________________
635 void AliTOF::Makehits(Bool_t hits) 
636 {
637 // default argument used, see AliTOF.h
638 // Enable/Disable the writing of the TOF-hits branch 
639 // on TreeH
640 // by default : enabled for TOFv1, v2, v3, v4
641 //              disabled for TOFv0
642 // 
643    if (hits &&  (IsVersion()!=0))
644       fIdSens = gMC->VolId("FPAD");
645    else
646       cout << "Option for writing the TOF-hits branch on TreeH: disabled" << endl;
647 }
648
649 //____________________________________________________________________________
650 void AliTOF::FinishEvent()
651 {
652 // do nothing
653 }
654
655 //___________________________________________
656 void AliTOF::SDigits2Digits()
657 {
658 //
659 // Generate digits performing merging
660 //
661   /*
662     int nparticles = gAlice->GetNtrack();
663     cout << "Particles       :" <<nparticles<<endl;
664     if (nparticles > 0 ) {
665       
666       AliTOF::Hits2Digits();
667       
668     }
669   */
670   cout<<"AliTOF::SDigits2Digits"<<endl; 
671     if (fMerger) {
672       fMerger->Init();
673       cout<<"AliTOF::SDigits2Digits Init"<<endl; 
674       fMerger->Digitise();
675       cout<<"AliTOF::SDigits2Digits Digitise() "<<endl; 
676      }
677 }
678
679 //---------------------------------------------------------------------
680 void   AliTOF::SetMerger(AliTOFMerger* merger)
681 {
682 // Set pointer to merger
683     fMerger = merger;
684 }
685
686 //---------------------------------------------------------------------
687 AliTOFMerger*  AliTOF::Merger()
688 {
689 // Return pointer to merger
690     return fMerger;
691 }
692
693 //---------------------------------------------------------------------
694 void AliTOF::Hits2SDigits()
695 {
696 //
697 // Use the TOF SDigitizer to make TOF SDigits
698 //
699
700 //  cout<<"AliTOF::Hits2SDigits> start...\n";
701   
702   AliRunLoader * rl = fLoader->GetRunLoader();
703   AliTOFSDigitizer sd((rl->GetFileName()).Data());
704   if (GetDebug()) sd.Print("");
705
706   sd.Exec("") ;
707
708 }
709
710 //---------------------------------------------------------------------
711 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
712 {
713 //
714 // Use the TOF SDigitizer to make TOF SDigits
715 //
716
717   if ((evNumber2-evNumber1)==1) 
718       cout << "<AliTOF::Hits2SDigits>: I am making sdigits for the " << evNumber1 << "th event \n";
719   else if ((evNumber2-evNumber1)>1)
720       cout << "<AliTOF::Hits2SDigits>: I am making sdigits for the events from the " 
721            << evNumber1 << "th to the " << evNumber2-1 << "th \n";
722  
723   AliRunLoader * rl = fLoader->GetRunLoader();
724   AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
725   if (GetDebug()) sd.Print("");
726
727   sd.Exec("") ;
728
729 }
730
731 //___________________________________________________________________________
732 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
733 {
734   return new AliTOFDigitizer(manager);
735 }
736
737 //___________________________________________________________________________
738 Bool_t AliTOF::CheckOverlap(Int_t* vol, Float_t* digit,Int_t Track)
739 {
740 //
741 // Checks if 2 or more hits belong to the same pad.
742 // In this case the data assigned to the digit object
743 // are the ones of the first hit in order of Time.
744 // 2 hits from the same track on the same pad are collected.
745 // Called only by Hits2SDigits.
746 // This procedure has to be optimized in the next TOF release.
747 //
748
749         Bool_t overlap = kFALSE;
750         Int_t  vol2[5];
751
752         for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
753            AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
754            currentDigit->GetLocation(vol2);
755            Bool_t idem= kTRUE;
756            // check on digit volume
757            for (Int_t i=0;i<=4;i++){
758                if (!idem) break;
759                if (vol[i]!=vol2[i]) idem=kFALSE;}
760
761            if (idem){  // same pad fired
762               Float_t tdc2 = digit[0];
763               Float_t tdc1 = currentDigit->GetTdc();
764
765               // we separate two digits on the same pad if
766               // they are separated in time by at least 25 ns
767               // remember that tdc time is given in ps
768
769               if (TMath::Abs(tdc1-tdc2)<25000){
770                   // in case of overlap we take the earliest
771                   if (tdc1>tdc2){
772                    currentDigit->SetTdc(tdc2); 
773                    currentDigit->SetAdc(digit[1]);
774                   }
775                   else {
776                    currentDigit->SetTdc(tdc1);
777                    currentDigit->SetAdc(digit[1]);
778                   }
779                   currentDigit->AddTrack(Track); // add track number in the track array
780                   overlap = kTRUE;
781                   return overlap;
782               } else 
783                 overlap= kFALSE;
784
785            } // close if (idem) -> two digits on the same TOF pad
786
787         } // end loop on existing sdigits
788
789         return overlap;
790 }
791
792
793 //____________________________________________________________________________
794 void AliTOF::Digits2Raw()
795 {
796 //
797 // Starting from the TOF digits, writes the Raw Data objects
798 //
799
800   fLoader->LoadDigits();
801
802   TTree* digits = fLoader->TreeD();
803   if (!digits) {
804     Error("Digits2Raw", "no digits tree");
805     return;
806   }
807   
808   AliTOFDDLRawData rawWriter;
809   rawWriter.SetVerbose(0);
810   
811   Info("Digits2Raw", "Formatting raw data for TOF");
812   digits->GetEvent(0);
813   rawWriter.RawDataTOF(digits->GetBranch("TOF"));  
814
815   fLoader->UnloadDigits();
816   
817 }
818 ////////////////////////////////////////////////////////////////////////
819 void AliTOF::RecreateSDigitsArray() {
820 //
821 // delete TClonesArray fSDigits and create it again
822 //  needed for backward compatability with PPR test production
823 //
824   delete fSDigits;
825   fSDigits       = new TClonesArray("AliTOFSDigit",  1000);
826 }
827 ////////////////////////////////////////////////////////////////////////
828 void AliTOF::CreateSDigitsArray() {
829 //
830 // create TClonesArray fSDigits
831 //  needed for backward compatability with PPR test production
832 //
833   fSDigits       = new TClonesArray("AliTOFSDigit",  1000);
834 }
835