本文整理汇总了C++中TFitResultPtr::Chi2方法的典型用法代码示例。如果您正苦于以下问题:C++ TFitResultPtr::Chi2方法的具体用法?C++ TFitResultPtr::Chi2怎么用?C++ TFitResultPtr::Chi2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFitResultPtr
的用法示例。
在下文中一共展示了TFitResultPtr::Chi2方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: covmat
hw()
{
Float_t data;
TFile *f=new TFile("data.root");
TTree* tree = f->Get("mytree");
TBranch* branch = tree->GetBranch("data");
branch->SetAddress(&data);
TH1F* h1 = new TH1F("h1","h1",200,0.0,5.0);
for(Int_t i= 0 ; i< tree->GetEntries() ; i++) {
tree->GetEntry(i);
h1->Fill( data) ;
}
TF1 *f2 = new TF1("f2", "[0]*x+[1]+gaus(2)", 0.0, 5.0);
f2->SetParameter(3,3.7);
TVirtualFitter *min = TVirtualFitter::Fitter(0,2);
TVirtualFitter::SetDefaultFitter("Minuit");
TFitResultPtr fitresult = h1->Fit("f2", "MES");
cout<< "Parameter 0" << fitresult->Parameter(0) << "+-" << fitresult->ParError(0) << endl;
cout<< "Parameter 1" <<fitresult->Parameter(1) << "+-" << fitresult->ParError(1) << endl;
cout << "Chi2 " << fitresult->Chi2() << endl;
cout << "NDF " << fitresult->Ndf() << endl;
cout << "Chi2 probability " << fitresult->Prob() << endl;
TMatrixD covmat(fitresult->GetCovarianceMatrix());
cout << "Covariance matrix" << endl;
covmat.Print();
TCanvas *c1 = new TCanvas("c1", "binned line fit", 600, 600);
c1->Draw();
h1->Draw();
}
示例2: analyzeInclusivejet
//.........这里部分代码省略.........
TTree* ic5t = (TTree*)inf->Get("icPu5JetAnalyzer/t");
TTree* t = (TTree*)inf->Get("hltanalysis/HltTree");
ic5t->SetBranchAddress("jtpt",jtpt_ic5);
ic5t->SetBranchAddress("jteta",jteta_ic5);
ic5t->SetBranchAddress("jtphi",jtphi_ic5);
ic5t->SetBranchAddress("nref",&njets_ic5);
TTree* ak3t = (TTree*)inf->Get("akPu3PFJetAnalyzer/t");
ak3t->SetBranchAddress("jtpt",jtpt_ak3);
ak3t->SetBranchAddress("jteta",jteta_ak3);
ak3t->SetBranchAddress("jtphi",jtphi_ak3);
ak3t->SetBranchAddress("nref",&njets_ak3);
t->SetBranchAddress("Run",&run);
t->SetBranchAddress("Event",&evt);
t->SetBranchAddress("hiBin",&bin);
TString outname = "JetSkimTree.root";
int Nevents = t->GetEntries();
for(int iev = 0; iev < Nevents; ++iev){
t->GetEntry(iev);
ic5t->GetEntry(iev);
ak3t->GetEntry(iev);
for(int i = 0; i < njets_ak3; ++i){
//if(jtpt_ak3[i] < cutPtJet) continue;
if(fabs(jteta_ak3[i]) > cutEtaJet) continue;
hak3pujet->Fill(jtpt_ak3[i]);
}//1st for loop
int id=0;
for(int i = 0; i < njets_ak3; ++i){
if(fabs(jteta_ic5[i]) < cutEtaJet)
id =1;
}// 2nd for loop
if(id == 1){
for(int i = 0; i < njets_ak3; ++i){
if(jtpt_ic5[i] < cutPtJet) continue;
//if(jtpt_ak3[i] < cutPtJet) continue;
if(fabs(jteta_ak3[i]) > cutEtaJet) continue;
hak3pujet_cut->Fill(jtpt_ak3[i]);
}
}// if loop
}//evt loop
TCanvas *c1 = new TCanvas("c1", "",46,477,700,509);
c1->Range(-125,-11.1492,1125,3.24528);
c1->SetBorderSize(0);
c1->SetBorderMode(0);
c1->SetLeftMargin(0.16);
c1->SetTopMargin(0.06);
c1->SetBottomMargin(0.17);
c1->SetTicks(1,1);
gROOT->LoadMacro("erf.C");
TGraphAsymmErrors *dividedthingy= new TGraphAsymmErrors;
dividedthingy->BayesDivide(hak3pujet_cut,hak3pujet);
float xstart=20.0;
float xend=300.0;
TF1 *fitfcn = new TF1("fitfcn",erf,xstart,xend,2); //<============
fitfcn->SetParameter(0,40); //<=============
TFitResultPtr results =dividedthingy->Fit("fitfcn","VSR");
cout << "Chi2: " << results->Chi2() << " / " << results->Ndf() << " NDF" << endl;
float turnon=fitfcn->GetX(0.99,10,300);
cout << "99% at: " << turnon << endl;
char turnontext[50]="";
sprintf(turnontext," ak5pu at %4.1f",turnon);
dividedthingy->GetFunction("fitfcn")->SetLineColor(3);
dividedthingy->SetLineColor(1);
dividedthingy->Draw("Ap");
TText *t2 = new TText(95,0.08,turnontext);
t2->SetTextSize(0.055);
t2->SetTextColor(1);
t2->Draw();
}
示例3: bToDRawYield
//.........这里部分代码省略.........
fitStatus = fitResult->Status();
cout<<"fit precision: "<<TFitter::GetPrecision()<<" status: "<<fitStatus<<endl;
if(fitStatus)
fitPrecision *= 10;
}
cout<<"============== do main fit ============"<<endl;
fMix->SetParameters(integralTotalYield,0.9);
fMix->SetParError(0,0.1*integralTotalYield);
fMix->SetParError(1,0.1);
fMix->SetNpx(10000);
fitResult = hD0DcaData->Fit("fMix","E S0", "", fitRangeL, fitRangeH);
hD0DcaData->GetFunction("fMix")->Draw("flsame");
fitStatus = fitResult->Status();
cout<<"fit precision: "<<TFitter::GetPrecision()<<" status: "<<fitStatus<<endl;
TF1* fNP = new TF1("fNP",&funNonPrompt, 0., 0.5, 2);
fNP->SetParameters(fMix->GetParameter(0),fMix->GetParameter(1));
fNP->SetRange(fitRangeL,fitRangeH);
fNP->SetLineColor(4);
fNP->SetFillStyle(1001);
fNP->SetFillColor(kBlue-9);
fNP->SetNpx(10000);
fNP->Draw("same");
hD0DcaData->Draw("same");
promptDYield[i-1] = fMix->GetParameter(0);
promptDYieldErrorDataOnly[i-1] = fMix->GetParError(0);
bToDYield[i-1] = fMix->GetParameter(1);
bToDYieldErrorDataOnly[i-1] = fMix->GetParError(1);
totalYield[i-1] = promptDYield[i-1]+bToDYield[i-1];
promptFraction[i-1] = promptDYield[i-1]/totalYield[i-1];
cout<<"chi2 / NDF: "<<fitResult->Chi2()<<" / "<<fitResult->Ndf()<<endl;
texCms->Draw();
texCol->Draw();
texPtY->Draw();
TLatex* texPrompt = new TLatex(0.4,0.73,Form("Prompt D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(0),fMix->GetParError(0)));
texPrompt->SetNDC();
texPrompt->SetTextFont(42);
texPrompt->SetTextSize(0.06);
texPrompt->SetLineWidth(2);
texPrompt->Draw();
TLatex* texNonPrompt = new TLatex(0.4,0.65,Form("B to D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(1),fMix->GetParError(1)));
texNonPrompt->SetNDC();
texNonPrompt->SetTextFont(42);
texNonPrompt->SetTextSize(0.06);
texNonPrompt->SetLineWidth(2);
texNonPrompt->Draw();
TLegend* leg4 = new TLegend(0.56,0.38,0.90,0.62);
leg4->SetBorderSize(0);
leg4->SetTextSize(0.06);
leg4->SetTextFont(42);
leg4->SetFillStyle(0);
leg4->AddEntry(hD0DcaData,"Data","pl");
leg4->AddEntry(fMix,"Prompt D^{0}","f");
leg4->AddEntry(fNP,"B to D^{0}","f");
leg4->Draw("same");
//smear MC smaple with the error, to simulate the MC statistic error effect.
c4->cd(3);
示例4: FitPeak
bool FitPeak(Double_t *par, TH1 *h, Float_t &area, Float_t &darea){
Double_t binWidth = h->GetXaxis()->GetBinWidth(1000);//Need to find the bin widths so that the integral makes sense
Int_t rw = binWidth*20; //This number may change depending on the source used
//Set the number of iterations. The code is pretty quick, so having a lot isn't an issue
TVirtualFitter::SetMaxIterations(4999);
Int_t xp = par[1];
//Define the fit function and the range of the fit
TF1 *pp = new TF1("photopeak",fitFunction,xp-rw,xp+rw,10);
//Name the parameters so it is easy to see what the code is doing
pp->SetParName(0,"Height");
pp->SetParName(1,"centroid");
pp->SetParName(2,"sigma");
pp->SetParName(3,"beta");
pp->SetParName(4,"R");
pp->SetParName(5,"step");
pp->SetParName(6,"A");
pp->SetParName(7,"B");
pp->SetParName(8,"C");
pp->SetParName(9,"bg offset");
//Set some physical limits for parameters
pp->SetParLimits(1,xp-rw,xp+rw);
pp->SetParLimits(3,0,30);
pp->SetParLimits(4,0,10);
pp->SetParLimits(5,0.000,1000000);
pp->SetParLimits(9,xp-20,xp+20);
//Actually set the parameters in the photopeak function
pp->SetParameters(par);
// pp->FixParameter(4,0);
// pp->FixParameter(5,0);
pp->SetNpx(1000); //Draws a nice smooth function on the graph
TFitResultPtr fitres = h->Fit("photopeak","RFS");
pp->Draw("same");
pp->GetParameters(&par[0]);
TF1 *photopeak = new TF1("photopeak",photo_peak,xp-rw,xp+rw,10);
photopeak->SetParameters(par);
Double_t integral = photopeak->Integral(xp-rw,xp+rw)/binWidth;
std::cout << "FIT RESULT CHI2 " << fitres->Chi2() << std::endl;
std::cout << "FWHM = " << 2.35482*fitres->Parameter(2)/binWidth <<"(" << fitres->ParError(2)/binWidth << ")" << std::endl;
std::cout << "NDF: " << fitres->Ndf() << std::endl;
std::cout << "X sq./v = " << fitres->Chi2()/fitres->Ndf() << std::endl;
TVirtualFitter *fitter = TVirtualFitter::GetFitter();
assert(fitter != 0); //make sure something was actually fit
Double_t * covMatrix = fitres->GetCovarianceMatrix(); //This allows us to find the uncertainty in the integral
Double_t sigma_integral = photopeak->IntegralError(xp-rw,xp+rw)/binWidth;
std::cout << "Integral = " << integral << " +/- " << sigma_integral << std::endl;
area = integral;
darea = sigma_integral;
if(fitres->Chi2()/fitres->Ndf() > 5.0)
return false;
return true;
// myFitResult.fIntegral = integral;
// return photopeak;
}
示例5: fitter
//.........这里部分代码省略.........
f_pdf ->Draw();
// Save canvas in .pdf and .epr format
c_pdf_gen->Print("./_fig/pdf_gen.pdf");
c_pdf_gen->Print("./_fig/pdf_gen.eps");
// ######################################################################
// ##################### Data sample generation #########################
// ######################################################################
//Create Canvas
TCanvas *c_histo_gen = new TCanvas("c_histo_gen","canvas histo",500,500);
c_histo_gen->cd();
//Create Histrogram
TH1F *histo_gen = new TH1F("histo","",100,a_min,a_max);
//Fill the histogram
Double_t x_var;
Double_t y_var;
Int_t i;
i=0;
while(i<N){
x_var= a_min + (a_max - a_min)*randGen.Uniform();
y_var= 0.4 * randGen.Uniform();
if(y_var < f_pdf->Eval(x_var)){
histo_gen->Fill(x_var);
i++;
};
};
// Set histogram Axis Labels
histo_gen->GetXaxis()->SetTitle("Invariant mass [GeV/#font[10]{c^{2}}] ");
histo_gen->GetYaxis()->SetTitle("Events per 0.1 GeV/#font[10]{c^{2}} ");
// Plot the histogram
histo_gen -> Draw();
// Save canvas in .pdf and .epr format
c_histo_gen->Print("./_fig/histo_gen.pdf");
c_histo_gen->Print("./_fig/histo_gen.eps");
// ######################################################################
// ############################# Fitter #################################
// ######################################################################
// Create Function
TF1 *f_pdf_fit = new TF1("f_pdf_fit",pdf_fit,a_min,a_max,8);
// Set Initial Parameters (usually you don't know precisely them!!!)
f_pdf_fit->SetParameter(0, 100000 );//N
f_pdf_fit->SetParameter(1, 0.3 );//fs
f_pdf_fit->SetParameter(2, 0.7 );//fA
f_pdf_fit->SetParameter(3, 4. );//mA
f_pdf_fit->SetParameter(4, 0.3 );//sA
f_pdf_fit->SetParameter(5, 5. );//mB
f_pdf_fit->SetParameter(6, 0.3 );//sB
f_pdf_fit->SetParameter(7, -0.5 );//slope
f_pdf_fit->SetParNames("N","fs","fA","mA","sA","mB","sB","slope");
cout << "##################### Minimal Fit ##################" << endl;
// For more details please take a look at the ROOT Referecence Guide
// In particular for TH1 --> http://root.cern.ch/root/html/TH1.html#TH1:Fit
// In particular for TGraph and TGraphErrors --> https://root.cern.ch/root/html/TGraph.html
histo_gen -> Fit(f_pdf_fit,"","",a_min,a_max);
Double_t fit_chi2 = f_pdf_fit->GetChisquare();
Int_t fit_ndof = f_pdf_fit->GetNDF();
Double_t fit_prob = f_pdf_fit->GetProb();
cout << "chi2 = " << fit_chi2 << endl;
cout << "ndof = " << fit_ndof << endl;
cout << "prob = " << fit_prob << endl;
cout << "##################### Fit and Covariance Matrix ##################" << endl;
// To access coveriance matrix and other fit information
TFitResultPtr r = histo_gen->Fit(f_pdf_fit,"S","",a_min,a_max); //Fit(myFunc,"S");
TMatrixDSym cov = r->GetCovarianceMatrix(); // to access the covariance matrix
Double_t chi2 = r->Chi2(); // to retrieve the fit chi2
Double_t par0 = r->Parameter(0); // retrieve the value for the parameter 0
Double_t err0 = r->ParError(0); // retrieve the error for the parameter 0
r->Print("V"); // print full information of fit including covariance matrix
cout << endl;
cout << "chi2 = " << chi2 << endl;
cout << "par0 = " << par0 << endl;
cout << "err0 = " << err0 << endl;
cout << "cov(2,3)=" << cov(2,3) << endl;
// Save canvas in .pdf and .epr format
c_histo_gen->Print("./_fig/histo_fit.pdf");
c_histo_gen->Print("./_fig/histo_fit.eps");
}
示例6: if
void WaveformAna3Tcell::analyze3TCellWaveform(bool &hit, float &stepSize, float &timeConstant, float &hitDetectionTime, float &offset, float &slope, float &chi2)
{
if(!_wave)
return;
// filter data
if (!_wave->isFiltered())
_wave->applyLowPassFilter(_avgBufLen);
// check for hit
_hit = checkForHit(_cutSimpleThreshold);
int hitStartTime = 0;
if(_hit){
hitStartTime = getHitStartTime(_cutTime, _cutTimeThreshold);
if(!_hit && (hitStartTime == 0))
{ //no hit, go out!
return;
}
else
{
stepSize = 0;
timeConstant = 0;
// cout << "\tDetected " << hitCnt << " hits" << endl;
stepSize = 0.04;
timeConstant = hitStartTime;
//showWaveform(_waveOrig);
//Fit parameters:
double par[5];
par[0]= _wave->getAmpl()[hitStartTime]; //Offset of linear w/o hit --> Charge collected by leakage current
par[1]= -0.000001; //(_wave->getAmpl()[_avgBufLen*10] - _wave->getAmpl()[hitStartTime])/(double)(_wave->getTime()[hitStartTime]-_wave->getTime()[_avgBufLen*10]); //Slope without hit --> Leakage current
par[2]= 100.0; //Time Constant of exp --> Charge collection time
par[3]= (double)_wave->getTime()[hitStartTime]; //Start time of step --> Time of particle detection
par[4]= abs(_wave->getAmpl()[_wave->getSize() - _avgBufLen*10] - _wave->getAmpl()[hitStartTime]); //Step Amplitude --> Collected charge
//cout << "Parameters: " << par[0] << ", " << par[1] << ", " << par[2] << ", " << par[3] << ", " << par[4] << endl;
//due to possible resets, fit range needs to be defined dynamically outside reset range
double min = _wave->getTime()[_avgBufLen*10];
double max = _wave->getTime()[_wave->getSize()-_avgBufLen*5];
if (hitStartTime > _resetEnd){
min = _wave->getTime()[_resetEnd];
max = _wave->getTime()[_wave->getSize()-_avgBufLen*5];
}
else if ((hitStartTime < _resetStart) && (_resetStart > 0)){
min = _wave->getTime()[_avgBufLen*10];
max = _wave->getTime()[_resetStart];
}
//Initiate function
TF1 *expStep = new TF1("expStep", this, &WaveformAna3Tcell::expstep, min, max, 5, "WaveformAna3Tcell", "expstep");
expStep->SetParameter(0, par[0]);
expStep->SetParameter(1, par[1]);
expStep->SetParameter(2, par[2]);
expStep->SetParameter(3, par[3]);
expStep->SetParameter(4, par[4]);
//showWaveform(_wave, expStep);
TGraph *wavegraph = new TGraph(_wave->getSize(), _wave->getTime(), _wave->getAmpl());
TFitResultPtr ptr = wavegraph->Fit("expStep", "SQ", "", min, max);
if (_showPulse)
showWaveform(_wave, expStep);
//Check and assign invalid, if needed. Need to define invalid conditions
if((ptr->Chi2() > _cutChi2) || (expStep->GetParameter(3) < _cutMinHitDetectionTime) || (expStep->GetParameter(3) > _cutMaxHitDetectionTime))
_isInvalid = true;
//fill the results into the given parameters
offset = expStep->GetParameter(0);
slope = expStep->GetParameter(1);
timeConstant = expStep->GetParameter(2);
hitDetectionTime = expStep->GetParameter(3);
stepSize = expStep->GetParameter(4);
chi2 = ptr->Chi2();
hit = _hit;
//For online histogram of amplitude
_stepAmplitude = expStep->GetParameter(4);
if(expStep) delete expStep;
if(wavegraph) delete wavegraph;
}
}
}
示例7: makePlots_vdm_ls
//.........这里部分代码省略.........
ostringstream graphTitle;
graphTitle << "section_" << type[n] << "_chi2_Graph_" << i;
sectionChi[i] = (new TGraphErrors(0));
sectionChi[i]->SetName(graphTitle.str().c_str());
for (int skipBin=0; skipBin<nSkipBins; skipBin++)
{
int binStart, binEnd, helper;
h_length_scale->GetBinXYZ(h_length_scale->FindBin(sectionBegin[i]),binStart,helper,helper); binStart++;
h_length_scale->GetBinXYZ(h_length_scale->FindBin(sectionEnd[i]),binEnd,helper,helper); binEnd--;
binStart += skipBin;
if(binStart >= binEnd)
continue;
double x = double(h_length_scale->GetBinLowEdge(binStart) - h_length_scale->GetBinLowEdge(binStart-skipBin)) / 11246.;
//cout << "skip bin: " << skipBin << "(" << binStart << ")" << endl;
ostringstream funcTitle;
funcTitle << "section" << type[n] << "Func_" << i << "_" << skipBin;
TF1* helperFunc = new TF1(funcTitle.str().c_str(),"gaus");
funcTitle << "_Prof";
TH1D* helperProfile = h_length_scale->ProjectionY(funcTitle.str().c_str(),binStart,binEnd);
TFitResultPtr helperPtr = helperProfile->Fit(helperFunc,"QSN");
if(Int_t(helperPtr) !=0)
{
cout << "fit failed" << endl;
cout << "skip bin: " << skipBin << "(" << binStart << ")" << endl;
continue;
}
double chi2 = helperPtr->Chi2()/double(helperPtr->Ndf());
sectionChi[i]->SetPoint(sectionChi[i]->GetN(),x,chi2);
//cout << skipBin << " " << x << " " << chi2 << endl;
}
//sectionChi[i]->Print("ALL");
sectionChi[i]->SetTitle(";skip interval [s]; #chi^{2}/NDF");
sectionChi[i]->GetYaxis()->SetRangeUser(0,6);
sectionChi[i]->GetXaxis()->SetLimits(0,30);
sectionChi[i]->SetLineWidth(2);
sectionChi[i]->SetLineColor(i);
sectionChi[i]->Draw(drawoption.c_str());
drawoption = string("L");
ostringstream legtext ; legtext << "Section " << i << " (" << sectionTruth[i] << " µm)";
legchi->AddEntry(sectionChi[i],legtext.str().c_str(),"l");
}
#ifdef __CINT__
CMSText(1,1,1,string("#Delta")+type[n]+string(" length scale"),"","pp, #sqrt{s}=2.76 TeV");
SetLegAtt(legchi);
#endif
legchi->Draw("SAME");
TLine* line = new TLine(skip/11246.,0,skip/11246.,2.5);
line->SetLineWidth(2);
line->SetLineStyle(2);
line->Draw("SAME");
can3->SaveAs((string("plots/vdm_length_scale_")+type[n]+string("_3_pp.pdf")).c_str());
//Determine reference value y0 to subtract from plotting
TGraph helperGraph(nSec);
double y0=0;
for (int i=0; i<nSec; i++)
{
示例8: plotPedestalAnalysis
void plotPedestalAnalysis(string inputFileName, string outputDIR, bool testDoubleGaussianChannels){
system(("mkdir -p "+outputDIR).c_str());
setTDRStyle();
gROOT->SetBatch(kTRUE);
TFile* inputFile = TFile::Open(inputFileName.c_str(),"READ");
inputFile->cd();
TTree* tree = (TTree*) inputFile->Get("pedestalFullNoise");
uint32_t detid,fedKey;
uint16_t fecCrate,fecSlot, fecRing, ccuAdd, ccuChan, lldChannel, fedId, fedCh, apvId, stripId;
float fitChi2Probab, kSProbab, jBProbab, aDProbab, fitChi2;
float noiseSkewness, noiseKurtosis;
float fitGausMean, fitGausSigma, fitGausNormalization;
float fitGausMeanError, fitGausSigmaError, fitGausNormalizationError;
vector<float>* noiseDistribution = 0;
vector<float>* noiseDistributionError = 0;
float nBin, xMin, xMax;
tree->SetBranchStatus("*",kFALSE);
tree->SetBranchStatus("detid",kTRUE);
tree->SetBranchStatus("fedKey",kTRUE);
tree->SetBranchStatus("fecCrate",kTRUE);
tree->SetBranchStatus("fecSlot",kTRUE);
tree->SetBranchStatus("fecRing",kTRUE);
tree->SetBranchStatus("ccuAdd",kTRUE);
tree->SetBranchStatus("ccuChan",kTRUE);
tree->SetBranchStatus("lldChannel",kTRUE);
tree->SetBranchStatus("fedId",kTRUE);
tree->SetBranchStatus("fedCh",kTRUE);
tree->SetBranchStatus("apvId",kTRUE);
tree->SetBranchStatus("stripId",kTRUE);
tree->SetBranchStatus("fitChi2",kTRUE);
tree->SetBranchStatus("fitChi2Probab",kTRUE);
tree->SetBranchStatus("kSProbab",kTRUE);
tree->SetBranchStatus("jBProbab",kTRUE);
tree->SetBranchStatus("aDProbab",kTRUE);
tree->SetBranchStatus("fitGausNormalization",kTRUE);
tree->SetBranchStatus("fitGausMean",kTRUE);
tree->SetBranchStatus("fitGausSigma",kTRUE);
tree->SetBranchStatus("fitGausNormalizationError",kTRUE);
tree->SetBranchStatus("fitGausMeanError",kTRUE);
tree->SetBranchStatus("fitGausSigmaError",kTRUE);
tree->SetBranchStatus("noiseSkewness",kTRUE);
tree->SetBranchStatus("noiseKurtosis",kTRUE);
tree->SetBranchStatus("noiseDistribution",kTRUE);
tree->SetBranchStatus("noiseDistributionError",kTRUE);
tree->SetBranchStatus("nBin",kTRUE);
tree->SetBranchStatus("xMin",kTRUE);
tree->SetBranchStatus("xMax",kTRUE);
tree->SetBranchAddress("detid",&detid);
tree->SetBranchAddress("fedKey",&fedKey);
tree->SetBranchAddress("fecCrate",&fecCrate);
tree->SetBranchAddress("fecSlot",&fecSlot);
tree->SetBranchAddress("fecRing",&fecRing);
tree->SetBranchAddress("ccuAdd",&ccuAdd);
tree->SetBranchAddress("ccuChan",&ccuChan);
tree->SetBranchAddress("lldChannel",&lldChannel);
tree->SetBranchAddress("fedId",&fedId);
tree->SetBranchAddress("fedCh",&fedCh);
tree->SetBranchAddress("apvId",&apvId);
tree->SetBranchAddress("stripId",&stripId);
tree->SetBranchAddress("fitGausNormalization",&fitGausNormalization);
tree->SetBranchAddress("fitGausMean",&fitGausMean);
tree->SetBranchAddress("fitGausSigma",&fitGausSigma);
tree->SetBranchAddress("fitGausNormalizationError",&fitGausNormalizationError);
tree->SetBranchAddress("fitGausMeanError",&fitGausMeanError);
tree->SetBranchAddress("fitGausSigmaError",&fitGausSigmaError);
tree->SetBranchAddress("fitChi2",&fitChi2);
tree->SetBranchAddress("fitChi2Probab",&fitChi2Probab);
tree->SetBranchAddress("noiseSkewness",&noiseSkewness);
tree->SetBranchAddress("noiseKurtosis",&noiseKurtosis);
tree->SetBranchAddress("kSProbab",&kSProbab);
tree->SetBranchAddress("aDProbab",&aDProbab);
tree->SetBranchAddress("jBProbab",&jBProbab);
tree->SetBranchAddress("noiseDistribution",&noiseDistribution);
tree->SetBranchAddress("noiseDistributionError",&noiseDistributionError);
tree->SetBranchAddress("nBin",&nBin);
tree->SetBranchAddress("xMin",&xMin);
tree->SetBranchAddress("xMax",&xMax);
TFile* badStripsNFilledBins = new TFile((outputDIR+"/badStripsNFilledBins.root").c_str(),"RECREATE");
TFile* badKsTest = new TFile((outputDIR+"/badStripsKsTest.root").c_str(),"RECREATE");
TFile* badjBTest = new TFile((outputDIR+"/badStripsjBTest.root").c_str(),"RECREATE");
TFile* badChi2Test = new TFile((outputDIR+"/badStripsChi2Test.root").c_str(),"RECREATE");
TFile* badaDTest = new TFile((outputDIR+"/badStripsaDTest.root").c_str(),"RECREATE");
TFile* badCombinedTest = new TFile((outputDIR+"/badStripsCombined.root").c_str(),"RECREATE");
TFile* badJBNotKSTest = new TFile((outputDIR+"/badStripsjBNotKS.root").c_str(),"RECREATE");
TFile* badaDNotKSandjBTest = new TFile((outputDIR+"/badStripaDNotKSNotjB.root").c_str(),"RECREATE");
TFile* badChi2NotKSandjBandaDTest = new TFile((outputDIR+"/badStripsChi2NotKsandjBandaD.root").c_str(),"RECREATE");
long int nbadNFilledBins = 0;
long int nbadKsTest = 0;
long int nbadjBTest = 0;
long int nbadaDTest = 0;
long int nbadChi2Test = 0;
long int nbadCombinedTest = 0;
//.........这里部分代码省略.........
示例9: compare_kFSR_em
void compare_kFSR_em(TString dir1, TString dir2, TString algo="PF",
TString dir_prefix="KOSTAS_L1_on_pt_plain_", TString label_dir1="", TString label_dir2="",TString binning_select ="kostas"){
setTDRStyle();
TCanvas* c = new TCanvas("c","",600,600);
TLatex latex;
latex.SetNDC();
latex.SetTextSize(0.05);
latex.SetTextAlign(13); //align at top
Double_t kFSR_extrapol_ymin=0.95;
Double_t kFSR_extrapol_ymax=1.1;
TFile *inf_Dir1;
inf_Dir1 = new TFile(dir_prefix+dir1+"/"+binning_select+"_use_easy_mean_TuneZ2_TuneZ2_" + algo + "_kFSR_histos.root","OPEN");
// inf_Dir1 = new TFile(dir_prefix+dir1+"/"+binning_select+"_TuneZ2_TuneZ2_" + algo + "_kFSR_histos.root","OPEN");
TFile *inf_Dir2;
inf_Dir2 = new TFile(dir_prefix+dir2+"/"+binning_select+"_use_easy_mean_TuneZ2_TuneZ2_" + algo + "_kFSR_histos.root","OPEN");
// inf_Dir2 = new TFile(dir_prefix+dir2+"/"+binning_select+"_TuneZ2_TuneZ2_" + algo + "_kFSR_histos.root","OPEN");
if(label_dir1!="")dir1=label_dir1;
if(label_dir2!="")dir2=label_dir2;
Double_t chisquared1, ndf1, chisquared2, ndf2;
char buffer [50];
import_kFSR_vs_Abseta_histo_res1_Dir1 = (TH1D*)inf_Dir1->Get("kFSR_vs_Abseta_histo_res1");
import_kFSR_vs_Abseta_histo_res1_Dir2 = (TH1D*)inf_Dir2->Get("kFSR_vs_Abseta_histo_res1");
import_kFSR_vs_Abseta_histo_res1_Dir1->SetStats(0);
import_kFSR_vs_Abseta_histo_res1_Dir2->SetStats(0);
import_kFSR_vs_Abseta_histo_res1_Dir1->GetYaxis()->SetTitle("k_{rad} correction");
import_kFSR_vs_Abseta_histo_res1_Dir2->GetYaxis()->SetTitle("k_{rad} correction");
import_kFSR_vs_Abseta_histo_res1_Dir1->Draw("");
import_kFSR_vs_Abseta_histo_res1_Dir1->GetYaxis()->SetRangeUser(kFSR_extrapol_ymin,kFSR_extrapol_ymax);
TF1 *kFSR_fit = new TF1("kFSR_fit","[0]+[1]*cosh(x)/(1+cosh(x)*[2])",import_kFSR_vs_Abseta_histo_res1_Dir1->GetXaxis()->GetXmin(),import_kFSR_vs_Abseta_histo_res1_Dir1->GetXaxis()->GetXmax()); //was used before...
import_kFSR_vs_Abseta_histo_res1_Dir1->GetFunction("kFSR_fit")->GetParameters();
kFSR_fit->SetParameters(import_kFSR_vs_Abseta_histo_res1_Dir1->GetFunction("kFSR_fit")->GetParameters());
import_kFSR_vs_Abseta_histo_res1_Dir1->GetFunction("kFSR_fit")->SetLineColor(1);
kFSR_fit->SetLineColor(2);
kFSR_fit->SetLineWidth(2);
TFitResultPtr r = import_kFSR_vs_Abseta_histo_res1_Dir1->Fit(kFSR_fit,"S E");
TMatrixDSym cov = r->GetCovarianceMatrix(); // to access the covariance matrix
chisquared1= r->Chi2();
ndf1= r->Ndf();
TGraphErrors* band1= get_error_band(cov, kFSR_fit);
band1->SetFillColor(15);
// band1->SetFillStyle(3001);
band1->Draw("same 3");
import_kFSR_vs_Abseta_histo_res1_Dir1->Draw("e same");
cmsPrel(intLumi=36, false);
TLine *line = new TLine(import_kFSR_vs_Abseta_histo_res1_Dir1->GetXaxis()->GetXmin(),1.,import_kFSR_vs_Abseta_histo_res1_Dir1->GetXaxis()->GetXmax(),1.);
line->Draw();
line->SetLineStyle(2);
line->SetLineColor(1);
sprintf (buffer, "Fit uncertainty (#chi^{2}/ndf = %.1f / %d )", chisquared1, ndf1);
cout << buffer << endl;
TLegend *leg_kFSR1;
leg_kFSR1 = new TLegend(0.2,0.70,0.65,0.85);
leg_kFSR1->SetFillColor(kWhite);
leg_kFSR1->SetTextFont(42);
// leg->SetHeader("Legende");
leg_kFSR1->AddEntry(kFSR_fit,"p_{0}+ #frac{p_{1}cosh(|#eta|)}{1+p_{2}cosh(|#eta|)}","l");
leg_kFSR1->AddEntry(band1,buffer,"f");
// leg_kFSR->AddEntry(import_kFSR_vs_Abseta_histo_res1_Dir1,"Data","lep");
leg_kFSR1->Draw();
//"kFSR_comp_"+
cmsPrel(intLumi=36, false);
c->SaveAs(GetDateDir()+"/kFSR_comp_"+dir1+"_kFSR_"+ algo +"_em.eps");
import_kFSR_vs_Abseta_histo_res1_Dir2->Draw("e");
import_kFSR_vs_Abseta_histo_res1_Dir2->GetYaxis()->SetRangeUser(kFSR_extrapol_ymin,kFSR_extrapol_ymax);
r = import_kFSR_vs_Abseta_histo_res1_Dir2->Fit(kFSR_fit,"S");
cov = r->GetCovarianceMatrix(); // to access the covariance matrix
TGraphErrors* band2= get_error_band(cov, kFSR_fit);
band2->SetFillColor(15);
// band2->SetFillStyle(3001);
band2->Draw("same 3");
chisquared2= r->Chi2();
ndf2= r->Ndf();
cout << "CHI2: " << chisquared2 << " ndf: " << ndf2 << endl;
import_kFSR_vs_Abseta_histo_res1_Dir2->Draw("e same");
sprintf (buffer, "Fit uncertainty (#chi^{2}/ndf = %.1f / %d )", chisquared2, ndf2);
cout << buffer << endl;
TLegend *leg_kFSR2;
leg_kFSR2 = new TLegend(0.2,0.70,0.65,0.85);
leg_kFSR2->SetFillColor(kWhite);
leg_kFSR2->SetTextFont(42);
// leg->SetHeader("Legende");
leg_kFSR2->AddEntry(kFSR_fit,"p_{0}+ #frac{p_{1}cosh(|#eta|)}{1+p_{2}cosh(|#eta|)}","l");
leg_kFSR2->AddEntry(band2,buffer,"f");
// leg_kFSR->AddEntry(import_kFSR_vs_Abseta_histo_res1_Dir1,"Data","lep");
//.........这里部分代码省略.........
示例10: TLatex
//---------------------------------------------------------------
double *treat(TString fileData, double lumi, TString decay, vector<double> mtop, vector<double> xlim, int binned, TString date, TString version)
//---------------------------------------------------------------
{
//TString indir = date+"/v"+version+"/";
TString indir = date+"/"+version+"/";
TString outdir = indir;
TString channel = " + Jets channel";
if (fileData.Contains("ElectronHad")) {
outdir += "CalibEl/";
indir += "MyAnaEl/";
if (decay.Contains("semi", TString::kIgnoreCase))
channel = "e"+channel;
if (decay.Contains("di", TString::kIgnoreCase))
channel = "ee/e#mu"+channel;
if (decay.Contains("all", TString::kIgnoreCase))
channel = "e/ee/e#mu"+channel;
}
if (fileData.Contains("MuHad")) {
outdir += "CalibMu/";
indir += "MyAnaMu/";
if (decay.Contains("semi", TString::kIgnoreCase))
channel = "#mu"+channel;
if (decay.Contains("di", TString::kIgnoreCase))
channel = "#mu#mu/#mue"+channel;
if (decay.Contains("all", TString::kIgnoreCase))
channel = "#mu/#mu#mu/#mue"+channel;
}
if (fileData.Contains("Run2012")) {
outdir += "CalibAll/";
indir += "MyAnaAll/";
if (decay.Contains("semi", TString::kIgnoreCase))
channel = "e/#mu"+channel;
if (decay.Contains("di", TString::kIgnoreCase))
channel = "ee/#mu#mu/e#mu"+channel;
if (decay.Contains("all", TString::kIgnoreCase))
channel = "e/#mu/ee/#mu#mu/e#mu"+channel;
}
gROOT->ProcessLine(".! mkdir "+outdir);
TLatex* channel_tex = new TLatex(0.22, 0.9, channel);
channel_tex->SetNDC(true);
channel_tex->SetTextFont(43);
channel_tex->SetTextSize(TITLE_FONTSIZE - 6);
const unsigned int numberOfPoints = mtop.size();
double x[numberOfPoints], ex[numberOfPoints];
double y[numberOfPoints], ey[numberOfPoints];
for (unsigned int itop = 0; itop < numberOfPoints; itop++) {
TString fileMC = TString::Format("All_%d_5.root", (int)mtop[itop]);
//TString fileMC = TString::Format("TTJets_MSDecays_JpsiFilter_%d_5.root", (int)mtop[itop]);
double *mean_err = new double[2];
if (binned < 2)
mean_err = unbinnedFit(indir+fileMC, xlim, mtop[itop], channel_tex, outdir, lumi);
if (binned == 2)
mean_err = binnedFit(indir+fileMC, xlim, mtop[itop], channel_tex, outdir, lumi);
y[itop] = mean_err[0];
ey[itop] = mean_err[1];
x[itop] = mtop[itop]+0.5;
ex[itop] = 0.;
}
TGraphErrors *gr = new TGraphErrors(numberOfPoints, x, y, ex, ey);
TFitResultPtr fitptr = gr->Fit("pol1", "FSQ", "");
TF1 *fit = gr->GetFunction("pol1");
double yinte = fitptr->Parameter(0);
double errYinte = fitptr->ParError(0);
double slope = fitptr->Parameter(1);
double errSlope = fitptr->ParError(1);
double chi2 = fitptr->Chi2();
double ndf = fitptr->Ndf();
double err_up[numberOfPoints];
double err_down[numberOfPoints];
double err_val[numberOfPoints];
fitptr->GetConfidenceIntervals(numberOfPoints, 1, 1, x, err_val, 0.68);
for(unsigned int itop = 0; itop < numberOfPoints; itop++) {
double error = err_val[itop];
err_up[itop] = fit->Eval(x[itop]) + error;
err_down[itop] = fit->Eval(x[itop]) - error;
}
TGraph *gr_up = new TGraph(numberOfPoints,x,err_up);
gr_up->Fit("pol2","FQ","");
TF1 *fit_up = gr_up->GetFunction("pol2");
TGraph *gr_down = new TGraph(numberOfPoints,x,err_down);
gr_down->Fit("pol2","FQ","");
TF1 *fit_down = gr_down->GetFunction("pol2");
TLegend *leg_calib = new TLegend(0.2,0.75,0.65,0.83,NULL,"brNDC");
leg_calib->SetTextSize(0.04);
leg_calib->AddEntry(gr,TString::Format("Slope of %.2f #pm %.2f", slope, errSlope),"lp");
leg_calib->SetHeader("Calibration curve");
// Blinded analysis
TCanvas *cn_calib = new TCanvas("cn_calib", "cn_calib", 800, 800);
cn_calib->cd();
grapherrors_myStyle(gr,"gr",2,30,1,30,1001,-1111,-1111,510,510,21,36,1.,"M_{t} (GeV)","M_{J/#psi+l} (GeV)");
//.........这里部分代码省略.........
示例11: fullPedestalAnalysis
void fullPedestalAnalysis(string inputDIR, string outputDIR, string inputCablingMap, string outputFileName){
gROOT->ProcessLine("gErrorIgnoreLevel = 1");
// open the file and prepare the cluster tree, adding the other trees as frined --> memory consuming
std::cout<<"##################################"<<std::endl;
std::cout<<"###### fullPedestalAnalysis ######"<<std::endl;
std::cout<<"##################################"<<std::endl;
clock_t tStart = clock();
// prepare style and load macros
setTDRStyle();
gROOT->SetBatch(kTRUE);
system(("mkdir -p "+outputDIR).c_str());
ifstream file;
std::cout<<"### Make input file list"<<std::endl;
system(("find "+inputDIR+" -name \"*.root\" > file.temp").c_str());
std::ifstream infile;
string line;
vector<string> fileList;
infile.open("file.temp",ifstream::in);
if(infile.is_open()){
while(!infile.eof()){
getline(infile,line);
if(line != "" and TString(line).Contains(".root") and line !="\n"){
fileList.push_back(line);
}
}
}
system("rm file.temp");
std::sort(fileList.begin(),fileList.end());
TFile* cablingFile = TFile::Open(inputCablingMap.c_str(),"READ");
cablingFile->cd();
TTree* readoutMap = (TTree*) cablingFile->FindObjectAny("readoutMap");
TTreeReader reader(readoutMap);
TTreeReaderValue<uint32_t> detid (reader,"detid");
TTreeReaderValue<uint16_t> fecCrate (reader,"fecCrate");
TTreeReaderValue<uint16_t> fecSlot (reader,"fecSlot");
TTreeReaderValue<uint16_t> fecRing (reader,"fecRing");
TTreeReaderValue<uint16_t> ccuAdd (reader,"ccuAdd");
TTreeReaderValue<uint16_t> ccuChan (reader,"ccuChan");
TTreeReaderValue<uint16_t> lldChannel (reader,"lldChannel");
TTreeReaderValue<uint16_t> fedId (reader,"fedId");
TTreeReaderValue<uint16_t> fedCh (reader,"fedCh");
// output tree
TFile* ouputTreeFile = new TFile((outputDIR+"/"+outputFileName).c_str(),"RECREATE");
ouputTreeFile->cd();
ouputTreeFile->SetCompressionLevel(0);
TTree* outputTree = new TTree("pedestalFullNoise","pedestalFullNoise");
// branches
uint32_t detid_,fedKey_;
uint16_t fecCrate_,fecSlot_, fecRing_, ccuAdd_, ccuChan_, lldChannel_, fedId_, fedCh_, apvId_, stripId_;
float noiseMean_,noiseRMS_, noiseSkewness_, noiseKurtosis_;
float fitChi2_, fitChi2Probab_, fitStatus_;
float fitGausMean_, fitGausSigma_, fitGausNormalization_;
float fitGausMeanError_, fitGausSigmaError_, fitGausNormalizationError_;
float noiseIntegral3Sigma_, noiseIntegral3SigmaFromFit_;
float noiseIntegral4Sigma_, noiseIntegral4SigmaFromFit_;
float noiseIntegral5Sigma_, noiseIntegral5SigmaFromFit_;
float kSValue_, kSProbab_, jBValue_, jBProbab_, aDValue_, aDProbab_;
vector<float> noiseDistribution_, noiseDistributionError_;
float xMin_, xMax_, nBin_ ;
outputTree->Branch("detid",&detid_,"detid/i");
outputTree->Branch("fedKey",&fedKey_,"fedKey/i");
outputTree->Branch("fecCrate",&fecCrate_,"fecCrate/s");
outputTree->Branch("fecSlot",&fecSlot_,"fecSlot/s");
outputTree->Branch("fecRing",&fecRing_,"fecRing/s");
outputTree->Branch("ccuAdd",&ccuAdd_,"ccuAdd/s");
outputTree->Branch("ccuChan",&ccuChan_,"ccuChan/s");
outputTree->Branch("lldChannel",&lldChannel_,"lldChannel/s");
outputTree->Branch("fedId",&fedId_,"fedId/s");
outputTree->Branch("fedCh",&fedCh_,"fedCh/s");
outputTree->Branch("apvId",&apvId_,"apvId/s");
outputTree->Branch("stripId",&stripId_,"stripId/s");
outputTree->Branch("noiseMean",&noiseMean_,"noiseMean/F");
outputTree->Branch("noiseRMS",&noiseRMS_,"noiseRMS/F");
outputTree->Branch("noiseSkewness",&noiseSkewness_,"noiseSkewness/F");
outputTree->Branch("noiseKurtosis",&noiseKurtosis_,"noiseKurtosis/F");
outputTree->Branch("fitGausNormalization",&fitGausNormalization_,"fitGausNormalization/F");
outputTree->Branch("fitGausMean",&fitGausMean_,"fitGausMean/F");
outputTree->Branch("fitGausSigma",&fitGausSigma_,"fitGausSigma/F");
outputTree->Branch("fitGausNormalizationError",&fitGausNormalizationError_,"fitGausNormalizationError/F");
outputTree->Branch("fitGausMeanError",&fitGausMeanError_,"fitGausMeanError/F");
outputTree->Branch("fitGausSigmaError",&fitGausSigmaError_,"fitGausSigmaError/F");
outputTree->Branch("fitChi2",&fitChi2_,"fitChi2/F");
outputTree->Branch("fitChi2Probab",&fitChi2Probab_,"fitChi2Probab/F");
outputTree->Branch("fitStatus",&fitStatus_,"fitStatus_F");
outputTree->Branch("noiseIntegral3Sigma",&noiseIntegral3Sigma_,"noiseIntegral3Sigma/F");
outputTree->Branch("noiseIntegral3SigmaFromFit",&noiseIntegral3SigmaFromFit_,"noiseIntegral3SigmaFromFit/F");
outputTree->Branch("noiseIntegral4Sigma",&noiseIntegral4Sigma_,"noiseIntegral4Sigma/F");
outputTree->Branch("noiseIntegral4SigmaFromFit",&noiseIntegral4SigmaFromFit_,"noiseIntegral4SigmaFromFit/F");
outputTree->Branch("noiseIntegral5Sigma",&noiseIntegral4Sigma_,"noiseIntegral5Sigma/F");
//.........这里部分代码省略.........