]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDSDigitizer.cxx
negative indexes allowed
[u/mrichter/AliRoot.git] / FMD / AliFMDSDigitizer.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /* $Id$ */
17
18 //_________________________________________________________________________
19 // This is a TTask that constructs SDigits out of Hits
20 // A Summable Digits is the sum of all hits in a cell
21 // A threshold is applied 
22 //
23 //-- Author: Alla Maevskaia(INR)
24 //////////////////////////////////////////////////////////////////////////////
25
26 // --- Standard library ---
27 #include <Riostream.h>
28 #include <stdlib.h>
29
30 // --- ROOT system ---
31 #include <TFile.h>
32 #include <TFolder.h>
33 #include <TROOT.h>
34 #include <TSystem.h>
35 #include <TTask.h>
36 #include <TTree.h>
37 #include <TVirtualMC.h>
38
39 // --- AliRoot header files ---
40 #include "AliConfig.h"
41 #include "AliDetector.h"
42 #include "AliFMD.h"
43 #include "AliFMDSDigitizer.h"
44 #include "AliFMDdigit.h"
45 #include "AliFMDhit.h"
46 #include "AliFMDv1.h"
47 #include "AliLoader.h"
48 #include "AliRun.h"
49 #include "AliRunLoader.h"
50 #include "AliStack.h"
51
52 ClassImp(AliFMDSDigitizer)
53
54 //____________________________________________________________________________ 
55   AliFMDSDigitizer::AliFMDSDigitizer():TTask("AliFMDSDigitizer","") 
56 {
57   // ctor
58   fNevents = 0 ;     
59   fSDigits = 0 ;
60   fHits = 0 ;
61   fRunLoader = 0;
62 }
63            
64 //____________________________________________________________________________ 
65 AliFMDSDigitizer::AliFMDSDigitizer(char* HeaderFile,char *SdigitsFile ):TTask("AliFMDSDigitizer","") 
66 {
67   fNevents = 0 ;     // Number of events to digitize, 0 means all evens in current file
68   // add Task to //root/Tasks folder
69   fRunLoader = AliRunLoader::Open(HeaderFile);//Load event in default folder
70   if (fRunLoader == 0x0)
71    {
72      Fatal("AliFMDSDigitizer","Can not open session. Header File is %s ",HeaderFile);
73      return;//never reached
74    }
75   AliLoader* gime = fRunLoader->GetLoader("FMDLoader");
76   if (gime == 0x0)
77    {
78      Fatal("AliFMDSDigitizer","Can not find FMD (loader) in specified event");
79      return;//never reached
80    }
81   //add Task to //root/Tasks folder
82   gime->PostSDigitizer(this);
83 }
84
85 //____________________________________________________________________________ 
86   AliFMDSDigitizer::~AliFMDSDigitizer()
87 {
88   // dtor
89 }
90
91 //---------------------------------------------------------------------
92 void AliFMDSDigitizer::SetRingsSi1(Int_t ringsSi1)
93 {
94   fRingsSi1=ringsSi1;
95 }
96 void AliFMDSDigitizer::SetSectorsSi1(Int_t sectorsSi1)
97 {
98   fSectorsSi1=sectorsSi1;
99 }
100 void AliFMDSDigitizer::SetRingsSi2(Int_t ringsSi2)
101 {
102   fRingsSi2=ringsSi2;
103 }
104 void AliFMDSDigitizer::SetSectorsSi2(Int_t sectorsSi2)
105 {
106   fSectorsSi2=sectorsSi2;
107 }
108
109 //____________________________________________________________________________
110 void AliFMDSDigitizer::Exec(Option_t *option) 
111  { 
112   Int_t NumberOfRings[5]=
113   {fRingsSi1,fRingsSi2,fRingsSi1,fRingsSi2,fRingsSi1};
114   Int_t NumberOfSectors[5]=
115   {fSectorsSi1,fSectorsSi2,fSectorsSi1,fSectorsSi2,fSectorsSi1};
116
117   if (fRunLoader)
118    {
119     Error("Exec","Run Loader loader is NULL - Session not opened");
120     return;
121    }
122   AliLoader* gime = fRunLoader->GetLoader("FMDLoader");
123   if (gime == 0x0)
124    {
125      Fatal("AliFMDReconstruction","Can not find FMD (loader) in specified event");
126      return;//never reached
127    }
128
129   fRunLoader->LoadgAlice();
130   fRunLoader->LoadHeader();
131   fRunLoader->LoadKinematics("READ");
132   
133   Int_t retval;
134
135   retval = gime->LoadHits("READ");
136   if (retval)
137    {
138      Error("Exec","Error occured while loading hits. Exiting.");
139      return;
140    }
141
142
143   // Initialise Hit array
144   fHits = new TClonesArray ("AliFMDhit", 1000);
145   fSDigits = new TClonesArray ("AliFMDdigit", 1000);
146
147   AliFMD *FMD = (AliFMD *) gAlice->GetDetector ("FMD");
148
149   if (fNevents == 0)
150     fNevents = (Int_t) fRunLoader->TreeE ()->GetEntries ();
151
152   for (Int_t ievent = 0; ievent < fNevents; ievent++)
153     {
154       fRunLoader->GetEvent (ievent);
155
156       TTree* TH = gime->TreeH();
157       if (TH == 0x0)
158        {
159          Error("Exec","Can not get TreeH");
160          return;
161        }
162       if (gime->TreeS () == 0)  gime->MakeTree("S");
163
164       //Make branch for digits
165       FMD->MakeBranch ("S");
166       //Now made SDigits from hits, for PHOS it is the same
167       Int_t volume, sector, ring, charge;
168       Float_t e;
169       Float_t de[10][50][150];
170       Int_t ivol, isec, iring;
171       Int_t hit, nbytes;
172       TParticle *particle;
173       AliFMDhit *fmdHit;
174       TClonesArray *FMDhits = FMD->Hits ();
175
176       // Event ------------------------- LOOP  
177
178       for (ivol = 0; ivol < 10; ivol++)
179        for (isec = 0; isec < 50; isec++)
180          for (iring = 0; iring < 150; iring++)
181            de[ivol][isec][iring] = 0;
182
183       if (FMD)
184        {
185          FMDhits = FMD->Hits ();
186
187          
188          Stat_t ntracks = TH->GetEntries ();
189          for (Int_t track = 0; track < ntracks; track++)
190            {
191              gAlice->ResetHits ();
192              nbytes += TH->GetEvent(track);
193              particle = fRunLoader->Stack()->Particle (track);
194              Int_t nhits = FMDhits->GetEntriesFast ();
195
196              for (hit = 0; hit < nhits; hit++)
197               {
198                 fmdHit = (AliFMDhit *) FMDhits->UncheckedAt (hit);
199
200                 volume = fmdHit->Volume ();
201                 sector = fmdHit->NumberOfSector ();
202                 ring = fmdHit->NumberOfRing ();
203                 e = fmdHit->Edep ();
204                 de[volume][sector][ring] += e;
205               }              //hit loop
206            }                     //track loop
207        }                     //if FMD
208
209
210       Int_t digit[5];
211       Float_t I = 1.664 * 0.04 * 2.33 / 22400;       // = 0.69e-6;
212       for (ivol = 1; ivol < 6; ivol++)
213        { 
214          for (isec = 1; isec <= NumberOfSectors[ivol-1]; isec++)
215            { 
216              for (iring = 1; iring <= NumberOfRings[ivol-1]; iring++)
217               {
218                     digit[0] = ivol;
219                     digit[1] = isec;
220                     digit[2] = iring;
221                     charge = Int_t (de[ivol][isec][iring] / I);
222
223                     digit[3] = charge;
224                     //dinamic diapason from MIP(0.155MeV) to 30MIP(4.65MeV)
225                     //1024 ADC channels 
226                     Float_t channelWidth = (22400 * 30) / 1024;
227
228                     digit[4] = Int_t (digit[3] / channelWidth);
229                     FMD->AddSDigit(digit);
230
231               }              // iring loop
232            }                     //sector loop
233        }                     // volume loop
234       
235       gime->TreeS()->Reset();
236       gime->TreeS()->Fill();
237       gime->WriteSDigits("OVERWRITE");
238     }  //event loop
239
240
241 }
242  
243 //__________________________________________________________________
244 void AliFMDSDigitizer::SetSDigitsFile(char * file ){
245   if(!fSDigitsFile.IsNull())
246     cout << "Changing SDigits file from " <<(char *)fSDigitsFile.Data() << " to " << file << endl ;
247   fSDigitsFile=file ;
248 }
249 //__________________________________________________________________
250 void AliFMDSDigitizer::Print(Option_t* option)const
251 {
252   cout << "------------------- "<< GetName() << " -------------" << endl ;
253   if(fSDigitsFile.IsNull())
254     cout << " Writing SDigitis to file galice.root "<< endl ;
255   else
256     cout << "    Writing SDigitis to file  " << (char*) fSDigitsFile.Data() << endl ;
257
258 }