void LHCOWriter::AnalyseJets() { Jet *element; Track *track; Int_t counter; fItJet->Reset(); while((element = static_cast<Jet*>(fItJet->Next()))) { if(element->TauTag != 0) continue; Reset(); counter = 0; fItTrack->Reset(); while((track = static_cast<Track*>(fItTrack->Next()))) { if(element->P4().DeltaR(track->P4()) < 0.5) ++counter; } fIntParam[1] = 4; fDblParam[0] = element->Eta; fDblParam[1] = element->Phi; fDblParam[2] = element->PT; fDblParam[3] = element->Mass; fDblParam[4] = counter; fDblParam[5] = element->BTag; fDblParam[6] = element->EhadOverEem; Write(); } }
bool Analysis::DphiCuts(){ bool IsCutPass = false; if (branchJet && branchMissingET){ MissingET *met = (MissingET*) branchMissingET->At(0); int nJets = branchJet->GetEntriesFast(); for (int i=0; i < nJets; i++){ Jet *jet = (Jet*) branchJet->At(i); if (jet->PT > 200.){ if (jet->P4().DeltaR(met->P4()) > 1.) IsCutPass=true; else {IsCutPass=false; break;} } } } IsEventPass = IsEventPass && IsCutPass; return IsCutPass; }
//void LeptonEnergy(const char *inputFile = "sourceFiles/LO/ttbar_LO_total.root") void LeptonEnergy(const TString & file) { //const char *inputFile = Form("/home/tjkim/work/pheno/topmass/sourceFiles/LO/fromSayaka/ttbar_%s.root",file.Data()); //gSystem->Load("/export/apps/delphes//libDelphes"); const char *inputFile = Form("/data/users/seohyun/analysis/ttbar_%s.root",file.Data()); gSystem->Load("/home/seohyun/delphes/libDelphes.so"); /* TFile *f2 = TFile::Open("weightfunc2.root"); TFile *f3 = TFile::Open("weightfunc3.root"); TFile *f5 = TFile::Open("weightfunc5.root"); TFile *f15 = TFile::Open("weightfunc15.root"); const int nmass = 151; float mymass[ nmass ]; float integral2[ nmass ]; float integral3[ nmass ]; float integral5[ nmass ]; float integral15[ nmass ]; for(int i=0; i < nmass ; i++){ integral2[i] = 0.0; integral3[i] = 0.0; integral5[i] = 0.0; integral15[i] = 0.0; } TGraph * g2[nmass]; TGraph * g3[nmass]; TGraph * g5[nmass]; TGraph * g15[nmass]; TIter next(f2->GetListOfKeys()); TKey *key; int i = 0; while( (key = (TKey*) next())) { TClass *cl = gROOT->GetClass( key->GetClassName()); if( !cl->InheritsFrom("TGraph")) continue; g2[i] = (TGraph*) key->ReadObj(); string mass = g2[i]->GetName(); float temp = atof(mass.c_str()); mymass[i] = temp; i++; } TIter next(f3->GetListOfKeys()); i = 0; while( (key = (TKey*) next())) { TClass *cl = gROOT->GetClass( key->GetClassName()); if( !cl->InheritsFrom("TGraph")) continue; g3[i] = (TGraph*) key->ReadObj(); i++; } TIter next(f5->GetListOfKeys()); i = 0; while( (key = (TKey*) next())) { TClass *cl = gROOT->GetClass( key->GetClassName()); if( !cl->InheritsFrom("TGraph")) continue; g5[i] = (TGraph*) key->ReadObj(); i++; } TIter next(f15->GetListOfKeys()); i = 0; while( (key = (TKey*) next())) { TClass *cl = gROOT->GetClass( key->GetClassName()); if( !cl->InheritsFrom("TGraph")) continue; g15[i] = (TGraph*) key->ReadObj(); i++; } TFile * res = TFile::Open("hist_LO_res_v3.root"); TH1F * h_acc = (TH1F*) res->Get("h_totalacc_lepton"); */ //TFile* f = TFile::Open("hist_LO_res_60.root", "recreate"); TFile* f = TFile::Open(Form("170717/hist_%s.root",file.Data()), "recreate"); // Create chain of root trees TChain chain("Delphes"); chain.Add(inputFile); // Create object of class ExRootTreeReader ExRootTreeReader *treeReader = new ExRootTreeReader(&chain); Long64_t numberOfEntries = treeReader->GetEntries(); // Get pointers to branches used in this analysis TClonesArray *branchParticle = treeReader->UseBranch("Particle"); TClonesArray *branchMuon = treeReader->UseBranch("Muon"); TClonesArray *branchElectron = treeReader->UseBranch("Electron"); TClonesArray *branchJet = treeReader->UseBranch("Jet"); TClonesArray *branchEvent = treeReader->UseBranch("Event"); GenParticle *particle; GenParticle *daughter1; GenParticle *daughter2; GenParticle *granddaughter1_1; GenParticle *granddaughter1_2; GenParticle *granddaughter2_1; GenParticle *granddaughter2_2; GenParticle *genelectron; GenParticle *genmuon; LHEFEvent * event; // Create TTree //Float_t Muon_E; //Float_t Electron_E; //Float_t Lepton_E; //Float_t Lepton_E_reco; //TTree * tree = new TTree("tree","lepton energy"); //tree->Branch("Lepton_E",&Lepton_E,"Lepton_E/F"); //tree->Branch("Lepton_E_reco",&Lepton_E_reco,"Lepton_E_reco/F"); //tree->Branch("Muon_E",&Muon_E,"Muon_E/F"); //tree->Branch("Electron_E",&Electron_E,"Electron_E/F"); // Book histograms TH1 * channel = new TH1F("channel", "ttbar event categorization", 7, 0.0, 7.0); TH1 * h_muon_energy = new TH1F("h_muon_energy", "muon energy distribution", 5000, 0, 500); TH1 * h_electron_energy = new TH1F("h_electron_energy", "electron energy distribution", 5000, 0, 500); TH1 * h_lepton_energy = new TH1F("h_lepton_energy", "lepton energy distribution", 5000, 0, 500); //TH1 * h_muon_energy_acc = new TH1F("h_muon_energy_acc", "muon energy distribution", 5000, 0, 500); //TH1 * h_electron_energy_acc = new TH1F("h_electron_energy_acc", "electron energy distribution", 5000, 0, 500); TH1 * h_lepton_energy_acc = new TH1F("h_lepton_energy_acc", "lepton energy distribution", 5000, 0, 500); //TH1 * h_muon_energy_reco = new TH1F("h_muon_energy_reco", "muon energy distribution at RECO", 5000, 0, 500); //TH1 * h_electron_energy_reco = new TH1F("h_electron_energy_reco", "electron energy distribution at RECO", 5000, 0, 500); TH1 * h_lepton_energy_reco = new TH1F("h_lepton_energy_reco", "lepton energy distribution at RECO", 5000, 0, 500); TH2 * h2_lepton_energy_response = new TH2F("h2_lepton_energy_response", "lepton energy response", 5000, 0, 500,5000,0,500); //TH1 * h_muon_energy_reco_S2 = new TH1F("h_muon_energy_reco_S2", "muon energy distribution at RECO", 5000, 0, 500); //TH1 * h_electron_energy_reco_S2 = new TH1F("h_electron_energy_reco_S2", "electron energy distribution at RECO", 5000, 0, 500); //TH1 * h_lepton_energy_reco_S2 = new TH1F("h_lepton_energy_reco_S2", "lepton energy distribution at RECO", 5000, 0, 500); //TH1 * h_lepton_nbjets_reco_S2 = new TH1F("h_lepton_nbjets_reco_S2","number of b jets",5,0,5); //TH1 * h_muon_energy_reco_final = new TH1F("h_muon_energy_reco_final", "muon energy distribution at RECO", 5000, 0, 500); //TH1 * h_electron_energy_reco_final = new TH1F("h_electron_energy_reco_final", "electron energy distribution at RECO", 5000, 0, 500); TH1 * h_lepton_energy_reco_final = new TH1F("h_lepton_energy_reco_final", "lepton energy distribution at RECO", 5000, 0, 500); TH2 * h2_lepton_energy_final_response = new TH2F("h2_lepton_energy_final_response", "lepton energy response", 5000, 0, 500,5000,0,500); //std::vector<float> lepton_E; //std::vector<float> lepton_E_final; int ndileptonic = 0; //ee, mm, tautau int ndileptonic2 = 0; //ee, mm, tau->ee, mm int ndileptonic3 = 0; //ee, mm int nsemileptonic = 0; int nsemileptonic2 = 0; int nsemileptonic3 = 0; int nhadronic = 0; // Loop over all events for(Int_t entry = 0; entry < numberOfEntries; ++entry) { //if( entry == 100000) break; if( entry%1000 == 0) cout << "starting with " << entry << endl; // Load selected branches with data from specified event treeReader->ReadEntry(entry); int nmuons = 0; int nelectrons= 0; int ntaumuons = 0; int ntauelectrons= 0; int ntaus = 0 ; int nhadrons = 0 ; // If event contains at least 1 particle int ntop = 0; double genweight = 1.0; if(branchEvent->GetEntries() > 0) { event = (LHEFEvent * ) branchEvent->At(0); genweight = event->Weight; //cout << "event number = " << event->Number << endl; //cout << "event weight = " << event->Weight << endl; } //Lepton_E = -1.0; if(branchParticle->GetEntries() > 0) { for(int i = 0; i < branchParticle->GetEntriesFast() ; i++){ if(ntop == 2) break; particle = (GenParticle *) branchParticle->At(i); int status = particle->Status; bool LO = true; //if( LO ) cout << "THIS IS LO..." << endl; if( status != 3) continue; int id = particle->PID; double gen_pt = particle->PT; double gen_eta = particle->Eta; //Leading order if( LO) { if( abs(id) == 11 ){ genelectron = particle; double energy = genelectron->E; h_electron_energy->Fill( energy, genweight ); h_lepton_energy->Fill( energy, genweight ); //Lepton_E = energy; //for(int i=0; i < nmass; i++){ // float w = g2[i]->Eval( energy ); // integral2[i] = integral2[i] + w ; //} //lepton_E.push_back( energy ); if( energy > 20 && fabs(gen_eta) < 2.4) { //h_electron_energy_acc->Fill( energy, genweight ); h_lepton_energy_acc->Fill( energy, genweight ); nmuons++; } //daughter1 = (GenParticle*) branchParticle->At( particle->D1); //daughter2 = (GenParticle*) branchParticle->At( particle->D2); //int d1_id = abs(daughter1->PID); //int d2_id = abs(daughter2->PID); //cout << "electron daughter " << d1_id << " , " << d2_id << endl; }else if( abs(id) == 13 ){ genmuon = particle; double energy = genmuon->E; h_muon_energy->Fill( energy, genweight ); h_lepton_energy->Fill( energy, genweight ); //Lepton_E = energy; //for(int i=0; i < nmass; i++){ // float w = g2[i]->Eval( energy ); // integral2[i] = integral2[i] + w ; //} //lepton_E.push_back( energy ); if( energy > 20 && fabs(gen_eta) < 2.4) { //h_muon_energy_acc->Fill( energy, genweight ); h_lepton_energy_acc->Fill( energy, genweight ); nelectrons++; } //int d1_id = -1; //int d2_id = -1; //if( particle->D1 >= branchParticle->GetEntries()){ // daughter1 = (GenParticle*) branchParticle->At( particle->D1); // int d1_id = abs(daughter1->PID); //} //if( particle->D1 >= branchParticle->GetEntries()){ // daughter1 = (GenParticle*) branchParticle->At( particle->D1); // int d1_id = abs(daughter1->PID); //} //cout << "muon daughter " << d1_id << " , " << d2_id << endl; } //NLO }else if( abs(id) == 6 ) { ntop++; particle = (GenParticle*) branchParticle->At( i ) ; if( particle->D1 >= branchParticle->GetEntries() ) continue; bool lasttop = false ; while( !lasttop ){ if( particle->D1 >= branchParticle->GetEntries() ) break; GenParticle * d = (GenParticle *) branchParticle->At( particle->D1 ); if( abs(d->PID) != 6 ) { lasttop = true; } else { particle = d ; } } if( particle->D1 >= branchParticle->GetEntries() || particle->D2 >= branchParticle->GetEntries() ){ continue; } daughter1 = (GenParticle*) branchParticle->At( particle->D1) ; daughter2 = (GenParticle*) branchParticle->At( particle->D2) ; bool lastW = false; int d1_id = abs(daughter1->PID); int d2_id = abs(daughter2->PID); //cout << "top daughter " << d1_id << " , " << d2_id << endl; while( !lastW) { if( daughter1->D1 >= branchParticle->GetEntries() ) break; GenParticle * d = (GenParticle *) branchParticle->At( daughter1->D1 ); if( abs(d->PID) != 24 ) { lastW = true; } else { daughter1 = d ; } } if( daughter1->D1 >= branchParticle->GetEntries() || daughter1->D2 >= branchParticle->GetEntries() ){ continue; } granddaughter1_1 = (GenParticle*) branchParticle->At( daughter1->D1) ; granddaughter1_2 = (GenParticle*) branchParticle->At( daughter1->D2) ; granddaughter2_1 = (GenParticle*) branchParticle->At( daughter2->D1) ; granddaughter2_2 = (GenParticle*) branchParticle->At( daughter2->D2) ; int gd1_1_id = abs(granddaughter1_1->PID); int gd1_2_id = abs(granddaughter1_2->PID); int gd2_1_id = abs(granddaughter2_1->PID); int gd2_2_id = abs(granddaughter2_2->PID); //cout << "W daughters = " << gd1_1_id << " , " << gd1_2_id << " , " << gd2_1_id << " , " << gd2_2_id << endl; int W_dau_status = granddaughter1_1->Status ; //if( gd1_1_id > gd1_2_id ) cout << "Something is WRONG ! " << endl; GenParticle * le = (GenParticle * ) branchParticle->At( granddaughter1_1->D1 ); //GenParticle * leda = (GenParticle * ) branchParticle->At( le->D1); if( gd1_1_id == 11 || gd1_1_id == 13 ){ cout << le->D1 << " , " << le->D2 << endl; // cout << " original id and status = " << gd1_1_id << " , " << W_dau_status << " le id and status = " << le->PID << " , " << le->Status << " leda id and status = " << leda->PID << " , " << leda->Status << endl; } if( gd1_1_id == 11 ) { nelectrons++; //genelectron = granddaughter1_2; genelectron = le; } else if( gd1_1_id == 13 ) { nmuons++; //genmuon = granddaughter1_2; genmuon = le; } else if( gd1_1_id == 15 ) { ntaus++; /* if( granddaughter1_2->D1 >= branchParticle->GetEntries() || granddaughter1_2->D2 >= branchParticle->GetEntries() ){ continue; } GenParticle * taudaughter1 = (GenParticle*) branchParticle->At( granddaughter1_2->D1) ; GenParticle * taudaughter2 = (GenParticle*) branchParticle->At( granddaughter1_2->D2) ; int taud1_id = abs(taudaughter1->PID); int taud2_id = abs(taudaughter2->PID); //cout << "tau daughter = " << taud1_id << " " << taud2_id << endl; if( taud1_id == 11 || taud1_id == 12 ) ntauelectrons++; else if( taud1_id == 13 || taud1_id == 14 ) ntaumuons++; else if( taud1_id == 15 || taud1_id == 16 ) { if( taudaughter1->D1 >= branchParticle->GetEntries() || taudaughter1->D2 >= branchParticle->GetEntries() ){ continue; } GenParticle * taugranddaughter1 = (GenParticle*) branchParticle->At( taudaughter1->D1) ; GenParticle * taugranddaughter2 = (GenParticle*) branchParticle->At( taudaughter1->D2) ; int taugd1_id = abs(taugranddaughter1->PID); int taugd2_id = abs(taugranddaughter2->PID); //cout << "tau grand daughter = " << taugd1_id << " " << taugd2_id << endl; if( taugd1_id == 11 || taugd1_id == 12 ) ntauelectrons++; else if( taugd1_id == 13 || taugd1_id == 14 ) ntaumuons++; ㅜㅜ else { continue; } } else { continue; } */ }else{ nhadrons++; } //cout << "nelectrons = " << nelectrons << " nmuons = " << nmuons << " ntaus = " << ntaus << " nhadrons = " << nhadrons << endl; } } } if( LO ){ }else{ int remaining = 0 ; int nleptons = nelectrons + nmuons + ntaus; if( nleptons == 2 && nhadrons == 0){ //cout << "dilepton" << endl; ndileptonic++; if( ntaus ==0 || ( ntaus == 1 && (ntauelectrons+ntaumuons) == 1) || (ntaus == 2 && (ntauelectrons+ntaumuons) == 2) ) { ndileptonic2++; } if( ntaus == 0) ndileptonic3++; }else if( nleptons == 1 && nhadrons == 1){ //cout << "lepton+jets" << endl; nsemileptonic++; if( ntaus ==0 || ( ntaus == 1 && (ntauelectrons+ntaumuons) == 1) ) nsemileptonic2++; if( ntaus == 0 ) { nsemileptonic3++; if( nmuons ) { h_muon_energy->Fill(genmuon->E, genweight); h_lepton_energy->Fill(genmuon->E, genweight); } if( nelectrons ) { h_electron_energy->Fill(genelectron->E, genweight); h_lepton_energy->Fill(genelectron->E, genweight); } } }else if ( nleptons == 0 && nhadrons == 2 ){ //cout << "hadronic" << endl; nhadronic++; }else{ //cout << "remaining" << endl; remaining++; } } Muon * mymuon; Electron * myelectron; bool passmuon = false; bool passelectron = false; if(branchMuon->GetEntries() > 0) { bool mymuonpass = false; for(int i = 0; i < branchMuon->GetEntriesFast() ; i++){ Muon * muon = (Muon *) branchMuon->At(i); if( muon->P4().E() > 20 && fabs( muon->P4().Eta() < 2.4) ){ mymuon = muon; mymuonpass = true; } break; } if( mymuonpass && ( nmuons > 0 || nelectrons > 0 ) ){ //h_muon_energy_reco->Fill(mymuon->P4().E(), genweight); h_lepton_energy_reco->Fill(mymuon->P4().E(), genweight); h2_lepton_energy_response->Fill(mymuon->P4().E(), genmuon->E, genweight); passmuon = true; } } if(branchElectron->GetEntries() > 0) { bool myelectronpass = false; for(int i = 0; i < branchElectron->GetEntriesFast() ; i++){ Electron * electron = (Electron *) branchElectron->At(i); if( electron->P4().E() > 20 && fabs( electron->P4().Eta() < 2.4) ){ myelectron = electron; myelectronpass = true; } break; } if( myelectronpass && ( nmuons > 0 || nelectrons > 0 ) ){ //h_electron_energy_reco->Fill(myelectron->P4().E(), genweight); h_lepton_energy_reco->Fill(myelectron->P4().E(), genweight); h2_lepton_energy_response->Fill(myelectron->P4().E(), genelectron->E, genweight); passelectron = true; } } if(branchJet->GetEntries() > 0 ) { int njets = 0; int nbjets = 0; for(int i = 0; i < branchJet->GetEntriesFast() ; i++){ Jet * jet = (Jet *) branchJet->At(i); if( jet->P4().Pt() > 30 && fabs( jet->P4().Eta() < 2.5) ){ njets++; if( jet->BTag ) nbjets++; } } } //Muon_E = -9.0; //Electron_E = -9.0; //Lepton_E_reco = -1.0; float Energy = 9.0; if( passelectron && !passmuon && njets >= 4){ float myele_energy = myelectron->P4().E(); //h_electron_energy_reco_S2->Fill(myele_energy, genweight); //h_lepton_energy_reco_S2->Fill(myele_energy, genweight); //h_lepton_nbjets_reco_S2->Fill(nbjets); if( nbjets >= 2 ){ //h_electron_energy_reco_final->Fill(myele_energy, genweight); h_lepton_energy_reco_final->Fill(myele_energy, genweight); h2_lepton_energy_final_response->Fill(myele_energy, genelectron->E, genweight); } //lepton_E_final.push_back( myelectron->P4().E() ); //for(int i=0; i < nmass; i++){ // float corr = 1.0/ h_acc->Interpolate( myelectron->P4().E() ); // float w = g2[i]->Eval( myelectron->P4().E() ); //integral2[i] = integral2[i] + w*corr ; //} //Electron_E = myele_energy; //Lepton_E_reco = myele_energy; } if( passmuon && !passelectron && njets >= 4){ float mymuon_energy = mymuon->P4().E(); //h_muon_energy_reco_S2->Fill(mymuon_energy, genweight); //h_lepton_energy_reco_S2->Fill(mymuon_energy, genweight); //h_lepton_nbjets_reco_S2->Fill(nbjets); if( nbjets >= 2 ){ // h_muon_energy_reco_final->Fill(mymuon_energy, genweight); h_lepton_energy_reco_final->Fill(mymuon_energy, genweight); h2_lepton_energy_final_response->Fill(mymuon_energy, genmuon->E, genweight); } //lepton_E_final.push_back( mymuon->P4().E() ); //for(int i=0; i < nmass; i++){ // float corr = 1.0/ h_acc->Interpolate( mymuon->P4().E() ); // float w = g2[i]->Eval( mymuon->P4().E() ); //integral2[i] = integral2[i] + w*corr ; //} //Muon_E = mymuon_energy; //Lepton_E_reco = mymuon_energy; } /* for(int i=0; i < nmass; i++){ //for(int i=0; i < 0; i++){ float lenergy = -9; if( Muon_E > 0 && Electron_E < 0 ) lenergy = Muon_E; if( Muon_E < 0 && Electron_E > 0 ) lenergy = Electron_E; float acc = h_acc->Interpolate( lenergy ); integral2[i] = integral2[i] + g2[i]->Eval( lenergy ) /acc ; integral3[i] = integral3[i] + g3[i]->Eval( lenergy ) /acc ; integral5[i] = integral5[i] + g5[i]->Eval( lenergy ) /acc ; integral15[i] = integral15[i] + g15[i]->Eval( lenergy ) /acc ; } */ //if( passmuon && passelectron) cout << "Lepton E = " << Lepton_E << endl; //tree->Fill(); } //tree->Print(); // for(int m=0; m < nmass; m++){ // for(int i=0; i < 400;i++){ // float bincenter = h_lepton_energy->GetBinCenter(i+1); // float binconten = h_lepton_energy->GetBinContent(i+1); // float weight_value = g2[m]->Eval( bincenter ); // integral2[m] = integral2[m] + weight_value*binconten; // } // } /* for(int m=0; m < nmass; m++){ for(int i=0; i < lepton_E_final.size() ;i++){ float energy = lepton_E_final[i]; float corr = 1.0/ h_acc->Interpolate( energy ); float weight_value2 = g2[m]->Eval( bincenter ); float weight_value3 = g3[m]->Eval( bincenter ); float weight_value5 = g5[m]->Eval( bincenter ); float weight_value15 = g15[m]->Eval( bincenter ); integral2[m] = integral2[m] + weight_value2*corr; integral3[m] = integral3[m] + weight_value3*corr; integral5[m] = integral5[m] + weight_value5*corr; integral15[m] = integral15[m] + weight_value15*corr; } } TGraph * final2 = new TGraph(); TGraph * final3 = new TGraph(); TGraph * final5 = new TGraph(); TGraph * final15 = new TGraph(); for (Int_t i=0;i<nmass;i++) { final2->SetPoint(i, mymass[i], integral2[i]); final3->SetPoint(i, mymass[i], integral3[i]); final5->SetPoint(i, mymass[i], integral5[i]); final15->SetPoint(i, mymass[i], integral15[i]); } final2->SetName("n2"); final3->SetName("n3"); final5->SetName("n5"); final15->SetName("n15"); final2->Write(); final3->Write(); final5->Write(); final15->Write(); */ if( remaining != 0 ) cout << "Someting is wrong" << endl; //TCanvas * c = new TCanvas("c","c",1000,600); channel->SetBinContent(1,ndileptonic); channel->SetBinContent(2,ndileptonic2); channel->SetBinContent(3,ndileptonic3); channel->SetBinContent(4,nsemileptonic); channel->SetBinContent(5,nsemileptonic2); channel->SetBinContent(6,nsemileptonic3); channel->SetBinContent(7,nhadronic); channel->GetXaxis()->SetBinLabel(1,"Dileptonic"); channel->GetXaxis()->SetBinLabel(2,"DileptonicTau"); channel->GetXaxis()->SetBinLabel(3,"DileptonicNoTau"); channel->GetXaxis()->SetBinLabel(4,"Semileptonic"); channel->GetXaxis()->SetBinLabel(5,"SemileptonicTau"); channel->GetXaxis()->SetBinLabel(6,"SemileptonicNoTau"); channel->GetXaxis()->SetBinLabel(7,"Hadronic"); //int nBins = 400; //h_lepton_energy->AddBinContent(nBins, h_lepton_energy->GetBinContent(nBins+1)); //h_lepton_energy_reco_final->AddBinContent(nBins, h_lepton_energy_reco_final->GetBinContent(nBins+1)); // Show resulting histograms channel->SetStats(0000); double scale = 1.0/numberOfEntries; channel->Scale( scale ); //channel->Draw("HText0"); /* channel->Write(); h_muon_energy->Write(); h_electron_energy->Write(); h_lepton_energy->Write(); h_muon_energy_acc->Write(); h_electron_energy_acc->Write(); h_lepton_energy_acc->Write(); h_muon_energy_reco->Write(); h_electron_energy_reco->Write(); h_lepton_energy_reco->Write(); h_muon_energy_reco_final->Write(); h_electron_energy_reco_final->Write(); h_lepton_energy_reco_final->Write(); */ f->Write(); f->Close(); }
void AnalyseEvents(ExRootTreeReader *treeReader, TestPlots *plots) { TClonesArray *branchParticle = treeReader->UseBranch("Particle"); TClonesArray *branchElectron = treeReader->UseBranch("Electron"); TClonesArray *branchMuon = treeReader->UseBranch("Muon"); TClonesArray *branchPhoton = treeReader->UseBranch("Photon"); TClonesArray *branchEFlowTrack = treeReader->UseBranch("EFlowTrack"); TClonesArray *branchEFlowTower = treeReader->UseBranch("EFlowTower"); TClonesArray *branchEFlowMuon = treeReader->UseBranch("EFlowMuon"); TClonesArray *branchJet = treeReader->UseBranch("Jet"); Long64_t allEntries = treeReader->GetEntries(); cout << "** Chain contains " << allEntries << " events" << endl; GenParticle *particle; Electron *electron; Photon *photon; Muon *muon; Track *track; Tower *tower; Jet *jet; // P4 returns a TLorentzVector TObject *object; TLorentzVector momentum; Float_t Eem, Ehad; Bool_t skip; Long64_t entry; Int_t i, j, pdgCode; // Loop over all events for(entry = 0; entry < allEntries; entry++) { // Load selected branches with data from specified event treeReader->ReadEntry(entry); ///---- take the two highest pt leptons in the event (m or e) // maps are ordered in ascending order std::map <float, int> m_maxptleptons; // Loop over all electrons in event for(i = 0; i < branchElectron->GetEntriesFast(); i++) { electron = (Electron*) branchElectron->At(i); double pt = electron->PT; m_maxptleptons[-pt] = -(i+1); } // Loop over all muons in event for(i = 0; i < branchMuon->GetEntriesFast(); i++) { muon = (Muon*) branchMuon->At(i); double pt = muon->PT; m_maxptleptons[-pt] = (i+1); } //---- at least 2 leptons ---- if (m_maxptleptons.size() < 2) continue; // kind = 0/1 if m/e std::map<float, int>::iterator it_type_m_lepton = m_maxptleptons.begin(); int flav1 = (it_type_m_lepton->second<0); // m>0, e<0 ---> m=0, e=1 plots->hpt1->Fill(- it_type_m_lepton->first); it_type_m_lepton++; int flav2 = (it_type_m_lepton->second<0); // m>0, e<0 ---> m=0, e=1 plots->hpt2->Fill(- it_type_m_lepton->first); int nlep = 0; for(it_type_m_lepton = m_maxptleptons.begin(); it_type_m_lepton != m_maxptleptons.end(); it_type_m_lepton++) { if ( -(it_type_m_lepton->first) > 10) nlep++; } plots->hnleppt10->Fill(nlep); // ee/mm e m m e plots->hchannel->Fill(flav1*flav2+2*(flav1>flav2)+3*(flav1<flav2)); // # mumu # channel == 0 // # mue # channel == 3 // # emu # channel == 2 // # ee # channel == 1 TLorentzVector l1, l2; it_type_m_lepton = m_maxptleptons.begin(); if (it_type_m_lepton->second>0) { l1 = ((Muon*) branchMuon->At( it_type_m_lepton->second - 1 ))->P4();} else { l1 = ((Electron*) branchElectron->At(-(it_type_m_lepton->second + 1)))->P4();} it_type_m_lepton++; if (it_type_m_lepton->second>0) { l2 = ((Muon*) branchMuon->At( it_type_m_lepton->second - 1 ))->P4();} else { l2 = ((Electron*) branchElectron->At(-(it_type_m_lepton->second + 1)))->P4();} plots->hmll->Fill((l1+l2).M()); plots->hdphill->Fill( l1.DeltaPhi(l2) ); // Loop over all jets in event //---- two highest mjj are VBF jets //---- the other two are "H>bb" jets //---- at least 4 jets with pt>MINPTJET GeV float MINPTJET = 15.; int countJets = 0; for(i = 0; i < branchJet->GetEntriesFast(); i++) { jet = (Jet*) branchJet->At(i); TLorentzVector jetP4 = jet->P4(); if (jet->PT > MINPTJET && !isThisJetALepton(jetP4, l1, l2)) countJets++; } if (countJets < 4) { continue; } TLorentzVector jet1, jet2, jet3, jet4; TLorentzVector Jet1, Jet2, bJet1, bJet2; //---- the VBF jets and the H>bb jets int ijet = 0; for(i = 0; i < branchJet->GetEntriesFast(); i++) { jet = (Jet*) branchJet->At(i); TLorentzVector jetP4 = jet->P4(); if (jet->PT > MINPTJET && !isThisJetALepton(jetP4, l1, l2)) { if (ijet == 0) {jet1 = jetP4; ijet++; } else if (ijet == 1) {jet2 = jetP4; ijet++; } else if (ijet == 2) {jet3 = jetP4; ijet++; } else if (ijet == 3) {jet4 = jetP4; ijet++; } } } if (jet4.Pt() < MINPTJET) { std::cout << "We have a problem; countJets = " << countJets << "; ijet = " << ijet << " and jet4.Pt() = " << jet4.Pt() << std::endl; } float mjj12 = (jet1+jet2).M(); float mjj13 = (jet1+jet3).M(); float mjj14 = (jet1+jet4).M(); float mjj23 = (jet2+jet3).M(); float mjj24 = (jet2+jet4).M(); float mjj34 = (jet3+jet4).M(); std::map<float, int> m_maxmjj; m_maxmjj[-mjj12] = 1; m_maxmjj[-mjj13] = 2; m_maxmjj[-mjj14] = 3; m_maxmjj[-mjj23] = 4; m_maxmjj[-mjj24] = 5; m_maxmjj[-mjj34] = 6; std::map<float, int>::iterator it_type_m_maxmjj = m_maxmjj.begin(); plots->hmjj->Fill( - it_type_m_maxmjj->first ); if (it_type_m_maxmjj->second == 1) { Jet1 = jet1; Jet2 = jet2; bJet1 = jet3; bJet2 = jet4; }; if (it_type_m_maxmjj->second == 2) { Jet1 = jet1; Jet2 = jet3; bJet1 = jet2; bJet2 = jet4; }; if (it_type_m_maxmjj->second == 3) { Jet1 = jet1; Jet2 = jet4; bJet1 = jet2; bJet2 = jet3; }; if (it_type_m_maxmjj->second == 4) { Jet1 = jet2; Jet2 = jet3; bJet1 = jet1; bJet2 = jet4; }; if (it_type_m_maxmjj->second == 5) { Jet1 = jet2; Jet2 = jet4; bJet1 = jet1; bJet2 = jet3; }; if (it_type_m_maxmjj->second == 6) { Jet1 = jet3; Jet2 = jet4; bJet1 = jet1; bJet2 = jet2; }; //---- sub-order in pt if (Jet1.Pt() < Jet2.Pt()) { TLorentzVector tempjet = Jet1; Jet1 = Jet2; Jet2 = tempjet; } if (bJet1.Pt() < bJet2.Pt()) { TLorentzVector tempjet = bJet1; bJet1 = bJet2; bJet2 = tempjet; } plots->hmbb->Fill( (bJet1+bJet2).M() ); plots->hbjetpt1->Fill( bJet1.Pt() ); plots->hbjetpt2->Fill( bJet2.Pt() ); plots->hjetpt1->Fill( Jet1.Pt() ); plots->hjetpt2->Fill( Jet2.Pt() ); // std::cout << " it_type_m_lepton->first = " << it_type_m_lepton->first << std::endl; // plots->hpt1->Fill(m_maxptleptons.begin()->first); // typedef std::map<float, int>::iterator it_type_m_lepton; // for(it_type iterator = m.begin(); iterator != m.end(); iterator++) { // plots->hpt1->Fill(v_maxptleptons.at(0).first); // Loop over all tracks in event for(i = 0; i < branchEFlowTrack->GetEntriesFast(); i++) { // track = (Track*) branchEFlowTrack->At(i); // particle = (GenParticle*) track->Particle.GetObject(); // // plots->fTrackDeltaPT->Fill((particle->PT - track->PT)/particle->PT); // plots->fTrackDeltaEta->Fill((particle->Eta - track->Eta)/particle->Eta); } // Loop over all towers in event for(i = 0; i < branchEFlowTower->GetEntriesFast(); i++) { // tower = (Tower*) branchEFlowTower->At(i); // v_maxptleptons // Eem = 0.0; // Ehad = 0.0; // skip = kFALSE; // for(j = 0; j < tower->Particles.GetEntriesFast(); ++j) // { // particle = (GenParticle*) tower->Particles.At(j); // pdgCode = TMath::Abs(particle->PID); // // // skip muons and neutrinos // if(pdgCode == 12 || pdgCode == 13 || pdgCode == 14 || pdgCode == 16) // { // continue; // } // // // skip K0short and Lambda // if(pdgCode == 310 || pdgCode == 3122) // { // skip = kTRUE; // } // // if(pdgCode == 11 || pdgCode == 22) // { // // Eem += particle->E; // } // else // { // Ehad += particle->E; // } // } // if(skip) continue; // if(Eem > 0.0 && tower->Eem > 0.0) plots->fTowerDeltaEem->Fill((Eem - tower->Eem)/Eem); // if(Ehad > 0.0 && tower->Ehad > 0.0) plots->fTowerDeltaEhad->Fill((Ehad - tower->Ehad)/Ehad); } // Loop over all jets in event for(i = 0; i < branchJet->GetEntriesFast(); i++) { // jet = (Jet*) branchJet->At(i); // // momentum.SetPxPyPzE(0.0, 0.0, 0.0, 0.0); // // // Loop over all jet's constituents // for(j = 0; j < jet->Constituents.GetEntriesFast(); ++j) // { // object = jet->Constituents.At(j); // // // Check if the constituent is accessible // if(object == 0) continue; // // if(object->IsA() == GenParticle::Class()) // { // momentum += ((GenParticle*) object)->P4(); // } // else if(object->IsA() == Track::Class()) // { // momentum += ((Track*) object)->P4(); // } // else if(object->IsA() == Tower::Class()) // { // momentum += ((Tower*) object)->P4(); // } // else if(object->IsA() == Muon::Class()) // { // momentum += ((Muon*) object)->P4(); // } // } // plots->fJetDeltaPT->Fill((jet->PT - momentum.Pt())/jet->PT ); // } } } }
void LHCOWriter::AnalyseMuons() { Muon *element; Track *track; Tower *tower; Jet *jet; Int_t muonCounter, tauCounter, jetCounter, minIndex; Float_t sumPT, sumET, ratET, jetDR, minDR; muonCounter = 0; fItMuon->Reset(); while((element = static_cast<Muon*>(fItMuon->Next()))) { Reset(); sumPT = 0.0; fItTrack->Reset(); while((track = static_cast<Track*>(fItTrack->Next()))) { if(element->P4().DeltaR(track->P4()) < 0.5) sumPT += track->PT; } sumET = 0.0; fItTower->Reset(); while((tower = static_cast<Tower*>(fItTower->Next()))) { if(element->P4().DeltaR(tower->P4()) < 0.5) sumET += tower->ET; } tauCounter = 0; jetCounter = 0; minIndex = -1; minDR = 1.0E9; fItJet->Reset(); while((jet = static_cast<Jet*>(fItJet->Next()))) { if(jet->TauTag != 0) { ++tauCounter; continue; } jetDR = element->P4().DeltaR(jet->P4()); if(jetDR < minDR) { minIndex = jetCounter; minDR = jetDR; } ++jetCounter; } fIntParam[1] = 2; fDblParam[0] = element->Eta; fDblParam[1] = element->Phi; fDblParam[2] = element->PT; fDblParam[3] = 0.11; fDblParam[4] = element->Charge; if(minIndex >= 0) { fDblParam[5] = fIntParam[0] + fBranchMuon->GetEntriesFast() - muonCounter + tauCounter + minIndex; } ratET = sumET/element->PT; fDblParam[6] = Float_t(TMath::Nint(sumPT)) + (ratET < 1.0 ? ratET : 0.99); Write(); ++muonCounter; } }
void GlobalRecoTTbarPlugin::CalculateVariables(Jet const &bTopLep, Jet const &bTopHad, Jet const &q1TopHad, Jet const &q2TopHad) { // Calculate variables related to the top quark decaying semileptonically auto const &lepton = (*reader)->GetLeptons().front(); Candidate const wLep(lepton.P4() + (*reader)->GetNeutrino().P4()); Candidate const topLep(wLep.P4() + bTopLep.P4()); //bfMass_TopLep = topLep.M(); LogPt_TopLep = log(topLep.Pt()); //bfEta_TopLep = topLep.Eta(); //bfPt_BTopLep = bTopLep.Pt(); //bfEta_BTopLep = bTopLep.Eta(); //PassBTag_BTopLep = 0 + bTagger->IsTagged(bTopLep); //bfCharge_BTopLep = bTopLep.Charge() * lepton.Charge(); LogMass_BTopLepLep = log((bTopLep.P4() + lepton.P4()).M()); DeltaR_BTopLepWLep = bTopLep.P4().DeltaR(wLep.P4()); //bfDEta_TopLepLep = fabs(topLep.Eta() - lepton.Eta()); // Calculate the cosine // TVector3 b((wLep.P4()).BoostVector()); // TLorentzVector boostedLepton(lepton.P4()); // boostedLepton.Boost(-b); // TVector3 p3Lepton(boostedLepton.Vect()); // TLorentzVector boostedBJet(bTopLep.P4()); // boostedBJet.Boost(-b); // TVector3 const p3BJet(boostedBJet.Vect()); // bfCos_LepBTopLep_WLep = p3Lepton.Dot(p3BJet) / (p3Lepton.Mag() * p3BJet.Mag()); // Calculate variables related to the top quark decaying semileptonically Candidate const wHad(q1TopHad.P4() + q2TopHad.P4()); Candidate const topHad(wHad.P4() + bTopHad.P4()); //bfMass_TopHad = topHad.M(); LogPt_TopHad = log(topHad.Pt()); AbsEta_TopHad = fabs(topHad.Eta()); LogMass_WHad = log(wHad.M()); //bfPt_WHad = wHad.Pt(); //bfEta_WHad= wHad.Eta(); DeltaR_BTopHadWHad = bTopHad.P4().DeltaR(wHad.P4()); //bfPt_BTopHad = bTopHad.Pt(); //bfEta_BTopHad = bTopHad.Eta(); //PassBTag_BTopHad = 0 + bTagger->IsTagged(bTopHad); //bfCharge_BTopHad = bTopHad.Charge() * lepton.Charge(); //bfMinPt_Light = min(fabs(q1TopHad.Pt()), fabs(q2TopHad.Pt())); //bfMaxEta_Light = max(fabs(q1TopHad.Eta()), fabs(q2TopHad.Eta())); SumCharge_Light = (q1TopHad.Charge() + q2TopHad.Charge()) * lepton.Charge(); NumBTag_Light = 0 + bTagger->IsTagged(q1TopHad) + bTagger->IsTagged(q2TopHad); DeltaR_Light = q1TopHad.P4().DeltaR(q2TopHad.P4()); // bfMaxMass_BTopHadLight = // max((bTopHad.P4() + q1TopHad.P4()).M(), (bTopHad.P4() + q2TopHad.P4()).M()); LogDMass_TopHadWHad = log(topHad.M() - wHad.M()); // Calcualate variables with correlations between different objects double Ht = lepton.Pt() + (*reader)->GetMET().Pt(); for (auto const &j: (*reader)->GetJets()) Ht += j.Pt(); RelHt = (topLep.Pt() + topHad.Pt()) / Ht; //bfMass_TopLepTopHad = (topLep.P4() + topHad.P4()).M(); //bfPt_TopLepTopHad = (topLep.P4() + topHad.P4()).Pt(); //bfEta_TopLepTopHad = (topLep.P4() + topHad.P4()).Eta(); //bfDeltaR_TopLepTopHad = topLep.P4().DeltaR(topHad.P4()); DCharge_BTopHadBTopLep = (bTopHad.Charge() - bTopLep.Charge()) * lepton.Charge(); }