]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HMPID/AliHMPIDCluster.cxx
some viol fixed
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDCluster.cxx
index 4a54c1b3cb49e8c320b1542e540d64ca72d1a101..45aa58bafa58fea93c20313fdcc0c5b3bbb59c8f 100644 (file)
@@ -81,7 +81,7 @@ void AliHMPIDCluster::Draw(Option_t*)
   TMarker *pMark=new TMarker(X(),Y(),5); pMark->SetUniqueID(fSt);pMark->SetMarkerColor(kBlue); pMark->Draw();
 }
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-void AliHMPIDCluster::FitFunc(Int_t &iNpars, Double_t* deriv, Double_t &chi2, Double_t *par, Int_t /* */)
+void AliHMPIDCluster::FitFunc(Int_t &iNpars, Double_t* deriv, Double_t &chi2, Double_t *par, Int_t iflag)
 {
 // Cluster fit function 
 // par[0]=x par[1]=y par[2]=q for the first Mathieson shape
@@ -96,55 +96,64 @@ void AliHMPIDCluster::FitFunc(Int_t &iNpars, Double_t* deriv, Double_t &chi2, Do
   AliHMPIDCluster *pClu=(AliHMPIDCluster*)TVirtualFitter::GetFitter()->GetObjectFit();
 
   Int_t nPads = pClu->Size();  
-  Double_t **derivPart;
   
-  derivPart = new Double_t*[iNpars];
   chi2 = 0;
   
   Int_t iNshape = iNpars/3;
   
-  for(Int_t j=0;j<iNpars;j++){                                                      
-    deriv[j] = 0;
-    derivPart[j] = new Double_t[nPads];
-    for(Int_t i=0;i<nPads;i++){                                                          
-      derivPart[j][i] = 0;
-    }
-  }
-  
-  if(iNshape>6) {Printf("HMPID Error!!: n. of clusters in FitFunc %i",iNshape);return;}
   for(Int_t i=0;i<nPads;i++){                                                          //loop on all pads of the cluster
     Double_t dQpadMath = 0;
     for(Int_t j=0;j<iNshape;j++){                                                      //Mathiesons loop as all of them may contribute to this pad
       Double_t fracMathi = pClu->Dig(i)->IntMathieson(par[3*j],par[3*j+1]);
       dQpadMath+=par[3*j+2]*fracMathi;                                                 // par[3*j+2] is charge par[3*j] is x par[3*j+1] is y of current Mathieson
-      
-      derivPart[3*j  ][i] += par[3*j+2]*(pClu->Dig(i)->Mathieson(par[3*j]-pClu->Dig(i)->LorsX()-0.5*AliHMPIDParam::SizePadX())-
-                                         pClu->Dig(i)->Mathieson(par[3*j]-pClu->Dig(i)->LorsX()+0.5*AliHMPIDParam::SizePadX()))*
-                                         pClu->Dig(i)->IntPartMathi(par[3*j+1],2);
-      derivPart[3*j+1][i] += par[3*j+2]*(pClu->Dig(i)->Mathieson(par[3*j+1]-pClu->Dig(i)->LorsY()-0.5*AliHMPIDParam::SizePadY())-
-                                         pClu->Dig(i)->Mathieson(par[3*j+1]-pClu->Dig(i)->LorsY()+0.5*AliHMPIDParam::SizePadY()))*
-                                         pClu->Dig(i)->IntPartMathi(par[3*j],1);
-      derivPart[3*j+2][i] += fracMathi;
     }
     if(dQpadMath>0 && pClu->Dig(i)->Q()>0) {
       chi2 +=TMath::Power((pClu->Dig(i)->Q()-dQpadMath),2)/pClu->Dig(i)->Q();          //chi2 function to be minimized
     }
   }
-                                                                                       //loop on all pads of the cluster     
-  for(Int_t i=0;i<nPads;i++){                                                          //loop on all pads of the cluster
-    Double_t dQpadMath = 0;                                                            //pad charge collector  
-    for(Int_t j=0;j<iNshape;j++){                                                      //Mathiesons loop as all of them may contribute to this pad
-      Double_t fracMathi = pClu->Dig(i)->IntMathieson(par[3*j],par[3*j+1]);
-      dQpadMath+=par[3*j+2]*fracMathi;                                                 
-      if(dQpadMath>0 && pClu->Dig(i)->Q()>0) {
-        deriv[3*j]   += 2/pClu->Dig(i)->Q()*(pClu->Dig(i)->Q()-dQpadMath)*derivPart[3*j  ][i];
-        deriv[3*j+1] += 2/pClu->Dig(i)->Q()*(pClu->Dig(i)->Q()-dQpadMath)*derivPart[3*j+1][i];
-        deriv[3*j+2] += 2/pClu->Dig(i)->Q()*(pClu->Dig(i)->Q()-dQpadMath)*derivPart[3*j+2][i];
+//---calculate gradients...  
+  if(iflag==2) {
+    Double_t **derivPart;
+
+    derivPart = new Double_t*[iNpars];
+
+    for(Int_t j=0;j<iNpars;j++){                                                      
+      deriv[j] = 0;
+      derivPart[j] = new Double_t[nPads];
+      for(Int_t i=0;i<nPads;i++){                                                          
+        derivPart[j][i] = 0;
+      }
+    }
+
+    for(Int_t i=0;i<nPads;i++){                                                          //loop on all pads of the cluster
+      for(Int_t j=0;j<iNshape;j++){                                                      //Mathiesons loop as all of them may contribute to this pad
+        Double_t fracMathi = pClu->Dig(i)->IntMathieson(par[3*j],par[3*j+1]);
+        derivPart[3*j  ][i] += par[3*j+2]*(pClu->Dig(i)->Mathieson(par[3*j]-pClu->Dig(i)->LorsX()-0.5*AliHMPIDParam::SizePadX())-
+                                           pClu->Dig(i)->Mathieson(par[3*j]-pClu->Dig(i)->LorsX()+0.5*AliHMPIDParam::SizePadX()))*
+                                           pClu->Dig(i)->IntPartMathi(par[3*j+1],2);
+        derivPart[3*j+1][i] += par[3*j+2]*(pClu->Dig(i)->Mathieson(par[3*j+1]-pClu->Dig(i)->LorsY()-0.5*AliHMPIDParam::SizePadY())-
+                                           pClu->Dig(i)->Mathieson(par[3*j+1]-pClu->Dig(i)->LorsY()+0.5*AliHMPIDParam::SizePadY()))*
+                                           pClu->Dig(i)->IntPartMathi(par[3*j],1);
+        derivPart[3*j+2][i] += fracMathi;
+      }
+    }
+                                                                                         //loop on all pads of the cluster     
+    for(Int_t i=0;i<nPads;i++){                                                          //loop on all pads of the cluster
+      Double_t dQpadMath = 0;                                                            //pad charge collector  
+      for(Int_t j=0;j<iNshape;j++){                                                      //Mathiesons loop as all of them may contribute to this pad
+        Double_t fracMathi = pClu->Dig(i)->IntMathieson(par[3*j],par[3*j+1]);
+        dQpadMath+=par[3*j+2]*fracMathi;                                                 
+        if(dQpadMath>0 && pClu->Dig(i)->Q()>0) {
+          deriv[3*j]   += 2/pClu->Dig(i)->Q()*(pClu->Dig(i)->Q()-dQpadMath)*derivPart[3*j  ][i];
+          deriv[3*j+1] += 2/pClu->Dig(i)->Q()*(pClu->Dig(i)->Q()-dQpadMath)*derivPart[3*j+1][i];
+          deriv[3*j+2] += 2/pClu->Dig(i)->Q()*(pClu->Dig(i)->Q()-dQpadMath)*derivPart[3*j+2][i];
+        }
       }
     }
+    //delete array...
+    for(Int_t i=0;i<iNpars;i++) delete [] derivPart[i]; delete [] derivPart;
   }
-  //delete array...
-  for(Int_t i=0;i<iNpars;i++) delete [] derivPart[i]; delete [] derivPart;
+//---gradient calculations ended
   
 }//FitFunction()
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -189,7 +198,7 @@ Int_t AliHMPIDCluster::Solve(TClonesArray *pCluLst,Bool_t isTryUnfold)
   CoG();                                                                                 //First calculate CoG for the given cluster
   Int_t iCluCnt=pCluLst->GetEntriesFast();                                               //get current number of clusters already stored in the list by previous operations
   if(isTryUnfold==kFALSE || Size()==1) {                                                 //if cluster contains single pad there is no way to improve the knowledge 
-    (isTryUnfold)?fSt=kSi1:fSt=kNot;
+    fSt = (isTryUnfold) ? kSi1: kNot;
     new ((*pCluLst)[iCluCnt++]) AliHMPIDCluster(*this);  //add this raw cluster 
     return 1;
   } 
@@ -240,7 +249,7 @@ Int_t AliHMPIDCluster::Solve(TClonesArray *pCluLst,Bool_t isTryUnfold)
       
       ierflg = fitter->SetParameter(3*fNlocMax  ,Form("x%i",fNlocMax),xStart,0.1,xMin,xMax);    // X,Y,Q initial values of the loc max pad
       ierflg = fitter->SetParameter(3*fNlocMax+1,Form("y%i",fNlocMax),yStart,0.1,yMin,yMax);    // X, Y constrained to be near the loc max
-      ierflg = fitter->SetParameter(3*fNlocMax+2,Form("q%i",fNlocMax),pDig1->Q(),0.1,0,100000); // Q constrained to be positive
+      ierflg = fitter->SetParameter(3*fNlocMax+2,Form("q%i",fNlocMax),pDig1->Q(),0.1,0,10000);  // Q constrained to be positive
       
       fNlocMax++;
       
@@ -253,7 +262,7 @@ Int_t AliHMPIDCluster::Solve(TClonesArray *pCluLst,Bool_t isTryUnfold)
    
    ierflg = fitter->SetParameter(3*fNlocMax  ,Form("x%i",fNlocMax),fX,0.1,0,0);              // Init values taken from CoG() -> fX,fY,fQRaw
    ierflg = fitter->SetParameter(3*fNlocMax+1,Form("y%i",fNlocMax),fY,0.1,0,0);              //
-   ierflg = fitter->SetParameter(3*fNlocMax+2,Form("q%i",fNlocMax),fQRaw,0.1,0,100000);      //
+   ierflg = fitter->SetParameter(3*fNlocMax+2,Form("q%i",fNlocMax),fQRaw,0.1,0,10000);       //
    
    fNlocMax = 1;
    fSt=kNoLoc;