]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
Run analyzer: added summary table writeout, compare one specific histogram with other...
authorBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Tue, 23 Feb 2016 13:46:21 +0000 (14:46 +0100)
committerBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Tue, 23 Feb 2016 13:46:21 +0000 (14:46 +0100)
MABS_run_analyzer/ChargeSpektrum.c
MABS_run_analyzer/ChargeSpektrumFunctions.c
MABS_run_analyzer/HistogramType.c
MABS_run_analyzer/HistogramType.h
MABS_run_analyzer/MAPS.c
MABS_run_analyzer/Run.c
MABS_run_analyzer/Run.h
MABS_run_analyzer/SetStyle.c
MABS_run_analyzer/help.h

index bf14713cc87676d6be5096fae3578936cc848df9..7f9d629df4b83efc40081cff6aec327292dbf6d7 100644 (file)
@@ -3,8 +3,8 @@
  * @brief Use brief, otherwise the index won't have a brief explanation.
  *
  * Detailed explanation.
- * 
- * 
+ *
+ *
  */
 
 #include "MAPS.c"
@@ -23,13 +23,14 @@ TString savepathresults = "./results/";
 
 void ChargeSpektrum(TString runnumber = "")
 {
-    #include "SetStyle.c"
-    cout << endl << endl; 
+#include "SetStyle.c"
+    cout << endl << endl;
     if (gROOT->IsBatch())
         isBatch = kTRUE;
-    
+
     numberRuns=0;
     std::vector<int> runList;
+    std::vector<Bool_t> runListForceAnalysis;
     std::vector<TString> sumuprunList;
     if (runnumber.Length() > 0)
     {
@@ -51,6 +52,7 @@ void ChargeSpektrum(TString runnumber = "")
                             for (Int_t i=tempintstart; i <= tempintend; i++)
                             {
                                 runList.push_back(i);
+                                runListForceAnalysis.push_back(kFALSE);
                                 numberRuns++;
                             }
                         }
@@ -58,19 +60,19 @@ void ChargeSpektrum(TString runnumber = "")
                             cout << coloryellow << "Invalid run number range "<< colorreset << colorwhite << tempintstart << " till " << tempintend << endlr;
                     }
                     else
-                        cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr;  
-                    
+                        cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr;
+
                 }
                 else
-                    cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr;    
+                    cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr;
             }
             else
             {
                 cout << endl << colorred << "Given parameters have wrong format, please enter integer run numbers devided by '" << colorreset << colorwhite << "," << colorreset << colorred << " or 2 runnumbers devided by " << colorreset << colorwhite << "-" << colorreset << colorred << "' and surrounded by '" << colorreset << colorwhite << "\"" << colorreset  << colorred << "'." << endlr;
                 cout << "For example run: " << colorwhite << "root -l 'ChargeSpektrum.c+(\"342815,342816\")'" << endl;
                 exit(1);
-            }  
-            
+            }
+
         } else {
             TObjArray* runarray = runnumber.Tokenize(",");
             if (runarray->GetEntries()>0)
@@ -91,6 +93,10 @@ void ChargeSpektrum(TString runnumber = "")
                             if (tempint > 0)
                             {
                                 runList.push_back(tempint);
+                                if (sumuprunsstrobj->GetString().Contains("!"))
+                                    runListForceAnalysis.push_back(kTRUE);
+                                else
+                                    runListForceAnalysis.push_back(kFALSE);
                                 sumrunsstr.Append(Form("%d,",tempint));
                                 numberRuns++;
                             }
@@ -101,25 +107,25 @@ void ChargeSpektrum(TString runnumber = "")
                     }
                     else
                         cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr;
-                }                
+                }
             }
             else
             {
                 cout << endl << colorred << "Given parameters have wrong format, please enter integer run numbers devided by '" << colorreset << colorwhite << "," << colorreset << colorred << "' and surrounded by '" << colorreset << colorwhite << "\"" << colorreset  << colorred << "'." << endlr;
                 cout << "For example run: " << colorwhite << "root -l 'ChargeSpektrum.c+(\"342815,342816\")'" << endl;
                 exit(1);
-            }         
+            }
         }
     }
     else
     {
-        /// number of runs to be analyzed, number of lines read by @c ReadRunList() 
+        /// number of runs to be analyzed, number of lines read by @c ReadRunList()
         ReadRunList(&runList);
     }
     runs = new Run*[numberRuns];
-    
+
     cout << "Found " << numberRuns << " run(s) in 'runlist.txt' or given as parameters." << endl;
-    for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
+    for(Int_t runi=0; runi<numberRuns; runi++) // loop over runs read from file
     {
         if (runList[runi]>0)
         {
@@ -131,15 +137,22 @@ void ChargeSpektrum(TString runnumber = "")
                 runs[runi]->setDynamicalNoiseMode("simple");
                 runs[runi]->useDynamicalNoise(true);
                 runs[runi]->useCommonModeFilter(false);
-                runs[runi]->setFixedThresholdValueElectrons(1440);
-//                 runs[runi]->setNoisethresholdborderADU(40);
-                
+                //runs[runi]->setFixedThresholdValueElectrons(1440);
+                //runs[runi]->setNoisethresholdborderADU(30);
+
 //                 runs[runi]->analyzeFrame(57826);
 //                 runs[runi]->analyzeFrame(57827);
-//                 runs[runi]->analyzeFrame(983603); 
-                
+//                 runs[runi]->analyzeFrame(983603);
+
                 // creates or opens .root file, can analyze the RAW data
-                runs[runi]->error=runs[runi]->analyzeRun(false); // creates or opens .root file, can analyze the RAW data
+                if (runListForceAnalysis.size() >= (unsigned)runi+1)
+                {
+                    if (runListForceAnalysis[runi])
+                        runs[runi]->error=runs[runi]->analyzeRun(true); // creates or opens .root file, can analyze the RAW data
+                    else
+                        runs[runi]->error=runs[runi]->analyzeRun(false); // creates or opens .root file, can analyze the RAW data
+                } else
+                    runs[runi]->error=runs[runi]->analyzeRun(false); // creates or opens .root file, can analyze the RAW data
                 if (runs[runi]->error) // first time analysis without forcing new ROOT file failed, retry with forcing new analysis
                 {
                     runs[runi]->error = false;
@@ -147,7 +160,7 @@ void ChargeSpektrum(TString runnumber = "")
                 }
                 if (!runs[runi]->error)
                 {
-            //         gROOT->SetBatch(kTRUE);
+                    //         gROOT->SetBatch(kTRUE);
                     if (!isBatch)
                         gROOT->SetBatch(kFALSE);
 //                     runs[runi]->plot1DHistogram(runs[runi]->histogram,runs[runi]->histogram->Seed,"landau","Test");
@@ -155,20 +168,30 @@ void ChargeSpektrum(TString runnumber = "")
 //                     runs[runi]->compareHistogramClassVector.push_back(runs[runi]->histogramthreshold->calibrated);
 //                     runs[runi]->compareHistogramClassVector.push_back(runs[runi]->histogramfixedthreshold);
 //                     runs[runi]->plotCompareHistograms();
-                       runs[runi]->plotAllHistograms(runs[runi]->histogramthreshold);
-                       compareHistogramClassVector.push_back(runs[runi]->histogramthreshold);
-                       //compareHistogramClassVector.push_back(runs[runi]->histogram);
-                    //                      runs[runi]->plot1DHistogram(runs[runi]->histogramthreshold, runs[runi]->histogramthreshold->Veto, "gaus"); 
-//                     runs[runi]->plot1DHistogram(runs[runi]->histogramthreshold, runs[runi]->histogramthreshold->SeedPerc, "landau", 0); 
-                       compareHistogramVector.push_back(runs[runi]->histogramthreshold->Seed);
-                    runs[runi]->writeAllHistogramsToFile(); 
+//                        runs[runi]->plotAllHistograms(runs[runi]->histogramthreshold);
+                    compareHistogramClassVector.push_back(runs[runi]->histogramthreshold->normalized);
+                    compareHistogramVector.push_back(runs[runi]->histogramthreshold->normalized->Seed);
+                    //compareHistogramClassVector.push_back(runs[runi]->histogram);
+                    //                      runs[runi]->plot1DHistogram(runs[runi]->histogramthreshold, runs[runi]->histogramthreshold->Veto, "gaus");
+//                      runs[runi]->plot1DHistogram(runs[runi]->histogramthreshold, runs[runi]->histogramthreshold->normalized->Sum, "gaus", 1);
+//                      runs[runi]->plot1DHistogram(runs[runi]->histogramthreshold, runs[runi]->histogramthreshold->normalized->Veto, "GaussTail", 1);
+//                     compareHistogramVector.push_back(runs[runi]->histogramthreshold->calibrated->normalized->Veto);
+                     runs[runi]->writeAllHistogramsToFile();
                 }
                 //cout << runs[runi]->histogram
             }
         }
     }
-    plotAllRuns(&compareHistogramClassVector);
-    printSummaryTable(&compareHistogramClassVector);
+//     if (numberRuns>0)
+//         runs[0]->setLabel("33x33 #mum, S(D)=8 #mum^2, F(D)=15 #mum^2");
+//     if (numberRuns>1)
+//            runs[1]->setLabel("66x33 #mum, S(D)=8 #mum^2, F(D)=15 #mum^2");
+//     if (numberRuns>2)
+//         runs[2]->setLabel("33x33 #mum, S(D)=11 #mum^2, F(D)=11 #mum^2");
+//     runs[3]->setLabel("HR18, P13, 5.0 V");
+printSummaryTable(&compareHistogramClassVector);
+CompareHistograms(&compareHistogramVector);
+plotAllRuns(&compareHistogramClassVector);
 //    plotAllRuns(&compareHistogramClassVector2);
 //     plotAllRuns(&compareHistogramClassVector3);
     writeObservableToFile();
index 5fbbc2bc6aebbb8d688806a0805f2b1d837a2c7a..1d72227b8b2579cc710b1769feaa7f641dc3e22a 100644 (file)
 #include <iomanip>
 #include <TPaveText.h>
 #include <TLatex.h>
+#include <THStack.h>
+#include <TCanvas.h>
+
+#include "help.h"
 using namespace std;
 
-TString trimRunnumberAtBegin(TString str);
 Int_t* ReadRunList();
 Int_t ReadRunList(std::vector<int>*);
 Bool_t plotAllRuns();
@@ -28,6 +31,13 @@ Bool_t plotAllRuns(vector<HistogramType*>*);
 /** @brief Prints a line with fixed width in the summary table   */
 template<typename varType> string printTableElement(varType t1, varType t2, const int precision=1);
 
+/** @brief A function to compare one type of histogram TH1F, plots them in same canvas
+ * 
+ * You must push TH1F pointers to #compareHistogramVector to be able to use this
+ *     
+ */
+Bool_t CompareHistograms(vector<TH1F*>* ptCompareHistogramVector, TString titlestr = "", TString YAxisTitle = "");
+
 Bool_t writeObservableToFile();
 /** @brief A vector able to hold pointer of type #Run::histogramstruct
  * 
@@ -133,6 +143,77 @@ Bool_t writeObservableToFile()
     return 0;
 }
 
+Bool_t CompareHistograms(vector<TH1F*>* ptCompareHistogramVector, TString titlestr, TString YAxisTitle)
+{
+    if (ptCompareHistogramVector->size() > 0)
+    { 
+        gROOT->SetStyle("RadHard_NoTitle");
+        
+        // legend entries
+        Float_t height = ptCompareHistogramVector->size() * 0.03;
+        TLegend* leg1 = new TLegend(0.3,0.89-height,0.95,0.89);//(0.6,0.7,0.89,0.89);
+        leg1->SetTextSize(0.025);
+        leg1->SetFillStyle(0);
+        leg1->SetTextFont(132);
+        leg1->SetFillColor(0); leg1->SetBorderSize(0);
+        TString  legendEntry;
+        
+        TPaveText *owntitle = new TPaveText(0.15,0.9,0.930401,0.995,"nbNDC");
+        owntitle->SetFillStyle(0);
+        owntitle->SetBorderSize(0);
+        owntitle->SetTextAlign(22);
+        owntitle->SetTextSize(0.05);
+        owntitle->SetTextFont(42);
+        
+        Float_t lastbin1=0;   
+        Float_t heighestval1=0; 
+        TString canvastitle = Form("Compare");
+        TTimeStamp* time = new TTimeStamp(); 
+        TString canvasname = Form("%d",time->GetNanoSec());        
+        for (UInt_t histogrami=0; histogrami < ptCompareHistogramVector->size(); histogrami++)
+        {
+            TH1F* curhistogramclone = (TH1F*) ptCompareHistogramVector->at(histogrami)->Clone();
+            heighestval1 = (curhistogramclone->GetMaximum()>heighestval1?curhistogramclone->GetMaximum():heighestval1); 
+            lastbin1 = (curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1))>lastbin1)?curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1)):lastbin1;
+            canvastitle+= Form("_%s",getRunnumberAtBegin(curhistogramclone->GetName()).Data());        
+        }        
+        TCanvas* canvas = new TCanvas(canvasname, canvastitle, 1200, 800);
+        
+        for (UInt_t histogrami=0; histogrami < ptCompareHistogramVector->size(); histogrami++)
+        {
+            TH1F* curhistogramclone = (TH1F*) ptCompareHistogramVector->at(histogrami)->Clone();
+            if (titlestr.Length() > 0) curhistogramclone->SetName(titlestr);
+            if (YAxisTitle.Length() > 0) curhistogramclone->SetYTitle(YAxisTitle);
+            curhistogramclone->SetLineColor(rootcolors[histogrami%13]);   
+            curhistogramclone->Draw("SAME");
+            legendEntry = Form("%s %s", getRunnumberAtBegin(curhistogramclone->GetName()).Data(), curhistogramclone->GetTitle());
+            leg1->AddEntry(curhistogramclone, legendEntry, "l");
+            leg1->Draw("SAME");
+            curhistogramclone->SetAxisRange(0,lastbin1*1.1,"X");
+            curhistogramclone->GetYaxis()->SetRangeUser(5,heighestval1*4);
+            gPad->SetLogy(1);
+            owntitle->Clear();
+            owntitle->AddText(trimRunnumberAtBegin(curhistogramclone->GetName()));
+            owntitle->Draw("SAME");
+        }
+        canvas->Update();
+        
+        TImageDump *img = new TImageDump(savepathresults + "/" + canvastitle + ".png");
+        canvas->Paint();
+        img->Close();
+        
+        TFile *f = new TFile(savepathresults + "/" + canvastitle + ".root","RECREATE");
+        f->cd();
+        f->Append(canvas);
+        f->Append(img);
+        f->Write();
+        
+        MSaveBigPNG(savepathresults + "/" + canvastitle + ".png");
+        return 0;
+    }
+    return 1;
+}
+
 
 Bool_t plotAllRuns() {
     return plotAllRuns(&compareHistogramClassVector);
@@ -167,16 +248,19 @@ Bool_t plotAllRuns(vector<HistogramType*>* ptCompareHistogramClassVector)
 {
     if (numberRuns>0)
     { 
+        gROOT->SetStyle("RadHard_NoTitle");
         if (testifMixingCalibration(ptCompareHistogramClassVector)) return 1;
         
         // legend entries
-        Float_t height = ptCompareHistogramClassVector->size() * 0.045;
-        TLegend* leg1 = new TLegend(0.35,0.89-height,0.89,0.89);//(0.6,0.7,0.89,0.89);
-        leg1->SetTextSize(0.025);
+        Float_t height = ptCompareHistogramClassVector->size() * 0.055;
+        TLegend* leg1 = new TLegend(0.10,0.89-height,0.95,0.89);//(0.6,0.7,0.89,0.89);
+        leg1->SetTextSize(0.035);
         leg1->SetFillStyle(0);
-        leg1->SetTextFont(12);
+        leg1->SetTextFont(132);
         leg1->SetFillColor(0); leg1->SetBorderSize(0);
         TLegend* leg2 = (TLegend*) leg1->Clone();
+        TLegend* leg3 = (TLegend*) leg1->Clone();
+        TLegend* leg4 = (TLegend*) leg1->Clone();
         TString  legendEntry;
         
         TPaveText *owntitle = new TPaveText(0.15,0.9,0.930401,0.995,"nbNDC");
@@ -188,12 +272,15 @@ Bool_t plotAllRuns(vector<HistogramType*>* ptCompareHistogramClassVector)
         TPaveText *owntitle2 = (TPaveText*)owntitle->Clone();
         TPaveText *owntitle3 = (TPaveText*)owntitle->Clone();
         TPaveText *owntitle4 = (TPaveText*)owntitle->Clone();
-        gStyle->SetOptTitle(0);
         
         Float_t lastbin1=0;
         Float_t lastbin2=0;
         Float_t lastbin3=0;
-        Float_t lastbin4=0;      
+        Float_t lastbin4=0;   
+        Float_t heighestval1=0;
+        Float_t heighestval2=0;
+        Float_t heighestval3=0;
+        Float_t heighestval4=0;   
         TString canvastitle = Form("Summary");  
         for (UInt_t histogrami=0; histogrami < ptCompareHistogramClassVector->size(); histogrami++)
         {
@@ -204,6 +291,23 @@ Bool_t plotAllRuns(vector<HistogramType*>* ptCompareHistogramClassVector)
         TString canvasname = Form("%d",time->GetNanoSec());
         TCanvas* canvas = new TCanvas(canvasname, canvastitle, 1200, 800);
         canvas->Divide(2,2);
+        THStack *hs = new THStack("hs","Sum spectra");
+        
+        for (UInt_t histogrami=0; histogrami < ptCompareHistogramClassVector->size(); histogrami++)
+        {
+            HistogramType* curhistogramclassp = ptCompareHistogramClassVector->at(histogrami);
+            TH1F* curhistogramclone = (TH1F*) curhistogramclassp->Seed->Clone();
+            heighestval1 = (curhistogramclone->GetMaximum()>heighestval1?curhistogramclone->GetMaximum():heighestval1);            
+            
+            curhistogramclone = (TH1F*) curhistogramclassp->Sum->Clone();
+            heighestval2 = (curhistogramclone->GetMaximum()>heighestval2?curhistogramclone->GetMaximum():heighestval2);
+            
+            curhistogramclone = (TH1F*) curhistogramclassp->Veto->Clone();
+            heighestval3 = (curhistogramclone->GetMaximum()>heighestval3?curhistogramclone->GetMaximum():heighestval3);
+            
+            curhistogramclone = (TH1F*) curhistogramclassp->Noise->Clone();
+            heighestval4 = (curhistogramclone->GetMaximum()>heighestval4?curhistogramclone->GetMaximum():heighestval4);
+        }
         for (UInt_t histogrami=0; histogrami < ptCompareHistogramClassVector->size(); histogrami++)
         {
             HistogramType* curhistogramclassp = ptCompareHistogramClassVector->at(histogrami);
@@ -215,13 +319,15 @@ Bool_t plotAllRuns(vector<HistogramType*>* ptCompareHistogramClassVector)
 //             Tl.SetNDC();
 //             Tl.DrawText(0.3, 0.2, "Titel titel");
             //TPaveText *t = new TPaveText(0.0, 0.9, 0.3, 1.0, "brNDC"); // left-up
-            curhistogramclone->SetLineColor(rootcolors[histogrami%13]);           
+            curhistogramclone->SetLineColor(rootcolors[histogrami%13]);    
+            //curhistogramclone->GetXaxis()->SetRange(0,curhistogramclone->GetXaxis()->GetNbins());
             curhistogramclone->Draw("SAME");
             legendEntry = Form("%d %s", curhistogramclassp->labbook->runnumber, curhistogramclone->GetTitle());
             leg1->AddEntry(curhistogramclone, legendEntry, "l");
             leg1->Draw("SAME");
-            lastbin1 = (curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1))>lastbin1)?curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1)):lastbin1;
+            lastbin1 = (curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(0,1))>lastbin1)?curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(0,1)):lastbin1;
             curhistogramclone->SetAxisRange(0,lastbin1*1.1,"X");
+            curhistogramclone->GetYaxis()->SetRangeUser(5,heighestval1*4);
             gPad->SetLogy(1);
             owntitle->Clear();
             owntitle->AddText(trimRunnumberAtBegin(curhistogramclone->GetName()));
@@ -231,21 +337,31 @@ Bool_t plotAllRuns(vector<HistogramType*>* ptCompareHistogramClassVector)
             curhistogramclone = (TH1F*) curhistogramclassp->Sum->Clone();
             curhistogramclone->SetLineColor(rootcolors[histogrami%13]);
             curhistogramclone->Draw("SAME");
-            leg1->Draw("SAME");
-            lastbin2 = (curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1))>lastbin2)?curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1)):lastbin2;
+            hs->Add(curhistogramclone);
+            leg2->AddEntry(curhistogramclone, legendEntry, "l");
+            leg2->Draw("SAME");
+//             hs->Add(leg1);
+            lastbin2 = (curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(1,1))>lastbin2)?curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(1,1)):lastbin2;
             curhistogramclone->SetAxisRange(0,lastbin2*1.1,"X");
+//             heighestval2 = (curhistogramclone->GetMaximum()>heighestval2?curhistogramclone->GetMaximum():heighestval2);
+            curhistogramclone->GetYaxis()->SetRangeUser(5,heighestval2*4);
+            curhistogramclone->Draw("SAME");
             gPad->SetLogy(1);
             owntitle2->Clear();
             owntitle2->AddText(trimRunnumberAtBegin(curhistogramclone->GetName()));
+//             hs->Add(owntitle2);
             owntitle2->Draw("SAME");
             
             canvas->cd(3);
             curhistogramclone = (TH1F*) curhistogramclassp->Veto->Clone();
             curhistogramclone->SetLineColor(rootcolors[histogrami%13]);
             curhistogramclone->Draw("SAME");
-            leg1->Draw("SAME");
-            lastbin3 = (curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1))>lastbin3)?curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1)):lastbin3;
-            curhistogramclone->SetAxisRange(0,lastbin3*1.1,"X");
+            leg3->AddEntry(curhistogramclone, legendEntry, "l");
+            leg3->Draw("SAME");
+            lastbin3 = (curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(0,1))>lastbin3)?curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(0,1)):lastbin3;
+            curhistogramclone->SetAxisRange(1,lastbin3*1.1,"X");            
+//             heighestval3 = (curhistogramclone->GetMaximum()>heighestval3?curhistogramclone->GetMaximum():heighestval3);
+            curhistogramclone->GetYaxis()->SetRangeUser(0,heighestval3*1.2);
             owntitle3->Clear();
             owntitle3->AddText(trimRunnumberAtBegin(curhistogramclone->GetName()));
             owntitle3->Draw("SAME");
@@ -255,15 +371,18 @@ Bool_t plotAllRuns(vector<HistogramType*>* ptCompareHistogramClassVector)
             curhistogramclone->SetLineColor(rootcolors[histogrami%13]);
             curhistogramclone->Draw("SAME");
             legendEntry = Form("%d Noise: %.2f + %.2f - %.2f",curhistogramclassp->labbook->runnumber, curhistogramclassp->avgNoise, curhistogramclassp->avgNoisePlus, curhistogramclassp->avgNoiseMinus);
-            leg2->AddEntry(curhistogramclone, legendEntry, "l");
-            leg2->Draw();
+            leg4->AddEntry(curhistogramclone, legendEntry, "l");
+            leg4->Draw();            
+//             heighestval4 = (curhistogramclone->GetMaximum()>heighestval4?curhistogramclone->GetMaximum():heighestval4);
+            curhistogramclone->GetYaxis()->SetRangeUser(0,heighestval4*1.4);
             owntitle4->Clear();
             owntitle4->AddText(trimRunnumberAtBegin(curhistogramclone->GetName()));
             owntitle4->Draw("SAME");
         }
-        
+        //TText T; T.SetTextFont(42); T.SetTextAlign(21);
+//                 canvas->cd(2); hs->Draw("nostack same");// T.DrawTextNDC(.5,.95,"Option \"nostack\"");
+//         canvas->BuildLegend();
         canvas->Update();
-        //gStyle->SetOptTitle(1);
         
         TImageDump *img = new TImageDump(savepathresults + "/" + canvastitle + ".png");
         canvas->Paint();
@@ -276,7 +395,7 @@ Bool_t plotAllRuns(vector<HistogramType*>* ptCompareHistogramClassVector)
         f->Write();
         
         MSaveBigPNG(savepathresults + "/" + canvastitle + ".png");
-        
+//         gROOT->SetStyle("RadHard_AutoTitle");
         return 0;
     }
     return 1;
@@ -287,61 +406,84 @@ Bool_t printSummaryTable(vector<HistogramType*>* ptCompareHistogramClassVector)
     if (ptCompareHistogramClassVector->size()>0)
     { 
         if (testifMixingCalibration(ptCompareHistogramClassVector)) return 1;
+        
+        system("mkdir "+ runs[0]->savepathresults + " -p");
+        TString filename = runs[0]->savepathresults + "/Summary";
+        TString filecontent = "";
+        for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
+        {
+            if (runs[runi] != nullptr)
+            {
+                if (!runs[runi]->error)
+                {
+                    filename+= Form("_%d",runs[runi]->labbook.runnumber);
+                }
+            }
+        }
+        filename+=".txt";
+        fstream* fout = new fstream(filename,ios::out);        
+        
         const int width = 15;
         cout << endlr << colorwhite << right << setw(width*9) << setfill('=') << " " << endl;
-        cout << left << setw(width*1) << setfill(' ')  << "Cut type: "<< left << setw(width*8) << setfill(' ')  << ptCompareHistogramClassVector->at(0)->histogramdescription << endl;
-
-        cout << left << setw(width-5) << setfill(' ') << "Runnumber";
-        cout << left << setw(width-10) << setfill(' ') << "Chp#";
-        cout << left << setw(width-10) << setfill(' ') << "Mtrx";
+        cout << left << setw(width*1) << setfill(' ')  << "Cut type: "<< left << setw(width*8) << setfill(' ')  << ptCompareHistogramClassVector->at(0)->histogramdescription << endl; filecontent += Form("Cut type: %s\n", ptCompareHistogramClassVector->at(0)->histogramdescription.Data());
+        cout << left << setw(width-5) << setfill(' ') << "Runnumber"; filecontent += Form("Runnumber\t");
+        cout << left << setw(width-5) << setfill(' ') << "Frames"; filecontent += Form("Frames\t");
+        cout << left << setw(width-10) << setfill(' ') << "Chp#"; filecontent += Form("Chp#\t");
+        cout << left << setw(width-10) << setfill(' ') << "Mtrx"; filecontent += Form("Mtrx\t");
         Float_t printradion = 0;
         for (vector<HistogramType*>::iterator curHistogramClass = ptCompareHistogramClassVector->begin(); curHistogramClass != ptCompareHistogramClassVector->end(); curHistogramClass++)
             printradion += (*curHistogramClass)->labbook->radDoseIon;
-        if (printradion != 0)  cout << left << setw(width-5) << setfill(' ') << "Rad. ion";
+        if (printradion > 0) {  cout << left << setw(width-5) << setfill(' ') << "Rad. ion"; filecontent += Form("Rad. ion\t"); }
         Float_t printradnonion = 0;
         for (vector<HistogramType*>::iterator curHistogramClass = ptCompareHistogramClassVector->begin(); curHistogramClass != ptCompareHistogramClassVector->end(); curHistogramClass++)
             printradnonion += (*curHistogramClass)->labbook->radDoseNonIon;
-        if (printradnonion != 0)  cout << left << setw(width-5) << setfill(' ') << "Rad. non-ion";
+        if (printradnonion > 0) {  cout << left << setw(width-8) << setfill(' ') << "N.Rad"; filecontent += Form("N.Rad\t"); }
         Float_t printCCE = 0;
         for (vector<HistogramType*>::iterator curHistogramClass = ptCompareHistogramClassVector->begin(); curHistogramClass != ptCompareHistogramClassVector->end(); curHistogramClass++) {
             printCCE += (*curHistogramClass)->CCE_in_Perc_1; printCCE += (*curHistogramClass)->CCE_in_Perc_25; 
         }
-        if (printCCE != 0)   cout << left << setw(width) << setfill(' ') << "CCE_1";
-        if (printCCE != 0)   cout << left << setw(width) << setfill(' ') << "CCE_25";
+        if (printCCE > 0) { cout << left << setw(width) << setfill(' ') << "CCE_1"; filecontent += Form("CCE_1\t"); }
+        if (printCCE > 0) { cout << left << setw(width) << setfill(' ') << "CCE_25"; filecontent += Form("CCE_25\t"); }
         Float_t printStoN = 0;
         for (vector<HistogramType*>::iterator curHistogramClass = ptCompareHistogramClassVector->begin(); curHistogramClass != ptCompareHistogramClassVector->end(); curHistogramClass++)
             printStoN += (*curHistogramClass)->StoN;
-        if (printStoN != 0)  cout << left << setw(width) << setfill(' ') << "S/N";
+        if (printStoN > 0) { cout << left << setw(width) << setfill(' ') << "S/N"; filecontent += Form("S/N\t"); }
         Float_t printIntegral = 0;
         for (vector<HistogramType*>::iterator curHistogramClass = ptCompareHistogramClassVector->begin(); curHistogramClass != ptCompareHistogramClassVector->end(); curHistogramClass++)
             printIntegral += (*curHistogramClass)->sr90IntegralVal;
-        if (printIntegral != 0)  cout << left << setw(width) << setfill(' ') << "Integral";
-        cout << left << setw(width) << setfill(' ') << "Seed Peak";
-        cout << left << setw(width) << setfill(' ') << "Veto Peak";
-        cout << left << setw(width) << setfill(' ') << "Noise";
-        cout << left << setw(width) << setfill(' ') << "Noise threshold";
-        //cout << left << setw(width) << setfill(' ') << "Frames";
-        cout << endl;
+        if (printIntegral > 0.0) { cout << left << setw(width+1) << setfill(' ') << "Integral"; filecontent += Form("Integral\t"); }
+        cout << left << setw(width) << setfill(' ') << "Seed Peak"; filecontent += Form("Seed Peak\t");
+        cout << left << setw(width) << setfill(' ') << "Veto Peak"; filecontent += Form("Veto Peak\t");
+        cout << left << setw(width+2) << setfill(' ') << "Veto Integral"; filecontent += Form("Veto Integral\t");
+        cout << left << setw(width-2) << setfill(' ') << "Noise"; filecontent += Form("Noise\t");
+        cout << left << setw(width) << setfill(' ') << "Noise threshold"; filecontent += Form("Noise threshold\t");
+        cout << endl; filecontent += Form("\n");
         for (UInt_t histogrami=0; histogrami < ptCompareHistogramClassVector->size(); histogrami++)
         {
             HistogramType* curhistogramclassp = ptCompareHistogramClassVector->at(histogrami);
-            cout << left << setw(width-5) << setfill(' ') << curhistogramclassp->labbook->runnumber;
-            cout << left << setw(width-10) << setfill(' ') << curhistogramclassp->labbook->chip;
-            cout << left << setw(width-10) << setfill(' ') << curhistogramclassp->labbook->matrix;
-            if (printradion != 0) cout << left << setw(width-5) << setfill(' ') << curhistogramclassp->labbook->radDoseIon;
-            if (printradnonion != 0) cout << left << setw(width-5) << setfill(' ') << curhistogramclassp->labbook->radDoseNonIon;
-            if (printCCE != 0) cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->CCE_in_Perc_1,ptCompareHistogramClassVector->at(0)->CCE_in_Perc_1);
-            if (printCCE != 0) cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->CCE_in_Perc_25,ptCompareHistogramClassVector->at(0)->CCE_in_Perc_25);
-            if (printStoN != 0)  cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->StoN,ptCompareHistogramClassVector->at(0)->StoN);
-            if (printIntegral != 0)  cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->sr90IntegralVal,ptCompareHistogramClassVector->at(0)->sr90IntegralVal);
-            cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->posSeed,ptCompareHistogramClassVector->at(0)->posSeed);
-            cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->posVeto,ptCompareHistogramClassVector->at(0)->posVeto);
-            cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->avgNoise,ptCompareHistogramClassVector->at(0)->avgNoise);
-            cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->noisethresholdborder,ptCompareHistogramClassVector->at(0)->noisethresholdborder);
-            //cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->frames_found,ptCompareHistogramClassVector->at(0)->frames_found);
-            cout << "" << endl;
+            cout << left << setw(width-5) << setfill(' ') << curhistogramclassp->labbook->runnumber; filecontent += Form("%d\t", curhistogramclassp->labbook->runnumber);
+//             cout << "1" << endl;
+            cout << left << setw(width-5) << setfill(' ') << to_str_w_prec(curhistogramclassp->frames_found); filecontent += Form("%s\t", to_str_w_prec(curhistogramclassp->frames_found).c_str());
+//             cout << "2" << endl;
+            cout << left << setw(width-10) << setfill(' ') << curhistogramclassp->labbook->chip; filecontent += Form("%s\t", curhistogramclassp->labbook->chip.Data());
+//             cout << "!" << endl;
+            cout << left << setw(width-10) << setfill(' ') << curhistogramclassp->labbook->matrix; filecontent += Form("%s\t", curhistogramclassp->labbook->matrix.Data());
+            if (printradion > 0) { cout << left << setw(width-5) << setfill(' ') << curhistogramclassp->labbook->radDoseIon; filecontent += Form("%.1f\t", curhistogramclassp->labbook->radDoseIon); }
+            if (printradnonion > 0) { cout << left << setw(width-8) << setfill(' ') << curhistogramclassp->labbook->radDoseNonIon; filecontent += Form("%.1f\t", curhistogramclassp->labbook->radDoseNonIon); }
+            if (printCCE > 0) { cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->CCE_in_Perc_1,ptCompareHistogramClassVector->at(0)->CCE_in_Perc_1); filecontent += Form("%s\t", printTableElement(curhistogramclassp->CCE_in_Perc_1,ptCompareHistogramClassVector->at(0)->CCE_in_Perc_1).c_str()); }
+            if (printCCE > 0) { cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->CCE_in_Perc_25,ptCompareHistogramClassVector->at(0)->CCE_in_Perc_25); filecontent += Form("%s\t", printTableElement(curhistogramclassp->CCE_in_Perc_25,ptCompareHistogramClassVector->at(0)->CCE_in_Perc_25).c_str()); }
+            if (printStoN > 0) {  cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->StoN,ptCompareHistogramClassVector->at(0)->StoN); filecontent += Form("%s\t", printTableElement(curhistogramclassp->StoN,ptCompareHistogramClassVector->at(0)->StoN).c_str()); }
+            if (printIntegral > 0.0) {  cout << left << setw(width+1) << setfill(' ') << printTableElement(curhistogramclassp->sr90IntegralVal,ptCompareHistogramClassVector->at(0)->sr90IntegralVal); filecontent += Form("%s\t", printTableElement(curhistogramclassp->sr90IntegralVal,ptCompareHistogramClassVector->at(0)->sr90IntegralVal).c_str()); }
+            cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->posSeed,ptCompareHistogramClassVector->at(0)->posSeed); filecontent += Form("%s\t", printTableElement(curhistogramclassp->posSeed,ptCompareHistogramClassVector->at(0)->posSeed).c_str());
+            cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->posVeto,ptCompareHistogramClassVector->at(0)->posVeto); filecontent += Form("%s\t", printTableElement(curhistogramclassp->posVeto,ptCompareHistogramClassVector->at(0)->posVeto).c_str());
+            cout << left << setw(width+2) << setfill(' ') << printTableElement(curhistogramclassp->integralVeto,ptCompareHistogramClassVector->at(0)->integralVeto,2); filecontent += Form("%s\t", printTableElement(curhistogramclassp->integralVeto,ptCompareHistogramClassVector->at(0)->integralVeto,4).c_str());
+            cout << left << setw(width-2) << setfill(' ') << printTableElement(curhistogramclassp->avgNoise,ptCompareHistogramClassVector->at(0)->avgNoise); filecontent += Form("%s\t", printTableElement(curhistogramclassp->avgNoise,ptCompareHistogramClassVector->at(0)->avgNoise).c_str());
+            cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->noisethresholdborder,ptCompareHistogramClassVector->at(0)->noisethresholdborder); filecontent += Form("%s\t", printTableElement(curhistogramclassp->noisethresholdborder,ptCompareHistogramClassVector->at(0)->noisethresholdborder).c_str());
+            cout << "" << endl; filecontent += Form("\n");
         }
         cout << right << setw(width*9) << setfill('=') << " " << endl;
+        *fout << filecontent << endl;
+        fout->close();
     }
     return 0;
 }
@@ -363,10 +505,3 @@ string to_str_w_prec(const Float_t a_value, const int precision)
     }
     return out.str();
 }
-
-TString trimRunnumberAtBegin(TString str) {
-    size_t i = 0;
-    while(isdigit(str(i++)));
-    return str.Remove(0, i);
-}
-
index 148b1abf50a4997a48d1bf06a599f279e637ffdc..dd08494e80850986f3921b05634983af01f5c660 100644 (file)
@@ -100,6 +100,7 @@ Bool_t HistogramType::calibrateHistograms( Float_t gotgain ) {
     calibrated->posSeed = posSeed * gain;
     calibrated->posSum = posSum * gain;
     calibrated->posVeto = posVeto * gain;
+    calibrated->integralVeto = integralVeto * gain;
     calibrated->posSeedPerc = posSeedPerc;
     calibrated->sigmaSeedPerc = sigmaSeedPerc;
     calibrated->avgNoise = avgNoise * gain;
@@ -109,6 +110,7 @@ Bool_t HistogramType::calibrateHistograms( Float_t gotgain ) {
     calibrated->StoN = StoN;
     calibrated->CCE_in_Perc_1 = CCE_in_Perc_1;
     calibrated->CCE_in_Perc_25 = CCE_in_Perc_25;
+    calibrated->noisethresholdborder = noisethresholdborder;
     
     calibrated->iscalibrated = true;
     
@@ -145,28 +147,85 @@ void HistogramType::calibrate2DHistogramCounts(TH2F* &histogrampointernew, TH2F*
     }   
 }
 
+
+Bool_t HistogramType::normalizeHistograms( Int_t got_frames_found ) {
+    if ( got_frames_found <= 0 )
+    {
+        if (labbook->frames_foundDB <= 0)
+        {
+            cout << coloryellow << "Cannot normalize run, no number of frames_found provided." << endlr;
+            return 1;
+        }
+        else
+            frames_found = labbook->frames_foundDB;
+    }
+    else
+        frames_found = got_frames_found;
+    
+    normalized = new HistogramType(histogramdescription+" normalized", cursystempar, cursensorinfo, humanreadablestr, labbook, color, style);
+    if (Seed != 0) normalizeHistogram(normalized->Seed, Seed);
+    if (Sum != 0) normalizeHistogram(normalized->Sum, Sum);
+    if (Veto != 0) normalizeHistogram(normalized->Veto, Veto);
+    if (SeedPerc != 0) normalized->SeedPerc = SeedPerc;
+    normalized->Noise = (TH1F*)Noise->Clone();
+    normalized->histAvgCluster = (TH2F*)histAvgCluster->Clone();
+    normalized->frames_found = frames_found;
+    normalized->posSeed = posSeed;
+    normalized->posSum = posSum;
+    normalized->posVeto = posVeto;
+    normalized->integralVeto= integralVeto;
+    normalized->posSeedPerc = posSeedPerc;
+    normalized->sigmaSeedPerc = sigmaSeedPerc;
+    normalized->noisethresholdborder = noisethresholdborder;
+    normalized->avgNoise = avgNoise;
+    normalized->avgNoisePlus = avgNoisePlus;
+    normalized->avgNoiseMinus = avgNoiseMinus;
+    normalized->sr90IntegralVal = sr90IntegralVal;
+    normalized->StoN = StoN;
+    normalized->CCE_in_Perc_1 = CCE_in_Perc_1;
+    normalized->CCE_in_Perc_25 = CCE_in_Perc_25;
+    normalized->iscalibrated = iscalibrated;
+    
+    normalized->isnormalized = true;
+    
+    return 1;    
+}
+
+void HistogramType::normalizeHistogram(TH1F* &histogrampointernew, TH1F* &histogrampointerold) {
+    histogrampointernew = (TH1F*)histogrampointerold->Clone();
+    histogrampointernew->SetName(Form("%s, norm.", histogrampointerold->GetName()));
+    histogrampointernew->SetTitle(Form("%s, norm.", histogrampointerold->GetTitle())); 
+    int nbins = histogrampointernew->GetXaxis()->GetNbins();    
+    for(int x=0; x <= nbins; x++){
+        histogrampointernew->SetBinContent(x,histogrampointerold->GetBinContent(x)/frames_found*1000000);
+    }
+    histogrampointernew->GetYaxis()->SetTitle(Form("%s\b/(%d/1000000)]",histogrampointernew->GetYaxis()->GetTitle(), frames_found));
+}
+
 Double_t* HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType, Bool_t verbose, Float_t fitstart) {
     Double_t* parameters = 0;
     Float_t posMax = 0;
+    Float_t integralPeak = 0;
     Float_t posMax2 = 0;
     Float_t posMaxValHist = histogrampointer->GetXaxis()->GetXmax();
-    // posMaxValHist/10 for USB system, the value is 90
-    Float_t noiseborder = 90;
+    // empirical value for USB system is 50, should be overwritten in 99% of cases
+    Float_t noiseborder = 50;
     if (fitstart >= 0)
         noiseborder = fitstart;
     else if (noisethresholdborder>=0 )
         noiseborder = noisethresholdborder;
+//         cout << "noisethresholdborder: " << noisethresholdborder << endl; }
     
     if (fitFuncType.EqualTo("gaus")) 
     {
-        histogrampointer->GetXaxis()->SetRange(histogrampointer->GetXaxis()->FindBin(noiseborder),histogrampointer->GetXaxis()->FindBin(posMaxValHist));   // look only for maxima with x greater than noiseborder, cut away noise
+        histogrampointer->GetXaxis()->SetRange(histogrampointer->GetXaxis()->FindBin(noiseborder),histogrampointer->GetXaxis()->FindBin(posMaxValHist));   // look only for maxima with x greater than noiseborder, cut away noise        
         //         Int_t xValMax = histogrampointer->GetBinCenter(histogrampointer->GetMaximumBin());
         TF1* fitFunc = new TF1("fitFunc",fitFuncType,noiseborder,posMaxValHist);
         
         if (TString(histogrampointer->GetName()).Contains("Veto")) 
         {
-//             if (verbose)
-//                 cout << "Range: " << histogrampointer->GetXaxis()->FindBin(noiseborder) << " to " << histogrampointer->GetXaxis()->FindBin(posMaxValHist) << endl;
+//              if (verbose)
+//                  cout << "Range: " << histogrampointer->GetXaxis()->FindBin(noiseborder) << " to " << histogrampointer->GetXaxis()->FindBin(posMaxValHist) << endl;
             Float_t peak1 = histogrampointer->GetMaximumBin();
             Float_t peak2;
 //             if (verbose)
@@ -192,6 +251,7 @@ Double_t* HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType,
             // DEBUG 
 //             if (verbose)
 //             {
+//                 cout << colorred << "    " << histogrampointer->GetName() << "   : " << endlr;
 //                 cout << coloryellow << "noisethresholdborder " << noisethresholdborder << endlr;
 //                 cout << coloryellow << "peak1 " << histogrampointer->GetXaxis()->GetBinCenter(peak1) << endlr;
 //                 cout << coloryellow << "peak1val " << histogrampointer->GetBinContent(peak1) << endlr;
@@ -207,11 +267,12 @@ Double_t* HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType,
             //histogrampointer->Fit(fitFunc, "N,Q,W", "", 70, 500);
             int fittries = 0;
             do {
-//                 cout << fittries <<  ": New range: " <<  histogrampointer->GetXaxis()->GetBinCenter(min+fittries*min/20) << " to " << posMaxValHist << endl;
-                histogrampointer->Fit(fitFunc, "N,Q,W", "", histogrampointer->GetXaxis()->GetBinCenter(min+fittries++*min/20), posMaxValHist);    
+//                cout << fittries <<  ": New range: " <<  histogrampointer->GetXaxis()->GetBinCenter(min+fittries*min/20) << " to " << posMaxValHist << endl;
+                histogrampointer->Fit(fitFunc, "N,Q,W", "", histogrampointer->GetXaxis()->GetBinCenter(min+fittries*min/20), posMaxValHist);    
 //                 cout << colorred << gMinuit->fCstatu.Data() << endlr;            
-            } while (gMinuit->fCstatu.Contains("FAILED") && fittries < 8);
+            } while (gMinuit->fCstatu.Contains("FAILED") && fittries++ < 8);
             posMax = histogrampointer->GetXaxis()->GetBinCenter(histogrampointer->GetMaximumBin()); // Methode 1
+            integralPeak = histogrampointer->Integral(min+fittries*min/20, histogrampointer->GetXaxis()->FindBin(posMaxValHist));
 //             if (verbose)
 //             {
 //                 cout << coloryellow << "min " << histogrampointer->GetXaxis()->GetBinCenter( min ) << endlr;
@@ -219,17 +280,22 @@ Double_t* HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType,
 //             }
             histogrampointer->GetXaxis()->SetRange(histogrampointer->GetXaxis()->FindBin(noiseborder),histogrampointer->GetXaxis()->FindBin(posMaxValHist));   // look only for maxima with x greater than noiseborder, cut away noise
 //             TCanvas* canvas = new TCanvas("2121", "212121212", 900, 700);
-//             histogrampointer->Draw();
-//             fitFunc->DrawCopy("same");
+            //             histogrampointer->Draw();if (verbose)
+            if (verbose)
+              fitFunc->DrawCopy("same");
         } else {
             histogrampointer->Fit(fitFunc, "N,Q,W", "", noiseborder, posMaxValHist);
+            integralPeak = histogrampointer->Integral(histogrampointer->GetXaxis()->FindBin(noiseborder), histogrampointer->GetXaxis()->FindBin(posMaxValHist));
             posMax = fitFunc->GetMaximumX(); // Methode 2
+            if (verbose)
+                fitFunc->Draw("SAME");
         }
-        parameters = (Double_t *)calloc(3, sizeof(Double_t));
+        parameters = (Double_t *)calloc(4, sizeof(Double_t));
         for (Int_t pari=0; pari<3; pari++) {
             //cout << colorcyan << fitFunc->GetParameter(pari) << endlr;
             parameters[pari]=fitFunc->GetParameter(pari);
         }
+        parameters[3]=integralPeak;
         Float_t sigma = fitFunc->GetParameter(2);
         posMax2 = fitFunc->GetMaximumX(); // Methode 2
 //         if (verbose)
@@ -237,8 +303,8 @@ Double_t* HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType,
         Float_t peakposdifperc = abs(posMax-posMax2)/min(posMax,posMax2);
         if (sigma > 260 || peakposdifperc>0.3)
         {
-            if (verbose)
-            {
+//             if (verbose)
+//             {
                 if (sigma > 260)
                 {
                     cout << "Sigma suspiciously height when fitting " << histogrampointer->GetName() << " spectrum: " << sigma  << endl;
@@ -249,14 +315,14 @@ Double_t* HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType,
                     cout << "Maximum peak position and fit gaussian peak position doesn't match in " << histogrampointer->GetName() << " spectrum. Difference: " <<  peakposdifperc*100 <<" % " << endl;
                     cout << colorred << "  Could not find " << histogrampointer->GetName() << " peak" << endlr;
                 }
-            }
-            parameters[1] = 0;
+//             }
+            parameters[1] = -1;
             return parameters;
         }
         else if (sigma > 40 || peakposdifperc>0.1)
         {
-            if (verbose)
-            {
+//             if (verbose)
+//             {
                 if (sigma > 260)
                 {
                     cout << "Sigma or  suspiciously height when fitting " << histogrampointer->GetName() << " spectrum: " << sigma  << endl;
@@ -267,7 +333,7 @@ Double_t* HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType,
                     cout << "Maximum peak position and fit gaussian peak position in " << histogrampointer->GetName() << " have difference of " <<  peakposdifperc*100 <<" % " << endl;
                     cout << coloryellow << "  Please check " << histogrampointer->GetName() << " peak position: " << colorreset << colorwhite << posMax  << endlr;
                 }
-            }
+//             }
         }       
         
 //         TString  legendEntry = TString(Form("%s","Gaus fit"));
@@ -281,37 +347,40 @@ Double_t* HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType,
     }
     else if (fitFuncType=="landau") 
     {
+        if (posVeto > 0)
+            posMaxValHist = posVeto-posVeto/8;
         histogrampointer->GetXaxis()->SetRange(histogrampointer->GetXaxis()->FindBin(noiseborder),histogrampointer->GetXaxis()->FindBin(posMaxValHist));   // look only for maxima with x greater than noiseborder, cut away noise
         //         Int_t xValMax = histogrampointer->GetBinCenter(histogrampointer->GetMaximumBin());
         TF1* fitFunc = new TF1("fitFunc",fitFuncType,noiseborder,posMaxValHist);
-        
+        parameters = (Double_t *)calloc(3, sizeof(Double_t));        
         Float_t fitMax1 = 1000;
         Float_t fitMax2 = 1000;
         Float_t fitMax3 = 1000;
         Float_t minFitMax = 1000;
         Float_t maxFitMax = 1000;
         histogrampointer->Fit(fitFunc, "N,Q,W", "", noiseborder, posMaxValHist);
-        parameters = (Double_t *)calloc(3, sizeof(Double_t));
         for (Int_t pari=0; pari<3; pari++)
             parameters[pari]=fitFunc->GetParameter(pari);
-        
-        posMax = fitFunc->GetParameter(1); // new method, just use MPV of fit, as noise border is well known. Compare with old method anyway and warn if something suspecious.
+//         posMax = fitFunc->GetParameter(1); // new method, just use MPV of fit, as noise border is well known. Compare with old method anyway and warn if something suspecious.
+        parameters[1]=fitFunc->GetMaximumX();
+        posMax = fitFunc->GetMaximumX(); // new method, just use MPV of fit, as noise border is well known. Compare with old method anyway and warn if something suspecious.
 //         cout << "fitFunc->GetParameter(0): " << fitFunc->GetParameter(0) << endl;
 //         cout << "fitFunc->GetParameter(1): " << fitFunc->GetParameter(1) << endl;
 //         cout << "fitFunc->GetParameter(2): " << fitFunc->GetParameter(2) << endl;
+//         cout << "fitFunc->GetMaximumX(): " << fitFunc->GetMaximumX() << endl;
 //         cout << colorred << "noiseborder: " << noiseborder << endlr;
         fitMax1 = fitFunc->GetMaximumX();
-//                      fitFunc->DrawCopy("same");         
+//                       fitFunc->DrawCopy("same");         
         histogrampointer->Fit(fitFunc, "N,Q,W", "", noiseborder, fitMax1*1.1);
         fitMax2 = fitFunc->GetMaximumX();
         fitFunc->SetLineColor(kBlue);
         fitFunc->SetLineStyle(2); // dashed
-//                      fitFunc->DrawCopy("same");
+//                       fitFunc->DrawCopy("same");
         histogrampointer->Fit(fitFunc, "N,Q,W", "", fitMax1*0.9, posMaxValHist);
         //             histogrampointer->Fit(fitFunc, "N,Q,W", "", fitMax1, histogrampointer->GetBinCenter(bini));
         fitMax3 = fitFunc->GetMaximumX();
         fitFunc->SetLineColor(kGreen);
-//                      fitFunc->DrawCopy("same");
+//                       fitFunc->DrawCopy("same");
         fitFunc->SetLineStyle(1); // normal for the following fits
         
         //Sort the three fits and save error estimation
@@ -355,13 +424,86 @@ Double_t* HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType,
         parameters = (Double_t *)calloc(4, sizeof(Double_t));
         for (Int_t pari=0; pari<4; pari++)
             parameters[pari]=fitFcn->GetParameter(pari);
-        if (verbose)
-        {
+//         if (verbose)
+//         {
             Printf("width: %.6f ",fitFcn->GetParameter(1));
             cout << "width:  " << fitFcn->GetParameter(1) << endl;
             cout << "peak:   " << fitFcn->GetParameter(2) << endl;
             cout << "y-shift:" << fitFcn->GetParameter(3) << endl;
+//         }
+    } else if (fitFuncType=="GaussTail")
+    {
+//         cout << colorcyan << "maxvalhist: " << posMaxValHist << endlr;
+//         cout << colorcyan << "noiseborder: " << noiseborder << endlr;
+//         histogrampointer->GetXaxis()->SetRange(noiseborder,histogrampointer->FindLastBinAbove(0));   // look only for maxima with x greater than noiseborder, cut away noise
+        histogrampointer->GetXaxis()->SetRange(noiseborder,posMaxValHist);   // look only for maxima with x greater than noiseborder, cut away noise
+//         histogrampointer->GetXaxis()->SetRangeUser(noiseborder,posMaxValHist);
+        TF1* fitFunc = new TF1("fitFunc",GaussTail,noiseborder,posMaxValHist,6);
+        parameters = (Double_t *)calloc(6, sizeof(Double_t));  
+        const Double_t def_amplitude=459.951;
+        const Double_t def_peakcenter=histogrampointer->GetBinCenter(histogrampointer->GetMaximumBin());
+//         cout << colorcyan << "def_peakcenter: " << def_peakcenter << endlr;
+        const Double_t def_gausssig=-8.68052;
+        const Double_t def_distgauss=20.4;
+        const Double_t def_bgslope=0;
+        const Double_t def_bgoffs=histogrampointer->GetBinContent(histogrampointer->FindBin((noiseborder+def_peakcenter)/2));
+        
+        fitFunc->SetLineWidth(4);
+        fitFunc->SetLineColor(kGreen);
+        // set start values for some parameters
+        fitFunc->SetParName(0,"amplitude of peak");
+        fitFunc->SetParameter(0,def_amplitude);
+        fitFunc->SetParName(1,"peak centroid");
+        fitFunc->SetParameter(1,def_peakcenter);
+        fitFunc->SetParLimits(1,def_peakcenter*0.8,def_peakcenter*1.2);
+        fitFunc->SetParName(2,"Gaussian sigma");
+        fitFunc->SetParameter(2,def_gausssig);
+        fitFunc->SetParName(3,"Distance from Gauss");
+        fitFunc->SetParameter(3,def_distgauss);
+        fitFunc->SetParLimits(3,0,def_distgauss*2);
+        fitFunc->SetParName(4,"background slope");
+        fitFunc->SetParameter(4,def_bgslope);
+        fitFunc->SetParLimits(4,def_bgslope-0.1,def_bgslope+0.1);
+        fitFunc->SetParName(5,"background offset");
+        fitFunc->SetParameter(5,def_bgoffs);
+//         fitFunc->SetParLimits(5,def_bgoffs*0.8,def_bgoffs*1.2);
+//         cout << "def_bgoffs from " << def_bgoffs*0.8 << " to " << def_bgoffs*1.2 << endl;
+        
+        int fittries = 0;
+        do {
+            //                cout << fittries <<  ": New range: " <<  histogrampointer->GetXaxis()->GetBinCenter(min+fittries*min/20) << " to " << posMaxValHist << endl;
+            histogrampointer->Fit(fitFunc, "N,M,Q,W", "", noiseborder, posMaxValHist);
+            if (gMinuit->fCstatu.Contains("FAILED")) {
+                fitFunc->SetParameter(0,def_amplitude*(1.0-0.1*++fittries));
+                fitFunc->SetParameter(3,def_distgauss*(exp(-fittries/2.0)));
+                fitFunc->SetParameter(1,def_peakcenter);
+                fitFunc->SetParameter(2,def_gausssig);
+                fitFunc->SetParameter(4,def_bgslope);
+                fitFunc->SetParameter(5,def_bgoffs);
+            }
+//             cout << colorred << gMinuit->fCstatu.Data() << " fit tries: " << fittries << endlr;            
+        } while (gMinuit->fCstatu.Contains("FAILED") && fittries < 10);
+         
+        parameters = (Double_t *)calloc(6, sizeof(Double_t));
+        for (Int_t pari=0; pari<6; pari++)
+        {
+            parameters[pari]=fitFunc->GetParameter(pari);
+//             fitFunc->SetParameter(pari,parameters[pari]);            
         }
+        fitFunc->FixParameter(1,parameters[1]+histogrampointer->GetBinWidth(0));            
+        histogrampointer->Fit(fitFunc, "N,M,W,Q", "", noiseborder, posMaxValHist);   
+        
+        for (Int_t pari=0; pari<6; pari++)
+            parameters[pari]=fitFunc->GetParameter(pari);     
+
+//             DEBUG
+//         TCanvas* canvas = new TCanvas(histogrampointer->GetName(), histogrampointer->GetName(), 900, 700);
+//         histogrampointer->Draw();
+//         fitFunc->Draw("SAME");
+        
+        if (verbose)
+            fitFunc->Draw("SAME");
+        
     }
     
     return parameters;
@@ -413,7 +555,7 @@ Bool_t HistogramType::FindNoisethresholdborder(TH1F* histogrampointer, Bool_t ov
         
         do {
             Float_t curval=smoothedcurce->GetBinContent(bini++);
-            if (curval*0.95 <= smoothedcurce->GetBinContent(bini))
+            if (curval*1.05 <= smoothedcurce->GetBinContent(bini))
             {
                 falling = 0;
                 noisepeakcandidate = bini;
@@ -538,5 +680,29 @@ Double_t HistogramType::lorentzianPeak(Double_t *x, Double_t *par) {
     + .25*par[1]*par[1]);
 }
 
+// The fit function will perform a loop which ends once the
+// function reaches the X value where the low-energy tail
+// ends and the Gaussian begins.  A modified form of the
+// Gaussian is used in this region (Koskelo et al., 1996):
+// f(x) = Ae^(C (2x-2u+C) / (2q^2) ) , for x < u-C, where u is the
+// peak centroid, C is the distance from the centroid to the point
+// where the Gaussian behavior begins and the tailing ends,
+// q is the Gaussian sigma, and A is the amplitude of the peak. 
+Double_t HistogramType::GaussTail(Double_t *x, Double_t *par) {
+    // par[0] = amplitude of peak
+    // par[1] = peak centroid
+    // par[2] = Gaussian sigma
+    // par[3] = Distance before par[3] where shape deviates from Gaussian
+    // par[4] = background slope
+    // par[5] = background offset
+    Double_t bg, offset, rgauss, rtail, rtn;
+    offset = par[1] - par[3];
+    bg = par[4]*x[0] + par[5];
+    rgauss =  par[0]*exp(-pow(x[0] - par[1],2)/(2*pow(par[2],2)));
+    rtail = par[0]*exp(par[3]*(2*x[0] - 2*par[1] + par[3])/(2*pow(par[2],2)));
+    rtn = (x[0] < offset)? rtail : rgauss;
+    return (rtn + bg);
+}
+
 #endif
 
index 43e310bd6b1903a2e17cfe9e72d783393efebea5..9e27c0755cd135113bdbe609e52735ef854fe8f0 100644 (file)
@@ -67,7 +67,11 @@ private:
     //*****************  
     /**
      * @brief rescales one specific histogram from ADU to electrons */
-    void calibrateHistogram(TH1F* &histogrampointernew, TH1F* &histogrampointerold);  
+    void calibrateHistogram(TH1F* &histogrampointernew, TH1F* &histogrampointerold); 
+    
+    /**
+     * @brief normalizes one specific histogram with #frames_found, so it can be compared graphically */
+    void normalizeHistogram(TH1F* &histogrampointernew, TH1F* &histogrampointerold);
     
     //*****************
     // OTHER
@@ -81,6 +85,11 @@ private:
     /**
      * @brief Lorenzian Peak function */
     static Double_t lorentzianPeak(Double_t *x, Double_t *par);
+    
+    /**
+     * @brief Gaussian with tail and background function */
+    static Double_t GaussTail(Double_t *x, Double_t *par);    
+        
    
 
 public:    
@@ -120,6 +129,8 @@ public:
     Float_t posSum=0;
     /// fitted position of the calibration peak of Fe55-beta-photons in the seed spectrum, from a run best suited to the current
     Float_t posVeto=0;
+    /// fitted position of the calibration peak of Fe55-beta-photons in the seed spectrum, from a run best suited to the current
+    Double_t integralVeto=0;
     
     /// Average Noise value
     Float_t avgNoise = 0;
@@ -173,6 +184,10 @@ public:
     Float_t CCE_in_Perc_1=0;
     /// Signal to noise ratio
     Float_t StoN=0;
+    /// The number of frames used to normalize the histograms
+    Int_t frames_found = 0;
+    /// The number of frames used to normalize the histograms
+    Bool_t isnormalized = false;
     /// stores information from the SQL database of a given run
     labbooksctruct* labbook;
     
@@ -183,6 +198,9 @@ public:
     /**
      * @brief rescales all histograms from ADU to electrons */
     Bool_t calibrateHistograms( Float_t gotgain );
+    /**
+     * @brief normalizes all histograms to the number of frames used in the histograms */
+    Bool_t normalizeHistograms( Int_t got_frames_found );
     /**
      * @brief rescales one specific histogram bin content from ADU to electrons */     
     void calibrate2DHistogramCounts(TH2F* &histogrampointernew, TH2F* &histogrampointerold );
@@ -236,6 +254,9 @@ public:
     /// pointer to calibrated HistogramType instance of this class
     HistogramType* calibrated = 0;
     
+    /// pointer to rscaled HistogramType instance of this class
+    HistogramType* normalized = 0;
+    
 };
 
 #endif
\ No newline at end of file
index 2cc163282fc2f00a1509d2f23f0b7a36e81c8f59..e48397b99c7e7bed21ecff7874aeb3bad1e66b57 100644 (file)
@@ -828,8 +828,8 @@ bool MAPS::InitialDynNoise(Int_t startframe, Int_t frames) {
         for(Int_t framei=startframe; framei<frames+startframe; framei++)
         {
             getFrame(framei);
-            //             cout << "RAW CDS signal, frame: "<< framei;;
-            //             debugStream(fCdsmatrix, fPixels, fColumns,3);
+//                         cout << "RAW CDS signal, frame: "<< framei;;
+//                         debugStream(fCdsmatrix, fPixels, fColumns,3);
             
             for(Int_t pixeli=0; pixeli<fPixels; pixeli++)
             {
index f9e121b7f08b63cab63d98a0a36ddbbb025ea65c..19c1419790000b60e242c726ffd4010b1687f94f 100644 (file)
@@ -40,7 +40,7 @@ Run::Run(Int_t runnumber, Int_t loopi)
     //db = TSQLServer::Connect("mysql://jspc29.x-matter.uni-frankfurt.de","radhard","mimosa88");
     try 
     {
-        string selectquery = prepareSQLStatement("select `System`, `TempCooling`, COALESCE(`TempChipStart`,-10000) as `TempChipStart`, COALESCE(`TempChipEnd`,-10000) as `TempChipEnd`, `ChipNum`, `RadiationSource`, `Matrix`, `Clock`, `StorePath`, `ChipGen`,COALESCE(`VetoPeak`,-1) as `VetoPeak`,COALESCE(`SeedPeak`,-1) as `SeedPeak`,COALESCE(`SumPeak`,-1) as `SumPeak`,COALESCE(`Gain`,-1) as `Gain`,COALESCE(`Avg.Noise`,-1) as `Avg.Noise`,COALESCE(`Avg.Noise+`,-1) as `Avg.Noise+`,COALESCE(`Avg.Noise-`,-1) as `Avg.Noise-`,COALESCE(`CCE_1`,-1) as `CCE_1`,COALESCE(`CCE_25`,-1) as `CCE_25`,COALESCE(`Frames_found`,-1) as `Frames_found`,COALESCE(`Sr90IntegralVal`,-1) as `Sr90IntegralVal`,COALESCE(`StoN`,-1) as `StoN` from `radhard`.`labbook` WHERE `runnumber`=" + numberToString<>(labbook.runnumber));
+        string selectquery = prepareSQLStatement("select `System`, `TempCooling`, COALESCE(`TempChipStart`,-10000) as `TempChipStart`, COALESCE(`TempChipEnd`,-10000) as `TempChipEnd`, `ChipNum`, `RadiationSource`, `Matrix`, `Clock`, `StorePath`, `ChipGen`,COALESCE(`VetoPeak`,-1) as `VetoPeak`,COALESCE(`SeedPeak`,-1) as `SeedPeak`,COALESCE(`SumPeak`,-1) as `SumPeak`,COALESCE(`Gain`,-1) as `Gain`,COALESCE(`Avg.Noise`,-1) as `Avg.Noise`,COALESCE(`Avg.Noise+`,-1) as `Avg.Noise+`,COALESCE(`Avg.Noise-`,-1) as `Avg.Noise-`,COALESCE(`CCE_1`,-1) as `CCE_1`,COALESCE(`CCE_25`,-1) as `CCE_25`,COALESCE(`Frames_found`,-1) as `Frames_found`,COALESCE(`Sr90IntegralVal`,-1) as `Sr90IntegralVal`,COALESCE(`StoN`,-1) as `StoN`, `Comment` from `radhard`.`labbook` WHERE `runnumber`=" + numberToString<>(labbook.runnumber));
         res = db->Query(selectquery.c_str());        
         nrows = res->GetRowCount();
         if (nrows > 0)
@@ -100,6 +100,7 @@ Run::Run(Int_t runnumber, Int_t loopi)
             labbook.frames_foundDB = (rowsql->GetField(19) != NULL)?atoi(rowsql->GetField(19)):-1;
             labbook.Sr90IntegralVal = (rowsql->GetField(20) != NULL)?atof(rowsql->GetField(20)):-1;
             labbook.StoN = (rowsql->GetField(21) != NULL)?atof(rowsql->GetField(21)):-1;
+            labbook.comment = (rowsql->GetField(22) != NULL)?std::string(rowsql->GetField(22)):"";
                //      labbook.frames_Analyzed = (rowsql->GetField(20) != NULL)?atoi(rowsql->GetField(20)):-1;
             delete res;
             if (labbook.chipGen.Length() > 0)
@@ -209,6 +210,7 @@ Bool_t Run::debugDBreadout()
     cout << "| StoN:            " << std::right << colorwhite << labbook.StoN  <<  endlr;
     cout << "| Sr90IntegralVal: " << std::right << colorwhite << std::scientific << labbook.Sr90IntegralVal <<  endlr; std::cout.unsetf ( std::ios::scientific );
     cout << "| frames_foundDB : " << std::right << colorwhite << std::scientific << labbook.frames_foundDB*1.0  <<  endlr; std::cout.unsetf ( std::ios::scientific );
+    cout << "| Comment:         " << std::right << colorgreen << labbook.comment  <<  endlr;
     cout << "|______________________________ " << endlr;
     cout << endlr;
     return 0;
@@ -421,6 +423,9 @@ Bool_t Run::analyzeRun(Bool_t force)
             histogramthreshold->integrateSr90Spectra(histogramthreshold->Seed, frames_found, -1, true);
             histogramfixedthreshold->integrateSr90Spectra(histogramfixedthreshold->Seed, frames_found, 0);
         }
+        cout << colorwhite << "normalizeHistogramClasses():" << endlr;
+        normalizeHistogramClasses();
+        cout << colorwhite << "rescaleHistogramClasses():" << endlr;
         rescaleHistogramClasses();
         cout << colorwhite << "updateDatabase():" << endlr;
         updateDatabase();
@@ -474,6 +479,17 @@ Bool_t Run::rescaleHistogramClasses()
     Float_t gain = 1640.0/vetopeakposition;
     for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)  {
         (*curHistogramClass)->calibrateHistograms(gain);
+        (*curHistogramClass)->normalized->calibrateHistograms(gain);
+    }
+    return 1;
+}
+
+
+Bool_t Run::normalizeHistogramClasses()
+{   
+    cout << "   For normalization use:  " << frames_found << " frames" << endl;
+    for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)  {
+        (*curHistogramClass)->normalizeHistograms(frames_found);
     }
     return 1;
 }
@@ -516,6 +532,29 @@ Bool_t Run::checkFileExists(TString file)
     return (stat (file.Data(), &buffer) == 0); 
 }
 
+Bool_t Run::setLabel(TString newlabel) 
+{
+    if (newlabel.Length() == 0)
+        newlabel = humanreadablestr;
+//     histogramthreshold->Seed->SetTitle(newlabel);
+    for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)  {
+        (*curHistogramClass)->Seed->SetTitle(newlabel);
+        (*curHistogramClass)->Veto->SetTitle(newlabel);
+        (*curHistogramClass)->Sum->SetTitle(newlabel);
+        (*curHistogramClass)->normalized->Seed->SetTitle(newlabel);
+        (*curHistogramClass)->normalized->Veto->SetTitle(newlabel);
+        (*curHistogramClass)->normalized->Sum->SetTitle(newlabel);
+        (*curHistogramClass)->calibrated->Seed->SetTitle(newlabel);
+        (*curHistogramClass)->calibrated->Veto->SetTitle(newlabel);
+        (*curHistogramClass)->calibrated->Sum->SetTitle(newlabel);
+        (*curHistogramClass)->normalized->calibrated->Seed->SetTitle(newlabel);
+        (*curHistogramClass)->normalized->calibrated->Veto->SetTitle(newlabel);
+        (*curHistogramClass)->normalized->calibrated->Sum->SetTitle(newlabel);
+    }
+    customLabel = true;
+    return 0;
+}
+
 Bool_t Run::generateReadableRunCode()
 {
     humanreadablestr = Form("%s, %s, chip %s, %s, %sT=%.1f", labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), humanreadablesuffix.Data(), labbook.temp);
@@ -712,6 +751,7 @@ void Run::updateDatabase() {
     constructUpdateString(&sqlupdatequery, "SumPeak",    histogram->posSum, 4);
     constructUpdateString(&sqlupdatequery, "SeedPeak",   histogram->posSeed, 4);
     constructUpdateString(&sqlupdatequery, "VetoPeak",   histogram->posVeto, 4);
+    constructUpdateString(&sqlupdatequery, "VetoIntegral",   histogram->integralVeto, 10);
     if (histogram->calibrated != 0)
         constructUpdateString(&sqlupdatequery, "Avg.Noise",  histogram->calibrated->avgNoise);
     if (histogram->calibrated != 0)
@@ -868,17 +908,20 @@ Bool_t Run::binSeedSumVeto()
 //     gROOT->SetBatch(kTRUE);
 
     for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)  {
-        Double_t* parameters = (Double_t *)calloc(3, sizeof(Double_t));
+        Double_t* parameters = (Double_t *)calloc(6, sizeof(Double_t));
         (*curHistogramClass)->FindNoisethresholdborder((*curHistogramClass)->Seed, false, false);
-        if (labbook.source.Contains("Fe")||labbook.source.Contains("Cd"))
-            parameters = (*curHistogramClass)->FitPerform((*curHistogramClass)->Veto, "gaus", true);
-        (*curHistogramClass)->posVeto = parameters[1];
-        parameters = (*curHistogramClass)->FitPerform((*curHistogramClass)->Seed, "landau", true);
+        if (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")) {
+            parameters = (*curHistogramClass)->FitPerform((*curHistogramClass)->Veto, "GaussTail");
+            (*curHistogramClass)->posVeto = parameters[1];
+//             cout << (*curHistogramClass)->histogramdescription << ": " << colorcyan <<  parameters[1] << endlr;
+        }
+        (*curHistogramClass)->integralVeto = parameters[3]/frames_found;
+        parameters = (*curHistogramClass)->FitPerform((*curHistogramClass)->Seed, "landau");
         (*curHistogramClass)->posSeed = parameters[1];
-        parameters = (*curHistogramClass)->FitPerform((*curHistogramClass)->Sum, "gaus", true);
+        parameters = (*curHistogramClass)->FitPerform((*curHistogramClass)->Sum, "gaus");
         (*curHistogramClass)->posSum = parameters[1];
         
-        parameters =(*curHistogramClass)->FitPerform((*curHistogramClass)->SeedPerc, "landau", true);
+        parameters =(*curHistogramClass)->FitPerform((*curHistogramClass)->SeedPerc, "landau");
         (*curHistogramClass)->posSeedPerc = parameters[1];
         (*curHistogramClass)->sigmaSeedPerc = parameters[2];
         
@@ -1222,6 +1265,16 @@ Bool_t Run::plotAllHistograms(HistogramType* HistogramTypepointer)
 {
     if (!error)
     {
+        TPaveText *owntitle = new TPaveText(0.15,0.9,0.930401,0.995,"nbNDC");
+        owntitle->SetFillStyle(0);
+        owntitle->SetBorderSize(0);
+        owntitle->SetTextAlign(22);
+        owntitle->SetTextSize(0.05);
+        owntitle->SetTextFont(42);
+        TPaveText *owntitle2 = (TPaveText*)owntitle->Clone();
+        TPaveText *owntitle3 = (TPaveText*)owntitle->Clone();
+        TPaveText *owntitle4 = (TPaveText*)owntitle->Clone();        
+        
         Float_t lastbin;
         Int_t random = random1->Rndm()*1000000;
         TString canvastitle = Form("%s %s", runcode.Data(), HistogramTypepointer->histogramdescription.Data());
@@ -1235,17 +1288,26 @@ Bool_t Run::plotAllHistograms(HistogramType* HistogramTypepointer)
         plotVerticalLine(HistogramTypepointer->Seed, HistogramTypepointer->posSeed);
         lastbin = HistogramTypepointer->Seed->GetBinCenter(HistogramTypepointer->Seed->FindLastBinAbove(2,1));
         HistogramTypepointer->Seed->SetAxisRange(0,lastbin*1.1,"X");
-       // gPad->SetLogy(1);
+        // gPad->SetLogy(1);
+        owntitle->Clear();
+        owntitle->AddText(trimRunnumberAtBegin(HistogramTypepointer->Seed->GetName()));
+        owntitle->Draw("SAME");        
         canvas->cd(2);
         HistogramTypepointer->Sum->Draw();
         plotVerticalLine(HistogramTypepointer->Sum, HistogramTypepointer->posSum);
         lastbin = HistogramTypepointer->Sum->GetBinCenter(HistogramTypepointer->Sum->FindLastBinAbove(2,1));
         HistogramTypepointer->Sum->SetAxisRange(0,lastbin*1.1,"X");
+        owntitle2->Clear();
+        owntitle2->AddText(trimRunnumberAtBegin(HistogramTypepointer->Sum->GetName()));
+        owntitle2->Draw("SAME");
         canvas->cd(3);
         HistogramTypepointer->Veto->Draw();
         if (labbook.source.Contains("Fe")||labbook.source.Contains("Cd"))
             plotVerticalLine(HistogramTypepointer->Veto, HistogramTypepointer->posVeto);
         HistogramTypepointer->Veto->SetAxisRange(HistogramTypepointer->posVeto*0.7,HistogramTypepointer->posVeto*1.4,"X");
+        owntitle3->Clear();
+        owntitle3->AddText(trimRunnumberAtBegin(HistogramTypepointer->Veto->GetName()));
+        owntitle3->Draw("SAME");
         canvas->cd(4);
         HistogramTypepointer->Noise->Draw();
         TString  legendEntry = Form("Noise: %.2f + %.2f - %.2f",HistogramTypepointer->avgNoise, HistogramTypepointer->avgNoisePlus, HistogramTypepointer->avgNoiseMinus);
@@ -1253,6 +1315,9 @@ Bool_t Run::plotAllHistograms(HistogramType* HistogramTypepointer)
         leg->AddEntry(HistogramTypepointer->Veto, legendEntry, "l");
         leg->SetTextSize(0.03);
         leg->Draw();
+        owntitle4->Clear();
+        owntitle4->AddText(trimRunnumberAtBegin(HistogramTypepointer->Noise->GetName()));
+        owntitle4->Draw("SAME");
         
 //         canvas -> Print( savepathresults + "/" + canvastitle + ".eps");
         
@@ -1445,7 +1510,7 @@ void Run::plotVerticalLine(TH1F* histogrampointer, Float_t xVal) {
     }
 }
 
-TCanvas* Run::plot1DHistogram(HistogramType* HistogramTypepointer, TH1F* onehistogram, TString fitFuncType, Float_t fitstart, TString titlestr, TString legendstr)
+TCanvas* Run::plot1DHistogram(HistogramType* HistogramTypepointer, TH1F* onehistogram, TString fitFuncType, Bool_t verbose, Float_t fitstart, TString titlestr, TString legendstr)
 {
     if (onehistogram != nullptr)
     {
@@ -1457,8 +1522,8 @@ TCanvas* Run::plot1DHistogram(HistogramType* HistogramTypepointer, TH1F* onehist
         TCanvas* canvas = new TCanvas(canvasname, canvastitle, 900, 700);
         onehistogram->SetTitle(titlestr);
         onehistogram->Draw();
-        Double_t* parameters = (Double_t *)calloc(6, sizeof(Double_t)); // allocate 6 parameters for safety, maximum 4 used at the moment
-        parameters = HistogramTypepointer->FitPerform(onehistogram, fitFuncType, true, fitstart);
+        Double_t* parameters = (Double_t *)calloc(6, sizeof(Double_t)); // allocate 7 parameters for safety, maximum 6 used at the moment
+        parameters = HistogramTypepointer->FitPerform(onehistogram, fitFuncType, verbose, fitstart);
         Float_t maxValue = parameters[1];
         plotVerticalLine(onehistogram, maxValue);
         Float_t startvalue = onehistogram->GetBinLowEdge(onehistogram->FindFirstBinAbove(0));
@@ -1543,26 +1608,35 @@ Bool_t Run::writeAllHistogramsToFile()
     
     TString header = Form("#%s %lu frames\n", runcode.Data(), frames_found);
     header += Form("#posVeto, run: %.1f, DB: %.1f, Fe55 DB (%d, %.1f): %.1f\n", histogram->posVeto, labbook.posVetoDB, Fe55run.posVetorunnumber, Fe55run.temperature, Fe55run.posVeto);
+    header += Form("#\t\t");
+    for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)  {
+        header += Form("%s\t\t\tnorm.\t\t\t", (*curHistogramClass)->histogramdescription.Data());
+    }      
+    header += Form("bin noise [ADU]\tbin noise [e]\tnoise\n");
+    header += Form("#\t\t");
+    for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)  {
+        header += Form("Seed\tSum\tVeto\tSeed\tSum\tVeto\t");
+    }      
+    header += Form("\n");
+    
+//     header += Form("#");
+//     for (vector<TH1F*>::iterator curHistogram = compareHistogramVector.begin(); curHistogram != compareHistogramVector.end(); curHistogram++)  {
+//         header += Form("bin\t%s\t",(*curHistogram)->GetName());
+//     }
+//     *fout << header << endl;
+    
     header += Form("#posSeed, run: %.1f, DB: %.1f\n", histogram->posSeed, labbook.posSeedDB);
     header += Form("#posSum, run: %.1f, DB: %.1f\n", histogram->posSum, labbook.posSumDB);
+    header += Form("#integralVeto, run: %.10f\n", histogram->integralVeto);
     if (labbook.source.Contains("Sr90")) {
         header += Form("#Sr90 integral: ");
         for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)
             header += Form("%s: %.6f\t", (*curHistogramClass)->histogramdescription.Data(), (*curHistogramClass)->sr90IntegralVal);
         header += Form("\n");
     }
-    header += Form("#Noise [ADU]: %.2f +%.2f -%.2f\n", histogram->avgNoise, histogram->avgNoisePlus, histogram->avgNoiseMinus );
+    header += Form("#Noise [ADU]: %.2f +%.2f -%.2f", histogram->avgNoise, histogram->avgNoisePlus, histogram->avgNoiseMinus );
     if (histogram->calibrated != 0)
-        header += Form("#Noise [e]: %.2f +%.2f -%.2f\n",histogram->calibrated->avgNoise, histogram->calibrated->avgNoisePlus, histogram->calibrated->avgNoiseMinus );
-    header += Form("#\t\t");
-    for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)  {
-        header += Form("%s\t\t\t", (*curHistogramClass)->histogramdescription.Data());
-    }
-    header += Form("\n#bin [ADU]\tbin [e]\t");
-    for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)  {
-        header += Form("Seed\tSum\tVeto\t");
-    }
-    header += Form("bin noise [ADU]\tbin noise [e]\tnoise");
+        header += Form("#Noise [e]: %.2f +%.2f -%.2f",histogram->calibrated->avgNoise, histogram->calibrated->avgNoisePlus, histogram->calibrated->avgNoiseMinus );
     *fout << header << endl;
     
     TString outline;
@@ -1571,6 +1645,7 @@ Bool_t Run::writeAllHistogramsToFile()
         outline=Form("%.1f\t%.1f\t", histogram->Seed->GetBinCenter(bin), histogram->calibrated!=0?histogram->calibrated->Seed->GetBinCenter(bin):0);
         for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)  {
             outline+=Form("%.1f\t%.1f\t%.1f\t", (*curHistogramClass)->Seed->GetBinContent(bin), (*curHistogramClass)->Sum->GetBinContent(bin), (*curHistogramClass)->Veto->GetBinContent(bin));
+            outline+=Form("%.1f\t%.1f\t%.1f\t", (*curHistogramClass)->normalized->Seed->GetBinContent(bin), (*curHistogramClass)->normalized->Sum->GetBinContent(bin), (*curHistogramClass)->normalized->Veto->GetBinContent(bin));
         }
         if (bin <= cursystemparam.nbinsnoise)
             outline+=Form("%.1f\t%.1f\t%.1f", histogram->Noise->GetBinCenter(bin),histogram->calibrated!=0?histogram->calibrated->Noise->GetBinCenter(bin):0,histogram->Noise->GetBinContent(bin));
index f02ccd053b8819407424e493c89ee15bddc8a2ad..18496726cc2ceed733903c2158534392ef931f66 100644 (file)
@@ -4,6 +4,7 @@
 #include <iomanip>
 #include <sstream>
 #include "sys/stat.h"
+//include <bits/stat.h>
 #include <cmath>       /* isinf, sqrt */
 
 #include <TSQLServer.h>
@@ -13,6 +14,7 @@
 #include <TBranch.h>
 #include <TNtuple.h>
 #include <TTree.h>
+#include <TPaveText.h>
 #include <TImage.h>
 #include <TLine.h>
 #include <TLegend.h>
@@ -61,6 +63,9 @@ private:
     
     Int_t plotStyle=0;
     
+    /** @brief is set to true, if custom label is used */
+    Bool_t customLabel = false;
+    
     TCanvas* noisecanvas = NULL;
     
     /**
@@ -211,8 +216,10 @@ private:
     
     /** @brief overwrite value from which the integral should be taken, overwrite noise cut in ADU */
     Float_t noisethresholdborderADU = -1;
-    
+    /** @brief Uses a found calibration peak value to rescale all the different cuts and histograms of type #HistogramType from ADU to e */
     Bool_t rescaleHistogramClasses();
+    /** @brief Uses the number of frames found (#frames_found) for calculation to normalize the histograms of type #HistogramType */
+    Bool_t normalizeHistogramClasses();
        
 public:
     /** @brief empty constructor */
@@ -227,6 +234,9 @@ public:
     systemparam cursystemparam; 
     
     void setPlotStyle(Int_t);
+    
+    /** @brief sets a custom description to be used as a label when plotting the run */
+    Bool_t setLabel(TString newlabel);
         
     /** @brief Compare histograms
      *
@@ -385,7 +395,7 @@ public:
      */
     Bool_t plotClusterDistribution(HistogramType*);
     
-    TCanvas* plot1DHistogram(HistogramType* histogramtypepointer, TH1F* onehistogram, TString fitFuncType = "landau", Float_t fitstart=-1, TString titlestr = "", TString legendstr = "");
+    TCanvas* plot1DHistogram(HistogramType* histogramtypepointer, TH1F* onehistogram, TString fitFuncType = "landau", Bool_t verbose = false, Float_t fitstart=-1, TString titlestr = "", TString legendstr = "");
     
     pixelinfo pixelinfoMi34[32];
         
@@ -443,4 +453,4 @@ public:
     /// sensor information to use in analysis, is the system read out by USB or PXI? Number of rows differ
     sensorinfostruct cursensorinfo;
 };
-#endif
\ No newline at end of file
+#endif
index d177108f79e837fe90de20b3c02b6c69aefb4414..90b914c18cedad3a4200cfd751ee90c6c5a4ae6e 100644 (file)
@@ -18,8 +18,8 @@
  ////////////////////////////////////////////////////////////////////////////
 
  // Definition of new styles
- TStyle *Nab_collaboration      = new TStyle("Nab_Collaboration","How Nab_Collaboration likes it");
- TStyle *Nab_collaboration_work = new TStyle("Nab_Collaboration_Work","How Nab_Collaboration likes it with stats");
+ TStyle *Nab_collaboration      = new TStyle("RadHard_AutoTitle","How we like it");
+ TStyle *Nab_collaboration_work = new TStyle("RadHard_NoTitle","How we like it without title");
 
  // Set the default parameters for style Nab_collaboration
  Nab_collaboration->SetCanvasBorderMode(0);     // Removes Canvas Border
@@ -34,7 +34,7 @@
  Nab_collaboration->SetPadTickY(1);             // Sets tic marks on both vertical axes
  Nab_collaboration->SetTickLength(0.018,"xyz"); // Sets tic length
  Nab_collaboration->SetOptStat(0);              // Turns off Statistics display
- Nab_collaboration->SetOptTitle(0);             // Turns off Title display
+ Nab_collaboration->SetOptTitle(1);             // Turns off Title display
  Nab_collaboration->SetHistLineWidth(2);        // Changes Histogram Line width
  Nab_collaboration->SetFrameBorderMode(0);      // Removes the Frame Border
  Nab_collaboration->SetFrameFillStyle(0);
 
  // Make Nab_collaboration_work a copy of Nab_collaboration and remove stats
  Nab_collaboration->Copy(*Nab_collaboration_work);
- Nab_collaboration_work->SetOptStat(1);
- Nab_collaboration_work->SetOptTitle(1);
//Nab_collaboration_work->SetOptStat(1);
+ Nab_collaboration_work->SetOptTitle(0);
  Nab_collaboration_work->SetPadTopMargin(0.1);
  Nab_collaboration_work->SetPadRightMargin(0.1);
 
  // Select Which Style to 
- gROOT->SetStyle("Nab_Collaboration_Work");
+ gROOT->SetStyle("RadHard_AutoTitle");
  // gROOT->SetStyle("Nab_Collaboration");
 
 
index ba5a2fa42fa01b8372c05f488019b4ebdcfa6164..96c0809d2cb2ea7e6e7d9b5a8cbf038d23e636a4 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <TCanvas.h>
 #include <Rtypes.h>
+#include <TString.h>
 
 #define MAXHITS                        1000000
 //####################################################################
@@ -220,6 +221,8 @@ struct labbooksctruct
     TString storepath = "";
     /// number of frames analyzed for this run
     Int_t frames_foundDB = -1;
+    /// Comment from database
+    TString comment = -1;
 };
 
 void preparecanvas() {
@@ -297,5 +300,17 @@ void MSaveBigPNG(TString filename="", double scale=2) {
     return;
 }
 
+TString trimRunnumberAtBegin(TString str) {
+    size_t i = 0;
+    while(isdigit(str(i++)));
+    return str.Remove(0, i);
+}
+
+TString getRunnumberAtBegin(TString str) {
+    size_t i = 0;
+    while(isdigit(str(i++)));
+    return str(0, i-1);
+}
+
 //####################################################################
 #endif
\ No newline at end of file