]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDMerger.cxx
52e9cc8d2c3548f7c641dd5eb7dca14bb3a60fc2
[u/mrichter/AliRoot.git] / FMD / AliFMDMerger.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 //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
18
19 //PH 20/05/2003 It seems this class is obsolete and not used anymore
20
21 /* $Id$ */
22
23 #include "AliFMDMerger.h"
24
25
26 #include <TTree.h> 
27 #include <TVector.h>
28 #include <TObjArray.h>
29 #include <TFile.h>
30 #include <TDirectory.h>
31
32 #include "AliDetector.h"
33 #include "AliRunLoader.h"
34 #include "AliLoader.h"
35
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>
45 #include <Riostream.h>
46 #include <Riostream.h>
47
48 ClassImp(AliFMDMerger)
49
50 //___________________________________________
51   AliFMDMerger::AliFMDMerger() 
52 {
53 // Default constructor    
54     fEvNrSig = 0;
55     fEvNrBgr = 0;
56     fBgrLoader = 0x0;
57     fSigLoader = 0x0;
58     fMerge   = kDigitize;
59     fDigits  = 0;
60     fSDigits = 0;
61     fFnBgr   = 0;
62     fFnSig   = 0;
63     fBgrFile = 0;
64 }
65
66 //------------------------------------------------------------------------
67 AliFMDMerger::~AliFMDMerger()
68 {
69 // Destructor
70   if(fSDigits)  {
71     fSDigits->Delete();
72     delete fSDigits ;
73     fSDigits = 0;
74   }
75 }
76
77
78 //---------------------------------------------------------------------
79 void AliFMDMerger::SetRingsSi1(Int_t ringsSi1)
80 {
81   fRingsSi1=ringsSi1;
82 }
83 void AliFMDMerger::SetSectorsSi1(Int_t sectorsSi1)
84 {
85   fSectorsSi1=sectorsSi1;
86 }
87 void AliFMDMerger::SetRingsSi2(Int_t ringsSi2)
88 {
89   fRingsSi2=ringsSi2;
90 }
91 void AliFMDMerger::SetSectorsSi2(Int_t sectorsSi2)
92 {
93   fSectorsSi2=sectorsSi2;
94 }
95 //---------------------------------------------------------------------
96
97 //------------------------------------------------------------------------
98 void AliFMDMerger::Init()
99 {
100 // Initialisation
101     if (fMerge) fBgrFile = InitBgr();
102 }
103
104
105
106 //------------------------------------------------------------------------
107 TFile* AliFMDMerger::InitBgr()
108 {
109 // Initialise background event
110     fBgrLoader= AliRunLoader::Open(fFnBgr);
111     TFile *file = TFile::Open(fFnBgr);
112 // add error checking later
113     printf("\n AliFMDMerger has opened %s file with background event \n", fFnBgr);
114     return file;
115 }
116
117 //------------------------------------------------------------------------
118 void 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
127   cout<<"ALiFMDMerger::>SDigits2Digits start...\n";
128 #endif
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   
139   AliFMD * FMD = (AliFMD *) gAlice->GetDetector("FMD") ;
140
141   Int_t chargeSum[10][30][150];
142   Int_t digit[5];
143   Int_t ivol, iSector, iRing;
144
145   Int_t NumberOfRings[5]=
146   {fRingsSi1,fRingsSi2,fRingsSi1,fRingsSi2,fRingsSi1};
147   Int_t NumberOfSectors[5]=
148   {fSectorsSi1,fSectorsSi2,fSectorsSi1,fSectorsSi2,fSectorsSi1};
149
150   TFile *f1 =0;
151   TTree *TK = fBgrLoader->TreeK();
152   if (TK) f1 = TK->GetCurrentFile();
153
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") ;
175   
176   loader->TreeD()->Reset();
177
178   //Make branches 
179    ReadDigit( chargeSum, fEvNrSig);
180
181    if(fMerge){ 
182 //    fBgrFile->cd();
183     // gAlice->TreeS()->Reset();
184     gAlice = fBgrLoader->GetAliRun();
185     Int_t chargeBgr[10][30][150];
186     ReadDigit( chargeBgr,fEvNrBgr);
187     for ( ivol=1; ivol<=5; ivol++)
188       for ( iSector=1; iSector<=NumberOfSectors[ivol-1]; iSector++)
189        for (  iRing=1; iRing<=NumberOfRings[ivol-1]; iRing++)
190          chargeSum[ivol][iSector][iRing]=
191            chargeBgr[ivol][iSector][iRing]+
192            chargeSum[ivol][iSector][iRing];
193     
194    } //if merge
195
196
197   // Put noise and make ADC signal
198   for ( ivol=1; ivol<=5; ivol++){
199     for ( iSector=1; iSector<=NumberOfSectors[ivol-1]; iSector++){
200       for ( iRing=1; iRing<=NumberOfRings[ivol-1]; iRing++){
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; 
206
207     //dinamic diapason from MIP(0.155MeV) to 30MIP(4.65MeV)
208     //1024 ADC channels 
209        Float_t channelWidth=(22400*50)/1024;
210        digit[4]=Int_t(digit[3]/channelWidth);
211        if (digit[4]>1024) digit[4]=1024; 
212
213        FMD->AddDigit(digit);
214
215       } //ivol
216     } //iSector
217   } //iRing
218
219   f1->cd();
220    
221   //Make branch for digits
222   FMD->MakeBranch("D");
223
224   loader->TreeD()->Reset();
225   loader->TreeD()->Fill();
226   
227   fDigits   = FMD->Digits();//should be moved to specialized loader (AliFMDLoader)
228   
229   loader->WriteDigits("OVERWRITE");
230   
231   gAlice->ResetDigits();
232
233 }
234
235 //---------------------------------------------------------------------
236
237 void AliFMDMerger::ReadDigit(Int_t chargeSum[][30][150], Int_t iEvNum)
238 {
239   AliFMDdigit *fmddigit;
240   
241   for (Int_t i=0; i<10; i++)
242     for(Int_t j=0; j<30; j++)
243       for(Int_t ij=0; ij<150; ij++)
244        chargeSum[i][j][ij]=0;
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