AliPhysics  5364b50 (5364b50)
AliAnalysisTaskEtaPhiEfficiency.cxx
Go to the documentation of this file.
1 /*
2  * AliAnalysisTaskEtaPhiEfficiency.cxx
3  *
4  * Created on: Feb 4, 2016
5  * Author: markus
6  */
7 
8 #include <TChain.h>
9 #include <TFile.h>
10 #include <THashList.h>
11 #include <THistManager.h>
12 #include <TKey.h>
13 #include <TList.h>
14 #include <TMath.h>
15 #include <TProfile.h>
16 #include <TString.h>
17 #include <TSystem.h>
18 
19 #include "AliAnalysisManager.h"
20 #include "AliAnalysisUtils.h"
21 #include "AliESDtrackCuts.h"
22 #include "AliESDtrack.h"
23 #include "AliLog.h"
24 #include "AliInputEventHandler.h"
25 #include "AliMCEvent.h"
26 #include "AliMCParticle.h"
27 #include "AliVEvent.h"
28 
30 
31 using namespace EMCalTriggerPtAnalysis;
32 
34 
37  fAnalysisUtil(NULL),
38  fHistos(NULL),
39  fTrackCuts(NULL)
40 {
41 }
42 
44  AliAnalysisTaskSE(name),
45  fAnalysisUtil(NULL),
46  fHistos(NULL),
47  fTrackCuts(NULL)
48 {
49  DefineOutput(1, TList::Class());
50 }
51 
53  if(fAnalysisUtil) delete fAnalysisUtil;
54  if(fTrackCuts) delete fTrackCuts;
55  if(fHistos) delete fHistos;
56 }
57 
59  fAnalysisUtil = new AliAnalysisUtils;
60 
61  fTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2011(true, 1);
62  fTrackCuts->SetName("Standard Track cuts");
63  fTrackCuts->SetMinNCrossedRowsTPC(120);
64  fTrackCuts->SetMaxDCAToVertexXYPtDep("0.0182+0.0350/pt^1.01");
65 
66  fHistos = new THistManager("EfficiencyMaps");
67  fHistos->CreateTH1("hNtrials", "Number of trials", 1, 0.5, 1.5);
68  fHistos->CreateTProfile("hCrossSection", "Cross section", 1, 0.5, 1.5);
69 
70  // make efficiency maps
71  for(int i = 10; i < 100; i += 10){
72  fHistos->CreateTH2(Form("hParticles_%d_%d", i, i + 10), Form("Efficiency Map between %d and %d GeV/c for true particles", i, i + 10), 100, -0.8, 0.8, 100, 0., 2 * TMath::Pi());
73  fHistos->CreateTH2(Form("hTracks_%d_%d", i, i + 10), Form("Efficiency Map between %d and %d GeV/c for reconstructed tracks", i, i + 10), 100, -0.8, 0.8, 100, 0., 2 * TMath::Pi());
74  }
75 
76  PostData(1, fHistos->GetListOfHistograms());
77 }
78 
80  if(!fInputHandler->IsEventSelected() & AliVEvent::kINT7) return;
81  if(fAnalysisUtil->IsFirstEventInChunk(InputEvent())) return;
82  if(fAnalysisUtil->IsPileUpEvent(InputEvent())) return;
83  if(!fAnalysisUtil->IsVertexSelected2013pA(InputEvent())) return;
84 
85  AliESDtrack *track = NULL;
86  AliMCParticle *part = 0;
87  Int_t ptmin, ptmax;
88  for(int ipart = 0; ipart < MCEvent()->GetNumberOfTracks(); ipart++){
89  part = static_cast<AliMCParticle *>(MCEvent()->GetTrack(ipart));
90  if(!part->Charge()) continue;
91  if(!MCEvent()->IsPhysicalPrimary(ipart)) continue;
92  if(TMath::Abs(part->Eta()) > 0.8) continue;
93  if(!FindPtBin(TMath::Abs(part->Pt()), ptmin, ptmax)) continue;
94  fHistos->FillTH2(Form("hParticles_%d_%d", ptmin, ptmax), part->Eta(), part->Phi());
95  }
96  for(int itrk = 0; itrk < InputEvent()->GetNumberOfTracks(); itrk++){
97  track = static_cast<AliESDtrack *>(InputEvent()->GetTrack(itrk));
98  part = static_cast<AliMCParticle *>(MCEvent()->GetTrack(TMath::Abs(track->GetLabel())));
99  if(!MCEvent()->IsPhysicalPrimary(TMath::Abs(part->GetLabel()))) continue;
100  if(TMath::Abs(part->Eta()) > 0.8) continue;
101  if(!fTrackCuts->AcceptTrack(track)) continue;
102  if(!FindPtBin(TMath::Abs(part->Pt()), ptmin, ptmax)) continue;
103  fHistos->FillTH2(Form("hTracks_%d_%d", ptmin, ptmax), part->Eta(), part->Phi());
104 
105  }
106 }
107 
109  // Called when file changes.
110 
111  TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
112  if (!tree) {
113  AliError(Form("%s - UserNotify: No current tree!",GetName()));
114  return kFALSE;
115  }
116 
117  Float_t xsection = 0;
118  Float_t trials = 0;
119  Int_t pthardbin = 0;
120 
121  TFile *curfile = tree->GetCurrentFile();
122  if (!curfile) {
123  AliError(Form("%s - UserNotify: No current file!",GetName()));
124  return kFALSE;
125  }
126 
127  TChain *chain = dynamic_cast<TChain*>(tree);
128  if (chain) tree = chain->GetTree();
129 
130  Int_t nevents = tree->GetEntriesFast();
131 
132  PythiaInfoFromFile(curfile->GetName(), xsection, trials, pthardbin);
133 
134  fHistos->FillTH1("hNtrials", 1., trials);
135  fHistos->FillProfile("hCrossSection", 1., xsection);
136  //fHistos->FillTH1(pthardbin, nevents);
137 
138  return kTRUE;
139 }
140 
141 Bool_t AliAnalysisTaskEtaPhiEfficiency::PythiaInfoFromFile(const char* currFile, Float_t &fXsec, Float_t &fTrials, Int_t &pthard) const {
142 
143  TString file(currFile);
144  fXsec = 0;
145  fTrials = 1;
146 
147  if (file.Contains(".zip#")) {
148  Ssiz_t pos1 = file.Index("root_archive",12,0,TString::kExact);
149  Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
150  Ssiz_t pos2 = file.Index(".root",5,TString::kExact);
151  file.Replace(pos+1,pos2-pos1,"");
152  } else {
153  // not an archive take the basename....
154  file.ReplaceAll(gSystem->BaseName(file.Data()),"");
155  }
156  AliDebug(1,Form("File name: %s",file.Data()));
157 
158  // Get the pt hard bin
159  TString strPthard(file);
160 
161  strPthard.Remove(strPthard.Last('/'));
162  strPthard.Remove(strPthard.Last('/'));
163  if (strPthard.Contains("AOD")) strPthard.Remove(strPthard.Last('/'));
164  strPthard.Remove(0,strPthard.Last('/')+1);
165  if (strPthard.IsDec())
166  pthard = strPthard.Atoi();
167  else
168  AliWarning(Form("Could not extract file number from path %s", strPthard.Data()));
169 
170  // problem that we cannot really test the existance of a file in a archive so we have to live with open error message from root
171  TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root"));
172 
173  if (!fxsec) {
174  // next trial fetch the histgram file
175  fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
176  if (!fxsec) {
177  // not a severe condition but inciate that we have no information
178  return kFALSE;
179  } else {
180  // find the tlist we want to be independtent of the name so use the Tkey
181  TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
182  if (!key) {
183  fxsec->Close();
184  return kFALSE;
185  }
186  TList *list = dynamic_cast<TList*>(key->ReadObj());
187  if (!list) {
188  fxsec->Close();
189  return kFALSE;
190  }
191  fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
192  fTrials = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
193  fxsec->Close();
194  }
195  } else { // no tree pyxsec.root
196  TTree *xtree = (TTree*)fxsec->Get("Xsection");
197  if (!xtree) {
198  fxsec->Close();
199  return kFALSE;
200  }
201  UInt_t ntrials = 0;
202  Double_t xsection = 0;
203  xtree->SetBranchAddress("xsection",&xsection);
204  xtree->SetBranchAddress("ntrials",&ntrials);
205  xtree->GetEntry(0);
206  fTrials = ntrials;
207  fXsec = xsection;
208  fxsec->Close();
209  }
210  return kTRUE;
211 }
212 
214  if(ptin < 10 || ptin > 100) return false;
215  for(double ptiter = 10; ptiter < 100; ptiter += 10){
216  if(ptin >= ptiter && ptin < ptiter + 10){
217  ptmin = static_cast<Int_t>(ptiter);
218  ptmax = static_cast<Int_t>(ptiter + 10);
219  break;
220  }
221  }
222  return true;
223 }
double Double_t
Definition: External.C:58
TSystem * gSystem
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
Bool_t PythiaInfoFromFile(const char *currFile, Float_t &fXsec, Float_t &fTrials, Int_t &pthard) const
TString part
use mixed event to constrain combinatorial background
Definition: InvMassFit.C:52
Bool_t FindPtBin(Double_t ptin, Int_t &ptmin, Int_t &ptmax) const
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 CreateTProfile(const char *name, const char *title, int nbinsX, double xmin, double xmax, Option_t *opt="")
Create a new TProfile within the container.
unsigned int UInt_t
Definition: External.C:33
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
float Float_t
Definition: External.C:68
const Double_t ptmax
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
void FillProfile(const char *name, double x, double y, double weight=1.)
const Double_t ptmin
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
Analysis of high- tracks in triggered events.
TFile * file
TList with histograms for a given trigger.
Int_t nevents[nsamples]
Container class for histograms.
Definition: THistManager.h:99
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53