Index: fact/tools/rootmacros/gainfit2.C
===================================================================
--- fact/tools/rootmacros/gainfit2.C	(revision 12720)
+++ fact/tools/rootmacros/gainfit2.C	(revision 12721)
@@ -14,6 +14,7 @@
 //  - draw gain vs. pixel
 //  - find Pixels with deviating gainvalue (e.g. dead , crazy Pixels)
-//    and write their number to log-file (e.g. date_run_gainfit.txt)
+//    and write their number to txt-file (e.g. date_run_gainfit.txt)
 //  - save histograms into root-file (e.g. date_run_gainfit.root)
+//  - Works also with ROI 300
 //
 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -65,5 +66,5 @@
 
 //Verbosity for Histograms
-TString verbos[3]={"Q","", ""};
+TString verbos[4]={"0Q","Q", "", "V"};
 //-----------------------------------------------------------------------------
 // Decleration of Histograms
@@ -96,12 +97,19 @@
 
 int gainfit2(
-        const char * InputRootFileName = "../analysis/fpeak/20111109_006/20111109_006_fpeak.root",
-        const char * InputBaselineFileName = "../analysis/fpeak/20111109_006/20111109_006_fbsl.root",
-        const char * OutTextFileName = "../analysis/fpeak/20111109_006/20111109_006_gainfit.txt",
-        const char * RootOutFileName = "../analysis/fpeak/20111109_006/20111109_006_gainfit.root",
-        bool showHistos = false,
-        bool debug = false,
-        int verbosityLevel = 3)
+        const char * InputRootFileName = "../analysis/fpeak/20111110_005/20111110_005_fpeak.root",
+        const char * InputBaselineFileName = "../analysis/fpeak/20111110_005/20111110_005_fbsl.root",
+        const char * OutTextFileName = "../analysis/fpeak/20111110_005/20111110_005_gainfit.txt",
+        const char * RootOutFileName = "../analysis/fpeak/20111110_005/20111110_005_gainfit.root",
+        bool showHistos = true,
+        bool debug = true,
+        int verbosityLevel = 2)
 {
+
+//-----------------------------------------------------------------------------
+// Fit Verbosity
+//-----------------------------------------------------------------------------
+
+  UInt_t fitverb = verbosityLevel;
+  if (verbosityLevel >= 3) fitverb =3;
 
 //-----------------------------------------------------------------------------
@@ -127,13 +135,15 @@
 
 //Define Fit Functions
-    Double_t par[9];
+    Double_t par[6];
+    Double_t par2[6];
     TF1 *g1    = new TF1("g1","gaus",5,15);
     TF1 *g2    = new TF1("g2","gaus",15,25);
-    TF1 *g3    = new TF1("g3","gaus",25,35);
+    //TF1 *g3    = new TF1("g3","gaus",-5,5);
     TF1 *g4    = new TF1("g4","gaus");
     //TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)",7,60);
-    TF1 *fspek_fit = new TF1("fspek_fit", spek_fit, 5, 60, 5);
-    TF1 *fspek_fit2 = new TF1("fspek_fit2", spek_fit2, 5, 60, 4);
-
+    TF1 *fspek_fit = new TF1("fspek_fit", spek_fit, 5, 60, 6);
+    fspek_fit->SetParNames("1.Max", "Gain", "Sigma", "2.Max", "Baseline", "Xtalk");
+    TF1 *fspek_fit2 = new TF1("fspek_fit2g3", spek_fit2, 5, 60, 4);
+    fspek_fit2->SetParNames("1.Max", "Gain", "Sigma", "2.Max");
 //Create Canvases
     TCanvas *cGainFit = new TCanvas("cGainFit", "Fit of Amplitude Spektra", 0,0, 1200,400);
@@ -211,5 +221,5 @@
   //Amplitude Spectrum of a Pixel
         hPixelAmplSpek[ pixel ] = new TH1D;
-        hPixelAmplSpek[ pixel ] = hAmplSpek->ProjectionY( histotitle , pixel+0, pixel+0);	 //Projectipon of each Pixel out of Ampl.Spectrum
+        hPixelAmplSpek[ pixel ] = hAmplSpek->ProjectionY( histotitle , pixel+1, pixel+1);	 //Projectipon of each Pixel out of Ampl.Spectrum
         hPixelAmplSpek[ pixel ]->SetAxisRange(0, 60, "X");
 
@@ -234,29 +244,33 @@
         gPad->SetLogy(1);
 
-        hPixelAmplSpek[ pixel ]->Fit(g1,verbos[verbosityLevel-1]+"R");
-        hPixelAmplSpek[ pixel ]->Fit(g2,verbos[verbosityLevel-1]+"0R+");
-        hPixelAmplSpek[ pixel ]->Fit(g3,verbos[verbosityLevel-1]+"0R+");
+        hPixelAmplSpek[ pixel ]->Fit(g1,verbos[fitverb]+"R");
+        hPixelAmplSpek[ pixel ]->Fit(g2,verbos[fitverb]+"0R+");
+        //hPixelAmplSpek[ pixel ]->Fit(g3,verbos[fitverb]+"0R+");
         g1->GetParameters(&par[0]);
+        g1->GetParameters(&par2[0]);
         g2->GetParameters(&par[3]);
-        g3->GetParameters(&par[6]);
+        g2->GetParameters(&par2[3]);
+
+        //g3->GetParameters(&par[6]);
 
         //total->SetParameters(par);
 
-        //hPixelAmplSpek[ pixel ]->Fit(total,verbos[verbosityLevel-1]+"R+");
+        //hPixelAmplSpek[ pixel ]->Fit(total,verbos[fitverb]+"R+");
         //channel[ pixel ].amplSD = total->GetParameter(4) - total->GetParameter(1);
         //channel[ pixel ].amplDT = total->GetParameter(7) - total->GetParameter(4);
         //channel[ pixel ].amplMean = fspek_fit->GetParameter(1);
 
-        par[4] = -1;
+        par2[4]=par[4] = hbaseline->GetMean();
+        cout << "starvalue of Baseline:" << par[4] << endl;
         fspek_fit->SetParameters(par);
-        cout << "spek_fit" << endl;
-        hPixelAmplSpek[ pixel ]->Fit(fspek_fit,verbos[verbosityLevel-1]+"R+");
+        if (verbosityLevel > 2) cout << "spek_fit" << endl;
+        hPixelAmplSpek[ pixel ]->Fit(fspek_fit,verbos[fitverb]+"R+");
         channel[ pixel ].ampl_fspek_fit = fspek_fit->GetParameter(1);
         channel[ pixel ].bsl = fspek_fit->GetParameter(4);
-        cout << "Baseline:" << channel[ pixel ].bsl << endl;
-
-        fspek_fit2->SetParameters(par);
-        cout << "fspek_fit2" << endl;
-        hPixelAmplSpek[ pixel ]->Fit(fspek_fit2,verbos[verbosityLevel-1]+"R+");
+        if (verbosityLevel > 2) cout << "Baseline:" << channel[ pixel ].bsl << endl;
+
+        fspek_fit2->SetParameters(par2);
+        if (verbosityLevel > 2) cout << "fspek_fit2" << endl;
+        hPixelAmplSpek[ pixel ]->Fit(fspek_fit2,verbos[fitverb]+"R+");
         channel[ pixel ].ampl_fspek_fit2 = fspek_fit2->GetParameter(1);
         
@@ -278,5 +292,5 @@
         g4->SetLineColor(2);
         hAmplDistribution->Fill( channel[ pixel ].ampl_fspek_fit ) ;
-        hAmplDistribution->Fit(g4, verbos[verbosityLevel-1]);
+        hAmplDistribution->Fit(g4, verbos[fitverb]);
         distribution.sigma = g4->GetParameter(2);
         distribution.mean = g4->GetParameter(1);
@@ -287,5 +301,5 @@
         g4->SetLineColor(kBlue);
         hAmplDistribution2->Fill(channel[ pixel ].ampl_fspek_fit2) ;
-        hAmplDistribution2->Fit(g4, verbos[verbosityLevel-1]);
+        hAmplDistribution2->Fit(g4, verbos[fitverb]);
 
         cGainFit->cd(3);
@@ -493,4 +507,5 @@
   Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3);
   Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4);
+  par[5]=cross;
   return peak1 + peak2 + peak3 + peak4;
 }
@@ -500,5 +515,5 @@
 //-----------------------------------------------------------------------------
 
-Double_t spek_fit2(Double_t *x, Double_t *par){
+Double_t spek_fit2(Double_t *x, Double_t *par2){
 
   Double_t arg = 0;
@@ -506,14 +521,14 @@
   Double_t arg3 = 0;
   Double_t arg4 = 0;
-  Double_t cross = 1;
-  if (par[0] != 0) cross = par[3]/par[0];
-  if (par[2] != 0) arg = (x[0] - par[1])/par[2];
-  if (par[2] != 0) arg2 = (x[0] - 2*par[1])/par[2];
-  if (par[2] != 0) arg3 = (x[0] - 3*par[1])/par[2];
-  if (par[2] != 0) arg4 = (x[0] - 4*par[1])/par[2];
-  Double_t peak1 = par[0]*TMath::Exp(-0.5 * arg * arg);
-  Double_t peak2 = cross*par[0]*TMath::Exp(-0.5 * arg2 * arg2 /2);
-  Double_t peak3 = cross*cross*par[0]*TMath::Exp(-0.5 * arg3 * arg3 /3);
-  Double_t peak4 = cross*cross*cross*par[0]*TMath::Exp(-0.5 * arg4 * arg4 /4);
+  Double_t cross = 0;
+  if (par2[0] != 0) cross = par2[3]/par2[0];
+  if (par2[2] != 0) arg = (x[0] - par2[1])/par2[2];
+  if (par2[2] != 0) arg2 = (x[0] - 2*par2[1])/par2[2];
+  if (par2[2] != 0) arg3 = (x[0] - 3*par2[1])/par2[2];
+  if (par2[2] != 0) arg4 = (x[0] - 4*par2[1])/par2[2];
+  Double_t peak1 = par2[0]*TMath::Exp(-0.5 * arg * arg);
+  Double_t peak2 = cross*par2[0]*TMath::Exp(-0.5 * arg2 * arg2 /2);
+  Double_t peak3 = cross*cross*par2[0]*TMath::Exp(-0.5 * arg3 * arg3 /3);
+  Double_t peak4 = cross*cross*cross*par2[0]*TMath::Exp(-0.5 * arg4 * arg4 /4);
   return peak1 + peak2 + peak3 + peak4;
 }
@@ -530,5 +545,5 @@
     }
   else{
-    if (verbosityLevel > 2) cout << "Not normal behaviotruer in Pixel: " << pixel +1 << endl;
+    if (verbosityLevel > 2) cout << "Not normal behaviour in Pixel: " << pixel +1 << endl;
     return true;
   }
