StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StJetSimuReader.cxx
1 //M.L. Miller
2 //MIT Software
3 //6/04
4 
5 //std
6 #include <map>
7 #include <string>
8 #include <algorithm>
9 #include <iostream>
10 #include <math.h>
11 
12 //root
13 #include "TTree.h"
14 #include "TFriendElement.h"
15 #include "TFile.h"
16 
17 //STAR
18 #include "StMessMgr.h"
19 
20 //StMCAsymMaker
21 #include "StSpinPool/StMCAsymMaker/StMCAsymMaker.h"
22 #include "StSpinPool/StMCAsymMaker/StPythiaEvent.h"
23 
24 //StMuDstMaker
25 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
26 
27 //StJetMaker
28 #include "StJetMaker/StJetSimuUtil/StJetSimuReader.h"
29 
30 // StSpinPool
31 #include "StSpinPool/StJets/StJet.h"
32 #include "StSpinPool/StJets/StJets.h"
33 #include "StSpinPool/StJetSkimEvent/StJetSkimEvent.h"
34 
35 ClassImp(StJetSimuReader)
36 
37 
38 bool verifyJet(StJets* stjets, int ijet);
39 
40 void dumpProtojetToStream(int event, ostream& os, StJets* stjets);
41 
42 string idString(TrackToJetIndex* t);
43 
44 
45 StJetSimuReader::StJetSimuReader(const char* name, StMuDstMaker* uDstMaker)
46  : StMaker(name), mFile(0), mTree(0), mSkimFile(0), mSkimTree(0),
47  mDstMaker(uDstMaker), mCounter(0), mValid(false), mSkimEvent(0), mOfstream(0)
48 {
49  LOG_DEBUG <<"StJetSimuReader::StJetSimuReader()"<<endm;
50 
51 }
52 
53 StJetSimuReader::~StJetSimuReader()
54 {
55  LOG_DEBUG <<"StJetSimuReader::~StJetSimuReader()"<<endm;
56 }
57 
58 
59 Int_t StJetSimuReader::Init()
60 {
61  LOG_DEBUG <<"StJetSimuReader::Init()"<<endm;
62  return kStOk;
63 }
64 
65 void StJetSimuReader::InitFile(const char* file)
66 {
67  LOG_DEBUG <<"StJetSimuReader::InitFile()"<<endm;
68 
69  LOG_DEBUG <<"open file:\t"<<file<<"\tfor reading"<<endm;
70  mFile = new TFile(file,"READ");
71  assert(mFile);
72 
73  LOG_DEBUG <<"recover jet tree"<<endm;
74  TObject* tree = mFile->Get("jet");
75  TTree* t = dynamic_cast<TTree*>(tree);
76  assert(t);
77  mTree = t;
78 
79  LOG_DEBUG <<"\tset tree pointer"<<endm;
80  LOG_DEBUG <<"Number of entries in jet tree:\t"<<t->GetEntries();
81 
82  LOG_DEBUG <<"\tGet Jet Branches"<<endm;
83  TObjArray* branches = t->GetListOfBranches();
84  if (!branches) {LOG_DEBUG <<"StJetSimuReader::InitFile(). Null branches"<<endm; abort();}
85 
86  LOG_DEBUG <<"\tLoop on branches"<<endm;
87 
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;
93 
94  if ( (bname.find("Cone")!=bname.npos) || (bname.find("cone")!=bname.npos) ) {
95  LOG_DEBUG <<"\t\tcreate StJets object for branch:\t"<<bname<<endm;
96 
97  //create StJets object here, put in map:
98  StJets* jets = new StJets();
99  jets->Clear();
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);
105  }
106  }
107 
108  if (0) {
109  string jetCheck(file);
110  jetCheck += ".read.txt";
111  mOfstream = new ofstream(jetCheck.c_str());
112  }
113 
114  LOG_DEBUG <<"\tfinished!"<<endm;
115 
116  return ;
117 }
118 
119 void StJetSimuReader::InitJetSkimFile(const char* file)
120 {
121  LOG_DEBUG <<" StJetSimuReader::InitJetSkimFile(const char* file)"<<endm;
122  LOG_DEBUG <<"open file:\t"<<file<<"\tfor reading"<<endm;
123 
124  mSkimFile = new TFile(file,"READ");
125  assert(mSkimFile);
126 
127  TObject* t = mSkimFile->Get("jetSkimTree");
128  assert(t);
129 
130  mSkimTree = dynamic_cast<TTree*>(t);
131  assert(mSkimTree);
132 
133  mSkimEvent = new StJetSkimEvent();
134 
135  //set branch status
136  mSkimTree->SetBranchStatus("skimEventBranch", 1);
137  mSkimTree->SetBranchAddress("skimEventBranch", &mSkimEvent);
138 
139  LOG_DEBUG <<"successfully recovered tree from file."<<endm;
140 }
141 
142 
143 void StJetSimuReader::InitTree(TTree* tree)
144 {
145  LOG_DEBUG <<"StJetSimuReader::InitTree()"<<endm;
146  LOG_DEBUG <<"\tset tree pointer"<<endm;
147  LOG_DEBUG <<"Number of entries in tree:\t"<<tree->GetEntries();
148 
149  TList* friendmist = tree->GetListOfFriends();
150  TTree* t=0;
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") {
155  t = fr->GetTree();
156  break;
157  }
158  }
159  assert(t);
160 
161  LOG_DEBUG <<"\tGet Branches"<<endm;
162  TObjArray* branches = t->GetListOfBranches();
163  if (!branches) {LOG_DEBUG <<"StJetSimuReader::InitFile(). Null branches"<<endm; abort();}
164 
165  LOG_DEBUG <<"\tLoop on branches"<<endm;
166 
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;
172 
173  if ( (bname.find("jet")!=bname.npos) || (bname.find("Jet")!=bname.npos) ) {
174  LOG_DEBUG <<"\t\tcreate StJets object for branch:\t"<<bname<<endm;
175 
176  //create StJets object here, put in map:
177  StJets* jets = new StJets();
178  jets->Clear();
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);
183  }
184  }
185 
186  LOG_DEBUG <<"\tfinished!"<<endm;
187 
188  return ;
189 }
190 
191 
193 {
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;
199  assert(mTree);
200  assert(mSkimTree);
201 
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);
207  assert(mSkimEvent);
208 
209  LOG_DEBUG <<"Congratulations, you are ready to process events!"<<endm;
210  mValid = true;
211  return 1;
212 }
213 
214 
216 {
217  int status = mTree->GetEntry(mCounter);
218  if (status<0) {
219  LOG_DEBUG <<"StJetSimuReader::getEvent(). ERROR:\tstatus<0. return null"<<endm;
220  }
221 
222  if (mSkimTree) {
223  status = mSkimTree->GetEntry(mCounter);
224  }
225 
226  mCounter++;
227 
228  return kStOk;
229 }
230 
232 {
233  if (mOfstream) {
234  delete mOfstream;
235  mOfstream=0;
236  }
237 
238  return kStOk;
239 }
240 
242 {
243  LOG_DEBUG <<"StJetSimuReader::exampleSimuAna()"<<endm;
244 
245  StJetSkimEvent* skEv = skimEvent();
246 
247  //basic information:
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;
250 
251  //some event info:
252  LOG_DEBUG <<"Ebbc:\t"<<skEv->eBbc()<<"\tWbbc:\t"<<skEv->wBbc()<<"\tbbcTimeBin:\t"<<skEv->bbcTimeBin()<<endm;
253 
254  //best vertex info:
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;
257 
258  //pythia event inf
259  const StPythiaEvent *pyEv=skEv->mcEvent();
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;
275 
276  //trigger info:
277  const TClonesArray* trigs = skEv->triggers();
278  assert(trigs);
279  int nTrigs = trigs->GetLast()+1;
280  for (int i=0; i<nTrigs; ++i) {
281  StJetSkimTrig* trig = static_cast<StJetSkimTrig*>( (*trigs)[i] );
282  assert(trig);
283  if (trig->shouldFire() != 0) {
284  LOG_DEBUG <<"\tTriggerd:\t"<<trig->trigId()<<endm;
285  }
286  }
287 
288  //GET PARTICLE JETS
289  for (JetBranchesMap::iterator it=mStJetsMap.begin(); it!=mStJetsMap.end(); ++it) {
290 
291  LOG_DEBUG <<"Found\t"<<(*it).first<<endm;
292  if ((*it).first!="PythiaConeR04") continue;
293 
294  StJets* stjets = (*it).second;
295  int nJets = stjets->nJets();
296 
297  //first make sure that we have the same run/event:
298  assert(stjets->runId()==skEv->runId());
299  assert(stjets->eventId()==skEv->eventId());
300 
301  TClonesArray* jets = stjets->jets();
302 
303  for (int ijet=0;ijet<nJets;ijet++){
304  StJet* j = static_cast<StJet*>( (*jets)[ijet] );
305  assert(j);
306  assert(verifyJet(stjets, ijet));
307  LOG_DEBUG<<"%PYpT="<<j->Pt()<<" PYeta="<<j->Eta()<<" PYphi="<<j->Phi()<<endm;
308  }
309 
310  }
311 
312  //GET DETECTOR JETS
313  for (JetBranchesMap::iterator it=mStJetsMap.begin(); it!=mStJetsMap.end(); ++it) {
314 
315  LOG_DEBUG <<"Found\t"<<(*it).first<<endm;
316  if ((*it).first!="MkConeR04") continue;
317 
318 
319  StJets* stjets = (*it).second;
320  int nJets = stjets->nJets();
321  LOG_DEBUG <<"Found\t"<<nJets<<"\tjets from:\t"<<(*it).first<<endm;
322 
323  //first make sure that we have the same run/event:
324  assert(stjets->runId()==skEv->runId());
325  assert(stjets->eventId()==skEv->eventId());
326  TClonesArray* jets = stjets->jets();
327 
328  for(int ijet=0; ijet<nJets; ++ijet){
329  StJet* j = static_cast<StJet*>( (*jets)[ijet] );
330  assert(j);
331  assert(verifyJet(stjets, ijet));
332  LOG_DEBUG <<"jet:\t"<<ijet<<"\tEjet:\t"<<j->E()<<"\tEta:\t"<<j->Eta()<<"\tPhi:\t"<<j->Phi()<<endm;
333 
334  //look at 4-momenta in the jet:
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);
339  assert(t2j);
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;}
342  }
343  }
344  }
345 }
346 
347 
348 
349 
350 
351 
TClonesArray * jets()
Access to the jets in this event.
Definition: StJets.h:42
Definition: StJets.h:24
int nJets() const
The number of jets found in this event.
Definition: StJets.h:39
int eventId() const
access to event numbers, used to synchronize with StMuDstMaker for simultaneous reading ...
Definition: StJets.h:59
void exampleSimuAna()
An example analysis method, look here for a demonstration of jet + event info.
StJetSkimEvent * skimEvent()
Acces to the StJetSkimEvent.
virtual Int_t Make()
virtual void InitTree(TTree *tree)
virtual void InitJetSkimFile(const char *file)
Recover the &quot;fast&quot; 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.
virtual Int_t Finish()
int preparedForDualRead()
Check if we are all ready to read the Skim and Jet trees together.
Definition: StJet.h:91
Definition: Stypes.h:41