ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPlots/Plot/src/PlotTask.cc
Revision: 1.9
Committed: Wed Mar 28 12:10:22 2012 UTC (13 years, 1 month ago) by paus
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029a, Mit_028, Mit_027, Mit_027a, HEAD
Changes since 1.8: +36 -13 lines
Log Message:
Small tweaks.

File Contents

# User Rev Content
1 paus 1.9 // $Id: PlotTask.cc,v 1.8 2011/12/11 19:22:29 bendavid Exp $
2 paus 1.2
3     #include <vector>
4     #include <TROOT.h>
5     #include <TSystem.h>
6     #include <TMath.h>
7     #include <TPad.h>
8     #include <TFile.h>
9     #include <TH1.h>
10     #include <TH1D.h>
11     #include <TBox.h>
12     #include <TMarker.h>
13     #include <TLatex.h>
14 bendavid 1.4 #include <TTree.h>
15 paus 1.2 #include "MitAna/DataUtil/interface/Debug.h"
16     #include "MitPlots/Style/interface/MitStyle.h"
17     #include "MitPlots/Plot/interface/PlotTask.h"
18    
19     ClassImp(mithep::PlotTask)
20    
21     using namespace std;
22     using namespace mithep;
23    
24 bendavid 1.8 const TH1D *PlotTask::sPuWeights = 0;
25    
26 paus 1.2 //--------------------------------------------------------------------------------------------------
27     PlotTask::PlotTask(const TaskSamples *taskSamples, const double lumi) :
28     fTask (taskSamples),
29     fHistStyles (0),
30     fTargetLumi (lumi),
31     fIdxHistMax (-1),
32     fNRebin (1),
33     fEmptyHist (0),
34     fDataHist (0),
35     fHistMinimum (0),
36     fHistMaximum (0),
37     fHistXMinimum(0),
38     fHistXMaximum(0),
39     fAxisTitleX (""),
40     fAxisTitleY ("Number of Events"),
41 bendavid 1.8 fXLegend (65.),
42     fYLegend (94.),
43     fNBins (100),
44     fPuTarget (0)
45 paus 1.2 {
46     // Constructor
47     }
48    
49     //--------------------------------------------------------------------------------------------------
50     PlotTask::~PlotTask()
51     {
52     // Destructor
53    
54     if (fEmptyHist)
55     delete fEmptyHist;
56     if (fDataHist)
57     delete fDataHist;
58     }
59    
60     //--------------------------------------------------------------------------------------------------
61     void PlotTask::SetAxisTitles(const char* xtit, const char* ytit)
62     {
63     fAxisTitleX = TString(xtit);
64     fAxisTitleY = TString(ytit);
65    
66     return;
67     }
68    
69     //--------------------------------------------------------------------------------------------------
70 bendavid 1.4 void PlotTask::SetDrawExp(const char* draw, const char* sel)
71     {
72     fDrawExp = TString(draw);
73     fSelExp = TString(sel);
74    
75     return;
76     }
77    
78    
79     //--------------------------------------------------------------------------------------------------
80 paus 1.2 void PlotTask::PlotContributions(const char* dir, const char* hist)
81     {
82     // Show present list of defined samples
83    
84     // scale the histograms
85     ScaleHistograms(dir,hist);
86     FindHistMaximum();
87    
88     // say what we are doing
89     printf("\n ==== Plotting Contributions -- %s ====\n\n",fTask->Name()->Data());
90 klute 1.6 printf(" index of highest histogram %d (0-%d)\n\n",fIdxHistMax,int(fHists.size()-1));
91 paus 1.2
92     // check x-axis title
93     if (fAxisTitleX == TString(""))
94     fAxisTitleX = TString(hist);
95    
96     // initialize the largest histogram properly and draw it
97     TH1D* hmax = 0;
98     if (fIdxHistMax == fHists.size())
99     hmax = fDataHist;
100     else
101     hmax = fHists[fHists.size()-1];
102     MitStyle::InitHist(hmax,fAxisTitleX.Data(),fAxisTitleY.Data(),kBlack);
103     hmax->GetXaxis()->SetNdivisions(505);
104     if (fHistMinimum != 0)
105     hmax->SetMinimum(fHistMinimum);
106     if (fIdxHistMax == fHists.size())
107     hmax->Draw("E");
108     else
109     hmax->Draw("hist");
110    
111     // loop through samples and draw all histograms
112     int iCol = (EColor) kBlack;
113     int iFill = 3001;
114     for (UInt_t i=0; i<*fTask->NSamples(); i++) {
115     //const Sample *s = fTask->GetSample(i);
116     MitStyle::InitHist(fHists[i],hist,"Number of Events",(EColor) iCol);
117    
118     fHists[i]->SetLineColor(iCol);
119     //fHists[i]->SetFillColor(iCol);
120     //fHists[i]->SetFillStyle(iFill);
121     fHists[i]->Draw("same;Hist");
122    
123     iFill++; iCol++;
124     }
125    
126     // overlay a frame to put the text and boxes on
127     OverlayFrame();
128    
129     return;
130     }
131    
132     //--------------------------------------------------------------------------------------------------
133 paus 1.9 void PlotTask::PlotStack(const char* dir, const char* hist, bool rescale)
134 paus 1.2 {
135     // Show present list of defined samples
136    
137     // scale the histograms
138     ScaleHistograms(dir,hist);
139     FindHistMaximum();
140    
141     // ensure the histogram styles are ready
142     if (! fHistStyles)
143     fHistStyles = new HistStyles();
144    
145     // check basics
146     if (fStackedHists.size() < 1) {
147     printf(" WARNING -- no histograms with name: %s. EXIT!\n",hist);
148     return;
149     }
150    
151     // determine the width of one bin
152     double binW = fEmptyHist->GetBinWidth(1);
153     char binWStr[7];
154     sprintf(binWStr," /%7.3f",binW);
155    
156     // say what we are doing
157     printf("\n ==== Plotting Stack -- %s ====\n",fTask->Name()->Data());
158     printf("\n bin width: %7.3f in xMin: %7.3f <--> xMax: %7.3f\n\n",
159     binW,fHistXMinimum,fHistXMaximum);
160    
161     // check x-axis title
162     if (fAxisTitleX == TString(""))
163     fAxisTitleX = TString(hist);
164    
165     // create the requested frame and initialize the empty histogram properly and draw it
166     TH1D *hFrame = 0;
167     if (fHistXMinimum != 0. || fHistXMaximum != 0.) {
168     hFrame = new TH1D("Frame",fEmptyHist->GetTitle(),1,fHistXMinimum,fHistXMaximum);
169     }
170     else
171     hFrame = fEmptyHist;
172    
173     MitStyle::InitHist(hFrame,fAxisTitleX.Data(),(fAxisTitleY+TString(binWStr)).Data(),kBlack);
174     hFrame->GetXaxis()->SetNdivisions(505);
175     if (fHistMinimum != 0)
176     hFrame->SetMinimum(fHistMinimum);
177     hFrame->SetMaximum(fHistMaximum*1.1);
178     hFrame->Draw("");
179    
180 paus 1.9 Double_t nmctotal = 0.;
181     for (UInt_t i=fHists.size(); i>0; i--) {
182     nmctotal += fHists[i-1]->GetSumOfWeights();
183     }
184    
185     Double_t ndata = 1.0;
186     Double_t scale = 1.0;
187     if (dynamic_cast<TH1D*>(fDataHist)) {
188     ndata = fDataHist->GetSumOfWeights();
189     scale = ndata/nmctotal;
190     }
191    
192     // if (fDataHist) {
193    
194     // }
195    
196     printf("nmc = %5f, ndata = %5f, scale = %5f\n",nmctotal,ndata,scale);
197    
198 paus 1.2 // loop through samples and draw all histograms
199     fHistStyles->ResetStyle();
200     for (UInt_t i=fStackedHists.size(); i>0; i--) {
201     const Sample *s = fTask->GetSample(i);
202     MitStyle::InitHist(fStackedHists[i-1],fAxisTitleX.Data(),fAxisTitleY.Data());
203 paus 1.9 if (rescale) fStackedHists[i-1]->Scale(scale);
204 paus 1.2 if (i == fStackedHists.size()) {
205     fHistStyles->ApplyCurrentStyle(fStackedHists[i-1]);
206     fStackedHists[i-1]->Draw("same;Hist");
207     fHistStyles->NextStyle();
208     }
209     else {
210     if (*s->Legend() != TString(" ")) {
211     // white out the histogram first
212     fStackedHists[i-1]->SetFillColor(10);
213     fStackedHists[i-1]->SetFillStyle(1001);
214     fStackedHists[i-1]->DrawCopy("same;Hist");
215     // overlay the histogram with proper hatching
216     fHistStyles->ApplyCurrentStyle(fStackedHists[i-1]);
217     fStackedHists[i-1]->Draw("same;Hist");
218     fHistStyles->NextStyle();
219     }
220     }
221     }
222    
223     if (fDataHist) {
224     fHistStyles->ApplyDataStyle(fDataHist);
225     fDataHist->Draw("same;E");
226     }
227    
228     // overlay a frame to put the text and boxes on
229     OverlayFrame();
230    
231     return;
232     }
233    
234     //--------------------------------------------------------------------------------------------------
235     void PlotTask::ScaleHistograms(const char* dir, const char* hist)
236     {
237     // Scale the histograms according to the cross section and the desired lumi and store them
238     // for later use
239    
240     if (fHists.size() > 0) {
241     printf(" WARNING - scaled histograms already exist. EXIT.");
242     return;
243     }
244    
245     fIdxHistMax = -1;
246    
247     // some useful definitions
248     TString *dirFwk = new TString("AnaFwkMod");
249     TString *allEvts = new TString("hDAllEvents");
250     TString slash ("/");
251    
252     // say what we are doing
253     printf("\n ==== Extracting and Scaling Contributions -- %s ====\n\n",fTask->Name()->Data());
254     printf(" target luminosity %f 1/fb\n\n",fTargetLumi/1000.);
255    
256     //------------------------------------------------------------------------------------------------
257     // go through the Monte Carlo samples
258     //------------------------------------------------------------------------------------------------
259     // loop through samples and determine maximum
260 paus 1.3 printf("\n Monte Carlo \n");
261     double nTotRaw = 0.0, nTot = 0.0, nTot2 = 0.0;
262 paus 1.2 for (UInt_t i=0; i<*fTask->NSamples(); i++) {
263     const Sample *s = fTask->GetSample(i);
264     // open file belonging to this sample
265     TFile *fif = new TFile((*fTask->Dir()+slash+*s->File()).Data());
266     // make sure the file exists
267     if (fif->IsOpen() == kFALSE) {
268     printf(" WARNING -- sample %s does not have a histogram file. Continue without!\n",
269     s->Name()->Data());
270     continue;
271     }
272     // read and determine general properties of this sample
273     TDirectory *dirTmp = (TDirectory*) gROOT->FindObject(dirFwk->Data());
274     if (dirTmp)
275     fif->cd(dirFwk->Data());
276     TH1D *hAllEvts = (TH1D*) gROOT->FindObject(allEvts->Data());
277     if (! hAllEvts) {
278     printf(" WARNING -- sample %s does not have a framework file. Next sample!\n",
279     s->Name()->Data());
280     continue;
281     }
282 bendavid 1.8
283     //set pileup weights
284     if (fPuTarget) {
285     if (sPuWeights) {
286     delete sPuWeights;
287     }
288    
289     TH1D *pusource = (TH1D*)dirTmp->Get("hNPU")->Clone();
290     pusource->Scale(1.0/pusource->GetSumOfWeights());
291    
292     sPuWeights = new TH1D( (*fPuTarget) / (*pusource) );
293    
294     }
295    
296 paus 1.2 double nEvts = hAllEvts->GetEntries();
297     double lumi = nEvts / *s->Xsec();
298     double factor,scale = *s->Scale();
299     if (lumi < 0)
300     factor = 1.0;
301     else if (lumi > 0)
302     factor = fTargetLumi/lumi;
303     else
304     factor = 0;
305    
306 bendavid 1.5 TDirectory *fid = 0;
307     TString histname = hist;
308     if (TString(hist).Contains("/")) {
309     TObjArray *substra = TString(hist).Tokenize("/");
310     fid = (TDirectory*)fif->FindObjectAny(((TObjString*)(substra->At(0)))->GetString());
311     histname = ((TObjString*)substra->At(1))->GetString();
312     delete substra;
313     }
314     else {
315     fid = fif;
316     }
317    
318    
319    
320     TH1D *h = dynamic_cast<TH1D*>(fid->FindObjectAny(histname));
321 bendavid 1.4
322     //histogram doesn't exist, try to find TTree instead
323     if (!h) {
324 bendavid 1.5 TTree *htree = dynamic_cast<TTree*>(fid->FindObjectAny(histname));
325 bendavid 1.4 if (!htree) {
326     printf(" WARNING -- sample %s does not have requested histogram. Next sample!\n",
327     s->Name()->Data());
328     continue;
329     }
330    
331     TString histname("htempmc_");
332     histname += i;
333     h = new TH1D(histname,histname,fNBins,fHistXMinimum,fHistXMaximum);
334     TString drawexp = fDrawExp + TString(">>") + histname;
335     htree->Draw(drawexp,fSelExp);
336 paus 1.2 }
337 bendavid 1.4
338 paus 1.2 if (! fEmptyHist) {
339     fEmptyHist = new TH1D(factor * scale * (*h));
340     fEmptyHist->Rebin(fNRebin);
341     fEmptyHist->Reset();
342     }
343    
344 bendavid 1.7 double nEvtsSelRaw = h->GetSumOfWeights();
345 paus 1.2 double nEvtsSel = nEvtsSelRaw * factor * scale;
346     double nEvtsSelErr = TMath::Sqrt(nEvtsSelRaw) * factor * scale;
347    
348 paus 1.9 printf(" -> %-40s %-6s - %14.0f %12.3f +- %8.3f %16.7f: %16.4f (x %f x %f - %p)\n",
349     s->Name()->Data(),s->SkimName()->Data(),
350     nEvts,nEvtsSel,nEvtsSelErr,*s->Xsec(),lumi,factor,scale,(void*)h);
351 paus 1.2
352 paus 1.3 nTotRaw += nEvts;
353     nTot += nEvtsSel;
354     nTot2 += nEvtsSelErr*nEvtsSelErr;
355    
356 paus 1.2 // scale it
357     TH1D *hTmp = new TH1D(factor * scale * (*h));
358     hTmp->Rebin(fNRebin);
359     // put it into our collection
360     fHists.push_back(hTmp);
361     // make a new histogram from the last added one and add the recent
362     if (i == 0)
363     fStackedHists.push_back(hTmp);
364     else {
365     TH1D *hStackedTmp = new TH1D(*fStackedHists[fStackedHists.size()-1]);
366     // remember the stored histogram is already rebinned
367     hStackedTmp->Add(hTmp);
368     fStackedHists.push_back(hStackedTmp);
369     }
370     }
371 paus 1.3 // Monte Carlo summary
372 paus 1.9 printf(" %-40s - %14.0f %12.3f +- %8.3f %16.7f: %16.4f (x %f x %f)\n",
373 paus 1.3 "== Monte Carlo Total ==",nTotRaw,nTot,TMath::Sqrt(nTot2),0.0,0.0,1.0,1.0);
374    
375 paus 1.2
376     //------------------------------------------------------------------------------------------------
377     // go through the data samples
378     //------------------------------------------------------------------------------------------------
379     // loop through data samples and add them up, straight away
380     if (*fTask->NDataSamples() > 0)
381 paus 1.3 printf("\n Data \n");
382     nTotRaw = 0.0;
383     nTot = 0.0;
384     nTot2 = 0.0;
385 paus 1.2 for (UInt_t i=0; i<*fTask->NDataSamples(); i++) {
386     const Sample *s = fTask->GetDataSample(i);
387     // open file belonging to the data sample
388     TFile *fif = new TFile((*fTask->Dir()+slash+*s->File()).Data());
389     // make sure the file exists
390     if (fif->IsOpen() == kFALSE) {
391     printf(" WARNING -- sample %s does not have a histogram file. Continue without!\n",
392     s->Name()->Data());
393     continue;
394     }
395     else {
396     // read and determine general properties of this sample
397     TDirectory *dirTmp = (TDirectory*) gROOT->FindObject(dirFwk->Data());
398     if (dirTmp)
399     fif->cd(dirFwk->Data());
400     TH1D *hAllEvts = (TH1D*) gROOT->FindObject(allEvts->Data());
401     if (! hAllEvts) {
402     printf(" WARNING -- sample %s does not have a framework file. Next sample!\n",
403     s->Name()->Data());
404     continue;
405     }
406     else {
407     double nEvts = hAllEvts->GetEntries();
408 bendavid 1.5
409     TDirectory *fid = 0;
410     TString histname = hist;
411     if (TString(hist).Contains("/")) {
412     TObjArray *substra = TString(hist).Tokenize("/");
413     fid = (TDirectory*)fif->FindObjectAny(((TObjString*)(substra->At(0)))->GetString());
414     histname = ((TObjString*)substra->At(1))->GetString();
415     delete substra;
416     }
417     else {
418     fid = fif;
419     }
420    
421     TH1D *h = dynamic_cast<TH1D*>(fid->FindObjectAny(histname));
422 bendavid 1.4 //histogram doesn't exist, try to find TTree instead
423     if (!h) {
424 bendavid 1.5 TTree *htree = dynamic_cast<TTree*>(fid->FindObjectAny(histname));
425 bendavid 1.4 if (!htree) {
426     printf(" WARNING -- sample %s does not have requested histogram. Next sample!\n",
427     s->Name()->Data());
428     continue;
429     }
430    
431     TString histname("htempdata_");
432     histname += i;
433     h = new TH1D(histname,histname,fNBins,fHistXMinimum,fHistXMaximum);
434     TString drawexp = fDrawExp + TString(">>") + histname;
435     //printf ("Draw(%s, %s);\n",drawexp.Data(),fSelExp.Data());
436     htree->Draw(drawexp,fSelExp);
437     }
438 paus 1.2 else
439     // rebin it
440     h->Rebin(fNRebin);
441    
442 bendavid 1.7 double nEvtsSelRaw = h->GetSumOfWeights();
443 paus 1.2 double nEvtsSel = nEvtsSelRaw;
444     double nEvtsSelErr = TMath::Sqrt(nEvtsSelRaw);
445    
446 paus 1.9 printf(" -> %-40s %-6s - %14.0f %12.3f +- %8.3f %16.7f: %16.4f (x %f)\n",
447     s->Name()->Data(),s->SkimName()->Data(),
448     nEvts,nEvtsSel,nEvtsSelErr,*s->Xsec(),fTargetLumi,1.0);
449 paus 1.2
450 paus 1.3 nTotRaw += nEvts;
451     nTot += nEvtsSel;
452     nTot2 += nEvtsSelErr*nEvtsSelErr;
453 paus 1.2
454     // construct the complete data histogram
455     if (! fDataHist)
456     fDataHist = new TH1D(1.0 * (*h));
457     else
458     fDataHist->Add(h);
459     }
460     }
461     }
462 paus 1.3 // Data summary
463 paus 1.9 printf(" %-40s - %14.0f %12.3f +- %8.3f %16.7f: %16.4f (x %f)\n\n",
464 paus 1.3 "== Data Total =========",nTotRaw,nTot,TMath::Sqrt(nTot2),0.0,0.0,1.0);
465 paus 1.2
466     return;
467     }
468    
469     //--------------------------------------------------------------------------------------------------
470     void PlotTask::FindHistMaximum()
471     {
472     // Find maximum of all histograms
473    
474     // first check whether value was overwritten by hand
475     if (fHistMaximum>0.)
476     return;
477    
478     // search through the single histograms
479     for (UInt_t i=0; i<fHists.size(); i++) {
480     if (fHists[i]->GetMaximum() > fHistMaximum) {
481     fHistMaximum = fHists[i]->GetMaximum();
482     fIdxHistMax = i;
483     }
484     }
485    
486     // search through the stacked histograms
487     fHistMaximum = 0.;
488     for (UInt_t i=0; i<fStackedHists.size(); i++) {
489     if (fStackedHists[i]->GetMaximum() > fHistMaximum)
490     fHistMaximum = fStackedHists[i]->GetMaximum();
491     }
492    
493     // check the data histogram if present
494     if (fDataHist && fDataHist->GetMaximum() > fHistMaximum) {
495     fHistMaximum = fDataHist->GetMaximum();
496     fIdxHistMax = fHists.size();
497     }
498    
499     printf(" Histogram maximum is set to be: %f\n",fHistMaximum);
500    
501     return;
502     }
503    
504     //--------------------------------------------------------------------------------------------------
505     void PlotTask::OverlayEmptyHist() const
506     {
507     // Overlay an empty histogram onto the picture
508     if (fEmptyHist)
509     fEmptyHist->Draw("same");
510    
511     return;
512     }
513    
514     //--------------------------------------------------------------------------------------------------
515     void PlotTask::OverlayFrame() const
516     {
517     // Overlay a linear frame from user coordinates (0-100,0-100)
518    
519     // create new transparent pad for the text
520     TPad *transPad = new TPad("transPad","Transparent Pad",0,0,1,1);
521     transPad->SetFillStyle(4000);
522     transPad->Draw();
523     transPad->cd();
524     // find out the right normalization to define the new range (histogram: 0,0 -> 100,100)
525     double xtot = 1./(1. - transPad->GetLeftMargin() - transPad->GetRightMargin());
526     double ytot = 1./(1. - transPad->GetBottomMargin() - transPad->GetTopMargin());
527     transPad->Range((xtot*transPad->GetLeftMargin() *-100 ),
528     (ytot*transPad->GetBottomMargin()*-100 ),
529     (xtot*transPad->GetRightMargin() * 100 + 100),
530     (ytot*transPad->GetTopMargin() * 100 + 100));
531     MDB(kGeneral,1)
532     printf(" Range: %f %f %f %f\n",
533     (xtot*transPad->GetLeftMargin() *-100 ),
534     (ytot*transPad->GetBottomMargin()*-100 ),
535     (xtot*transPad->GetRightMargin() * 100 + 100),
536     (ytot*transPad->GetTopMargin() * 100 + 100) );
537    
538     // define the basic text to be used
539     TLatex* text = new TLatex();
540     text->SetTextFont (42);
541     text->SetTextAlign(12);
542     text->SetTextSize (0.03);
543    
544     // define the basic box to be used
545     TBox *box = new TBox();
546     box->SetLineWidth(2);
547     // base coordinates for the text/boxes
548     double xCorner = fXLegend, yCorner = fYLegend, yDelLine = 4.;
549     double xIndent = 1.5*yDelLine;
550     // count samples with non empty legend
551     int nLegends = 0;
552     for (UInt_t i=*fTask->NSamples(); i>0; i--) {
553     // attach to the specific sample
554     const Sample *s = fTask->GetSample(i-1);
555     if (*s->Legend() != TString(" "))
556     nLegends++;
557     }
558     int iDat = 0;
559     if (fDataHist) {
560     iDat = 1;
561     nLegends++;
562     }
563    
564     // set start values
565     fHistStyles->ResetStyle();
566     int iLeg = 0;
567     // loop through the sampels
568     for (UInt_t i=*fTask->NSamples(); i>0; i--) {
569     // attach to the specific sample
570     const Sample *s = fTask->GetSample(i-1);
571     // calculate corners for the text
572     double xText = xCorner+xIndent, yText = yCorner-float((iLeg+iDat)+0.5)*yDelLine;
573     // say what goes where
574     MDB(kGeneral,1)
575     printf(" Adding box at: (x1,y1,x2,y2) = (%6.2f,%6.2f,%6.2f,%6.2f)\n",
576     xCorner+0.15*xIndent,yText-0.3*yDelLine,
577     xCorner+0.85*xIndent,yText+0.4*yDelLine);
578     // plot the box
579     if (*s->Legend() != TString(" ")) {
580     const HistStyle *hStyle = fHistStyles->CurrentStyle();
581     box->SetFillStyle(0);
582     box->SetFillColor(hStyle->Color());
583     box->SetLineColor(hStyle->Color());
584     box->DrawBox(xCorner+0.15*xIndent,yText-0.3*yDelLine,
585     xCorner+0.85*xIndent,yText+0.4*yDelLine);
586     box->SetFillStyle(hStyle->FillStyle());
587     box->DrawBox(xCorner+0.15*xIndent,yText-0.3*yDelLine,
588     xCorner+0.85*xIndent,yText+0.4*yDelLine);
589    
590     TString pText = *s->Legend();
591     MDB(kGeneral,1)
592     printf(" Adding text \"%s\" at: (x,y) = (%6.2f,%6.2f)\n",pText.Data(),xText,yText);
593     // set the proper text color
594     text->SetTextColor(hStyle->Color());
595     // plot the text
596     text->SetTextAlign(12);
597     text->DrawLatex(xText,yText,pText.Data());
598    
599     fHistStyles->NextStyle();
600     // keep track of how many were printed
601     iLeg++;
602     }
603     }
604    
605     // attach to the data sample
606     if (fDataHist) {
607     const Sample *s = fTask->GetDataSample(0);
608     // calculate corners for the text
609     double xText = xCorner+xIndent, yText = yCorner-float(1-0.7)*yDelLine;
610     // say what goes where
611     MDB(kGeneral,1)
612     printf(" Adding marker at: (x,y) = (%6.2f,%6.2f)\n",
613     xCorner+0.5*xIndent,yText);
614     // plot the marker
615     if (*s->Legend() != TString(" ")) {
616     const HistStyle *hStyle = fHistStyles->GetDataStyle();
617    
618     // draw marker
619     TMarker *m = new TMarker(xCorner+0.5*xIndent,yText,20);
620     m->SetMarkerColor(hStyle->Color ());
621     m->SetMarkerSize (hStyle->MarkerSize ());
622     m->SetMarkerStyle(hStyle->MarkerStyle());
623     m->Draw();
624     // draw text
625     char l[1024];
626     sprintf(l,"%4.2f",fTargetLumi);
627     //TString pText = *s->Legend() + TString(" (#int L = ") + TString(l) + TString("/pb)");
628     TString pText = *s->Legend() + TString(" (") + TString(l) + TString("/pb)");
629     MDB(kGeneral,1)
630     printf(" Adding text \"%s\" at: (x,y) = (%6.2f,%6.2f)\n",pText.Data(),xText,yText);
631     // set the proper text color
632     text->SetTextColor(hStyle->Color());
633     // plot the text
634     text->SetTextAlign(12);
635     text->DrawLatex(xText,yText,pText.Data());
636     }
637     }
638    
639     // Make sure the histogram frame is nice
640     box->SetFillStyle(0);
641     box->SetLineColor(kBlack);
642     box->DrawBox(0,0,100,100);
643    
644     delete text;
645     delete box;
646    
647     return;
648     }
649 bendavid 1.8
650     //--------------------------------------------------------------------------------------------------
651 paus 1.9 float PlotTask::PuWeight(Int_t npu)
652     {
653     if (npu<0)
654     return 1.0;
655     if (!sPuWeights)
656     return 1.0;
657 bendavid 1.8
658     return sPuWeights->GetBinContent(sPuWeights->FindFixBin(npu));
659 paus 1.9 }