]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliReconstruction.cxx
Fixes for bug #52499: Field polarities inconsistiency
[u/mrichter/AliRoot.git] / STEER / AliReconstruction.cxx
index 9ea21b3373ed49e35679c9f714404ddb381d1116..19ddd855a8770f2af2b1f9bdd28af5602dfd1ff8 100644 (file)
 #include <TProofOutputFile.h>
 #include <TROOT.h>
 #include <TSystem.h>
+#include <THashTable.h>
 
 #include "AliAlignObj.h"
 #include "AliCDBEntry.h"
 #include "AliTracker.h"
 #include "AliTriggerClass.h"
 #include "AliTriggerCluster.h"
+#include "AliTriggerIR.h"
 #include "AliTriggerConfiguration.h"
 #include "AliV0vertexer.h"
 #include "AliVertexer.h"
@@ -229,6 +231,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   fUseHLTData(),
   fRunInfo(NULL),
   fEventInfo(),
+  fRunScalers(NULL),
 
   fRunLoader(NULL),
   fRawReader(NULL),
@@ -241,6 +244,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   fDiamondProfileSPD(NULL),
   fDiamondProfile(NULL),
   fDiamondProfileTPC(NULL),
+  fListOfCosmicTriggers(NULL),
   
   fGRPData(NULL),
 
@@ -324,6 +328,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fUseHLTData(rec.fUseHLTData),
   fRunInfo(NULL),
   fEventInfo(),
+  fRunScalers(NULL),
 
   fRunLoader(NULL),
   fRawReader(NULL),
@@ -336,6 +341,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fDiamondProfileSPD(rec.fDiamondProfileSPD),
   fDiamondProfile(rec.fDiamondProfile),
   fDiamondProfileTPC(rec.fDiamondProfileTPC),
+  fListOfCosmicTriggers(NULL),
   
   fGRPData(NULL),
 
@@ -441,6 +447,10 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
 
   fEventInfo                     = rec.fEventInfo;
 
+  delete fRunScalers; fRunScalers = NULL;
+  if (rec.fRunScalers) fRunScalers = new AliTriggerRunScalers(*rec.fRunScalers); 
+
+  
   fRunLoader       = NULL;
   fRawReader       = NULL;
   fParentRawReader = NULL;
@@ -467,6 +477,9 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
   delete fDiamondProfileTPC; fDiamondProfileTPC = NULL;
   if (rec.fDiamondProfileTPC) fDiamondProfileTPC = new AliESDVertex(*rec.fDiamondProfileTPC);
 
+  delete fListOfCosmicTriggers; fListOfCosmicTriggers = NULL;
+  if (rec.fListOfCosmicTriggers) fListOfCosmicTriggers = (THashTable*)((rec.fListOfCosmicTriggers)->Clone());
+
   delete fGRPData; fGRPData = NULL;
   //  if (rec.fGRPData) fGRPData = (TMap*)((rec.fGRPData)->Clone());
   if (rec.fGRPData) fGRPData = (AliGRPObject*)((rec.fGRPData)->Clone());
@@ -507,7 +520,12 @@ AliReconstruction::~AliReconstruction()
 // clean up
 
   CleanUp();
+  if (fListOfCosmicTriggers) {
+    fListOfCosmicTriggers->Delete();
+    delete fListOfCosmicTriggers;
+  }
   delete fGRPData;
+  delete fRunScalers;
   fOptions.Delete();
   if (fAlignObjArray) {
     fAlignObjArray->Delete();
@@ -527,7 +545,7 @@ void AliReconstruction::InitQA()
   if (fInitQACalled) return;
   fInitQACalled = kTRUE;
   
-  AliQAManager * qam = AliQAManager::QAManager("rec") ; 
+  AliQAManager * qam = AliQAManager::QAManager(AliQAv1::kRECMODE) ; 
   if (fWriteQAExpertData)
     qam->SetWriteExpert() ; 
  
@@ -889,15 +907,16 @@ void AliReconstruction::SetRecoParam(const char* detector, AliDetectorRecoParam
 
 //_____________________________________________________________________________
 Bool_t AliReconstruction::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Pol, 
-                                     Float_t diPol, Float_t beamenergy, 
-                                     const Char_t *beamtype, const Char_t *path) 
+                                 Float_t diPol, Int_t convention, Bool_t uniform,
+                                 Float_t beamenergy, const Char_t *beamtype, const Char_t *path) 
 {
   //------------------------------------------------
   // The magnetic field map, defined externally...
   // L3 current 30000 A  -> 0.5 T
   // L3 current 12000 A  -> 0.2 T
   // dipole current 6000 A
-  // The polarities must be the same
+  // The polarities must match the convention (LHC or DCS2008) 
+  // unless the special uniform map was used for MC
   //------------------------------------------------
   const Float_t l3NominalCurrent1=30000.; // (A)
   const Float_t l3NominalCurrent2=12000.; // (A)
@@ -906,50 +925,46 @@ Bool_t AliReconstruction::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Po
   const Float_t tolerance=0.03; // relative current tolerance
   const Float_t zero=77.;       // "zero" current (A)
   //
-  TString s=(l3Pol < 0) ? "L3: -" : "L3: +";
-  //
-  AliMagF::BMap_t map = AliMagF::k5kG;
-  //
-  double fcL3,fcDip;
+  AliMagF::BMap_t map;
+  double sclL3,sclDip;
   //
   l3Cur = TMath::Abs(l3Cur);
-  if (TMath::Abs(l3Cur-l3NominalCurrent1)/l3NominalCurrent1 < tolerance) {
-    fcL3 = l3Cur/l3NominalCurrent1;
-    map  = AliMagF::k5kG;
-    s   += "0.5 T;  ";
-  } else if (TMath::Abs(l3Cur-l3NominalCurrent2)/l3NominalCurrent2 < tolerance) {
-    fcL3 = l3Cur/l3NominalCurrent2;
-    map  = AliMagF::k2kG;
-    s   += "0.2 T;  ";
-  } else if (l3Cur <= zero) {
-    fcL3 = 0;
-    map  = AliMagF::k5kGUniform;
-    s   += "0.0 T;  ";
-  } else {
-    AliError(Form("Wrong L3 current (%f A)!",l3Cur));
-    return kFALSE;
+  diCur = TMath::Abs(diCur);
+  //
+  if (TMath::Abs((sclDip=diCur/diNominalCurrent)-1.) > tolerance && !uniform) {
+    if (diCur <= zero) sclDip = 0.; // some small current.. -> Dipole OFF
+    else {
+      AliError(Form("Wrong dipole current (%f A)!",diCur));
+      return kFALSE;
+    }
   }
   //
-  diCur = TMath::Abs(diCur);
-  if (TMath::Abs(diCur-diNominalCurrent)/diNominalCurrent < tolerance) {
-    // 3% current tolerance...
-    fcDip = diCur/diNominalCurrent;
-    s    += "Dipole ON";
-  } else if (diCur <= zero) { // some small current..
-    fcDip = 0.;
-    s    += "Dipole OFF";
-  } else {
-    AliError(Form("Wrong dipole current (%f A)!",diCur));
-    return kFALSE;
+  if (uniform) { 
+    // special treatment of special MC with uniform mag field (normalized to 0.5 T)
+    // no check for scaling/polarities are done
+    map   = AliMagF::k5kGUniform;
+    sclL3 = l3Cur/l3NominalCurrent1; 
+  }
+  else {
+    if      (TMath::Abs((sclL3=l3Cur/l3NominalCurrent1)-1.) < tolerance) map  = AliMagF::k5kG;
+    else if (TMath::Abs((sclL3=l3Cur/l3NominalCurrent2)-1.) < tolerance) map  = AliMagF::k2kG;
+    else if (l3Cur <= zero)                                { sclL3 = 0;  map  = AliMagF::k5kGUniform;}
+    else {
+      AliError(Form("Wrong L3 current (%f A)!",l3Cur));
+      return kFALSE;
+    }
   }
   //
-  if (l3Pol!=diPol && (map==AliMagF::k5kG || map==AliMagF::k2kG) && fcDip!=0) {
-    AliError("L3 and Dipole polarities must be the same");
+  if (sclDip!=0 && (map==AliMagF::k5kG || map==AliMagF::k2kG) &&
+      ((convention==AliMagF::kConvLHC     && l3Pol!=diPol) ||
+       (convention==AliMagF::kConvDCS2008 && l3Pol==diPol)) ) { 
+    AliError(Form("Wrong combination for L3/Dipole polarities (%c/%c) for convention %d",
+                 l3Pol>0?'+':'-',diPol>0?'+':'-',AliMagF::GetPolarityConvention()));
     return kFALSE;
   }
   //
-  if (l3Pol<0) fcL3  = -fcL3;
-  if (diPol<0) fcDip = -fcDip;
+  if (l3Pol<0) sclL3  = -sclL3;
+  if (diPol<0) sclDip = -sclDip;
   //
   AliMagF::BeamType_t btype = AliMagF::kNoBeamField;
   TString btypestr = beamtype;
@@ -961,8 +976,10 @@ Bool_t AliReconstruction::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Po
   else {
     AliInfo(Form("Cannot determine the beam type from %s, assume no LHC magnet field",beamtype));
   }
-  
-  AliMagF* fld = new AliMagF("MagneticFieldMap", s.Data(), 2, fcL3, fcDip, 10., map, path, 
+  char ttl[50];
+  sprintf(ttl,"L3: %+5d Dip: %+4d kA; %s",(int)TMath::Sign(l3Cur,float(sclL3)),
+         (int)TMath::Sign(diCur,float(sclDip)),uniform ? " Constant":"");
+  AliMagF* fld = new AliMagF("MagneticFieldMap", ttl, 2, sclL3, sclDip, 10., map, path, 
                             btype,beamenergy);
   TGeoGlobalMagField::Instance()->SetField( fld );
   TGeoGlobalMagField::Instance()->Lock();
@@ -970,7 +987,6 @@ Bool_t AliReconstruction::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Po
   return kTRUE;
 }
 
-
 Bool_t AliReconstruction::InitGRP() {
   //------------------------------------
   // Initialization of the GRP entry 
@@ -994,7 +1010,11 @@ Bool_t AliReconstruction::InitGRP() {
        entry->SetOwner(0);
     }
 
-    AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
+    //    FIX ME: The unloading of GRP entry is temporarily disabled
+    //    because ZDC and VZERO are using it in order to initialize
+    //    their reconstructor objects. In the future one has to think
+    //    of propagating AliRunInfo to the reconstructors.
+    //    AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
   }
 
   if (!fGRPData) {
@@ -1104,42 +1124,17 @@ Bool_t AliReconstruction::InitGRP() {
       ok = kFALSE;
     }
 
-    /*
-    TObjString *l3Current=
-       dynamic_cast<TObjString*>(fGRPData->GetValue("fL3Current"));
-    if (!l3Current) {
-      AliError("GRP/GRP/Data entry:  missing value for the L3 current !");
-      ok = kFALSE;
-    }
-    TObjString *l3Polarity=
-       dynamic_cast<TObjString*>(fGRPData->GetValue("fL3Polarity"));
-    if (!l3Polarity) {
-      AliError("GRP/GRP/Data entry:  missing value for the L3 polarity !");
-      ok = kFALSE;
-    }
-    
-    // Dipole
-    TObjString *diCurrent=
-       dynamic_cast<TObjString*>(fGRPData->GetValue("fDipoleCurrent"));
-    if (!diCurrent) {
-      AliError("GRP/GRP/Data entry:  missing value for the dipole current !");
-      ok = kFALSE;
-    }
-    TObjString *diPolarity=
-       dynamic_cast<TObjString*>(fGRPData->GetValue("fDipolePolarity"));
-    if (!diPolarity) {
-      AliError("GRP/GRP/Data entry:  missing value for the dipole polarity !");
-      ok = kFALSE;
-    }
-    */
+    // read special bits for the polarity convention and map type
+    Int_t  polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
+    Bool_t uniformB = fGRPData->IsUniformBMap();
 
     if (ok) { 
-      if ( !SetFieldMap(l3Current, diCurrent, l3Polarity ? -1:1, diPolarity ? -1:1) )
+      if ( !SetFieldMap(l3Current, diCurrent, l3Polarity ? -1:1, diPolarity ? -1:1, 
+                       polConvention,uniformB,beamEnergy, beamType.Data()))
        AliFatal("Failed to creat a B field map ! Exiting...");
       AliInfo("Running with the B field constructed out of GRP !");
     }
     else AliFatal("B field is neither set nor constructed from GRP ! Exitig...");
-    
   }
   
   //*** Get the diamond profiles from OCDB
@@ -1164,6 +1159,17 @@ Bool_t AliReconstruction::InitGRP() {
      AliError("No TPC diamond profile found in OCDB!");
   }
 
+  entry = AliCDBManager::Instance()->Get("GRP/Calib/CosmicTriggers");
+  if (entry) {
+    fListOfCosmicTriggers = dynamic_cast<THashTable*>(entry->GetObject());
+    entry->SetOwner(0);
+    AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
+  }
+
+  if (!fListOfCosmicTriggers) {
+    AliWarning("Can not get list of cosmic triggers from OCDB! Cosmic event specie will be effectively disabled!");
+  }
+
   return kTRUE;
 } 
 
@@ -1181,7 +1187,23 @@ Bool_t AliReconstruction::LoadCDB()
   }
   return kTRUE;
 }
+//_____________________________________________________________________________
+Bool_t AliReconstruction::LoadTriggerScalersCDB()
+{
+  AliCodeTimerAuto("");
+
+  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/Scalers");
 
+  if (entry) { 
+   
+       AliInfo("Found an AliTriggerRunScalers in GRP/CTP/Scalers, reading it");
+       fRunScalers = dynamic_cast<AliTriggerRunScalers*> (entry->GetObject());
+       entry->SetOwner(0);
+       if (fRunScalers->CorrectScalersOverflow() == 0) AliInfo("32bit Trigger counters corrected for overflow");
+
+  }
+  return kTRUE;
+}
 //_____________________________________________________________________________
 Bool_t AliReconstruction::Run(const char* input)
 {
@@ -1345,6 +1367,13 @@ void AliReconstruction::Begin(TTree *)
   }
   AliSysInfo::AddStamp("LoadCDB");
 
+  if (!LoadTriggerScalersCDB()) {
+    Abort("LoadTriggerScalersCDB", TSelector::kAbortProcess);
+    return;
+  }
+  AliSysInfo::AddStamp("LoadTriggerScalersCDB");
+
+
   // Read the reconstruction parameters from OCDB
   if (!InitRecoParams()) {
     AliWarning("Not all detectors have correct RecoParam objects initialized");
@@ -1567,7 +1596,7 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
 
   // Fill Event-info object
   GetEventInfo();
-  fRecoParam.SetEventSpecie(fRunInfo,fEventInfo);
+  fRecoParam.SetEventSpecie(fRunInfo,fEventInfo,fListOfCosmicTriggers);
   AliInfo(Form("Current event specie: %s",fRecoParam.PrintEventSpecie()));
 
   // Set the reco-params
@@ -1579,8 +1608,10 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
       if (reconstructor && fRecoParam.GetDetRecoParamArray(iDet)) {
         const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
         reconstructor->SetRecoParam(par);
+       reconstructor->SetEventInfo(&fEventInfo);
         if (fRunQA) {
           AliQAManager::QAManager()->SetRecoParam(iDet, par) ; 
+          AliQAManager::QAManager()->SetEventSpecie(AliRecoParam::Convert(par->GetEventSpecie())) ;
         }
       }
     }
@@ -1680,6 +1711,7 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
   
     // fill Event header information from the RawEventHeader
     if (fRawReader){FillRawEventHeaderESD(fesd);}
+    if (fRawReader){FillRawEventHeaderESD(fhltesd);}
 
     // combined PID
     AliESDpid::MakePID(fesd);
@@ -1856,8 +1888,11 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
   
     fEventInfo.Reset();
     for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
-      if (fReconstructor[iDet])
+      if (fReconstructor[iDet]) {
        fReconstructor[iDet]->SetRecoParam(NULL);
+       fReconstructor[iDet]->SetEventInfo(NULL);
+      }
+      if (fTracker[iDet]) fTracker[iDet]->SetEventInfo(NULL);
     }
        
   if (fRunQA || fRunGlobalQA) 
@@ -1916,7 +1951,7 @@ void AliReconstruction::SlaveTerminate()
     ftree->SetBranchStatus("ESDfriend*",0);
   // we want to have only one tree version number
   ftree->Write(ftree->GetName(),TObject::kOverwrite);
-  fhlttree->Write();
+  fhlttree->Write(fhlttree->GetName(),TObject::kOverwrite);
 
 // Finish with Plane Efficiency evaluation: before of CleanUp !!!
   if (fRunPlaneEff && !FinishPlaneEff()) {
@@ -2287,7 +2322,16 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
 
   AliInfo("running tracking");
 
-  
+  // Set the event info which is used
+  // by the trackers in order to obtain
+  // information about read-out detectors,
+  // trigger etc.
+  AliDebug(1, "Setting event info");
+  for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
+    if (!fTracker[iDet]) continue;
+    fTracker[iDet]->SetEventInfo(&fEventInfo);
+  }
+
   //Fill the ESD with the T0 info (will be used by the TOF) 
   if (fReconstructor[11] && fLoader[11]) {
     fLoader[11]->LoadRecPoints("READ");
@@ -2539,17 +2583,29 @@ Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
       esdheader->SetL0TriggerInputs(input.GetL0Inputs());
       esdheader->SetL1TriggerInputs(input.GetL1Inputs());
       esdheader->SetL2TriggerInputs(input.GetL2Inputs());
+      // IR
+      UInt_t orbit=input.GetOrbitID();
+       for(Int_t i=0 ; i<input.GetNIRs() ; i++ )
+          if(TMath::Abs(Int_t(orbit-(input.GetIR(i))->GetOrbit()))<=1){
+            esdheader->AddTriggerIR(input.GetIR(i));
+         }
     }
-
-  // Here one has to add the filling interaction records
+  }
+  //Scalers
+  //fRunScalers->Print();
+  if(fRunScalers && fRunScalers->CheckRunScalers()){
+     AliTimeStamp* timestamp = new AliTimeStamp(esd->GetOrbitNumber(), esd->GetPeriodNumber(), esd->GetBunchCrossNumber());
+     //AliTimeStamp* timestamp = new AliTimeStamp(10308000, 0, (ULong64_t)486238);
+     AliESDHeader* esdheader = fesd->GetHeader();
+     for(Int_t i=0;i<50;i++){
+          if((1<<i) & esd->GetTriggerMask()){
+          AliTriggerScalersESD* scalesd = fRunScalers->GetScalersForEventClass( timestamp, i+1);
+          if(scalesd)esdheader->SetTriggerScalersRecord(scalesd);
+        }
+     }
   }
   return kTRUE;
 }
-
-
-
-
-
 //_____________________________________________________________________________
 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
 {
@@ -2671,6 +2727,7 @@ AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
     if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
       const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
       fReconstructor[iDet]->SetRecoParam(par);
+      fReconstructor[iDet]->SetRunInfo(fRunInfo);
     }
     return fReconstructor[iDet];
   }
@@ -2752,6 +2809,7 @@ AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
   if (fRecoParam.GetDetRecoParamArray(iDet) && !AliReconstructor::GetRecoParam(iDet)) {
     const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(iDet);
     reconstructor->SetRecoParam(par);
+    reconstructor->SetRunInfo(fRunInfo);
   }
   return reconstructor;
 }
@@ -2765,7 +2823,7 @@ AliVertexer* AliReconstruction::CreateVertexer()
 
   AliVertexer* vertexer = NULL;
   AliReconstructor* itsReconstructor = GetReconstructor(0);
-  if (itsReconstructor && (fRunLocalReconstruction.Contains("ITS"))) {
+  if (itsReconstructor && ((fRunLocalReconstruction.Contains("ITS")) || fRunTracking.Contains("ITS"))) {
     vertexer = itsReconstructor->CreateVertexer();
   }
   if (!vertexer) {
@@ -3144,6 +3202,40 @@ Bool_t AliReconstruction::InitRecoParams()
 
   Bool_t isOK = kTRUE;
 
+  if (fRecoParam.GetDetRecoParamArray(kNDetectors)) {
+    AliInfo("Using custom GRP reconstruction parameters");
+  }
+  else {
+    AliInfo("Loading GRP reconstruction parameter objects");
+
+    AliCDBPath path("GRP","Calib","RecoParam");
+    AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());
+    if(!entry){ 
+      AliWarning("Couldn't find GRP RecoParam entry in OCDB");
+      isOK = kFALSE;
+    }
+    else {
+      TObject *recoParamObj = entry->GetObject();
+      if (dynamic_cast<TObjArray*>(recoParamObj)) {
+       // GRP has a normal TobjArray of AliDetectorRecoParam objects
+       // Registering them in AliRecoParam
+       fRecoParam.AddDetRecoParamArray(kNDetectors,dynamic_cast<TObjArray*>(recoParamObj));
+      }
+      else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
+       // GRP has only onse set of reco parameters
+       // Registering it in AliRecoParam
+       AliInfo("Single set of GRP reconstruction parameters found");
+       dynamic_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
+       fRecoParam.AddDetRecoParam(kNDetectors,dynamic_cast<AliDetectorRecoParam*>(recoParamObj));
+      }
+      else {
+       AliError("No valid GRP RecoParam object found in the OCDB");
+       isOK = kFALSE;
+      }
+      entry->SetOwner(0);
+    }
+  }
+
   TString detStr = fLoadCDB;
   for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
 
@@ -3181,7 +3273,11 @@ Bool_t AliReconstruction::InitRecoParams()
        isOK = kFALSE;
       }
       entry->SetOwner(0);
-      AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
+      //      FIX ME: We have to disable the unloading of reco-param CDB
+      //      entries because QA framework is using them. Has to be fix in
+      //      a way that the QA takes the objects already constructed in
+      //      this method.
+      //      AliCDBManager::Instance()->UnloadFromCache(path.GetPath());
     }
   }