StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEStructCuts.h
1 /**********************************************************************
2  *
3  * $Id: StEStructCuts.h,v 1.9 2012/11/16 21:19:06 prindle Exp $
4  *
5  * Author: Jeff Porter
6  *
7  **********************************************************************
8  *
9  * Description: Abstract class for cuts. It does implement reading
10  * of a cut file and building histograms. Specific
11  * cuts are done in derived classes
12  *
13  ***********************************************************************/
14 #ifndef __STEBYECUTS__H
15 #define __STEBYECUTS__H
16 
17 
18 // -> for rootcint preprocessing
19 #include "TROOT.h"
20 
21 class TH1;
22 class TFile;
23 
24 // local name-id mapping
25 class CutName {
26 
27  public:
28  CutName(): idx(99){};
29  int idx;
30  char name[32];
31 };
32 
33 
35 
36 protected:
37 
38  char* mcutFileName;
39 
40  int mMaxStore;
41  char** mvarName;
42  float* mvalues;
43  float* mminVal;
44  float* mmaxVal;
45  int mnumVars;
46  TH1** mvarHistsNoCut;
47  TH1** mvarHistsCut;
48  bool mDoFillHists; // If true we fill histograms. If false skip filling.
49 
50  char mcutTypeName[64];
51 
52  void resize();
53  void initVars();
54  void deleteVars();
55 
56 public:
57 
58  StEStructCuts(const char* cutFileName);
59  StEStructCuts();
60  virtual ~StEStructCuts();
61 
62  virtual void setCutFile(const char* cutFileName);
63  virtual bool isLoaded();
64 
65  virtual bool loadCuts();
66  virtual void dataValue(const char* name, float value);
67 
68  virtual int createCutHists(const char* name, float* range, int nvals=2);
69  virtual int createCutHists(const char* name, double* range, int nvals=2);
70  virtual int createCutHists(const char* name, int* range, int nvals=2);
71  virtual int createCutHists(const char* name, unsigned int* range, int nvals=2);
72  virtual void addCutHists(TH1* before, TH1* after, const char* name=NULL);
73  virtual void setDoFillHists(bool filling);
74  virtual bool doFillHists();
75 
76 
77  virtual void fillHistogram(const char* name, float value, bool passed);
78  virtual void fillHistogram(const char* name, float val1, float val2, bool passed);
79  virtual void fillHistogram(const char* name, float val1, float val2, float val3, bool passed);
80  virtual void fillHistograms(bool passed);
81  virtual void writeCutHists(TFile* tf);
82  virtual bool loadBaseCuts(const char* name,const char** vals,int nvals)=0;
83  bool loadBaseCuts(const char* name,const char* val1,const char* val2,const char* val3="",const char* val4=""); // overloaded to accept strings
84  virtual void loadUserCuts(const char* name,const char** vals,int nvals)=0;
85  void loadUserCuts(const char* name,const char* val1,const char* val2); // overloaded to accept strings
86  virtual void printCuts(std::ostream& of, int i=-1);
87  virtual void printCuts(const char* fileName);
88  virtual void printCutStats(std::ostream& of) = 0;
89  virtual bool loadCutDB(); // Loads pre-compiled cuts from database
90 
91  virtual bool isCut(const char* cutName);
92  virtual int cutID(const char* cutName);
93  virtual float maxVal(const char* cutName);
94  virtual float maxVal(int cutID);
95  virtual float minVal(const char* cutName);
96  virtual float minVal(int cutID);
97 
98  virtual void setRange(const char* cutName, float xmin, float xmax);
99  virtual void setRange(int cutID, float xmin, float xmax);
100 
101  ClassDef(StEStructCuts,1)
102 
103 };
104 
105 inline void StEStructCuts::dataValue(const char* name,float value){
106 
107  int i = cutID(name);
108  if(i<0 || i==mnumVars) return;
109  mvalues[i]=value;
110 }
111 
112 inline int StEStructCuts::createCutHists(const char* name, double* range, int nvals){
113  float* tmp=new float[nvals];
114  for(int i=0;i<nvals;i++)tmp[i]=(float)range[i];
115  int retVal=createCutHists(name,tmp,nvals);
116  delete [] tmp;
117  return retVal;
118 }
119 
120 inline int StEStructCuts::createCutHists(const char* name, int* range, int nvals){
121  float* tmp=new float[nvals];
122  for(int i=0;i<nvals;i++)tmp[i]=(float)range[i];
123  int retVal=createCutHists(name,tmp,nvals);
124  delete [] tmp;
125  return retVal;
126 }
127 
128 inline int StEStructCuts::createCutHists(const char* name, unsigned int* range, int nvals){
129  float* tmp=new float[nvals];
130  for(int i=0;i<nvals;i++)tmp[i]=(float)range[i];
131  int retVal=createCutHists(name,tmp,nvals);
132  delete [] tmp;
133  return retVal;
134 
135 }
136 
137 inline bool StEStructCuts::isLoaded(){ return (mcutFileName) ? true : false ; }
138 
139 
140 inline int StEStructCuts::cutID(const char* cutName){
141 
142  if(mnumVars<0) return -1;
143  int i;
144  for(i=0;i<mnumVars;i++)if(strstr(cutName,mvarName[i]))break;
145  if(i==mnumVars)i=-1;
146  return i;
147 
148 }
149 
150 inline bool StEStructCuts::isCut(const char* cutName){
151  int id=cutID(cutName);
152  if(id<0) return false;
153  return true;
154 }
155 
156 inline float StEStructCuts::minVal(int cutID){
157  if(cutID<0 || cutID==mnumVars)return 0.;
158  return mminVal[cutID];
159 }
160 
161 inline float StEStructCuts::minVal(const char* cutName){
162  return minVal(cutID(cutName));
163 }
164 
165 inline float StEStructCuts::maxVal(int cutID){
166  if(cutID<0 || cutID==mnumVars)return 0.;
167  return mmaxVal[cutID];
168 }
169 
170 
171 inline float StEStructCuts::maxVal(const char* cutName){
172  return maxVal(cutID(cutName));
173 }
174 
175 inline void StEStructCuts::setRange(int cutID, float xmin, float xmax){
176  if(cutID<0 || cutID==mnumVars) return;
177  mminVal[cutID]=xmin;
178  mmaxVal[cutID]=xmax;
179 }
180 
181 inline void StEStructCuts::setRange(const char* cutName, float xmin, float xmax){
182  setRange(cutID(cutName),xmin,xmax);
183 }
184 
185 inline void StEStructCuts::setDoFillHists(bool filling) {
186  mDoFillHists = filling;
187 }
188 inline bool StEStructCuts::doFillHists() {
189  return mDoFillHists;
190 }
191 
192 
193 #endif
194 
195 
196 /***********************************************************************
197  *
198  * $Log: StEStructCuts.h,v $
199  * Revision 1.9 2012/11/16 21:19:06 prindle
200  * Moved EventCuts, TrackCuts to EventReader. Affects most readers.
201  * Added support to write and read EStructEvents.
202  * Cuts: 3D histo support, switch to control filling of histogram for reading EStructEvents
203  * EventCuts: A few new cuts
204  * MuDstReader: Add 2D to some histograms, treat ToFCut, PrimaryCuts, VertexRadius histograms like other cut histograms.
205  * QAHists: Add refMult
206  * TrackCuts: Add some hijing cuts.
207  *
208  * Revision 1.8 2012/06/11 14:35:32 fisyak
209  * std namespace
210  *
211  * Revision 1.7 2010/09/02 21:20:09 prindle
212  * Cuts: Add flag to not fill histograms. Important when scanning files for sorting.
213  * EventCuts: Add radius cut on vertex, ToF fraction cut. Merge 2004 AuAu 200 GeV datasets.
214  * Add 7, 11 and 39 GeV dataset selections
215  * MuDstReader: Add 2D histograms for vertex radius and ToF fraction cuts.
216  * Modify countGoodTracks to return number of dEdx and ToF pid identified tracks.
217  * Include code to set track pid information from Dst.
218  * QAHists: New ToF QA hists. Modify dEdx to include signed momentum.
219  *
220  * Revision 1.6 2010/03/02 21:43:38 prindle
221  * Use outerHelix() for global tracks
222  * Add sensible triggerId histograms
223  * Starting to add support to sort events (available for Hijing)
224  *
225  * Revision 1.5 2006/04/04 22:05:03 porter
226  * a handful of changes:
227  * - changed the StEStructAnalysisMaker to contain 1 reader not a list of readers
228  * - added StEStructQAHists object to contain histograms that did exist in macros or elsewhere
229  * - made centrality event cut taken from StEStructCentrality singleton
230  * - put in ability to get any max,min val from the cut class - one must call setRange in class
231  *
232  * Revision 1.4 2005/09/14 17:08:32 msd
233  * Fixed compiler warnings, a few tweaks and upgrades
234  *
235  * Revision 1.3 2005/02/09 23:08:44 porter
236  * added method to add histograms directly instead of under
237  * the control of the class. Useful for odd 2D hists that don't
238  * fit the current model.
239  *
240  * Revision 1.2 2004/08/23 19:12:13 msd
241  * Added pre-compiled cut database, minor changes to cut base class
242  *
243  * Revision 1.1 2003/10/15 18:20:32 porter
244  * initial check in of Estruct Analysis maker codes.
245  *
246  *
247  *********************************************************************/