Correct index when filling amplitude histograms, L1 amplitude histograms for gamma...
[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
b44c933e 24#include <TH1F.h>
25#include <TF1.h>
b6fd9c4a 26#include <TParameter.h>
b44c933e 27
35b120ff 28#include "AliRunLoader.h"
2eb38194 29#include "AliRawReader.h"
fe0adf2a 30#include "AliGRPObject.h"
31#include "AliCDBManager.h"
32#include "AliCDBStorage.h"
33#include "AliCDBEntry.h"
b0d2c2d3 34#include "AliVZEROReconstructor.h"
2eb38194 35#include "AliVZERORawStream.h"
b44c933e 36#include "AliVZEROConst.h"
b14e6eb4 37#include "AliESDEvent.h"
a055ee24 38#include "AliVZEROTriggerMask.h"
b090e6a3 39#include "AliESDfriend.h"
40#include "AliESDVZEROfriend.h"
fad64858 41#include "AliVZEROdigit.h"
e58b4e66 42#include "AliVZEROCalibData.h"
75b6bc77 43#include "AliRunInfo.h"
b44c933e 44#include "AliCTPTimeParams.h"
30d5d647 45#include "AliLHCClockPhase.h"
b0d2c2d3 46
b0d2c2d3 47ClassImp(AliVZEROReconstructor)
48
ce7090f5 49//_____________________________________________________________________________
cb2228e6 50AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
fe0adf2a 51 fESDVZERO(0x0),
52 fESD(0x0),
53 fESDVZEROfriend(0x0),
b44c933e 54 fCalibData(NULL),
1999c0f1 55 fTriggerData(NULL),
b44c933e 56 fTimeSlewing(NULL),
53ad561b 57 fSaturationCorr(NULL),
fe0adf2a 58 fCollisionMode(0),
dbf24214 59 fBeamEnergy(0.),
60 fDigitsArray(0)
ce7090f5 61{
62 // Default constructor
ce7090f5 63 // Get calibration data
64
b44c933e 65 fCalibData = GetCalibData();
66
67 AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
68 if (!entry) AliFatal("CTP timing parameters are not found in OCDB !");
69 AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
70 Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
71
7905581c 72 AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
73 if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
74 AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
75 l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
76
b44c933e 77 AliCDBEntry *entry2 = AliCDBManager::Instance()->Get("VZERO/Calib/TimeDelays");
78 if (!entry2) AliFatal("VZERO time delays are not found in OCDB !");
79 TH1F *delays = (TH1F*)entry2->GetObject();
80
81 AliCDBEntry *entry3 = AliCDBManager::Instance()->Get("VZERO/Calib/TimeSlewing");
82 if (!entry3) AliFatal("VZERO time slewing function is not found in OCDB !");
83 fTimeSlewing = (TF1*)entry3->GetObject();
84
30d5d647 85 AliCDBEntry *entry4 = AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
86 if (!entry4) AliFatal("LHC clock-phase shift is not found in OCDB !");
87 AliLHCClockPhase *phase = (AliLHCClockPhase*)entry4->GetObject();
88
b44c933e 89 for(Int_t i = 0 ; i < 64; ++i) {
90 Int_t board = AliVZEROCalibData::GetBoardNumber(i);
87e3cdfb 91 fTimeOffset[i] = (((Float_t)fCalibData->GetRollOver(board)-
92 (Float_t)fCalibData->GetTriggerCountOffset(board))*25.0+
7905581c 93 fCalibData->GetTimeOffset(i)-
30d5d647 94 l1Delay-
95 phase->GetMeanPhase()+
b44c933e 96 delays->GetBinContent(i+1)+
97 kV0Offset);
98 }
53ad561b 99
100 AliCDBEntry *entry5 = AliCDBManager::Instance()->Get("VZERO/Calib/Saturation");
101 if (!entry5) AliFatal("Saturation entry is not found in OCDB !");
102 fSaturationCorr = (TObjArray*)entry5->GetObject();
1999c0f1 103
104 AliCDBEntry *entry6 = AliCDBManager::Instance()->Get("VZERO/Trigger/Data");
105 if (!entry6) AliFatal("VZERO trigger config data is not found in OCDB !");
106 fTriggerData = (AliVZEROTriggerData*)entry6->GetObject();
ce7090f5 107}
108
109
110//_____________________________________________________________________________
111AliVZEROReconstructor& AliVZEROReconstructor::operator =
112 (const AliVZEROReconstructor& /*reconstructor*/)
113{
114// assignment operator
115
116 Fatal("operator =", "assignment operator not implemented");
117 return *this;
118}
119
120//_____________________________________________________________________________
121AliVZEROReconstructor::~AliVZEROReconstructor()
122{
123// destructor
44b6212f 124
829852e8 125 if(fESDVZERO)
126 delete fESDVZERO;
127 if(fESDVZEROfriend)
b090e6a3 128 delete fESDVZEROfriend;
829852e8 129 if(fDigitsArray)
dbf24214 130 delete fDigitsArray;
35b120ff 131}
132
133//_____________________________________________________________________________
d76c31f4 134void AliVZEROReconstructor::Init()
35b120ff 135{
ef314913 136// initializer
ce7090f5 137
35b120ff 138 fESDVZERO = new AliESDVZERO;
b090e6a3 139 fESDVZEROfriend = new AliESDVZEROfriend;
fe0adf2a 140
141 GetCollisionMode(); // fCollisionMode =1 for Pb-Pb simulated data
35b120ff 142}
143
144//______________________________________________________________________
2e0ee64a 145void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
35b120ff 146{
75b6bc77 147// converts RAW to digits
ef314913 148
2e0ee64a 149 if (!digitsTree) {
150 AliError("No digits tree!");
151 return;
152 }
35b120ff 153
dbf24214 154 if (!fDigitsArray)
155 fDigitsArray = new TClonesArray("AliVZEROdigit", 64);
156 digitsTree->Branch("VZERODigit", &fDigitsArray);
2e0ee64a 157
b090e6a3 158 fESDVZEROfriend->Reset();
159
2e0ee64a 160 rawReader->Reset();
161 AliVZERORawStream rawStream(rawReader);
75b6bc77 162 if (rawStream.Next()) {
1d51e5e5 163
164 Int_t aBBflagsV0A = 0;
165 Int_t aBBflagsV0C = 0;
166 Int_t aBGflagsV0A = 0;
167 Int_t aBGflagsV0C = 0;
168
169 for(Int_t iChannel=0; iChannel < 64; ++iChannel) {
170 Int_t offlineCh = rawStream.GetOfflineChannel(iChannel);
171 // ADC charge samples
172 Short_t chargeADC[AliVZEROdigit::kNClocks];
173 for(Int_t iClock=0; iClock < AliVZEROdigit::kNClocks; ++iClock) {
174 chargeADC[iClock] = rawStream.GetPedestal(iChannel,iClock);
175 }
176 // Integrator flag
177 Bool_t integrator = rawStream.GetIntegratorFlag(iChannel,AliVZEROdigit::kNClocks/2);
178 // Beam-beam and beam-gas flags
179 if(offlineCh<32) {
180 if (rawStream.GetBBFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBBflagsV0C |= (1 << offlineCh);
181 if (rawStream.GetBGFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBGflagsV0C |= (1 << offlineCh);
182 } else {
183 if (rawStream.GetBBFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBBflagsV0A |= (1 << (offlineCh-32));
184 if (rawStream.GetBGFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBGflagsV0A |= (1 << (offlineCh-32));
185 }
186 // HPTDC data (leading time and width)
187 Int_t board = AliVZEROCalibData::GetBoardNumber(offlineCh);
188 Float_t time = rawStream.GetTime(iChannel)*fCalibData->GetTimeResolution(board);
189 Float_t width = rawStream.GetWidth(iChannel)*fCalibData->GetWidthResolution(board);
190 // Add a digit
191 if(!fCalibData->IsChannelDead(iChannel)){
192 new ((*fDigitsArray)[fDigitsArray->GetEntriesFast()])
b47d88ce 193 AliVZEROdigit(offlineCh, time,
1d51e5e5 194 width,integrator,
195 chargeADC);
196 }
197
198 // Filling the part of esd friend object that is available only for raw data
199 fESDVZEROfriend->SetBBScalers(offlineCh,rawStream.GetBBScalers(iChannel));
200 fESDVZEROfriend->SetBGScalers(offlineCh,rawStream.GetBGScalers(iChannel));
201 for (Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++) {
202 fESDVZEROfriend->SetChargeMB(offlineCh,iBunch,rawStream.GetChargeMB(iChannel,iBunch));
203 fESDVZEROfriend->SetIntMBFlag(offlineCh,iBunch,rawStream.GetIntMBFlag(iChannel,iBunch));
204 fESDVZEROfriend->SetBBMBFlag(offlineCh,iBunch,rawStream.GetBBMBFlag(iChannel,iBunch));
205 fESDVZEROfriend->SetBGMBFlag(offlineCh,iBunch,rawStream.GetBGMBFlag(iChannel,iBunch));
206 }
14f1a074 207 for (Int_t iEv = 0; iEv < AliESDVZEROfriend::kNEvOfInt; iEv++) {
208 fESDVZEROfriend->SetBBFlag(offlineCh,iEv,rawStream.GetBBFlag(iChannel,iEv));
209 fESDVZEROfriend->SetBGFlag(offlineCh,iEv,rawStream.GetBGFlag(iChannel,iEv));
210 }
1d51e5e5 211 }
212
213 // Filling the global part of esd friend object that is available only for raw data
1999c0f1 214 rawStream.FillTriggerBits(fTriggerData);
1d51e5e5 215 fESDVZEROfriend->SetTriggerInputs(rawStream.GetTriggerInputs());
216 fESDVZEROfriend->SetTriggerInputsMask(rawStream.GetTriggerInputsMask());
217
218 for(Int_t iScaler = 0; iScaler < AliESDVZEROfriend::kNScalers; iScaler++)
219 fESDVZEROfriend->SetTriggerScalers(iScaler,rawStream.GetTriggerScalers(iScaler));
220
221 for(Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++)
222 fESDVZEROfriend->SetBunchNumbersMB(iBunch,rawStream.GetBunchNumbersMB(iBunch));
b090e6a3 223
1d51e5e5 224 // Store the BB and BG flags in the digits tree (user info)
225 digitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0A",aBBflagsV0A));
226 digitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0C",aBBflagsV0C));
227 digitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0A",aBGflagsV0A));
228 digitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0C",aBGflagsV0C));
b090e6a3 229
1999c0f1 230 UShort_t chargeA,chargeC;
231 rawStream.CalculateChargeForCentrTriggers(fTriggerData,chargeA,chargeC);
232 digitsTree->GetUserInfo()->Add(new TParameter<int>("ChargeA",(Int_t)chargeA));
233 digitsTree->GetUserInfo()->Add(new TParameter<int>("ChargeC",(Int_t)chargeC));
234 digitsTree->GetUserInfo()->Add(new TParameter<int>("TriggerInputs",(Int_t)rawStream.GetTriggerInputs()));
235
1d51e5e5 236 digitsTree->Fill();
2e0ee64a 237 }
dbf24214 238
239 fDigitsArray->Clear();
1d51e5e5 240}
2e0ee64a 241
242//______________________________________________________________________
243void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
b14e6eb4 244 AliESDEvent* esd) const
2e0ee64a 245{
75b6bc77 246// fills multiplicities to the ESD - pedestal is now subtracted
fe0adf2a 247
2e0ee64a 248 if (!digitsTree) {
fe0adf2a 249 AliError("No digits tree!");
250 return;
2e0ee64a 251 }
a055ee24 252
2e0ee64a 253 TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
dbf24214 254 digitBranch->SetAddress(&fDigitsArray);
35b120ff 255
44b6212f 256 Float_t mult[64];
db0db003 257 Float_t adc[64];
258 Float_t time[64];
259 Float_t width[64];
b6fd9c4a 260 Bool_t aBBflag[64];
261 Bool_t aBGflag[64];
d0502ab2 262
35b120ff 263 for (Int_t i=0; i<64; i++){
db0db003 264 adc[i] = 0.0;
d0502ab2 265 mult[i] = 0.0;
b44c933e 266 time[i] = kInvalidTime;
db0db003 267 width[i] = 0.0;
b6fd9c4a 268 aBBflag[i] = kFALSE;
269 aBGflag[i] = kFALSE;
a055ee24 270 }
35b120ff 271
b6fd9c4a 272 Int_t aBBflagsV0A = 0;
273 Int_t aBBflagsV0C = 0;
274 Int_t aBGflagsV0A = 0;
275 Int_t aBGflagsV0C = 0;
276
277 if (digitsTree->GetUserInfo()->FindObject("BBflagsV0A")) {
278 aBBflagsV0A = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BBflagsV0A"))->GetVal();
279 }
1999c0f1 280 else {
281 if (esd && (esd->GetEventType() == 7))
282 AliWarning("V0A beam-beam flags not found in digits tree UserInfo!");
283 }
b6fd9c4a 284
285 if (digitsTree->GetUserInfo()->FindObject("BBflagsV0C")) {
286 aBBflagsV0C = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BBflagsV0C"))->GetVal();
287 }
1999c0f1 288 else {
289 if (esd && (esd->GetEventType() == 7))
290 AliWarning("V0C beam-beam flags not found in digits tree UserInfo!");
291 }
b6fd9c4a 292
293 if (digitsTree->GetUserInfo()->FindObject("BGflagsV0A")) {
294 aBGflagsV0A = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BGflagsV0A"))->GetVal();
295 }
1999c0f1 296 else {
297 if (esd && (esd->GetEventType() == 7))
298 AliWarning("V0A beam-gas flags not found in digits tree UserInfo!");
299 }
b6fd9c4a 300
301 if (digitsTree->GetUserInfo()->FindObject("BGflagsV0C")) {
302 aBGflagsV0C = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BGflagsV0C"))->GetVal();
303 }
1999c0f1 304 else {
305 if (esd && (esd->GetEventType() == 7))
306 AliWarning("V0C beam-gas flags not found in digits tree UserInfo!");
307 }
308
1d51e5e5 309 // Beam-beam and beam-gas flags (hardware)
310 for (Int_t iChannel = 0; iChannel < 64; ++iChannel) {
311 if(iChannel < 32) {
312 aBBflag[iChannel] = (aBBflagsV0C >> iChannel) & 0x1;
313 aBGflag[iChannel] = (aBGflagsV0C >> iChannel) & 0x1;
314 }
315 else {
316 aBBflag[iChannel] = (aBBflagsV0A >> (iChannel-32)) & 0x1;
317 aBGflag[iChannel] = (aBGflagsV0A >> (iChannel-32)) & 0x1;
318 }
319 }
b6fd9c4a 320
1999c0f1 321 // Fill the trigger charges and bits
322 UShort_t chargeA = 0;
323 UShort_t chargeC = 0;
324 UShort_t triggerInputs = 0;
325 if (digitsTree->GetUserInfo()->FindObject("ChargeA")) {
326 chargeA = (UShort_t)(((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("ChargeA"))->GetVal());
327 }
328 else {
329 if (esd && (esd->GetEventType() == 7))
330 AliWarning("V0A trigger charge not found in digits tree UserInfo!");
331 }
332
333 if (digitsTree->GetUserInfo()->FindObject("ChargeC")) {
334 chargeC = (UShort_t)(((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("ChargeC"))->GetVal());
335 }
336 else {
337 if (esd && (esd->GetEventType() == 7))
338 AliWarning("V0C trigger charge not found in digits tree UserInfo!");
339 }
340
341 if (digitsTree->GetUserInfo()->FindObject("TriggerInputs")) {
342 triggerInputs = (UShort_t)(((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("TriggerInputs"))->GetVal());
343 }
344 else {
345 if (esd && (esd->GetEventType() == 7))
346 AliWarning("V0C trigger charge not found in digits tree UserInfo!");
347 }
348
2e0ee64a 349 Int_t nEntries = (Int_t)digitsTree->GetEntries();
35b120ff 350 for (Int_t e=0; e<nEntries; e++) {
2e0ee64a 351 digitsTree->GetEvent(e);
35b120ff 352
dbf24214 353 Int_t nDigits = fDigitsArray->GetEntriesFast();
35b120ff 354
355 for (Int_t d=0; d<nDigits; d++) {
dbf24214 356 AliVZEROdigit* digit = (AliVZEROdigit*) fDigitsArray->At(d);
1d51e5e5 357 Int_t pmNumber = digit->PMNumber();
358
359 // Pedestal retrieval and suppression
360 Bool_t integrator = digit->Integrator();
361 Float_t maxadc = 0;
362 Int_t imax = -1;
363 Float_t adcPedSub[AliVZEROdigit::kNClocks];
364 for(Int_t iClock=0; iClock < AliVZEROdigit::kNClocks; ++iClock) {
365 Short_t charge = digit->ChargeADC(iClock);
366 Bool_t iIntegrator = (iClock%2 == 0) ? integrator : !integrator;
367 Int_t k = pmNumber + 64*iIntegrator;
368 adcPedSub[iClock] = (Float_t)charge - fCalibData->GetPedestal(k);
369 if(adcPedSub[iClock] <= GetRecoParam()->GetNSigmaPed()*fCalibData->GetSigma(k)) {
370 adcPedSub[iClock] = 0;
371 continue;
372 }
373 if(iClock < GetRecoParam()->GetStartClock() || iClock > GetRecoParam()->GetEndClock()) continue;
374 if(adcPedSub[iClock] > maxadc) {
375 maxadc = adcPedSub[iClock];
376 imax = iClock;
377 }
b6fd9c4a 378 }
1d51e5e5 379
380 if (imax != -1) {
381 Int_t start = imax - GetRecoParam()->GetNPreClocks();
382 if (start < 0) start = 0;
383 Int_t end = imax + GetRecoParam()->GetNPostClocks();
384 if (end > 20) end = 20;
385 for(Int_t iClock = start; iClock <= end; iClock++) {
386 adc[pmNumber] += adcPedSub[iClock];
387 }
b6fd9c4a 388 }
389
1d51e5e5 390 // HPTDC leading time and width
391 // Correction for slewing and various time delays
392 time[pmNumber] = CorrectLeadingTime(pmNumber,digit->Time(),adc[pmNumber]);
393 width[pmNumber] = digit->Width();
394
829852e8 395 if (adc[pmNumber] > 0) {
396 AliDebug(1,Form("PM = %d ADC = %f TDC %f (%f) Int %d (%d %d %d %d %d) %f %f %f %f %d %d",pmNumber, adc[pmNumber],
397 digit->Time(),time[pmNumber],
398 integrator,
399 digit->ChargeADC(8),digit->ChargeADC(9),digit->ChargeADC(10),
400 digit->ChargeADC(11),digit->ChargeADC(12),
401 fCalibData->GetPedestal(pmNumber),fCalibData->GetSigma(pmNumber),
402 fCalibData->GetPedestal(pmNumber+64),fCalibData->GetSigma(pmNumber+64),
403 aBBflag[pmNumber],aBGflag[pmNumber]));
404 };
75b6bc77 405
53ad561b 406 TF1 *saturationFunc = (TF1*)fSaturationCorr->UncheckedAt(pmNumber);
407 if (!saturationFunc) AliFatal(Form("Saturation correction for channel %d is not found!",pmNumber));
408 AliDebug(1,Form("Saturation PM=%d %f %f",pmNumber,adc[pmNumber],saturationFunc->Eval(adc[pmNumber])));
409 mult[pmNumber] = saturationFunc->Eval(adc[pmNumber])*fCalibData->GetMIPperADC(pmNumber);
1d51e5e5 410
411 // Fill ESD friend object
412 for (Int_t iEv = 0; iEv < AliESDVZEROfriend::kNEvOfInt; iEv++) {
413 fESDVZEROfriend->SetPedestal(pmNumber,iEv,(Float_t)digit->ChargeADC(iEv));
414 fESDVZEROfriend->SetIntegratorFlag(pmNumber,iEv,(iEv%2 == 0) ? integrator : !integrator);
1d51e5e5 415 }
416 fESDVZEROfriend->SetTime(pmNumber,digit->Time());
417 fESDVZEROfriend->SetWidth(pmNumber,digit->Width());
418
35b120ff 419 } // end of loop over digits
35b120ff 420 } // end of loop over events in digits tree
6c6d6114 421
b44c933e 422 fESDVZERO->SetBit(AliESDVZERO::kCorrectedLeadingTime,kTRUE);
6c6d6114 423 fESDVZERO->SetMultiplicity(mult);
28fdf12c 424 fESDVZERO->SetADC(adc);
425 fESDVZERO->SetTime(time);
d0502ab2 426 fESDVZERO->SetWidth(width);
89a39339 427 fESDVZERO->SetBit(AliESDVZERO::kOnlineBitsFilled,kTRUE);
b6fd9c4a 428 fESDVZERO->SetBBFlag(aBBflag);
429 fESDVZERO->SetBGFlag(aBGflag);
6a5802c8 430 fESDVZERO->SetBit(AliESDVZERO::kCorrectedForSaturation,kTRUE);
a055ee24 431
b44c933e 432 // now fill the V0 decision and channel flags
433 {
434 AliVZEROTriggerMask triggerMask;
7bf5b178 435 triggerMask.SetRecoParam(GetRecoParam());
b44c933e 436 triggerMask.FillMasks(fESDVZERO, fCalibData, fTimeSlewing);
437 }
a055ee24 438
2e0ee64a 439 if (esd) {
44b6212f 440 AliDebug(1, Form("Writing VZERO data to ESD tree"));
441 esd->SetVZEROData(fESDVZERO);
2e0ee64a 442 }
b090e6a3 443
444 if (esd) {
fe0adf2a 445 AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
446 if (fr) {
447 AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
448 fr->SetVZEROfriend(fESDVZEROfriend);
b090e6a3 449 }
450 }
dbf24214 451
452 fDigitsArray->Clear();
35b120ff 453}
454
ce7090f5 455//_____________________________________________________________________________
456AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
457{
ef314913 458// Sets the storage
459
ce7090f5 460 Bool_t deleteManager = kFALSE;
461
462 AliCDBManager *manager = AliCDBManager::Instance();
463 AliCDBStorage *defstorage = manager->GetDefaultStorage();
464
465 if(!defstorage || !(defstorage->Contains("VZERO"))){
466 AliWarning("No default storage set or default storage doesn't contain VZERO!");
467 manager->SetDefaultStorage(uri);
468 deleteManager = kTRUE;
469 }
470
471 AliCDBStorage *storage = manager->GetDefaultStorage();
472
473 if(deleteManager){
44b6212f 474 AliCDBManager::Instance()->UnsetDefaultStorage();
475 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
ce7090f5 476 }
477
478 return storage;
479}
480
fe0adf2a 481//____________________________________________________________________________
482void AliVZEROReconstructor::GetCollisionMode()
483{
75b6bc77 484 // Retrieval of collision mode
fe0adf2a 485
75b6bc77 486 TString beamType = GetRunInfo()->GetBeamType();
fe0adf2a 487 if(beamType==AliGRPObject::GetInvalidString()){
75b6bc77 488 AliError("VZERO cannot retrieve beam type");
fe0adf2a 489 return;
490 }
491
75b6bc77 492 if( (beamType.CompareTo("P-P") ==0) || (beamType.CompareTo("p-p") ==0) ){
493 fCollisionMode=0;
494 }
495 else if( (beamType.CompareTo("Pb-Pb") ==0) || (beamType.CompareTo("A-A") ==0) ){
496 fCollisionMode=1;
fe0adf2a 497 }
fe0adf2a 498
75b6bc77 499 fBeamEnergy = GetRunInfo()->GetBeamEnergy();
fe0adf2a 500 if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
75b6bc77 501 AliError("Missing value for the beam energy ! Using 0");
fe0adf2a 502 fBeamEnergy = 0.;
503 }
504
75b6bc77 505 AliDebug(1,Form("\n ++++++ Beam type and collision mode retrieved as %s %d @ %1.3f GeV ++++++\n\n",beamType.Data(), fCollisionMode, fBeamEnergy));
fe0adf2a 506
507}
508
ce7090f5 509//_____________________________________________________________________________
510AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
511{
ef314913 512 // Gets calibration object for VZERO set
ce7090f5 513
c0b82b5a 514 AliCDBManager *man = AliCDBManager::Instance();
ce7090f5 515
c0b82b5a 516 AliCDBEntry *entry=0;
517
518 entry = man->Get("VZERO/Calib/Data");
519
c0b82b5a 520 AliVZEROCalibData *calibdata = 0;
521
522 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
94a600a1 523 if (!calibdata) AliFatal("No calibration data from calibration database !");
ce7090f5 524
525 return calibdata;
526}
44b6212f 527
b44c933e 528Float_t AliVZEROReconstructor::CorrectLeadingTime(Int_t i, Float_t time, Float_t adc) const
529{
530 // Correct the leading time
531 // for slewing effect and
532 // misalignment of the channels
533 if (time < 1e-6) return kInvalidTime;
534
535 // Channel alignment and general offset subtraction
536 if (i < 32) time -= kV0CDelayCables;
537 time -= fTimeOffset[i];
538
539 // In case of pathological signals
540 if (adc < 1e-6) return time;
541
542 // Slewing correction
ed1ea59f 543 Float_t thr = fCalibData->GetCalibDiscriThr(i,kTRUE);
b44c933e 544 time -= fTimeSlewing->Eval(adc/thr);
545
546 return time;
547}