correction for the gbbox search
[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
35b120ff 24#include "AliRunLoader.h"
2eb38194 25#include "AliRawReader.h"
fe0adf2a 26#include "AliGRPObject.h"
27#include "AliCDBManager.h"
28#include "AliCDBStorage.h"
29#include "AliCDBEntry.h"
b0d2c2d3 30#include "AliVZEROReconstructor.h"
2eb38194 31#include "AliVZERORawStream.h"
b14e6eb4 32#include "AliESDEvent.h"
a055ee24 33#include "AliVZEROTriggerMask.h"
b090e6a3 34#include "AliESDfriend.h"
35#include "AliESDVZEROfriend.h"
fad64858 36#include "AliVZEROdigit.h"
e58b4e66 37#include "AliVZEROCalibData.h"
75b6bc77 38#include "AliRunInfo.h"
b0d2c2d3 39
b0d2c2d3 40ClassImp(AliVZEROReconstructor)
41
ce7090f5 42//_____________________________________________________________________________
cb2228e6 43AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
fe0adf2a 44 fESDVZERO(0x0),
45 fESD(0x0),
46 fESDVZEROfriend(0x0),
47 fCalibData(GetCalibData()),
48 fCollisionMode(0),
49 fBeamEnergy(0.)
ce7090f5 50{
51 // Default constructor
ce7090f5 52 // Get calibration data
53
35b120ff 54 // fCalibData = GetCalibData();
44b6212f 55
ce7090f5 56}
57
58
59//_____________________________________________________________________________
60AliVZEROReconstructor& AliVZEROReconstructor::operator =
61 (const AliVZEROReconstructor& /*reconstructor*/)
62{
63// assignment operator
64
65 Fatal("operator =", "assignment operator not implemented");
66 return *this;
67}
68
69//_____________________________________________________________________________
70AliVZEROReconstructor::~AliVZEROReconstructor()
71{
72// destructor
44b6212f 73
b090e6a3 74 delete fESDVZERO;
75 delete fESDVZEROfriend;
35b120ff 76}
77
78//_____________________________________________________________________________
d76c31f4 79void AliVZEROReconstructor::Init()
35b120ff 80{
ef314913 81// initializer
ce7090f5 82
35b120ff 83 fESDVZERO = new AliESDVZERO;
b090e6a3 84 fESDVZEROfriend = new AliESDVZEROfriend;
fe0adf2a 85
86 GetCollisionMode(); // fCollisionMode =1 for Pb-Pb simulated data
35b120ff 87}
88
89//______________________________________________________________________
2e0ee64a 90void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
35b120ff 91{
75b6bc77 92// converts RAW to digits
ef314913 93
2e0ee64a 94 if (!digitsTree) {
95 AliError("No digits tree!");
96 return;
97 }
35b120ff 98
2e0ee64a 99 TClonesArray* digitsArray = new TClonesArray("AliVZEROdigit");
100 digitsTree->Branch("VZERODigit", &digitsArray);
101
b090e6a3 102 fESDVZEROfriend->Reset();
103
2e0ee64a 104 rawReader->Reset();
105 AliVZERORawStream rawStream(rawReader);
75b6bc77 106 if (rawStream.Next()) {
107 Float_t adc[64];
6c115a32 108 Float_t time[64], width[64];
75b6bc77 109 Bool_t BBFlag[64], BGFlag[64], integrator[64];
9d62c464 110 for(Int_t i=0; i<64; i++) {
75b6bc77 111 Int_t j = rawStream.GetOfflineChannel(i);
112 adc[j] = 0.0;
113 time[j] = 0.0;
114 width[j] = 0.0;
115 BBFlag[j] = kFALSE;
116 BGFlag[j] = kFALSE;
117 integrator[j] = kFALSE;
118 // Search for the maximum charge in the train of 21 LHC clocks
119 // regardless of the integrator which has been operated:
120 Float_t maxadc = 0;
121 Int_t imax = -1;
122 Float_t adcPedSub[21];
123 for(Int_t iClock=0; iClock<21; iClock++){
124 Bool_t iIntegrator = rawStream.GetIntegratorFlag(i,iClock);
125 Int_t k = j+64*iIntegrator;
126 adcPedSub[iClock] = rawStream.GetPedestal(i,iClock) - fCalibData->GetPedestal(k);
127 if(adcPedSub[iClock] <= GetRecoParam()->GetNSigmaPed()*fCalibData->GetSigma(k)) {
128 adcPedSub[iClock] = 0;
129 continue;
130 }
131 if(iClock < GetRecoParam()->GetStartClock() || iClock > GetRecoParam()->GetEndClock()) continue;
132 if(adcPedSub[iClock] > maxadc) {
133 maxadc = adcPedSub[iClock];
134 imax = iClock;
135 }
136 }
137
138 AliDebug(2,Form("Channel %d (online), %d (offline)",i,j));
139 if (imax != -1) {
140 Int_t start = imax - GetRecoParam()->GetNPreClocks();
141 if (start < 0) start = 0;
142 Int_t end = imax + GetRecoParam()->GetNPostClocks();
143 if (end > 20) end = 20;
144 for(Int_t iClock = start; iClock <= end; iClock++) {
f93f97bb 145 if (iClock >= imax) {
146 BBFlag[j] |= rawStream.GetBBFlag(i,iClock);
147 BGFlag[j] |= rawStream.GetBGFlag(i,iClock);
148 }
75b6bc77 149 if (iClock == imax)
150 adc[j] += rawStream.GetPedestal(i,iClock);
151 else
152 adc[j] += adcPedSub[iClock];
153
154 AliDebug(2,Form("clock = %d adc = %f",iClock,rawStream.GetPedestal(i,iClock)));
155 }
156 // Convert i (FEE channel numbering) to j (aliroot channel numbering)
157
75b6bc77 158 integrator[j] = rawStream.GetIntegratorFlag(i,imax);
159 }
b090e6a3 160
82dae5d9 161 Int_t board = j / 8;
162 time[j] = rawStream.GetTime(i)/ (25./256.) * fCalibData->GetTimeResolution(board);
163 width[j] = rawStream.GetWidth(i) / 0.4 * fCalibData->GetWidthResolution(board);
164
b090e6a3 165 // Filling the esd friend object
166 fESDVZEROfriend->SetBBScalers(j,rawStream.GetBBScalers(i));
167 fESDVZEROfriend->SetBGScalers(j,rawStream.GetBGScalers(i));
168 for (Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++) {
db0db003 169 fESDVZEROfriend->SetChargeMB(j,iBunch,rawStream.GetChargeMB(i,iBunch));
170 fESDVZEROfriend->SetIntMBFlag(j,iBunch,rawStream.GetIntMBFlag(i,iBunch));
171 fESDVZEROfriend->SetBBMBFlag(j,iBunch,rawStream.GetBBMBFlag(i,iBunch));
172 fESDVZEROfriend->SetBGMBFlag(j,iBunch,rawStream.GetBGMBFlag(i,iBunch));
b090e6a3 173 }
174 for (Int_t iEv = 0; iEv < AliESDVZEROfriend::kNEvOfInt; iEv++) {
db0db003 175 fESDVZEROfriend->SetPedestal(j,iEv,rawStream.GetPedestal(i,iEv));
176 fESDVZEROfriend->SetIntegratorFlag(j,iEv,rawStream.GetIntegratorFlag(i,iEv));
177 fESDVZEROfriend->SetBBFlag(j,iEv,rawStream.GetBBFlag(i,iEv));
178 fESDVZEROfriend->SetBGFlag(j,iEv,rawStream.GetBGFlag(i,iEv));
b090e6a3 179 }
e58b4e66 180 fESDVZEROfriend->SetTime(j,time[j]);
181 fESDVZEROfriend->SetWidth(j,width[j]);
9d62c464 182 }
b090e6a3 183
184 // Filling the esd friend object
185 fESDVZEROfriend->SetTriggerInputs(rawStream.GetTriggerInputs());
186 fESDVZEROfriend->SetTriggerInputsMask(rawStream.GetTriggerInputsMask());
187
188 for(Int_t iScaler = 0; iScaler < AliESDVZEROfriend::kNScalers; iScaler++)
db0db003 189 fESDVZEROfriend->SetTriggerScalers(iScaler,rawStream.GetTriggerScalers(iScaler));
b090e6a3 190
db0db003 191 for(Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++)
192 fESDVZEROfriend->SetBunchNumbersMB(iBunch,rawStream.GetBunchNumbersMB(iBunch));
b090e6a3 193
194
9d62c464 195 // Channels(aliroot numbering) will be ordered in the tree
196 for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
7495d2be 197 if(fCalibData->IsChannelDead(iChannel)){
198 adc[iChannel] = (Float_t) kInvalidADC;
199 time[iChannel] = (Float_t) kInvalidTime;
200 }
75b6bc77 201 if (adc[iChannel] > 0)
202 new ((*digitsArray)[digitsArray->GetEntriesFast()])
d0502ab2 203 AliVZEROdigit(iChannel, adc[iChannel], time[iChannel],
fad64858 204 width[iChannel], BBFlag[iChannel], BGFlag[iChannel],integrator[iChannel]);
7495d2be 205
f0ff6fad 206 }
207 digitsTree->Fill();
2e0ee64a 208 }
2e0ee64a 209}
210
211//______________________________________________________________________
212void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
b14e6eb4 213 AliESDEvent* esd) const
2e0ee64a 214{
75b6bc77 215// fills multiplicities to the ESD - pedestal is now subtracted
fe0adf2a 216
2e0ee64a 217 if (!digitsTree) {
fe0adf2a 218 AliError("No digits tree!");
219 return;
2e0ee64a 220 }
a055ee24 221
2e0ee64a 222 TClonesArray* digitsArray = NULL;
223 TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
224 digitBranch->SetAddress(&digitsArray);
35b120ff 225
44b6212f 226 Float_t mult[64];
db0db003 227 Float_t adc[64];
228 Float_t time[64];
229 Float_t width[64];
d0502ab2 230 Bool_t BBFlag[64];
231 Bool_t BGFlag[64];
232
35b120ff 233 for (Int_t i=0; i<64; i++){
db0db003 234 adc[i] = 0.0;
d0502ab2 235 mult[i] = 0.0;
db0db003 236 time[i] = 0.0;
237 width[i] = 0.0;
d0502ab2 238 BBFlag[i] = kFALSE;
239 BGFlag[i] = kFALSE;
a055ee24 240 }
35b120ff 241
a055ee24 242 // loop over VZERO entries to get multiplicity
2e0ee64a 243 Int_t nEntries = (Int_t)digitsTree->GetEntries();
35b120ff 244 for (Int_t e=0; e<nEntries; e++) {
2e0ee64a 245 digitsTree->GetEvent(e);
35b120ff 246
2e0ee64a 247 Int_t nDigits = digitsArray->GetEntriesFast();
35b120ff 248
249 for (Int_t d=0; d<nDigits; d++) {
63627899 250 AliVZEROdigit* digit = (AliVZEROdigit*)digitsArray->At(d);
251 Int_t pmNumber = digit->PMNumber();
252 // Pedestal retrieval and suppression:
75b6bc77 253 Bool_t integrator = digit->Integrator();
f93f97bb 254 Int_t k = pmNumber+64*integrator;
255 Float_t pedestal = fCalibData->GetPedestal(k);
db0db003 256 adc[pmNumber] = digit->ADC() - pedestal;
257 time[pmNumber] = digit->Time();
258 width[pmNumber] = digit->Width();
259 BBFlag[pmNumber]= digit->BBFlag();
260 BGFlag[pmNumber]= digit->BGFlag();
75b6bc77 261
262 AliDebug(2,Form("PM = %d ADC = %f TDC %f",pmNumber, digit->ADC(),digit->Time()));
263
75b6bc77 264 if(adc[pmNumber] > (fCalibData->GetPedestal(k) + GetRecoParam()->GetNSigmaPed()*fCalibData->GetSigma(k))) {
265 mult[pmNumber] += adc[pmNumber]*fCalibData->GetMIPperADC(pmNumber);
fe0adf2a 266 }
35b120ff 267 } // end of loop over digits
35b120ff 268 } // end of loop over events in digits tree
6c6d6114 269
270 fESDVZERO->SetMultiplicity(mult);
28fdf12c 271 fESDVZERO->SetADC(adc);
272 fESDVZERO->SetTime(time);
d0502ab2 273 fESDVZERO->SetWidth(width);
274 fESDVZERO->SetBBFlag(BBFlag);
275 fESDVZERO->SetBGFlag(BGFlag);
a055ee24 276
277 // now get the trigger mask
278
279 AliVZEROTriggerMask *TriggerMask = new AliVZEROTriggerMask();
fe0adf2a 280 TriggerMask->SetAdcThreshold(10.0/2.0);
a055ee24 281 TriggerMask->SetTimeWindowWidthBBA(50);
282 TriggerMask->SetTimeWindowWidthBGA(20);
283 TriggerMask->SetTimeWindowWidthBBC(50);
284 TriggerMask->SetTimeWindowWidthBGC(20);
285 TriggerMask->FillMasks(digitsTree,digitsArray);
286
287 fESDVZERO->SetBBtriggerV0A(TriggerMask->GetBBtriggerV0A());
288 fESDVZERO->SetBGtriggerV0A(TriggerMask->GetBGtriggerV0A());
289 fESDVZERO->SetBBtriggerV0C(TriggerMask->GetBBtriggerV0C());
290 fESDVZERO->SetBGtriggerV0C(TriggerMask->GetBGtriggerV0C());
35b120ff 291
2e0ee64a 292 if (esd) {
44b6212f 293 AliDebug(1, Form("Writing VZERO data to ESD tree"));
294 esd->SetVZEROData(fESDVZERO);
2e0ee64a 295 }
b090e6a3 296
297 if (esd) {
fe0adf2a 298 AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
299 if (fr) {
300 AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
301 fr->SetVZEROfriend(fESDVZEROfriend);
b090e6a3 302 }
303 }
35b120ff 304}
305
ce7090f5 306//_____________________________________________________________________________
307AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
308{
ef314913 309// Sets the storage
310
ce7090f5 311 Bool_t deleteManager = kFALSE;
312
313 AliCDBManager *manager = AliCDBManager::Instance();
314 AliCDBStorage *defstorage = manager->GetDefaultStorage();
315
316 if(!defstorage || !(defstorage->Contains("VZERO"))){
317 AliWarning("No default storage set or default storage doesn't contain VZERO!");
318 manager->SetDefaultStorage(uri);
319 deleteManager = kTRUE;
320 }
321
322 AliCDBStorage *storage = manager->GetDefaultStorage();
323
324 if(deleteManager){
44b6212f 325 AliCDBManager::Instance()->UnsetDefaultStorage();
326 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
ce7090f5 327 }
328
329 return storage;
330}
331
fe0adf2a 332//____________________________________________________________________________
333void AliVZEROReconstructor::GetCollisionMode()
334{
75b6bc77 335 // Retrieval of collision mode
fe0adf2a 336
75b6bc77 337 TString beamType = GetRunInfo()->GetBeamType();
fe0adf2a 338 if(beamType==AliGRPObject::GetInvalidString()){
75b6bc77 339 AliError("VZERO cannot retrieve beam type");
fe0adf2a 340 return;
341 }
342
75b6bc77 343 if( (beamType.CompareTo("P-P") ==0) || (beamType.CompareTo("p-p") ==0) ){
344 fCollisionMode=0;
345 }
346 else if( (beamType.CompareTo("Pb-Pb") ==0) || (beamType.CompareTo("A-A") ==0) ){
347 fCollisionMode=1;
fe0adf2a 348 }
fe0adf2a 349
75b6bc77 350 fBeamEnergy = GetRunInfo()->GetBeamEnergy();
fe0adf2a 351 if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
75b6bc77 352 AliError("Missing value for the beam energy ! Using 0");
fe0adf2a 353 fBeamEnergy = 0.;
354 }
355
75b6bc77 356 AliDebug(1,Form("\n ++++++ Beam type and collision mode retrieved as %s %d @ %1.3f GeV ++++++\n\n",beamType.Data(), fCollisionMode, fBeamEnergy));
fe0adf2a 357
358}
359
ce7090f5 360//_____________________________________________________________________________
361AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
362{
ef314913 363 // Gets calibration object for VZERO set
ce7090f5 364
c0b82b5a 365 AliCDBManager *man = AliCDBManager::Instance();
ce7090f5 366
c0b82b5a 367 AliCDBEntry *entry=0;
368
369 entry = man->Get("VZERO/Calib/Data");
370
94a600a1 371// if(!entry){
372// AliWarning("Load of calibration data from default storage failed!");
373// AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
374// Int_t runNumber = man->GetRun();
162637e4 375// entry = man->GetStorage("local://$ALICE_ROOT/OCDB")
94a600a1 376// ->Get("VZERO/Calib/Data",runNumber);
377//
378// }
c0b82b5a 379
380 // Retrieval of data in directory VZERO/Calib/Data:
381
c0b82b5a 382 AliVZEROCalibData *calibdata = 0;
383
384 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
94a600a1 385 if (!calibdata) AliFatal("No calibration data from calibration database !");
ce7090f5 386
387 return calibdata;
388}
44b6212f 389