CMS 3D CMS Logo

FWMagField.cc
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include "TH1F.h"
10 
12  TEveMagField(),
13 
14  m_source(kNone),
15  m_userField(-1),
16  m_eventField(-1),
17 
18  m_reverse(true),
19  m_simpleModel(false),
20 
21  m_guessValHist(0),
22  m_numberOfFieldIsOnEstimates(0),
23  m_numberOfFieldEstimates(0),
24  m_updateFieldEstimate(true),
25  m_guessedField(0)
26 {
27  m_guessValHist = new TH1F("FieldEstimations", "Field estimations from tracks and muons",
28  200, -4.5, 4.5);
29  m_guessValHist->SetDirectory(0);
30 }
31 
33 {
34  delete m_guessValHist;
35 }
36 
37 //______________________________________________________________________________
38 
39 TEveVector
40 FWMagField::GetField(Float_t x, Float_t y, Float_t z) const
41 {
42  // Virtual method of TEveMagField class.
43 
44  Float_t R = sqrt(x*x+y*y);
45  Float_t field = m_reverse ? -GetFieldMag() : GetFieldMag();
46 
47  //barrel
48  if ( TMath::Abs(z)<724 ){
49 
50  //inside solenoid
51  if ( R < 300) return TEveVector(0,0,field);
52  // outside solinoid
53  if ( m_simpleModel ||
54  ( R>461.0 && R<490.5 ) ||
55  ( R>534.5 && R<597.5 ) ||
56  ( R>637.0 && R<700.0 ) )
57  return TEveVector(0,0,-field/3.8*1.2);
58 
59  } else {
60  // endcaps
61  if (m_simpleModel){
62  if ( R < 50 ) return TEveVector(0,0,field);
63  if ( z > 0 )
64  return TEveVector(x/R*field/3.8*2.0, y/R*field/3.8*2.0, 0);
65  else
66  return TEveVector(-x/R*field/3.8*2.0, -y/R*field/3.8*2.0, 0);
67  }
68  // proper model
69  if ( ( ( TMath::Abs(z)>724 ) && ( TMath::Abs(z)<786 ) ) ||
70  ( ( TMath::Abs(z)>850 ) && ( TMath::Abs(z)<910 ) ) ||
71  ( ( TMath::Abs(z)>975 ) && ( TMath::Abs(z)<1003 ) ) )
72  {
73  if ( z > 0 )
74  return TEveVector(x/R*field/3.8*2.0, y/R*field/3.8*2.0, 0);
75  else
76  return TEveVector(-x/R*field/3.8*2.0, -y/R*field/3.8*2.0, 0);
77  }
78  }
79  return TEveVector(0,0,0);
80 }
81 
82 //______________________________________________________________________________
83 
84 Float_t
86 {
87  float res;
88  switch ( m_source )
89  {
90  case kEvent:
91  {
92  res = m_eventField;
93  break;
94  }
95  case kUser:
96  {
97  res = m_userField;
98  break;
99  }
100  default:
101  {
102  if ( m_updateFieldEstimate )
103  {
104  if ( m_guessValHist->GetEntries() > 2 && m_guessValHist->GetRMS() < 0.5 )
105  {
106  m_guessedField = m_guessValHist->GetMean();
107 
108 
109  // std::cout << "FWMagField::GetFieldMag(), get average "
110  // << m_guessValHist->GetMean() << " guessed value: RMS= "<< m_guessValHist->GetRMS()
111  // <<" samples "<< m_guessValHist->GetEntries() << std::endl;
112 
113  }
115  {
116  m_guessedField = 3.8;
117  // fwLog(fwlog::kDebug) << "FWMagField::GetFieldMag() get default field, number estimates "
118  // << m_numberOfFieldEstimates << " number fields is on m_numberOfFieldIsOnEstimates" <<std::endl;
119  }
120  else
121  {
122  m_guessedField = 0;
123  // fwLog(fwlog::kDebug) << "Update field estimate, guess field is OFF." <<std::endl;
124  }
125  m_updateFieldEstimate = false;
126  }
127 
128  res = m_guessedField;
129  }
130  }
131 
132  return res;
133 }
134 
135 Float_t
137 {
138  // Runge-Kutta stepper does not like this to be zero.
139  // Will be fixed in root.
140  // The return value should definitley not be negative -- so Abs
141  // should stay!
142 
143  return TMath::Max(TMath::Abs(GetFieldMag()), 0.01f);
144 }
145 
146 //______________________________________________________________________________
147 
148 void FWMagField::guessFieldIsOn(bool isOn) const
149 {
150  if ( isOn ) ++m_numberOfFieldIsOnEstimates;
152  m_updateFieldEstimate = true;
153 }
154 
155 void FWMagField::guessField(float val) const
156 {
157  // fwLog(filedDebug) << "FWMagField::guessField "<< val << std::endl;
158  m_guessValHist->Fill(val);
159  m_updateFieldEstimate = true;
160 }
161 
163 {
164  m_guessValHist->Reset();
165  m_guessValHist->SetAxisRange(-4, 4);
168  m_updateFieldEstimate = true;
169 }
170 
171 //______________________________________________________________________________
173 {
174  const static float currentToField = 3.8/18160;
175  bool available = false;
176  try
177  {
178  edm::InputTag conditionsTag("conditionsInEdm");
180  // FIXME: ugly hack to avoid exposing an fwlite::Event. Need to ask
181  // Chris / Ianna how to get mag field from an EventBase.
182  const fwlite::Event *fwEvent = dynamic_cast<const fwlite::Event*>(event);
183  if (!fwEvent)
184  return;
185 
186  m_source = kNone;
187  fwEvent->getRun().getByLabel(conditionsTag, runCond);
188 
189  if( runCond.isValid())
190  {
191  available = true;
192  m_eventField = currentToField * runCond->BAvgCurrent;
193  m_source = kEvent;
194  fwLog( fwlog::kDebug ) << "Magnetic field info found in ConditionsInEdm branch : "<< m_eventField << std::endl;
195  }
196  else
197  {
198  edm::InputTag dcsTag("scalersRawToDigi");
200  event->getByLabel(dcsTag, dcsStatus);
201 
202  if (dcsStatus.isValid() && dcsStatus->size())
203  {
204  float sum = 0;
205  for (std::vector<DcsStatus>::const_iterator i = dcsStatus->begin(); i < dcsStatus->end(); ++i)
206  sum += (*i).magnetCurrent();
207 
208  available = true;
209  m_eventField = currentToField * sum/dcsStatus->size();
210  m_source = kEvent;
211  fwLog( fwlog::kDebug) << "Magnetic field info found in DcsStatus branch: " << m_eventField << std::endl;
212  }
213 
214  }
215  }
216  catch (cms::Exception&)
217  {
218  fwLog( fwlog::kDebug ) << "Cought exception in FWMagField::checkFieldInfo\n";
219  }
220 
221  if (!available)
222  {
223  fwLog( fwlog::kDebug ) << "No magnetic field info available in Event\n";
224  }
225 }
226 
227 
228 //______________________________________________________________________________
230 {
231  // AMT this is a workaround for seting FF in FFLooper
232  // Correct imeplementation is having a base class of FWMagField amd do implementation for FF and FWLite version
233 
234  m_source = kEvent;
235  m_eventField = mag;
236 }
int m_numberOfFieldEstimates
Definition: FWMagField.h:63
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:62
Float_t GetFieldMag() const
Definition: FWMagField.cc:85
bool m_simpleModel
Definition: FWMagField.h:58
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
float m_guessedField
Definition: FWMagField.h:65
virtual TEveVector GetField(Float_t x, Float_t y, Float_t z) const
Definition: FWMagField.cc:40
fwlite::Run const & getRun() const
Definition: Event.cc:530
bool m_reverse
Definition: FWMagField.h:57
bool m_updateFieldEstimate
Definition: FWMagField.h:64
TH1F * m_guessValHist
Definition: FWMagField.h:61
Definition: Electron.h:4
void setFFFieldMag(float)
Definition: FWMagField.cc:229
ESource m_source
Definition: FWMagField.h:53
T sqrt(T t)
Definition: SSEVec.h:18
void guessField(float estimate) const
Definition: FWMagField.cc:155
T Abs(T a)
Definition: MathUtil.h:49
double f[11][100]
float m_userField
Definition: FWMagField.h:54
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:74
T Max(T a, T b)
Definition: MathUtil.h:44
void checkFieldInfo(const edm::EventBase *)
Definition: FWMagField.cc:172
#define fwLog(_level_)
Definition: fwLog.h:50
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const
Definition: Run.cc:217
float m_eventField
Definition: FWMagField.h:55
void guessFieldIsOn(bool guess) const
Definition: FWMagField.cc:148
virtual Float_t GetMaxFieldMag() const
Definition: FWMagField.cc:136
void resetFieldEstimate() const
Definition: FWMagField.cc:162
virtual ~FWMagField()
Definition: FWMagField.cc:32
Definition: event.py:1