ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPlots/Input/src/TaskSamples.cc
Revision: 1.3
Committed: Wed Mar 28 12:10:21 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.2: +21 -21 lines
Log Message:
Small tweaks.

File Contents

# User Rev Content
1 paus 1.3 // $Id: TaskSamples.cc,v 1.2 2011/01/25 14:24:52 fabstoec Exp $
2 fabstoec 1.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 paus 1.3 printf(" Dataset name Skim Legend Histogram file");
31 fabstoec 1.2 printf(" Cross Section [pb] Scale\n");
32 paus 1.3 printf(" ------------------------------------------------------------------------");
33 fabstoec 1.2 printf("----------------------------------------------------------------------------\n");
34     for (UInt_t i=0; i<fDataSamples.size(); i++)
35     fDataSamples[i].Show();
36 paus 1.3 printf(" ------------------------------------------------------------------------");
37 fabstoec 1.2 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 paus 1.3 Sample *TaskSamples::AddSample(const char* name,const char* skimName, const char* file,
68     double xsec, double scale)
69 fabstoec 1.2 {
70     // Adding another sample (vector takes care of memory management)
71    
72 paus 1.3 Sample* tmpSample = new Sample(name,skimName,file,fDir,xsec,scale);
73 fabstoec 1.2 fMcSamples.push_back(*tmpSample);
74     fNMcSamples++;
75     // cleanup after yourself
76     delete tmpSample;
77    
78     return &fMcSamples[fMcSamples.size()-1];
79     }
80    
81     //--------------------------------------------------------------------------------------------------
82 paus 1.3 Sample *TaskSamples::AddDataSample(const char* name, const char* skimName, const char* file)
83 fabstoec 1.2 {
84     // Adding another the data sample (existing definition is overwritten)
85    
86 paus 1.3 Sample* tmpSample = new Sample(name,skimName,file,fDir,-1.0,1.0);
87 fabstoec 1.2 fDataSamples.push_back(*tmpSample);
88     fNDataSamples++;
89     // cleanup after yourself
90     delete tmpSample;
91    
92     return &fDataSamples[fDataSamples.size()-1];
93     }
94    
95     //--------------------------------------------------------------------------------------------------
96     void TaskSamples::ReadFile(const char* dir)
97     {
98     // Reading the full task setup from a single file
99    
100 paus 1.3 char vers[1024], dset[1024], skim[1024], legend[1024], json[1024];
101 fabstoec 1.2 float xsec,scale,overlap;
102    
103     // construct name of the config file
104     TString txtFile = TString(dir)+TString("/")+fNameTxt+TString(".txt");
105     printf("\n Initializing analysis task from %s\n\n",txtFile.Data());
106    
107     // open file in a pipe (leaves options for filtering)
108     FILE *f = gSystem->OpenPipe((TString("cat ")+txtFile+TString("| grep -v ^#")).Data(),"r");
109     MDB(kGeneral,1) {
110     printf(" Cross Section [pb] Dataset name ");
111     printf("Legend Skim? \n");
112     printf(" ------------------------------------------------------------------------");
113     printf("----------------------------\n");
114     }
115 paus 1.3 while (fscanf(f,"%s %s %s %s %f %f %f %s",vers,dset,skim,legend,&xsec,&scale,&overlap,json)
116     != EOF) {
117 fabstoec 1.2 // show what was read
118     MDB(kGeneral,1)
119     printf(" adding: %3s %-40s %-40s %20.7f %7.3f %7.1f %-70s %-8s\n",
120 paus 1.3 vers,dset,legend,xsec,scale,overlap,json,skim);
121 fabstoec 1.2
122 paus 1.3 TString histFile = fName + TString("_") + TString(dset) + TString("_")
123     + TString(skim) + TString(".root");
124    
125 fabstoec 1.2 Sample *tmpSample = 0;
126 paus 1.3 if (xsec < 0) // found 'the data sample'
127     tmpSample = AddDataSample(dset,skim,histFile.Data());
128     else // define the new Monte Carlo sample
129     tmpSample = AddSample(dset,skim,histFile.Data(), double(xsec), double(scale));
130    
131 fabstoec 1.2 // 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     }