]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
Analyzer: cleaned up code
authorBenjamin Linnik <blinnik@jspc61.x-matter.uni-frankfurt.de>
Mon, 4 Sep 2017 09:43:29 +0000 (11:43 +0200)
committerBenjamin Linnik <blinnik@jspc61.x-matter.uni-frankfurt.de>
Mon, 4 Sep 2017 09:43:29 +0000 (11:43 +0200)
MABS_run_analyzer/HistogramType.c
MABS_run_analyzer/Run.c

index 566596c1e71a0ee69a5e575f4a10351b7a7ea118..d0f5c2b303fc8ea0b0e6d8b025c8654ae87118ce 100644 (file)
@@ -50,12 +50,12 @@ void HistogramType::initHistograms(Int_t gotcolor, Int_t gotstyle) {
     initHistogram(Noise, "Noise" + histogramdescription, color, style);
     initHistogram(NoiseEnd, "Noise at end" + histogramdescription, 16, style);
     initHistogramCustom(SeedPerc, "Seed Percentage" + histogramdescription, color, style, 0, 120, 121, Form("Entries [1/%%]"), "Q_coll [%]");
-    initHistogramCustom(pixeltimefired, "Pixel fired, used for " + histogramdescription, color, style, 0, cursensorinfo->columns*cursensorinfo->rows-1, cursensorinfo->columns*cursensorinfo->rows, "Pixel index", "Counts");
-    initHistogramCustom(pixeltimefiredDistrib, "Fire counter" + histogramdescription, color, style, 0, labbook->frames_foundDB/100-1, labbook->frames_foundDB/100, "times fired", "Counts");
-    initHistogramCustom(LeakageCurrentInPixel, "Leakage current per pixel" + histogramdescription, color, style, 0, cursensorinfo->columns*cursensorinfo->rows-1, cursensorinfo->columns*cursensorinfo->rows, "Pixel index", "Average CDS");
-    initHistogramCustom(LeakageCurrentInPixelSorted, "Leakage current per pixel sorted" + histogramdescription, color, style, 0, cursensorinfo->columns*cursensorinfo->rows-1, cursensorinfo->columns*cursensorinfo->rows, "Pixel index", "Average CDS");
+    initHistogramCustom(pixeltimefired, "Pixel fired, used for " + histogramdescription, color, style, 0, cursensorinfo->columns*cursensorinfo->rows, cursensorinfo->columns*cursensorinfo->rows, "Pixel index", "Counts");
+    initHistogramCustom(pixeltimefiredDistrib, "Fire counter" + histogramdescription, color, style, 0, labbook->frames_foundDB/100, labbook->frames_foundDB/100, "times fired", "Counts");
+    initHistogramCustom(LeakageCurrentInPixel, "Leakage current per pixel" + histogramdescription, color, style, 0, cursensorinfo->columns*cursensorinfo->rows, cursensorinfo->columns*cursensorinfo->rows, "Pixel index", "Average CDS");
+    initHistogramCustom(LeakageCurrentInPixelSorted, "Leakage current per pixel sorted" + histogramdescription, color, style, 0, cursensorinfo->columns*cursensorinfo->rows, cursensorinfo->columns*cursensorinfo->rows, "Pixel index", "Average CDS");
 //     initHistogram(LeakageCurrentInPixelSorted, "Leakage current" + histogramdescription, color, style);
-    initHistogramCustom(pixelHadGoodVeto, "Number of times pixel had good veto" + histogramdescription, color, style, 0, cursensorinfo->columns*cursensorinfo->rows-1, cursensorinfo->columns*cursensorinfo->rows, "Pixel index", "Counter good veto");
+    initHistogramCustom(pixelHadGoodVeto, "Number of times pixel had good veto" + histogramdescription, color, style, 0, cursensorinfo->columns*cursensorinfo->rows, cursensorinfo->columns*cursensorinfo->rows, "Pixel index", "Counter good veto");
     
     SeedPerc->GetXaxis()->SetRangeUser(0,50);
     Noise->SetBins(cursystempar->nbinsnoise, 0, cursystempar->maxbinnoise);
index ffdcc1f22e04a49ce9ee11bd951360ddabb3d286..8c840d93df6c8a408a85af3a0f169016f382ddff 100644 (file)
@@ -1095,7 +1095,7 @@ Bool_t Run::binLeakageCurrent(HistogramType* oneHistogramClass)
     Bool_t RTSpixel =false;
     u_int numberofconsideredpixel=0;
     u_int poscounter = 0;
-    for (u_int pixeli=0; (int)pixeli<cursensorinfo.columns*cursensorinfo.rows ; pixeli++) { // loop over all pixel
+    for (u_int pixeli=1; (int)pixeli<=cursensorinfo.columns*cursensorinfo.rows ; pixeli++) { // loop over all pixel
         RTSpixel = false;
         oneHistogramClass->LeakageCurrentInPixel->SetBinContent(pixeli, 0);
         for (u_int RTSpixeli=poscounter; RTSpixeli < oneHistogramClass->RTSpixel.size(); RTSpixeli++) { // loop over all RTS pixel
@@ -1131,15 +1131,15 @@ Bool_t Run::binLeakageCurrent(HistogramType* oneHistogramClass)
 //     th1->Run();
 //     
     std::vector<Float_t> sortedHistogram;  
-    for (Int_t pixeli=0; pixeli < oneHistogramClass->LeakageCurrentInPixel->GetNbinsX(); pixeli++) {
+    for (Int_t pixeli=1; pixeli <= oneHistogramClass->LeakageCurrentInPixel->GetNbinsX(); pixeli++) {
         if (oneHistogramClass->LeakageCurrentInPixel->GetBinContent(pixeli) != 0) // != 0 TODO
             sortedHistogram.push_back(oneHistogramClass->LeakageCurrentInPixel->GetBinContent(pixeli));
 //         cout << oneHistogramClass->LeakageCurrentInPixel->GetBinContent(pixeli) << " " << endl;
     }
     std::sort(sortedHistogram.begin(),sortedHistogram.end());
 //     oneHistogramClass->LeakageCurrentInPixelSorted->SetBins(sortedHistogram.size(), 0, sortedHistogram.size());
-    for (UInt_t pixeli=0; pixeli < sortedHistogram.size(); pixeli++) {
-        oneHistogramClass->LeakageCurrentInPixelSorted->SetBinContent(pixeli, sortedHistogram.at(pixeli));
+    for (UInt_t pixeli=1; pixeli <= sortedHistogram.size(); pixeli++) {
+        oneHistogramClass->LeakageCurrentInPixelSorted->SetBinContent(pixeli, sortedHistogram.at(pixeli-1));
     }
     
     oneHistogramClass->avgLeakageCurrentInChip /= numberofconsideredpixel;
@@ -1264,248 +1264,229 @@ Bool_t Run::binSeedSumVeto()
     }
     
     Bool_t RTSpixel = false;
-        
-    for (Int_t framei=0; framei<processed->fHitTree->GetEntries(); framei++) // loop over all frames
-    {
-        processed->fHitTree->GetEntry(framei);
-        // account only frames with less then 10 hits
-//           cout << colorcyan << processed->fFrameInfo.hits << endlr;
-//         if (processed->fFrameInfo.hits<(unsigned int)10)
+    
+    // used by goodveto hisogramtype
+    Double_t* parameters = (Double_t *)calloc(11, sizeof(Double_t));
+    Double_t gausscenter = 0;
+    Double_t gausssigma = 0;
+    
+    
+    for (Int_t filli=0; filli<3; filli++) { // first and second fill loop   
+        for (Int_t framei=0; framei<processed->fHitTree->GetEntries(); framei++) // loop over all frames
         {
-            for(Int_t hiti=0; (unsigned int)hiti<processed->fFrameInfo.hits;hiti++)
+            processed->fHitTree->GetEntry(framei);
+            // account only frames with less then 10 hits
+            //         if (processed->fFrameInfo.hits<(unsigned int)10)
             {
-//                 if (!hiti && framei==1994914)
-//                     cout << coloryellow << "   " << framei << endlr;
-                uint pixel_column_x = processed->fFrameInfo.pixel[hiti]%cursensorinfo.columns;    //  column of seed
-                uint pixel_row_y = processed->fFrameInfo.pixel[hiti]/cursensorinfo.columns;       //  row of seed
-                if (false) {
-                    cout << "submatrix_x_start: " << submatrix_x_start << ", submatrix_x_end: " << submatrix_x_end << endl;
-                    cout << "submatrix_y_start: " << submatrix_y_start << ", submatrix_y_end: " << submatrix_y_end << endl;
-                    cout << "pixel_column_x: " << pixel_column_x << ", pixel_row_y: " << pixel_row_y << endl;
-                }
-                if (pixel_column_x >= submatrix_x_start && pixel_column_x < submatrix_x_end && pixel_row_y >= submatrix_y_start && pixel_row_y < submatrix_y_end) // Diode sitzt oben im SeedPixel, da nach PitchY angeordnet
+                for(Int_t hiti=0; (unsigned int)hiti<processed->fFrameInfo.hits;hiti++)
                 {
-                    histogram->numberofhits++;
-                    
-                    // histogram with the single pixel
-                    histogram->Seed->Fill(processed->fFrameInfo.p[12][hiti]);
-//                     cout << colorcyan << "filled seed" << endlr;
-                    
-                    pixelSum = 0;
-                    notSeedSum = 0;                    
-                    // sum histogram
-                    for (Int_t clusteri=0; clusteri<completeclustersize; clusteri++) {
-                        a_pixelSum[clusteri]  = 0;
-                        a_notSeedSum[clusteri] = 0;
+                    uint pixelno = processed->fFrameInfo.pixel[hiti];       //  number of pixel fired (seed)
+                    uint pixel_column_x = pixelno%cursensorinfo.columns;    //  column of seed
+                    uint pixel_row_y = pixelno/cursensorinfo.columns;       //  row of seed
+                    if (false) {
+                        cout << "submatrix_x_start: " << submatrix_x_start << ", submatrix_x_end: " << submatrix_x_end << endl;
+                        cout << "submatrix_y_start: " << submatrix_y_start << ", submatrix_y_end: " << submatrix_y_end << endl;
+                        cout << "pixel_column_x: " << pixel_column_x << ", pixel_row_y: " << pixel_row_y << endl;
                     }
-                    //cout << colorpurple << framei << endlr;
-                    
-                    // look only at 3x3 cluster around seed
-                    if( labbook.chipGen=="FSBB" || labbook.chipGen=="Pipper2") {
-                        for (Int_t clusteri=0; clusteri<sqrt(completeclustersize); clusteri++) 
-                            processed->fFrameInfo.p[clusteri][hiti] = -9999;
-                        for (Int_t clusteri=completeclustersize-sqrt(completeclustersize); clusteri<completeclustersize; clusteri++) 
-                            processed->fFrameInfo.p[clusteri][hiti] = -9999;
-                        for (Int_t clusteri=0; clusteri<completeclustersize; clusteri=clusteri+sqrt(completeclustersize)) 
-                            processed->fFrameInfo.p[clusteri][hiti] = -9999;
-                        for (Int_t clusteri=4; clusteri<completeclustersize; clusteri=clusteri+sqrt(completeclustersize)) 
-                            processed->fFrameInfo.p[clusteri][hiti] = -9999;
-                    }
-                       
-//                     DEBUG
-//                     for (Int_t clusteri=0; clusteri<sqrt(completeclustersize); clusteri++)  {
-//                         for (Int_t clusterj=0; clusterj<sqrt(completeclustersize); clusterj++) 
-//                             cout << " " << processed->fFrameInfo.p[clusteri*5+clusterj][hiti];
-//                         cout << endl;
-//                     }
-//                     cout << "......." << endl;
+                    if (pixel_column_x >= submatrix_x_start && pixel_column_x < submatrix_x_end && pixel_row_y >= submatrix_y_start && pixel_row_y < submatrix_y_end) // Diode sitzt oben im SeedPixel, da nach PitchY angeordnet
+                    {                        
+                        pixelSum = 0;
+                        notSeedSum = 0;     
+                        for (Int_t clusteri=0; clusteri<completeclustersize; clusteri++) {
+                            a_pixelSum[clusteri]  = 0;
+                            a_notSeedSum[clusteri] = 0;
+                        }
+                        //cout << colorpurple << framei << endlr;
                         
-                    Float_t clusterArray[completeclustersize];// temp variable clusterArray necessary, because Sort only accepts 1-dim arrays
-                    for (Int_t clusteri=0; clusteri<completeclustersize; clusteri++) {
-                        clusterArray[clusteri] = processed->fFrameInfo.p[clusteri][hiti];
-                    }
-                    Int_t index[completeclustersize];
-                    TMath::Sort(completeclustersize,clusterArray,index,1);
-                    for (Int_t clusteri=0; clusteri<completeclustersize; clusteri++)
-                    {
-                       if (clusterArray[index[clusteri]] > -9000) {
-                           pixelSum += clusterArray[index[clusteri]];                            
-                           for (Int_t clusterj=clusteri; clusterj<completeclustersize; clusterj++) {
-                               a_pixelSum[clusterj] += clusterArray[index[clusteri]];
-                           }
-                           
-                           if (index[clusteri] != 12) {
-                               notSeedSum += processed->fFrameInfo.p[index[clusteri]][hiti];
-                               for (Int_t clusterj=clusteri; clusterj<completeclustersize; clusterj++) { // not used yet
-                                   a_notSeedSum[clusterj] += clusterArray[index[clusteri]];
-                               }
-                           }
-                       }
-                    }
-                    histogram->Sum->Fill(pixelSum);  
-                    for (Int_t clusterj=0; clusterj<completeclustersize; clusterj++) {
-                        histogram->a_Sum[clusterj]->Fill(a_pixelSum[clusterj]);  
-                    }
-                    
-                    // seed percentage spectrum
-                    histogram->SeedPerc->Fill(processed->fFrameInfo.p[12][hiti]/pixelSum*100); 
-//                     if (framei==1994914) {
-//                         cout << "pixel_column_x: " << pixel_column_x << ", pixel_row_y: " << pixel_row_y << " pixelcharge: " << processed->fFrameInfo.p[12][hiti] << endl;
-//                         cout << coloryellow << processed->fFrameInfo.p[12][hiti]/pixelSum*100 << endlr;
-//                     }
-                    
-                    // veto spectrum
-                    if (TMath::Abs(notSeedSum) < cursystemparam.vetothreshold && (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")))
-                        histogram->Veto->Fill(processed->fFrameInfo.p[12][hiti]);    // histogram with the single pixel
-                    
-                                        
-                    if (processed->fFrameInfo.pixelthreshold[hiti]>0)
-                    {
-                        histogramthreshold->numberofhits++;                        
-                        fillAHistogramsinclass(histogramthreshold, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
+                        // look only at 3x3 cluster around seed
+                        if( labbook.chipGen=="FSBB" || labbook.chipGen=="Pipper2") {
+                            for (Int_t clusteri=0; clusteri<sqrt(completeclustersize); clusteri++) 
+                                processed->fFrameInfo.p[clusteri][hiti] += -9999;
+                            for (Int_t clusteri=completeclustersize-sqrt(completeclustersize); clusteri<completeclustersize; clusteri++) 
+                                processed->fFrameInfo.p[clusteri][hiti] += -9999;
+                            for (Int_t clusteri=0; clusteri<completeclustersize; clusteri=clusteri+sqrt(completeclustersize)) 
+                                processed->fFrameInfo.p[clusteri][hiti] += -9999;
+                            for (Int_t clusteri=4; clusteri<completeclustersize; clusteri=clusteri+sqrt(completeclustersize)) 
+                                processed->fFrameInfo.p[clusteri][hiti] += -9999;
+                        }
                             
-                        // bin the RTS cleaned histogram class
-                        if (histogramwoRTSthreshold != 0) {
-                            RTSpixel = false;
-                            for (u_int RTSpixeli=0; RTSpixeli < histogramwoRTSthreshold->RTSpixel.size(); RTSpixeli++) {
-                                if (processed->fFrameInfo.pixel[hiti] == histogramwoRTSthreshold->RTSpixel[RTSpixeli])
-                                {
-                                    RTSpixel = true;
-//                                     cout << "not binned! RTS pixel #" << processed->fFrameInfo.pixel[hiti] << endl;
+        //                     DEBUG
+        //                     for (Int_t clusteri=0; clusteri<sqrt(completeclustersize); clusteri++)  {
+        //                         for (Int_t clusterj=0; clusterj<sqrt(completeclustersize); clusterj++) 
+        //                             cout << " " << processed->fFrameInfo.p[clusteri*5+clusterj][hiti];
+        //                         cout << endl;
+        //                     }
+        //                     cout << "......." << endl;
+                            
+                        Float_t clusterArray[completeclustersize];// temp variable clusterArray necessary, because Sort only accepts 1-dim arrays
+                        for (Int_t clusteri=0; clusteri<completeclustersize; clusteri++) {
+                            clusterArray[clusteri] = processed->fFrameInfo.p[clusteri][hiti];
+                        }
+                        Int_t index[completeclustersize];
+                        TMath::Sort(completeclustersize,clusterArray,index,1);
+                        for (Int_t clusteri=0; clusteri<completeclustersize; clusteri++)
+                        {
+                            if (clusterArray[index[clusteri]] > -9000) {
+                                pixelSum += clusterArray[index[clusteri]];                            
+                                for (Int_t clusterj=clusteri; clusterj<completeclustersize; clusterj++) {
+                                    a_pixelSum[clusterj] += clusterArray[index[clusteri]];
+                                }
+                                
+                                if (index[clusteri] != 12) {
+                                    notSeedSum += processed->fFrameInfo.p[index[clusteri]][hiti];
+                                    for (Int_t clusterj=clusteri; clusterj<completeclustersize; clusterj++) { // not used yet
+                                        a_notSeedSum[clusterj] += clusterArray[index[clusteri]];
+                                    }
                                 }
-                            }
-                            if (!RTSpixel) {                                
-                                fillAHistogramsinclass(histogramwoRTSthreshold, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
                             }
                         }
-                        // bin the more agressive RTS histogram class
-                        if (histogramwoRTSAggresivethreshold != 0) {
-                            RTSpixel = false;
-                            for (u_int RTSpixeli=0; RTSpixeli < histogramwoRTSAggresivethreshold->RTSpixel.size(); RTSpixeli++) {
-                                if (processed->fFrameInfo.pixel[hiti] == histogramwoRTSAggresivethreshold->RTSpixel[RTSpixeli])
-                                {
-                                    RTSpixel = true;
-                                    //                                     cout << "not binned! RTS pixel #" << processed->fFrameInfo.pixel[hiti] << endl;
+                        if (filli == 0) { // first fill round                            
+                            histogram->numberofhits++;                            
+                            // histogram with the single pixel
+                            histogram->Seed->Fill(processed->fFrameInfo.p[12][hiti]);
+                            histogram->Sum->Fill(pixelSum);  
+                            for (Int_t clusterj=0; clusterj<completeclustersize; clusterj++) {
+                                histogram->a_Sum[clusterj]->Fill(a_pixelSum[clusterj]);  
+                            }
+                            
+                            // seed percentage spectrum
+                            histogram->SeedPerc->Fill(processed->fFrameInfo.p[12][hiti]/pixelSum*100); 
+                            
+                            // veto spectrum
+                            if (TMath::Abs(notSeedSum) < cursystemparam.vetothreshold && (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")))
+                                histogram->Veto->Fill(processed->fFrameInfo.p[12][hiti]);    // histogram with the single pixel
+                            
+                                                
+                            if (processed->fFrameInfo.pixelthreshold[hiti]>0)
+                            {
+                                histogramthreshold->numberofhits++;                        
+                                fillAHistogramsinclass(histogramthreshold, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
+                                    
+                                // bin the RTS cleaned histogram class
+                                if (histogramwoRTSthreshold != 0) {
+                                    RTSpixel = false;
+                                    for (u_int RTSpixeli=0; RTSpixeli < histogramwoRTSthreshold->RTSpixel.size(); RTSpixeli++) {
+                                        if (pixelno == histogramwoRTSthreshold->RTSpixel[RTSpixeli])
+                                        {
+                                            RTSpixel = true;
+                                        }
+                                    }
+                                    if (!RTSpixel) {                                
+                                        fillAHistogramsinclass(histogramwoRTSthreshold, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
+                                    }
+                                }
+                                // bin the more agressive RTS histogram class
+                                if (histogramwoRTSAggresivethreshold != 0) {
+                                    RTSpixel = false;
+                                    for (u_int RTSpixeli=0; RTSpixeli < histogramwoRTSAggresivethreshold->RTSpixel.size(); RTSpixeli++) {
+                                        if (pixelno == histogramwoRTSAggresivethreshold->RTSpixel[RTSpixeli])
+                                        {
+                                            RTSpixel = true;
+                                            //                                     cout << "not binned! RTS pixel #" << pixelno << endl;
+                                        }
+                                    }
+                                    if (!RTSpixel) {
+                                        fillAHistogramsinclass(histogramwoRTSAggresivethreshold, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
+                                    }
                                 }
+                                
                             }
-                            if (!RTSpixel) {
-                                fillAHistogramsinclass(histogramwoRTSAggresivethreshold, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
+                            // bin the RTS cleaned histogram class
+                            if (histogramwoRTS != 0) {
+                                RTSpixel = false;
+                                for (u_int RTSpixeli=0; RTSpixeli < histogramwoRTS->RTSpixel.size(); RTSpixeli++) {
+                                    if (pixelno == histogramwoRTS->RTSpixel[RTSpixeli])
+                                    {
+                                        RTSpixel = true;
+                                        break;
+                                    }
+                                    
+                                }
+                                if (!RTSpixel) {
+                                    fillAHistogramsinclass(histogramwoRTS, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
+                                }                    
+                            }           
+                            // bin the more agressive RTS histogram class
+                            if (histogramwoRTSAggresive != 0) {
+                                RTSpixel = false;
+                                for (u_int RTSpixeli=0; RTSpixeli < histogramwoRTSAggresive->RTSpixel.size(); RTSpixeli++) {
+                                    if (pixelno == histogramwoRTSAggresive->RTSpixel[RTSpixeli])
+                                    {
+                                        RTSpixel = true;
+            //                                 cout << "not binned! RTS pixel #" << processed->fFrameInfo.pixel[hiti] << " with charge: " << processed->fFrameInfo.p[12][hiti] << endl;
+                                        //                                 cout << "not binned! RTS pixel #" << processed->fFrameInfo.pixel[hiti] << " with charge: " << processed->fFrameInfo.p[12][hiti] << endl;
+                                    }
+                                }
+                                if (!RTSpixel) {
+                                    fillAHistogramsinclass(histogramwoRTSAggresive, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
+                                }                        
                             }
-                        }
-                        
-                    }
-                    // bin the RTS cleaned histogram class
-                    if (histogramwoRTS != 0) {
-//                         cout << "is " << processed->fFrameInfo.pixel[hiti] << " an RTS pixel? size of rts pixel matrix:  " << histogramwoRTS->RTSpixel.size();
-                        RTSpixel = false;
-                        for (u_int RTSpixeli=0; RTSpixeli < histogramwoRTS->RTSpixel.size(); RTSpixeli++) {
-                            if (processed->fFrameInfo.pixel[hiti] == histogramwoRTS->RTSpixel[RTSpixeli])
-                            {
-                             //   if (RTSpixeli == 0)
-                                RTSpixel = true;
-                                break;
+                        } else if (filli == 1) { // second fill round, some histograms are allready filled
+                            
+                            // histogramfixedthreshold relies on "histogram", therefore 'histogram' has to be completly filled before a threshold can be Set
+                            // bin the fixed threshold for charge histogram class
+                            if (histogramfixedthreshold != 0 && histogram != 0) {
+                                if (histogramfixedthreshold->fixedThresholdValue <= 0) {
+                                    float_t cutval = histogram->Sum->GetBinCenter(histogram->Sum->FindLastBinAbove(3,1));
+                                    setFixedThresholdValueADU(cutval*0.8);
+                                }
+                                if (pixelSum > histogramfixedthreshold->fixedThresholdValue) // charge is more then histogramfixedthreshold->fixedThresholdValue in whole cluster
+                                {
+                                    histogramfixedthreshold->numberofhits++;                            
+                                    fillAHistogramsinclass(histogramfixedthreshold, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
+                                }
                             }
                             
-                        }
-//                         if (RTSpixel)
-//                             cout << " yes";
-//                         cout << endlr;
-                        if (!RTSpixel) {
-                            fillAHistogramsinclass(histogramwoRTS, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
-                        }                    
-                    }           
-                    // bin the more agressive RTS histogram class
-                    if (histogramwoRTSAggresive != 0) {
-                        RTSpixel = false;
-                        for (u_int RTSpixeli=0; RTSpixeli < histogramwoRTSAggresive->RTSpixel.size(); RTSpixeli++) {
-                            if (processed->fFrameInfo.pixel[hiti] == histogramwoRTSAggresive->RTSpixel[RTSpixeli])
-                            {
-                                RTSpixel = true;
-//                                 cout << "not binned! RTS pixel #" << processed->fFrameInfo.pixel[hiti] << " with charge: " << processed->fFrameInfo.p[12][hiti] << endl;
-                                //                                 cout << "not binned! RTS pixel #" << processed->fFrameInfo.pixel[hiti] << " with charge: " << processed->fFrameInfo.p[12][hiti] << endl;
+                            if (histogramGoodVeto != 0 && histogram != 0) {
+                                if (framei == 0) { // only one time job, do while in first frame only
+                                    histogram->FindNoisethresholdborder(histogram->Seed, false, false);
+                                    if (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")) {
+                                        parameters = histogram->FitPerform(histogram->Veto, "GaussTail");
+                                        histogramGoodVeto->posVeto = parameters[1];
+                                        gausscenter = parameters[1];
+                                        gausssigma = parameters[2];
+                                        cout << colorcyan << "gausscenter: " << gausscenter << endlr;
+                                        cout << colorcyan << "gausssigma: " << gausssigma << endlr;
+                                    }
+                                    if (TMath::Abs(notSeedSum) < cursystemparam.vetothreshold && (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")) && abs(processed->fFrameInfo.p[12][hiti]-gausscenter) < abs(3.0*gausssigma)) {
+                                        histogramGoodVeto->pixelHadGoodVeto->Fill(pixelno);
+                                    }// if good veto
+                                }
+                            }
+                                
+                        } else if (filli == 2) { // third fill round, some histograms are allready filled
+                            
+                            if (histogramGoodVeto != 0 && histogram != 0) {
+                                
+                                if (framei == 0) { // only one time job, do while in first frame only
+                                    uint numberofgoodvetopixels = 0;
+                                    // calculate the percentage of veto "good" pixel on chip
+                                    for (Int_t pixeli=1; pixeli <= histogramGoodVeto->pixelHadGoodVeto->GetNbinsX(); pixeli++) {
+                                        if (histogramGoodVeto->pixelHadGoodVeto->GetBinContent(pixeli) > 0) {
+                                            numberofgoodvetopixels++;
+                                        }
+                                    }
+                                    Float_t percentageofGoodVetoPixel = 0;
+                                    cout << colorcyan << "numberofgoodvetopixels: " << numberofgoodvetopixels << endlr;
+                                    cout << colorcyan << "numberofactivepixel: " << numberofactivepixel << endlr;
+                                    percentageofGoodVetoPixel = (numberofgoodvetopixels*100.0)/numberofactivepixel;
+                                    cout << colorcyan << "percentageodGoodVetoPixel: " << percentageofGoodVetoPixel << endlr;
+                                }
+                                
+                                if (histogramGoodVeto->pixelHadGoodVeto->GetBinContent(pixelno+1) > 1) {
+                                    histogramGoodVeto->numberofhits++;                            
+                                    fillAHistogramsinclass(histogramGoodVeto, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
+                                }
                             }
-                        }
-                        if (!RTSpixel) {
-                            fillAHistogramsinclass(histogramwoRTSAggresive, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
-                        }                        
-                    }    
-                } // end if in range for submatrix analysis
-            } // end loop over hits in frame
-        }
-    } // end loop over all frames
-    
-    // histogramfixedthreshold relies on "histogram", therefore histogram has to be completly filled before a threshold can be Set
-    for (Int_t framei=0; framei<processed->fHitTree->GetEntries(); framei++) // loop over all frames
-    {
-        processed->fHitTree->GetEntry(framei);
-        {
-            for(Int_t hiti=0; (unsigned int)hiti<processed->fFrameInfo.hits;hiti++)
-            {
-                uint pixel_column_x = processed->fFrameInfo.pixel[hiti]%cursensorinfo.columns;    //  column of seed
-                uint pixel_row_y = processed->fFrameInfo.pixel[hiti]/cursensorinfo.columns;       //  row of seed
-                if (pixel_column_x >= submatrix_x_start && pixel_column_x < submatrix_x_end && pixel_row_y >= submatrix_y_start && pixel_row_y < submatrix_y_end) // Diode sitzt oben im SeedPixel, da nach PitchY angeordnet
-                {
-                    pixelSum = 0;
-                    notSeedSum = 0;                    
-                    // sum histogram
-                    for (Int_t clusteri=0; clusteri<completeclustersize; clusteri++) {
-                        a_pixelSum[clusteri]  = 0;
-                        a_notSeedSum[clusteri] = 0;
-                    }
-                    // look only at 3x3 cluster around seed
-                    if( labbook.chipGen=="FSBB" || labbook.chipGen=="Pipper2") {
-                        for (Int_t clusteri=0; clusteri<sqrt(completeclustersize); clusteri++) 
-                            processed->fFrameInfo.p[clusteri][hiti] = -9999;
-                        for (Int_t clusteri=completeclustersize-sqrt(completeclustersize); clusteri<completeclustersize; clusteri++) 
-                            processed->fFrameInfo.p[clusteri][hiti] = -9999;
-                        for (Int_t clusteri=0; clusteri<completeclustersize; clusteri=clusteri+sqrt(completeclustersize)) 
-                            processed->fFrameInfo.p[clusteri][hiti] = -9999;
-                        for (Int_t clusteri=4; clusteri<completeclustersize; clusteri=clusteri+sqrt(completeclustersize)) 
-                            processed->fFrameInfo.p[clusteri][hiti] = -9999;
-                    }
                         
-                    Float_t clusterArray[completeclustersize];// temp variable clusterArray necessary, because Sort only accepts 1-dim arrays
-                    for (Int_t clusteri=0; clusteri<completeclustersize; clusteri++) {
-                        clusterArray[clusteri] = processed->fFrameInfo.p[clusteri][hiti];
-                    }
-                    Int_t index[completeclustersize];
-                    TMath::Sort(completeclustersize,clusterArray,index,1);
-                    for (Int_t clusteri=0; clusteri<completeclustersize; clusteri++)
-                    {
-                        if (clusterArray[index[clusteri]] > -9000) {
-                           pixelSum += clusterArray[index[clusteri]];                            
-                           for (Int_t clusterj=clusteri; clusterj<completeclustersize; clusterj++) {
-                               a_pixelSum[clusterj] += clusterArray[index[clusteri]];
-                           }
-                           
-                           if (index[clusteri] != 12) {
-                               notSeedSum += processed->fFrameInfo.p[index[clusteri]][hiti];
-                               for (Int_t clusterj=clusteri; clusterj<completeclustersize; clusterj++) { // not used yet
-                                   a_notSeedSum[clusterj] += clusterArray[index[clusteri]];
-                               }
-                           }
-                       }                     
-                    }
-                    
-                    // bin the fixed threshold for charge histogram class
-                    if (histogramfixedthreshold != 0) {
-                       if (histogramfixedthreshold->fixedThresholdValue <= 0) {
-                         float_t cutval = histogram->Sum->GetBinCenter(histogram->Sum->FindLastBinAbove(3,1));
-                         setFixedThresholdValueADU(cutval*0.8);
-                       }
-                        if (pixelSum > histogramfixedthreshold->fixedThresholdValue) // charge is more then histogramfixedthreshold->fixedThresholdValue in whole cluster
-                        {
-                            histogramfixedthreshold->numberofhits++;                            
-                            fillAHistogramsinclass(histogramfixedthreshold, hiti, completeclustersize, pixelSum, notSeedSum, &a_pixelSum[0], &a_notSeedSum[0]);
-                        }
-                    }
-               }
-           }
-       }
-    }
-    
-    
-    
+                        } // if fill round == 2 (third round)
+                    } // end if in range for submatrix analysis
+                }// end loop over hits in frame
+            }
+        } // end loop over all frames
+    } // end of loop of fill round counter
+        
+        
     //     gROOT->SetBatch(kTRUE);
     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     
@@ -1547,127 +1528,7 @@ Bool_t Run::binSeedSumVeto()
         for (Int_t bini=1; bini <= 100; bini++) {
             (*curHistogramClass)->SeedPerc->SetBinContent(bini,(*curHistogramClass)->SeedPerc->GetBinContent(bini));//((*curHistogramClass)->SeedPerc->GetEntries()));
         }
-    }
-    if (histogramGoodVeto != 0 && histogram != 0) {
-        Double_t* parameters = (Double_t *)calloc(8, sizeof(Double_t));
-        Double_t gausssigma = 0;
-        Double_t gausscenter = 0;
-        if (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")) {
-            parameters = histogram->FitPerform(histogram->Veto, "GaussTail");
-            histogramGoodVeto->posVeto = parameters[1];
-            gausscenter = parameters[1];
-            gausssigma = parameters[2];
-            cout << colorcyan << "gausscenter: " << gausscenter << endlr;
-            cout << colorcyan << "gausssigma: " << gausssigma << endlr;
-        }
-        
-        for (Int_t framei=0; framei<processed->fHitTree->GetEntries(); framei++) // loop over all frames
-        {
-            processed->fHitTree->GetEntry(framei);
-            for(Int_t hiti=0; (unsigned int)hiti<processed->fFrameInfo.hits;hiti++)
-            {
-                uint pixel_column_x = processed->fFrameInfo.pixel[hiti]%cursensorinfo.columns;    //  column of seed
-                uint pixel_row_y = processed->fFrameInfo.pixel[hiti]/cursensorinfo.columns;       //  row of seed
-                if (pixel_column_x >= submatrix_x_start && pixel_column_x < submatrix_x_end && pixel_row_y >= submatrix_y_start && pixel_row_y < submatrix_y_end) // Diode sitzt oben im SeedPixel, da nach PitchY angeordnet
-                {
-                    pixelSum = 0;
-                    notSeedSum = 0;
-                    if(labbook.chipGen=="FSBB")
-                    {   
-                        Float_t clusterArray[processed->clustersize*processed->clustersize];// temp variable clusterArray necessary, because Sort only accepts 1-dim arrays
-                        Int_t index[processed->clustersize*processed->clustersize];
-                        for (Int_t clusteri=0; clusteri<processed->clustersize*processed->clustersize; clusteri++)
-                        {
-                            clusterArray[clusteri] = processed->fFrameInfo.p[clusteri][hiti];
-                            if (clusteri != 12)
-                                notSeedSum += processed->fFrameInfo.p[clusteri][hiti];
-                        }
-                        TMath::Sort(processed->clustersize*processed->clustersize,clusterArray,index,1);
-                        for (Int_t clusteri=0; clusteri<4; clusteri++)
-                        {
-                            pixelSum += clusterArray[index[clusteri]];
-                            
-                        }
-                    }
-                    else
-                    {
-                        for (Int_t clusteri=0; clusteri<processed->clustersize*processed->clustersize; clusteri++)
-                        {
-                            pixelSum += processed->fFrameInfo.p[clusteri][hiti];
-                            if (clusteri != 12)
-                                notSeedSum += processed->fFrameInfo.p[clusteri][hiti];
-                        }
-                    }
-                    if (TMath::Abs(notSeedSum) < cursystemparam.vetothreshold && (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")) && abs(processed->fFrameInfo.p[12][hiti]-gausscenter) < abs(3.0*gausssigma)) {
-                        histogramGoodVeto->pixelHadGoodVeto->Fill(processed->fFrameInfo.pixel[hiti]);
-                    }// if good veto
-                } // if in submatrix range (if defined)
-            } // loop over hots
-        } // loop over frames
-        uint numberofgoodvetopixels = 0;
-        // calculate the percentage of veto "good" pixel on chip
-        for (Int_t pixeli=0; pixeli < histogramGoodVeto->pixelHadGoodVeto->GetNbinsX(); pixeli++) {
-            if (histogramGoodVeto->pixelHadGoodVeto->GetBinContent(pixeli) > 0) {
-                numberofgoodvetopixels++;
-            }
-        } 
-        Float_t percentageofGoodVetoPixel = 0;
-        cout << colorcyan << "numberofgoodvetopixels: " << numberofgoodvetopixels << endlr;
-        cout << colorcyan << "numberofactivepixel: " << numberofactivepixel << endlr;
-        percentageofGoodVetoPixel = (numberofgoodvetopixels*100.0)/numberofactivepixel;
-        cout << colorcyan << "percentageodGoodVetoPixel: " << percentageofGoodVetoPixel << endlr;
-
-        
-        for (Int_t framei=0; framei<processed->fHitTree->GetEntries(); framei++) // loop over all frames
-        {
-            processed->fHitTree->GetEntry(framei);
-            for(Int_t hiti=0; (unsigned int)hiti<processed->fFrameInfo.hits;hiti++)
-            {
-                uint pixel_column_x = processed->fFrameInfo.pixel[hiti]%cursensorinfo.columns;    //  column of seed
-                uint pixel_row_y = processed->fFrameInfo.pixel[hiti]/cursensorinfo.columns;       //  row of seed
-                uint pixeli = processed->fFrameInfo.pixel[hiti];
-                if (pixel_column_x >= submatrix_x_start && pixel_column_x < submatrix_x_end && pixel_row_y >= submatrix_y_start && pixel_row_y < submatrix_y_end) // Diode sitzt oben im SeedPixel, da nach PitchY angeordnet
-                {
-                    if (histogramGoodVeto->pixelHadGoodVeto->GetBinContent(pixeli) > 1) {
-                        histogramGoodVeto->numberofhits++;
-                        histogramGoodVeto->Seed->Fill(processed->fFrameInfo.p[12][hiti]);
-                        pixelSum = 0;
-                        notSeedSum = 0;
-                        if(labbook.chipGen=="FSBB")
-                        {   
-                            Float_t clusterArray[processed->clustersize*processed->clustersize];// temp variable clusterArray necessary, because Sort only accepts 1-dim arrays
-                            Int_t index[processed->clustersize*processed->clustersize];
-                            for (Int_t clusteri=0; clusteri<processed->clustersize*processed->clustersize; clusteri++)
-                            {
-                                clusterArray[clusteri] = processed->fFrameInfo.p[clusteri][hiti];
-                                if (clusteri != 12)
-                                    notSeedSum += processed->fFrameInfo.p[clusteri][hiti];
-                            }
-                            TMath::Sort(processed->clustersize*processed->clustersize,clusterArray,index,1);
-                            for (Int_t clusteri=0; clusteri<4; clusteri++)
-                            {
-                                pixelSum += clusterArray[index[clusteri]];
-                                
-                            }
-                        }
-                        else
-                        {
-                            for (Int_t clusteri=0; clusteri<processed->clustersize*processed->clustersize; clusteri++)
-                            {
-                                pixelSum += processed->fFrameInfo.p[clusteri][hiti];
-                                if (clusteri != 12)
-                                    notSeedSum += processed->fFrameInfo.p[clusteri][hiti];
-                            }
-                        }
-                        histogramGoodVeto->Sum->Fill(pixelSum);  
-                        histogramGoodVeto->SeedPerc->Fill(processed->fFrameInfo.p[12][hiti]/pixelSum*100);  
-                        if (TMath::Abs(notSeedSum) < cursystemparam.vetothreshold && (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")))
-                            histogramGoodVeto->Veto->Fill(processed->fFrameInfo.p[12][hiti]);    // histogram with the single pixel
-                    }
-                }
-            }
-        }        
-    } // clause for histogramGoodVeto    
+    }  
     
     if (histogramfixedthreshold != 0) {
         histogramfixedthreshold->noisethresholdborder=0;