AliPhysics  8d00e07 (8d00e07)
AliEmcalFastOrMonitorTask.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 <vector>
30 #include <THashList.h>
31 #include <TH2.h>
32 #include <THistManager.h>
33 #include <TLorentzVector.h>
34 #include <TMath.h>
35 #include <TObjArray.h>
36 #include <TParameter.h>
37 #include <TVector3.h>
38 
40 #include "AliEMCALGeometry.h"
41 #include "AliEMCALTriggerConstants.h"
42 #include "AliInputEventHandler.h"
43 #include "AliLog.h"
44 #include "AliOADBContainer.h"
45 #include "AliVCaloCells.h"
46 #include "AliVCaloTrigger.h"
47 #include "AliVEvent.h"
48 #include "AliVVertex.h"
49 #include "AliDataFile.h"
50 
54 
55 using namespace PWG::EMCAL;
56 
59  fHistos(nullptr),
60  fGeom(nullptr),
61  fLocalInitialized(false),
62  fOldRun(-1),
63  fRequestTrigger(AliVEvent::kAny),
64  fTriggerPattern(""),
65  fCellData(),
66  fMaskedFastors(),
67  fMaskedCells(),
68  fNameMaskedFastorOADB(),
69  fNameMaskedCellOADB(AliDataFile::GetFileNameOADB("EMCAL/EMCALBadChannels.root").data()),
70  fMaskedFastorOADB(nullptr),
71  fMaskedCellOADB(nullptr)
72 {
73 
74 }
75 
76 AliEmcalFastOrMonitorTask::AliEmcalFastOrMonitorTask(const char *name) :
77  AliAnalysisTaskSE(name),
78  fHistos(nullptr),
79  fGeom(nullptr),
80  fLocalInitialized(false),
81  fOldRun(-1),
82  fRequestTrigger(AliVEvent::kAny),
83  fTriggerPattern(""),
84  fMaskedFastors(),
85  fMaskedCells(),
86  fNameMaskedFastorOADB(),
87  fNameMaskedCellOADB(AliDataFile::GetFileNameOADB("EMCAL/EMCALBadChannels.root").data()),
88  fMaskedFastorOADB(nullptr),
89  fMaskedCellOADB(nullptr)
90 {
91  DefineOutput(1, TList::Class());
92 }
93 
97 }
98 
100  fHistos = new THistManager("fastOrHistos");
101 
102  const int kMaxCol = 48, kMaxRow = 104, kMaxFastOr = kMaxRow * kMaxCol;
103 
104  fHistos->CreateTH1("hEvents", "Number of events", 1, 0.5, 1.5);
105  fHistos->CreateTH1("hFastOrFrequencyL0", "FastOr frequency at Level0", kMaxFastOr, -0.5, kMaxFastOr - 0.5);
106  fHistos->CreateTH1("hFastOrFrequencyL1", "FastOr frequency at Level1", kMaxFastOr, -0.5, kMaxFastOr - 0.5);
107  fHistos->CreateTH2("hFastOrAmplitude", "FastOr amplitudes", kMaxFastOr, -0.5, kMaxFastOr - 0.5, 513, -0.5, 512.5);
108  fHistos->CreateTH2("hFastOrTimeSum", "FastOr time sum", kMaxFastOr, -0.5, kMaxFastOr - 0.5, 2049, -0.5, 2048.5);
109  fHistos->CreateTH2("hFastOrTransverseTimeSum", "FastOr transverse time sum", kMaxFastOr, -0.5, kMaxFastOr - 0.5, 2049, -0.5, 2048.5);
110  fHistos->CreateTH2("hFastOrNL0Times", "FastOr Number of L0 times", kMaxFastOr, -0.5, kMaxFastOr - 0.5, 16, -0.5, 15.5);
111  fHistos->CreateTH2("hFastOrColRowFrequencyL0", "FastOr Frequency (col-row) at Level1", kMaxCol, -0.5, kMaxCol - 0.5, kMaxRow, -0.5, kMaxRow - 0.5);
112  fHistos->CreateTH2("hFastOrColRowFrequencyL1", "FastOr Frequency (col-row) at Level0", kMaxCol, -0.5, kMaxCol - 0.5, kMaxRow, -0.5, kMaxRow - 0.5);
113  fHistos->CreateTH2("hEnergyFastorCell", "Sum of cell energy vs. fastor Energy", 1000, 0., 20., 1000 , 0., 20.);
114 
115  // Helper histograms checking the mask status of cells and FastORs
116  fHistos->CreateTH1("hMaskedFastors", "Index of masked FastOR; FastOR index; Counts", 3001, -0.5, 3000.5);
117  fHistos->CreateTH1("hMaskedCells", "Index of masked cell; Cell index; Counts", 20001, -0.5, 20000.5);
118  fHistos->CreateTH1("hCellEnergyCount", "Counts of non-0 cell entries; Cell index; Counts", 20001, -0.5, 20000.5);
119 
120  // THnSparse for fastor-by-fastor energy decalibration
121  TAxis fastorIDAxis(4992, -0.5, 4991.5), offlineaxis(200, 0., 20.), onlineaxis(200, 0., 20.), cellmaskaxis(5, -0.5, 4.5);
122  const TAxis *sparseaxis[4] = {&fastorIDAxis, &offlineaxis, &onlineaxis, &cellmaskaxis};
123  fastorIDAxis.SetNameTitle("fastorAbsID", "FastOR abs. ID");
124  offlineaxis.SetNameTitle("offlinenergy", "E_{2x2 cells} (GeV)");
125  onlineaxis.SetNameTitle("onlineenergy", "E_{FastOR} (GeV)");
126  cellmaskaxis.SetNameTitle("maskedcells", "Number of masked cells");
127  fHistos->CreateTHnSparse("hFastOrEnergyOfflineOnline", "FastOr Offline vs Online energy", 4, sparseaxis);
128 
129  PostData(1, fHistos->GetListOfHistograms());
130 }
131 
133  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(InputEvent()->GetRunNumber());
134 
135  int nrow = fGeom->GetTriggerMappingVersion() == 2 ? 104 : 64;
136  fCellData.Allocate(48, nrow);
137 
138  if(fNameMaskedCellOADB.Length()){
139  fMaskedCellOADB = new AliOADBContainer("AliEMCALBadChannels");
140  fMaskedCellOADB->InitFromFile(fNameMaskedCellOADB, "AliEMCALBadChannels");
141  }
142 
143  if(fNameMaskedFastorOADB.Length()){
144  fMaskedFastorOADB = new AliOADBContainer("AliEmcalMaskedFastors");
145  fMaskedFastorOADB->InitFromFile(fNameMaskedFastorOADB, "AliEmcalMaskedFastors");
146  }
147 }
148 
150  // Load masked FastOR data
151  if(fMaskedFastorOADB){
152  AliInfoStream() << "Loading masked cells for run " << newrun << std::endl;
153  fMaskedFastors.clear();
154  TObjArray *maskedfastors = static_cast<TObjArray *>(fMaskedFastorOADB->GetObject(newrun));
155  if(maskedfastors && maskedfastors->GetEntries()){
156  for(auto masked : *maskedfastors){
157  TParameter<int> *fastOrAbsID = static_cast<TParameter<int> *>(masked);
158  fMaskedFastors.push_back(fastOrAbsID->GetVal());
159  fHistos->FillTH1("hMaskedFastors", fastOrAbsID->GetVal());
160  }
161  std::sort(fMaskedFastors.begin(), fMaskedFastors.end(), std::less<int>());
162  }
163  }
164 
165  // Load masked cell data
166  if(fMaskedCellOADB){
167  AliInfoStream() << "Loading masked cells for run " << newrun << std::endl;
168  fMaskedCells.clear();
169  TObjArray *maskhistos = static_cast<TObjArray *>(fMaskedCellOADB->GetObject(newrun));
170  if(maskhistos && maskhistos->GetEntries()){
171  for(auto mod : *maskhistos){
172  TH2 *modhist = static_cast<TH2 *>(mod);
173  TString modname = modhist->GetName();
174  AliDebugStream(1) << "Reading bad channels from histogram " << modname << std::endl;
175  modname.ReplaceAll("EMCALBadChannelMap_Mod", "");
176  Int_t modid = modname.Atoi();
177  for(int icol = 0; icol < 48; icol++){
178  for(int irow = 0; irow < 24; irow++){
179  if(modhist->GetBinContent(icol, irow) > 0.){
180  int cellindex = fGeom->GetAbsCellIdFromCellIndexes(modid, irow, icol);
181  fMaskedCells.push_back(cellindex);
182  fHistos->FillTH1("hMaskedCells", cellindex);
183  }
184  }
185  }
186  }
187  std::sort(fMaskedCells.begin(), fMaskedCells.end(), std::less<int>());
188  }
189  }
190 }
191 
193  if(!fLocalInitialized){
194  ExecOnce();
195  fLocalInitialized = true;
196  }
197 
198  // Run change
199  if(InputEvent()->GetRunNumber() != fOldRun){
200  RunChanged(InputEvent()->GetRunNumber());
201  fOldRun = InputEvent()->GetRunNumber();
202  }
203 
204  // Check trigger
205  if(!(fInputHandler->IsEventSelected() & fRequestTrigger)) return;
206  if(fTriggerPattern.Length()){
207  if(!TString(InputEvent()->GetFiredTriggerClasses()).Contains(fTriggerPattern)) return;
208  }
209 
210  const AliVVertex *vtx = fInputEvent->GetPrimaryVertex();
211  Double_t vtxpos[3];
212  vtx->GetXYZ(vtxpos);
213 
215 
216  fHistos->FillTH1("hEvents", 1);
217 
218  AliVCaloTrigger *triggerdata = InputEvent()->GetCaloTrigger("EMCAL");
219  triggerdata->Reset();
220  Int_t nl0times, l1timesum, fastOrID, globCol, globRow;
221  Float_t amp;
222  while(triggerdata->Next()){
223  triggerdata->GetAmplitude(amp);
224  triggerdata->GetNL0Times(nl0times);
225  triggerdata->GetL1TimeSum(l1timesum);
226  triggerdata->GetPosition(globCol, globRow);
227  fGeom->GetTriggerMapping()->GetAbsFastORIndexFromPositionInEMCAL(globCol, globRow, fastOrID);
228  if(amp > 1e-5){
229  fHistos->FillTH2("hFastOrColRowFrequencyL0", globCol, globRow);
230  fHistos->FillTH1("hFastOrFrequencyL0", fastOrID);
231  }
232  if(l1timesum){
233  fHistos->FillTH2("hFastOrColRowFrequencyL1", globCol, globRow);
234  fHistos->FillTH1("hFastOrFrequencyL1", fastOrID);
235  }
236  if(std::find(fMaskedFastors.begin(), fMaskedFastors.end(), fastOrID) == fMaskedFastors.end()){
237  fHistos->FillTH2("hFastOrAmplitude", fastOrID, amp);
238  fHistos->FillTH2("hFastOrTimeSum", fastOrID, l1timesum);
239  fHistos->FillTH2("hFastOrNL0Times", fastOrID, nl0times);
240  fHistos->FillTH2("hFastOrTransverseTimeSum", fastOrID, GetTransverseTimeSum(fastOrID, l1timesum, vtxpos));
241  fHistos->FillTH2("hEnergyFastorCell", fCellData(globCol, globRow), l1timesum * EMCALTrigger::kEMCL1ADCtoGeV);
242  int ncellmasked = 0;
243  int fastorCells[4];
244  fGeom->GetTriggerMapping()->GetCellIndexFromFastORIndex(fastOrID, fastorCells);
245  for(int icell = 0; icell < 4; icell++){
246  if(std::find(fMaskedCells.begin(), fMaskedCells.end(), fastorCells[icell]) != fMaskedCells.end()) ncellmasked++;
247  }
248  double energydata[4] = {
249  static_cast<double>(fastOrID),
250  fCellData(globCol, globRow),
251  l1timesum * EMCALTrigger::kEMCL1ADCtoGeV,
252  static_cast<double>(ncellmasked)
253  };
254  fHistos->FillTHnSparse("hFastOrEnergyOfflineOnline", energydata);
255  }
256  }
257 
258  PostData(1, fHistos->GetListOfHistograms());
259 }
260 
262  fCellData.Reset();
263  AliVCaloCells *emccells = InputEvent()->GetEMCALCells();
264  for(int icell = 0; icell < emccells->GetNumberOfCells(); icell++){
265  int position = emccells->GetCellNumber(icell);
266  double amplitude = emccells->GetAmplitude(icell);
267  if(amplitude > 0){
268  fHistos->FillTH1("hCellEnergyCount", position);
269  if(std::find(fMaskedCells.begin(), fMaskedCells.end(), position) != fMaskedCells.end()){
270  AliErrorStream() << "Non-0 cell energy " << amplitude << " found for masked cell " << position << std::endl;
271  }
272  int absFastor, col, row;
273  fGeom->GetTriggerMapping()->GetFastORIndexFromCellIndex(position, absFastor);
274  fGeom->GetPositionInEMCALFromAbsFastORIndex(absFastor, col, row);
275  fCellData(col, row) += amplitude;
276  }
277  }
278 }
279 
281  Int_t cellIDs[4];
282  fGeom->GetTriggerMapping()->GetCellIndexFromFastORIndex(fastorAbsID, cellIDs);
283  std::vector<double> eta, phi;
284  for(int i = 0l; i < 4; i++){
285  double etatmp, phitmp;
286  fGeom->EtaPhiFromIndex(cellIDs[i], etatmp, phitmp);
287  eta.push_back(etatmp);
288  phi.push_back(phitmp);
289  }
290 
291  // Calculate FastOR position: for the approximation take mean eta and phi
292  // Radius is taken from the geometry
293  TVector3 fastorPos, vertexPos(vertex[0], vertex[1], vertex[2]);
294  fastorPos.SetPtEtaPhi(fGeom->GetIPDistance(), TMath::Mean(eta.begin(), eta.end()), TMath::Mean(phi.begin(), phi.end()));
295  fastorPos -= vertexPos;
296 
297  TLorentzVector evec(fastorPos, adc);
298  return evec.Et();
299 }
Bool_t fLocalInitialized
Switch whether task is initialized (for ExecOnce)
virtual void UserExec(Option_t *)
Event loop.
Double_t GetTransverseTimeSum(Int_t fastorAbsID, Double_t adc, const Double_t *vtx) const
Calculate transverse L1 time sum of a FastOR.
double Double_t
Definition: External.C:58
std::vector< int > fMaskedCells
List of masked cells.
Int_t fOldRun
Old Run (for RunChanged())
TString fNameMaskedFastorOADB
Name of the OADB container with masked fastors.
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
ULong_t fRequestTrigger
Trigger selection bits.
THistManager * fHistos
! Histogram handler
std::vector< int > fMaskedFastors
List of masked fastors.
Namespace for EMCAL framework classes and task.
void FillTHnSparse(const char *name, const double *x, double weight=1., Option_t *opt="")
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
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
float Float_t
Definition: External.C:68
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
AliOADBContainer * fMaskedFastorOADB
! OADB container with masked fastors
AliEMCALTriggerDataGrid< double > fCellData
Grid with summed cell data.
AliEMCALGeometry * fGeom
! EMCAL Geometry object
TString fNameMaskedCellOADB
Name of the OADB container with masked cells.
Namespace for PWG framework classes.
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
virtual void UserCreateOutputObjects()
Creating output objects.
Definition: External.C:220
virtual void ExecOnce()
Initialization of the task.
Container class for histograms.
Definition: THistManager.h:99
void LoadEventCellData()
Load event-dependent cell data.
Int_t GetRunNumber(TString)
Definition: PlotMuonQA.C:2235
const char Option_t
Definition: External.C:48
AliOADBContainer * fMaskedCellOADB
! OADB container with masked cells
virtual void RunChanged(Int_t newrun)
Run-dependent setup of the task.
THnSparse * CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt="")
Create a new THnSparse within the container.
TString fTriggerPattern
Trigger string pattern used in addition to the trigger selection bits.
Simlple monitoring of EMCAL FastOr quantities.