13 #include "StEmcClusterCollection.h"
14 #include "StEmcPoint.h"
15 #include "StEmcUtil/geometry/StEmcGeom.h"
16 #include "StEmcUtil/others/emcDetectorName.h"
17 #include "StEmcADCtoEMaker/StBemcData.h"
18 #include "StEmcADCtoEMaker/StEmcADCtoEMaker.h"
22 #include "TFriendElement.h"
26 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
27 #include "StMuDSTMaker/COMMON/StMuDst.h"
28 #include "StMuDSTMaker/COMMON/StMuEvent.h"
31 #include "StSpinPool/StJets/StJet.h"
32 #include "StSpinPool/StJets/StJets.h"
33 #include "StJetMaker/StJetReader.h"
34 #include "StSpinPool/StJetSkimEvent/StJetSkimEvent.h"
48 LOG_INFO <<
"StJetReader::StJetReader()" << endm;
51 StJetReader::~StJetReader()
53 LOG_INFO <<
"StJetReader::~StJetReader()" << endm;
56 Int_t StJetReader::Init()
63 LOG_INFO <<
"StJetReader::InitFile()" << endm;
65 LOG_INFO <<
"open file:\t" << file <<
"\tfor reading" << endm;
66 mFile = TFile::Open(file);
69 LOG_INFO <<
"recover tree" << endm;
70 mTree =
dynamic_cast<TTree*
>(mFile->Get(
"jet"));
74 int nentries = mTree->BuildIndex(
"mRunNumber",
"mEventNumber");
76 LOG_WARN <<
"Could not build jet tree index: nentries=" << nentries << endm;
79 LOG_INFO <<
"Built jet tree index: nentries=" << nentries << endm;
82 LOG_INFO <<
"\tset tree pointer" << endm;
83 LOG_INFO <<
"Number of entries in tree:\t" << mTree->GetEntriesFast() << endm;
85 LOG_INFO <<
"\tGet Branches" << endm;
86 TObjArray* branches = mTree->GetListOfBranches();
88 LOG_ERROR <<
"StJetReader::InitFile(). Null branches" << endm;
92 LOG_INFO <<
"\tLoop on branches" << endm;
94 for (
int i=0; i<branches->GetEntriesFast(); ++i) {
95 TBranch* branch =
dynamic_cast<TBranch*
>(branches->At(i));
97 LOG_ERROR <<
"StJetReader::InitFile(). Null branch" << endm;
101 LOG_INFO <<
"\t--- Found branch:\t" << branch->GetName() << endm;
105 string jetCheck(file);
106 jetCheck +=
".read.txt";
107 mOfstream =
new ofstream(jetCheck.c_str());
110 LOG_INFO <<
"\tfinished!" <<endm;
117 LOG_INFO <<
"StJetReader::InitJetSkimFile(const char* file)" << endm;
118 LOG_INFO <<
"open file:\t" << file <<
"\tfor reading" << endm;
120 mSkimFile = TFile::Open(file);
123 mSkimTree =
dynamic_cast<TTree*
>(mSkimFile->Get(
"jetSkimTree"));
127 int nentries = mSkimTree->BuildIndex(
"mRunId",
"mEventId");
129 LOG_WARN <<
"Could not build skim tree index: nentries=" << nentries << endm;
132 LOG_INFO <<
"Built skim tree index: nentries=" << nentries << endm;
138 mSkimTree->SetBranchStatus(
"skimEventBranch", 1);
139 mSkimTree->SetBranchAddress(
"skimEventBranch", &mSkimEvent);
141 LOG_INFO <<
"successfully recovered tree from file." << endm;
146 LOG_INFO <<
"StJetReader::InitTree()" << endm;
148 LOG_INFO <<
"\tset tree pointer" << endm;
149 LOG_INFO <<
"Number of entries in tree:\t" << tree->GetEntriesFast() << endm;
151 TList* friendList = tree->GetListOfFriends();
153 for (
int j=0; j<friendList->GetSize(); ++j) {
154 TFriendElement* fr =
static_cast<TFriendElement*
>( friendList->At(j) );
155 string tree_name( fr->GetTreeName() );
156 if (tree_name ==
"jet") {
163 LOG_INFO <<
"\tGet Branches" << endm;
164 TObjArray* branches = t->GetListOfBranches();
166 LOG_ERROR <<
"StJetReader::InitFile(). Null branches" << endm;
170 LOG_INFO <<
"\tLoop on branches" << endm;
172 for (
int i=0; i<branches->GetEntriesFast(); ++i) {
173 TBranch* branch =
dynamic_cast<TBranch*
>(branches->At(i));
175 LOG_INFO <<
"StJetReader::InitFile(). Null branch" << endm;
179 LOG_INFO <<
"\t--- Found branch:\t" << branch->GetName() << endm;
182 LOG_INFO <<
"\tfinished!" << endm;
189 LOG_INFO <<
"StJetReader::preparedForDualRead()" << endm;
190 int jetStatus = mTree != 0;
191 int skimStatus = mSkimTree != 0;
192 LOG_INFO <<
"jet tree status:\t" << jetStatus << endm;
193 LOG_INFO <<
"skim tree status:\t" << skimStatus << endm;
197 int nJetEvents = mTree->GetEntriesFast();
198 int nSkimEvents = mSkimTree->GetEntriesFast();
199 LOG_INFO <<
"nJetEvents:\t" << nJetEvents << endm;
200 LOG_INFO <<
"nSkimEvents:\t" << nSkimEvents << endm;
201 assert(nJetEvents == nSkimEvents);
204 LOG_INFO <<
"Congratulations, you are ready to process events!" << endm;
211 if (mTree && mTree->GetEntryWithIndex(
GetRunNumber(),GetEventNumber()) < 0) {
212 LOG_WARN << Form(
"Could not find jet tree entry for run=%d event=%d",
GetRunNumber(),GetEventNumber()) << endm;
216 if (mSkimTree && mSkimTree->GetEntryWithIndex(
GetRunNumber(),GetEventNumber()) < 0) {
217 LOG_WARN << Form(
"Could not find skim tree entry for run=%d event=%d",
GetRunNumber(),GetEventNumber()) << endm;
234 void dumpProtojetToStream(
int event, ostream& os,
StJets* stjets);
239 StDetectorId mDetId = t->detectorId();
240 if (mDetId==kTpcId) {
243 else if (mDetId==kBarrelEmcTowerId) {
244 idstring =
"kBarrelEmcTowerId";
246 else if (mDetId==kEndcapEmcTowerId) {
247 idstring =
"kEndcapEmcTowerId";
250 idstring =
"kUnknown";
256 bool verifyJet(
StJets* stjets,
int ijet)
258 TClonesArray& jets = *(stjets->
jets());
269 typedef vector<TLorentzVector*> FourpList;
270 FourpList particles = stjets->particles(ijet);
272 for (FourpList::iterator it=particles.begin(); it!=particles.end(); ++it) {
273 TLorentzVector* v = *it;
281 if (abs(diff)>1.e-6) {
282 LOG_INFO <<
"verifyJet. assert will fail for jet:\t" << ijet <<
"\t4p:\t" << j4 <<
"\tcompared to sum_particles:\t" << jetMom << endm;
293 LOG_INFO <<
"StJetReader::exampleEventAna()" << endm;
298 LOG_INFO <<
"fill/run/event:\t" << skEv->fill() <<
"\t" << skEv->runId() <<
"\t" << skEv->eventId() << endm;
299 LOG_INFO <<
"fileName:\t" << skEv->mudstFileName().GetString() << endm;
302 LOG_INFO <<
"bx48:\t" << skEv->bx48() <<
"\tspinBits:\t" << skEv->spinBits() << endm;
305 LOG_INFO <<
"Ebbc:\t" << skEv->eBbc() <<
"\tWbbc:\t" << skEv->wBbc() <<
"\tbbcTimeBin:\t" << skEv->bbcTimeBin() << endm;
308 const float* bestPos = skEv->bestVert()->position();
309 LOG_INFO <<
"best Vertex (x,y,z):\t" << bestPos[0] <<
"\t" << bestPos[1] <<
"\t" << bestPos[2] << endm;
312 const TClonesArray* trigs = skEv->triggers();
314 int nTrigs = trigs->GetEntriesFast();
315 for (
int i=0; i<nTrigs; ++i) {
318 if (trig->didFire() != 0) {
321 if (trig->shouldFireL2() == 1) {
322 LOG_INFO <<
"\tshTrigger L2: " << trig->trigId() << endm;
323 const int* l2temp = trig->L2ResultEmulated();
324 for (
int ii = 0; ii < 9; ++ii) {
325 LOG_INFO <<
"SimL2--- " << ii <<
"\t" << l2temp[ii] << endm;
331 LOG_INFO <<
"\n--- Non-zero L2 Results:" << endm;
332 const int* l2temp = skEv->L2Result();
333 for (
int ii=0; ii<9; ii++) {
334 if (l2temp[ii]!=0) LOG_INFO <<
"DatL2--- " << ii <<
"\t" << l2temp[ii] << endm;
338 const TClonesArray* verts = skEv->vertices();
340 int nVerts = verts->GetEntriesFast();
341 for (
int i=0; i<nVerts; ++i) {
344 const float* vertPos = vert->position();
345 LOG_INFO <<
"vert:\t" << i <<
"\t at z:\t" << vertPos[2] <<
"\tranking:\t"
346 << vert->ranking() <<
"\tnTracks:\t" << vert->nTracksUsed() << endm;
350 LOG_INFO <<
"\nLoop on jet branches" << endm;
352 StJets* stjets = getStJets(i);
353 int nJets = stjets->
nJets();
354 LOG_INFO <<
"Found\t" << nJets <<
"\tjets from:\t" << branchName(i) << endm;
357 assert(stjets->runId()==skEv->runId());
358 assert(stjets->
eventId()==skEv->eventId());
360 TClonesArray* jets = stjets->
jets();
362 for(
int ijet=0; ijet<nJets; ++ijet){
365 StJet* j =
dynamic_cast<StJet*
>( jets->At(ijet) );
369 LOG_INFO <<
"jet:\t"<<ijet<<
"\tEjet:\t"<<j->E()<<
"\tEta:\t"<<j->Eta()<<
"\tPhi:\t"<<j->Phi()<<
"\tdetEta:\t"<<j->detEta()<<endm;
372 typedef vector<TLorentzVector*> TrackToJetVec;
373 TrackToJetVec particles = stjets->particles(ijet);
375 for (TrackToJetVec::iterator partIt=particles.begin(); partIt!=particles.end(); ++partIt) {
376 const TLorentzVector* theParticle = *partIt;
377 LOG_INFO <<
"\tparticle \t pt:\t"<<theParticle->Pt()<<
"\teta:\t"<<theParticle->Eta()<<
"\tphi:\t"<<theParticle->Phi()<<endm;
385 LOG_INFO <<
"StJetReader::exampleEventAna()"<<endm;
387 LOG_INFO <<
"nPrimary:\t"<<StMuDst::numberOfPrimaryTracks() << endm;
390 StJets* stjets = getStJets(i);
391 int nJets = stjets->
nJets();
392 LOG_INFO <<
"Found\t"<<nJets<<
"\tjets from:\t"<<branchName(i)<<endm;
394 TClonesArray* jets = stjets->
jets();
398 if (stjets->
nJets()>0) {
399 dumpProtojetToStream(
StMuDst::event()->eventId(), *mOfstream, stjets);
403 for(
int ijet=0; ijet<nJets; ++ijet){
406 StJet* j =
dynamic_cast<StJet*
>( jets->At(ijet) );
408 assert(verifyJet(stjets, ijet));
410 LOG_INFO <<
"jet:\t"<<ijet<<
"\tEjet:\t"<<j->E()<<
"\tEta:\t"<<j->Eta()<<
"\tPhi:\t"<<j->Phi()<<endm;
413 typedef vector<TLorentzVector*> TrackToJetVec;
414 TrackToJetVec particles = stjets->particles(ijet);
421 return mTree->GetNbranches();
424 const char* StJetReader::branchName(
int i)
const
426 TBranch* branch = (TBranch*)mTree->GetListOfBranches()->At(i);
427 return branch ? branch->GetName() : 0;
430 StJets* StJetReader::getStJets(
int i)
const
432 TBranch* branch = (TBranch*)mTree->GetListOfBranches()->At(i);
433 return branch ? *(
StJets**)branch->GetAddress() : 0;
436 StJets* StJetReader::getStJets(
const char* bname)
const
438 TBranch* branch = mTree->GetBranch(bname);
439 return branch ? *(
StJets**)branch->GetAddress() : 0;
virtual void InitJetSkimFile(const char *file)
Recover the "fast" tree of StJetSkimEvent.
int preparedForDualRead()
Check if we are all ready to read the Skim and StjJet trees together.
void exampleFastAna()
An example analysis method to read StJetSkimEvent and StJets trees together.
virtual void InitFile(const char *file)
Recover the TTree from file and prepare for reading.
StJetReader(const char *name="JetReader")
The constructor requires a valid instance of StMuDstMaker.
void exampleEventAna()
An example analysis method, look here for a demonstration of jet/track histogramming.
TClonesArray * jets()
Access to the jets in this event.
StJetSkimEvent * skimEvent() const
Acces to the StJetSkimEvent.
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 ...
virtual void InitTree(TTree *tree)
int numberOfBranches() const
Access to jet branches.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
virtual Int_t GetRunNumber() const
Returns the current RunNumber.