]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/EVE/AliHLTEveCalo.cxx
Created more advanced histo drawing for PHOS in alihlteve
[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 "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"
35 #include "TH2F.h"
36 #include "TH1F.h"
37
38
39
40 ClassImp(AliHLTEveCalo);
41
42 AliHLTEveCalo::AliHLTEveCalo(Int_t nm, TString name) : 
43   AliHLTEveBase(), 
44   fBoxSet(NULL),
45   fElementList(NULL),
46   fNModules(nm),
47   fName(name)
48 {
49   // Constructor.
50   for(int i = 0; i < 9; i++) {
51     fPadTitles[i] = "";
52   }
53   
54
55 }
56
57 AliHLTEveCalo::~AliHLTEveCalo()
58 {
59   //Destructor
60   if(fBoxSet)
61     delete fBoxSet;
62   fBoxSet = NULL;
63
64   if(fElementList)
65     delete fElementList;
66   fElementList = NULL;
67 }
68
69
70 void AliHLTEveCalo::ProcessBlock(AliHLTHOMERBlockDesc * block) {
71   //See header file for documentation
72
73   if ( block->GetDataType().CompareTo("ROOTHIST") == 0 ) { 
74
75     cout <<"calo histo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<< endl;
76     ProcessHistogram(block);
77    
78   } else {
79
80     if( !fElementList ) {
81       fElementList = CreateElementList();
82       fEventManager->GetEveManager()->AddElement(fElementList);
83     }
84     
85     if ( block->GetDataType().CompareTo("CALOCLUS") == 0 ){
86       //cout <<"Skipping calo clusters"<<endl;
87       ProcessClusters( block );
88     }
89     else if ( block->GetDataType().CompareTo("DIGITTYP") == 0 ) {
90       //ProcessDigits( block);
91       //
92     }
93     else if ( block->GetDataType().CompareTo("CHANNELT") == 0 ) 
94       ProcessClusters( block );
95   }
96 }
97
98 void AliHLTEveCalo::ProcessHistogram(AliHLTHOMERBlockDesc * block ) {
99   //See header file for documentation
100   
101   if(!fCanvas) {
102     fCanvas = CreateCanvas(Form("%s QA", fName.Data()), Form("%s QA", fName.Data()));
103     fCanvas->Divide(3, 3);
104   }
105
106   AddHistogramsToCanvas(block, fCanvas, fHistoCount);
107
108
109 }
110
111
112 void AliHLTEveCalo::ProcessDigits(AliHLTHOMERBlockDesc* block) {
113   //See header file for documentation
114   
115   AliHLTCaloDigitDataStruct *ds = reinterpret_cast<AliHLTCaloDigitDataStruct*> (block->GetData());
116   UInt_t nDigits = block->GetSize()/sizeof(AliHLTCaloDigitDataStruct);
117     
118
119   for(UInt_t i = 0; i < nDigits; i++, ds++) {
120
121     Float_t x = (ds->fX - 32)* 2.2;
122       Float_t z = (ds->fZ - 28) * 2.2;
123
124       cout << "MODULE DIGITTYP  :" << ds->fModule;
125
126     fBoxSet[4-ds->fModule].AddBox(x, 0, z, 2.2, ds->fEnergy*200, 2.2);
127     fBoxSet[4-ds->fModule].DigitValue(static_cast<Int_t>(ds->fEnergy*10));
128   }
129
130 }
131
132
133 void AliHLTEveCalo::ProcessClusters(AliHLTHOMERBlockDesc* block) {
134   //See header file for documentation
135
136
137   AliHLTCaloClusterHeaderStruct *dh = reinterpret_cast<AliHLTCaloClusterHeaderStruct*> (block->GetData());
138   AliHLTCaloClusterReader * clusterReader = new AliHLTCaloClusterReader();
139   clusterReader->SetMemory(dh);  
140
141   AliHLTCaloClusterDataStruct * ds;
142
143   while( (ds = clusterReader->NextCluster()) ){
144      AddClusters(ds->fGlobalPos, ds->fModule, ds->fEnergy);
145   }
146
147   AliHLTCaloDigitDataStruct *dg = clusterReader->GetDigits();
148   UInt_t nDigits = clusterReader->GetNDigits();;
149   for(UInt_t i = 0; i < nDigits; i++, dg++) {
150     AddDigits(dg->fX, dg->fZ, dg->fModule, dg->fEnergy);
151   }
152 }
153
154 void AliHLTEveCalo::UpdateElements() {
155   //See header file for documentation
156   if(fCanvas) fCanvas->Update();
157
158   if(fBoxSet) {
159     for(int im = 0; im < fNModules; im++) {
160       fBoxSet[im].ElementChanged();
161     }
162   }
163 }
164
165 void AliHLTEveCalo::ResetElements(){
166   //See header file for documentation
167   fHistoCount = 0;
168   
169   if ( fBoxSet ){
170     for(int im = 0; im < fNModules; im++){
171       cout<<"Resetting"<<endl;
172       fBoxSet[im].Reset();   
173     }
174   }
175 }
176
177 Int_t AliHLTEveCalo::GetPadNumber(TString name) {
178
179
180   cout << "GetPadNumber name   " << name << endl;
181
182   for(int i = 0; i < 9; i++) {
183     if (!fPadTitles[i].CompareTo(name)){
184       return i+1;
185     }
186     else if (!fPadTitles[i].CompareTo("")) {
187       cout <<"in empty title"<<endl;
188       fPadTitles[i] = name;
189       return i+1;
190     }
191   }
192   
193   cout << "BALLE returning default 1"<< endl;
194
195   return 1;
196
197 }
198
199 void AliHLTEveCalo::AddHistogramsToCanvas(AliHLTHOMERBlockDesc * block, TCanvas * canvas, Int_t &cdCount ) {
200   //See header file for documentation
201
202   if ( ! block->GetClassName().CompareTo("TObjArray")) {
203     TIter next((TObjArray*)(block->GetTObject()));
204     TObject *object;
205    
206     while (( object = (TObject*) next())) {
207       
208       Int_t iPad = GetPadNumber((static_cast<TH1*>(object))->GetName());
209       canvas->cd(iPad);
210
211       //Check if histo is 2D histo
212       TH2F* histo = dynamic_cast<TH2F*>(object);
213       if(histo){
214         
215         TString name = histo->GetName();
216         if(name.Contains("ClusterEnergy")) {
217           cout << "BALLE CE"<< endl;
218
219           Int_t lb = histo->FindLastBinAbove(0,1);
220           Int_t fb = histo->FindFirstBinAbove(0,1);
221
222           if(lb > -1) {
223             histo->SetAxisRange(0, histo->GetXaxis()->GetBinUpEdge(histo->FindLastBinAbove(0, 1) + 3), "X");
224             histo->SetAxisRange(0, histo->GetYaxis()->GetBinUpEdge(histo->FindLastBinAbove(0, 2) + 3), "Y");
225           }
226         } 
227         
228         else if (name.Contains("MatchDistance")) {
229           cout << "BALLE MD"<< endl;
230           Float_t min = histo->GetXaxis()->GetBinLowEdge( histo->FindFirstBinAbove(0, 1) -3 );
231           Float_t max = histo->GetXaxis()->GetBinUpEdge( histo->FindLastBinAbove(0, 1) + 3);
232           min = TMath::Abs(min);
233           if(min > max) 
234             max = min;
235           histo->SetAxisRange(-max, max, "X");
236
237           min = histo->GetYaxis()->GetBinLowEdge( histo->FindFirstBinAbove(0, 2) -3 );
238           max = histo->GetYaxis()->GetBinUpEdge( histo->FindLastBinAbove(0, 2) + 3 );
239           min = TMath::Abs(min);
240           if(min > max) 
241             max = min;
242           histo->SetAxisRange(-max, max, "Y");
243         } 
244
245         histo->Draw("COLZ");
246       }
247       
248
249       //Must be 1D histo
250       else {
251         TH1F* histo = dynamic_cast<TH1F*>(object);
252         if (histo) {
253
254           TString name = histo->GetName();
255         
256           //canvas->cd(++cdCount);
257           
258           if(name.Contains("Energy")) {
259             histo->SetAxisRange(0, histo->GetXaxis()->GetBinUpEdge(histo->FindLastBinAbove(0, 1) + 3), "X");
260           }
261
262           else if(name.Contains("InvMass")) {
263             histo->SetAxisRange(histo->GetXaxis()->GetBinLowEdge(histo->FindLastBinAbove(0, 1) - 3), histo->GetXaxis()->GetBinUpEdge(histo->FindLastBinAbove(0, 1) + 3), "X");
264           }
265
266           histo->Draw();
267         } else {
268           cout <<"AliHLTEveCaloBase::AddHistogramsTocCanvas: Histogram neither TH1F nor TH2F"<<endl;
269         }
270       }
271     }
272   }
273     
274   else if ( ! block->GetClassName().CompareTo("TH1F")) {
275
276     TH1F* histo = reinterpret_cast<TH1F*>(block->GetTObject());
277     ++cdCount;
278     canvas->cd(cdCount);
279     histo->Draw();
280     
281   } 
282   
283   else if ( ! block->GetClassName().CompareTo("TH2F")) {
284     TH2F *histo = reinterpret_cast<TH2F*>(block->GetTObject());
285     if (histo) {
286       ++cdCount;
287       canvas->cd(cdCount);
288       histo->Draw("COLZ");
289     }
290   }
291
292   canvas->cd();
293 }
294