Merge branch 'feature-parfiles'
[u/mrichter/AliRoot.git] / AD / ADrec / AliADReconstructor.cxx
CommitLineData
5e319bd5 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: AliADReconstructor.cxx 20956 2007-09-26 14:22:18Z mrodrigu $ */
17//////////////////////////////////////////////////////////////////////////////
18// //
19// Class for AD reconstruction //
20//////////////////////////////////////////////////////////////////////////////
fcb6ff8b 21#include <TParameter.h>
5e319bd5 22
23#include "AliRawReader.h"
fcb6ff8b 24#include "AliGRPObject.h"
25#include "AliCDBManager.h"
26#include "AliCDBStorage.h"
27#include "AliCDBEntry.h"
28#include "AliESDEvent.h"
5e319bd5 29
30#include "AliADReconstructor.h"
5e319bd5 31#include "AliADdigit.h"
7b752923 32#include "AliESDAD.h"
fcb6ff8b 33#include "AliADConst.h"
34#include "AliADCalibData.h"
35#include "AliADRawStream.h"
5e319bd5 36
37ClassImp(AliADReconstructor)
fcb6ff8b 38//_____________________________________________________________________________
5e319bd5 39AliADReconstructor:: AliADReconstructor():
40 AliReconstructor(),
41 fESDAD(0x0),
fcb6ff8b 42 fCalibData(NULL),
5e319bd5 43 fDigitsArray(0)
fcb6ff8b 44
5e319bd5 45{
fcb6ff8b 46 fCalibData = GetCalibData();
5e319bd5 47 // Default constructor
48 // Get calibration data
49
50}
51
52//_____________________________________________________________________________
53AliADReconstructor& AliADReconstructor::operator =
54 (const AliADReconstructor& /*reconstructor*/)
55{
56// assignment operator
57
58 Fatal("operator =", "assignment operator not implemented");
59 return *this;
60}
61
62//_____________________________________________________________________________
63AliADReconstructor::~AliADReconstructor()
64{
65// destructor
66 delete fESDAD;
67 delete fDigitsArray;
68}
69
70//_____________________________________________________________________________
71void AliADReconstructor::Init()
72{
73// initializer
74 fESDAD = new AliESDAD;
75}
76
fcb6ff8b 77//_____________________________________________________________________________
78void AliADReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
5e319bd5 79{
fcb6ff8b 80// converts RAW to digits
81
82 if (!digitsTree) {
83 AliError("No digits tree!");
84 return;
85 }
86
87 if (!fDigitsArray){
88 fDigitsArray = new TClonesArray("AliADdigit", 16);
89 digitsTree->Branch("ADDigit", &fDigitsArray);
90 }
91
92 rawReader->Reset();
93 AliADRawStream rawStream(rawReader);
94 if (rawStream.Next()) {
95
fcb6ff8b 96 for(Int_t iChannel=0; iChannel < 16; ++iChannel) {
97 Int_t offlineCh = rawStream.GetOfflineChannel(iChannel);
98 // ADC charge samples
99 Short_t chargeADC[kNClocks];
100 for(Int_t iClock=0; iClock < kNClocks; ++iClock) {
101 chargeADC[iClock] = rawStream.GetPedestal(iChannel,iClock);
102 }
103 // Integrator flag
104 Bool_t integrator = rawStream.GetIntegratorFlag(iChannel,kNClocks/2);
a67ec576 105 Bool_t BBflag = rawStream.GetBBFlag(iChannel,kNClocks/2);
106 Bool_t BGflag = rawStream.GetBGFlag(iChannel,kNClocks/2);
107
fcb6ff8b 108 // HPTDC data (leading time and width)
109 Int_t board = AliADCalibData::GetBoardNumber(offlineCh);
110 Float_t time = rawStream.GetTime(iChannel)*fCalibData->GetTimeResolution(board);
111 Float_t width = rawStream.GetWidth(iChannel)*fCalibData->GetWidthResolution(board);
112 // Add a digit
113 if(!fCalibData->IsChannelDead(iChannel)){
a67ec576 114 new ((*fDigitsArray)[fDigitsArray->GetEntriesFast()]) AliADdigit(offlineCh, time, width,integrator, chargeADC, BBflag, BGflag);
fcb6ff8b 115 }
116 }
fcb6ff8b 117
118 digitsTree->Fill();
119 }
120
121 fDigitsArray->Clear();
5e319bd5 122
5e319bd5 123}
124
fcb6ff8b 125//_____________________________________________________________________________
5e319bd5 126void AliADReconstructor::FillESD(TTree* digitsTree, TTree* /*clustersTree*/,AliESDEvent* esd) const
127{
128
129 printf("Running AD Reconstruction \n");
130
131 // fills ESD with AD Digits
132
133 if (!digitsTree)
134 {
135 AliError("No digits tree!");
136 return;
137 }
138
139 TBranch* digitBranch = digitsTree->GetBranch("ADdigit");
140 if (!digitBranch) {
141 AliError("No AD digits branch found!");
142 return;
143 }
144 digitBranch->SetAddress(&fDigitsArray);
145
146 digitsTree->GetEvent(0);
147
148 Bool_t ADHits[16];
149 for(Int_t i = 0; i < 16; i++) { ADHits[i] = kFALSE; }
150
151 Int_t nDigits = fDigitsArray->GetEntriesFast();
152
153 for (Int_t d=0; d<nDigits; d++) {
154 AliADdigit* digit = (AliADdigit*) fDigitsArray->At(d);
aa8120bb 155 Int_t module = digit->PMNumber();
5e319bd5 156 // printf("AD Module: %d\n",module);
157 ADHits[module] = kTRUE;
158 }
159 if (!esd) {
160 AliError("NO AD ESD branch found!");
161 return;
162}
6ab3a0cd 163 //fESDAD->SetADBitCell(ADHits);
5e319bd5 164
165 if (esd)
166 {
167 AliDebug(1, Form("Writing AD data to ESD Tree"));
168 esd->SetADData(fESDAD);
169 }
170
171 fDigitsArray->Clear();
172}
173
fcb6ff8b 174//_____________________________________________________________________________
175AliADCalibData* AliADReconstructor::GetCalibData() const
176{
177 AliCDBManager *man = AliCDBManager::Instance();
178
179 AliCDBEntry *entry=0;
180
181 //entry = man->Get("AD/Calib/Data");
182 //if(!entry){
183 //AliWarning("Load of calibration data from default storage failed!");
184 //AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
185
186 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
187 man->SetRun(1);
188 entry = man->Get("AD/Calib/Data");
189 //}
190 // Retrieval of data in directory AD/Calib/Data:
191
192 AliADCalibData *calibdata = 0;
193
194 if (entry) calibdata = (AliADCalibData*) entry->GetObject();
195 if (!calibdata) AliFatal("No calibration data from calibration database !");
196
197 return calibdata;
198}
199
5e319bd5 200