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 *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();
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();
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)+
83 delays->GetBinContent(i+1)+
89 //_____________________________________________________________________________
90 AliVZEROReconstructor& AliVZEROReconstructor::operator =
91 (const AliVZEROReconstructor& /*reconstructor*/)
93 // assignment operator
95 Fatal("operator =", "assignment operator not implemented");
99 //_____________________________________________________________________________
100 AliVZEROReconstructor::~AliVZEROReconstructor()
105 delete fESDVZEROfriend;
109 //_____________________________________________________________________________
110 void AliVZEROReconstructor::Init()
114 fESDVZERO = new AliESDVZERO;
115 fESDVZEROfriend = new AliESDVZEROfriend;
117 GetCollisionMode(); // fCollisionMode =1 for Pb-Pb simulated data
120 //______________________________________________________________________
121 void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
123 // converts RAW to digits
126 AliError("No digits tree!");
131 fDigitsArray = new TClonesArray("AliVZEROdigit", 64);
132 digitsTree->Branch("VZERODigit", &fDigitsArray);
134 fESDVZEROfriend->Reset();
137 AliVZERORawStream rawStream(rawReader);
138 if (rawStream.Next()) {
140 Float_t time[64], width[64];
141 Bool_t BBFlag[64], BGFlag[64], integrator[64];
142 Short_t chargeADC[64][21];
143 for(Int_t i=0; i<64; i++) {
144 Int_t j = rawStream.GetOfflineChannel(i);
150 integrator[j] = kFALSE;
151 // Search for the maximum charge in the train of 21 LHC clocks
152 // regardless of the integrator which has been operated:
155 Float_t adcPedSub[21];
156 for(Int_t iClock=0; iClock<21; iClock++){
157 chargeADC[j][iClock] = (Short_t)rawStream.GetPedestal(i,iClock);
158 Bool_t iIntegrator = rawStream.GetIntegratorFlag(i,iClock);
159 Int_t k = j+64*iIntegrator;
160 adcPedSub[iClock] = rawStream.GetPedestal(i,iClock) - fCalibData->GetPedestal(k);
161 if(adcPedSub[iClock] <= GetRecoParam()->GetNSigmaPed()*fCalibData->GetSigma(k)) {
162 adcPedSub[iClock] = 0;
165 if(iClock < GetRecoParam()->GetStartClock() || iClock > GetRecoParam()->GetEndClock()) continue;
166 if(adcPedSub[iClock] > maxadc) {
167 maxadc = adcPedSub[iClock];
172 AliDebug(2,Form("Channel %d (online), %d (offline)",i,j));
174 Int_t start = imax - GetRecoParam()->GetNPreClocks();
175 if (start < 0) start = 0;
176 Int_t end = imax + GetRecoParam()->GetNPostClocks();
177 if (end > 20) end = 20;
178 for(Int_t iClock = start; iClock <= end; iClock++) {
179 if (iClock >= imax) {
180 BBFlag[j] |= rawStream.GetBBFlag(i,iClock);
181 BGFlag[j] |= rawStream.GetBGFlag(i,iClock);
184 adc[j] += rawStream.GetPedestal(i,iClock);
186 adc[j] += adcPedSub[iClock];
188 AliDebug(2,Form("clock = %d adc = %f",iClock,rawStream.GetPedestal(i,iClock)));
190 // Convert i (FEE channel numbering) to j (aliroot channel numbering)
192 integrator[j] = rawStream.GetIntegratorFlag(i,imax);
196 time[j] = rawStream.GetTime(i)/ (25./256.) * fCalibData->GetTimeResolution(board);
197 width[j] = rawStream.GetWidth(i) / 0.4 * fCalibData->GetWidthResolution(board);
199 // Filling the esd friend object
200 fESDVZEROfriend->SetBBScalers(j,rawStream.GetBBScalers(i));
201 fESDVZEROfriend->SetBGScalers(j,rawStream.GetBGScalers(i));
202 for (Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++) {
203 fESDVZEROfriend->SetChargeMB(j,iBunch,rawStream.GetChargeMB(i,iBunch));
204 fESDVZEROfriend->SetIntMBFlag(j,iBunch,rawStream.GetIntMBFlag(i,iBunch));
205 fESDVZEROfriend->SetBBMBFlag(j,iBunch,rawStream.GetBBMBFlag(i,iBunch));
206 fESDVZEROfriend->SetBGMBFlag(j,iBunch,rawStream.GetBGMBFlag(i,iBunch));
208 for (Int_t iEv = 0; iEv < AliESDVZEROfriend::kNEvOfInt; iEv++) {
209 fESDVZEROfriend->SetPedestal(j,iEv,rawStream.GetPedestal(i,iEv));
210 fESDVZEROfriend->SetIntegratorFlag(j,iEv,rawStream.GetIntegratorFlag(i,iEv));
211 fESDVZEROfriend->SetBBFlag(j,iEv,rawStream.GetBBFlag(i,iEv));
212 fESDVZEROfriend->SetBGFlag(j,iEv,rawStream.GetBGFlag(i,iEv));
214 fESDVZEROfriend->SetTime(j,time[j]);
215 fESDVZEROfriend->SetWidth(j,width[j]);
218 // Filling the esd friend object
219 fESDVZEROfriend->SetTriggerInputs(rawStream.GetTriggerInputs());
220 fESDVZEROfriend->SetTriggerInputsMask(rawStream.GetTriggerInputsMask());
222 for(Int_t iScaler = 0; iScaler < AliESDVZEROfriend::kNScalers; iScaler++)
223 fESDVZEROfriend->SetTriggerScalers(iScaler,rawStream.GetTriggerScalers(iScaler));
225 for(Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++)
226 fESDVZEROfriend->SetBunchNumbersMB(iBunch,rawStream.GetBunchNumbersMB(iBunch));
229 Int_t aBBflagsV0A = 0;
230 Int_t aBBflagsV0C = 0;
231 Int_t aBGflagsV0A = 0;
232 Int_t aBGflagsV0C = 0;
234 // Channels(aliroot numbering) will be ordered in the tree
235 for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
237 if (BBFlag[iChannel]) aBBflagsV0C |= (1 << iChannel);
238 if (BGFlag[iChannel]) aBGflagsV0C |= (1 << iChannel);
240 if (BBFlag[iChannel]) aBBflagsV0A |= (1 << (iChannel-32));
241 if (BGFlag[iChannel]) aBGflagsV0A |= (1 << (iChannel-32));
243 if(fCalibData->IsChannelDead(iChannel)){
244 adc[iChannel] = (Float_t) kInvalidADC;
245 time[iChannel] = (Float_t) kInvalidTime;
247 if (adc[iChannel] > 0)
248 new ((*fDigitsArray)[fDigitsArray->GetEntriesFast()])
249 AliVZEROdigit(iChannel, adc[iChannel], time[iChannel],
250 width[iChannel],integrator[iChannel],
251 chargeADC[iChannel]);
255 // Store the BB and BG flags in the digits tree (user info)
256 digitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0A",aBBflagsV0A));
257 digitsTree->GetUserInfo()->Add(new TParameter<int>("BBflagsV0C",aBBflagsV0C));
258 digitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0A",aBGflagsV0A));
259 digitsTree->GetUserInfo()->Add(new TParameter<int>("BGflagsV0C",aBGflagsV0C));
264 fDigitsArray->Clear();
267 //______________________________________________________________________
268 void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
269 AliESDEvent* esd) const
271 // fills multiplicities to the ESD - pedestal is now subtracted
274 AliError("No digits tree!");
278 TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
279 digitBranch->SetAddress(&fDigitsArray);
288 for (Int_t i=0; i<64; i++){
291 time[i] = kInvalidTime;
297 Int_t aBBflagsV0A = 0;
298 Int_t aBBflagsV0C = 0;
299 Int_t aBGflagsV0A = 0;
300 Int_t aBGflagsV0C = 0;
302 if (digitsTree->GetUserInfo()->FindObject("BBflagsV0A")) {
303 aBBflagsV0A = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BBflagsV0A"))->GetVal();
306 AliWarning("V0A beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
308 if (digitsTree->GetUserInfo()->FindObject("BBflagsV0C")) {
309 aBBflagsV0C = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BBflagsV0C"))->GetVal();
312 AliWarning("V0C beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
314 if (digitsTree->GetUserInfo()->FindObject("BGflagsV0A")) {
315 aBGflagsV0A = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BGflagsV0A"))->GetVal();
318 AliWarning("V0A beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
320 if (digitsTree->GetUserInfo()->FindObject("BGflagsV0C")) {
321 aBGflagsV0C = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BGflagsV0C"))->GetVal();
324 AliWarning("V0C beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
327 Int_t nEntries = (Int_t)digitsTree->GetEntries();
328 for (Int_t e=0; e<nEntries; e++) {
329 digitsTree->GetEvent(e);
331 Int_t nDigits = fDigitsArray->GetEntriesFast();
333 for (Int_t d=0; d<nDigits; d++) {
334 AliVZEROdigit* digit = (AliVZEROdigit*) fDigitsArray->At(d);
335 Int_t pmNumber = digit->PMNumber();
336 // Pedestal retrieval and suppression:
337 Bool_t integrator = digit->Integrator();
338 Int_t k = pmNumber+64*integrator;
339 Float_t pedestal = fCalibData->GetPedestal(k);
340 adc[pmNumber] = digit->ADC() - pedestal;
341 time[pmNumber] = CorrectLeadingTime(pmNumber,digit->Time(),adc[pmNumber]);
342 width[pmNumber] = digit->Width();
344 aBBflag[pmNumber] = (aBBflagsV0C >> pmNumber) & 0x1;
345 aBGflag[pmNumber] = (aBGflagsV0C >> pmNumber) & 0x1;
348 aBBflag[pmNumber] = (aBBflagsV0A >> (pmNumber-32)) & 0x1;
349 aBGflag[pmNumber] = (aBGflagsV0A >> (pmNumber-32)) & 0x1;
352 if (adc[pmNumber] > 0) AliDebug(1,Form("PM = %d ADC = %f TDC %f Int %d (%d %d %d %d %d) %f %f %f %f %d %d",pmNumber, adc[pmNumber],digit->Time(),
354 digit->ChargeADC(8),digit->ChargeADC(9),digit->ChargeADC(10),
355 digit->ChargeADC(11),digit->ChargeADC(12),
356 fCalibData->GetPedestal(pmNumber),fCalibData->GetSigma(pmNumber),
357 fCalibData->GetPedestal(pmNumber+64),fCalibData->GetSigma(pmNumber+64),
358 aBBflag[pmNumber],aBGflag[pmNumber]));
360 if(adc[pmNumber] > (fCalibData->GetPedestal(k) + GetRecoParam()->GetNSigmaPed()*fCalibData->GetSigma(k))) {
361 mult[pmNumber] += adc[pmNumber]*fCalibData->GetMIPperADC(pmNumber);
363 } // end of loop over digits
364 } // end of loop over events in digits tree
366 fESDVZERO->SetBit(AliESDVZERO::kCorrectedLeadingTime,kTRUE);
367 fESDVZERO->SetMultiplicity(mult);
368 fESDVZERO->SetADC(adc);
369 fESDVZERO->SetTime(time);
370 fESDVZERO->SetWidth(width);
371 fESDVZERO->SetBBFlag(aBBflag);
372 fESDVZERO->SetBGFlag(aBGflag);
374 // now fill the V0 decision and channel flags
376 AliVZEROTriggerMask triggerMask;
377 triggerMask.FillMasks(fESDVZERO, fCalibData, fTimeSlewing);
381 AliDebug(1, Form("Writing VZERO data to ESD tree"));
382 esd->SetVZEROData(fESDVZERO);
386 AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
388 AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
389 fr->SetVZEROfriend(fESDVZEROfriend);
393 fDigitsArray->Clear();
396 //_____________________________________________________________________________
397 AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
401 Bool_t deleteManager = kFALSE;
403 AliCDBManager *manager = AliCDBManager::Instance();
404 AliCDBStorage *defstorage = manager->GetDefaultStorage();
406 if(!defstorage || !(defstorage->Contains("VZERO"))){
407 AliWarning("No default storage set or default storage doesn't contain VZERO!");
408 manager->SetDefaultStorage(uri);
409 deleteManager = kTRUE;
412 AliCDBStorage *storage = manager->GetDefaultStorage();
415 AliCDBManager::Instance()->UnsetDefaultStorage();
416 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
422 //____________________________________________________________________________
423 void AliVZEROReconstructor::GetCollisionMode()
425 // Retrieval of collision mode
427 TString beamType = GetRunInfo()->GetBeamType();
428 if(beamType==AliGRPObject::GetInvalidString()){
429 AliError("VZERO cannot retrieve beam type");
433 if( (beamType.CompareTo("P-P") ==0) || (beamType.CompareTo("p-p") ==0) ){
436 else if( (beamType.CompareTo("Pb-Pb") ==0) || (beamType.CompareTo("A-A") ==0) ){
440 fBeamEnergy = GetRunInfo()->GetBeamEnergy();
441 if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
442 AliError("Missing value for the beam energy ! Using 0");
446 AliDebug(1,Form("\n ++++++ Beam type and collision mode retrieved as %s %d @ %1.3f GeV ++++++\n\n",beamType.Data(), fCollisionMode, fBeamEnergy));
450 //_____________________________________________________________________________
451 AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
453 // Gets calibration object for VZERO set
455 AliCDBManager *man = AliCDBManager::Instance();
457 AliCDBEntry *entry=0;
459 entry = man->Get("VZERO/Calib/Data");
461 AliVZEROCalibData *calibdata = 0;
463 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
464 if (!calibdata) AliFatal("No calibration data from calibration database !");
469 Float_t AliVZEROReconstructor::CorrectLeadingTime(Int_t i, Float_t time, Float_t adc) const
471 // Correct the leading time
472 // for slewing effect and
473 // misalignment of the channels
474 if (time < 1e-6) return kInvalidTime;
476 // Channel alignment and general offset subtraction
477 if (i < 32) time -= kV0CDelayCables;
478 time -= fTimeOffset[i];
480 // In case of pathological signals
481 if (adc < 1e-6) return time;
483 // Slewing correction
484 Float_t thr = fCalibData->GetDiscriThr(i);
485 time -= fTimeSlewing->Eval(adc/thr);