]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliEmcalSetupTask.cxx
Add track propagation (Marta)
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliEmcalSetupTask.cxx
1 // $Id$
2 //
3 // Task to setup emcal related global objects.
4 //
5 // Author: C.Loizides
6
7 #include "AliEmcalSetupTask.h"
8 #include <TClonesArray.h>
9 #include <TGeoGlobalMagField.h>
10 #include <TGeoManager.h>
11 #include "AliAODEvent.h"
12 #include "AliAnalysisManager.h"
13 #include "AliCDBManager.h"
14 #include "AliEMCALGeometry.h"
15 #include "AliESDEvent.h"
16 #include "AliGeomManager.h"
17 #include "AliMagF.h"
18 #include "AliOADBContainer.h"
19
20 ClassImp(AliEmcalSetupTask)
21
22 //________________________________________________________________________
23 AliEmcalSetupTask::AliEmcalSetupTask() : 
24   AliAnalysisTaskSE(),
25   fOcdbPath(),
26   fOadbPath("$ALICE_ROOT/OADB/EMCAL"),
27   fGeoPath("."),
28   fIsInit(kFALSE)
29 {
30   // Constructor.
31 }
32
33 //________________________________________________________________________
34 AliEmcalSetupTask::AliEmcalSetupTask(const char *name) : 
35   AliAnalysisTaskSE(name),
36   fOcdbPath(),
37   fOadbPath("$ALICE_ROOT/OADB/EMCAL"),
38   fGeoPath("$ALICE_ROOT/OADB/EMCAL"),
39   fIsInit(kFALSE)
40 {
41   // Constructor.
42   fBranchNames = "ESD:AliESDHeader.,AliESDRun.";
43 }
44
45 //________________________________________________________________________
46 AliEmcalSetupTask::~AliEmcalSetupTask()
47 {
48   // Destructor.
49 }
50
51 //________________________________________________________________________
52 void AliEmcalSetupTask::UserExec(Option_t *) 
53 {
54   // Main loop, called for each event.
55
56   if (fIsInit)
57     return;
58
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
67   Int_t runno = InputEvent()->GetRunNumber();
68   TString geoname("EMCAL_COMPLETE12SMV1");
69   Int_t year = 2013;
70   if (runno<=139517) {
71     year = 2010;
72     geoname = "EMCAL_FIRSTYEARV1";
73   } else if ((runno>139517) && (runno<=170593)) {
74     year = 2011;
75     geoname = "EMCAL_COMPLETEV1";
76   } else if ((runno>170593) && (runno<=193766)) {
77     year = 2012;
78   }
79
80   AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance(geoname);
81   if (!geom) {
82     AliFatal(Form("Can not create geometry: %s",geoname.Data()));
83     return;
84   }
85
86   AliCDBManager *man = 0;
87   if (fOcdbPath.Length()>0) {
88     AliInfo(Form("Setting up OCDB"));
89     man = AliCDBManager::Instance();
90     if (!man->IsDefaultStorageSet())
91       man->SetDefaultStorage(fOcdbPath);
92     if (man->GetRun()!=runno)
93       man->SetRun(runno);
94   }
95
96   TGeoManager *geo = AliGeomManager::GetGeometry();
97   if (!geo) {
98     TString fname(gSystem->ExpandPathName(Form("%s/geometry_%d.root", fGeoPath.Data(), year)));
99     if (gSystem->AccessPathName(fname)==0) {
100       AliInfo(Form("Loading geometry from %s", fname.Data()));
101       AliGeomManager::LoadGeometry(fname);
102       geo = AliGeomManager::GetGeometry();
103     } else if (man) {
104       AliInfo(Form("Loading geometry from OCDB"));
105       AliGeomManager::LoadGeometry();
106       AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC TRD EMCAL");
107       geo = AliGeomManager::GetGeometry();
108     }
109     if (geo) {
110       AliInfo(Form("Locking geometry"));
111       geo->LockGeometry();
112     }
113   }
114
115   if (!TGeoGlobalMagField::Instance()->GetField()) { // construct field map
116     InputEvent()->InitMagneticField();
117   }
118
119   if (fOadbPath.Length()>0) {
120     AliOADBContainer emcalgeoCont(Form("emcal"));
121     emcalgeoCont.InitFromFile(Form("%s/EMCALlocal2master.root",fOadbPath.Data()),
122                               Form("AliEMCALgeo"));
123     TObjArray *mobj=dynamic_cast<TObjArray*>(emcalgeoCont.GetObject(runno,"EmcalMatrices"));
124     if (mobj) {
125       for(Int_t mod=0; mod < (geom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
126         //AliInfo(Form("Misalignment matrix %d", mod));
127         geom->SetMisalMatrix((TGeoHMatrix*) mobj->At(mod),mod);
128       } 
129     }
130   }
131
132   fIsInit = kTRUE;
133 }