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