ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ShapeDroplet.C
Revision: 1.3
Committed: Mon Apr 16 17:22:51 2012 UTC (13 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -0 lines
Log Message:
Making sure filename isn't empty

File Contents

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