StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEEmcDisplayMaker.cxx
1 #include "StEEmcDisplayMaker.h"
2 
3 #include "StEEmcPool/StEEmcA2EMaker/StEEmcA2EMaker.h"
4 #include "StEEmcPool/StEEmcClusterMaker/StEEmcGenericClusterMaker.h"
5 #include "StEEmcPool/StEEmcPointMaker/StEEmcGenericPointMaker.h"
6 #include "StEEmcPool/StEEmcPi0Mixer/StEEmcPi0Maker.h"
7 
8 #include "StMessMgr.h"
9 
10 
11 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
12 #include "StMuDSTMaker/COMMON/StMuDst.h"
13 #include "StMuDSTMaker/COMMON/StMuEvent.h"
14 #include "StMuDSTMaker/COMMON/StMuTriggerIdCollection.h"
15 
16 #include "StEvent/StEvent.h"
17 #include "StEvent/StTriggerIdCollection.h"
18 #include "StEvent/StTriggerId.h"
19 
20 #include "StEEmcDisplay.h"
21 
22 #include "TString.h"
23 #include "TTree.h"
24 
25 ClassImp(StEEmcDisplayMaker);
26 
27 StEEmcDisplayMaker::StEEmcDisplayMaker( const Char_t *name ) : StMaker(name)
28 {
29  mDisplay=new StEEmcDisplay();
30  mFileLocal=true;
31  mFile=0;
32  mTree=0;
33  mCheckTrigger=false;
34 }
35 
36 // ----------------------------------------------------------------------------
37 Int_t StEEmcDisplayMaker::Init()
38 {
39 
40  // create TTree, but only if a file is specified
41  if ( mFile )
42  {
43  LOG_INFO<<"creating TTree, resident in file="<<mFile->GetName()<<endm;
44  mTree=new TTree("mTree","StEEmcDisplayMaker TTree");
45  mTree->Branch("display",&mDisplay,32000,2);
46  mTree->SetDirectory( mFile ); /* directory resides on disk */
47  }
48 
49  return StMaker::Init();
50 }
51 
52 // ----------------------------------------------------------------------------
54 {
55 
56 
57  Int_t run = GetRunNumber();
58  Int_t event = GetEventNumber();
59 
60  LOG_INFO<<"run="<<run<<" event="<<event<<endm;
61 
62  Int_t triggerid = checkTrigger();
63  if ( mCheckTrigger && !triggerid ) return kStOK;
64 
65  LOG_INFO << "triggers "<<triggerList()<<endm;
66 
67 
68  /*
69  * User event selection.
70  *
71  * The way the code is configured by default, all events which satisfy
72  * the trigger conditions will be saved. This can get expensive in terms
73  * of disk space. If you're looking for "rare" events, this is a good
74  * place to select them.
75  *
76  * The example below checks the pi0 finder for a pi0 or eta candidate
77  *
78  */
79 
80 #if 0
81 
82  if ( mEEpairs )
83  {
84  Bool_t go = false;
85  StEEmcPairVec_t pairs = mEEpairs->pairs();
86  for ( UInt_t ii=0;ii<pairs.size();ii++ )
87  {
88  if ( pair.mass() > 0.11 && pair.mass() < 0.16 ) go = true;
89  if ( pair.mass() > 0.45 && pair.mass() < 0.65 ) go = true;
90  }
91  if ( !go ) return kStOK;
92  }
93 
94 #endif
95 
96 
97  /*
98  *
99  */
100 
101 
102 
103  // form title and name for display
104  TString name="R";name+=run;name+="-";name+=event;
105  TString title="run=";title+=run;
106  title+=" event=";title+=event;
107  title+=" triggers=";title+=triggerList();
108 
109  title+=" ntow/pre1/pre2/post=";
110  title+=mEEanalysis->numberOfHitTowers(0);title+="/";
111  title+=mEEanalysis->numberOfHitTowers(1);title+="/";
112  title+=mEEanalysis->numberOfHitTowers(2);title+="/";
113  title+=mEEanalysis->numberOfHitTowers(3);
114 
115  mDisplay->SetName(name);
116  mDisplay->SetTitle(title);
117 
118  /*
119  * ADC to Energy
120  */
121 
122  if ( mEEanalysis )
123  {
124 
125  // add hit towers to display (0=towers, ..., 3=postshower)
126  for ( Int_t layer=0;layer<4;layer++ )
127  for ( Int_t i=0;i<mEEanalysis->numberOfHitTowers(layer);i++ )
128  mDisplay->add( mEEanalysis->hittower(i,layer) );
129 
130  // add hit smd strips to display
131  for ( Int_t sec=0;sec<12;sec++ )
132  for ( Int_t plane=0;plane<2;plane++ )
133  for ( Int_t i=0;i<mEEanalysis->numberOfHitStrips(sec,plane);i++ )
134  mDisplay->add( mEEanalysis->hitstrip(sec,plane,i) );
135 
136  }
137  else
138  LOG_WARN<<" adc-to-energy maker not in chain"<<endm;
139 
140  /*
141  ***********************************************************
142  *
143  * SMD Clusters
144  *
145  ***********************************************************
146  */
147  StEEmcSmdClusterVec_t uclusters; // flat array of smd-u clusters
148  StEEmcSmdClusterVec_t vclusters; // flat array of smd-v clusters
149  std::vector<Int_t> uflags; // flags for smd-u clusters
150  std::vector<Int_t> vflags; // flags for smd-v clusters
151  std::map<Int_t,Int_t> umap; // map for key -> index of smd-u cluster in above arrays
152  std::map<Int_t,Int_t> vmap; // map for key -> index of smd-v cluster in above arrays
153 
154  Int_t nu=0;
155  Int_t nv=0;
156 
157  if ( mEEclusters )
158  {
159 
160  for ( Int_t sec=0;sec<12;sec++ )
161  {
162  StEEmcSmdClusterVec_t u=mEEclusters->smdclusters(sec,0);
163  for ( UInt_t ii=0;ii<u.size();ii++ )
164  {
165  uclusters.push_back( u[ii] );
166  uflags.push_back(0);
167  umap[ u[ii].key() ] = nu;
168  LOG_INFO<<"++++ ukey="<<u[ii].key()<<" uid="<<nu << endm;
169  nu++;
170  }
171 
172  StEEmcSmdClusterVec_t v=mEEclusters->smdclusters(sec,1);
173  for ( UInt_t ii=0;ii<v.size();ii++ )
174  {
175  vclusters.push_back( v[ii] );
176  vflags.push_back(0);
177  vmap[ v[ii].key() ] = nv;
178  LOG_INFO<<"++++ vkey="<<v[ii].key()<<" vid="<<nv << endm;
179  nv++;
180  }
181 
182  }
183 
184  }
185  else
186  LOG_WARN<<" cluster maker not in chain"<<endm;
187 
188 
189  /*
190  ******************************************************
191  *
192  * Points
193  *
194  ******************************************************
195  */
196  StEEmcPointVec_t points;
197  std::vector<Int_t> pflags;
198  std::vector<Int_t> point_uid;
199  std::vector<Int_t> point_vid;
200 
201  if ( mEEpoints )
202  {
203  points = mEEpoints->points();
204  for ( UInt_t ii=0;ii<points.size();ii++ )
205  {
206  StEEmcPoint p=points[ii];
207  StEEmcSmdCluster u=p.cluster(0);
208  StEEmcSmdCluster v=p.cluster(1);
209  Int_t ukey=u.key();
210  Int_t vkey=v.key();
211  pflags.push_back( 0 );
212  Int_t uid=umap[ukey];
213  Int_t vid=vmap[vkey];
214  point_uid.push_back( uid );
215  point_vid.push_back( vid );
216  LOG_INFO<<"++++" << " point key="<<p.key()<<" ukey="<<ukey<<" vkey="<<vkey << " uid="<<uid<<" vid="<<vid << endm;
217  }
218 
219  }
220  else
221  LOG_WARN<<" point maker not in chain" << endm;
222 
223 
224  /*
225  ******************************************************
226  *
227  * Pairs
228  *
229  ******************************************************
230  */
231 
232  StEEmcPairVec_t pairs;
233  if ( mEEpairs )
234  {
235  pairs = mEEpairs->pairs();
236  }
237  else
238  LOG_WARN<<" pi0 maker is not in chain"<<endm;
239 
240 
241 
242  /*
243  ******************************************************
244  *
245  * Build display data
246  *
247  ******************************************************
248  */
249 
250  // loop over points and add to display
251 
252  for ( UInt_t i = 0; i < points.size(); i++ )
253  {
254 
255 
256  Int_t icol = 20 + 10 * ( i%3 ) + i/3;
257 
258  StEEmcPoint p = points[i];
259  mDisplay->add(p,icol);
260 
261  StEEmcSmdCluster u=uclusters[ point_uid[i] ];
262  StEEmcSmdCluster v=vclusters[ point_vid[i] ];
263 
264 
265 
266  mDisplay->add(u, icol, 1001);
267  mDisplay->add(v, icol, 1001);
268 
269  uflags[ point_uid[i] ] = 1; // flag cluster as already displayed
270  vflags[ point_vid[i] ] = 1; // flag cluster as already displayed
271 
272  }
273 
274  // loop over unassociated u clusters and add to display
275 
276  for ( UInt_t i = 0; i < uclusters.size(); i++ )
277  {
278 
279  if ( uflags[i] ) continue; // cluster is claimed by a point
280  mDisplay->add( uclusters[i], 13+i%5, 3425 );
281 
282  }
283 
284  for ( UInt_t i = 0; i < vclusters.size(); i++ )
285  {
286 
287  if ( vflags[i] ) continue; // cluster is claimed by a point
288  mDisplay->add( vclusters[i], 13+i%5, 3425 );
289 
290  }
291 
292  if ( mTree )
293  {
294  mTree->Fill();
295  }
296  else
297  LOG_WARN<<" tree doesn't exist, no data saved"<<endm;
298 
299 
300  return kStOK;
301 }
302 
303 // ----------------------------------------------------------------------------
304 void StEEmcDisplayMaker::Clear( Option_t *opts )
305 {
306  mDisplay->clear();
307 }
308 
309 // ----------------------------------------------------------------------------
310 TFile *StEEmcDisplayMaker::setFile( const Char_t *file, const Option_t *opts )
311 {
312  mFile=new TFile(file,opts);
313  mFileLocal=true;
314  return mFile;
315 }
316 TFile *StEEmcDisplayMaker::setFile( TFile *file )
317 {
318  mFile=file;
319  mFileLocal=false;
320  return mFile;
321 }
322 
323 
324 // ----------------------------------------------------------------------------
326 {
327 
329  if ( mTriggerList.size() == 0 ) return 1;
330 
331  StTriggerId nominal;
332 
334  StMuDstMaker *mumk = (StMuDstMaker*)GetMaker("MuDst");
335  StEvent *event = (StEvent*)GetInputDS("StEvent");
336 
337  if ( mumk )
338  {
339  nominal = mumk->muDst()->event()->triggerIdCollection().nominal();
340  goto CHECK_TRIGGER;
341  }
342 
344 
345  if ( event )
346  {
347  nominal=*event->triggerIdCollection()->nominal();
348  goto CHECK_TRIGGER;
349  }
350 
352  goto NO_DATA;
353 
354 
355  CHECK_TRIGGER:
356 
357  for ( UInt_t ii=0;ii<mTriggerList.size();ii++ )
358  {
359  if ( nominal.isTrigger( mTriggerList[ii] ) ) return mTriggerList[ii];
360  }
361  return 0;
362 
363  NO_DATA:
364  assert(2+2==5); // noooo data
365  return 0;
366 
367 }
368 
369 const
371 {
372 
373  static TString triggers="";
374 
375  StTriggerId nominal;
377  StMuDstMaker *mumk = (StMuDstMaker*)GetMaker("MuDst");
378  StEvent *event = (StEvent*)GetInputDS("StEvent");
379  if ( mumk )
380  {
381  nominal = mumk->muDst()->event()->triggerIdCollection().nominal();
382  goto CHECK_TRIGGER;
383  }
384 
386  if ( event )
387  {
388  nominal=*event->triggerIdCollection()->nominal();
389  goto CHECK_TRIGGER;
390  }
391 
393  goto NO_DATA;
394 
395 
396  CHECK_TRIGGER:
397 
398  triggers="";
399 
400  for ( UInt_t ii=0;ii<mTriggerList.size();ii++ )
401  {
402  if ( nominal.isTrigger( mTriggerList[ii] ) ) {
403  triggers+=mTriggerList[ii];
404  triggers+=" ";
405  }
406  }
407 
408  return triggers.Data();
409 
410  NO_DATA:
411  assert(2+2==5); // noooo data
412  return 0;
413 
414 }
void clear()
clears all storage arrays, deletes all canvases and histograms
TFile * setFile(TFile *file)
StEEmcSmdClusterVec_t & smdclusters(Int_t sec, Int_t plane)
Return a vector of smd clusters.
void cluster(const StEEmcSmdCluster &c, Int_t plane)
Add an smd cluster to this point.
Definition: StEEmcPoint.h:40
Base class for representing EEMC points.
Definition: StEEmcPoint.h:24
StMuDst * muDst()
Definition: StMuDstMaker.h:425
StEEmcTower & hittower(Int_t hit, Int_t layer)
StEEmcDisplay * mDisplay
StEEmcGenericPointMaker * mEEpoints
const Char_t * triggerList()
void Clear(Option_t *opts="")
User defined functions.
std::vector< Int_t > mTriggerList
StEEmcStrip & hitstrip(Int_t sec, Int_t pl, Int_t hit)
StEEmcPairVec_t pairs()
Return a copy of the list of diphoton candidates.
Int_t numberOfHitStrips(Int_t sector, Int_t plane) const
Int_t numberOfHitTowers(Int_t layer) const
StEEmcA2EMaker * mEEanalysis
StEEmcGenericClusterMaker * mEEclusters
StEEmcPi0Maker * mEEpairs
void add(StEEmcTower tower)
Add a tower to the display.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
Int_t key()
Return a unique key assigned by the cluster maker.
Definition: Stypes.h:40
virtual Int_t GetRunNumber() const
Returns the current RunNumber.
Definition: StMaker.cxx:1054
A base class for representing clusters of EEMC smd strips.
void points(StEEmcGenericPointMaker *p)
StEEmcPointVec_t & points()
Return vector of EEmc points.