AliPhysics  608b256 (608b256)
AliEmcalTriggerSimQATask.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2018, 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 
16 #include <TClonesArray.h>
17 #include <THashList.h>
18 
19 #include <AliVEventHandler.h>
20 #include <AliAnalysisManager.h>
21 #include <AliClusterContainer.h>
22 #include <AliEMCALTriggerPatchInfo.h>
23 
25 
27 ClassImp(AliEmcalTriggerSimQATask);
29 
34 fTriggerPatchesName("EmcalTriggers"),
35 fTriggerPatches(0),
36 fMinAmplitude(0),
37 fMinClusterEnergy(3.),
38 fPtBinWidth(0.5),
39 fMaxPt(120),
40 fEventTriggerBits(0x0),
41 fHistManager("AliEmcalTriggerSimQATask")
42 {}
43 
49 fTriggerPatchesName("EmcalTriggers"),
51 fMinAmplitude(0),
53 fPtBinWidth(0.5),
54 fMaxPt(120),
56 fHistManager(name)
57 {
59 
60  // Initializing array in CINT-compatible way
61  //EventEMCALTriggerType_t fTriggerTypesValues[kNTriggerTypes] = {kMB, kEL0, kEG1, kEG2, kEJ1, kEJ2};
62  EventEMCALTriggerType_t fTriggerTypesValues[kNTriggerTypes] = {kMB, kEL0, kDL0, kEG1, kDG1, kEG2, kDG2, kEJ1, kDJ1, kEJ2, kDJ2};
63  memcpy (fTriggerTypes,fTriggerTypesValues,sizeof(fTriggerTypes));
64 }
65 
66 
71 
72 }
73 
74 
80 }
81 
87 
88  TString histname;
89  TString title;
90 
91  Int_t nPtBins = TMath::CeilNint(fMaxPt/fPtBinWidth);
92 
93  Double_t fMinEta = -0.7;
94  Double_t fMaxEta = 0.7;
95  Double_t fMinDeltaEta = -1.4;
96  Double_t fMaxDeltaEta = 1.4;
97  Double_t fMinPhi = 0;
98  Double_t fMaxPhi = 2*TMath::Pi();
99  Double_t fMinDeltaPhi = -TMath::Pi();
100  Double_t fMaxDeltaPhi = TMath::Pi();
101  Int_t nEtaBins = 96;
102  Int_t nPhiBins = 208;
103  Int_t nDeltaEtaBins = 192;
104  Int_t nDeltaPhiBins = 416;
105 
106  Double_t fMinCol = 0;
107  Double_t fMaxCol = 48;
108  Double_t fMinRow = 0;
109  Double_t fMaxRow = 104;
110  Int_t nCol = 48;
111  Int_t nRow = 104;
112 
113  Double_t fMaxADCValue = 1024;
114  Int_t nADCBins = 512;
115 
116  Int_t nSmallADCBins = 128;
117  Int_t nSmallEBins = 100;
118 
119  // Hist for counting clusters
120  fHistManager.CreateTH1("NClusters","NClusters;N_{cluster}; counts",300,0,300);
121 
122  // loop over trigger types
123  for (Int_t i = 0; i < kNTriggerTypes; i++) {
124  // Clusters in the EMCal (not including DCal)
125  histname = TString::Format("fHistEMCalClusEnergy_Trig_%s",fTriggerNames[i].Data());
126  title = histname + ";#it{E}_{cluster} (GeV); counts";
127  fHistManager.CreateTH1(histname.Data(),title.Data(),nPtBins,0,fMaxPt);
128  // Clusters in the DCal
129  histname = TString::Format("fHistDCalClusEnergy_Trig_%s",fTriggerNames[i].Data());
130  title = histname + ";#it{E}_{cluster} (GeV); counts";
131  fHistManager.CreateTH1(histname.Data(),title.Data(),nPtBins,0,fMaxPt);
132  }
133 
134  for (Int_t i = 0; i < kNTriggerTypes; i++) {
135  histname = TString::Format("fHistClusEtaPhi_Trig_%s",fTriggerNames[i].Data());
136  title = histname + ";#eta_{cluster};#phi_{cluster};counts";
137  fHistManager.CreateTH2(histname.Data(),title.Data(),nEtaBins,fMinEta,fMaxEta,nPhiBins,fMinPhi,fMaxPhi);
138  }
139 
140  for (Int_t i = 1; i < kNTriggerTypes; i++) {
141  histname = TString::Format("fHistPatchEnergy_Trig_%s",fTriggerNames[i].Data());
142  title = histname + ";#it{E}_{patch} (GeV); counts";
143  fHistManager.CreateTH1(histname.Data(),title.Data(),nPtBins,0,fMaxPt);
144  }
145 
146  for (Int_t i = 1; i < kNTriggerTypes; i++) {
147  histname = TString::Format("fHistPatchOnlineADCAmp_Trig_%s",fTriggerNames[i].Data());
148  title = histname + ";#it{E}_{patch} (ADC); counts";
149  fHistManager.CreateTH1(histname.Data(),title.Data(),nADCBins,0,fMaxADCValue);
150  }
151 
152  for (Int_t i = 1; i < kNTriggerTypes; i++) {
153  histname = TString::Format("fHistPatchColRow_Trig_%s",fTriggerNames[i].Data());
154  title = histname + ";Col;Row;counts";
155  fHistManager.CreateTH2(histname.Data(),title.Data(),nCol,fMinCol,fMaxCol,nRow,fMinRow,fMaxRow);
156  }
157  // Patch Geometric Centers
158  for (Int_t i = 1; i < kNTriggerTypes; i++) {
159  histname = TString::Format("fHistPatchEtaPhiGeo_Trig_%s",fTriggerNames[i].Data());
160  title = histname + ";#eta_{patch};#phi_{patch};counts";
161  fHistManager.CreateTH2(histname.Data(),title.Data(),nEtaBins,fMinEta,fMaxEta,nPhiBins,fMinPhi,fMaxPhi);
162  }
163 
164  // Patch Cluster Matching Histograms
165  Int_t nTRU = 0;
166  if (!fGeom) {
167  AliError("Geometry not found. Initializing...");
168  fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
169  if (!fGeom) {
170  AliError("Geometry instance could not be found. Assuming 52 TRU.");
171  nTRU = 52;
172  } else {
173  nTRU = fGeom->GetNTotalTRU();
174  }
175  } else {
176  nTRU = fGeom->GetNTotalTRU();
177  }
178 
179  // Patch Cluster Delta Eta, per TRU
180  for (Int_t i = 1; i < kNTriggerTypes; i++) {
181  histname = TString::Format("fHistClusPatchDEtaTRU_Trig_%s",fTriggerNames[i].Data());
182  title = histname + ";#Delta#eta_{cluster-patch};TRU;counts";
183  fHistManager.CreateTH2(histname.Data(),title.Data(),nDeltaEtaBins,fMinDeltaEta,fMaxDeltaEta,nTRU,0,nTRU);
184  }
185  // Patch Cluster Delta Phi, per TRU
186  for (Int_t i = 1; i < kNTriggerTypes; i++) {
187  histname = TString::Format("fHistClusPatchDPhiTRU_Trig_%s",fTriggerNames[i].Data());
188  title = histname + ";#Delta#phi_{cluster-patch};TRU;counts";
189  fHistManager.CreateTH2(histname.Data(),title.Data(),nDeltaPhiBins,fMinDeltaPhi,fMaxDeltaPhi,nTRU,0,nTRU);
190  }
191 
192  // Patch Cluster Energy, per TRU
193  for (Int_t i = 1; i < kNTriggerTypes; i++) {
194  histname = TString::Format("fHistClusEnergyPatchAmpTRU_Trig_%s",fTriggerNames[i].Data());
195  title = histname + ";E_{clus} (GeV);E_{patch} (ADC);TRU;counts";
196  fHistManager.CreateTH3(histname.Data(),title.Data(),nSmallEBins,0,fMaxPt,nSmallADCBins,0,fMaxADCValue,nTRU,0,nTRU);
197  }
198 
199 
201 }
202 
208  if (!fCaloClusters)
209  {
210  fCaloClusters = (TClonesArray*)GetClusterContainer(0);
211  }
212 
213  return kTRUE;
214 }
215 
221  // Loop over patches, identify which trigger conditions are met
222  DoPatchLoop();
223 
224  // Loop over clusters
225  DoClusterLoop();
226  return kTRUE;
227 }
228 
234  TString ClusterContName = "caloClusters";
235 
236  // Get the pointer to the existing analysis manager via the static access method
237  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
238  if (!mgr) {
239  ::Error("AliEmcalTriggerSimQATask", "No analysis manager to connect to.");
240  return 0;
241  }
242 
243  // Check the analysis type using the event handlers connected to the analysis manager
244  AliVEventHandler *evhand = mgr->GetInputEventHandler();
245  if (!evhand) {
246  ::Error("AliEmcalTriggerSimQATask", "This task requires an input event handler");
247  return 0;
248  }
249 
250  // Init the task and set settings
251  TString taskName("AliEmcalTriggerSimQATask");
252  AliEmcalTriggerSimQATask * eTask = new AliEmcalTriggerSimQATask(taskName);
253  eTask->AddClusterContainer(ClusterContName);
254 
255  mgr->AddTask(eTask);
256  // Create containers for input/output
257  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
258  mgr->ConnectInput(eTask, 0, cinput1);
259 
260  TString commonoutput(Form("%s", AliAnalysisManager::GetCommonFileName()));
261 
262  TString contOutName(Form("%s_histos", taskName.Data()));
263  mgr->ConnectOutput(eTask, 1, mgr->CreateContainer(contOutName, TList::Class(), AliAnalysisManager::kOutputContainer, commonoutput.Data()));
264 
265  return eTask;
266 }
267 
269 
270  Int_t fPatchTriggerBits = 0x0;
271 
272  Bool_t fIsDCal = patch->IsDCalPHOS();
273  // In Trigger Types array, DCal Triggers are 1 more than the EMCal Trigger type
274  Int_t fTriggerInt = 0;
275 
276  if (patch->IsLevel0()) {
277  fTriggerInt = kEL0 + fIsDCal;
278  fPatchTriggerBits |= 0x1 << fTriggerInt;
279  }
280  if (patch->IsGammaHigh()) {
281  fTriggerInt = kEG1 + fIsDCal;
282  fPatchTriggerBits |= 0x1 << fTriggerInt;
283  }
284  if (patch->IsGammaLow()) {
285  fTriggerInt = kEG2 + fIsDCal;
286  fPatchTriggerBits |= 0x1 << fTriggerInt;
287  }
288  if (patch->IsJetHigh()) {
289  fTriggerInt = kEJ1 + fIsDCal;
290  fPatchTriggerBits |= 0x1 << fTriggerInt;
291  }
292  if (patch->IsJetLow()) {
293  fTriggerInt = kEJ2 + fIsDCal;
294  fPatchTriggerBits |= 0x1 << fTriggerInt;
295  }
296  return fPatchTriggerBits;
297 }
298 
300  fEventTriggerBits = 0x0; // Reset
301  fTriggerPatches = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTriggerPatchesName));
302 
303  if (!fTriggerPatches) return;
304 
305  Int_t nPatches = fTriggerPatches->GetEntries();
306 
307  for (Int_t i = 0; i < nPatches; i++) {
308  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
309  if (!patch) continue;
310  if (patch->GetADCAmp() < fMinAmplitude) continue;
311  Bool_t fIsDCal = patch->IsDCalPHOS();
312  // In Trigger Types array, DCal Triggers are 1 more than the EMCal Trigger type
313  Int_t fTriggerInt = 0;
314  if (patch->IsLevel0()) {
315  fTriggerInt = kEL0 + fIsDCal;
316  fEventTriggerBits |= 0x1 << fTriggerInt;
317  FillPatchHistograms(patch,fTriggerInt);
318  }
319  if (patch->IsGammaHigh()) {
320  fTriggerInt = kEG1 + fIsDCal;
321  fEventTriggerBits |= 0x1 << fTriggerInt;
322  FillPatchHistograms(patch,fTriggerInt);
323  }
324  if (patch->IsGammaLow()) {
325  fTriggerInt = kEG2 + fIsDCal;
326  fEventTriggerBits |= 0x1 << fTriggerInt;
327  FillPatchHistograms(patch,fTriggerInt);
328  }
329  if (patch->IsJetHigh()) {
330  fTriggerInt = kEJ1 + fIsDCal;
331  fEventTriggerBits |= 0x1 << fTriggerInt;
332  FillPatchHistograms(patch,fTriggerInt);
333  }
334  if (patch->IsJetLow()) {
335  fTriggerInt = kEJ2 + fIsDCal;
336  fEventTriggerBits |= 0x1 << fTriggerInt;
337  FillPatchHistograms(patch,fTriggerInt);
338  }
339  }
340 }
341 
342 void AliEmcalTriggerSimQATask::FillPatchHistograms(AliEMCALTriggerPatchInfo * patch, Int_t i) {
343  fHistManager.FillTH1(Form("fHistPatchEnergy_Trig_%s",fTriggerNames[i+1].Data()),patch->GetPatchE());
344  fHistManager.FillTH1(Form("fHistPatchOnlineADCAmp_Trig_%s",fTriggerNames[i+1].Data()),patch->GetADCAmp());
345  fHistManager.FillTH2(Form("fHistPatchColRow_Trig_%s",fTriggerNames[i+1].Data()),patch->GetColStart(),patch->GetRowStart());
346  fHistManager.FillTH2(Form("fHistPatchEtaPhiGeo_Trig_%s",fTriggerNames[i+1].Data()),patch->GetEtaGeo(),patch->GetPhiGeo());
347 }
348 
349 
351  TString histname;
352 
354  if (!clusters) {
355  AliError("Cluster Container Not Found");
356  return ;
357  }
358  Int_t nClusters = clusters->GetNClusters();
359  fHistManager.FillTH1("NClusters",nClusters);
360 
361  // Cycle over clusters
362  for (Int_t i = 0; i < nClusters; i++) {
363  AliVCluster * cluster = (AliVCluster *) clusters->GetAcceptCluster(i);
364  if (!cluster) continue;
365  MatchClusterToPatches(cluster);
366  for (Int_t j = 0; j < kNTriggerTypes; j++) {
367  // Check if this event had this trigger
368  if (fTriggerTypes[j] < 0) {
369  // This is Minimum Bias, so accept all events
370  }
371  else if (!(fEventTriggerBits & (0x1 << fTriggerTypes[j]))) {
372  continue;
373  }
374 
375  // Get Cluster vector
376  TLorentzVector vCluster;
377  clusters->GetMomentum(vCluster,cluster);
378  Double_t fPhi = vCluster.Phi();
379  if (fPhi < 0) fPhi+=2*TMath::Pi();
380 
381  // Split Cluster spectra into EMCal, DCal
382  Bool_t isDCal = (fPhi > 4.); // Lazy check
383  if (isDCal) {
384  histname = TString::Format("fHistDCalClusEnergy_Trig_%s",fTriggerNames[j].Data());
385  } else {
386  histname = TString::Format("fHistEMCalClusEnergy_Trig_%s",fTriggerNames[j].Data());
387  }
388  fHistManager.FillTH1(histname,cluster->E());
389 // histname = TString::Format("fHistClusEnergy_Trig_%s",fTriggerNames[j].Data());
390 // fHistManager.FillTH1(histname,cluster->E());
391  histname = TString::Format("fHistClusEtaPhi_Trig_%s",fTriggerNames[j].Data());
392  fHistManager.FillTH1(histname,vCluster.Eta(),fPhi);
393  }
394  }
395 }
396 
398  if (!fTriggerPatches) return;
399  if (!fGeom) return; // Can't run this without geometry
401  if (!clusters) {
402  AliError("Cluster Container Not Found");
403  return ;
404  }
405 
406  Int_t nPatches = fTriggerPatches->GetEntries();
407  for (Int_t i = 0; i < nPatches; i++) {
408  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
409  if (!patch) continue;
410  if (patch->GetADCAmp() < fMinAmplitude) continue;
411  if (cluster->E() < fMinClusterEnergy) continue;
412 
413  TLorentzVector vCluster; // Cluster Vector
414  clusters->GetMomentum(vCluster,cluster);
415 
416  // Cluster, Patch centers
417  Float_t ClusterPhi = vCluster.Phi();
418  Float_t ClusterEta = vCluster.Eta();
419  Float_t PatchPhi = patch->GetPhiGeo();
420  Float_t PatchEta = patch->GetEtaGeo();
421 
422  Float_t DeltaPhi = fmod(ClusterPhi - PatchPhi,2*TMath::Pi());
423  if (DeltaPhi >= TMath::Pi()) DeltaPhi -= 2*TMath::Pi();
424  Float_t DeltaEta = ClusterEta - PatchEta;
425 
426  // Getting TRU info based on patch corner
427  Int_t PatchRow = patch->GetRowStart();
428  Int_t PatchCol = patch->GetColStart();
429 
430  Int_t fAbsId = -1;
431  if (!fGeom->GetAbsFastORIndexFromPositionInEMCAL(PatchCol,PatchRow, fAbsId)) {
432  AliError("Could not find FastOR index from position");
433  }
434  Int_t iTRU = -1;
435  Int_t iADC = -1;
436  if (!fGeom->GetTRUFromAbsFastORIndex(fAbsId, iTRU, iADC)) {
437  AliError(Form("Mapping mismatch: could not find TRU from FastOR Id %d",fAbsId));
438  }
439 
440  Int_t iTriggerClass = GeneratePatchTriggerBits(patch);
441 
442  if (iTriggerClass != 0) {
443  for (Int_t i = 1; i < kNTriggerTypes; i++) {
444  if (!(iTriggerClass & (0x1 << fTriggerTypes[i]))) continue;
445 
446  // Fill These histograms for all pairs:
447  TString histName = TString::Format("fHistClusPatchDEtaTRU_Trig_%s",fTriggerNames[i].Data());
448  fHistManager.FillTH2(histName,DeltaEta,iTRU);
449 
450  histName = TString::Format("fHistClusPatchDPhiTRU_Trig_%s",fTriggerNames[i].Data());
451  fHistManager.FillTH2(histName,DeltaPhi,iTRU);
452  }
453  }
454 
455  // Match Method 1
456  // Check Delta R between patch cluster
457 
458  // Match Method 2
459  // Check if Cluster Center is in Patch
460  Float_t PatchPhiMin = patch->GetPhiMin();
461  Float_t PatchPhiMax = patch->GetPhiMax();
462  Float_t PatchEtaMin = patch->GetEtaMin();
463  Float_t PatchEtaMax = patch->GetEtaMax();
464 
465  if ((PatchPhiMin <= ClusterPhi) && (ClusterPhi <= PatchPhiMax)) {
466  if ((PatchEtaMin <= ClusterEta) && (ClusterEta <= PatchEtaMax)) {
467  // Patch Cluster Matched
468  if (iTriggerClass != 0) {
469  for (Int_t i = 1; i < kNTriggerTypes; i++) {
470  if (!(iTriggerClass & (0x1 << fTriggerTypes[i]))) continue;
471  TString sHistName = TString::Format("fHistClusEnergyPatchAmpTRU_Trig_%s",fTriggerNames[i].Data());
472  fHistManager.FillTH3(sHistName,cluster->E(),patch->GetADCAmp(),iTRU);
473  }
474  }
475  }
476  }
477  }
478 }
479 
480 
double Double_t
Definition: External.C:58
static Double_t DeltaPhi(Double_t phia, Double_t phib, Double_t rMin=-TMath::Pi()/2, Double_t rMax=3 *TMath::Pi()/2)
const char * title
Definition: MakeQAPdf.C:27
Base task in the EMCAL framework.
EventEMCALTriggerType_t fTriggerTypes[kNTriggerTypes]
Trigger type array.
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
void MatchClusterToPatches(AliVCluster *cluster)
void FillTH3(const char *hname, double x, double y, double z, double weight=1., Option_t *opt="")
Fill a 3D histogram within the container.
Float_t fMaxPt
Histogram pt limit.
AliClusterContainer * AddClusterContainer(const char *n)
Create new cluster container and attach it to the task.
const Int_t nPtBins
Float_t fPtBinWidth
Histogram pt bin width.
TClonesArray * fCaloClusters
!clusters
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
void FillPatchHistograms(AliEMCALTriggerPatchInfo *patch, Int_t i)
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
float Float_t
Definition: External.C:68
AliEMCALGeometry * fGeom
!emcal geometry
Int_t fMinAmplitude
Minimum trigger patch amplitude.
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
AliClusterContainer * GetClusterContainer(Int_t i=0) const
Get cluster container attached to this task.
Int_t fEventTriggerBits
! Variable storing trigger bits for entire event, set by DoPatchLoop()
AliVCluster * GetAcceptCluster(Int_t i) const
Int_t GetNClusters() const
Int_t GeneratePatchTriggerBits(AliEMCALTriggerPatchInfo *patch)
const TString fTriggerNames[kNTriggerTypes]
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
TString fTriggerPatchesName
name of input trigger array
static AliEmcalTriggerSimQATask * AddTaskEmcalTriggerSimQA()
THistManager fHistManager
Histogram Manager.
AliEmcalList * fOutput
!output list
void SetMakeGeneralHistograms(Bool_t g)
Enable general histograms.
Bool_t GetMomentum(TLorentzVector &mom, const AliVCluster *vc, Double_t mass) const
virtual void ExecOnce()
Perform steps needed to initialize the analysis.
void UserCreateOutputObjects()
Main initialization function on the worker.
EMCAL trigger simulation QA Task Produces QA histograms for the simulated EMCAL trigger in MC...
bool Bool_t
Definition: External.C:53
Container structure for EMCAL clusters.
Float_t fMinClusterEnergy
Minimum cluster energy.
TH3 * CreateTH3(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, int nbinsz, double zmin, double zmax, Option_t *opt="")
Create a new TH2 within the container.
TClonesArray * fTriggerPatches
! trigger array in