]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZERODigitizer.cxx
VZERO volumes now placed in common mother.
[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 /* $Id$ */
17
18 ///_________________________________________________________________________
19 ///
20 /// This class constructs Digits out of Hits
21 ///
22 ///
23
24 // --- Standard library ---
25
26 // --- ROOT system ---
27 #include <TMath.h>
28 #include <TTree.h>
29 #include <TRandom.h>
30
31 // --- AliRoot header files ---
32 #include "AliVZEROConst.h"
33 #include "AliRun.h"
34 #include "AliVZERO.h"
35 #include "AliVZEROhit.h"
36 #include "AliRunLoader.h"
37 #include "AliLoader.h"
38 #include "AliRunDigitizer.h"
39 #include "AliCDBManager.h"
40 #include "AliCDBStorage.h"
41 #include "AliCDBEntry.h"
42 #include "AliVZEROCalibData.h"
43
44 #include "AliVZEROdigit.h"
45 #include "AliVZERODigitizer.h"
46
47 ClassImp(AliVZERODigitizer)
48
49  AliVZERODigitizer::AliVZERODigitizer()
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    
58 {
59   // default constructor
60
61 //    fNdigits = 0;
62 //    fDigits  = 0;
63 //   
64 //    fPhotoCathodeEfficiency =   0.18;
65 //    fPMVoltage              =  768.0;
66 //    fPMGain = TMath::Power((fPMVoltage / 112.5) ,7.04277); 
67    
68 //   fCalibData = GetCalibData();
69 }
70
71 //____________________________________________________________________________ 
72   AliVZERODigitizer::AliVZERODigitizer(AliRunDigitizer* manager)
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                                         
81 {
82   // constructor
83   
84 //   fNdigits = 0;
85 //   fDigits  = 0;
86 //   
87 //   fPhotoCathodeEfficiency =   0.18;
88 //   fPMVoltage              =  768.0;
89 //   fPMGain = TMath::Power( (fPMVoltage / 112.5) ,7.04277 );
90   
91 //  fCalibData = GetCalibData();
92   
93 }
94            
95 //____________________________________________________________________________ 
96   AliVZERODigitizer::~AliVZERODigitizer()
97 {
98   // destructor
99   
100   if (fDigits) {
101     fDigits->Delete();
102     delete fDigits;
103     fDigits=0; 
104   }
105 }
106
107 //_____________________________________________________________________________
108 Bool_t AliVZERODigitizer::Init()
109 {
110   // Initialises the digitizer
111
112   // Initialises the Digit array
113   fDigits = new TClonesArray ("AliVZEROdigit", 1000);
114
115   return kTRUE;
116 }
117
118 //____________________________________________________________________________
119 void AliVZERODigitizer::Exec(Option_t* /*option*/) 
120 {   
121   // Creates digits from hits
122      
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
125   Float_t    time[80], time_ref[80], time2[64];
126   Float_t    adc_gain[80];    
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
133   
134   // Reminder : We have 16 scintillating cells mounted on 8 PMs 
135   // on Ring 3 and Ring 4 in V0C -  added to produce  ADC outputs 
136   // on these rings... 
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             
148   AliRunLoader* outRunLoader = 
149     AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());    
150   if (!outRunLoader) {
151     Error("Exec", "Can not get output Run Loader");
152     return;}
153     
154   AliLoader* outLoader = outRunLoader->GetLoader("VZEROLoader");
155   if (!outLoader) {
156     Error("Exec", "Can not get output VZERO Loader");
157     return;}
158
159   outLoader->LoadDigits("update");
160   if (!outLoader->TreeD()) outLoader->MakeTree("D");
161   outLoader->MakeDigitsContainer();
162   TTree* treeD  = outLoader->TreeD();
163   Int_t bufsize = 16000;
164   treeD->Branch("VZERODigit", &fDigits, bufsize); 
165   
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);
172       continue;}
173       
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);
179       continue;}
180       
181     loader->LoadHits();
182     TTree* treeH = loader->TreeH();
183     if (!treeH) {
184       Error("Exec", "Cannot get TreeH for input %d", iInput);
185       continue; }
186        
187     for(Int_t i=0; i<80; i++) {map[i] = 0; time[i] = 0.0;}
188               
189     TClonesArray* hits = vzero->Hits();
190              
191 //  Now makes Digits from hits
192          
193     Int_t nTracks = (Int_t) treeH->GetEntries();
194     for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
195       for (Int_t i=0; i<80; i++) {time_ref[i] = 999999.0;}   
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();                                    
203         map[cell] += nPhot;
204         Float_t dt_scintillator = gRandom->Gaus(0,0.7);
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      
211     }             // track loop
212
213     loader->UnloadHits();
214
215   }               // input loop
216
217 // Now builds the scintillator cell response (80 cells i.e. 80 responses)
218          
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      }
226       
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++){
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
247 // Now add digits to the digit Tree 
248         
249    for (Int_t i=0; i<64; i++) {      
250       if(adc[i] > 0) {
251 //      printf(" Event, cell, adc, tof = %d %d %d %f\n", 
252 //                 outRunLoader->GetEventNumber(),i, map[i], time2[i]*10.0);
253 //   multiply by 10 to have 100 ps per channel :
254       AddDigit(i, adc[i], Int_t(time2[i]*10.0) );
255      } 
256    }
257     
258   treeD->Fill();
259   outLoader->WriteDigits("OVERWRITE");  
260   outLoader->UnloadDigits();     
261   ResetDigit();
262 }
263
264 //____________________________________________________________________________
265 void AliVZERODigitizer::AddDigit(Int_t PMnumber, Int_t adc, Int_t time) 
266  { 
267  
268 // Adds Digit 
269  
270   TClonesArray &ldigits = *fDigits;  
271   new(ldigits[fNdigits++]) AliVZEROdigit(PMnumber,adc,time);
272 }
273 //____________________________________________________________________________
274 void AliVZERODigitizer::ResetDigit()
275 {
276 //
277 // Clears Digits
278 //
279   fNdigits = 0;
280   if (fDigits) fDigits->Delete();
281 }
282
283 //____________________________________________________________________________
284 AliVZEROCalibData* AliVZERODigitizer::GetCalibData() const
285
286 {
287   AliCDBManager *man = AliCDBManager::Instance();
288
289   AliCDBEntry *entry=0;
290
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:
303
304
305   AliVZEROCalibData *calibdata = 0;
306
307   if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
308   if (!calibdata)  AliError("No calibration data from calibration database !");
309
310   return calibdata;
311
312 }
313