isystrename.C
Go to the documentation of this file.
1 /// isystrename.C by J. Hewes (jhewes15@fnal.gov)
2 // I found the ISyst names were malformed because of an error in the NusSystematicsMaker
3 // constructor. I threw together this little macro which corrects this error everywhere
4 // it shows up.
5 
6 #include <iostream>
7 
8 #include "TFile.h"
9 #include "TKey.h"
10 #include "TObjString.h"
11 
12 #include "NuXAna/Analysis/NusSystsMaker.h"
13 
14 using namespace ana;
15 
16 void isystrename() {
17 
18  std::string det = "fardet";
19 
20  TFile* f_in = TFile::Open(Form("isysts_%s.root", det.c_str()), "update");
21  TFile* f_out = TFile::Open(Form("isysts_%s_v2.root", det.c_str()), "recreate");
22 
23  std::string new_prefix = "nus_fhc_"+det;
24 
25  TDirectory* topdir = f_in->GetDirectory(Form("systmaker_nc_%s", det.c_str()));
26  TDirectory* outdir = f_out->mkdir(new_prefix.c_str());
27 
28  TIter next(topdir->GetListOfKeys());
29  TKey* key;
30  while ((key = (TKey*)next())) {
31  TDirectory* systdir = (TDirectory*)key->ReadObj();
32  systdir->cd();
33 
34  TObjString* obj = (TObjString*)systdir->Get("name");
35  std::string name(obj->String());
36  name = name.substr(8+det.length());
37  name = new_prefix+"_"+name;
38  TObjString newname(name.c_str());
39  newname.Write("name", TObject::kOverwrite);
40 
41  TObjString newsname(new_prefix.c_str());
42  newsname.Write("sample_name", TObject::kOverwrite);
43 
44  NusISyst* syst = NusISyst::LoadFrom(systdir).release();
45  syst->SaveTo(outdir, syst->ShortName().c_str());
46  }
47 
48  delete f_in;
49  delete f_out;
50 
51 }
const XML_Char * name
Definition: expat.h:151
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
std::unique_ptr< T > LoadFrom(TDirectory *dir, const std::string &label)
Definition: LoadFromFile.h:17
void next()
Definition: show_event.C:84
const std::string outdir
void isystrename()
Definition: isystrename.C:16
enum BeamMode string