]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZERODigitizer.cxx
Adding AliVZEROv6
[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 class constructs Digits out of Hits
19 ///
20 ///
21
22 // --- Standard library ---
23
24 // --- ROOT system ---
25 #include <TTree.h>
26
27 // --- AliRoot header files ---
28 #include "AliVZEROConst.h"
29 #include "AliRun.h"
30 #include "AliVZERO.h"
31 #include "AliVZEROhit.h"
32 #include "AliRunLoader.h"
33 #include "AliLoader.h"
34 #include "AliRunDigitizer.h"
35 #include "AliVZEROdigit.h"
36 #include "AliVZERODigitizer.h"
37
38 ClassImp(AliVZERODigitizer)
39
40  AliVZERODigitizer::AliVZERODigitizer()
41 {
42   // default constructor
43
44    fNdigits = 0;
45    fDigits = 0 ;
46   
47    fPhotoCathodeEfficiency =   0.18;
48    fPMVoltage              =  768.0;
49    fPMGain = TMath::Power((fPMVoltage / 112.5) ,7.04277);     
50 }
51
52 //____________________________________________________________________________ 
53   AliVZERODigitizer::AliVZERODigitizer(AliRunDigitizer* manager)
54                     :AliDigitizer(manager)
55                     
56 {
57   // constructor
58   
59   fNdigits = 0;
60   fDigits = 0 ;
61   
62   fPhotoCathodeEfficiency =   0.18;
63   fPMVoltage              =  768.0;
64   fPMGain = TMath::Power( (fPMVoltage / 112.5) ,7.04277 );
65 }
66            
67 //____________________________________________________________________________ 
68   AliVZERODigitizer::~AliVZERODigitizer()
69 {
70   // destructor
71   
72   if (fDigits) {
73     fDigits->Delete();
74     delete fDigits;
75     fDigits=0; 
76   }
77 }
78
79 //_____________________________________________________________________________
80 Bool_t AliVZERODigitizer::Init()
81 {
82   // Initialises the digitizer
83
84   // Initialises the Digit array
85   fDigits = new TClonesArray ("AliVZEROdigit", 1000);
86
87   return kTRUE;
88 }
89
90 //____________________________________________________________________________
91 void AliVZERODigitizer::Exec(Option_t* /*option*/) 
92
93   //
94   // Creates digits from hits
95   //
96   
97   fNdigits = 0;
98   Int_t map[96];
99   Float_t cPM = fPhotoCathodeEfficiency * fPMGain;
100              
101   for(Int_t i=0; i<96; i++) map[i] = 0; 
102           
103   AliRunLoader* outRunLoader = 
104     AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());    
105   if (!outRunLoader) {
106     Error("Exec", "Can not get output Run Loader");
107     return;
108   }
109   AliLoader* outLoader = outRunLoader->GetLoader("VZEROLoader");
110   if (!outLoader) {
111     Error("Exec", "Can not get output VZERO Loader");
112     return;
113   }
114
115   outLoader->LoadDigits("update");
116   if (!outLoader->TreeD()) outLoader->MakeTree("D");
117   outLoader->MakeDigitsContainer();
118   TTree* treeD = outLoader->TreeD();
119   Int_t bufsize = 16000;
120   treeD->Branch("VZERODigit", &fDigits, bufsize); 
121
122   for (Int_t iInput = 0; iInput < fManager->GetNinputs(); iInput++) {
123     AliRunLoader* runLoader = 
124       AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
125     AliLoader* loader = runLoader->GetLoader("VZEROLoader");
126     if (!loader) {
127       Error("Exec", "Can not get VZERO Loader for input %d", iInput);
128       continue;
129     }
130     if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
131
132     AliVZERO* vzero = (AliVZERO*) runLoader->GetAliRun()->GetDetector("VZERO");
133     if (!vzero) {
134       Error("Exec", "No VZERO detector for input %d", iInput);
135       continue;
136     }
137       
138     loader->LoadHits();
139     TTree* treeH = loader->TreeH();
140     if (!treeH) {
141       Error("Exec", "Cannot get TreeH for input %d", iInput);
142       continue; 
143     }
144     TClonesArray* hits = vzero->Hits();
145              
146 //  Now makes Digits from hits
147          
148     Int_t nTracks = (Int_t) treeH->GetEntries();
149     for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
150       vzero->ResetHits();
151       treeH->GetEvent(iTrack);
152       Int_t nHits = hits->GetEntriesFast();
153       for (Int_t iHit = 0; iHit < nHits; iHit++) {
154         AliVZEROhit* hit = (AliVZEROhit *)hits->UncheckedAt(iHit);
155         Int_t nPhot = hit->Nphot();
156         Int_t cell  = hit->Cell();                                    
157         map[cell] += nPhot;
158       }           // hit   loop
159     }             // track loop
160
161     loader->UnloadHits();
162
163   }               // input loop
164             
165   for (Int_t i=0; i<96; i++) {
166     Float_t q1 = Float_t ( map[i] )* cPM * kQe;
167     Float_t noise = gRandom->Gaus(10.5,3.22);
168     Float_t pmResponse  =  q1/kC*TMath::Power(ktheta/kthau,1/(1-ktheta/kthau)) 
169       + noise*1e-3;
170     map[i] = Int_t( pmResponse * 200.0);
171     if(map[i] > 3) {
172 //    printf(" Event, cell, adc = %d %d %d\n", outRunLoader->GetEventNumber(),i, map[i]);
173       AddDigit(i, map[i]);
174     } 
175   }
176
177   treeD->Fill();
178   outLoader->WriteDigits("OVERWRITE");  
179   outLoader->UnloadDigits();     
180   ResetDigit();
181 }
182
183 //____________________________________________________________________________
184 void AliVZERODigitizer::AddDigit(Int_t cellnumber, Int_t adc) 
185  { 
186  
187 // Adds Digit 
188  
189   TClonesArray &ldigits = *fDigits;  
190   new(ldigits[fNdigits++]) AliVZEROdigit(cellnumber,adc);
191 }
192 //____________________________________________________________________________
193 void AliVZERODigitizer::ResetDigit()
194 {
195 //
196 // Clears Digits
197 //
198   fNdigits = 0;
199   if (fDigits) fDigits->Delete();
200 }