StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StCustomFilter.cxx
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "StCustomFilter.h"
4 
5 #include "StEvent.h"
6 #include "StHit.h"
7 #include "StTrack.h"
8 #include "StVertex.h"
9 #include "StTrackGeometry.h"
10 #include "StTrackDetectorInfo.h"
11 // For L3 filter
12 #include "StarClassLibrary/BetheBloch.h"
13 #include "StEvent/StDedxPidTraits.h"
14 
15 
16 //______________________________________________________________________________
17 ClassImp(StCustomFilter)
18 StCustomFilter::StCustomFilter(const char *name,bool active):StFilterABC(name,active)
19 {
20  // Assing a custom data-member
21  mBB = new BetheBloch();
22  // Set the default values for the parameters.
23  // Don't change this line !!!
24  SetDefs();
25 
26 }
27 //______________________________________________________________________________
28 StCustomFilter::~StCustomFilter()
29 { // delete the custom data-member
30  delete mBB;
31 }
32 //______________________________________________________________________________
33 const char **StCustomFilter::GetNams() const
34 {
35  // Create a "Label" list to be used with the dialog box
36  static const char *nams[] = {
37  " pCutHigh ",
38  " nHitsCutHighP ",
39  " pCutLow ",
40  " nHitsCutLowP ",
41  " chargeForLowP ",
42  " dEdxMassCutHigh ",
43  " dEdxFractionCutHigh ",
44  " dEdxMassCutLow ",
45  " dEdxFractionCutLow ",
46  0
47  };
48  return nams;
49 }
50 //______________________________________________________________________________
51 const float *StCustomFilter::GetDefs() const
52 {
53  // Create a list of the "default values"
54  // The order of the default values must match the "label" list (see: StCustomFilter::GetNams)
55  static const float defs[] = {
56  /* pCutHigh */ 2.0, // high momentum cut for RICH/Upsilon candidates
57  /* nHitsCutHighP */ 10, // nHits cut for all tracks
58  /* pCutLow */ 0.2, // low momentum cut
59  /* nHitsCutLowP */ 15,
60  /* chargeForLowP */ -1, // charge for tracks with pCutLow < p < pCutHigh, set to 0 for all tracks
61  /* dEdxMassCutHigh */ 0.939, // cut below BetheBloch(p/dEdxMassCutHigh), e.g. proton-band
62  /* dEdxFractionCutHigh */ 0.6, // cut fraction of dEdx-band, i.e. dEdxFractionCut * BetheBloch(p/dEdxMassCut)
63  /* dEdxMassCutLow */ 0.494, // cut above BetheBloch(p/dEdxMassCutLow), e.g. kaon-band
64  /* dEdxFractionCutLow */ 1.1,
65  //-------------------------------------------------------------------------------------------
66  0 // the last valuse MUST be zero and it MUST be present
67  //-------------------------------------------------------------------------------------------
68  };
69  return defs;
70 }
71 
72 //______________________________________________________________________________
73 Int_t StCustomFilter::Accept(StPoints3DABC *pnt, Color_t&color, Size_t&size, Style_t&style)
74 {
75  // ---
76  // "Accept" method is called by the StEventDisplayMaker event loop
77  // once for each component of the StEvent.
78  //
79  // To see all possible combinations check:
80  // StRoot/StEventUtilities/StEventHelper.cxx:StFilterDef::Accept()
81  // method
82  //
83  // Input: pnt - the interface to the object 3D coordinate
84  // color - the default color
85  // size - the default size (it if the line width for trach and the dot diameter for the hits)
86  // style - the default style (it is the line style or ROOT marker style)
87  //
88  // Output color - the custom color if any
89  // size - the custom size if any
90  // style - the custom style if any
91  //
92  // return : 0 the object is rejected and it will not be drawn
93  // +n the object is accepted and will be passed to next filter if any
94  // optionally you may change the object visual attribute
95  // like color, style and size
96  // If you have no intention to change the default values
97  // you may simply ignore the parameters.
98  // The attributes set by the filter do overwrite what other filter may have set
99  //
100  // If the object has passed the last filter in row it will be drawn.
101  // ---
102  TObject *to;
103  StTrack *trk;
104  to = pnt->GetObject();
105  if (!to) return 1;
106  // We want to provide our own custom cut for the StTrack object only.
107  if (!to->InheritsFrom(StTrack::Class())) return 1;
108 
109  // The track component of StEvent was found let's apply our custom cut.
110  trk = (StTrack*)to;
111  return Accept(trk,color,size,style);
112 }
113 //______________________________________________________________________________
114 Int_t StCustomFilter::Accept(const StTrack* track,Color_t&color, Size_t&size, Style_t&style)
115 {
116  //
117  // User provided the selection and cutom visual attribute fot the track
118  // It is assumed this function needs the value assigned through interactive dialog
119  //
120  // If you don't want to change the default visual attribute you may simply ignore the input parameters
121  // This concrete cut implementation was borrowed from StRoot/StMuDSTMaker/COMMON/StMStMuL3Filter
122  //-----
123 
124 
125 
126  //-----
127  // Note: The statements below make a copy of the object data-mambers to the local variables
128  //-----
129  // There is no need to assign the local variable.
130  // We do that to highlight the difference between the original "StMStMuL3Filter"
131  //-----
132 
133  float pCutHigh = fpCutHigh; // high momentum cut for RICH/Upsilon candidates
134  int nHitsCutHighP = int(fnHitsCutHighP); // nHits cut for all tracks
135 
136  // following cuts apply only for tracks with pCutLow < p <pHigh
137  float pCutLow = fpCutLow; // low momentum cut
138  int nHitsCutLowP = int(fnHitsCutLowP);
139  int chargeForLowP = int(fchargeForLowP); // charge for tracks with pCutLow < p < fpCutHigh, set to 0 for all tracks
140  float dEdxMassCutHigh = fdEdxMassCutHigh; // cut below BetheBloch(p/dEdxMassCutHigh), e.g. proton-band
141  float dEdxFractionCutHigh = fdEdxFractionCutHigh;// cut fraction of dEdx-band, i.e. dEdxFractionCut * BetheBloch(p/dEdxMassCut)
142  float dEdxMassCutLow = fdEdxMassCutLow; // cut above BetheBloch(p/dEdxMassCutLow), e.g. kaon-band
143  float dEdxFractionCutLow = fdEdxFractionCutLow;
144  // -- The copy of the all data-members have been made
145 
146  int iret = 0;
147  int chargeOK = 0;
148  int dedxOK = 0;
149 
150  float magnitude = track->geometry()->momentum().magnitude();
151  int nPoints = track->detectorInfo()->numberOfPoints();
152 
153  if ( magnitude > pCutHigh && nPoints >= nHitsCutHighP) iret = 1;
154  else {
155  if ( magnitude > pCutLow && nPoints >= nHitsCutLowP )
156  {
157  // check charge
158  if (chargeForLowP==0)
159  chargeOK = 1;
160  else if (track->geometry()->charge() == chargeForLowP)
161  chargeOK = 1;
162 
163  // check dEdx
164  // if (mBB==0) mBB = new BetheBloch();
165  float dedxHigh = dEdxFractionCutHigh * mBB->Sirrf(magnitude/dEdxMassCutHigh);
166  float dedxLow = dEdxFractionCutLow * mBB->Sirrf(magnitude/dEdxMassCutLow);
167  float dedx = 0;
168 
169  // get track dEdx
170  const StSPtrVecTrackPidTraits& traits = track->pidTraits();
171  StDedxPidTraits* dedxPidTr;
172  for (unsigned int itrait = 0; itrait < traits.size(); itrait++){
173  dedxPidTr = 0;
174  if (traits[itrait]->detector() == kTpcId) {
175  StTrackPidTraits* thisTrait = traits[itrait];
176  dedxPidTr = dynamic_cast<StDedxPidTraits*>(thisTrait);
177  if (dedxPidTr && dedxPidTr->method() == kTruncatedMeanId) {
178  // adjust L3 dE/dx by a factor of 2 to match offline
179  dedx = 2 * dedxPidTr->mean();
180  }
181  }
182  }
183  if (dedx > dedxHigh && dedx > dedxLow)
184  dedxOK = 1;
185  // final answer
186  iret = chargeOK * dedxOK;
187  } // if (pCutLow && nHitsCutLowP)
188  }
189  return iret;
190 }