1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
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 //
25 // VERSIONE WITH 5 SYMMETRIC MODULES ALONG Z AXIS //
26 // ============================================================ //
28 // VERSION WITH HOLES FOR PHOS AND TRD IN SPACEFRAME WITH HOLES //
30 // Volume sensibile : FPAD //
35 ///////////////////////////////////////////////////////////////////////////////
38 <img src="picts/AliTOFClass.gif">
42 #include <TClonesArray.h>
48 #include <TVirtualMC.h>
51 #include "AliLoader.h"
56 #include "AliTOFDDLRawData.h"
57 #include "AliTOFDigitizer.h"
58 #include "AliTOFdigit.h"
59 #include "AliTOFhitT0.h"
60 #include "AliTOFhit.h"
61 #include "AliTOFGeometry.h"
62 #include "AliTOFSDigitizer.h"
63 #include "AliTOFSDigit.h"
70 extern TVirtualMC *gMC;
72 extern AliRun *gAlice;
77 //_____________________________________________________________________________
90 // Default constructor
97 //_____________________________________________________________________________
98 AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
100 AliDetector(name,title),
106 fReconParticles(0x0),
112 // AliTOF standard constructor
114 // Here are fixed some important parameters
117 // Initialization of hits, sdigits and digits array
118 // added option for time zero analysis
120 fTOFGeometry = new AliTOFGeometry();
122 if (strstr(option,"tzero")){
123 fHits = new TClonesArray("AliTOFhitT0", 1000);
125 // AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
127 fHits = new TClonesArray("AliTOFhit", 1000);
131 AliFatal("gAlice==0 !");
134 AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
136 if (mcApplication->GetHitLists())
137 mcApplication->AddHitList(fHits);
138 else AliError("gAlice->GetHitLists()==0");
141 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
142 fDigits = new TClonesArray("AliTOFdigit", 1000);
145 // Digitization parameters
147 // (Transfer Functions to be inserted here)
149 //PH SetMarkerColor(7);
150 //PH SetMarkerStyle(2);
151 //PH SetMarkerSize(0.4);
154 //fGapA = 4.; //cm Gap beetween tilted strip in A-type plate
155 //fGapB = 6.; //cm Gap beetween tilted strip in B-type plate
157 // Physical performances
158 //fTimeRes = 100.;//ps
159 //fChrgRes = 100.;//pC
163 //____________________________________________________________________________
164 void AliTOF::SetTOFSectors(Int_t *sectors)
166 // Setter for partial/full TOF configuration
168 for(Int_t isec=0;isec<18;isec++){
169 fTOFSectors[isec]=sectors[isec];
172 //____________________________________________________________________________
173 void AliTOF::GetTOFSectors(Int_t *sectors) const
175 // Getter for partial/full TOF configuration
177 for(Int_t isec=0;isec<18;isec++){
178 sectors[isec]=fTOFSectors[isec];
181 //_____________________________________________________________________________
182 AliTOF::AliTOF(const AliTOF &source)
189 fReconParticles(0x0),
196 this->fReconParticles=source.fReconParticles;
197 this->fSDigits=source.fSDigits;
198 this->fTOFGeometry=source.fTOFGeometry;
202 //_____________________________________________________________________________
203 AliTOF& AliTOF::operator=(const AliTOF &source)
207 this->fReconParticles=source.fReconParticles;
208 this->fSDigits=source.fSDigits;
209 this->fTOFGeometry=source.fTOFGeometry;
214 //_____________________________________________________________________________
215 void AliTOF::CreateTOFFolders()
217 // create the ALICE TFolder
218 // create the ALICE TTasks
219 // create the ALICE main TFolder
220 // to be done by AliRun
222 TFolder * alice = new TFolder();
223 alice->SetNameTitle("FPAlice", "Alice Folder") ;
224 gROOT->GetListOfBrowsables()->Add(alice) ;
226 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
227 // make it the owner of the objects that it contains
230 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
231 TFolder * aliceT = alice->AddFolder("tasks", "Alice tasks Folder") ;
232 // make it the owner of the objects that it contains
235 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
236 aliceT->Add(aliceDi);
238 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
239 aliceT->Add(aliceRe);
241 char * tempo = new char[80] ;
243 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
244 sprintf(tempo, "%sDigitizers container",GetName() ) ;
245 fDTask = new TTask(GetName(), tempo);
246 aliceDi->Add(fDTask) ;
248 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
249 sprintf(tempo, "%sReconstructioner container",GetName() ) ;
250 fReTask = new TTask(GetName(), tempo);
251 aliceRe->Add(fReTask) ;
255 // creates the TOF geometry folder
256 geomF->AddFolder("TOF", "Geometry for TOF") ;
259 //_____________________________________________________________________________
263 // it remove also the alice folder
264 // and task that TOF creates instead of AliRun
265 /* PH Temporarily commented because of problems
266 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
291 fReconParticles->Delete ();
292 delete fReconParticles;
298 //_____________________________________________________________________________
299 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
303 // new with placement used
305 TClonesArray &lhits = *fHits;
306 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
309 //_____________________________________________________________________________
310 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
314 // new with placement used
316 TClonesArray &lhits = *fHits;
317 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
320 //_____________________________________________________________________________
321 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Float_t *digits)
325 // new with placement used
327 TClonesArray &ldigits = *fDigits;
328 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
331 //_____________________________________________________________________________
332 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Float_t *digits)
339 TClonesArray &lSDigits = *fSDigits;
340 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
343 //_____________________________________________________________________________
344 void AliTOF::SetTreeAddress ()
346 // Set branch address for the Hits and Digits Tree.
348 if (fLoader->TreeH())
352 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
353 else fHits = new TClonesArray("AliTOFhit", 1000);
356 AliDetector::SetTreeAddress ();
360 if (fLoader->TreeS () )
362 branch = fLoader->TreeS ()->GetBranch ("TOF");
364 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
365 branch->SetAddress (&fSDigits);
369 if (fLoader->TreeR() )
371 branch = fLoader->TreeR()->GetBranch("TOF");
374 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
375 branch->SetAddress(&fReconParticles);
380 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
382 branch = fLoader->TreeR()->GetBranch("TOF");
385 branch->SetAddress(&fReconParticles) ;
391 //_____________________________________________________________________________
392 void AliTOF::CreateGeometry()
395 // Common geometry code
399 <img src="picts/AliTOFv23.gif">
406 if (IsVersion()==7) {
408 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
409 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
410 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
412 // TOF module internal definitions
413 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
417 Float_t wall = 4.;//cm // frame inbetween TOF modules
419 // Sizes of TOF module with its support etc..
420 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
421 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
423 // TOF module internal definitions
424 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
429 //_____________________________________________________________________________
430 void AliTOF::DrawModule() const
433 // Draw a shaded view of the common part of the TOF geometry
436 AliInfo(" Drawing of AliTOF");
437 // Set everything unseen
438 gMC->Gsatt("*", "seen", -1);
440 // Set ALIC mother transparent
441 gMC->Gsatt("ALIC","SEEN",0);
443 // Set the volumes visible
444 gMC->Gsatt("FTOA","SEEN",1);
445 gMC->Gsatt("FTOB","SEEN",1);
446 gMC->Gsatt("FTOC","SEEN",1);
447 gMC->Gsatt("FLTA","SEEN",1);
448 gMC->Gsatt("FLTB","SEEN",1);
449 gMC->Gsatt("FLTC","SEEN",1);
450 gMC->Gsatt("FSTR","SEEN",1);
452 gMC->Gdopt("hide", "on");
453 gMC->Gdopt("shad", "on");
454 gMC->Gsatt("*", "fill", 7);
455 gMC->SetClipBox(".");
456 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
458 gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
459 gMC->Gdhead(1111, "Time Of Flight");
460 gMC->Gdman(18, 4, "MAN");
461 gMC->Gdopt("hide","off");
464 //_____________________________________________________________________________
465 Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t )
468 // Returns distance from mouse pointer to detector, default version
473 //___________________________________________
474 void AliTOF::ResetHits ()
476 // Reset number of clusters and the cluster array for this detector
477 AliDetector::ResetHits ();
480 //____________________________________________
481 void AliTOF::ResetDigits ()
484 // Reset number of digits and the digits array for this detector
485 AliDetector::ResetDigits ();
488 //____________________________________________
489 void AliTOF::ResetSDigits ()
492 // Reset number of sdigits and the sdigits array for this detector
497 //_____________________________________________________________________________
501 // Initialise TOF detector after it has been built
503 // Set id of TOF sensitive volume
504 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
508 TDirectory* saveDir = gDirectory;
509 gAlice->GetRunLoader()->CdGAFile();
510 fTOFGeometry->Write("TOFGeometry");
515 //____________________________________________________________________________
516 void AliTOF::MakeBranch(Option_t* option)
519 // Initializes the Branches of the TOF inside the
520 // trees written for each event.
521 // AliDetector::MakeBranch initializes just the
522 // Branch inside TreeH. Here we add the branches in
523 // TreeD, TreeS and TreeR.
525 const char *oH = strstr(option,"H");
526 if (fLoader->TreeH() && oH)
530 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
531 else fHits = new TClonesArray("AliTOFhit", 1000);
535 AliDetector::MakeBranch(option);
537 Int_t buffersize = 4000;
538 Char_t branchname[10];
539 sprintf(branchname,"%s",GetName());
541 const char *oD = strstr(option,"D");
542 const char *oS = strstr(option,"S");
543 const char *oR = strstr(option,"R");
545 if (fLoader->TreeD() && oD){
546 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
547 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
550 if (fLoader->TreeS() && oS){
551 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
552 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
555 if (fLoader->TreeR() && oR){
556 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
557 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
561 if (fReconParticles && fLoader->TreeR() && oR){
562 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
567 //____________________________________________________________________________
568 void AliTOF::Makehits(Bool_t hits)
570 // default argument used, see AliTOF.h
571 // Enable/Disable the writing of the TOF-hits branch
573 // by default : enabled for TOFv1, v2, v3, v4, v5
574 // disabled for TOFv0
576 if (hits && (IsVersion()!=0))
577 fIdSens = gMC->VolId("FPAD");
579 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
582 //____________________________________________________________________________
583 void AliTOF::FinishEvent()
588 //____________________________________________________________________________
589 void AliTOF::Hits2SDigits()
592 // Use the TOF SDigitizer to make TOF SDigits
595 // AliInfo("Start...");
597 AliRunLoader * rl = fLoader->GetRunLoader();
598 AliTOFSDigitizer sd((rl->GetFileName()).Data());
599 ToAliDebug(1, sd.Print(""));
605 //____________________________________________________________________________
606 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
609 // Use the TOF SDigitizer to make TOF SDigits
612 if ((evNumber2-evNumber1)==1)
613 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
614 if ((evNumber2-evNumber1)>1)
615 AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
617 AliRunLoader * rl = fLoader->GetRunLoader();
618 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
619 ToAliDebug(1, sd.Print(""));
625 //___________________________________________________________________________
626 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
628 return new AliTOFDigitizer(manager);
631 //___________________________________________________________________________
632 Bool_t AliTOF::CheckOverlap(Int_t* vol, Float_t* digit,Int_t Track)
635 // Checks if 2 or more hits belong to the same pad.
636 // In this case the data assigned to the digit object
637 // are the ones of the first hit in order of Time.
638 // 2 hits from the same track on the same pad are collected.
639 // Called only by Hits2SDigits.
640 // This procedure has to be optimized in the next TOF release.
643 Bool_t overlap = kFALSE;
646 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
647 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
648 currentDigit->GetLocation(vol2);
650 // check on digit volume
651 for (Int_t i=0;i<=4;i++){
653 if (vol[i]!=vol2[i]) idem=kFALSE;}
655 if (idem){ // same pad fired
656 Float_t tdc2 = digit[0];
657 Float_t tdc1 = currentDigit->GetTdc();
659 // we separate two digits on the same pad if
660 // they are separated in time by at least 25 ns
661 // remember that tdc time is given in ps
663 if (TMath::Abs(tdc1-tdc2)<25000){
664 // in case of overlap we take the earliest
666 currentDigit->SetTdc(tdc2);
667 currentDigit->SetAdc(digit[1]);
670 currentDigit->SetTdc(tdc1);
671 currentDigit->SetAdc(digit[1]);
673 currentDigit->AddTrack(Track); // add track number in the track array
679 } // close if (idem) -> two digits on the same TOF pad
681 } // end loop on existing sdigits
685 //____________________________________________________________________________
686 void AliTOF::Digits2Raw()
689 // Starting from the TOF digits, writes the Raw Data objects
692 fLoader->LoadDigits();
694 TTree* digits = fLoader->TreeD();
696 AliError("no digits tree");
700 //AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(),"read");
701 fRunLoader->CdGAFile();
702 TFile *in=(TFile*)gFile;
704 AliTOFGeometry *geometry = (AliTOFGeometry*)in->Get("TOFgeometry");
706 AliTOFDDLRawData rawWriter(geometry);
707 //AliTOFDDLRawData rawWriter;
708 rawWriter.SetVerbose(0);
709 //rawWriter.SetAcquisitionMode(kFALSE);
711 AliDebug(1,"Formatting raw data for TOF");
713 rawWriter.RawDataTOF(digits->GetBranch("TOF"));
715 fLoader->UnloadDigits();
719 //____________________________________________________________________________
720 void AliTOF::RecreateSDigitsArray() {
722 // delete TClonesArray fSDigits and create it again
723 // needed for backward compatability with PPR test production
726 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
728 //____________________________________________________________________________
729 void AliTOF::CreateSDigitsArray() {
731 // create TClonesArray fSDigits
732 // needed for backward compatability with PPR test production
734 fSDigits = new TClonesArray("AliTOFSDigit", 1000);