AliPhysics  2797316 (2797316)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  fWeightModel(NULL),
32  fBinWeights(NULL),
33  fUseCrossSection(kFALSE)
34 {
35  /*
36  * See header file for details
37  */
38 }
39 
41  /*
42  * See header file for details
43  */
44  if(fWeightModel) delete fWeightModel;
45  if(fBinWeights) delete fBinWeights;
46 }
47 
48 void AliEMCalTriggerWeightHandler::SetWeightForBin(double ptmin, double ptmax, double weight){
49  /*
50  * See header file for details
51  */
52  if(!fBinWeights) fBinWeights = new TObjArray;
53  // check whether bin already exists
54  AliEMCalTriggerPtHardWeight *exist = NULL, *tmp = NULL;
55  for(TIter biniter = TIter(fBinWeights).Begin(); biniter != TIter::End(); ++biniter){
56  tmp = static_cast<AliEMCalTriggerPtHardWeight *>(*biniter);
57  if(ptmin == tmp->GetPtMin() && ptmax == tmp->GetPtMax()){
58  exist = tmp;
59  break;
60  }
61  }
62  if(exist) exist->SetWeight(weight);
63  else fBinWeights->Add(new AliEMCalTriggerPtHardWeight(ptmin, ptmax, weight));
64 }
65 
66 double AliEMCalTriggerWeightHandler::GetEventWeight(const AliMCEvent* const event) const {
67  /*
68  * See header file for details
69  */
70  const AliGenPythiaEventHeader *header = dynamic_cast<const AliGenPythiaEventHeader *>(event->GenEventHeader());
71  if(!header){
72  AliError("Event not a pythia event - returning 1");
73  return 1.;
74  }
75  return GetEventWeight(header);
76 }
77 
78 double AliEMCalTriggerWeightHandler::GetEventWeight(const AliGenPythiaEventHeader * const header) const {
79  /*
80  * See header file for details
81  */
82  double weight = 1.;
83  if(fWeightModel) {
84  weight = fWeightModel->Eval(header->GetPtHard());
85  } else if(fBinWeights){
86  const AliEMCalTriggerPtHardWeight *tmp = FindWeight(header->GetPtHard());
87  if(tmp) weight = tmp->GetWeight();
88  } else if(fUseCrossSection){
89  // Using cross section
90  weight = header->GetXsection()/static_cast<double>(header->Trials());
91  }
92  return weight;
93 }
94 
96  /*
97  * See header file for details
98  */
99  const AliEMCalTriggerPtHardWeight *result = NULL, *tmp = NULL;
100  for(TIter biniter = TIter(fBinWeights).Begin(); biniter != TIter::End(); ++biniter){
101  tmp = static_cast<const AliEMCalTriggerPtHardWeight *>(*biniter);
102  if(tmp->IsSelected(pthard)){
103  result = tmp;
104  break;
105  }
106  }
107  return result;
108 }
109 
110 } /* namespace EMCalTriggerPtAnalysis */
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.
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC