1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// class for VZERO reconstruction //
22 ///////////////////////////////////////////////////////////////////////////////
26 #include <TParameter.h>
28 #include "AliRunLoader.h"
29 #include "AliRawReader.h"
30 #include "AliGRPObject.h"
31 #include "AliCDBManager.h"
32 #include "AliCDBStorage.h"
33 #include "AliCDBEntry.h"
34 #include "AliVZEROReconstructor.h"
35 #include "AliVZERORawStream.h"
36 #include "AliVZEROConst.h"
37 #include "AliESDEvent.h"
38 #include "AliVZEROTriggerMask.h"
39 #include "AliESDfriend.h"
40 #include "AliESDVZEROfriend.h"
41 #include "AliVZEROdigit.h"
42 #include "AliVZEROCalibData.h"
43 #include "AliRunInfo.h"
44 #include "AliCTPTimeParams.h"
46 ClassImp(AliVZEROReconstructor)
48 //_____________________________________________________________________________
49 AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
59 // Default constructor
60 // Get calibration data
62 fCalibData = GetCalibData();
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;
69 AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
70 if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
71 AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
72 l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
74 AliCDBEntry *entry2 = AliCDBManager::Instance()->Get("VZERO/Calib/TimeDelays");
75 if (!entry2) AliFatal("VZERO time delays are not found in OCDB !");
76 TH1F *delays = (TH1F*)entry2->GetObject();
78 AliCDBEntry *entry3 = AliCDBManager::Instance()->Get("VZERO/Calib/TimeSlewing");
79 if (!entry3) AliFatal("VZERO time slewing function is not found in OCDB !");
80 fTimeSlewing = (TF1*)entry3->GetObject();
82 for(Int_t i = 0 ; i < 64; ++i) {
83 Int_t board = AliVZEROCalibData::GetBoardNumber(i);
84 fTimeOffset[i] = (((Float_t)fCalibData->GetTriggerCountOffset(board)-
85 (Float_t)fCalibData->GetRollOver(board))*25.0+
86 fCalibData->GetTimeOffset(i)-
88 delays->GetBinContent(i+1)+
94 //_____________________________________________________________________________
95 AliVZEROReconstructor& AliVZEROReconstructor::operator =
96 (const AliVZEROReconstructor& /*reconstructor*/)
98 // assignment operator
100 Fatal("operator =", "assignment operator not implemented");
104 //_____________________________________________________________________________
105 AliVZEROReconstructor::~AliVZEROReconstructor()
110 delete fESDVZEROfriend;
114 //_____________________________________________________________________________
115 void AliVZEROReconstructor::Init()
119 fESDVZERO = new AliESDVZERO;
120 fESDVZEROfriend = new AliESDVZEROfriend;
122 GetCollisionMode(); // fCollisionMode =1 for Pb-Pb simulated data
125 //______________________________________________________________________
126 void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
128 // converts RAW to digits
131 AliError("No digits tree!");
136 fDigitsArray = new TClonesArray("AliVZEROdigit", 64);
137 digitsTree->Branch("VZERODigit", &fDigitsArray);
139 fESDVZEROfriend->Reset();
142 AliVZERORawStream rawStream(rawReader);
143 if (rawStream.Next()) {
145 Int_t aBBflagsV0A = 0;
146 Int_t aBBflagsV0C = 0;
147 Int_t aBGflagsV0A = 0;
148 Int_t aBGflagsV0C = 0;
150 for(Int_t iChannel=0; iChannel < 64; ++iChannel) {
151 Int_t offlineCh = rawStream.GetOfflineChannel(iChannel);
152 // ADC charge samples
153 Short_t chargeADC[AliVZEROdigit::kNClocks];
154 for(Int_t iClock=0; iClock < AliVZEROdigit::kNClocks; ++iClock) {
155 chargeADC[iClock] = rawStream.GetPedestal(iChannel,iClock);
158 Bool_t integrator = rawStream.GetIntegratorFlag(iChannel,AliVZEROdigit::kNClocks/2);
159 // Beam-beam and beam-gas flags
161 if (rawStream.GetBBFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBBflagsV0C |= (1 << offlineCh);
162 if (rawStream.GetBGFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBGflagsV0C |= (1 << offlineCh);
164 if (rawStream.GetBBFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBBflagsV0A |= (1 << (offlineCh-32));
165 if (rawStream.GetBGFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBGflagsV0A |= (1 << (offlineCh-32));
167 // HPTDC data (leading time and width)
168 Int_t board = AliVZEROCalibData::GetBoardNumber(offlineCh);
169 Float_t time = rawStream.GetTime(iChannel)*fCalibData->GetTimeResolution(board);
170 Float_t width = rawStream.GetWidth(iChannel)*fCalibData->GetWidthResolution(board);
172 if(!fCalibData->IsChannelDead(iChannel)){
173 new ((*fDigitsArray)[fDigitsArray->GetEntriesFast()])
174 AliVZEROdigit(offlineCh, time,
179 // Filling the part of esd friend object that is available only for raw data
180 fESDVZEROfriend->SetBBScalers(offlineCh,rawStream.GetBBScalers(iChannel));
181 fESDVZEROfriend->SetBGScalers(offlineCh,rawStream.GetBGScalers(iChannel));
182 for (Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++) {
183 fESDVZEROfriend->SetChargeMB(offlineCh,iBunch,rawStream.GetChargeMB(iChannel,iBunch));
184 fESDVZEROfriend->SetIntMBFlag(offlineCh,iBunch,rawStream.GetIntMBFlag(iChannel,iBunch));
185 fESDVZEROfriend->SetBBMBFlag(offlineCh,iBunch,rawStream.GetBBMBFlag(iChannel,iBunch));
186 fESDVZEROfriend->SetBGMBFlag(offlineCh,iBunch,rawStream.GetBGMBFlag(iChannel,iBunch));
191 // Filling the global part of esd friend object that is available only for raw data
192 fESDVZEROfriend->SetTriggerInputs(rawStream.GetTriggerInputs());
193 fESDVZEROfriend->SetTriggerInputsMask(rawStream.GetTriggerInputsMask());
195 for(Int_t iScaler = 0; iScaler < AliESDVZEROfriend::kNScalers; iScaler++)
196 fESDVZEROfriend->SetTriggerScalers(iScaler,rawStream.GetTriggerScalers(iScaler));
198 for(Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++)
199 fESDVZEROfriend->SetBunchNumbersMB(iBunch,rawStream.GetBunchNumbersMB(iBunch));
201 // Store the BB and BG flags in the digits tree (user info)
202 digitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0A",aBBflagsV0A));
203 digitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0C",aBBflagsV0C));
204 digitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0A",aBGflagsV0A));
205 digitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0C",aBGflagsV0C));
210 fDigitsArray->Clear();
213 //______________________________________________________________________
214 void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
215 AliESDEvent* esd) const
217 // fills multiplicities to the ESD - pedestal is now subtracted
220 AliError("No digits tree!");
224 TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
225 digitBranch->SetAddress(&fDigitsArray);
234 for (Int_t i=0; i<64; i++){
237 time[i] = kInvalidTime;
243 Int_t aBBflagsV0A = 0;
244 Int_t aBBflagsV0C = 0;
245 Int_t aBGflagsV0A = 0;
246 Int_t aBGflagsV0C = 0;
248 if (digitsTree->GetUserInfo()->FindObject("BBflagsV0A")) {
249 aBBflagsV0A = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BBflagsV0A"))->GetVal();
252 AliWarning("V0A beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
254 if (digitsTree->GetUserInfo()->FindObject("BBflagsV0C")) {
255 aBBflagsV0C = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BBflagsV0C"))->GetVal();
258 AliWarning("V0C beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
260 if (digitsTree->GetUserInfo()->FindObject("BGflagsV0A")) {
261 aBGflagsV0A = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BGflagsV0A"))->GetVal();
264 AliWarning("V0A beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
266 if (digitsTree->GetUserInfo()->FindObject("BGflagsV0C")) {
267 aBGflagsV0C = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BGflagsV0C"))->GetVal();
270 AliWarning("V0C beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
272 // Beam-beam and beam-gas flags (hardware)
273 for (Int_t iChannel = 0; iChannel < 64; ++iChannel) {
275 aBBflag[iChannel] = (aBBflagsV0C >> iChannel) & 0x1;
276 aBGflag[iChannel] = (aBGflagsV0C >> iChannel) & 0x1;
279 aBBflag[iChannel] = (aBBflagsV0A >> (iChannel-32)) & 0x1;
280 aBGflag[iChannel] = (aBGflagsV0A >> (iChannel-32)) & 0x1;
284 Int_t nEntries = (Int_t)digitsTree->GetEntries();
285 for (Int_t e=0; e<nEntries; e++) {
286 digitsTree->GetEvent(e);
288 Int_t nDigits = fDigitsArray->GetEntriesFast();
290 for (Int_t d=0; d<nDigits; d++) {
291 AliVZEROdigit* digit = (AliVZEROdigit*) fDigitsArray->At(d);
292 Int_t pmNumber = digit->PMNumber();
294 // Pedestal retrieval and suppression
295 Bool_t integrator = digit->Integrator();
298 Float_t adcPedSub[AliVZEROdigit::kNClocks];
299 for(Int_t iClock=0; iClock < AliVZEROdigit::kNClocks; ++iClock) {
300 Short_t charge = digit->ChargeADC(iClock);
301 Bool_t iIntegrator = (iClock%2 == 0) ? integrator : !integrator;
302 Int_t k = pmNumber + 64*iIntegrator;
303 adcPedSub[iClock] = (Float_t)charge - fCalibData->GetPedestal(k);
304 if(adcPedSub[iClock] <= GetRecoParam()->GetNSigmaPed()*fCalibData->GetSigma(k)) {
305 adcPedSub[iClock] = 0;
308 if(iClock < GetRecoParam()->GetStartClock() || iClock > GetRecoParam()->GetEndClock()) continue;
309 if(adcPedSub[iClock] > maxadc) {
310 maxadc = adcPedSub[iClock];
316 Int_t start = imax - GetRecoParam()->GetNPreClocks();
317 if (start < 0) start = 0;
318 Int_t end = imax + GetRecoParam()->GetNPostClocks();
319 if (end > 20) end = 20;
320 for(Int_t iClock = start; iClock <= end; iClock++) {
321 adc[pmNumber] += adcPedSub[iClock];
325 // HPTDC leading time and width
326 // Correction for slewing and various time delays
327 time[pmNumber] = CorrectLeadingTime(pmNumber,digit->Time(),adc[pmNumber]);
328 width[pmNumber] = digit->Width();
330 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],
331 digit->Time(),time[pmNumber],
333 digit->ChargeADC(8),digit->ChargeADC(9),digit->ChargeADC(10),
334 digit->ChargeADC(11),digit->ChargeADC(12),
335 fCalibData->GetPedestal(pmNumber),fCalibData->GetSigma(pmNumber),
336 fCalibData->GetPedestal(pmNumber+64),fCalibData->GetSigma(pmNumber+64),
337 aBBflag[pmNumber],aBGflag[pmNumber]));
339 mult[pmNumber] = adc[pmNumber]*fCalibData->GetMIPperADC(pmNumber);
341 // Fill ESD friend object
342 for (Int_t iEv = 0; iEv < AliESDVZEROfriend::kNEvOfInt; iEv++) {
343 fESDVZEROfriend->SetPedestal(pmNumber,iEv,(Float_t)digit->ChargeADC(iEv));
344 fESDVZEROfriend->SetIntegratorFlag(pmNumber,iEv,(iEv%2 == 0) ? integrator : !integrator);
345 fESDVZEROfriend->SetBBFlag(pmNumber,iEv,aBBflag[pmNumber]);
346 fESDVZEROfriend->SetBGFlag(pmNumber,iEv,aBGflag[pmNumber]);
348 fESDVZEROfriend->SetTime(pmNumber,digit->Time());
349 fESDVZEROfriend->SetWidth(pmNumber,digit->Width());
351 } // end of loop over digits
352 } // end of loop over events in digits tree
354 fESDVZERO->SetBit(AliESDVZERO::kCorrectedLeadingTime,kTRUE);
355 fESDVZERO->SetMultiplicity(mult);
356 fESDVZERO->SetADC(adc);
357 fESDVZERO->SetTime(time);
358 fESDVZERO->SetWidth(width);
359 fESDVZERO->SetBit(AliESDVZERO::kOnlineBitsFilled,kTRUE);
360 fESDVZERO->SetBBFlag(aBBflag);
361 fESDVZERO->SetBGFlag(aBGflag);
363 // now fill the V0 decision and channel flags
365 AliVZEROTriggerMask triggerMask;
366 triggerMask.FillMasks(fESDVZERO, fCalibData, fTimeSlewing);
370 AliDebug(1, Form("Writing VZERO data to ESD tree"));
371 esd->SetVZEROData(fESDVZERO);
375 AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
377 AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
378 fr->SetVZEROfriend(fESDVZEROfriend);
382 fDigitsArray->Clear();
385 //_____________________________________________________________________________
386 AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
390 Bool_t deleteManager = kFALSE;
392 AliCDBManager *manager = AliCDBManager::Instance();
393 AliCDBStorage *defstorage = manager->GetDefaultStorage();
395 if(!defstorage || !(defstorage->Contains("VZERO"))){
396 AliWarning("No default storage set or default storage doesn't contain VZERO!");
397 manager->SetDefaultStorage(uri);
398 deleteManager = kTRUE;
401 AliCDBStorage *storage = manager->GetDefaultStorage();
404 AliCDBManager::Instance()->UnsetDefaultStorage();
405 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
411 //____________________________________________________________________________
412 void AliVZEROReconstructor::GetCollisionMode()
414 // Retrieval of collision mode
416 TString beamType = GetRunInfo()->GetBeamType();
417 if(beamType==AliGRPObject::GetInvalidString()){
418 AliError("VZERO cannot retrieve beam type");
422 if( (beamType.CompareTo("P-P") ==0) || (beamType.CompareTo("p-p") ==0) ){
425 else if( (beamType.CompareTo("Pb-Pb") ==0) || (beamType.CompareTo("A-A") ==0) ){
429 fBeamEnergy = GetRunInfo()->GetBeamEnergy();
430 if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
431 AliError("Missing value for the beam energy ! Using 0");
435 AliDebug(1,Form("\n ++++++ Beam type and collision mode retrieved as %s %d @ %1.3f GeV ++++++\n\n",beamType.Data(), fCollisionMode, fBeamEnergy));
439 //_____________________________________________________________________________
440 AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
442 // Gets calibration object for VZERO set
444 AliCDBManager *man = AliCDBManager::Instance();
446 AliCDBEntry *entry=0;
448 entry = man->Get("VZERO/Calib/Data");
450 AliVZEROCalibData *calibdata = 0;
452 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
453 if (!calibdata) AliFatal("No calibration data from calibration database !");
458 Float_t AliVZEROReconstructor::CorrectLeadingTime(Int_t i, Float_t time, Float_t adc) const
460 // Correct the leading time
461 // for slewing effect and
462 // misalignment of the channels
463 if (time < 1e-6) return kInvalidTime;
465 // Channel alignment and general offset subtraction
466 if (i < 32) time -= kV0CDelayCables;
467 time -= fTimeOffset[i];
469 // In case of pathological signals
470 if (adc < 1e-6) return time;
472 // Slewing correction
473 Float_t thr = fCalibData->GetDiscriThr(i);
474 time -= fTimeSlewing->Eval(adc/thr);