AliPhysics  608b256 (608b256)
AliEMCalTriggerWeightHandler.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2014, 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 <TF1.h>
16 #include <TObjArray.h>
17 
19 #include "AliGenPythiaEventHeader.h"
20 #include "AliLog.h"
21 #include "AliMCEvent.h"
22 
25 ClassImp(EMCalTriggerPtAnalysis::AliEMCalTriggerPtHardWeight)
27 
28 namespace EMCalTriggerPtAnalysis {
29 
30 AliEMCalTriggerWeightHandler::AliEMCalTriggerWeightHandler() :
31  TObject(),
32  fWeightModel(nullptr),
33  fBinWeights(nullptr),
34  fUseCrossSection(kFALSE)
35 {
36  /*
37  * See header file for details
38  */
39 }
40 
42  TObject(ref),
46 {
47  /*
48  * See header file for details
49  */
50  if(ref.fWeightModel) fWeightModel = new TF1(*ref.fWeightModel);
51  if(ref.fBinWeights){
52  fBinWeights = new TObjArray;
53  for(auto o : *(ref.fBinWeights)){
54  fBinWeights->Add(o);
55  }
56  }
57 }
58 
61  TObject::operator=(ref);
62  if(this != &ref){
63  if(ref.fWeightModel) fWeightModel = new TF1(*ref.fWeightModel);
64  if(ref.fBinWeights){
65  fBinWeights = new TObjArray;
66  for(auto o : *(ref.fBinWeights)){
67  fBinWeights->Add(o);
68  }
69  }
71  }
72  return *this;
73 }
74 
76  /*
77  * See header file for details
78  */
79  if(fWeightModel) delete fWeightModel;
80  if(fBinWeights) delete fBinWeights;
81 }
82 
83 void AliEMCalTriggerWeightHandler::SetWeightForBin(double ptmin, double ptmax, double weight){
84  /*
85  * See header file for details
86  */
88  // check whether bin already exists
89  AliEMCalTriggerPtHardWeight *exist = NULL, *tmp = NULL;
90  for(TIter biniter = TIter(fBinWeights).Begin(); biniter != TIter::End(); ++biniter){
91  tmp = static_cast<AliEMCalTriggerPtHardWeight *>(*biniter);
92  if(ptmin == tmp->GetPtMin() && ptmax == tmp->GetPtMax()){
93  exist = tmp;
94  break;
95  }
96  }
97  if(exist) exist->SetWeight(weight);
98  else fBinWeights->Add(new AliEMCalTriggerPtHardWeight(ptmin, ptmax, weight));
99 }
100 
101 double AliEMCalTriggerWeightHandler::GetEventWeight(const AliMCEvent* const event) const {
102  /*
103  * See header file for details
104  */
105  const AliGenPythiaEventHeader *header = dynamic_cast<const AliGenPythiaEventHeader *>(event->GenEventHeader());
106  if(!header){
107  AliError("Event not a pythia event - returning 1");
108  return 1.;
109  }
110  return GetEventWeight(header);
111 }
112 
113 double AliEMCalTriggerWeightHandler::GetEventWeight(const AliGenPythiaEventHeader * const header) const {
114  /*
115  * See header file for details
116  */
117  double weight = 1.;
118  if(fWeightModel) {
119  weight = fWeightModel->Eval(header->GetPtHard());
120  } else if(fBinWeights){
121  const AliEMCalTriggerPtHardWeight *tmp = FindWeight(header->GetPtHard());
122  if(tmp) weight = tmp->GetWeight();
123  } else if(fUseCrossSection){
124  // Using cross section
125  weight = header->GetXsection()/static_cast<double>(header->Trials());
126  }
127  return weight;
128 }
129 
131  /*
132  * See header file for details
133  */
134  const AliEMCalTriggerPtHardWeight *result = NULL, *tmp = NULL;
135  for(TIter biniter = TIter(fBinWeights).Begin(); biniter != TIter::End(); ++biniter){
136  tmp = static_cast<const AliEMCalTriggerPtHardWeight *>(*biniter);
137  if(tmp->IsSelected(pthard)){
138  result = tmp;
139  break;
140  }
141  }
142  return result;
143 }
144 
145 } /* namespace EMCalTriggerPtAnalysis */
double Double_t
Definition: External.C:58
const AliEMCalTriggerPtHardWeight * FindWeight(Double_t pthard) const
void SetWeightForBin(double ptmin, double ptmax, double weight)
const Double_t ptmax
const Double_t ptmin
double GetEventWeight(const AliMCEvent *const event) const
TObjArray * fBinWeights
Container for weights in a given pt-hard bin.
Analysis of high- tracks in triggered events.
AliEMCalTriggerWeightHandler & operator=(const AliEMCalTriggerWeightHandler &ref)