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