]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZERODigitizer.cxx
Pyhtia comparison extended
[u/mrichter/AliRoot.git] / VZERO / AliVZERODigitizer.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 //
18 // This  constructs Digits out of Hits
19 //
20
21 // --- Standard library ---
22 #include <Riostream.h>
23 #include <stdlib.h>
24
25 // --- ROOT system ---
26 #include <TFile.h>
27 #include <TFolder.h>
28 #include <TROOT.h>
29 #include <TSystem.h>
30 #include <TTree.h>
31 #include <TVirtualMC.h>
32
33 // --- AliRoot header files ---
34 #include "AliVZEROConst.h"
35 #include "AliRun.h"
36 #include "AliVZERO.h"
37 #include "AliVZEROhit.h"
38 #include "AliHit.h"
39 #include "AliDetector.h"
40 #include "AliRunLoader.h"
41 #include "AliLoader.h"
42 #include "AliConfig.h"
43 #include "AliRunDigitizer.h"
44 #include "AliDigitizer.h"
45 #include "AliHeader.h"
46 #include "AliStack.h"
47 #include "AliVZERODigitizer.h"
48 #include "AliVZEROdigit.h"
49 #include "AliMC.h"
50
51 ClassImp(AliVZERODigitizer)
52
53  AliVZERODigitizer::AliVZERODigitizer()
54 {
55    if (!fDigits) fDigits = new TClonesArray("AliVZEROdigit", 1000);
56    
57    fNevents = 0 ;     
58    fDigits = 0 ;
59    fNdigits = 0;
60    fHits = 0 ;
61    fRunLoader = 0;
62   
63    fPhotoCathodeEfficiency =   0.18;
64    fPMVoltage              =  768.0;
65    fPMGain = TMath::Power((fPMVoltage / 112.5) ,7.04277);     
66 }
67
68 //____________________________________________________________________________ 
69   AliVZERODigitizer::AliVZERODigitizer(AliRunDigitizer* manager)
70                     :AliDigitizer(manager)
71                     
72 {
73   // constructor
74   
75   fNevents = 0;     
76   fDigits = 0;
77   fNdigits = 0;
78   fHits = 0;
79   fRunLoader = 0;
80   
81   fPhotoCathodeEfficiency =   0.18;
82   fPMVoltage              =  768.0;
83   fPMGain = TMath::Power( (fPMVoltage / 112.5) ,7.04277 );
84 }
85            
86 //____________________________________________________________________________ 
87   AliVZERODigitizer::~AliVZERODigitizer()
88 {
89   // destructor
90   
91   if (fDigits) {
92     fDigits->Delete();
93     delete fDigits;
94     fDigits=0; }
95 }
96
97 //____________________________________________________________________________
98 void AliVZERODigitizer::OpengAliceFile(const char *file)
99 {
100   // Loads galice.root file and corresponding header, kinematics
101   // hits and  digits 
102   
103   fRunLoader = AliRunLoader::Open(file,AliConfig::fgkDefaultEventFolderName,
104                                   "UPDATE");
105   
106   if (!fRunLoader)
107    {
108      Error("Open","Can not open session for file %s.",file);
109    }
110   
111   fRunLoader->LoadgAlice();
112   fRunLoader->LoadHeader();
113   fRunLoader->LoadKinematics();
114
115   gAlice = fRunLoader->GetAliRun();
116   
117   if (gAlice)
118     { printf("<AliVZEROdigitizer::Open> ");
119       printf("AliRun object found on file.\n");}
120   else
121     { printf("<AliVZEROdigitizer::Open> ");
122       printf("Could not find AliRun object.\n");}
123     
124   // Initialise Hit and Digit arrays
125   fHits   = new TClonesArray ("AliVZEROhit", 1000);
126   fDigits = new TClonesArray ("AliVZEROdigit", 1000);
127
128   fVZERO  = (AliVZERO*) gAlice->GetDetector("VZERO");
129   fVZEROLoader = fRunLoader->GetLoader("VZEROLoader");
130   
131   if (fVZEROLoader == 0x0){
132       cerr<<"Hits2Digits : Can not find VZERO or VZEROLoader\n";}
133     
134   Int_t retval = fVZEROLoader->LoadHits("read");
135   if (retval){
136      Error("Open","Error occured while loading hits... Exiting.");
137      return;}
138       
139   fVZEROLoader->LoadDigits("recreate");  
140 }
141
142 //____________________________________________________________________________
143 void AliVZERODigitizer::Exec() 
144  { 
145
146   Int_t nbytes;
147   fNdigits = 0;
148   Int_t N; 
149   Int_t map[96];
150   Int_t cell = 0;
151   Float_t cPM = fPhotoCathodeEfficiency * fPMGain;
152              
153   for(Int_t i=0; i<96; i++) map[i] = 0; 
154           
155   fNevents = (Int_t) fRunLoader->TreeE()->GetEntries ();  
156   printf(" Number of events in file =  %d \n", fNevents);
157   
158   for (Int_t ievent = 0; ievent < fNevents; ievent++){
159       
160       for(Int_t i=0; i<96; i++) map[i] = 0;     
161       
162       fRunLoader->GetEvent(ievent);
163       
164       fTreeH = fVZEROLoader->TreeH();
165       if (fTreeH == 0x0)
166        { Error("Exec","Cannot get TreeH");
167          return; }
168              
169       fTreeD = fVZEROLoader->TreeD();
170       if (fTreeD == 0x0)
171       { fVZEROLoader->MakeTree("D");
172         fVZEROLoader->MakeDigitsContainer();
173         fTreeD = fVZEROLoader->TreeD(); }
174         
175       Int_t bufsize = 16000;
176       fTreeD->Branch("VZERODigit", &fDigits, bufsize); 
177       
178 //    Now make Digits from hits
179
180       if (fVZERO)
181        {
182          fHits = fVZERO->Hits();
183          
184          Int_t ntracks = (Int_t) fTreeH->GetEntries ();
185 //       printf(" Number of Tracks in the TreeH = %d \n", ntracks);
186          for (Int_t track = 0; track < ntracks; track++)
187            {
188              gAlice->ResetHits ();
189              nbytes += fTreeH->GetEvent(track);
190              fParticle = fRunLoader->Stack()->Particle(track);
191              Int_t nhits = fHits->GetEntriesFast();
192              for (Int_t hit = 0; hit < nhits; hit++)
193                  {
194                    fVZEROHit = (AliVZEROhit *)fHits->UncheckedAt(hit);
195                    N    = fVZEROHit->Nphot();
196                    cell = fVZEROHit->Cell();                                    
197                    map[cell] = map[cell] + N;
198                  }           // hit   loop
199            }                 // track loop
200             
201            Int_t icount = 0; 
202            
203            for(Int_t i=0; i<96; i++) {
204               Float_t q1 = Float_t ( map[i] )* cPM * kQe;
205               Float_t noise = gRandom->Gaus(10.5,3.22);
206               Float_t PMresponse  =  q1/kC*TMath::Power(ktheta/kthau,1/(1-ktheta/kthau)) 
207                                   + noise*1e-3;
208               map[i] = Int_t( PMresponse * 200.0);
209               if(map[i] > 3) {
210                  icount++;
211 //               printf(" Event, cell, adc = %d %d %d\n", ievent, i, map[i]);
212                  AddDigit(ievent, i, map[i]);} 
213             }
214
215            fTreeD->Reset();
216            fTreeD->Fill();
217            ResetDigit();
218            fVZEROLoader->WriteDigits("OVERWRITE");  
219            fVZEROLoader->UnloadDigits();     
220       }                     // VZERO loop
221     }  //event loop
222 }
223
224 //____________________________________________________________________________
225 void AliVZERODigitizer::AddDigit(Int_t eventnumber, Int_t cellnumber, Int_t adc) 
226  { 
227  
228 // Adds Digit 
229  
230   TClonesArray &ldigits = *fDigits;  
231   new(ldigits[fNdigits++]) AliVZEROdigit(eventnumber,cellnumber,adc);
232 }
233 //____________________________________________________________________________
234 void AliVZERODigitizer::ResetDigit()
235 {
236 // Clears Digits
237   fNdigits = 0;
238   if (fDigits) fDigits->Clear();
239 }