- adding the use of the histogram merger
[u/mrichter/AliRoot.git] / HLT / EVE / AliHLTEveMultCorr.cxx
1 #include "AliHLTEveMultCorr.h"
2 #include "TH1F.h"
3 #include "TH2F.h"
4 #include <iostream>
5 #include <TCanvas.h>
6 #include "AliHLTHOMERBlockDesc.h"
7 #include "AliHLTEveHistoMerger.h"
8 #include "TList.h"
9 #include "AliLog.h"
10
11 AliHLTEveMultCorr::AliHLTEveMultCorr(const char* name): AliHLTEveBase(name)
12         ,fVzeroMultCanvas(0)
13         ,fZdcMultCanvas(0)
14         ,fTrackMultCanvas(0)
15         ,fCorrCanvas(0)
16         ,fEtCorrCanvas(0)
17         ,fZdcVzeroSpdCorrCanvas(0)
18         ,fMerger(0)
19         ,fMyList(0)
20 {
21   fMerger = new AliHLTEveHistoMerger();
22 }
23
24 AliHLTEveMultCorr::~AliHLTEveMultCorr()
25 {
26   if(fMerger)
27   {
28     delete fMerger;
29   }
30   if(fMyList)
31   {
32     delete fMyList;
33   }
34 }
35
36 void AliHLTEveMultCorr::ResetElements()
37 {
38
39 }
40
41 void AliHLTEveMultCorr::UpdateElements()
42 {
43     fVzeroMultCanvas->Update();
44     fZdcMultCanvas->Update();
45     fTrackMultCanvas->Update();
46     fCorrCanvas->Update();
47     fEtCorrCanvas->Update();
48     fZdcVzeroSpdCorrCanvas->Update();
49
50 }
51
52 void AliHLTEveMultCorr::ProcessBlock(AliHLTHOMERBlockDesc* block)
53 {
54     TString msg;
55     
56     TList *hlist = dynamic_cast<TList*>(block->GetTObject());
57     if(kFALSE)
58     {
59       hlist = dynamic_cast<TList*>(fMerger->Process(hlist, block->GetSpecification()));
60     }
61     else
62     {
63       if(fMyList)
64       {
65         delete fMyList;
66         fMyList = 0;
67       }
68       fMyList = dynamic_cast<TList*>(hlist->Clone());
69       hlist = fMyList;
70     }
71     if (hlist)
72     {
73
74         if (hlist->Contains("fVzeroMult")) // These are the correlation histograms
75         {
76             TH1F *oneDf = 0;
77             TH2F *twoDf = 0;
78             int cd = 1;
79
80             //VZERO multiplicity hists
81             if (!fVzeroMultCanvas) 
82             {
83               fVzeroMultCanvas = CreateCanvas("V0 M", "V0 Multiplicities");
84               fVzeroMultCanvas->Divide(2, 2);
85             }
86             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fVzeroMult"));
87             AddHistogramToCanvas(oneDf, fVzeroMultCanvas, cd);
88             cd++;
89             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fVzeroMultAC"));
90             AddHistogramToCanvas(twoDf, fVzeroMultCanvas, cd);
91             cd++;
92             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fVzeroFlaggedMult"));
93             AddHistogramToCanvas(oneDf, fVzeroMultCanvas, cd);
94             cd++;
95             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fVzeroFlaggedMultAC"));
96             AddHistogramToCanvas(twoDf, fVzeroMultCanvas, cd);
97
98             cd = 1;
99             //ZDC multiplicity hists
100             if (!fZdcMultCanvas) 
101             {
102               fZdcMultCanvas = CreateCanvas("ZDC M", "ZDC Multiplicities");
103               fZdcMultCanvas->Divide(3, 3);
104             }
105             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fZdcEzdc"));
106             AddHistogramToCanvas(oneDf, fZdcMultCanvas, cd);
107             cd++;
108             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fZdcEzn"));
109             AddHistogramToCanvas(oneDf, fZdcMultCanvas, cd);
110             cd++;
111             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fZdcEzp"));
112             AddHistogramToCanvas(oneDf, fZdcMultCanvas, cd);
113             cd++;
114             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fZdcEzem"));
115             AddHistogramToCanvas(oneDf, fZdcMultCanvas, cd);
116             cd++;
117             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fZdcNpart"));
118             AddHistogramToCanvas(oneDf, fZdcMultCanvas, cd);
119             cd++;
120             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fZdcB"));
121             AddHistogramToCanvas(oneDf, fZdcMultCanvas, cd);
122             cd++;
123             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fZdcEzemEzdc"));
124             AddHistogramToCanvas(twoDf, fZdcMultCanvas, cd);
125
126             cd = 1;
127             // TPC multiplicity
128             if (!fTrackMultCanvas) 
129             {
130               fTrackMultCanvas = CreateCanvas("Track M", "Track Multiplicities");
131               fTrackMultCanvas->Divide(2, 2);
132             }
133             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fTpcNch2"));
134             AddHistogramToCanvas(oneDf, fTrackMultCanvas, cd);
135             cd++;
136             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fTpcNch3"));
137             AddHistogramToCanvas(oneDf, fTrackMultCanvas, cd);
138             cd++;
139             oneDf = dynamic_cast<TH1F*>(FindHistogram(hlist, "fSpdNClusters"));
140             
141             AddHistogramToCanvas(oneDf, fTrackMultCanvas, cd);
142
143             cd = 1;
144             // Correlations
145             if (!fCorrCanvas) 
146             {
147               fCorrCanvas = CreateCanvas("Corr", "Multiplicity Correlations");
148               fCorrCanvas->Divide(3, 2);
149             }
150             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrEzdcNch"));
151             AddHistogramToCanvas(twoDf, fCorrCanvas, cd);
152             cd++;
153             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrVzeroNch"));
154             AddHistogramToCanvas(twoDf, fCorrCanvas, cd);
155             cd++;
156             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrSpdTpcNch"));
157             AddHistogramToCanvas(twoDf, fCorrCanvas, cd);
158             cd++;
159             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrEzemNch"));
160             AddHistogramToCanvas(twoDf, fCorrCanvas, cd);
161             cd++;
162             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrEzdcVzero"));
163             AddHistogramToCanvas(twoDf, fCorrCanvas, cd);
164             cd++;
165             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrEzemVzero"));
166             AddHistogramToCanvas(twoDf, fCorrCanvas, cd);
167             
168             cd = 1;
169             // ET Correlations
170             if (!fEtCorrCanvas) 
171             {
172               fEtCorrCanvas = CreateCanvas("ET", "E_{T} Correlations");
173               fEtCorrCanvas->Divide(3, 2);
174             }
175             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrZdcTotEvsPhosTotEt"));
176             AddHistogramToCanvas(twoDf, fEtCorrCanvas, cd);
177             cd++;
178             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrZdcTotEvsEmcalTotEt"));
179             AddHistogramToCanvas(twoDf, fEtCorrCanvas, cd);
180             cd++;
181             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrZdcTotEvsTotEt"));
182             AddHistogramToCanvas(twoDf, fEtCorrCanvas, cd);
183             cd++;
184             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrVzerovsPhosTotEt"));
185             AddHistogramToCanvas(twoDf, fEtCorrCanvas, cd);
186             cd++;
187             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrVzerovsEmcalTotEt"));
188             AddHistogramToCanvas(twoDf, fEtCorrCanvas, cd);
189             cd++;
190             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrVzerovsTotEt"));
191             AddHistogramToCanvas(twoDf, fEtCorrCanvas, cd);
192
193             cd = 1;
194             // ZDC,V0 vs SPD
195             if (!fZdcVzeroSpdCorrCanvas) 
196             {
197               fZdcVzeroSpdCorrCanvas = CreateCanvas("ZDC/V0 vs SPD", "ZDC/V0 vs. SPD");
198               fZdcVzeroSpdCorrCanvas->Divide(3, 2);
199               
200             }
201             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrVzeroSpd"));
202             AddHistogramToCanvas(twoDf, fZdcVzeroSpdCorrCanvas, cd);
203             cd++;
204             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrVzeroASpd"));
205             AddHistogramToCanvas(twoDf, fZdcVzeroSpdCorrCanvas, cd);
206             cd++;
207             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrVzeroCSpd"));
208             AddHistogramToCanvas(twoDf, fZdcVzeroSpdCorrCanvas, cd);
209             cd++;
210             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrEzdcSpd"));
211             AddHistogramToCanvas(twoDf, fZdcVzeroSpdCorrCanvas, cd);
212             cd++;
213             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrEzdcASpd"));
214             AddHistogramToCanvas(twoDf, fZdcVzeroSpdCorrCanvas, cd);
215             cd++;
216             twoDf = dynamic_cast<TH2F*>(FindHistogram(hlist, "fCorrEzdcCSpd"));
217             AddHistogramToCanvas(twoDf, fZdcVzeroSpdCorrCanvas, cd);
218         }
219         else
220         {
221             AliWarning("This block does not contain what you think it contains!");
222         }
223     }
224     else
225     {
226       AliWarning("There is no TList object in the block");
227     }
228
229
230 }
231
232 void AliHLTEveMultCorr::AddHistogramsToCanvas(AliHLTHOMERBlockDesc* /*block*/, TCanvas* /*canvas*/, Int_t& /*cdCount*/)
233 {
234 }
235
236 void AliHLTEveMultCorr::AddHistogramToCanvas(TH1* hist, TCanvas* canvas, Int_t& cdCount, Bool_t zoom)
237 {
238   
239   TString msg;
240     if (hist)
241     {
242         if (!strcmp(hist->ClassName(), "TH1F"))
243         {
244             canvas->cd(cdCount);
245             TPad * pad = dynamic_cast<TPad*>(canvas->cd(cdCount));
246             pad->SetLogy();
247             if(zoom) 
248             {
249               TH1F *h = dynamic_cast<TH1F*>(hist);
250               h->GetXaxis()->SetRange(0, h->GetMaximumBin() + h->GetMaximumBin()*0.2);
251             }
252             dynamic_cast<TH1F*>(hist)->Draw();
253         }
254         else if (!strcmp(hist->ClassName(), "TH2F"))
255         {
256             canvas->cd(cdCount);
257             if(zoom)
258             {
259               TH2F *h = dynamic_cast<TH2F*>(hist);
260               h->GetXaxis()->SetRange(0, h->GetMaximumBin() + h->GetMaximumBin()*0.2);
261               h->GetYaxis()->SetRange(0, h->GetMaximumBin() + h->GetMaximumBin()*0.2);
262             }
263             dynamic_cast<TH2F*>(hist)->Draw("COLZ");
264         }
265         else
266         {       
267           msg.Form("I don't want histograms of type %s", hist->ClassName());
268           AliWarning(msg.Data());
269         }
270     }
271     else
272     {
273       AliWarning("You gave me a null pointer!");
274     }
275 }
276
277 TH1* AliHLTEveMultCorr::FindHistogram(TCollection* coll, const char* name)
278 {
279   TString msg;
280   TH1 *hist = dynamic_cast<TH1*>(coll->FindObject(name));
281   if(!hist)
282   {
283     msg.Form("Could not find object %s", name);
284     AliWarning(msg);
285   }
286   return hist;
287 }