Fixes to the raw-data reco. 1. Possibility to select the max adc search window. 2...
[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++) {
145 if (iClock == imax)
146 adc[j] += rawStream.GetPedestal(i,iClock);
147 else
148 adc[j] += adcPedSub[iClock];
149
150 AliDebug(2,Form("clock = %d adc = %f",iClock,rawStream.GetPedestal(i,iClock)));
151 }
152 // Convert i (FEE channel numbering) to j (aliroot channel numbering)
153
154 Int_t board = j / 8;
155 time[j] = rawStream.GetTime(i)/ (25./256.) * fCalibData->GetTimeResolution(board);
156 width[j] = rawStream.GetWidth(i) / 0.4 * fCalibData->GetWidthResolution(board);
157 BBFlag[j] = rawStream.GetBBFlag(i,imax);
158 BGFlag[j] = rawStream.GetBGFlag(i,imax);
159 integrator[j] = rawStream.GetIntegratorFlag(i,imax);
160 }
b090e6a3 161
162 // Filling the esd friend object
163 fESDVZEROfriend->SetBBScalers(j,rawStream.GetBBScalers(i));
164 fESDVZEROfriend->SetBGScalers(j,rawStream.GetBGScalers(i));
165 for (Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++) {
db0db003 166 fESDVZEROfriend->SetChargeMB(j,iBunch,rawStream.GetChargeMB(i,iBunch));
167 fESDVZEROfriend->SetIntMBFlag(j,iBunch,rawStream.GetIntMBFlag(i,iBunch));
168 fESDVZEROfriend->SetBBMBFlag(j,iBunch,rawStream.GetBBMBFlag(i,iBunch));
169 fESDVZEROfriend->SetBGMBFlag(j,iBunch,rawStream.GetBGMBFlag(i,iBunch));
b090e6a3 170 }
171 for (Int_t iEv = 0; iEv < AliESDVZEROfriend::kNEvOfInt; iEv++) {
db0db003 172 fESDVZEROfriend->SetPedestal(j,iEv,rawStream.GetPedestal(i,iEv));
173 fESDVZEROfriend->SetIntegratorFlag(j,iEv,rawStream.GetIntegratorFlag(i,iEv));
174 fESDVZEROfriend->SetBBFlag(j,iEv,rawStream.GetBBFlag(i,iEv));
175 fESDVZEROfriend->SetBGFlag(j,iEv,rawStream.GetBGFlag(i,iEv));
b090e6a3 176 }
e58b4e66 177 fESDVZEROfriend->SetTime(j,time[j]);
178 fESDVZEROfriend->SetWidth(j,width[j]);
9d62c464 179 }
b090e6a3 180
181 // Filling the esd friend object
182 fESDVZEROfriend->SetTriggerInputs(rawStream.GetTriggerInputs());
183 fESDVZEROfriend->SetTriggerInputsMask(rawStream.GetTriggerInputsMask());
184
185 for(Int_t iScaler = 0; iScaler < AliESDVZEROfriend::kNScalers; iScaler++)
db0db003 186 fESDVZEROfriend->SetTriggerScalers(iScaler,rawStream.GetTriggerScalers(iScaler));
b090e6a3 187
db0db003 188 for(Int_t iBunch = 0; iBunch < AliESDVZEROfriend::kNBunches; iBunch++)
189 fESDVZEROfriend->SetBunchNumbersMB(iBunch,rawStream.GetBunchNumbersMB(iBunch));
b090e6a3 190
191
9d62c464 192 // Channels(aliroot numbering) will be ordered in the tree
193 for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
7495d2be 194 if(fCalibData->IsChannelDead(iChannel)){
195 adc[iChannel] = (Float_t) kInvalidADC;
196 time[iChannel] = (Float_t) kInvalidTime;
197 }
75b6bc77 198 if (adc[iChannel] > 0)
199 new ((*digitsArray)[digitsArray->GetEntriesFast()])
d0502ab2 200 AliVZEROdigit(iChannel, adc[iChannel], time[iChannel],
fad64858 201 width[iChannel], BBFlag[iChannel], BGFlag[iChannel],integrator[iChannel]);
7495d2be 202
f0ff6fad 203 }
204 digitsTree->Fill();
2e0ee64a 205 }
2e0ee64a 206}
207
208//______________________________________________________________________
209void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
b14e6eb4 210 AliESDEvent* esd) const
2e0ee64a 211{
75b6bc77 212// fills multiplicities to the ESD - pedestal is now subtracted
fe0adf2a 213
2e0ee64a 214 if (!digitsTree) {
fe0adf2a 215 AliError("No digits tree!");
216 return;
2e0ee64a 217 }
a055ee24 218
2e0ee64a 219 TClonesArray* digitsArray = NULL;
220 TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
221 digitBranch->SetAddress(&digitsArray);
35b120ff 222
44b6212f 223 Float_t mult[64];
db0db003 224 Float_t adc[64];
225 Float_t time[64];
226 Float_t width[64];
d0502ab2 227 Bool_t BBFlag[64];
228 Bool_t BGFlag[64];
229
35b120ff 230 for (Int_t i=0; i<64; i++){
db0db003 231 adc[i] = 0.0;
d0502ab2 232 mult[i] = 0.0;
db0db003 233 time[i] = 0.0;
234 width[i] = 0.0;
d0502ab2 235 BBFlag[i] = kFALSE;
236 BGFlag[i] = kFALSE;
a055ee24 237 }
35b120ff 238
a055ee24 239 // loop over VZERO entries to get multiplicity
2e0ee64a 240 Int_t nEntries = (Int_t)digitsTree->GetEntries();
35b120ff 241 for (Int_t e=0; e<nEntries; e++) {
2e0ee64a 242 digitsTree->GetEvent(e);
35b120ff 243
2e0ee64a 244 Int_t nDigits = digitsArray->GetEntriesFast();
35b120ff 245
246 for (Int_t d=0; d<nDigits; d++) {
63627899 247 AliVZEROdigit* digit = (AliVZEROdigit*)digitsArray->At(d);
248 Int_t pmNumber = digit->PMNumber();
249 // Pedestal retrieval and suppression:
75b6bc77 250 Bool_t integrator = digit->Integrator();
251 Float_t pedestal = fCalibData->GetPedestal(d + 64*integrator);
db0db003 252 adc[pmNumber] = digit->ADC() - pedestal;
253 time[pmNumber] = digit->Time();
254 width[pmNumber] = digit->Width();
255 BBFlag[pmNumber]= digit->BBFlag();
256 BGFlag[pmNumber]= digit->BGFlag();
75b6bc77 257
258 AliDebug(2,Form("PM = %d ADC = %f TDC %f",pmNumber, digit->ADC(),digit->Time()));
259
260 Int_t k = pmNumber+64*integrator;
261 if(adc[pmNumber] > (fCalibData->GetPedestal(k) + GetRecoParam()->GetNSigmaPed()*fCalibData->GetSigma(k))) {
262 mult[pmNumber] += adc[pmNumber]*fCalibData->GetMIPperADC(pmNumber);
fe0adf2a 263 }
35b120ff 264 } // end of loop over digits
35b120ff 265 } // end of loop over events in digits tree
6c6d6114 266
267 fESDVZERO->SetMultiplicity(mult);
28fdf12c 268 fESDVZERO->SetADC(adc);
269 fESDVZERO->SetTime(time);
d0502ab2 270 fESDVZERO->SetWidth(width);
271 fESDVZERO->SetBBFlag(BBFlag);
272 fESDVZERO->SetBGFlag(BGFlag);
a055ee24 273
274 // now get the trigger mask
275
276 AliVZEROTriggerMask *TriggerMask = new AliVZEROTriggerMask();
fe0adf2a 277 TriggerMask->SetAdcThreshold(10.0/2.0);
a055ee24 278 TriggerMask->SetTimeWindowWidthBBA(50);
279 TriggerMask->SetTimeWindowWidthBGA(20);
280 TriggerMask->SetTimeWindowWidthBBC(50);
281 TriggerMask->SetTimeWindowWidthBGC(20);
282 TriggerMask->FillMasks(digitsTree,digitsArray);
283
284 fESDVZERO->SetBBtriggerV0A(TriggerMask->GetBBtriggerV0A());
285 fESDVZERO->SetBGtriggerV0A(TriggerMask->GetBGtriggerV0A());
286 fESDVZERO->SetBBtriggerV0C(TriggerMask->GetBBtriggerV0C());
287 fESDVZERO->SetBGtriggerV0C(TriggerMask->GetBGtriggerV0C());
35b120ff 288
2e0ee64a 289 if (esd) {
44b6212f 290 AliDebug(1, Form("Writing VZERO data to ESD tree"));
291 esd->SetVZEROData(fESDVZERO);
2e0ee64a 292 }
b090e6a3 293
294 if (esd) {
fe0adf2a 295 AliESDfriend *fr = (AliESDfriend*)esd->FindListObject("AliESDfriend");
296 if (fr) {
297 AliDebug(1, Form("Writing VZERO friend data to ESD tree"));
298 fr->SetVZEROfriend(fESDVZEROfriend);
b090e6a3 299 }
300 }
35b120ff 301}
302
ce7090f5 303//_____________________________________________________________________________
304AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
305{
ef314913 306// Sets the storage
307
ce7090f5 308 Bool_t deleteManager = kFALSE;
309
310 AliCDBManager *manager = AliCDBManager::Instance();
311 AliCDBStorage *defstorage = manager->GetDefaultStorage();
312
313 if(!defstorage || !(defstorage->Contains("VZERO"))){
314 AliWarning("No default storage set or default storage doesn't contain VZERO!");
315 manager->SetDefaultStorage(uri);
316 deleteManager = kTRUE;
317 }
318
319 AliCDBStorage *storage = manager->GetDefaultStorage();
320
321 if(deleteManager){
44b6212f 322 AliCDBManager::Instance()->UnsetDefaultStorage();
323 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
ce7090f5 324 }
325
326 return storage;
327}
328
fe0adf2a 329//____________________________________________________________________________
330void AliVZEROReconstructor::GetCollisionMode()
331{
75b6bc77 332 // Retrieval of collision mode
fe0adf2a 333
75b6bc77 334 TString beamType = GetRunInfo()->GetBeamType();
fe0adf2a 335 if(beamType==AliGRPObject::GetInvalidString()){
75b6bc77 336 AliError("VZERO cannot retrieve beam type");
fe0adf2a 337 return;
338 }
339
75b6bc77 340 if( (beamType.CompareTo("P-P") ==0) || (beamType.CompareTo("p-p") ==0) ){
341 fCollisionMode=0;
342 }
343 else if( (beamType.CompareTo("Pb-Pb") ==0) || (beamType.CompareTo("A-A") ==0) ){
344 fCollisionMode=1;
fe0adf2a 345 }
fe0adf2a 346
75b6bc77 347 fBeamEnergy = GetRunInfo()->GetBeamEnergy();
fe0adf2a 348 if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
75b6bc77 349 AliError("Missing value for the beam energy ! Using 0");
fe0adf2a 350 fBeamEnergy = 0.;
351 }
352
75b6bc77 353 AliDebug(1,Form("\n ++++++ Beam type and collision mode retrieved as %s %d @ %1.3f GeV ++++++\n\n",beamType.Data(), fCollisionMode, fBeamEnergy));
fe0adf2a 354
355}
356
ce7090f5 357//_____________________________________________________________________________
358AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
359{
ef314913 360 // Gets calibration object for VZERO set
ce7090f5 361
c0b82b5a 362 AliCDBManager *man = AliCDBManager::Instance();
ce7090f5 363
c0b82b5a 364 AliCDBEntry *entry=0;
365
366 entry = man->Get("VZERO/Calib/Data");
367
94a600a1 368// if(!entry){
369// AliWarning("Load of calibration data from default storage failed!");
370// AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
371// Int_t runNumber = man->GetRun();
162637e4 372// entry = man->GetStorage("local://$ALICE_ROOT/OCDB")
94a600a1 373// ->Get("VZERO/Calib/Data",runNumber);
374//
375// }
c0b82b5a 376
377 // Retrieval of data in directory VZERO/Calib/Data:
378
c0b82b5a 379 AliVZEROCalibData *calibdata = 0;
380
381 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
94a600a1 382 if (!calibdata) AliFatal("No calibration data from calibration database !");
ce7090f5 383
384 return calibdata;
385}
44b6212f 386