]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/EMCALTasks/AliEmcalSetupTask.cxx
CreateCTTMMatrix call: moved from CreateLTMMatrixFromDigits to CreateLTMMatrix (F...
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliEmcalSetupTask.cxx
CommitLineData
6ea93b32 1// $Id$
2//
980821ba 3// Task to setup emcal related global objects.
6ea93b32 4//
cd231d42 5// Author: C.Loizides
6ea93b32 6
7#include <TClonesArray.h>
6ea93b32 8#include <TGeoGlobalMagField.h>
dec5f256 9#include <TGeoManager.h>
10#include "AliAODEvent.h"
6ea93b32 11#include "AliAnalysisManager.h"
12#include "AliCDBManager.h"
13#include "AliEMCALGeometry.h"
14#include "AliESDEvent.h"
15#include "AliEmcalSetupTask.h"
16#include "AliGeomManager.h"
dec5f256 17#include "AliMagF.h"
6ea93b32 18#include "AliOADBContainer.h"
19
20ClassImp(AliEmcalSetupTask)
21
22//________________________________________________________________________
23AliEmcalSetupTask::AliEmcalSetupTask() :
24 AliAnalysisTaskSE(),
25 fOcdbPath(),
26 fOadbPath("$ALICE_ROOT/OADB/EMCAL"),
277be17b 27 fGeoPath("."),
6ea93b32 28 fIsInit(kFALSE)
29{
30 // Constructor.
31}
32
33//________________________________________________________________________
34AliEmcalSetupTask::AliEmcalSetupTask(const char *name) :
35 AliAnalysisTaskSE(name),
36 fOcdbPath(),
37 fOadbPath("$ALICE_ROOT/OADB/EMCAL"),
277be17b 38 fGeoPath("."),
6ea93b32 39 fIsInit(kFALSE)
40{
41 // Constructor.
42 fBranchNames = "ESD:AliESDHeader.,AliESDRun.";
43}
44
45//________________________________________________________________________
46AliEmcalSetupTask::~AliEmcalSetupTask()
47{
48 // Destructor.
49}
50
51//________________________________________________________________________
52void AliEmcalSetupTask::UserExec(Option_t *)
53{
54 // Main loop, called for each event.
55
56 if (fIsInit)
57 return;
58
6ea93b32 59 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
60 if (!am) {
61 AliError("Manager zero, returning");
62 return;
63 }
64 am->LoadBranch("AliESDRun.");
65 am->LoadBranch("AliESDHeader.");
66
dec5f256 67 Int_t runno = InputEvent()->GetRunNumber();
64a8dac7 68 TString geoname("EMCAL_FIRSTYEARV1");
69 Int_t year = 2010;
6ea93b32 70 if (runno>139517) {
64a8dac7 71 year = 2011;
72 geoname = "EMCAL_COMPLETEV1";
dec5f256 73 }
74 if (runno>170593) {
64a8dac7 75 year = 2012;
dec5f256 76 geoname = "EMCAL_COMPLETE12SMV1";
6ea93b32 77 }
78
6ea93b32 79 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance(geoname);
80 if (!geom) {
81 AliFatal(Form("Can not create geometry: %s",geoname.Data()));
82 return;
83 }
84
85 AliCDBManager *man = 0;
86 if (fOcdbPath.Length()>0) {
87 AliInfo(Form("Setting up OCDB"));
88 man = AliCDBManager::Instance();
89 man->SetDefaultStorage(fOcdbPath);
90 man->SetRun(runno);
91 }
92
93 TGeoManager *geo = AliGeomManager::GetGeometry();
94 if (!geo) {
64a8dac7 95 TString fname(gSystem->ExpandPathName(Form("%s/geometry_%d.root", fGeoPath.Data(), year)));
6ea93b32 96 if (gSystem->AccessPathName(fname)==0) {
97 AliInfo(Form("Loading geometry from %s", fname.Data()));
98 AliGeomManager::LoadGeometry(fname);
99 } else if (man) {
100 AliInfo(Form("Loading geometry from OCDB"));
101 AliGeomManager::LoadGeometry();
102 }
103 }
104 if (geo) {
105 AliGeomManager::ApplyAlignObjsFromCDB("EMCAL");
106 AliInfo(Form("Locking geometry"));
107 geo->LockGeometry();
108 }
109
110 if (!TGeoGlobalMagField::Instance()->GetField()) { // construct field map
dec5f256 111 AliESDEvent *esdEv = dynamic_cast<AliESDEvent*>(InputEvent());
112 if (esdEv) {
113 AliInfo("Constructing field map from ESD run info");
114 esdEv->InitMagneticField();
115 } else {
116 AliAODEvent *aodEv = dynamic_cast<AliAODEvent*>(InputEvent());
117 Double_t curSol = 30000*aodEv->GetMagneticField()/5.00668;
118 Double_t curDip = 6000 *aodEv->GetMuonMagFieldScale();
119 AliMagF *field = AliMagF::CreateFieldMap(curSol,curDip);
120 TGeoGlobalMagField::Instance()->SetField(field);
121 }
6ea93b32 122 }
123
124 if (fOadbPath.Length()>0) {
125 AliOADBContainer emcalgeoCont(Form("emcal"));
126 emcalgeoCont.InitFromFile(Form("%s/EMCALlocal2master.root",fOadbPath.Data()),
127 Form("AliEMCALgeo"));
128 TObjArray *mobj=dynamic_cast<TObjArray*>(emcalgeoCont.GetObject(runno,"EmcalMatrices"));
129 if (mobj) {
130 for(Int_t mod=0; mod < (geom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
131 //AliInfo(Form("Misalignment matrix %d", mod));
132 geom->SetMisalMatrix((TGeoHMatrix*) mobj->At(mod),mod);
133 }
134 }
135 }
136
137 fIsInit = kTRUE;
138}