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;
78 AliTOFDDLRawData AliTOF::fgTOFRawWriter = AliTOFDDLRawData();
81 //_____________________________________________________________________________
95 // Default constructor
98 //by default all sectors switched on
99 for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
107 //_____________________________________________________________________________
108 AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
110 AliDetector(name,title),
116 fReconParticles(0x0),
123 // AliTOF standard constructor
125 // Here are fixed some important parameters
128 // Initialization of hits, sdigits and digits array
129 // added option for time zero analysis
131 fTOFGeometry = new AliTOFGeometry();
133 //by default all sectors switched on
134 for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
136 if (strstr(option,"tzero")){
137 fHits = new TClonesArray("AliTOFhitT0", 1000);
139 // AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
141 fHits = new TClonesArray("AliTOFhit", 1000);
145 AliFatal("gAlice==0 !");
148 AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
150 if (mcApplication->GetHitLists())
151 mcApplication->AddHitList(fHits);
152 else AliError("gAlice->GetHitLists()==0");
155 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
156 fDigits = new TClonesArray("AliTOFdigit", 1000);
159 // Digitization parameters
161 // (Transfer Functions to be inserted here)
163 //PH SetMarkerColor(7);
164 //PH SetMarkerStyle(2);
165 //PH SetMarkerSize(0.4);
168 //fGapA = 4.; //cm Gap beetween tilted strip in A-type plate
169 //fGapB = 6.; //cm Gap beetween tilted strip in B-type plate
171 // Physical performances
172 //fTimeRes = 100.;//ps
173 //fChrgRes = 100.;//pC
177 //____________________________________________________________________________
178 void AliTOF::SetTOFSectors(Int_t *sectors)
180 // Setter for partial/full TOF configuration
182 for(Int_t isec=0;isec<18;isec++){
183 fTOFSectors[isec]=sectors[isec];
186 //____________________________________________________________________________
187 void AliTOF::GetTOFSectors(Int_t *sectors) const
189 // Getter for partial/full TOF configuration
191 for(Int_t isec=0;isec<18;isec++){
192 sectors[isec]=fTOFSectors[isec];
196 //_____________________________________________________________________________
197 void AliTOF::CreateTOFFolders()
199 // create the ALICE TFolder
200 // create the ALICE TTasks
201 // create the ALICE main TFolder
202 // to be done by AliRun
204 TFolder * alice = new TFolder();
205 alice->SetNameTitle("FPAlice", "Alice Folder") ;
206 gROOT->GetListOfBrowsables()->Add(alice) ;
208 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
209 // make it the owner of the objects that it contains
212 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
213 TFolder * aliceT = alice->AddFolder("tasks", "Alice tasks Folder") ;
214 // make it the owner of the objects that it contains
217 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
218 aliceT->Add(aliceDi);
220 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
221 aliceT->Add(aliceRe);
223 char * tempo = new char[80] ;
225 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
226 sprintf(tempo, "%sDigitizers container",GetName() ) ;
227 fDTask = new TTask(GetName(), tempo);
228 aliceDi->Add(fDTask) ;
230 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
231 sprintf(tempo, "%sReconstructioner container",GetName() ) ;
232 fReTask = new TTask(GetName(), tempo);
233 aliceRe->Add(fReTask) ;
237 // creates the TOF geometry folder
238 geomF->AddFolder("TOF", "Geometry for TOF") ;
241 //_____________________________________________________________________________
245 // it remove also the alice folder
246 // and task that TOF creates instead of AliRun
247 /* PH Temporarily commented because of problems
248 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
273 fReconParticles->Delete ();
274 delete fReconParticles;
280 //_____________________________________________________________________________
281 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
285 // new with placement used
287 TClonesArray &lhits = *fHits;
288 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
291 //_____________________________________________________________________________
292 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
296 // new with placement used
298 TClonesArray &lhits = *fHits;
299 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
302 //_____________________________________________________________________________
303 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Int_t *digits)
307 // new with placement used
309 TClonesArray &ldigits = *fDigits;
310 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
313 //_____________________________________________________________________________
314 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Int_t *digits)
321 TClonesArray &lSDigits = *fSDigits;
322 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
325 //_____________________________________________________________________________
326 void AliTOF::SetTreeAddress ()
328 // Set branch address for the Hits and Digits Tree.
330 if (fLoader->TreeH())
334 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
335 else fHits = new TClonesArray("AliTOFhit", 1000);
338 AliDetector::SetTreeAddress ();
342 if (fLoader->TreeS () )
344 branch = fLoader->TreeS ()->GetBranch ("TOF");
346 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
347 branch->SetAddress (&fSDigits);
351 if (fLoader->TreeR() )
353 branch = fLoader->TreeR()->GetBranch("TOF");
356 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
357 branch->SetAddress(&fReconParticles);
362 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
364 branch = fLoader->TreeR()->GetBranch("TOF");
367 branch->SetAddress(&fReconParticles) ;
373 //_____________________________________________________________________________
374 void AliTOF::CreateGeometry()
377 // Common geometry code
381 <img src="picts/AliTOFv23.gif">
388 if (IsVersion()==8) {
390 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
391 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
392 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
394 // TOF module internal definitions
395 TOFpc(xTof, yTof, zTof);
397 } else if (IsVersion()==7) {
399 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
400 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
401 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
403 // TOF module internal definitions
404 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
408 Float_t wall = 4.;//cm // frame inbetween TOF modules
410 // Sizes of TOF module with its support etc..
411 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
412 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
414 // TOF module internal definitions
415 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
420 //_____________________________________________________________________________
421 void AliTOF::DrawModule() const
424 // Draw a shaded view of the common part of the TOF geometry
427 AliInfo(" Drawing of AliTOF");
428 // Set everything unseen
429 gMC->Gsatt("*", "seen", -1);
431 // Set ALIC mother transparent
432 gMC->Gsatt("ALIC","SEEN",0);
434 // Set the volumes visible
435 gMC->Gsatt("FTOA","SEEN",1);
436 gMC->Gsatt("FTOB","SEEN",1);
437 gMC->Gsatt("FTOC","SEEN",1);
438 gMC->Gsatt("FLTA","SEEN",1);
439 gMC->Gsatt("FLTB","SEEN",1);
440 gMC->Gsatt("FLTC","SEEN",1);
441 gMC->Gsatt("FSTR","SEEN",1);
443 gMC->Gdopt("hide", "on");
444 gMC->Gdopt("shad", "on");
445 gMC->Gsatt("*", "fill", 7);
446 gMC->SetClipBox(".");
447 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
449 gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
450 gMC->Gdhead(1111, "Time Of Flight");
451 gMC->Gdman(18, 4, "MAN");
452 gMC->Gdopt("hide","off");
455 //___________________________________________
456 void AliTOF::ResetHits ()
458 // Reset number of clusters and the cluster array for this detector
459 AliDetector::ResetHits ();
462 //____________________________________________
463 void AliTOF::ResetDigits ()
466 // Reset number of digits and the digits array for this detector
467 AliDetector::ResetDigits ();
470 //____________________________________________
471 void AliTOF::ResetSDigits ()
474 // Reset number of sdigits and the sdigits array for this detector
479 //_____________________________________________________________________________
483 // Initialise TOF detector after it has been built
485 // Set id of TOF sensitive volume
486 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
490 TDirectory* saveDir = gDirectory;
491 AliRunLoader::GetRunLoader()->CdGAFile();
492 fTOFGeometry->Write("TOFGeometry");
497 //____________________________________________________________________________
498 void AliTOF::MakeBranch(Option_t* option)
501 // Initializes the Branches of the TOF inside the
502 // trees written for each event.
503 // AliDetector::MakeBranch initializes just the
504 // Branch inside TreeH. Here we add the branches in
505 // TreeD, TreeS and TreeR.
507 const char *oH = strstr(option,"H");
508 if (fLoader->TreeH() && oH)
512 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
513 else fHits = new TClonesArray("AliTOFhit", 1000);
517 AliDetector::MakeBranch(option);
519 Int_t buffersize = 4000;
520 Char_t branchname[10];
521 sprintf(branchname,"%s",GetName());
523 const char *oD = strstr(option,"D");
524 const char *oS = strstr(option,"S");
525 const char *oR = strstr(option,"R");
527 if (fLoader->TreeD() && oD){
528 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
529 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
532 if (fLoader->TreeS() && oS){
533 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
534 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
537 if (fLoader->TreeR() && oR){
538 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
539 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
543 if (fReconParticles && fLoader->TreeR() && oR){
544 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
549 //____________________________________________________________________________
550 void AliTOF::Makehits(Bool_t hits)
552 // default argument used, see AliTOF.h
553 // Enable/Disable the writing of the TOF-hits branch
555 // by default : enabled for TOFv1, v2, v3, v4, v5
556 // disabled for TOFv0
558 if (hits && (IsVersion()!=0))
559 fIdSens = gMC->VolId("FPAD");
561 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
564 //____________________________________________________________________________
565 void AliTOF::FinishEvent()
570 //____________________________________________________________________________
571 void AliTOF::Hits2SDigits()
574 // Use the TOF SDigitizer to make TOF SDigits
577 // AliInfo("Start...");
579 AliRunLoader * rl = fLoader->GetRunLoader();
580 AliTOFSDigitizer sd((rl->GetFileName()).Data());
581 ToAliDebug(1, sd.Print(""));
587 //____________________________________________________________________________
588 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
591 // Use the TOF SDigitizer to make TOF SDigits
594 if ((evNumber2-evNumber1)==1)
595 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
596 if ((evNumber2-evNumber1)>1)
597 AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
599 AliRunLoader * rl = fLoader->GetRunLoader();
600 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
601 ToAliDebug(1, sd.Print(""));
607 //___________________________________________________________________________
608 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
610 return new AliTOFDigitizer(manager);
613 //___________________________________________________________________________
614 Bool_t AliTOF::CheckOverlap(Int_t* vol, Int_t* digit,Int_t Track)
617 // Checks if 2 or more hits belong to the same pad.
618 // In this case the data assigned to the digit object
619 // are the ones of the first hit in order of Time.
620 // 2 hits from the same track on the same pad are collected.
621 // Called only by Hits2SDigits.
622 // This procedure has to be optimized in the next TOF release.
625 Bool_t overlap = kFALSE;
628 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
629 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
630 currentDigit->GetLocation(vol2);
632 // check on digit volume
633 for (Int_t i=0;i<=4;i++){
635 if (vol[i]!=vol2[i]) idem=kFALSE;}
637 if (idem){ // same pad fired
638 Int_t tdc2 = digit[0];
639 Int_t tdc1 = currentDigit->GetTdc();
641 // we separate two digits on the same pad if
642 // they are separated in time by at least 25 ns
643 // remember that tdc time is given in ps
645 if (TMath::Abs(tdc1-tdc2)<25000){
646 // in case of overlap we take the earliest
648 currentDigit->SetTdc(tdc2);
649 currentDigit->SetAdc(digit[1]);
652 currentDigit->SetTdc(tdc1);
653 currentDigit->SetAdc(digit[1]);
655 currentDigit->AddTrack(Track); // add track number in the track array
661 } // close if (idem) -> two digits on the same TOF pad
663 } // end loop on existing sdigits
667 //____________________________________________________________________________
668 void AliTOF::Digits2Raw()
671 // Starting from the TOF digits, writes the Raw Data objects
674 TStopwatch stopwatch;
677 fLoader->LoadDigits();
679 TTree* digits = fLoader->TreeD();
681 AliError("no digits tree");
685 fgTOFRawWriter.Clear();
686 fgTOFRawWriter.SetVerbose(0);
687 if (fgTOFRawWriter.GetPackedAcquisitionMode()) {
688 if(fgTOFRawWriter.GetMatchingWindow()>8192)
689 AliWarning(Form("You are running in packing mode and the matching window is %.2f ns, i.e. greater than 199.8848 ns",
690 fgTOFRawWriter.GetMatchingWindow()*AliTOFGeometry::TdcBinWidth()*1.e-03));
692 fgTOFRawWriter.Clear();
694 AliDebug(1,"Formatting raw data for TOF");
696 fgTOFRawWriter.RawDataTOF(digits->GetBranch("TOF"));
698 fLoader->UnloadDigits();
700 AliDebug(1, Form("Execution time to write TOF raw data : R:%.2fs C:%.2fs",
701 stopwatch.RealTime(),stopwatch.CpuTime()));
705 //____________________________________________________________________________
706 void AliTOF::RecreateSDigitsArray() {
708 // delete TClonesArray fSDigits and create it again
709 // needed for backward compatability with PPR test production
713 //____________________________________________________________________________
714 void AliTOF::CreateSDigitsArray() {
716 // create TClonesArray fSDigits
717 // needed for backward compatability with PPR test production
719 fSDigits = new TClonesArray("AliTOFSDigit", 1000);