]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - FMD/AliFMDMerger.cxx
A pointer was set to zero in the default constructor to avoid memory management problems
[u/mrichter/AliRoot.git] / FMD / AliFMDMerger.cxx
... / ...
CommitLineData
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/*
17$Log$
18Revision 1.1 2001/05/29 12:01:06 hristov
19Last minute changes and new code for event mixing and reconstruction (A.Maevskaia)
20
21Revision 1.3 2001/03/05 23:57:44 morsch
22Writing of digit tree moved to macro.
23
24Revision 1.2 2001/03/05 08:40:25 morsch
25Method SortTracks(..) imported from AliMUON.
26
27Revision 1.1 2001/02/02 14:11:53 morsch
28AliMUONMerger prototype to be called by the merge manager.
29
30*/
31
32#include <TTree.h>
33#include <TVector.h>
34#include <TObjArray.h>
35#include <TFile.h>
36#include <TDirectory.h>
37
38
39#include "AliFMDMerger.h"
40#include "AliFMD.h"
41#include "AliFMDSDigitizer.h"
42#include "AliFMDhit.h"
43#include "AliFMDdigit.h"
44
45#include "AliRun.h"
46#include "AliPDG.h"
47
48#include <stdlib.h>
49#include <iostream.h>
50#include <fstream.h>
51
52ClassImp(AliFMDMerger)
53
54//___________________________________________
55 AliFMDMerger::AliFMDMerger()
56{
57// Default constructor
58 fEvNrSig = 0;
59 fEvNrBgr = 0;
60 fMerge =kDigitize;
61 fFnBgr = 0;
62}
63
64//------------------------------------------------------------------------
65AliFMDMerger::~AliFMDMerger()
66{
67// Destructor
68 if(fSDigits) {
69 fSDigits->Delete();
70 delete fSDigits ;
71 fSDigits = 0;
72 }
73}
74
75
76//---------------------------------------------------------------------
77void AliFMDMerger::SetRingsSi1(Int_t ringsSi1)
78{
79 fRingsSi1=ringsSi1;
80}
81void AliFMDMerger::SetSectorsSi1(Int_t sectorsSi1)
82{
83 fSectorsSi1=sectorsSi1;
84}
85void AliFMDMerger::SetRingsSi2(Int_t ringsSi2)
86{
87 fRingsSi2=ringsSi2;
88}
89void AliFMDMerger::SetSectorsSi2(Int_t sectorsSi2)
90{
91 fSectorsSi2=sectorsSi2;
92}
93//---------------------------------------------------------------------
94
95//------------------------------------------------------------------------
96void AliFMDMerger::Init()
97{
98// Initialisation
99 if (fMerge) fBgrFile = InitBgr();
100
101}
102
103
104
105//------------------------------------------------------------------------
106TFile* AliFMDMerger::InitBgr()
107{
108// Initialise background event
109 TFile *file = new TFile(fFnBgr);
110// add error checking later
111 printf("\n AliFMDMerger has opened %s file with background event \n", fFnBgr);
112 return file;
113}
114
115//------------------------------------------------------------------------
116void AliFMDMerger::Digitise()
117{
118
119 // keep galice.root for signal and name differently the file for
120 // background when add! otherwise the track info for signal will be lost !
121
122
123
124#ifdef DEBUG
125 cout<<"ALiFMDMerger::>SDigits2Digits start...\n";
126#endif
127
128 AliFMD * FMD = (AliFMD *) gAlice->GetDetector("FMD") ;
129
130 Int_t chargeSum[10][30][150];
131 Int_t digit[5];
132 Int_t ivol, iSector, iRing;
133
134 Int_t NumberOfRings[5]=
135 {fRingsSi1,fRingsSi2,fRingsSi1,fRingsSi2,fRingsSi1};
136 Int_t NumberOfSectors[5]=
137 {fSectorsSi1,fSectorsSi2,fSectorsSi1,fSectorsSi2,fSectorsSi1};
138
139 TFile *f1 =0;
140 TTree *TK = gAlice->TreeK();
141 if (TK) f1 = TK->GetCurrentFile();
142
143 gAlice->GetEvent(fEvNrSig) ;
144
145 if(gAlice->TreeD() == 0)
146 gAlice->MakeTree("D") ;
147 gAlice->TreeD()->Reset();
148
149 //Make branches
150 ReadDigit( chargeSum, fEvNrSig);
151
152 if(fMerge){
153 fBgrFile->cd();
154 // gAlice->TreeS()->Reset();
155 gAlice = (AliRun*)fBgrFile->Get("gAlice");
156 Int_t chargeBgr[10][30][150];
157 ReadDigit( chargeBgr,fEvNrBgr);
158 for ( ivol=1; ivol<=5; ivol++)
159 for ( iSector=1; iSector<=NumberOfSectors[ivol-1]; iSector++)
160 for ( iRing=1; iRing<=NumberOfRings[ivol-1]; iRing++)
161 chargeSum[ivol][iSector][iRing]=
162 chargeBgr[ivol][iSector][iRing]+
163 chargeSum[ivol][iSector][iRing];
164
165 } //if merge
166
167
168 // Put noise and make ADC signal
169 for ( ivol=1; ivol<=5; ivol++){
170 for ( iSector=1; iSector<=NumberOfSectors[ivol-1]; iSector++){
171 for ( iRing=1; iRing<=NumberOfRings[ivol-1]; iRing++){
172 digit[0]=ivol;
173 digit[1]=iSector;
174 digit[2]=iRing;
175 digit[3]=PutNoise(chargeSum[ivol][iSector][iRing]);
176 if(chargeSum[ivol][iSector][iRing] <= 500) digit[3]=500;
177
178 //dinamic diapason from MIP(0.155MeV) to 30MIP(4.65MeV)
179 //1024 ADC channels
180 Float_t channelWidth=(22400*50)/1024;
181 digit[4]=Int_t(digit[3]/channelWidth);
182 if (digit[4]>1024) digit[4]=1024;
183
184 FMD->AddDigit(digit);
185
186 } //ivol
187 } //iSector
188 } //iRing
189
190 f1->cd();
191
192 //Make branch for digits
193 FMD->MakeBranch("D");
194
195 gAlice->TreeD()->Reset();
196 gAlice->TreeD()->Fill();
197
198 fDigits = FMD->Digits();
199
200 gAlice->TreeD()->Write(0,TObject::kOverwrite) ;
201
202 gAlice->ResetDigits();
203
204}
205
206//---------------------------------------------------------------------
207
208void AliFMDMerger::ReadDigit(Int_t chargeSum[][30][150], Int_t iEvNum)
209{
210 AliFMDdigit *fmddigit;
211
212 for (Int_t i=0; i<10; i++)
213 for(Int_t j=0; j<30; j++)
214 for(Int_t ij=0; ij<150; ij++)
215 chargeSum[i][j][ij]=0;
216
217 AliFMD * FMD = (AliFMD *) gAlice->GetDetector("FMD") ;
218
219 gAlice->GetEvent(iEvNum) ;
220 if(gAlice->TreeS()==0) {
221 cout<<" TreeS==0 -> return"<<gAlice->TreeS()<<endl;
222 return ;}
223
224 Int_t ndig, k;
225 gAlice->ResetDigits();
226 gAlice->TreeS()->GetEvent(iEvNum);
227 TClonesArray * FMDdigits = FMD->SDigits();
228
229 ndig=FMDdigits->GetEntries();
230
231 for (k=0; k<ndig; k++) {
232 fmddigit= (AliFMDdigit*) FMDdigits->UncheckedAt(k);
233
234 Int_t iVolume=fmddigit->Volume();
235 Int_t iNumberOfSector =fmddigit->NumberOfSector();
236 Int_t iNumberOfRing=fmddigit->NumberOfRing();
237 chargeSum[iVolume][iNumberOfSector][iNumberOfRing]=fmddigit->Charge();
238 }
239}
240
241