#include "statTreeAnalyzer.h" #include "TH1.h" #include "TH2.h" #include "TFile.h" statTreeAnalyzer::statTreeAnalyzer(std::string treeName_source, std::string fileName_source, std::string fileName_target) : statTreeAnalyzer_auto(treeName_source,fileName_source) { outfileName = fileName_target; } statTreeAnalyzer::~statTreeAnalyzer() { } void statTreeAnalyzer::rangeSetHelper(double val, double& more, double& less) { if(val>0.) { less = 0.999; more = 1.001; } else { less = 1.001; more = 0.999; } } void statTreeAnalyzer::Loop() { if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; std::cout << outfileName << std::endl; TFile outfile(outfileName.c_str(),"RECREATE"); outfile.mkdir("pull_vs_resStart"); outfile.mkdir("pull_vs_state"); std::cout << outfileName << " 1" <GetEntry(0); const int dimension = state->GetNrows(); //loop over all entries to look for minima and maxima for histo ranges double pull_min[dimension]; double pull_max[dimension]; double res_MCtruth_min[dimension]; double res_MCtruth_max[dimension]; double res_start_min[dimension]; double res_start_max[dimension]; double state_min[dimension]; double state_max[dimension]; double chi2_min; double chi2_max; //init all the values with first entry double less,more; rangeSetHelper(chi2,more,less); chi2_min = less * chi2; chi2_max = more * chi2; for(int i=0;iGetEntry(jentry); nbytes += nb; // if (Cut(ientry) < 0) continue; for(int i=0;i -1000. ) { if((*residMCtruth)[i][0] / sqrt( (*covFit)[i][i] ) < pull_min[i]) { pull_min[i] = (*residMCtruth)[i][0] / sqrt( (*covFit)[i][i] ); } if((*residMCtruth)[i][0] / sqrt( (*covFit)[i][i] ) > pull_max[i]) { pull_max[i] = (*residMCtruth)[i][0] / sqrt( (*covFit)[i][i] ); } } if((*residMCtruth)[i][0] < 1000. && (*residMCtruth)[i][0] > -1000. ) { if((*residMCtruth)[i][0] < res_MCtruth_min[i]) { res_MCtruth_min[i] = (*residMCtruth)[i][0]; } if((*residMCtruth)[i][0] > res_MCtruth_max[i]) { res_MCtruth_max[i] = (*residMCtruth)[i][0]; } } if((*residStart)[i][0] < 1.e5 && (*residStart)[i][0] > -1.e5 ) { if((*residStart)[i][0] < res_start_min[i]) { res_start_min[i] = (*residStart)[i][0]; } if((*residStart)[i][0] > res_start_max[i]) { res_start_max[i] = (*residStart)[i][0]; } } if((*state)[i][0] < 1.e5 && (*state)[i][0] > -1.e5 ) { if((*state)[i][0] < state_min[i]) { state_min[i] = (*state)[i][0]; } if((*state)[i][0] > state_max[i]) { state_max[i] = (*state)[i][0]; } } } if(chi2 > -1.e5 && chi2 < 1.e5) { if(chi2 < chi2_min) { chi2_min = chi2; } if(chi2 > chi2_max) { chi2_max = chi2; } } else { // std::cout << "statTreeAnalyzer trying to find range for chi2-histo: found chi2 value in tree: " // << chi2 << " -> skipping" << endl; } } //create and name the histos TH1D* pull_H[dimension]; TH1D* resStart_H[dimension]; TH1D* resMCtruth_H[dimension]; TH1D* chi2_H; TH2D* pull_vs_resStart_H[dimension][dimension]; TH2D* pull_vs_state_H[dimension][dimension]; TH2D* chi2_vs_resStart_H[dimension]; int nbins = 100; double margin = 0.1; double hist_minX,hist_maxX,par_minX,par_maxX, hist_minY,hist_maxY,par_minY,par_maxY; par_minX = chi2_min; par_maxX = chi2_max; hist_minX = par_minX - margin * (par_maxX-par_minX); hist_maxX = par_maxX + margin * (par_maxX-par_minX); chi2_H = new TH1D("chi2","chi2",nbins,hist_minX,hist_maxX); for(int i=0;iGetEntry(jentry); nbytes += nb; // if (Cut(ientry) < 0) continue; if(!TMath::IsNaN(chi2)) chi2_H->Fill(chi2); for(int i=0;iFill(pullVal); if(!(TMath::IsNaN((*residMCtruth)[i][0])) && (*residMCtruth)[i][0]>-1.e30 && (*residMCtruth)[i][0] < 1.e30) { resMCtruth_H[i]->Fill( (*residMCtruth)[i][0] ); std::cout << (*residMCtruth)[i][0] << std::endl; covFit->Print(); } if(!TMath::IsNaN( (*residStart)[i][0] )) resStart_H[i]->Fill( (*residStart)[i][0] ); for(int j=0;jFill((*residStart)[j][0],pullVal); if(!TMath::IsNaN( (*state)[j][0] ) && !TMath::IsNaN( pullVal ))pull_vs_state_H[i][j]->Fill((*state)[j][0],pullVal); } if(!TMath::IsNaN( (*residStart)[i][0] ) && !TMath::IsNaN( chi2 ))chi2_vs_resStart_H[i]->Fill((*residStart)[i][0],chi2); } } chi2_H->Write(); delete chi2_H; for(int i=0;iWrite(); resMCtruth_H[i]->Write(); resStart_H[i]->Write(); chi2_vs_resStart_H[i]->Write(); outfile.cd("pull_vs_resStart"); for(int j=0;jWrite(); } outfile.cd("pull_vs_state"); for(int j=0;jWrite(); } delete pull_H[i]; delete resMCtruth_H[i]; delete resStart_H[i]; for(int j=0;jGetListOfFiles()->FindObject("statTree.root"); TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(fileName.c_str()); if (!f) { //f = new TFile("statTree.root"); f = new TFile(fileName.c_str()); } tree = (TTree*)gDirectory->Get(treeName.c_str()); if(tree == NULL) { std::cerr << "Error in statTreeAnalyzer-packet:" << std::endl << "tree\"" << treeName << "\" not found in file \"" << fileName << "\" -> abort" << std::endl; throw; } Init(tree); } */