]>
Commit | Line | Data |
---|---|---|
81f1d3ae | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | ||
4d610fd5 | 18 | //----------------------------------------------------------------------------- |
19 | /// \class AliMUONAlignmentTask | |
20 | /// AliAnalysisTask to align the MUON spectrometer. | |
21 | /// The Task reads as input ESDs and feeds the MUONTracks to AliMUONAlignment. | |
22 | /// The alignment itself is performed by AliMillepede. | |
23 | /// A OCDB entry is written with the alignment parameters. | |
24 | /// A list of graph are written to monitor the alignment parameters. | |
25 | /// | |
26 | /// \author Javier Castillo, CEA/Saclay - Irfu/SPhN | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
56218672 | 29 | // this class header must always come first |
30 | #include "AliMUONAlignmentTask.h" | |
4d610fd5 | 31 | |
56218672 | 32 | // local header must come before system headers |
4d610fd5 | 33 | #include "AliAnalysisManager.h" |
56218672 | 34 | #include "AliAODInputHandler.h" |
35 | #include "AliAODHandler.h" | |
36 | #include "AliAODEvent.h" | |
37 | #include "AliAODHeader.h" | |
4d610fd5 | 38 | #include "AliESDInputHandler.h" |
39 | #include "AliESDEvent.h" | |
40 | #include "AliESDMuonTrack.h" | |
41 | #include "AliMagF.h" | |
56218672 | 42 | #include "AliCDBStorage.h" |
4d610fd5 | 43 | #include "AliCDBManager.h" |
cd8521dd | 44 | #include "AliGRPManager.h" |
4d610fd5 | 45 | #include "AliCDBMetaData.h" |
46 | #include "AliCDBId.h" | |
47 | #include "AliGeomManager.h" | |
48 | ||
49 | #include "AliMpCDB.h" | |
56218672 | 50 | #include "AliMUONCDB.h" |
4d610fd5 | 51 | #include "AliMUONAlignment.h" |
52 | #include "AliMUONTrack.h" | |
53 | #include "AliMUONTrackExtrap.h" | |
54 | #include "AliMUONTrackParam.h" | |
55 | #include "AliMUONGeometryTransformer.h" | |
56 | #include "AliMUONESDInterface.h" | |
57 | ||
56218672 | 58 | // system headers |
59 | #include <fstream> | |
60 | #include <TString.h> | |
61 | #include <TError.h> | |
62 | #include <TGraphErrors.h> | |
63 | #include <TTree.h> | |
64 | #include <TChain.h> | |
65 | #include <TClonesArray.h> | |
66 | #include <TGeoGlobalMagField.h> | |
67 | #include <TGeoManager.h> | |
68 | #include <Riostream.h> | |
4d610fd5 | 69 | |
56218672 | 70 | ///\cond CLASSIMP |
4d610fd5 | 71 | ClassImp(AliMUONAlignmentTask) |
72 | ///\endcond | |
73 | ||
4d610fd5 | 74 | //________________________________________________________________________ |
56218672 | 75 | AliMUONAlignmentTask::AliMUONAlignmentTask(const char *name, const char *newalignocdb, const char *oldalignocdb, const char *defaultocdb, const char *geofilename): |
76 | AliAnalysisTaskSE(name), | |
77 | fReadRecords( kFALSE ), | |
78 | fWriteRecords( kFALSE ), | |
79 | fDoAlignment( kTRUE ), | |
80 | fAlign(0x0), | |
81 | fGeoFilename(geofilename), | |
82 | fDefaultStorage(defaultocdb), | |
83 | fOldAlignStorage(oldalignocdb), | |
84 | fNewAlignStorage(newalignocdb), | |
85 | fOldGeoTransformer(NULL), | |
86 | fNewGeoTransformer(NULL), | |
87 | fLoadOCDBOnce(kFALSE), | |
88 | fOCDBLoaded(kFALSE), | |
89 | fTrackTot(0), | |
90 | fTrackOk(0), | |
91 | fLastRunNumber(-1), | |
92 | fMSDEx(0x0), | |
93 | fMSDEy(0x0), | |
94 | fMSDEz(0x0), | |
95 | fMSDEp(0x0), | |
96 | fList(0x0), | |
97 | fRecords(0x0), | |
98 | fRecordCount(0) | |
4d610fd5 | 99 | { |
100 | /// Default Constructor | |
101 | // Define input and output slots here | |
102 | // Input slot #0 works with a TChain | |
103 | DefineInput(0, TChain::Class()); | |
56218672 | 104 | |
4d610fd5 | 105 | // Output slot #0 writes NTuple/histos into a TList |
56218672 | 106 | DefineOutput(1, TList::Class()); |
4d610fd5 | 107 | |
108 | // initialize parameters ... | |
56218672 | 109 | for(Int_t k=0;k<4*156;k++) |
110 | { | |
4d610fd5 | 111 | fParameters[k]=0.; |
112 | fErrors[k]=0.; | |
113 | fPulls[k]=0.; | |
114 | } | |
115 | ||
56218672 | 116 | fOldGeoTransformer = new AliMUONGeometryTransformer(); |
4d610fd5 | 117 | |
56218672 | 118 | } |
4d610fd5 | 119 | |
120 | //________________________________________________________________________ | |
56218672 | 121 | AliMUONAlignmentTask::AliMUONAlignmentTask(const AliMUONAlignmentTask& other): |
122 | AliAnalysisTaskSE(other), | |
123 | fReadRecords( other.fReadRecords ), | |
124 | fWriteRecords( other.fWriteRecords ), | |
125 | fDoAlignment( other.fDoAlignment ), | |
21fd9b2c | 126 | fAlign( other.fAlign ), |
56218672 | 127 | fGeoFilename( other.fGeoFilename ), |
128 | fDefaultStorage( other.fDefaultStorage ), | |
129 | fOldAlignStorage( other.fOldAlignStorage ), | |
130 | fNewAlignStorage( other.fNewAlignStorage ), | |
131 | fOldGeoTransformer( other.fOldGeoTransformer ), | |
132 | fNewGeoTransformer( other.fNewGeoTransformer ), | |
133 | fLoadOCDBOnce( other.fLoadOCDBOnce ), | |
134 | fOCDBLoaded( other.fOCDBLoaded ), | |
135 | fTrackTot( other.fTrackTot ), | |
136 | fTrackOk( other.fTrackOk ), | |
137 | fLastRunNumber( other.fLastRunNumber ), | |
138 | fMSDEx( other.fMSDEx ), | |
139 | fMSDEy( other.fMSDEy ), | |
140 | fMSDEz( other.fMSDEz ), | |
141 | fMSDEp( other.fMSDEp ), | |
142 | fList( other.fList ), | |
143 | fRecords( other.fRecords ), | |
144 | fRecordCount( other.fRecordCount ) | |
4d610fd5 | 145 | { |
f4c2989f | 146 | |
56218672 | 147 | // initialize parameters |
148 | for(Int_t k=0;k<4*156;k++) | |
149 | { | |
150 | ||
151 | fParameters[k]=other.fParameters[k]; | |
152 | fErrors[k]=other.fErrors[k]; | |
153 | fPulls[k]=other.fPulls[k]; | |
154 | ||
f4c2989f | 155 | } |
156 | ||
4d610fd5 | 157 | } |
158 | ||
159 | //________________________________________________________________________ | |
56218672 | 160 | AliMUONAlignmentTask& AliMUONAlignmentTask::operator=(const AliMUONAlignmentTask& other) |
4d610fd5 | 161 | { |
162 | /// Assignment | |
56218672 | 163 | AliAnalysisTaskSE::operator=(other); |
164 | ||
165 | fReadRecords = other.fReadRecords; | |
166 | fWriteRecords = other.fWriteRecords; | |
167 | fDoAlignment = other.fDoAlignment; | |
168 | ||
169 | // this breaks in destructor | |
4d610fd5 | 170 | fAlign = other.fAlign; |
56218672 | 171 | |
4d610fd5 | 172 | fGeoFilename = other.fGeoFilename; |
56218672 | 173 | fDefaultStorage = other.fDefaultStorage; |
174 | fOldAlignStorage = other.fOldAlignStorage; | |
175 | fNewAlignStorage = other.fNewAlignStorage; | |
176 | ||
177 | // this breaks in destructor | |
178 | fOldGeoTransformer = other.fOldGeoTransformer; | |
179 | fNewGeoTransformer = other.fNewGeoTransformer; | |
180 | ||
181 | fLoadOCDBOnce = other.fLoadOCDBOnce; | |
182 | fOCDBLoaded = other.fOCDBLoaded; | |
183 | fTrackTot = other.fTrackTot; | |
184 | fTrackOk = other.fTrackOk; | |
2df5c2cf | 185 | fLastRunNumber = other.fLastRunNumber; |
56218672 | 186 | fMSDEx = other.fMSDEx; |
187 | fMSDEy = other.fMSDEy; | |
4d610fd5 | 188 | fMSDEz = other.fMSDEz; |
189 | fMSDEp = other.fMSDEp; | |
56218672 | 190 | fList = other.fList; |
191 | fRecords = other.fRecords; | |
192 | fRecordCount = other.fRecordCount; | |
f4c2989f | 193 | |
194 | // initialize parameters ... | |
56218672 | 195 | for( Int_t k=0; k<4*156; ++k) |
196 | { | |
197 | ||
f4c2989f | 198 | fParameters[k]=other.fParameters[k]; |
199 | fErrors[k]=other.fErrors[k]; | |
200 | fPulls[k]=other.fPulls[k]; | |
56218672 | 201 | |
f4c2989f | 202 | } |
56218672 | 203 | |
4d610fd5 | 204 | return *this; |
205 | } | |
206 | ||
207 | //________________________________________________________________________ | |
56218672 | 208 | AliMUONAlignmentTask::~AliMUONAlignmentTask() |
209 | { | |
210 | /* | |
211 | it is safe to delete NULL pointers, so | |
212 | there is no need to test their validity here. | |
213 | However, it crashes here, because of incorrect assignment operator | |
214 | and copy constructor, resulting in double deletion of objects. | |
215 | Would require deep copy instead. | |
216 | */ | |
217 | delete fAlign; | |
218 | delete fOldGeoTransformer; | |
219 | delete fNewGeoTransformer; | |
4d610fd5 | 220 | } |
221 | ||
222 | //________________________________________________________________________ | |
56218672 | 223 | void AliMUONAlignmentTask::LocalInit() |
4d610fd5 | 224 | { |
56218672 | 225 | /// Local initialization, called once per task on the client machine |
4d610fd5 | 226 | /// where the analysis train is assembled |
56218672 | 227 | |
228 | // print configuration | |
229 | AliInfo( Form( "fReadRecords: %s", (fReadRecords ? "kTRUE":"kFALSE" ) ) ); | |
230 | AliInfo( Form( "fWriteRecords: %s", (fWriteRecords ? "kTRUE":"kFALSE" ) ) ); | |
231 | AliInfo( Form( "fDoAlignment: %s", (fDoAlignment ? "kTRUE":"kFALSE" ) ) ); | |
232 | ||
233 | // consistency checks between flags | |
234 | /* need at least one of the flags set to true */ | |
235 | if( !( fReadRecords || fWriteRecords || fDoAlignment ) ) | |
236 | { AliFatal( "Need at least one of the three flags fReadRecords, fWriteRecords and fDoAlignment set to kTRUE" ); } | |
237 | ||
238 | /* cannot read and write records at the same time */ | |
239 | if( fReadRecords && fWriteRecords ) | |
240 | { AliFatal( "Cannot set both fReadRecords and fWriteRecords to kTRUE at the same time" ); } | |
241 | ||
242 | /* must run alignment when reading records */ | |
243 | if( fReadRecords && !fDoAlignment ) | |
244 | { | |
245 | ||
246 | AliInfo( "Automatically setting fDoAlignment to kTRUE because fReadRecords is kTRUE" ); | |
247 | SetDoAlignment( kTRUE ); | |
248 | ||
249 | } | |
4d610fd5 | 250 | |
251 | // Set initial values here, good guess may help convergence | |
56218672 | 252 | // St 1 |
4d610fd5 | 253 | // Int_t iPar = 0; |
56218672 | 254 | // fParameters[iPar++] = 0.010300 ; fParameters[iPar++] = 0.010600 ; fParameters[iPar++] = 0.000396 ; |
4d610fd5 | 255 | |
56218672 | 256 | fAlign = new AliMUONAlignment(); |
4d610fd5 | 257 | fAlign->InitGlobalParameters(fParameters); |
258 | ||
56218672 | 259 | // AliCDBManager::Instance()->Print(); |
260 | // | |
261 | // fAlign->SetGeometryTransformer(fOldGeoTransformer); | |
4d610fd5 | 262 | |
263 | // Do alignment with magnetic field off | |
264 | fAlign->SetBFieldOn(kFALSE); | |
56218672 | 265 | |
4d610fd5 | 266 | // Set tracking station to use |
267 | // Bool_t bStOnOff[5] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE}; | |
56218672 | 268 | Bool_t bChOnOff[10] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE}; |
4d610fd5 | 269 | |
270 | // Set degrees of freedom to align (see AliMUONAlignment) | |
271 | fAlign->AllowVariations(bChOnOff); | |
272 | ||
56218672 | 273 | // Set expected resolution (see AliMUONAlignment) |
274 | fAlign->SetSigmaXY(0.15,0.10); | |
275 | ||
4d610fd5 | 276 | // Fix parameters or add constraints here |
277 | // for (Int_t iSt=0; iSt<5; iSt++) | |
278 | // if (!bStOnOff[iSt]) fAlign->FixStation(iSt+1); | |
279 | for (Int_t iCh=0; iCh<10; iCh++) | |
280 | if (!bChOnOff[iCh]) fAlign->FixChamber(iCh+1); | |
281 | ||
56218672 | 282 | // Left and right sides of the detector are independent, one can choose to align |
4d610fd5 | 283 | // only one side |
284 | Bool_t bSpecLROnOff[2] = {kTRUE,kTRUE}; | |
285 | fAlign->FixHalfSpectrometer(bChOnOff,bSpecLROnOff); | |
286 | ||
287 | fAlign->SetChOnOff(bChOnOff); | |
288 | fAlign->SetSpecLROnOff(bChOnOff); | |
289 | ||
290 | // Here we can fix some detection elements | |
56218672 | 291 | // fAlign->FixDetElem(908); |
292 | // fAlign->FixDetElem(1012); | |
293 | fAlign->FixDetElem(608); | |
4d610fd5 | 294 | |
295 | // Set predifined global constrains: X, Y, P, XvsZ, YvsZ, PvsZ, XvsY, YvsY, PvsY | |
296 | // Bool_t bVarXYT[9] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE}; | |
297 | // Bool_t bDetTLBR[4] = {kFALSE,kTRUE,kFALSE,kTRUE}; | |
298 | // fAlign->AddConstraints(bChOnOff,bVarXYT,bDetTLBR,bSpecLROnOff); | |
299 | ||
300 | } | |
301 | ||
302 | //________________________________________________________________________ | |
56218672 | 303 | void AliMUONAlignmentTask::UserCreateOutputObjects() |
4d610fd5 | 304 | { |
56218672 | 305 | |
306 | if( fDoAlignment ) | |
307 | { | |
308 | ||
309 | // Creating graphs | |
310 | fMSDEx = new TGraphErrors(156); | |
311 | fMSDEy = new TGraphErrors(156); | |
312 | fMSDEz = new TGraphErrors(156); | |
313 | fMSDEp = new TGraphErrors(156); | |
314 | ||
315 | // Add Ntuples to the list | |
316 | fList = new TList(); | |
317 | fList->Add(fMSDEx); | |
318 | fList->Add(fMSDEy); | |
319 | fList->Add(fMSDEz); | |
320 | fList->Add(fMSDEp); | |
321 | ||
322 | fList->SetOwner(kTRUE); | |
323 | PostData(1, fList); | |
324 | } | |
325 | ||
326 | // connect AOD output | |
327 | if( fWriteRecords ) | |
328 | { | |
329 | AliAODHandler* handler = dynamic_cast<AliAODHandler*>( AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler() ); | |
330 | if( handler ) | |
331 | { | |
332 | ||
333 | // get AOD output handler and add Branch | |
334 | fRecords = new TClonesArray( "AliMUONAlignmentTrackRecord", 0 ); | |
335 | fRecords->SetName( "records" ); | |
336 | handler->AddBranch("TClonesArray", &fRecords); | |
337 | ||
338 | fRecordCount = 0; | |
339 | ||
340 | } else AliInfo( "Error: invalid output event handler" ); | |
341 | ||
4d610fd5 | 342 | } |
4d610fd5 | 343 | |
4d610fd5 | 344 | } |
345 | ||
346 | //________________________________________________________________________ | |
56218672 | 347 | void AliMUONAlignmentTask::UserExec(Option_t *) |
4d610fd5 | 348 | { |
56218672 | 349 | // print configuration |
350 | // AliInfo( Form( "fReadRecords: %s", (fReadRecords ? "kTRUE":"kFALSE" ) ) ); | |
351 | // AliInfo( Form( "fWriteRecords: %s", (fWriteRecords ? "kTRUE":"kFALSE" ) ) ); | |
352 | // AliInfo( Form( "fDoAlignment: %s", (fDoAlignment ? "kTRUE":"kFALSE" ) ) ); | |
353 | // clear array | |
354 | if( fWriteRecords && fRecords ) | |
355 | { | |
356 | fRecords->Clear(); | |
357 | fRecordCount = 0; | |
4d610fd5 | 358 | } |
359 | ||
56218672 | 360 | // local track parameters |
4d610fd5 | 361 | Double_t trackParams[8] = {0.,0.,0.,0.,0.,0.,0.,0.}; |
56218672 | 362 | |
363 | if( fReadRecords ) { | |
364 | ||
365 | AliAODEvent* lAOD( dynamic_cast<AliAODEvent*>(InputEvent() ) ); | |
366 | ||
367 | // check AOD | |
368 | if( !lAOD ) | |
369 | { | |
370 | AliInfo("Error: AOD event not available"); | |
371 | return; | |
372 | } | |
373 | ||
374 | // read records | |
375 | TClonesArray* records = static_cast<TClonesArray*>( lAOD->FindListObject( "records" ) ); | |
376 | if( !records ) | |
377 | { | |
378 | AliInfo( "Unable to read object name \"records\"" ); | |
379 | return; | |
380 | } | |
381 | ||
382 | // get number of records and print | |
383 | const Int_t lRecordsCount( records->GetEntriesFast() ); | |
384 | fTrackTot += lRecordsCount; | |
385 | ||
386 | // loop over records | |
387 | for( Int_t index = 0; index < lRecordsCount; ++index ) | |
388 | { | |
389 | ||
390 | if( AliMUONAlignmentTrackRecord* record = dynamic_cast<AliMUONAlignmentTrackRecord*>( records->UncheckedAt(index) ) ) | |
391 | { | |
392 | ||
393 | fAlign->ProcessTrack( record, fDoAlignment ); | |
394 | if( fDoAlignment ) | |
395 | { fAlign->LocalFit( fTrackOk++, trackParams, 0 ); } | |
396 | ||
397 | } else AliInfo( Form( "Invalid record at %i", index ) ); | |
398 | ||
399 | } | |
400 | ||
401 | } else { | |
402 | ||
403 | /// Main loop, called for each event | |
404 | AliESDEvent* lESD( dynamic_cast<AliESDEvent*>(InputEvent()) ); | |
405 | ||
406 | // check ESD | |
407 | if( !lESD ) | |
408 | { | |
409 | AliInfo("Error: ESD event not available"); | |
410 | return; | |
4d610fd5 | 411 | } |
56218672 | 412 | |
413 | // HUGO: Comment out check on run number, to be able to run on MC | |
414 | // if (!lESD->GetRunNumber()) | |
415 | // { | |
416 | // AliInfo( Form( "Current Run Number: %i", lESD->GetRunNumber() ) ); | |
417 | // return; | |
418 | // } | |
419 | ||
420 | // if (lESD->GetRunNumber()!=fLastRunNumber){ | |
421 | // fLastRunNumber = lESD->GetRunNumber(); | |
422 | // Prepare(fGeoFilename.Data(),fDefaultOCDB.Data(),fMisAlignOCDB.Data()); | |
423 | // } | |
424 | ||
425 | Int_t nTracks = Int_t(lESD->GetNumberOfMuonTracks()); | |
426 | // cout << " there are " << nTracks << " tracks" << endl; | |
427 | for( Int_t iTrack = 0; iTrack < nTracks; iTrack++ ) | |
428 | { | |
429 | ||
430 | AliESDMuonTrack* esdTrack = lESD->GetMuonTrack(iTrack); | |
431 | if (!esdTrack->ClustersStored()) continue; | |
432 | if (!esdTrack->ContainTriggerData()) continue; | |
433 | ||
434 | Double_t invBenMom = esdTrack->GetInverseBendingMomentum(); | |
435 | // fInvBenMom->Fill(invBenMom); | |
436 | // fBenMom->Fill(1./invBenMom); | |
437 | if (TMath::Abs(invBenMom)<=1.04) | |
438 | { | |
439 | ||
440 | AliMUONTrack track; | |
441 | AliMUONESDInterface::ESDToMUON(*esdTrack, track); | |
442 | ||
443 | // process track and retrieve corresponding records, for storage | |
444 | const AliMUONAlignmentTrackRecord* lRecords( fAlign->ProcessTrack( &track, fDoAlignment ) ); | |
445 | ||
446 | // do the fit, if required | |
447 | if( fDoAlignment ) fAlign->LocalFit(fTrackOk++,trackParams,0); | |
448 | else fTrackOk++; | |
449 | ||
450 | // store in array | |
451 | if( fWriteRecords && fRecords ) | |
452 | { | |
453 | new((*fRecords)[fRecordCount]) AliMUONAlignmentTrackRecord( *lRecords ); | |
454 | ++fRecordCount; | |
455 | } | |
456 | ||
457 | } | |
458 | ||
459 | ++fTrackTot; | |
460 | ||
461 | if(!(fTrackTot%1000)) | |
462 | { AliInfo( Form( "Processed %i Tracks and %i were fitted.", fTrackTot, fTrackOk ) ); } | |
463 | ||
464 | // cout << "Processed " << fTrackTot << " Tracks." << endl; | |
465 | // Post final data. Write histo list to a file with option "RECREATE" | |
466 | PostData(1,fList); | |
467 | ||
468 | } | |
469 | ||
470 | // save AOD | |
471 | if( fWriteRecords && fRecordCount > 0 ) { | |
ec542584 | 472 | AliAODHandler* handler = dynamic_cast<AliAODHandler*>( AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler() ); |
473 | if( handler ) | |
474 | { | |
56218672 | 475 | // printf("handler: %p\n",handler); |
476 | AliAODEvent* aod = handler->GetAOD(); | |
477 | // printf("aod: %p\n",aod); | |
478 | AliAODHeader* header = aod->GetHeader(); | |
479 | // printf("header: %p\n",header); | |
480 | header->SetRunNumber(lESD->GetRunNumber()); | |
481 | // printf("RunNumber: %d\n",lESD->GetRunNumber()); | |
ec542584 | 482 | AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE); |
483 | } else AliInfo( "Error: invalid output event handler" ); | |
484 | } | |
56218672 | 485 | |
4d610fd5 | 486 | } |
56218672 | 487 | |
488 | } | |
489 | ||
490 | //________________________________________________________________________ | |
491 | void AliMUONAlignmentTask::Terminate(const Option_t*) | |
492 | { return; } | |
4d610fd5 | 493 | |
494 | //________________________________________________________________________ | |
2df5c2cf | 495 | void AliMUONAlignmentTask::FinishTaskOutput() |
4d610fd5 | 496 | { |
56218672 | 497 | |
4d610fd5 | 498 | /// Called once per task on the client machine at the end of the analysis. |
56218672 | 499 | AliInfo( Form( "Processed %i tracks.", fTrackTot ) ); |
500 | AliInfo( Form( "Accepted %i tracks.", fTrackOk ) ); | |
501 | ||
502 | // stop here if no alignment is to be performed | |
503 | if( !fDoAlignment ) return; | |
504 | ||
505 | AliLog::SetGlobalLogLevel(AliLog::kInfo); | |
4d610fd5 | 506 | |
4d610fd5 | 507 | // Perform global fit |
508 | fAlign->GlobalFit(fParameters,fErrors,fPulls); | |
509 | ||
2df5c2cf | 510 | // // Update pointers reading them from the output slot |
511 | // fList = (TList*)GetOutputData(0); | |
512 | // fMSDEx = (TGraphErrors*)fList->At(0); | |
513 | // fMSDEy = (TGraphErrors*)fList->At(1); | |
514 | // fMSDEz = (TGraphErrors*)fList->At(2); | |
515 | // fMSDEp = (TGraphErrors*)fList->At(3); | |
4d610fd5 | 516 | |
517 | // Store results | |
56218672 | 518 | Double_t DEid[156] = {0}; |
519 | Double_t MSDEx[156] = {0}; | |
520 | Double_t MSDEy[156] = {0}; | |
521 | Double_t MSDEz[156] = {0}; | |
522 | Double_t MSDEp[156] = {0}; | |
523 | Double_t DEidErr[156] = {0}; | |
524 | Double_t MSDExErr[156] = {0}; | |
525 | Double_t MSDEyErr[156] = {0}; | |
526 | Double_t MSDEzErr[156] = {0}; | |
527 | Double_t MSDEpErr[156] = {0}; | |
4d610fd5 | 528 | Int_t lNDetElem = 4*2+4*2+18*2+26*2+26*2; |
529 | Int_t lNDetElemCh[10] = {4,4,4,4,18,18,26,26,26,26}; | |
530 | // Int_t lSNDetElemCh[10] = {4,8,12,16,34,52,78,104,130,156}; | |
531 | Int_t idOffset = 0; // 400 | |
532 | Int_t lSDetElemCh = 0; | |
56218672 | 533 | for(Int_t iDE=0; iDE<lNDetElem; iDE++) |
534 | { | |
535 | ||
536 | DEidErr[iDE] = 0.; | |
537 | DEid[iDE] = idOffset+100; | |
538 | DEid[iDE] += iDE; | |
4d610fd5 | 539 | lSDetElemCh = 0; |
56218672 | 540 | for(Int_t iCh=0; iCh<9; iCh++) |
541 | { | |
4d610fd5 | 542 | lSDetElemCh += lNDetElemCh[iCh]; |
56218672 | 543 | |
544 | if (iDE>=lSDetElemCh) | |
545 | { | |
546 | DEid[iDE] += 100; | |
547 | DEid[iDE] -= lNDetElemCh[iCh]; | |
4d610fd5 | 548 | } |
56218672 | 549 | |
4d610fd5 | 550 | } |
56218672 | 551 | |
552 | MSDEx[iDE]=fParameters[4*iDE+0]; | |
553 | MSDEy[iDE]=fParameters[4*iDE+1]; | |
554 | MSDEz[iDE]=fParameters[4*iDE+3]; | |
555 | MSDEp[iDE]=fParameters[4*iDE+2]; | |
556 | MSDExErr[iDE]=(Double_t)fAlign->GetParError(4*iDE+0); | |
557 | MSDEyErr[iDE]=(Double_t)fAlign->GetParError(4*iDE+1); | |
558 | MSDEzErr[iDE]=(Double_t)fAlign->GetParError(4*iDE+3); | |
559 | MSDEpErr[iDE]=(Double_t)fAlign->GetParError(4*iDE+2); | |
560 | fMSDEx->SetPoint(iDE,DEid[iDE],fParameters[4*iDE+0]); | |
561 | fMSDEx->SetPointError(iDE,DEidErr[iDE],(Double_t)fAlign->GetParError(4*iDE+0)); | |
562 | fMSDEy->SetPoint(iDE,DEid[iDE],fParameters[4*iDE+1]); | |
563 | fMSDEy->SetPointError(iDE,DEidErr[iDE],(Double_t)fAlign->GetParError(4*iDE+1)); | |
564 | fMSDEz->SetPoint(iDE,DEid[iDE],fParameters[4*iDE+3]); | |
565 | fMSDEz->SetPointError(iDE,DEidErr[iDE],(Double_t)fAlign->GetParError(4*iDE+3)); | |
566 | fMSDEp->SetPoint(iDE,DEid[iDE],fParameters[4*iDE+2]); | |
567 | fMSDEp->SetPointError(iDE,DEidErr[iDE],(Double_t)fAlign->GetParError(4*iDE+2)); | |
568 | ||
4d610fd5 | 569 | } |
570 | ||
571 | // Post final data. Write histo list to a file with option "RECREATE" | |
56218672 | 572 | PostData(1,fList); |
573 | ||
574 | // HUGO: stop here to test reproducibility | |
575 | // return; | |
4d610fd5 | 576 | |
4d610fd5 | 577 | // Re Align |
56218672 | 578 | fNewGeoTransformer = fAlign->ReAlign(fOldGeoTransformer,fParameters,true); |
579 | // newTransform->WriteTransformations("transform2ReAlign.dat"); | |
580 | ||
4d610fd5 | 581 | // Generate realigned data in local cdb |
56218672 | 582 | const TClonesArray* array = fNewGeoTransformer->GetMisAlignmentData(); |
4d610fd5 | 583 | |
584 | // 100 mum residual resolution for chamber misalignments? | |
585 | fAlign->SetAlignmentResolution(array,-1,0.01,0.01,0.004,0.003); | |
56218672 | 586 | |
4d610fd5 | 587 | // CDB manager |
56218672 | 588 | AliLog::SetGlobalDebugLevel(2); |
589 | AliCDBManager* cdbm = AliCDBManager::Instance(); | |
590 | // cdbManager->SetDefaultStorage(fDefaultOCDB.Data()); | |
591 | ||
592 | // recover default storage full name (raw:// cannot be used to set specific storage) | |
593 | TString defaultStorage(cdbm->GetDefaultStorage()->GetType()); | |
594 | if (defaultStorage == "alien") defaultStorage += Form("://folder=%s", cdbm->GetDefaultStorage()->GetBaseFolder().Data()); | |
595 | else defaultStorage += Form("://%s", cdbm->GetDefaultStorage()->GetBaseFolder().Data()); | |
596 | ||
597 | if (fOldAlignStorage != "none") cdbm->UnloadFromCache("MUON/Align/Data"); | |
598 | if (!fNewAlignStorage.IsNull()) cdbm->SetSpecificStorage("MUON/Align/Data",fNewAlignStorage.Data()); | |
599 | // else cdbm->SetSpecificStorage("MUON/Align/Data",fDefaultStorage.Data()); | |
600 | else cdbm->SetSpecificStorage("MUON/Align/Data",defaultStorage.Data()); | |
601 | ||
602 | ||
4d610fd5 | 603 | AliCDBMetaData* cdbData = new AliCDBMetaData(); |
604 | cdbData->SetResponsible("Dimuon Offline project"); | |
605 | cdbData->SetComment("MUON alignment objects with residual misalignment"); | |
56218672 | 606 | AliCDBId id("MUON/Align/Data", 0, AliCDBRunRange::Infinity()); |
607 | cdbm->Put(const_cast<TClonesArray*>(array), id, cdbData); | |
608 | ||
609 | gSystem->Exec("cp -a ReAlignOCDB/MUON/Align/Data/Run0_999999999_v0_s0.root Run0_999999999_v0_s0.root"); | |
610 | gSystem->Exec("ls -l"); | |
4d610fd5 | 611 | |
612 | } | |
613 | ||
2df5c2cf | 614 | //________________________________________________________________________ |
56218672 | 615 | void AliMUONAlignmentTask::NotifyRun() |
2df5c2cf | 616 | { |
56218672 | 617 | |
618 | if (fOCDBLoaded && fLoadOCDBOnce) { AliError(Form("OCDB already loaded %d %d",fOCDBLoaded,fLoadOCDBOnce)); | |
619 | return; | |
620 | } | |
2df5c2cf | 621 | |
56218672 | 622 | AliCDBManager* cdbm = AliCDBManager::Instance(); |
623 | cdbm->SetDefaultStorage(fDefaultStorage.Data()); | |
624 | // cdbm->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); | |
2df5c2cf | 625 | |
56218672 | 626 | // HUGO: add to comment out the specific settings below in order to be able to run. |
627 | //cdbm->SetSpecificStorage("GRP/GRP/Data",fDefaultStorage.Data()); | |
628 | //cdbm->SetSpecificStorage("GRP/Geometry/data",fDefaultStorage.Data()); | |
629 | //cdbm->SetSpecificStorage("MUON/Calib/MappingData",fDefaultStorage.Data()); | |
630 | cdbm->SetRun(fCurrentRunNumber); | |
cd8521dd | 631 | |
56218672 | 632 | if (!AliMUONCDB::LoadField()) { AliError("Problem field"); return;} |
2df5c2cf | 633 | |
cd8521dd | 634 | // set the magnetic field for track extrapolations |
635 | AliMUONTrackExtrap::SetField(); | |
56218672 | 636 | |
637 | if (!AliMUONCDB::LoadMapping(kTRUE)) { AliError("Problem mapping"); return;} | |
638 | ||
639 | // recover default storage full name (raw:// cannot be used to set specific storage) | |
640 | TString defaultStorage(cdbm->GetDefaultStorage()->GetType()); | |
641 | if (defaultStorage == "alien") defaultStorage += Form("://folder=%s", cdbm->GetDefaultStorage()->GetBaseFolder().Data()); | |
642 | else defaultStorage += Form("://%s", cdbm->GetDefaultStorage()->GetBaseFolder().Data()); | |
643 | ||
644 | // reset existing geometry/alignment if any | |
645 | if (cdbm->GetEntryCache()->Contains("GRP/Geometry/Data")) cdbm->UnloadFromCache("GRP/Geometry/Data"); | |
646 | if (cdbm->GetEntryCache()->Contains("MUON/Align/Data")) cdbm->UnloadFromCache("MUON/Align/Data"); | |
647 | if (AliGeomManager::GetGeometry()) AliGeomManager::GetGeometry()->UnlockGeometry(); | |
648 | ||
649 | // get original geometry transformer | |
650 | AliGeomManager::LoadGeometry(); | |
651 | if (!AliGeomManager::GetGeometry()) { AliError("Problem geometry"); return;} | |
652 | if (fOldAlignStorage != "none") | |
653 | { | |
654 | ||
655 | if (!fOldAlignStorage.IsNull()) cdbm->SetSpecificStorage("MUON/Align/Data",fOldAlignStorage.Data()); | |
656 | else cdbm->SetSpecificStorage("MUON/Align/Data",defaultStorage.Data()); | |
657 | // else cdbm->SetSpecificStorage("MUON/Align/Data",fDefaultStorage.Data()); | |
658 | ||
659 | AliGeomManager::ApplyAlignObjsFromCDB("MUON"); | |
660 | ||
661 | } | |
662 | ||
663 | // fOldGeoTransformer = new AliMUONGeometryTransformer(); | |
664 | fOldGeoTransformer->LoadGeometryData(); | |
665 | fAlign->SetGeometryTransformer(fOldGeoTransformer); | |
666 | ||
667 | fOCDBLoaded = kTRUE; | |
668 | ||
cd8521dd | 669 | } |