9 #include "StSpinTreeReader.h"
11 #include "TDirectory.h"
13 #include "TStopwatch.h"
19 StSpinTreeReader::StSpinTreeReader(
const char *treeName) : connectJets(true),
20 connectNeutralJets(true), connectChargedPions(true), connectBemcPions(true),
21 connectEemcPions(true), connectBemcElectrons(true), requireDidFire(false), requireShouldFire(false),
22 mEemcPions(NULL), mEventList(NULL), mIsConnected(false)
24 mChain =
new TChain(treeName);
25 mChainConeJets =
new TChain(
"ConeJets");
26 mChainConeJetsEMC =
new TChain(
"ConeJetsEMC");
27 mChainChargedPions =
new TChain(
"chargedPions");
28 mChainBemcPions =
new TChain(
"bemcPions");
29 mChainBemcElectrons =
new TChain(
"bemcElectrons");
32 mConeJets =
new TClonesArray(
"StJet",100);
33 mConeJetsEMC =
new TClonesArray(
"StJet",100);
34 mChargedPions =
new TClonesArray(
"StChargedPionTrack",100);
35 mBemcPions =
new TClonesArray(
"TPi0Candidate",100);
36 mBemcElectrons =
new TClonesArray(
"StPrimaryElectron",100);
37 mBemcGlobalElectrons =
new TClonesArray(
"StGlobalElectron",500);
40 StSpinTreeReader::~StSpinTreeReader() {
41 std::cout <<
"StSpinTreeReader::~StSpinTreeReader()" << std::endl;
42 delete mChainConeJets;
43 delete mChainConeJetsEMC;
44 delete mChainChargedPions;
45 delete mChainBemcPions;
46 delete mChainBemcElectrons;
53 delete mBemcElectrons;
54 delete mBemcGlobalElectrons;
70 void StSpinTreeReader::selectDataset(
const char *path) {
71 TString fullPath = path;
72 fullPath.ReplaceAll(
"$STAR",getenv(
"STAR"));
73 std::ifstream filelist(fullPath.Data());
74 std::string currentFile;
75 while(filelist.good()) {
76 getline(filelist,currentFile);
77 if(currentFile.size() == 0)
continue;
79 selectFile(currentFile);
83 void StSpinTreeReader::selectFile(
const char *path) {
84 std::string theFile(path);
88 void StSpinTreeReader::selectFile(std::string & path) {
89 int run = atoi(path.substr(path.length()-17,7).c_str());
90 mFileList[run] = path;
93 long StSpinTreeReader::GetEntries() {
95 if(mEventList)
return mEventList->GetN();
96 return mChain->GetEntries();
99 void StSpinTreeReader::GetEntry(
long i) {
102 long n = mEventList->GetEntry(i);
105 else mChain->GetEntry(i);
107 if(mCurrentFileName != mChain->GetFile()->GetName()) {
108 mCurrentFileName = mChain->GetFile()->GetName();
109 std::cout <<
"now analyzing " << mCurrentFileName << std::endl;
113 void StSpinTreeReader::connect() {
116 if(mFileList.empty()) std::cout <<
"no files to analyze! check your macro" << std::endl;
117 for(map<int,std::string>::iterator it=mFileList.begin(); it!=mFileList.end(); it++) {
118 if(mRunList.empty() || mRunList.count(it->first)) {
119 std::cout <<
"adding " << it->second << std::endl;
120 mChain->AddFile(it->second.c_str());
121 if(connectJets) mChainConeJets->AddFile(it->second.c_str());
122 if(connectNeutralJets) mChainConeJetsEMC->AddFile(it->second.c_str());
123 if(connectChargedPions) mChainChargedPions->AddFile(it->second.c_str());
124 if(connectBemcPions) mChainBemcPions->AddFile(it->second.c_str());
125 if(connectBemcElectrons)mChainBemcElectrons->AddFile(it->second.c_str());
129 mChain->SetBranchAddress(
"skimEventBranch",&mEvent);
132 mChain->AddFriend(
"ConeJets");
133 mChain->SetBranchAddress(
"ConeJets", &mConeJets);
136 if(connectNeutralJets) {
137 mChain->AddFriend(
"ConeJetsEMC");
138 mChain->SetBranchAddress(
"ConeJetsEMC",&mConeJetsEMC);
141 if(connectChargedPions) {
142 mChain->AddFriend(
"chargedPions");
143 mChain->SetBranchAddress(
"chargedPions",&mChargedPions);
146 if(connectBemcPions) {
147 mChain->AddFriend(
"bemcPions");
148 mChain->SetBranchAddress(
"bemcPions",&mBemcPions);
150 if(connectBemcElectrons) {
151 mChain->AddFriend(
"bemcElectrons");
152 mChain->SetBranchAddress(
"PrimaryElectrons",&mBemcElectrons);
153 mChain->SetBranchAddress(
"GlobalElectrons",&mBemcGlobalElectrons);
155 if(connectEemcPions) {
161 if(mEventList == NULL) {
164 for(std::set<int>::const_iterator it = mTriggerList.begin(); it != mTriggerList.end(); it++) {
166 s +=
"( mTriggers.mTrigId==";
169 else { s +=
" || mTriggers.mTrigId=="; }
172 if(mTriggerList.size()) s +=
" )";
173 if(requireDidFire || requireShouldFire) {
175 if(requireDidFire && requireShouldFire) s +=
"mTriggers.mDidFire==1 && mTriggers.mShouldFire==1 )";
176 else if(requireDidFire) s +=
"mTriggers.mDidFire==1 )";
177 else s+=
"mTriggers.mShouldFire==1 )";
180 std::cout <<
"begin generation of TEventList with contents \n" << s << std::endl;
182 mChain->Draw(
">>elist_spinTreeReader",s.Data(),
"entrylist");
183 mEventList = (TEventList*)gDirectory->Get(
"elist_spinTreeReader");
184 mChain->SetEventList(mEventList);
185 std::cout <<
"TEventList generated and stored in " << timer.CpuTime()
186 <<
" CPU / " << timer.RealTime() <<
" real seconds" << std::endl;
194 void StSpinTreeReader::selectRunlist(
const char *path) {
195 TString fullPath = path;
196 fullPath.ReplaceAll(
"$STAR",getenv(
"STAR"));
197 std::ifstream list(fullPath.Data());
201 if(currentRun == 0)
continue;
203 mRunList.insert(currentRun);
207 void StSpinTreeReader::selectRun(
int runnumber) {
208 mRunList.insert(runnumber);
211 void StSpinTreeReader::removeRun(
int runnumber) {
212 mRunList.erase(runnumber);
215 void StSpinTreeReader::selectTrigger(
int trigger) {
216 mTriggerList.insert(trigger);