void annconvergencetest( TDirectory *lhdir ) { TCanvas* c = new TCanvas( "MLPConvergenceTest", "MLP Convergence Test", 150, 0, 600, 580*0.8 ); TH1* estimatorHistTrain = (TH1*)lhdir->Get( "estimatorHistTrain" ); TH1* estimatorHistTest = (TH1*)lhdir->Get( "estimatorHistTest" ); Double_t m1 = estimatorHistTrain->GetMaximum(); Double_t m2 = estimatorHistTest ->GetMaximum(); Double_t max = TMath::Max( m1, m2 ); m1 = estimatorHistTrain->GetMinimum(); m2 = estimatorHistTest ->GetMinimum(); Double_t min = TMath::Min( m1, m2 ); estimatorHistTrain->SetMaximum( max + 0.1*(max - min) ); estimatorHistTrain->SetMinimum( min - 0.1*(max - min) ); estimatorHistTrain->SetLineColor( 2 ); estimatorHistTrain->SetLineWidth( 2 ); estimatorHistTrain->SetTitle( TString("MLP Convergence Test") ); estimatorHistTest->SetLineColor( 4 ); estimatorHistTest->SetLineWidth( 2 ); estimatorHistTrain->GetXaxis()->SetTitle( "Epochs" ); estimatorHistTrain->GetYaxis()->SetTitle( "Estimator" ); estimatorHistTrain->GetXaxis()->SetTitleOffset( 1.20 ); estimatorHistTrain->GetYaxis()->SetTitleOffset( 1.65 ); estimatorHistTrain->Draw(); estimatorHistTest ->Draw("same"); // need a legend TLegend *legend= new TLegend( 1 - c->GetRightMargin() - 0.45, 1-c->GetTopMargin() - 0.20, 1 - c->GetRightMargin() - 0.05, 1-c->GetTopMargin() - 0.05 ); legend->AddEntry(estimatorHistTrain,"Training Sample","l"); legend->AddEntry(estimatorHistTest,"Test sample","l"); legend->Draw("same"); legend->SetMargin( 0.3 ); c->cd(); TMVAGlob::plot_logo(); // don't understand why this doesn't work ... :-( c->Update(); TString fname = "plots/annconvergencetest"; TMVAGlob::imgconv( c, fname ); }
TH1* GetOne(UShort_t sNN, const TString& trigger) { Long_t p = gROOT->ProcessLine(Form("Drawer::GetStack(0, \"pp\", %d, " "\"%s\", false, true)", sNN, trigger.Data())); THStack* s = (THStack*)p; TList* l = s->GetHists(); TH1* h = 0; TIter n(l); l->ls(); while ((h = static_cast<TH1*>(n()))) { TString m(h->GetName()); if (m.EqualTo("dndetaForward_all")) break; } if (h) { switch (sNN) { case 900: h->SetTitle("900GeV"); h->SetMarkerColor(kRed+2); break; case 2760: h->SetTitle("2.76TeV"); h->SetMarkerColor(kGreen+2); break; case 7000: h->SetTitle("7TeV"); h->SetMarkerColor(kBlue+2); break; case 8000: h->SetTitle("8TeV"); h->SetMarkerColor(kBlack); break; } } return h; }
void QAvertex(const Char_t *fdata, const Char_t *fmc) { style(); TFile *fdtin = TFile::Open(fdata); TList *ldtin = (TList *)fdtin->Get("clist"); TH2 *hdtin = (TH2 *)ldtin->FindObject("zv"); TH1 *hdt = (TH1 *)ldtin->FindObject("zvNoSel"); SetHistoStyle(hdt, 20, kRed+1); hdt->Scale(1. / hdt->Integral()); TH1 *hdt0010 = hdtin->ProjectionX("hdt0010", 1, 4); SetHistoStyle(hdt0010, 20, kRed+1); hdt0010->Scale(1. / hdt0010->Integral()); TH1 *hdt7080 = hdtin->ProjectionX("hdt7080", 11, 11); SetHistoStyle(hdt7080, 25, kAzure-3); hdt7080->Scale(1. / hdt7080->Integral()); TFile *fmcin = TFile::Open(fmc); TList *lmcin = (TList *)fmcin->Get("clist"); TH1 *hmc = (TH1 *)lmcin->FindObject("zvNoSel"); SetHistoStyle(hmc, 25, kAzure-3); hmc->Scale(1. / hmc->Integral()); TCanvas *c = new TCanvas("cVertex", "cVertex", 800, 800); TH1 * hfr = c->DrawFrame(-20., 0., 20., 0.1); hfr->SetTitle(";#it{z}_{vtx};"); hdt0010->Draw("same"); hdt7080->Draw("same"); TLegend *legend = new TLegend(0.20, 0.18+0.60, 0.50, 0.30+0.60); legend->SetFillColor(0); legend->SetBorderSize(0); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->AddEntry(hdt0010, "0-10%", "p"); legend->AddEntry(hdt7080, "70-80%", "p"); legend->Draw("same"); c->SaveAs(canvasPrefix+"vertex.pdf"); TCanvas *c1 = new TCanvas("cVertexDataMC", "cVertexDataMC", 800, 800); hfr = c1->DrawFrame(-20., 0., 20., 0.1); hfr->SetTitle(";#it{z}_{vtx};"); hdt->Draw("same"); hmc->Draw("same"); legend = new TLegend(0.20, 0.18+0.60, 0.50, 0.30+0.60); legend->SetFillColor(0); legend->SetBorderSize(0); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->AddEntry(hdt, "data", "p"); legend->AddEntry(hmc, "Monte Carlo", "p"); legend->Draw("same"); c1->SaveAs(canvasPrefix+"vertexDataMC.pdf"); //return 0; }
void QAcentrality(const Char_t *fdata) { style(); TFile *fin = TFile::Open(fdata); TList *lin = (TList *)fin->Get("clist"); lin->ls(); TH1 *hin = (TH1 *)lin->FindObject("EvCentrDist"); Float_t sum = 1.2 * hin->Integral(hin->FindBin(0.1), hin->FindBin(79.9)); hin->Scale(1. / sum); SetHistoStyle(hin, 20, kRed+1); TCanvas *c = new TCanvas("cQAcentrality", "cQAcentrality", 800, 800); TH1 * hfr = c->DrawFrame(0., 0.005, 100., 0.015); hfr->SetTitle(";centrality percentile;events"); hin->Draw("same"); c->SaveAs(canvasPrefix+"centrality.pdf"); TH2 *hinv0 = (TH2 *)lin->FindObject("V0"); TCanvas *cv0 = new TCanvas("cQAcentralityV0", "cQAcentralityV0", 800, 800); cv0->SetLogx(); cv0->SetLogz(); // TH1 * hfrv0 = cv0->DrawFrame(100., -0.5, 50000., 10.5); // DrawBinLabelsY(hfrv0, kTRUE); // hfrv0->SetTitle(";V0 signal;"); //hinv0->Draw("same,col"); hinv0->Draw("col"); cv0->SaveAs(canvasPrefix+"centralityV0.pdf"); }
// draw the next waveform that we find associated with an event void DrawNext(void) { static Int_t evno=0; if (tree == nullptr) { tree = (TTree*)gROOT->FindObject("FragmentTree"); } tree->SetBranchAddress("TFragment", &frag); do { tree->GetEntry(evno++); } while (frag->wavebuffer.empty()); cout<<"Event number "<<evno<<endl; frag->Print(); //printf("wavebuffer.size() = %i\n",wavebuffer.size()); TH1 *his = makeHisto(frag->wavebuffer); TChannel *chan = TChannel::GetChannel(frag->ChannelAddress); // if(chan && (strncmp(chan->GetChannelName(),"DSC",3)==0)) // TH1 *his = makeDescantHisto(frag->wavebuffer); if(chan) his->SetTitle(chan->GetChannelName()); his->Draw(); }
void SetTitle(TH1& h, TString Xtitle, TString Ytitle, TString title){ h.GetXaxis()->SetTitle(Xtitle); h.GetYaxis()->SetTitle(Ytitle); h.GetXaxis()->CenterTitle(); h.GetYaxis()->CenterTitle(); h.SetTitle(title); }
histoBook* histoBook::set( string param, string p1, string p2, string p3, string p4 ){ // force the param name to lowercase transform(param.begin(), param.end(), param.begin(), ::tolower); TH1* h = get( styling ); if ( h ){ if ( "title" == param ){ h->SetTitle( p1.c_str() ); } else if ( "x" == param ){ h->GetXaxis()->SetTitle( p1.c_str() ); } else if ( "y" == param ){ h->GetYaxis()->SetTitle( p1.c_str() ); } else if ( "legend" == param ){ if ( p2 == "") p2="lpf"; legend->AddEntry( h, p1.c_str(), p2.c_str() ); legend->Draw(); } else if ( "draw" == param ){ drawOption = p1; } } return this; }
TCanvas* DrawNP(int np, TObjArray* harr, TCanvas* cnv) { if (!harr) harr = &histoArr; if (!cnv) cnv = new TCanvas(Form("cnv%d",np),Form("cnv%d",np),900,700); cnv->Clear(); cnv->Divide(2,1); cnv->cd(1); // TH1* dxodd = (TH1*)harr->At(np*10+kDTXodd); TH1* dxevn = (TH1*)harr->At(np*10+kDTXeven); TH1* dxoddS =(TH1*)harr->At(np*10+kDTXoddSPL); TH1* dxevnS =(TH1*)harr->At(np*10+kDTXevenSPL); double max = TMath::Max(dxodd->GetMaximum(),dxevn->GetMaximum()); dxodd->SetMaximum(1.1*max); dxodd->GetXaxis()->SetTitle("#DeltaX, #mum"); dxodd->SetTitle(Form("#DeltaX for clSize=%d",np)); dxodd->Fit("gaus","",""); dxevn->Fit("gaus","","sames"); // dxoddS->Draw("sames"); dxevnS->Draw("sames"); // gPad->Modified(); gPad->Update(); SetStPadPos(dxodd,0.75,0.97,0.8,1., -1,dxodd->GetLineColor()); SetStPadPos(dxevn,0.75,0.97,0.6,0.8, -1,dxevn->GetLineColor()); SetStPadPos(dxoddS,0.75,0.97,0.4,0.6, -1,dxoddS->GetLineColor()); SetStPadPos(dxevnS,0.75,0.97,0.2,0.4, -1,dxevnS->GetLineColor()); // cnv->cd(2); TH1* dz = (TH1*)harr->At(np*10+kDTZ); dz->SetTitle(Form("#DeltaZ for clSize=%d",np)); dz->GetXaxis()->SetTitle("#DeltaZ, #mum"); dz->Fit("gaus"); TH1* dzS = (TH1*)harr->At(np*10+kDTZSPL); dz->Draw("sames"); gPad->Modified(); gPad->Update(); SetStPadPos(dz,0.75,0.97,0.8,1., -1, dz->GetLineColor()); SetStPadPos(dzS,0.75,0.97,0.5,0.7, -1, dzS->GetLineColor()); gPad->Modified(); gPad->Update(); // cnv->cd(); return cnv; }
void showGraph(double canvasSizeX, double canvasSizeY, TGraph* graph, bool useLogScaleX, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset, bool useLogScaleY, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetTopMargin(0.05); canvas->SetLeftMargin(0.19); canvas->SetBottomMargin(0.19); canvas->SetRightMargin(0.05); canvas->SetLogx(useLogScaleX); canvas->SetLogy(useLogScaleY); TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", 10, xMin, xMax); dummyHistogram->SetTitle(""); dummyHistogram->SetStats(false); dummyHistogram->SetMinimum(yMin); dummyHistogram->SetMaximum(yMax); dummyHistogram->Draw("axis"); TAxis* xAxis = dummyHistogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleOffset(xAxisOffset); xAxis->SetTitleSize(0.065); xAxis->SetLabelSize(0.055); xAxis->SetLabelOffset(0.01); xAxis->SetTickLength(0.055); xAxis->SetNdivisions(505); TAxis* yAxis = dummyHistogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleOffset(yAxisOffset); yAxis->SetTitleSize(0.070); yAxis->SetLabelSize(0.055); yAxis->SetLabelOffset(0.01); yAxis->SetTickLength(0.055); yAxis->SetNdivisions(505); graph->SetMarkerColor(1); graph->SetLineColor(1); graph->Draw("p"); canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( useLogScaleY ) outputFileName_plot.append("_log"); else outputFileName_plot.append("_linear"); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); //canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); //canvas->Print(std::string(outputFileName_plot).append(".root").data()); delete dummyHistogram; delete canvas; }
void OnlineGUI::TreeDraw(vector <TString> command) { // Called by DoDraw(), this will plot a Tree Variable TString var = command[0]; // Combine the cuts (definecuts and specific cuts) TCut cut = ""; TString tempCut; if(command.size()>1) { tempCut = command[1]; vector <TString> cutIdents = fConfig->GetCutIdent(); for(UInt_t i=0; i<cutIdents.size(); i++) { if(tempCut.Contains(cutIdents[i])) { TString cut_found = (TString)fConfig->GetDefinedCut(cutIdents[i]); tempCut.ReplaceAll(cutIdents[i],cut_found); } } cut = (TCut)tempCut; } // Determine which Tree the variable comes from, then draw it. UInt_t iTree; if(command[4].IsNull()) { iTree = GetTreeIndex(var); } else { iTree = GetTreeIndexFromName(command[4]); } TString drawopt = command[2]; Int_t errcode=0; if(drawopt.IsNull() && var.Contains(":")) drawopt = "box"; if(drawopt=="scat") drawopt = ""; if (iTree <= fRootTree.size() ) { errcode = fRootTree[iTree]->Draw(var,cut,drawopt, 1000000000,fTreeEntries[iTree]); TObject *hobj = (TObject*)gROOT->FindObject("htemp"); if(errcode==-1) { BadDraw(var+" not found"); } else if (errcode!=0) { if(!command[3].IsNull()) { TH1* thathist = (TH1*)hobj; thathist->SetTitle(command[3]); } } else { BadDraw("Empty Histogram"); } } else { BadDraw(var+" not found"); if (fConfig->IsMonitor()){ // Maybe we missed it... look again. I dont like the code // below... maybe I can come up with something better GetFileObjects(); GetRootTree(); GetTreeVars(); } } }
void QAoccupancy(const Char_t *fdata, const Char_t *fmc) { style(); TFile *fdtin = TFile::Open(fdata); TList *ldtin = (TList *)fdtin->Get("clist"); TH2 *hdtin = (TH2 *)ldtin->FindObject("NClustersSPD2"); TProfile *pdtin = hdtin->ProfileY("pdtin_clusters"); pdtin->SetMarkerStyle(20); pdtin->SetMarkerSize(2); pdtin->SetMarkerColor(kAzure-3); TFile *fmcin = TFile::Open(fmc); TList *lmcin = (TList *)fmcin->Get("clist"); TH2 *hmcin = (TH2 *)lmcin->FindObject("NClustersSPD2"); TProfile *pmcin = hmcin->ProfileY("pmcin_clusters"); pmcin->SetMarkerStyle(25); pmcin->SetMarkerSize(2); pmcin->SetMarkerColor(kRed+1); TCanvas *c = new TCanvas("cOccupancy", "cOccupancy", 800, 800); c->SetLogy(); TH1 * hfr = c->DrawFrame(-0.5, 2., 10.5, 500.); DrawBinLabelsX(hfr, kTRUE); hfr->SetTitle(";;#LT#it{N}_{clusters,SPD-1}#GT"); pdtin->DrawCopy("same"); pmcin->DrawCopy("same"); TLegend *legend = new TLegend(0.20, 0.18, 0.50, 0.30); legend->SetFillColor(0); legend->SetBorderSize(0); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->AddEntry(pdtin, "data", "pl"); legend->AddEntry(pmcin, "Monte Carlo", "pl"); legend->Draw("same"); c->SaveAs(canvasPrefix+"occupancy.pdf"); return; TCanvas *cr = new TCanvas("cOccupancyr", "cOccupancyr", 800, 800); // hfr = cr->DrawFrame(-0.5, 0.75, 10.5, 1.25); // DrawBinLabelsX(hfr, kTRUE); // hfr->SetTitle(";;#LT#it{N}_{clusters,SPD-1}#GT ratio"); pdtin->SetLineColor(kAzure-3); pdtin->SetLineWidth(3); pdtin->Divide(pmcin); pdtin->Draw("same,histo"); legend = new TLegend(0.505025, 0.760673, 0.805276, 0.930142); legend->SetFillColor(0); legend->SetBorderSize(0); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->AddEntry(pdtin, "data / Monte Carlo", "l"); legend->Draw("same"); cr->SaveAs(canvasPrefix+"occupancyr.pdf"); }
void compareDYTemplates(TString baseURL="~/scratch0/top-newjec/syst_plotter.root") { TString ch[]={"ee","mumu"}; TString categs[]={"eq1jets",""}; for(size_t ich=0; ich<2; ich++) { for(size_t icat=0; icat<2; icat++) { TObjArray lowMet = getDistributionFromPlotter(ch[ich]+"_"+categs[icat]+"lowmetdilarccosine",baseURL); TH1 *lowMetH = (TH1 *) ((TList *)lowMet.At(3))->At(3); formatPlot(lowMetH,1,1,1,24,0,false,false,1,1,1); lowMetH->SetTitle("E_{T}^{miss}<30 GeV/c^{2}"); lowMetH->Scale(1./lowMetH->Integral()); TObjArray highMet = getDistributionFromPlotter(ch[ich]+"_"+categs[icat]+"dilarccosine",baseURL); TH1 *highMetH = (TH1 *) ((TList *)highMet.At(3))->At(3); formatPlot(highMetH,1,1,1,20,0,false,false,1,1,1); highMetH->SetTitle("E_{T}^{miss}>30 GeV/c^{2}"); highMetH->Scale(1./highMetH->Integral()); TString channelTitle(ich==0 ? "ee" : "#mu#mu"); if(categs[icat]=="eq1jets") channelTitle += "+ 1 jet"; else channelTitle += "+ #geq 2 jets"; //draw TString plot(ch[ich]+categs[icat]+"_anglecomparison"); TCanvas *cnv = getNewCanvas(plot+"c",plot+"c",false); cnv->Clear(); cnv->SetWindowSize(600,600); cnv->cd(); TList *mc = new TList; mc->Add(lowMetH); TList *data = new TList; data->Add(highMetH); TList *spimpose = new TList; TLegend *leg=showPlotsAndMCtoDataComparison(cnv,*mc,*spimpose,*data,false); TPad *p=(TPad *)cnv->cd(1); formatForCmsPublic(p,leg,"CMS simulation, " + channelTitle, 4); cnv->SaveAs(plot+".C"); cnv->SaveAs(plot+".pdf"); cnv->SaveAs(plot+".png"); } } }
/** * Create ratios to other data * * @param ib Bin number * @param res Result * @param alice ALICE result if any * @param cms CMS result if any * @param all Stack to add ratio to */ void Ratio2Stack(Int_t ib, TH1* res, TGraph* alice, TGraph* cms, THStack* all) { if (!all || !res || !(alice || cms)) return; Int_t off = 5*ib; TGraph* gs[] = { (alice ? alice : cms), (alice ? cms : 0), 0 }; TGraph** pg = gs; while (*pg) { TGraph* g = *pg; const char* n = (g == alice ? "ALICE" : "CMS"); TH1* r = static_cast<TH1*>(res->Clone(Form("ratio%s", n))); TString tit(r->GetTitle()); tit.ReplaceAll("Corrected", Form("Ratio to %s", n)); r->SetTitle(tit); r->SetMarkerColor(g->GetMarkerColor()); r->SetLineColor(g->GetLineColor()); TObject* tst = r->FindObject("legend"); if (tst) r->GetListOfFunctions()->Remove(tst); for (Int_t i = 1; i <= r->GetNbinsX(); i++) { Double_t c = r->GetBinContent(i); Double_t e = r->GetBinError(i); Double_t o = g->Eval(r->GetBinCenter(i)); if (o < 1e-12) { r->SetBinContent(i, 0); r->SetBinError(i, 0); continue; } r->SetBinContent(i, (c - o) / o + off); r->SetBinError(i, e / o); } all->Add(r); pg++; } TLegend* leg = StackLegend(all); if (!leg) return; TString txt = res->GetTitle(); txt.ReplaceAll("Corrected P(#it{N}_{ch}) in ", ""); if (ib == 0) txt.Append(" "); // (#times1)"); // else if (ib == 1) txt.Append(" (#times10)"); else txt.Append(Form(" (+%d)", off)); TObject* dummy = 0; TLegendEntry* e = leg->AddEntry(dummy, txt, "p"); e->SetMarkerStyle(res->GetMarkerStyle()); e->SetMarkerSize(res->GetMarkerSize()); e->SetMarkerColor(kBlack); e->SetFillColor(0); e->SetFillStyle(0); e->SetLineColor(kBlack); }
void plotter::draw_output_stat(TH1* output_, TH1* stat_, TH1D* truth_, bool norm, TString file_name){ // std::vector<double> sys = get_sys_errors(); // TH1* output_sys = add_error_bar(output, sys); TH1* output = (TH1*) output_->Clone("output"); TH1* stat = (TH1*) stat_->Clone("stat"); TH1D* truth = (TH1D*) truth_->Clone("truth"); TCanvas *c = new TCanvas("c","",600,600); double ymax; gPad->SetLeftMargin(0.15); if(truth->GetMaximum() > output->GetMaximum()) ymax = 1.5 * truth->GetMaximum(); else ymax = 1.5 * output->GetMaximum(); TGaxis::SetMaxDigits(3); output->SetTitle(" "); output->GetYaxis()->SetRangeUser(0., ymax); output->GetXaxis()->SetTitle("Leading-jet mass [GeV]"); if(norm) output->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]"); else output->GetYaxis()->SetTitle("events"); output->GetYaxis()->SetTitleOffset(1.1); output->GetXaxis()->SetTitleOffset(0.9); output->GetYaxis()->SetTitleSize(0.05); output->GetXaxis()->SetTitleSize(0.05); output->GetYaxis()->SetNdivisions(505); output->SetLineColor(kBlack); output->SetMarkerColor(kBlack); output->SetMarkerStyle(8); output->SetMarkerSize(1); output->Draw("E1"); stat->SetLineColor(kBlack); stat->SetMarkerColor(kBlack); stat->SetMarkerStyle(8); stat->SetMarkerSize(1); gStyle->SetEndErrorSize(5); truth->SetLineWidth(3); truth->SetLineColor(kRed); truth->SetLineStyle(2); truth->Draw("HIST SAME"); stat->Draw("E1 SAME"); output->Draw("E1 SAME"); TLegend *l=new TLegend(0.5,0.65,0.85,0.85); l->SetBorderSize(0); l->SetFillStyle(0); l->AddEntry(output,"data unfolded","pl"); l->AddEntry(truth,"MC particle level","pl"); l->SetTextSize(0.04); l->Draw(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
void DrawSkippable(TTree* tree, const char* what, const char* where, Bool_t draw = true) { //cerr << "Doing " << what << " which is " << skip << endl; if (draw) { TString cut = what; cut.Append(">>"); cut.Append(where); tree->Draw(cut.Data(),"","goff"); TH1* h = (TH1*)gDirectory->FindObject(where); if (h) h->SetTitle(Form("histo made from T->Draw(\"%s\")",what)); } else { gSkipped.Add(new TNamed(where,where)); } };
TH1* makeCDF(TH1* h) { TString sName(TString(h->GetName())+TString("_CDF")); TString sTitle(TString(h->GetTitle())+TString(" CDF")); TH1* hOut = (TH1*) h->Clone(sName); hOut->SetTitle(sTitle); hOut->Reset(); double cdf = 0; for (int ibin=0; ibin < h->GetNbinsX()+2; ++ibin) { cdf += h->GetBinContent(ibin); hOut->SetBinContent(ibin,cdf); } hOut->Scale(1.0/(h->Integral(0,h->GetNbinsX()+1))); return hOut; }
void plotter::draw_delta(TH1* hist_, TString file_name){ TH1* hist = (TH1*) hist_->Clone("hist"); TCanvas *c= new TCanvas("Particle Level","",600,600); gPad->SetLeftMargin(0.15); hist->SetTitle(file_name); hist->GetXaxis()->SetTitle("Leading-jet mass [GeV]"); hist->GetYaxis()->SetTitle("#Delta events"); hist->GetYaxis()->SetTitleOffset(1.5); hist->GetYaxis()->SetNdivisions(505); hist->SetFillColor(810); hist->SetLineColor(810); hist->Draw("HIST"); gPad->RedrawAxis(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
//____________________________________________________________________ TH1* One(TDirectory* newDir, TDirectory* oldDir, Double_t c1, Double_t c2) { TString name; name.Form("cent%03dd%02d_%03dd%02d", Int_t(c1), Int_t(c1*100)%100, Int_t(c2), Int_t(c2*100)%100); TDirectory* newSubDir = GetD(newDir, name); TDirectory* oldSubDir = GetD(oldDir, name); if (!newSubDir || !oldSubDir) return 0; Int_t newDim = 0; if (TString(newDir->GetName()).Contains("etaipz")) newDim = 3; else if (TString(newDir->GetName()).Contains("eta")) newDim = 2; else if (TString(newDir->GetName()).Contains("const")) newDim = 1; Int_t oldDim = 0; if (TString(oldDir->GetName()).Contains("etaipz")) oldDim = 3; else if (TString(oldDir->GetName()).Contains("eta")) oldDim = 2; else if (TString(oldDir->GetName()).Contains("const")) oldDim = 1; TDirectory* newSubSubDir = GetD(newSubDir, Form("results%dd",newDim)); TDirectory* oldSubSubDir = GetD(oldSubDir, Form("results%dd",oldDim)); if (!newSubSubDir || !oldSubSubDir) return 0; TH1* newRes = GetH1(newSubSubDir, "result"); TH1* oldRes = GetH1(oldSubSubDir, "result"); if (!newRes || !oldRes) return 0; TH1* ratio = static_cast<TH1*>(newRes->Clone(name)); ratio->SetDirectory(0); ratio->SetTitle(Form("%5.1f - %5.1f%%", c1, c2)); ratio->SetYTitle("New / Old"); ratio->Divide(oldRes); fMin = TMath::Min(fMin, ratio->GetMinimum()); fMax = TMath::Max(fMax, ratio->GetMaximum()); Printf("Calculated %s/%s", newDir->GetName(), oldDir->GetName()); if (!fLegend) return ratio; TLegendEntry* e = fLegend->AddEntry("", Form("%3.0f - %3.0f%%", c1, c2), "f"); e->SetFillStyle(1001); e->SetFillColor(ratio->GetMarkerColor()); return ratio; }
TH1 *PullHisto(const TList *list, const char *name, Int_t min, Int_t max, Double_t &mean) { THnSparse *hs = list->FindObject(name); if (!hs) return 0; TAxis *atmp = hs->GetAxis(1); atmp->SetRange(min, max); // !!!!!!!!!!!!!!!!!!!! hs->GetAxis(2)->SetRangeUser(-0.5, 0.5); TH1 *hfin = hs->Projection(0); hfin->SetTitle(Form("p_{t} #in (%4.2f, %4.2f) GeV/c", atmp->GetBinLowEdge(min), atmp->GetBinLowEdge(max) + atmp->GetBinWidth(max))); mean = atmp->GetBinLowEdge(min) + (atmp->GetBinLowEdge(max) + atmp->GetBinWidth(max) - atmp->GetBinLowEdge(min))/2.0; // !!!!!!!!!!!!!!!!!!!! return hfin;//->Rebin(); }
void DrawHijing50GeV() { TCanvas *c1 = new TCanvas(); TFile *fin = TFile::Open("Gamma_Neutron_Hijing_Energy_Graphs.root"); gROOT->cd(); TH1 *hjbkg = (TH1 *) fin->Get("hjbkg")->Clone(); TGraph *anti_neutron50GeV = (TGraph *) fin->Get("anti_neutron50GeV")->Clone(); TGraph *neutron50GeV = (TGraph *) fin->Get("neutron50GeV")->Clone(); hjbkg->SetStats(0); hjbkg->SetLineColor(6); hjbkg->SetMaximum(5.5); hjbkg->SetLineWidth(2); hjbkg->SetTitle("50 GeV Hadronic Showers with HIJING background"); hjbkg->GetYaxis()->SetTitle("Deposited Energey [GeV]"); hjbkg->GetYaxis()->SetTitleOffset(0.8); hjbkg->GetXaxis()->SetTitle("cone size (#sqrt{#Delta#Phi^{2}+#Delta#Theta^{2}})"); hjbkg->GetXaxis()->SetTitleOffset(1.2); hjbkg->Draw(); anti_neutron50GeV->SetLineColor(4); anti_neutron50GeV->SetLineWidth(2); anti_neutron50GeV->Draw("same"); neutron50GeV->SetLineColor(2); neutron50GeV->SetLineWidth(2); neutron50GeV->Draw("same"); TLine *tl = new TLine(); tl->SetLineStyle(2); tl->DrawLine(0.1,0,0.1,5.5); TLegend *legrda = new TLegend(0.67,0.54,0.87,0.74,NULL,"brNDC"); legrda->SetLineColor(1); legrda->SetLineStyle(1); legrda->SetLineWidth(1); legrda->SetFillColor(10); legrda->SetFillStyle(1001); legrda->SetBorderSize(0); // legrda->SetTextSize(labelsize); legrda->AddEntry(hjbkg,"HIJING bkg"); legrda->AddEntry(anti_neutron50GeV, "50 GeV Anti Neutron","l"); legrda->AddEntry(neutron50GeV, "50 GeV Neutron", "l"); legrda->AddEntry(tl, "HCal tower size","l"); legrda->Draw(); fin->Close(); c1->Print("Hijing50GeV.png"); }
void drawTimeDifference (TDirectory* directory, TH1* refHisto, const char* fname=0) { TGraphErrors* graphX = (TGraphErrors*)directory->Get("x"); if ( graphX==0 ) return; TH1I* hFirst = (TH1I*)directory->Get("firstTime"); TH1I* hLast = (TH1I*)directory->Get("lastTime"); if ( hFirst==0 || hLast==0 ) return; std::string fullName("cDeltaT"); if ( fname ) fullName += fname; else fullName += directory->GetName(); TCanvas* c = new TCanvas(fullName.c_str(),fullName.c_str()); TH1* h = refHisto->Clone("DeltaT"); h->Reset(); h->SetTitle("DeltaT"); TGraph* graph = new TGraph(); graph->SetName("gDeltaT"); double xg,yg; for ( unsigned int i=1; i<=hFirst->GetNbinsX(); ++i ) { std::time_t t1 = hFirst->GetAt(i); std::time_t t2 = hLast->GetAt(i); TTimeStamp ts1(hFirst->GetAt(i)); std::cout << "Fit started at " << ts1.AsString() << std::endl; graphX->GetPoint(i-1,xg,yg); graph->SetPoint(i-1,xg,difftime(t2,t1)); } double xmin,xmax,ymin,ymax; graph->ComputeRange(xmin,ymin,xmax,ymax); h->SetMinimum(0.); h->SetMaximum((ymax+ymin)/2.+2.*(ymax-ymin)/2.); h->Draw(); graph->SetMarkerStyle(20); // graph->SetMarkerColor(2); // graph->SetLineColor(2); graph->Draw("P"); }
// Called just after the main event loop // Can be used to write things out, dump a summary etc // Return non-zero to indicate a problem int IslandAmplitude::AfterLastEntry(TGlobalData* gData,const TSetupData *setup){ // Print extra info if we're debugging this module: if(Debug()){ cout<<"-----IslandAmplitude::AfterLastEntry(): I'm debugging!"<<endl; } double run_norm = fAmpNorm->Integral(0,-1); for(mapSH_t::iterator it = fAmpHist.begin(); it != fAmpHist.end(); ++it) { TH1F* h = it->second; TObject* obj = h->Clone((std::string(h->GetName()) + "_RunNorm").c_str()); TH1* hn = static_cast<TH1*>(obj); hn->SetTitle((std::string(h->GetTitle()) + " (run normalized)").c_str()); hn->Scale(1.0/run_norm); } for(mapSH_t::iterator it = fAmpHistNorm.begin(); it != fAmpHistNorm.end(); ++it) it->second->Scale(1.0/fNProcessed); return 0; }
void axesStyle(TH1& hist, const char* titleX, const char* titleY, float yMin, float yMax, float yTitleSize, float yTitleOffset) { hist.SetTitle(""); hist.GetXaxis()->SetTitle(titleX); hist.GetXaxis()->CenterTitle(); hist.GetXaxis()->SetTitleSize ( 0.06); hist.GetXaxis()->SetTitleColor ( 1); hist.GetXaxis()->SetTitleOffset( 1.0); hist.GetXaxis()->SetTitleFont ( 62); hist.GetXaxis()->SetLabelSize ( 0.05); hist.GetXaxis()->SetLabelFont ( 62); hist.GetXaxis()->SetNdivisions ( 505); hist.GetYaxis()->SetTitle(titleY); hist.GetYaxis()->SetTitleSize ( yTitleSize ); hist.GetYaxis()->SetTitleColor ( 1); hist.GetYaxis()->SetTitleOffset(yTitleOffset); hist.GetYaxis()->SetTitleFont ( 62); hist.GetYaxis()->SetLabelSize ( 0.04); hist.GetYaxis()->SetLabelFont ( 62); hist.GetYaxis()->CenterTitle ( true); if(yMin!=-123) hist.SetMinimum(yMin); if(yMax!=-123) hist.SetMaximum(yMax); }
void drawEventDifference (TDirectory* directory, TH1* refHisto, const char* fname=0) { TGraphErrors* graphX = (TGraphErrors*)directory->Get("x"); if ( graphX==0 ) return; TH1I* hFirst = (TH1I*)directory->Get("firstEvent"); TH1I* hLast = (TH1I*)directory->Get("lastEvent"); if ( hFirst==0 || hLast==0 ) return; std::string fullName("cDeltaE"); if ( fname ) fullName += fname; else fullName += directory->GetName(); TCanvas* c = new TCanvas(fullName.c_str(),fullName.c_str()); TH1* h = refHisto->Clone("DeltaE"); h->Reset(); h->SetTitle("DeltaE"); TGraph* graph = new TGraph(); graph->SetName("gDeltaE"); double xg,yg; for ( unsigned int i=1; i<=hFirst->GetNbinsX(); ++i ) { int e1 = hFirst->GetAt(i); int e2 = hLast->GetAt(i); graphX->GetPoint(i-1,xg,yg); graph->SetPoint(i-1,xg,e2-e1); } double xmin,xmax,ymin,ymax; graph->ComputeRange(xmin,ymin,xmax,ymax); h->SetMinimum(0.); h->SetMaximum((ymax+ymin)/2.+2.*(ymax-ymin)/2.); h->Draw(); graph->SetMarkerStyle(20); // graph->SetMarkerColor(2); // graph->SetLineColor(2); graph->Draw("P"); }
void QCD_MC_test(){ TString basepath = "/uscms/home/aperloff/nobackup/Summer12ME8TeV/MEInput/"; vector<TString> fnames; vector<double> scaleFactors; fnames.push_back("QCD_EM_20to30.root" ); scaleFactors.push_back(2.886e+08/3504052.0); fnames.push_back("QCD_EM_30to80.root" ); scaleFactors.push_back(7.433e+07/3308873.0); fnames.push_back("QCD_EM_80to170.root" ); scaleFactors.push_back(1.191e+06/3447258.0); fnames.push_back("QCD_EM_170to250.root"); scaleFactors.push_back( 30990.0/3169702.0); fnames.push_back("QCD_EM_250to350.root"); scaleFactors.push_back( 4250.0/3461112.0); fnames.push_back("QCD_EM_350.root" ); scaleFactors.push_back( 810.0/3408046.0); TCanvas * c = new TCanvas("sf","sf", 1200,800); c->Divide(fnames.size()/2,2); for (int h=0;h<fnames.size();h++){ c->cd(h+1); TH1* aux = processFile(basepath+fnames[h], scaleFactors[h]); aux->SetTitle(fnames[h]); aux->Draw("E"); } }//QCD_MC_test
void plotter::draw_matrix(TH2* hist_, TString file_name, bool zlog, bool is_migration){ TH1* hist = (TH1*) hist_->Clone("hist"); TCanvas *c= new TCanvas("c","",600,600); gPad->SetRightMargin(0.15); gPad->SetLeftMargin(0.15); if(zlog) gPad->SetLogz(); hist->SetTitle(" "); hist->GetXaxis()->SetTitleOffset(1.1); hist->GetYaxis()->SetTitleOffset(1.5); if(is_migration){ hist->GetXaxis()->SetTitle("generator binning"); hist->GetYaxis()->SetTitle("detector binning"); } else{ hist->GetXaxis()->SetTitle("Leading-jet mass [GeV]"); hist->GetYaxis()->SetTitle("Leading-jet mass [GeV]"); } hist->Draw("COLZ"); hist->Draw("BOX SAME"); c->SaveAs(directory + file_name + ".pdf"); delete c; }
void patBJetTracks_efficiencies() { // define proper canvas style setNiceStyle(); gStyle->SetOptStat(0); // open file TFile* file = new TFile("analyzePatBJetTracks.root"); TLegend *legend[3] = { 0, 0, 0 }; // draw canvas with efficiencies TCanvas *canv; canv = new TCanvas("canv0", "hand-crafted track counting efficiencies", 800, 300); canv->Divide(3, 1); TH1 *total = (TH1*)file->Get(Form("%s/flavours", directory)); TH1 *effVsCutB = 0; unsigned int i = 0; for(const char **flavour = flavours; *flavour; flavour++, i++) { TH1 *h = (TH1*)file->Get(Form("%s/trackIPSig_%s", directory, *flavour)); TH1 *discrShape = (TH1*)h->Clone(Form("%s_discrShape", h->GetName())); discrShape->Scale(1.0 / discrShape->Integral()); discrShape->SetMaximum(discrShape->GetMaximum() * 5); TH1 *effVsCut = computeEffVsCut(h, total->GetBinContent(4 - i)); TH1 *effVsBEff = 0; if (flavour == flavours) // b-jets effVsCutB = effVsCut; else effVsBEff = computeEffVsBEff(effVsCut, effVsCutB); discrShape->SetTitle("discriminator shape"); effVsCut->SetTitle("efficiency versus discriminator cut"); if (effVsBEff) effVsBEff->SetTitle("mistag versus b efficiency"); setHistStyle(discrShape); setHistStyle(effVsCut); setHistStyle(effVsBEff); canv->cd(1); gPad->SetLogy(1); gPad->SetGridy(1); discrShape->SetLineColor(i + 1); discrShape->SetMarkerColor(i + 1); discrShape->Draw(i > 0 ? "same" : ""); if (!legend[0]) legend[0] = new TLegend(0.5, 0.7, 0.78, 0.88); legend[0]->AddEntry(discrShape, *flavour); canv->cd(2); gPad->SetLogy(1); gPad->SetGridy(1); effVsCut->SetLineColor(i + 1); effVsCut->SetMarkerColor(i + 1); effVsCut->Draw(i > 0 ? "same" : ""); if (!legend[1]) legend[1] = new TLegend(0.12, 0.12, 0.40, 0.30); legend[1]->AddEntry(effVsCut, *flavour); if (!effVsBEff) continue; canv->cd(3); gPad->SetLogy(1); gPad->SetGridx(1); gPad->SetGridy(1); effVsBEff->SetLineColor(i + 1); effVsBEff->SetMarkerColor(i + 1); effVsBEff->Draw(i > 1 ? "same" : ""); if (!legend[2]) legend[2] = new TLegend(0.12, 0.7, 0.40, 0.88); legend[2]->AddEntry(effVsBEff, *flavour); } canv->cd(1); legend[0]->Draw(); canv->cd(2); legend[1]->Draw(); canv->cd(3); legend[2]->Draw(); //////////////////////////////////////////// // canvas to compare negative tagger with light flavour mistag TCanvas *canv; canv = new TCanvas("canv1", "comparing light flavour mistag with negative tagger", 530, 300); canv->Divide(2, 1); TH1 *h1 = (TH1*)file->Get(Form("%s/trackIPSig_udsg", directory)); TH1 *h2 = (TH1*)file->Get(Form("%s/negativeIPSig_all", directory)); h2 = invertHisto(h2); // invert x-axis TH1 *discrShape1 = (TH1*)h1->Clone("discrShape1"); TH1 *discrShape2 = (TH1*)h2->Clone("discrShape2"); discrShape1->Scale(1.0 / discrShape1->Integral()); discrShape1->SetMaximum(discrShape1->GetMaximum() * 5); discrShape2->Scale(1.0 / discrShape2->Integral()); TH1 *effVsCut1 = computeEffVsCut(h1, total->GetBinContent(2)); TH1 *effVsCut2 = computeEffVsCut(h2, total->GetBinContent(1)); discrShape1->SetTitle("discriminator shape"); effVsCut1->SetTitle("efficiency versus discriminator cut"); setHistStyle(discrShape1); setHistStyle(discrShape2); setHistStyle(effVsCut1); setHistStyle(effVsCut2); canv->cd(1); gPad->SetLogy(1); gPad->SetGridy(1); discrShape1->SetLineColor(1); discrShape1->SetMarkerColor(1); discrShape2->SetLineColor(2); discrShape2->SetMarkerColor(2); discrShape1->Draw(); discrShape2->Draw("same"); TLegend *l = new TLegend(0.5, 0.7, 0.78, 0.88); l->AddEntry(discrShape1, "udsg"); l->AddEntry(discrShape2, "inv. neg"); l->Draw(); canv->cd(2); gPad->SetLogy(1); gPad->SetGridy(1); effVsCut1->SetLineColor(1); effVsCut1->SetMarkerColor(1); effVsCut2->SetLineColor(2); effVsCut2->SetMarkerColor(2); effVsCut1->Draw(); effVsCut2->Draw("same"); l = new TLegend(0.5, 0.7, 0.78, 0.88); l->AddEntry(effVsCut1, "udsg"); l->AddEntry(effVsCut2, "inv. neg"); l->Draw(); }
void FFT() { //This tutorial illustrates the Fast Fourier Transforms interface in ROOT. //FFT transform types provided in ROOT: // - "C2CFORWARD" - a complex input/output discrete Fourier transform (DFT) // in one or more dimensions, -1 in the exponent // - "C2CBACKWARD"- a complex input/output discrete Fourier transform (DFT) // in one or more dimensions, +1 in the exponent // - "R2C" - a real-input/complex-output discrete Fourier transform (DFT) // in one or more dimensions, // - "C2R" - inverse transforms to "R2C", taking complex input // (storing the non-redundant half of a logically Hermitian array) // to real output // - "R2HC" - a real-input DFT with output in ¡Èhalfcomplex¡É format, // i.e. real and imaginary parts for a transform of size n stored as // r0, r1, r2, ..., rn/2, i(n+1)/2-1, ..., i2, i1 // - "HC2R" - computes the reverse of FFTW_R2HC, above // - "DHT" - computes a discrete Hartley transform // Sine/cosine transforms: // DCT-I (REDFT00 in FFTW3 notation) // DCT-II (REDFT10 in FFTW3 notation) // DCT-III(REDFT01 in FFTW3 notation) // DCT-IV (REDFT11 in FFTW3 notation) // DST-I (RODFT00 in FFTW3 notation) // DST-II (RODFT10 in FFTW3 notation) // DST-III(RODFT01 in FFTW3 notation) // DST-IV (RODFT11 in FFTW3 notation) //First part of the tutorial shows how to transform the histograms //Second part shows how to transform the data arrays directly //Authors: Anna Kreshuk and Jens Hoffmann //********* Histograms ********// //prepare the canvas for drawing TCanvas *myc = new TCanvas("myc", "Fast Fourier Transform", 800, 600); myc->SetFillColor(45); TPad *c1_1 = new TPad("c1_1", "c1_1",0.01,0.67,0.49,0.99); TPad *c1_2 = new TPad("c1_2", "c1_2",0.51,0.67,0.99,0.99); TPad *c1_3 = new TPad("c1_3", "c1_3",0.01,0.34,0.49,0.65); TPad *c1_4 = new TPad("c1_4", "c1_4",0.51,0.34,0.99,0.65); TPad *c1_5 = new TPad("c1_5", "c1_5",0.01,0.01,0.49,0.32); TPad *c1_6 = new TPad("c1_6", "c1_6",0.51,0.01,0.99,0.32); c1_1->Draw(); c1_2->Draw(); c1_3->Draw(); c1_4->Draw(); c1_5->Draw(); c1_6->Draw(); c1_1->SetFillColor(30); c1_1->SetFrameFillColor(42); c1_2->SetFillColor(30); c1_2->SetFrameFillColor(42); c1_3->SetFillColor(30); c1_3->SetFrameFillColor(42); c1_4->SetFillColor(30); c1_4->SetFrameFillColor(42); c1_5->SetFillColor(30); c1_5->SetFrameFillColor(42); c1_6->SetFillColor(30); c1_6->SetFrameFillColor(42); c1_1->cd(); TH1::AddDirectory(kFALSE); //A function to sample TF1 *fsin = new TF1("fsin", "sin(x)*sin(x)/(x*x)", 0, 4*TMath::Pi()); fsin->Draw(); Int_t n=25; TH1D *hsin = new TH1D("hsin", "hsin", n+1, 0, 4*TMath::Pi()); Double_t x; //Fill the histogram with function values for (Int_t i=0; i<=n; i++){ x = (Double_t(i)/n)*(4*TMath::Pi()); hsin->SetBinContent(i+1, fsin->Eval(x)); } hsin->Draw("same"); fsin->GetXaxis()->SetLabelSize(0.05); fsin->GetYaxis()->SetLabelSize(0.05); c1_2->cd(); //Compute the transform and look at the magnitude of the output TH1 *hm =0; TVirtualFFT::SetTransform(0); hm = hsin->FFT(hm, "MAG"); hm->SetTitle("Magnitude of the 1st transform"); hm->Draw(); //NOTE: for "real" frequencies you have to divide the x-axes range with the range of your function //(in this case 4*Pi); y-axes has to be rescaled by a factor of 1/SQRT(n) to be right: this is not done automatically! hm->SetStats(kFALSE); hm->GetXaxis()->SetLabelSize(0.05); hm->GetYaxis()->SetLabelSize(0.05); c1_3->cd(); //Look at the phase of the output TH1 *hp = 0; hp = hsin->FFT(hp, "PH"); hp->SetTitle("Phase of the 1st transform"); hp->Draw(); hp->SetStats(kFALSE); hp->GetXaxis()->SetLabelSize(0.05); hp->GetYaxis()->SetLabelSize(0.05); //Look at the DC component and the Nyquist harmonic: Double_t re, im; //That's the way to get the current transform object: TVirtualFFT *fft = TVirtualFFT::GetCurrentTransform(); c1_4->cd(); //Use the following method to get just one point of the output fft->GetPointComplex(0, re, im); printf("1st transform: DC component: %f\n", re); fft->GetPointComplex(n/2+1, re, im); printf("1st transform: Nyquist harmonic: %f\n", re); //Use the following method to get the full output: Double_t *re_full = new Double_t[n]; Double_t *im_full = new Double_t[n]; fft->GetPointsComplex(re_full,im_full); //Now let's make a backward transform: TVirtualFFT *fft_back = TVirtualFFT::FFT(1, &n, "C2R M K"); fft_back->SetPointsComplex(re_full,im_full); fft_back->Transform(); TH1 *hb = 0; //Let's look at the output hb = TH1::TransformHisto(fft_back,hb,"Re"); hb->SetTitle("The backward transform result"); hb->Draw(); //NOTE: here you get at the x-axes number of bins and not real values //(in this case 25 bins has to be rescaled to a range between 0 and 4*Pi; //also here the y-axes has to be rescaled (factor 1/bins) hb->SetStats(kFALSE); hb->GetXaxis()->SetLabelSize(0.05); hb->GetYaxis()->SetLabelSize(0.05); delete fft_back; fft_back=0; //********* Data array - same transform ********// //Allocate an array big enough to hold the transform output //Transform output in 1d contains, for a transform of size N, //N/2+1 complex numbers, i.e. 2*(N/2+1) real numbers //our transform is of size n+1, because the histogram has n+1 bins Double_t *in = new Double_t[2*((n+1)/2+1)]; Double_t re_2,im_2; for (Int_t i=0; i<=n; i++){ x = (Double_t(i)/n)*(4*TMath::Pi()); in[i] = fsin->Eval(x); } //Make our own TVirtualFFT object (using option "K") //Third parameter (option) consists of 3 parts: //-transform type: // real input/complex output in our case //-transform flag: // the amount of time spent in planning // the transform (see TVirtualFFT class description) //-to create a new TVirtualFFT object (option "K") or use the global (default) Int_t n_size = n+1; TVirtualFFT *fft_own = TVirtualFFT::FFT(1, &n_size, "R2C ES K"); if (!fft_own) return; fft_own->SetPoints(in); fft_own->Transform(); //Copy all the output points: fft_own->GetPoints(in); //Draw the real part of the output c1_5->cd(); TH1 *hr = 0; hr = TH1::TransformHisto(fft_own, hr, "RE"); hr->SetTitle("Real part of the 3rd (array) tranfsorm"); hr->Draw(); hr->SetStats(kFALSE); hr->GetXaxis()->SetLabelSize(0.05); hr->GetYaxis()->SetLabelSize(0.05); c1_6->cd(); TH1 *him = 0; him = TH1::TransformHisto(fft_own, him, "IM"); him->SetTitle("Im. part of the 3rd (array) transform"); him->Draw(); him->SetStats(kFALSE); him->GetXaxis()->SetLabelSize(0.05); him->GetYaxis()->SetLabelSize(0.05); myc->cd(); //Now let's make another transform of the same size //The same transform object can be used, as the size and the type of the transform //haven't changed TF1 *fcos = new TF1("fcos", "cos(x)+cos(0.5*x)+cos(2*x)+1", 0, 4*TMath::Pi()); for (Int_t i=0; i<=n; i++){ x = (Double_t(i)/n)*(4*TMath::Pi()); in[i] = fcos->Eval(x); } fft_own->SetPoints(in); fft_own->Transform(); fft_own->GetPointComplex(0, re_2, im_2); printf("2nd transform: DC component: %f\n", re_2); fft_own->GetPointComplex(n/2+1, re_2, im_2); printf("2nd transform: Nyquist harmonic: %f\n", re_2); delete fft_own; delete [] in; delete [] re_full; delete [] im_full; }
/////////////////////////////////////////////////////////////////// //////// Go4 GUI example script addhistos.C // J.Adamczewski, gsi, May 2006 // JAM May 2015: added support for 2d histograms // NOTE: to be run in Go4 GUI local command line only! // NEVER call this script in remote analysis process!!! /////// Functionality: // adds histogram of name2 to histogram of name1 /////// Usage: // histogram name2 will be scaled by factor. // (e.g. if factor==-1, his2 is substracted from his1) // The draw flag switches if the results are displayed each time this makro is called // if display is switched off, the result histogram is just updated in browser and existing displays /////// Bool_t addhistos(const char* name1, const char* name2, Double_t factor, Bool_t draw) { if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) { std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl; return kFALSE; } TString fullname1 = go4->FindItem(name1); TObject* ob1=go4->GetObject(fullname1,1000); // 1000=timeout to get object from analysis in ms TH1 *his1(0), *his2(0); if(ob1 && ob1->InheritsFrom("TH1")) his1 = (TH1*) ob1; if(his1==0) { std::cout <<"addhistos could not get histogram "<<fullname1 << std::endl; return kFALSE; } TString fullname2 = go4->FindItem(name2); TObject* ob2=go4->GetObject(fullname2,1000); // 1000=timeout to get object from analysis in ms if(ob2 && ob2->InheritsFrom("TH1")) his2 = (TH1*)ob2; if(his2==0) { std::cout <<"addhistos could not get histogram "<<fullname2 << std::endl; return kFALSE; } if((his1->GetDimension()) != (his2->GetDimension())) { std::cout <<"addhistos could not add histograms of different dimensions "<< std::endl; return kFALSE; } TH1* result = (TH1*) his1->Clone(); TString n1 = his1->GetName(); TString n2 = his2->GetName(); TString t1 = his1->GetTitle(); TString t2 = his2->GetTitle(); TString soper; if(factor>0) soper.Form(") + %4.1E * (",factor); else soper.Form(") - %4.1E * (",-1*factor); TString finalname = TString("(")+n1+soper+n2+")"; TString finaltitle = TString("(")+t1+soper+t2+")"; result->SetName(finalname); result->SetTitle(finaltitle); result->Sumw2(); result->Add(his2,factor); result->SetDirectory(0); TString rname = go4->SaveToMemory("Sums", result, kTRUE); std::cout<< "Saved result histogram to " << rname.Data() <<std::endl; if(draw) { ViewPanelHandle vpanel = go4->StartViewPanel(); if(result->GetDimension()>1) { // superimpose mode is not supported for 2d histograms go4->DrawItem(rname, vpanel); } else { go4->SetSuperimpose(vpanel,kTRUE); go4->DrawItem(fullname1, vpanel); go4->DrawItem(fullname2, vpanel); go4->DrawItem(rname, vpanel); } } return kTRUE; }
// input: - Input file (result from TMVA) // - use of TMVA plotting TStyle void mvas( TString fin = "TMVA.root", HistType htype = MVAType, Bool_t useTMVAStyle = kTRUE ) { // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); // switches const Bool_t Save_Images = kTRUE; // checks if file with name "fin" is already open, and if not opens one TFile* file = TMVAGlob::OpenFile( fin ); // define Canvas layout here! Int_t xPad = 1; // no of plots in x Int_t yPad = 1; // no of plots in y Int_t noPad = xPad * yPad ; const Int_t width = 600; // size of canvas // this defines how many canvases we need TCanvas *c = 0; // counter variables Int_t countCanvas = 0; // search for the right histograms in full list of keys TIter next(file->GetListOfKeys()); TKey *key(0); while ((key = (TKey*)next())) { if (!TString(key->GetName()).BeginsWith("Method_")) continue; if( ! gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory") ) continue; TString methodName; TMVAGlob::GetMethodName(methodName,key); TDirectory* mDir = (TDirectory*)key->ReadObj(); TIter keyIt(mDir->GetListOfKeys()); TKey *titkey; while ((titkey = (TKey*)keyIt())) { if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue; TDirectory *titDir = (TDirectory *)titkey->ReadObj(); TString methodTitle; TMVAGlob::GetMethodTitle(methodTitle,titDir); cout << "--- Found directory for method: " << methodName << "::" << methodTitle << flush; TString hname = "MVA_" + methodTitle; if (htype == ProbaType ) hname += "_Proba"; else if (htype == RarityType ) hname += "_Rarity"; TH1* sig = dynamic_cast<TH1*>(titDir->Get( hname + "_S" )); TH1* bgd = dynamic_cast<TH1*>(titDir->Get( hname + "_B" )); if (sig==0 || bgd==0) { if (htype == MVAType) cout << "mva distribution not available (this is normal for Cut classifier)" << endl; else if(htype == ProbaType) cout << "probability distribution not available (this is normal for Cut classifier)" << endl; else if(htype == RarityType) cout << "rarity distribution not available (this is normal for Cut classifier)" << endl; else if(htype == CompareType) cout << "overtraining check not available (this is normal for Cut classifier)" << endl; else cout << endl; } else { cout << endl; // chop off useless stuff sig->SetTitle( Form("TMVA response for classifier: %s", methodTitle.Data()) ); if (htype == ProbaType) sig->SetTitle( Form("TMVA probability for classifier: %s", methodTitle.Data()) ); else if (htype == RarityType) sig->SetTitle( Form("TMVA Rarity for classifier: %s", methodTitle.Data()) ); else if (htype == CompareType) sig->SetTitle( Form("TMVA overtraining check for classifier: %s", methodTitle.Data()) ); // create new canvas TString ctitle = ((htype == MVAType) ? Form("TMVA response %s",methodTitle.Data()) : (htype == ProbaType) ? Form("TMVA probability %s",methodTitle.Data()) : (htype == CompareType) ? Form("TMVA comparison %s",methodTitle.Data()) : Form("TMVA Rarity %s",methodTitle.Data())); TString cname = ((htype == MVAType) ? Form("output_%s",methodTitle.Data()) : (htype == ProbaType) ? Form("probability_%s",methodTitle.Data()) : (htype == CompareType) ? Form("comparison_%s",methodTitle.Data()) : Form("rarity_%s",methodTitle.Data())); c = new TCanvas( Form("canvas%d", countCanvas+1), ctitle, countCanvas*50+200, countCanvas*20, width, (Int_t)width*0.78 ); // set the histogram style TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd ); // normalise both signal and background TMVAGlob::NormalizeHists( sig, bgd ); // frame limits (choose judicuous x range) Float_t nrms = 4; cout << "--- Mean and RMS (S): " << sig->GetMean() << ", " << sig->GetRMS() << endl; cout << "--- Mean and RMS (B): " << bgd->GetMean() << ", " << bgd->GetRMS() << endl; Float_t xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), bgd->GetMean() - nrms*bgd->GetRMS() ), sig->GetXaxis()->GetXmin() ); Float_t xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), bgd->GetMean() + nrms*bgd->GetRMS() ), sig->GetXaxis()->GetXmax() ); Float_t ymin = 0; Float_t maxMult = (htype == CompareType) ? 1.3 : 1.2; Float_t ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*maxMult; // build a frame Int_t nb = 500; TString hFrameName(TString("frame") + methodTitle); TObject *o = gROOT->FindObject(hFrameName); if(o) delete o; TH2F* frame = new TH2F( hFrameName, sig->GetTitle(), nb, xmin, xmax, nb, ymin, ymax ); frame->GetXaxis()->SetTitle( methodTitle + ((htype == MVAType || htype == CompareType) ? " response" : "") ); if (htype == ProbaType ) frame->GetXaxis()->SetTitle( "Signal probability" ); else if (htype == RarityType ) frame->GetXaxis()->SetTitle( "Signal rarity" ); frame->GetYaxis()->SetTitle("Normalized"); TMVAGlob::SetFrameStyle( frame ); // eventually: draw the frame frame->Draw(); c->GetPad(0)->SetLeftMargin( 0.105 ); frame->GetYaxis()->SetTitleOffset( 1.2 ); // Draw legend TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12, c->GetLeftMargin() + (htype == CompareType ? 0.40 : 0.3), 1 - c->GetTopMargin() ); legend->SetFillStyle( 1 ); legend->AddEntry(sig,TString("Signal") + ((htype == CompareType) ? " (test sample)" : ""), "F"); legend->AddEntry(bgd,TString("Background") + ((htype == CompareType) ? " (test sample)" : ""), "F"); legend->SetBorderSize(1); legend->SetMargin( (htype == CompareType ? 0.2 : 0.3) ); legend->Draw("same"); // overlay signal and background histograms sig->Draw("samehist"); bgd->Draw("samehist"); if (htype == CompareType) { // if overtraining check, load additional histograms TH1* sigOv = 0; TH1* bgdOv = 0; TString ovname = hname += "_Train"; sigOv = dynamic_cast<TH1*>(titDir->Get( ovname + "_S" )); bgdOv = dynamic_cast<TH1*>(titDir->Get( ovname + "_B" )); if (sigOv == 0 || bgdOv == 0) { cout << "+++ Problem in \"mvas.C\": overtraining check histograms do not exist" << endl; } else { cout << "--- Found comparison histograms for overtraining check" << endl; TLegend *legend2= new TLegend( 1 - c->GetRightMargin() - 0.42, 1 - c->GetTopMargin() - 0.12, 1 - c->GetRightMargin(), 1 - c->GetTopMargin() ); legend2->SetFillStyle( 1 ); legend2->SetBorderSize(1); legend2->AddEntry(sigOv,"Signal (training sample)","P"); legend2->AddEntry(bgdOv,"Background (training sample)","P"); legend2->SetMargin( 0.1 ); legend2->Draw("same"); } Int_t col = sig->GetLineColor(); sigOv->SetMarkerColor( col ); sigOv->SetMarkerSize( 0.7 ); sigOv->SetMarkerStyle( 20 ); sigOv->SetLineWidth( 1 ); sigOv->SetLineColor( col ); sigOv->Draw("e1same"); col = bgd->GetLineColor(); bgdOv->SetMarkerColor( col ); bgdOv->SetMarkerSize( 0.7 ); bgdOv->SetMarkerStyle( 20 ); bgdOv->SetLineWidth( 1 ); bgdOv->SetLineColor( col ); bgdOv->Draw("e1same"); ymax = TMath::Max( ymax, TMath::Max( sigOv->GetMaximum(), bgdOv->GetMaximum() )*maxMult ); frame->GetYaxis()->SetLimits( 0, ymax ); // for better visibility, plot thinner lines sig->SetLineWidth( 1 ); bgd->SetLineWidth( 1 ); // perform K-S test cout << "--- Perform Kolmogorov-Smirnov tests" << endl; Double_t kolS = sig->KolmogorovTest( sigOv ); Double_t kolB = bgd->KolmogorovTest( bgdOv ); cout << "--- Goodness of signal (background) consistency: " << kolS << " (" << kolB << ")" << endl; TString probatext = Form( "Kolmogorov-Smirnov test: signal (background) probability = %5.3g (%5.3g)", kolS, kolB ); TText* tt = new TText( 0.12, 0.74, probatext ); tt->SetNDC(); tt->SetTextSize( 0.032 ); tt->AppendPad(); } // redraw axes frame->Draw("sameaxis"); // text for overflows Int_t nbin = sig->GetNbinsX(); Double_t dxu = sig->GetBinWidth(0); Double_t dxo = sig->GetBinWidth(nbin+1); TString uoflow = Form( "U/O-flow (S,B): (%.1f, %.1f)%% / (%.1f, %.1f)%%", sig->GetBinContent(0)*dxu*100, bgd->GetBinContent(0)*dxu*100, sig->GetBinContent(nbin+1)*dxo*100, bgd->GetBinContent(nbin+1)*dxo*100 ); TText* t = new TText( 0.975, 0.115, uoflow ); t->SetNDC(); t->SetTextSize( 0.030 ); t->SetTextAngle( 90 ); t->AppendPad(); // update canvas c->Update(); // save canvas to file TMVAGlob::plot_logo(1.058); if (Save_Images) { if (htype == MVAType) TMVAGlob::imgconv( c, Form("plots/mva_%s", methodTitle.Data()) ); else if (htype == ProbaType) TMVAGlob::imgconv( c, Form("plots/proba_%s", methodTitle.Data()) ); else if (htype == CompareType) TMVAGlob::imgconv( c, Form("plots/overtrain_%s", methodTitle.Data()) ); else TMVAGlob::imgconv( c, Form("plots/rarity_%s", methodTitle.Data()) ); } countCanvas++; } } } }