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 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliRunLoader.h"
25 #include "AliRawReader.h"
26 #include "AliGRPObject.h"
27 #include "AliCDBManager.h"
28 #include "AliCDBStorage.h"
29 #include "AliCDBEntry.h"
30 #include "AliVZEROReconstructor.h"
31 #include "AliVZERORawStream.h"
32 #include "AliESDEvent.h"
33 #include "AliVZEROTriggerMask.h"
34 #include "AliESDfriend.h"
35 #include "AliESDVZEROfriend.h"
36 #include "AliVZEROdigit.h"
37 #include "AliVZEROCalibData.h"
38 #include "AliRunInfo.h"
40 ClassImp(AliVZEROReconstructor)
42 //_____________________________________________________________________________
43 AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
47 fCalibData(GetCalibData()),
52 // Default constructor
53 // Get calibration data
55 // fCalibData = GetCalibData();
60 //_____________________________________________________________________________
61 AliVZEROReconstructor& AliVZEROReconstructor::operator =
62 (const AliVZEROReconstructor& /*reconstructor*/)
64 // assignment operator
66 Fatal("operator =", "assignment operator not implemented");
70 //_____________________________________________________________________________
71 AliVZEROReconstructor::~AliVZEROReconstructor()
76 delete fESDVZEROfriend;
80 //_____________________________________________________________________________
81 void AliVZEROReconstructor::Init()
85 fESDVZERO = new AliESDVZERO;
86 fESDVZEROfriend = new AliESDVZEROfriend;
88 GetCollisionMode(); // fCollisionMode =1 for Pb-Pb simulated data
91 //______________________________________________________________________
92 void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
94 // converts RAW to digits
97 AliError("No digits tree!");
102 fDigitsArray = new TClonesArray("AliVZEROdigit", 64);
103 digitsTree->Branch("VZERODigit", &fDigitsArray);
105 fESDVZEROfriend->Reset();
108 AliVZERORawStream rawStream(rawReader);
109 if (rawStream.Next()) {
111 Float_t time[64], width[64];
112 Bool_t BBFlag[64], BGFlag[64], integrator[64];
113 for(Int_t i=0; i<64; i++) {
114 Int_t j = rawStream.GetOfflineChannel(i);
120 integrator[j] = kFALSE;
121 // Search for the maximum charge in the train of 21 LHC clocks
122 // regardless of the integrator which has been operated:
125 Float_t adcPedSub[21];
126 for(Int_t iClock=0; iClock<21; iClock++){
127 Bool_t iIntegrator = rawStream.GetIntegratorFlag(i,iClock);
128 Int_t k = j+64*iIntegrator;
129 adcPedSub[iClock] = rawStream.GetPedestal(i,iClock) - fCalibData->GetPedestal(k);
130 if(adcPedSub[iClock] <= GetRecoParam()->GetNSigmaPed()*fCalibData->GetSigma(k)) {
131 adcPedSub[iClock] = 0;
134 if(iClock < GetRecoParam()->GetStartClock() || iClock > GetRecoParam()->GetEndClock()) continue;
135 if(adcPedSub[iClock] > maxadc) {
136 maxadc = adcPedSub[iClock];
141 AliDebug(2,Form("Channel %d (online), %d (offline)",i,j));
143 Int_t start = imax - GetRecoParam()->GetNPreClocks();
144 if (start < 0) start = 0;
145 Int_t end = imax + GetRecoParam()->GetNPostClocks();
146 if (end > 20) end = 20;
147 for(Int_t iClock = start; iClock <= end; iClock++) {
148 if (iClock >= imax) {
149 BBFlag[j] |= rawStream.GetBBFlag(i,iClock);
150 BGFlag[j] |= rawStream.GetBGFlag(i,iClock);
153 adc[j] += rawStream.GetPedestal(i,iClock);
155 adc[j] += adcPedSub[iClock];
157 AliDebug(2,Form("clock = %d adc = %f",iClock,rawStream.GetPedestal(i,iClock)));
159 // Convert i (FEE channel numbering) to j (aliroot channel numbering)
161 integrator[j] = rawStream.GetIntegratorFlag(i,imax);
165 time[j] = rawStream.GetTime(i)/ (25./256.) * fCalibData->GetTimeResolution(board);
166 width[j] = rawStream.GetWidth(i) / 0.4 * fCalibData->GetWidthResolution(board);
168 // Filling the esd friend object
169 fESDVZEROfriend->SetBBScalers(j,rawStream.GetBBScalers(i));
170 fESDVZEROfriend->SetBGScalers(j,rawStream.GetBGScalers(i));
171 for (Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++) {
172 fESDVZEROfriend->SetChargeMB(j,iBunch,rawStream.GetChargeMB(i,iBunch));
173 fESDVZEROfriend->SetIntMBFlag(j,iBunch,rawStream.GetIntMBFlag(i,iBunch));
174 fESDVZEROfriend->SetBBMBFlag(j,iBunch,rawStream.GetBBMBFlag(i,iBunch));
175 fESDVZEROfriend->SetBGMBFlag(j,iBunch,rawStream.GetBGMBFlag(i,iBunch));
177 for (Int_t iEv = 0; iEv < AliESDVZEROfriend::kNEvOfInt; iEv++) {
178 fESDVZEROfriend->SetPedestal(j,iEv,rawStream.GetPedestal(i,iEv));
179 fESDVZEROfriend->SetIntegratorFlag(j,iEv,rawStream.GetIntegratorFlag(i,iEv));
180 fESDVZEROfriend->SetBBFlag(j,iEv,rawStream.GetBBFlag(i,iEv));
181 fESDVZEROfriend->SetBGFlag(j,iEv,rawStream.GetBGFlag(i,iEv));
183 fESDVZEROfriend->SetTime(j,time[j]);
184 fESDVZEROfriend->SetWidth(j,width[j]);
187 // Filling the esd friend object
188 fESDVZEROfriend->SetTriggerInputs(rawStream.GetTriggerInputs());
189 fESDVZEROfriend->SetTriggerInputsMask(rawStream.GetTriggerInputsMask());
191 for(Int_t iScaler = 0; iScaler < AliESDVZEROfriend::kNScalers; iScaler++)
192 fESDVZEROfriend->SetTriggerScalers(iScaler,rawStream.GetTriggerScalers(iScaler));
194 for(Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++)
195 fESDVZEROfriend->SetBunchNumbersMB(iBunch,rawStream.GetBunchNumbersMB(iBunch));
198 // Channels(aliroot numbering) will be ordered in the tree
199 for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
200 if(fCalibData->IsChannelDead(iChannel)){
201 adc[iChannel] = (Float_t) kInvalidADC;
202 time[iChannel] = (Float_t) kInvalidTime;
204 if (adc[iChannel] > 0)
205 new ((*fDigitsArray)[fDigitsArray->GetEntriesFast()])
206 AliVZEROdigit(iChannel, adc[iChannel], time[iChannel],
207 width[iChannel], BBFlag[iChannel], BGFlag[iChannel],integrator[iChannel]);
213 fDigitsArray->Clear();
216 //______________________________________________________________________
217 void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
218 AliESDEvent* esd) const
220 // fills multiplicities to the ESD - pedestal is now subtracted
223 AliError("No digits tree!");
227 TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
228 digitBranch->SetAddress(&fDigitsArray);
237 for (Int_t i=0; i<64; i++){
246 // loop over VZERO entries to get multiplicity
247 Int_t nEntries = (Int_t)digitsTree->GetEntries();
248 for (Int_t e=0; e<nEntries; e++) {
249 digitsTree->GetEvent(e);
251 Int_t nDigits = fDigitsArray->GetEntriesFast();
253 for (Int_t d=0; d<nDigits; d++) {
254 AliVZEROdigit* digit = (AliVZEROdigit*) fDigitsArray->At(d);
255 Int_t pmNumber = digit->PMNumber();
256 // Pedestal retrieval and suppression:
257 Bool_t integrator = digit->Integrator();
258 Int_t k = pmNumber+64*integrator;
259 Float_t pedestal = fCalibData->GetPedestal(k);
260 adc[pmNumber] = digit->ADC() - pedestal;
261 time[pmNumber] = digit->Time();
262 width[pmNumber] = digit->Width();
263 BBFlag[pmNumber]= digit->BBFlag();
264 BGFlag[pmNumber]= digit->BGFlag();
266 AliDebug(2,Form("PM = %d ADC = %f TDC %f",pmNumber, digit->ADC(),digit->Time()));
268 if(adc[pmNumber] > (fCalibData->GetPedestal(k) + GetRecoParam()->GetNSigmaPed()*fCalibData->GetSigma(k))) {
269 mult[pmNumber] += adc[pmNumber]*fCalibData->GetMIPperADC(pmNumber);
271 } // end of loop over digits
272 } // end of loop over events in digits tree
274 fESDVZERO->SetMultiplicity(mult);
275 fESDVZERO->SetADC(adc);
276 fESDVZERO->SetTime(time);
277 fESDVZERO->SetWidth(width);
278 fESDVZERO->SetBBFlag(BBFlag);
279 fESDVZERO->SetBGFlag(BGFlag);
281 // now get the trigger mask
283 AliVZEROTriggerMask *TriggerMask = new AliVZEROTriggerMask();
284 TriggerMask->SetAdcThreshold(10.0/2.0);
285 TriggerMask->SetTimeWindowWidthBBA(50);
286 TriggerMask->SetTimeWindowWidthBGA(20);
287 TriggerMask->SetTimeWindowWidthBBC(50);
288 TriggerMask->SetTimeWindowWidthBGC(20);
289 TriggerMask->FillMasks(digitsTree, fDigitsArray);
291 fESDVZERO->SetBBtriggerV0A(TriggerMask->GetBBtriggerV0A());
292 fESDVZERO->SetBGtriggerV0A(TriggerMask->GetBGtriggerV0A());
293 fESDVZERO->SetBBtriggerV0C(TriggerMask->GetBBtriggerV0C());
294 fESDVZERO->SetBGtriggerV0C(TriggerMask->GetBGtriggerV0C());
297 AliDebug(1, Form("Writing VZERO data to ESD tree"));
298 esd->SetVZEROData(fESDVZERO);
302 AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
304 AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
305 fr->SetVZEROfriend(fESDVZEROfriend);
309 fDigitsArray->Clear();
312 //_____________________________________________________________________________
313 AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
317 Bool_t deleteManager = kFALSE;
319 AliCDBManager *manager = AliCDBManager::Instance();
320 AliCDBStorage *defstorage = manager->GetDefaultStorage();
322 if(!defstorage || !(defstorage->Contains("VZERO"))){
323 AliWarning("No default storage set or default storage doesn't contain VZERO!");
324 manager->SetDefaultStorage(uri);
325 deleteManager = kTRUE;
328 AliCDBStorage *storage = manager->GetDefaultStorage();
331 AliCDBManager::Instance()->UnsetDefaultStorage();
332 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
338 //____________________________________________________________________________
339 void AliVZEROReconstructor::GetCollisionMode()
341 // Retrieval of collision mode
343 TString beamType = GetRunInfo()->GetBeamType();
344 if(beamType==AliGRPObject::GetInvalidString()){
345 AliError("VZERO cannot retrieve beam type");
349 if( (beamType.CompareTo("P-P") ==0) || (beamType.CompareTo("p-p") ==0) ){
352 else if( (beamType.CompareTo("Pb-Pb") ==0) || (beamType.CompareTo("A-A") ==0) ){
356 fBeamEnergy = GetRunInfo()->GetBeamEnergy();
357 if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
358 AliError("Missing value for the beam energy ! Using 0");
362 AliDebug(1,Form("\n ++++++ Beam type and collision mode retrieved as %s %d @ %1.3f GeV ++++++\n\n",beamType.Data(), fCollisionMode, fBeamEnergy));
366 //_____________________________________________________________________________
367 AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
369 // Gets calibration object for VZERO set
371 AliCDBManager *man = AliCDBManager::Instance();
373 AliCDBEntry *entry=0;
375 entry = man->Get("VZERO/Calib/Data");
378 // AliWarning("Load of calibration data from default storage failed!");
379 // AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
380 // Int_t runNumber = man->GetRun();
381 // entry = man->GetStorage("local://$ALICE_ROOT/OCDB")
382 // ->Get("VZERO/Calib/Data",runNumber);
386 // Retrieval of data in directory VZERO/Calib/Data:
388 AliVZEROCalibData *calibdata = 0;
390 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
391 if (!calibdata) AliFatal("No calibration data from calibration database !");