]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCComposedCorrection.cxx
bug fix for fmd eventplane
[u/mrichter/AliRoot.git] / TPC / AliTPCComposedCorrection.cxx
index 1268b382323a88acd3cc64f67dc68730aa589166..e14f0e0f3dae22c337ebfc5ff05422ac38b1a321 100644 (file)
@@ -55,8 +55,9 @@
 
 
 #include <TCollection.h>
-#include <TIterator.h>
 #include <TTimeStamp.h>
+#include <TIterator.h>
+#include "AliLog.h"
 
 #include "AliTPCComposedCorrection.h"
 
@@ -65,7 +66,8 @@ AliTPCComposedCorrection::AliTPCComposedCorrection()
   : AliTPCCorrection("composed_correction",
                     "composition of corrections"),
     fCorrections(0),
-    fMode(kParallel)
+    fMode(kParallel),
+    fWeights(0)  // weights of corrections
 {
   //
   // default constructor
@@ -77,7 +79,8 @@ AliTPCComposedCorrection::AliTPCComposedCorrection(TCollection *corrections,
   : AliTPCCorrection("composed_correction",
                     "composition of corrections"),
     fCorrections(corrections),
-    fMode(mode)
+    fMode(mode),
+    fWeights(0) //weights of correction
 {
   //
   // Constructor that defines the set of corrections, this one is composed of.
@@ -86,25 +89,61 @@ AliTPCComposedCorrection::AliTPCComposedCorrection(TCollection *corrections,
 
 AliTPCComposedCorrection::~AliTPCComposedCorrection() {
   // 
-  // virtual destructor
+  // destructor
   //
+  if (!fCorrections) {
+    AliInfo("No Correction-models were set: can not delete them");
+  } else {
+    TIterator *i=fCorrections->MakeIterator();
+    AliTPCCorrection *c;
+    while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
+      delete c;
+    }
+    delete i;
+  }
+  if (fWeights) delete fWeights;
 }
 
+AliTPCCorrection * AliTPCComposedCorrection::GetSubCorrection(Int_t ipos){
+  //
+  //
+  //
+  TObjArray *arr = (TObjArray*)fCorrections;
+  return (AliTPCCorrection *)arr->At(ipos);
+}
+
+AliTPCCorrection * AliTPCComposedCorrection::GetSubCorrection(const char *cname){
+  //
+  //
+  //
+  TCollection *arr = fCorrections;
+  return (AliTPCCorrection *)arr->FindObject(cname);
+}
+
+
 
 void AliTPCComposedCorrection::GetCorrection(const Float_t x[],const Short_t roc,Float_t dx[]) {
   //
   // This applies all correction and the specified manner (see general
   // class description for details).
   //
+
+  if (!fCorrections) {
+    AliInfo("No Corrections-models were set: can not calculate distortions");
+    return;
+  }
   TIterator *i=fCorrections->MakeIterator();
   AliTPCCorrection *c;
+  Int_t weightIndex=0;
   switch (fMode) {
   case kParallel:
     Float_t dxi[3];
     for (int j=0;j<3;++j) dx[j]=0.;
     while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
       c->GetCorrection(x,roc,dxi);
-      for (Int_t j=0;j<3;++j) dx[j]+=dxi[j];
+      Double_t w=1;
+      if (fWeights) w=(*fWeights)[weightIndex++];
+      for (Int_t j=0;j<3;++j) dx[j]+=w*dxi[j];
     }
     break;
   case kQueue:
@@ -112,7 +151,9 @@ void AliTPCComposedCorrection::GetCorrection(const Float_t x[],const Short_t roc
     for (Int_t j=0;j<3;++j) xi[j]=x[j];
     while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
       c->GetCorrection(xi,roc,dx);
-      for (Int_t j=0;j<3;++j) xi[j]+=dx[j];
+      Double_t w=1;
+      if (fWeights) w=(*fWeights)[weightIndex++];
+      for (Int_t j=0;j<3;++j) xi[j]+=w*dx[j];
     }
     for (Int_t j=0;j<3;++j) dx[j]=xi[j]-x[j];
     break;
@@ -126,15 +167,22 @@ void AliTPCComposedCorrection::GetDistortion(const Float_t x[],const Short_t roc
   // class descxiption for details).
   //
 
+  if (!fCorrections) {
+    AliInfo("No Corrections-models were set: can not calculate distortions");
+    return;
+  }
   TIterator *i=fCorrections->MakeReverseIterator();
   AliTPCCorrection *c;
+  Int_t weightIndex=0;
   switch (fMode) {
   case kParallel:
     Float_t dxi[3];
     for (int j=0;j<3;++j) dx[j]=0.;
     while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
       c->GetDistortion(x,roc,dxi);
-      for (Int_t j=0;j<3;++j) dx[j]+=dxi[j];
+      Double_t w=1;
+      if (fWeights) w=(*fWeights)[weightIndex++];
+      for (Int_t j=0;j<3;++j) dx[j]+=w*dxi[j];
     }
     break;
   case kQueue:
@@ -142,7 +190,9 @@ void AliTPCComposedCorrection::GetDistortion(const Float_t x[],const Short_t roc
     for (Int_t j=0;j<3;++j) xi[j]=x[j];
     while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
       c->GetDistortion(xi,roc,dx);
-      for (Int_t j=0;j<3;++j) xi[j]+=dx[j];
+      Double_t w=1;
+      if (fWeights) w=(*fWeights)[weightIndex++];
+      for (Int_t j=0;j<3;++j) xi[j]+=w*dx[j];
     }
     for (Int_t j=0;j<3;++j) dx[j]=xi[j]-x[j];
     break;
@@ -161,14 +211,19 @@ void AliTPCComposedCorrection::Print(Option_t* option) const {
   printf("Composed TPC spacepoint correction \"%s\" -- composed of:\n",GetTitle());
   TString opt = option; opt.ToLower();
   Int_t in=1;
+  if (!fCorrections) {
+    printf("   - composed correction is empty!\n");
+    return;
+  }
   TIterator *i=fCorrections->MakeIterator();
   AliTPCCorrection *c;
   while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
     if (opt.Contains("d")) {
-      printf("%d. ",in);
+      printf("\n");
+      printf("%d. %s\t%s\n",in,c->GetTitle(), c->GetName());
       c->Print(option);
     } else {
-      printf("%d. %s\n",in,c->GetTitle());
+      printf("%d. %s\t%s\n",in,c->GetTitle(), c->GetName());
     }
     ++in;
   }
@@ -181,7 +236,10 @@ void AliTPCComposedCorrection::Init() {
   //
   // Initialization funtion (not used at the moment)
   //
-  
+  if (!fCorrections) {
+    AliInfo("No Correction-models were set");
+    return;
+  }
   TIterator *i=fCorrections->MakeIterator();
   AliTPCCorrection *c;
   while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) 
@@ -194,6 +252,10 @@ void AliTPCComposedCorrection::Update(const TTimeStamp &timeStamp) {
   //
   // Update function 
   //
+  if (!fCorrections) {
+    AliInfo("No Correction-models were set");
+    return;
+  }
 
   TIterator *i=fCorrections->MakeIterator();
   AliTPCCorrection *c;
@@ -218,6 +280,11 @@ void AliTPCComposedCorrection::SetOmegaTauT1T2(Float_t omegaTau,Float_t t1,Float
   // Note: overwrites previously set values!
   // 
 
+  if (!fCorrections) {
+    AliInfo("No Correction-models were set");
+    return;
+  }
+
   TIterator *i=fCorrections->MakeIterator();
   AliTPCCorrection *c;
   while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {