AliPhysics  fde8a9f (fde8a9f)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalTriggerOfflineSelection.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 
19 #include <TClonesArray.h>
20 #include <TH2.h>
21 #include <TLorentzVector.h>
22 #include <TRandom.h>
23 
24 #include "AliEMCALTriggerConstants.h"
25 #include "AliEMCALTriggerPatchInfo.h"
27 #include "AliLog.h"
28 #include "AliVEvent.h"
29 
33 
34 namespace EMCalTriggerPtAnalysis {
35 
36 const TString AliEmcalTriggerOfflineSelection::fgkTriggerNames[AliEmcalTriggerOfflineSelection::kTrgn] = {
37  "EMC7", "EG1", "EG2", "EJ1", "EJ2", "DMC7", "DG1", "DG2", "DJ1", "DJ2"
38 };
39 
40 AliEmcalTriggerOfflineSelection::AliEmcalTriggerOfflineSelection():
41  TObject(),
42  fEnergyDefinition(kFEEEnergy),
43  fNameClusterContainer()
44 {
45  for(int itrg = 0; itrg < kTrgn; itrg++) fOfflineEnergyThreshold[itrg] = 100000.; // unimplemented triggers get very high threshold assinged, so that the result is automatically false
46  memset(fAcceptanceMaps, 0, sizeof(TH2 *) * kTrgn);
47 }
48 
50  for(int itrg = 0; itrg < kTrgn; itrg++){
51  if(fAcceptanceMaps[itrg]) delete fAcceptanceMaps[itrg];
52  }
53 }
54 
56  if(fOfflineEnergyThreshold[trgcls] < 0) return true;
57  AliDebugStream(1) << "Applying offline threshold " << fOfflineEnergyThreshold[trgcls] << " for trigger class " << GetTriggerName(trgcls) << std::endl;
58  if(UseClusters()){
59  return ApplyClusterTrigger(trgcls, data);
60  }
61  return ApplyPatchTrigger(trgcls, static_cast<TClonesArray *>(data->FindListObject("EmcalTriggers")));
62 }
63 
64 bool AliEmcalTriggerOfflineSelection::ApplyPatchTrigger(EmcalTriggerClass trgcls, const TClonesArray * const triggerpatches) const {
65  bool isSingleShower = IsSingleShower(trgcls), isDCAL = IsDCAL(trgcls);
66  int nfound = 0;
67  AliEMCALTriggerPatchInfo *patch = NULL;
68  std::vector<double> patchefficiencies;
69  for(auto patchIter : *triggerpatches){
70  patch = static_cast<AliEMCALTriggerPatchInfo *>(patchIter);
71  if(!patch->IsOfflineSimple()) continue;
72  if((isDCAL && !patch->IsDCalPHOS()) || (!isDCAL && patch->IsDCalPHOS())) continue; // reject patches in opposite detector
73  if(isSingleShower){
74  if(!patch->IsGammaLowSimple()) continue;
75  } else {
76  if(!patch->IsJetLowSimple()) continue;
77  }
78  double energy(0);
79  // No switch as only cases for patches are handled in this class
80  if(fEnergyDefinition == kFEEEnergy) energy = patch->GetPatchE();
81  else if(fEnergyDefinition == kFEETransverseEnergy) energy = patch->GetPatchET();
82  else if(fEnergyDefinition == kFEEADC) energy = patch->GetADCOfflineAmp();
83  else if(fEnergyDefinition == kFEETransverseADC) energy = patch->GetPatchET() / EMCALTrigger::kEMCL1ADCtoGeV;
84  if(energy > fOfflineEnergyThreshold[trgcls]){
85  AliDebugStream(2) << GetTriggerName(trgcls) << " patch above threshold (" << patch->GetPatchE() << " | " << fOfflineEnergyThreshold[trgcls] << ")" << std::endl;
86  if(fAcceptanceMaps[trgcls]){
87  // Handle azimuthal inefficiencies of the trigger observed online:
88  // For each patch provide an efficiency. Once all patches in the event
89  // is determined, only the patch with the maximum efficiency is chosen.
90  // The event is selected in this case if the sample value is below the
91  // efficiency for the chosen patch.
92  double peff = fAcceptanceMaps[trgcls]->GetBinContent(patch->GetColStart(), patch->GetRowStart());
93  patchefficiencies.push_back(peff);
94  AliDebugStream(2) << "Spatial Efficiency " << peff
95  << " for trigger patch at position (" << patch->GetColStart()
96  << "," << patch->GetRowStart() << ")" << std::endl;
97  } else{
98  patchefficiencies.push_back(1.);
99  }
100  }
101  }
102  if(patchefficiencies.size()){
103  std::sort(patchefficiencies.begin(), patchefficiencies.end(), std::greater<double>());
104  double sample = gRandom->Uniform(0., 1.);
105  if(sample < patchefficiencies[0]){
106  AliDebugStream(1) << "Event selected for trigger class " << GetTriggerName(trgcls) << ", " << nfound << " good patch(es) found" << std::endl;
107  return true;
108  }
109  }
110  return false;
111 }
112 
113 bool AliEmcalTriggerOfflineSelection::ApplyClusterTrigger(EmcalTriggerClass trgcls, const AliVEvent * const ev) const {
114  int ntrigger = 0;
115  TClonesArray *clusters = static_cast<TClonesArray *>(ev->FindListObject(fNameClusterContainer));
116  double vertex[3]; ev->GetPrimaryVertex()->GetXYZ(vertex);
117  for(auto o : *clusters){
118  AliVCluster *c = dynamic_cast<AliVCluster *>(o);
119  if(!c->IsEMCAL()) continue;
120  // don't apply a time cut in case of simulations
121  double energy = c->GetNonLinCorrEnergy();
123  TLorentzVector vec;
124  c->GetMomentum(vec, vertex);
125  energy = vec.Et();
126  }
127  if(energy > fOfflineEnergyThreshold[trgcls]) ntrigger++;
128  }
129  return ntrigger > 0;
130 }
131 
133  return ((cls == kTrgEG1) || (cls == kTrgEG2) || (cls == kTrgEL0) || (cls == kTrgDG1) || (cls == kTrgDG2) || (cls == kTrgDL0));
134 
135 }
136 
138  return ((cls == kTrgDL0) || (cls == kTrgDG1) || (cls == kTrgDG2) || (cls == kTrgDJ1) || (cls == kTrgDJ2));
139 }
140 
143 }
144 
147 }
148 
149 } /* namespace EMCalTriggerPtAnalysis */
Bool_t IsOfflineSelected(EmcalTriggerClass trgcls, const AliVEvent *const data) const
static const TString & GetTriggerName(EmcalTriggerClass cls)
TCanvas * c
Definition: TestFitELoss.C:172
Helper class selecting events on the presence of a trigger patch for the given type above threshold...
TRandom * gRandom
Double_t fOfflineEnergyThreshold[kTrgn]
Thresholds applied on offline energy.
EmcalTriggerClass
Definition of the various supported trigger types.
energy
Definition: External.C:220
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
bool ApplyPatchTrigger(EmcalTriggerClass trgcls, const TClonesArray *const triggerpatches) const
EmcalEnergyDefinition_t fEnergyDefinition
Define type of energy to be use for the patch selection.
const TH2 * fAcceptanceMaps[kTrgn]
! Online acceptance distribution
bool Bool_t
Definition: External.C:53
bool ApplyClusterTrigger(EmcalTriggerClass trgcls, const AliVEvent *const triggerpatches) const