AliRoot Core  3dc7879 (3dc7879)
AliTPCComposedCorrection.cxx
Go to the documentation of this file.
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 
59 
60 
61 #include <TCollection.h>
62 #include <TTimeStamp.h>
63 #include <TIterator.h>
64 #include <TMath.h>
65 #include "AliLog.h"
66 
68 
69 
71  : AliTPCCorrection("composed_correction",
72  "composition of corrections"),
73  fCorrections(0),
74  fMode(kParallel),
75  fWeights(0) // weights of corrections
76 {
78 
79 }
80 
83  : AliTPCCorrection("composed_correction",
84  "composition of corrections"),
85  fCorrections(corrections),
86  fMode(mode),
87  fWeights(0) //weights of correction
88 {
90 
91 }
92 
95 
96  if (!fCorrections) {
97  AliInfo("No Correction-models were set: can not delete them");
98  } else {
99  TIterator *i=fCorrections->MakeIterator();
100  AliTPCCorrection *c;
101  while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
102  delete c;
103  }
104  delete i;
105  }
106  if (fWeights) delete fWeights;
107 }
108 
109 
117 
118  const Int_t knCorr=100;
119  if (corr==NULL) {
120  AliError("Zerro pointer - correction");
121  return kFALSE;
122  }
123  if (!fCorrections) fCorrections= new TObjArray(knCorr);
124  // 1.) Case of Composed correction
125  AliTPCComposedCorrection * corrC = dynamic_cast<AliTPCComposedCorrection *>(corr);
126  if (corrC){
127  Int_t ncorrs= corrC->fCorrections->GetEntries();
128  Bool_t isOK=kTRUE;
129  for (Int_t icorr=0; icorr<ncorrs; icorr++){
130  Double_t weight0=((corrC->fWeights)==NULL)?1:(*(corrC->fWeights))[icorr];
131  isOK&=AddCorrectionCompact(corrC->GetSubCorrection(icorr),weight*weight0);
132  }
133  return isOK;
134  }
135  // 2.) Find subcorrection of the same type
136  AliTPCCorrection * toAdd=0;
137  Int_t ncorr=fCorrections->GetEntries();
138  for (Int_t icorr=0; icorr<ncorr; icorr++){
139  if (GetSubCorrection(icorr)==NULL) continue;
140  if (GetSubCorrection(icorr)->IsA()==corr->IsA()) toAdd=GetSubCorrection(icorr);
141  }
142  // 3.) create of givent type if does not exist
143  if (toAdd==NULL){
144  toAdd= (AliTPCCorrection*)((corr->IsA())->New());
145  fCorrections->Add(toAdd);
146  }
147  // 4.) add to object of given type
148  return toAdd->AddCorrectionCompact(corr, weight);
149 }
150 
151 
154 
156  return (AliTPCCorrection *)arr->At(ipos);
157 }
158 
161 
162  TCollection *arr = fCorrections;
163  return (AliTPCCorrection *)arr->FindObject(cname);
164 }
165 
166 
167 
168 void AliTPCComposedCorrection::GetCorrection(const Float_t x[],const Short_t roc,Float_t dx[]) {
171 
172  if (!fCorrections) {
173  AliInfo("No Corrections-models were set: can not calculate distortions");
174  return;
175  }
176  TIterator *i=fCorrections->MakeIterator();
177  AliTPCCorrection *c;
178  Int_t weightIndex=0;
179  switch (fMode) {
180  case kParallel:
181  Float_t dxi[3];
182  for (int j=0;j<3;++j) dx[j]=0.;
183  while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
184  c->GetCorrection(x,roc,dxi);
185  Double_t w=1;
186  if (fWeights) w=(*fWeights)[weightIndex++];
187  for (Int_t j=0;j<3;++j) dx[j]+=w*dxi[j];
188  }
189  break;
190  case kQueue:
191  Float_t xi[3];
192  for (Int_t j=0;j<3;++j) xi[j]=x[j];
193  while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
194  c->GetCorrection(xi,roc,dx);
195  Double_t w=1;
196  if (fWeights) w=(*fWeights)[weightIndex++];
197  for (Int_t j=0;j<3;++j) xi[j]+=w*dx[j];
198  }
199  for (Int_t j=0;j<3;++j) dx[j]=xi[j]-x[j];
200  break;
201  case kQueueResidual:
202  //TODO: for the moment assume inverse of distortion
203  // check if this is what is desired
204  GetDistortion(x,roc,dx);
205  for (Int_t j=0;j<3;++j) dx[j]*=-1.;
206  break;
207  }
208  delete i;
209 }
210 
211 void AliTPCComposedCorrection::GetDistortion(const Float_t x[],const Short_t roc,Float_t dx[]) {
214 
215  if (!fCorrections) {
216  AliInfo("No Corrections-models were set: can not calculate distortions");
217  return;
218  }
219 
220  if (fMode==kQueueResidual && !fWeights) {
221  AliInfo("kQueueResidual mode was selected but no weights were given. Switching to kQueue instead.");
222  fMode=kQueue;
223  }
224 
225  TIterator *i=fCorrections->MakeReverseIterator();
226  AliTPCCorrection *c;
227  Int_t weightIndex=0;
228  switch (fMode) {
229  case kParallel:
230  Float_t dxi[3];
231  for (int j=0;j<3;++j) dx[j]=0.;
232  while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
233  c->GetDistortion(x,roc,dxi);
234  Double_t w=1;
235  if (fWeights) w=(*fWeights)[weightIndex++];
236  for (Int_t j=0;j<3;++j) dx[j]+=w*dxi[j];
237  }
238  break;
239  case kQueue:
240  Float_t xi[3];
241  for (Int_t j=0;j<3;++j) xi[j]=x[j];
242  while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
243  c->GetDistortion(xi,roc,dx);
244  Double_t w=1;
245  if (fWeights) w=(*fWeights)[weightIndex++];
246  for (Int_t j=0;j<3;++j) xi[j]+=w*dx[j];
247  }
248  for (Int_t j=0;j<3;++j) dx[j]=xi[j]-x[j];
249  break;
250  case kQueueResidual:
251  Float_t xi2[3];
252  for (Int_t j=0;j<3;++j) xi2[j]=x[j];
253  while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
254  Double_t w=(*fWeights)[weightIndex++];
255  if (w>0) c->GetDistortion(xi2,roc,dx);
256  else c->GetCorrection(xi2,roc,dx);
257  for (Int_t j=0;j<3;++j) xi2[j]+=TMath::Abs(w)*dx[j];
258  }
259  for (Int_t j=0;j<3;++j) dx[j]=xi2[j]-x[j];
260  break;
261  }
262  delete i;
263 }
264 
265 
266 void AliTPCComposedCorrection::Print(Option_t* option) const {
270 
271  printf("Composed TPC spacepoint correction \"%s\" -- composed of:\n",GetTitle());
272  TString opt = option; opt.ToLower();
273  Int_t in=1;
274  if (!fCorrections) {
275  printf(" - composed correction is empty!\n");
276  return;
277  }
278  TIterator *i=fCorrections->MakeIterator();
279  AliTPCCorrection *c;
280  while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
281  if (opt.Contains("d")) {
282  printf("\n");
283  printf("%d. %s\t%s\n",in,c->GetTitle(), c->GetName());
284  c->Print(option);
285  } else {
286  printf("%d. %s\t%s\n",in,c->GetTitle(), c->GetName());
287  }
288  ++in;
289  }
290  if (in==1) printf(" Info: The correction compound is empty: No corrections set\n");
291  delete i;
292 }
293 
294 
297 
298  if (!fCorrections) {
299  AliInfo("No Correction-models were set");
300  return;
301  }
302  TIterator *i=fCorrections->MakeIterator();
303  AliTPCCorrection *c;
304  while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next())))
305  c->Init();
306  delete i;
307 
308 }
309 
310 void AliTPCComposedCorrection::Update(const TTimeStamp &timeStamp) {
312 
313  if (!fCorrections) {
314  AliInfo("No Correction-models were set");
315  return;
316  }
317 
318  TIterator *i=fCorrections->MakeIterator();
319  AliTPCCorrection *c;
320  while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next())))
321  c->Update(timeStamp);
322  delete i;
323 
324 }
325 
326 
327 
328 void AliTPCComposedCorrection::SetOmegaTauT1T2(Float_t omegaTau,Float_t t1,Float_t t2) {
338 
339  if (!fCorrections) {
340  AliInfo("No Correction-models were set");
341  return;
342  }
343 
344  TIterator *i=fCorrections->MakeIterator();
345  AliTPCCorrection *c;
346  while (0!=(c=dynamic_cast<AliTPCCorrection*>(i->Next()))) {
347  c->SetOmegaTauT1T2(omegaTau,t1,t2);
348  }
349  delete i;
350 }
351 
353 ClassImp(AliTPCComposedCorrection)
virtual Bool_t AddCorrectionCompact(AliTPCCorrection *corr, Double_t weight)
virtual void GetCorrection(const Float_t x[], const Short_t roc, Float_t dx[])
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
TFile * fCorrections
virtual void Print(Option_t *option="") const
#define TObjArray
virtual void SetOmegaTauT1T2(Float_t omegaTau, Float_t t1, Float_t t2)
void SetOmegaTauT1T2(Float_t omegaTau, Float_t t1, Float_t t2)
virtual Bool_t AddCorrectionCompact(AliTPCCorrection *corr, Double_t weight)
virtual void GetDistortion(const Float_t x[], Short_t roc, Float_t dx[])
AliTPCCorrection class.
AliTPCComposedCorrection class.
#define AliInfo(message)
Definition: AliLog.h:484
virtual void GetDistortion(const Float_t x[], const Short_t roc, Float_t dx[])
virtual void Update(const TTimeStamp &timeStamp)
virtual AliTPCCorrection * GetSubCorrection(Int_t ipos)
CompositionType fMode
The way to apply the corrections (see general class documentation)
TCollection * fCorrections
The corrections this one is composed of.
virtual void GetCorrection(const Float_t x[], Short_t roc, Float_t dx[])
TVectorD * fWeights
optional vector with weights - used for fit benchmarking
#define AliError(message)
Definition: AliLog.h:591
virtual void Update(const TTimeStamp &timeStamp)
virtual void Init()
virtual void Print(Option_t *option="") const