-
Notifications
You must be signed in to change notification settings - Fork 5
/
run.C
113 lines (95 loc) · 3.86 KB
/
run.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "TString.h"
#include <iostream>
#include <fstream>
#include "TProof.h"
std::vector<TString> TStringToVector(TString t, char separator = ','){
std::vector<TString> v;
t.ReplaceAll(" ", "");
Int_t n = t.CountChar(separator);
TString element;
for(Int_t i = 0; i < n; i++){
element = t(0, t.First(separator));
t = t(t.First(separator)+1, t.Sizeof());
v.push_back(element);
}
v.push_back(t);
return v;
}
std::vector<Double_t> TStringToDouble(TString t, char separator = ','){
std::vector<TString> tv = TStringToVector(t, separator);
std::vector<Double_t> fv;
Int_t n = tv.size();
for(int i = 0; i < n; i++){
fv.push_back(tv.at(i).Atof());
}
return fv;
}
void run(TString samp, TString selection, Double_t xsec, Double_t sumofweights, Int_t year, TString outname, Int_t nSlots = 1, TString outpath = "", TString options = "", Bool_t isamcatnlo = false, Bool_t isData = false, Long64_t nEvents = 0, Long64_t FirstEvent = 0, TString workingdir = "", TString path = "", Bool_t debug = false, TString SumOfMEweights = "", TString SumOfPDFweights = "") {
if (debug) {
gProofDebugMask = TProofDebug::kAll;
gProofDebugLevel = 5;
}
PAFProject* myProject = 0;
vector<TString> samples = TStringToVector(samp);
if(path != ""){
if(!path.EndsWith("/")) path += "/";
Int_t nFiles = samples.size(); Int_t i;
for(i = 0; i < nFiles; i++) samples.at(i) = path + samples.at(i);
}
// PAF mode selection (based on number of slots)
PAFIExecutionEnvironment* pafmode = 0;
if (nSlots <=1 ) pafmode = new PAFSequentialEnvironment();
else pafmode = new PAFPROOFLiteEnvironment(nSlots);
myProject = new PAFProject(pafmode);
myProject->AddDataFiles(samples);
myProject->SetDefaultTreeName("/Events");
// Deal with first and last event
if (nEvents > 0 ) myProject->SetNEvents(nEvents);
if (FirstEvent > 0) myProject->SetFirstEvent(FirstEvent);
// Set output file
if(outpath == "") outpath = "./"+selection+"_temp";
gSystem->mkdir(outpath, 1);
TString outfilename = Form("%s", outname.Data());
if(!outfilename.EndsWith(".root")) outfilename += ".root";
myProject->SetOutputFile(outpath + "/" + outfilename);
Double_t tmpw = xsec/sumofweights;
// Parameters for the analysis
if(workingdir == "") workingdir = gSystem->pwd();
myProject->SetInputParam("sampleName", outname);
myProject->SetInputParam("sampString", samp);
myProject->SetInputParam("IsData", isData);
myProject->SetInputParam("weight", tmpw);
myProject->SetInputParam("IsMCatNLO", isamcatnlo);
myProject->SetInputParam("selection", selection);
myProject->SetInputParam("WorkingDir", workingdir);
myProject->SetInputParam("xsec", xsec);
myProject->SetInputParam("path", path); //quitar
myProject->SetInputParam("_options", options);
myProject->SetInputParam("year", TString(Form("%i",year)));
myProject->SetInputParam("SumOfPDFweights", SumOfPDFweights);
myProject->SetInputParam("SumOfMEweights", SumOfMEweights);
if (selection == "TWAnalysis") {
TString tmvalibpath = gSystem->Getenv("ROOTSYS");
tmvalibpath += "/lib/libTMVA.so";
myProject->AddLibrary(tmvalibpath);
}
// Adding packages
myProject->AddSelectorPackage("LeptonSelector");
myProject->AddSelectorPackage("JetSelector");
myProject->AddSelectorPackage("EventBuilder");
// Analysis selector
if (selection != "")
myProject->AddSelectorPackage(selection);
//if (selection == "TopAnalysis")
// myProject->AddSelectorPackage("LepEffTop");
// Additional packages
myProject->AddPackage("Lepton");
myProject->AddPackage("Jet");
myProject->AddPackage("Functions");
if (selection == "TopAnalysis") myProject->AddPackage("mt2");
myProject->AddPackage("LeptonSF");
myProject->AddPackage("BTagSFUtil");
if (selection == "TopAnalysis")
myProject->AddPackage("SUSYnorm");
myProject->Run();
}