TLorentzVector rotate(TLorentzVector v, Float_t theta, Float_t phi){ v.RotateX(theta); v.RotateY(phi); return v; }
void sqrtBins(){ //OPTIONS AND CUTS______________ bool useBlueBeam = false; bool useYellowBeam = true; bool randomizeSpin = false; bool fullEta = false; double PI = 3.14159265359; cout << "\n"; if (useBlueBeam && useYellowBeam){cout << "using both beams-----" << endl;} if (useBlueBeam && !useYellowBeam){cout << "using blue beam------" << endl;} if (!useBlueBeam && useYellowBeam){cout << "using yellow beam----" << endl;} cout << "\n"; if (randomizeSpin){cout << "randomizing spin-----" << endl;} //______________________________ //LOAD LIBS_____________________ cout << "\n"; gROOT->Macro("StRoot/LoadLibs.C"); gSystem->Load("pionPair"); cout << " loading of pionPair library done" << endl; //______________________________ //SET UP INPUT FILE_____________ TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/schedOut_Full_4_2/allPairs_4_2.root"); string outFileName = "./resultsNew_4_22/yellowEtaGT0_pairs_4_2.root"; //______________________________ //SET UP TREE TO RECEIVE INPUT__ pionPair* pair1 = new pionPair(); TTree* pairTree = infile->Get("pionPairTree"); pairTree->SetBranchAddress("pionPair", &pair1); //______________________________ //SET UP HISTOGRAMS_____________ //event variable histograms /* TH1D* hInvarM = new TH1D("invarM","invarM",80,0,2); TH1D* hEtaTot = new TH1D("etaTot","etaTot",60,-1.5,1.5); TH1D* hPhiR = new TH1D("hPhiR","hPhiR",60,-4,4); TH1D* hPhiS = new TH1D("hPhiS","hPhiS",60,-4,4); TH1D* hPhiSR = new TH1D("hPhiSR","hPhiSR",60,-4,4); TH1D* hTheta = new TH1D("hTheta","hTheta",30,-0.85,4); TH1D* hCosTheta = new TH1D("hCosTheta","hCosTheta",80,-1,1); TH1D* hZ = new TH1D("hZ","hZ",80,0,1); TH1D* hPtot = new TH1D("hPtot","hPtot",80,0,20); TH1D* hPtTOT = new TH1D("hPt","hPt",80,0,15); */ //histos for asym analysis double histMin = -PI; double histMax = PI; TH1D * hNumberUp = new TH1D("hNumberUp","hNumberUp",nPhisrBins,histMin,histMax); TH1D * hNumberDown = new TH1D("hNumberDown","hNumberDown",nPhisrBins,histMin,histMax); TH1D * hNumberUp_Pt[nPtBins]; TH1D * hNumberDown_Pt[nPtBins]; TH1D * hNumberUp_Mass[nMassBins]; TH1D * hNumberDown_Mass[nMassBins]; TH1D * hNumberUp_Eta[nEtaBins]; TH1D * hNumberDown_Eta[nEtaBins]; createFiveBins(hNumberUp_Pt,nPhisrBins,histMin,histMax,"hNumUp_Ptbin_"); createFiveBins(hNumberDown_Pt,nPhisrBins,histMin,histMax,"hNumDwn_Ptbin_"); createFiveBins(hNumberUp_Mass,nPhisrBins,histMin,histMax,"hNumUp_Massbin_"); createFiveBins(hNumberDown_Mass,nPhisrBins,histMin,histMax,"hNumDwn_Massbin_"); createFourBins(hNumberUp_Eta,nPhisrBins,histMin,histMax,"hNumUp_Etabin_"); createFourBins(hNumberDown_Eta,nPhisrBins,histMin,histMax,"hNumDwn_Etabin_"); TH1D* hAut_Pt[nPtBins]; TH1D* hAut_Mass[nMassBins]; TH1D* hAut_Eta[nEtaBins]; createFiveBins(hAut_Pt, nPhisrBins, histMin, histMax, "hAut_Ptbin_"); createFiveBins(hAut_Mass, nPhisrBins, histMin, histMax, "hAut_Massbin_"); createFourBins(hAut_Eta, nPhisrBins, histMin, histMax, "hAut_Etabin_"); /* TH1D* polOfBinUp_Pt[nPtBins][binNumber]; TH1D* polOfBinDown_Pt[nPtBins][binNumber]; TH1D* polOfBinUp_Mass[nMassBins][binNumber]; TH1D* polOfBinDown_Mass[nMassBins][binNumber]; TH1D* polOfBinUp_Eta[nEtaBins][binNumber]; TH1D* polOfBinDown_Eta[nEtaBins][binNumber]; createPolHists(polOfBinUp_Pt, 25, 0, 1, "hPolOfBinUp_Ptbin_"); createPolHists(polOfBinDown_Pt, 25, 0, 1, "hPolOfBinDown_Ptbin_"); createPolHists(polOfBinUp_Mass, 25, 0, 1, "hPolOfBinUp_Massbin_"); createPolHists(polOfBinDown_Mass, 25, 0, 1, "hPolOfBinDown_Massbin_"); createPolHists(polOfBinUp_Eta, 25, 0, 1, "hPolOfBinUp_Etabin_"); createPolHists(polOfBinDown_Eta, 25, 0, 1, "hPolOfBinDown_Etabin_"); */ TH1D* polOfBin_Pt[nPtBins][nPhisrBins]; TH1D* polOfBin_Mass[nMassBins][nPhisrBins]; TH1D* polOfBin_Eta[nEtaBins][nPhisrBins]; createPolHists(polOfBin_Pt, 25, 0, 1, "hPolOfBin_Ptbin_"); createPolHists(polOfBin_Mass, 25, 0, 1, "hPolOfBin_Massbin_"); createPolHistsEta(polOfBin_Eta, 25, 0, 1, "hPolOfBin_Etabin_"); //HISTOGRAMS TO HOLD PT MASS AND ETA VALES TH1D* hPt[nPtBins]; TH1D* hMass[nMassBins]; TH1D* hEta[nEtaBins]; createFiveBins(hPt, 500, 3.0, 50, "hPt_Ptbin_"); createFiveBins(hMass, 1000, 0.0, 100, "hMass_Massbin_"); createFourBins(hEta, 20, -1.4, 1.4, "hEta_Etabin_"); //TH1D * hDiff = new TH1D("hNumberSum","hNumberSum",binNumber,histMin,histMax); //TH1D * hAut = new TH1D("Aut","Aut",binNumber,histMin,histMax); //______________________________ //BEAM POLARIZATION_____________ ifstream polFile; polFile.open("/star/u/klandry/ucladisk/2012IFF/BeamPolarization2012.txt"); map<int, double> polarizationOfFill_Y; map<int, double> polErrOfFill_Y; map<int, double> polarizationOfFill_B; map<int, double> polErrOfFill_B; int fill; int beamE; int startT; string plusminus; double pAvrgBlue; double pErrAvrgBlue; double pInitialBlue; double pErrInitialBlue; double dPdTBlue; double dPdTErrBlue; double pAvrgYellow; double pErrAvrgYellow; double pInitialYellow; double pErrInitialYellow; double dPdTYellow; double dPdTErrYellow; string header; for (int i=0; i<19; i++){polFile >> header;} while (!polFile.eof()) { polFile >> fill; polFile >> beamE; polFile >> startT; polFile >> pAvrgBlue; polFile >> plusminus; polFile >> pErrAvrgBlue; polFile >> pInitialBlue; polFile >> plusminus; polFile >> pErrInitialBlue; polFile >> dPdTBlue; polFile >> plusminus; polFile >> dPdTErrBlue; polFile >> pAvrgYellow; polFile >> plusminus; polFile >> pErrAvrgYellow; polFile >> pInitialYellow; polFile >> plusminus; polFile >> pErrInitialYellow; polFile >> dPdTYellow; polFile >> plusminus; polFile >> dPdTErrYellow; polarizationOfFill_B[fill] = pAvrgBlue/100.; polErrOfFill_B[fill] = pErrAvrgBlue/100.; polarizationOfFill_Y[fill] = pAvrgYellow/100.; polErrOfFill_Y[fill] = pErrAvrgYellow/100.; } double avgPolOfBinUp[nPhisrBins]; double polOfBinSumUp[nPhisrBins]; double avgPerrorOfBinUp[nPhisrBins]; double pErrorOfBinUp[nPhisrBins]; double avgPolOfBinDown[nPhisrBins]; double polOfBinSumDown[nPhisrBins]; double avgPerrorOfBinDown[nPhisrBins]; double pErrorOfBinDown[nPhisrBins]; for (int i=0; i<nPhisrBins; i++) { avgPolOfBinUp[i] = 0; polOfBinSumUp[i] = 0; avgPerrorOfBinUp[i] = 0; pErrorOfBinUp[i] = 0; avgPolOfBinDown[i] = 0; polOfBinSumDown[i] = 0; avgPerrorOfBinDown[i] = 0; pErrorOfBinDown[i] = 0; } //______________________________ //CUTS__________________________ double lowLimitPt = ptBinStart[0]; double hiLimitPt = ptBinEnd[4]; double lowLimitEta = etaBinStart[0]; double hiLimitEta = etaBinEnd[3]; double lowLimitMass = massBinStart[0]; double hiLimitMass = massBinEnd[4]; double blueLowLimitEta = 0; double yellowLowLimitEta = 0; //this is for testing individual beams //hiLimitEta = 0; if (fullEta) { assert(hiLimitEta > 0); assert(lowLimitEta < 0); } cout << "Pt between " << lowLimitPt << " and " << hiLimitPt << endl; cout << "M between " << lowLimitMass << " and " << hiLimitMass << endl; cout << "Eta between " << lowLimitEta << " and " << hiLimitEta << endl; //______________________________ //* // ====================================================================== //============================================================================ //START ANALYSIS============================================================== //============================================================================ // ====================================================================== //* cout << "\n"; cout << "<----STARTING ANALYSIS---->" << endl; cout << "\n"; cout << pairTree->GetEntries() << " pairs to analyze" << endl; int blueFillNo; int yellowFillNo; int phiSRbin; TLorentzVector sum; TLorentzVector sumY; TLorentzVector sumB; //random number for randomizing spin. //set seed to zero to gaurenty unique numbers each time. TRandom3 r; r.SetSeed(0); int rand5 = 0; int rand6 = 0; int rand9 = 0; int rand10 = 0; int totalPairsFinal = 0; int blueD = 0; int blueU = 0; int yellowD = 0; int yellowU = 0; int pionStarNumber = 0; int test = 0; for (int iPair = pionStarNumber; iPair < pairTree->GetEntries(); iPair++) { if (iPair%10000 == 0) {cout << "processing pair number " << iPair << endl;} //if (iPair == pionStarNumber+100000){break;} pairTree->GetEntry(iPair); if (pair1->withinRadius(0.05, 0.3)) { bool triggerFired = false; bool fromKaon = false; bool passInitialCut_B = false; bool passInitialCut_Y = false; bool passDCAcut = false; StTriggerId trigId = pair1->triggerIds(); //JP0,JP1,JP2,AJP if (trigId.isTrigger(370601) || trigId.isTrigger(370611) || trigId.isTrigger(370621) || trigId.isTrigger(370641)) { triggerFired = true; } //BHT0VPD,BHT1VPD,BHT2BBC,BHT2 if (trigId.isTrigger(370501) || trigId.isTrigger(370511) || trigId.isTrigger(370522) || trigId.isTrigger(370531)) { triggerFired = true; } if (triggerFired) { blueFillNo = pair1->runInfo().beamFillNumber(1); //1 = blue beam yellowFillNo = pair1->runInfo().beamFillNumber(0); //0 = yellow beam sum = pair1->piPlusLV() + pair1->piMinusLV(); sumB = sum; //blue beam. //yellow beam must rotate around y axis by pi so the eta cut can be the same for both beams. sumY = sum; sumY.RotateY(PI); //blue low limit eta is 0 yellow high limit eta is 0 this is a test if (sumB.Pt() >= lowLimitPt && sumB.Pt() <= hiLimitPt && sumB.M() >= lowLimitMass && sumB.M() <= hiLimitMass && sumB.Eta() >= lowLimitEta && sumB.Eta() <= hiLimitEta) { passInitialCut_B = true; } if (sumY.Pt() >= lowLimitPt && sumY.Pt() <= hiLimitPt && sumY.M() >= lowLimitMass && sumY.M() <= hiLimitMass && sumY.Eta() >= yellowLowLimitEta && sumY.Eta() <= hiLimitEta) { passInitialCut_Y = true; } if (passInitialCut_B && useBlueBeam) { //BLUE BEAM SPIN UP: spin bin 9 and 10 if (pair1->spinBit() == 9 || pair1->spinBit() == 10) { fillCorrectPtBin(hNumberUp_Pt, sumB, pair1->phiSR('b'), polOfBin_Pt, polarizationOfFill_B[blueFillNo],hPt); fillCorrectMassBin(hNumberUp_Mass, sumB, pair1->phiSR('b'), polOfBin_Mass, polarizationOfFill_B[blueFillNo],hMass); if(fullEta){fillCorrectEtaBin(hNumberUp_Eta, sumB, pair1->phiSR('b'), polOfBin_Eta, polarizationOfFill_B[blueFillNo],hEta);} } //BLUE BEAM SPIN DOWN: spin bin 5 and 6 if (pair1->spinBit() == 5 || pair1->spinBit() == 6) { fillCorrectPtBin(hNumberDown_Pt, sumB, pair1->phiSR('b'), polOfBin_Pt, polarizationOfFill_B[blueFillNo],hPt); fillCorrectMassBin(hNumberDown_Mass, sumB, pair1->phiSR('b'), polOfBin_Mass, polarizationOfFill_B[blueFillNo],hMass); if(fullEta){fillCorrectEtaBin(hNumberDown_Eta, sumB, pair1->phiSR('b'), polOfBin_Eta, polarizationOfFill_B[blueFillNo],hEta);} } }//done with blue beam if (passInitialCut_Y && useYellowBeam) { //YELLOW BEAM SPIN UP: spin bin 6 and 10 if (pair1->spinBit() == 6 || pair1->spinBit() == 10) { fillCorrectPtBin(hNumberUp_Pt, sumY, pair1->phiSR('y'), polOfBin_Pt, polarizationOfFill_Y[yellowFillNo],hPt); fillCorrectMassBin(hNumberUp_Mass, sumY, pair1->phiSR('y'), polOfBin_Mass, polarizationOfFill_Y[yellowFillNo],hMass); if(fullEta){fillCorrectEtaBin(hNumberUp_Eta, sumY, pair1->phiSR('y'), polOfBin_Eta, polarizationOfFill_Y[yellowFillNo],hEta);} } //YELLOW BEAM SPIN DOWN: spin bit 5 and 9 if (pair1->spinBit() == 5 || pair1->spinBit() == 9) { fillCorrectPtBin(hNumberDown_Pt, sumY, pair1->phiSR('y'), polOfBin_Pt, polarizationOfFill_Y[yellowFillNo],hPt); fillCorrectMassBin(hNumberDown_Mass, sumY, pair1->phiSR('y'), polOfBin_Mass, polarizationOfFill_Y[yellowFillNo],hMass); if(fullEta){fillCorrectEtaBin(hNumberDown_Eta, sumY, pair1->phiSR('y'), polOfBin_Eta, polarizationOfFill_Y[yellowFillNo],hEta);} } }//done with yellow beam }//end trigger check }//end radius check }//end pion tree loop //CALCULATE ASYMMETRY BIN BY BIN cout << "\n"; cout << "<----CALCULATING ASYMMETRY---->" << endl; cout << "\n"; double asymsPt[5]; double asymsMass[5]; double asymsEta[4]; double asymsPtE[5]; double asymsMassE[5]; double asymsEtaE[4]; cout << "\n"; cout << "\n"; cout << "\n \n calcing pt asym " << endl; calcAsym(hAut_Pt, hNumberUp_Pt, hNumberDown_Pt, polOfBin_Pt, asymsPt, asymsPtE); cout << "\n"; cout << "\n"; cout << "\n \n calcing mass asym " << endl; calcAsym(hAut_Mass, hNumberUp_Mass, hNumberDown_Mass, polOfBin_Mass, asymsMass, asymsMassE); cout << "\n"; cout << "\n"; if (fullEta) { cout << "\n \n calcing eta asym " << endl; calcAsymEta(hAut_Eta, hNumberUp_Eta, hNumberDown_Eta, polOfBin_Eta, asymsEta, asymsEtaE); } //PLOT ASYMMETRIES cout << "\n"; cout << "<----PLOTTING ASYMMETRIES---->" << endl; cout << "\n"; double ptPoints[5]; double ptPointsErr[5]; double massPoints[5]; double massPointsErr[5]; double etaPoints[5]; double etaPointsErr[5]; getPtPoints(hPt, ptPoints, ptPointsErr); getMassPoints(hMass, massPoints, massPointsErr); if(fullEta){getEtaPoints(hEta, etaPoints, etaPointsErr);} TCanvas* cAsymPt = new TCanvas(); TGraphErrors* gAsymPt = new TGraphErrors(nPtBins,ptPoints,asymsPt,ptPointsErr,asymsPtE); gAsymPt->Draw("AP"); TCanvas* cAsymMass = new TCanvas(); TGraphErrors* gAsymMass = new TGraphErrors(nMassBins,massPoints,asymsMass,massPointsErr,asymsMassE); gAsymMass->Draw("AP"); if (fullEta) { TCanvas* cAsymEta = new TCanvas(); TGraphErrors* gAsymEta = new TGraphErrors(nEtaBins,etaPoints,asymsEta,etaPointsErr,asymsEtaE); gAsymEta->Draw("AP"); } //DRAW HISTOGRAMS cout << "\n"; cout << "<----DRAWING HISTOGRAMS---->" << endl; cout << "\n"; TCanvas* cPt = new TCanvas("cPt","cPt",1200,600); TCanvas* cMass = new TCanvas("cMass","cMass",1200,600); if(fullEta){TCanvas* cEta = new TCanvas("cEta","cEta",800,600);} //drawAllBins(hPt, cPt); //drawAllBins(hMass, cMass); drawFiveBins(hAut_Pt, cPt); drawFiveBins(hAut_Mass, cMass); if(fullEta){drawFourBins(hAut_Eta, cEta);} TFile* outFile = new TFile(outFileName.c_str(),"recreate"); writeFiveBins(hPt); writeFiveBins(hMass); writeFourBins(hEta); writeFiveBins(hAut_Pt); writeFiveBins(hAut_Mass); if(fullEta){writeFourBins(hAut_Eta);} gAsymPt->Write(); gAsymMass->Write(); if(fullEta){gAsymEta->Write();} /* cPt->SaveAs("./resultsNew_4_22/ptCanvasFullrangeLoEta.png"); cPt->SaveAs("./resultsNew_4_22/ptCanvasFullrangeLoEta.pdf"); cMass->SaveAs("./resultsNew_4_22/massCanvasFullrangeLoEta.png"); cMass->SaveAs("./resultsNew_4_22/massCanvasFullrangeLoEta.pdf"); if(fullEta) { cEta->SaveAs("./resultsNew_4_22/etaCanvasFullrangeHiEta.png"); cEta->SaveAs("./resultsNew_4_22/etaCanvasFullrangeHiEta.pdf"); } */ for (int ibin = 1; ibin <= 16; ibin++) { cout << "bin " << ibin << endl; cout << "Nup = " << hNumberUp_Mass[0]->GetBinContent(ibin) << endl; cout << "Ndown = " << hNumberDown_Mass[0]->GetBinContent(ibin) << endl; } cout << "<----END---->" << endl; }
void sqrtByFill(){ //OPTIONS AND CUTS______________ bool useBlueBeam = true; bool useYellowBeam = true; bool randomizeSpin = false; bool fullEta = true; double PI = 3.14159265359; //LOAD LIBS_____________________ cout << "\n"; gROOT->Macro("StRoot/LoadLibs.C"); gSystem->Load("pionPair"); cout << " loading of pionPair library done" << endl; //______________________________ //SET UP INPUT FILE_____________ TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/schedOut_Full_4_2/allPairs_4_2.root"); string outFileName = "./resultsNew_4_22/pairsFrom4_2ByFill.root"; //______________________________ //SET UP TREE TO RECEIVE INPUT__ pionPair* pair1 = new pionPair(); TTree* pairTree = infile->Get("pionPairTree"); pairTree->SetBranchAddress("pionPair", &pair1); //______________________________ double histMin = -PI; double histMax = PI; const int binNumber = 16; TH1D * hNumberUp = new TH1D("hNumberUp","hNumberUp",binNumber,histMin,histMax); TH1D * hNumberDown = new TH1D("hNumberDown","hNumberDown",binNumber,histMin,histMax); TH1D * hAut = new TH1D("Aut","Aut",binNumber,histMin,histMax); TH1D* polOfBin[16]; for (int i = 0; i < 16; i++) { stringstream ss; ss << i; string fullname = "hPolOfBin_phiSRbin_" + ss.str(); cout << fullname << endl; polOfBin[i] = new TH1D(fullname.c_str(),fullname.c_str(),25,0,1); } //BEAM POLARIZATION_____________ ifstream polFile; polFile.open("/star/u/klandry/ucladisk/2012IFF/BeamPolarization2012.txt"); map<int, double> polarizationOfFill_Y; map<int, double> polErrOfFill_Y; map<int, double> polarizationOfFill_B; map<int, double> polErrOfFill_B; int fill; int beamE; int startT; string plusminus; double pAvrgBlue; double pErrAvrgBlue; double pInitialBlue; double pErrInitialBlue; double dPdTBlue; double dPdTErrBlue; double pAvrgYellow; double pErrAvrgYellow; double pInitialYellow; double pErrInitialYellow; double dPdTYellow; double dPdTErrYellow; string header; for (int i=0; i<19; i++){polFile >> header;} while (!polFile.eof()) { polFile >> fill; polFile >> beamE; polFile >> startT; polFile >> pAvrgBlue; polFile >> plusminus; polFile >> pErrAvrgBlue; polFile >> pInitialBlue; polFile >> plusminus; polFile >> pErrInitialBlue; polFile >> dPdTBlue; polFile >> plusminus; polFile >> dPdTErrBlue; polFile >> pAvrgYellow; polFile >> plusminus; polFile >> pErrAvrgYellow; polFile >> pInitialYellow; polFile >> plusminus; polFile >> pErrInitialYellow; polFile >> dPdTYellow; polFile >> plusminus; polFile >> dPdTErrYellow; polarizationOfFill_B[fill] = pAvrgBlue/100.; polErrOfFill_B[fill] = pErrAvrgBlue/100.; polarizationOfFill_Y[fill] = pAvrgYellow/100.; polErrOfFill_Y[fill] = pErrAvrgYellow/100.; } double avgPolOfBinUp[binNumber]; double polOfBinSumUp[binNumber]; double avgPerrorOfBinUp[binNumber]; double pErrorOfBinUp[binNumber]; double avgPolOfBinDown[binNumber]; double polOfBinSumDown[binNumber]; double avgPerrorOfBinDown[binNumber]; double pErrorOfBinDown[binNumber]; for (int i=0; i<binNumber; i++) { avgPolOfBinUp[i] = 0; polOfBinSumUp[i] = 0; avgPerrorOfBinUp[i] = 0; pErrorOfBinUp[i] = 0; avgPolOfBinDown[i] = 0; polOfBinSumDown[i] = 0; avgPerrorOfBinDown[i] = 0; pErrorOfBinDown[i] = 0; } //CUTS__________________________ double lowLimitPt = ptBinStart[0]; double hiLimitPt = ptBinEnd[4]; double lowLimitEta = etaBinStart[3]; //set up do only do eta bin 3 double hiLimitEta = etaBinEnd[3]; double lowLimitMass = massBinStart[0]; double hiLimitMass = massBinEnd[4]; //______________________________ // ====================================================================== //============================================================================ //START ANALYSIS============================================================== //============================================================================ // ====================================================================== //* cout << "\n"; cout << "<----STARTING ANALYSIS---->" << endl; cout << "\n"; cout << pairTree->GetEntries() << " pairs to analyze" << endl; int blueFillNo; int yellowFillNo; int phiSRbin; vector<double> fillAsyms; vector<double> fillAsymsE; vector<double> fillVec; TLorentzVector sum; TLorentzVector sumY; TLorentzVector sumB; //random number for randomizing spin. //set seed to zero to gaurenty unique numbers each time. TRandom3 r; r.SetSeed(0); int rand5 = 0; int rand6 = 0; int rand9 = 0; int rand10 = 0; int totalPairsFinal = 0; int blueD = 0; int blueU = 0; int yellowD = 0; int yellowU = 0; int pionStarNumber = 0; int runsProcessed = 0; double currentFillNo = 0; double currentRunNo = 0; for (int iPair = pionStarNumber; iPair < pairTree->GetEntries(); iPair++) { if (iPair%10000 == 0) {cout << "processing pair number " << iPair << endl;} //if (iPair == pionStarNumber+300000){break;} pairTree->GetEntry(iPair); //if (runsProcessed > 4){break;} if (pair1->runInfo().beamFillNumber(1) != currentFillNo && currentFillNo != 0 && currentFillNo != 16427) //if (pair1->runInfo().runId() != currentRunNo && currentRunNo != 0) { runsProcessed++; cout << "runsProcessed " << runsProcessed << endl; double* asym = new double(); double* asymE = new double(); calcAsyms(hAut, hNumberUp, hNumberDown, polOfBin, asym, asymE); fillAsyms.push_back(*asym); fillAsymsE.push_back(*asymE); fillVec.push_back(runsProcessed); hNumberUp->Reset(); hNumberDown->Reset(); hAut->Reset(); for (int i=0; i<binNumber; i++) { polOfBin[i]->Reset(); } } else if (currentRunNo == 16427) { //fillAsyms.push_back(*asym); //fillAsymsE.push_back(*asymE); //fillVec.push_back(runsProcessed); hNumberUp->Reset(); hNumberDown->Reset(); hAut->Reset(); for (int i=0; i<binNumber; i++) { polOfBin[i]->Reset(); } } currentRunNo = pair1->runInfo().runId(); currentFillNo = pair1->runInfo().beamFillNumber(1); if (pair1->withinRadius(0.05, 0.3)) { bool triggerFired = false; bool fromKaon = false; bool passInitialCut_B = false; bool passInitialCut_Y = false; bool passDCAcut = false; StTriggerId trigId = pair1->triggerIds(); //JP0,JP1,JP2,AJP if (trigId.isTrigger(370601) || trigId.isTrigger(370611) || trigId.isTrigger(370621) || trigId.isTrigger(370641)) { triggerFired = true; } //BHT0VPD,BHT1VPD,BHT2BBC,BHT2 if (trigId.isTrigger(370501) || trigId.isTrigger(370511) || trigId.isTrigger(370522) || trigId.isTrigger(370531)) { triggerFired = true; } if (triggerFired) { blueFillNo = pair1->runInfo().beamFillNumber(1); //1 = blue beam yellowFillNo = pair1->runInfo().beamFillNumber(0); //0 = yellow beam sum = pair1->piPlusLV() + pair1->piMinusLV(); sumB = sum; //blue beam. //yellow beam must rotate around y axis by pi so the eta cut can be the same for both beams. sumY = sum; sumY.RotateY(PI); if (sumB.Pt() >= lowLimitPt && sumB.Pt() <= hiLimitPt && sumB.M() >= lowLimitMass && sumB.M() <= hiLimitMass && sumB.Eta() >= lowLimitEta && sumB.Eta() <= hiLimitEta) { passInitialCut_B = true; } if (sumY.Pt() >= lowLimitPt && sumY.Pt() <= hiLimitPt && sumY.M() >= lowLimitMass && sumY.M() <= hiLimitMass && sumY.Eta() >= lowLimitEta && sumY.Eta() <= hiLimitEta) { passInitialCut_Y = true; } if (passInitialCut_B && useBlueBeam) { //BLUE BEAM SPIN UP: spin bin 9 and 10 if (pair1->spinBit() == 9 || pair1->spinBit() == 10) { hNumberUp->Fill(pair1->phiSR('b')); phiSRbin = hNumberUp->FindBin(pair1->phiSR('b')); polOfBin[phiSRbin-1]->Fill(polarizationOfFill_B[blueFillNo]); /*if (iPair > 39000) { cout << "polarization = " << polarizationOfFill_B[blueFillNo] << " " << blueFillNo << endl; }*/ } //BLUE BEAM SPIN DOWN: spin bin 5 and 6 if (pair1->spinBit() == 5 || pair1->spinBit() == 6) { hNumberDown->Fill(pair1->phiSR('b')); phiSRbin = hNumberDown->FindBin(pair1->phiSR('b')); polOfBin[phiSRbin-1]->Fill(polarizationOfFill_B[blueFillNo]); } }//done with blue beam if (passInitialCut_Y && useYellowBeam) { //YELLOW BEAM SPIN UP: spin bin 6 and 10 if (pair1->spinBit() == 6 || pair1->spinBit() == 10) { hNumberUp->Fill(pair1->phiSR('y')); phiSRbin = hNumberUp->FindBin(pair1->phiSR('y')); polOfBin[phiSRbin-1]->Fill(polarizationOfFill_Y[yellowFillNo]); } //YELLOW BEAM SPIN DOWN: spin bit 5 and 9 if (pair1->spinBit() == 5 || pair1->spinBit() == 9) { hNumberDown->Fill(pair1->phiSR('y')); phiSRbin = hNumberDown->FindBin(pair1->phiSR('y')); polOfBin[phiSRbin-1]->Fill(polarizationOfFill_Y[yellowFillNo]); } }//done with yellow beam }//end trigger check }//end radius check }//end pion tree loop cout << "out of tree loop" << endl; cout << fillAsyms.size() << endl; TGraphErrors* gAsymVsFill = new TGraphErrors(fillAsyms.size(), &fillVec[0], &fillAsyms[0], 0, &fillAsymsE[0]); gAsymVsFill->Draw("AP"); TFile* outFile = new TFile(outFileName.c_str(),"recreate"); gAsymVsFill->Write(); }
void figureOutpiover2(int ptBin, double ptCutLo, double ptCutHi, int massBin, double mCutLo, double mCutHi, int etaBin, double etaCutLo, double etaCutHi) { //OPTIONS AND CUTS------------ bool useBlueBeam = false; bool useYellowBeam = true; double PI = 3.14159265359; if (useBlueBeam && useYellowBeam) { cout << "using both beams" << endl; } if (useBlueBeam && !useYellowBeam) { cout << "using blue beam" << endl; } if (!useBlueBeam && useYellowBeam) { cout << "using yellow beam" << endl; } //PION PAIR CUTS: /* double ptCutLo = 4; double ptCutHi = 10; double mCutLo = .4; double mCutHi = 1; double etaCutLo = -1.4; double etaCutHi = 1.4; //*/ //double phiCutLo = -.5; //double phiCutHi = .5; //---------------------------- //LOAD LIBS cout << "\n"; gROOT->Macro("StRoot/LoadLibs.C"); gSystem->Load("pionPair"); cout << " loading of pionPair library done" << endl; //SET UP INPUT FILE //TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/all2012dataAll.root"); //TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/schedOutputWithinRad/allWithRadcut.root"); TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/schedOutAllDataTry1/allDataTry1.root"); //SET UP TREE TO RECEIVE INPUT pionPair* pair1 = new pionPair(); TTree* pairTree = infile->Get("pionPairTree"); pairTree->SetBranchAddress("pionPair", &pair1); //SET UP HISTOGRAMS //event variable histograms TH1D* hInvarM = new TH1D("invarM","invarM",80,0,2); TH1D* hEtaTot = new TH1D("etaTot","etaTot",60,-1.5,1.5); TH1D* hPhiR = new TH1D("hPhiR","hPhiR",60,-4,4); TH1D* hPhiS = new TH1D("hPhiS","hPhiS",60,-4,4); TH1D* hPhiSR = new TH1D("hPhiSR","hPhiSR",60,-4,4); TH1D* hTheta = new TH1D("hTheta","hTheta",30,-0.85,4); TH1D* hCosTheta = new TH1D("hCosTheta","hCosTheta",80,-1,1); TH1D* hZ = new TH1D("hZ","hZ",80,0,1); TH1D* hPtot = new TH1D("hPtot","hPtot",80,0,20); TH1D* hPtTOT = new TH1D("hPt","hPt",80,0,15); //histos for asym analysis double histMin = -PI; double histMax = PI; const int binNumber = 16; TH1D * hNumberUp = new TH1D("hNumberUp","hNumberUp",binNumber,histMin,histMax); TH1D * hNumberDown = new TH1D("hNumberDown","hNumberDown",binNumber,histMin,histMax); TH1D * hDiff = new TH1D("hNumberSum","hNumberSum",binNumber,histMin,histMax); TH1D * hAut = new TH1D("Aut","Aut",binNumber,histMin,histMax); //BEAM POLARIZATION ifstream polFile; polFile.open("/star/u/klandry/ucladisk/2012IFF/BeamPolarization2012.txt"); map<int, double> polarizationOfFill_Y; map<int, double> polErrOfFill_Y; map<int, double> polarizationOfFill_B; map<int, double> polErrOfFill_B; int fill; int beamE; int startT; string plusminus; double pAvrgBlue; double pErrAvrgBlue; double pInitialBlue; double pErrInitialBlue; double dPdTBlue; double dPdTErrBlue; double pAvrgYellow; double pErrAvrgYellow; double pInitialYellow; double pErrInitialYellow; double dPdTYellow; double dPdTErrYellow; string header; for (int i=0; i<19; i++) { polFile >> header; } while (!polFile.eof()) { polFile >> fill; polFile >> beamE; polFile >> startT; polFile >> pAvrgBlue; polFile >> plusminus; polFile >> pErrAvrgBlue; polFile >> pInitialBlue; polFile >> plusminus; polFile >> pErrInitialBlue; polFile >> dPdTBlue; polFile >> plusminus; polFile >> dPdTErrBlue; polFile >> pAvrgYellow; polFile >> plusminus; polFile >> pErrAvrgYellow; polFile >> pInitialYellow; polFile >> plusminus; polFile >> pErrInitialYellow; polFile >> dPdTYellow; polFile >> plusminus; polFile >> dPdTErrYellow; polarizationOfFill_B[fill] = pAvrgBlue/100.; polErrOfFill_B[fill] = pErrAvrgBlue/100.; polarizationOfFill_Y[fill] = pAvrgYellow/100.; polErrOfFill_Y[fill] = pErrAvrgYellow/100.; } double avgPolOfBinUp[binNumber]; double polOfBinSumUp[binNumber]; double avgPerrorOfBinUp[binNumber]; double pErrorOfBinUp[binNumber]; double avgPolOfBinDown[binNumber]; double polOfBinSumDown[binNumber]; double avgPerrorOfBinDown[binNumber]; double pErrorOfBinDown[binNumber]; for (int i=0; i<binNumber; i++) { avgPolOfBinUp[i] = 0; polOfBinSumUp[i] = 0; avgPerrorOfBinUp[i] = 0; pErrorOfBinUp[i] = 0; avgPolOfBinDown[i] = 0; polOfBinSumDown[i] = 0; avgPerrorOfBinDown[i] = 0; pErrorOfBinDown[i] = 0; } // ====================================================================== //============================================================================ //START ANALYSIS============================================================== //============================================================================ // ====================================================================== cout << pairTree->GetEntries() << endl; cout << "\n"; cout << "<----STARTING ANALYSIS---->" << endl; cout << "\n"; double blueFillNo; double yellowFillNo; int bin; TLorentzVector sum; TLorentzVector sumY; TLorentzVector sumB; TRandom3 r; int totalPairsFinal = 0; for (int iPair = 0; iPair < pairTree->GetEntries(); iPair++) { if (iPair%10000 == 0) { cout << "processing pair number " << iPair << endl; } //cout << "processing pair number " << iPair << endl; //if (iPair == 80000){break;} pairTree->GetEntry(iPair); if (pair1->withinRadius(0.05, 0.3)) { bool triggerFired = false; bool fromKaon = false; StTriggerId trigId = pair1->triggerIds(); if (trigId.isTrigger(370601) || trigId.isTrigger(370611) || trigId.isTrigger(370621)) { triggerFired = true; } if (trigId.isTrigger(370501) || trigId.isTrigger(370511) || trigId.isTrigger(370522) || trigId.isTrigger(370531)) { triggerFired = true; } if (pair1->invarientMass() > .4921 && pair1->invarientMass() < .4990) { fromKaon = true; } if (triggerFired) { blueFillNo = pair1->runInfo().beamFillNumber(1); //1 = blue beam yellowFillNo = pair1->runInfo().beamFillNumber(0); //0 = yellow beam //cout << blueFillNo << " " << yellowFillNo << endl; if (polarizationOfFill_B[blueFillNo] == 0 || polarizationOfFill_Y[yellowFillNo] == 0) { continue; } hInvarM->Fill(pair1->invarientMass()); TVector3 spinVec; sum = pair1->piPlusLV() + pair1->piMinusLV(); sumB = sum; //blue beam. //yellow beam must rotate around y axis by pi so the eta cut can be the same for both beams. sumY = sum; sumY.RotateY(PI); double randomSpin = r.Uniform(0, 1); int randomSpinBit; if (randomSpin >=0 && randomSpin <0.25) { randomSpinBit = 5; } if (randomSpin >=0.25 && randomSpin <0.5) { randomSpinBit = 6; } if (randomSpin >=0.5 && randomSpin <0.75) { randomSpinBit = 9; } if (randomSpin >=0.75 && randomSpin <1.0) { randomSpinBit = 10; } //CHECK CUTS if (sumB.Pt() > ptCutLo && sumB.Pt() < ptCutHi && sumB.M() > mCutLo && sumB.M() < mCutHi && sumB.Eta() > etaCutLo && sumB.Eta() < etaCutHi && useBlueBeam == true) { //BLUE BEAM SPIN UP: spin bin 9 and 10 if (pair1->spinBit() == 9 || pair1->spinBit() == 10) { bin = hNumberUp->FindBin(pair1->phiSR('b')); //hNumberUp->Fill(pair1->phiSR('b')); polOfBinSumUp[bin] += polarizationOfFill_B[blueFillNo]; pErrorOfBinUp[bin] += polErrOfFill_B[blueFillNo]; } //BLUE BEAM SPIN DOWN: spin bin 5 and 6 if (pair1->spinBit() == 5 || pair1->spinBit() == 6) { bin = hNumberDown->FindBin(pair1->phiSR('b')); hNumberDown->Fill(pair1->phiSR('b')); polOfBinSumDown[bin] += polarizationOfFill_B[blueFillNo]; pErrorOfBinDown[bin] += polErrOfFill_B[blueFillNo]; } }//end blue cuts TVector3 Pa; Pa.SetXYZ(0, 0, 1); //blue is unpolarized beam TVector3 Pb; Pb.SetXYZ(0, 0, -1); //yellow is polarized beam if (sumY.Pt()>ptCutLo && sumY.Pt() < ptCutHi && sumY.M() > mCutLo && sumY.M() < mCutHi && sumY.Eta() > etaCutLo && sumY.Eta() < etaCutHi && useYellowBeam == true) { //YELLOW BEAM SPIN UP: spin bin 6 and 10 //if (pair1->spinBit() == 6 || pair1->spinBit() == 10) if (randomSpinBit == 6 || randomSpinBit == 10) { totalPairsFinal++; spinVec.SetXYZ(0, 1, 0); TVector3 Ph = pair1->piPlusLV().Vect() + pair1->piMinusLV().Vect(); TVector3 Rh = pair1->piPlusLV().Vect() - pair1->piMinusLV().Vect(); double cosPhi_S = -Pb.Unit().Cross(Ph).Unit() * Pb.Unit().Cross(spinVec).Unit(); double cosPhi_R = Ph.Unit().Cross(Pb).Unit() * Ph.Unit().Cross(Rh).Unit(); double sinPhi_S = Ph.Cross(spinVec) * Pb.Unit() / (Pb.Unit().Cross(Ph).Mag() * Pb.Unit().Cross(spinVec).Mag()); double sinPhi_R = Pb.Cross(Rh) * Ph.Unit() / (Ph.Unit().Cross(Pb).Mag() * Ph.Unit().Cross(Rh).Mag()); double sinPhi_S_R = sinPhi_S*cosPhi_R - cosPhi_S*sinPhi_R; double cosPhi_S_R = cosPhi_S*cosPhi_R + sinPhi_S*sinPhi_R; double phi_S_R; if (cosPhi_S_R >= 0) { phi_S_R = asin(sinPhi_S_R); } else if (cosPhi_S_R < 0) { if (sinPhi_S_R >= 0) { phi_S_R = TMath::Pi() - asin(sinPhi_S_R); } if (sinPhi_S_R < 0) { phi_S_R = -TMath::Pi() - asin(sinPhi_S_R); } } //cout << "phisr = " << phi_S_R << endl; bin = hNumberUp->FindBin(phi_S_R); hNumberUp->Fill(phi_S_R); polOfBinSumUp[bin] += polarizationOfFill_Y[yellowFillNo]; pErrorOfBinUp[bin] += polErrOfFill_Y[yellowFillNo]; } //YELLOW BEAM SPIN DOWN: spin bit 5 and 9 if (randomSpinBit == 5 || randomSpinBit == 9) { totalPairsFinal++; spinVec.SetXYZ(0, -1, 0); TVector3 Ph = pair1->piPlusLV().Vect() + pair1->piMinusLV().Vect(); TVector3 Rh = pair1->piPlusLV().Vect() - pair1->piMinusLV().Vect(); double cosPhi_S = -Pb.Unit().Cross(Ph).Unit() * Pb.Unit().Cross(spinVec).Unit(); double cosPhi_R = Ph.Unit().Cross(Pa).Unit() * Ph.Unit().Cross(Rh).Unit(); double sinPhi_S = Ph.Cross(spinVec) * Pb.Unit() / (Pb.Unit().Cross(Ph).Mag() * Pb.Unit().Cross(spinVec).Mag()); double sinPhi_R = Pa.Cross(Rh) * Ph.Unit() / (Ph.Unit().Cross(Pa).Mag() * Ph.Unit().Cross(Rh).Mag()); double sinPhi_S_R = sinPhi_S*cosPhi_R - cosPhi_S*sinPhi_R; double cosPhi_S_R = cosPhi_S*cosPhi_R + sinPhi_S*sinPhi_R; double phi_S_R; if (cosPhi_S_R >= 0) { phi_S_R = asin(sinPhi_S_R); } else if (cosPhi_S_R < 0) { if (sinPhi_S_R >= 0) { phi_S_R = TMath::Pi() - asin(sinPhi_S_R); } if (sinPhi_S_R < 0) { phi_S_R = -TMath::Pi() - asin(sinPhi_S_R); } } // cout << "phisr = " << phi_S_R << endl; bin = hNumberDown->FindBin(phi_S_R); hNumberDown->Fill(phi_S_R); polOfBinSumDown[bin] += polarizationOfFill_Y[yellowFillNo]; pErrorOfBinDown[bin] += polErrOfFill_Y[yellowFillNo]; } }//end yellow cuts }//end triger check }//end radius check }//end pairTree loop //CALCULATE ASYMMETRY BIN BY BIN cout << "\n"; cout << "<----CALCULATING ASYMMETRY---->" << endl; cout << "\n"; //* for (int ibin=1; ibin<=binNumber; ibin++) { if (ibin <= binNumber*0.5) { double nUp = hNumberUp->GetBinContent(ibin); double nUpPi = hNumberUp->GetBinContent(ibin+binNumber*0.5); double nDown = hNumberDown->GetBinContent(ibin); double nDownPi = hNumberDown->GetBinContent(ibin+binNumber*0.5); cout << nUp << " " << nUpPi << " " << nDown << " " << nDownPi << " " << endl; int binIndexPi = ibin+binNumber*0.5; double avgPolA = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi])/(nUp+nDownPi); double avgPolB = (polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUpPi+nDown); double realAvgPol = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi]+polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUp+nUpPi+nDown+nDownPi); } else { double nUp = hNumberUp->GetBinContent(ibin); double nUpPi = hNumberUp->GetBinContent(ibin-binNumber*0.5); double nDown = hNumberDown->GetBinContent(ibin); double nDownPi = hNumberDown->GetBinContent(ibin-binNumber*0.5); int binIndexPi = ibin-binNumber*0.5; cout << nUp << " " << nUpPi << " " << nDown << " " << nDownPi << " " << endl; double avgPolA = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi])/(nUp+nDownPi); double avgPolB = (polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUpPi+nDown); double realAvgPol = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi]+polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUp+nUpPi+nDown+nDownPi); double realAvgPolE = (pErrorOfBinUp[ibin]+pErrorOfBinDown[binIndexPi]+pErrorOfBinUp[binIndexPi]+pErrorOfBinDown[ibin])/(nUp+nUpPi+nDown+nDownPi); } cout << avgPolA << " " << avgPolB << endl; hDiff->SetBinContent(ibin, sqrt(nUp*nDownPi) - sqrt(nDown*nUpPi)); //hAut->SetBinContent(ibin, (1/avgPolA * sqrt(nUp*nDownPi) - 1/avgPolB * sqrt(nDown*nUpPi)) / (sqrt(nUp*nDownPi) + sqrt(nDown*nUpPi)) ); hAut->SetBinContent(ibin, 1/realAvgPol * (sqrt(nUp*nDownPi) - sqrt(nDown*nUpPi)) / (sqrt(nUp*nDownPi) + sqrt(nDown*nUpPi)) ); //error if (realAvgPol*pow(sqrt(nUp*nDownPi)+sqrt(nDown*nUpPi), 2) != 0) { double a = sqrt(nUp*nDownPi); double b = sqrt(nUpPi*nDown); double firstTerm = realAvgPol**2 * (nUpPi*nDown*(nUp+nDownPi) + nDownPi*nUp*(nUpPi+nDown)); //double secondTerm = ((nUp*nDownPi)**2 +(nUpPi*nDown)**2 - 2*nUp*nDown*nUpPi*nDownPi)*realAvgPolE**2; double secondTerm = 0; double binError = 1/realAvgPol**2 * 1/(a+b)**2 * sqrt(firstTerm + secondTerm); } else { double binError = 0.01; cout << "bin " << ibin << " Has problem with error" << endl; } hAut->SetBinError(ibin, binError); }//end Asym calc //*/ //DRAW HISTOGRAMS hInvarM->Draw(); TCanvas* cNup = new TCanvas(); hNumberUp->Draw(); TCanvas* cNdown = new TCanvas(); hNumberDown->Draw(); TCanvas* cAut = new TCanvas(); cAut->SetName("cAut"); TF1* fitFunc = new TF1("fitFunc","[0]*sin(x)+[1]",-PI,PI); //hAut->Fit("fitFunc","R"); hAut->Draw(); hAut->GetXaxis()->SetTitle("#phi_{S} - #phi_{R}"); char title[150]; sprintf(title, "%.1f < P_{T}^{#pi^{+}#pi^{-}} < %.1f %.1f < M_{inv}^{#pi^{+}#pi^{-}} < %.1f %.1f < #eta^{#pi^{+}#pi^{-}} < %.1f", ptCutLo, ptCutHi, mCutLo, mCutHi, etaCutLo, etaCutHi); hAut->SetTitle(title); //SAVE CANVAS stringstream pt; stringstream eta; stringstream mass; string part1 = "_ptBin"; string part2 = "_massBin"; string part3 = "_etaBin"; string ptBinStr; string etaBinStr; string massBinStr; pt << ptBin; eta << etaBin; mass << massBin; if (ptBin == 9) { ptBinStr = "All"; } else { ptBinStr = pt.str(); } if (massBin == 9) { massBinStr = "All"; } else { massBinStr = mass.str(); } if (etaBin == 9) { etaBinStr = "All"; } else { etaBinStr = eta.str(); } cout << "total pairs " << totalPairsFinal << endl; string outFileName = "./resultsTesting/piover2issue"+part1+ptBinStr+part2+massBinStr+part3+etaBinStr+".root"; TFile* outFile = new TFile(outFileName.c_str(),"Recreate"); cout << "---WRITING FILE---" << endl; //cAut->SaveAs(outFileName.c_str()); hAut->Write(); hNumberUp->Write(); hNumberDown->Write(); cout << "---END---" << endl; }
void sqrtMethodSameSign(int ptBin, double ptCutLo, double ptCutHi, int massBin, double mCutLo, double mCutHi, int etaBin, double etaCutLo, double etaCutHi){ //OPTIONS AND CUTS------------ bool useBlueBeam = true; bool useYellowBeam = true; bool randomizeSpin = false; double PI = 3.14159265359; cout << "\n"; if (useBlueBeam && useYellowBeam){cout << "using both beams-----" << endl;} if (useBlueBeam && !useYellowBeam){cout << "using blue beam------" << endl;} if (!useBlueBeam && useYellowBeam){cout << "using yellow beam----" << endl;} cout << "\n"; if (randomizeSpin){cout << "randomizing spin-----" << endl;} //PION PAIR CUTS: /* double ptCutLo = 4; double ptCutHi = 10; double mCutLo = .4; double mCutHi = 1; double etaCutLo = -1.4; double etaCutHi = 1.4; //*/ //double phiCutLo = -.5; //double phiCutHi = .5; //---------------------------- //LOAD LIBS cout << "\n"; gROOT->Macro("StRoot/LoadLibs.C"); gSystem->Load("sameSignPair"); cout << " loading of sameSignPair library done" << endl; //SET UP INPUT FILE TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/schedOut_samesign_4_14/allSameSign_4_14.root"); //SET UP TREE TO RECEIVE INPUT sameSignPair* pair1 = new sameSignPair(); TTree* pairTree = infile->Get("sameSignTree"); pairTree->SetBranchAddress("sameSignPair", &pair1); //SET UP HISTOGRAMS //event variable histograms TH1D* hInvarM = new TH1D("invarM","invarM",80,0,2); TH1D* hEtaTot = new TH1D("etaTot","etaTot",60,-1.5,1.5); TH1D* hPhiR = new TH1D("hPhiR","hPhiR",60,-4,4); TH1D* hPhiS = new TH1D("hPhiS","hPhiS",60,-4,4); TH1D* hPhiSR = new TH1D("hPhiSR","hPhiSR",60,-4,4); TH1D* hTheta = new TH1D("hTheta","hTheta",30,-0.85,4); TH1D* hCosTheta = new TH1D("hCosTheta","hCosTheta",80,-1,1); TH1D* hZ = new TH1D("hZ","hZ",80,0,1); TH1D* hPtot = new TH1D("hPtot","hPtot",80,0,20); TH1D* hPtTOT = new TH1D("hPt","hPt",80,0,15); //histos for asym analysis double histMin = -PI; double histMax = PI; const int binNumber = 16; TH1D * hNumberUp = new TH1D("hNumberUp","hNumberUp",binNumber,histMin,histMax); TH1D * hNumberDown = new TH1D("hNumberDown","hNumberDown",binNumber,histMin,histMax); TH1D * hDiff = new TH1D("hNumberSum","hNumberSum",binNumber,histMin,histMax); TH1D * hAut = new TH1D("Aut","Aut",binNumber,histMin,histMax); //BEAM POLARIZATION ifstream polFile; polFile.open("/star/u/klandry/ucladisk/2012IFF/BeamPolarization2012.txt"); map<int, double> polarizationOfFill_Y; map<int, double> polErrOfFill_Y; map<int, double> polarizationOfFill_B; map<int, double> polErrOfFill_B; int fill; int beamE; int startT; string plusminus; double pAvrgBlue; double pErrAvrgBlue; double pInitialBlue; double pErrInitialBlue; double dPdTBlue; double dPdTErrBlue; double pAvrgYellow; double pErrAvrgYellow; double pInitialYellow; double pErrInitialYellow; double dPdTYellow; double dPdTErrYellow; string header; for (int i=0; i<19; i++){polFile >> header;} while (!polFile.eof()) { polFile >> fill; polFile >> beamE; polFile >> startT; polFile >> pAvrgBlue; polFile >> plusminus; polFile >> pErrAvrgBlue; polFile >> pInitialBlue; polFile >> plusminus; polFile >> pErrInitialBlue; polFile >> dPdTBlue; polFile >> plusminus; polFile >> dPdTErrBlue; polFile >> pAvrgYellow; polFile >> plusminus; polFile >> pErrAvrgYellow; polFile >> pInitialYellow; polFile >> plusminus; polFile >> pErrInitialYellow; polFile >> dPdTYellow; polFile >> plusminus; polFile >> dPdTErrYellow; polarizationOfFill_B[fill] = pAvrgBlue/100.; polErrOfFill_B[fill] = pErrAvrgBlue/100.; polarizationOfFill_Y[fill] = pAvrgYellow/100.; polErrOfFill_Y[fill] = pErrAvrgYellow/100.; } double avgPolOfBinUp[binNumber]; double polOfBinSumUp[binNumber]; double avgPerrorOfBinUp[binNumber]; double pErrorOfBinUp[binNumber]; double avgPolOfBinDown[binNumber]; double polOfBinSumDown[binNumber]; double avgPerrorOfBinDown[binNumber]; double pErrorOfBinDown[binNumber]; for (int i=0; i<binNumber; i++) { avgPolOfBinUp[i] = 0; polOfBinSumUp[i] = 0; avgPerrorOfBinUp[i] = 0; pErrorOfBinUp[i] = 0; avgPolOfBinDown[i] = 0; polOfBinSumDown[i] = 0; avgPerrorOfBinDown[i] = 0; pErrorOfBinDown[i] = 0; } // ====================================================================== //============================================================================ //START ANALYSIS============================================================== //============================================================================ // ====================================================================== cout << pairTree->GetEntries() << endl; cout << "\n"; cout << "<----STARTING ANALYSIS---->" << endl; cout << "\n"; double blueFillNo; double yellowFillNo; int bin; TLorentzVector sum; TLorentzVector sumY; TLorentzVector sumB; //random number for randomizing spin. //set seed to zero to gaurenty unique numbers each time. TRandom3 r; r.SetSeed(0); int rand5 = 0; int rand6 = 0; int rand9 = 0; int rand10 = 0; int totalPairsFinal = 0; int blueD = 0; int blueU = 0; int yellowD = 0; int yellowU = 0; int pionStarNumber = 0; for (int iPair = pionStarNumber; iPair < pairTree->GetEntries(); iPair++) { if (iPair%10000 == 0) {cout << "processing pair number " << iPair << endl;} //if (iPair == pionStarNumber+2000000){break;} pairTree->GetEntry(iPair); if (pair1->withinRadius(0.05, 0.3)) { bool triggerFired = false; bool fromKaon = false; StTriggerId trigId = pair1->triggerIds(); //JP0,JP1,JP2,AJP if (trigId.isTrigger(370601) || trigId.isTrigger(370611) || trigId.isTrigger(370621) || trigId.isTrigger(370641)) { triggerFired = true; } //BHT0VPD,BHT1VPD,BHT2BBC,BHT2 if (trigId.isTrigger(370501) || trigId.isTrigger(370511) || trigId.isTrigger(370522) || trigId.isTrigger(370531)) { triggerFired = true; } if (pair1->invarientMass() > .4921 && pair1->invarientMass() < .4990) { fromKaon = true; } if (triggerFired) { blueFillNo = pair1->runInfo().beamFillNumber(1); //1 = blue beam yellowFillNo = pair1->runInfo().beamFillNumber(0); //0 = yellow beam //cout << blueFillNo << " " << yellowFillNo << endl; if (polarizationOfFill_B[blueFillNo] == 0 || polarizationOfFill_Y[yellowFillNo] == 0) //0 is gap { continue; } hInvarM->Fill(pair1->invarientMass()); sum = pair1->pion1LV() + pair1->pion2LV(); sumB = sum; //blue beam. //yellow beam must rotate around y axis by pi so the eta cut can be the same for both beams. sumY = sum; sumY.RotateY(PI); //cout << pair1->phiS('y')-pair1->phiR('y') << " " << pair1->phiSR('y') << endl; //option for randomizing spin if (randomizeSpin) { int origSpinBit = pair1->spinBit(); double randomSpin = r.Uniform(0, 1); int randomSpinBit; if (randomSpin >=0 && randomSpin <0.25) {randomSpinBit = 5; rand5++;} if (randomSpin >=0.25 && randomSpin <0.5){randomSpinBit = 6; rand6++;} if (randomSpin >=0.5 && randomSpin <0.75){randomSpinBit = 9; rand9++;} if (randomSpin >=0.75 && randomSpin <1.0){randomSpinBit = 10; rand10++;} pair1->setSpinBit(randomSpinBit); } //cout << pair1->sinPhiSR('b') << " " << pair1->cosPhiSR('b') << " " << pair1->phiSR('b') << endl; //MANUALLY ALTER ANGLES FOR TESTING----- /* double testPhiS_y = -pair1->phiS('y'); double testPhiR_y = pair1->phiR('y'); double testPhiS_b = -pair1->phiS('b'); double testPhiR_b = pair1->phiR('b'); double testPhiSR_y = testPhiS_y - testPhiR_y; double testPhiSR_b = testPhiS_b - testPhiR_b; //cout << testPhiS_b << " " << testPhiR_b << " " << testPhiS_y << " " << testPhiR_y << endl; if (testPhiSR_y > PI) { testPhiSR_y -= 2*PI; } if (testPhiSR_y < -PI) { testPhiSR_y += 2*PI; } if (testPhiSR_b > PI) { testPhiSR_b -= 2*PI; } if (testPhiSR_b < -PI) { testPhiSR_b += 2*PI; } //cout << testPhiSR_b << " " << testPhiSR_y << endl; //*/ //CHECK CUTS if (sumB.Pt() > ptCutLo && sumB.Pt() < ptCutHi && sumB.M() > mCutLo && sumB.M() < mCutHi && sumB.Eta() > etaCutLo && sumB.Eta() < etaCutHi && useBlueBeam == true) { //BLUE BEAM SPIN UP: spin bin 9 and 10 if (pair1->spinBit() == 9 || pair1->spinBit() == 10) { blueU++; //make sure to set it back if you randomized it for up/down. //still need origional spin bit to calc anlge. if (randomizeSpin){pair1->setSpinBit(origSpinBit);} bin = hNumberUp->FindBin(pair1->phiSR('b')); hNumberUp->Fill(pair1->phiSR('b')); //bin = hNumberUp->FindBin(testPhiSR_b); //hNumberUp->Fill(testPhiSR_b); polOfBinSumUp[bin] += polarizationOfFill_B[blueFillNo]; pErrorOfBinUp[bin] += polErrOfFill_B[blueFillNo]; //If rondomized spin, have to set the spin bit back to random //for next spin bit check if (randomizeSpin){pair1->setSpinBit(randomSpinBit);} } //BLUE BEAM SPIN DOWN: spin bin 5 and 6 if (pair1->spinBit() == 5 || pair1->spinBit() == 6) { blueD++; if (randomizeSpin){pair1->setSpinBit(origSpinBit);} bin = hNumberDown->FindBin(pair1->phiSR('b')); hNumberDown->Fill(pair1->phiSR('b')); //bin = hNumberDown->FindBin(testPhiSR_b); //hNumberDown->Fill(testPhiSR_b); polOfBinSumDown[bin] += polarizationOfFill_B[blueFillNo]; pErrorOfBinDown[bin] += polErrOfFill_B[blueFillNo]; if (randomizeSpin){pair1->setSpinBit(randomSpinBit);} } }//end blue cuts if (sumY.Pt()>ptCutLo && sumY.Pt() < ptCutHi && sumY.M() > mCutLo && sumY.M() < mCutHi && sumY.Eta() > etaCutLo && sumY.Eta() < etaCutHi && useYellowBeam == true) { //YELLOW BEAM SPIN UP: spin bin 6 and 10 if (pair1->spinBit() == 6 || pair1->spinBit() == 10) { yellowU++; if (randomizeSpin){pair1->setSpinBit(origSpinBit);} bin = hNumberUp->FindBin(pair1->phiSR('y')); hNumberUp->Fill(pair1->phiSR('y')); //bin = hNumberUp->FindBin(testPhiSR_y); //hNumberUp->Fill(testPhiSR_y); polOfBinSumUp[bin] += polarizationOfFill_Y[yellowFillNo]; pErrorOfBinUp[bin] += polErrOfFill_Y[yellowFillNo]; if (randomizeSpin){pair1->setSpinBit(randomSpinBit);} } //YELLOW BEAM SPIN DOWN: spin bit 5 and 9 if (pair1->spinBit() == 5 || pair1->spinBit() == 9) { yellowD++; if (randomizeSpin){pair1->setSpinBit(origSpinBit);} bin = hNumberDown->FindBin(pair1->phiSR('y')); hNumberDown->Fill(pair1->phiSR('y')); //bin = hNumberDown->FindBin(testPhiSR_y); //hNumberDown->Fill(testPhiSR_y); polOfBinSumDown[bin] += polarizationOfFill_Y[yellowFillNo]; pErrorOfBinDown[bin] += polErrOfFill_Y[yellowFillNo]; if (randomizeSpin){pair1->setSpinBit(randomSpinBit);} } }//end yellow cuts }//end triger check }//end radius check }//end pairTree loop //CALCULATE ASYMMETRY BIN BY BIN cout << "\n"; cout << "<----CALCULATING ASYMMETRY---->" << endl; cout << "\n"; for (int ibin=1; ibin<=binNumber; ibin++) { if (ibin <= binNumber*0.5) { double nUp = hNumberUp->GetBinContent(ibin); double nUpPi = hNumberUp->GetBinContent(ibin+binNumber*0.5); double nDown = hNumberDown->GetBinContent(ibin); double nDownPi = hNumberDown->GetBinContent(ibin+binNumber*0.5); int binIndexPi = ibin+binNumber*0.5; double avgPolA = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi])/(nUp+nDownPi); double avgPolB = (polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUpPi+nDown); double realAvgPol = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi]+polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUp+nUpPi+nDown+nDownPi); } else { double nUp = hNumberUp->GetBinContent(ibin); double nUpPi = hNumberUp->GetBinContent(ibin-binNumber*0.5); double nDown = hNumberDown->GetBinContent(ibin); double nDownPi = hNumberDown->GetBinContent(ibin-binNumber*0.5); int binIndexPi = ibin-binNumber*0.5; double avgPolA = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi])/(nUp+nDownPi); double avgPolB = (polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUpPi+nDown); double realAvgPol = (polOfBinSumUp[ibin]+polOfBinSumDown[binIndexPi]+polOfBinSumUp[binIndexPi]+polOfBinSumDown[ibin])/(nUp+nUpPi+nDown+nDownPi); double realAvgPolE = (pErrorOfBinUp[ibin]+pErrorOfBinDown[binIndexPi]+pErrorOfBinUp[binIndexPi]+pErrorOfBinDown[ibin])/(nUp+nUpPi+nDown+nDownPi); } cout << avgPolA << " " << avgPolB << endl; hDiff->SetBinContent(ibin, sqrt(nUp*nDownPi) - sqrt(nDown*nUpPi)); //hAut->SetBinContent(ibin, (1/avgPolA * sqrt(nUp*nDownPi) - 1/avgPolB * sqrt(nDown*nUpPi)) / (sqrt(nUp*nDownPi) + sqrt(nDown*nUpPi)) ); hAut->SetBinContent(ibin, 1/realAvgPol * (sqrt(nUp*nDownPi) - sqrt(nDown*nUpPi)) / (sqrt(nUp*nDownPi) + sqrt(nDown*nUpPi)) ); //error if (realAvgPol*pow(sqrt(nUp*nDownPi)+sqrt(nDown*nUpPi), 2) != 0) { double a = sqrt(nUp*nDownPi); double b = sqrt(nUpPi*nDown); double firstTerm = realAvgPol**2 * (nUpPi*nDown*(nUp+nDownPi) + nDownPi*nUp*(nUpPi+nDown)); //double secondTerm = ((nUp*nDownPi)**2 +(nUpPi*nDown)**2 - 2*nUp*nDown*nUpPi*nDownPi)*realAvgPolE**2; double secondTerm = 0; double binError = 1/realAvgPol**2 * 1/(a+b)**2 * sqrt(firstTerm + secondTerm); } else { double binError = 0.01; cout << "bin " << ibin << " Has problem with error" << endl; } hAut->SetBinError(ibin, binError); }//end Asym calc //DRAW HISTOGRAMS hInvarM->Draw(); TCanvas* cNup = new TCanvas(); hNumberUp->Draw(); TCanvas* cNdown = new TCanvas(); hNumberDown->Draw(); TCanvas* cAut = new TCanvas(); cAut->SetName("cAut"); TF1* fitFunc = new TF1("fitFunc","[0]*cos(x)+[1]",-PI,PI); hAut->Fit("fitFunc","R"); hAut->Draw(); hAut->GetXaxis()->SetTitle("#phi_{S} - #phi_{R}"); char title[150]; sprintf(title, "%.1f < P_{T}^{#pi^{1}#pi^{2}} < %.1f %.1f < M_{inv}^{#pi^{1}#pi^{2}} < %.1f %.1f < #eta^{#pi^{1}#pi^{2}} < %.1f", ptCutLo, ptCutHi, mCutLo, mCutHi, etaCutLo, etaCutHi); hAut->SetTitle(title); cout << "Asym = " << hAut->GetFunction("fitFunc")->GetParameter(0) << endl; cout << "error = " << hAut->GetFunction("fitFunc")->GetParError(0) << endl; cout << "chi2 = " << hAut->GetFunction("fitFunc")->GetChisquare() << endl; cout << "Nup = " << hNumberUp->GetEntries() << endl; cout << "Ndown = " << hNumberDown->GetEntries() << endl; cout << "ran5 = " << rand5 << endl; cout << "ran6 = " << rand6 << endl; cout << "ran9 = " << rand9 << endl; cout << "ran10 = " << rand10 << endl; cout << "blueU = " << blueU << endl; cout << "blueD = " << blueD << endl; cout << "yellowU = " << yellowU << endl; cout << "yellowD = " << yellowD << endl; //SAVE CANVAS stringstream pt; stringstream eta; stringstream mass; string part1 = "_ptBin"; string part2 = "_massBin"; string part3 = "_etaBin"; string ptBinStr; string etaBinStr; string massBinStr; pt << ptBin; eta << etaBin; mass << massBin; if (ptBin == 9){ptBinStr = "All";} else{ ptBinStr = pt.str();} if (massBin == 9){massBinStr = "All";} else{ massBinStr = mass.str();} if (etaBin == 9){etaBinStr = "All";} else{ etaBinStr = eta.str();} cout << "total pairs " << totalPairsFinal << endl; stringstream pionNum; pionNum << pionStarNumber; string pionNumStr = pionNum.str(); string outFileName = "./results_samesign_4_14/sameSign"+part1+ptBinStr+part2+massBinStr+part3+etaBinStr+".root"; TFile* outFile = new TFile(outFileName.c_str(),"Recreate"); cout << "---WRITING FILE---" << endl; //cAut->SaveAs(outFileName.c_str()); hAut->Write(); hNumberUp->Write(); hNumberDown->Write(); cout << "---END---" << endl; }