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";
20 #define PREFIX "$(ALICE_ROOT)/PWG2/FORWARD/corrections/"
22 //____________________________________________________________________
23 AliForwardCorrectionManager& AliForwardCorrectionManager::Instance()
26 // Access to the singleton object
29 // Reference to the singleton object
31 if (!fgInstance) fgInstance= new AliForwardCorrectionManager;
35 //____________________________________________________________________
36 AliForwardCorrectionManager::AliForwardCorrectionManager()
42 fELossFitsPath(PREFIX "ELossFits"),
43 fMergingEffPath(PREFIX "MergingEfficiency"),
44 fSecondaryMapPath(PREFIX "SecondaryMap"),
45 fDoubleHitPath(PREFIX "DoubleHit"),
46 fVertexBiasPath(PREFIX "VertexBias"),
54 // Default constructor
57 //____________________________________________________________________
58 AliForwardCorrectionManager::AliForwardCorrectionManager(const AliForwardCorrectionManager& o)
64 fELossFitsPath(o.fELossFitsPath),
65 fMergingEffPath(o.fMergingEffPath),
66 fSecondaryMapPath(o.fSecondaryMapPath),
67 fDoubleHitPath(o.fDoubleHitPath),
68 fVertexBiasPath(o.fVertexBiasPath),
69 fELossFit(o.fELossFit),
70 fSecondaryMap(o.fSecondaryMap),
71 fDoubleHit(o.fDoubleHit),
72 fVertexBias(o.fVertexBias),
73 fMergingEfficiency(o.fMergingEfficiency)
80 // o Object to copy from
83 //____________________________________________________________________
84 AliForwardCorrectionManager&
85 AliForwardCorrectionManager::operator=(const AliForwardCorrectionManager& o)
88 // Assignment operator
91 // o Object to assign from
94 // Reference to this object
100 fELossFitsPath = o.fELossFitsPath;
101 fMergingEffPath = o.fMergingEffPath;
102 fSecondaryMapPath = o.fSecondaryMapPath;
103 fDoubleHitPath = o.fDoubleHitPath;
104 fVertexBiasPath = o.fVertexBiasPath;
105 fELossFit = o.fELossFit;
106 fSecondaryMap = o.fSecondaryMap;
107 fDoubleHit = o.fDoubleHit;
108 fVertexBias = o.fVertexBias;
109 fMergingEfficiency= o.fMergingEfficiency;
113 //____________________________________________________________________
115 AliForwardCorrectionManager::Init(const char* cms,
123 // Read in correction based on passed parameters
126 // collisionSystem Collision system string
127 // cmsNN Center of mass energy per nucleon pair [GeV]
128 // field Magnetic field [kG]
129 // mc Monte-carlo switch
130 // what What to read in
131 // force Force (re-)reading of specified things
136 UShort_t col = AliForwardUtil::ParseCollisionSystem(cms);
138 AliForwardUtil::ParseCenterOfMassEnergy(col, sNN),
139 AliForwardUtil::ParseMagneticField(field),
143 //____________________________________________________________________
145 AliForwardCorrectionManager::Init(UShort_t cms,
153 // Read in corrections based on the parameters given
156 // collisionSystem Collision system
157 // cmsNN Center of mass energy per nuclean pair [GeV]
158 // field Magnetic field setting [kG]
159 // mc Monte-carlo switch
160 // what What to read in.
161 // force Force (re-)reading of specified things
166 if (force) fInit = kFALSE;
167 if (fInit) return kTRUE;
170 if (fSys == cms && TMath::Abs(fSNN - sNN) < 10 && fField == field) {
171 // We're already initialised for these settings - do nothing and return
175 // Set cached parameters
180 // Read secondary map if requested
181 if (what & kSecondaryMap) {
182 if (!ReadSecondaryMap(cms, sNN, field)) {
183 AliWarning(Form("Failed to read in secondary map for "
184 "cms=%d, sNN=%dGeV, field=%dkG", cms, sNN, field));
188 // Read double hit if requested
189 if (what & kDoubleHit) {
190 if (!ReadDoubleHit(cms, sNN, field)) {
191 AliWarning(Form("Failed to read in double hit correction for "
192 "cms=%d, sNN=%dGeV, field=%dkG", cms, sNN, field));
196 // Read energy loss fits if requested
197 if (what & kELossFits) {
198 if (!ReadELossFits(cms, sNN, field, mc)) {
199 AliWarning(Form("Failed to read in energy loss fits for "
200 "cms=%d, sNN=%dGeV, field=%dkG, %s",
201 cms, sNN, field, mc ? "MC" : "real"));
205 // Read event selection efficiencies if requested
206 if (what & kVertexBias) {
207 if (!ReadVertexBias(cms, sNN, field)) {
208 AliWarning(Form("Failed to read in event selection efficiency for "
209 "cms=%d, sNN=%dGeV, field=%dkG", cms, sNN, field));
213 // Read merging efficiencies if requested
214 if (what & kMergingEfficiency) {
215 if (!ReadMergingEfficiency(cms, sNN, field)) {
216 AliWarning(Form("Failed to read in hit merging efficiency for "
217 "cms=%d, sNN=%dGeV, field=%dkG",
226 //____________________________________________________________________
228 AliForwardCorrectionManager::GetFileName(ECorrection what,
235 // Get the path to the specified object
238 // what Which stuff to get the path for
239 // sys Collision system
240 // sNN Center of mass energy [GeV]
241 // field Magnetic field in the L3 magnet [kG]
242 // mc Whether the correction objects should be valid for MC
245 // The full path or null
248 fname = GetObjectName(what);
249 fname.Append(Form("_%s_%04dGeV_%c%1dkG_%s.root",
250 AliForwardUtil::CollisionSystemString(sys),
251 sNN, (field < 0 ? 'm' : 'p'), TMath::Abs(field),
252 (mc ? "MC" : "real")));
255 //____________________________________________________________________
257 AliForwardCorrectionManager::GetFileName(ECorrection what) const
260 // Get the file name of the specified object
263 // what Which stuff to get the path for
266 // The full path or null
269 AliWarning("Corrections manager initialised, do a forced Init(...)");
272 return GetFileName(what, fSys, fSNN, fField, false);
275 //____________________________________________________________________
277 AliForwardCorrectionManager::GetFileDir(ECorrection what) const
280 // Get the path to the specified object
283 // what Which stuff to get the path for
286 // The full path or null
288 if (what & kSecondaryMap) return fSecondaryMapPath;
289 else if (what & kDoubleHit) return fDoubleHitPath;
290 else if (what & kELossFits) return fELossFitsPath;
291 else if (what & kVertexBias) return fVertexBiasPath;
292 else if (what & kMergingEfficiency) return fMergingEffPath;
294 AliWarning(Form("Unknown correction: %d", what));
298 //____________________________________________________________________
300 AliForwardCorrectionManager::GetFilePath(ECorrection what,
307 // Get the path to the specified object
310 // what Which stuff to get the path for
311 // sys Collision system
312 // sNN Center of mass energy [GeV]
313 // field Magnetic field in the L3 magnet [kG]
314 // mc Whether the correction objects should be valid for MC
317 // The full path or null
320 const Char_t* dir = GetFileDir(what);
321 if (!dir) return path;
323 TString fname(GetFileName(what, sys, sNN, field, mc));
324 if (fname.IsNull()) return path;
326 path = gSystem->ConcatFileName(gSystem->ExpandPathName(dir), fname);
330 //____________________________________________________________________
332 AliForwardCorrectionManager::GetFilePath(ECorrection what) const
335 // Get the full path to the object. Note, the manager must be
336 // initialised for this to work
339 // what Which stuff to get the path for
342 // The full path or null
345 AliWarning("Corrections manager initialised, do a forced Init(...)");
348 return GetFilePath(what, fSys, fSNN, fField, false);
351 //____________________________________________________________________
353 AliForwardCorrectionManager::GetFile(ECorrection what,
359 Bool_t newfile) const
362 // Open the file that contains the correction object specified
365 // what Which stuff to get the path for
366 // sys Collision system
367 // sNN Center of mass energy [GeV]
368 // field Magnetic field in the L3 magnet [kG]
369 // mc Whether the correction objects should be valid for MC
370 // rw Whether to open the file in read/write
371 // newfile Wheter to make the file if it doesn't exist
374 // The file that contains the correction object or null
376 TString path = GetFilePath(what, sys, sNN, field, mc);
377 if (path.IsNull()) return 0;
380 if (newfile) opt="RECREATE";
382 if (gSystem->AccessPathName(path.Data(),
383 (rw ? kWritePermission : kReadPermission))) {
384 AliWarning(Form("file %s cannot be found or insufficient permissions",
388 opt=(rw ? "UPDATE" : "READ");
390 TFile* file = TFile::Open(path.Data(), opt.Data());
392 AliWarning(Form("file %s cannot be opened in mode %s",
393 path.Data(), opt.Data()));
398 //____________________________________________________________________
400 AliForwardCorrectionManager::GetFile(ECorrection what) const
403 // Get the file that contains the object specifed. Note, the manager
404 // must be initialised for this to work.
407 // what Which stuff to get the path for
410 // The file that contains the correction object or null
413 AliWarning("Corrections manager initialised, do a forced Init(...)");
416 return GetFile(what, fSys, fSNN, fField, false);
419 //____________________________________________________________________
421 AliForwardCorrectionManager::GetObjectName(ECorrection what) const
424 // Get the object name corresponding to correction type
430 // Object name or null
432 if (what & kSecondaryMap) return fgkSecondaryMapSkel;
433 else if (what & kDoubleHit) return fgkDoubleHitSkel;
434 else if (what & kELossFits) return fgkELossFitsSkel;
435 else if (what & kVertexBias) return fgkVertexBiasSkel;
436 else if (what & kMergingEfficiency) return fgkMergingEffSkel;
440 //____________________________________________________________________
442 AliForwardCorrectionManager::CheckObject(TFile* file, ECorrection what) const
445 // Check if the specified objet exists in the file, and return it
448 // file File to query
449 // what Correction type
452 // Object found, or null
454 TObject* o = file->Get(GetObjectName(what));
456 AliWarning(Form("Object %s not found in %s",
457 GetObjectName(what), file->GetName()));
464 //____________________________________________________________________
466 AliForwardCorrectionManager::GetObject(ECorrection what,
473 // Get the path to the specified object
476 // what Which stuff to get the path for
477 // sys Collision system
478 // sNN Center of mass energy [GeV]
479 // field Magnetic field in the L3 magnet [kG]
480 // mc Whether the correction objects should be valid for MC
483 // The full path or null
485 TFile* file = GetFile(what, sys, sNN, field, mc, false, false);
488 return CheckObject(file, what);
490 //____________________________________________________________________
492 AliForwardCorrectionManager::GetObject(ECorrection what) const
495 // Get the object that contaisn the specified correction
498 // what Which object to get
501 // The object or null
504 AliWarning("Corrections manager initialised, do a forced Init(...)");
507 return GetObject(what, fSys, fSNN, fField, false);
511 //____________________________________________________________________
513 AliForwardCorrectionManager::ReadSecondaryMap(UShort_t sys, UShort_t sNN,
517 // Read in the secondary map
520 // sys Collision system
521 // sNN Center of mass energy [GeV]
522 // field Magnetic field in the L3 magnet [kG]
525 // True on success, false otherwise
528 AliWarning("Corrections manager initialised, do a forced Init(...)");
532 TObject* o = GetObject(kSecondaryMap, sys, sNN, field, false);
533 if (!o) return kFALSE;
535 fSecondaryMap = dynamic_cast<AliFMDCorrSecondaryMap*>(o);
536 if (!fSecondaryMap) {
537 AliWarning(Form("Object %s (%p) is not an AliFMDCorrSecondaryMap object, "
538 "but %s", fgkSecondaryMapSkel, o, o->ClassName()));
545 //____________________________________________________________________
547 AliForwardCorrectionManager::ReadDoubleHit(UShort_t sys, UShort_t sNN,
551 // Read in the double hit correction
554 // sys Collision system
555 // sNN Center of mass energy [GeV]
556 // field Magnetic field in the L3 magnet [kG]
559 // True on success, false otherwise
562 AliWarning("Corrections manager initialised, do a forced Init(...)");
566 TObject* o = GetObject(kDoubleHit, sys, sNN, field, false);
567 if (!o) return kFALSE;
569 fDoubleHit = dynamic_cast<AliFMDCorrDoubleHit*>(o);
571 AliWarning(Form("Object %s (%p) is not an AliFMDCorrDoubleHit object, "
572 "but %s", fgkDoubleHitSkel, o, o->ClassName()));
580 //____________________________________________________________________
582 AliForwardCorrectionManager::ReadELossFits(UShort_t sys, UShort_t sNN,
583 Short_t field, Bool_t mc)
586 // Read in the energy loss fits
589 // sys Collision system
590 // sNN Center of mass energy [GeV]
591 // field Magnetic field in the L3 magnet [kG]
592 // mc Whether the correction objects should be valid for MC
595 // True on success, false otherwise
598 AliWarning("Corrections manager initialised, do a forced Init(...)");
602 TObject* o = GetObject(kELossFits, sys, sNN, field, mc);
603 if (!o) return kFALSE;
605 fELossFit = dynamic_cast<AliFMDCorrELossFit*>(o);
607 AliWarning(Form("Object %s (%p) is not an AliFMDCorrELossFit object, "
608 "but %s", fgkELossFitsSkel, o, o->ClassName()));
616 //____________________________________________________________________
618 AliForwardCorrectionManager::ReadVertexBias(UShort_t sys,
623 // Read in the event selection efficiency
626 // sys Collision system
627 // sNN Center of mass energy [GeV]
628 // field Magnetic field in the L3 magnet [kG]
631 // True on success, false otherwise
634 AliWarning("Corrections manager initialised, do a forced Init(...)");
638 TObject* o = GetObject(kVertexBias, sys, sNN, field, false);
639 if (!o) return kFALSE;
641 fVertexBias = dynamic_cast<AliFMDCorrVertexBias*>(o);
643 AliWarning(Form("Object %s (%p) is not an AliFMDCorrVertexBias object, "
644 "but %s", fgkVertexBiasSkel, o, o->ClassName()));
652 //____________________________________________________________________
654 AliForwardCorrectionManager::ReadMergingEfficiency(UShort_t sys,
659 // Read in the merging efficiency
662 // sys Collision system
663 // sNN Center of mass energy [GeV]
664 // field Magnetic field in the L3 magnet [kG]
667 // True on success, false otherwise
670 AliWarning("Corrections manager initialised, do a forced Init(...)");
674 TObject* o = GetObject(kMergingEfficiency, sys, sNN, field, false);
675 if (!o) return kFALSE;
677 fMergingEfficiency = dynamic_cast<AliFMDCorrMergingEfficiency*>(o);
678 if (!fMergingEfficiency) {
679 AliWarning(Form("Object %s (%p) is not an AliFMDCorrMergingEfficiency "
680 "object, but %s", fgkMergingEffSkel, o, o->ClassName()));
688 //____________________________________________________________________