Compatibility with new changes in magnetic field methods.
authordibari <dibari@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 12 Feb 2009 09:41:02 +0000 (09:41 +0000)
committerdibari <dibari@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 12 Feb 2009 09:41:02 +0000 (09:41 +0000)
HMPID/HESDfromKin.C
HMPID/Hconfig.C

index b26a1ef..effd7d0 100644 (file)
@@ -54,7 +54,11 @@ void SimEsd(AliLoader *pHL,AliESDEvent *pEsd,Bool_t htaCheck)
     Printf("| SimESD: Utility to embed ESD from kinematics|");
     Printf("-----------------------------------------------");
 }
-  AliHMPIDTracker::SetFieldMap(gAL->GetAliRun()->Field(),kTRUE);
+
+  InitGRP();
+//  AliMagF *magFieldMap = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
+
+//  AliHMPIDTracker::SetFieldMap(gAL->GetAliRun()->Field(),kTRUE);
   AliHMPIDTracker pTracker;
   AliHMPID *pH=(AliHMPID*)gAL->GetAliRun()->GetDetector("HMPID");
   Int_t iNevt=gAL->GetNumberOfEvents();
@@ -114,7 +118,8 @@ void SimEsd(AliLoader *pHL,AliESDEvent *pEsd,Bool_t htaCheck)
 Bool_t OpenCalib()
 {
   AliCDBManager* pCDB = AliCDBManager::Instance();
-  pCDB->SetDefaultStorage("local://$HOME");
+  pCDB->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  pCDB->SetRun(0);
   AliCDBEntry *pQthreEnt=pCDB->Get("HMPID/Calib/Qthre",0);
   AliCDBEntry *pNmeanEnt=pCDB->Get("HMPID/Calib/Nmean",0);
   
@@ -127,3 +132,201 @@ Bool_t OpenCalib()
   return kTRUE;
 }
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t InitGRP() {
+  //------------------------------------
+  // Initialization of the GRP entry 
+  //------------------------------------
+  
+  AliGRPObject *fGRPData;
+  
+  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
+
+  if (entry) {
+
+    TMap* m = dynamic_cast<TMap*>(entry->GetObject());  // old GRP entry
+
+    if (!m) {
+       Printf("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
+       m->Print();
+       fGRPData = new AliGRPObject();
+       fGRPData->ReadValuesFromMap(m);
+    }
+
+    else {
+       Printf("Found an AliGRPObject in GRP/GRP/Data, reading it");
+       fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject());  // new GRP entry
+       entry->SetOwner(0);
+    }
+
+    AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
+  }
+
+  if (!fGRPData) {
+     Printf("No GRP entry found in OCDB!");
+     return kFALSE;
+  }
+
+  TString lhcState = fGRPData->GetLHCState();
+  if (lhcState==AliGRPObject::GetInvalidString()) {
+    Printf("GRP/GRP/Data entry:  missing value for the LHC state ! Using UNKNOWN");
+    lhcState = "UNKNOWN";
+  }
+
+  TString beamType = fGRPData->GetBeamType();
+  if (beamType==AliGRPObject::GetInvalidString()) {
+    Printf("GRP/GRP/Data entry:  missing value for the beam type ! Using UNKNOWN");
+    beamType = "UNKNOWN";
+  }
+
+  Float_t beamEnergy = fGRPData->GetBeamEnergy();
+  if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
+    Printf("GRP/GRP/Data entry:  missing value for the beam energy ! Using 0");
+    beamEnergy = 0;
+  }
+  // energy is provided in MeV*120
+  beamEnergy /= 120E3;
+
+  TString runType = fGRPData->GetRunType();
+  if (runType==AliGRPObject::GetInvalidString()) {
+    Printf("GRP/GRP/Data entry:  missing value for the run type ! Using UNKNOWN");
+    runType = "UNKNOWN";
+  }
+
+  Int_t activeDetectors = fGRPData->GetDetectorMask();
+  if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
+    Printf("GRP/GRP/Data entry:  missing value for the detector mask ! Using 1074790399");
+    activeDetectors = 1074790399;
+  }
+
+  fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
+  printf("qqqqqqqqqqqqqqqqqqqqqqq %s %s %f %s %d\n", lhcState.Data(), beamType.Data(), beamEnergy, runType.Data(), activeDetectors);
+  fRunInfo->Dump();
+
+  //*** Dealing with the magnetic field map
+  if ( TGeoGlobalMagField::Instance()->IsLocked() ) {Printf("Running with the externally locked B field !");}
+  else {
+    // Construct the field map out of the information retrieved from GRP.
+    Bool_t ok = kTRUE;
+    // L3
+    Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
+    if (l3Current == AliGRPObject::GetInvalidFloat()) {
+      Prtinf("GRP/GRP/Data entry:  missing value for the L3 current !");
+      ok = kFALSE;
+    }
+    
+    Char_t l3Polarity = fGRPData->GetL3Polarity();
+    if (l3Polarity == AliGRPObject::GetInvalidChar()) {
+      Printf("GRP/GRP/Data entry:  missing value for the L3 polarity !");
+      ok = kFALSE;
+    }
+
+    // Dipole
+    Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
+    if (diCurrent == AliGRPObject::GetInvalidFloat()) {
+      Printf("GRP/GRP/Data entry:  missing value for the dipole current !");
+      ok = kFALSE;
+    }
+
+    Char_t diPolarity = fGRPData->GetDipolePolarity();
+    if (diPolarity == AliGRPObject::GetInvalidChar()) {
+      Printf("GRP/GRP/Data entry:  missing value for the dipole polarity !");
+      ok = kFALSE;
+    }
+
+    if (ok) { 
+      if ( !SetFieldMap(l3Current, diCurrent, l3Polarity ? -1:1, diPolarity ? -1:1) )
+       AliFatal("Failed to creat a B field map ! Exiting...");
+      Printf("Running with the B field constructed out of GRP !");
+    }
+    else AliFatal("B field is neither set nor constructed from GRP ! Exitig...");
+    
+  }
+  
+  return kTRUE;
+} 
+
+//_____________________________________________________________________________
+//_____________________________________________________________________________
+  Bool_t SetFieldMap(Float_t l3Cur=30000., Float_t diCur=6000., 
+                    Float_t l3Pol=1., Float_t diPol=1., Float_t beamenergy=7000., 
+                    const Char_t* beamtype="pp",  
+                    const Char_t* path="$(ALICE_ROOT)/data/maps/mfchebKGI_sym.root")
+{
+  //------------------------------------------------
+  // 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
+  //------------------------------------------------
+  const Float_t l3NominalCurrent1=30000.; // (A)
+  const Float_t l3NominalCurrent2=12000.; // (A)
+  const Float_t diNominalCurrent =6000. ; // (A)
+
+  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;
+  //
+  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;  ";
+    fUniformField=kTRUE;        // track with the uniform (zero) B field
+  } else {
+    AliError(Form("Wrong L3 current (%f A)!",l3Cur));
+    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 (l3Pol!=diPol && (map==AliMagF::k5kG || map==AliMagF::k2kG) && fcDip!=0) {
+    AliError("L3 and Dipole polarities must be the same");
+    return kFALSE;
+  }
+  //
+  if (l3Pol<0) fcL3  = -fcL3;
+  if (diPol<0) fcDip = -fcDip;
+  //
+  AliMagF::BeamType_t btype = AliMagF::kNoBeamField;
+  TString btypestr = beamtype;
+  btypestr.ToLower();
+  TPRegexp protonBeam("(proton|p)\\s*-?\\s*\\1");
+  TPRegexp ionBeam("(lead|pb|ion|a)\\s*-?\\s*\\1");
+  if (btypestr.Contains(ionBeam)) btype = AliMagF::kBeamTypeAA;
+  else if (btypestr.Contains(protonBeam)) btype = AliMagF::kBeamTypepp;
+  else {
+    Printf(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, 
+                            btype,beamenergy);
+  TGeoGlobalMagField::Instance()->SetField( fld );
+  TGeoGlobalMagField::Instance()->Lock();
+  //
+  return kTRUE;
+}
index f29efa5..396d209 100644 (file)
@@ -689,20 +689,16 @@ void HmpConfig::WriteBatch()
   
                                                     fprintf(fp,"void %s()\n{\n",sBatchName);
                                                     fprintf(fp,"  gSystem->Exec(\"rm -rf *RRR \");  //remove garbage\n"); 
-
   if(fRecB->GetState()){
-  
-       if(fMagBG->GetButton(kFld0)->GetState())     fprintf(fp,"  AliMagF *field=new AliMagF(\"Maps\",\"Maps\",2,0,1,10.,2);//no field\n");
-  else if(fMagBG->GetButton(kFld2)->GetState())     fprintf(fp,"  AliMagF *field=new AliMagF(\"Maps\",\"Maps\",2,1,1,10,0);//0.2 Tesla field\n");
-  else if(fMagBG->GetButton(kFld4)->GetState())     fprintf(fp,"  AliMagF *field=new AliMagF(\"Maps\",\"Maps\",2,1,1,10,1);//0.4 Tesla field\n");
-  else if(fMagBG->GetButton(kFld5)->GetState())     fprintf(fp,"  AliMagF *field=new AliMagF(\"Maps\",\"Maps\",2,1,1,10,2);//0.5 Tesla field\n");
-  else if(fMagBG->GetButton(kFld_2)->GetState())    fprintf(fp,"  AliMagF *field=new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,0);//-0.2 Tesla field\n");
-  else if(fMagBG->GetButton(kFld_4)->GetState())    fprintf(fp,"  AliMagF *field=new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,1);//-0.4 Tesla field\n");
-  else if(fMagBG->GetButton(kFld_5)->GetState())    fprintf(fp,"  AliMagF *field=new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,2);//-0.5 Tesla field\n");
-  
-                                                    fprintf(fp,"  Bool_t uniform=kTRUE;\n");
-                                                    fprintf(fp,"  AliTracker::SetFieldMap(field,uniform);\n\n");
-
+/*
+       if(fMagBG->GetButton(kFld0)->GetState())     fprintf(fp,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2, 0,1,10.,2));//no field\n");
+  else if(fMagBG->GetButton(kFld2)->GetState())     fprintf(fp,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2, 1,1,10,AliMagF::k2kG));//0.2 Tesla field\n");
+  else if(fMagBG->GetButton(kFld4)->GetState())     fprintf(fp,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2, 1,1,10,AliMagF::k4kG));//0.4 Tesla field\n");
+  else if(fMagBG->GetButton(kFld5)->GetState())     fprintf(fp,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2, 1,1,10,AliMagF::k5kG));//0.5 Tesla field\n");
+  else if(fMagBG->GetButton(kFld_2)->GetState())    fprintf(fp,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,AliMagF::k2kG));//-0.2 Tesla field\n");
+  else if(fMagBG->GetButton(kFld_4)->GetState())    fprintf(fp,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,AliMagF::k4kG));//-0.4 Tesla field\n");
+  else if(fMagBG->GetButton(kFld_5)->GetState())    fprintf(fp,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,AliMagF::k5kG));//-0.5 Tesla field\n");
+*/  
                                                     fprintf(fp,"  AliReconstruction *pRec=new AliReconstruction;\n");
                                                     fprintf(fp,"  gBenchmark->Start(\"ALICE\"); TDatime time;      //start benchmarking\n\n");
                                                     
@@ -797,13 +793,13 @@ void HmpConfig::WriteConfig()
   WritePhys(pF); //physics processes
   
 //Field
-       if(fMagBG->GetButton(kFld0)->GetState())     fprintf(pF,"  gAlice->SetField(new AliMagF(\"Maps\",\"Maps\",2,0,0,10,2));       //no field\n\n");
-  else if(fMagBG->GetButton(kFld2)->GetState())     fprintf(pF,"  gAlice->SetField(new AliMagF(\"Maps\",\"Maps\",2,1,1,10,0));//0.2 Tesla field\n\n");
-  else if(fMagBG->GetButton(kFld4)->GetState())     fprintf(pF,"  gAlice->SetField(new AliMagF(\"Maps\",\"Maps\",2,1,1,10,1));//0.4 Tesla field\n\n");
-  else if(fMagBG->GetButton(kFld5)->GetState())     fprintf(pF,"  gAlice->SetField(new AliMagF(\"Maps\",\"Maps\",2,1,1,10,2));//0.5 Tesla field\n\n");
-  else if(fMagBG->GetButton(kFld_2)->GetState())    fprintf(pF,"  gAlice->SetField(new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,0));//-0.2 Tesla field\n\n");
-  else if(fMagBG->GetButton(kFld_4)->GetState())    fprintf(pF,"  gAlice->SetField(new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,1));//-0.4 Tesla field\n\n");
-  else if(fMagBG->GetButton(kFld_5)->GetState())    fprintf(pF,"  gAlice->SetField(new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,2));//-0.5 Tesla field\n\n");
+       if(fMagBG->GetButton(kFld0)->GetState())     fprintf(pF,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2, 0,1,10,AliMagF::k2kG));// NO field\n");
+  else if(fMagBG->GetButton(kFld2)->GetState())     fprintf(pF,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2, 1,1,10,AliMagF::k2kG));//0.2 Tesla field\n");
+  else if(fMagBG->GetButton(kFld4)->GetState())     fprintf(pF,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2, 1,1,10,AliMagF::k4kG));//0.4 Tesla field\n");
+  else if(fMagBG->GetButton(kFld5)->GetState())     fprintf(pF,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2, 1,1,10,AliMagF::k5kG));//0.5 Tesla field\n");
+  else if(fMagBG->GetButton(kFld_2)->GetState())    fprintf(pF,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,AliMagF::k2kG));//-0.2 Tesla field\n");
+  else if(fMagBG->GetButton(kFld_4)->GetState())    fprintf(pF,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,AliMagF::k4kG));//-0.4 Tesla field\n");
+  else if(fMagBG->GetButton(kFld_5)->GetState())    fprintf(pF,"  TGeoGlobalMagField::Instance()->SetField(new AliMagF(\"Maps\",\"Maps\",2,-1,1,10,AliMagF::k5kG));//-0.5 Tesla field\n");
   
   fprintf(pF,"  pAL->CdGAFile();\n\n");                                 //????       
 //Generator