// File: plotFrc.C // Author: Zaher Salman // Date: 11/01/2012 // Purpose: ROOT macro to read and plot implantation fractions in layers from trimsp calculation // Assume following file Format: // // $Id$ // // Energy SigmaE Alpha SigAlpha ntot imp backsc trans tried negE impL1 impL2 impL3 impL4 impL5 impL6 impL7 range straggeling Eback sigEback Etrans SigEtrans red. E PRC // 15.00 0.45 0.00 15.00 100000 98362 1638 0 100000 0 98362 0 0 0 0 0 0 0.6664E+03 0.1799E+03 0.4980E+04 0.4250E+04 0.0000E+00 0.0000E+00 0.0000E+00 0.0000E+00 // plotFrc(file_name) void plotFrc(char *FileName) { TObjString *ostr; TString str,xlab,ylab; TString line, label, treeLabel; TString rootFileName; TObjArray *token,*labels; TObjString *strtoken; Int_t nPars = 0; Int_t ntokens = 0; Int_t i = 0; Int_t nline=0; Ssiz_t pos; Double_t x[100],yl1[100],yl2[100],yl3[100],yl4[100],yl5[100],yl6[100],yl7[100]; Int_t Flag[6]=0; FILE *fp = fopen(FileName,"r"); if ( fp == NULL ){ printf("File %s does not exist!\n", FileName); return; } while (line.Gets(fp)){ if ( nline==0 ){ // First line, get data labels nline++; labels = line.Tokenize(" "); ntokens = labels->GetEntries(); nPars=ntokens; ostr = dynamic_cast(labels->At(0)); xlab = ostr->GetString(); ylab = ostr->GetString(); } else { token = line.Tokenize(" "); ntokens = token->GetEntries(); strtoken = (TObjString*) token->At(0); label = strtoken->GetName(); x[i] = label.Atof(); // Plot all layers for now. Maybe stop when sum is zero in the future // Layers start from column # 10 up to 16. // for (col=10;col<17;col++) { strtoken = (TObjString*) token->At(10); label = strtoken->GetName(); yl1[i] = label.Atof(); if (yl1[i]>0) { Flag[0]=1;} strtoken = (TObjString*) token->At(11); label = strtoken->GetName(); yl2[i] = label.Atof(); if (yl2[i]>0) { Flag[1]=1;} strtoken = (TObjString*) token->At(12); label = strtoken->GetName(); yl3[i] = label.Atof(); if (yl3[i]>0) { Flag[2]=1;} strtoken = (TObjString*) token->At(13); label = strtoken->GetName(); yl4[i] = label.Atof(); if (yl4[i]>0) { Flag[3]=1;} strtoken = (TObjString*) token->At(14); label = strtoken->GetName(); yl5[i] = label.Atof(); if (yl5[i]>0) { Flag[4]=1;} strtoken = (TObjString*) token->At(15); label = strtoken->GetName(); yl6[i] = label.Atof(); if (yl6[i]>0) { Flag[5]=1;} strtoken = (TObjString*) token->At(16); label = strtoken->GetName(); yl7[i] = label.Atof(); if (yl7[i]>0) { Flag[6]=1;} //} nline++; i++; } } TCanvas *c = new TCanvas("c",str); c->Show(); TLegend *legend = new TLegend(0.8, 0.8, 0.95, 0.95); legend->SetFillColor(TColor::GetColor(255,255,255)); // white if (Flag[0]==1){ TGraph *gr1 = new TGraph(i-1,x,yl1); gr1->GetXaxis()->SetTitle(xlab); gr1->GetYaxis()->SetTitle("Implanted Fraction"); gr1->Draw("APC"); gr1->SetMarkerStyle(20); gr1->SetMarkerColor(TColor::kRed); gr1->SetLineColor(TColor::kRed); legend->AddEntry(gr1,"Layer 1"); } if (Flag[1]==1){ TGraph *gr2 = new TGraph(i-1,x,yl2); gr2->SetMarkerStyle(20); gr2->SetMarkerColor(TColor::kGreen); gr2->SetLineColor(TColor::kGreen); gr2->Draw("PC"); legend->AddEntry(gr2,"Layer 2"); } if (Flag[2]==1){ TGraph *gr3 = new TGraph(i-1,x,yl3); gr3->SetMarkerStyle(20); gr3->SetMarkerColor(TColor::kBlue); gr3->SetLineColor(TColor::kBlue); gr3->Draw("PC"); legend->AddEntry(gr3,"Layer 3"); } if (Flag[3]==1){ TGraph *gr4 = new TGraph(i-1,x,yl4); gr4->SetMarkerStyle(20); gr4->SetMarkerColor(TColor::kMagenta); gr4->SetLineColor(TColor::kMagenta); gr4->Draw("PC"); legend->AddEntry(gr4,"Layer 4"); } if (Flag[4]==1){ TGraph *gr5 = new TGraph(i-1,x,yl5); gr5->SetMarkerStyle(20); gr5->SetMarkerColor(TColor::kOrange); gr5->SetLineColor(TColor::kOrange); gr5->Draw("PC"); legend->AddEntry(gr5,"Layer 5"); } if (Flag[5]==1){ TGraph *gr6 = new TGraph(i-1,x,yl6); gr6->SetMarkerStyle(20); gr6->SetMarkerColor(TColor::kViolet); gr6->SetLineColor(TColor::kViolet); gr6->Draw("PC"); legend->AddEntry(gr6,"Layer 6"); } if (Flag[6]==1){ TGraph *gr7 = new TGraph(i-1,x,yl7); gr7->SetMarkerStyle(20); gr7->SetMarkerColor(TColor::kAzure+7); gr7->SetLineColor(TColor::kAzure+7); gr7->Draw("PC"); legend->AddEntry(gr7,"Layer 7"); } legend->Draw(); // I am not sure what this does, but it waits until canvas is closed c->WaitPrimitive(" "); cout << endl << "Canvas Closed" << endl ; // Then quit root cleanly gApplication->Terminate(); }