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 //////////////////////////////////////////////////////////////////////////////
28 #include <TObjArray.h>
29 #include <TCollection.h>
30 #include "AliESDEvent.h"
31 #include "AliRelAlignerKalman.h"
32 #include "AliRelAlignerKalmanArray.h"
34 ClassImp(AliRelAlignerKalmanArray)
36 //______________________________________________________________________________
37 AliRelAlignerKalmanArray::AliRelAlignerKalmanArray():
39 fArray(new TObjArray()),
40 fSaveInterval(600), //default every 10minutes
41 fTimeMatchingTolerance(20),
43 fAligner(new AliRelAlignerKalman())
48 //______________________________________________________________________________
49 AliRelAlignerKalmanArray::AliRelAlignerKalmanArray(const char* name):
51 fArray(new TObjArray()),
52 fSaveInterval(600), //default every 10 minutes
53 fTimeMatchingTolerance(60),
55 fAligner(new AliRelAlignerKalman())
60 //______________________________________________________________________________
61 AliRelAlignerKalmanArray::~AliRelAlignerKalmanArray()
69 //______________________________________________________________________________
70 Long64_t AliRelAlignerKalmanArray::Merge( TCollection* list )
72 //Merge all the arrays
73 //the merge is vertical, meaning matching entries in tree are merged
75 AliRelAlignerKalmanArray *arrayFromList;
78 while ( (arrayFromList = dynamic_cast<AliRelAlignerKalmanArray*>(next())) )
80 if (arrayFromList==this) continue;
82 fArray->AddAll(arrayFromList->fArray); //put all objects in one array
86 TObjArray* tmpArray = SortedMerge(fArray);
87 tmpArray->SetOwner(kTRUE);
89 TObjArray* newArray = dynamic_cast<TObjArray*>(tmpArray->Clone());
90 delete fArray; //takes care of all loaded objects
93 fArray->AddLast(arrayFromList->fAligner); //add the endofrun aligner
96 //TODO: this can be done better!
97 //Add own endofrun aligner and clean up
98 fArray->AddLast(fAligner);
100 //TObjArray* tmpArray = SortedMerge(fArray);
101 //tmpArray->SetOwner(kTRUE);
102 //TObjArray* newArray = dynamic_cast<TObjArray*>(tmpArray->Clone());
103 //delete fArray; //takes care of all loaded objects
106 return fArray->GetEntriesFast();
109 //______________________________________________________________________________
110 TObjArray* AliRelAlignerKalmanArray::SortedMerge( TObjArray* input )
112 //Merges the adjacent aligners if close enough
113 //input needs to be already sorted
116 AliRelAlignerKalman* alignerIn;
117 AliRelAlignerKalman* alignerOut = dynamic_cast<AliRelAlignerKalman*>(input->At(0));
118 TObjArray* output = new TObjArray(); //empty array
119 output->AddLast(alignerOut); //first object in: copy of first input element
121 timeStampIn = alignerOut->GetTimeStamp();
122 SetCurrentTimeBin( timeStampIn );
124 while ( (alignerIn = dynamic_cast<AliRelAlignerKalman*>(next())) )
126 timeStampIn = alignerIn->GetTimeStamp();
127 if ( IsInCurrentTimeBin(timeStampIn) )
129 alignerOut->Merge(alignerIn);
133 alignerOut = alignerIn;
134 output->AddLast(alignerOut);
136 SetCurrentTimeBin( timeStampIn );
141 //______________________________________________________________________________
142 void AliRelAlignerKalmanArray::SetCurrentTimeBin( UInt_t timestamp )
144 //set the current timebin
145 fCurrentTimeBin = TimeBin(timestamp);
148 //______________________________________________________________________________
149 UInt_t AliRelAlignerKalmanArray::TimeBin( UInt_t timestamp ) const
151 return (timestamp+(fSaveInterval/2))/fSaveInterval*fSaveInterval; //it's all integers!
154 //______________________________________________________________________________
155 Bool_t AliRelAlignerKalmanArray::IsInCurrentTimeBin( UInt_t timestamp ) const
157 //check if timestamp is within the current timebin
158 UInt_t timeDiff = (timestamp>=fCurrentTimeBin)?timestamp-fCurrentTimeBin:
159 fCurrentTimeBin-timestamp;
160 return (timeDiff < fTimeMatchingTolerance);
163 ////______________________________________________________________________________
164 //void AliRelAlignerKalmanArray::AddESDEvent( AliESDEvent* event )
166 // //add an AliESDEvent, take care of bookkeeping
167 // if (!fAligner) return;
168 // if (event->GetRunNumber() != fAligner->GetRunNumber())
170 // //what to do when a new run starts
175 ////______________________________________________________________________________
176 Bool_t AliRelAlignerKalmanArray::AddCosmicEvent( AliESDEvent* event )
178 if (!fAligner->AddCosmicEvent(event)) return kFALSE;
180 UInt_t currentTimeStamp = event->GetTimeStamp();
181 UInt_t timeFromLastBinCentre = currentTimeStamp - fCurrentTimeBin;
182 UInt_t binCentre = TimeBin(currentTimeStamp);
183 UInt_t timeFromBinCentre = currentTimeStamp-binCentre;
184 UInt_t nIntervals = timeFromLastBinCentre/fSaveInterval;
186 //////////////////////////////////////////////////////////////////////////////
187 //only ONE SAVE PER TIMEBIN!!!!, as close as possible to the bin center
188 //////////////////////////////////////////////////////////////////////////////
189 if ( (nIntervals == 1) && //is in next time bin passed centre
190 (timeFromBinCentre < fTimeMatchingTolerance) ) //and close to it
192 AddLast(new AliRelAlignerKalman(*fAligner));
194 else if ( (nIntervals > 2) ) //TODO: don't hardwire stuff!
196 //if missed a few windows save anyway at current bin centre
197 fAligner->SetTimeStamp(binCentre);
198 AddLast(new AliRelAlignerKalman(*fAligner));
200 //////////////////////////////////////////////////////////////////////////////
205 //______________________________________________________________________________
206 AliRelAlignerKalmanArray::AliRelAlignerKalmanArray( const AliRelAlignerKalmanArray& in):
207 TNamed(in.GetName(), in.GetTitle()),
209 fSaveInterval(in.fSaveInterval),
210 fTimeMatchingTolerance(in.fTimeMatchingTolerance),
211 fCurrentTimeBin(in.fCurrentTimeBin),
212 fAligner(new AliRelAlignerKalman(*in.fAligner))
215 fArray = static_cast<TObjArray*>(in.Clone());
218 //______________________________________________________________________________
219 AliRelAlignerKalmanArray& AliRelAlignerKalmanArray::operator=(const AliRelAlignerKalmanArray& in)
221 //assignment operator
222 fArray = static_cast<TObjArray*>(in.Clone());
223 fSaveInterval = in.fSaveInterval;
224 fTimeMatchingTolerance = in.fTimeMatchingTolerance;
228 //______________________________________________________________________________
229 Bool_t AliRelAlignerKalmanArray::SetSaveInterval( const UInt_t s )
231 //only set if array empty
232 if (fArray->GetEntriesFast()) return kFALSE;
237 //______________________________________________________________________________
238 Bool_t AliRelAlignerKalmanArray::SetTimeMatchingTolerance( const UInt_t m )
240 //only set if array empty
241 if (fArray->GetEntriesFast()) return kFALSE;
242 fTimeMatchingTolerance = m;
246 //______________________________________________________________________________
247 AliRelAlignerKalman* AliRelAlignerKalmanArray::At( Int_t i ) const
249 //mimic TObjArray::At( Int_t i )
250 return dynamic_cast<AliRelAlignerKalman*>(fArray->At(i));
253 //______________________________________________________________________________
254 void AliRelAlignerKalmanArray::AddLast( AliRelAlignerKalman* al )
256 //mimic TObjArray::AddLast( TObject* obj )
257 fArray->AddLast( al );
258 SetCurrentTimeBin(al->GetTimeStamp());
261 //______________________________________________________________________________
262 AliRelAlignerKalman* AliRelAlignerKalmanArray::Last() const
264 //mimic TObjArray::Last()
265 return dynamic_cast<AliRelAlignerKalman*>(fArray->Last());
268 //______________________________________________________________________________
269 AliRelAlignerKalman* AliRelAlignerKalmanArray::operator[](Int_t i) const
271 //mimic TObjArray::operator[](Int_t)
272 return dynamic_cast<AliRelAlignerKalman*>(fArray->At(i));