]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
Anylyzer: Added real frame number counter to database and code, added noise threshold...
authorBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Tue, 9 Jun 2015 12:16:29 +0000 (14:16 +0200)
committerBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Tue, 9 Jun 2015 12:16:29 +0000 (14:16 +0200)
MABS_run_analyzer/ChargeSpektrum.c
MABS_run_analyzer/Run.c
MABS_run_analyzer/Run.h

index 231d85f697c68ed8ea14459a51172b11a562dddc..603e8e884aa4158fb36babb485476911bbf07a06 100644 (file)
@@ -176,16 +176,16 @@ void ChargeSpektrum(TString runnumber = "")
                 {
             //         gROOT->SetBatch(kTRUE);
                     //           runs[runi]->plotSeed();
-//                     runs[runi]->plotSeedThresholdCalibrated();
+                    runs[runi]->plotSeedThresholdCalibrated();
 //                     runs[runi]->plotSeedThreshold();
-                    runs[runi]->plotSeed();
+//                     runs[runi]->plotSeed();
             //         runs[runi]->plotSum();
             //         runs[runi]->plotVeto();
                     //         runs[runi]->plotNoise();
                     if (!isBatch)
                         gROOT->SetBatch(kFALSE);
-                            runs[runi]->plotAllHistograms();
-//                     runs[runi]->plotAllHistogramsThresholdCluster();
+//                             runs[runi]->plotAllHistograms();
+                    runs[runi]->plotAllHistogramsThresholdCluster();
 //                     runs[runi]->plotAllHistogramsThresholdClusterCalibrated();
             //          runs[runi]->plotAllHistogramsCalibrated(); 
                     runs[runi]->writeAllHistogramsToFile(); 
index b07e6cae92463af8a34edaa45c82b7e6c108b957..ff8cf4f7226f981856cff9c75a34f2dc6a53ac96 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` 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` from `radhard`.`labbook` WHERE `runnumber`=" + numberToString<>(labbook.runnumber));
         res = db->Query(selectquery.c_str());        
         nrows = res->GetRowCount();
         if (nrows > 0)
@@ -96,6 +96,7 @@ Run::Run(Int_t runnumber, Int_t loopi)
             labbook.NoiseAvgMinusDB = (rowsql->GetField(16) != NULL)?atoi(rowsql->GetField(16)):-1;
             labbook.CCE_in_Perc_1DB = (rowsql->GetField(17) != NULL)?atoi(rowsql->GetField(17)):-1;
             labbook.CCE_in_Perc_25DB = (rowsql->GetField(18) != NULL)?atoi(rowsql->GetField(18)):-1;
+            labbook.frames_foundDB = (rowsql->GetField(19) != NULL)?atoi(rowsql->GetField(19)):-1;
             delete res;
             if (labbook.chip.Length() > 0 && labbook.chipGen.Length() > 0) // versuche infos zum Chip aus der ChipDatenbank zu bekommen
             {
@@ -278,6 +279,10 @@ Bool_t Run::analyzeRun(Bool_t force)
         histogramthresholdCalibrated.calibrated = histogramCalibrated.calibrated;
         cout << colorwhite << "calculateCCE():" << endlr;
         calculteCCE();
+        if (labbook.source.Contains("Sr90")) {
+            cout << colorwhite << "integrateSr90Spectra():" << endlr;
+            integrateSr90Spectra(histogramthresholdCalibrated.Seed);
+        }
         cout << colorwhite << "updateDatabase():" << endlr;
         updateDatabase();
         cout << colorwhite << "delete MAPS class:" << endlr;
@@ -350,6 +355,7 @@ Bool_t Run::rescaleHistograms()
     histogramthresholdCalibrated.avgNoise = histogramthreshold.avgNoise * gain;
     histogramthresholdCalibrated.avgNoisePlus = histogramthreshold.avgNoisePlus * gain;
     histogramthresholdCalibrated.avgNoiseMinus = histogramthreshold.avgNoiseMinus * gain;
+    
     return 1;    
 }
 
@@ -576,10 +582,10 @@ void Run::getVetoPeakPositionFromFe55Run()
     }
 }
 
-void Run::constructUpdateString(string *sqlupdatequery, const string databasevaluename, const Float_t value, const int precision=3)
+void Run::constructUpdateString(string *sqlupdatequery, const string databasevaluename, const Double_t value, const int precision=3)
 {
     //     cout << colorred << databasevaluename << " :  " << value << endlr;
-    if (!isinf(value))
+    if (!std::isinf(value))
     {
         if (value>0)
         {
@@ -604,6 +610,7 @@ void Run::updateDatabase() {
     constructUpdateString(&sqlupdatequery, "CCE_1",      CCE_in_Perc_1);
     constructUpdateString(&sqlupdatequery, "CCE_25",     CCE_in_Perc_25);
     constructUpdateString(&sqlupdatequery, "Frames_found", frames_found,100000000);
+    constructUpdateString(&sqlupdatequery, "Sr90IntegralVal", sr90IntegralVal,1000000000);
     
     if (sqlupdatequery.length()>0)
     {
@@ -904,12 +911,78 @@ Bool_t Run::plotAllHistogramsThresholdClusterCalibrated()
     return 1;
 }
 
+Bool_t Run::integrateSr90Spectra(TH1F* histogrampointer, Bool_t verbose)
+{
+    Float_t posMaxValHist = histogrampointer->GetXaxis()->GetXmax();
+    
+    TH1F* smoothedcurce = (TH1F*)histogrampointer->Clone();
+    smoothedcurce->Smooth(4);
+    
+    Int_t rising = 0;
+    Int_t bini =smoothedcurce->GetMaximumBin();
+    Float_t curval = smoothedcurce->GetXaxis()->GetBinCenter(bini);
+    Float_t thresholdbincurcandidate = 0;
+    
+    do {
+        curval=smoothedcurce->GetBinContent(bini++);
+        if (curval*0.95 <= smoothedcurce->GetBinContent(bini))
+        {
+            rising++;
+//             cout << "rising at " <<  smoothedcurce->GetXaxis()->GetBinCenter(bini) << "   as " << curval  << " < " << smoothedcurce->GetBinContent(bini) << endl; // debug
+        }
+        else
+        {
+            rising = 0;
+            thresholdbincurcandidate = bini;
+        }
+    } while (rising < 3 && bini<smoothedcurce->GetNbinsX());
+
+    
+    
+//     histogrampointer->GetXaxis()->SetRange(histogrampointer->GetXaxis()->FindBin(0),histogrampointer->GetXaxis()->FindBin(posMaxValHist));
+//     Float_t posNoiseMax= histogrampointer->GetMaximum();
+//     histogrampointer->GetXaxis()->SetRange(posNoiseMax,histogrampointer->GetXaxis()->FindBin(posMaxValHist));
+//     Float_t posChargeMax= histogrampointer->GetMaximum();
+    
+    noisethresholdborder =  histogrampointer->GetXaxis()->GetBinUpEdge(thresholdbincurcandidate);
+    
+    if (verbose) {
+        cout << "   Noise threshold at " << noisethresholdborder;
+        TString histtitle=histogrampointer->GetXaxis()->GetTitle();
+        if (histtitle.Contains("[e]"))
+        {
+            cout << " e" << endl;
+            if (noisethresholdborder > 300) {
+                cout << coloryellow << "   This noise threshold seems too high, please check manually the " << histogrampointer->GetName() << " spectrum." << endlr;
+            }
+        }
+        else
+        {
+            cout << " ADU" << endl;
+            if (noisethresholdborder > 75) {
+                cout << coloryellow << "   This noise threshold seems too high, please check manually the " << histogrampointer->GetName() << " spectrum." << endlr;
+            }
+        }
+    }
+    sr90IntegralVal = histogrampointer->IntegralAndError(thresholdbincurcandidate,histogrampointer->GetMaximumBin(), sr90IntegralErr);
+    sr90IntegralErr /= sr90IntegralVal/100;
+    cout << "   ";
+    if (labbook.frames_foundDB>0 || frames_found>0)
+    {
+        sr90IntegralVal/=(labbook.frames_foundDB>0)?labbook.frames_foundDB:frames_found;
+        cout << "Scaled ";
+    }
+    cout << "Integral is " << Form("%e",sr90IntegralVal) << ", error " << sr90IntegralErr << "%" <<  endl;
+    
+    return 0;
+}
+
 Float_t Run::FitPerform(TH1F* histogrampointer, TString fitFuncType, Bool_t verbose)
 {
     Float_t posMax = 0;
     Float_t posMax2 = 0;
     Float_t posMaxValHist = histogrampointer->GetXaxis()->GetXmax();
-    Float_t noiseborder = 90; // posMaxValHist/10 for USB system, the value is 90
+    Float_t noiseborder = (noisethresholdborder>0)?noisethresholdborder:90; // posMaxValHist/10 for USB system, the value is 90
     
     if (doFits) 
     {        
index bab97345a32bce76ed3f5b73fb6a1d56d8ee8f33..7f7314a7cf40791a88161dbcc3b42d127640cb67 100644 (file)
@@ -4,7 +4,7 @@
 #include <iomanip>
 #include <sstream>
 #include "sys/stat.h"
-#include <math.h>       /* isinf, sqrt */
+#include <cmath>       /* isinf, sqrt */
 
 #include <TSQLServer.h>
 #include <TSQLResult.h>
@@ -77,7 +77,7 @@ private:
     /**
      * @brief takes a float value and a precision and appends it to an SQL statement used to update the database
      */
-    void constructUpdateString(string*, const string, const Float_t, int);
+    void constructUpdateString(string*, const string, const Double_t, int);
        
     /**
      * @brief A structure to hold information about a given sensor, like number of #columns and #rows
@@ -146,6 +146,7 @@ private:
     Bool_t binSeedSumVeto();
     /// noise quantiles: mean value, sigma in postive direction and sigma in negative direction
     Double_t noisequantiles[3];
+        
     
     TCanvas* plot1DHistogram(TH1F* onehistogram, TString fitFuncType = "landau", TString titlestr = "", TString legendstr = "");
     
@@ -162,13 +163,23 @@ private:
     /**
      * @brief intern function to calculate and plot fit curve to given histogram
      * 
-     * @param histNtuple histogram pointer to calculate fit to
+     * @param histogrampointer histogram pointer to calculate fit to
      * @return peak position of the fit
      * 
      */
     Float_t FitPerform(TH1F*, TString fitFuncType="landau", Bool_t verbose=true);
-    
-    
+        
+    /**
+     * @brief find the border between the noise and the signal in Sr90 runs
+     * 
+     * writes the found threshold into the private variable #posNoiseThreshold
+     * 
+     * @param histogrampointer pointer to the histogram structure, threshold will be searched in seed spectra
+     * @return true if succesfull
+     * 
+     */
+    Bool_t integrateSr90Spectra(TH1F* histogrampointer, Bool_t verbose=true);
+        
     
     /**
      * @brief rescales all histograms from ADU to electrons */
@@ -209,7 +220,7 @@ private:
     };
     systemparam systemparamUSB {
         2800, // maxbin;
-        2800/8,// nbins;
+        2800/4,// nbins;
         25, //vetothreshold
         10,
         100
@@ -384,6 +395,8 @@ public:
         Int_t clock = 100;
         /// path to the RAW files as seen from system which took the run
         TString storepath = "";
+        /// number of frames analyzed for this run
+        Int_t frames_foundDB = -1;
     };
     /// stores information from the SQL database of a given run
     labbooksctruct labbook;
@@ -494,6 +507,13 @@ public:
     Float_t CCE_in_Perc_25=0;
     /// Charge collection efficciency of the seed pixel in percent
     Float_t CCE_in_Perc_1=0;
+    /// threshold for integrating the Sr90 spectrum, is set dynamically in @c integrateSr90Spectra()
+    Float_t noisethresholdborder = -1;
+    /// Integral value, after integrating  from #noisethresholdborder to maxbin.
+    Double_t sr90IntegralVal = -1;
+    Double_t sr90IntegralErr = -1;
+    
+    
     /// specific string wich encodes the database information of the run
     TString runcode="";