Adding DAQ_TEST as a trigger detector since DAQ can send inputs to CTP
[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();
44b6212f 43
ce7090f5 44}
45
46
47//_____________________________________________________________________________
48AliVZEROReconstructor& AliVZEROReconstructor::operator =
49 (const AliVZEROReconstructor& /*reconstructor*/)
50{
51// assignment operator
52
53 Fatal("operator =", "assignment operator not implemented");
54 return *this;
55}
56
57//_____________________________________________________________________________
58AliVZEROReconstructor::~AliVZEROReconstructor()
59{
60// destructor
44b6212f 61
62 delete fESDVZERO;
35b120ff 63}
64
65//_____________________________________________________________________________
d76c31f4 66void AliVZEROReconstructor::Init()
35b120ff 67{
ef314913 68// initializer
ce7090f5 69
35b120ff 70 fESDVZERO = new AliESDVZERO;
71}
72
73//______________________________________________________________________
2e0ee64a 74void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
35b120ff 75{
44b6212f 76// converts RAW to digits - pedestal is subtracted
ef314913 77
2e0ee64a 78 if (!digitsTree) {
79 AliError("No digits tree!");
80 return;
81 }
35b120ff 82
2e0ee64a 83 TClonesArray* digitsArray = new TClonesArray("AliVZEROdigit");
84 digitsTree->Branch("VZERODigit", &digitsArray);
85
86 rawReader->Reset();
87 AliVZERORawStream rawStream(rawReader);
9d62c464 88 if (rawStream.Next()) {
d0502ab2 89 Int_t ADC_max[64], adc[64], time[64], width[64], BBFlag[64], BGFlag[64];
9d62c464 90 for(Int_t i=0; i<64; i++) {
44b6212f 91 // Search for the maximum charge in the train of 21 LHC clocks
9d62c464 92 // regardless of the integrator which has been operated:
93 ADC_max[i] = 0;
d0502ab2 94 Int_t imax = 0;
9d62c464 95 for(Int_t iClock=0; iClock<21; iClock++){
96 if((Int_t)rawStream.GetPedestal(i,iClock) > ADC_max[i])
d0502ab2 97 {ADC_max[i]=(Int_t)rawStream.GetPedestal(i,iClock);
98 imax = iClock;}
9d62c464 99 }
100 // Convert i (FEE channel numbering) to j (aliroot channel numbering)
d0502ab2 101 Int_t j = rawStream.GetOfflineChannel(i);
102 adc[j] = ADC_max[i];
103 time[j] = rawStream.GetTime(i);
104 width[j] = rawStream.GetWidth(i);
105 BBFlag[j] = rawStream.GetBBFlag(i,imax);
106 BGFlag[j] = rawStream.GetBGFlag(i,imax);
9d62c464 107 }
108 // Channels(aliroot numbering) will be ordered in the tree
109 for(Int_t iChannel = 0; iChannel < 64; iChannel++) {
110 new ((*digitsArray)[digitsArray->GetEntriesFast()])
d0502ab2 111 AliVZEROdigit(iChannel, adc[iChannel], time[iChannel],
112 width[iChannel], BBFlag[iChannel], BGFlag[iChannel]);
9d62c464 113 }
2e0ee64a 114 }
115
116 digitsTree->Fill();
117}
118
119//______________________________________________________________________
120void AliVZEROReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,
b14e6eb4 121 AliESDEvent* esd) const
2e0ee64a 122{
ef314913 123// fills multiplicities to the ESD
124
2e0ee64a 125 if (!digitsTree) {
126 AliError("No digits tree!");
127 return;
128 }
a055ee24 129
2e0ee64a 130 TClonesArray* digitsArray = NULL;
131 TBranch* digitBranch = digitsTree->GetBranch("VZERODigit");
132 digitBranch->SetAddress(&digitsArray);
35b120ff 133
a055ee24 134 Short_t Multiplicity[64];
44b6212f 135 Float_t mult[64];
136 Short_t adc[64];
28fdf12c 137 Short_t time[64];
d0502ab2 138 Short_t width[64];
139 Bool_t BBFlag[64];
140 Bool_t BGFlag[64];
141
35b120ff 142 for (Int_t i=0; i<64; i++){
d0502ab2 143 adc[i] = 0;
144 mult[i] = 0.0;
145 time[i] = 0;
146 width[i] = 0;
147 BBFlag[i] = kFALSE;
148 BGFlag[i] = kFALSE;
a055ee24 149 }
35b120ff 150
a055ee24 151 // loop over VZERO entries to get multiplicity
2e0ee64a 152 Int_t nEntries = (Int_t)digitsTree->GetEntries();
35b120ff 153 for (Int_t e=0; e<nEntries; e++) {
2e0ee64a 154 digitsTree->GetEvent(e);
35b120ff 155
2e0ee64a 156 Int_t nDigits = digitsArray->GetEntriesFast();
35b120ff 157
158 for (Int_t d=0; d<nDigits; d++) {
63627899 159 AliVZEROdigit* digit = (AliVZEROdigit*)digitsArray->At(d);
160 Int_t pmNumber = digit->PMNumber();
161 // Pedestal retrieval and suppression:
162 Int_t pedestal = int(fCalibData->GetPedestal(d));
d0502ab2 163 adc[pmNumber] = (Short_t) digit->ADC() - pedestal;
164 time[pmNumber] = (Short_t) digit->Time();
165 width[pmNumber] = (Short_t) digit->Width();
166 BBFlag[pmNumber]= digit->BBFlag();
167 BGFlag[pmNumber]= digit->BGFlag();
44b6212f 168 // printf("PM = %d, MIP per ADC channel = %f \n",pmNumber, GetMIP(pmNumber));
169 // cut of ADC at 1MIP/2
170 if (adc[pmNumber] > (int(1.0/GetMIP(pmNumber)) /2) )
171 mult[pmNumber] += float(adc[pmNumber])*GetMIP(pmNumber);
35b120ff 172 } // end of loop over digits
35b120ff 173 } // end of loop over events in digits tree
174
d0502ab2 175 for (Int_t j=0; j<64; j++) Multiplicity[j] = short(mult[j]+0.5);
176
a055ee24 177 fESDVZERO->SetMultiplicity(Multiplicity);
28fdf12c 178 fESDVZERO->SetADC(adc);
179 fESDVZERO->SetTime(time);
d0502ab2 180 fESDVZERO->SetWidth(width);
181 fESDVZERO->SetBBFlag(BBFlag);
182 fESDVZERO->SetBGFlag(BGFlag);
a055ee24 183
184 // now get the trigger mask
185
186 AliVZEROTriggerMask *TriggerMask = new AliVZEROTriggerMask();
44b6212f 187 TriggerMask->SetAdcThreshold(20.0/2.0);
a055ee24 188 TriggerMask->SetTimeWindowWidthBBA(50);
189 TriggerMask->SetTimeWindowWidthBGA(20);
190 TriggerMask->SetTimeWindowWidthBBC(50);
191 TriggerMask->SetTimeWindowWidthBGC(20);
192 TriggerMask->FillMasks(digitsTree,digitsArray);
193
194 fESDVZERO->SetBBtriggerV0A(TriggerMask->GetBBtriggerV0A());
195 fESDVZERO->SetBGtriggerV0A(TriggerMask->GetBGtriggerV0A());
196 fESDVZERO->SetBBtriggerV0C(TriggerMask->GetBBtriggerV0C());
197 fESDVZERO->SetBGtriggerV0C(TriggerMask->GetBGtriggerV0C());
35b120ff 198
2e0ee64a 199 if (esd) {
44b6212f 200 AliDebug(1, Form("Writing VZERO data to ESD tree"));
201 esd->SetVZEROData(fESDVZERO);
2e0ee64a 202 }
35b120ff 203}
204
ce7090f5 205//_____________________________________________________________________________
206AliCDBStorage* AliVZEROReconstructor::SetStorage(const char *uri)
207{
ef314913 208// Sets the storage
209
ce7090f5 210 Bool_t deleteManager = kFALSE;
211
212 AliCDBManager *manager = AliCDBManager::Instance();
213 AliCDBStorage *defstorage = manager->GetDefaultStorage();
214
215 if(!defstorage || !(defstorage->Contains("VZERO"))){
216 AliWarning("No default storage set or default storage doesn't contain VZERO!");
217 manager->SetDefaultStorage(uri);
218 deleteManager = kTRUE;
219 }
220
221 AliCDBStorage *storage = manager->GetDefaultStorage();
222
223 if(deleteManager){
44b6212f 224 AliCDBManager::Instance()->UnsetDefaultStorage();
225 defstorage = 0; // the storage is killed by AliCDBManager::Instance()->Destroy()
ce7090f5 226 }
227
228 return storage;
229}
230
231//_____________________________________________________________________________
232AliVZEROCalibData* AliVZEROReconstructor::GetCalibData() const
233{
ef314913 234 // Gets calibration object for VZERO set
ce7090f5 235
c0b82b5a 236 AliCDBManager *man = AliCDBManager::Instance();
ce7090f5 237
c0b82b5a 238 AliCDBEntry *entry=0;
239
240 entry = man->Get("VZERO/Calib/Data");
241
94a600a1 242// if(!entry){
243// AliWarning("Load of calibration data from default storage failed!");
244// AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
245// Int_t runNumber = man->GetRun();
246// entry = man->GetStorage("local://$ALICE_ROOT")
247// ->Get("VZERO/Calib/Data",runNumber);
248//
249// }
c0b82b5a 250
251 // Retrieval of data in directory VZERO/Calib/Data:
252
c0b82b5a 253 AliVZEROCalibData *calibdata = 0;
254
255 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
94a600a1 256 if (!calibdata) AliFatal("No calibration data from calibration database !");
ce7090f5 257
258 return calibdata;
259}
44b6212f 260
261//_____________________________________________________________________________
262Float_t AliVZEROReconstructor::GetMIP(Int_t channel) const {
263
264// Computes the MIP conversion factor - MIP per ADC channel -
265// Argument passed is the PM number (aliroot numbering)
266
267 Float_t P0[64] = {
268 7.094891, 7.124938, 7.089708, 7.098169, 7.094482, 7.147250, 7.170978, 7.183392,
269 7.145760, 7.148096, 7.153840, 7.143544, 7.186069, 7.194580, 7.203516, 7.195176,
270 7.188333, 7.198607, 7.209412, 7.226565, 7.221695, 7.205132, 7.191238, 7.227724,
271 7.232810, 7.252655, 7.230309, 7.273518, 7.273518, 7.242969, 7.252859, 7.252655,
272 7.026802, 7.079913, 7.134147, 7.092387, 7.079561, 7.072848, 7.123192, 7.003141,
273 7.024667, 7.124784, 7.123442, 7.129744, 7.110671, 7.143031, 7.139439, 7.178109,
274 7.247803, 7.139396, 7.293809, 7.094454, 6.992198, 7.206448, 7.244765, 7.056197,
275 7.263595, 7.138569, 7.089582, 7.215683, 7.266183, 7.165123, 7.243276, 7.235135 };
276 Float_t P1[64] = {
277 0.135569, 0.146405, 0.142425, 0.144278, 0.142307, 0.141648, 0.128477, 0.138239,
278 0.144173, 0.143419, 0.143572, 0.144482, 0.138024, 0.136542, 0.135955, 0.138537,
279 0.148521, 0.141999, 0.139627, 0.130014, 0.134970, 0.135635, 0.139094, 0.140634,
280 0.137971, 0.142080, 0.142793, 0.142778, 0.142778, 0.146045, 0.139133, 0.142080,
281 0.144121, 0.142311, 0.136564, 0.142686, 0.138792, 0.166285, 0.136387, 0.155391,
282 0.176082, 0.140408, 0.164738, 0.144270, 0.142766, 0.147486, 0.141951, 0.138012,
283 0.132394, 0.142849, 0.140477, 0.144592, 0.141558, 0.157646, 0.143758, 0.173385,
284 0.146489, 0.143279, 0.145230, 0.147203, 0.147333, 0.144979, 0.148597, 0.138985 };
285
286// High Voltage retrieval from Calibration Data Base:
287 Float_t HV = fCalibData->GetMeanHV(channel);
288 Float_t MIP = 0.5/TMath::Exp((TMath::Log(HV) - P0[channel] )/P1[channel]);
289 return MIP;
290
291}