StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHbtManager.cxx
1 /***************************************************************************
2  *
3  * $Id: StHbtManager.cxx,v 1.20 2001/06/21 19:15:46 laue Exp $
4  *
5  * Author: Mike Lisa, Ohio State, lisa@mps.ohio-state.edu
6  ***************************************************************************
7  *
8  * Description: part of STAR HBT Framework: StHbtMaker package
9  * The Manager is the top-level object that coordinates activities
10  * and performs event, particle, and pair loops, and checks the
11  * various Cuts of the Analyses in its AnalysisCollection
12  *
13  ***************************************************************************
14  *
15  * $Log: StHbtManager.cxx,v $
16  * Revision 1.20 2001/06/21 19:15:46 laue
17  * Modified fiels:
18  * CTH.hh : new constructor added
19  * StHbtEvent, StHbtKink, StHbtTrack : constructors from the persistent
20  * (TTree) classes added
21  * StHbtLikeSignAnalysis : minor changes, for debugging
22  * StHbtTypes: split into different files
23  * Added files: for the new TTree muDst's
24  * StExceptions.cxx StExceptions.hh StHbtEnumeration.hh
25  * StHbtHelix.hh StHbtHisto.hh StHbtString.hh StHbtTFile.hh
26  * StHbtTTreeEvent.cxx StHbtTTreeEvent.h StHbtTTreeKink.cxx
27  * StHbtTTreeKink.h StHbtTTreeTrack.cxx StHbtTTreeTrack.h
28  * StHbtTTreeV0.cxx StHbtTTreeV0.h StHbtVector.hh
29  *
30  * Revision 1.19 2000/05/08 15:45:50 laue
31  * Memory leak fixed. Current hbt event was not deleted
32  *
33  * Revision 1.18 2000/03/17 17:23:05 laue
34  * Roberts new three particle correlations implemented.
35  *
36  * Revision 1.16 2000/02/26 19:04:52 laue
37  * Some unnecessary includes removed.
38  * StThreeVectorD replace by StHbtThreeVector.
39  * StHbtCoulomb modified to compile without Root (ClassDef embraced into
40  * #ifdef __ROOT__ ..... #endif)
41  * StHbtParticle now returns references (FourMomentum(),Helix(),
42  * DecayVertexPosiion())
43  *
44  * Revision 1.15 2000/02/18 21:32:24 laue
45  * franksTrackCut changed. If mCharge is set to '0' there will be no cut
46  * on charge. This is important for front-loaded cuts.
47  *
48  * copy constructor implemented for StHbtEvent, StHbtTrack and StHbtV0.
49  *
50  * franks1HistoD.cxx franks1HistoD.h franks2HistoD.cxx franks2HistoD.h
51  * removed. We can now (CC5 on Solaris) use the versions (no D)
52  *
53  * Revision 1.14 2000/02/13 17:17:12 laue
54  * Calls to the EventBegin() and EventEnd() functions implemented
55  * The actual analysis is moved from StHbtManager to StHbtAnalysis
56  *
57  * Revision 1.13 2000/01/25 17:35:17 laue
58  * I. In order to run the stand alone version of the StHbtMaker the following
59  * changes have been done:
60  * a) all ClassDefs and ClassImps have been put into #ifdef __ROOT__ statements
61  * b) unnecessary includes of StMaker.h have been removed
62  * c) the subdirectory StHbtMaker/doc/Make has been created including everything
63  * needed for the stand alone version
64  *
65  * II. To reduce the amount of compiler warning
66  * a) some variables have been type casted
67  * b) some destructors have been declared as virtual
68  *
69  * Revision 1.12 1999/10/15 01:57:29 lisa
70  * Important enhancement of StHbtMaker - implement Franks CutMonitors
71  * ----------------------------------------------------------
72  * This means 3 new files in Infrastructure area (CutMonitor),
73  * several specific CutMonitor classes in the Cut area
74  * and a new base class in the Base area (StHbtCutMonitor).
75  * This means also changing all Cut Base class header files from .hh to .h
76  * so we have access to CutMonitor methods from Cint command line.
77  * This last means
78  * 1) files which include these header files are slightly modified
79  * 2) a side benefit: the TrackCuts and V0Cuts no longer need
80  * a SetMass() implementation in each Cut class, which was stupid.
81  * Also:
82  * -----
83  * Include Franks StHbtAssociationReader
84  * ** None of these changes should affect any user **
85  *
86  * Revision 1.11 1999/10/04 15:38:57 lisa
87  * include Franks new accessor methods StHbtAnalysis::CorrFctn and StHbtManager::Analysis as well as McEnt example macro
88  *
89  * Revision 1.10 1999/09/17 22:38:02 lisa
90  * first full integration of V0s into StHbt framework
91  *
92  * Revision 1.9 1999/09/08 04:15:52 lisa
93  * persistent microDST implementation tweaked to please fickle solaris details
94  *
95  * Revision 1.8 1999/09/05 02:58:11 lisa
96  * add ASCII microDST reader/writer AND franksParticle cuts
97  *
98  * Revision 1.7 1999/09/04 04:41:01 lisa
99  * StHbtEvent IO --and-- StHbtEventWriter (microDST) method added to framework
100  *
101  * Revision 1.6 1999/09/03 22:39:15 lisa
102  * Readers now MUST have Report() methods and MAY have WriteHbtEvent() methods
103  *
104  * Revision 1.5 1999/07/27 10:47:04 lisa
105  * now works in dev on linux and solaris - mistake in deleting picoEvents fixed
106  *
107  * Revision 1.4 1999/07/26 16:21:26 lisa
108  * always convert string to char when output - needed on solaris
109  *
110  * Revision 1.3 1999/07/22 18:49:10 lisa
111  * Implement idea of Fabrice to not create and delete StHbtPair all the time
112  *
113  * Revision 1.2 1999/07/06 22:33:22 lisa
114  * Adjusted all to work in pro and new - dev itself is broken
115  *
116  * Revision 1.1.1.1 1999/06/29 16:02:57 lisa
117  * Installation of StHbtMaker
118  *
119  **************************************************************************/
120 
121 #include "StHbtMaker/Infrastructure/StHbtManager.h"
122 //#include "StHbtMaker/Infrastructure/StHbtParticleCollection.hh"
123 //#include "StHbtMaker/Base/StHbtTrackCut.h"
124 //#include "StHbtMaker/Base/StHbtV0Cut.h"
125 #include <cstdio>
126 
127 #ifdef __ROOT__
128 ClassImp(StHbtManager)
129 #endif
130 
131 
132 
133 //____________________________
134 StHbtManager::StHbtManager(){
135  mAnalysisCollection = new StHbtAnalysisCollection;
136  mEventWriterCollection = new StHbtEventWriterCollection;
137  mEventReader = 0;
138 }
139 //____________________________
140 StHbtManager::~StHbtManager(){
141  delete mEventReader;
142  // now delete each Analysis in the Collection, and then the Collection itself
143  StHbtAnalysisIterator AnalysisIter;
144  for (AnalysisIter=mAnalysisCollection->begin();AnalysisIter!=mAnalysisCollection->end();AnalysisIter++){
145  delete *AnalysisIter;
146  *AnalysisIter = 0;
147  }
148  delete mAnalysisCollection;
149  // now delete each EventWriter in the Collection, and then the Collection itself
150  StHbtEventWriterIterator EventWriterIter;
151  for (EventWriterIter=mEventWriterCollection->begin();EventWriterIter!=mEventWriterCollection->end();EventWriterIter++){
152  delete *EventWriterIter;
153  *EventWriterIter = 0;
154  }
155  delete mEventWriterCollection;
156 }
157 //____________________________
158 int StHbtManager::Init(){
159  StHbtString readerMessage;
160  readerMessage += "*** *** *** *** *** *** *** *** *** *** *** *** \n";
161  // EventReader
162  if (mEventReader) {
163  if (mEventReader->Init("r",readerMessage)){
164  cout << " StHbtManager::Init() - Reader initialization failed " << endl;
165  return (1);
166  }
167  readerMessage += mEventReader->Report();
168  }
169  // EventWriters
170  StHbtEventWriterIterator EventWriterIter;
171  for (EventWriterIter=mEventWriterCollection->begin();EventWriterIter!=mEventWriterCollection->end();EventWriterIter++){
172  //cout << "*EventWriterIter " << *EventWriterIter << endl;
173  // The message (StHbtString) passed into Init will be at the file header.
174  // for that reason take the readerReport, add my own report and pass as message
175  StHbtString writerMessage = readerMessage;
176  writerMessage += "*** *** *** *** *** *** *** *** *** *** *** *** \n";
177  writerMessage += (*EventWriterIter)->Report();
178  if (*EventWriterIter) {
179  if ( (*EventWriterIter)->Init("w",writerMessage)){ // yes, the message from the reader is passed into the writer
180  cout << " StHbtManager::Init() - Writer initialization failed " << endl;
181  return (1);
182  }
183  }
184  }
185 
186 
187  return (0);
188 }
189 //____________________________
190 void StHbtManager::Finish(){
191  // EventReader
192  if (mEventReader) mEventReader->Finish();
193  // EventWriters
194  StHbtEventWriterIterator EventWriterIter;
195  StHbtEventWriter* currentEventWriter;
196  for (EventWriterIter=mEventWriterCollection->begin();EventWriterIter!=mEventWriterCollection->end();EventWriterIter++){
197  currentEventWriter = *EventWriterIter;
198  currentEventWriter->Finish();
199  }
200  // Analyses
201  StHbtAnalysisIterator AnalysisIter;
202  StHbtBaseAnalysis* currentAnalysis;
203  for (AnalysisIter=mAnalysisCollection->begin();AnalysisIter!=mAnalysisCollection->end();AnalysisIter++){
204  currentAnalysis = *AnalysisIter;
205  currentAnalysis->Finish();
206  }
207 }
208 //____________________________
209 StHbtString StHbtManager::Report(){
210  string stemp;
211  char ctemp[100];
212  // EventReader
213  stemp = mEventReader->Report();
214  // EventWriters
215  sprintf(ctemp,"\nStHbtManager Reporting %u EventWriters\n",mEventWriterCollection->size());
216  stemp += ctemp;
217  StHbtEventWriterIterator EventWriterIter;
218  StHbtEventWriter* currentEventWriter;
219  for (EventWriterIter=mEventWriterCollection->begin();EventWriterIter!=mEventWriterCollection->end();EventWriterIter++){
220  cout << "StHbtManager - asking for EventWriter Report" << endl;
221  currentEventWriter = *EventWriterIter;
222  stemp+=currentEventWriter->Report();
223  }
224  // Analyses
225  sprintf(ctemp,"\nStHbtManager Reporting %u Analyses\n",mAnalysisCollection->size());
226  stemp += ctemp;
227  StHbtAnalysisIterator AnalysisIter;
228  StHbtBaseAnalysis* currentAnalysis;
229  for (AnalysisIter=mAnalysisCollection->begin();AnalysisIter!=mAnalysisCollection->end();AnalysisIter++){
230  cout << "StHbtManager - asking for Analysis Report" << endl;
231  currentAnalysis = *AnalysisIter;
232  stemp+=currentAnalysis->Report();
233  }
234 
235  StHbtString returnThis = stemp;
236  return returnThis;
237 }
238 //____________________________
239 StHbtBaseAnalysis* StHbtManager::Analysis( int n ){ // return pointer to n-th analysis
240  if ( n<0 || n > (int) mAnalysisCollection->size() )
241  return NULL;
242  StHbtAnalysisIterator iter = mAnalysisCollection->begin();
243  for (int i=0; i<n ;i++){
244  iter++;
245  }
246  return *iter;
247 }
248 //____________________________
249 StHbtEventWriter* StHbtManager::EventWriter( int n ){ // return pointer to n-th analysis
250  if ( n<0 || n > (int) mEventWriterCollection->size() )
251  return NULL;
252  StHbtEventWriterIterator iter = mEventWriterCollection->begin();
253  for (int i=0; i<n ;i++){
254  iter++;
255  }
256  return *iter;
257 }
258  //____________________________
259 int StHbtManager::ProcessEvent(){
260  cout << "StHbtManager::ProcessEvent" << endl;
261  // NOTE - this ReturnHbtEvent makes a *new* StHbtEvent - delete it when done!
262  StHbtEvent* currentHbtEvent = mEventReader->ReturnHbtEvent();
263  cout << "Event reader has returned control to manager" << endl;
264 
265  // if no HbtEvent is returned, then we abort processing.
266  // the question is now: do we try again next time (i.e. there may be an HbtEvent next time)
267  // or are we at EOF or something? If Reader says Status=0, then that means try again later.
268  // so, we just return the Reader's Status.
269  if (!currentHbtEvent){
270  cout << "StHbtManager::ProcessEvent() - Reader::ReturnHbtEvent() has returned null pointer\n";
271  return mEventReader->Status();
272  }
273 
274  // loop over all the EventWriters
275  StHbtEventWriterIterator EventWriterIter;
276  for (EventWriterIter=mEventWriterCollection->begin();EventWriterIter!=mEventWriterCollection->end();EventWriterIter++){
277 #ifdef STHBRDEBUG
278  cout << " *EventWriterIter " << *EventWriterIter << endl;
279 #endif
280  (*EventWriterIter)->WriteHbtEvent(currentHbtEvent);
281  }
282 
283  // loop over all the Analysis
284  StHbtAnalysisIterator AnalysisIter;
285  for (AnalysisIter=mAnalysisCollection->begin();AnalysisIter!=mAnalysisCollection->end();AnalysisIter++){
286  (*AnalysisIter)->ProcessEvent(currentHbtEvent);
287  }
288 
289  if (currentHbtEvent) delete currentHbtEvent;
290 #ifdef STHBRDEBUG
291  cout << "StHbtManager::ProcessEvent() - return to caller ... " << endl;
292 #endif
293  return 0; // 0 = "good return"
294 } // ProcessEvent