babymaker  e95a6a9342d4604277fe7cc6149b6b5b24447d89
change_xsec.cxx
Go to the documentation of this file.
1 // change_xsec: Changes cross section of ntuple
2 
3 #include <iostream>
4 #include <ctime>
5 #include <string>
6 #include <vector>
7 
8 #include "TChain.h"
9 #include "TError.h"
10 #include "TSystem.h"
11 #include "TDirectory.h"
12 
13 #include "utilities.hh"
14 #include "cross_sections.hh"
15 
16 using namespace std;
17 
18 int main(int argc, char *argv[]){
19  time_t begtime, endtime;
20  time(&begtime);
21 
22  if(argc<1){
23  cout<<"Format: ./run/change_xsec.exe infile <outfolder>"<<endl;
24  return 1;
25  }
26 
27  // Take command line arguments
28  TString infile("/net/cms2/cms2r0/babymaker/babies/2016_02_09/mc/T2tt/baby_SMS-T2tt_mGluino-550_mLSP-375_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15FSPremix-MCRUN2_74_V9-v1_renorm.root"), outfolder("new_stops");
29  if(argc>=2) infile = argv[1];
30  if(argc>=3) outfolder=argv[2];
31  if(!outfolder.EndsWith("/")) outfolder.Append("/");
32  gSystem->mkdir(outfolder, kTRUE);
33 
34  TString folder(infile), file(infile);
35  folder.Remove(folder.Last('/')+1, folder.Length());
36  file.Remove(0, file.Last('/')+1);
37 
38  // Parsing masses
39  TString mstop_s(infile);
40  mstop_s.Remove(0,mstop_s.Index("ino-")+4);
41  mstop_s.Remove(mstop_s.Index('_'), mstop_s.Length());
42  int mstop(mstop_s.Atoi());
43  TString mlsp_s(infile);
44  mlsp_s.Remove(0,mlsp_s.Index("LSP-")+4);
45  mlsp_s.Remove(mlsp_s.Index('_'), mlsp_s.Length());
46  int mlsp(mlsp_s.Atoi());
47  TString stop_lsp = "mGluino-"+mstop_s+"_mLSP-"+mlsp_s;
48 
49 
50  float xsecOri, xsecNew, exsec;
51  xsec::stopCrossSection(mstop, xsecOri, exsec);
52 
53  for(int mstopNew = mstop+25; mstopNew <= 1500; mstopNew += 25){
54  xsec::stopCrossSection(mstopNew, xsecNew, exsec);
55  TString factorXsec("*"); factorXsec += xsecNew/xsecOri;
56  cout<<"mstop "<<mstop<<", xsecOri "<<xsecOri<<", new stop "<<mstopNew<<", xsecNew "<<xsecNew<<", factor "<<factorXsec<<endl;
57  TString newname = file;
58  TString stopNew_lsp = "mGluino-"+to_string(mstopNew)+"_mLSP-"+to_string(mlsp+mstopNew-mstop);
59  newname.ReplaceAll(stop_lsp, stopNew_lsp);
60  vector<TString> var_types({"float", "float"}), vars({"weight","w_lumi"}), var_vals({factorXsec, factorXsec});
61  change_branch_one(folder, file, outfolder, var_types, vars, var_vals, newname);
62  cout<<"Saved "<<outfolder<<newname<<endl;
63  }
64 
65  time(&endtime);
66  int seconds = difftime(endtime, begtime);
67  cout<<endl<<"Took "<<seconds<<" seconds ("<<hoursMinSec(seconds)<<") "<<endl<<endl;
68 }
TString hoursMinSec(long seconds)
Definition: utilities.cc:599
void stopCrossSection(int stop_mass, float &xsec, float &xsec_unc)
STL namespace.
int change_branch_one(TString indir, TString name, TString outdir, std::vector< TString > var_type, std::vector< TString > var, std::vector< std::vector< TString > > var_val, int totentries)
Definition: utilities.cc:32
int main(int argc, char *argv[])
Definition: change_xsec.cxx:18