]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TOF/AliTOF.cxx
Coding conventions (Annalisa)
[u/mrichter/AliRoot.git] / TOF / AliTOF.cxx
... / ...
CommitLineData
1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Time Of Flight //
21// This class contains the basic functions for the Time Of Flight //
22// detector. Functions specific to one particular geometry are //
23// contained in the derived classes //
24// //
25// VERSIONE WITH 5 SYMMETRIC MODULES ALONG Z AXIS //
26// ============================================================ //
27// //
28// VERSION WITH HOLES FOR PHOS AND TRD IN SPACEFRAME WITH HOLES //
29// //
30// Volume sensibile : FPAD //
31// //
32// //
33// //
34// //
35///////////////////////////////////////////////////////////////////////////////
36// Begin_Html
37/*
38<img src="picts/AliTOFClass.gif">
39*/
40//End_Html
41
42
43
44#include <Riostream.h>
45#include <Rstrstream.h>
46#include <stdlib.h>
47
48#include <TBRIK.h>
49#include <TFile.h>
50#include <TFolder.h>
51#include <TNode.h>
52#include <TObject.h>
53#include <TROOT.h>
54#include <TSystem.h>
55#include <TTask.h>
56#include <TTree.h>
57#include <TVirtualMC.h>
58#include <TDirectory.h>
59
60#include "AliLog.h"
61#include "AliConfig.h"
62#include "AliHeader.h"
63#include "AliConst.h"
64#include "AliLoader.h"
65#include "AliMagF.h"
66#include "AliRun.h"
67#include "AliTOF.h"
68#include "AliTOFGeometry.h"
69#include "AliTOFGeometryV4.h"
70#include "AliTOFGeometryV5.h"
71#include "AliTOFSDigit.h"
72#include "AliTOFdigit.h"
73#include "AliTOFhit.h"
74#include "AliTOFhitT0.h"
75#include "AliMC.h"
76#include "AliTOFDigitizer.h"
77#include "AliTOFDDLRawData.h"
78#include "AliTOFcluster.h"
79
80ClassImp(AliTOF)
81
82//_____________________________________________________________________________
83AliTOF::AliTOF()
84{
85 //
86 // Default constructor
87 //
88 fFGeom = 0x0;
89 fDTask = 0x0;
90 fReTask = 0x0;
91 fIshunt = 0;
92 fSDigits = 0 ;
93 fNSDigits = 0;
94 fDigits = 0 ;
95 fReconParticles = 0x0;
96 fName="TOF";
97 fTZero = kFALSE;
98 fTOFGeometry = 0;
99}
100
101//_____________________________________________________________________________
102AliTOF::AliTOF(const char *name, const char *title, Option_t *option)
103 : AliDetector(name,title)
104{
105 //
106 // AliTOF standard constructor
107 //
108 // Here are fixed some important parameters
109 //
110
111 // Initialization of hits, sdigits and digits array
112 // added option for time zero analysis
113 fFGeom = 0x0; //skowron
114 fDTask = 0x0;
115 fReTask = 0x0;
116 fReconParticles= 0x0;
117 fTOFGeometry = new AliTOFGeometry();
118
119 if (strstr(option,"tzero")){
120 fHits = new TClonesArray("AliTOFhitT0", 1000);
121 fTZero = kTRUE;
122 AliWarning("tzero option requires AliTOFv4T0/AliTOFv5T0 as TOF version (check Your Config.C)");
123 }else{
124 fHits = new TClonesArray("AliTOFhit", 1000);
125 fTZero = kFALSE;
126 }
127 if (gAlice==0) {
128 AliFatal("gAlice==0 !");
129 }
130 if (gAlice->GetMCApp()->GetHitLists())
131 gAlice->GetMCApp()->AddHitList(fHits);
132 else AliError("gAlice->GetHitLists()==0");
133
134 fIshunt = 0;
135 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
136 fDigits = new TClonesArray("AliTOFdigit", 1000);
137 fNSDigits = 0;
138
139 fFGeom = 0x0;
140 fDTask = 0x0;
141 fReTask = 0x0;
142 fReconParticles = 0x0;
143
144 //
145 // Digitization parameters
146 //
147 // (Transfer Functions to be inserted here)
148 //
149 SetMarkerColor(7);
150 SetMarkerStyle(2);
151 SetMarkerSize(0.4);
152
153// Strip Parameters
154 //fGapA = 4.; //cm Gap beetween tilted strip in A-type plate
155 //fGapB = 6.; //cm Gap beetween tilted strip in B-type plate
156
157 // Physical performances
158 //fTimeRes = 100.;//ps
159 //fChrgRes = 100.;//pC
160
161}
162
163//_____________________________________________________________________________
164AliTOF::AliTOF(const AliTOF &source)
165 :AliDetector()
166{
167 // copy constructor
168
169 this->fReconParticles=source.fReconParticles;
170 this->fSDigits=source.fSDigits;
171 this->fTOFGeometry=source.fTOFGeometry;
172
173}
174
175//_____________________________________________________________________________
176AliTOF& AliTOF::operator=(const AliTOF &source)
177{
178 // ass. op.
179
180 this->fReconParticles=source.fReconParticles;
181 this->fSDigits=source.fSDigits;
182 this->fTOFGeometry=source.fTOFGeometry;
183 return *this;
184
185}
186
187//_____________________________________________________________________________
188void AliTOF::CreateTOFFolders()
189{
190 // create the ALICE TFolder
191 // create the ALICE TTasks
192 // create the ALICE main TFolder
193 // to be done by AliRun
194
195 TFolder * alice = new TFolder();
196 alice->SetNameTitle("FPAlice", "Alice Folder") ;
197 gROOT->GetListOfBrowsables()->Add(alice) ;
198
199 TFolder * aliceF = alice->AddFolder("folders", "Alice memory Folder") ;
200 // make it the owner of the objects that it contains
201 aliceF->SetOwner() ;
202 // geometry folder
203 TFolder * geomF = aliceF->AddFolder("Geometry", "Geometry objects") ;
204 TFolder * aliceT = alice->AddFolder("tasks", "Alice tasks Folder") ;
205 // make it the owner of the objects that it contains
206 aliceT->SetOwner() ;
207
208 TTask * aliceDi = new TTask("(S)Digitizer", "Alice SDigitizer & Digitizer") ;
209 aliceT->Add(aliceDi);
210
211 TTask * aliceRe = new TTask("Reconstructioner", "Alice Reconstructioner") ;
212 aliceT->Add(aliceRe);
213
214 char * tempo = new char[80] ;
215
216 // creates the TOF Digitizer and adds it to alice main (S)Digitizer task
217 sprintf(tempo, "%sDigitizers container",GetName() ) ;
218 fDTask = new TTask(GetName(), tempo);
219 aliceDi->Add(fDTask) ;
220
221 // creates the TOF reconstructioner and adds it to alice main Reconstructioner task
222 sprintf(tempo, "%sReconstructioner container",GetName() ) ;
223 fReTask = new TTask(GetName(), tempo);
224 aliceRe->Add(fReTask) ;
225
226 delete [] tempo ;
227
228 // creates the TOF geometry folder
229 geomF->AddFolder("TOF", "Geometry for TOF") ;
230}
231
232//_____________________________________________________________________________
233AliTOF::~AliTOF()
234{
235 // dtor:
236 // it remove also the alice folder
237 // and task that TOF creates instead of AliRun
238 /* PH Temporarily commented because of problems
239 TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ;
240 delete alice;
241 alice = 0;
242 */
243 if (fHits)
244 {
245 fHits->Delete ();
246 delete fHits;
247 fHits = 0;
248 }
249 if (fDigits)
250 {
251 fDigits->Delete ();
252 delete fDigits;
253 fDigits = 0;
254 }
255 if (fSDigits)
256 {
257 fSDigits->Delete();
258 delete fSDigits;
259 fSDigits = 0;
260 }
261
262 if (fReconParticles)
263 {
264 fReconParticles->Delete ();
265 delete fReconParticles;
266 fReconParticles = 0;
267 }
268
269}
270
271//_____________________________________________________________________________
272void AliTOF::AddHit(Int_t track, Int_t *vol, Float_t *hits)
273{
274 //
275 // Add a TOF hit
276 // new with placement used
277 //
278 TClonesArray &lhits = *fHits;
279 new(lhits[fNhits++]) AliTOFhit(fIshunt, track, vol, hits);
280}
281
282//_____________________________________________________________________________
283void AliTOF::AddT0Hit(Int_t track, Int_t *vol, Float_t *hits)
284{
285 //
286 // Add a TOF hit
287 // new with placement used
288 //
289 TClonesArray &lhits = *fHits;
290 new(lhits[fNhits++]) AliTOFhitT0(fIshunt, track, vol, hits);
291}
292
293//_____________________________________________________________________________
294void AliTOF::AddDigit(Int_t *tracks, Int_t *vol, Float_t *digits)
295{
296 //
297 // Add a TOF digit
298 // new with placement used
299 //
300 TClonesArray &ldigits = *fDigits;
301 new (ldigits[fNdigits++]) AliTOFdigit(tracks, vol, digits);
302}
303
304//_____________________________________________________________________________
305void AliTOF::AddSDigit(Int_t tracknum, Int_t *vol, Float_t *digits)
306{
307
308//
309// Add a TOF sdigit
310//
311
312 TClonesArray &lSDigits = *fSDigits;
313 new(lSDigits[fNSDigits++]) AliTOFSDigit(tracknum, vol, digits);
314}
315
316//_____________________________________________________________________________
317void AliTOF::SetTreeAddress ()
318{
319 // Set branch address for the Hits and Digits Tree.
320
321 if (fLoader->TreeH())
322 {
323 if (fHits == 0x0)
324 {
325 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
326 else fHits = new TClonesArray("AliTOFhit", 1000);
327 }
328 }
329 AliDetector::SetTreeAddress ();
330
331 TBranch *branch;
332
333 if (fLoader->TreeS () )
334 {
335 branch = fLoader->TreeS ()->GetBranch ("TOF");
336 if (branch) {
337 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
338 branch->SetAddress (&fSDigits);
339 }
340 }
341
342 if (fLoader->TreeR() )
343 {
344 branch = fLoader->TreeR()->GetBranch("TOF");
345 if (branch)
346 {
347 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
348 branch->SetAddress(&fReconParticles);
349 }
350 }
351
352 /*
353 if (fLoader->TreeR() && fReconParticles) //I do not know where this array is created - skowron
354 {
355 branch = fLoader->TreeR()->GetBranch("TOF");
356 if (branch)
357 {
358 branch->SetAddress(&fReconParticles) ;
359 }
360 }
361 */
362}
363
364//_____________________________________________________________________________
365void AliTOF::CreateGeometry()
366{
367 //
368 // Common geometry code
369 //
370 //Begin_Html
371 /*
372 <img src="picts/AliTOFv23.gif">
373 */
374 //End_Html
375 //
376
377 Float_t xTof, yTof;
378
379 if (IsVersion()==7) {
380
381 xTof = 124.5;//fTOFGeometry->StripLength()+2.*(0.3+0.03); // cm, x-dimension of FTOA volume
382 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin(); // cm, y-dimension of FTOA volume
383 Float_t zTof = fTOFGeometry->ZlenA(); // cm, z-dimension of FTOA volume
384
385 // TOF module internal definitions
386 TOFpc(xTof, yTof, zTof, fTOFGeometry->ZlenB());
387
388 } else {
389
390 Float_t wall = 4.;//cm // frame inbetween TOF modules
391
392 // Sizes of TOF module with its support etc..
393 xTof = 2.*(fTOFGeometry->Rmin()*TMath::Tan(10.*kDegrad)-wall/2.-0.5);
394 yTof = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
395
396 // TOF module internal definitions
397 TOFpc(xTof, yTof, fTOFGeometry->ZlenC(), fTOFGeometry->ZlenB(), fTOFGeometry->ZlenA(), fTOFGeometry->MaxhZtof());
398 }
399
400}
401
402//_____________________________________________________________________________
403void AliTOF::DrawModule() const
404{
405 //
406 // Draw a shaded view of the common part of the TOF geometry
407 //
408
409 AliInfo(" Drawing of AliTOF");
410 // Set everything unseen
411 gMC->Gsatt("*", "seen", -1);
412 //
413 // Set ALIC mother transparent
414 gMC->Gsatt("ALIC","SEEN",0);
415 //
416 // Set the volumes visible
417 gMC->Gsatt("FTOA","SEEN",1);
418 gMC->Gsatt("FTOB","SEEN",1);
419 gMC->Gsatt("FTOC","SEEN",1);
420 gMC->Gsatt("FLTA","SEEN",1);
421 gMC->Gsatt("FLTB","SEEN",1);
422 gMC->Gsatt("FLTC","SEEN",1);
423 gMC->Gsatt("FSTR","SEEN",1);
424 //
425 gMC->Gdopt("hide", "on");
426 gMC->Gdopt("shad", "on");
427 gMC->Gsatt("*", "fill", 7);
428 gMC->SetClipBox(".");
429 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
430 gMC->DefaultRange();
431 gMC->Gdraw("alic", 40, 30, 0, 12, 9.5, .02, .02);
432 gMC->Gdhead(1111, "Time Of Flight");
433 gMC->Gdman(18, 4, "MAN");
434 gMC->Gdopt("hide","off");
435}
436
437//_____________________________________________________________________________
438Int_t AliTOF::DistancetoPrimitive(Int_t , Int_t ) const
439{
440 //
441 // Returns distance from mouse pointer to detector, default version
442 //
443 return 9999;
444}
445
446//___________________________________________
447void AliTOF::ResetHits ()
448{
449 // Reset number of clusters and the cluster array for this detector
450 AliDetector::ResetHits ();
451}
452
453//____________________________________________
454void AliTOF::ResetDigits ()
455{
456 //
457 // Reset number of digits and the digits array for this detector
458 AliDetector::ResetDigits ();
459 //
460}
461//____________________________________________
462void AliTOF::ResetSDigits ()
463{
464 //
465 // Reset number of sdigits and the sdigits array for this detector
466 fNSDigits = 0;
467 //fSDigits = 0x0;
468 //
469}
470//_____________________________________________________________________________
471void AliTOF::Init()
472{
473 //
474 // Initialise TOF detector after it has been built
475 //
476 // Set id of TOF sensitive volume
477 if (IsVersion() !=0) fIdSens=gMC->VolId("FPAD");
478
479 /*
480 // Save the geometry
481 TDirectory* saveDir = gDirectory;
482 gAlice->GetRunLoader()->CdGAFile();
483 fTOFGeometry->Write("TOFGeometry");
484 saveDir->cd();
485 */
486}
487
488//____________________________________________________________________________
489void AliTOF::MakeBranch(Option_t* option)
490{
491 //
492 // Initializes the Branches of the TOF inside the
493 // trees written for each event.
494 // AliDetector::MakeBranch initializes just the
495 // Branch inside TreeH. Here we add the branches in
496 // TreeD, TreeS and TreeR.
497 //
498 const char *oH = strstr(option,"H");
499 if (fLoader->TreeH() && oH)
500 {
501 if (fHits == 0x0)
502 {
503 if (fTZero) fHits = new TClonesArray("AliTOFhitT0", 1000);
504 else fHits = new TClonesArray("AliTOFhit", 1000);
505 }
506 }
507
508 AliDetector::MakeBranch(option);
509
510 Int_t buffersize = 4000;
511 Char_t branchname[10];
512 sprintf(branchname,"%s",GetName());
513
514 const char *oD = strstr(option,"D");
515 const char *oS = strstr(option,"S");
516 const char *oR = strstr(option,"R");
517
518 if (fLoader->TreeD() && oD){
519 if (fDigits == 0x0) fDigits = new TClonesArray("AliTOFdigit", 1000);
520 MakeBranchInTree(fLoader->TreeD(), branchname, &fDigits,buffersize, 0) ;
521 }
522
523 if (fLoader->TreeS() && oS){
524 if (fSDigits == 0x0) fSDigits = new TClonesArray("AliTOFSDigit", 1000);
525 MakeBranchInTree(fLoader->TreeS(), branchname, &fSDigits,buffersize, 0) ;
526 }
527
528 if (fLoader->TreeR() && oR){
529 if (fReconParticles == 0x0) fReconParticles = new TClonesArray("AliTOFcluster", 1000);
530 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
531 }
532
533 /*
534 if (fReconParticles && fLoader->TreeR() && oR){
535 MakeBranchInTree(fLoader->TreeR(), branchname, &fReconParticles,buffersize, 0) ;
536 }
537 */
538}
539
540//____________________________________________________________________________
541void AliTOF::Makehits(Bool_t hits)
542{
543// default argument used, see AliTOF.h
544// Enable/Disable the writing of the TOF-hits branch
545// on TreeH
546// by default : enabled for TOFv1, v2, v3, v4, v5
547// disabled for TOFv0
548//
549 if (hits && (IsVersion()!=0))
550 fIdSens = gMC->VolId("FPAD");
551 else
552 AliInfo("Option for writing the TOF-hits branch on TreeH: disabled");
553}
554
555//____________________________________________________________________________
556void AliTOF::FinishEvent()
557{
558// do nothing
559}
560
561//____________________________________________________________________________
562void AliTOF::Hits2SDigits()
563{
564//
565// Use the TOF SDigitizer to make TOF SDigits
566//
567
568// cout<<"AliTOF::Hits2SDigits> start...\n";
569
570 AliRunLoader * rl = fLoader->GetRunLoader();
571 AliTOFSDigitizer sd((rl->GetFileName()).Data());
572 ToAliDebug(1, sd.Print(""));
573
574 sd.Exec("") ;
575
576}
577
578//____________________________________________________________________________
579void AliTOF::Hits2SDigits(Int_t evNumber1, Int_t evNumber2)
580{
581//
582// Use the TOF SDigitizer to make TOF SDigits
583//
584
585 if ((evNumber2-evNumber1)==1)
586 AliDebug(1, Form("I am making sdigits for the %dth event", evNumber1))
587 else if ((evNumber2-evNumber1)>1)
588 AliDebug(1, Form("I am making sdigits for the events from the "
589 "%dth to the %dth", evNumber1, evNumber2-1));
590
591 AliRunLoader * rl = fLoader->GetRunLoader();
592 AliTOFSDigitizer sd((rl->GetFileName()).Data(),evNumber1,evNumber2) ;
593 ToAliDebug(1, sd.Print(""));
594
595 sd.Exec("") ;
596
597}
598
599//___________________________________________________________________________
600AliDigitizer* AliTOF::CreateDigitizer(AliRunDigitizer* manager) const
601{
602 return new AliTOFDigitizer(manager);
603}
604
605//___________________________________________________________________________
606Bool_t AliTOF::CheckOverlap(Int_t* vol, Float_t* digit,Int_t Track)
607{
608//
609// Checks if 2 or more hits belong to the same pad.
610// In this case the data assigned to the digit object
611// are the ones of the first hit in order of Time.
612// 2 hits from the same track on the same pad are collected.
613// Called only by Hits2SDigits.
614// This procedure has to be optimized in the next TOF release.
615//
616
617 Bool_t overlap = kFALSE;
618 Int_t vol2[5];
619
620 for (Int_t ndig=0; ndig<fSDigits->GetEntries(); ndig++){
621 AliTOFdigit* currentDigit = (AliTOFdigit*)(fSDigits->UncheckedAt(ndig));
622 currentDigit->GetLocation(vol2);
623 Bool_t idem= kTRUE;
624 // check on digit volume
625 for (Int_t i=0;i<=4;i++){
626 if (!idem) break;
627 if (vol[i]!=vol2[i]) idem=kFALSE;}
628
629 if (idem){ // same pad fired
630 Float_t tdc2 = digit[0];
631 Float_t tdc1 = currentDigit->GetTdc();
632
633 // we separate two digits on the same pad if
634 // they are separated in time by at least 25 ns
635 // remember that tdc time is given in ps
636
637 if (TMath::Abs(tdc1-tdc2)<25000){
638 // in case of overlap we take the earliest
639 if (tdc1>tdc2){
640 currentDigit->SetTdc(tdc2);
641 currentDigit->SetAdc(digit[1]);
642 }
643 else {
644 currentDigit->SetTdc(tdc1);
645 currentDigit->SetAdc(digit[1]);
646 }
647 currentDigit->AddTrack(Track); // add track number in the track array
648 overlap = kTRUE;
649 return overlap;
650 } else
651 overlap= kFALSE;
652
653 } // close if (idem) -> two digits on the same TOF pad
654
655 } // end loop on existing sdigits
656
657 return overlap;
658}
659//____________________________________________________________________________
660void AliTOF::Digits2Raw()
661{
662//
663// Starting from the TOF digits, writes the Raw Data objects
664//
665
666 fLoader->LoadDigits();
667
668 TTree* digits = fLoader->TreeD();
669 if (!digits) {
670 AliError("no digits tree");
671 return;
672 }
673
674 //AliRunLoader *rl = AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(),"read");
675 fRunLoader->CdGAFile();
676 TFile *in=(TFile*)gFile;
677 in->cd();
678 AliTOFGeometry *geometry = (AliTOFGeometry*)in->Get("TOFgeometry");
679
680 AliTOFDDLRawData rawWriter(geometry);
681 //AliTOFDDLRawData rawWriter;
682 rawWriter.SetVerbose(0);
683
684 AliInfo("Formatting raw data for TOF");
685 digits->GetEvent(0);
686 rawWriter.RawDataTOF(digits->GetBranch("TOF"));
687
688 fLoader->UnloadDigits();
689
690}
691
692//____________________________________________________________________________
693void AliTOF::RecreateSDigitsArray() {
694//
695// delete TClonesArray fSDigits and create it again
696// needed for backward compatability with PPR test production
697//
698 delete fSDigits;
699 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
700}
701//____________________________________________________________________________
702void AliTOF::CreateSDigitsArray() {
703//
704// create TClonesArray fSDigits
705// needed for backward compatability with PPR test production
706//
707 fSDigits = new TClonesArray("AliTOFSDigit", 1000);
708}