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">
44 #include <Riostream.h>
45 #include <Rstrstream.h>
57 #include <TVirtualMC.h>
58 #include <TDirectory.h>
61 #include "AliConfig.h"
62 #include "AliHeader.h"
64 #include "AliLoader.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"
76 #include "AliTOFDigitizer.h"
77 #include "AliTOFDDLRawData.h"
78 #include "AliTOFcluster.h"
82 //_____________________________________________________________________________
86 // Default constructor
95 fReconParticles = 0x0;
101 //_____________________________________________________________________________
102 AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
103 : AliDetector(name,title)
106 // AliTOF standard constructor
108 // Here are fixed some important parameters
111 // Initialization of hits, sdigits and digits array
112 // added option for time zero analysis
113 fFGeom = 0x0; //skowron
116 fReconParticles= 0x0;
117 fTOFGeometry = new AliTOFGeometry();
119 if (strstr(option,"tzero")){
120 fHits = new TClonesArray("AliTOFhitT0", 1000);
122 AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
124 fHits = new TClonesArray("AliTOFhit", 1000);
128 AliFatal("gAlice==0 !");
130 if (gAlice->GetMCApp()->GetHitLists())
131 gAlice->GetMCApp()->AddHitList(fHits);
132 else AliError("gAlice->GetHitLists()==0");
135 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
136 fDigits = new TClonesArray("AliTOFdigit", 1000);
142 fReconParticles = 0x0;
145 // Digitization parameters
147 // (Transfer Functions to be inserted here)
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::CreateTOFFolders()
166 // create the ALICE TFolder
167 // create the ALICE TTasks
168 // create the ALICE main TFolder
169 // to be done by AliRun
171 TFolder * alice = new TFolder();
172 alice->SetNameTitle("FPAlice", "Alice Folder") ;
173 gROOT->GetListOfBrowsables()->Add(alice) ;
175 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
176 // make it the owner of the objects that it contains
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
184 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
185 aliceT->Add(aliceDi);
187 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
188 aliceT->Add(aliceRe);
190 char * tempo = new char[80] ;
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) ;
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) ;
204 // creates the TOF geometry folder
205 geomF->AddFolder("TOF", "Geometry for TOF") ;
208 //_____________________________________________________________________________
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") ;
240 fReconParticles->Delete ();
241 delete fReconParticles;
247 //_____________________________________________________________________________
248 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
252 // new with placement used
254 TClonesArray &lhits = *fHits;
255 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
258 //_____________________________________________________________________________
259 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
263 // new with placement used
265 TClonesArray &lhits = *fHits;
266 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
269 //_____________________________________________________________________________
270 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Float_t *digits)
274 // new with placement used
276 TClonesArray &ldigits = *fDigits;
277 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
280 //_____________________________________________________________________________
281 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Float_t *digits)
288 TClonesArray &lSDigits = *fSDigits;
289 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
292 //_____________________________________________________________________________
293 void AliTOF::SetTreeAddress ()
295 // Set branch address for the Hits and Digits Tree.
297 if (fLoader->TreeH())
301 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
302 else fHits = new TClonesArray("AliTOFhit", 1000);
305 AliDetector::SetTreeAddress ();
309 if (fLoader->TreeS () )
311 branch = fLoader->TreeS ()->GetBranch ("TOF");
313 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
314 branch->SetAddress (&fSDigits);
318 if (fLoader->TreeR() )
320 branch = fLoader->TreeR()->GetBranch("TOF");
323 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
324 branch->SetAddress(&fReconParticles);
329 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
331 branch = fLoader->TreeR()->GetBranch("TOF");
334 branch->SetAddress(&fReconParticles) ;
340 //_____________________________________________________________________________
341 void AliTOF::CreateGeometry()
344 // Common geometry code
348 <img src="picts/AliTOFv23.gif">
355 if (IsVersion()==7) {
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
361 // TOF module internal definitions
362 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
366 Float_t wall = 4.;//cm // frame inbetween TOF modules
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();
372 // TOF module internal definitions
373 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
378 //_____________________________________________________________________________
379 void AliTOF::DrawModule() const
382 // Draw a shaded view of the common part of the TOF geometry
385 AliInfo(" Drawing of AliTOF");
386 // Set everything unseen
387 gMC->Gsatt("*", "seen", -1);
389 // Set ALIC mother transparent
390 gMC->Gsatt("ALIC","SEEN",0);
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);
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);
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");
413 //_____________________________________________________________________________
414 Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t )
417 // Returns distance from mouse pointer to detector, default version
422 //___________________________________________
423 void AliTOF::ResetHits ()
425 // Reset number of clusters and the cluster array for this detector
426 AliDetector::ResetHits ();
429 //____________________________________________
430 void AliTOF::ResetDigits ()
433 // Reset number of digits and the digits array for this detector
434 AliDetector::ResetDigits ();
437 //____________________________________________
438 void AliTOF::ResetSDigits ()
441 // Reset number of sdigits and the sdigits array for this detector
446 //_____________________________________________________________________________
450 // Initialise TOF detector after it has been built
452 // Set id of TOF sensitive volume
453 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
457 TDirectory* saveDir = gDirectory;
458 gAlice->GetRunLoader()->CdGAFile();
459 fTOFGeometry->Write("TOFGeometry");
464 //____________________________________________________________________________
465 void AliTOF::MakeBranch(Option_t* option)
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.
474 const char *oH = strstr(option,"H");
475 if (fLoader->TreeH() && oH)
479 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
480 else fHits = new TClonesArray("AliTOFhit", 1000);
484 AliDetector::MakeBranch(option);
486 Int_t buffersize = 4000;
487 Char_t branchname[10];
488 sprintf(branchname,"%s",GetName());
490 const char *oD = strstr(option,"D");
491 const char *oS = strstr(option,"S");
492 const char *oR = strstr(option,"R");
494 if (fLoader->TreeD() && oD){
495 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
496 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
499 if (fLoader->TreeS() && oS){
500 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
501 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
504 if (fLoader->TreeR() && oR){
505 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
506 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
510 if (fReconParticles && fLoader->TreeR() && oR){
511 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
516 //____________________________________________________________________________
517 void AliTOF::Makehits(Bool_t hits)
519 // default argument used, see AliTOF.h
520 // Enable/Disable the writing of the TOF-hits branch
522 // by default : enabled for TOFv1, v2, v3, v4, v5
523 // disabled for TOFv0
525 if (hits && (IsVersion()!=0))
526 fIdSens = gMC->VolId("FPAD");
528 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
531 //____________________________________________________________________________
532 void AliTOF::FinishEvent()
537 //____________________________________________________________________________
538 void AliTOF::Hits2SDigits()
541 // Use the TOF SDigitizer to make TOF SDigits
544 // cout<<"AliTOF::Hits2SDigits> start...\n";
546 AliRunLoader * rl = fLoader->GetRunLoader();
547 AliTOFSDigitizer sd((rl->GetFileName()).Data());
548 ToAliDebug(1, sd.Print(""));
554 //____________________________________________________________________________
555 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
558 // Use the TOF SDigitizer to make TOF SDigits
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));
567 AliRunLoader * rl = fLoader->GetRunLoader();
568 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
569 ToAliDebug(1, sd.Print(""));
575 //___________________________________________________________________________
576 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
578 return new AliTOFDigitizer(manager);
581 //___________________________________________________________________________
582 Bool_t AliTOF::CheckOverlap(Int_t* vol, Float_t* digit,Int_t Track)
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.
593 Bool_t overlap = kFALSE;
596 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
597 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
598 currentDigit->GetLocation(vol2);
600 // check on digit volume
601 for (Int_t i=0;i<=4;i++){
603 if (vol[i]!=vol2[i]) idem=kFALSE;}
605 if (idem){ // same pad fired
606 Float_t tdc2 = digit[0];
607 Float_t tdc1 = currentDigit->GetTdc();
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
613 if (TMath::Abs(tdc1-tdc2)<25000){
614 // in case of overlap we take the earliest
616 currentDigit->SetTdc(tdc2);
617 currentDigit->SetAdc(digit[1]);
620 currentDigit->SetTdc(tdc1);
621 currentDigit->SetAdc(digit[1]);
623 currentDigit->AddTrack(Track); // add track number in the track array
629 } // close if (idem) -> two digits on the same TOF pad
631 } // end loop on existing sdigits
635 //____________________________________________________________________________
636 void AliTOF::Digits2Raw()
639 // Starting from the TOF digits, writes the Raw Data objects
642 fLoader->LoadDigits();
644 TTree* digits = fLoader->TreeD();
646 AliError("no digits tree");
650 //AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(),"read");
651 fRunLoader->CdGAFile();
652 TFile *in=(TFile*)gFile;
654 AliTOFGeometry *geometry = (AliTOFGeometry*)in->Get("TOFgeometry");
656 AliTOFDDLRawData rawWriter(geometry);
657 //AliTOFDDLRawData rawWriter;
658 rawWriter.SetVerbose(0);
660 AliInfo("Formatting raw data for TOF");
662 rawWriter.RawDataTOF(digits->GetBranch("TOF"));
664 fLoader->UnloadDigits();
668 //____________________________________________________________________________
669 void AliTOF::RecreateSDigitsArray() {
671 // delete TClonesArray fSDigits and create it again
672 // needed for backward compatability with PPR test production
675 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
677 //____________________________________________________________________________
678 void AliTOF::CreateSDigitsArray() {
680 // create TClonesArray fSDigits
681 // needed for backward compatability with PPR test production
683 fSDigits = new TClonesArray("AliTOFSDigit", 1000);