]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMagFMaps.cxx
AliCollisionGeometry added.
[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 /*
17 $Log$
18 Revision 1.8  2002/10/14 14:57:32  hristov
19 Merging the VirtualMC branch to the main development branch (HEAD)
20
21 Revision 1.5.6.2  2002/08/01 15:35:30  alibrary
22 Updating VirtualMC
23
24 Revision 1.7  2002/08/01 12:34:48  morsch
25 Initialize maps in first call to Field() after streaming in.
26
27 Revision 1.6  2002/04/11 11:17:48  morsch
28 ReadField() used in Constructor.
29
30 Revision 1.5  2002/02/26 09:48:14  morsch
31 Extra argument in constructor for l3 map choice.
32
33 Revision 1.4  2002/02/22 14:00:20  morsch
34 Protection against replication of fieldmap data in gAlice.
35
36 Revision 1.3  2002/02/21 09:23:41  morsch
37 Create dummy field map for L3 in case no detailed map is needed.
38
39 Revision 1.2  2002/02/19 16:14:35  morsch
40 Reading of 0.2 T solenoid field map enabled.
41
42 Revision 1.1  2002/02/14 11:41:28  morsch
43 Magnetic field map for ALICE for L3+muon spectrometer stored in 3 seperate
44 root files.
45
46 */
47
48 //
49 // Author: Andreas Morsch <andreas.morsch@cern.ch>
50 //
51
52 #include <TFile.h>
53 #include <TSystem.h>
54
55 #include "AliFieldMap.h"
56 #include "AliMagFMaps.h"
57
58
59 ClassImp(AliMagFMaps)
60
61 //_______________________________________________________________________
62 AliMagFMaps::AliMagFMaps():
63   fSolenoid(0),
64   fL3Option(0),
65   fFieldRead(0)
66 {
67   //
68   // Default constructor
69   //
70   fFieldMap[0] = fFieldMap[1] = fFieldMap[2] = 0;
71 }
72
73 //_______________________________________________________________________
74 AliMagFMaps::AliMagFMaps(const char *name, const char *title, const Int_t integ, 
75                          const Float_t factor, const Float_t fmax, const Int_t map, 
76                          const Int_t l3):
77   AliMagF(name,title,integ,factor,fmax),
78   fSolenoid(0),
79   fL3Option(l3),
80   fFieldRead(0)
81 {
82   //
83   // Standard constructor
84   //
85   fType         = kConMesh;
86   fFieldMap[0]  = 0;
87   fMap          = map;
88   fL3Option     = l3;
89
90   ReadField();
91   fFieldRead = 1;
92   //
93   // Don't replicate field information in gAlice
94   for (Int_t i = 0; i < 3; i++)  fFieldMap[i]->SetWriteEnable(0);
95   //
96 }
97
98 //_______________________________________________________________________
99 AliMagFMaps::AliMagFMaps(const AliMagFMaps &magf):
100   AliMagF(magf),
101   fSolenoid(0),
102   fL3Option(0),
103   fFieldRead(0)
104 {
105   //
106   // Copy constructor
107   //
108   magf.Copy(*this);
109 }
110
111 //_______________________________________________________________________
112 AliMagFMaps::~AliMagFMaps()
113 {
114   //
115   //  Destructor
116   //
117   delete fFieldMap[0];
118   delete fFieldMap[1];
119   delete fFieldMap[2];    
120 }
121
122 //_______________________________________________________________________
123 void AliMagFMaps::ReadField()
124 {
125   //  Read Field Map from file
126   //
127   //  don't read twice
128   //
129   if (fFieldRead) return;
130   fFieldRead = 1;
131   //    
132   char* fname;
133   TFile* file = 0;
134   if (fMap == k2kG) {
135         if (fL3Option) {
136       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B02.root");
137       file = new TFile(fname);
138       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B02"));
139       file->Close();
140       delete file;
141         }
142         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB02.root");
143         file = new TFile(fname);
144         fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB02"));
145         file->Close();
146         delete file;;
147         
148         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB02.root");
149         file = new TFile(fname);
150         fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB02"));
151         file->Close();
152         delete file;
153         fSolenoid = 2.;
154   } else if (fMap == k4kG) {
155         if (fL3Option) {
156       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B04.root");
157       file = new TFile(fname);
158       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B04"));
159       file->Close();
160       delete file;
161         }
162         
163         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB04.root");
164         file = new TFile(fname);
165         fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB04"));
166         file->Close();
167         delete file;
168         
169         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB04.root");
170         file = new TFile(fname);
171         fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB04"));
172         file->Close();
173         delete file;
174         fSolenoid = 4.;
175   } else if (fMap == k5kG) {
176         if (fL3Option) {
177       fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/L3B05.root");
178       file = new TFile(fname);
179       fFieldMap[0] = dynamic_cast<AliFieldMap*>(file->Get("L3B05"));
180       file->Close();
181       delete file;
182         }
183         
184         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/DipB05.root");
185         file = new TFile(fname);
186         fFieldMap[1] = dynamic_cast<AliFieldMap*>(file->Get("DipB05"));
187         file->Close();
188         delete file;
189         
190         fname = gSystem->ExpandPathName("$(ALICE_ROOT)/data/maps/ExtB05.root");
191         file = new TFile(fname);
192         fFieldMap[2] = dynamic_cast<AliFieldMap*>(file->Get("ExtB05"));
193         file->Close();
194         delete file;
195         
196         fSolenoid = 5.;
197   }
198   
199   if (!fL3Option) {
200     //
201     // Dummy L3 map
202         fFieldMap[0] = new AliFieldMap();
203         fFieldMap[0] -> SetLimits(-800., 800., -800., 800., -700., 700.);
204   }
205 }
206
207 //_______________________________________________________________________
208 Float_t AliMagFMaps::SolenoidField() const
209 {
210   //
211   // Returns max. L3 (solenoid) field strength 
212   // according to field map setting 
213   //
214   return fSolenoid;
215 }
216
217 //_______________________________________________________________________
218 void AliMagFMaps::Field(Float_t *x, Float_t *b)
219 {
220   //
221   // Method to calculate the magnetic field
222   //
223   // --- find the position in the grid ---
224   
225   if (!fFieldRead) ReadField();
226   
227   b[0]=b[1]=b[2]=0;
228   AliFieldMap* map = 0;
229   if (fFieldMap[0]->Inside(x[0], x[1], x[2])) {
230     map = fFieldMap[0];
231     if (!fL3Option) {
232       //
233       //     Constant L3 field, if this option was selected
234       //
235           b[2] = fSolenoid;
236           return;
237     }
238   } else if (fFieldMap[1]->Inside(x[0], x[1], x[2])) {
239     map = fFieldMap[1];
240   } else if (fFieldMap[2]->Inside(x[0], x[1], x[2])) {
241     map = fFieldMap[2];
242   }
243   
244   if(map){
245     map->Field(x,b);
246   } else {
247     //This is the ZDC part
248     Float_t rad2=x[0]*x[0]+x[1]*x[1];
249     if(x[2]>kCORBEG2 && x[2]<kCOREND2){
250           if(rad2<kCOR2RA2){
251         b[0] = kFCORN2;
252           }
253     }
254     else if(x[2]>kZ1BEG && x[2]<kZ1END){  
255           if(rad2<kZ1RA2){
256         b[0] = -kG1*x[1];
257         b[1] = -kG1*x[0];
258           }
259     }
260     else if(x[2]>kZ2BEG && x[2]<kZ2END){  
261           if(rad2<kZ2RA2){
262         b[0] = kG1*x[1];
263         b[1] = kG1*x[0];
264           }
265     }
266     else if(x[2]>kZ3BEG && x[2]<kZ3END){  
267           if(rad2<kZ3RA2){
268         b[0] = kG1*x[1];
269         b[1] = kG1*x[0];
270           }
271     }
272     else if(x[2]>kZ4BEG && x[2]<kZ4END){  
273           if(rad2<kZ4RA2){
274         b[0] = -kG1*x[1];
275         b[1] = -kG1*x[0];
276           }
277     }
278     else if(x[2]>kD1BEG && x[2]<kD1END){ 
279           if(rad2<kD1RA2){
280         b[1] = -kFDIP;
281           }
282     }
283     else if(x[2]>kD2BEG && x[2]<kD2END){
284           if(((x[0]-kXCEN1D2)*(x[0]-kXCEN1D2)+(x[1]-kYCEN1D2)*(x[1]-kYCEN1D2))<kD2RA2
285              || ((x[0]-kXCEN2D2)*(x[0]-kXCEN2D2)+(x[1]-kYCEN2D2)*(x[1]-kYCEN2D2))<kD2RA2){
286         b[1] = kFDIP;
287           }
288     }
289   }
290   if(fFactor!=1) {
291     b[0]*=fFactor;
292     b[1]*=fFactor;
293     b[2]*=fFactor;
294   }
295 }
296
297 //_______________________________________________________________________
298 void AliMagFMaps::Copy(AliMagFMaps & /* magf */) const
299 {
300   //
301   // Copy *this onto magf -- Not implemented
302   //
303   Fatal("Copy","Not implemented!\n");
304 }
305
306 //_______________________________________________________________________
307 void AliMagFMaps::Streamer(TBuffer &R__b)
308 {
309   // Stream an object of class AliMagFMaps.
310   if (R__b.IsReading()) {
311     AliMagFMaps::Class()->ReadBuffer(R__b, this);
312     fFieldRead = 0;
313   } else {
314     AliMagFMaps::Class()->WriteBuffer(R__b, this);
315   }
316 }