Changeset 14707 for fact/tools
- Timestamp:
- 11/30/12 16:24:47 (12 years ago)
- Location:
- fact/tools/rootmacros/PulseTemplates
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/rootmacros/PulseTemplates/templateextractors.C
r14477 r14707 86 86 if (verbosityLevel > 2) cout << "\t...calculation of " 87 87 << "pulse order " << pulse_order; 88 // vector max_value_of to number of timeslices in Overlay Spectra88 // vector max_value_of to number of slices in Overlay Spectra 89 89 CalcMaxPropabilityOfSlice( 90 90 hInputHistoArray[pulse_order], … … 135 135 //---------------------------------------------------------------------------- 136 136 137 Double_t MedianOfH1withRndSlices ( 138 TH1* inputHisto, //histogram from which median will be calculated 139 vector<int>* position //array with random slice numbers 140 ) 141 { 142 //compute the median for 1-d histogram h1 143 Int_t nbins = inputHisto->GetXaxis()->GetNbins(); 144 Double_t *x = new Double_t[nbins]; 145 Double_t *y = new Double_t[nbins]; 146 for (Int_t i=0;i<nbins;i++) { 147 x[i] = inputHisto->GetXaxis()->GetBinCenter(position->at(i) ); 148 y[i] = inputHisto->GetBinContent(position->at(i) ); 149 } 150 Double_t median = TMath::Median(nbins,x,y); 151 delete [] x; 152 delete [] y; 153 return median; 154 } 155 // end of PlotMedianEachSliceOfPulse 156 //---------------------------------------------------------------------------- 157 137 158 void 138 159 PlotMedianOfSlice( … … 148 169 TH2F** hInputHistoArray = NULL; 149 170 TH1F** hOutputHistoArray = NULL; 150 TH1* hTempHisto = NULL;151 float median = 0;171 // TH1* hTempHisto = NULL; 172 // float median = 0; 152 173 153 174 if (overlayType.Contains("Edge")) … … 175 196 << "pulse order " << pulse_order; 176 197 177 Int_t nbins = hInputHistoArray[pulse_order]->GetXaxis()->GetNbins(); 178 179 for (Int_t TimeSlice=1;TimeSlice<=nbins;TimeSlice++) { 180 181 hTempHisto = hInputHistoArray[pulse_order]->ProjectionY("",TimeSlice,TimeSlice); 182 median = MedianOfH1(hTempHisto); 183 184 if (verbosityLevel > 2) printf("Median of Slice %d, Median=%g\n",TimeSlice,median); 185 186 hOutputHistoArray[pulse_order]->SetBinContent(TimeSlice, median ); 198 MedianOfTH2Slices( 199 hInputHistoArray[pulse_order], 200 hOutputHistoArray[pulse_order], 201 verbosityLevel 202 ); 203 204 ErrorMedianOfTH2Slices( 205 hInputHistoArray[pulse_order], 206 hOutputHistoArray[pulse_order], 207 5, //numIterations 208 verbosityLevel 209 ); 210 211 // Int_t nbins = hInputHistoArray[pulse_order]->GetXaxis()->GetNbins(); 212 213 // for (Int_t slice=1;slice<=nbins;slice++) { 214 215 // hTempHisto = hInputHistoArray[pulse_order]->ProjectionY("",slice,slice); 216 // median = MedianOfH1(hTempHisto); 217 218 // if (verbosityLevel > 2) printf("Median of Slice %d, Median=%g\n",slice,median); 219 220 // hOutputHistoArray[pulse_order]->SetBinContent(slice, median ); 221 //// delete h1; 222 // } 223 224 if (verbosityLevel > 2) cout << "\t...done" << endl; 225 } 226 } 227 // end of PlotMedianEachSliceOfPulse 228 //---------------------------------------------------------------------------- 229 230 void 231 MedianOfTH2Slices( 232 TH2* inputHisto, 233 TH1* outputHisto, 234 int verbosityLevel 235 ) 236 { 237 Int_t nbins = inputHisto->GetXaxis()->GetNbins(); 238 float median = 0; 239 240 for (Int_t slice=1;slice<=nbins;slice++) { 241 242 median = MedianOfH1( inputHisto->ProjectionY("",slice,slice) ); 243 244 if (verbosityLevel > 2) printf("Median of Slice %d, Median=%g\n",slice,median); 245 246 outputHisto->SetBinContent(slice, median ); 187 247 // delete h1; 248 } 249 return; 250 } 251 // end of MedianOfTH2Slices 252 //---------------------------------------------------------------------------- 253 254 void 255 ErrorMedianOfTH2Slices( 256 TH2* inputHisto, 257 TH1* outputHisto, 258 int numIterations, 259 int verbosityLevel 260 ) 261 { 262 Int_t nbins = inputHisto->GetXaxis()->GetNbins(); 263 264 // float MedianOfSliceMean[nbins]; 265 // float MedianOfSliceRMS[nbins]; 266 267 for (Int_t slice=1;slice<=nbins;slice++) { 268 269 float median[numIterations]; 270 int sample_min = inputHisto->GetXaxis()->GetFirst(); 271 int sample_max = inputHisto->GetXaxis()->GetLast(); 272 int sample_size = sample_max - sample_min; 273 vector<int> rndList; 274 275 276 Sample sample(sample_size); 277 for (int i = 0; i < numIterations; i++) 278 { 279 sample.BootstrapSample(rndList, sample_min, sample_max, sample_size); 280 median[i] = MedianOfH1withRndSlices( 281 inputHisto->ProjectionY("",slice,slice), 282 rndList 283 ); 284 285 if (verbosityLevel > 2) printf("Median of Slice %d, Median=%g\n",slice,median); 188 286 } 189 190 if (verbosityLevel > 2) cout << "\t...done" << endl; 191 } 287 // MedianOfSliceMean[slice] = TMath::Mean(numIterations, median); 288 // MedianOfSliceRMS[slice] = TMath::RMS(numIterations, median); 289 // outputHisto->SetBinError(slice, MedianOfSliceRMS); 290 outputHisto->SetBinError(slice, RMS(numIterations, median) ); 291 292 // outputHisto->SetBinContent(slice, median ); 293 // delete h1; 294 } 295 return; 192 296 } 193 297 // end of PlotMedianEachSliceOfPulse … … 236 340 Int_t nbins = hInputHistoArray[pulse_order]->GetXaxis()->GetNbins(); 237 341 238 for (Int_t TimeSlice=1;TimeSlice<=nbins;TimeSlice++) {239 240 hTempHisto = hInputHistoArray[pulse_order]->ProjectionY("", TimeSlice,TimeSlice);342 for (Int_t slice=1;slice<=nbins;slice++) { 343 344 hTempHisto = hInputHistoArray[pulse_order]->ProjectionY("",slice,slice); 241 345 mean = hTempHisto->GetMean(); 242 346 243 if (verbosityLevel > 2) printf("Mean of Slice %d, Mean=%g\n", TimeSlice,mean);244 245 hOutputHistoArray[pulse_order]->SetBinContent( TimeSlice, mean );347 if (verbosityLevel > 2) printf("Mean of Slice %d, Mean=%g\n",slice,mean); 348 349 hOutputHistoArray[pulse_order]->SetBinContent(slice, mean ); 246 350 // delete h1; 247 351 } … … 326 430 // if (verbosityLevel > 2) cout << "\t...# slices processed " << nbins << endl; 327 431 328 for (Int_t TimeSlice=1;TimeSlice<=300;TimeSlice++)329 { 330 331 hTempHisto = hInputHisto->ProjectionY("", TimeSlice,TimeSlice);432 for (Int_t slice=1;slice<=300;slice++) 433 { 434 435 hTempHisto = hInputHisto->ProjectionY("",slice,slice); 332 436 333 437 if (verbosityLevel > 3) 334 438 { 335 cout << "\t\t...calculating maxProb of slice " << TimeSlice << endl;439 cout << "\t\t...calculating maxProb of slice " << slice << endl; 336 440 } 337 441 max_prop = hTempHisto->GetBinCenter( hTempHisto->GetMaximumBin() ); … … 339 443 if (verbosityLevel > 3) 340 444 { 341 cout << "\t\t...calculating Median of slice " << TimeSlice << endl;445 cout << "\t\t...calculating Median of slice " << slice << endl; 342 446 } 343 447 median = MedianOfH1(hTempHisto); 344 448 345 if (verbosityLevel > 4) cout << "\t\t...calculating Mean of slice " << TimeSlice << endl;449 if (verbosityLevel > 4) cout << "\t\t...calculating Mean of slice " << slice << endl; 346 450 mean = hTempHisto->GetMean(); 347 451 348 if (verbosityLevel > 4) cout << "\t\t\t\t MaxProb of Slice " << TimeSlice << ": " << max_prop << endl;349 hOutputMaxHisto->SetBinContent( TimeSlice, max_prop );350 351 if (verbosityLevel > 4) cout << "\t\t\t\t Mean of Slice " << TimeSlice << ": " << mean << endl;352 hOutputMeanHisto->SetBinContent( TimeSlice, mean );353 354 if (verbosityLevel > 4) cout << "\t\t\t\t Median of Slice " << TimeSlice << ": " << median << endl;355 hOutputMedianHisto->SetBinContent( TimeSlice, median );452 if (verbosityLevel > 4) cout << "\t\t\t\t MaxProb of Slice " << slice << ": " << max_prop << endl; 453 hOutputMaxHisto->SetBinContent(slice, max_prop ); 454 455 if (verbosityLevel > 4) cout << "\t\t\t\t Mean of Slice " << slice << ": " << mean << endl; 456 hOutputMeanHisto->SetBinContent(slice, mean ); 457 458 if (verbosityLevel > 4) cout << "\t\t\t\t Median of Slice " << slice << ": " << median << endl; 459 hOutputMedianHisto->SetBinContent(slice, median ); 356 460 delete hTempHisto; 357 461 358 }//Loop over Timeslices462 }//Loop over slices 359 463 } 360 464 // end of PlotMaxPropabilityPulse … … 423 527 out << "time [slices],AmplitudeMax [mV],AmplitudeMean [mV],AmplitudeMedian [mV]" << endl; 424 528 425 for (int TimeSlice=1;TimeSlice<=nbins;TimeSlice++)426 { 427 out << TimeSlice << "," ;428 out << Max_histo->GetBinContent( TimeSlice) << ",";429 out << Mean_histo->GetBinContent( TimeSlice) << ",";430 out << Median_histo->GetBinContent( TimeSlice) << endl;529 for (int slice=1;slice<=nbins;slice++) 530 { 531 out << slice << "," ; 532 out << Max_histo->GetBinContent(slice) << ","; 533 out << Mean_histo->GetBinContent(slice) << ","; 534 out << Median_histo->GetBinContent(slice) << endl; 431 535 } 432 536 out.close(); -
fact/tools/rootmacros/PulseTemplates/templateextractors.h
r14477 r14707 13 13 14 14 #include "pixel.h" 15 #include "Sample.h" 15 16 16 17 /** Assignment operator. … … 57 58 ); 58 59 60 Double_t MedianOfH1withRndSlices ( 61 TH1* inputHisto, //histogram from which median will be calculated 62 vector<int> *position //array with random slice numbers 63 ); 64 59 65 void 60 66 PlotMedianOfSlice( … … 69 75 TString overlayType, 70 76 int verbosityLevel 77 ); 78 79 void 80 MedianOfTH2Slices( 81 TH2* inputHisto, 82 TH1* outputHisto, 83 int verbosityLevel 84 ); 85 86 void 87 ErrorMedianOfTH2Slices( 88 TH2* inputHisto, 89 TH1* outputHisto, 90 int numIterations, 91 int verbosityLevel 71 92 ); 72 93
Note:
See TracChangeset
for help on using the changeset viewer.