end-of-line normalization
[u/mrichter/AliRoot.git] / HLT / QA / tasks / AliAnalysisTaskHLTCalo.cxx
CommitLineData
7fac8669 1// $Id: AliAnalysisTaskHLTCalo.cxx 40285 2010-04-09 14:04:51Z kkanaki $
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Zhongbao Yin <zbyin@mail.ccnu.edu.cn>, *
8//* Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> *
9//* for The ALICE HLT Project. *
10//* *
11//* Permission to use, copy, modify and distribute this software and its *
12//* documentation strictly for non-commercial purposes is hereby granted *
13//* without fee, provided that the above copyright notice appears in all *
14//* copies and that both the copyright notice and this permission notice *
15//* appear in the supporting documentation. The authors make no claims *
16//* about the suitability of this software for any purpose. It is *
17//* provided "as is" without express or implied warranty. *
18//**************************************************************************
19
20/** @file AliAnalysisTaskHLTCalo.cxx
21 @author Zhongbao Yin, Kalliopi Kanaki, Svein Lindal
22 @date
23 @brief
24*/
25
26#include <iostream>
27
28#include "TChain.h"
29#include "TTree.h"
30#include "TH1F.h"
31#include "TH2F.h"
32#include "TCanvas.h"
33#include "TVector3.h"
34#include "TString.h"
35#include "TObjArray.h"
36#include "TFile.h"
37#include "TList.h"
38#include "TRefArray.h"
39
40#include "AliESDEvent.h"
41#include "AliESDRun.h"
42#include "AliESDInputHandler.h"
43#include "AliESDCaloCluster.h"
44#include "AliESDtrack.h"
45#include "AliAnalysisTask.h"
46#include "AliAnalysisManager.h"
47#include "AliAnalysisTaskHLTCalo.h"
48
49#include "AliHLTCaloHistoInvMass.h"
50#include "AliHLTCaloHistoClusterEnergy.h"
51#include "AliHLTCaloHistoMatchedTracks.h"
52#include "AliHLTCaloHistoProducer.h"
53
54#include "AliHLTGlobalTriggerDecision.h"
55
56ClassImp(AliAnalysisTaskHLTCalo)
57
58//===========================================================================================
59
60AliAnalysisTaskHLTCalo::AliAnalysisTaskHLTCalo() : AliAnalysisTaskSE()
61 ,fUseHLTTrigger(kFALSE)
62 ,fESDRun(0)
63 ,fOutputList(0)
64 ,fHistOfflResiduals(NULL)
65 ,fHistOnlResiduals(NULL)
66 ,fHistOfflDz(NULL)
67 ,fHistOnlDz(NULL)
68 ,fHistOfflDxy(NULL)
69 ,fHistOnlDxy(NULL)
70 ,fNevt(0)
71 ,fTrgClsArray(0)
72 ,fGlobalHistoProdArrOff(NULL)
73 ,fGlobalHistoProdArrOn(NULL)
74 ,fClustersArray(NULL)
75 ,fCaloName("")
76{
77 // Constructor
78
79 // Define input and output slots here
80 // Input slot #0 works with a TChain
81 // DefineInput(0, TChain::Class());
82 // Output slot #0 writes into a TH1 container
83
84 //DefineOutput(1, TList::Class());
85}
86
87AliAnalysisTaskHLTCalo::AliAnalysisTaskHLTCalo(const char *name)
88:
89AliAnalysisTaskSE(name)
90 ,fUseHLTTrigger(kFALSE)
91 ,fESDRun(0)
92 ,fOutputList(0)
93 ,fHistOfflResiduals(NULL)
94 ,fHistOnlResiduals(NULL)
95 ,fHistOfflDz(NULL)
96 ,fHistOnlDz(NULL)
97 ,fHistOfflDxy(NULL)
98 ,fHistOnlDxy(NULL)
99 ,fHistOfflResidualsPos(NULL)
100 ,fHistOnlResidualsPos(NULL)
101 ,fHistOfflDzPos(NULL)
102 ,fHistOnlDzPos(NULL)
103 ,fHistOfflDxyPos(NULL)
104 ,fHistOnlDxyPos(NULL)
105 ,fHistOfflResidualsNeg(NULL)
106 ,fHistOnlResidualsNeg(NULL)
107 ,fHistOfflDzNeg(NULL)
108 ,fHistOnlDzNeg(NULL)
109 ,fHistOfflDxyNeg(NULL)
110 ,fHistOnlDxyNeg(NULL)
111 ,fHistNclvsNcl(NULL)
112 ,fHistTotEVsTotE(NULL)
113 ,fNevt(0)
114 ,fTrgClsArray(0)
115 ,fGlobalHistoProdArrOff(NULL)
116 ,fGlobalHistoProdArrOn(NULL)
117 ,fClustersArray(NULL)
118 ,fCaloName(name)
119{
120 // Constructor
121
122 // Define input and output slots here
123 // Input slot #0 works with a TChain
124 // DefineInput(0, TChain::Class());
125 // Output slot #0 writes into a TH1 container
126
127 DefineOutput(1, TList::Class());
128}
129
130
131//----------------------------------------------------------------------------------------------------
132
133void AliAnalysisTaskHLTCalo::UserCreateOutputObjects(){
134// Create histograms
135
136 OpenFile(1);
137
138 fOutputList = new TList();
139 fOutputList->SetOwner();
140 fOutputList->SetName(GetName());
141
142 CreateSpecificStuff(fOutputList);
143
144// --------------- define histograms ---------------------//
145
146 fHistOfflResiduals = new TH1F("fHistOfflResiduals", "Residuals between cluster and nearest track in cm (offline)", 50, 0, 50);
147 fHistOnlResiduals = new TH1F("fHistOnlResiduals", "Residuals between cluster and nearest track in cm (online)", 50, 0, 50);
148 fHistOfflDxy = new TH1F("fHistOfflDxy", "Dxy between cluster and nearest track in cm (offline)", 80, -40, 40);
149 fHistOnlDxy = new TH1F("fHistOnlDxy", "Dxy between cluster and nearest track in cm (online)", 80, -40, 40);
150 fHistOfflDz = new TH1F("fHistOfflDz", "Dz between cluster and nearest track in cm (offline)", 80, -40, 40);
151 fHistOnlDz = new TH1F("fHistOnlDz", "Dz between cluster and nearest track in cm (online)", 80, -40, 40);
152
153 fHistOfflResidualsPos = new TH1F("fHistOfflResidualsPos", "Residuals between cluster and nearest track in cm (offline)Pos", 50, 0, 50);
154 fHistOnlResidualsPos = new TH1F("fHistOnlResidualsPos", "Residuals between cluster and nearest track in cm (online)Pos", 50, 0, 50);
155 fHistOfflDxyPos = new TH1F("fHistOfflDxyPos", "Dxy between cluster and nearest track in cm (offline)Pos", 80, -40, 40);
156 fHistOnlDxyPos = new TH1F("fHistOnlDxyPos", "Dxy between cluster and nearest track in cm (online)Pos", 80, -40, 40);
157 fHistOfflDzPos = new TH1F("fHistOfflDzPos", "Dz between cluster and nearest track in cm (offline)Pos", 80, -40, 40);
158 fHistOnlDzPos = new TH1F("fHistOnlDzPos", "Dz between cluster and nearest track in cm (online)Pos", 80, -40, 40);
159
160 fHistOfflResidualsNeg = new TH1F("fHistOfflResidualsNeg", "Residuals between cluster and nearest track in cm (offline)Neg", 50, 0, 50);
161 fHistOnlResidualsNeg = new TH1F("fHistOnlResidualsNeg", "Residuals between cluster and nearest track in cm (online)Neg", 50, 0, 50);
162 fHistOfflDxyNeg = new TH1F("fHistOfflDxyNeg", "Dxy between cluster and nearest track in cm (offline)Neg", 80, -40, 40);
163 fHistOnlDxyNeg = new TH1F("fHistOnlDxyNeg", "Dxy between cluster and nearest track in cm (online)Neg", 80, -40, 40);
164 fHistOfflDzNeg = new TH1F("fHistOfflDzNeg", "Dz between cluster and nearest track in cm (offline)Neg", 80, -40, 40);
165 fHistOnlDzNeg = new TH1F("fHistOnlDzNeg", "Dz between cluster and nearest track in cm (online)Neg", 80, -40, 40);
166
167 fHistNclvsNcl = new TH2F("fHistNclvsNcl", "Number of offline cl vs online cl", 100, 0, 10, 100, 0, 10);
168 fHistTotEVsTotE = new TH2F("fHistTotEVsTotE", "Total energy in online cl vs total energy in offline cl", 300, 0, 150, 300, 0, 150);
169 fHistTotEVsTotE->SetXTitle("Offline energy sum");
170 fHistTotEVsTotE->SetYTitle("Online energy sum");
171 // HLT histogram producers
172 fGlobalHistoProdArrOff = new TObjArray();
173 fGlobalHistoProdArrOn = new TObjArray();
174
175
176 fGlobalHistoProdArrOff->AddLast(dynamic_cast<TObject*>(new AliHLTCaloHistoClusterEnergy(Form("%s_OFF", fCaloName.Data()))));
177 fGlobalHistoProdArrOff->AddLast(dynamic_cast<TObject*>(new AliHLTCaloHistoInvMass(Form("%s_OFF", fCaloName.Data() ))));
178 fGlobalHistoProdArrOff->AddLast(dynamic_cast<TObject*>(new AliHLTCaloHistoMatchedTracks(Form("%s_OFF", fCaloName.Data() ))));
179
180 fGlobalHistoProdArrOn->AddLast(dynamic_cast<TObject*>(new AliHLTCaloHistoClusterEnergy(Form("%s_ON", fCaloName.Data() ))));
181 fGlobalHistoProdArrOn->AddLast(dynamic_cast<TObject*>(new AliHLTCaloHistoInvMass(Form("%s_ON", fCaloName.Data() ))));
182 fGlobalHistoProdArrOn->AddLast(dynamic_cast<TObject*>(new AliHLTCaloHistoMatchedTracks(Form("%s_ON", fCaloName.Data() ))));
183
184 fClustersArray = new TRefArray();
185
186 // -------------- add histograms to the output TList -----------------//
187
188 fOutputList->Add(fHistOfflResiduals);
189 fOutputList->Add(fHistOnlResiduals);
190 fOutputList->Add(fHistOfflDz);
191 fOutputList->Add(fHistOnlDz);
192 fOutputList->Add(fHistOfflDxy);
193 fOutputList->Add(fHistOnlDxy);
194
195
196 fOutputList->Add(fHistOfflResidualsPos);
197 fOutputList->Add(fHistOnlResidualsPos);
198 fOutputList->Add(fHistOfflDzPos);
199 fOutputList->Add(fHistOnlDzPos);
200 fOutputList->Add(fHistOfflDxyPos);
201 fOutputList->Add(fHistOnlDxyPos);
202
203
204 fOutputList->Add(fHistOfflResidualsNeg);
205 fOutputList->Add(fHistOnlResidualsNeg);
206 fOutputList->Add(fHistOfflDzNeg);
207 fOutputList->Add(fHistOnlDzNeg);
208 fOutputList->Add(fHistOfflDxyNeg);
209 fOutputList->Add(fHistOnlDxyNeg);
210
211
212 fOutputList->Add(fHistTotEVsTotE);
213 fOutputList->Add(fHistNclvsNcl);
214
215 for(int ip = 0; ip < fGlobalHistoProdArrOff->GetEntriesFast(); ip++) {
216 AliHLTCaloHistoProducer *prod = dynamic_cast<AliHLTCaloHistoProducer*>(fGlobalHistoProdArrOff->At(ip));
217 fOutputList->AddAll(prod->GetHistograms());
218 }
219
220 for(int ip = 0; ip < fGlobalHistoProdArrOn->GetEntriesFast(); ip++) {
221 AliHLTCaloHistoProducer *prod = dynamic_cast<AliHLTCaloHistoProducer*>(fGlobalHistoProdArrOn->At(ip));
222 fOutputList->AddAll(prod->GetHistograms());
223 }
224
225 PostData(1, fOutputList);
226}
227
228void AliAnalysisTaskHLTCalo::NotifyRun(){
229// This will not work if the active trigger classes change from run to run.
230// Then one has to know all trigger classes before processing the data.
231
232 AliESDEvent* evESD = dynamic_cast<AliESDEvent*>(InputEvent());
233 TString trgClasses = evESD->GetESDRun()->GetActiveTriggerClasses();
234
235 fTrgClsArray = trgClasses.Tokenize(" ");
236 //cout<<fTrgClsArray->GetEntries()<<endl;
237
238// for(Int_t i = 0; i < fTrgClsArray->GetEntries(); i++){
239// TString str = ((TObjString *)fTrgClsArray->At(i))->GetString();
240// (fHistTrigger->GetXaxis())->SetBinLabel(i+1, str.Data());
241// (fHistHLTTrigger->GetXaxis())->SetBinLabel(i+1, str.Data());
242// }
243
244 evESD = NULL;
245}
246
247void AliAnalysisTaskHLTCalo::UserExec(Option_t *){
248 //UserExec
249
250 AliESDEvent* evESD = dynamic_cast<AliESDEvent*>(InputEvent());
251
252 if (!evESD) {
253 Printf("ERROR: fESD not available");
254 return;
255 }
256
257 AliESDEvent* evHLTESD = 0;
258 AliESDInputHandler* esdH = dynamic_cast<AliESDInputHandler*>(fInputHandler);
259
260 if(esdH) evHLTESD = esdH->GetHLTEvent();
261
262 if(!evHLTESD){
263 Printf("ERROR: HLTesd not available");
264 return;
265 }
266
267 // To check if anything was triggered in HLT.
268 if(fUseHLTTrigger){
269 if (!((AliHLTGlobalTriggerDecision*)evHLTESD->GetHLTTriggerDecision())->Result()){
270 return;
271 // Process all and any events that were triggered by HLT.
272 }
273 }
274
275 DoSpecificStuff(evESD, evHLTESD);
276
277 Double_t offE = 0.0;
278 Double_t onE = 0.0;
279
280
281 for(int icl = 0; icl < evESD->GetNumberOfCaloClusters(); icl++) {
282 AliESDCaloCluster * cluster = evESD->GetCaloCluster(icl);
283 if(IsThisDetector(cluster)) {
284
285 offE += cluster->E();
286 fHistOfflResiduals->Fill(cluster->GetEmcCpvDistance());
287 fHistOfflDz->Fill(cluster->GetTrackDz());
288 fHistOfflDxy->Fill(cluster->GetTrackDx());
289
290
291 TArrayI* matchedTracks = cluster->GetTracksMatched();
292
293 if (matchedTracks) {
294 if (matchedTracks->At(0) > -1) {
295
296 Int_t trackID = matchedTracks->At(0);
297
298 AliESDtrack * track = evESD->GetTrack(trackID);
299
300 if(track) {
301 if (track->Charge() > 0) {
302
303 fHistOfflResidualsPos->Fill(cluster->GetEmcCpvDistance());;
304 fHistOfflDzPos->Fill(cluster->GetTrackDz());
305 fHistOfflDxyPos->Fill(cluster->GetTrackDx());
306
307 } else if (track->Charge() < 0) {
308
309 fHistOfflResidualsNeg->Fill(cluster->GetEmcCpvDistance());;
310 fHistOfflDzNeg->Fill(cluster->GetTrackDz());
311 fHistOfflDxyNeg->Fill(cluster->GetTrackDx());
312
313 } else {
314 cout <<"BALLE wtf!!"<<endl;
315 }
316
317 } else {
318 cout << "BALLE no track!"<<endl;
319 }
320 }
321 } else {
322 cout << "BALLE no array"<<endl;
323 }
324 }
325 }
326
327
328
329 for(int icl = 0; icl < evHLTESD->GetNumberOfCaloClusters(); icl++) {
330 AliESDCaloCluster * cluster = evHLTESD->GetCaloCluster(icl);
331 if(IsThisDetector(cluster)) {
332 onE += cluster->E();
333 fHistOnlResiduals->Fill(evHLTESD->GetCaloCluster(icl)->GetEmcCpvDistance());
334 fHistOnlDxy->Fill(evHLTESD->GetCaloCluster(icl)->GetTrackDx());
335 fHistOnlDz->Fill(evHLTESD->GetCaloCluster(icl)->GetTrackDz());
336
337 TArrayI* matchedTracks = cluster->GetTracksMatched();
338
339 if (matchedTracks) {
340 if (matchedTracks->At(0) > -1) {
341
342 Int_t trackID = matchedTracks->At(0);
343
344 AliESDtrack * track = evHLTESD->GetTrack(trackID);
345
346 if(track) {
347 if (track->Charge() > 0) {
348
349 fHistOnlResidualsPos->Fill(cluster->GetEmcCpvDistance());;
350 fHistOnlDzPos->Fill(cluster->GetTrackDz());
351 fHistOnlDxyPos->Fill(cluster->GetTrackDx());
352
353 } else if (track->Charge() < 0) {
354
355 fHistOnlResidualsNeg->Fill(cluster->GetEmcCpvDistance());;
356 fHistOnlDzNeg->Fill(cluster->GetTrackDz());
357 fHistOnlDxyNeg->Fill(cluster->GetTrackDx());
358
359 } else {
360 cout <<"BALLE wtf!!"<<endl;
361 }
362
363 } else {
364 cout << "BALLE no track!"<<endl;
365 }
366 }
367 } else {
368 //cout << "BALLE no array"<<endl;
369 }
370
371
372
373
374
375 }
376 }
377
378 Int_t nc = GetClusters(evESD, fClustersArray);
379 for(int ip = 0; ip < fGlobalHistoProdArrOff->GetEntriesFast(); ip++) {
380 AliHLTCaloHistoProducer *prod = dynamic_cast<AliHLTCaloHistoProducer*>(fGlobalHistoProdArrOff->At(ip));
381 prod->FillHistograms(nc, fClustersArray);
382 }
383
384 Int_t nOnc = GetClusters(evHLTESD, fClustersArray);
385 for(int ip = 0; ip < fGlobalHistoProdArrOn->GetEntriesFast(); ip++) {
386 AliHLTCaloHistoProducer *prod = dynamic_cast<AliHLTCaloHistoProducer*>(fGlobalHistoProdArrOn->At(ip));
387 prod->FillHistograms(nOnc, fClustersArray);
388 }
389
390 fHistNclvsNcl->Fill(nc, nOnc);
391 fHistTotEVsTotE->Fill(offE, onE);
392
393
394 fNevt++;
395
396 // Post output data.
397 PostData(1, fOutputList);
398
399}
400
401void AliAnalysisTaskHLTCalo::Terminate(Option_t *){
402
403
404
405 // Printf("Number of tracks thru CE: %d", fNtracksThruZ0);
406 // Printf("Number of tracks thru CE from triggered events: %d",
407 // fNtracksThruZ0Trig);
408
409
410 // Draw result to the screen
411 // Called once at the end of the query
412
413 // TCanvas *c1 = new TCanvas("AliAnalysisTaskHLTCalo","Trigger",10,10,510,510);
414 //fHistTrigger->DrawCopy("E");
415
416}