void help() { new TCanvas("chelp","Help on gldemos",200,10,700,600); TPaveLabel *title = new TPaveLabel(0.04, 0.86, 0.96, 0.98, "These demos show different gl painters."); title->SetFillColor(32); title->Draw(); TPaveText *hdemo = new TPaveText(0.04, 0.04, 0.96, 0.8); hdemo->SetTextAlign(12); hdemo->SetTextFont(52); hdemo->SetTextColor(kBlue); hdemo->AddText("1. Glsurfaces demo shows glsurf4, glsurf1, glsurf3, glsurf1cyl, glsurfpol, gltf3 options."); hdemo->AddText("2. Glrose demontrates \"glsurf2pol\" drawing option and user-defined palette."); hdemo->AddText("3. Gltf3 demo shows \"gltf3\" option."); hdemo->AddText("4. Glbox demo shows \"glbox\" and \"glbox1\" options for TH3."); hdemo->AddText("5. Glparametric demo shows how to define and display parametric surfaces."); hdemo->AddText("You can zoom any plot: press 'J', 'K', 'j', 'k' keys, or use mouse wheel."); hdemo->AddText("Rotate any plot:"); hdemo->AddText(" ---select plot with mouse cursor,"); hdemo->AddText(" ---move mouse cursor, pressing and holding left mouse button "); hdemo->AddText("Pan plot:"); hdemo->AddText(" ---select with mouse cursor a part of a plot, other than back box planes ,"); hdemo->AddText(" ---move mouse cursor, pressing and holding middle mouse button "); hdemo->AddText("Selected part of a plot is higlighted (TF3 higlighting is not implemented yet.)"); hdemo->AddText("You can select one of back box planes, press middle mouse button and move cursor-"); hdemo->AddText("this will create \"slice\" (TF does not support yet)."); hdemo->AddText("After the slice was created, you can project it on a back box"); hdemo->AddText(" ---press key 'p' (now implemented only for surf options )."); hdemo->AddText("Left double click removes all slices/projections."); hdemo->Draw(); }
TCanvas *ellipse(){ TCanvas *c1 = new TCanvas("c1"); c1->Range(0,0,1,1); TPaveLabel *pel = new TPaveLabel(0.1,0.8,0.9,0.95,"Examples of Ellipses"); pel->SetFillColor(42); pel->Draw(); TEllipse *el1 = new TEllipse(0.25,0.25,.1,.2); el1->Draw(); TEllipse *el2 = new TEllipse(0.25,0.6,.2,.1); el2->SetFillColor(6); el2->SetFillStyle(3008); el2->Draw(); TEllipse *el3 = new TEllipse(0.75,0.6,.2,.1,45,315); el3->SetFillColor(2); el3->SetFillStyle(1001); el3->SetLineColor(4); el3->Draw(); TEllipse *el4 = new TEllipse(0.75,0.25,.2,.15,45,315,62); el4->SetFillColor(5); el4->SetFillStyle(1001); el4->SetLineColor(4); el4->SetLineWidth(6); el4->Draw(); return c1; }
void draw_input_labels(Int_t nInputs, Double_t* cy, Double_t rad, Double_t layerWidth) { const Double_t LABEL_HEIGHT = 0.03; const Double_t LABEL_WIDTH = 0.20; Double_t width = LABEL_WIDTH + (layerWidth-4*rad); Double_t margX = 0.01; Double_t effHeight = 0.8*LABEL_HEIGHT; TString *varNames = get_var_names(nInputs); if (varNames == 0) exit(1); TString input; for (Int_t i = 0; i < nInputs; i++) { if (i != nInputs-1) input = varNames[i]; else input = "Bias node"; Double_t x1 = margX; Double_t x2 = margX + width; Double_t y1 = cy[i] - effHeight; Double_t y2 = cy[i] + effHeight; TPaveLabel *p = new TPaveLabel(x1, y1, x2, y2, input+"", "br"); p->SetFillColor(gStyle->GetTitleFillColor()); p->SetFillStyle(1001); p->Draw(); if (i == nInputs-1) p->SetTextColor( TMVAGlob::c_NovelBlue ); } delete[] varNames; }
//Draw arrows //Author: Rene Brun TCanvas *arrow(){ TCanvas *c1 = new TCanvas("c1"); c1->Range(0,0,1,1); TPaveLabel *par = new TPaveLabel(0.1,0.8,0.9,0.95,"Examples of various arrow formats"); par->SetFillColor(42); par->Draw(); TArrow *ar1 = new TArrow(0.1,0.1,0.1,0.7); ar1->Draw(); TArrow *ar2 = new TArrow(0.2,0.1,0.2,0.7,0.05,"|>"); ar2->SetAngle(40); ar2->SetLineWidth(2); ar2->Draw(); TArrow *ar3 = new TArrow(0.3,0.1,0.3,0.7,0.05,"<|>"); ar3->SetAngle(40); ar3->SetLineWidth(2); ar3->Draw(); TArrow *ar4 = new TArrow(0.46,0.7,0.82,0.42,0.07,"|>"); ar4->SetAngle(60); ar4->SetLineWidth(2); ar4->SetFillColor(2); ar4->Draw(); TArrow *ar5 = new TArrow(0.4,0.25,0.95,0.25,0.15,"<|>"); ar5->SetAngle(60); ar5->SetLineWidth(4); ar5->SetLineColor(4); ar5->SetFillStyle(3008); ar5->SetFillColor(2); ar5->Draw(); return c1; }
void glbox() { gStyle->SetCanvasPreferGL(kTRUE); TCanvas *c = new TCanvas("glc","TH3 Drawing", 100, 10, 850, 400); TPaveLabel *title = new TPaveLabel(0.04, 0.86, 0.96, 0.98, "\"glbox\" and \"glbox1\" options for TH3."); title->SetFillColor(32); title->Draw(); TPad *boxPad = new TPad("box", "box", 0.02, 0.02, 0.48, 0.82); TPad *box1Pad = new TPad("box1", "box1", 0.52, 0.02, 0.98, 0.82); boxPad->Draw(); box1Pad->Draw(); TH3F *h31 = new TH3F("h31", "h31", 10, -1, 1, 10, -1, 1, 10, -1, 1); h31->FillRandom("gaus"); h31->SetFillColor(2); boxPad->cd(); h31->Draw("glbox"); TH3F *h32 = new TH3F("h32", "h32", 10, -2, 2, 10, -1, 1, 10, -3, 3); h32->FillRandom("gaus"); h32->SetFillColor(4); box1Pad->cd(); h32->Draw("glbox1"); }
void testRoot() { //Fill a 1-D histogram from a parametric function // To see the output of this macro, click begin_html <a href="gif/fillrandom.gif">here</a>. end_html //Author: Rene Brun TCanvas *c1 = new TCanvas("c1","The FillRandom example",200,10,700,900); c1->SetFillColor(18); TPad* pad1 = new TPad("pad1","The pad with the function",0.05,0.50,0.95,0.95,21); TPad* pad2 = new TPad("pad2","The pad with the histogram",0.05,0.05,0.95,0.45,21); pad1->Draw(); pad2->Draw(); pad1->cd(); gBenchmark->Start("fillrandom"); // // A function (any dimension) or a formula may reference // an already defined formula // TFormula* form1 = new TFormula("form1","abs(sin(x)/x)"); TF1* sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10); sqroot->SetParameters(10,4,1,20); pad1->SetGridx(); pad1->SetGridy(); pad1->GetFrame()->SetFillColor(42); pad1->GetFrame()->SetBorderMode(-1); pad1->GetFrame()->SetBorderSize(5); sqroot->SetLineColor(4); sqroot->SetLineWidth(6); sqroot->Draw(); TPaveLabel* lfunction = new TPaveLabel(5,39,9.8,46,"The sqroot function"); lfunction->SetFillColor(41); lfunction->Draw(); c1->Update(); // // Create a one dimensional histogram (one float per bin) // and fill it following the distribution in function sqroot. // pad2->cd(); pad2->GetFrame()->SetFillColor(42); pad2->GetFrame()->SetBorderMode(-1); pad2->GetFrame()->SetBorderSize(5); TH1F* h1f = new TH1F("h1f","Test random numbers",200,0,10); h1f->SetFillColor(45); h1f->FillRandom("sqroot",10000); h1f->Draw(); c1->Update(); // // Open a ROOT file and save the formula, function and histogram // TFile myfile("fillrandom.root","RECREATE"); form1->Write(); sqroot->Write(); h1f->Write(); gBenchmark->Show("fillrandom"); }
//////////////////////////////////////////////////////////// // // This function performs a compatibility test between two // histogram based on the Kolmogorov-Smirnof algorithm. It // also prints the value in a TPaveLabel at the upper-right // corner. // The return value contains the result of the test // double KolmogorovTest(TH1 *h1, TH1 *h2){ double mya_array[1300], myb_array[1300]; vector<double> mya; vector<double> myb; for (int i=0; i<h1->GetNbinsX(); i++){ mya.push_back(h1->GetBinContent(i+1)); myb.push_back(h2->GetBinContent(i+1)); } sort(mya.begin(),mya.end()); sort(myb.begin(),myb.end()); copy(mya.begin(),mya.end(),mya_array); copy(myb.begin(),myb.end(),myb_array); const int nbinsa = h1->GetNbinsX(); const int nbinsb = h2->GetNbinsX(); double kstest = TMath::KolmogorovTest(nbinsa, mya_array, nbinsb, myb_array, "UOX"); if (DEBUGP) cout << " + KS value = " << kstest << endl; // Create text with the value TString legend = Form("KS=%4.2f", kstest); // Create a pave text to put the value inside TPaveLabel* pl = new TPaveLabel(0.79,0.91,0.93,0.96, legend.Data(), "NDC"); // Tune style //pl->SetTextSize(0.04); pl->SetLineColor(41); pl->SetLineWidth(1); pl->SetLineStyle(1); pl->SetFillColor(41); pl->SetBorderSize(3); if (kstest < 0.7) pl->SetTextColor(kRed); pl->Draw(); return kstest; }
void DoFit(const char* fitter, TVirtualPad *pad, Int_t npass) { TStopwatch timer; TVirtualFitter::SetDefaultFitter(fitter); pad->SetGrid(); fitFcn->SetParameters(100,0,0,2,7); fitFcn->Update(); timer.Start(); histo->Fit("fitFcn","0"); timer.Stop(); histo->Draw(); Double_t cputime = timer.CpuTime(); printf("%s, npass=%d : RT=%7.3f s, Cpu=%7.3f s\n",fitter,npass,timer.RealTime(),cputime); TPaveLabel *p = new TPaveLabel(0.5,0.7,0.85,0.8,Form("%s CPU= %g s",fitter,cputime),"brNDC"); p->Draw(); pad->Update(); }
void first() { TCanvas *nut = new TCanvas("nut", "FirstSession",100,10,700,900); nut->Range(0,0,20,24); nut->SetFillColor(10); nut->SetBorderSize(2); TPaveLabel *pl = new TPaveLabel(3,22,17,23.7, "My first ROOT interactive session","br"); pl->SetFillColor(18); pl->Draw(); TText t(0,0,"a"); t.SetTextFont(62); t.SetTextSize(0.025); t.SetTextAlign(12); t.DrawText(2,20.3,"ROOT is based on CINT, a powerful C/C++ interpreter."); t.DrawText(2,19.3,"Blocks of lines can be entered within {...}."); t.DrawText(2,18.3,"Previous typed lines can be recalled."); t.SetTextFont(72); t.SetTextSize(0.026); t.DrawText(3,17,"Root > float x=5; float y=7;"); t.DrawText(3,16,"Root > x*sqrt(y)"); t.DrawText(3,14, "Root > for (int i=2;i<7;i++) printf(\"sqrt(%d) = %f\\n\",i,sqrt(i));"); t.DrawText(3,10,"Root > TF1 f1(\"f1\",\"sin(x)/x\",0,10)"); t.DrawText(3, 9,"Root > f1.Draw()"); t.SetTextFont(81); t.SetTextSize(0.018); t.DrawText(4,15,"(float) 13.2288f"); t.DrawText(4,13.3,"sqrt(2) = 1.414214"); t.DrawText(4,12.7,"sqrt(3) = 1.732051"); t.DrawText(4,12.1,"sqrt(4) = 2.000000"); t.DrawText(4,11.5,"sqrt(5) = 2.236068"); t.DrawText(4,10.9,"sqrt(6) = 2.449490"); TPad *pad = new TPad("pad","pad",.2,.05,.8,.35); pad->Draw(); pad->cd(); pad->SetGrid(); TF1 *f1 = new TF1("f1","sin(x)/x",0,10); f1->Draw(); }
// Render a TF2 looking like a rose. // Author: Timur Pocheptsov void glrose() { //Define and set user's palette, //use polar system. const Int_t paletteSize = 10; Float_t rgb[paletteSize * 3] = {0.80f, 0.55f, 0.40f, 0.85f, 0.60f, 0.45f, 0.90f, 0.65f, 0.50f, 0.95f, 0.70f, 0.55f, 1.f, 0.75f, 0.60f, 1.f, 0.80f, 0.65f, 1.f, 0.85f, 0.70f, 1.f, 0.90f, 0.75f, 1.f, 0.95f, 0.80f, 1.f, 1.f, 0.85f}; Int_t palette[paletteSize] = {0}; for (Int_t i = 0; i < paletteSize; ++i) palette[i] = TColor::GetColor(rgb[i * 3], rgb[i * 3 + 1], rgb[i * 3 + 2]); gStyle->SetPalette(paletteSize, palette); gStyle->SetCanvasPreferGL(1); TCanvas *cnv = new TCanvas("glc", "Surface sample", 200, 10, 600, 550); TPaveLabel *title = new TPaveLabel(0.04, 0.86, 0.96, 0.98, "\"glsurf2pol\" option + user defined palette."); title->SetFillColor(32); title->Draw(); TPad *rosePad = new TPad("box", "box", 0.04, 0.04, 0.96, 0.8); rosePad->Draw(); TF2 *fun = new TF2("a", "cos(y)*sin(x)+cos(x)*sin(y)", -6, 6, -6, 6); fun->SetContour(paletteSize); fun->SetNpx(30); fun->SetNpy(30); rosePad->cd(); fun->Draw("glsurf2pol"); }
void draw_layer_labels(Int_t nLayers) { const Double_t LABEL_HEIGHT = 0.03; const Double_t LABEL_WIDTH = 0.20; Double_t effWidth = 0.8*(1.0-LABEL_WIDTH)/nLayers; Double_t height = 0.8*LABEL_HEIGHT; Double_t margY = LABEL_HEIGHT - height; for (Int_t i = 0; i < nLayers; i++) { TString label = Form("Layer %i", i); Double_t cx = i*(1.0-LABEL_WIDTH)/nLayers+1.0/(2.0*nLayers)+LABEL_WIDTH; Double_t x1 = cx-0.8*effWidth/2.0; Double_t x2 = cx+0.8*effWidth/2.0; Double_t y1 = margY; Double_t y2 = margY + height; TPaveLabel *p = new TPaveLabel(x1, y1, x2, y2, label+"", "br"); p->SetFillColor(gStyle->GetTitleFillColor()); p->SetFillStyle(1001); p->Draw(); } }
void show ( char* inpDir = "", // MuDST directory char* inpFile = "show.lis", // MuDST file(s); char* outFile = "show.root",// output tree file Int_t nFiles = 50, // # of MuDST file(s) Int_t nEvents = 100 // # of events ) // remeber to adjust dbase timestamp below !!!! // what a ... design { //gErrorIgnoreLevel=1999; // load root/root4star libraries gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C"); loadSharedLibraries(); // load more libraries :) gSystem->Load("libmysqlclient"); gSystem->Load("libGeom"); gSystem->Load("StDbLib"); gSystem->Load("StDbBroker"); gSystem->Load("St_db_Maker"); // load even more libraries (EEMC stuff) gSystem->Load("StEEmcUtil"); gSystem->Load("StEEmcDbMaker"); gSystem->Load("StEEmcPoolTTM"); // create the chain chain = new StChain("StChain"); // now = new TDatime; // for display TCanvas *c1 = new TCanvas("eemc","eemc",10,10,1000,1000); TPaveLabel *tlab = new TPaveLabel(-0.99,+0.99,+0.99,+0.90, "EEMC TOWERS & TPC TRACKS Piotr A Zolnierczuk (IU)"); eventInfo = new TPaveText (-0.99,-0.99,+0.0 ,-0.75); dateInfo = new TPaveLabel(+0.60,-0.99,+0.99,-0.95,now->AsString()); TGeoManager *gm = new TGeoManager("eemc", "eemc tower display"); TGeoVolume *top = gm->MakeBox("star",0, 200., 200., 350.); TGeoVolume *smbox = gm->MakeBox("smbox1",0, 2., 2., 2.); smbox->SetLineColor(kRed); // eemc eemc = new EEmcTTDisplay(); eemc->SetMagneticField(0.5); // in Tesla eemc->SetShowExtrapolatedTracks(true); TGeoTranslation *etra = new TGeoTranslation(0.0,0.0,0.5*(eemc->getZ1()+eemc->getZ2())); top->AddNode(smbox, 1,NULL); top->AddNode(eemc(),1,etra); gm->SetTopVolume(top); gm->CloseGeometry(); gm->SetVisLevel(4); gm->SetVisOption(0); c1->SetTheta(90); c1->SetPhi(0); top->Draw(); tlab->Draw(); gPad->Update(); // now we add Makers to the chain... some of that is black magic :) muDstMk = new StMuDstMaker(0,0,inpDir,inpFile,"",nFiles); // muDST main chain StMuDbReader *db = StMuDbReader::instance(); // need the database St_db_Maker *dbMk = new St_db_Maker("StarDb", "MySQL:StarDb"); // need another db(?) new StEEmcDbMaker("eemcDb"); // need EEMC database // now comment in/out/change the below if you want it your way dbMk->setTimeStampDay(20040331); // format: yyyymmdd // finally after so many lines we arrive at the good stuff ttm = new EEmcTTMMaker ("TTM",muDstMk,eemcDbMk); ttm->Summary(cout); // StMuDebug::setLevel(0); chain->Init(); StEEmcDb *eemcDb = (StEEmcDb*)chain->GetDataSet("StEEmcDb"); eemcDb->setSectors(1,12); // request EEMC DB for sectors you need (dafault:1-12) eemcDb->setPreferedFlavor("onlped","eemcPMTped"); // request alternative flavor chain->ls(3); //--------------------------------------------------- next(); }
void zlljets_ZpT_recoGenAna(const string fmumuName = "zmumujets_resoResp_noSkim_light.root", const string feeName = "zeejets_resoResp_noSkim_light.root", const char* suffix = "") { TH1::SetDefaultSumw2(); string plotDirectoryPath = "/cmshome/ciprianim/CMSSW721/pdfsFromAnalysis/plots/ZtoLLSamples/ZpTAnalysis/"; //string plotDirectoryPath = "./tmpPlots/"; used when working in my pc string plotFileExtension = ".pdf"; // index 0 of array is for muons, index 1 is for electrons, thus recoZpt[0] refers to Z->mumu ((maybe it will be better to change it) vector<string> fileName; fileName.push_back(fmumuName); fileName.push_back(feeName); vector<string> sample; sample.push_back("Z(#mu#mu)+jets"); sample.push_back("Z(ee)+jets"); vector<TH1D*> hZpTreco; vector<TH1D*> hZpTgen; vector<TH1D*> hZpTrecoGenRatio; vector<TH1D*> hZpTrecoGenRatio_pdf; Int_t nFiles = (Int_t)fileName.size(); Int_t histColor[] = {kBlue,kOrange,kRed,kGreen}; Double_t zptStart = 400.0; Double_t zptEnd = 800.0; TH1D *HZtoLLPt_RecoGenRatio_pdf_inRange[2]; for(Int_t i = 0; i < 2; i++) { HZtoLLPt_RecoGenRatio_pdf_inRange[i] = new TH1D(Form("HZtoLLPt_RecoGenRatio_pdf_%d_Zpt%2.0lfTo%2.0lf",i+1,zptStart,zptEnd),"",100,0.5,1.5); } for(Int_t i = 0; i < nFiles; i++) { cout<<"fileName : "<<fileName[i]<<endl; TFile* f = TFile::Open(fileName[i].c_str(),"READ"); if (!f || !f->IsOpen()) { cout<<"*******************************"<<endl; cout<<"Error opening file \""<<fileName[i]<<"\".\nApplication will be terminated."<<endl; cout<<"*******************************"<<endl; exit(EXIT_FAILURE); } hZpTreco.push_back((TH1D*)f->Get("HZtoLLRecoPt")); hZpTgen.push_back((TH1D*)f->Get("HZtoLLGenPt")); hZpTrecoGenRatio.push_back((TH1D*)f->Get("HZtoLLPt_RecoGenRatio")); hZpTrecoGenRatio_pdf.push_back((TH1D*)f->Get("HZtoLLPt_RecoGenRatio_pdf")); if ( !(hZpTreco[i] && hZpTgen[i] && hZpTrecoGenRatio[i] && hZpTrecoGenRatio_pdf[i] ) ) { cout << "Error: could not get histograms from file " << fileName[i] << endl; exit(EXIT_FAILURE); } } Int_t startingBin = hZpTrecoGenRatio[0]->FindBin(zptStart) ; // will consider ratio pdf for Zpt > 600 GeV (they should be equal for Z->ee and Z->nunu) Int_t endingBin = hZpTrecoGenRatio[0]->FindBin(zptEnd) ; // will consider ratio pdf for Zpt < 1000 GeV (they should be equal for Z->ee and Z->nunu) cout << "ZpT bins from "<<startingBin<<" to "<<endingBin<< endl; for (Int_t j = 0; j < 2; j++) { for (Int_t i = startingBin; i < endingBin; i++) { HZtoLLPt_RecoGenRatio_pdf_inRange[j]->Fill(hZpTrecoGenRatio[j]->GetBinContent(i)); } HZtoLLPt_RecoGenRatio_pdf_inRange[j]->Scale(1./HZtoLLPt_RecoGenRatio_pdf_inRange[j]->Integral(0,1 + HZtoLLPt_RecoGenRatio_pdf_inRange[j]->GetNbinsX())); } // note that this distribution will be almost empty because it's the distribution of the mean of various ZpT points. //cout << " **************** check ************** " << endl; for (Int_t j = 0; j < nFiles; j++) { hZpTreco[j]->SetStats(kFALSE); // to avoid drawing statistic box hZpTreco[j]->SetLineColor(histColor[j]); // no need to use TH1::Scale() between reco and gen of Z->mumu or Z->ee, because histogram are filled for the same set of events, so integral // should be the same in principle //hZpTreco[j]->SetFillColorAlpha(histColor[j], 0.80); hZpTgen[j]->SetStats(kFALSE); // to avoid drawing statistic box hZpTgen[j]->SetLineColor(histColor[j+2]); hZpTrecoGenRatio[j]->SetStats(kFALSE); //hZpTrecoGenRatio[j]->SetLineColor(histColor[j]); hZpTrecoGenRatio_pdf[j]->SetStats(kFALSE); hZpTrecoGenRatio_pdf[j]->SetLineColor(histColor[j+2]); HZtoLLPt_RecoGenRatio_pdf_inRange[j]->SetStats(kFALSE); HZtoLLPt_RecoGenRatio_pdf_inRange[j]->SetLineColor(histColor[j*2]); } TPad *subpad1 = NULL; // will use it to access specific subpad in canvas TPad *subpad2 = NULL; TCanvas *cZtomumuPtRecoGen = new TCanvas("cZtomumuPtRecoGen","",700,700); TLegend *legZtomumuPtRecoGen = new TLegend(0.70,0.7,0.89,0.89); subpad1 = new TPad("pad1","",0.0,0.36,1.0,1.0); subpad1->SetLogy(); subpad1->SetBottomMargin(0); subpad2 = new TPad("pad2","",0.0,0.0,1.0,0.36); subpad2->SetGrid(); subpad2->SetTopMargin(0); subpad2->SetBottomMargin(0.2); subpad1->Draw(); subpad2->Draw(); //cout <<"Drawing histograms and ratio"<<endl; subpad1->cd(); // hZpTreco[0]->GetXaxis()->SetTitle("Z_{pT}[GeV]"); // hZpTreco[0]->GetXaxis()->SetTitleSize(0.04); //hZpTreco[0]->GetXaxis()->SetLabelSize(0.04); hZpTreco[0]->GetYaxis()->SetTitle("# events"); hZpTreco[0]->GetYaxis()->SetTitleSize(0.04); hZpTreco[0]->GetYaxis()->SetLabelSize(0.04); hZpTreco[0]->GetYaxis()->CenterTitle(); //hZpTreco[0]->GetYaxis()->SetLabelSize(0.04); hZpTreco[0]->Draw("HE"); hZpTgen[0]->Draw("HE SAME"); legZtomumuPtRecoGen->AddEntry(hZpTreco[0],"Z(#mu#mu) reco","l"); legZtomumuPtRecoGen->AddEntry(hZpTgen[0],"Z(#mu#mu) gen","l"); gStyle->SetStatStyle(0); legZtomumuPtRecoGen->Draw(); legZtomumuPtRecoGen->SetMargin(0.3); legZtomumuPtRecoGen->SetBorderSize(0); subpad2->cd(); hZpTrecoGenRatio[0]->GetXaxis()->SetLabelSize(0.08); hZpTrecoGenRatio[0]->GetXaxis()->SetTitle("Z_{pT}[GeV]"); hZpTrecoGenRatio[0]->GetXaxis()->SetTitleSize(0.07); hZpTrecoGenRatio[0]->GetXaxis()->SetTitleOffset(1.2); hZpTrecoGenRatio[0]->GetYaxis()->SetLabelSize(0.07); hZpTrecoGenRatio[0]->GetYaxis()->SetTitle("reco/gen ZpT"); hZpTrecoGenRatio[0]->GetYaxis()->SetTitleSize(0.07); hZpTrecoGenRatio[0]->GetYaxis()->SetTitleOffset(0.5); hZpTrecoGenRatio[0]->GetYaxis()->CenterTitle(); hZpTrecoGenRatio[0]->Draw("E"); hZpTrecoGenRatio[0]->SetMarkerStyle(7); //medium dot cZtomumuPtRecoGen->SaveAs( (plotDirectoryPath + cZtomumuPtRecoGen->GetName() + suffix + plotFileExtension).c_str() ); TPad *subpad1_bis = NULL; TPad *subpad2_bis = NULL; TCanvas *cZtoeePtRecoGen = new TCanvas("cZtoeePtRecoGen","",700,700); TLegend *legZtoeePtRecoGen = new TLegend(0.70,0.7,0.89,0.89); subpad1_bis = new TPad("pad1","",0.0,0.36,1.0,1.0); subpad1_bis->SetLogy(); subpad1_bis->SetBottomMargin(0); subpad2_bis = new TPad("pad2","",0.0,0.0,1.0,0.36); subpad2_bis->SetGrid(); subpad2_bis->SetTopMargin(0); subpad2_bis->SetBottomMargin(0.2); subpad1_bis->Draw(); subpad2_bis->Draw(); //cout <<"Drawing histograms and ratio"<<endl; subpad1_bis->cd(); // hZpTreco[1]->GetXaxis()->SetTitle("Z_{pT}[GeV]"); // hZpTreco[1]->GetXaxis()->SetTitleSize(0.04); //hZpTreco[1]->GetXaxis()->SetLabelSize(0.04); hZpTreco[1]->GetYaxis()->SetTitle("# events"); hZpTreco[1]->GetYaxis()->SetTitleSize(0.04); hZpTreco[1]->GetYaxis()->SetLabelSize(0.04); hZpTreco[1]->GetYaxis()->CenterTitle(); //hZpTreco[1]->GetYaxis()->SetLabelSize(0.04); hZpTreco[1]->Draw("HE"); hZpTgen[1]->Draw("HE SAME"); legZtoeePtRecoGen->AddEntry(hZpTreco[0],"Z(ee) reco","l"); legZtoeePtRecoGen->AddEntry(hZpTgen[0],"Z(ee) gen","l"); gStyle->SetStatStyle(0); legZtoeePtRecoGen->Draw(); legZtoeePtRecoGen->SetMargin(0.3); legZtoeePtRecoGen->SetBorderSize(0); subpad2_bis->cd(); hZpTrecoGenRatio[1]->GetXaxis()->SetLabelSize(0.08); hZpTrecoGenRatio[1]->GetXaxis()->SetTitle("Z_{pT}[GeV]"); hZpTrecoGenRatio[1]->GetXaxis()->SetTitleSize(0.07); hZpTrecoGenRatio[1]->GetXaxis()->SetTitleOffset(1.2); hZpTrecoGenRatio[1]->GetYaxis()->SetLabelSize(0.07); hZpTrecoGenRatio[1]->GetYaxis()->SetTitle("reco/gen ZpT"); hZpTrecoGenRatio[1]->GetYaxis()->SetTitleOffset(0.5); hZpTrecoGenRatio[1]->GetYaxis()->SetTitleSize(0.07); hZpTrecoGenRatio[1]->GetYaxis()->CenterTitle(); hZpTrecoGenRatio[1]->Draw("E"); hZpTrecoGenRatio[1]->SetMarkerStyle(7); //medium dot cZtoeePtRecoGen->SaveAs( (plotDirectoryPath + cZtoeePtRecoGen->GetName() + suffix + plotFileExtension).c_str() ); // TCanvas *cZtoeePtRecoGen = new TCanvas("cZtoeePtRecoGen","",700,700); // TLegend *legZtoeePtRecoGen = new TLegend(0.70,0.7,0.89,0.89); // cZtoeePtRecoGen->Divide(1,2,0,0); // cZtoeePtRecoGen->cd(1); // subpad1 = (TPad*)cZtoeePtRecoGen->GetPad(1); // subpad1->SetPad(0.0,0.36,0.98,0.99); // subpad1->SetLogy(); // //cout <<"Drawing histograms and ratio"<<endl; // // hZpTreco[1]->GetXaxis()->SetTitle("Z_{pT}[GeV]"); // // hZpTreco[1]->GetXaxis()->SetTitleSize(0.04); // hZpTreco[1]->GetYaxis()->SetTitle("# events"); // hZpTreco[1]->GetYaxis()->SetTitleSize(0.045); // hZpTreco[1]->GetYaxis()->CenterTitle(); // //hZpTreco[1]->GetYaxis()->SetLabelSize(0.1); // hZpTreco[1]->Draw("HE"); // hZpTgen[1]->Draw("HE SAME"); // legZtoeePtRecoGen->AddEntry(hZpTreco[1],"Z(ee) reco","l"); // legZtoeePtRecoGen->AddEntry(hZpTgen[1],"Z(ee) gen","l"); // gStyle->SetStatStyle(0); // legZtoeePtRecoGen->Draw(); // legZtoeePtRecoGen->SetMargin(0.3); // legZtoeePtRecoGen->SetBorderSize(0); // cZtoeePtRecoGen->cd(2); // subpad2 = (TPad*)cZtoeePtRecoGen->GetPad(2); // subpad2->SetPad(0.0,0.0,0.98,0.36); // subpad2->SetGrid(); // hZpTrecoGenRatio[1]->GetXaxis()->SetLabelSize(0.08); // hZpTrecoGenRatio[1]->GetXaxis()->SetTitle("Z_{pT}[GeV]"); // hZpTrecoGenRatio[1]->GetXaxis()->SetTitleSize(0.06); // hZpTrecoGenRatio[1]->GetXaxis()->SetTitleOffset(1.2); // hZpTrecoGenRatio[1]->GetYaxis()->SetLabelSize(0.08); // hZpTrecoGenRatio[1]->Draw("E"); // hZpTrecoGenRatio[1]->SetMarkerStyle(7); //medium dot // cZtoeePtRecoGen->SaveAs( (plotDirectoryPath + cZtoeePtRecoGen->GetName() + suffix + plotFileExtension).c_str() ); // now I normalize histograms to same area (here is 1) to compare Z->mumu and Z->ee which have different numbers of events for (Int_t j = 0; j < nFiles; j++) { hZpTreco[j]->Scale(1./hZpTreco[j]->Integral(0,1 + hZpTreco[j]->GetNbinsX())); // normalize to unity, use integral including underflow & overflow bin hZpTgen[j]->Scale(1./hZpTgen[j]->Integral(0,1 + hZpTgen[j]->GetNbinsX())); hZpTrecoGenRatio_pdf[j]->Scale(1./hZpTrecoGenRatio_pdf[j]->Integral(0,1 + hZpTrecoGenRatio_pdf[j]->GetNbinsX())); } TCanvas *cZtollPtRecoGen = new TCanvas("cZtollPtRecoGen",""); TLegend *legZtollPtRecoGen = new TLegend(0.70,0.7,0.89,0.89); cZtollPtRecoGen->SetLogy(); //cout <<"Drawing histograms and ratio"<<endl; hZpTreco[0]->GetXaxis()->SetTitle("Z_{pT}[GeV]"); hZpTreco[0]->GetXaxis()->SetTitleSize(0.04); hZpTreco[0]->GetYaxis()->SetTitle("# events"); hZpTreco[0]->GetYaxis()->SetTitleSize(0.045); hZpTreco[0]->GetYaxis()->CenterTitle(); hZpTreco[0]->Draw("HE"); hZpTgen[0]->Draw("HE SAME"); hZpTreco[1]->Draw("HE SAME"); hZpTgen[1]->Draw("HE SAME"); legZtollPtRecoGen->AddEntry(hZpTreco[0],"Z(#mu#mu) reco","l"); legZtollPtRecoGen->AddEntry(hZpTgen[0],"Z(#mu#mu) gen","l"); legZtollPtRecoGen->AddEntry(hZpTreco[1],"Z(ee) reco","l"); legZtollPtRecoGen->AddEntry(hZpTgen[1],"Z(ee) gen","l"); gStyle->SetStatStyle(0); legZtollPtRecoGen->Draw(); legZtollPtRecoGen->SetMargin(0.3); legZtollPtRecoGen->SetBorderSize(0); cZtollPtRecoGen->SaveAs( (plotDirectoryPath + cZtollPtRecoGen->GetName() + suffix + plotFileExtension).c_str() ); Int_t bins; Double_t firstEdge; Double_t lastEdge; TH1D *hZpTMuEleRecoRatio; TCanvas *cZpTMuEleRecoRatio; if( hZpTreco[0]->GetNbinsX() == hZpTreco[1]->GetNbinsX() ) { bins = hZpTreco[0]->GetNbinsX(); firstEdge = hZpTreco[0]->GetXaxis()->GetBinLowEdge(1); lastEdge = hZpTreco[0]->GetXaxis()->GetBinUpEdge(bins); hZpTMuEleRecoRatio = new TH1D("hZpTMuEleRecoRatio","",bins,firstEdge,lastEdge); // cout << "hZpTreco[0]->GetNbinsX() : "<< hZpTreco[0]->GetNbinsX() << endl; // cout << "hZpTreco[1]->GetNbinsX() : "<< hZpTreco[1]->GetNbinsX() << endl; // cout << "hZpTMuEleGenRatio->GetNbinsX() : "<< hZpTMuEleGenRatio->GetNbinsX() << endl; if (!hZpTMuEleRecoRatio->Divide(hZpTreco[0],hZpTreco[1])) cout << " Error in hZpTMuEleRecoRatio->Divide(hZpTreco[0],hZpTreco[1])" << endl; hZpTMuEleRecoRatio->SetStats(kFALSE); cZpTMuEleRecoRatio = new TCanvas("cZpTMuEleRecoRatio",""); hZpTMuEleRecoRatio->GetXaxis()->SetTitle("Z_{pT}[GeV]"); hZpTMuEleRecoRatio->GetXaxis()->SetTitleSize(0.04); hZpTMuEleRecoRatio->GetYaxis()->SetTitle("reco pT_{Z(#mu#mu)} / pT_{Z(ee)} "); hZpTMuEleRecoRatio->GetYaxis()->SetTitleSize(0.045); hZpTMuEleRecoRatio->GetYaxis()->SetRangeUser(0.5,1.5); hZpTMuEleRecoRatio->GetYaxis()->CenterTitle(); hZpTMuEleRecoRatio->Draw("E"); gStyle->SetStatStyle(0); cZpTMuEleRecoRatio->SaveAs( (plotDirectoryPath + cZpTMuEleRecoRatio->GetName() + suffix + plotFileExtension).c_str() ); } TH1D *hZpTMuEleGenRatio; TCanvas *cZpTMuEleGenRatio; if (hZpTgen[0]->GetNbinsX() == hZpTgen[1]->GetNbinsX()) { bins = hZpTgen[0]->GetNbinsX(); firstEdge = hZpTgen[0]->GetXaxis()->GetBinLowEdge(1); lastEdge = hZpTgen[0]->GetXaxis()->GetBinUpEdge(bins); hZpTMuEleGenRatio = new TH1D("hZpTMuEleGenRatio","",bins,firstEdge,lastEdge); if (!hZpTMuEleGenRatio->Divide(hZpTgen[0],hZpTgen[1])) cout << " Error in hZpTMuEleGenRatio->Divide(hZpTgen[0],hZpTgen[1])" << endl; hZpTMuEleGenRatio->SetStats(kFALSE); cZpTMuEleGenRatio = new TCanvas("cZpTMuEleGenRatio",""); hZpTMuEleGenRatio->GetXaxis()->SetTitle("Z_{pT}[GeV]"); hZpTMuEleGenRatio->GetXaxis()->SetTitleSize(0.04); hZpTMuEleGenRatio->GetYaxis()->SetTitle("gen pT_{Z(#mu#mu)} / pT_{Z(ee)} "); hZpTMuEleGenRatio->GetYaxis()->SetTitleSize(0.045); hZpTMuEleGenRatio->GetYaxis()->SetRangeUser(0.5,1.5); hZpTMuEleGenRatio->GetYaxis()->CenterTitle(); hZpTMuEleGenRatio->Draw("E"); gStyle->SetStatStyle(0); cZpTMuEleGenRatio->SaveAs( (plotDirectoryPath + cZpTMuEleGenRatio->GetName() + suffix + plotFileExtension).c_str() ); } TCanvas *cZpTRecoGenRatio_pdf = new TCanvas("cZpTRecoGenRatio_pdf",""); TLegend *legZpTRecoGenRatio_pdf = new TLegend(0.78,0.78,0.89,0.89); hZpTrecoGenRatio_pdf[0]->GetXaxis()->SetTitle("reco Z_{pT}/gen Z_{pT}"); hZpTrecoGenRatio_pdf[0]->GetXaxis()->SetTitleSize(0.04); hZpTrecoGenRatio_pdf[0]->GetXaxis()->SetRangeUser(0.7,1.3); hZpTrecoGenRatio_pdf[0]->GetYaxis()->SetTitle("a.u. "); hZpTrecoGenRatio_pdf[0]->GetYaxis()->SetTitleSize(0.045); hZpTrecoGenRatio_pdf[0]->GetYaxis()->SetRangeUser(0.0,0.4); hZpTrecoGenRatio_pdf[0]->GetYaxis()->CenterTitle(); hZpTrecoGenRatio_pdf[0]->Draw("HE"); hZpTrecoGenRatio_pdf[1]->Draw("HE SAME"); legZpTRecoGenRatio_pdf->AddEntry(hZpTrecoGenRatio_pdf[0],"Z(#mu#mu)","l"); legZpTRecoGenRatio_pdf->AddEntry(hZpTrecoGenRatio_pdf[1],"Z(ee)","l"); gStyle->SetStatStyle(0); legZpTRecoGenRatio_pdf->Draw(); legZpTRecoGenRatio_pdf->SetMargin(0.3); legZpTRecoGenRatio_pdf->SetBorderSize(0); cZpTRecoGenRatio_pdf->SaveAs( (plotDirectoryPath + cZpTRecoGenRatio_pdf->GetName() + suffix + plotFileExtension).c_str() ); TCanvas *cZpTRecoGenRatio_pdf_inRange = new TCanvas(Form("ZpTRecoGenRatio_pdf_Zpt%2.0lfTo%2.0lf",zptStart,zptEnd),""); TLegend *legZpTRecoGenRatio_pdf_inRange = new TLegend(0.78,0.78,0.89,0.89); TPaveLabel *title = new TPaveLabel(0.1,0.94,0.9,0.98,Form("Zpt recoGen ratio: %2.0lf < ZpT < %2.0lf",zptStart,zptEnd)); title->Draw(); HZtoLLPt_RecoGenRatio_pdf_inRange[0]->GetXaxis()->SetTitle("reco Z_{pT}/gen Z_{pT}"); HZtoLLPt_RecoGenRatio_pdf_inRange[0]->GetXaxis()->SetTitleSize(0.04); HZtoLLPt_RecoGenRatio_pdf_inRange[0]->GetXaxis()->SetRangeUser(0.7,1.3); HZtoLLPt_RecoGenRatio_pdf_inRange[0]->GetYaxis()->SetTitle("a.u. "); HZtoLLPt_RecoGenRatio_pdf_inRange[0]->GetYaxis()->SetTitleSize(0.045); HZtoLLPt_RecoGenRatio_pdf_inRange[0]->GetYaxis()->SetRangeUser(0.0,0.4); HZtoLLPt_RecoGenRatio_pdf_inRange[0]->GetYaxis()->CenterTitle(); HZtoLLPt_RecoGenRatio_pdf_inRange[0]->Draw("HE"); HZtoLLPt_RecoGenRatio_pdf_inRange[1]->Draw("HE SAME"); legZpTRecoGenRatio_pdf_inRange->AddEntry(HZtoLLPt_RecoGenRatio_pdf_inRange[0],"Z(#mu#mu)","l"); legZpTRecoGenRatio_pdf_inRange->AddEntry(HZtoLLPt_RecoGenRatio_pdf_inRange[1],"Z(ee)","l"); gStyle->SetStatStyle(0); legZpTRecoGenRatio_pdf_inRange->Draw(); legZpTRecoGenRatio_pdf_inRange->SetMargin(0.3); legZpTRecoGenRatio_pdf_inRange->SetBorderSize(0); cZpTRecoGenRatio_pdf_inRange->SaveAs( (plotDirectoryPath + cZpTRecoGenRatio_pdf_inRange->GetName() + suffix + plotFileExtension).c_str() ); }
void h1draw() { // We attach (or generate) the ROOT file in $ROOTSYS/tutorials/hsimple.root // or $PWD/hsimple.root // We draw one histogram in different formats //Author: Rene Brun TFile *example = TFile::Open("hsimple.root"); if (!example) return; example->ls(); TH1 *hpx = (TH1*)example->Get("hpx"); TCanvas *c1 = new TCanvas("c1","Histogram Drawing Options",200,10,700,900); TPad *pad1 = new TPad("pad1", "The pad with the function",0.03,0.62,0.50,0.92,21); TPad *pad2 = new TPad("pad2", "The pad with the histogram",0.51,0.62,0.98,0.92,21); TPad *pad3 = new TPad("pad3", "The pad with the histogram",0.03,0.02,0.97,0.57,21); pad1->Draw(); pad2->Draw(); pad3->Draw(); // Draw a global picture title TPaveLabel *title = new TPaveLabel(0.1,0.94,0.9,0.98, "Drawing options for one dimensional histograms"); title->SetFillColor(16); title->SetTextFont(52); title->Draw(); // Draw histogram hpx in first pad with the default option. pad1->cd(); pad1->GetFrame()->SetFillColor(18); hpx->SetFillColor(45); hpx->DrawCopy(); TPaveLabel *label1 = new TPaveLabel(-3.5,700,-1,800,"Default option"); label1->SetFillColor(42); label1->Draw(); // Draw hpx as a lego. Clicking on the lego area will show // a "transparent cube" to guide you rotating the lego in real time. pad2->cd(); hpx->DrawCopy("lego1"); TPaveLabel *label2 = new TPaveLabel(-0.72,0.74,-0.22,0.88,"option Lego1"); label2->SetFillColor(42); label2->Draw(); TPaveLabel *label2a = new TPaveLabel(-0.93,-1.08,0.25,-0.92, "Click on lego to rotate"); label2a->SetFillColor(42); label2a->Draw(); // Draw hpx with its errors and a marker. pad3->cd(); pad3->SetGridx(); pad3->SetGridy(); pad3->GetFrame()->SetFillColor(18); hpx->SetMarkerStyle(21); hpx->Draw("e1p"); TPaveLabel *label3 = new TPaveLabel(2,600,3.5,650,"option e1p"); label3->SetFillColor(42); label3->Draw(); // The following illustrates how to add comments using a PaveText. // Attributes of text/lines/boxes added to a PaveText can be modified. // The AddText function returns a pointer to the added object. TPaveText *pave = new TPaveText(-3.78,500,-1.2,750); pave->SetFillColor(42); TText *t1=pave->AddText("You can move"); t1->SetTextColor(4); t1->SetTextSize(0.05); pave->AddText("Title and Stats pads"); pave->AddText("X and Y axis"); pave->AddText("You can modify bin contents"); pave->Draw(); c1->Update(); }
void file(){ TCanvas *c1 = new TCanvas("c1","ROOT File description",200,10,700,550); c1->Range(0,-0.25,21,14); TPaveLabel *title = new TPaveLabel(5,12,15,13.7,c1->GetTitle()); title->SetFillColor(16); title->Draw(); // horizonthal file layout TPave *file = new TPave(1,8.5,20,11); file->SetFillColor(11); file->Draw(); TPave *fileh = new TPave(1,8.5,2.5,11); fileh->SetFillColor(44); fileh->Draw(); TPave *lrh = new TPave(2.5,8.5,3.3,11,1); lrh->SetFillColor(33); lrh->Draw(); lrh->DrawPave(6.9,8.5,7.7,11,1); lrh->DrawPave(10.5,8.5,11.3,11,1); lrh->DrawPave(14.5,8.5,15.3,11,1); TLine *ldot = new TLine(1,8.5,0.5,6.5); ldot->SetLineStyle(2); ldot->Draw(); ldot->DrawLine(2.5, 8.5, 9.4, 6.5); ldot->DrawLine(10.5, 8.5, 10, 6.5); ldot->DrawLine(11.3, 8.5, 19.5, 6.5); TLine *line = new TLine(2.6,11,2.6,11.5); line->Draw(); line->DrawLine(2.6,11.5,7,11.5); TArrow *arrow = new TArrow(7,11.5,7,11.1,0.01,"|>"); arrow->SetFillStyle(1001); arrow->Draw(); line->DrawLine( 7, 8.5, 7, 8.0); line->DrawLine( 7, 8.0, 10.6, 8); arrow->DrawArrow( 10.6,8, 10.6, 8.4,0.01,"|>"); line->DrawLine( 10.6, 11, 10.6, 11.5); line->DrawLine( 10.6, 11.5, 14.6, 11.5); arrow->DrawArrow( 14.6,11.5, 14.6,11.1,0.01,"|>"); line->DrawLine( 14.6, 8.5, 14.6, 8.0); line->DrawLine( 14.6, 8.0, 16, 8); ldot->DrawLine(16, 8, 19, 8); TText *vert = new TText(1.5,9.75,"File"); vert->SetTextAlign(21); vert->SetTextAngle(90); vert->SetTextSize(0.025); vert->Draw(); vert->DrawText(2.0, 9.75,"Header"); vert->DrawText(2.9, 9.75,"Logical Record"); vert->DrawText(3.2, 9.75,"Header"); vert->DrawText(7.3, 9.75,"Logical Record"); vert->DrawText(7.6, 9.75,"Header"); vert->DrawText(10.9,9.75,"Logical Record"); vert->DrawText(11.2,9.75,"Header"); vert->DrawText(14.9,9.75,"Logical Record"); vert->DrawText(15.2,9.75,"Header"); TText *hori = new TText(4.75,10,"Object"); hori->SetTextAlign(22); hori->SetTextSize(0.035); hori->Draw(); hori->DrawText(4.75, 9.5,"Data"); hori->DrawText(9.2, 10,"Deleted"); hori->DrawText(9.2, 9.5,"Object"); line->DrawLine( 6.9, 8.5, 10.5, 11); line->DrawLine( 6.9, 11, 10.5, 8.5); TText *tbig = new TText(17,9.75,"............"); tbig->SetTextAlign(22); tbig->SetTextSize(0.03); tbig->Draw(); tbig->DrawText(2.6, 7, "fBEGIN"); tbig->DrawText(20., 7, "fEND"); arrow->DrawArrow( 2.6,7, 2.6,8.4,0.01,"|>"); arrow->DrawArrow( 20,7, 20,8.4,0.01,"|>"); //file header TPaveText *header = new TPaveText(0.5,.2,9.4,6.5); header->SetFillColor(44); header->Draw(); TText *fh=header->AddText("File Header"); fh->SetTextAlign(22); fh->SetTextSize(0.04); header->SetTextSize(0.027); header->SetTextAlign(12); header->AddText(" "); header->AddLine(0,0,0,0); header->AddText("\"root\": Root File Identifier"); header->AddText("fVersion: File version identifier"); header->AddText("fBEGIN: Pointer to first data record"); header->AddText("fEND: Pointer to first free word at EOF"); header->AddText("fSeekFree: Pointer to FREE data record"); header->AddText("fNbytesFree: Number of bytes in FREE"); header->AddText("fNfree: Number of free data records"); header->AddText("fNbytesName: Number of bytes in name/title"); header->AddText("fUnits: Number of bytes for pointers"); header->AddText("fCompress: Compression level"); //logical record header TPaveText *lrecord = new TPaveText(10,0.2,19.5,6.5); lrecord->SetFillColor(33); lrecord->Draw(); TText *tlrh=lrecord->AddText("Logical Record Header (TKEY)"); tlrh->SetTextAlign(22); tlrh->SetTextSize(0.04); lrecord->SetTextSize(0.027); lrecord->SetTextAlign(12); lrecord->AddText(" "); lrecord->AddLine(0,0,0,0); lrecord->AddText("fNbytes: Length of compressed object"); lrecord->AddText("fVersion: Key version identifier"); lrecord->AddText("fObjLen: Length of uncompressed object"); lrecord->AddText("fDatime: Date/Time when written to store"); lrecord->AddText("fKeylen: Number of bytes for the key"); lrecord->AddText("fCycle : Cycle number"); lrecord->AddText("fSeekKey: Pointer to object on file"); lrecord->AddText("fSeekPdir: Pointer to directory on file"); lrecord->AddText("fClassName: class name of the object"); lrecord->AddText("fName: name of the object"); lrecord->AddText("fTitle: title of the object"); c1->Update(); c1->Print("file.png"); }
// File: ST_Monitoring_Efficiency.C // Last Modified: 05/27/2015 // Creator: Mahmoud Kamel [email protected] // Purpose: Displaying histograms for online monitoring purposes void ST_Monitoring_Eff () { // Define the directory that contains the histograms TDirectory *dir = (TDirectory*)gDirectory->FindObjectAny("st_tracking"); if(dir) dir->cd(); // Grab 1D histograms TH1D *MacropEff = (TH1D*)dir->FindObjectAny("MacropEff"); TH1D *MacropEff_adc = (TH1D*)dir->FindObjectAny("MacropEff_adc"); TH1D *h_phi_sec_pred_hit_cntr = (TH1D*)dir->FindObjectAny("h_phi_sec_pred_hit_cntr"); TH1D *h_phi_sec_hit_cntr = (TH1D*)dir->FindObjectAny("h_phi_sec_hit_cntr"); TH1D *h_phi_sec_adc_cntr = (TH1D*)dir->FindObjectAny("h_phi_sec_adc_cntr"); // get Binomial errors in an efficiency plot // hit object efficiency h_phi_sec_hit_cntr->Sumw2(); h_phi_sec_pred_hit_cntr->Sumw2(); MacropEff->Sumw2(); MacropEff->Divide(h_phi_sec_hit_cntr,h_phi_sec_pred_hit_cntr,1,1,"B"); // adc efficiency h_phi_sec_adc_cntr->Sumw2(); MacropEff_adc->Sumw2(); MacropEff_adc->Divide(h_phi_sec_adc_cntr,h_phi_sec_pred_hit_cntr,1,1,"B"); //Create the canvas if(gPad == NULL) { TCanvas *c1 = new TCanvas("c1","Start Counter 1D Histograms", 200, 10, 600, 480); c1->cd(0); c1->Draw(); c1->Update(); } if(!gPad) return; TCanvas *c1 = gPad->GetCanvas(); c1->Divide(2,1); // ST ADC Efficiency histogram c1->cd(1); gStyle->SetOptStat(0); gStyle->SetErrorX(0); gPad->SetTicks(); gPad->SetGrid(); if (MacropEff_adc) { MacropEff_adc->Draw("E1"); MacropEff_adc->SetMarkerStyle(21); MacropEff_adc->SetMarkerSize(1.5); MacropEff_adc->SetMarkerColor(4.0); MacropEff_adc->SetAxisRange(0., 1.,"Y"); MacropEff_adc->GetYaxis()->SetTitleOffset(1.26); Double_t TWA_adc=0; Double_t sumE_adc=0; Double_t Final_adc=0; Double_t error_adc=0.; Double_t BC_adc=0.; Double_t WA_adc=0.; //Double_t Final_adc=0.; for (int i = 0; i < 30; i++) { error_adc = MacropEff_adc->GetBinError(i+2); sumE_adc = sumE_adc + error_adc; BC_adc = MacropEff_adc->GetBinContent(i+2); WA_adc = BC_adc*error_adc; TWA_adc = TWA_adc + WA_adc ; Final_adc = TWA_adc/sumE_adc; // cout << "error_adc = "<< error_adc << endl; // cout << "BC_adc = "<< BC_adc << endl; // cout << "Final_adc = "<< Final_adc << endl; } TLine *line = new TLine(1,Final_adc,30,Final_adc); line->SetLineWidth(3); line->SetLineColor(2); //Write the eff value on the histogram char tFinal_adc[40]; char terror_adc[40]; sprintf(tFinal_adc,"ADC Efficiency (%%) = %g",Final_adc*100); sprintf(terror_adc,"ADC Efficiency error (%%) = %g",error_adc*100); line->Draw(); TPaveLabel *p = new TPaveLabel(0.3,0.6,0.7,0.7,tFinal_adc,"brNDC"); p->Draw(); TPaveLabel *p1 = new TPaveLabel(0.3,0.5,0.7,0.6,terror_adc,"brNDC"); p1->Draw(); } // ST Hit Efficiency histogram c1->cd(2); gPad->SetTicks(); gPad->SetGrid(); if (MacropEff) { MacropEff->Draw("E1"); MacropEff->SetMarkerStyle(21); MacropEff->SetMarkerSize(1.5); MacropEff->SetMarkerColor(4.0); MacropEff->SetAxisRange(0., 1.,"Y"); MacropEff->GetYaxis()->SetTitleOffset(1.26); Double_t TWA=0; Double_t sumE=0; Double_t Final=0; Double_t error=0.; Double_t BC=0.; Double_t WA=0.; //Double_t Final=0.; for (int i = 0; i < 30; i++) { error = MacropEff->GetBinError(i+2); sumE = sumE+error; BC = MacropEff->GetBinContent(i+2); WA = BC*error; TWA = TWA + WA ; Final = TWA/sumE; // cout << "error = "<< error << endl; // cout << "BC = "<< BC << endl; // cout << "Final = "<< Final << endl; } TLine *line = new TLine(1,Final,30,Final); line->SetLineWidth(3); line->SetLineColor(2); //Write the eff value on the histogram char tFinal[40]; char terror[40]; sprintf(tFinal,"Hit Efficiency (%%) = %g",Final*100); sprintf(terror,"Hit Efficiency error (%%) = %g",error*100); line->Draw(); TPaveLabel *p = new TPaveLabel(0.3,0.6,0.7,0.7,tFinal,"brNDC"); p->Draw(); TPaveLabel *p1 = new TPaveLabel(0.3,0.5,0.7,0.6,terror,"brNDC"); p1->Draw(); } }
void plotFinalEnergy() { gStyle->SetStatH(0.3); gStyle->SetStatY(0.88); gStyle->SetStatW(0.3); char canTitle[180]; sprintf(canTitle,"Energy at Terminal Interaction (10000 tries)"); TCanvas *canFinalEnergy = new TCanvas("canFinalEnergy","Final Energy",800,800); TPaveLabel *pl = new TPaveLabel(0.1,0.96,0.9,0.99,canTitle,"br NDC"); pl->SetBorderSize(0); pl->SetFillColor(0); pl->SetFillStyle(0); pl->Draw(); TPad *subCanFinalEnergy = new TPad("subCanFinalEnergy","",0,0,1,0.95); subCanFinalEnergy->Draw(); subCanFinalEnergy->cd(); subCanFinalEnergy->Divide(2,4); subCanFinalEnergy->Update(); // gStyle->SetOptStat(0); char fileName[80]; char histTitle[80]; char theEnergies[4][5]={"1e9","1e10","1e11","1e12"}; int theColours[2][3]={{50,42,46},{40,30,38}}; for(int isATau=0;isATau<=1;isATau++) { for(int i=0;i<4;i++) { sprintf(fileName, "newest%sFile%sIce.root",getParticleNameCaps(isATau),theEnergies[i]); sprintf(histTitle,"%s -- %s GeV",getParticleNameCaps(isATau),theEnergies[i]); TFile *fp = new TFile(fileName); TH1F *histEnergy = new TH1F("histEnergy",histTitle,100,7.5,12.5); TH1F *histEnergy2 = new TH1F("histEnergy2","Last Energy",100,7.5,12.5); TH1F *histEnergy3 = new TH1F("histEnergy3","Last Energy",100,7.5,12.5); TTree *theTree = (TTree*) fp->Get("theTree"); cout << theTree->GetEntries() << endl; subCanFinalEnergy->cd((2*i)+isATau+1); gPad->SetTopMargin(0.12); // gPad->SetBottomMargin(0.2); histEnergy->SetLineWidth(3); histEnergy->SetLineColor(theColours[isATau][0]); histEnergy2->SetLineWidth(3); histEnergy2->SetLineColor(theColours[isATau][1]); histEnergy3->SetLineWidth(3); histEnergy3->SetLineColor(theColours[isATau][2]); theTree->Draw("log10(stepIntEnergy)>>histEnergy","stepIntType>=4"); // histEnergy->GetXaxis()->SetTitle("IntType (#mus)"); // histEnergy->GetXaxis()->SetBinLabel(2,"Bremsstrahlung"); // histEnergy->GetXaxis()->SetBinLabel(3,"Pair Production"); // histEnergy->GetXaxis()->SetBinLabel(4,"Photonuclear"); // histEnergy->GetXaxis()->SetLabelSize(0.09); // histEnergy->GetXaxis()->SetLabelOffset(0.02); theTree->Draw("log10(stepIntEnergy)>>histEnergy2","stepIntType==4"); theTree->Draw("log10(stepIntEnergy)>>histEnergy3","stepIntType==5"); histEnergy->DrawCopy(); if(histEnergy2->GetEntries()) histEnergy2->DrawCopy("same"); if(histEnergy3->GetEntries()) histEnergy3->DrawCopy("same"); if(histEnergy->GetEntries()) gPad->SetLogy(); if(i==0) { TLegend *leg = new TLegend(0.7,0.2,0.9,0.6); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->AddEntry(histEnergy2,"Decay","l"); leg->AddEntry(histEnergy3,"Weak (CC)","l"); leg->AddEntry(histEnergy,"Either","l"); leg->Draw("same"); } } } for(int i=0;i<8;i++) { // cout << "Doing title "<< i+1 << endl; subCanFinalEnergy->cd(i+1); sortOutTitle(0.07); } // gStyle->SetOptStat(1110); }
void advancedNoiseAnalysis( unsigned int runNumber, unsigned int loop = 1) { string inputFileName = "./histo/run00" + toString( runNumber ) + "-ped-histo.root"; string outputFileName = "./histo/run00" + toString( runNumber ) + "-adv-noise.root"; // before opening the input and the output files, try to see if they // are not opened yet and in case close them before continue TList * listOfOpenedFile = (TList*) gROOT->GetListOfFiles(); for ( int i = 0; i < listOfOpenedFile->GetSize() ; ++i ) { TFile * file = (TFile*) listOfOpenedFile->At( i ) ; TString fileName(file->GetName()); TString inputFileName1( inputFileName.c_str() ); TString outputFileName1( outputFileName.c_str() ); if ( ( fileName.Contains( inputFileName1 ) ) || ( inputFileName1.Contains( fileName ) ) || ( fileName.Contains( outputFileName1 ) ) || ( outputFileName1.Contains( fileName ) ) ) { cout << "Closing " << fileName << " before reopen " << endl; file->Close(); } } // close also all the previously opened canvas TList * listOfOpenedCanvas = (TList*) gROOT->GetListOfCanvases(); for ( int i = 0 ; i < listOfOpenedCanvas->GetSize() ; ++i ) { TCanvas * canvas = (TCanvas*) listOfOpenedCanvas->At( i ); TString canvasName2 = canvas->GetName(); if ( canvasName2.Contains( "det" ) ) { canvas->Close(); } } // now safely open the file TFile * inputFile = TFile::Open( inputFileName.c_str() ) ; TFile * outputFile = TFile::Open( outputFileName.c_str(), "RECREATE") ; TList * outputHistoList = new TList; // look into the inputFile for a folder named string pedeProcessorFolderName = "PedestalAndNoiseCalculator"; TDirectoryFile * pedeProcessorFolder = (TDirectoryFile*) inputFile->Get( pedeProcessorFolderName.c_str() ); if ( pedeProcessorFolder == 0 ) { cerr << "No pedestal processor folder found in file " << inputFileName << endl; return ; } // this folder should contain one folder for each loop. string loopFolderName = "loop-" + toString( loop ); TDirectoryFile * loopFolder = (TDirectoryFile *) pedeProcessorFolder->Get( loopFolderName.c_str() ); if ( loopFolder == 0 ) { cerr << "No " << loopFolderName << " found in file " << inputFileName << endl; return ; } // guess the number of sensors from the number of subfolder in the loopfolder size_t nDetector = loopFolder->GetListOfKeys()->GetSize(); cout << "This file contains " << nDetector << " detectors" << endl; // prepare arrays to store the mean and the rms of the noise distribution if ( noiseMean == NULL ) { delete [] noiseMean; noiseMean = NULL; } if ( noiseRMS == NULL ) { delete [] noiseRMS; noiseRMS = NULL; } if ( channel == NULL ) { delete [] channel; channel = NULL; } noiseMean = new double[ nDetector * kNChan ]; noiseRMS = new double[ nDetector * kNChan ]; channel = new double[ kNChan ]; string canvasName = "comparison"; string canvasTitle = "Noise comparison"; TCanvas * comparisonCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 ); comparisonCanvas->Divide(1,2); TPad * topPad = (TPad*) comparisonCanvas->cd(1); topPad->Divide( nDetector ); TPad * middlePad = (TPad *) comparisonCanvas->cd(2); middlePad->Divide( kNChan ); // for each detector we have to get the noise map and to prepare 4 // separe histos and maps for ( unsigned int iDetector = 0; iDetector < nDetector; iDetector++ ) { // get the noise map. string noiseMapName = "detector-" + toString( iDetector ) ; noiseMapName += "/NoiseMap-d" + toString( iDetector ) ; noiseMapName += "-l" + toString( loop ) ; TH2D * noiseMap = ( TH2D* ) loopFolder->Get( noiseMapName.c_str() ); // create a folder in the output file TDirectory * subfolder = outputFile->mkdir( string( "detector_" + toString( iDetector ) ).c_str(), string( "detector_" + toString( iDetector ) ).c_str() ); subfolder->cd(); string canvasName = "det" + toString( iDetector ); string canvasTitle = "Detector " + toString( iDetector ); TCanvas * canvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 ); canvas->Divide( kNChan, 2 ); // ok now start the loop on channels for ( size_t iChan = 0 ; iChan < kNChan ; ++iChan ) { if ( iDetector == 0 ) channel[iChan] = iChan - 0.5; string tempName = "NoiseMap_d" + toString( iDetector ) + "_l" + toString( loop ) + "_ch" + toString( iChan ) ; string tempTitle = "NoiseMap Det. " + toString( iDetector ) + " - Ch. " + toString( iChan ) ; TH2D * noiseMapCh = new TH2D ( tempName.c_str() , tempTitle.c_str(), kXPixel / kNChan , -0.5 + xLimit[ iChan ] , -0.5 + xLimit[ iChan + 1 ], kYPixel, -0.5, -0.5 + kYPixel ); noiseMapCh->SetXTitle("X [pixel]"); noiseMapCh->SetYTitle("Y [pixel]"); noiseMapCh->SetZTitle("Noise [ADC]"); noiseMapCh->SetStats( false ); outputHistoList->Add( noiseMapCh ) ; tempName = "NoiseDist_d" + toString( iDetector ) + "_l" + toString( loop ) + "_ch" + toString( iChan ) ; tempTitle = "NoiseDist Det. " + toString( iDetector ) + " - Ch. " + toString( iChan ) ; TH1D * noiseDistCh = new TH1D( tempName.c_str(), tempTitle.c_str(), 50, 0., 10. ); noiseDistCh->SetXTitle("Noise [ADC]"); noiseDistCh->SetLineColor( kColor[iDetector] ); noiseDistCh->SetLineStyle( iChan + 2 ); noiseDistCh->SetLineWidth( 2 ); outputHistoList->Add( noiseDistCh ); // let's start looping on pixels now for ( size_t yPixel = 1 ; yPixel <= kYPixel ; ++yPixel ) { for ( size_t xPixel = xLimit[ iChan ] + 1; xPixel <= xLimit[ iChan +1 ] ; ++xPixel ) { double noise = noiseMap->GetBinContent( xPixel , yPixel ); noiseMapCh->Fill( xPixel - 1 , yPixel - 1, noise ); noiseDistCh->Fill( noise ); } } canvas->cd( iChan + 1 ) ; noiseMapCh->Draw("colz"); canvas->cd( iChan + kNChan + 1 ); noiseDistCh->Draw(); topPad->cd( iDetector + 1 ); if ( iChan == 0 ) { noiseDistCh->Draw(); } else { noiseDistCh->Draw("same"); } middlePad->cd( iChan + 1 ); if ( iDetector == 0 ) { noiseDistCh->Draw(); } else { noiseDistCh->Draw("same"); } noiseMean[ kNChan * iDetector + iChan ] = noiseDistCh->GetMean(); noiseRMS[ kNChan * iDetector + iChan ] = noiseDistCh->GetRMS(); } canvas->Write(); } canvasName = "summary"; canvasTitle = "Noise summary"; TCanvas * summaryCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 ); summaryCanvas->SetGridx(1); TLegend * legend = new TLegend(0.5, 4.8, 1.5, 4.3,"","br");; for ( size_t iDetector = 0 ; iDetector < nDetector ; ++iDetector ) { TGraphErrors * gr = new TGraphErrors( kNChan, channel, &noiseMean[ iDetector * kNChan ], NULL, &noiseRMS[ iDetector * kNChan ] ); gr->SetName( string( "NoisePerChannel_d" + toString( iDetector )).c_str()); gr->SetTitle(string("Detector " + toString( iDetector )).c_str()); gr->GetXaxis()->SetTitle("Channel #"); gr->GetYaxis()->SetTitle("Noise [ADC]"); gr->GetXaxis()->SetNdivisions( 5 ); gr->GetXaxis()->SetLabelSize( 0 ); gr->SetMarkerStyle( iDetector + 1 ); gr->SetMarkerColor( kColor[iDetector] ); gr->SetLineColor( kColor[iDetector] ); gr->SetLineWidth( 2 ); legend->AddEntry( gr, string("Detector " + toString( iDetector )).c_str(), "LP"); if ( iDetector == 0 ) { gr->Draw("ALP"); } else { gr->Draw("LP"); } } legend->Draw(); for ( size_t iChan = 0 ; iChan < kNChan ; ++iChan ) { TPaveLabel * label = new TPaveLabel( iChan - 0.75 , 3.2 , iChan -0.25 , 3, string("Ch " + toString( iChan ) ).c_str()); label->Draw(); } summaryCanvas->Write(); comparisonCanvas->Write(); outputHistoList->Write(); }
int main(int argc, char** argv){ TString chfile; TString chfileref; TString DirectoryLast; TString labelData; TString labelRef; int ntrueargs = 0; bool logyFlag = true; bool normalize = false; for (int i=1; i<argc; ++i) { if (argv[i][0] == '-') { if (argv[i][1]=='l') logyFlag = false; else if (argv[i][1]=='b') gROOT->SetBatch(); else if (argv[i][1]=='h') return printUsage(); else if (argv[i][1]=='n') normalize=true; else if (argv[i][1]=='D') labelData = argv[i+1]; else if (argv[i][1]=='R') labelRef= argv[i+1]; } else { ntrueargs += 1; if (ntrueargs==1) chfile = argv[i]; else if (ntrueargs==2) chfileref = argv[i]; else if (ntrueargs==3) DirectoryLast = argv[i]; } } if (ntrueargs<3) return printUsage(); TRint* app = new TRint("CMS Root Application", 0, 0); TString cmssw_version = gSystem->Getenv("CMSSW_VERSION"); TString chsample = "EWKMu"; TString chtitle = chsample + " validation for " + cmssw_version; //TCanvas* c1 = new TCanvas("c1",chtitle.Data()); TCanvas* c1 = new TCanvas("c1",chtitle.Data(),0,0,1024,768); c1->SetFillColor(0); TPaveLabel* paveTitle = new TPaveLabel(0.1,0.93,0.9,0.99, chtitle.Data()); paveTitle->Draw(); paveTitle->SetFillColor(0); gStyle->SetOptLogy(logyFlag); gStyle->SetPadGridX(true); gStyle->SetPadGridY(true); gStyle->SetOptStat(0); // gStyle->SetFillColor(0); TPad* pad[4]; pad[0] = new TPad("pad_tl","The top-left pad",0.01,0.48,0.49,0.92); pad[0]->SetFillColor(0); pad[1] = new TPad("pad_tr","The top-right pad",0.51,0.48,0.99,0.92); pad[1]->SetFillColor(0); pad[2] = new TPad("pad_bl","The bottom-left pad",0.01,0.01,0.49,0.46); pad[2]->SetFillColor(0); pad[3] = new TPad("pad_br","The bottom-right pad",0.51,0.01,0.99,0.46); pad[3]->SetFillColor(0); for (unsigned int i=0; i<4; ++i) pad[i]->Draw(); TLegend* leg = new TLegend(0.6041667,0.7487715,0.9861111,0.9576167); leg->SetFillColor(0); TFile* input_file = new TFile(chfile.Data(),"READONLY"); TFile* input_fileref = new TFile(chfileref.Data(),"READONLY"); bool first_plots_done = false; TString directory = DirectoryLast + "/BeforeCuts"; TDirectory* dir_before = input_file->GetDirectory(directory); TDirectory* dirref_before = input_fileref->GetDirectory(directory); TList* list_before = dir_before->GetListOfKeys(); list_before->Print(); unsigned int list_before_size = list_before->GetSize(); TString auxTitle = chtitle + ": BEFORE CUTS"; for (unsigned int i=0; i<list_before_size; i+=4) { if (first_plots_done==true) c1->DrawClone(); paveTitle->SetLabel(auxTitle.Data()); for (unsigned int j=0; j<4; ++j) { pad[j]->cd(); pad[j]->Clear(); if ((i+j)>=list_before_size) continue; TH1D* h1 = (TH1D*)dir_before->Get(list_before->At(i+j)->GetName()); // h1->SetLineColor(kBlue); // h1->SetMarkerColor(kBlue); h1->SetMarkerStyle(21); h1->SetLineStyle(1); h1->SetLineWidth(3); h1->SetTitleSize(0.05,"X"); h1->SetTitleSize(0.05,"Y"); TString title=(TString)dir_before->Get(list_before->At(i+j)->GetName())->GetTitle(); TString name=(TString)dir_before->Get(list_before->At(i+j)->GetName())->GetName(); TString nameD =name+"_MC"; h1->SetXTitle(title); h1->SetName(nameD); h1->SetYTitle(""); h1->SetTitle(""); h1->SetTitleOffset(0.85,"X"); TH1D* hr = (TH1D*)dirref_before->Get(list_before->At(i+j)->GetName()); hr->SetLineColor(kPink-4); // hr->SetLineStyle(2); hr->SetLineWidth(3); hr->SetTitleSize(0.05,"X"); hr->SetTitleSize(0.05,"Y"); hr->SetFillColor(kPink-4); hr->SetFillStyle(3001); hr->SetXTitle(title); TString nameMC =name+"_Data"; h1->SetName(nameMC); hr->SetYTitle(""); hr->SetTitle(""); hr->SetTitleOffset(0.85,"X"); if(normalize) {hr->DrawNormalized("hist",h1->Integral());} else{hr->Draw("hist");} h1->Draw("sames,p,E"); int max1=h1->GetMaximum(); int maxr=hr->GetMaximum(); if(!normalize){ if(max1 >= maxr) { hr->SetMaximum(max1*1.2); h1->SetMaximum(max1*1.2);} else {hr->SetMaximum(maxr*1.2); h1->SetMaximum(maxr*1.2);} } else if (normalize){ hr->GetYaxis()->SetRangeUser(h1->GetMinimum()*0.1,max1*1.2); } leg->Clear(); leg->AddEntry(h1,labelData.Data(),"Lp"); leg->AddEntry(hr,labelRef.Data() ,"f"); leg->Draw(); } first_plots_done = true; c1->Modified(); c1->Update(); char chplot[80]; sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.root",chsample.Data(),cmssw_version.Data(),i/4); c1->SaveAs(chplot); sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.gif",chsample.Data(),cmssw_version.Data(),i/4); c1->SaveAs(chplot); } TString directory2 = DirectoryLast + "/LastCut"; TDirectory* dir_lastcut = input_file->GetDirectory(directory2); TDirectory* dirref_lastcut = input_fileref->GetDirectory(directory2); TList* list_lastcut = dir_lastcut->GetListOfKeys(); list_lastcut->Print(); unsigned int list_lastcut_size = list_lastcut->GetSize(); auxTitle = chtitle + ": AFTER N-1 CUTS"; for (unsigned int i=0; i<list_lastcut_size; i+=4) { if (first_plots_done==true) c1->DrawClone(); paveTitle->SetLabel(auxTitle.Data()); for (unsigned int j=0; j<4; ++j) { pad[j]->cd(); pad[j]->Clear(); if ((i+j)>=list_lastcut_size) continue; TH1D* h1 = (TH1D*)dir_lastcut->Get(list_lastcut->At(i+j)->GetName()); // h1->SetLineColor(kBlue); // h1->SetMarkerColor(kBlue); h1->SetMarkerStyle(21); h1->SetLineWidth(3); h1->SetTitleSize(0.05,"X"); h1->SetTitleSize(0.05,"Y"); TString name=(TString)dir_lastcut->Get(list_lastcut->At(i+j)->GetName())->GetName(); TString title=(TString)dir_lastcut->Get(list_lastcut->At(i+j)->GetName())->GetTitle(); TString nameD=name+"_Data"; h1->SetXTitle(title); h1->SetName(nameD); h1->SetYTitle(""); h1->SetTitle(""); h1->SetTitleOffset(0.85,"X"); TH1D* hr = (TH1D*)dirref_lastcut->Get(list_lastcut->At(i+j)->GetName()); hr->SetLineColor(kAzure+5); // hr->SetLineStyle(2); hr->SetLineWidth(3); hr->SetTitleSize(0.05,"X"); hr->SetTitleSize(0.05,"Y"); hr->SetFillColor(kAzure+5); hr->SetFillStyle(3001); hr->SetXTitle(title); TString nameMC=name+"_Data"; h1->SetName(nameMC); hr->SetYTitle(""); hr->SetTitle(""); hr->SetTitleOffset(0.85,"X"); if(normalize) {hr->DrawNormalized("hist",h1->Integral());} else{hr->Draw("hist");} h1->Draw("sames,p,E"); int max1=h1->GetMaximum(); int maxr=hr->GetMaximum(); if(!normalize){ if(max1 >= maxr) { hr->SetMaximum(max1*1.2); h1->SetMaximum(max1*1.2);} else {hr->SetMaximum(maxr*1.2); h1->SetMaximum(maxr*1.2);} } else if (normalize){ hr->GetYaxis()->SetRangeUser(h1->GetMinimum()*0.1,max1*1.2); } leg->Clear(); leg->AddEntry(h1,labelData.Data(),"lp"); leg->AddEntry(hr,labelRef.Data(),"f"); leg->Draw(); } first_plots_done = true; c1->Modified(); c1->Update(); char chplot[80]; sprintf(chplot,"%sValidation_%s_LASTCUT_%d.root",chsample.Data(),cmssw_version.Data(),i/4); c1->SaveAs(chplot); sprintf(chplot,"%sValidation_%s_LASTCUT_%d.gif",chsample.Data(),cmssw_version.Data(),i/4); c1->SaveAs(chplot); } if (!gROOT->IsBatch()) app->Run(); return 0; }
void archi() { TCanvas *c1 = new TCanvas("c1","Dictionary Architecture",20,10,750,930); c1->SetBorderSize(0); c1->Range(0,0,20.5,26); TPaveLabel *title = new TPaveLabel(4,24,16,25.5,c1->GetTitle()); title->SetFillColor(46); title->Draw(); TPavesText *dll = new TPavesText(0.5,19,4.5,23,5,"tr"); dll->SetFillColor(39); dll->SetTextSize(0.023); dll->AddText(" "); dll->AddText("Dynamically"); dll->AddText("Linked"); dll->AddText("Libraries"); dll->Draw(); TPaveLabel *dlltitle = new TPaveLabel(1.5,22.6,3.5,23.3,"DLLs"); dlltitle->SetFillColor(28); dlltitle->Draw(); TPavesText *cpp = new TPavesText(5.5,19,9.5,23,5,"tr"); cpp->SetTextSize(0.023); cpp->AddText(" "); cpp->AddText("Commented"); cpp->AddText("Header"); cpp->AddText("Files"); cpp->Draw(); TPaveLabel *cpptitle = new TPaveLabel(6.5,22.6,8.5,23.3,"C++"); cpptitle->SetFillColor(28); cpptitle->Draw(); TPavesText *odl = new TPavesText(10.5,19,14.5,23,5,"tr"); odl->SetTextSize(0.023); odl->AddText(" "); odl->AddText("Objects"); odl->AddText("Description"); odl->AddText("Files"); odl->Draw(); TPaveLabel *odltitle = new TPaveLabel(11.5,22.6,13.5,23.3,"ODL"); odltitle->SetFillColor(28); odltitle->Draw(); TPavesText *idl = new TPavesText(15.5,19,19.5,23,5,"tr"); idl->SetTextSize(0.023); idl->AddText(" "); idl->AddText("Interface"); idl->AddText("Definition"); idl->AddText("Language"); idl->Draw(); TPaveLabel *idltitle = new TPaveLabel(16.5,22.6,18.5,23.3,"IDL"); idltitle->SetFillColor(28); idltitle->Draw(); TWbox *p1 = new TWbox(7.8,10,13.2,17,11,12,1); p1->Draw(); TText *pro1 = new TText(10.5,15.8,"Process 1"); pro1->SetTextAlign(21); pro1->SetTextSize(0.03); pro1->Draw(); TPaveText *p1dict = new TPaveText(8.8,13.8,12.2,15.6); p1dict->SetTextSize(0.023); p1dict->AddText("Dictionary"); p1dict->AddText("in memory"); p1dict->Draw(); TPavesText *p1object = new TPavesText(8.6,10.6,12.1,13.0,5,"tr"); p1object->SetTextSize(0.023); p1object->AddText("Objects"); p1object->AddText("in memory"); p1object->Draw(); TWbox *p2 = new TWbox(15.5,10,20,17,11,12,1); p2->Draw(); TText *pro2 = new TText(17.75,15.8,"Process 2"); pro2->SetTextAlign(21); pro2->SetTextSize(0.03); pro2->Draw(); TPaveText *p2dict = new TPaveText(16,13.8,19.5,15.6); p2dict->SetTextSize(0.023); p2dict->AddText("Dictionary"); p2dict->AddText("in memory"); p2dict->Draw(); TPavesText *p2object = new TPavesText(16.25,10.6,19.25,13.0,5,"tr"); p2object->SetTextSize(0.023); p2object->AddText("Objects"); p2object->AddText("in memory"); p2object->Draw(); TWbox *stub1 = new TWbox(12.9,11.5,13.6,15.5,49,3,1); stub1->Draw(); TText *tstub1 = new TText(13.25,13.5,"Stub1"); tstub1->SetTextSize(0.025); tstub1->SetTextAlign(22); tstub1->SetTextAngle(90); tstub1->Draw(); TWbox *stub2 = new TWbox(15.1,11.5,15.8,15.5,49,3,1); stub2->Draw(); TText *tstub2 = new TText(15.45,13.5,"Stub2"); tstub2->SetTextSize(0.025); tstub2->SetTextAlign(22); tstub2->SetTextAngle(-90); tstub2->Draw(); TArrow *ar1 = new TArrow(); ar1->SetLineWidth(6); ar1->SetLineColor(1); ar1->SetFillStyle(1001); ar1->SetFillColor(1); ar1->DrawArrow(13.5,14,15,14,0.012,"|>"); ar1->DrawArrow(15.1,13,13.51,13,0.012,"|>"); TPaveText *cint = new TPaveText(1.0,15.0,8.0,17.5); cint->SetFillColor(39); cint->SetBorderSize(1); cint->SetTextSize(0.023); cint->AddText("C++ Interpreter"); cint->AddText("and program builder"); cint->Draw(); TPaveText *command = new TPaveText(2.5,13.4,8.0,14.5); command->SetTextSize(0.023); command->SetFillColor(39); command->SetBorderSize(1); command->AddText("Command Thread"); command->Draw(); TPavesText *view = new TPavesText(1.0,9.5,7.7,12.6,3,"tr"); view->SetFillColor(39); view->SetBorderSize(2); view->SetTextSize(0.023); view->AddText("Viewer Thread(s)"); view->AddText("Picking"); view->AddText("Context Menus"); view->AddText("Inspector/Browser"); view->Draw(); TPavesText *web = new TPavesText(0.5,5,6,8.5,5,"tr"); web->SetTextSize(0.023); web->AddText(" "); web->AddText("generated"); web->AddText("automatically"); web->AddText("from dictionary"); web->AddText("and source files"); web->Draw(); TPaveLabel *webtitle = new TPaveLabel(1.5,8.1,5.0,8.8,"HTML Files"); webtitle->SetFillColor(28); webtitle->Draw(); TPavesText *printed = new TPavesText(0.5,1.0,6,4,5,"tr"); printed->SetTextSize(0.023); printed->AddText(" "); printed->AddText("generated"); printed->AddText("automatically"); printed->AddText("from HTML files"); printed->Draw(); TPaveLabel *printedtitle = new TPaveLabel(1.5,3.6,5.0,4.3,"Printed Docs"); printedtitle->SetFillColor(28); printedtitle->Draw(); TBox *box1 = new TBox(0.2,9.2,14.25,17.8); box1->SetFillStyle(0); box1->SetLineStyle(2); box1->Draw(); TBox *box2 = new TBox(10.2,18.7,20.2,23.6); box2->SetFillStyle(0); box2->SetLineStyle(3); box2->Draw(); ar1->DrawArrow(2.5,17.5,2.5,18.9,0.012,"|>"); ar1->DrawArrow(5.5,9.2,5.5,8.7,0.012,"|>"); ar1->DrawArrow(5.5,5,5.5,4.2,0.012,"|>"); ar1->DrawArrow(8.5,9.2,8.5,8.2,0.012,"|>"); ar1->DrawArrow(9.5,8.1,9.5,9.0,0.012,"|>"); ar1->DrawArrow(6.5,19,6.5,17.6,0.012,"|>"); ar1->DrawArrow(8.5,19,8.5,17.1,0.012,"|>"); ar1->DrawArrow(11.5,19,11.5,17.1,0.012,"|>"); TPaveLabel *ootitle = new TPaveLabel(10.5,7.8,17,8.8,"Objects Data Base"); ootitle->SetFillColor(28); ootitle->Draw(); TPad *pio = new TPad("pio","pio",0.37,0.02,0.95,0.31,49); pio->Range(0,0,12,8); pio->Draw(); pio->cd(); TPavesText *raw = new TPavesText(0.5,1,2.5,6,7,"tr"); raw->Draw(); TPavesText *dst1 = new TPavesText(4,1,5,3,7,"tr"); dst1->Draw(); TPavesText *dst2 = new TPavesText(6,1,7,3,7,"tr"); dst2->Draw(); TPavesText *dst3 = new TPavesText(4,4,5,6,7,"tr"); dst3->Draw(); TPavesText *dst4 = new TPavesText(6,4,7,6,7,"tr"); dst4->Draw(); Float_t xlow = 8.5; Float_t ylow = 1; Float_t dx = 0.5; Float_t dy = 0.5; for (Int_t j=1;j<9;j++) { Float_t y0 = ylow + (j-1)*0.7; Float_t y1 = y0 + dy; for (Int_t i=1;i<5;i++) { Float_t x0 = xlow +(i-1)*0.6; Float_t x1 = x0 + dx; TPavesText *anal = new TPavesText(x0,y0,x1,y1,7,"tr"); anal->Draw(); } } TText *daq = new TText(); daq->SetTextSize(0.07); daq->SetTextAlign(22); daq->DrawText(1.5,7.3,"DAQ"); daq->DrawText(6,7.3,"DST"); daq->DrawText(10.,7.3,"Physics Analysis"); daq->DrawText(1.5,0.7,"Events"); daq->DrawText(1.5,0.3,"Containers"); daq->DrawText(6,0.7,"Tracks/Hits"); daq->DrawText(6,0.3,"Containers"); daq->DrawText(10.,0.7,"Attributes"); daq->DrawText(10.,0.3,"Containers"); c1->cd(); }
void second() { TCanvas *nut = new TCanvas("nut", "Second Session",100,10,750,1000); nut->Range(0,0,20,24); nut->SetFillColor(18); TPaveLabel *pl = new TPaveLabel(3,22,17,23.7,"My second ROOT interactive session","br"); pl->SetFillColor(18); pl->Draw(); TText t(0,0,"a"); t.SetTextFont(62); t.SetTextSize(0.025); t.SetTextAlign(12); t.DrawText(2,21,"Very large C/C++ files can be interpreted (50,000 lines+)."); t.DrawText(2,20,"Functions in macros can reference other functions, etc."); t.DrawText(2,19,"Let's make a file \"graph.C\" with the following statements:"); TPaveText *macro = new TPaveText(2,11,18,18); macro->SetFillColor(10); macro->SetTextColor(kBlue); macro->SetBorderSize(6); macro->SetTextAlign(12); macro->SetTextFont(61); macro->AddText("{"); macro->AddText(" TCanvas *c1 = new TCanvas(\"c1\",\"A Simple Graph Example\",200,10,700,500);"); macro->AddText(" c1->Range(-0.5,-2,2.5,12);"); macro->AddText(" const Int_t n = 20"); macro->AddText(" Float_t x[n], y[n];"); macro->AddText(" for (Int_t i=0;i<n;i++) {"); macro->AddText(" x[i] = i*0.1;"); macro->AddText(" y[i] = 10*sin(x[i]+0.2);"); macro->AddText(" }"); macro->AddText(" gr = new TGraph(n,x,y);"); macro->AddText(" gr->Draw(\"AC*\");"); macro->AddText("}"); macro->AddText(" "); macro->Draw(); t.SetTextFont(72); t.SetTextColor(kRed); t.SetTextSize(0.026); t.DrawText(3,10,"Root > .x graph.C"); TPad *pad = new TPad("pad","pad",.15,.05,.85,.40); pad->SetFillColor(41); pad->SetFrameFillColor(33); pad->Draw(); pad->cd(); pad->SetGrid(); pad->Range(-0.5,-2,2.5,12); const Int_t n = 20; Float_t x[n], y[n]; for (Int_t i=0;i<n;i++) { x[i] = i*0.1; y[i] = 10*sin(x[i]+0.2); } gr = new TGraph(n,x,y); gr->Draw("AC*"); nut->cd(); }
void MEComparePlot(TH1 * href_, TH1 * hnew_, TString currentfile, TString referencefile, TString theDir, TString theHisto ) { TString theName = theDir+"/"+theHisto; std::cout << "Histogram name = " << theName << std::endl; HistoCompare * myPV = new HistoCompare(); int rcolor = 2; int scolor = 4; int rmarker = 21; int smarker = 20; Double_t markerSize = 0.75; href_->SetLineColor(rcolor); href_->SetMarkerStyle(rmarker); href_->SetMarkerSize(markerSize); href_->SetMarkerColor(rcolor); hnew_->SetLineColor(scolor); hnew_->SetMarkerStyle(smarker); hnew_->SetMarkerSize(markerSize); hnew_->SetMarkerColor(scolor); TCanvas *myPlot = 0; if ( href_ && hnew_ ) { myPlot = new TCanvas("myPlot","Histogram comparison",200,10,700,900); TPad *pad1 = new TPad("pad1", "The pad with the function",0.03,0.62,0.50,0.92); TPad *pad2 = new TPad("pad2", "The pad with the histogram",0.51,0.62,0.98,0.92); TPad *pad3 = new TPad("pad3", "The pad with the histogram",0.03,0.02,0.97,0.57); pad1->Draw(); pad2->Draw(); pad3->Draw(); // Draw a global picture title TPaveLabel *title = new TPaveLabel(0.1,0.94,0.9,0.98,theName); title->SetFillColor(16); title->SetTextFont(52); title->Draw(); TText * titte = new TText(); // Draw reference pad1->cd(); href_->DrawCopy("e1"); titte->DrawTextNDC(0.,0.02, referencefile); // Draw new pad2->cd(); hnew_->DrawCopy("e1"); titte->DrawTextNDC(0.,0.02, currentfile); gStyle->SetOptStat("nemruoi"); // Draw the two overlayed pad3->cd(); pad3->SetGridx(); pad3->SetGridy(); href_->DrawCopy("e1"); hnew_->DrawCopy("e1same"); TText* te = new TText(); te->SetTextSize(0.1); myPV->PVCompute( href_ , hnew_ , te ); gStyle->SetOptStat(0000000); } TString plotFile = theHisto+".jpg"; if(myPlot) myPlot->Print(plotFile); delete myPV; delete myPlot; }
void geugd_riordan() { gROOT->SetStyle("HALLA"); TCanvas *cn = new TCanvas("cn"); cn->Draw(); cn->UseCurrentStyle(); TH1F *frm = new TH1F("frm","",100,0.,12.); frm->GetXaxis()->SetTitle("Q^{2} [GeV^{2}]"); frm->GetXaxis()->CenterTitle(); frm->GetYaxis()->SetTitle("G_{E}^{u}/G_{D}"); frm->GetYaxis()->CenterTitle(); frm->SetMinimum(.40); frm->SetMaximum(2.4); //frm->SetMaximum(0.3); frm->UseCurrentStyle(); frm->Draw(); frm->SetAxisRange(0.10,12.,"X"); TF1* galster = new TF1("galster", "x/(4.*0.938*.938)*1.91/(1.+x/.71)^2/(1.+5.6*x/(4.*.938*.938))", 0.,4.); galster->SetLineColor(kBlack); galster->SetLineStyle(kBlack); galster->SetLineWidth(2); TF1* gen0 = new TF1("gen0", f1dugen0, 0.,12.); gen0->SetLineColor(kBlack); gen0->SetLineStyle(kBlack); gen0->SetLineWidth(1); TF1 *genf = new TF1("genf",genff,1.,10.,1); genf->SetLineColor(kBlue); genf->SetLineStyle(1); genf->SetParameter(0,1.); // match to Madey point just below 1.5 // genf->SetParameter(0,.0411/genf->Eval(1.45)); // genf->SetParameter(0,-0.558645); genf->SetParameter(0,-0.182645); TF1 *roberts_curve = new TF1("roberts",roberts_gen,0.035,12.344,1); roberts_curve->SetLineColor(kRed); roberts_curve->SetLineStyle(9); TF1 *ourfit = new TF1("ourfit",gen_ourfit,0.,10.,0); ourfit->SetLineColor(kBlue); ourfit->SetLineStyle(0); /* TF1 *bbba05 = new TF1("BBBA05",gen_bbba05,0.,10.,0); bbba05->SetLineColor(kGreen); bbba05->SetLineStyle(3); */ // TF1 *lomon = new TF1("Lomon",Lomon_GEn,0.,10.,0); // lomon->SetLineColor(7); // lomon->SetLineStyle(4); TMultiGraph* mgrDta = new TMultiGraph("Data","G_{E}^{n}"); //TLegend *legDta = new TLegend(.3448,.6123,.6810,.9110,"","brNDC"); TLegend *legDta = new TLegend(.6020,.4004,.9382,.9089,"","brNDC"); TMultiGraph* wgr = mgrDta; TLegend *wlg = legDta; // the data legDta->SetBorderSize(0); // turn off border legDta->SetFillStyle(0); datafile_t *f = datafiles; TGraph* gr=0; TGraph* ogr=0; while ( f && f->filename ) { ogr=OneGraph(f); if (ogr) { gr = fromGEntransform(ogr); gr->SetLineStyle(0); if (f->lnpt) { mgrDta->Add(gr,f->lnpt); if( f->label[0] != 'x' ) legDta->AddEntry(gr,f->label,f->lnpt); } mgrDta->Add(gr,"p"); if( f->label[0] != 'x' ) legDta->AddEntry(gr,f->label,"p"); /* else if (gr->GetMarkerStyle()>=20) { mgrDta->Add(gr,"p"); if( f->label[0] != 'x' ) legDta->AddEntry(gr,f->label,"p"); } else { mgrDta->Add(gr,"l"); if( f->label[0] != 'x' ) legDta->AddEntry(gr,f->label,"l"); } */ } f++; } mgrDta->Draw("p"); legDta->Draw(); TMultiGraph* mgrThry = new TMultiGraph("Theory","G_{E}^{n}"); // TLegend *legThry = new TLegend(.546,.6208,.8822,.9195,"","brNDC"); // TLegend *legThry = new TLegend(.2055,.7013,.6020,.8893,"","brNDC"); TLegend *legThry = new TLegend(.4267,.8453,.6236,.8962,"","brNDC"); wgr = mgrThry; wlg = legThry; // the theory wlg->SetBorderSize(0); // turn off border wlg->SetFillStyle(0); f = theoryfiles1; gr=0; Bool_t isfill; while ( f && f->filename ) { gr=OneGraph(f); gr->SetLineWidth(2); isfill = kFALSE; if (gr) { TGraphAsymmErrors *egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetN()>1 && egr->GetEYhigh() && egr->GetEYhigh()[1]>0) { gr = toerror_band(egr); gr->SetFillStyle(3000+f->style); gr->SetFillStyle(1); gr->SetFillColor(gr->GetLineColor()); isfill = kTRUE; } if (f->lnpt) { wgr->Add(gr,f->lnpt); if( f->label[0] != 'x' ) wlg->AddEntry(gr,f->label,f->lnpt); } else if (gr->GetMarkerStyle()>=20) { wgr->Add(gr,"p"); if( f->label[0] != 'x' ) wlg->AddEntry(gr,f->label,"p"); } else { if( isfill ){ gr->SetLineStyle(0); wgr->Add(gr,"f"); // wgr->Add( new TGraph(*egr),"l"); if( f->label[0] != 'x' ) wlg->AddEntry(gr,f->label,"lf"); } else { wgr->Add(gr,"l"); if( f->label[0] != 'x' ) wlg->AddEntry(gr,f->label,"l"); } } } f++; } TPaveLabel *prelim = new TPaveLabel( 0.3204, 0.1886, 0.9310, 0.4643, "PRELIMINARY", "NDC" ); prelim->SetTextAngle(0); TColor *pink = new TColor(300, 1.0, 0.7, 0.7, "pink"); prelim->SetTextColor(300); prelim->SetFillStyle(0); prelim->SetBorderSize(0); #ifdef FAKE_SCHIAVILLA TGraph *schiagraph = draw_schiavilla(); schiagraph->Draw("F"); schiagraph = draw_schiavilla(1); schiagraph->Draw("C"); legThry->AddEntry(schiagraph, "d(e,e'd) T_{20} - Schiavilla & Sick", "LF"); #endif #ifdef PRELIMINARY prelim->Draw("same"); #endif TPaveLabel *nofsilab = new TPaveLabel( 0.4569, 0.1674, 0.7514, 0.2415, "No FSI Corrections", "NDC" ); nofsilab->SetFillStyle(0); nofsilab->SetBorderSize(0); nofsilab->SetTextColor(kRed); #ifdef NOFSI // nofsilab->Draw("same"); #endif #ifdef PQCD genf->Draw("same"); #endif mgrThry->Draw("c"); #ifdef GALSTER galster->Draw("same"); #endif // gen0->Draw("same"); #ifdef NEW_ROBERTS roberts_curve->Draw("same"); #endif // ourfit->Draw("same"); // bbba05->Draw("same"); //lomon->Draw("same"); // bandi->Draw("same"); #ifdef PQCD legThry->AddEntry(genf,"F_{2}/F_{1} #propto ln^{2}(Q^{2}/#Lambda^{2})/Q^{2}","l"); #endif #ifdef GALSTER legThry->AddEntry(galster,"Galster fit (1971)","l"); #endif // legThry->AddEntry(gen0,"G_{E}^{n} = 0","l"); #ifdef NEW_ROBERTS legThry->AddEntry(roberts_curve,"q(qq) Faddeev - I. Cloet, ANL","l"); #endif // legThry->AddEntry(bbba05,"BBBA05","l"); // legThry->AddEntry(lomon, "Lomon", "l"); // legThry->AddEntry(ourfit, "Our Fit", "l"); legThry->Draw(); legDta->Draw(); mgrDta->Draw("p"); legDta->Draw(); TEllipse *cir1 = new TEllipse(1.31, 0.0, 0.17, 0.0065); TEllipse *cir2 = new TEllipse(2.4, 0.0, 0.17, 0.0065); cir1->SetFillStyle(0); cir2->SetFillStyle(0); #ifdef PLOTKIN1 cir1->Draw("same"); // cir2->Draw("same"); // TPaveLabel *exacc = new TPaveLabel( 0.3779, 0.2691, 0.5963, 0.3114, "Expected Accuracy", "NDC"); TPaveLabel *exacc = new TPaveLabel( 0.2716, 0.2733, 0.4899, 0.3136, "Expected Accuracy", "NDC"); exacc->SetFillStyle(0); exacc->SetBorderSize(0); exacc->Draw("same"); #endif // draw a line at 1 cn->Modified(); cn->Update(); cn->SaveAs(Form("%s.pdf",psfile)); cn->SaveAs(Form("%s.eps",psfile)); // cn->SaveAs(Form("%s.root",psfile)); // gSystem->Exec(Form("./replace_symbols.pl %s.eps",psfile)); // cn->SaveAs("bogdan_gen.eps"); return; // LEAVING HERE // now an overlay, hopefully matching dimensions // remove everything but the graph cn->Update(); TList *clist = cn->GetListOfPrimitives(); TFrame* frame = cn->GetFrame(); for (int i=0; i<clist->GetSize(); ) { if (clist->At(i) != frame) { clist->RemoveAt(i); } else i++; } // draw markers in the corners TMarker *mkr = new TMarker(frame->GetX1(),frame->GetY1(),2); mkr->Draw(); mkr = new TMarker(frame->GetX2(),frame->GetY1(),2); mkr->Draw(); mkr = new TMarker(frame->GetX1(),frame->GetY2(),2); mkr->Draw(); mkr = new TMarker(frame->GetX2(),frame->GetY2(),2); mkr->Draw(); frame->SetLineColor(10); cn->Update(); datafile_t miller = { "figure_input/Miller/lattice.GEn.rtf","Miller", "[0]","[1]","[1]-[3]","[2]-[1]",0,0,1,3,"F" }; gr = OneGraph(&miller); TGraphAsymmErrors* egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetEYhigh() && egr->GetEYhigh()[egr->GetN()/2]>0) { gr = toerror_band(egr); gr->SetLineStyle(1); gr->SetFillColor(gr->GetLineColor()); gr->SetFillStyle(3000+miller.style); } gr->Draw("F"); cn->Update(); cn->SaveAs("gen_Miller_Overlay.pdf"); cn->SaveAs("gen_Miller_Overlay.root"); }
void fildir(){ TCanvas *c1 = new TCanvas("c1","ROOT FilDir description",700,900); c1->Range(1,1,19,24.5); TPaveLabel *title = new TPaveLabel(4,23,16,24.2,"ROOT File/Directory/Key description"); title->SetFillColor(16); title->Draw(); Int_t keycolor = 42; Int_t dircolor = 21; Int_t objcolor = 46; TPaveText *file = new TPaveText(2,19,6,22); file->SetFillColor(39); file->Draw(); file->SetTextSize(0.04); file->AddText("TFile"); file->AddText("Header"); TArrow *arrow = new TArrow(6,20.5,17,20.5,0.02,"|>"); arrow->SetFillStyle(1001); arrow->SetLineWidth(2); arrow->Draw(); TPaveText *free1 = new TPaveText(8,20,11,21); free1->SetFillColor(18); free1->Draw(); free1->AddText("First:Last"); TPaveText *free2 = new TPaveText(12,20,15,21); free2->SetFillColor(18); free2->Draw(); free2->AddText("First:Last"); TText *tfree = new TText(6.2,21.2,"fFree = TList of free blocks"); tfree->SetTextSize(0.02); tfree->Draw(); TText *tkeys = new TText(5.2,18.2,"fKeys = TList of Keys"); tkeys->SetTextSize(0.02); tkeys->Draw(); TText *tmemory = new TText(3.2,15.2,"fListHead = TList of Objects in memory"); tmemory->SetTextSize(0.02); tmemory->Draw(); arrow->DrawArrow(5,17,17,17,0.02,"|>"); TLine *line = new TLine(5,19,5,17); line->SetLineWidth(2); line->Draw(); TPaveText *key0 = new TPaveText(7,16,10,18); key0->SetTextSize(0.04); key0->SetFillColor(keycolor); key0->AddText("Key 0"); key0->Draw(); TPaveText *key1 = new TPaveText(12,16,15,18); key1->SetTextSize(0.04); key1->SetFillColor(keycolor); key1->AddText("Key 1"); key1->Draw(); line->DrawLine(3,19,3,14); line->DrawLine(3,14,18,14); TPaveText *obj0 = new TPaveText(5,13,8,15); obj0->SetFillColor(objcolor); obj0->AddText("Object"); obj0->Draw(); TPaveText *dir1 = new TPaveText(10,13,13,15); dir1->SetFillColor(dircolor); dir1->AddText("SubDir"); dir1->Draw(); TPaveText *obj1 = new TPaveText(15,13,18,15); obj1->SetFillColor(objcolor); obj1->AddText("Object"); obj1->Draw(); arrow->DrawArrow(12,11,17,11,0.015,"|>"); arrow->DrawArrow(11,9,17,9,0.015,"|>"); line->DrawLine(12,13,12,11); line->DrawLine(11,13,11,9); TPaveText *key2 = new TPaveText(14,10.5,16,11.5); key2->SetFillColor(keycolor); key2->AddText("Key 0"); key2->Draw(); TPaveText *obj2 = new TPaveText(14,8.5,16,9.5); obj2->SetFillColor(objcolor); obj2->AddText("Object"); obj2->Draw(); TLine *ldot = new TLine(10,15,2,11); ldot->SetLineStyle(2); ldot->Draw(); ldot->DrawLine(13,15,8,11); ldot->DrawLine(13,13,8,5); TPaveText *dirdata = new TPaveText(2,5,8,11); dirdata->SetTextAlign(12); dirdata->SetFillColor(dircolor); dirdata->Draw(); dirdata->SetTextSize(0.015); dirdata->AddText("fModified: True if directory is modified"); dirdata->AddText("fWritable: True if directory is writable"); dirdata->AddText("fDatimeC: Creation Date/Time"); dirdata->AddText("fDatimeM: Last mod Date/Time"); dirdata->AddText("fNbytesKeys: Number of bytes of key"); dirdata->AddText("fNbytesName : Header length up to title"); dirdata->AddText("fSeekDir: Start of Directory on file"); dirdata->AddText("fSeekParent: Start of Parent Directory"); dirdata->AddText("fSeekKeys: Pointer to Keys record"); TPaveText *keydata = new TPaveText(10,2,17,7); keydata->SetTextAlign(12); keydata->SetFillColor(keycolor); keydata->Draw(); ldot->DrawLine(14,11.5,10,7); ldot->DrawLine(16,11.5,17,7); keydata->SetTextSize(0.015); keydata->AddText("fNbytes: Size of compressed Object"); keydata->AddText("fObjLen: Size of uncompressed Object"); keydata->AddText("fDatime: Date/Time when written to store"); keydata->AddText("fKeylen: Number of bytes for the key"); keydata->AddText("fCycle : Cycle number"); keydata->AddText("fSeekKey: Pointer to Object on file"); keydata->AddText("fSeekPdir: Pointer to directory on file"); keydata->AddText("fClassName: 'TKey'"); keydata->AddText("fName: Object name"); keydata->AddText("fTitle: Object Title"); c1->Print("fildir.png"); }
void drawValueBox(double x1, double x2, double x3, int colour) { char optionfile[60]; std::vector<double> options; double delta1(0.), delta2(0.), delta3(0.), delta4(0.); double tsize(0.7); sprintf(optionfile,"./config/drawValueBox.dat"); readData(optionfile,options); delta1 = options[0]; delta2 = options[1]; delta3 = options[2]; delta4 = options[3]; tsize = options[4]; double xmin = x1 + delta1; double xmax = x1 + delta2; double ymin = x2 + delta3; double ymax = x2 + delta4; if ( x1 < 0 && x2 > 0) { xmin = x1 - delta1; xmax = x1 - delta2; } else if ( x1 < 0 && x2 < 0) { xmin = x1 - delta1; xmax = x1 - delta2; ymin = x2 - delta3; ymax = x2 - delta4; } else if ( x1 > 0 && x2 < 0) { ymin = x2 - delta3; ymax = x2 - delta4; } else if ( x1 == 0.0 ) { xmin = xmin - delta1; xmax = xmax ; } else if ( x2 == 0.0 ) { ymin = ymin - delta3; ymax = ymax ; } else {} char label[10]; sprintf(label,"%.1f",float(x3)); TPaveLabel *box = new TPaveLabel(xmin,ymin,xmax,ymax,label); box->SetBorderSize(0); box->SetTextFont(42); box->SetTextSize(tsize); box->SetTextAlign(22); box->SetTextColor(colour); if (colour == 1) box->SetFillStyle(4000); else { box->SetFillColor(10); box->SetTextColor(colour); box->SetBorderSize(1); } box->Draw("same"); TLine * ln = new TLine(x1,x2,xmin,ymin); ln->SetLineWidth(1); ln->SetLineStyle(1); ln->SetLineColor(14); ln->Draw("same"); }
void h1draw() { TString dir = gROOT->GetTutorialDir(); dir.Append("/hsimple.C"); dir.ReplaceAll("/./","/"); if (gBenchmark->GetBench("hsimple") < 0) gInterpreter->LoadMacro(dir.Data()); TFile *example = (TFile*)gROOT->ProcessLineFast("hsimple(1)"); if (!example) return; example->ls(); TH1 *hpx = (TH1*)example->Get("hpx"); TCanvas *c1 = new TCanvas("c1","Histogram Drawing Options",200,10,700,900); TPad *pad1 = new TPad("pad1", "The pad with the function",0.03,0.62,0.50,0.92); TPad *pad2 = new TPad("pad2", "The pad with the histogram",0.51,0.62,0.98,0.92); TPad *pad3 = new TPad("pad3", "The pad with the histogram",0.03,0.02,0.97,0.57); pad1->Draw(); pad2->Draw(); pad3->Draw(); // Draw a global picture title TPaveLabel *title = new TPaveLabel(0.1,0.94,0.9,0.98, "Drawing options for one dimensional histograms"); title->SetTextFont(52); title->Draw(); // Draw histogram hpx in first pad with the default option. pad1->cd(); pad1->GetFrame()->SetFillColor(18); hpx->SetFillColor(45); hpx->DrawCopy(); TPaveLabel *label1 = new TPaveLabel(-3.5,700,-1,800,"Default option"); label1->Draw(); // Draw hpx as a lego. Clicking on the lego area will show // a "transparent cube" to guide you rotating the lego in real time. pad2->cd(); hpx->DrawCopy("lego1"); TPaveLabel *label2 = new TPaveLabel(-0.72,0.74,-0.22,0.88,"option Lego1"); label2->Draw(); TPaveLabel *label2a = new TPaveLabel(-0.93,-1.08,0.25,-0.92, "Click on lego to rotate"); label2a->Draw(); // Draw hpx with its errors and a marker. pad3->cd(); pad3->SetGridx(); pad3->SetGridy(); hpx->SetMarkerStyle(21); hpx->Draw("e1p"); TPaveLabel *label3 = new TPaveLabel(2,600,3.5,650,"option e1p"); label3->Draw(); // The following illustrates how to add comments using a PaveText. // Attributes of text/lines/boxes added to a PaveText can be modified. // The AddText function returns a pointer to the added object. TPaveText *pave = new TPaveText(-3.78,500,-1.2,750); TText *t1=pave->AddText("You can move"); t1->SetTextColor(4); t1->SetTextSize(0.05); pave->AddText("Title and Stats pads"); pave->AddText("X and Y axis"); pave->AddText("You can modify bin contents"); pave->Draw(); c1->Update(); }
void ClassTree() { TCanvas *ClassTree = new TCanvas("ClassTree", "",186,135,594,449); ClassTree->SetHighLightColor(2); ClassTree->Range(0,5,20,20); ClassTree->SetFillColor(33); ClassTree->SetBorderSize(2); TLine *line = new TLine(0.5,18.15,4.4,18.15); line->Draw(); line = new TLine(4.4,17.725,4.4,18.575); line->Draw(); TPaveLabel *pl = new TPaveLabel(1,17.895,4.205,18.405,"TArray","br"); pl->SetFillColor(30); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(0.5,16.875,1,16.875); line->Draw(); pl = new TPaveLabel(1,16.62,4.205,17.13,"TAttFill","br"); pl->SetFillColor(30); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(0.5,16.025,1,16.025); line->Draw(); pl = new TPaveLabel(1,15.77,4.205,16.28,"TAttLine","br"); pl->SetFillColor(30); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(0.5,15.175,1,15.175); line->Draw(); pl = new TPaveLabel(1,14.92,4.205,15.43,"TAttMarker","br"); pl->SetFillColor(30); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(0.5,9.775,4.4,9.775); line->Draw(); line = new TLine(4.4,7.65,4.4,12.325); line->Draw(); pl = new TPaveLabel(1,9.52,4.205,10.03,"TObject","br"); pl->SetFillColor(5); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(4.4,12.325,4.9,12.325); line->Draw(); pl = new TPaveLabel(4.9,12.07,8.105,12.58,"AliArrayI","br"); pl->SetFillColor(18); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(4.4,11.475,4.9,11.475); line->Draw(); pl = new TPaveLabel(4.9,11.22,8.105,11.73,"AliArrayS","br"); pl->SetFillColor(18); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(4.4,18.575,4.9,18.575); line->Draw(); pl = new TPaveLabel(4.9,18.32,8.105,18.83,"TArrayI","br"); pl->SetFillColor(30); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(4.4,17.725,4.9,17.725); line->Draw(); pl = new TPaveLabel(4.9,17.47,8.105,17.98,"TArrayS","br"); pl->SetFillColor(30); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(4.4,10.2,8.3,10.2); line->Draw(); pl = new TPaveLabel(4.9,9.945,8.105,10.455,"TCollection","br"); pl->SetFillColor(18); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(4.4,7.65,8.3,7.65); line->Draw(); line = new TLine(8.3,6.8,8.3,8.075); line->Draw(); pl = new TPaveLabel(4.9,7.395,8.105,7.905,"TNamed","br"); pl->SetFillColor(18); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(8.3,8.075,12.2,8.075); line->Draw(); pl = new TPaveLabel(8.8,7.82,12.005,8.33,"AliSegmentArray","br"); pl->SetFillColor(18); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(8.3,10.2,12.2,10.2); line->Draw(); pl = new TPaveLabel(8.8,9.945,12.005,10.455,"TSeqCollection","br"); pl->SetFillColor(18); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(8.3,6.8,8.8,6.8); line->Draw(); pl = new TPaveLabel(8.8,6.545,12.005,7.055,"TTree","br"); pl->SetFillColor(18); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(12.2,8.075,12.7,8.075); line->Draw(); pl = new TPaveLabel(12.7,7.82,15.905,8.33,"AliTPCClustersArray","br"); pl->SetFillColor(18); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(12.2,10.2,16.1,10.2); line->Draw(); pl = new TPaveLabel(12.7,9.945,15.905,10.455,"TObjArray","br"); pl->SetFillColor(18); pl->SetTextSize(0.9); pl->Draw(); line = new TLine(16.1,10.2,16.6,10.2); line->Draw(); pl = new TPaveLabel(16.6,9.945,19.805,10.455,"TClonesArray","br"); pl->SetFillColor(18); pl->SetTextSize(0.9); pl->Draw(); pl = new TPaveLabel(0.1,19.1,18.2,19.9,"*AliSegmet:*AliSegmentArray:*AliArrayI:*AliArrayS:TTree:*TObjArray","br"); pl->SetFillColor(42); pl->SetTextSize(0.7); pl->Draw(); line = new TLine(11.4041,6.8,14.3025,10.2); line->SetLineColor(6); line->SetLineStyle(3); line->Draw(); line = new TLine(11.4842,6.8,14.3025,10.2); line->SetLineColor(6); line->SetLineStyle(3); line->Draw(); line = new TLine(6.5025,12.325,6.5025,18.575); line->SetLineColor(4); line->SetLineStyle(2); line->Draw(); line = new TLine(6.5025,11.475,6.5025,17.725); line->SetLineColor(4); line->SetLineStyle(2); line->Draw(); line = new TLine(10.4025,6.8,2.6025,16.025); line->SetLineColor(4); line->SetLineStyle(2); line->Draw(); line = new TLine(10.4025,6.8,2.6025,16.875); line->SetLineColor(4); line->SetLineStyle(2); line->Draw(); line = new TLine(10.4025,6.8,2.6025,15.175); line->SetLineColor(4); line->SetLineStyle(2); line->Draw(); TArrow *arrow = new TArrow(5.43417,10.2,6.5025,10.2,0.008,"|>"); arrow->SetFillColor(2); arrow->SetFillStyle(1001); arrow->SetLineColor(2); arrow->Draw(); arrow = new TArrow(6.85861,10.2,2.6025,9.775,0.008,"|>"); arrow->SetFillColor(2); arrow->SetFillStyle(1001); arrow->SetLineColor(2); arrow->Draw(); arrow = new TArrow(9.60125,8.075,14.3025,10.2,0.008,"|>"); arrow->SetFillColor(2); arrow->SetFillStyle(1001); arrow->SetLineColor(2); arrow->Draw(); arrow = new TArrow(10.1354,8.075,6.5025,12.325,0.008,"|>"); arrow->SetFillColor(2); arrow->SetFillStyle(1001); arrow->SetLineColor(2); arrow->Draw(); arrow = new TArrow(11.2037,8.075,10.4025,6.8,0.008,"|>"); arrow->SetFillColor(2); arrow->SetFillStyle(1001); arrow->SetLineColor(2); arrow->Draw(); arrow = new TArrow(13.9019,10.2,2.6025,9.775,0.008,"|>"); arrow->SetFillColor(2); arrow->SetFillStyle(1001); arrow->SetLineColor(2); arrow->Draw(); arrow = new TArrow(19.2708,10.2,14.3025,10.2,0.008,"|>"); arrow->SetFillColor(2); arrow->SetFillStyle(1001); arrow->SetLineColor(2); arrow->Draw(); ClassTree->Modified(); ClassTree->cd(); }
void EpEd() { TCanvas *c1 = new TCanvas("c1","multipads",700,700); gStyle->SetPadBorderMode(0); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetFrameLineWidth(1); c1->Divide(1,2,0.001,0.000001); c1->cd(1); gPad->SetTopMargin(0.2); gPad->SetBottomMargin(0.0); gPad->SetRightMargin(0.15); /// Near site { TFile f("../../data/Sample/P12e_1.5MeV/H/Near.root"); h2dAccSum->GetXaxis()->SetRangeUser(1.3,10); h2dAccSum->GetYaxis()->SetRangeUser(1.3,10.5); //h2dAccSum->GetZaxis()->SetRangeUser(-20,1.5308177e+03); h2dAccSum->GetYaxis()->SetLabelSize(0.06); h2dAccSum->GetYaxis()->SetTitleSize(0.06); h2dAccSum->GetYaxis()->SetTitleOffset(0.5); h2dAccSum->GetZaxis()->SetLabelSize(0.05); h2dAccSum->GetZaxis()->SetTitleSize(0.05); //h2dAccSum->SetMinimum(0); // What is this principle? h2dAccSum->DrawCopy("col"); TExec *ex1 = new TExec("ex1","Pal1();"); ex1->Draw(); h2dAccSum->SetContour(500); h2dAccSum->DrawCopy("colz same"); h2dAccSum->DrawCopy("same axis"); // top frame is blocked. Now redraw it. TLine *line = new TLine; line->DrawLine(1.3,10.6, 10.1,10.6); line->DrawLine(10.1,10.6, 10.1,1.3); TPaveLabel *label = new TPaveLabel(8,8.7,10,10.2,"Near site"); label->SetFillColor(0); label->SetShadowColor(0); label->SetTextSize(0.5); label->Draw(); f.Close(); } c1->cd(2); gPad->SetTopMargin(0.0); gPad->SetRightMargin(0.15); gPad->SetBottomMargin(0.2); /// Far site { TFile ff("../../data/Sample/P12e_1.5MeV/H/EH3.root"); h2dAccSum->GetXaxis()->SetRangeUser(1.3,10); h2dAccSum->GetYaxis()->SetRangeUser(1.3,10.5); h2dAccSum->GetXaxis()->SetLabelSize(0.06); h2dAccSum->GetXaxis()->SetTitleSize(0.06); h2dAccSum->GetYaxis()->SetLabelSize(0.06); h2dAccSum->GetYaxis()->SetTitleSize(0.06); h2dAccSum->GetYaxis()->SetTitleOffset(0.5); h2dAccSum->GetZaxis()->SetLabelSize(0.05); h2dAccSum->GetZaxis()->SetTitleSize(0.05); // What is this principle? h2dAccSum->DrawCopy("col"); TExec *ex2 = new TExec("ex2","Pal2();"); ex2->Draw(); h2dAccSum->SetContour(500); h2dAccSum->DrawCopy("same colz"); h2dAccSum->DrawCopy("same axis"); // top frame is blocked. Now redraw it. TLine *line = new TLine; line->DrawLine(1.3,10.6, 10.1,10.6); line->DrawLine(10.1,10.6, 10.1,1.3); TPaveLabel *label = new TPaveLabel(8,8.7,10,10.2,"Far site"); label->SetFillColor(0); label->SetShadowColor(0); label->SetTextSize(0.5); label->Draw(); ff.Close(); } }
void tree() { // // This macro displays the Tree data structures //Author: Rene Brun TCanvas* c1 = new TCanvas("c1","Tree Data Structure",200,10,750,940); c1->Range(0,-0.1,1,1.15); gBenchmark->Start("tree"); Int_t branchcolor = 26; Int_t leafcolor = 30; Int_t basketcolor = 42; Int_t offsetcolor = 43; TPaveLabel* title = new TPaveLabel(.3,1.05,.8,1.13,c1->GetTitle()); title->SetFillColor(16); title->Draw(); TPaveText* treePave = new TPaveText(.01,.75,.15,1.00); treePave->SetFillColor(18); treePave->SetTextAlign(12); TText *tnt = treePave->AddText("Tree"); tnt->SetTextAlign(22); tnt->SetTextSize(0.030); treePave->AddText("fScanField"); treePave->AddText("fMaxEventLoop"); treePave->AddText("fMaxVirtualSize"); treePave->AddText("fEntries"); treePave->AddText("fDimension"); treePave->AddText("fSelectedRows"); treePave->Draw(); TPavesText* farm = new TPavesText(.01,1.02,.15,1.1,9,"tr"); TText *tfarm = farm->AddText("CHAIN"); tfarm->SetTextSize(0.024); farm->AddText("Collection"); farm->AddText("of Trees"); farm->Draw(); TLine* llink = new TLine(.15,.92,.80,.92); llink->SetLineWidth(2); llink->SetLineColor(1); llink->Draw(); llink->DrawLine(.21,.87,.21,.275); llink->DrawLine(.23,.87,.23,.375); llink->DrawLine(.25,.87,.25,.775); llink->DrawLine(.41,.25,.41,-.025); llink->DrawLine(.43,.25,.43,.075); llink->DrawLine(.45,.25,.45,.175); TPaveLabel* branch0 = new TPaveLabel(.20,.87,.35,.97,"Branch 0"); branch0->SetTextSize(0.35); branch0->SetFillColor(branchcolor); branch0->Draw(); TPaveLabel* branch1 = new TPaveLabel(.40,.87,.55,.97,"Branch 1"); branch1->SetTextSize(0.35); branch1->SetFillColor(branchcolor); branch1->Draw(); TPaveLabel* branch2 = new TPaveLabel(.60,.87,.75,.97,"Branch 2"); branch2->SetTextSize(0.35); branch2->SetFillColor(branchcolor); branch2->Draw(); TPaveLabel* branch3 = new TPaveLabel(.80,.87,.95,.97,"Branch 3"); branch3->SetTextSize(0.35); branch3->SetFillColor(branchcolor); branch3->Draw(); TPaveLabel* leaf0 = new TPaveLabel(.4,.75,.5,.8,"Leaf 0"); leaf0->SetFillColor(leafcolor); leaf0->Draw(); TPaveLabel* leaf1 = new TPaveLabel(.6,.75,.7,.8,"Leaf 1"); leaf1->SetFillColor(leafcolor); leaf1->Draw(); TPaveLabel* leaf2 = new TPaveLabel(.8,.75,.9,.8,"Leaf 2"); leaf2->SetFillColor(leafcolor); leaf2->Draw(); TPaveText* firstevent = new TPaveText(.4,.35,.9,.4); firstevent->AddText("First event of each basket"); firstevent->AddText("Array of fMaxBaskets Integers"); firstevent->SetFillColor(basketcolor); firstevent->Draw(); TPaveLabel* basket0 = new TPaveLabel(.4,.25,.5,.3,"Basket 0"); basket0->SetFillColor(basketcolor); basket0->Draw(); TPaveLabel* basket1 = new TPaveLabel(.6,.25,.7,.3,"Basket 1"); basket1->SetFillColor(basketcolor); basket1->Draw(); TPaveLabel* basket2 = new TPaveLabel(.8,.25,.9,.3,"Basket 2"); basket2->SetFillColor(basketcolor); basket2->Draw(); TPaveText* offset = new TPaveText(.55,.15,.9,.2); offset->AddText("Offset of events in fBuffer"); offset->AddText("Array of fEventOffsetLen Integers"); offset->AddText("(if variable length structure)"); offset->SetFillColor(offsetcolor); offset->Draw(); TPaveText* buffer = new TPaveText(.55,.05,.9,.1); buffer->AddText("Basket buffer"); buffer->AddText("Array of fBasketSize chars"); buffer->SetFillColor(offsetcolor); buffer->Draw(); TPaveText* zipbuffer = new TPaveText(.55,-.05,.75,.0); zipbuffer->AddText("Basket compressed buffer"); zipbuffer->AddText("(if compression)"); zipbuffer->SetFillColor(offsetcolor); zipbuffer->Draw(); TArrow* ar1 = new TArrow(); ar1->SetLineWidth(2); ar1->SetLineColor(1); ar1->SetFillStyle(1001); ar1->SetFillColor(1); ar1->DrawArrow(.21,.275,.39,.275,0.015,"|>"); ar1->DrawArrow(.23,.375,.39,.375,0.015,"|>"); ar1->DrawArrow(.25,.775,.39,.775,0.015,"|>"); ar1->DrawArrow(.50,.775,.59,.775,0.015,"|>"); ar1->DrawArrow(.70,.775,.79,.775,0.015,"|>"); ar1->DrawArrow(.50,.275,.59,.275,0.015,"|>"); ar1->DrawArrow(.70,.275,.79,.275,0.015,"|>"); ar1->DrawArrow(.45,.175,.54,.175,0.015,"|>"); ar1->DrawArrow(.43,.075,.54,.075,0.015,"|>"); ar1->DrawArrow(.41,-.025,.54,-.025,0.015,"|>"); TLine* ldot = new TLine(.95,.92,.99,.92); ldot->SetLineStyle(3); ldot->Draw(); ldot->DrawLine(.9,.775,.99,.775); ldot->DrawLine(.9,.275,.99,.275); ldot->DrawLine(.55,.05,.55,0); ldot->DrawLine(.9,.05,.75,0); TText* pname = new TText(.46,.21,"fEventOffset"); pname->SetTextFont(72); pname->SetTextSize(0.018); pname->Draw(); pname->DrawText(.44,.11,"fBuffer"); pname->DrawText(.42,.01,"fZipBuffer"); pname->DrawText(.26,.81,"fLeaves = TObjArray of TLeaf"); pname->DrawText(.24,.40,"fBasketEvent"); pname->DrawText(.22,.31,"fBaskets = TObjArray of TBasket"); pname->DrawText(.20,1.0,"fBranches = TObjArray of TBranch"); TPaveText* ntleaf = new TPaveText(0.30,.42,.62,.7); ntleaf->SetTextSize(0.014); ntleaf->SetFillColor(leafcolor); ntleaf->SetTextAlign(12); ntleaf->AddText("fLen: number of fixed elements"); ntleaf->AddText("fLenType: number of bytes of data type"); ntleaf->AddText("fOffset: relative to Leaf0-fAddress"); ntleaf->AddText("fNbytesIO: number of bytes used for I/O"); ntleaf->AddText("fIsPointer: True if pointer"); ntleaf->AddText("fIsRange: True if leaf has a range"); ntleaf->AddText("fIsUnsigned: True if unsigned"); ntleaf->AddText("*fLeafCount: points to Leaf counter"); ntleaf->AddText(" "); ntleaf->AddLine(0,0,0,0); ntleaf->AddText("fName = Leaf name"); ntleaf->AddText("fTitle = Leaf type (see Type codes)"); ntleaf->Draw(); TPaveText* type = new TPaveText(.65,.42,.95,.7); type->SetTextAlign(12); type->SetFillColor(leafcolor); type->AddText(" "); type->AddText("C : a character string"); type->AddText("B : an 8 bit signed integer"); type->AddText("b : an 8 bit unsigned integer"); type->AddText("S : a 16 bit signed short integer"); type->AddText("s : a 16 bit unsigned short integer"); type->AddText("I : a 32 bit signed integer"); type->AddText("i : a 32 bit unsigned integer"); type->AddText("F : a 32 bit floating point"); type->AddText("D : a 64 bit floating point"); type->AddText("TXXXX : a class name TXXXX"); type->Draw(); TPaveLabel* typecode = new TPaveLabel(.7,.68,.9,.72,"fType codes"); typecode->SetFillColor(leafcolor); typecode->Draw(); ldot->DrawLine(.4,.75,.30,.7); ldot->DrawLine(.5,.75,.62,.7); TPaveText* ntbasket = new TPaveText(0.02,-0.07,0.35,.25); ntbasket->SetFillColor(basketcolor); ntbasket->SetTextSize(0.014); ntbasket->SetTextAlign(12); ntbasket->AddText("fNbytes: Size of compressed Basket"); ntbasket->AddText("fObjLen: Size of uncompressed Basket"); ntbasket->AddText("fDatime: Date/Time when written to store"); ntbasket->AddText("fKeylen: Number of bytes for the key"); ntbasket->AddText("fCycle : Cycle number"); ntbasket->AddText("fSeekKey: Pointer to Basket on file"); ntbasket->AddText("fSeekPdir: Pointer to directory on file"); ntbasket->AddText("fClassName: 'TBasket'"); ntbasket->AddText("fName: Branch name"); ntbasket->AddText("fTitle: TreePave name"); ntbasket->AddText(" "); ntbasket->AddLine(0,0,0,0); ntbasket->AddText("fNevBuf: Number of events in Basket"); ntbasket->AddText("fLast: pointer to last used byte in Basket"); ntbasket->Draw(); ldot->DrawLine(.4,.3,0.02,0.25); ldot->DrawLine(.5,.25,0.35,-.07); ldot->DrawLine(.5,.3,0.35,0.25); TPaveText* ntbranch = new TPaveText(0.02,0.40,0.18,0.68); ntbranch->SetFillColor(branchcolor); ntbranch->SetTextSize(0.015); ntbranch->SetTextAlign(12); ntbranch->AddText("fBasketSize"); ntbranch->AddText("fEventOffsetLen"); ntbranch->AddText("fMaxBaskets"); ntbranch->AddText("fEntries"); ntbranch->AddText("fAddress of Leaf0"); ntbranch->AddText(" "); ntbranch->AddLine(0,0,0,0); ntbranch->AddText("fName: Branchname"); ntbranch->AddText("fTitle: leaflist"); ntbranch->Draw(); ldot->DrawLine(.2,.97,.02,.68); ldot->DrawLine(.35,.97,.18,.68); ldot->DrawLine(.35,.87,.18,.40); TPavesText* basketstore = new TPavesText(.8,-0.088,0.952,-0.0035,7,"tr"); basketstore->SetFillColor(28); basketstore->AddText("Baskets"); basketstore->AddText("Stores"); basketstore->Draw(); c1->Update(); gBenchmark->Show("treePave"); }
void memstat(double update=0.01, const char* fname="*") { // Open the memstat data file, then call TTree::Draw to precompute // the arrays of positions and nbytes per entry. // update is the time interval in the data file in seconds after which // the display is updated. For example is the job producing the memstat.root file // took 100s to execute, an update of 0.1s will generate 1000 time views of // the memory use. // if fname=="*" (default), the most recent file memstat*.root will be taken. TString s; if (!fname || strlen(fname) <5 || strstr(fname,"*")) { //take the most recent file memstat*.root s = gSystem->GetFromPipe("ls -lrt memstat*.root"); Int_t ns = s.Length(); fname = strstr(s.Data()+ns-25,"memstat"); } printf("Analyzing file: %s\n",fname); f = TFile::Open(fname); if (!f) { printf("Cannot open file %s\n",fname); return; } T = (TTree*)f->Get("T"); if (!T) { printf("cannot find the TMemStat TTree named T in file %s\n",fname); return; } if (update <= 0) { printf("Illegal update value %g, changed to 0.01\n",update); update = 0.01; } if (update < 0.001) printf("Warning update parameter is very small, processing may be slow\n"); Long64_t nentries = T->GetEntries(); T->SetEstimate(nentries+10); Long64_t nsel = T->Draw("pos:nbytes:time:btid","","goff"); //now we compute the best binning for the histogram Int_t nbytes; Double_t pos; V1 = T->GetV1(); V2 = T->GetV2(); V3 = T->GetV3(); V4 = T->GetV4(); Long64_t imean = (Long64_t)TMath::Mean(nsel,V1); Long64_t irms = (Long64_t)TMath::RMS(nsel,V1); //Long64_t bw = 10000; Long64_t bw = 1000; imean = imean - imean%bw; irms = irms -irms%bw; Int_t nbins = Int_t(4*irms/bw); Long64_t ivmin = imean -bw*nbins/2; Long64_t ivmax = ivmin+bw*nbins; if (ivmax > 2000000000 && ivmin <2000000000) { //the data set has been likely generated on a 32 bits machine //we are mostly interested by the small allocations, so we select //only values below 2 GBytes printf("memory locations above 2GBytes will be ignored\n"); nsel = T->Draw("pos:nbytes:time:btid","pos <2e9","goff"); V1 = T->GetV1(); V2 = T->GetV2(); V3 = T->GetV3(); V4 = T->GetV4(); imean = (Long64_t)TMath::Mean(nsel,V1); irms = (Long64_t)TMath::RMS(nsel,V1); bw = 10000; imean = imean - imean%bw; irms = irms -irms%bw; nbins = Int_t(4*irms/bw); ivmin = imean -bw*nbins/2; ivmax = ivmin+bw*nbins; } update *= 0.0001*V3[nsel-1]; //convert time per cent in seconds Long64_t nvm = Long64_t(ivmax-ivmin+1); Long64_t *nbold = new Long64_t[nvm]; Int_t *ientry = new Int_t[nvm]; memset(nbold,0,nvm*8); Double_t dv = (ivmax-ivmin)/nbins; h = new TH1D("h",Form("%s;pos;per cent of pages used",fname),nbins,ivmin,ivmax); TAxis *axis = h->GetXaxis(); gStyle->SetOptStat("ie"); h->SetFillColor(kRed); h->SetMinimum(0); h->SetMaximum(100); halloc = new TH1D("halloc",Form("%s;pos;number of mallocs",fname),nbins,ivmin,ivmax); hfree = new TH1D("hfree", Form("%s;pos;number of frees",fname),nbins,ivmin,ivmax); //open a canvas and draw the empty histogram TCanvas *c1 = new TCanvas("c1","c1",1200,600); c1->SetFrameFillColor(kYellow-3); c1->SetGridx(); c1->SetGridy(); h->Draw(); //create a TPaveText to show the summary results TPaveText *pvt = new TPaveText(.5,.9,.75,.99,"brNDC"); pvt->Draw(); //create a TPaveLabel to show the time TPaveLabel *ptime = new TPaveLabel(.905,.7,.995,.76,"time","brNDC"); ptime->SetFillColor(kYellow-3); ptime->Draw(); //draw producer identifier TNamed *named = (TNamed*)T->GetUserInfo()->FindObject("SysInfo"); TText tmachine; tmachine.SetTextSize(0.02); tmachine.SetNDC(); if (named) tmachine.DrawText(0.01,0.01,named->GetTitle()); //start loop on selected rows Int_t bin,nb=0,j; Long64_t ipos; Double_t dbin,rest,time; Double_t updateLast = 0; Int_t nleaks = 0; Int_t i; for (i=0;i<nsel;i++) { pos = V1[i]; ipos = (Long64_t)(pos-ivmin); nbytes = (Int_t)V2[i]; time = 0.0001*V3[i]; bin = axis->FindBin(pos); if (bin<1 || bin>nbins) continue; dbin = axis->GetBinUpEdge(bin)-pos; if (nbytes > 0) { halloc->Fill(pos); if (dbin > nbytes) dbin = nbytes; //fill bytes in the first page h->AddBinContent(bin,100*dbin/dv); //fill bytes in full following pages nb = Int_t((nbytes-dbin)/dv); if (bin+nb >nbins) nb = nbins-bin; for (j=1;j<=nb;j++) h->AddBinContent(bin+j,100); //fill the bytes remaining in last page rest = nbytes-nb*dv-dbin; if (rest > 0) h->AddBinContent(bin+nb+1,100*rest/dv); //we save nbytes at pos. This info will be used when we free this slot if (nbold[ipos] > 0) printf("reallocating %d bytes (was %lld) at %lld, entry=%d\n",nbytes,nbold[ipos],ipos,i); if (nbold[ipos] == 0) { nleaks++; //save the Tree entry number where we made this allocation ientry[ipos] = i; } nbold[ipos] = nbytes; } else { hfree->Fill(pos); nbytes = nbold[ipos]; if (bin+nb >nbins) nb = nbins-bin; nbold[ipos] = 0; nleaks--; if (nbytes <= 0) continue; //fill bytes free in the first page if (dbin > nbytes) dbin = nbytes; h->AddBinContent(bin,-100*dbin/dv); //fill bytes free in full following pages nb = Int_t((nbytes-dbin)/dv); if (bin+nb >nbins) nb = nbins-bin; for (j=1;j<=nb;j++) h->AddBinContent(bin+j,-100); //fill the bytes free in in last page rest = nbytes-nb*dv-dbin; if (rest > 0) h->AddBinContent(bin+nb+1,-100*rest/dv); } if (time -updateLast > update) { //update canvas at regular intervals updateLast = time; h->SetEntries(i); c1->Modified(); pvt->GetListOfLines()->Delete(); Double_t mbytes = 0; Int_t nonEmpty = 0; Double_t w; for (Int_t k=1;k<nbins;k++) { w = h->GetBinContent(k); if (w > 0) { nonEmpty++; mbytes += 0.01*w*dv; } } Double_t occupancy = mbytes/(nonEmpty*0.01*dv); pvt->AddText(Form("memory used = %g Mbytes",mbytes*1e-6)); pvt->AddText(Form("page occupancy = %f per cent",occupancy)); pvt->AddText("(for non empty pages only)"); ptime->SetLabel(Form("%g sec",time)); c1->Update(); gSystem->ProcessEvents(); } } h->SetEntries(nsel); Int_t nlmax = nleaks; nleaks += 1000; Int_t *lindex = new Int_t[nleaks]; Int_t *entry = new Int_t[nleaks]; Int_t *ileaks = new Int_t[nleaks]; nleaks =0; for (Int_t ii=0;ii<nvm;ii++) { if (nbold[ii] > 0) { ileaks[nleaks] = (Int_t)nbold[ii]; entry[nleaks] = ientry[ii]; nleaks++; if (nleaks > nlmax) break; } } TMath::Sort(nleaks,ileaks,lindex); hentry = new TH1I("hentry","leak entry index",nleaks,0,nleaks); hleaks = new TH1I("hleaks","leaks;leak number;nbytes in leak",nleaks,0,nleaks); for (Int_t k=0;k<nleaks;k++) { Int_t kk = lindex[k]; i = entry[kk]; hentry->SetBinContent(k+1,i); hleaks->SetBinContent(k+1,ileaks[kk]); } hentry->SetEntries(nleaks); hleaks->SetEntries(nleaks); //open a second canvas and draw the histogram with leaks in decreasing order TCanvas *c2 = new TCanvas("c2","c2",1200,600); c2->SetFrameFillColor(kCyan-6); c2->SetGridx(); c2->SetGridy(); c2->SetLogy(); hleaks->SetFillColor(kRed-3); if (nleaks > 1000) hleaks->GetXaxis()->SetRange(1,1000); hleaks->Draw(); //draw producer identifier if (named) tmachine.DrawText(0.01,0.01,named->GetTitle()); //construct the tooltip TRootCanvas *rc = (TRootCanvas *)c2->GetCanvasImp(); TGMainFrame *frm = dynamic_cast<TGMainFrame *>(rc); // create the tooltip with a timeout of 250 ms if (!gTip) gTip = new TGToolTip(gClient->GetDefaultRoot(), frm, "", 250); c2->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", 0, 0, "EventInfo(Int_t, Int_t, Int_t, TObject*)"); }