CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
FWMagField Class Reference

#include <FWMagField.h>

Inheritance diagram for FWMagField:

Public Types

enum  ESource { kNone, kEvent, kUser }
 

Public Member Functions

void checkFieldInfo (const edm::EventBase *)
 
 FWMagField ()
 
TEveVector GetField (Float_t x, Float_t y, Float_t z) const override
 
Float_t GetMaxFieldMag () const override
 
ESource getSource () const
 
float getUserField () const
 
void guessField (float estimate) const
 
void guessFieldIsOn (bool guess) const
 
bool isReverse () const
 
bool isSimpleModel () const
 
void resetFieldEstimate () const
 
void setFFFieldMag (float)
 
void setReverseState (bool state)
 
void setSimpleModel (bool simpleModel)
 
void setSource (ESource x)
 
void setUserField (float b)
 
 ~FWMagField () override
 

Private Member Functions

 FWMagField (const FWMagField &)=delete
 
Float_t GetFieldMag () const
 
const FWMagFieldoperator= (const FWMagField &)=delete
 

Private Attributes

float m_eventField
 
float m_guessedField
 
TH1F * m_guessValHist
 
int m_numberOfFieldEstimates
 
int m_numberOfFieldIsOnEstimates
 
bool m_reverse
 
bool m_simpleModel
 
ESource m_source
 
bool m_updateFieldEstimate
 
float m_userField
 

Detailed Description

Definition at line 15 of file FWMagField.h.

Member Enumeration Documentation

Enumerator
kNone 
kEvent 
kUser 

Definition at line 20 of file FWMagField.h.

Constructor & Destructor Documentation

FWMagField::FWMagField ( )

Definition at line 11 of file FWMagField.cc.

References m_guessValHist.

11  :
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(nullptr),
26 {
27  m_guessValHist = new TH1F("FieldEstimations", "Field estimations from tracks and muons",
28  200, -4.5, 4.5);
29  m_guessValHist->SetDirectory(nullptr);
30 }
int m_numberOfFieldEstimates
Definition: FWMagField.h:63
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:62
bool m_simpleModel
Definition: FWMagField.h:58
float m_guessedField
Definition: FWMagField.h:65
bool m_reverse
Definition: FWMagField.h:57
bool m_updateFieldEstimate
Definition: FWMagField.h:64
TH1F * m_guessValHist
Definition: FWMagField.h:61
ESource m_source
Definition: FWMagField.h:53
float m_userField
Definition: FWMagField.h:54
float m_eventField
Definition: FWMagField.h:55
FWMagField::~FWMagField ( )
override

Definition at line 32 of file FWMagField.cc.

References m_guessValHist.

33 {
34  delete m_guessValHist;
35 }
TH1F * m_guessValHist
Definition: FWMagField.h:61
FWMagField::FWMagField ( const FWMagField )
privatedelete

Member Function Documentation

void FWMagField::checkFieldInfo ( const edm::EventBase event)

Definition at line 172 of file FWMagField.cc.

References edm::ConditionsInRunBlock::BAvgCurrent, event(), fwLog, fwlite::Run::getByLabel(), fwlite::Event::getRun(), mps_fire::i, edm::HandleBase::isValid(), fwlog::kDebug, kEvent, kNone, m_eventField, and m_source.

Referenced by CmsShowMainBase::draw().

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->empty())
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 }
fwlite::Run const & getRun() const
Definition: Event.cc:539
ESource m_source
Definition: FWMagField.h:53
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
bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const override
Definition: Run.cc:217
#define fwLog(_level_)
Definition: fwLog.h:50
float m_eventField
Definition: FWMagField.h:55
TEveVector FWMagField::GetField ( Float_t  x,
Float_t  y,
Float_t  z 
) const
override

Definition at line 40 of file FWMagField.cc.

References Abs(), GetFieldMag(), m_reverse, m_simpleModel, dttmaxenums::R, and mathSSE::sqrt().

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 }
Float_t GetFieldMag() const
Definition: FWMagField.cc:85
bool m_simpleModel
Definition: FWMagField.h:58
bool m_reverse
Definition: FWMagField.h:57
T sqrt(T t)
Definition: SSEVec.h:18
T Abs(T a)
Definition: MathUtil.h:49
Float_t FWMagField::GetFieldMag ( ) const
private

Definition at line 85 of file FWMagField.cc.

References kEvent, kUser, m_eventField, m_guessedField, m_guessValHist, m_numberOfFieldEstimates, m_numberOfFieldIsOnEstimates, m_source, m_updateFieldEstimate, and m_userField.

Referenced by GetField(), and GetMaxFieldMag().

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 }
int m_numberOfFieldEstimates
Definition: FWMagField.h:63
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:62
float m_guessedField
Definition: FWMagField.h:65
bool m_updateFieldEstimate
Definition: FWMagField.h:64
TH1F * m_guessValHist
Definition: FWMagField.h:61
Definition: Electron.h:4
ESource m_source
Definition: FWMagField.h:53
float m_userField
Definition: FWMagField.h:54
float m_eventField
Definition: FWMagField.h:55
Float_t FWMagField::GetMaxFieldMag ( ) const
override

Definition at line 136 of file FWMagField.cc.

References Abs(), f, GetFieldMag(), and Max().

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 }
Float_t GetFieldMag() const
Definition: FWMagField.cc:85
T Abs(T a)
Definition: MathUtil.h:49
double f[11][100]
T Max(T a, T b)
Definition: MathUtil.h:44
ESource FWMagField::getSource ( ) const
inline

Definition at line 33 of file FWMagField.h.

Referenced by FWMuonBuilder::calculateField(), CmsShowMainBase::draw(), and CmsShowMain::fileChangedSlot().

33 { return m_source; }
ESource m_source
Definition: FWMagField.h:53
float FWMagField::getUserField ( ) const
inline

Definition at line 31 of file FWMagField.h.

31 { return m_userField; }
float m_userField
Definition: FWMagField.h:54
void FWMagField::guessField ( float  estimate) const

Definition at line 155 of file FWMagField.cc.

References m_guessValHist, and m_updateFieldEstimate.

Referenced by FWTrackProxyBuilder::build(), and FWMuonBuilder::calculateField().

156 {
157  // fwLog(filedDebug) << "FWMagField::guessField "<< val << std::endl;
158  m_guessValHist->Fill(val);
159  m_updateFieldEstimate = true;
160 }
bool m_updateFieldEstimate
Definition: FWMagField.h:64
TH1F * m_guessValHist
Definition: FWMagField.h:61
void FWMagField::guessFieldIsOn ( bool  guess) const

Definition at line 148 of file FWMagField.cc.

References m_numberOfFieldEstimates, m_numberOfFieldIsOnEstimates, and m_updateFieldEstimate.

Referenced by FWMuonBuilder::calculateField().

149 {
150  if ( isOn ) ++m_numberOfFieldIsOnEstimates;
152  m_updateFieldEstimate = true;
153 }
int m_numberOfFieldEstimates
Definition: FWMagField.h:63
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:62
bool m_updateFieldEstimate
Definition: FWMagField.h:64
bool FWMagField::isReverse ( ) const
inline

Definition at line 37 of file FWMagField.h.

37 { return m_reverse;}
bool m_reverse
Definition: FWMagField.h:57
bool FWMagField::isSimpleModel ( ) const
inline

Definition at line 39 of file FWMagField.h.

References mps_check::guess.

39 { return m_simpleModel;}
bool m_simpleModel
Definition: FWMagField.h:58
const FWMagField& FWMagField::operator= ( const FWMagField )
privatedelete
void FWMagField::resetFieldEstimate ( ) const

Definition at line 162 of file FWMagField.cc.

References m_guessValHist, m_numberOfFieldEstimates, m_numberOfFieldIsOnEstimates, and m_updateFieldEstimate.

Referenced by CmsShowMain::fileChangedSlot().

163 {
164  m_guessValHist->Reset();
165  m_guessValHist->SetAxisRange(-4, 4);
168  m_updateFieldEstimate = true;
169 }
int m_numberOfFieldEstimates
Definition: FWMagField.h:63
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:62
bool m_updateFieldEstimate
Definition: FWMagField.h:64
TH1F * m_guessValHist
Definition: FWMagField.h:61
void FWMagField::setFFFieldMag ( float  mag)

Definition at line 229 of file FWMagField.cc.

References kEvent, m_eventField, m_source, and mag().

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 }
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
ESource m_source
Definition: FWMagField.h:53
float m_eventField
Definition: FWMagField.h:55
void FWMagField::setReverseState ( bool  state)
inline

Definition at line 36 of file FWMagField.h.

36 { m_reverse = state; }
bool m_reverse
Definition: FWMagField.h:57
void FWMagField::setSimpleModel ( bool  simpleModel)
inline

Definition at line 38 of file FWMagField.h.

38 { m_simpleModel = simpleModel; }
bool m_simpleModel
Definition: FWMagField.h:58
void FWMagField::setSource ( ESource  x)
inline

Definition at line 32 of file FWMagField.h.

32 { m_source = x; }
ESource m_source
Definition: FWMagField.h:53
void FWMagField::setUserField ( float  b)
inline

Definition at line 30 of file FWMagField.h.

References b.

30 { m_userField = b; }
float m_userField
Definition: FWMagField.h:54
double b
Definition: hdecay.h:120

Member Data Documentation

float FWMagField::m_eventField
private

Definition at line 55 of file FWMagField.h.

Referenced by checkFieldInfo(), GetFieldMag(), and setFFFieldMag().

float FWMagField::m_guessedField
mutableprivate

Definition at line 65 of file FWMagField.h.

Referenced by GetFieldMag().

TH1F* FWMagField::m_guessValHist
mutableprivate

Definition at line 61 of file FWMagField.h.

Referenced by FWMagField(), GetFieldMag(), guessField(), resetFieldEstimate(), and ~FWMagField().

int FWMagField::m_numberOfFieldEstimates
mutableprivate

Definition at line 63 of file FWMagField.h.

Referenced by GetFieldMag(), guessFieldIsOn(), and resetFieldEstimate().

int FWMagField::m_numberOfFieldIsOnEstimates
mutableprivate

Definition at line 62 of file FWMagField.h.

Referenced by GetFieldMag(), guessFieldIsOn(), and resetFieldEstimate().

bool FWMagField::m_reverse
private

Definition at line 57 of file FWMagField.h.

Referenced by GetField().

bool FWMagField::m_simpleModel
private

Definition at line 58 of file FWMagField.h.

Referenced by GetField().

ESource FWMagField::m_source
private

Definition at line 53 of file FWMagField.h.

Referenced by checkFieldInfo(), GetFieldMag(), and setFFFieldMag().

bool FWMagField::m_updateFieldEstimate
mutableprivate

Definition at line 64 of file FWMagField.h.

Referenced by GetFieldMag(), guessField(), guessFieldIsOn(), and resetFieldEstimate().

float FWMagField::m_userField
private

Definition at line 54 of file FWMagField.h.

Referenced by GetFieldMag().