5 #include <boost/foreach.hpp>
6 #include <boost/algorithm/string/erase.hpp>
12 it->second->SetTitle(
"Mean Cluster Width;tan#theta_{t}");
13 TH1*
const p = it->second;
14 if(p->GetEntries() < 400) {
delete p; book[it->first]=0;
continue;}
15 p->SetTitle(
";tan#theta_{t};");
16 const float min = p->GetMinimum();
17 const float max = p->GetMaximum();
18 float xofmin = p->GetBinCenter(p->GetMinimumBin());
if( xofmin>0.0 || xofmin<-0.15) xofmin = -0.05;
19 const float xofmax = p->GetBinCenter(p->GetMaximumBin());
21 TF1*
const fit =
new TF1(
"LA_profile_fit",
"[2]*(TMath::Abs(x-[0]))+[1]",-1,1);
22 fit->SetParLimits(0,-0.15,0.01);
23 fit->SetParLimits(1, 0.6*min, 1.25*min );
24 fit->SetParLimits(2,0.1,10);
25 fit->SetParameters( xofmin, min, (max-min) / fabs( xofmax - xofmin ) );
27 int badfit = p->Fit(fit,
"IEQ",
"",-.5,.3);
28 if( badfit ) badfit = p->Fit(fit,
"IEQ",
"", -.46,.26);
29 if( badfit ) { book.
erase(it); }
36 const std::string
base = boost::erase_all_copy(it->first,
"_all");
38 std::vector<Book::iterator> rebin_hists;
46 BOOST_FOREACH(
Book::iterator it, rebin_hists)
if(it!=book.
end()) it->second->Rebin( rebin>1 ? rebin<7 ? rebin : 6 : 1);
52 std::vector<TH1*> fit_hists;
55 fit_hists.push_back(prob_w1); prob_w1->SetTitle(
"Width==1 Probability;tan#theta_{t}-(dx/dz)_{reco}");
57 if(var_w2!=book.
end()) {
59 fit_hists.push_back(var_w2->second); var_w2->second->SetTitle(
"Width==2 Mean Variance;tan#theta_{t}-(dx/dz)_{reco}");
60 fit_hists.push_back(rmsv_w2); rmsv_w2->SetTitle(
"Width==2 RMS Variance;tan#theta_{t}-(dx/dz)_{reco}");
62 if(var_w3!=book.
end()) {
64 fit_hists.push_back(var_w3->second); var_w3->second->SetTitle(
"Width==3 Mean Variance;tan#theta_{t}-(dx/dz)_{reco}");
65 fit_hists.push_back(rmsv_w3); rmsv_w3->SetTitle(
"Width==3 RMS Variance;tan#theta_{t}-(dx/dz)_{reco}");
68 if(!fit_hists.size())
continue;
69 const unsigned bins = fit_hists[0]->GetNbinsX();
70 const unsigned guess = fit_hists[0]->FindBin(0);
71 const std::pair<unsigned,unsigned> range(guess-bins/30,guess+bins/30);
73 BOOST_FOREACH(TH1*
const hist, fit_hists) {
75 if(chi2) {book.
book(chi2->GetName(),chi2); chi2->SetTitle(
"Symmetry #chi^{2};tan#theta_{t}-(dx/dz)_{reco}");}
82 const double mean = hist->GetMean();
83 const double rms = hist->GetRMS();
84 const int begin =
std::min( 1, hist->GetXaxis()->FindFixBin(mean-rms));
85 const int end =
std::max(hist->GetNbinsX(), hist->GetXaxis()->FindFixBin(mean+rms)) + 1;
86 unsigned current_hole(0), max_hole(0);
87 for(
int i=begin;
i<
end;
i++) {
88 if(!hist->GetBinError(
i)) current_hole++;
89 else if(current_hole) {max_hole =
std::max(current_hole,max_hole); current_hole=0;}
96 const int bins = prof->GetNbinsX();
97 TH1*
const rms =
new TH1F(name.c_str(),
"",
bins, prof->GetBinLowEdge(1), prof->GetBinLowEdge(bins) + prof->GetBinWidth(bins) );
99 const double Me = prof->GetBinError(
i);
100 const double neff = prof->GetBinEntries(
i);
101 rms->SetBinContent(
i, Me*
sqrt(neff) );
102 rms->SetBinError(
i, Me/
sqrt(2) );
109 const int bins = subset->GetNbinsX();
110 TH1*
const prob =
new TH1F(name.c_str(),
"",
bins, subset->GetBinLowEdge(1), subset->GetBinLowEdge(bins) + subset->GetBinWidth(bins) );
112 const double s = subset->GetBinContent(
i);
113 const double T = total->GetBinContent(
i);
114 const double B = T-
s;
116 const double p = T? s/T : 0;
117 const double perr = T? ( (s&&
B)?
sqrt(s*s*B+B*B*s)/(T*
T) : 1/T ) : 0;
119 prob->SetBinContent(
i,p);
120 prob->SetBinError(
i,perr);
static void fit(Book &book)
static TH1 * subset_probability(const std::string name, const TH1 *const , const TH1 *const )
static void fit_width_profile(Book &)
static TH1 * symmetryChi2(std::string, const std::vector< TH1 * > &, const std::pair< unsigned, unsigned >)
const T & max(const T &a, const T &b)
iterator begin(string_t re=".*")
static std::string method(Method m, bool fit=true)
static unsigned find_rebin(const TH1 *const)
static TH1 * rms_profile(const std::string, const TProfile *const)
static void make_and_fit_symmchi2(Book &)
iterator find(string_t name, string_t re=".*")
void erase(string_t name)
boost::filter_iterator< match_name, book_t::iterator > iterator
iterator end(string_t re=".*")
TH1 * book(string_t name, TH1 *const hist)