ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/merge.cc
Revision: 1.1
Committed: Tue Oct 23 11:39:21 2012 UTC (12 years, 6 months ago) by dkralph
Content type: text/plain
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 dkralph 1.1 #include <TROOT.h>
2     #include <TChain.h>
3     #include <TFile.h>
4     #include <TString.h>
5     #include <TBenchmark.h>
6     #include <vector>
7     #include <iostream>
8     #include <fstream>
9     #include <string>
10     #include <assert.h>
11    
12     #include "SampleWeight.h"
13     #include "Angles.h"
14     #include "KinematicsStruct.h"
15     #include "InfoStruct.h"
16     #include "GenInfoStruct.h"
17     #include "WeightStruct.h"
18     #include "AngleTuple.h"
19     #include "FOTuple.h"
20     #include "filestuff.h"
21     #include "SelectionFuncs.h"
22    
23     #ifndef CMSSW_BASE
24     #define CMSSW_BASE "../../"
25     #endif
26    
27     TH1D *hpu_2011, *hpu_2012;
28    
29     // Main macro function
30     //--------------------------------------------------------------------------------------------------
31     int main(int argc, char** argv)
32     // void MergeNtuples(TString input, TString dset, long ntot)
33     {
34     initPUWeights();
35    
36     char * argv1 = argv[1];
37     TString input(argv1);
38     char * argv2 = argv[2];
39     assert(argc>1); TString dset(argv2);
40     assert(argc>2); long ntot = atoi(argv[3]);
41     assert(argc>3); bool isdata = bool(atoi(argv[4]));
42     assert(argc>4); bool fos = bool(atoi(argv[5]));
43     assert(argc>5); int era = atoi(argv[6]);
44    
45     // cout << "args: " << input << " " << dset << " " << ntot << " " << isdata << " " << fos << endl;
46    
47     TString outfilename; // output of merged files
48     vector<TString> infilenames; // list input ntuple files to be stored
49    
50     TString cmsswpath(CMSSW_BASE + TString("/src"));
51     string xspath = (string(cmsswpath)+"/MitPhysics/data/xs.dat");
52     SimpleTable xstab(xspath.c_str());
53    
54     //
55     // parse input file
56     //
57     ifstream ifs;
58     ifs.open(input.Data());
59     assert(ifs.is_open());
60     string line;
61     getline(ifs,line);
62     outfilename = line;
63     while(getline(ifs,line)) { infilenames.push_back(line); }
64     ifs.close();
65    
66     TString tmpfname(outfilename);
67     tmpfname.ReplaceAll("merged.root","merged-tmp.root");
68     TFile tmpfile(tmpfname,"recreate");
69     TChain zzchain("zznt");
70     for(UInt_t ifile=0; ifile<infilenames.size(); ifile++) {
71     zzchain.Add(infilenames[ifile]);
72     }
73     zzchain.Merge(tmpfname,"fast");
74    
75     filestuff fs(dset,tmpfname,dset,isdata,era);
76     fs.makeOutputFile(outfilename,fos);
77    
78     double xswgt = isdata ? 1 : xstab.Get(fs.dataset_) / ntot;
79    
80     for(unsigned ientry=0; ientry<fs.getentries("zznt"); ientry++) {
81     fs.getentry(ientry,"","zznt");
82     if(fos) fs.getentry(ientry,"","FOs");
83    
84     if(!isdata) {
85     fs.weights->w = xswgt;
86     int npu = fs.weights->npu;
87     // fs.weights->npuw = (dset.Contains("f11")) ? hpu_2011->GetBinContent(hpu_2011->FindBin(npu)) : hpu_2012->GetBinContent(hpu_2012->FindBin(npu));
88     fs.weights->npuw = getPUWeight(fs.era_, "", npu);
89     }
90     fs.outtuple->Fill();
91     if(fos) fs.outFotuple->Fill();
92     }
93     if(fos) {
94     fs.outFotuple->getFile()->cd();
95     fs.outFotuple->getTree()->Write();
96     }
97     fs.outtuple->WriteClose();
98     }