Beispiel #1
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 #2
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];
}
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);
    }

}