ExampleTree.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "Rivet/Rivet.hh"
00003 #include "Rivet/Tools/Logging.hh"
00004 #include "Rivet/Analyses/ExampleTree.hh"
00005 #include "Rivet/RivetAIDA.hh"
00006 using namespace AIDA;
00007 
00008 #include "HepPDT/ParticleID.hh"
00009 using namespace HepMC;
00010 
00011 
00012 namespace Rivet {
00013 
00014 
00015   // Book histograms
00016   void ExampleTree::init() {
00017     
00018 #ifndef HAVE_ROOT
00019     Log log = getLog();
00020     log << Log::WARN << "Rivet was not compiled against ROOT. ExampleTree will do nothing." << endl;
00021 #else
00022     
00023     _jet_pt_cut = 20;
00024     _subj_pt_cut = 20;
00025     _lepton_pt_cut = 20;
00026     _store_partons = true;
00027 
00028     _treeFileName = "rivetTree.root";
00029 
00030     // Create a file for the Tree
00031     _treeFile = new TFile(_treeFileName, "recreate");
00032 
00033     // Book the ntuple.
00034     _rivetTree = new TTree("Rivet Tree", "Rivet Example Tree");
00035 
00036     // Event number 
00037     _rivetTree->Branch("nevt", &_nevt, "nevt/I");
00038 
00039     // Vector bosons
00040     _rivetTree->Branch("nvb", &_nvb, "nvb/I");
00041     _rivetTree->Branch("vbtype", &_vbtype, "vbtype[nvb]/I");
00042     _rivetTree->Branch("vbvec", &_vbvec, "vbvec[nvb][4]/F");
00043 
00044     _rivetTree->Branch("njet", &_njet, "njet/I");
00045     _rivetTree->Branch("vjet", &_vjet, "vjet[njet][4]/F");
00046 
00047     _rivetTree->Branch("nsub", &_nsub, "nsub/I");
00048     _rivetTree->Branch("sjet3", &_sjet3, "sjet3[nsub][4]/F");
00049     _rivetTree->Branch("ysubsj", &_ysubsj, "ysubsj[nsub][4]/F");
00050 
00051     _rivetTree->Branch("nlep", &_nlep, "nlep/I");
00052     _rivetTree->Branch("vlep", &_vlep, "vlep[nlep][4]/F");
00053     _rivetTree->Branch("leptype", &_leptype, "leptype[nlep][3]/F");
00054 
00055     _rivetTree->Branch("npart", &_npart, "npart/I");
00056     _rivetTree->Branch("ppart", &_ppart, "ppart[npart][4]/F");
00057     _rivetTree->Branch("pid", &_pid, "pid[npart]/I");
00058     _rivetTree->Branch("mo", &_mo, "mo[npart]/I");  // first mother.
00059 
00060     _rivetTree->Branch("esumr", &_esumr, "esumr[4]/F");
00061 
00062 #endif
00063   }
00064 
00065 
00066 
00067   // Do the analysis
00068   void ExampleTree::analyze(const Event & event) {
00069 #ifdef HAVE_ROOT
00070     Log log = getLog();
00071     log << Log::DEBUG << "Filling the ntuple" << endl;
00072 
00073     const GenEvent& ev = event.genEvent();
00074 
00075     // Event number
00076     _nevt = ev.event_number();
00077 
00078     // Jets.
00079     const KtJets& jets = event.applyProjection(_ktjetsproj);
00080 
00081     // Leptons
00082     const ChargedLeptons& cl = event.applyProjection(_chgleptonsproj);
00083 
00084     // Missing Et/total energy
00085     const TotalVisibleMomentum& tvm = event.applyProjection(_totvismomproj);
00086 
00087     // Vector bosons.
00088     const WZandh& wzh = event.applyProjection(_wzandhproj);
00089 
00090     // Get the vector bosons
00091     _nvb = 0;
00092     for (ParticleVector::const_iterator p = wzh.Zees().begin(); p != wzh.Zees().end(); ++p) {
00093       _vbvec[_nvb][1] = p->getMomentum().px();
00094       _vbvec[_nvb][2] = p->getMomentum().py();
00095       _vbvec[_nvb][3] = p->getMomentum().pz();
00096       _vbvec[_nvb][0] = p->getMomentum().e();
00097       _vbtype[_nvb]   = 1;
00098       ++_nvb;
00099     }
00100 
00101     // Get the partons. This is generator dependent and should not be
00102     // used in normal analyses.
00103     _npart = 0;
00104     if (_store_partons) {
00105 
00106       for (GenEvent::particle_const_iterator pi = event.genEvent().particles_begin(); 
00107            pi != event.genEvent().particles_end(); ++pi ) {
00108         // Only include particles which are documentation line (status = 3) 
00109         // The result/meaning will be generator dependent.
00110         if ( (*pi)->status() >= 2 ) {
00111           _ppart[_npart][1] = (*pi)->momentum().px();
00112           _ppart[_npart][2] = (*pi)->momentum().py();
00113           _ppart[_npart][3] = (*pi)->momentum().pz();
00114           _ppart[_npart][0] = (*pi)->momentum().e();
00115           HepPDT::ParticleID pInfo = (*pi)->pdg_id();
00116           _pid[_npart] = pInfo.pid();
00117           const GenVertex* vertex = (*pi)->production_vertex();
00118           // get the first mother
00119           if (vertex) {
00120             if (vertex->particles_in_size()>0) {
00121               GenVertex::particles_in_const_iterator p1 = vertex->particles_in_const_begin();
00122               _mo[_npart] = (*p1)->pdg_id();
00123             } else {
00124               _mo[_npart] = 0;
00125             }
00126           } else {
00127             _mo[_npart] = 0;
00128           }
00129           
00130           //const GenParticle mother = **(vertex->particles_in_const_begin());
00131           log << Log::DEBUG << _npart << ":" << _pid[_npart] << endl;
00132           ++_npart;
00133         }
00134       }
00135     }
00136     
00137     
00138     // Get the jets in decreasing ET order.
00139     vector<KtJet::KtLorentzVector> jetList = jets.getJetsEt();
00140     _njet = 0;
00141     _nsub = 0;
00142     for (vector<KtJet::KtLorentzVector>::iterator j = jetList.begin(); j != jetList.end(); ++j) {
00143       if (j->perp() > _jet_pt_cut) {
00144         _vjet[_njet][1] = j->px();
00145         _vjet[_njet][2] = j->py();
00146         _vjet[_njet][3] = j->pz();
00147         _vjet[_njet][0] = j->e();
00148         if (j->perp() > _subj_pt_cut) {
00149           _sjet3[_nsub][1] = j->px();
00150           _sjet3[_nsub][2] = j->py();
00151           _sjet3[_nsub][3] = j->pz();
00152           _sjet3[_nsub][0] = j->e();
00153           vector<double> ys = jets.getYSubJet(*j);
00154       for (unsigned int i=0; i<5; ++i){
00155         if (ys.size()>i) {
00156           _ysubsj[_nsub][i] = ys.at(i);
00157         } else {
00158           _ysubsj[_nsub][i] = 0;
00159         }
00160           }
00161           ++_nsub;
00162         }
00163         ++_njet;
00164       }
00165     }
00166 
00167     // Loop over leptons
00168     _nlep = 0;
00169     for (ParticleVector::const_iterator p = cl.chargedLeptons().begin(); p != cl.chargedLeptons().end(); ++p) {
00170       if (p->getMomentum().perp() > _lepton_pt_cut) {
00171         _vlep[_nlep][1] = p->getMomentum().px();
00172         _vlep[_nlep][2] = p->getMomentum().py();
00173         _vlep[_nlep][3] = p->getMomentum().pz();
00174         _vlep[_nlep][0] = p->getMomentum().e();
00175         ++_nlep;
00176       }
00177     }
00178 
00179     // Total/missing energy.  
00180     _esumr[1] = tvm.getMomentum().px();
00181     _esumr[2] = tvm.getMomentum().py();
00182     _esumr[3] = tvm.getMomentum().pz();
00183     _esumr[0] = tvm.getMomentum().e();
00184 
00185     // Finished...
00186     log << Log::DEBUG << "Finished analyzing" << endl;
00187 
00188     _rivetTree->Fill();
00189 #endif
00190   }
00191 
00192 
00193   // Finalize
00194   void ExampleTree::finalize() { 
00195 #ifdef HAVE_ROOT
00196     // Write the tree to file.
00197     _rivetTree->Write();
00198 #endif
00199   }
00200   
00201 
00202 }