]> git.uio.no Git - u/mrichter/AliRoot.git/blame - VZERO/AliVZERODigitizer.cxx
AliCDBManager added
[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>
e939a978 26#include <TRandom.h>
9e04c3b6 27
28// --- AliRoot header files ---
29#include "AliVZEROConst.h"
30#include "AliRun.h"
31#include "AliVZERO.h"
32#include "AliVZEROhit.h"
9e04c3b6 33#include "AliRunLoader.h"
34#include "AliLoader.h"
9e04c3b6 35#include "AliRunDigitizer.h"
ce7090f5 36#include "AliCDBManager.h"
37#include "AliCDBStorage.h"
38#include "AliCDBEntry.h"
39#include "AliVZEROCalibData.h"
40
9e04c3b6 41#include "AliVZEROdigit.h"
b0d2c2d3 42#include "AliVZERODigitizer.h"
9e04c3b6 43
44ClassImp(AliVZERODigitizer)
45
46 AliVZERODigitizer::AliVZERODigitizer()
0b2bea8b 47 :AliDigitizer(),
48 fCalibData(GetCalibData()),
49 fPhotoCathodeEfficiency(0.18),
50 fPMVoltage(768.0),
51 fPMGain(TMath::Power((fPMVoltage / 112.5) ,7.04277)),
52 fNdigits(0),
53 fDigits(0)
54
9e04c3b6 55{
b0d2c2d3 56 // default constructor
57
0b2bea8b 58// fNdigits = 0;
59// fDigits = 0;
60//
61// fPhotoCathodeEfficiency = 0.18;
62// fPMVoltage = 768.0;
63// fPMGain = TMath::Power((fPMVoltage / 112.5) ,7.04277);
ce7090f5 64
0b2bea8b 65// fCalibData = GetCalibData();
9e04c3b6 66}
67
68//____________________________________________________________________________
69 AliVZERODigitizer::AliVZERODigitizer(AliRunDigitizer* manager)
0b2bea8b 70 :AliDigitizer(manager),
71 fCalibData(GetCalibData()),
72 fPhotoCathodeEfficiency(0.18),
73 fPMVoltage(768.0),
74 fPMGain(TMath::Power((fPMVoltage / 112.5) ,7.04277)),
75 fNdigits(0),
76 fDigits(0)
77
9e04c3b6 78{
79 // constructor
80
0b2bea8b 81// fNdigits = 0;
82// fDigits = 0;
83//
84// fPhotoCathodeEfficiency = 0.18;
85// fPMVoltage = 768.0;
86// fPMGain = TMath::Power( (fPMVoltage / 112.5) ,7.04277 );
ce7090f5 87
0b2bea8b 88// fCalibData = GetCalibData();
ce7090f5 89
9e04c3b6 90}
91
92//____________________________________________________________________________
93 AliVZERODigitizer::~AliVZERODigitizer()
94{
95 // destructor
96
97 if (fDigits) {
98 fDigits->Delete();
99 delete fDigits;
b0d2c2d3 100 fDigits=0;
101 }
9e04c3b6 102}
103
b0d2c2d3 104//_____________________________________________________________________________
105Bool_t AliVZERODigitizer::Init()
9e04c3b6 106{
b0d2c2d3 107 // Initialises the digitizer
9e04c3b6 108
b0d2c2d3 109 // Initialises the Digit array
9e04c3b6 110 fDigits = new TClonesArray ("AliVZEROdigit", 1000);
111
b0d2c2d3 112 return kTRUE;
9e04c3b6 113}
114
115//____________________________________________________________________________
b0d2c2d3 116void AliVZERODigitizer::Exec(Option_t* /*option*/)
ce7090f5 117{
b0d2c2d3 118 // Creates digits from hits
ce7090f5 119
20277079 120 Int_t map[80]; // 48 values on V0C + 32 on V0A
121 Int_t adc[64]; // 32 PMs on V0C + 32 PMs on V0A
122 Float_t time[80], time2[64], adc_gain[80];
ce7090f5 123 fNdigits = 0;
124 Float_t cPM = fPhotoCathodeEfficiency * fPMGain;
125
126 // Retrieval of ADC gain values from local CDB
127 // I use only the first 64th values of the calibration array in CDB
128 // as I have no beam burst structure - odd or even beam burst number
b0d2c2d3 129
ce7090f5 130 // Reminder : We have 16 scintillating cells mounted on 8 PMs
20277079 131 // on Ring 3 and Ring 4 in V0C - added to produce ADC outputs
132 // on these rings...
ce7090f5 133
134 for(Int_t i=0; i<16; i++) { adc_gain[i] = fCalibData->GetGain(i) ; };
135
136 for(Int_t j=16; j<48; j=j+2) {
137 Int_t i=(j+17)/2;
138 adc_gain[j] = fCalibData->GetGain(i) ;
139 adc_gain[j+1] = fCalibData->GetGain(i) ; }
140 for(Int_t i=48; i<80; i++) { adc_gain[i] = fCalibData->GetGain(i-16) ; }
141
142// for(Int_t i=0; i<80; i++) { printf(" i = %d gain = %f\n\n", i, adc_gain[i] );}
143
b0d2c2d3 144 AliRunLoader* outRunLoader =
145 AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
146 if (!outRunLoader) {
147 Error("Exec", "Can not get output Run Loader");
ce7090f5 148 return;}
149
b0d2c2d3 150 AliLoader* outLoader = outRunLoader->GetLoader("VZEROLoader");
151 if (!outLoader) {
152 Error("Exec", "Can not get output VZERO Loader");
ce7090f5 153 return;}
b0d2c2d3 154
155 outLoader->LoadDigits("update");
156 if (!outLoader->TreeD()) outLoader->MakeTree("D");
157 outLoader->MakeDigitsContainer();
ce7090f5 158 TTree* treeD = outLoader->TreeD();
b0d2c2d3 159 Int_t bufsize = 16000;
160 treeD->Branch("VZERODigit", &fDigits, bufsize);
161
162 for (Int_t iInput = 0; iInput < fManager->GetNinputs(); iInput++) {
163 AliRunLoader* runLoader =
164 AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
165 AliLoader* loader = runLoader->GetLoader("VZEROLoader");
166 if (!loader) {
167 Error("Exec", "Can not get VZERO Loader for input %d", iInput);
ce7090f5 168 continue;}
169
b0d2c2d3 170 if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
171
172 AliVZERO* vzero = (AliVZERO*) runLoader->GetAliRun()->GetDetector("VZERO");
173 if (!vzero) {
174 Error("Exec", "No VZERO detector for input %d", iInput);
ce7090f5 175 continue;}
9e04c3b6 176
b0d2c2d3 177 loader->LoadHits();
178 TTree* treeH = loader->TreeH();
179 if (!treeH) {
180 Error("Exec", "Cannot get TreeH for input %d", iInput);
ce7090f5 181 continue; }
841137ce 182
183 Float_t timeV0 = 1e12;
20277079 184 for(Int_t i=0; i<80; i++) { map[i] = 0; time[i] = 0.0; }
841137ce 185
b0d2c2d3 186 TClonesArray* hits = vzero->Hits();
9e04c3b6 187
b0d2c2d3 188// Now makes Digits from hits
9e04c3b6 189
b0d2c2d3 190 Int_t nTracks = (Int_t) treeH->GetEntries();
191 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
192 vzero->ResetHits();
193 treeH->GetEvent(iTrack);
194 Int_t nHits = hits->GetEntriesFast();
195 for (Int_t iHit = 0; iHit < nHits; iHit++) {
196 AliVZEROhit* hit = (AliVZEROhit *)hits->UncheckedAt(iHit);
197 Int_t nPhot = hit->Nphot();
198 Int_t cell = hit->Cell();
20277079 199 map[cell] += nPhot;
200 Float_t dt_scintillator = gRandom->Gaus(0,0.7);
841137ce 201 time[cell] = dt_scintillator + 1e9*hit->Tof();
202 if(time[cell] < timeV0) timeV0 = time[cell];
b0d2c2d3 203 } // hit loop
204 } // track loop
205
206 loader->UnloadHits();
207
208 } // input loop
20277079 209
210// Now builds the scintillator cell response (80 cells i.e. 80 responses)
841137ce 211
20277079 212 for (Int_t i=0; i<80; i++) {
213 Float_t q1 = Float_t ( map[i] )* cPM * kQe;
214 Float_t noise = gRandom->Gaus(10.5,3.22);
215 Float_t pmResponse = q1/kC*TMath::Power(ktheta/kthau,1/(1-ktheta/kthau))
216 + noise*1e-3;
217 map[i] = Int_t( pmResponse * adc_gain[i]);
218 }
219
220
221// Now transforms 80 cell responses into 64 photomultiplier responses
222
223 for (Int_t j=0; j<32; j++){
224 adc[j] = map [j];
225 time2[j]= time[j];}
226
227 for (Int_t j=48; j<80; j++){
228 adc[j-16] = map [j];
229 time2[j-16]= time[j];}
230
231 for (Int_t j=0; j<16; j++){
232 adc[16+j] = map [16 + 2*j]+ map [16 + 2*j + 1];
233 time2[16+j] = TMath::Min(time [16 + 2*j], time [16 + 2*j + 1]);}
234
235// Now add digits to the digit Tree
236
237 for (Int_t i=0; i<64; i++) {
238 if(adc[i] > 0) {
239// printf(" Event, cell, adc, tof = %d %d %d %f\n",
240// outRunLoader->GetEventNumber(),i, map[i], time[i]*100.0);
5c1828c2 241// multiply by 10 to have 100 ps per channel :
20277079 242 AddDigit(i, adc[i], Int_t(time2[i]*10.0) );
243 }
244 }
b0d2c2d3 245
20277079 246
b0d2c2d3 247 treeD->Fill();
248 outLoader->WriteDigits("OVERWRITE");
249 outLoader->UnloadDigits();
250 ResetDigit();
9e04c3b6 251}
252
253//____________________________________________________________________________
20277079 254void AliVZERODigitizer::AddDigit(Int_t PMnumber, Int_t adc, Int_t time)
9e04c3b6 255 {
256
257// Adds Digit
258
259 TClonesArray &ldigits = *fDigits;
20277079 260 new(ldigits[fNdigits++]) AliVZEROdigit(PMnumber,adc,time);
9e04c3b6 261}
262//____________________________________________________________________________
263void AliVZERODigitizer::ResetDigit()
264{
b0d2c2d3 265//
9e04c3b6 266// Clears Digits
b0d2c2d3 267//
9e04c3b6 268 fNdigits = 0;
b0d2c2d3 269 if (fDigits) fDigits->Delete();
9e04c3b6 270}
ce7090f5 271
272//____________________________________________________________________________
273AliVZEROCalibData* AliVZERODigitizer::GetCalibData() const
274
275{
c0b82b5a 276 AliCDBManager *man = AliCDBManager::Instance();
ce7090f5 277
c0b82b5a 278 AliCDBEntry *entry=0;
ce7090f5 279
c0b82b5a 280 entry = man->Get("VZERO/Calib/Data");
281
282 if(!entry){
283 AliWarning("Load of calibration data from default storage failed!");
284 AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
285 Int_t runNumber = man->GetRun();
286 entry = man->GetStorage("local://$ALICE_ROOT")
287 ->Get("VZERO/Calib/Data",runNumber);
288
289 }
290
291 // Retrieval of data in directory VZERO/Calib/Data:
ce7090f5 292
ce7090f5 293
c0b82b5a 294 AliVZEROCalibData *calibdata = 0;
ce7090f5 295
c0b82b5a 296 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
297 if (!calibdata) AliError("No calibration data from calibration database !");
ce7090f5 298
c0b82b5a 299 return calibdata;
ce7090f5 300
301}
302