#include "DSelector_Cm1Star.h"

void DSelector_Cm1Star::Init(TTree *locTree)
{

	dOutputFileName = "Cm1Star.root"; 
	dOutputTreeFileName = ""; 
	dFlatTreeFileName = ""; 
	dFlatTreeName = ""; 
	bool locInitializedPriorFlag = dInitializedFlag; 
	DSelector::Init(locTree); 
	if(locInitializedPriorFlag)
		return; 

	Get_ComboWrappers();
	dPreviousRunNumber = 0;

	/*********************************** EXAMPLE USER INITIALIZATION: ANALYSIS ACTIONS **********************************/

	// EXAMPLE: Create deque for histogramming particle masses:
	// // For histogramming the phi mass in phi -> K+ K-
	// // Be sure to change this and dAnalyzeCutActions to match reaction
	std::deque<Particle_t> MyPhi;

	MyPhi.push_back(KPlus); MyPhi.push_back(KMinus);

	//ANALYSIS ACTIONS: //Executed in order if added to dAnalysisActions
	//false/true below: use measured/kinfit data

	//PID
	dAnalysisActions.push_back(new DHistogramAction_ParticleID(dComboWrapper, false));
	//below: value: +/- N ns, Unknown: All PIDs, SYS_NULL: all timing systems
	//dAnalysisActions.push_back(new DCutAction_PIDDeltaT(dComboWrapper, false, 0.5, KPlus, SYS_BCAL));

	//MASSES
	//dAnalysisActions.push_back(new DHistogramAction_InvariantMass(dComboWrapper, false, Lambda, 1000, 1.0, 1.2, "Lambda"));
	//dAnalysisActions.push_back(new DHistogramAction_MissingMassSquared(dComboWrapper, false, 1000, -0.1, 0.1));

	//KINFIT RESULTS
	dAnalysisActions.push_back(new DHistogramAction_KinFitResults(dComboWrapper));
	//cout<<"test:1"<<endl;
	//CUT MISSING MASS
	//dAnalysisActions.push_back(new DCutAction_MissingMassSquared(dComboWrapper, false, -0.03, 0.02));

	//BEAM ENERGY
	dAnalysisActions.push_back(new DHistogramAction_BeamEnergy(dComboWrapper, false));
	//dAnalysisActions.push_back(new DCutAction_BeamEnergy(dComboWrapper, false, 8.4, 9.05));

	//KINEMATICS
	dAnalysisActions.push_back(new DHistogramAction_ParticleComboKinematics(dComboWrapper, false));

	// ANALYZE CUT ACTIONS
	// // Change MyPhi to match reaction
	dAnalyzeCutActions = new DHistogramAction_AnalyzeCutActions( dAnalysisActions, dComboWrapper, false, 0, MyPhi, 1000, 0.9, 2.4, "CutActionEffect" );

	//INITIALIZE ACTIONS
	//If you create any actions that you want to run manually (i.e. don't add to dAnalysisActions), be sure to initialize them here as well
	Initialize_Actions();
	dAnalyzeCutActions->Initialize(); // manual action, must call Initialize()

	/******************************** EXAMPLE USER INITIALIZATION: STAND-ALONE HISTOGRAMS *******************************/

	//EXAMPLE MANUAL HISTOGRAMS:
	dHist_MissingMassSquared = new TH1I("MissingMassSquared", ";Missing Mass Squared (GeV/c^{2})^{2}", 600, -0.06, 0.06);
	dHist_BeamEnergy = new TH1I("BeamEnergy", ";Beam Energy (GeV)", 600, 0.0, 12.0);
 
	//ASDF - histo define
	int nBinsX = 100;
	int nBinsY = 100;
	double xLow = 0.0, xHigh = 10.0;
	double yLow = 0.0, yHigh = 10.0;
	hXiMinus  = new TH1D("hXiMinus","",150,1.2,1.5);//200 bins from 1.0 to 2.0
	hTmp2d  = new TH2D("hTmp2d","",nBinsX,xLow,xHigh,nBinsY,yLow,yHigh);//100 bins from 0.0 to 1.0

	hXiStar  = new TH1D("hXiStar","",500,1.0,3.5);//100 bins from 0.0 to 1.0
	hXiMinusvsCl = new TH2D("hXiMinusvsCl","",300,0.0,1.0,500,0.0,2.0);//100 bins from 0.0 to 1.0
	hXiStarvsCl  = new TH2D("hXiStarvsCl","",300,0.0,1.0,500,1.0,3.0);//100 bins from 0.0 to 1.0
	hPvsBeta = new TH2D("hPvsBeta","",100,0.0,12.0,100,0.0,1.0);
	hPK1vsBeta = new TH2D("hPK1vsBeta","",100,0.0,12.0,100,0.0,1.1);
	hPK2vsBeta = new TH2D("hPK2vsBeta","",100,0.0,12.0,100,0.0,1.1);
	hPK1vsBeta_M = new TH2D("hPK1vsBeta_M","",100,0.0,12.0,100,0.0,1.1);
	hPK2vsBeta_M = new TH2D("hPK2vsBeta_M","",100,0.0,12.0,100,0.0,1.1);
	hPPimvsBeta_M_CL = new TH2D("hPPimvsBeta_M_CL","",100,0.0,12.0,100,0.0,1.1);
	hPK1vsBeta_M_CL = new TH2D("hPK1vsBeta_M_CL","",100,0.0,12.0,100,0.0,1.1);
	hPK2vsBeta_M_CL = new TH2D("hPK2vsBeta_M_CL","",100,0.0,12.0,100,0.0,1.1);
	
	hCasvsBeta_M = new TH2D("hCasvsBeta_M","",100,0.0,12.0,100,0.0,1.1);
       	hCasvsBeta_M_CL = new TH2D("hCasvsBeta_M_CL","",100,0.0,12.0,100,0.0,1.1);
	hCascade_CL =new TH1D("hCascade_CL","",500,1.25,1.55);
	hCascadeStar_CL =new TH1D("hCascadeStar_CL","",550,1.3,3.5);

	hCasMass_BCAL =new TH1D("hCasMass_BCAL","",500,1.25,1.55); 
	hCasStarMass_BCAL =new TH1D("hCasStarMass_BCAL","",1000,1.3,3.5);
	hPPimvsBeta_BCAL = new TH2D("hPPimvsBeta_BCAL","",1000,0.0,10.0,500,0.0,1.1);
	hPK1vsBeta_BCAL = new TH2D("hPK1vsBeta_BCAL","",1000,0.0,10.0,500,0.0,1.1);
	hPK2vsBeta_BCAL = new TH2D("hPK2vsBeta_BCAL","",1000,0.0,10.0,500,0.0,1.1);
	hPProtonvsBeta_BCAL= new TH2D("hPProtonvsBeta_BCAL","",1000,0.0,10.0,500,0.0,1.1);

	hCasMass_ST =new TH1D("hCasMass_ST","",500,1.25,1.55);
	hCasStarMass_ST =new TH1D("hCasStarMass_ST","",550,1.3,3.5);
	hPPimvsBeta_ST = new TH2D("hPPimvsBeta_ST","",500,0.0,10.0,500,0.0,1.1);
	hPK1vsBeta_ST = new TH2D("hPK1vsBeta_ST","",1000,0.0,10.0,500,0.0,1.1);
	hPK2vsBeta_ST = new TH2D("hPK2vsBeta_ST","",1000,0.0,10.0,500,0.0,1.1);
	hPProtonvsBeta_ST= new TH2D("hPProtonvsBeta_ST","",1000,0.0,10.0,500,0.0,1.1);
	
	hCasMass_TOF =new TH1D("hCasMass_TOF","",500,1.25,1.55);
	hCasStarMass_TOF =new TH1D("hCasStarMass_TOF","",1000,1.3,3.5);
	hPPimvsBeta_TOF = new TH2D("hPPimvsBeta_TOF","",1000,0.0,10.0,500,0.0,1.1);
	hPK1vsBeta_TOF = new TH2D("hPK1vsBeta_TOF","",1000,0.0,10.0,1000,0.0,1.1);
	hPK2vsBeta_TOF = new TH2D("hPK2vsBeta_TOF","",1000,0.0,10.0,1000,0.0,1.1);
	hPProtonvsBeta_TOF= new TH2D("hPProtonvsBeta_TOF","",1000,0.0,10.0,500,0.0,1.1);	

	hCasMass_FCAL =new TH1D("hCasMass_FCAL","",500,1.25,1.55);
	hCasStarMass_FCAL =new TH1D("hCasStarMass_FCAL","",1000,1.3,3.5);
	hPPimvsBeta_FCAL = new TH2D("hPPimvsBeta_FCAL","",1000,0.0,10.0,500,0.0,1.1);
	hPK1vsBeta_FCAL = new TH2D("hPK1vsBeta_FCAL","",1000,0.0,10.0,500,0.0,1.1);
	hPK2vsBeta_FCAL = new TH2D("hPK2vsBeta_FCAL","",1000,0.0,10.0,500,0.0,1.1);
	hPProtonvsBeta_FCAL= new TH2D("hPProtonvsBeta_FCAL","",1000,0.0,10.0,500,0.0,1.1);	

	hCasMass_NULL =new TH1D("hCasMass_NULL","",500,1.25,1.55);
	hCasStarMass_NULL =new TH1D("hCasStarMass_NULL","",1000,1.3,3.5);
	hPPimvsBeta_NULL = new TH2D("hPPimvsBeta_NULL","",1000,0.0,10.0,500,0.0,1.1);
	hPK1vsBeta_NULL = new TH2D("hPK1vsBeta_NULL","",1000,0.0,10.0,500,0.0,1.1);
	hPK2vsBeta_NULL = new TH2D("hPK2vsBeta_NULL","",1000,0.0,10.0,500,0.0,1.1);
	hPProtonvsBeta_NULL= new TH2D("hPProtonvsBeta_NULL","",1000,0.0,10.0,500,0.0,1.1);

	hCasMass_CL_D =new TH1D("hCasMass_CL_D","",500,1.25,1.55);
	hCasStarMass_CL_D =new TH1D("hCasStarMass_CL_D","",1000,1.3,3.5);
	hPPimvsBeta_CL_D = new TH2D("hPPimvsBeta_CL_D","",1000,0.0,10.0,500,0.0,1.1);
	hPK1vsBeta_CL_D = new TH2D("hPK1vsBeta_CL_D","",1000,0.0,10.0,500,0.0,1.1);
	hPK2vsBeta_CL_D = new TH2D("hPK2vsBeta_CL_D","",1000,0.0,10.0,500,0.0,1.1);
	
	hCasMassvsBeta = new TH2D("hCasMassvsBeta","",500,1.25,1.55,1000,0.0,10.0);
	hCasMassvsP = new TH2D("hCasMassvsP","",600,1.1,2.4,1000,0.0,10.0);
	hCasMassvsBeta_CL = new TH2D("hCasMassvsBeta_CL","",500,0.0,1.2,500,0.0,3.0);
	hCasMassvsP_CL =  new TH2D("hCasMassvsP_CL","",600,1.0,2.4,1000,0.0,10.0);


	hCasMass_CL_D_B     =new TH1D("hCasMass_CL_D_B","",500,1.25,1.5);
	hCasStarMass_CL_D_B =new TH1D("hCasStarMass_CL_D_B","",1000,1.3,3.5);
	hPPimvsBeta_CL_D_B  =new TH2D("hPPimvsBeta_CL_D_B","",500,0.0,3.0,500,0.0,1.1);
	hPK1vsBeta_CL_D_B   =new TH2D("hPK1vsBeta_CL_D_B","",1000,0.0,10.0,500,0.0,1.1);
	hPK2vsBeta_CL_D_B   =new TH2D("hPK2vsBeta_CL_D_B","",1000,0.0,10.0,500,0.0,1.1);
	  
	hCasvsCasStar_CL    =new TH2D("hCasvsCasStar_CL","",1000,1.24,1.5,1500,1.4,3.5);
	hCasvsCasStar_CL_D  =new TH2D("hCasvsCasStar_CL_D","",1000,1.24,1.5,1500,1.4,3.5);

	hCasStar_MC     = new TH1D("hCasStar_MC","",1000,1.4,2.8);
	hCasStar_MC_Kin = new TH1D("hCasStar_MC_Kin","",1000,1.4,2.8);

	hCasStarVsK1Star = new TH2D("hCasStarVsK1Star","",200,0.6,2.6,1000,1.4,2.8);
	hCasStarVsK2Star = new TH2D("hCasStarVsK2Star","",200,0.6,2.6,1000,1.4,2.8);
	hCasStarVsK1BStar = new TH2D("hCasStarVsK1BStar","",200,0.6,2.6,1000,1.4,2.8);
	hCasStarVsK2BStar = new TH2D("hCasStarVsK2BStar","",200,0.6,2.6,1000,1.4,2.8);

        hCasStarKCut = new TH1D("hCasStarKCut","",1000,1.4,2.8);
        hCasStarKCutB = new TH1D("hCasStarKCutB","",1000,1.4,2.8);

	hCasStar_MC_Kin_1 = new TH1D("hCasStar_MC_Kin_1","",1000,1.4,2.8);
	hCasStar_MC_Kin_2 = new TH1D("hCasStar_MC_Kin_2","",1000,1.4,2.8);
	hCasStar_MC_Kin_3 = new TH1D("hCasStar_MC_Kin_3","",1000,1.4,2.8);
	hCasStar_MC_Kin_4 = new TH1D("hCasStar_MC_Kin_4","",1000,1.4,2.8);
	hCasStar_MC_Kin_4B = new TH1D("hCasStar_MC_Kin_4B","",1000,1.4,2.8);
	hCasStar_MC_Kin_5 = new TH1D("hCasStar_MC_Kin_5","",1000,1.4,2.8);
	hCasStar_MC_Kin_6 = new TH1D("hCasStar_MC_Kin_6","",1000,1.4,2.8);
	hCasStar_MC_Kin_7 = new TH1D("hCasStar_MC_Kin_7","",1000,1.4,2.8);
	hCasStar_MC_Kin_8 = new TH1D("hCasStar_MC_Kin_8","",1000,1.4,2.8);
	hCasStar_MC_Kin_9 = new TH1D("hCasStar_MC_Kin_9","",1000,1.4,2.8);
	hCasStar_MC_Kin_10 = new TH1D("hCasStar_MC_Kin_10","",1000,1.4,2.8);
	hCasStar_MC_Kin_11 = new TH1D("hCasStar_MC_Kin_11","",1000,1.4,2.8);
	hCasStar_MC_Kin_12 = new TH1D("hCasStar_MC_Kin_12","",1000,1.4,2.8);
	hCasStar_MC_Kin_13 = new TH1D("hCasStar_MC_Kin_13","",1000,1.4,2.8);
	hCasStar_MC_Kin_14 = new TH1D("hCasStar_MC_Kin_14","",1000,1.4,2.8);
	hCasStar_MC_Kin_15 = new TH1D("hCasStar_MC_Kin_15","",1000,1.4,2.8);
	hCasStar_MC_Kin_16 = new TH1D("hCasStar_MC_Kin_16","",1000,1.4,2.8);
	hCasStar_MC_Kin_17 = new TH1D("hCasStar_MC_Kin_17","",1000,1.4,2.8);
	hCasStar_MC_Kin_18 = new TH1D("hCasStar_MC_Kin_18","",1000,1.4,2.8);
	hCasStar_MC_Kin_19 = new TH1D("hCasStar_MC_Kin_19","",1000,1.4,2.8);
	hCasStar_MC_Kin_20 = new TH1D("hCasStar_MC_Kin_20","",1000,1.4,2.8);
 
	hCosThetaHzVsCasStar_MC_Kin_4K = new TH2D("hCosThetaHzVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaHzVsCasStar_MC_Kin_4KB = new TH2D("hCosThetaHzVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaHzVsCasStar_MC_Kin_4 = new TH2D("hCosThetaHzVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-1.0,1.0);

	hCosThetaHxVsCasStar_MC_Kin_4K = new TH2D("hCosThetaHxVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaHxVsCasStar_MC_Kin_4KB = new TH2D("hCosThetaHxVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaHxVsCasStar_MC_Kin_4 = new TH2D("hCosThetaHxVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-1.0,1.0);

	hCosThetaHyVsCasStar_MC_Kin_4K = new TH2D("hCosThetaHyVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaHyVsCasStar_MC_Kin_4KB = new TH2D("hCosThetaHyVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaHyVsCasStar_MC_Kin_4 = new TH2D("hCosThetaHyVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-1.0,1.0);
	///
	hCosThetaGJzVsCasStar_MC_Kin_4K = new TH2D("hCosThetaGJzVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaGJzVsCasStar_MC_Kin_4KB = new TH2D("hCosThetaGJzVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaGJzVsCasStar_MC_Kin_4 = new TH2D("hCosThetaGJzVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-1.0,1.0);

	hCosThetaGJxVsCasStar_MC_Kin_4K = new TH2D("hCosThetaGJxVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaGJxVsCasStar_MC_Kin_4KB = new TH2D("hCosThetaGJxVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaGJxVsCasStar_MC_Kin_4 = new TH2D("hCosThetaGJxVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-1.0,1.0);

	hCosThetaGJyVsCasStar_MC_Kin_4K = new TH2D("hCosThetaGJyVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaGJyVsCasStar_MC_Kin_4KB = new TH2D("hCosThetaGJyVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-1.0,1.0);
	hCosThetaGJyVsCasStar_MC_Kin_4 = new TH2D("hCosThetaGJyVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-1.0,1.0);
	///
	hPhiHzVsCasStar_MC_Kin_4K = new TH2D("hPhiHzVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-180.0,180.0);
	hPhiHzVsCasStar_MC_Kin_4KB = new TH2D("hPhiHzVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-180.0,180.0);
	hPhiHzVsCasStar_MC_Kin_4 = new TH2D("hPhiHzVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-180.0,180.0);

	hPhiHxVsCasStar_MC_Kin_4K = new TH2D("hPhiHxVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-180.0,180.0);
	hPhiHxVsCasStar_MC_Kin_4KB = new TH2D("hPhiHxVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-180.0,180.0);
	hPhiHxVsCasStar_MC_Kin_4 = new TH2D("hPhiHxVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-180.0,180.0);

	hPhiHyVsCasStar_MC_Kin_4K = new TH2D("hPhiHyVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-180.0,180.0);
	hPhiHyVsCasStar_MC_Kin_4KB = new TH2D("hPhiHyVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-180.0,180.0);
	hPhiHyVsCasStar_MC_Kin_4 = new TH2D("hPhiHyVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-180.0,180.0);
	///
	hPhiGJzVsCasStar_MC_Kin_4K = new TH2D("hPhiGJzVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-180.0,180.0);
	hPhiGJzVsCasStar_MC_Kin_4KB = new TH2D("hPhiGJzVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-180.0,180.0);
	hPhiGJzVsCasStar_MC_Kin_4 = new TH2D("hPhiGJzVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-180.0,180.0);

	hPhiGJxVsCasStar_MC_Kin_4K = new TH2D("hPhiGJxVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-180.0,180.0);
	hPhiGJxVsCasStar_MC_Kin_4KB = new TH2D("hPhiGJxVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-180.0,180.0);
	hPhiGJxVsCasStar_MC_Kin_4 = new TH2D("hPhiGJxVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-180.0,180.0);

	hPhiGJyVsCasStar_MC_Kin_4K = new TH2D("hPhiGJyVsCasStar_MC_Kin_4K","",140,1.4,2.8,20,-180.0,180.0);
	hPhiGJyVsCasStar_MC_Kin_4KB = new TH2D("hPhiGJyVsCasStar_MC_Kin_4KB","",140,1.4,2.8,20,-180.0,180.0);
	hPhiGJyVsCasStar_MC_Kin_4 = new TH2D("hPhiGJyVsCasStar_MC_Kin_4","",140,1.4,2.8,20,-180.0,180.0);
	//
	

	hCasStarVsCas_MC_Kin_1 = new TH2D("hCasStarVsCas_MC_Kin_1","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_2 = new TH2D("hCasStarVsCas_MC_Kin_2","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_3 = new TH2D("hCasStarVsCas_MC_Kin_3","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_4 = new TH2D("hCasStarVsCas_MC_Kin_4","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_4KCut = new TH2D("hCasStarVsCas_MC_Kin_4KCut","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_4B = new TH2D("hCasStarVsCas_MC_Kin_4B","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_4T = new TH2D("hCasStarVsCas_MC_Kin_4T","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_5 = new TH2D("hCasStarVsCas_MC_Kin_5","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_6 = new TH2D("hCasStarVsCas_MC_Kin_6","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_7 = new TH2D("hCasStarVsCas_MC_Kin_7","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_8 = new TH2D("hCasStarVsCas_MC_Kin_8","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_9 = new TH2D("hCasStarVsCas_MC_Kin_9","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_10 = new TH2D("hCasStarVsCas_MC_Kin_10","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_11 = new TH2D("hCasStarVsCas_MC_Kin_11","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_12 = new TH2D("hCasStarVsCas_MC_Kin_12","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_13 = new TH2D("hCasStarVsCas_MC_Kin_13","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_14 = new TH2D("hCasStarVsCas_MC_Kin_14","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_15 = new TH2D("hCasStarVsCas_MC_Kin_15","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_16 = new TH2D("hCasStarVsCas_MC_Kin_16","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_17 = new TH2D("hCasStarVsCas_MC_Kin_17","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_18 = new TH2D("hCasStarVsCas_MC_Kin_18","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_19 = new TH2D("hCasStarVsCas_MC_Kin_19","",140,1.4,2.8,150,1.2,1.5);
	hCasStarVsCas_MC_Kin_20 = new TH2D("hCasStarVsCas_MC_Kin_20","",140,1.4,2.8,150,1.2,1.5);


	hPion_Kin      = new TH1D("hPion_Kin","",1000,1.4,2.8);
	hPion_M        = new TH1D("hPion_M","",500,0.0,0.2);
	hXiMinus_Kin   = new TH1D("hXiMinus_Kin","",1000,1.0,2.0);
	hXiMinus_MS    = new TH1D("hXiMinus_MS","",1000,1.0,2.0);

	hPiMinusMom   = new TH1D("hPiMinusMom","",500,0.9,1.1);
	hK1PlusMom    = new TH1D("hK1PlusMom","",500,0.9,1.1);
	hK2PlusMom    = new TH1D("hK2PlusMom","",500,0.9,1.1); 
	hPKvsCasStar  = new TH2D("hPKvsCasStar","",500,1.4,2.8,1000,0.0,9.0);
	hPKvsCasStar_MC  = new TH2D("hPKvsCasStar_MC","",500,1.4,2.8,1000,0.0,9.0);
	hGoodMass = new TH1D("hGoodMass", "",1000,1.4,2.8);

	hCasStar_MC_Kin_7100  = new TH1D("hCasStar_MC_Kin_7100","",250,1.4,2.8);
	hCasStar_MC_Kin_7300  = new TH1D("hCasStar_MC_Kin_7300","",250,1.4,2.8);
	hCasStar_MC_Kin_7500  = new TH1D("hCasStar_MC_Kin_7500","",250,1.4,2.8);
	hCasStar_MC_Kin_7700  = new TH1D("hCasStar_MC_Kin_7700","",250,1.4,2.8);
	hCasStar_MC_Kin_7900  = new TH1D("hCasStar_MC_Kin_7900","",250,1.4,2.8);
	hCasStar_MC_Kin_8100  = new TH1D("hCasStar_MC_Kin_8100","",250,1.4,2.8);
	hCasStar_MC_Kin_8300  = new TH1D("hCasStar_MC_Kin_8300","",250,1.4,2.8);
	hCasStar_MC_Kin_8500  = new TH1D("hCasStar_MC_Kin_8500","",250,1.4,2.8);
	hCasStar_MC_Kin_8700  = new TH1D("hCasStar_MC_Kin_8700","",250,1.4,2.8);
	hCasStar_MC_Kin_8900  = new TH1D("hCasStar_MC_Kin_8900","",250,1.4,2.8);
	hCasStar_MC_Kin_9100  = new TH1D("hCasStar_MC_Kin_9100","",250,1.4,2.8);
	hCasStar_MC_Kin_9300  = new TH1D("hCasStar_MC_Kin_9300","",250,1.4,2.8);
	hCasStar_MC_Kin_9500  = new TH1D("hCasStar_MC_Kin_9500","",250,1.4,2.8);
	hCasStar_MC_Kin_9700  = new TH1D("hCasStar_MC_Kin_9700","",250,1.4,2.8);
	hCasStar_MC_Kin_9900  = new TH1D("hCasStar_MC_Kin_9900","",250,1.4,2.8);
	hCasStar_MC_Kin_10100 = new TH1D("hCasStar_MC_Kin_10100","",250,1.4,2.8);
	hCasStar_MC_Kin_10300 = new TH1D("hCasStar_MC_Kin_10300","",250,1.4,2.8);
	hCasStar_MC_Kin_10500 = new TH1D("hCasStar_MC_Kin_10500","",250,1.4,2.8);
	hCasStar_MC_Kin_10700 = new TH1D("hCasStar_MC_Kin_10700","",250,1.4,2.8);
	hCasStar_MC_Kin_10900 = new TH1D("hCasStar_MC_Kin_10900","",250,1.4,2.8);

	hAccidentals = new TH1D("hAccidentals", "", 1000,-20.0,20.0);

	hRawTchan = new TH1D("hRawTchan", "",1500,0.0,12.0);
	hTval8100 = new TH1D("hTval8100", "",800,0.0,12.0);
	hTval8300 = new TH1D("hTval8300", "",800,0.0,12.0);
	hTval8500 = new TH1D("hTval8500", "",800,0.0,12.0);
	hTval8700 = new TH1D("hTval8700", "",800,0.0,12.0);
	hTval8900 = new TH1D("hTval8900", "",800,0.0,12.0);
	hRawTchan_CL = new TH1D("hRawTchan_CL", "",1500,0.0,12.0);
	hRawTchan_CLprime = new TH1D("hRawTchan_CLprime", "",1500,0.0,12.0);
	hPhotonVsTval = new TH2D("hPhotonVsTval", "",1600,0.0,12.0,1000,0.0,10.0);

	hOutOfTime  = new TH1D("hOutofTime","",1000,-20.0,20.0);
	hInTime     = new TH1D("hInTime","",1000,-20.0,20.0);
	hCasMassIT  = new TH1D("hCasMassIT","",1000,1.4,2.8);
	hCasMassOT  = new TH1D("hCasMassOT","",1000,1.4,2.8);
	hCasMassSub  = new TH1D("hCasMassSub","",1000,1.4,2.8); hCasMassSub->Sumw2();

	hCasMassITB2  = new TH1D("hCasMassITB2","",1400,1.4,2.8);
	hCasMassOTB2  = new TH1D("hCasMassOTB2","",1400,1.4,2.8);
	hCasMassSubB2  = new TH1D("hCasMassSubB2","",1400,1.4,2.8); hCasMassSubB2->Sumw2();

	hCasMassBGS = new TH1D("hCasMassBGS","",1000,1.4,2.8);


	hCasStarTval_1 =  new TH1D("hCasStarTval_1","",500,1.4,2.8);
	hCasStarTval_2 =  new TH1D("hCasStarTval_2","",500,1.4,2.8);
	hCasStarTval_3 =  new TH1D("hCasStarTval_3","",500,1.4,2.8);
	hCasStarTval_4 =  new TH1D("hCasStarTval_4","",500,1.4,2.8);
	hCasStarTval_5 =  new TH1D("hCasStarTval_5","",500,1.4,2.8);
	hCasStarTval_6 =  new TH1D("hCasStarTval_6","",500,1.4,2.8);
	hCasStarTval_7 =  new TH1D("hCasStarTval_7","",500,1.4,2.8);
	hCasStarTval_8 =  new TH1D("hCasStarTval_8","",500,1.4,2.8);
	hCasStarTval_9 =  new TH1D("hCasStarTval_9","",500,1.4,2.8);
	hCasStarTval_10 =  new TH1D("hCasStarTval_10","",500,1.4,2.8);
	hCasStarTval_11 =  new TH1D("hCasStarTval_11","",500,1.4,2.8);
	hCasStarTval_12 =  new TH1D("hCasStarTval_12","",500,1.4,2.8);

	hTval_K1 =  new TH1D("hTval_K1","",1000,0,7);
	hTval_K2 =  new TH1D("hTval_K2","",1000,0,7);
	hTval_K3 =  new TH1D("hTval_K3","",1000,0,7);
	hTval_K4 =  new TH1D("hTval_K4","",1000,0,7);
	hTval_K5 =  new TH1D("hTval_K5","",1000,0,7);
	hTval_K6 =  new TH1D("hTval_K6","",1000,0,7);
	hTval_K7 =  new TH1D("hTval_K7","",1000,0,7);
	hTval_K8 =  new TH1D("hTval_K8","",1000,0,7);
	hTval_K9 =  new TH1D("hTval_K9","",1000,0,7);
	hTval_K10 =  new TH1D("hTval_K10","",1000,0,7);
	hTval_K11 =  new TH1D("hTval_K11","",1000,0,7);
	hTval_K12 =  new TH1D("hTval_K12","",1000,0,7);



	hKp1vsThetav1 =  new TH2D("hKp1vsThetav1","",720,0,180,1000,0.0,10);
	hKp2vsThetav1 =  new TH2D("hKp2vsThetav1","",720,0,180,1000,0.0,10);
	hKp1vsThetav2 =  new TH2D("hKp1vsThetav2","",720,0,180,1000,0.0,10);
	hKp2vsThetav2 =  new TH2D("hKp2vsThetav2","",720,0,180,1000,0.0,10);
	

	hCasStarMass_72   =  new TH1D("hCasStarMass_72","",500,1.4,2.8);
	hCasStarMass_76   =  new TH1D("hCasStarMass_76","",500,1.4,2.8);
	hCasStarMass_80   =  new TH1D("hCasStarMass_80","",500,1.4,2.8);
	hCasStarMass_84   =  new TH1D("hCasStarMass_84","",500,1.4,2.8);
	hCasStarMass_88   =  new TH1D("hCasStarMass_88","",500,1.4,2.8);
	hCasStarMass_92   =  new TH1D("hCasStarMass_92","",500,1.4,2.8);
	hCasStarMass_96   =  new TH1D("hCasStarMass_96","",500,1.4,2.8);
	hCasStarMass_10   =  new TH1D("hCasStarMass_10","",500,1.4,2.8);
	hCasStarMass_104   =  new TH1D("hCasStarMass_104","",500,1.4,2.8);
	hCasStarMass_108   =  new TH1D("hCasStarMass_108","",500,1.4,2.8);


}

Bool_t DSelector_Cm1Star::Process(Long64_t locEntry)
{
  
  DSelector::Process(locEntry);
  
  /******************************************** GET POLARIZATION ORIENTATION ******************************************/
  
  UInt_t locRunNumber = Get_RunNumber();
  if(locRunNumber != dPreviousRunNumber)
    {
      dIsPolarizedFlag = dAnalysisUtilities.Get_IsPolarizedBeam(locRunNumber, dIsPARAFlag);
      dPreviousRunNumber = locRunNumber;
    }
  
  /********************************************* SETUP UNIQUENESS TRACKING ********************************************/
  
  //ANALYSIS ACTIONS: Reset uniqueness tracking for each action
  //For any actions that you are executing manually, be sure to call Reset_NewEvent() on them here
  Reset_Actions_NewEvent();
  dAnalyzeCutActions->Reset_NewEvent(); // manual action, must call Reset_NewEvent()
  
  //PREVENT-DOUBLE COUNTING WHEN HISTOGRAMMING
  //Sometimes, some content is the exact same between one combo and the next
  //e.g. maybe two combos have different beam particles, but the same data for the final-state
  //When histogramming, you don't want to double-count when this happens: artificially inflates your signal (or background)
		//So, for each quantity you histogram, keep track of what particles you used (for a given combo)
		//Then for each combo, just compare to what you used before, and make sure it's unique

	//EXAMPLE 1: Particle-specific info:
  set<Int_t> locUsedSoFar_BeamEnergy; //Int_t: Unique ID for beam particles. set: easy to use, fast to search
  
	//EXAMPLE 2: Combo-specific info:
  //In general: Could have multiple particles with the same PID: Use a set of Int_t's
		//In general: Multiple PIDs, so multiple sets: Contain within a map
		//Multiple combos: Contain maps within a set (easier, faster to search)
  set<map<Particle_t, set<Int_t> > > locUsedSoFar_MissingMass;
 


  
	//INSERT USER ANALYSIS UNIQUENESS TRACKING HERE

	/************************************************* LOOP OVER COMBOS *************************************************/

  UInt_t loc_i_best = 10000000;
  double clValBest = -1;
  for(UInt_t loc_i = 0; loc_i < Get_NumCombos(); ++loc_i)
    {
      dComboWrapper->Set_ComboIndex(loc_i);
      if(dComboWrapper->Get_IsComboCut()) continue;
      float locRFTime = dComboWrapper->Get_RFTime();
      TLorentzVector locVertex = dComboBeamWrapper->Get_X4();
      float DT_RF = locVertex.T() - (locRFTime + (locVertex.Z() - dTargetCenter.Z())/29.9792458);
      float abs_DT_RF = abs(DT_RF);
      bool inTime = false;
      if (abs_DT_RF <= 2.0) inTime = true;
      Int_t locBeamID = dComboBeamWrapper->Get_BeamID();
      double clVal   = dComboWrapper->Get_ConfidenceLevel_KinFit("");
      //if (clVal > pow(10,-4) && inTime == true) keeper = true;                                                                          \
                                                                                                                                                 
      if (clVal > clValBest && inTime == true){
	clValBest = clVal;
	loc_i_best = loc_i;
      }

    }

	//Loop over combos
  for(UInt_t loc_i = 0; loc_i < Get_NumCombos(); ++loc_i)
    {
		//Set branch array indices for combo and all combo particles
		dComboWrapper->Set_ComboIndex(loc_i);

		// Is used to indicate when combos have been cut
		if(dComboWrapper->Get_IsComboCut()) // Is false when tree originally created
			continue; // Combo has been cut previously

		/********************************************** GET PARTICLE INDICES *********************************************/

		//Used for tracking uniqueness when filling histograms, and for determining unused particles

		//Step 0
		Int_t locBeamID = dComboBeamWrapper->Get_BeamID();
		Int_t locKPlus1TrackID = dKPlus1Wrapper->Get_TrackID();
		Int_t locKPlus2TrackID = dKPlus2Wrapper->Get_TrackID();

		//Step 1
		Int_t locPhoton1NeutralID = dPhoton1Wrapper->Get_NeutralID();
		Int_t locPhoton2NeutralID = dPhoton2Wrapper->Get_NeutralID();

		//Step 2
		Int_t locPiMinus1TrackID = dPiMinus1Wrapper->Get_TrackID();

		//Step 3
		Int_t locPiMinus2TrackID = dPiMinus2Wrapper->Get_TrackID();
		Int_t locProtonTrackID = dProtonWrapper->Get_TrackID();

		/*********************************************** GET FOUR-MOMENTUM **********************************************/

		// Get P4's: //is kinfit if kinfit performed, else is measured
		//dTargetP4 is target p4
		//Step 0
		TLorentzVector locBeamP4 = dComboBeamWrapper->Get_P4();
		TLorentzVector locKPlus1P4 = dKPlus1Wrapper->Get_P4();
		TLorentzVector locKPlus2P4 = dKPlus2Wrapper->Get_P4();
		//Step 1
		TLorentzVector locDecayingPi0P4 = dDecayingPi0Wrapper->Get_P4();
		TLorentzVector locPhoton1P4 = dPhoton1Wrapper->Get_P4();
		TLorentzVector locPhoton2P4 = dPhoton2Wrapper->Get_P4();
		//Step 2
		TLorentzVector locPiMinus1P4 = dPiMinus1Wrapper->Get_P4();
		//Step 3
		TLorentzVector locDecayingLambdaP4 = dDecayingLambdaWrapper->Get_P4();
		TLorentzVector locPiMinus2P4 = dPiMinus2Wrapper->Get_P4();
		TLorentzVector locProtonP4 = dProtonWrapper->Get_P4();



		// Get Measured P4's:
		//Step 0
		TLorentzVector locBeamP4_Measured = dComboBeamWrapper->Get_P4_Measured();
		TLorentzVector locKPlus1P4_Measured = dKPlus1Wrapper->Get_P4_Measured();
		TLorentzVector locKPlus2P4_Measured = dKPlus2Wrapper->Get_P4_Measured();
		//Step 1
		TLorentzVector locPhoton1P4_Measured = dPhoton1Wrapper->Get_P4_Measured();
		TLorentzVector locPhoton2P4_Measured = dPhoton2Wrapper->Get_P4_Measured();
		//Step 2
		TLorentzVector locPiMinus1P4_Measured = dPiMinus1Wrapper->Get_P4_Measured();
		//Step 3
		TLorentzVector locPiMinus2P4_Measured = dPiMinus2Wrapper->Get_P4_Measured();
		TLorentzVector locProtonP4_Measured = dProtonWrapper->Get_P4_Measured();
		




		double betaKp1_M     = dKPlus1Wrapper->Get_Beta_Timing_Measured();
		double betaKp2_M     = dKPlus2Wrapper->Get_Beta_Timing_Measured();
		double piMinusBeta_M = dPiMinus1Wrapper->Get_Beta_Timing_Measured();
		double betaProton    = dProtonWrapper->Get_Beta_Timing_Measured();

		//cout<<dKPlus1Wrapper->Get_Detector_System_Timing()<<endl;

		//cout<<"SYS_BCAL = "<<SYS_BCAL<<endl;     // = 4
		//cout<<"SYS_FCAL = "<<SYS_FCAL<<endl;     // = 32
		//cout<<"SYS_TOF = "<<SYS_TOF<<endl;       // = 8
		//cout<<"SYS_START = "<<SYS_START<<endl;   // = 256
		//cout<<"SYS_NULL = "<<SYS_NULL<<endl;     // = 0

		//double betaKp1_M = 1;
		//double betaKp2_M = 1;
		

		//ASDF
		TLorentzVector moK1 = locKPlus1P4;
		TLorentzVector moK2 = locKPlus2P4;

		TLorentzVector moPi0    = locDecayingPi0P4;
		TLorentzVector moLambda = locDecayingLambdaP4;
		TLorentzVector moPim    = locPiMinus1P4;
		TLorentzVector moCs1    = moLambda + moPim;
		TLorentzVector moXiStar    = moCs1 + moPi0;

		TLorentzVector moPi0_M   = locPhoton1P4_Measured  + locPhoton2P4_Measured;
		TLorentzVector moLambda_M = locPiMinus2P4_Measured + locProtonP4_Measured;
		TLorentzVector moPim_M    = locPiMinus1P4_Measured;
		TLorentzVector moCs1_M    = moLambda_M + moPim_M;
		TLorentzVector moCs2_M    = moLambda_M + moPi0_M;
		
		TLorentzVector moCasStar_M    = moCs1_M + moPi0_M;
		TLorentzVector proInt(0,0,0,.938);
		TLorentzVector RootT = proInt-moXiStar;
		double Tval=abs(RootT.Mag()*RootT.Mag());
		double moKfast = locKPlus1P4.P(); 
		if(locKPlus1P4.P()< locKPlus2P4.P())
		  {
		    moKfast=  locKPlus2P4.P(); 
		  }
		
		double pimP_M  = moPim_M.P();
		double clVal   = dComboWrapper->Get_ConfidenceLevel_KinFit("");

		double chi2 = dComboWrapper->Get_ChiSq_KinFit();
		int ndf = dComboWrapper->Get_NDF_KinFit();
		double chi2NDF = chi2/ndf;

		//Cut values
		double clCut = 1e-4;
		double massStarLow = 1.31;//1.31
		double massStarHigh = 1.34;//1.34

		double beamEng = locBeamP4.P();
		

		double KPtheta_1 = locKPlus1P4.Theta()*180/3.14159;
		double KPtheta_2 = locKPlus2P4.Theta()*180/3.14159;

		TLorentzVector rootTVal_K =locBeamP4-moK1 ;
		TLorentzVector k1Star = moK1 + moPi0;
		TLorentzVector k2Star = moK2 + moPi0;
		if (KPtheta_2<=KPtheta_1)
		  {
		    rootTVal_K = locBeamP4 - moK2;
		    //k2Star = moK1 + moPi0;
		    //k1Star = moK2 + moPi0;
		  }
		
		  double kStarCenter = 8.95108e-01;
		  double kStarSigma = 2.79198e-02;
		  double kStarLow = kStarCenter - 3*kStarSigma;
		  double kStarHigh = kStarCenter + 3*kStarSigma;
		  double kStar1Mass = k1Star.M();
		  double kStar2Mass = k2Star.M();
		  bool isKStar = false;
		  if (kStar1Mass > kStarLow && kStar1Mass < kStarHigh) isKStar = true;
		  if (kStar2Mass > kStarLow && kStar2Mass < kStarHigh) isKStar = true;

		double Tval_K = rootTVal_K.Mag2();


		float locRFTime = dComboWrapper->Get_RFTime();
		TLorentzVector locVertex = dComboBeamWrapper->Get_X4();
//Beam photon time at vertex
		float DT_RF = locVertex.T() - (locRFTime + (locVertex.Z() - dTargetCenter.Z())/29.9792458);
		float abs_DT_RF = abs(DT_RF);
		bool inTime = false;
		if (abs_DT_RF <= 2.0) inTime = true;

		////start helicity
		TLorentzVector p1 = moCs1;
		TLorentzVector p2 = moPi0;
		TLorentzVector p3 = moK1;
		if (KPtheta_2>KPtheta_1) p3 = moK2;

		TLorentzVector beam = locBeamP4;
		TLorentzVector resonance = p1 + p2 + p3;
		TLorentzVector daughter1 = p1 + p2;
		TLorentzVector daughter2 = p1;
		TLorentzVector daughter3 = p2;

		TLorentzVector target(0,0,0,0.938);
		TLorentzVector cm = beam+target;

		TLorentzVector beam_cm = beam;

		TVector3 cmRestBoost = cm.BoostVector();
		TLorentzVector resonance_cm = resonance;
		TLorentzVector daughter1_cm = daughter1;
		TLorentzVector daughter2_cm = daughter2;
		TLorentzVector daughter3_cm = daughter3;
		resonance_cm.Boost(-1.0*cmRestBoost);
		daughter1_cm.Boost(-1.0*cmRestBoost);
		daughter2_cm.Boost(-1.0*cmRestBoost);
		daughter3_cm.Boost(-1.0*cmRestBoost);

		TVector3 resRestBoost = resonance_cm.BoostVector();
		TLorentzVector resonance_res = resonance_cm;
		TLorentzVector daughter1_res = daughter1_cm;
		TLorentzVector daughter2_res = daughter2_cm;
		TLorentzVector daughter3_res = daughter3_cm;
		resonance_res.Boost(-1.0*resRestBoost);
		daughter1_res.Boost(-1.0*resRestBoost);
		daughter2_res.Boost(-1.0*resRestBoost);
		daughter3_res.Boost(-1.0*resRestBoost);

		TVector3 vRestBoost = daughter1_res.BoostVector();
		TLorentzVector daughter2_v = daughter2_res;
		TLorentzVector daughter3_v = daughter3_res;

		daughter2_v.Boost(-1.0*vRestBoost);
		daughter3_v.Boost(-1.0*vRestBoost);

		TVector3 daughter1_res_vec = daughter1_res.Vect().Unit();
		TVector3 beam_cm_vec = beam_cm.Vect().Unit();
		

		TVector3 daughter2_vec = daughter2_v.Vect().Unit();
		TVector3 daughter3_vec = daughter3_v.Vect().Unit();

		//Define coordinate system in res frame using cm-frame variables                                                     
		//z-axis is still in direction of resonance_cm. Production plane                                                     
		//of beam/res contains z and x                                                                                       
		TVector3 z = resonance_cm.Vect().Unit();
		TVector3 y = (beam_cm_vec.Cross(z)).Unit();
		TVector3 x = (y.Cross(z)).Unit();

		TVector3 Angles(daughter1_res_vec.Dot(x),
				daughter1_res_vec.Dot(y),
				daughter1_res_vec.Dot(z));

		double cosTheta = Angles.CosTheta();
		double theta = Angles.Theta();
		double phi = Angles.Phi();

		//H rotation                                                                                                         

		TVector3 z_H = daughter1_res.Vect().Unit();
		TVector3 y_H = (z.Cross(z_H)).Unit();
		TVector3 x_H = (y_H.Cross(z_H)).Unit();


		TVector3 Angles_Hz(daughter2_vec.Dot(x_H),
				   daughter2_vec.Dot(y_H),
				   daughter2_vec.Dot(z_H));

		TVector3 Angles_Hx(daughter2_vec.Dot(y_H),
				   daughter2_vec.Dot(z_H),
				   daughter2_vec.Dot(x_H));

		TVector3 Angles_Hy(daughter2_vec.Dot(z_H),
				   daughter2_vec.Dot(x_H),
				   daughter2_vec.Dot(y_H));


		double cosTheta_Hz = Angles_Hz.CosTheta();
		double theta_Hz = Angles_Hz.Theta();
		double phi_Hz = Angles_Hz.Phi()*180.0/3.14159;

		double cosTheta_Hx = Angles_Hx.CosTheta();
		double theta_Hx = Angles_Hx.Theta();
		double phi_Hx = Angles_Hx.Phi()*180.0/3.14159;

		double cosTheta_Hy = Angles_Hy.CosTheta();
		double theta_Hy = Angles_Hy.Theta();
		double phi_Hy = Angles_Hy.Phi()*180.0/3.14159;


		////end helicity

		////start GJ
		TVector3 d1RestBoost = daughter1_cm.BoostVector();
		TLorentzVector daughter2_d1 = daughter2_cm;
		daughter2_d1.Boost(-1.0*d1RestBoost);


		TVector3 z_GJ = beam_cm.Vect().Unit();
		TVector3 y_GJ = (z_GJ.Cross(daughter1_cm.Vect())).Unit();
		TVector3 x_GJ = (y_GJ.Cross(z_GJ)).Unit();

		TVector3 Angles_GJz(daughter2_d1.Vect().Dot(x_GJ),
				    daughter2_d1.Vect().Dot(y_GJ),
				    daughter2_d1.Vect().Dot(z_GJ));
		
		TVector3 Angles_GJx(daughter2_d1.Vect().Dot(y_GJ),
				   daughter2_d1.Vect().Dot(z_GJ),
				   daughter2_d1.Vect().Dot(x_GJ));

		TVector3 Angles_GJy(daughter2_d1.Vect().Dot(z_GJ),
				   daughter2_d1.Vect().Dot(x_GJ),
				   daughter2_d1.Vect().Dot(y_GJ));

		double cosTheta_GJz = Angles_GJz.CosTheta();
		double theta_GJz = Angles_GJz.Theta();
		double phi_GJz = Angles_GJz.Phi()*180.0/3.14159;

		double cosTheta_GJx = Angles_GJx.CosTheta();
		double theta_GJx = Angles_GJx.Theta();
		double phi_GJx = Angles_GJx.Phi()*180.0/3.14159;

		double cosTheta_GJy = Angles_GJy.CosTheta();
		double theta_GJy = Angles_GJy.Theta();
		double phi_GJy = Angles_GJy.Phi()*180.0/3.14159;

		////end GJ

		//if (inTime == false) continue;
		/********************************************* COMBINE FOUR-MOMENTUM ********************************************/
		//ASDF- 4 Momentum 
		// DO YOUR STUFF HERE

		// Combine 4-vectors
		TLorentzVector locMissingP4_Measured = locBeamP4_Measured + dTargetP4;
		locMissingP4_Measured -= locKPlus1P4_Measured + locKPlus2P4_Measured + locPhoton1P4_Measured + locPhoton2P4_Measured + locPiMinus1P4_Measured + locPiMinus2P4_Measured + locProtonP4_Measured;

		double Cs1_Px   =  moCs1_M.Px();
		double Cs1_Py   =  moCs1_M.Py();
		double Cs1_Pz   =  moCs1_M.Pz();
		double mag_pCs1 =  sqrt(Cs1_Px*Cs1_Px+Cs1_Py*Cs1_Py+Cs1_Pz*Cs1_Pz);
		
		// Kaon momentum construction 
		
		double kaon_mom_M_1 = locKPlus1P4_Measured.P();
		double kaon_mom_M_2 = locKPlus2P4_Measured.P();
		double pi0_mom    = locDecayingPi0P4.P();
		/******************************************** EXECUTE ANALYSIS ACTIONS *******************************************/
		
		
		dAnalyzeCutActions->Perform_Action();
		if(!Execute_Actions())
		  continue;

		//if you manually execute any actions, and it fails a cut, be sure to call:
			//dComboWrapper->Set_IsComboCut(true);


		/**************************************** EXAMPLE: HISTOGRAM BEAM ENERGY *****************************************/


		if(locUsedSoFar_BeamEnergy.find(locBeamID) == locUsedSoFar_BeamEnergy.end())
		{
		  dHist_BeamEnergy->Fill(locBeamP4.E());
			locUsedSoFar_BeamEnergy.insert(locBeamID);
		}

		/************************************ EXAMPLE: HISTOGRAM MISSING MASS SQUARED ************************************/
		
		//Missing Mass Squared
		double locMissingMassSquared = locMissingP4_Measured.M2();
		
		//Uniqueness tracking: Build the map of particles used for the missing mass
		//For beam: Don't want to group with final-state photons. Instead use "Unknown" PID (not ideal, but it's easy).
		map<Particle_t, set<Int_t> > locUsedThisCombo_MissingMass;
		locUsedThisCombo_MissingMass[Unknown].insert(locBeamID); //beam
		locUsedThisCombo_MissingMass[KPlus].insert(locKPlus1TrackID);
		locUsedThisCombo_MissingMass[KPlus].insert(locKPlus2TrackID);
		locUsedThisCombo_MissingMass[Gamma].insert(locPhoton1NeutralID);
		locUsedThisCombo_MissingMass[Gamma].insert(locPhoton2NeutralID);
		locUsedThisCombo_MissingMass[PiMinus].insert(locPiMinus1TrackID);
		locUsedThisCombo_MissingMass[PiMinus].insert(locPiMinus2TrackID);
		locUsedThisCombo_MissingMass[Proton].insert(locProtonTrackID);

	
		//compare to what's been used so far
		if(locUsedSoFar_MissingMass.find(locUsedThisCombo_MissingMass) == locUsedSoFar_MissingMass.end())
		  {
		    //unique missing mass combo: histogram it, and register this combo of particles
		    dHist_MissingMassSquared->Fill(locMissingMassSquared);
		    locUsedSoFar_MissingMass.insert(locUsedThisCombo_MissingMass);
		  	
		//ASDFASDF


		    
		    //		        hXiMinus->Fill(moCs1_M.M());
		        hTmp2d->Fill(1,3);
			//  hXiStar->Fill(moCasStar_M.M());
			hXiStarvsCl->Fill(clVal,moCasStar_M.M());
			hPvsBeta->Fill(mag_pCs1,moCasStar_M.Beta());
			hXiMinusvsCl->Fill(clVal,moCs1.M());
			hRawTchan->Fill(Tval);
			//hPK1vsBeta->Fill(kaon_mom_1,locKPlus1P4.Beta()); //beta comes from the kinfit 
			//hPK2vsBeta->Fill(kaon_mom_2,locKPlus2P4.Beta()) ;//beta comes from the kinfit 
			hPK1vsBeta_M->Fill(kaon_mom_M_1,betaKp1_M); //beta comes from fixed quantities 
			hPK2vsBeta_M->Fill(kaon_mom_M_2,betaKp2_M) ;//beta comes from fixed quantities 
			hCasvsBeta_M->Fill(moCs1.P(),moCs1.Beta());
			
			hCasMassvsP->Fill(moCs1_M.M(),moCs1_M.P());		
			hXiMinus_Kin->Fill(moCs1.M());
			hPion_Kin->Fill(moPi0.M());
			hPion_M->Fill(moPi0_M.M());
			hAccidentals->Fill(DT_RF);
			hKp1vsThetav2->Fill(KPtheta_1,locKPlus1P4.P());
			hKp2vsThetav2->Fill(KPtheta_2,locKPlus2P4.P());


			
			if (clVal > clCut){
			  hPK1vsBeta_M_CL->Fill(kaon_mom_M_1,betaKp1_M); 
			  hPK2vsBeta_M_CL->Fill(kaon_mom_M_2,betaKp2_M);
			  hCasvsBeta_M_CL->Fill(moCs1_M.P(),moCs1_M.Beta());
			  hCascade_CL->Fill(moCs1_M.M());
			  hCascadeStar_CL->Fill(moCasStar_M.M());
			  hPPimvsBeta_M_CL->Fill(pimP_M,piMinusBeta_M);
			  hCasMassvsBeta_CL->Fill(moCs1_M.M(),moCs1_M.Beta());
			  hCasMassvsP_CL->Fill(moCs1_M.M(),moCs1_M.P());
			  hCasvsCasStar_CL->Fill(moCs1_M.M(),moCasStar_M.M());
			  
			  hKp1vsThetav1->Fill(KPtheta_1,locKPlus1P4.P());
			  hKp2vsThetav1->Fill(KPtheta_2,locKPlus2P4.P());
			  


			}
			
			//bool csGood = false;
			//if (moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow) csGood = true; 

			if(abs_DT_RF >=2.0 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow ){
			  
			  hOutOfTime->Fill(DT_RF);
			  hCasMassOT->Fill(moXiStar.M());
			  hCasMassSub->Fill(moXiStar.M(),-1.0/8);
			  hCasMassOTB2->Fill(moXiStar.M());
			  hCasMassSubB2->Fill(moXiStar.M(),-1.0/8);

			}
			
			if(abs_DT_RF <=2.0 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow ){
			  
			  hInTime->Fill(DT_RF);
			  hCasMassIT->Fill(moXiStar.M());
			  hCasMassSub->Fill(moXiStar.M());
			  hCasMassITB2->Fill(moXiStar.M());
			  hCasMassSubB2->Fill(moXiStar.M());
			}
			
			//			hCasMassBGS->Add( hCasMassIT, hCasMassOT,1.0,-.125);
			
			

			
			
			
			
			if ((dKPlus1Wrapper->Get_Detector_System_Timing() == 4) && (dKPlus2Wrapper->Get_Detector_System_Timing() == 4)){
			  hCasMass_BCAL->Fill(moCs1_M.M());
			  hCasStarMass_BCAL->Fill(moCasStar_M.M());
			  hPPimvsBeta_BCAL->Fill(pimP_M,piMinusBeta_M);
			  hPK1vsBeta_BCAL->Fill(kaon_mom_M_1,betaKp1_M);
			  hPK2vsBeta_BCAL->Fill(kaon_mom_M_2,betaKp2_M); 
			  hPProtonvsBeta_BCAL->Fill(locProtonP4.P(),betaProton);
			}

			if ((dKPlus1Wrapper->Get_Detector_System_Timing() == 0) && (dKPlus2Wrapper->Get_Detector_System_Timing() == 0)){
			  hCasMass_NULL->Fill(moCs1_M.M());
			  hCasStarMass_NULL->Fill(moCasStar_M.M());
			  hPPimvsBeta_NULL->Fill(pimP_M,piMinusBeta_M);
			  hPK1vsBeta_NULL->Fill(kaon_mom_M_1,betaKp1_M);
			  hPK2vsBeta_NULL->Fill(kaon_mom_M_2,betaKp2_M); 
			  hPProtonvsBeta_NULL->Fill(locProtonP4.P(),betaProton);
			}
			
			if ((dKPlus1Wrapper->Get_Detector_System_Timing() == 8) && (dKPlus2Wrapper->Get_Detector_System_Timing() ==8) && clVal> clCut){
			  hCasMass_TOF->Fill(moCs1_M.M());
			  hCasStarMass_TOF->Fill(moCasStar_M.M());
			  hPPimvsBeta_TOF->Fill(pimP_M,piMinusBeta_M);
			  hPK1vsBeta_TOF->Fill(kaon_mom_M_1,betaKp1_M);
			  hPK2vsBeta_TOF->Fill(kaon_mom_M_2,betaKp2_M); 
			  hPProtonvsBeta_TOF->Fill(locProtonP4.P(),betaProton);
			  hPKvsCasStar_MC->Fill(moXiStar.M(),moKfast);
			  double goodMass = moXiStar.M() ;
			  hGoodMass->Fill(goodMass);
			}
			
			
			
			
			if ((dKPlus1Wrapper->Get_Detector_System_Timing() == 32) && (dKPlus2Wrapper->Get_Detector_System_Timing() == 32)){
			  hCasMass_FCAL->Fill(moCs1_M.M());
			  hCasStarMass_FCAL->Fill(moCasStar_M.M());
			  hPPimvsBeta_FCAL->Fill(pimP_M,piMinusBeta_M);
			  hPK1vsBeta_FCAL->Fill(kaon_mom_M_1,betaKp1_M);
			  hPK2vsBeta_FCAL->Fill(kaon_mom_M_2,betaKp2_M); 
			  hPProtonvsBeta_FCAL->Fill(locProtonP4.P(),betaProton);
			}
			
			if (dKPlus1Wrapper->Get_Detector_System_Timing() == 256 && dKPlus2Wrapper->Get_Detector_System_Timing() == 256 ){
			  hCasMass_ST->Fill(moCs1_M.M());
			  hCasStarMass_ST->Fill(moCasStar_M.M());
			  hPPimvsBeta_ST->Fill(pimP_M,piMinusBeta_M);
			  hPK1vsBeta_ST->Fill(kaon_mom_M_1,betaKp1_M);
			  hPK2vsBeta_ST->Fill(kaon_mom_M_2,betaKp2_M); 
			  hPProtonvsBeta_ST->Fill(locProtonP4.P(),betaProton);
			}
			
			
			
			if ( (dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			      //&& dKPlus1Wrapper->Get_Detector_System_Timing() != 32 && dKPlus2Wrapper->Get_Detector_System_Timing() != 32
			      && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			      && (clVal > clCut))){
			  
			  hCasMass_CL_D->Fill(moCs1_M.M());
			  hCasStarMass_CL_D->Fill(moCasStar_M.M());
			  hPPimvsBeta_CL_D->Fill(pimP_M,piMinusBeta_M);
			  hPK1vsBeta_CL_D->Fill(kaon_mom_M_1,betaKp1_M);
			  hPK2vsBeta_CL_D->Fill(kaon_mom_M_2,betaKp2_M);
			  
			  
			}
			
			//cout<<"1"<<endl;
			
			if ( (dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			      && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			      && clVal > clCut  && betaKp1_M <=.98 && betaKp2_M <= .98 && moCs1.M()< massStarHigh && moCs1.M()>massStarLow )){
			  
			  hCasMass_CL_D_B->Fill(moCs1.M());
			  hCasStarMass_CL_D_B->Fill(moXiStar.M());
			  hPPimvsBeta_CL_D_B->Fill(pimP_M,piMinusBeta_M);
			  hPK1vsBeta_CL_D_B->Fill(kaon_mom_M_1,betaKp1_M);
			  hPK2vsBeta_CL_D_B->Fill(kaon_mom_M_2,betaKp2_M);
			  
			  
			  
			}
			
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>clCut && moKfast>= 1.20 && moKfast<= 5.2){			  
			  hPKvsCasStar->Fill(moXiStar.M(),moKfast);
			  hXiMinus->Fill(moCs1.M());
			  hXiStar->Fill(moXiStar.M());	
			  //			  hGoodMass->Fill(goodMass);
			}
		  	
			//	cout<<"2"<<end l;
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow ){			   
			  
			  hXiMinus_MS->Fill(moCs1_M.M());
			  hCasStar_MC->Fill(moCasStar_M.M());
			  hCasStar_MC_Kin->Fill(moXiStar.M());
			  hCasMassvsBeta->Fill(moCs1.M(),moCs1.P());
			  hCasvsCasStar_CL_D->Fill(moCs1.M(),moXiStar.M());
			  hPKvsCasStar_MC->Fill(moXiStar.M(),moKfast);
			}
			
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0){
			  if (clVal > pow(10,-1)) hCasStarVsCas_MC_Kin_1->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-2)) hCasStarVsCas_MC_Kin_2->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-3)) hCasStarVsCas_MC_Kin_3->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-4)){
			    hCasStarVsCas_MC_Kin_4->Fill(moXiStar.M(),moCs1.M());
			    if (isKStar == false) hCasStarVsCas_MC_Kin_4KCut->Fill(moXiStar.M(),moCs1.M());
			  }

			  if (clVal > pow(10,-4) && loc_i == loc_i_best){
			    hCasStarVsCas_MC_Kin_4B->Fill(moXiStar.M(),moCs1.M());
			  }
			  if (clVal > pow(10,-4) && dKPlus2Wrapper->Get_Detector_System_Timing() == 8) 
			    hCasStarVsCas_MC_Kin_4T->Fill(moXiStar.M(),moCs1.M());

			  if (clVal > pow(10,-5)) hCasStarVsCas_MC_Kin_5->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-6)) hCasStarVsCas_MC_Kin_6->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-7)) hCasStarVsCas_MC_Kin_7->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-8)) hCasStarVsCas_MC_Kin_8->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-9)) hCasStarVsCas_MC_Kin_9->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-10)) hCasStarVsCas_MC_Kin_10->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-11)) hCasStarVsCas_MC_Kin_11->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-12)) hCasStarVsCas_MC_Kin_12->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-13)) hCasStarVsCas_MC_Kin_13->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-14)) hCasStarVsCas_MC_Kin_14->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-15)) hCasStarVsCas_MC_Kin_15->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-16)) hCasStarVsCas_MC_Kin_16->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-17)) hCasStarVsCas_MC_Kin_17->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-18)) hCasStarVsCas_MC_Kin_18->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-19)) hCasStarVsCas_MC_Kin_19->Fill(moXiStar.M(),moCs1.M());
			  if (clVal > pow(10,-20)) hCasStarVsCas_MC_Kin_20->Fill(moXiStar.M(),moCs1.M());
			}			

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.1 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_1->Fill(moXiStar.M());
			    
			    hTval_K1->Fill(-Tval_K);
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.01 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_2->Fill(moXiStar.M());
			    hTval_K2->Fill(-Tval_K);
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_3->Fill(moXiStar.M());
			    hTval_K3->Fill(-Tval_K);
			  }


			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_4->Fill(moXiStar.M());
			    hTval_K4->Fill(-Tval_K);
			    //
			    hCosThetaHxVsCasStar_MC_Kin_4->Fill(moXiStar.M(),cosTheta_Hx);
			    hPhiHxVsCasStar_MC_Kin_4->Fill(moXiStar.M(),phi_Hx);

			    hCosThetaHyVsCasStar_MC_Kin_4->Fill(moXiStar.M(),cosTheta_Hy);
			    hPhiHyVsCasStar_MC_Kin_4->Fill(moXiStar.M(),phi_Hy);

			    hCosThetaHzVsCasStar_MC_Kin_4->Fill(moXiStar.M(),cosTheta_Hz);
			    hPhiHzVsCasStar_MC_Kin_4->Fill(moXiStar.M(),phi_Hz);
			    //
			    hCosThetaGJxVsCasStar_MC_Kin_4->Fill(moXiStar.M(),cosTheta_GJx);
			    hPhiGJxVsCasStar_MC_Kin_4->Fill(moXiStar.M(),phi_GJx);

			    hCosThetaGJyVsCasStar_MC_Kin_4->Fill(moXiStar.M(),cosTheta_GJy);
			    hPhiGJyVsCasStar_MC_Kin_4->Fill(moXiStar.M(),phi_GJy);

			    hCosThetaGJzVsCasStar_MC_Kin_4->Fill(moXiStar.M(),cosTheta_GJz);
			    hPhiGJzVsCasStar_MC_Kin_4->Fill(moXiStar.M(),phi_GJz);

			    if (k1Star.Theta() < k2Star.Theta()){
			      if (k1Star.Theta() < moK2.Theta()) hCasStarVsK1Star->Fill(k1Star.M(),moXiStar.M());
			      if (k1Star.Theta() > moK2.Theta()) hCasStarVsK1BStar->Fill(k1Star.M(),moXiStar.M());
			    } else {
			      //hCasStarVsK1Star->Fill(k2Star.M(),moXiStar.M());
			      if (k2Star.Theta() < moK1.Theta()) hCasStarVsK2Star->Fill(k2Star.M(),moXiStar.M());
			      if (k2Star.Theta() > moK1.Theta()) hCasStarVsK2BStar->Fill(k2Star.M(),moXiStar.M());
			      //hCasStarVsK2Star->Fill(k1Star.M(),moXiStar.M());
			    }


			    if (isKStar == false) {
			      hCasStarKCut->Fill(moXiStar.M());
			      hCosThetaHzVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),cosTheta_Hz);
			      hPhiHzVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),phi_Hz);

			      //
			      hCosThetaHxVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),cosTheta_Hx);
			      hPhiHxVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),phi_Hx);
			      
			      hCosThetaHyVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),cosTheta_Hy);
			      hPhiHyVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),phi_Hy);
			      
			      hCosThetaHzVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),cosTheta_Hz);
			      hPhiHzVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),phi_Hz);
			      //
			      hCosThetaGJxVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),cosTheta_GJx);
			      hPhiGJxVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),phi_GJx);
			      
			      hCosThetaGJyVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),cosTheta_GJy);
			      hPhiGJyVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),phi_GJy);
			      
			      hCosThetaGJzVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),cosTheta_GJz);
			      hPhiGJzVsCasStar_MC_Kin_4K->Fill(moXiStar.M(),phi_GJz);
			      
			      if (loc_i == loc_i_best){
				//
				hCosThetaHxVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),cosTheta_Hx);
				hPhiHxVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),phi_Hx);
				
				hCosThetaHyVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),cosTheta_Hy);
				hPhiHyVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),phi_Hy);
				
				hCosThetaHzVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),cosTheta_Hz);
				hPhiHzVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),phi_Hz);
				//
				hCosThetaGJxVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),cosTheta_GJx);
				hPhiGJxVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),phi_GJx);
				
				hCosThetaGJyVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),cosTheta_GJy);
				hPhiGJyVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),phi_GJy);
			      
				hCosThetaGJzVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),cosTheta_GJz);
				hPhiGJzVsCasStar_MC_Kin_4KB->Fill(moXiStar.M(),phi_GJz);
				
				hCasStarKCutB->Fill(moXiStar.M());
			      }
			    }
			  }
			
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.00001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_5->Fill(moXiStar.M());
			    hTval_K5->Fill(-Tval_K);
			  }
			
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_6->Fill(moXiStar.M());
			    hTval_K6->Fill(-Tval_K);
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_7->Fill(moXiStar.M());
			    hTval_K7->Fill(-Tval_K);
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.01 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && moXiStar.M()>=1.5 && moXiStar.M()<=1.57)// && beamEng < 9.0 && beamEng > 8.0 )
			  {			   
			    hRawTchan_CLprime->Fill(-Tval_K);
			  
			  }

	
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && moXiStar.M()>=1.5 && moXiStar.M()<=1.57)// && beamEng < 9.0 && beamEng > 8.0 )            
                          {
                            hRawTchan_CL->Fill(-Tval_K);

                          }

			 

			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.00000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {		
			    hCasStar_MC_Kin_8->Fill(moXiStar.M());
			    hTval_K8->Fill(-Tval_K);
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_9->Fill(moXiStar.M());
			    hTval_K9->Fill(-Tval_K);
			  }
			
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_10->Fill(moXiStar.M());
			    hTval_K10->Fill(-Tval_K);
			  }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.00000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_11->Fill(moXiStar.M());
			    hTval_K11->Fill(-Tval_K);
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.000000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_12->Fill(moXiStar.M());
			    hTval_K12->Fill(-Tval_K);
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0000000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_13->Fill(moXiStar.M());
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.00000000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_14->Fill(moXiStar.M());
			  }


			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.000000000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_15->Fill(moXiStar.M());
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0000000000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_16->Fill(moXiStar.M());
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.00000000000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_17->Fill(moXiStar.M());
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.000000000000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_18->Fill(moXiStar.M());
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0000000000000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_19->Fill(moXiStar.M());
			  }


			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.00000000000000000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow )
			  {			   
			    hCasStar_MC_Kin_20->Fill(moXiStar.M());
			  }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 7.2 && beamEng > 7.0 )
			  {			   
			    hCasStar_MC_Kin_7100->Fill(moXiStar.M());
			  }	
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 7.4 && beamEng > 7.2 )
			  {			   
			    hCasStar_MC_Kin_7300->Fill(moXiStar.M());
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 7.6 && beamEng > 7.4 )
			  {			   
			    hCasStar_MC_Kin_7500->Fill(moXiStar.M());
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 7.8 && beamEng > 7.6 )
			  {			   
			    hCasStar_MC_Kin_7700->Fill(moXiStar.M());
			  }
			
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 8.0 && beamEng > 7.8 )
			  {			   
			    hCasStar_MC_Kin_7900->Fill(moXiStar.M());
			  }


			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 8.2 && beamEng > 8.0 )
			  {			   
			    hCasStar_MC_Kin_8100->Fill(moXiStar.M());
			    //	    hTval8100->Fill(Tval);
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 9.0  && beamEng > 8.0 )
			  {			   
		
			    hTval8100->Fill(Tval);
			  }

			//hPhotonVsTval
                        if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && moXiStar.M()>=1.5 && moXiStar.M()<=1.57 && beamEng < 9.0 && beamEng > 8.0  )
                          {

                            hPhotonVsTval->Fill(Tval,beamEng);
                          }



			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval > 0.0  && Tval < 1.0)//  && beamEng < 9.0 && beamEng > 8.0 )
                          {
                            hCasStarTval_1->Fill(moXiStar.M());
                          }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 1.0  && Tval < 2.0)// && beamEng < 9.0 && beamEng > 8.0)
                          {
                            hCasStarTval_2->Fill(moXiStar.M());
                          }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 2.0  && Tval < 3.0)// && beamEng < 9.0 && beamEng > 8.0 )
                          {
                            hCasStarTval_3->Fill(moXiStar.M());
                          }
                        if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 3.0  && Tval < 4.0 && beamEng < 9.0 && beamEng > 8.0 )
                          {
                            hCasStarTval_4->Fill(moXiStar.M());
                          }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 4.0  && Tval < 5.0 && beamEng < 9.0 && beamEng > 8.0 )
                          {
                            hCasStarTval_5->Fill(moXiStar.M());
                          }
                        if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 5.0  && Tval < 6.0 && beamEng < 9.0 && beamEng > 8.0)
                          {
                            hCasStarTval_6->Fill(moXiStar.M());
                          }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 6.0  && Tval < 7.0 && beamEng < 9.0 && beamEng > 8.0 )
                          {
                            hCasStarTval_7->Fill(moXiStar.M());
                          }
                        if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 7.0  && Tval < 8.0 && beamEng < 9.0 && beamEng > 8.0 )
                          {
                            hCasStarTval_8->Fill(moXiStar.M());
                          }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 8.0  && Tval < 9.0 && beamEng < 9.0 && beamEng > 8.0 )
                          {
                            hCasStarTval_9->Fill(moXiStar.M());
                          }
                        if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 9.0  && Tval < 10.0 && beamEng < 9.0 && beamEng > 8.0 )
                          {
                            hCasStarTval_10->Fill(moXiStar.M());
                          }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 10.0  && Tval < 11.0 && beamEng < 9.0 && beamEng > 8.0 )
                          {
                            hCasStarTval_11->Fill(moXiStar.M());
                          }
                        if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
                           && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
                           && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && Tval >= 11.0  && Tval < 12.0 && beamEng < 9.0 && beamEng > 8.0 )
                          {
                            hCasStarTval_12->Fill(moXiStar.M());
                          }








			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 8.4 && beamEng > 8.2 )
			  {			   
			    hCasStar_MC_Kin_8300->Fill(moXiStar.M());
			    hTval8300->Fill(Tval); 
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>.0000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 8.6 && beamEng > 8.4 )
			  {			   
			    hCasStar_MC_Kin_8500->Fill(moXiStar.M());
			    hTval8500->Fill(Tval);
			  }
			
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 8.8 && beamEng > 8.6 )
			  {			   
			    hCasStar_MC_Kin_8700->Fill(moXiStar.M());
			    hTval8700->Fill(Tval);
			  }

			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0000001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 9.0 && beamEng > 8.8 )
			  {			   
			    hCasStar_MC_Kin_8900->Fill(moXiStar.M());
			    hTval8900->Fill(Tval);
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 9.2 && beamEng > 9.0 )
			  {			   
			    hCasStar_MC_Kin_9100->Fill(moXiStar.M());
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 9.4 && beamEng > 9.2)
			  {			   
			    hCasStar_MC_Kin_9300->Fill(moXiStar.M());
			  }
						
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 9.6 && beamEng > 9.4 )
			  {			   
			    hCasStar_MC_Kin_9500->Fill(moXiStar.M());
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 9.8 && beamEng > 9.6 )
			  {			   
			    hCasStar_MC_Kin_9700->Fill(moXiStar.M());
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 10.0 && beamEng > 9.8 )
			  {			   
			    hCasStar_MC_Kin_9900->Fill(moXiStar.M());
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 10.2 && beamEng > 10.0 )
			  {			   
			    hCasStar_MC_Kin_10100->Fill(moXiStar.M());
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 10.4 && beamEng > 10.2 )
			  {			   
			    hCasStar_MC_Kin_10300->Fill(moXiStar.M());
			  }
			

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 10.6 && beamEng > 10.4 )
			  {			   
			    hCasStar_MC_Kin_10500->Fill(moXiStar.M());
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus2Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 && dKPlus2Wrapper->Get_Detector_System_Timing() != 0
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 10.8 && beamEng > 10.6 )
			  {			   
			    hCasStar_MC_Kin_10700->Fill(moXiStar.M());
			  }
			
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>.0001 && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 11.0 && beamEng > 10.8 )
			  {			   
			    hCasStar_MC_Kin_10900->Fill(moXiStar.M());
			  }
			
			//KILL LINE IS HERE		

			if (clVal > clCut){ 
			  //cout<<"PASS: clVal, chi2NDF = "<<clVal<<" , "<<chi2NDF<<endl;
			  //cout<<"PASS: clVal = "<<clVal<<" , "<<"moCs1.M() = "<<moCs1.M()<<" , "<<beamEng<<" , "<<"D = "<<dKPlus2Wrapper->Get_Detector_System_Timing()<<endl;
			}else{
			  //cout<<"FAIL: clVal, chi2NDF = "<<clVal<<" , "<<chi2NDF<<endl;
			  //cout<<"FAIL: clVal = "<<clVal<<" , "<<"moCs1.M() = "<<moCs1.M()<<" , "<<beamEng<<" , "<<"D = "<<dKPlus2Wrapper->Get_Detector_System_Timing()<<endl;
			}
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 7.4 && beamEng >= 7.0 )
			  {			   
			    hCasStarMass_72->Fill(moXiStar.M());
			  }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 7.8 && beamEng >= 7.4 )
			  {			   
			    hCasStarMass_76->Fill(moXiStar.M());
			  }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 8.2 && beamEng >= 7.8 )
			  {			   
			    hCasStarMass_80->Fill(moXiStar.M());
			  }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 8.6 && beamEng >= 8.2 )
			  {			   
			    hCasStarMass_84->Fill(moXiStar.M());
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 9.0 && beamEng >= 8.6 )
			  {			   
			    hCasStarMass_88->Fill(moXiStar.M());
			  }
			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 9.4 && beamEng >= 9.0 )
			  {			   
			    hCasStarMass_92->Fill(moXiStar.M());
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 9.8 && beamEng >= 9.4 )
			  {			   
			    hCasStarMass_96->Fill(moXiStar.M());
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 10.2 && beamEng >= 9.8 )
			  {			   
			    hCasStarMass_10->Fill(moXiStar.M());
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng < 10.6 && beamEng >= 10.2 )
			  {			   
			    hCasStarMass_104->Fill(moXiStar.M());
			  }

			if(dKPlus1Wrapper->Get_Detector_System_Timing() !=256 && dKPlus1Wrapper->Get_Detector_System_Timing() !=256
			   && dKPlus2Wrapper->Get_Detector_System_Timing() != 0 && dKPlus1Wrapper->Get_Detector_System_Timing() != 0 
			   && clVal>clCut && moCs1.M() <= massStarHigh && moCs1.M() >= massStarLow && beamEng <=11.0 && beamEng >= 10.6 )
			  {			   
			    hCasStarMass_108->Fill(moXiStar.M());
			  }

		       


			
			
			
		  }		
		
		//hPK1vsBeta->Draw();
		//hPK2vsBeta->Draw("SAME");
			//hPPi0vsBeta->Draw("SAME");
		
			//if (clVal > 0.01) cout<<"moCs1_M.M() & clVal = "<<moCs1_M.M()<<" , "<<clVal<<endl;
		
		
//E.g. Cut
//if((locMissingMassSquared < -0.04) || (locMissingMassSquared > 0.04))
	//{
	//	dComboWrapper->Set_IsComboCut(true);
	//	continue;
		//}

	//FILL HISTOGRAMS: Num combos / events surviving actions
	}
  Fill_NumCombosSurvivedHists();
			return kTRUE;
  
}



void DSelector_Cm1Star::Finalize(void)
{
  DSelector::Finalize();
}
 
