AliPhysics  421aab4 (421aab4)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalCellMonitorTask.cxx
Go to the documentation of this file.
1 /**************************************************************************************
2  * Copyright (C) 2017, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  **************************************************************************************/
27 #include <algorithm>
28 #include <iostream>
29 #include <map>
30 #include <vector>
31 #include <TArrayD.h>
32 #include <TClonesArray.h>
33 #include <TGrid.h>
34 #include <THashList.h>
35 #include <THistManager.h>
36 #include <TLinearBinning.h>
37 #include <TObjArray.h>
38 #include <TParameter.h>
39 
40 #include "AliEMCALGeometry.h"
42 #include "AliInputEventHandler.h"
43 #include "AliLog.h"
44 #include "AliOADBContainer.h"
45 #include "AliVCaloCells.h"
46 #include "AliVEvent.h"
47 
51 
52 using namespace PWG::EMCAL;
53 
56  fLocalInitialized(kFALSE),
57  fHistManager(nullptr),
58  fGeometry(nullptr),
59  fMinCellAmplitude(0),
60  fRequestTrigger(AliVEvent::kAnyINT),
61  fBadChannelContainer(""),
62  fTriggerString(""),
63  fNumberOfCells(12288),
64  fOldRun(-1),
65  fMaskedCells()
66 {
67 
68 }
69 
70 AliEmcalCellMonitorTask::AliEmcalCellMonitorTask(const char *name) :
71  AliAnalysisTaskSE(name),
72  fLocalInitialized(kFALSE),
73  fHistManager(nullptr),
74  fGeometry(nullptr),
75  fMinCellAmplitude(0),
76  fRequestTrigger(AliVEvent::kAnyINT),
77  fBadChannelContainer(""),
78  fTriggerString(""),
79  fNumberOfCells(12288),
80  fOldRun(-1),
81  fMaskedCells()
82 {
83  DefineOutput(1, TList::Class());
84 }
85 
87  if(fGeometry) delete fGeometry;
88 }
89 
91  fHistManager = new THistManager("EMCALCellMonitor");
92 
93 
94  PostData(1, fHistManager->GetListOfHistograms());
95 }
96 
98  if(!fGeometry)
99  fGeometry = AliEMCALGeometry::GetInstanceFromRunNumber(fInputEvent->GetRunNumber());
100  fNumberOfCells = fGeometry->GetNCells();
102 }
103 
105  if(fBadChannelContainer.Length()) LoadCellMasking();
106  for(auto cellID : fMaskedCells) fHistManager->FillTH1("cellMasking", cellID);
107 }
108 
110  if(!fLocalInitialized) {
111  ExecOnce();
112  fLocalInitialized = kTRUE;
113  }
114 
115  // Run change
116  if(InputEvent()->GetRunNumber() != fOldRun){
117  RunChanged();
118  fOldRun = InputEvent()->GetRunNumber();
119  }
120 
121  // Check trigger
122  if(!(fInputHandler->IsEventSelected() & fRequestTrigger)) return;
123  if(fTriggerString.Length()){
124  if(!TString(InputEvent()->GetFiredTriggerClasses()).Contains(fTriggerString)) return;
125  }
126 
127  fHistManager->FillTH1("events", 1);
128 
129  AliVCaloCells *emcalcells = fInputEvent->GetEMCALCells();
130 
131  // input data
132  Short_t cellNumber;
133  Double_t amplitude, celltime, efrac;
134  Int_t mclabel;
135 
136  Int_t sm, mod, meta, mphi, ieta, iphi;
137  for(int icell = 0; icell < emcalcells->GetNumberOfCells(); icell++){
138  emcalcells->GetCell(icell, cellNumber, amplitude, celltime, mclabel, efrac);
139  if(IsCellMasked(cellNumber)) continue;
140  fHistManager->FillTH2("cellAmplitude", amplitude, cellNumber);
141  if(amplitude < fMinCellAmplitude) continue;
142  fHistManager->FillTH1("cellAmplitudeCut", amplitude, cellNumber);
143  fHistManager->FillTH1("cellFrequency", cellNumber);
144  fHistManager->FillTH2("cellTime", celltime, cellNumber);
145  if(celltime >= 1e-6) fHistManager->FillTH2("cellTimeOutlier", celltime, cellNumber);
146  if(celltime > -5e-8 && celltime < 1e-7) fHistManager->FillTH2("cellTimeMain", celltime, cellNumber);
147 
148  // Get Cell index in eta-phi of sm
149  fGeometry->GetCellIndex(cellNumber, sm, mod, mphi, meta);
150  fGeometry->GetCellPhiEtaIndexInSModule(sm, mod, mphi, meta, iphi, ieta);
151 
152  fHistManager->FillTH2(Form("cellCountSM%d", sm), ieta, iphi);
153  fHistManager->FillTH2(Form("cellAmpSM%d", sm), ieta, iphi, amplitude);
154  fHistManager->FillTH2(Form("cellAmpTimeCorrSM%d", sm), celltime, amplitude);
155  }
156 
157  // Cluster loop
158  if(fNameClusters.Length()){
159  TClonesArray *clustercont = dynamic_cast<TClonesArray *>(InputEvent()->FindListObject(fNameClusters.Data()));
160  if(clustercont){
161  const AliVCluster *myclust = nullptr;
162  for(TIter clusteriter = TIter(clustercont).Begin(); clusteriter != TIter::End(); ++clusteriter){
163  myclust = dynamic_cast<const AliVCluster *>(*clusteriter);
164  if(!myclust) continue;
165  for(int icell = 0; icell < myclust->GetNCells(); icell++){
166  fHistManager->FillTH1("cellClusterOccurrency", myclust->GetCellAbsId(icell));
167  fHistManager->FillTH2("cellAmplitudeFractionCluster", myclust->GetCellAbsId(icell), myclust->GetCellAmplitudeFraction(icell));
168  }
169  }
170  } else {
171  AliErrorStream() << GetName() << ": cluster container " << fNameClusters << " not found in the input event" << std::endl;
172  }
173  }
174  PostData(1, fHistManager->GetListOfHistograms());
175 }
176 
178  fHistManager->CreateTH1("events", "Number of events", 1, 0.5, 1.5);
179  fHistManager->CreateTH1("cellMasking", "Monitoring for masked cells", TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5));
180  fHistManager->CreateTH1("cellFrequency", "Frequency of cell firing", TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5));
181  fHistManager->CreateTH2("cellAmplitude", "Energy distribution per cell", AliEmcalCellMonitorAmplitudeBinning(), TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5));
182  fHistManager->CreateTH2("cellAmplitudeCut", "Energy distribution per cell (after energy cut)", AliEmcalCellMonitorAmplitudeBinning(), TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5));
183  fHistManager->CreateTH2("cellTime", "Time distribution per cell", 300, -3e-7, 1e-6, fNumberOfCells, -0.5, fNumberOfCells - 0.5);
184  fHistManager->CreateTH2("cellTimeOutlier", "Outlier time distribution per cell", 100, 1e-6, 5e-5, fNumberOfCells, -0.5, fNumberOfCells - 0.5);
185  fHistManager->CreateTH2("cellTimeMain", "Time distribution per cell for the main bunch", 150, -50e-9, 100e-9, fNumberOfCells, -0.5, fNumberOfCells - 0.5);
186  fHistManager->CreateTH1("cellClusterOccurrency", "Occurrency of a cell in clusters", fNumberOfCells, -0.5, fNumberOfCells - 0.5);
187  fHistManager->CreateTH2("cellAmplitudeFractionCluster", "Summed cell amplitude fraction in a cluster", fNumberOfCells, -0.5, fNumberOfCells - 0.5, 200, 0., 200.);
188  for(int ism = 0; ism < 20; ++ism){
189  fHistManager->CreateTH2(Form("cellAmpSM%d", ism), Form("Integrated cell amplitudes for SM %d; col; row", ism), 48, -0.5, 47.5, 24, -0.5, 23.5);
190  fHistManager->CreateTH2(Form("cellCountSM%d", ism), Form("Count rate per cell for SM %d; col; row", ism), 48, -0.5, 47.5, 24, -0.5, 23.5);
191  }
192 
193  for(int ism = 0; ism < 20; ++ism){
194  fHistManager->CreateTH2(Form("cellAmpTimeCorrSM%d", ism), Form("Correlation between cell amplitude and time in Supermodule %d", ism), 1000, -5e-7, 5e-7, 1000, 0., 100.);
195  }
196 }
197 
199  if(!fBadChannelContainer.Length()) return;
200  AliInfoStream() << GetName() << ": Loading bad channel map from " <<fBadChannelContainer << std::endl;
201  fMaskedCells.clear();
202  if(fBadChannelContainer.Contains("alien://") && ! gGrid) TGrid::Connect("alien://"); // Make sure alien connection is available as the AliOADBContainer doesn't handle it
203  AliOADBContainer contreader("EmcalBadChannelsAdditional");
204  contreader.InitFromFile(fBadChannelContainer.Data(), "EmcalBadChannelsAdditional");
205  TObjArray *rundata = dynamic_cast<TObjArray *>(contreader.GetObject(InputEvent()->GetRunNumber()));
206  if(!rundata) return;
207  for(TIter channeliter = TIter(rundata).Begin(); channeliter != TIter::End(); ++channeliter){
208  TParameter<int> *cellID = static_cast<TParameter<int> *>(*channeliter);
209  if(cellID) SetBadCell(cellID->GetVal());
210  }
211 }
212 
214  if(std::find(fMaskedCells.begin(), fMaskedCells.end(), cellId) != fMaskedCells.end()) return;
215  fMaskedCells.push_back(cellId);
216 }
217 
219  return (std::find(fMaskedCells.begin(), fMaskedCells.end(), cellId) != fMaskedCells.end());
220 }
221 
224 {
225  SetMinimum(0);
226  AddStep(2., 0.1);
227  AddStep(5., 0.2);
228  AddStep(10., 0.5);
229  AddStep(20., 1.);
230  AddStep(50., 2.);
231  AddStep(100., 5.);
232  AddStep(200., 10.);
233 }
AliEMCALGeometry * fGeometry
! EMCAL geometry
double Double_t
Definition: External.C:58
Class creating a linear binning, used in the histogram manager.
Int_t fOldRun
! Old Run number (for run change check)
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
void AddStep(Double_t max, Double_t binwidth)
TString fBadChannelContainer
Bad channel container name.
TH2 * CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
Create a new TH2 within the container.
int Int_t
Definition: External.C:63
Simple monitoring task for cell related quantities.
THistManager * fHistManager
! Histogram handler
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
TString fNameClusters
Name of the cluster container (as TClonesArray)
std::vector< Int_t > fMaskedCells
Vector of masked cells.
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
Helper class creating user defined custom binning.
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
short Short_t
Definition: External.C:23
Double_t fMinCellAmplitude
Min. cell amplitude requested for cell time and frequency.
ClassImp(AliAnalysisTaskDeltaPt) AliAnalysisTaskDeltaPt
Bool_t fLocalInitialized
Check whether task is initialized (for ExecOnce)
ULong_t fRequestTrigger
Trigger selection.
TString fTriggerString
Trigger string in addition to trigger selection.
Container class for histograms.
Definition: THistManager.h:99
Int_t GetRunNumber(TString)
Definition: PlotMuonQA.C:2235
const char Option_t
Definition: External.C:48
void SetMinimum(Double_t min)