Index: trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- trunk/MagicSoft/Mars/macros/calibration.C	(revision 2908)
+++ trunk/MagicSoft/Mars/macros/calibration.C	(revision 2923)
@@ -23,6 +23,9 @@
 \* ======================================================================== */
 
-const TString pedfile = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/20031218_03522_P_Park_E.root";
-const TString calfile = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/20031218_03527_C_Park_E.root";
+const TString pedfile = "/mnt/Data/rootdata/Mrk421/2004_01_26/20040125_12094_P_Mrk421_E.root";
+const TString calfile = "/mnt/Data/rootdata/Mrk421/2004_01_26/20040125_1211*_C_Mrk421_E.root";
+
+//const TString pedfile = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/20031218_03522_P_Park_E.root";
+//const TString calfile = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/20031218_03527_C_Park_E.root";
 
 void calibration(TString pedname=pedfile,
@@ -114,4 +117,10 @@
 
     //
+    // Making the step size a bit bigger, gives us 
+    // faster results
+    // 
+    timecalc.SetStepSize(0.5);
+
+    //
     // As long, as we don't have digital modules, 
     // we have to set the color of the pulser LED by hand
@@ -148,4 +157,5 @@
     //
     MCalibrationBlindPix *bp = calcam.GetBlindPixel();
+    //    bp->ChangeFitFunc(MHCalibrationBlindPixel::kEPolya);
     bp->ChangeFitFunc(MHCalibrationBlindPixel::kEPoisson5);
 
@@ -156,5 +166,5 @@
     // of the arrival times using a spline, uncomment the next line
     //
-    // tlist2.AddToList(&timecalc);
+    tlist2.AddToList(&timecalc);
     tlist2.AddToList(&calcalc);
 
@@ -164,5 +174,5 @@
     MEvtLoop evtloop2;
     evtloop2.SetParList(&plist2);
-
+    
     //
     // Execute second analysis
@@ -183,5 +193,4 @@
     calcam[17].DrawClone();
 
-    MHCamEvent camevt;
     MHCamera disp1   (geomcam, "MCalibrationPix;Charge", "Fitted Mean Charges");
     MHCamera disp3   (geomcam, "MCalibrationPix;SigmaCharge", "Sigma of Fitted Charges");
@@ -258,6 +267,6 @@
     c1.Divide(2,3);
 
-    CamDraw(c1,disp1,&calcam,1,2,1);
-    CamDraw(c1,disp3,&calcam,2,2,2);
+    CamDraw(c1,disp1,calcam,1,2,1);
+    CamDraw(c1,disp3,calcam,2,2,1);
 
     // Fit Probability
@@ -265,5 +274,5 @@
     c2.Divide(1,3);
 
-    CamDraw(c2,disp5,&calcam,1,1,3);
+    CamDraw(c2,disp5,calcam,1,1,3);
 
     // Times
@@ -271,7 +280,7 @@
     c3.Divide(3,3);
 
-    CamDraw(c3,disp6,&calcam,1,3,1);
-    CamDraw(c3,disp7,&calcam,2,3,0);
-    CamDraw(c3,disp8,&calcam,3,3,0);
+    CamDraw(c3,disp6,calcam,1,3,1);
+    CamDraw(c3,disp7,calcam,2,3,0);
+    CamDraw(c3,disp8,calcam,3,3,0);
 
     // Pedestals
@@ -279,6 +288,6 @@
     c4.Divide(2,3);
 
-    CamDraw(c4,disp9,&calcam,1,2,0);
-    CamDraw(c4,disp10,&calcam,2,2,1);
+    CamDraw(c4,disp9,calcam,1,2,0);
+    CamDraw(c4,disp10,calcam,2,2,1);
 
     // Reduced Sigmas
@@ -286,6 +295,7 @@
     c5.Divide(2,3);
 
-    CamDraw(c5,disp11,&calcam,1,2,2);
-    CamDraw(c5,disp16,&calcam,2,2,2);
+    //    CamDraw(c5,disp11,calcam,1,2,1);
+    CamDraw(c5,disp11,calcam,1,2,2);
+    CamDraw(c5,disp16,calcam,2,2,1);
 
     // F-Factor Method
@@ -293,6 +303,6 @@
     c6.Divide(2,3);
 
-    CamDraw(c6,disp12,&calcam,1,2,1);
-    CamDraw(c6,disp13,&calcam,2,2,2);
+    CamDraw(c6,disp12,calcam,1,2,1);
+    CamDraw(c6,disp13,calcam,2,2,1);
 
     // Blind Pixel Method
@@ -300,10 +310,10 @@
     c7.Divide(2, 3);
 
-    CamDraw(c7,disp14,&calcam,1,2,9);
-    CamDraw(c7,disp15,&calcam,2,2,2);
+    CamDraw(c7,disp14,calcam,1,2,9);
+    CamDraw(c7,disp15,calcam,2,2,1);
 
 }
 
-void CamDraw(TCanvas &c, MHCamera &cam, MCamEvent *evt, Int_t i, Int_t j, Int_t fit)
+void CamDraw(TCanvas &c, MHCamera &cam, MCamEvent &evt, Int_t i, Int_t j, Int_t fit)
 {
 
@@ -311,5 +321,5 @@
   gPad->SetBorderMode(0);
   MHCamera *obj1=(MHCamera*)cam.DrawCopy("hist");
-  obj1->AddNotify(*evt);
+  obj1->AddNotify(evt);
   
   c.cd(i+j);
@@ -326,9 +336,9 @@
   const Double_t min   = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
   const Double_t max   = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
-  const Double_t integ = obj2->Integral("width")/2.5;
+  const Double_t integ = obj2->Integral("width")/2.5066283;
   const Double_t mean  = obj2->GetMean();
   const Double_t rms   = obj2->GetRMS();
   const Double_t width = max-min;
-  
+
   if (rms == 0. || width == 0. )
     return;
@@ -349,20 +359,26 @@
 
     case 1:
-      TF1 *dgaus = new TF1("dgaus","gaus(0)+gaus(3)",min,max);
+      TString dgausform = "([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])";
+      dgausform += "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])";
+      TF1 *dgaus = new TF1("dgaus",dgausform.Data(),min,max);
       dgaus->SetBit(kCanDelete);
-      dgaus->SetParNames("A1","#mu1","#sigma1","A2","#mu2","#sigma2");
-      dgaus->SetParameters(integ/width,max-width/6.,width/4.,
-                           integ/width,min+width/6.,width/4.);
-      dgaus->SetParLimits(0,0,integ);
-      dgaus->SetParLimits(1,min,max);
-      dgaus->SetParLimits(2,0,width/3.);
+      dgaus->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}","A_{2}","#mu_{2}","#sigma_{2}");
+      dgaus->SetParameters(integ,(min+mean)/2.,width/4.,
+                           integ/width/2.,(max+mean)/2.,width/4.);
+      dgaus->SetParLimits(0,integ-1.5,integ+1.5);
+      dgaus->SetParLimits(1,min+(width/10.),mean);
+      dgaus->SetParLimits(2,0,width/2.);
       dgaus->SetParLimits(3,0,integ);
-      dgaus->SetParLimits(4,min,max);
-      dgaus->SetParLimits(5,0,width/3.);
-      obj2->Fit("dgaus","QLR");
+      dgaus->SetParLimits(4,mean,max-(width/10.));
+      cout << "mean: " << mean << " maxL " << max-(width/10.) << endl;
+      
+      dgaus->SetParLimits(5,0,width/2.);
+      obj2->Fit("dgaus","QLRM");
       obj2->GetFunction("dgaus")->SetLineColor(kYellow);
       break;
 
     case 2:
+      TString tgausform = "([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])";
+      tgausform += "+[3]/[4]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])";
       TF1 *tgaus = new TF1("tgaus","gaus(0)+gaus(3)+gaus(6)",min,max);
       tgaus->SetBit(kCanDelete);
