Ignore:
Timestamp:
12/13/11 16:18:15 (13 years ago)
Author:
Jens Buss
Message:
bug-fix: took wrong pixelorder from ampl_spk, now it works
File:
1 edited

Legend:

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

    r12713 r12721  
    1414//  - draw gain vs. pixel
    1515//  - find Pixels with deviating gainvalue (e.g. dead , crazy Pixels)
    16 //    and write their number to log-file (e.g. date_run_gainfit.txt)
     16//    and write their number to txt-file (e.g. date_run_gainfit.txt)
    1717//  - save histograms into root-file (e.g. date_run_gainfit.root)
     18//  - Works also with ROI 300
    1819//
    1920//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     
    6566
    6667//Verbosity for Histograms
    67 TString verbos[3]={"Q","", ""};
     68TString verbos[4]={"0Q","Q", "", "V"};
    6869//-----------------------------------------------------------------------------
    6970// Decleration of Histograms
     
    9697
    9798int gainfit2(
    98         const char * InputRootFileName = "../analysis/fpeak/20111109_006/20111109_006_fpeak.root",
    99         const char * InputBaselineFileName = "../analysis/fpeak/20111109_006/20111109_006_fbsl.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",
    102         bool showHistos = false,
    103         bool debug = false,
    104         int verbosityLevel = 3)
     99        const char * InputRootFileName = "../analysis/fpeak/20111110_005/20111110_005_fpeak.root",
     100        const char * InputBaselineFileName = "../analysis/fpeak/20111110_005/20111110_005_fbsl.root",
     101        const char * OutTextFileName = "../analysis/fpeak/20111110_005/20111110_005_gainfit.txt",
     102        const char * RootOutFileName = "../analysis/fpeak/20111110_005/20111110_005_gainfit.root",
     103        bool showHistos = true,
     104        bool debug = true,
     105        int verbosityLevel = 2)
    105106{
     107
     108//-----------------------------------------------------------------------------
     109// Fit Verbosity
     110//-----------------------------------------------------------------------------
     111
     112  UInt_t fitverb = verbosityLevel;
     113  if (verbosityLevel >= 3) fitverb =3;
    106114
    107115//-----------------------------------------------------------------------------
     
    127135
    128136//Define Fit Functions
    129     Double_t par[9];
     137    Double_t par[6];
     138    Double_t par2[6];
    130139    TF1 *g1    = new TF1("g1","gaus",5,15);
    131140    TF1 *g2    = new TF1("g2","gaus",15,25);
    132     TF1 *g3    = new TF1("g3","gaus",25,35);
     141    //TF1 *g3    = new TF1("g3","gaus",-5,5);
    133142    TF1 *g4    = new TF1("g4","gaus");
    134143    //TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",7,60);
    135     TF1 *fspek_fit = new TF1("fspek_fit", spek_fit, 5, 60, 5);
    136     TF1 *fspek_fit2 = new TF1("fspek_fit2", spek_fit2, 5, 60, 4);
    137 
     144    TF1 *fspek_fit = new TF1("fspek_fit", spek_fit, 5, 60, 6);
     145    fspek_fit->SetParNames("1.Max", "Gain", "Sigma", "2.Max", "Baseline", "Xtalk");
     146    TF1 *fspek_fit2 = new TF1("fspek_fit2g3", spek_fit2, 5, 60, 4);
     147    fspek_fit2->SetParNames("1.Max", "Gain", "Sigma", "2.Max");
    138148//Create Canvases
    139149    TCanvas *cGainFit = new TCanvas("cGainFit", "Fit of Amplitude Spektra", 0,0, 1200,400);
     
    211221  //Amplitude Spectrum of a Pixel
    212222        hPixelAmplSpek[ pixel ] = new TH1D;
    213         hPixelAmplSpek[ pixel ] = hAmplSpek->ProjectionY( histotitle , pixel+0, pixel+0);        //Projectipon of each Pixel out of Ampl.Spectrum
     223        hPixelAmplSpek[ pixel ] = hAmplSpek->ProjectionY( histotitle , pixel+1, pixel+1);        //Projectipon of each Pixel out of Ampl.Spectrum
    214224        hPixelAmplSpek[ pixel ]->SetAxisRange(0, 60, "X");
    215225
     
    234244        gPad->SetLogy(1);
    235245
    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+");
     246        hPixelAmplSpek[ pixel ]->Fit(g1,verbos[fitverb]+"R");
     247        hPixelAmplSpek[ pixel ]->Fit(g2,verbos[fitverb]+"0R+");
     248        //hPixelAmplSpek[ pixel ]->Fit(g3,verbos[fitverb]+"0R+");
    239249        g1->GetParameters(&par[0]);
     250        g1->GetParameters(&par2[0]);
    240251        g2->GetParameters(&par[3]);
    241         g3->GetParameters(&par[6]);
     252        g2->GetParameters(&par2[3]);
     253
     254        //g3->GetParameters(&par[6]);
    242255
    243256        //total->SetParameters(par);
    244257
    245         //hPixelAmplSpek[ pixel ]->Fit(total,verbos[verbosityLevel-1]+"R+");
     258        //hPixelAmplSpek[ pixel ]->Fit(total,verbos[fitverb]+"R+");
    246259        //channel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1);
    247260        //channel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4);
    248261        //channel[ pixel ].amplMean = fspek_fit->GetParameter(1);
    249262
    250         par[4] = -1;
     263        par2[4]=par[4] = hbaseline->GetMean();
     264        cout << "starvalue of Baseline:" << par[4] << endl;
    251265        fspek_fit->SetParameters(par);
    252         cout << "spek_fit" << endl;
    253         hPixelAmplSpek[ pixel ]->Fit(fspek_fit,verbos[verbosityLevel-1]+"R+");
     266        if (verbosityLevel > 2) cout << "spek_fit" << endl;
     267        hPixelAmplSpek[ pixel ]->Fit(fspek_fit,verbos[fitverb]+"R+");
    254268        channel[ pixel ].ampl_fspek_fit = fspek_fit->GetParameter(1);
    255269        channel[ pixel ].bsl = fspek_fit->GetParameter(4);
    256         cout << "Baseline:" << channel[ pixel ].bsl << endl;
    257 
    258         fspek_fit2->SetParameters(par);
    259         cout << "fspek_fit2" << endl;
    260         hPixelAmplSpek[ pixel ]->Fit(fspek_fit2,verbos[verbosityLevel-1]+"R+");
     270        if (verbosityLevel > 2) cout << "Baseline:" << channel[ pixel ].bsl << endl;
     271
     272        fspek_fit2->SetParameters(par2);
     273        if (verbosityLevel > 2) cout << "fspek_fit2" << endl;
     274        hPixelAmplSpek[ pixel ]->Fit(fspek_fit2,verbos[fitverb]+"R+");
    261275        channel[ pixel ].ampl_fspek_fit2 = fspek_fit2->GetParameter(1);
    262276       
     
    278292        g4->SetLineColor(2);
    279293        hAmplDistribution->Fill( channel[ pixel ].ampl_fspek_fit ) ;
    280         hAmplDistribution->Fit(g4, verbos[verbosityLevel-1]);
     294        hAmplDistribution->Fit(g4, verbos[fitverb]);
    281295        distribution.sigma = g4->GetParameter(2);
    282296        distribution.mean = g4->GetParameter(1);
     
    287301        g4->SetLineColor(kBlue);
    288302        hAmplDistribution2->Fill(channel[ pixel ].ampl_fspek_fit2) ;
    289         hAmplDistribution2->Fit(g4, verbos[verbosityLevel-1]);
     303        hAmplDistribution2->Fit(g4, verbos[fitverb]);
    290304
    291305        cGainFit->cd(3);
     
    493507  Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3);
    494508  Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4);
     509  par[5]=cross;
    495510  return peak1 + peak2 + peak3 + peak4;
    496511}
     
    500515//-----------------------------------------------------------------------------
    501516
    502 Double_t spek_fit2(Double_t *x, Double_t *par){
     517Double_t spek_fit2(Double_t *x, Double_t *par2){
    503518
    504519  Double_t arg = 0;
     
    506521  Double_t arg3 = 0;
    507522  Double_t arg4 = 0;
    508   Double_t cross = 1;
    509   if (par[0] != 0) cross = par[3]/par[0];
    510   if (par[2] != 0) arg = (x[0] - par[1])/par[2];
    511   if (par[2] != 0) arg2 = (x[0] - 2*par[1])/par[2];
    512   if (par[2] != 0) arg3 = (x[0] - 3*par[1])/par[2];
    513   if (par[2] != 0) arg4 = (x[0] - 4*par[1])/par[2];
    514   Double_t peak1 = par[0]*TMath::Exp(-0.5 * arg * arg);
    515   Double_t peak2 = cross*par[0]*TMath::Exp(-0.5 * arg2 * arg2 /2);
    516   Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3);
    517   Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4);
     523  Double_t cross = 0;
     524  if (par2[0] != 0) cross = par2[3]/par2[0];
     525  if (par2[2] != 0) arg = (x[0] - par2[1])/par2[2];
     526  if (par2[2] != 0) arg2 = (x[0] - 2*par2[1])/par2[2];
     527  if (par2[2] != 0) arg3 = (x[0] - 3*par2[1])/par2[2];
     528  if (par2[2] != 0) arg4 = (x[0] - 4*par2[1])/par2[2];
     529  Double_t peak1 = par2[0]*TMath::Exp(-0.5 * arg * arg);
     530  Double_t peak2 = cross*par2[0]*TMath::Exp(-0.5 * arg2 * arg2 /2);
     531  Double_t peak3 = cross*cross*par2[0]*TMath::Exp(-0.5 * arg3 * arg3 /3);
     532  Double_t peak4 = cross*cross*cross*par2[0]*TMath::Exp(-0.5 * arg4 * arg4 /4);
    518533  return peak1 + peak2 + peak3 + peak4;
    519534}
     
    530545    }
    531546  else{
    532     if (verbosityLevel > 2) cout << "Not normal behaviotruer in Pixel: " << pixel +1 << endl;
     547    if (verbosityLevel > 2) cout << "Not normal behaviour in Pixel: " << pixel +1 << endl;
    533548    return true;
    534549  }
Note: See TracChangeset for help on using the changeset viewer.