AliRoot Core  edcc906 (edcc906)
AliMUONAlignmentTask.cxx
Go to the documentation of this file.
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 
18 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
28 
29 // this class header must always come first
30 #include "AliMUONAlignmentTask.h"
31 
32 // local header must come before system headers
33 #include "AliAnalysisManager.h"
34 #include "AliAlignObjMatrix.h"
35 #include "AliAODInputHandler.h"
36 #include "AliAODHandler.h"
37 #include "AliAODEvent.h"
38 #include "AliAODHeader.h"
39 #include "AliCDBEntry.h"
40 #include "AliESDInputHandler.h"
41 #include "AliESDEvent.h"
42 #include "AliESDMuonTrack.h"
43 #include "AliCDBStorage.h"
44 #include "AliCDBManager.h"
45 #include "AliGRPManager.h"
46 #include "AliCDBMetaData.h"
47 #include "AliCDBId.h"
48 #include "AliGeomManager.h"
49 
50 #include "AliMagF.h"
51 #include "AliMillePedeRecord.h"
52 #include "AliMpCDB.h"
53 #include "AliMUONAlignment.h"
54 #include "AliMUONCDB.h"
55 #include "AliMUONESDInterface.h"
57 #include "AliMUONConstants.h"
58 #include "AliMUONRecoParam.h"
59 #include "AliMUONTrack.h"
60 #include "AliMUONTrackExtrap.h"
61 #include "AliMUONTrackParam.h"
62 #include "AliMUONVCluster.h"
63 
64 // system headers
65 #include <cassert>
66 #include <fstream>
67 
68 // root headers
69 #include <TString.h>
70 #include <TError.h>
71 #include <TFile.h>
72 #include <TGraphErrors.h>
73 #include <TTree.h>
74 #include <TChain.h>
75 #include <TClonesArray.h>
76 #include <TGeoGlobalMagField.h>
77 #include <TGeoManager.h>
78 #include <Riostream.h>
79 
81 ClassImp(AliMUONAlignmentTask)
84 
85 //________________________________________________________________________
86 Int_t AliMUONAlignmentTrackParam::GetNChambers( void ) const
87 {
88  Int_t out(0);
89  for( Int_t iCh = 0; iCh < 10; ++iCh )
90  { if( fHitPattern&(1<<iCh) ) out++; }
91 
92  return out;
93 
94 }
95 
96 //______________________________________
98 {
99 
100  Int_t out(0);
101  for( Int_t iSt = 0; iSt < 5; ++iSt )
102  { if( fHitPattern&( (1<<(iSt*2)) | (1<<(iSt*2+1) ) ) ) out++; }
103 
104  return out;
105 
106 }
107 
108 
109 //________________________________________________________________________
110 // Double_t Square( Double_t x ) { return x*x; }
111 // defined in AliMUONAlignent0
112 Double_t Square( Double_t x );
113 
114 //________________________________________________________________________
116  AliAnalysisTaskSE(name),
117  fReadRecords( kFALSE ),
118  fWriteRecords( kFALSE ),
119  fDoAlignment( kTRUE ),
120  fMergeAlignmentCDBs( kTRUE ),
121  fForceBField( kFALSE ),
122  fBFieldOn( kFALSE ),
123  fRefitStraightTracks( kFALSE ),
124  fDoEvaluation( kFALSE ),
125  fMinPt( 0 ),
126  fMinPyPz( 0 ),
127  fMinStations( 0 ),
128  fAlign(0x0),
129  fDefaultStorage(),
130  fOldAlignStorage(),
131  fNewAlignStorage( "local://ReAlignOCDB" ),
132  fOldGeoTransformer(0x0),
133  fNewGeoTransformer(0x0),
134  fLoadOCDBOnce(kFALSE),
135  fOCDBLoaded(kFALSE),
136  fEvent(0),
137  fTrackTot(0),
138  fTrackOk(0),
139  fRecordsTot(0),
140  fRunNumberMin( 0 ),
141  fRunNumberMax( AliCDBRunRange::Infinity() ),
142  fTrackParams(0x0),
143  fRecords(0x0),
144  fRecordCount(0)
145 {
147  // Define input and output slots here
148  // Input slot #0 works with a TChain
149  DefineInput(0, TChain::Class());
150 
151  // initialize parameters ...
152  for(Int_t k=0;k<AliMUONAlignment::fNGlobal;k++)
153  {
154  fParameters[k]=0.;
155  fErrors[k]=0.;
156  fPulls[k]=0.;
157  }
158 
159  // create alignment object
160  fAlign = new AliMUONAlignment();
161 
162  // create old geometry transformer
164 
165 }
166 
167 //________________________________________________________________________
169 {
171  delete fAlign;
172  delete fOldGeoTransformer;
173  delete fNewGeoTransformer;
174 }
175 
176 //________________________________________________________________________
178 {
184  /* must run alignment when reading records */
185  if( fReadRecords && !fDoAlignment )
186  {
187 
188  std::cout << "I-AliMUONAlignmentTask::LocalInit: " << "Automatically setting fDoAlignment to kTRUE because fReadRecords is kTRUE" << std::endl;
189  SetDoAlignment( kTRUE );
190 
191  }
192 
193  // print configuration
194  if( fRunNumberMin > 0 || fRunNumberMax > 0 )
195  { std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "run range: %i - %i", fRunNumberMin, fRunNumberMax ) << std::endl; }
196 
197  std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fReadRecords: %s", (fReadRecords ? "kTRUE":"kFALSE" ) ) << std::endl;
198  std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fWriteRecords: %s", (fWriteRecords ? "kTRUE":"kFALSE" ) ) << std::endl;
199  std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fDoAlignment: %s", (fDoAlignment ? "kTRUE":"kFALSE" ) ) << std::endl;
200 
201  if( fDoAlignment )
202  {
203  // merge alignment DB flag is irrelevant if not actually performing the alignemnt
204  std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fMergeAlignmentCDBs: %s", (fMergeAlignmentCDBs ? "kTRUE":"kFALSE" ) ) << std::endl;
205  }
206 
207  // storage elements
208  if( !fDefaultStorage.IsNull() ) std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fDefaultStorage: %s", fDefaultStorage.Data() ) << std::endl;
209  if( !fOldAlignStorage.IsNull() ) std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fOldAlignStorage: %s", fOldAlignStorage.Data() ) << std::endl;
210 
211  if( fDoAlignment )
212  {
213  // new alignment storage is irrelevant if not actually performing the alignemnt
214  if( !fNewAlignStorage.IsNull() ) std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fNewAlignStorage: %s", fNewAlignStorage.Data() ) << std::endl;
215  else AliFatal( "Invalid new alignment storage path" );
216  }
217 
218  if( !fReadRecords )
219  {
220  // following flags are only relevant if not reading records
221  if( fForceBField ) std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fBFieldOn: %s", (fBFieldOn ? "kTRUE":"kFALSE" ) ) << std::endl;
222  else std::cout << "I-AliMUONAlignmentTask::LocalInit: " << "fBFieldOn: from GRP" << std::endl;
223 
224  // refit straight tracks
225  std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fRefitStraightTracks: %s", (fRefitStraightTracks ? "kTRUE":"kFALSE" ) ) << std::endl;
226  std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fDoEvaluation: %s", (fDoEvaluation ? "kTRUE":"kFALSE" ) ) << std::endl;
227 
228  // min px/pz cut
229  if( fMinPt > 0 ) std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fMinPt: %f", fMinPt ) << std::endl;
230 
231  // min px/pz cut
232  if( fMinPyPz > 0 ) std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fMinPyPz: %f", fMinPyPz ) << std::endl;
233 
234  // min number of stations
235  if( fMinStations > 0 ) std::cout << "I-AliMUONAlignmentTask::LocalInit: " << Form( "fMinStations: %i", fMinStations ) << std::endl;
236 
237  }
238 
239  // consistency checks between flags
240  /* need at least one of the flags set to true */
241  if( !( fReadRecords || fWriteRecords || fDoAlignment ) )
242  { AliFatal( "Need at least one of the three flags fReadRecords, fWriteRecords and fDoAlignment set to kTRUE" ); }
243 
244  /* cannot read and write records at the same time */
245  if( fReadRecords && fWriteRecords )
246  { AliFatal( "Cannot set both fReadRecords and fWriteRecords to kTRUE at the same time" ); }
247 
248  /*
249  fix detectors
250  warning, counting chambers from 1.
251  this must be done before calling the Init method
252  */
253  if( fDoAlignment )
254  {
255 
256 // // Note: grouping must be done before fixing chambers
257 // AliInfo( "Grouping all detectors by half chambers" );
258 // for( Int_t iCh = 5; iCh <= 10; ++iCh )
259 // {
260 // fAlign->GroupHalfChamber( iCh, 0 );
261 // fAlign->GroupHalfChamber( iCh, 1 );
262 // }
263 
264  // fix chambers
265  const Int_t chambers[] = { 1, 10, 0 };
266  for( Int_t i = 0; chambers[i] > 0; ++i )
267  {
268  AliInfo( Form( "Fixing chamber %i", chambers[i] ) );
269  fAlign->FixChamber( chambers[i] );
270  }
271 
272  } else {
273 
274  AliInfo( "Not fixing detector elements, since alignment is not required" );
275 
276  }
277 
278  // propagate magnetic field flag
282 
283  // initialize
284  fAlign->Init();
285 
286  // Set expected resolution (see AliMUONAlignment)
287  fAlign->SetSigmaXY(0.15,0.10);
288 
289  // initialize global parameters to provided values
291 
292 }
293 
294 //________________________________________________________________________
296 {
297 
298  // connect AOD output
299  if( fWriteRecords )
300  {
301  // get AOD output handler and add Branch
302  AliAODHandler* handler = dynamic_cast<AliAODHandler*>( AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler() );
303  if( handler )
304  {
305 
306  // track params
307  fTrackParams = new TClonesArray( "AliMUONAlignmentTrackParam", 0 );
308  fTrackParams->SetName( "trackParams" );
309  handler->AddBranch("TClonesArray", &fTrackParams);
310 
311  // records
312  fRecords = new TClonesArray( "AliMillePedeRecord", 0 );
313  fRecords->SetName( "records" );
314  handler->AddBranch("TClonesArray", &fRecords);
315 
316  fRecordCount = 0;
317 
318  } else AliFatal( "Error: invalid output event handler" );
319 
320  }
321 
322 }
323 
324 //________________________________________________________________________
326 {
327 
328  // do nothing if run number not in range
329  if( fRunNumberMin > 0 && fCurrentRunNumber < fRunNumberMin ) return;
330  if( fRunNumberMax > 0 && fCurrentRunNumber > fRunNumberMax ) return;
331 
332  // increase event count
333  ++fEvent;
334 
335  // clear array
336  if( fWriteRecords )
337  {
338  if( fTrackParams ) fTrackParams->Clear();
339  if( fRecords ) fRecords->Clear();
340  fRecordCount = 0;
341  }
342 
343  if( fReadRecords )
344  {
345 
346  AliAODEvent* lAOD( dynamic_cast<AliAODEvent*>(InputEvent() ) );
347 
348  // check AOD
349  if( !lAOD )
350  {
351  AliInfo("Error: AOD event not available");
352  return;
353  }
354 
355  // read track parameters
356  TClonesArray* trackParams = static_cast<TClonesArray*>( lAOD->FindListObject( "trackParams" ) );
357  if( !trackParams )
358  {
359  AliInfo( "Unable to read object name \"trackParams\"" );
360  return;
361  }
362 
363  // read records
364  TClonesArray* records = static_cast<TClonesArray*>( lAOD->FindListObject( "records" ) );
365  if( !records )
366  {
367  AliInfo( "Unable to read object name \"records\"" );
368  return;
369  }
370 
371  // get number of records and print
372  const Int_t lRecordsCount( records->GetEntriesFast() );
373  fTrackTot += lRecordsCount;
374 
375  // loop over records
376  for( Int_t index = 0; index < lRecordsCount; ++index )
377  {
378 
379  // read track param
380  AliMUONAlignmentTrackParam* trackParam = 0;
381  if( !( trackParam = dynamic_cast<AliMUONAlignmentTrackParam*>( trackParams->UncheckedAt(index) ) ) )
382  {
383  AliInfo( Form( "Invalid trackParam at %i", index ) );
384  continue;
385  }
386 
387  // apply minPyPz cut
388  const Bool_t pypzOk( fMinPyPz <= 0 || TMath::Sqrt( Square(trackParam->fPy) + Square(trackParam->fPz) ) >= fMinPyPz );
389  if( !pypzOk ) continue;
390 
391  // apply minPt cut
392  const Bool_t ptOk( fMinPt <= 0 || TMath::Sqrt( Square(trackParam->fPx) + Square(trackParam->fPy) ) >= fMinPt );
393  if( !ptOk ) continue;
394 
395  // check number of stations
396  if( fMinStations > 0 && trackParam->GetNStations() < fMinStations )
397  {
398  AliInfo( "Skipping track because no enough stations hit" );
399  continue;
400  }
401 
402  // read record
403  AliMillePedeRecord* record = 0;
404  if( !( record = dynamic_cast<AliMillePedeRecord*>( records->UncheckedAt(index) ) ) )
405  {
406  AliInfo( Form( "Invalid record at %i", index ) );
407  continue;
408  }
409 
410  // process track
411  fAlign->ProcessTrack( record );
412  ++fTrackOk;
413 
414  if(!(fTrackTot%100))
415  { AliInfo( Form( "Processed %i Tracks and %i were fitted.", fTrackTot, fTrackOk ) ); }
416 
417  }
418 
419  } else {
420 
422  AliESDEvent* lESD( dynamic_cast<AliESDEvent*>(InputEvent()) );
423 
424  // check ESD
425  if( !lESD )
426  {
427  AliInfo("Error: ESD event not available");
428  return;
429  }
430 
431  Int_t nTracks = Int_t(lESD->GetNumberOfMuonTracks());
432  for( Int_t iTrack = 0; iTrack < nTracks; iTrack++ )
433  {
434 
435  AliESDMuonTrack* esdTrack = lESD->GetMuonTrack(iTrack);
436  if (!esdTrack->ContainTrackerData()) continue;
437  if (!esdTrack->ContainTriggerData()) continue;
438 
439  // apply minPyPz and pt cut
440  const Bool_t pypzOk( fMinPyPz <= 0 || TMath::Sqrt( Square(esdTrack->Py()) + Square(esdTrack->Pz()) ) >= fMinPyPz );
441  const Bool_t ptOk( fMinPt <= 0 || esdTrack->Pt() >= fMinPt );
442  const Bool_t invBendMomentumOk( TMath::Abs( esdTrack->GetInverseBendingMomentum() ) <= 1.04 );
443  if( pypzOk && ptOk && invBendMomentumOk )
444  {
445 
447  AliMUONESDInterface::ESDToMUON(*esdTrack, track);
448 
449  // process track and retrieve corresponding records, for storage
450  const AliMillePedeRecord* lRecords( fAlign->ProcessTrack( &track, fDoAlignment ) );
451  ++fTrackOk;
452 
453  // store in array
454  if( fWriteRecords )
455  {
456 
457  if( fTrackParams )
458  {
459 
460  // create local track parameters
461  AliMUONAlignmentTrackParam trackParams( esdTrack->Px(), esdTrack->Py(), esdTrack->Pz() );
462 
463  // fill hit pattern
465  AliMUONESDInterface::ESDToMUON(*esdTrack, track);
466  TObjArray* trackParamAtCluster( track.GetTrackParamAtCluster() );
467  for( Int_t iCluster = 0; iCluster < trackParamAtCluster->GetEntries(); ++iCluster )
468  {
469 
470  AliMUONTrackParam* trackParam( (AliMUONTrackParam*) trackParamAtCluster->At(iCluster) );
471  if (!trackParam) continue;
472 
473  // cluster
474  AliMUONVCluster* cluster( trackParam->GetClusterPtr() );
475  if( !cluster ) continue;
476 
477  trackParams.fHitPattern |= (1<<cluster->GetChamberId());
478 
479  }
480 
481  // append to TClonesArray
482  new((*fTrackParams)[fRecordCount]) AliMUONAlignmentTrackParam( trackParams );
483 
484  }
485  if( fRecords ) new((*fRecords)[fRecordCount]) AliMillePedeRecord( *lRecords );
486  ++fRecordCount;
487  }
488 
489  }
490 
491  ++fTrackTot;
492 
493  if(!(fTrackTot%100))
494  { AliInfo( Form( "Processed %i Tracks and %i were fitted.", fTrackTot, fTrackOk ) ); }
495 
496  // Post final data. Write histo list to a file with option "RECREATE"
497  // PostData(1,fList);
498 
499  }
500 
501  // save AOD
502  fRecordsTot += fRecords->GetEntriesFast();
503  if( fWriteRecords && fRecordCount > 0 )
504  {
505  AliAODHandler* handler = dynamic_cast<AliAODHandler*>( AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler() );
506  if( handler )
507  {
508  AliAODEvent* aod = handler->GetAOD();
509  AliAODHeader* header = dynamic_cast<AliAODHeader*>(aod->GetHeader());
510  header->SetRunNumber(lESD->GetRunNumber());
511  AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
512  AliInfo( Form( "Fitted Tracks: %i, records: %i", fTrackOk, fRecordsTot ) );
513 
514  } else AliInfo( "Error: invalid output event handler" );
515 
516  }
517 
518  }
519 
520 }
521 
522 //________________________________________________________________________
524 {
525 
527  AliInfo( Form( "Processed %i tracks.", fTrackTot ) );
528  AliInfo( Form( "Accepted %i tracks.", fTrackOk ) );
529 
530  // terminate output
531  fAlign->Terminate();
532 
533  // stop here if no alignment is to be performed
534  if( !fDoAlignment ) return;
535 
537 
538  // Perform global fit
540 
541  // store misalignments from OCDB into old transformers
542  if( fMergeAlignmentCDBs )
544 
545  // Re Align
547 
548  // Generate realigned data in local cdb
549  const TClonesArray* array = fNewGeoTransformer->GetMisAlignmentData();
550 
551  // 100 mum residual resolution for chamber misalignments?
552  fAlign->SetAlignmentResolution( array, -1, 0.01, 0.01, 0.004, 0.003 );
553 
554  // CDB manager
556 
557  // recover default storage full name (raw:// cannot be used to set specific storage)
558  AliCDBManager* cdbManager = AliCDBManager::Instance();
559 
560  // unload old alignment path
561  if( cdbManager->GetEntryCache()->Contains("MUON/Align/Data") )
562  { cdbManager->UnloadFromCache("MUON/Align/Data"); }
563 
564  // load new alignment path
565  if( !fNewAlignStorage.IsNull() ) cdbManager->SetSpecificStorage("MUON/Align/Data",fNewAlignStorage.Data());
566  else {
567 
568  TString defaultStorage(cdbManager->GetDefaultStorage()->GetType());
569  if (defaultStorage == "alien") defaultStorage += Form("://folder=%s", cdbManager->GetDefaultStorage()->GetBaseFolder().Data());
570  else defaultStorage += Form("://%s", cdbManager->GetDefaultStorage()->GetBaseFolder().Data());
571  cdbManager->SetSpecificStorage("MUON/Align/Data",defaultStorage.Data());
572 
573  }
574 
575  // create new DB entry
576  AliCDBMetaData* cdbData = new AliCDBMetaData();
577  cdbData->SetResponsible("Dimuon Offline project");
578  cdbData->SetComment("MUON alignment objects with residual misalignment");
579  AliCDBId id("MUON/Align/Data", fRunNumberMin, fRunNumberMax );
580  cdbManager->Put(const_cast<TClonesArray*>(array), id, cdbData);
581 
582 }
583 
584 //________________________________________________________________________
586 {
587 
589 
590  // propagate run number to fAlign
591  if( fAlign ) fAlign->SetRunNumber( fCurrentRunNumber );
592 
593  // update ocdb
594  if (fOCDBLoaded && fLoadOCDBOnce)
595  {
596  AliError(Form("OCDB already loaded %d %d",fOCDBLoaded,fLoadOCDBOnce));
597  return;
598  }
599 
600  AliCDBManager* cdbManager = AliCDBManager::Instance();
601 
602  // Initialize default storage
603  if( !( cdbManager->IsDefaultStorageSet() || fDefaultStorage.IsNull() ) )
604  {
605 
606  AliInfo( Form( "Initializing default storage: %s", fDefaultStorage.Data() ) );
607  cdbManager->SetDefaultStorage(fDefaultStorage.Data());
608 
609  } else if( !fDefaultStorage.IsNull() ) {
610 
611  AliInfo( "Default storage already set. Ignoring fDefaultStorage" );
612 
613  } else {
614 
615  AliInfo( "Default storage already set" );
616 
617  }
618 
619  // Initialize run number
620  if( cdbManager->GetRun() < 0 )
621  {
622  AliInfo( Form( "Setting run number: %i", fCurrentRunNumber ) );
623  cdbManager->SetRun(fCurrentRunNumber);
624  }
625 
626  // following initialization is not needed when reading records
627  if( !fReadRecords )
628  {
629 
630  // load magnetic field if needed
631  if( !TGeoGlobalMagField::Instance()->IsLocked() )
632  {
633 
634  AliInfo( "Loading magnetic field" );
635  if( !AliMUONCDB::LoadField() )
636  {
637  AliError( "Failed to load magnetic field" );
638  return;
639  }
640 
641  } else { AliInfo( "Magnetic field already locked" ); }
642 
643  // checking magnitic field
644  if( !fForceBField )
645  {
646  AliInfo( "Reading magnetic field setup from GRP" );
647 
648  // decide bFieldOn value base on dipole current
649  // propagete to Alignment class
650  // and printout
651  AliMagF* magF = dynamic_cast<AliMagF*>( TGeoGlobalMagField::Instance()->GetField() );
652  fBFieldOn = TMath::Abs( magF->GetFactorDip() ) > 1e-5;
654  AliInfo( Form( "Dipole magnetic field factor: %.2f", magF->GetFactorDip() ) );
655  AliInfo( Form( "fBFieldOn = %s", (fBFieldOn ? "kTRUE":"kFALSE") ) );
656  }
657 
658  AliInfo( "Loading muon mapping" );
659  if( !AliMUONCDB::LoadMapping(kFALSE) )
660  {
661  AliError( "Failed to load muon mapping" );
662  return;
663  }
664 
665  AliInfo( "Assigning field to Track extrapolator" );
667 
668  }
669 
670  // load geometry if needed
672  {
673 
674  // reset existing geometry/alignment if any
675  if( cdbManager->GetEntryCache()->Contains("GRP/Geometry/Data") )
676  {
677  AliInfo( "Unloading GRP/Geometry/Data" );
678  cdbManager->UnloadFromCache("GRP/Geometry/Data");
679  }
680 
681  if( cdbManager->GetEntryCache()->Contains("MUON/Align/Data") )
682  {
683  AliInfo( Form( "Unloading MUON/Align/Data from %s", cdbManager->GetSpecificStorage( "MUON/Align/Data" )->GetBaseFolder().Data() ) );
684  cdbManager->UnloadFromCache("MUON/Align/Data");
685  }
686 
687  // get original geometry transformer
688  AliInfo( "Loading geometry" );
691  {
692  AliError("Failed to load geometry");
693  return;
694  }
695 
696  if (!fOldAlignStorage.IsNull())
697  {
698 
699  AliInfo( Form( "Initializing MUON/Align/Data using: %s", fOldAlignStorage.Data() ) );
700  cdbManager->SetSpecificStorage("MUON/Align/Data",fOldAlignStorage.Data());
701 
702  } else {
703 
704  // recover default storage full name (raw:// cannot be used to set specific storage)
705  TString defaultStorage(cdbManager->GetDefaultStorage()->GetType());
706  if (defaultStorage == "alien") defaultStorage += Form("://folder=%s", cdbManager->GetDefaultStorage()->GetBaseFolder().Data());
707  else defaultStorage += Form("://%s", cdbManager->GetDefaultStorage()->GetBaseFolder().Data());
708 
709  AliInfo( Form( "Re-initializing MUON/Align/Data using: %s", defaultStorage.Data() ) );
710  cdbManager->SetSpecificStorage("MUON/Align/Data",defaultStorage.Data());
711 
712  }
713 
714  AliInfo("Loading muon Alignment objects");
716 
717  } else { AliInfo( "Geometry already initialized - fOldAlignStorage ignored" ); }
718 
719  // update geometry transformer and pass to Alignment object
720  AliInfo("Loading muon geometry in transformer");
723 
724  fOCDBLoaded = kTRUE;
725 
726 }
727 
728 //_____________________________________________________________________________________
730 {
731 
732  // clear transformer
733  transformer->ClearMisAlignmentData();
734 
735  // load MUON/Align/Data from OCDB
736  AliCDBManager* cdbManager = AliCDBManager::Instance();
737  AliCDBEntry* cdbEntry = cdbManager->Get( "MUON/Align/Data" );
738  if (!cdbEntry)
739  {
740 
741  AliError( "unable to load entry for path MUON/Align/Data" );
742  return;
743 
744  }
745 
746  // get TClonesArray and check
747  TClonesArray* misArray = (TClonesArray*)cdbEntry->GetObject();
748  if( !misArray )
749  {
750 
751  AliError( "unable to load old misalignment array" );
752  return;
753 
754  }
755 
756  // loop over stored entries
757  for (Int_t index=0; index<misArray->GetEntriesFast(); ++index )
758  {
759 
760  // load matrix and check
761  AliAlignObjMatrix* matrix = (AliAlignObjMatrix*) misArray->At( index );
762  if( !matrix )
763  {
764  AliError( Form( "unable to load matrix for index %i", index ) );
765  continue;
766  }
767 
768  // get volume ID
769  AliGeomManager::ELayerID layerId;
770  Int_t moduleId;
771  matrix->GetVolUID( layerId, moduleId);
772 
773  AliInfo( Form( "layer: %i, module: %i name: %s", layerId, moduleId, matrix->GetSymName() ) );
774 
775  // make sure ELayerID is correct
776  assert( layerId == AliGeomManager::kMUON );
777 
778  // printout
779  // AliInfo( Form( "Found matrix for %s %i", matrix->GetSymName(), moduleId ) );
780 
781  // get matrix
782  TGeoHMatrix misMatrix;
783  matrix->GetMatrix(misMatrix);
784 
785  // add to geometry transformer
786  // need the detector element
787  // "detElement->GetId()"
788  // see fOldGeoTransformer->GetMisAlignmentData( ... )
789 
790  if( TString( matrix->GetSymName() ).Contains( "DE" ) ) transformer->AddMisAlignDetElement( moduleId, misMatrix);
791  else transformer->AddMisAlignModule( moduleId, misMatrix);
792  }
793 
794  return;
795 }
796 
Class for alignment of muon spectrometer.
void SetDoEvaluation(Bool_t value)
set to true to do refit evaluation
void InitGlobalParameters(Double_t *par)
initialize global parameters to a give set of values
AliMUONAlignment * fAlign
The MUON alignment object.
Double_t fParameters[AliMUONAlignment::fNGlobal]
Array of alignment parameters.
Int_t fTrackTot
Total number of track read.
static void ESDToMUON(const AliESDMuonTrack &esdTrack, AliMUONTrack &track, Bool_t refit=kTRUE)
Bool_t fDoEvaluation
Flag for running refit evaluation.
Task to align the muon spectrometer.
Bool_t fOCDBLoaded
set to true when OCDB was loaded at least once
Bool_t fLoadOCDBOnce
set to true if not willing to re-initialize OCDB at every new run
virtual void UserExec(Option_t *)
per-event method
Int_t GetRun() const
AliESDMuonTrack * GetMuonTrack(Int_t i)
AliCDBStorage * GetSpecificStorage(const char *calibType)
Bool_t fForceBField
true if magnetic field was forced to value, instead of reading from GRP
static void SetGlobalLogLevel(EType_t type)
Definition: AliLog.cxx:447
Bool_t LoadGeometryData(const TString &fileName)
Class to describe the MUON tracks in the Event Summary Data class.
#define TObjArray
Top container class for geometry transformations.
const TString & GetType() const
Definition: AliCDBStorage.h:35
static Bool_t ApplyAlignObjsFromCDB(const char *AlDetsList)
const TString & GetBaseFolder() const
Definition: AliCDBStorage.h:36
Double_t fPulls[AliMUONAlignment::fNGlobal]
Array of alignment parameters pulls.
void SetComment(const char *comment)
AliMUONGeometryTransformer * fNewGeoTransformer
new geometry transformer containing the new alignment to be applied
Track parameters in ALICE dimuon spectrometer.
AliVHeader * GetHeader() const
Definition: AliAODEvent.h:91
void SetResponsible(const char *yourName)
AliTPCfastTrack * track
Double_t Py() const
TClonesArray * fRecords
list of track records
Bool_t LoadMapping(Bool_t segmentationOnly)
Definition: AliMUONCDB.cxx:502
void SetBFieldOn(Bool_t value)
Set flag for Magnetic field On/Off.
void AddMisAlignDetElement(Int_t detElemId, const TGeoHMatrix &matrix, Bool_t bGlobal=kTRUE)
Bool_t ContainTrackerData() const
virtual void GetMatrix(TGeoHMatrix &m) const
void SetRunNumber(Int_t id)
run number
Bool_t LoadField()
Definition: AliMUONCDB.cxx:478
TObjArray * array
Definition: AnalyzeLaser.C:12
AliCDBEntry * Get(const AliCDBId &query, Bool_t forceCaching=kFALSE)
Double_t GetFactorDip() const
Definition: AliMagF.cxx:539
Double_t fErrors[AliMUONAlignment::fNGlobal]
Array of alignment parameters errors.
const TClonesArray * GetMisAlignmentData() const
Return the array of misalignment data.
TObject * GetObject()
Definition: AliCDBEntry.h:56
Int_t fMinStations
track min number of stations
Int_t fEvent
event number (internal counter)
abstract base class for clusters
AliMUONGeometryTransformer * fOldGeoTransformer
geometry transformer used to recontruct the present data
void GlobalFit(Double_t *parameters, Double_t *errors, Double_t *pulls)
perform global fit
void SetSpecificStorage(const char *calibType, const char *dbString, Int_t version=-1, Int_t subVersion=-1)
Bool_t fReadRecords
perform alignment from alignment records is true. Use ESD tracks otherwise
Int_t GetNumberOfMuonTracks() const
Definition: AliESDEvent.h:543
void SetRunNumber(Int_t nRun)
Definition: AliAODHeader.h:133
const TMap * GetEntryCache() const
Bool_t fDoAlignment
perform alignment (from either tracks or records depending on fReadRecords)
Int_t fRecordCount
number of records
Bool_t fWriteRecords
write alignment records to AOD if true
Double_t GetInverseBendingMomentum(void) const
#define AliInfo(message)
Definition: AliLog.h:484
Int_t GetRunNumber() const
Definition: AliESDEvent.h:141
Int_t fRunNumberMin
run range
AliMillePedeRecord * ProcessTrack(AliMUONTrack *track, Bool_t doAlignment, Double_t weight=1)
TObject * FindListObject(const char *objName) const
Double_t fMinPt
track momentum cut
TString fNewAlignStorage
location of the OCDB storage where to put new MUON/Align/Data (use the default one if empty) ...
Bool_t fMergeAlignmentCDBs
merge old and new Align CDBs into the new one.
Number of global parameters.
void SetDoAlignment(Bool_t value)
perform alignment (from either tracks or records depending on fReadRecords)
Bool_t Put(TObject *object, const AliCDBId &id, AliCDBMetaData *metaData, const char *mirrors="", DataType type=kPrivate)
Int_t fRecordsTot
Number of records (should match fTrackOk)
void AddMisAlignModule(Int_t moduleId, const TGeoHMatrix &matrix, Bool_t bGlobal=kTRUE)
AliMUONGeometryTransformer * ReAlign(const AliMUONGeometryTransformer *transformer, const double *misAlignments, Bool_t verbose)
void SetRun(Int_t run)
Bool_t fBFieldOn
Flag for Magnetic field On/Off.
Int_t GetNStations(void) const
return number of stations hit
Definition: AliCDBEntry.h:18
#define AliFatal(message)
Definition: AliLog.h:640
Int_t fTrackOk
Number of tracks used for alignment.
Double_t fMinPyPz
track momentum cut
void SetDefaultStorage(const char *dbString)
void UnloadFromCache(const char *path)
Double_t Square(Double_t x)
TString fOldAlignStorage
location of the OCDB storage where to find old MUON/Align/Data (use the default one if empty) ...
void SetSigmaXY(Double_t sigmaX, Double_t sigmaY)
virtual void UserCreateOutputObjects()
output data
AliAODEvent * GetAOD()
Definition: AliAODHandler.h:72
void SetAlignmentResolution(const TClonesArray *misAlignArray, Int_t chId, Double_t chResX, Double_t chResY, Double_t deResX, Double_t deResY)
virtual void FinishTaskOutput()
end of task execution
void FixChamber(Int_t iCh, UInt_t parameterMask=ParAll)
void AddBranch(const char *cname, void *addobj, const char *fname="")
static void SetGlobalDebugLevel(Int_t level)
Definition: AliLog.cxx:466
AliMUONAlignmentTask(const char *name="AliMUONAlignmentTask")
constructor
Double_t Px() const
AliCDBStorage * GetDefaultStorage() const
Definition: AliCDBManager.h:61
const char * GetSymName() const
Definition: AliAlignObj.h:63
UShort_t GetVolUID() const
Definition: AliAlignObj.h:64
Bool_t ContainTriggerData() const
Reconstructed track in ALICE dimuon spectrometer.
Definition: AliMUONTrack.h:24
#define AliError(message)
Definition: AliLog.h:591
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
Bool_t fRefitStraightTracks
Flag for refitting straight tracks.
Bool_t IsDefaultStorageSet() const
Definition: AliCDBManager.h:60
void SaveMisAlignmentData(AliMUONGeometryTransformer *) const
store misalignment matrices from OCDB into geometry transformer
static TGeoManager * GetGeometry()
void SetRefitStraightTracks(Bool_t value)
set to true to refit tracks
TString fDefaultStorage
location of the default OCDB storage
static void LoadGeometry(const char *geomFileName=NULL)
TClonesArray * fTrackParams
list of track parameters
virtual ~AliMUONAlignmentTask()
destructor
void SetGeometryTransformer(AliMUONGeometryTransformer *transformer)
Set geometry transformer.
Double_t Pz() const