]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/EVCHAR/AliCentralityBy1D.cxx
Moving to ansi isfinite
[u/mrichter/AliRoot.git] / PWG2 / EVCHAR / AliCentralityBy1D.cxx
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
38 ClassImp(AliCentralityBy1D)  
39  
40 //______________________________________________________________________________
41
42
43 AliCentralityBy1D::AliCentralityBy1D() {
44   // standard constructor
45 }
46
47 AliCentralityBy1D::~AliCentralityBy1D() {
48   // destructor
49 }
50
51 void AliCentralityBy1D::AddHisto(TString name) {
52   histnames.push_back(name);
53 }
54
55 void AliCentralityBy1D::SetPercentileFile(TString filename) {
56   outrootfilename = filename;
57 }
58
59 void AliCentralityBy1D::SetPercentileCrossSection(Float_t xsec) {
60   percentXsec = xsec;
61 }
62
63 void AliCentralityBy1D::SetMultLowBound(Float_t mult) {
64   multLowBound = mult;
65 }
66
67 void AliCentralityBy1D::MakePercentiles(TString infilename) {
68   TH1D *thist;
69   
70   TFile *outrootfile;
71   
72   // open inrootfile, outrootfile
73   inrootfile  = new TFile(infilename);
74   outrootfile = new TFile(outrootfilename,"RECREATE");
75   
76   // loop over all distribution names
77   
78   vector<TString>::const_iterator hni;
79   for(hni=histnames.begin(); hni!=histnames.end(); hni++) {
80     thist = MakePercentHisto(*hni);
81     TH1D *htemp  = (TH1D*) (inrootfile->Get(*hni)); 
82     SaveHisto(htemp,thist,outrootfile);
83     delete thist; //??
84   }
85   // close inrootfile, outrootfile
86   inrootfile->Close();
87   outrootfile->Close();
88   
89 }
90
91 TH1D * AliCentralityBy1D::MakePercentHisto(TString hdistributionName) {
92   TH1D *htemp  = (TH1D*) (inrootfile->Get(hdistributionName)); 
93   // TList *list  = (TList*) (inrootfile->Get("chist")); 
94   // TH1D *htemp  = (TH1D*) (list->FindObject(hdistributionName)); 
95   TH1D *hpercent  = (TH1D*) htemp->Clone("hpercent");
96   hpercent->SetName(hdistributionName.Append("_percentile"));
97   hpercent->Reset();
98
99   int start_bin=htemp->FindBin(multLowBound);
100   for (int ibin=1; ibin<=htemp->GetNbinsX(); ibin++) {
101     
102     if (ibin>=start_bin)
103       hpercent->SetBinContent(ibin, percentXsec *
104                               htemp->Integral(ibin,htemp->GetNbinsX())  / 
105                               htemp->Integral(start_bin,htemp->GetNbinsX()));
106     else
107       hpercent->SetBinContent(ibin, 100);
108   }
109   
110   delete htemp;
111   return hpercent;
112   
113 }
114
115 void AliCentralityBy1D::SaveHisto(TH1D *hist1, TH1D *hist2, TFile *outrootfile) {
116   outrootfile->cd();
117   hist1->Write();
118   hist2->Write();
119
120   // int n=12;
121   // Float_t x1[n];
122   // Float_t centrality[]= {0.,5.,10.,20.,30.,40.,50.,60.,70.,80.,90.,100.};
123   // for (int i=n-1; i>=0; i--) {
124   //   x1[i] = hist2->GetBinCenter(hist2->FindLastBinAbove(centrality[i]));
125   //   cout << x1[i] << ",";
126   // }
127   // cout << endl;
128   
129 }
130
131
132