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"
71 // extern TROOT *gROOT;
72 // extern TVirtualMC *TVirtualMC::GetMC();
74 // extern AliRun *gAlice;
78 //_____________________________________________________________________________
88 fTOFRawWriter(AliTOFDDLRawData())
91 // Default constructor
94 //by default all sectors switched on
95 for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
103 //_____________________________________________________________________________
104 AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
106 AliDetector(name,title),
110 fReconParticles(0x0),
115 fTOFRawWriter(AliTOFDDLRawData())
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 * const 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];
191 //_____________________________________________________________________________
192 void AliTOF::CreateTOFFolders()
194 // create the ALICE TFolder
195 // create the ALICE main TFolder
196 // to be done by AliRun
198 TFolder * alice = new TFolder();
199 alice->SetNameTitle("FPAlice", "Alice Folder") ;
200 gROOT->GetListOfBrowsables()->Add(alice) ;
202 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
203 // make it the owner of the objects that it contains
206 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
208 // creates the TOF geometry folder
209 geomF->AddFolder("TOF", "Geometry for TOF") ;
212 //_____________________________________________________________________________
216 // it remove also the alice folder
217 /* PH Temporarily commented because of problems
218 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
243 fReconParticles->Delete ();
244 delete fReconParticles;
250 //_____________________________________________________________________________
251 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
255 // new with placement used
257 TClonesArray &lhits = *fHits;
258 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
261 //_____________________________________________________________________________
262 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
266 // new with placement used
268 TClonesArray &lhits = *fHits;
269 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
272 //_____________________________________________________________________________
273 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Int_t *digits)
277 // new with placement used
279 TClonesArray &ldigits = *fDigits;
280 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
283 //_____________________________________________________________________________
284 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Int_t *digits)
291 TClonesArray &lSDigits = *fSDigits;
292 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
295 //_____________________________________________________________________________
296 void AliTOF::SetTreeAddress ()
298 // Set branch address for the Hits and Digits Tree.
300 if (fLoader->TreeH())
304 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
305 else fHits = new TClonesArray("AliTOFhit", 1000);
308 AliDetector::SetTreeAddress ();
312 if (fLoader->TreeS () )
314 branch = fLoader->TreeS ()->GetBranch ("TOF");
316 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
317 branch->SetAddress (&fSDigits);
321 if (fLoader->TreeR() )
323 branch = fLoader->TreeR()->GetBranch("TOF");
326 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
327 branch->SetAddress(&fReconParticles);
332 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
334 branch = fLoader->TreeR()->GetBranch("TOF");
337 branch->SetAddress(&fReconParticles) ;
343 //_____________________________________________________________________________
344 void AliTOF::CreateGeometry()
347 // Common geometry code
351 <img src="picts/AliTOFv23.gif">
358 if (IsVersion()==8) {
360 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
361 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
362 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
364 // TOF module internal definitions
365 TOFpc(xTof, yTof, zTof);
367 } else if (IsVersion()==7) {
369 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
370 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
371 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
373 // TOF module internal definitions
374 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
378 Float_t wall = 4.;//cm // frame inbetween TOF modules
380 // Sizes of TOF module with its support etc..
381 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
382 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
384 // TOF module internal definitions
385 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
391 //___________________________________________
392 void AliTOF::ResetHits ()
394 // Reset number of clusters and the cluster array for this detector
395 AliDetector::ResetHits ();
398 //____________________________________________
399 void AliTOF::ResetDigits ()
402 // Reset number of digits and the digits array for this detector
403 AliDetector::ResetDigits ();
406 //____________________________________________
407 void AliTOF::ResetSDigits ()
410 // Reset number of sdigits and the sdigits array for this detector
415 //_____________________________________________________________________________
419 // Initialise TOF detector after it has been built
421 // Set id of TOF sensitive volume
422 if (IsVersion() !=0) fIdSens=TVirtualMC::GetMC()->VolId("FPAD");
426 TDirectory* saveDir = gDirectory;
427 AliRunLoader::Instance()->CdGAFile();
428 fTOFGeometry->Write("TOFGeometry");
433 //____________________________________________________________________________
434 void AliTOF::MakeBranch(Option_t* option)
437 // Initializes the Branches of the TOF inside the
438 // trees written for each event.
439 // AliDetector::MakeBranch initializes just the
440 // Branch inside TreeH. Here we add the branches in
441 // TreeD, TreeS and TreeR.
443 const char *oH = strstr(option,"H");
444 if (fLoader->TreeH() && oH)
448 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
449 else fHits = new TClonesArray("AliTOFhit", 1000);
453 AliDetector::MakeBranch(option);
455 Int_t buffersize = 4000;
456 const Int_t kSize=10;
457 Char_t branchname[kSize];
458 snprintf(branchname,kSize,"%s",GetName());
460 const char *oD = strstr(option,"D");
461 const char *oS = strstr(option,"S");
462 const char *oR = strstr(option,"R");
464 if (fLoader->TreeD() && oD){
465 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
466 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
469 if (fLoader->TreeS() && oS){
470 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
471 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
474 if (fLoader->TreeR() && oR){
475 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
476 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
480 if (fReconParticles && fLoader->TreeR() && oR){
481 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
486 //____________________________________________________________________________
487 void AliTOF::Makehits(Bool_t hits)
489 // default argument used, see AliTOF.h
490 // Enable/Disable the writing of the TOF-hits branch
492 // by default : enabled for TOFv1, v2, v3, v4, v5
493 // disabled for TOFv0
495 if (hits && (IsVersion()!=0))
496 fIdSens = TVirtualMC::GetMC()->VolId("FPAD");
498 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
501 //____________________________________________________________________________
502 void AliTOF::FinishEvent()
507 //____________________________________________________________________________
508 void AliTOF::Hits2SDigits()
511 // Use the TOF SDigitizer to make TOF SDigits
514 // AliInfo("Start...");
516 AliRunLoader * rl = fLoader->GetRunLoader();
517 AliDebug(2,"Initialized runLoader");
518 AliTOFSDigitizer sd((rl->GetFileName()).Data());
519 AliDebug(2,"Initialized TOF sdigitizer");
520 //ToAliDebug(1, sd.Print(""));
521 //AliInfo("ToAliDebug");
523 //sd.Digitize("all") ;
524 sd.Digitize("partial") ;
526 AliDebug(2,"I am sorting from AliTOF class");
530 //____________________________________________________________________________
531 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
534 // Use the TOF SDigitizer to make TOF SDigits
537 if ((evNumber2-evNumber1)==1)
538 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
539 if ((evNumber2-evNumber1)>1)
540 AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
542 AliRunLoader * rl = fLoader->GetRunLoader();
543 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
544 ToAliDebug(1, sd.Print(""));
550 //___________________________________________________________________________
551 AliDigitizer* AliTOF::CreateDigitizer(AliDigitizationInput* digInput) const
553 AliDebug(2,"I am creating the TOF digitizer");
554 return new AliTOFDigitizer(digInput);
557 //___________________________________________________________________________
558 Bool_t AliTOF::CheckOverlap(const Int_t * const vol,
559 Int_t* digit,Int_t Track)
562 // Checks if 2 or more hits belong to the same pad.
563 // In this case the data assigned to the digit object
564 // are the ones of the first hit in order of Time.
565 // 2 hits from the same track on the same pad are collected.
566 // Called only by Hits2SDigits.
567 // This procedure has to be optimized in the next TOF release.
570 Bool_t overlap = kFALSE;
573 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
574 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
575 currentDigit->GetLocation(vol2);
577 // check on digit volume
578 for (Int_t i=0;i<=4;i++){
580 if (vol[i]!=vol2[i]) idem=kFALSE;}
582 if (idem){ // same pad fired
583 Int_t tdc2 = digit[0];
584 Int_t tdc1 = currentDigit->GetTdc();
586 // we separate two digits on the same pad if
587 // they are separated in time by at least 25 ns
588 // remember that tdc time is given in ps
590 if (TMath::Abs(tdc1-tdc2)<25000){
591 // in case of overlap we take the earliest
593 currentDigit->SetTdc(tdc2);
594 currentDigit->SetAdc(digit[1]);
597 currentDigit->SetTdc(tdc1);
598 currentDigit->SetAdc(digit[1]);
600 currentDigit->AddTrack(Track); // add track number in the track array
606 } // close if (idem) -> two digits on the same TOF pad
608 } // end loop on existing sdigits
612 //____________________________________________________________________________
613 void AliTOF::Digits2Raw()
616 // Starting from the TOF digits, writes the Raw Data objects
619 TStopwatch stopwatch;
622 fLoader->LoadDigits();
624 TTree* digits = fLoader->TreeD();
626 AliError("no digits tree");
630 //AliTOFDDLRawData rawWriter;
631 fTOFRawWriter.Clear();
632 fTOFRawWriter.SetVerbose(0);
633 if (fTOFRawWriter.GetPackedAcquisitionMode()) {
634 if(fTOFRawWriter.GetMatchingWindow()>8192)
635 AliWarning(Form("You are running in packing mode and the matching window is %.2f ns, i.e. greater than 199.8848 ns",
636 fTOFRawWriter.GetMatchingWindow()*AliTOFGeometry::TdcBinWidth()*1.e-03));
639 AliDebug(1,"Formatting raw data for TOF");
641 fTOFRawWriter.RawDataTOF(digits->GetBranch("TOF"));
643 fLoader->UnloadDigits();
645 AliDebug(1, Form("Execution time to write TOF raw data : R:%.2fs C:%.2fs",
646 stopwatch.RealTime(),stopwatch.CpuTime()));
650 //____________________________________________________________________________
651 void AliTOF::RecreateSDigitsArray() {
653 // delete TClonesArray fSDigits and create it again
654 // needed for backward compatability with PPR test production
658 //____________________________________________________________________________
659 void AliTOF::CreateSDigitsArray() {
661 // create TClonesArray fSDigits
662 // needed for backward compatability with PPR test production
664 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
666 //____________________________________________________________________________
667 Bool_t AliTOF::Raw2SDigits(AliRawReader* rawReader)
670 // Converts raw data to sdigits for TOF
673 TStopwatch stopwatch;
676 if(!GetLoader()->TreeS()) {MakeTree("S"); MakeBranch("S");}
677 //TClonesArray &aSDigits = *fSDigits;
679 AliTOFRawStream tofRawStream = AliTOFRawStream();
680 tofRawStream.Raw2SDigits(rawReader, fSDigits);
682 GetLoader()->TreeS()->Fill(); GetLoader()->WriteSDigits("OVERWRITE");//write out sdigits
683 Int_t nSDigits = fSDigits->GetEntries();
687 AliDebug(1, Form("Got %d TOF sdigits", nSDigits));
688 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF sdigit tree : R:%.2fs C:%.2fs",
689 stopwatch.RealTime(),stopwatch.CpuTime()));
695 //____________________________________________________________________________
696 void AliTOF::Raw2Digits(AliRawReader* rawReader)
699 // Converts raw data to digits for TOF
702 TStopwatch stopwatch;
705 if(!GetLoader()->TreeD()) {MakeTree("D"); MakeBranch("D");}
706 //TClonesArray &aDigits = *fDigits;
708 AliTOFRawStream tofRawStream = AliTOFRawStream();
709 tofRawStream.Raw2Digits(rawReader, fDigits);
711 GetLoader()->TreeD()->Fill(); GetLoader()->WriteDigits("OVERWRITE");//write out digits
712 Int_t nDigits = fDigits->GetEntries();
716 AliDebug(1, Form("Got %d TOF digits", nDigits));
717 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
718 stopwatch.RealTime(),stopwatch.CpuTime()));