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"
39 ClassImp(AliRelAlignerKalmanArray)
41 //______________________________________________________________________________
42 AliRelAlignerKalmanArray::AliRelAlignerKalmanArray():
43 TNamed("alignerArray","array of aligners"),
47 fOutRejSigmaOnMerge(10.),
48 fOutRejSigmaOnSmooth(1.),
56 //______________________________________________________________________________
57 AliRelAlignerKalmanArray::AliRelAlignerKalmanArray(Int_t t0, Int_t tend, Int_t slotwidth):
58 TNamed("alignerArray","array of aligners"),
60 fTimebinWidth(slotwidth),
62 fOutRejSigmaOnMerge(10.),
63 fOutRejSigmaOnSmooth(1.),
66 fListOfGraphs(new TList)
69 if (slotwidth==0) fSize = 1;
70 else fSize = (tend-t0)/slotwidth;
71 fPArray = new AliRelAlignerKalman* [fSize];
72 if (fPArray) for (Int_t i=0;i<fSize;i++){fPArray[i]=NULL;}//fill with zeros
74 fListOfGraphs->SetName("graphs");
75 fListOfGraphs->SetOwner(kTRUE);
78 //______________________________________________________________________________
79 AliRelAlignerKalmanArray::AliRelAlignerKalmanArray( const AliRelAlignerKalmanArray& in):
80 TNamed(in.GetName(), in.GetTitle()),
82 fTimebinWidth(in.fTimebinWidth),
84 fOutRejSigmaOnMerge(in.fOutRejSigmaOnMerge),
85 fOutRejSigmaOnSmooth(in.fOutRejSigmaOnSmooth),
86 fAlignerTemplate(in.fAlignerTemplate),
88 fListOfGraphs(new TList)
91 fPArray = new AliRelAlignerKalman* [fSize];
92 if (!fPArray) {fSize=0;return;} //if fail
93 for (Int_t i=0;i<fSize;i++)
95 if (in.fPArray[i]) fPArray[i]=new AliRelAlignerKalman(*(in.fPArray[i]));
98 fListOfGraphs->SetName("graphs");
99 fListOfGraphs->SetOwner(kTRUE);
102 //______________________________________________________________________________
103 AliRelAlignerKalmanArray::~AliRelAlignerKalmanArray()
108 delete fListOfGraphs;
111 //______________________________________________________________________________
112 void AliRelAlignerKalmanArray::SetupArray(Int_t t0, Int_t tend, Int_t slotwidth)
114 //setup array - clears old content
117 fTimebinWidth=slotwidth;
119 if (slotwidth==0) tmpsize = 1;
120 else tmpsize = (tend-t0)/slotwidth;
124 fPArray=new AliRelAlignerKalman* [tmpsize];
125 if (fPArray) fSize=tmpsize;
128 for (Int_t i=0;i<fSize;i++){fPArray[i]=NULL;}//fill with zeros
131 //______________________________________________________________________________
132 AliRelAlignerKalman* AliRelAlignerKalmanArray::GetAlignerTemplate()
134 //get aligner template
135 return &fAlignerTemplate;
138 //______________________________________________________________________________
139 Long64_t AliRelAlignerKalmanArray::Merge( TCollection* list )
141 //Merge all the arrays
142 //tlihe merge is vertical, meaning matching entries in tree are merged
144 AliRelAlignerKalmanArray *arrayFromList;
147 while ( (arrayFromList = dynamic_cast<AliRelAlignerKalmanArray*>(next())) )
149 if (fT0 != arrayFromList->fT0) continue;
150 if (fTimebinWidth != arrayFromList->fTimebinWidth) continue;
151 if (fSize != arrayFromList->fSize) continue;
153 for (Int_t i=0; i<GetSize(); i++)
155 AliRelAlignerKalman* a1 = fPArray[i];
156 AliRelAlignerKalman* a2 = arrayFromList->fPArray[i];
159 a1->SetRejectOutliers(kFALSE);
160 a1->SetOutRejSigma(fOutRejSigmaOnMerge); a1->Merge(a2);
163 if (!a1 && a2) fPArray[i] = new AliRelAlignerKalman(*a2);
166 fListOfGraphs->Delete();
170 //______________________________________________________________________________
171 Int_t AliRelAlignerKalmanArray::Timebin( UInt_t timestamp ) const
173 //calculate binnumber for given timestamp
174 if (fTimebinWidth==0) return 0;
175 Int_t slot = (timestamp-fT0)/fTimebinWidth; //it's all integers!
179 //______________________________________________________________________________
180 AliRelAlignerKalman* AliRelAlignerKalmanArray::GetAligner(UInt_t ts)
182 //get the aligner for specified timestamp
183 Int_t tb = Timebin(ts);
184 if (tb<0) return NULL;
185 if (tb>=fSize) return NULL;
186 if (!fPArray) return NULL;
189 fPArray[tb] = new AliRelAlignerKalman( fAlignerTemplate );
190 fPArray[tb]->SetTimeStamp(fT0+tb*fTimebinWidth);
195 //______________________________________________________________________________
196 AliRelAlignerKalman* AliRelAlignerKalmanArray::GetAligner(AliESDEvent* event)
198 //get the aligner for this event and set relevant info
199 AliRelAlignerKalman* a = GetAligner(event->GetTimeStamp());
200 if (a) a->SetRunNumber(event->GetRunNumber());
201 if (a) a->SetMagField(event->GetMagneticField());
205 //______________________________________________________________________________
206 AliRelAlignerKalmanArray& AliRelAlignerKalmanArray::operator=(const AliRelAlignerKalmanArray& in)
208 //assignment operator
211 //if sizes different, delete curent and make a new one with new size
214 fPArray = new AliRelAlignerKalman* [in.fSize];
217 fOutRejSigmaOnMerge=in.fOutRejSigmaOnMerge;
218 fOutRejSigmaOnSmooth=in.fOutRejSigmaOnSmooth;
220 if (!fPArray) fSize=0;
221 else fSize = in.fSize;
222 fTimebinWidth = in.fTimebinWidth;
224 for (Int_t i=0;i<fSize;i++)
226 if (in.fPArray[i]) fPArray[i] = new AliRelAlignerKalman(*(in.fPArray[i]));
227 else fPArray[i]=NULL;
232 //______________________________________________________________________________
233 void AliRelAlignerKalmanArray::ClearContents()
235 //clear contents of array
236 for (Int_t i=0;i<fSize;i++)
238 if (fPArray[i]) delete fPArray[i];
242 //______________________________________________________________________________
243 AliRelAlignerKalman* AliRelAlignerKalmanArray::At( Int_t i ) const
245 //mimic TObjArray::At( Int_t i )
246 if (i>=fSize) {printf("AliRelAlignerKalmanArray::At index %i out of bounds, size=%i\n",i,fSize); return NULL;}
247 if (i<0) return NULL;
251 //______________________________________________________________________________
252 AliRelAlignerKalman* AliRelAlignerKalmanArray::operator[](Int_t i) const
254 //mimic TObjArray::operator[](Int_t)
255 if (i>=fSize) {printf("AliRelAlignerKalmanArray::operator[] index %i out of bounds, size=%i\n",i,fSize); return NULL;}
256 if (i<0) return NULL;
260 //______________________________________________________________________________
261 AliRelAlignerKalman*& AliRelAlignerKalmanArray::operator[](Int_t i)
263 //mimic TObjArray::operator[](Int_t) can be used as lvalue
264 if (i>=fSize||i<0) {Error("operator[]", "index %i out of bounds, size=%i\n",i,fSize); return fPArray[0];}
268 //______________________________________________________________________________
269 AliRelAlignerKalman* AliRelAlignerKalmanArray::Last() const
271 //return aligner in last filled slot
272 if (fSize==0) return NULL;
273 return fPArray[fSize-1];
276 //______________________________________________________________________________
277 void AliRelAlignerKalmanArray::Print(Option_t* option) const
280 TString optionStr(option);
281 printf( "%s: t0: %i, tend: %i, width: %i, size: %i, entries: %i\n",
283 fT0, (fT0+(fSize)*fTimebinWidth), fTimebinWidth,
284 fSize, GetEntries() );
285 if (optionStr.Contains("a"))
286 for (Int_t i=0; i<fSize; i++)
288 AliRelAlignerKalman* al = fPArray[i];
294 //______________________________________________________________________________
295 Int_t AliRelAlignerKalmanArray::GetEntries() const
297 //get number of filled slots
298 if (!fPArray) return 0;
300 for (Int_t i=0; i<fSize; i++)
302 if (fPArray[i]) entries++;
307 //______________________________________________________________________________
308 void AliRelAlignerKalmanArray::FillTree( TTree* tree ) const
310 AliRelAlignerKalman* al = NULL;
311 tree->Branch("aligner","AliRelAlignerKalman",&al);
312 //fill a tree with filled slots
313 for (Int_t i=0; i<fSize; i++)
316 if (al) tree->Fill();
320 //______________________________________________________________________________
321 TGraphErrors* AliRelAlignerKalmanArray::MakeGraph(Int_t iparam) const
323 //return a graph for the iparam-th parameter
324 if (iparam>8 || iparam<0)
326 printf("wrong parameter number. must be from 0-8");
330 Int_t n=GetEntries();
336 for (Int_t i=0; i<fSize; i++)
338 AliRelAlignerKalman* al = fPArray[i];
340 vx(entry) = al->GetTimeStamp();
341 vy(entry) = al->GetStateArr()[iparam];
342 TMatrixDSym* cm = al->GetStateCov();
343 vey(entry) = TMath::Sqrt((*cm)(iparam,iparam));
347 TGraphErrors* graph = new TGraphErrors(vx,vy,vex,vey);
353 graphtitle="rotation \\psi";
354 graphtitley="\\psi [rad]";
357 graphtitle="rotation \\theta";
358 graphtitley="\\theta [rad]";
361 graphtitle="rotation \\phi";
362 graphtitley="\\phi [rad]";
365 graphtitle="shift x";
366 graphtitley="x [cm]";
369 graphtitle="shift y";
370 graphtitley="y [cm]";
373 graphtitle="shift z";
374 graphtitley="z [cm]";
377 graphtitle="TPC vd correction";
378 graphtitley="correction factor []";
381 graphtitle="TPC t0 correction";
382 graphtitley="t0 correction [\\micros]";
385 graphtitle="TPC dv/dy";
386 graphtitley="dv/dy [cm/\\micros/m]";
389 graph->SetName(graphtitle);
390 graph->SetTitle(graphtitle);
391 TAxis* xas = graph->GetXaxis();
392 TAxis* yas = graph->GetYaxis();
393 xas->SetTitle("time");
394 xas->SetTimeDisplay(1);
395 yas->SetTitle(graphtitley);
399 //______________________________________________________________________________
400 AliRelAlignerKalmanArray* AliRelAlignerKalmanArray::MakeSmoothArray() const
402 //return a smoothed version of the data
403 AliRelAlignerKalmanArray* outputarr = new AliRelAlignerKalmanArray(fT0,
404 fT0+fSize*fTimebinWidth,fTimebinWidth);
406 AliRelAlignerKalman* tmpaligner = outputarr->GetAlignerTemplate();
407 tmpaligner->SetOutRejSigma(fOutRejSigmaOnSmooth);
408 //copy the first filled slot
410 while (!fPArray[n]) {n++;}
411 if (n==fSize) return NULL;
412 *tmpaligner = *fPArray[n];
413 if (fPArray[n]->GetNUpdates()>10)
414 (*outputarr)[n] = new AliRelAlignerKalman(*(fPArray[n]));
415 //for the rest of slots use merge
416 for (Int_t i=n+1;i<fSize;i++)
418 if (!fPArray[i]) continue;
419 PropagateToTime(tmpaligner, fPArray[i]->GetTimeStamp());
420 if (tmpaligner->Merge(fPArray[i]))
421 (*outputarr)[i] = new AliRelAlignerKalman(*tmpaligner);
423 (*outputarr)[i] = new AliRelAlignerKalman(*(fPArray[i]));
426 tmpaligner->Reset(); //clean up
431 //______________________________________________________________________________
432 void AliRelAlignerKalmanArray::PropagateToTime(AliRelAlignerKalman* al, UInt_t timestamp ) const
434 //propagate an aligner in time
435 TMatrixDSym* cov = al->GetStateCov();
436 TMatrixDSym corr(TMatrixDSym::kZero,*cov);
437 UInt_t dt = (timestamp>al->GetTimeStamp())?
438 timestamp-al->GetTimeStamp():al->GetTimeStamp()-timestamp;
439 //the propagation matrix
440 //to be added to the covariance matrix of kalman filter
441 corr(6,6) = dt*1e-8; //vdrift
445 //______________________________________________________________________________
446 void AliRelAlignerKalmanArray::Browse(TBrowser* b )
451 fListOfGraphs=new TList();
452 fListOfGraphs->SetName("graphs");
453 fListOfGraphs->SetOwner(kTRUE);
455 for (Int_t i=0;i<9;i++)
457 TGraphErrors* gr = dynamic_cast<TGraphErrors*>(fListOfGraphs->At(i));
459 fListOfGraphs->AddAt(MakeGraph(i),i);
461 b->Add(fListOfGraphs);