StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMuETofCollection.cxx
1 /***************************************************************************
2  *
3  * $Id: StMuETofCollection.cxx,v 1.1 2019/02/21 13:32:54 jdb Exp $
4  *
5  * Author: Florian Seck, October 2018
6  ***************************************************************************
7  *
8  * Description: Data collection for storing eTOF information (header, digis,
9  * hits) in the muDsts
10  *
11  ***************************************************************************
12  *
13  * $Log: StMuETofCollection.cxx,v $
14  * Revision 1.1 2019/02/21 13:32:54 jdb
15  * 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
16  *
17  *
18  ***************************************************************************/
19 #include <map>
20 
21 #include "StMuETofCollection.h"
22 #include "StMuETofHeader.h"
23 #include "StMuETofDigi.h"
24 #include "StMuETofHit.h"
25 
26 #include "StETofCollection.h"
27 #include "StETofHeader.h"
28 #include "StETofDigi.h"
29 #include "StETofHit.h"
30 
31 #include "StMessMgr.h"
32 
33 
34 StMuETofCollection::StMuETofCollection()
35 {
36 
37 }
38 
39 
40 StMuETofCollection::~StMuETofCollection()
41 {
42  /* no op */
43 }
44 
45 StMuETofCollection::StMuETofCollection( const StETofCollection* etofColl )
46 {
47  // fill header
48  if( etofColl->etofHeader() ) {
49  mETofHeader.push_back( etofColl->etofHeader() );
50  }
51  else {
52  mETofHeader.push_back( StMuETofHeader() );
53  }
54 
55  // store hits for better searchability
56  //--> key: detector index, value: vector of hits indices in mETofHit vector
57  std::map< int, vector< unsigned int > > mapStoreHit;
58 
59  LOG_DEBUG << "StMuETofCollection ctor -- filling hits into storage" << endm;
60 
61  //fill hits --> needed for assigning associatedHitId to digis
62  if( etofColl->hitsPresent() ) {
63  const StSPtrVecETofHit& vecHit = etofColl->etofHits();
64 
65  for( size_t i=0; i<vecHit.size(); i++ ){
66  StETofHit* pHit = ( StETofHit* ) vecHit.at( i );
67 
68  if( !pHit ) continue;
69 
70  mETofHits.push_back( StMuETofHit( pHit ) );
71 
72  int detIndex = pHit->sector() * 100 + pHit->zPlane() * 10 + pHit->counter();
73 
74  mapStoreHit[ detIndex ].push_back( i );
75  }
76  }
77 
78  /*
79  LOG_DEBUG << "StMuETofCollection ctor -- hit map created" << endm;
80  for( auto kv: mapStoreHit ) {
81  LOG_DEBUG << "detIndex :" << kv.first << " -- hit index: ";
82  for( auto v : kv.second ) {
83  LOG_DEBUG << v << " ";
84  }
85  LOG_DEBUG << endm;
86  }
87  */
88 
89  //fill digis
90  if( etofColl->digisPresent() ) {
91  const StSPtrVecETofDigi& vecDigi = etofColl->etofDigis();
92 
93  for( size_t i=0; i<vecDigi.size(); i++ ) {
94  StETofDigi* pDigi = ( StETofDigi* ) vecDigi.at( i );
95 
96  if( !pDigi ) continue;
97 
98  int assocHitId = -1;
99 
100  if( pDigi->associatedHit() != nullptr ) {
101  int detIndex = pDigi->sector() * 100 + pDigi->zPlane() * 10 + pDigi->counter();
102 
103  double assocLocalX = pDigi->associatedHit()->localX();
104  double assocLocalY = pDigi->associatedHit()->localY();
105  double assocTime = pDigi->associatedHit()->time();
106 
107  if( mapStoreHit.count( detIndex ) ) {
108  for( auto v : mapStoreHit.at( detIndex ) ) {
109  if( fabs( mETofHits.at( v ).localX() - assocLocalX ) > 0.0001 ) continue;
110  if( fabs( mETofHits.at( v ).localY() - assocLocalY ) > 0.0001 ) continue;
111  if( fabs( mETofHits.at( v ).time() - assocTime ) > 0.0001 ) continue;
112 
113  assocHitId = v;
114  break;
115  }
116  }
117  mETofDigis.push_back( StMuETofDigi( pDigi, assocHitId ) );
118  LOG_DEBUG << "StMuETofCollection ctor -- added digi with associatedHitId = " << assocHitId << endm;
119  }
120  else {
121  mETofDigis.push_back( StMuETofDigi( pDigi ) );
122  LOG_DEBUG << "StMuETofCollection ctor -- added digi with associatedHitId = -1" << endm;
123  }
124 
125  }
126  }
127 
128 }
129 
130 
131 const StMuETofHeader*
132 StMuETofCollection::etofHeader() const {
133  return &mETofHeader.at( 0 );
134 }
135 
137 StMuETofCollection::etofHeader() {
138  return &mETofHeader.at( 0 );
139 }
140 
141 
143 StMuETofCollection::etofDigi( int i ) {
144  return &mETofDigis.at( i );
145 }
146 
147 
149 StMuETofCollection::etofHit( int i ) {
150  return &mETofHits.at( i );
151 }
152 
153 
154 int
155 StMuETofCollection::digisPresent() {
156  return mETofDigis.size();
157 }
158 
159 int
160 StMuETofCollection::hitsPresent() {
161  return mETofHits.size();
162 }
StETofHit * associatedHit()
pointer to the hit which has been reconstructed from this digi
Definition: StETofDigi.h:222
unsigned int zPlane() const
ZPlane.
Definition: StETofDigi.h:213
double time() const
Time.
Definition: StETofHit.h:193
unsigned int sector() const
Sector.
Definition: StETofDigi.h:212
unsigned int counter() const
Counter.
Definition: StETofHit.h:191
unsigned int zPlane() const
ZPlane.
Definition: StETofHit.h:190
double localX() const
X-position.
Definition: StETofHit.h:198
double localY() const
Y-position.
Definition: StETofHit.h:199
unsigned int sector() const
Sector.
Definition: StETofHit.h:189
unsigned int counter() const
Counter.
Definition: StETofDigi.h:214