]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/Base/AliTPCComposedCorrection.cxx
ATO-98 AddCorrectionCompact - to make corrections compact in memory + UnitTests...
[u/mrichter/AliRoot.git] / TPC / Base / AliTPCComposedCorrection.cxx
CommitLineData
0116859c 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. //
0f236b4e 31// 3. kQueueResidual: like kQueue with the exception that in case of //
32// a positive weight the 'Distortion' is called and in case of a negative //
33// weight the 'Correction' is called, where the absolute of the weight //
34// will be applied to the correction
0116859c 35// For the inverse of the correction this is taken into account by reversing //
36// the order the corrections are applied in the kQueue case (no issue for //
37// kParallel). //
38// //
39// date: 27/04/2010 //
40// Authors: Magnus Mager, Stefan Rossegger, Jim Thomas //
41// //
42// Example usage: //
43// //
44// AliMagF mag("mag","mag"); //
45// AliTPCExBBShape exb; // B field shape distortions //
46// exb.SetBField(&mag); //
47// //
48// AliTPCExBTwist twist; // ExB Twist distortions //
49// twist.SetXTwist(0.001); //
50// //
51// TObjArray cs; cs.Add(&exb); cs.Add(&twist); //
52// //
53// AliTPCComposedCorrection cc; //
54// cc.SetCorrections(&cs); //
55// cc.SetOmegaTauT1T2(wt,T1,T2); //
56// cc.Print("DA"); //
57// cc.CreateHistoDRPhiinZR(0,100,100)->Draw("surf2"); //
58////////////////////////////////////////////////////////////////////////////////
59
60
61#include <TCollection.h>
e527a1b9 62#include <TTimeStamp.h>
b1f0a2a5 63#include <TIterator.h>
0f236b4e 64#include <TMath.h>
c9cbd2f2 65#include "AliLog.h"
0116859c 66
67#include "AliTPCComposedCorrection.h"
68
69
70AliTPCComposedCorrection::AliTPCComposedCorrection()
71 : AliTPCCorrection("composed_correction",
72 "composition of corrections"),
73 fCorrections(0),
cfe2c39a 74 fMode(kParallel),
75 fWeights(0) // weights of corrections
0116859c 76{
77 //
78 // default constructor
79 //
80}
81
82AliTPCComposedCorrection::AliTPCComposedCorrection(TCollection *corrections,
83 AliTPCComposedCorrection::CompositionType mode)
84 : AliTPCCorrection("composed_correction",
85 "composition of corrections"),
86 fCorrections(corrections),
cfe2c39a 87 fMode(mode),
88 fWeights(0) //weights of correction
0116859c 89{
90 //
91 // Constructor that defines the set of corrections, this one is composed of.
92 //
93}
94
95AliTPCComposedCorrection::~AliTPCComposedCorrection() {
96 //
c9cbd2f2 97 // destructor
0116859c 98 //
c9cbd2f2 99 if (!fCorrections) {
100 AliInfo("No Correction-models were set: can not delete them");
101 } else {
102 TIterator *i=fCorrections->MakeIterator();
103 AliTPCCorrection *c;
104 while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
105 delete c;
106 }
107 delete i;
108 }
cfe2c39a 109 if (fWeights) delete fWeights;
0116859c 110}
111
69d03c4d 112
113Bool_t AliTPCComposedCorrection::AddCorrectionCompact(AliTPCCorrection* corr, Double_t weight){
114 //
115 // Add correction - better name needed (left/right) - for the moment I assumme they commute
116 // Why not to just use array of corrections - CPU consideration
117 // Assumptions:
118 // - origin of distortion/correction are additive
119 // - corrections/distortion are small and they commute
120 // - only correction ot the same type supported
121 const Int_t knCorr=100;
122 if (corr==NULL) {
123 AliError("Zerro pointer - correction");
124 return kFALSE;
125 }
126 if (!fCorrections) fCorrections= new TObjArray(knCorr);
127 // 1.) Case of Composed correction
128 AliTPCComposedCorrection * corrC = dynamic_cast<AliTPCComposedCorrection *>(corr);
129 if (corrC){
130 Int_t ncorrs= corrC->fCorrections->GetEntries();
131 Bool_t isOK=kTRUE;
132 for (Int_t icorr=0; icorr<ncorrs; icorr++){
133 isOK&=AddCorrectionCompact(corrC->GetSubCorrection(icorr),weight*(*((corrC->fWeights)))[icorr]);
134 }
135 return isOK;
136 }
137 // 2.) Find subcorrection of the same type
138 AliTPCCorrection * toAdd=0;
139 Int_t ncorr=fCorrections->GetEntries();
140 for (Int_t icorr=0; icorr<ncorr; icorr++){
141 if (GetSubCorrection(icorr)==NULL) continue;
142 if (GetSubCorrection(icorr)->IsA()==corr->IsA()) toAdd=GetSubCorrection(icorr);
143 }
144 // 3.) create of givent type if does not exist
145 if (toAdd==NULL){
146 toAdd= (AliTPCCorrection*)((corr->IsA())->New());
147 fCorrections->Add(toAdd);
148 }
149 // 4.) add to object of given type
150 return toAdd->AddCorrectionCompact(corr, weight);
151}
152
153
72bb0bb7 154AliTPCCorrection * AliTPCComposedCorrection::GetSubCorrection(Int_t ipos){
155 //
156 //
157 //
158 TObjArray *arr = (TObjArray*)fCorrections;
159 return (AliTPCCorrection *)arr->At(ipos);
160}
161
162AliTPCCorrection * AliTPCComposedCorrection::GetSubCorrection(const char *cname){
163 //
164 //
165 //
166 TCollection *arr = fCorrections;
167 return (AliTPCCorrection *)arr->FindObject(cname);
168}
169
170
0116859c 171
172void AliTPCComposedCorrection::GetCorrection(const Float_t x[],const Short_t roc,Float_t dx[]) {
173 //
174 // This applies all correction and the specified manner (see general
175 // class description for details).
176 //
c9cbd2f2 177
178 if (!fCorrections) {
179 AliInfo("No Corrections-models were set: can not calculate distortions");
180 return;
181 }
cfe2c39a 182 TIterator *i=fCorrections->MakeIterator();
0116859c 183 AliTPCCorrection *c;
cfe2c39a 184 Int_t weightIndex=0;
0116859c 185 switch (fMode) {
186 case kParallel:
187 Float_t dxi[3];
188 for (int j=0;j<3;++j) dx[j]=0.;
189 while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
190 c->GetCorrection(x,roc,dxi);
cfe2c39a 191 Double_t w=1;
192 if (fWeights) w=(*fWeights)[weightIndex++];
193 for (Int_t j=0;j<3;++j) dx[j]+=w*dxi[j];
0116859c 194 }
195 break;
196 case kQueue:
197 Float_t xi[3];
198 for (Int_t j=0;j<3;++j) xi[j]=x[j];
199 while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
200 c->GetCorrection(xi,roc,dx);
cfe2c39a 201 Double_t w=1;
202 if (fWeights) w=(*fWeights)[weightIndex++];
203 for (Int_t j=0;j<3;++j) xi[j]+=w*dx[j];
0116859c 204 }
205 for (Int_t j=0;j<3;++j) dx[j]=xi[j]-x[j];
206 break;
0f236b4e 207 case kQueueResidual:
208 //TODO: for the moment assume inverse of distortion
209 // check if this is what is desired
210 GetDistortion(x,roc,dx);
211 for (Int_t j=0;j<3;++j) dx[j]*=-1.;
212 break;
0116859c 213 }
214 delete i;
215}
216
217void AliTPCComposedCorrection::GetDistortion(const Float_t x[],const Short_t roc,Float_t dx[]) {
218 //
219 // This applies all distortions and the specified manner (see general
220 // class descxiption for details).
221 //
222
c9cbd2f2 223 if (!fCorrections) {
224 AliInfo("No Corrections-models were set: can not calculate distortions");
225 return;
226 }
0f236b4e 227
228 if (fMode==kQueueResidual && !fWeights) {
229 AliInfo("kQueueResidual mode was selected but no weights were given. Switching to kQueue instead.");
230 fMode=kQueue;
231 }
232
0116859c 233 TIterator *i=fCorrections->MakeReverseIterator();
234 AliTPCCorrection *c;
cfe2c39a 235 Int_t weightIndex=0;
0116859c 236 switch (fMode) {
237 case kParallel:
238 Float_t dxi[3];
239 for (int j=0;j<3;++j) dx[j]=0.;
240 while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
241 c->GetDistortion(x,roc,dxi);
cfe2c39a 242 Double_t w=1;
243 if (fWeights) w=(*fWeights)[weightIndex++];
244 for (Int_t j=0;j<3;++j) dx[j]+=w*dxi[j];
0116859c 245 }
246 break;
247 case kQueue:
248 Float_t xi[3];
249 for (Int_t j=0;j<3;++j) xi[j]=x[j];
250 while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
251 c->GetDistortion(xi,roc,dx);
cfe2c39a 252 Double_t w=1;
253 if (fWeights) w=(*fWeights)[weightIndex++];
254 for (Int_t j=0;j<3;++j) xi[j]+=w*dx[j];
0116859c 255 }
256 for (Int_t j=0;j<3;++j) dx[j]=xi[j]-x[j];
257 break;
0f236b4e 258 case kQueueResidual:
259 Float_t xi2[3];
260 for (Int_t j=0;j<3;++j) xi2[j]=x[j];
261 while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
262 Double_t w=(*fWeights)[weightIndex++];
263 if (w>0) c->GetDistortion(xi2,roc,dx);
264 else c->GetCorrection(xi2,roc,dx);
265 for (Int_t j=0;j<3;++j) xi2[j]+=TMath::Abs(w)*dx[j];
266 }
267 for (Int_t j=0;j<3;++j) dx[j]=xi2[j]-x[j];
268 break;
0116859c 269 }
270 delete i;
271}
272
273
274void AliTPCComposedCorrection::Print(Option_t* option) const {
275 //
276 // Print function to check which correction classes are used
277 // option=="d" prints details regarding the setted magnitude
278 // option=="a" prints the C0 and C1 coefficents for calibration purposes
279 //
280
281 printf("Composed TPC spacepoint correction \"%s\" -- composed of:\n",GetTitle());
282 TString opt = option; opt.ToLower();
283 Int_t in=1;
c9cbd2f2 284 if (!fCorrections) {
285 printf(" - composed correction is empty!\n");
286 return;
287 }
0116859c 288 TIterator *i=fCorrections->MakeIterator();
289 AliTPCCorrection *c;
290 while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
291 if (opt.Contains("d")) {
0b736a46 292 printf("\n");
293 printf("%d. %s\t%s\n",in,c->GetTitle(), c->GetName());
0116859c 294 c->Print(option);
295 } else {
0b736a46 296 printf("%d. %s\t%s\n",in,c->GetTitle(), c->GetName());
0116859c 297 }
298 ++in;
299 }
e527a1b9 300 if (in==1) printf(" Info: The correction compound is empty: No corrections set\n");
0116859c 301 delete i;
302}
303
304
e527a1b9 305void AliTPCComposedCorrection::Init() {
306 //
307 // Initialization funtion (not used at the moment)
308 //
c9cbd2f2 309 if (!fCorrections) {
310 AliInfo("No Correction-models were set");
311 return;
312 }
e527a1b9 313 TIterator *i=fCorrections->MakeIterator();
314 AliTPCCorrection *c;
315 while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next())))
316 c->Init();
317 delete i;
318
319}
320
321void AliTPCComposedCorrection::Update(const TTimeStamp &timeStamp) {
322 //
323 // Update function
324 //
c9cbd2f2 325 if (!fCorrections) {
326 AliInfo("No Correction-models were set");
327 return;
328 }
e527a1b9 329
330 TIterator *i=fCorrections->MakeIterator();
331 AliTPCCorrection *c;
332 while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next())))
333 c->Update(timeStamp);
334 delete i;
335
336}
337
338
339
0116859c 340void AliTPCComposedCorrection::SetOmegaTauT1T2(Float_t omegaTau,Float_t t1,Float_t t2) {
341 //
342 // Gives the possibility to set the OmegaTau plus Tensor corrections T1 and T2 (effective omega Tau)
343 // to each subcorrection (since they might become event specific due to changing drift velocity)
344 //
345 // The omegaTau comes idealy from the Database, since it is a function of drift velocity, B and E field
346 // e.g. omegaTau = -10.0 * Bz * vdrift / Ez ; // with Bz in kG and Ez in V/cm
347 // omegaTau = -0.325 for Bz=5kG, Ez=400V/cm and vdrift = 2.6cm/muSec
348 // The T1 and T2 tensors were measured in a dedicated calibration run
349 //
350 // Note: overwrites previously set values!
351 //
352
c9cbd2f2 353 if (!fCorrections) {
354 AliInfo("No Correction-models were set");
355 return;
356 }
357
0116859c 358 TIterator *i=fCorrections->MakeIterator();
359 AliTPCCorrection *c;
360 while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
361 c->SetOmegaTauT1T2(omegaTau,t1,t2);
362 }
363 delete i;
364}
365
366ClassImp(AliTPCComposedCorrection)