#define calAnalyzerTree_cxx #include "calAnalyzerTree.h" #include #include #include calAnalyzerTree* calAnalyzerTree::m_instance; calAnalyzerTree::calAnalyzerTree(TTree *tree) : fChain(0) { // if parameter tree is not specified (or zero), connect the file // used to generate this class and read the Tree. if (tree == 0) { TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("ftest.root"); if (!f || !f->IsOpen()) { f = new TFile("ftest.root"); } f->GetObject("calAnalyzerTree",tree); } Init(tree); } calAnalyzerTree* calAnalyzerTree::giveThis() { if(DEBUG_sim) std::cout << "debug::m_instance calAnalyzerTree " << m_instance << std::endl; if (0 == m_instance){ std::cout << "calAnalyzerTree::giveThis error not constructed properly " << std::endl; } return m_instance; } // Open a TTree for reading calAnalyzerTree* calAnalyzerTree::giveThis(TTree* aTree, const std::string& option) { if(DEBUG_sim) std::cout << "debug::m_instance calAnalyzerTree " << m_instance << std::endl; if (0 == m_instance){ m_instance = new calAnalyzerTree(aTree/*, option*/); } else{ std::cout << "calAnalyzerTree::giveThis Warning " << aTree->GetTitle() << std::endl; } return m_instance; } // Delete unique instance void calAnalyzerTree::releaseThis() { if ( m_instance != 0 ) { delete m_instance; m_instance = 0; } } calAnalyzerTree::~calAnalyzerTree() { if (!fChain) return; delete fChain->GetCurrentFile(); } Int_t calAnalyzerTree::GetEntry(Long64_t entry) { // Read contents of entry. if (!fChain) return 0; return fChain->GetEntry(entry); } Long64_t calAnalyzerTree::LoadTree(Long64_t entry) { // Set the environment to read one entry if (!fChain) return -5; Long64_t centry = fChain->LoadTree(entry); if (centry < 0) return centry; if (fChain->GetTreeNumber() != fCurrent) { fCurrent = fChain->GetTreeNumber(); Notify(); } return centry; } void calAnalyzerTree::Init(TTree *tree) { // The Init() function is called when the selector needs to initialize // a new tree or chain. Typically here the branch addresses and branch // pointers of the tree will be set. // It is normally not necessary to make changes to the generated // code, but the routine can be extended by the user if needed. // Init() will be called many times when running on PROOF // (once per file to be processed). // Set branch addresses and branch pointers if (!tree) return; fChain = tree; fCurrent = -1; fChain->SetMakeClass(1); fChain->SetBranchAddress("mac5", &mac5, &b_mac5); fChain->SetBranchAddress("active", active, &b_active); fChain->SetBranchAddress("gain", gain, &b_gain); fChain->SetBranchAddress("gainErr", gainErr, &b_gainErr); fChain->SetBranchAddress("gainXsqr", gainXsqr, &b_gainXsqr); fChain->SetBranchAddress("gainNdf", gainNdf, &b_gainNdf); fChain->SetBranchAddress("gainPed", gainPed, &b_gainPed); fChain->SetBranchAddress("gainPedErr", gainPedErr, &b_gainPedErr); fChain->SetBranchAddress("nPeak", nPeak, &b_nPeak); fChain->SetBranchAddress("peakXsqr", peakXsqr, &b_peakXsqr); fChain->SetBranchAddress("peakNdf", peakNdf, &b_peakNdf); fChain->SetBranchAddress("peakMean", peakMean, &b_peakMean); fChain->SetBranchAddress("peakMeanErr", peakMeanErr, &b_peakMeanErr); fChain->SetBranchAddress("peakNorm", peakNorm, &b_peakNorm); fChain->SetBranchAddress("peakNormErr", peakNormErr, &b_peakNormErr); fChain->SetBranchAddress("peakSigma", peakSigma, &b_peakSigma); fChain->SetBranchAddress("peakSigmaErr", peakSigmaErr, &b_peakSigmaErr); fChain->SetBranchAddress("ped", ped, &b_ped); fChain->SetBranchAddress("pedErr", pedErr, &b_pedErr); fChain->SetBranchAddress("pedXsqr", pedXsqr, &b_pedXsqr); fChain->SetBranchAddress("pedNdf", pedNdf, &b_pedNdf); fChain->SetBranchAddress("pedSigma", pedSigma, &b_pedSigma); fChain->SetBranchAddress("pedSigmaErr", pedSigmaErr, &b_pedSigmaErr); fChain->SetBranchAddress("pedNorm", pedNorm, &b_pedNorm); fChain->SetBranchAddress("pedNormErr", pedNormErr, &b_pedNormErr); fChain->SetBranchAddress("threshAdc", threshAdc, &b_threshAdc); fChain->SetBranchAddress("threshPe", threshPe, &b_threshPe); fChain->SetBranchAddress("nAbove", nAbove, &b_nAbove); Notify(); } Bool_t calAnalyzerTree::Notify() { // The Notify() function is called when a new file is opened. This // can be either for a new TTree in a TChain or when when a new TTree // is started when using PROOF. It is normally not necessary to make changes // to the generated code, but the routine can be extended by the // user if needed. The return value is currently not used. return kTRUE; } void calAnalyzerTree::Show(Long64_t entry) { // Print contents of entry. // If entry is not specified, print current entry if (!fChain) return; fChain->Show(entry); } Int_t calAnalyzerTree::Cut(Long64_t entry) { // This function may be called from Loop. // returns 1 if entry is accepted. // returns -1 otherwise. return 1; } TTree* calAnalyzerTree::GetInputTree() {return m_treeIn;}; void calAnalyzerTree::GetcalAnalyzerTree(Long64_t entry) { if (!m_treeIn) { std::cout << "calAnalyzerTree::getEntry error" << std::endl; exit(1); } m_treeIn->GetEntry(entry); if(DEBUG_sim) m_treeIn->Show(entry); m_mac5 = mac5; for(int k=0; k<32; k++) { m_active[k]=active[k]; m_gain[k]=gain[k]; m_gainerr[k]=gainErr[k]; m_gainxsqr[k]=gainXsqr[k]; m_gainndf[k]=gainNdf[k]; m_gainped[k]=gainPed[k]; m_gainpederr[k]=gainPedErr[k]; m_npeak[k]=nPeak[k]; for(int l=0; l<5; l++) { m_peakxsqr[k][l]=peakXsqr[k][l]; m_peakndf[k][l]=peakNdf[k][l]; m_peakmean[k][l]=peakMean[k][l]; m_peakmeanerr[k][l]=peakMeanErr[k][l]; m_peaknorm[k][l]=peakNorm[k][l]; m_peaknormerr[k][l]=peakNormErr[k][l]; m_peaksigma[k][l]=peakSigma[k][l]; m_peaksigmaerr[k][l]=peakSigmaErr[k][l]; }//end loop for 5-element data m_ped[k]=ped[k]; m_pederr[k]=pedErr[k]; m_pedxsqr[k]=pedXsqr[k]; m_pedndf[k]=pedNdf[k]; m_pedsigma[k]=pedSigma[k]; m_pedsigmaerr[k]=pedSigmaErr[k]; m_pednorm[k]=pedNorm[k]; m_pednormerr[k]=pedNormErr[k]; m_threshadc[k]=threshAdc[k]; m_threshpe[k]=threshPe[k]; m_nabove[k]=nAbove[k]; }//end loop over chans } void calAnalyzerTree::Loop() { // In a ROOT session, you can do: // root> .L calAnalyzerTree.C // root> calAnalyzerTree t // root> t.GetEntry(12); // Fill t data members with entry number 12 // root> t.Show(); // Show values of entry 12 // root> t.Show(16); // Read and show values of entry 16 // root> t.Loop(); // Loop on all entries // // This is the loop skeleton where: // jentry is the global entry number in the chain // ientry is the entry number in the current Tree // Note that the argument to GetEntry must be: // jentry for TChain::GetEntry // ientry for TTree::GetEntry and TBranch::GetEntry // // To read only selected branches, Insert statements like: // METHOD1: // fChain->SetBranchStatus("*",0); // disable all branches // fChain->SetBranchStatus("branchname",1); // activate branchname // METHOD2: replace line // fChain->GetEntry(jentry); //read all branches //by b_branchname->GetEntry(ientry); //read only this branch if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; for (Long64_t jentry=0; jentryGetEntry(jentry); nbytes += nb; // if (Cut(ientry) < 0) continue; } }