2 // Manager (singleton) of corrections
4 #include "AliForwardCorrectionManager.h"
5 #include "AliForwardUtil.h"
12 //____________________________________________________________________
13 AliForwardCorrectionManager* AliForwardCorrectionManager::fgInstance = 0;
14 const char* AliForwardCorrectionManager::fgkSecondaryMapSkel = "secondary";
15 const char* AliForwardCorrectionManager::fgkDoubleHitSkel = "doublehit";
16 const char* AliForwardCorrectionManager::fgkELossFitsSkel = "elossfits";
17 const char* AliForwardCorrectionManager::fgkVertexBiasSkel = "vertexbias";
18 const char* AliForwardCorrectionManager::fgkMergingEffSkel = "merging";
19 const char* AliForwardCorrectionManager::fgkAcceptanceSkel = "acceptance";
21 #define PREFIX "$(ALICE_ROOT)/PWG2/FORWARD/corrections/"
22 #define ELOSSFIT_DIR "ELossFits"
23 #define MERGING_DIR "MergingEfficiency"
24 #define SECONDARY_DIR "SecondaryMap"
25 #define DOUBLE_DIR "DoubleHit"
26 #define VERTEX_DIR "VertexBias"
27 #define ACCEPTANCE_DIR "Acceptance"
29 //____________________________________________________________________
30 AliForwardCorrectionManager& AliForwardCorrectionManager::Instance()
33 // Access to the singleton object
36 // Reference to the singleton object
38 if (!fgInstance) fgInstance= new AliForwardCorrectionManager;
42 //____________________________________________________________________
43 AliForwardCorrectionManager::AliForwardCorrectionManager()
49 fELossFitsPath(PREFIX ELOSSFIT_DIR),
50 fMergingEffPath(PREFIX MERGING_DIR),
51 fSecondaryMapPath(PREFIX SECONDARY_DIR),
52 fDoubleHitPath(PREFIX DOUBLE_DIR),
53 fVertexBiasPath(PREFIX VERTEX_DIR),
54 fAcceptancePath(PREFIX ACCEPTANCE_DIR),
59 fMergingEfficiency(0),
63 // Default constructor
66 //____________________________________________________________________
67 AliForwardCorrectionManager::AliForwardCorrectionManager(const AliForwardCorrectionManager& o)
73 fELossFitsPath(o.fELossFitsPath),
74 fMergingEffPath(o.fMergingEffPath),
75 fSecondaryMapPath(o.fSecondaryMapPath),
76 fDoubleHitPath(o.fDoubleHitPath),
77 fVertexBiasPath(o.fVertexBiasPath),
78 fAcceptancePath(o.fAcceptancePath),
79 fELossFit(o.fELossFit),
80 fSecondaryMap(o.fSecondaryMap),
81 fDoubleHit(o.fDoubleHit),
82 fVertexBias(o.fVertexBias),
83 fMergingEfficiency(o.fMergingEfficiency),
84 fAcceptance(o.fAcceptance)
91 // o Object to copy from
94 //____________________________________________________________________
95 AliForwardCorrectionManager&
96 AliForwardCorrectionManager::operator=(const AliForwardCorrectionManager& o)
99 // Assignment operator
102 // o Object to assign from
105 // Reference to this object
111 fELossFitsPath = o.fELossFitsPath;
112 fMergingEffPath = o.fMergingEffPath;
113 fSecondaryMapPath = o.fSecondaryMapPath;
114 fDoubleHitPath = o.fDoubleHitPath;
115 fVertexBiasPath = o.fVertexBiasPath;
116 fAcceptancePath = o.fAcceptancePath;
117 fELossFit = o.fELossFit;
118 fSecondaryMap = o.fSecondaryMap;
119 fDoubleHit = o.fDoubleHit;
120 fVertexBias = o.fVertexBias;
121 fMergingEfficiency= o.fMergingEfficiency;
122 fAcceptance = o.fAcceptance;
126 //____________________________________________________________________
128 AliForwardCorrectionManager::SetPrefix(const char* prefix)
130 fELossFitsPath = Form("%s/%s", prefix, ELOSSFIT_DIR);
131 fMergingEffPath = Form("%s/%s", prefix, MERGING_DIR);
132 fSecondaryMapPath = Form("%s/%s", prefix, SECONDARY_DIR);
133 fDoubleHitPath = Form("%s/%s", prefix, DOUBLE_DIR);
134 fVertexBiasPath = Form("%s/%s", prefix, VERTEX_DIR);
135 fAcceptancePath = Form("%s/%s", prefix, ACCEPTANCE_DIR);
138 //____________________________________________________________________
140 AliForwardCorrectionManager::SetFileDir(ECorrection what, const char* dir)
144 // Get the path to the specified object
147 // what Which stuff to get the path for
150 // The full path or null
152 if (what & kSecondaryMap) path = &fSecondaryMapPath;
153 else if (what & kDoubleHit) path = &fDoubleHitPath;
154 else if (what & kELossFits) path = &fELossFitsPath;
155 else if (what & kVertexBias) path = &fVertexBiasPath;
156 else if (what & kMergingEfficiency) path = &fMergingEffPath;
157 else if (what & kAcceptance) path = &fAcceptancePath;
159 AliWarning(Form("No such path defined for 0x%02x", what));
163 AliWarning(Form("Couldn't find string for path 0x%02x", what));
169 //____________________________________________________________________
171 AliForwardCorrectionManager::Init(const char* cms,
179 // Read in correction based on passed parameters
182 // collisionSystem Collision system string
183 // cmsNN Center of mass energy per nucleon pair [GeV]
184 // field Magnetic field [kG]
185 // mc Monte-carlo switch
186 // what What to read in
187 // force Force (re-)reading of specified things
192 UShort_t col = AliForwardUtil::ParseCollisionSystem(cms);
193 // AliInfo(Form("Initialising with cms='%s', sNN=%fGeV field=%fkG",
194 // cms, sNN, field));
196 AliForwardUtil::ParseCenterOfMassEnergy(col, sNN),
197 AliForwardUtil::ParseMagneticField(field),
201 //____________________________________________________________________
203 AliForwardCorrectionManager::Init(UShort_t cms,
211 // Read in corrections based on the parameters given
214 // collisionSystem Collision system
215 // cmsNN Center of mass energy per nuclean pair [GeV]
216 // field Magnetic field setting [kG]
217 // mc Monte-carlo switch
218 // what What to read in.
219 // force Force (re-)reading of specified things
224 if (force) fInit = kFALSE;
226 // Check that the initialisation and the passed parameters
227 // match - if not give an error but continue - this allows
228 // users to override particular settings.
231 AliWarning(Form("Initialised collision system %s (%d) and "
232 "passed same %s (%d) does not match",
233 AliForwardUtil::CollisionSystemString(fSys), fSys,
234 AliForwardUtil::CollisionSystemString(cms), cms));
237 if (TMath::Abs(fSNN - sNN) >= 10) {
238 AliWarning(Form("Initialised center of mass energy per nuclean "
239 "%s (%d) and passed same %s (%d) does not match",
240 AliForwardUtil::CenterOfMassEnergyString(fSNN), fSNN,
241 AliForwardUtil::CenterOfMassEnergyString(sNN), sNN));
244 if (fField != field) {
245 AliWarning(Form("Initialied L3 magnetic field %s (%d) and passed "
246 "same %s (%d) does not match",
247 AliForwardUtil::MagneticFieldString(fField), fField,
248 AliForwardUtil::MagneticFieldString(field), field));
252 AliWarning("Intialised parameters and these are not the same "
253 "- PROCEED WITH CAUTION!");
259 if (fSys == cms && TMath::Abs(fSNN - sNN) < 10 && fField == field) {
260 // We're already initialised for these settings - do nothing and return
264 // Set cached parameters
269 // AliInfo(Form("Initialising with cms=%d, sNN=%dGeV field=%dkG",
270 // cms, sNN, field));
271 // Read secondary map if requested
272 if (what & kSecondaryMap) {
273 if (!ReadSecondaryMap(cms, sNN, field)) {
274 AliWarning(Form("Failed to read in secondary map for "
275 "cms=%d, sNN=%dGeV, field=%dkG", cms, sNN, field));
279 // Read double hit if requested
280 if (what & kDoubleHit) {
281 if (!ReadDoubleHit(cms, sNN, field)) {
282 AliWarning(Form("Failed to read in double hit correction for "
283 "cms=%d, sNN=%dGeV, field=%dkG", cms, sNN, field));
287 // Read energy loss fits if requested
288 if (what & kELossFits) {
289 if (!ReadELossFits(cms, sNN, field, mc)) {
290 AliWarning(Form("Failed to read in energy loss fits for "
291 "cms=%d, sNN=%dGeV, field=%dkG, %s",
292 cms, sNN, field, mc ? "MC" : "real"));
296 // Read acceptance correction if requested
297 if (what & kAcceptance) {
298 if (!ReadAcceptance(cms, sNN, 0)) {
299 AliWarning(Form("Failed to read in acceptance for "
300 "cms=%d, sNN=%dGeV, field=%dkG", cms, sNN, 0));
304 // Read event selection efficiencies if requested
305 if (what & kVertexBias) {
306 if (!ReadVertexBias(cms, sNN, field)) {
307 AliWarning(Form("Failed to read in vertex bias correction for "
308 "cms=%d, sNN=%dGeV, field=%dkG", cms, sNN, field));
312 // Read merging efficiencies if requested
313 if (what & kMergingEfficiency) {
314 if (!ReadMergingEfficiency(cms, sNN, field)) {
315 AliWarning(Form("Failed to read in hit merging efficiency for "
316 "cms=%d, sNN=%dGeV, field=%dkG",
325 //____________________________________________________________________
327 AliForwardCorrectionManager::GetFileName(ECorrection what,
334 // Get the path to the specified object
337 // what Which stuff to get the path for
338 // sys Collision system
339 // sNN Center of mass energy [GeV]
340 // field Magnetic field in the L3 magnet [kG]
341 // mc Whether the correction objects should be valid for MC
344 // The full path or null
347 fname = GetObjectName(what);
348 fname.Append(Form("_%s_%04dGeV_%c%1dkG_%s.root",
349 AliForwardUtil::CollisionSystemString(sys),
350 sNN, (field < 0 ? 'm' : 'p'), TMath::Abs(field),
351 (mc ? "MC" : "real")));
354 //____________________________________________________________________
356 AliForwardCorrectionManager::GetFileName(ECorrection what) const
359 // Get the file name of the specified object
362 // what Which stuff to get the path for
365 // The full path or null
368 AliWarning("Corrections manager initialised, do a forced Init(...)");
371 return GetFileName(what, fSys, fSNN, fField, false);
374 //____________________________________________________________________
376 AliForwardCorrectionManager::GetFileDir(ECorrection what) const
379 // Get the path to the specified object
382 // what Which stuff to get the path for
385 // The full path or null
387 if (what & kSecondaryMap) return fSecondaryMapPath;
388 else if (what & kDoubleHit) return fDoubleHitPath;
389 else if (what & kELossFits) return fELossFitsPath;
390 else if (what & kVertexBias) return fVertexBiasPath;
391 else if (what & kMergingEfficiency) return fMergingEffPath;
392 else if (what & kAcceptance) return fAcceptancePath;
394 AliWarning(Form("Unknown correction: %d", what));
398 //____________________________________________________________________
400 AliForwardCorrectionManager::GetFilePath(ECorrection what,
407 // Get the path to the specified object
410 // what Which stuff to get the path for
411 // sys Collision system
412 // sNN Center of mass energy [GeV]
413 // field Magnetic field in the L3 magnet [kG]
414 // mc Whether the correction objects should be valid for MC
417 // The full path or null
420 const Char_t* dir = GetFileDir(what);
421 if (!dir) return path;
423 TString fname(GetFileName(what, sys, sNN, field, mc));
424 if (fname.IsNull()) return path;
426 path = gSystem->ConcatFileName(gSystem->ExpandPathName(dir), fname);
430 //____________________________________________________________________
432 AliForwardCorrectionManager::GetFilePath(ECorrection what) const
435 // Get the full path to the object. Note, the manager must be
436 // initialised for this to work
439 // what Which stuff to get the path for
442 // The full path or null
445 AliWarning("Corrections manager initialised, do a forced Init(...)");
448 return GetFilePath(what, fSys, fSNN, fField, false);
451 //____________________________________________________________________
453 AliForwardCorrectionManager::GetFile(ECorrection what,
459 Bool_t newfile) const
462 // Open the file that contains the correction object specified
465 // what Which stuff to get the path for
466 // sys Collision system
467 // sNN Center of mass energy [GeV]
468 // field Magnetic field in the L3 magnet [kG]
469 // mc Whether the correction objects should be valid for MC
470 // rw Whether to open the file in read/write
471 // newfile Wheter to make the file if it doesn't exist
474 // The file that contains the correction object or null
476 TString path = GetFilePath(what, sys, sNN, field, mc);
477 if (path.IsNull()) return 0;
480 if (newfile) opt="RECREATE";
482 if (gSystem->AccessPathName(path.Data(),
483 (rw ? kWritePermission : kReadPermission))) {
484 AliWarning(Form("file %s cannot be found or insufficient permissions",
488 opt=(rw ? "UPDATE" : "READ");
490 TFile* file = TFile::Open(path.Data(), opt.Data());
492 AliWarning(Form("file %s cannot be opened in mode %s",
493 path.Data(), opt.Data()));
498 //____________________________________________________________________
500 AliForwardCorrectionManager::GetFile(ECorrection what) const
503 // Get the file that contains the object specifed. Note, the manager
504 // must be initialised for this to work.
507 // what Which stuff to get the path for
510 // The file that contains the correction object or null
513 AliWarning("Corrections manager initialised, do a forced Init(...)");
516 return GetFile(what, fSys, fSNN, fField, false);
519 //____________________________________________________________________
521 AliForwardCorrectionManager::GetObjectName(ECorrection what) const
524 // Get the object name corresponding to correction type
530 // Object name or null
532 if (what & kSecondaryMap) return fgkSecondaryMapSkel;
533 else if (what & kDoubleHit) return fgkDoubleHitSkel;
534 else if (what & kELossFits) return fgkELossFitsSkel;
535 else if (what & kVertexBias) return fgkVertexBiasSkel;
536 else if (what & kMergingEfficiency) return fgkMergingEffSkel;
537 else if (what & kAcceptance) return fgkAcceptanceSkel;
541 //____________________________________________________________________
543 AliForwardCorrectionManager::CheckObject(TFile* file, ECorrection what) const
546 // Check if the specified objet exists in the file, and return it
549 // file File to query
550 // what Correction type
553 // Object found, or null
555 TObject* o = file->Get(GetObjectName(what));
557 AliWarning(Form("Object %s not found in %s",
558 GetObjectName(what), file->GetName()));
565 //____________________________________________________________________
567 AliForwardCorrectionManager::GetObject(ECorrection what,
574 // Get the path to the specified object
577 // what Which stuff to get the path for
578 // sys Collision system
579 // sNN Center of mass energy [GeV]
580 // field Magnetic field in the L3 magnet [kG]
581 // mc Whether the correction objects should be valid for MC
584 // The full path or null
586 TFile* file = GetFile(what, sys, sNN, field, mc, false, false);
589 return CheckObject(file, what);
591 //____________________________________________________________________
593 AliForwardCorrectionManager::GetObject(ECorrection what) const
596 // Get the object that contaisn the specified correction
599 // what Which object to get
602 // The object or null
605 AliWarning("Corrections manager initialised, do a forced Init(...)");
608 return GetObject(what, fSys, fSNN, fField, false);
612 //____________________________________________________________________
614 AliForwardCorrectionManager::ReadSecondaryMap(UShort_t sys, UShort_t sNN,
618 // Read in the secondary map
621 // sys Collision system
622 // sNN Center of mass energy [GeV]
623 // field Magnetic field in the L3 magnet [kG]
626 // True on success, false otherwise
629 AliWarning("Corrections manager initialised, do a forced Init(...)");
633 TObject* o = GetObject(kSecondaryMap, sys, sNN, field, false);
634 if (!o) return kFALSE;
636 fSecondaryMap = dynamic_cast<AliFMDCorrSecondaryMap*>(o);
637 if (!fSecondaryMap) {
638 AliWarning(Form("Object %s (%p) is not an AliFMDCorrSecondaryMap object, "
639 "but %s", fgkSecondaryMapSkel, o, o->ClassName()));
646 //____________________________________________________________________
648 AliForwardCorrectionManager::ReadDoubleHit(UShort_t sys, UShort_t sNN,
652 // Read in the double hit correction
655 // sys Collision system
656 // sNN Center of mass energy [GeV]
657 // field Magnetic field in the L3 magnet [kG]
660 // True on success, false otherwise
663 AliWarning("Corrections manager initialised, do a forced Init(...)");
667 TObject* o = GetObject(kDoubleHit, sys, sNN, field, false);
668 if (!o) return kFALSE;
670 fDoubleHit = dynamic_cast<AliFMDCorrDoubleHit*>(o);
672 AliWarning(Form("Object %s (%p) is not an AliFMDCorrDoubleHit object, "
673 "but %s", fgkDoubleHitSkel, o, o->ClassName()));
681 //____________________________________________________________________
683 AliForwardCorrectionManager::ReadELossFits(UShort_t sys, UShort_t sNN,
684 Short_t field, Bool_t mc)
687 // Read in the energy loss fits
690 // sys Collision system
691 // sNN Center of mass energy [GeV]
692 // field Magnetic field in the L3 magnet [kG]
693 // mc Whether the correction objects should be valid for MC
696 // True on success, false otherwise
699 AliWarning("Corrections manager initialised, do a forced Init(...)");
703 TObject* o = GetObject(kELossFits, sys, sNN, field, mc);
704 if (!o) return kFALSE;
706 fELossFit = dynamic_cast<AliFMDCorrELossFit*>(o);
708 AliWarning(Form("Object %s (%p) is not an AliFMDCorrELossFit object, "
709 "but %s", fgkELossFitsSkel, o, o->ClassName()));
717 //____________________________________________________________________
719 AliForwardCorrectionManager::ReadVertexBias(UShort_t sys,
724 // Read in the event selection efficiency
727 // sys Collision system
728 // sNN Center of mass energy [GeV]
729 // field Magnetic field in the L3 magnet [kG]
732 // True on success, false otherwise
735 AliWarning("Corrections manager initialised, do a forced Init(...)");
739 TObject* o = GetObject(kVertexBias, sys, sNN, field, false);
740 if (!o) return kFALSE;
742 fVertexBias = dynamic_cast<AliFMDCorrVertexBias*>(o);
744 AliWarning(Form("Object %s (%p) is not an AliFMDCorrVertexBias object, "
745 "but %s", fgkVertexBiasSkel, o, o->ClassName()));
753 //____________________________________________________________________
755 AliForwardCorrectionManager::ReadMergingEfficiency(UShort_t sys,
760 // Read in the merging efficiency
763 // sys Collision system
764 // sNN Center of mass energy [GeV]
765 // field Magnetic field in the L3 magnet [kG]
768 // True on success, false otherwise
771 AliWarning("Corrections manager initialised, do a forced Init(...)");
775 TObject* o = GetObject(kMergingEfficiency, sys, sNN, field, false);
776 if (!o) return kFALSE;
778 fMergingEfficiency = dynamic_cast<AliFMDCorrMergingEfficiency*>(o);
779 if (!fMergingEfficiency) {
780 AliWarning(Form("Object %s (%p) is not an AliFMDCorrMergingEfficiency "
781 "object, but %s", fgkMergingEffSkel, o, o->ClassName()));
789 //____________________________________________________________________
791 AliForwardCorrectionManager::ReadAcceptance(UShort_t sys,
796 // Read in the event selection efficiency
799 // sys Collision system
800 // sNN Center of mass energy [GeV]
801 // field Magnetic field in the L3 magnet [kG]
804 // True on success, false otherwise
807 AliWarning("Corrections manager initialised, do a forced Init(...)");
811 TObject* o = GetObject(kAcceptance, sys, sNN, field, false);
812 if (!o) return kFALSE;
814 fAcceptance = dynamic_cast<AliFMDCorrAcceptance*>(o);
816 AliWarning(Form("Object %s (%p) is not an AliFMDCorrAcceptance object, "
817 "but %s", fgkAcceptanceSkel, o, o->ClassName()));
825 //____________________________________________________________________