StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHitFilterMaker.cxx
1 //*-- Author : James Dunlop
2 //
3 // $Id: StHitFilterMaker.cxx,v 1.7 2013/05/07 18:37:43 jeromel Exp $
4 // $Log: StHitFilterMaker.cxx,v $
5 // Revision 1.7 2013/05/07 18:37:43 jeromel
6 // Modified HitFilter takes a WestEta cut to keep hits in the FGT direction - requested Akio on behalf of the FGT effort
7 //
8 // Revision 1.6 2007/04/28 17:56:18 perev
9 // Redundant StChain.h removed
10 //
11 // Revision 1.5 2006/05/17 23:42:42 fisyak
12 // Use option KeepTpcHit and KeepSvtHit for StHitFilterMaker to keep corresponing hits regardless of track selection
13 //
14 // Revision 1.4 2004/09/02 19:13:44 fisyak
15 // Keep Tpc hits for tracks with Tof Pid Traits
16 //
17 // Revision 1.3 2004/04/08 19:28:55 caines
18 // Make Hitfilter take out those SVT hits not on tracks defined in the constructor - same as TPC filtering
19 //
20 // Revision 1.2 2003/07/30 15:27:00 caines
21 // Set options so you delete TPC and SVT hit if Zert >30. If ZVert<30cm save all good svt hits and TPC hits on tracks
22 //
23 // Revision 1.1 2003/02/07 02:16:15 jeromel
24 // First version of a generlized HitFilter/removal maker. Expeditious review
25 // done.
26 //
27 //
28 
29 
30 #include "StHitFilterMaker.h"
31 #include "StMessMgr.h"
32 
33 
34 #include "StEventTypes.h"
35 #include <algorithm>
36 #ifndef ST_NO_NAMESPACES
37 using std::binary_search;
38 using std::unique;
39 using std::sort;
40 
41 #endif
42 
43 
44 ClassImp(StHitFilterMaker)
45 
46 //_____________________________________________________________________________
48  StHitFilterMaker::StHitFilterMaker(const char *name, Double_t ptl, Double_t pth, Double_t eta, Double_t zvert, Double_t WestEta): StMaker(name),mPtLowerCut(ptl),mPtUpperCut(pth), mAbsEtaCut(eta), mAbsZVertCut(zvert), mKeepWestHighEtaHits(WestEta){
49  // This has defaults for the cuts in the include file
50 }
51 
54  //NOOP
55 }
56 
59 
60  // Output the cuts
61  gMessMgr->Info() << "StHitFilterMaker::Init(): keeping tracks between " <<
62  mPtLowerCut << " and " << mPtUpperCut << "GeV/c (negative = no cut)" << endm;
63  gMessMgr->Info() << "StHitFilterMaker::Init(): keeping tracks with |eta| < " <<
64  mAbsEtaCut << endm;
65  gMessMgr->Info() << "StHitFilterMaker::Init(): keeping tracks with |ZVert| < " <<
66  mAbsZVertCut << endm;
67  return StMaker::Init();
68 }
69 
70 
71 //_____________________________________________________________________________
78  // Get StEvent
79  //
80  StEvent* event;
81  event = (StEvent *) GetInputDS("StEvent");
82 
83 
84  if (!event) {
85  gMessMgr->Info() <<"StHitFilterMaker::Make(): not a valid StEvent: " << endm;
86 
87 
88  return kStOK;
89  }
90  // Fill up the ones to keep if ZVert in range
91  vector<StTrackNode*> keptTrackNodes;
92  if( accept(event)){
93  StSPtrVecTrackNode& nodes = event->trackNodes();
94  for (StSPtrVecTrackNodeIterator nodeIter = nodes.begin();
95  nodeIter != nodes.end(); ++nodeIter) {
96  bool isAcceptedTrack = false;
97 
98  for (UInt_t ientry=0;
99  ientry < (*nodeIter)->entries(); ++ientry) {
100  StTrack *track = (*nodeIter)->track(ientry);
101 
102  // Check that it's got tpc hits
103 
104  if (!(track->topologyMap().hasHitInDetector(kTpcId))) {
105  continue;
106  }
107 
108  if (accept(track)) {
109  isAcceptedTrack = true;
110  break;
111  }
112  }
113  if (isAcceptedTrack) {
114  keptTrackNodes.push_back(*nodeIter);
115  }
116  }
117  // Sort it and keep unique
118  sort(keptTrackNodes.begin(),keptTrackNodes.end());
119  vector<StTrackNode*>::iterator uniquePos =
120  unique(keptTrackNodes.begin(),keptTrackNodes.end());
121  keptTrackNodes.erase(uniquePos,keptTrackNodes.end());
122  }
123 
124  gMessMgr->Info() << "StHitFilterMaker::Make(): keeping TPC hits on " <<
125  keptTrackNodes.size() << " track nodes " << endm;
126  if (! TESTBIT(m_Mode, kTpcId))
127  this->removeTpcHitsNotOnTracks(event,keptTrackNodes);
128  if (! TESTBIT(m_Mode, kSvtId)) {
129  this->removeSvtHitsNotOnTracks(event,keptTrackNodes);
130  this->removeBadSvtHits(event);
131  }
132  return kStOK;
133 }
134 
135 bool StHitFilterMaker::accept(StEvent *event) {
136 
137  if( !(event->primaryVertex())) return false;
138  if( fabs(event->primaryVertex()->position().z()) > mAbsZVertCut) return false;
139  return true;
140 }
141 
142 bool StHitFilterMaker::accept(StTrack *track) {
143  if (track->flag() <= 0) return false;
144  StSPtrVecTrackPidTraits &traits = track->pidTraits();
145  unsigned int size = traits.size();
146  if (size) {
147  for (unsigned int i = 0; i < size; i++) {
148  if (! traits[i]) continue;
149  if ( traits[i]->IsZombie()) continue;
150  StTofPidTraits* p = dynamic_cast<StTofPidTraits*>(traits[i]);
151  if (p) {return true;}
152  }
153  }
154  if (track->geometry()) {
155  if (mPtLowerCut > 0 && track->geometry()->momentum().perp() < mPtLowerCut )
156  return false;
157  if (mPtUpperCut > 0 && track->geometry()->momentum().perp() > mPtUpperCut )
158  return false;
159  if (mAbsEtaCut > 0 && fabs(track->geometry()->momentum().pseudoRapidity()) > mAbsEtaCut)
160  return false;
161 
162  }
163 
164  return true;
165 }
166 
167 bool StHitFilterMaker::accept(StHit *hit) {
168  if( hit->flag() > 3) return false;
169  return true;
170 }
171 
172 
179  vector<StTrackNode*>& keptTrackNodes)
180 {
181  Int_t totalHits = 0;
182  Int_t removedHits1 = 0, removedHits2 = 0;
183  Int_t keep4fgt1=0, keep4fgt2=0;
184 
185  if (event && event->tpcHitCollection()) {
186  // first remove all hits not associated with a track at all
187  StTpcHitCollection *theHits = event->tpcHitCollection();
188  for (unsigned int n=0; n<theHits->numberOfSectors(); n++) {
189  for (unsigned int m=0; m<theHits->sector(n)->numberOfPadrows(); m++) {
190 
191  for (unsigned int h=0; h<theHits->sector(n)->padrow(m)->hits().size(); h++) {
192  totalHits++;
193  if (theHits->sector(n)->padrow(m)->hits()[h]->trackReferenceCount() == 0) {
194  if (! (theHits->sector(n)->padrow(m)->hits()[h]->isZombie())) {
195  if(mKeepWestHighEtaHits<=0.0 ||
196  checkHitTowardFgt(theHits->sector(n)->padrow(m)->hits()[h])==0 ){
197  theHits->sector(n)->padrow(m)->hits()[h]->makeZombie();
198  ++removedHits1;
199  }else{
200  keep4fgt1++;
201  }
202  }
203  }
204  }
205  }
206  }
207  gMessMgr->Info() << "StHitFilterMaker::removeTpcHitsNotOnTracks. Total "<<totalHits<<
208  ", Removed " << removedHits1 << " TPC hits not on any tracks" << endm;
209 
210  if(mKeepWestHighEtaHits>0.0) gMessMgr->Info() << " But keeping "<<keep4fgt1<<" hits for fgt"<<endm;
211 
212  // now all hits not associated
213  StSPtrVecTrackNode& nodes = event->trackNodes();
214  for (unsigned int i = 0; i < nodes.size(); i++) { // loop nodes
215  StTrackNode* node = nodes[i];
216  if (!binary_search(keptTrackNodes.begin(),
217  keptTrackNodes.end(),
218  node))
219  {
220 
221  for (unsigned int j = 0; j < node->entries(); j++) { // loop tracks in node
222  StTrack* track = node->track(j);
223  // Don't do anything if it doesn't have a TPC hit
224  if (!(track->topologyMap().hasHitInDetector(kTpcId))) {
225  continue;
226  }
227 
228  StTrackDetectorInfo* info = track->detectorInfo();
229  if (info) {
230  StPtrVecHit& hitList = info->hits();
231  for (unsigned int k = 0; k < hitList.size(); k++) // loop hits
232  if (hitList[k]->detector() == kTpcId &&
233  !(hitList[k]->isZombie()) ) {
234  if(mKeepWestHighEtaHits<=0.0 || checkHitTowardFgt(hitList[k])==0 ){
235  hitList[k]->makeZombie();
236  ++removedHits2;
237  }else{
238  keep4fgt2++;
239  }
240  }
241 
242  }
243  }
244  }
245  }
246  gMessMgr->Info() << "StHitFilterMaker::removeTpcHitsNotOnTracks. Removed " <<
247  removedHits2 << " TPC hits not on passed tracks" << endm;
248  if(mKeepWestHighEtaHits>0.0) gMessMgr->Info() << " But keeping "<<keep4fgt2<<" hits for fgt"<<endm;
249  gMessMgr->Info() << "StHitFilterMaker::removeTpcHitsNotOnTracks. Saving " <<
250  (totalHits - removedHits1 - removedHits2) << " after filter" << endm;
251 
252  return true;
253  }
254  else
255  return false;
256 }
257 
263  vector<StTrackNode*>& keptTrackNodes)
264 {
265  Int_t removedHits = 0;
266 
267  if (event && event->svtHitCollection()) {
268  // first remove all hits not associated with a track at all
269  StSvtHitCollection *theHits = event->svtHitCollection();
270  for (unsigned int l=0; l<theHits->numberOfBarrels(); l++) {
271  for (unsigned int m=0; m<theHits->barrel(l)->numberOfLadders(); m++) {
272  for (unsigned int n=0; n<theHits->barrel(l)->ladder(m)->numberOfWafers(); n++) {
273  for (unsigned int h=0; h<theHits->barrel(l)->ladder(m)->wafer(n)->hits().size(); h++) {
274 
275  if (theHits->barrel(l)->ladder(m)->wafer(n)->hits()[h]->trackReferenceCount() == 0) {
276  if (! (theHits->barrel(l)->ladder(m)->wafer(n)->hits()[h]->isZombie())) {
277  theHits->barrel(l)->ladder(m)->wafer(n)->hits()[h]->makeZombie();
278  ++removedHits;
279  }
280  }
281  }
282  }
283  }
284  }
285 
286  gMessMgr->Info() << "StHitFilterMaker::removedSvtHitsNotOnTracks. Removed " <<
287  removedHits << " SVT hits not on any tracks" << endm;
288  removedHits = 0;
289 
290  // now all hits not associated
291  StSPtrVecTrackNode& nodes = event->trackNodes();
292  for (unsigned int i = 0; i < nodes.size(); i++) { // loop nodes
293  StTrackNode* node = nodes[i];
294  if (!binary_search(keptTrackNodes.begin(),
295  keptTrackNodes.end(),
296  node))
297  {
298 
299  for (unsigned int j = 0; j < node->entries(); j++) { // loop tracks in node
300  StTrack* track = node->track(j);
301  // Don't do anything if it doesn't have a SVT hit
302  if (!(track->topologyMap().hasHitInDetector(kSvtId))) {
303  continue;
304  }
305 
306  StTrackDetectorInfo* info = track->detectorInfo();
307  if (info) {
308  StPtrVecHit& hitList = info->hits();
309  for (unsigned int k = 0; k < hitList.size(); k++) // loop hits
310  if (hitList[k]->detector() == kSvtId &&
311  !(hitList[k]->isZombie()) ) {
312  hitList[k]->makeZombie();
313  ++removedHits;
314  }
315 
316  }
317  }
318  }
319  }
320  gMessMgr->Info() << "StHitFilterMaker::removeSvtHitsNotOnTracks. Removed " <<
321  removedHits << " SVT hits not on passed tracks" << endm;
322 
323  return true;
324  }
325  else
326  return false;
327 }
328 
329 
336 {
337  Int_t removedHits = 0;
338 
339  if (event && event->svtHitCollection()) {
340  // first remove all hits with flag > 3
341  StSvtHitCollection *theHits = event->svtHitCollection();
342  for (unsigned int l=0; l<theHits->numberOfBarrels(); l++) {
343  for (unsigned int m=0; m<theHits->barrel(l)->numberOfLadders(); m++) {
344  for (unsigned int n=0; n<theHits->barrel(l)->ladder(m)->numberOfWafers(); n++) {
345  for (unsigned int h=0; h<theHits->barrel(l)->ladder(m)->wafer(n)->hits().size(); h++) {
346  if (! (accept(theHits->barrel(l)->ladder(m)->wafer(n)->hits()[h])) ||
347  !accept(event)) {
348  if (! (theHits->barrel(l)->ladder(m)->wafer(n)->hits()[h]->isZombie())) {
349  theHits->barrel(l)->ladder(m)->wafer(n)->hits()[h]->makeZombie();
350  ++removedHits;
351  }
352  }
353  }
354  }
355  }
356  }
357 
358  gMessMgr->Info() << "StHitFilterMaker::removeBadSvtHits. Removed " <<
359  removedHits << " bad SVT hits" << endm;
360  return true;
361  }
362  else
363  return false;
364 }
365 
366 
367 Int_t StHitFilterMaker::checkHitTowardFgt(StHit* hit){
368  if(hit->position().z() < 0) return 0;
369  if(hit->position().pseudoRapidity()>mKeepWestHighEtaHits) return 1;
370  return 0;
371 }
372 
Int_t m_Mode
counters
Definition: StMaker.h:81
virtual ~StHitFilterMaker()
Dummy destructor.
bool removeTpcHitsNotOnTracks(StEvent *, vector< StTrackNode * > &)
Definition: StHit.h:125
bool removeSvtHitsNotOnTracks(StEvent *, vector< StTrackNode * > &)
Definition: Stypes.h:40
virtual Int_t Init()
Init - is a first method the top level StChain calls to initialize all its makers.
virtual Int_t Make()
bool removeBadSvtHits(StEvent *)
Filters out TPC hits from StEvent on tracks that don&#39;t pass cuts. This is based on the StEventScaveng...