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