Пример #1
0
// always top first, tobar second if both exist
std::vector<reco::GenParticle> GenTopEvent::GetAllWAntiQuarks() const{
  if(!isFilled) std::cerr << "Trying to access GenTopEvent but it is not filled" << std::endl;
  std::vector<reco::GenParticle> quarks;
  for(auto p=wplus_decay_products.begin();isFilled&& p!=wplus_decay_products.end();p++){
    if(p->pdgId()<0&&p->pdgId()>-6) quarks.push_back(*p);
  }
  for(auto p=wminus_decay_products.begin();isFilled&& p!=wminus_decay_products.end();p++){
    if(p->pdgId()<0&&p->pdgId()>-6) quarks.push_back(*p);
  }
  return quarks;
}
Пример #2
0
// always top first, tobar second if both exist
std::vector<reco::GenParticle> GenTopEvent::GetAllNeutrinos() const{
  std::vector<reco::GenParticle> neutrinos;
  for(auto p=wplus_decay_products.begin(); isFilled&&p!=wplus_decay_products.end();p++){
    if(abs(p->pdgId())==12||abs(p->pdgId())==14||abs(p->pdgId())==16) neutrinos.push_back(*p);
  }
  for(auto p=wminus_decay_products.begin(); isFilled&&p!=wminus_decay_products.end();p++){
    if(abs(p->pdgId())==12||abs(p->pdgId())==14||abs(p->pdgId())==16) neutrinos.push_back(*p);
  }
  return neutrinos;
}
Пример #3
0
// always top first, tobar second if both exist
std::vector<reco::GenParticle> GenTopEvent::GetAllLeptons() const{
  if(!isFilled) std::cerr << "Trying to access GenTopEvent but it is not filled" << std::endl;
  std::vector<reco::GenParticle> leptons;
  for(auto p=wplus_decay_products.begin();isFilled&& p!=wplus_decay_products.end();p++){
    if(abs(p->pdgId())==11||abs(p->pdgId())==13||abs(p->pdgId())==15) leptons.push_back(*p);
  }
  for(auto p=wminus_decay_products.begin();isFilled&& p!=wminus_decay_products.end();p++){
    if(abs(p->pdgId())==11||abs(p->pdgId())==13||abs(p->pdgId())==15) leptons.push_back(*p);
  }
  return leptons;
}
Пример #4
0
reco::GenParticle GenTopEvent::GetNeutrino() const{
  if(!isFilled) std::cerr << "Trying to access GenTopEvent but it is not filled" << std::endl;
  if(topIsHadronic&&!topbarIsHadronic){
    for(auto p=wminus_decay_products.begin();p!=wminus_decay_products.end();p++){
      if(abs(p->pdgId())==12||abs(p->pdgId())==14||abs(p->pdgId())==16)
	return *p;
    }
    std::cerr <<"no lepton found" <<std::endl;
    return reco::GenParticle();
  }
  else if(!topIsHadronic&&topbarIsHadronic){
    for(auto p=wplus_decay_products.begin();p!=wplus_decay_products.end();p++){
      if(abs(p->pdgId())==12||abs(p->pdgId())==14||abs(p->pdgId())==16)
	return *p;
    }
    std::cerr <<"no lepton found" <<std::endl;
    return reco::GenParticle();
  }
  std::cerr <<"hadronic/leptonic function called in GenTopEvent, but not a semileptonic event" << std::endl;
  return reco::GenParticle();  
}
Пример #5
0
int NeroMonteCarlo::analyze(const edm::Event& iEvent){

    if ( iEvent.isRealData() ) return 0;
    isRealData = iEvent.isRealData() ? 1 : 0 ; // private, not the one in the tree

    TStopwatch sw;
    if(VERBOSE)sw.Start();
    // maybe handle should be taken before
    iEvent.getByToken(info_token, info_handle);
    iEvent.getByToken(packed_token, packed_handle);
    iEvent.getByToken(pruned_token, pruned_handle);
    iEvent.getByToken(pu_token, pu_handle);
    iEvent.getByToken(jet_token, jet_handle);

    if ( not info_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] info_handle is not valid"<<endl;
    if ( not packed_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] packed_handle is not valid"<<endl;
    if ( not pruned_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] pruned_handle is not valid"<<endl;
    if ( not pu_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] pu_handle is not valid"<<endl;
    if ( not jet_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] jet_handle is not valid"<<endl;

    if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] getToken took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();}
    // INFO
    if(VERBOSE>1) cout<<"[NeroMonteCarlo]::[analyze]::[DEBUG] mcWeight="<<endl;
    mcWeight = info_handle -> weight();
    if(VERBOSE>1) cout<<"                                     mcWeight="<<mcWeight<<endl;
    //weights() 
    //---  scale
    if ( info_handle -> weights()  .size() >= 9){
        r1f2 = info_handle -> weights() [1] ;   
        r1f5 = info_handle -> weights() [2] ;   
        r2f1 = info_handle -> weights() [3] ;   
        r2f2 = info_handle -> weights() [4] ;   
        r5f1 = info_handle -> weights() [6] ;    
        r5f5 = info_handle -> weights() [8] ;     
    }

    if (info_handle -> weights().size() > 109)
        for( int pdfw = 9 ; pdfw<109 ;++pdfw)
        {
        pdfRwgt -> push_back( info_handle -> weights() [pdfw] );    
        }
    // --- fill pdf Weights
    //
    if(VERBOSE>1) cout<<"[NeroMonteCarlo]::[analyze]::[DEBUG] PDF="<<endl;
    if ( mParticleGun ) {
        qScale   = -999 ;
        alphaQED = -999 ;
        alphaQCD = -999 ;
        x1       = -999 ;
        x2       = -999 ;
        pdf1Id   = -999 ;
        pdf2Id   = -999 ;
        scalePdf = -999 ;
    }
    else {
        qScale   = info_handle -> qScale();
        alphaQED = info_handle -> alphaQED();
        alphaQCD = info_handle -> alphaQCD();
        x1       = info_handle -> pdf() -> x.first;
        x2       = info_handle -> pdf() -> x.second;
        pdf1Id   = info_handle -> pdf() -> id.first;
        pdf2Id   = info_handle -> pdf() -> id.second;
        scalePdf = info_handle -> pdf() -> scalePDF;
    }
    if(VERBOSE>1) cout<<"                                     PDF="<<qScale<<" "<< alphaQED<<endl;

    //PU
    if(VERBOSE>1){ cout<<endl<<"[NeroMonteCarlo]::[analyze] PU LOOP"<<endl;}
    puTrueInt = 0;
    for(const auto & pu : *pu_handle)
    {
        //Intime
        if (pu.getBunchCrossing() == 0)
            puTrueInt += pu.getTrueNumInteractions();
        //puInt += getPU_NumInteractions(); //old
        //Out-of-time
    }

    if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] pu&info took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();}
    // GEN PARTICLES
    //TLorentzVector genmet(0,0,0,0);
    //for ( auto & gen : *packed_handle)
    for ( unsigned int i=0;i < packed_handle->size() ;++i)
    {
        const auto gen  = & (*packed_handle)[i];
        if (gen->pt()  < 5 ) continue;
        if (gen->pt() < mMinGenParticlePt ) continue;
        int pdg = gen->pdgId();
        int apdg = abs(pdg);

        //neutrinos
        // --- if ( (apdg != 12 and apdg !=14 and apdg != 16
        // ---       and apdg > 1000000  neutrinos and neutralinos
        // ---      )//SUSY
        // ---         and fabs(gen->eta() ) <4.7 
        // ---    )
        // --- { 
        // ---     TLorentzVector tmp( gen->px(),gen->py(),gen->pz(),gen->energy() ); 
        // ---     genmet += tmp;
        // --- }
        // --- genmet = -genmet;


        //FILL
        //    e mu photons
        if ( apdg == 11 or apdg == 13 or apdg == 22  // e - mu - gamma
                or (apdg >=12 and apdg<=16) // neutrinos
                or apdg > 1000000  // susy neutrinos and neutralinos
            )
        {
            new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(gen->px(), gen->py(), gen->pz(), gen->energy());
            pdgId -> push_back( pdg );
            flags -> push_back( ComputeFlags( *gen ) );
            // compute ISOLATION
            float iso=0;
            float isoFx=0;

            if (apdg == 22 or apdg ==11 or apdg ==13)
            {

                    TLorentzVector g1(gen->px(),gen->py(),gen->pz(),gen->energy());
                    vector< pair<float,float> > inIsoFx ; //isoFx, dR, pT
                    for ( unsigned int j=0;j < packed_handle->size() ;++j)
                    {
                        if (i==j) continue;
                        const auto gen2  = & (*packed_handle)[j];
                        if ( gen2->pt() ==0 ) continue;
                        if (gen2->pz() > 10e8 ) continue; // inf
                        TLorentzVector g2(gen2->px(),gen2->py(),gen2->pz(),gen2->energy());
                        if (g2.DeltaR(g1) <0.4){
                            iso += g2.Pt();
                            // isoFx containes the epsilon 
                            inIsoFx.push_back( pair<float,float>(g2.DeltaR(g1) ,g2.Pt() ) );
                         }
                    }

                    if (apdg==22){ // ONLY for photon Frixione isolation
                        sort(inIsoFx.begin(), inIsoFx.end() );  // sort in DR, first entry

                        float sumEtFx=0;
                        for( const auto & p : inIsoFx )
                        {
                               const float& pt= p.second ;
                               const float& delta = p.first;
                               sumEtFx += pt / gen->pt(); // relative iso
                               if (delta == 0 ) continue; // guard
                               float isoCandidate = sumEtFx * TMath::Power(  (1. - TMath::Cos(0.4) ) / (1. - TMath::Cos(delta ) ), 2) ;// n=2
                               if (isoFx < isoCandidate) isoFx = isoCandidate;
                        }
                    }
            
            }
            genIso -> push_back(iso);
            genIsoFrixione -> push_back(isoFx);
            // computed dressed objects
            //

            if (apdg == 11 or apdg == 13) { // only for final state muons and electrons
                    TLorentzVector dressedLepton(gen->px(),gen->py(),gen->pz(),gen->energy());
                    TLorentzVector lepton(dressedLepton); //original lepton for dR
                    for ( unsigned int j=0;j < packed_handle->size() ;++j)
                    {
                        const auto gen2  = & (*packed_handle)[j];
                        TLorentzVector photon(gen2->px(),gen2->py(),gen2->pz(),gen2->energy());
                        if (i != j and abs( gen->pdgId() ) ==22  and lepton.DeltaR( photon ) <0.1 ) dressedLepton += photon;
                    }
                    new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector( dressedLepton );
                    pdgId -> push_back( pdg );
                    flags -> push_back( Dressed );
                    genIso -> push_back (0.) ;
                    genIsoFrixione -> push_back (0.) ;
                    // --- end of dressing
            }
             
        }

    } //end packed


    if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] packed took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();}
    // LOOP over PRUNED PARTICLES
    //for (auto & gen : *pruned_handle)
    for (unsigned int i=0;i<pruned_handle->size() ;++i)
    {
        const auto gen = &(*pruned_handle)[i];
        if (gen->pt()  < 5 ) continue;
        if (gen->pt()  < mMinGenParticlePt ) continue;
        int pdg = gen->pdgId();
        int apdg = abs(pdg);
        if (gen->status() == 1) continue; //packed

        unsigned flag = ComputeFlags(*gen);

    
        if ( apdg == 15 or  // tau (15)
                (apdg >= 23 and apdg <26 ) or   // Z(23) W(24) H(25)
                apdg == 37 or // chHiggs: H+(37)
                apdg <= 6 or // quarks up (2) down (1)  charm (4) strange (3) top (6) bottom (5)
                apdg == 21 or // gluons (21)
                apdg > 1000000 // susy neutrinos,neutralinos, charginos ...  lightest neutralinos (1000022)
                or ( apdg == 11 and  ( flag &  HardProcessBeforeFSR) )
                or ( apdg == 11 and  ( flag &  HardProcess) )
                or ( apdg == 13 and  ( flag &  HardProcessBeforeFSR) )
                or ( apdg == 13 and  ( flag &  HardProcess) )
                )
        {
            new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(gen->px(), gen->py(), gen->pz(), gen->energy());
            pdgId -> push_back( pdg );
            flags -> push_back( flag );
            genIso -> push_back (0.) ;
            genIsoFrixione -> push_back (0.) ;
        }
    }

    if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] pruned took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();}
    // GEN JETS
    for (const auto & j : *jet_handle)
    {
        if (j.pt() < 20 ) continue;
        if (j.pt() < mMinGenJetPt ) continue;
        // --- FILL
        new ( (*jetP4)[jetP4->GetEntriesFast()]) TLorentzVector(j.px(), j.py(), j.pz(), j.energy());
    }
    if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] jets took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset();}
    return 0;
}
Пример #6
0
void GenTopEvent::Fill(const std::vector<reco::GenParticle>& prunedGenParticles, int ttXid_){

  ttXid=ttXid_;
  for(auto p=prunedGenParticles.begin(); p!=prunedGenParticles.end(); p++){
    if (abs(p->pdgId())==6){
      bool lastTop=true;
      for(uint i=0;i<p->numberOfDaughters();i++){
	if (abs(p->daughter(i)->pdgId())==6)
	  lastTop=false;
      }
      if(lastTop){
	if(p->pdgId()==6) top=*p;
	if(p->pdgId()==-6) topbar=*p;
	bool setTDecay=false;
	bool setTBarDecay=false;
	for(uint i=0;i<p->numberOfDaughters();i++){
	  if(p->pdgId()==6 && abs(p->daughter(i)->pdgId())<6){
	    if(setTDecay) std::cerr << "GenTopEvent: error 1"<<std::endl;
	    top_decay_quark=*(reco::GenParticle*)p->daughter(i);
	    setTDecay=true;
	  }
	  if(p->pdgId()==-6 && abs(p->daughter(i)->pdgId())<6){
	    if(setTBarDecay) std::cerr << "GenTopEvent: error 1"<<std::endl;
	    topbar_decay_quark=*(reco::GenParticle*)p->daughter(i);
	    setTBarDecay=true;
	  }
	}
      }
    }
  
    if (abs(p->pdgId())==24){
      bool lastW=true;
      for(uint i=0;i<p->numberOfDaughters();i++){
	if (abs(p->daughter(i)->pdgId())==24)
	  lastW=false;
      }
      bool fromT=false;
      const reco::Candidate* mother=&(*p);
      while(mother!=0 && abs(mother->pdgId())==24){
	if (abs(mother->mother()->pdgId())==6){
	  fromT=true;
	  break;
	}
	else mother=mother->mother();
	
      }
      if(lastW&&fromT){
	if(p->pdgId()==24) wplus=*p;
	if(p->pdgId()==-24) wminus=*p;
	for(uint i=0;i<p->numberOfDaughters();i++){
	  if(p->pdgId()==24 && abs(p->daughter(i)->pdgId())<=16){
	    wplus_decay_products.push_back(*(reco::GenParticle*)p->daughter(i));
	  }
	  if(p->pdgId()==-24 && abs(p->daughter(i)->pdgId())<=16){
	    wminus_decay_products.push_back(*(reco::GenParticle*)p->daughter(i));
	  }
	}
      }
    }

    if (abs(p->pdgId())==25){
      bool lastH=true;
      for(uint i=0;i<p->numberOfDaughters();i++){
	if (abs(p->daughter(i)->pdgId())==25)
	  lastH=false;
      }
      if(lastH){
	higgs=*p;
	for(uint i=0;i<p->numberOfDaughters();i++){
	  if(p->pdgId()==25 && abs(p->daughter(i)->pdgId())!=25){
	    higgs_decay_products.push_back(*(reco::GenParticle*)p->daughter(i));
	  }
	}
      }
    }

  }
  if(wminus_decay_products.size()!=2 || wplus_decay_products.size()!=2) std::cerr << "GenTopEvent: error 2"<<std::endl;
  if(top.energy()<1||topbar.energy()<1||wplus.energy()<1||wminus.energy()<1||top_decay_quark.energy()<1||topbar_decay_quark.energy()<1) std::cerr << "GenTopEvent: error 4"<<std::endl;

  int nquarks_from_wplus=0;
  for(auto p=wplus_decay_products.begin(); p!=wplus_decay_products.end();p++){
    if(abs(p->pdgId())<6) nquarks_from_wplus++;
  }
  int nquarks_from_wminus=0;
  for(auto p=wminus_decay_products.begin(); p!=wminus_decay_products.end();p++){
    if(abs(p->pdgId())<6) nquarks_from_wminus++;
  }
  topIsHadronic=nquarks_from_wplus==2;
  topbarIsHadronic=nquarks_from_wminus==2;
  isFilled=true;
}