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