- AliHLTComponent: bugfix in buffer handling; overwrite check added to
[u/mrichter/AliRoot.git] / VZERO / AliVZEROReconstructor.cxx
CommitLineData
b0d2c2d3 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/// class for VZERO reconstruction //
21/// //
22///////////////////////////////////////////////////////////////////////////////
23
35b120ff 24#include "AliRunLoader.h"
2eb38194 25#include "AliRawReader.h"
b0d2c2d3 26#include "AliVZEROReconstructor.h"
2eb38194 27#include "AliVZERORawStream.h"
35b120ff 28#include "AliESD.h"
b0d2c2d3 29
b0d2c2d3 30ClassImp(AliVZEROReconstructor)
31
ce7090f5 32//_____________________________________________________________________________
cb2228e6 33AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
35b120ff 34 fESDVZERO(0x0),
35 fESD(0x0),
36 fRunLoader(0x0),
cb2228e6 37 fCalibData(GetCalibData())
ce7090f5 38{
39 // Default constructor
ce7090f5 40 // Get calibration data
41
35b120ff 42 // fCalibData = GetCalibData();
ce7090f5 43}
44
45
46//_____________________________________________________________________________
47AliVZEROReconstructor& AliVZEROReconstructor::operator =
48 (const AliVZEROReconstructor& /*reconstructor*/)
49{
50// assignment operator
51
52 Fatal("operator =", "assignment operator not implemented");
53 return *this;
54}
55
56//_____________________________________________________________________________
57AliVZEROReconstructor::~AliVZEROReconstructor()
58{
59// destructor
35b120ff 60 delete fESDVZERO;
61
62}
63
64//_____________________________________________________________________________
65void AliVZEROReconstructor::Init(AliRunLoader* runLoader)
66{
67/// initializer
ce7090f5 68
35b120ff 69 fRunLoader = runLoader;
70 fESDVZERO = new AliESDVZERO;
71}
72
73//______________________________________________________________________
74void AliVZEROReconstructor::Reconstruct(AliRunLoader* runLoader) const
75{
76
77 AliVZEROLoader* loader = (AliVZEROLoader* )runLoader->GetLoader( "VZEROLoader" );
78// AliVZEROLoader* loader = (AliVZEROLoader* )fRunLoader->GetLoader( "VZEROLoader" );
79
80 loader->LoadDigits("READ");
81 TTree* vzeroDigitsTree = loader->TreeD();
82 if (!vzeroDigitsTree) return;
83
84 TClonesArray* vzeroDigits = new TClonesArray("AliVZEROdigit",1000);
85 TBranch* digitBranch = vzeroDigitsTree->GetBranch("VZERODigit");
86 digitBranch->SetAddress(&vzeroDigits);
87
88 Int_t NbPMV0A = 0;
89 Int_t NbPMV0C = 0;
90 Int_t MTotV0A = 0;
91 Int_t MTotV0C = 0;
92 Float_t ADCV0A = 0.0;
93 Float_t ADCV0C = 0.0;
94 Float_t MultV0A[4];
95 Float_t MultV0C[4];
96 Int_t MRingV0A[4];
97 Int_t MRingV0C[4];
98
99 Int_t ADC[64];
100 Float_t MIP[64];
101 for (Int_t i=0; i<64; i++){
102 ADC[i] = 0;
103 MIP[i] = 110.0;}
104 for (Int_t j=0; j<4; j++){
105 MultV0A[j] = 0.0;
106 MultV0C[j] = 0.0;
107 MRingV0A[j] = 0;
108 MRingV0C[j] = 0;}
109
110 // loop over VZERO entries
111 Int_t nEntries = (Int_t)vzeroDigitsTree->GetEntries();
112 for (Int_t e=0; e<nEntries; e++) {
113 vzeroDigitsTree->GetEvent(e);
114
115 Int_t nDigits = vzeroDigits->GetEntriesFast();
116
117 for (Int_t d=0; d<nDigits; d++) {
118 AliVZEROdigit* digit = (AliVZEROdigit*)vzeroDigits->At(d);
119 Int_t PMNumber = digit->PMNumber();
120 ADC[PMNumber] = digit->ADC();
121 if (PMNumber<=31) {
122 if (PMNumber<=7) MultV0C[0]=MultV0C[0]+ float(ADC[PMNumber])/MIP[PMNumber];
123 if (PMNumber>=8 && PMNumber<=15) MultV0C[1]=MultV0C[1]+ float(ADC[PMNumber])/MIP[PMNumber];
124 if (PMNumber>=16 && PMNumber<=23) MultV0C[2]=MultV0C[2]+ float(ADC[PMNumber])/MIP[PMNumber];
125 if (PMNumber>=24 && PMNumber<=31) MultV0C[3]=MultV0C[3]+ float(ADC[PMNumber])/MIP[PMNumber];
126 ADCV0C = ADCV0C + float(ADC[PMNumber])/MIP[PMNumber];
127 if(ADC[PMNumber] > 4) NbPMV0C++;
128 }
129 if (PMNumber>=32) {
130 if (PMNumber>=32 && PMNumber<=39) MultV0A[0]=MultV0A[0]+ float(ADC[PMNumber])/MIP[PMNumber];
131 if (PMNumber>=40 && PMNumber<=47) MultV0A[1]=MultV0A[1]+ float(ADC[PMNumber])/MIP[PMNumber];
132 if (PMNumber>=48 && PMNumber<=55) MultV0A[2]=MultV0A[2]+ float(ADC[PMNumber])/MIP[PMNumber];
133 if (PMNumber>=56 && PMNumber<=63) MultV0A[3]=MultV0A[3]+ float(ADC[PMNumber])/MIP[PMNumber];
134 ADCV0A = ADCV0A + float(ADC[PMNumber])/MIP[PMNumber];
135 if(ADC[PMNumber] > 4) NbPMV0A++;
136 }
137 } // end of loop over digits
138
139 } // end of loop over events in digits tree
140
141 MTotV0A = int(ADCV0A + 0.5);
142 MTotV0C = int(ADCV0C + 0.5);
143 for (Int_t j=0; j<4; j++){
144 MRingV0A[j] = int(MultV0A[j] + 0.5);
145 MRingV0C[j] = int(MultV0C[j] + 0.5);}
146
147 AliDebug(1,Form("VZERO multiplicities : %d (V0A) %d (V0C)", MTotV0A, MTotV0C));
148 AliDebug(1,Form("Number of PMs fired : %d (V0A) %d (V0C)", NbPMV0A, NbPMV0C));
149
150 fESDVZERO->SetNbPMV0A(NbPMV0A);
151 fESDVZERO->SetNbPMV0C(NbPMV0C);
152 fESDVZERO->SetMTotV0A(MTotV0A);
153 fESDVZERO->SetMTotV0C(MTotV0C);
154 fESDVZERO->SetMRingV0A(MRingV0A);
155 fESDVZERO->SetMRingV0C(MRingV0C);
156
ce7090f5 157}
158
2eb38194 159//______________________________________________________________________
160void AliVZEROReconstructor::Reconstruct(AliRunLoader* runLoader,AliRawReader* rawReader) const
161{
162
163 Int_t nEvents = runLoader->GetNumberOfEvents();
164
165 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
166 if (!rawReader->NextEvent()) break;
167 AliVZERORawStream rawStream(rawReader);
168
169 Int_t NbPMV0A = 0;
170 Int_t NbPMV0C = 0;
171 Int_t MTotV0A = 0;
172 Int_t MTotV0C = 0;
173 Float_t ADCV0A = 0.0;
174 Float_t ADCV0C = 0.0;
175 Float_t MultV0A[4];
176 Float_t MultV0C[4];
177 Int_t MRingV0A[4];
178 Int_t MRingV0C[4];
179
180 Int_t ADC[64];
181 Float_t MIP[64];
182 for (Int_t i=0; i<64; i++){
183 ADC[i] = 0;
184 MIP[i] = 110.0;}
185 for (Int_t j=0; j<4; j++){
186 MultV0A[j] = 0.0;
187 MultV0C[j] = 0.0;
188 MRingV0A[j] = 0;
189 MRingV0C[j] = 0;}
190
191 // loop over VZERO entries
192 while (rawStream.Next()) {
193 Int_t PMNumber = rawStream.GetCell();
194 ADC[PMNumber] = rawStream.GetADC();
195 if (PMNumber<=31) {
196 if (PMNumber<=7) MultV0C[0]=MultV0C[0]+ float(ADC[PMNumber])/MIP[PMNumber];
197 if (PMNumber>=8 && PMNumber<=15) MultV0C[1]=MultV0C[1]+ float(ADC[PMNumber])/MIP[PMNumber];
198 if (PMNumber>=16 && PMNumber<=23) MultV0C[2]=MultV0C[2]+ float(ADC[PMNumber])/MIP[PMNumber];
199 if (PMNumber>=24 && PMNumber<=31) MultV0C[3]=MultV0C[3]+ float(ADC[PMNumber])/MIP[PMNumber];
200 ADCV0C = ADCV0C + float(ADC[PMNumber])/MIP[PMNumber];
201 if(ADC[PMNumber] > 4) NbPMV0C++;
202 }
203 if (PMNumber>=32) {
204 if (PMNumber>=32 && PMNumber<=39) MultV0A[0]=MultV0A[0]+ float(ADC[PMNumber])/MIP[PMNumber];
205 if (PMNumber>=40 && PMNumber<=47) MultV0A[1]=MultV0A[1]+ float(ADC[PMNumber])/MIP[PMNumber];
206 if (PMNumber>=48 && PMNumber<=55) MultV0A[2]=MultV0A[2]+ float(ADC[PMNumber])/MIP[PMNumber];
207 if (PMNumber>=56 && PMNumber<=63) MultV0A[3]=MultV0A[3]+ float(ADC[PMNumber])/MIP[PMNumber];
208 ADCV0A = ADCV0A + float(ADC[PMNumber])/MIP[PMNumber];
209 if(ADC[PMNumber] > 4) NbPMV0A++;
210 }
211 } // end of loop over digits
212
213 MTotV0A = int(ADCV0A + 0.5);
214 MTotV0C = int(ADCV0C + 0.5);
215 for (Int_t j=0; j<4; j++){
216 MRingV0A[j] = int(MultV0A[j] + 0.5);
217 MRingV0C[j] = int(MultV0C[j] + 0.5);}
218
219 AliDebug(1,Form("VZERO multiplicities : %d (V0A) %d (V0C)", MTotV0A, MTotV0C));
220 AliDebug(1,Form("Number of PMs fired : %d (V0A) %d (V0C)", NbPMV0A, NbPMV0C));
221
222 fESDVZERO->SetNbPMV0A(NbPMV0A);
223 fESDVZERO->SetNbPMV0C(NbPMV0C);
224 fESDVZERO->SetMTotV0A(MTotV0A);
225 fESDVZERO->SetMTotV0C(MTotV0C);
226 fESDVZERO->SetMRingV0A(MRingV0A);
227 fESDVZERO->SetMRingV0C(MRingV0C);
228 } // end of loop over events in digits tree
229}
35b120ff 230
231//_____________________________________________________________________________
232void AliVZEROReconstructor::FillESD(AliRunLoader* /*runLoader*/,
233 AliESD* esd) const
234{
235// fill ESD
236
237 if (esd) {
238 AliDebug(1, Form("Writing VZERO data to ESD tree"));
239 esd->SetVZEROData(fESDVZERO);
240 }
ce7090f5 241
35b120ff 242}
243
ce7090f5 244//_____________________________________________________________________________
245AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
246{
247
248 Bool_t deleteManager = kFALSE;
249
250 AliCDBManager *manager = AliCDBManager::Instance();
251 AliCDBStorage *defstorage = manager->GetDefaultStorage();
252
253 if(!defstorage || !(defstorage->Contains("VZERO"))){
254 AliWarning("No default storage set or default storage doesn't contain VZERO!");
255 manager->SetDefaultStorage(uri);
256 deleteManager = kTRUE;
257 }
258
259 AliCDBStorage *storage = manager->GetDefaultStorage();
260
261 if(deleteManager){
262 AliCDBManager::Instance()->UnsetDefaultStorage();
263 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
264 }
265
266 return storage;
267}
268
269//_____________________________________________________________________________
270AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
271{
272
273 // Getting calibration object for VZERO set
274
c0b82b5a 275 AliCDBManager *man = AliCDBManager::Instance();
ce7090f5 276
c0b82b5a 277 AliCDBEntry *entry=0;
278
279 entry = man->Get("VZERO/Calib/Data");
280
281 if(!entry){
282 AliWarning("Load of calibration data from default storage failed!");
283 AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
284 Int_t runNumber = man->GetRun();
285 entry = man->GetStorage("local://$ALICE_ROOT")
286 ->Get("VZERO/Calib/Data",runNumber);
287
288 }
289
290 // Retrieval of data in directory VZERO/Calib/Data:
291
292
293 AliVZEROCalibData *calibdata = 0;
294
295 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
296 if (!calibdata) AliError("No calibration data from calibration database !");
ce7090f5 297
298 return calibdata;
299}