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