Changeset 12713


Ignore:
Timestamp:
12/09/11 18:32:03 (13 years ago)
Author:
Jens Buss
Message:
 histos of pixels with to high gain in seperate folder, comments, fit functions improved  
File:
1 edited

Legend:

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

    r12712 r12713  
     1//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     2//+   Root Macro: GainFit2 for FACT                                           +
     3//+---------------------------------------------------------------------------+
     4//+   by: jens.buss@tu-dortmund.de                                            +
     5//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     6//
     7//  - analyse gain of pixels from Dark-Count-Photon-Spektrum (pedestal on)
     8//  - read a root-file produced by "fpeak.C" and get Amplitudespektrum
     9//    of all pixel
     10//  - read a root-file produced by "fbsl.C" and get baseline
     11//  - calculate pixelgain from multi-gaussian-fit
     12//    over each pixels amplitudespektrum
     13//  - draw distribution of gains
     14//  - draw gain vs. pixel
     15//  - find Pixels with deviating gainvalue (e.g. dead , crazy Pixels)
     16//    and write their number to log-file (e.g. date_run_gainfit.txt)
     17//  - save histograms into root-file (e.g. date_run_gainfit.root)
     18//
     19//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     20
    121#include <TFile.h>
    222#include <TH2F.h>
     
    2949  Double_t amplSD;
    3050  Double_t amplDT;
    31   Double_t amplMean;
     51  Double_t cross;
    3252  Double_t ampl_fspek_fit;
     53  Double_t ampl_fspek_fit2;
     54  Double_t bsl;
    3355  bool crazy;
    3456  } proj;
     
    4264dist_t distribution;
    4365
     66//Verbosity for Histograms
     67TString verbos[3]={"Q","", ""};
    4468//-----------------------------------------------------------------------------
    4569// Decleration of Histograms
     
    4973TH1F *hAmplDistribution = NULL;
    5074TH1F *hAmplDistribution2 = NULL;
    51 TH1F *hPixelGainFit = NULL;
     75TH1F *hGainFitBsl = NULL;
    5276
    5377//Lists of Histograms that have to be saved
    5478TObjArray hList;
    5579TObjArray hListPeakSpektra;
     80TObjArray hListCrazy;
    5681
    5782//-----------------------------------------------------------------------------
     
    6388void BookHistos();
    6489void SaveHistograms(const char * );
    65 bool SearchAnormal(UInt_t, Double_t );
     90bool SearchAnormal(UInt_t, Double_t, int verbosityLevel );
    6691
    6792//-----------------------------------------------------------------------------
     
    7398        const char * InputRootFileName = "../analysis/fpeak/20111109_006/20111109_006_fpeak.root",
    7499        const char * InputBaselineFileName = "../analysis/fpeak/20111109_006/20111109_006_fbsl.root",
    75         const char * OutTextFileName = "../analysis/fpeak/20111109_006_gainfit_test.txt",
    76         const char * RootOutFileName = "../analysis/fpeak/20111109_006_gainfit_test.root",
     100        const char * OutTextFileName = "../analysis/fpeak/20111109_006/20111109_006_gainfit.txt",
     101        const char * RootOutFileName = "../analysis/fpeak/20111109_006/20111109_006_gainfit.root",
    77102        bool showHistos = false,
    78         bool debug = false)
     103        bool debug = false,
     104        int verbosityLevel = 3)
    79105{
    80106
     
    106132    TF1 *g3    = new TF1("g3","gaus",25,35);
    107133    TF1 *g4    = new TF1("g4","gaus");
    108     TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",7,32);
     134    //TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",7,60);
    109135    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);
     136    TF1 *fspek_fit2 = new TF1("fspek_fit2", spek_fit2, 5, 60, 4);
    111137
    112138//Create Canvases
     
    128154
    129155
    130     cGainFit->cd(2);
     156    cGainFit->cd(3);
    131157    hbaseline->SetTitle("Baselinedistribution of all Pixels");
    132     hbaseline->SetAxisRange(-5, 5, "X");
    133     //hbaseline->SetAxisRange(0, 100, "Y");
    134     hbaseline->Fit("gaus");
     158    Double_t Xrange = hbaseline->GetMean(1);
     159    hbaseline->SetAxisRange(Xrange-1.5, Xrange + 1.5, "X");
     160    hbaseline->SetAxisRange(0, (hbaseline->GetBinContent(hbaseline->GetMaximumBin())+300), "Y");
    135161    hbaseline->Draw();
    136162
     
    154180    gr2->SetMarkerStyle(2);
    155181    gr1->SetMarkerColor(kRed);
    156     gr2->SetMarkerColor(kBlack);
     182    gr2->SetMarkerColor(kBlue);
    157183    gr1->SetMarkerSize(0.5);
    158184    gr2->SetMarkerSize(0.5);
     185    gr1->SetTitle("G-APD Amplification vs. Channel (with Baseline Parameter)");
     186    gr2->SetTitle("G-APD Amplification vs. Channel (without Baseline Parameter)");
    159187    TMultiGraph *mg = new TMultiGraph();
    160188    mg->Add(gr1);
     
    165193//-----------------------------------------------------------------------------
    166194
    167     cout << "Number of Pixels: " << NumberOfPixels << endl;
     195    if (verbosityLevel > 1) cout << "Number of Pixels: " << NumberOfPixels << endl;
    168196    // Begin of Loop
    169197    for (UInt_t pixel = 0; pixel < NumberOfPixels; pixel++){
    170198
    171         //Title
     199      channel[ pixel ].PID = pixel+0;
     200
     201    //Title
    172202         TString histotitle;
    173203         histotitle += "hPixelPro_";
    174          histotitle += pixel + 1 ;
    175 
     204         histotitle += pixel+0 ;
     205
     206      if (verbosityLevel > 1){
    176207        cout << "-----------------------------------------------------------" << endl;
    177         cout << " PID: " << pixel+1 << endl;
     208        cout << " PID: " << pixel+0 << endl;
    178209        cout << "-----------------------------------------------------------" << endl;
     210      }
    179211  //Amplitude Spectrum of a Pixel
    180212        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");
     213        hPixelAmplSpek[ pixel ] = hAmplSpek->ProjectionY( histotitle , pixel+0, pixel+0);        //Projectipon of each Pixel out of Ampl.Spectrum
     214        hPixelAmplSpek[ pixel ]->SetAxisRange(0, 60, "X");
    183215
    184216        histotitle = "Amplitude Spectrum of Pixel #";
    185         histotitle += pixel + 1 ;
     217        histotitle += pixel+0 ;
    186218
    187219        hPixelAmplSpek[ pixel ]->SetTitle(histotitle);
     
    194226//-----------------------------------------------------------------------------
    195227
    196         total->SetLineColor(2);
    197         fspek_fit->SetLineColor(3);
     228        //total->SetLineColor(2);
     229        fspek_fit->SetLineColor(kRed);
    198230        fspek_fit2->SetLineColor(kBlue);
    199231        fspek_fit2->SetLineStyle(2);
    200232
    201         cGainFit->cd(3);
     233        cGainFit->cd(4);
    202234        gPad->SetLogy(1);
    203235
    204         hPixelAmplSpek[ pixel ]->Fit(g1,"R");
    205         hPixelAmplSpek[ pixel ]->Fit(g2,"R+");
    206         hPixelAmplSpek[ pixel ]->Fit(g3,"R+");
     236        hPixelAmplSpek[ pixel ]->Fit(g1,verbos[verbosityLevel-1]+"R");
     237        hPixelAmplSpek[ pixel ]->Fit(g2,verbos[verbosityLevel-1]+"0R+");
     238        hPixelAmplSpek[ pixel ]->Fit(g3,verbos[verbosityLevel-1]+"0R+");
    207239        g1->GetParameters(&par[0]);
    208240        g2->GetParameters(&par[3]);
    209241        g3->GetParameters(&par[6]);
    210242
     243        //total->SetParameters(par);
     244
     245        //hPixelAmplSpek[ pixel ]->Fit(total,verbos[verbosityLevel-1]+"R+");
     246        //channel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1);
     247        //channel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4);
     248        //channel[ pixel ].amplMean = fspek_fit->GetParameter(1);
     249
     250        par[4] = -1;
    211251        fspek_fit->SetParameters(par);
     252        cout << "spek_fit" << endl;
     253        hPixelAmplSpek[ pixel ]->Fit(fspek_fit,verbos[verbosityLevel-1]+"R+");
     254        channel[ pixel ].ampl_fspek_fit = fspek_fit->GetParameter(1);
     255        channel[ pixel ].bsl = fspek_fit->GetParameter(4);
     256        cout << "Baseline:" << channel[ pixel ].bsl << endl;
     257
    212258        fspek_fit2->SetParameters(par);
    213         total->SetParameters(par);
    214         hPixelAmplSpek[ pixel ]->Fit(total,"R+");
    215         hPixelAmplSpek[ pixel ]->Fit(fspek_fit,"R+");
    216         hPixelAmplSpek[ pixel ]->Fit(fspek_fit2,"R+");
    217 
     259        cout << "fspek_fit2" << endl;
     260        hPixelAmplSpek[ pixel ]->Fit(fspek_fit2,verbos[verbosityLevel-1]+"R+");
     261        channel[ pixel ].ampl_fspek_fit2 = fspek_fit2->GetParameter(1);
     262       
    218263        if( showHistos ){
    219264        hPixelAmplSpek[ pixel ]->Draw();
     
    222267
    223268
    224 //-----------------------------------------------------------------------------
    225 // Save Parameters into vetor
    226 //-----------------------------------------------------------------------------
    227 
    228 //        total->GetParameters(channel[ pixel ].fitParameters);
    229         channel[ pixel ].PID = pixel+1;
    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);
    234 
    235 //        channel[ pixel ].tripple_peakSigm = total->GetParameter(8);
    236 //        channel[ pixel ].ampl = total->GetParameter(1) - total->GetParameter(4);
     269
     270
    237271
    238272//-----------------------------------------------------------------------------
     
    240274//-----------------------------------------------------------------------------
    241275
    242         cGainFit->cd(4);
     276        cGainFit->cd(2);
    243277        gPad->SetLogy(1);
    244278        g4->SetLineColor(2);
    245         hAmplDistribution->Fill( channel[ pixel ].amplSD ) ;
    246         hAmplDistribution->Fit(g4);
     279        hAmplDistribution->Fill( channel[ pixel ].ampl_fspek_fit ) ;
     280        hAmplDistribution->Fit(g4, verbos[verbosityLevel-1]);
    247281        distribution.sigma = g4->GetParameter(2);
    248282        distribution.mean = g4->GetParameter(1);
     
    251285        cGainFit->cd(5);
    252286        gPad->SetLogy(1);
    253         g4->SetLineColor(2);
    254         hAmplDistribution2->Fill(channel[ pixel ].amplMean) ;
    255         hAmplDistribution2->Fit(g4);
    256 
    257         cGainFit->cd(6);
    258         hPixelGainFit->SetBinContent(pixel, channel[ pixel ].amplSD);
    259 
     287        g4->SetLineColor(kBlue);
     288        hAmplDistribution2->Fill(channel[ pixel ].ampl_fspek_fit2) ;
     289        hAmplDistribution2->Fit(g4, verbos[verbosityLevel-1]);
     290
     291        cGainFit->cd(3);
     292        hGainFitBsl->Fill(channel[ pixel ].bsl);
     293        hGainFitBsl->Draw("same");
    260294        if( showHistos ){
    261295            if (pixel%40==0){
    262             cGainFit->cd(4);
     296            cGainFit->cd(2);
    263297            hAmplDistribution->Draw();
    264298            cGainFit->cd(5);
     
    267301
    268302            cGainFit->cd(6);
    269             hPixelGainFit->Draw();
     303            hGainFitBsl->Draw();
    270304          }
    271305
     
    274308//-----------------------------------------------------------------------------
    275309
    276         gr1->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplSD);
    277         gr2->SetPoint(pixel, channel[pixel].PID, channel[pixel].amplMean);
     310        gr1->SetPoint(pixel, channel[pixel].PID, channel[pixel].ampl_fspek_fit);
     311        gr2->SetPoint(pixel, channel[pixel].PID, channel[pixel].ampl_fspek_fit2);
    278312
    279313
    280314    if( showHistos ){
    281315        if (pixel%60==0){
     316          cGraphs->cd(1);
     317          gr2->Draw("APL");
    282318          cGraphs->cd(2);
    283           gr2->Draw("APL");
    284           cGraphs->cd(1);
    285319          gr1->Draw("APL");
    286320        }
     
    311345
    312346
    313 //   ( cGainFit->cd(3);
     347//   ( cGainFit->cd(4);
    314348//    hPixelAmplSpek[ NumberOfPixels ]->Draw();
    315349
    316     cGainFit->cd(4);
     350    cGainFit->cd(2);
    317351    hAmplDistribution->Draw();
    318352
     
    321355
    322356    cGainFit->cd(6);
    323     hPixelGainFit->Draw();
     357    hGainFitBsl->Draw();
     358    hbaseline->Draw("same");
    324359
    325360    cGainFit->Modified();
    326361    cGainFit->Update();
    327362
     363    cGraphs->cd(1);
     364    gr2->Draw("APL");
    328365    cGraphs->cd(2);
    329     gr2->Draw("APL");
    330     cGraphs->cd(1);
    331366    gr1->Draw("APL");
    332367    cGraphs->Modified();
     
    351386                    ++it;
    352387    }
    353     cout << filename << endl;
     388if (verbosityLevel > 0)    cout << filename << endl;
    354389
    355390    ofstream out;
     
    362397    for (UInt_t pixel=0; pixel<NumberOfPixels; pixel++){
    363398            out << channel[ pixel ].PID << ";\t"    ;
    364             out << channel[ pixel ].amplSD << ";\t" ;
    365             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
     399            out << channel[ pixel ].ampl_fspek_fit << ";\t" ;
     400           // out << channel[ pixel ].amplDT << ";\t" ;
     401            out << channel[ pixel ].ampl_fspek_fit2 << "\t" ;
     402
     403    //check if pixel gain is compareable to gain of the others and save result to logfile
     404            channel[ pixel ].crazy = SearchAnormal(pixel, 4, verbosityLevel);
     405            if (channel[ pixel ].crazy) hListCrazy.Add(hPixelAmplSpek[ pixel ]);
    369406            out << channel[ pixel ].crazy << "\t" ;
    370407
     
    399436
    400437  //Amplification Distribution - Single2Double
    401   hAmplDistribution = new TH1F("hAmplDistribution","Distribution of G-APD Amplification (1+2)", 500, 0 , 20 );
     438  hAmplDistribution = new TH1F("hAmplDistribution","Distribution of G-APD Amplification (with Baseline Parameter)", 500, 0 , 20 );
    402439  hAmplDistribution->SetXTitle("Amplification [mV]");
    403440  hAmplDistribution->SetYTitle("Counts");
     
    406443
    407444  //Amplification Distribution2 - Double2Tripple
    408   hAmplDistribution2 = new TH1F("hAmplDistribution2","Distribution of G-APD Amplification(2+3)", 500, 0 , 20 );
     445  hAmplDistribution2 = new TH1F("hAmplDistribution2","Distribution of G-APD Amplification(without Baseline Parameter)", 500, 0 , 20 );
    409446  hAmplDistribution2->SetXTitle("Amplification [mV]");
    410447  hAmplDistribution2->SetYTitle("Counts");
     
    412449  hList.Add( hAmplDistribution2 );
    413450
    414   //Amplification vs Channels
    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 );
     451  //cross vs Channels
     452  hGainFitBsl = new TH1F("hGainFitBsl","BaselineDistribution from plot", 400,-99.5,100.5);
     453  hGainFitBsl->SetYTitle("Counts");
     454  hGainFitBsl->SetXTitle("Voltage [mV]");
     455  hGainFitBsl->SetLineColor(2);
     456  hList.Add( hGainFitBsl );
    420457
    421458}
     
    432469    tf.mkdir("PeakSpektra"); tf.cd("PeakSpektra"); // go to new subdirectory
    433470    hListPeakSpektra.Write(); // write histos into subdirectory
    434 
     471    tf.mkdir("CrazyPixels"); tf.cd("CrazyPixels"); // go to new subdirectory
     472    hListCrazy.Write(); // write histos into subdirector
    435473    tf.Close(); // close the file
    436474}
    437475
    438476//-----------------------------------------------------------------------------
    439 // MulitOrder MultiGauß Function
     477// Fit-Function: Sum of several Gauß-Function with falling Maximum Amplitude
    440478//-----------------------------------------------------------------------------
    441479
    442480Double_t spek_fit(Double_t *x, Double_t *par){
     481  Double_t arg = 0;
     482  Double_t arg2 = 0;
     483  Double_t arg3 = 0;
     484  Double_t arg4 = 0;
     485  Double_t cross = 0;
     486  if (par[0] != 0) cross = par[3]/par[0];
     487  if (par[2] != 0) arg = (x[0] - par[1]-par[4])/par[2];
     488  if (par[2] != 0) arg2 = (x[0] - 2*par[1]-par[4])/par[2];
     489  if (par[2] != 0) arg3 = (x[0] - 3*par[1]-par[4])/par[2];
     490  if (par[2] != 0) arg4 = (x[0] - 4*par[1]-par[4])/par[2];
     491  Double_t peak1 = par[0]*TMath::Exp(-0.5 * arg * arg);
     492  Double_t peak2 = cross*par[0]*TMath::Exp(-0.5 * arg2 * arg2 /2);
     493  Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3);
     494  Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4);
     495  return peak1 + peak2 + peak3 + peak4;
     496}
     497
     498//-----------------------------------------------------------------------------
     499// Fit-Function: Sum of several Gauß-Function with overlying potential decay
     500//-----------------------------------------------------------------------------
     501
     502Double_t spek_fit2(Double_t *x, Double_t *par){
    443503
    444504  Double_t arg = 0;
     
    447507  Double_t arg4 = 0;
    448508  Double_t cross = 1;
    449   if (par[0] != 0) cross = par[4]/par[0];
     509  if (par[0] != 0) cross = par[3]/par[0];
    450510  if (par[2] != 0) arg = (x[0] - par[1])/par[2];
    451511  if (par[2] != 0) arg2 = (x[0] - 2*par[1])/par[2];
    452512  if (par[2] != 0) arg3 = (x[0] - 3*par[1])/par[2];
    453513  if (par[2] != 0) arg4 = (x[0] - 4*par[1])/par[2];
    454   cross = par[4]/par[0];
    455514  Double_t peak1 = par[0]*TMath::Exp(-0.5 * arg * arg);
    456515  Double_t peak2 = cross*par[0]*TMath::Exp(-0.5 * arg2 * arg2 /2);
    457516  Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3);
    458517  Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4);
    459   //Double_t decayoverlay = TMath::Exp(-x[0]);
    460518  return peak1 + peak2 + peak3 + peak4;
    461519}
    462520
    463 Double_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 
    484 bool SearchAnormal(UInt_t pixel, Double_t distance){  //// MACHT ALLES KEINEN SINN WENN MAN KEINE BETRÄGE BETRACHTET
     521//-----------------------------------------------------------------------------
     522// Function: Search for Pixel that do not have a compareable gain to the Other
     523//-----------------------------------------------------------------------------
     524
     525bool SearchAnormal(UInt_t pixel, Double_t distance, int verbosityLevel){
    485526  Double_t check = channel[ pixel ].ampl_fspek_fit;
    486527  check = TMath::Sqrt(check*check);
     
    489530    }
    490531  else{
    491     cout << "Not normal behaviotruer in Pixel: " << pixel +1 << endl;
     532    if (verbosityLevel > 2) cout << "Not normal behaviotruer in Pixel: " << pixel +1 << endl;
    492533    return true;
    493534  }
    494535}
    495536
    496 /*
    497 
    498 
    499 
    500 
    501 
    502 
    503   */
    504 
    505 
    506 /*
    507 Double_t spek_fit(Double_t *x, Double_t *par, Uint_t *maxorder)
    508         {
    509                 Double_t exp = 0;
    510 
    511                 //Double_t arg2 = 0;
    512                 //if (par[2] != 0) arg = (v[0] - par[1])/par[2];
    513                 //if (par[5] != 0) arg2 = (v[0] - par[4])/par[5];
    514 
    515                 //Double_t fitval = par[0]*TMath::Exp(-0.5*arg*arg) + par[3]*TMath::Exp(-0.5*arg2*arg2);
    516 
    517                 for(int order = 0; order < maxorder; order++){
    518                 peak[order]=par[0]*par[4]/(order+1)*((x[0]-(order+1)*par[1])*(x[0]-(order+1)*par[1]))/(par[2]*par[2]);
    519                             exp = exp + peak[order];
    520                           }
    521 
    522                 Double_t fitval = TMath::Exp(-0.5*exp);
    523                 return fitval;
    524         }
    525 */
Note: See TracChangeset for help on using the changeset viewer.