StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBTofMixerMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StBTofMixerMaker.cxx,v 1.3 2018/06/21 03:38:46 jdb Exp $
4  *
5  * Author: Nickolas Luttrell (Rice University), November 2016
6  ***************************************************************************
7  *
8  * Description: StBTofMixerMaker.cpp - This maker accepts the BTof Collection
9  * and checks for duplicate hits (hits in the same cell of the BTof). Upon
10  * finding a duplicate, it takes the hit with the lowest time of flight. The
11  * original BTof collection is replaced with the new, clean collection. This
12  * can be used for embedding, as both simulation and data hits are parsed.
13  *
14  ***************************************************************************
15  *
16  * $Log: StBTofMixerMaker.cxx,v $
17  * Revision 1.3 2018/06/21 03:38:46 jdb
18  * Fixed the MixerMakers technique for updating the BTofCollection-previously was not storing MC hits in some embedding cases
19  *
20  * Revision 1.2 2017/10/20 17:50:33 smirnovd
21  * Squashed commit of the following:
22  *
23  * StBTof: Remove outdated ClassImp macro
24  *
25  * Prefer explicit namespace for std:: names in header files
26  *
27  * Removed unnecessary specification of default std::allocator
28  *
29  * Frank signed-off
30  *
31  * Revision 1.1 2017/03/02 18:40:57 jeromel
32  * First version of BTofMixer jdb / nl
33  *
34  *
35  ***************************************************************************/
36 
37 #include <Stiostream.h>
38 #include "StBTofMixerMaker.h"
39 #include "StEventTypes.h"
40 #include "StEvent/StBTofCollection.h"
41 
42 #include "StBTofSimMaker/StBTofSimMaker.h"
43 
44 
45 //_____________________________________________________________________________
47 {
49  mEvent = 0;
50  mEventCollection = 0;
52  mNewCollection = 0;
53 }
54 
56 {
58 }
59 
60 //_____________________________________________________________________________
61 int StBTofMixerMaker::Init()
62 {
63 
64  return StMaker::Init();
65 }
66 
67 
68 //_____________________________________________________________________________
69 int StBTofMixerMaker::InitRun(int runnumber)
70 {
71  return kStOK;
72 }
73 
74 //_____________________________________________________________________________
75 int StBTofMixerMaker::FinishRun(int runnumber)
76 {
77  return kStOk;
78 }
79 
80 
81 //_____________________________________________________________________________
83 {
84  return kStOK;
85 }
86 
87 //_____________________________________________________________________________
89 {
90  int keyId = 0;
91 
92  mEvent = (StEvent*)GetInputDS("StEvent");
93  if (!mEvent) {
94  LOG_ERROR << "No StEvent! Bailing out ..." << endm;
95  }
96 
97  StBTofSimMaker *btofSim = (StBTofSimMaker *)GetMaker("TofSim");
98 
99  if (btofSim) {
100  mBTofSimCollection = btofSim->GetBTofCollection();
101  mIsEmbedding = btofSim->getEmbeddingMode();
102  }
103 
104  if (!mIsEmbedding) {
105  LOG_WARN << "Embedding flag is false! StBTofMixerMaker should only be run if the embedding mode is active in StBTofSimMaker!" << endm;
106  return kStOK;
107  }
108 
109  mEventCollection = mEvent->btofCollection();
110  if(!mEventCollection) {
111  LOG_ERROR << "No BTofCollection! Bailing out ..." << endm;
112  return kStFatal;
113  }
114  LOG_DEBUG << "The original size of the collection was " << mEventCollection->tofHits().size() << endm;
115  LOG_DEBUG << "There are " << mBTofSimCollection->tofHits().size() << " hits in the BTofSimMakers Collection" << endm;
116 
117  std::vector<StBTofHit*> sortedEventHitsVec(23447,0);
118 
120  for (int j=0; j < (int)mEventCollection->tofHits().size(); j++) {
121  keyId = mEventCollection->tofHits()[j]->ID()*mEventCollection->tofHits()[j]->kNCell + mEventCollection->tofHits()[j]->cell()-1;
122  sortedEventHitsVec[keyId] = mEventCollection->tofHits()[j];
123  }
124 
125  findDuplicates(sortedEventHitsVec, mBTofSimCollection);
127  LOG_DEBUG << "size of sortedEventHitsVec=" << sortedEventHitsVec.size() << endm;
128  for (int k=0; k < (int)sortedEventHitsVec.size(); k++) {
129  if (sortedEventHitsVec[k]) {
130  StBTofHit aBTofHit = *sortedEventHitsVec[k];
131  mNewCollection->addHit(new StBTofHit(aBTofHit));
132  }
133  }
134 
135  // mEventCollection = mNewCollection; //! Link StEvent to the new mixer collection.
136  mNewCollection->setHeader( new StBTofHeader( *(mEventCollection->tofHeader()) ) );
137  LOG_DEBUG << "mEventCollection=" << mEventCollection << endm;
138  LOG_DEBUG << "mEvent->btofCollection()=" << mEvent->btofCollection() << endm;
139  mEvent->setBTofCollection( mNewCollection );
140  LOG_DEBUG << "mEvent->btofCollection()=" << mEvent->btofCollection() << endm;
141 
143  LOG_DEBUG << "... Modified StBTofCollection Stored in StEvent! " << endm;
144 
145  LOG_DEBUG << "The size of the collection is now " << mEvent->btofCollection()->tofHits().size() << endm;
146 
147  return kStOK;
148 }
149 
150 
151 //_____________________________________________________________________________
152 // Takes BTofCollections from StEvent and one of the SimMakers, finds duplicate hits and chooses earlier time.
153 // This function performs the task of embedding
154 void StBTofMixerMaker::findDuplicates (std::vector<StBTofHit*> &eventHits, StBTofCollection *simHits) {
155  for (int i=0; i<(int)simHits->tofHits().size(); i++) {
156  if (simHits->tofHits()[i]) {
157  int simKeyId = simHits->tofHits()[i]->ID()*simHits->tofHits()[i]->kNCell + simHits->tofHits()[i]->cell()-1;
158  if (eventHits[simKeyId] != 0) {
159  // perform check to see which Leading edge time occurs sooner
160  if ( eventHits[i]->leadingEdgeTime() > simHits->tofHits()[i]->leadingEdgeTime() ) {
161  eventHits[simKeyId] = simHits->tofHits()[i]; // Replace slow hit with faster (simulation) hit
162  }
163  }
164  else {
165  eventHits[simKeyId] = simHits->tofHits()[i]; // Embed simulation hit
166  }
167  }
168  }
169 }
170 
171 
172 // End StBTofMixerMaker.cpp
virtual ~StBTofMixerMaker()
bool mIsEmbedding
Embedding flag.
virtual int Finish()
StBTofMixerMaker(const char *name="Simulation")
StBTofCollection * mEventCollection
BtofCollection from StEvent.
void findDuplicates(std::vector< StBTofHit * > &eventHits, StBTofCollection *simHits)
Find duplicate hits between the BTofCollections.
Definition: Stypes.h:40
StEvent * mEvent
The StEvent info from previous Makers.
virtual int Make()
StBTofCollection * mBTofSimCollection
BTofCollection produced by BTofSimMaker.
StBTofCollection * mNewCollection
BTofCollection to be assembled by embedding.
Definition: Stypes.h:41