Changeset 12712


Ignore:
Timestamp:
12/08/11 00:28:06 (13 years ago)
Author:
Jens Buss
Message:
added differnt typee of fit function to see which fits best; detect pixel with not normal gain
File:
1 edited

Legend:

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

    r12690 r12712  
    2727  UInt_t PID;
    2828  vector<float> fitParameters[9];
    29   float amplSD;
    30   float amplDT;
    31   float amplMean;
     29  Double_t amplSD;
     30  Double_t amplDT;
     31  Double_t amplMean;
     32  Double_t ampl_fspek_fit;
     33  bool crazy;
    3234  } proj;
    3335vector<proj> channel;
    3436
     37typedef struct{
     38  Double_t constant;
     39  Double_t mean;
     40  Double_t sigma;
     41} dist_t;
     42dist_t distribution;
    3543
    3644//-----------------------------------------------------------------------------
     
    4149TH1F *hAmplDistribution = NULL;
    4250TH1F *hAmplDistribution2 = NULL;
    43 TH1F *hAmplVsChannel = NULL;
    44 
    45 //Lists of Histograms taht are to be saved
     51TH1F *hPixelGainFit = NULL;
     52
     53//Lists of Histograms that have to be saved
    4654TObjArray hList;
    4755TObjArray hListPeakSpektra;
    4856
    49 
    5057//-----------------------------------------------------------------------------
    5158// Functions
    5259//-----------------------------------------------------------------------------
     60Double_t spek_fit(Double_t *, Double_t *);
     61Double_t spek_fit2(Double_t *, Double_t *);
    5362
    5463void BookHistos();
    5564void SaveHistograms(const char * );
    56 //Double_t spek_fit(Double_t *x, Double_t *par)
    57 
     65bool SearchAnormal(UInt_t, Double_t );
    5866
    5967//-----------------------------------------------------------------------------
     
    7987    TFile * file = TFile::Open( InputRootFileName );
    8088
    81 
    82     TH1D *hPixelProjection = NULL;
    8389//Baseline
    8490    TH2F * hbaseline = (TH2F*)baseline->Get("histo_mean");
    8591//Amplitude spectrum
    86     TH2F *h = (TH2F*)file->Get("hAmplSpek_cfd");
    87    
     92    TH2F *hAmplSpek = (TH2F*)file->Get("hAmplSpek_cfd");
     93    NumberOfPixels = hAmplSpek->GetNbinsX();
     94    channel.resize(hAmplSpek->GetNbinsX());
     95
     96//Amplitude Spectrum of a Pixel
     97    TH1D* hPixelAmplSpek[1440]; ///++++ TODO: Warning hardcoded pixelnumber, change that +++
     98
     99//Book Histograms
    88100    BookHistos();
    89101
     102//Define Fit Functions
    90103    Double_t par[9];
    91104    TF1 *g1    = new TF1("g1","gaus",5,15);
     
    94107    TF1 *g4    = new TF1("g4","gaus");
    95108    TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",7,32);
    96 
    97 
     109    TF1 *fspek_fit = new TF1("fspek_fit", spek_fit, 5, 60, 5);
     110    TF1 *fspek_fit2 = new TF1("fspek_fit2", spek_fit2, 5, 60, 5);
     111
     112//Create Canvases
    98113    TCanvas *cGainFit = new TCanvas("cGainFit", "Fit of Amplitude Spektra", 0,0, 1200,400);
    99114    cGainFit->Clear();
    100115    cGainFit->Divide(3, 2);
    101116
    102     TCanvas *cGraphs = new TCanvas("cGraphs", "Horst", 0,401, 1200,400);
     117    TCanvas *cGraphs = new TCanvas("cGraphs", "gain vs. channel", 0,401, 1200,400);
    103118    cGraphs->Clear();
    104119    cGraphs->Divide(1, 2);
    105120
     121//Draw imported Histograms
    106122    cGainFit->cd(1);
    107123    gStyle->SetPalette(1,0);
    108124    gROOT->SetStyle("Plain");
    109     h->SetTitle("Amplitude Spectrum of all Pixels");
    110     h->SetAxisRange(0, 100, "Y");
    111     h->Draw("COLZ");
    112     channel.resize(h->GetNbinsX());
    113     NumberOfPixels = h->GetNbinsX();
     125    hAmplSpek->SetTitle("Amplitude Spectrum of all Pixels");
     126    hAmplSpek->SetAxisRange(0, 100, "Y");
     127    hAmplSpek->Draw("COLZ");
     128
    114129
    115130    cGainFit->cd(2);
     
    146161    mg->Add(gr2);
    147162
    148 
    149 
    150 
    151163//-----------------------------------------------------------------------------
    152164// Loop over all Pixels and fit Distribution of singles, doubles and tripples
     
    158170
    159171        //Title
    160         TString pixelnumber;
    161         pixelnumber += "hPixelProj";
    162         pixelnumber += "_";
    163         pixelnumber += pixel + 1 ;
     172         TString histotitle;
     173         histotitle += "hPixelPro_";
     174         histotitle += pixel + 1 ;
    164175
    165176        cout << "-----------------------------------------------------------" << endl;
    166177        cout << " PID: " << pixel+1 << endl;
    167178        cout << "-----------------------------------------------------------" << endl;
    168        
    169         hPixelProjection = h->ProjectionY( pixelnumber , pixel+1, pixel+1);      //Projectipon of each Pixel out of Ampl.Spectrum
    170         hPixelProjection->SetTitle("Amplitude Spectrum of one Pixels");
    171         hPixelProjection->SetAxisRange(0, 40, "X");
     179  //Amplitude Spectrum of a Pixel
     180        hPixelAmplSpek[ pixel ] = new TH1D;
     181        hPixelAmplSpek[ pixel ] = hAmplSpek->ProjectionY( histotitle , pixel+1, pixel+1);        //Projectipon of each Pixel out of Ampl.Spectrum
     182        hPixelAmplSpek[ pixel ]->SetAxisRange(0, 40, "X");
     183
     184        histotitle = "Amplitude Spectrum of Pixel #";
     185        histotitle += pixel + 1 ;
     186
     187        hPixelAmplSpek[ pixel ]->SetTitle(histotitle);
     188        hPixelAmplSpek[ pixel ]->SetYTitle("Counts [a.u.]");
     189        hListPeakSpektra.Add(hPixelAmplSpek[ pixel ]);
     190
    172191
    173192//-----------------------------------------------------------------------------
     
    176195
    177196        total->SetLineColor(2);
     197        fspek_fit->SetLineColor(3);
     198        fspek_fit2->SetLineColor(kBlue);
     199        fspek_fit2->SetLineStyle(2);
     200
    178201        cGainFit->cd(3);
    179202        gPad->SetLogy(1);
    180         hPixelProjection->SetYTitle("Counts");
    181         hPixelProjection->Fit(g1,"R");
    182         hPixelProjection->Fit(g2,"R+");
    183         hPixelProjection->Fit(g3,"R+");
     203
     204        hPixelAmplSpek[ pixel ]->Fit(g1,"R");
     205        hPixelAmplSpek[ pixel ]->Fit(g2,"R+");
     206        hPixelAmplSpek[ pixel ]->Fit(g3,"R+");
    184207        g1->GetParameters(&par[0]);
    185208        g2->GetParameters(&par[3]);
    186209        g3->GetParameters(&par[6]);
     210
     211        fspek_fit->SetParameters(par);
     212        fspek_fit2->SetParameters(par);
    187213        total->SetParameters(par);
     214        hPixelAmplSpek[ pixel ]->Fit(total,"R+");
     215        hPixelAmplSpek[ pixel ]->Fit(fspek_fit,"R+");
     216        hPixelAmplSpek[ pixel ]->Fit(fspek_fit2,"R+");
     217
    188218        if( showHistos ){
    189         hPixelProjection->Draw();
    190         hPixelProjection->Fit(total,"R+");
     219        hPixelAmplSpek[ pixel ]->Draw();
    191220        }
    192221
    193         //TODO: Logarithmic Scale
     222
    194223
    195224//-----------------------------------------------------------------------------
     
    199228//        total->GetParameters(channel[ pixel ].fitParameters);
    200229        channel[ pixel ].PID = pixel+1;
    201 
     230        channel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1);
     231        channel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4);
     232        channel[ pixel ].amplMean = fspek_fit->GetParameter(1);
     233        channel[ pixel ].ampl_fspek_fit = fspek_fit->GetParameter(1);
    202234
    203235//        channel[ pixel ].tripple_peakSigm = total->GetParameter(8);
     
    211243        gPad->SetLogy(1);
    212244        g4->SetLineColor(2);
    213         channel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1);
    214245        hAmplDistribution->Fill( channel[ pixel ].amplSD ) ;
    215246        hAmplDistribution->Fit(g4);
     247        distribution.sigma = g4->GetParameter(2);
     248        distribution.mean = g4->GetParameter(1);
     249        distribution.constant = g4->GetParameter(0);
    216250
    217251        cGainFit->cd(5);
    218252        gPad->SetLogy(1);
    219253        g4->SetLineColor(2);
    220         channel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4);
    221         hAmplDistribution2->Fill(channel[ pixel ].amplDT) ;
     254        hAmplDistribution2->Fill(channel[ pixel ].amplMean) ;
    222255        hAmplDistribution2->Fit(g4);
    223256
    224257        cGainFit->cd(6);
    225         hAmplVsChannel->SetBinContent(pixel, channel[ pixel ].amplSD);
     258        hPixelGainFit->SetBinContent(pixel, channel[ pixel ].amplSD);
     259
     260        if( showHistos ){
     261            if (pixel%40==0){
     262            cGainFit->cd(4);
     263            hAmplDistribution->Draw();
     264            cGainFit->cd(5);
     265            hAmplDistribution2->Draw();
     266            }
     267
     268            cGainFit->cd(6);
     269            hPixelGainFit->Draw();
     270          }
     271
     272//-----------------------------------------------------------------------------
     273// Draw Graphs of Distributions
     274//-----------------------------------------------------------------------------
    226275
    227276        gr1->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplSD);
    228         gr2->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplDT);
     277        gr2->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplMean);
    229278
    230279
    231280    if( showHistos ){
    232         if (pixel%40==0){
    233         cGainFit->cd(4);
    234         hAmplDistribution->Draw();
    235         cGainFit->cd(5);
    236         hAmplDistribution2->Draw();
    237         }
    238 
    239         cGainFit->cd(6);
    240         hAmplVsChannel->Draw();
    241281        if (pixel%60==0){
    242282          cGraphs->cd(2);
    243           mg->Draw("APL");
     283          gr2->Draw("APL");
    244284          cGraphs->cd(1);
    245285          gr1->Draw("APL");
     
    251291        cGraphs->Update();
    252292    }
     293
     294    //-----------------------------------------------------------------------------
     295    // Debug Modus
     296    //-----------------------------------------------------------------------------
    253297        if(debug){
    254298
     
    266310//-----------------------------------------------------------------------------
    267311
    268     cGainFit->cd(3);
    269     hPixelProjection->Draw();
    270     hPixelProjection->Fit(total,"R+");
     312
     313//   ( cGainFit->cd(3);
     314//    hPixelAmplSpek[ NumberOfPixels ]->Draw();
    271315
    272316    cGainFit->cd(4);
     
    277321
    278322    cGainFit->cd(6);
    279     hAmplVsChannel->Draw();
     323    hPixelGainFit->Draw();
    280324
    281325    cGainFit->Modified();
     
    283327
    284328    cGraphs->cd(2);
    285     mg->Draw("APL");
     329    gr2->Draw("APL");
    286330    cGraphs->cd(1);
    287331    gr1->Draw("APL");
     
    320364            out << channel[ pixel ].amplSD << ";\t" ;
    321365            out << channel[ pixel ].amplDT << ";\t" ;
     366            out << channel[ pixel ].ampl_fspek_fit << "\t" ;
     367
     368            channel[ pixel ].crazy = SearchAnormal(pixel, 4);  //check if pixel had a strange gain
     369            out << channel[ pixel ].crazy << "\t" ;
     370
    322371            out << filename << endl;
    323372
     
    364413
    365414  //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 );
     415  hPixelGainFit = new TH1F("hPixelGainFit","Amplifications (SD) of each Channel", 1440, -0.5 , 1439.5 );
     416  hPixelGainFit->SetYTitle("Amplification [mV]");
     417  hPixelGainFit->SetXTitle("Channels");
     418  hPixelGainFit->SetLineColor(2);
     419  hList.Add( hPixelGainFit );
     420
    371421}
    372422
     
    389439// MulitOrder MultiGauß Function
    390440//-----------------------------------------------------------------------------
     441
     442Double_t spek_fit(Double_t *x, Double_t *par){
     443
     444  Double_t arg = 0;
     445  Double_t arg2 = 0;
     446  Double_t arg3 = 0;
     447  Double_t arg4 = 0;
     448  Double_t cross = 1;
     449  if (par[0] != 0) cross = par[4]/par[0];
     450  if (par[2] != 0) arg = (x[0] - par[1])/par[2];
     451  if (par[2] != 0) arg2 = (x[0] - 2*par[1])/par[2];
     452  if (par[2] != 0) arg3 = (x[0] - 3*par[1])/par[2];
     453  if (par[2] != 0) arg4 = (x[0] - 4*par[1])/par[2];
     454  cross = par[4]/par[0];
     455  Double_t peak1 = par[0]*TMath::Exp(-0.5 * arg * arg);
     456  Double_t peak2 = cross*par[0]*TMath::Exp(-0.5 * arg2 * arg2 /2);
     457  Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3);
     458  Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4);
     459  //Double_t decayoverlay = TMath::Exp(-x[0]);
     460  return peak1 + peak2 + peak3 + peak4;
     461}
     462
     463Double_t spek_fit2(Double_t *x, Double_t *par){
     464
     465  Double_t arg = 0;
     466  Double_t arg2 = 0;
     467  Double_t arg3 = 0;
     468  Double_t arg4 = 0;
     469  Double_t cross = 1;
     470  if (par[0] != 0) cross = par[4]/par[0];
     471  if (par[2] != 0) arg = (x[0] - par[1])/par[2];
     472  if (par[2] != 0) arg2 = (x[0] - 2*par[1])/par[2];
     473  if (par[2] != 0) arg3 = (x[0] - 3*par[1])/par[2];
     474  if (par[2] != 0) arg4 = (x[0] - 4*par[1])/par[2];
     475  cross = par[4]/par[0];
     476  Double_t peak1 = par[0]*TMath::Exp(-0.5 * arg * arg);
     477  Double_t peak2 = cross*par[0]*TMath::Exp(-0.5 * arg2 * arg2 /2);
     478  Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3);
     479  Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4);
     480  Double_t decayoverlay =  TMath::Exp(-x[0]*TMath::Log(1.0001));
     481  return peak1 + peak2 + peak3 + peak4 + decayoverlay;
     482}
     483
     484bool SearchAnormal(UInt_t pixel, Double_t distance){  //// MACHT ALLES KEINEN SINN WENN MAN KEINE BETRÄGE BETRACHTET
     485  Double_t check = channel[ pixel ].ampl_fspek_fit;
     486  check = TMath::Sqrt(check*check);
     487  if (check < (distance * distribution.sigma + distribution.mean)){
     488    return false;
     489    }
     490  else{
     491    cout << "Not normal behaviotruer in Pixel: " << pixel +1 << endl;
     492    return true;
     493  }
     494}
     495
     496/*
     497
     498
     499
     500
     501
     502
     503  */
     504
    391505
    392506/*
     
    410524        }
    411525*/
    412 
Note: See TracChangeset for help on using the changeset viewer.