]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliMagFMaps.cxx
Corected mass histograms and calculation of efficiencies (T.Kuhr)
[u/mrichter/AliRoot.git] / STEER / AliMagFMaps.cxx
index 99eafbd166e86a5c0e57401eca834f0c7ff68367..aa43984d1c3aef1fe61d4cc13a9cfbe907cc6c36 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.3  2002/02/21 09:23:41  morsch
-Create dummy field map for L3 in case no detailed map is needed.
+/* $Id$ */
 
-Revision 1.2  2002/02/19 16:14:35  morsch
-Reading of 0.2 T solenoid field map enabled.
-
-Revision 1.1  2002/02/14 11:41:28  morsch
-Magnetic field map for ALICE for L3+muon spectrometer stored in 3 seperate
-root files.
-
-*/
-
-//
+//------------------------------------------------------------------------
+// Magnetic field composed by 3 maps: the L3 magnet, extended region, and
+// dipole magnet
+// Used in the configuration macros (macros/Config.C, etc.)
 // Author: Andreas Morsch <andreas.morsch@cern.ch>
-//
+//------------------------------------------------------------------------
 
 #include <TFile.h>
 #include <TSystem.h>
+#include <TVector.h>
+
 #include "AliFieldMap.h"
 #include "AliMagFMaps.h"
 
-
 ClassImp(AliMagFMaps)
 
-//________________________________________
-AliMagFMaps::AliMagFMaps(const char *name, const char *title, const Int_t integ, 
-                    const Float_t factor, const Float_t fmax, const Int_t map)
-  : AliMagF(name,title,integ,factor,fmax)
+//_______________________________________________________________________
+AliMagFMaps::AliMagFMaps():
+  fSolenoid(0),
+  fSolenoidUser(0.),
+  fL3Option(0),
+  fFieldRead(0)
+{
+  //
+  // Default constructor
+  //
+  fFieldMap[0] = fFieldMap[1] = fFieldMap[2] = 0;
+}
+
+//_______________________________________________________________________
+AliMagFMaps::AliMagFMaps(const char *name, const char *title, Int_t integ, 
+                         Float_t factor, Float_t fmax, Int_t map, 
+                         Int_t l3):
+  AliMagFC(name,title,integ,factor,fmax),
+  fSolenoid(0),
+  fSolenoidUser(0),
+  fL3Option(l3),
+  fFieldRead(0)
 {
   //
   // Standard constructor
   //
   fType         = kConMesh;
   fFieldMap[0]  = 0;
+  fMap          = map;
+  fL3Option     = l3;
+  ReadField();
+  fFieldRead = 1;
+  //
+  // Don't replicate field information in gAlice
+  for (Int_t i = 0; i < 3; i++)  fFieldMap[i]->SetWriteEnable(0);
+  //
+}
+
+//_______________________________________________________________________
+AliMagFMaps::AliMagFMaps(const AliMagFMaps &magf):
+  AliMagFC(magf),
+  fSolenoid(0),
+  fL3Option(0),
+  fFieldRead(0)
+{
+  //
+  // Copy constructor
+  //
+  magf.Copy(*this);
+}
+
+//_______________________________________________________________________
+AliMagFMaps::~AliMagFMaps()
+{
+  //
+  //  Destructor
+  //
+  delete fFieldMap[0];
+  delete fFieldMap[1];
+  delete fFieldMap[2];    
+}
+
+//_______________________________________________________________________
+void AliMagFMaps::ReadField()
+{
+  //  Read Field Map from file
+  //
+  //  don't read twice
+  //
+  if (fFieldRead) return;
+  fFieldRead = 1;
+  //    
   char* fname;
-  
-  fMap = map;
   TFile* file = 0;
   if (fMap == k2kG) {
-      if (integ) {
-         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B02.root");
-         file = new TFile(fname);
-         fFieldMap[0] = (AliFieldMap*) file->Get("L3B02");
-         file->Close();
-         delete file;
-      }
+      fSolenoid = 2.;
+      fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B02.root");
+      file = new TFile(fname);
+      fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B02"));
+      file->Close();
+      delete file;
       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB02.root");
       file = new TFile(fname);
-      fFieldMap[1] = (AliFieldMap*) file->Get("DipB02");
+      fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB02"));
       file->Close();
       delete file;;
       
       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB02.root");
       file = new TFile(fname);
-      fFieldMap[2] = (AliFieldMap*) file->Get("ExtB02");
+      fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB02"));
       file->Close();
       delete file;
-      fSolenoid = 2.;
   } else if (fMap == k4kG) {
-      if (integ) {
-         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B04.root");
-         file = new TFile(fname);
-         fFieldMap[0] = (AliFieldMap*) file->Get("L3B04");
-         file->Close();
-         delete file;
-      }
-      
+      fSolenoid = 4.;
+      fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B04.root");
+      file = new TFile(fname);
+      fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B04"));
+      file->Close();
+      delete file;
       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB04.root");
       file = new TFile(fname);
-      fFieldMap[1] = (AliFieldMap*) file->Get("DipB04");
+      fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB04"));
       file->Close();
-      delete file;;
+      delete file;
       
       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB04.root");
       file = new TFile(fname);
-      fFieldMap[2] = (AliFieldMap*) file->Get("ExtB04");
+      fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB04"));
       file->Close();
       delete file;
-      fSolenoid = 4.;
   } else if (fMap == k5kG) {
-      if (integ) {
-         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B05.root");
-         file = new TFile(fname);
-         fFieldMap[0] = (AliFieldMap*) file->Get("L3B05");
-         file->Close();
-         delete file;
-      }
-      
+      fSolenoid = 5.;
+      fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B05.root");
+      file = new TFile(fname);
+      fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B05"));
+      file->Close();
+      delete file;
       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB05.root");
       file = new TFile(fname);
-      fFieldMap[1] = (AliFieldMap*) file->Get("DipB05");
+      fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB05"));
       file->Close();
-      delete file;;
+      delete file;
       
       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB05.root");
       file = new TFile(fname);
-      fFieldMap[2] = (AliFieldMap*) file->Get("ExtB05");
+      fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB05"));
       file->Close();
       delete file;
-      
-      fSolenoid = 5.;
   }
 
-  if (!integ) {
-//
-// Dummy L3 map
-      fFieldMap[0] = new AliFieldMap();
-      fFieldMap[0] -> SetLimits(-800., 800., -800., 800., -700., 700.);
-  }
-  
-//
-// Don't replicate field information in gAlice
-  for (Int_t i = 0; i < 3; i++)  fFieldMap[i]->SetWriteEnable(0);
-//
-  SetL3ConstField(0);
-}
+  if (!fL3Option) fSolenoidUser = fSolenoid;
 
-//________________________________________
-AliMagFMaps::AliMagFMaps(const AliMagFMaps &magf)
-{
-  //
-  // Copy constructor
-  //
-  magf.Copy(*this);
 }
 
-AliMagFMaps::~AliMagFMaps()
-{
-//
-//  Destructor
-//
-    delete fFieldMap[0];
-    delete fFieldMap[1];
-    delete fFieldMap[2];    
-}
-
-
+//_______________________________________________________________________
 Float_t AliMagFMaps::SolenoidField() const
 {
-//
-// Returns max. L3 (solenoid) field strength 
-// according to field map setting
-
-    return fSolenoid;
+  //
+  // Returns max. L3 (solenoid) field strength 
+  // according to field map setting 
+  //
+  return fSolenoid;
 }
 
-    
-
-//________________________________________
+//_______________________________________________________________________
 void AliMagFMaps::Field(Float_t *x, Float_t *b)
 {
   //
@@ -171,69 +183,51 @@ void AliMagFMaps::Field(Float_t *x, Float_t *b)
   //
   // --- find the position in the grid ---
   
+
+    
+    if (!fFieldRead) ReadField();
+
+  //
+  // Field Maps have been calculated for the coordinate system in which 
+  // the Muon Spectrometer is placed at z > 0
+  // Transform coordinates corresponingly 
+  //
+  
   b[0]=b[1]=b[2]=0;
+  Float_t xm[3];
+  xm[0] = - x[0];
+  xm[1] =   x[1];
+  xm[2] = - x[2];
+  
   AliFieldMap* map = 0;
-  if (fFieldMap[0]->Inside(x[0], x[1], x[2])) {
+  if (fFieldMap[0]->Inside(xm[0], xm[1], xm[2])) {
       map = fFieldMap[0];
-      if (fL3Option) {
-//
-//     Constant L3 field, if this option was selected
-//
-         b[2] = fSolenoid;
+      Float_t r = TMath::Sqrt(xm[0] * xm[0] + xm[1] * xm[1]);
+      
+      if (!fL3Option && TMath::Abs(xm[2]) < 370. && r < 550.) {
+      //
+      //     Constant L3 field , if this option was selected
+      //
+         b[2] = - fSolenoid;
          return;
-      }
-  } else if (fFieldMap[1]->Inside(x[0], x[1], x[2])) {
-      map = fFieldMap[1];
-  } else if (fFieldMap[2]->Inside(x[0], x[1], x[2])) {
-      map = fFieldMap[2];
+      } 
+  } else if (fFieldMap[1]->Inside(xm[0], xm[1], xm[2])) {
+    map = fFieldMap[1];
+  } else if (fFieldMap[2]->Inside(xm[0], xm[1], xm[2])) {
+    map = fFieldMap[2];
   }
   
   if(map){
-      map->Field(x,b);
+    map->Field(xm,b);
+    b[0] = - b[0];
+    b[2] = - b[2];
+
   } else {
-//This is the ZDC part
-      Float_t rad2=x[0]*x[0]+x[1]*x[1];
-      if(x[2]>kCORBEG2 && x[2]<kCOREND2){
-         if(rad2<kCOR2RA2){
-             b[0] = kFCORN2;
-         }
-      }
-      else if(x[2]>kZ1BEG && x[2]<kZ1END){  
-         if(rad2<kZ1RA2){
-             b[0] = -kG1*x[1];
-             b[1] = -kG1*x[0];
-         }
-      }
-      else if(x[2]>kZ2BEG && x[2]<kZ2END){  
-         if(rad2<kZ2RA2){
-             b[0] = kG1*x[1];
-             b[1] = kG1*x[0];
-         }
-      }
-      else if(x[2]>kZ3BEG && x[2]<kZ3END){  
-         if(rad2<kZ3RA2){
-             b[0] = kG1*x[1];
-             b[1] = kG1*x[0];
-         }
-      }
-      else if(x[2]>kZ4BEG && x[2]<kZ4END){  
-         if(rad2<kZ4RA2){
-             b[0] = -kG1*x[1];
-             b[1] = -kG1*x[0];
-         }
-      }
-      else if(x[2]>kD1BEG && x[2]<kD1END){ 
-         if(rad2<kD1RA2){
-             b[1] = -kFDIP;
-         }
-      }
-      else if(x[2]>kD2BEG && x[2]<kD2END){
-         if(((x[0]-kXCEN1D2)*(x[0]-kXCEN1D2)+(x[1]-kYCEN1D2)*(x[1]-kYCEN1D2))<kD2RA2
-            || ((x[0]-kXCEN2D2)*(x[0]-kXCEN2D2)+(x[1]-kYCEN2D2)*(x[1]-kYCEN2D2))<kD2RA2){
-             b[1] = kFDIP;
-         }
-      }
+      //This is the ZDC part
+      ZDCField(x, b);
   }
+
+  
   if(fFactor!=1) {
       b[0]*=fFactor;
       b[1]*=fFactor;
@@ -241,8 +235,8 @@ void AliMagFMaps::Field(Float_t *x, Float_t *b)
   }
 }
 
-//________________________________________
-void AliMagFMaps::Copy(AliMagFMaps & /* magf */) const
+//_______________________________________________________________________
+void AliMagFMaps::Copy(TObject & /* magf */) const
 {
   //
   // Copy *this onto magf -- Not implemented
@@ -250,9 +244,14 @@ void AliMagFMaps::Copy(AliMagFMaps & /* magf */) const
   Fatal("Copy","Not implemented!\n");
 }
 
-//________________________________________
-AliMagFMaps & AliMagFMaps::operator =(const AliMagFMaps &magf)
+//_______________________________________________________________________
+void AliMagFMaps::Streamer(TBuffer &R__b)
 {
-  magf.Copy(*this);
-  return *this;
+  // Stream an object of class AliMagFMaps.
+  if (R__b.IsReading()) {
+    AliMagFMaps::Class()->ReadBuffer(R__b, this);
+    fFieldRead = 0;
+  } else {
+    AliMagFMaps::Class()->WriteBuffer(R__b, this);
+  }
 }