]>
Commit | Line | Data |
---|---|---|
6ea93b32 | 1 | // $Id$ |
2 | // | |
3 | // Task to setup emcal related global objects | |
4 | // | |
5 | // | |
6 | ||
7 | #include <TClonesArray.h> | |
8 | #include <TGeoManager.h> | |
9 | #include <TGeoGlobalMagField.h> | |
10 | #include "AliAnalysisManager.h" | |
11 | #include "AliCDBManager.h" | |
12 | #include "AliEMCALGeometry.h" | |
13 | #include "AliESDEvent.h" | |
14 | #include "AliEmcalSetupTask.h" | |
15 | #include "AliGeomManager.h" | |
16 | #include "AliOADBContainer.h" | |
17 | ||
18 | ClassImp(AliEmcalSetupTask) | |
19 | ||
20 | //________________________________________________________________________ | |
21 | AliEmcalSetupTask::AliEmcalSetupTask() : | |
22 | AliAnalysisTaskSE(), | |
23 | fOcdbPath(), | |
24 | fOadbPath("$ALICE_ROOT/OADB/EMCAL"), | |
277be17b | 25 | fGeoPath("."), |
6ea93b32 | 26 | fEsdEv(0), |
27 | fIsInit(kFALSE) | |
28 | { | |
29 | // Constructor. | |
30 | } | |
31 | ||
32 | //________________________________________________________________________ | |
33 | AliEmcalSetupTask::AliEmcalSetupTask(const char *name) : | |
34 | AliAnalysisTaskSE(name), | |
35 | fOcdbPath(), | |
36 | fOadbPath("$ALICE_ROOT/OADB/EMCAL"), | |
277be17b | 37 | fGeoPath("."), |
6ea93b32 | 38 | fEsdEv(0), |
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 | fEsdEv = dynamic_cast<AliESDEvent*>(InputEvent()); | |
60 | if (!fEsdEv) { | |
61 | AliError("Task works only on ESD events, returning"); | |
62 | return; | |
63 | } | |
64 | ||
65 | AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager(); | |
66 | if (!am) { | |
67 | AliError("Manager zero, returning"); | |
68 | return; | |
69 | } | |
70 | am->LoadBranch("AliESDRun."); | |
71 | am->LoadBranch("AliESDHeader."); | |
72 | ||
73 | Int_t runno = fEsdEv->GetRunNumber(); | |
64a8dac7 | 74 | TString geoname("EMCAL_FIRSTYEARV1"); |
75 | Int_t year = 2010; | |
6ea93b32 | 76 | if (runno>139517) { |
64a8dac7 | 77 | year = 2011; |
78 | geoname = "EMCAL_COMPLETEV1"; | |
79 | } if (runno>170593) { | |
80 | year = 2012; | |
81 | geoname = "EMCAL_COMPLETE12SM"; | |
6ea93b32 | 82 | } |
83 | ||
6ea93b32 | 84 | AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance(geoname); |
85 | if (!geom) { | |
86 | AliFatal(Form("Can not create geometry: %s",geoname.Data())); | |
87 | return; | |
88 | } | |
89 | ||
90 | AliCDBManager *man = 0; | |
91 | if (fOcdbPath.Length()>0) { | |
92 | AliInfo(Form("Setting up OCDB")); | |
93 | man = AliCDBManager::Instance(); | |
94 | man->SetDefaultStorage(fOcdbPath); | |
95 | man->SetRun(runno); | |
96 | } | |
97 | ||
98 | TGeoManager *geo = AliGeomManager::GetGeometry(); | |
99 | if (!geo) { | |
64a8dac7 | 100 | TString fname(gSystem->ExpandPathName(Form("%s/geometry_%d.root", fGeoPath.Data(), year))); |
6ea93b32 | 101 | if (gSystem->AccessPathName(fname)==0) { |
102 | AliInfo(Form("Loading geometry from %s", fname.Data())); | |
103 | AliGeomManager::LoadGeometry(fname); | |
104 | } else if (man) { | |
105 | AliInfo(Form("Loading geometry from OCDB")); | |
106 | AliGeomManager::LoadGeometry(); | |
107 | } | |
108 | } | |
109 | if (geo) { | |
110 | AliGeomManager::ApplyAlignObjsFromCDB("EMCAL"); | |
111 | AliInfo(Form("Locking geometry")); | |
112 | geo->LockGeometry(); | |
113 | } | |
114 | ||
115 | if (!TGeoGlobalMagField::Instance()->GetField()) { // construct field map | |
116 | AliInfo("Constructing field map from ESD run info"); | |
117 | fEsdEv->InitMagneticField(); | |
118 | } | |
119 | ||
120 | if (fOadbPath.Length()>0) { | |
121 | AliOADBContainer emcalgeoCont(Form("emcal")); | |
122 | emcalgeoCont.InitFromFile(Form("%s/EMCALlocal2master.root",fOadbPath.Data()), | |
123 | Form("AliEMCALgeo")); | |
124 | TObjArray *mobj=dynamic_cast<TObjArray*>(emcalgeoCont.GetObject(runno,"EmcalMatrices")); | |
125 | if (mobj) { | |
126 | for(Int_t mod=0; mod < (geom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){ | |
127 | //AliInfo(Form("Misalignment matrix %d", mod)); | |
128 | geom->SetMisalMatrix((TGeoHMatrix*) mobj->At(mod),mod); | |
129 | } | |
130 | } | |
131 | } | |
132 | ||
133 | fIsInit = kTRUE; | |
134 | } |