ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/OverlapStudy.C
Revision: 1.1
Committed: Fri Apr 5 12:20:30 2013 UTC (12 years, 1 month ago) by buchmann
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
Added overlap study for METJZB / JZB

File Contents

# Content
1 #include <iostream>
2 #include <fstream>
3 #include <sstream>
4 #include <vector>
5 #include <algorithm>
6
7 #include <TLatex.h>
8
9 class event {
10 public:
11 long eventNum;
12 int runNum;
13 int lumi;
14 event(long,int,int);
15 bool operator==(const event &other);
16 };
17
18 event::event(long rn,int ln,int en): eventNum(en),runNum(rn),lumi(ln) {}
19 bool event::operator==(const event &other) {
20 if(this->eventNum!=other.eventNum) return false;
21 if(this->runNum!=other.runNum) return false;
22 if(this->lumi!=other.lumi) return false;
23 return true;
24 }
25
26 void MatchEventLists(std::vector<event> List1, std::vector<event> List2, const char* arg1, const char* arg2, bool QuietMode) {
27 std::vector<event> OneOnly;
28 std::vector<event> TwoOnly;
29 std::vector<event> Both;
30
31 for(int i=0;i<List1.size();i++) {
32 bool MatchFound=false;
33 for(int j=0;j<List2.size();j++) {
34 if(List1[i]==List2[j]) {
35 MatchFound=true;
36 break;
37 }
38 }
39 if(MatchFound) Both.push_back(List1[i]);
40 else OneOnly.push_back(List1[i]);
41 }
42
43 for(int i=0;i<List2.size();i++) {
44 bool MatchFound=false;
45 for(int j=0;j<List1.size();j++) {
46 if(List2[i]==List1[j]) {
47 MatchFound=true;
48 break;
49 }
50 }
51 if(!MatchFound) TwoOnly.push_back(List2[i]);
52 }
53
54 dout << "Results (summary): " << endl;
55 dout << " Only in " << arg1 << ": " << OneOnly.size() << " ( out of " << List1.size() << ")" << endl;
56 dout << " Only in " << arg2 << ": " << TwoOnly.size() << " ( out of " << List2.size() << ")" << endl;
57 dout << " In both : " << Both.size() << endl;
58
59 dout << "Results (more verbose): " << endl;
60 dout << " Only in " << arg1 << ": " << OneOnly.size() << " ( out of " << List1.size() << ")" << endl;
61 for(unsigned int i=0;!QuietMode && i<OneOnly.size();i++) dout << OneOnly[i].runNum << ":" << OneOnly[i].lumi << ":" << OneOnly[i].eventNum << endl;
62 dout << " Only in " << arg2 << ": " << TwoOnly.size() << " ( out of " << List2.size() << ")" << endl;
63 for(unsigned int i=0;!QuietMode && i<TwoOnly.size();i++) dout << TwoOnly[i].runNum << ":" << TwoOnly[i].lumi << ":" << TwoOnly[i].eventNum << endl;
64 }
65
66 std::vector<event> EventsFromFile(const char* filename) {
67 std::vector<event> EventList;
68 std::ifstream myfile(filename);
69
70 std::string line;
71 while (std::getline(myfile, line)) {
72 replace(line.begin(),line.end(),':',' ');
73 std::istringstream iss(line);
74 long eventNum;
75 int runNum,lumi;
76 if (!(iss >> runNum >> lumi >> eventNum)) break; // error
77 EventList.push_back(event(runNum,lumi,eventNum));
78
79 }
80 myfile.close();
81
82 return EventList;
83 }
84
85 void CompareTwoEventLists(string path1, string path2, bool QuietMode) {
86 dout << "Comparing " << path1 << " and " << path2 << endl;
87
88 std::vector<event> ListOne = EventsFromFile(path1.c_str());
89 std::vector<event> ListTwo = EventsFromFile(path2.c_str());
90
91 MatchEventLists(ListOne,ListTwo,path1.c_str(),path2.c_str(),QuietMode);
92 }
93
94
95 void overlapanalysis(string datajzb, string mcjzb) {
96
97 TCanvas *can = new TCanvas("can","can");
98 can->SetRightMargin(0.16);
99
100 bool QuietMode=true;//don't print each event
101
102 dout << "Going to compute event lists for the tight selection" << endl;
103 pick_up_events("((((((passed_triggers ||!is_data)))&&((abs(eta1)<1.4 && abs(eta2)<1.4 && pt1>30 && pt2>20)))&&(((met[4]>100)&&((id1==id2)&&(ch1*ch2<0)))&&((((pfJetGoodNum40>=2&&pfJetGoodID[0]!=0)&&(pfJetGoodNum40>=2&&pfJetGoodID[1]!=0))&&((mll>2)&&((abs(eta1)<1.4 && abs(eta2)<1.4 && pt1>30 && pt2>20))))&&(pfJetGoodNum40>=3))&&mll>20&&mll<70&&(abs(eta1)<1.4 && abs(eta2)<1.4 && pt1>30 && pt2>20)&&pt1>20&&pt2>20)))*((weight*(weight<1000)*(is_data+(!is_data)*((id1==id2)*0.95+(id1!=id2)*0.94))))","ETH_SF.txt",QuietMode);
104
105 dout << "Going to compute event lists for iJZB" << endl;
106 pick_up_events("((((((passed_triggers ||!is_data)))&&((abs(eta1)<1.4 && abs(eta2)<1.4 && pt1>30 && pt2>20)))&&(((("+datajzb+">100))&&((id1==id2)&&(ch1*ch2<0)))&&((((pfJetGoodNum40>=2&&pfJetGoodID[0]!=0)&&(pfJetGoodNum40>=2&&pfJetGoodID[1]!=0))&&((mll>2)&&((abs(eta1)<1.4 && abs(eta2)<1.4 && pt1>30 && pt2>20))))&&(pfJetGoodNum40>=3))&&mll>20&&mll<70&&(abs(eta1)<1.4 && abs(eta2)<1.4 && pt1>30 && pt2>20)&&pt1>20&&pt2>20)))*((weight*(weight<1000)*(is_data+(!is_data)*((id1==id2)*0.95+(id1!=id2)*0.94))))","JZB_SF.txt",QuietMode);
107
108 CompareTwoEventLists("JZB_SF.txt","ETH_SF.txt", QuietMode);
109
110 vector<float> binningx;
111 vector<float> binningy;
112 vector<int> emptyvector;
113
114 for(int i=0;i<=45;i++) {
115 binningx.push_back(i*10);
116 binningy.push_back(i*10);
117 if(i>0) binningy.push_back(-10*i);
118 }
119 sort(binningy.begin(),binningy.end());
120
121 TH2F *OverLapIllustration = allsamples.Draw("OverLapIllustration",datajzb+":met[4]",binningx,binningy,"MET","JZB","((((((passed_triggers ||!is_data)))&&((abs(eta1)<1.4 && abs(eta2)<1.4 && pt1>30 && pt2>20)))&&(((met[4]>100)&&((id1==id2)&&(ch1*ch2<0)))&&((((pfJetGoodNum40>=2&&pfJetGoodID[0]!=0)&&(pfJetGoodNum40>=2&&pfJetGoodID[1]!=0))&&((mll>2)&&((abs(eta1)<1.4 && abs(eta2)<1.4 && pt1>30 && pt2>20))))&&(pfJetGoodNum40>=3))&&mll>20&&mll<70&&(abs(eta1)<1.4 && abs(eta2)<1.4 && pt1>30 && pt2>20)&&pt1>20&&pt2>20)))*((weight*(weight<1000)*(is_data+(!is_data)*((id1==id2)*0.95+(id1!=id2)*0.94))))", data, luminosity,emptyvector,false);
122
123 OverLapIllustration->Draw("COLZ");
124 TLine *ltop = new TLine(0,0,450,450);
125 ltop->SetLineColor(kBlue);
126 TLine *lbottom = new TLine(0,0,450,-450);
127 lbottom->SetLineColor(kBlue);
128
129 TLine *metline = new TLine(100,-450,100,450);
130 metline->SetLineColor(kBlue);
131
132 TLine *jzbline = new TLine(0,100,450,100);
133 jzbline->SetLineColor(kBlue);
134
135 TBox *bjzb = new TBox(100,100,450,450);
136 bjzb->SetFillColor(kGreen);
137 bjzb->SetFillStyle(3002);
138
139 TBox *bmet = new TBox(100,-450,450,450);
140 bmet->SetFillColor(TColor::GetColor("#58ACFA"));
141 bmet->SetFillStyle(3003);
142
143
144
145 float onlymet=0;
146 float both=0;
147
148 for(int ix=1;ix<=OverLapIllustration->GetNbinsX();ix++) {
149 for(int iy=1;iy<=OverLapIllustration->GetNbinsY();iy++) {
150 if(OverLapIllustration->GetXaxis()->GetBinCenter(ix)<100) continue;
151 if(OverLapIllustration->GetYaxis()->GetBinCenter(iy)>100) both+=OverLapIllustration->GetBinContent(ix,iy);
152 else onlymet+=OverLapIllustration->GetBinContent(ix,iy);
153 }
154 }
155
156 dout << "Both : " << both << " and only MET : " << onlymet << endl;
157
158 bmet->Draw("same");
159 bjzb->Draw("same");
160 OverLapIllustration->Draw("COLZ,same");
161
162 stringstream RegionSummary;
163 RegionSummary << "#splitline{MET signal region: " << onlymet+both << " (also in JZB: " << both << ")}{JZB signal region: " << both << " (also in MET: " << both << ")}";
164
165 TLatex *text = new TLatex(120,-250,RegionSummary.str().c_str());
166 text->SetTextSize(0.03);
167 text->Draw();
168
169 metline->Draw();
170 jzbline->Draw();
171
172 DrawPrelim();
173
174 CompleteSave(can,"Overlap/OverlapIllustration");
175
176 delete OverLapIllustration;
177 }