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 "AliRawReader.h"
58 //#include "AliTOFDDLRawData.h"
59 #include "AliTOFDigitizer.h"
60 #include "AliTOFdigit.h"
61 #include "AliTOFhitT0.h"
62 #include "AliTOFhit.h"
63 #include "AliTOFGeometry.h"
64 #include "AliTOFSDigitizer.h"
65 #include "AliTOFSDigit.h"
67 #include "AliTOFrawData.h"
68 #include "AliTOFRawStream.h"
73 extern TVirtualMC *gMC;
75 extern AliRun *gAlice;
79 //_____________________________________________________________________________
91 fTOFRawWriter(AliTOFDDLRawData())
94 // Default constructor
97 //by default all sectors switched on
98 for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
106 //_____________________________________________________________________________
107 AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
109 AliDetector(name,title),
115 fReconParticles(0x0),
120 fTOFRawWriter(AliTOFDDLRawData())
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 * const 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 const Int_t kSize=80;
224 //char * tempo = new char[80] ;
227 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
228 snprintf(tempo,kSize, "%sDigitizers container",GetName() ) ;
229 fDTask = new TTask(GetName(), tempo);
230 aliceDi->Add(fDTask) ;
232 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
233 snprintf(tempo,kSize, "%sReconstructioner container",GetName() ) ;
234 fReTask = new TTask(GetName(), tempo);
235 aliceRe->Add(fReTask) ;
239 // creates the TOF geometry folder
240 geomF->AddFolder("TOF", "Geometry for TOF") ;
243 //_____________________________________________________________________________
247 // it remove also the alice folder
248 // and task that TOF creates instead of AliRun
249 /* PH Temporarily commented because of problems
250 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
275 fReconParticles->Delete ();
276 delete fReconParticles;
282 //_____________________________________________________________________________
283 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
287 // new with placement used
289 TClonesArray &lhits = *fHits;
290 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
293 //_____________________________________________________________________________
294 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
298 // new with placement used
300 TClonesArray &lhits = *fHits;
301 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
304 //_____________________________________________________________________________
305 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Int_t *digits)
309 // new with placement used
311 TClonesArray &ldigits = *fDigits;
312 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
315 //_____________________________________________________________________________
316 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Int_t *digits)
323 TClonesArray &lSDigits = *fSDigits;
324 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
327 //_____________________________________________________________________________
328 void AliTOF::SetTreeAddress ()
330 // Set branch address for the Hits and Digits Tree.
332 if (fLoader->TreeH())
336 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
337 else fHits = new TClonesArray("AliTOFhit", 1000);
340 AliDetector::SetTreeAddress ();
344 if (fLoader->TreeS () )
346 branch = fLoader->TreeS ()->GetBranch ("TOF");
348 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
349 branch->SetAddress (&fSDigits);
353 if (fLoader->TreeR() )
355 branch = fLoader->TreeR()->GetBranch("TOF");
358 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
359 branch->SetAddress(&fReconParticles);
364 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
366 branch = fLoader->TreeR()->GetBranch("TOF");
369 branch->SetAddress(&fReconParticles) ;
375 //_____________________________________________________________________________
376 void AliTOF::CreateGeometry()
379 // Common geometry code
383 <img src="picts/AliTOFv23.gif">
390 if (IsVersion()==8) {
392 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
393 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
394 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
396 // TOF module internal definitions
397 TOFpc(xTof, yTof, zTof);
399 } else if (IsVersion()==7) {
401 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
402 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
403 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
405 // TOF module internal definitions
406 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
410 Float_t wall = 4.;//cm // frame inbetween TOF modules
412 // Sizes of TOF module with its support etc..
413 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
414 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
416 // TOF module internal definitions
417 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
423 //___________________________________________
424 void AliTOF::ResetHits ()
426 // Reset number of clusters and the cluster array for this detector
427 AliDetector::ResetHits ();
430 //____________________________________________
431 void AliTOF::ResetDigits ()
434 // Reset number of digits and the digits array for this detector
435 AliDetector::ResetDigits ();
438 //____________________________________________
439 void AliTOF::ResetSDigits ()
442 // Reset number of sdigits and the sdigits array for this detector
447 //_____________________________________________________________________________
451 // Initialise TOF detector after it has been built
453 // Set id of TOF sensitive volume
454 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
458 TDirectory* saveDir = gDirectory;
459 AliRunLoader::Instance()->CdGAFile();
460 fTOFGeometry->Write("TOFGeometry");
465 //____________________________________________________________________________
466 void AliTOF::MakeBranch(Option_t* option)
469 // Initializes the Branches of the TOF inside the
470 // trees written for each event.
471 // AliDetector::MakeBranch initializes just the
472 // Branch inside TreeH. Here we add the branches in
473 // TreeD, TreeS and TreeR.
475 const char *oH = strstr(option,"H");
476 if (fLoader->TreeH() && oH)
480 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
481 else fHits = new TClonesArray("AliTOFhit", 1000);
485 AliDetector::MakeBranch(option);
487 Int_t buffersize = 4000;
488 const Int_t kSize=10;
489 Char_t branchname[kSize];
490 snprintf(branchname,kSize,"%s",GetName());
492 const char *oD = strstr(option,"D");
493 const char *oS = strstr(option,"S");
494 const char *oR = strstr(option,"R");
496 if (fLoader->TreeD() && oD){
497 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
498 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
501 if (fLoader->TreeS() && oS){
502 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
503 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
506 if (fLoader->TreeR() && oR){
507 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
508 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
512 if (fReconParticles && fLoader->TreeR() && oR){
513 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
518 //____________________________________________________________________________
519 void AliTOF::Makehits(Bool_t hits)
521 // default argument used, see AliTOF.h
522 // Enable/Disable the writing of the TOF-hits branch
524 // by default : enabled for TOFv1, v2, v3, v4, v5
525 // disabled for TOFv0
527 if (hits && (IsVersion()!=0))
528 fIdSens = gMC->VolId("FPAD");
530 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
533 //____________________________________________________________________________
534 void AliTOF::FinishEvent()
539 //____________________________________________________________________________
540 void AliTOF::Hits2SDigits()
543 // Use the TOF SDigitizer to make TOF SDigits
546 // AliInfo("Start...");
548 AliRunLoader * rl = fLoader->GetRunLoader();
549 AliDebug(2,"Initialized runLoader");
550 AliTOFSDigitizer sd((rl->GetFileName()).Data());
551 AliDebug(2,"Initialized TOF sdigitizer");
552 //ToAliDebug(1, sd.Print(""));
553 //AliInfo("ToAliDebug");
558 AliDebug(2,"I am sorting from AliTOF class");
562 //____________________________________________________________________________
563 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
566 // Use the TOF SDigitizer to make TOF SDigits
569 if ((evNumber2-evNumber1)==1)
570 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
571 if ((evNumber2-evNumber1)>1)
572 AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
574 AliRunLoader * rl = fLoader->GetRunLoader();
575 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
576 ToAliDebug(1, sd.Print(""));
582 //___________________________________________________________________________
583 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
585 AliDebug(2,"I am creating the TOF digitizer");
586 return new AliTOFDigitizer(manager);
589 //___________________________________________________________________________
590 Bool_t AliTOF::CheckOverlap(const Int_t * const vol,
591 Int_t* digit,Int_t Track)
594 // Checks if 2 or more hits belong to the same pad.
595 // In this case the data assigned to the digit object
596 // are the ones of the first hit in order of Time.
597 // 2 hits from the same track on the same pad are collected.
598 // Called only by Hits2SDigits.
599 // This procedure has to be optimized in the next TOF release.
602 Bool_t overlap = kFALSE;
605 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
606 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
607 currentDigit->GetLocation(vol2);
609 // check on digit volume
610 for (Int_t i=0;i<=4;i++){
612 if (vol[i]!=vol2[i]) idem=kFALSE;}
614 if (idem){ // same pad fired
615 Int_t tdc2 = digit[0];
616 Int_t tdc1 = currentDigit->GetTdc();
618 // we separate two digits on the same pad if
619 // they are separated in time by at least 25 ns
620 // remember that tdc time is given in ps
622 if (TMath::Abs(tdc1-tdc2)<25000){
623 // in case of overlap we take the earliest
625 currentDigit->SetTdc(tdc2);
626 currentDigit->SetAdc(digit[1]);
629 currentDigit->SetTdc(tdc1);
630 currentDigit->SetAdc(digit[1]);
632 currentDigit->AddTrack(Track); // add track number in the track array
638 } // close if (idem) -> two digits on the same TOF pad
640 } // end loop on existing sdigits
644 //____________________________________________________________________________
645 void AliTOF::Digits2Raw()
648 // Starting from the TOF digits, writes the Raw Data objects
651 TStopwatch stopwatch;
654 fLoader->LoadDigits();
656 TTree* digits = fLoader->TreeD();
658 AliError("no digits tree");
662 //AliTOFDDLRawData rawWriter;
663 fTOFRawWriter.Clear();
664 fTOFRawWriter.SetVerbose(0);
665 if (fTOFRawWriter.GetPackedAcquisitionMode()) {
666 if(fTOFRawWriter.GetMatchingWindow()>8192)
667 AliWarning(Form("You are running in packing mode and the matching window is %.2f ns, i.e. greater than 199.8848 ns",
668 fTOFRawWriter.GetMatchingWindow()*AliTOFGeometry::TdcBinWidth()*1.e-03));
671 AliDebug(1,"Formatting raw data for TOF");
673 fTOFRawWriter.RawDataTOF(digits->GetBranch("TOF"));
675 fLoader->UnloadDigits();
677 AliDebug(1, Form("Execution time to write TOF raw data : R:%.2fs C:%.2fs",
678 stopwatch.RealTime(),stopwatch.CpuTime()));
682 //____________________________________________________________________________
683 void AliTOF::RecreateSDigitsArray() {
685 // delete TClonesArray fSDigits and create it again
686 // needed for backward compatability with PPR test production
690 //____________________________________________________________________________
691 void AliTOF::CreateSDigitsArray() {
693 // create TClonesArray fSDigits
694 // needed for backward compatability with PPR test production
696 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
698 //____________________________________________________________________________
699 Bool_t AliTOF::Raw2SDigits(AliRawReader* rawReader)
702 // Converts raw data to sdigits for TOF
705 TStopwatch stopwatch;
708 if(!GetLoader()->TreeS()) {MakeTree("S"); MakeBranch("S");}
709 //TClonesArray &aSDigits = *fSDigits;
711 AliTOFRawStream tofRawStream = AliTOFRawStream();
712 tofRawStream.Raw2SDigits(rawReader, fSDigits);
714 GetLoader()->TreeS()->Fill(); GetLoader()->WriteSDigits("OVERWRITE");//write out sdigits
715 Int_t nSDigits = fSDigits->GetEntries();
719 AliDebug(1, Form("Got %d TOF sdigits", nSDigits));
720 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF sdigit tree : R:%.2fs C:%.2fs",
721 stopwatch.RealTime(),stopwatch.CpuTime()));
727 //____________________________________________________________________________
728 void AliTOF::Raw2Digits(AliRawReader* rawReader)
731 // Converts raw data to digits for TOF
734 TStopwatch stopwatch;
737 if(!GetLoader()->TreeD()) {MakeTree("D"); MakeBranch("D");}
738 //TClonesArray &aDigits = *fDigits;
740 AliTOFRawStream tofRawStream = AliTOFRawStream();
741 tofRawStream.Raw2Digits(rawReader, fDigits);
743 GetLoader()->TreeD()->Fill(); GetLoader()->WriteDigits("OVERWRITE");//write out digits
744 Int_t nDigits = fDigits->GetEntries();
748 AliDebug(1, Form("Got %d TOF digits", nDigits));
749 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
750 stopwatch.RealTime(),stopwatch.CpuTime()));