ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FGolf/Tools/vtxreweight.cc
Revision: 1.1
Committed: Fri Jul 8 09:17:39 2011 UTC (13 years, 9 months ago) by fgolf
Content type: text/plain
Branch: MAIN
CVS Tags: ss_summer2011approvalV2, ss_summer2011approval, HEAD
Error occurred while calculating annotation data.
Log Message:
first commit

File Contents

# Content
1 //-------------------------------------------------------------------------------
2 // Use this utility to reweight MC to match the nvtx distribution in data.
3 // This requires a root file with a histogram named "hratio" whose bin contents
4 // specify the weight for each nvtx bin. This weight is determined by plotting
5 // the nvtx distribution for a data sample and a MC sample and taking the ratio.
6 //
7 // A sample file can be found at:
8 // /tas/benhoob/vtxreweight/vtxreweight_Spring11MC_153pb_Zselection.root
9 //
10 // This root file was made with this macro:
11 // /tas/benhoob/vtxreweight/make_vtxreweight_Spring11MC_153pb_Zselection.cc
12 //
13 // and was produced after applying a Z selection.
14 //
15 // You can make your own root file by modifying this macro
16 //
17 //
18 // usage:
19 //
20 // //include header
21 // #include "../Tools/vtxreweight.cc"
22 //
23 // //initialize
24 // bool verbose = true;
25 // char* vtxfile = "/tas/benhoob/vtxreweight/vtxreweight_Spring11MC_153pb_Zselection.root";
26 // set_vtxreweight_rootfile( vtxfile , verbose );
27 //
28 // //in the event loop
29 // float myvtxweight = vtxweight();
30 //
31 //
32 // PLEASE NOTE: ALWAYS CHECK THAT THE WEIGHTING HAS BEEN DONE PROPERLY
33 // BY COMPARING THE DATA NVTX DIST WITH THE WEIGHTED MC NVTX DISTRIBUTION,
34 // WHERE NVTX IS THE NUMBER OF DA VERTICES PASSING isGoodDAVertex()
35 //------------------------------------------------------------------------------
36
37 // $Id: vtxreweight.cc,v 1.4 2011/05/20 14:24:22 warren Exp $
38
39 // CINT is allowed to see this, but nothing else:
40 #include "vtxreweight.h"
41
42 #ifndef __CINT__
43
44 #include <assert.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <unistd.h>
49 #include <sys/types.h>
50 #include <sys/wait.h>
51 #include <sys/stat.h>
52 #include <set>
53 #include <string>
54
55 #include "../CORE/CMS2.h"
56 #include "../CORE/eventSelections.h"
57
58 bool loaded_vtxreweight_hist = false;
59
60 float vtxweight( bool isData , int nvtx ){
61
62 if( isData ) return 1;
63
64 if( !loaded_vtxreweight_hist ){
65 cout << "vtxreweight.cc: You need to do" << endl;
66 cout << "set_vtxreweight_rootfile( filename )" << endl;
67 cout << "before calling vtxweight()" << endl;
68 cout << "a sample vtxreweight file can be found at" << endl;
69 cout << "/tas/benhoob/vtxreweight/vtxreweight_Spring11MC_23pbPR.root" << endl;
70 cout << "now, quitting" << endl;
71 exit(2);
72 }
73
74 if( nvtx == 0 ){
75 cout << "vtxreweight.cc: warning 0 good vertices found, returning 0 weight" << endl;
76 return 0;
77 }
78
79 if( nvtx > vtxreweight_hist->GetNbinsX() ) nvtx = vtxreweight_hist->GetNbinsX();
80
81 //cout << "nvtx " << nvtx << " weight " << vtxreweight_hist->GetBinContent(nvtx) << endl;
82 return vtxreweight_hist->GetBinContent(nvtx);
83
84 }
85
86 void set_vtxreweight_rootfile ( const char* filename , bool verbose ){
87 TFile* file = TFile::Open(filename);
88
89 if( file == 0 ){
90 cout << "vtxreweight.cc: error, couldn't open file : " << filename << endl;
91 cout << "Quitting!" << endl;
92 exit(0);
93 }
94
95 vtxreweight_hist = (TH1F*) file->Get("hratio");
96
97 if( vtxreweight_hist == 0 ){
98 cout << "vtxreweight.cc: error, couldn't retrieve hist hratio from file " << filename << endl;
99 cout << "Quitting" << endl;
100 exit(1);
101 }
102
103 if( verbose ){
104 cout << "Opened vtx reweighting file " << filename << endl;
105
106 cout << "|" << setw(10) << "nvtx" << setw(4)
107 << "|" << setw(10) << "weight" << setw(4) << "|" << endl;
108
109 for(unsigned int ibin = 1 ; ibin <= (unsigned int)vtxreweight_hist->GetNbinsX() ; ++ibin ){
110
111 cout << "|" << setw(10) << ibin << setw(4)
112 << "|" << setw(10) << vtxreweight_hist->GetBinContent(ibin) << setw(4) << "|" << endl;
113
114 }
115 }
116 loaded_vtxreweight_hist = true;
117
118 }
119
120 #endif // __CUNT__
121