int ChargedHiggsQCDPurity::analyze(Event*e,string systname)
{
    #ifdef VERBOSE
    if (VERBOSE >0 ) cout<<"[ChargedHiggsQCDPurity]::[analyze]::[DEBUG1] start analyze event"<<endl;
    #endif
    string label = GetLabel(e);
    // do not distinguish between data and mc, 
    // so we can run closures
    // Fill Real Iso 
    Tau *t = e->GetTau(0);
    // Fill Inverted Iso
    Tau *tInv = e->GetTauInvIso(0);

    e->ApplyTopReweight();

    e->ApplyWReweight();

    #ifdef VERBOSE
    if (VERBOSE >0 ) cout<<"[ChargedHiggsQCDPurity]::[analyze]::[DEBUG1] is Tau? "<< (t==NULL) <<endl;
    if (VERBOSE >0 ) cout<<"[ChargedHiggsQCDPurity]::[analyze]::[DEBUG1] is TauInv? "<< (tInv == NULL)<<endl;
    #endif

    // --- take the selection from the tau nu analysis
    CutSelector direct; 
        direct.SetMask(ChargedHiggsTauNu::MaxCut-1);
        direct.SetCut(ChargedHiggsTauNu::Selection(e,true,false,is80X,isLightMass));
    CutSelector inverse;
        inverse.SetMask(ChargedHiggsTauNu::MaxCut-1);
        inverse.SetCut(ChargedHiggsTauNu::Selection(e,false,false,is80X,isLightMass));

    // TODO:
    // * what do I do with event with a Tau and an Inv tau? -> DY ? 
    // * put a limit on the TauInv sideband ? 3.0 -20 GeV

    bool passDirectLoose=direct.passAllUpTo(ChargedHiggsTauNu::ThreeJets);
   bool passInverseLoose=inverse.passAllUpTo(ChargedHiggsTauNu::ThreeJets);

    
  // bool passDirectLoose=direct.passAllUpTo(ChargedHiggsTauNu::OneBjet);
  // bool passInverseLoose=inverse.passAllUpTo(ChargedHiggsTauNu::OneBjet);
    //#warning QCD BJets
    //LogN(__FUNCTION__,"WARNING","ONE B REQUIRED FOR QCD LOOSE",10);
    
    
    // check minimal selection: Three bjets
    if ( not passDirectLoose
         and not  passInverseLoose
       ) return EVENT_NOT_USED;
   
   
    bool passPrescale=false;
    if(e->GetWeight()->GetMC().find("ST") != string::npos || e->GetWeight()->GetMC().find("WZ") != string::npos || e->GetWeight()->GetMC().find("WW") != string::npos || e->GetWeight()->GetMC().find("ZZ") != string::npos) {
        
        passPrescale=true; // set trigger, but apply SF!
 
        // Met SF only for pT > 20 (only for MC)
        string metLegSF = "metLegData";
        if(not e->ExistSF(metLegSF)) Log(__FUNCTION__,"WARING" ,"No Tau metLeg SF");
        else if(e->GetMet().Pt()>20 and not e->IsRealData()) {
            e->SetPtEtaSF(metLegSF, e->GetMet().Pt(), 0);
            e->ApplySF(metLegSF);
        }
    }
    else {
        

        // Apply MET leg SF (only on MC)
        // NEGLECT IT
        /*
        string metLegSF = "metLeg";
        if(not e->ExistSF(metLegSF)) Log(__FUNCTION__,"WARING" ,"No Tau metLeg SF");
        else if(e->GetMet().Pt()>20 and not e->IsRealData()) {
            e->SetPtEtaSF(metLegSF, e->GetMet().Pt(), 0);
            e->ApplySF(metLegSF);
        }
        */
        if(e->IsTriggered("HLT_LooseIsoPFTau50_Trk30_eta2p1_MET90")) passPrescale=true;   
    }
   

    //  USE PRESCALE PATH ONLY FOR THE "inclusive/Loose" selection
    //bool passPrescale=false;
    //if (not e->IsRealData()) passPrescale=true;
    //if (  e->IsTriggered("HLT_LooseIsoPFTau50_Trk30_eta2p1_v") ) passPrescale=true;
    //#warning MET80 TRigger in QCD
    //if (  e->IsTriggered("HLT_LooseIsoPFTau50_Trk30_eta2p1_MET90") ) passPrescale=true;
    //LogN(__FUNCTION__,"WARNING","MET 80 in QCD Loose",10);
    //
    //bool passMatchDirect=true;
    //bool passMatchInverse=true;
    
    #warning Tau Match
    bool passMatchDirect=false;
    bool passMatchInverse=false;
    if (e->IsRealData()) { passMatchDirect=true; passMatchInverse=true;}
    else {  
        if (e->GetTau(0) !=NULL and e->GetTau(0)->Rematch(e)==15) passMatchDirect=true;
        if (e->GetTauInvIso(0) !=NULL and e->GetTauInvIso(0)->Rematch(e)==15) passMatchInverse=true;
    }

    /*
    if (not e->IsRealData() )
    {
        if (passDirectLoose)
        {
            e->SetPtEtaSF("antiE",e->GetTau(0)->Pt(),e->GetTau(0)->Eta() );
            e->ApplySF("antiE");
        }
        else if (passInverseLoose) // don't apply them twice
        {
            e->SetPtEtaSF("antiE",e->GetTauInvIso(0)->Pt(),e->GetTauInvIso(0)->Eta() );
            e->ApplySF("antiE");
        }
    }
    */

    //--------------

    if (t != NULL and passMatchDirect and passDirectLoose and passPrescale) // direct
    {
        float pt = t->Pt();
        int flavor= t->Rematch(e);

        if (pt  > 8000 or pt <0 )  Log(__FUNCTION__,"INFO",Form("strange event : tau Pt=%.0f",pt));

        string hist = HistName(pt,true, false);
        Fill( dir + hist +"_"+label,systname, e->GetMet().Pt(), e->weight() );
        hist = HistName(pt,true, false,"Uperp");
        Fill( dir+hist +"_"+label,systname, Upar(e,t), e->weight() );
        hist = HistName(pt,true, false,"Upar");
        Fill( dir+hist +"_"+label,systname, Uperp(e,t), e->weight() );
        hist = HistName(pt, true, false, "TauPt") ;
        Fill( dir+hist +"_"+label,systname, t->Pt(), e->weight() );

        /*
        hist = HistName(pt, true, false) ;
        if (flavor == 15) hist += "_T";
        else if (flavor == 21 ) hist+="_G";
        else if (flavor <5 and flavor != 0 ) hist+="_Q";
        else hist += "_U";
        Fill( dir + hist +"_"+label,systname, e->GetMet().Pt(), e->weight() );
         */

        hist = HistName(pt, true, false) ;
        if (t->GetNProng()==1) hist +="_1p";
        else hist+="_3p";
        Fill( dir + hist +"_"+label,systname, e->GetMet().Pt(), e->weight() );

        { // CONTROL PLOTS -- LOOSE SELECTION
            string hist= "TauPt_Control";
            Fill( dir+hist +"_"+label,systname, t->Pt(), e->weight() );
            hist= "EtMiss_Control";
            Fill( dir+hist +"_"+label,systname, e->GetMet().Pt(), e->weight() );
        }

    }

    if (tInv != NULL and passMatchInverse and passInverseLoose and passPrescale) // inv iso
    {
        float pt = tInv->Pt();
        int flavor= tInv->Rematch(e);
        if (pt  > 8000 or pt <0 )  Log(__FUNCTION__,"INFO",Form("strange event : tau Pt=%.0f",pt));
        string hist = HistName(pt,false,false);
        Fill( dir+hist +"_"+label,systname, e->GetMet().Pt(), e->weight() );
        hist = HistName(pt,false, false,"Uperp");
        Fill( dir+hist +"_"+label,systname, Upar(e,tInv), e->weight() );
        hist = HistName(pt,false, false,"Upar");
        Fill( dir+hist +"_"+label,systname, Uperp(e,tInv), e->weight() );
        hist = HistName(pt, false, false, "TauPt") ;
        Fill( dir+hist +"_"+label,systname, tInv->Pt(), e->weight() );

        /*
        hist = HistName(pt, false, false) ;
        if (flavor == 15) hist += "_T";
        else if (flavor == 21 ) hist+="_G";
        else if (flavor <5 and flavor != 0 ) hist+="_Q";
        else hist += "_U";
        Fill( dir + hist +"_"+label,systname, e->GetMet().Pt(), e->weight() );
         */
        hist = HistName(pt, false, false) ;
        if (tInv->GetNProng()==1) hist+="_1p";
        else hist+="_3p";
        Fill( dir + hist +"_"+label,systname, e->GetMet().Pt(), e->weight() );
    }

    // not in the LOOSE --- BTAG SF, only MC
    //#warning no-btag-sf
    if (not e->IsRealData()) e->ApplyBTagSF(0);// 0=loos wp
    // -------------------------- FULL SELECTION -----------------------------------------------
    //
    if (t!=NULL and passMatchDirect and not e->IsRealData()) 
    {
        e->ApplyTauSF(t, false); 
    }
    
    // N minus one direct
    if (t!=NULL and passMatchDirect and direct.passAllExcept(ChargedHiggsTauNu::Met) ) 
        {
            Fill( none + "EtMiss" +"_"+label,systname, e->GetMet().Pt(), e->weight() );
        }

    if (t!=NULL and passMatchDirect and direct.passAllExcept(ChargedHiggsTauNu::AngRbb) ) 
        {
            Fill( none + "RbbMin" +"_"+label,systname, e->RbbMin(), e->weight() );
        }

    if (t!=NULL and passMatchDirect and direct.passAllExcept(ChargedHiggsTauNu::AngColl) ) 
        {
            Fill( none + "RCollMin" +"_"+label,systname, e->RCollMin(), e->weight() );
        }
    
    if (t!=NULL and passMatchDirect and direct.passAllExcept(ChargedHiggsTauNu::OneTau) ) 
        {
            Fill( none + "Tau1Pt" +"_"+label,systname, t->Pt(), e->weight() );
        }

    if (t!=NULL and passMatchDirect and direct.passAll() ) 
    {
            //if ( not e->IsRealData()) e->ApplySF("btag");
            #ifdef VERBOSE
            if (VERBOSE >0 ) Log(__FUNCTION__,"DEBUG", "is tau pass full selection");
            #endif
            //if(e->IsRealData() and (systname=="NONE" or systname=="") ) Log(__FUNCTION__,"SYNC",Form("%d,%d,%ld",e->runNum(),e->lumiNum(),e->eventNum()) );
            float pt = t->Pt();
            int flavor= t->Rematch(e);
            string hist = HistName(pt,true,true);  
            Fill(dir+hist+"_"+label,systname, e->GetMet().Pt() ,e->weight());

            hist= "Mt"; //UNBLIND --------
            if ( Unblind(e) ) Fill(dir+hist+"_"+label,systname, e->Mt() ,e->weight());

            hist = HistName(pt,true, true,"Uperp");
            Fill( dir+hist +"_"+label,systname, Upar(e,t), e->weight() );
            hist = HistName(pt,true, true,"Upar");
            Fill( dir+hist +"_"+label,systname, Uperp(e,t), e->weight() );

            hist = HistName(pt, true,true) ;
            if (flavor == 15) hist += "_T";
            else if (flavor == 21 ) hist+="_G";
            else if (flavor <5 and flavor != 0 ) hist+="_Q";
            else hist += "_U";
            Fill( dir + hist +"_"+label,systname, e->GetMet().Pt(), e->weight() );

            hist = HistName(pt, true,true) ;
            if (t->GetNProng()==1) hist+="_1p";
            else hist+="_3p";
            Fill( dir + hist +"_"+label,systname, e->GetMet().Pt(), e->weight() );
    }

    // ---------------------- INF TAU SF 
    //
    if (tInv != NULL and passMatchInverse and passInverseLoose ){ // USE weight(false) to apply TF on data!
        float pt = tInv->Pt();                                                   
        //const string sf="tauinviso";
        string sfname="tauinvisospline";
        //if (tInv->GetNProng() ==1 ) sfname+="_1p";
        //else sfname+="_3p";
        // if the SF don't exist go on, but don't fill inconsistent events
        if( not e->ExistSF(sfname) ){
            LogN(__FUNCTION__,"WARNING","Tau inviso SF does not exist",10);
            return EVENT_NOT_USED;
        }
        e->SetPtEtaSF(sfname,tInv->Pt(),tInv->Eta());
        e->ApplySF(sfname); // only in weight(false) sf are applied in data

        if(inverse.passAllUpTo(ChargedHiggsTauNu::ThreeJets) && inverse.pass(ChargedHiggsTauNu::Trigger)) Fill("ChargedHiggsTauNu/CutFlowQCD/CutFlowQCD_"+label,systname,0,e->weight(false));
        if(inverse.passAllUpTo(ChargedHiggsTauNu::OneBjet) && inverse.pass(ChargedHiggsTauNu::Trigger)) Fill("ChargedHiggsTauNu/CutFlowQCD/CutFlowQCD_"+label,systname,1,e->weight(false));
        if(inverse.passAllUpTo(ChargedHiggsTauNu::Met)) Fill("ChargedHiggsTauNu/CutFlowQCD/CutFlowQCD_"+label,systname,2,e->weight(false));
        if(inverse.passAllUpTo(ChargedHiggsTauNu::AngRbb)) Fill("ChargedHiggsTauNu/CutFlowQCD/CutFlowQCD_"+label,systname,3,e->weight(false));
     
        
        
        //Log(__FUNCTION__,"DEBUG",string("syst name is ") + systname + Form("weight is %f",e->weight(false)) );
        if (tInv != NULL and passInverseLoose and passPrescale){ // CONTROL PLOTS -- LOOSE SELECTION
            string hist= "TauPt_IsoInv_Control";
            Fill( dir+hist +"_"+label,systname, tInv->Pt(), e->weight(false) );
            hist= "EtMiss_IsoInv_Control";
            Fill( dir+hist +"_"+label,systname, e->GetMet().Pt(), e->weight(false) );
        }

        if (inverse.passAllExcept(ChargedHiggsTauNu::Met))
        {
            //if (not e->IsTriggered("HLT_LooseIsoPFTau50_Trk30_eta2p1_MET120") ) Log(__FUNCTION__,"ERROR","Event Is NOT Triggered!!! Why am I here?");
            //Log(__FUNCTION__,"DEBUG",Form("N-1 MET Selection InvIso w=%.4f",e->weight(false)));
            Fill( none + "EtMissIsoInv" +"_"+label,systname, e->GetMet().Pt(), e->weight(false) );

        }

        if (inverse.passAllExcept(ChargedHiggsTauNu::AngRbb) ) 
            {
                Fill( none + "RbbMinIsoInv" +"_"+label,systname, e->RbbMin(3,tInv), e->weight(false) );
            }

        if (inverse.passAllExcept(ChargedHiggsTauNu::AngColl) ) 
            {
                Fill( none + "RCollMinIsoInv" +"_"+label,systname, e->RCollMin(3,tInv), e->weight(false) );
            }
        
        
        if (inverse.passAllExcept(ChargedHiggsTauNu::OneBjet) ) 
        {
            Fill( none + "NBjetsIsoInv" +"_"+label,systname, e->Bjets(), e->weight(false) );
        }
        
        // TauPtIsoInv
        if (inverse.passAllExcept(ChargedHiggsTauNu::OneTau) ) 
        {
            Fill( none + "Tau1PtIsoInv" +"_"+label,systname, pt, e->weight(false) );
        }        

        // remove trigger & met
        /*
        unsigned mymask =  0 ;
        for(unsigned i=0;i<ChargedHiggsTauNu::MaxCut;++i){
            if (i==ChargedHiggsTauNu::Trigger) continue;
            if (i==ChargedHiggsTauNu::Met) continue;
            mymask |= (1<<i); // set all 1
        }

        if (passPrescale and passInverseLoose and inverse.passMask(mymask) )
        {
            // On data avoid R fact -- n minus one
            string hist=HistName(pt, false, true)+"_NoR";
            Fill(dir+hist+"_"+label,systname, e->GetMet().Pt() ,e->weight(true));
        }
         */

        if (inverse.passAll()) { // FULL SELECTION
            //if ( not e->IsRealData()) e->ApplySF("btag");
            #ifdef VERBOSE
            if (VERBOSE >0 ) Log(__FUNCTION__,"DEBUG","is tauInv full selection");
            #endif


            if (e->weight(false) == 0 )Log(__FUNCTION__,"WARNING","event weight after SF is 0 ");

            int flavor= tInv->Rematch(e);
            string hist = HistName(pt,false,true);                                   
            Fill(dir+hist+"_"+label,systname, e->GetMet().Pt() ,e->weight(false));


            //hist = HistName(pt,false,true,"Mt");  
            hist = "MtIsoInv";
            Fill(dir+hist+"_"+label,systname, e->Mt(Event::MtTauInv) ,e->weight(false));
            hist = HistName(pt,false, true,"Uperp");
            Fill( dir+hist +"_"+label,systname, Upar(e,tInv), e->weight(false) );
            hist = HistName(pt,false, true,"Upar");
            Fill( dir+hist +"_"+label,systname, Uperp(e,tInv), e->weight(false) );

            /*
            hist = HistName(pt, false, true) ;
            if (flavor == 15) hist += "_T";
            else if (flavor == 21 ) hist+="_G";
            else if (flavor <5 and flavor != 0 ) hist+="_Q";
            else hist += "_U";
            Fill( dir + hist +"_"+label,systname, e->GetMet().Pt(), e->weight(false) );
            */
            hist = HistName(pt, false, true) ;
            if (tInv->GetNProng() ==1 ) hist+="_1p";
            else hist+="_3p";
            Fill( dir + hist +"_"+label,systname, e->GetMet().Pt(), e->weight(false) );
             
        } // inverse.passAll
    } // tInv


    return EVENT_NOT_USED;
}
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; }
}