Subversion Repositories f9daq

Rev

Rev 173 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 173 Rev 181
Line 57... Line 57...
57
      resol2d->widgetNE[1]->SetNumber(40);
57
      resol2d->widgetNE[1]->SetNumber(40);
58
   }
58
   }
59
   else if(analTab->GetCurrent() == 1)  // Relative PDE
59
   else if(analTab->GetCurrent() == 1)  // Relative PDE
60
   {
60
   {
61
      relPde->widgetChBox[0]->SetState(kButtonDown);
61
      relPde->widgetChBox[0]->SetState(kButtonDown);
62
      relPde->widgetChBox[1]->SetState(kButtonUp);
-
 
63
      midPeak->widgetChBox[0]->SetState(kButtonUp);
62
      midPeak->widgetChBox[0]->SetState(kButtonUp);
64
      zeroAngle->widgetNE[0]->SetNumber(0.00);
63
      zeroAngle->widgetNE[0]->SetNumber(0.00);
65
   }
64
   }
66
   else if(analTab->GetCurrent() == 2)  // Breakdown voltage
65
   else if(analTab->GetCurrent() == 2)  // Breakdown voltage
67
   {
66
   {
Line 693... Line 692...
693
   float progVal = 0;
692
   float progVal = 0;
694
   analysisProgress->widgetPB->SetPosition(progVal);
693
   analysisProgress->widgetPB->SetPosition(progVal);
695
   gVirtualX->Update(1);
694
   gVirtualX->Update(1);
696
 
695
 
697
   // Check if the checkbox for no peaks is selected - TODO: Still need the situation when we do not have a peaked ADC spectrum
696
   // Check if the checkbox for no peaks is selected - TODO: Still need the situation when we do not have a peaked ADC spectrum
698
   if(relPde->widgetChBox[1]->IsDown())
697
/*   if(relPde->widgetChBox[1]->IsDown())
699
   {
698
   {
700
      printf("PhotonMu(): ADC spectrum has no peak structure.\n");
699
      printf("PhotonMu(): ADC spectrum has no peak structure.\n");
701
      nopeaks = 1;
700
      nopeaks = 1;
702
 
701
 
703
      // Error if there is no darkhist
702
      // Error if there is no darkhist
Line 710... Line 709...
710
         delete[] pdeval;
709
         delete[] pdeval;
711
         delete[] muval;
710
         delete[] muval;
712
         return;
711
         return;
713
      }
712
      }
714
 
713
 
715
   }
714
   }*/
716
 
715
 
717
   // Start if we select at least one file
716
   // Start if we select at least one file
718
   if(nrfiles > 0)
717
   if(nrfiles > 0)
719
   {
718
   {
720
      // Find the pedestal peak for the dark histogram, and use it for all if there are no peaks
719
      // Find the pedestal peak for the dark histogram, and use it for all if there are no peaks
721
      if(nopeaks != -1)
720
      if(nopeaks != -1)
722
      {
721
      {
723
         // Replot the spectrum on analysisCanvas and do not close the input file
722
         // Replot the spectrum on analysisCanvas and do not close the input file
724
         DisplayHistogram( (char*)(darkRun->widgetTE->GetText()), 0, 1);
723
         DisplayHistogram( (char*)(darkRun->widgetTE->GetText()), 0, 1);
725
         analysisCanvas->GetCanvas()->Modified();
724
         analysisCanvas->GetCanvas()->Modified();
726
         analysisCanvas->GetCanvas()->Update();
725
         analysisCanvas->GetCanvas()->Update();
727
       
726
       
728
         // Get the spectrum
727
         // Get the spectrum
729
         histtemp = (TH1F*)analysisCanvas->GetCanvas()->GetPrimitive(histname);
728
         histtemp = (TH1F*)analysisCanvas->GetCanvas()->GetPrimitive(histname);
730
         npeaks = 15;
729
         npeaks = 15;
731
         double par[300];
730
         double par[300];
732
         spec = new TSpectrum(npeaks);
731
         spec = new TSpectrum(npeaks);
733
         // Find spectrum background
732
         // Find spectrum background
734
         histback = spec->Background(histtemp, (int)fitInter->widgetNE[0]->GetNumber(), "same");
733
         histback = spec->Background(histtemp, (int)fitInter->widgetNE[0]->GetNumber(), "same");
735
         // Clone histogram and subtract background from it if we select that option
734
         // Clone histogram and subtract background from it if we select that option
736
         h2 = (TH1F*)histtemp->Clone("h2");
735
         h2 = (TH1F*)histtemp->Clone("h2");
737
         if(fitChecks->widgetChBox[0]->IsDown())
736
         if(fitChecks->widgetChBox[0]->IsDown())
738
            h2->Add(histback, -1);
737
            h2->Add(histback, -1);
739
         // Search for the peaks
738
         // Search for the peaks
740
         int found = spec->Search(h2, fitSigma->widgetNE[0]->GetNumber(), "goff", fitTresh->widgetNE[0]->GetNumber() );
739
         int found = spec->Search(h2, fitSigma->widgetNE[0]->GetNumber(), "goff", fitTresh->widgetNE[0]->GetNumber() );
741
         printf("PhotonMu(): Found %d candidates to fit.\n",found);
740
         printf("PhotonMu(): Found %d candidates to fit.\n",found);
742
         npeaks = found;
741
         npeaks = found;
743
   
742
   
744
         // Set initial peak parameters
743
         // Set initial peak parameters
745
         xpeaks = spec->GetPositionX();
744
         xpeaks = spec->GetPositionX();
746
         for(j = 0; j < found; j++)
745
         for(j = 0; j < found; j++)
747
         {
746
         {
748
            float xp = xpeaks[j];
747
            float xp = xpeaks[j];
749
            int bin = h2->GetXaxis()->FindBin(xp);
748
            int bin = h2->GetXaxis()->FindBin(xp);
750
            float yp = h2->GetBinContent(bin);
749
            float yp = h2->GetBinContent(bin);
751
            par[3*j] = yp;
750
            par[3*j] = yp;
752
            par[3*j+1] = xp;
751
            par[3*j+1] = xp;
753
            par[3*j+2] = (double)fitSigma->widgetNE[0]->GetNumber();
752
            par[3*j+2] = (double)fitSigma->widgetNE[0]->GetNumber();
754
         }
753
         }
755
         
754
         
756
         // Fit the histogram
755
         // Fit the histogram
757
         fit = new TF1("fit", FindPeaks, adcRange->widgetNE[0]->GetNumber(), adcRange->widgetNE[1]->GetNumber(), 3*npeaks);
756
         fit = new TF1("fit", FindPeaks, adcRange->widgetNE[0]->GetNumber(), adcRange->widgetNE[1]->GetNumber(), 3*npeaks);
758
         TVirtualFitter::Fitter(histtemp, 3*npeaks);
757
         TVirtualFitter::Fitter(histtemp, 3*npeaks);
759
         fit->SetParameters(par);
758
         fit->SetParameters(par);
760
         fit->SetNpx(300);
759
         fit->SetNpx(300);
761
         h2->Fit("fit","Q");
760
         h2->Fit("fit","Q");
762
         // Get the fitted parameters
761
         // Get the fitted parameters
763
         fittingfunc = h2->GetFunction("fit");
762
         fittingfunc = h2->GetFunction("fit");
764
         fparam = fittingfunc->GetParameters();
763
         fparam = fittingfunc->GetParameters();
765
         fparamerr = fittingfunc->GetParErrors();
764
         fparamerr = fittingfunc->GetParErrors();
766
   
765
   
767
         // Gather the parameters (mean peak value for now)
766
         // Gather the parameters (mean peak value for now)
768
         int j = 1;
767
         int j = 1;
769
         int nrfit = 0;
768
         int nrfit = 0;
770
         while(1)
769
         while(1)
771
         {
770
         {
772
            if( (fparam[j] < 1.E-30) || (nrfit > 8) )
771
            if( (fparam[j] < 1.E-30) || (nrfit > 8) )
773
               break;
772
               break;
774
            else
773
            else
775
            {
774
            {
776
               // Check if pedestal is above the lower limit and sigma is smaller than the mean
775
               // Check if pedestal is above the lower limit and sigma is smaller than the mean
777
               if( (fparam[j] > pedesLow->widgetNE[0]->GetNumber()) && ((double)fparamerr[j]/fparam[j] < accError->widgetNE[0]->GetNumber()) )
776
               if( (fparam[j] > pedesLow->widgetNE[0]->GetNumber()) && ((double)fparamerr[j]/fparam[j] < accError->widgetNE[0]->GetNumber()) )
778
               {
777
               {
779
                  // With the additional ADC offset, we can shift the mean values slightly, so they are not close to the X.5, but to the X.0 values
778
                  // With the additional ADC offset, we can shift the mean values slightly, so they are not close to the X.5, but to the X.0 values
780
                  meansel[nrfit] = fparam[j]+(adcOffset->widgetNE[0]->GetNumber());
779
                  meansel[nrfit] = fparam[j]+(adcOffset->widgetNE[0]->GetNumber());
781
                  sigmasel[nrfit] = fparam[j+1];
780
                  sigmasel[nrfit] = fparam[j+1];
782
                  nrfit++;
781
                  nrfit++;
783
               }
782
               }
784
            }
783
            }
Line 862... Line 861...
862
      {
861
      {
863
         if( (nrfiles == 1) || (!multiSelect->widgetChBox[0]->IsDown()) )
862
         if( (nrfiles == 1) || (!multiSelect->widgetChBox[0]->IsDown()) )
864
         {
863
         {
865
            printf("PhotonMu(): Only one file selected. Not running analysis, just showing the fit.\n");
864
            printf("PhotonMu(): Only one file selected. Not running analysis, just showing the fit.\n");
866
 
865
 
867
            // Replot the spectrum on analysisCanvas and do not close the input file
866
            // Replot the spectrum on analysisCanvas and do not close the input file
868
            DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, 1);
867
            DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, 1);
869
            analysisCanvas->GetCanvas()->Modified();
868
            analysisCanvas->GetCanvas()->Modified();
870
            analysisCanvas->GetCanvas()->Update();
869
            analysisCanvas->GetCanvas()->Update();
871
       
870
       
872
            // Get the spectrum
871
            // Get the spectrum
873
            histtemp = (TH1F*)analysisCanvas->GetCanvas()->GetPrimitive(histname);
872
            histtemp = (TH1F*)analysisCanvas->GetCanvas()->GetPrimitive(histname);
874
            npeaks = 15;
873
            npeaks = 15;
875
            double par[300];
874
            double par[300];
876
            spec = new TSpectrum(npeaks);
875
            spec = new TSpectrum(npeaks);
877
            // Find spectrum background
876
            // Find spectrum background
878
            histback = spec->Background(histtemp, (int)fitInter->widgetNE[0]->GetNumber(), "same");
877
            histback = spec->Background(histtemp, (int)fitInter->widgetNE[0]->GetNumber(), "same");
879
            // Clone histogram and subtract background from it if we select that option
878
            // Clone histogram and subtract background from it if we select that option
880
            h2 = (TH1F*)histtemp->Clone("h2");
879
            h2 = (TH1F*)histtemp->Clone("h2");
881
            if(fitChecks->widgetChBox[0]->IsDown())
880
            if(fitChecks->widgetChBox[0]->IsDown())
882
               h2->Add(histback, -1);
881
               h2->Add(histback, -1);
883
            // Search for the peaks
882
            // Search for the peaks
884
            int found = spec->Search(h2, fitSigma->widgetNE[0]->GetNumber(), "goff", fitTresh->widgetNE[0]->GetNumber() );
883
            int found = spec->Search(h2, fitSigma->widgetNE[0]->GetNumber(), "goff", fitTresh->widgetNE[0]->GetNumber() );
885
            printf("PhotonMu(): Found %d candidates to fit.\n",found);
884
            printf("PhotonMu(): Found %d candidates to fit.\n",found);
886
            npeaks = found;
885
            npeaks = found;
887
   
886
   
888
            // Set initial peak parameters
887
            // Set initial peak parameters
889
            xpeaks = spec->GetPositionX();
888
            xpeaks = spec->GetPositionX();
890
            for(j = 0; j < found; j++)
889
            for(j = 0; j < found; j++)
891
            {
890
            {
892
               float xp = xpeaks[j];
891
               float xp = xpeaks[j];
893
               int bin = h2->GetXaxis()->FindBin(xp);
892
               int bin = h2->GetXaxis()->FindBin(xp);
894
               float yp = h2->GetBinContent(bin);
893
               float yp = h2->GetBinContent(bin);
895
               par[3*j] = yp;
894
               par[3*j] = yp;
896
               par[3*j+1] = xp;
895
               par[3*j+1] = xp;
897
               par[3*j+2] = (double)fitSigma->widgetNE[0]->GetNumber();
896
               par[3*j+2] = (double)fitSigma->widgetNE[0]->GetNumber();
898
            }
897
            }
899
         
898
         
900
            // Fit the histogram
899
            // Fit the histogram
901
            fit = new TF1("fit", FindPeaks, adcRange->widgetNE[0]->GetNumber(), adcRange->widgetNE[1]->GetNumber(), 3*npeaks);
900
            fit = new TF1("fit", FindPeaks, adcRange->widgetNE[0]->GetNumber(), adcRange->widgetNE[1]->GetNumber(), 3*npeaks);
902
            TVirtualFitter::Fitter(histtemp, 3*npeaks);
901
            TVirtualFitter::Fitter(histtemp, 3*npeaks);
903
            fit->SetParameters(par);
902
            fit->SetParameters(par);
904
            fit->SetNpx(300);
903
            fit->SetNpx(300);
905
            h2->Fit("fit","Q");
904
            h2->Fit("fit","Q");
906
            // Get the fitted parameters
905
            // Get the fitted parameters
907
            fittingfunc = h2->GetFunction("fit");
906
            fittingfunc = h2->GetFunction("fit");
908
            fparam = fittingfunc->GetParameters();
907
            fparam = fittingfunc->GetParameters();
909
            fparamerr = fittingfunc->GetParErrors();
908
            fparamerr = fittingfunc->GetParErrors();
910
   
909
   
911
            // Gather the parameters (mean peak value for now)
910
            // Gather the parameters (mean peak value for now)
912
            int j = 1;
911
            int j = 1;
913
            int nrfit = 0;
912
            int nrfit = 0;
914
            while(1)
913
            while(1)
915
            {
914
            {
Line 1194... Line 1193...
1194
            exclude = false;
1193
            exclude = false;
1195
 
1194
 
1196
            // Get next point values (if zero value -> need to add the dark hist value again)
1195
            // Get next point values (if zero value -> need to add the dark hist value again)
1197
            pointest[10] = angle[i];
1196
            pointest[10] = angle[i];
1198
            pointest[11] = muval[i];
1197
            pointest[11] = muval[i];
-
 
1198
//          printf("Last point = [%lf,%lf]\n", pointest[10], pointest[11]);
1199
 
1199
 
1200
            // Check if next point has larger error than acceptable (if yes, set exclude signal to true), reuse meansel[0]
1200
            // Check if next point has larger error than acceptable (if yes, set exclude signal to true), reuse meansel[0]
1201
            meansel[0] = PointEstimate(5, pointest);    // PointEstimate only works with very small step size
1201
            meansel[0] = PointEstimate(5, pointest);    // PointEstimate only works with very small step size
1202
            if(meansel[0] > accError->widgetNE[0]->GetNumber())
1202
            if(meansel[0] > accError->widgetNE[0]->GetNumber())
1203
            {
1203
            {
1204
               printf("PhotonMu(): Point (%lf, %lf) excluded due to error: %lf\n", pointest[10], pointest[11], meansel[0]);
1204
               printf("PhotonMu(): Point (%lf, %lf) excluded due to error: %lf\n", pointest[10], pointest[11], meansel[0]);
-
 
1205
               exclude = true;
-
 
1206
            }
-
 
1207
 
-
 
1208
            if(isinf(meansel[0]))
-
 
1209
            {
-
 
1210
               printf("PhotonMu(): Point (%lf, %lf) excluded due to being infinite: %lf\n", pointest[10], pointest[11], meansel[0]);
1205
               exclude = true;
1211
               exclude = true;
1206
            }
1212
            }
1207
 
1213
 
1208
            // Value with 0 angle and dark histogram are always needed, so should not be excluded
1214
            // Value with 0 angle and dark histogram are always needed, so should not be excluded
1209
            if(i == darkhist)
1215
            if(i == darkhist)
1210
               exclude = false;
1216
               exclude = false;
1211
 
1217
 
1212
            // If nothing excluded, pass the points in pointest variable like in a FIFO
1218
            // If nothing excluded, pass the points in pointest variable like in a FIFO
1213
            if(!exclude)
1219
            if(!exclude)
1214
            {
1220
            {
1215
               for(int j = 0; j < 10; j++)
1221
               for(int j = 0; j < 10; j++)
1216
               {
1222
               {
1217
                  if(DBGSIG) printf("PhotonMu(): j = %d: Old X value = %lf\n", j, pointest[j]);
1223
                  if(DBGSIG) printf("PhotonMu(): j = %d: Old X value = %lf\n", j, pointest[j]);
1218
                  pointest[j] = pointest[j+2];
1224
                  pointest[j] = pointest[j+2];
1219
               }
1225
               }
1220
            }
1226
            }
1221
            else
1227
            else
1222
            {
1228
            {
1223
               for(int j = 0; j < 10; j++)
1229
               for(int j = 0; j < 10; j++)
1224
                  if(DBGSIG) printf("PhotonMu(): No j = %d: Old X value = %lf\n", j, pointest[j]);
1230
                  if(DBGSIG) printf("PhotonMu(): No j = %d: Old X value = %lf\n", j, pointest[j]);
1225
            }
1231
            }
Line 1228... Line 1234...
1228
         {
1234
         {
1229
            // First 5 points act as estimator points for next one
1235
            // First 5 points act as estimator points for next one
1230
            pointest[2*m] = angle[i];
1236
            pointest[2*m] = angle[i];
1231
            pointest[2*m+1] = muval[i];
1237
            pointest[2*m+1] = muval[i];
1232
         }
1238
         }
-
 
1239
 
-
 
1240
         printf("Exclude signal = %d\n", (int)exclude);
1233
 
1241
 
1234
         // Run only if we have a dark run histogram and middle pedestal peak estimation
1242
         // Run only if we have a dark run histogram and middle pedestal peak estimation
1235
         if( (darkhist != -1) && midPeak->widgetChBox[0]->IsDown() )
1243
         if( (darkhist != -1) && midPeak->widgetChBox[0]->IsDown() )
1236
         {
1244
         {
1237
            if(DBGSIG) printf("PhotonMu(): m = %d, i = %d: muval = %lf, ", m, i, muval[i]);
1245
            if(DBGSIG) printf("PhotonMu(): m = %d, i = %d: muval = %lf, ", m, i, muval[i]);