#include #include #include #include #include #include using namespace std; void makeObEventTree(TString fName){ TFile* f = TFile::Open(fName,"UPDATE"); TTree* treeR = (TTree*) f->Get("treeR"); TString productName = "BASICCALOJETS1MATCHED"; TTree* newTree = new TTree(TString::Format("tree_%s",productName.Data()),TString::Format("tree_%s",productName.Data())); vector globalVars = { "ONZ", "hasGoodVertex", "hasDoubleElTriggers", "hasDoubleMuTriggers", "hasSingleElTriggers", "hasSingleMuTriggers", "Max$(abs(LEPTON_DPHI))", "Min$(abs(LEPTON_DPHI))", "MET", "PTOSSF", TString::Format("N%s",productName.Data()), "Alt$(MT,0)", "Alt$(WPT,0)", "EVENT", "NBASICCALOJETS" }; vector objVars = { "MISSINGINNER", "MISSINGOUTER", "NCLEANMATCHEDTRACKS", "NMATCHEDTRACKS", "NTRACKSIPLT0P05", "NTRACKSIPSIGGT10", "NTRACKSIPSIGLT5", "ALPHAMAX2", "ALPHAMAXPRIME2", "ALPHAMAXPRIME", "ALPHAMAX", "ASSOCAPLANARITY", "ASSOCIATEDTRACKPT", "ASSOCSPHERICITY", "ASSOCTHRUSTMAJOR", "ASSOCTHRUSTMINOR", "BETA2", "BETA", "ETA", "HITSINFRONTOFVERTPERTRACK", "IVFSCORE", "JETAREA", "LEPANGLE_DANGLE", "LEPANGLE_DPHI", "LEPDELTAR", "LINEARRADIALMOMENT", "MEDIANIPLOG10SIG", "MEDIANIPLOGSIG", "MEDIANLOG10TRACKANGLE", "METANGLE_DANGLE", "METANGLE_DPHI", "METDELTAR", "MISSHITSAFTERVERTPERTRACK", "PHI", "PT", "STUPAKPT", "STUPAKR", "SUMIPLOGSIG", "SUMIPSIG", "SUMIP", "TOTALTRACKANGLEPT", "TOTALTRACKANGLE", "TOTALTRACKPT", "TRACKENERGY", "TRACKMASS", "AVFASSOCSPHERICITY", "AVFASSOCTHRUSTMAJOR", "AVFVERTEXDISTANCETOBEAM", "AVFVERTEXTRACKENERGY", "AVFBEAMSPOTRECOILPT", "AVFVERTEXTRANSVERSESIG", "AVFVERTEXTRACKMASS" }; double allVals[globalVars.size() + objVars.size()]; for(int i=0; i < globalVars.size() + objVars.size(); i++){ allVals[i] = 0; } TString varexp = ""; for(int i=0; i < globalVars.size(); i++){ if(i == 0) varexp += globalVars[i]; else varexp += TString::Format(":%s",globalVars[i].Data()); if(globalVars[i].Contains("abs(LEPTON_DPHI)") || globalVars[i].Contains("Alt$")){ globalVars[i].ReplaceAll("$(abs(","_"); globalVars[i].ReplaceAll("Alt$(",""); globalVars[i].ReplaceAll(",0)",""); globalVars[i].ReplaceAll(")",""); } cout << "adding branch " << globalVars[i].Data() << endl; newTree->Branch(globalVars[i],&(allVals[i]),TString::Format("%s/D",globalVars[i].Data())); } treeR->Draw(varexp,"","goff para"); vector globValues; for(int i=0; i < globalVars.size(); i++){ globValues.push_back(treeR->GetVal(i)); } vector*> objValues; for(int j=0; j < objVars.size(); j++) objValues.push_back(0); for(int j=0; j < objVars.size(); j++){ objVars[j] += TString::Format("_%s",productName.Data()); treeR->SetBranchAddress(objVars[j],&(objValues[j])); cout << "adding branch " << objVars[j].Data() << endl; newTree->Branch(objVars[j],&(allVals[globalVars.size()+j]),TString::Format("%s/D",objVars[j].Data())); } int nEvents = (int)treeR->GetEntries(); for(int event=0; event < nEvents; event++){ if(event%10000 == 0) cout << "processing event: " << event << " of " << nEvents << endl; treeR->GetEntry(event); for(int i=0; i < globalVars.size(); i++){ allVals[i] = globValues[i][event]; } for(int obj=0; obj < objValues[0]->size(); obj++){ for(int j=0; j < objVars.size(); j++){ allVals[globalVars.size()+j] = (*objValues[j])[obj]; } newTree->Fill(); } } newTree->Write(); f->Close(); }