]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/EVE/AliHLTEveCalo.cxx
8335cdd82b47d4f0ad5c70ba5eeb533e8d35bb58
[u/mrichter/AliRoot.git] / HLT / EVE / AliHLTEveCalo.cxx
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 "TCollection.h"
22 #include "TObjArray.h"
23 #include "AliHLTEveCalo.h"
24 #include "AliHLTHOMERBlockDesc.h"
25 #include "TCanvas.h"
26 #include "AliHLTEveBase.h"
27 #include "TEveBoxSet.h"
28 #include "AliPHOSGeometry.h"
29 #include "TVector3.h"
30 #include "AliEveHLTEventManager.h"
31 #include "TEveManager.h"
32 #include "AliHLTCaloDigitDataStruct.h"
33 #include "AliHLTCaloClusterDataStruct.h"
34 #include "AliHLTCaloClusterReader.h"
35 #include "TEveTrans.h"
36 #include "TString.h"
37 #include "TH2F.h"
38 #include "TH1F.h"
39 #include "TRefArray.h"
40 #include "AliESDEvent.h"
41 #include "AliESDCaloCluster.h"
42
43 ClassImp(AliHLTEveCalo);
44
45 AliHLTEveCalo::AliHLTEveCalo(Int_t nm, TString name) : 
46   AliHLTEveBase(name), 
47   fBoxSetDigits(NULL),
48   fBoxSetClusters(NULL),
49   fNModules(nm),
50   fClustersArray(NULL),
51   fName(name), 
52   fPadTitles(NULL),
53   fInvMassCanvas(NULL)
54 {
55   // Constructor.
56
57   SetMaxHistograms(6);
58
59   fPadTitles = new TString[GetMaxHistograms()];
60  
61   for(int i = 0; i < GetMaxHistograms(); i++) {
62     fPadTitles[i] = "";
63   }
64
65   fClustersArray = new TRefArray();
66
67 }
68
69 AliHLTEveCalo::~AliHLTEveCalo()
70 {
71   //Destructor
72   if(fBoxSetDigits)
73     delete fBoxSetDigits;
74   fBoxSetDigits = NULL;
75   
76   if(fBoxSetClusters)
77     delete fBoxSetClusters;
78   fBoxSetClusters = NULL;
79
80
81   if(fPadTitles)
82     delete [] fPadTitles;
83   fPadTitles = NULL;
84
85 }
86
87
88 void AliHLTEveCalo::ProcessBlock(AliHLTHOMERBlockDesc * block) {
89   //See header file for documentation
90
91   if ( block->GetDataType().CompareTo("ROOTHIST") == 0 ) { 
92     ProcessHistogram(block);
93    
94   } else {
95
96     
97     if ( block->GetDataType().CompareTo("CALOCLUS") == 0 ){
98       //cout <<"Skipping calo clusters"<<endl;
99       ProcessClusters( block );
100     } else if ( block->GetDataType().CompareTo("DIGITTYP") == 0 ) {
101       //ProcessDigits( block);
102       //
103     } else if ( block->GetDataType().CompareTo("CHANNELT") == 0 ) {
104       //ProcessClusters( block );
105     } else if (!block->GetDataType().CompareTo("ALIESDV0")) {
106       ProcessEsdBlock(block);
107     }
108   }
109 }
110
111 void AliHLTEveCalo::ProcessHistogram(AliHLTHOMERBlockDesc * block ) {
112   //See header file for documentation
113   
114   if(!fCanvas) {
115     fCanvas = CreateCanvas(Form("%s QA", fName.Data()), Form("%s QA", fName.Data()));
116     fCanvas->Divide(3, 3);
117   }
118
119   if(!fInvMassCanvas) {
120     fInvMassCanvas = CreateCanvas(Form("%s IM", fName.Data()), Form("%s IM", fName.Data()));
121     fInvMassCanvas->Divide(3, 2);
122   }
123
124
125   AddHistogramsToCanvas(block, fCanvas, fHistoCount);
126
127
128 }
129
130
131 // void AliHLTEveCalo::ProcessDigits(AliHLTHOMERBlockDesc* block) {
132 //   //See header file for documentation
133   
134 //   AliHLTCaloDigitDataStruct *ds = reinterpret_cast<AliHLTCaloDigitDataStruct*> (block->GetData());
135 //   UInt_t nDigits = block->GetSize()/sizeof(AliHLTCaloDigitDataStruct);
136     
137
138 //   for(UInt_t i = 0; i < nDigits; i++, ds++) {
139
140 //     Float_t x = (ds->fX - 32)* 2.2;
141 //       Float_t z = (ds->fZ - 28) * 2.2;
142
143
144 //     fBoxSetDigits[4-ds->fModule].AddBox(x, 0, z, 2.2, ds->fEnergy*200, 2.2);
145 //     fBoxSetDigits[4-ds->fModule].DigitValue(static_cast<Int_t>(ds->fEnergy*10));
146 //   }
147
148 // }
149
150 void AliHLTEveCalo::ProcessEsdBlock(AliHLTHOMERBlockDesc * block) {
151   AliESDEvent * event = dynamic_cast<AliESDEvent*>(block->GetTObject());
152   if (event) {
153     ProcessEvent(event);
154   } else {
155     cout << "problem getting the event!"<<endl;
156   }
157
158 }
159
160 void AliHLTEveCalo::ProcessEvent(AliESDEvent * event) {
161   //see header file for documentation
162
163
164
165   Int_t nClusters = GetClusters(event, fClustersArray);
166   for(int ic = 0; ic < nClusters; ic++) {
167     AliESDCaloCluster * cluster = dynamic_cast<AliESDCaloCluster*>(fClustersArray->At(ic));
168     ProcessESDCluster(cluster);
169   }
170   
171 }
172
173
174 void AliHLTEveCalo::ProcessClusters(AliHLTHOMERBlockDesc* block) {
175   //See header file for documentation
176
177   AliHLTCaloClusterHeaderStruct *dh = reinterpret_cast<AliHLTCaloClusterHeaderStruct*> (block->GetData());
178   AliHLTCaloClusterReader * clusterReader = new AliHLTCaloClusterReader();
179   clusterReader->SetMemory(dh);  
180
181   AliHLTCaloClusterDataStruct * ds;
182
183   while( (ds = clusterReader->NextCluster()) ){
184      AddClusters(ds->fGlobalPos, ds->fModule, ds->fEnergy);
185   }
186
187   AliHLTCaloDigitDataStruct *dg = clusterReader->GetDigits();
188   UInt_t nDigits = clusterReader->GetNDigits();;
189   for(UInt_t i = 0; i < nDigits; i++, dg++) {
190     AddDigits(dg->fX, dg->fZ, dg->fModule, dg->fEnergy);
191   }
192 }
193
194 void AliHLTEveCalo::UpdateElements() {
195   //See header file for documentation
196   if(fCanvas) fCanvas->Update();
197   if(fInvMassCanvas) fInvMassCanvas->Update();
198
199
200   if(fBoxSetDigits) {
201     for(int im = 0; im < fNModules; im++) {
202       fBoxSetDigits[im].ElementChanged();
203     }
204   }
205
206   if(fBoxSetClusters) {
207     for(int im = 0; im < fNModules; im++) {
208       fBoxSetClusters[im].ElementChanged();
209     }
210   }
211
212 }
213
214 void AliHLTEveCalo::ResetElements(){
215   //See header file for documentation
216   fHistoCount = 0;
217   
218   if ( fBoxSetDigits ){
219     for(int im = 0; im < fNModules; im++){
220       fBoxSetDigits[im].Reset();   
221     }
222   }
223
224   if ( fBoxSetClusters ){
225     for(int im = 0; im < fNModules; im++){
226       fBoxSetClusters[im].Reset();   
227     }
228   }
229
230 }
231
232 Int_t AliHLTEveCalo::GetPadNumber(TString name) {
233
234
235   //cout << "GetPadNumber name   " << name << endl;
236
237   for(int i = 0; i < GetMaxHistograms(); i++) {
238     if (!fPadTitles[i].CompareTo(name)){
239       return i+1;
240     }
241     else if (!fPadTitles[i].CompareTo("")) {
242       //cout <<"in empty title"<<endl;
243       fPadTitles[i] = name;
244       return i+1;
245     }
246   }
247   
248   if(fPadTitles[GetMaxHistograms()].CompareTo("")) {
249     cout << "AliHLTEveCalo::GetPadNumber:  We have more histograms than we have room for"<< endl;
250   }
251   return 1;
252
253 }
254
255 void AliHLTEveCalo::DrawInvMassHistogram(TH1F * histo) {
256   
257   fInvMassCanvas->cd(++fHistoCount);
258
259   histo->SetAxisRange(histo->GetXaxis()->GetBinLowEdge(histo->FindFirstBinAbove(0, 1) - 3), histo->GetXaxis()->GetBinUpEdge(histo->FindLastBinAbove(0, 1) + 3), "X");
260   histo->Fit("gaus", "", "", histo->GetXaxis()->GetBinLowEdge(histo->FindFirstBinAbove(0, 1)), histo->GetXaxis()->GetBinUpEdge(histo->FindLastBinAbove(0, 1)));
261
262   histo->Draw();
263
264 }
265
266 void AliHLTEveCalo::AddHistogramsToCanvas(AliHLTHOMERBlockDesc * block, TCanvas * canvas, Int_t &/*cdCount*/) {
267   //See header file for documentation
268
269   if ( ! block->GetClassName().CompareTo("TObjArray")) {
270     TIter next((TObjArray*)(block->GetTObject()));
271     TObject *object;
272
273
274    
275     while (( object = (TObject*) next())) {
276
277       TString name = static_cast<TH1*>(object)->GetName();
278       if(name.Contains("InvMass")){
279         DrawInvMassHistogram(static_cast<TH1F*>(object));
280         
281       } else {
282
283         
284         Int_t iPad = GetPadNumber(name);
285         canvas->cd(iPad);
286         
287         
288         //Check if histo is 2D histo
289         TH2F* histo2 = dynamic_cast<TH2F*>(object);
290         if(histo2){
291           
292           Int_t lb = histo2->FindLastBinAbove(0,1);
293           if(lb > -1) {
294             histo2->SetAxisRange(0, histo2->GetXaxis()->GetBinUpEdge(histo2->FindLastBinAbove(0, 1) + 3), "X");
295             histo2->SetAxisRange(0, histo2->GetYaxis()->GetBinUpEdge(histo2->FindLastBinAbove(0, 2) + 3), "Y");
296           }
297           
298           histo2->Draw("COLZ");
299         }
300         
301         
302         //Must be 1D histo
303         else {
304           TH1F* histo = dynamic_cast<TH1F*>(object);
305           if (histo) {
306             
307             TString name2 = histo->GetName();
308             
309             if(name2.Contains("Energy")) {
310               histo->SetAxisRange(0, histo->GetXaxis()->GetBinUpEdge(histo->FindLastBinAbove(0, 1) + 3), "X");
311             }
312             
313             
314             histo->Draw();
315           } else {
316             cout <<"AliHLTEveCaloBase::AddHistogramsTocCanvas: Histogram neither TH1F nor TH2F"<<endl;
317           }
318         }
319       }
320     }
321
322   } else if ( ! block->GetClassName().CompareTo("TH1F")) {
323
324     TH1F* histo = reinterpret_cast<TH1F*>(block->GetTObject());
325     if(histo) {
326       
327       Int_t iPad = GetPadNumber(histo->GetName());
328       canvas->cd(iPad);
329       histo->Draw();
330     }
331   
332   
333   } else if ( ! block->GetClassName().CompareTo("TH2F")) {
334     
335     TH2F *histo = reinterpret_cast<TH2F*>(block->GetTObject());
336     if(histo) {
337       
338       Int_t iPad = GetPadNumber(histo->GetName());
339       canvas->cd(iPad);
340       histo->Draw();
341     }
342
343
344   }
345   
346   canvas->cd();
347 }
348