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
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),
117 // AliTOF standard constructor
119 // Here are fixed some important parameters
122 // Initialization of hits, sdigits and digits array
123 // added option for time zero analysis
125 fTOFGeometry = new AliTOFGeometry();
127 //by default all sectors switched on
128 for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
130 if (strstr(option,"tzero")){
131 fHits = new TClonesArray("AliTOFhitT0", 1000);
133 // AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
135 fHits = new TClonesArray("AliTOFhit", 1000);
139 AliFatal("gAlice==0 !");
142 AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
144 if (mcApplication->GetHitLists())
145 mcApplication->AddHitList(fHits);
146 else AliError("gAlice->GetHitLists()==0");
149 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
150 fDigits = new TClonesArray("AliTOFdigit", 1000);
153 // Digitization parameters
155 // (Transfer Functions to be inserted here)
157 //PH SetMarkerColor(7);
158 //PH SetMarkerStyle(2);
159 //PH SetMarkerSize(0.4);
162 //fGapA = 4.; //cm Gap beetween tilted strip in A-type plate
163 //fGapB = 6.; //cm Gap beetween tilted strip in B-type plate
165 // Physical performances
166 //fTimeRes = 100.;//ps
167 //fChrgRes = 100.;//pC
171 //____________________________________________________________________________
172 void AliTOF::SetTOFSectors(Int_t *sectors)
174 // Setter for partial/full TOF configuration
176 for(Int_t isec=0;isec<18;isec++){
177 fTOFSectors[isec]=sectors[isec];
180 //____________________________________________________________________________
181 void AliTOF::GetTOFSectors(Int_t *sectors) const
183 // Getter for partial/full TOF configuration
185 for(Int_t isec=0;isec<18;isec++){
186 sectors[isec]=fTOFSectors[isec];
189 //_____________________________________________________________________________
190 AliTOF::AliTOF(const AliTOF &source)
197 fReconParticles(0x0),
204 this->fReconParticles=source.fReconParticles;
205 this->fSDigits=source.fSDigits;
206 this->fTOFGeometry=source.fTOFGeometry;
210 //_____________________________________________________________________________
211 AliTOF& AliTOF::operator=(const AliTOF &source)
215 this->fReconParticles=source.fReconParticles;
216 this->fSDigits=source.fSDigits;
217 this->fTOFGeometry=source.fTOFGeometry;
222 //_____________________________________________________________________________
223 void AliTOF::CreateTOFFolders()
225 // create the ALICE TFolder
226 // create the ALICE TTasks
227 // create the ALICE main TFolder
228 // to be done by AliRun
230 TFolder * alice = new TFolder();
231 alice->SetNameTitle("FPAlice", "Alice Folder") ;
232 gROOT->GetListOfBrowsables()->Add(alice) ;
234 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
235 // make it the owner of the objects that it contains
238 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
239 TFolder * aliceT = alice->AddFolder("tasks", "Alice tasks Folder") ;
240 // make it the owner of the objects that it contains
243 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
244 aliceT->Add(aliceDi);
246 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
247 aliceT->Add(aliceRe);
249 char * tempo = new char[80] ;
251 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
252 sprintf(tempo, "%sDigitizers container",GetName() ) ;
253 fDTask = new TTask(GetName(), tempo);
254 aliceDi->Add(fDTask) ;
256 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
257 sprintf(tempo, "%sReconstructioner container",GetName() ) ;
258 fReTask = new TTask(GetName(), tempo);
259 aliceRe->Add(fReTask) ;
263 // creates the TOF geometry folder
264 geomF->AddFolder("TOF", "Geometry for TOF") ;
267 //_____________________________________________________________________________
271 // it remove also the alice folder
272 // and task that TOF creates instead of AliRun
273 /* PH Temporarily commented because of problems
274 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
299 fReconParticles->Delete ();
300 delete fReconParticles;
306 //_____________________________________________________________________________
307 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
311 // new with placement used
313 TClonesArray &lhits = *fHits;
314 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
317 //_____________________________________________________________________________
318 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
322 // new with placement used
324 TClonesArray &lhits = *fHits;
325 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
328 //_____________________________________________________________________________
329 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Int_t *digits)
333 // new with placement used
335 TClonesArray &ldigits = *fDigits;
336 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
339 //_____________________________________________________________________________
340 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Int_t *digits)
347 TClonesArray &lSDigits = *fSDigits;
348 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
351 //_____________________________________________________________________________
352 void AliTOF::SetTreeAddress ()
354 // Set branch address for the Hits and Digits Tree.
356 if (fLoader->TreeH())
360 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
361 else fHits = new TClonesArray("AliTOFhit", 1000);
364 AliDetector::SetTreeAddress ();
368 if (fLoader->TreeS () )
370 branch = fLoader->TreeS ()->GetBranch ("TOF");
372 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
373 branch->SetAddress (&fSDigits);
377 if (fLoader->TreeR() )
379 branch = fLoader->TreeR()->GetBranch("TOF");
382 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
383 branch->SetAddress(&fReconParticles);
388 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
390 branch = fLoader->TreeR()->GetBranch("TOF");
393 branch->SetAddress(&fReconParticles) ;
399 //_____________________________________________________________________________
400 void AliTOF::CreateGeometry()
403 // Common geometry code
407 <img src="picts/AliTOFv23.gif">
414 if (IsVersion()==8) {
416 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
417 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
418 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
420 // TOF module internal definitions
421 TOFpc(xTof, yTof, zTof);
423 } else if (IsVersion()==7) {
425 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
426 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
427 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
429 // TOF module internal definitions
430 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
434 Float_t wall = 4.;//cm // frame inbetween TOF modules
436 // Sizes of TOF module with its support etc..
437 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
438 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
440 // TOF module internal definitions
441 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
446 //_____________________________________________________________________________
447 void AliTOF::DrawModule() const
450 // Draw a shaded view of the common part of the TOF geometry
453 AliInfo(" Drawing of AliTOF");
454 // Set everything unseen
455 gMC->Gsatt("*", "seen", -1);
457 // Set ALIC mother transparent
458 gMC->Gsatt("ALIC","SEEN",0);
460 // Set the volumes visible
461 gMC->Gsatt("FTOA","SEEN",1);
462 gMC->Gsatt("FTOB","SEEN",1);
463 gMC->Gsatt("FTOC","SEEN",1);
464 gMC->Gsatt("FLTA","SEEN",1);
465 gMC->Gsatt("FLTB","SEEN",1);
466 gMC->Gsatt("FLTC","SEEN",1);
467 gMC->Gsatt("FSTR","SEEN",1);
469 gMC->Gdopt("hide", "on");
470 gMC->Gdopt("shad", "on");
471 gMC->Gsatt("*", "fill", 7);
472 gMC->SetClipBox(".");
473 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
475 gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
476 gMC->Gdhead(1111, "Time Of Flight");
477 gMC->Gdman(18, 4, "MAN");
478 gMC->Gdopt("hide","off");
481 //_____________________________________________________________________________
482 Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t )
485 // Returns distance from mouse pointer to detector, default version
490 //___________________________________________
491 void AliTOF::ResetHits ()
493 // Reset number of clusters and the cluster array for this detector
494 AliDetector::ResetHits ();
497 //____________________________________________
498 void AliTOF::ResetDigits ()
501 // Reset number of digits and the digits array for this detector
502 AliDetector::ResetDigits ();
505 //____________________________________________
506 void AliTOF::ResetSDigits ()
509 // Reset number of sdigits and the sdigits array for this detector
514 //_____________________________________________________________________________
518 // Initialise TOF detector after it has been built
520 // Set id of TOF sensitive volume
521 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
525 TDirectory* saveDir = gDirectory;
526 gAlice->GetRunLoader()->CdGAFile();
527 fTOFGeometry->Write("TOFGeometry");
532 //____________________________________________________________________________
533 void AliTOF::MakeBranch(Option_t* option)
536 // Initializes the Branches of the TOF inside the
537 // trees written for each event.
538 // AliDetector::MakeBranch initializes just the
539 // Branch inside TreeH. Here we add the branches in
540 // TreeD, TreeS and TreeR.
542 const char *oH = strstr(option,"H");
543 if (fLoader->TreeH() && oH)
547 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
548 else fHits = new TClonesArray("AliTOFhit", 1000);
552 AliDetector::MakeBranch(option);
554 Int_t buffersize = 4000;
555 Char_t branchname[10];
556 sprintf(branchname,"%s",GetName());
558 const char *oD = strstr(option,"D");
559 const char *oS = strstr(option,"S");
560 const char *oR = strstr(option,"R");
562 if (fLoader->TreeD() && oD){
563 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
564 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
567 if (fLoader->TreeS() && oS){
568 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
569 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
572 if (fLoader->TreeR() && oR){
573 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
574 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
578 if (fReconParticles && fLoader->TreeR() && oR){
579 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
584 //____________________________________________________________________________
585 void AliTOF::Makehits(Bool_t hits)
587 // default argument used, see AliTOF.h
588 // Enable/Disable the writing of the TOF-hits branch
590 // by default : enabled for TOFv1, v2, v3, v4, v5
591 // disabled for TOFv0
593 if (hits && (IsVersion()!=0))
594 fIdSens = gMC->VolId("FPAD");
596 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
599 //____________________________________________________________________________
600 void AliTOF::FinishEvent()
605 //____________________________________________________________________________
606 void AliTOF::Hits2SDigits()
609 // Use the TOF SDigitizer to make TOF SDigits
612 // AliInfo("Start...");
614 AliRunLoader * rl = fLoader->GetRunLoader();
615 AliTOFSDigitizer sd((rl->GetFileName()).Data());
616 ToAliDebug(1, sd.Print(""));
622 //____________________________________________________________________________
623 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
626 // Use the TOF SDigitizer to make TOF SDigits
629 if ((evNumber2-evNumber1)==1)
630 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
631 if ((evNumber2-evNumber1)>1)
632 AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
634 AliRunLoader * rl = fLoader->GetRunLoader();
635 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
636 ToAliDebug(1, sd.Print(""));
642 //___________________________________________________________________________
643 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
645 return new AliTOFDigitizer(manager);
648 //___________________________________________________________________________
649 Bool_t AliTOF::CheckOverlap(Int_t* vol, Int_t* digit,Int_t Track)
652 // Checks if 2 or more hits belong to the same pad.
653 // In this case the data assigned to the digit object
654 // are the ones of the first hit in order of Time.
655 // 2 hits from the same track on the same pad are collected.
656 // Called only by Hits2SDigits.
657 // This procedure has to be optimized in the next TOF release.
660 Bool_t overlap = kFALSE;
663 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
664 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
665 currentDigit->GetLocation(vol2);
667 // check on digit volume
668 for (Int_t i=0;i<=4;i++){
670 if (vol[i]!=vol2[i]) idem=kFALSE;}
672 if (idem){ // same pad fired
673 Int_t tdc2 = digit[0];
674 Int_t tdc1 = currentDigit->GetTdc();
676 // we separate two digits on the same pad if
677 // they are separated in time by at least 25 ns
678 // remember that tdc time is given in ps
680 if (TMath::Abs(tdc1-tdc2)<25000){
681 // in case of overlap we take the earliest
683 currentDigit->SetTdc(tdc2);
684 currentDigit->SetAdc(digit[1]);
687 currentDigit->SetTdc(tdc1);
688 currentDigit->SetAdc(digit[1]);
690 currentDigit->AddTrack(Track); // add track number in the track array
696 } // close if (idem) -> two digits on the same TOF pad
698 } // end loop on existing sdigits
702 //____________________________________________________________________________
703 void AliTOF::Digits2Raw()
706 // Starting from the TOF digits, writes the Raw Data objects
709 TStopwatch stopwatch;
712 fLoader->LoadDigits();
714 TTree* digits = fLoader->TreeD();
716 AliError("no digits tree");
721 fRunLoader->CdGAFile();
722 TFile *in=(TFile*)gFile;
724 AliTOFGeometry *geometry = (AliTOFGeometry*)in->Get("TOFgeometry");
726 AliTOFDDLRawData rawWriter;
727 //AliTOFDDLRawData rawWriter;
728 rawWriter.SetVerbose(0);
729 //rawWriter.SetFakeOrphaneProduction(kTRUE);
730 //rawWriter.SetPackedAcquisitionMode(kFALSE);
731 if (rawWriter.GetPackedAcquisitionMode()) {
732 if(rawWriter.GetMatchingWindow()>8192)
733 AliWarning(Form("You are running in packing mode and the matching window is %.2f ns, i.e. greater than 199.8848 ns",
734 rawWriter.GetMatchingWindow()*AliTOFGeometry::TdcBinWidth()*1.e-03));
737 AliDebug(1,"Formatting raw data for TOF");
739 rawWriter.RawDataTOF(digits->GetBranch("TOF"));
741 fLoader->UnloadDigits();
743 AliDebug(1, Form("Execution time to write TOF raw data : R:%.2fs C:%.2fs",
744 stopwatch.RealTime(),stopwatch.CpuTime()));
748 //____________________________________________________________________________
749 void AliTOF::RecreateSDigitsArray() {
751 // delete TClonesArray fSDigits and create it again
752 // needed for backward compatability with PPR test production
755 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
757 //____________________________________________________________________________
758 void AliTOF::CreateSDigitsArray() {
760 // create TClonesArray fSDigits
761 // needed for backward compatability with PPR test production
763 fSDigits = new TClonesArray("AliTOFSDigit", 1000);