]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOF.cxx
Possibility for partial TOF geometry (S.Arcelli)
[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 //                                                                           //
35 ///////////////////////////////////////////////////////////////////////////////
36 // Begin_Html
37 /*
38 <img src="picts/AliTOFClass.gif">
39 */
40 //End_Html
41
42 #include "TFile.h"
43 #include "TFolder.h"
44 #include "TROOT.h"
45 #include "TTask.h"
46 #include "TTree.h"
47 #include "TVirtualMC.h"
48
49 #include "AliConst.h"
50 #include "AliLoader.h"
51 #include "AliLog.h"
52 #include "AliMC.h"
53 #include "AliRun.h"
54
55 #include "AliTOFDDLRawData.h"
56 #include "AliTOFDigitizer.h"
57 #include "AliTOFdigit.h"
58 #include "AliTOFhitT0.h"
59 #include "AliTOFhit.h"
60 #include "AliTOFGeometry.h"
61 #include "AliTOFSDigitizer.h"
62 #include "AliTOFSDigit.h"
63 #include "AliTOF.h"
64
65 class AliTOFcluster;
66
67 extern TFile *gFile;
68 extern TROOT *gROOT;
69 extern TVirtualMC *gMC;
70
71 extern AliRun *gAlice;
72
73  
74 ClassImp(AliTOF)
75  
76 //_____________________________________________________________________________
77 AliTOF::AliTOF()
78 {
79   //
80   // Default constructor
81   //
82   fFGeom  = 0x0;
83   fDTask  = 0x0;
84   fReTask = 0x0;
85   fIshunt   = 0;
86   fSDigits  = 0 ;
87   fNSDigits = 0;
88   fDigits   = 0 ;
89   fReconParticles = 0x0;
90   fName="TOF";
91   fTZero  = kFALSE;
92   fTOFGeometry = 0;
93 }
94  
95 //_____________________________________________________________________________
96 AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
97        : AliDetector(name,title)
98 {
99   //
100   // AliTOF standard constructor
101   // 
102   // Here are fixed some important parameters
103   //
104
105   // Initialization of hits, sdigits and digits array
106   // added option for time zero analysis
107   fFGeom  = 0x0; //skowron
108   fDTask  = 0x0;
109   fReTask = 0x0;
110   fReconParticles= 0x0;
111   fTOFGeometry = new AliTOFGeometry();
112
113   if (strstr(option,"tzero")){
114     fHits   = new TClonesArray("AliTOFhitT0",  1000);
115     fTZero = kTRUE;
116     AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
117   }else{
118     fHits   = new TClonesArray("AliTOFhit",  1000);
119     fTZero = kFALSE;
120   }
121   if (gAlice==0) {
122      AliFatal("gAlice==0 !");
123   }
124
125   AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
126
127   if (mcApplication->GetHitLists())
128      mcApplication->AddHitList(fHits);
129   else AliError("gAlice->GetHitLists()==0");
130
131   fIshunt  = 0;
132   fSDigits = new TClonesArray("AliTOFSDigit", 1000);
133   fDigits  = new TClonesArray("AliTOFdigit",  1000);
134   fNSDigits = 0;
135
136   fFGeom = 0x0;
137   fDTask = 0x0;
138   fReTask = 0x0;
139   fReconParticles = 0x0;
140
141   //
142   // Digitization parameters
143   //
144   // (Transfer Functions to be inserted here)
145   //
146   SetMarkerColor(7);
147   SetMarkerStyle(2);
148   SetMarkerSize(0.4);
149
150 // Strip Parameters
151   //fGapA    =   4.; //cm  Gap beetween tilted strip in A-type plate
152   //fGapB    =   6.; //cm  Gap beetween tilted strip in B-type plate
153
154   // Physical performances
155   //fTimeRes = 100.;//ps
156   //fChrgRes = 100.;//pC
157
158 }
159
160 //____________________________________________________________________________
161 void AliTOF::SetTOFSectors(Int_t *sectors){
162   for(Int_t isec=0;isec<18;isec++){
163     fTOFSectors[isec]=sectors[isec];
164   }
165 }
166 //____________________________________________________________________________
167 void AliTOF::GetTOFSectors(Int_t *sectors) const {
168
169   for(Int_t isec=0;isec<18;isec++){
170     sectors[isec]=fTOFSectors[isec];
171   }
172 }
173 //_____________________________________________________________________________
174 AliTOF::AliTOF(const AliTOF &source)
175   :AliDetector()
176 {
177   // copy constructor
178
179   this->fReconParticles=source.fReconParticles;
180   this->fSDigits=source.fSDigits;
181   this->fTOFGeometry=source.fTOFGeometry;
182
183 }
184
185 //_____________________________________________________________________________
186 AliTOF& AliTOF::operator=(const AliTOF &source)
187 {
188   // ass. op.
189
190   this->fReconParticles=source.fReconParticles;
191   this->fSDigits=source.fSDigits;
192   this->fTOFGeometry=source.fTOFGeometry;
193   return *this;
194
195 }
196
197 //_____________________________________________________________________________
198 void AliTOF::CreateTOFFolders()
199 {
200   // create the ALICE TFolder
201   // create the ALICE TTasks
202   // create the ALICE main TFolder
203   // to be done by AliRun
204
205   TFolder * alice = new TFolder();
206   alice->SetNameTitle("FPAlice", "Alice Folder") ;
207   gROOT->GetListOfBrowsables()->Add(alice) ;
208
209   TFolder * aliceF  = alice->AddFolder("folders", "Alice memory Folder") ;
210   //  make it the owner of the objects that it contains
211   aliceF->SetOwner() ;
212   // geometry folder
213   TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
214   TFolder * aliceT  = alice->AddFolder("tasks", "Alice tasks Folder") ;   
215   //  make it the owner of the objects that it contains
216   aliceT->SetOwner() ;
217
218   TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
219   aliceT->Add(aliceDi);
220
221   TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
222   aliceT->Add(aliceRe);
223
224   char * tempo = new char[80] ;
225
226   // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
227   sprintf(tempo, "%sDigitizers container",GetName() ) ;
228   fDTask = new TTask(GetName(), tempo);
229   aliceDi->Add(fDTask) ;
230
231   // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
232   sprintf(tempo, "%sReconstructioner container",GetName() ) ;
233   fReTask = new TTask(GetName(), tempo);
234   aliceRe->Add(fReTask) ;
235
236   delete [] tempo ;
237  
238   // creates the TOF geometry  folder
239   geomF->AddFolder("TOF", "Geometry for TOF") ;
240 }
241
242 //_____________________________________________________________________________
243 AliTOF::~AliTOF()
244 {
245   // dtor:
246   // it remove also the alice folder 
247   // and task that TOF creates instead of AliRun
248   /* PH Temporarily commented because of problems
249   TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
250   delete alice;
251   alice = 0;
252   */
253   if (fHits)
254     {
255       fHits->Delete ();
256       delete fHits;
257       fHits = 0;
258     }
259   if (fDigits)
260     {
261       fDigits->Delete ();
262       delete fDigits;
263       fDigits = 0;
264     }
265   if (fSDigits)
266     {
267       fSDigits->Delete();
268       delete fSDigits;
269       fSDigits = 0;
270     }
271
272   if (fReconParticles)
273     {
274       fReconParticles->Delete ();
275       delete fReconParticles;
276       fReconParticles = 0;
277     }
278
279 }
280
281 //_____________________________________________________________________________
282 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
283 {
284   //
285   // Add a TOF hit
286   // new with placement used
287   //
288   TClonesArray &lhits = *fHits;
289   new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
290 }
291
292 //_____________________________________________________________________________
293 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
294 {
295   //
296   // Add a TOF hit
297   // new with placement used
298   //
299   TClonesArray &lhits = *fHits;
300   new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
301 }
302
303 //_____________________________________________________________________________
304 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Float_t *digits)
305 {
306   //
307   // Add a TOF digit
308   // new with placement used
309   //
310   TClonesArray &ldigits = *fDigits;
311   new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
312 }
313
314 //_____________________________________________________________________________
315 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Float_t *digits)
316 {
317      
318 //
319 // Add a TOF sdigit
320 //
321         
322   TClonesArray &lSDigits = *fSDigits;   
323   new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
324 }
325
326 //_____________________________________________________________________________
327 void AliTOF::SetTreeAddress ()
328 {
329   // Set branch address for the Hits and Digits Tree.
330   
331   if (fLoader->TreeH())
332    {
333      if (fHits == 0x0)
334       {
335         if (fTZero) fHits   = new TClonesArray("AliTOFhitT0", 1000);
336         else fHits   = new TClonesArray("AliTOFhit", 1000);
337       }
338    }
339   AliDetector::SetTreeAddress ();
340
341   TBranch *branch;
342
343   if (fLoader->TreeS () )
344     {
345       branch = fLoader->TreeS ()->GetBranch ("TOF");
346       if (branch) {
347         if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit",  1000);
348         branch->SetAddress (&fSDigits);
349       }
350     }
351
352   if (fLoader->TreeR() ) 
353     {
354       branch = fLoader->TreeR()->GetBranch("TOF"); 
355       if (branch) 
356        {
357          if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster",  1000);
358          branch->SetAddress(&fReconParticles);
359        }
360     }
361
362   /*
363   if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
364     {
365       branch = fLoader->TreeR()->GetBranch("TOF"); 
366       if (branch) 
367        {
368          branch->SetAddress(&fReconParticles) ;
369        }
370     }
371   */
372 }
373
374 //_____________________________________________________________________________
375 void AliTOF::CreateGeometry()
376 {
377   //
378   // Common geometry code 
379   //
380   //Begin_Html
381   /*
382     <img src="picts/AliTOFv23.gif">
383   */
384   //End_Html
385   //
386
387   Float_t xTof, yTof;
388
389   if (IsVersion()==7) {
390
391     xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm,  x-dimension of FTOA volume
392     yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm,  y-dimension of FTOA volume
393     Float_t zTof = fTOFGeometry->ZlenA();             // cm,  z-dimension of FTOA volume
394     
395     //  TOF module internal definitions
396     TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
397
398   } else {
399
400     Float_t wall = 4.;//cm // frame inbetween TOF modules
401
402     // Sizes of TOF module with its support etc..
403     xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
404     yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
405
406     //  TOF module internal definitions 
407     TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
408   }
409
410 }
411
412 //_____________________________________________________________________________
413 void AliTOF::DrawModule() const
414 {
415   //
416   // Draw a shaded view of the common part of the TOF geometry
417   //
418
419   AliInfo(" Drawing of AliTOF"); 
420   // Set everything unseen
421   gMC->Gsatt("*", "seen", -1);
422   // 
423   // Set ALIC mother transparent
424   gMC->Gsatt("ALIC","SEEN",0);
425   //
426   // Set the volumes visible
427   gMC->Gsatt("FTOA","SEEN",1);
428   gMC->Gsatt("FTOB","SEEN",1);
429   gMC->Gsatt("FTOC","SEEN",1);
430   gMC->Gsatt("FLTA","SEEN",1);
431   gMC->Gsatt("FLTB","SEEN",1);
432   gMC->Gsatt("FLTC","SEEN",1);
433   gMC->Gsatt("FSTR","SEEN",1);
434   //
435   gMC->Gdopt("hide", "on");
436   gMC->Gdopt("shad", "on");
437   gMC->Gsatt("*", "fill", 7);
438   gMC->SetClipBox(".");
439   gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
440   gMC->DefaultRange();
441   gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
442   gMC->Gdhead(1111, "Time Of Flight");
443   gMC->Gdman(18, 4, "MAN");
444   gMC->Gdopt("hide","off");
445 }
446
447 //_____________________________________________________________________________
448 Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t )
449 {
450   //
451   // Returns distance from mouse pointer to detector, default version
452   //
453   return 9999;
454 }
455
456 //___________________________________________
457 void AliTOF::ResetHits ()
458 {
459   // Reset number of clusters and the cluster array for this detector
460   AliDetector::ResetHits ();
461 }
462
463 //____________________________________________
464 void AliTOF::ResetDigits ()
465 {
466   //
467   // Reset number of digits and the digits array for this detector
468   AliDetector::ResetDigits ();
469   //
470
471 //____________________________________________
472 void AliTOF::ResetSDigits ()
473 {
474   //
475   // Reset number of sdigits and the sdigits array for this detector
476   fNSDigits = 0;
477   //fSDigits = 0x0;
478   //
479
480 //_____________________________________________________________________________
481 void AliTOF::Init()
482 {
483   //
484   // Initialise TOF detector after it has been built
485   //
486   // Set id of TOF sensitive volume
487   if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
488
489   /*
490   // Save the geometry
491   TDirectory* saveDir = gDirectory;
492   gAlice->GetRunLoader()->CdGAFile();
493   fTOFGeometry->Write("TOFGeometry");
494   saveDir->cd();
495   */
496 }
497
498 //____________________________________________________________________________
499 void AliTOF::MakeBranch(Option_t* option)
500 {
501  //
502  // Initializes the Branches of the TOF inside the 
503  // trees written for each event. 
504  // AliDetector::MakeBranch initializes just the 
505  // Branch inside TreeH. Here we add the branches in 
506  // TreeD, TreeS and TreeR.
507  //
508   const char *oH = strstr(option,"H");
509   if (fLoader->TreeH() && oH)
510    {
511      if (fHits == 0x0)
512       {
513         if (fTZero) fHits   = new TClonesArray("AliTOFhitT0", 1000);
514         else fHits   = new TClonesArray("AliTOFhit", 1000);
515       }
516    }
517   
518   AliDetector::MakeBranch(option);
519
520   Int_t buffersize = 4000;
521   Char_t branchname[10];
522   sprintf(branchname,"%s",GetName());
523   
524   const char *oD = strstr(option,"D");
525   const char *oS = strstr(option,"S");
526   const char *oR = strstr(option,"R");
527
528   if (fLoader->TreeD() && oD){
529     if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit",  1000); 
530     MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
531   }
532
533   if (fLoader->TreeS() && oS){
534     if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit",  1000);
535     MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
536   }
537
538   if (fLoader->TreeR() && oR){
539     if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster",  1000);
540     MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
541   }
542
543   /*
544   if (fReconParticles && fLoader->TreeR() && oR){
545     MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
546   }
547   */
548 }
549
550 //____________________________________________________________________________
551 void AliTOF::Makehits(Bool_t hits) 
552 {
553 // default argument used, see AliTOF.h
554 // Enable/Disable the writing of the TOF-hits branch 
555 // on TreeH
556 // by default :  enabled for TOFv1, v2, v3, v4, v5
557 //              disabled for TOFv0
558 // 
559    if (hits &&  (IsVersion()!=0))
560       fIdSens = gMC->VolId("FPAD");
561    else
562       AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
563 }
564
565 //____________________________________________________________________________
566 void AliTOF::FinishEvent()
567 {
568 // do nothing
569 }
570
571 //____________________________________________________________________________
572 void AliTOF::Hits2SDigits()
573 {
574 //
575 // Use the TOF SDigitizer to make TOF SDigits
576 //
577
578 //  AliInfo("Start...");
579   
580   AliRunLoader * rl = fLoader->GetRunLoader();
581   AliTOFSDigitizer sd((rl->GetFileName()).Data());
582   ToAliDebug(1, sd.Print(""));
583
584   sd.Exec("") ;
585
586 }
587
588 //____________________________________________________________________________
589 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
590 {
591 //
592 // Use the TOF SDigitizer to make TOF SDigits
593 //
594
595   if ((evNumber2-evNumber1)==1) 
596       AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1))
597   else if ((evNumber2-evNumber1)>1)
598       AliDebug(1, Form("I am making sdigits for the events from the " 
599                        "%dth to the %dth", evNumber1, evNumber2-1));
600  
601   AliRunLoader * rl = fLoader->GetRunLoader();
602   AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
603   ToAliDebug(1, sd.Print(""));
604
605   sd.Exec("") ;
606
607 }
608
609 //___________________________________________________________________________
610 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
611 {
612   return new AliTOFDigitizer(manager);
613 }
614
615 //___________________________________________________________________________
616 Bool_t AliTOF::CheckOverlap(Int_t* vol, Float_t* digit,Int_t Track)
617 {
618 //
619 // Checks if 2 or more hits belong to the same pad.
620 // In this case the data assigned to the digit object
621 // are the ones of the first hit in order of Time.
622 // 2 hits from the same track on the same pad are collected.
623 // Called only by Hits2SDigits.
624 // This procedure has to be optimized in the next TOF release.
625 //
626
627   Bool_t overlap = kFALSE;
628   Int_t  vol2[5];
629
630   for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
631     AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
632     currentDigit->GetLocation(vol2);
633     Bool_t idem= kTRUE;
634     // check on digit volume
635     for (Int_t i=0;i<=4;i++){
636       if (!idem) break;
637       if (vol[i]!=vol2[i]) idem=kFALSE;}
638
639     if (idem){  // same pad fired
640       Float_t tdc2 = digit[0];
641       Float_t tdc1 = currentDigit->GetTdc();
642
643       // we separate two digits on the same pad if
644       // they are separated in time by at least 25 ns
645       // remember that tdc time is given in ps
646
647       if (TMath::Abs(tdc1-tdc2)<25000){
648         // in case of overlap we take the earliest
649         if (tdc1>tdc2){
650           currentDigit->SetTdc(tdc2); 
651           currentDigit->SetAdc(digit[1]);
652         }
653         else {
654           currentDigit->SetTdc(tdc1);
655           currentDigit->SetAdc(digit[1]);
656         }
657         currentDigit->AddTrack(Track); // add track number in the track array
658         overlap = kTRUE;
659         return overlap;
660       } else 
661                 overlap= kFALSE;
662
663     } // close if (idem) -> two digits on the same TOF pad
664
665   } // end loop on existing sdigits
666
667   return overlap;
668 }
669 //____________________________________________________________________________
670 void AliTOF::Digits2Raw()
671 {
672 //
673 // Starting from the TOF digits, writes the Raw Data objects
674 //
675
676   fLoader->LoadDigits();
677
678   TTree* digits = fLoader->TreeD();
679   if (!digits) {
680     AliError("no digits tree");
681     return;
682   }
683   
684   //AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(),"read");
685   fRunLoader->CdGAFile();
686   TFile *in=(TFile*)gFile;
687   in->cd();
688   AliTOFGeometry *geometry  = (AliTOFGeometry*)in->Get("TOFgeometry");
689
690   AliTOFDDLRawData rawWriter(geometry);
691   //AliTOFDDLRawData rawWriter;
692   rawWriter.SetVerbose(0);
693   
694   AliInfo("Formatting raw data for TOF");
695   digits->GetEvent(0);
696   rawWriter.RawDataTOF(digits->GetBranch("TOF"));  
697
698   fLoader->UnloadDigits();
699   
700 }
701
702 //____________________________________________________________________________
703 void AliTOF::RecreateSDigitsArray() {
704 //
705 // delete TClonesArray fSDigits and create it again
706 //  needed for backward compatability with PPR test production
707 //
708   delete fSDigits;
709   fSDigits       = new TClonesArray("AliTOFSDigit",  1000);
710 }
711 //____________________________________________________________________________
712 void AliTOF::CreateSDigitsArray() {
713 //
714 // create TClonesArray fSDigits
715 //  needed for backward compatability with PPR test production
716 //
717   fSDigits       = new TClonesArray("AliTOFSDigit",  1000);
718 }