StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEStructCentrality.cxx
1 /**********************************************************************
2  *
3  * $Id: StEStructCentrality.cxx,v 1.8 2010/03/02 21:47:18 prindle Exp $
4  *
5  * Author: Jeff Porter
6  *
7  **********************************************************************
8  *
9  * Description: allows run-time definition of event class centrality
10  * this used to be persistent with dst...
11  *
12  ***********************************************************************/
13 #include "StEStructCentrality.h"
14 #include "Stiostream.h"
15 
16 ClassImp(StEStructCentrality)
17 
19 
21 
22  if(!mInstance) mInstance=new StEStructCentrality();
23  return mInstance;
24 }
25 
26 
27 //--------------------------------------------------------------------
28 StEStructCentrality::~StEStructCentrality(){
29 
30  if (mcentralities) {
31  delete [] mcentralities;
32  }
33  if (mpts) {
34  delete [] mpts;
35  }
36  if (mptcents) {
37  delete [] mptcents;
38  }
39 
40 }
41 
42 //--------------------------------------------------------------------
43 // Feb 26, 2004 djp Change from UInt_t to Double_t and check that
44 // input is within range covered by definition.
45 int StEStructCentrality::centrality(const double impact) {
46  if(!mcentralities) {
47  if(warningCount<10){
48  warningCount++;
49  cout<<" Error:: centrality requested without initialization (warning #"<<warningCount<<")"<<endl;
50  }
51  return -1;
52  }
53 
54  mValue = impact;
55  int found = 0;
56  int retVal = 0;
57  for(retVal=0;retVal<mnumCentralities-1;retVal++) {
58  if(impact>=mcentralities[retVal] && impact<mcentralities[retVal+1]) {
59  found = 1;
60  break;
61  }
62  }
63  if (!found) {
64  return -1;
65  }
66  return retVal;
67 }
68 
69 int StEStructCentrality::ptIndex(const double pt) {
70  if(!mpts) {
71  if(warningCount<10){
72  warningCount++;
73  cout<<" Error:: Pt index requested without initialization (warning #"<<warningCount<<")"<<endl;
74  }
75  return -1;
76  }
77 
78  int found = 0;
79  int retVal = 0;
80  for(retVal=0;retVal<mnumpts-1;retVal++) {
81  if(pt>=mpts[retVal] && pt<mpts[retVal+1]) {
82  found = 1;
83  break;
84  }
85  }
86  if (!found) {
87  return -1;
88  }
89  return retVal;
90 }
91 
92 int StEStructCentrality::ptCentrality(const double cent) {
93  if(!mptcents) {
94  if(warningCount<10){
95  warningCount++;
96  cout<<" Error:: Pt centrality index requested without initialization (warning #"<<warningCount<<")"<<endl;
97  }
98  return -1;
99  }
100 
101  int found = 0;
102  int retVal = 0;
103  for(retVal=0;retVal<mnumptcents-1;retVal++) {
104  if(cent>=mptcents[retVal] && cent<mptcents[retVal+1]) {
105  found = 1;
106  break;
107  }
108  }
109  if (!found) {
110  return -1;
111  }
112  return retVal;
113 }
114 
115 //--------------------------------------------------------------------
116 void StEStructCentrality::setCentralities(const double* centralities, const int num){
117 
118  if (!centralities || num==0) {
119  return;
120  }
121  if (mcentralities) {
122  delete [] mcentralities;
123  }
124  mcentralities = new double[num];
125  for (int i=0;i<num;i++) {
126  mcentralities[i]=centralities[i];
127  }
128  mnumCentralities=num;
129 }
130 
131 int StEStructCentrality::numCentralities() {
132  if(!mcentralities) { // this is set with mnumCentralities in setCentralities
133  if(warningCount<10){
134  warningCount++;
135  cout<<" Error:: numCentralities requested without initialization (warning #"<<warningCount<<")"<<endl;
136  }
137  return -1;
138  }
139 
140  return mnumCentralities;
141 }
142 
143 double StEStructCentrality::centralityLimit( const int index ) {
144  if ((index < 0) || (mnumCentralities <index)) {
145  return -1;
146  }
147  return mcentralities[index];
148 }
149 
150 
151 void StEStructCentrality::setPts( const double* pts, const int numPt,
152  const double* cents, const int numCent ) {
153  if (!pts || numPt==0 || !cents || numCent==0) {
154  return;
155  }
156  if(mpts) {
157  delete [] mpts;
158  }
159  if(mptcents) {
160  delete [] mptcents;
161  }
162  mpts = new double[numPt];
163  for (int i=0;i<numPt;i++) {
164  mpts[i] = pts[i];
165  }
166  mnumpts = numPt;
167  mptcents = new double[numCent];
168  for (int i=0;i<numCent;i++) {
169  mptcents[i] = cents[i];
170  }
171  mnumptcents=numCent;
172 }
173 void StEStructCentrality::setPtLimit( const int index, double pt ) {
174  if ((index < 0) || (mnumpts <index)) {
175  return;
176  }
177  mpts[index] = pt;
178 }
179 int StEStructCentrality::numPts() {
180  return mnumpts;
181 }
182 int StEStructCentrality::numPtCentralities() {
183  return mnumptcents;
184 }
185 double StEStructCentrality::ptLimit( const int index ) {
186  if ((index < 0) || (mnumpts <index)) {
187  return -1;
188  }
189  return mpts[index];
190 }
191 double StEStructCentrality::ptCentralityLimit( const int index ) {
192  if ((index < 0) || (mnumptcents <index)) {
193  return -1;
194  }
195  return mptcents[index];
196 }
197 void StEStructCentrality::Print() {
198  if(!mcentralities) {
199  cout << "Print::Centralities not initialized!" << endl;
200  return;
201  }
202  cout << "Centrality bin definitions:" << endl;
203  cout << " bin\tmin\tmax" <<endl;
204  for(int i=0; i<numCentralities()-1; i++) cout << " " << i << "\t" << minCentrality(i) << "\t" << maxCentrality(i) << endl;
205 }
206 
207 
208 /***********************************************************************
209  *
210  * $Log: StEStructCentrality.cxx,v $
211  * Revision 1.8 2010/03/02 21:47:18 prindle
212  * Support to retrieve track radius when it crosses endplate
213  * Add way to retrieve centrality
214  *
215  * Revision 1.7 2007/01/26 17:19:49 msd
216  * Added Print function.
217  *
218  * Revision 1.6 2006/04/04 22:12:29 porter
219  * Set up StEtructCentrality for use in event cut selection - includes impact para for generators
220  *
221  * Revision 1.5 2005/09/29 17:41:50 msd
222  * Added initialization check to numCentralities
223  *
224  * Revision 1.4 2004/09/24 01:46:45 prindle
225  * Added call for setPtLimit. I use this in fluctuations which prevented
226  * a fresh CVS checkout from compiling
227  *
228  * Revision 1.3 2004/06/09 22:39:06 prindle
229  * Expanded centrality class.
230  * Call to set centrality from event reader.
231  *
232  *
233  * CVS :nded ----------------------------------------------------------------------
234  *
235  * Revision 1.2 2004/02/27 02:28:02 prindle
236  *
237  * Small modification to StEStructCentrality in EventMaker branch.
238  * Many modifications to Fluctuations branch, although that branch is not
239  * stable yet.
240  *
241  * Revision 1.1 2003/10/15 18:20:51 porter
242  * initial check in of Estruct Analysis maker codes.
243  *
244  *
245  *********************************************************************/
246 
247 
248 
249 
250 
251