Changeset 14743 for fact/tools/rootmacros/PulseTemplates
- Timestamp:
- 12/13/12 18:15:41 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/PulseTemplates/Sample.C
r14706 r14743 86 86 int max) 87 87 { 88 int rndNum = min + mRandom.Integer(max - min); 89 cout << rndNum << endl; 88 // int rndNum = min + mRandom.Integer(max - min); 89 int rndNum = (int) mRandom.Uniform(min, max); 90 // cout << rndNum << endl; 90 91 return rndNum; 91 92 } … … 166 167 } 167 168 169 170 int 171 Sample::BootstrapVector(vector<double> *inVector, vector<double> *outVector) 172 { 173 //get size of sample to be bootstrapped 174 int sampleSize = inVector->size(); 175 176 //Vector with positions in original sample 177 vector<int> entryID (sampleSize,0); 178 179 //calculate wich entries from inVector will be put into outVector 180 BootstrapSample(&entryID, 0, sampleSize, sampleSize ); 181 182 vector<int>::iterator it; 183 184 //Loop over entryID vector to fill content from inVector to outVector 185 int counter = 0; 186 for ( it=entryID.begin() ; it != entryID.end(); it++ ) 187 { 188 outVector->at(counter) = inVector->at(*it); 189 counter++; 190 } 191 192 return counter + 1; 193 } 194 195 int 196 Sample::BootstrapTH1(TH1* inputHisto, TH1* outHisto) 197 { 198 //compute the median for 1-d histogram h1 199 int nbins = inputHisto->GetXaxis()->GetNbins(); 200 201 //we need to get the binning 202 203 //entries of TH1 204 vector<float> entries; 205 206 //quantity of entries in bin 207 int quantity = 0; 208 float value = 0; 209 for (int i=0;i<nbins;i++) 210 { 211 value = inputHisto->GetBinLowEdge(i); 212 quantity = inputHisto->GetBinContent(i); 213 // cout << value << "(" << quantity << ") "; 214 for (int j = 0; j < quantity; j++) 215 { 216 entries.push_back(value); 217 } 218 } 219 220 //get size of sample to be bootstrapped 221 int sampleSize = entries.size(); 222 223 //Vector with positions in original sample 224 vector<int> entryID (sampleSize,0); 225 226 //calculate a list with random EntryIDs and fill it into entryID 227 BootstrapSample(&entryID, 0, sampleSize, sampleSize ); 228 229 //Loop over entryID vector to bootstrap the histogram 230 int counter = 0; 231 for ( unsigned int i = 0 ; i < entryID.size(); i++ ) 232 { 233 outHisto->Fill( 234 entries.at( entryID.at(i) ) 235 ); 236 counter++; 237 } 238 239 return counter + 1; 240 } 241 168 242 void 169 243 Sample::BootstrapSample() … … 181 255 int size) 182 256 { 257 if (size == 0){ 258 cout << "size = 0; nothing to do" << endl; 259 return; 260 } 261 262 //resize the sample vector to size of boostrapped sample 183 263 sampleVector->resize(size); 184 264 265 //list of rndnumbers pulled with putting back 185 266 multiset<int> sampleSet; 186 267 268 //loop over samplesize to generate random numbers to fill into sampleset 187 269 for (int i = 0; i < size; i++) 188 270 { … … 196 278 197 279 int counter = 0; 280 // loop over list of rndnumbers and fill their entries into sampleVector 281 // entries are vector positions 198 282 for ( it=sampleSet.begin() ; it != sampleSet.end(); it++ ) 199 283 { … … 204 288 return; 205 289 } 290 //NOTE: crashes for some reason if size is smaller than max-min
Note:
See TracChangeset
for help on using the changeset viewer.