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>
46 #include <TVirtualMC.h>
47 #include <TStopwatch.h>
50 #include "AliLoader.h"
55 #include "AliRawReader.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"
66 #include "AliTOFrawData.h"
67 #include "AliTOFRawStream.h"
73 extern AliRun *gAlice;
77 //_____________________________________________________________________________
87 fTOFRawWriter(AliTOFDDLRawData())
90 // Default constructor
93 //by default all sectors switched on
94 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),
109 fReconParticles(0x0),
114 fTOFRawWriter(AliTOFDDLRawData())
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 * const 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];
190 //_____________________________________________________________________________
191 void AliTOF::CreateTOFFolders()
193 // create the ALICE TFolder
194 // create the ALICE main TFolder
195 // to be done by AliRun
197 TFolder * alice = new TFolder();
198 alice->SetNameTitle("FPAlice", "Alice Folder") ;
199 gROOT->GetListOfBrowsables()->Add(alice) ;
201 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
202 // make it the owner of the objects that it contains
205 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
207 // creates the TOF geometry folder
208 geomF->AddFolder("TOF", "Geometry for TOF") ;
211 //_____________________________________________________________________________
215 // it remove also the alice folder
216 /* PH Temporarily commented because of problems
217 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
242 fReconParticles->Delete ();
243 delete fReconParticles;
249 //_____________________________________________________________________________
250 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
254 // new with placement used
256 TClonesArray &lhits = *fHits;
257 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
260 //_____________________________________________________________________________
261 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
265 // new with placement used
267 TClonesArray &lhits = *fHits;
268 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
271 //_____________________________________________________________________________
272 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Int_t *digits)
276 // new with placement used
278 TClonesArray &ldigits = *fDigits;
279 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
282 //_____________________________________________________________________________
283 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Int_t *digits)
290 TClonesArray &lSDigits = *fSDigits;
291 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
294 //_____________________________________________________________________________
295 void AliTOF::SetTreeAddress ()
297 // Set branch address for the Hits and Digits Tree.
299 if (fLoader->TreeH())
303 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
304 else fHits = new TClonesArray("AliTOFhit", 1000);
307 AliDetector::SetTreeAddress ();
311 if (fLoader->TreeS () )
313 branch = fLoader->TreeS ()->GetBranch ("TOF");
315 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
316 branch->SetAddress (&fSDigits);
320 if (fLoader->TreeR() )
322 branch = fLoader->TreeR()->GetBranch("TOF");
325 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
326 branch->SetAddress(&fReconParticles);
331 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
333 branch = fLoader->TreeR()->GetBranch("TOF");
336 branch->SetAddress(&fReconParticles) ;
342 //_____________________________________________________________________________
343 void AliTOF::CreateGeometry()
346 // Common geometry code
350 <img src="picts/AliTOFv23.gif">
357 if (IsVersion()==8) {
359 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
360 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
361 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
363 // TOF module internal definitions
364 TOFpc(xTof, yTof, zTof);
366 } else if (IsVersion()==7) {
368 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
369 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
370 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
372 // TOF module internal definitions
373 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
377 Float_t wall = 4.;//cm // frame inbetween TOF modules
379 // Sizes of TOF module with its support etc..
380 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
381 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
383 // TOF module internal definitions
384 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
390 //___________________________________________
391 void AliTOF::ResetHits ()
393 // Reset number of clusters and the cluster array for this detector
394 AliDetector::ResetHits ();
397 //____________________________________________
398 void AliTOF::ResetDigits ()
401 // Reset number of digits and the digits array for this detector
402 AliDetector::ResetDigits ();
405 //____________________________________________
406 void AliTOF::ResetSDigits ()
409 // Reset number of sdigits and the sdigits array for this detector
414 //_____________________________________________________________________________
418 // Initialise TOF detector after it has been built
420 // Set id of TOF sensitive volume
421 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
425 TDirectory* saveDir = gDirectory;
426 AliRunLoader::Instance()->CdGAFile();
427 fTOFGeometry->Write("TOFGeometry");
432 //____________________________________________________________________________
433 void AliTOF::MakeBranch(Option_t* option)
436 // Initializes the Branches of the TOF inside the
437 // trees written for each event.
438 // AliDetector::MakeBranch initializes just the
439 // Branch inside TreeH. Here we add the branches in
440 // TreeD, TreeS and TreeR.
442 const char *oH = strstr(option,"H");
443 if (fLoader->TreeH() && oH)
447 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
448 else fHits = new TClonesArray("AliTOFhit", 1000);
452 AliDetector::MakeBranch(option);
454 Int_t buffersize = 4000;
455 const Int_t kSize=10;
456 Char_t branchname[kSize];
457 snprintf(branchname,kSize,"%s",GetName());
459 const char *oD = strstr(option,"D");
460 const char *oS = strstr(option,"S");
461 const char *oR = strstr(option,"R");
463 if (fLoader->TreeD() && oD){
464 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
465 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
468 if (fLoader->TreeS() && oS){
469 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
470 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
473 if (fLoader->TreeR() && oR){
474 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
475 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
479 if (fReconParticles && fLoader->TreeR() && oR){
480 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
485 //____________________________________________________________________________
486 void AliTOF::Makehits(Bool_t hits)
488 // default argument used, see AliTOF.h
489 // Enable/Disable the writing of the TOF-hits branch
491 // by default : enabled for TOFv1, v2, v3, v4, v5
492 // disabled for TOFv0
494 if (hits && (IsVersion()!=0))
495 fIdSens = gMC->VolId("FPAD");
497 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
500 //____________________________________________________________________________
501 void AliTOF::FinishEvent()
506 //____________________________________________________________________________
507 void AliTOF::Hits2SDigits()
510 // Use the TOF SDigitizer to make TOF SDigits
513 // AliInfo("Start...");
515 AliRunLoader * rl = fLoader->GetRunLoader();
516 AliDebug(2,"Initialized runLoader");
517 AliTOFSDigitizer sd((rl->GetFileName()).Data());
518 AliDebug(2,"Initialized TOF sdigitizer");
519 //ToAliDebug(1, sd.Print(""));
520 //AliInfo("ToAliDebug");
522 //sd.Digitize("all") ;
523 sd.Digitize("partial") ;
525 AliDebug(2,"I am sorting from AliTOF class");
529 //____________________________________________________________________________
530 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
533 // Use the TOF SDigitizer to make TOF SDigits
536 if ((evNumber2-evNumber1)==1)
537 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
538 if ((evNumber2-evNumber1)>1)
539 AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
541 AliRunLoader * rl = fLoader->GetRunLoader();
542 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
543 ToAliDebug(1, sd.Print(""));
549 //___________________________________________________________________________
550 AliDigitizer* AliTOF::CreateDigitizer(AliDigitizationInput* digInput) const
552 AliDebug(2,"I am creating the TOF digitizer");
553 return new AliTOFDigitizer(digInput);
556 //___________________________________________________________________________
557 Bool_t AliTOF::CheckOverlap(const Int_t * const vol,
558 Int_t* digit,Int_t Track)
561 // Checks if 2 or more hits belong to the same pad.
562 // In this case the data assigned to the digit object
563 // are the ones of the first hit in order of Time.
564 // 2 hits from the same track on the same pad are collected.
565 // Called only by Hits2SDigits.
566 // This procedure has to be optimized in the next TOF release.
569 Bool_t overlap = kFALSE;
572 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
573 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
574 currentDigit->GetLocation(vol2);
576 // check on digit volume
577 for (Int_t i=0;i<=4;i++){
579 if (vol[i]!=vol2[i]) idem=kFALSE;}
581 if (idem){ // same pad fired
582 Int_t tdc2 = digit[0];
583 Int_t tdc1 = currentDigit->GetTdc();
585 // we separate two digits on the same pad if
586 // they are separated in time by at least 25 ns
587 // remember that tdc time is given in ps
589 if (TMath::Abs(tdc1-tdc2)<25000){
590 // in case of overlap we take the earliest
592 currentDigit->SetTdc(tdc2);
593 currentDigit->SetAdc(digit[1]);
596 currentDigit->SetTdc(tdc1);
597 currentDigit->SetAdc(digit[1]);
599 currentDigit->AddTrack(Track); // add track number in the track array
605 } // close if (idem) -> two digits on the same TOF pad
607 } // end loop on existing sdigits
611 //____________________________________________________________________________
612 void AliTOF::Digits2Raw()
615 // Starting from the TOF digits, writes the Raw Data objects
618 TStopwatch stopwatch;
621 fLoader->LoadDigits();
623 TTree* digits = fLoader->TreeD();
625 AliError("no digits tree");
629 //AliTOFDDLRawData rawWriter;
630 fTOFRawWriter.Clear();
631 fTOFRawWriter.SetVerbose(0);
632 if (fTOFRawWriter.GetPackedAcquisitionMode()) {
633 if(fTOFRawWriter.GetMatchingWindow()>8192)
634 AliWarning(Form("You are running in packing mode and the matching window is %.2f ns, i.e. greater than 199.8848 ns",
635 fTOFRawWriter.GetMatchingWindow()*AliTOFGeometry::TdcBinWidth()*1.e-03));
638 AliDebug(1,"Formatting raw data for TOF");
640 fTOFRawWriter.RawDataTOF(digits->GetBranch("TOF"));
642 fLoader->UnloadDigits();
644 AliDebug(1, Form("Execution time to write TOF raw data : R:%.2fs C:%.2fs",
645 stopwatch.RealTime(),stopwatch.CpuTime()));
649 //____________________________________________________________________________
650 void AliTOF::RecreateSDigitsArray() {
652 // delete TClonesArray fSDigits and create it again
653 // needed for backward compatability with PPR test production
657 //____________________________________________________________________________
658 void AliTOF::CreateSDigitsArray() {
660 // create TClonesArray fSDigits
661 // needed for backward compatability with PPR test production
663 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
665 //____________________________________________________________________________
666 Bool_t AliTOF::Raw2SDigits(AliRawReader* rawReader)
669 // Converts raw data to sdigits for TOF
672 TStopwatch stopwatch;
675 if(!GetLoader()->TreeS()) {MakeTree("S"); MakeBranch("S");}
676 //TClonesArray &aSDigits = *fSDigits;
678 AliTOFRawStream tofRawStream = AliTOFRawStream();
679 tofRawStream.Raw2SDigits(rawReader, fSDigits);
681 GetLoader()->TreeS()->Fill(); GetLoader()->WriteSDigits("OVERWRITE");//write out sdigits
682 Int_t nSDigits = fSDigits->GetEntries();
686 AliDebug(1, Form("Got %d TOF sdigits", nSDigits));
687 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF sdigit tree : R:%.2fs C:%.2fs",
688 stopwatch.RealTime(),stopwatch.CpuTime()));
694 //____________________________________________________________________________
695 void AliTOF::Raw2Digits(AliRawReader* rawReader)
698 // Converts raw data to digits for TOF
701 TStopwatch stopwatch;
704 if(!GetLoader()->TreeD()) {MakeTree("D"); MakeBranch("D");}
705 //TClonesArray &aDigits = *fDigits;
707 AliTOFRawStream tofRawStream = AliTOFRawStream();
708 tofRawStream.Raw2Digits(rawReader, fDigits);
710 GetLoader()->TreeD()->Fill(); GetLoader()->WriteDigits("OVERWRITE");//write out digits
711 Int_t nDigits = fDigits->GetEntries();
715 AliDebug(1, Form("Got %d TOF digits", nDigits));
716 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
717 stopwatch.RealTime(),stopwatch.CpuTime()));