ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPlots/Input/src/TaskSamples.cc
Revision: 1.2
Committed: Tue Jan 25 14:24:52 2011 UTC (14 years, 3 months ago) by fabstoec
Content type: text/plain
Branch: MAIN
Changes since 1.1: +139 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 fabstoec 1.2 // $Id: TaskSamples.cc,v 1.1.2.2 2011/01/24 15:04:34 paus Exp $
2    
3     #include <TSystem.h>
4     #include "MitAna/DataUtil/interface/Debug.h"
5     #include "MitPlots/Input/interface/TaskSamples.h"
6    
7     ClassImp(mithep::TaskSamples)
8    
9     using namespace std;
10     using namespace mithep;
11    
12     //--------------------------------------------------------------------------------------------------
13     TaskSamples::TaskSamples(const char *name, const char* dir) :
14     fName (name),
15     fNameTxt (name),
16     fDir (dir),
17     fNMcSamples (0),
18     fNDataSamples(0)
19     {
20     // Constructor
21     }
22    
23     //--------------------------------------------------------------------------------------------------
24     void TaskSamples::Show() const
25     {
26     // Show present list of defined samples
27    
28     printf("\n ==== Analysis task overview -- %s ====\n\n",fName.Data());
29     printf(" Histogram directory: %s\n\n",fDir.Data());
30     printf(" Dataset name Legend Histogram file");
31     printf(" Cross Section [pb] Scale\n");
32     printf(" ------------------------------------------------------------------");
33     printf("----------------------------------------------------------------------------\n");
34     for (UInt_t i=0; i<fDataSamples.size(); i++)
35     fDataSamples[i].Show();
36     printf(" ------------------------------------------------------------------");
37     printf("----------------------------------------------------------------------------\n");
38     for (UInt_t i=0; i<fMcSamples.size(); i++)
39     fMcSamples[i].Show();
40    
41     return;
42     }
43    
44     //--------------------------------------------------------------------------------------------------
45     const Sample *TaskSamples::GetSample(UInt_t iSample) const
46     {
47     // Get sample corresponding to given sample number. Return NULL pointer if index out of range.
48    
49     if (iSample >= fNMcSamples)
50     return 0;
51    
52     return &fMcSamples[iSample];
53     }
54    
55     //--------------------------------------------------------------------------------------------------
56     const Sample *TaskSamples::GetDataSample(UInt_t iSample) const
57     {
58     // Get data sample. Return NULL pointer if not available.
59    
60     if (iSample >= fNDataSamples)
61     return 0;
62    
63     return &fDataSamples[iSample];
64     }
65    
66     //--------------------------------------------------------------------------------------------------
67     Sample *TaskSamples::AddSample(const char* name, const char* file, double xsec, double scale)
68     {
69     // Adding another sample (vector takes care of memory management)
70    
71     Sample* tmpSample = new Sample(name,file,fDir,xsec,scale);
72     fMcSamples.push_back(*tmpSample);
73     fNMcSamples++;
74     // cleanup after yourself
75     delete tmpSample;
76    
77     return &fMcSamples[fMcSamples.size()-1];
78     }
79    
80     //--------------------------------------------------------------------------------------------------
81     Sample *TaskSamples::AddDataSample(const char* name, const char* file)
82     {
83     // Adding another the data sample (existing definition is overwritten)
84    
85     Sample* tmpSample = new Sample(name,file,fDir,-1.0,1.0);
86     fDataSamples.push_back(*tmpSample);
87     fNDataSamples++;
88     // cleanup after yourself
89     delete tmpSample;
90    
91     return &fDataSamples[fDataSamples.size()-1];
92     }
93    
94     //--------------------------------------------------------------------------------------------------
95     void TaskSamples::ReadFile(const char* dir)
96     {
97     // Reading the full task setup from a single file
98    
99     char vers[1024], dset[1024], legend[1024], json[1024];
100     float xsec,scale,overlap;
101    
102     // construct name of the config file
103     TString txtFile = TString(dir)+TString("/")+fNameTxt+TString(".txt");
104     printf("\n Initializing analysis task from %s\n\n",txtFile.Data());
105    
106     // open file in a pipe (leaves options for filtering)
107     FILE *f = gSystem->OpenPipe((TString("cat ")+txtFile+TString("| grep -v ^#")).Data(),"r");
108     MDB(kGeneral,1) {
109     printf(" Cross Section [pb] Dataset name ");
110     printf("Legend Skim? \n");
111     printf(" ------------------------------------------------------------------------");
112     printf("----------------------------\n");
113     }
114     while (fscanf(f,"%s %s %s %f %f %f %s",vers,dset,legend,&xsec,&scale,&overlap,json) != EOF) {
115     // show what was read
116     TString skim("noskim");
117     MDB(kGeneral,1)
118     printf(" adding: %3s %-40s %-40s %20.7f %7.3f %7.1f %-70s %-8s\n",
119     vers,dset,legend,xsec,scale,overlap,json,skim.Data());
120    
121     TString histFile = fName+TString("_")+TString(dset)+TString("_")+skim+TString(".root");
122     // found 'the data sample'
123     Sample *tmpSample = 0;
124     if (xsec < 0) {
125     tmpSample = AddDataSample(dset,histFile.Data());
126     }
127     // define the new Monte Carlo sample
128     else {
129     tmpSample = AddSample(dset,histFile.Data(), double(xsec), double(scale));
130     }
131     // Convert '~' -> ' '
132     TString tmpLegend = TString(legend);
133     tmpLegend.ReplaceAll(TString("~"),TString(" "));
134     tmpSample->SetLegend(tmpLegend.Data());
135     }
136     gSystem->ClosePipe(f);
137    
138     return;
139     }