ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/merge.cc
Revision: 1.2
Committed: Mon Dec 17 12:33:56 2012 UTC (12 years, 5 months ago) by dkralph
Content type: text/plain
Branch: MAIN
CVS Tags: compiled
Changes since 1.1: +25 -12 lines
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     // Main macro function
28     //--------------------------------------------------------------------------------------------------
29     int main(int argc, char** argv)
30     {
31     initPUWeights();
32    
33     char * argv1 = argv[1];
34     TString input(argv1);
35     char * argv2 = argv[2];
36     assert(argc>1); TString dset(argv2);
37     assert(argc>2); long ntot = atoi(argv[3]);
38     assert(argc>3); bool isdata = bool(atoi(argv[4]));
39 dkralph 1.2 //????????????????????????????????????????????????????????????????????????????????????????
40     // note: reset below
41 dkralph 1.1 assert(argc>4); bool fos = bool(atoi(argv[5]));
42 dkralph 1.2 //????????????????????????????????????????????????????????????????????????????????????????
43 dkralph 1.1 assert(argc>5); int era = atoi(argv[6]);
44    
45     TString outfilename; // output of merged files
46     vector<TString> infilenames; // list input ntuple files to be stored
47    
48     TString cmsswpath(CMSSW_BASE + TString("/src"));
49     string xspath = (string(cmsswpath)+"/MitPhysics/data/xs.dat");
50     SimpleTable xstab(xspath.c_str());
51    
52     //
53     // parse input file
54     //
55     ifstream ifs;
56     ifs.open(input.Data());
57     assert(ifs.is_open());
58     string line;
59     getline(ifs,line);
60     outfilename = line;
61     while(getline(ifs,line)) { infilenames.push_back(line); }
62     ifs.close();
63    
64     TString tmpfname(outfilename);
65     tmpfname.ReplaceAll("merged.root","merged-tmp.root");
66 dkralph 1.2 //
67     // doing this with hadd beforehand now...
68     //
69     // TFile tmpfile(tmpfname,"recreate");
70     // TChain zzchain("zznt");
71     // TChain FOchain("FOtree");
72     // 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
73    
74     // for(UInt_t ifile=0; ifile<infilenames.size(); ifile++) {
75     // zzchain.Add(infilenames[ifile]);
76     // if(fos)
77     // FOchain.Add(infilenames[ifile]);
78     // }
79     // zzchain.Merge(tmpfname,"fast");
80     // if(fos)
81     // FOchain.Merge(tmpfname,"fast");
82 dkralph 1.1
83     filestuff fs(dset,tmpfname,dset,isdata,era);
84 dkralph 1.2 fos = fs.hasfo_;
85 dkralph 1.1 fs.makeOutputFile(outfilename,fos);
86    
87     double xswgt = isdata ? 1 : xstab.Get(fs.dataset_) / ntot;
88    
89     for(unsigned ientry=0; ientry<fs.getentries("zznt"); ientry++) {
90     fs.getentry(ientry,"","zznt");
91 dkralph 1.2 if(fos) {
92     fs.getentry(ientry,"FOs","FOtree");
93     fs.getentry(ientry,"Zleptons","FOtree");
94     }
95     // if(fos) fs.getentry(ientry,"","FOs"); // WARNING: doesn't friggin work. dunno why...
96 dkralph 1.1
97     if(!isdata) {
98     fs.weights->w = xswgt;
99     int npu = fs.weights->npu;
100     // fs.weights->npuw = (dset.Contains("f11")) ? hpu_2011->GetBinContent(hpu_2011->FindBin(npu)) : hpu_2012->GetBinContent(hpu_2012->FindBin(npu));
101     fs.weights->npuw = getPUWeight(fs.era_, "", npu);
102     }
103     fs.outtuple->Fill();
104     if(fos) fs.outFotuple->Fill();
105     }
106     if(fos) {
107     fs.outFotuple->getFile()->cd();
108     fs.outFotuple->getTree()->Write();
109     }
110     fs.outtuple->WriteClose();
111     }