CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/GeneratorInterface/GenFilters/src/BdecayFilter.cc

Go to the documentation of this file.
00001 #include "GeneratorInterface/GenFilters/interface/BdecayFilter.h"
00002 
00003 using namespace edm;
00004 using namespace std;
00005 using namespace HepMC;
00006 
00007 
00008 
00009 BdecayFilter::BdecayFilter(const edm::ParameterSet& iConfig)
00010 {
00011   label_ = iConfig.getUntrackedParameter("moduleLabel",std::string("generator"));
00012   motherParticle = iConfig.getParameter< int >("motherParticle");
00013 
00014   firstDaughter.type = iConfig.getParameter< int >("firstDaughter");
00015   firstDaughter.decayProduct   = iConfig.getParameter< vector<int> >("firstDaughterDecay");
00016   firstDaughter.etaMin = iConfig.getParameter<double>("firstDaughterDecayEtaMin");
00017   firstDaughter.etaMax = iConfig.getParameter<double>("firstDaughterDecayEtaMax");
00018   firstDaughter.ptMin = iConfig.getParameter<double>("firstDaughterDecayPtMin");
00019 
00020   secondDaughter.type = iConfig.getParameter< int >("secondDaughter");
00021   secondDaughter.decayProduct   = iConfig.getParameter< vector<int> >("secondDaughterDecay");
00022   secondDaughter.etaMin = iConfig.getParameter<double>("secondDaughterDecayEtaMin");
00023   secondDaughter.etaMax = iConfig.getParameter<double>("secondDaughterDecayEtaMax");
00024   secondDaughter.ptMin = iConfig.getParameter<double>("secondDaughterDecayPtMin");
00025 
00026   noAccepted = 0;
00027 }
00028 
00029 
00030 BdecayFilter::~BdecayFilter()
00031 {  
00032   std::cout << "Total number of accepted events = " << noAccepted << std::endl;
00033 }
00034 
00035 /*
00036 HepMC::GenParticle * BdecayFilter::findParticle(const GenPartVect genPartVect,
00037         const int requested_id)
00038 {
00039   for (GenPartVectIt p = genPartVect.begin(); p != genPartVect.end(); p++)
00040     {
00041       int event_particle_id = abs( (*p)->pdg_id() );
00042   cout << "isC "<<event_particle_id<<"\n";
00043       if (requested_id == event_particle_id) return *p;
00044     }
00045   return 0;
00046 }
00047 */
00048 
00049 HepMC::GenParticle * BdecayFilter::findParticle(HepMC::GenVertex* vertex, 
00050                                                    const int requested_id)
00051 {
00052   // for(std::set<GenParticle*>::const_iterator p = vertex->particles_out_const_begin(); 
00053   for(GenVertex::particles_out_const_iterator  p = vertex->particles_out_const_begin(); 
00054       p != vertex->particles_out_const_end(); p++)
00055     {
00056       int event_particle_id = abs( (*p)->pdg_id() );
00057       cout << "particle Id: "<<event_particle_id<<"\n";
00058       if (requested_id == event_particle_id) return *p;
00059     }
00060   return 0;
00061 }
00062 
00063 HepMC::GenEvent::particle_const_iterator BdecayFilter::getNextBs(const HepMC::GenEvent::particle_const_iterator start, const HepMC::GenEvent::particle_const_iterator end)
00064 {
00065   HepMC::GenEvent::particle_const_iterator p;
00066   for (p = start; p != end; p++) 
00067     {
00068       int event_particle_id = abs( (*p)->pdg_id() );
00069 //   cout << "search "<<event_particle_id<<"\n";
00070       if (event_particle_id == motherParticle) return p;
00071     }
00072   return p;  
00073 }
00074 
00075 
00076 bool BdecayFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00077 {
00078   edm::Handle<HepMCProduct> evt;
00079   iEvent.getByLabel(label_, evt);
00080   
00081   const HepMC::GenEvent * generated_event = evt->GetEvent();
00082   //cout << "Start\n";
00083 
00084   bool event_passed = false;
00085   HepMC::GenEvent::particle_const_iterator bs = getNextBs(generated_event->particles_begin(), generated_event->particles_end());
00086   while (bs!=  generated_event->particles_end() ) {
00087 
00088     // vector< GenParticle * > bsChild = (*bs)->listChildren();
00089 
00090     //***
00091     HepMC::GenVertex* outVertex = (*bs)->end_vertex();
00092     //***
00093     
00094     GenParticle * jpsi = 0;
00095     GenParticle * phi = 0;
00096     // cout << "bs size "<<bsChild.size()<<endl;
00097     //***
00098     int numChildren = outVertex->particles_out_size();
00099     cout<< "B children "<<numChildren<<endl;
00100     //***
00101     
00102     /*    if ((bsChild.size()==2) && ((jpsi = findParticle(bsChild, 443))!=0) && 
00103           ((phi = findParticle(bsChild, 333))!=0)) {
00104           cout << bsChild[0]->momentum()<<" "<<bsChild[0]->momentum().eta()
00105           <<" "<<bsChild[1]->momentum()<<" "<<bsChild[1]->momentum().eta()<<endl;
00106     */
00107     
00108     //***
00109     if( (numChildren==2) && ((jpsi = findParticle(outVertex, firstDaughter.type))!=0) && 
00110         ((phi = findParticle(outVertex, secondDaughter.type))!=0)) {
00111       
00112       cout << jpsi->momentum().rho() <<" "<<jpsi->momentum().eta() <<" "<<phi->momentum().rho()<<" "<<phi->momentum().eta()<<endl;
00113       //cout <<"bs dec trouve"<<endl;
00114       if (cuts(phi, secondDaughter) && cuts(jpsi, firstDaughter)) {
00115         cout <<"decay found"<<endl;
00116         event_passed = true;
00117         break;
00118       }
00119     }
00120     bs = getNextBs(++bs, generated_event->particles_end());
00121   }
00122   
00123   if (event_passed) noAccepted++;
00124   cout << "End filter\n";
00125   
00126   delete generated_event; 
00127   
00128   return event_passed;
00129 }
00130 
00131 
00132 bool BdecayFilter::cuts(const GenParticle * jpsi, const CutStruct cut)
00133 {
00134         cout << "start cuts" << endl;
00135   HepMC::GenVertex* myVertex = jpsi->end_vertex();
00136   int numChildren = myVertex->particles_out_size();
00137   int numDecProd = cut.decayProduct.size();
00138   std::vector<HepMC::GenParticle*> psiChild;
00139   // for(std::set<GenParticle*>::const_iterator p = myVertex->particles_out_const_begin();
00140   for(GenVertex::particles_out_const_iterator p = myVertex->particles_out_const_begin();
00141       p != myVertex->particles_out_const_end(); p++) 
00142     psiChild.push_back((*p));
00143 
00144   if (numChildren!=numDecProd) return false;
00145     cout << psiChild[0]->pdg_id()<<" "<<psiChild[1]->pdg_id()<<endl;
00146 
00147   for (int i=0; i<numChildren; ++i) {
00148     bool goodPart = false;
00149     for (int j=0; j < numChildren; ++j){
00150       if (abs(psiChild[i]->pdg_id()) == abs(cut.decayProduct[j])) goodPart = true;
00151         }
00152         cout << psiChild[i]->momentum().perp() << endl;
00153     if ( !goodPart || (!etaInRange(psiChild[i]->momentum().eta(), cut.etaMin, cut.etaMax)) || (psiChild[i]->momentum().perp() < cut.ptMin) ) return false;
00154   }
00155         cout << "cuts true" << endl;
00156   return true;
00157 }
00158 
00159 bool BdecayFilter::etaInRange(float eta, float etamin, float etamax)
00160 {
00161   return ( (etamin < eta) && (eta < etamax) );
00162 }