]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/PHOSTasks/CaloCellQA/AliAnalysisTaskCaloCellsQA.cxx
change library dependencies and paths to the new places of the analysis under PWGGA...
[u/mrichter/AliRoot.git] / PWGGA / PHOSTasks / CaloCellQA / AliAnalysisTaskCaloCellsQA.cxx
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 //
17 // By default, pileup events are not processed, use SetAvoidPileup()
18 // to change this.
19 //
20 // Clusters containing a bad cell can be rejected, use SetBadCells().
21 //
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 //
31 // See AddTaskCaloCellsQA.C for usage example.
32 //
33 //----
34 //  Author: Olga Driga (SUBATECH)
35
36 // --- ROOT system ---
37 #include <TFile.h>
38 #include <TObjArray.h>
39
40 // --- AliRoot header files ---
41 #include <AliAnalysisTaskCaloCellsQA.h>
42 #include "AliAnalysisManager.h"
43 #include <AliVEvent.h>
44 #include <AliVCaloCells.h>
45 #include <AliVCluster.h>
46 #include <AliVVertex.h>
47 #include <AliEMCALGeometry.h>
48 #include <AliPHOSGeometry.h>
49 #include <AliLog.h>
50
51 ClassImp(AliAnalysisTaskCaloCellsQA)
52
53 //________________________________________________________________
54 AliAnalysisTaskCaloCellsQA::AliAnalysisTaskCaloCellsQA() : AliAnalysisTaskSE(),
55   fkAvoidPileup(kTRUE),
56   fCellsQA(0),
57   fOutfile(""),
58   fNBad(0),
59   fBadCells(0)
60 {
61   // Constructor for root I/O, do not use it
62 }
63
64 //________________________________________________________________
65 AliAnalysisTaskCaloCellsQA::AliAnalysisTaskCaloCellsQA(const char *name, Int_t nmods, Int_t det, char *outfile) :
66   AliAnalysisTaskSE(name),
67   fkAvoidPileup(kTRUE),
68   fCellsQA(0),
69   fOutfile(""),
70   fNBad(0),
71   fBadCells(0)
72 {
73   // Main constructor.
74   //
75   // nmods -- number of supermodules + 1;
76   // det -- detector;
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
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
87     AliFatal("Wrong detector provided");
88
89   if (outfile) fOutfile = outfile;
90   else
91     DefineOutput(1, TObjArray::Class());
92 }
93
94 //________________________________________________________________
95 AliAnalysisTaskCaloCellsQA::~AliAnalysisTaskCaloCellsQA()
96 {
97   if (!AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fCellsQA;
98   if (fBadCells) delete [] fBadCells;
99 }
100
101 //________________________________________________________________
102 void AliAnalysisTaskCaloCellsQA::UserCreateOutputObjects()
103 {
104   // Per run histograms cannot be initialized here
105
106   fCellsQA->InitSummaryHistograms();
107
108   if (fOutfile.Length() == 0)
109     PostData(1, fCellsQA->GetListOfHistos());
110 }
111
112 //________________________________________________________________
113 void AliAnalysisTaskCaloCellsQA::UserExec(Option_t *)
114 {
115   // Does the job for one event
116
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
126   // check geometry
127   if (fCellsQA->GetDetector() == AliCaloCellsQA::kEMCAL) {
128     if (!AliEMCALGeometry::GetInstance()) {
129       AliInfo("EMCAL geometry not initialized, initializing it for you");
130       AliEMCALGeometry::GetInstance("EMCAL_COMPLETEV1");
131     }
132   } else {
133     if (!AliPHOSGeometry::GetInstance()) {
134       AliInfo("PHOS geometry not initialized, initializing it for you");
135       AliPHOSGeometry::GetInstance("IHEP");
136     }
137   }
138
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
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) {
151     AliWarning("Could not get cells");
152     return;
153   }
154
155   // primary vertex
156   AliVVertex *vertex = (AliVVertex*) event->GetPrimaryVertex();
157   if (!vertex) {
158     AliWarning("Could not get primary vertex");
159     return;
160   }
161
162   // collect clusters
163   TObjArray clusArray;
164   for (Int_t i = 0; i < event->GetNumberOfCaloClusters(); i++) {
165     AliVCluster *clus = event->GetCaloCluster(i);
166     if (!clus) {
167       AliWarning("Could not get cluster");
168       return;
169     }
170
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
176     clusArray.Add(clus);
177   }
178
179   Double_t vertexXYZ[3];
180   vertex->GetXYZ(vertexXYZ);
181   fCellsQA->Fill(event->GetRunNumber(), &clusArray, cells, vertexXYZ);
182
183   if (fOutfile.Length() == 0)
184     PostData(1, fCellsQA->GetListOfHistos());
185 }
186
187 //________________________________________________________________
188 void AliAnalysisTaskCaloCellsQA::Terminate(Option_t*)
189 {
190   // Handle direct saving of the histograms into a file
191
192   if (fOutfile.Length() > 0) {
193     TFile f(fOutfile.Data(), "RECREATE");
194     fCellsQA->GetListOfHistos()->Write();
195   }
196 }
197
198 //____________________________________________________________
199 void 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
204   if (fBadCells) delete [] fBadCells;
205
206   // switch off bad cells, if asked
207   if (nbad <= 0) {
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 //________________________________________________________________
220 Bool_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 }