AliFMDMerger.h
[u/mrichter/AliRoot.git] / FMD / AliFMDMerger.cxx
CommitLineData
dc8af42e 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 **************************************************************************/
88cb7938 15//Piotr.Skowronski@cern.ch
16//Fast fixes to be able to compile with new Folder and I/O structure
17//To be implemented correctly by the responsible person
dc8af42e 18
88cb7938 19//PH 20/05/2003 It seems this class is obsolete and not used anymore
93bdec82 20
88cb7938 21/* $Id$ */
2685bf00 22
88cb7938 23#include "AliFMDMerger.h"
dc8af42e 24
dc8af42e 25
26#include <TTree.h>
27#include <TVector.h>
28#include <TObjArray.h>
29#include <TFile.h>
30#include <TDirectory.h>
31
88cb7938 32#include "AliDetector.h"
33#include "AliRunLoader.h"
34#include "AliLoader.h"
dc8af42e 35
dc8af42e 36#include "AliFMD.h"
37#include "AliFMDSDigitizer.h"
38#include "AliFMDhit.h"
39#include "AliFMDdigit.h"
40
41#include "AliRun.h"
42#include "AliPDG.h"
43
44#include <stdlib.h>
93bdec82 45#include <Riostream.h>
46#include <Riostream.h>
dc8af42e 47
48ClassImp(AliFMDMerger)
49
50//___________________________________________
51 AliFMDMerger::AliFMDMerger()
52{
53// Default constructor
54 fEvNrSig = 0;
55 fEvNrBgr = 0;
88cb7938 56 fBgrLoader = 0x0;
57 fSigLoader = 0x0;
2685bf00 58 fMerge = kDigitize;
59 fDigits = 0;
60 fSDigits = 0;
dc8af42e 61 fFnBgr = 0;
2685bf00 62 fFnSig = 0;
63 fBgrFile = 0;
dc8af42e 64}
65
66//------------------------------------------------------------------------
67AliFMDMerger::~AliFMDMerger()
68{
69// Destructor
70 if(fSDigits) {
71 fSDigits->Delete();
72 delete fSDigits ;
73 fSDigits = 0;
74 }
75}
76
77
37c55dc0 78//---------------------------------------------------------------------
79void AliFMDMerger::SetRingsSi1(Int_t ringsSi1)
80{
81 fRingsSi1=ringsSi1;
82}
83void AliFMDMerger::SetSectorsSi1(Int_t sectorsSi1)
84{
85 fSectorsSi1=sectorsSi1;
86}
87void AliFMDMerger::SetRingsSi2(Int_t ringsSi2)
88{
89 fRingsSi2=ringsSi2;
90}
91void AliFMDMerger::SetSectorsSi2(Int_t sectorsSi2)
92{
93 fSectorsSi2=sectorsSi2;
94}
95//---------------------------------------------------------------------
dc8af42e 96
97//------------------------------------------------------------------------
98void AliFMDMerger::Init()
99{
100// Initialisation
101 if (fMerge) fBgrFile = InitBgr();
dc8af42e 102}
103
104
105
106//------------------------------------------------------------------------
107TFile* AliFMDMerger::InitBgr()
108{
109// Initialise background event
88cb7938 110 fBgrLoader= AliRunLoader::Open(fFnBgr);
111 TFile *file = TFile::Open(fFnBgr);
dc8af42e 112// add error checking later
113 printf("\n AliFMDMerger has opened %s file with background event \n", fFnBgr);
114 return file;
115}
116
117//------------------------------------------------------------------------
118void AliFMDMerger::Digitise()
119{
120
121 // keep galice.root for signal and name differently the file for
122 // background when add! otherwise the track info for signal will be lost !
123
124
125
126#ifdef DEBUG
37c55dc0 127 cout<<"ALiFMDMerger::>SDigits2Digits start...\n";
dc8af42e 128#endif
88cb7938 129 if (fBgrLoader == 0x0)
130 {
131 cerr<<"AliFMDMerger::Digitise : Background Run Loader is NULL"<<endl;
132 return;
133 }
134
135 fBgrLoader->LoadgAlice();
136 fBgrLoader->LoadHeader();
137 fBgrLoader->LoadKinematics();
138
dc8af42e 139 AliFMD * FMD = (AliFMD *) gAlice->GetDetector("FMD") ;
140
37c55dc0 141 Int_t chargeSum[10][30][150];
dc8af42e 142 Int_t digit[5];
143 Int_t ivol, iSector, iRing;
144
37c55dc0 145 Int_t NumberOfRings[5]=
146 {fRingsSi1,fRingsSi2,fRingsSi1,fRingsSi2,fRingsSi1};
147 Int_t NumberOfSectors[5]=
148 {fSectorsSi1,fSectorsSi2,fSectorsSi1,fSectorsSi2,fSectorsSi1};
149
dc8af42e 150 TFile *f1 =0;
88cb7938 151 TTree *TK = fBgrLoader->TreeK();
dc8af42e 152 if (TK) f1 = TK->GetCurrentFile();
153
88cb7938 154 //just patches to be able to compile
155
156
157 fBgrLoader->GetEvent(fEvNrSig) ;
158 AliLoader* loader = fBgrLoader->GetLoader("FMDLoader");
159 if (loader == 0x0)
160 {
161 cerr<<"AliFMDMerger::Digitise : Can not find loader for FMD. Exiting"<<endl;
162 return;
163 }
164
165 Int_t retval;
166 retval = loader->LoadDigits("UPDATE");
167 if (retval == 0x0)
168 {
169 cerr<<"AliFMDMerger::Digitise : Error occured while loading digits. Exiting"<<endl;
170 return;
171 }
172
173 if(loader->TreeD() == 0)
174 loader->MakeTree("D") ;
dc8af42e 175
88cb7938 176 loader->TreeD()->Reset();
dc8af42e 177
178 //Make branches
179 ReadDigit( chargeSum, fEvNrSig);
180
181 if(fMerge){
88cb7938 182// fBgrFile->cd();
dc8af42e 183 // gAlice->TreeS()->Reset();
88cb7938 184 gAlice = fBgrLoader->GetAliRun();
37c55dc0 185 Int_t chargeBgr[10][30][150];
dc8af42e 186 ReadDigit( chargeBgr,fEvNrBgr);
187 for ( ivol=1; ivol<=5; ivol++)
37c55dc0 188 for ( iSector=1; iSector<=NumberOfSectors[ivol-1]; iSector++)
88cb7938 189 for ( iRing=1; iRing<=NumberOfRings[ivol-1]; iRing++)
190 chargeSum[ivol][iSector][iRing]=
191 chargeBgr[ivol][iSector][iRing]+
192 chargeSum[ivol][iSector][iRing];
dc8af42e 193
194 } //if merge
195
196
197 // Put noise and make ADC signal
198 for ( ivol=1; ivol<=5; ivol++){
37c55dc0 199 for ( iSector=1; iSector<=NumberOfSectors[ivol-1]; iSector++){
200 for ( iRing=1; iRing<=NumberOfRings[ivol-1]; iRing++){
88cb7938 201 digit[0]=ivol;
202 digit[1]=iSector;
203 digit[2]=iRing;
204 digit[3]=PutNoise(chargeSum[ivol][iSector][iRing]);
205 if(chargeSum[ivol][iSector][iRing] <= 500) digit[3]=500;
dc8af42e 206
207 //dinamic diapason from MIP(0.155MeV) to 30MIP(4.65MeV)
208 //1024 ADC channels
88cb7938 209 Float_t channelWidth=(22400*50)/1024;
210 digit[4]=Int_t(digit[3]/channelWidth);
211 if (digit[4]>1024) digit[4]=1024;
dc8af42e 212
88cb7938 213 FMD->AddDigit(digit);
dc8af42e 214
215 } //ivol
216 } //iSector
217 } //iRing
218
219 f1->cd();
220
221 //Make branch for digits
222 FMD->MakeBranch("D");
223
88cb7938 224 loader->TreeD()->Reset();
225 loader->TreeD()->Fill();
dc8af42e 226
88cb7938 227 fDigits = FMD->Digits();//should be moved to specialized loader (AliFMDLoader)
dc8af42e 228
88cb7938 229 loader->WriteDigits("OVERWRITE");
dc8af42e 230
231 gAlice->ResetDigits();
232
233}
234
235//---------------------------------------------------------------------
236
37c55dc0 237void AliFMDMerger::ReadDigit(Int_t chargeSum[][30][150], Int_t iEvNum)
dc8af42e 238{
239 AliFMDdigit *fmddigit;
240
241 for (Int_t i=0; i<10; i++)
37c55dc0 242 for(Int_t j=0; j<30; j++)
dc8af42e 243 for(Int_t ij=0; ij<150; ij++)
88cb7938 244 chargeSum[i][j][ij]=0;
dc8af42e 245
246 AliFMD * FMD = (AliFMD *) gAlice->GetDetector("FMD") ;
247
248 gAlice->GetEvent(iEvNum) ;
249 if(gAlice->TreeS()==0) {
250 cout<<" TreeS==0 -> return"<<gAlice->TreeS()<<endl;
251 return ;}
252
253 Int_t ndig, k;
254 gAlice->ResetDigits();
255 gAlice->TreeS()->GetEvent(iEvNum);
256 TClonesArray * FMDdigits = FMD->SDigits();
257
258 ndig=FMDdigits->GetEntries();
259
260 for (k=0; k<ndig; k++) {
261 fmddigit= (AliFMDdigit*) FMDdigits->UncheckedAt(k);
262
263 Int_t iVolume=fmddigit->Volume();
264 Int_t iNumberOfSector =fmddigit->NumberOfSector();
265 Int_t iNumberOfRing=fmddigit->NumberOfRing();
266 chargeSum[iVolume][iNumberOfSector][iNumberOfRing]=fmddigit->Charge();
267 }
268}
269
270