Пример #1
0
HS_BOOL8
    CHSSysCloak::GetAttributeValue(const HS_INT8 * pcAttrName,
                                   CHSVariant & rvarValue,
                                   HS_BOOL8 bAdjusted, HS_BOOL8 bLocalOnly)
{
    // Determine attribute, and return the value.
    if (!_stricmp(pcAttrName, "EFFICIENCY"))
    {
        if (m_efficiency)
        {
            rvarValue = *m_efficiency;
        }
        else if (!bLocalOnly)
        {
            rvarValue = GetEfficiency(bAdjusted);
        }
        else
        {
            return false;
        }
        return true;
    }
    else if (!_stricmp(pcAttrName, "ENGAGED"))
    {
        rvarValue = m_engaged;
        return true;
    }
    else
    {
        // See if the base class knows about this attr.
        return CHSEngSystem::GetAttributeValue(pcAttrName, rvarValue,
                                               bAdjusted, bLocalOnly);
    }
}
Пример #2
0
HS_BOOL8 CHSJumpDrive::GetAttributeValue(const HS_INT8 * pcAttrName,
                                         CHSVariant & rvarValue,
                                         HS_BOOL8 bAdjusted,
                                         HS_BOOL8 bLocalOnly)
{
    // Determine attribute, and return the value.
    if (!strcasecmp(pcAttrName, "ENGAGED"))
    {
        rvarValue = m_bEngaged;
        return true;
    }
    else if (!strcasecmp(pcAttrName, "JUMPSPEED MULTIPLIER"))
    {
        rvarValue = m_iJumpSpeedMultiplier;
        return true;
    }
    else if (!strcasecmp(pcAttrName, "EFFICIENCY"))
    {
        if (m_puiEfficiency)
        {
            rvarValue = *m_puiEfficiency;
        }
        else if (!bLocalOnly)
        {
            rvarValue = GetEfficiency();
        }
        else
        {
            return false;
        }
        return true;
    }
    else if (!strcasecmp(pcAttrName, "MIN SPEED"))
    {
        if (m_puiMinJumpSpeed)
        {
            rvarValue = *m_puiMinJumpSpeed;
        }
        else if (!bLocalOnly)
        {
            rvarValue = GetMinJumpSpeed();
        }
        else
        {
            return false;
        }
        return true;
    }
    else if (!strcasecmp(pcAttrName, "CHARGE"))
    {
        rvarValue = m_fChargeLevel;
        return true;
    }
    else
    {
        return CHSEngSystem::GetAttributeValue(pcAttrName, rvarValue,
                                               bAdjusted, bLocalOnly);
    }
}
Пример #3
0
// Tells the engines that they need to gobble up some fuel
// from the fuel source.  The engines know their efficiency
// and such, so they just drain the fuel from the fuel system.
// Speed here should be given in units per hour.
void CHSSysEngines::ConsumeFuelBySpeed(HS_INT32 speed)
{
    float fConsume;
    float fRealized;

    // Do we have a fuel system?
    if (!GetFuelSource() ||
        (GetFuelSource()->GetFuelRemaining() <= 0))
    {
        return;
    }

    // If efficiency is 0, do not consume fuel
    if (0 == GetEfficiency())
    {
        return;
    }

    // Calculate per second travel rate
    fConsume = (float) (speed * .0002778);

    // Divide by efficiency
    fConsume = (float) (fConsume / (1000.0 * GetEfficiency()));

    // Engines consume burnable fuel
    fRealized = GetFuelSource()->ExtractFuelUnit(fConsume);

    // check system consumed the ammount we asked for
    if (fRealized < fConsume)
    {
        // Out of gas.  Set desired speed to 0.
        m_desired_speed = 0;
        HS_INT8 tbuf[128];
        sprintf_s(tbuf,
                "%s%s-%s A warning light flashing, indicating engines have run \
			out of fuel.",
                ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL);
        if (GetOwnerObject())
        {
            GetOwnerObject()->HandleMessage(tbuf, MSG_ENGINEERING, NULL);
        }
    }
}
Пример #4
0
// Tells the engines that they need to gobble up some fuel
// from the fuel source.  The engines know their efficiency
// and such, so they just drain the fuel from the fuel system.
// Speed here should be given in units per hour.
void CHSJumpDrive::ConsumeFuelBySpeed(HS_INT32 speed)
{
    float fConsume;
    float fRealized;

    // Do we have a fuel system?
    if (!GetFuelSource() || (GetFuelSource()->GetFuelRemaining() <= 0))
    {
        return;
    }

    // Do not consume fuel if efficiency is 0
    if (0 == GetEfficiency())
    {
        return;
    }

    // Calculate per second travel rate
    fConsume = (float) (speed * .0002778);

    // Divide by efficiency
    fConsume = (float) (fConsume / (1000.0 * GetEfficiency()));

    fRealized = GetFuelSource()->ExtractFuelUnit(fConsume);
    if (fRealized < fConsume)
    {
        // Out of gas.  Disengage.
        m_bEngaged = false;
        HS_INT8 tbuf[128];
        sprintf(tbuf,
                "%s%s-%s A warning light flashing, indicating jump drives have \
			run out of fuel.",
                ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL);

        if (GetOwnerObject())
        {
            GetOwnerObject()->HandleMessage(tbuf, MSG_ENGINEERING, NULL);
        }
    }
}
Пример #5
0
/****************************************************************************
* INPUT(S)             : Measurements.
* OUTPUT(S)            : Loss of efficiency compared to the reference model.
* DESIGN DOC.          :
* FUNCTION DESCRIPTION : Return the loss of efficiency between the actual
*                        operating conditions and the the efficiency
*                        calculated based on the reference model.
****************************************************************************/
float PumpEvaluation::EfficiencyEvaluation(float deltaP, float T, float w, float q, AFC_PUMP_STATE_TYPE pumpState, float pitArea)
{
  float eff_reduction, eff_model;

  if ( ((0.0f != mPressureParameters[0]) ||
    (0.0f != mPressureParameters[1]) ||
    (0.0f != mPressureParameters[2]) ||
    (0.0f != mPressureParameters[3]) ||
    (0.0f != mPowerParameters[0]) ||
    (0.0f != mPowerParameters[1]) ||
    (0.0f != mPowerParameters[2]) ||
    (0.0f != mPowerParameters[3])) && (pumpState == AFC_PUMP_RUNNING) )
  {
    eff_model = GetModelEfficiency(w, q, pitArea);

    if (eff_model > 0.0f)
    {
      eff_reduction = GetEfficiency(deltaP, T, w, q) / eff_model;
      //eff_reduction = GetEfficiency2(w, q, pitArea) / eff_model;
    }
    else
    {
      eff_reduction = 0.0f;
    }
    if (eff_reduction > 1.0f)
    {
      eff_reduction = 1.0f;
    }
    if (eff_reduction < 0.0f)
    {
      eff_reduction = 0.0f;
    }
  }
  else
  {
    eff_reduction = 0.0f;
  }
  return eff_reduction;
}
Пример #6
0
void CASW_Parasite::NPCThink()
{
	BaseClass::NPCThink();

	if ( GetEfficiency() < AIE_DORMANT && GetSleepState() == AISS_AWAKE 
		&& !m_bDefanged && gpGlobals->curtime > s_fNextSpottedChatterTime && GetEnemy())
	{
		CASW_Marine *pMarine = UTIL_ASW_Marine_Can_Chatter_Spot(this);
		if (pMarine)
		{
			pMarine->GetMarineSpeech()->Chatter(CHATTER_PARASITE);
			s_fNextSpottedChatterTime = gpGlobals->curtime + 30.0f;
		}
		else
			s_fNextSpottedChatterTime = gpGlobals->curtime + 1.0f;
	}
	if (m_bDefanged && m_fSuicideTime < gpGlobals->curtime && GetEnemy() == NULL)
	{
		// suicide!		
		CTakeDamageInfo info(NULL, NULL, Vector(0,0,0), GetAbsOrigin(), GetHealth() * 2,
				DMG_ACID);
		TakeDamage(info);
	}
}
Пример #7
0
//==============================================
void MCTnPTriggerEff::Loop(Int_t effSample, Char_t *trigLabel)
{
  if (fChain == 0) return;

  Long64_t nentries = fChain->GetEntries();
  Long64_t nb = 0;
  Long64_t countRecEvent = 0;
  printf("number of entries = %d\n", (Int_t) nentries);

  Bool_t incrementTrig;
  Double_t epsL1L2Trig_Pos, epsL3Trig_Pos, epsL1L2Trig_Neg, epsL3Trig_Neg;
  Double_t eps1TMandHLT_Pos, eps1TMandHLT_Neg;
  Double_t eps2TMandHLT_Pos, eps2TMandHLT_Neg;
  Double_t epsTMandHLT_Pos, epsTMandHLT_Neg;
  Double_t trigEff = 0.;

  //loop over the events
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
  // for (Long64_t jentry=0; jentry<500;jentry++) {

    if(jentry % 100000 == 0) printf("event %d\n", (Int_t) jentry);
    //printf("event %d\n", (Int_t) jentry);

    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);

    //check that this is a RECO event
    if(onia->Pt() > 990.)
      continue;

    Double_t etaMuPos = muPos->PseudoRapidity();
    Double_t etaMuNeg = muNeg->PseudoRapidity();
    Double_t pTMuPos = muPos->Pt();
    Double_t pTMuNeg = muNeg->Pt();
    Double_t pMuPos = muPos->P();
    Double_t pMuNeg = muNeg->P();
    Double_t phiMuPos = muPos->Phi();
    Double_t phiMuNeg = muNeg->Phi();

    //take muons only within a certain eta range
    if((fabs(etaMuPos) < eff::etaPS[0] && pTMuPos < eff::pTMuMin[0]) || //mid-rapidity cut
       (fabs(etaMuPos) > eff::etaPS[0] && fabs(etaMuPos) < eff::etaPS[1] && pMuPos < eff::pMuMin[1]) ||
       (fabs(etaMuPos) > eff::etaPS[1] && fabs(etaMuPos) < eff::etaPS[2] && pTMuPos < eff::pTMuMin[2]))
      continue;
    //(b) on the negative muon
    if((fabs(etaMuNeg) < eff::etaPS[0] && pTMuNeg < eff::pTMuMin[0]) || //mid-rapidity cut
       (fabs(etaMuNeg) > eff::etaPS[0] && fabs(etaMuNeg) < eff::etaPS[1] && pMuNeg < eff::pMuMin[1]) ||
       (fabs(etaMuNeg) > eff::etaPS[1] && fabs(etaMuNeg) < eff::etaPS[2] && pTMuNeg < eff::pTMuMin[2]))
      continue;

    if(fabs(onia->Rapidity()) > eff::rapMax)
      continue;
    if(JpsiVprob > 0.01) 
      continue;

    Double_t onia_mass = onia->M();
    Double_t onia_pt = onia->Pt();
    Double_t onia_P = onia->P();
    Double_t onia_eta = onia->PseudoRapidity();
    Double_t onia_rap = onia->Rapidity();
    Double_t onia_phi = onia->Phi();
    Double_t onia_mT = sqrt(onia_mass*onia_mass + onia_pt*onia_pt);
    
    Int_t rapIndex = -1;
    for(int iRap = 0; iRap < 2*eff::kNbRapBins; iRap++){
      if(onia_rap > eff::rapRange[iRap] && onia_rap < eff::rapRange[iRap+1]){
	rapIndex = iRap;
	break;
      }
    }
    Int_t rapForPTIndex = -1;
    for(int iRap = 0; iRap < eff::kNbRapForPTBins; iRap++){
      if(TMath::Abs(onia_rap) > eff::rapForPTRange[iRap] && 
	 TMath::Abs(onia_rap) < eff::rapForPTRange[iRap+1]){
	rapForPTIndex = iRap+1;
	break;
      }
    }
    Int_t pTIndex = -1;
    for(int iPT = 0; iPT < eff::kNbPTBins[rapForPTIndex]; iPT++){
      if(onia_pt > eff::pTRange[rapForPTIndex][iPT] && onia_pt < eff::pTRange[rapForPTIndex][iPT+1]){
	pTIndex = iPT+1;
	break;
      }
    }
    Int_t rapIntegratedPTIndex = -1;
    for(int iPT = 0; iPT < eff::kNbPTBins[0]; iPT++){
      if(onia_pt > eff::pTRange[0][iPT] && onia_pt < eff::pTRange[0][iPT+1]){
	rapIntegratedPTIndex = iPT+1;
	break;
      }
    }
    if(rapIndex < 0){
      // printf("rapIndex %d, rap(onia) = %f\n", rapIndex, onia_rap);
      continue;
    }
    if(rapForPTIndex < 1){
      // printf("rapForPTIndex %d, rap(onia) = %f\n", rapForPTIndex, onia_rap);
      continue;
    }
    if(pTIndex < 1){
      // printf("pTIndex %d, pT(onia) = %f\n", pTIndex, onia_pt);
      continue;
    }

    //==============================
    calcPol(*muPos, *muNeg);
    //==============================

    Bool_t usePTFit = kTRUE; //alternative to the T&P histograms use fitted pT differential efficiency

    // ---> For the asymmetric triggers:
    // 0 : event not firing the corresponding trigger
    // 1 : event firing the corresponding trigger, 2 RECO muons matched to 2 HLT objects, POSITIVE-charge muon matched to the tighter HLT object (usually a L3 muon)
    // -1 : event firing the corresponding trigger, 2 RECO muons matched to 2 HLT objects, NEGATIVE-charge muon matched to the tighter HLT object (usually a L3 muon)
    // 2 : event firing the corresponding trigger, 2 RECO muons matched to 2 HLT objects, both matched to the tighter HLT object (usually a L3 muon)
    // 3 : event firing the corresponding trigger but at least one RECO muon is not matched to the HLT objects 

    if(strncmp("HLT_DoubleMu0", trigLabel, 13) == 0){//DoubleMu0 trigger
      if(usePTFit){
	epsL1L2Trig_Pos = GetEfficiency_FromParametrization(L1L2Eff, effSample, etaMuPos, pTMuPos);
	epsL3Trig_Pos   = GetEfficiency_FromParametrization(L3Eff, effSample, etaMuPos, pTMuPos);
	epsL1L2Trig_Neg = GetEfficiency_FromParametrization(L1L2Eff, effSample, etaMuNeg, pTMuNeg);
	epsL3Trig_Neg   = GetEfficiency_FromParametrization(L3Eff, effSample, etaMuNeg, pTMuNeg);
      }
      else{
	epsL1L2Trig_Pos = GetEfficiency(L1L2Eff, effSample, etaMuPos, pTMuPos);
	epsL3Trig_Pos   = GetEfficiency(L3Eff, effSample, etaMuPos, pTMuPos);
	epsL1L2Trig_Neg = GetEfficiency(L1L2Eff, effSample, etaMuNeg, pTMuNeg);
	epsL3Trig_Neg   = GetEfficiency(L3Eff, effSample, etaMuNeg, pTMuNeg);
      }
      trigEff = epsL1L2Trig_Pos * epsL3Trig_Pos * epsL1L2Trig_Neg * epsL3Trig_Neg;
    }
    else if(strncmp("HLT_Mu0_TkMu0_OST_Jpsi", trigLabel, 22) == 0){//any of the "low pT J/psi triggers" --> steering via the input filename

      eps1TMandHLT_Pos = GetEfficiency(TMandHLT1Eff, effSample, etaMuPos, pTMuPos);
      eps1TMandHLT_Neg = GetEfficiency(TMandHLT1Eff, effSample, etaMuNeg, pTMuNeg);

      if(usePTFit){
	epsL1L2Trig_Pos  = GetEfficiency_FromParametrization(L1L2Eff, effSample, etaMuPos, pTMuPos);
	epsL3Trig_Pos    = GetEfficiency_FromParametrization(L3Eff, effSample, etaMuPos, pTMuPos);
	epsL1L2Trig_Neg  = GetEfficiency_FromParametrization(L1L2Eff, effSample, etaMuNeg, pTMuNeg);
	epsL3Trig_Neg    = GetEfficiency_FromParametrization(L3Eff, effSample, etaMuNeg, pTMuNeg);

	eps2TMandHLT_Pos = GetEfficiency_FromParametrization(TMandHLT2Eff, effSample, etaMuPos, pTMuPos);
	eps2TMandHLT_Neg = GetEfficiency_FromParametrization(TMandHLT2Eff, effSample, etaMuNeg, pTMuNeg);
      }
      else{
	epsL1L2Trig_Pos  = GetEfficiency(L1L2Eff, effSample, etaMuPos, pTMuPos);
	epsL3Trig_Pos    = GetEfficiency(L3Eff, effSample, etaMuPos, pTMuPos);
	epsL1L2Trig_Neg  = GetEfficiency(L1L2Eff, effSample, etaMuNeg, pTMuNeg);
	epsL3Trig_Neg    = GetEfficiency(L3Eff, effSample, etaMuNeg, pTMuNeg);

	eps2TMandHLT_Pos = GetEfficiency(TMandHLT2Eff, effSample, etaMuPos, pTMuPos);
	eps2TMandHLT_Neg = GetEfficiency(TMandHLT2Eff, effSample, etaMuNeg, pTMuNeg);
      }

      epsTMandHLT_Pos = eps1TMandHLT_Pos * eps2TMandHLT_Pos;
      epsTMandHLT_Neg = eps1TMandHLT_Neg * eps2TMandHLT_Neg;


      Double_t epsTM1_Neg  = GetEfficiency(Trk_TkMu0, effSample, etaMuNeg, pTMuNeg);
      Double_t epsTM2_Neg  = GetEfficiency(Mu_TkMu0, effSample, etaMuNeg, pTMuNeg);
      
      Double_t epsHLT_Pos = epsL1L2Trig_Pos * epsL3Trig_Pos;
      Double_t epsHLT_Neg = epsL1L2Trig_Neg * epsL3Trig_Neg;
      Double_t epsTM_Neg = epsTM1_Neg *epsTM2_Neg;
      
      Double_t epsTM1_Pos = GetEfficiency(Trk_TkMu0, effSample, etaMuPos, pTMuPos);
      Double_t epsTM2_Pos = GetEfficiency(Mu_TkMu0, effSample, etaMuPos, pTMuPos);
      Double_t epsTM_Pos = epsTM1_Pos *epsTM2_Pos;

      trigEff = epsHLT_Pos * (epsTM_Neg - epsTMandHLT_Neg) + TMath::Max(0., (epsHLT_Pos - epsTMandHLT_Pos)) * epsTMandHLT_Neg; //last version
      //unconditioned (pos.) HLT muon and exclusive (neg.) TM + exclusive (pos.) HLT and incluseve (neg.) HLT 
      trigEff += epsHLT_Neg * (epsTM_Pos - epsTMandHLT_Pos) + TMath::Max(0., (epsHLT_Neg - epsTMandHLT_Neg)) * epsTMandHLT_Pos; //last version
      //mirror image of the above (exchanging the charge)
      trigEff += epsTMandHLT_Pos * epsTMandHLT_Neg; 
      //combination of 2 inclusve HLT and TM 

      // if((epsTM_Neg - epsTMandHLT_Neg) < 0.)//this component is always okay
      // 	printf("negative value for (epsTM_Neg - epsTMandHLT_Neg) = %1.3f - %1.3f = %f\n", epsTM_Neg, epsTMandHLT_Neg, epsTM_Neg - epsTMandHLT_Neg);
      // if((epsHLT_Pos - epsTMandHLT_Pos) < 0.)
      // 	printf("negative value for (epsHLT_Pos - epsTMandHLT_Pos) = %1.3f - %1.3f = %f\n", epsHLT_Pos, epsTMandHLT_Pos, epsHLT_Pos - epsTMandHLT_Pos);
      // if((epsTM_Pos - epsTMandHLT_Pos) < 0.)//this component is always okay
      // 	printf("negative value for (epsTM_Pos - epsTMandHLT_Pos) = %1.3f - %1.3f = %f\n", epsTM_Pos, epsTMandHLT_Pos, epsTM_Pos - epsTMandHLT_Pos);
      // if((epsHLT_Neg - epsTMandHLT_Neg) < 0.)
      // 	printf("negative value for (epsHLT_Neg - epsTMandHLT_Neg): %1.3f - %1.3f = %f\n", epsHLT_Neg, epsTMandHLT_Neg, epsHLT_Neg - epsTMandHLT_Neg);


    	if(trigEff < 0.)
    	  trigEff = 0.;
    	else if(trigEff > 1.)
    	  trigEff = 1.;
    }//end of low pT J/psi trigger efficiency

    //the indiv. histograms will be filled depending on the
    //assigned probability
    Double_t randNb = gRandom->Uniform();

    if(trigEff > randNb)
      incrementTrig = kTRUE;
    else
      incrementTrig = kFALSE;

    // hGen_pT->Fill(onia_pt);
    // hGen_y->Fill(onia_rap);
    // hGen_phi->Fill(onia_phi);
    // hGen2D_pT_rapNP->Fill(onia_rap, onia_pt);
    // hGen2D_pT_rap->Fill(fabs(onia_rap), onia_pt);

    // if(incrementTrig){
    //   trigEff_pT->Fill(onia_pt);
    //   trigEff_y->Fill(onia_rap);
    //   trigEff_phi->Fill(onia_phi);
    //   trigEff2D_pT_rapNP->Fill(onia_rap, onia_pt);
    //   trigEff2D_pT_rap->Fill(fabs(onia_rap), onia_pt);
    // 	//      }
    //   }
    // }
    // if(incrementTot){
    //   totEff_pT->Fill(onia_pt);
    //   totEff_y->Fill(onia_rap);
    //   totEff_phi->Fill(onia_phi);
    //   totEff2D_pT_rapNP->Fill(onia_rap, onia_pt);
    //   totEff2D_pT_rap->Fill(fabs(onia_rap), onia_pt);
    // }

    trigEff_pT->Fill(incrementTrig, onia_pt);
    trigEff_y->Fill(incrementTrig, onia_rap);
    trigEff_phi->Fill(incrementTrig, onia_phi);
      
    trigEff2D_pT_rap->Fill(incrementTrig, fabs(onia_rap), onia_pt);
    trigEff2D_pT_rapNP->Fill(incrementTrig, onia_rap, onia_pt);

    //fill the eff. histos for all the different frames
    for(int iFrame = 0; iFrame < eff::kNbFrames; iFrame++){

      //histos for neg. and pos. rapidity separately:
      if(rapIndex >= 0)
	trigEff2D_pol_pT_rapNP[iFrame][0][rapIndex]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
      if(pTIndex > 0 && rapIndex >= 0)
	trigEff2D_pol_pT_rapNP[iFrame][pTIndex][rapIndex]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
	
      //histos taking together +y and -y
      trigEff2D_pol_pT_rap[iFrame][0][0]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
      trigEff2D_pol_pT_rap[iFrame][rapIntegratedPTIndex][0]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
      if(rapForPTIndex > 0)
	trigEff2D_pol_pT_rap[iFrame][0][rapForPTIndex]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
      if(pTIndex > 0 && rapForPTIndex > 0)
	trigEff2D_pol_pT_rap[iFrame][pTIndex][rapForPTIndex]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
	  
      //histos taking together +y and -y and phi 4-folding
      Double_t phiFolded = thisPhi[iFrame];
      Double_t thetaAdjusted = thisCosTh[iFrame];
      if(thisPhi[iFrame] > -90. && thisPhi[iFrame] < 0.)
    	phiFolded *= -1;
      else if(thisPhi[iFrame] > 90 && thisPhi[iFrame] < 180){
    	phiFolded = 180. - thisPhi[iFrame];
    	thetaAdjusted *= -1;
      }
      else if(thisPhi[iFrame] > -180. && thisPhi[iFrame] < -90.){
    	phiFolded = 180. + thisPhi[iFrame];
    	thetaAdjusted *= -1;
      }

      trigEff2D_pol_pT_rap_phiFolded[iFrame][0][0]->Fill(incrementTrig, thetaAdjusted, phiFolded);
      if(rapIntegratedPTIndex > 0)
	trigEff2D_pol_pT_rap_phiFolded[iFrame][rapIntegratedPTIndex][0]->Fill(incrementTrig, thetaAdjusted, phiFolded);
      if(rapForPTIndex > 0)
	trigEff2D_pol_pT_rap_phiFolded[iFrame][0][rapForPTIndex]->Fill(incrementTrig, thetaAdjusted, phiFolded);
      if(pTIndex > 0 && rapForPTIndex > 0)
	trigEff2D_pol_pT_rap_phiFolded[iFrame][pTIndex][rapForPTIndex]->Fill(incrementTrig, thetaAdjusted, phiFolded);
    }

    // //fill the series of correlation histos for lab-frame
    // Double_t deltaEta = fabs(etaMuPos - etaMuNeg);
    // Double_t deltaPhi = phiMuPos - phiMuNeg;
    // if(deltaPhi < -TMath::Pi()) deltaPhi += 2.*TMath::Pi();
    // else if(deltaPhi > TMath::Pi()) deltaPhi -= 2.*TMath::Pi();
    // Double_t deltaPhiDeg = deltaPhi * 180./TMath::Pi();
    // Double_t deltaR = sqrt(pow(deltaEta,2) + pow(deltaPhi,2));

    // //convert the deltaPhi variable from the TTree from rad to deg:
    // Double_t JpsiDetaM2 = sqrt(pow(JpsiDrM2,2) - pow(JpsiDphiM2,2));
    // JpsiDphiM2 *= 180./TMath::Pi();


    // hGen_deltaR_pT_rap[0][0]->Fill(deltaR);
    // hGen_deltaRM2_pT_rap[0][0]->Fill(JpsiDrM2);
    // hGen_deltaPhiM2_pT_rap[0][0]->Fill(JpsiDphiM2);
    // hGen_deltaEtaM2_pT_rap[0][0]->Fill(JpsiDetaM2);
    // hGen_distM2_pT_rap[0][0]->Fill(JpsiDistM2);
    // if(incrementReco){
    //   recoEff_deltaR_pT_rap[0][0]->Fill(deltaR);
    //   recoEff_deltaRM2_pT_rap[0][0]->Fill(JpsiDrM2);
    //   recoEff_deltaPhiM2_pT_rap[0][0]->Fill(JpsiDphiM2);
    //   recoEff_deltaEtaM2_pT_rap[0][0]->Fill(JpsiDetaM2);
    //   recoEff_distM2_pT_rap[0][0]->Fill(JpsiDistM2);
    //   //    }
    //   if(incrementTrig){
    // 	trigEff_deltaR_pT_rap[0][0]->Fill(deltaR);
    // 	trigEff_deltaRM2_pT_rap[0][0]->Fill(JpsiDrM2);
    // 	trigEff_deltaPhiM2_pT_rap[0][0]->Fill(JpsiDphiM2);
    // 	trigEff_deltaEtaM2_pT_rap[0][0]->Fill(JpsiDetaM2);
    // 	trigEff_distM2_pT_rap[0][0]->Fill(JpsiDistM2);
    //   }
    // }
    // if(incrementTot){
    //   totEff_deltaR_pT_rap[0][0]->Fill(deltaR);
    //   totEff_deltaRM2_pT_rap[0][0]->Fill(JpsiDrM2);
    //   totEff_deltaPhiM2_pT_rap[0][0]->Fill(JpsiDphiM2);
    //   totEff_deltaEtaM2_pT_rap[0][0]->Fill(JpsiDetaM2);
    //   totEff_distM2_pT_rap[0][0]->Fill(JpsiDistM2);
    // }
    // hGen2D_deltaPhiVsDeltaEta_pT_rap[0][0]->Fill(deltaEta, deltaPhiDeg);
    // if(incrementReco){
    //   recoEff2D_deltaPhiVsDeltaEta_pT_rap[0][0]->Fill(deltaEta, deltaPhiDeg);
    //   if(incrementTrig)
    // 	trigEff2D_deltaPhiVsDeltaEta_pT_rap[0][0]->Fill(deltaEta, deltaPhiDeg);
    // }
    // if(incrementTot)
    //   totEff2D_deltaPhiVsDeltaEta_pT_rap[0][0]->Fill(deltaEta, deltaPhiDeg);

    // if(rapIntegratedPTIndex > 0){
    //   hGen_deltaR_pT_rap[rapIntegratedPTIndex][0]->Fill(deltaR);
    //   hGen_deltaRM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDrM2);
    //   hGen_deltaPhiM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDphiM2);
    //   hGen_deltaEtaM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDetaM2);
    //   hGen_distM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDistM2);
    //   if(incrementReco){
    // 	recoEff_deltaR_pT_rap[rapIntegratedPTIndex][0]->Fill(deltaR);
    // 	recoEff_deltaRM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDrM2);
    // 	recoEff_deltaPhiM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDphiM2);
    // 	recoEff_deltaEtaM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDetaM2);
    // 	recoEff_distM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDistM2);
    //   // }
    // 	if(incrementTrig){
    // 	  trigEff_deltaR_pT_rap[rapIntegratedPTIndex][0]->Fill(deltaR);
    // 	  trigEff_deltaRM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDrM2);
    // 	  trigEff_deltaPhiM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDphiM2);
    // 	  trigEff_deltaEtaM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDetaM2);
    // 	  trigEff_distM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDistM2);
    // 	}
    //   }
    //   if(incrementTot){
    // 	totEff_deltaR_pT_rap[rapIntegratedPTIndex][0]->Fill(deltaR);
    // 	totEff_deltaRM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDrM2);
    // 	totEff_deltaPhiM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDphiM2);
    // 	totEff_deltaEtaM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDetaM2);
    // 	totEff_distM2_pT_rap[rapIntegratedPTIndex][0]->Fill(JpsiDistM2);
    //   }

    //   hGen2D_deltaPhiVsDeltaEta_pT_rap[rapIntegratedPTIndex][0]->Fill(deltaEta, deltaPhiDeg);
    //   if(incrementReco){
    // 	recoEff2D_deltaPhiVsDeltaEta_pT_rap[rapIntegratedPTIndex][0]->Fill(deltaEta, deltaPhiDeg);
    // 	if(incrementTrig)
    // 	  trigEff2D_deltaPhiVsDeltaEta_pT_rap[rapIntegratedPTIndex][0]->Fill(deltaEta, deltaPhiDeg);
    //   }
    //   if(incrementTot)
    // 	totEff2D_deltaPhiVsDeltaEta_pT_rap[rapIntegratedPTIndex][0]->Fill(deltaEta, deltaPhiDeg);
    // }
    // if(rapForPTIndex > 0){
    //   hGen_deltaR_pT_rap[0][rapForPTIndex]->Fill(deltaR);
    //   hGen_deltaRM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDrM2);
    //   hGen_deltaPhiM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDphiM2);
    //   hGen_deltaEtaM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDetaM2);
    //   hGen_distM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDistM2);
    //   if(incrementReco){
    // 	recoEff_deltaR_pT_rap[0][rapForPTIndex]->Fill(deltaR);
    // 	recoEff_deltaRM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDrM2);
    // 	recoEff_deltaPhiM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDphiM2);
    // 	recoEff_deltaEtaM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDetaM2);
    // 	recoEff_distM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDistM2);
    //   // }
    // 	if(incrementTrig){
    // 	  trigEff_deltaR_pT_rap[0][rapForPTIndex]->Fill(deltaR);
    // 	  trigEff_deltaRM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDrM2);
    // 	  trigEff_deltaPhiM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDphiM2);
    // 	  trigEff_deltaEtaM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDetaM2);
    // 	  trigEff_distM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDistM2);
    // 	}
    //   }
    //   if(incrementTot){
    // 	totEff_deltaR_pT_rap[0][rapForPTIndex]->Fill(deltaR);
    // 	totEff_deltaRM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDrM2);
    // 	totEff_deltaPhiM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDphiM2);
    // 	totEff_deltaEtaM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDetaM2);
    // 	totEff_distM2_pT_rap[0][rapForPTIndex]->Fill(JpsiDistM2);
    //   }

    //   hGen2D_deltaPhiVsDeltaEta_pT_rap[0][rapForPTIndex]->Fill(deltaEta, deltaPhiDeg);
    //   if(incrementReco){
    // 	recoEff2D_deltaPhiVsDeltaEta_pT_rap[0][rapForPTIndex]->Fill(deltaEta, deltaPhiDeg);
    // 	if(incrementTrig)
    // 	  trigEff2D_deltaPhiVsDeltaEta_pT_rap[0][rapForPTIndex]->Fill(deltaEta, deltaPhiDeg);
    //   }
    //   if(incrementTot)
    // 	totEff2D_deltaPhiVsDeltaEta_pT_rap[0][rapForPTIndex]->Fill(deltaEta, deltaPhiDeg);
    // }
    // if(pTIndex > 0 && rapForPTIndex > 0){
    //   hGen_deltaR_pT_rap[pTIndex][rapForPTIndex]->Fill(deltaR);
    //   hGen_deltaRM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDrM2);
    //   hGen_deltaPhiM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDphiM2);
    //   hGen_deltaEtaM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDetaM2);
    //   hGen_distM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDistM2);
    //   if(incrementReco){
    // 	recoEff_deltaR_pT_rap[pTIndex][rapForPTIndex]->Fill(deltaR);
    // 	recoEff_deltaRM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDrM2);
    // 	recoEff_deltaPhiM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDphiM2);
    // 	recoEff_deltaEtaM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDetaM2);
    // 	recoEff_distM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDistM2);
    // 	//}
    // 	if(incrementTrig){
    // 	  trigEff_deltaR_pT_rap[pTIndex][rapForPTIndex]->Fill(deltaR);
    // 	  trigEff_deltaRM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDrM2);
    // 	  trigEff_deltaPhiM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDphiM2);
    // 	  trigEff_deltaEtaM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDetaM2);
    // 	  trigEff_distM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDistM2);
    // 	}
    //   }
    //   if(incrementTot){
    // 	totEff_deltaR_pT_rap[pTIndex][rapForPTIndex]->Fill(deltaR);
    // 	totEff_deltaRM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDrM2);
    // 	totEff_deltaPhiM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDphiM2);
    // 	totEff_deltaEtaM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDetaM2);
    // 	totEff_distM2_pT_rap[pTIndex][rapForPTIndex]->Fill(JpsiDistM2);
    //   }

    //   hGen2D_deltaPhiVsDeltaEta_pT_rap[pTIndex][rapForPTIndex]->Fill(deltaEta, deltaPhiDeg);
    //   if(incrementReco){
    // 	recoEff2D_deltaPhiVsDeltaEta_pT_rap[pTIndex][rapForPTIndex]->Fill(deltaEta, deltaPhiDeg);
    // 	if(incrementTrig)
    // 	  trigEff2D_deltaPhiVsDeltaEta_pT_rap[pTIndex][rapForPTIndex]->Fill(deltaEta, deltaPhiDeg);
    //   }
    //   if(incrementTot)
    // 	totEff2D_deltaPhiVsDeltaEta_pT_rap[pTIndex][rapForPTIndex]->Fill(deltaEta, deltaPhiDeg);
    // }

  }//loop over entries

  printf("nb. of rec. events is %d of a total of %d events\n", (Int_t) countRecEvent, (Int_t) nentries);
}
Пример #8
0
HS_BOOL8 CHSSysEngines::GetAttributeValue(const HS_INT8 * pcAttrName,
        CHSVariant & rvarValue, HS_BOOL8 bAdjusted, HS_BOOL8 bLocalOnly)
{
    // Determine attribute, and return the value.
    if (!_stricmp(pcAttrName, "EFFICIENCY"))
    {
        if (m_puiEfficiency)
        {
            rvarValue = *m_puiEfficiency;
        }
        else if (!bLocalOnly)
        {
            rvarValue = GetEfficiency();
        }
        else
        {
            return false;
        }
        return true;
    }
    else if (!_stricmp(pcAttrName, "MAX VELOCITY"))
    {
        if (m_puiMaxVelocity)
        {
            rvarValue = *m_puiMaxVelocity;
        }
        else if (!bLocalOnly)
        {
            rvarValue = GetMaxVelocity();
        }
        else
        {
            return false;
        }
        return true;
    }
    else if (!_stricmp(pcAttrName, "ACCELERATION"))
    {
        if (m_puiAcceleration)
        {
            rvarValue = *m_puiAcceleration;
        }
        else if (!bLocalOnly)
        {
            rvarValue = GetAcceleration();
        }
        else
        {
            return false;
        }

        return true;
    }
    else if (!_stricmp(pcAttrName, "DESIRED SPEED"))
    {
        rvarValue = m_desired_speed;
        return true;
    }
    else if (!_stricmp(pcAttrName, "CURRENT SPEED"))
    {
        rvarValue = m_current_speed;
        return true;
    }
    else if (!_stricmp(pcAttrName, "CAN AFTERBURN"))
    {
        if (m_pbCanAfterburn)
        {
            rvarValue = *m_pbCanAfterburn;
        }
        else if (!bLocalOnly)
        {
            rvarValue = CanBurn();
        }
        else
        {
            return false;
        }

        return true;
    }
    else if (!_stricmp(pcAttrName, "AFTERBURNING"))
    {
        rvarValue = m_afterburning;
        return true;
    }
    else if (!_stricmp(pcAttrName, "AFTERBURN RATIO"))
    {
        rvarValue = m_iAfterburnRatio;
        return true;
    }
    else
    {
        return CHSEngSystem::GetAttributeValue(pcAttrName, rvarValue,
                                               bAdjusted, bLocalOnly);
    }
}
Пример #9
0
int main(int argc, char** argv){

  Year year=Twel;
  DataFile RawMCFile(std::getenv("BUKETAPMCROOT"),MC,year,MagAll,buketap);
  TFile* TRaw= new TFile((RawMCFile.GetFP()).data());
  TTree* RawTree=(TTree*)TRaw->Get("DecayTreeTuple/DecayTree");
  if(!RawTree){
    std::cout<<"Null pointer to raw tree"<<std::endl;
    return 1;
  }

  const int GeneratedMC=((year==Twel) ? (547828+541116) : (259865+261888));
  
  //========================================== Use truth cuts to get raw baseline and stripping efficiency================================================
  TCut TRUEIDs ="Bu_TRUEID==521&&Kaon_TRUEID==321&&eta_prime_TRUEID==331&&piminus_TRUEID==-211&&piplus_TRUEID==211&&gamma_TRUEID==22";

  TCut MotherIDs="Kaon_MC_MOTHER_ID==521&&eta_prime_MC_MOTHER_ID==521&&piminus_MC_MOTHER_ID==113&&piminus_MC_GD_MOTHER_ID==331&&piplus_MC_MOTHER_ID==113&&piplus_MC_GD_MOTHER_ID==331&&gamma_MC_MOTHER_ID==331&&gamma_MC_GD_MOTHER_ID==521";

  TCut MotherKeys="(piminus_MC_MOTHER_KEY==piplus_MC_MOTHER_KEY)&&(eta_prime_MC_MOTHER_KEY==Kaon_MC_MOTHER_KEY)";

  TCut AntiTRUEIDs ="Bu_TRUEID==-521&&Kaon_TRUEID==-321&&eta_prime_TRUEID==331&&piminus_TRUEID==211&&piplus_TRUEID==-211&&gamma_TRUEID==22";

  TCut AntiMotherIDs="Kaon_MC_MOTHER_ID==-521&&eta_prime_MC_MOTHER_ID==-521&&piminus_MC_MOTHER_ID==113&&piminus_MC_GD_MOTHER_ID==331&&piplus_MC_MOTHER_ID==113&&piplus_MC_GD_MOTHER_ID==331&&gamma_MC_MOTHER_ID==331&&gamma_MC_GD_MOTHER_ID==-521";

  TCut Matter=TRUEIDs&&MotherIDs;
  TCut AntiMatter=AntiTRUEIDs&&AntiMotherIDs;

  const TCut TruthCuts=(Matter||AntiMatter)&&MotherKeys;

  Long64_t Baseline=RawTree->GetEntries(TruthCuts);

  double StripEff=GetEfficiency(Baseline,GeneratedMC);
  double StripEffUncert=EfficiencyUncert(Baseline,GeneratedMC);

  std::cout<<"Stripping Efficiency = "<<StripEff<<" +/- "<<StripEffUncert<<std::endl;

  //============================================== Assess efficiencies of Pre Selection Cuts============================================================

  const TCut PreSelCut="gamma_CL>0.1&&Kaon_TRACK_CHI2NDOF<3.0&&piminus_TRACK_CHI2NDOF<3.0&&piplus_TRACK_CHI2NDOF<3.0&&Kaon_MC12TuneV3_ProbNNk>0.1&&piminus_MC12TuneV3_ProbNNpi>0.1&&piplus_MC12TuneV3_ProbNNpi>0.1&&piminus_PT>300.0&&piplus_PT>300.0";
  
  Long64_t PreSelPassing = RawTree->GetEntries(TruthCuts&&PreSelCut);

  double PreSelEff=GetEfficiency(PreSelPassing,Baseline);
  double PreSelUncert=EfficiencyUncert(PreSelPassing,Baseline);

  std::cout<<"Pre Selection Efficiency = "<<PreSelEff<<" +/- "<<PreSelUncert<<std::endl;

  std::cout<<"Passing Truth and PreSelection "<<PreSelPassing<<std::endl;

  std::cout<<"Passing PreSel with no truth "<<RawTree->GetEntries(PreSelCut)<<std::endl;

  //============================================== Assess efficiencies of Initial Pre Selection Cuts============================================================

  const TCut InitPreSelCut="Kaon_TRACK_CHI2NDOF<3.0&&piminus_TRACK_CHI2NDOF<3.0&&piplus_TRACK_CHI2NDOF<3.0&&Kaon_MC12TuneV3_ProbNNk>0.1&&piminus_MC12TuneV3_ProbNNpi>0.1&&piplus_MC12TuneV3_ProbNNpi>0.1&&piminus_PT>300.0&&piplus_PT>300.0";
  
  Long64_t InitPreSelPassing = RawTree->GetEntries(TruthCuts&&InitPreSelCut);

  double InitPreSelEff=GetEfficiency(InitPreSelPassing,Baseline);
  double InitPreSelUncert=EfficiencyUncert(InitPreSelPassing,Baseline);

  std::cout<<"Initial Pre Selection Efficiency = "<<InitPreSelEff<<" +/- "<<InitPreSelUncert<<std::endl;

  std::cout<<"Passing Truth and Initial PreSelection "<<InitPreSelPassing<<std::endl;

  std::cout<<"Passing Initial PreSel with no truth "<<RawTree->GetEntries(InitPreSelCut)<<std::endl;

  
  //============================================ Trigger Efficiencies ==========================================================================

  const TCut LOTrigger = "Bu_L0HadronDecision_TOS||Bu_L0Global_TIS";
  const TCut HLT1 = "Bu_Hlt1TrackAllL0Decision_TOS";
  const TCut HLT2 = "Bu_Hlt2Topo2BodyBBDTDecision_TOS||Bu_Hlt2Topo3BodyBBDTDecision_TOS||Bu_Hlt2Topo4BodyBBDTDecision_TOS";

  //L0 Efficiency  
  Long64_t PassingL0=RawTree->GetEntries(TruthCuts&&PreSelCut&&LOTrigger);

  double L0Efficiency=GetEfficiency(PassingL0,PreSelPassing);
  double L0EfficiencyUncert=EfficiencyUncert(PassingL0,PreSelPassing);

  std::cout<<" L0 efficiency = "<<L0Efficiency<<" +/- "<<L0EfficiencyUncert<<std::endl;

  //HLT1 Efficiency
  Long64_t PassingHLT1=RawTree->GetEntries(TruthCuts&&PreSelCut&&LOTrigger&&HLT1);

  double HLT1Efficiency=GetEfficiency(PassingHLT1,PassingL0);
  double HLT1EfficiencyUncert=EfficiencyUncert(PassingHLT1,PassingL0);

  std::cout<<" HLT1 Efficiency "<<HLT1Efficiency<<" +/- "<<HLT1EfficiencyUncert<<std::endl;

  //HLT2 Efficiency
  Long64_t PassingHLT2=RawTree->GetEntries(TruthCuts&&PreSelCut&&LOTrigger&&HLT1&&HLT2);

  double HLT2Efficiency=GetEfficiency(PassingHLT2,PassingHLT1);
  double HLT2EfficiencyUncert= EfficiencyUncert(PassingHLT2,PassingHLT1);

  std::cout<< "HLT2 Efficiency "<<HLT2Efficiency<<" +/- "<<HLT2EfficiencyUncert<<std::endl;


  //Overall Trigger Efficiency
  double OverallMultiplication = L0Efficiency*HLT1Efficiency*HLT2Efficiency;
  std::cout<<"Overall Trigger Efficiency from multiplcation = "<<OverallMultiplication<<std::endl;

  double OverallTriggerEfficiency=GetEfficiency(PassingHLT2,PreSelPassing);
  double OverallTriggerEfficiencyUncert=EfficiencyUncert(PassingHLT2,PreSelPassing);

  std::cout<<" Overtall Trigger Efficiency = "<<OverallTriggerEfficiency<<" +/- "<<OverallTriggerEfficiencyUncert<<std::endl;
  
  std::cout<<" Total Passing Trigger = "<<PassingHLT2<<std::endl;

  //EtaPrime 2Sigma Efficiency
  const double EtaPrimeMass=957.78;
  const double Sigma=13.5;
  std::string UpperCutString="eta_prime_MM<"+std::to_string(EtaPrimeMass+(2*Sigma));
  TCut UpperMassCut=UpperCutString.data();
  std::string LowerCutString = "eta_prime_MM>"+std::to_string(EtaPrimeMass-(2*Sigma));
  TCut LowerMassCut=LowerCutString.data();

  Long64_t PassingSigmaCut=RawTree->GetEntries(TruthCuts&&PreSelCut&&LOTrigger&&HLT1&&HLT2&&UpperMassCut&&LowerMassCut);

  std::cout<<" Sigma Efficiency = "<<GetEfficiency(PassingSigmaCut,PassingHLT2)<<" +/- "<<EfficiencyUncert(PassingSigmaCut,PassingHLT2)<<std::endl;
  


  DataFile MVAA(std::getenv("BUKETAPMCBDTRESPROOT"),MC,year,MagAll,buketap,"BDTApplied_SampleA");

  DataFile MVAB(std::getenv("BUKETAPMCBDTRESPROOT"),MC,year,MagAll,buketap,"BDTApplied_SampleB");

  TChain* MVAChain = new TChain("DecayTree");
  MVAChain->AddFile((MVAA.GetFP()).data());
  MVAChain->AddFile((MVAB.GetFP()).data());


  std::cout<<"Entries in MVA Chain before MVA Cut = "<<MVAChain->GetEntries("gamma_CL>0.1")<<std::endl;

  int PassingMVA=MVAChain->GetEntries("gamma_CL>0.1&&BDT_response>0.20");
  double MVACutEfficiency=GetEfficiency(PassingMVA,PassingHLT2);
  double MVACutUncert=EfficiencyUncert(PassingMVA,PassingHLT2);

  std::cout<<" MVA efficiency= "<<MVACutEfficiency<<" +/- "<<MVACutUncert<<std::endl;
  
  TChain* PIDChain = new TChain("DecayTree");
  if(year==Twel){
    DataFile MagUpA(std::getenv("BUKETAPMCBDTRESPROOT"),MC,year,MagUp,buketap,"BDTApplied_SampleA_PID-All-corrected");
    DataFile MagUpB(std::getenv("BUKETAPMCBDTRESPROOT"),MC,year,MagUp,buketap,"BDTApplied_SampleB_PID-All-corrected");
    DataFile MagDownB(std::getenv("BUKETAPMCBDTRESPROOT"),MC,year,MagDown,buketap,"BDTApplied_SampleB_PID-All-corrected");
    DataFile MagDownA(std::getenv("BUKETAPMCBDTRESPROOT"),MC,year,MagDown,buketap,"BDTApplied_SampleA_PID-All-corrected");
    
    PIDChain->AddFile(MagUpA);
    PIDChain->AddFile(MagUpB);
    PIDChain->AddFile(MagDownA);
    PIDChain->AddFile(MagDownB);

  

  }else if(year==Elev){
    DataFile MC11A(std::getenv("BUKETAPMCBDTRESPROOT"),MC,year,MagAll,buketap,"BDTApplied_SampleA");
    DataFile MC11B(std::getenv("BUKETAPMCBDTRESPROOT"),MC,year,MagAll,buketap,"BDTApplied_SampleB");
    PIDChain->AddFile(MC11A);
    PIDChain->AddFile(MC11B);
    
  }
  
  int BeforePIDCuts=PIDChain->GetEntries("gamma_CL>0.1&&BDT_response>0.20");
  int AfterPIDCuts=PIDChain->GetEntries("gamma_CL>0.1&&BDT_response>0.20&&Kaon_MC12TuneV3_ProbNNk>0.4&&piminus_MC12TuneV3_ProbNNpi>0.2&&piplus_MC12TuneV3_ProbNNpi>0.2");
  
  double PIDEfficiency= GetEfficiency(AfterPIDCuts,BeforePIDCuts);
  double PIDEfficiencyUncert=EfficiencyUncert(AfterPIDCuts,BeforePIDCuts);
  std::cout<<"PID Efficiency = "<<PIDEfficiency<<" +/- "<<PIDEfficiencyUncert<<std::endl;
  
}
Int_t DstPiAnalysis::WeightEvents(){
 
  
  if(!OpenReducedNtuple())return 0;
  SetReducedNtupleBranches();
  if(!OpenEfficiency()){cout<<"Could not open efficiecy file"<<endl;return 0;}


  //
  TH1F HDstPi("HDstPi","HDstPi",2000,2.1,4.1);
 
  //
  TH1F HDstPiEff("HDstPiEff","HDstPiEff",2000,2.1,4.1);
  HDstPiEff.Sumw2();
    
  //mass cut abs(heli)>.75
  TH1F HDstPiMD2420Helicity("HDstPiMD2420Helicity","HDstPiMD2420Helicity",2000,2.1,4.1);
  HDstPiMD2420Helicity.Sumw2();

  //mass cut abs(heli)<.5
  TH1F HDstPiMD2460Helicity("HDstPiMD2460Helicity","HDstPiMD2460Helicity",2000,2.1,4.1);
  HDstPiMD2460Helicity.Sumw2();


  //mass vs helicity .2 slices
  TH1F* HDstPiMVsHelicity[10];
  for(Int_t i=0;i<10;i++){
    HDstPiMVsHelicity[i]=new TH1F(TString("HDstPiMVsHelicity")+(long)i,"HDstPiMVsHelicity",2000,2.1,4.1);
    HDstPiMVsHelicity[i]->Sumw2();
  }  

  //mass vs helicity .1 slices
  TH1F* HDstPiMVsHelicityFine[20];
  for(Int_t i=0;i<20;i++){
    HDstPiMVsHelicityFine[i]=new TH1F(TString("HDstPiMVsHelicityFine")+(long)i,"HDstPiMVsHelicityFine",2000,2.1,4.1);
    HDstPiMVsHelicityFine[i]->Sumw2();
  }  


  //mass vs helicity .2 slices cut -.5 cosD*
  TH1F* HDstPiMVsHelicityN5Cos[10];
  for(Int_t i=0;i<10;i++){
    HDstPiMVsHelicityN5Cos[i]=new TH1F(TString("HDstPiMVsHelicityN5Cos")+(long)i,"HDstPiMVsHelicityN5Cos",2000,2.1,4.1);
    HDstPiMVsHelicityN5Cos[i]->Sumw2();
  }  


  //mass vs helicity .2 slices cut -.9 cosD*
  TH1F* HDstPiMVsHelicityN9Cos[10];
  for(Int_t i=0;i<10;i++){
    HDstPiMVsHelicityN9Cos[i]=new TH1F(TString("HDstPiMVsHelicityN9Cos")+(long)i,"HDstPiMVsHelicityN9Cos",2000,2.1,4.1);
    HDstPiMVsHelicityN9Cos[i]->Sumw2();
  }  


  //mass vs helicity in slices of .25, for dependent mass widths 
  TH1F* HDstPiMVsHelicityMW[8];
  for(Int_t i=0;i<8;i++){
    HDstPiMVsHelicityMW[i]=new TH1F(TString("HDstPiMVsHelicityMW")+(long)i,"HDstPiMVsHelicityMW",2000,2.1,4.1);
    HDstPiMVsHelicityMW[i]->Sumw2();
  }


  //mass vs helicity in slices of .25, for dependent mass widths 
  TH1F* HDstPiMVsCoarseAbsHelicity[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsCoarseAbsHelicity[i]=new TH1F(TString("HDstPiMVsCoarseAbsHelicity")+(long)i,"HDstPiMVsCoarseAbsHelicity",2000,2.1,4.1);
    HDstPiMVsCoarseAbsHelicity[i]->Sumw2();
  }




  //efficiency corrected mass vs p* coarse
  TH1F* HDstPiMVsPstar[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPstar[i]=new TH1F(TString("HDstPiMVsPstar")+(long)i,"HDstPiMVsPstar",2000,2.1,4.1);
    HDstPiMVsPstar[i]->Sumw2();
  } 
  TH1* HDstPiMVsPstarNoEff[4];//for p* dependent mass-width systematics with no helicity cut
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPstarNoEff[i]=new TH1F(TString("HDstPiMVsPstarNoEff")+(long)i,"HDstPiMVsPstarNoEff",2000,2.1,4.1); 

  TH1* HDstPiMVsPstarD2420[4];//for p* systematics for MC this should not be weighted due to low stats
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPstarD2420[i]=new TH1F(TString("HDstPiMVsPstarD2420")+(long)i,"HDstPiMVsPstarD2420",2000,2.1,4.1); 
    HDstPiMVsPstarD2420[i]->Sumw2();
  }
  TH1* HDstPiMVsPstarD2460[4];//for p* systematics
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPstarD2460[i]=new TH1F(TString("HDstPiMVsPstarD2460")+(long)i,"HDstPiMVsPstarD2460",2000,2.1,4.1); 
    HDstPiMVsPstarD2460[i]->Sumw2();
  }


  //efficiency corrected mass vs p* for crossections  
  TH1F* HDstPiMVsPstarFine[10];
  for(Int_t i=0;i<10;i++){
    HDstPiMVsPstarFine[i]=new TH1F(TString("HDstPiMVsPstarFine")+(long)i,"HDstPiMVsPstarFine",2000,2.1,4.1);
    HDstPiMVsPstarFine[i]->Sumw2();
  }   
  TH1F* HDstPiMVsEnergyFine[30];
  for(Int_t i=0;i<30;i++){
    HDstPiMVsEnergyFine[i]=new TH1F(TString("HDstPiMVsEnergyFine")+(long)i,"HDstPiMVsEnergyFine",2000,2.1,4.1);
    HDstPiMVsEnergyFine[i]->Sumw2();
  }   
  

  //efficiency corrected mass vs cos Dstar  
  TH1F* HDstPiMVsCosDstar[20];
  for(Int_t i=0;i<20;i++){
    HDstPiMVsCosDstar[i]=new TH1F(TString("HDstPiMVsCosDstar")+(long)i,"HDstPiMVsCosDstar",2000,2.1,4.1);
    HDstPiMVsCosDstar[i]->Sumw2();
  }


  //efficiency corrected mass vs cosD* in slices of .25, for dependent mass widths 
  TH1F* HDstPiMVsCosDstarMW[8];
  for(Int_t i=0;i<8;i++){
    HDstPiMVsCosDstarMW[i]=new TH1F(TString("HDstPiMVsCosDstarMW")+(long)i,"HDstPiMVsCosDstarMW",2000,2.1,4.1);
    HDstPiMVsCosDstarMW[i]->Sumw2();
  }

  //efficiency corrected mass vs cosD* in slices of .25, for dependent mass widths , for D2420 cut helicity>.75
  TH1F* HDstPiMVsCosDstarD2420MW[8];
  for(Int_t i=0;i<8;i++){
    HDstPiMVsCosDstarD2420MW[i]=new TH1F(TString("HDstPiMVsCosDstarD2420MW")+(long)i,"HDstPiMVsCosDstarD2420MW",2000,2.1,4.1);
    HDstPiMVsCosDstarD2420MW[i]->Sumw2();
  }
  //efficiency corrected mass vs cosD* in slices of .25, for dependent mass widths , for D2420 cut helicity<.5
  TH1F* HDstPiMVsCosDstarD2460MW[8];
  for(Int_t i=0;i<8;i++){
    HDstPiMVsCosDstarD2460MW[i]=new TH1F(TString("HDstPiMVsCosDstarD2460MW")+(long)i,"HDstPiMVsCosDstarD2460MW",2000,2.1,4.1);
    HDstPiMVsCosDstarD2460MW[i]->Sumw2();
  }




  //efficiency corrected mass vs phi*
  TH1F* HDstPiMVsPhi[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPhi[i]=new TH1F(TString("HDstPiMVsPhi")+(long)i,"HDstPiMVsPhi",2000,2.1,4.1);
    HDstPiMVsPhi[i]->Sumw2();
  } 
  TH1F* HDstPiMVsPhiNoEff[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPhiNoEff[i]=new TH1F(TString("HDstPiMVsPhiNoEff")+(long)i,"HDstPiMVsPhiNoEff",2000,2.1,4.1);
    HDstPiMVsPhiNoEff[i]->Sumw2();
  } 
  TH1* HDstPiMVsPhiD2420[4];//for  systematics
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPhiD2420[i]=new TH1F(TString("HDstPiMVsPhiD2420")+(long)i,"HDstPiMVsPhiD2420",2000,2.1,4.1);
    HDstPiMVsPhiD2420[i]->Sumw2();
  }
  TH1* HDstPiMVsPhiD2460[4];//for   systematics 
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPhiD2460[i]=new TH1F(TString("HDstPiMVsPhiD2460")+(long)i,"HDstPiMVsPhiD2460",2000,2.1,4.1); 
    HDstPiMVsPhiD2460[i]->Sumw2();
  }




  //efficiency corrected mass vs cos*
  TH1F* HDstPiMVsCos[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsCos[i]=new TH1F(TString("HDstPiMVsCos")+(long)i,"HDstPiMVsCos",2000,2.1,4.1);
    HDstPiMVsCos[i]->Sumw2();
  }
  TH1F* HDstPiMVsCosNoEff[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsCosNoEff[i]=new TH1F(TString("HDstPiMVsCosNoEff")+(long)i,"HDstPiMVsCosNoEff",2000,2.1,4.1);
    HDstPiMVsCosNoEff[i]->Sumw2();
  } 
  TH1* HDstPiMVsCosD2420[4];//for  systematics  
  for(Int_t i=0;i<4;i++){
    HDstPiMVsCosD2420[i]=new TH1F(TString("HDstPiMVsCosD2420")+(long)i,"HDstPiMVsCosD2420",2000,2.1,4.1); 
    HDstPiMVsCosD2420[i]->Sumw2();
  }
  TH1* HDstPiMVsCosD2460[4];//for  systematics 
  for(Int_t i=0;i<4;i++){
    HDstPiMVsCosD2460[i]=new TH1F(TString("HDstPiMVsCosD2460")+(long)i,"HDstPiMVsCosD2460",2000,2.1,4.1); 
    HDstPiMVsCosD2460[i]->Sumw2();
  }





  //Legendre projections
  TH1F* HDstPiMLegendre[NPROJS];
  for(Int_t i=0;i<NPROJS;i++){
    HDstPiMLegendre[i]=new TH1F(TString("HDstPiMLegendre")+(long)i,"HDstPiMLegendre",2000,2.1,4.1);
    HDstPiMLegendre[i]->Sumw2();
  }  
  //slice P2 in cosD* 
  TH1F* HDstPiMP2VsCosDstar[8];
  for(Int_t i=0;i<8;i++){
    HDstPiMP2VsCosDstar[i]=new TH1F(TString("HDstPiMP2VsCosDstar")+(long)i,"HDstPiMP2VsCosDstar",2000,2.1,4.1);
    HDstPiMP2VsCosDstar[i]->Sumw2();
  }  



  //2D Helicity vs mass
  TH2F H2DstPiMVsDstarHel("H2DstPiMVsDstarHel","H2DstPiMVsDstarHel",2000,2.1,4.1,20,-1.0,1.0);
  H2DstPiMVsDstarHel.Sumw2();
  TH2F H2DstPiMVsDstarHelNoEff("H2DstPiMVsDstarHelNoEff","H2DstPiMVsDstarHelNoEff",2000,2.1,4.1,20,-1.0,1.0);
  H2DstPiMVsDstarHelNoEff.Sumw2();

  TH2F* H2DstPiMVsHelCosDstar[4];
  for(Int_t i=0;i<4;i++){
    H2DstPiMVsHelCosDstar[i]=new TH2F(TString("H2DstPiMVsHelCosDstar")+(long)i,TString("H2DstPiMVsHelCosDstar")+(long)i,2000,2.1,4.1,20,-1.0,1.0);
    H2DstPiMVsHelCosDstar[i]->Sumw2();
  }  



  ///------------------------------------------
  ////efficiencies after eff corrections
  //----------------------------
  TH3F H3PvsMVsDstA; 

  TH2F H2PvsM;   

  TH1F HDstarHelicityNoShape;

  TH1F HDstarHelicity;
 
  TH1F HDstPiMNoShape;

  TH1F HDstPiDM;

  TH1F HPstarNoShape;

  TH1F HDstarAngleNoShape;

  TH1F HDstarAngle;
  
  TH1F HDstPiCosstarNoShape;
    
  //fully efficiency corrected mass
  TH1F HDstPiMFineNoRes;

  //Generated mass vs p*   
  TH1* HMCMVsPstar[4];

  if(_TruthMatch){
   
    if(!OpenReducedFile())return 0;

    HMCDstarHelicity=(TH1F*)ReducedFile->Get("HMCDstarHelicity");
    if(!HMCDstarHelicity)return 0;
  
    HMCXMass=(TH1F*)ReducedFile->Get("HMCXMass");
    if(!HMCXMass)return 0;  
  
    HMCXp3CM=(TH1F*)ReducedFile->Get("HMCXp3CM");
    if(!HMCXp3CM)return 0;

    HMCXcosthCM=(TH1F*)ReducedFile->Get("HMCXcosthCM");
    if(!HMCXcosthCM)return 0;

    HMCDstarAngle=(TH1F*)ReducedFile->Get("HMCDstarAngle");
    if(!HMCDstarAngle)return 0;

    H3MCPvsMassVsDstAngle=(TH3F*)ReducedFile->Get("H3MCPvsMassVsDstAngle");                                                    
    if(!H3MCPvsMassVsDstAngle){
      cout<<"No histogram found"<<endl;
      return 0;
    }
    
    H2MCPvsMass=(TH2F*)ReducedFile->Get("H2MCPvsMass");                                                    
    if(!H2MCPvsMass){
      cout<<"No histogram found"<<endl;
      return 0;
    }

    H2MCPvsMassFine=(TH2F*)ReducedFile->Get("H2MCPvsMassFine");                                                    
    if(!H2MCPvsMass){
      cout<<"No histogram found"<<endl;
      return 0;
    }


    //----------------------------
    H3PvsMVsDstA.SetNameTitle("H3PvsMVsDstA","H3PvsMVsDstA");
    H3PvsMVsDstA.SetBins(H3MCPvsMassVsDstAngle->GetXaxis()->GetNbins(),
		      H3MCPvsMassVsDstAngle->GetXaxis()->GetXmin(),
		      H3MCPvsMassVsDstAngle->GetXaxis()->GetXmax(),
		      H3MCPvsMassVsDstAngle->GetYaxis()->GetNbins(),
		      H3MCPvsMassVsDstAngle->GetYaxis()->GetXmin(),
		      H3MCPvsMassVsDstAngle->GetYaxis()->GetXmax(),
		      H3MCPvsMassVsDstAngle->GetZaxis()->GetNbins(),
		      H3MCPvsMassVsDstAngle->GetZaxis()->GetXmin(),
		      H3MCPvsMassVsDstAngle->GetZaxis()->GetXmax()); 
    H3PvsMVsDstA.Sumw2();


    //----------------------------
    H2PvsM.SetNameTitle("H2PvsM","H2PvsM");
    H2PvsM.SetBins(H2MCPvsMass->GetXaxis()->GetNbins(),
		H2MCPvsMass->GetXaxis()->GetXmin(),
		H2MCPvsMass->GetXaxis()->GetXmax(),
		H2MCPvsMass->GetYaxis()->GetNbins(),
		H2MCPvsMass->GetYaxis()->GetXmin(),
		H2MCPvsMass->GetYaxis()->GetXmax());   

    H2PvsM.Sumw2();


    //
    HDstarHelicityNoShape.SetNameTitle("HDstarHelicityNoShape","HDstarHelicityNoShape");
    HDstarHelicityNoShape.SetBins(HMCDstarHelicity->GetXaxis()->GetNbins(),HMCDstarHelicity->GetXaxis()->GetXmin(),HMCDstarHelicity->GetXaxis()->GetXmax());
    HDstarHelicityNoShape.Sumw2();
    
    
    HDstarHelicity.SetNameTitle("HDstarHelicity","HDstarHelicity");
    HDstarHelicity.SetBins(HMCDstarHelicity->GetXaxis()->GetNbins(),HMCDstarHelicity->GetXaxis()->GetXmin(),HMCDstarHelicity->GetXaxis()->GetXmax());
    HDstarHelicity.Sumw2();
    
    //efficiency corrected mass
    HDstPiMNoShape.SetNameTitle("HDstPiMNoShape","HDstPiMNoShape");
    HDstPiMNoShape.SetBins(HMCXMass->GetXaxis()->GetNbins(),HMCXMass->GetXaxis()->GetXmin(),HMCXMass->GetXaxis()->GetXmax());
    HDstPiMNoShape.Sumw2();
    
    //fully efficiency corrected delta mass
    HDstPiDM.SetNameTitle("HDstPiDM","HDstPiDM");
    HDstPiDM.SetBins(HMCXMass->GetXaxis()->GetNbins(),HMCXMass->GetXaxis()->GetXmin(),HMCXMass->GetXaxis()->GetXmax());
    HDstPiDM.Sumw2();
    
    HPstarNoShape.SetNameTitle("HPstarNoShape","HPstarNoShape");
    HPstarNoShape.SetBins(HMCXp3CM->GetXaxis()->GetNbins(),HMCXp3CM->GetXaxis()->GetXmin(),HMCXp3CM->GetXaxis()->GetXmax());
    HPstarNoShape.Sumw2();
    
    HDstarAngleNoShape.SetNameTitle("HDstarAngleNoShape","HDstarAngleNoShape");
    HDstarAngleNoShape.SetBins(HMCDstarAngle->GetXaxis()->GetNbins(),HMCDstarAngle->GetXaxis()->GetXmin(),HMCDstarAngle->GetXaxis()->GetXmax());
    HDstarAngleNoShape.Sumw2();

    HDstarAngle.SetNameTitle("HDstarAngle","HDstarAngle");
    HDstarAngle.SetBins(HMCDstarAngle->GetXaxis()->GetNbins(),HMCDstarAngle->GetXaxis()->GetXmin(),HMCDstarAngle->GetXaxis()->GetXmax());
    HDstarAngle.Sumw2();
    
    HDstPiCosstarNoShape.SetNameTitle("HDstPiCosstarNoShape","HDstPiCosstarNoShape");
    HDstPiCosstarNoShape.SetBins(HMCXcosthCM->GetXaxis()->GetNbins(),HMCXcosthCM->GetXaxis()->GetXmin(),HMCXcosthCM->GetXaxis()->GetXmax());
    HDstPiCosstarNoShape.Sumw2();
    
    //efficiency corrected mass
    HDstPiMFineNoRes.SetNameTitle("HDstPiMFineNoRes","HDstPiMFineNoRes");
    HDstPiMFineNoRes.SetBins(2000,2.1,4.1);
    HDstPiMFineNoRes.Sumw2();
   
   
    //Generated mass vs p*   
    for(Int_t i=0;i<4;i++){
      HMCMVsPstar[i]=H2MCPvsMassFine->ProjectionY(TString("HMCMVsPstar")+(long)i,i+1,i+1,"");
      if(!HMCMVsPstar[i]){cout<<"bad projection of HMCMVsPstar"<<endl; return 0;}
    } 


    if(!CloseReducedFile())return 0;
  
  }


  ///
  Float_t eff;
  Float_t effnoshape;
  Int_t e=0;
  while(ReducedNtuple->GetEntry(e)){
    e++;
    if(e%50000==0)cout<<e<<" cands done"<<endl;


    //for checking eff shapes after 3-D eff correction
    if(_TruthMatch){
      effnoshape=GetEfficiencyNoShape();
      if(effnoshape>0){//note resolution is removed so should not attemp to fit these 
	HDstarHelicityNoShape.Fill(dstarhelicity,1./effnoshape);
	HDstPiMNoShape.Fill(dstpimdm-dstpidmres,1./effnoshape);
	HPstarNoShape.Fill(dstpipstar,1./effnoshape);
	HDstarAngleNoShape.Fill(dstarcostheta,1./effnoshape);
	HDstPiCosstarNoShape.Fill(dstpicosstar,1./effnoshape);
	H3PvsMVsDstA.Fill(dstpipstar,dstpimdm-dstpidmres,dstarcostheta,1./effnoshape);
	H2PvsM.Fill(dstpipstar,dstpimdm-dstpidmres,1./effnoshape);
      }

    }
    

    HDstPi.Fill(dstpimdm);   
    H2DstPiMVsDstarHelNoEff.Fill(dstpimdm,dstarhelicity);
    ///
    HDstPiDM.Fill(dstpideltam);
    if(fabs(dstarhelicity)>.75)
      HDstPiMD2420Helicity.Fill(dstpimdm);
    if(fabs(dstarhelicity)<.5)
      HDstPiMD2460Helicity.Fill(dstpimdm);

    //for bumps
    for(Int_t i=0;i<10;i++){
      if((-1+.2*i)<dstarhelicity&&dstarhelicity<(-1+.2*(i+1))){
	if(dstarcostheta<-.5)
	  HDstPiMVsHelicityN5Cos[i]->Fill(dstpimdm);
	
	if(dstarcostheta<-.9)
	  HDstPiMVsHelicityN9Cos[i]->Fill(dstpimdm);
	
      }
    }

    for(Int_t i=0;i<4;i++){
      if(.25*i<fabs(dstarhelicity)&&fabs(dstarhelicity)<.25*(i+1))
	HDstPiMVsCoarseAbsHelicity[i]->Fill(dstpimdm);
    }


    //
    for(Int_t i=0;i<10;i++){
      if((-1+.2*i)<dstarhelicity&&dstarhelicity<(-1+.2*(i+1))){
	HDstPiMVsHelicity[i]->Fill(dstpimdm);
      }
    }
    for(Int_t i=0;i<20;i++){
      if((-1+.1*i)<dstarhelicity&&dstarhelicity<(-1+.1*(i+1)))
	HDstPiMVsHelicityFine[i]->Fill(dstpimdm);
    }
    for(Int_t i=0;i<8;i++)
      if((-1+.25*i)<dstarhelicity&&dstarhelicity<(-1.+.25*(i+1)))
	HDstPiMVsHelicityMW[i]->Fill(dstpimdm);



    //p* dependence
    for(Int_t i=0;i<4;i++)
      if((3+.5*i)<dstpipstar&&dstpipstar<(3+.5*(i+1)))
	HDstPiMVsPstar[i]->Fill(dstpimdm); 
    for(Int_t i=0;i<10;i++)
      if((3+.2*i)<dstpipstar&&dstpipstar<(3+.2*(i+1)))
	HDstPiMVsPstarFine[i]->Fill(dstpimdm);
    Float_t energyfraction=sqrt(dstpimass*dstpimass+dstpipstar*dstpipstar)/(OnPeakEnergy/2.);
    for(Int_t i=0;i<30;i++)
      if((.5+.02*i)<energyfraction&&energyfraction<(.5+.02*(i+1)))
	HDstPiMVsEnergyFine[i]->Fill(dstpimdm);

    //cos D*
    for(Int_t i=0;i<20;i++)
      if((-1+.1*i)<dstarcostheta&&dstarcostheta<(-1.+.1*(i+1)))
	HDstPiMVsCosDstar[i]->Fill(dstpimdm);
    for(Int_t i=0;i<8;i++)
      if((-1+.25*i)<dstarcostheta&&dstarcostheta<(-1.+.25*(i+1)))
	HDstPiMVsCosDstarMW[i]->Fill(dstpimdm);
    for(Int_t i=0;i<4;i++){
      if((-1+.5*i)<dstarcostheta&&dstarcostheta<(-1.+.5*(i+1)))
	H2DstPiMVsHelCosDstar[i]->Fill(dstpimdm,dstarhelicity);
    }
    for(Int_t i=0;i<8;i++)
      if((-1+.25*i)<dstarcostheta&&dstarcostheta<(-1.+.25*(i+1))&&fabs(dstarhelicity)>.75)
	HDstPiMVsCosDstarD2420MW[i]->Fill(dstpimdm);
    for(Int_t i=0;i<8;i++)
      if((-1+.25*i)<dstarcostheta&&dstarcostheta<(-1.+.25*(i+1))&&fabs(dstarhelicity)<.5)
	HDstPiMVsCosDstarD2460MW[i]->Fill(dstpimdm);

        
    //phi dependence
    for(Int_t i=0;i<4;i++)
      if((-mypi+i*mypi/2)<dstpiphistar&&dstpiphistar<(-mypi+(i+1)*mypi/2))
	HDstPiMVsPhi[i]->Fill(dstpimdm);



    //cos* dependence
    for(Int_t i=0;i<4;i++)
      if((-1+.5*i)<dstpicosstar&&dstpicosstar<(-1.+(i+1)*.5))
	HDstPiMVsCos[i]->Fill(dstpimdm);



    // p* systematics
    for(Int_t i=0;i<4;i++)
      if((3+.5*i)<dstpipstar&&dstpipstar<(3+.5*(i+1)))
	HDstPiMVsPstarNoEff[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)>.75)
      for(Int_t i=0;i<4;i++)
	if((3+.5*i)<dstpipstar&&dstpipstar<(3+.5*(i+1)))
	  HDstPiMVsPstarD2420[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)<.5)
      for(Int_t i=0;i<4;i++)
	if((3+.5*i)<dstpipstar&&dstpipstar<(3+.5*(i+1)))
	  HDstPiMVsPstarD2460[i]->Fill(dstpimdm);
    
    //phi
    for(Int_t i=0;i<4;i++)
      if((-mypi+i*mypi/2)<dstpiphistar&&dstpiphistar<(-mypi+(i+1)*mypi/2))
	HDstPiMVsPhiNoEff[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)>.75)
      for(Int_t i=0;i<4;i++)
	if((-mypi+i*mypi/2)<dstpiphistar&&dstpiphistar<(-mypi+(i+1)*mypi/2))
	  HDstPiMVsPhiD2420[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)<.5)
      for(Int_t i=0;i<4;i++)
	if((-mypi+i*mypi/2)<dstpiphistar&&dstpiphistar<(-mypi+(i+1)*mypi/2))
	  HDstPiMVsPhiD2460[i]->Fill(dstpimdm);

    //cos(theta*)
    for(Int_t i=0;i<4;i++)
      if((-1+.5*i)<dstpicosstar&&dstpicosstar<(-1.+(i+1)*.5))
	HDstPiMVsCosNoEff[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)>.75)
      for(Int_t i=0;i<4;i++)
	if((-1+.5*i)<dstpicosstar&&dstpicosstar<(-1.+(i+1)*.5))
	  HDstPiMVsCosD2420[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)<.5)
      for(Int_t i=0;i<4;i++)
	if((-1+.5*i)<dstpicosstar&&dstpicosstar<(-1.+(i+1)*.5))
	  HDstPiMVsCosD2460[i]->Fill(dstpimdm);
   


    //
    eff=GetEfficiency();
    if(eff<=0)continue;

    HDstPiEff.Fill(dstpimdm,1./eff);  

    //angles
    HDstarAngle.Fill(dstarcostheta,1./eff);
    HDstarHelicity.Fill(dstarhelicity,1./eff);

    HDstPiMFineNoRes.Fill(dstpimdm-dstpidmres,1./eff);


    ///
    H2DstPiMVsDstarHel.Fill(dstpimdm,dstarhelicity,1./eff);
 
    for(Int_t i=0;i<NPROJS;i++){
      HDstPiMLegendre[i]->Fill(dstpimdm,((2.*i+1.)/2.)*legendre(i,dstarhelicity)/eff);
    }
    for(Int_t i=0;i<8;i++)//weight by P2
      if((-1+.25*i)<dstarcostheta&&dstarcostheta<(-1.+.25*(i+1)))
	HDstPiMP2VsCosDstar[i]->Fill(dstpimdm,((2.*2+1.)/2.)*legendre(2,dstarhelicity)/eff);



  }
  if(CloseReducedNtuple()!=1)return 0;
  CloseEfficiency();


  //   //add error from the efficiency;
  //   TArrayD* sw2=HDstPiMFine.GetSumw2();
  //   for(Int_t i=1;i<=HDstPiMFine.GetNbinsX();i++){
  //     (*sw2)[i]=(*sw2)[i]+pow(.0*HDstPiMFine.GetBinContent(i),2);    
  //     if(i>300&&i<350)cout<<" "<<HDstPiMFine.GetBinError(i)/HDstPiMFine.GetBinContent(i)<<endl;        
  //   }


  TFile HistosForFit(_OutputDir+"/HistosForFit.root","recreate");  

  if(_TruthMatch){
    HDstarHelicityNoShape.Write();
    HDstPiMNoShape.Write();
    HPstarNoShape.Write();
    HDstarAngleNoShape.Write();
    HDstPiCosstarNoShape.Write();
    H3PvsMVsDstA.Write();
    H2PvsM.Write();
    HDstPiMFineNoRes.Write();

    for(Int_t i=0;i<4;i++)      
      HMCMVsPstar[i]->Write();
    
  }

  //
  HDstPi.Write();
  HDstPiEff.Write();
  HDstPiMD2420Helicity.Write();
  HDstPiMD2460Helicity.Write();
  

  //
  HDstarHelicity.Write();
  HDstarAngle.Write();
  HDstPiDM.Write();

  for(Int_t i=0;i<10;i++)
    HDstPiMVsHelicityN5Cos[i]->Write();
  for(Int_t i=0;i<10;i++)
    HDstPiMVsHelicityN9Cos[i]->Write();
  for(Int_t i=0;i<10;i++)
    HDstPiMVsHelicity[i]->Write();
  for(Int_t i=0;i<20;i++)
    HDstPiMVsHelicityFine[i]->Write();
  for(Int_t i=0;i<8;i++)
    HDstPiMVsHelicityMW[i]->Write();

  for(Int_t i=0;i<4;i++)
    HDstPiMVsCoarseAbsHelicity[i]->Write();

  for(Int_t i=0;i<4;i++)
    HDstPiMVsPstar[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPstarNoEff[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPstarD2420[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPstarD2460[i]->Write();
  for(Int_t i=0;i<10;i++)
    HDstPiMVsPstarFine[i]->Write();
  for(Int_t i=0;i<30;i++)
    HDstPiMVsEnergyFine[i]->Write();


  for(Int_t i=0;i<20;i++)
    HDstPiMVsCosDstar[i]->Write();
  for(Int_t i=0;i<8;i++)
    HDstPiMVsCosDstarMW[i]->Write();
  for(Int_t i=0;i<4;i++)
    H2DstPiMVsHelCosDstar[i]->Write();
  for(Int_t i=0;i<8;i++)
    HDstPiMVsCosDstarD2420MW[i]->Write();
  for(Int_t i=0;i<8;i++)
    HDstPiMVsCosDstarD2460MW[i]->Write();



  for(Int_t i=0;i<4;i++)
    HDstPiMVsPhi[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPhiNoEff[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPhiD2420[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPhiD2460[i]->Write();

  for(Int_t i=0;i<4;i++)
    HDstPiMVsCos[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsCosNoEff[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsCosD2420[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsCosD2460[i]->Write();

  H2DstPiMVsDstarHel.Write();
  H2DstPiMVsDstarHelNoEff.Write();


  for(Int_t i=0;i<NPROJS;i++){
    HDstPiMLegendre[i]->Write();
  }
  for(Int_t i=0;i<8;i++)
    HDstPiMP2VsCosDstar[i]->Write();


  HistosForFit.ls();
  HistosForFit.Close();


  //-------------
  //clean up
  
  for(Int_t i=0;i<NPROJS;i++)
    delete HDstPiMLegendre[i];
  for(Int_t i=0;i<8;i++)
    delete HDstPiMP2VsCosDstar[i];
  
  for(Int_t i=0;i<10;i++)
    delete HDstPiMVsHelicityN5Cos[i];
  for(Int_t i=0;i<10;i++)
    delete HDstPiMVsHelicityN9Cos[i];
  for(Int_t i=0;i<10;i++)
    delete HDstPiMVsHelicity[i];  
  for(Int_t i=0;i<20;i++)
    delete HDstPiMVsHelicityFine[i];
  for(Int_t i=0;i<8;i++)
    delete HDstPiMVsHelicityMW[i];
 
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsCoarseAbsHelicity[i];

  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPstar[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPstarNoEff[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPstarD2420[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPstarD2460[i];
  for(Int_t i=0;i<10;i++)
    delete HDstPiMVsPstarFine[i];
  for(Int_t i=0;i<30;i++)
    delete HDstPiMVsEnergyFine[i];

  for(Int_t i=0;i<20;i++)
    delete HDstPiMVsCosDstar[i];
  for(Int_t i=0;i<8;i++)
    delete HDstPiMVsCosDstarMW[i];
  for(Int_t i=0;i<4;i++)
    delete H2DstPiMVsHelCosDstar[i];
  for(Int_t i=0;i<8;i++)
    delete HDstPiMVsCosDstarD2420MW[i];
  for(Int_t i=0;i<8;i++)
    delete HDstPiMVsCosDstarD2460MW[i];

  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPhi[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPhiNoEff[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPhiD2420[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPhiD2460[i];

  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsCos[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsCosNoEff[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsCosD2420[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsCosD2460[i];
  
 
  return 1;
}
Пример #11
0
//==============================================
void MCTnPEff::Loop(Int_t effSample, Int_t resonance, Bool_t rejectCowboys, Bool_t use2DGraph, Bool_t useTEfficiency, Int_t useEventNTimes)
{
  if (fChain == 0) return;

  if(resonance == JPSI)
    pTMin = 10.;
  else if(resonance == UPS1S || resonance == UPS2S || resonance == UPS3S)
    pTMin = 5.;

  Long64_t nentries = fChain->GetEntries();
  Long64_t nb = 0;
  Long64_t countRecEvent = 0;
  printf("number of entries = %d\n", (Int_t) nentries);

  Bool_t incrementReco, incrementTrig, incrementTot;

  //loop over the events
  for (Long64_t jentry=0; jentry<nentries;jentry++) {

    if(jentry % 100000 == 0) printf("event %d\n", (Int_t) jentry);

    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);

    //===================================================================
    //1.) check all generated (and filtered) events and 
    //fill the corresponding histograms
    //===================================================================
    Double_t etaMuPos_Gen = muPos_Gen->PseudoRapidity();

    Double_t etaMuNeg_Gen = muNeg_Gen->PseudoRapidity();
    Double_t pTMuPos_Gen = muPos_Gen->Pt();
    Double_t pTMuNeg_Gen = muNeg_Gen->Pt();
    Double_t pMuPos_Gen = muPos_Gen->P();
    Double_t pMuNeg_Gen = muNeg_Gen->P();
    Double_t phiMuPos_Gen = muPos_Gen->Phi();
    Double_t phiMuNeg_Gen = muNeg_Gen->Phi();

    Double_t deltaPhi = phiMuNeg_Gen - phiMuPos_Gen;
    if(rejectCowboys){
      if(deltaPhi > TMath::Pi()) deltaPhi -= 2.*TMath::Pi();
      else if(deltaPhi < -TMath::Pi()) deltaPhi += 2.*TMath::Pi();
      if(deltaPhi < 0.) //reject cowboys
	continue;
    }

    // //if(!(isMuonInAcceptance(LOOSE, pTMuPos_Gen, etaMuPos_Gen) && isMuonInAcceptance(LOOSE, pTMuNeg_Gen, etaMuNeg_Gen)))
    // if(!(isMuonInAcceptance(TIGHT, pTMuPos_Gen, etaMuPos_Gen) && isMuonInAcceptance(TIGHT, pTMuNeg_Gen, etaMuNeg_Gen)))
    //   continue;
    // // if(pTMuPos_Gen < 2.5 || pTMuNeg_Gen < 2.5)
    // //   continue;
    // if(fabs(etaMuPos_Gen) > 1.6 || fabs(etaMuNeg_Gen) > 1.6)
    //   continue;

    Bool_t decisionPos = kFALSE, decisionNeg = kFALSE;
    //positive muon
    if(TMath::Abs(etaMuPos_Gen)<1.2 && pTMuPos_Gen>4.5) decisionPos=kTRUE;
    if(TMath::Abs(etaMuPos_Gen)>1.2 && TMath::Abs(etaMuPos_Gen)<1.4 && pTMuPos_Gen>3.5) decisionPos=kTRUE;
    if(TMath::Abs(etaMuPos_Gen)>1.4 && TMath::Abs(etaMuPos_Gen)<1.6 && pTMuPos_Gen>3.) decisionPos=kTRUE;
    //negative muon
    if(TMath::Abs(etaMuNeg_Gen)<1.2 && pTMuNeg_Gen>4.5) decisionNeg=kTRUE;
    if(TMath::Abs(etaMuNeg_Gen)>1.2 && TMath::Abs(etaMuNeg_Gen)<1.4 && pTMuNeg_Gen>3.5) decisionNeg=kTRUE;
    if(TMath::Abs(etaMuNeg_Gen)>1.4 && TMath::Abs(etaMuNeg_Gen)<1.6 && pTMuNeg_Gen>3.) decisionNeg=kTRUE;

    if(!decisionPos || !decisionNeg)
      continue;

    Double_t onia_Gen_mass = onia_Gen->M();
    Double_t onia_Gen_pt = onia_Gen->Pt();
    Double_t onia_Gen_P = onia_Gen->P();
    Double_t onia_Gen_eta = onia_Gen->PseudoRapidity();
    Double_t onia_Gen_rap = onia_Gen->Rapidity();
    Double_t onia_Gen_phi = onia_Gen->Phi();
    Double_t onia_Gen_mT = sqrt(onia_Gen_mass*onia_Gen_mass + onia_Gen_pt*onia_Gen_pt);
    
    if(fabs(onia_Gen_rap) > eff::rapMax)
      continue;

    Int_t rapIndex_Gen = -1;
    for(int iRap = 0; iRap < 2*eff::kNbRapBins; iRap++){
      if(onia_Gen_rap > eff::rapRange[iRap] && onia_Gen_rap < eff::rapRange[iRap+1]){
	rapIndex_Gen = iRap;
	break;
      }
    }
    Int_t rapForPTIndex_Gen = -1;
    for(int iRap = 0; iRap < eff::kNbRapForPTBins; iRap++){
      if(TMath::Abs(onia_Gen_rap) > eff::rapForPTRange[iRap] && 
	 TMath::Abs(onia_Gen_rap) < eff::rapForPTRange[iRap+1]){
	rapForPTIndex_Gen = iRap+1;
	break;
      }
    }
    Int_t pTIndex_Gen = -1;
    for(int iPT = 0; iPT < eff::kNbPTBins[rapForPTIndex_Gen]; iPT++){
      if(onia_Gen_pt > eff::pTRange[rapForPTIndex_Gen][iPT] && onia_Gen_pt < eff::pTRange[rapForPTIndex_Gen][iPT+1]){
	pTIndex_Gen = iPT+1;
	break;
      }
    }
    Int_t rapIntegratedPTIndex_Gen = -1;
    for(int iPT = 0; iPT < eff::kNbPTBins[0]; iPT++){
      if(onia_Gen_pt > eff::pTRange[0][iPT] && onia_Gen_pt < eff::pTRange[0][iPT+1]){
	rapIntegratedPTIndex_Gen = iPT+1;
	break;
      }
    }
    if(rapIndex_Gen < 0){
      // printf("rapIndex_Gen %d, rap(onia) = %f\n", rapIndex_Gen, onia_rap);
      continue;
    }
    if(rapForPTIndex_Gen < 1){
      // printf("rapForPTIndex_Gen %d, rap(onia) = %f\n", rapForPTIndex_Gen, onia_rap);
      continue;
    }
    if(pTIndex_Gen < 1){
      // printf("pTIndex_Gen %d, pT(onia) = %f\n", pTIndex_Gen, onia_pt);
      continue;
    }

    //==============================
    calcPol(*muPos_Gen, *muNeg_Gen);
    //==============================

    // Bool_t usePTFit = kTRUE; //alternative to the T&P histograms use fitted pT differential efficiency
    Bool_t usePTFit = kFALSE; //alternative to the T&P histograms use fitted pT differential efficiency

    Double_t randNb = 0.;
    Double_t totEff = 0.;

    for(int iN = 0; iN < useEventNTimes; iN++){

      randNb = gRandom->Uniform();
      if(!useIndivEff){
      
	totEff = 0.99*0.99; //tracking efficiency
	//totEff = 1.0 * 1.0;
      
	if(usePTFit){
	  if(!useTEfficiency){
	    totEff *= GetEfficiency_FromParametrization(SingleMuEff, effSample, etaMuPos_Gen, pTMuPos_Gen);
	    totEff *= GetEfficiency_FromParametrization(SingleMuEff, effSample, etaMuNeg_Gen, pTMuNeg_Gen);
	  }
	}
	else{
	  if(!useTEfficiency){
	    totEff *= GetEfficiency(SingleMuEff, effSample, etaMuPos_Gen, pTMuPos_Gen, use2DGraph);
	    totEff *= GetEfficiency(SingleMuEff, effSample, etaMuNeg_Gen, pTMuNeg_Gen, use2DGraph);
	  }
	  else{
	    totEff *= GetTEfficiency(SingleMuEff, effSample, etaMuPos_Gen, pTMuPos_Gen);
	    totEff *= GetTEfficiency(SingleMuEff, effSample, etaMuNeg_Gen, pTMuNeg_Gen);
	  }
	}
	// //dimuon vertexing cut NOT included in the (single) muon quality cuts...
	// if(JpsiVprob < 0.01)
	// 	totEff = 0.;
      }
      else{
	Double_t epsTrack_Pos = 0.99;
	Double_t epsTrack_Neg = 0.99;
	// Double_t epsTrack_Pos  = 1.0;
	// Double_t epsTrack_Neg = 1.0;
	Double_t epsMuonID_Pos, epsQual_Pos, epsMuonID_Neg, epsQual_Neg;
	if(usePTFit){
	  epsMuonID_Pos = GetEfficiency_FromParametrization(MuIDEff, effSample, etaMuPos_Gen, pTMuPos_Gen);
	  epsQual_Pos   = GetEfficiency_FromParametrization(MuQualEff, effSample, etaMuPos_Gen, pTMuPos_Gen);
	  epsMuonID_Neg = GetEfficiency_FromParametrization(MuIDEff, effSample, etaMuNeg_Gen, pTMuNeg_Gen);
	  epsQual_Neg   = GetEfficiency_FromParametrization(MuQualEff, effSample, etaMuNeg_Gen, pTMuNeg_Gen);
	}
	else{
	  epsMuonID_Pos = GetEfficiency(MuIDEff, effSample, etaMuPos_Gen, pTMuPos_Gen);
	  epsQual_Pos   = GetEfficiency(MuQualEff, effSample, etaMuPos_Gen, pTMuPos_Gen);
	  epsMuonID_Neg = GetEfficiency(MuIDEff, effSample, etaMuNeg_Gen, pTMuNeg_Gen);
	  epsQual_Neg   = GetEfficiency(MuQualEff, effSample, etaMuNeg_Gen, pTMuNeg_Gen);
	}
	Double_t recoEff_Pos = epsTrack_Pos * epsMuonID_Pos * epsQual_Pos;
	Double_t recoEff_Neg = epsTrack_Neg * epsMuonID_Neg * epsQual_Neg;
	Double_t recoEff = recoEff_Pos * recoEff_Neg;
	
	// //dimuon vertexing cut NOT included in the (single) muon quality cuts...
	// if(JpsiVprob < 0.01)
	// 	recoEff = 0.;
	
	//the indiv. histograms will be filled depending on the
	//assigned probability
	if(recoEff > randNb)
	  incrementReco = kTRUE;
	else
	  incrementReco = kFALSE;

	//test: check whether this particular event was really reconstructed...
	Bool_t recoPassed = kFALSE;
	//      if(onia->Pt() < 990. && fabs(onia->Rapidity()) < eff::rapMax && JpsiVprob > 0.01) recoPassed = kTRUE;
	if(onia->Pt() < 990. && fabs(onia->Rapidity()) < eff::rapMax) recoPassed = kTRUE;
	hCorrRECO->Fill(recoPassed, incrementReco);

	Double_t epsL1L2Trig_Pos, epsL3Trig_Pos, epsL1L2Trig_Neg, epsL3Trig_Neg;
	Double_t trigEff = 0.;
	// if(recoPassed){//check the trigger efficiency only for those events that pass RECO
	incrementTrig = kFALSE;
	if(incrementReco){

	  //if(strncmp("HLT_Dimuon10_Jpsi_Barrel", trigLabel, 24) == 0 || strncmp("HLT_Dimuon5_Upsilon_Barrel", trigLabel, 26) == 0){
	  //HLT_Dimuon10_Jpsi_Barrel_v3... 1.4E33
	  //HLT_Dimuon10_Jpsi_Barrel_v5... no cowboys
	  //HLT_Dimuon10_Jpsi_Barrel_v6... L1DoubleMu0_HighQ
	  //HLT_Dimuon13_Jpsi_Barrel_v1... L1DoubleMu0_HighQ
	  //HLT_Dimuon5_Upsilon_Barrel_v3... 1.4E33
	  //HLT_Dimuon5_Upsilon_Barrel_v5... no cowboys
	  //HLT_Dimuon7_Upsilon_Barrel_v1... L1DoubleMu0_HighQ
	  //HLT_Dimuon9_Upsilon_Barrel_v1... L1DoubleMu0_HighQ

	  if(usePTFit){
	    epsL1L2Trig_Pos = GetEfficiency_FromParametrization(L1L2Eff, effSample, etaMuPos_Gen, pTMuPos_Gen);
	    epsL3Trig_Pos   = GetEfficiency_FromParametrization(L3Eff, effSample, etaMuPos_Gen, pTMuPos_Gen);
	    epsL1L2Trig_Neg = GetEfficiency_FromParametrization(L1L2Eff, effSample, etaMuNeg_Gen, pTMuNeg_Gen);
	    epsL3Trig_Neg   = GetEfficiency_FromParametrization(L3Eff, effSample, etaMuNeg_Gen, pTMuNeg_Gen);
	  }
	  else{
	    epsL1L2Trig_Pos = GetEfficiency(L1L2Eff, effSample, etaMuPos_Gen, pTMuPos_Gen);
	    epsL3Trig_Pos   = GetEfficiency(L3Eff, effSample, etaMuPos_Gen, pTMuPos_Gen);
	    epsL1L2Trig_Neg = GetEfficiency(L1L2Eff, effSample, etaMuNeg_Gen, pTMuNeg_Gen);
	    epsL3Trig_Neg   = GetEfficiency(L3Eff, effSample, etaMuNeg_Gen, pTMuNeg_Gen);
	  }
	  trigEff = epsL1L2Trig_Pos * epsL3Trig_Pos * epsL1L2Trig_Neg * epsL3Trig_Neg;
	  //}
	}
	if(trigEff > randNb)
	  incrementTrig = kTRUE;
	else
	  incrementTrig = kFALSE;

	totEff = trigEff * recoEff;
      }//useIndivEff
      // //account for the dimuon vertexing efficiency:
      // totEff *= GetDimuEfficiency(effSample, thisCosTh[eff::CS], thisPhi[eff::CS]);

      if(totEff > randNb) 
	incrementTot = kTRUE;
      else
	incrementTot = kFALSE;

      if(useIndivEff){
	recoEff_pT->Fill(incrementReco, onia_Gen_pt);
	// if(onia_Gen_pt > 10. && onia_Gen_pt < 25. && onia_Gen_rap > -2.0 && onia_Gen_rap < 2.0){
	if(onia_Gen_pt > pTMin){
	  recoEff_y->Fill(incrementReco, onia_Gen_rap);
	  recoEff_phi->Fill(incrementReco, onia_Gen_phi);
	}
	recoEff2D_pT_rapNP->Fill(incrementReco, onia_Gen_rap, onia_Gen_pt);
	recoEff2D_pT_rap->Fill(incrementReco, fabs(onia_Gen_rap), onia_Gen_pt);
    
	//      if(incrementReco){ //calculate the trigger efficiency only for events that pass RECO
	trigEff_pT->Fill(incrementTrig, onia_Gen_pt);
	//if(onia_Gen_pt > 10. && onia_Gen_pt < 25. && onia_Gen_rap > -2.0 && onia_Gen_rap < 2.0){
	if(onia_Gen_pt > pTMin){
	  trigEff_y->Fill(incrementTrig, onia_Gen_rap);
	  trigEff_phi->Fill(incrementTrig, onia_Gen_phi);
	}
	trigEff2D_pT_rapNP->Fill(incrementTrig, onia_Gen_rap, onia_Gen_pt);
	trigEff2D_pT_rap->Fill(incrementTrig, fabs(onia_Gen_rap), onia_Gen_pt);
	//}
      }

      totEff_pT->Fill(incrementTot, onia_Gen_pt);

      //if(onia_Gen_pt > 10. && onia_Gen_pt < 25. && onia_Gen_rap > -2.0 && onia_Gen_rap < 2.0){
      if(onia_Gen_pt > pTMin){
	totEff_y->Fill(incrementTot, onia_Gen_rap);
	totEff_phi->Fill(incrementTot, onia_Gen_phi);
      }
      totEff2D_pT_rapNP->Fill(incrementTot, onia_Gen_rap, onia_Gen_pt);
      totEff2D_pT_rap->Fill(incrementTot, fabs(onia_Gen_rap), onia_Gen_pt);
      
      //fill the eff. histos for all the different frames
      for(int iFrame = 0; iFrame < eff::kNbFrames; iFrame++){

	//if(onia_Gen_pt > 10. && onia_Gen_pt < 25. && onia_Gen_rap > -2.0 && onia_Gen_rap < 2.0){
	if(onia_Gen_pt > pTMin){
	  if(useIndivEff){
	    recoEff_cosTheta[iFrame]->Fill(incrementReco, thisCosTh[iFrame]);
	    recoEff_phiPol[iFrame]->Fill(incrementReco, thisPhi[iFrame]);
	    recoEff2D_cosTheta_phiPol[iFrame]->Fill(incrementReco, thisCosTh[iFrame], thisPhi[iFrame]);
	    
	    recoEff_phiPol_pT_rap[iFrame][0][0]->Fill(incrementReco, thisPhi[iFrame]);
	    recoEff_cosTheta_pT_rap[iFrame][0][0]->Fill(incrementReco, thisCosTh[iFrame]);
	  
	    // if(incrementReco){
	    trigEff_cosTheta[iFrame]->Fill(incrementTrig, thisCosTh[iFrame]);
	    trigEff_phiPol[iFrame]->Fill(incrementTrig, thisPhi[iFrame]);
	    trigEff2D_cosTheta_phiPol[iFrame]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
	    
	    trigEff_phiPol_pT_rap[iFrame][0][0]->Fill(incrementTrig, thisPhi[iFrame]);
	    trigEff_cosTheta_pT_rap[iFrame][0][0]->Fill(incrementTrig, thisCosTh[iFrame]);
	    // }
	  }

	  totEff_cosTheta[iFrame]->Fill(incrementTot, thisCosTh[iFrame]);
	  totEff_phiPol[iFrame]->Fill(incrementTot, thisPhi[iFrame]);
	  totEff2D_cosTheta_phiPol[iFrame]->Fill(incrementTot, thisCosTh[iFrame], thisPhi[iFrame]);
	  
	  totEff_phiPol_pT_rap[iFrame][0][0]->Fill(incrementTot, thisPhi[iFrame]);
	  totEff_cosTheta_pT_rap[iFrame][0][0]->Fill(incrementTot, thisCosTh[iFrame]);
	}
	//histos for neg. and pos. rapidity separately:
	if(rapIndex_Gen >= 0){

	  if(useIndivEff){
	    recoEff2D_pol_pT_rapNP[iFrame][0][rapIndex_Gen]->Fill(incrementReco, thisCosTh[iFrame], thisPhi[iFrame]);
	    // if(incrementReco)
	    trigEff2D_pol_pT_rapNP[iFrame][0][rapIndex_Gen]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
	  }
	  totEff2D_pol_pT_rapNP[iFrame][0][rapIndex_Gen]->Fill(incrementTot, thisCosTh[iFrame], thisPhi[iFrame]);
	}
	if(pTIndex_Gen > 0 && rapIndex_Gen >= 0){
	  
	  if(useIndivEff){
	    recoEff2D_pol_pT_rapNP[iFrame][pTIndex_Gen][rapIndex_Gen]->Fill(incrementReco, thisCosTh[iFrame], thisPhi[iFrame]);
	    // if(incrementReco)
	    trigEff2D_pol_pT_rapNP[iFrame][pTIndex_Gen][rapIndex_Gen]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
	  }
	  totEff2D_pol_pT_rapNP[iFrame][pTIndex_Gen][rapIndex_Gen]->Fill(incrementTot, thisCosTh[iFrame], thisPhi[iFrame]);
	}
	
	//histos taking together +y and -y
	if(useIndivEff){
	  recoEff2D_pol_pT_rap[iFrame][0][0]->Fill(incrementReco, thisCosTh[iFrame], thisPhi[iFrame]);
	  // if(incrementReco)
	  trigEff2D_pol_pT_rap[iFrame][0][0]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
	}
	totEff2D_pol_pT_rap[iFrame][0][0]->Fill(incrementTot, thisCosTh[iFrame], thisPhi[iFrame]);
	if(rapIntegratedPTIndex_Gen > 0){
	  if(useIndivEff){
	    recoEff2D_pol_pT_rap[iFrame][rapIntegratedPTIndex_Gen][0]->Fill(incrementReco, thisCosTh[iFrame], thisPhi[iFrame]);
	    // if(incrementReco)
	    trigEff2D_pol_pT_rap[iFrame][rapIntegratedPTIndex_Gen][0]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
	  }
	  totEff2D_pol_pT_rap[iFrame][rapIntegratedPTIndex_Gen][0]->Fill(incrementTot, thisCosTh[iFrame], thisPhi[iFrame]);
	}
	if(rapForPTIndex_Gen > 0){
	  if(useIndivEff){
	    recoEff2D_pol_pT_rap[iFrame][0][rapForPTIndex_Gen]->Fill(incrementReco, thisCosTh[iFrame], thisPhi[iFrame]);
	    // if(incrementReco)
	    trigEff2D_pol_pT_rap[iFrame][0][rapForPTIndex_Gen]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
	  }
	  totEff2D_pol_pT_rap[iFrame][0][rapForPTIndex_Gen]->Fill(incrementTot, thisCosTh[iFrame], thisPhi[iFrame]);
	}
	if(pTIndex_Gen > 0 && rapForPTIndex_Gen > 0){
	  if(useIndivEff){
	    recoEff2D_pol_pT_rap[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementReco, thisCosTh[iFrame], thisPhi[iFrame]);
	    recoEff_phiPol_pT_rap[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementReco, thisPhi[iFrame]);
	    recoEff_cosTheta_pT_rap[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementReco, thisCosTh[iFrame]);
	    
	    // if(incrementReco)
	    trigEff2D_pol_pT_rap[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementTrig, thisCosTh[iFrame], thisPhi[iFrame]);
	    
	    trigEff_phiPol_pT_rap[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementTrig, thisPhi[iFrame]);
	    trigEff_cosTheta_pT_rap[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementTrig, thisCosTh[iFrame]);
	  }
	  totEff2D_pol_pT_rap[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementTot, thisCosTh[iFrame], thisPhi[iFrame]);
	  
	  totEff_phiPol_pT_rap[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementTot, thisPhi[iFrame]);
	  totEff_cosTheta_pT_rap[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementTot, thisCosTh[iFrame]);
	}

	//histos taking together +y and -y and phi 4-folding
	Double_t phiFolded = thisPhi[iFrame];
	Double_t thetaAdjusted = thisCosTh[iFrame];
	if(thisPhi[iFrame] > -90. && thisPhi[iFrame] < 0.)
	  phiFolded *= -1;
	else if(thisPhi[iFrame] > 90 && thisPhi[iFrame] < 180){
	  phiFolded = 180. - thisPhi[iFrame];
	  thetaAdjusted *= -1;
	}
	else if(thisPhi[iFrame] > -180. && thisPhi[iFrame] < -90.){
	  phiFolded = 180. + thisPhi[iFrame];
	  thetaAdjusted *= -1;
	}
	if(useIndivEff){
	  recoEff2D_pol_pT_rap_phiFolded[iFrame][0][0]->Fill(incrementReco, thetaAdjusted, phiFolded);
	  // if(incrementReco)
	  trigEff2D_pol_pT_rap_phiFolded[iFrame][0][0]->Fill(incrementTrig, thetaAdjusted, phiFolded);
	}
	totEff2D_pol_pT_rap_phiFolded[iFrame][0][0]->Fill(incrementTot, thetaAdjusted, phiFolded);
	if(rapIntegratedPTIndex_Gen > 0){
	  if(useIndivEff){
	    recoEff2D_pol_pT_rap_phiFolded[iFrame][rapIntegratedPTIndex_Gen][0]->Fill(incrementReco, thetaAdjusted, phiFolded);
	    // if(incrementReco)
	    trigEff2D_pol_pT_rap_phiFolded[iFrame][rapIntegratedPTIndex_Gen][0]->Fill(incrementTrig, thetaAdjusted, phiFolded);
	  }
	  totEff2D_pol_pT_rap_phiFolded[iFrame][rapIntegratedPTIndex_Gen][0]->Fill(incrementTot, thetaAdjusted, phiFolded);
	}
	if(rapForPTIndex_Gen > 0){
	  if(useIndivEff){
	    recoEff2D_pol_pT_rap_phiFolded[iFrame][0][rapForPTIndex_Gen]->Fill(incrementReco, thetaAdjusted, phiFolded);
	    // if(incrementReco)
	    trigEff2D_pol_pT_rap_phiFolded[iFrame][0][rapForPTIndex_Gen]->Fill(incrementTrig, thetaAdjusted, phiFolded);
	  }
	  totEff2D_pol_pT_rap_phiFolded[iFrame][0][rapForPTIndex_Gen]->Fill(incrementTot, thetaAdjusted, phiFolded);
	}
	if(pTIndex_Gen > 0 && rapForPTIndex_Gen > 0){
	  if(useIndivEff){
	    recoEff2D_pol_pT_rap_phiFolded[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementReco, thetaAdjusted, phiFolded);
	    // if(incrementReco)
	    trigEff2D_pol_pT_rap_phiFolded[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementTrig, thetaAdjusted, phiFolded);
	  }
	  totEff2D_pol_pT_rap_phiFolded[iFrame][pTIndex_Gen][rapForPTIndex_Gen]->Fill(incrementTot, thetaAdjusted, phiFolded);
	} 
      }//frame
    }//useEventNTimes
  }//loop over entries

  printf("nb. of rec. events is %d of a total of %d events\n", (Int_t) countRecEvent, (Int_t) nentries);
}
void DrawEfficiencyCentralitySource(Int_t bincentrality,Int_t source,const char *testfile) {
  
  //
  // source: 0 (charm), 1 (beauty), 2 (gamma), 3 (others)
  // centrality:  from 0 to 100 with 0-5, 5-10, 10-15...
  //
  //

  gStyle->SetPalette(1);
  gStyle->SetOptStat(1111);
  gStyle->SetPadBorderMode(0);
  gStyle->SetCanvasColor(10);
  gStyle->SetPadLeftMargin(0.13);
  gStyle->SetPadRightMargin(0.13);

  ///////////////////////////////////
  // Take the stuff
  //////////////////////////////////


  TList *results = GetResults(testfile,"");
  if(!results){
    printf("No output objects: Calculation will terminate here\n");
    return;
  }

  AliHFEcontainer *containerhfe = (AliHFEcontainer *) results->FindObject("trackContainer");
  if(!containerhfe) {
    printf("No hfe container \n");
    return;
  }

  // 0: pt, 1: eta, 2: phi, 3: charge, 4: source, 5: centrality
  AliCFContainer *sumcontaineresdd = containerhfe->MakeMergedCFContainer("sumesd","sumesd","MCTrackCont:recTrackContReco");
  AliCFContainer *sumcontainermcc = containerhfe->MakeMergedCFContainer("summc","summc","MCTrackCont:recTrackContMC");

  if(!sumcontaineresdd) {
    printf("No container sum esd\n");
    return;
  }

  if(!sumcontainermcc) {
    printf("No container sum mc\n");
    return;
  }

  // 0: pt, 1: eta, 2: phi for a given centrality and source
  //AliCFContainer *sumcontaineresd = GetContainerSourceCentrality(sumcontaineresdd,bincentrality,source);
  //AliCFContainer *sumcontainermc = GetContainerSourceCentrality(sumcontainermcc,bincentrality,source);

  // 0: pt, 1: eta, 2: phi, 3: centrality for a given centrality and source
  AliCFContainer *sumcontaineresd = GetContainerSourceAsFunctionOfCentrality(sumcontaineresdd,source);
  AliCFContainer *sumcontainermc = GetContainerSourceAsFunctionOfCentrality(sumcontainermcc,source);

 

  Int_t nSteps = sumcontaineresd->GetNStep();
  printf("In total %d steps\n",nSteps);

  AliCFDataGrid *dataGrida = (AliCFDataGrid *) GetSpectrum(sumcontaineresdd,nSteps-1);
 
  TH1D *spectrumcentrality = (TH1D *) dataGrida->Project(5);
  TH1D *spectrumpt = (TH1D *) dataGrida->Project(0);
  TH2D *spectrumptc = (TH2D *) dataGrida->Project(5,0);

  TAxis *xaxis = spectrumptc->GetXaxis();
  Int_t bin0 = xaxis->FindBin(0.0);
  Int_t bin5_s = xaxis->FindBin(4.99);
  Int_t bin30 = xaxis->FindBin(30.0);
  Int_t bin40_s = xaxis->FindBin(39.9);
  Int_t bin70 = xaxis->FindBin(70.0);
  Int_t bin80_s = xaxis->FindBin(79.9);

  printf("Bin 0 %d\n",bin0);
  printf("Bin 5 %d\n",bin5_s);
  printf("Bin 30 %d\n",bin30);
  printf("Bin 40 %d\n",bin40_s);
  printf("Bin 70 %d\n",bin70);
  printf("Bin 80 %d\n",bin80_s);
  
  TH1D *spectrumcentrality_0_5 = spectrumptc->ProjectionY("centrality_0_5",bin0,bin5_s);
  TH1D *spectrumcentrality_30_40 = spectrumptc->ProjectionY("centrality_30_40",bin30,bin40_s);
  TH1D *spectrumcentrality_70_80 = spectrumptc->ProjectionY("centrality_70_80",bin70,bin80_s);

  Int_t numberOfEvents = (Int_t) containerhfe->GetNumberOfEvents();
  
  printf("Number of events for a %d after Event cut\n",numberOfEvents);

  ////////////////////////////////
  // Input after ITS&TPC refit
  ///////////////////////////////
  TCanvas * canvascpt = new TCanvas("RawSpectrumCentrality","RawSpectrumCentrality",1000,700);
  canvascpt->Divide(2,1);
  canvascpt->cd(1);
  spectrumpt->SetTitle("");
  spectrumpt->SetStats(0);
  spectrumpt->SetLineColor(kBlue);
  spectrumpt->SetMarkerColor(kBlue);
  spectrumpt->SetMarkerStyle(25);
  //
  spectrumcentrality_0_5->SetTitle("");
  spectrumcentrality_0_5->SetStats(0);
  spectrumcentrality_0_5->SetLineColor(kRed);
  spectrumcentrality_0_5->SetMarkerColor(kRed);
  spectrumcentrality_0_5->SetMarkerStyle(26);
  //
  spectrumcentrality_30_40->SetTitle("");
  spectrumcentrality_30_40->SetStats(0);
  spectrumcentrality_30_40->SetLineColor(kMagenta);
  spectrumcentrality_30_40->SetMarkerColor(kBlack);
  spectrumcentrality_30_40->SetMarkerStyle(27);
  //
  spectrumcentrality_70_80->SetTitle("");
  spectrumcentrality_70_80->SetStats(0);
  spectrumcentrality_70_80->SetLineColor(kBlue);
  spectrumcentrality_70_80->SetMarkerColor(kBlue);
  spectrumcentrality_70_80->SetMarkerStyle(28);
  //
  spectrumpt->Draw();
  spectrumcentrality_0_5->Draw("same");
  spectrumcentrality_30_40->Draw("same");
  spectrumcentrality_70_80->Draw("same");
  TLegend *leg_different_centralities = new TLegend(0.4,0.6,0.89,0.89);
  leg_different_centralities->AddEntry(spectrumpt,"Minimum-bias","p");
  leg_different_centralities->AddEntry(spectrumcentrality_0_5,"0_5","p");
  leg_different_centralities->AddEntry(spectrumcentrality_30_40,"30_40","p");
  leg_different_centralities->AddEntry(spectrumcentrality_70_80,"70_80","p");
  leg_different_centralities->Draw("same");

  canvascpt->cd(2);
  spectrumptc->Draw("colz");
  
  /////////////////////////////////////
  // Take efficiencies
  /////////////////////////////////////
  
  AliCFEffGrid  *efficiencystepkineITSTPC  = (AliCFEffGrid*)  GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecKineITSTPC,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecNoCut);
  AliCFEffGrid  *efficiencystepPrim        = (AliCFEffGrid*)  GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecPrim,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecKineITSTPC);
  AliCFEffGrid  *efficiencystepHFEcutsITS  = (AliCFEffGrid*)  GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsITS,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecPrim);
  AliCFEffGrid  *efficiencystepHFEcutsTRD  = (AliCFEffGrid*)  GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsITS);
  AliCFEffGrid  *efficiencystepPIDTOF      = (AliCFEffGrid*)  GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+1,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD);
  AliCFEffGrid  *efficiencystepPIDTPC      = (AliCFEffGrid*)  GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+1);

  AliCFEffGrid  *efficiencystepPIDall      = (AliCFEffGrid*)  GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD);

  AliCFEffGrid  *efficiencystepall      = (AliCFEffGrid*)  GetEfficiency(sumcontaineresd,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecNoCut);

  //

  AliCFEffGrid  *efficiencystepMCkineITSTPC  = (AliCFEffGrid*)  GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecKineITSTPC,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecNoCut);
  AliCFEffGrid  *efficiencystepMCPrim        = (AliCFEffGrid*)  GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecPrim,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecKineITSTPC);
  AliCFEffGrid  *efficiencystepMCHFEcutsITS  = (AliCFEffGrid*)  GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsITS,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepRecPrim);
  AliCFEffGrid  *efficiencystepMCHFEcutsTRD  = (AliCFEffGrid*)  GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsITS);
  AliCFEffGrid  *efficiencystepMCPIDTOF      = (AliCFEffGrid*)  GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+1,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD);
  AliCFEffGrid  *efficiencystepMCPIDTPC      = (AliCFEffGrid*)  GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+1);

  AliCFEffGrid  *efficiencystepMCPIDall      = (AliCFEffGrid*)  GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD);

  AliCFEffGrid  *efficiencystepMCall      = (AliCFEffGrid*)  GetEfficiency(sumcontainermc,AliHFEcuts::kNcutStepsMCTrack+AliHFEcuts::kStepHFEcutsTRD+2,0);

  
  ///////////////////////////////////////
  // Plot 1D
  ///////////////////////////////////////

  /////////////////////
  // Different cuts
  /////////////////////
  TCanvas * canvascomparison = new TCanvas("ITSTPCrefitStepESD","ITSTPCrefitStepESD",1000,700);
  canvascomparison->Divide(2,2);
 
  canvascomparison->cd(1);
  TH2D* h_effsteponlykineITSTPC1Donly = (TH2D *) efficiencystepkineITSTPC->Project(0,3);
  h_effsteponlykineITSTPC1Donly->SetTitle("");
  h_effsteponlykineITSTPC1Donly->SetStats(0);
  h_effsteponlykineITSTPC1Donly->SetLineColor(kBlue);
  h_effsteponlykineITSTPC1Donly->SetMarkerColor(kBlue);
  h_effsteponlykineITSTPC1Donly->SetMarkerStyle(25);
  h_effsteponlykineITSTPC1Donly->Draw("colz");
   
  canvascomparison->cd(2);
  TH2D* h_effsteponlyPrim1Donly =( TH2D *) efficiencystepPrim->Project(0,3);
  h_effsteponlyPrim1Donly->SetTitle("");
  h_effsteponlyPrim1Donly->SetStats(0);
  h_effsteponlyPrim1Donly->SetLineColor(kBlue);
  h_effsteponlyPrim1Donly->SetMarkerColor(kBlue);
  h_effsteponlyPrim1Donly->SetMarkerStyle(25);
  h_effsteponlyPrim1Donly->Draw("colz");

  
  canvascomparison->cd(3);
  TH2D* h_effsteponlyHFEcutsITS1Donly = (TH2D *) efficiencystepHFEcutsITS->Project(0,3);
  h_effsteponlyHFEcutsITS1Donly->SetTitle("");
  h_effsteponlyHFEcutsITS1Donly->SetStats(0);
  h_effsteponlyHFEcutsITS1Donly->SetLineColor(kBlue);
  h_effsteponlyHFEcutsITS1Donly->SetMarkerColor(kBlue);
  h_effsteponlyHFEcutsITS1Donly->SetMarkerStyle(25);
  h_effsteponlyHFEcutsITS1Donly->Draw("colz");
 
  
  canvascomparison->cd(4);
  TH2D* h_effsteponlyPID1Donly = (TH2D *) efficiencystepHFEcutsTRD->Project(0,3);
  h_effsteponlyPID1Donly->SetTitle("");
  h_effsteponlyPID1Donly->SetStats(0);
  h_effsteponlyPID1Donly->SetLineColor(kBlue);
  h_effsteponlyPID1Donly->SetMarkerColor(kBlue);
  h_effsteponlyPID1Donly->SetMarkerStyle(25);
  h_effsteponlyPID1Donly->Draw("colz");
 

  /////////////////////
  // Different cuts
  /////////////////////
  TCanvas * canvascomparisonbis = new TCanvas("ITSTPCrefitStepMC","ITSTPCrefitStepMC",1000,700);
  canvascomparisonbis->Divide(2,2);
 
  canvascomparisonbis->cd(1);
  TH2D* h_effstepMCkineITSTPC1Donly =  (TH2D *)efficiencystepMCkineITSTPC->Project(0,3);
  h_effstepMCkineITSTPC1Donly->SetTitle("");
  h_effstepMCkineITSTPC1Donly->SetStats(0);
  h_effstepMCkineITSTPC1Donly->SetLineColor(kBlue);
  h_effstepMCkineITSTPC1Donly->SetMarkerColor(kBlue);
  h_effstepMCkineITSTPC1Donly->SetMarkerStyle(25);
  h_effstepMCkineITSTPC1Donly->Draw("colz");
  

  canvascomparisonbis->cd(2);
  TH2D* h_effstepMCPrim1Donly = (TH2D *) efficiencystepMCPrim->Project(0,3);
  h_effstepMCPrim1Donly->SetTitle("");
  h_effstepMCPrim1Donly->SetStats(0);
  h_effstepMCPrim1Donly->SetLineColor(kBlue);
  h_effstepMCPrim1Donly->SetMarkerColor(kBlue);
  h_effstepMCPrim1Donly->SetMarkerStyle(25);
  h_effstepMCPrim1Donly->Draw("colz");
  
  canvascomparisonbis->cd(3);
  TH2D* h_effstepMCHFEcutsITS1Donly = (TH2D *) efficiencystepMCHFEcutsITS->Project(0,3);
  h_effstepMCHFEcutsITS1Donly->SetTitle("");
  h_effstepMCHFEcutsITS1Donly->SetStats(0);
  h_effstepMCHFEcutsITS1Donly->SetLineColor(kBlue);
  h_effstepMCHFEcutsITS1Donly->SetMarkerColor(kBlue);
  h_effstepMCHFEcutsITS1Donly->SetMarkerStyle(25);
  h_effstepMCHFEcutsITS1Donly->Draw("colz");
  
  canvascomparisonbis->cd(4);
  TH2D* h_effstepMCPID1Donly = (TH2D *) efficiencystepMCHFEcutsTRD->Project(0,3);
  h_effstepMCPID1Donly->SetTitle("");
  h_effstepMCPID1Donly->SetStats(0);
  h_effstepMCPID1Donly->SetLineColor(kBlue);
  h_effstepMCPID1Donly->SetMarkerColor(kBlue);
  h_effstepMCPID1Donly->SetMarkerStyle(25);
  h_effstepMCPID1Donly->Draw("colz");
  

  ///////////
  // PID
  ///////////
  TCanvas * canvasc1Don = new TCanvas("PIDstepESD","PIDstepESD",1000,700);
  canvasc1Don->Divide(3,1);
  
  canvasc1Don->cd(1);
  TH2D* h_effstepPID1Donly = (TH2D *) efficiencystepPIDTOF->Project(0,3);
  h_effstepPID1Donly->SetTitle("");
  h_effstepPID1Donly->SetStats(0);
  h_effstepPID1Donly->SetLineColor(kBlue);
  h_effstepPID1Donly->SetMarkerColor(kBlue);
  h_effstepPID1Donly->SetMarkerStyle(25);
  gPad->SetLogz();
  h_effstepPID1Donly->Draw("colz");
  
  canvasc1Don->cd(2);
  TH2D* h_effstepPID1Donlyy = (TH2D *) efficiencystepPIDTPC->Project(0,3);
  h_effstepPID1Donlyy->SetTitle("");
  h_effstepPID1Donlyy->SetStats(0);
  h_effstepPID1Donlyy->SetLineColor(kBlue);
  h_effstepPID1Donlyy->SetMarkerColor(kBlue);
  h_effstepPID1Donlyy->SetMarkerStyle(25);
  gPad->SetLogz();
  h_effstepPID1Donlyy->Draw("colz");
  
  canvasc1Don->cd(3);
  TH2D* h_effstepPID1Donlyyy = (TH2D *) efficiencystepPIDall->Project(0,3);
  h_effstepPID1Donlyyy->SetTitle("");
  h_effstepPID1Donlyyy->SetStats(0);
  h_effstepPID1Donlyyy->SetLineColor(kBlue);
  h_effstepPID1Donlyyy->SetMarkerColor(kBlue);
  h_effstepPID1Donlyyy->SetMarkerStyle(25);
  gPad->SetLogz();
  h_effstepPID1Donlyyy->Draw("colz");
  
  //

  TCanvas * canvasc1DonMC = new TCanvas("PIDstepMC","PIDstepMC",1000,700);
  canvasc1DonMC->Divide(3,1);
  
  canvasc1DonMC->cd(1);
  TH2D* h_effstepPID1DMConly = (TH2D *) efficiencystepMCPIDTOF->Project(0,3);
  h_effstepPID1DMConly->SetTitle("");
  h_effstepPID1DMConly->SetStats(0);
 
  h_effstepPID1DMConly->SetLineColor(kBlue);
 
  h_effstepPID1DMConly->SetMarkerColor(kBlue);
 
  h_effstepPID1DMConly->SetMarkerStyle(25);
  gPad->SetLogz(); 
  h_effstepPID1DMConly->Draw("colz");
 

  canvasc1DonMC->cd(2);
  TH2D* h_effstepPID1DMConlyy = (TH2D *) efficiencystepMCPIDTPC->Project(0,3);
  h_effstepPID1DMConlyy->SetTitle("");
  h_effstepPID1DMConlyy->SetStats(0);
  h_effstepPID1DMConlyy->SetLineColor(kBlue);
  h_effstepPID1DMConlyy->SetMarkerColor(kBlue);
  h_effstepPID1DMConlyy->SetMarkerStyle(25);
  gPad->SetLogz();
  h_effstepPID1DMConlyy->Draw("colz");
 

  canvasc1DonMC->cd(3);
  TH2D* h_effstepPID1DMConlyyy = (TH2D *) efficiencystepMCPIDall->Project(0,3);
  h_effstepPID1DMConlyyy->SetTitle("");
  h_effstepPID1DMConlyyy->SetStats(0);
  h_effstepPID1DMConlyyy->SetLineColor(kBlue);
  h_effstepPID1DMConlyyy->SetMarkerColor(kBlue);
  h_effstepPID1DMConlyyy->SetMarkerStyle(25);
  gPad->SetLogz();
  h_effstepPID1DMConlyyy->Draw("colz");


  //////////
  // all
  //////////

  TCanvas * canvasall = new TCanvas("AllMC","AllMC",1000,700);
  //canvasall->Divide(2,1);

  canvasall->cd(1);
  TH2D* h_effstepPID1Dall = (TH2D *) efficiencystepMCall->Project(0,3);
  h_effstepPID1Dall->SetTitle("");
  h_effstepPID1Dall->SetStats(0);
  h_effstepPID1Dall->SetLineColor(kBlue);
  h_effstepPID1Dall->SetMarkerColor(kBlue);
  h_effstepPID1Dall->SetMarkerStyle(25);
  gPad->SetLogz();
  h_effstepPID1Dall->Draw("colz");

  
 


}