]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCComposedCorrection.cxx
Additional protection
[u/mrichter/AliRoot.git] / TPC / AliTPCComposedCorrection.cxx
index c85d82d3c66283631cef1a12e1486469a30f1758..2081e1edbadb3c0f993dc6320ef66678ff447cdd 100644 (file)
@@ -57,7 +57,7 @@
 #include <TCollection.h>
 #include <TTimeStamp.h>
 #include <TIterator.h>
-
+#include "AliLog.h"
 
 #include "AliTPCComposedCorrection.h"
 
@@ -66,7 +66,8 @@ AliTPCComposedCorrection::AliTPCComposedCorrection()
   : AliTPCCorrection("composed_correction",
                     "composition of corrections"),
     fCorrections(0),
-    fMode(kParallel)
+    fMode(kParallel),
+    fWeights(0)  // weights of corrections
 {
   //
   // default constructor
@@ -78,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.
@@ -87,8 +89,19 @@ 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;
 }
 
 
@@ -97,15 +110,23 @@ void AliTPCComposedCorrection::GetCorrection(const Float_t x[],const Short_t roc
   // 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:
@@ -113,7 +134,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;
@@ -127,15 +150,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:
@@ -143,7 +173,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;
@@ -162,14 +194,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;
   }
@@ -182,7 +219,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()))) 
@@ -195,6 +235,10 @@ void AliTPCComposedCorrection::Update(const TTimeStamp &timeStamp) {
   //
   // Update function 
   //
+  if (!fCorrections) {
+    AliInfo("No Correction-models were set");
+    return;
+  }
 
   TIterator *i=fCorrections->MakeIterator();
   AliTPCCorrection *c;
@@ -219,6 +263,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()))) {