CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #include "GeneratorInterface/GenFilters/interface/PythiaFilterGammaJetWithBg.h"
00002 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00003 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include <iostream>
00007 #include<list>
00008 #include<vector>
00009 #include<cmath>
00010 
00011 //using namespace edm;
00012 //using namespace std;
00013 
00014 namespace{
00015 
00016   double deltaR2(double eta0, double phi0, double eta, double phi){
00017     double dphi=phi-phi0;
00018     if(dphi>M_PI) dphi-=2*M_PI;
00019     else if(dphi<=-M_PI) dphi+=2*M_PI;
00020     return dphi*dphi+(eta-eta0)*(eta-eta0);
00021   }
00022 
00023   double deltaPhi(double phi0, double phi){
00024     double dphi=phi-phi0;
00025     if(dphi>M_PI) dphi-=2*M_PI;
00026     else if(dphi<=-M_PI) dphi+=2*M_PI;
00027     return dphi;
00028   }
00029 
00030   class ParticlePtGreater{
00031   public:
00032     int operator()(const HepMC::GenParticle * p1, 
00033                    const HepMC::GenParticle * p2) const{
00034       return p1->momentum().perp() > p2->momentum().perp();
00035     }
00036   };
00037 }
00038 
00039 
00040 PythiaFilterGammaJetWithBg::PythiaFilterGammaJetWithBg(const edm::ParameterSet& iConfig) :
00041 label_(iConfig.getUntrackedParameter("moduleLabel",std::string("generator"))),
00042 etaMax(iConfig.getUntrackedParameter<double>("MaxPhotonEta", 2.8)),
00043 ptSeed(iConfig.getUntrackedParameter<double>("PhotonSeedPt", 5.)),
00044 ptMin(iConfig.getUntrackedParameter<double>("MinPhotonPt")),
00045 ptMax(iConfig.getUntrackedParameter<double>("MaxPhotonPt")),
00046 dphiMin(iConfig.getUntrackedParameter<double>("MinDeltaPhi", -1)/180*M_PI),
00047 detaMax(iConfig.getUntrackedParameter<double>("MaxDeltaEta", 10.)),
00048 etaPhotonCut2(iConfig.getUntrackedParameter<double>("MinPhotonEtaForwardJet", 1.3)),
00049 cone(0.5),ebEtaMax(1.479),
00050 maxnumberofeventsinrun(iConfig.getUntrackedParameter<int>("MaxEvents",10)){ 
00051   
00052   deltaEB=0.01745/2  *5; // delta_eta, delta_phi
00053   deltaEE=2.93/317/2 *5; // delta_x/z, delta_y/z
00054   theNumberOfSelected = 0;
00055 }
00056 
00057 
00058 PythiaFilterGammaJetWithBg::~PythiaFilterGammaJetWithBg(){}
00059 
00060 
00061 // ------------ method called to produce the data  ------------
00062 bool PythiaFilterGammaJetWithBg::filter(edm::Event& iEvent, const edm::EventSetup& iSetup){
00063 
00064 // <<<<<<< PythiaFilterGammaJetWithBg.cc
00065 //  if(theNumberOfSelected>=maxnumberofeventsinrun)   {
00066 //    throw cms::Exception("endJob")<<"we have reached the maximum number of events ";
00067 //  }
00068 // =======
00069 // >>>>>>> 1.4
00070 
00071   bool accepted = false;
00072   edm::Handle<edm::HepMCProduct> evt;
00073   iEvent.getByLabel(label_, evt);
00074 
00075   std::list<const HepMC::GenParticle *> seeds;
00076   const HepMC::GenEvent * myGenEvent = evt->GetEvent();
00077 
00078   for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();   p != myGenEvent->particles_end(); ++p ) {
00079    
00080     if ( (*p)->pdg_id()==22 && (*p)->status()==1
00081          && (*p)->momentum().perp() > ptSeed 
00082          && std::abs((*p)->momentum().eta()) < etaMax  ) seeds.push_back(*p);
00083 
00084   }
00085 
00086   seeds.sort(ParticlePtGreater());
00087   
00088 //  std::cout<<" Number of seeds "<<seeds.size()<<" ProccessID "<<myGenEvent->signal_process_id()<<std::endl;
00089 //  std::cout<<" ParticleId 7= "<<myGenEvent->particle(7)->pdg_id()
00090 //  <<" pT "<<myGenEvent->particle(7)->momentum().perp()
00091 //  <<" Eta "<<myGenEvent->particle(7)->momentum().eta()
00092 //  <<" Phi "<<myGenEvent->particle(7)->momentum().phi()<<std::endl;
00093 //  std::cout<<" ParticleId 8= "<<myGenEvent->particle(8)->pdg_id()<<" pT "<<myGenEvent->particle(8)->momentum().perp()<<" Eta "<<myGenEvent->particle(8)->momentum().eta()<<" Phi "<<myGenEvent->particle(8)->momentum().phi()<<std::endl;
00094 
00095   for(std::list<const HepMC::GenParticle *>::const_iterator is=
00096         seeds.begin(); is!=seeds.end(); is++){
00097  
00098     double etaPhoton=(*is)->momentum().eta();
00099     double phiPhoton=(*is)->momentum().phi();
00100 
00101     /*
00102     double dphi7=std::abs(deltaPhi(phiPhoton, 
00103                                myGenEvent->particle(7)->momentum().phi()));
00104     double dphi=std::abs(deltaPhi(phiPhoton, 
00105                               myGenEvent->particle(8)->momentum().phi()));
00106     */
00107 
00108     //***
00109     HepMC::GenEvent::particle_const_iterator ppp = myGenEvent->particles_begin();
00110     for(int i=0;i<6;++i) ppp++;
00111     HepMC::GenParticle* particle7 = (*ppp);
00112     ppp++;
00113     HepMC::GenParticle* particle8 = (*ppp);
00114 
00115     double dphi7=std::abs(deltaPhi(phiPhoton, 
00116                                    particle7->momentum().phi()));
00117     double dphi=std::abs(deltaPhi(phiPhoton, 
00118                                   particle8->momentum().phi()));
00119     //***
00120 
00121     int jetline=8;
00122     int photonline = 7; 
00123     if(dphi7>dphi) {
00124       dphi=dphi7;
00125       jetline=7;
00126       photonline = 8; 
00127     }
00128     
00129 //    std::cout<<" Dphi "<<dphi<<" "<<dphiMin<<std::endl;
00130 //    if(dphi<dphiMin) {
00131 //      std::cout<<"Reject dphi"<<std::endl;
00132 //      continue;
00133 //    }
00134     
00135     //double etaJet= myGenEvent->particle(jetline)->momentum().eta();
00136     //***
00137     double etaJet = 0.0;
00138     if(jetline==8) etaJet = particle8->momentum().eta();
00139     else etaJet = particle7->momentum().eta();
00140     //***
00141 
00142     double eta1=etaJet-detaMax;
00143     double eta2=etaJet+detaMax;
00144     if (eta1>etaPhotonCut2) eta1=etaPhotonCut2;
00145     if (eta2<-etaPhotonCut2) eta2=-etaPhotonCut2;
00146 //    std::cout<<" Etaphoton "<<etaPhoton<<" "<<eta1<<" "<<eta2<<std::endl;
00147     if (etaPhoton<eta1 ||etaPhoton>eta2) {
00148 //       std::cout<<"Reject eta"<<std::endl;
00149        continue;
00150     }
00151     bool inEB(0);
00152     double tgx(0);
00153     double tgy(0);
00154     if( std::abs(etaPhoton)<ebEtaMax) inEB=1;
00155     else{
00156       tgx=(*is)->momentum().px()/(*is)->momentum().pz();
00157       tgy=(*is)->momentum().py()/(*is)->momentum().pz();
00158     }
00159 
00160     double etPhoton=0;
00161     double etPhotonCharged=0;
00162     double etCone=0;
00163     double etConeCharged=0;
00164     double ptMaxHadron=0;
00165     
00166     
00167     for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();   p != myGenEvent->particles_end(); ++p ) {
00168     
00169       if ( (*p)->status()!=1 ) continue; 
00170       int pid= (*p)->pdg_id();
00171       int apid= std::abs(pid);
00172       if (apid>11 &&  apid<21) continue; //get rid of muons and neutrinos
00173       double eta=(*p)->momentum().eta();
00174       double phi=(*p)->momentum().phi();
00175       if (deltaR2(etaPhoton, phiPhoton, eta, phi)>cone*cone) continue;
00176       double pt=(*p)->momentum().perp();
00177       
00178       //***
00179       edm::ESHandle<ParticleDataTable> pdt;
00180       iSetup.getData( pdt );
00181       
00182       
00183       // double charge=(*p)->particledata().charge();
00184       // int charge3=(*p)->particleID().threeCharge();
00185       
00186       int charge3 = ((pdt->particle((*p)->pdg_id()))->ID().threeCharge());
00187       //***
00188 
00189       etCone+=pt;
00190       if(charge3 && pt<2) etConeCharged+=pt;
00191 
00192       //select particles matching a crystal array centered on photon
00193       if(inEB) {
00194         if(  std::abs(eta-etaPhoton)> deltaEB ||
00195              std::abs(deltaPhi(phi,phiPhoton)) > deltaEB) continue;
00196       }
00197       else if( std::abs((*p)->momentum().px()/(*p)->momentum().pz() - tgx)
00198                > deltaEE || 
00199                std::abs((*p)->momentum().py()/(*p)->momentum().pz() - tgy)
00200                > deltaEE) continue;
00201 
00202       etPhoton+=pt;
00203       if(charge3 && pt<2) etPhotonCharged+=pt;
00204       if(apid>100 && apid!=310 && pt>ptMaxHadron) ptMaxHadron=pt;
00205 
00206     }
00207 //    std::cout<<" etPhoton "<<etPhoton<<" "<<ptMin<<" "<<ptMax<<std::endl;
00208     
00209     if(etPhoton<ptMin ||etPhoton>ptMax) {
00210 //     std::cout<<" Reject etPhoton "<<std::endl;
00211      continue;
00212     }
00213     //isolation cuts
00214 
00215     double isocut1 = 5+etPhoton/20-etPhoton*etPhoton/1e4;
00216     double isocut2 = 3+etPhoton/20-etPhoton*etPhoton*etPhoton/1e6;
00217     double isocut3 = 4.5+etPhoton/40;
00218     if (etPhoton>165.)
00219     {
00220       isocut1 = 5.+165./20.-165.*165./1e4;
00221       isocut2 = 3.+165./20.-165.*165.*165./1e6;
00222       isocut3 = 4.5+165./40.;
00223     }
00224 
00225 //    std::cout<<" etCone "<<etCone<<" "<<etPhoton<<" "<<etCone-etPhoton<<" "<<isocut1<<std::endl;
00226 //    std::cout<<"Second cut on iso "<<etCone-etPhoton-(etConeCharged-etPhotonCharged)<<" cut value "<<isocut2<<" etPhoton "<<etPhoton<<std::endl;
00227 //    std::cout<<" PtHadron "<<ptMaxHadron<<" "<<4.5+etPhoton/40<<std::endl;
00228     
00229     if(etCone-etPhoton> 5+etPhoton/20-etPhoton*etPhoton/1e4) continue;
00230 //    std::cout<<" Accept 1"<<std::endl;
00231     if(etCone-etPhoton-(etConeCharged-etPhotonCharged) > 
00232        isocut2) continue;
00233 //     std::cout<<" Accept 2"<<std::endl;
00234     if(ptMaxHadron > isocut3) continue;
00235     
00236 //    std::cout<<"Accept event "<<std::endl;
00237     accepted=true;
00238     break;
00239 
00240   } //loop over seeds
00241   
00242   
00243   if (accepted) {
00244     theNumberOfSelected++;
00245     std::cout<<" Event preselected "<<theNumberOfSelected<<" Proccess ID "<<myGenEvent->signal_process_id()<<std::endl;
00246     return true; 
00247   }
00248   else return false;
00249 
00250 }
00251