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