void printJet(Jet *jet)
{

  GenParticle *particle;
  Muon *muon;

  Track *track;
  Tower *tower;

  TObject *object;
  TLorentzVector momentum;
      momentum.SetPxPyPzE(0.0, 0.0, 0.0, 0.0);
      //TRefArray constituentarray(jet->Constituents);
      TRefArray particlearray(jet->Particles);
      cout<<"Looping over jet constituents. Jet pt: "<<jet->PT<<", eta: "<<jet->Eta<<", phi: "<<jet->Phi<<endl;      

      // Loop over all jet's constituents
      for(Int_t j = 0; j < jet->Constituents.GetEntriesFast(); ++j)
      {
        object = jet->Constituents.At(j);
        // Check if the constituent is accessible
        if(object == 0) continue;

        if(object->IsA() == GenParticle::Class())
        {
          particle = (GenParticle*) object;
          cout << "    GenPart pt: " << particle->PT << ", eta: " << particle->Eta << ", phi: " << particle->Phi << endl;
          momentum += particle->P4();
        }
        else if(object->IsA() == Track::Class())
        {
          track = (Track*) object;
          cout << "    Track pt: " << track->PT << ", eta: " << track->Eta << ", phi: " << track->Phi << endl;
          momentum += track->P4();
        }
        else if(object->IsA() == Tower::Class())
        {
          tower = (Tower*) object;
          cout << "    Tower pt: " << tower->ET << ", eta: " << tower->Eta << ", phi: " << tower->Phi << endl;
          momentum += tower->P4();
        }
        else if(object->IsA() == Muon::Class())
        {
          muon = (Muon*) object;
          cout << "    Muon pt: " << muon->PT << ", eta: " << muon->Eta << ", phi: " << muon->Phi << endl;
          momentum += muon->P4();
        }
      }
      cout << " constituent sum pt:  " << momentum.Pt() <<" eta "<< momentum.Eta()  <<"  phi " << momentum.Phi() << std::endl;


      for (Int_t j =0; j<jet->Particles.GetEntries();  j++){
     		GenParticle *p_tmp = (GenParticle*) particlearray.At(j);
		printGenParticle(p_tmp);
	}
}
Beispiel #2
0
bool Event::GenParticleDecayedFrom( int iGenPar, int apdgid ,int& idx){
    //if( apdgid==25) Logger::getInstance().Log("Event",__FUNCTION__,"DEBUG",Form("* Called GenParticleDecaydFrom %d",iGenPar) );//DEBUG
    GenParticle *g = GetGenParticle(iGenPar);
    if (g ==NULL)return false;
    //if( apdgid==25) Logger::getInstance().Log("Event",__FUNCTION__,"DEBUG",Form("*  ---> Current pdgId is %d",g->GetPdgId()) );//DEBUG
    if (abs(g->GetPdgId()) == apdgid) { idx=iGenPar; return true;}
    int moidx = g->GetParentIdx();
    if (moidx == iGenPar) return false;
    return GenParticleDecayedFrom( moidx, apdgid,idx);
}
void GenParticleFactory::update()
/*****************************************************************/
{
    m_data.clear();
    for(int i=0;i<m_gen_n;i++)
    {
        GenParticle gen;
        gen.setId        ( (*m_gen_id)[i] );
        gen.setStatus    ( (*m_gen_status)[i] );
        gen.SetPtEtaPhiE ( (*m_gen_pt)[i], (*m_gen_eta)[i], (*m_gen_phi)[i], (*m_gen_energy)[i] );

        m_data.push_back( gen );
    }
}
Beispiel #4
0
GenParticle * Event::GetGenStable( int iGenPar ,int pdgid,float aeta) 
{  
    // status 1, electrons
    vector<pair<float,int> > valid; // pt, idx
    for(int i = 0 ; i<genparticles_.size() ;++i)
    {
        GenParticle *gp = genparticles_[i];
        if (not gp->IsPromptFinalState()  ) continue;
        if ( abs(gp->GetPdgId()) != pdgid)  continue;
        if ( fabs(gp->Eta() ) > aeta) continue;
        valid.push_back(pair<float,int>(gp->Pt(),i)); 
    }
    if (valid.size() == 0 ) return NULL;
    if (valid.size() <= iGenPar  ) return NULL;

    sort(valid.begin(),valid.end(),[](pair<float,int> &a,pair<float,int> &b) { if (a.first> b.first) return true; if (a.first<b.first) return false; return a.second<b.second;} ) ;

    return genparticles_[ valid[iGenPar].second];
}
Beispiel #5
0
int Tau::Rematch(Event *e,float dR){
    if (rematch_ >=0 ) return rematch_; // cache

    GenParticle * gp =NULL;
    int ig=0;
    bool isTau=false;
    bool isQuark=false;
    bool isGluon=false;
    bool isEle = false;
    bool isMuon= false;
    float hardestPt=-1.;
    bool isHardestQ = false;

    for (gp = e->GetGenParticle(ig) ; gp != NULL ; gp=e->GetGenParticle(++ig))
    {
        if  (gp->DeltaR(this) >dR) continue;
        //if  (gp->IsPromptFinalState() ) continue; // useless
        if  ( abs(gp->GetPdgId()) == 15 ) isTau = true; // I don't care the status
        if ( abs(gp->GetPdgId()) == 11) 
        {
            isEle = true;
        }
        if ( abs(gp->GetPdgId()) == 13) 
        {
            isMuon = true;
        }
        if ( abs(gp->GetPdgId() ) == 21 )
            {
            isGluon=true;
            if (hardestPt < gp->Pt() ) { hardestPt=gp->Pt(); isHardestQ=false;}
            }
        if ( abs(gp->GetPdgId() ) <= 4 )
            {
            isQuark=true;
            if (hardestPt < gp->Pt() ) { hardestPt=gp->Pt(); isHardestQ=true;}
            }
    }
    if (isTau) rematch_=15;
    //the additional check isQuark, prevent the default value on isHardest
    if (rematch_<0 and isMuon) rematch_=13;
    if (rematch_<0 and isEle) rematch_=11;
    if (rematch_ <0 and isQuark and isHardestQ) rematch_=1;
    if (rematch_ <0 and isGluon and not isHardestQ) rematch_=21;
    // no match
    if (rematch_ <0 ) rematch_=0;
    return rematch_;
}
Beispiel #6
0
void AnalyseEvents(ExRootTreeReader *treeReader, TestPlots *plots)
{
  TClonesArray *branchParticle = treeReader->UseBranch("Particle");
  TClonesArray *branchElectron = treeReader->UseBranch("Electron");
  TClonesArray *branchPhoton = treeReader->UseBranch("Photon");
  TClonesArray *branchMuon = treeReader->UseBranch("Muon");

  TClonesArray *branchTrack = treeReader->UseBranch("Track");
  TClonesArray *branchTower = treeReader->UseBranch("Tower");

  TClonesArray *branchEFlowTrack = treeReader->UseBranch("EFlowTrack");
  TClonesArray *branchEFlowPhoton = treeReader->UseBranch("EFlowPhoton");
  TClonesArray *branchEFlowNeutralHadron = treeReader->UseBranch("EFlowNeutralHadron");
  TClonesArray *branchJet = treeReader->UseBranch("Jet");

  Long64_t allEntries = treeReader->GetEntries();

  cout << "** Chain contains " << allEntries << " events" << endl;

  GenParticle *particle;
  Electron *electron;
  Photon *photon;
  Muon *muon;

  Track *track;
  Tower *tower;

  Jet *jet;
  TObject *object;

  TLorentzVector momentum;

  Float_t Eem, Ehad;
  Bool_t skip;

  Long64_t entry;

  Int_t i, j, pdgCode;

  // Loop over all events
  for(entry = 0; entry < allEntries; ++entry)
  {
    // Load selected branches with data from specified event
    treeReader->ReadEntry(entry);

    // Loop over all electrons in event
    for(i = 0; i < branchElectron->GetEntriesFast(); ++i)
    {
      electron = (Electron*) branchElectron->At(i);
      particle = (GenParticle*) electron->Particle.GetObject();

      plots->fElectronDeltaPT->Fill((particle->PT - electron->PT)/particle->PT);
      plots->fElectronDeltaEta->Fill((particle->Eta - electron->Eta)/particle->Eta);
    }

    // Loop over all photons in event
    for(i = 0; i < branchPhoton->GetEntriesFast(); ++i)
    {
      photon = (Photon*) branchPhoton->At(i);

      // skip photons with references to multiple particles
      if(photon->Particles.GetEntriesFast() != 1) continue;

      particle = (GenParticle*) photon->Particles.At(0);

      plots->fPhotonDeltaPT->Fill((particle->PT - photon->PT)/particle->PT);
      plots->fPhotonDeltaEta->Fill((particle->Eta - photon->Eta)/particle->Eta);
      plots->fPhotonDeltaE->Fill((particle->E - photon->E)/particle->E);
    }

    // Loop over all muons in event
    for(i = 0; i < branchMuon->GetEntriesFast(); ++i)
    {
      muon = (Muon*) branchMuon->At(i);
      particle = (GenParticle*) muon->Particle.GetObject();

      plots->fMuonDeltaPT->Fill((particle->PT - muon->PT)/particle->PT);
      plots->fMuonDeltaEta->Fill((particle->Eta - muon->Eta)/particle->Eta);
    }

    // Loop over all tracks in event
    for(i = 0; i < branchTrack->GetEntriesFast(); ++i)
    {
      track = (Track*) branchTrack->At(i);
      particle = (GenParticle*) track->Particle.GetObject();

      plots->fTrackDeltaPT->Fill((particle->PT - track->PT)/particle->PT);
      plots->fTrackDeltaEta->Fill((particle->Eta - track->Eta)/particle->Eta);
    }

    // cout << "--  New event -- " << endl;

    // Loop over all jets in event
    for(i = 0; i < branchJet->GetEntriesFast(); ++i)
    {
      jet = (Jet*) branchJet->At(i);

      momentum.SetPxPyPzE(0.0, 0.0, 0.0, 0.0);

      // cout<<"Looping over jet constituents. Jet pt: "<<jet->PT<<", eta: "<<jet->Eta<<", phi: "<<jet->Phi<<endl;

      // Loop over all jet's constituents
      for(j = 0; j < jet->Constituents.GetEntriesFast(); ++j)
      {
        object = jet->Constituents.At(j);

        // Check if the constituent is accessible
        if(object == 0) continue;

        if(object->IsA() == GenParticle::Class())
        {
          particle = (GenParticle*) object;
          // cout << "    GenPart pt: " << particle->PT << ", eta: " << particle->Eta << ", phi: " << particle->Phi << endl;
          momentum += particle->P4();
        }
        else if(object->IsA() == Track::Class())
        {
          track = (Track*) object;
          // cout << "    Track pt: " << track->PT << ", eta: " << track->Eta << ", phi: " << track->Phi << endl;
          momentum += track->P4();
        }
        else if(object->IsA() == Tower::Class())
        {
          tower = (Tower*) object;
          // cout << "    Tower pt: " << tower->ET << ", eta: " << tower->Eta << ", phi: " << tower->Phi << endl;
          momentum += tower->P4();
        }
      }
      plots->fJetDeltaPT->Fill((jet->PT - momentum.Pt())/jet->PT);
    }
  }
}
int ChargedHiggsTauNu::analyze(Event*e,string systname)
{
    #ifdef VERBOSE
        if(VERBOSE>0)Log(__FUNCTION__,"DEBUG","analyze event with syst "+systname);
    #endif
    if(doGen)analyzeGen(e,systname);

    string label = GetLabel(e);
    
    if(e->weight() == 0.) cout <<"[ChargedHiggsTauNu]::[analyze]::[INFO] Even Weight is NULL !!"<< e->weight() <<endl;

    #ifdef SYNC
        if (not e->IsRealData() and e->GetWeight() ->GetBareSF() != 1.0)  Log(__FUNCTION__,"SYNC-ERROR",Form("SF at the beginning is not 1: %lf",e->GetWeight() ->GetBareSF()));
    #endif
    
    e->ApplyTopReweight();

    #ifdef SYNC
        double toprw = e->GetWeight()->GetBareSF();
    #endif

    Fill("ChargedHiggsTauNu/CutFlow/CutFlow_"+label,systname,Total,e->weight());
    Fill("ChargedHiggsTauNu/NOne/NTaus_"+label,systname, e->Ntaus() ,e->weight());
    
    Tau *t= e->GetTau(0);


    cut.reset();
    cut.SetMask(MaxCut-1) ;
    cut.SetCut( Selection(e,true, false) );

    #ifdef SYNC
    if (SYNC>0){
        if(not e->IsRealData()) Log(__FUNCTION__,"SYNC",Form("(%d,%d,%u) MCWeight=%lf Xsec=%lf PU=%lf TopReweight=%lf",
                    e->runNum(),e->lumiNum(),e->eventNum(),
                    e->GetWeight()->GetBareMCWeight(),
                    e->GetWeight()->GetBareMCXsec(),
                    e->GetWeight()->GetBarePUWeight(),
                    toprw)
                );
        CutSelector mymask(MaxCut);
        mymask.reset();
        mymask.SetCutBit(Trigger);

        // Print info
        /*
        Log(__FUNCTION__,"SYNC",Form("(%d,%d,%u) SELECTION=%s",e->runNum(),e->lumiNum(),e->eventNum(),ChargedHiggs::printBinary(cut.raw()).c_str()));
        Log(__FUNCTION__,"SYNC","SYST="+systname);
        Log(__FUNCTION__,"SYNC",Form("Ntaus=%d",e->Ntaus()));
        Log(__FUNCTION__,"SYNC",Form("NJets=%d",e->Njets()));
        Log(__FUNCTION__,"SYNC",Form("NCJets=%d",e->NcentralJets()));
        for(int i=0;;++i)
        {
            Tau* myt= e->GetBareTau(i);
            if (myt==NULL) break;
            Log(__FUNCTION__,"SYNC", Form("* Tau-%d: Npr=%d,Npi=%d,EleRej=%d,MuRej=%d,Iso=%.3f,IdIso=%d,Pt=%.1f",
                        i, myt->GetNProng(),myt->GetNPiZero(),
                        myt->id_ele,myt->id_mu,myt->iso2,
                        myt->id_iso,myt->Pt()
                        ) ) ;
            cout <<endl;
            myt->MyIsTau();
            cout <<endl;
        }
        */
        /*
        cout <<endl;
        for(int i=0;;++i)
        {
            Jet* myj= e->GetJet(i);
            if (myj==NULL) break;
            Log(__FUNCTION__,"SYNC", Form("* Jet-%d: Pt=%.1f",
                        i, myj->Pt()
                        ) ) ;
        }
        cout <<endl;
        */
        if (cut.passMask(mymask) ) Log(__FUNCTION__,"SYNC",Form("(%d,%d,%u) Trigger",e->runNum(),e->lumiNum(),e->eventNum()) ) ; 
        mymask.SetCutBit(OneTau);
        if (cut.passMask(mymask) ) Log(__FUNCTION__,"SYNC",Form("(%d,%d,%u) Selected tau: pt=%e eta=%e",e->runNum(),e->lumiNum(),e->eventNum(),e->GetTau(0)->Pt(),e->GetTau(0)->Eta()) ) ; 
        if (cut.passMask(mymask) ) Log(__FUNCTION__,"SYNC",Form("(%d,%d,%u) Njets %d Bjets %d",e->runNum(),e->lumiNum(),e->eventNum(),e->Njets(), e->Bjets()) ) ; 
        if (cut.passMask(mymask) ) Log(__FUNCTION__,"SYNC",Form("(%d,%d,%u) TauSel metPt=%e metPhi=%e mT=%e",e->runNum(),e->lumiNum(),e->eventNum(),e->GetMet().Pt(),e->GetMet().Phi(),e->Mt()) ) ; 
    }
    #endif

    // here I have the PV and the MET Filters
    //if (e->IsRealData() ) 
        { 
            int pos=0;
            Fill("ChargedHiggsTauNu/CutFlow/CutFlow2_"+label,systname,pos,e->weight());

            CutSelector mymask(MaxCut);
            mymask.reset();

            mymask.SetCutBit(Trigger); ++pos;
            if( cut.passMask( mymask ) ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow2_"+label,systname,pos,e->weight());

            mymask.SetCutBit(OneTau);++pos;
            if( cut.passMask( mymask ) ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow2_"+label,systname,pos,e->weight());

            mymask.SetCutBit(NoLep); ++pos;
            if( cut.passMask( mymask ) ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow2_"+label,systname,pos,e->weight());

            mymask.SetCutBit(ThreeJets); ++pos;
            if( cut.passMask( mymask ) ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow2_"+label,systname,pos,e->weight());

            mymask.SetCutBit(OneBjet); ++pos;
            if( cut.passMask( mymask ) ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow2_"+label,systname,pos,e->weight());

            mymask.SetCutBit(Met); ++pos;
            if( cut.passMask( mymask ) ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow2_"+label,systname,pos,e->weight());

            mymask.SetCutBit(AngRbb); ++pos;
            if( cut.passMask( mymask ) ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow2_"+label,systname,pos,e->weight());

        }


    //Log(__FUNCTION__,"DEBUG","Analyze event with syst "+ systname + Form(" Njets=%d NB=%d PassAll=%d cuts=%s", e->Njets(),e->Bjets() ,cut.passAll(), ChargedHiggs::printBinary(cut.raw()).c_str() ));

    if ( cut.pass(NoLep) and not e->IsRealData() ){
        //Muon
        {
            GenParticle * gp  = e->GetGenMuon(0,2.4);
            if (not e->ExistSF("muIDloose")) Log(__FUNCTION__,"WARNING","No muveto SF"); //FIXME Remove this line, may be slow
            if (gp != NULL and gp->Pt() > 10) {e->SetPtEtaSF("muIDloose",gp->Pt(),fabs(gp->Eta())); e->ApplySF("muIDloose");}  // this should be SC-eta, some how propagated
        }
    }
 
    // Tau and Trigger efficiency (SAMI)
    // For non re-HLT samples --> apply directly the efficiencies in data
    // For all the oters, apply data/mc efficiencies
    string tauLegSF, metLegSF;
    tauLegSF = "tauLeg";
    metLegSF = "metLeg";  


    //#warning no sf trigger
    if (cut.pass(Trigger) and not e->IsRealData()) {
        
        if (t!=NULL){e->ApplyTauSF(t,false,"");}

        
        // Met SF only for pT > 20
        if(e->GetMet().Pt()>20 and not singleTauTrigger) {
            if( not e->ExistSF(metLegSF) ) Log(__FUNCTION__,"WARNING" ,"No Tau"+metLegSF+" SF");  
            e->SetPtEtaSF(metLegSF, e->GetMet().Pt(), 0);
            e->ApplySF(metLegSF);
        }
    } 

    //#warning nobtag-sf
    //Log(__FUNCTION__,"DEBUG",Form("syst is=%s weight before=%e",systname.c_str(),e->weight()) ) ;
    
    if (not e->IsRealData()) e->ApplyBTagSF(1);// 0=loos wp

    //Log(__FUNCTION__,"DEBUG",Form("syst is=%s weight after=%e",systname.c_str(),e->weight()) ) ;

    #warning TauMatch
    if (not e->IsRealData() ) 
        {
        if (e->GetTau(0) == NULL )  return 0;
        //if (e->GetTau(0)->Rematch(e) !=15) return 0;
        }
    

    if (e->IsRealData() or e->GetTau(0)->Rematch(e) == 15) {
        if( cut.passAllUpTo( OneTau)   ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow_"+label,systname,OneTau,e->weight());
        if( cut.passAllUpTo(NoLep)     ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow_"+label,systname,NoLep,e->weight());
        if( cut.passAllUpTo(ThreeJets) ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow_"+label,systname,ThreeJets,e->weight());
        if( cut.passAllUpTo(OneBjet)   ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow_"+label,systname,OneBjet,e->weight());
        if( cut.passAllUpTo(Met)       ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow_"+label,systname,Met,e->weight());
        if( cut.passAllUpTo(Trigger)   ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow_"+label,systname,Trigger,e->weight());

        
        if( cut.passAllUpTo(ThreeJets) && cut.pass(Trigger)) Fill("ChargedHiggsTauNu/CutFlowQCD/CutFlowQCD_"+label,systname,0,e->weight());
        if( cut.passAllUpTo(OneBjet) && cut.pass(ChargedHiggsTauNu::Trigger)) Fill("ChargedHiggsTauNu/CutFlowQCD/CutFlowQCD_"+label,systname,1,e->weight());
        if( cut.passAllUpTo(Met)) Fill("ChargedHiggsTauNu/CutFlowQCD/CutFlowQCD_"+label,systname,2,e->weight());
    }

    // fill tau1 pt base selection
    if( cut.passAllUpTo(ThreeJets) ) 
    {
            //OneTau ,
            //NoLep ,
            //ThreeJets ,
            bool singleTrigger= e->IsTriggered("HLT_VLooseIsoPFTau140_Trk50_eta2p1_v") or e->IsTriggered("HLT_VLooseIsoPFTau120_Trk50_eta2p1_v");
            bool metTrigger=e->IsTriggered("HLT_LooseIsoPFTau50_Trk30_eta2p1_MET110");
            Fill("ChargedHiggsTauNu/Base/Tau1Pt_"+label,systname, t->Pt() ,e->weight());
            if( t->GetNPiZero() == 0 )Fill("ChargedHiggsTauNu/Base/Tau1Pt_0Pi_"+label,systname, t->Pt() ,e->weight());
            if( t->GetNPiZero() == 1 )Fill("ChargedHiggsTauNu/Base/Tau1Pt_1Pi_"+label,systname, t->Pt() ,e->weight());
            if( t->GetNPiZero() == 2 )Fill("ChargedHiggsTauNu/Base/Tau1Pt_2Pi_"+label,systname, t->Pt() ,e->weight());
            if( t->GetNPiZero() == 0 and singleTrigger)Fill("ChargedHiggsTauNu/Base/Tau1Pt_0Pi_TrSingleTau_"+label,systname, t->Pt() ,e->weight());
            if( t->GetNPiZero() == 1 and singleTrigger)Fill("ChargedHiggsTauNu/Base/Tau1Pt_1Pi_TrSingleTau_"+label,systname, t->Pt() ,e->weight());
            if( t->GetNPiZero() == 0 and metTrigger)Fill("ChargedHiggsTauNu/Base/Tau1Pt_0Pi_TrMet110_"+label,systname, t->Pt() ,e->weight());
            if( t->GetNPiZero() == 1 and metTrigger)Fill("ChargedHiggsTauNu/Base/Tau1Pt_1Pi_TrMet110_"+label,systname, t->Pt() ,e->weight());
            if (metTrigger) Fill("ChargedHiggsTauNu/Base/Tau1Pt_TrMet110_"+label,systname, t->Pt() ,e->weight());
            if (singleTrigger) Fill("ChargedHiggsTauNu/Base/Tau1Pt_TrSingleTau_"+label,systname, t->Pt() ,e->weight());
            if (metTrigger and singleTrigger) Fill("ChargedHiggsTauNu/Base/Tau1Pt_TrBoth_"+label,systname, t->Pt() ,e->weight());
            if (e->GetMet().Pt() >150 and metTrigger) Fill("ChargedHiggsTauNu/Base/Tau1Pt_Met150_TrMet110_"+label,systname, t->Pt() ,e->weight());
            if (e->GetMet().Pt() >150 and metTrigger and singleTrigger) Fill("ChargedHiggsTauNu/Base/Tau1Pt_Met150_TrBoth_"+label,systname, t->Pt() ,e->weight());
    }
    

    // VARS, N-1 ,
    // 1 hadronic tau only. with Pt> 50 and eta <2.1
    // before angular variables
    // ...
   
    //cout <<"cut = "<<cut<<endl;
    //CutSelector s; s.SetCutBit(Met);
    //cout <<"met = "<<s<<endl;
    // -------------------- ANGULAR VARIABLES -----------
    double DEtaMax=0.;
    double InvMassMax=0.;
  
    
    Jet * bj1 = e->LeadBjet();
    for(int i=0;i!=e->Njets();++i)
        {
            if (bj1 == NULL ) break;
            Jet* jet = e->GetJet(i);
            if(bj1->DeltaEta(*jet)>DEtaMax) DEtaMax=bj1->DeltaEta(*jet);
            if(bj1->InvMass(*jet)>InvMassMax) InvMassMax=bj1->InvMass(*jet);
        }


    double DPhiEtMissJet1=e->DPhiEtMissJet(0); 
    double DPhiEtMissJet2=e->DPhiEtMissJet(1); 
    double DPhiEtMissJet3=e->DPhiEtMissJet(2); 
    double DPhiEtMissTau= ( t== NULL) ? -1 : fabs(e->GetMet().DeltaPhi(t));

    // up To angular variables
    double RbbMin= e->RbbMin();
    double RCollMin= e-> RCollMin();
    double RsrMax= e->RsrMax();


    double DPhiTauJet1=e->DPhiTauJet(t,0);

    // --- studies for angular variables
    if ( cut.passAllUpTo(Met) and (e->IsRealData() or e->GetTau(0)->Rematch(e) == 15 )){
        //Fill("ChargedHiggsTauNu/NOne/MaxDEtaBjetJets_"+label,systname, DEtaMax ,e->weight());
        //Fill("ChargedHiggsTauNu/NOne/MaxInvMassBjetJets_"+label,systname, InvMassMax ,e->weight());
        Fill2D("ChargedHiggsTauNu/NOne/DPhiJet1MetVsDPhiTauMet_"+label,systname,DPhiEtMissTau,DPhiEtMissJet1,e->weight());
        Fill2D("ChargedHiggsTauNu/NOne/DPhiJet2MetVsDPhiTauMet_"+label,systname,DPhiEtMissTau,DPhiEtMissJet2,e->weight());
        Fill2D("ChargedHiggsTauNu/NOne/DPhiJet3MetVsDPhiTauMet_"+label,systname,DPhiEtMissTau,DPhiEtMissJet3,e->weight());
        // ---
        //Fill("ChargedHiggsTauNu/NOne/RsrMax_"+label,systname,RsrMax,e->weight());
        //Fill2D("ChargedHiggsTauNu/NOne/RsrMaxVsMt_"+label,systname,e->Mt(),RsrMax,e->weight());
        //Fill("ChargedHiggsTauNu/NOne/DPhiTauJet1_"+label,systname,DPhiTauJet1,e->weight());
        //Fill2D("ChargedHiggsTauNu/NOne/DPhiTauJet1VsMt_"+label,systname,e->Mt(),DPhiTauJet1,e->weight());
    }


    //Angular Cuts

    // ANG VALUES FOR Regression
    if (e->IsRealData() or e->GetTau(0)->Rematch(e) == 15){
        if (cut.passAllUpTo(AngColl) ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow_"+label,systname,AngColl,e->weight());

        if(cut.passAllUpTo(AngRbb) ) Fill("ChargedHiggsTauNu/CutFlow/CutFlow_"+label,systname,AngRbb,e->weight());

        if(cut.passAllUpTo(AngRbb) ) Fill("ChargedHiggsTauNu/CutFlowQCD/CutFlowQCD_"+label,systname,3,e->weight());
        
        // ------------------- N-1 SELECTIONS
        if( cut.passAllExcept(Met) )
        {   
            //Fill2D("ChargedHiggsTauNu/NOne/EtMissVsMt_"+label,systname,e->Mt(),e->GetMet().Pt(),e->weight());
            Fill("ChargedHiggsTauNu/NOne/EtMiss_"+label,systname, e->GetMet().Pt() ,e->weight());
        }

        if (cut.passAllExcept( AngRbb) ){
            Fill("ChargedHiggsTauNu/NOne/RbbMin_"+label,systname,RbbMin,e->weight());
            //Fill2D("ChargedHiggsTauNu/NOne/RbbMinVsMt_"+label,systname,e->Mt(),RbbMin,e->weight());
        }

        if (cut.passAllExcept(AngColl) ) {
            Fill("ChargedHiggsTauNu/NOne/RCollMin_"+label,systname,RCollMin,e->weight());
            //Fill2D("ChargedHiggsTauNu/NOne/RCollMinVsMt_"+label,systname,e->Mt(),RCollMin,e->weight());
        }

        if (cut.passAllExcept(ThreeJets) ) 
        {
            Fill("ChargedHiggsTauNu/NOne/NJets_"+label,systname, e->Njets() ,e->weight());
            Jet* j1 = e->LeadJet();
            if (j1 !=NULL ) 
                {        
                    Fill("ChargedHiggsTauNu/NOne/Jet1Pt_"+label,systname, j1->Pt() ,e->weight());
                    Fill("ChargedHiggsTauNu/NOne/Jet1Eta_"+label,systname,j1->Eta() ,e->weight());
                }

            Jet* j2 = e->GetJet(1);
            if (j2 !=NULL ) 
                {        
                    //Fill("ChargedHiggsTauNu/NOne/Jet2Pt_"+label,systname, j2->Pt() ,e->weight());
                    //Fill("ChargedHiggsTauNu/NOne/Jet2Eta_"+label,systname,j2->Eta() ,e->weight());
                }

            Jet* j3 = e->GetJet(3);
            if (j3 !=NULL ) 
                {        
                    //Fill("ChargedHiggsTauNu/NOne/Jet3Pt_"+label,systname, j3->Pt() ,e->weight());
                    //Fill("ChargedHiggsTauNu/NOne/Jet3Eta_"+label,systname,j3->Eta() ,e->weight());
                }
        } // Three jets , n-1

        if( cut.passAllExcept( OneTau) )
        { 
            Fill("ChargedHiggsTauNu/NOne/Tau1Pt_"+label,systname, t->Pt() ,e->weight());
            //Fill("ChargedHiggsTauNu/NOne/Tau1Eta_"+label,systname,t->Eta(),e->weight());
        }
   

        if (cut.passAllExcept(OneBjet) )
        {
            Fill("ChargedHiggsTauNu/NOne/NBjets_"+label,systname, e->Bjets() ,e->weight());
            if( e->GetCentralJet(0)) Fill("ChargedHiggsTauNu/NOne/Bdiscr_"+label,systname, e->GetCentralJet(0)->bdiscr ,e->weight()); // of the leading jet or of the b?
            if (bj1 != NULL) 
                {        
                    Fill("ChargedHiggsTauNu/NOne/Bjet1Pt_"+label,systname, bj1->Pt() ,e->weight());
                    //Fill("ChargedHiggsTauNu/NOne/Bjet1Eta_"+label,systname,bj1->Eta(),e->weight());
                }
        }
    }

    // ------------------------ FULL SELECTION ---------------
    if (cut.passAll() ) 
    {
        e->ApplySF("tauid"); // only in MC

        //Log(__FUNCTION__,"DEBUG",Form("Syst=%s, Weight Before=%le",systname.c_str(),e->weight()));
        e->SetPtEtaSF("tauid2",e->GetTau(0)->Pt(),0.);
        e->ApplySF("tauid2"); // only in MC
        //Log(__FUNCTION__,"DEBUG",Form("Syst=%s, Weight After=%le",systname.c_str(),e->weight()));

        //if(e->IsRealData() and (systname=="NONE" or systname=="")) Log(__FUNCTION__,"SYNC",Form("%d,%d,%ld",e->runNum(),e->lumiNum(),e->eventNum()) );
        //

        if ( Unblind(e) and (e->IsRealData() or e->GetTau(0)->Rematch(e) == 15 )) 
        { 
            Fill("ChargedHiggsTauNu/Vars/Mt_"+label,systname, e->Mt() ,e->weight());
            if (e->Bjets() >1) Fill("ChargedHiggsTauNu/Vars/Mt_cat0_"+label,systname, e->Mt() ,e->weight());
            else  Fill("ChargedHiggsTauNu/Vars/Mt_cat1_"+label,systname, e->Mt() ,e->weight());
        }
        //if ( Unblind(e) ) Fill("ChargedHiggsTauNu/Vars/MtDecoQ_"+label,systname, e->MtDecoQ() ,e->weight());
        //if ( Unblind(e) ) Fill("ChargedHiggsTauNu/Vars/MtDecoCosPhi_"+label,systname, e->MtDecoCosPhi() ,e->weight());

        // -- Book(    "ChargedHiggsTauNu/Vars/Mt_matchTau_"+l,"Mt "+l + ";m_{T} [GeV]",8000,0,8000); // the Vars directory contains the full selection
        // -- Book(    "ChargedHiggsTauNu/Vars/Mt_matchEle_"+l,"Mt "+l + ";m_{T} [GeV]",8000,0,8000); // the Vars directory contains the full selection
        // -- Book(    "ChargedHiggsTauNu/Vars/Mt_matchMu_"+l,"Mt "+l + ";m_{T} [GeV]",8000,0,8000); // the Vars directory contains the full selection
        // -- Book(    "ChargedHiggsTauNu/Vars/Mt_matchJet_"+l,"Mt "+l + ";m_{T} [GeV]",8000,0,8000); // the Vars directory contains the full selection
        // -- Book(    "ChargedHiggsTauNu/Vars/Mt_matchOther_"+l,"Mt "+l + ";m_{T} [GeV]",8000,0,8000); // the Vars directory contains the full selection

        if (not e->IsRealData() )
        {
            int pdgid=e->GetTau(0)->Rematch(e);
            if (pdgid==15)Fill("ChargedHiggsTauNu/Vars/Mt_matchTau_"+label,systname, e->Mt() ,e->weight());
            else if (pdgid==11)Fill("ChargedHiggsTauNu/Vars/Mt_matchEle_"+label,systname, e->Mt() ,e->weight());
            else if (pdgid==13)Fill("ChargedHiggsTauNu/Vars/Mt_matchMu_"+label,systname, e->Mt() ,e->weight());
            else if (pdgid==21 or pdgid==1 )Fill("ChargedHiggsTauNu/Vars/Mt_matchJet_"+label,systname, e->Mt() ,e->weight());
            else Fill("ChargedHiggsTauNu/Vars/Mt_matchOther_"+label,systname, e->Mt() ,e->weight());
        }

        //Fill("ChargedHiggsTauNu/Vars/Jet1QGL_"+label,systname,e->GetJet(0)->QGL() , e->weight() );
        //Fill("ChargedHiggsTauNu/Vars/Jet2QGL_"+label,systname,e->GetJet(1)->QGL() , e->weight() );
        if (e->IsRealData() or e->GetTau(0)->Rematch(e) == 15) Fill("ChargedHiggsTauNu/Vars/JetInvMass_"+label,systname,e->GetJet(0)->InvMass(e->GetJet(1)) , e->weight() );
        //Fill("ChargedHiggsTauNu/Vars/Jet13InvMass_"+label,systname,e->GetJet(0)->InvMass(e->GetJet(2)) , e->weight() );
        //Fill("ChargedHiggsTauNu/Vars/Jet23InvMass_"+label,systname,e->GetJet(1)->InvMass(e->GetJet(2)) , e->weight() );

        return EVENT_USED;
    }
    else { return EVENT_NOT_USED; }
}
void ChargedHiggsTauNu::analyzeGen(Event*e, string systname)
{
    // no systematics shifts for this
    if (systname !="" and systname != "NONE") return;

    string label = GetLabel(e);

    Weight* w = e->GetWeight();
    // make sure we don't book sf or corrections here
    double mcWeight=w->GetBareMCWeight() * w->GetBarePUWeight()* w->GetBareMCXsec() * w->GetBareLumi() / w->GetBareNevents();
    Fill("ChargedHiggsTauNu/Gen/CutFlow_"+label,systname,0,mcWeight);

    // find the H+
    int iHpm=-1;
    int iTau=-1;
    int iLFromTau=-1; // find leptonic taus
    int iIsoL = -1; // is there an isolated lepton ?
    for(unsigned i = 0 ; ;++i)
    {
        GenParticle *g = e->GetGenParticle(i);
        if (g==NULL) break; //exit condition

        int apdg = abs(g->GetPdgId());
        if (iHpm <0  and apdg == 37 ) { iHpm = i; }
        if (iTau <0 and apdg == 15 ) { iTau = i; }
        if (iLFromTau <0 and (apdg == 11 or apdg == 13) and e->GenParticleDecayedFrom(i,15) ) { iLFromTau = i; }
        if (iIsoL <0  and (apdg == 11 or apdg == 13) and g->IsPromptFinalState() and g->Pt() >10 and abs(g->Eta())<2.4){
            float iso = 0.0;
            for(unsigned j = 0 ; ;++j)
            {
                if (i == j ) continue; // no double counting;
                GenParticle *g2 = e->GetGenParticle(j);
                if (g2 == NULL) break;
                if (not g2->IsPromptFinalState()) continue;
                if (g2->IsDressed() ) continue; // no dressed leptons
                if (g2->DeltaR(g) >0.1)  continue;
                iso += g2->Pt();
            }
            if (iso<10) iIsoL = i;
        }

    }

    bool lepVeto=false;
    if (e->Nleps() ==0 ) lepVeto=true;
    else if( e->GetMuon(0) == NULL){ // no 10 GeV muon
        
        if (e->GetElectron(0) !=NULL and e->GetElectron(0)->Pt() <15) lepVeto=true; // pt ordered
    }

    vector<Lepton*> miniIsoLeptons;
    bool lepVetoMiniIso=true;
    for(unsigned il=0 ; ;++il)
    {
        Lepton *l = e->GetBareLepton(il);
        if (l == NULL) break;  // exit strategy
        
        // selection
        if (l->Pt() <10 ) continue;
        //l->SetIsoRelCut(0.25);
        if (abs(l->Eta()) >2.4) continue;
        //medium id
        if( not l->GetMediumId() ) continue;

        //MINI-ISO
        if( l->MiniIsolation() >0.4 ) continue;//loose

        // for muons require tracker and global
        if (l->IsMuonDirty() and not l->GetTrackerMuon())  continue;
        if (l->IsMuonDirty() and not l->GetGlobalMuon())  continue;

        // selected leptons
        miniIsoLeptons.push_back(l);
        lepVetoMiniIso=false;
    }
    // sort miniIsoLeptons by pt
    std::sort(miniIsoLeptons.begin(),miniIsoLeptons.end(),[](Lepton const *a, Lepton const *b ){return a->Pt() > b->Pt();});


    if (iHpm >=0 ) Fill("ChargedHiggsTauNu/Gen/CutFlow_"+label,systname,1,mcWeight);
    if (iHpm >=0 and iTau>=0 ) Fill("ChargedHiggsTauNu/Gen/CutFlow_"+label,systname,2,mcWeight);
    if (iHpm >=0 and iTau>=0 and iLFromTau<0){

        Fill("ChargedHiggsTauNu/Gen/CutFlow_"+label,systname,3,mcWeight);
        if (iIsoL <0) Fill("ChargedHiggsTauNu/Gen/CutFlow_"+label,systname,4,mcWeight);
        if (lepVeto) Fill("ChargedHiggsTauNu/Gen/CutFlow_"+label,systname,5,mcWeight);
        if (lepVetoMiniIso ) Fill("ChargedHiggsTauNu/Gen/CutFlow_"+label,systname,6,mcWeight);
    }

}
Beispiel #9
0
int DYAnalysis::analyzeMM(Event *e, string systname)
{
    string label = GetLabel(e);
    cut.reset();
    cut.SetMask(MaxCut-1) ;
    cut.SetCutBit( Total ) ;

    Lepton*mu0 = e->GetMuon(0);
    Lepton*mu1 = e->GetMuon(1);
    Jet *j0 = e->GetJet(0);
    Jet *j1 = e->GetJet(1);

    // Truth
    GenParticle *genmu0=NULL; GenParticle *genmu1=NULL;

    for( int iGen=0 ; /*empty*/ ; ++iGen)
    {
        GenParticle *g = e->GetGenParticle(iGen); 
        if (g==NULL ) break;  // end loop statement
        if (not g->IsDressed()) continue;
        if (not abs(g->GetPdgId())==13) continue;
        
        if (genmu0== NULL) genmu0=g;
        else if (genmu1==NULL) {genmu1=g; break;}
    }

    bool genMuons = genmu0!=NULL and genmu1 !=NULL;

    bool isGen=false;
    bool isReco=false;
    if (genMuons) // no requirement on pT
    {
        Object Ztruth(*genmu0); 
        Ztruth += *genmu1;
        if (Ztruth.M() > 60 and Ztruth.M()<120) isGen=true;
    }

    bool recoMuons= mu0 != NULL and mu1 !=NULL; 
    //if (not recoMuons) return 0;

    if (mu0!=NULL and mu0->Pt() > 25 and fabs(mu0->Eta())< 2.4) 
    {
        if (e->IsTriggered("HLT_IsoMu20") ) {
            Fill("DYAnalysis/Vars/MuonIso_"+ label,systname, mu0->Isolation(),e->weight()) ;
        }
    }

    if (recoMuons and mu1->Pt() >20)
    { // ------------------- 20 -------------------
        Object Z(*mu0);
        Z += *mu1;
        if (Z.M()> 60 && Z.M()<120){
            Fill("DYAnalysis/Vars/Pt20mm_"+ label,systname, Z.Pt(),e->weight()) ;
        }
    
    }

    // ---------------------- 25 -------------------
    if ( recoMuons and mu1->Pt() >25)
    {
        cut.SetCutBit(Leptons);
        if (e->IsTriggered("HLT_IsoMu20") ) cut.SetCutBit(Trigger);

        Object Z(*mu0);
        Z += *mu1;
       	if (cut.passAllUpTo(Trigger) ){
            Fill("DYAnalysis/Vars/Mmm_"+ label,systname, Z.M(),e->weight()) ;
        }

        if (Z.M()> 60 && Z.M()<120) cut.SetCutBit(Mass);

       	if (cut.passAll() ){
            Fill("DYAnalysis/Vars/Ptmm_"+ label,systname, Z.Pt(),e->weight()) ;
            Fill("DYAnalysis/Vars/EtaMu1_"+ label,systname, mu0->Eta(),e->weight()) ;
       	    Fill("DYAnalysis/Vars/Npvmm_"+ label,systname, e->Npv(),e->weight()) ;
            Fill("DYAnalysis/Vars/NJmm_"+ label,systname, e->NcentralJets(),e->weight()) ;
            Fill("DYAnalysis/Vars/PtmmUW_"+ label,systname, Z.Pt(),1.0) ;
            isReco=true;
        }

        if ( Z.Pt() > 500) // NoSingleMuon Trigger -> ISO
        {
            Fill( "DYAnalysis/Vars/MHighPtmm_" + label,systname,Z.M() ,e->weight() ) ;
            if( j1 != NULL ) Fill( "DYAnalysis/Vars/MJHighPtmm_" + label,systname, j1->InvMass(j0) ,e->weight() ) ;
        }

        if(mu0->DeltaR(mu1) <.8) {
	        Fill ("DYAnalysis/Vars/MCloseMt_"+ label , systname, ChargedHiggs::mt(Z.GetP4(), e->GetMet().GetP4()) , e->weight());
	        if (j0!=NULL)Fill ("DYAnalysis/Vars/MCloseJZ_"+ label,systname,j0->InvMass(&Z)  , e->weight());
        }
    }

    if (isReco and isGen) Fill("DYAnalysis/Vars/Accmm_"+label,systname, 0);
    else if ( isGen ) Fill("DYAnalysis/Vars/Accmm_"+label,systname, 1);
    else if ( isReco ) Fill("DYAnalysis/Vars/Accmm_"+label,systname, 2); 
    return 0;
}
Beispiel #10
0
int DYAnalysis::analyzeEE(Event *e, string systname)
{
    string label = GetLabel(e);
    cut.reset();
    cut.SetMask(MaxCut-1) ;
    cut.SetCutBit( Total ) ;

    if (e->weight() == 0.) Log(__FUNCTION__,"WARNING","Event Weight is NULL");

    Lepton*e0 = e->GetElectron(0);
    Lepton*e1 = e->GetElectron(1);
    Jet *j0 = e->GetJet(0);
    Jet *j1 = e->GetJet(1);

    bool recoEles = e0 !=NULL and e1 !=NULL;
    //if (e0 == NULL or e1 == NULL) return 0;

    GenParticle *genele0=NULL; GenParticle *genele1=NULL;

    for( int iGen=0 ; /*empty*/ ; ++iGen)
    {
        GenParticle *g = e->GetGenParticle(iGen); 
        if (g==NULL ) break;  // end loop statement
        if (not g->IsDressed()) continue;
        if (not abs(g->GetPdgId())==11) continue;
        
        if (genele0== NULL) genele0=g;
        else if (genele1==NULL) {genele1=g; break;}
    }

    bool genEles = genele0!=NULL and genele1 !=NULL;

    bool isGen=false;
    bool isReco=false;
    if (genEles) // no requirement on pT
    {
        Object Ztruth(*genele0); 
        Ztruth += *genele1;
        if (Ztruth.M() > 60 and Ztruth.M()<120) isGen=true;
    }

    if ( recoEles and e1->Pt() >25)
    {
        cut.SetCutBit(Leptons);
        //if (e->IsTriggered("HLT_Ele27_eta2p1_WPLoose_Gsf") ) cut.SetCutBit(Trigger);
        cut.SetCutBit(Trigger);
        Object Z(*e0);
        Z += *e1;
       	if (cut.passAllUpTo(Trigger))Fill("DYAnalysis/Vars/Mee_"+ label,systname ,Z.M(),e->weight()) ;

        if (Z.M()> 60 && Z.M()<120) cut.SetCutBit(Mass);

        if (cut.passAll()){
       	    Fill("DYAnalysis/Vars/Ptee_"+ label,systname, Z.Pt(),e->weight()) ;
            Fill("DYAnalysis/Vars/NJee_"+ label,systname, e->NcentralJets(),e->weight()) ;
       	    Fill("DYAnalysis/Vars/Npvee_"+ label,systname, e->Npv(),e->weight()) ;
            isReco=true;
        }

        if ( Z.Pt() > 500)
        {
            Fill( "DYAnalysis/Vars/MHighPtee_" + label,systname,Z.M() ,e->weight() ) ;
            if( j1 != NULL ) Fill( "DYAnalysis/Vars/MJHighPtee_" + label,systname, j1->InvMass(j0) ,e->weight() ) ;
        }
    }

    if (isReco and isGen) Fill("DYAnalysis/Vars/Accee_"+label,systname, 0);
    else if ( isGen ) Fill("DYAnalysis/Vars/Accee_"+label,systname, 1);
    else if ( isReco ) Fill("DYAnalysis/Vars/Accee_"+label,systname, 2); 

    return 0;
}