// Idea behind this macro is to implement cuts which are functions of // several ntuple variables. // // Tracy Usher (July 18, 2001) #ifndef nTupleVars_c #define nTupleVars_c #include "iostream.h" #include "string.h" #include "math.h" #endif class nTupleVars { private: //The input file information TFile* inputFile; TDirectory* pTkrDir; TTree* pTree; Int_t numValues; //Define pointers to the branch variables TBranch* pNumTrks; TBranch* pFitType; TBranch* pGamErr; TBranch* pGamEne; TBranch* pCorEne; TBranch* pCalEne; TBranch* pzDir; TBranch* pFitKink; TBranch* pTAngle; TBranch* pConv; TBranch* pShwr1; TBranch* pShwr2; TBranch* pFitGaps; TBranch* pFitHits; //Variables for the above Float_t numTrks; Float_t fitType; Float_t mcGamErr; Float_t mcGamEne; Float_t corEne; Float_t calEne; Float_t zDir; Float_t fitKink; Float_t tAngle; Float_t Rec_Conv_Twr_Dist; Float_t Rec_showerHits1; Float_t Rec_showerHits2; Float_t Tkr_Fit_Gaps; Float_t Tkr_No_Hits; Float_t CalEneSclFctr; //Private function for setting branch variables TBranch* setBranchVar(TTree* pTree, char* pVarName, Float_t* pVar); public: nTupleVars(); nTupleVars(char* pHistName); ~nTupleVars(); bool getVars(int tupleIdx); Float_t getNumTrks() {return numTrks;} Float_t getFitType() {return fitType;} Float_t getMcGamErr() {return mcGamErr;} Float_t getMcGamEne() {return mcGamEne;} Float_t getCorEne() {return corEne;} Float_t getCalEne() {return calEne;} Float_t getZDir() {return zDir;} Float_t getFitKink() {return fitKink;} Float_t getTAngle() {return tAngle;} Float_t getTwrDist() {return Rec_Conv_Twr_Dist;} Float_t getShwr1() {return Rec_showerHits1;} Float_t getShwr2() {return Rec_showerHits2;} Float_t getFitGaps() {return Tkr_Fit_Gaps;} Float_t getNoHits() {return Tkr_No_Hits;} }; nTupleVars::nTupleVars() { return; } nTupleVars::nTupleVars(char* pHistName) { //******************************************************************** //Gyrations to find the input ntuple root file inputFile = 0; printf("--In nTupleVars constructor\n"); printf(" Attempting to open file:%s\n",pHistName); if (!pHistName) { char histFileName[120]; printf("Please enter an input file name:"); int nScan = scanf("%s",histFileName); if (nScan) {inputFile = new TFile(histFileName);} else { printf("Failed to read file name\n"); return; } } else {inputFile = new TFile(pHistName);} pTkrDir = (TDirectory *)inputFile->Get("PDR"); pTree = (TTree *)pTkrDir->Get("t1"); char* pStart = strstr(pHistName,"ao"); if (strstr(pHistName, "ao")) { //AO Recon ntuple variable names printf(" ***Setting up for AO Recon ntuple***\n"); pNumTrks = setBranchVar(pTree, "No_Tracks", &numTrks); pFitType = setBranchVar(pTree, "Fit_Type", &fitType); pGamErr = setBranchVar(pTree, "Gamma_Err", &mcGamErr); pGamEne = setBranchVar(pTree, "MC_Energy", &mcGamEne); pCorEne = setBranchVar(pTree, "CsI_Corr_Energy", &corEne); pCalEne = setBranchVar(pTree, "CsI_Energy_Sum", &calEne); pzDir = setBranchVar(pTree, "Gamma_z_dir", &zDir); pFitKink = setBranchVar(pTree, "Fit_Kink", &fitKink); pTAngle = setBranchVar(pTree, "t_Angle", &tAngle); pConv = setBranchVar(pTree, "Conv_Twr_Dist", &Rec_Conv_Twr_Dist); pShwr1 = setBranchVar(pTree, "showerHits1", &Rec_showerHits1); pShwr2 = setBranchVar(pTree, "showerHits2", &Rec_showerHits2); pFitGaps = setBranchVar(pTree, "Fit_Gaps", &Tkr_Fit_Gaps); pFitHits = setBranchVar(pTree, "No_Trk_Hits", &Tkr_No_Hits); CalEneSclFctr = 1000.; } else { //Standard recon variable names printf(" ***Setting up for Standard Recon ntuple***\n"); pNumTrks = setBranchVar(pTree, "TKR_No_Tracks", &numTrks); pFitType = setBranchVar(pTree, "TKR_Fit_Type", &fitType); pGamErr = setBranchVar(pTree, "MC_Gamma_Err", &mcGamErr); pGamEne = setBranchVar(pTree, "MC_Energy", &mcGamEne); pCorEne = setBranchVar(pTree, "REC_CsI_Corr_Energy", &corEne); pCalEne = setBranchVar(pTree, "Cal_Energy_Deposit", &calEne); pzDir = setBranchVar(pTree, "TKR_Gamma_zdir", &zDir); pFitKink = setBranchVar(pTree, "TKR_Fit_Kink", &fitKink); pTAngle = setBranchVar(pTree, "TKR_t_angle", &tAngle); pConv = setBranchVar(pTree, "REC_Conv_Twr_Dist", &Rec_Conv_Twr_Dist); pShwr1 = setBranchVar(pTree, "REC_showerHits1", &Rec_showerHits1); pShwr2 = setBranchVar(pTree, "REC_showerHits2", &Rec_showerHits2); pFitGaps = setBranchVar(pTree, "TKR_Fit_Gaps", &Tkr_Fit_Gaps); pFitHits = setBranchVar(pTree, "TKR_No_Hits", &Tkr_No_Hits); CalEneSclFctr = 1.; } numValues = pTree->GetEntries(); printf("--Done with nTupleVars constructor, nVals=%i\n",numValues); return; } bool nTupleVars::getVars(int tupleIdx) { bool newValue = 0; if (tupleIdx < numValues) { pNumTrks->GetEntry(tupleIdx); pFitType->GetEntry(tupleIdx); pGamErr->GetEntry(tupleIdx); pGamEne->GetEntry(tupleIdx); pCorEne->GetEntry(tupleIdx); pCalEne->GetEntry(tupleIdx); pzDir->GetEntry(tupleIdx); pFitKink->GetEntry(tupleIdx); pTAngle->GetEntry(tupleIdx); pConv->GetEntry(tupleIdx); pShwr1->GetEntry(tupleIdx); pShwr2->GetEntry(tupleIdx); pFitGaps->GetEntry(tupleIdx); pFitHits->GetEntry(tupleIdx); calEne = CalEneSclFctr * calEne; newValue = 1; } return newValue; } TBranch* nTupleVars::setBranchVar(TTree* pTree, char* pVarName, Float_t* pVar) { //Look for the branch corresponding to the desired ntuple variable TBranch* pBranch = pTree->GetBranch(pVarName); if (pBranch) { int nLeaves = pBranch->GetNleaves(); //cout << " ** find branch for %s" << pVarName << endl; printf(" ** find branch for %s\n", pVarName); printf(" This branch has %i leaf(ves)\n",nLeaves); //Find the leaf on this branch for this variable TLeaf* pLeaf = pBranch->GetLeaf(pVarName); if (pLeaf) { //Set the variable pVar to receive the value of the ntuple variable pLeaf->SetAddress(pVar); } } else { printf(" ** No branch found for variable %s\n", pVarName); } return pBranch; }