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"
74 extern TVirtualMC *gMC;
76 extern AliRun *gAlice;
80 //_____________________________________________________________________________
92 fTOFRawWriter(AliTOFDDLRawData())
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),
121 fTOFRawWriter(AliTOFDDLRawData())
124 // AliTOF standard constructor
126 // Here are fixed some important parameters
129 // Initialization of hits, sdigits and digits array
130 // added option for time zero analysis
132 fTOFGeometry = new AliTOFGeometry();
134 //by default all sectors switched on
135 for (Int_t ii=0; ii<18; ii++) fTOFSectors[ii]=0;
137 if (strstr(option,"tzero")){
138 fHits = new TClonesArray("AliTOFhitT0", 1000);
140 // AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
142 fHits = new TClonesArray("AliTOFhit", 1000);
146 AliFatal("gAlice==0 !");
149 AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
151 if (mcApplication->GetHitLists())
152 mcApplication->AddHitList(fHits);
153 else AliError("gAlice->GetHitLists()==0");
156 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
157 fDigits = new TClonesArray("AliTOFdigit", 1000);
160 // Digitization parameters
162 // (Transfer Functions to be inserted here)
164 //PH SetMarkerColor(7);
165 //PH SetMarkerStyle(2);
166 //PH SetMarkerSize(0.4);
169 //fGapA = 4.; //cm Gap beetween tilted strip in A-type plate
170 //fGapB = 6.; //cm Gap beetween tilted strip in B-type plate
172 // Physical performances
173 //fTimeRes = 100.;//ps
174 //fChrgRes = 100.;//pC
178 //____________________________________________________________________________
179 void AliTOF::SetTOFSectors(Int_t * const sectors)
181 // Setter for partial/full TOF configuration
183 for(Int_t isec=0;isec<18;isec++){
184 fTOFSectors[isec]=sectors[isec];
187 //____________________________________________________________________________
188 void AliTOF::GetTOFSectors(Int_t *sectors) const
190 // Getter for partial/full TOF configuration
192 for(Int_t isec=0;isec<18;isec++){
193 sectors[isec]=fTOFSectors[isec];
197 //_____________________________________________________________________________
198 void AliTOF::CreateTOFFolders()
200 // create the ALICE TFolder
201 // create the ALICE TTasks
202 // create the ALICE main TFolder
203 // to be done by AliRun
205 TFolder * alice = new TFolder();
206 alice->SetNameTitle("FPAlice", "Alice Folder") ;
207 gROOT->GetListOfBrowsables()->Add(alice) ;
209 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
210 // make it the owner of the objects that it contains
213 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
214 TFolder * aliceT = alice->AddFolder("tasks", "Alice tasks Folder") ;
215 // make it the owner of the objects that it contains
218 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
219 aliceT->Add(aliceDi);
221 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
222 aliceT->Add(aliceRe);
224 const Int_t kSize=80;
225 //char * tempo = new char[80] ;
228 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
229 snprintf(tempo,kSize, "%sDigitizers container",GetName() ) ;
230 fDTask = new TTask(GetName(), tempo);
231 aliceDi->Add(fDTask) ;
233 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
234 snprintf(tempo,kSize, "%sReconstructioner container",GetName() ) ;
235 fReTask = new TTask(GetName(), tempo);
236 aliceRe->Add(fReTask) ;
240 // creates the TOF geometry folder
241 geomF->AddFolder("TOF", "Geometry for TOF") ;
244 //_____________________________________________________________________________
248 // it remove also the alice folder
249 // and task that TOF creates instead of AliRun
250 /* PH Temporarily commented because of problems
251 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
276 fReconParticles->Delete ();
277 delete fReconParticles;
283 //_____________________________________________________________________________
284 void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
288 // new with placement used
290 TClonesArray &lhits = *fHits;
291 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
294 //_____________________________________________________________________________
295 void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
299 // new with placement used
301 TClonesArray &lhits = *fHits;
302 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
305 //_____________________________________________________________________________
306 void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Int_t *digits)
310 // new with placement used
312 TClonesArray &ldigits = *fDigits;
313 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
316 //_____________________________________________________________________________
317 void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Int_t *digits)
324 TClonesArray &lSDigits = *fSDigits;
325 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
328 //_____________________________________________________________________________
329 void AliTOF::SetTreeAddress ()
331 // Set branch address for the Hits and Digits Tree.
333 if (fLoader->TreeH())
337 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
338 else fHits = new TClonesArray("AliTOFhit", 1000);
341 AliDetector::SetTreeAddress ();
345 if (fLoader->TreeS () )
347 branch = fLoader->TreeS ()->GetBranch ("TOF");
349 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
350 branch->SetAddress (&fSDigits);
354 if (fLoader->TreeR() )
356 branch = fLoader->TreeR()->GetBranch("TOF");
359 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
360 branch->SetAddress(&fReconParticles);
365 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
367 branch = fLoader->TreeR()->GetBranch("TOF");
370 branch->SetAddress(&fReconParticles) ;
376 //_____________________________________________________________________________
377 void AliTOF::CreateGeometry()
380 // Common geometry code
384 <img src="picts/AliTOFv23.gif">
391 if (IsVersion()==8) {
393 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
394 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
395 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
397 // TOF module internal definitions
398 TOFpc(xTof, yTof, zTof);
400 } else if (IsVersion()==7) {
402 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
403 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
404 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
406 // TOF module internal definitions
407 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
411 Float_t wall = 4.;//cm // frame inbetween TOF modules
413 // Sizes of TOF module with its support etc..
414 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
415 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
417 // TOF module internal definitions
418 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
423 //_____________________________________________________________________________
424 void AliTOF::DrawModule() const
427 // Draw a shaded view of the common part of the TOF geometry
430 AliInfo(" Drawing of AliTOF");
431 // Set everything unseen
432 gMC->Gsatt("*", "seen", -1);
434 // Set ALIC mother transparent
435 gMC->Gsatt("ALIC","SEEN",0);
437 // Set the volumes visible
438 gMC->Gsatt("FTOA","SEEN",1);
439 gMC->Gsatt("FTOB","SEEN",1);
440 gMC->Gsatt("FTOC","SEEN",1);
441 gMC->Gsatt("FLTA","SEEN",1);
442 gMC->Gsatt("FLTB","SEEN",1);
443 gMC->Gsatt("FLTC","SEEN",1);
444 gMC->Gsatt("FSTR","SEEN",1);
446 gMC->Gdopt("hide", "on");
447 gMC->Gdopt("shad", "on");
448 gMC->Gsatt("*", "fill", 7);
449 gMC->SetClipBox(".");
450 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
452 gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
453 gMC->Gdhead(1111, "Time Of Flight");
454 gMC->Gdman(18, 4, "MAN");
455 gMC->Gdopt("hide","off");
458 //___________________________________________
459 void AliTOF::ResetHits ()
461 // Reset number of clusters and the cluster array for this detector
462 AliDetector::ResetHits ();
465 //____________________________________________
466 void AliTOF::ResetDigits ()
469 // Reset number of digits and the digits array for this detector
470 AliDetector::ResetDigits ();
473 //____________________________________________
474 void AliTOF::ResetSDigits ()
477 // Reset number of sdigits and the sdigits array for this detector
482 //_____________________________________________________________________________
486 // Initialise TOF detector after it has been built
488 // Set id of TOF sensitive volume
489 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
493 TDirectory* saveDir = gDirectory;
494 AliRunLoader::Instance()->CdGAFile();
495 fTOFGeometry->Write("TOFGeometry");
500 //____________________________________________________________________________
501 void AliTOF::MakeBranch(Option_t* option)
504 // Initializes the Branches of the TOF inside the
505 // trees written for each event.
506 // AliDetector::MakeBranch initializes just the
507 // Branch inside TreeH. Here we add the branches in
508 // TreeD, TreeS and TreeR.
510 const char *oH = strstr(option,"H");
511 if (fLoader->TreeH() && oH)
515 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
516 else fHits = new TClonesArray("AliTOFhit", 1000);
520 AliDetector::MakeBranch(option);
522 Int_t buffersize = 4000;
523 const Int_t kSize=10;
524 Char_t branchname[kSize];
525 snprintf(branchname,kSize,"%s",GetName());
527 const char *oD = strstr(option,"D");
528 const char *oS = strstr(option,"S");
529 const char *oR = strstr(option,"R");
531 if (fLoader->TreeD() && oD){
532 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
533 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
536 if (fLoader->TreeS() && oS){
537 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
538 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
541 if (fLoader->TreeR() && oR){
542 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
543 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
547 if (fReconParticles && fLoader->TreeR() && oR){
548 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
553 //____________________________________________________________________________
554 void AliTOF::Makehits(Bool_t hits)
556 // default argument used, see AliTOF.h
557 // Enable/Disable the writing of the TOF-hits branch
559 // by default : enabled for TOFv1, v2, v3, v4, v5
560 // disabled for TOFv0
562 if (hits && (IsVersion()!=0))
563 fIdSens = gMC->VolId("FPAD");
565 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
568 //____________________________________________________________________________
569 void AliTOF::FinishEvent()
574 //____________________________________________________________________________
575 void AliTOF::Hits2SDigits()
578 // Use the TOF SDigitizer to make TOF SDigits
581 // AliInfo("Start...");
583 AliRunLoader * rl = fLoader->GetRunLoader();
584 AliDebug(2,"Initialized runLoader");
585 AliTOFSDigitizer sd((rl->GetFileName()).Data());
586 AliDebug(2,"Initialized TOF sdigitizer");
587 //ToAliDebug(1, sd.Print(""));
588 //AliInfo("ToAliDebug");
593 AliDebug(2,"I am sorting from AliTOF class");
597 //____________________________________________________________________________
598 void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
601 // Use the TOF SDigitizer to make TOF SDigits
604 if ((evNumber2-evNumber1)==1)
605 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1));
606 if ((evNumber2-evNumber1)>1)
607 AliDebug(1, Form("I am making sdigits for the events from the %dth to the %dth", evNumber1, evNumber2-1));
609 AliRunLoader * rl = fLoader->GetRunLoader();
610 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
611 ToAliDebug(1, sd.Print(""));
617 //___________________________________________________________________________
618 AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
620 AliDebug(2,"I am creating the TOF digitizer");
621 return new AliTOFDigitizer(manager);
624 //___________________________________________________________________________
625 Bool_t AliTOF::CheckOverlap(const Int_t * const vol,
626 Int_t* digit,Int_t Track)
629 // Checks if 2 or more hits belong to the same pad.
630 // In this case the data assigned to the digit object
631 // are the ones of the first hit in order of Time.
632 // 2 hits from the same track on the same pad are collected.
633 // Called only by Hits2SDigits.
634 // This procedure has to be optimized in the next TOF release.
637 Bool_t overlap = kFALSE;
640 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
641 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
642 currentDigit->GetLocation(vol2);
644 // check on digit volume
645 for (Int_t i=0;i<=4;i++){
647 if (vol[i]!=vol2[i]) idem=kFALSE;}
649 if (idem){ // same pad fired
650 Int_t tdc2 = digit[0];
651 Int_t tdc1 = currentDigit->GetTdc();
653 // we separate two digits on the same pad if
654 // they are separated in time by at least 25 ns
655 // remember that tdc time is given in ps
657 if (TMath::Abs(tdc1-tdc2)<25000){
658 // in case of overlap we take the earliest
660 currentDigit->SetTdc(tdc2);
661 currentDigit->SetAdc(digit[1]);
664 currentDigit->SetTdc(tdc1);
665 currentDigit->SetAdc(digit[1]);
667 currentDigit->AddTrack(Track); // add track number in the track array
673 } // close if (idem) -> two digits on the same TOF pad
675 } // end loop on existing sdigits
679 //____________________________________________________________________________
680 void AliTOF::Digits2Raw()
683 // Starting from the TOF digits, writes the Raw Data objects
686 TStopwatch stopwatch;
689 fLoader->LoadDigits();
691 TTree* digits = fLoader->TreeD();
693 AliError("no digits tree");
697 //AliTOFDDLRawData rawWriter;
698 fTOFRawWriter.Clear();
699 fTOFRawWriter.SetVerbose(0);
700 if (fTOFRawWriter.GetPackedAcquisitionMode()) {
701 if(fTOFRawWriter.GetMatchingWindow()>8192)
702 AliWarning(Form("You are running in packing mode and the matching window is %.2f ns, i.e. greater than 199.8848 ns",
703 fTOFRawWriter.GetMatchingWindow()*AliTOFGeometry::TdcBinWidth()*1.e-03));
706 AliDebug(1,"Formatting raw data for TOF");
708 fTOFRawWriter.RawDataTOF(digits->GetBranch("TOF"));
710 fLoader->UnloadDigits();
712 AliDebug(1, Form("Execution time to write TOF raw data : R:%.2fs C:%.2fs",
713 stopwatch.RealTime(),stopwatch.CpuTime()));
717 //____________________________________________________________________________
718 void AliTOF::RecreateSDigitsArray() {
720 // delete TClonesArray fSDigits and create it again
721 // needed for backward compatability with PPR test production
725 //____________________________________________________________________________
726 void AliTOF::CreateSDigitsArray() {
728 // create TClonesArray fSDigits
729 // needed for backward compatability with PPR test production
731 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
733 //____________________________________________________________________________
734 Bool_t AliTOF::Raw2SDigits(AliRawReader* rawReader)
737 // Converts raw data to sdigits for TOF
740 TStopwatch stopwatch;
743 if(!GetLoader()->TreeS()) {MakeTree("S"); MakeBranch("S");}
744 //TClonesArray &aSDigits = *fSDigits;
746 AliTOFRawStream tofRawStream = AliTOFRawStream();
747 tofRawStream.Raw2SDigits(rawReader, fSDigits);
749 GetLoader()->TreeS()->Fill(); GetLoader()->WriteSDigits("OVERWRITE");//write out sdigits
750 Int_t nSDigits = fSDigits->GetEntries();
754 AliDebug(1, Form("Got %d TOF sdigits", nSDigits));
755 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF sdigit tree : R:%.2fs C:%.2fs",
756 stopwatch.RealTime(),stopwatch.CpuTime()));
762 //____________________________________________________________________________
763 void AliTOF::Raw2Digits(AliRawReader* rawReader)
766 // Converts raw data to digits for TOF
769 TStopwatch stopwatch;
772 if(!GetLoader()->TreeD()) {MakeTree("D"); MakeBranch("D");}
773 //TClonesArray &aDigits = *fDigits;
775 AliTOFRawStream tofRawStream = AliTOFRawStream();
776 tofRawStream.Raw2Digits(rawReader, fDigits);
778 GetLoader()->TreeD()->Fill(); GetLoader()->WriteDigits("OVERWRITE");//write out digits
779 Int_t nDigits = fDigits->GetEntries();
783 AliDebug(1, Form("Got %d TOF digits", nDigits));
784 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
785 stopwatch.RealTime(),stopwatch.CpuTime()));