]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDSDigitizer.cxx
New files for folders and Stack
[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 //_________________________________________________________________________
17 // This is a TTask that constructs SDigits out of Hits
18 // A Summable Digits is the sum of all hits in a cell
19 // A threshold is applied 
20 //
21 //-- Author: Alla Maevskaia(INR)
22 //////////////////////////////////////////////////////////////////////////////
23
24 // --- ROOT system ---
25 #include "TTask.h"
26 #include "TTree.h"
27 #include "TSystem.h"
28 #include "TFile.h"
29 // --- Standard library ---
30
31 // --- AliRoot header files ---
32
33 #include "AliFMDdigit.h"
34 #include "AliFMDhit.h"
35 #include "AliFMD.h"
36 #include "AliFMDv1.h"
37 #include "AliFMDSDigitizer.h"
38 #include "AliRun.h"
39 #include "AliDetector.h"
40 #include "AliMC.h"
41
42 #include "TROOT.h"
43 #include "TFolder.h"
44 #include <stdlib.h>
45 #include <iostream.h>
46 #include <fstream.h>
47
48 ClassImp(AliFMDSDigitizer)
49
50            
51 //____________________________________________________________________________ 
52   AliFMDSDigitizer::AliFMDSDigitizer():TTask("AliFMDSDigitizer","") 
53 {
54   fNevents = 0 ;     // Number of events to digitize, 0 means all evens in current file
55   // add Task to //root/Tasks folder
56   TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
57   roottasks->Add(this) ; 
58 }
59 //____________________________________________________________________________ 
60 AliFMDSDigitizer::AliFMDSDigitizer(char* HeaderFile, char *SDigitsFile):TTask("AliFMDSDigitizer","")
61 {
62   // ctor
63   fNevents = 0 ;    // Number of events to digitize, 0 means all events in current file
64   fSDigitsFile = SDigitsFile ;
65   fHeadersFile = HeaderFile ;
66   //add Task to //root/Tasks folder
67   TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
68   roottasks->Add(this) ; 
69     
70 }
71
72 //____________________________________________________________________________ 
73   AliFMDSDigitizer::~AliFMDSDigitizer()
74 {
75   // dtor
76 }
77
78
79 //____________________________________________________________________________
80 void AliFMDSDigitizer::Exec(Option_t *option) { 
81   //Collects all hits in the same active volume into digit
82   TClonesArray * sdigits = new TClonesArray("AliFMDdigit",1000) ;
83   TFile * file = 0;
84
85   AliFMD * FMD = (AliFMD *) gAlice->GetDetector("FMD") ;
86   
87   if(fNevents == 0) 
88     fNevents = (Int_t) gAlice->TreeE()->GetEntries() ; 
89
90   cout<<"AliFMDSDigitizer-> Nevents"<<fNevents<<endl;
91   for(Int_t ievent = 0; ievent < fNevents; ievent++){
92     gAlice->GetEvent(ievent) ;
93     if(gAlice->TreeH()==0) return ;
94
95     if(gAlice->TreeS() == 0)            
96       gAlice->MakeTree("S") ;
97     
98     TClonesArray * FMDhits = FMD->Hits() ;
99
100     
101
102     Int_t nSdigits = 0 ;
103     
104     //Make branches
105     char branchname[20];
106     sprintf(branchname,"%s",FMD->GetName());  
107     
108     Int_t bufferSize = 16000 ;
109     char * file =0;
110     if(!fSDigitsFile.IsNull())
111       file = (char*) fSDigitsFile.Data() ; //ievent ;
112     else
113       if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
114         file = new char[30] ;
115         sprintf(file,"FMD.SDigits.root") ;
116         cout<<"CONFIG_SPLIT_FILE "<<file<<endl; 
117       }
118       else{
119         file = 0 ;
120         cout<<" FILE =0 "<<endl;}
121         cout<<"After CONFIG_SPLIT_FILE "<<file<<endl; 
122     
123     FMD->MakeBranchInTree(gAlice->TreeS(),branchname,&sdigits,bufferSize,file);
124   
125     /*    
126     Int_t splitlevel = 0 ;
127     sprintf(branchname,"AliFMDSDigitizer");   
128     AliFMDSDigitizer * sd = this ;
129     FMD->MakeBranchInTree(gAlice->TreeS(),branchname,"AliFMDSDigitizer",&sd, bufferSize, splitlevel,file); 
130     */
131
132     //Now made SDigits from hits, for PHOS it is the same
133   Int_t volume,sector,ring,charge;
134   Float_t e;
135   Float_t de[10][20][150];
136   Int_t ivol,isec,iring;
137   Int_t hit,nbytes;
138   TParticle *particle;
139   AliFMDhit  *fmdHit;
140
141  
142  // Event ------------------------- LOOP  
143  
144   for (ivol=1; ivol<=6; ivol++)
145     for(isec=0; isec<16; isec++)
146       for(iring=0; iring<128; iring++)
147         de[ivol][isec][iring]=0;
148       
149   if (FMD){
150     FMDhits   = FMD->Hits();
151     TTree *TH = gAlice->TreeH();
152     Stat_t ntracks    = TH->GetEntries();
153  
154    for (Int_t track=0; track<ntracks;track++) {
155      gAlice->ResetHits();
156      nbytes += TH->GetEvent(track);
157      particle=gAlice->Particle(track);
158      Int_t nhits =FMDhits->GetEntriesFast();
159      
160      for (hit=0;hit<nhits;hit++) {
161        fmdHit   = (AliFMDhit*)FMDhits->UncheckedAt(hit);
162        
163        volume = fmdHit->Volume();
164        sector = fmdHit->NumberOfSector();
165        ring   = fmdHit->NumberOfRing();
166        e = fmdHit->Edep();
167        de[volume][sector][ring]=de[volume][sector][ring]+e;
168
169      } //hit loop
170    } //track loop
171   }//if FMD
172   Int_t digit[5];
173   Float_t I=1.664*0.04*2.33/22400; // = 0.69e-6;
174   for(ivol=1; ivol<=6; ivol++){
175     for(isec=0; isec<16; isec++){
176       for(iring=0; iring<128; iring++){
177         if(de[ivol][isec][iring]>0.){
178           digit[0]=ivol;
179           digit[1]=isec;
180           digit[2]=iring;
181           charge=Int_t (de[ivol][isec][iring]/I);
182           digit[3]=charge;
183
184           //dinamic diapason from MIP(0.155MeV) to 30MIP(4.65MeV)
185           //1024 ADC channels 
186           Float_t channelWidth=(22400*30)/1024;
187           digit[4]=Int_t(digit[3]/channelWidth);
188
189           new((*sdigits)[nSdigits++]) AliFMDdigit(digit) ;
190           
191         } //de >threshold
192       }// iring loop
193     }//sector loop
194   } // volume loop
195
196
197   
198   
199     gAlice->TreeS()->Fill() ;
200     TFile *f1 = new TFile(file,"RECREATE");
201     f1->cd();
202     gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
203   }
204
205   if (sdigits) {
206     sdigits->Delete();
207     delete sdigits ;
208     sdigits = 0;
209   }
210
211   if(file)
212     file->Close() ;
213
214 }
215 //__________________________________________________________________
216 void AliFMDSDigitizer::SetSDigitsFile(char * file ){
217   if(!fSDigitsFile.IsNull())
218     cout << "Changing SDigits file from " <<(char *)fSDigitsFile.Data() << " to " << file << endl ;
219   fSDigitsFile=file ;
220 }
221 //__________________________________________________________________
222 void AliFMDSDigitizer::Print(Option_t* option)const{
223   cout << "------------------- "<< GetName() << " -------------" << endl ;
224   if(fSDigitsFile.IsNull())
225     cout << " Writing SDigitis to file galice.root "<< endl ;
226   else
227     cout << "    Writing SDigitis to file  " << (char*) fSDigitsFile.Data() << endl ;
228
229 }