#define small_ana_cxx // The class definition in small_ana.h has been generated automatically // by the ROOT utility TTree::MakeSelector(). This class is derived // from the ROOT class TSelector. For more information on the TSelector // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual. // The following methods are defined in this file: // Begin(): called every time a loop on the tree starts, // a convenient place to create your histograms. // SlaveBegin(): called after Begin(), when on PROOF called only on the // slave servers. // Process(): called for each event, in this function you decide what // to read and fill your histograms. // SlaveTerminate: called at the end of the loop on the tree, when on PROOF // called only on the slave servers. // Terminate(): called at the end of the loop on the tree, // a convenient place to draw/fit your histograms. // // To use this file, try the following session on your Tree T: // // root> T->Process("small_ana.C") // root> T->Process("small_ana.C","some options") // root> T->Process("small_ana.C+") // #include "small_ana.h" #include #include void small_ana::Begin(TTree * /*tree*/) { // The Begin() function is called at the start of the query. // When running with PROOF Begin() is only called on the client. // The tree argument is deprecated (on PROOF 0 is passed). TString option = GetOption(); } void small_ana::SlaveBegin(TTree * /*tree*/) { // The SlaveBegin() function is called after the Begin() function. // When running with PROOF SlaveBegin() is called on each slave server. // The tree argument is deprecated (on PROOF 0 is passed). TString option = GetOption(); int nbin = 100.; double xmax = 200.; hnl_invmass = new TH1F("hnl_invmass","",nbin,0.,xmax); hnl_invmass_trkmet = new TH1F("hnl_invmass_trkmet","",nbin,0.,xmax); hnl_invmass_truthmet = new TH1F("hnl_invmass_truthmet","",nbin,0.,xmax); hnl_invmass_truthmetxy = new TH1F("hnl_invmass_truthmetxy","",nbin,0.,xmax); hnl_invmass_truthmet2 = new TH2F("hnl_invmass_truthmet2","",nbin,0.,xmax,nbin,0.,xmax); hnl_invmass_mlp = new TH1F("hnl_invmass_mlp","",nbin,0.,xmax); hnl_invmass_mlp3 = new TH1F("hnl_invmass_mlp3","",nbin,0.,xmax); hnl_invmass_mlp4 = new TH1F("hnl_invmass_mlp4","",nbin,0.,xmax); hnl_invmass_mlp5 = new TH1F("hnl_invmass_mlp5","",nbin,0.,xmax); hnl_invmass_mlp6 = new TH1F("hnl_invmass_mlp6","",nbin,0.,xmax); W_invmass = new TH1F("W_invmass","",400,0.,200); W_invmass_mlp3 = new TH1F("W_invmass_mlp3","",400,0.,200); W_invmass_mlp4 = new TH1F("W_invmass_mlp4","",400,0.,200); reso_pznu = new TH2F("reso_pznu","",200,-50,50,200,-50,50.); reso2_pznu = new TH2F("reso2_pznu","",200,-50,50,200,-50,50.); reso4_pznu = new TH2F("reso4_pznu","",200,-50,50,200,-50,50.); reso5_pznu = new TH2F("reso5_pznu","",200,-50,50,200,-50,50.); fOutput->Add(hnl_invmass); fOutput->Add(hnl_invmass_trkmet); fOutput->Add(hnl_invmass_truthmetxy); fOutput->Add(hnl_invmass_truthmet); fOutput->Add(hnl_invmass_truthmet2); fOutput->Add(hnl_invmass_mlp); fOutput->Add(hnl_invmass_mlp3); fOutput->Add(hnl_invmass_mlp4); fOutput->Add(hnl_invmass_mlp5); fOutput->Add(hnl_invmass_mlp6); fOutput->Add(W_invmass); fOutput->Add(W_invmass_mlp3); fOutput->Add(W_invmass_mlp4); fOutput->Add(reso_pznu); fOutput->Add(reso2_pznu); fOutput->Add(reso4_pznu); fOutput->Add(reso5_pznu); // // const char* fullfilepath = gSystem->ExpandPathName("/Users/testa/HL_Analysis/regression/TMVAReg_allsig-wjets_4k.root"); // const char* fullfilepath = gSystem->ExpandPathName("/Users/testa/HL_Analysis/regression/TMVAReg_sig10-wjets_4k.root"); const char* fullfilepath = gSystem->ExpandPathName("/Users/testa/HL_Analysis/regression/TMVAReg_sig10_1k.root"); auto file = TFile::Open(fullfilepath); my_map = getMap(fullfilepath); my_map2 = getMap2(fullfilepath); cout<<"dopo getmap"<AddVariable( "BL_LepPt[0]*cos(BL_LepPhi[0])", &lep1_px); reader6->AddVariable( "BL_LepPt[1]*cos(BL_LepPhi[1])", &lep2_px); reader6->AddVariable( "BL_LepPt[2]*cos(BL_LepPhi[2])", &lep3_py); reader6->AddVariable( "MET_px - MET_SoftTrk_px + BL_LepPt[0]*cos(BL_LepPhi[0])+ BL_LepPt[1]*cos(BL_LepPhi[1])+ BL_LepPt[2]*cos(BL_LepPhi[2])", &met_rest_px ); reader6->AddVariable( "MET_SoftTrk_px", &softmet_px); reader6->AddVariable("BL_LepPt[0]+BL_LepPt[1]+BL_LepPt[2]",&ptall_lep); reader6->AddVariable( "BL_LepPt[0]*sin(BL_LepPhi[0])", &lep1_py); reader6->AddVariable( "BL_LepPt[1]*sin(BL_LepPhi[1])", &lep2_py); reader6->AddVariable( "BL_LepPt[2]*sin(BL_LepPhi[2])", &lep3_py); reader6->AddVariable( "MET_py-MET_SoftTrk_py+BL_LepPt[0]*sin(BL_LepPhi[0])+BL_LepPt[1]*sin(BL_LepPhi[1])+BL_LepPt[2]*sin(BL_LepPhi[2])", &met_rest_py ); reader6->AddVariable( "MET_SoftTrk_py", &softmet_py); reader6->AddSpectator( "MET_px", &ssspec1 ); reader6->AddSpectator( "MET_py", &ssspec2 ); reader6->AddSpectator( "MET_px_truth", &ssspec3 ); reader6->AddSpectator( "MET_py_truth", &ssspec4 ); reader6->AddSpectator( "MET_pz_truth", &ssspec5 ); reader6->AddSpectator( "year" ,&m_year); reader6->AddSpectator("EventNumber", &m_eventnumber); // reader6->BookMVA( "MLP invmass", "/Users/testa/HL_Analysis/regression/weights/sig10-30-50_invmass_11var_njet0_ch_dphilet1.xml"); // reader6->BookMVA( "MLP invmass", "/Users/testa/HL_Analysis/regression/weights/sig10_invmass_11var_njet0_ch_dphilet1.xml"); // reader6->BookMVA( "MLP invmass", "/Users/testa/HL_Analysis/regression/weights/TMVARegression_BDTG.weights_allsig-wjet_4k.xml"); // reader6->BookMVA( "BDTG", "/Users/testa/HL_Analysis/regression/weights/TMVARegression_BDTG.weights_sig10-wjet_4k.xml"); reader6->BookMVA( "BDTG", "/Users/testa/HL_Analysis/regression/weights/TMVARegression_BDTG.weights_sig10_1k.xml"); } Bool_t small_ana::Process(Long64_t entry) { // The Process() function is called for each entry in the tree (or possibly // keyed object in the case of PROOF) to be processed. The entry argument // specifies which entry in the currently loaded tree is to be processed. // It can be passed to either small_ana::GetEntry() or TBranch::GetEntry() // to read either all or the required parts of the data. When processing // keyed objects with PROOF, the object is already loaded and is available // via the fObject pointer. // // This function should contain the "body" of the analysis. It can contain // simple or elaborate selection criteria, run algorithms on the data // of the event and typically fill histograms. // // The processing can be stopped by calling Abort(). // // Use fStatus to set the return value of TTree::Process(). // // The return value is currently not used. fChain->GetTree()->GetEntry(entry); double weight = 1.;//XSecWeight; // double weight = XSecWeight; // m_mu = actualIntPerXing; // my_map = getMap(fullfilepath); // auto iterator = my_map.find( eventInfo->eventNumber() ); auto iterator = my_map.find( EventNumber ); if (iterator != my_map.end()) { float temp = my_map[EventNumber]; // std::cout<<"found "<eventNumber()]; m_bdtg_invmass = my_map2[EventNumber]; // std::cout<<"found "<EvaluateRegression( "BDTG" ))[0]; TLorentzVector met6_tl; cout<<"comp "<at(0)*TMath::Cos(BL_LepPhi->at(0))<<" "<Fill(invmass_mlp6,weight); return kTRUE; } void small_ana::SlaveTerminate() { // The SlaveTerminate() function is called after all entries or objects // have been processed. When running with PROOF SlaveTerminate() is called // on each slave server. } void small_ana::Terminate() { // The Terminate() function is the last function to be called during // a query. It always runs on the client, it can be used to present // the results graphically or save the results to file. hnl_invmass =dynamic_cast(fOutput->FindObject("hnl_invmass")); hnl_invmass_trkmet =dynamic_cast(fOutput->FindObject("hnl_invmass_trkmet")); hnl_invmass_truthmet =dynamic_cast(fOutput->FindObject("hnl_invmass_truthmet")); hnl_invmass_truthmetxy =dynamic_cast(fOutput->FindObject("hnl_invmass_truthmetxy")); hnl_invmass_truthmet2 =dynamic_cast(fOutput->FindObject("hnl_invmass_truthmet2")); reso_pznu =dynamic_cast(fOutput->FindObject("reso_pznu")); reso2_pznu =dynamic_cast(fOutput->FindObject("reso2_pznu")); reso4_pznu =dynamic_cast(fOutput->FindObject("reso4_pznu")); hnl_invmass_mlp =dynamic_cast(fOutput->FindObject("hnl_invmass_mlp")); hnl_invmass_mlp3 =dynamic_cast(fOutput->FindObject("hnl_invmass_mlp3")); W_invmass_mlp3 =dynamic_cast(fOutput->FindObject("W_invmass_mlp3")); hnl_invmass_mlp4 =dynamic_cast(fOutput->FindObject("hnl_invmass_mlp4")); W_invmass_mlp4 =dynamic_cast(fOutput->FindObject("W_invmass_mlp4")); TFile efile("elist.root","recreate"); fOutput->Write(); efile.Close(); } TLorentzVector small_ana::calcHN( TLorentzVector pl1, int ch1, TLorentzVector pl2, int ch2, TLorentzVector pl3, int ch3, double pxm, double pym) { // // std::cout<<"pxm "< calcpznu( TLorentzVector, double, double, double); TLorentzVector HN; TLorentzVector nur1; TLorentzVector nur2; TLorentzVector pl=pl1+pl2+pl3; auto pznout=calcpznu( pl, pxm, pym, 80*GeV); double pzn1=std::get<0>(pznout); double pzn2=std::get<1>(pznout); // int idisc=std::get<2>(pznout); // // store as solution 1 the one // yielding highest pzW // double pzwr1=pl.Pz()+pzn1; double pzwr2=pl.Pz()+pzn2; double dum; // order neutrino momenta based on pzw if(abs(pzwr2)>abs(pzwr1)){ dum=pzn1; pzn1=pzn2; pzn2=dum; } nur1.SetPxPyPzE (pxm,pym,pzn1,sqrt(pxm*pxm+pym*pym+pzn1*pzn1)); // // default: lepton from W is the one with // highest pt // HN=pl2+pl3+nur1; // // if leptons 2 and 3 have same charge, leptons from HN // are 2 and 3 // if(abs(ch2+ch3)==2)HN=pl1+pl3+nur1; return HN; } TLorentzVector small_ana::calcHN_inv( TLorentzVector pl1, int ch1, TLorentzVector pl2, int ch2, TLorentzVector pl3, int ch3, double pxm, double pym) { // // std::cout<<"pxm "< calcpznu( TLorentzVector, double, double, double); TLorentzVector HN; TLorentzVector nur1; TLorentzVector nur2; TLorentzVector pl=pl1+pl2+pl3; auto pznout=calcpznu( pl, pxm, pym, 80*GeV); double pzn1=std::get<0>(pznout); double pzn2=std::get<1>(pznout); // int idisc=std::get<2>(pznout); // // store as solution 1 the one // yielding lowest pzW // double pzwr1=pl.Pz()+pzn1; double pzwr2=pl.Pz()+pzn2; double dum; // order neutrino momenta based on pzw if(abs(pzwr2) small_ana::calcpznu( TLorentzVector pl, double pxnu, double pynu, double mw) { double ml=pl.M(); double pxl=pl.X(); double pyl=pl.Y(); double pzl=pl.Z(); double eel=pl.E(); double ptnus=pxnu*pxnu+pynu*pynu; double C=ml*ml-2*pxnu*pxl-2*pynu*pyl; double A=2*eel; double B=-2*pzl; double A1=(A*A-B*B); double Cm=C-mw*mw; double B1=-2.*B*Cm; double C1=A*A*ptnus-Cm*Cm; double disc=B1*B1-4*A1*C1; int idisc=1; if(disc<0){ disc=0.; idisc=-1; } double pzn1=(-B1+sqrt(disc))/2./A1; double pzn2=(-B1-sqrt(disc))/2./A1; return std::make_tuple(pzn1,pzn2,idisc); } std::map small_ana::getMap(std::string path_to_rootfile) { auto file = TFile::Open(path_to_rootfile.c_str()); TTreeReader reader("TestTree", file); TTreeReaderValue m_eventnumber(reader, "EventNumber"); std::map event_t0; while(reader.Next()) { if(1) { // if(*m_hast0) { // event_t0[*m_eventnumber] = *m_t0; event_t0[*m_eventnumber] = *m_eventnumber; // std::cout<<"In getmap "<< event_t0[*m_eventnumber] <<" "<<*m_eventnumber<Close(); return event_t0; } std::map small_ana::getMap2(std::string path_to_rootfile) { auto file = TFile::Open(path_to_rootfile.c_str()); TTreeReader reader("TestTree", file); TTreeReaderValue m_bdtg_invmass(reader, "BDTG.invmass"); // TTreeReaderValue m_bdtg_invmass(reader, "MET_SoftTrk_px"); // TTreeReaderValue m_bdtg_invmass(reader, "lep0x"); TTreeReaderValue m_eventnumber(reader, "EventNumber"); std::map event_BDTG; while(reader.Next()) { if(1) { // if(*m_hast0) { // event_t0[*m_eventnumber] = *m_t0; // event_BDTG[*m_eventnumber] = *m_bdtg_invmass; event_BDTG[*m_eventnumber] = *m_bdtg_invmass; if (*m_eventnumber==181021)std::cout<<"In getmap2 "<< event_BDTG[*m_eventnumber] <<" "<<*m_bdtg_invmass<<" "<<*m_eventnumber<Close(); return event_BDTG; }