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