/*********************************************************************** ** ** ** /----------------------------------------------\ ** ** | Delphes, a framework for the fast simulation | ** ** | of a generic collider experiment | ** ** \----------------------------------------------/ ** ** ** ** ** ** This package uses: ** ** ------------------ ** ** FastJet algorithm: Phys. Lett. B641 (2006) [hep-ph/0512210] ** ** Hector: JINST 2:P09005 (2007) [physics.acc-ph:0707.1198v2] ** ** FROG: [hep-ex/0901.2718v1] ** ** ** ** ------------------------------------------------------------------ ** ** ** ** Main authors: ** ** ------------- ** ** ** ** Severine Ovyn Xavier Rouby ** ** severine.ovyn@uclouvain.be xavier.rouby@cern ** ** ** ** Center for Particle Physics and Phenomenology (CP3) ** ** Universite catholique de Louvain (UCL) ** ** Louvain-la-Neuve, Belgium ** ** ** ** Copyright (C) 2008-2009, ** ** All rights reserved. ** ** ** ***********************************************************************/ // local includes #include "LHCOConverter.h" #include "ExRootTreeReader.h" #include "BlockClasses.h" // root includes #include "TFile.h" #include "TChain.h" #include "TClonesArray.h" // c++ includes #include #include #include #include #include using namespace std; //------------------------------------------------------------------------------ extern const float UNDEFINED; LHCOConverter::LHCOConverter(const string& inputroot, const string& inputlog): inputfilename_(inputroot), inputlogname_(inputlog), outputfilename_(inputroot), valid_(true) { if (inputfilename_ == "") {valid_ = false;} else { TFile ftest(inputfilename_.c_str(),"READ"); if (!ftest.IsOpen()) { cout << "ERROR: file " << inputfilename_ << " could not be opened\n"; valid_=false; } else { ftest.Close(); const unsigned int r_find = outputfilename_.rfind(".root"); if(r_find > outputfilename_.size()) { cerr << "ERROR: the extension of the input file is not '.root'. Exiting...\n"; valid_=false; } else { outputfilename_.replace(r_find,5,"_events.lhco"); ofstream outfile( outputfilename_.c_str()); outfile.close(); cout << left << setw(20) <<"** INFO: "<<"" << left << setw(29) << outputfilename_ <<"" << right << setw(20) <<"created **"<UseBranch("Photon"); TClonesArray *branchElectron = analysisTree->UseBranch("Electron"); TClonesArray *branchMuon = analysisTree->UseBranch("Muon"); TClonesArray *branchTauJet = analysisTree->UseBranch("TauJet"); TClonesArray *branchJet = analysisTree->UseBranch("Jet"); TClonesArray *branchETmis = analysisTree->UseBranch("ETmis"); Long64_t Nevents = analysisTree->GetEntries(); Nevents = min(Nevents,triggerTree->GetEntries()); if (Nevents != analysisTree->GetEntries()) cout << "** WARNING: not the same number of entries in 'Analysis' and **\n** 'Trigger' trees\n"; for(Long64_t event = 0; event < Nevents; ++event) { analysisTree->ReadEntry(event); triggerTree->ReadEntry(event); unsigned int triginfo = 0; unsigned int line =0; outfile << setw(3) << line++ << setw(4) << " " << setw(7) << event << setw(7) << triginfo << endl; // 0 photon data BranchReader(branchPhoton,line,lhcoPhotonID); // 1 electron/positron data BranchReader(branchElectron,line,lhcoElectronID); // 2 muon data BranchReader(branchMuon,line,lhcoMuonID); // 3 tau-jets BranchReader(branchTauJet,line,lhcoTauJetID); // 4 jets BranchReader(branchJet,line,lhcoJetID); // 6 MET BranchReaderETmis(branchETmis,line); } // event loop outfile.close(); delete triggerTree; delete analysisTree; } //ostringstream LHCOConverter::BranchReader(const TClonesArray* branch, unsigned int& line, unsigned short int lhcoID) const { void LHCOConverter::BranchReader(const TClonesArray* branch, unsigned int& line, unsigned short int lhcoID) const { //ostringstream outfile; ofstream outfile( outputfilename_.c_str(),ios_base::app); unsigned int branch_size = branch->GetEntries(); TRootParticle * particle = 0; for (unsigned int i=0; i< branch_size; i++) { particle = (TRootParticle*) branch->At(i); TLorentzVector pmu; pmu.SetPtEtaPhiE(particle->PT, particle->Eta, particle->Phi, particle->E); float jmass = pmu.M(); float ntrk = 0.0; float btag =0; double ratioE = 0; if(lhcoID == lhcoPhotonID){TRootPhoton gam(*((TRootPhoton*) branch->At(i))); jmass=0; ratioE = gam.EHoverEE;} if(lhcoID == lhcoElectronID) { TRootElectron elec(*((TRootElectron*) branch->At(i))); ntrk = elec.Charge; ratioE = elec.EHoverEE;} else if (lhcoID == lhcoMuonID) { TRootMuon muon(*((TRootMuon*) branch->At(i))); ntrk = muon.Charge; ratioE = muon.EHoverEE;} else if (lhcoID == lhcoTauJetID) { TRootTauJet taujet(*((TRootTauJet*) branch->At(i))); ntrk = taujet.Charge; } else if (lhcoID == lhcoJetID) { TRootJet jet(*((TRootJet*) branch->At(i))); ntrk = jet.NTracks; btag = jet.Btag; ratioE = jet.EHoverEE;} if(lhcoID != lhcoETmisID) { outfile << fixed << setprecision(3) << setw(3) << line++ // line counter << setw(4) << lhcoID << " " // object ID in lhco format << setw(7) << particle->Eta <<" " << setw(7) << particle->Phi <<" " << setw(7) << particle->PT <<" " << setw(7) << jmass <<" " // invariant mass << setw(7) << ntrk <<" " // number of tracks << setw(7) << btag <<" " << setw(7) << ratioE <<" " // E_had/E_em << setw(7) << 0.0 << setw(7) << 0.0 // dummy/dummy << endl; } else { outfile << fixed << setprecision(3) << setw(3) << line++ // line counter << setw(4) << lhcoID << " " // object ID in lhco format << setw(7) << 0.000 <<" " << setw(7) << particle->Phi <<" " << setw(7) << particle->PT <<" " << setw(7) << 0. <<" " // invariant mass << setw(7) << 0 <<" " // number of tracks << setw(7) << 0. <<" " << setw(7) << 0. <<" " // E_had/E_em << setw(7) << 0.0 << setw(7) << 0.0 // dummy/dummy << endl; } } outfile.close(); // return outfile; } //ostringstream LHCOConverter::BranchReader(const TClonesArray* branch, unsigned int& line, unsigned short int lhcoID) const { void LHCOConverter::BranchReaderETmis(const TClonesArray* branch, unsigned int& line) const { //ostringstream outfile; ofstream outfile( outputfilename_.c_str(),ios_base::app); TRootETmis * particle = 0; particle = (TRootETmis*) branch->At(0); outfile << fixed << setprecision(3) << setw(3) << line++ // line counter << setw(4) << 6 << " " // object ID in lhco format << setw(7) << 0.000 <<" " << setw(7) << particle->Phi <<" " << setw(7) << particle->ET <<" " << setw(7) << 0. <<" " // invariant mass << setw(7) << 0 <<" " // number of tracks << setw(7) << 0. <<" " << setw(7) << 0. <<" " // E_had/E_em << setw(7) << 0.0 << setw(7) << 0.0 // dummy/dummy << endl; outfile.close(); // return outfile; }