Changeset 12690


Ignore:
Timestamp:
12/02/11 18:43:49 (13 years ago)
Author:
Jens Buss
Message:
added plot Amplification vs. Channel
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/rootmacros/gainfit2.C

    r12640 r12690  
    3131  float amplMean;
    3232  } proj;
    33 vector<proj> proj_of_pixel;
     33vector<proj> channel;
     34
     35
     36//-----------------------------------------------------------------------------
     37// Decleration of Histograms
     38//-----------------------------------------------------------------------------
     39
     40//Amplification Distribution
     41TH1F *hAmplDistribution = NULL;
     42TH1F *hAmplDistribution2 = NULL;
     43TH1F *hAmplVsChannel = NULL;
     44
     45//Lists of Histograms taht are to be saved
     46TObjArray hList;
     47TObjArray hListPeakSpektra;
     48
    3449
    3550//-----------------------------------------------------------------------------
     
    3752//-----------------------------------------------------------------------------
    3853
     54void BookHistos();
     55void SaveHistograms(const char * );
     56//Double_t spek_fit(Double_t *x, Double_t *par)
     57
    3958
    4059//-----------------------------------------------------------------------------
     
    4463
    4564int gainfit2(
    46         const char * InputRootFileName = "../analysis/fpeak/20111109_006_fpeak.root",
    47         const char * OutTextFileName = "../analysis/fpeak/20111109_006_gainfit.txt",
    48         //TODO: Output into txt-file
     65        const char * InputRootFileName = "../analysis/fpeak/20111109_006/20111109_006_fpeak.root",
     66        const char * InputBaselineFileName = "../analysis/fpeak/20111109_006/20111109_006_fbsl.root",
     67        const char * OutTextFileName = "../analysis/fpeak/20111109_006_gainfit_test.txt",
     68        const char * RootOutFileName = "../analysis/fpeak/20111109_006_gainfit_test.root",
    4969        bool showHistos = false,
    5070        bool debug = false)
     
    5575//-----------------------------------------------------------------------------
    5676
     77//Open Rootfiles Files
     78    TFile * baseline = TFile::Open( InputBaselineFileName );
     79    TFile * file = TFile::Open( InputRootFileName );
     80
     81
    5782    TH1D *hPixelProjection = NULL;
    58     TFile * file = TFile::Open( InputRootFileName );
     83//Baseline
     84    TH2F * hbaseline = (TH2F*)baseline->Get("histo_mean");
     85//Amplitude spectrum
    5986    TH2F *h = (TH2F*)file->Get("hAmplSpek_cfd");
    6087   
     88    BookHistos();
    6189
    6290    Double_t par[9];
     
    6593    TF1 *g3    = new TF1("g3","gaus",25,35);
    6694    TF1 *g4    = new TF1("g4","gaus");
    67     TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",5,35);
    68     TH1F *hAmplDistribution = new TH1F("hAmplDistribution","Distribution of G-APD Amplification (1+2)", 500, 0 , 20 );
    69     TH1F *hAmplDistribution2 = new TH1F("hAmplDistribution2","Distribution of G-APD Amplification(2+3)", 500, 0 , 20 );
    70     TH1F *hAmplDistribution3 = new TH1F("hAmplDistribution3","Distribution of G-APD Amplification(2+3)", 500, 0 , 20 );
    71 
    72     TCanvas *cGainFit = new TCanvas("cGainFit", "Fit of Amplitude Spektra", 0,0, 800,800);
    73     //TCanvas *cGainDist = new TCanvas("cGainDist", "cGainDist", 0,501, 1000,500);
     95    TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",7,32);
     96
     97
     98    TCanvas *cGainFit = new TCanvas("cGainFit", "Fit of Amplitude Spektra", 0,0, 1200,400);
    7499    cGainFit->Clear();
    75     cGainFit->Divide(2, 2);
    76 
    77 //-----------------------------------------------------------------------------
    78 // Loop over all Pixels and fit Distribution of singles, doubles and tripples
    79 //-----------------------------------------------------------------------------
     100    cGainFit->Divide(3, 2);
     101
     102    TCanvas *cGraphs = new TCanvas("cGraphs", "Horst", 0,401, 1200,400);
     103    cGraphs->Clear();
     104    cGraphs->Divide(1, 2);
    80105
    81106    cGainFit->cd(1);
     
    85110    h->SetAxisRange(0, 100, "Y");
    86111    h->Draw("COLZ");
    87     proj_of_pixel.resize(h->GetNbinsX());
     112    channel.resize(h->GetNbinsX());
    88113    NumberOfPixels = h->GetNbinsX();
     114
     115    cGainFit->cd(2);
     116    hbaseline->SetTitle("Baselinedistribution of all Pixels");
     117    hbaseline->SetAxisRange(-5, 5, "X");
     118    //hbaseline->SetAxisRange(0, 100, "Y");
     119    hbaseline->Fit("gaus");
     120    hbaseline->Draw();
     121
     122    //-----------------------------------------------------------------------------
     123    // Graphs
     124    //-----------------------------------------------------------------------------
     125
     126    Double_t simple_gain[NumberOfPixels];
     127    Double_t gain[NumberOfPixels];
     128    Double_t pixelvec[NumberOfPixels];
     129    for (UInt_t i=0; i<NumberOfPixels; i++){
     130       pixelvec[i]=i;
     131       simple_gain[i]=0;
     132       gain[i]=0;
     133    }
     134
     135    TGraph *gr1 = new TGraph(NumberOfPixels,pixelvec,simple_gain);
     136    TGraph *gr2 = new TGraph(NumberOfPixels,pixelvec,gain);
     137
     138    gr1->SetMarkerStyle(5);
     139    gr2->SetMarkerStyle(2);
     140    gr1->SetMarkerColor(kRed);
     141    gr2->SetMarkerColor(kBlack);
     142    gr1->SetMarkerSize(0.5);
     143    gr2->SetMarkerSize(0.5);
     144    TMultiGraph *mg = new TMultiGraph();
     145    mg->Add(gr1);
     146    mg->Add(gr2);
     147
     148
     149
     150
     151//-----------------------------------------------------------------------------
     152// Loop over all Pixels and fit Distribution of singles, doubles and tripples
     153//-----------------------------------------------------------------------------
     154
    89155    cout << "Number of Pixels: " << NumberOfPixels << endl;
    90 
    91156    // Begin of Loop
    92157    for (UInt_t pixel = 0; pixel < NumberOfPixels; pixel++){
     158
     159        //Title
     160        TString pixelnumber;
     161        pixelnumber += "hPixelProj";
     162        pixelnumber += "_";
     163        pixelnumber += pixel + 1 ;
    93164
    94165        cout << "-----------------------------------------------------------" << endl;
     
    96167        cout << "-----------------------------------------------------------" << endl;
    97168       
    98         hPixelProjection = h->ProjectionY( "# " , pixel+1, pixel+1);     //Projectipon of each Pixel out of Ampl.Spectrum
     169        hPixelProjection = h->ProjectionY( pixelnumber , pixel+1, pixel+1);      //Projectipon of each Pixel out of Ampl.Spectrum
    99170        hPixelProjection->SetTitle("Amplitude Spectrum of one Pixels");
    100171        hPixelProjection->SetAxisRange(0, 40, "X");
     
    105176
    106177        total->SetLineColor(2);
    107         cGainFit->cd(2);
     178        cGainFit->cd(3);
    108179        gPad->SetLogy(1);
    109180        hPixelProjection->SetYTitle("Counts");
     
    126197//-----------------------------------------------------------------------------
    127198
    128 //        total->GetParameters(proj_of_pixel[ pixel ].fitParameters);
    129         proj_of_pixel[ pixel ].PID = pixel+1;
    130 
    131 
    132 //        proj_of_pixel[ pixel ].tripple_peakSigm = total->GetParameter(8);
    133 //        proj_of_pixel[ pixel ].ampl = total->GetParameter(1) - total->GetParameter(4);
     199//        total->GetParameters(channel[ pixel ].fitParameters);
     200        channel[ pixel ].PID = pixel+1;
     201
     202
     203//        channel[ pixel ].tripple_peakSigm = total->GetParameter(8);
     204//        channel[ pixel ].ampl = total->GetParameter(1) - total->GetParameter(4);
    134205
    135206//-----------------------------------------------------------------------------
    136207// Draw Histograms
    137208//-----------------------------------------------------------------------------
    138 
    139         cGainFit->cd(3);
    140         gPad->SetLogy(1);
    141         g4->SetLineColor(2);
    142         hAmplDistribution->SetXTitle("Amplification [mV]");
    143         hAmplDistribution->SetYTitle("Counts");
    144         hAmplDistribution->SetAxisRange(7.5, 12.5, "X");
    145         proj_of_pixel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1);
    146         hAmplDistribution->Fill( proj_of_pixel[ pixel ].amplSD ) ;
    147         hAmplDistribution->Fit(g4);
    148209
    149210        cGainFit->cd(4);
    150211        gPad->SetLogy(1);
    151212        g4->SetLineColor(2);
    152         hAmplDistribution2->SetXTitle("Amplification [mV]");
    153         hAmplDistribution2->SetYTitle("Counts");
    154         hAmplDistribution2->SetAxisRange(7.5, 12.5, "X");
    155         proj_of_pixel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4);
    156         hAmplDistribution2->Fill(proj_of_pixel[ pixel ].amplDT) ;
     213        channel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1);
     214        hAmplDistribution->Fill( channel[ pixel ].amplSD ) ;
     215        hAmplDistribution->Fit(g4);
     216
     217        cGainFit->cd(5);
     218        gPad->SetLogy(1);
     219        g4->SetLineColor(2);
     220        channel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4);
     221        hAmplDistribution2->Fill(channel[ pixel ].amplDT) ;
    157222        hAmplDistribution2->Fit(g4);
    158223
     224        cGainFit->cd(6);
     225        hAmplVsChannel->SetBinContent(pixel, channel[ pixel ].amplSD);
     226
     227        gr1->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplSD);
     228        gr2->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplDT);
     229
     230
    159231    if( showHistos ){
    160         cGainFit->cd(3);
     232        if (pixel%40==0){
     233        cGainFit->cd(4);
    161234        hAmplDistribution->Draw();
    162         cGainFit->cd(4);
     235        cGainFit->cd(5);
    163236        hAmplDistribution2->Draw();
     237        }
     238
     239        cGainFit->cd(6);
     240        hAmplVsChannel->Draw();
     241        if (pixel%60==0){
     242          cGraphs->cd(2);
     243          mg->Draw("APL");
     244          cGraphs->cd(1);
     245          gr1->Draw("APL");
     246        }
     247
    164248        cGainFit->Modified();
    165249        cGainFit->Update();
     250        cGraphs->Modified();
     251        cGraphs->Update();
    166252    }
    167253        if(debug){
     
    180266//-----------------------------------------------------------------------------
    181267
    182     cGainFit->cd(2);
     268    cGainFit->cd(3);
    183269    hPixelProjection->Draw();
    184270    hPixelProjection->Fit(total,"R+");
    185271
    186     cGainFit->cd(3);
     272    cGainFit->cd(4);
    187273    hAmplDistribution->Draw();
    188274
    189     cGainFit->cd(4);
     275    cGainFit->cd(5);
    190276    hAmplDistribution2->Draw();
     277
     278    cGainFit->cd(6);
     279    hAmplVsChannel->Draw();
    191280
    192281    cGainFit->Modified();
    193282    cGainFit->Update();
     283
     284    cGraphs->cd(2);
     285    mg->Draw("APL");
     286    cGraphs->cd(1);
     287    gr1->Draw("APL");
     288    cGraphs->Modified();
     289    cGraphs->Update();
    194290
    195291//-----------------------------------------------------------------------------
     
    220316    out << "# PixelID : gain between Single and Double Peak : gain between Double and Tripple Peak " << endl;
    221317    out << "# gain is derived from the parameters of a three gaussian fit function " << endl;
    222     for (int pixel=0; pixel<1440; pixel++){
    223             out << proj_of_pixel[ pixel ].PID << ";\t"    ;
    224             out << proj_of_pixel[ pixel ].amplSD << ";\t" ;
    225             out << proj_of_pixel[ pixel ].amplDT << ";\t" ;
     318    for (UInt_t pixel=0; pixel<NumberOfPixels; pixel++){
     319            out << channel[ pixel ].PID << ";\t"    ;
     320            out << channel[ pixel ].amplSD << ";\t" ;
     321            out << channel[ pixel ].amplDT << ";\t" ;
    226322            out << filename << endl;
    227323
    228324    }
    229325    out.close();
    230 
     326SaveHistograms( RootOutFileName );
    231327return( 0 );
    232328}
     329
     330//-----------------------------------------------------------------------------
     331// End of Main
     332//-----------------------------------------------------------------------------
     333
     334
     335
     336
     337//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     338//+                                                                           +
     339//+                     Function definitions                                  +
     340//+                                                                           +
     341//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     342
     343
     344
     345//-----------------------------------------------------------------------------
     346// Function: Book Histograms
     347//-----------------------------------------------------------------------------
     348
     349void BookHistos(){
     350
     351  //Amplification Distribution - Single2Double
     352  hAmplDistribution = new TH1F("hAmplDistribution","Distribution of G-APD Amplification (1+2)", 500, 0 , 20 );
     353  hAmplDistribution->SetXTitle("Amplification [mV]");
     354  hAmplDistribution->SetYTitle("Counts");
     355  hAmplDistribution->SetAxisRange(7.5, 12.5, "X");
     356  hList.Add( hAmplDistribution );
     357
     358  //Amplification Distribution2 - Double2Tripple
     359  hAmplDistribution2 = new TH1F("hAmplDistribution2","Distribution of G-APD Amplification(2+3)", 500, 0 , 20 );
     360  hAmplDistribution2->SetXTitle("Amplification [mV]");
     361  hAmplDistribution2->SetYTitle("Counts");
     362  hAmplDistribution2->SetAxisRange(7.5, 12.5, "X");
     363  hList.Add( hAmplDistribution2 );
     364
     365  //Amplification vs Channels
     366  hAmplVsChannel = new TH1F("hAmplVsChannel","Amplifications (SD) of each Channel", 1440, -0.5 , 1439.5 );
     367  hAmplVsChannel->SetYTitle("Amplification [mV]");
     368  hAmplVsChannel->SetXTitle("Channels");
     369  hAmplVsChannel->SetLineColor(2);
     370  hList.Add( hAmplVsChannel );
     371}
     372
     373//-----------------------------------------------------------------------------
     374// Save Histograms
     375//-----------------------------------------------------------------------------
     376
     377void SaveHistograms( const char * loc_fname){
     378    // create the histogram file (replace if already existing)
     379    TFile tf( loc_fname, "RECREATE");
     380
     381    hList.Write(); // write the major histograms into the top level directory
     382    tf.mkdir("PeakSpektra"); tf.cd("PeakSpektra"); // go to new subdirectory
     383    hListPeakSpektra.Write(); // write histos into subdirectory
     384
     385    tf.Close(); // close the file
     386}
     387
     388//-----------------------------------------------------------------------------
     389// MulitOrder MultiGauß Function
     390//-----------------------------------------------------------------------------
     391
     392/*
     393Double_t spek_fit(Double_t *x, Double_t *par, Uint_t *maxorder)
     394        {
     395                Double_t exp = 0;
     396
     397                //Double_t arg2 = 0;
     398                //if (par[2] != 0) arg = (v[0] - par[1])/par[2];
     399                //if (par[5] != 0) arg2 = (v[0] - par[4])/par[5];
     400
     401                //Double_t fitval = par[0]*TMath::Exp(-0.5*arg*arg) + par[3]*TMath::Exp(-0.5*arg2*arg2);
     402
     403                for(int order = 0; order < maxorder; order++){
     404                peak[order]=par[0]*par[4]/(order+1)*((x[0]-(order+1)*par[1])*(x[0]-(order+1)*par[1]))/(par[2]*par[2]);
     405                            exp = exp + peak[order];
     406                          }
     407
     408                Double_t fitval = TMath::Exp(-0.5*exp);
     409                return fitval;
     410        }
     411*/
     412
Note: See TracChangeset for help on using the changeset viewer.