ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ShapeDroplet.C
Revision: 1.1
Committed: Tue Apr 10 08:28:06 2012 UTC (13 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Log Message:
Added shape droplet to contain information for limits and systematics

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2     #include <fstream>
3     #include <vector>
4     #include <algorithm>
5    
6     class ShapeDroplet{
7     public:
8     std::string DropletName;
9     float observed;
10     float expected;
11     float expectedPlus1Sigma;
12     float expectedMinus1Sigma;
13     float expectedPlus2Sigma;
14     float expectedMinus2Sigma;
15     float JES;
16     float JSU;
17     float PDF;
18     float toterr;
19     float staterr;
20    
21     void saveDroplet(std::string filename);//save droplet to file
22     void readDroplet(std::string filename);//get droplet from file
23     void fill_limit_vector(std::string line, std::vector<float> &res);
24     ShapeDroplet();
25     };
26    
27     ShapeDroplet::ShapeDroplet() {
28     observed=-1;expected=-1;expectedPlus1Sigma=-1;expectedPlus2Sigma=-1;expectedMinus1Sigma=-1;expectedMinus2Sigma=-1;JES=-1;JSU=-1;PDF=-1;toterr=-1;staterr=-1;
29     }
30    
31     std::ostream &operator<<(std::ostream &ostr, ShapeDroplet v)
32     {
33     return ostr << " ShapeDroplet : Limits::observed : " << v.observed << " \n " <<
34     " Limits::expected : " << v.expected << " \n " <<
35     " Limits::1 sigma : [" << v.expectedMinus1Sigma << " , " << v.expectedPlus1Sigma << " ] \n " <<
36     " Limits::2 sigma : [" << v.expectedMinus2Sigma << " , " << v.expectedPlus2Sigma << " ] \n " <<
37     " Systematics::JES : " << v.JES << " \n " <<
38     " Systematics::JSU : " << v.JSU << " \n " <<
39     " Systematics::PDF : " << v.PDF << " \n " <<
40     " Systematics::toterr : " << v.toterr << " \n " <<
41     " Systematics::staterr : " << v.staterr << " \n ";
42     }
43    
44     void ShapeDroplet::saveDroplet(std::string filename) {
45     std::ofstream myreport(filename.c_str());
46     myreport<<this->observed<<";"<<this->expected<<";"<<this->expectedMinus1Sigma<<";"<<this->expectedPlus1Sigma<<";"<<this->expectedMinus2Sigma<<";"<<this->expectedPlus2Sigma<<";"<<this->JES<<";"<<this->JSU<<";"<<this->PDF<<";"<<this->toterr<<";"<<this->staterr<<";";
47     myreport.close();
48     }
49    
50     void ShapeDroplet::fill_limit_vector(std::string line, std::vector<float> &res) {
51     if(line=="") return;
52     while((int)line.find(";")>-1) {
53     int pos=(int)line.find(";");
54     std::string thisentry=line.substr(0,pos);
55     res.push_back(atof(thisentry.c_str()));
56     line=line.substr(pos+1,line.size()-pos);
57     }
58     }
59     void ShapeDroplet::readDroplet(std::string filename) {
60     std::ifstream myreport;
61     myreport.open(filename.c_str());
62     if(!myreport) {
63     std::cerr << "Watch out, cannot read shape droplet using " << filename << std::endl;
64     } else {
65     std::vector<float> lresults;
66     char c[255];
67     while(myreport) {
68     myreport.getline(c,255);
69     this->fill_limit_vector((std::string)c,lresults);
70     }
71     if(lresults.size()<10) std::cerr << "Watch out, stored limit droplet from " << filename << " does not contain sufficient information" << std::endl;
72     else {
73     this->observed=lresults[0];
74     this->expected=lresults[1];
75     this->expectedMinus1Sigma=lresults[2];
76     this->expectedPlus1Sigma=lresults[3];
77     this->expectedMinus2Sigma=lresults[4];
78     this->expectedPlus2Sigma=lresults[5];
79     this->JES=lresults[6];
80     this->JSU=lresults[7];
81     this->PDF=lresults[8];
82     this->toterr=lresults[9];
83     this->staterr=lresults[10];
84     }//result vector is of right size
85     }//report exists
86     myreport.close();
87     }
88    
89    
90     /*
91     int main() {
92     std::cout << "Shape Droplet class test!" << std::endl;
93     ShapeDroplet alpha;
94    
95     bool trywriting=false; // switch this to true if you'd like to try writing a droplet
96     bool tryreading=false; // switch this to true if you'd like to try reading a droplet
97    
98     if(trywriting) {
99     alpha.observed=1;
100     alpha.expected=2;
101     alpha.expectedPlus1Sigma=3;
102     alpha.expectedMinus1Sigma=4;
103     alpha.expectedPlus2Sigma=5;
104     alpha.expectedMinus2Sigma=6;
105     alpha.JES=7;
106     alpha.JSU=8;
107     alpha.PDF=9;
108     alpha.toterr=10;
109     alpha.staterr=11;
110     alpha.saveDroplet("report_999741748.txt");
111     }
112    
113     if(tryreading) {
114     alpha.readDroplet("report_999741748.txt");
115     std::cout << alpha << std::endl;
116     }
117    
118     return 0;
119     }
120     */