1 |
anderson |
1.1 |
/*************************************************
|
2 |
|
|
This provides an example of how to add a branch
|
3 |
|
|
to the specified TTree the specified files.
|
4 |
|
|
|
5 |
|
|
The value placed in the new branch is a function
|
6 |
|
|
of values currently in the TTree.
|
7 |
|
|
|
8 |
|
|
Michael B. Anderson
|
9 |
|
|
Oct 8, 2009
|
10 |
|
|
*************************************************/
|
11 |
|
|
|
12 |
|
|
#include <vector>
|
13 |
|
|
#include <cmath>
|
14 |
|
|
|
15 |
|
|
void addFisherValue() {
|
16 |
|
|
//************************************************************
|
17 |
|
|
// Variables //
|
18 |
|
|
TString fileName[] = {"QCD_Pt15_Summer09.root",
|
19 |
|
|
"QCD_Pt30_Summer09.root",
|
20 |
|
|
"QCD_Pt80_Summer09.root" };
|
21 |
|
|
int numberOfFiles = 3;
|
22 |
|
|
|
23 |
|
|
TString treeName = "TreePhotonJet";
|
24 |
|
|
|
25 |
|
|
// Variables in the TTree used to determine new value
|
26 |
|
|
TString variableNames[] = {"photon_ecalRecHitSumEtConeDR03",
|
27 |
|
|
"photon_hcalTowerSumEtConeDR03",
|
28 |
|
|
"photon_trkSumPtHollowConeDR03",
|
29 |
|
|
"photon_hadronicOverEm",
|
30 |
|
|
"photon_r2x5"};
|
31 |
|
|
Float_t variableValues[] = {0.0, 0.0, 0.0, 0.0, 0.0}; // Dummy values, just initializing array
|
32 |
|
|
Int_t numberOfVariables = 5;
|
33 |
|
|
|
34 |
|
|
Float_t coeff[] = {-1.0799E0, -1.1344E-1, -5.0319E-2, -1.0400E-1, -2.6775E0, 1.5899E0};
|
35 |
|
|
// END of Variables //
|
36 |
|
|
//************************************************************
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
// Loop over all the Files
|
40 |
|
|
for (int i=0; i < numberOfFiles; i++) {
|
41 |
|
|
TFile* currentFile = new TFile(fileName[i],"update");
|
42 |
|
|
|
43 |
|
|
cout << "Opened " << fileName[i] << ", adding new branch" << endl;
|
44 |
|
|
|
45 |
|
|
TTree *tree = (TTree*)currentFile->Get(treeName);
|
46 |
|
|
|
47 |
|
|
// Loop over all the entries, and add the new branch
|
48 |
|
|
for (int j=0;j<numberOfVariables;j++) {
|
49 |
|
|
tree->SetBranchAddress(variableNames[j], &variableValues[j]);
|
50 |
|
|
}
|
51 |
|
|
float fisherValue;
|
52 |
|
|
TBranch *newBranch = tree->Branch("fisherValue", &fisherValue,"fisherValue/F");
|
53 |
|
|
|
54 |
|
|
Int_t numEntries = (Int_t)tree->GetEntries();
|
55 |
|
|
for (Int_t j=0; j<numEntries; j++) {
|
56 |
|
|
// Push values from TTree into "var" vector
|
57 |
|
|
tree->GetEntry(j);
|
58 |
|
|
// Calculate fisher value
|
59 |
|
|
fisherValue=coeff[0]+coeff[1]*variableValues[0]+coeff[2]*variableValues[1]+coeff[3]*variableValues[2]+coeff[4]*variableValues[3]+coeff[5]*variableValues[4];
|
60 |
|
|
newBranch->Fill();
|
61 |
|
|
}
|
62 |
|
|
tree->Write("",TObject::kOverwrite); // save new version only
|
63 |
|
|
currentFile->Close();
|
64 |
|
|
cout << " ...closed file." << endl;
|
65 |
|
|
}
|
66 |
|
|
}
|