]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCComposedCorrection.cxx
1. Protection against 0 error estimate
[u/mrichter/AliRoot.git] / TPC / AliTPCComposedCorrection.cxx
1
2 /**************************************************************************
3  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  *                                                                        *
5  * Author: The ALICE Off-line Project.                                    *
6  * Contributors are mentioned in the code where appropriate.              *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 ////////////////////////////////////////////////////////////////////////////////
18 //                                                                            //
19 // AliTPCComposedCorrection class                                             //
20 //                                                                            //
21 // This class is creating a correction that is composed out of smaller        //
22 // corrections.                                                               //
23 // There are two ways the sub-corrections can be combined into this one:      //
24 // 1. kParallel: All corrections are applied at the given position x and      //
25 //    the dx terms are summed up (this commutes).                             //
26 // 2. kQueue: The corrections are called in order. The first one at the       //
27 //    given position x resulting in dx1, the second one is called at          //
28 //    the corrected position (x+dx1) resulting in dx2, the third one          //
29 //    is then called at position (x+dx1+dx2) and so forth. dx=dx1+dx2+...     //
30 //    is returned.                                                            //
31 // For the inverse of the correction this is taken into account by reversing  //
32 // the order the corrections are applied in the kQueue case (no issue for     //
33 // kParallel).                                                                //
34 //                                                                            //
35 // date: 27/04/2010                                                           //
36 // Authors: Magnus Mager, Stefan Rossegger, Jim Thomas                       //
37 //                                                                            //
38 // Example usage:                                                             //
39 //                                                                            //
40 //  AliMagF mag("mag","mag");                                                 //
41 //  AliTPCExBBShape exb;             // B field shape distortions             //
42 //  exb.SetBField(&mag);                                                      //
43 //                                                                            //
44 //  AliTPCExBTwist twist;            // ExB Twist distortions                 //
45 //  twist.SetXTwist(0.001);                                                   //
46 //                                                                            //
47 //   TObjArray cs;  cs.Add(&exb); cs.Add(&twist);                             //
48 //                                                                            //
49 //  AliTPCComposedCorrection cc;                                              //
50 //  cc.SetCorrections(&cs);                                                   //
51 //  cc.SetOmegaTauT1T2(wt,T1,T2);                                             //
52 //  cc.Print("DA");                                                           //               
53 //  cc.CreateHistoDRPhiinZR(0,100,100)->Draw("surf2");                        //
54 ////////////////////////////////////////////////////////////////////////////////
55
56
57 #include <TCollection.h>
58 #include <TTimeStamp.h>
59 #include <TIterator.h>
60 #include "AliLog.h"
61
62 #include "AliTPCComposedCorrection.h"
63
64
65 AliTPCComposedCorrection::AliTPCComposedCorrection() 
66   : AliTPCCorrection("composed_correction",
67                      "composition of corrections"),
68     fCorrections(0),
69     fMode(kParallel),
70     fWeights(0)  // weights of corrections
71 {
72   //
73   // default constructor
74   //
75 }
76
77 AliTPCComposedCorrection::AliTPCComposedCorrection(TCollection *corrections,
78                                                    AliTPCComposedCorrection::CompositionType mode)
79   : AliTPCCorrection("composed_correction",
80                      "composition of corrections"),
81     fCorrections(corrections),
82     fMode(mode),
83     fWeights(0) //weights of correction
84 {
85   //
86   // Constructor that defines the set of corrections, this one is composed of.
87   //
88 }
89
90 AliTPCComposedCorrection::~AliTPCComposedCorrection() {
91   // 
92   // destructor
93   //
94   if (!fCorrections) {
95     AliInfo("No Correction-models were set: can not delete them");
96   } else {
97     TIterator *i=fCorrections->MakeIterator();
98     AliTPCCorrection *c;
99     while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
100       delete c;
101     }
102     delete i;
103   }
104   if (fWeights) delete fWeights;
105 }
106
107
108 void AliTPCComposedCorrection::GetCorrection(const Float_t x[],const Short_t roc,Float_t dx[]) {
109   //
110   // This applies all correction and the specified manner (see general
111   // class description for details).
112   //
113
114   if (!fCorrections) {
115     AliInfo("No Corrections-models were set: can not calculate distortions");
116     return;
117   }
118   TIterator *i=fCorrections->MakeIterator();
119   AliTPCCorrection *c;
120   Int_t weightIndex=0;
121   switch (fMode) {
122   case kParallel:
123     Float_t dxi[3];
124     for (int j=0;j<3;++j) dx[j]=0.;
125     while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
126       c->GetCorrection(x,roc,dxi);
127       Double_t w=1;
128       if (fWeights) w=(*fWeights)[weightIndex++];
129       for (Int_t j=0;j<3;++j) dx[j]+=w*dxi[j];
130     }
131     break;
132   case kQueue:
133     Float_t xi[3];
134     for (Int_t j=0;j<3;++j) xi[j]=x[j];
135     while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
136       c->GetCorrection(xi,roc,dx);
137       Double_t w=1;
138       if (fWeights) w=(*fWeights)[weightIndex++];
139       for (Int_t j=0;j<3;++j) xi[j]+=w*dx[j];
140     }
141     for (Int_t j=0;j<3;++j) dx[j]=xi[j]-x[j];
142     break;
143   }
144   delete i;
145 }
146
147 void AliTPCComposedCorrection::GetDistortion(const Float_t x[],const Short_t roc,Float_t dx[]) {
148   //
149   // This applies all distortions and the specified manner (see general
150   // class descxiption for details).
151   //
152
153   if (!fCorrections) {
154     AliInfo("No Corrections-models were set: can not calculate distortions");
155     return;
156   }
157   TIterator *i=fCorrections->MakeReverseIterator();
158   AliTPCCorrection *c;
159   Int_t weightIndex=0;
160   switch (fMode) {
161   case kParallel:
162     Float_t dxi[3];
163     for (int j=0;j<3;++j) dx[j]=0.;
164     while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
165       c->GetDistortion(x,roc,dxi);
166       Double_t w=1;
167       if (fWeights) w=(*fWeights)[weightIndex++];
168       for (Int_t j=0;j<3;++j) dx[j]+=w*dxi[j];
169     }
170     break;
171   case kQueue:
172     Float_t xi[3];
173     for (Int_t j=0;j<3;++j) xi[j]=x[j];
174     while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
175       c->GetDistortion(xi,roc,dx);
176       Double_t w=1;
177       if (fWeights) w=(*fWeights)[weightIndex++];
178       for (Int_t j=0;j<3;++j) xi[j]+=w*dx[j];
179     }
180     for (Int_t j=0;j<3;++j) dx[j]=xi[j]-x[j];
181     break;
182   }
183   delete i;
184 }
185
186
187 void AliTPCComposedCorrection::Print(Option_t* option) const {
188   //
189   // Print function to check which correction classes are used 
190   // option=="d" prints details regarding the setted magnitude 
191   // option=="a" prints the C0 and C1 coefficents for calibration purposes
192   //
193
194   printf("Composed TPC spacepoint correction \"%s\" -- composed of:\n",GetTitle());
195   TString opt = option; opt.ToLower();
196   Int_t in=1;
197   if (!fCorrections) {
198     printf("   - composed correction is empty!\n");
199     return;
200   }
201   TIterator *i=fCorrections->MakeIterator();
202   AliTPCCorrection *c;
203   while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
204     if (opt.Contains("d")) {
205       printf("\n");
206       printf("%d. %s\t%s\n",in,c->GetTitle(), c->GetName());
207       c->Print(option);
208     } else {
209       printf("%d. %s\t%s\n",in,c->GetTitle(), c->GetName());
210     }
211     ++in;
212   }
213   if (in==1) printf("  Info: The correction compound is empty: No corrections set\n");
214   delete i;
215 }
216
217
218 void AliTPCComposedCorrection::Init() {
219   //
220   // Initialization funtion (not used at the moment)
221   //
222   if (!fCorrections) {
223     AliInfo("No Correction-models were set");
224     return;
225   }
226   TIterator *i=fCorrections->MakeIterator();
227   AliTPCCorrection *c;
228   while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) 
229     c->Init();
230   delete i;
231   
232 }
233
234 void AliTPCComposedCorrection::Update(const TTimeStamp &timeStamp) {
235   //
236   // Update function 
237   //
238   if (!fCorrections) {
239     AliInfo("No Correction-models were set");
240     return;
241   }
242
243   TIterator *i=fCorrections->MakeIterator();
244   AliTPCCorrection *c;
245   while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) 
246     c->Update(timeStamp);
247   delete i;
248  
249 }
250
251
252
253 void AliTPCComposedCorrection::SetOmegaTauT1T2(Float_t omegaTau,Float_t t1,Float_t t2) {
254   //
255   // Gives the possibility to set the OmegaTau plus Tensor corrections T1 and T2 (effective omega Tau)
256   // to each subcorrection (since they might become event specific due to changing drift velocity)
257   //
258   // The omegaTau comes idealy from the Database, since it is a function of drift velocity, B and E field 
259   // e.g. omegaTau  = -10.0 * Bz * vdrift / Ez ; // with Bz in kG and Ez in V/cm
260   //      omegaTau  = -0.325 for Bz=5kG, Ez=400V/cm and vdrift = 2.6cm/muSec
261   // The T1 and T2 tensors were measured in a dedicated calibration run
262   //
263   // Note: overwrites previously set values!
264   // 
265
266   if (!fCorrections) {
267     AliInfo("No Correction-models were set");
268     return;
269   }
270
271   TIterator *i=fCorrections->MakeIterator();
272   AliTPCCorrection *c;
273   while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
274     c->SetOmegaTauT1T2(omegaTau,t1,t2);
275   }
276   delete i;
277 }
278
279 ClassImp(AliTPCComposedCorrection)