diff --git a/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.cxx b/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.cxx index e1ed1d0..f333b23 100644 --- a/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.cxx +++ b/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.cxx @@ -1,275 +1,164 @@ // Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret /******************************************************************************* * This file is part of NUISANCE. * * NUISANCE is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * NUISANCE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NUISANCE. If not, see . *******************************************************************************/ #include "T2K_SignalDef.h" #include "T2K_CC0pi_XSec_2DPcos_nu.h" //******************************************************************** T2K_CC0pi_XSec_2DPcos_nu::T2K_CC0pi_XSec_2DPcos_nu(nuiskey samplekey) { //******************************************************************** // Sample overview --------------------------------------------------- std::string descrip = "T2K_CC0pi_XSec_2DPcos_nu sample. \n" \ "Target: CH \n" \ "Flux: MINERvA Medium Energy FHC numu \n" \ "Signal: CC-inclusive with theta < 20deg \n"; // Setup common settings fSettings = LoadSampleSettings(samplekey); fSettings.SetDescription(descrip); fSettings.SetXTitle("P_{#mu} (GeV)"); fSettings.SetYTitle("cos#theta_{#mu}"); fSettings.SetZTitle("d^{2}#sigma/dP_{#mu}dcos#theta_{#mu} (cm^{2}/GeV)"); fSettings.SetAllowedTypes("DIAG,FULL/FREE,SHAPE,FIX/SYSTCOV/STATCOV","FIX"); fSettings.SetEnuRange(0.0, 10.0); fSettings.DefineAllowedTargets("C,H"); if (fName == "T2K_CC0pi_XSec_2DPcos_nu_I") fAnalysis = 1; else fAnalysis = 2; // CCQELike plot information fSettings.SetTitle("T2K_CC0pi_XSec_2DPcos_nu"); fSettings.DefineAllowedSpecies("numu"); forwardgoing = (fSettings.GetS("type").find("REST") != std::string::npos); FinaliseSampleSettings(); // Scaling Setup --------------------------------------------------- // ScaleFactor automatically setup for DiffXSec/cm2/Nucleon fScaleFactor = ((GetEventHistogram()->Integral("width")/(fNEvents+0.)) * 1E-38 / (TotalIntegratedFlux())); // Setup Histograms SetHistograms(); - StatUtils::SetDataErrorFromCov(fDataHist, fFullCovar, fMapHist, 1E-38); // Final setup --------------------------------------------------- FinaliseMeasurement(); }; bool T2K_CC0pi_XSec_2DPcos_nu::isSignal(FitEvent *event){ return SignalDef::isT2K_CC0pi(event, EnuMin, EnuMax, forwardgoing); }; void T2K_CC0pi_XSec_2DPcos_nu::FillEventVariables(FitEvent* event){ if (event->NumFSParticle(13) == 0) return; TLorentzVector Pnu = event->GetNeutrinoIn()->fP; TLorentzVector Pmu = event->GetHMFSParticle(13)->fP; double pmu = Pmu.Vect().Mag()/1000.; double CosThetaMu = cos(Pnu.Vect().Angle(Pmu.Vect())); fXVar = pmu; fYVar = CosThetaMu; return; }; -// Modification is needed after the full reconfigure to move bins around -// Otherwise this would need to be replaced by a TH2Poly which is too awkward. -void T2K_CC0pi_XSec_2DPcos_nu::ConvertEventRates(){ - - // Do standard conversion. - Measurement2D::ConvertEventRates(); - - if (fAnalysis == 1){ - - // Following code handles weird ND280 Binning - int nbins = this->fMCHist->GetNbinsX() + 1; - double total = 0.0; - - // Y = 1 - total = 0.0; - for (int i = 3; i < nbins; i++){ - - double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(1); - total += this->fMCHist->GetBinContent(i, 1) * width; - this->fMCHist->SetBinContent(i,1,0); - } - this->fMCHist->SetBinContent(3, 1, total / (1.0 * 29.6)); - - // Y = 2 - total = 0.0; - for (int i = 5; i < nbins; i++){ - double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(2); - total += this->fMCHist->GetBinContent(i, 2)* width; - this->fMCHist->SetBinContent(i,2,0); - } - this->fMCHist->SetBinContent(5, 2, total / (0.6 *29.4)); - - // Y = 3 - total = 0.0; - for (int i = 7; i < nbins; i++){ - double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(3); - total += this->fMCHist->GetBinContent(i, 3)* width; - this->fMCHist->SetBinContent(i, 3,0); - } - this->fMCHist->SetBinContent(7, 3, total/ (0.1 * 29.2)); - - // Y = 4 - total = 0.0; - for (int i = 7; i < nbins; i++){ - double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(4); - total += this->fMCHist->GetBinContent(i, 4)* width; - this->fMCHist->SetBinContent(i, 4,0); - } - this->fMCHist->SetBinContent(7, 4, total / (0.1 * 29.2)); - - // Y = 5 - total = 0.0; - for (int i = 8; i < nbins; i++){ - double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(5); - total += this->fMCHist->GetBinContent(i, 5)* width; - this->fMCHist->SetBinContent(i,5,0); - } - this->fMCHist->SetBinContent(8, 5, total / (0.05 * 29.0)); - - // Y = 6 - total = 0.0; - for (int i = 9; i < nbins; i++){ - double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(6); - total += this->fMCHist->GetBinContent(i, 6)* width; - this->fMCHist->SetBinContent(i, 6,0); - } - this->fMCHist->SetBinContent(9, 6, total / (0.05 * 28.5)); - - // Y = 7 - total = 0.0; - for (int i = 8; i < nbins; i++){ - double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(7); - total += this->fMCHist->GetBinContent(i, 7)* width; - this->fMCHist->SetBinContent(i, 7,0); - } - this->fMCHist->SetBinContent(8, 7, total/ (0.04 * 28.0)); - - // Y = 8 - total = 0.0; - for (int i = 11; i < nbins; i++){ - double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(8); - total += this->fMCHist->GetBinContent(i, 8)* width; - this->fMCHist->SetBinContent(i, 8,0); - } - this->fMCHist->SetBinContent(11, 8, total / (0.4 * 27.0)); - - // Y = 9 - total = 0.0; - for (int i = 9; i < nbins; i++){ - double width = this->fMCHist->GetXaxis()->GetBinWidth(i) * this->fMCHist->GetYaxis()->GetBinWidth(9); - total += this->fMCHist->GetBinContent(i, 9)* width; - this->fMCHist->SetBinContent(i,9,0); - } - this->fMCHist->SetBinContent(9, 9, total / (0.02 * 25.0)); - } - - return; -} - - void T2K_CC0pi_XSec_2DPcos_nu::SetHistograms(){ fIsSystCov = fSettings.GetS("type").find("SYSTCOV") != std::string::npos; fIsStatCov = fSettings.GetS("type").find("STATCOV") != std::string::npos; fIsNormCov = fSettings.GetS("type").find("NORMCOV") != std::string::npos; fNDataPointsX = 12; fNDataPointsY = 10; // Open file std::string infile = FitPar::GetDataBase()+"/T2K/CC0pi/T2K_CC0PI_2DPmuCosmu_Data.root"; TFile* rootfile = new TFile(infile.c_str(), "READ"); TH2D* tempcov = NULL; // ANALYSIS 2 if (fAnalysis == 2){ // Get Data fDataHist = (TH2D*) rootfile->Get("analysis2_data"); fDataHist->SetDirectory(0); fDataHist->SetNameTitle((fName + "_data").c_str(), (fName + "_data" + fPlotTitles).c_str()); // Get Map fMapHist = (TH2I*) rootfile->Get("analysis2_map"); fMapHist->SetDirectory(0); fMapHist->SetNameTitle((fName + "_map").c_str(), (fName + "_map" + fPlotTitles).c_str()); // Get Syst/Stat Covar TH2D* tempsyst = (TH2D*) rootfile->Get("analysis2_systcov"); TH2D* tempstat = (TH2D*) rootfile->Get("analysis2_statcov"); TH2D* tempnorm = (TH2D*) rootfile->Get("analysis2_normcov"); // Create covar [Default is both] tempcov = (TH2D*) tempsyst->Clone(); tempcov->Reset(); if (fIsSystCov) tempcov->Add(tempsyst); if (fIsStatCov) tempcov->Add(tempstat); if (fIsNormCov) tempcov->Add(tempnorm); if (!fIsSystCov && !fIsStatCov && !fIsNormCov){ tempcov->Add(tempsyst); tempcov->Add(tempstat); tempcov->Add(tempnorm); } - - // SARAS ANALYSIS - } else if (fAnalysis == 1){ - - //TODO (P.Stowell) Add a TH2Poly Measurement class - ERR(FTL) << "T2K CC0Pi Analysis 1 is not yet available due to its awkward binning!" << std::endl; - ERR(FTL) << "If you want to use it, add a TH2Poly Class!" << std::endl; - throw; - } + if (!tempcov){ ERR(FTL) << "TEMPCOV NOT SET" << std::endl; throw; } // Setup Covar int nbins = tempcov->GetNbinsX(); fFullCovar = new TMatrixDSym(nbins); for (int i = 0; i < nbins; i++){ for (int j = 0; j < nbins; j++){ - (*fFullCovar)(i,j) = tempcov->GetBinContent(i+1,j+1); - } } covar = StatUtils::GetInvert(fFullCovar); fDecomp = StatUtils::GetDecomp(covar); // Set Data Errors StatUtils::SetDataErrorFromCov(fDataHist, fFullCovar, fMapHist, 1E-38); // Remove root file rootfile->Close(); return; }; diff --git a/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.h b/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.h index a856cef..afcbb61 100644 --- a/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.h +++ b/src/T2K/T2K_CC0pi_XSec_2DPcos_nu.h @@ -1,67 +1,67 @@ // Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret /******************************************************************************* * This file is part of NUISANCE. * * NUISANCE is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * NUISANCE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NUISANCE. If not, see . *******************************************************************************/ #ifndef T2K_CC0PI_2DPCOS_NU_H_SEEN #define T2K_CC0PI_2DPCOS_NU_H_SEEN #include "Measurement2D.h" class T2K_CC0pi_XSec_2DPcos_nu : public Measurement2D { public: /// Basic Constructor. /// /brief Parses two different measurements. /// /// T2K_CC0pi_XSec_2DPcos_nu -> T2K CC0PI Analysis 2 /// T2K_CC0pi_XSec_2DPcos_nu_I -> T2K CC0PI Analysis 1 /// T2K_CC0pi_XSec_2DPcos_nu_II -> T2K CC0PI Analysis 2 T2K_CC0pi_XSec_2DPcos_nu(nuiskey samplekey); /// Virtual Destructor ~T2K_CC0pi_XSec_2DPcos_nu() {}; /// Numu CC0PI Signal Definition /// /// /item bool isSignal(FitEvent *nvect); /// Read histograms in a special way because format is different. /// Read from FitPar::GetDataBase()+"/T2K/CC0pi/T2K_CC0PI_2DPmuCosmu_Data.root" void SetHistograms(); /// Bin Tmu CosThetaMu void FillEventVariables(FitEvent* customEvent); /// Have to do a weird event scaling for analysis 1 - void ConvertEventRates(); + // void ConvertEventRates(); private: bool forwardgoing; bool only_allowed_particles; bool numu_event; double numu_energy; int particle_pdg; double pmu, CosThetaMu; int fAnalysis; bool fIsSystCov, fIsStatCov, fIsNormCov; }; #endif diff --git a/src/T2K/T2K_CC0pi_XSec_2DPcos_nu_nonuniform.cxx b/src/T2K/T2K_CC0pi_XSec_2DPcos_nu_nonuniform.cxx index 9f83362..d55c194 100644 --- a/src/T2K/T2K_CC0pi_XSec_2DPcos_nu_nonuniform.cxx +++ b/src/T2K/T2K_CC0pi_XSec_2DPcos_nu_nonuniform.cxx @@ -1,210 +1,215 @@ // Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret /******************************************************************************* * This file is part of NUISANCE. * * NUISANCE is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * NUISANCE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NUISANCE. If not, see . *******************************************************************************/ #include "T2K_SignalDef.h" #include "T2K_CC0pi_XSec_2DPcos_nu_nonuniform.h" //******************************************************************** T2K_CC0pi_XSec_2DPcos_nu_nonuniform::T2K_CC0pi_XSec_2DPcos_nu_nonuniform(nuiskey samplekey) { //******************************************************************** // Sample overview --------------------------------------------------- std::string descrip = "T2K_CC0pi_XSec_2DPcos_nu_nonuniform sample. \n" \ "Target: CH \n" \ "Flux: MINERvA Medium Energy FHC numu \n" \ "Signal: CC-inclusive with theta < 20deg \n"; // Setup common settings fSettings = LoadSampleSettings(samplekey); fSettings.SetDescription(descrip); fSettings.SetXTitle("P_{#mu} (GeV)"); fSettings.SetYTitle("cos#theta_{#mu}"); fSettings.SetZTitle("d^{2}#sigma/dP_{#mu}dcos#theta_{#mu} (cm^{2}/GeV)"); fSettings.SetAllowedTypes("FULL,DIAG/FREE,SHAPE,FIX/SYSTCOV/STATCOV","FIX/FULL"); fSettings.SetEnuRange(0.0, 10.0); fSettings.DefineAllowedTargets("C,H"); fAnalysis = 1; // CCQELike plot information fSettings.SetTitle("T2K_CC0pi_XSec_2DPcos_nu_nonuniform"); fSettings.DefineAllowedSpecies("numu"); forwardgoing = (fSettings.GetS("type").find("REST") != std::string::npos); FinaliseSampleSettings(); // Scaling Setup --------------------------------------------------- // ScaleFactor automatically setup for DiffXSec/cm2/Nucleon fScaleFactor = ((GetEventHistogram()->Integral("width")/(fNEvents+0.)) * 1E-38 / (TotalIntegratedFlux())); // Setup Histograms SetHistograms(); // Final setup --------------------------------------------------- FinaliseMeasurement(); }; bool T2K_CC0pi_XSec_2DPcos_nu_nonuniform::isSignal(FitEvent *event){ return SignalDef::isT2K_CC0pi(event, EnuMin, EnuMax, forwardgoing); }; void T2K_CC0pi_XSec_2DPcos_nu_nonuniform::FillEventVariables(FitEvent* event){ if (event->NumFSParticle(13) == 0) return; TLorentzVector Pnu = event->GetNeutrinoIn()->fP; TLorentzVector Pmu = event->GetHMFSParticle(13)->fP; double pmu = Pmu.Vect().Mag()/1000.; double CosThetaMu = cos(Pnu.Vect().Angle(Pmu.Vect())); fXVar = pmu; fYVar = CosThetaMu; return; }; void T2K_CC0pi_XSec_2DPcos_nu_nonuniform::FillHistograms(){ Measurement1D::FillHistograms(); if (Signal){ fMCHist_Fine2D->Fill( fXVar, fYVar, Weight ); FillMCSlice( fXVar, fYVar, Weight ); } } // Modification is needed after the full reconfigure to move bins around // Otherwise this would need to be replaced by a TH2Poly which is too awkward. void T2K_CC0pi_XSec_2DPcos_nu_nonuniform::ConvertEventRates(){ + for (int i = 0; i < 9; i++){ + fMCHist_Slices[i]->GetSumw2(); + } + // Do standard conversion. Measurement1D::ConvertEventRates(); // First scale MC slices also by their width in Y fMCHist_Slices[0]->Scale(1.0 / 1.00); fMCHist_Slices[1]->Scale(1.0 / 0.60); fMCHist_Slices[2]->Scale(1.0 / 0.10); fMCHist_Slices[3]->Scale(1.0 / 0.10); fMCHist_Slices[4]->Scale(1.0 / 0.05); fMCHist_Slices[5]->Scale(1.0 / 0.05); fMCHist_Slices[6]->Scale(1.0 / 0.04); fMCHist_Slices[7]->Scale(1.0 / 0.04); fMCHist_Slices[8]->Scale(1.0 / 0.02); // Now Convert into 1D list fMCHist->Reset(); int bincount = 0; for (int i = 0; i < 9; i++){ for (int j = 0; j < fDataHist_Slices[i]->GetNbinsX(); j++){ fMCHist->SetBinContent(bincount+1, fMCHist_Slices[i]->GetBinContent(j+1)); + fMCHist->SetBinError(bincount+1, fMCHist_Slices[i]->GetBinError(j+1)); bincount++; } } return; } void T2K_CC0pi_XSec_2DPcos_nu_nonuniform::FillMCSlice(double x, double y, double w){ if (y >= -1.0 and y < 0.0) fMCHist_Slices[0]->Fill(x,w); else if (y >= 0.0 and y < 0.6) fMCHist_Slices[1]->Fill(x,w); else if (y >= 0.6 and y < 0.7) fMCHist_Slices[2]->Fill(x,w); else if (y >= 0.7 and y < 0.8) fMCHist_Slices[3]->Fill(x,w); else if (y >= 0.8 and y < 0.85) fMCHist_Slices[4]->Fill(x,w); else if (y >= 0.85 and y < 0.90) fMCHist_Slices[5]->Fill(x,w); else if (y >= 0.90 and y < 0.94) fMCHist_Slices[6]->Fill(x,w); else if (y >= 0.94 and y < 0.98) fMCHist_Slices[7]->Fill(x,w); else if (y >= 0.98 and y <= 1.00) fMCHist_Slices[8]->Fill(x,w); } void T2K_CC0pi_XSec_2DPcos_nu_nonuniform::SetHistograms(){ // Read in 1D Data Histograms fInputFile = new TFile( (FitPar::GetDataBase() + "/T2K/CC0pi/T2K_CC0PI_2DPmuCosmu_Data.root").c_str(),"READ"); fInputFile->ls(); // Read in 1D Data fDataHist = (TH1D*) fInputFile->Get("datahist"); fMCHist_Fine2D = new TH2D("T2K_CC0pi_XSec_2DPcos_nu_nonuniform_Fine2D","T2K_CC0pi_XSec_2DPcos_nu_nonuniform_Fine2D", 400, 0.0,30.0,100,-1.0,1.0); SetAutoProcessTH1(fMCHist_Fine2D); TH2D* tempcov = (TH2D*) fInputFile->Get("analysis1_totcov"); fFullCovar = new TMatrixDSym(fDataHist->GetNbinsX()); for (int i = 0; i < fDataHist->GetNbinsX(); i++){ for (int j = 0; j < fDataHist->GetNbinsX(); j++){ (*fFullCovar)(i,j) = tempcov->GetBinContent(i+1, j+1); } } covar = StatUtils::GetInvert(fFullCovar); fDecomp = StatUtils::GetDecomp(fFullCovar); // Read in 2D Data fDataPoly = (TH2Poly*) fInputFile->Get("datapoly"); fDataPoly->SetNameTitle("T2K_CC0pi_XSec_2DPcos_nu_nonuniform_datapoly","T2K_CC0pi_XSec_2DPcos_nu_nonuniform_datapoly"); SetAutoProcessTH1(fDataPoly, kCMD_Write); fDataHist->Reset(); // Read in 2D Data Slices and Make MC Slices int bincount = 0; for (int i = 0; i < 9; i++){ // Get Data Histogram fInputFile->ls(); fDataHist_Slices.push_back((TH1D*)fInputFile->Get(Form("dataslice_%i",i))->Clone()); fDataHist_Slices[i]->SetNameTitle(Form("T2K_CC0pi_XSec_2DPcos_nu_nonuniform_data_Slice%i",i), (Form("T2K_CC0pi_XSec_2DPcos_nu_nonuniform_data_Slice%i",i))); // Loop over nbins and set errors from covar for (int j = 0; j < fDataHist_Slices[i]->GetNbinsX(); j++){ fDataHist_Slices[i]->SetBinError(j+1, sqrt((*fFullCovar)(bincount,bincount)) * 1E-38); std::cout << "Setting data hist " << fDataHist_Slices[i]->GetBinContent(j+1) << " " << fDataHist_Slices[i]->GetBinError(j+1) << std::endl; fDataHist->SetBinContent(bincount+1, fDataHist_Slices[i]->GetBinContent(j+1) ); fDataHist->SetBinError(bincount+1, fDataHist_Slices[i]->GetBinError(j+1) ); bincount++; } // Make MC Clones fMCHist_Slices.push_back((TH1D*) fDataHist_Slices[i]->Clone()); fMCHist_Slices[i]->SetNameTitle(Form("T2K_CC0pi_XSec_2DPcos_nu_nonuniform_MC_Slice%i",i), (Form("T2K_CC0pi_XSec_2DPcos_nu_nonuniform_MC_Slice%i",i))); SetAutoProcessTH1(fDataHist_Slices[i],kCMD_Write); SetAutoProcessTH1(fMCHist_Slices[i]); // fMCHist_Slices[i]->Reset(); } return; };