14 #include "TFriendElement.h"
18 #include "StMessMgr.h"
21 #include "StSpinPool/StMCAsymMaker/StMCAsymMaker.h"
22 #include "StSpinPool/StMCAsymMaker/StPythiaEvent.h"
25 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
28 #include "StJetMaker/StJetSimuUtil/StJetSimuReader.h"
31 #include "StSpinPool/StJets/StJet.h"
32 #include "StSpinPool/StJets/StJets.h"
33 #include "StSpinPool/StJetSkimEvent/StJetSkimEvent.h"
38 bool verifyJet(
StJets* stjets,
int ijet);
40 void dumpProtojetToStream(
int event, ostream& os,
StJets* stjets);
46 :
StMaker(name), mFile(0), mTree(0), mSkimFile(0), mSkimTree(0),
47 mDstMaker(uDstMaker), mCounter(0), mValid(false), mSkimEvent(0), mOfstream(0)
49 LOG_DEBUG <<
"StJetSimuReader::StJetSimuReader()"<<endm;
53 StJetSimuReader::~StJetSimuReader()
55 LOG_DEBUG <<
"StJetSimuReader::~StJetSimuReader()"<<endm;
59 Int_t StJetSimuReader::Init()
61 LOG_DEBUG <<
"StJetSimuReader::Init()"<<endm;
67 LOG_DEBUG <<
"StJetSimuReader::InitFile()"<<endm;
69 LOG_DEBUG <<
"open file:\t"<<file<<
"\tfor reading"<<endm;
70 mFile =
new TFile(file,
"READ");
73 LOG_DEBUG <<
"recover jet tree"<<endm;
74 TObject*
tree = mFile->Get(
"jet");
75 TTree* t =
dynamic_cast<TTree*
>(
tree);
79 LOG_DEBUG <<
"\tset tree pointer"<<endm;
80 LOG_DEBUG <<
"Number of entries in jet tree:\t"<<t->GetEntries();
82 LOG_DEBUG <<
"\tGet Jet Branches"<<endm;
83 TObjArray* branches = t->GetListOfBranches();
84 if (!branches) {LOG_DEBUG <<
"StJetSimuReader::InitFile(). Null branches"<<endm; abort();}
86 LOG_DEBUG <<
"\tLoop on branches"<<endm;
88 for (
int i=0; i<branches->GetLast()+1; ++i) {
89 TBranch* branch =
dynamic_cast<TBranch*
>((*branches)[i]);
90 if (!branch) {LOG_DEBUG <<
"StJetSimuReader::InitFile(). Null branch"<<endm; abort();}
91 string bname( branch->GetName() );
92 LOG_DEBUG <<
"\t--- Found branch:\t"<<bname<<endm;
94 if ( (bname.find(
"Cone")!=bname.npos) || (bname.find(
"cone")!=bname.npos) ) {
95 LOG_DEBUG <<
"\t\tcreate StJets object for branch:\t"<<bname<<endm;
100 mStJetsMap[bname] = jets;
101 LOG_DEBUG <<
"\t\tset branch address for branch:\t"<<bname.c_str()<<endm;
102 t->SetBranchStatus(bname.c_str(), 1);
103 t->SetBranchAddress(bname.c_str(), &jets);
104 branch->SetAutoDelete(
true);
109 string jetCheck(file);
110 jetCheck +=
".read.txt";
111 mOfstream =
new ofstream(jetCheck.c_str());
114 LOG_DEBUG <<
"\tfinished!"<<endm;
121 LOG_DEBUG <<
" StJetSimuReader::InitJetSkimFile(const char* file)"<<endm;
122 LOG_DEBUG <<
"open file:\t"<<file<<
"\tfor reading"<<endm;
124 mSkimFile =
new TFile(file,
"READ");
127 TObject* t = mSkimFile->Get(
"jetSkimTree");
130 mSkimTree =
dynamic_cast<TTree*
>(t);
136 mSkimTree->SetBranchStatus(
"skimEventBranch", 1);
137 mSkimTree->SetBranchAddress(
"skimEventBranch", &mSkimEvent);
139 LOG_DEBUG <<
"successfully recovered tree from file."<<endm;
145 LOG_DEBUG <<
"StJetSimuReader::InitTree()"<<endm;
146 LOG_DEBUG <<
"\tset tree pointer"<<endm;
147 LOG_DEBUG <<
"Number of entries in tree:\t"<<tree->GetEntries();
149 TList* friendmist = tree->GetListOfFriends();
151 for (
int j=0; j<friendmist->GetSize()+1; ++j) {
152 TFriendElement* fr =
static_cast<TFriendElement*
>( friendmist->At(j) );
153 string tree_name( fr->GetTreeName() );
154 if (tree_name ==
"jet") {
161 LOG_DEBUG <<
"\tGet Branches"<<endm;
162 TObjArray* branches = t->GetListOfBranches();
163 if (!branches) {LOG_DEBUG <<
"StJetSimuReader::InitFile(). Null branches"<<endm; abort();}
165 LOG_DEBUG <<
"\tLoop on branches"<<endm;
167 for (
int i=0; i<branches->GetLast()+1; ++i) {
168 TBranch* branch =
dynamic_cast<TBranch*
>((*branches)[i]);
169 if (!branch) {LOG_DEBUG <<
"StJetSimuReader::InitFile(). Null branch"<<endm; abort();}
170 string bname( branch->GetName() );
171 LOG_DEBUG <<
"\t--- Found branch:\t"<<bname<<endm;
173 if ( (bname.find(
"jet")!=bname.npos) || (bname.find(
"Jet")!=bname.npos) ) {
174 LOG_DEBUG <<
"\t\tcreate StJets object for branch:\t"<<bname<<endm;
179 mStJetsMap[bname] = jets;
180 LOG_DEBUG <<
"\t\tset branch address for branch:\t"<<bname.c_str()<<endm;
181 t->SetBranchStatus(bname.c_str(), 1);
182 t->SetBranchAddress(bname.c_str(), &jets);
186 LOG_DEBUG <<
"\tfinished!"<<endm;
194 LOG_DEBUG <<
"StJetSimuReader::preparedForDualRead()"<<endm;
195 int jetStatus = (mTree) ? 1 : 0;
196 int skimStatus = (mSkimTree) ? 1 : 0;
197 LOG_DEBUG <<
"jet tree status:\t"<<jetStatus<<endm;
198 LOG_DEBUG <<
"skim tree status:\t"<<skimStatus<<endm;
202 int nJetEvents = mTree->GetEntries();
203 int nSkimEvents = mSkimTree->GetEntries();
204 LOG_DEBUG <<
"nJetEvents:\t"<<nJetEvents<<endm;
205 LOG_DEBUG <<
"nSkimEvents:\t"<<nSkimEvents<<endm;
206 assert(nJetEvents==nSkimEvents);
209 LOG_DEBUG <<
"Congratulations, you are ready to process events!"<<endm;
217 int status = mTree->GetEntry(mCounter);
219 LOG_DEBUG <<
"StJetSimuReader::getEvent(). ERROR:\tstatus<0. return null"<<endm;
223 status = mSkimTree->GetEntry(mCounter);
243 LOG_DEBUG <<
"StJetSimuReader::exampleSimuAna()"<<endm;
248 LOG_DEBUG <<
"fill/run/event:\t"<<skEv->fill()<<
"\t"<<skEv->runId()<<
"\t"<<skEv->eventId()<<endm;
249 LOG_DEBUG <<
"fileName:\t"<<skEv->mudstFileName().GetString()<<endm;
252 LOG_DEBUG <<
"Ebbc:\t"<<skEv->eBbc()<<
"\tWbbc:\t"<<skEv->wBbc()<<
"\tbbcTimeBin:\t"<<skEv->bbcTimeBin()<<endm;
255 const float* bestPos = skEv->bestVert()->position();
256 LOG_DEBUG <<
"best Vertex (x,y,z):\t"<<bestPos[0]<<
"\t"<<bestPos[1]<<
"\t"<<bestPos[2]<<endm;
260 LOG_DEBUG <<
" subprocess Id="<<pyEv->processId()<<endm;
261 LOG_DEBUG <<
" s =" <<pyEv->s()<<endm;
262 LOG_DEBUG <<
" t =" <<pyEv->t()<<endm;
263 LOG_DEBUG <<
" u =" <<pyEv->u()<<endm;
264 LOG_DEBUG <<
" x1 =" <<pyEv->x1()<<endm;
265 LOG_DEBUG <<
" x2 =" <<pyEv->x2()<<endm;
266 LOG_DEBUG <<
" Q2 =" <<pyEv->Q2()<<endm;
267 LOG_DEBUG <<
" Partonic pT="<<pyEv->pt()<<endm;
268 LOG_DEBUG <<
" Partonic cos(th)="<<pyEv->cosTheta()<<endm;
269 LOG_DEBUG <<
" Partonic Asym="<<pyEv->partonALL()<<endm;
270 LOG_DEBUG <<
" Polarzied PDF for x1="<<pyEv->dF1(StPythiaEvent::STD)<<endm;
271 LOG_DEBUG <<
" Polarzied PDF for x2="<<pyEv->dF2(StPythiaEvent::STD)<<endm;
272 LOG_DEBUG <<
" UnPolarzied PDF for x1="<<pyEv->f1(StPythiaEvent::STD)<<endm;
273 LOG_DEBUG <<
" UnPolarzied PDF for x2="<<pyEv->f1(StPythiaEvent::STD)<<endm;
274 LOG_DEBUG <<
" Weighting =(dF1*dF2*partonALL)/(f1*f2)="<<pyEv->ALL(StPythiaEvent::STD)<<endm;
277 const TClonesArray* trigs = skEv->triggers();
279 int nTrigs = trigs->GetLast()+1;
280 for (
int i=0; i<nTrigs; ++i) {
283 if (trig->shouldFire() != 0) {
284 LOG_DEBUG <<
"\tTriggerd:\t"<<trig->trigId()<<endm;
289 for (JetBranchesMap::iterator it=mStJetsMap.begin(); it!=mStJetsMap.end(); ++it) {
291 LOG_DEBUG <<
"Found\t"<<(*it).first<<endm;
292 if ((*it).first!=
"PythiaConeR04")
continue;
294 StJets* stjets = (*it).second;
295 int nJets = stjets->
nJets();
298 assert(stjets->runId()==skEv->runId());
299 assert(stjets->
eventId()==skEv->eventId());
301 TClonesArray* jets = stjets->
jets();
303 for (
int ijet=0;ijet<nJets;ijet++){
304 StJet* j =
static_cast<StJet*
>( (*jets)[ijet] );
306 assert(verifyJet(stjets, ijet));
307 LOG_DEBUG<<
"%PYpT="<<j->Pt()<<
" PYeta="<<j->Eta()<<
" PYphi="<<j->Phi()<<endm;
313 for (JetBranchesMap::iterator it=mStJetsMap.begin(); it!=mStJetsMap.end(); ++it) {
315 LOG_DEBUG <<
"Found\t"<<(*it).first<<endm;
316 if ((*it).first!=
"MkConeR04")
continue;
319 StJets* stjets = (*it).second;
320 int nJets = stjets->
nJets();
321 LOG_DEBUG <<
"Found\t"<<nJets<<
"\tjets from:\t"<<(*it).first<<endm;
324 assert(stjets->runId()==skEv->runId());
325 assert(stjets->
eventId()==skEv->eventId());
326 TClonesArray* jets = stjets->
jets();
328 for(
int ijet=0; ijet<nJets; ++ijet){
329 StJet* j =
static_cast<StJet*
>( (*jets)[ijet] );
331 assert(verifyJet(stjets, ijet));
332 LOG_DEBUG <<
"jet:\t"<<ijet<<
"\tEjet:\t"<<j->E()<<
"\tEta:\t"<<j->Eta()<<
"\tPhi:\t"<<j->Phi()<<endm;
335 typedef vector<TLorentzVector*> TrackToJetVec;
336 TrackToJetVec particles = stjets->particles(ijet);
337 for (TrackToJetVec::iterator it=particles.begin(); it!=particles.end(); ++it) {
338 TLorentzVector* t2j = (*it);
340 if (dynamic_cast<TrackToJetIndex*>(t2j)) {LOG_DEBUG<<
"TPC track pT="<<t2j->Pt()<<endm;}
341 if (dynamic_cast<TowerToJetIndex*>(t2j)) {LOG_DEBUG<<
"TOWER track eT="<<t2j->Et()<<endm;}
TClonesArray * jets()
Access to the jets in this event.
int nJets() const
The number of jets found in this event.
int eventId() const
access to event numbers, used to synchronize with StMuDstMaker for simultaneous reading ...
void exampleSimuAna()
An example analysis method, look here for a demonstration of jet + event info.
StJetSkimEvent * skimEvent()
Acces to the StJetSkimEvent.
virtual void InitTree(TTree *tree)
virtual void InitJetSkimFile(const char *file)
Recover the "fast" tree of StJetSkimEvent.
TTree * tree()
Access to the StJets tree.
virtual void InitFile(const char *file)
Recover the TTree from file and prepare for reading.
int preparedForDualRead()
Check if we are all ready to read the Skim and Jet trees together.