void updateweight(TString filename) { auto f = new TFile(filename,"update"); auto nt = (TTree *)f->Get("nt"); float prew, weight; TBranch *bw; bw = nt->Branch("weight",&weight); nt->SetBranchAddress("prew",&prew); int n = nt->GetEntries(); int onep = n/100; for (int i=0;i<n;i++) { if (i%onep==0) cout<<i/onep<<endl; nt->GetEntry(i); weight = prew; bw->Fill(); } nt->Write(); f->Close(); }
int SetBranchAddress(TTree *tree,int nBranches,TString *trybranches,void *variable) { int result = -6; for (int i = 0; i < nBranches; i++) { result = SetBranchAddress(tree,trybranches[i],variable); if (result >= 0) break; } return result; }
void updatePbPbBtriggerweight(TString filename, vector<float> w) { auto f = new TFile(filename,"update"); auto nt = (TTree *)f->Get("nt"); float csv60, csv80; float triggermatched; float weight; TBranch *bw; bw = nt->Branch("weight",&weight); nt->SetBranchAddress("hltCSV60",&csv60); nt->SetBranchAddress("hltCSV80",&csv80); nt->SetBranchAddress("triggermatched",&triggermatched); int n = nt->GetEntries(); int onep = n/100; for (int i=0;i<n;i++) { if (i%onep==0) cout<<i/onep<<endl; nt->GetEntry(i); weight = 0; if (triggermatched && csv80) weight = w[1]; if (triggermatched && csv60 && !csv80) weight = w[0]; bw->Fill(); } nt->Write(); f->Close(); }
int SetBranchAddress(TTree *tree,TString branch1,TString branch2,TString branch3,void *variable) { TString trybranches[3] = {branch1,branch2,branch3}; return SetBranchAddress(tree,3,trybranches,variable); }