ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ShapeDroplet.C
Revision: 1.5
Committed: Thu May 17 19:55:17 2012 UTC (12 years, 11 months ago) by buchmann
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +7 -3 lines
Log Message:
Added possibility to mark shape droplet as invalid if its contents were loaded from an invalid source

File Contents

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