]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
Analyzer: Bugfixes, Added 'leak' command line flag for leakage current analysis
authorBenjamin Linnik <blinnik@jspc61.x-matter.uni-frankfurt.de>
Tue, 28 Nov 2017 13:53:52 +0000 (14:53 +0100)
committerBenjamin Linnik <blinnik@jspc61.x-matter.uni-frankfurt.de>
Tue, 28 Nov 2017 13:53:52 +0000 (14:53 +0100)
MABS_run_analyzer/ChargeSpektrum.c
MABS_run_analyzer/ChargeSpektrumFunctions.c
MABS_run_analyzer/HistogramType.c
MABS_run_analyzer/Run.c

index b24821b6cb608557c9702643d371f582b4e81f02..ac756af50506e684ba49f4002c56fef36a1ac95d 100644 (file)
@@ -85,9 +85,13 @@ void ChargeSpektrum(TString runnumber = "")
     
     // f0 analysis variables  
     vector<TH1FO*> compareHistogramAllRunsVectorF0;
+        
+    // leakage current analysis variables  
+    vector<TH1FO*> compareHistogramLeakageCurrent;
     
     for(Int_t runi=0; runi<numberRuns; runi++) // loop over runs read from file or given as aparameters
     {
+        
         if (runList[runi]>0)
         {
             runs[runi] = new Run(runList[runi], runi);
@@ -148,7 +152,7 @@ void ChargeSpektrum(TString runnumber = "")
                         gROOT->SetBatch(kFALSE);
                     
                     // use only lower case when matching anaylsis types
-                    
+                                        
                     if (analysisType.Contains("clas")) { // classic analysis                        
                         compareHistogramClassVectorClassic.push_back(runs[runi]->histogram->normalized);
                         if (runi+1 == numberRuns) 
@@ -410,6 +414,21 @@ void ChargeSpektrum(TString runnumber = "")
                         compareHistogramAllRunsVectorF0.push_back(runs[runi]->averageF0Distr);
                         runs[runi]->plot1DHistogram( runs[runi]->averageF0Distr, "gaus", true);
                     }
+                    
+                    
+                    
+                    if (analysisType.Contains("leak")) { // analyze cluster formation
+                        // Plot leakage current            
+                        compareHistogramLeakageCurrent.push_back(runs[runi]->histogramwoRTS->LeakageCurrentDistrib);
+                        if (runi+1 == numberRuns) {
+                            compareHistogramVectorVector.push_back(compareHistogramLeakageCurrent);     
+                        }
+                        
+                        runs[runi]->plot1DHistogram(runs[runi]->histogramdynamicalthreshold->Veto, "GaussTail", true);
+                        runs[runi]->plot1DHistogram(runs[runi]->histogramwoRTS->LeakageCurrentInPixelSorted, "", false, true);
+                    }
+                    
+                    
 
                     // write all histograms to a dat file, can be imported by ORIGIN or Excel. Leave this line ;)
                     runs[runi]->writeAllHistogramsToFile();
index f7ed149fdeaff7414b50536255c2c2ed0a7a0a92..09c711f8ce35cb2b8f334f704444da43b73680b8 100644 (file)
@@ -83,6 +83,9 @@ TCanvas* plot1DData(std::vector<TNtupleO*>* ntuplepvectorpointer, Bool_t verbose
 Bool_t writeNTupleVectorToFile(std::vector<TNtupleO*>* ntuplepvectorpointer);
 
 Bool_t writeObservableToFile(vector<TH1FO*>* ptCompareHistogramVector);
+
+// Write one histogram to its own file
+Bool_t writeHistogramToFile(TH1FO* onehistogram);
 /** @brief A vector able to hold pointer of type #Run::histogramstruct
  * 
  * You push in pointer of the type Run::histogramstruct in ChargeSpectrum.C and then 
@@ -478,13 +481,35 @@ Bool_t writeOneHistogramTypeToFile(vector<HistogramType*>* ptCompareHistogramCla
 }
 
 
+Bool_t writeHistogramToFile(TH1FO* onehistogram)
+{
+    Run* runp = onehistogram->itsHistogramType->run;
+    system("mkdir \""+  runp->savepathresults + "\" -p");
+    TString filename= runp->savepathresults + "/" + runp->runcode + " " + onehistogram->GetName() + " hist.dat";
+    fstream* fout = new fstream(filename,ios::out);        
+    
+    TString header = Form("#bin [ADU]\tCounts");
+    *fout << header << endl;
+    
+    TString outline;
+    for(Int_t bin=1;bin<=onehistogram->GetNbinsX();bin++)
+    {
+        outline=Form("%.3f\t%.3f", onehistogram->GetBinCenter(bin), onehistogram->GetBinContent(bin));
+        *fout<<outline<<endl;
+    }
+    fout->close();
+    return 0;
+}
+
+
 Bool_t writeObservableToFile(vector<TH1FO*>* ptCompareHistogramVector)
 {
     if (numberRuns>0)
     {
-        system("mkdir \""+ savepathresults + folderadd + "/\"" + " -p");
         
-        TString filename = savepathresults + folderadd + "/Spectra";
+        TH1FO* histogrampfirst = ptCompareHistogramVector->at(0);  
+        system("mkdir \""+ savepathresults + folderadd + "/\"" + " -p");        
+        TString filename = savepathresults + folderadd + "/Spectra " + histogrampfirst->GetName();
         TString header = "";
         for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
         {
@@ -505,7 +530,7 @@ Bool_t writeObservableToFile(vector<TH1FO*>* ptCompareHistogramVector)
         }
         *fout << header << endl;
         TString outline;
-        for(Int_t bin=1;bin<=runs[0]->cursystemparam.nbins;bin++)
+        for(Int_t bin=1;bin<=histogrampfirst->GetNbinsX();bin++)
         {
             outline ="";
             for (vector<TH1FO*>::iterator curHistogram = ptCompareHistogramVector->begin(); curHistogram != ptCompareHistogramVector->end(); curHistogram++)  {
@@ -514,6 +539,11 @@ Bool_t writeObservableToFile(vector<TH1FO*>* ptCompareHistogramVector)
             *fout<<outline<<endl;
         }
         fout->close();
+        
+        
+//         for (vector<TH1FO*>::iterator curHistogram = ptCompareHistogramVector->begin(); curHistogram != ptCompareHistogramVector->end(); curHistogram++)  {
+//             writeHistogramToFile(curHistogram);
+//         }
         return 0;
         
     }    
index 0a5c06f0360e651d228dc9908da53c01ea2b12f3..9002c0ce5753e0d53fab46b68d4b215fc36bee62 100644 (file)
@@ -747,25 +747,28 @@ Double_t* HistogramType::FitPerform(TH1FO* histogrampointer, TString fitFuncType
             cout << "peak:   " << fitFcn->GetParameter(2) << endl;
             cout << "y-shift:" << fitFcn->GetParameter(3) << endl;
 //         }
-    } else if (fitFuncType=="GaussTail")
-    {
-        histogrampointer->GetXaxis()->UnZoom();
-         posMaxValHist = (histogrampointer->GetBinCenter(histogrampointer->FindLastBinAbove(1,1)));
+    } else if (fitFuncType=="GaussTail") // this option is used when fitting the calibration peak
+    {           
+        // for Cadmium, the Veto spectrum is not so clean, set the noise border to higher values
+        // this way the other peaks which come not from the K-Alpha line will be ignored.
+        if (labbook->source.Contains("Cd")) {
+            noiseborder = 100;
+            cout << "Set noiseborder to: " << noiseborder << endlr;
+        }
+        
+        histogrampointer->GetXaxis()->UnZoom(); // resets range
+        posMaxValHist = (histogrampointer->GetBinCenter(histogrampointer->FindLastBinAbove(1,1)));
          
-         if (verbose) {
+        if (verbose) {
             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(histogrampointer->GetXaxis()->FindBin(noiseborder),histogrampointer->GetXaxis()->FindBin(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(10, sizeof(Double_t));  
         const Double_t def_amplitude=histogrampointer->GetBinContent(histogrampointer->GetMaximumBin());
         const Double_t def_peakcenter=histogrampointer->GetBinCenter(histogrampointer->GetMaximumBin());
-//                  cout << colorcyan << "def_peakcenter: " << def_peakcenter << endlr;
-//                  cout << colorcyan << "histogrampointer->GetMaximumBin(): " << histogrampointer->GetMaximumBin() << endlr;
         const Double_t def_gausssig=8.68052;
         const Double_t def_distgauss=20.4;
         const Double_t def_bgslope=0;
@@ -829,34 +832,37 @@ Double_t* HistogramType::FitPerform(TH1FO* histogrampointer, TString fitFuncType
 //              cout << colorcyan << gMinuit->fCstatu.Data() << " fit tries: " << fittries << endlr;            
         } while (fittries < 6);        
         fittries = 0;
-        do {
-            failed = false;
-            fit_result_ptr = histogrampointer->Fit(fitFunc, "N,M,W,Q,S", "", posMaxValHist-posMaxValHist/4*(++fittries), posMaxValHist);
-            //             cout << colorcyan << " AFTER fit " << endlr;   
-            if (gMinuit == nullptr) { 
-                failed = true;
-            } else 
-            {
-                if (gMinuit->fCstatu == "NOT POSDEF" || gMinuit->fCstatu.Contains("FAILED")) {
+        if (failed)
+        {
+            do {
+                failed = false;
+                fit_result_ptr = histogrampointer->Fit(fitFunc, "N,M,W,Q,S", "", posMaxValHist-posMaxValHist/4*(++fittries), posMaxValHist);
+                //             cout << colorcyan << " AFTER fit " << endlr;   
+                if (gMinuit == nullptr) { 
                     failed = true;
+                } else 
+                {
+                    if (gMinuit->fCstatu == "NOT POSDEF" || gMinuit->fCstatu.Contains("FAILED")) {
+                        failed = true;
+                    }
                 }
-            }
-            if (failed)
-            {
-                fitFunc->SetParameter(0,def_amplitude);
-                fitFunc->SetParameter(1,posMaxValHist-posMaxValHist/4*(fittries));
-                fitFunc->SetParameter(2,def_gausssig);
-                fitFunc->SetParameter(3,def_distgauss);
-                fitFunc->SetParameter(4,def_bgslope);
-                fitFunc->SetParameter(5,def_bgoffs);
-            }
-            else
-                fittries = 100;        
-        } while (fittries < 4); 
+                if (failed)
+                {
+                    fitFunc->SetParameter(0,def_amplitude);
+                    fitFunc->SetParameter(1,posMaxValHist-posMaxValHist/4*(fittries));
+                    fitFunc->SetParameter(2,def_gausssig);
+                    fitFunc->SetParameter(3,def_distgauss);
+                    fitFunc->SetParameter(4,def_bgslope);
+                    fitFunc->SetParameter(5,def_bgoffs);
+                }
+                else
+                    fittries = 100;        
+            } while (fittries < 4); 
+        }
         if (failed)
         {
             failed = false;
-            cout << "Most emphasized estimate" << endlr;
+            cout << "More emphasized estimate" << endlr;
             histogrampointer->GetXaxis()->SetRange(0,posMaxValHist);   // look only for maxima with x greater than noiseborder, cut away noise
             fitFunc->SetParameter(0,def_amplitude);
             fitFunc->SetParameter(1,def_peakcenter);
@@ -952,8 +958,8 @@ Double_t* HistogramType::FitPerform(TH1FO* histogrampointer, TString fitFuncType
         fitFunc->SetLineStyle(1); // normal for the following fits
         if (verbose)
         {
-            TCanvas* canvas = new TCanvas(histogrampointer->GetName(), histogrampointer->GetName(), 900, 700);
-            histogrampointer->Draw();
+//             TCanvas* canvas = new TCanvas(histogrampointer->GetName(), histogrampointer->GetName(), 900, 700);
+//             histogrampointer->Draw();
             fitFunc->Draw("SAME");
         }
         
index b35701973682f57357a1f230b00a64b1c2887e8c..bfa8e9b113f23eb848a88d68dd3c7bc1f5ff47ea 100644 (file)
@@ -1150,9 +1150,10 @@ Bool_t Run::binLeakageCurrent(HistogramType* oneHistogramClass)
     
     std::vector<Float_t> sortedHistogram; // 
     for (Int_t pixeli=1; pixeli <= oneHistogramClass->LeakageCurrentInPixel->GetNbinsX(); pixeli++) {
-        oneHistogramClass->LeakageCurrentDistrib->Fill(oneHistogramClass->LeakageCurrentInPixel->GetBinContent(pixeli));
-        if (oneHistogramClass->LeakageCurrentInPixel->GetBinContent(pixeli) != 0) // != 0 // not RTS pixel
+        if (oneHistogramClass->LeakageCurrentInPixel->GetBinContent(pixeli) != 0) { // != 0 // not RTS pixel
+            oneHistogramClass->LeakageCurrentDistrib->Fill(oneHistogramClass->LeakageCurrentInPixel->GetBinContent(pixeli));
             sortedHistogram.push_back(oneHistogramClass->LeakageCurrentInPixel->GetBinContent(pixeli));
+        }
 //         cout << oneHistogramClass->LeakageCurrentInPixel->GetBinContent(pixeli) << " " << endl;
     }
     std::sort(sortedHistogram.begin(),sortedHistogram.end());
@@ -1698,25 +1699,11 @@ Bool_t Run::binSeedSumVeto()
     for (vector<HistogramType*>::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++)  {
         Double_t* parameters = (Double_t *)calloc(11, sizeof(Double_t)); // allocate 11 parameters for safety, maximum 10 used at the moment     
         
-        cout << colorcyan << (*curHistogramClass)->histogramdescription << endlr;
+//         cout << colorcyan << (*curHistogramClass)->histogramdescription << endlr;
         (*curHistogramClass)->FindNoisethresholdborder((*curHistogramClass)->Seed, false, false);
-        if (labbook.runnumber == 343056)
-            (*curHistogramClass)->noisethresholdborder = 34;
-        if (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")) {
-            
+        if (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")) {            
             parameters = (*curHistogramClass)->FitPerform((*curHistogramClass)->Veto, "GaussTail");
             (*curHistogramClass)->posVeto = parameters[1];
-            if (labbook.runnumber == 343056)
-                (*curHistogramClass)->posVeto = 234;
-            if (labbook.runnumber == 345045)
-                (*curHistogramClass)->posVeto = 425;
-            if (labbook.runnumber == 342824)
-                (*curHistogramClass)->posVeto = 425;
-            if (labbook.runnumber == 342265)
-                (*curHistogramClass)->posVeto = 417;
-            if (labbook.runnumber == 345054)
-                (*curHistogramClass)->posVeto = 417;
-            //             cout << (*curHistogramClass)->histogramdescription << ": " << colorcyan <<  parameters[1] << endlr;
             (*curHistogramClass)->integralVeto = parameters[6];
         }
         if (labbook.chipGen.EqualTo("Pipper2") || labbook.chipGen.EqualTo("Pegasus"))