StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMuEvent.cxx
1 
2 /***************************************************************************
3  *
4  * $Id: StMuEvent.cxx,v 1.30 2019/02/21 13:32:54 jdb Exp $
5  * Author: Frank Laue, BNL, laue@bnl.gov
6  *
7  ***************************************************************************/
8 
9 #include <string.h>
10 #include "StEvent/StEvent.h"
11 #include "StEvent/StEventTypes.h"
12 #include "StEvent/StEventSummary.h"
13 #include "StEvent/StEventInfo.h"
14 #include "StEvent/StDetectorState.h"
15 #include "StEvent/StIstHitCollection.h"
16 #include "StEvent/StSsdHitCollection.h"
17 #include "StEvent/StPxlHitCollection.h"
18 #include "StEvent/StPxlSectorHitCollection.h"
19 #include "StEvent/StPxlLadderHitCollection.h"
20 
21 #include "StEventUtilities/StuRefMult.hh"
22 #include "StEventUtilities/StuFtpcRefMult.hh"
23 
24 #include "StarClassLibrary/SystemOfUnits.h"
25 #include "StarClassLibrary/StTimer.hh"
26 
27 #include "StMuException.hh"
28 #include "StMuEvent.h"
29 #include "StMuTrack.h"
30 #include "StMuL3EventSummary.h"
31 #include "StMuCut.h"
32 #include "StMuDebug.h"
33 #include "StMuDst.h"
34 #include "StMuPrimaryVertex.h"
35 #include "StMuBTofHit.h"
36 #include "StMuETofHit.h"
37 #include "StMuETofDigi.h"
38 
39 #include "TClonesArray.h"
40 #include "TObject.h"
41 #include "TClass.h"
42 
43 ClassImp(StMuEvent)
44 
45 //-----------------------------------------------------------------------
46 //-----------------------------------------------------------------------
47 //-----------------------------------------------------------------------
48  StMuEvent::StMuEvent() : mTriggerData(0), mPrimaryVertexError(-999.,-999.,-999) {
49  DEBUGMESSAGE("");
50  int n = (char*)mReactionPlanePtWgt - (char*)&mRefMultPos+sizeof(mReactionPlanePtWgt);
51  memset(&mRefMultPos,0,n);
52 }
53 //-----------------------------------------------------------------------
54 //-----------------------------------------------------------------------
55 //-----------------------------------------------------------------------
56 StMuEvent::StMuEvent(const StEvent* event) : mPrimaryVertexError(-999.,-999.,-999.) {
57  try {
58  fill(event);
59  }
60  catch (StMuException e) {
61  throw e;
62  }
63 }
64 //-----------------------------------------------------------------------
65 //-----------------------------------------------------------------------
66 //-----------------------------------------------------------------------
67 StMuEvent::~StMuEvent(){
68  DEBUGMESSAGE("");
69 }
70 //-----------------------------------------------------------------------
71 //-----------------------------------------------------------------------
72 //-----------------------------------------------------------------------
73 void StMuEvent::clear(){
74  DEBUGMESSAGE1("");
75 }
76 //-----------------------------------------------------------------------
77 //-----------------------------------------------------------------------
78 //-----------------------------------------------------------------------
79 void StMuEvent::fill(const StEvent* event){
80  DEBUGMESSAGE("");
81  if ( !event ) throw StMuExceptionNullPointer("no StEvent",__PRETTYF__);
82  if ( !event->info() ) throw StMuExceptionNullPointer("no event info",__PRETTYF__);
83  if ( !event->runInfo() ) throw StMuExceptionNullPointer("no run info",__PRETTYF__);
84  if ( !event->summary() ) throw StMuExceptionNullPointer("no event summary",__PRETTYF__);
85 // if (event->numberOfPrimaryVertices() != 1 ) throw StMuExceptionBadValue("!= 1 primary vertex");
86 
87 
89  mRunInfo = *event->runInfo();
90  mEventInfo = *event->info();
91  mEventSummary = *event->summary();
92  const StPrimaryVertex *p_vtx=event->primaryVertex();
93  if (p_vtx) {
94  mPrimaryVertexError=p_vtx->positionError();
95  }
96 
97  if ( !event->triggerDetectorCollection() ) {
98  DEBUGVALUE2(event->type());
99  DEBUGVALUE2(event->info()->time());
100  DEBUGMESSAGE2("no trigger detector collection, creating dummy");
101  }
102  else {
103  mVpdTriggerDetector = event->triggerDetectorCollection()->vpd();
104  mMtdTriggerDetector = event->triggerDetectorCollection()->mtd();
105  mCtbTriggerDetector = event->triggerDetectorCollection()->ctb();
106  mZdcTriggerDetector = event->triggerDetectorCollection()->zdc();
107  mBbcTriggerDetector = event->triggerDetectorCollection()->bbc();
108  mEmcTriggerDetector = event->triggerDetectorCollection()->emc();
109  mFpdTriggerDetector = event->triggerDetectorCollection()->fpd();
110  mFmsTriggerDetector = event->triggerDetectorCollection()->fms();
111  }
112 
113  if (event->fpdCollection())
114  mFpdCollection = *event->fpdCollection();
115  if (event->l0Trigger())
116  mL0Trigger = *event->l0Trigger();
117  mL3EventSummary.fill(event);
118 
119  mTriggerIdCollection.fill( event->triggerIdCollection() ); // pointer check done inside
120 
121 
122  mRefMultPos = uncorrectedNumberOfPositivePrimaries(*event);
123  mRefMultNeg = uncorrectedNumberOfNegativePrimaries(*event);
124  mRefMultFtpcEast = uncorrectedNumberOfFtpcEastPrimaries(*event);
125  mRefMultFtpcWest = uncorrectedNumberOfFtpcWestPrimaries(*event);
126 
127  if (event->triggerData()) // MC has no triggerData
128  mL2Result.Set(event->triggerData()->l2ResultLength(),(const Int_t*) event->triggerData()->l2Result());
129 
130  // calibrated vpd for TOF - X.Dong
131  mVpdEast = mVpdWest = 0;
132  mVpdTstart = mVpdTdiff = 0.;
133  if (event->tofCollection()) {
134  mVpdEast = event->tofCollection()->vpdEast();
135  mVpdWest = event->tofCollection()->vpdWest();
136  mVpdTstart = event->tofCollection()->tstart();
137  mVpdTdiff = event->tofCollection()->tdiff();
138  mVpdVz = event->tofCollection()->vzVpd();
139  }
140  // trigger data
141  mTriggerData = const_cast<StTriggerData*>(event->triggerData());
142  if(mTriggerData!=0) mTriggerData->setDebug(0);
143 
144  // HFT hits per layer - dongx
145  for(int i=0;i<4;i++) mNHitsHFT[i] = 0;
146  const StPxlHitCollection* PxlHitCollection = event->pxlHitCollection();
147  if(PxlHitCollection) {
148  UInt_t numberOfSectors=PxlHitCollection->numberOfSectors();
149  for(UInt_t i=0;i<numberOfSectors;i++){
150  const StPxlSectorHitCollection* PxlSectorHitCollection=PxlHitCollection->sector(i);
151  if(!PxlSectorHitCollection) continue;
152 
153  UInt_t numberOfLadders=PxlSectorHitCollection->numberOfLadders();
154  for(UInt_t j=0;j<numberOfLadders;j++){
155  const StPxlLadderHitCollection* PxlLadderHitCollection=PxlSectorHitCollection->ladder(j);
156  if(!PxlLadderHitCollection) continue;
157 
158  if(j==0) mNHitsHFT[0] += PxlLadderHitCollection->numberOfHits();
159  else mNHitsHFT[1] += PxlLadderHitCollection->numberOfHits();
160  }
161  }
162  } // PXL hits
163 
164  const StIstHitCollection *IstHitCollection = event->istHitCollection();
165  if(IstHitCollection) mNHitsHFT[2] += IstHitCollection->numberOfHits();
166 
167  const StSsdHitCollection *SsdHitCollection = event->ssdHitCollection();
168  if(SsdHitCollection) mNHitsHFT[3] += SsdHitCollection->numberOfHits();
169  //
170 
171 }
172 
173 unsigned short StMuEvent::refMultPos(int vtx_id) {
174  // Check old format (no StMuPrimaryVertex stored)
175  if (StMuDst::numberOfPrimaryVertices()==0 && (vtx_id == 0 || vtx_id == -1))
176  return mRefMultPos;
177  if (vtx_id == -1)
178  vtx_id = StMuDst::currentVertexIndex();
179  if (StMuDst::primaryVertex(vtx_id))
180  return StMuDst::primaryVertex(vtx_id)->refMultPos();
181  return 0;
182 }
183 
184 unsigned short StMuEvent::refMultNeg(int vtx_id) {
185  // Check old format (no StMuPrimaryVertex stored)
186  if (StMuDst::numberOfPrimaryVertices()==0 && (vtx_id == 0 || vtx_id == -1))
187  return mRefMultNeg;
188  if (vtx_id == -1)
189  vtx_id = StMuDst::currentVertexIndex();
190  if (StMuDst::primaryVertex(vtx_id))
191  return StMuDst::primaryVertex(vtx_id)->refMultNeg();
192  return 0;
193 }
194 
195 unsigned short StMuEvent::refMult(int vtx_id) {return refMultPos(vtx_id)+refMultNeg(vtx_id);}
196 
197 unsigned short StMuEvent::refMultFtpcEast(int vtx_id) {
198  // Check old format (no StMuPrimaryVertex stored)
199  if (StMuDst::numberOfPrimaryVertices()==0 && (vtx_id == 0 || vtx_id == -1))
200  return mRefMultFtpcEast;
201  if (vtx_id == -1)
202  vtx_id = StMuDst::currentVertexIndex();
203  if (StMuDst::primaryVertex(vtx_id))
204  return StMuDst::primaryVertex(vtx_id)->refMultFtpcEast();
205  return 0;
206 }
207 
208 unsigned short StMuEvent::refMultFtpcWest(int vtx_id) {
209  // Check old format (no StMuPrimaryVertex stored)
210  if (StMuDst::numberOfPrimaryVertices()==0 && (vtx_id == 0 || vtx_id == -1))
211  return mRefMultFtpcWest;
212  if (vtx_id == -1)
213  vtx_id = StMuDst::currentVertexIndex();
214  if (StMuDst::primaryVertex(vtx_id))
215  return StMuDst::primaryVertex(vtx_id)->refMultFtpcWest();
216  return 0;
217 }
218 
219 unsigned short StMuEvent::refMultFtpc(int vtx_id) {return refMultFtpcEast(vtx_id)+refMultFtpcWest(vtx_id);}
220 
222  StThreeVectorF vz(-999,-999,-999);
223  // Check old format (no StMuPrimaryVertex stored)
224  if (StMuDst::numberOfPrimaryVertices()==0 && (vtx_id == 0 || vtx_id == -1)){
225  if(fabs(mEventSummary.primaryVertexPosition().x()) < 1.e-5 && fabs(mEventSummary.primaryVertexPosition().y()) < 1.e-5 && fabs(mEventSummary.primaryVertexPosition().z()) < 1.e-5) return vz;
226  else return mEventSummary.primaryVertexPosition();
227  }
228  if (vtx_id == -1)
229  vtx_id = StMuDst::currentVertexIndex();
230  if (StMuDst::primaryVertex(vtx_id))
231  return StMuDst::primaryVertex(vtx_id)->position();
232  return vz;
233 }
234 StThreeVectorF StMuEvent::primaryVertexErrors(int vtx_id) const {
235  StThreeVectorF vz(-999,-999,-999);
236  // Check old format (no StMuPrimaryVertex stored)
237  if (StMuDst::numberOfPrimaryVertices()==0 && (vtx_id == 0 || vtx_id == -1)){
238  if(fabs(mEventSummary.primaryVertexPosition().x()) < 1.e-5 && fabs(mEventSummary.primaryVertexPosition().y()) < 1.e-5 && fabs(mEventSummary.primaryVertexPosition().z()) < 1.e-5) return vz;
239  else return mPrimaryVertexError;
240  }
241  if (vtx_id == -1)
242  vtx_id = StMuDst::currentVertexIndex();
243  if (StMuDst::primaryVertex(vtx_id))
244  return StMuDst::primaryVertex(vtx_id)->posError();
245  return vz;
246 }
247 
248 unsigned short StMuEvent::grefmult(int vtx_id){
249  unsigned short grefmult = 0;
250  StMuTrack *glob;
251  //For old MuDsts where there was one vertex per event
252  if (StMuDst::numberOfPrimaryVertices()==0 && (vtx_id == 0 || vtx_id == -1)){
253  if(!(fabs(mEventSummary.primaryVertexPosition().x()) < 1.e-5 && fabs(mEventSummary.primaryVertexPosition().y()) < 1.e-5 && fabs(mEventSummary.primaryVertexPosition().z()) < 1.e-5)){
254  for (int i=0;i<StMuDst::globalTracks()->GetEntriesFast();i++){
255  glob = StMuDst::globalTracks(i);
256  if (fabs(glob->eta()) < 0.5 && fabs(glob->dcaGlobal().mag()) < 3 && glob->nHitsFit(kTpcId) >= 10) grefmult++;
257  }
258  return grefmult;
259  }
260  else return 0;
261  }
262 
263  if (vtx_id == -1)
264  vtx_id = StMuDst::currentVertexIndex();
265 
266  if (StMuDst::primaryVertex(vtx_id)){
267  for (int i=0;i<StMuDst::globalTracks()->GetEntriesFast();i++){
268  glob = StMuDst::globalTracks(i);
269  if (fabs(glob->eta()) < 0.5 && fabs(glob->dcaGlobal(vtx_id).mag()) < 3 && glob->nHitsFit(kTpcId) >= 10) grefmult++;
270  }
271  return grefmult;
272  }
273  else return 0;
274 }
275 
276 unsigned short StMuEvent::btofTrayMultiplicity(){
277 
278  unsigned short btofmult = (unsigned short)StMuDst::numberOfBTofHit();
279  for(unsigned int i=0;i< StMuDst::numberOfBTofHit();i++) if(StMuDst::btofHit(i)->tray() > 120) btofmult--;
280  return btofmult;
281 
282 }
283 
284 unsigned short StMuEvent::etofHitMultiplicity(){
285  return (unsigned short) StMuDst::numberOfETofHit();
286 }
287 unsigned short StMuEvent::etofDigiMultiplicity(){
288  return (unsigned short) StMuDst::numberOfETofDigi();
289 }
290 
291 float StMuEvent::nearestVertexZ(int vtx_id){
292 
293  float dz = 999.0;
294  //For old MuDsts where there was one vertex per event
295  if (StMuDst::numberOfPrimaryVertices()==0) return dz;
296  const int Nvert = StMuDst::primaryVertices()->GetEntriesFast();
297  if(Nvert < 2) return dz;
298 
299  if (vtx_id == -1) vtx_id = StMuDst::currentVertexIndex();
300  float z = primaryVertexPosition(vtx_id).z();
301  for(int i=0;i<Nvert;i++){
302  if(vtx_id!=i) {
303  if(fabs(z-StMuDst::primaryVertex(i)->position().z()) < dz) dz = fabs(z-StMuDst::primaryVertex(i)->position().z());
304  }
305  }
306  return dz;
307 }
308 
309 /***************************************************************************
310  *
311  * $Log: StMuEvent.cxx,v $
312  * Revision 1.30 2019/02/21 13:32:54 jdb
313  * Inclusion of ETOF MuDst code. This code adds support for the full set of ETOF data which includes EtofDigi, EtofHit, EtofHeader. The code essentially copies similar structures from StEvent and additionally rebuilds the maps between Digis and Hits. Accessor methods are added based on the pattern from BTOF to provide access to data at various levels. The code for accessing the PID traits provided by ETOF is also provided
314  *
315  * Revision 1.29 2017/04/17 20:40:56 smirnovd
316  * StMuEvent: Declare getters const. They don't modify anything
317  *
318  * Revision 1.28 2015/03/06 20:02:01 jdb
319  * Added 4 unsigned shorts to StMuEvent at request of Xin Dong. Change StMuEvent.{h, cxx}
320  *
321  * Revision 1.27 2012/11/26 23:14:33 fisyak
322  * Replace GetEntries() by GetEntriesFast(), fix print outs
323  *
324  * Revision 1.26 2011/08/30 14:41:26 fisyak
325  * Keep DAQ time for the event untouched
326  *
327  * Revision 1.25 2010/05/29 16:36:52 tone421
328  * Added pointer protection to StTriggerData member
329  *
330  * Revision 1.24 2010/05/28 19:47:51 tone421
331  * Removed a cout needed for test purposes in StMuDstMaker. Made sure StTriggerData objects copied into the MuDst have a debug value of 0..
332  *
333  * Revision 1.23 2010/05/26 04:25:50 tone421
334  * Added StTriggerData arrays in muevent and fixed an issue with PMD arrays being read....
335  *
336  * Revision 1.22 2010/02/03 17:16:22 tone421
337  * Added function StMuEvent::nearestVertexZ(int vtx_id) which returns the z distance of the nearest vertex in relation to vertex vtx_id
338  *
339  * Revision 1.21 2010/02/03 04:54:45 tone421
340  * Added StMuEvent::btofTrayMultiplicity() to return only TOF hits from trays. Should be looked at instead of ctbSum for run 9 and beyond.
341  *
342  * Revision 1.20 2009/01/09 19:43:47 tone421
343  * OAdded gremult in StMuEvent (globals tracks with DCA < 3cm, >= 10 TPC fit hits and |eta| < 0.5)
344  *
345  * Revision 1.19 2008/11/18 15:34:32 tone421
346  * 2 changes. The first ensures StMuEvent::primaryVertexPosition() returns the position of current vertex (set by StMuDst::setVertexIndex(Int_t vtx_id)): previously it returned the position of best ranked vertex. The second insures events with no vertex have a PVx=PYy=PYz=-999 rather than 0.
347  *
348  * Revision 1.18 2008/06/26 15:46:13 tone421
349  *
350  * Add getter and setter for the vpd z vertex position
351  *
352  * Revision 1.17 2008/02/20 09:00:48 mvl
353  * Included FMS data (StFMSTriggerDetector) (code by Akio)
354  *
355  * Revision 1.16 2007/09/21 02:27:12 mvl
356  * Added calibrated VPD info from StTofCollection (run-8 prep)
357  *
358  * Revision 1.15 2007/09/05 23:21:21 mvl
359  * Added StMtdTriggerDetector
360  *
361  * Revision 1.14 2007/04/20 06:25:21 mvl
362  * Removed Q-vectors (will implement utility class).
363  * Added Vpd info.
364  *
365  * Revision 1.12 2006/09/20 17:23:39 mvl
366  * Added protected for events with StTriggerData (e.g. simulation)
367  *
368  * Revision 1.11 2006/09/20 01:50:35 mvl
369  * Added data member and code for L2Result array (TArrayI).
370  *
371  * Revision 1.10 2005/08/19 19:46:05 mvl
372  * Further updates for multiple vertices. The main changes are:
373  * 1) StMudst::primaryTracks() now returns a list (TObjArray*) of tracks
374  * belonging to the 'current' primary vertex. The index number of the
375  * 'current' vertex can be set using StMuDst::setCurrentVertex().
376  * This also affects StMuDst::primaryTracks(int i) and
377  * StMuDst::numberOfprimaryTracks().
378  * 2) refMult is now stored for all vertices, in StMuPrimaryVertex. The
379  * obvious way to access these numbers is from the StMuprimaryVertex structures,
380  * but for ebakcward compatibility a function is provided in StMuEvent as well
381  * (this is the only function taht works for existing MuDst)
382  *
383  * As an aside, I've also changes the internals of StMuDst::createStEvent and
384  * StMuDst::fixTrackIndices() to be able to deal with a larger range of index numbers for tracks as generated by Ittf.
385  *
386  * BIG FAT WARNING: StMudst2StEventMaker and StMuDstFilterMaker
387  * do not fully support the multiple vertex functionality yet.
388  *
389  * Revision 1.9 2004/12/02 00:19:52 mvl
390  * Added error on primary vertex
391  *
392  * Revision 1.8 2004/08/04 17:57:13 mvl
393  * Added EMC trigger information and fpd trigger (tower) information
394  *
395  * Revision 1.7 2004/02/17 04:56:36 jeromel
396  * Extended help, added crs support, restored __GNUC__ for PRETTY_FUNCTION(checked once
397  * more and yes, it is ONLY defined in GCC and so is __FUCTION__), use of a consistent
398  * internal __PRETTYF__, return NULL if no case selected (+message) and protected against
399  * NULL mChain.
400  *
401  * Revision 1.6 2003/10/20 19:50:13 perev
402  * workaround added for TClonesArray::Delete + some cleanup of MuEmc
403  *
404  * Revision 1.5 2003/07/22 19:14:41 laue
405  * multiplicities for FTPC added
406  *
407  * Revision 1.4 2003/02/20 15:29:42 laue
408  * StMuTriggerIdCollection added
409  *
410  * Revision 1.3 2003/02/19 13:51:58 laue
411  * added the StTriggerIdCollection
412  *
413  * Revision 1.2 2002/08/27 19:05:57 laue
414  * Minor updates to make the muDst from simulation work
415  *
416  * Revision 1.1 2002/03/08 17:04:17 laue
417  * initial revision
418  *
419  *
420  **************************************************************************/
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Definition: StMuDst.h:322
static StMuBTofHit * btofHit(int i)
returns pointer to the i-th muBTofHit
Definition: StMuDst.h:419
static TObjArray * globalTracks()
returns pointer to the global tracks list
Definition: StMuDst.h:303
StThreeVectorF primaryVertexPosition(int vtx_id=-1) const
The StMuDst is supposed to be structured in &#39;physical events&#39;. Therefore there is only 1 primary vert...
Definition: StMuEvent.cxx:221
unsigned short refMultNeg(int vtx_id=-1)
Reference multiplicity of negative particles as defined in StEventUtilities/StuRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:184
void fill(const StEvent *)
Definition: StMuEvent.cxx:79
unsigned short refMultFtpcWest(int vtx_id=-1)
Reference multiplicity of particles in the west FTPC as defined in StEventUtilities/StuFtpcRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:208
static TClonesArray * primaryVertices()
returns pointer to the primary vertex list
Definition: StMuDst.h:299
UShort_t nHitsFit() const
Return total number of hits used in fit.
Definition: StMuTrack.h:239
unsigned short refMultFtpc(int vtx_id=-1)
Reference multiplicity of particles in the east+west FTPC as defined in StEventUtilities/StuFtpcRefMu...
Definition: StMuEvent.cxx:219
Double_t eta() const
Returns pseudo rapidity at point of dca to primary vertex.
Definition: StMuTrack.h:257
unsigned short refMult(int vtx_id=-1)
Reference multiplicity of charged particles as defined in StEventUtilities/StuRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:195
static Int_t currentVertexIndex()
Get the index number of the current primary vertex.
Definition: StMuDst.h:260
StThreeVectorF dcaGlobal(Int_t vtx_id=-1) const
Returns 3D distance of closest approach to primary vertex of associated global track.
Definition: StMuTrack.cxx:371
unsigned short refMultPos(int vtx_id=-1)
Reference multiplicity of positive particles as defined in StEventUtilities/StuRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:173
unsigned short refMultFtpcEast(int vtx_id=-1)
Reference multiplicity of particles in the east FTPC as defined in StEventUtilities/StuFtpcRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:197