AliPhysics  608b256 (608b256)
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  fHistosQA(nullptr),
60  fLocalInitialized(false),
61  fOldRun(-1),
62  fRequestTrigger(AliVEvent::kAny),
63  fTriggerPattern(""),
64  fCellData(),
65  fMaskedFastors(),
66  fMaskedCells(),
67  fNameMaskedFastorOADB(),
68  fNameMaskedCellOADB(AliDataFile::GetFileNameOADB("EMCAL/EMCALBadChannels.root").data()),
69  fMaskedFastorOADB(nullptr),
70  fMaskedCellOADB(nullptr)
71 {
72  SetNeedEmcalGeom(kTRUE);
73 }
74 
75 AliEmcalFastOrMonitorTask::AliEmcalFastOrMonitorTask(const char *name) :
76  AliAnalysisTaskEmcal(name, kTRUE),
77  fHistosQA(nullptr),
78  fLocalInitialized(false),
79  fOldRun(-1),
80  fRequestTrigger(AliVEvent::kAny),
81  fTriggerPattern(""),
82  fMaskedFastors(),
83  fMaskedCells(),
84  fNameMaskedFastorOADB(),
85  fNameMaskedCellOADB(AliDataFile::GetFileNameOADB("EMCAL/EMCALBadChannels.root").data()),
86  fMaskedFastorOADB(nullptr),
87  fMaskedCellOADB(nullptr)
88 {
89  SetNeedEmcalGeom(kTRUE);
90  DefineOutput(1, TList::Class());
91 }
92 
96 }
97 
100 
101  fHistosQA = new THistManager("fastOrHistos");
102 
103  const int kMaxCol = 48, kMaxRow = 104, kMaxFastOr = kMaxRow * kMaxCol;
104 
105  fHistosQA->CreateTH1("hEvents", "Number of events", 1, 0.5, 1.5);
106  fHistosQA->CreateTH1("hFastOrFrequencyL0", "FastOr frequency at Level0", kMaxFastOr, -0.5, kMaxFastOr - 0.5);
107  fHistosQA->CreateTH1("hFastOrFrequencyL1", "FastOr frequency at Level1", kMaxFastOr, -0.5, kMaxFastOr - 0.5);
108  fHistosQA->CreateTH2("hFastOrAmplitude", "FastOr amplitudes; FastOR Abs ID; Amplitude", kMaxFastOr, -0.5, kMaxFastOr - 0.5, 513, -0.5, 512.5);
109  fHistosQA->CreateTH2("hFastOrTimeSum", "FastOr time sum; FastOR Abs ID; L0 time sum", kMaxFastOr, -0.5, kMaxFastOr - 0.5, 2049, -0.5, 2048.5);
110  fHistosQA->CreateTH2("hFastOrTransverseTimeSum", "FastOr transverse time sum; FastOR Abs ID; L0 transverse time sum", kMaxFastOr, -0.5, kMaxFastOr - 0.5, 2049, -0.5, 2048.5);
111  fHistosQA->CreateTH2("hFastOrNL0Times", "FastOr Number of L0 times; FastOR AbsID; Number of L0 times", kMaxFastOr, -0.5, kMaxFastOr - 0.5, 16, -0.5, 15.5);
112  fHistosQA->CreateTH2("hFastOrColRowFrequencyL0", "FastOr Frequency (col-row) at Level0; col; row", kMaxCol, -0.5, kMaxCol - 0.5, kMaxRow, -0.5, kMaxRow - 0.5);
113  fHistosQA->CreateTH2("hFastOrColRowFrequencyL1", "FastOr Frequency (col-row) at Level1; col; row", kMaxCol, -0.5, kMaxCol - 0.5, kMaxRow, -0.5, kMaxRow - 0.5);
114  fHistosQA->CreateTH2("hEnergyFastorCell", "Sum of cell energy vs. fastor Energy", 1000, 0., 20., 1000 , 0., 20.);
115 
116  // Helper histograms checking the mask status of cells and FastORs
117  fHistosQA->CreateTH1("hMaskedFastors", "Index of masked FastOR; FastOR index; Counts", 3001, -0.5, 3000.5);
118  fHistosQA->CreateTH1("hMaskedCells", "Index of masked cell; Cell index; Counts", 20001, -0.5, 20000.5);
119  fHistosQA->CreateTH1("hCellEnergyCount", "Counts of non-0 cell entries; Cell index; Counts", 20001, -0.5, 20000.5);
120 
121  // THnSparse for fastor-by-fastor energy decalibration
122  TAxis fastorIDAxis(4992, -0.5, 4991.5), offlineaxis(200, 0., 20.), onlineaxis(200, 0., 20.), cellmaskaxis(5, -0.5, 4.5);
123  const TAxis *sparseaxis[4] = {&fastorIDAxis, &offlineaxis, &onlineaxis, &cellmaskaxis};
124  fastorIDAxis.SetNameTitle("fastorAbsID", "FastOR abs. ID");
125  offlineaxis.SetNameTitle("offlinenergy", "E_{2x2 cells} (GeV)");
126  onlineaxis.SetNameTitle("onlineenergy", "E_{FastOR} (GeV)");
127  cellmaskaxis.SetNameTitle("maskedcells", "Number of masked cells");
128  fHistosQA->CreateTHnSparse("hFastOrEnergyOfflineOnline", "FastOr Offline vs Online energy", 4, sparseaxis);
129 
130  TAxis adcAxisL0(2101, -0.5, 2100.5), adcAxisL1(2101, -0.5, 2100.5);
131  const TAxis *adcaxes[3] = {&fastorIDAxis, &adcAxisL0, &adcAxisL1};
132  adcAxisL0.SetNameTitle("adcL0", "L0 ADC amplitude");
133  adcAxisL1.SetNameTitle("adcL1", "L1 ADC amplitude");
134  fHistosQA->CreateTHnSparse("hFastOrADCL0L1", "FastOR ADC in L0 and L1", 3, adcaxes);
135 
136 
137  for(auto h : *(fHistosQA->GetListOfHistograms())) fOutput->Add(h);
138  PostData(1, fOutput);
139 }
140 
142  int nrow = fGeom->GetTriggerMappingVersion() == 2 ? 104 : 64;
143  fCellData.Allocate(48, nrow);
144 
145  if(fNameMaskedCellOADB.Length()){
146  fMaskedCellOADB = new AliOADBContainer("AliEMCALBadChannels");
147  fMaskedCellOADB->InitFromFile(fNameMaskedCellOADB, "AliEMCALBadChannels");
148  }
149 
150  if(fNameMaskedFastorOADB.Length()){
151  fMaskedFastorOADB = new AliOADBContainer("AliEmcalMaskedFastors");
152  fMaskedFastorOADB->InitFromFile(fNameMaskedFastorOADB, "AliEmcalMaskedFastors");
153  }
154 }
155 
157  // Load masked FastOR data
158  if(fMaskedFastorOADB){
159  AliInfoStream() << "Loading masked cells for run " << newrun << std::endl;
160  fMaskedFastors.clear();
161  TObjArray *maskedfastors = static_cast<TObjArray *>(fMaskedFastorOADB->GetObject(newrun));
162  if(maskedfastors && maskedfastors->GetEntries()){
163  for(auto masked : *maskedfastors){
164  TParameter<int> *fastOrAbsID = static_cast<TParameter<int> *>(masked);
165  fMaskedFastors.push_back(fastOrAbsID->GetVal());
166  fHistosQA->FillTH1("hMaskedFastors", fastOrAbsID->GetVal());
167  }
168  std::sort(fMaskedFastors.begin(), fMaskedFastors.end(), std::less<int>());
169  }
170  }
171 
172  // Load masked cell data
173  if(fMaskedCellOADB){
174  AliInfoStream() << "Loading masked cells for run " << newrun << std::endl;
175  fMaskedCells.clear();
176  TObjArray *maskhistos = static_cast<TObjArray *>(fMaskedCellOADB->GetObject(newrun));
177  if(maskhistos && maskhistos->GetEntries()){
178  for(auto mod : *maskhistos){
179  TH2 *modhist = static_cast<TH2 *>(mod);
180  TString modname = modhist->GetName();
181  AliDebugStream(1) << "Reading bad channels from histogram " << modname << std::endl;
182  modname.ReplaceAll("EMCALBadChannelMap_Mod", "");
183  Int_t modid = modname.Atoi();
184  for(int icol = 0; icol < 48; icol++){
185  for(int irow = 0; irow < 24; irow++){
186  if(modhist->GetBinContent(icol, irow) > 0.){
187  int cellindex = fGeom->GetAbsCellIdFromCellIndexes(modid, irow, icol);
188  fMaskedCells.push_back(cellindex);
189  fHistosQA->FillTH1("hMaskedCells", cellindex);
190  }
191  }
192  }
193  }
194  std::sort(fMaskedCells.begin(), fMaskedCells.end(), std::less<int>());
195  }
196  }
197 }
198 
200  // Check trigger
201  if(!(fInputHandler->IsEventSelected() & fRequestTrigger)) return false;
202  if(fTriggerPattern.Length()){
203  if(!TString(InputEvent()->GetFiredTriggerClasses()).Contains(fTriggerPattern)) return false;
204  }
205  return true;
206 }
207 
210  fHistosQA->FillTH1("hEvents", 1);
211  AliVCaloTrigger *triggerdata = InputEvent()->GetCaloTrigger("EMCAL");
212  triggerdata->Reset();
213  Int_t nl0times, l1timesum, fastOrID, globCol, globRow;
214  Float_t amp;
215  while(triggerdata->Next()){
216  triggerdata->GetAmplitude(amp);
217  triggerdata->GetNL0Times(nl0times);
218  triggerdata->GetL1TimeSum(l1timesum);
219  triggerdata->GetPosition(globCol, globRow);
220  fGeom->GetTriggerMapping()->GetAbsFastORIndexFromPositionInEMCAL(globCol, globRow, fastOrID);
221  if(amp > 1e-5){
222  fHistosQA->FillTH2("hFastOrColRowFrequencyL0", globCol, globRow);
223  fHistosQA->FillTH1("hFastOrFrequencyL0", fastOrID);
224  }
225  if(l1timesum){
226  fHistosQA->FillTH2("hFastOrColRowFrequencyL1", globCol, globRow);
227  fHistosQA->FillTH1("hFastOrFrequencyL1", fastOrID);
228  }
229  if(std::find(fMaskedFastors.begin(), fMaskedFastors.end(), fastOrID) == fMaskedFastors.end()){
230  fHistosQA->FillTH2("hFastOrAmplitude", fastOrID, amp);
231  fHistosQA->FillTH2("hFastOrTimeSum", fastOrID, l1timesum);
232  fHistosQA->FillTH2("hFastOrNL0Times", fastOrID, nl0times);
233  fHistosQA->FillTH2("hFastOrTransverseTimeSum", fastOrID, GetTransverseTimeSum(fastOrID, l1timesum, fVertex));
234  fHistosQA->FillTH2("hEnergyFastorCell", fCellData(globCol, globRow), l1timesum * EMCALTrigger::kEMCL1ADCtoGeV);
235  int ncellmasked = 0;
236  int fastorCells[4];
237  fGeom->GetTriggerMapping()->GetCellIndexFromFastORIndex(fastOrID, fastorCells);
238  for(int icell = 0; icell < 4; icell++){
239  if(std::find(fMaskedCells.begin(), fMaskedCells.end(), fastorCells[icell]) != fMaskedCells.end()) ncellmasked++;
240  }
241  double energydata[4] = {
242  static_cast<double>(fastOrID),
243  fCellData(globCol, globRow),
244  static_cast<double>(l1timesum) * EMCALTrigger::kEMCL1ADCtoGeV,
245  static_cast<double>(ncellmasked)
246  };
247  fHistosQA->FillTHnSparse("hFastOrEnergyOfflineOnline", energydata);
248  double adcdata[3] = {
249  static_cast<double>(fastOrID),
250  amp * 4., // correction for the bit shift
251  static_cast<double>(l1timesum)
252  };
253  fHistosQA->FillTHnSparse("hFastOrADCL0L1", adcdata);
254  }
255  }
256  return true;
257 }
258 
260  fCellData.Reset();
261  AliVCaloCells *emccells = InputEvent()->GetEMCALCells();
262  for(int icell = 0; icell < emccells->GetNumberOfCells(); icell++){
263  int position = emccells->GetCellNumber(icell);
264  double amplitude = emccells->GetAmplitude(icell);
265  if(amplitude > 0){
266  fHistosQA->FillTH1("hCellEnergyCount", position);
267  if(std::find(fMaskedCells.begin(), fMaskedCells.end(), position) != fMaskedCells.end()){
268  AliErrorStream() << "Non-0 cell energy " << amplitude << " found for masked cell " << position << std::endl;
269  }
270  int absFastor, col, row;
271  fGeom->GetTriggerMapping()->GetFastORIndexFromCellIndex(position, absFastor);
272  fGeom->GetPositionInEMCALFromAbsFastORIndex(absFastor, col, row);
273  fCellData(col, row) += amplitude;
274  }
275  }
276 }
277 
279  Int_t cellIDs[4];
280  fGeom->GetTriggerMapping()->GetCellIndexFromFastORIndex(fastorAbsID, cellIDs);
281  std::vector<double> eta, phi;
282  for(int i = 0l; i < 4; i++){
283  double etatmp, phitmp;
284  fGeom->EtaPhiFromIndex(cellIDs[i], etatmp, phitmp);
285  eta.push_back(etatmp);
286  phi.push_back(phitmp);
287  }
288 
289  // Calculate FastOR position: for the approximation take mean eta and phi
290  // Radius is taken from the geometry
291  TVector3 fastorPos, vertexPos(vertex[0], vertex[1], vertex[2]);
292  fastorPos.SetPtEtaPhi(fGeom->GetIPDistance(), TMath::Mean(eta.begin(), eta.end()), TMath::Mean(phi.begin(), phi.end()));
293  fastorPos -= vertexPos;
294 
295  TLorentzVector evec(fastorPos, adc);
296  return evec.Et();
297 }
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.
virtual void UserExecOnce()
Initialization of the task.
Base task in the EMCAL framework.
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.
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
virtual bool IsEventSelected()
Perform event selection.
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
float Float_t
Definition: External.C:68
AliEMCALGeometry * fGeom
!emcal geometry
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.
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.
THistManager * fHistosQA
! Histogram handler
AliEmcalList * fOutput
!output list
virtual void UserCreateOutputObjects()
Creating output objects.
Definition: External.C:220
Double_t fVertex[3]
!event vertex
void SetNeedEmcalGeom(Bool_t n)
Container class for histograms.
Definition: THistManager.h:99
void LoadEventCellData()
Load event-dependent cell data.
void UserCreateOutputObjects()
Main initialization function on the worker.
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.