reverting r42022, changes to be committed separately in order to disentangle backporting
[u/mrichter/AliRoot.git] / HLT / EVE / AliHLTEveCalo.cxx
CommitLineData
33791895 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Primary Authors: Svein Lindal <slindal@fys.uio.no > *
6 * for The ALICE HLT Project. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/// @file AliHLTEveCalo.cxx
18/// @author Svein Lindal <slindal@fys.uio.no>
19/// @brief Calorimeter base class for the HLT EVE display
20
21#include "AliHLTEveCalo.h"
22#include "AliHLTHOMERBlockDesc.h"
23#include "TCanvas.h"
24#include "AliHLTEveBase.h"
25#include "TEveBoxSet.h"
26#include "AliPHOSGeometry.h"
27#include "TVector3.h"
28#include "AliEveHOMERManager.h"
29#include "TEveManager.h"
30#include "AliHLTCaloDigitDataStruct.h"
31#include "AliHLTCaloClusterDataStruct.h"
32#include "AliHLTCaloClusterReader.h"
33#include "TEveTrans.h"
34#include "TString.h"
e77bc5e0 35#include "TH2F.h"
36#include "TH1F.h"
37
38
33791895 39
40ClassImp(AliHLTEveCalo);
41
42AliHLTEveCalo::AliHLTEveCalo(Int_t nm, TString name) :
43 AliHLTEveBase(),
9374a7f9 44 fBoxSetDigits(NULL),
45 fBoxSetClusters(NULL),
33791895 46 fElementList(NULL),
47 fNModules(nm),
3d600a8b 48 fName(name),
3fe4881e 49 fPadTitles(NULL),
50 fInvMassCanvas(NULL)
33791895 51{
52 // Constructor.
3d600a8b 53
3fe4881e 54 SetMaxHistograms(6);
3d600a8b 55
56 fPadTitles = new TString[GetMaxHistograms()];
3fe4881e 57
3d600a8b 58 for(int i = 0; i < GetMaxHistograms(); i++) {
e77bc5e0 59 fPadTitles[i] = "";
60 }
3fe4881e 61
e77bc5e0 62
33791895 63}
64
65AliHLTEveCalo::~AliHLTEveCalo()
66{
67 //Destructor
9374a7f9 68 if(fBoxSetDigits)
69 delete fBoxSetDigits;
70 fBoxSetDigits = NULL;
bc1a13f1 71
9374a7f9 72 if(fBoxSetClusters)
73 delete fBoxSetClusters;
74 fBoxSetClusters = NULL;
33791895 75
bc1a13f1 76 if(fElementList) {
77
33791895 78 delete fElementList;
bc1a13f1 79 }
33791895 80 fElementList = NULL;
3fe4881e 81
82 if(fPadTitles)
83 delete [] fPadTitles;
84 fPadTitles = NULL;
85
33791895 86}
87
88
89void AliHLTEveCalo::ProcessBlock(AliHLTHOMERBlockDesc * block) {
90 //See header file for documentation
91
92 if ( block->GetDataType().CompareTo("ROOTHIST") == 0 ) {
93 ProcessHistogram(block);
94
95 } else {
96
97 if( !fElementList ) {
98 fElementList = CreateElementList();
99 fEventManager->GetEveManager()->AddElement(fElementList);
100 }
101
102 if ( block->GetDataType().CompareTo("CALOCLUS") == 0 ){
103 //cout <<"Skipping calo clusters"<<endl;
104 ProcessClusters( block );
105 }
db76648f 106 else if ( block->GetDataType().CompareTo("DIGITTYP") == 0 ) {
107 //ProcessDigits( block);
108 //
109 }
33791895 110 else if ( block->GetDataType().CompareTo("CHANNELT") == 0 )
111 ProcessClusters( block );
112 }
113}
114
115void AliHLTEveCalo::ProcessHistogram(AliHLTHOMERBlockDesc * block ) {
116 //See header file for documentation
117
118 if(!fCanvas) {
119 fCanvas = CreateCanvas(Form("%s QA", fName.Data()), Form("%s QA", fName.Data()));
3fe4881e 120 fCanvas->Divide(3, 2);
33791895 121 }
122
3fe4881e 123 if(!fInvMassCanvas) {
124 fInvMassCanvas = CreateCanvas(Form("%s IM", fName.Data()), Form("%s IM", fName.Data()));
125 fInvMassCanvas->Divide(3, 2);
126 }
127
128
33791895 129 AddHistogramsToCanvas(block, fCanvas, fHistoCount);
130
131
132}
133
134
9374a7f9 135// void AliHLTEveCalo::ProcessDigits(AliHLTHOMERBlockDesc* block) {
136// //See header file for documentation
33791895 137
9374a7f9 138// AliHLTCaloDigitDataStruct *ds = reinterpret_cast<AliHLTCaloDigitDataStruct*> (block->GetData());
139// UInt_t nDigits = block->GetSize()/sizeof(AliHLTCaloDigitDataStruct);
33791895 140
141
9374a7f9 142// for(UInt_t i = 0; i < nDigits; i++, ds++) {
33791895 143
9374a7f9 144// Float_t x = (ds->fX - 32)* 2.2;
145// Float_t z = (ds->fZ - 28) * 2.2;
33791895 146
33791895 147
9374a7f9 148// fBoxSetDigits[4-ds->fModule].AddBox(x, 0, z, 2.2, ds->fEnergy*200, 2.2);
149// fBoxSetDigits[4-ds->fModule].DigitValue(static_cast<Int_t>(ds->fEnergy*10));
150// }
33791895 151
9374a7f9 152// }
33791895 153
154
155void AliHLTEveCalo::ProcessClusters(AliHLTHOMERBlockDesc* block) {
156 //See header file for documentation
157
158
159 AliHLTCaloClusterHeaderStruct *dh = reinterpret_cast<AliHLTCaloClusterHeaderStruct*> (block->GetData());
160 AliHLTCaloClusterReader * clusterReader = new AliHLTCaloClusterReader();
161 clusterReader->SetMemory(dh);
162
163 AliHLTCaloClusterDataStruct * ds;
164
33791895 165 while( (ds = clusterReader->NextCluster()) ){
db76648f 166 AddClusters(ds->fGlobalPos, ds->fModule, ds->fEnergy);
33791895 167 }
168
169 AliHLTCaloDigitDataStruct *dg = clusterReader->GetDigits();
170 UInt_t nDigits = clusterReader->GetNDigits();;
171 for(UInt_t i = 0; i < nDigits; i++, dg++) {
172 AddDigits(dg->fX, dg->fZ, dg->fModule, dg->fEnergy);
173 }
174}
175
176void AliHLTEveCalo::UpdateElements() {
177 //See header file for documentation
178 if(fCanvas) fCanvas->Update();
3fe4881e 179 if(fInvMassCanvas) fInvMassCanvas->Update();
180
33791895 181
9374a7f9 182 if(fBoxSetDigits) {
183 for(int im = 0; im < fNModules; im++) {
184 fBoxSetDigits[im].ElementChanged();
185 }
186 }
187
188 if(fBoxSetClusters) {
33791895 189 for(int im = 0; im < fNModules; im++) {
9374a7f9 190 fBoxSetClusters[im].ElementChanged();
33791895 191 }
192 }
9374a7f9 193
33791895 194}
195
196void AliHLTEveCalo::ResetElements(){
197 //See header file for documentation
198 fHistoCount = 0;
199
9374a7f9 200 if ( fBoxSetDigits ){
33791895 201 for(int im = 0; im < fNModules; im++){
9374a7f9 202 fBoxSetDigits[im].Reset();
33791895 203 }
204 }
9374a7f9 205
206 if ( fBoxSetClusters ){
207 for(int im = 0; im < fNModules; im++){
208 fBoxSetClusters[im].Reset();
209 }
210 }
211
33791895 212}
e77bc5e0 213
214Int_t AliHLTEveCalo::GetPadNumber(TString name) {
215
216
3d600a8b 217 //cout << "GetPadNumber name " << name << endl;
e77bc5e0 218
3d600a8b 219 for(int i = 0; i < GetMaxHistograms(); i++) {
e77bc5e0 220 if (!fPadTitles[i].CompareTo(name)){
221 return i+1;
222 }
223 else if (!fPadTitles[i].CompareTo("")) {
3d600a8b 224 //cout <<"in empty title"<<endl;
e77bc5e0 225 fPadTitles[i] = name;
226 return i+1;
227 }
228 }
229
3d600a8b 230 if(fPadTitles[GetMaxHistograms()].CompareTo("")) {
231 cout << "AliHLTEveCalo::GetPadNumber: We have more histograms than we have room for"<< endl;
232 }
e77bc5e0 233 return 1;
234
235}
236
3fe4881e 237void AliHLTEveCalo::DrawInvMassHistogram(TH1F * histo) {
238
239 fInvMassCanvas->cd(++fHistoCount);
240
241 histo->SetAxisRange(histo->GetXaxis()->GetBinLowEdge(histo->FindFirstBinAbove(0, 1) - 3), histo->GetXaxis()->GetBinUpEdge(histo->FindLastBinAbove(0, 1) + 3), "X");
242 histo->Fit("gaus", "", "", histo->GetXaxis()->GetBinLowEdge(histo->FindFirstBinAbove(0, 1)), histo->GetXaxis()->GetBinUpEdge(histo->FindLastBinAbove(0, 1)));
243
244 histo->Draw();
245
246}
247
9328177e 248void AliHLTEveCalo::AddHistogramsToCanvas(AliHLTHOMERBlockDesc * block, TCanvas * canvas, Int_t &/*cdCount*/) {
e77bc5e0 249 //See header file for documentation
250
251 if ( ! block->GetClassName().CompareTo("TObjArray")) {
252 TIter next((TObjArray*)(block->GetTObject()));
253 TObject *object;
e77bc5e0 254
3d600a8b 255
3fe4881e 256
257 while (( object = (TObject*) next())) {
e77bc5e0 258
3fe4881e 259 TString name = static_cast<TH1*>(object)->GetName();
260 if(name.Contains("InvMass")){
261 DrawInvMassHistogram(static_cast<TH1F*>(object));
e77bc5e0 262
3fe4881e 263 } else {
e77bc5e0 264
3fe4881e 265
266 Int_t iPad = GetPadNumber(name);
267 canvas->cd(iPad);
268
269
270 //Check if histo is 2D histo
271 TH2F* histo2 = dynamic_cast<TH2F*>(object);
272 if(histo2){
e77bc5e0 273
3fe4881e 274 Int_t lb = histo2->FindLastBinAbove(0,1);
275 if(lb > -1) {
276 histo2->SetAxisRange(0, histo2->GetXaxis()->GetBinUpEdge(histo2->FindLastBinAbove(0, 1) + 3), "X");
277 histo2->SetAxisRange(0, histo2->GetYaxis()->GetBinUpEdge(histo2->FindLastBinAbove(0, 2) + 3), "Y");
e77bc5e0 278 }
3fe4881e 279
280 histo2->Draw("COLZ");
281 }
282
283
284 //Must be 1D histo
285 else {
286 TH1F* histo = dynamic_cast<TH1F*>(object);
287 if (histo) {
288
d7ef992b 289 TString name = histo->GetName();
3fe4881e 290
d7ef992b 291 if(name.Contains("Energy")) {
3fe4881e 292 histo->SetAxisRange(0, histo->GetXaxis()->GetBinUpEdge(histo->FindLastBinAbove(0, 1) + 3), "X");
293 }
294
295
296 histo->Draw();
297 } else {
298 cout <<"AliHLTEveCaloBase::AddHistogramsTocCanvas: Histogram neither TH1F nor TH2F"<<endl;
e77bc5e0 299 }
e77bc5e0 300 }
301 }
302 }
3d600a8b 303
304 } else if ( ! block->GetClassName().CompareTo("TH1F")) {
e77bc5e0 305
306 TH1F* histo = reinterpret_cast<TH1F*>(block->GetTObject());
3d600a8b 307 if(histo) {
308
309 Int_t iPad = GetPadNumber(histo->GetName());
310 canvas->cd(iPad);
311 histo->Draw();
312 }
e77bc5e0 313
3d600a8b 314
315 } else if ( ! block->GetClassName().CompareTo("TH2F")) {
316
e77bc5e0 317 TH2F *histo = reinterpret_cast<TH2F*>(block->GetTObject());
3d600a8b 318 if(histo) {
319
320 Int_t iPad = GetPadNumber(histo->GetName());
321 canvas->cd(iPad);
322 histo->Draw();
e77bc5e0 323 }
e77bc5e0 324
3d600a8b 325
326 }
327
e77bc5e0 328 canvas->cd();
329}
330