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