| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

NIMmodel.h

Go to the documentation of this file.
00001 // ---------------------------------------------------
00002 // NIMmodel.h
00003 //
00004 // Used to fit adc distributions. 
00005 //
00006 // Author: J. Pedro Ochoa, adapted from Qing He's Calibration/RollingGain package
00007 //
00008 // March 19 2011
00009 // ---------------------------------------------------
00010 
00011 #include <iostream>
00012 #include <math.h>
00013 #include "TSystem.h"
00014 #include "TMath.h"
00015 
00016 double poisson(double u, int n){
00017   return pow(u,n)*exp(-u)/TMath::Gamma(n+1);
00018 }
00019 
00020 double gn(double x,double n, double q0, double sigma0,
00021           double q1, double sigma1){
00022   double sigman = sqrt(sigma0*sigma0+n*sigma1*sigma1);
00023   double xn = x-q0-n*q1;
00024   double tmp = pow(xn,2)/(2*sigman*sigman);
00025   return exp(-tmp)/(sigman*sqrt(2*TMath::Pi()));
00026 }
00027 
00028 double NIMmodel(double* xpar,double* par){
00029   double x =      xpar[0];
00030   double norm =   par[0];
00031   double q0 =     par[1];
00032   double sigma0 = par[2];
00033   double q1 =     par[3];  
00034   double sigma1 = par[4];
00035   double w =      par[5];
00036   double a =      par[6];
00037   double u =      par[7];
00038   int nmin =   1;
00039   int nmax =   6;
00040 
00041   double total = 0;
00042   for(int i=nmin; i<nmax; i++){
00043     int n = i;
00044     double tmp = poisson(u,n);
00045     double tmp2 = gn(x,n,q0,sigma0,q1,sigma1);
00046     double qn = q0+n*q1;
00047     double sigman = sqrt(sigma0*sigma0+n*sigma1*sigma1);
00048 
00049     double tmp3 = exp(-a*(x-qn-a*sigman*sigman/2.))*a/2.;
00050     double tmp4 = TMath::Erf(fabs(q0-qn-a*sigman*sigman)/(sigman*sqrt(2.)));
00051     double sign = 1.0;
00052     if((x-qn-sigman*sigman*a)<0) sign = -1.0;
00053     tmp4 += sign*TMath::Erf(fabs(x-qn-sigman*sigman*a)/(sigman*sqrt(2.)));
00054     tmp3 *= tmp4;
00055     
00056     double result = tmp*((1-w)*tmp2+w*tmp3);
00057     total += result;
00058   }
00059   return total*norm;
00060 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:29:39 2011 for CalibParam by doxygen 1.4.7