TF1* Mathematics::landau_func() { // Want plotting consistancy so have defined my own landau function TF1 *land = new TF1( "mylandau", "[0]*TMath::Landau( x, [1], [2] )" ); land->SetParName( 0, "Constant" ); land->SetParName( 1, "Mean" ); land->SetParName( 2, "Sigma" ); return land; }
TF1 * getDoubleFit(TH1 * hist, bool autorange, double inner, double outer, int which=1){ /** * @brief performes a double gaussian Fit */ Double_t parameters[6] = {0,0,0,0,0,0}; Double_t parameters_new[6] = {0,0,0,0,0,0}; double center = hist->GetMean(); if (autorange){ double inner = fabs(center - hist->GetXaxis()->GetXmax()) /10; double outer = fabs(center - hist->GetXaxis()->GetXmax()) /10*8; } TF1 * fit1 = new TF1("fit1", "gaus", center-inner, center+inner ); hist->Fit(fit1, "Q0R"); fit1->GetParameters(¶meters[0]); TF1 * fit2 = new TF1("fit2", "gaus", center-outer, center+outer ); hist->Fit(fit2, "Q0R"); fit2->GetParameters(¶meters[3]); TF1 * fitproper = new TF1("fitproper", "gaus(0)+gaus(3)", center-outer, center+outer); fitproper->SetParameters(parameters); fitproper->SetParName(0, "Const.(inner)"); fitproper->SetParName(1, "Mean (inner)"); fitproper->SetParName(2, "Sigma (inner)"); fitproper->SetParName(3, "Const.(outer)"); fitproper->SetParName(4, "Mean (outer)"); fitproper->SetParName(5, "Sigma (outer)"); hist->Fit(fitproper, "Q0R"); fitproper->GetParameters(¶meters_new[0]); fitproper->SetLineColor(hist->GetLineColor()); fitproper->SetLineWidth(hist->GetLineWidth()); fitproper->SetLineStyle(2); if (which==1){ TF1 * Gausinner = new TF1("Gausinner", "gaus(0)", center-inner, center+inner); Gausinner->SetParameters(parameters_new); return Gausinner; } else{ TF1 * Gausouter = new TF1("Gausouter", "gaus(3)", center-outer, center+outer); Gausouter->SetParameters(parameters_new); return Gausouter; } }
TF1* Mathematics::raw_gamma_func( int OutputLevel ) { (void) OutputLevel; TF1* output = new TF1( "gammaf", "[0]*TMath::GammaDist( x, [1], [2], [3] )" ); output->SetParName( 0, "Const" ); output->SetParName( 1, "#gamma" ); output->SetParName( 2, "#mu" ); output->SetParName( 3, "#beta" ); return output; }
TF1* GetFit(const char *address, int lyr, double xinit) { const char *bgr = Form("[6]*TMath::Exp([7]*(x-%f))",xinit); const char *la1 = "(1-[3]-[4]-[5])*TMath::Landau(x,[1],[2],1)"; const char *la2 = "[3]*TMath::Landau(x,2*[1]+1.4*[2],2.0*[2],1)"; const char *la3 = "[4]*TMath::Landau(x,3*[1]+3.3*[2],3.0*[2],1)"; const char *la4 = "[5]*TMath::Landau(x,4*[1]+5.6*[2],4.0*[2],1)"; TF1 *ret = new TF1("fit_H1", Form("[0]*(%s+%s+%s+%s)+%s",la1,la2,la3,la4,bgr) ); ret->SetParName(0,"A"); ret->SetParName(1,"lambda"); ret->SetParName(2,"sigma"); ret->SetParName(3,"f2"); ret->SetParameter(0,1e4); ret->SetParLimits(0,1e2,1e7); ret->SetParameter(1,21); ret->SetParLimits(1,13,25.0); ret->SetParameter(2,3.0); ret->SetParLimits(2,1.5,5.0); if(lyr>1) { ret->SetParameter(1,15); ret->SetParLimits(1,2,30); ret->SetParameter(2,5.0); ret->SetParLimits(2,0.8,10.0); } ret->SetParameter(3,0.20); ret->SetParLimits(3,0,0.40); ret->SetParameter(4,0.0); ret->SetParameter(5,0.0); ret->SetParameter(6,500); ret->SetParLimits(6,1e2,1e7); ret->SetParameter(7,-1); ret->SetParLimits(7,-10,-0.1); ret->SetLineColor(kRed-3); ifstream infit; infit.open( address ); double tmp; bool found=false; for(int n=0; n!=ret->GetNpar(); ++n) { infit >> tmp; if(!infit.good()) break; ret->SetParameter(n,tmp); infit >> tmp; found = true; } infit.close(); if(found) { cout << " Previous fit results found" << endl; ret->SetParLimits(4,0,0.40); ret->SetParLimits(5,0,0.40); } else { ret->SetParLimits(4,+1,-1); ret->SetParLimits(5,+1,-1); } return ret; }
int main(int argc, char const *argv[]) { TFile *myFile = new TFile("output.root","RECREATE"); Float_t E1,Px1,Py1,Pz1,E2,Px2,Py2,Pz2; Double_t mass = 0; TH1D *m12 = new TH1D("m12","m12",60,0.99,1.08); TF1 *myBW = new TF1("myBW","TMath::BreitWigner(x,[0],[1])", 1.01, 1.03); myBW->SetParName(0,"Mass"); myBW->SetParName(1,"#Gamma"); TFile *inputFile = new TFile("data.root"); TTree *data_tree = (TTree*)inputFile->Get("data"); data_tree->SetBranchAddress("E1", &E1); data_tree->SetBranchAddress("Px1", &Px1); data_tree->SetBranchAddress("Py1", &Py1); data_tree->SetBranchAddress("Pz1", &Pz1); data_tree->SetBranchAddress("E2", &E2); data_tree->SetBranchAddress("Px2", &Px2); data_tree->SetBranchAddress("Py2", &Py2); data_tree->SetBranchAddress("Pz2", &Pz2); TLorentzVector vec1(0.0,0.0,0.0,0.0); TLorentzVector vec2(0.0,0.0,0.0,0.0); int count = data_tree->GetEntries(); for (int i = 0; i < count; i++) { data_tree->GetEntry(i); vec1.SetPxPyPzE(Px1,Py1,Pz1,E1); vec2.SetPxPyPzE(Px2,Py2,Pz2,E2); mass = (vec1 + vec2).M(); m12->Fill(mass); } myBW->SetParameters(0,1.02,0.05); myBW->SetParLimits(0,1.01,1.03); m12->Fit("myBW","","",0,2); m12->GetXaxis()->SetTitle("Mass (GeV)"); gStyle->SetOptFit(1111); myFile->cd(); myFile->Write(); myFile->Close(); return 0; }
//------------------------------------------------------------------------------ std::pair<double,double> fitskwlin( char* hs, double xl=-0.1, double xr=0.1 ) { TH1 *h = (TH1*)gDirectory->Get(hs); if( h == NULL ) { cout << hs << " does not exist\n"; return std::make_pair(0.,0.); } int nb = h->GetNbinsX(); double x1 = h->GetBinCenter(1); // first double x9 = h->GetBinCenter(nb); // last if( xl > x1 && xl < x9 ) x1 = xl; // left if( xr > x1 && xr < x9 ) x9 = xr; // right // create a TF1 with the range from x1 to x9 and 3 parameters TF1 *tanhFcn = new TF1( "tanhFcn", fitSkw, x1, x9, 2 ); tanhFcn->SetParName( 0, "dyoff" ); tanhFcn->SetParName( 1, "dyslp" ); // set start values: tanhFcn->SetParameter( 0, 0 ); // dy off [um] tanhFcn->SetParameter( 1, 99 ); // dy slope [um/skw] h->Fit( "tanhFcn", "R Q", "p" );// R = range from tanhFcn return std::make_pair(tanhFcn->GetParameter(0),tanhFcn->GetParameter(1)); }
TF1 * tripleGaussFit(TH1 * hist, bool autorange, double inner=0.01, double outer=0.1){ /** * @brief performes a double gaussian Fit */ Double_t parameters[9] = {0,0,0,0,0,0,0,0,0}; double center = hist->GetMean(); if (autorange){ double inner = fabs(center - hist->GetXaxis()->GetXmax()) /10; double outer = fabs(center - hist->GetXaxis()->GetXmax()) /10*8; } double middle = (outer - inner)/2; TF1 * fit1 = new TF1("fit1", "gaus", center-inner, center+inner ); hist->Fit(fit1, "0R"); fit1->GetParameters(¶meters[0]); TF1 * fitmid = new TF1("fitmid", "gaus", center-middle, center+middle ); fitmid->SetParameter(1, parameters[1]); hist->Fit(fitmid, "0R"); fitmid->GetParameters(¶meters[3]); TF1 * fit2 = new TF1("fit2", "gaus", center-outer, center+outer ); fit2->SetParameter(1, parameters[1]); hist->Fit(fit2, "0R"); fit2->GetParameters(¶meters[6]); TF1 * fitproper = new TF1("fitproper", "gaus(0)+gaus(3)+gaus(6)", center-outer, center+outer); fitproper->SetParameters(parameters); fitproper->SetParName(0, "Const.(inner)"); fitproper->SetParName(1, "Mean (inner)"); fitproper->SetParName(2, "Sigma (inner)"); fitproper->SetParName(3, "Const.(middle)"); fitproper->SetParName(4, "Mean (middle)"); fitproper->SetParName(5, "Sigma (middle)"); fitproper->SetParName(6, "Const.(outer)"); fitproper->SetParName(7, "Mean (outer)"); fitproper->SetParName(8, "Sigma (outer)"); hist->Fit(fitproper, "0R"); // fitproper->SetLineColor(hist->GetLineColor()); // fitproper->SetLineWidth(hist->GetLineWidth()); //// fitproper->SetLineStyle(2); return fitproper; }
TF1 * gaussFit(TH1 * hist, double inner) { Double_t parameters[6] = {0,0,0,0,0,0}; double center =0;// hist->GetMean(); TF1 * fit = new TF1("fit", "gaus", center-inner, center+inner ); hist->Fit(fit, "Q0R"); fit->GetParameters(¶meters[0]); fit->SetParameters(parameters); fit->SetParName(0, "Const."); fit->SetParName(1, "Mean"); fit->SetParName(2, "Sigma"); return fit; }
void plotMttResolution() { setTDRStyle(); TCanvas *c = new TCanvas("c", "c", 800, 800); TH1F *mtt = (TH1F*) _file0->Get("mtt_resolution_mva"); mtt->SetTitle(""); mtt->SetName("m_{t#bar{t}}"); mtt->GetXaxis()->SetTitle("m_{t#bar{t}} - m_{t#bar{t}}^{gen} (GeV)"); mtt->SetLineColor(TColor::GetColor("#542437")); mtt->SetLineColor(TColor::GetColor("#8A9B0F")); mtt->SetLineColor(TColor::GetColor("#C02942")); mtt->SetFillColor(mtt->GetLineColor()); mtt->SetFillStyle(3004); mtt->GetXaxis()->SetTitleOffset(1.2); TF1 *voigt = new TF1("voigt", "gaus", -100, 100); voigt->SetParName(0, "amp"); voigt->SetParName(2, "mean"); voigt->SetParName(1, "sigma"); voigt->SetParameter(0, mtt->GetMaximum()); voigt->SetParameter(2, 0); voigt->SetParameter(1, 100); mtt->Fit(voigt, "RVN"); voigt->SetLineColor(TColor::GetColor("#8A9B0F")); voigt->SetLineWidth(2); mtt->Draw(); voigt->Draw("same"); TLatex* latex = new TLatex(); latex->SetTextFont(42); latex->SetTextSize(0.033); latex->DrawLatexNDC(0.25, 0.84, TString::Format("mean = %.2f", voigt->GetParameter(1))); latex->DrawLatexNDC(0.25, 0.8, TString::Format("#sigma = %.2f", voigt->GetParameter(2))); gPad->Modified(); gPad->Update(); c->Print("mtt_resolution.pdf"); }
Double_t fitfulllang( char* hs ) { TH1 *h = (TH1*)gDirectory->Get(hs); if( h == NULL ){ cout << hs << " does not exist\n"; return 0; } double aa = h->GetEntries();//normalization // find peak: int ipk = h->GetMaximumBin(); double xpk = h->GetBinCenter(ipk); double sm = xpk / 9; // sigma double ns = sm; // noise // fit range: int ib0 = ipk/2; int ib9 = h->GetNbinsX() - 1; double x0 = h->GetBinLowEdge(ib0); double x9 = h->GetBinLowEdge(ib9) + h->GetBinWidth(ib9); // create a TF1 with the range from x0 to x9 and 4 parameters TF1 *fitFcn = new TF1( "fitFcn", fitLandauGauss, x0, x9, 4 ); fitFcn->SetParName( 0, "peak" ); fitFcn->SetParName( 1, "sigma" ); fitFcn->SetParName( 2, "area" ); fitFcn->SetParName( 3, "smear" ); fitFcn->SetNpx(500); fitFcn->SetLineWidth(4); fitFcn->SetLineColor(kMagenta); // set start values: fitFcn->SetParameter( 0, xpk ); // peak position, defined above fitFcn->SetParameter( 1, sm ); // width fitFcn->SetParameter( 2, aa ); // area fitFcn->SetParameter( 3, ns ); // noise h->Fit("fitFcn", "NQR", "ep" );// R = range from fitFcn return fitFcn->GetParameter(0); }
TF1 * GetVoigtFit(TH1 * hist, double lower, double upper){ /** * @brief performes a Fit with a Breit-Wigner-Distribution. */ double parameter[3]; double max = hist->GetMaximum(); int bin1 = hist->FindFirstBinAbove(max-1); double center = hist->GetBinCenter(bin1); TString func = TString::Format("TMath::Voigt(x-%.4f, [0], [1])", center); TF1 * fit = new TF1("fit", func, lower, upper); hist->Fit(fit, "0R"); fit->GetParameters(¶meter[0]); TF1 * voigt = new TF1("voigt", func+"*[2]", lower, upper); voigt->SetParameter(0, parameter[0]); voigt->SetParameter(1, parameter[1]); voigt->SetParName(0, "#sigma"); voigt->SetParName(1, "#Gamma"); voigt->SetParName(2, "A"); // voigt->SetParName(3, "B"); // voigt->SetParName(4, "C"); hist->Fit(voigt, "0R"); return voigt; }
void countZs(const char* filename, int run1=1, int run2=0, float lumi=0, bool add=false) { TFile *file = new TFile(filename); if (!file) return; TCanvas *c1 = new TCanvas(); c1->cd(); TH1F *h = (TH1F*) file->Get("Run summary/DiMuonHistograms/GlbGlbMuon_HM"); h->GetYaxis()->SetRangeUser(0,200); h->Draw(); TF1 *f = new TF1("f","gaus(0)+pol2(3)",70,110); f->SetParName(0,"norm"); f->SetParName(1,"mass"); f->SetParName(2,"width"); f->SetParameters(1.16028e+02,9.07785e+01,2.11556e+00,-2.17600e+01,9.67443e-01,-6.98382e-03); f->SetParLimits(0,0,1e6); f->SetParLimits(1,85,95); f->SetParLimits(2,1.5,5); h->Fit(f,"","",70,110); h->GetYaxis()->SetRangeUser(0,200); c1->Update(); TF1 *f2 = new TF1("f2","gaus(0)",70,110); f2->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2)); int integral = (int) (f2->Integral(70,110) / h->GetBinWidth(2)); TLatex *tl = new TLatex(); tl->DrawLatexNDC(0.1,0.95,Form("pPb 8TeV [%i-%i, %.1f nb^{-1}]",run1,run2,lumi)); tl->DrawLatexNDC(0.18,0.75,Form("%i Z bosons",integral)); tl->DrawLatexNDC(0.18,0.7,Form("(#sigma = %.1f nb)",integral/lumi)); if (!add) c1->SaveAs(Form("plotZ_%i_%i.pdf",run1,run2)); else c1->SaveAs("plotZ.gif+100"); file->Close(); }
std::vector<double> fitskwpol( char* hs, double xl=-0.1, double xr=0.1) { TH1 *h = (TH1*)gDirectory->Get(hs); if( h == NULL ) { cout << hs << " does not exist\n"; return std::vector<double>(); } int nb = h->GetNbinsX(); double x1 = h->GetBinCenter(1); // first double x9 = h->GetBinCenter(nb); // last if( xl > x1 && xl < x9 ) x1 = xl; // left if( xr > x1 && xr < x9 ) x9 = xr; // right // create a TF1 with the range from x1 to x9 and 3 parameters TF1 *tanhFcn = new TF1( "tanhFcn", fitSkwPol, x1, x9, 4 ); tanhFcn->SetParName( 0, "dyoff" ); tanhFcn->SetParName( 1, "dyslp" ); tanhFcn->SetParName( 2, "dypar" ); tanhFcn->SetParName( 3, "dyhyp" ); // set start values: tanhFcn->SetParameter( 0, 0 ); // dy off [um] tanhFcn->SetParameter( 1, 99 ); // dy slope [um/skw] tanhFcn->SetParameter( 2, 0 ); // dy parabola tanhFcn->SetParameter( 3, 0 ); // dy hyperbola h->Fit( "tanhFcn", "R Q", "p" );// R = range from tanhFcn std::vector<double> result; for(size_t i = 0; i < 4; i++) { result.push_back(tanhFcn->GetParameter(i)); } return result; }
void fitTProfileCustom(TProfile* p) { // Display fit info on canvas. gStyle->SetOptFit(0011); // Fit things. // TF1* fit = new TF1("fit", "[0]*exp([4]*x)*sin([1]*x**0.5 + [2]) + [3]", -20, 20); TF1* fit = new TF1("fit", "[0]*(x**2)*sin([1]*x**0.5 + [2]) + [3]", -20, 20); fit->SetParName(0, "Scale"); fit->SetParName(1, "Frequency"); fit->SetParName(2, "Phase"); fit->SetParName(3, "Shift"); // fit->SetParName(4, "Decay Length"); fit->SetParameter(0, 0.006 ); // fit->SetParameter(0, 0.01 ); fit->SetParameter(1, -7); fit->SetParameter(2, 2.5); fit->SetParameter(3, 91); // fit->SetParameter(4, 0.000795); bool converged = 0; int ntries = 0; // Make sure the fit converges. while(!converged) { if(ntries >= 50) break; std::cout << "==== " << p->GetTitle() << " ====" << std::endl; p->Fit("fit", "", "", 20, 61); TString sconverge = gMinuit->fCstatu.Data(); converged = sconverge.Contains(TString("CONVERGED")); ntries++; } }
TF1* Mathematics::gamma_func( int OutputLevel ) { // the gamma function in ROOT has issues with verbosity, let's silence it and then return the verbosity back at the end streambuf *nullbuf=NULL, *cout_bak=NULL, *cerr_bak=NULL, *clog_bak=NULL; ofstream filestr; filestr.open ("/dev/null"); // If the user wanted silence we point the Std Output Streams to /dev/null if( OutputLevel <= -1 ) { cout_bak = cout.rdbuf(); cerr_bak = cerr.rdbuf(); clog_bak = clog.rdbuf(); nullbuf = filestr.rdbuf(); cout.rdbuf(nullbuf); cerr.rdbuf(nullbuf); clog.rdbuf(nullbuf); } TF1* output = new TF1( "gammaf", "[0]*TMath::GammaDist( x, ([1]*[1])/([2]*[2]), 0, ([2]*[2])/[1] )" ); // TF1 inherits from TFormula so we can use it's functions to rename the parameters to have consistancy with gaus / landau functions output->SetParName( 0, "Constant" ); output->SetParName( 1, "Mean" ); output->SetParName( 2, "Sigma" ); // Reset Std Output Streams if( OutputLevel <= -1 ) { cout.rdbuf(cout_bak); cerr.rdbuf(cerr_bak); clog.rdbuf(clog_bak); } return output; }
TF1* GetFit(const char *run, const char *inname, const char *outname) { ifstream infit; infit.open( Form("%s/fit/%s.dat",run,inname) ); double tmp; bool found; infit >> alp >> tmp >> lda >> elda >> sgm >> esgm >> f2 >> tmp >> f3 >> tmp >> f4; infit.close(); cout << alp << endl; cout << lda << endl; cout << sgm << endl; cout << f2 << endl; cout << f3 << endl; cout << f4 << endl; double f1 = 1-f2-f3-f4; if(1-f2<0.01) return NULL; const char *la1 = Form("%f*TMath::Landau(x,1.00*%f*[0],1.0*%f*[1],1)",f1,lda,sgm); const char *la2 = Form("%f*TMath::Landau(x,2.14*%f*[0],2.0*%f*[1],1)",f2,lda,sgm); const char *la3 = Form("%f*TMath::Landau(x,3.33*%f*[0],3.0*%f*[1],1)",f3,lda,sgm); const char *la4 = Form("%f*TMath::Landau(x,4.55*%f*[0],4.0*%f*[1],1)",f4,lda,sgm); TF1 *ret = new TF1("fit_H1", Form("%f*(%s+%s+%s+%s)",alp,la1,la2,la3,la4) ); ret->SetParName(0,"sLDA"); ret->SetParName(1,"SSGM"); ret->SetParameter(0,1.0); ret->SetParLimits(0,1e-3,2.0); ret->SetParameter(1,1.0); ret->SetParLimits(1,1e-3,2.0); ret->SetLineColor(kRed-3); infit.open( Form("%s/fit/%s.dat",run,outname) ); tmp; found=false; for(int n=0; n!=ret->GetNpar(); ++n) { infit >> tmp; if(!infit.good()) break; ret->SetParameter(n,tmp); infit >> tmp; found = true; } infit.close(); if(found) { cout << " Previous fit results found" << endl; } cout << lda << endl; return ret; }
void doCoinc3(const char *fileIn="SAVO-01-SAVO-02-SAVO-03-2016-01-26.root"){ Int_t adayMin = (yearRange[0]-2007) * 1000 + monthRange[0]*50 + dayRange[0]; Int_t adayMax = (yearRange[1]-2007) * 1000 + monthRange[1]*50 + dayRange[1]; // define some histos TH1F *hDeltaTheta12 = new TH1F("hDeltaTheta12","#Delta#theta_{12} below the peak (500 ns);#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhi12 = new TH1F("hDeltaPhi12","#Delta#phi_{12} below the peak (500 ns);#Delta#phi (#circ)",200,-360,360); TH1F *hDeltaThetaBack12 = new TH1F("hDeltaThetaBack12","#Delta#theta_{12} out of the peak (> 1000 ns) - normalized;#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhiBack12 = new TH1F("hDeltaPhiBack12","#Delta#phi_{12} out of the peak (> 1000 ns) - normalized;#Delta#phi (#circ)",200,-360,360); TH1F *hThetaRel12 = new TH1F("hThetaRel12","#theta_{rel}_{12} below the peak (500 ns);#theta_{rel} (#circ)",100,0,120); TH1F *hThetaRelBack12 = new TH1F("hThetaRelBack12","#theta_{rel}_{12} out of the peak (> 1000 ns) - normalized;#theta_{rel} (#circ)",100,0,120); TH1F *hDeltaTheta13 = new TH1F("hDeltaTheta13","#Delta#theta_{13} below the peak (500 ns);#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhi13 = new TH1F("hDeltaPhi13","#Delta#phi_{13} below the peak (500 ns);#Delta#phi (#circ)",200,-360,360); TH1F *hDeltaThetaBack13 = new TH1F("hDeltaThetaBack13","#Delta#theta_{13} out of the peak (> 1000 ns) - normalized;#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhiBack13 = new TH1F("hDeltaPhiBack13","#Delta#phi_{13} out of the peak (> 1000 ns) - normalized;#Delta#phi (#circ)",200,-360,360); TH1F *hThetaRel13 = new TH1F("hThetaRel13","#theta_{rel}_{13} below the peak (500 ns);#theta_{rel} (#circ)",100,0,120); TH1F *hThetaRelBack13 = new TH1F("hThetaRelBack13","#theta_{rel}_{13} out of the peak (> 1000 ns) - normalized;#theta_{rel} (#circ)",100,0,120); TFile *f = new TFile(fileIn); TTree *t = (TTree *) f->Get("tree"); TTree *tel[3]; tel[0] = (TTree *) f->Get("treeTel1"); tel[1] = (TTree *) f->Get("treeTel2"); tel[2] = (TTree *) f->Get("treeTel3"); TTree *telC = (TTree *) f->Get("treeTimeCommon"); // quality info of runs Bool_t runstatus[3][10][12][31][500]; //#telescope, year-2007, month, day, run if(tel[0] && tel[1] && tel[2]){ for(Int_t i=0;i < 3;i++){ // loop on telescopes for(Int_t j=0;j < tel[i]->GetEntries();j++){ // loop on runs tel[i]->GetEvent(j); Int_t aday = (tel[i]->GetLeaf("year")->GetValue()-2007) * 1000 + tel[i]->GetLeaf("month")->GetValue()*50 + tel[i]->GetLeaf("day")->GetValue(); if(aday < adayMin || aday > adayMax) continue; if(tel[i]->GetLeaf("FractionGoodTrack")->GetValue() < fracGT[i]) continue; // cut on fraction of good track if(tel[i]->GetLeaf("timeduration")->GetValue()*tel[i]->GetLeaf("rateHitPerRun")->GetValue() < hitevents[i]) continue; // cut on the number of event if(tel[i]->GetLeaf("ratePerRun")->GetValue() < rateMin[i] || tel[i]->GetLeaf("ratePerRun")->GetValue() > rateMax[i]) continue; // cut on the rate if(tel[i]->GetLeaf("run")->GetValue() > 499) continue; // run < 500 Float_t missinghitfrac = (tel[i]->GetLeaf("ratePerRun")->GetValue()-tel[i]->GetLeaf("rateHitPerRun")->GetValue()-2)/(tel[i]->GetLeaf("ratePerRun")->GetValue()-2); if(missinghitfrac < minmissingHitFrac[i] || missinghitfrac > maxmissingHitFrac[i]) continue; runstatus[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2007][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = kTRUE; } } } else{ telC = NULL; } Int_t n = t->GetEntries(); // counter for seconds Int_t nsec = 0; Int_t nsecGR = 0; // for good runs Int_t isec = -1; // used only in case the tree with time info is not available if(telC){ for(Int_t i=0; i < telC->GetEntries();i++){ telC->GetEvent(i); nsec += telC->GetLeaf("timeduration")->GetValue(); if(telC->GetLeaf("run")->GetValue() > 499 || telC->GetLeaf("run2")->GetValue() > 499 || telC->GetLeaf("run3")->GetValue() > 499) continue; if(!runstatus[0][Int_t(telC->GetLeaf("year")->GetValue())-2007][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())]) continue; if(!runstatus[1][Int_t(telC->GetLeaf("year")->GetValue())-2007][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run2")->GetValue())]) continue; if(!runstatus[2][Int_t(telC->GetLeaf("year")->GetValue())-2007][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run2")->GetValue())]) continue; nsecGR += telC->GetLeaf("timeduration")->GetValue(); } } char title[600]; TH1F *h; TH2F *h2; sprintf(title,"correction assuming #Delta#phi_{12} = %4.2f, #DeltaL_{12} = %.1f m, #Delta#phi_{13} = %4.2f, #DeltaL_{13} = %.1f m;#Deltat_{13} (ns) when |#Deltat_{12}| < %i ns;entries",angle12,distance12,angle13,distance13,timeCutOn12); h = new TH1F("hCoinc",title,nbint,tmin,tmax); sprintf(title,"correction assuming #Delta#phi_{12} = %4.2f, #DeltaL_{12} = %.1f m, #Delta#phi_{13} = %4.2f, #DeltaL_{13} = %.1f m;#Deltat_{12} (ns);#Deltat_{13} (ns);entries",angle12,distance12,angle13,distance13,timeCutOn12); h2 = new TH2F("hCoinc2D",title,nbint,tmin,tmax,nbint,tmin,tmax); Float_t DeltaT12,DeltaT13; Float_t phiAv,thetaAv,corr12,corr13; Float_t Theta1,Theta2,Theta3; Float_t Phi1,Phi2,Phi3; Float_t v1[3],v2[3],v3[3],vSP12,vSP13; // variable to recompute ThetaRel on the fly for(Int_t i=0;i<n;i++){ t->GetEvent(i); // if(t->GetLeaf("RunNumber1") && (t->GetLeaf("RunNumber1")->GetValue() > 499 || t->GetLeaf("RunNumber2")->GetValue() > 499) || t->GetLeaf("RunNumber3")->GetValue() > 499)) continue; // if(tel[0] && !runstatus[0][Int_t(t->GetLeaf("year")->GetValue())-2007][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber1")->GetValue())]) continue; // if(tel[1] && !runstatus[1][Int_t(t->GetLeaf("year")->GetValue())-2007][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber2")->GetValue())]) continue; // if(tel[2] && !runstatus[2][Int_t(t->GetLeaf("year")->GetValue())-2007][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber2")->GetValue())]) continue; Int_t timec = t->GetLeaf("ctime1")->GetValue(); if(! telC){ if(isec == -1) isec = timec; if(timec != isec){ if(timec - isec < 20){ // printf("diff = %i\n",timec-isec); nsec +=(timec - isec); nsecGR +=(timec - isec); } isec = timec; } } Float_t thetarel12 = t->GetLeaf("ThetaRel12")->GetValue(); Float_t thetarel13 = t->GetLeaf("ThetaRel13")->GetValue(); Theta1 = t->GetLeaf("Theta1")->GetValue()*TMath::DegToRad(); Theta2 = t->GetLeaf("Theta2")->GetValue()*TMath::DegToRad(); Theta3 = t->GetLeaf("Theta3")->GetValue()*TMath::DegToRad(); Phi1 = t->GetLeaf("Phi1")->GetValue()*TMath::DegToRad(); Phi2 = t->GetLeaf("Phi2")->GetValue()*TMath::DegToRad(); Phi3 = t->GetLeaf("Phi3")->GetValue()*TMath::DegToRad(); if(recomputeThetaRel){ // recompute ThetaRel applying corrections Phi1 -= phi1Corr*TMath::DegToRad(); Phi2 -= phi2Corr*TMath::DegToRad(); Phi3 -= phi3Corr*TMath::DegToRad(); if(Phi1 > 2*TMath::Pi()) Phi1 -= 2*TMath::Pi(); if(Phi1 < 0) Phi1 += 2*TMath::Pi(); if(Phi2 > 2*TMath::Pi()) Phi2 -= 2*TMath::Pi(); if(Phi2 < 0) Phi2 += 2*TMath::Pi(); if(Phi3 > 2*TMath::Pi()) Phi3 -= 2*TMath::Pi(); if(Phi3 < 0) Phi3 += 2*TMath::Pi(); v1[0] = TMath::Sin(Theta1)*TMath::Cos(Phi1); v1[1] = TMath::Sin(Theta1)*TMath::Sin(Phi1); v1[2] = TMath::Cos(Theta1); v2[0] = TMath::Sin(Theta2)*TMath::Cos(Phi2); v2[1] = TMath::Sin(Theta2)*TMath::Sin(Phi2); v2[2] = TMath::Cos(Theta2); v3[0] = TMath::Sin(Theta3)*TMath::Cos(Phi3); v3[1] = TMath::Sin(Theta3)*TMath::Sin(Phi3); v3[2] = TMath::Cos(Theta3); v2[0] *= v1[0]; v2[1] *= v1[1]; v2[2] *= v1[2]; v3[0] *= v1[0]; v3[1] *= v1[1]; v3[2] *= v1[2]; vSP12 = v2[0] + v2[1] + v2[2]; vSP13 = v3[0] + v3[1] + v3[2]; thetarel12 = TMath::ACos(vSP12)*TMath::RadToDeg(); thetarel13 = TMath::ACos(vSP13)*TMath::RadToDeg(); } // cuts if(thetarel12 > maxthetarel) continue; if(thetarel13 > maxthetarel) continue; if(t->GetLeaf("ChiSquare1")->GetValue() > maxchisquare) continue; if(t->GetLeaf("ChiSquare2")->GetValue() > maxchisquare) continue; if(t->GetLeaf("ChiSquare3")->GetValue() > maxchisquare) continue; DeltaT12 = t->GetLeaf("DiffTime12")->GetValue(); DeltaT13 = t->GetLeaf("DiffTime13")->GetValue(); // get primary direction if(TMath::Abs(Phi1-Phi2) < TMath::Pi()) phiAv = (Phi1+Phi2)*0.5; else phiAv = (Phi1+Phi2)*0.5 + TMath::Pi(); if(TMath::Abs(phiAv-Phi3) < TMath::Pi()) phiAv = (phiAv*2+Phi2)*0.33333333333; else if(phiAv > Phi3) phiAv = (phiAv*2+Phi3+2*TMath::Pi())*0.33333333333; else phiAv = (phiAv*2+4*TMath::Pi()+Phi3)*0.33333333333; thetaAv = (Theta1+Theta2+Theta3)*0.333333333333; // extra cuts if needed // if(TMath::Cos(Phi1-Phi2) < 0.) continue; corr12 = distance12 * TMath::Sin(thetaAv)*TMath::Cos(phiAv-angle12)/2.99792458000000039e-01 + deltatCorr12; corr13 = distance13 * TMath::Sin(thetaAv)*TMath::Cos(phiAv-angle13)/2.99792458000000039e-01 + deltatCorr13; if(TMath::Abs(DeltaT12-corr12) < timeCutOn12) h->Fill(DeltaT13-corr13); h2->Fill(DeltaT12-corr12,DeltaT13-corr13); if(TMath::Abs(DeltaT12-corr12) < 500){ hDeltaTheta12->Fill((Theta1-Theta2)*TMath::RadToDeg()); hDeltaPhi12->Fill((Phi1-Phi2)*TMath::RadToDeg()); hThetaRel12->Fill(thetarel12); } else if(TMath::Abs(DeltaT12-corr12) > 1000 && TMath::Abs(DeltaT12-corr12) < 6000){ hDeltaThetaBack12->Fill((Theta1-Theta2)*TMath::RadToDeg()); hDeltaPhiBack12->Fill((Phi1-Phi2)*TMath::RadToDeg()); hThetaRelBack12->Fill(thetarel12); } if(TMath::Abs(DeltaT13-corr13) < 500){ hDeltaTheta13->Fill((Theta1-Theta3)*TMath::RadToDeg()); hDeltaPhi13->Fill((Phi1-Phi3)*TMath::RadToDeg()); hThetaRel13->Fill(thetarel13); } else if(TMath::Abs(DeltaT13-corr13) > 1000 && TMath::Abs(DeltaT13-corr13) < 6000){ hDeltaThetaBack13->Fill((Theta1-Theta3)*TMath::RadToDeg()); hDeltaPhiBack13->Fill((Phi1-Phi3)*TMath::RadToDeg()); hThetaRelBack13->Fill(thetarel13); } } h->SetStats(0); hDeltaThetaBack12->Sumw2(); hDeltaPhiBack12->Sumw2(); hThetaRelBack12->Sumw2(); hDeltaThetaBack12->Scale(0.1); hDeltaPhiBack12->Scale(0.1); hThetaRelBack12->Scale(0.1); hDeltaThetaBack13->Sumw2(); hDeltaPhiBack13->Sumw2(); hThetaRelBack13->Sumw2(); hDeltaThetaBack13->Scale(0.1); hDeltaPhiBack13->Scale(0.1); hThetaRelBack13->Scale(0.1); Float_t val,eval; TCanvas *c1=new TCanvas(); TF1 *ff = new TF1("ff","[0]*[4]/[2]/sqrt(2*TMath::Pi())*TMath::Exp(-(x-[1])*(x-[1])*0.5/[2]/[2]) + [3]*[4]/6/[2]"); ff->SetParName(0,"signal"); ff->SetParName(1,"mean"); ff->SetParName(2,"sigma"); ff->SetParName(3,"background"); ff->SetParName(4,"bin width"); ff->SetParameter(0,42369); ff->SetParameter(1,0); ff->SetParLimits(2,10,1000); ff->SetParameter(2,150); // fix witdh if needed ff->SetParameter(3,319); ff->FixParameter(4,20000./nbint); // bin width ff->SetNpx(1000); h->Fit(ff); val = ff->GetParameter(2); eval = ff->GetParError(2); printf("significance = %f\n",ff->GetParameter(0)/sqrt(ff->GetParameter(0) + ff->GetParameter(3))); h->Draw(); TF1 *func1 = (TF1 *) h->GetListOfFunctions()->At(0); func1->SetLineColor(2); h->SetLineColor(4); TPaveText *text = new TPaveText(1500,(h->GetMinimum()+(h->GetMaximum()-h->GetMinimum())*0.6),9500,h->GetMaximum()); text->SetFillColor(0); sprintf(title,"width = %5.1f #pm %5.1f",func1->GetParameter(2),func1->GetParError(2)); text->AddText(title); sprintf(title,"signal (S) = %5.1f #pm %5.1f",func1->GetParameter(0),func1->GetParError(0)); text->AddText(title); sprintf(title,"background (B) (3#sigma) = %5.1f #pm %5.1f",func1->GetParameter(3),func1->GetParError(3)); text->AddText(title); sprintf(title,"significance (S/#sqrt{S+B}) = %5.1f",func1->GetParameter(0)/sqrt(func1->GetParameter(0)+func1->GetParameter(3))); text->AddText(title); text->SetFillStyle(0); text->SetBorderSize(0); text->Draw("SAME"); printf("n_day = %f\nn_dayGR = %f\n",nsec*1./86400,nsecGR*1./86400); text->AddText(Form("rate = %f #pm %f per day",func1->GetParameter(0)*86400/nsecGR,func1->GetParError(0)*86400/nsecGR)); TFile *fo = new TFile("output-SAVO-010203.root","RECREATE"); h->Write(); h2->Write(); hDeltaTheta12->Write(); hDeltaPhi12->Write(); hThetaRel12->Write(); hDeltaThetaBack12->Write(); hDeltaPhiBack12->Write(); hThetaRelBack12->Write(); hDeltaTheta13->Write(); hDeltaPhi13->Write(); hThetaRel13->Write(); hDeltaThetaBack13->Write(); hDeltaPhiBack13->Write(); hThetaRelBack13->Write(); fo->Close(); }
void fitGausExample() { int bins = 100; int min = 0; int max = 1600; sigMin = 500; sigMax = 800; double bgMin = 100; double bgMax = 1300; double xpos; TCanvas *testCanvas = new TCanvas("testCanvas","testCanvas",600,400); //x,y pad1 = new TPad("pad1","pad1",0.0000,0.0000,1.0000,1.0000,0,0,0); pad1->Draw(); pad1->cd(); TH1F *h1 = new TH1F("h1","Fitting Example",bins,min,max); TH1F *h2 = new TH1F("h2","h2",bins,min,max); TH1F *h3 = new TH1F("h3","Fitting Example",bins,min,max); TH1F *bg = new TH1F("bg","bg",bins,min,max); // The section below will fill h1 with a guassian // function with a mean of 670 and a sigma of 20 // and fill h2 with a "uniform" random background // from bgMin<x<bgMax for (int i=0; i<10000000; i++) { // h1->Fill(gRandom->Uniform(10,1400)); h1->Fill(gRandom->Uniform(0,1600)); h1->Fill(gRandom->Exp(1400)); } for (int i=0; i<100000; i++) { // h1->Fill(gRandom->Uniform(1400,1500)); } for (int i=0; i<50000; i++) { h1->Fill(gRandom->Gaus(670,20)); } for (int i=0; i<bins; i++) { // xpos = i*((max-min)/bins)+min; // cout << "xpos: " << xpos << endl; // h1->Fill(xpos,100*exp((-1)*xpos)); // h2->Fill(i*((max-min)/bins)+min,i*500); } // h1->Add(h2,-1); h1->SetMinimum(0); h1->SetMaximum(300000); h1->Draw(); TF1 *bgFit = new TF1("bgFit","[0]+[1]*x",bgMin,bgMax); // TF1 *bgFit = new TF1("bgFit","expo",bgMin,bgMax); // TF1 *bgFit = new TF1("bgFit","exp([1]*x+[0])+[2]",bgMin,bgMax); TF1 *bgFit = new TF1("bgFit",fline,bgMin,sigMin,3); bgFit->SetLineColor(kOrange); bgFit->SetParameter(0,1); bgFit->SetParameter(1,1/1600); bgFit->SetParameter(2,1); bgFit->SetParName(0,"Offset"); bgFit->SetParName(1,"Tau"); bgFit->SetParName(2,"Background"); reject = kTRUE; h1->Fit(bgFit,"R"); reject = kFALSE; TF1 *fleft = new TF1("fleft",fline,bgMin,sigMin,3); fleft->SetLineColor(kOrange); fleft->SetParameters(bgFit->GetParameters()); h1->GetListOfFunctions()->Add(fleft); gROOT->GetListOfFunctions()->Remove(fleft); TF1 *fright = new TF1("fright",fline,sigMax,bgMax,3); fright->SetLineColor(kOrange); fright->SetParameters(bgFit->GetParameters()); h1->GetListOfFunctions()->Add(fright); gROOT->GetListOfFunctions()->Remove(fright); // h1->SetMaximum(300000); h1->Draw(); double fitOffset = bgFit->GetParameter(0); double fitTau = bgFit->GetParameter(1); // double fitBackground = bgFit->GetParameter(2); double fitOffsetErr = bgFit->GetParError(0); double fitTauErr = bgFit->GetParError(1); // double fitBackgroundErr = bgFit->GetParError(2); cout << "Number of Bins: " << h1->GetSize()-2 << endl;; cout << "fitOffset: " << fitOffset << endl;; cout << "fitTau: " << fitTau << endl;; for (int i=0; i<(h1->GetSize()-2); i++) { xpos = i*((max-min)/bins)+min; // h2->Fill(xpos,i*500); bg->Fill(xpos,(fitOffset + fitTau*xpos)); // bg->Fill(xpos,(exp(fitTau*xpos + fitOffset) + fitBackground)); } bg->SetLineColor(kBlue); bg->Draw("same"); h3->Add(h1); h3->Add(bg,-1); h3->SetLineColor(kRed); h3->SetMinimum(0); h3->Draw("same"); cout << "sigMin: " << sigMin << ", sigMax: " << sigMax << endl; TF1 *sigFit = new TF1("sigFit","gaus",sigMin,sigMax); sigFit->SetLineColor(kBlue); sigFit->SetParameter(0,1000); sigFit->SetParameter(1,690); sigFit->SetParameter(2,20); sigFit->SetParameter(3,1); sigFit->SetParName(0,"Weight"); sigFit->SetParName(1,"Mean"); sigFit->SetParName(2,"Sigma"); // sigFit->SetParName(3,"Background"); h3->SetMaximum(300000); h3->Fit(sigFit,"R"); sigFit->Draw("same"); double fitWeight = sigFit->GetParameter(0); double fitMean = sigFit->GetParameter(1); double fitSigma = sigFit->GetParameter(2); double fitWeightErr = sigFit->GetParError(0); double fitMeanErr = sigFit->GetParError(1); double fitSigmaErr = sigFit->GetParError(2); fitResults = new TPaveText(0.11,0.70,0.4,0.89,"NDC"); TString WeightStr = "Weight = "; WeightStr += fitWeight; WeightStr += " ± "; WeightStr += fitWeightErr; TString MeanStr = "Mean = "; MeanStr += fitMean; MeanStr += " ± "; MeanStr += fitMeanErr; TString SigmaStr = "Sigma = "; SigmaStr += sqrt(fitSigma*fitSigma); SigmaStr += " ± "; SigmaStr += fitSigmaErr; TString OffsetStr = "Offset = "; OffsetStr += fitOffset; OffsetStr += " ± "; OffsetStr += fitOffsetErr; TString TauStr = "Tau = "; TauStr += fitTau; TauStr += " ± "; TauStr += fitTauErr; TString BackgroundStr = "BackgroundConst = "; BackgroundStr += fitBackground; BackgroundStr += " ± "; BackgroundStr += fitBackgroundErr; TText *t1 = fitResults->AddText(WeightStr); TText *t2 = fitResults->AddText(MeanStr); TText *t3 = fitResults->AddText(SigmaStr); TText *t4 = fitResults->AddText(BackgroundStr); TText *t5 = fitResults->AddText(TauStr); TText *t6 = fitResults->AddText(OffsetStr); h1->Draw("same"); TString theFitStr = "("; theFitStr += fitWeight; theFitStr += "*exp(-0.5*((x-"; theFitStr += fitMean; theFitStr += ")/"; theFitStr += fitSigma; theFitStr += ")^2))+"; theFitStr += fitBackground; theFitStr += "+exp("; theFitStr += fitTau; theFitStr += "*x+"; theFitStr += fitOffset; theFitStr += ")"; TF1 *theFit = new TF1("theFit",theFitStr,bgMin,bgMax); theFit->SetLineColor(kMagenta); theFit->Draw("same"); double integralOfPeak; integralOfPeak = sigFit->Integral((fitMean - 3*sqrt(fitSigma*fitSigma)),(fitMean + 3*sqrt(fitSigma*fitSigma))); TString peakInt = "Integral of Peak: "; peakInt += integralOfPeak; cout << peakInt << endl; TText *t7 = fitResults->AddText(peakInt); pad1->Update(); TString outputPlotsHere = "/home/ellie/physics/e05-102/analysis-scripts/devel/test_stuff/"; TString testOutTitle = outputPlotsHere; testOutTitle += "test_out_step_1"; testOutTitle += ".svg"; fitResults->Draw("same"); }
void plotphi(int top, bool phi=kFALSE){ if (setup("vm","","pol__")==kFALSE) return; gStyle->SetOptFit(1111); //pcev = 1111 //gStyle->SetTitleW(1.5); int itop = top-1; TFile* fy = _fyexp[itop]; int nq2wbins = fy->GetNkeys(); TIter nextkey(fy->GetListOfKeys()); TKey *key; int iq2wbin = 0; while (key = (TKey*)nextkey()) { TString Q2Wdirname = key->GetName(); if(Q2Wdirname.EqualTo("hYW_Dir") || Q2Wdirname.EqualTo("hYW"))continue; cout << "Q2Wdirname = " << Q2Wdirname << endl; THStack* hs[10]; TF1 *fphi = new TF1("fphi", "([0] + [1]*cos(x*TMath::DegToRad()) + [2]*cos(2*x*TMath::DegToRad()) + [3]*sin(x*TMath::DegToRad()))",0, 360); fphi->SetParameter(0,1); fphi->SetParameter(1,10); fphi->SetParameter(2,20); fphi->SetParameter(3,100); fphi->SetParName(0, "A"); fphi->SetParName(1, "B"); fphi->SetParName(2, "C"); fphi->SetParName(3, "hPR"); for (int i = 0; i < 10; i++) { TString hname_unp = TString::Format("%s/hPhi/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1); TString hname_pos = TString::Format("%s/hPhi_POS/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1); TString hname_neg = TString::Format("%s/hPhi_NEG/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1); cout << "hname_unp = " << hname_unp << endl; cout << "hname_pos = " << hname_pos << endl; cout << "hname_neg = " << hname_neg << endl; TH1D* hunp = (TH1D*)fy->Get(hname_unp); TH1D* hpos = (TH1D*)fy->Get(hname_pos); TH1D* hneg = (TH1D*)fy->Get(hname_neg); if (hunp==NULL || hpos==NULL || hneg==NULL) cout << "histogram not found" << endl; hunp->SetLineColor(kBlack); hpos->SetLineColor(kRed); hneg->SetLineColor(kBlue); hunp->Fit(fphi); hpos->Fit(fphi); hneg->Fit(fphi); //! Modify titles TObjArray *tarr; char t[100]; TPaveText *ptunp = new TPaveText(0.0, 0.9, 1.0, 1, "NDC"); TString tunp = hunp->GetTitle(); tarr = tunp.Tokenize("|"); sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName()); ptunp->AddText(tarr->At(0)->GetName()); ptunp->AddText(t); hunp->SetTitle(""); TPaveText *ptpos = new TPaveText(0.0, 0.9, 1.0, 1, "NDC"); TString tpos = hpos->GetTitle(); tarr = tpos.Tokenize("|"); sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName()); ptpos->AddText(tarr->At(0)->GetName()); ptpos->AddText(t); hpos->SetTitle(""); TPaveText *ptneg = new TPaveText(0.0, 0.9, 1.0, 1, "NDC"); TString tneg = hneg->GetTitle(); tarr = tneg.Tokenize("|"); sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName()); ptneg->AddText(tarr->At(0)->GetName()); ptneg->AddText(t); hneg->SetTitle(""); //! Draw histograms TCanvas *c = new TCanvas(hpos->GetName(),hpos->GetName(),900, 600); c->Divide(3,1); c->cd(1); hunp->Draw(); ptunp->Draw(); c->cd(2); hpos->Draw(); ptpos->Draw(); c->cd(3); hneg->Draw(); ptneg->Draw(); TString dir = TString::Format("./polobs/top%d/%s/Varset1/theta", top, Q2Wdirname.Data()); gSystem->mkdir(dir,1); c->SaveAs(TString::Format("%s/%s.png", dir.Data(), c->GetName())); c->Close(); c->Delete(); } } }
//________________________________________________________________________________ void peaks(TH1* h, Int_t np=10, Int_t ij=0) { if (! h) return; npeaks = TMath::Abs(np); if (! c1) c1 = new TCanvas(); else c1->Clear(); if (c2 && ij > 0) {c2->cd(ij); h->Draw(); c2->Update();} c1->Divide(1,2); c1->cd(1); h->Draw(); TH1F *h2 = (TH1F*)h->Clone("h2"); //Use TSpectrum to find the peak candidates TSpectrum *s = new TSpectrum(2*npeaks); Int_t nfound = s->Search(h,5,"",0.05); printf("Found %d candidate peaks to fit\n",nfound); if (! nfound) return; //Estimate background using TSpectrum::Background TH1 *hb = s->Background(h,20,"same"); hb->Draw("same"); c1->Update(); if (c2 && ij > 0) {c2->cd(ij); h->Draw(); c2->Update();} if (np <0) return; //estimate linear background using a fitting method c1->cd(2); TF1 *fline = new TF1("fline","pol1",0,1000); fline->FixParameter(1,0.); h->Fit("fline","qnlw"); if (c2 && ij > 0) {c2->cd(ij+1); h->Draw(); c2->Update(); c1->cd(2);} //Loop on all found peaks. Eliminate peaks at the background level Double_t par[3000]; par[0] = fline->GetParameter(0); par[1] = fline->GetParameter(1); npeaks = 0; Float_t *xpeaks = s->GetPositionX(); Float_t ymax = 0; for (Int_t p=0;p<nfound;p++) { Float_t xp = xpeaks[p]; Int_t bin = h->GetXaxis()->FindBin(xp); Float_t yp = h->GetBinContent(bin); if (yp-3*TMath::Sqrt(yp) < fline->Eval(xp)) continue; par[3*npeaks+2] = yp; if (yp > ymax) ymax = yp; par[3*npeaks+3] = xp; par[3*npeaks+4] = 3; npeaks++; } cout << "Found " << npeaks << " useful peaks to fit" << endl; Int_t NP = 0; Int_t nbad = 0; TString LineH(" {\""); LineH += h->GetName(); LineH += "\""; TString Line(""); struct ParErr_t {Double_t par, err;}; ParErr_t parErr[10]; TF1 *fit = 0; if (ymax > 2*par[0]) { cout << "Now fitting: Be patient" << endl; fit = new TF1("fit",fpeaks,0,1000,2+3*npeaks); TVirtualFitter::Fitter(h2,10+3*npeaks); //we may have more than the default 25 parameters fit->SetParameter(0,par[0]); fit->FixParameter(1,0.); for (Int_t p = 0; p < npeaks; p++) { fit->SetParName(3*p+2,Form("A%i",p)); fit->SetParLimits(3*p+2,0,1e6); fit->SetParameter(3*p+2,par[3*p+2]); fit->SetParName(3*p+3,Form("#mu%i",p)); fit->SetParLimits(3*p+3,TMath::Max(0.,par[3*p+3]-2), TMath::Min(240.,par[3*p+3]+2)); fit->SetParameter(3*p+3,par[3*p+3]); fit->SetParName(3*p+4,Form("#sigma%i",p)); fit->SetParLimits(3*p+4,0.01,20); fit->SetParameter(3*p+4,par[3*p+4]); } fit->SetNpx(1000); h2->SetStats(0); h2->Fit("fit","l"); if (c2 && ij > 0) {c2->cd(ij); h2->Draw("same"); c2->Update(); c1->cd(2);} fit->GetParameters(par); for (Int_t p = 0; p<np;p++) { if (p < npeaks && par[3*p+2] > 5*fit->GetParError(3*p+2) && par[3*p+2] > par[0]) { if (TMath::Abs(par[3*p+4]) > 5.0) nbad++; // Line += Form(",%f,%f,%7.2f,%5.2f",par[3*p+2],fit->GetParError(3*p+2),par[3*p+3],TMath::Abs(par[3*p+4])); parErr[NP].par = par[3*p+3]; parErr[NP].err = TMath::Abs(par[3*p+4]); for (Int_t i = 0; i < NP; i++) { if (parErr[i].par > parErr[NP].par) { ParErr_t temp = parErr[i]; parErr[i] = parErr[NP]; parErr[NP] = temp; } } NP++; } } } for (Int_t p = 0; p < np; p++) { if (p < NP) Line += Form(",%7.2f,%5.2f",parErr[p].par,parErr[p].err); else Line += ",0,0"; } Line += "},"; if (nbad > 1) NP = -NP; // reject whole hybrid LineH += Form(",%3i",NP); cout << LineH << Line << endl; out << LineH << Line << endl; c1->Update(); if (c2) c2->Update(); delete fit; delete s; }
TH1D* readData(TString dataset, TString name, TString wavel, Double_t peak1, Double_t peak2, Double_t intTime, Double_t shift){ TString fileName = "./Data/" + dataset + ".txt"; Double_t histoMin = 99999, histoMax = 0; ifstream ifs(fileName); if(!ifs.is_open()){cout << "Error. File " << fileName << " not found. Exiting...\n"; return NULL;} Double_t entry, wavelength, photons, stepsize; while(ifs >> entry >> wavelength >> photons){ if(entry == 1) stepsize = wavelength; else if(entry == 2) stepsize = wavelength - stepsize; if(wavelength < histoMin) histoMin = wavelength; if(wavelength > histoMax) histoMax = wavelength; } ifs.close(); TH1D *histo = new TH1D(name + wavel + TString::Format(" %1.2f", shift), name + wavel + TString::Format(" %1.2f", shift), Nint(entry), histoMin + shift - stepsize/2.0, histoMax + shift + stepsize/2.0); ifs.open(fileName); if(!ifs.is_open()){cout << "Error. File " << fileName << " not found. Exiting...\n"; return NULL;} while(ifs >> entry >> wavelength >> photons){ for(Int_t x = 0; x< photons/(1000.0/intTime); x++){ histo->Fill(wavelength + shift); } } ifs.close(); TF1 *f; if(peak2 == 0.){ f = new TF1("fit", "[0]+[1]*TMath::Voigt(x-[2],[3],[4])"); f->SetParameter(0, histo->GetMinimum()); f->SetParameter(1, histo->GetMaximum()/25.); f->SetParameter(2, peak1 + shift); f->SetParameter(3, .02); f->SetParameter(4, .02); f->SetParName(0, "Offset"); f->SetParName(1, "Normalization"); f->SetParName(2, "Mean"); f->SetParName(3, "Sigma"); f->SetParName(4, "Gamma"); } else{ f = new TF1("fit", "[0]+[1]*TMath::Voigt(x-[2],[3],[4])+[5]*TMath::Voigt(x-[6],[7],[8])"); f->SetParameter(0, histo->GetMinimum()); f->SetParameter(1, histo->GetMaximum()/20.); f->SetParameter(2, peak1+shift-0.1); f->SetParameter(3, .02); f->SetParameter(4, .02); f->SetParameter(5, histo->GetMaximum()/20.); f->SetParameter(6, peak2+shift+0.1); f->SetParameter(7, .02); f->SetParameter(8, .02); f->SetParName(0, "Offset"); f->SetParName(1, "Normalization 1"); f->SetParName(2, "Mean 1"); f->SetParName(3, "Sigma 1"); f->SetParName(4, "Gamma 1"); f->SetParName(5, "Normalization 2"); f->SetParName(6, "Mean 2"); f->SetParName(7, "Sigma 2"); f->SetParName(8, "Gamma 2"); } histo->SetLineWidth(2); histo->SetMarkerStyle(20); histo->SetMarkerSize(1.5); histo->SetMarkerColor(kRed); histo->SetLineColor(kBlack); histo->GetXaxis()->SetTitle("Wavelength (#AA)"); histo->GetXaxis()->CenterTitle(); histo->GetXaxis()->SetTitleSize(0.045); histo->GetXaxis()->SetTitleOffset(1.00); histo->GetXaxis()->SetLabelOffset(0.010); histo->GetXaxis()->SetLabelSize(0.045); histo->GetYaxis()->SetTitle("Photon count"); histo->GetYaxis()->CenterTitle(); histo->GetYaxis()->SetTitleSize(0.050); histo->GetYaxis()->SetTitleOffset(0.95); histo->GetYaxis()->SetLabelSize(0.045); gStyle->SetTitleSize(0.070, "t"); if(peak2 == 0.) histo->SetTitle(name + TString::Format(" %4.2f #AA", f->GetParameter(2))); else histo->SetTitle(name + TString::Format(" %4.2f / %4.2f #AA", f->GetParameter(2), f->GetParameter(6))); //histo->SetTitle("Sodium 5890.522 / 5890.567 #AA"); cout << shift << endl; f->SetLineColor(kBlue); f->SetLineWidth(4); cout << "Fitting " << name << endl; histo->Fit(f, "ME"); return histo; }
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; }
void produceTF() { gROOT->SetBatch(); setTDRStyle(); TChain ch("trGEN"); ch.Add("runTEST_MERGED/ST_FCNC-TH_Tleptonic_HTobb_eta_hut-MadGraph5-pythia8/data.root"); ch.Add("runTEST_MERGED/ST_FCNC-TH_Tleptonic_HTobb_eta_hct-MadGraph5-pythia8/data.root"); float dMetPx, dMetPy; float dTopLepBJetPx, dTopLepBJetPy, dTopLepBJetPz, dTopLepBJetE; float dHiggsBJet1Px, dHiggsBJet1Py, dHiggsBJet1Pz, dHiggsBJet1E; float dHiggsBJet2Px, dHiggsBJet2Py, dHiggsBJet2Pz, dHiggsBJet2E; float dElecPx, dElecPy, dElecPz, dElecE; float dMuonPx, dMuonPy, dMuonPz, dMuonE; float TopLepWM, TopLepRecM, TopHadRecM, HiggsRecM; ch.SetBranchAddress("dMetPx",&dMetPx); ch.SetBranchAddress("dMetPy",&dMetPy); ch.SetBranchAddress("dTopLepBJetPx",&dTopLepBJetPx); ch.SetBranchAddress("dTopLepBJetPy",&dTopLepBJetPy); ch.SetBranchAddress("dTopLepBJetPz",&dTopLepBJetPz); ch.SetBranchAddress("dTopLepBJetE",&dTopLepBJetE); ch.SetBranchAddress("dHiggsBJet1Px",&dHiggsBJet1Px); ch.SetBranchAddress("dHiggsBJet1Py",&dHiggsBJet1Py); ch.SetBranchAddress("dHiggsBJet1Pz",&dHiggsBJet1Pz); ch.SetBranchAddress("dHiggsBJet1E",&dHiggsBJet1E); ch.SetBranchAddress("dHiggsBJet2Px",&dHiggsBJet2Px); ch.SetBranchAddress("dHiggsBJet2Py",&dHiggsBJet2Py); ch.SetBranchAddress("dHiggsBJet2Pz",&dHiggsBJet2Pz); ch.SetBranchAddress("dHiggsBJet2E",&dHiggsBJet2E); ch.SetBranchAddress("dElecPx",&dElecPx); ch.SetBranchAddress("dElecPy",&dElecPy); ch.SetBranchAddress("dElecPz",&dElecPz); ch.SetBranchAddress("dElecE",&dElecE); ch.SetBranchAddress("dMuonPx",&dMuonPx); ch.SetBranchAddress("dMuonPy",&dMuonPy); ch.SetBranchAddress("dMuonPz",&dMuonPz); ch.SetBranchAddress("dMuonE",&dMuonE); ch.SetBranchAddress("TopLepWM",&TopLepWM); ch.SetBranchAddress("TopLepRecM",&TopLepRecM); ch.SetBranchAddress("HiggsRecM",&HiggsRecM); int nHist = 0; TH1D *h[1000]; std::string hName[1000]; std::string hLab[1000]; TFile *fOut = new TFile("pdf.root","RECREATE"); h[nHist] = new TH1D("h_TopLepRecM","h_TopLepRecM",100,80.,260.); h[nHist]->Sumw2(); hName[nHist] = "TopLepRecM"; hLab[nHist] = "m(t) [GeV]"; nHist++; h[nHist] = new TH1D("h_TopLepWM","h_TopLepWM",100,60.,100.); h[nHist]->Sumw2(); hName[nHist] = "TopLepWM"; hLab[nHist] = "m(W) [GeV]"; nHist++; h[nHist] = new TH1D("h_HiggsRecM","h_HiggsRecM",100,20.,220.); h[nHist]->Sumw2(); hName[nHist] = "HiggsRecM"; hLab[nHist] = "m(H) [GeV]"; nHist++; h[nHist] = new TH1D("h_dMetPx","h_dMetPx",100,-140.,140.); h[nHist]->Sumw2(); hName[nHist] = "dMetPx"; hLab[nHist] = "MetPx_{gen} - MetPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMetPy","h_dMetPy",100,-140.,140.); h[nHist]->Sumw2(); hName[nHist] = "dMetPy"; hLab[nHist] = "MetPy_{gen} - MetPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPx","h_dBJetPx",100,-60.,60.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPx"; hLab[nHist] = "BJetPx_{gen} - BJetPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPy","h_dBJetPy",100,-60.,60.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPy"; hLab[nHist] = "BJetPy_{gen} - BJetPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPz","h_dBJetPz",100,-80.,80.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPz"; hLab[nHist] = "BJetPz_{gen} - BJetPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetE","h_dBJetE",100,-300.,120.); h[nHist]->Sumw2(); hName[nHist] = "dBJetE"; hLab[nHist] = "BJetE_{gen} - BJetE_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPx","h_dElecPx",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dElecPx"; hLab[nHist] = "ElecPx_{gen} - ElecPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPy","h_dElecPy",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dElecPy"; hLab[nHist] = "ElecPy_{gen} - ElecPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPz","h_dElecPz",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dElecPz"; hLab[nHist] = "ElecPz_{gen} - ElecPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecE","h_dElecE",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dElecE"; hLab[nHist] = "ElecE_{gen} - ElecE_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPx","h_dMuonPx",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPx"; hLab[nHist] = "MuonPx_{gen} - MuonPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPy","h_dMuonPy",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPy"; hLab[nHist] = "MuonPy_{gen} - MuonPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPz","h_dMuonPz",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPz"; hLab[nHist] = "MuonPz_{gen} - MuonPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonE","h_dMuonE",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dMuonE"; hLab[nHist] = "MuonE_{gen} - MuonE_{reco} [GeV]"; nHist++; int nev = ch.GetEntries(); TRandom3 *rnd = new TRandom3(); for(int i=0;i<nev;i++) { ch.GetEntry(i); for(int ih=0;ih<nHist;ih++) { if( hName[ih] == "TopLepRecM" ) h[ih]->Fill(TopLepRecM); else if( hName[ih] == "TopLepWM" ) h[ih]->Fill(TopLepWM); else if( hName[ih] == "HiggsRecM" ) h[ih]->Fill(HiggsRecM); else if( hName[ih] == "dMetPx" ) h[ih]->Fill(dMetPx); else if( hName[ih] == "dMetPy" ) h[ih]->Fill(dMetPy); else if( hName[ih] == "dBJetPx" ) {h[ih]->Fill(dHiggsBJet1Px);h[ih]->Fill(dHiggsBJet2Px);h[ih]->Fill(dTopLepBJetPx);} else if( hName[ih] == "dBJetPy" ) {h[ih]->Fill(dHiggsBJet1Py);h[ih]->Fill(dHiggsBJet2Py);h[ih]->Fill(dTopLepBJetPy);} else if( hName[ih] == "dBJetPz" ) {h[ih]->Fill(dHiggsBJet1Pz);h[ih]->Fill(dHiggsBJet2Pz);h[ih]->Fill(dTopLepBJetPz);} else if( hName[ih] == "dBJetE" ) {h[ih]->Fill(dHiggsBJet1E);h[ih]->Fill(dHiggsBJet2E);h[ih]->Fill(dTopLepBJetE);} else if( hName[ih] == "dElecPx" ) {h[ih]->Fill(dElecPx);} else if( hName[ih] == "dElecPy" ) {h[ih]->Fill(dElecPy);} else if( hName[ih] == "dElecPz" ) {h[ih]->Fill(dElecPz);} else if( hName[ih] == "dElecE" ) {h[ih]->Fill(dElecE);} else if( hName[ih] == "dMuonPx" ) {h[ih]->Fill(dMuonPx);} else if( hName[ih] == "dMuonPy" ) {h[ih]->Fill(dMuonPy);} else if( hName[ih] == "dMuonPz" ) {h[ih]->Fill(dMuonPz);} else if( hName[ih] == "dMuonE" ) {h[ih]->Fill(dMuonE);} } } delete rnd; // Plots TCanvas *c1 = new TCanvas(); c1->Draw(); c1->cd(); TPad *c1_1; gStyle->SetHistTopMargin(0); for(int i=0;i<nHist;i++) { // addbin(h[i]); h[i]->Scale(1./h[i]->Integral()); h[i]->Scale(1./h[i]->GetMaximum()); h[i]->SetLineWidth(2); h[i]->SetLineColor(kRed); h[i]->SetMarkerColor(kRed); h[i]->SetMarkerStyle(20); h[i]->Draw("hist e1"); h[i]->GetXaxis()->SetTitle(hLab[i].c_str()); // h[i]->GetYaxis()->SetTitle("Normalized to unity"); float max = h[i]->GetMaximum(); h[i]->SetMaximum(1.2*max); if( hName[i] == "TopLepWM" || hName[i] == "TopLepM" ) { std::string funcName = hName[i]+"_Fit"; TF1 *func = new TF1(funcName.c_str(),BW,h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins()),3); double mean = 80.4; if( hName[i] == "TopLepM" ) mean = 173.0; double sigma = 2.0; if( hName[i] == "TopLepM" ) sigma = 2.0; func->SetParameter(0,mean); func->SetParName(0,"mean"); func->SetParameter(1,sigma); func->SetParName(1,"sigma"); func->SetParameter(2,1.0); func->SetParName(2,"constant"); func->FixParameter(2,1.); h[i]->Fit(funcName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->Write(); std::string funcGausName = hName[i]+"_Gaus"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"gaus(0)",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); funcGaus->Write(); } if( hName[i] == "dMetPx" || hName[i] == "dMetPy" ) { double mean = 0.; double sigma = 50.; std::string funcGausName = hName[i]+"_Gaus"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); funcGaus->SetParameter(3,0.5); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dBJetPx" || hName[i] == "dBJetPy" || hName[i] == "dBJetPz" || hName[i] == "dBJetE" ) { double mean = 0.; double sigma = 20.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[12]*(gaus(0)+gaus(3)+gaus(6)+gaus(9))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(12,1.0); funcGaus->SetParameter(0,1.0); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(0,0.6); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(0,0.6); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(3,0.15); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(3,0.3); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(5,sigma*4); if( hName[i] == "dBJetPy" ) funcGaus->SetParameter(3,0.2); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(8,sigma/3.); funcGaus->SetParameter(9,0.5); funcGaus->SetParameter(10,mean); funcGaus->SetParameter(11,sigma); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); if( hName[i] == "dBJetE" ) { c1->Update(); TPaveStats *st = (TPaveStats*)h[i]->FindObject("stats"); st->SetX1NDC(0.20); st->SetX2NDC(0.47); } fit->Draw("same"); fit->SetParameter(12,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dElecPx" || hName[i] == "dElecPy" || hName[i] == "dElecPz" || hName[i] == "dElecE" ) { double mean = 0.; double sigma = 1.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dElecPz" ) funcGaus->SetParameter(0,0.8); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dElecPz" ) funcGaus->SetParameter(3,0.15); if( hName[i] == "dElecE" ) funcGaus->SetParameter(3,0.1); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dMuonPx" || hName[i] == "dMuonPy" || hName[i] == "dMuonPz" || hName[i] == "dMuonE" ) { double mean = 0.; double sigma = 1.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dMuonPz" ) funcGaus->SetParameter(0,0.8); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dMuonPz" ) funcGaus->SetParameter(3,0.2); if( hName[i] == "dMuonE" ) funcGaus->SetParameter(3,0.1); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "HiggsRecM" || hName[i] == "TopLepRecM" ) { double mean = 125.; double sigma = 10.; if( hName[i] == "TopLepRecM" ) { mean = 170; sigma = 20; } std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] != "TopLepRecM" ) funcGaus->FixParameter(0,0.7); funcGaus->SetParameter(3,0.3); if( hName[i] == "TopLepRecM" ) funcGaus->SetParameter(3,0.7); if( hName[i] == "TopLepRecM" ) funcGaus->SetParameter(4,150); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } std::string figName = "pics/"+hName[i]+".eps"; c1->Print(figName.c_str()); c1->Clear(); } fOut->Write(); fOut->Close(); gApplication->Terminate(); }
void calibration(){ Double_t wavelength[10], marker[10], wavelengthError[10], markerError[10]; wavelength[0] = 3131.548; marker[0] = 3133.78; wavelength[1] = 3131.839; marker[1] = 3134.07; wavelength[2] = 3650.153; marker[2] = 3649.38; wavelength[3] = 4046.563; marker[3] = 4043.15; wavelength[4] = 4358.328; marker[4] = 4352.62; wavelength[5] = 5460.735; marker[5] = 5445.24; wavelength[6] = 5769.598; marker[6] = 5751.11; wavelength[7] = 5790.663; marker[7] = 5771.92; // wavelengthError[0] = 0.0068; markerError[0] = 5.80457e-2; // wavelengthError[1] = 0.0068; markerError[1] = 4.18374e-2; // wavelengthError[2] = 0.0068; markerError[2] = 3.65332e-2; // wavelengthError[3] = 0.0068; markerError[3] = 4.64119e-2; // wavelengthError[4] = 0.0068; markerError[4] = 2.41694e-2; // wavelengthError[5] = 0.0068; markerError[5] = 2.45160e-2; // wavelengthError[6] = 0.0068; markerError[6] = 3.25336e-2; // wavelengthError[7] = 0.0068; markerError[7] = 3.44601e-2; // wavelengthError[0] = 0.0068; markerError[0] = 5.72027e-2; // wavelengthError[1] = 0.0068; markerError[1] = 4.14216e-2; // wavelengthError[2] = 0.0068; markerError[2] = 3.68554e-2; // wavelengthError[3] = 0.0068; markerError[3] = 5.18892e-2; // wavelengthError[4] = 0.0068; markerError[4] = 2.84812e-2; // wavelengthError[5] = 0.0068; markerError[5] = 2.64957e-2; // wavelengthError[6] = 0.0068; markerError[6] = 3.22631e-2; // wavelengthError[7] = 0.0068; markerError[7] = 4.06117e-2; wavelengthError[0] = 0.0068; markerError[0] = 5.72027e-2+0.000945915; wavelengthError[1] = 0.0068; markerError[1] = 4.14216e-2+0.000622423; wavelengthError[2] = 0.0068; markerError[2] = 3.68554e-2+0.000184086; wavelengthError[3] = 0.0068; markerError[3] = 5.18892e-2+0.000365154; wavelengthError[4] = 0.0068; markerError[4] = 2.84812e-2+0.000200005; wavelengthError[5] = 0.0068; markerError[5] = 2.64957e-2+0.000222945; wavelengthError[6] = 0.0068; markerError[6] = 3.22631e-2+0.000696721; wavelengthError[7] = 0.0068; markerError[7] = 4.06117e-2+0.016829400; // From fits // wavelength[0] = 3650.153; marker[0] = 3649.60; // wavelength[1] = 4046.563; marker[1] = 4043.29; // wavelength[2] = 4358.328; marker[2] = 4352.77; // wavelength[3] = 5460.735; marker[3] = 5445.41; // wavelength[4] = 5769.598; marker[4] = 5751.18; // wavelength[5] = 5790.663; marker[5] = 5771.98; TGraph *graph = new TGraph(8, marker, wavelength); TGraphErrors *graphErrors = new TGraphErrors(8, marker, wavelength, markerError, wavelengthError); TF1 *f = new TF1("CalibFit", "[0]+[1]*x+[2]*x*x+[3]*x*x*x"); f->SetParameter(0, 1.98759); f->SetParameter(1, 1.00606); f->SetParameter(2, -2.20401e-06); f->SetParameter(3, 9.30838e-11); f->SetParName(0, "a"); f->SetParName(1, "b"); f->SetParName(2, "c"); f->SetParName(3, "d"); //graph->Fit(f, "FME"); graphErrors->Fit(f, "FE"); TCanvas *c1 = new TCanvas("Calibration", "Calibration", 1600, 900); gStyle->SetOptStat(2210); gStyle->SetOptFit(1111); graphErrors->SetMarkerSize(2.0); graphErrors->SetTitle("Mercury calibration"); graphErrors->SetMarkerColor(4); graphErrors->SetMarkerStyle(21); graphErrors->GetXaxis()->SetTitle("Measured wavelength"); graphErrors->GetXaxis()->CenterTitle(); graphErrors->GetXaxis()->SetTitleSize(0.045); graphErrors->GetXaxis()->SetTitleOffset(1.00); graphErrors->GetXaxis()->SetLabelOffset(0.010); graphErrors->GetXaxis()->SetLabelSize(0.045); graphErrors->GetYaxis()->SetTitle("True wavelength"); graphErrors->GetYaxis()->CenterTitle(); graphErrors->GetYaxis()->SetTitleSize(0.050); graphErrors->GetYaxis()->SetTitleOffset(0.95); graphErrors->GetYaxis()->SetLabelSize(0.045); gStyle->SetTitleSize(0.070, "t"); graphErrors->Draw("ALP"); c1->SaveAs("Plot_Calibration.png"); calF = new TF1("Calibration", "[0]+[1]*x+[2]*x*x+[3]*x*x*x"); calSigF = new TF1("Calibration plus sigma", "[0]+[1]*x+[2]*x*x+[3]*x*x*x"); // calF->FixParameter(0, f->GetParameter(0)); // calF->FixParameter(1, f->GetParameter(1)); // calF->FixParameter(2, f->GetParameter(2)); // calF->FixParameter(3, f->GetParameter(3)); // calSigF->FixParameter(0, f->GetParameter(0) + f->GetParError(0)); // calSigF->FixParameter(1, f->GetParameter(1) + f->GetParError(1)); // calSigF->FixParameter(2, f->GetParameter(2) + f->GetParError(2)); // calSigF->FixParameter(3, f->GetParameter(3) + f->GetParError(3)); calF->FixParameter(0, -1.84462); calF->FixParameter(1, 9.93825e-01); calF->FixParameter(2, 2.22390e-06); calF->FixParameter(3, -9.29431e-11); calSigF->FixParameter(0, -1.84462 + 8.25177e-02); calSigF->FixParameter(1, 9.93825e-01 + 2.84972e-05); calSigF->FixParameter(2, 2.22390e-06 + 7.45643e-09); calSigF->FixParameter(3, -9.29431e-11 + 1.01904e-12); cout << "Par error " << f->GetParError(2) << endl; cout << "error 5000 " << getWavelengthError(5000, 0); }
void updateHIN11010(int etPho = 60, int etJet = 30, bool scaleByR=true, bool drawMC=true, int prodDate=20131021) { bool mcOnly=false; int percentBin[5] = {0,10,30,50,100}; TH1D* hxgj[5][10]; //[data kind] [ centrality] TH1D* hxgjpp[20]; TFile *fSum1 = new TFile(Form("histOutputFiles60GeVInclusive/HisOutput_Photonv7_v29_akPu3PF_InclPtRatio_gamma%djet%ddphiSig2749_Isol0_Norm1.root",etPho,etJet)); for ( int icent=0; icent<=3 ; icent++) { hxgj[khimc][icent] = (TH1D*)fSum1->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khimc,icent)); hxgj[khidata][icent] = (TH1D*)fSum1->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khidata,icent)); } hxgjpp[kppdata] = (TH1D*)fSum1->Get("dataSrc2_reco1_cent0SubtractedExtrapExtrapNorm"); TFile *fSum2 = new TFile(Form("histOutputFiles60GeVInclusive/HisOutput_Photonv7_v29_akPu3PF_InclPtRatio_gamma%djet%ddphiSig2749_Isol0_Norm2.root",etPho,etJet)); TGraphAsymmErrors* mxhimc = (TGraphAsymmErrors*)fSum2->Get("dataSrc0_reco1_x_Summary_0"); TGraphAsymmErrors* mxhidata = (TGraphAsymmErrors*)fSum2->Get("dataSrc1_reco1_x_Summary_0"); // TGraphAsymmErrors* mxppdata = (TGraphAsymmErrors*)fSum2->Get("dataSrc2_reco1_x_Summary_0"); TGraphAsymmErrors* mxppdata; TGraphAsymmErrors* mxppmc = (TGraphAsymmErrors*)fSum2->Get("dataSrc10_reco1_x_Summary_0"); TGraphAsymmErrors* rxhimc = (TGraphAsymmErrors*)fSum2->Get("dataSrc0_reco1_R_Summary_0"); TGraphAsymmErrors* rxhidata = (TGraphAsymmErrors*)fSum2->Get("dataSrc1_reco1_R_Summary_0"); TGraphAsymmErrors* rxppdata = (TGraphAsymmErrors*)fSum2->Get("dataSrc2_reco1_R_Summary_0"); TGraphAsymmErrors* rxppmc = (TGraphAsymmErrors*)fSum2->Get("dataSrc10_reco1_R_Summary_0"); TFile *fSum3 = new TFile(Form("histOutputFiles60GeVInclusive/HisOutput_Photonv7_v29_akPu3PF_InclDeltaPhi_gamma%djet%ddphiSig628_subJ1SS1_Isol0_Norm1.root",etPho,etJet)); TFile *fSum4 = new TFile("histOutputFiles60GeVInclusive/HisSummary_Photonv7_v29_akPu3PF_InclDeltaPhi_gamma60jet30dphiSig628_subJ1SS1_Isol0_Norm1.root"); TGraphAsymmErrors* dphihimc = (TGraphAsymmErrors*)fSum4->Get("dataSrc0_reco1_dphi_Summary"); TGraphAsymmErrors* dphihidata = (TGraphAsymmErrors*)fSum4->Get("dataSrc1_reco1_dphi_Summary"); TGraphAsymmErrors* dphippdata = (TGraphAsymmErrors*)fSum4->Get("dataSrc2_reco1_dphi_Summary"); TGraphAsymmErrors* dphippmc = (TGraphAsymmErrors*)fSum4->Get("dataSrc10_reco1_dphi_Summary"); // new dphihidata points // double sysDphi[4] = {0.032,0.03,0.045,0.077}; //0.109940, 0.046998, 0.034206,0.142664}; double sysDphipp[1] = {sysDphi[3]}; double sysR[4] = {0.045,0.039,0.041,0.037}; //0.017232,0.012847,0.011691,0.012724}; double sysRpp[1] = {sysR[3]}; double sysMx[4] = { 0.053,0.048,0.051,0.032}; double sysMxpp[1] = {0.009}; double corrSysMx = 0.028; TH1D* hdphi[5][5]; //[data kind] [ centrality] TH1D* hdphipp[20]; for ( int icent=0; icent<=3 ; icent++) { hdphi[khimc][icent] = (TH1D*)fSum3->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khimc,icent)); hdphi[khidata][icent] = (TH1D*)fSum3->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khidata,icent)); } hdphipp[kppdata] = (TH1D*)fSum3->Get("dataSrc2_reco1_cent0SubtractedExtrapExtrapNorm"); // 2013 pp data!!!!!! TFile* pp13 = new TFile(Form("ffFilesPP60GeVInclusive/photonTrackCorr_ppDATA_output_photonPtThr60_to_9999_jetPtThr30_%d.root", prodDate)); // TFile* pp13 = new TFile("ffFilesPP60GeVInclusive/oldSmearing.root"); hdphi[kppdata13][1] = (TH1D*)pp13->Get("jetDphi_icent10010_final"); hxgj[kppdata13][1] = (TH1D*)pp13->Get("xjg_icent10010_final"); hdphi[kppdata13][2] = (TH1D*)pp13->Get("jetDphi_icent11030_final"); hxgj[kppdata13][2] = (TH1D*)pp13->Get("xjg_icent11030_final"); hdphi[kppdata13][3] = (TH1D*)pp13->Get("jetDphi_icent13050_final"); hxgj[kppdata13][3] = (TH1D*)pp13->Get("xjg_icent13050_final"); hdphi[kppdata13][4] = (TH1D*)pp13->Get("jetDphi_icent15099_final"); hxgj[kppdata13][4] = (TH1D*)pp13->Get("xjg_icent15099_final"); hdphi[kppdata13][5] = (TH1D*)pp13->Get("jetDphi_icent7_final"); hxgj[kppdata13][5] = (TH1D*)pp13->Get("xjg_icent7_final"); for ( int icent = 1 ; icent<=5 ; icent++) { hdphi[kppdata13][icent]->Scale(1./hdphi[kppdata13][icent]->Integral()); for ( int i = 1 ; i<=5 ; i++) { hdphi[kppdata13][icent]->SetBinContent(i,-1e4); } // hxgj[kppdata13][icent]->Rebin(10); // Now the bins are already rebined from photonTrackCorr_ppDATA_output_photonPtThr60_to_9999_jetPtThr30_20131021.root hxgj[kppdata13][icent]->Scale(1./hxgj[kppdata13][icent]->Integral("width")); } TH1D* hPtPP2013[10]; hPtPP2013[1] = (TH1D*)pp13->Get("jetPt_icent10010_final"); hPtPP2013[2] = (TH1D*)pp13->Get("jetPt_icent11030_final"); hPtPP2013[3] = (TH1D*)pp13->Get("jetPt_icent13050_final"); hPtPP2013[4] = (TH1D*)pp13->Get("jetPt_icent15099_final"); hPtPP2013[5] = (TH1D*)pp13->Get("jetPt_icent7_final"); TH1D* hRpp2013[10]; hRpp2013[1] = new TH1D("hrpp2013_icent1","",1, 359.1-10, 359.1+10); hRpp2013[2] = new TH1D("hrpp2013_icent2","",1, 235.6-10, 235.6+10); hRpp2013[3] = new TH1D("hrpp2013_icent3","",1, 116.4-10, 116.4+10); hRpp2013[4] = new TH1D("hrpp2013_icent4","",1, 43.6-10, 43.6 +10); hRpp2013[5] = new TH1D("hrpp2013_icent5","",1, -8, 18 ); for ( int icent=1 ; icent<=5; icent++) { double temprPP13err; double temprPP13 = hPtPP2013[icent]->IntegralAndError(1,hPtPP2013[icent]->GetNbinsX(),temprPP13err,"width"); hRpp2013[icent]->SetBinContent(1,temprPP13); hRpp2013[icent]->SetBinError(1,temprPP13err); handsomeTH1(hRpp2013[icent],1); hRpp2013[icent]->SetMarkerStyle(21); } TH1D* hMXpp2013[10]; hMXpp2013[1] = new TH1D("hmxpp2013_icent1","",1, 359.1-10, 359.1+10); hMXpp2013[2] = new TH1D("hmxpp2013_icent2","",1, 235.6-10, 235.6+10); hMXpp2013[3] = new TH1D("hmxpp2013_icent3","",1, 116.4-10, 116.4+10); hMXpp2013[4] = new TH1D("hmxpp2013_icent4","",1, 43.6-10, 43.6 +10); hMXpp2013[5] = new TH1D("hmxpp2013_icent5","",1, -8, 18); for ( int icent=1 ; icent<=5; icent++) { hMXpp2013[icent]->SetBinContent(1,hxgj[kppdata13][icent]->GetMean()); hMXpp2013[icent]->SetBinError(1,hxgj[kppdata13][icent]->GetMeanError()); handsomeTH1(hMXpp2013[icent],1); hMXpp2013[icent]->SetMarkerStyle(21); } TFile* fPPsys = new TFile("ffFilesPP60GeVInclusive/relativeSys_merged_pp60GeV.root"); TH1D* hdphiWidth = (TH1D*)fPPsys->Get("dphiWidth_uncertainty_merged"); TH1D* hDphiPPUnc = new TH1D("hdphippunc","",1,0,1); hDphiPPUnc->SetBinContent(1, hdphiWidth->GetBinContent(1) ); TH1D* ppSysX[4]; ppSysX[0] = (TH1D*)fPPsys->Get("dNdXjg_uncertainty_merged"); ppSysX[1] = (TH1D*)ppSysX[0]->Clone("ppSysx1"); ppSysX[2] = (TH1D*)ppSysX[0]->Clone("ppSysx2"); ppSysX[3] = (TH1D*)ppSysX[0]->Clone("ppSysx3"); TH1D* meanXpp13Sys = (TH1D*)fPPsys->Get("meanXjg_uncertainty_merged"); float ppSysMx60 = meanXpp13Sys->GetBinContent(1); // UPDATED on Oct 22nd TH1D* ppSysMx = new TH1D("ppSysMx","",1,0,1); ppSysMx->SetBinContent(1,ppSysMx60); TH1D* meanRpp13Sys = (TH1D*)fPPsys->Get("meanRjg_uncertainty_merged"); float ppSysR60 = meanRpp13Sys->GetBinContent(1); // UPDATED on Oct 22nd TH1D* ppSysR = new TH1D("ppSysR","",1,0,1); ppSysR->SetBinContent(1,ppSysR60); // xjg distributions TCanvas *c1 = new TCanvas("c1","",1100,330); makeMultiPanelCanvas(c1,4,1,0.0,0.0,0.24,0.15,0.075); c1->cd(0); drawCMSppPbPb(0.1,0.95); //c1->Divide(4,1,0.0,0.0); for ( int icent=0; icent<=3 ; icent++) { c1->cd( 4 - icent); //hxgj[khimc][icent]->SetAxisRange(-.2,2.5,"Y"); hxgj[khimc][icent]->SetAxisRange(0,2.5,"Y"); hxgj[khimc][icent]->SetNdivisions(505); // hxgj[khimc][icent]->SetTitle(";x_{J#gamma} = p^{Jet}_{T}/p^{#gamma}_{T}; #frac{1}{N_{J#gamma}} #frac{dN_{J#gamma}}{dx_{J#gamma}}"); hxgj[khimc][icent]->SetTitle(";x_{J#gamma}; #frac{1}{N_{J#gamma}} #frac{dN_{J#gamma}}{dx_{J#gamma}}"); handsomeTH1(hxgj[khimc][icent]); fixedFontHist(hxgj[khimc][icent],1,1.35); mcStyle2(hxgj[khimc][icent]); handsomeTH1(hxgj[khidata][icent],2); hxgj[khimc][icent]->GetYaxis()->SetTitleOffset(1.5); TH1D * htemp41 = (TH1D*)hxgj[khimc][icent]->Clone(Form("htemp41_%d",icent)); for ( int i=0 ; i<=20 ; i++) { htemp41->SetBinContent(i,0); htemp41->SetBinError(i,0); } if (scaleByR) { htemp41->SetAxisRange(0,2,"Y"); htemp41->SetYTitle("#frac{1}{N_{#gamma}} #frac{dN_{J#gamma}}{dx_{J#gamma}}"); } htemp41->DrawCopy("hist"); if (scaleByR) { hxgj[kppdata13][icent+1]->Scale(hRpp2013[icent+1]->GetBinContent(1)); std::cout <<" Scaled by pp R :" << hRpp2013[icent+1]->GetBinContent(1) << std::endl; double x,y; rxhidata->GetPoint(icent, x,y); hxgj[khidata][icent]->Scale(y); std::cout << " scaled by PbPb R: " << y << std::endl; rxhimc->GetPoint(icent, x,y); hxgj[khimc][icent]->Scale(y); std::cout << " scaled by PbPb R: " << y << std::endl; } if(drawMC) hxgj[khimc][icent]->DrawCopy("hist same"); if ( !mcOnly ) drawXSys(icent,hxgj[khidata][icent]); // if ( icent==3){ } handsomeTH1(hxgj[kppdata13][icent+1]); hxgj[kppdata13][icent+1]->SetMarkerStyle(21); drawSys(hxgj[kppdata13][icent+1],ppSysX[icent],kGreen,3001); hxgj[kppdata13][icent+1]->Draw("same "); if ( !mcOnly ) hxgj[khidata][icent]->Draw("same"); //onSun(0,0,2,0); // if ( icent == 2) { // TLegend *leg0 = new TLegend(0.2796373,0.7545885,0.9742202,0.9937661,NULL,"brNDC"); // easyLeg(leg0,""); // // if ( !mcOnly ) leg0->AddEntry(hxgj[khidata][icent],"PbPb Data","p"); // leg0->AddEntry(hxgj[khimc][icent],"PYTHIA + HYDJET","f"); // leg0->AddEntry(hxgjpp[kppdata],"",""); // leg0->Draw(); // } if ( icent == 3) { TLegend *leg0 = new TLegend(0.2916647,0.7045885,0.9862476,0.9869226,NULL,"brNDC"); easyLeg(leg0); leg0->AddEntry(hxgj[khidata][icent],"PbPb Data","p"); if ( !mcOnly ) leg0->AddEntry(hxgj[kppdata13][icent+1],"Smeared pp reference","p"); // leg0->AddEntry(hxgj[khidata][icent],"",""); if(drawMC) leg0->AddEntry(hxgj[khimc][icent],"PbPb PYTHIA + HYDJET","f"); leg0->Draw(); //drawText("#sqrt{s_{NN}}=2.76 TeV ",0.65,0.74,0,15); } if ( icent == 2) { drawText(Form("p^{#gamma}_{T} > %d GeV/c |#eta^{#gamma}| < 1.44",etPho),0.2,0.85,0,15); drawText(Form("p^{Jet}_{T} > %d GeV/c |#eta^{Jet}| < 1.6",etJet),0.2,0.77,0,15); drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.2,0.69,0,15); } if ( icent == 0 ) { // drawText("CMS",0.8,0.9,1); // drawText("pp #int L dt = 231 nb^{-1}",0.4,0.68,1,15); } if ( icent == 3) drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.72,0.5,0,15); else drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.67,0.5,0,15); /* if ( icent == 3) drawText("(a)",0.275,0.8,1); if ( icent == 2) drawText("(b)",0.05,0.8,1); if ( icent == 1) drawText("(c)",0.05,0.8,1); if ( icent == 0) drawText("(d)",0.05,0.8,1); */ gPad->RedrawAxis(); } c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.pdf"); //c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.png"); //c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.gif"); //c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.C"); // TCanvas *c1all = new TCanvas("c1all","",500,500); // for ( int icent=0;icent<4;icent++){ // hxgj[khimc][icent]->SetFillStyle(0); // hxgj[khimc][icent]->SetMarkerSize(1.5); // } // hxgj[khimc][0]->SetMarkerStyle(22); // hxgj[khimc][1]->SetMarkerStyle(26); // hxgj[khimc][2]->SetMarkerStyle(23); // hxgj[khimc][3]->SetMarkerStyle(32); // hxgj[khimc][0]->DrawCopy(""); // hxgj[khimc][1]->DrawCopy(" same"); // hxgj[khimc][2]->DrawCopy(" same"); // hxgj[khimc][3]->DrawCopy(" same"); // jumSun(0,0,2,0); // drawText("PYTHIA+HYDJET",0.2,0.80,0,25); // TLegend *legc1all = new TLegend(0.6149194,0.6716102,0.9435484,0.9555085,NULL,"brNDC"); // easyLeg(legc1all,""); // legc1all->AddEntry(hxgj[khimc][3],"50-100%","p"); // legc1all->AddEntry(hxgj[khimc][2],"30-50%","p"); // legc1all->AddEntry(hxgj[khimc][1],"10-30%","p"); // legc1all->AddEntry(hxgj[khimc][0],"0-10%","p"); // legc1all->Draw(); // dphi distributions TCanvas *c1ppDphi = new TCanvas("c1ppDphi","",500,500); TString fitFunc = "(TMath::Pi()/20.0)*exp(-(TMath::Pi()-x)/[0])/([0]*(1-exp(-TMath::Pi()/[0])))"; float fitxmin=3.1415926*2./3; TF1 *fdphiPP[10]; TH1D* hDphiPP2013[10]; hDphiPP2013[1] = new TH1D("hDphiPP2013_icent1","",1, 359.1-10, 359.1+10); hDphiPP2013[2] = new TH1D("hDphiPP2013_icent2","",1, 235.6-10, 235.6+10); hDphiPP2013[3] = new TH1D("hDphiPP2013_icent3","",1, 116.4-10, 116.4+10); hDphiPP2013[4] = new TH1D("hDphiPP2013_icent4","",1, 43.6-10, 43.6 +10); hDphiPP2013[5] = new TH1D("hDphiPP2013_icent5","",1, -8, 18); for ( int icent=1; icent<=5 ; icent++) { fdphiPP[icent] = new TF1(Form("fdphiPP_icent%d",icent),fitFunc.Data(),2.0*TMath::Pi()/3.0,TMath::Pi()); fdphiPP[icent]->SetParName(0,"width"); fdphiPP[icent]->SetParameter("width",0.3); hdphi[kppdata13][icent]->Fit(Form("fdphiPP_icent%d",icent),"0","",fitxmin,3.1415926); fdphiPP[icent]->SetLineWidth(1); fdphiPP[icent]->SetLineStyle(2); fdphiPP[icent]->SetLineColor(1); hdphi[kppdata13][icent]->SetAxisRange(1.00001e-3,1,"Y"); hdphi[kppdata13][icent]->SetStats(0); hdphi[kppdata13][icent]->Draw(""); hdphi[kppdata13][icent]->SetAxisRange(1.00001e-3,1,"Y"); hdphi[kppdata13][icent]->SetStats(0); fdphiPP[icent]->SetLineWidth(2); fdphiPP[icent]->SetLineStyle(7); fdphiPP[icent]->DrawCopy("same"); gPad->SetLogy(); float dphiWidth13 = fdphiPP[icent]->GetParameter(0) ; float dphiWidth13err = fdphiPP[icent]->GetParError(0); hDphiPP2013[icent]->SetBinContent(1,dphiWidth13); hDphiPP2013[icent]->SetBinError( 1,dphiWidth13err); handsomeTH1(hDphiPP2013[icent],1); hDphiPP2013[icent]->SetMarkerStyle(21); } TCanvas *c1dphi = new TCanvas("c1dphi","",1100,330); makeMultiPanelCanvas(c1dphi,4,1,0.0,0.0,0.24,0.18,0.075); c1dphi->cd(0); drawCMSppPbPb(0.1,0.95); for ( int icent=0; icent<=3 ; icent++) { c1dphi->cd( 4 - icent); hdphi[khimc][icent]->SetAxisRange(1.e-3,1,"Y"); // hdphi[khimc][icent]->SetNdivisions(505); hdphi[khimc][icent]->GetXaxis()->SetNdivisions(3,5,0,kFALSE); hdphi[khimc][icent]->SetTitle(";#Delta#phi_{J#gamma};Pair Fraction"); handsomeTH1(hdphi[khimc][icent]); fixedFontHist(hdphi[khimc][icent],1,1.35); mcStyle2(hdphi[khimc][icent]); handsomeTH1(hdphi[khidata][icent],2); TF1 *fdphi = new TF1("fdphi",fitFunc.Data(),2.0*TMath::Pi()/3.0,TMath::Pi()); fdphi->SetParName(0,"width"); fdphi->SetParameter("width",0.3); hdphi[khimc][icent]->Fit("fdphi","0llm","",fitxmin,3.1415926); fdphi->SetLineWidth(1); fdphi->SetLineStyle(2); fdphi->SetLineColor(kBlue); // float dphiWidth = fdphi->GetParameter("width"); // float dphiWidthErr = fdphi->GetParError(0); // std::cout << " dphiWidth,dphiWidthErr = " << dphiWidth <<" "<< dphiWidthErr << std::endl; hdphi[khimc][icent]->SetAxisRange(1.00001e-3,1,"Y"); hdphi[khimc][icent]->SetStats(0); TH1D* hdphitemp = (TH1D*)hdphi[khimc][icent]->Clone(Form("hdphitemp55_%d",icent)); if(!drawMC) { for ( int i=0;i<=30;i++) { hdphitemp->SetBinContent(i,0); hdphitemp->SetBinError(i,0); } } hdphitemp->Draw("hist"); hdphi[khidata][icent]->SetAxisRange(1.00001e-3,1,"Y"); if (!mcOnly) hdphi[khidata][icent]->Draw("same "); hdphi[khidata][icent]->SetStats(0); fdphi->SetLineWidth(2); fdphi->SetLineStyle(7); if ( mcOnly ) fdphi->DrawCopy("same"); gPad->SetLogy(); handsomeTH1(hdphi[kppdata13][icent+1]); hdphi[kppdata13][icent+1]->SetMarkerStyle(21); hdphi[kppdata13][icent+1]->Draw("same"); if ( icent == 3) { TLegend *leg0 = new TLegend(0.32,0.7,0.9,0.89,NULL,"brNDC"); easyLeg(leg0); if ( !mcOnly ) leg0->AddEntry(hdphi[kppdata13][icent+1],"Smeared pp reference","p"); if ( !mcOnly ) leg0->AddEntry(hdphi[khidata][icent],"PbPb Data","p"); if(drawMC) leg0->AddEntry(hdphi[khimc][icent],"PYTHIA + HYDJET","f"); leg0->Draw(); } if (( !mcOnly ) && ( icent == 2)) { //drawText("#sqrt{s_{NN}}=2.76 TeV ",0.4,0.88,0,15); //drawText("#int L dt = 150 #mub^{-1}",0.4,0.75,0,15); } if ( icent == 1) { drawText(Form("p^{#gamma}_{T} > %d GeV/c |#eta^{#gamma}| < 1.44",etPho),0.15,0.8,0,15); drawText(Form("p^{Jet}_{T} > %d GeV/c |#eta^{Jet}| < 1.6",etJet),0.15,0.7,0,15); } if ( icent == 0 ) { // drawText("CMS",0.8,0.9,1); // drawText("pp #int L dt = 231 nb^{-1}",0.4,0.68,1,15); } if ( icent == 3) drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.313,0.6,0,15); else drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.1,0.6,0,15); if ( icent == 3) drawText("(a)",0.275,0.8,1); if ( icent == 2) drawText("(b)",0.05,0.8,1); if ( icent == 1) drawText("(c)",0.05,0.8,1); if ( icent == 0) drawText("(d)",0.05,0.8,1); double bottomY = 0.0009; double pi = TMath::Pi(); drawPatch(-0.5,bottomY/100,pi+0.5,bottomY); bottomY = 0.0005; drawText("0",0.05,bottomY,0,18,false); drawText("#frac{1}{3}#pi",pi/3-0.05,bottomY,0,18,0); drawText("#frac{2}{3}#pi",2*pi/3-0.05,bottomY,0,18,0); if ( icent==0) drawText("#pi",pi-0.1,bottomY,0,18,0); drawText("#Delta#phi_{J#gamma}",pi/2.-0.1,bottomY-0.0002,0,18,0); } gPad->RedrawAxis(); c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.pdf"); //c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.png"); //c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.gif"); //c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.C"); ////////////////////////////// summary plots TCanvas *c2 = new TCanvas("c2","",350,350); TH1D* hTemp2 = new TH1D("htemp2",";N_{part};<x_{J#gamma}>",100,-20,400); hTemp2->SetNdivisions(505); handsomeTH1(hTemp2,1); handsomeTGraph(mxhidata,2); mxhidata->SetMarkerStyle(20); handsomeTGraph(mxhimc,1); mxhimc->SetMarkerStyle(24); // handsomeTGraph(mxppdata,1); // mxppdata->SetMarkerStyle(21); handsomeTGraph(mxppmc,1); mxppmc->SetMarkerStyle(25); hTemp2->SetAxisRange(0.6,1.1,"Y"); hTemp2->DrawCopy(); // TH1D* hMXpp2013_2 = new TH1D("hmxpp2013_2","",1,-10,370); // hMXpp2013_2->SetBinContent(1,hMXpp2013->GetBinContent(1)); // if ( !mcOnly ) drawSys(hMXpp2013_2,sysMxpp,kGreen,3001); if ( !mcOnly ) drawSys(mxhidata,sysMx,10); // mxppmc->Draw("p"); // if ( !mcOnly ) mxppdata->Draw("p"); if ( !mcOnly ) { hMXpp2013[5]->SetMarkerStyle(20); for ( int icent = 1 ; icent<=5 ; icent++) { drawSys(hMXpp2013[icent],ppSysMx,kGreen,3001); hMXpp2013[icent]->DrawCopy("p same"); } } if(drawMC) mxhimc->Draw("p same"); if ( !mcOnly ) mxhidata->Draw("p same"); hMXpp2013[5]->SetFillStyle(3001); hMXpp2013[5]->SetFillColor(kGreen); hMXpp2013[5]->SetLineColor(0); hDphiPP2013[2]->SetFillStyle(3001); hDphiPP2013[2]->SetFillColor(kGreen); hDphiPP2013[2]->SetLineColor(0); TH1D *dummyHist = new TH1D("dummyHist","",10,0,1); dummyHist->SetFillStyle(1001); dummyHist->SetMarkerColor(kRed); dummyHist->SetFillColor(90); dummyHist->SetLineColor(0); //// sys bar by energy scale /* TBox *b1 = new TBox(400-20,0.85 - corrSysMx ,400, 0.85 + corrSysMx); b1->SetFillColor(1); b1->SetFillStyle(1001); if ( !mcOnly ) b1->Draw(); TBox *b2 = new TBox(400-20+3,0.85 - corrSysMx+ 0.002 ,400-3, 0.85 + corrSysMx- 0.002); b2->SetFillColor(0); b2->SetFillStyle(1001); if ( !mcOnly ) b2->Draw(); */ // drawText("Common uncertainty due to jet ",0.35,0.25,0,15); // drawText("energy scale & photon purity",0.35,0.2,0,15); // drawText("#sqrt{s_{NN}}=2.76 TeV ",0.5,0.85,0,15); // drawText("#int L dt = 150 #mub^{-1}",0.5,0.72,0,15); // drawText("(a)",0.22,0.87,1); drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.7,0.75,0); drawCMSppPbPb(0.1,0.95,12); // drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.5,0.38,0); // drawText("CMS",0.78,0.88,1); TLegend *leg4 = new TLegend(0.1630303,0.6054839,0.7590909,0.8931183,NULL,"brNDC"); easyLeg(leg4,""); // if ( !mcOnly ) leg4->AddEntry(mxppdata,"pp Data 231nb^{-1}","p"); if ( !mcOnly ) leg4->AddEntry(dummyHist,"PbPb Data","fp"); if ( !mcOnly ) leg4->AddEntry(hMXpp2013[5],"pp Data","fp"); if ( !mcOnly ) leg4->AddEntry(hDphiPP2013[2],"Smeared pp reference","fp"); if(drawMC) leg4->AddEntry(mxhimc,"PYTHIA + HYDJET","p"); // leg4->AddEntry(mxppmc,"PYTHIA","p"); // leg4->AddEntry(hSysTemp,"Sys. Uncertainty","f"); leg4->Draw(); gPad->RedrawAxis(); c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.pdf"); //c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.png"); //c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.gif"); //c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.C"); ////////////////////////////// rx TCanvas *c3 = new TCanvas("c3","",350,350); TH1D* hTemp3 = new TH1D("htemp2",";N_{part};R_{J#gamma}",100,-20,400); hTemp3->SetNdivisions(505); handsomeTH1(hTemp3,1); handsomeTGraph(rxhidata,2); rxhidata->SetMarkerStyle(20); handsomeTGraph(rxhimc,1); rxhimc->SetMarkerStyle(24); handsomeTGraph(rxppdata,1); rxppdata->SetMarkerStyle(21); handsomeTGraph(rxppmc,1); rxppmc->SetMarkerStyle(25); hTemp3->SetAxisRange(0.41,1.,"Y"); hTemp3->Draw(); // Ratio // DivideTG(rxppdata,rxppmc); // DivideTG(rxhidata,rxhimc); ////////////////////////////////////////////// // TH1D* hdphi2013_2 = new TH1D("hdphi2013_2","",1,-10,370); // hdphi2013_2->SetBinContent(1,hRpp2013->GetBinContent(1)); // if ( !mcOnly ) drawSys(hdphi2013_2,sysRpp,kGreen,3001); if ( !mcOnly ) drawSys(rxhidata,sysR,10); // if ( !mcOnly ) drawSys(rxppdata,sysRpp,10); // jumSun(-10,1,400,1); if(drawMC) rxhimc->Draw("p"); // rxppmc->Draw("p"); // if ( !mcOnly ) rxppdata->Draw("p"); if ( !mcOnly ) { hRpp2013[5]->SetMarkerStyle(20); for ( int icent =1 ; icent<=5 ; icent++) { drawSys(hRpp2013[icent],ppSysR,kGreen,3001); hRpp2013[icent]->Draw("same"); } } if ( !mcOnly ) rxhidata->Draw("p same"); // drawText(Form("p^{#gamma}_{T} > %d GeV/c",etPho),0.6,0.75,0,15); // drawText(Form("p^{Jet}_{T} > %d GeV/c",etJet),0.6,0.67,0,15); // drawText("CMS",0.78,0.88,1); // drawText("(b)",0.22,0.87,1); drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.7,0.75,0); drawCMSppPbPb(0.1,0.95,12); leg4->Draw(); gPad->RedrawAxis(); c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.pdf"); //c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.png"); //c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.gif"); //c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.C"); TCanvas *c4 = new TCanvas("c4","",350,350); TH1D* hTemp4 = new TH1D("htemp2",";N_{part};#sigma(#Delta#phi_{J#gamma})",100,-20,400); hTemp4->SetNdivisions(505); handsomeTH1(hTemp4,1); handsomeTGraph(dphihidata,2); dphihidata->SetMarkerStyle(20); handsomeTGraph(dphihimc,1); dphihimc->SetMarkerStyle(24); handsomeTGraph(dphippdata,1); dphippdata->SetMarkerStyle(21); handsomeTGraph(dphippmc,1); dphippmc->SetMarkerStyle(25); hTemp4->SetAxisRange(0,.5,"Y"); hTemp4->Draw(); // TH1D* h2013_3 = new TH1D("hdphi2013_3","",1,-10,370); // h2013_3->SetBinContent(1,hDphiPP2013->GetBinContent(1)); // if ( !mcOnly ) drawSys(h2013_3,sysDphipp,kGreen,3001); if ( !mcOnly ) drawSys(dphihidata,sysDphi,10); if(drawMC) dphihimc->Draw("p same"); // dphippmc->Draw("p"); // if ( !mcOnly ) dphippdata->Draw("p"); for ( int icent=1 ; icent<=5 ; icent++){ drawSys(hDphiPP2013[icent], hDphiPPUnc, kGreen,3001); } TH1D* hDphiPP2013Temp = new TH1D("hDphiPP2013Temp","",1,380,400); hDphiPP2013Temp->SetBinContent(1,0.27); hDphiPP2013[5]->SetMarkerStyle(20); for ( int icent=1 ; icent<=5 ; icent++){ hDphiPP2013[icent]->Draw("same"); } if ( !mcOnly ) dphihidata->Draw("p"); // TLegend *legDphi = new TLegend(0.32,0.18,0.93,0.7,NULL,"brNDC"); // easyLeg(legDphi,""); // legDphi->SetTextSize(17); // // drawText("|#Delta#phi_{J#gamma}| > #frac{2}{3}#pi",0.5,0.38,0); // // drawText("Fit : #frac{e^{#frac{|#Delta#phi_{J#gamma}|-#pi}{#sigma}}}{#sigma(1-e^{-#pi/#sigma})}",0.5,0.23,0); // legDphi->Draw(); // // drawText("(a)",0.22,0.87,1); // // drawText("CMS",0.78,0.88,1); TH1D* hSysTemp = new TH1D("hSystemp","",1,0,1); hSysTemp->SetFillColor(newYellow); hSysTemp->SetLineColor(newYellow); leg4->Draw(); drawText(Form("p^{#gamma}_{T} > %d GeV/c |#eta^{#gamma}| < 1.44",etPho),0.25,0.3,0,15); drawText(Form("p^{Jet}_{T} > %d GeV/c |#eta^{Jet}| < 1.6",etJet),0.25,0.2,0,15); drawCMSppPbPb(0.1,0.95,12); gPad->RedrawAxis(); c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.pdf"); //c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.png"); //c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.gif"); //c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.C"); // // print numbers // std::cout << " Summary of Points for PbPb " << std::endl; // PrintGraphAndSys(dphihidata,sysDphi); // PrintGraphAndSys(mxhidata,sysMx); // PrintGraphAndSys(rxhidata,sysR); // std::cout << " Summary of Points for PYTHIA + HYDJET " << std::endl; // PrintGraph(dphihimc); // PrintGraph(mxhimc); // PrintGraph(rxhimc); // std::cout << " Summary of Points for pp " << std::endl; // PrintGraphAndSys(dphippdata[5],sysDphipp); // PrintGraphAndSys(mxppdata[5],sysMxpp); // PrintGraphAndSys(rxppdata[5],sysRpp); /* TCanvas *c5 = new TCanvas("c5","",500,500); hxgj[khidata][0]->SetAxisRange(-.2,2.5,"Y"); hxgj[khidata][0]->SetNdivisions(505); fixedFontHist(hxgj[khidata][0],1,1.35); handsomeTH1(hxgj[khidata][0],2); hxgj[khidata][0]->GetYaxis()->SetTitleOffset(1.5); hxgj[khidata][0]->DrawCopy(""); handsomeTH1(hxgj[kppdata13][5],4); hxgj[kppdata13][5]->Draw("same hist"); onSun(0,0,2,0); */ }
void Sigmoide(TGraphAsymmErrors* Efficiency,TGraphErrors* EfficiencyStat,OutFileRoot& out,std::string name,Reader& read) { double min=999999; double max=-99999; int lLimit=0; int uLimit=0; for (int i = 0; i < Efficiency->GetN(); i++) { double x=0.0; double y=0.0; Efficiency->GetPoint(i, x, y); if(x>max)max=x; if(x<min)min=x; double errorY = Efficiency->GetErrorYlow(i); double errorYlow_stat = EfficiencyStat->GetErrorYlow(i); double errorYhigh_stat = EfficiencyStat->GetErrorYhigh(i); double errorYhigh = sqrt(errorY/2*errorY/2+errorYhigh_stat*errorYhigh_stat); double errorYlow = sqrt(errorY/2*errorY/2 + errorYlow_stat*errorYlow_stat); Efficiency->SetPoint(i, x, y-errorY/2); Efficiency->SetPointEYhigh (i, errorYhigh); Efficiency->SetPointEYlow (i, errorYlow); if (i == 0) lLimit = x; else if (i == Efficiency->GetN()-1) uLimit = x; std::cout<<yellow << "HV = " << x << " eff = " << y-errorY/2 << " errorY = " << errorY/2 << " errorYhigh_stat = " << errorYhigh_stat << " errorYlow_stat = " << errorYlow_stat <<normal<<std::endl; } int color = 2; int marker = 20; TCanvas* c1 = new TCanvas(); c1->SetTitle((name+Efficiency->GetTitle()).c_str()); c1->SetName((name+Efficiency->GetTitle()).c_str()); TH1D* PLOTTER = new TH1D("PLOTTER", "", 1, min, max); PLOTTER->SetStats(0); std::string xLabel = "HV_{eff} (V)"; if (read.getType() == "volEff" || read.getType() == "noisevolEff") { xLabel = "Voltage_{eff} (V)"; } else if (read.getType() == "thrEff" ||read.getType() == "noisethrEff") { xLabel = "Threshod ("+unitthr(read)+")"; } else if (read.getType() == "srcEff" ||read.getType() == "noisesrcEff") { xLabel = "Attenuator"; } else if (read.getType() == "PulEff" ||read.getType() == "noisePulEff") { xLabel = "Pulse (ns)"; } std::string lName = "Sigmoid for RE11 GRPC; " + xLabel + "; Efficiency"; PLOTTER->SetTitle(lName.c_str()); PLOTTER->SetMaximum(1); PLOTTER->SetMinimum(0); PLOTTER->Draw(""); Efficiency->SetMarkerColor(color); Efficiency->SetMarkerStyle(marker); Efficiency->Draw("SAMEPE"); int HVhalf = (lLimit+uLimit)/2; //**************************************************** TF1* sigmoid = new TF1("sigmoid","[0]/(1+exp([1]*([2]-x)))",lLimit,uLimit); sigmoid->SetParName(0,"#epsilon_{max}"); sigmoid->SetParName(1,"#lambda"); sigmoid->SetParName(2,"HV_{50%}"); sigmoid->SetParameter(0,0.98); sigmoid->SetParameter(1,0.01); sigmoid->SetParameter(2,HVhalf); Efficiency->Fit(sigmoid); Efficiency->GetFunction("sigmoid")->SetLineColor(kBlue); double p1 = sigmoid->GetParameter(0); double p2 = sigmoid->GetParameter(1); double p3 = sigmoid->GetParameter(2); TLatex* ltx = new TLatex(); ltx->SetTextSize(0.04); double knee = p3 - log(1/0.95-1)/p2; TLine* lKnee = new TLine(knee, 0, knee, 1); lKnee->SetLineStyle(2); lKnee->Draw(); double WP = knee+150; double add = (uLimit-lLimit)/11.; if (uLimit-knee < 4/11.*(uLimit-lLimit)) add = -add*4; ltx->DrawLatex(knee+add, 0.22, Form("WP = %.f V", WP)); ltx->DrawLatex(knee+add, 0.15, Form("knee = %.f V", knee)); ltx->DrawLatex(knee+add, 0.08, Form("HV(50%) = %.f V", p3)); TLine* plateau = new TLine(lLimit-50, p1, uLimit+50, p1); plateau->SetLineStyle(2); plateau->Draw(); if ((knee - lLimit) < (uLimit-lLimit)*(3/11.)) add = knee + add; else add = lLimit+add; ltx->DrawLatex(add, p1+0.04, Form("plateau = %.2f", p1)); c1->Update(); out.writeObject("Sigmoid",c1); delete c1; delete ltx; delete sigmoid; delete PLOTTER; }
Float_t doCoinc(const char *fileIn="coincCERN_0102n.root",TCanvas *cout=NULL,Float_t &rate,Float_t &rateErr){ // Print settings printf("SETTINGS\nAnalyze output from new Analyzer\n"); printf("Input file = %s\n",fileIn); printf("School distance = %f m, angle = %f deg\n",distance,angle); printf("School orientation: tel1=%f deg, tel2=%f deg\n",phi1Corr,phi2Corr); printf("Max Chi2 = %f\n",maxchisquare); printf("Theta Rel Range = %f - %f deg\n",minthetarel,maxthetarel); printf("Range for N sattellite in each run = (tel1) %f - %f, (tel2) %f - %f \n",minAvSat[0],maxAvSat[0],minAvSat[1],maxAvSat[1]); printf("Min N satellite in a single event = %i\n",satEventThr); Int_t adayMin = (yearRange[0]-2014) * 1000 + monthRange[0]*50 + dayRange[0]; Int_t adayMax = (yearRange[1]-2014) * 1000 + monthRange[1]*50 + dayRange[1]; Float_t nsigPeak=0; Float_t nbackPeak=0; angle *= TMath::DegToRad(); // define some histos TH1F *hDeltaTheta = new TH1F("hDeltaTheta","#Delta#theta below the peak (500 ns);#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhi = new TH1F("hDeltaPhi","#Delta#phi below the peak (500 ns);#Delta#phi (#circ)",200,-360,360); TH1F *hDeltaThetaBack = new TH1F("hDeltaThetaBack","#Delta#theta out of the peak (> 1000 ns) - normalized;#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhiBack = new TH1F("hDeltaPhiBack","#Delta#phi out of the peak (> 1000 ns) - normalized;#Delta#phi (#circ)",200,-360,360); TH1F *hThetaRel = new TH1F("hThetaRel","#theta_{rel} below the peak (500 ns);#theta_{rel} (#circ)",100,0,120); TH1F *hThetaRelBack = new TH1F("hThetaRelBack","#theta_{rel} out of the peak (> 1000 ns) - normalized;#theta_{rel} (#circ)",100,0,120); TH2F *hAngle = new TH2F("hAngle",";#Delta#theta (#circ);#Delta#phi (#circ}",20,-60,60,20,-360,360); TH2F *hAngleBack = new TH2F("hAngleBack",";#Delta#theta (#circ);#Delta#phi (#circ}",20,-60,60,20,-360,360); TProfile *hModulation = new TProfile("hModulation","#theta^{rel} < 10#circ;#phi - #alpha;dist (m)",50,0,360); TProfile *hModulation2 = new TProfile("hModulation2","#theta^{rel} < 10#circ;#phi - #alpha;dist (m)",50,0,360); TProfile *hModulationAv = new TProfile("hModulationAv","#theta^{rel} < 10#circ;#phi - #alpha;dist (m)",50,0,360); TProfile *hModulationAvCorr = new TProfile("hModulationAvCorr","#theta^{rel} < 10#circ;#phi - #alpha;diff (ns)",50,0,360); TH1F *hnsigpeak = new TH1F("hnsigpeak","",50,0,360); TH1F *hnbackpeak = new TH1F("hnbackpeak","",50,0,360); TProfile *hSinTheta = new TProfile("hSinTheta",";#phi - #alpha;sin(#theta)",50,0,360); TProfile *hSinTheta2 = new TProfile("hSinTheta2",";#phi - #alpha;sin(#theta)",50,0,360); TH1F *hRunCut[2]; hRunCut[0] = new TH1F("hRunCut1","Reason for Run Rejection Tel-1;Reason;runs rejected",11,0,11); hRunCut[1] = new TH1F("hRunCut2","Reason for Run Rejection Tel-2;Reason;runs rejected",11,0,11); for(Int_t i=0;i<2;i++){ hRunCut[i]->Fill("DateRange",0); hRunCut[i]->Fill("LowFractionGT",0); hRunCut[i]->Fill("TimeDuration",0); hRunCut[i]->Fill("rateGT",0); hRunCut[i]->Fill("RunNumber",0); hRunCut[i]->Fill("MissingHitFrac",0); hRunCut[i]->Fill("DeadStripBot",0); hRunCut[i]->Fill("DeadStripMid",0); hRunCut[i]->Fill("DeadStripTop",0); hRunCut[i]->Fill("NSatellites",0); hRunCut[i]->Fill("NoGoodWeather",0); } TFile *f = new TFile(fileIn); TTree *t = (TTree *) f->Get("tree"); TTree *tel[2]; tel[0] = (TTree *) f->Get("treeTel1"); tel[1] = (TTree *) f->Get("treeTel2"); TTree *telC = (TTree *) f->Get("treeTimeCommon"); // quality info of runs const Int_t nyearmax = 5; Bool_t runstatus[2][nyearmax][12][31][500]; //#telescope, year-2014, month, day, run Float_t effTel[2][nyearmax][12][31][500]; Int_t nStripDeadBot[2][nyearmax][12][31][500]; Int_t nStripDeadMid[2][nyearmax][12][31][500]; Int_t nStripDeadTop[2][nyearmax][12][31][500]; Float_t nstripDeadB[2]={0,0},nstripDeadM[2]={0,0},nstripDeadT[2]={0,0}; // sat info Float_t NsatAv[2][nyearmax][12][31][500]; // weather info Float_t pressureTel[2][nyearmax][12][31][500]; Float_t TempInTel[2][nyearmax][12][31][500]; Float_t TempOutTel[2][nyearmax][12][31][500]; Float_t timeWeath[2][nyearmax][12][31][500]; Float_t rateGT; Float_t phirelative; Float_t phirelative2; Float_t phirelativeAv; printf("Check Run quality\n"); if(tel[0] && tel[1]){ for(Int_t i=0;i < 2;i++){ // loop on telescopes printf("Tel-%i\n",i+1); for(Int_t j=0;j < tel[i]->GetEntries();j++){ // loop on runs tel[i]->GetEvent(j); rateGT = tel[i]->GetLeaf("FractionGoodTrack")->GetValue()*tel[i]->GetLeaf("rateHitPerRun")->GetValue(); Int_t aday = (tel[i]->GetLeaf("year")->GetValue()-2014) * 1000 + tel[i]->GetLeaf("month")->GetValue()*50 + tel[i]->GetLeaf("day")->GetValue(); if(i==1) printf("%f %f\n",rateGT , rateMin[i]); if(aday < adayMin || aday > adayMax){ hRunCut[i]->Fill("DateRange",1); continue;} if(tel[i]->GetLeaf("FractionGoodTrack")->GetValue() < fracGT[i]){ hRunCut[i]->Fill("LowFractionGT",1); continue;} // cut on fraction of good track if(tel[i]->GetLeaf("timeduration")->GetValue()*tel[i]->GetLeaf("rateHitPerRun")->GetValue() < hitevents[i]){ hRunCut[i]->Fill("TimeDuration",1); continue;} // cut on the number of event if(rateGT < rateMin[i] || rateGT > rateMax[i]){ hRunCut[i]->Fill("rateGT",1); continue;} // cut on the rate if(tel[i]->GetLeaf("run")->GetValue() > 499){ hRunCut[i]->Fill("RunNumber",1); continue;} // run < 500 if(i==1) printf("GR\n"); Float_t missinghitfrac = (tel[i]->GetLeaf("ratePerRun")->GetValue()-tel[i]->GetLeaf("rateHitPerRun")->GetValue()-2)/(tel[i]->GetLeaf("ratePerRun")->GetValue()-2); if(missinghitfrac < minmissingHitFrac[i] || missinghitfrac > maxmissingHitFrac[i]){ hRunCut[i]->Fill("MissingHitFrac",1); continue;} // active strip maps if(tel[i]->GetLeaf("maskB")) nStripDeadBot[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = countBits(Int_t(tel[i]->GetLeaf("maskB")->GetValue())); if(tel[i]->GetLeaf("maskM")) nStripDeadMid[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = countBits(Int_t(tel[i]->GetLeaf("maskM")->GetValue())); if(tel[i]->GetLeaf("maskT")) nStripDeadTop[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = countBits(Int_t(tel[i]->GetLeaf("maskT")->GetValue())); if(nStripDeadBot[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] > ndeadBotMax[i] || nStripDeadBot[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] < ndeadBotMin[i]) { hRunCut[i]->Fill("DeadStripBot",1); continue;} if(nStripDeadMid[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] > ndeadMidMax[i] || nStripDeadMid[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] < ndeadMidMin[i]){ hRunCut[i]->Fill("DeadStripMid",1); continue;} if(nStripDeadTop[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] > ndeadTopMax[i] || nStripDeadTop[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] < ndeadTopMin[i]){ hRunCut[i]->Fill("DeadStripTop",1); continue;} // nsat averaged per run if(tel[i]->GetLeaf("nSat")) NsatAv[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = tel[i]->GetLeaf("nSat")->GetValue(); if(NsatAv[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] < minAvSat[i] || NsatAv[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] > maxAvSat[i]){ hRunCut[i]->Fill("NSatellites",1); continue;} // weather info if(tel[i]->GetLeaf("Pressure")) pressureTel[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = tel[i]->GetLeaf("Pressure")->GetValue(); if(tel[i]->GetLeaf("IndoorTemperature")) TempInTel[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = tel[i]->GetLeaf("IndoorTemperature")->GetValue(); if(tel[i]->GetLeaf("OutdoorTemperature")) TempOutTel[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = tel[i]->GetLeaf("OutdoorTemperature")->GetValue(); if(tel[i]->GetLeaf("TimeWeatherUpdate")) timeWeath[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = tel[i]->GetLeaf("TimeWeatherUpdate")->GetValue(); if(timeWeath[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] < minWeathTimeDelay[i] || timeWeath[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] > maxWeathTimeDelay[i]){ hRunCut[i]->Fill("NoGoodWeather",1); continue; } // Set good runs runstatus[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = kTRUE; effTel[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2014][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = 1;//rateGT/refRate[i]; } } } else{ telC = NULL; } printf("Start to process correlations\n"); Int_t n = t->GetEntries(); // counter for seconds Int_t nsec = 0; Int_t nsecGR = 0; // for good runs Int_t isec = -1; // used only in case the tree with time info is not available Float_t neventsGR = 0; Float_t neventsGRandSat = 0; if(telC){ for(Int_t i=0; i < telC->GetEntries();i++){ telC->GetEvent(i); nsec += telC->GetLeaf("timeduration")->GetValue(); if(telC->GetLeaf("run")->GetValue() > 499 || telC->GetLeaf("run2")->GetValue() > 499) continue; if(!runstatus[0][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())]) continue; if(!runstatus[1][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run2")->GetValue())]) continue; nsecGR += telC->GetLeaf("timeduration")->GetValue(); nstripDeadB[0] += countBits(nStripDeadBot[0][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); nstripDeadM[0] += countBits(nStripDeadMid[0][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); nstripDeadT[0] += countBits(nStripDeadTop[0][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); nstripDeadB[1] += countBits(nStripDeadBot[1][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); nstripDeadM[1] += countBits(nStripDeadMid[1][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); nstripDeadT[1] += countBits(nStripDeadTop[1][Int_t(telC->GetLeaf("year")->GetValue())-2014][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())])*telC->GetLeaf("timeduration")->GetValue(); } nstripDeadB[0] /= nsecGR; nstripDeadM[0] /= nsecGR; nstripDeadT[0] /= nsecGR; nstripDeadB[1] /= nsecGR; nstripDeadM[1] /= nsecGR; nstripDeadT[1] /= nsecGR; printf("Dead channel tel1 = %f - %f - %f\n",nstripDeadB[0],nstripDeadM[0],nstripDeadT[0]); printf("Dead channel tel2 = %f - %f - %f\n",nstripDeadB[1],nstripDeadM[1],nstripDeadT[1]); } char title[300]; TH1F *h; sprintf(title,"correction assuming #Delta#phi = %4.2f, #DeltaL = %.1f m;#Deltat (ns);entries",angle,distance); h = new TH1F("hCoinc",title,nbint,tmin,tmax); Float_t DeltaT; Float_t phiAv,thetaAv,corr; Float_t Theta1,Theta2; Float_t Phi1,Phi2; Int_t nsatel1cur,nsatel2cur,ntrack1,ntrack2; Float_t v1[3],v2[3],vSP; // variable to recompute ThetaRel on the fly Float_t eff = 1; for(Int_t i=0;i<n;i++){ t->GetEvent(i); if(t->GetLeaf("RunNumber1") && (t->GetLeaf("RunNumber1")->GetValue() > 499 || t->GetLeaf("RunNumber2")->GetValue() > 499)) continue; if(tel[0] && !runstatus[0][Int_t(t->GetLeaf("year")->GetValue())-2014][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber1")->GetValue())]) continue; if(tel[1] && !runstatus[1][Int_t(t->GetLeaf("year")->GetValue())-2014][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber2")->GetValue())]) continue; eff = effTel[0][Int_t(t->GetLeaf("year")->GetValue())-2014][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber1")->GetValue())]; eff *= effTel[1][Int_t(t->GetLeaf("year")->GetValue())-2014][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber2")->GetValue())]; Int_t timec = t->GetLeaf("ctime1")->GetValue(); if(! telC){ if(isec == -1) isec = timec; if(timec != isec){ if(timec - isec < 20){ // printf("diff = %i\n",timec-isec); nsec +=(timec - isec); nsecGR +=(timec - isec); } isec = timec; } } Float_t thetarel = t->GetLeaf("ThetaRel")->GetValue(); Theta1 = (t->GetLeaf("Theta1")->GetValue())*TMath::DegToRad(); Theta2 = t->GetLeaf("Theta2")->GetValue()*TMath::DegToRad(); Phi1 = t->GetLeaf("Phi1")->GetValue()*TMath::DegToRad(); Phi2 = t->GetLeaf("Phi2")->GetValue()*TMath::DegToRad(); nsatel1cur = t->GetLeaf("Nsatellite1")->GetValue(); nsatel2cur = t->GetLeaf("Nsatellite2")->GetValue(); ntrack1 = t->GetLeaf("Ntracks1")->GetValue(); ntrack2 = t->GetLeaf("Ntracks2")->GetValue(); if(recomputeThetaRel){ // recompute ThetaRel applying corrections Phi1 += phi1Corr*TMath::DegToRad(); Phi2 += phi2Corr*TMath::DegToRad(); if(Phi1 > 2*TMath::Pi()) Phi1 -= 2*TMath::Pi(); if(Phi1 < 0) Phi1 += 2*TMath::Pi(); if(Phi2 > 2*TMath::Pi()) Phi2 -= 2*TMath::Pi(); if(Phi2 < 0) Phi2 += 2*TMath::Pi(); v1[0] = TMath::Sin(Theta1)*TMath::Cos(Phi1); v1[1] = TMath::Sin(Theta1)*TMath::Sin(Phi1); v1[2] = TMath::Cos(Theta1); v2[0] = TMath::Sin(Theta2)*TMath::Cos(Phi2); v2[1] = TMath::Sin(Theta2)*TMath::Sin(Phi2); v2[2] = TMath::Cos(Theta2); v1[0] *= v2[0]; v1[1] *= v2[1]; v1[2] *= v2[2]; vSP = v1[0] + v1[1] + v1[2]; thetarel = TMath::ACos(vSP)*TMath::RadToDeg(); } // cuts if(thetarel < minthetarel) continue; if(thetarel > maxthetarel) continue; if(t->GetLeaf("ChiSquare1")->GetValue() > maxchisquare) continue; if(t->GetLeaf("ChiSquare2")->GetValue() > maxchisquare) continue; neventsGR++; // reject events with not enough satellites if(nsatel1cur < satEventThr || nsatel1cur < satEventThr) continue; neventsGRandSat++; DeltaT = t->GetLeaf("DiffTime")->GetValue(); // get primary direction if(TMath::Abs(Phi1-Phi2) < TMath::Pi()) phiAv = (Phi1+Phi2)*0.5; else phiAv = (Phi1+Phi2)*0.5 + TMath::Pi(); thetaAv = (Theta1+Theta2)*0.5; // extra cuts if needed // if(TMath::Cos(Phi1-Phi2) < 0.) continue; Float_t resFactor = 1; if(thetarel > 10 ) resFactor *= 0.5; if(thetarel > 20 ) resFactor *= 0.5; if(thetarel > 30 ) resFactor *= 0.5; corr = distance * TMath::Sin(thetaAv)*TMath::Cos(phiAv-angle)/2.99792458000000039e-01 + deltatCorr; phirelative = (Phi1-angle)*TMath::RadToDeg(); if(phirelative < 0) phirelative += 360; if(phirelative < 0) phirelative += 360; if(phirelative > 360) phirelative -= 360; if(phirelative > 360) phirelative -= 360; phirelative2 = (Phi2-angle)*TMath::RadToDeg(); if(phirelative2 < 0) phirelative2 += 360; if(phirelative2 < 0) phirelative2 += 360; if(phirelative2 > 360) phirelative2 -= 360; if(phirelative2 > 360) phirelative2 -= 360; phirelativeAv = (phiAv-angle)*TMath::RadToDeg(); if(phirelativeAv < 0) phirelativeAv += 360; if(phirelativeAv < 0) phirelativeAv += 360; if(phirelativeAv > 360) phirelativeAv -= 360; if(phirelativeAv > 360) phirelativeAv -= 360; // if(TMath::Abs(DeltaT- deltatCorr) < windowAlignment){ // } if(thetarel < 10){//cos(thetarel*TMath::DegToRad())>0.98 && sin(thetaAv)>0.1){ if(TMath::Abs(DeltaT- corr) < windowAlignment) hModulationAvCorr->Fill(phirelativeAv,DeltaT-corr); if(TMath::Abs(DeltaT- deltatCorr) < windowAlignment){ hModulation->Fill(phirelative,(DeltaT-deltatCorr)/sin(thetaAv)*2.99792458000000039e-01); hModulation2->Fill(phirelative2,(DeltaT-deltatCorr)/sin(thetaAv)*2.99792458000000039e-01); hModulationAv->Fill(phirelativeAv,(DeltaT-deltatCorr)/sin(thetaAv)*2.99792458000000039e-01); hSinTheta->Fill(phirelative,sin(thetaAv)); hSinTheta2->Fill(phirelative2,sin(thetaAv)); nsigPeak++; hnsigpeak->Fill(phirelativeAv); } else if(TMath::Abs(DeltaT- deltatCorr) < windowAlignment*10){ nbackPeak++; hnbackpeak->Fill(phirelativeAv); } } h->Fill(DeltaT-corr,1./eff); if(TMath::Abs(DeltaT-corr) < windowAlignment){ hDeltaTheta->Fill((Theta1-Theta2)*TMath::RadToDeg()); hDeltaPhi->Fill((Phi1-Phi2)*TMath::RadToDeg()); hThetaRel->Fill(thetarel); hAngle->Fill((Theta1-Theta2)*TMath::RadToDeg(),(Phi1-Phi2)*TMath::RadToDeg()); } else if(TMath::Abs(DeltaT-corr) > windowAlignment*2 && TMath::Abs(DeltaT-corr) < windowAlignment*12){ hDeltaThetaBack->Fill((Theta1-Theta2)*TMath::RadToDeg()); hDeltaPhiBack->Fill((Phi1-Phi2)*TMath::RadToDeg()); hThetaRelBack->Fill(thetarel); hAngleBack->Fill((Theta1-Theta2)*TMath::RadToDeg(),(Phi1-Phi2)*TMath::RadToDeg()); } } // compute (S+B)/S for(Int_t i=1;i<=50;i++){ Float_t corrfactorPeak = 1; if(nsigPeak-nbackPeak*0.1 > 0) corrfactorPeak = hnsigpeak->GetBinContent(i)/(hnsigpeak->GetBinContent(i)-hnbackpeak->GetBinContent(i)*0.1); else printf("bin %i) not enough statistics\n",i); hnsigpeak->SetBinContent(i,corrfactorPeak); } TF1 *fpol0 = new TF1("fpol0","pol0"); hnsigpeak->Fit(fpol0); hModulation->Scale(fpol0->GetParameter(0)); hModulation2->Scale(fpol0->GetParameter(0)); hModulationAv->Scale(fpol0->GetParameter(0)); hModulationAvCorr->Scale(fpol0->GetParameter(0)); TF1 *fmod = new TF1("fmod","[0] + [1]*cos((x-[2])*TMath::DegToRad())"); hModulationAv->Fit(fmod); printf("Estimates from time delay: Distance = %f +/- %f m -- Angle = %f +/- %f deg\n",fmod->GetParameter(1),fmod->GetParError(1),fmod->GetParameter(2),fmod->GetParError(2)); h->SetStats(0); hDeltaThetaBack->Sumw2(); hDeltaPhiBack->Sumw2(); hThetaRelBack->Sumw2(); hDeltaThetaBack->Scale(0.1); hDeltaPhiBack->Scale(0.1); hThetaRelBack->Scale(0.1); hAngleBack->Scale(0.1); hAngle->Add(hAngleBack,-1); printf("bin counting: SIGNAL = %f +/- %f\n",hDeltaPhi->Integral()-hDeltaPhiBack->Integral(),sqrt(hDeltaPhi->Integral())); rate = (hDeltaPhi->Integral()-hDeltaPhiBack->Integral())/nsecGR*86400; rateErr = sqrt(hDeltaPhi->Integral())/nsecGR*86400; Float_t val,eval; TCanvas *c1=new TCanvas(); TF1 *ff = new TF1("ff","[0]*[4]/[2]/sqrt(2*TMath::Pi())*TMath::Exp(-(x-[1])*(x-[1])*0.5/[2]/[2]) + [3]*[4]/6/[2]"); ff->SetParName(0,"signal"); ff->SetParName(1,"mean"); ff->SetParName(2,"sigma"); ff->SetParName(3,"background"); ff->SetParName(4,"bin width"); ff->SetParameter(0,42369); ff->SetParameter(1,0); ff->SetParLimits(2,10,maxwidth); ff->SetParameter(2,350); // fix witdh if needed ff->SetParameter(3,319); ff->FixParameter(4,(tmax-tmin)/nbint); // bin width ff->SetNpx(1000); if(cout) cout->cd(); h->Fit(ff,"EI","",-10000,10000); val = ff->GetParameter(2); eval = ff->GetParError(2); printf("significance = %f\n",ff->GetParameter(0)/sqrt(ff->GetParameter(0) + ff->GetParameter(3))); h->Draw(); new TCanvas; TF1 *func1 = (TF1 *) h->GetListOfFunctions()->At(0); func1->SetLineColor(2); h->SetLineColor(4); TPaveText *text = new TPaveText(1500,(h->GetMinimum()+(h->GetMaximum()-h->GetMinimum())*0.6),9500,h->GetMaximum()); text->SetFillColor(0); sprintf(title,"width = %5.1f #pm %5.1f",func1->GetParameter(2),func1->GetParError(2)); text->AddText(title); sprintf(title,"signal (S) = %5.1f #pm %5.1f",func1->GetParameter(0),func1->GetParError(0)); text->AddText(title); sprintf(title,"background (B) (3#sigma) = %5.1f #pm %5.1f",func1->GetParameter(3),func1->GetParError(3)); text->AddText(title); sprintf(title,"significance (S/#sqrt{S+B}) = %5.1f",func1->GetParameter(0)/sqrt(func1->GetParameter(0)+func1->GetParameter(3))); text->AddText(title); text->SetFillStyle(0); text->SetBorderSize(0); text->Draw("SAME"); // correct nsecGR for the event rejected because of the number of satellites (event by event cut) nsecGR *= neventsGRandSat/neventsGR; printf("n_day = %f\nn_dayGR = %f\n",nsec*1./86400,nsecGR*1./86400); text->AddText(Form("rate = %f #pm %f per day",func1->GetParameter(0)*86400/nsecGR,func1->GetParError(0)*86400/nsecGR)); TFile *fo = new TFile("outputCERN-01-02.root","RECREATE"); h->Write(); hDeltaTheta->Write(); hDeltaPhi->Write(); hThetaRel->Write(); hDeltaThetaBack->Write(); hDeltaPhiBack->Write(); hThetaRelBack->Write(); hAngle->Write(); hModulation->Write(); hModulation2->Write(); hModulationAv->Write(); hModulationAvCorr->Write(); hSinTheta->Write(); hSinTheta2->Write(); hnsigpeak->Write(); hRunCut[0]->Write(); hRunCut[1]->Write(); fo->Close(); return nsecGR*1./86400; }
//Fit a peak in an energy spectrum void FitPeak(int run, int decay, int shaping, int top) { TH1D* hCe = (TH1D*) gROOT->FindObject("hCe"); if (hCe != 0) delete hCe; hCe = new TH1D("hCe","hCe",3000,0,6000); trapf.SetPath("Files/Dec15/Fixed"); if (!trapf.Open(run,decay,shaping,top)) return; for (int i = 0; i < trapf.GetNumEvents(); i++) { trapf.GetEvent(i); if (trapf.Trap_event.ch == 9 && trapf.Trap_event.AveE > 0) { hCe->Fill(trapf.Trap_event.AveE); } } gROOT->cd(); hCe->GetXaxis()->SetRangeUser(abslo,abshi); //avoid low energy stuffs hCe->Draw(); double max = hCe->GetMaximum(); int binmax = hCe->GetMaximumBin(); double xmax = hCe->GetXaxis()->GetBinCenter(binmax); TF1* floo = (TF1*) gROOT->FindObject("floo"); if (floo != 0) delete floo; floo = new TF1("floo", floof, 0, 6000, 7); floo->SetParameters(max,xmax,10,max*0.1,50,20,5); floo->SetParLimits(0,0,2*max); floo->SetParLimits(3,0,2*max); floo->SetParLimits(4,0,500); floo->SetParName(2,"sigma"); hCe->Fit(floo,"Q","",1000,xmax+60); double mean, fwhm; double lo, hi; GetFWHM(floo,mean,fwhm); lo = mean-8.5*fwhm; hi = mean+3*fwhm; if (lo < abslo) lo = abslo; ReFit(lo,hi); GetFWHM(floo,mean,fwhm); lo = mean-8.5*fwhm; hi = mean+3*fwhm; if (lo < abslo) lo = abslo; ReFit(lo,hi); GetFWHM(floo,mean,fwhm); lo = mean-8.5*fwhm; hi = mean+3*fwhm; if (lo < abslo) lo = abslo; ReFit(lo,hi); GetFWHM(floo,mean,fwhm); //draw parts TF1* part1 = (TF1*) gROOT->FindObject("part1"); if (part1 != 0) delete part1; part1 = new TF1("part1", gaussian, 0, 6000, 3); for (int i=0;i<3;i++) part1->SetParameter(i,floo->GetParameter(i)); part1->SetLineColor(kViolet); part1->Draw("same"); TF1* part2 = (TF1*) gROOT->FindObject("part2"); if (part2 != 0) delete part2; part2 = new TF1("part2", hypermet, 0, 6000, 4); part2->SetParameter(0,floo->GetParameter(3)); part2->SetParameter(1,floo->GetParameter(1)); part2->SetParameter(2,floo->GetParameter(2)); part2->SetParameter(3,floo->GetParameter(4)); part2->SetLineColor(kBlue); part2->Draw("same"); TF1* part3 = (TF1*) gROOT->FindObject("part3"); if (part3!= 0) delete part3; part3 = new TF1("part3", stepbkgd, 0, 6000, 4); part3->SetParameter(0,floo->GetParameter(5)); part3->SetParameter(1,floo->GetParameter(6)); part3->SetParameter(2,floo->GetParameter(1)); part3->SetParameter(3,floo->GetParameter(2)); part3->SetLineColor(kGreen); part3->Draw("same"); fgt->SetLineColor(kBlack); fgt->Draw("same"); }
void multidimSampling() { #ifdef __CINT__ std::cout << "DO NOT RUN WITH CINT:" << std::endl; std::cout << "we are using a custom function which requires" << std::endl; std::cout << "that this tutorial must be compiled with ACLIC" << std::endl; return; #endif const int N = 100000; //const int NBin = 1000; const int DIM = 4; double xmin[] = {-10,-10,-10, -10}; double xmax[] = { 10, 10, 10, 10}; double par0[] = { 1., -1., 2, 0, // the gaussian mu 1, 2, 1, 3, // the sigma 0.5,0.,0.,0.,0.,0.8 }; // the correlation const int NPAR = DIM + DIM*(DIM+1)/2; // 14 in the 4d case // generate the sample GausND gaus4d(4); TF1 * f = new TF1("functionND",gaus4d,0,1,14); f->SetParameters(par0); double x0[] = {0,0,0,0}; // for debugging if (debug) f->EvalPar(x0,0); debug = false; TString name; for (int i = 0; i < NPAR; ++i ) { if (i < DIM) f->SetParName(i, name.Format("mu_%d",i+1) ); else if (i < 2*DIM) f->SetParName(i, name.Format("sig_%d",i-DIM+1) ); else if (i < 2*DIM) f->SetParName(i, name.Format("sig_%d",i-2*DIM+1) ); } //ROOT::Math::DistSamplerOptions::SetDefaultSampler("Foam"); DistSampler * sampler = Factory::CreateDistSampler(); if (sampler == 0) { Info("multidimSampling","Default sampler %s is not available try with Foam ", ROOT::Math::DistSamplerOptions::DefaultSampler().c_str() ); ROOT::Math::DistSamplerOptions::SetDefaultSampler("Foam"); } sampler = Factory::CreateDistSampler(); if (sampler == 0) { Error("multidimSampling","Foam sampler is not available - exit "); return; } sampler->SetFunction(*f,DIM); sampler->SetRange(xmin,xmax); bool ret = sampler->Init(); std::vector<double> data1(DIM*N); double v[DIM]; TStopwatch w; if (!ret) { Error("Sampler::Init","Error initializing unuran sampler"); return; } // generate the data w.Start(); for (int i = 0; i < N; ++i) { sampler->Sample(v); for (int j = 0; j < DIM; ++j) data1[N*j + i] = v[j]; } w.Stop(); w.Print(); // fill tree with data TFile * file = new TFile("multiDimSampling.root","RECREATE"); double x[DIM]; TTree * t1 = new TTree("t1","Tree from Unuran"); t1->Branch("x",x,"x[4]/D"); for (int i = 0; i < N; ++i) { for (int j = 0; j < DIM; ++j) { x[j] = data1[i+N*j]; } t1->Fill(); } // plot the data t1->Draw("x[0]:x[1]:x[2]:x[3]","","candle"); TCanvas * c2 = new TCanvas(); c2->Divide(3,2); int ic=1; c2->cd(ic++); t1->Draw("x[0]:x[1]"); c2->cd(ic++); t1->Draw("x[0]:x[2]"); c2->cd(ic++); t1->Draw("x[0]:x[3]"); c2->cd(ic++); t1->Draw("x[1]:x[2]"); c2->cd(ic++); t1->Draw("x[1]:x[3]"); c2->cd(ic++); t1->Draw("x[2]:x[3]"); t1->Write(); file->Close(); }
void pionContaminationVeta(){ gStyle->SetOptStat(0); gStyle->SetOptFit(1); gStyle->SetPalette(1); char hist [100]; char hfile [100]; sprintf(hfile,"~/Desktop/Research/2012IFF/rootFiles/nsigma20bintest35mil.root"); TFile* file = TFile::Open(hfile,"read"); assert(file); double totalYieldWhole = 0; double pionYieldWhole = 0; double kpYieldWhole = 0; double electYieldWhile = 0; double pionFrac [20]; double kpFrac [20]; double electFrac [20]; double pionCent [20]; double kpCent [20]; double electCent [20]; double pionMax [20]; double kpMax [20]; double electMax [20]; double pionSig [20]; double kpSig [20]; double electSig [20]; double etastart[20]; double etaend[20]; double eta[20]; double piYield[20]; double highestYield = 0; double totalYeild[20]; TH1F* hTotal = new TH1F("hTotal","hTotal",300,-10,10); for (int ihist=0; ihist<20; ihist++) { /* if (ihist != 0 || ihist != 1 || ihist != 2 || ihist != 3 ||) { cou } */ sprintf(hist,"nSigmaPionBin_%i",ihist); cout << hist << endl; TH1F *hNsigma = (TH1F*) file->Get(hist); assert(hNsigma); hTotal->Add(hNsigma, 1); cout << hTotal->GetEntries() << endl; TF1 *fitFunc = new TF1("fitFunc","gaus(0)+gaus(3)+gaus(6)",-10,10); TF1 *piFunc = new TF1("piFunc","gaus(0)",-10,10); TF1 *kpFunc = new TF1("kpFunc","gaus(0)",-10,10); TF1 *eFunc = new TF1( "eFunc","gaus(0)",-10,10); fitFunc->SetParName(0, "A_{#pi}"); fitFunc->SetParName(1, "#LTn_{#pi}#GT"); fitFunc->SetParName(2, "#sigma_{#pi}"); fitFunc->SetParName(3, "A_{K/p}"); fitFunc->SetParName(4, "#LTn_{K/p}#GT"); fitFunc->SetParName(5, "#sigma_{K/p}"); fitFunc->SetParName(6, "A_{e}"); fitFunc->SetParName(7, "#LTn_{e}#GT"); fitFunc->SetParName(8, "#sigma_{e}"); fitFunc->SetParameter(0, hNsigma->GetMaximum()); fitFunc->SetParameter(1, 0.); fitFunc->SetParameter(2, 1.); fitFunc->SetParameter(3, 0.05*hNsigma->GetMaximum()); fitFunc->SetParameter(4,-3.); fitFunc->SetParameter(5, 1.5); fitFunc->SetParameter(6, 0.05*hNsigma->GetMaximum()); fitFunc->SetParameter(7, 4.); //was at 5. but it seems like 4. works better fitFunc->SetParameter(8, 3.); hNsigma->Fit("fitFunc"); float ampPi = fitFunc->GetParameter(0); float centPi = fitFunc->GetParameter(1); float sigPi = fitFunc->GetParameter(2); piFunc->SetParameters(ampPi,centPi,sigPi); piFunc->SetLineColor(kViolet+1); float ampKP = fitFunc->GetParameter(3); float centKP = fitFunc->GetParameter(4); float sigKP = fitFunc->GetParameter(5); kpFunc->SetParameters(ampKP,centKP,sigKP); kpFunc->SetLineColor(kGreen+2); float ampE = fitFunc->GetParameter(6); float centE = fitFunc->GetParameter(7); float sigE = fitFunc->GetParameter(8); eFunc->SetParameters(ampE,centE,sigE); eFunc->SetLineColor(kBlue); piFunc->Draw("same"); kpFunc->Draw("same"); eFunc->Draw("same"); TLine *l1 = new TLine( 2.5,0, 2.5,0.9*hNsigma->GetMaximum()); TLine *l2 = new TLine(-1.0,0,-1.0,0.9*hNsigma->GetMaximum()); l1->SetLineColor(kOrange+2); l2->SetLineColor(kOrange+2); l1->SetLineWidth(2); l2->SetLineWidth(2); l1->Draw(); l2->Draw(); //* float totYield = fitFunc->Integral(-1.,2.5); float pionYield = piFunc->Integral(-1.,2.5); float kpYield = kpFunc->Integral(-1.,2.5); float eYield = eFunc->Integral(-1.,2.5); //*/ /* float totYield = fitFunc->Integral(-2.,2.); float pionYield = piFunc->Integral(-2.,2.); float kpYield = kpFunc->Integral(-2.,2.); float eYield = eFunc->Integral(-2.,2.); //*/ totalYieldWhole += totYield; pionYieldWhole += pionYield; kpYieldWhole += kpYield; electYieldWhile += eYield; printf("\nTotal Yield\tPion Yield\tK/p Yield\tElect Yield\n"); printf("%e\t%e\t%e\t%e\n",totYield,pionYield,kpYield,eYield); printf("Pion Fraction = %e\n",(pionYield/totYield)); totalYeild[ihist] = totYield; pionFrac[ihist] = pionYield/totYield; kpFrac[ihist] = kpYield/totYield; electFrac[ihist] = eYield/totYield; etastart[ihist] = -2+ihist*0.2; etaend[ihist] = -2+(ihist+1)*0.2; eta[ihist] = (etastart[ihist]+etaend[ihist])*.5; piYield[ihist] = pionYield; if (highestYield < pionYield){highestYield = pionYield;} } double normlzd_PiYield[20]; double sumPiYield = 0; for (int i=0; i<20; i++) { if (pionFrac[i] != pionFrac[i]) { cout << i << " " << eta[i] << " testFailed" << " highyeild " << highestYield << endl; pionFrac[i] = -.2; } else { cout << i << " " << eta[i] << " " << pionFrac[i] << " highyeild " << highestYield << endl; } normlzd_PiYield[i] = piYield[i]/highestYield; sumPiYield += piYield[i]; } double pionFracErr[20]; double kpFracErr[20]; double electFracErr[20]; for (int i=0; i<20; i++) { pionFracErr[i] = sqrt((1-pionFrac[i])*pionFrac[i]/totalYeild[i]); kpFracErr[i] = sqrt((1-kpFrac[i])*kpFrac[i]/totalYeild[i]); electFracErr[i] = sqrt((1-electFrac[i])*electFrac[i]/totalYeild[i]); } cout << "total Pion Yield = " << sumPiYield << endl; TGraphErrors* gPionYield = new TGraphErrors(20,eta,normlzd_PiYield,0,0); gPionYield->SetMarkerColor(kRed+2); gPionYield->SetMarkerStyle(24); TGraphErrors* gPionFrac = new TGraphErrors(20,eta,pionFrac,0,pionFracErr); TGraphErrors* gKpFrac = new TGraphErrors(20,eta,kpFrac,0,kpFracErr); TGraphErrors* gElecFrac = new TGraphErrors(20,eta,electFrac,0,electFracErr); gPionFrac->SetMarkerColor(kViolet+1); gPionFrac->SetLineColor(kViolet+1); gPionFrac->SetLineWidth(2); gKpFrac->SetMarkerColor(kGreen+2); gKpFrac->SetLineColor(kGreen+2); gKpFrac->SetLineWidth(2); gKpFrac->SetMarkerStyle(22); gElecFrac->SetMarkerColor(kBlue); gElecFrac->SetLineColor(kBlue); gElecFrac->SetLineWidth(2); gElecFrac->SetMarkerStyle(20); TMultiGraph* multiFracs = new TMultiGraph(); multiFracs->Add(gPionFrac); multiFracs->Add(gKpFrac); multiFracs->Add(gElecFrac); //multiFracs->Add(gPionYield); TCanvas* cMultiG = new TCanvas(); multiFracs->Draw("AP"); multiFracs->GetXaxis()->SetTitle("#eta^{#pi^{+}#pi^{-}}"); multiFracs->GetYaxis()->SetTitle("particle Fractions"); gPad->Modified(); TLegend* leg = new TLegend(0.52,0.17,0.89,0.30); leg->AddEntry(gPionFrac,"Pion","P"); leg->AddEntry(gKpFrac,"K/P","P"); leg->AddEntry(gElecFrac,"Electron","P"); // leg->Draw(); TCanvas* cPiYeild = new TCanvas(); TGraphErrors* gPionYield = new TGraphErrors(20,eta,piYield,0,0); gPionYield->Draw("AP"); gPionYield->SetMarkerColor(kRed+2); gPionYield->SetMarkerStyle(24); gPionYield->GetXaxis()->SetTitle("#eta^{#pi^{+}#pi^{-}}"); gPionYield->GetYaxis()->SetTitle("Pion Yield"); cout << pionYieldWhole/totalYieldWhole << endl; hTotal->Draw(); TF1 *fitFunc = new TF1("fitFunc","gaus(0)+gaus(3)+gaus(6)",-10,10); TF1 *piFunc = new TF1("piFunc","gaus(0)",-10,10); TF1 *kpFunc = new TF1("kpFunc","gaus(0)",-10,10); TF1 *eFunc = new TF1( "eFunc","gaus(0)",-10,10); fitFunc->SetParName(0, "A_{#pi}"); fitFunc->SetParName(1, "#LTn_{#pi}#GT"); fitFunc->SetParName(2, "#sigma_{#pi}"); fitFunc->SetParName(3, "A_{K/p}"); fitFunc->SetParName(4, "#LTn_{K/p}#GT"); fitFunc->SetParName(5, "#sigma_{K/p}"); fitFunc->SetParName(6, "A_{e}"); fitFunc->SetParName(7, "#LTn_{e}#GT"); fitFunc->SetParName(8, "#sigma_{e}"); fitFunc->SetParameter(0, hTotal->GetMaximum()); fitFunc->SetParameter(1, 0.); fitFunc->SetParameter(2, 1.); fitFunc->SetParameter(3, 0.05*hTotal->GetMaximum()); fitFunc->SetParameter(4,-3.); fitFunc->SetParameter(5, 1.5); fitFunc->SetParameter(6, 0.05*hTotal->GetMaximum()); fitFunc->SetParameter(7, 4.); //was at 5. but it seems like 4. works better fitFunc->SetParameter(8, 3.); hTotal->Fit("fitFunc"); float ampPi = fitFunc->GetParameter(0); float centPi = fitFunc->GetParameter(1); float sigPi = fitFunc->GetParameter(2); piFunc->SetParameters(ampPi,centPi,sigPi); piFunc->SetLineColor(kViolet+1); float ampKP = fitFunc->GetParameter(3); float centKP = fitFunc->GetParameter(4); float sigKP = fitFunc->GetParameter(5); kpFunc->SetParameters(ampKP,centKP,sigKP); kpFunc->SetLineColor(kGreen+2); float ampE = fitFunc->GetParameter(6); float centE = fitFunc->GetParameter(7); float sigE = fitFunc->GetParameter(8); eFunc->SetParameters(ampE,centE,sigE); eFunc->SetLineColor(kBlue); piFunc->Draw("same"); kpFunc->Draw("same"); eFunc->Draw("same"); TLine *l1 = new TLine( 2.5,0, 2.5,0.9*hNsigma->GetMaximum()); TLine *l2 = new TLine(-1.0,0,-1.0,0.9*hNsigma->GetMaximum()); l1->SetLineColor(kOrange+2); l2->SetLineColor(kOrange+2); l1->SetLineWidth(2); l2->SetLineWidth(2); l1->Draw(); l2->Draw(); //* float totYield = fitFunc->Integral(-1.,2.5); float pionYield = piFunc->Integral(-1.,2.5); float kpYield = kpFunc->Integral(-1.,2.5); float eYield = eFunc->Integral(-1.,2.5); double pionerr = sqrt((1-pionYield/totYield)*pionYield/totYield/totalYeild); cout << pionYield/totYield << " " << pionerr << endl; }