void FluxErr_nomcheck(){ //TFile *fop = TFile::Open("/home/kikawa/for_pm_v3/flux_cov/flux_cov_full.root"); TFile *fop = TFile::Open("/home/cvson/cc1picoh/syst/flux_cov_full.root"); TMatrixDSym *mat = (TMatrixDSym*)fop->Get("flux_cov"); if(mat==NULL){ cout << "Cannot get matrix from " << fop->GetPath() << endl; exit; } float cov_mat[nbin][nbin]; for(int i=0; i<nbin; i++) for(int j=0; j<nbin; j++) cov_mat[i][j] = (*mat)(i+258, j+258); #ifdef MKPLOT draw_matrix(cov_mat); #endif float chol_mat[nbin][nbin]; cholcov_conv(cov_mat, chol_mat); #ifdef MKPLOT draw_matrix(chol_mat); #endif int nthrows = 1000000; float weight[nbin],nrand[nbin]; TH1F* hqeint; TH1F* hqedet; TH1F* hnqeint; TH1F* hnqedet; TH1F* hflux; //TFile *fccqe = new TFile("cccoh.root"); //TFile *fccqe = new TFile("cccoh_frkikawa.root"); //TFile *fccqe = new TFile("cccoh_mva.root"); TFile *fccqe = new TFile("cccoh_nomcheck.root"); hqeint = (TH1F*)fccqe -> Get("qeint");//all signal hnqeint = (TH1F*)fccqe -> Get("nqeint");//all background hqedet = (TH1F*)fccqe -> Get("qedet");//all signal-selected hnqedet = (TH1F*)fccqe -> Get("nqedet");// all background-selected hflux = (TH1F*)fccqe -> Get("flux"); //TFile *fout = new TFile("toymc_nom.root","recreate"); TFile *fout = new TFile("toymc_nomcheck.root","recreate"); TTree *tree = new TTree("tree","tree"); //float pm,ing,pm_int,ing_int,pm_det,ing_det; //float pm_ccint,ing_ccint,pm_ccdet,ing_ccdet,pm_ncint,ing_ncint,pm_ncdet,ing_ncdet,pm_cceff,ing_cceff,pm_nceff,ing_nceff,pm_flux,ing_flux; float qeint,nqeint, qedet,nqedet, qeeff,nqeeff, flux; tree->Branch("qeint",&qeint,"qeint/F");//all signal interaction tree->Branch("nqeint",&nqeint,"nqeint/F");//all background interaction tree->Branch("qedet",&qedet,"qedet/F");// all selected-signal tree->Branch("nqedet",&nqedet,"nqedet/F");//all selected-background tree->Branch("qeeff",&qeeff,"qeeff/F");//efficiency of signal selection tree->Branch("nqeeff",&nqeeff,"nqeeff/F");//efficiency of background selection tree->Branch("flux",&flux,"flux/F"); //float pm0_ccint=0,ing0_ccint=0,pm0_ccdet=0,ing0_ccdet=0,pm0_ncint=0,ing0_ncint=0,pm0_ncdet=0,ing0_ncdet=0,pm0_cceff=0,ing0_cceff=0,pm0_nceff=0,ing0_nceff=0,pm0_flux=0,ing0_flux=0; float qeint_nomi=0,nqeint_nomi=0, qedet_nomi=0,nqedet_nomi=0, qeeff_nomi=0,nqeeff_nomi=0, flux_nomi=0; for(int j=0;j<nbin;j++){ qeint_nomi += hqeint -> GetBinContent(j+1); nqeint_nomi += hnqeint -> GetBinContent(j+1); qedet_nomi += hqedet -> GetBinContent(j+1); nqedet_nomi += hnqedet -> GetBinContent(j+1); flux_nomi += hflux -> GetBinContent(j+1); } //make toy simulation for(int i=0;i<nthrows;i++){ if(i%10000==0)cout<<i<<endl; //pm_ccint=0,ing_ccint=0,pm_ccdet=0,ing_ccdet=0,pm_ncint=0,ing_ncint=0,pm_ncdet=0,ing_ncdet=0,pm_cceff=0,ing_cceff=0,pm_nceff=0,ing_nceff=0,pm_flux=0,ing_flux=0; qeint=0;nqeint=0; qedet=0;nqedet=0; qeeff=0;nqeeff=0; flux=0; for(int k=0;k<nbin;k++){ nrand[k]=rand.Gaus();//gaussian random } //fluctuate the weight for(int j=0;j<nbin;j++){ weight[j]=1; for(int k=0;k<=j;k++){ weight[j]+=chol_mat[j][k]*nrand[k]; } qeint += hqeint -> GetBinContent(j+1)*weight[j]; nqeint += hnqeint -> GetBinContent(j+1)*weight[j]; qedet += hqedet -> GetBinContent(j+1)*weight[j]; nqedet += hnqedet -> GetBinContent(j+1)*weight[j]; flux += hflux -> GetBinContent(j+1)*weight[j]; } qeint /= qeint_nomi; nqeint /= nqeint_nomi; qedet /= qedet_nomi; nqedet /= nqedet_nomi; flux /= flux_nomi; qeeff = qedet/qeint; nqeeff = nqedet/nqeint; tree->Fill(); } tree->Write(); hqedet ->Write(); hnqedet ->Write(); fout->Close(); }
///////////////////////////////////////////////// //// Save Histograms or Profiles /// ///////////////////////////////////////////////// void hist_files::save(const char* root_name, bool ps, bool debug) { // skip saving if histograms do not exist! if( size()==0 ) return; gStyle->SetCanvasColor(0); gStyle->SetPadColor(0); gStyle->SetOptStat(111111); TCanvas c1; TFile *hist = new TFile(root_name); cout << "Saving histograms to file to " << hist->GetPath() << endl; if (debug) cout << "hist_files::save: 1D_HISTOS=" << size1D() << endl << flush; for(map<TString, TH1D*>::iterator it_1d = hist_files_1d.begin(); it_1d != hist_files_1d.end(); it_1d++) if ((*it_1d).first != "" && (*it_1d).second != NULL) { if (debug) cout << "hist_files::save: 1D_NAME=" << ((*it_1d).second)->GetName() << endl << flush; TString fn = ((*it_1d).second)->GetName(); fn = fn + ".ps"; ((*it_1d).second)->Draw(); ((*it_1d).second)->Write(); if(ps) c1.Print(fn); } if (debug) cout << "hist_files::save: 2D_HISTOS=" << size2D() << endl << flush; for(map<TString, TH2D*>::iterator it_2d = hist_files_2d.begin(); it_2d != hist_files_2d.end(); it_2d++) if ((*it_2d).first != "" && (*it_2d).second != NULL) { if (debug) cout << "hist_files::save: 2D_NAME=" << ((*it_2d).second)->GetName() << endl << flush; TString fn = ((*it_2d).second)->GetName(); fn = fn + ".ps"; ((*it_2d).second)->Draw(); ((*it_2d).second)->Write(); if(ps) c1.Print(fn); } if (debug) cout << "hist_files::save: 3D_HISTOS=" << size3D() << endl << flush; for(map<TString, TH3D*>::iterator it_3d = hist_files_3d.begin(); it_3d != hist_files_3d.end(); it_3d++) if ((*it_3d).first != "" && (*it_3d).second != NULL) { if (debug) cout << "hist_files::save: 3D_NAME=" << ((*it_3d).second)->GetName() << endl << flush; TString fn = ((*it_3d).second)->GetName(); fn = fn + ".ps"; ((*it_3d).second)->Draw(); ((*it_3d).second)->Write(); if(ps) c1.Print(fn); } if (debug) cout << "hist_files::save: PROFILE_HISTOS=" << sizeProfile() << endl << flush; for(map<TString, TProfile*>::iterator it_profile = hist_files_profile.begin(); it_profile != hist_files_profile.end(); it_profile++) if ((*it_profile).first != "" && (*it_profile).second != NULL) { if (debug) cout << "hist_files::save: PROFILE_NAME=" << ((*it_profile).second)->GetName() << endl << flush; TString fn = ((*it_profile).second)->GetName(); fn = fn + ".ps"; ((*it_profile).second)->Draw(); ((*it_profile).second)->Write(); if(ps) c1.Print(fn); } if (debug) cout << "hist_files::save: PROFILE_2D_HISTOS=" << sizeProfile2D() << endl << flush; for(map<TString, TProfile2D*>::iterator it_profile_2d = hist_files_profile_2d.begin(); it_profile_2d != hist_files_profile_2d.end(); it_profile_2d++) if ((*it_profile_2d).first != "" && (*it_profile_2d).second != NULL) { if (debug) cout << "hist_files::save: PROFILE_2D_NAME=" << ((*it_profile_2d).second)->GetName() << endl << flush; TString fn = ((*it_profile_2d).second)->GetName(); fn = fn + ".ps"; ((*it_profile_2d).second)->Draw(); ((*it_profile_2d).second)->Write(); if(ps) c1.Print(fn); } hist->Close(); cout << "Done." << endl; }