CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  fwEvent->getRun().getByLabel(conditionsTag, runCond);
186 
187  if( runCond.isValid())
188  {
189  available = true;
190  m_eventField = currentToField * runCond->BAvgCurrent;
191  fwLog( fwlog::kDebug ) << "Magnetic field info found in ConditionsInEdm branch : "<< m_eventField << std::endl;
192  }
193  else
194  {
195  edm::InputTag dcsTag("scalersRawToDigi");
197  event->getByLabel(dcsTag, dcsStatus);
198 
199  if (dcsStatus.isValid() && dcsStatus->size())
200  {
201  float sum = 0;
202  for (std::vector<DcsStatus>::const_iterator i = dcsStatus->begin(); i < dcsStatus->end(); ++i)
203  sum += (*i).magnetCurrent();
204 
205  available = true;
206  m_eventField = currentToField * sum/dcsStatus->size();
207  fwLog( fwlog::kDebug) << "Magnetic field info found in DcsStatus branch: " << m_eventField << std::endl;
208  }
209 
210  }
211  }
212  catch (cms::Exception&)
213  {
214  fwLog( fwlog::kDebug ) << "Cought exception in FWMagField::checkFieldInfo\n";
215  }
216 
217  if (!available)
218  {
219  m_source = kNone;
220  fwLog( fwlog::kDebug ) << "No magnetic field info available in Event\n";
221  }
222 }
223 
int m_numberOfFieldEstimates
Definition: FWMagField.h:63
int i
Definition: DBlmapReader.cc:9
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:62
Float_t GetFieldMag() const
Definition: FWMagField.cc:85
bool m_simpleModel
Definition: FWMagField.h:58
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:507
bool m_reverse
Definition: FWMagField.h:57
bool m_updateFieldEstimate
Definition: FWMagField.h:64
TH1F * m_guessValHist
Definition: FWMagField.h:61
float float float z
ESource m_source
Definition: FWMagField.h:53
T sqrt(T t)
Definition: SSEVec.h:48
void guessField(float estimate) const
Definition: FWMagField.cc:155
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:76
void checkFieldInfo(const edm::EventBase *)
Definition: FWMagField.cc:172
#define fwLog(_level_)
Definition: fwLog.h:51
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const
Definition: Run.cc:219
float m_eventField
Definition: FWMagField.h:55
void guessFieldIsOn(bool guess) const
Definition: FWMagField.cc:148
Definition: DDAxes.h:10
virtual Float_t GetMaxFieldMag() const
Definition: FWMagField.cc:136
void resetFieldEstimate() const
Definition: FWMagField.cc:162
virtual ~FWMagField()
Definition: FWMagField.cc:32