]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFMerger.cxx
Several pointers were set to zero in the default constructors to avoid memory managem...
[u/mrichter/AliRoot.git] / TOF / AliTOFMerger.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2000, 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 #include <TTree.h> 
17 #include <TVector.h>
18 #include <TObjArray.h>
19 #include <TFile.h>
20 #include <TDirectory.h>
21
22
23 #include "AliTOFMerger.h"
24 #include "AliTOF.h"
25 #include "AliTOFSDigitizer.h"
26 #include "AliTOFhit.h"
27 #include "AliTOFdigit.h"
28
29 #include "AliRun.h"
30 #include "AliPDG.h"
31
32 #include <stdlib.h>
33 #include <iostream.h>
34 #include <fstream.h>
35
36 ClassImp(AliTOFMerger)
37
38 //___________________________________________
39   AliTOFMerger::AliTOFMerger() 
40 {
41 // Default ctor    
42     fNDigits = 0;
43     fEvNrSig = 0;
44     fEvNrBgr = 0;
45     fMerge =kDigitize;
46     fFnBgr   = 0;
47     fDigits = 0;
48     fSDigits =0;
49     fFnBgr = 0;
50     fFnSig = 0;
51     fBgrFile = 0;
52 }
53
54 //------------------------------------------------------------------------
55 AliTOFMerger::~AliTOFMerger()
56 {
57 // Dtor
58   if(fSDigits)  {
59     fSDigits->Delete();
60     delete fSDigits ;
61     fSDigits = 0;
62   }
63 }
64
65
66 //------------------------------------------------------------------------
67 void AliTOFMerger::Init()
68 {
69 // Initialisation
70     if (fMerge) fBgrFile = InitBgr();
71     
72 }
73
74
75
76 //------------------------------------------------------------------------
77 TFile* AliTOFMerger::InitBgr()
78 {
79 // Initialise background event
80     TFile *file = new TFile(fFnBgr);
81 // add error checking later
82     printf("\n AliTOFMerger has opened %s file with background event \n", fFnBgr);
83     return file;
84 }
85
86 //------------------------------------------------------------------------
87 void AliTOFMerger::Digitise()
88 {
89 // as in FMD
90 // keep galice.root for signal and name differently the file for 
91 // background when add! otherwise the track info for signal will be lost !
92
93
94
95 #ifdef DEBUG
96   cout<<"ALiTOFMerger::>SDigits2Digits start...\n";
97 #endif
98
99   AliTOF* TOF = (AliTOF *) gAlice->GetDetector("TOF") ;
100
101
102   TFile *f1 =0;
103   TTree *TK = gAlice->TreeK();
104   if (TK) f1 = TK->GetCurrentFile();
105
106   gAlice->GetEvent(fEvNrSig) ;
107   
108   if(gAlice->TreeD() == 0)      
109     gAlice->MakeTree("D") ;
110   gAlice->TreeD()->Reset();
111
112   // read and write digits for signal
113    ReadWriteDigit(fEvNrSig);
114
115    if(fMerge){ 
116      // bgr file
117     fBgrFile->cd();
118     // gAlice->TreeS()->Reset();
119     gAlice = (AliRun*)fBgrFile->Get("gAlice");
120     ReadWriteDigit(fEvNrBgr);
121    } //if merge
122
123
124   f1->cd();
125    
126   //Make branch for digits
127   TOF->MakeBranch("D");
128
129   gAlice->TreeD()->Reset();
130   gAlice->TreeD()->Fill();
131   
132   fDigits   = TOF->Digits();
133   
134   gAlice->TreeD()->Write(0,TObject::kOverwrite) ;
135   
136   gAlice->ResetDigits();
137
138 }
139
140 //---------------------------------------------------------------------
141
142 void AliTOFMerger::ReadWriteDigit(Int_t iEvNum)
143 {
144 //
145 // Read Sdigits from the current file and write them in the TreeD
146 //
147   AliTOFdigit* tofsdigit;
148   
149   AliTOF * tofinfile = (AliTOF *) gAlice->GetDetector("TOF") ;
150   
151   gAlice->GetEvent(iEvNum) ;
152   if(gAlice->TreeS()==0) {
153     cout<<" TreeS==0 -> return"<<gAlice->TreeS()<<endl; 
154     return ;}
155   
156   Int_t ndig, k;
157   Int_t    tracks[3];    // track info
158   Int_t    vol[5];       // location for a digit
159   Float_t  digit[2];     // TOF digit variables
160
161   gAlice->ResetDigits();
162   gAlice->TreeS()->GetEvent(iEvNum);
163   TClonesArray * TOFdigits   = tofinfile->SDigits();
164   
165   ndig=TOFdigits->GetEntries();
166
167   for (k=0; k<ndig; k++) {
168     tofsdigit= (AliTOFdigit*) TOFdigits->UncheckedAt(k);
169
170         tracks[0] = tofsdigit->GetTrack(0);
171         tracks[1] = tofsdigit->GetTrack(1);
172         tracks[2] = tofsdigit->GetTrack(2);
173
174         vol[0] = tofsdigit->GetSector();
175         vol[1] = tofsdigit->GetPlate();
176         vol[2] = tofsdigit->GetStrip();
177         vol[3] = tofsdigit->GetPadx();
178         vol[4] = tofsdigit->GetPadz();
179
180         digit[0] = tofsdigit->GetTdc();
181         digit[1] = tofsdigit->GetAdc();
182
183         new ((*fDigits)[fNDigits++]) AliTOFdigit(tracks, vol, digit);
184   } // end loop on sdigits in the current file
185 }
186
187
188