1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 // Data container for relative ITS-TPC alignment analysis
19 // Holds an array of AliRelAlignerKalman objects
20 // and takes care of merging when processing data in parallel
22 // Origin: Mikolaj Krzewicki, Nikhef, Mikolaj.Krzewicki@cern.ch
24 //////////////////////////////////////////////////////////////////////////////
27 #include <TGraphErrors.h>
31 #include <TObjArray.h>
32 #include <TCollection.h>
33 #include <AliESDEvent.h>
34 #include <AliRelAlignerKalman.h>
35 #include "AliRelAlignerKalmanArray.h"
37 ClassImp(AliRelAlignerKalmanArray)
39 //______________________________________________________________________________
40 AliRelAlignerKalmanArray::AliRelAlignerKalmanArray():
41 TNamed("alignerArray","array of aligners"),
45 fOutRejSigmaOnMerge(10.),
46 fOutRejSigmaOnSmooth(1.),
53 //______________________________________________________________________________
54 AliRelAlignerKalmanArray::AliRelAlignerKalmanArray(Int_t t0, Int_t tend, Int_t slotwidth):
55 TNamed("alignerArray","array of aligners"),
57 fTimebinWidth(slotwidth),
59 fOutRejSigmaOnMerge(10.),
60 fOutRejSigmaOnSmooth(1.),
65 if (slotwidth==0) fSize = 1;
66 else fSize = (tend-t0)/slotwidth;
67 fPArray = new AliRelAlignerKalman* [fSize];
68 if (fPArray) for (Int_t i=0;i<fSize;i++){fPArray[i]=NULL;}//fill with zeros
72 //______________________________________________________________________________
73 AliRelAlignerKalmanArray::AliRelAlignerKalmanArray( const AliRelAlignerKalmanArray& in):
74 TNamed(in.GetName(), in.GetTitle()),
76 fTimebinWidth(in.fTimebinWidth),
78 fOutRejSigmaOnMerge(in.fOutRejSigmaOnMerge),
79 fOutRejSigmaOnSmooth(in.fOutRejSigmaOnSmooth),
80 fAlignerTemplate(in.fAlignerTemplate),
84 fPArray = new AliRelAlignerKalman* [fSize];
85 if (!fPArray) {fSize=0;return;} //if fail
86 for (Int_t i=0;i<fSize;i++)
88 if (in.fPArray[i]) fPArray[i]=new AliRelAlignerKalman(*(in.fPArray[i]));
93 //______________________________________________________________________________
94 AliRelAlignerKalmanArray::~AliRelAlignerKalmanArray()
101 //______________________________________________________________________________
102 void AliRelAlignerKalmanArray::SetupArray(Int_t t0, Int_t tend, Int_t slotwidth)
104 //setup array - clears old content
107 fTimebinWidth=slotwidth;
109 if (slotwidth==0) tmpsize = 1;
110 else tmpsize = (tend-t0)/slotwidth;
114 fPArray=new AliRelAlignerKalman* [tmpsize];
115 if (fPArray) fSize=tmpsize;
118 for (Int_t i=0;i<fSize;i++){fPArray[i]=NULL;}//fill with zeros
121 //______________________________________________________________________________
122 AliRelAlignerKalman* AliRelAlignerKalmanArray::GetAlignerTemplate()
124 //get aligner template
125 return &fAlignerTemplate;
128 //______________________________________________________________________________
129 Long64_t AliRelAlignerKalmanArray::Merge( TCollection* list )
131 //Merge all the arrays
132 //tlihe merge is vertical, meaning matching entries in tree are merged
134 AliRelAlignerKalmanArray *arrayFromList;
137 while ( (arrayFromList = dynamic_cast<AliRelAlignerKalmanArray*>(next())) )
139 if (fT0 != arrayFromList->fT0) continue;
140 if (fTimebinWidth != arrayFromList->fTimebinWidth) continue;
141 if (fSize != arrayFromList->fSize) continue;
143 for (Int_t i=0; i<GetSize(); i++)
145 AliRelAlignerKalman* a1 = fPArray[i];
146 AliRelAlignerKalman* a2 = arrayFromList->fPArray[i];
149 a1->SetRejectOutliers(kFALSE);
150 a1->SetOutRejSigma(fOutRejSigmaOnMerge); a1->Merge(a2);
153 if (!a1 && a2) fPArray[i] = new AliRelAlignerKalman(*a2);
159 //______________________________________________________________________________
160 Int_t AliRelAlignerKalmanArray::Timebin( UInt_t timestamp ) const
162 //calculate binnumber for given timestamp
163 if (fTimebinWidth==0) return 0;
164 Int_t slot = (timestamp-fT0)/fTimebinWidth; //it's all integers!
168 //______________________________________________________________________________
169 AliRelAlignerKalman* AliRelAlignerKalmanArray::GetAligner(UInt_t ts)
171 //get the aligner for specified timestamp
172 Int_t tb = Timebin(ts);
173 if (tb<0) return NULL;
174 if (tb>=fSize) return NULL;
175 if (!fPArray) return NULL;
178 fPArray[tb] = new AliRelAlignerKalman( fAlignerTemplate );
179 fPArray[tb]->SetTimeStamp(fT0+tb*fTimebinWidth);
184 //______________________________________________________________________________
185 AliRelAlignerKalman* AliRelAlignerKalmanArray::GetAligner(AliESDEvent* event)
187 //get the aligner for this event and set relevant info
188 AliRelAlignerKalman* a = GetAligner(event->GetTimeStamp());
189 if (a) a->SetRunNumber(event->GetRunNumber());
190 if (a) a->SetMagField(event->GetMagneticField());
194 //______________________________________________________________________________
195 AliRelAlignerKalmanArray& AliRelAlignerKalmanArray::operator=(const AliRelAlignerKalmanArray& in)
197 //assignment operator
200 //if sizes different, delete curent and make a new one with new size
203 fPArray = new AliRelAlignerKalman* [in.fSize];
206 fOutRejSigmaOnMerge=in.fOutRejSigmaOnMerge;
207 fOutRejSigmaOnSmooth=in.fOutRejSigmaOnSmooth;
209 if (!fPArray) fSize=0;
210 else fSize = in.fSize;
211 fTimebinWidth = in.fTimebinWidth;
213 for (Int_t i=0;i<fSize;i++)
215 if (in.fPArray[i]) fPArray[i] = new AliRelAlignerKalman(*(in.fPArray[i]));
216 else fPArray[i]=NULL;
221 //______________________________________________________________________________
222 void AliRelAlignerKalmanArray::ClearContents()
224 //clear contents of array
225 for (Int_t i=0;i<fSize;i++)
227 if (fPArray[i]) delete fPArray[i];
231 //______________________________________________________________________________
232 AliRelAlignerKalman* AliRelAlignerKalmanArray::At( Int_t i ) const
234 //mimic TObjArray::At( Int_t i )
235 if (i>=fSize) {printf("AliRelAlignerKalmanArray::At index %i out of bounds, size=%i\n",i,fSize); return NULL;}
236 if (i<0) return NULL;
240 //______________________________________________________________________________
241 AliRelAlignerKalman* AliRelAlignerKalmanArray::operator[](Int_t i) const
243 //mimic TObjArray::operator[](Int_t)
244 if (i>=fSize) {printf("AliRelAlignerKalmanArray::operator[] index %i out of bounds, size=%i\n",i,fSize); return NULL;}
245 if (i<0) return NULL;
249 //______________________________________________________________________________
250 AliRelAlignerKalman*& AliRelAlignerKalmanArray::operator[](Int_t i)
252 //mimic TObjArray::operator[](Int_t) can be used as lvalue
253 if (i>=fSize||i<0) {Error("operator[]", "index %i out of bounds, size=%i\n",i,fSize); return fPArray[0];}
257 //______________________________________________________________________________
258 AliRelAlignerKalman* AliRelAlignerKalmanArray::Last() const
260 //return aligner in last filled slot
261 if (fSize==0) return NULL;
262 return fPArray[fSize-1];
265 //______________________________________________________________________________
266 void AliRelAlignerKalmanArray::Print(Option_t* option) const
269 TString optionStr(option);
270 printf( "%s: t0: %i, tend: %i, width: %i, size: %i, entries: %i\n",
272 fT0, (fT0+(fSize)*fTimebinWidth), fTimebinWidth,
273 fSize, GetEntries() );
274 if (optionStr.Contains("a"))
275 for (Int_t i=0; i<fSize; i++)
277 AliRelAlignerKalman* al = fPArray[i];
283 //______________________________________________________________________________
284 Int_t AliRelAlignerKalmanArray::GetEntries() const
286 //get number of filled slots
287 if (!fPArray) return 0;
289 for (Int_t i=0; i<fSize; i++)
291 if (fPArray[i]) entries++;
296 //______________________________________________________________________________
297 void AliRelAlignerKalmanArray::FillTree( TTree* tree ) const
299 AliRelAlignerKalman* al = NULL;
300 tree->Branch("aligner","AliRelAlignerKalman",&al);
301 //fill a tree with filled slots
302 for (Int_t i=0; i<fSize; i++)
305 if (al) tree->Fill();
309 //______________________________________________________________________________
310 TGraphErrors* AliRelAlignerKalmanArray::MakeGraph(Int_t iparam) const
312 //return a graph for the iparam-th parameter
313 if (iparam>8 || iparam<0)
315 printf("wrong parameter number. must be from 0-8");
319 TVectorD vx(GetEntries());
320 TVectorD vy(GetEntries());
321 TVectorD vex(GetEntries());
322 TVectorD vey(GetEntries());
324 for (Int_t i=0; i<fSize; i++)
326 AliRelAlignerKalman* al = fPArray[i];
328 vx(entry) = al->GetTimeStamp();
329 vy(entry) = al->GetStateArr()[iparam];
330 TMatrixDSym* cm = al->GetStateCov();
331 vey(entry) = TMath::Sqrt((*cm)(iparam,iparam));
335 TGraphErrors* graph = new TGraphErrors(vx,vy,vex,vey);
341 graphtitle="rotation \\psi";
342 graphtitley="\\psi [rad]";
345 graphtitle="rotation \\theta";
346 graphtitley="\\theta [rad]";
349 graphtitle="rotation \\phi";
350 graphtitley="\\phi [rad]";
353 graphtitle="shift x";
354 graphtitley="x [cm]";
357 graphtitle="shift y";
358 graphtitley="y [cm]";
361 graphtitle="shift z";
362 graphtitley="z [cm]";
365 graphtitle="TPC vd correction";
366 graphtitley="correction factor []";
369 graphtitle="TPC t0 correction";
370 graphtitley="t0 correction [\\micros]";
373 graphtitle="TPC dv/dy";
374 graphtitley="dv/dy [cm/\\micros/m]";
377 graph->SetTitle(graphtitle);
378 TAxis* xas = graph->GetXaxis();
379 TAxis* yas = graph->GetYaxis();
380 xas->SetTitle("time");
381 xas->SetTimeDisplay(1);
382 yas->SetTitle(graphtitley);
386 //______________________________________________________________________________
387 AliRelAlignerKalmanArray* AliRelAlignerKalmanArray::MakeSmoothArray() const
389 //return a smoothed version of the data
390 AliRelAlignerKalmanArray* outputarr = new AliRelAlignerKalmanArray(fT0,
391 fT0+fSize*fTimebinWidth,fTimebinWidth);
393 AliRelAlignerKalman* tmpaligner = outputarr->GetAlignerTemplate();
394 tmpaligner->SetOutRejSigma(fOutRejSigmaOnSmooth);
395 //copy the first filled slot
397 while (!fPArray[n]) {n++;}
398 if (n==fSize) return NULL;
399 *tmpaligner = *fPArray[n];
400 if (fPArray[n]->GetNUpdates()>10)
401 (*outputarr)[n] = new AliRelAlignerKalman(*(fPArray[n]));
402 //for the rest of slots use merge
403 for (Int_t i=n+1;i<fSize;i++)
405 if (!fPArray[i]) continue;
406 PropagateToTime(tmpaligner, fPArray[i]->GetTimeStamp());
407 if (tmpaligner->Merge(fPArray[i]))
408 (*outputarr)[i] = new AliRelAlignerKalman(*tmpaligner);
410 (*outputarr)[i] = new AliRelAlignerKalman(*(fPArray[i]));
413 tmpaligner->Reset(); //clean up
418 //______________________________________________________________________________
419 void AliRelAlignerKalmanArray::PropagateToTime(AliRelAlignerKalman* al, UInt_t timestamp ) const
421 //propagate an aligner in time
422 TMatrixDSym* cov = al->GetStateCov();
423 TMatrixDSym corr(TMatrixDSym::kZero,*cov);
424 UInt_t dt = (timestamp>al->GetTimeStamp())?
425 timestamp-al->GetTimeStamp():al->GetTimeStamp()-timestamp;
426 //the propagation matrix
427 //to be added to the covariance matrix of kalman filter
428 corr(6,6) = dt*1e-8; //vdrift