ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/zSelection/testSelectionZee.C
Revision: 1.3
Committed: Sun Oct 23 18:41:27 2011 UTC (13 years, 6 months ago) by yangyong
Content type: text/plain
Branch: MAIN
CVS Tags: V01-00-01, HEAD
Changes since 1.2: +6 -3 lines
Log Message:
first event load data/MC geometry file

File Contents

# User Rev Content
1 yangyong 1.1 #include "rootheader.h"
2     #include "roofitheader.h"
3     #include "RecoAnalyzer.h"
4    
5    
6     #ifdef __MAKECINT__
7     #pragma link C++ class vector<vector<float> >+;
8     #pragma link C++ class vector<vector<unsigned short> >+;
9     #endif
10    
11    
12    
13     #include "TMVAGui.C"
14    
15     #if not defined(__CINT__) || defined(__MAKECINT__)
16     #include "TMVA/Tools.h"
17     #include "TMVA/Factory.h"
18     #include "TMVA/Reader.h"
19     #endif
20     using namespace TMVA;
21    
22    
23    
24     #include "testSelection.h"
25    
26     #include "ecalGap.cc"
27     #include "egammMVACorrection.cc"
28    
29     int debug_ = -2;
30    
31    
32     #include "setBranchAddress_ele.cc"
33    
34     #include "physUtils.cc"
35     #include "usefullcode.cc"
36    
37     #include "getGoodLS.cc"
38    
39     #include "electronSelection.cc"
40    
41     ///re-weighting code
42     #include "LumiReWeighting.cc"
43    
44    
45     void testSelectionZee(char *test_datasetname, int test_evtRange){
46    
47    
48     rgen_ = new TRandom3(0);
49     cout<< rgen_->Gaus(0,0.01) <<endl;
50    
51    
52     dataversion = "v3";
53     datasetname = test_datasetname;
54     evtRange = test_evtRange;
55    
56    
57     egammaMVACorrection_LoadWeights();
58    
59     fChain =new TChain("Analysis");
60     TString filename ;
61 yangyong 1.2
62     /// those files are preselected with two electron Et > 25GeV
63     filename = TString( Form("/castor/cern.ch/user/y/yangyong/data/Run2011A/HiggsAnalysis/dielectronSkimmed/testAnalysisZee.%s.%s.allconv1.vtxmethod2.presel5.vtxtmva0.r%d.root",dataversion.c_str(),datasetname.c_str(),evtRange));
64 yangyong 1.1 cout<<filename<<endl;
65     fChain->Add(filename);
66    
67    
68     TChain *fevtInfo = new TChain("evtInfo");
69     fevtInfo->Add(filename);
70     fevtInfo->SetBranchAddress("totalNumberofEvents", &totalNumberofEvents);
71     fevtInfo->SetBranchAddress("preselectedNumberofEvents", &preselectedNumberofEvents);
72     fevtInfo->SetBranchAddress("datasettag", &datasettag);
73    
74     fevtInfo->GetEntry(0);
75     string dname = datasettag->at(0);
76     string dv = datasettag->at(1);
77     int ntotal = totalNumberofEvents;
78     int nskimmed = preselectedNumberofEvents;
79     for(int n=1; n< fevtInfo->GetEntries(); n++){
80     fevtInfo->GetEntry(n);
81     ntotal += totalNumberofEvents;
82     nskimmed += preselectedNumberofEvents;
83     }
84    
85    
86     setBranchAddress_ele();
87    
88     totalEntries = fChain->GetEntries();
89    
90     cout<<"totalEntries " << totalEntries <<endl;
91    
92     ///get json file good lumis for each run
93     vector<string> certFile;
94     certFile.push_back("JsonFile/Cert_160404-163869_7TeV_May10ReReco_Collisions11_CMSSWConfig_v2.txtv1");
95     certFile.push_back("JsonFile/Cert_160404-167913_7TeV_PromptReco_Collisions11_CMSSWConfig.txt.afterMay10");
96     certFile.push_back("JsonFile/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_CMSSWConfig.txtv1");
97     certFile.push_back("JsonFile/Cert_160404-173692_7TeV_PromptReco_Collisions11_CMSSWConfig.txtv1.run172620up");
98     getLSrangeofEachRuns(certFile);
99    
100    
101     TH1D *hh_pileupmc = new TH1D("hh_pileupmc","hh_npileup mc",51,-0.5,50.5);
102     vector<double> weights_pileup;
103     if( datasetname.find("SIM") != string::npos){
104     /////for PU reweighting (added root files together)
105     filename = TString( Form("PileUPDistrubtion/testAnalysis.%s.%s.puHist.root",dataversion.c_str(),datasetname.c_str()));
106     TFile *fpumc = new TFile(filename,"read");
107     TH1D *hh_npileupbx0 = (TH1D*)fpumc->Get("hh_npileupbx0");
108     TH1D *hh_npileupbx1 = (TH1D*)fpumc->Get("hh_npileupbx1");
109     TH1D *hh_npileupbxm1 = (TH1D*)fpumc->Get("hh_npileupbxm1");
110     TH1D *hh_npileupbxav = (TH1D*)fpumc->Get("hh_npileupbxav"); //right now using averaged
111     TFile *fpudata = new TFile("PileUPDistrubtion/Pileup_2011_EPS_8_jul.root","read");
112    
113     TH1D *hh_npileupdata = (TH1D*)fpudata->Get("pileup");
114     weights_pileup = LumiReWeighting_getWeights(hh_npileupdata, hh_npileupbxav);
115     fpumc->Close();
116     fpudata->Close();
117     }
118    
119    
120     filename = TString (Form("selres/testSelectionZee.%s.%s.r%d.root",dataversion.c_str(), datasetname.c_str(),evtRange));
121     cout<<filename<<endl;
122     TFile *fnew = new TFile(filename,"recreate");
123    
124     TH1I *hh_nevents = new TH1I("hh_nevents","total and skimm events",2,0,2);
125     hh_nevents->SetBinContent(1,ntotal);
126     hh_nevents->SetBinContent(2,nskimmed);
127    
128    
129     vector<string> mpair_var;
130     mpair_var.push_back("mpair_ebeb");
131     mpair_var.push_back("mpair_ebeb_highr9");
132     mpair_var.push_back("mpair_ebeb_lowr9");
133     mpair_var.push_back("mpair_eeee");
134     mpair_var.push_back("mpair_eeee_highr9");
135     mpair_var.push_back("mpair_eeee_lowr9");
136     mpair_var.push_back("mpair_eeee_highr9_loweps"); //eps_escraw < 0.05
137     mpair_var.push_back("mpair_eeee_highr9_higheps");//eps_escraw > 0.05
138     mpair_var.push_back("mpair_eeee_lowr9_loweps"); //eps_escraw < 0.05
139     mpair_var.push_back("mpair_eeee_lowr9_higheps");//eps_escraw > 0.05
140    
141    
142    
143     RooRealVar *rv_mass = new RooRealVar("rv_mass","mass",100,0,1000);
144     RooRealVar *rv_weight = new RooRealVar("rv_weight","weight",1.0,0,1E6);
145     map<string,RooDataSet*> rhs_map_mpair;
146     map<string,RooDataSet*> rhs_map_mpair_corr;
147     for(int j=0; j< int( mpair_var.size()); j++){
148     string mpairname = mpair_var[j];
149     TString rname = TString( Form("rhs_%s",mpairname.c_str()) );
150     rhs_map_mpair[mpairname] = new RooDataSet(rname,rname,RooArgList(*rv_mass,*rv_weight),rv_weight->GetName());
151     mpairname = string (Form("%s_corr",mpair_var[j].c_str()));
152     rname = TString( Form("rhs_%s",mpairname.c_str()) );
153     rhs_map_mpair_corr[mpairname] = new RooDataSet(rname,rname,RooArgList(*rv_mass,*rv_weight),rv_weight->GetName());
154     }
155     map<string,TH1F*> hh_map_mpair;
156     map<string,TH1F*> hh_map_mpaircorr;
157     for(int j=0; j< int( mpair_var.size()); j++){
158     string mpairname = mpair_var[j];
159     filename = TString(Form("hh_%s",mpairname.c_str()));
160     TH1F *hhtmp = new TH1F(filename,filename,2000,0,200);
161     hh_map_mpair[mpairname] = hhtmp;
162     hh_map_mpair[mpairname] ->Sumw2();
163    
164     mpairname = string (Form("%s_corr",mpair_var[j].c_str()));
165     filename = TString(Form("hh_%s",mpairname.c_str()));
166     TH1F *hhtmp2 = new TH1F(filename,filename,2000,0,200);
167     hh_map_mpaircorr[mpairname] = hhtmp2;
168     hh_map_mpaircorr[mpairname] ->Sumw2();
169     }
170    
171    
172    
173     bool goodCurLumiBlock = false;
174     int curLumiBlock = -1;
175     int curRun = -1;
176     vector<int> runNotUsed;
177    
178    
179    
180     float en[2];
181     float encorr[2];
182     float pt[2];
183     float eta[2];
184     float phi[2];
185     float res[20];
186     float scr9[2];
187     float scrps[2];
188    
189     float mpaircorr;
190    
191    
192     int nsel = 0;
193    
194 yangyong 1.3 bool firstEvent = true;
195 yangyong 1.1
196     ////loop over all events ( di-photon skimmed)
197     for(entry = 0; entry < totalEntries; entry ++){
198     fChain->GetEntry(entry);
199     if(entry % 1000 ==0 ) cout<<" entry " <<entry<<endl;
200    
201 yangyong 1.3 if( firstEvent){
202     loadecalGapCoordinates();
203     firstEvent = false;
204     }
205    
206 yangyong 1.1 ///JSON file good run and LS
207     if( isRealData ){
208     vector<int>::iterator it = find(goodRunList.begin(),goodRunList.end(),runNumber);
209     if( it == goodRunList.end()){
210     vector<int>::iterator it2 = find(runNotUsed.begin(),runNotUsed.end(),runNumber);
211     if( it2 == runNotUsed.end()){
212     runNotUsed.push_back(runNumber);
213     }
214     continue;
215     }
216     if( curLumiBlock != lumiBlock || curRun != runNumber){ /// a new lumiBlock or starting of a new Run
217     curLumiBlock = lumiBlock;
218     curRun = runNumber;
219     goodCurLumiBlock = checkLumiBlockofRun(); //check this lumiBlock
220     }
221     if( ! goodCurLumiBlock) continue;
222    
223     }
224    
225     for(int j=0; j< nElectron; j++){
226     electronecalEnergy[j] = electronscenergy[j]; //right now ecalEnerg = scEnergy
227     float corr = getElectronCorrection(j); ///correction from regression
228     electronecalEnergyCorr[j] = (electronscrawEnergy[j] + electronscpreshowerEnergy[j]) * corr;
229     }
230    
231    
232     vector<int> indsel;
233     for(int j=0; j< nElectron; j++){
234     if( electronecalDrivenSeed[j] ==0) continue;
235     float et = electronscenergy[j] * sin(2*atan(exp(-electroneta[j])));
236     if( et < 30 ) continue; ///ET > 30
237     if(! passElectronID(j,3)) continue; ///right now WP80
238     indsel.push_back(j);
239     }
240     if( int(indsel.size()) <2) continue;
241    
242     nsel ++;
243    
244    
245     for(int j=0; j<2;j++){
246     int k = indsel[j];
247     en[j] = electronecalEnergy[k];
248     encorr[j] = electronecalEnergyCorr[k];
249     eta[j] = electrongsfTracketa[k];
250     phi[j] = electrongsfTrackphi[k];
251     scr9[j] = electrone3x3[k]/electronscrawEnergy[k];
252     scrps[j] = electronscpreshowerEnergy[k] / electronscrawEnergy[k];
253     }
254    
255     calcPairObjects(11,11,en,eta,phi,res);
256     mpair = res[0];
257     calcPairObjects(11,11,encorr,eta,phi,res);
258     mpaircorr = res[0];
259    
260    
261     double evtweight =1;
262    
263    
264     ///get pile up weghit
265     if( ! isRealData){
266     int npubxav = 0;
267     for(unsigned int j =0; j < pileupBunchX->size(); j++){
268     int BX = pileupBunchX->at(j);
269     int npv = pileupNInteraction->at(j);
270     if( BX >=-1 && BX <= 1){
271     npubxav += npv;
272     }
273     }
274     npvbxav = npubxav*1.0/3;
275     int bin_weight = hh_pileupmc->FindFixBin(npvbxav) -1;
276     double puwt = LumiReWeighting_weightINT_v2(bin_weight, weights_pileup);
277    
278     evtweight = puwt;
279    
280     }
281    
282    
283     int ind1 = indsel[0];
284     int ind2 = indsel[1];
285     int bothEB = fabs(electronsceta[ind1]) < 1.482 && fabs(electronsceta[ind2]) < 1.482;
286     int bothEE = fabs(electronsceta[ind1]) > 1.482 && fabs(electronsceta[ind2]) > 1.482;
287     int bothHighR9 = scr9[0] > 0.94 && scr9[1] > 0.94;
288     int bothLowR9 = scr9[0] < 0.94 && scr9[1] < 0.94;
289     int bothLowEPS = scrps[0] < 0.05 && scrps[1] < 0.05;
290     int bothHighEPS = scrps[0] > 0.05 && scrps[1] > 0.05;
291    
292    
293    
294     bool fillflag[20] = {bothEB,
295     bothEB && bothHighR9,
296     bothEB && bothLowR9,
297     bothEE,
298     bothEE && bothHighR9,
299     bothEE && bothLowR9,
300     bothEE && bothHighR9 && bothLowEPS,
301     bothEE && bothHighR9 && bothHighEPS,
302     bothEE && bothLowR9 && bothLowEPS,
303     bothEE && bothLowR9 && bothHighEPS};
304    
305     for(int j=0; j< int( mpair_var.size()); j++){
306     if( fillflag[j]==false) continue;
307     string mpairname = mpair_var[j];
308     rv_mass->setVal(mpair);
309     hh_map_mpair[mpairname]->Fill(mpair,evtweight);
310     rhs_map_mpair[mpairname]->add(*rv_mass,evtweight);
311     rv_mass->setVal(mpaircorr);
312     mpairname = TString( Form("%s_corr",mpair_var[j].c_str()));
313     hh_map_mpaircorr[mpairname]->Fill(mpaircorr,evtweight);
314     rhs_map_mpair_corr[mpairname]->add(*rv_mass,evtweight);
315     }
316    
317     }
318    
319     cout <<" nsel" << nsel <<endl;
320    
321    
322     fnew->cd();
323     //RooContainer_Save();
324     RooWorkspace *w = new RooWorkspace("zeeShape","workspace") ;
325     for (std::map<string,RooDataSet*>::iterator it_data = rhs_map_mpair.begin()
326     ;it_data != rhs_map_mpair.end();it_data++) {
327     w->import(*it_data->second);
328     }
329     for (std::map<string,RooDataSet*>::iterator it_data = rhs_map_mpair_corr.begin()
330     ;it_data != rhs_map_mpair_corr.end();it_data++) {
331     w->import(*it_data->second);
332     }
333     w->Write();
334    
335     fnew->Write();
336     fnew->Close();
337     }