Coverity fixes (Jens)
[u/mrichter/AliRoot.git] / PWGGA / PHOSTasks / CaloCellQA / AliAnalysisTaskCaloCellsQA.cxx
CommitLineData
045862db 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15// Container class for bad channels & bad runs identification
16//
0d81af58 17// By default, pileup events are not processed, use SetAvoidPileup()
18// to change this.
19//
f4dd0897 20// Clusters containing a bad cell can be rejected, use SetBadCells().
21//
4dfe4df7 22// The output can be directly saved into a file (see the class second
23// constructor). Saving through AliAnalysisManager is always happen with
24// TObject::kSingleKey option. In such case an output from different runs
25// cannot be merged later, because here we have histograms which are
26// run-dependent, i.e. not the same between every analysis instance.
27//
28// If you forget to initialize EMCAL/PHOS geometry, the class will do it
29// for you.
30//
045862db 31// See AddTaskCaloCellsQA.C for usage example.
32//
33//----
34// Author: Olga Driga (SUBATECH)
35
36// --- ROOT system ---
37#include <TFile.h>
0d81af58 38#include <TObjArray.h>
045862db 39
40// --- AliRoot header files ---
41#include <AliAnalysisTaskCaloCellsQA.h>
9c12af5f 42#include "AliAnalysisManager.h"
045862db 43#include <AliVEvent.h>
44#include <AliVCaloCells.h>
45#include <AliVCluster.h>
46#include <AliVVertex.h>
4dfe4df7 47#include <AliEMCALGeometry.h>
48#include <AliPHOSGeometry.h>
db05d873 49#include <AliLog.h>
045862db 50
51ClassImp(AliAnalysisTaskCaloCellsQA)
52
60a1d411 53//________________________________________________________________
54AliAnalysisTaskCaloCellsQA::AliAnalysisTaskCaloCellsQA() : AliAnalysisTaskSE(),
55 fkAvoidPileup(kTRUE),
56 fCellsQA(0),
d30ac678 57 fOutfile(""),
4dfe4df7 58 fNBad(0),
59 fBadCells(0)
60a1d411 60{
d30ac678 61 // Constructor for root I/O, do not use it
60a1d411 62}
63
045862db 64//________________________________________________________________
d30ac678 65AliAnalysisTaskCaloCellsQA::AliAnalysisTaskCaloCellsQA(const char *name, Int_t nmods, Int_t det, char *outfile) :
66 AliAnalysisTaskSE(name),
0d81af58 67 fkAvoidPileup(kTRUE),
045862db 68 fCellsQA(0),
d30ac678 69 fOutfile(""),
4dfe4df7 70 fNBad(0),
71 fBadCells(0)
045862db 72{
d30ac678 73 // Main constructor.
74 //
75 // nmods -- number of supermodules + 1;
76 // det -- detector;
4dfe4df7 77 // outfile -- file name to write to; if NULL, write into output container;
78 // allows to avoid limitation of AliAnalysisManager, which always
79 // writes with TObject::kSingleKey option.
80
d30ac678 81
82 if (det == kEMCAL)
83 fCellsQA = new AliCaloCellsQA(nmods, AliCaloCellsQA::kEMCAL);
84 else if (det == kPHOS)
85 fCellsQA = new AliCaloCellsQA(nmods, AliCaloCellsQA::kPHOS);
86 else
db05d873 87 AliFatal("Wrong detector provided");
d30ac678 88
89 if (outfile) fOutfile = outfile;
4dfe4df7 90 else
91 DefineOutput(1, TObjArray::Class());
045862db 92}
93
94//________________________________________________________________
95AliAnalysisTaskCaloCellsQA::~AliAnalysisTaskCaloCellsQA()
96{
9c12af5f 97 if (!AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fCellsQA;
f4dd0897 98 if (fBadCells) delete [] fBadCells;
045862db 99}
100
045862db 101//________________________________________________________________
102void AliAnalysisTaskCaloCellsQA::UserCreateOutputObjects()
103{
104 // Per run histograms cannot be initialized here
105
106 fCellsQA->InitSummaryHistograms();
4dfe4df7 107
d30ac678 108 if (fOutfile.Length() == 0)
4dfe4df7 109 PostData(1, fCellsQA->GetListOfHistos());
045862db 110}
111
112//________________________________________________________________
113void AliAnalysisTaskCaloCellsQA::UserExec(Option_t *)
114{
115 // Does the job for one event
116
db05d873 117 // event
118 AliVEvent *event = InputEvent();
119 if (!event) {
120 AliWarning("Could not get event");
121 return;
122 }
123
124 fCellsQA->InitTransientFindCurrentRun(event->GetRunNumber());
125
4dfe4df7 126 // check geometry
d30ac678 127 if (fCellsQA->GetDetector() == AliCaloCellsQA::kEMCAL) {
4dfe4df7 128 if (!AliEMCALGeometry::GetInstance()) {
db05d873 129 AliInfo("EMCAL geometry not initialized, initializing it for you");
4dfe4df7 130 AliEMCALGeometry::GetInstance("EMCAL_COMPLETEV1");
131 }
132 } else {
133 if (!AliPHOSGeometry::GetInstance()) {
db05d873 134 AliInfo("PHOS geometry not initialized, initializing it for you");
4dfe4df7 135 AliPHOSGeometry::GetInstance("IHEP");
136 }
137 }
138
0d81af58 139 // pileup; FIXME: why AliVEvent does not allow a version without arguments?
140 if (fkAvoidPileup && event->IsPileupFromSPD(3,0.8,3.,2.,5.))
141 return;
142
045862db 143 // cells
144 AliVCaloCells *cells;
145 if (fCellsQA->GetDetector() == AliCaloCellsQA::kEMCAL)
146 cells = event->GetEMCALCells();
147 else
148 cells = event->GetPHOSCells();
149
150 if (!cells) {
db05d873 151 AliWarning("Could not get cells");
045862db 152 return;
153 }
154
155 // primary vertex
156 AliVVertex *vertex = (AliVVertex*) event->GetPrimaryVertex();
157 if (!vertex) {
db05d873 158 AliWarning("Could not get primary vertex");
045862db 159 return;
160 }
161
162 // collect clusters
0d81af58 163 TObjArray clusArray;
045862db 164 for (Int_t i = 0; i < event->GetNumberOfCaloClusters(); i++) {
165 AliVCluster *clus = event->GetCaloCluster(i);
166 if (!clus) {
db05d873 167 AliWarning("Could not get cluster");
045862db 168 return;
169 }
170
f4dd0897 171 // basic filtering
172 if (fCellsQA->GetDetector() == AliCaloCellsQA::kEMCAL && !clus->IsEMCAL()) continue;
173 if (fCellsQA->GetDetector() == AliCaloCellsQA::kPHOS && !clus->IsPHOS()) continue;
174 if (IsClusterBad(clus)) continue;
175
0d81af58 176 clusArray.Add(clus);
045862db 177 }
178
179 Double_t vertexXYZ[3];
180 vertex->GetXYZ(vertexXYZ);
0d81af58 181 fCellsQA->Fill(event->GetRunNumber(), &clusArray, cells, vertexXYZ);
4dfe4df7 182
d30ac678 183 if (fOutfile.Length() == 0)
4dfe4df7 184 PostData(1, fCellsQA->GetListOfHistos());
045862db 185}
186
187//________________________________________________________________
188void AliAnalysisTaskCaloCellsQA::Terminate(Option_t*)
189{
4dfe4df7 190 // Handle direct saving of the histograms into a file
191
d30ac678 192 if (fOutfile.Length() > 0) {
193 TFile f(fOutfile.Data(), "RECREATE");
4dfe4df7 194 fCellsQA->GetListOfHistos()->Write();
195 }
045862db 196}
f4dd0897 197
198//____________________________________________________________
199void AliAnalysisTaskCaloCellsQA::SetBadCells(Int_t badcells[], Int_t nbad)
200{
201 // Set absId numbers for bad cells;
202 // clusters which contain a bad cell will be rejected.
203
ef7b092d 204 if (fBadCells) delete [] fBadCells;
205
f4dd0897 206 // switch off bad cells, if asked
207 if (nbad <= 0) {
f4dd0897 208 fNBad = 0;
209 return;
210 }
211
212 fNBad = nbad;
213 fBadCells = new Int_t[nbad];
214
215 for (Int_t i = 0; i < nbad; i++)
216 fBadCells[i] = badcells[i];
217}
218
219//________________________________________________________________
220Bool_t AliAnalysisTaskCaloCellsQA::IsClusterBad(AliVCluster *clus)
221{
222 // Returns true if cluster contains a bad cell
223
224 for (Int_t b = 0; b < fNBad; b++)
225 for (Int_t c = 0; c < clus->GetNCells(); c++)
226 if (clus->GetCellAbsId(c) == fBadCells[b])
227 return kTRUE;
228
229 return kFALSE;
230}