本文整理汇总了C++中TF1::Mean方法的典型用法代码示例。如果您正苦于以下问题:C++ TF1::Mean方法的具体用法?C++ TF1::Mean怎么用?C++ TF1::Mean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TF1
的用法示例。
在下文中一共展示了TF1::Mean方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetRandomTest
void GetRandomTest(){
double k0=1.39;
double k1 = 0.425;
double theta0 = 3.41;
double theta1 = 1.30;
int iNpart=2;
double k_=k0+k1*(iNpart-2);
double theta_=theta0+theta1*TMath::Log(iNpart-1);
TF1 *f = new TF1("f","TMath::GammaDist(x,[0],0,[1])",0,200);
f->SetParameters(k1,theta_);
cout<<"Value at 0 = "<<f->Eval(0)<<endl;
cout<<"Value at 1e-11 = "<<f->Eval(1e-11)<<endl;
cout<<"Integral 1= "<<f->Integral(f->GetXmin(),f->GetXmax())<<endl;
f->SetRange(1e-12,200);
cout<<"Integral 2= "<<f->Integral(f->GetXmin(),f->GetXmax())<<endl;
cout<<"fXmin = "<<f->GetXmin()<<"\tfXmax = "<<f->GetXmax()<<"\tfNpx = "<<f->GetNpx()<<endl;
f->SetNpx(1e5);
TCanvas *c1 = new TCanvas();
c1->SetLogy();
cout<<"f mean = "<<f->Mean(0,200)<<endl;
cout<<"math mean = "<<f->GetParameter(0)*f->GetParameter(1)<<endl;
TH1D* h = new TH1D("h","h",1000,0,200);
for(int i=0;i<1e6;i++){
double para = f->GetRandom();
h->Fill(para);
}
h->Scale(1.0/h->Integral()*1000/200);
h->GetYaxis()->SetRangeUser(1e-10,1);
h->SetMarkerStyle(24);
h->SetMarkerColor(4);
h->SetMarkerSize(1.1);
TLegend *leg = new TLegend(0.6,0.7,0.8,0.9);
leg->SetFillColor(0);
leg->SetFillStyle(0);
leg->SetBorderSize(0);
leg->SetTextFont(42);
leg->SetTextSize(0.03);
leg->AddEntry(f,"function","lp");
leg->AddEntry(h,"filled histogram","lp");
h->Draw("P");
f->Draw("same");
leg->Draw("same");
cout<<"h mean = "<<h->GetMean(1)<<endl;
c1->Print("TestGetRandom.png");
}
示例2: SPEFit
void SPEFit(char * fLEDname, char * fPEDname, int run, int LED_amp, double cutmax = 250.0)
{
//set plotting styles
gStyle->SetCanvasColor(0);
gStyle->SetPadColor(0);
gStyle->SetCanvasBorderMode(0);
gStyle->SetFrameBorderMode(0);
gStyle->SetStatColor(0);
gStyle->SetPadTickX(1);
gStyle->SetPadTickY(1);
//set file names
stringstream out_fname;
stringstream out_fname1;
out_fname<<"SPEconstants_Run_"<<run<<".txt";
out_fname1<<"SPEspec_Run_"<<run<<".txt";
ofstream constants_file(out_fname.str().c_str(),ios_base::trunc);
//ofstream constants_file1(out_fname1.str().c_str(),ios_base::trunc);
constants_file<<"Run "<<run<<endl;
constants_file<<"type SPE"<<endl;
constants_file<<"LED_amplitude "<<LED_amp<<endl<<endl;
constants_file<<endl<<"LED_amplitude Depth Phi Eta Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl;
out_fname.str("");
out_fname<<"SPEdistributions_Run_"<<run<<".txt";
out_fname.str("");
out_fname<<"SPEextra_Run_"<<run<<".txt";
//ofstream extra_file(out_fname.str().c_str(),ios_base::trunc);
double scale = 1.0;
scale = 2.6; //Need to scale up HF charge
double fC2electrons = 6240.; //convert fC to #electrons
char spename[128], pedname[128], spehistname[128];
TFile *tfLED = new TFile(fLEDname);
TFile *tfPED = new TFile(fPEDname);
//const int NnewBins = 106;
//double binsX[NnewBins] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,180,190,200,210,220,230,240,250,266,282,298,316,336,356,378,404,430,456,482,500};
const int NnewBins = 80;
double binsX[NnewBins] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,190,200,210,220,230,240,250,266,282,298,316,336,356,378,404,430,456,482,500};
TH1F* hspe = new TH1F("hspe","hspe",NnewBins-1,binsX);
int NDepth = 2; //number of depths
int MinDepth = 1;
int MaxDepth = 2;
int MinEta = 29;
int MaxEta = 41;
int MinPhi = 41;
int MaxPhi = 53;
TCanvas *Carray[NDepth+1][MaxPhi+1];
bool drawflag[NDepth+1][MaxPhi+1];
TH1F *LED[NDepth+1][MaxEta+1][MaxPhi+1];
TH1F *PED[NDepth+1][MaxEta+1][MaxPhi+1];
for(int iDepth = MinDepth; iDepth <= MaxDepth; iDepth++){
for(int iPhi = MinPhi; iPhi <= MaxPhi; iPhi++){
bool nonNull = false;
for(int iEta = MinEta; iEta <= MaxEta; iEta++){
sprintf(spename,"Analyzer/CommonDir/ResPlotDir/Histo_for_Depth_%d_Eta_%d_Phi_%d",iDepth,iEta,iPhi);
LED[iDepth][iEta][iPhi]=(TH1F *)tfLED->Get(spename);
if(LED[iDepth][iEta][iPhi]) nonNull = true;
sprintf(spename,"Analyzer/CommonDir/ResPlotDir/Histo_for_Depth_%d_Eta_%d_Phi_%d",iDepth,iEta,iPhi);
PED[iDepth][iEta][iPhi]=(TH1F *)tfPED->Get(spename);
}
drawflag[iDepth][iPhi] = false;
char canvname[16];
sprintf(canvname, "c_%d_%d", iDepth,iPhi);
if(nonNull){ //only create canvas if distributions exist
Carray[iDepth][iPhi] = new TCanvas(canvname,canvname,1200,700);
Carray[iDepth][iPhi]->Divide(5,3);
}
}
}
int HV=0;
for(int iDepth = MinDepth; iDepth <= MaxDepth; iDepth++){
for(int iPhi = MinPhi; iPhi <= MaxPhi; iPhi++){
for(int iEta = MinEta; iEta <= MaxEta; iEta++){
//.........这里部分代码省略.........
示例3: SPEFit_UXC_Ana_V2
// filname : output file name
// pmode : pedestal mode
// mode :
void SPEFit_UXC_Ana_V2(int run=254743, TString filname="test", bool pmode=false, int mode=1)
{
/*mode 1: TH1F * HistoSum[2][72][13]; // integral of TS 2-5
mode 2: TH1F * HistoFullSum[2][72][13]; // integral of TS 0-9
mode 3: TH1F * HistoEachTS[2][72][13]; // no sum but each TS
mode 4: TH1F * HistoEachTSsub[2][72][13]; // no sum but ecah TS(2-5)
mode5-15 TH1F * HistoSeparateTS[2][72][13][mode-5] // draw only TS = mode-5
*/
TString fLEDname = Form("Run_%i.root",run);
TString fPEDname = fLEDname;
TString rootname = filname+"_mode_";
rootname+=mode;
rootname+=".root";
pedmode=pmode;
int LED_amp=40;
_hstFile = new TFile(rootname,"recreate");
BookHistograms();
GetHFPMap();
//set plotting styles
gStyle->SetCanvasColor(0);
gStyle->SetPadColor(0);
gStyle->SetCanvasBorderMode(0);
gStyle->SetFrameBorderMode(0);
gStyle->SetStatColor(0);
gStyle->SetPadTickX(1);
gStyle->SetPadTickY(1);
//set file names
stringstream out_fname;
stringstream out_fname1;
out_fname<<"SPEconstants_Run_"<<run<<"_"<<filname<<"_mode_"<<mode<<".txt";
out_fname1<<"SPEspec_Run_"<<run<<"_"<<filname<<".txt";
ofstream constants_file(out_fname.str().c_str(),ios_base::trunc);
//ofstream constants_file1(out_fname1.str().c_str(),ios_base::trunc);
constants_file<<"#Run "<<run<<endl;
constants_file<<"#type SPE"<<endl;
constants_file<<"#LED_amplitude "<<LED_amp<<endl;
constants_file<<"#Robox Column iDepth iPhi iEta Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err"<<endl;
out_fname.str("");
out_fname<<"SPEdistributions_Run_"<<run<<".txt";
out_fname.str("");
out_fname<<"SPEextra_Run_"<<run<<".txt";
//ofstream extra_file(out_fname.str().c_str(),ios_base::trunc);
double scale = 1.0;
scale = 2.6; //Need to scale up HF charge
double fC2electrons = 6240.; //convert fC to #electrons
char spename[128], pedname[128], spehistname[128], numname[128];
TFile *tfLED = new TFile(fLEDname);
TFile *tfPED = new TFile(fPEDname);
//const int NnewBins = 106;
//double binsX[NnewBins] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,180,190,200,210,220,230,240,250,266,282,298,316,336,356,378,404,430,456,482,500};
//const int NnewBins = 80;//75
//double binsX[NnewBins] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,190,200,210,220,230,240,250,266,282,298,316,336,356,378,404,430,456,482,500};
const int NnewBins = 101;//75
double binsX[NnewBins] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100};
const int NnewBins_single = 57;
double binsX_single[NnewBins] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,45,51,57,63,69,75,81,87,93,99,105,111,117,123,129,135,141,147,153,159,165,171,177,183,190,200,210,220,230,240,250,266,282,298,316,336,356,378,404,430,456,482,500};
//default:
const int NnewBins_ped = 46;//75
double binsX_ped[NnewBins] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,120,138,156,174,200,230,266,316,378,456,500};
double binsX_ped_single[NnewBins] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,45,51,57,63,69,75,81,87,93,99,120,138,156,174,200,230,266,316,378,456,500};
const int NnewBins_ped_single = 31;
//var1
// const int NnewBins_ped = 37;//75
// double binsX_ped[NnewBins_ped] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,200,350,500};
//double binsX[NnewBins] = {0,6,12,18,24,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,190,200,210,220,230,240,250,266,282,298,316,336,356,378,404,430,456,482,500};
TH1F *hspe[8], *resid[8];
if(!pedmode) {
if(mode<3){
for(int i=0; i<8; i++) hspe[i] = new TH1F(Form("hspe_pmt%i",i+1),Form("hspe_pmt%i",i+1),NnewBins-1,binsX);
for(int i=0; i<8; i++) resid[i] = new TH1F(Form("resid_pmt%i",i+1),Form("resid_pmt%i",i+1),NnewBins-1,binsX);
}
else{
for(int i=0; i<8; i++) hspe[i] = new TH1F(Form("hspe_pmt%i",i+1),Form("hspe_pmt%i",i+1),NnewBins_single-1,binsX_single);
for(int i=0; i<8; i++) resid[i] = new TH1F(Form("resid_pmt%i",i+1),Form("resid_pmt%i",i+1),NnewBins_single-1,binsX_single);
}
}
else if(pedmode) {
if(mode<3){
for(int i=0; i<8; i++) hspe[i] = new TH1F(Form("hspe_pmt%i",i+1),Form("hspe_pmt%i",i+1),NnewBins_ped-1,binsX);
for(int i=0; i<8; i++) resid[i] = new TH1F(Form("resid_pmt%i",i+1),Form("resid_pmt%i",i+1),NnewBins_ped-1,binsX);
//.........这里部分代码省略.........
示例4: SPEFit
void SPEFit(char * fname, int run, int LED_amp, double cutmax = 250.0)
{
//set plotting styles
gStyle->SetCanvasColor(0);
gStyle->SetPadColor(0);
gStyle->SetCanvasBorderMode(0);
gStyle->SetFrameBorderMode(0);
gStyle->SetStatColor(0);
gStyle->SetPadTickX(1);
gStyle->SetPadTickY(1);
//set file names
stringstream out_fname;
stringstream out_fname1;
out_fname<<"SPEconstants_Run_"<<run<<".txt";
out_fname1<<"SPEspec_Run_"<<run<<".txt";
ofstream constants_file(out_fname.str().c_str(),ios_base::trunc);
ofstream constants_file1(out_fname1.str().c_str(),ios_base::trunc);
constants_file<<"Run "<<run<<endl;
constants_file<<"type SPE"<<endl;
constants_file<<"LED_amplitude "<<LED_amp<<endl<<endl;
//constants_file<<endl<<"LED_amplitude HV Spigot Channel Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl;
constants_file<<endl<<"LED_amplitude HV Spigot Channel Ped_mean Ped_mean_err Ped_RMS Ped_RMS_err SPEPeak_RMS SPEPeak_RMS_err Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag Polya_shape Polya_shape_err Polya_mode"<<endl;
out_fname.str("");
out_fname<<"SPEdistributions_Run_"<<run<<".txt";
out_fname.str("");
out_fname<<"SPEextra_Run_"<<run<<".txt";
//ofstream extra_file(out_fname.str().c_str(),ios_base::trunc);
//extra_file<<endl<<"LED_amplitude HV Spigot Channel PedSubtracted_mean Gain Gain_err Normalized_Chi2 MeanPE_fit MeanPE_fit_err MeanPE_estimate PE5flag"<<endl;
double scale = 1.0;
scale = 2.6; //Need to scale up HF charge
double fC2electrons = 6240.; //convert fC to #electrons
char spename[128], pedname[128], spehistname[128];
bool drawflag;
TFile *tf = new TFile(fname);
TCanvas *c1 = new TCanvas("c1","c1",1200,700);
c1->Divide(6,4);
c1->SetBorderMode(0);
c1->SetBorderSize(0);
TCanvas *c2 = new TCanvas("c2","c2",1200,700);
c2->Divide(6,4);
c2->SetBorderMode(0);
c2->SetBorderSize(0);
TCanvas *c3 = new TCanvas("c3","c3",1200,700);
c3->Divide(6,4);
c3->SetBorderMode(0);
c3->SetBorderSize(0);
const int NnewBins = 106;
double binsX[NnewBins] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,180,190,200,210,220,230,240,250,266,282,298,316,336,356,378,404,430,456,482,500};
TH1F* hspe = new TH1F("hspe","hspe",NnewBins-1,binsX);
int Npoints;
TH2D *tmp;
for(Npoints=0;Npoints<10;Npoints++){
sprintf(spename,"spetest/spigot_%d/bb_%d/LED_HVset_%d_sp_%d_BB_%d",0,1,Npoints,0,1);
tmp=(TH2D *)tf->Get(spename);
if(tmp==0) break;
}
TH2D *LED[3][3][20];
TH2D *PED[3][3];
for(int iSpig = 0; iSpig < 3; iSpig++)for(int bb = 1; bb < 4; bb++){
for(int ii=0; ii<Npoints; ii++){
sprintf(spename,"spetest/spigot_%d/bb_%d/LED_HVset_%d_sp_%d_BB_%d",iSpig,bb,ii,iSpig,bb);
LED[iSpig][bb-1][ii]=(TH2D *)tf->Get(spename);
}
sprintf(spename,"spetest/spigot_%d/bb_%d/PED_sp_%d_BB_%d",iSpig,bb,iSpig,bb);
PED[iSpig][bb-1]=(TH2D *)tf->Get(spename);
}
for(int ii=0; ii<Npoints; ii++) {
drawflag=false;
int HV=0;
for (int iSpig = 0; iSpig < 3; iSpig++) {
for(int i = 0; i < 24; i++) {
int bb=BB_MAP[i];
int pmt=PMT_MAP[i];
sprintf(spehistname,"led %d %d %d",ii,iSpig,i);
TH1D *hspe_temp = (TH1D *)LED[iSpig][bb-1][ii]->ProjectionX(spehistname,pmt,pmt,"")->Clone();
sprintf(spehistname,"ped %d %d %d",ii,iSpig,i);
TH1D *hped = (TH1D *)PED[iSpig][bb-1]->ProjectionX(spehistname,pmt,pmt,"")->Clone();
sscanf(&hspe_temp->GetTitle()[7],"%d",&HV);
hspe->Reset();
sprintf (spehistname, "SumLED%d_sp_%d_ch_%d", HV, iSpig, i);
hspe->SetTitle(spehistname);
//combine bins of original SPE histogram
//.........这里部分代码省略.........