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