]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMagFMaps.cxx
Memory leak corrected (Ch. Klein-Boesing)
[u/mrichter/AliRoot.git] / STEER / AliMagFMaps.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //------------------------------------------------------------------------
19 // Magnetic field composed by 3 maps: the L3 magnet, extended region, and
20 // dipole magnet
21 // Used in the configuration macros (macros/Config.C, etc.)
22 // Author: Andreas Morsch <andreas.morsch@cern.ch>
23 //------------------------------------------------------------------------
24
25 #include <TClass.h>
26 #include <TFile.h>
27 #include <TMath.h>
28 #include <TSystem.h>
29
30 #include "AliLog.h"
31 #include "AliFieldMap.h"
32 #include "AliMagFMaps.h"
33
34 ClassImp(AliMagFMaps)
35     
36
37 //_______________________________________________________________________
38 AliMagFMaps::AliMagFMaps():
39   fSolenoid(0),
40   fSolenoidUser(0.),
41   fL3Option(0)
42 {
43   //
44   // Default constructor
45   //
46   //
47   // Don't replicate field information in gAlice
48   fFieldMap[0] = fFieldMap[1] = fFieldMap[2] = 0;
49 }
50
51 //_______________________________________________________________________
52 AliMagFMaps::AliMagFMaps(const char *name, const char *title, Int_t integ, 
53                          Float_t factor, Float_t fmax, Int_t map, 
54                          Int_t l3):
55   AliMagFC(name,title,integ,factor,fmax),
56   fSolenoid(0),
57   fSolenoidUser(0),
58   fL3Option(l3)
59 {
60   //
61   // Standard constructor
62   //
63   fType         = kConMesh;
64   fFieldMap[0]  = 0;
65   fMap          = map;
66   fL3Option     = l3;
67   ReadField();
68   //
69   // Don't replicate field information in gAlice
70   for (Int_t i = 0; i < 3; i++)  fFieldMap[i]->SetWriteEnable(0);
71   //
72 }
73
74 //_______________________________________________________________________
75 AliMagFMaps::AliMagFMaps(const AliMagFMaps &magf):
76   AliMagFC(magf),
77   fSolenoid(0),
78   fSolenoidUser(0),
79   fL3Option(0)
80 {
81   //
82   // Copy constructor
83   //
84   magf.Copy(*this);
85 }
86
87 //_______________________________________________________________________
88 AliMagFMaps::~AliMagFMaps()
89 {
90   //
91   //  Destructor
92   //
93   delete fFieldMap[0];
94   delete fFieldMap[1];
95   delete fFieldMap[2];    
96 }
97
98 //_______________________________________________________________________
99 void AliMagFMaps::ReadField()
100 {
101   //  Read Field Map from file
102   //
103   //  don't read twice
104   //
105     if (!fReadField) return;
106     fReadField = kFALSE;
107   //    
108    
109
110   char* fname;
111   TFile* file = 0;
112   if (fMap == k2kG) {
113       fSolenoid = 2.;
114       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B02.root");
115       file = new TFile(fname);
116       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B02"));
117       file->Close();
118       delete file;
119       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB02.root");
120       file = new TFile(fname);
121       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB02"));
122       file->Close();
123       delete file;;
124       
125       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB02.root");
126       file = new TFile(fname);
127       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB02"));
128       file->Close();
129       delete file;
130   } else if (fMap == k4kG) {
131       fSolenoid = 4.;
132       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B04.root");
133       file = new TFile(fname);
134       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B04"));
135       file->Close();
136       delete file;
137       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB04.root");
138       file = new TFile(fname);
139       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB04"));
140       file->Close();
141       delete file;
142       
143       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB04.root");
144       file = new TFile(fname);
145       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB04"));
146       file->Close();
147       delete file;
148   } else if (fMap == k5kG) {
149       fSolenoid = 5.;
150       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B05.root");
151       file = new TFile(fname);
152       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B05"));
153       file->Close();
154       delete file;
155       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB05.root");
156       file = new TFile(fname);
157       fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB05"));
158       file->Close();
159       delete file;
160       
161       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB05.root");
162       file = new TFile(fname);
163       fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB05"));
164       file->Close();
165       delete file;
166   }
167
168   if (!fL3Option) fSolenoidUser = fSolenoid;
169
170 }
171
172 //_______________________________________________________________________
173 Float_t AliMagFMaps::SolenoidField() const
174 {
175   //
176   // Returns max. L3 (solenoid) field strength 
177   // according to field map setting 
178   //
179   return -Factor()*fSolenoid;
180 }
181
182 //_______________________________________________________________________
183 void AliMagFMaps::Field(Float_t *x, Float_t *b) const
184 {
185   //
186   // Method to calculate the magnetic field
187   //
188   // --- find the position in the grid ---
189   
190
191     
192  //    if (!fFieldRead) ReadField();
193
194   //
195   // Field Maps have been calculated for the coordinate system in which 
196   // the Muon Spectrometer is placed at z > 0
197   // Transform coordinates corresponingly 
198   //
199   
200   b[0]=b[1]=b[2]=0;
201   Float_t xm[3];
202   xm[0] = - x[0];
203   xm[1] =   x[1];
204   xm[2] = - x[2];
205   
206   AliFieldMap* map = 0;
207   if (fFieldMap[0]->Inside(xm[0], xm[1], xm[2])) {
208       map = fFieldMap[0];
209       Float_t r = TMath::Sqrt(xm[0] * xm[0] + xm[1] * xm[1]);
210       
211       if (!fL3Option && TMath::Abs(xm[2]) < 370. && r < 550.) {
212       //
213       //     Constant L3 field , if this option was selected
214       //
215         b[2] = (- fSolenoid)*fFactor;
216           return;
217       } 
218   } else if (fFieldMap[1]->Inside(xm[0], xm[1], xm[2])) {
219     map = fFieldMap[1];
220   } else if (fFieldMap[2]->Inside(xm[0], xm[1], xm[2])) {
221     map = fFieldMap[2];
222   }
223   
224   if(map){
225     map->Field(xm,b);
226     b[0] = - b[0];
227     b[2] = - b[2];
228
229   } else {
230       //This is the ZDC part
231       ZDCField(x, b);
232   }
233
234   
235   if(fFactor!=1) {
236       b[0]*=fFactor;
237       b[1]*=fFactor;
238       b[2]*=fFactor;
239   }
240 }
241
242 //_______________________________________________________________________
243 void AliMagFMaps::Copy(TObject & /* magf */) const
244 {
245   //
246   // Copy *this onto magf -- Not implemented
247   //
248   AliFatal("Not implemented!");
249 }
250
251 //_______________________________________________________________________
252 void AliMagFMaps::Streamer(TBuffer &R__b)
253 {
254   // Stream an object of class AliMagFMaps.
255   if (R__b.IsReading()) {
256    R__b.ReadClassBuffer(AliMagFMaps::Class(), this);
257    // 
258    fReadField = kTRUE;
259    ReadField();
260   } else {
261     R__b.WriteClassBuffer(AliMagFMaps::Class(), this);
262   }
263 }