Be sure to load mapping when needed
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraVdriftLinearFit.cxx
index 7fed240..a2a2581 100644 (file)
@@ -117,6 +117,10 @@ AliTRDCalibraVdriftLinearFit::~AliTRDCalibraVdriftLinearFit() /*FOLD00*/
   //
   // destructor
   //
+  fLinearFitterHistoArray.SetOwner();
+  fLinearFitterPArray.SetOwner();
+  fLinearFitterEArray.SetOwner();
+
   fLinearFitterHistoArray.Delete();
   fLinearFitterPArray.Delete();
   fLinearFitterEArray.Delete();
@@ -180,7 +184,7 @@ Long64_t AliTRDCalibraVdriftLinearFit::Merge(const TCollection* list)
   return count;
 }
 //_____________________________________________________________________
-void AliTRDCalibraVdriftLinearFit::Add(AliTRDCalibraVdriftLinearFit *ped)
+void AliTRDCalibraVdriftLinearFit::Add(const AliTRDCalibraVdriftLinearFit *ped)
 {
   //
   // Add histo
@@ -189,7 +193,7 @@ void AliTRDCalibraVdriftLinearFit::Add(AliTRDCalibraVdriftLinearFit *ped)
   fVersion++;
 
   for (Int_t idet = 0; idet < 540; idet++){
-    const TH2S         *hped        = (TH2S*)ped->GetLinearFitterHisto(idet);
+    const TH2S         *hped        = (TH2S*)ped->GetLinearFitterHistoNoForce(idet);
     //printf("idet %d\n",idet);
     if ( hped != 0x0 ){
       //printf("add\n");
@@ -210,25 +214,38 @@ TH2S* AliTRDCalibraVdriftLinearFit::GetLinearFitterHisto(Int_t detector, Bool_t
     if ( !force || fLinearFitterHistoArray.UncheckedAt(detector) )
        return (TH2S*)fLinearFitterHistoArray.UncheckedAt(detector);
 
-    // if we are forced and TLinearFitter doesn't yes exist create it
-
-    // new TH2F
-    TString name("LFDV");
-    name += detector;
-    name += "version";
-    name +=  fVersion;
-
-    TH2S *lfdv = new TH2S((const Char_t *)name,(const Char_t *) name
-                 ,36,-0.9,0.9,48
-                 ,-1.2,1.2);
-    lfdv->SetXTitle("tan(phi_{track})");
-    lfdv->SetYTitle("dy/dt");
-    lfdv->SetZTitle("Number of clusters");
-    lfdv->SetStats(0);
-    lfdv->SetDirectory(0);
+    return GetLinearFitterHistoForce(detector);
 
-    fLinearFitterHistoArray.AddAt(lfdv,detector);
-    return lfdv;
+}
+//______________________________________________________________________________________
+TH2S* AliTRDCalibraVdriftLinearFit::GetLinearFitterHistoForce(Int_t detector)
+{
+  //
+  // return pointer to TH2F histo 
+  // if NULL create a new histo if it doesn't exist allready
+  //
+  if (fLinearFitterHistoArray.UncheckedAt(detector))
+    return (TH2S*)fLinearFitterHistoArray.UncheckedAt(detector);
+  
+  // if we are forced and TLinearFitter doesn't yes exist create it
+  
+  // new TH2F
+  TString name("LFDV");
+  name += detector;
+  name += "version";
+  name +=  fVersion;
+  
+  TH2S *lfdv = new TH2S((const Char_t *)name,(const Char_t *) name
+                       ,36,-0.9,0.9,48
+                       ,-1.2,1.2);
+  lfdv->SetXTitle("tan(phi_{track})");
+  lfdv->SetYTitle("dy/dt");
+  lfdv->SetZTitle("Number of clusters");
+  lfdv->SetStats(0);
+  lfdv->SetDirectory(0);
+  
+  fLinearFitterHistoArray.AddAt(lfdv,detector);
+  return lfdv;
 }
 //______________________________________________________________________________________
 Bool_t AliTRDCalibraVdriftLinearFit::GetParam(Int_t detector, TVectorD *param)
@@ -301,15 +318,29 @@ void AliTRDCalibraVdriftLinearFit::FillPEArray()
       TAxis *yaxis = linearfitterhisto->GetYaxis();
       TLinearFitter linearfitter = TLinearFitter(2,"pol1");
       //printf("test\n");
+      Double_t integral = linearfitterhisto->Integral();
+      //printf("Integral is %f\n",integral);
+      Bool_t securitybreaking = kFALSE;
+      if(TMath::Abs(integral-1199) < 0.00001) securitybreaking = kTRUE;
       for(Int_t ibinx = 0; ibinx < linearfitterhisto->GetNbinsX(); ibinx++){
        for(Int_t ibiny = 0; ibiny < linearfitterhisto->GetNbinsY(); ibiny++){
          if(linearfitterhisto->GetBinContent(ibinx+1,ibiny+1)>0){
            Double_t x = xaxis->GetBinCenter(ibinx+1);
            Double_t y = yaxis->GetBinCenter(ibiny+1);
+           
            for(Int_t k = 0; k < (Int_t)linearfitterhisto->GetBinContent(ibinx+1,ibiny+1); k++){
-             linearfitter.AddPoint(&x,y);
-             arrayI[cb]++;
+             if(!securitybreaking){
+               linearfitter.AddPoint(&x,y);
+               arrayI[cb]++;
+             }
+             else {
+               if(arrayI[cb]< 1198){
+                 linearfitter.AddPoint(&x,y);
+                 arrayI[cb]++; 
+               }
+             }
            }
+           
          }
        }
       }
@@ -321,23 +352,37 @@ void AliTRDCalibraVdriftLinearFit::FillPEArray()
        TVectorD  *par  = new TVectorD(2);
        TVectorD   pare = TVectorD(2);
        TVectorD  *parE = new TVectorD(3);
-       linearfitter.Eval();
-       linearfitter.GetParameters(*par);
-       linearfitter.GetErrors(pare);
-       Float_t  ppointError =  TMath::Sqrt(TMath::Abs(linearfitter.GetChisquare())/arrayI[cb]);
-       (*parE)[0] = pare[0]*ppointError;
-       (*parE)[1] = pare[1]*ppointError;
-       (*parE)[2] = (Double_t) arrayI[cb];
-       fLinearFitterPArray.AddAt(par,cb);
-       fLinearFitterEArray.AddAt(parE,cb);
-       //par->Print();
-       //parE->Print();
+       //printf("Fit\n");
+       if((linearfitter.EvalRobust(0.8)==0)) {
+         //if((linearfitter.Eval()==0)) {
+         //printf("Take the param\n");
+         linearfitter.GetParameters(*par);
+         //printf("Done\n");
+         //linearfitter.GetErrors(pare);
+         //Float_t  ppointError =  TMath::Sqrt(TMath::Abs(linearfitter.GetChisquare())/arrayI[cb]);
+         //(*parE)[0] = pare[0]*ppointError;
+         //(*parE)[1] = pare[1]*ppointError;
+         
+         (*parE)[0] = 0.0;
+         (*parE)[1] = 0.0;
+         (*parE)[2] = (Double_t) arrayI[cb];
+         fLinearFitterPArray.AddAt(par,cb);
+         fLinearFitterEArray.AddAt(parE,cb);
+         
+         //par->Print();
+         //parE->Print();
+       }
+       //printf("Finish\n");
       }
-
-      delete linearfitterhisto;
+      
+      //delete linearfitterhisto;
       
     }// if something
+
   }
+
+  delete [] arrayI;
    
 }
 
+