Digitization included into AliSimulation framework
[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;
b0d2c2d3 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
9e04c3b6 97 fNdigits = 0;
9e04c3b6 98 Int_t map[96];
9e04c3b6 99 Float_t cPM = fPhotoCathodeEfficiency * fPMGain;
2d7933c7 100
9e04c3b6 101 for(Int_t i=0; i<96; i++) map[i] = 0;
102
b0d2c2d3 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 }
9e04c3b6 137
b0d2c2d3 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();
9e04c3b6 145
b0d2c2d3 146// Now makes Digits from hits
9e04c3b6 147
b0d2c2d3 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
9e04c3b6 164
b0d2c2d3 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();
9e04c3b6 181}
182
183//____________________________________________________________________________
b0d2c2d3 184void AliVZERODigitizer::AddDigit(Int_t cellnumber, Int_t adc)
9e04c3b6 185 {
186
187// Adds Digit
188
189 TClonesArray &ldigits = *fDigits;
b0d2c2d3 190 new(ldigits[fNdigits++]) AliVZEROdigit(cellnumber,adc);
9e04c3b6 191}
192//____________________________________________________________________________
193void AliVZERODigitizer::ResetDigit()
194{
b0d2c2d3 195//
9e04c3b6 196// Clears Digits
b0d2c2d3 197//
9e04c3b6 198 fNdigits = 0;
b0d2c2d3 199 if (fDigits) fDigits->Delete();
9e04c3b6 200}