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