StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcTreeMaker.cxx
1 /*
2  * Created by S. Gliske, May 2012
3  *
4  * Description: see header
5  *
6  */
7 
8 #include <Rtypes.h>
9 #include <TChain.h>
10 #include <TTree.h>
11 #include <TFile.h>
12 
13 #include "StEEmcTreeMaker.h"
14 #include "StEEmcEnergyMaker.h"
15 
16 #include "StMuDSTMaker/COMMON/StMuDst.h"
17 #include "StMuDSTMaker/COMMON/StMuEvent.h"
18 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
19 #include "StarClassLibrary/StThreeVectorF.hh"
20 
21 #include "StRoot/StEEmcPool/EEmcTreeContainers/EEmcEnergy.h"
22 #include "StRoot/StEEmcPool/EEmcTreeContainers/EEmcSmdCluster.h"
23 #include "StRoot/StEEmcPool/EEmcTreeContainers/EEmcHit.h"
24 #include "StRoot/StEEmcPool/EEmcTreeContainers/EEmcParticleCandidate.h"
25 #include "StRoot/StEEmcPool/EEmcTreeContainers/EEmc2ParticleCandidate.h"
26 #include "StRoot/StEEmcPool/EEmcTreeContainers/TrigSet.h"
27 
28 #include "StRoot/StEEmcPool/StEEmcTreeMaker/StSpinInfoMaker.h"
29 #include "StRoot/StEEmcPool/StEEmcTreeMaker/StTrigCounter.h"
30 #include "StRoot/StEEmcPool/EEmcTreeContainers/StSpinInfo.h"
31 #include "StRoot/StEEmcPool/StEEmcHitMaker/StEEmcHitMaker.h"
32 #include "StRoot/StEEmcPool/StEEmcHitMaker/StESMDClustersPerSector.h"
33 
34 #include "StRoot/StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
35 
36 StEEmcTreeMaker_t::StEEmcTreeMaker_t( const Char_t *myName ) : StMaker( myName ), mNumEvents(0), mNumPart1EventsWritten(0), mMaxNumEvents(-1),
37  mSpinInfoIO(1), mEventHddrIO(1),
38  mDoMakePairs(1), mNumTowers( 0 ), mHTthres( 2 ), mTPthres( 4 ),
39  mEventHddr(0), mSpinInfo(0), mEEmcEnergy(0),
40  mBbcOnlineTimeDiff(0), mVertexRank(-999), mVertex(0), mHrdTrigSet(0), mSftTrigSet(0), mClusArr(0), mHitArr(0),
41  mParticleArr1(0), mParticleArr2(0), mET0ht(0), mET0tp(0),
42  mSpinInfoMkr(0), mEnMkr(0), mHitMkr(0) {
43  for( Int_t i=0; i<NUM_TREE_PARTS; ++i ){
44  mIOStat[i] = IGNORE;
45  mFile[i] = 0;
46  mTree[i] = 0;
47  mChain[i] = 0;
48  };
49 
50  mVertex = new TVector3();
51  mVertex->SetXYZ( -999, -999, -999 );
52 
53  mHrdTrigSet = new TrigSet();
54  mSftTrigSet = new TrigSet();
55 
56  // get pointer to the eta bin ranges
57  mEta = EEmcGeomSimple::Instance().getEtaBinRangeArray();
58 };
59 
60 
63  if( mClusArr )
64  delete mClusArr;
65 
66  if( mHitArr && mIOStat[ PART_2 ] != IGNORE )
67  delete mHitArr;
68 
69  if( mParticleArr1 )
70  delete mParticleArr1;
71 
72  if( mParticleArr2 )
73  delete mParticleArr2;
74 
75  if( mET0ht )
76  delete mET0ht;
77 
78  if( mET0tp )
79  delete mET0tp;
80 
81  if( mHrdTrigSet )
82  delete mHrdTrigSet;
83 
84  if( mSftTrigSet )
85  delete mSftTrigSet;
86 
87  for( Int_t i=0; i<NUM_TREE_PARTS; ++i ){
88  if( mChain[i] )
89  delete mChain[i];
90 
91  if( mFile[i] )
92  delete mFile[i];
93 
94  // no need to delete the TTree after deleting the TFile
95  };
96 
97  delete mVertex;
98 };
99 
102  Int_t ierr = kStOk;
103 
104  for( Int_t i=0; i<NUM_TREE_PARTS; ++i ){
105  LOG_INFO << GetName() << ": Part " << i+1 << " set to "
106  << ( mIOStat[i] == IGNORE ? "IGNORE" : ( mIOStat[i] == READ ? "READ" : "WRITE" ) )
107  << endm;
108  };
109 
110  if( !ierr ){
111  if( mIOStat[ PART_1 ] == READ ){
112  ierr = openForRead( PART_1 );
113 
114  if( !ierr ){
115  // set the branch addresses of the branches that must be there
116  mEEmcEnergy = 0;
117  mTree[PART_1]->SetBranchAddress( "eemcEnergy", &mEEmcEnergy );
118  mTree[PART_1]->SetBranchAddress( "vertex", &mVertex );
119  mTree[PART_1]->SetBranchAddress( "vertexRank", &mVertexRank );
120  mTree[PART_1]->SetBranchAddress( "bbcOnlineTimeDiff", &mBbcOnlineTimeDiff );
121  mTree[PART_1]->SetBranchAddress( "hardwareTriggers", &mHrdTrigSet );
122  mTree[PART_1]->SetBranchAddress( "softwareTriggers", &mSftTrigSet );
123 
124  // for searching for branches
125  TObjArray *branchArray = mTree[PART_1]->GetListOfBranches();
126 
127  // deal with evtHddr branch
128  TObject *objPtr = branchArray->FindObject("evtHddr");
129  if( objPtr ){
130  mTree[PART_1]->SetBranchStatus( "evtHddr", 0 );
131 
132  if( mEventHddrIO ){
133  mTree[PART_1]->SetBranchStatus( "evtHddr", 1 );
134  mEventHddr = 0;
135  mTree[PART_1]->SetBranchAddress( "evtHddr", &mEventHddr );
136  };
137  } else if ( mEventHddrIO ){
138  LOG_ERROR << "Requested EventHeaderIO, but event header branch not present in tree from file '" << mFilename[PART_1] << "'" << endm;
139  ierr = kStFatal;
140  };
141 
142  // deal with spinInfo branch
143  objPtr = branchArray->FindObject("spinInfo");
144  if( objPtr ){
145  mTree[PART_1]->SetBranchStatus( "spinInfo", 0 );
146 
147  if( mSpinInfoIO ){
148  mTree[PART_1]->SetBranchStatus( "spinInfo", 1 );
149  mSpinInfo = 0;
150  mTree[PART_1]->SetBranchAddress( "spinInfo", &mSpinInfo );
151  };
152  } else if ( mSpinInfoIO ){
153  LOG_ERROR << "Requested SpinInfoIO, but spin info branch not present in tree from file '" << mFilename[PART_1] << "'" << endm;
154  ierr = kStFatal;
155  };
156  };
157  } else if( mIOStat[ PART_1 ] == WRITE ){
158  ierr = openForWrite( PART_1, "EEmcTreePart1" );
159  if( !ierr ){
160  mEventHddr = 0;
161  if( mEventHddrIO )
162  mTree[PART_1]->Branch( "evtHddr", &mEventHddr );
163 
164  mSpinInfo = 0;
165  if( mSpinInfoIO )
166  mTree[PART_1]->Branch( "spinInfo", &mSpinInfo );
167 
168  mTree[PART_1]->Branch( "vertex", &mVertex );
169  mTree[PART_1]->Branch( "vertexRank", &mVertexRank );
170 
171  mTree[PART_1]->Branch( "hardwareTriggers", &mHrdTrigSet, 32000, 1 );
172  mTree[PART_1]->Branch( "softwareTriggers", &mSftTrigSet, 32000, 1 );
173 
174  mTree[PART_1]->Branch( "bbcOnlineTimeDiff", &mBbcOnlineTimeDiff );
175 
176  mEEmcEnergy = 0;
177  mTree[PART_1]->Branch( "eemcEnergy", &mEEmcEnergy );
178  };
179  } else if( mIOStat[ PART_1 ] == IGNORE ){
180  if( !mTreeRdr && !mEnMkr ){
181  LOG_FATAL << "If this StEEmcTreeMaker is ignoring Part 1, then one must set a pointer to a StEEmcTreeMaker with a valid EEmcEnergy_t or" << endm;
182  LOG_FATAL << "by setting a pointer to an EEmcEnergyMaker_t. This is done via calling StEEmcTreeMaker_t::setEEmcTreeReader(...) or " << endm;
183  LOG_FATAL << "StEEmcTreeMaker_t::setEEmcEnergyMaker(...) on this class before ::Init is called." << endm;
184  ierr = kStFatal;
185  };
186  };
187  };
188 
189  if( !ierr ){
190  if( mIOStat[ PART_2 ] != IGNORE ){
191  mClusArr = new TClonesArray( "EEmcSmdCluster_t", 100 );
192  mHitArr = new TClonesArray( "EEmcHit_t", 50 );
193 
194  if( mIOStat[ PART_2 ] == READ ){
195  ierr = openForRead( PART_2 );
196 
197  if( !ierr ){
198  mTree[ PART_2 ]->SetBranchStatus( "eemcClusArr", 1 );
199  mTree[ PART_2 ]->SetBranchStatus( "eemcHitArr", 1 );
200 
201  mTree[ PART_2 ]->SetBranchAddress( "eemcClusArr", &mClusArr );
202  mTree[ PART_2 ]->SetBranchAddress( "eemcHitArr", &mHitArr );
203  };
204  } else {
205  ierr = openForWrite( PART_2, "EEmcTreePart2" );
206  if( !ierr ){
207  mTree[ PART_2 ]->Branch( "eemcClusArr", &mClusArr );
208  mTree[ PART_2 ]->Branch( "eemcHitArr", &mHitArr );
209  };
210  };
211  };
212  };
213 
214  if( !ierr ){
215  if( mIOStat[ PART_3 ] != IGNORE ){
216  mParticleArr1 = new TClonesArray( "EEmcParticleCandidate_t", 10 );
217  mParticleArr2 = new TClonesArray( "EEmc2ParticleCandidate_t", 10 );
218 
219  if( mIOStat[ PART_3 ] == READ ){
220  ierr = openForRead( PART_3 );
221 
222  if( !ierr ){
223  mTree[ PART_3 ]->SetBranchStatus( "photon", 1 );
224  mTree[ PART_3 ]->SetBranchStatus( "pi0", 1 );
225  mTree[ PART_3 ]->SetBranchAddress( "photon", &mParticleArr1 );
226  mTree[ PART_3 ]->SetBranchAddress( "pi0", &mParticleArr2 );
227  };
228  } else {
229  ierr = openForWrite( PART_3, "EEmcTreePart3" );
230  if( !ierr ){
231  mTree[ PART_3 ]->Branch( "photon", &mParticleArr1 );
232  mTree[ PART_3 ]->Branch( "pi0", &mParticleArr2 );
233  };
234  };
235  };
236  };
237 
238  if( !ierr && mIOStat[ PART_4 ] != IGNORE ){
239  mET0ht = new TArrayF(5);
240  mET0tp = new TArrayF(5);
241 
242  if( mIOStat[ PART_4 ] == READ ){
243  ierr = openForRead( PART_4 );
244 
245  if( !ierr ){
246  // set the branch addresses of the branches that must be there
247  mTree[ PART_4 ]->SetBranchAddress( "htET0", &mET0ht );
248  mTree[ PART_4 ]->SetBranchAddress( "tpET0", &mET0tp );
249  };
250  } else {
251  ierr = openForWrite( PART_4, "EEmcTreePart4" );
252  if( !ierr ){
253  mTree[ PART_4 ]->Branch( "htET0", &mET0ht );
254  mTree[ PART_4 ]->Branch( "tpET0", &mET0tp );
255  };
256  };
257  };
258 
259  Int_t treeMax = -1111;
260  if( mIOStat[ PART_1 ] == READ && mChain[ PART_1 ]->GetEntries() > treeMax )
261  treeMax = mChain[ PART_1 ]->GetEntries();
262 
263  if( mIOStat[ PART_2 ] == READ && mChain[ PART_2 ]->GetEntries() > treeMax )
264  treeMax = mChain[ PART_2 ]->GetEntries();
265 
266  if( mIOStat[ PART_3 ] == READ && mChain[ PART_3 ]->GetEntries() > treeMax )
267  treeMax = mChain[ PART_3 ]->GetEntries();
268 
269  if( mIOStat[ PART_4 ] == READ && mChain[ PART_4 ]->GetEntries() > treeMax )
270  treeMax = mChain[ PART_4 ]->GetEntries();
271 
272  if( mMaxNumEvents < 0 || mMaxNumEvents > treeMax )
273  mMaxNumEvents = treeMax;
274 
275  return ierr;
276 };
277 
278 
281  Int_t ierr = kStOk;
282 
283  // if reading, throw error if read past the end
284  if( ( mIOStat[ PART_1 ] == READ || mIOStat[ PART_2 ] == READ || mIOStat[ PART_3 ] == READ ) && mNumEvents >= mMaxNumEvents )
285  ierr = kStEOF;
286 
287  // otherwise, only do stuff if not past the end
288  if( !ierr && ( mNumEvents < mMaxNumEvents || mMaxNumEvents < 0 ) ){
289  if( mIOStat[ PART_1 ] == READ ){
290  mChain[ PART_1 ]->GetEntry( mNumEvents );
291  } else if( mIOStat[ PART_1 ] == WRITE ){
292  ierr = fillPart1();
293  } else if( mIOStat[ PART_1 ] == IGNORE ){
294  if( mTreeRdr ){
295  mEEmcEnergy = mTreeRdr->getEEmcEnergy();
296  } else if ( mEnMkr ){
297  mEEmcEnergy = mEnMkr->getEEmcEnergyPtr();
298  } else {
299  LOG_FATAL << "Cannot find valid pointer for EEmcEnergy_t" << endm;
300  ierr = kStFatal;
301  };
302  };
303 
304  if( !ierr && mIOStat[ PART_2 ] == READ ){
305  mChain[ PART_2 ]->GetEntry( mNumEvents );
306  } else if( mIOStat[ PART_2 ] == IGNORE && mIOStat[ PART_3 ] != IGNORE ){
307  if( mTreeRdr ){
308  mHitArr = mTreeRdr->getHitArray();
309  assert( mHitArr ); // fix your chain
310  } else {
311  LOG_FATAL << "Cannot find valid pointer for the hit array" << endm;
312  ierr = kStFatal;
313  };
314  } else if( mIOStat[ PART_2 ] == WRITE ){
315  ierr = fillPart2();
316  };
317 
318  if( !ierr && mIOStat[ PART_3 ] == READ ){
319  mChain[ PART_3 ]->GetEntry( mNumEvents );
320  } else if( mIOStat[ PART_3 ] == WRITE ){
321  ierr = fillPart3();
322  };
323 
324  if( !ierr && mIOStat[ PART_4 ] == READ ){
325  mChain[ PART_4 ]->GetEntry( mNumEvents );
326  } else if( mIOStat[ PART_4 ] == WRITE ){
327  ierr = fillPart4();
328  };
329 
330  };
331 
332  // must increment after all the checks and processing
333  ++mNumEvents;
334  return ierr;
335 };
336 
337 Int_t StEEmcTreeMaker_t::fillPart1(){
338  Int_t ierr = kStOk;
339 
340  if( !mEnMkr ){
341  LOG_ERROR << "Must set energy maker pointer to write out Part 1" << endm;
342  ierr = kStFatal;
343  };
344 
345  mEEmcEnergy = mEnMkr->getEEmcEnergyPtr();
346  assert( mEEmcEnergy );
347 
348  // check if passes the simple filter
349  if( mEEmcEnergy->nTowers > mNumTowers ){
350 
351  // fill the hardware trigger
352  const StMuDst* muDst = (const StMuDst*)GetInputDS( "MuDst" );
353  if( muDst ){
354  StMuEvent *event = muDst->event();
355 
356  if( event )
357  mHrdTrigSet->insert( event->triggerIdCollection().nominal().triggerIds() ); // l1 -> nominal, Sept 18th
358  };
359 
360  // fill the software trigger
361  StTriggerSimuMaker *trgSimMkr= (StTriggerSimuMaker*) StMaker::GetChain()->GetMaker("StarTrigSimu");
362  if( trgSimMkr ){
363  // only copy Ids not vetoed
364  std::vector< UInt_t > trigIds;
365  const std::vector< int >& trigL0 = trgSimMkr->triggerIds();
366 
367  Int_t id = 0;
368  for( UInt_t i=0; i<trigL0.size(); ++i ){
369  //cout << mNumEvents << " L0 trig " << trigL0[i] << " passed L2?" << trgSimMkr->isTrigger( trigL0[i] ) << endl;
370  if( trgSimMkr->isTrigger( ( id = trigL0[i] ) ) )
371  trigIds.push_back( static_cast< UInt_t >( id ) );
372  };
373 
374  mSftTrigSet->insert( trigIds );
375  };
376 
377  if( mEventHddrIO )
378  mEventHddr = static_cast< StEvtHddr* >( GetEvtHddr()->Clone("eventHeader") );
379 
380  if( mSpinInfoIO ){
381  if( !mSpinInfoMkr ){
382  LOG_ERROR << "Requested to write SpinInfo, but pointer to maker not provided" << endm;
383  ierr = kStFatal;
384  } else {
385  mSpinInfo = mSpinInfoMkr->getSpinInfoPtr();
386  };
387  };
388 
389  if( !ierr ){
390  const StMuDst* muDst = (const StMuDst*)GetInputDS( "MuDst" );
391  mVertex->SetXYZ( -999, -999, -999 );
392  mVertexRank = -999;
393 
394  if( muDst ){
395  StMuEvent *event = muDst->event();
396 
397  if( event ){
398  const StThreeVectorF& v = event->primaryVertexPosition();
399  mVertex->SetXYZ( v.x(), v.y(), v.z() );
400  if( muDst->primaryVertex() )
401  mVertexRank = muDst->primaryVertex()->ranking();
402 
403 #ifdef DEBUG
404  cout << "vertex at " << v.x() << ' ' << v.y() << ' ' << v.z() << " | " << mVertex->X() << ' ' << mVertex->Y() << ' ' << mVertex->Z() << endl;
405 #endif
406 
407  mBbcOnlineTimeDiff = event->bbcTriggerDetector().onlineTimeDifference();
408  };
409  };
410 
411  mTree[ PART_1 ]->Fill();
412  ++mNumPart1EventsWritten;
413  };
414  };
415 
416  return ierr;
417 };
418 
419 
420 Int_t StEEmcTreeMaker_t::fillPart2(){
421  Int_t ierr = kStOk;
422 
423  if( !mHitMkr ){
424  LOG_ERROR << "Cannot fill Part 2, as no StEEmcHitMaker pointer was provided." << endm;
425  ierr = kStFatal;
426  };
427 
428  if( !ierr ){
429  // Clear. May not be needed, but just to be safe.
430  // Note, cluster and hit array must always be cleared with option "C".
431  mClusArr->Clear("C");
432  mHitArr->Clear("C");
433 
434  // convert from clus::ID to index in TClonesArray
435  std::map< Int_t, Int_t > clusMapU, clusMapV;
436 
437  if( mHitMkr->getIfClusteredSMD() ){
438 // Int_t nClus = mHitMkr->getNumSMDClusters();
439 // if( mClusArr->GetEntries() < nClus )
440 // mClusArr->Expand( nClus );
441 
442  const StESMDClustersVec_t& clusVec = mHitMkr->getESMDClustersVec();
443 
444  Int_t clusIdx = -1;
445  for( UInt_t i = 0; i<clusVec.size(); ++i ){
446  Short_t sector = clusVec[i].getSector();
447 
448  const StSimpleClusterVec_t& clusVecU = clusVec[i].getClusterVecU();
449  const StSimpleClusterVec_t& clusVecV = clusVec[i].getClusterVecV();
450 
451  Float_t *blah = new Float_t[12];
452  delete[] blah;
453  blah = 0;
454 
455  for( UInt_t j=0; j<clusVecU.size(); ++j ){
456  new( (*mClusArr)[++clusIdx] ) EEmcSmdCluster_t();
457  copySimpleClusterToSmdCluster( *mEEmcEnergy, sector, 0, clusVecU[j], *static_cast< EEmcSmdCluster_t* >( mClusArr->UncheckedAt( clusIdx ) ) );
458  clusMapU[ clusVecU[j].getID() ] = clusIdx;
459  };
460 
461  for( UInt_t j=0; j<clusVecV.size(); ++j ){
462  new( (*mClusArr)[++clusIdx] ) EEmcSmdCluster_t();
463  copySimpleClusterToSmdCluster( *mEEmcEnergy, sector, 1, clusVecV[j], *static_cast< EEmcSmdCluster_t* >( mClusArr->UncheckedAt( clusIdx ) ) );
464  clusMapV[ clusVecV[j].getID() ] = clusIdx;
465  };
466  };
467  };
468 
469  // copy hits
470  const StEEmcHitVec_t& hitVec = mHitMkr->getHitVec();
471  if( mHitArr->GetEntries() < (Int_t)hitVec.size() )
472  mHitArr->Expand( hitVec.size() );
473 
474  Int_t hitIdx = -1;
475  for( UInt_t i=0; i<hitVec.size(); ++i ){
476  if( hitVec[i].mUsedTowerIndices.GetSize() && hitVec[i].mUsedTowerWeights.GetSize() ){
477  new( (*mHitArr)[++hitIdx] ) EEmcHit_t();
478  copyStEEmcHitToEEmcHit( *mEEmcEnergy, clusMapU[ hitVec[i].getClusIDu() ], clusMapV[ hitVec[i].getClusIDv() ], hitVec[i],
479  *static_cast< EEmcHit_t* >( mHitArr->UncheckedAt( hitIdx ) ) );
480  };
481  };
482  };
483 
484 #ifdef DEBUG3
485  cout << "Filling part 2 with " << mClusArr->GetEntriesFast() << " clusters and " << mHitArr->GetEntriesFast() << " hits." << endl;
486 #endif
487  mTree[ PART_2 ]->Fill();
488 
489  return ierr;
490 };
491 
492 Int_t StEEmcTreeMaker_t::fillPart3(){
493  Int_t ierr = kStOk;
494 
495  // Clear. May not be needed, but just to be safe.
496  mParticleArr1->Clear();
497  mParticleArr2->Clear();
498 
499  assert( mHitArr ); // fix your chain
500 
501  Int_t numHits = mHitArr->GetEntriesFast();
502 
503  if( numHits ){
504  if( mParticleArr1->GetSize() < numHits )
505  mParticleArr1->Expand( numHits );
506 
507  Int_t numPairs = 0;
508  if( mDoMakePairs ){
509  numPairs = TMath::Binomial( numHits, 2 );
510  if( mParticleArr2->GetSize() < numPairs )
511  mParticleArr2->Expand( numPairs );
512  };
513 
514  TIter hitIter1 = mHitArr;
515  assert( mTreeRdr ); // update this later to use the energy maker???
516  TVector3* vertexPtr = mTreeRdr->getVertex();
517  assert( vertexPtr ); // fix your chain
518  mBbcOnlineTimeDiff = mTreeRdr->getBbcOnlineTimeDiff();
519 
520  if( vertexPtr->Z() < -900 && mBbcOnlineTimeDiff ){
521  // not vertex defined yet--use the BBC time diff.
522 
523  UInt_t bbcTimeBin = mBbcOnlineTimeDiff/32;
524 
525  vertexPtr->SetX( 0 );
526  vertexPtr->SetY( 0 );
527 
528  if( bbcTimeBin <= 2 )
529  vertexPtr->SetZ( 40.1377 );
530  else if( bbcTimeBin == 3 )
531  vertexPtr->SetZ( 54.1733 );
532  else if( bbcTimeBin == 4 )
533  vertexPtr->SetZ( 75.2597 );
534  else if( bbcTimeBin == 5 )
535  vertexPtr->SetZ( 66.9572 );
536  else if( bbcTimeBin == 6 )
537  vertexPtr->SetZ( 38.324 );
538  else if( bbcTimeBin == 7 )
539  vertexPtr->SetZ( 5.83516 );
540  else if( bbcTimeBin == 8 )
541  vertexPtr->SetZ( -27.6028 );
542  else if( bbcTimeBin == 9 )
543  vertexPtr->SetZ( -60.6408 );
544  else if( bbcTimeBin == 10 )
545  vertexPtr->SetZ( -91.4053 );
546  else if( bbcTimeBin == 11 )
547  vertexPtr->SetZ( -105.579 );
548  else if( bbcTimeBin == 12 )
549  vertexPtr->SetZ( -95.7182 );
550  else if( bbcTimeBin == 13 )
551  vertexPtr->SetZ( -85.9305 );
552  else if( bbcTimeBin >= 14 )
553  vertexPtr->SetZ( -87.5347 );
554  };
555 
556  EEmcHit_t *hitPtr1 = 0;
557  Int_t hitIdx = -1;
558  Int_t pairIdx = -1;
559  while(( hitPtr1 = static_cast< EEmcHit_t* >(hitIter1.Next()) )){
560  ++hitIdx;
561  new( (*mParticleArr1)[ hitIdx ] ) EEmcParticleCandidate_t( hitIdx, *hitPtr1, *vertexPtr );
562 
563  if( mDoMakePairs ){
564  const EEmcParticleCandidate_t *p1 = static_cast< const EEmcParticleCandidate_t* >( (*mParticleArr1)[ hitIdx ] );
565  EEmcParticleCandidate_t *p2 = 0;
566  TIter pIter = mParticleArr1;
567 
568  while( (p2 = static_cast< EEmcParticleCandidate_t* >(pIter.Next())) && p2->hitIdx1 != p1->hitIdx1 )
569  new( (*mParticleArr2)[ ++pairIdx ] ) EEmc2ParticleCandidate_t( *p1, *p2 );
570  };
571  };
572  };
573 
574 #ifdef DEBUG3
575  cout << "Filling part 3 with " << mParticleArr1->GetEntriesFast() << " + " << mParticleArr2->GetEntriesFast() << " particle candidates." << endl;
576 #endif
577  mTree[ PART_3 ]->Fill();
578 
579  return ierr;
580 };
581 
582 Int_t StEEmcTreeMaker_t::fillPart4(){
583  assert( mEEmcEnergy );
584 
585  std::vector< std::pair< Float_t, Float_t > > httpVec;
586 
587  const ETowEnergy_t& eTow = mEEmcEnergy->eTow;
588 
589  std::vector< Int_t > neighbors;
590  neighbors.reserve(9);
591 
592  // find a tower above threshold
593  for( Int_t idx=0; idx<720; ++idx ){
594  const EEmcElement_t& elem = eTow.getByIdx( idx );
595 
596  Int_t etabin = idx%12;
597  Double_t cosHeta = TMath::CosH( 0.5*( mEta[etabin]+mEta[etabin+1] ) );
598 
599  // check if passes ht thres
600  Double_t htET = elem.energy/cosHeta;
601  if( htET > mHTthres && !elem.fail ){
602 
603  // now compute trigger patch energy
604 
605  Int_t phiBin = idx/12;
606  Int_t phiBinLow = ( phiBin > 0 ? phiBin-1 : 59 );
607  Int_t phiBinHigh = ( phiBin < 59 ? phiBin+1 : 0 );
608 
609  neighbors.clear();
610 
611  neighbors.push_back(idx);
612  neighbors.push_back(etabin+12*phiBinLow);
613  neighbors.push_back(etabin+12*phiBinHigh);
614 
615  if( etabin > 0 ){
616  neighbors.push_back(idx-1);
617  neighbors.push_back(etabin+12*phiBinLow-1);
618  neighbors.push_back(etabin+12*phiBinHigh-1);
619  };
620 
621  if( etabin < 11 ){
622  neighbors.push_back(idx+1);
623  neighbors.push_back(etabin+12*phiBinLow+1);
624  neighbors.push_back(etabin+12*phiBinHigh+1);
625  };
626 
627  Double_t tpET = 0;
628  for( UInt_t i = 0; i<neighbors.size(); ++i ){
629  Int_t idx2 = neighbors[i];
630  const EEmcElement_t& elem = eTow.getByIdx( idx2 );
631  if( !elem.fail )
632  tpET += elem.energy / TMath::CosH( 0.5*( mEta[idx2%12]+mEta[idx2%12+1] ) );
633  };
634 
635  //cout << mNumEvents << ' ' << htET << ' ' << tpET << ' ' << phiBin << ' ' << etabin << endl;
636 
637  if( tpET > mTPthres )
638  httpVec.push_back( std::make_pair( htET, tpET ) );
639  };
640  };
641 
642 
643  mET0ht->Set( httpVec.size() );
644  mET0tp->Set( httpVec.size() );
645 
646  for( UInt_t i=0; i<httpVec.size(); ++i ){
647  const std::pair< Float_t, Float_t >& http = httpVec[i];
648 
649  // add at is really set at
650  mET0ht->AddAt( http.first, i);
651  mET0tp->AddAt( http.second, i);
652  };
653 
654  mTree[ PART_4 ]->Fill();
655 
656  return 0;
657 };
658 
660 void StEEmcTreeMaker_t::Clear(Option_t *opts ){
661  if( mIOStat[ PART_1 ] != IGNORE ){
662  if( mEventHddr )
663  mEventHddr->Clear();
664  if( mSpinInfo )
665  mSpinInfo->Clear();
666  if( mEEmcEnergy )
667  mEEmcEnergy->Clear();
668  if( mVertex )
669  mVertex->SetXYZ( -999, -999, -999 );
670  mVertexRank = -999;
671  mBbcOnlineTimeDiff = 0;
672  };
673 
674  if( mIOStat[ PART_2 ] != IGNORE ){
675  mClusArr->Clear("C");
676  mHitArr->Clear("C");
677  };
678 
679  if( mIOStat[ PART_3 ] != IGNORE ){
680  mParticleArr1->Clear();
681  mParticleArr2->Clear();
682  };
683 
684 };
685 
688 
689  // write out the trigger count information
690 
691  if( mIOStat[ PART_1 ] == WRITE ){
692  StTrigCounter* trigCounter = (StTrigCounter*)StMaker::GetChain()->GetMaker("trigCounter");
693  if( !trigCounter ){
694  LOG_WARN << "ERROR cannot find the trigger counter" << endl;
695  } else {
696  TArrayI trigArray(3);
697  trigArray[0] = trigCounter->getTrigID();
698  trigArray[1] = trigCounter->getNumEventsTot();
699  trigArray[2] = trigCounter->getNumEventsInCut();
700 
701  cout << "Writing trigger counts " << trigArray[0] << ' ' << trigArray[1] << ' ' << trigArray[2] << endl;
702  mFile[ PART_1 ]->WriteObject( &trigArray, "trigCounts" );
703  };
704  };
705 
706  for( Int_t ipart=0; ipart<NUM_TREE_PARTS; ++ipart ){
707  if( mIOStat[ ipart ] == WRITE ){
708  mFile[ ipart ]->Write();
709  mFile[ ipart ]->Close();
710  };
711  };
712 
713  return kStOk;
714 };
715 
717 void StEEmcTreeMaker_t::setTreeStatus( treeTypeEnum_t type, iostatus_t iostatus, const Char_t* fileName ){
718  mIOStat[ type ] = iostatus;
719  mFilename[ type ] = fileName;
720 };
721 
722 void StEEmcTreeMaker_t::setMaxNumEvents( Int_t maxNum ){
723  mMaxNumEvents = maxNum;
724 };
725 
726 void StEEmcTreeMaker_t::setSpinInfoMkr( StSpinInfoMaker_t* spinInfoMkr ){
727  mSpinInfoMkr = spinInfoMkr;
728 };
729 
730 void StEEmcTreeMaker_t::setEEmcEnergyMkr( StEEmcEnergyMaker_t* eMkr ){
731  mEnMkr = eMkr;
732 };
733 
734 void StEEmcTreeMaker_t::setEEmcHitMkr( StEEmcHitMaker_t* hMkr ){
735  mHitMkr = hMkr;
736 };
737 
738 void StEEmcTreeMaker_t::setEEmcTreeReader( StEEmcTreeMaker_t* treeRdr ){
739  mTreeRdr = treeRdr;
740 };
741 
742 void StEEmcTreeMaker_t::doSpinInfoIO( Bool_t doIt ){ mSpinInfoIO = doIt; };
743 void StEEmcTreeMaker_t::doEvtHddrIO( Bool_t doIt ){ mEventHddrIO = doIt; };
744 
745 Int_t StEEmcTreeMaker_t::openForRead( treeTypeEnum_t type ){
746  Int_t ierr = kStOk;
747 
748  mChain[type] = new TChain("tree");
749  Int_t nFiles = mChain[type]->Add( mFilename[type].data(), 1 );
750 
751  if( nFiles ){
752  LOG_INFO << "Opened " << nFiles << " based on '" << mFilename[type] << endm;
753  } else {
754  LOG_ERROR << "Opened " << nFiles << " based on '" << mFilename[type] << endm;
755  ierr = kStFatal;
756  };
757  mTree[type] = mChain[type];
758 
759  return ierr;
760 };
761 
762 Int_t StEEmcTreeMaker_t::openForWrite( treeTypeEnum_t type, const Char_t *name ){
763  Int_t ierr = kStOk;
764 
765  mFile[type] = new TFile( mFilename[type].data(), "RECREATE" );
766  if( mFile[type]->IsOpen() ){
767  LOG_INFO << "Opened file '" << mFilename[type] << "' for writing" << endm;
768  } else {
769  LOG_FATAL << "Error opening file '" << mFilename[type] << "'" << endm;
770  ierr = kStFatal;
771  };
772 
773  if( !ierr )
774  mTree[type] = new TTree( "tree", name );
775 
776  return ierr;
777 };
778 
779 void StEEmcTreeMaker_t::copySimpleClusterToSmdCluster( const EEmcEnergy_t& eemcEnergy, Short_t sector, Bool_t inLayerV, const StSimpleCluster_t& other, EEmcSmdCluster_t& clus ){
780  clus.sector = sector;
781  clus.inLayerV = inLayerV;
782  clus.seedStripIdx = other.getSeedMember();
783  clus.energy = 0;
784  clus.meanPos = 0;
785  clus.width = 0;
786 
787  // make a reference, so that one doesn't have to type such a long name
788  const TArrayS& iArr = other.getMemberArray();
789  const TArrayF& wArr = other.getWeightArray();
790 
791  clus.numUsedStrips = wArr.GetSize();
792  if( iArr.GetSize() < wArr.GetSize() )
793  clus.numUsedStrips = iArr.GetSize();
794 
795  if( clus.numUsedStrips > EEmcSmdCluster_t::kMaxClusterSize ) // cluster is too wide
796  clus.numUsedStrips = EEmcSmdCluster_t::kMaxClusterSize;
797 
798  // loop over used strips
799  for( Int_t i=0; i<clus.numUsedStrips; ++i ){
800  // copy the values
801  Int_t idx = clus.usedStripIdx[i] = iArr[i];
802  Float_t weight = clus.usedStripWeight[i] = wArr[i];
803 
804  // recompute mean, width, and energy
805  const EEmcElement_t& element = eemcEnergy.eSmd.sec[sector].layer[inLayerV].strip[ idx ];
806  Float_t energy = ( element.fail ? 0 : element.energy );
807 
808  energy *= weight;
809  clus.energy += energy;
810  clus.meanPos += energy*idx;
811  clus.width += energy*idx*idx;
812  };
813  if( clus.energy ){
814  clus.meanPos /= clus.energy;
815  clus.width /= clus.energy;
816  clus.width = sqrt( clus.width - clus.meanPos*clus.meanPos );
817  };
818 };
819 
820 void StEEmcTreeMaker_t::copyStEEmcHitToEEmcHit( const EEmcEnergy_t& eemcEnergy, Int_t uClusIdx, Int_t vClusIdx, const StEEmcHit_t& other, EEmcHit_t& hit ){
821  hit.uClusIdx = uClusIdx;
822  hit.vClusIdx = vClusIdx;
823 
824  const TVector3& position = other.getPosition();
825  hit.x = position.X();
826  hit.y = position.Y();
827  hit.eta = position.Eta();
828  hit.phi = position.Phi();
829 
830  hit.centralTowerIdx = other.getTowerIdx();
831 
832  // make a reference, so that one doesn't have to type such a long name
833  const TArrayS& iArr = other.mUsedTowerIndices;
834  const TArrayF& wArr = other.mUsedTowerWeights;
835 
836  // determine number of used towers
837  hit.numUsedTowers = wArr.GetSize();
838  if( hit.numUsedTowers > iArr.GetSize() )
839  hit.numUsedTowers = iArr.GetSize();
840 
841  if( hit.numUsedTowers > EEmcHit_t::kMaxNumTowers ) // too many towers to save them all
842  hit.numUsedTowers = EEmcHit_t::kMaxNumTowers;
843 
844  // clear
845  hit.eTow = hit.ePre1 = hit.ePre2 = hit.ePost = 0;
846 
847  // to hold onto after loop
848  Float_t centralTowerWeight = 0;
849 
850  //cout << "hit " << other.getID() << " central tower " << hit.centralTowerIdx << " num used " << hit.numUsedTowers << endl;
851 
852  // loop over towers
853  for( Int_t i = 0; i < hit.numUsedTowers; ++i ){
854  // copy the values
855  Short_t idx = hit.usedTowerIdx[i] = iArr[i];
856  Float_t weight = hit.usedTowerWeight[i] = wArr[i];
857 
858  const EEmcElement_t& towElement = eemcEnergy.eTow.getByIdx( idx );
859  const EEmcElement_t& pstElement = eemcEnergy.ePost.getByIdx( idx );
860 
861  hit.eTow += ( towElement.fail ? 0 : towElement.energy )*weight;
862  hit.ePost += ( pstElement.fail ? 0 : pstElement.energy )*weight;
863 
864  //cout << " \t used tower " << idx << ' ' << weight << endl;
865 
866  if( idx == hit.centralTowerIdx )
867  centralTowerWeight = weight;
868  };
869 
870  // if the central tower is not in the array of used towers, perhaps
871  // it was a failed tower, but the preshowers and post showers are
872  // still OK. Assume a weight of 1.
873  if( !centralTowerWeight )
874  centralTowerWeight = 1;
875 
876  // assert( centralTowerWeight ); // some code didn't include the central tower!
877 
878  // get the energy in the preshowers
879  const EEmcElement_t& pr1Element = eemcEnergy.ePre1.getByIdx( hit.centralTowerIdx );
880  const EEmcElement_t& pr2Element = eemcEnergy.ePre2.getByIdx( hit.centralTowerIdx );
881 
882  // set to negative 1 if failed.
883  hit.ePre1 = ( pr1Element.fail ? -1 : pr1Element.energy )*centralTowerWeight;
884  hit.ePre2 = ( pr2Element.fail ? -1 : pr2Element.energy )*centralTowerWeight;
885 };
886 
887 ClassImp( StEEmcTreeMaker_t );
888 
889 /*
890  * $Id: StEEmcTreeMaker.cxx,v 1.5 2013/02/28 23:37:18 sgliske Exp $
891  * $Log: StEEmcTreeMaker.cxx,v $
892  * Revision 1.5 2013/02/28 23:37:18 sgliske
893  * Updated so result of StTrigCounter gets saved in EEmcTree Part1
894  * rather than just being output to the console (log file)
895  *
896  * Revision 1.4 2013/02/28 02:34:48 sgliske
897  * bug fix for copying vertex rank
898  *
899  * Revision 1.3 2013/02/21 21:57:12 sgliske
900  * updated values of vertexZ for BBC time bins (affects part 3)
901  *
902  * Revision 1.2 2013/02/21 21:28:50 sgliske
903  * added vertex rank
904  *
905  * Revision 1.1 2012/11/26 19:06:10 sgliske
906  * moved from offline/users/sgliske/StRoot/StEEmcPool/StEEmcTreeMaker to StRoot/StEEmcPool/StEEmcTreeMaker
907  *
908  *
909  */
iostatus_t mIOStat[NUM_TREE_PARTS]
filenames
virtual TObject * Clone(const char *name=0) const
the custom implementation fo the TObject::Clone
Definition: StEvtHddr.h:14
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Definition: StMuDst.h:322
Int_t mMaxNumEvents
max number of events
StEvtHddr * mEventHddr
The data.
static EEmcGeomSimple & Instance()
returns a reference to a static instance of EEmcGeomSimple
UInt_t getTrigID() const
get values
TFile * mFile[NUM_TREE_PARTS]
TFiles/TTrees for writing.
UInt_t mNumTowers
thresholds for keeping the event
virtual ~StEEmcTreeMaker_t()
deconstructor
void setTreeStatus(treeTypeEnum_t type, iostatus_t iostatus, const Char_t *fileName)
modifiers
Int_t mNumEvents
number of events processed / written outt
UInt_t mBbcOnlineTimeDiff
BBC time difference.
const StEEmcHitVec_t & getHitVec() const
const accessors
StEEmcTreeMaker_t(const Char_t *myName)
constructor
void Clear(Option_t *opts="")
Clear for next event.
Bool_t mSpinInfoIO
whether to save various things
TChain * mChain[NUM_TREE_PARTS]
TChains for reading.
The class.
Definition: StEEmcHit.h:37
TVector3 * mVertex
the following pointers are owned by the class
Definition: Stypes.h:43
TArrayS mUsedTowerIndices
just a flag whether to keep in vector
Definition: StEEmcHit.h:101
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Int_t Make()
Build an event.
Int_t Finish()
Write everything to file.
Include StRoot headers.
Int_t Init()
Initialize.
Definition: dbStruct.hh:78
Definition: Stypes.h:41
StSpinInfo_t * getSpinInfoPtr()
Accessors.