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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
20 // This class contains the basic functions for the Time Of Flight //
21 // detector. Functions specific to one particular geometry are //
22 // contained in the derived classes //
24 // VERSIONE WITH 5 SYMMETRIC MODULES ALONG Z AXIS //
25 // ============================================================ //
27 // VERSION WITH HOLES FOR PHOS AND TRD IN SPACEFRAME WITH HOLES //
29 // Volume sensibile : FPAD //
34 ///////////////////////////////////////////////////////////////////////////////
37 <img src="picts/AliTOFClass.gif">
41 #include <TClonesArray.h>
47 #include <TVirtualMC.h>
48 #include <TStopwatch.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 //_____________________________________________________________________________
91 // Default constructor
94 //by default all sectors switched on
95 for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
102 //_____________________________________________________________________________
103 AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
105 AliDetector(name,title),
111 fReconParticles(0x0),
118 // AliTOF standard constructor
120 // Here are fixed some important parameters
123 // Initialization of hits, sdigits and digits array
124 // added option for time zero analysis
126 fTOFGeometry = new AliTOFGeometry();
128 //by default all sectors switched on
129 for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
131 if (strstr(option,"tzero")){
132 fHits = new TClonesArray("AliTOFhitT0", 1000);
134 // AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
136 fHits = new TClonesArray("AliTOFhit", 1000);
140 AliFatal("gAlice==0 !");
143 AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
145 if (mcApplication->GetHitLists())
146 mcApplication->AddHitList(fHits);
147 else AliError("gAlice->GetHitLists()==0");
150 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
151 fDigits = new TClonesArray("AliTOFdigit", 1000);
154 // Digitization parameters
156 // (Transfer Functions to be inserted here)
158 //PH SetMarkerColor(7);
159 //PH SetMarkerStyle(2);
160 //PH SetMarkerSize(0.4);
163 //fGapA = 4.; //cm Gap beetween tilted strip in A-type plate
164 //fGapB = 6.; //cm Gap beetween tilted strip in B-type plate
166 // Physical performances
167 //fTimeRes = 100.;//ps
168 //fChrgRes = 100.;//pC
172 //____________________________________________________________________________
173 void AliTOF::SetTOFSectors(Int_t *sectors)
175 // Setter for partial/full TOF configuration
177 for(Int_t isec=0;isec<18;isec++){
178 fTOFSectors[isec]=sectors[isec];
181 //____________________________________________________________________________
182 void AliTOF::GetTOFSectors(Int_t *sectors) const
184 // Getter for partial/full TOF configuration
186 for(Int_t isec=0;isec<18;isec++){
187 sectors[isec]=fTOFSectors[isec];
190 //_____________________________________________________________________________
191 AliTOF::AliTOF(const AliTOF &source)
199 fReconParticles(0x0),
207 this->fReconParticles=source.fReconParticles;
208 this->fSDigits=source.fSDigits;
209 this->fTOFGeometry=source.fTOFGeometry;
213 //_____________________________________________________________________________
214 AliTOF& AliTOF::operator=(const AliTOF &source)
218 this->fReconParticles=source.fReconParticles;
219 this->fSDigits=source.fSDigits;
220 this->fTOFGeometry=source.fTOFGeometry;
225 //_____________________________________________________________________________
226 void AliTOF::CreateTOFFolders()
228 // create the ALICE TFolder
229 // create the ALICE TTasks
230 // create the ALICE main TFolder
231 // to be done by AliRun
233 TFolder * alice = new TFolder();
234 alice->SetNameTitle("FPAlice", "Alice Folder") ;
235 gROOT->GetListOfBrowsables()->Add(alice) ;
237 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
238 // make it the owner of the objects that it contains
241 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
242 TFolder * aliceT = alice->AddFolder("tasks", "Alice tasks Folder") ;
243 // make it the owner of the objects that it contains
246 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
247 aliceT->Add(aliceDi);
249 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
250 aliceT->Add(aliceRe);
252 char * tempo = new char[80] ;
254 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
255 sprintf(tempo, "%sDigitizers container",GetName() ) ;
256 fDTask = new TTask(GetName(), tempo);
257 aliceDi->Add(fDTask) ;
259 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
260 sprintf(tempo, "%sReconstructioner container",GetName() ) ;
261 fReTask = new TTask(GetName(), tempo);
262 aliceRe->Add(fReTask) ;
266 // creates the TOF geometry folder
267 geomF->AddFolder("TOF", "Geometry for TOF") ;
270 //_____________________________________________________________________________
274 // it remove also the alice folder
275 // and task that TOF creates instead of AliRun
276 /* PH Temporarily commented because of problems
277 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
302 fReconParticles->Delete ();
303 delete fReconParticles;
309 //_____________________________________________________________________________
310 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
314 // new with placement used
316 TClonesArray &lhits = *fHits;
317 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
320 //_____________________________________________________________________________
321 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
325 // new with placement used
327 TClonesArray &lhits = *fHits;
328 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
331 //_____________________________________________________________________________
332 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Int_t *digits)
336 // new with placement used
338 TClonesArray &ldigits = *fDigits;
339 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
342 //_____________________________________________________________________________
343 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Int_t *digits)
350 TClonesArray &lSDigits = *fSDigits;
351 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
354 //_____________________________________________________________________________
355 void AliTOF::SetTreeAddress ()
357 // Set branch address for the Hits and Digits Tree.
359 if (fLoader->TreeH())
363 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
364 else fHits = new TClonesArray("AliTOFhit", 1000);
367 AliDetector::SetTreeAddress ();
371 if (fLoader->TreeS () )
373 branch = fLoader->TreeS ()->GetBranch ("TOF");
375 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
376 branch->SetAddress (&fSDigits);
380 if (fLoader->TreeR() )
382 branch = fLoader->TreeR()->GetBranch("TOF");
385 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
386 branch->SetAddress(&fReconParticles);
391 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
393 branch = fLoader->TreeR()->GetBranch("TOF");
396 branch->SetAddress(&fReconParticles) ;
402 //_____________________________________________________________________________
403 void AliTOF::CreateGeometry()
406 // Common geometry code
410 <img src="picts/AliTOFv23.gif">
417 if (IsVersion()==8) {
419 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
420 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
421 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
423 // TOF module internal definitions
424 TOFpc(xTof, yTof, zTof);
426 } else if (IsVersion()==7) {
428 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
429 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
430 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
432 // TOF module internal definitions
433 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
437 Float_t wall = 4.;//cm // frame inbetween TOF modules
439 // Sizes of TOF module with its support etc..
440 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
441 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
443 // TOF module internal definitions
444 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
449 //_____________________________________________________________________________
450 void AliTOF::DrawModule() const
453 // Draw a shaded view of the common part of the TOF geometry
456 AliInfo(" Drawing of AliTOF");
457 // Set everything unseen
458 gMC->Gsatt("*", "seen", -1);
460 // Set ALIC mother transparent
461 gMC->Gsatt("ALIC","SEEN",0);
463 // Set the volumes visible
464 gMC->Gsatt("FTOA","SEEN",1);
465 gMC->Gsatt("FTOB","SEEN",1);
466 gMC->Gsatt("FTOC","SEEN",1);
467 gMC->Gsatt("FLTA","SEEN",1);
468 gMC->Gsatt("FLTB","SEEN",1);
469 gMC->Gsatt("FLTC","SEEN",1);
470 gMC->Gsatt("FSTR","SEEN",1);
472 gMC->Gdopt("hide", "on");
473 gMC->Gdopt("shad", "on");
474 gMC->Gsatt("*", "fill", 7);
475 gMC->SetClipBox(".");
476 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
478 gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
479 gMC->Gdhead(1111, "Time Of Flight");
480 gMC->Gdman(18, 4, "MAN");
481 gMC->Gdopt("hide","off");
484 //_____________________________________________________________________________
485 Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t )
488 // Returns distance from mouse pointer to detector, default version
493 //___________________________________________
494 void AliTOF::ResetHits ()
496 // Reset number of clusters and the cluster array for this detector
497 AliDetector::ResetHits ();
500 //____________________________________________
501 void AliTOF::ResetDigits ()
504 // Reset number of digits and the digits array for this detector
505 AliDetector::ResetDigits ();
508 //____________________________________________
509 void AliTOF::ResetSDigits ()
512 // Reset number of sdigits and the sdigits array for this detector
517 //_____________________________________________________________________________
521 // Initialise TOF detector after it has been built
523 // Set id of TOF sensitive volume
524 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
528 TDirectory* saveDir = gDirectory;
529 gAlice->GetRunLoader()->CdGAFile();
530 fTOFGeometry->Write("TOFGeometry");
535 //____________________________________________________________________________
536 void AliTOF::MakeBranch(Option_t* option)
539 // Initializes the Branches of the TOF inside the
540 // trees written for each event.
541 // AliDetector::MakeBranch initializes just the
542 // Branch inside TreeH. Here we add the branches in
543 // TreeD, TreeS and TreeR.
545 const char *oH = strstr(option,"H");
546 if (fLoader->TreeH() && oH)
550 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
551 else fHits = new TClonesArray("AliTOFhit", 1000);
555 AliDetector::MakeBranch(option);
557 Int_t buffersize = 4000;
558 Char_t branchname[10];
559 sprintf(branchname,"%s",GetName());
561 const char *oD = strstr(option,"D");
562 const char *oS = strstr(option,"S");
563 const char *oR = strstr(option,"R");
565 if (fLoader->TreeD() && oD){
566 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
567 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
570 if (fLoader->TreeS() && oS){
571 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
572 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
575 if (fLoader->TreeR() && oR){
576 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
577 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
581 if (fReconParticles && fLoader->TreeR() && oR){
582 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
587 //____________________________________________________________________________
588 void AliTOF::Makehits(Bool_t hits)
590 // default argument used, see AliTOF.h
591 // Enable/Disable the writing of the TOF-hits branch
593 // by default : enabled for TOFv1, v2, v3, v4, v5
594 // disabled for TOFv0
596 if (hits && (IsVersion()!=0))
597 fIdSens = gMC->VolId("FPAD");
599 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
602 //____________________________________________________________________________
603 void AliTOF::FinishEvent()
608 //____________________________________________________________________________
609 void AliTOF::Hits2SDigits()
612 // Use the TOF SDigitizer to make TOF SDigits
615 // AliInfo("Start...");
617 AliRunLoader * rl = fLoader->GetRunLoader();
618 AliTOFSDigitizer sd((rl->GetFileName()).Data());
619 ToAliDebug(1, sd.Print(""));
625 //____________________________________________________________________________
626 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
629 // Use the TOF SDigitizer to make TOF SDigits
632 if ((evNumber2-evNumber1)==1)
633 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
634 if ((evNumber2-evNumber1)>1)
635 AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
637 AliRunLoader * rl = fLoader->GetRunLoader();
638 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
639 ToAliDebug(1, sd.Print(""));
645 //___________________________________________________________________________
646 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
648 return new AliTOFDigitizer(manager);
651 //___________________________________________________________________________
652 Bool_t AliTOF::CheckOverlap(Int_t* vol, Int_t* digit,Int_t Track)
655 // Checks if 2 or more hits belong to the same pad.
656 // In this case the data assigned to the digit object
657 // are the ones of the first hit in order of Time.
658 // 2 hits from the same track on the same pad are collected.
659 // Called only by Hits2SDigits.
660 // This procedure has to be optimized in the next TOF release.
663 Bool_t overlap = kFALSE;
666 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
667 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
668 currentDigit->GetLocation(vol2);
670 // check on digit volume
671 for (Int_t i=0;i<=4;i++){
673 if (vol[i]!=vol2[i]) idem=kFALSE;}
675 if (idem){ // same pad fired
676 Int_t tdc2 = digit[0];
677 Int_t tdc1 = currentDigit->GetTdc();
679 // we separate two digits on the same pad if
680 // they are separated in time by at least 25 ns
681 // remember that tdc time is given in ps
683 if (TMath::Abs(tdc1-tdc2)<25000){
684 // in case of overlap we take the earliest
686 currentDigit->SetTdc(tdc2);
687 currentDigit->SetAdc(digit[1]);
690 currentDigit->SetTdc(tdc1);
691 currentDigit->SetAdc(digit[1]);
693 currentDigit->AddTrack(Track); // add track number in the track array
699 } // close if (idem) -> two digits on the same TOF pad
701 } // end loop on existing sdigits
705 //____________________________________________________________________________
706 void AliTOF::Digits2Raw()
709 // Starting from the TOF digits, writes the Raw Data objects
712 TStopwatch stopwatch;
715 fLoader->LoadDigits();
717 TTree* digits = fLoader->TreeD();
719 AliError("no digits tree");
724 fRunLoader->CdGAFile();
725 TFile *in=(TFile*)gFile;
727 AliTOFGeometry *geometry = (AliTOFGeometry*)in->Get("TOFgeometry");
729 AliTOFDDLRawData rawWriter;
730 //AliTOFDDLRawData rawWriter;
731 rawWriter.SetVerbose(0);
732 //rawWriter.SetFakeOrphaneProduction(kTRUE);
733 //rawWriter.SetPackedAcquisitionMode(kFALSE);
734 if (rawWriter.GetPackedAcquisitionMode()) {
735 if(rawWriter.GetMatchingWindow()>8192)
736 AliWarning(Form("You are running in packing mode and the matching window is %.2f ns, i.e. greater than 199.8848 ns",
737 rawWriter.GetMatchingWindow()*AliTOFGeometry::TdcBinWidth()*1.e-03));
740 AliDebug(1,"Formatting raw data for TOF");
742 rawWriter.RawDataTOF(digits->GetBranch("TOF"));
744 fLoader->UnloadDigits();
746 AliDebug(1, Form("Execution time to write TOF raw data : R:%.2fs C:%.2fs",
747 stopwatch.RealTime(),stopwatch.CpuTime()));
751 //____________________________________________________________________________
752 void AliTOF::RecreateSDigitsArray() {
754 // delete TClonesArray fSDigits and create it again
755 // needed for backward compatability with PPR test production
758 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
760 //____________________________________________________________________________
761 void AliTOF::CreateSDigitsArray() {
763 // create TClonesArray fSDigits
764 // needed for backward compatability with PPR test production
766 fSDigits = new TClonesArray("AliTOFSDigit", 1000);