Changeset 14707 for fact/tools


Ignore:
Timestamp:
11/30/12 16:24:47 (12 years ago)
Author:
Jens Buss
Message:
implemented error calculation for median
Location:
fact/tools/rootmacros/PulseTemplates
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/rootmacros/PulseTemplates/templateextractors.C

    r14477 r14707  
    8686        if (verbosityLevel > 2) cout << "\t...calculation of "
    8787                                     << "pulse order " << pulse_order;
    88         //  vector max_value_of to number of timeslices in Overlay Spectra
     88        //  vector max_value_of to number of slices in Overlay Spectra
    8989        CalcMaxPropabilityOfSlice(
    9090                    hInputHistoArray[pulse_order],
     
    135135//----------------------------------------------------------------------------
    136136
     137Double_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
    137158void
    138159PlotMedianOfSlice(
     
    148169    TH2F**  hInputHistoArray    = NULL;
    149170    TH1F**  hOutputHistoArray   = NULL;
    150     TH1*    hTempHisto          = NULL;
    151     float   median              = 0;
     171//    TH1*    hTempHisto          = NULL;
     172//    float   median              = 0;
    152173
    153174    if (overlayType.Contains("Edge"))
     
    175196                                     << "pulse order " << pulse_order;
    176197
    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
     230void
     231MedianOfTH2Slices(
     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 );
    187247//            delete h1;
     248    }
     249    return;
     250}
     251// end of MedianOfTH2Slices
     252//----------------------------------------------------------------------------
     253
     254void
     255ErrorMedianOfTH2Slices(
     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);
    188286        }
    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;
    192296}
    193297// end of PlotMedianEachSliceOfPulse
     
    236340        Int_t   nbins       = hInputHistoArray[pulse_order]->GetXaxis()->GetNbins();
    237341
    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);
    241345            mean      = hTempHisto->GetMean();
    242346
    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 );
    246350//            delete h1;
    247351        }
     
    326430//    if (verbosityLevel > 2) cout << "\t...# slices processed " << nbins << endl;
    327431
    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);
    332436
    333437        if (verbosityLevel > 3)
    334438        {
    335             cout << "\t\t...calculating maxProb of slice " << TimeSlice << endl;
     439            cout << "\t\t...calculating maxProb of slice " << slice << endl;
    336440        }
    337441        max_prop    = hTempHisto->GetBinCenter( hTempHisto->GetMaximumBin() );
     
    339443        if (verbosityLevel > 3)
    340444        {
    341             cout << "\t\t...calculating Median of slice " << TimeSlice << endl;
     445            cout << "\t\t...calculating Median of slice " << slice << endl;
    342446        }
    343447        median      = MedianOfH1(hTempHisto);
    344448
    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;
    346450        mean        = hTempHisto->GetMean();
    347451
    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 );
    356460        delete hTempHisto;
    357461
    358     }//Loop over Timeslices
     462    }//Loop over slices
    359463}
    360464// end of PlotMaxPropabilityPulse
     
    423527    out << "time [slices],AmplitudeMax [mV],AmplitudeMean [mV],AmplitudeMedian [mV]" << endl;
    424528
    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;
    431535    }
    432536    out.close();
  • fact/tools/rootmacros/PulseTemplates/templateextractors.h

    r14477 r14707  
    1313
    1414#include "pixel.h"
     15#include "Sample.h"
    1516
    1617/** Assignment operator.
     
    5758        );
    5859
     60Double_t MedianOfH1withRndSlices (
     61        TH1*            inputHisto,     //histogram from which median will be calculated
     62        vector<int> *position        //array with random slice numbers
     63        );
     64
    5965void
    6066PlotMedianOfSlice(
     
    6975        TString         overlayType,
    7076        int             verbosityLevel
     77        );
     78
     79void
     80MedianOfTH2Slices(
     81        TH2*        inputHisto,
     82        TH1*        outputHisto,
     83        int         verbosityLevel
     84        );
     85
     86void
     87ErrorMedianOfTH2Slices(
     88        TH2*        inputHisto,
     89        TH1*        outputHisto,
     90        int         numIterations,
     91        int         verbosityLevel
    7192        );
    7293
Note: See TracChangeset for help on using the changeset viewer.