void THisHandler::FillHists() { fTree->SetBranchStatus("*", 0); TVector3 position; fTree->SetBranchStatus("x", 1); fTree->SetBranchStatus("y", 1); fTree->SetBranchStatus("z", 1); fTree->SetBranchAddress("x", &position[0]); fTree->SetBranchAddress("y", &position[1]); fTree->SetBranchAddress("z", &position[2]); Char_t volumeName[256]; // Array size is enough? fTree->SetBranchStatus("VolumeName", 1); fTree->SetBranchAddress("VolumeName", volumeName); Double_t ene; fTree->SetBranchStatus("DepositEnergy", 1); fTree->SetBranchAddress("DepositEnergy", &ene); const Int_t kEntries = fTree->GetEntries(); for(Int_t iEntry = 0; iEntry < kEntries; iEntry++){ //if(iEntry%100000 == 0) cout << iEntry <<" / "<< kEntries << endl; fTree->GetEntry(iEntry); if(!(ene > 0.)) continue; fHisAll->Fill(position.X(), position.Y(), position.Z(), ene); if(TString(volumeName) == "Sealing") fHisSealing->Fill(position.X(), position.Y(), position.Z(), ene); else if(TString(volumeName) == "Window") fHisWindow->Fill(position.X(), position.Y(), position.Z(), ene); else if(TString(volumeName) == "Foil") fHisFoil->Fill(position.X(), position.Y(), position.Z(), ene); else if(TString(volumeName) == "Holder") fHisHolder->Fill(position.X(), position.Y(), position.Z(), ene); else if(TString(volumeName) == "Cassette") fHisCassette->Fill(position.X(), position.Y(), position.Z(), ene); else if(TString(volumeName) == "Air") fHisAir->Fill(position.X(), position.Y(), position.Z(), ene); else if(TString(volumeName) == "Plate" || TString(volumeName) == "Well" || TString(volumeName) == "Outer") fHisPlate->Fill(position.X(), position.Y(), position.Z(), ene); else if(TString(volumeName) == "Film") fHisFilm->Fill(position.X(), position.Y(), position.Z(), ene); else if(TString(volumeName) == "Stuff") fHisWell->Fill(position.X(), position.Y(), position.Z(), ene); else if(TString(volumeName) == "Cell"){ Int_t wellID = XYtoIndex(position.X(), position.Y()); fHisEachCell20[wellID]->Fill(position.X(), position.Y(), ene); fHisEachCell50[wellID]->Fill(position.X(), position.Y(), ene); } } }
void ConnectFriends() { // Connect the friends tree as soon as available. // // Handle the friends first // if (!esdTree->FindBranch("ESDfriend.")) { // Try to add ESDfriend. branch as friend TString esdFriendTreeFName; esdFriendTreeFName = (esdTree->GetCurrentFile())->GetName(); TString basename = gSystem->BaseName(esdFriendTreeFName); Int_t index = basename.Index("#")+1; basename.Remove(index); basename += "AliESDfriends.root"; TString dirname = gSystem->DirName(esdFriendTreeFName); dirname += "/"; esdFriendTreeFName = dirname + basename; // TTree* cTree = esdTree->GetTree(); if (!cTree) cTree = esdTree; cTree->AddFriend("esdFriendTree", esdFriendTreeFName.Data()); cTree->SetBranchStatus("ESDfriend.", 1); esdFr = (AliESDfriend*)(esdEv->FindListObject("AliESDfriend")); if (esdFr) cTree->SetBranchAddress("ESDfriend.", &esdFr); } }
void skim(){ int numSkip = 1013; TFile* file = TFile::Open("bigFile.root"); TTree* tree = (TTree*) file->Get("T"); Long64_t nEntries = tree->GetEntries(); ULong64_t event; tree->SetBranchAddress("event", &event); tree->SetBranchStatus("*",1); TFile *newfile = new TFile("skimmedTree.root","recreate"); TTree *newtree = tree->CloneTree(0); for (Long64_t n=0; n<nEntries; n++) { tree->GetEntry(n); if (event % numSkip == 0) newtree->Fill(); } newtree->Print(); newfile->Write(); delete file; delete newfile; }
void mass_fit() { TFile *file = new TFile("/nfs/lhcb/malexander01/charm/4pi/data/full-run-I/full_2011_data.root"); TTree *tree = (TTree*) file->Get("Dst2010ToD0TopipipipipiTuple/DecayTree;1"); tree->SetBranchStatus("*", 0) ; tree->SetBranchStatus("D0_M", 1) ; tree->SetBranchStatus("D0_L0HadronDecision_TOS", 1); tree->SetBranchStatus("lab0_L0Global_TIS", 1); tree->SetBranchStatus("D0_Hlt1TrackAllL0Decision_TOS", 1); tree->SetBranchStatus("lab0_Hlt2CharmHadD02HHHHDecision_TOS", 1); tree->SetBranchStatus("piplus_P", 1); tree->SetBranchStatus("piplus_PT",1); //RooRealVar D0_M("D0_M","D0_M",1780,1950); RooRealVar D0_M("D0_M","D0_M",1805,1925); RooRealVar D0_L0HadronDecision_TOS("D0_L0HadronDecision_TOS","D0_L0HadronDecision_TOS",0,2); RooRealVar lab0_L0Global_TIS("lab0_L0Global_TIS","lab0_L0Global_TIS",0,2); RooRealVar lab0_Hlt2CharmHadD02HHHHDecision_TOS("lab0_Hlt2CharmHadD02HHHHDecision_TOS","lab0_Hlt2CharmHadD02HHHHDecision_TOS",0,2); RooRealVar D0_Hlt1TrackAllL0Decision_TOS("D0_Hlt1TrackAllL0Decision_TOS","D0_Hlt1TrackAllL0Decision_TOS",0,2); RooRealVar piplus_P("piplus_P","piplus_P",0,20e6); RooRealVar piplus_PT("piplus_PT","piplus_PT",0,540e3); // --Constructors-- // const char* name,const char* title,const RooArgSet &vars,const char* wgtVarName = 0 (for an empty ds) // const char* name,const char* title,TTree* intree,const RooArgSet& vars,const char* selExpr = 0,const char* wgtVarName = 0 (obtained from tree) //RooDataSet data("data","data",tree,RooArgSet(D0_M,lab0_Hlt2CharmHadD02HHHHDecision_TOS)); RooDataSet data("data","data",RooArgSet(D0_M,D0_L0HadronDecision_TOS,lab0_L0Global_TIS,lab0_Hlt2CharmHadD02HHHHDecision_TOS,D0_Hlt1TrackAllL0Decision_TOS,piplus_P,piplus_PT),Import(*tree),Cut("(D0_L0HadronDecision_TOS||lab0_L0Global_TIS)&&lab0_Hlt2CharmHadD02HHHHDecision_TOS&&D0_Hlt1TrackAllL0Decision_TOS&&(piplus_P>3000)&&(piplus_PT>350)")); //RooDataSet data = data.reduce("lab0_Hlt2CharmHadD02HHHHDecision_TOS && D0_Hlt1TrackAllL0Decision_TOS && (lab0_L0Global_TIS || D0_L0HadronDecision_TOS) && piplus_P > 3000 && piplus_PT > 350"); // Gaussian signal PDF RooRealVar sigmean("sigmean","D^{0} mass",1865,1805,1925); RooRealVar sigwidth("sigwidth","D^{0} width",2.5,0.,10.); RooGaussian signal("signal","Signal PDF",D0_M,sigmean,sigwidth); /* // Linear background PDF RooRealVar a_coeff("a_coeff","a_coeff",.5,0.,1.); RooRealVar b_coeff("b_coeff","b_coeff",45000.,40000.,50000.); RooPolynomial bkg("bkg","bkg",D0_M,RooArgSet(a_coeff,b_coeff)); */ // Expo bakcground RooRealVar expo("expo", "expo shape parameter", 0., -10., 10.); RooExponential bkg("bkg", "bkg", D0_M, expo); RooRealVar bkgfrac("bkgfrac","bkgfrac",.9,0.,1.); RooAddPdf model("model", "Sg+Bkg",RooArgList(signal,bkg),bkgfrac); model.fitTo(data); //model.fitTo(data, Extended(),NumCPU(6)); TCanvas c; RooPlot* frame = D0_M.frame(); data.plotOn(frame); model.plotOn(frame); frame->Draw(); c.SaveAs("D0_mass_fit_all_cuts.eps"); }
void TestTree(const char* filename, const char* treename, int numbranches, int branchsize, int activebranches, float* RealTime, float* CpuTime) { TFile f(filename); TTree* t = (TTree*) f.Get(treename); Float_t* data = new Float_t[numbranches*branchsize]; for(int nbr=0;nbr<numbranches;nbr++) { TString brname = "Branch"; brname+=nbr; t->SetBranchAddress(brname,&(data[nbr*branchsize])); } if (activebranches<=0) t->SetBranchStatus("*",1); else { t->SetBranchStatus("*",0); for (int nbr=0;nbr<activebranches;nbr++) { TString brname = "Branch"; brname+=nbr; t->SetBranchStatus(brname,1); } } Int_t counter = 0; if (RealTime && CpuTime) { gBenchmark->Reset(); gBenchmark->Start("TestTree"); } while (t->GetEntry(counter++)); if (RealTime && CpuTime) { gBenchmark->Stop("TestTree"); gBenchmark->Show("TestTree"); *RealTime = gBenchmark->GetRealTime("TestTree"); *CpuTime = gBenchmark->GetCpuTime("TestTree"); } delete[] data; }
void CommonFiducialSkim() { // Example of Root macro to copy a subset of a Tree to a new Tree //gSystem->Load("$ROOTSYS/test/libEvent"); //Get old file, old tree and set top branch address TFile *origFile = new TFile(origFileLoc.c_str()); TTree *origTree = (TTree*)origFile->Get(origTreeLoc.c_str()); //Event *event = new Event(); //origTree->SetBranchAddress("event",&event); vector<float>* L1Muon_Etas; origTree->SetBranchAddress("L1Muon_Etas", &L1Muon_Etas); origTree->SetBranchStatus("*",0); //Disables All Branches //Then enables only select branches origTree->SetBranchStatus("Generator_Weights",1); origTree->SetBranchStatus("L1Muon_Etas",1); origTree->SetBranchStatus("L1Muon_Phis",1); origTree->SetBranchStatus("L1Muon_Pts",1); origTree->SetBranchStatus("HOReco_Etas",1); origTree->SetBranchStatus("HOReco_Phis",1); origTree->SetBranchStatus("HOReco_Energies",1); origTree->SetBranchStatus("hltMu5PropToRPC1_Etas",1); origTree->SetBranchStatus("hltMu5PropToRPC1_Phis",1); origTree->SetBranchStatus("hltMu5PropToRPC1_Pts",1); //origTree->SetBranchStatus("fH",1); //Create a new file + a clone of old tree in new file TFile *skimFile = new TFile("/data/users/cranelli/HOL1Muon/Trees/" "Version_5_1/Skim_HOMuonTreee_Test.root", "RECREATE"); TTree *skimTree = origTree->CloneTree(0); Long64_t nentries = origTree->GetEntries(); for (Long64_t i=0;i<nentries; i++) { if(i%1000==0) std::cout << i << std::endl; origTree->GetEntry(i); // Select Only Events with a L1Muon inside the barrel. bool keepEvent = false; for(unsigned int l1MuonB_index = 0; l1MuonB_index < L1Muon_Etas->size(); l1MuonB_index++){ if(fabs(L1Muon_Etas->at(l1MuonB_index)) < loose_barrel_eta) keepEvent = true; } if (keepEvent) skimTree->Fill(); L1Muon_Etas->clear(); } skimTree->Print(); skimFile->Write(); //delete oldfile; //delete newfile; }
void ExtractEventNums(std::string inFileName, std::string outFileName) { std::cout << "Copying from tree: " << inFileName << std::endl; std::cout << "Writing to: " << outFileName << std::endl; TFile inFile(inFileName.c_str(), "READ"); TTree* inTree = static_cast<TTree*>(inFile.Get("bdttree")); inTree->SetBranchStatus("*", 0); inTree->SetBranchStatus("Run", 1); inTree->SetBranchStatus("Event", 1); inTree->SetBranchStatus("LumiSec", 1); TFile outFile(outFileName.c_str(), "RECREATE"); TTree* outTree = static_cast<TTree*>(inTree->CloneTree()); outTree->Print(); outTree->Write(); //outFile.Write(); return; }
int reader_wrapper::initFormulas(TString targetbranch) { /// don't care about spectators here // TODO: does this tree get created in the outfile? m_intree->SetBranchStatus("*",1); m_outtree = m_intree->CloneTree(-1,"fast"); int buffer(0); for (auto& var : m_variables) { var.ttreeformula = new TTreeFormula(Form("local_var_%d",buffer++),var.formula,m_outtree); for (size_t v = 0 ; v < var.ttreeformula->GetNcodes() ; ++v) { m_branches.insert(var.ttreeformula->GetLeaf(v)->GetBranch()); } } m_outtree->SetBranchStatus("*",0); for (auto b : m_branches) { b->SetStatus(1); } // check if output branch exists already if (nullptr == m_outtree->GetBranch(targetbranch.Data())) { m_responseBranch = m_outtree->Branch(targetbranch.Data(),&m_response,(targetbranch + "/F").Data()); return 0; } std::cout << "Output branch exists already. Aborting." << std::endl; return 4; }
void getTreeVariables(){ tree->SetBranchStatus("*",0); tree->SetBranchStatus("trackEta",1); tree->SetBranchAddress("trackEta",&trackEta); tree->SetBranchStatus("trackPt",1); tree->SetBranchAddress("trackPt",&trackPt); tree->SetBranchStatus("trackCaloIsolation",1); tree->SetBranchAddress("trackCaloIsolation",&trackCaloIso); tree->SetBranchStatus("trackNValid",1); tree->SetBranchAddress("trackNValid",&trackNValid); tree->SetBranchStatus("trackPdgId",1); tree->SetBranchAddress("trackPdgId",&trackPdgId); tree->SetBranchStatus("weight*",1); tree->SetBranchAddress("weight",&weight); tree->SetBranchAddress("weight_xsec_lumi",&weight_xsec_lumi); };
void PECLeptonReader::BeginRun(Dataset const &) { // Save pointer to the plugin providing access to input data inputDataPlugin = dynamic_cast<PECInputData const *>(GetDependencyPlugin(inputDataPluginName)); // Set up the trees. Branches with properties that are currently not utilized, are disabled inputDataPlugin->LoadTree(electronTreeName); inputDataPlugin->LoadTree(muonTreeName); ROOTLock::Lock(); TTree *t = inputDataPlugin->ExposeTree(electronTreeName); t->SetBranchStatus("electrons.mvaId*", false); t->SetBranchAddress("electrons", &bfElectronPointer); t = inputDataPlugin->ExposeTree(muonTreeName); t->SetBranchAddress("muons", &bfMuonPointer); ROOTLock::Unlock(); }
//______________________________________________________________________________ Bool_t alice_esd_loadlib(const char* project) { // Make sure that shared library created from the auto-generated project // files exists and load it. TString lib(Form("%s/%s.%s", project, project, gSystem->GetSoExt())); if (gSystem->AccessPathName(lib, kReadPermission)) { TFile* f = TFile::Open(esd_file_name, "CACHEREAD"); if (f == 0) return kFALSE; TFile *f2 = TFile::Open(esd_friends_file_name, "CACHEREAD"); TTree *tree = (TTree*) f->Get("esdTree"); tree->SetBranchStatus ("ESDfriend*", 1); f->MakeProject(project, "*", "++"); f->Close(); delete f; } return gSystem->Load(lib) >= 0; }
void cloneAODTreeAndRemoveObject(const char *newFileName = "AliAOD_new.root", const char *orgFileName = "AliAOD.root") { // This little macro takes an already created AOD file and clones it. // After removing an old brach, the new TTree is written to a new file. // open input file and get the TTree TFile orgFile(orgFileName, "READ"); // get original TTree TTree *orgAodTree = (TTree*)orgFile.Get("aodTree"); // switch off one branch (and its subbranches!) orgAodTree->SetBranchStatus("tracks*", 0); // open new output file TFile *newFile = new TFile(newFileName, "RECREATE"); // clone old TTree (only clones branches that are switched on) TTree *newAodTree = orgAodTree->CloneTree(); // get the event within the new TTree AliAODEvent *evNew = new AliAODEvent(); evNew->ReadFromTree(newAodTree); // remove TObject from the list evNew->RemoveObject(evNew->GetTracks()); // delete old and write new UserInfo newAodTree->GetUserInfo()->Clear(); newAodTree->GetUserInfo()->Add(evNew); // write new TTree to file newAodTree->Write(); // close files newFile->Close(); delete newFile; orgFile.Close(); }
//////////////////////////////////////////////////////////////////////////////// /// Main /// //////////////////////////////////////////////////////////////////////////////// void GrowTree(TString process, std::string regMethod="BDTG", Long64_t beginEntry=0, Long64_t endEntry=-1) { gROOT->SetBatch(1); TH1::SetDefaultSumw2(1); gROOT->LoadMacro("HelperFunctions.h"); //< make functions visible to TTreeFormula if (!TString(gROOT->GetVersion()).Contains("5.34")) { std::cout << "INCORRECT ROOT VERSION! Please use 5.34:" << std::endl; std::cout << "source /uscmst1/prod/sw/cms/slc5_amd64_gcc462/lcg/root/5.34.02-cms/bin/thisroot.csh" << std::endl; std::cout << "Return without doing anything." << std::endl; return; } const TString indir = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Phys14_PU20bx25/skimV11/"; const TString outdir = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Phys14_PU20bx25/skimV11/step3/"; const TString prefix = "skim_"; const TString suffix = ".root"; TFile *input = TFile::Open(indir + prefix + process + suffix); if (!input) { std::cout << "ERROR: Could not open input file." << std::endl; exit(1); } /// Make output directory if it doesn't exist if (gSystem->AccessPathName(outdir)) gSystem->mkdir(outdir); std::cout << "--- GrowTree : Using input file: " << input->GetName() << std::endl; TTree *inTree = (TTree *) input->Get("tree"); TH1F *hcount = (TH1F *) input->Get("Count"); TFile *output(0); if (beginEntry == 0 && endEntry == -1) output = TFile::Open(outdir + "Step3_" + process + suffix, "RECREATE"); else output = TFile::Open(outdir + "Step3_" + process + TString::Format("_%Li_%Li", beginEntry, endEntry) + suffix, "RECREATE"); TTree *outTree = inTree->CloneTree(0); // Do no copy the data yet /// The clone should not delete any shared i/o buffers. ResetDeleteBranches(outTree); ///-- Set branch addresses ------------------------------------------------- EventInfo EVENT; double hJet_pt[MAXJ], hJet_eta[MAXJ], hJet_phi[MAXJ], hJet_m[MAXJ], hJet_ptRaw[MAXJ], hJet_genPt[MAXJ]; int hJCidx[2]; inTree->SetBranchStatus("*", 1); inTree->SetBranchStatus("hJCidx",1); inTree->SetBranchStatus("Jet_*",1); inTree->SetBranchAddress("hJCidx", &hJCidx); inTree->SetBranchAddress("Jet_pt", &hJet_pt); inTree->SetBranchAddress("Jet_eta", &hJet_eta); inTree->SetBranchAddress("Jet_phi", &hJet_phi); inTree->SetBranchAddress("Jet_mass", &hJet_m); inTree->SetBranchAddress("Jet_rawPt", &hJet_ptRaw); inTree->SetBranchAddress("Jet_mcPt", &hJet_genPt); ///-- Make new branches ---------------------------------------------------- int EVENT_run, EVENT_event; // set these as TTree index? float lumi_ = lumi, efflumi, efflumi_old, efflumi_UEPS_up, efflumi_UEPS_down; float hJet_ptReg[2]; float HptNorm, HptGen, HptReg; float HmassNorm, HmassGen, HmassReg; outTree->Branch("EVENT_run", &EVENT_run, "EVENT_run/I"); outTree->Branch("EVENT_event", &EVENT_event, "EVENT_event/I"); outTree->Branch("lumi", &lumi_, "lumi/F"); outTree->Branch("efflumi", &efflumi, "efflumi/F"); outTree->Branch("efflumi_old", &efflumi_old, "efflumi_old/F"); outTree->Branch("efflumi_UEPS_up", &efflumi_UEPS_up, "efflumi_UEPS_up/F"); outTree->Branch("efflumi_UEPS_down", &efflumi_UEPS_down, "efflumi_UEPS_down/F"); outTree->Branch("hJet_ptReg", &hJet_ptReg, "hJet_ptReg[2]/F"); outTree->Branch("HptNorm", &HptNorm, "HptNorm/F"); outTree->Branch("HptGen", &HptGen, "HptGen/F"); outTree->Branch("HptReg", &HptReg, "HptReg/F"); outTree->Branch("HmassNorm", &HmassNorm, "HmassNorm/F"); outTree->Branch("HmassGen", &HmassGen, "HmassGen/F"); outTree->Branch("HmassReg", &HmassReg, "HmassReg/F"); /// Get effective lumis std::map < std::string, float > efflumis = GetLumis(); efflumi = efflumis[process.Data()]; assert(efflumi > 0); efflumi_old = efflumi; efflumi_UEPS_up = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(3); efflumi_UEPS_down = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(4); TTreeFormula* ttf_lheweight = new TTreeFormula("ttf_lheweight", Form("%f", efflumi), inTree); #ifdef STITCH std::map < std::string, std::string > lheweights = GetLHEWeights(); TString process_lhe = process; if (process_lhe.BeginsWith("WJets") && process_lhe != "WJetsHW") process_lhe = "WJets"; else if (process_lhe.BeginsWith("ZJets") && process_lhe != "ZJetsHW") process_lhe = "ZJets"; else process_lhe = ""; TString lheweight = lheweights[process_lhe.Data()]; if (lheweight != "") { delete ttf_lheweight; // Bug fix for ZJetsPtZ100 if (process == "ZJetsPtZ100") lheweight.ReplaceAll("lheV_pt", "999"); std::cout << "BUGFIX: " << lheweight << std::endl; ttf_lheweight = new TTreeFormula("ttf_lheweight", lheweight, inTree); } #endif ttf_lheweight->SetQuickLoad(1); // regression stuff here ///-- Setup TMVA Reader ---------------------------------------------------- TMVA::Tools::Instance(); //< This loads the library TMVA::Reader * reader = new TMVA::Reader("!Color:!Silent"); /// Get the variables const std::vector < std::string > & inputExpressionsReg = GetInputExpressionsReg(); const UInt_t nvars = inputExpressionsReg.size(); Float_t readerVars[nvars]; int idx_rawpt = -1, idx_pt = -1, idx_et = -1, idx_mt = -1; for (UInt_t iexpr = 0; iexpr < nvars; iexpr++) { const TString& expr = inputExpressionsReg.at(iexpr); reader->AddVariable(expr, &readerVars[iexpr]); if (expr.BeginsWith("breg_rawptJER := ")) idx_rawpt = iexpr; else if (expr.BeginsWith("breg_pt := ")) idx_pt = iexpr; else if (expr.BeginsWith("breg_et := ")) idx_et = iexpr; else if (expr.BeginsWith("breg_mt := ")) idx_mt = iexpr; } // assert(idx_rawpt!=-1 && idx_pt!=-1 && idx_et!=-1 && idx_mt!=-1); assert(idx_rawpt!=-1 && idx_pt!=-1 ); /// Setup TMVA regression inputs const std::vector < std::string > & inputExpressionsReg0 = GetInputExpressionsReg0(); const std::vector < std::string > & inputExpressionsReg1 = GetInputExpressionsReg1(); assert(inputExpressionsReg0.size() == nvars); assert(inputExpressionsReg1.size() == nvars); /// Load TMVA weights TString weightdir = "weights/"; TString weightfile = weightdir + "TMVARegression_" + regMethod + ".testweights.xml"; reader->BookMVA(regMethod + " method", weightfile); TStopwatch sw; sw.Start(); /// Create TTreeFormulas TTreeFormula *ttf = 0; std::vector < TTreeFormula * >::const_iterator formIt, formItEnd; std::vector < TTreeFormula * > inputFormulasReg0; std::vector < TTreeFormula * > inputFormulasReg1; std::vector < TTreeFormula * > inputFormulasFJReg0; std::vector < TTreeFormula * > inputFormulasFJReg1; std::vector < TTreeFormula * > inputFormulasFJReg2; for (UInt_t iexpr = 0; iexpr < nvars; iexpr++) { ttf = new TTreeFormula(Form("ttfreg%i_0", iexpr), inputExpressionsReg0.at(iexpr).c_str(), inTree); ttf->SetQuickLoad(1); inputFormulasReg0.push_back(ttf); ttf = new TTreeFormula(Form("ttfreg%i_1", iexpr), inputExpressionsReg1.at(iexpr).c_str(), inTree); ttf->SetQuickLoad(1); inputFormulasReg1.push_back(ttf); } ///-- Loop over events ----------------------------------------------------- Int_t curTree = inTree->GetTreeNumber(); const Long64_t nentries = inTree->GetEntries(); if (endEntry < 0) endEntry = nentries; Long64_t ievt = 0; for (ievt=TMath::Max(ievt, beginEntry); ievt<TMath::Min(nentries, endEntry); ievt++) { if (ievt % 2000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl; const Long64_t local_entry = inTree->LoadTree(ievt); // faster, but only for TTreeFormula if (local_entry < 0) break; inTree->GetEntry(ievt); // same event as received by LoadTree() if (inTree->GetTreeNumber() != curTree) { curTree = inTree->GetTreeNumber(); for (formIt=inputFormulasReg0.begin(), formItEnd=inputFormulasReg0.end(); formIt!=formItEnd; formIt++) (*formIt)->UpdateFormulaLeaves(); // if using TChain for (formIt=inputFormulasReg1.begin(), formItEnd=inputFormulasReg1.end(); formIt!=formItEnd; formIt++) (*formIt)->UpdateFormulaLeaves(); // if using TChain for (formIt=inputFormulasFJReg0.begin(), formItEnd=inputFormulasFJReg0.end(); formIt!=formItEnd; formIt++) (*formIt)->UpdateFormulaLeaves(); // if using TChain for (formIt=inputFormulasFJReg1.begin(), formItEnd=inputFormulasFJReg1.end(); formIt!=formItEnd; formIt++) (*formIt)->UpdateFormulaLeaves(); // if using TChain for (formIt=inputFormulasFJReg2.begin(), formItEnd=inputFormulasFJReg2.end(); formIt!=formItEnd; formIt++) (*formIt)->UpdateFormulaLeaves(); // if using TChain ttf_lheweight->UpdateFormulaLeaves(); } /// These need to be called when arrays of variable size are used in TTree. for (formIt=inputFormulasReg0.begin(), formItEnd=inputFormulasReg0.end(); formIt!=formItEnd; formIt++) (*formIt)->GetNdata(); for (formIt=inputFormulasReg1.begin(), formItEnd=inputFormulasReg1.end(); formIt!=formItEnd; formIt++) (*formIt)->GetNdata(); for (formIt=inputFormulasFJReg0.begin(), formItEnd=inputFormulasFJReg0.end(); formIt!=formItEnd; formIt++) (*formIt)->GetNdata(); for (formIt=inputFormulasFJReg1.begin(), formItEnd=inputFormulasFJReg1.end(); formIt!=formItEnd; formIt++) (*formIt)->GetNdata(); for (formIt=inputFormulasFJReg2.begin(), formItEnd=inputFormulasFJReg2.end(); formIt!=formItEnd; formIt++) (*formIt)->GetNdata(); ttf_lheweight->GetNdata(); /// Fill branches EVENT_run = EVENT.run; EVENT_event = EVENT.event; #ifdef STITCH efflumi = ttf_lheweight->EvalInstance(); // efflumi_UEPS_up = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(3); //efflumi_UEPS_down = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(4); #endif bool verbose = false; for (Int_t ihj = 0; ihj < 2; ihj++) { /// Evaluate TMVA regression output for (UInt_t iexpr = 0; iexpr < nvars; iexpr++) { if (ihj==0) { readerVars[iexpr] = inputFormulasReg0.at(iexpr)->EvalInstance(); } else if (ihj==1) { readerVars[iexpr] = inputFormulasReg1.at(iexpr)->EvalInstance(); } } hJet_ptReg[ihj] = (reader->EvaluateRegression(regMethod + " method"))[0]; if (verbose) std::cout << readerVars[idx_pt] << " " << readerVars[idx_rawpt] << " " << hJet_pt[ihj] << " " << hJet_ptReg[ihj] << " " << hJet_genPt[ihj] << std::endl; const TLorentzVector p4Zero = TLorentzVector(0., 0., 0., 0.); // int idx = hJCidx[0] ; // std::cout << "the regressed pt for jet 0 is " << hJet_ptReg[0] << "; the hJCidx is " << hJCidx[0] << ", hence the origianl pt is " << hJet_pt[idx] << std::endl; const TLorentzVector& hJet_p4Norm_0 = makePtEtaPhiM(hJet_pt[hJCidx[0]] , hJet_pt[hJCidx[0]], hJet_eta[hJCidx[0]], hJet_phi[hJCidx[0]], hJet_m[hJCidx[0]]); const TLorentzVector& hJet_p4Norm_1 = makePtEtaPhiM(hJet_pt[hJCidx[1]] , hJet_pt[hJCidx[1]], hJet_eta[hJCidx[1]], hJet_phi[hJCidx[1]], hJet_m[hJCidx[1]]); const TLorentzVector& hJet_p4Gen_0 = hJet_genPt[hJCidx[0]] > 0 ? makePtEtaPhiM(hJet_genPt[hJCidx[0]] , hJet_pt[hJCidx[0]], hJet_eta[hJCidx[0]], hJet_phi[hJCidx[0]], hJet_m[hJCidx[0]]) : p4Zero; const TLorentzVector& hJet_p4Gen_1 = hJet_genPt[hJCidx[1]] > 0 ? makePtEtaPhiM(hJet_genPt[hJCidx[1]] , hJet_pt[hJCidx[1]], hJet_eta[hJCidx[1]], hJet_phi[hJCidx[1]], hJet_m[hJCidx[1]]) : p4Zero; const TLorentzVector& hJet_p4Reg_0 = makePtEtaPhiM(hJet_ptReg[0] , hJet_pt[hJCidx[0]], hJet_eta[hJCidx[0]], hJet_phi[hJCidx[0]], hJet_m[hJCidx[0]]); const TLorentzVector& hJet_p4Reg_1 = makePtEtaPhiM(hJet_ptReg[1] , hJet_pt[hJCidx[1]], hJet_eta[hJCidx[1]], hJet_phi[hJCidx[1]], hJet_m[hJCidx[1]]); HptNorm = (hJet_p4Norm_0 + hJet_p4Norm_1 ).Pt(); HptGen = (hJet_p4Gen_0 + hJet_p4Gen_1 ).Pt(); HptReg = (hJet_p4Reg_0 + hJet_p4Reg_1 ).Pt(); HmassNorm = (hJet_p4Norm_0 + hJet_p4Norm_1 ).M(); HmassGen = (hJet_p4Gen_0 + hJet_p4Gen_1 ).M(); HmassReg = (hJet_p4Reg_0 + hJet_p4Reg_1 ).M(); // std::cout << "HmassReg is " << HmassReg << std::endl; } outTree->Fill(); // fill it! } // end loop over TTree entries /// Get elapsed time sw.Stop(); std::cout << "--- End of event loop: "; sw.Print(); output->cd(); outTree->Write(); output->Close(); input->Close(); delete input; delete output; for (formIt=inputFormulasReg0.begin(), formItEnd=inputFormulasReg0.end(); formIt!=formItEnd; formIt++) delete *formIt; for (formIt=inputFormulasReg1.begin(), formItEnd=inputFormulasReg1.end(); formIt!=formItEnd; formIt++) delete *formIt; for (formIt=inputFormulasFJReg0.begin(), formItEnd=inputFormulasFJReg0.end(); formIt!=formItEnd; formIt++) delete *formIt; for (formIt=inputFormulasFJReg1.begin(), formItEnd=inputFormulasFJReg1.end(); formIt!=formItEnd; formIt++) delete *formIt; for (formIt=inputFormulasFJReg2.begin(), formItEnd=inputFormulasFJReg2.end(); formIt!=formItEnd; formIt++) delete *formIt; delete ttf_lheweight; std::cout << "==> GrowTree is done!" << std::endl << std::endl; return; }
void PlotOpt(){ // fixed background uncertainty (%) g_deltaNbkg = 20.; // integrated luminosity (fb^-1) g_lumi = 10.; // minimum number of expected background events g_minBKG = 0.01; TFile* input = new TFile("test.root","READ"); int ParentMass = 250; int LSPMass = 77; double Sscale = 1.; double Bscale = 1.; string SignalModel = "TT"; string plot_title = "#tilde{t} #tilde{t} #rightarrow (t #tilde{#chi})(t #tilde{#chi}); m_{#tilde{t}} = "; plot_title += to_string(ParentMass)+", m_{#tilde{#chi}} = "+to_string(LSPMass)+" GeV"; TTree* tree = (TTree*) input->Get("optimization"); double Nsig, Nbkg; vector<double> VAR; TBranch *b_Nsig,*b_Nbkg; vector<TBranch*> b_VAR; //int Ncut = tree->GetNbranches()-2; int Ncut = 0; TObjArray* branches = tree->GetListOfBranches(); int Nbranch = branches->GetEntries(); for(int i = 0; i < Nbranch; i++) if(string(branches->At(i)->GetName()).find("var") != string::npos) Ncut++; tree->SetBranchStatus("*",0); string sname = "Nsig_"+SignalModel+"_"+to_string(ParentMass)+"_"+to_string(LSPMass); tree->SetBranchStatus(sname.c_str(),"1"); tree->SetBranchAddress(sname.c_str(),&Nsig,&b_Nsig); tree->SetBranchStatus("Nbkg","1"); tree->SetBranchAddress("Nbkg",&Nbkg,&b_Nbkg); for(int i = 0; i < Ncut; i++){ VAR.push_back(0.); b_VAR.push_back(new TBranch()); } for(int i = 0; i < Ncut; i++){ tree->SetBranchStatus(("var"+to_string(i)).c_str(),"1"); tree->SetBranchAddress(("var"+to_string(i)).c_str(),&(VAR[i]),&b_VAR[i]); } int Ncomb = tree->GetEntries(); vector<vector<double> > VAR_cut; for(int i = 0; i < Ncut; i++) VAR_cut.push_back(vector<double>()); // find max metric combination int c_max = -1; double metric_max = -1.; for(int c = 0; c < Ncomb; c++){ tree->GetEntry(c); double metric = 0; if(Nsig > 0. && Nbkg > 0. && g_lumi*Nbkg*Bscale > g_minBKG) metric = EvaluateMetric(g_lumi*Nsig*Sscale,g_lumi*Nbkg*Bscale); if(metric > metric_max && g_lumi*Nbkg*Bscale > g_minBKG){ metric_max = metric; c_max = c; } for(int i = 0; i < Ncut; i++){ int N = VAR_cut[i].size(); bool found = false; for(int j = 0; j < N; j++){ if(VAR_cut[i][j] == VAR[i]){ found = true; break; } } if(!found) VAR_cut[i].push_back(VAR[i]); } } vector<double> VAR_max; tree->GetEntry(c_max); cout << "Point: " << ParentMass << " " << LSPMass << endl;; cout << "Max significance of " << EvaluateMetric(g_lumi*Nsig*Sscale,g_lumi*Nbkg*Bscale); cout << " sigma with:" << endl; cout << " Nsig = " << g_lumi*Nsig*Sscale << endl; cout << " Nbkg = " << g_lumi*Nbkg*Bscale << endl; for(int i = 0; i < Ncut; i++){ VAR_max.push_back(VAR[i]); cout << "var " << i << " " << VAR[i] << endl; } vector<vector<double> > VAR_max_fix; vector<vector<double> > VAR_max_float; for(int i = 0; i < Ncut; i++){ VAR_max_fix.push_back(vector<double>()); VAR_max_float.push_back(vector<double>()); int N = VAR_cut[i].size(); for(int j = 0; j < N; j++){ VAR_max_fix[i].push_back(-1.); VAR_max_float[i].push_back(-1.); } } for(int c = 0; c < Ncomb; c++){ tree->GetEntry(c); double metric = 0; if(Nsig > 0. && Nbkg > 0. && g_lumi*Nbkg*Bscale > g_minBKG) metric = EvaluateMetric(g_lumi*Nsig*Sscale,g_lumi*Nbkg*Bscale); for(int i = 0; i < Ncut; i++){ int N = VAR_cut[i].size(); int jcut = -1; for(int j = 0; j < N; j++) if(VAR[i] == VAR_cut[i][j]) jcut = j; if(metric > VAR_max_float[i][jcut]) VAR_max_float[i][jcut] = metric; bool fix = true; for(int j = 0; j < Ncut; j++){ if(i == j) continue; if(fabs(VAR[j]-VAR_max[j]) > 1e-10){ fix = false; break; } } if(!fix) continue; if(metric > VAR_max_fix[i][jcut]){ VAR_max_fix[i][jcut] = metric; } } } TGraph* gr_fix[Ncut]; TGraph* gr_float[Ncut]; TMultiGraph* mg[Ncut]; TCanvas* can[Ncut]; TLegend* leg; for(int icut = 0; icut < Ncut; icut++){ int Nval = VAR_cut[icut].size(); double x[Nval]; double y[2][Nval]; for(int i = 0; i < Nval; i++){ x[i] = VAR_cut[icut][i]; y[0][i] = VAR_max_fix[icut][i]; y[1][i] = VAR_max_float[icut][i]; } gr_fix[icut] = (TGraph*) new TGraph(Nval,x,y[0]); gr_float[icut] = (TGraph*) new TGraph(Nval,x,y[1]); gr_fix[icut]->SetLineWidth(4); gr_fix[icut]->SetLineColor(kBlue+2); gr_fix[icut]->SetFillColor(kWhite); gr_fix[icut]->SetMarkerSize(0); gr_float[icut]->SetLineWidth(4); gr_float[icut]->SetLineStyle(7); gr_float[icut]->SetLineColor(kGreen+3); gr_float[icut]->SetFillColor(kWhite); gr_float[icut]->SetMarkerSize(0); mg[icut] = (TMultiGraph*) new TMultiGraph(); mg[icut]->Add(gr_fix[icut]); mg[icut]->Add(gr_float[icut]); string scan = "can_"+to_string(icut); can[icut] = (TCanvas*) new TCanvas(scan.c_str(),scan.c_str(),600.,500); can[icut]->SetLeftMargin(0.15); can[icut]->SetRightMargin(0.04); can[icut]->SetBottomMargin(0.15); can[icut]->SetGridx(); can[icut]->SetGridy(); can[icut]->Draw(); can[icut]->cd(); mg[icut]->Draw("AL"); mg[icut]->GetXaxis()->CenterTitle(); mg[icut]->GetXaxis()->SetTitleFont(132); mg[icut]->GetXaxis()->SetTitleSize(0.06); mg[icut]->GetXaxis()->SetTitleOffset(1.13); mg[icut]->GetXaxis()->SetLabelFont(132); mg[icut]->GetXaxis()->SetLabelSize(0.05); mg[icut]->GetXaxis()->SetTitle(("Var "+to_string(icut)).c_str()); mg[icut]->GetYaxis()->CenterTitle(); mg[icut]->GetYaxis()->SetTitleFont(132); mg[icut]->GetYaxis()->SetTitleSize(0.06); mg[icut]->GetYaxis()->SetTitleOffset(1.2); mg[icut]->GetYaxis()->SetLabelFont(132); mg[icut]->GetYaxis()->SetLabelSize(0.05); mg[icut]->GetYaxis()->SetTitle("Significance ( Z_{Bi} )"); if(icut == 0){ leg = (TLegend*) new TLegend(0.688,0.22,0.93,0.42); leg->SetTextFont(132); leg->SetTextSize(0.06); leg->AddEntry(gr_fix[icut],"#vec{c} |_{global max}"); leg->AddEntry(gr_float[icut],"#vec{c} |_{local max}"); leg->SetFillColor(kWhite); leg->SetLineColor(kWhite); leg->SetShadowColor(kWhite); } leg->Draw("SAME"); TLatex l; l.SetTextFont(132); l.SetNDC(); l.SetTextSize(0.04); l.SetTextFont(132); l.DrawLatex(0.17,0.855,plot_title.c_str()); l.SetTextSize(0.04); l.SetTextFont(42); l.DrawLatex(0.15,0.943,"#bf{#it{ATLAS}} Internal"); l.SetTextSize(0.045); l.SetTextFont(132); string bla = "#scale[0.6]{#int} #it{L dt} = "+to_string(int(g_lumi))+" fb^{-1}, #Delta_{N#scale[0.8]{bkg}} = "; bla += to_string(int(g_deltaNbkg))+" %"; l.DrawLatex(0.55,0.943,bla.c_str()); } }
void doPostProcessing(TString infname, TString outfile, Int_t events, Float_t xsec, Float_t kfactor, Float_t filt_eff, bool SortBasketsByEntry = false) { cout << "Processing File " << infname << endl; TFile *f = TFile::Open(infname.Data(), "READ"); if (! f || f->IsZombie()) { cout << "File does not exist!" << endl; return; } TTree* t = (TTree*)f->Get("Events"); if (! t || t->IsZombie()) { cout << "Tree does not exist!" << endl; return; } //------------------------------------------------------------- // Removes all non *_CMS2.* branches //-------------------------------------------------------------` t->SetBranchStatus("*", 0); t->SetBranchStatus("*_CMS2.*", 1); // Removes the branches (if they exist) that we want to replace //evt_xsec_excl TString bName = t->GetAlias("evt_xsec_excl"); //cout << "evt_xsec_excl " << bName << endl; if(bName != "") { bName.ReplaceAll(".obj", "*"); t->SetBranchStatus(bName.Data(), 0); } //evt_xsec_incl bName = t->GetAlias("evt_xsec_incl"); //cout << "evt_xsec_incl " << bName << endl; if(bName != "") { bName.ReplaceAll(".obj", "*"); t->SetBranchStatus(bName.Data(), 0); } //evt_kfactor bName = t->GetAlias("evt_kfactor"); //cout << "evt_kfactor " << bName << endl; if(bName != "") { bName.ReplaceAll(".obj", "*"); t->SetBranchStatus(bName.Data(), 0); } //evt_nEvts bName = t->GetAlias("evt_nEvts"); //cout << "evt_nEvts " << bName << endl; if(bName != "") { bName.ReplaceAll(".obj", "*"); t->SetBranchStatus(bName.Data(), 0); } //evt_filt_eff bName = t->GetAlias("evt_filt_eff"); //cout << "evt_filt_eff " << bName << endl; if(bName != "") { bName.ReplaceAll(".obj", "*"); t->SetBranchStatus(bName.Data(), 0); } //evt_scale1fb bName = t->GetAlias("evt_scale1fb"); //cout << "evt_scale1fb " << bName << endl; if(bName != "") { bName.ReplaceAll(".obj", "*"); t->SetBranchStatus(bName.Data(), 0); } TFile *out = TFile::Open(outfile.Data(), "RECREATE"); TTree *clone; if(SortBasketsByEntry) clone = t->CloneTree(-1, "fastSortBasketsByEntry"); else clone = t->CloneTree(-1, "fast"); //------------------------------------------------------------- //Calculate scaling factor and put variables into tree Float_t scale1fb = xsec*kfactor*1000*filt_eff/(Float_t)events; cout << "scale1fb: " << scale1fb << endl; TBranch* b1 = clone->Branch("evtscale1fb", &scale1fb, "evt_scale1fb/F"); TBranch* b2 = clone->Branch("evtxsecexcl", &xsec, "evt_xsec_excl/F"); TBranch* b3 = clone->Branch("evtxsecincl", &xsec, "evt_xsec_incl/F"); TBranch* b4 = clone->Branch("evtkfactor", &kfactor, "evt_kfactor/F"); TBranch* b5 = clone->Branch("evtnEvts", &events, "evt_nEvts/I"); TBranch* b6 = clone->Branch("evtfilteff", &filt_eff, "evt_filt_eff/F"); clone->SetAlias("evt_scale1fb", "evtscale1fb"); clone->SetAlias("evt_xsec_excl", "evtxsecexcl"); clone->SetAlias("evt_xsec_incl", "evtxsecincl"); clone->SetAlias("evt_kfactor", "evtkfactor"); clone->SetAlias("evt_nEvts", "evtnEvts"); clone->SetAlias("evt_filt_eff", "evtfilteff"); Int_t nentries = t->GetEntries(); for(Int_t i = 0; i < nentries; i++) { b1->Fill(); b2->Fill(); b3->Fill(); b4->Fill(); b5->Fill(); b6->Fill(); } //------------------------------------------------------------- clone->Write(); out->Close(); f->Close(); return; }
void Acceptance( void ) { gROOT->Reset(); TFile *file = new TFile("root/grun_e07.root"); TTree *tree = (TTree*)file->Get("tree"); const Int_t MaxHits = 256; Int_t evnum; Int_t beam_sw; Double_t pg[4]; Double_t xg[3]; Double_t product_pg[4]; Double_t product_xg[3]; Int_t npid; Double_t x0[2][3]; Double_t p0[2][5]; Double_t pt0[2]; Double_t mass0[2]; Double_t theta0[2]; Double_t pfermi[4]; Double_t crosssection; Int_t ntSsd; Int_t tidSsd[MaxHits]; Int_t pidSsd[MaxHits]; Int_t didSsd[MaxHits]; Double_t massSsd[MaxHits]; Int_t chargeSsd[MaxHits]; Double_t edepSsd[MaxHits]; Double_t xSsd[MaxHits]; Double_t ySsd[MaxHits]; Double_t zSsd[MaxHits]; Double_t pxSsd[MaxHits]; Double_t pySsd[MaxHits]; Double_t pzSsd[MaxHits]; Double_t ppSsd[MaxHits]; Double_t tofSsd[MaxHits]; Int_t SsdpID[MaxHits]; Double_t vtxpxSsd[MaxHits]; Double_t vtxpySsd[MaxHits]; Double_t vtxpzSsd[MaxHits]; Double_t vtxppSsd[MaxHits]; Double_t vtxxSsd[MaxHits]; Double_t vtxySsd[MaxHits]; Double_t vtxzSsd[MaxHits]; Double_t lengthSsd[MaxHits]; Int_t ntAc; Int_t tidAc[MaxHits]; Int_t pidAc[MaxHits]; Int_t didAc[MaxHits]; Double_t massAc[MaxHits]; Int_t chargeAc[MaxHits]; Double_t xAc[MaxHits]; Double_t yAc[MaxHits]; Double_t zAc[MaxHits]; Double_t pxAc[MaxHits]; Double_t pyAc[MaxHits]; Double_t pzAc[MaxHits]; Double_t ppAc[MaxHits]; Double_t tofAc[MaxHits]; Int_t AcpID[MaxHits]; Double_t vtxpxAc[MaxHits]; Double_t vtxpyAc[MaxHits]; Double_t vtxpzAc[MaxHits]; Double_t vtxppAc[MaxHits]; Double_t vtxxAc[MaxHits]; Double_t vtxyAc[MaxHits]; Double_t vtxzAc[MaxHits]; Double_t lengthAc[MaxHits]; Int_t ntBac; Int_t tidBac[MaxHits]; Int_t pidBac[MaxHits]; Int_t didBac[MaxHits]; Double_t massBac[MaxHits]; Int_t chargeBac[MaxHits]; Double_t edepBac[MaxHits]; Double_t xBac[MaxHits]; Double_t yBac[MaxHits]; Double_t zBac[MaxHits]; Double_t pxBac[MaxHits]; Double_t pyBac[MaxHits]; Double_t pzBac[MaxHits]; Double_t ppBac[MaxHits]; Double_t tofBac[MaxHits]; Int_t BacpID[MaxHits]; Double_t vtxpxBac[MaxHits]; Double_t vtxpyBac[MaxHits]; Double_t vtxpzBac[MaxHits]; Double_t vtxppBac[MaxHits]; Double_t vtxxBac[MaxHits]; Double_t vtxyBac[MaxHits]; Double_t vtxzBac[MaxHits]; Double_t lengthBac[MaxHits]; Int_t ntBh2; Int_t tidBh2[MaxHits]; Int_t pidBh2[MaxHits]; Int_t didBh2[MaxHits]; Double_t massBh2[MaxHits]; Int_t chargeBh2[MaxHits]; Double_t edepBh2[MaxHits]; Double_t xBh2[MaxHits]; Double_t yBh2[MaxHits]; Double_t zBh2[MaxHits]; Double_t pxBh2[MaxHits]; Double_t pyBh2[MaxHits]; Double_t pzBh2[MaxHits]; Double_t ppBh2[MaxHits]; Double_t tofBh2[MaxHits]; Int_t Bh2pID[MaxHits]; Double_t vtxpxBh2[MaxHits]; Double_t vtxpyBh2[MaxHits]; Double_t vtxpzBh2[MaxHits]; Double_t vtxppBh2[MaxHits]; Double_t vtxxBh2[MaxHits]; Double_t vtxyBh2[MaxHits]; Double_t vtxzBh2[MaxHits]; Double_t lengthBh2[MaxHits]; Int_t ntSch; Int_t tidSch[MaxHits]; Int_t pidSch[MaxHits]; Int_t didSch[MaxHits]; Double_t massSch[MaxHits]; Int_t chargeSch[MaxHits]; Double_t edepSch[MaxHits]; Double_t xSch[MaxHits]; Double_t ySch[MaxHits]; Double_t zSch[MaxHits]; Double_t pxSch[MaxHits]; Double_t pySch[MaxHits]; Double_t pzSch[MaxHits]; Double_t ppSch[MaxHits]; Double_t tofSch[MaxHits]; Int_t SchpID[MaxHits]; Double_t vtxpxSch[MaxHits]; Double_t vtxpySch[MaxHits]; Double_t vtxpzSch[MaxHits]; Double_t vtxppSch[MaxHits]; Double_t vtxxSch[MaxHits]; Double_t vtxySch[MaxHits]; Double_t vtxzSch[MaxHits]; Double_t lengthSch[MaxHits]; Int_t ntTof; Int_t tidTof[MaxHits]; Int_t pidTof[MaxHits]; Int_t didTof[MaxHits]; Double_t massTof[MaxHits]; Int_t chargeTof[MaxHits]; Double_t edepTof[MaxHits]; Double_t xTof[MaxHits]; Double_t yTof[MaxHits]; Double_t zTof[MaxHits]; Double_t pxTof[MaxHits]; Double_t pyTof[MaxHits]; Double_t pzTof[MaxHits]; Double_t ppTof[MaxHits]; Double_t tofTof[MaxHits]; Int_t TofpID[MaxHits]; Double_t vtxpxTof[MaxHits]; Double_t vtxpyTof[MaxHits]; Double_t vtxpzTof[MaxHits]; Double_t vtxppTof[MaxHits]; Double_t vtxxTof[MaxHits]; Double_t vtxyTof[MaxHits]; Double_t vtxzTof[MaxHits]; Double_t lengthTof[MaxHits]; Int_t ntSdc; Int_t tidSdc[MaxHits]; Int_t pidSdc[MaxHits]; Int_t didSdc[MaxHits]; Double_t massSdc[MaxHits]; Int_t chargeSdc[MaxHits]; Double_t xSdc[MaxHits]; Double_t ySdc[MaxHits]; Double_t zSdc[MaxHits]; Double_t pxSdc[MaxHits]; Double_t pySdc[MaxHits]; Double_t pzSdc[MaxHits]; Double_t ppSdc[MaxHits]; Double_t tofSdc[MaxHits]; Int_t SdcpID[MaxHits]; Double_t vtxpxSdc[MaxHits]; Double_t vtxpySdc[MaxHits]; Double_t vtxpzSdc[MaxHits]; Double_t vtxppSdc[MaxHits]; Double_t vtxxSdc[MaxHits]; Double_t vtxySdc[MaxHits]; Double_t vtxzSdc[MaxHits]; Double_t lengthSdc[MaxHits]; Int_t targethits; Int_t targetpid[MaxHits]; Int_t targetparentid[MaxHits]; Int_t targettid[MaxHits]; Double_t targetpos[MaxHits][3]; Double_t targetvtx[MaxHits][3]; Int_t ntXi; Double_t XipID[MaxHits]; Double_t massXi[MaxHits]; Double_t chargeXi[MaxHits]; Double_t xXi[MaxHits]; Double_t yXi[MaxHits]; Double_t zXi[MaxHits]; Double_t pxXi[MaxHits]; Double_t pyXi[MaxHits]; Double_t pzXi[MaxHits]; Double_t ppXi[MaxHits]; Double_t tlengthXi[MaxHits]; Double_t tidXi[MaxHits]; Double_t didXi[MaxHits]; Double_t pidXi[MaxHits]; Double_t vtxxXi[MaxHits]; Double_t vtxyXi[MaxHits]; Double_t vtxzXi[MaxHits]; Double_t vtxpxXi[MaxHits]; Double_t vtxpyXi[MaxHits]; Double_t vtxpzXi[MaxHits]; Double_t vtxppXi[MaxHits]; // Set branch addresses. tree->SetBranchAddress("evnum",&evnum); tree->SetBranchAddress("beam_sw",&beam_sw); tree->SetBranchAddress("pg",pg); tree->SetBranchAddress("xg",xg); tree->SetBranchAddress("product_pg",product_pg); tree->SetBranchAddress("product_xg",product_xg); tree->SetBranchAddress("npid",&npid); tree->SetBranchAddress("x0",x0); tree->SetBranchAddress("p0",p0); tree->SetBranchAddress("pt0",pt0); tree->SetBranchAddress("mass0",mass0); tree->SetBranchAddress("theta0",theta0); tree->SetBranchAddress("pfermi",pfermi); tree->SetBranchAddress("crosssection",&crosssection); tree->SetBranchAddress("ntSsd",&ntSsd); tree->SetBranchAddress("tidSsd",tidSsd); tree->SetBranchAddress("pidSsd",pidSsd); tree->SetBranchAddress("didSsd",didSsd); tree->SetBranchAddress("massSsd",massSsd); tree->SetBranchAddress("chargeSsd",chargeSsd); tree->SetBranchAddress("edepSsd",edepSsd); tree->SetBranchAddress("xSsd",xSsd); tree->SetBranchAddress("ySsd",ySsd); tree->SetBranchAddress("zSsd",zSsd); tree->SetBranchAddress("pxSsd",pxSsd); tree->SetBranchAddress("pySsd",pySsd); tree->SetBranchAddress("pzSsd",pzSsd); tree->SetBranchAddress("ppSsd",ppSsd); tree->SetBranchAddress("tofSsd",tofSsd); tree->SetBranchAddress("SsdpID",SsdpID); tree->SetBranchAddress("vtxpxSsd",vtxpxSsd); tree->SetBranchAddress("vtxpySsd",vtxpySsd); tree->SetBranchAddress("vtxpzSsd",vtxpzSsd); tree->SetBranchAddress("vtxppSsd",vtxppSsd); tree->SetBranchAddress("vtxxSsd",vtxxSsd); tree->SetBranchAddress("vtxySsd",vtxySsd); tree->SetBranchAddress("vtxzSsd",vtxzSsd); tree->SetBranchAddress("lengthSsd",lengthSsd); tree->SetBranchAddress("ntAc",&ntAc); tree->SetBranchAddress("tidAc",tidAc); tree->SetBranchAddress("pidAc",pidAc); tree->SetBranchAddress("didAc",didAc); tree->SetBranchAddress("massAc",massAc); tree->SetBranchAddress("chargeAc",chargeAc); tree->SetBranchAddress("xAc",xAc); tree->SetBranchAddress("yAc",yAc); tree->SetBranchAddress("zAc",zAc); tree->SetBranchAddress("pxAc",pxAc); tree->SetBranchAddress("pyAc",pyAc); tree->SetBranchAddress("pzAc",pzAc); tree->SetBranchAddress("ppAc",ppAc); tree->SetBranchAddress("tofAc",tofAc); tree->SetBranchAddress("AcpID",AcpID); tree->SetBranchAddress("vtxpxAc",vtxpxAc); tree->SetBranchAddress("vtxpyAc",vtxpyAc); tree->SetBranchAddress("vtxpzAc",vtxpzAc); tree->SetBranchAddress("vtxppAc",vtxppAc); tree->SetBranchAddress("vtxxAc",vtxxAc); tree->SetBranchAddress("vtxyAc",vtxyAc); tree->SetBranchAddress("vtxzAc",vtxzAc); tree->SetBranchAddress("lengthAc",lengthAc); tree->SetBranchAddress("ntBac",&ntBac); tree->SetBranchAddress("tidBac",&tidBac); tree->SetBranchAddress("pidBac",&pidBac); tree->SetBranchAddress("didBac",&didBac); tree->SetBranchAddress("massBac",&massBac); tree->SetBranchAddress("chargeBac",&chargeBac); tree->SetBranchAddress("edepBac",&edepBac); tree->SetBranchAddress("xBac",&xBac); tree->SetBranchAddress("yBac",&yBac); tree->SetBranchAddress("zBac",&zBac); tree->SetBranchAddress("pxBac",&pxBac); tree->SetBranchAddress("pyBac",&pyBac); tree->SetBranchAddress("pzBac",&pzBac); tree->SetBranchAddress("ppBac",&ppBac); tree->SetBranchAddress("tofBac",&tofBac); tree->SetBranchAddress("BacpID",&BacpID); tree->SetBranchAddress("vtxpxBac",&vtxpxBac); tree->SetBranchAddress("vtxpyBac",&vtxpyBac); tree->SetBranchAddress("vtxpzBac",&vtxpzBac); tree->SetBranchAddress("vtxppBac",&vtxppBac); tree->SetBranchAddress("vtxxBac",&vtxxBac); tree->SetBranchAddress("vtxyBac",&vtxyBac); tree->SetBranchAddress("vtxzBac",&vtxzBac); tree->SetBranchAddress("lengthBac",&lengthBac); tree->SetBranchAddress("ntBh2",&ntBh2); tree->SetBranchAddress("tidBh2",&tidBh2); tree->SetBranchAddress("pidBh2",&pidBh2); tree->SetBranchAddress("didBh2",&didBh2); tree->SetBranchAddress("massBh2",&massBh2); tree->SetBranchAddress("chargeBh2",&chargeBh2); tree->SetBranchAddress("edepBh2",&edepBh2); tree->SetBranchAddress("xBh2",&xBh2); tree->SetBranchAddress("yBh2",&yBh2); tree->SetBranchAddress("zBh2",&zBh2); tree->SetBranchAddress("pxBh2",&pxBh2); tree->SetBranchAddress("pyBh2",&pyBh2); tree->SetBranchAddress("pzBh2",&pzBh2); tree->SetBranchAddress("ppBh2",&ppBh2); tree->SetBranchAddress("tofBh2",&tofBh2); tree->SetBranchAddress("Bh2pID",&Bh2pID); tree->SetBranchAddress("vtxpxBh2",&vtxpxBh2); tree->SetBranchAddress("vtxpyBh2",&vtxpyBh2); tree->SetBranchAddress("vtxpzBh2",&vtxpzBh2); tree->SetBranchAddress("vtxppBh2",&vtxppBh2); tree->SetBranchAddress("vtxxBh2",&vtxxBh2); tree->SetBranchAddress("vtxyBh2",&vtxyBh2); tree->SetBranchAddress("vtxzBh2",&vtxzBh2); tree->SetBranchAddress("lengthBh2",&lengthBh2); tree->SetBranchAddress("ntSch",&ntSch); tree->SetBranchAddress("tidSch",tidSch); tree->SetBranchAddress("pidSch",pidSch); tree->SetBranchAddress("didSch",didSch); tree->SetBranchAddress("massSch",massSch); tree->SetBranchAddress("chargeSch",chargeSch); tree->SetBranchAddress("edepSch",edepSch); tree->SetBranchAddress("xSch",xSch); tree->SetBranchAddress("ySch",ySch); tree->SetBranchAddress("zSch",zSch); tree->SetBranchAddress("pxSch",pxSch); tree->SetBranchAddress("pySch",pySch); tree->SetBranchAddress("pzSch",pzSch); tree->SetBranchAddress("ppSch",ppSch); tree->SetBranchAddress("tofSch",tofSch); tree->SetBranchAddress("SchpID",SchpID); tree->SetBranchAddress("vtxpxSch",vtxpxSch); tree->SetBranchAddress("vtxpySch",vtxpySch); tree->SetBranchAddress("vtxpzSch",vtxpzSch); tree->SetBranchAddress("vtxppSch",vtxppSch); tree->SetBranchAddress("vtxxSch",vtxxSch); tree->SetBranchAddress("vtxySch",vtxySch); tree->SetBranchAddress("vtxzSch",vtxzSch); tree->SetBranchAddress("lengthSch",lengthSch); tree->SetBranchAddress("ntTof",&ntTof); tree->SetBranchAddress("tidTof",tidTof); tree->SetBranchAddress("pidTof",pidTof); tree->SetBranchAddress("didTof",didTof); tree->SetBranchAddress("massTof",massTof); tree->SetBranchAddress("chargeTof",chargeTof); tree->SetBranchAddress("edepTof",edepTof); tree->SetBranchAddress("xTof",xTof); tree->SetBranchAddress("yTof",yTof); tree->SetBranchAddress("zTof",zTof); tree->SetBranchAddress("pxTof",pxTof); tree->SetBranchAddress("pyTof",pyTof); tree->SetBranchAddress("pzTof",pzTof); tree->SetBranchAddress("ppTof",ppTof); tree->SetBranchAddress("tofTof",tofTof); tree->SetBranchAddress("TofpID",TofpID); tree->SetBranchAddress("vtxpxTof",vtxpxTof); tree->SetBranchAddress("vtxpyTof",vtxpyTof); tree->SetBranchAddress("vtxpzTof",vtxpzTof); tree->SetBranchAddress("vtxppTof",vtxppTof); tree->SetBranchAddress("vtxxTof",vtxxTof); tree->SetBranchAddress("vtxyTof",vtxyTof); tree->SetBranchAddress("vtxzTof",vtxzTof); tree->SetBranchAddress("lengthTof",lengthTof); tree->SetBranchAddress("ntSdc",&ntSdc); tree->SetBranchAddress("tidSdc",tidSdc); tree->SetBranchAddress("pidSdc",pidSdc); tree->SetBranchAddress("didSdc",didSdc); tree->SetBranchAddress("massSdc",massSdc); tree->SetBranchAddress("chargeSdc",chargeSdc); tree->SetBranchAddress("xSdc",xSdc); tree->SetBranchAddress("ySdc",ySdc); tree->SetBranchAddress("zSdc",zSdc); tree->SetBranchAddress("pxSdc",pxSdc); tree->SetBranchAddress("pySdc",pySdc); tree->SetBranchAddress("pzSdc",pzSdc); tree->SetBranchAddress("ppSdc",ppSdc); tree->SetBranchAddress("tofSdc",tofSdc); tree->SetBranchAddress("SdcpID",SdcpID); tree->SetBranchAddress("vtxpxSdc",vtxpxSdc); tree->SetBranchAddress("vtxpySdc",vtxpySdc); tree->SetBranchAddress("vtxpzSdc",vtxpzSdc); tree->SetBranchAddress("vtxppSdc",vtxppSdc); tree->SetBranchAddress("vtxxSdc",vtxxSdc); tree->SetBranchAddress("vtxySdc",vtxySdc); tree->SetBranchAddress("vtxzSdc",vtxzSdc); tree->SetBranchAddress("lengthSdc",lengthSdc); tree->SetBranchAddress("targethits",&targethits); tree->SetBranchAddress("targetpid",&targetpid); tree->SetBranchAddress("targetparentid",&targetparentid); tree->SetBranchAddress("targettid",&targettid); tree->SetBranchAddress("targetpos",&targetpos); tree->SetBranchAddress("targetvtx",&targetvtx); tree->SetBranchAddress("ntXi",&ntXi); tree->SetBranchAddress("XipID",&XipID); tree->SetBranchAddress("massXi",&massXi); tree->SetBranchAddress("chargeXi",&chargeXi); tree->SetBranchAddress("xXi",&xXi); tree->SetBranchAddress("yXi",&yXi); tree->SetBranchAddress("zXi",&zXi); tree->SetBranchAddress("pxXi",&pxXi); tree->SetBranchAddress("pyXi",&pyXi); tree->SetBranchAddress("pzXi",&pzXi); tree->SetBranchAddress("ppXi",&ppXi); tree->SetBranchAddress("tlengthXi",&tlengthXi); tree->SetBranchAddress("tidXi",&tidXi); tree->SetBranchAddress("didXi",&didXi); tree->SetBranchAddress("pidXi",&pidXi); tree->SetBranchAddress("vtxxXi",&vtxxXi); tree->SetBranchAddress("vtxyXi",&vtxyXi); tree->SetBranchAddress("vtxzXi",&vtxzXi); tree->SetBranchAddress("vtxpxXi",&vtxpxXi); tree->SetBranchAddress("vtxpyXi",&vtxpyXi); tree->SetBranchAddress("vtxpzXi",&vtxpzXi); tree->SetBranchAddress("vtxppXi",&vtxppXi); tree->SetBranchStatus("*",0); tree->SetBranchStatus("ntSsd",1); tree->SetBranchStatus("didSsd",1); tree->SetBranchStatus("pidSsd",1); tree->SetBranchStatus("massSsd",1); tree->SetBranchStatus("chargeSsd",1); tree->SetBranchStatus("ntSdc",1); tree->SetBranchStatus("didSdc",1); tree->SetBranchStatus("pidSdc",1); tree->SetBranchStatus("massSdc",1); tree->SetBranchStatus("chargeSdc",1); Long64_t nentries = tree->GetEntries(); TH1F *hSsd = new TH1F( "hSsd", "SSD NHits", 20, 0., 20. ); TH1F *hSdc[3]; for( Int_t i=0; i<3; ++i ){ hSdc[i] = new TH1F( Form("hSdc%d", i+1), Form("SDC%d NHits", i+1), 20, 0., 20. ); } for( Long64_t ievent=0; ievent<nentries; ++ievent ){ tree->GetEntry( ievent ); if( ievent%1000==0 ) std::cout << ievent << std::endl; { Int_t nt = 0; Bool_t ok[8] = {}; for( Int_t i=0; i<ntSsd; ++i ){ if( pidSsd[i]==321 ){ Int_t ssd = (Int_t)(didSsd[i]/100000); Int_t layer = (Int_t)(didSsd[i]/10000) - ssd*10 + (ssd-1)*4; // std::cout << didSsd[i] << " " << ssd << " " << layer << std::endl; ok[layer] = true; } // std::cout << pidSsd[i] << " " << chargeSsd[i]*massSsd[i] << std::endl; } for( Int_t i=0; i<8; ++i ){ if( ok[i] ) nt++; } // std::cout << nt << std::endl; hSsd->Fill( nt ); } { Int_t nt[3] = {}; Bool_t ok[3][8] = {}; for( Int_t i=0; i<ntSdc; ++i ){ if( pidSdc[i]==321 ){ Int_t sdc = (Int_t)(didSdc[i]/10000); Int_t layer = (Int_t)(didSdc[i]/1000) - sdc*10; // std::cout << didSdc[i] << " " << sdc << " " << layer << std::endl; ok[sdc-1][layer-1] = true; } // std::cout << pidSdc[i] << " " << chargeSdc[i]*massSdc[i] << std::endl; } for( Int_t i=0; i<3; ++i ){ for( Int_t j=0; j<8; ++j ){ if( ok[i][j] ) nt[i]++; } hSdc[i]->Fill( nt[i] ); } // std::cout << nt << std::endl; } } hSdc[1]->Draw(); }
void newReduceTree(){ // -- define tuple file name, tuple name and cuts to apply // -- and also the name of the output file const std::string filename = "/afs/cern.ch/work/a/apmorris/public/Lb2chicpK/signal_samples/Lb2chicpK_MC_2011_2012_signal_cut.root";//change const std::string treename = "DecayTree"; const std::string cuts = ""; const std::string outFile = "/afs/cern.ch/work/a/apmorris/public/Lb2chicpK/signal_samples/reduced_Lb2chicpK_MC_2011_2012_signal.root");//change TFile* file = TFile::Open( filename.c_str() ); if( !file ) std::cout << "file " << filename << " does not exist" << std::endl; TTree* tree = (TTree*)file->Get( treename.c_str() ); if( !tree ) std::cout << "tree " << treename << " does not exist" << std::endl; // -- activate the branches you need tree->SetBranchStatus("*", 0); tree->SetBranchStatus("chi_c_M",1); tree->SetBranchStatus("chi_c_P",1); tree->SetBranchStatus("chi_c_PE",1); tree->SetBranchStatus("chi_c_PT",1); tree->SetBranchStatus("chi_c_PX",1); tree->SetBranchStatus("chi_c_PY",1); tree->SetBranchStatus("chi_c_PZ",1); tree->SetBranchStatus("chi_c_ETA",1); tree->SetBranchStatus("kaon_M",1); tree->SetBranchStatus("kaon_P",1); tree->SetBranchStatus("kaon_PE",1); tree->SetBranchStatus("kaon_PT",1); tree->SetBranchStatus("kaon_PX",1); tree->SetBranchStatus("kaon_PY",1); tree->SetBranchStatus("kaon_PZ",1); tree->SetBranchStatus("kaon_ETA",1); tree->SetBranchStatus("kaon_IPCHI2_OWNPV",1); tree->SetBranchStatus("kaon_TRACK_GhostProb",1); tree->SetBranchStatus("kaon_ProbNNp",1); tree->SetBranchStatus("kaon_ProbNNk",1); tree->SetBranchStatus("proton_M",1); tree->SetBranchStatus("proton_P",1); tree->SetBranchStatus("proton_PE",1); tree->SetBranchStatus("proton_PT",1); tree->SetBranchStatus("proton_PX",1); tree->SetBranchStatus("proton_PY",1); tree->SetBranchStatus("proton_PZ",1); tree->SetBranchStatus("proton_ETA",1); tree->SetBranchStatus("proton_IPCHI2_OWNPV",1); tree->SetBranchStatus("proton_TRACK_GhostProb",1); tree->SetBranchStatus("proton_ProbNNp",1); tree->SetBranchStatus("proton_ProbNNk",1); tree->SetBranchStatus("Jpsi_M",1); tree->SetBranchStatus("Jpsi_P",1); tree->SetBranchStatus("Jpsi_PE",1); tree->SetBranchStatus("Jpsi_PT",1); tree->SetBranchStatus("Jpsi_PX",1); tree->SetBranchStatus("Jpsi_PY",1); tree->SetBranchStatus("Jpsi_PZ",1); tree->SetBranchStatus("Jpsi_ETA",1); tree->SetBranchStatus("gamma_M",1); tree->SetBranchStatus("gamma_P",1); tree->SetBranchStatus("gamma_PE",1); tree->SetBranchStatus("gamma_PT",1); tree->SetBranchStatus("gamma_PX",1); tree->SetBranchStatus("gamma_PY",1); tree->SetBranchStatus("gamma_PZ",1); tree->SetBranchStatus("gamma_CL",1); tree->SetBranchStatus("gamma_ETA",1); tree->SetBranchStatus("muminus_M",1); tree->SetBranchStatus("muminus_P",1); tree->SetBranchStatus("muminus_PE",1); tree->SetBranchStatus("muminus_PT",1); tree->SetBranchStatus("muminus_PX",1); tree->SetBranchStatus("muminus_PY",1); tree->SetBranchStatus("muminus_PZ",1); tree->SetBranchStatus("muminus_ETA",1); tree->SetBranchStatus("muminus_ProbNNmu",1); tree->SetBranchStatus("muminus_TRACK_GhostProb",1); tree->SetBranchStatus("muplus_M",1); tree->SetBranchStatus("muplus_P",1); tree->SetBranchStatus("muplus_PE",1); tree->SetBranchStatus("muplus_PT",1); tree->SetBranchStatus("muplus_PX",1); tree->SetBranchStatus("muplus_PY",1); tree->SetBranchStatus("muplus_PZ",1); tree->SetBranchStatus("muplus_ETA",1); tree->SetBranchStatus("muplus_ProbNNmu",1); tree->SetBranchStatus("muplus_TRACK_GhostProb",1); tree->SetBranchStatus("Lambda_b0_DTF_MASS_constr1",1); tree->SetBranchStatus("Lambda_b0_DTF_MASS_constr2",1); tree->SetBranchStatus("Lambda_b0_DTF_CHI2NDOF",1); tree->SetBranchStatus("Lambda_b0_IPCHI2_OWNPV",1); tree->SetBranchStatus("Lambda_b0_FDS",1); tree->SetBranchStatus("Lambda_b0_L0MuonDecision_TOS",1); tree->SetBranchStatus("Lambda_b0_L0DiMuonDecision_TOS",1); tree->SetBranchStatus("Lambda_b0_Hlt1DiMuonHighMassDecision_TOS",1); tree->SetBranchStatus("Lambda_b0_Hlt1DiMuonLowMassDecision_TOS",1); tree->SetBranchStatus("Lambda_b0_Hlt1TrackMuonDecision_TOS",1); tree->SetBranchStatus("Lambda_b0_Hlt1TrackAllL0Decision_TOS",1); tree->SetBranchStatus("Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS",1); tree->SetBranchStatus("Lambda_b0_Hlt2DiMuonDetachedDecision_TOS",1); tree->SetBranchStatus("Lambda_b0_Hlt2DiMuonDetachedJPsiDecision_TOS",1); tree->SetBranchStatus("Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS",1); tree->SetBranchStatus("Lambda_b0_pi0veto",1); tree->SetBranchStatus("Lambda_b0_PT",1); //for MC only // tree->SetBranchStatus("chi_c_BKGCAT",1); // tree->SetBranchStatus("Jpsi_BKGCAT",1); // tree->SetBranchStatus("Lambda_b0_BKGCAT",1); // // -- this file is just here to make the 'CopyTree' happy TFile* dummyFile = new TFile("/afs/cern.ch/work/a/apmorris/private/cern/ntuples/dummy.root","RECREATE"); TTree* rTree1 = tree->CopyTree(cuts.c_str()); double chi_c_M, chi_c_P, chi_c_PE, chi_c_PT, chi_c_PX, chi_c_PY, chi_c_PZ, chi_c_ETA; double kaon_M, kaon_P, kaon_PE, kaon_PX, kaon_PT, kaon_PY, kaon_PZ, kaon_ETA; double proton_M, proton_P, proton_PE, proton_PT, proton_PX, proton_PY, proton_PZ, proton_ETA; double Jpsi_M, Jpsi_P, Jpsi_PE, Jpsi_PT, Jpsi_PX, Jpsi_PY, Jpsi_PZ, Jpsi_ETA; double gamma_M, gamma_P, gamma_PE, gamma_PT, gamma_PX, gamma_PY, gamma_PZ, gamma_ETA, gamma_CL; double muminus_M, muminus_P, muminus_PE, muminus_PT, muminus_PX, muminus_PY, muminus_PZ, muminus_ETA, muminus_ProbNNmu, muminus_TRACK_GhostProb; double muplus_M, muplus_P, muplus_PE, muplus_PT, muplus_PX, muplus_PY, muplus_PZ, muplus_ETA, muplus_ProbNNmu, muplus_TRACK_GhostProb; double kaon_IPCHI2_OWNPV, kaon_TRACK_GhostProb, kaon_ProbNNp, kaon_ProbNNk; double proton_IPCHI2_OWNPV, proton_TRACK_GhostProb, proton_ProbNNp, proton_ProbNNk; double Lambda_b0_DTF_MASS_constr1, Lambda_b0_DTF_MASS_constr2, Lambda_b0_DTF_CHI2NDOF, Lambda_b0_IPCHI2_OWNPV; double Lambda_b0_FDS, Lambda_b0_pi0veto, Lambda_b0_PT; bool Lambda_b0_L0MuonDecision_TOS, Lambda_b0_L0DiMuonDecision_TOS; bool Lambda_b0_Hlt1DiMuonHighMassDecision_TOS, Lambda_b0_Hlt1DiMuonLowMassDecision_TOS; bool Lambda_b0_Hlt1TrackMuonDecision_TOS, Lambda_b0_Hlt1TrackAllL0Decision_TOS; bool Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS, Lambda_b0_Hlt2DiMuonDetachedDecision_TOS; bool Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS, Lambda_b0_Hlt2DiMuonDetachedJPsiDecision_TOS; rTree1->SetBranchAddress("chi_c_M", &chi_c_M); rTree1->SetBranchAddress("chi_c_P", &chi_c_P); rTree1->SetBranchAddress("chi_c_PE", &chi_c_PE); rTree1->SetBranchAddress("chi_c_PT", &chi_c_PT); rTree1->SetBranchAddress("chi_c_PX", &chi_c_PX); rTree1->SetBranchAddress("chi_c_PY", &chi_c_PY); rTree1->SetBranchAddress("chi_c_PZ", &chi_c_PZ); rTree1->SetBranchAddress("chi_c_ETA", &chi_c_ETA); rTree1->SetBranchAddress("kaon_M", &kaon_M); rTree1->SetBranchAddress("kaon_P", &kaon_P); rTree1->SetBranchAddress("kaon_PE", &kaon_PE); rTree1->SetBranchAddress("kaon_PX", &kaon_PX); rTree1->SetBranchAddress("kaon_PT", &kaon_PT); rTree1->SetBranchAddress("kaon_PY", &kaon_PY); rTree1->SetBranchAddress("kaon_PZ", &kaon_PZ); rTree1->SetBranchAddress("kaon_ETA", &kaon_ETA); rTree1->SetBranchAddress("kaon_IPCHI2_OWNPV", &kaon_IPCHI2_OWNPV); rTree1->SetBranchAddress("kaon_TRACK_GhostProb", &kaon_TRACK_GhostProb); rTree1->SetBranchAddress("kaon_ProbNNp", &kaon_ProbNNp); rTree1->SetBranchAddress("kaon_ProbNNk", &kaon_ProbNNk); rTree1->SetBranchAddress("proton_M", &proton_M); rTree1->SetBranchAddress("proton_P", &proton_P); rTree1->SetBranchAddress("proton_PE", &proton_PE); rTree1->SetBranchAddress("proton_PT", &proton_PT); rTree1->SetBranchAddress("proton_PX", &proton_PX); rTree1->SetBranchAddress("proton_PY", &proton_PY); rTree1->SetBranchAddress("proton_PZ", &proton_PZ); rTree1->SetBranchAddress("proton_ETA", &proton_ETA); rTree1->SetBranchAddress("proton_IPCHI2_OWNPV", &proton_IPCHI2_OWNPV); rTree1->SetBranchAddress("proton_TRACK_GhostProb", &proton_TRACK_GhostProb); rTree1->SetBranchAddress("proton_ProbNNp", &proton_ProbNNp); rTree1->SetBranchAddress("proton_ProbNNk", &proton_ProbNNk); rTree1->SetBranchAddress("Jpsi_M", &Jpsi_M); rTree1->SetBranchAddress("Jpsi_P", &Jpsi_P); rTree1->SetBranchAddress("Jpsi_PE", &Jpsi_PE); rTree1->SetBranchAddress("Jpsi_PT", &Jpsi_PT); rTree1->SetBranchAddress("Jpsi_PX", &Jpsi_PX); rTree1->SetBranchAddress("Jpsi_PY", &Jpsi_PY); rTree1->SetBranchAddress("Jpsi_PZ", &Jpsi_PZ); rTree1->SetBranchAddress("Jpsi_ETA", &Jpsi_ETA); rTree1->SetBranchAddress("gamma_M", &gamma_M); rTree1->SetBranchAddress("gamma_P", &gamma_P); rTree1->SetBranchAddress("gamma_PE", &gamma_PE); rTree1->SetBranchAddress("gamma_PT", &gamma_PT); rTree1->SetBranchAddress("gamma_PX", &gamma_PX); rTree1->SetBranchAddress("gamma_PY", &gamma_PY); rTree1->SetBranchAddress("gamma_PZ", &gamma_PZ); rTree1->SetBranchAddress("gamma_ETA", &gamma_ETA); rTree1->SetBranchAddress("gamma_CL", &gamma_CL); rTree1->SetBranchAddress("muminus_M", &muminus_M); rTree1->SetBranchAddress("muminus_P", &muminus_P); rTree1->SetBranchAddress("muminus_PE", &muminus_PE); rTree1->SetBranchAddress("muminus_PT", &muminus_PT); rTree1->SetBranchAddress("muminus_PX", &muminus_PX); rTree1->SetBranchAddress("muminus_PY", &muminus_PY); rTree1->SetBranchAddress("muminus_PZ", &muminus_PZ); rTree1->SetBranchAddress("muminus_ETA", &muminus_ETA); rTree1->SetBranchAddress("muminus_ProbNNmu", &muminus_ProbNNmu); rTree1->SetBranchAddress("muminus_TRACK_GhostProb", &muminus_TRACK_GhostProb); rTree1->SetBranchAddress("muplus_M", &muplus_M); rTree1->SetBranchAddress("muplus_P", &muplus_P); rTree1->SetBranchAddress("muplus_PE", &muplus_PE); rTree1->SetBranchAddress("muplus_PT", &muplus_PT); rTree1->SetBranchAddress("muplus_PX", &muplus_PX); rTree1->SetBranchAddress("muplus_PY", &muplus_PY); rTree1->SetBranchAddress("muplus_PZ", &muplus_PZ); rTree1->SetBranchAddress("muplus_ETA", &muplus_ETA); rTree1->SetBranchAddress("muplus_ProbNNmu", &muplus_ProbNNmu); rTree1->SetBranchAddress("muplus_TRACK_GhostProb", &muplus_TRACK_GhostProb); rTree1->SetBranchAddress("Lambda_b0_DTF_MASS_constr1", &Lambda_b0_DTF_MASS_constr1); rTree1->SetBranchAddress("Lambda_b0_DTF_MASS_constr2", &Lambda_b0_DTF_MASS_constr2); rTree1->SetBranchAddress("Lambda_b0_DTF_CHI2NDOF", &Lambda_b0_DTF_CHI2NDOF); rTree1->SetBranchAddress("Lambda_b0_IPCHI2_OWNPV", &Lambda_b0_IPCHI2_OWNPV); rTree1->SetBranchAddress("Lambda_b0_L0DiMuonDecision_TOS", &Lambda_b0_L0DiMuonDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_L0MuonDecision_TOS", &Lambda_b0_L0MuonDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_FDS", &Lambda_b0_FDS); rTree1->SetBranchAddress("Lambda_b0_Hlt1DiMuonHighMassDecision_TOS", &Lambda_b0_Hlt1DiMuonHighMassDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt1DiMuonLowMassDecision_TOS", &Lambda_b0_Hlt1DiMuonLowMassDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt1TrackMuonDecision_TOS", &Lambda_b0_Hlt1TrackMuonDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt1TrackAllL0Decision_TOS", &Lambda_b0_Hlt1TrackAllL0Decision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS", &Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt2DiMuonDetachedDecision_TOS", &Lambda_b0_Hlt2DiMuonDetachedDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt2DiMuonDetachedJPsiDecision_TOS", &Lambda_b0_Hlt2DiMuonDetachedJPsiDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS", &Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_pi0veto", &Lambda_b0_pi0veto); rTree1->SetBranchAddress("Lambda_b0_PT", &Lambda_b0_PT); //for MC only // int chi_c_BKGCAT, Jpsi_BKGCAT, Lambda_b0_BKGCAT; // rTree1->SetBranchAddress("chi_c_BKGCAT", &chi_c_BKGCAT); // rTree1->SetBranchAddress("Jpsi_BKGCAT", &Jpsi_BKGCAT); // rTree1->SetBranchAddress("Lambda_b0_BKGCAT", &Lambda_b0_BKGCAT); // TFile* rFile = new TFile( outFile.c_str() ,"RECREATE"); TTree* rTree2 = new TTree(); rTree2->SetName("DecayTree"); rTree2->Branch("chi_c_M", &chi_c_M, "chi_c_M/D"); rTree2->Branch("chi_c_P", &chi_c_P, "chi_c_P/D"); rTree2->Branch("chi_c_PE", &chi_c_PE, "chi_c_PE/D"); rTree2->Branch("chi_c_PT", &chi_c_PT, "chi_c_PT/D"); rTree2->Branch("chi_c_PX", &chi_c_PX, "chi_c_PX/D"); rTree2->Branch("chi_c_PY", &chi_c_PY, "chi_c_PY/D"); rTree2->Branch("chi_c_PZ", &chi_c_PZ, "chi_c_PZ/D"); rTree2->Branch("chi_c_ETA", &chi_c_ETA, "chi_c_ETA/D"); rTree2->Branch("kaon_M", &kaon_M, "kaon_M/D"); rTree2->Branch("kaon_P", &kaon_P, "kaon_P/D"); rTree2->Branch("kaon_PE", &kaon_PE, "kaon_PE/D"); rTree2->Branch("kaon_PX", &kaon_PX, "kaon_PX/D"); rTree2->Branch("kaon_PT", &kaon_PT, "kaon_PT/D"); rTree2->Branch("kaon_PY", &kaon_PY, "kaon_PY/D"); rTree2->Branch("kaon_PZ", &kaon_PZ, "kaon_PZ/D"); rTree2->Branch("kaon_ETA", &kaon_ETA, "kaon_ETA/D"); rTree2->Branch("kaon_IPCHI2_OWNPV", &kaon_IPCHI2_OWNPV, "kaon_IPCHI2_OWNPV/D"); rTree2->Branch("kaon_TRACK_GhostProb", &kaon_TRACK_GhostProb, "kaon_TRACK_GhostProb/D"); rTree2->Branch("kaon_ProbNNp", &kaon_ProbNNp, "kaon_ProbNNp/D"); rTree2->Branch("kaon_ProbNNk", &kaon_ProbNNk, "kaon_ProbNNk/D"); rTree2->Branch("proton_M", &proton_M, "proton_M/D"); rTree2->Branch("proton_P", &proton_P, "proton_P/D"); rTree2->Branch("proton_PE", &proton_PE, "proton_PE/D"); rTree2->Branch("proton_PT", &proton_PT, "proton_PT/D"); rTree2->Branch("proton_PX", &proton_PX, "proton_PX/D"); rTree2->Branch("proton_PY", &proton_PY, "proton_PY/D"); rTree2->Branch("proton_PZ", &proton_PZ, "proton_PZ/D"); rTree2->Branch("proton_ETA", &proton_ETA, "proton_ETA/D"); rTree2->Branch("proton_IPCHI2_OWNPV", &proton_IPCHI2_OWNPV, "proton_IPCHI2_OWNPV/D"); rTree2->Branch("proton_TRACK_GhostProb", &proton_TRACK_GhostProb, "proton_TRACK_GhostProb/D"); rTree2->Branch("proton_ProbNNp", &proton_ProbNNp, "proton_ProbNNp/D"); rTree2->Branch("proton_ProbNNk", &proton_ProbNNk, "proton_ProbNNk/D"); rTree2->Branch("Jpsi_M", &Jpsi_M, "Jpsi_M/D"); rTree2->Branch("Jpsi_P", &Jpsi_P, "Jpsi_P/D"); rTree2->Branch("Jpsi_PE", &Jpsi_PE, "Jpsi_PE/D"); rTree2->Branch("Jpsi_PT", &Jpsi_PT, "Jpsi_PT/D"); rTree2->Branch("Jpsi_PX", &Jpsi_PX, "Jpsi_PX/D"); rTree2->Branch("Jpsi_PY", &Jpsi_PY, "Jpsi_PY/D"); rTree2->Branch("Jpsi_PZ", &Jpsi_PZ, "Jpsi_PZ/D"); rTree2->Branch("Jpsi_ETA", &Jpsi_ETA, "Jpsi_ETA/D"); rTree2->Branch("gamma_M", &gamma_M, "gamma_M/D"); rTree2->Branch("gamma_P", &gamma_P, "gamma_P/D"); rTree2->Branch("gamma_PE", &gamma_PE, "gamma_PE/D"); rTree2->Branch("gamma_PT", &gamma_PT, "gamma_PT/D"); rTree2->Branch("gamma_PX", &gamma_PX, "gamma_PX/D"); rTree2->Branch("gamma_PY", &gamma_PY, "gamma_PY/D"); rTree2->Branch("gamma_PZ", &gamma_PZ, "gamma_PZ/D"); rTree2->Branch("gamma_ETA", &gamma_ETA, "gamma_ETA/D"); rTree2->Branch("gamma_CL", &gamma_CL, "gamma_CL/D"); rTree2->Branch("muminus_M", &muminus_M, "muminus_M/D"); rTree2->Branch("muminus_P", &muminus_P, "muminus_P/D"); rTree2->Branch("muminus_PE", &muminus_PE, "muminus_PE/D"); rTree2->Branch("muminus_PT", &muminus_PT, "muminus_PT/D"); rTree2->Branch("muminus_PX", &muminus_PX, "muminus_PX/D"); rTree2->Branch("muminus_PY", &muminus_PY, "muminus_PY/D"); rTree2->Branch("muminus_PZ", &muminus_PZ, "muminus_PZ/D"); rTree2->Branch("muminus_ETA", &muminus_ETA, "muminus_ETA/D"); rTree2->Branch("muminus_ProbNNmu", &muminus_ProbNNmu, "muminus_ProbNNmu/D"); rTree2->Branch("muminus_TRACK_GhostProb", &muminus_TRACK_GhostProb, "muminus_TRACK_GhostProb/D"); rTree2->Branch("muplus_M", &muplus_M, "muplus_M/D"); rTree2->Branch("muplus_P", &muplus_P, "muplus_P/D"); rTree2->Branch("muplus_PE", &muplus_PE, "muplus_PE/D"); rTree2->Branch("muplus_PT", &muplus_PT, "muplus_PT/D"); rTree2->Branch("muplus_PX", &muplus_PX, "muplus_PX/D"); rTree2->Branch("muplus_PY", &muplus_PY, "muplus_PY/D"); rTree2->Branch("muplus_PZ", &muplus_PZ, "muplus_PZ/D"); rTree2->Branch("muplus_ETA", &muplus_ETA, "muplus_ETA/D"); rTree2->Branch("muplus_ProbNNmu", &muplus_ProbNNmu, "muplus_ProbNNmu/D"); rTree2->Branch("muplus_TRACK_GhostProb", &muplus_TRACK_GhostProb, "muplus_TRACK_GhostProb/D"); rTree2->Branch("Lambda_b0_DTF_MASS_constr1", &Lambda_b0_DTF_MASS_constr1, "Lambda_b0_DTF_MASS_constr1/D"); rTree2->Branch("Lambda_b0_DTF_MASS_constr2", &Lambda_b0_DTF_MASS_constr2, "Lambda_b0_DTF_MASS_constr2/D"); rTree2->Branch("Lambda_b0_DTF_CHI2NDOF", &Lambda_b0_DTF_CHI2NDOF, "Lambda_b0_DTF_CHI2NDOF/D"); rTree2->Branch("Lambda_b0_IPCHI2_OWNPV", &Lambda_b0_IPCHI2_OWNPV, "Lambda_b0_IPCHI2_OWNPV/D"); rTree2->Branch("Lambda_b0_L0DiMuonDecision_TOS",&Lambda_b0_L0DiMuonDecision_TOS,"Lambda_b0_L0DiMuonDecision_TOS/B"); rTree2->Branch("Lambda_b0_L0MuonDecision_TOS", &Lambda_b0_L0MuonDecision_TOS, "Lambda_b0_L0MuonDecision_TOS/B"); rTree2->Branch("Lambda_b0_FDS", &Lambda_b0_FDS, "Lambda_b0_FDS/D"); rTree2->Branch("Lambda_b0_Hlt1DiMuonHighMassDecision_TOS", &Lambda_b0_Hlt1DiMuonHighMassDecision_TOS, "Lambda_b0_Hlt1DiMuonHighMassDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt1DiMuonLowMassDecision_TOS", &Lambda_b0_Hlt1DiMuonLowMassDecision_TOS, "Lambda_b0_Hlt1DiMuonLowMassDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt1TrackMuonDecision_TOS", &Lambda_b0_Hlt1TrackMuonDecision_TOS, "Lambda_b0_Hlt1TrackMuonDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt1TrackAllL0Decision_TOS", &Lambda_b0_Hlt1TrackAllL0Decision_TOS, "Lambda_b0_Hlt1TrackAllL0Decision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS", &Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS, "Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt2DiMuonDetachedDecision_TOS", &Lambda_b0_Hlt2DiMuonDetachedDecision_TOS, "Lambda_b0_Hlt2DiMuonDetachedDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt2DiMuonDetachedJPsiDecision_TOS", &Lambda_b0_Hlt2DiMuonDetachedJPsiDecision_TOS, "Lambda_b0_Hlt2DiMuonDetachedJPsiDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS", &Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS, "Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS/B"); rTree2->Branch("Lambda_b0_pi0veto", &Lambda_b0_pi0veto, "Lambda_b0_pi0veto/D"); rTree2->Branch("Lambda_b0_PT", &Lambda_b0_PT, "Lambda_b0_PT/D"); //for MC only // rTree2->Branch("chi_c_BKGCAT", &chi_c_BKGCAT, "chi_c_BKGCAT/I"); // rTree2->Branch("Jpsi_BKGCAT", &Jpsi_BKGCAT, "Jpsi_BKGCAT/I"); // rTree2->Branch("Lambda_b0_BKGCAT", &Lambda_b0_BKGCAT, "Lambda_b0_BKGCAT/I"); // //----------------------------------------------------------------------------------- const double mK(493.677); const double mpi(139.57); const double mp(938.27); double m_pK, m_chicp; double proton_as_kaon_M, proton_as_pion_M, proton_as_proton_M; double m_chicpK_proton_as_kaon, m_chicpK_proton_as_pion, m_chicpK_proton_as_proton; double m_JpsipK; rTree2->Branch("m_JpsipK", &m_JpsipK, "m_JpsipK/D"); rTree2->Branch("m_chicp", &m_chicp, "m_chicp/D"); rTree2->Branch("m_pK", &m_pK, "m_pK/D"); rTree2->Branch("proton_as_kaon_M", &proton_as_kaon_M, "proton_as_kaon_M/D"); rTree2->Branch("proton_as_pion_M", &proton_as_pion_M, "proton_as_pion_M/D"); rTree2->Branch("proton_as_proton_M", &proton_as_proton_M, "proton_as_proton_M/D"); rTree2->Branch("m_chicpK_proton_as_kaon", &m_chicpK_proton_as_kaon, "m_chicpK_proton_as_kaon/D"); rTree2->Branch("m_chicpK_proton_as_pion", &m_chicpK_proton_as_pion, "m_chicpK_proton_as_pion/D"); rTree2->Branch("m_chicpK_proton_as_proton", &m_chicpK_proton_as_proton, "m_chicpK_proton_as_proton/D"); int percentCounter = 1; for(int i = 0; i < rTree1->GetEntries(); ++i){ const int percent = (int)(rTree1->GetEntries()/100.0); if( i == percent*percentCounter ){ std::cout << percentCounter << " %" << std::endl; percentCounter++; } rTree1->GetEntry(i); double proton_P = sqrt(proton_PX*proton_PX + proton_PY*proton_PY + proton_PZ*proton_PZ) ; TLorentzVector proton_as_kaon( proton_PX, proton_PY, proton_PZ, sqrt(proton_P*proton_P + mK*mK)); TLorentzVector proton_as_pion( proton_PX, proton_PY, proton_PZ, sqrt(proton_P*proton_P + mpi*mpi)); TLorentzVector proton_as_proton( proton_PX, proton_PY, proton_PZ, sqrt(proton_P*proton_P + proton_M*proton_M)); TLorentzVector kaon( kaon_PX, kaon_PY, kaon_PZ, kaon_PE); TLorentzVector chic( chi_c_PX, chi_c_PY, chi_c_PZ, chi_c_PE); TLorentzVector proton(proton_PX, proton_PY, proton_PZ, proton_PE); TLorentzVector Jpsi( Jpsi_PX, Jpsi_PY, Jpsi_PZ, Jpsi_PE); proton_as_kaon_M = proton_as_kaon.M(); proton_as_pion_M = proton_as_pion.M(); proton_as_proton_M = proton_as_proton.M(); TLorentzVector chic_PasK_K = chic + kaon + proton_as_kaon; TLorentzVector chic_PasPi_K = chic + kaon + proton_as_pion; TLorentzVector chic_PasP_K = chic + kaon + proton_as_proton; m_chicpK_proton_as_kaon = chic_PasK_K.M(); m_chicpK_proton_as_pion = chic_PasPi_K.M(); m_chicpK_proton_as_proton = chic_PasP_K.M(); TLorentzVector JpsipK = Jpsi + proton + kaon; TLorentzVector chicp = chic + proton; TLorentzVector pK = proton + kaon; m_JpsipK = JpsipK.M(); m_chicp = chicp.M(); m_pK = pK.M(); rTree2->Fill(); } rTree2->Print(); rTree2->Write(); rFile->Save(); }
//______________________________________________________________________________ void showSdcOutTrack( void ) { const TString& root_file("root/grun_e07_1.4.root"); TFile *file = TFile::Open( root_file ); if( !file || !file->IsOpen() ) gApplication->Terminate(); TTree *tree = (TTree*)file->Get("tree"); if( !tree ) gApplication->Terminate(); TCanvas *c1 = new TCanvas("c1", "c1", 800, 600); c1->Divide(2,2); //c1->DrawFrame( -2000., -2000., 4000., 2000. ); const Int_t MaxHits = 256; Int_t ntTof; Int_t pidTof[MaxHits]; Double_t xTof[MaxHits]; Double_t yTof[MaxHits]; Double_t zTof[MaxHits]; Double_t pxTof[MaxHits]; Double_t pyTof[MaxHits]; Double_t pzTof[MaxHits]; Double_t ppTof[MaxHits]; tree->SetBranchAddress("ntTof", &ntTof); tree->SetBranchAddress("pidTof", pidTof); tree->SetBranchAddress("xTof", xTof); tree->SetBranchAddress("yTof", yTof); tree->SetBranchAddress("zTof", zTof); tree->SetBranchAddress("pxTof", pxTof); tree->SetBranchAddress("pyTof", pyTof); tree->SetBranchAddress("pzTof", pzTof); tree->SetBranchAddress("ppTof", ppTof); tree->SetBranchStatus("*", kFALSE); tree->SetBranchStatus("ntTof", kTRUE); tree->SetBranchStatus("pidTof", kTRUE); tree->SetBranchStatus("xTof", kTRUE); tree->SetBranchStatus("yTof", kTRUE); tree->SetBranchStatus("zTof", kTRUE); tree->SetBranchStatus("pxTof", kTRUE); tree->SetBranchStatus("pyTof", kTRUE); tree->SetBranchStatus("pzTof", kTRUE); tree->SetBranchStatus("ppTof", kTRUE); TH1F *h_u0 = new TH1F("h_u0", "U0", 200, -0.25, -0.05 ); TH1F *h_x0 = new TH1F("h_x0", "X0", 200, -100., 100. ); const Int_t NEntries = tree->GetEntries(); for( Int_t ie=0; ie<NEntries; ++ie ){ tree->GetEntry(ie); for( Int_t ih=0; ih<ntTof; ++ih ){ if( pidTof[ih] != -211 ) continue; Double_t u0 = pxTof[ih]/pzTof[ih]; Double_t x0 = xTof[ih] - u0*zTof[ih]; TF1 *f = new TF1("f", "[0]*x+[1]", 0., 4000. ); f->SetLineColor(kRed+1); f->SetParameter(0, u0); f->SetParameter(1, x0); std::cout << u0 << "\t" << x0 << std::endl; //f->Draw("same"); h_u0->Fill( u0 ); h_x0->Fill( x0 ); } } c1->cd(1); h_u0->Draw(); c1->cd(2); h_x0->Draw(); }
Int_t AnalyzeCells_Fill( const char* runlist = "/home/yuxip/FMS/CellScan/macros/fill15419.list",const char* ls = "small" ){ gStyle->SetPalette(1); gSystem->Load("../lib/libMyCellMgr.so"); gROOT->LoadMacro("/home/yuxip/FMS/CellScan/macros/Legal.C"); gROOT->LoadMacro("/home/yuxip/FMS/CellScan/macros/ConvertTH2Bin.C"); mGeom = new Geom("./","geom.txt"); cout<<"runlist: "<<runlist<<endl; Int_t fillnum = 0; Int_t runtoshow = 1; Long_t runnum = 0; Int_t rcnt = 0; sscanf(runlist,"/home/yuxip/FMS/CellScan/macros/fill%d.list",&fillnum); fstream infill(runlist,ios::in); if(!infill){ cout<<"ERROR! "<<runlist<<" does not exist!!"<<endl; return -1; } while(infill>>runnum){ rcnt++; if(rcnt==runtoshow)break; } cout<<"runtoshow: "<<runnum<<endl; Char_t outfilename[30]; if(!strcmp(ls,"large")){ sprintf(outfilename,"LargeCells_fill%d_run%ld_n2.ps",fillnum,runnum); } else if(!strcmp(ls,"small")){ sprintf(outfilename,"SmallCells_fill%d_run%ld_n4.ps",fillnum,runnum); } else{ cout<<"invalid 2nd argument!!"<<endl; return -1; } TString outfile(outfilename); TString headout = outfile + "["; TString endout = outfile + "]"; TCanvas* c1 = new TCanvas("c1","c1",700,1100); c1->Divide(2,3); c1->Print(headout); Int_t ncell = 1000; //for test only Int_t cellcnt = 0; Char_t cellname[30]; Char_t cellfile[30]; TDirectory* h1where = gDirectory; TH1F* hmass = new TH1F("hmass","hmass",50,0,1); TH2F* hxy1 = new TH2F("hxy1","hxy1",34,-98.6,98.6,34,-98.6,98.6); TH2F* hxy2 = new TH2F("hxy2","hxy2",34,-98.6,98.6,34,-98.6,98.6); TH2F* smallxy1 = new TH2F("smallxy1","smallxy1",52,-98.6,98.6,52,-98.6,98.6); TH2F* smallxy2 = new TH2F("smallxy2","smallxy2",52,-98.6,98.6,52,-98.6,98.6); Float_t wbox = 12.0*3.8; Int_t nentries; Int_t maxy = 0; Int_t maxx = 0; UChar_t Status = 0x00; Char_t text[30]; MyCell* mcell = new MyCell(); TTree* Trpi; Float_t x2, y2; Int_t cnt = 1; Int_t n1 = 0; Int_t n2 = 0; if(!strcmp(ls,"large")){ n1 = 2; n2 = 2; //analysis each nstb separately } else if(!strcmp(ls,"small")){ n1 = 4; n2 = 4; } else{ cout<<"invalid 2nd argument"<<endl; return -1; } Int_t largeN1 = 0; Int_t smallN1 = 0; Int_t largeN2 = 0; Int_t smallN2 = 0; TFile* fcell = 0; MyCellEvt* mcevt = new MyCellEvt(); for(Int_t nstb = n1; nstb <= n2; nstb++){ for(Int_t row0 = 0; row0 < 34; row0++){ for(Int_t col0 = 0; col0 < 17; col0++){ cout<<"row0: "<<row0<<" col0: "<<col0<<" nstb: "<<nstb<<endl; if(!Legal(2,nstb,row0,col0)){ continue; } cellcnt++; sprintf(cellname,"Cellr%d_c%d_n%d",row0,col0,nstb); cout<<"processing "<<cellname<<endl; sprintf(cellfile,"../cells/Cellr%d_c%d_n%d.root",row0,col0,nstb); fcell = new TFile(cellfile,"read"); mcell = (MyCell*)fcell->Get(cellname); mcell->SetGeom(mGeom); mcell->Print(); if(!mcell){ cout<<"ERROR getting "<<cellname<<endl; return 0; } c1->cd(cnt); c1->GetPad(cnt)->SetLogy(); c1->GetPad(cnt)->SetLogx(); mcell->GetAdcSpectrum(runnum)->Draw(); cnt++; c1->cd(cnt); c1->GetPad(cnt)->SetLogy(); c1->GetPad(cnt)->SetLogx(); mcell->GetLEDSpectrum(runnum)->Draw(); mcell->GetLEDSpectrum(runnum)->SetLineColor(kBlue); Status = mcell->GetStatusBit(runnum); sprintf(text,"0x%x",Status); TLatex l(0.5,0.5,text); l.SetNDC(); l.SetTextColor(2); l.Draw(); cnt++; c1->cd(cnt); // c1->GetPad(cnt)->SetLogy(); c1->GetPad(cnt)->SetFillColor(37); maxy = mcell->GetLEDvsEvt(runnum)->FindLastBinAbove(0,2); maxx = mcell->GetLEDvsEvt(runnum)->FindLastBinAbove(0,1); cout<<"maxx: "<<maxx<<endl; if(maxy < 2000){ mcell->GetLEDvsEvt(runnum)->GetYaxis()->SetRange(0,2*maxy); } if(maxx < 2000){ mcell->GetLEDvsEvt(runnum)->GetXaxis()->SetRange(0,(maxx+100)); } mcell->GetLEDvsEvt(runnum)->Draw("COLZ"); Trpi = mcell->GetPionSample("all",runlist); nentries = Trpi->GetEntries(); // Trpi->Print(); cout<<"Trpi nentries: "<<nentries<<endl; if(nentries!=0){ /* */ // h1where->cd(); // cnt++; // c1->cd(cnt); // Trpi->Project("hmass","M",""); // hmass->Draw(); // cnt++; // c1->cd(cnt); Float_t x1; Float_t x2; Float_t y1; Float_t y2; Float_t m; Trpi->ResetBranchAddresses(); //the orginal MergedTr was hooked up with transient member MyCellEvt of MyCell Trpi->SetBranchAddress("mycevt",&mcevt); // Trpi->SetBranchAddress("Y2",&y2); // Trpi->SetBranchAddress("M",&m); Trpi->SetBranchStatus("*",0); Trpi->SetBranchStatus("X2",1); Trpi->SetBranchStatus("Y2",1); Trpi->SetBranchStatus("M",1); // Trpi->GetEntry(0); // Trpi->Show(0); // cout<<"X2: "<<(mcevt->X2)<<", Y2: "<<(mcevt->Y2)<<", M: "<<(mcevt->M)<<endl; Int_t binx; Int_t biny; TString partner; Int_t pnstb = 0; Int_t prow0 = 0; Int_t pcol0 = 0; Long_t prun = 0; for(Int_t i = 0; i < nentries; i++){ if(nstb<3){ //large cells if(!ConvertTH2Bin(nstb,row0,col0,binx,biny,hxy1)){ cout<<"ERROR in ConvertTH2Bin()!"<<endl; return -1; } hxy1->SetBinContent(binx,biny,(hxy1->GetBinContent(binx,biny)+1)); } if(nstb>2){ //small cells if(!ConvertTH2Bin(nstb,row0,col0,binx,biny,smallxy1)){ cout<<"ERROR in ConvertTH2Bin()!"<<endl; return -1; } smallxy1->SetBinContent(binx,biny,(smallxy1->GetBinContent(binx,biny)+1)); } // cout<<"binx: "<<binx<<", biny: "<<biny<<endl; Trpi->GetEntry(i); // Trpi->Show(i); x2 = mcevt->X2; y2 = mcevt->Y2; m = mcevt->M; // cout<<"X2: "<<x2<<", Y2: "<<y2<<", M: "<<m<<endl; hmass->Fill(m); if(!mGeom->getNSTB(x2,y2))continue; //bypass abnormal nstb partner = mcell->GetPartnerByXY(x2,y2,runnum); if(col0==0){ cout<<"debug: partner: "<<partner<<endl; } sscanf((const char*)partner,"Cellr%d_c%d_n%d_run%ld",&prow0,&pcol0,&pnstb,&prun); if(col0==0){ cout<<"debug: partner (nstb,row0,col0): ("<<pnstb<<", "<<prow0<<", "<<pcol0<<") "<<endl; } if(!Legal(2,pnstb,prow0,pcol0)){ cout<<"invalid partner id"<<endl; continue; } if(pnstb<3){ //large cells if(!ConvertTH2Bin(pnstb,prow0,pcol0,binx,biny,hxy2)){ cout<<"ERROR in ConvertTH2Bin()!"<<endl; return -1; } hxy2->SetBinContent(binx,biny,(hxy2->GetBinContent(binx,biny)+1)); } if(pnstb>2){ //small cells if(!ConvertTH2Bin(pnstb,prow0,pcol0,binx,biny,smallxy2)){ cout<<"ERROR in ConvertTH2Bin()!"<<endl; return -1; } smallxy2->SetBinContent(binx,biny,(smallxy2->GetBinContent(binx,biny)+1)); } } smallN1 = smallxy1->GetBinContent(smallxy1->GetMaximumBin()); largeN1 = hxy1->GetBinContent(hxy1->GetMaximumBin()); if(smallN1>=largeN1){ cout<<"smallN1: "<<smallN1<<endl; hxy1->GetZaxis()->SetRangeUser(0,smallN1); smallxy1->GetZaxis()->SetRangeUser(0,smallN1); } else{ cout<<"largeN1: "<<largeN1<<endl; hxy1->GetZaxis()->SetRangeUser(0,largeN1); smallxy1->GetZaxis()->SetRangeUser(0,largeN1); } cnt++; c1->cd(cnt); hmass->Draw(); cnt++; c1->cd(cnt); hxy1->SetStats(0); hxy1->Draw("COLZ"); TBox bx(-wbox,-wbox,wbox,wbox); bx.SetFillColor(18); bx.Draw("same"); smallxy1->SetStats(0); smallxy1->Draw("zcolsame"); cnt++; c1->cd(cnt); largeN2 = hxy2->GetBinContent(hxy2->GetMaximumBin()); smallN2 = smallxy2->GetBinContent(smallxy2->GetMaximumBin()); if(smallN2>=largeN2){ cout<<"smallN2: "<<smallN2<<endl; hxy2->GetZaxis()->SetRangeUser(0,smallN2); smallxy2->GetZaxis()->SetRangeUser(0,smallN2); } else{ cout<<"largeN2: "<<largeN2<<endl; hxy2->GetZaxis()->SetRangeUser(0,largeN2); smallxy2->GetZaxis()->SetRangeUser(0,largeN2); } hxy2->SetStats(0); hxy2->Draw("COLZ"); bx.Draw("same"); smallxy2->SetStats(0); smallxy2->Draw("zcolsame"); } largeN1 = largeN2 = 0; smallN1 = smallN2 = 0; Trpi = 0; c1->Print(outfile); mcell = 0; hmass->Reset(); hxy1->Reset(); hxy2->Reset(); smallxy1->Reset(); smallxy2->Reset(); fcell->Close(); fcell = 0; c1->Clear(); c1->Divide(2,3); cnt = 1; if(cellcnt == ncell)break; } if(cellcnt == ncell)break; } if(cellcnt == ncell)break; } c1->Print(endout); return 1; }
//std::mutex mtx; void ProcessFilePar(TString fileIn, TString fileOut, TString treename, vector<TString> friends, vector<TString> branches, vector<TString> newbranches, unsigned jobid = 0, unsigned NPAR = 1) { //mtx.lock(); //for threads TFile *fin = new TFile(fileIn); TTree *tjet = (TTree*)fin->Get(treename); //mtx.unlock(); vector<TTree *> friendTrees; vector<bool> sameFileFriend; for (auto f:friends) { auto fr = tokenize(f,":"); if (fr.size()==1) {tjet->AddFriend(fr[0]); sameFileFriend.push_back(true);} else if (fr.size()==2) {tjet->AddFriend(fr[1],fr[0]); sameFileFriend.push_back(false);} TTree *tfriend = (TTree*)fin->Get(f); friendTrees.push_back(tfriend); } AddBranchesByCounter(tjet, branches); for (unsigned i=0;i<friendTrees.size();i++) AddBranchesByCounter(friendTrees[i],branches); //sort branches into categories for (auto bName:branches) { TBranch *b=tjet->GetBranch(bName); if (b==0) cout <<"Branch "<<bName<<" doesn't exist!"<<endl; //parse in case there is a tree name in the branch auto branchtoken = tokenize(bName,"."); auto leafname = branchtoken[branchtoken.size()-1]; TObjArray *bl = b->GetListOfLeaves(); if (bl->GetEntries()>1) cout <<" Branch "<<b->GetTitle()<<" has more than 1 leave. Taking first..."<<endl; if (bl->GetEntries()==0) { cout <<" Branch "<<b->GetTitle()<<" has no leaves! Skipping..."<<endl; continue; } TLeaf * l = (TLeaf *)(*bl)[0]; //what's the type? TString type = l->GetTypeName(); if (VERBOSE) cout<<l->GetTitle()<<endl; //array? bool array = l->GetLeafCount()!=0; TString counter; if (array) counter = l->GetLeafCount()->GetBranch()->GetName(); if (type=="Float_t") { if (array) {brVFloat.push_back(bName); brVFloatCounter.push_back(counter); }else brFloat.push_back(bName);} else if (type=="Int_t") { if (array) {brVInt.push_back(bName); brVIntCounter.push_back(counter); }else brInt.push_back(bName);} else cout << "Unsupported branch type "<<type<<" for branch "<<bName<<". Skipping..."<<endl; } //treat counters as ints only AppendToListUniquely(brVIntCounter, brInt); AppendToListUniquely(brVFloatCounter, brInt); //too keep track of old branches, which cannot be read (todo: just check it...) int noldbrInt = brInt.size(), noldbrFloat = brFloat.size(), noldbrVInt = brVInt.size(), noldbrVIntCounter = brVIntCounter.size(), noldbrVFloat = brVFloat.size(), noldbrVFloatCounter = brVFloatCounter.size(); //add new branches ParseNewBranches(newbranches, brInt, brFloat, brVInt, brVIntCounter, brVFloat, brVFloatCounter); //print for debugging if (VERBOSE) { cout<<"int : "; for (auto s:brInt) cout <<s<<", "; cout<<endl; cout<<"float : "; for (auto s:brFloat) cout <<s<<", "; cout<<endl; cout<<"Vint : "; for (auto s:brVInt) cout <<s<<", "; cout<<endl; cout<<"Vfloat : "; for (auto s:brVFloat) cout <<s<<", "; cout<<endl; cout<<"Vintcnt : "; for (auto s:brVIntCounter) cout <<s<<", "; cout<<endl; cout<<"Vfloatcnt : "; for (auto s:brVFloatCounter) cout <<s<<", "; cout<<endl; } tjet->SetBranchStatus("*",1); for (auto b:brVFloat) if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,0); for (auto b:brFloat) if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,0); for (auto b:brVInt) if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,0); for (auto b:brInt) if (tjet->GetBranch(b)!=0) {unsigned f=0; tjet->SetBranchStatus(b,0,&f); if (VERBOSE) cout<<"turning off "<<b<<", found = "<<f<<endl;} TFile *fout = new TFile(fileOut,"recreate"); TTree *tjetout; //in case of one-to-many event - do not copy branches automatically! if (useOneToOne) tjetout = tjet->CloneTree(0); else tjetout = new TTree(tjet->GetName(),tjet->GetTitle()); //think about memory tree // tjetout->SetDirectory(0); tjetout->SetName(tjet->GetName()); //TTree *tjetout = new TTree("t","t"); //to see what is copied... //tjetout->Print(); for (auto b:brVFloat) if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,1); for (auto b:brFloat) if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,1); for (auto b:brVInt) if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,1); for (auto b:brInt) if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,1); vector<int> valIntIn(brInt.size()), valIntOut(brInt.size()); vector<float> valFloatIn(brFloat.size()), valFloatOut(brFloat.size()); vector<vector<int> >valVIntIn (brVInt.size()); vector<vector<int> >valVIntOut (brVInt.size()); vector<vector<float> >valVFloatIn (brVFloat.size()); vector<vector<float> >valVFloatOut (brVFloat.size()); for (unsigned i=0;i<brInt.size();i++) { if (tjet->GetBranch(brInt[i])!=0) tjet->SetBranchAddress(brInt[i],&valIntIn[i]); if (tjetout->GetBranch(brInt[i])!=0) {//why would it? tjetout->SetBranchAddress(brInt[i],&valIntOut[i]); cout<<"branch "<<brInt[i]<<" already exist for some reason..."<<endl; } else //logical... if (NonFriendBranch(tjet, brInt[i])) tjetout->Branch(brInt[i],&valIntOut[i],Form("%s/I",brInt[i].Data())); } for (unsigned i=0;i<brFloat.size();i++) { if (tjet->GetBranch(brFloat[i])!=0) tjet->SetBranchAddress(brFloat[i],&valFloatIn[i]); if (NonFriendBranch(tjet, brFloat[i])) tjetout->Branch(brFloat[i],&valFloatOut[i],Form("%s/F",brFloat[i].Data())); } for (unsigned i=0;i<brVFloat.size();i++) { if (tjet->GetBranch(brVFloat[i])!=0) { valVFloatIn[i] = vector<float>(NMAX); tjet->SetBranchAddress(brVFloat[i],&valVFloatIn[i][0]); } valVFloatOut[i] = vector<float>(NMAX); if (NonFriendBranch(tjet, brVFloat[i])) tjetout->Branch(brVFloat[i],&valVFloatOut[i][0],Form("%s[%s]/F",brVFloat[i].Data(),brVFloatCounter[i].Data())); } for (unsigned i=0;i<brVInt.size();i++) { if (tjet->GetBranch(brVInt[i])) { valVIntIn[i] = vector<int>(NMAX); tjet->SetBranchAddress(brVInt[i],&valVIntIn[i][0]); } valVIntOut[i] = vector<int>(NMAX); if (NonFriendBranch(tjet, brVInt[i])) tjetout->Branch(brVInt[i],&valVIntOut[i][0],Form("%s[%s]/I",brVInt[i].Data(),brVIntCounter[i].Data())); } Long64_t nentries = tjet->GetEntries(); int nentries1 = nentries/NPAR*jobid; int nentries2 = nentries/NPAR*(jobid+1); nentries = nentries2-nentries1; int oneperc = nentries/100; if (oneperc==0) oneperc = 1; cout<<"Start processing..."<<endl; TStopwatch s; s.Start(); TTimeStamp t0; double readTime = 0, processingTime = 0, copyToTime = 0, cloneTime=0, copyFromTime=0, fillTime = 0; for (Long64_t i=0; i<nentries;i++) { if (jobid==0 && i % oneperc == 0 && i>0) { std::cout << std::fixed; TTimeStamp t1; cout<<" \r"<<i/oneperc<<"% "<<" est. time "<<setprecision(2) <<(t1-t0)*nentries/(i+.1)<<" s "; cout<<";Processing:"<<setprecision(2)<<processingTime/(t1-t0)*100<<" %"; cout<<";Copy1:"<<setprecision(2) <<copyToTime/(t1-t0)*100<<" %"; cout<<";Clone:"<<setprecision(2) <<cloneTime/(t1-t0)*100<<" %"; cout<<";Copy2:"<<setprecision(2) <<copyFromTime/(t1-t0)*100<<" %"; cout<<";Fill:"<<setprecision(2) <<fillTime/(t1-t0)*100<<" %"; cout<<";Read:"<<setprecision(2) <<readTime/(t1-t0)*100<<" %"; cout<<flush; } TTimeStamp tsRead0; tjet->GetEntry(i+nentries1); TTimeStamp tsRead1; readTime+=tsRead1-tsRead0; Everything ev; TTimeStamp tsCpTo0; for (unsigned j=0;j<brInt.size();j++) ev.PutInt(brInt[j],valIntIn[j]); for (unsigned j=0;j<brFloat.size();j++) ev.PutFloat(brFloat[j],valFloatIn[j]); for (unsigned j=0;j<brVFloat.size();j++) ev.PutVFloat(brVFloat[j],brVFloatCounter[j],valVFloatIn[j]); for (unsigned j=0;j<brVInt.size();j++) ev.PutVInt(brVInt[j],brVIntCounter[j],valVIntIn[j]); TTimeStamp tsCpTo1; copyToTime+=tsCpTo1-tsCpTo0; TTimeStamp tsCl0; //think about: copy object (timing 10% ->3%) //but it copies vectors, so push_back will add in the end... // Everything evout = ev; //or even reference(in place?) (->0.2%) //Everything &evout = ev; Everything evout = ev.CloneStructure(); TTimeStamp tsCl1; cloneTime+=tsCl1-tsCl0; bool exitEvent = false; int counter = 0; while (!exitEvent) { TTimeStamp tsPr0; if (useOneToOne) { fProcessOneToOne(ev, evout); evout.UpdateCounters(); exitEvent = true; } else { exitEvent = fProcessOneToMany(ev, evout, counter); // if (!exitEvent) cout<<"event to write "<<counter<<endl; counter++; } TTimeStamp tsPr1; processingTime+=tsPr1-tsPr0; //Everything evout = ev; TTimeStamp tsCpFrom0; for (unsigned j=0;j<brInt.size();j++) valIntOut[j] = evout.GetInt(brInt[j]); for (unsigned j=0;j<brFloat.size();j++) {valFloatOut[j] = evout.GetFloat(brFloat[j]); // cout<<brFloat[j]<<" "<<evout.GetFloat(brFloat[j])<<endl; } for (unsigned j=0;j<brVFloat.size();j++) valVFloatOut[j] = evout[brVFloat[j]]; for (unsigned j=0;j<brVInt.size();j++) valVIntOut[j] = evout.GetVInt(brVInt[j]); TTimeStamp tsCpFrom1; copyFromTime+=tsCpFrom1-tsCpFrom0; TTimeStamp tsFill0; tjetout->Fill(); TTimeStamp tsFill1; fillTime+=tsFill1-tsFill0; } } cout<<endl; s.Stop(); cout<<"Done in ";s.Print(); tjetout->FlushBaskets(); tjetout->Write(); cout<<"Copying other trees..."<<endl; for (unsigned i=0;i<friendTrees.size();i++) { TTree *t = friendTrees[i]; if (sameFileFriend[i]) { //TTree *triendout = t->CloneTree(-1,"fast"); TTree *triendout = t->CopyTree("","",nentries,nentries1); triendout->Write(); } } fout->Close(); friendTrees.clear(); }
BCC::BCC(TString filename, std::vector<TString> vecPathnames, std::vector<TString> vecBranches, bool mergeLepHad, bool addCrossCheckVariables) { error_code = 0; // Please provide your own function 'makeVariableBinning' producing a std::map with your binning mapBinning = makeVariableBinning(addCrossCheckVariables); // Set variable 'largeMGFile', open file and get tree largeMGFile = (filename.Contains("Large")) ? 1 : 0; datafile = new TFile(filename,"READ"); // Local variables float tempData = 0; std::vector<double> vecBranchData; BCCMap mapTempData; if (datafile) { // fill data from tree into temporary map for (std::vector<TString>::iterator iterBranch = vecBranches.begin(); iterBranch != vecBranches.end(); iterBranch++) { datafile -> cd(vecPathnames[iterBranch-vecBranches.begin()]); TTree *treeData = (TTree*)gDirectory->Get("tree"); vecBranchData.clear(); std::cout << " Processing Data for .... " << filename << ": "; std::cout << vecPathnames.at(iterBranch-vecBranches.begin()) << "/" << *iterBranch << std::endl; TString activeBranchName = ""; activeBranchName = (*iterBranch); // for b-jet quantities: treat thm like had/lep altough their name does not contain these appendices activeBranchName.ReplaceAll("GenLep","Gen"); activeBranchName.ReplaceAll("GenHad","Gen"); if( activeBranchName.Contains("lepEtaMinus") || activeBranchName.Contains("lepEtaPlus")) activeBranchName="lepEta"; std::cout << " --> " << activeBranchName << std::endl; treeData->SetBranchStatus("*",0); treeData->SetBranchStatus(activeBranchName,1); treeData->SetBranchAddress(activeBranchName,(&tempData)); for (int j=0; j<treeData->GetEntries(); j++) { treeData->GetEntry(j); vecBranchData.push_back(tempData); } TString tempmapname=*iterBranch; tempmapname.ReplaceAll("bbarq","bq"); mapTempData[tempmapname] = vecBranchData; } vecBranchData.clear(); // Merge data for top- and antitop-quarks if no distinction between them is required if (mergeLepHad) { TString strNew, strHad, strLep; for (BCCMap::iterator iter = mapTempData.begin(); iter != mapTempData.end(); iter++) { vecBranchData.clear(); // Default values strHad = "DefaultHad"; strLep = "DefaultLep"; strNew = iter->first; vecBranchData = iter->second; //std::cout << "variable: " << strNew << std::endl; // Check if data belong to top -> bqq' if (iter != mapTempData.end() && iter->first.EndsWith("Had")) { strHad = (iter->first); strHad.ReplaceAll("Gen" ,""); //std::cout << "had identified: " << strHad << std::endl; iter++; } // Check if immediately following entry in map belongs to top -> blnu // This works because the map is sorted alphabetically -> must be reviewed and fixed if new a branch is added between topxxHad and topxxLep //std::cout << iter->first << std::endl; //std::cout << "if (iter != mapTempData.end())" << (iter != mapTempData.end()) << std::endl; //std::cout << "if (iter->first.EndsWith(\"Lep\")" << iter->first.EndsWith("Lep") << std::endl; if (iter != mapTempData.end() && iter->first.EndsWith("Lep")) { strLep = (iter->first); strLep.ReplaceAll("Gen" ,""); //std::cout << "lep identified: " << strLep << std::endl; } if (strHad != "DefaultHad" && strLep != "DefaultLep" && strHad(0,strHad.Length()-3) == strLep(0,strLep.Length()-3) ) { strNew = strHad(0,strHad.Length()-3); vecBranchData.insert(vecBranchData.end(),iter->second.begin(),iter->second.end()); //std::cout << "merging vectors " << std::endl; } mapData[strNew] = vecBranchData; } } if (mapBinning.size() != mapData.size() ) { error_code = -2; std::cout << " WARNING ---- Size of maps for binning and data do not correspond!" << std::endl; std::cout << " WARNING ---- Calculation of corrected bin centres will be suppressed." << std::endl; std::cout << " WARNING ---- Switch to geometrical centres as default values." << std::endl; std::cout << " data entries: " << std::endl; for (BCCMap::iterator iter = mapData.begin(); iter != mapData.end(); iter++) { std::cout << " " << iter->first << std::endl; } std::cout << " binning entries: " << std::endl; for (BCCMap::iterator iter = mapBinning.begin(); iter != mapBinning.end(); iter++) { std::cout << " " << iter->first << std::endl; } } else { for (BCCMap::iterator iter = mapData.begin(); iter != mapData.end(); iter++) std::cout << " Creating new branch .... " << iter->first << " with " << iter->second.size() << " entries." << std::endl; MakeHistos(); } } else { std::cout << "Input Data File not found. " << std::endl; error_code = -1; } }
void FitterUtils::prepare_PDFs(string trigStr, string BDTVar, double BDTcut, string signalfile, string partrecofile, string combfile, string JpsiLeakfile, double minBMass, double maxBMass, string signaltree, string partrecotree, string combtree, string JpsiLeaktree) { //***********Get the datasets TFile* fSignal = new TFile(signalfile.c_str()); TTree* tSignal = (TTree*)fSignal->Get(signaltree.c_str()); TFile* fPartReco = new TFile(partrecofile.c_str()); TTree* tPartReco = (TTree*)fPartReco->Get(partrecotree.c_str()); TFile* fComb = new TFile(combfile.c_str()); TTree* tComb = (TTree*)fComb->Get(combtree.c_str()); TFile* fJpsiLeak = new TFile(JpsiLeakfile.c_str()); TTree* tJpsiLeak = (TTree*)fJpsiLeak->Get(JpsiLeaktree.c_str()); //**********Define variables RooRealVar trigVar(trigStr.c_str(), trigStr.c_str(), -10, 10); RooRealVar BDTRooRealVar(BDTVar.c_str(), BDTVar.c_str(), -1,1); RooRealVar B_plus_M("B_plus_M", "M_{visible}", minBMass, maxBMass, "MeV"); RooRealVar misPT("misPT", "p_{#perp}", 0, 5000, "MeV"); RooRealVar B_plus_DTFM_M_zero("B_plus_DTFM_M_zero", "M_{constr}", 0, 20000, "MeV"); RooRealVar e_plus_BremMultiplicity("e_plus_BremMultiplicity","e_plus_BremMultiplicity", -1,2); RooRealVar e_minus_BremMultiplicity("e_minus_BremMultiplicity","e_minus_BremMultiplicity", -1,2); RooRealVar weightPartReco("weightPartReco", "weightPartReco", 0, 10); RooRealVar weightLeakage("weightLeakage", "weightLeakage", 0, 10); RooRealVar dataMCWeightee("DataMCWeightee", "DataMCWeightee",0, 30); //***********Set only variables needed tSignal->SetBranchStatus("*", 0); tSignal->SetBranchStatus("B_plus_M", 1); tSignal->SetBranchStatus("misPT", 1); tSignal->SetBranchStatus("B_plus_DTFM_M_zero", 1); tSignal->SetBranchStatus(BDTVar.c_str(),1); tSignal->SetBranchStatus("e_plus_BremMultiplicity", 1); tSignal->SetBranchStatus("e_minus_BremMultiplicity", 1); tSignal->SetBranchStatus(trigStr.c_str()); tSignal->SetBranchStatus("DataMCWeightee",1); tPartReco->SetBranchStatus("*", 0); tPartReco->SetBranchStatus("B_plus_M", 1); tPartReco->SetBranchStatus("misPT", 1); tPartReco->SetBranchStatus("B_plus_DTFM_M_zero", 1);tPartReco->SetBranchStatus(BDTVar.c_str(),1); tPartReco->SetBranchStatus("e_plus_BremMultiplicity", 1); tPartReco->SetBranchStatus("e_minus_BremMultiplicity", 1); tPartReco->SetBranchStatus(trigStr.c_str()); tPartReco->SetBranchStatus("weightPartReco",1); tComb->SetBranchStatus("*", 0); tComb->SetBranchStatus("B_plus_M", 1); tComb->SetBranchStatus("misPT", 1); tComb->SetBranchStatus("B_plus_DTFM_M_zero", 1);tComb->SetBranchStatus(BDTVar.c_str(),1); tComb->SetBranchStatus("e_plus_BremMultiplicity", 1); tComb->SetBranchStatus("e_minus_BremMultiplicity", 1); tComb->SetBranchStatus(trigStr.c_str()); tJpsiLeak->SetBranchStatus("*", 0); tJpsiLeak->SetBranchStatus("B_plus_M", 1); tJpsiLeak->SetBranchStatus("misPT", 1); tJpsiLeak->SetBranchStatus("B_plus_DTFM_M_zero", 1);tJpsiLeak->SetBranchStatus(BDTVar.c_str(),1); tJpsiLeak->SetBranchStatus("e_plus_BremMultiplicity", 1); tJpsiLeak->SetBranchStatus("e_minus_BremMultiplicity", 1); tJpsiLeak->SetBranchStatus(trigStr.c_str()); tJpsiLeak->SetBranchStatus("weightLeakage",1); //***********Set Binning RooBinning defaultMBins(floor((maxBMass-minBMass)/(40.)), B_plus_M.getMin(), B_plus_M.getMax() ); RooBinning defaultMisPTBins(floor(40), misPT.getMin(), misPT.getMax()); RooBinning broaderMBins(floor((maxBMass-minBMass)/(80.)), B_plus_M.getMin(), B_plus_M.getMax()); RooBinning broaderMisPTBins(floor(40), misPT.getMin(), misPT.getMax()); B_plus_M.setBinning( defaultMBins); misPT.setBinning( defaultMisPTBins ); B_plus_M.setBinning( broaderMBins, "broaderBins"); misPT.setBinning( broaderMisPTBins, "broaderBins" ); B_plus_DTFM_M_zero.setBins(100); RooArgSet argset(BDTRooRealVar, B_plus_DTFM_M_zero, misPT, B_plus_M, trigVar, e_plus_BremMultiplicity, e_minus_BremMultiplicity); RooArgSet argsetPartReco(BDTRooRealVar, B_plus_DTFM_M_zero, misPT, B_plus_M, trigVar, e_plus_BremMultiplicity, e_minus_BremMultiplicity, weightPartReco); RooArgSet argsetLeakage(BDTRooRealVar, B_plus_DTFM_M_zero, misPT, B_plus_M, trigVar, e_plus_BremMultiplicity, e_minus_BremMultiplicity, weightLeakage); RooArgSet argsetSignal(BDTRooRealVar, B_plus_DTFM_M_zero, misPT, B_plus_M, trigVar, e_plus_BremMultiplicity, e_minus_BremMultiplicity, dataMCWeightee); cout<<"getting the datasets:"<<endl; RooDataSet* dataSetSignalZeroGamma; RooDataSet* dataSetSignalOneGamma; RooDataSet* dataSetSignalTwoGamma; RooDataSet* dataSetPartReco; RooDataSet* dataSetJpsiLeak; RooDataSet* dataSetComb; TFile* fw(NULL); string BDTCutString( ("("+BDTVar+">"+d2s(BDTcut)+")").c_str() ); dataSetSignalZeroGamma = new RooDataSet("dataSetSignalZeroGamma", "dataSetSignalZeroGamma", argsetSignal, Import(*tSignal), Cut(( " ("+trigStr+" > 0.9) && "+BDTCutString+" && ((e_plus_BremMultiplicity+e_minus_BremMultiplicity) > -0.5) && ((e_plus_BremMultiplicity+e_minus_BremMultiplicity) < 0.5) && B_plus_M > "+d2s(minBMass)+" && B_plus_M < "+d2s(maxBMass)).c_str()), WeightVar("DataMCWeightee") ); dataSetSignalOneGamma = new RooDataSet("dataSetSignalOneGamma", "dataSetSignalOneGamma", argsetSignal, Import(*tSignal), Cut(( " ("+trigStr+" > 0.9) && "+BDTCutString+" && ((e_plus_BremMultiplicity+e_minus_BremMultiplicity) > 0.5) && ((e_plus_BremMultiplicity+e_minus_BremMultiplicity) < 1.5) && B_plus_M > "+d2s(minBMass)+" && B_plus_M < "+d2s(maxBMass)).c_str()), WeightVar("DataMCWeightee") ); dataSetSignalTwoGamma = new RooDataSet("dataSetSignalTwoGamma", "dataSetSignalTwoGamma", argsetSignal, Import(*tSignal), Cut(( " ("+trigStr+" > 0.9) && "+BDTCutString+" && ((e_plus_BremMultiplicity+e_minus_BremMultiplicity) > 1.5) && ((e_plus_BremMultiplicity+e_minus_BremMultiplicity) < 2.5) && B_plus_M > "+d2s(minBMass)+" && B_plus_M < "+d2s(maxBMass)).c_str()), WeightVar("DataMCWeightee") ); dataSetPartReco = new RooDataSet("dataSetPartReco", "dataSetPartReco", argsetPartReco, Import(*tPartReco),Cut(("("+trigStr+" > 0.9) && "+BDTCutString+ " && B_plus_M > "+d2s(minBMass)+" && B_plus_M < "+d2s(maxBMass)).c_str()), WeightVar("weightPartReco")); dataSetJpsiLeak = new RooDataSet("dataSetJpsiLeak", "dataSetJpsiLeak", argsetLeakage, Import(*tJpsiLeak),Cut(("B_plus_M > "+d2s(minBMass)+" && B_plus_M < "+d2s(maxBMass)).c_str()), WeightVar("weightLeakage")); // dataSetComb = new RooDataSet("dataSetComb", "dataSetComb", tComb, argset, ("("+trigStr+" > 0.9) && (UBDT3R > "+d2s(BDTcut-0.03)+") && B_plus_M > "+d2s(minBMass)+" && B_plus_M < "+d2s(maxBMass)).c_str()); dataSetComb = new RooDataSet("dataSetComb", "dataSetComb", tComb, argset, ("("+trigStr+" > 0.9) && "+BDTCutString+" && B_plus_M > "+d2s(minBMass)+" && B_plus_M < "+d2s(maxBMass)).c_str()); cout<<"Number of zero: "<< dataSetSignalZeroGamma->sumEntries()<<endl; cout<<"Number of one: "<< dataSetSignalOneGamma->sumEntries()<<endl; cout<<"Number of two: "<< dataSetSignalTwoGamma->sumEntries()<<endl; cout<<"Number of PartReco: "<< dataSetPartReco->sumEntries()<<endl; cout<<"Number of Jpsi leaking:"<< dataSetJpsiLeak->sumEntries()<<endl; cout<<"Number of combinatorial events:"<< dataSetComb->sumEntries()<<endl; cout<<"binning the datasets:"<<endl; RooArgSet argset2(B_plus_M); if (fit2D) argset2.add(misPT); RooDataHist dataHistSignalZeroGamma("dataHistSignalZeroGamma", "dataHistSignalZeroGamma", argset2, *dataSetSignalZeroGamma); RooDataHist dataHistSignalOneGamma("dataHistSignalOneGamma", "dataHistSignalOneGamma", argset2, *dataSetSignalOneGamma); RooDataHist dataHistSignalTwoGamma("dataHistSignalTwoGamma", "dataHistSignalTwoGamma", argset2, *dataSetSignalTwoGamma); RooDataHist dataHistComb("dataHistComb", "dataHistComb", argset2, *dataSetComb); RooDataHist dataHistPartReco("dataHistPartReco", "dataHistPartReco", argset2, *dataSetPartReco); RooDataHist dataHistJpsiLeak("dataHistJpsiLeak", "dataHistJpsiLeak", argset2, "broaderBins"); dataHistJpsiLeak.add(*dataSetJpsiLeak); //*************** Compute Error on J/psi leak double ErrorJpsi(0); if(dataSetJpsiLeak->sumEntries(("("+trigStr+" > 0.9) && "+BDTCutString+" && B_plus_M > "+d2s(minBMass)+" && B_plus_M < "+d2s(maxBMass)).c_str()) > 0) ErrorJpsi = 1./sqrt(dataSetJpsiLeak->sumEntries(("("+trigStr+" > 0.9) && "+BDTCutString+" && B_plus_M > "+d2s(minBMass)+" && B_plus_M < "+d2s(maxBMass)).c_str())); RooRealVar fractionalErrorJpsiLeak("fractionalErrorJpsiLeak", "fractionalErrorJpsiLeak", ErrorJpsi); cout<<"JPSI LEAK: "<<dataSetJpsiLeak->sumEntries(("("+trigStr+" > 0.9) && "+BDTCutString+" && B_plus_M > "+d2s(minBMass)+" && B_plus_M < "+d2s(maxBMass)).c_str()); cout<<"JPSI LEAK fractional Error: "<<ErrorJpsi<<endl; //***************Create 2D histogram estimates from data cout<<"Preparing the 3 2D histPdf: 1"; // RooArgSet argset2(B_plus_M); RooHistPdf histPdfSignalZeroGamma("histPdfSignalZeroGamma", "histPdfSignalZeroGamma", argset2, dataHistSignalZeroGamma,2); cout<<" 2"; RooHistPdf histPdfSignalOneGamma("histPdfSignalOneGamma", "histPdfSignalOneGamma", argset2, dataHistSignalOneGamma,2); cout<<" 3"; RooHistPdf histPdfSignalTwoGamma("histPdfSignalTwoGamma", "histPdfSignalTwoGamma", argset2, dataHistSignalTwoGamma,2); cout<<" 4"; RooHistPdf histPdfPartReco("histPdfPartReco", "histPdfPartReco", argset2, dataHistPartReco,2); cout<<" 5"; RooHistPdf histPdfJpsiLeak("histPdfJpsiLeak", "histPdfJpsiLeak", argset2, dataHistJpsiLeak,2); cout<<" 6"; //***************Create combinatorial from fit to data RooRealVar expoConst("expoConst", "expoConst", -1e-3, -1, 1); RooRealVar T("T", "T", 97, 0, 200); RooRealVar n("n", "n", 3.5, 1., 5.5); RooAbsPdf *combPDF; if (fit2D) { combPDF = new RooPTMVis("PTMVis", "PTMVis", misPT, B_plus_M, T, n, expoConst); } else { combPDF = new RooExponential("histPdfComb", "histPdfComb", B_plus_M, expoConst); } combPDF->fitTo(*dataSetComb); // if (fit2D) { T.setConstant(true); n.setConstant(true); std::cout<<"T generated is: "<<T.getVal()<<std::endl; } RooRealVar trueExp("trueExp","trueExp", expoConst.getVal(), -1000, 1000); trueExp.setError(expoConst.getError()); RooRealVar trueT("trueT","trueT", T.getVal(), -1000, 1000); trueT.setError(T.getError()); RooRealVar trueN("trueN","trueN", n.getVal(), -1000, 1000); trueN.setError(n.getError()); //***************Save everything on a workspace RooWorkspace workspace("workspace", "workspace"); workspace.import(B_plus_DTFM_M_zero); workspace.import(B_plus_M); workspace.import(misPT); workspace.import(expoConst); workspace.import(trueExp); workspace.import(T); workspace.import(n); workspace.import(*dataSetSignalZeroGamma); workspace.import(*dataSetSignalOneGamma); workspace.import(*dataSetSignalTwoGamma); workspace.import(*dataSetPartReco); workspace.import(*dataSetComb); workspace.import(*dataSetJpsiLeak); workspace.import(histPdfSignalZeroGamma); workspace.import(histPdfSignalOneGamma); workspace.import(histPdfSignalTwoGamma); workspace.import(histPdfPartReco); workspace.import(histPdfJpsiLeak); workspace.import(fractionalErrorJpsiLeak); workspace.import(trueT); workspace.import(trueN); workspace.writeToFile(workspacename.c_str()); delete fComb; delete fSignal; delete fPartReco; if(fw!=0 && fw != NULL) delete fw; delete combPDF; delete dataSetSignalZeroGamma; delete dataSetSignalOneGamma; delete dataSetSignalTwoGamma; delete dataSetPartReco; delete dataSetJpsiLeak; delete dataSetComb; }
void UpsCheck() { TFile *file = TFile::Open("/scratch_rigel/CMSTrees/PbPb_Data/MegaTree/OniaTree_MEGA_Peripheral30100_PromptReco_262548_263757.root"); //Track Tree Set Up TTree *trackTree = (TTree*)file->Get("anaTrack/trackTree"); trackTree->SetBranchStatus("*",0); trackTree->SetBranchStatus("nLumi", 1); trackTree->SetBranchStatus("nTrk", 1); trackTree->SetBranchStatus("trkPt", 1); trackTree->SetBranchStatus("trkEta", 1); trackTree->SetBranchStatus("trkPhi", 1); trackTree->SetBranchStatus("trkCharge", 1); trackTree->SetBranchStatus("nEv", 1); Int_t Lumi, nTrk, event; Float_t eta[9804]; Float_t phi[9804]; Int_t charge[9804]; Float_t pT[9804]; trackTree->SetBranchAddress("nLumi", &Lumi); trackTree->SetBranchAddress("nTrk", &nTrk); trackTree->SetBranchAddress("trkPt", pT); trackTree->SetBranchAddress("trkEta", eta); trackTree->SetBranchAddress("trkPhi", phi); trackTree->SetBranchAddress("trkCharge", charge); trackTree->SetBranchAddress("nEv", &event); //Dimuon Tree Set Up TTree *myTree = (TTree*)file->Get("hionia/myTree"); myTree->SetBranchStatus("*",0); myTree->SetBranchStatus("Reco_QQ_4mom",1); myTree->SetBranchStatus("Reco_QQ_mupl_4mom",1); myTree->SetBranchStatus("Reco_QQ_mumi_4mom",1); myTree->SetBranchStatus("Reco_QQ_size",1); myTree->SetBranchStatus("Centrality",1); myTree->SetBranchStatus("HLTriggers",1); myTree->SetBranchStatus("Reco_QQ_trig",1); myTree->SetBranchStatus("Reco_QQ_sign",1); TClonesArray *Reco_QQ_4mom=0; TClonesArray *Reco_QQ_mupl_4mom=0; TClonesArray *Reco_QQ_mumi_4mom=0; TLorentzVector *dimuon; TLorentzVector *mumi; TLorentzVector *mupl; double events=0; events = myTree->GetEntries(); cout << events << endl; Int_t QQsize=0; Int_t Centrality=0; ULong64_t HLTrigger=0; ULong64_t Reco_QQ_trig[21]; Int_t Reco_QQ_sign[21]; myTree->SetBranchAddress("Centrality",&Centrality); myTree->SetBranchAddress("HLTriggers",&HLTrigger); myTree->SetBranchAddress("Reco_QQ_4mom",&Reco_QQ_4mom); myTree->SetBranchAddress("Reco_QQ_mupl_4mom", &Reco_QQ_mupl_4mom); myTree->SetBranchAddress("Reco_QQ_mumi_4mom", &Reco_QQ_mumi_4mom); myTree->SetBranchAddress("Reco_QQ_size", &QQsize); myTree->SetBranchAddress("Reco_QQ_trig", Reco_QQ_trig); myTree->SetBranchAddress("Reco_QQ_sign", Reco_QQ_sign); //Histogram Initialization TH1D* phidiffmid = new TH1D( "phidiffmid", "#Delta#phi for mid mass band (9.0-9.8 GeV)",128,0,3.2); TH1D* rapdiffmid = new TH1D( "rapdiffmid", "#Delta#eta for mid mass band (9.0-9.8 GeV)",200,-5, 5); TH2D* midmass = new TH2D("midmass","#Delta#phi vs #Delta#eta for mid mass band",128,0,3.2,200,-5,5); //Event Loop int test = 0; int mid = 0; int index = 0; for(int i = 0; i < trackTree->GetEntries(); i++) { trackTree->GetEntry(i); myTree->GetEntry(i); if(Centrality > 140) { if((HLTrigger&128) == 128 || (HLTrigger&256) == 256) { for(Int_t j=0; j < QQsize; j++) { dimuon = (TLorentzVector*)Reco_QQ_4mom->At(j); mumi = (TLorentzVector*)Reco_QQ_mumi_4mom->At(j); mupl = (TLorentzVector*)Reco_QQ_mupl_4mom->At(j); if(((Reco_QQ_trig[j]&128) == 128 || (Reco_QQ_trig[j]&256) == 256) && Reco_QQ_sign[j] == 0) { if(mumi->Pt() > 4 && mupl->Pt() > 4 && TMath::Abs(mumi->Eta()) < 2.4 && TMath::Abs(mupl->Eta()) < 2.4 ) { index++; if(dimuon->M() > 9.3 && dimuon->M() < 9.6) { test++; for(Int_t k=0; k < nTrk; k++) { if(TMath::Abs(eta[k]) < 2.4 && pT[k] > .1 && TMath::Abs(charge[k]) == 1) { if(TMath::Abs(dimuon->Phi() - phi[k]) > 3.1416) { phidiffmid->Fill(6.2832-TMath::Abs(phi[k]-dimuon->Phi())); rapdiffmid->Fill(eta[k] - dimuon->Rapidity()); midmass->Fill(6.2832-TMath::Abs(phi[k]-dimuon->Phi()),eta[k]-dimuon->Rapidity()); } if(TMath::Abs(dimuon->Phi() - phi[k]) <= 3.1416) { phidiffmid->Fill(TMath::Abs(phi[k] - dimuon->Phi())); rapdiffmid->Fill(eta[k]-dimuon->Rapidity()); midmass->Fill(TMath::Abs(phi[k]-dimuon->Phi()),eta[k]-dimuon->Rapidity()); } } } } } } } } } } TFile out("EtaPhiMidCent.root", "RECREATE"); phidiffmid->Write(); rapdiffmid->Write(); midmass->Write(); out.Close(); cout << "Done! " << test << " Total Dimuons: " << index <<endl; cout << "Mid: " << mid << endl; return; }
void skimDistr() { const string inDir = "/home/ieeya/Downloads/HLT_Val/dev/e_74x/file/v15p1/"; const string outputFile = "skim_dat.root"; Bool_t hasReco = false; TFile* out_file = new TFile((inDir + outputFile).c_str(), "recreate"); TTree* out_tree = new TTree("eleDistr", "eleDistr"); out_tree->SetAutoSave(25000000); Int_t cand, npf, hlt_n, reco_n, nvtx, gpn, itype, pass[10], mishitspf[10], reco_mishits[10]; Float_t rho, puWgt, weight, epf[10], eRawpf[10], etpf[10], etRawpf[10], etapf[10], phipf[10], sieiepf[10]; Float_t ecalpf[10], dphipf[10], detapf[10], detaseedpf[10], hoepf[10], hcalpf[10]; Float_t tkisopf[10], eoppf[10], gppt[10], gpeta[10], gpphi[10], chi2pf[10]; Float_t reco_e[10], reco_et[10], reco_eRaw[10], reco_etRaw[10], reco_pt[10], reco_eta[10], reco_phi[10]; Float_t reco_sieie[10], reco_hoe[10], reco_ecal[10], reco_dphi[10], reco_deta[10], reco_detaseed[10]; Float_t reco_hcal[10], reco_tkiso[10], reco_eop[10], reco_chi2[10]; Float_t hlt_e[10], hlt_er[10], hlt_et[10], hlt_etr[10], hlt_eta[10], hlt_phi[10], hlt_hoe[10]; Float_t hlt_sie[10], hlt_dph[10], hlt_det[10], hlt_des[10], hlt_eop[10], hlt_chi[10], hlt_mih[10]; Float_t hlt_eca[10], hlt_ecc[10], hlt_ecu[10], hlt_hca[10], hlt_hcc[10], hlt_hcu[10], hlt_tki[10]; Float_t reco_er[10], reco_etr[10], reco_sie[10], reco_dph[10], reco_det[10], reco_des[10]; Float_t reco_eca[10], reco_ecu[10], reco_hca[10], reco_hcu[10], reco_tki[10], reco_chi[10], reco_mih[10]; out_tree->Branch("nvtx", &nvtx, "nvtx/I"); out_tree->Branch("rho" , &rho, "rho/F"); out_tree->Branch("puWgt", &puWgt, "puWgt/F"); out_tree->Branch("hlt_n" , &hlt_n, "hlt_n/I"); out_tree->Branch("hlt_e" , hlt_e, "hlt_e[hlt_n]/F"); out_tree->Branch("hlt_er" , hlt_er, "hlt_er[hlt_n]/F"); out_tree->Branch("hlt_et" , hlt_et, "hlt_et[hlt_n]/F"); out_tree->Branch("hlt_etr" , hlt_etr, "hlt_etr[hlt_n]/F"); out_tree->Branch("hlt_eta" , hlt_eta, "hlt_eta[hlt_n]/F"); out_tree->Branch("hlt_phi" , hlt_phi, "hlt_phi[hlt_n]/F"); out_tree->Branch("hlt_sie", hlt_sie, "hlt_sie[hlt_n]/F"); out_tree->Branch("hlt_eca" , hlt_eca, "hlt_eca[hlt_n]/F"); out_tree->Branch("hlt_ecc" , hlt_ecc, "hlt_ecc[hlt_n]/F"); out_tree->Branch("hlt_ecu" , hlt_ecu, "hlt_ecu[hlt_n]/F"); out_tree->Branch("hlt_dph" , hlt_dph, "hlt_dph[hlt_n]/F"); out_tree->Branch("hlt_det" , hlt_det, "hlt_det[hlt_n]/F"); out_tree->Branch("hlt_des" , hlt_des, "hlt_des[hlt_n]/F"); out_tree->Branch("hlt_hoe" , hlt_hoe, "hlt_hoe[hlt_n]/F"); out_tree->Branch("hlt_hca" , hlt_hca, "hlt_hca[hlt_n]/F"); out_tree->Branch("hlt_hcc" , hlt_hcc, "hlt_hcc[hlt_n]/F"); out_tree->Branch("hlt_hcu" , hlt_hcu, "hlt_hcu[hlt_n]/F"); out_tree->Branch("hlt_tki", hlt_tki, "hlt_tki[hlt_n]/F"); out_tree->Branch("hlt_eop" , hlt_eop, "hlt_eop[hlt_n]/F"); out_tree->Branch("hlt_chi" , hlt_chi, "hlt_chi[hlt_n]/F"); out_tree->Branch("hlt_mih" , hlt_mih, "hlt_mih[hlt_n]/F"); out_tree->Branch("pass_hlt" , pass, "pass_hlt[hlt_n]/I"); out_tree->Branch("itype" , &itype, "itype/I"); out_tree->Branch("weight" , &weight, "weight/F"); if (hasReco) { out_tree->Branch("reco_n" , &reco_n, "reco_n/I"); out_tree->Branch("reco_e" , reco_e, "reco_e[reco_n]/F"); out_tree->Branch("reco_et" , reco_et, "reco_et[reco_n]/F"); out_tree->Branch("reco_er" , reco_er, "reco_er[reco_n]/F"); out_tree->Branch("reco_etr" , reco_etr, "reco_etr[reco_n]/F"); out_tree->Branch("reco_pt" , reco_pt, "reco_pt[reco_n]/F"); out_tree->Branch("reco_eta" , reco_eta, "reco_eta[reco_n]/F"); out_tree->Branch("reco_phi" , reco_phi, "reco_phi[reco_n]/F"); out_tree->Branch("reco_sie", reco_sie, "reco_sie[reco_n]/F"); out_tree->Branch("reco_eca" , reco_eca, "reco_eca[reco_n]/F"); out_tree->Branch("reco_ecu" , reco_ecu, "reco_ecu[reco_n]/F"); out_tree->Branch("reco_dph" , reco_dph, "reco_dph[reco_n]/F"); out_tree->Branch("reco_det" , reco_det, "reco_det[reco_n]/F"); out_tree->Branch("reco_des" , reco_des, "reco_des[reco_n]/F"); out_tree->Branch("reco_hoe" , reco_hoe, "reco_hoe[reco_n]/F"); out_tree->Branch("reco_hca" , reco_hca, "reco_hca[reco_n]/F"); out_tree->Branch("reco_hcu" , reco_hcu, "reco_hcu[reco_n]/F"); out_tree->Branch("reco_tki", reco_tki, "reco_tki[reco_n]/F"); out_tree->Branch("reco_eop" , reco_eop, "reco_eop[reco_n]/F"); out_tree->Branch("reco_chi" , reco_chi, "reco_chi[reco_n]/F"); out_tree->Branch("reco_mih" , reco_mih, "reco_mih[reco_n]/F"); } // MC vs data: weight = xsec_mc * intLumi_dat / nEvt_mc const int proc = 1; const int type[proc] = {1}; const float weights[proc] = {1.}; const char* names[proc] = {"ntup_dat_00.root"}; //const Int_t proc = 2; //const Int_t type[proc] = {-1, -2}; //const Float_t weights[proc] = {1., 1.}; //const char* names[proc] = {"ntup_mcStd.root", "ntup_mcHFFlat.root"}; //const int proc = 1; //const int type[proc] = {1}; //const float weights[proc] = {1.}; //const char* names[proc] = {"reco_pts2c1.root"}; for (Int_t nfiles = 0; nfiles < proc; nfiles++) { TFile* file = TFile::Open((inDir + names[nfiles]).c_str()); TTree* inputTree = (TTree*)file->Get("tree"); inputTree->SetBranchStatus("*" , 0); inputTree->SetBranchStatus("npf" , 1); inputTree->SetBranchStatus("nvtx" , 1); inputTree->SetBranchStatus("rho" , 1); //inputTree->SetBranchStatus("puWgt" , 1); inputTree->SetBranchStatus("epf" , 1); inputTree->SetBranchStatus("eRawpf" , 1); inputTree->SetBranchStatus("etpf" , 1); inputTree->SetBranchStatus("etRawpf" , 1); inputTree->SetBranchStatus("etapf" , 1); inputTree->SetBranchStatus("phipf" , 1); inputTree->SetBranchStatus("sieiepf" , 1); inputTree->SetBranchStatus("ecalpf" , 1); inputTree->SetBranchStatus("dphipf" , 1); inputTree->SetBranchStatus("detapf" , 1); inputTree->SetBranchStatus("detaseedpf" , 1); inputTree->SetBranchStatus("hoepf" , 1); inputTree->SetBranchStatus("hcalpf" , 1); inputTree->SetBranchStatus("tkisopf" , 1); inputTree->SetBranchStatus("eoppf" , 1); inputTree->SetBranchStatus("chi2pf" , 1); inputTree->SetBranchStatus("mishitspf" , 1); inputTree->SetBranchAddress("npf" , &npf); inputTree->SetBranchAddress("nvtx" , &nvtx); inputTree->SetBranchAddress("rho" , &rho); //inputTree->SetBranchAddress("puWgt" , &puWgt); inputTree->SetBranchAddress("epf" , epf); inputTree->SetBranchAddress("eRawpf" , eRawpf); inputTree->SetBranchAddress("etpf" , etpf); inputTree->SetBranchAddress("etRawpf" , etRawpf); inputTree->SetBranchAddress("etapf" , etapf); inputTree->SetBranchAddress("phipf" , phipf); inputTree->SetBranchAddress("sieiepf" , sieiepf); inputTree->SetBranchAddress("ecalpf" , ecalpf); inputTree->SetBranchAddress("dphipf" , dphipf); inputTree->SetBranchAddress("detapf" , detapf); inputTree->SetBranchAddress("detaseedpf" , detaseedpf); inputTree->SetBranchAddress("hoepf" , hoepf); inputTree->SetBranchAddress("hcalpf" , hcalpf); inputTree->SetBranchAddress("tkisopf" , tkisopf); inputTree->SetBranchAddress("eoppf" , eoppf); inputTree->SetBranchAddress("chi2pf" , chi2pf); inputTree->SetBranchAddress("mishitspf" , mishitspf); if (hasReco) { inputTree->SetBranchStatus("reco_n" , 1); inputTree->SetBranchStatus("reco_e" , 1); inputTree->SetBranchStatus("reco_et" , 1); inputTree->SetBranchStatus("reco_eRaw" , 1); inputTree->SetBranchStatus("reco_etRaw" , 1); inputTree->SetBranchStatus("reco_pt" , 1); inputTree->SetBranchStatus("reco_eta" , 1); inputTree->SetBranchStatus("reco_phi" , 1); inputTree->SetBranchStatus("reco_sieie" , 1); inputTree->SetBranchStatus("reco_ecal" , 1); inputTree->SetBranchStatus("reco_dphi" , 1); inputTree->SetBranchStatus("reco_deta" , 1); inputTree->SetBranchStatus("reco_detaseed" , 1); inputTree->SetBranchStatus("reco_hoe" , 1); inputTree->SetBranchStatus("reco_hcal" , 1); inputTree->SetBranchStatus("reco_tkiso" , 1); inputTree->SetBranchStatus("reco_eop" , 1); inputTree->SetBranchStatus("reco_chi2" , 1); inputTree->SetBranchStatus("reco_mishits" , 1); inputTree->SetBranchAddress("reco_n" , &reco_n); inputTree->SetBranchAddress("reco_e" , reco_e); inputTree->SetBranchAddress("reco_et" , reco_et); inputTree->SetBranchAddress("reco_eRaw" , reco_eRaw); inputTree->SetBranchAddress("reco_etRaw" , reco_etRaw); inputTree->SetBranchAddress("reco_pt" , reco_pt); inputTree->SetBranchAddress("reco_eta" , reco_eta); inputTree->SetBranchAddress("reco_phi" , reco_phi); inputTree->SetBranchAddress("reco_sieie" , reco_sieie); inputTree->SetBranchAddress("reco_ecal" , reco_ecal); inputTree->SetBranchAddress("reco_dphi" , reco_dphi); inputTree->SetBranchAddress("reco_deta" , reco_deta); inputTree->SetBranchAddress("reco_detaseed" , reco_detaseed); inputTree->SetBranchAddress("reco_hoe" , reco_hoe); inputTree->SetBranchAddress("reco_hcal" , reco_hcal); inputTree->SetBranchAddress("reco_tkiso" , reco_tkiso); inputTree->SetBranchAddress("reco_eop" , reco_eop); inputTree->SetBranchAddress("reco_chi2" , reco_chi2); inputTree->SetBranchAddress("reco_mishits" , reco_mishits); } Int_t entries = inputTree->GetEntries(); for (Int_t z = 0; z < entries; z++) { inputTree->GetEntry(z); itype = type[nfiles]; weight = weights[nfiles]; puWgt = 1.; cand = 0; for (Int_t i = 0; i < npf; i++) { if(!notFake(sieiepf[i], (hoepf[i] / epf[i]), (ecalpf[i] / etpf[i]), (hcalpf[i] / etpf[i]), eoppf[i], chi2pf[i], (Float_t) mishitspf[i], detapf[i], dphipf[i], (tkisopf[i] / etpf[i]))) continue; pass[cand] = 0; hlt_e[cand] = epf[i]; hlt_er[cand] = eRawpf[i]; hlt_et[cand] = etpf[i]; hlt_etr[cand] = etRawpf[i]; hlt_eta[cand] = etapf[i]; hlt_phi[cand] = phipf[i]; hlt_sie[cand] = sieiepf[i]; hlt_ecc[cand] = ecalpf[i] / etpf[i]; hlt_dph[cand] = dphipf[i]; hlt_det[cand] = detapf[i]; hlt_des[cand] = detaseedpf[i]; hlt_hoe[cand] = hoepf[i] / epf[i]; hlt_hcc[cand] = hcalpf[i] / etpf[i]; hlt_tki[cand] = tkisopf[i] / etpf[i]; hlt_eop[cand] = eoppf[i]; hlt_chi[cand] = chi2pf[i]; hlt_mih[cand] = (Float_t) mishitspf[i]; if (fabs(hlt_eta[cand]) < 1.4791) { if(barWPLoose(hlt_sie[cand], hlt_hoe[cand], hlt_ecc[cand], hlt_hcc[cand], hlt_eop[cand], hlt_chi[cand], hlt_mih[cand], hlt_det[cand], hlt_dph[cand], hlt_tki[cand])) pass[cand] = 1; // Recompute the non-corr iso hlt_ecu[cand] = (ecalpf[i] + (0.16544 * rho)) / etpf[i]; hlt_hcu[cand] = (hcalpf[i] + (0.05956 * rho)) / etpf[i]; } else if (fabs(hlt_eta[cand]) >= 1.4791) { if(endWPLoose(hlt_sie[cand], hlt_hoe[cand], hlt_ecc[cand], hlt_hcc[cand], hlt_eop[cand], hlt_chi[cand], hlt_mih[cand], hlt_det[cand], hlt_dph[cand], hlt_tki[cand])) pass[cand] = 1; // Recompute the non-corr iso hlt_ecu[cand] = (ecalpf[i] + (0.13212 * rho)) / etpf[i]; hlt_hcu[cand] = (hcalpf[i] + (0.13052 * rho)) / etpf[i]; } hlt_eca[cand] = hlt_ecc[cand] * etpf[i]; hlt_hca[cand] = hlt_hcc[cand] * etpf[i]; cand++; } hlt_n = cand; if (hasReco) { for (Int_t j = 0; j < reco_n; j++) { reco_er[j] = reco_eRaw[j]; reco_etr[j] = reco_etRaw[j]; reco_sie[j] = reco_sieie[j]; reco_eca[j] = reco_ecal[j]; reco_ecu[j] = reco_ecal[j] / reco_et[j]; reco_dph[j] = fabs(reco_dphi[j]); reco_det[j] = fabs(reco_deta[j]); reco_des[j] = fabs(reco_detaseed[j]); reco_eop[j] = fabs(reco_eop[j]); reco_hca[j] = reco_hcal[j]; reco_hcu[j] = reco_hcal[j] / reco_et[j]; reco_tki[j] = reco_tkiso[j] / reco_et[j]; reco_chi[j] = reco_chi2[j]; reco_mih[j] = (Float_t) reco_mishits[j]; } } out_tree->Fill(); } } out_file->cd(); out_tree->Write(); out_file->Close(); gROOT->ProcessLine(".q"); }
void buildPdf() { Double_t lorange = 100.; Double_t hirange = 140.; // Import data TFile *file = new TFile("/atlas/data18a/yupan/HZZ4l2012/MiniTree/data12.root"); TTree *tree = (TTree*)file->Get("tree_incl_4mu"); // should include all channels, for now just testing... // Define variables Float_t m4l = 0; Float_t m4lerr = 0; // Float_t wgt = 0; // Get number of entries and setbranchaddress Int_t nevents = tree->GetEntries(); tree->SetBranchStatus("*",0); tree->SetBranchStatus("m4l_unconstrained",1); tree->SetBranchStatus("m4lerr_unconstrained",1); //tree->SetBranchStatus("weight",1); tree->SetBranchAddress("m4l_unconstrained",&m4l); tree->SetBranchAddress("m4lerr_unconstrained",&m4lerr); //tree->SetBranchAddress("weight",&wgt); /////////////// // Build pdfs ////////////// RooRealVar* mass = new RooRealVar("m4l","mass",lorange,hirange,"GeV"); RooRealVar merr("m4lerr","mass err",0.1,4.0,"GeV"); //RooRealVar weight("weight","weight",0,10); RooRealVar scale("scale","per-event error scale factor",1.0,0.2,4.0); RooProduct sigmaErr("sigmaErr","sigmaErr",RooArgSet(scale,merr)); /* float totalwgt(0); for (Int_t i=0; i<nevents; i++) { tree->GetEntry(i); totalwgt+=wgt; } std::cout<<"total weight = "<<totalwgt<<std::endl; */ /// Make DataSet RooDataSet signal("signal","signal",RooArgSet(*mass,merr)); std::cout<<"Reading in events from signal minitree"<<std::endl; for (Int_t i=0; i<nevents; i++) { tree->GetEntry(i); mass->setVal(m4l); merr.setVal(m4lerr); //weight.setVal(wgt/totalwgt); signal.add(RooArgSet(*mass,merr)); } // Create 1D kernel estimation for signal mass std::cout<<"Building mass keys"<<std::endl; RooKeysPdf kestsig("kestsig","kestsig",*mass,signal); TH1F* hm = (TH1F*)kestsig.createHistogram("hm",*mass); kestsig.fillHistogram(hm,RooArgList(*mass)); std::cout<<"Building mass pdf"<<std::endl; RooDataHist* dmass = new RooDataHist("dmass","binned dataset",*mass,hm); RooHistPdf* masspdf = new RooHistPdf("masspdf","pdf(dm)",*mass,*dmass,2); // Create 1D kernel estimation for mass err std::cout<<"Building error keys"<<std::endl; RooKeysPdf kestsigerr("kestsigerr","kestsigerr",merr,signal,RooKeysPdf::MirrorBoth,2); TH1F* herr = (TH1F*)kestsigerr.createHistogram("herr",merr); kestsigerr.fillHistogram(herr,RooArgList(merr)); std::cout<<"Integral "<<herr->Integral()<<std::endl; std::cout<<"Building error pdf"<<std::endl; RooDataHist* derr = new RooDataHist("derr","binned dataset",merr,herr); RooHistPdf* errpdf = new RooHistPdf("errpdf","pdf(de)",merr,*derr,2); //Make the crystal ball resolution model with CB sigma = mass error RooRealVar meanCB ("meanCB", "mean CB", hmass, hmass-10., hmass+5.); RooRealVar alphaCB ("alphaCB", "alpha CB", 7, 0., 10.); RooRealVar nnCB ("nnCB", "nn CB", 1.5, 0., 15.); RooCBShape* shapeCB = new RooCBShape("shapeCB", "crystal ball pdf", *mass, meanCB, sigmaErr, alphaCB, nnCB); // Make conditional pdf RooProdPdf* sigmodel = new RooProdPdf("sigmodel","sigmodel", *errpdf, Conditional(*shapeCB, *mass)); // Make a workspace to store the fit model RooWorkspace* pdfWsp = new RooWorkspace("pdfWspCB"); pdfWsp->import(*sigmodel,RecycleConflictNodes()); pdfWsp->import(*masspdf); pdfWsp->import(*errpdf,RecycleConflictNodes()); pdfWsp->import(signal); pdfWsp->Print(); pdfWsp->writeToFile("pdfWspCB.root"); // Make some plots TCanvas *c = new TCanvas("c","c",500,500); c->Divide(2); RooPlot* frame = merr.frame(Title("keys signal error")); signal.plotOn(frame); kestsigerr.plotOn(frame,LineColor(kRed)); errpdf->plotOn(frame); RooPlot* frame2 = mass->frame(Title("keys signal")); signal.plotOn(frame2); kestsig.plotOn(frame2,LineColor(kRed)); masspdf->plotOn(frame2); c->cd(2); frame->Draw(); c->cd(1); grame2->Draw(); c->Print("testPdf.png"); }
Int_t integrateRatePlots() { gROOT->SetStyle("Plain"); gStyle->SetOptStat(0); // gStyle->SetOptTitle(0); TGaxis::SetMaxDigits(3); const Int_t nFiles = 3; // const Int_t nElectrons = 3; TFile * histoFile = new TFile("integratedRates-eta2p1-26Jan12.root","RECREATE"); TFile * inputFile[nFiles]; inputFile[0] = TFile::Open("RctEmTree-Rates-scaleV1-thr2p0-01Dec11.root"); // v1, 2.0, BOTH ISO AND NON-ISO inputFile[1] = TFile::Open("RctEmTree-Rates-scaleV3-thr1p0-12Jan12.root"); // v3, 1.0, iso inputFile[2] = TFile::Open("RctEmTree-Rates-HighPU-scaleV3-thr1p0-18Jan12.root"); // v3, 1.0, highPU, iso TH1F * h_rank[nFiles], * h_rankIntegrated[nFiles]; TH1F * h_rankBarrel[nFiles], * h_rankBarrelIntegrated[nFiles]; // scale factor here is 1./(total n LS * 23 s/LS) * (total lumi / effective lumi) to get from total event counts to rate (event count per second) Float_t scaleFactor[3]; scaleFactor[0] = 14.2 * 1./(15379.*23.) * (713729./68.794); scaleFactor[1] = 1./(15379.*23.) * (713729./68.794); scaleFactor[2] = 1./(299. * 23.) * (299.556 / 49.926) * (201.78 / 4.3559); // scaled up to 2e33 inst lumi from 4e31 -- those last two numbers are times 10^31 // tree stuff TTree * tree; vector<int> *emRank; vector<int> *emIso; vector<int> *emIeta; TBranch *b_emRank; TBranch *b_emIso; TBranch *b_emIeta; // end tree stuff // Int_t nBins = 64; // Float_t xMin = 0., xMax = 64.; Int_t nBins = 52; Float_t xMin = 12., xMax = 64.; // |eta| < 1.5, barrel-only // Int_t barrelIEtaBoundaryLower = 7; // this is REGION ieta -- goes from 4 to 17, not including HF. // Int_t barrelIEtaBoundaryUpper = 14; // this takes first four regions (last 3 are endcap) // |eta| < 2.1 Int_t barrelIEtaBoundaryLower = 8; // this is REGION ieta -- goes from 4 to 17, not including HF. Int_t barrelIEtaBoundaryUpper = 13; // this takes first three regions (first 24 towers), going to eta 2.1720 TCanvas * rankCanvas = new TCanvas("rankCanvas","EM rank distribution"); TCanvas * rankBarrelCanvas = new TCanvas("rankBarrelCanvas","EM rank distribution (|#eta| < 2.1)"); TCanvas * integratedCanvas = new TCanvas("integratedCanvas","Rate by trigger threshold"); integratedCanvas->cd(); TPad * pad1 = new TPad("pad1","pad1",0.,0.35,1.0,1.0); pad1->SetBottomMargin(0); pad1->Draw(); TPad * pad2 = new TPad("pad2","pad2",0.,0.,1.0,0.35); pad2->SetTopMargin(0); pad2->SetBottomMargin(0.3); pad2->Draw(); TCanvas * integratedBarrelCanvas = new TCanvas("integratedBarrelCanvas","Rate by trigger threshold (|#eta| < 2.1)"); integratedBarrelCanvas->cd(); TPad * pad1B = new TPad("pad1B","pad1B",0.,0.35,1.0,1.0); pad1B->SetBottomMargin(0); pad1B->Draw(); TPad * pad2B = new TPad("pad2B","pad2B",0.,0.,1.0,0.35); pad2B->SetTopMargin(0); pad2B->SetBottomMargin(0.3); pad2B->Draw(); for (Int_t file = 0; file < nFiles; file++) { std::cout << "File " << file << std::endl; inputFile[file]->cd(); TString treeName = TString("rctAnalyzer/emTree;1"); std::cout << "getting tree" << std::endl; gDirectory->GetObject(treeName,tree); // std::cout << "X min = " << h_rank->GetXaxis()->GetXmin() << std::endl; // std::cout << "X max = " << h_rank->GetXaxis()->GetXmax() << std::endl; // Int_t nBins = h_rank->GetNbinsX(); // h_rank = new TH1F("h_rank","EM Rank",nBins,h_rank->GetXaxis()->GetXmin(),h_rank->GetXaxis()->GetXmax()); // h_rankIntegrated = new TH1F("h_rankIntegrated","Rates by trigger threshold",nBins,h_rank->GetXaxis()->GetXmin(),h_rank->GetXaxis()->GetXmax()); std::cout << "making histograms" << std::endl; h_rank[file] = new TH1F(makeName("h_rank",file),"EM Rank",nBins,xMin,xMax); h_rankIntegrated[file] = new TH1F(makeName("h_rankIntegrated",file),"Rates by trigger threshold",nBins,xMin,xMax); h_rankBarrel[file] = new TH1F(makeName("h_rankBarrel",file),"EM Rank (|#eta| < 2.1)",nBins,xMin,xMax); h_rankBarrelIntegrated[file] = new TH1F(makeName("h_rankBarrelIntegrated",file),"Rates by trigger threshold (|#eta| < 2.1)",nBins,xMin,xMax); rankCanvas->cd(); // tree stuff emRank = 0; emIso = 0; emIeta = 0; tree->SetBranchAddress("emRank", &emRank, &b_emRank); tree->SetBranchAddress("emIso", &emIso, &b_emIso); tree->SetBranchAddress("emIeta", &emIeta, &b_emIeta); b_emRank->SetAutoDelete(kTRUE); b_emIso->SetAutoDelete(kTRUE); b_emIeta->SetAutoDelete(kTRUE); tree->SetBranchStatus("*",0); tree->SetBranchStatus("emRank",1); tree->SetBranchStatus("emIso",1); tree->SetBranchStatus("emIeta",1); // loop over tree std::cout << "Looping over tree" << std::endl; Long64_t nentries = tree->GetEntriesFast(); for (Long64_t jentry = 0; jentry < nentries; jentry++) { //std::cout << "entry " << jentry << std::endl; //Long64_t ientry = tree->LoadTree(jentry); //tree->LoadTree(jentry); // Set current entry. tree->GetEntry(jentry); // Read all branches of entry and return total number of bytes read. Int_t elecSize = emRank->size(); for (Int_t elec = 0; elec < elecSize; elec++) { if (file == 0) // isolated and non-isolated { h_rank[file]->Fill(emRank->at(elec)); if (emIeta->at(elec) >= barrelIEtaBoundaryLower && emIeta->at(elec) <= barrelIEtaBoundaryUpper) { h_rankBarrel[file]->Fill(emRank->at(elec)); } break; } else // isolated only { if (emIso->at(elec) == 1) { h_rank[file]->Fill(emRank->at(elec)); if (emIeta->at(elec) >= barrelIEtaBoundaryLower && emIeta->at(elec) <= barrelIEtaBoundaryUpper) { h_rankBarrel[file]->Fill(emRank->at(elec)); } break; } } } } // end tree stuff // making pretty colors for the lines in the rank plots h_rank[file]->SetLineColor(file+1); if (file+1 == 3) { h_rank[file]->SetLineColor(8); } if (file+1 == 5) { h_rank[file]->SetLineColor(41); } h_rank[file]->SetLineWidth(2); h_rankBarrel[file]->SetLineColor(file+40); h_rankBarrel[file]->SetLineWidth(2); if (file == 0) { h_rank[file]->Draw(); } else { h_rank[file]->Draw("same"); h_rankBarrel[file]->Draw("same"); } rankBarrelCanvas->cd(); if (file == 0) { h_rankBarrel[file]->Draw(); } else { h_rankBarrel[file]->Draw("same"); } // doing the integration Int_t eventsAboveThreshold = 0; for (int i = nBins-1; i >= 0; i--) { eventsAboveThreshold = eventsAboveThreshold + h_rank[file]->GetBinContent(i); std::cout << "bin is " << i << ", bin content is " << h_rank[file]->GetBinContent(i) << ", eventsAboveThreshold is " << eventsAboveThreshold << std::endl; h_rankIntegrated[file]->Fill(xMin+i,eventsAboveThreshold); } eventsAboveThreshold = 0; for (int i = nBins-1; i >= 0; i--) { eventsAboveThreshold = eventsAboveThreshold + h_rankBarrel[file]->GetBinContent(i); std::cout << "bin is " << i << ", bin content is " << h_rankBarrel[file]->GetBinContent(i) << ", eventsAboveThreshold is " << eventsAboveThreshold << std::endl; h_rankBarrelIntegrated[file]->Fill(xMin+i,eventsAboveThreshold); } std::cout << "sumw2" << std::endl; h_rankIntegrated[file]->Sumw2(); h_rankIntegrated[file]->Scale(scaleFactor[file]); h_rankBarrelIntegrated[file]->Sumw2(); h_rankBarrelIntegrated[file]->Scale(scaleFactor[file]); // more pretty colors, this time for integrated plots h_rankIntegrated[file]->SetLineColor(file+1); if (file+1 == 3) { h_rankIntegrated[file]->SetLineColor(8); } if (file+1 == 5) { h_rankIntegrated[file]->SetLineColor(41); } h_rankIntegrated[file]->SetLineWidth(2); if (file == 1) { h_rankBarrelIntegrated[file]->SetLineColor(kRed+2); } if (file == 2) { h_rankBarrelIntegrated[file]->SetLineColor(kYellow+2); } h_rankBarrelIntegrated[file]->SetLineWidth(2); integratedCanvas->cd(); pad1->cd(); std::cout << "Draw" << std::endl; if(file == 0) { h_rankIntegrated[file]->Draw(); } else { h_rankIntegrated[file]->Draw("same"); h_rankBarrelIntegrated[file]->Draw("same"); } integratedBarrelCanvas->cd(); pad1B->cd(); std::cout << "Draw" << std::endl; if(file == 0) { h_rankBarrelIntegrated[file]->Draw(); } else { h_rankBarrelIntegrated[file]->Draw("same"); } std::cout << "Done drawing" << std::endl; } std::cout << "Making legend" << std::endl; TLegend legend(0.3,0.6,0.89,0.89); legend.AddEntry(h_rankIntegrated[0],"v1 scales, thr = 2.0, Relaxed"); legend.AddEntry(h_rankIntegrated[1],"v3 scales, thr = 1.0, Isolated"); legend.AddEntry(h_rankBarrelIntegrated[1],"v3 scales, thr = 1.0, Isolated, |#eta| < 2.1"); legend.AddEntry(h_rankIntegrated[2],"High-PU, v3 scales, thr = 1.0, Isolated"); legend.AddEntry(h_rankBarrelIntegrated[2],"High-PU, v3 scales, thr = 1.0, Isolated, |#eta| < 2.1"); legend.SetFillColor(0); integratedCanvas->cd(); pad1->cd(); legend.Draw("same"); integratedBarrelCanvas->cd(); pad1B->cd(); legend.Draw("same"); std::cout << "Making ratio plots" << std::endl; integratedCanvas->cd(); pad2->cd(); TH1F * r_eff1; TH1F * r_eff2; r_eff1 = (TH1F*) h_rankIntegrated[1]->Clone("r_eff1"); r_eff2 = (TH1F*) h_rankIntegrated[2]->Clone("r_eff2"); r_eff1->Divide(h_rankIntegrated[0]); r_eff2->Divide(h_rankIntegrated[0]); r_eff1->SetTitle(""); r_eff2->SetTitle(""); r_eff1->GetXaxis()->SetRangeUser(xMin,xMax); r_eff2->GetXaxis()->SetRangeUser(xMin,xMax); r_eff1->SetMinimum(0.3); r_eff1->SetMaximum(1.0); r_eff2->SetMinimum(0.3); r_eff2->SetMaximum(1.0); r_eff1->GetXaxis()->SetTitle("Trigger threshold (GeV)"); r_eff1->GetXaxis()->SetLabelSize(0.07); r_eff1->GetXaxis()->SetTitleSize(0.07); r_eff1->GetYaxis()->SetLabelSize(0.07); r_eff2->GetXaxis()->SetTitle("Trigger threshold (GeV)"); r_eff2->GetXaxis()->SetLabelSize(0.07); r_eff2->GetXaxis()->SetTitleSize(0.07); r_eff2->GetYaxis()->SetLabelSize(0.07); r_eff1->Draw(); r_eff2->Draw("same"); integratedBarrelCanvas->cd(); pad2B->cd(); TH1F * r_eff1B; TH1F * r_eff2B; r_eff1B = (TH1F*) h_rankBarrelIntegrated[1]->Clone("r_eff1B"); r_eff2B = (TH1F*) h_rankBarrelIntegrated[2]->Clone("r_eff2B"); r_eff1B->Divide(h_rankIntegrated[0]); r_eff2B->Divide(h_rankIntegrated[0]); r_eff1B->SetTitle(""); r_eff2B->SetTitle(""); r_eff1B->GetXaxis()->SetRangeUser(xMin,xMax); r_eff2B->GetXaxis()->SetRangeUser(xMin,xMax); r_eff1B->SetMinimum(0.3); r_eff1B->SetMaximum(1.0); r_eff2B->SetMinimum(0.3); r_eff2B->SetMaximum(1.0); r_eff1B->GetXaxis()->SetTitle("Trigger threshold (GeV)"); r_eff1B->GetXaxis()->SetLabelSize(0.07); r_eff1B->GetXaxis()->SetTitleSize(0.07); r_eff1B->GetYaxis()->SetLabelSize(0.07); r_eff2B->GetXaxis()->SetTitle("Trigger threshold (GeV)"); r_eff2B->GetXaxis()->SetLabelSize(0.07); r_eff2B->GetXaxis()->SetTitleSize(0.07); r_eff2B->GetYaxis()->SetLabelSize(0.07); r_eff1B->Draw(); r_eff2B->Draw("same"); integratedCanvas->cd(); r_eff1B->Draw("same"); r_eff2B->Draw("same"); TLine * unity; unity = new TLine(0.,1.0,64.,1.0); unity->SetX1(gPad->PadtoX(xMin)); unity->SetX2(gPad->PadtoX(xMax)); unity->SetLineColor(kBlue); integratedCanvas->cd(); pad2->cd(); r_eff1B->Draw("same"); r_eff2B->Draw("same"); unity->Draw("same"); integratedBarrelCanvas->cd(); pad2B->cd(); unity->Draw("same"); std::cout << "Writing canvases to file" << std::endl; histoFile->WriteTObject(rankCanvas); histoFile->WriteTObject(rankBarrelCanvas); histoFile->WriteTObject(integratedCanvas); histoFile->WriteTObject(integratedBarrelCanvas); std::cout << "Closing input files" << std::endl; for (Int_t i = 0; i < nFiles; i++) { inputFile[i]->Close(); } std::cout << "Deleting canvases" << std::endl; delete rankCanvas; delete rankBarrelCanvas; delete pad1; delete pad2; delete integratedCanvas; delete pad1B; delete pad2B; delete integratedBarrelCanvas; return 0; }
void makeQCDTrees(){ TFile *outFile = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/nTupleVBF115.root","RECREATE"); TTree* outTreePtOrd = new TTree("outTreePtOrd","tree jets pT-ord"); TTree* outTreePtEtaOrd = new TTree("outTreePtEtaOrd","tree jets pT-eta ord"); TTree* outTreePtDEtaOrd = new TTree("outTreePtDEtaOrd","tree jets pT-Deta ord"); TTree* outTreePtMjjOrd = new TTree("outTreePtMjjOrd","tree jets pT-Mjj ord"); double pt1,pt2,eta1,eta2,Deta,Mjj, Dphi ; outTreePtOrd->Branch("pt1", &pt1,"pt1/D"); outTreePtOrd->Branch("pt2", &pt2,"pt2/D"); outTreePtOrd->Branch("eta1", &eta1,"eta1/D"); outTreePtOrd->Branch("eta2", &eta2,"eta2/D"); outTreePtOrd->Branch("Deta", &Deta,"Deta/D"); outTreePtOrd->Branch("Dphi", &Dphi,"Dphi/D"); outTreePtOrd->Branch("Mjj", &Mjj,"Mjj/D"); outTreePtEtaOrd->Branch("pt1", &pt1,"pt1/D"); outTreePtEtaOrd->Branch("pt2", &pt2,"pt2/D"); outTreePtEtaOrd->Branch("eta1", &eta1,"eta1/D"); outTreePtEtaOrd->Branch("eta2", &eta2,"eta2/D"); outTreePtEtaOrd->Branch("Deta", &Deta,"Deta/D"); outTreePtEtaOrd->Branch("Dphi", &Dphi,"Dphi/D"); outTreePtEtaOrd->Branch("Mjj", &Mjj,"Mjj/D"); outTreePtDEtaOrd->Branch("pt1", &pt1,"pt1/D"); outTreePtDEtaOrd->Branch("pt2", &pt2,"pt2/D"); outTreePtDEtaOrd->Branch("eta1", &eta1,"eta1/D"); outTreePtDEtaOrd->Branch("eta2", &eta2,"eta2/D"); outTreePtDEtaOrd->Branch("Deta", &Deta,"Deta/D"); outTreePtDEtaOrd->Branch("Dphi", &Dphi,"Dphi/D"); outTreePtDEtaOrd->Branch("Mjj", &Mjj,"Mjj/D"); outTreePtMjjOrd->Branch("pt1", &pt1,"pt1/D"); outTreePtMjjOrd->Branch("pt2", &pt2,"pt2/D"); outTreePtMjjOrd->Branch("eta1", &eta1,"eta1/D"); outTreePtMjjOrd->Branch("eta2", &eta2,"eta2/D"); outTreePtMjjOrd->Branch("Deta", &Deta,"Deta/D"); outTreePtMjjOrd->Branch("Dphi", &Dphi,"Dphi/D"); outTreePtMjjOrd->Branch("Mjj", &Mjj,"Mjj/D"); TFile* file = new TFile("/data_CMS/cms/lbianchini/MuTauStream/NoMuIsoNoTauIsoNo2Tcuts/treeMuTauStream_VBFH115-PU-L.root","READ"); TTree* currentTree = (TTree*)file->Get("muTauStreamAnalyzer/tree"); int nEntries = currentTree->GetEntries() ; currentTree->SetBranchStatus("diTauVisP4",0); currentTree->SetBranchStatus("diTauCAP4",0); currentTree->SetBranchStatus("diTauICAP4",0); currentTree->SetBranchStatus("diTauSVfit1P4",0); currentTree->SetBranchStatus("diTauSVfit2P4",0); currentTree->SetBranchStatus("diTauSVfit3P4",0); //currentTree->SetBranchStatus("diTauLegsP4",0); currentTree->SetBranchStatus("genDiTauLegsP4",0); currentTree->SetBranchStatus("METP4",0); currentTree->SetBranchStatus("genMETP4",0); currentTree->SetBranchStatus("jetsP4",0); currentTree->SetBranchStatus("genJetsIDP4",0); currentTree->SetBranchStatus("jetsBtagHE",0); currentTree->SetBranchStatus("jetsBtagHP",0); currentTree->SetBranchStatus("sumEt",0); //currentTree->SetBranchStatus("MtLeg1",0); //currentTree->SetBranchStatus("chIsoLeg1",0); //currentTree->SetBranchStatus("nhIsoLeg1",0); //currentTree->SetBranchStatus("phIsoLeg1",0); currentTree->SetBranchStatus("chIsoLeg2",0); currentTree->SetBranchStatus("nhIsoLeg2",0); currentTree->SetBranchStatus("phIsoLeg2",0); currentTree->SetBranchStatus("dxy1",0); currentTree->SetBranchStatus("dxy2",0); currentTree->SetBranchStatus("run",0); currentTree->SetBranchStatus("event",0); currentTree->SetBranchStatus("numPV",0); currentTree->SetBranchStatus("numOfDiTaus",0); currentTree->SetBranchStatus("decayMode",0); //currentTree->SetBranchStatus("tightestHPSWP",0); currentTree->SetBranchStatus("visibleTauMass",0); currentTree->SetBranchStatus("isTauLegMatched",0); currentTree->SetBranchStatus("isMuLegMatched",0); currentTree->SetBranchStatus("isTauLegMatched",0); currentTree->SetBranchStatus("isMuLegMatched",0); //currentTree->SetBranchStatus("diTauCharge",0); std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* jets; std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* diTauLegsP4; float chIsoLeg1,nhIsoLeg1,phIsoLeg1; int tightestHPSWP; float diTauCharge,MtLeg1; currentTree->SetBranchAddress("jetsIDP4", &jets); currentTree->SetBranchAddress("diTauLegsP4",&diTauLegsP4); currentTree->SetBranchAddress("chIsoLeg1",&chIsoLeg1); currentTree->SetBranchAddress("nhIsoLeg1",&nhIsoLeg1); currentTree->SetBranchAddress("phIsoLeg1",&phIsoLeg1); currentTree->SetBranchAddress("tightestHPSWP",&tightestHPSWP); currentTree->SetBranchAddress("diTauCharge",&diTauCharge); currentTree->SetBranchAddress("MtLeg1",&MtLeg1); for (int n = 0; n < nEntries ; n++) { currentTree->GetEntry(n); pt1=-99;pt2=-99;eta1=-99,eta2=-99;Deta=-99;Dphi=-99;Mjj=-99; bool eventSel = (chIsoLeg1+nhIsoLeg1+phIsoLeg1)/(*diTauLegsP4)[0].Pt()<0.1 && MtLeg1<40 && diTauCharge==0; if(jets->size()>1 && (*jets)[0].Et()>MINPt1 && (*jets)[1].Et()>MINPt2 && eventSel){ pt1 = (*jets)[0].Pt(); pt2 = (*jets)[1].Pt(); eta1 = (*jets)[0].Eta(); eta2 = (*jets)[1].Eta(); Deta = abs(eta1-eta2); Dphi = abs((*jets)[0].Phi()-(*jets)[1].Phi()) > TMath::Pi() ? -abs( (*jets)[0].Phi()-(*jets)[1].Phi() ) + 2*TMath::Pi() : abs( (*jets)[0].Phi()-(*jets)[1].Phi() ); Mjj = ((*jets)[0]+(*jets)[1]).M(); outTreePtOrd->Fill(); continue; } outTreePtOrd->Fill(); } for (int n = 0; n < nEntries ; n++) { currentTree->GetEntry(n); pt1=-99;pt2=-99;eta1=-99,eta2=-99;Deta=-99;Dphi=-99;Mjj=-99; bool eventSel = (chIsoLeg1+nhIsoLeg1+phIsoLeg1)/(*diTauLegsP4)[0].Pt()<0.1 && MtLeg1<40 && diTauCharge==0; if(jets->size()>1 && abs((*jets)[0].Eta()-(*jets)[1].Eta())>1.4 && (*jets)[0].Et()>MINPt1 && (*jets)[1].Et()>MINPt2 && eventSel){ pt1 = (*jets)[0].Pt(); pt2 = (*jets)[1].Pt(); eta1 = (*jets)[0].Eta(); eta2 = (*jets)[1].Eta(); Deta = abs(eta1-eta2); Dphi = abs((*jets)[0].Phi()-(*jets)[1].Phi()) > TMath::Pi() ? -abs( (*jets)[0].Phi()-(*jets)[1].Phi() ) + 2*TMath::Pi() : abs( (*jets)[0].Phi()-(*jets)[1].Phi() ); Mjj = ((*jets)[0]+(*jets)[1]).M(); outTreePtEtaOrd->Fill(); continue; } else if(jets->size()>2 && abs((*jets)[0].Eta()-(*jets)[2].Eta())>1.4 && (*jets)[0].Et()>MINPt1 && (*jets)[2].Et()>MINPt2 && eventSel){ pt1 = (*jets)[0].Pt(); pt2 = (*jets)[2].Pt(); eta1 = (*jets)[0].Eta(); eta2 = (*jets)[2].Eta(); Deta = abs(eta1-eta2); Dphi = abs((*jets)[0].Phi()-(*jets)[2].Phi()) > TMath::Pi() ? -abs( (*jets)[0].Phi()-(*jets)[2].Phi() ) + 2*TMath::Pi() : abs( (*jets)[0].Phi()-(*jets)[2].Phi() ); Mjj = ((*jets)[0]+(*jets)[2]).M(); outTreePtEtaOrd->Fill(); continue; } outTreePtEtaOrd->Fill(); } for (int n = 0; n < nEntries ; n++) { currentTree->GetEntry(n); pt1=-99;pt2=-99;eta1=-99,eta2=-99;Deta=-99;Dphi=-99;Mjj=-99; bool eventSel = (chIsoLeg1+nhIsoLeg1+phIsoLeg1)/(*diTauLegsP4)[0].Pt()<0.1 && MtLeg1<40 && diTauCharge==0; double Deta_tmp = -99; unsigned int lead=999 ; unsigned int trail=999; for(unsigned int i=0; i<jets->size(); i++){ for(unsigned int j=0; j<jets->size(); j++){ if(j>i && (*jets)[i].Et()>MINPt1 && (*jets)[j].Et()>MINPt2 && abs((*jets)[j].Eta()-(*jets)[i].Eta()) > Deta_tmp){ Deta_tmp = abs((*jets)[j].Eta()-(*jets)[i].Eta()); lead = i; trail = j; } }// j }// i if(lead!=999 && trail!=999 && eventSel ){ pt1 = (*jets)[lead].Pt(); pt2 = (*jets)[trail].Pt(); eta1 = (*jets)[lead].Eta(); eta2 = (*jets)[trail].Eta(); Deta = abs(eta1-eta2); Dphi = abs((*jets)[lead].Phi()-(*jets)[trail].Phi()) > TMath::Pi() ? -abs( (*jets)[lead].Phi()-(*jets)[trail].Phi() ) + 2*TMath::Pi() : abs( (*jets)[lead].Phi()-(*jets)[trail].Phi() ); Mjj = ((*jets)[lead]+(*jets)[trail]).M(); outTreePtDEtaOrd->Fill(); continue; } outTreePtDEtaOrd->Fill(); } for (int n = 0; n < nEntries ; n++) { currentTree->GetEntry(n); pt1=-99;pt2=-99;eta1=-99,eta2=-99;Deta=-99;Dphi=-99;Mjj=-99; bool eventSel = (chIsoLeg1+nhIsoLeg1+phIsoLeg1)/(*diTauLegsP4)[0].Pt()<0.1 && MtLeg1<40 && diTauCharge==0; double Mjj_tmp = -99; unsigned int lead=999 ; unsigned int trail=999; for(unsigned int i=0; i<jets->size(); i++){ for(unsigned int j=0; j<jets->size(); j++){ if(j>i && (*jets)[i].Et()>MINPt1 && (*jets)[j].Et()>MINPt2 && ((*jets)[j]+(*jets)[i]).M() > Mjj_tmp){ Mjj_tmp = ((*jets)[j]+(*jets)[i]).M(); lead = i; trail = j; } }// j }// i if(lead!=999 && trail!=999 && eventSel){ pt1 = (*jets)[lead].Pt(); pt2 = (*jets)[trail].Pt(); eta1 = (*jets)[lead].Eta(); eta2 = (*jets)[trail].Eta(); Deta = abs(eta1-eta2); Dphi = abs((*jets)[lead].Phi()-(*jets)[trail].Phi()) > TMath::Pi() ? -abs( (*jets)[lead].Phi()-(*jets)[trail].Phi() ) + 2*TMath::Pi() : abs( (*jets)[lead].Phi()-(*jets)[trail].Phi() ); Mjj = ((*jets)[lead]+(*jets)[trail]).M(); outTreePtMjjOrd->Fill(); continue; } outTreePtMjjOrd->Fill(); } file->Close(); if(SAVE) outFile->Write(); outFile->Close(); }
void makeTrees_ElecTauStream(int index = 4){ std::vector<std::string> samples; samples.push_back("Run2011-Elec-v6"); samples.push_back("DYJets-50-madgraph-PUS1"); samples.push_back("DYToEE-20-PUS1"); samples.push_back("DYToTauTau-20-PUS1"); //samples.push_back("Zjets-alpgen-PUS1"); samples.push_back("TTJets-madgraph-PUS1"); samples.push_back("WJets-madgraph-PUS1"); //samples.push_back("WW-pythia-PUS1"); //samples.push_back("WZ-pythia-PUS1"); //samples.push_back("ZZ-pythia-PUS1"); samples.push_back("DiBoson"); samples.push_back("QCD"); samples.push_back("G1Jet"); samples.push_back("VBFH115-powheg-PUS1"); samples.push_back("VBFH135-powheg-PUS1"); samples.push_back("GGFH115-powheg-PUS1"); samples.push_back("GGFH130-powheg-PUS1"); std::vector<float> crossSec; crossSec.push_back( 0 ); crossSec.push_back( 3048 ); crossSec.push_back( 1666 ); crossSec.push_back( 1666 ); //crossSec.push_back( -1 ); crossSec.push_back( 157.5 ); crossSec.push_back( 31314.0); crossSec.push_back( -1 ); //crossSec.push_back( 2.9 ); //crossSec.push_back( 10.4 ); //crossSec.push_back( 4.297 ); crossSec.push_back( -1 ); crossSec.push_back( -1 ); crossSec.push_back( 0.1012); crossSec.push_back( 0.05049); crossSec.push_back( 7.65e-02 * 18.13 ); crossSec.push_back( 4.52e-02 * 13.8 ); Float_t Lumi=1000; TString sample(samples[index]); //TString outName = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/nTuple"+sample+"_Open_ElecTauStream.root"; TString outName = "nTuple"+sample+"_Open_ElecTauStream_Inclusive.root"; TFile *outFile = new TFile(outName,"RECREATE"); TTree* outTreePtOrd = new TTree("outTreePtOrd","tree jets pT-ord"); //float pt1,pt2,eta1,eta2,Deta,Mjj; //float Dphi; float diTauSVFitMass,diTauVisPt,diTauVisEta,diTauCAPt,diTauCAEta,diTauSVFitPt,diTauSVFitEta; float diTauVisMass; float ptL1,ptL2,etaL1,etaL2; float diTauCharge_,MtLeg1_; float numPV_; float sampleWeight,combRelIsoLeg1; int tightestHPSWP_; float jetsBtagHE1,jetsBtagHE2; //float ptVeto; float HLT; int isTauLegMatched_; //outTreePtOrd->Branch("pt1", &pt1,"pt1/F"); //outTreePtOrd->Branch("pt2", &pt2,"pt2/F"); //outTreePtOrd->Branch("eta1", &eta1,"eta1/F"); //outTreePtOrd->Branch("eta2", &eta2,"eta2/F"); //outTreePtOrd->Branch("Deta", &Deta,"Deta/F"); //outTreePtOrd->Branch("Mjj", &Mjj,"Mjj/F"); //outTreePtOrd->Branch("ptVeto", &ptVeto,"ptVeto/F"); outTreePtOrd->Branch("diTauVisMass", &diTauVisMass,"diTauVisMass/F"); outTreePtOrd->Branch("diTauSVFitPt", &diTauSVFitPt,"diTauSVFitPt/F"); outTreePtOrd->Branch("diTauSVFitMass", &diTauSVFitMass,"diTauSVFitMass/F"); outTreePtOrd->Branch("etaL1", &etaL1,"etaL1/F"); outTreePtOrd->Branch("etaL2", &etaL2,"etaL2/F"); outTreePtOrd->Branch("ptL1", &ptL1,"ptL1/F"); outTreePtOrd->Branch("ptL2", &ptL2,"ptL2/F"); outTreePtOrd->Branch("diTauCharge", &diTauCharge_,"diTauCharge/F"); outTreePtOrd->Branch("MtLeg1", &MtLeg1_,"MtLeg1/F"); outTreePtOrd->Branch("numPV", &numPV_,"numPV/F"); outTreePtOrd->Branch("sampleWeight", &sampleWeight,"sampleWeight/F"); outTreePtOrd->Branch("combRelIsoLeg1", &combRelIsoLeg1,"combRelIsoLeg1/F"); outTreePtOrd->Branch("tightestHPSWP", &tightestHPSWP_,"tightestHPSWP/I"); outTreePtOrd->Branch("HLT", &HLT,"HLT/F"); outTreePtOrd->Branch("isTauLegMatched", &isTauLegMatched_,"isTauLegMatched/I"); //outTreePtOrd->Branch("diTauVisPt", &diTauVisPt,"diTauVisPt/F"); //outTreePtOrd->Branch("diTauVisEta", &diTauVisEta,"diTauVisEta/F"); //outTreePtOrd->Branch("diTauCAPt", &diTauCAPt,"diTauCAPt/F"); //outTreePtOrd->Branch("diTauCAEta", &diTauCAEta,"diTauCAEta/F"); //outTreePtOrd->Branch("Dphi", &Dphi,"Dphi/F"); //outTreePtOrd->Branch("diTauSVFitEta", &diTauSVFitEta,"diTauSVFitEta/F"); //outTreePtOrd->Branch("jetsBtagHE1", &jetsBtagHE1,"jetsBtagHE1/F"); //outTreePtOrd->Branch("jetsBtagHE2", &jetsBtagHE2,"jetsBtagHE2/F"); TString inName = "/data_CMS/cms/lbianchini/ElecTauStream2011//treeElecTauStream_"+sample+".root"; TFile* file = new TFile(inName,"READ"); if(file->IsZombie()){ cout << "No such file!" << endl; return; } TTree* currentTree = (TTree*)file->Get("elecTauStreamAnalyzer/tree"); int nEntries = currentTree->GetEntries() ; TH1F* allEvents = (TH1F*)file->Get("allEventsFilter/totalEvents"); float totalEvents = allEvents->GetBinContent(1); float scaleFactor = (crossSec[index] != 0) ? ((crossSec[index])*Lumi) / totalEvents : 1; //currentTree->SetBranchStatus("diTauVisP4",0); currentTree->SetBranchStatus("diTauCAP4",0); currentTree->SetBranchStatus("diTauICAP4",0); currentTree->SetBranchStatus("diTauSVfit1P4",0); currentTree->SetBranchStatus("diTauSVfit2P4",0); //currentTree->SetBranchStatus("diTauSVfit3P4",0); //currentTree->SetBranchStatus("diTauLegsP4",0); currentTree->SetBranchStatus("genDiTauLegsP4",0); currentTree->SetBranchStatus("METP4",0); currentTree->SetBranchStatus("genMETP4",0); currentTree->SetBranchStatus("jetsP4",0); currentTree->SetBranchStatus("genJetsIDP4",0); currentTree->SetBranchStatus("jetsBtagHE",0); currentTree->SetBranchStatus("jetsBtagHP",0); currentTree->SetBranchStatus("sumEt",0); //currentTree->SetBranchStatus("MtLeg1",0); //currentTree->SetBranchStatus("chIsoLeg1",0); //currentTree->SetBranchStatus("nhIsoLeg1",0); //currentTree->SetBranchStatus("phIsoLeg1",0); currentTree->SetBranchStatus("chIsoLeg2",0); currentTree->SetBranchStatus("nhIsoLeg2",0); currentTree->SetBranchStatus("phIsoLeg2",0); currentTree->SetBranchStatus("dxy1",0); currentTree->SetBranchStatus("dxy2",0); currentTree->SetBranchStatus("run",0); currentTree->SetBranchStatus("event",0); //currentTree->SetBranchStatus("numPV",0); currentTree->SetBranchStatus("numOfDiTaus",0); currentTree->SetBranchStatus("decayMode",0); //currentTree->SetBranchStatus("tightestHPSWP",0); currentTree->SetBranchStatus("visibleTauMass",0); //currentTree->SetBranchStatus("isTauLegMatched",0); currentTree->SetBranchStatus("isElecLegMatched",0); //currentTree->SetBranchStatus("diTauCharge",0); //currentTree->SetBranchStatus("tauXTriggers",0); float chIsoLeg1,nhIsoLeg1,phIsoLeg1; int tightestHPSWP; float diTauCharge, MtLeg1; float numPV; float weight; int isTauLegMatched; std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* jets = new std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >(); //currentTree->SetBranchAddress("jetsIDP4", &jets); std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* diTauLegsP4 = new std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >(); currentTree->SetBranchAddress("diTauLegsP4",&diTauLegsP4); std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* diTauVisP4 = new std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >(); currentTree->SetBranchAddress("diTauVisP4",&diTauVisP4); std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* diTauICAP4 = new std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >(); //currentTree->SetBranchAddress("diTauICAP4",&diTauICAP4); std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* diTauSVfit3P4 = new std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >(); currentTree->SetBranchAddress("diTauSVfit3P4",&diTauSVfit3P4); std::vector< int >* tauXTriggers = new std::vector< int >(); currentTree->SetBranchAddress("tauXTriggers",&tauXTriggers); //currentTree->SetBranchAddress("jetsBtagHE",&jetsBtagHE); currentTree->SetBranchAddress("chIsoLeg1",&chIsoLeg1); currentTree->SetBranchAddress("nhIsoLeg1",&nhIsoLeg1); currentTree->SetBranchAddress("phIsoLeg1",&phIsoLeg1); currentTree->SetBranchAddress("tightestHPSWP",&tightestHPSWP); currentTree->SetBranchAddress("diTauCharge",&diTauCharge); currentTree->SetBranchAddress("MtLeg1",&MtLeg1); currentTree->SetBranchAddress("numPV",&numPV); currentTree->SetBranchAddress("isTauLegMatched",&isTauLegMatched); if(crossSec[index]<0) currentTree->SetBranchAddress("weight",&weight); for (int n = 0; n < nEntries ; n++) { currentTree->GetEntry(n); if(n%1000==0) cout << n << endl; //pt1=-99;pt2=-99;eta1=-99,eta2=-99;Deta=-99;Dphi=-99;Mjj=-99; diTauVisPt=-99;diTauVisEta=-99;diTauCAPt=-99;diTauCAEta=-99; diTauSVFitMass = -99;diTauSVFitPt=-99;diTauSVFitEta=-99;diTauVisMass=-99; ptL1=-99;ptL2=-99;etaL1=-99;etaL2=-99;diTauCharge_=-99;MtLeg1_=-99; tightestHPSWP_=-99;numPV_=-99;combRelIsoLeg1=-99;sampleWeight=-99; //ptVeto=-99; HLT=-99;isTauLegMatched_=-99; //pt1 = (*jets)[0].Pt(); //pt2 = (*jets)[1].Pt(); //eta1 = (*jets)[0].Eta(); //eta2 = (*jets)[1].Eta(); //Deta = abs(eta1-eta2); //Dphi = abs((*jets)[0].Phi()-(*jets)[1].Phi()) > TMath::Pi() ? //-abs( (*jets)[0].Phi()-(*jets)[1].Phi() ) + 2*TMath::Pi() : //abs( (*jets)[0].Phi()-(*jets)[1].Phi() ) ; //Mjj = ((*jets)[0]+(*jets)[1]).M(); // for(unsigned k=0; k < jets->size(); k++){ //if(k>1 && // ( ((*jets)[k].Eta()>(*jets)[1].Eta()+0.5 && (*jets)[k].Eta()<(*jets)[0].Eta()-0.5) || // ((*jets)[k].Eta()>(*jets)[0].Eta()+0.5 && (*jets)[k].Eta()<(*jets)[1].Eta()-0.5) ) && (*jets)[k].Et()>ptVeto) ptVeto=(*jets)[k].Et(); //} diTauVisMass = (*diTauVisP4)[0].M(); diTauVisPt = (*diTauVisP4)[0].Pt(); diTauVisEta = (*diTauVisP4)[0].Eta(); //diTauCAPt = (*diTauICAP4)[0].Pt(); //diTauCAEta = (*diTauICAP4)[0].Eta(); diTauSVFitPt = (*diTauSVfit3P4)[0].Pt(); diTauSVFitEta = (*diTauSVfit3P4)[0].Eta(); diTauSVFitMass = (*diTauSVfit3P4)[0].M(); //jetsBtagHE1 = (*jetsBtagHE)[0]; //jetsBtagHE2 = (*jetsBtagHE)[1]; ptL1 = (*diTauLegsP4)[0].Pt(); ptL2 = (*diTauLegsP4)[1].Pt(); etaL1 = (*diTauLegsP4)[0].Eta(); etaL2 = (*diTauLegsP4)[1].Eta(); diTauCharge_ = diTauCharge; MtLeg1_ = MtLeg1; tightestHPSWP_ = tightestHPSWP; numPV_ = numPV; combRelIsoLeg1 = (chIsoLeg1+nhIsoLeg1+phIsoLeg1)/(*diTauLegsP4)[0].Pt(); sampleWeight = (scaleFactor>=0) ? scaleFactor : weight; HLT = (std::string(sample.Data())).find("Data")!=string::npos ? float((*tauXTriggers)[0]) : float((*tauXTriggers)[0]);//<--- isTauLegMatched_ = isTauLegMatched; outTreePtOrd->Fill(); } file->Close(); if(SAVE) outFile->Write(); outFile->Close(); delete jets; delete diTauLegsP4; delete diTauVisP4; delete diTauICAP4; delete diTauSVfit3P4; delete tauXTriggers; }
void PID_misidentification() { // -- define tuple file name, tuple name and cuts to apply----------------------- // -- and also the name of the output file const std::string filename = "/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/background_MC_samples/Bs2JpsiX_MC_2012_signal_withbdt.root"; const std::string treename = "withbdt"; const std::string outFilename("/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/background_MC_samples/Bs2JpsiX_MC_2012_signal_withbdt_misidentification.root"); TFile* file = TFile::Open( filename.c_str() ); if( !file ) std::cout << "file " << filename << " does not exist" << std::endl; TTree* tree = (TTree*)file->Get( treename.c_str() ); if( !tree ) std::cout << "tree " << treename << " does not exist" << std::endl; // -- activate the branches you need--------------------------------------------- tree->SetBranchStatus("*", 1); // -- this file is just here to make the 'CopyTree' happy TFile* dummyFile = new TFile("/afs/cern.ch/work/a/apmorris/private/cern/ntuples/dummy.root","RECREATE"); TTree* rTree1 = tree->CopyTree("bdtg>=0.85"); double chi_c_M, chi_c_P, chi_c_PE, chi_c_PT, chi_c_PX, chi_c_PY, chi_c_PZ, chi_c_ETA; double kaon_M, kaon_P, kaon_PE, kaon_PX, kaon_PT, kaon_PY, kaon_PZ, kaon_ETA, kaon_IPCHI2_OWNPV, kaon_TRACK_GhostProb, kaon_ProbNNp, kaon_ProbNNk; double proton_M, proton_P, proton_PE, proton_PT, proton_PX, proton_PY, proton_PZ, proton_ETA, proton_IPCHI2_OWNPV, proton_TRACK_GhostProb, proton_ProbNNp, proton_ProbNNk; double Jpsi_M, Jpsi_P, Jpsi_PE, Jpsi_PT, Jpsi_PX, Jpsi_PY, Jpsi_PZ, Jpsi_ETA; double gamma_M, gamma_P, gamma_PE, gamma_PT, gamma_PX, gamma_PY, gamma_PZ, gamma_ETA, gamma_CL; double muminus_M, muminus_P, muminus_PE, muminus_PT, muminus_PX, muminus_PY, muminus_PZ, muminus_ETA, muminus_ProbNNmu, muminus_TRACK_GhostProb; double muplus_M, muplus_P, muplus_PE, muplus_PT, muplus_PX, muplus_PY, muplus_PZ, muplus_ETA, muplus_ProbNNmu, muplus_TRACK_GhostProb; double Lambda_b0_DTF_MASS_constr1, Lambda_b0_DTF_CHI2NDOF, Lambda_b0_IPCHI2_OWNPV; double Lambda_b0_FDS, Lambda_b0_pi0veto, Lambda_b0_PT; float bdtg; bool Lambda_b0_L0MuonDecision_TOS, Lambda_b0_L0DiMuonDecision_TOS; bool Lambda_b0_Hlt1DiMuonHighMassDecision_TOS, Lambda_b0_Hlt1DiMuonLowMassDecision_TOS; bool Lambda_b0_Hlt1TrackMuonDecision_TOS, Lambda_b0_Hlt1TrackAllL0Decision_TOS; bool Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS, Lambda_b0_Hlt2DiMuonDetachedDecision_TOS; bool Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS; rTree1->SetBranchAddress("chi_c_M", &chi_c_M); rTree1->SetBranchAddress("chi_c_P", &chi_c_P); rTree1->SetBranchAddress("chi_c_PE", &chi_c_PE); rTree1->SetBranchAddress("chi_c_PT", &chi_c_PT); rTree1->SetBranchAddress("chi_c_PX", &chi_c_PX); rTree1->SetBranchAddress("chi_c_PY", &chi_c_PY); rTree1->SetBranchAddress("chi_c_PZ", &chi_c_PZ); //rTree1->SetBranchAddress("chi_c_ETA", &chi_c_ETA); rTree1->SetBranchAddress("kaon_M", &kaon_M); rTree1->SetBranchAddress("kaon_P", &kaon_P); rTree1->SetBranchAddress("kaon_PE", &kaon_PE); rTree1->SetBranchAddress("kaon_PX", &kaon_PX); rTree1->SetBranchAddress("kaon_PT", &kaon_PT); rTree1->SetBranchAddress("kaon_PY", &kaon_PY); rTree1->SetBranchAddress("kaon_PZ", &kaon_PZ); //rTree1->SetBranchAddress("kaon_ETA", &kaon_ETA); rTree1->SetBranchAddress("kaon_IPCHI2_OWNPV", &kaon_IPCHI2_OWNPV); rTree1->SetBranchAddress("kaon_TRACK_GhostProb", &kaon_TRACK_GhostProb); rTree1->SetBranchAddress("kaon_ProbNNp", &kaon_ProbNNp); rTree1->SetBranchAddress("kaon_ProbNNk", &kaon_ProbNNk); rTree1->SetBranchAddress("proton_M", &proton_M); rTree1->SetBranchAddress("proton_P", &proton_P); rTree1->SetBranchAddress("proton_PE", &proton_PE); rTree1->SetBranchAddress("proton_PT", &proton_PT); rTree1->SetBranchAddress("proton_PX", &proton_PX); rTree1->SetBranchAddress("proton_PY", &proton_PY); rTree1->SetBranchAddress("proton_PZ", &proton_PZ); //rTree1->SetBranchAddress("proton_ETA", &proton_ETA); rTree1->SetBranchAddress("proton_IPCHI2_OWNPV", &proton_IPCHI2_OWNPV); rTree1->SetBranchAddress("proton_TRACK_GhostProb", &proton_TRACK_GhostProb); rTree1->SetBranchAddress("proton_ProbNNp", &proton_ProbNNp); rTree1->SetBranchAddress("proton_ProbNNk", &proton_ProbNNk); rTree1->SetBranchAddress("Jpsi_M", &Jpsi_M); rTree1->SetBranchAddress("Jpsi_P", &Jpsi_P); rTree1->SetBranchAddress("Jpsi_PE", &Jpsi_PE); rTree1->SetBranchAddress("Jpsi_PT", &Jpsi_PT); rTree1->SetBranchAddress("Jpsi_PX", &Jpsi_PX); rTree1->SetBranchAddress("Jpsi_PY", &Jpsi_PY); rTree1->SetBranchAddress("Jpsi_PZ", &Jpsi_PZ); //rTree1->SetBranchAddress("Jpsi_ETA", &Jpsi_ETA); rTree1->SetBranchAddress("gamma_M", &gamma_M); rTree1->SetBranchAddress("gamma_P", &gamma_P); rTree1->SetBranchAddress("gamma_PE", &gamma_PE); rTree1->SetBranchAddress("gamma_PT", &gamma_PT); rTree1->SetBranchAddress("gamma_PX", &gamma_PX); rTree1->SetBranchAddress("gamma_PY", &gamma_PY); rTree1->SetBranchAddress("gamma_PZ", &gamma_PZ); //rTree1->SetBranchAddress("gamma_ETA", &gamma_ETA); rTree1->SetBranchAddress("gamma_CL", &gamma_CL); rTree1->SetBranchAddress("muminus_M", &muminus_M); rTree1->SetBranchAddress("muminus_P", &muminus_P); rTree1->SetBranchAddress("muminus_PE", &muminus_PE); rTree1->SetBranchAddress("muminus_PT", &muminus_PT); rTree1->SetBranchAddress("muminus_PX", &muminus_PX); rTree1->SetBranchAddress("muminus_PY", &muminus_PY); rTree1->SetBranchAddress("muminus_PZ", &muminus_PZ); //rTree1->SetBranchAddress("muminus_ETA", &muminus_ETA); rTree1->SetBranchAddress("muminus_ProbNNmu", &muminus_ProbNNmu); rTree1->SetBranchAddress("muminus_TRACK_GhostProb", &muminus_TRACK_GhostProb); rTree1->SetBranchAddress("muplus_M", &muplus_M); rTree1->SetBranchAddress("muplus_P", &muplus_P); rTree1->SetBranchAddress("muplus_PE", &muplus_PE); rTree1->SetBranchAddress("muplus_PT", &muplus_PT); rTree1->SetBranchAddress("muplus_PX", &muplus_PX); rTree1->SetBranchAddress("muplus_PY", &muplus_PY); rTree1->SetBranchAddress("muplus_PZ", &muplus_PZ); //rTree1->SetBranchAddress("muplus_ETA", &muplus_ETA); rTree1->SetBranchAddress("muplus_ProbNNmu", &muplus_ProbNNmu); rTree1->SetBranchAddress("muplus_TRACK_GhostProb", &muplus_TRACK_GhostProb); rTree1->SetBranchAddress("Lambda_b0_DTF_MASS_constr1", &Lambda_b0_DTF_MASS_constr1); rTree1->SetBranchAddress("Lambda_b0_DTF_CHI2NDOF", &Lambda_b0_DTF_CHI2NDOF); rTree1->SetBranchAddress("Lambda_b0_IPCHI2_OWNPV", &Lambda_b0_IPCHI2_OWNPV); rTree1->SetBranchAddress("Lambda_b0_L0DiMuonDecision_TOS", &Lambda_b0_L0DiMuonDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_L0MuonDecision_TOS", &Lambda_b0_L0MuonDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_FDS", &Lambda_b0_FDS); rTree1->SetBranchAddress("Lambda_b0_Hlt1DiMuonHighMassDecision_TOS", &Lambda_b0_Hlt1DiMuonHighMassDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt1DiMuonLowMassDecision_TOS", &Lambda_b0_Hlt1DiMuonLowMassDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt1TrackMuonDecision_TOS", &Lambda_b0_Hlt1TrackMuonDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt1TrackAllL0Decision_TOS", &Lambda_b0_Hlt1TrackAllL0Decision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS", &Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt2DiMuonDetachedDecision_TOS", &Lambda_b0_Hlt2DiMuonDetachedDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS", &Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS); rTree1->SetBranchAddress("Lambda_b0_pi0veto", &Lambda_b0_pi0veto); rTree1->SetBranchAddress("Lambda_b0_PT", &Lambda_b0_PT); rTree1->SetBranchAddress("bdtg", &bdtg); //------------------------------------------------------------------------------- TFile* rFile = new TFile( outFilename.c_str() ,"RECREATE"); TTree* rTree2 = new TTree(); rTree2->SetName("withbdt"); rTree2->Branch("chi_c_M", &chi_c_M, "chi_c_M/D"); rTree2->Branch("chi_c_P", &chi_c_P, "chi_c_P/D"); rTree2->Branch("chi_c_PE", &chi_c_PE, "chi_c_PE/D"); rTree2->Branch("chi_c_PT", &chi_c_PT, "chi_c_PT/D"); rTree2->Branch("chi_c_PX", &chi_c_PX, "chi_c_PX/D"); rTree2->Branch("chi_c_PY", &chi_c_PY, "chi_c_PY/D"); rTree2->Branch("chi_c_PZ", &chi_c_PZ, "chi_c_PZ/D"); //rTree2->Branch("chi_c_ETA", &chi_c_ETA, "chi_c_ETA/D"); rTree2->Branch("kaon_M", &kaon_M, "kaon_M/D"); rTree2->Branch("kaon_P", &kaon_P, "kaon_P/D"); rTree2->Branch("kaon_PE", &kaon_PE, "kaon_PE/D"); rTree2->Branch("kaon_PX", &kaon_PX, "kaon_PX/D"); rTree2->Branch("kaon_PT", &kaon_PT, "kaon_PT/D"); rTree2->Branch("kaon_PY", &kaon_PY, "kaon_PY/D"); rTree2->Branch("kaon_PZ", &kaon_PZ, "kaon_PZ/D"); //rTree2->Branch("kaon_ETA", &kaon_ETA, "kaon_ETA/D"); rTree2->Branch("kaon_IPCHI2_OWNPV", &kaon_IPCHI2_OWNPV, "kaon_IPCHI2_OWNPV/D"); rTree2->Branch("kaon_TRACK_GhostProb", &kaon_TRACK_GhostProb, "kaon_TRACK_GhostProb/D"); rTree2->Branch("kaon_ProbNNp", &kaon_ProbNNp, "kaon_ProbNNp/D"); rTree2->Branch("kaon_ProbNNk", &kaon_ProbNNk, "kaon_ProbNNk/D"); rTree2->Branch("proton_M", &proton_M, "proton_M/D"); rTree2->Branch("proton_P", &proton_P, "proton_P/D"); rTree2->Branch("proton_PE", &proton_PE, "proton_PE/D"); rTree2->Branch("proton_PT", &proton_PT, "proton_PT/D"); rTree2->Branch("proton_PX", &proton_PX, "proton_PX/D"); rTree2->Branch("proton_PY", &proton_PY, "proton_PY/D"); rTree2->Branch("proton_PZ", &proton_PZ, "proton_PZ/D"); //rTree2->Branch("proton_ETA", &proton_ETA, "proton_ETA/D"); rTree2->Branch("proton_IPCHI2_OWNPV", &proton_IPCHI2_OWNPV, "proton_IPCHI2_OWNPV/D"); rTree2->Branch("proton_TRACK_GhostProb", &proton_TRACK_GhostProb, "proton_TRACK_GhostProb/D"); rTree2->Branch("proton_ProbNNp", &proton_ProbNNp, "proton_ProbNNp/D"); rTree2->Branch("proton_ProbNNk", &proton_ProbNNk, "proton_ProbNNk/D"); rTree2->Branch("Jpsi_M", &Jpsi_M, "Jpsi_M/D"); rTree2->Branch("Jpsi_P", &Jpsi_P, "Jpsi_P/D"); rTree2->Branch("Jpsi_PE", &Jpsi_PE, "Jpsi_PE/D"); rTree2->Branch("Jpsi_PT", &Jpsi_PT, "Jpsi_PT/D"); rTree2->Branch("Jpsi_PX", &Jpsi_PX, "Jpsi_PX/D"); rTree2->Branch("Jpsi_PY", &Jpsi_PY, "Jpsi_PY/D"); rTree2->Branch("Jpsi_PZ", &Jpsi_PZ, "Jpsi_PZ/D"); //rTree2->Branch("Jpsi_ETA", &Jpsi_ETA, "Jpsi_ETA/D"); rTree2->Branch("gamma_M", &gamma_M, "gamma_M/D"); rTree2->Branch("gamma_P", &gamma_P, "gamma_P/D"); rTree2->Branch("gamma_PE", &gamma_PE, "gamma_PE/D"); rTree2->Branch("gamma_PT", &gamma_PT, "gamma_PT/D"); rTree2->Branch("gamma_PX", &gamma_PX, "gamma_PX/D"); rTree2->Branch("gamma_PY", &gamma_PY, "gamma_PY/D"); rTree2->Branch("gamma_PZ", &gamma_PZ, "gamma_PZ/D"); //rTree2->Branch("gamma_ETA", &gamma_ETA, "gamma_ETA/D"); rTree2->Branch("gamma_CL", &gamma_CL, "gamma_CL/D"); rTree2->Branch("muminus_M", &muminus_M, "muminus_M/D"); rTree2->Branch("muminus_P", &muminus_P, "muminus_P/D"); rTree2->Branch("muminus_PE", &muminus_PE, "muminus_PE/D"); rTree2->Branch("muminus_PT", &muminus_PT, "muminus_PT/D"); rTree2->Branch("muminus_PX", &muminus_PX, "muminus_PX/D"); rTree2->Branch("muminus_PY", &muminus_PY, "muminus_PY/D"); rTree2->Branch("muminus_PZ", &muminus_PZ, "muminus_PZ/D"); //rTree2->Branch("muminus_ETA", &muminus_ETA, "muminus_ETA/D"); rTree2->Branch("muminus_ProbNNmu", &muminus_ProbNNmu, "muminus_ProbNNmu/D"); rTree2->Branch("muminus_TRACK_GhostProb", &muminus_TRACK_GhostProb, "muminus_TRACK_GhostProb/D"); rTree2->Branch("muplus_M", &muplus_M, "muplus_M/D"); rTree2->Branch("muplus_P", &muplus_P, "muplus_P/D"); rTree2->Branch("muplus_PE", &muplus_PE, "muplus_PE/D"); rTree2->Branch("muplus_PT", &muplus_PT, "muplus_PT/D"); rTree2->Branch("muplus_PX", &muplus_PX, "muplus_PX/D"); rTree2->Branch("muplus_PY", &muplus_PY, "muplus_PY/D"); rTree2->Branch("muplus_PZ", &muplus_PZ, "muplus_PZ/D"); //rTree2->Branch("muplus_ETA", &muplus_ETA, "muplus_ETA/D"); rTree2->Branch("muplus_ProbNNmu", &muplus_ProbNNmu, "muplus_ProbNNmu/D"); rTree2->Branch("muplus_TRACK_GhostProb", &muplus_TRACK_GhostProb, "muplus_TRACK_GhostProb/D"); rTree2->Branch("Lambda_b0_DTF_MASS_constr1", &Lambda_b0_DTF_MASS_constr1, "Lambda_b0_DTF_MASS_constr1/D"); rTree2->Branch("Lambda_b0_DTF_CHI2NDOF", &Lambda_b0_DTF_CHI2NDOF, "Lambda_b0_DTF_CHI2NDOF/D"); rTree2->Branch("Lambda_b0_IPCHI2_OWNPV", &Lambda_b0_IPCHI2_OWNPV, "Lambda_b0_IPCHI2_OWNPV/D"); rTree2->Branch("Lambda_b0_L0DiMuonDecision_TOS", &Lambda_b0_L0DiMuonDecision_TOS, "Lambda_b0_L0DiMuonDecision_TOS/B"); rTree2->Branch("Lambda_b0_L0MuonDecision_TOS", &Lambda_b0_L0MuonDecision_TOS, "Lambda_b0_L0MuonDecision_TOS/B"); rTree2->Branch("Lambda_b0_FDS", &Lambda_b0_FDS, "Lambda_b0_FDS/D"); rTree2->Branch("Lambda_b0_Hlt1DiMuonHighMassDecision_TOS", &Lambda_b0_Hlt1DiMuonHighMassDecision_TOS, "Lambda_b0_Hlt1DiMuonHighMassDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt1DiMuonLowMassDecision_TOS", &Lambda_b0_Hlt1DiMuonLowMassDecision_TOS, "Lambda_b0_Hlt1DiMuonLowMassDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt1TrackMuonDecision_TOS", &Lambda_b0_Hlt1TrackMuonDecision_TOS, "Lambda_b0_Hlt1TrackMuonDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt1TrackAllL0Decision_TOS", &Lambda_b0_Hlt1TrackAllL0Decision_TOS, "Lambda_b0_Hlt1TrackAllL0Decision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS", &Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS, "Lambda_b0_Hlt1SingleMuonHighPTDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt2DiMuonDetachedDecision_TOS", &Lambda_b0_Hlt2DiMuonDetachedDecision_TOS, "Lambda_b0_Hlt2DiMuonDetachedDecision_TOS/B"); rTree2->Branch("Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS", &Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS, "Lambda_b0_Hlt2DiMuonDetachedHeavyDecision_TOS/B"); rTree2->Branch("Lambda_b0_pi0veto", &Lambda_b0_pi0veto, "Lambda_b0_pi0veto/D"); rTree2->Branch("Lambda_b0_PT", &Lambda_b0_PT, "Lambda_b0_PT/D"); rTree2->Branch("bdtg", &bdtg, "bdtg/F"); //This is where the misidentification is calculated for P and K--------------------------- const double mK(0.493677); double mass_proton_as_proton, mass_proton_as_kaon, mass_kaon_as_kaon; rTree2->Branch("mass_proton_as_proton", &mass_proton_as_proton, "mass_proton_as_proton/D"); rTree2->Branch("mass_proton_as_kaon", &mass_proton_as_kaon, "mass_proton_as_kaon/D"); rTree2->Branch("mass_kaon_as_kaon", &mass_kaon_as_kaon, "mass_kaon_as_kaon/D"); double proton_P = sqrt(proton_PX*proton_PX + proton_PY*proton_PY + proton_PZ*proton_PZ) ; for(int i = 0; i < rTree1->GetEntries(); ++i){ //for event in tree rTree1->GetEntry(i); TLorentzVector * proton = new TLorentzVector(proton_PX, proton_PY, proton_PZ, proton_PE); TLorentzVector * proton_as_kaon = new TLorentzVector(proton_PX, proton_PY, proton_PZ, sqrt(proton_P*proton_P + mK*mK)); TLorentzVector * kaon = new TLorentzVector(kaon_PX, kaon_PY, kaon_PZ, kaon_PE); mass_proton_as_proton = proton->M(); mass_proton_as_kaon = proton_as_kaon->M(); mass_kaon_as_kaon = kaon->M(); rTree2->Fill(); } rTree2->Print(); rTree2->Write(); rFile->Save(); }
void DoSimple1() { // gROOT->ProcessLine(".L AdScaled.C+"); ifstream runlist; runlist.open("recon.list"); string run; while( getline(runlist,run) ) { cout<<"Now is processing "<<TString(run)<<endl; TFile *oldfile = new TFile(TString(run)); TTree *oldtree = (TTree*)oldfile->Get("/Event/Rec/AdScaled"); oldtree->SetBranchStatus("*",0); oldtree->SetBranchStatus("site", 1); oldtree->SetBranchStatus("detector",1); oldtree->SetBranchStatus("triggerType",1); oldtree->SetBranchStatus("triggerNumber",1); oldtree->SetBranchStatus("triggerTimeSec",1); oldtree->SetBranchStatus("triggerTimeNanoSec",1); oldtree->SetBranchStatus("energy",1); oldtree->SetBranchStatus("rawEvis",1); oldtree->SetBranchStatus("enrec",1); oldtree->SetBranchStatus("eprec",1); oldtree->SetBranchStatus("x",1); oldtree->SetBranchStatus("y",1); oldtree->SetBranchStatus("z",1); TTree *oldtree1 = (TTree*)oldfile->Get("/Event/Data/CalibStats"); oldtree1->SetBranchStatus("*",0); oldtree1->SetBranchStatus("nHit", 1); oldtree1->SetBranchStatus("MaxQ",1); oldtree1->SetBranchStatus("Quadrant",1); oldtree1->SetBranchStatus("MaxQ_2inchPMT",1); oldtree1->SetBranchStatus("Column_2inchPMT",1); oldtree1->SetBranchStatus("MiddleTimeRMS",1); oldtree1->SetBranchStatus("tRMS",1); oldtree1->SetBranchStatus("nPEMax",1); oldtree1->SetBranchStatus("nPEMedian",1); oldtree1->SetBranchStatus("nPERMS",1); oldtree1->SetBranchStatus("nPESum",1); TTree *oldtree2 = (TTree*)oldfile->Get("/Event/CalibReadout/CalibReadoutHeader"); oldtree2->SetBranchStatus("*",0); oldtree2->SetBranchStatus("nHitsRpc", 1); oldtree2->SetBranchStatus("rpcRow", 1); oldtree2->SetBranchStatus("rpcColumn", 1); oldtree2->SetBranchStatus("rpcLayer", 1); TFile *newfile = new TFile("small.root","recreate"); gDirectory->mkdir("Event"); gDirectory->cd("Event"); gDirectory->mkdir("Rec"); gDirectory->mkdir("Data"); gDirectory->mkdir("CalibReadout"); gDirectory->cd("Rec"); TTree *newtree = oldtree->CloneTree(); gDirectory->cd("../Data"); TTree *newtree1 = oldtree1->CloneTree(); gDirectory->cd("../CalibReadout"); TTree *newtree2 = oldtree2->CloneTree(); newfile->Write(); delete oldfile; delete newfile; } }