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 Int_t aBBflagsV0A = 0;
141 Int_t aBBflagsV0C = 0;
142 Int_t aBGflagsV0A = 0;
143 Int_t aBGflagsV0C = 0;
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);
153 Bool_t integrator = rawStream.GetIntegratorFlag(iChannel,AliVZEROdigit::kNClocks/2);
154 // Beam-beam and beam-gas flags
156 if (rawStream.GetBBFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBBflagsV0C |= (1 << offlineCh);
157 if (rawStream.GetBGFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBGflagsV0C |= (1 << offlineCh);
159 if (rawStream.GetBBFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBBflagsV0A |= (1 << (offlineCh-32));
160 if (rawStream.GetBGFlag(iChannel,AliVZEROdigit::kNClocks/2)) aBGflagsV0A |= (1 << (offlineCh-32));
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);
167 if(!fCalibData->IsChannelDead(iChannel)){
168 new ((*fDigitsArray)[fDigitsArray->GetEntriesFast()])
169 AliVZEROdigit(offlineCh, time,
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));
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());
190 for(Int_t iScaler = 0; iScaler < AliESDVZEROfriend::kNScalers; iScaler++)
191 fESDVZEROfriend->SetTriggerScalers(iScaler,rawStream.GetTriggerScalers(iScaler));
193 for(Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++)
194 fESDVZEROfriend->SetBunchNumbersMB(iBunch,rawStream.GetBunchNumbersMB(iBunch));
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));
205 fDigitsArray->Clear();
208 //______________________________________________________________________
209 void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
210 AliESDEvent* esd) const
212 // fills multiplicities to the ESD - pedestal is now subtracted
215 AliError("No digits tree!");
219 TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
220 digitBranch->SetAddress(&fDigitsArray);
229 for (Int_t i=0; i<64; i++){
232 time[i] = kInvalidTime;
238 Int_t aBBflagsV0A = 0;
239 Int_t aBBflagsV0C = 0;
240 Int_t aBGflagsV0A = 0;
241 Int_t aBGflagsV0C = 0;
243 if (digitsTree->GetUserInfo()->FindObject("BBflagsV0A")) {
244 aBBflagsV0A = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BBflagsV0A"))->GetVal();
247 AliWarning("V0A beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
249 if (digitsTree->GetUserInfo()->FindObject("BBflagsV0C")) {
250 aBBflagsV0C = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BBflagsV0C"))->GetVal();
253 AliWarning("V0C beam-beam flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
255 if (digitsTree->GetUserInfo()->FindObject("BGflagsV0A")) {
256 aBGflagsV0A = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BGflagsV0A"))->GetVal();
259 AliWarning("V0A beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
261 if (digitsTree->GetUserInfo()->FindObject("BGflagsV0C")) {
262 aBGflagsV0C = ((TParameter<int>*)digitsTree->GetUserInfo()->FindObject("BGflagsV0C"))->GetVal();
265 AliWarning("V0C beam-gas flags not found in digits tree UserInfo! The flags will not be written to the raw-data stream!");
267 // Beam-beam and beam-gas flags (hardware)
268 for (Int_t iChannel = 0; iChannel < 64; ++iChannel) {
270 aBBflag[iChannel] = (aBBflagsV0C >> iChannel) & 0x1;
271 aBGflag[iChannel] = (aBGflagsV0C >> iChannel) & 0x1;
274 aBBflag[iChannel] = (aBBflagsV0A >> (iChannel-32)) & 0x1;
275 aBGflag[iChannel] = (aBGflagsV0A >> (iChannel-32)) & 0x1;
279 Int_t nEntries = (Int_t)digitsTree->GetEntries();
280 for (Int_t e=0; e<nEntries; e++) {
281 digitsTree->GetEvent(e);
283 Int_t nDigits = fDigitsArray->GetEntriesFast();
285 for (Int_t d=0; d<nDigits; d++) {
286 AliVZEROdigit* digit = (AliVZEROdigit*) fDigitsArray->At(d);
287 Int_t pmNumber = digit->PMNumber();
289 // Pedestal retrieval and suppression
290 Bool_t integrator = digit->Integrator();
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;
303 if(iClock < GetRecoParam()->GetStartClock() || iClock > GetRecoParam()->GetEndClock()) continue;
304 if(adcPedSub[iClock] > maxadc) {
305 maxadc = adcPedSub[iClock];
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];
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();
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],
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]));
334 mult[pmNumber] = adc[pmNumber]*fCalibData->GetMIPperADC(pmNumber);
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]);
343 fESDVZEROfriend->SetTime(pmNumber,digit->Time());
344 fESDVZEROfriend->SetWidth(pmNumber,digit->Width());
346 } // end of loop over digits
347 } // end of loop over events in digits tree
349 fESDVZERO->SetBit(AliESDVZERO::kCorrectedLeadingTime,kTRUE);
350 fESDVZERO->SetMultiplicity(mult);
351 fESDVZERO->SetADC(adc);
352 fESDVZERO->SetTime(time);
353 fESDVZERO->SetWidth(width);
354 fESDVZERO->SetBit(AliESDVZERO::kOnlineBitsFilled,kTRUE);
355 fESDVZERO->SetBBFlag(aBBflag);
356 fESDVZERO->SetBGFlag(aBGflag);
358 // now fill the V0 decision and channel flags
360 AliVZEROTriggerMask triggerMask;
361 triggerMask.FillMasks(fESDVZERO, fCalibData, fTimeSlewing);
365 AliDebug(1, Form("Writing VZERO data to ESD tree"));
366 esd->SetVZEROData(fESDVZERO);
370 AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
372 AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
373 fr->SetVZEROfriend(fESDVZEROfriend);
377 fDigitsArray->Clear();
380 //_____________________________________________________________________________
381 AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
385 Bool_t deleteManager = kFALSE;
387 AliCDBManager *manager = AliCDBManager::Instance();
388 AliCDBStorage *defstorage = manager->GetDefaultStorage();
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;
396 AliCDBStorage *storage = manager->GetDefaultStorage();
399 AliCDBManager::Instance()->UnsetDefaultStorage();
400 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
406 //____________________________________________________________________________
407 void AliVZEROReconstructor::GetCollisionMode()
409 // Retrieval of collision mode
411 TString beamType = GetRunInfo()->GetBeamType();
412 if(beamType==AliGRPObject::GetInvalidString()){
413 AliError("VZERO cannot retrieve beam type");
417 if( (beamType.CompareTo("P-P") ==0) || (beamType.CompareTo("p-p") ==0) ){
420 else if( (beamType.CompareTo("Pb-Pb") ==0) || (beamType.CompareTo("A-A") ==0) ){
424 fBeamEnergy = GetRunInfo()->GetBeamEnergy();
425 if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
426 AliError("Missing value for the beam energy ! Using 0");
430 AliDebug(1,Form("\n ++++++ Beam type and collision mode retrieved as %s %d @ %1.3f GeV ++++++\n\n",beamType.Data(), fCollisionMode, fBeamEnergy));
434 //_____________________________________________________________________________
435 AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
437 // Gets calibration object for VZERO set
439 AliCDBManager *man = AliCDBManager::Instance();
441 AliCDBEntry *entry=0;
443 entry = man->Get("VZERO/Calib/Data");
445 AliVZEROCalibData *calibdata = 0;
447 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
448 if (!calibdata) AliFatal("No calibration data from calibration database !");
453 Float_t AliVZEROReconstructor::CorrectLeadingTime(Int_t i, Float_t time, Float_t adc) const
455 // Correct the leading time
456 // for slewing effect and
457 // misalignment of the channels
458 if (time < 1e-6) return kInvalidTime;
460 // Channel alignment and general offset subtraction
461 if (i < 32) time -= kV0CDelayCables;
462 time -= fTimeOffset[i];
464 // In case of pathological signals
465 if (adc < 1e-6) return time;
467 // Slewing correction
468 Float_t thr = fCalibData->GetDiscriThr(i);
469 time -= fTimeSlewing->Eval(adc/thr);