StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTrigTreeMaker.cxx
1 /*
2  * Created by S. Gliske, Aug 2012
3  *
4  * Description: see header
5  *
6  */
7 
8 
9 //#define DEBUG
10 
11 #include <Rtypes.h>
12 #include <TTree.h>
13 #include <TFile.h>
14 
15 #include <set>
16 #include <vector>
17 
18 #include "StTrigTreeMaker.h"
19 #include "StMuDSTMaker/COMMON/StMuDst.h"
20 #include "StMuDSTMaker/COMMON/StMuEvent.h"
21 
22 #include "StRoot/StEEmcPool/./EEmcTreeContainers/TrigSet.h"
23 
24 StTrigTreeMaker_t::StTrigTreeMaker_t( const Char_t *myName, const Char_t* filenameOut, Bool_t isMC, Bool_t useSimu )
25  : StMaker( myName ), mIsMC( isMC ), mUseSimuTrg( useSimu ), mFilename( filenameOut), mFile( 0 ), mTree( 0 ), mTrigSet( 0 ) { /* */ };
26 
29  if( mTrigSet )
30  delete mTrigSet;
31  if( mFile )
32  delete mFile;
33  // no need to delete the TTree after deleting the TFile
34 };
35 
38 
39 #ifdef DEBUG
40  cout << "--------------------------------------------------> StTrigTreeMaker_t::Init() <--------------------------------------------------" << endl;
41 #endif
42 
43  Int_t ierr = kStOk;
44 
45  // check trigger set
46  if( mTriggerSet.empty() ){
47  LOG_FATAL << "ERROR: trigger set is empty." << endm;
48  LOG_FATAL << "If you really want to process all triggers, enter a single trigger ID of -999." << endm;
49  ierr = kStFatal;
50  } else if (mTriggerSet.size() == 1 && mTriggerSet.count( -999 ) ) {
51  // user has flagged to process all triggers
52  mTriggerSet.clear();
53  };
54 
55  if( !ierr ){
56  mFile = TFile::Open( mFilename.data(), "RECREATE" );
57  assert( mFile && mFile->IsOpen() );
58  if( mFile->IsOpen() ){
59  LOG_INFO << "Opened file '" << mFilename << "' for writing" << endm;
60  } else {
61  LOG_FATAL << "Error opening file '" << mFilename << "'" << endm;
62  ierr = kStFatal;
63  };
64  };
65 
66  if( !ierr ){
67  if( mIsMC )
68  mTree = new TTree( "tree", "StMcTrigTree" );
69  else
70  mTree = new TTree( "tree", "StTrigTree" );
71 
72  mTrigSet = new TrigSet();
73  mTree->Branch( "trigSet", &mTrigSet, 32000, 1 );
74  };
75 
76 #ifdef DEBUG
77  cout << "--------------------------------------------------> end of StTrigTreeMaker_t::Init() <--------------------------------------------------" << endl;
78 #endif
79 
80  return ierr;
81 };
82 
83 
86 
87 #ifdef DEBUG
88  cout << "--------------------------------------------------> StTrigTreeMaker_t::Make() <--------------------------------------------------" << endl;
89 #endif
90 
91  mTrigSet->Clear();
92  Bool_t passesCuts = 1;
93 
94  if( mIsMC || mUseSimuTrg ){
95  StTriggerSimuMaker *trgSimMkr= (StTriggerSimuMaker*) StMaker::GetChain()->GetMaker("StarTrigSimu");
96  assert(trgSimMkr);
97 
98  if( !mTriggerSet.empty() ){
99  passesCuts = 0;
100 
101  std::set< UInt_t >::iterator iter = mTriggerSet.begin();
102  for( ; iter != mTriggerSet.end() && !passesCuts; ++iter )
103  passesCuts = trgSimMkr->isTrigger( (*iter) );
104  };
105 
106  if( passesCuts ){
107  // only copy Ids not vetoed
108  std::vector< UInt_t > trigIds;
109  const std::vector< int >& trigL0 = trgSimMkr->triggerIds();
110 
111  Int_t id = 0;
112  for( UInt_t i=0; i<trigL0.size(); ++i )
113  if( trgSimMkr->isTrigger( ( id = trigL0[i] ) ) )
114  trigIds.push_back( static_cast< UInt_t >( id ) );
115 
116  mTrigSet->insert( trigIds );
117  };
118 
119  } else {
120 
121  const StMuDst* muDst = (const StMuDst*)GetInputDS( "MuDst" );
122  if( muDst ){
123  StMuEvent *event = muDst->event();
124 
125  if( event ){
126  const StTriggerId& l1trig = event->triggerIdCollection().l1();
127 
128  if( !mTriggerSet.empty() ){
129  passesCuts = 0;
130 
131  std::set< UInt_t >::iterator iter = mTriggerSet.begin();
132  for( ; iter != mTriggerSet.end() && !passesCuts; ++iter )
133  passesCuts = l1trig.isTrigger( (*iter) );
134  };
135 
136  if( passesCuts ){
137  const std::vector< UInt_t > &trigIds = l1trig.triggerIds();
138  mTrigSet->insert( trigIds );
139  };
140  };
141  };
142  };
143 
144 #ifdef DEBUG
145  cout << "--------------------------------------------------> fill (" << passesCuts << ") <--------------------------------------------------" << endl;
146 #endif
147 
148  if( passesCuts )
149  mTree->Fill();
150 
151 #ifdef DEBUG
152  cout << "--------------------------------------------------> end of StTrigTreeMaker_t::Make() <--------------------------------------------------" << endl;
153 #endif
154 
155  return kStOK;
156 };
157 
159 void StTrigTreeMaker_t::Clear(Option_t *opts ){
160 #ifdef DEBUG
161  cout << "--------------------------------------------------> StTrigTreeMaker_t::Clear() <--------------------------------------------------" << endl;
162 #endif
163 
164  if( mTrigSet )
165  mTrigSet->Clear();
166 
167 #ifdef DEBUG
168  cout << "--------------------------------------------------> end of StTrigTreeMaker_t::Clear() <--------------------------------------------------" << endl;
169 #endif
170 
171 };
172 
175 
176 #ifdef DEBUG
177  cout << "--------------------------------------------------> StTrigTreeMaker_t::Finish() <--------------------------------------------------" << endl;
178 #endif
179 
180  mFile->Write();
181  mFile->Close();
182 
183 #ifdef DEBUG
184  cout << "--------------------------------------------------> end of StTrigTreeMaker_t::Finish() <--------------------------------------------------" << endl;
185 #endif
186 
187  return kStOk;
188 };
189 
190 
191 ClassImp( StTrigTreeMaker_t );
192 
193 /*
194  * $Id: StTrigTreeMaker.cxx,v 1.1 2012/11/26 19:06:11 sgliske Exp $
195  * $Log: StTrigTreeMaker.cxx,v $
196  * Revision 1.1 2012/11/26 19:06:11 sgliske
197  * moved from offline/users/sgliske/StRoot/StEEmcPool/StEEmcTreeMaker to StRoot/StEEmcPool/StEEmcTreeMaker
198  *
199  *
200  */
Bool_t mIsMC
whether is Monte Carlo or data
void Clear(Option_t *opts="")
Clear for next event.
Int_t Init()
Initialize.
virtual ~StTrigTreeMaker_t()
deconstructor
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
Definition: Stypes.h:40
Int_t Finish()
Write everything to file.
Int_t Make()
Build an event.
TFile * mFile
TFiles/TTrees for writing.
std::string mFilename
filenames
StTrigTreeMaker_t(const Char_t *myName="TrigTreeMaker", const Char_t *filenameOut="trigTree.root", Bool_t isMC=0, Bool_t useSimu=1)
constructor
Definition: Stypes.h:41
Bool_t mUseSimuTrg
whether to use MuDst (hardware) triggers or simulated (software) triggers