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>
49 #include <TStopwatch.h>
52 #include "AliLoader.h"
57 #include "AliTOFDDLRawData.h"
58 #include "AliTOFDigitizer.h"
59 #include "AliTOFdigit.h"
60 #include "AliTOFhitT0.h"
61 #include "AliTOFhit.h"
62 #include "AliTOFGeometry.h"
63 #include "AliTOFSDigitizer.h"
64 #include "AliTOFSDigit.h"
71 extern TVirtualMC *gMC;
73 extern AliRun *gAlice;
78 //_____________________________________________________________________________
91 // Default constructor
98 //_____________________________________________________________________________
99 AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
101 AliDetector(name,title),
107 fReconParticles(0x0),
113 // AliTOF standard constructor
115 // Here are fixed some important parameters
118 // Initialization of hits, sdigits and digits array
119 // added option for time zero analysis
121 fTOFGeometry = new AliTOFGeometry();
123 if (strstr(option,"tzero")){
124 fHits = new TClonesArray("AliTOFhitT0", 1000);
126 // AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
128 fHits = new TClonesArray("AliTOFhit", 1000);
132 AliFatal("gAlice==0 !");
135 AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
137 if (mcApplication->GetHitLists())
138 mcApplication->AddHitList(fHits);
139 else AliError("gAlice->GetHitLists()==0");
142 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
143 fDigits = new TClonesArray("AliTOFdigit", 1000);
146 // Digitization parameters
148 // (Transfer Functions to be inserted here)
150 //PH SetMarkerColor(7);
151 //PH SetMarkerStyle(2);
152 //PH SetMarkerSize(0.4);
155 //fGapA = 4.; //cm Gap beetween tilted strip in A-type plate
156 //fGapB = 6.; //cm Gap beetween tilted strip in B-type plate
158 // Physical performances
159 //fTimeRes = 100.;//ps
160 //fChrgRes = 100.;//pC
164 //____________________________________________________________________________
165 void AliTOF::SetTOFSectors(Int_t *sectors)
167 // Setter for partial/full TOF configuration
169 for(Int_t isec=0;isec<18;isec++){
170 fTOFSectors[isec]=sectors[isec];
173 //____________________________________________________________________________
174 void AliTOF::GetTOFSectors(Int_t *sectors) const
176 // Getter for partial/full TOF configuration
178 for(Int_t isec=0;isec<18;isec++){
179 sectors[isec]=fTOFSectors[isec];
182 //_____________________________________________________________________________
183 AliTOF::AliTOF(const AliTOF &source)
190 fReconParticles(0x0),
197 this->fReconParticles=source.fReconParticles;
198 this->fSDigits=source.fSDigits;
199 this->fTOFGeometry=source.fTOFGeometry;
203 //_____________________________________________________________________________
204 AliTOF& AliTOF::operator=(const AliTOF &source)
208 this->fReconParticles=source.fReconParticles;
209 this->fSDigits=source.fSDigits;
210 this->fTOFGeometry=source.fTOFGeometry;
215 //_____________________________________________________________________________
216 void AliTOF::CreateTOFFolders()
218 // create the ALICE TFolder
219 // create the ALICE TTasks
220 // create the ALICE main TFolder
221 // to be done by AliRun
223 TFolder * alice = new TFolder();
224 alice->SetNameTitle("FPAlice", "Alice Folder") ;
225 gROOT->GetListOfBrowsables()->Add(alice) ;
227 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
228 // make it the owner of the objects that it contains
231 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
232 TFolder * aliceT = alice->AddFolder("tasks", "Alice tasks Folder") ;
233 // make it the owner of the objects that it contains
236 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
237 aliceT->Add(aliceDi);
239 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
240 aliceT->Add(aliceRe);
242 char * tempo = new char[80] ;
244 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
245 sprintf(tempo, "%sDigitizers container",GetName() ) ;
246 fDTask = new TTask(GetName(), tempo);
247 aliceDi->Add(fDTask) ;
249 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
250 sprintf(tempo, "%sReconstructioner container",GetName() ) ;
251 fReTask = new TTask(GetName(), tempo);
252 aliceRe->Add(fReTask) ;
256 // creates the TOF geometry folder
257 geomF->AddFolder("TOF", "Geometry for TOF") ;
260 //_____________________________________________________________________________
264 // it remove also the alice folder
265 // and task that TOF creates instead of AliRun
266 /* PH Temporarily commented because of problems
267 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
292 fReconParticles->Delete ();
293 delete fReconParticles;
299 //_____________________________________________________________________________
300 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
304 // new with placement used
306 TClonesArray &lhits = *fHits;
307 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
310 //_____________________________________________________________________________
311 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
315 // new with placement used
317 TClonesArray &lhits = *fHits;
318 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
321 //_____________________________________________________________________________
322 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Int_t *digits)
326 // new with placement used
328 TClonesArray &ldigits = *fDigits;
329 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
332 //_____________________________________________________________________________
333 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Int_t *digits)
340 TClonesArray &lSDigits = *fSDigits;
341 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
344 //_____________________________________________________________________________
345 void AliTOF::SetTreeAddress ()
347 // Set branch address for the Hits and Digits Tree.
349 if (fLoader->TreeH())
353 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
354 else fHits = new TClonesArray("AliTOFhit", 1000);
357 AliDetector::SetTreeAddress ();
361 if (fLoader->TreeS () )
363 branch = fLoader->TreeS ()->GetBranch ("TOF");
365 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
366 branch->SetAddress (&fSDigits);
370 if (fLoader->TreeR() )
372 branch = fLoader->TreeR()->GetBranch("TOF");
375 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
376 branch->SetAddress(&fReconParticles);
381 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
383 branch = fLoader->TreeR()->GetBranch("TOF");
386 branch->SetAddress(&fReconParticles) ;
392 //_____________________________________________________________________________
393 void AliTOF::CreateGeometry()
396 // Common geometry code
400 <img src="picts/AliTOFv23.gif">
407 if (IsVersion()==8) {
409 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
410 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
411 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
413 // TOF module internal definitions
414 TOFpc(xTof, yTof, zTof);
416 } else if (IsVersion()==7) {
418 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
419 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
420 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
422 // TOF module internal definitions
423 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
427 Float_t wall = 4.;//cm // frame inbetween TOF modules
429 // Sizes of TOF module with its support etc..
430 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
431 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
433 // TOF module internal definitions
434 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
439 //_____________________________________________________________________________
440 void AliTOF::DrawModule() const
443 // Draw a shaded view of the common part of the TOF geometry
446 AliInfo(" Drawing of AliTOF");
447 // Set everything unseen
448 gMC->Gsatt("*", "seen", -1);
450 // Set ALIC mother transparent
451 gMC->Gsatt("ALIC","SEEN",0);
453 // Set the volumes visible
454 gMC->Gsatt("FTOA","SEEN",1);
455 gMC->Gsatt("FTOB","SEEN",1);
456 gMC->Gsatt("FTOC","SEEN",1);
457 gMC->Gsatt("FLTA","SEEN",1);
458 gMC->Gsatt("FLTB","SEEN",1);
459 gMC->Gsatt("FLTC","SEEN",1);
460 gMC->Gsatt("FSTR","SEEN",1);
462 gMC->Gdopt("hide", "on");
463 gMC->Gdopt("shad", "on");
464 gMC->Gsatt("*", "fill", 7);
465 gMC->SetClipBox(".");
466 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
468 gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
469 gMC->Gdhead(1111, "Time Of Flight");
470 gMC->Gdman(18, 4, "MAN");
471 gMC->Gdopt("hide","off");
474 //_____________________________________________________________________________
475 Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t )
478 // Returns distance from mouse pointer to detector, default version
483 //___________________________________________
484 void AliTOF::ResetHits ()
486 // Reset number of clusters and the cluster array for this detector
487 AliDetector::ResetHits ();
490 //____________________________________________
491 void AliTOF::ResetDigits ()
494 // Reset number of digits and the digits array for this detector
495 AliDetector::ResetDigits ();
498 //____________________________________________
499 void AliTOF::ResetSDigits ()
502 // Reset number of sdigits and the sdigits array for this detector
507 //_____________________________________________________________________________
511 // Initialise TOF detector after it has been built
513 // Set id of TOF sensitive volume
514 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
518 TDirectory* saveDir = gDirectory;
519 gAlice->GetRunLoader()->CdGAFile();
520 fTOFGeometry->Write("TOFGeometry");
525 //____________________________________________________________________________
526 void AliTOF::MakeBranch(Option_t* option)
529 // Initializes the Branches of the TOF inside the
530 // trees written for each event.
531 // AliDetector::MakeBranch initializes just the
532 // Branch inside TreeH. Here we add the branches in
533 // TreeD, TreeS and TreeR.
535 const char *oH = strstr(option,"H");
536 if (fLoader->TreeH() && oH)
540 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
541 else fHits = new TClonesArray("AliTOFhit", 1000);
545 AliDetector::MakeBranch(option);
547 Int_t buffersize = 4000;
548 Char_t branchname[10];
549 sprintf(branchname,"%s",GetName());
551 const char *oD = strstr(option,"D");
552 const char *oS = strstr(option,"S");
553 const char *oR = strstr(option,"R");
555 if (fLoader->TreeD() && oD){
556 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
557 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
560 if (fLoader->TreeS() && oS){
561 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
562 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
565 if (fLoader->TreeR() && oR){
566 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
567 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
571 if (fReconParticles && fLoader->TreeR() && oR){
572 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
577 //____________________________________________________________________________
578 void AliTOF::Makehits(Bool_t hits)
580 // default argument used, see AliTOF.h
581 // Enable/Disable the writing of the TOF-hits branch
583 // by default : enabled for TOFv1, v2, v3, v4, v5
584 // disabled for TOFv0
586 if (hits && (IsVersion()!=0))
587 fIdSens = gMC->VolId("FPAD");
589 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
592 //____________________________________________________________________________
593 void AliTOF::FinishEvent()
598 //____________________________________________________________________________
599 void AliTOF::Hits2SDigits()
602 // Use the TOF SDigitizer to make TOF SDigits
605 // AliInfo("Start...");
607 AliRunLoader * rl = fLoader->GetRunLoader();
608 AliTOFSDigitizer sd((rl->GetFileName()).Data());
609 ToAliDebug(1, sd.Print(""));
615 //____________________________________________________________________________
616 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
619 // Use the TOF SDigitizer to make TOF SDigits
622 if ((evNumber2-evNumber1)==1)
623 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
624 if ((evNumber2-evNumber1)>1)
625 AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
627 AliRunLoader * rl = fLoader->GetRunLoader();
628 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
629 ToAliDebug(1, sd.Print(""));
635 //___________________________________________________________________________
636 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
638 return new AliTOFDigitizer(manager);
641 //___________________________________________________________________________
642 Bool_t AliTOF::CheckOverlap(Int_t* vol, Int_t* digit,Int_t Track)
645 // Checks if 2 or more hits belong to the same pad.
646 // In this case the data assigned to the digit object
647 // are the ones of the first hit in order of Time.
648 // 2 hits from the same track on the same pad are collected.
649 // Called only by Hits2SDigits.
650 // This procedure has to be optimized in the next TOF release.
653 Bool_t overlap = kFALSE;
656 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
657 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
658 currentDigit->GetLocation(vol2);
660 // check on digit volume
661 for (Int_t i=0;i<=4;i++){
663 if (vol[i]!=vol2[i]) idem=kFALSE;}
665 if (idem){ // same pad fired
666 Int_t tdc2 = digit[0];
667 Int_t tdc1 = currentDigit->GetTdc();
669 // we separate two digits on the same pad if
670 // they are separated in time by at least 25 ns
671 // remember that tdc time is given in ps
673 if (TMath::Abs(tdc1-tdc2)<25000){
674 // in case of overlap we take the earliest
676 currentDigit->SetTdc(tdc2);
677 currentDigit->SetAdc(digit[1]);
680 currentDigit->SetTdc(tdc1);
681 currentDigit->SetAdc(digit[1]);
683 currentDigit->AddTrack(Track); // add track number in the track array
689 } // close if (idem) -> two digits on the same TOF pad
691 } // end loop on existing sdigits
695 //____________________________________________________________________________
696 void AliTOF::Digits2Raw()
699 // Starting from the TOF digits, writes the Raw Data objects
702 TStopwatch stopwatch;
705 fLoader->LoadDigits();
707 TTree* digits = fLoader->TreeD();
709 AliError("no digits tree");
713 fRunLoader->CdGAFile();
714 TFile *in=(TFile*)gFile;
716 AliTOFGeometry *geometry = (AliTOFGeometry*)in->Get("TOFgeometry");
718 AliTOFDDLRawData rawWriter(geometry);
719 //AliTOFDDLRawData rawWriter;
720 rawWriter.SetVerbose(0);
721 //rawWriter.SetFakeOrphaneProduction(kTRUE);
722 //rawWriter.SetPackedAcquisitionMode(kFALSE);
723 if (rawWriter.GetPackedAcquisitionMode()) {
724 if(rawWriter.GetMatchingWindow()>8192)
725 AliWarning(Form("You are running in packing mode and the matching window is %.2f ns, i.e. greater than 199.8848 ns",
726 rawWriter.GetMatchingWindow()*AliTOFGeometry::TdcBinWidth()*1.e-03));
729 AliDebug(1,"Formatting raw data for TOF");
731 rawWriter.RawDataTOF(digits->GetBranch("TOF"));
733 fLoader->UnloadDigits();
735 AliDebug(1, Form("Execution time to write TOF raw data : R:%.2fs C:%.2fs",
736 stopwatch.RealTime(),stopwatch.CpuTime()));
740 //____________________________________________________________________________
741 void AliTOF::RecreateSDigitsArray() {
743 // delete TClonesArray fSDigits and create it again
744 // needed for backward compatability with PPR test production
747 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
749 //____________________________________________________________________________
750 void AliTOF::CreateSDigitsArray() {
752 // create TClonesArray fSDigits
753 // needed for backward compatability with PPR test production
755 fSDigits = new TClonesArray("AliTOFSDigit", 1000);