#include "fQROOTOut.h" #include #include #include #include #include #include #include "spliTChanOutC.h" #include "fitqunoutC.h" #include "TKey.h" #include "TROOT.h" fQROOTOut::fQROOTOut(char *ofname){ oFile = NULL; trout = NULL; oFile = new TFile(ofname,"RECREATE"); if (oFile->IsZombie()) { std::cout << "fQROOTOut: Failed to open output file : " << ofname << std::endl; exit(-1); } else { std::cout << "fiTQun ROOT output : " << ofname << std::endl; } InitTree(); } fQROOTOut::~fQROOTOut(){ SaveTree(); std::cout << "Destructing fQROOTOut!!" << std::endl; } void fQROOTOut::Fill(){ if (trout) { trout->Fill(); } else { std::cout << "fQROOTOut: Cannot fill the tree!" << std::endl; } } void fQROOTOut::SaveTree(){ if (oFile) { oFile->cd(); std::cout << "fQROOTOut: Saving tree..."; trout->Write(); delete trout; oFile->Close(); delete oFile; std::cout << "done!" << std::endl; trout=NULL; oFile=NULL; } } void fQROOTOut::CopyInput(char* infile, std::string treeList){ bool noCopyTree = (treeList.find("nocopy")!= std::string::npos); bool copyAll = (treeList.find("all")!= std::string::npos); if (oFile) { TFile input(infile, "READ"); oFile->cd(); TKey *key; TIter nextkey(input.GetListOfKeys()); while ((key = (TKey*)nextkey())) { const char *classname = key->GetClassName(); TClass *cl = gROOT->GetClass(classname); if (!cl) continue; if (cl->InheritsFrom("TTree")) { std::string name = key->GetName(); if(noCopyTree){ if(treeList.find(name)!=std::string::npos) continue; } else if (!copyAll){ if(treeList.find(name)==std::string::npos) continue; } std::cout << "Copying input tree = " << key->GetName() << std::endl; TTree *T = (TTree*)input.Get(key->GetName()); oFile->cd(); TTree *newT = T->CloneTree(-1, "fast"); newT->Write(); std::cout << "Done" << std::endl; } } oFile->cd(); } } void fQROOTOut::InitTree(){ if (trout) delete trout; trout = new TTree("fiTQun",""); // spliTChan variables trout->Branch("cluster_ncand" ,&fitqunse_.cluster_ncand, "cluster_ncand/I"); trout->Branch("cluster_tstart" , fitqunse_.cluster_tstart, "cluster_tstart[cluster_ncand]/F"); trout->Branch("cluster_tend" , fitqunse_.cluster_tend, "cluster_tend[cluster_ncand]/F"); trout->Branch("cluster_nhits" , fitqunse_.cluster_nhits, "cluster_nhits[cluster_ncand]/I"); trout->Branch("cluster_totq" , fitqunse_.cluster_totq, "cluster_totq[cluster_ncand]/F"); trout->Branch("cluster_goodflag" , fitqunse_.cluster_goodflag, "cluster_goodflag[cluster_ncand]/I"); trout->Branch("cluster_npeaks" , fitqunse_.cluster_npeaks, Form("cluster_npeaks[cluster_ncand][%d]/I",NPEAKFINDS)); trout->Branch("cluster_ipeak" , fitqunse_.cluster_ipeak, Form("cluster_ipeak[cluster_ncand][%d][%d]/I",NPEAKFINDS,MAXSE)); trout->Branch("cluster_timeofpeak" , fitqunse_.cluster_timeofpeak, Form("cluster_timeofpeak[cluster_ncand][%d][%d]/F",NPEAKFINDS,MAXSE)); trout->Branch("muechk_ncand" ,fitqunse_.muechk_ncand, Form("muechk_ncand[%d]/I",NPEAKFINDS)); trout->Branch("muechk_toya" ,fitqunse_.muechk_toya, Form("muechk_toya[%d]/F",NPEAKFINDS)); trout->Branch("muechk_tpeak" , fitqunse_.muechk_tpeak, Form("muechk_tpeak[%d][%d]/F",NPEAKFINDS,MAXSE)); trout->Branch("muechk_bg" , fitqunse_.muechk_bg, Form("muechk_bg[%d][%d]/I",NPEAKFINDS,MAXSE)); trout->Branch("muechk_mean" ,fitqunse_. muechk_mean, Form("muechk_mean[%d][%d]/F",NPEAKFINDS,MAXSE)); trout->Branch("muechk_excess", fitqunse_.muechk_excess,Form("muechk_excess[%d][%d]/F",NPEAKFINDS,MAXSE)); trout->Branch("muechk_signif", fitqunse_.muechk_signif,Form("muechk_signif[%d][%d]/F",NPEAKFINDS,MAXSE)); trout->Branch("muechk_icluster", fitqunse_.muechk_icluster,Form("muechk_icluster[%d][%d]/I",NPEAKFINDS,MAXSE)); // fiTQun variables trout->Branch("trgoff" , &fitquntwnd_.trgoff, "trgoff/F"); trout->Branch("fqntwnd" , &fitquntwnd_.fqntwnd, "fqntwnd/I"); trout->Branch("fqtwnd_iclstr" , fitquntwnd_.fqtwnd_iclstr, "fqtwnd_iclstr[fqntwnd]/I"); trout->Branch("fqtwnd_npeak" , fitquntwnd_.fqtwnd_npeak, "fqtwnd_npeak[fqntwnd]/I"); trout->Branch("fqtwnd_prftt0" , fitquntwnd_.fqtwnd_prftt0, "fqtwnd_prftt0[fqntwnd]/F"); trout->Branch("fqtwnd_prftpos" , fitquntwnd_.fqtwnd_prftpos, "fqtwnd_prftpos[fqntwnd][3]/F"); trout->Branch("fqtwnd" , fitquntwnd_.fqtwnd, "fqtwnd[fqntwnd][2]/F"); trout->Branch("fqtwnd_peakt0" , fitquntwnd_.fqtwnd_peakt0, Form("fqtwnd_peakt0[fqntwnd][%d]/F",MAXNPEAK)); trout->Branch("fqtwnd_peakiness" , fitquntwnd_.fqtwnd_peakiness, Form("fqtwnd_peakiness[fqntwnd][%d]/F",MAXNPEAK)); trout->Branch("fqnse" , &fitqun1r_.fqnse, "fqnse/I"); trout->Branch("fqitwnd" , fitqun1r_.fqitwnd, "fqitwnd[fqnse]/I"); trout->Branch("fqipeak" , fitqun1r_.fqipeak, "fqipeak[fqnse]/I"); trout->Branch("fqnhitpmt" , fitqun1r_.fqnhitpmt, "fqnhitpmt[fqnse]/I"); trout->Branch("fqtotq" , fitqun1r_.fqtotq, "fqtotq[fqnse]/F"); trout->Branch("fq0rtotmu" , fitqun1r_.fq0rtotmu, "fq0rtotmu[fqnse]/F"); trout->Branch("fq0rnll" , fitqun1r_.fq0rnll, "fq0rnll[fqnse]/F"); trout->Branch("fqn50" , fitqun1r_.fqn50, "fqn50[fqnse]/I"); trout->Branch("fqq50" , fitqun1r_.fqq50, "fqq50[fqnse]/F"); trout->Branch("fq1rpcflg" , fitqun1r_.fq1rpcflg, Form("fq1rpcflg[fqnse][%d]/I",MAXPX)); trout->Branch("fq1rmom" , fitqun1r_.fq1rmom, Form("fq1rmom[fqnse][%d]/F",MAXPX)); trout->Branch("fq1rt0" , fitqun1r_.fq1rt0, Form("fq1t0[fqnse][%d]/F",MAXPX)); trout->Branch("fq1rtotmu" , fitqun1r_.fq1rtotmu, Form("fq1totmu[fqnse][%d]/F",MAXPX)); trout->Branch("fq1rnll" , fitqun1r_.fq1rnll, Form("fq1nll[fqnse][%d]/F",MAXPX)); trout->Branch("fq1rpos" , fitqun1r_.fq1rpos, Form("fq1rpos[fqnse][%d][3]/F",MAXPX)); trout->Branch("fq1rdir" , fitqun1r_.fq1rdir, Form("fq1rdir[fqnse][%d][3]/F",MAXPX)); trout->Branch("fq1rdconv" , fitqun1r_.fq1rdconv, Form("fq1rdconv[fqnse][%d]/F",MAXPX)); trout->Branch("fq1reloss" , fitqun1r_.fq1reloss, Form("fq1reloss[fqnse][%d]/F",MAXPX)); trout->Branch("fqpi0pcflg" , fitqunpi0_.fqpi0pcflg, "fqpi0pcflg[2]/I"); trout->Branch("fqpi0mom1" , fitqunpi0_.fqpi0mom1, "fqpi0mom1[2]/F"); trout->Branch("fqpi0mom2" , fitqunpi0_.fqpi0mom2, "fqpi0mom2[2]/F"); trout->Branch("fqpi0momtot" , fitqunpi0_.fqpi0momtot, "fqpi0momtot[2]/F"); trout->Branch("fqpi0dconv1" , fitqunpi0_.fqpi0dconv1, "fqpi0dconv1[2]/F"); trout->Branch("fqpi0dconv2" , fitqunpi0_.fqpi0dconv2, "fqpi0dconv2[2]/F"); trout->Branch("fqpi0t0" , fitqunpi0_.fqpi0t0, "fqpi0t0[2]/F"); trout->Branch("fqpi0totmu" , fitqunpi0_.fqpi0totmu, "fqpi0totmu[2]/F"); trout->Branch("fqpi0nll" , fitqunpi0_.fqpi0nll, "fqpi0nll[2]/F"); trout->Branch("fqpi0mass" , fitqunpi0_.fqpi0mass, "fqpi0mass[2]/F"); trout->Branch("fqpi0photangle" , fitqunpi0_.fqpi0photangle, "fqpi0photangle[2]/F"); trout->Branch("fqpi0pos" , fitqunpi0_.fqpi0pos, "fqpi0pos[2][3]/F"); trout->Branch("fqpi0dir1" , fitqunpi0_.fqpi0dir1, "fqpi0dir1[2][3]/F"); trout->Branch("fqpi0dir2" , fitqunpi0_.fqpi0dir2, "fqpi0dir2[2][3]/F"); trout->Branch("fqpi0dirtot" , fitqunpi0_.fqpi0dirtot, "fqpi0dirtot[2][3]/F"); trout->Branch("fqnmrfit" , &fitqunmr_.fqnmrfit, "fqnmrfit/I"); trout->Branch("fqmrifit" , fitqunmr_.fqmrifit, "fqmrifit[fqnmrfit]/I"); trout->Branch("fqmrnring" , fitqunmr_.fqmrnring, "fqmrnring[fqnmrfit]/I"); trout->Branch("fqmrpcflg" , fitqunmr_.fqmrpcflg, "fqmrpcflg[fqnmrfit]/I"); trout->Branch("fqmrnll" , fitqunmr_.fqmrnll, "fqmrnll[fqnmrfit]/F"); trout->Branch("fqmrtotmu" , fitqunmr_.fqmrtotmu, "fqmrtotmu[fqnmrfit]/F"); trout->Branch("fqmrpid" , fitqunmr_.fqmrpid, Form("fqmrpid[fqnmrfit][%d]/I",FQMAXNRING)); trout->Branch("fqmrmom" , fitqunmr_.fqmrmom, Form("fqmrmom[fqnmrfit][%d]/F",FQMAXNRING)); trout->Branch("fqmrdconv" , fitqunmr_.fqmrdconv, Form("fqmrdconv[fqnmrfit][%d]/F",FQMAXNRING)); trout->Branch("fqmreloss" , fitqunmr_.fqmreloss, Form("fqmreloss[fqnmrfit][%d]/F",FQMAXNRING)); trout->Branch("fqmrt0" , fitqunmr_.fqmrt0, Form("fqmrt0[fqnmrfit][%d]/F",FQMAXNRING)); trout->Branch("fqmrpos" , fitqunmr_.fqmrpos, Form("fqmrpos[fqnmrfit][%d][3]/F",FQMAXNRING)); trout->Branch("fqmrdir" , fitqunmr_.fqmrdir, Form("fqmrdir[fqnmrfit][%d][3]/F",FQMAXNRING)); trout->Branch("fqmsnfit" , &fitqunms_.fqmsnfit, "fqmsnfit/I"); trout->Branch("fqmspcflg" , fitqunms_.fqmspcflg, "fqmspcflg[fqmsnfit]/I"); trout->Branch("fqmsnseg" , fitqunms_.fqmsnseg, "fqmsnseg[fqmsnfit]/I"); trout->Branch("fqmspid" , fitqunms_.fqmspid, "fqmspid[fqmsnfit]/I"); trout->Branch("fqmsifit" , fitqunms_.fqmsifit, "fqmsifit[fqmsnfit]/I"); trout->Branch("fqmsimer" , fitqunms_.fqmsimer, "fqmsimer[fqmsnfit]/I"); trout->Branch("fqmstotmu" , fitqunms_.fqmstotmu, "fqmstotmu[fqmsnfit]/F"); trout->Branch("fqmsnll" , fitqunms_.fqmsnll, "fqmsnll[fqmsnfit]/F"); trout->Branch("fqmsmom" , fitqunms_.fqmsmom, Form("fqmsmom[fqmsnfit][%d]/F",FQMSMAXRING)); trout->Branch("fqmseloss" , fitqunms_.fqmseloss, Form("fqmseloss[fqmsnfit][%d]/F",FQMSMAXRING)); trout->Branch("fqmst0" , fitqunms_.fqmst0, Form("fqmst0[fqmsnfit][%d]/F",FQMSMAXRING)); trout->Branch("fqmspos" , fitqunms_.fqmspos, Form("fqmspos[fqmsnfit][%d][3]/F",FQMSMAXRING)); trout->Branch("fqmsdir" , fitqunms_.fqmsdir, Form("fqmsdir[fqmsnfit][%d][3]/F",FQMSMAXRING)); trout->Branch("fqtestn1r" , &fitqun1rtest_.fqtestn1r, "fqtestn1r/I"); trout->Branch("fqtest1rstage" , fitqun1rtest_.fqtest1rstage, "fqtest1rstage[fqtestn1r]/I"); trout->Branch("fqtest1rse" , fitqun1rtest_.fqtest1rse, "fqtest1rse[fqtestn1r]/I"); trout->Branch("fqtest1rpid" , fitqun1rtest_.fqtest1rpid, "fqtest1rpid[fqtestn1r]/I"); trout->Branch("fqtest1rpcflg" , fitqun1rtest_.fqtest1rpcflg, "fqtest1rpcflg[fqtestn1r]/I"); trout->Branch("fqtest1rmom" , fitqun1rtest_.fqtest1rmom, "fqtest1rmom[fqtestn1r]/F"); trout->Branch("fqtest1rt0" , fitqun1rtest_.fqtest1rt0, "fqtest1rt0[fqtestn1r]/F"); trout->Branch("fqtest1rtotmu" , fitqun1rtest_.fqtest1rtotmu, "fqtest1rtotmu[fqtestn1r]/F"); trout->Branch("fqtest1rnll" , fitqun1rtest_.fqtest1rnll, "fqtest1rnll[fqtestn1r]/F"); trout->Branch("fqtest1rpos" , fitqun1rtest_.fqtest1rpos, "fqtest1rpos[fqtestn1r][3]/F"); trout->Branch("fqtest1rdir" , fitqun1rtest_.fqtest1rdir, "fqtest1rdir[fqtestn1r][3]/F"); trout->Branch("fqtest1rdconv" , fitqun1rtest_.fqtest1rdconv, "fqtest1rdconv[fqtestn1r]/F"); trout->Branch("fqtest1reloss" , fitqun1rtest_.fqtest1reloss, "fqtest1reloss[fqtestn1r]/F"); trout->Branch("fqtestnpi0" , &fitqunpi0test_.fqtestnpi0, "fqtestnpi0/I"); trout->Branch("fqtestpi0stage" , fitqunpi0test_.fqtestpi0stage, "fqtestpi0stage[fqtestnpi0]/I"); trout->Branch("fqtestpi0pcflg" , fitqunpi0test_.fqtestpi0pcflg, "fqtestpi0pcflg[fqtestnpi0]/I"); trout->Branch("fqtestpi0mom1" , fitqunpi0test_.fqtestpi0mom1, "fqtestpi0mom1[fqtestnpi0]/F"); trout->Branch("fqtestpi0mom2" , fitqunpi0test_.fqtestpi0mom2, "fqtestpi0mom2[fqtestnpi0]/F"); trout->Branch("fqtestpi0momtot" , fitqunpi0test_.fqtestpi0momtot, "fqtestpi0momtot[fqtestnpi0]/F"); trout->Branch("fqtestpi0dconv1" , fitqunpi0test_.fqtestpi0dconv1, "fqtestpi0dconv1[fqtestnpi0]/F"); trout->Branch("fqtestpi0dconv2" , fitqunpi0test_.fqtestpi0dconv2, "fqtestpi0dconv2[fqtestnpi0]/F"); trout->Branch("fqtestpi0t0" , fitqunpi0test_.fqtestpi0t0, "fqtestpi0t0[fqtestnpi0]/F"); trout->Branch("fqtestpi0totmu" , fitqunpi0test_.fqtestpi0totmu, "fqtestpi0totmu[fqtestnpi0]/F"); trout->Branch("fqtestpi0nll" , fitqunpi0test_.fqtestpi0nll, "fqtestpi0nll[fqtestnpi0]/F"); trout->Branch("fqtestpi0mass" , fitqunpi0test_.fqtestpi0mass, "fqtestpi0mass[fqtestnpi0]/F"); trout->Branch("fqtestpi0photangle" , fitqunpi0test_.fqtestpi0photangle, "fqtestpi0photangle[fqtestnpi0]/F"); trout->Branch("fqtestpi0pos" , fitqunpi0test_.fqtestpi0pos, "fqtestpi0pos[fqtestnpi0][3]/F"); trout->Branch("fqtestpi0dir1" , fitqunpi0test_.fqtestpi0dir1, "fqtestpi0dir1[fqtestnpi0][3]/F"); trout->Branch("fqtestpi0dir2" , fitqunpi0test_.fqtestpi0dir2, "fqtestpi0dir2[fqtestnpi0][3]/F"); trout->Branch("fqtestpi0dirtot" , fitqunpi0test_.fqtestpi0dirtot, "fqtestpi0dirtot[fqtestnpi0][3]/F"); trout->Branch("fqpmgpcflg" , fitqunpmg_.fqpmgpcflg, "fqpmgpcflg[2]/I"); trout->Branch("fqpmgmom1" , fitqunpmg_.fqpmgmom1, "fqpmgmom1[2]/F"); trout->Branch("fqpmgmom2" , fitqunpmg_.fqpmgmom2, "fqpmgmom2[2]/F"); trout->Branch("fqpmgt01" , fitqunpmg_.fqpmgt01, "fqpmgt01[2]/F"); trout->Branch("fqpmgt02" , fitqunpmg_.fqpmgt02, "fqpmgt02[2]/F"); trout->Branch("fqpmgtotmu" , fitqunpmg_.fqpmgtotmu, "fqpmgtotmu[2]/F"); trout->Branch("fqpmgnll" , fitqunpmg_.fqpmgnll, "fqpmgnll[2]/F"); trout->Branch("fqpmgpos1" , fitqunpmg_.fqpmgpos1, "fqpmgpos1[2][3]/F"); trout->Branch("fqpmgpos2" , fitqunpmg_.fqpmgpos2, "fqpmgpos2[2][3]/F"); trout->Branch("fqpmgdir1" , fitqunpmg_.fqpmgdir1, "fqpmgdir1[2][3]/F"); trout->Branch("fqpmgdir2" , fitqunpmg_.fqpmgdir2, "fqpmgdir2[2][3]/F"); trout->Branch("ifqver" , &fitquninfo_.ifqver, "ifqver/I"); trout->Branch("fqproctime" , fitquninfo_.fqproctime, "fqproctime[20]/F"); }