read_particles_from_TAUOLA.cxx

00001 #include "TauSpinner/read_particles_from_TAUOLA.h"
00002 using namespace TauSpinner;
00003 
00004 // Global variables - used to store the state of the search
00005 // for boson in 'readParticlesFromTAUOLA_HepMC'
00006 HepMC::GenEvent                          *event = new HepMC::GenEvent();
00007 HepMC::GenEvent::particle_const_iterator     it = event->particles_end();
00008 
00009 /*******************************************************************************
00010   Get daughters of HepMC::GenParticle
00011 
00012   Recursively searches for final-state daughters of 'x'
00013 *******************************************************************************/
00014 inline vector<SimpleParticle> *getDaughters(HepMC::GenParticle *x)
00015 {
00016   vector<SimpleParticle> *daughters = new vector<SimpleParticle>();
00017   if(!x->end_vertex()) return daughters;
00018 
00019   // Check decay products of 'x'
00020   for(HepMC::GenVertex::particles_out_const_iterator p = x->end_vertex()->particles_out_const_begin(); p!=x->end_vertex()->particles_out_const_end(); ++p)
00021   {
00022     HepMC::GenParticle *pp = *p;
00023     HepMC::FourVector   mm = pp->momentum();
00024 
00025     // If the daughter of 'x' has its end vertex - recursively read
00026     // all of its daughters.
00027     if( pp->end_vertex() && pp->pdg_id()!=111)
00028     {
00029       vector<SimpleParticle> *sub_daughters = getDaughters(pp);
00030       daughters->insert(daughters->end(),sub_daughters->begin(),sub_daughters->end());
00031       
00032       delete sub_daughters;
00033     }
00034     // Otherwise - add this particle to the list of daughters.
00035     else
00036     {
00037       SimpleParticle tp( mm.px(), mm.py(), mm.pz(), mm.e(), pp->pdg_id() );
00038       daughters->push_back(tp);
00039     }
00040   }
00041 
00042   return daughters;
00043 }
00044 
00045 /*******************************************************************************
00046   Read HepMC::IO_GenEvent.
00047 
00048   Read HepMC event from data file
00049   and return particles filtered out from the event.
00050   
00051   This routine is prepared for use with files generated by Pythia8.
00052   Fills:
00053   
00054   'X'              - Heavy particle (W+/-, H+/-, H, Z)
00055   'tau'            - first tau
00056   'tau2'           - second tau or nu_tau, if 'X' decays to one tau only
00057   'tau_daughters'  - daughters of 'tau'
00058   'tau2_daughters' - daughters of 'tau2' or empty list, if 'tau2' is nu_tau.
00059   
00060   Returns:
00061   0 - no more events to read               (finished processing the file)
00062   1 - no decay found in the event          (finished processing current event)
00063   2 - decay found and processed correctly.
00064       Event will continue to be processed
00065       with next function call. 
00066 *******************************************************************************/
00067 int readParticlesFromTAUOLA_HepMC(HepMC::IO_GenEvent &input_file, SimpleParticle &X, SimpleParticle &tau, SimpleParticle &tau2, vector<SimpleParticle> &tau_daughters, vector<SimpleParticle> &tau2_daughters)
00068 {
00069   // If finished processing the event with previous function call
00070   if(it == event->particles_end())
00071   {
00072     // Delete previous event and create a new one
00073     delete event;
00074     event = new HepMC::GenEvent();
00075     
00076     // Read (parsed i.e. consiting of W and tau decay vertices only) event from input file
00077     input_file.fill_next_event(event);
00078     
00079     // Finish if there are no more events to read
00080     if(input_file.rdstate()) return 0;
00081     
00082     it = event->particles_begin();
00083   }
00084 
00085   // Exctract particles from event
00086   HepMC::GenParticle *hX=NULL, *hTau=NULL, *hTau2=NULL;
00087 
00088   for(; it!=event->particles_end(); ++it)
00089   {
00090     int pdgid = (*it)->pdg_id();
00091     if(
00092         (
00093           abs(pdgid)==37 ||
00094               pdgid ==25 ||
00095           abs(pdgid)==24 ||
00096               pdgid ==23          
00097         ) &&
00098         (*it)->end_vertex()->particles_out_size()==2
00099       )
00100     {
00101       hX = *it;
00102 
00103       // Get daughters of X
00104       HepMC::GenVertex   *x_daughters = (*it)->end_vertex();
00105 
00106       // tau should be the 1st daughter of X
00107       HepMC::GenParticle *first_daughter  =     *x_daughters->particles_out_const_begin();
00108       HepMC::GenParticle *second_daughter = *(++(x_daughters->particles_out_const_begin()));
00109 
00110       // Check if it is tau and it has decay products
00111       if( abs(first_daughter->pdg_id())==15 && first_daughter->end_vertex()!=NULL)
00112       {
00113          hTau  = first_daughter;
00114          hTau2 = second_daughter;
00115          ++it;
00116          break;
00117       }
00118       else if( abs(second_daughter->pdg_id())==15 && second_daughter->end_vertex()!=NULL)
00119       {
00120          hTau  = second_daughter;
00121          hTau2 = first_daughter;
00122          ++it;
00123          break;
00124       }
00125       else hX = NULL;
00126     }
00127   }
00128 
00129   // Boson not found - finished processing the event
00130   if(!hX) return 1;
00131 
00132   if(!hTau || !hTau2)
00133   {
00134     cout<<"ERROR: Something is wrong with event record."<<endl;
00135     exit(-1);
00136   }
00137 
00138   // Fill SimpleParticles from HepMC particles
00139   X.setPx(hX->momentum().px());
00140   X.setPy(hX->momentum().py());
00141   X.setPz(hX->momentum().pz());
00142   X.setE (hX->momentum().e ());
00143   X.setPdgid(hX->pdg_id());
00144 
00145   tau.setPx(hTau->momentum().px());
00146   tau.setPy(hTau->momentum().py());
00147   tau.setPz(hTau->momentum().pz());
00148   tau.setE (hTau->momentum().e ());
00149   tau.setPdgid(hTau->pdg_id());
00150 
00151   tau2.setPx(hTau2->momentum().px());
00152   tau2.setPy(hTau2->momentum().py());
00153   tau2.setPz(hTau2->momentum().pz());
00154   tau2.setE (hTau2->momentum().e ());
00155   tau2.setPdgid(hTau2->pdg_id());
00156 
00157   // Create list of tau daughters
00158   vector<SimpleParticle> *buf = getDaughters(hTau);
00159   tau_daughters.clear();
00160   tau_daughters.insert(tau_daughters.end(),buf->begin(),buf->end());
00161   
00162   delete buf;
00163 
00164   // Second particle can be 2nd tau. In that case - read its daughters.
00165   // Otherwise it is nu_tau~
00166   buf = getDaughters(hTau2);
00167   tau2_daughters.clear();
00168   tau2_daughters.insert(tau2_daughters.end(),buf->begin(),buf->end());
00169   
00170   delete buf;
00171 
00172   return 2;
00173 }
Generated on Sun Oct 20 20:24:10 2013 for C++InterfacetoTauola by  doxygen 1.6.3