ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Common/CPlot.cc
(Generate patch)

Comparing UserCode/Common/CPlot.cc (file contents):
Revision 1.1 by dkralph, Sat Jun 4 14:09:51 2011 UTC vs.
Revision 1.2 by dkralph, Tue Jul 26 07:18:45 2011 UTC

# Line 61 | Line 61 | fRooPlot(frame)
61  
62  
63   //--------------------------------------------------------------------------------------------------
64 < void CPlot::AddHist1D(TH1F *h, TString drawopt, int color, int linesty, int fillsty)
64 > void CPlot::AddHist1D(TH1F *h, TString drawopt, int color, int linesty, int fillsty, int linecolor)
65   {
66    if(!h)
67      return;
68    
69 <  h->SetLineColor(color);
69 >  if(linecolor==0)
70 >    h->SetLineColor(color);
71 >  else
72 >    h->SetLineColor(linecolor);
73    h->SetLineStyle(linesty);
74    h->SetFillColor(color);
75    h->SetFillStyle(fillsty);
# Line 133 | Line 136 | void CPlot::AddToStack(TH1F *h, int colo
136    AddHist1D(h,"",color,1,1001);
137   }
138  
139 < void CPlot::AddToStack(TH1F *h, TString label, int color)
139 > void CPlot::AddToStack(TH1F *h, TString label, int color, int linecolor,
140 >                       int linestyle, int linewidth, int fillstyle)
141   {
142    if(!h)
143      return;
# Line 147 | Line 151 | void CPlot::AddToStack(TH1F *h, TString
151      fLeg->SetY1(fLeg->GetY1()-0.06);  
152      
153    // make legend entries appear in reverse of the order the histograms are added
154 <  fStackEntries.push_back(fLeg->AddEntry(h,label,"F"));
155 <  for(Int_t ientry=(fStackEntries.size()-2); ientry>=0; ientry--) {
156 <    TObject* hh = fStackEntries[ientry]->GetObject();
157 <    TString ll  = fStackEntries[ientry]->GetLabel();
158 <    fStackEntries[ientry+1]->SetObject(hh);
159 <    fStackEntries[ientry+1]->SetLabel(ll);
154 >  if(label.Length()>0) {
155 >    fStackEntries.push_back(fLeg->AddEntry(h,label,"F"));
156 >    for(Int_t ientry=(fStackEntries.size()-2); ientry>=0; ientry--) {
157 >      TObject* hh = fStackEntries[ientry]->GetObject();
158 >      TString ll  = fStackEntries[ientry]->GetLabel();
159 >      fStackEntries[ientry+1]->SetObject(hh);
160 >      fStackEntries[ientry+1]->SetLabel(ll);
161 >    }
162 >    fStackEntries[0]->SetObject(h);
163 >    fStackEntries[0]->SetLabel(label);
164    }
157  fStackEntries[0]->SetObject(h);
158  fStackEntries[0]->SetLabel(label);
165      
166    fStack->Add(h);  
167 <  AddHist1D(h,"",color,1,1001);  
167 >
168 >  h->SetLineColor(linecolor);
169 >  h->SetLineStyle(linestyle);
170 >  h->SetLineWidth(linewidth);
171 >  h->SetFillStyle(fillstyle);
172 >
173 >  AddHist1D(h,"",color,linestyle,fillstyle,linecolor);
174 >  // cout << h->GetLineColor() << " " << h->GetLineStyle() << " " << h->GetLineWidth() << endl;
175   }
176  
177   void CPlot::AddToStack(TFile *f, TString histName, int color)
# Line 180 | Line 193 | void CPlot::AddToStack(TFile *f, TString
193   }  
194    
195   //--------------------------------------------------------------------------------------------------
196 < void CPlot::AddHist2D(TH2F *h, TString drawopt, int fillcolor, int linecolor)
196 > void CPlot::AddHist2D(TH2D *h, TString drawopt, int fillcolor, int linecolor)
197   {
198    if(!h)
199      return;
# Line 200 | Line 213 | void CPlot::AddHist2D(TFile *f, TString
213    if(!f)
214      return;
215    
216 <  TH2F *h = (TH2F*)f->FindObjectAny(histName);
216 >  TH2D *h = (TH2D*)f->FindObjectAny(histName);
217    AddHist2D(h,drawopt,linecolor,fillcolor);
218   }
219  
# Line 216 | Line 229 | void CPlot::AddGraph(TGraph *gr, TString
229    gr->SetLineWidth(2);
230    gr->SetMarkerStyle(marksty);
231    gr->SetMarkerSize(1.2);
232 +
233 + if(gr->GetN()==1) gr->SetMarkerSize(3.5);
234    
235    CPlotItem item;
236    item.graph = gr;
# Line 232 | Line 247 | void CPlot::AddGraph(TGraph *gr, TString
247      fLeg = new TLegend(0.6,0.84,0.93,0.9);
248    else
249      fLeg->SetY1(fLeg->GetY1()-0.06);
250 <  if( (drawopt.Contains("L",TString::kIgnoreCase)==0) ||
251 <      (drawopt.Contains("C",TString::kIgnoreCase)==0) ) {    
252 <    fLeg->AddEntry(gr,label,"LP");
250 >  if( (drawopt.Contains("L",TString::kIgnoreCase) ||
251 >      drawopt.Contains("C",TString::kIgnoreCase))
252 >      && !(drawopt.Contains("P",TString::kIgnoreCase)) ) {    
253 >    fLeg->AddEntry(gr,label,"L");
254    } else {  
255 <    fLeg->AddEntry(gr,label,"P");
255 >    fLeg->AddEntry(gr,label,"LP");
256    }
257    
258    AddGraph(gr,drawopt,color,marksty,linesty);
# Line 312 | Line 328 | void CPlot::AddProfile(TFile *f, TString
328    AddProfile(pr,label,drawopt,color,marksty,linesty);
329   }
330  
315
331   //--------------------------------------------------------------------------------------------------
332   void CPlot::AddTextBox(TString text, double x1, double y1, double x2, double y2,
333                         int bordersize, int textcolor, int fillcolor)
# Line 498 | Line 513 | void CPlot::Draw(TCanvas *c, bool doSave
513          gSystem->mkdir(sOutDir,true);
514          TString outname = sOutDir+TString("/")+fName+TString(".");
515          if(format.CompareTo("all",TString::kIgnoreCase)==0) {
516 +          c->SaveAs(outname+TString("pdf"));
517            c->SaveAs(outname+TString("png"));
518 <          c->SaveAs(outname+TString("eps"));
518 >          c->SaveAs(outname+TString("eps"));      
519            c->SaveAs(outname+TString("C"));
520          } else {
521            c->SaveAs(outname+format);
# Line 536 | Line 552 | void CPlot::Draw(TCanvas *c, bool doSave
552        else
553          h = (TH1F*)fItems[i].hist1D->Clone(hname);
554    
555 <      if(fXmin < fXmax)
555 >      if(fXmin < fXmax) {
556          h->GetXaxis()->SetRangeUser(fXmin,fXmax);
557 +      }
558        
559 <      if(fYmin < fYmax) {
559 >      if(fYmin < fYmax) {
560          h->GetYaxis()->SetRangeUser(fYmin,fYmax);
561        } else {
562          if(ymax < h->GetMaximum()) {
# Line 558 | Line 575 | void CPlot::Draw(TCanvas *c, bool doSave
575        vHists[ifirst]->GetYaxis()->SetTitle(fYTitle);
576        vHists[ifirst]->SetLineWidth(2);
577        vHists[ifirst]->Draw(vHistOpts[ifirst].Data());
578 <    }
578 >  }
579    
580      //
581      // Draw histogram stack
# Line 602 | Line 619 | void CPlot::Draw(TCanvas *c, bool doSave
619        TH1F *h = vHists[i];              
620        h->SetLineWidth(2);
621        char opt[100];
622 <      sprintf(opt,"same%s",vHistOpts[i].Data());    
622 >      sprintf(opt,"same%s",vHistOpts[i].Data());
623        h->Draw(opt);
624      }
625    }  
626 +  c->RedrawAxis();
627    
628    //
629    // Draw graphs

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines