3 // Task to setup emcal related global objects.
7 #include "AliEmcalSetupTask.h"
8 #include <TClonesArray.h>
9 #include <TGeoGlobalMagField.h>
10 #include <TGeoManager.h>
12 #include "AliAODEvent.h"
13 #include "AliAnalysisManager.h"
14 #include "AliCDBManager.h"
15 #include "AliEMCALGeometry.h"
16 #include "AliESDEvent.h"
17 #include "AliGRPManager.h"
18 #include "AliGeomManager.h"
20 #include "AliOADBContainer.h"
22 ClassImp(AliEmcalSetupTask)
24 //________________________________________________________________________
25 AliEmcalSetupTask::AliEmcalSetupTask() :
27 fOcdbPath("uselocal"),
28 fOadbPath("$ALICE_ROOT/OADB/EMCAL"),
29 fGeoPath("$ALICE_ROOT/OADB/EMCAL"),
30 fObjs("GRP ITS TPC TRD EMCAL"),
37 //________________________________________________________________________
38 AliEmcalSetupTask::AliEmcalSetupTask(const char *name) :
39 AliAnalysisTaskSE(name),
40 fOcdbPath("uselocal"),
41 fOadbPath("$ALICE_ROOT/OADB/EMCAL"),
42 fGeoPath("$ALICE_ROOT/OADB/EMCAL"),
43 fObjs("GRP ITS TPC TRD EMCAL"),
48 fBranchNames = "ESD:AliESDHeader.,AliESDRun.";
51 //________________________________________________________________________
52 AliEmcalSetupTask::~AliEmcalSetupTask()
57 //________________________________________________________________________
58 void AliEmcalSetupTask::UserExec(Option_t *)
60 // Main loop, called for each event.
65 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
67 AliError("Manager zero, returning");
71 am->LoadBranch("AliESDRun.");
72 am->LoadBranch("AliESDHeader.");
74 // Setup AliEMCALGeometry corresponding to year
75 Int_t runno = InputEvent()->GetRunNumber();
76 TString geoname("EMCAL_COMPLETE12SMV1");
80 geoname = "EMCAL_FIRSTYEARV1";
81 } else if ((runno>139517) && (runno<=170593)) {
83 geoname = "EMCAL_COMPLETEV1";
84 } else if ((runno>170593) && (runno<=193766)) {
87 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance(geoname);
89 AliFatal(Form("Can not create geometry: %s",geoname.Data()));
94 AliCDBManager *man = 0;
95 man = AliCDBManager::Instance();
96 if (man->IsDefaultStorageSet()) {
97 AliInfo(Form("Default OCDB storage already set"));
99 if (fOcdbPath.Length()==0) {
100 man = 0; // do not use OCDB
101 } else if (fOcdbPath != "uselocal") {
102 AliInfo(Form("Setting up OCDB to point to %s",fOcdbPath.Data()));
103 man->SetDefaultStorage(fOcdbPath);
104 } else { // use local copy of OCDB
105 TString tmpdir=gSystem->WorkingDirectory();
106 if (gSystem->AccessPathName(tmpdir))
109 tmpdir+=gSystem->GetUid();
116 fLocalOcdb += Form("%d%d%d%",gRandom->Integer(999999999),gRandom->Integer(999999999),gRandom->Integer(999999999));
117 while (!gSystem->AccessPathName(fLocalOcdb)) {
119 fLocalOcdb += Form("%d%d%d%",gRandom->Integer(999999999),gRandom->Integer(999999999),gRandom->Integer(999999999));
122 AliFatal(Form("Could not create local directory for OCDB at %s",tmpdir.Data()));
125 gSystem->MakeDirectory(fLocalOcdb);
126 TString filename(Form("$ALICE_ROOT/PWG/EMCAL/data/%d.dat",year));
127 TString cmd(Form("cd %s && tar -xf %s",fLocalOcdb.Data(),filename.Data()));
128 Int_t ret = gSystem->Exec(cmd);
130 TString locdb("local://");
134 AliInfo(Form("Setting up local OCDB at %s",locdb.Data()));
135 man->SetDefaultStorage(locdb);
137 AliFatal(Form("Could not set up local OCDB at %s",fLocalOcdb.Data()));
142 // Load geometry from OCDB
144 if (man->GetRun()!=runno)
146 AliInfo(Form("Loading grp data from OCDB for run %d", runno));
147 AliGRPManager GRPManager;
148 GRPManager.ReadGRPEntry();
149 GRPManager.SetMagField();
150 AliInfo(Form("Loading geometry from OCDB"));
151 AliGeomManager::LoadGeometry();
153 AliGeomManager::ApplyAlignObjsFromCDB(fObjs);
156 // Load geometry from file (does not use misalignment of ITS/TPC!)
157 TGeoManager *geo = AliGeomManager::GetGeometry();
158 if (!geo && fGeoPath.Length()>0) {
159 TString fname(gSystem->ExpandPathName(Form("%s/geometry_%d.root", fGeoPath.Data(), year)));
160 if (gSystem->AccessPathName(fname)==0) {
161 AliInfo(Form("Loading geometry from file %s (should be avoided!)", fname.Data()));
162 AliGeomManager::LoadGeometry(fname);
163 geo = AliGeomManager::GetGeometry();
169 AliInfo(Form("Locking geometry"));
173 // Construct field map
174 if (!TGeoGlobalMagField::Instance()->GetField()) {
175 InputEvent()->InitMagneticField();
178 // Apply mis-alignment matrices from OADB
179 if (fOadbPath.Length()>0) {
180 AliOADBContainer emcalgeoCont(Form("emcal"));
181 emcalgeoCont.InitFromFile(Form("%s/EMCALlocal2master.root",fOadbPath.Data()),
182 Form("AliEMCALgeo"));
183 TObjArray *mobj=dynamic_cast<TObjArray*>(emcalgeoCont.GetObject(runno,"EmcalMatrices"));
185 for(Int_t mod=0; mod < (geom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
186 //AliInfo(Form("Misalignment matrix %d", mod));
187 geom->SetMisalMatrix((TGeoHMatrix*) mobj->At(mod),mod);
195 //________________________________________________________________________
196 void AliEmcalSetupTask::Terminate(Option_t *)
198 // Called at the end.
200 if (fLocalOcdb.Length()>0) {
201 TString cmd(Form("rm -rf %s", fLocalOcdb.Data()));