]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/EVCHAR/AliCentralityBy1D.cxx
- fix documentation error
[u/mrichter/AliRoot.git] / PWG2 / EVCHAR / AliCentralityBy1D.cxx
CommitLineData
e6f3f2fe 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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/* Origin: Alberica Toia, CERN, Alberica.Toia@cern.ch */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// class to determine centrality percentiles from 1D distributions //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
24#include <TNamed.h>
25#include <TH1D.h>
26#include <TString.h>
27#include <TFile.h>
28#include <TMath.h>
29#include <TROOT.h>
30#include <TH2F.h>
31#include <TF1.h>
32#include <TStyle.h>
33#include <TGraphErrors.h>
34#include <vector>
35#include "AliCentralityBy1D.h"
36
37
38ClassImp(AliCentralityBy1D)
39
40//______________________________________________________________________________
41
42
43AliCentralityBy1D::AliCentralityBy1D() {
44 // standard constructor
45}
46
47AliCentralityBy1D::~AliCentralityBy1D() {
48 // destructor
49}
50
51void AliCentralityBy1D::AddHisto(TString name) {
52 histnames.push_back(name);
53}
54
55void AliCentralityBy1D::SetPercentileFile(TString filename) {
56 outrootfilename = filename;
57}
58
59void AliCentralityBy1D::SetPercentileCrossSection(Float_t xsec) {
60 percentXsec = xsec;
61}
62
63void AliCentralityBy1D::MakePercentiles(TString infilename) {
64 TH1D *thist;
65
66 TFile *outrootfile;
67
68 // open inrootfile, outrootfile
69 inrootfile = new TFile(infilename);
70 outrootfile = new TFile(outrootfilename,"RECREATE");
71
72 // loop over all distribution names
73
74 vector<TString>::const_iterator hni;
75 for(hni=histnames.begin(); hni!=histnames.end(); hni++) {
76 thist = MakePercentHisto(*hni);
77 SaveHisto(thist,outrootfile);
78 delete thist; //??
79 }
80 // close inrootfile, outrootfile
81 inrootfile->Close();
82 outrootfile->Close();
83
84}
85
86TH1D * AliCentralityBy1D::MakePercentHisto(TString hdistributionName) {
87 TH1D *htemp = (TH1D*) (inrootfile->Get(hdistributionName));
88 TH1D *hpercent = (TH1D*) htemp->Clone("hpercent");
89 hpercent->SetName(hdistributionName.Append("_percentile"));
90 hpercent->Reset();
91
92 for (int ibin=1; ibin<=htemp->GetNbinsX(); ibin++) {
93
94 hpercent->SetBinContent(ibin, percentXsec *
95 htemp->Integral(ibin,htemp->GetNbinsX()) /
96 htemp->Integral(1,htemp->GetNbinsX()));
97
98 }
99
100 delete htemp;
101 return hpercent;
102
103}
104
105void AliCentralityBy1D::SaveHisto(TH1D *hist, TFile *outrootfile) {
106 outrootfile->cd();
107 hist->Write();
108}
109
110
111