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