Using detector quality flag (taken from ALICE logbook) to decide whether to rpodcue...
[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) {
b6e08e3e 406 AliDebug(1,Form("PM = %d ADC = %.2f (%.2f) TDC %.2f (%.2f) Int %d (%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d) %.2f %.2f %.2f %.2f %d %d",pmNumber, adc[pmNumber],
407 digit->ChargeADC(11)+digit->ChargeADC(10)+digit->ChargeADC(9)+digit->ChargeADC(8)+
408 digit->ChargeADC(7)+digit->ChargeADC(6)+digit->ChargeADC(5)+digit->ChargeADC(4)-
409 4.*fCalibData->GetPedestal(pmNumber)-4.*fCalibData->GetPedestal(pmNumber+64),
829852e8 410 digit->Time(),time[pmNumber],
411 integrator,
b6e08e3e 412 digit->ChargeADC(0),digit->ChargeADC(1),digit->ChargeADC(2),digit->ChargeADC(3),digit->ChargeADC(4),digit->ChargeADC(5),digit->ChargeADC(6),digit->ChargeADC(7),
829852e8 413 digit->ChargeADC(8),digit->ChargeADC(9),digit->ChargeADC(10),
414 digit->ChargeADC(11),digit->ChargeADC(12),
b6e08e3e 415 digit->ChargeADC(13),digit->ChargeADC(14),digit->ChargeADC(15),digit->ChargeADC(16),digit->ChargeADC(17),digit->ChargeADC(18),digit->ChargeADC(19),digit->ChargeADC(20),
829852e8 416 fCalibData->GetPedestal(pmNumber),fCalibData->GetSigma(pmNumber),
417 fCalibData->GetPedestal(pmNumber+64),fCalibData->GetSigma(pmNumber+64),
418 aBBflag[pmNumber],aBGflag[pmNumber]));
419 };
75b6bc77 420
53ad561b 421 TF1 *saturationFunc = (TF1*)fSaturationCorr->UncheckedAt(pmNumber);
422 if (!saturationFunc) AliFatal(Form("Saturation correction for channel %d is not found!",pmNumber));
423 AliDebug(1,Form("Saturation PM=%d %f %f",pmNumber,adc[pmNumber],saturationFunc->Eval(adc[pmNumber])));
424 mult[pmNumber] = saturationFunc->Eval(adc[pmNumber])*fCalibData->GetMIPperADC(pmNumber);
1d51e5e5 425
426 // Fill ESD friend object
427 for (Int_t iEv = 0; iEv < AliESDVZEROfriend::kNEvOfInt; iEv++) {
428 fESDVZEROfriend->SetPedestal(pmNumber,iEv,(Float_t)digit->ChargeADC(iEv));
429 fESDVZEROfriend->SetIntegratorFlag(pmNumber,iEv,(iEv%2 == 0) ? integrator : !integrator);
1d51e5e5 430 }
431 fESDVZEROfriend->SetTime(pmNumber,digit->Time());
432 fESDVZEROfriend->SetWidth(pmNumber,digit->Width());
433
35b120ff 434 } // end of loop over digits
35b120ff 435 } // end of loop over events in digits tree
6c6d6114 436
b44c933e 437 fESDVZERO->SetBit(AliESDVZERO::kCorrectedLeadingTime,kTRUE);
6c6d6114 438 fESDVZERO->SetMultiplicity(mult);
28fdf12c 439 fESDVZERO->SetADC(adc);
440 fESDVZERO->SetTime(time);
d0502ab2 441 fESDVZERO->SetWidth(width);
89a39339 442 fESDVZERO->SetBit(AliESDVZERO::kOnlineBitsFilled,kTRUE);
b6fd9c4a 443 fESDVZERO->SetBBFlag(aBBflag);
444 fESDVZERO->SetBGFlag(aBGflag);
6a5802c8 445 fESDVZERO->SetBit(AliESDVZERO::kCorrectedForSaturation,kTRUE);
a055ee24 446
b44c933e 447 // now fill the V0 decision and channel flags
448 {
449 AliVZEROTriggerMask triggerMask;
7bf5b178 450 triggerMask.SetRecoParam(GetRecoParam());
b44c933e 451 triggerMask.FillMasks(fESDVZERO, fCalibData, fTimeSlewing);
452 }
a055ee24 453
2e0ee64a 454 if (esd) {
44b6212f 455 AliDebug(1, Form("Writing VZERO data to ESD tree"));
456 esd->SetVZEROData(fESDVZERO);
1dc767cf 457 const AliESDRun *esdRun = esd->GetESDRun();
458 if (esdRun) {
459 Float_t factors[64];
460 Float_t factorSum = 0;
461 for(Int_t i = 0; i < 64; ++i) {
462 factors[i] = fEqFactors->GetBinContent(i+1)*fCalibData->GetMIPperADC(i);
463 factorSum += factors[i];
464 }
465 for(Int_t i = 0; i < 64; ++i) factors[i] *= (64./factorSum);
466
467 esd->SetVZEROEqFactors(factors);
468 }
469 else
470 AliError("AliESDRun object is not available! Cannot write the equalization factors!");
2e0ee64a 471 }
b090e6a3 472
473 if (esd) {
fe0adf2a 474 AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
475 if (fr) {
476 AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
477 fr->SetVZEROfriend(fESDVZEROfriend);
b090e6a3 478 }
479 }
dbf24214 480
481 fDigitsArray->Clear();
35b120ff 482}
483
ce7090f5 484//_____________________________________________________________________________
485AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
486{
ef314913 487// Sets the storage
488
ce7090f5 489 Bool_t deleteManager = kFALSE;
490
491 AliCDBManager *manager = AliCDBManager::Instance();
492 AliCDBStorage *defstorage = manager->GetDefaultStorage();
493
494 if(!defstorage || !(defstorage->Contains("VZERO"))){
495 AliWarning("No default storage set or default storage doesn't contain VZERO!");
496 manager->SetDefaultStorage(uri);
497 deleteManager = kTRUE;
498 }
499
500 AliCDBStorage *storage = manager->GetDefaultStorage();
501
502 if(deleteManager){
44b6212f 503 AliCDBManager::Instance()->UnsetDefaultStorage();
504 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
ce7090f5 505 }
506
507 return storage;
508}
509
fe0adf2a 510//____________________________________________________________________________
511void AliVZEROReconstructor::GetCollisionMode()
512{
75b6bc77 513 // Retrieval of collision mode
fe0adf2a 514
75b6bc77 515 TString beamType = GetRunInfo()->GetBeamType();
fe0adf2a 516 if(beamType==AliGRPObject::GetInvalidString()){
75b6bc77 517 AliError("VZERO cannot retrieve beam type");
fe0adf2a 518 return;
519 }
520
75b6bc77 521 if( (beamType.CompareTo("P-P") ==0) || (beamType.CompareTo("p-p") ==0) ){
522 fCollisionMode=0;
523 }
524 else if( (beamType.CompareTo("Pb-Pb") ==0) || (beamType.CompareTo("A-A") ==0) ){
525 fCollisionMode=1;
fe0adf2a 526 }
fe0adf2a 527
75b6bc77 528 fBeamEnergy = GetRunInfo()->GetBeamEnergy();
fe0adf2a 529 if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
75b6bc77 530 AliError("Missing value for the beam energy ! Using 0");
fe0adf2a 531 fBeamEnergy = 0.;
532 }
533
75b6bc77 534 AliDebug(1,Form("\n ++++++ Beam type and collision mode retrieved as %s %d @ %1.3f GeV ++++++\n\n",beamType.Data(), fCollisionMode, fBeamEnergy));
fe0adf2a 535
536}
537
ce7090f5 538//_____________________________________________________________________________
539AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
540{
ef314913 541 // Gets calibration object for VZERO set
ce7090f5 542
c0b82b5a 543 AliCDBManager *man = AliCDBManager::Instance();
ce7090f5 544
c0b82b5a 545 AliCDBEntry *entry=0;
546
547 entry = man->Get("VZERO/Calib/Data");
548
c0b82b5a 549 AliVZEROCalibData *calibdata = 0;
550
551 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
94a600a1 552 if (!calibdata) AliFatal("No calibration data from calibration database !");
ce7090f5 553
554 return calibdata;
555}
44b6212f 556
b44c933e 557Float_t AliVZEROReconstructor::CorrectLeadingTime(Int_t i, Float_t time, Float_t adc) const
558{
559 // Correct the leading time
560 // for slewing effect and
561 // misalignment of the channels
562 if (time < 1e-6) return kInvalidTime;
563
564 // Channel alignment and general offset subtraction
565 if (i < 32) time -= kV0CDelayCables;
566 time -= fTimeOffset[i];
567
568 // In case of pathological signals
569 if (adc < 1e-6) return time;
570
571 // Slewing correction
ed1ea59f 572 Float_t thr = fCalibData->GetCalibDiscriThr(i,kTRUE);
b44c933e 573 time -= fTimeSlewing->Eval(adc/thr);
574
575 return time;
576}