ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/merge.cc
Revision: 1.3
Committed: Tue Jan 15 10:09:16 2013 UTC (12 years, 4 months ago) by dkralph
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +0 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
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 "KinematicsStruct.h"
14 #include "InfoStruct.h"
15 #include "GenInfoStruct.h"
16 #include "WeightStruct.h"
17 #include "AngleTuple.h"
18 #include "FOTuple.h"
19 #include "filestuff.h"
20 #include "SelectionFuncs.h"
21
22 #ifndef CMSSW_BASE
23 #define CMSSW_BASE "../../"
24 #endif
25
26 // Main macro function
27 //--------------------------------------------------------------------------------------------------
28 int main(int argc, char** argv)
29 {
30 initPUWeights();
31
32 char * argv1 = argv[1];
33 TString input(argv1);
34 char * argv2 = argv[2];
35 assert(argc>1); TString dset(argv2);
36 assert(argc>2); long ntot = atoi(argv[3]);
37 assert(argc>3); bool isdata = bool(atoi(argv[4]));
38 //????????????????????????????????????????????????????????????????????????????????????????
39 // note: reset below
40 assert(argc>4); bool fos = bool(atoi(argv[5]));
41 //????????????????????????????????????????????????????????????????????????????????????????
42 assert(argc>5); int era = atoi(argv[6]);
43
44 TString outfilename; // output of merged files
45 vector<TString> infilenames; // list input ntuple files to be stored
46
47 TString cmsswpath(CMSSW_BASE + TString("/src"));
48 string xspath = (string(cmsswpath)+"/MitPhysics/data/xs.dat");
49 SimpleTable xstab(xspath.c_str());
50
51 //
52 // parse input file
53 //
54 ifstream ifs;
55 ifs.open(input.Data());
56 assert(ifs.is_open());
57 string line;
58 getline(ifs,line);
59 outfilename = line;
60 while(getline(ifs,line)) { infilenames.push_back(line); }
61 ifs.close();
62
63 TString tmpfname(outfilename);
64 tmpfname.ReplaceAll("merged.root","merged-tmp.root");
65 //
66 // doing this with hadd beforehand now...
67 //
68 // TFile tmpfile(tmpfname,"recreate");
69 // TChain zzchain("zznt");
70 // TChain FOchain("FOtree");
71 // TString command("hadd -k -f "$dir/merged.root $dir/[^m][^e][^r][^g][^e][^d]*.root 2>&1 | grep -v 'hadd Source\|hadd Target\|no dictionary for class' | tee -a badfiles.txt
72
73 // for(UInt_t ifile=0; ifile<infilenames.size(); ifile++) {
74 // zzchain.Add(infilenames[ifile]);
75 // if(fos)
76 // FOchain.Add(infilenames[ifile]);
77 // }
78 // zzchain.Merge(tmpfname,"fast");
79 // if(fos)
80 // FOchain.Merge(tmpfname,"fast");
81
82 filestuff fs(dset,tmpfname,dset,isdata,era);
83 fos = fs.hasfo_;
84 fs.makeOutputFile(outfilename,fos);
85
86 double xswgt = isdata ? 1 : xstab.Get(fs.dataset_) / ntot;
87
88 for(unsigned ientry=0; ientry<fs.getentries("zznt"); ientry++) {
89 fs.getentry(ientry,"","zznt");
90 if(fos) {
91 fs.getentry(ientry,"FOs","FOtree");
92 fs.getentry(ientry,"Zleptons","FOtree");
93 }
94 // if(fos) fs.getentry(ientry,"","FOs"); // WARNING: doesn't friggin work. dunno why...
95
96 if(!isdata) {
97 fs.weights->w = xswgt;
98 int npu = fs.weights->npu;
99 // fs.weights->npuw = (dset.Contains("f11")) ? hpu_2011->GetBinContent(hpu_2011->FindBin(npu)) : hpu_2012->GetBinContent(hpu_2012->FindBin(npu));
100 fs.weights->npuw = getPUWeight(fs.era_, "", npu);
101 }
102 fs.outtuple->Fill();
103 if(fos) fs.outFotuple->Fill();
104 }
105 if(fos) {
106 fs.outFotuple->getFile()->cd();
107 fs.outFotuple->getTree()->Write();
108 }
109 fs.outtuple->WriteClose();
110 }