Example #1
0
UnitQuaternion&
	UnitQuaternion::LnDif(
		const UnitQuaternion& p, 
		const UnitQuaternion& q
	)
{
	UnitQuaternion r;
	r.Divide(q,p);
	return(LogN(r));
}
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;
}
Example #3
0
int QGAnalysis::analyzeJJ(Event *e, string systname)
{
    if ( e->IsRealData() and e->GetName().find("ZeroBias") == string::npos )  return 0; // avoid data double counting


    string label = GetLabel(e);
    cut.reset();
    cut.SetMask(DiJetMaxCut-1) ;
    cut.SetCutBit( DiJetTotal ) ;
    Fill("QGAnalysis/CutFlow/CutFlowDiJet_"+label,systname,DiJetTotal,e->weight());

    Jet *j0 = e->GetJet(0);
    Jet *j1 = e->GetJet(1);
    Jet *j2 = e->GetJet(2);


    if ( j0 == NULL or j1 == NULL) return 0;
    if ( j2 == NULL  or 2.*j2->Pt()/( j1->Pt() + j0->Pt() ) ) cut.SetCutBit(DiJetTwoJets) ;

    if (cut.passAllUpTo(DiJetTwoJets) ){
        Fill("QGAnalysis/CutFlow/CutFlowDiJet_" + label,systname,DiJetTwoJets, e->weight() ) ;
    }

    if ( j0->DeltaPhi(*j1) > 2.5 ) cut.SetCutBit(DiJetDeltaPhi);

    if( cut.passAllUpTo(DiJetTwoJets) ) Fill("QGAnalysis/CutFlow/CutFlowDiJet_"+label,systname,DiJetDeltaPhi,e->weight());

    if (cut.passAll() ){
        Fill("QGAnalysis/CutFlow/CutFlowDiJet_"+label,systname,DiJetMaxCut,e->weight());
        Fill("QGAnalysis/DiJet/Npv_"+ label,systname, e->Npv(),e->weight()) ;
        string etaStrJ0=Binning::findBinStr( aetaBins, fabs(j0->Eta()), "eta%.1f_%.1f");
        string etaStrJ1=Binning::findBinStr( aetaBins, fabs(j1->Eta()), "eta%.1f_%.1f");
        LogN(__FUNCTION__,"WARNING","Not T&P diJet",10);
        string ptStrJ0=Binning::findBinStr( ptBins, j0->Pt(), "pt%.0f_%.0f"); 
        string ptStrJ1=Binning::findBinStr( ptBins, j1->Pt(), "pt%.0f_%.0f"); 
        int flavorJ0 = abs(j0->Flavor());

        string typeJ0="U";
        if (flavorJ0 == 21) typeJ0="G";
        else if (flavorJ0 < 6 and flavorJ0 != 0) typeJ0="Q"; 

        int flavorJ1 = abs(j1->Flavor());
        string typeJ1="U";
        if (flavorJ1 == 21) typeJ1="G";
        else if (flavorJ1 < 6 and flavorJ1 != 0) typeJ1="Q"; 
           
        // global 
        Fill("QGAnalysis/DiJet/QGL_" +typeJ0 +"_"+ label, systname, j0->QGL(),e->weight()) ;
        Fill("QGAnalysis/DiJet/QGL_" +typeJ1 +"_"+ label, systname, j1->QGL(),e->weight()) ;
         
        Fill("QGAnalysis/DiJet/mult_" +typeJ0 +"_"+ label, systname, j0->QGLVar("mult"),e->weight()) ;
        Fill("QGAnalysis/DiJet/ptD_" +typeJ0 +"_"+ label, systname, j0->QGLVar("ptD"),e->weight()) ;
        Fill("QGAnalysis/DiJet/axis2_" +typeJ0 +"_"+ label, systname, j0->QGLVar("axis2"),e->weight()) ;

        Fill("QGAnalysis/DiJet/mult_" +typeJ1 +"_"+ label, systname, j1->QGLVar("mult"),e->weight()) ;
        Fill("QGAnalysis/DiJet/ptD_" +typeJ1 +"_"+ label, systname, j1->QGLVar("ptD"),e->weight()) ;
        Fill("QGAnalysis/DiJet/axis2_" +typeJ1 +"_"+ label, systname, j1->QGLVar("axis2"),e->weight()) ;
        // binned
        
        // pt1 <-> pt0: TP
        if (etaStrJ0 != "NotFound" and ptStrJ1 != "NotFound")
        {
            Fill("QGAnalysis/DiJet/QGL_"  +typeJ0 +"_" + ptStrJ1 + "_" + etaStrJ0+"_"+ label, systname, j0->QGL(),e->weight()) ;
            Fill("QGAnalysis/DiJet/mult_" +typeJ0 +"_" + ptStrJ1 + "_" + etaStrJ0+"_"+ label, systname, j0->QGLVar("mult"),e->weight()) ;
            Fill("QGAnalysis/DiJet/ptD_"  +typeJ0 +"_" + ptStrJ1 + "_" + etaStrJ0+"_"+ label, systname, j0->QGLVar("ptD"),e->weight()) ;
            Fill("QGAnalysis/DiJet/axis2_"+typeJ0 +"_" + ptStrJ1 + "_" + etaStrJ0+"_"+ label, systname, -TMath::Log(j0->QGLVar("axis2")),e->weight()) ;
        }

        if (etaStrJ1 != "NotFound" and ptStrJ0 != "NotFound")
        {
            Fill("QGAnalysis/DiJet/QGL_"  +typeJ1 +"_" + ptStrJ0 + "_" + etaStrJ1+"_"+ label, systname, j1->QGL(),e->weight()) ;
            Fill("QGAnalysis/DiJet/mult_" +typeJ1 +"_" + ptStrJ0 + "_" + etaStrJ1+"_"+ label, systname, j1->QGLVar("mult"),e->weight()) ;
            Fill("QGAnalysis/DiJet/ptD_"  +typeJ1 +"_" + ptStrJ0 + "_" + etaStrJ1+"_"+ label, systname, j1->QGLVar("ptD"),e->weight()) ;
            Fill("QGAnalysis/DiJet/axis2_"+typeJ1 +"_" + ptStrJ0 + "_" + etaStrJ1+"_"+ label, systname, -TMath::Log(j1->QGLVar("axis2")),e->weight()) ;
        }

    }

    return 0;
}