new updates in MC usage inside the train
[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"
b0d2c2d3 26#include "AliVZEROReconstructor.h"
2eb38194 27#include "AliVZERORawStream.h"
b14e6eb4 28#include "AliESDEvent.h"
a055ee24 29#include "AliVZEROTriggerMask.h"
b0d2c2d3 30
b0d2c2d3 31ClassImp(AliVZEROReconstructor)
32
ce7090f5 33//_____________________________________________________________________________
cb2228e6 34AliVZEROReconstructor:: AliVZEROReconstructor(): AliReconstructor(),
35b120ff 35 fESDVZERO(0x0),
36 fESD(0x0),
cb2228e6 37 fCalibData(GetCalibData())
ce7090f5 38{
39 // Default constructor
ce7090f5 40 // Get calibration data
41
35b120ff 42 // fCalibData = GetCalibData();
ce7090f5 43}
44
45
46//_____________________________________________________________________________
47AliVZEROReconstructor& AliVZEROReconstructor::operator =
48 (const AliVZEROReconstructor& /*reconstructor*/)
49{
50// assignment operator
51
52 Fatal("operator =", "assignment operator not implemented");
53 return *this;
54}
55
56//_____________________________________________________________________________
57AliVZEROReconstructor::~AliVZEROReconstructor()
58{
59// destructor
35b120ff 60 delete fESDVZERO;
61
62}
63
64//_____________________________________________________________________________
d76c31f4 65void AliVZEROReconstructor::Init()
35b120ff 66{
ef314913 67// initializer
ce7090f5 68
35b120ff 69 fESDVZERO = new AliESDVZERO;
70}
71
72//______________________________________________________________________
2e0ee64a 73void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
35b120ff 74{
9d62c464 75// converts RAW to digits
ef314913 76
2e0ee64a 77 if (!digitsTree) {
78 AliError("No digits tree!");
79 return;
80 }
35b120ff 81
2e0ee64a 82 TClonesArray* digitsArray = new TClonesArray("AliVZEROdigit");
83 digitsTree->Branch("VZERODigit", &digitsArray);
84
85 rawReader->Reset();
86 AliVZERORawStream rawStream(rawReader);
9d62c464 87 if (rawStream.Next()) {
88 Int_t ADC_max[64], adc[64], time[64];
89 for(Int_t i=0; i<64; i++) {
90 // Search for the maximun charge in the train of 21 LHC clocks
91 // regardless of the integrator which has been operated:
92 ADC_max[i] = 0;
93 for(Int_t iClock=0; iClock<21; iClock++){
94 if((Int_t)rawStream.GetPedestal(i,iClock) > ADC_max[i])
95 {ADC_max[i]=(Int_t)rawStream.GetPedestal(i,iClock);}
96 }
97 // Convert i (FEE channel numbering) to j (aliroot channel numbering)
98 Int_t j = rawStream.GetOfflineChannel(i);
99 adc[j] = ADC_max[i];
100 time[j] = rawStream.GetTime(i);
101 }
102 // Channels(aliroot numbering) will be ordered in the tree
103 for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
104 new ((*digitsArray)[digitsArray->GetEntriesFast()])
105 AliVZEROdigit(iChannel,adc[iChannel],time[iChannel]);
106 }
2e0ee64a 107 }
108
109 digitsTree->Fill();
110}
111
112//______________________________________________________________________
113void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
b14e6eb4 114 AliESDEvent* esd) const
2e0ee64a 115{
ef314913 116// fills multiplicities to the ESD
117
2e0ee64a 118 if (!digitsTree) {
119 AliError("No digits tree!");
120 return;
121 }
a055ee24 122
2e0ee64a 123 TClonesArray* digitsArray = NULL;
124 TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
125 digitBranch->SetAddress(&digitsArray);
35b120ff 126
a055ee24 127 const Float_t mip0=110.0;
128 Short_t Multiplicity[64];
129 Float_t mult[64];
28fdf12c 130 Short_t adc[64];
131 Short_t time[64];
ef314913 132 Float_t mip[64];
35b120ff 133 for (Int_t i=0; i<64; i++){
ef314913 134 adc[i] = 0;
a055ee24 135 mip[i] = mip0;
136 mult[i]= 0.0;
137 }
35b120ff 138
a055ee24 139 // loop over VZERO entries to get multiplicity
2e0ee64a 140 Int_t nEntries = (Int_t)digitsTree->GetEntries();
35b120ff 141 for (Int_t e=0; e<nEntries; e++) {
2e0ee64a 142 digitsTree->GetEvent(e);
35b120ff 143
2e0ee64a 144 Int_t nDigits = digitsArray->GetEntriesFast();
35b120ff 145
146 for (Int_t d=0; d<nDigits; d++) {
63627899 147 AliVZEROdigit* digit = (AliVZEROdigit*)digitsArray->At(d);
148 Int_t pmNumber = digit->PMNumber();
149 // Pedestal retrieval and suppression:
150 Int_t pedestal = int(fCalibData->GetPedestal(d));
151 adc[pmNumber] = (Short_t) digit->ADC() - pedestal;
152 time[pmNumber] = (Short_t) digit->Time();
153 // cut of ADC at MIP/2
154 if (adc[pmNumber] > (mip[pmNumber]/2))
155 mult[pmNumber] += float(adc[pmNumber])/mip[pmNumber];
35b120ff 156 } // end of loop over digits
35b120ff 157 } // end of loop over events in digits tree
158
a055ee24 159 for (Int_t j=0; j<64; j++) Multiplicity[j] = short(mult[j]+0.5);
160 fESDVZERO->SetMultiplicity(Multiplicity);
28fdf12c 161 fESDVZERO->SetADC(adc);
162 fESDVZERO->SetTime(time);
a055ee24 163
164 // now get the trigger mask
165
166 AliVZEROTriggerMask *TriggerMask = new AliVZEROTriggerMask();
167 TriggerMask->SetAdcThreshold(mip0/2.0);
168 TriggerMask->SetTimeWindowWidthBBA(50);
169 TriggerMask->SetTimeWindowWidthBGA(20);
170 TriggerMask->SetTimeWindowWidthBBC(50);
171 TriggerMask->SetTimeWindowWidthBGC(20);
172 TriggerMask->FillMasks(digitsTree,digitsArray);
173
174 fESDVZERO->SetBBtriggerV0A(TriggerMask->GetBBtriggerV0A());
175 fESDVZERO->SetBGtriggerV0A(TriggerMask->GetBGtriggerV0A());
176 fESDVZERO->SetBBtriggerV0C(TriggerMask->GetBBtriggerV0C());
177 fESDVZERO->SetBGtriggerV0C(TriggerMask->GetBGtriggerV0C());
35b120ff 178
2e0ee64a 179 if (esd) {
a055ee24 180 AliDebug(1, Form("Writing VZERO data to ESD tree"));
181 esd->SetVZEROData(fESDVZERO);
2e0ee64a 182 }
35b120ff 183}
184
ce7090f5 185//_____________________________________________________________________________
186AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
187{
ef314913 188// Sets the storage
189
ce7090f5 190 Bool_t deleteManager = kFALSE;
191
192 AliCDBManager *manager = AliCDBManager::Instance();
193 AliCDBStorage *defstorage = manager->GetDefaultStorage();
194
195 if(!defstorage || !(defstorage->Contains("VZERO"))){
196 AliWarning("No default storage set or default storage doesn't contain VZERO!");
197 manager->SetDefaultStorage(uri);
198 deleteManager = kTRUE;
199 }
200
201 AliCDBStorage *storage = manager->GetDefaultStorage();
202
203 if(deleteManager){
204 AliCDBManager::Instance()->UnsetDefaultStorage();
205 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
206 }
207
208 return storage;
209}
210
211//_____________________________________________________________________________
212AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
213{
ef314913 214 // Gets calibration object for VZERO set
ce7090f5 215
c0b82b5a 216 AliCDBManager *man = AliCDBManager::Instance();
ce7090f5 217
c0b82b5a 218 AliCDBEntry *entry=0;
219
220 entry = man->Get("VZERO/Calib/Data");
221
94a600a1 222// if(!entry){
223// AliWarning("Load of calibration data from default storage failed!");
224// AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
225// Int_t runNumber = man->GetRun();
226// entry = man->GetStorage("local://$ALICE_ROOT")
227// ->Get("VZERO/Calib/Data",runNumber);
228//
229// }
c0b82b5a 230
231 // Retrieval of data in directory VZERO/Calib/Data:
232
c0b82b5a 233 AliVZEROCalibData *calibdata = 0;
234
235 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
94a600a1 236 if (!calibdata) AliFatal("No calibration data from calibration database !");
ce7090f5 237
238 return calibdata;
239}