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 ()
 
 FWMagField (const FWMagField &)=delete
 
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
 
const FWMagFieldoperator= (const FWMagField &)=delete
 
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

Float_t GetFieldMag () const
 

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 14 of file FWMagField.h.

Member Enumeration Documentation

◆ ESource

Enumerator
kNone 
kEvent 
kUser 

Definition at line 18 of file FWMagField.h.

Constructor & Destructor Documentation

◆ FWMagField() [1/2]

FWMagField::FWMagField ( )

Definition at line 11 of file FWMagField.cc.

References m_guessValHist.

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),
25  m_guessedField(0) {
26  m_guessValHist = new TH1F("FieldEstimations", "Field estimations from tracks and muons", 200, -4.5, 4.5);
27  m_guessValHist->SetDirectory(nullptr);
28 }
int m_numberOfFieldEstimates
Definition: FWMagField.h:61
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:60
bool m_simpleModel
Definition: FWMagField.h:56
float m_guessedField
Definition: FWMagField.h:63
bool m_reverse
Definition: FWMagField.h:55
bool m_updateFieldEstimate
Definition: FWMagField.h:62
TH1F * m_guessValHist
Definition: FWMagField.h:59
ESource m_source
Definition: FWMagField.h:51
float m_userField
Definition: FWMagField.h:52
float m_eventField
Definition: FWMagField.h:53

◆ ~FWMagField()

FWMagField::~FWMagField ( )
override

Definition at line 30 of file FWMagField.cc.

References m_guessValHist.

30 { delete m_guessValHist; }
TH1F * m_guessValHist
Definition: FWMagField.h:59

◆ FWMagField() [2/2]

FWMagField::FWMagField ( const FWMagField )
delete

Member Function Documentation

◆ checkFieldInfo()

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

Definition at line 144 of file FWMagField.cc.

References edm::ConditionsInRunBlock::BAvgCurrent, topElectronID_cff::dcsTag, edmPickEvents::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().

144  {
145  const static float currentToField = 3.8 / 18160;
146  bool available = false;
147  try {
148  edm::InputTag conditionsTag("conditionsInEdm");
150  // FIXME: ugly hack to avoid exposing an fwlite::Event. Need to ask
151  // Chris / Ianna how to get mag field from an EventBase.
152  const fwlite::Event* fwEvent = dynamic_cast<const fwlite::Event*>(event);
153  if (!fwEvent)
154  return;
155 
156  m_source = kNone;
157  fwEvent->getRun().getByLabel(conditionsTag, runCond);
158 
159  if (runCond.isValid()) {
160  available = true;
161  m_eventField = currentToField * runCond->BAvgCurrent;
162  m_source = kEvent;
163  fwLog(fwlog::kDebug) << "Magnetic field info found in ConditionsInEdm branch : " << m_eventField << std::endl;
164  } else {
165  edm::InputTag dcsTag("scalersRawToDigi");
167  event->getByLabel(dcsTag, dcsStatus);
168 
169  if (dcsStatus.isValid() && !dcsStatus->empty()) {
170  float sum = 0;
171  for (std::vector<DcsStatus>::const_iterator i = dcsStatus->begin(); i < dcsStatus->end(); ++i)
172  sum += (*i).magnetCurrent();
173 
174  available = true;
175  m_eventField = currentToField * sum / dcsStatus->size();
176  m_source = kEvent;
177  fwLog(fwlog::kDebug) << "Magnetic field info found in DcsStatus branch: " << m_eventField << std::endl;
178  }
179  }
180  } catch (cms::Exception&) {
181  fwLog(fwlog::kDebug) << "Cought exception in FWMagField::checkFieldInfo\n";
182  }
183 
184  if (!available) {
185  fwLog(fwlog::kDebug) << "No magnetic field info available in Event\n";
186  }
187 }
bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const override
Definition: Run.cc:184
ESource m_source
Definition: FWMagField.h:51
#define fwLog(_level_)
Definition: fwLog.h:45
bool isValid() const
Definition: HandleBase.h:70
float m_eventField
Definition: FWMagField.h:53
fwlite::Run const & getRun() const
Definition: Event.cc:517

◆ GetField()

TEveVector FWMagField::GetField ( Float_t  x,
Float_t  y,
Float_t  z 
) const
override

Definition at line 34 of file FWMagField.cc.

References GetFieldMag(), m_reverse, m_simpleModel, dttmaxenums::R, mathSSE::sqrt(), x, y, and z.

34  {
35  // Virtual method of TEveMagField class.
36 
37  Float_t R = sqrt(x * x + y * y);
38  Float_t field = m_reverse ? -GetFieldMag() : GetFieldMag();
39 
40  //barrel
41  if (TMath::Abs(z) < 724) {
42  //inside solenoid
43  if (R < 300)
44  return TEveVector(0, 0, field);
45  // outside solinoid
46  if (m_simpleModel || (R > 461.0 && R < 490.5) || (R > 534.5 && R < 597.5) || (R > 637.0 && R < 700.0))
47  return TEveVector(0, 0, -field / 3.8 * 1.2);
48 
49  } else {
50  // endcaps
51  if (m_simpleModel) {
52  if (R < 50)
53  return TEveVector(0, 0, field);
54  if (z > 0)
55  return TEveVector(x / R * field / 3.8 * 2.0, y / R * field / 3.8 * 2.0, 0);
56  else
57  return TEveVector(-x / R * field / 3.8 * 2.0, -y / R * field / 3.8 * 2.0, 0);
58  }
59  // proper model
60  if (((TMath::Abs(z) > 724) && (TMath::Abs(z) < 786)) || ((TMath::Abs(z) > 850) && (TMath::Abs(z) < 910)) ||
61  ((TMath::Abs(z) > 975) && (TMath::Abs(z) < 1003))) {
62  if (z > 0)
63  return TEveVector(x / R * field / 3.8 * 2.0, y / R * field / 3.8 * 2.0, 0);
64  else
65  return TEveVector(-x / R * field / 3.8 * 2.0, -y / R * field / 3.8 * 2.0, 0);
66  }
67  }
68  return TEveVector(0, 0, 0);
69 }
bool m_simpleModel
Definition: FWMagField.h:56
bool m_reverse
Definition: FWMagField.h:55
T sqrt(T t)
Definition: SSEVec.h:19
Float_t GetFieldMag() const
Definition: FWMagField.cc:73

◆ GetFieldMag()

Float_t FWMagField::GetFieldMag ( ) const
private

Definition at line 73 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().

73  {
74  float res;
75  switch (m_source) {
76  case kEvent: {
77  res = m_eventField;
78  break;
79  }
80  case kUser: {
81  res = m_userField;
82  break;
83  }
84  default: {
86  if (m_guessValHist->GetEntries() > 2 && m_guessValHist->GetRMS() < 0.5) {
87  m_guessedField = m_guessValHist->GetMean();
88 
89  // std::cout << "FWMagField::GetFieldMag(), get average "
90  // << m_guessValHist->GetMean() << " guessed value: RMS= "<< m_guessValHist->GetRMS()
91  // <<" samples "<< m_guessValHist->GetEntries() << std::endl;
92 
94  m_guessedField = 3.8;
95  // fwLog(fwlog::kDebug) << "FWMagField::GetFieldMag() get default field, number estimates "
96  // << m_numberOfFieldEstimates << " number fields is on m_numberOfFieldIsOnEstimates" <<std::endl;
97  } else {
98  m_guessedField = 0;
99  // fwLog(fwlog::kDebug) << "Update field estimate, guess field is OFF." <<std::endl;
100  }
101  m_updateFieldEstimate = false;
102  }
103 
105  }
106  }
107 
108  return res;
109 }
int m_numberOfFieldEstimates
Definition: FWMagField.h:61
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:60
float m_guessedField
Definition: FWMagField.h:63
bool m_updateFieldEstimate
Definition: FWMagField.h:62
TH1F * m_guessValHist
Definition: FWMagField.h:59
Definition: Electron.h:6
ESource m_source
Definition: FWMagField.h:51
float m_userField
Definition: FWMagField.h:52
float m_eventField
Definition: FWMagField.h:53

◆ GetMaxFieldMag()

Float_t FWMagField::GetMaxFieldMag ( ) const
override

Definition at line 111 of file FWMagField.cc.

References f, GetFieldMag(), and METSkim_cff::Max.

111  {
112  // Runge-Kutta stepper does not like this to be zero.
113  // Will be fixed in root.
114  // The return value should definitley not be negative -- so Abs
115  // should stay!
116 
117  return TMath::Max(TMath::Abs(GetFieldMag()), 0.01f);
118 }
double f[11][100]
Float_t GetFieldMag() const
Definition: FWMagField.cc:73

◆ getSource()

ESource FWMagField::getSource ( ) const
inline

◆ getUserField()

float FWMagField::getUserField ( ) const
inline

Definition at line 29 of file FWMagField.h.

References m_userField.

29 { return m_userField; }
float m_userField
Definition: FWMagField.h:52

◆ guessField()

void FWMagField::guessField ( float  estimate) const

Definition at line 129 of file FWMagField.cc.

References m_guessValHist, m_updateFieldEstimate, and heppy_batch::val.

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

129  {
130  // fwLog(filedDebug) << "FWMagField::guessField "<< val << std::endl;
131  m_guessValHist->Fill(val);
132  m_updateFieldEstimate = true;
133 }
bool m_updateFieldEstimate
Definition: FWMagField.h:62
TH1F * m_guessValHist
Definition: FWMagField.h:59

◆ guessFieldIsOn()

void FWMagField::guessFieldIsOn ( bool  guess) const

Definition at line 122 of file FWMagField.cc.

References m_numberOfFieldEstimates, m_numberOfFieldIsOnEstimates, and m_updateFieldEstimate.

Referenced by FWMuonBuilder::calculateField().

122  {
123  if (isOn)
126  m_updateFieldEstimate = true;
127 }
int m_numberOfFieldEstimates
Definition: FWMagField.h:61
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:60
bool m_updateFieldEstimate
Definition: FWMagField.h:62

◆ isReverse()

bool FWMagField::isReverse ( ) const
inline

Definition at line 35 of file FWMagField.h.

References m_reverse.

35 { return m_reverse; }
bool m_reverse
Definition: FWMagField.h:55

◆ isSimpleModel()

bool FWMagField::isSimpleModel ( ) const
inline

Definition at line 37 of file FWMagField.h.

References m_simpleModel.

37 { return m_simpleModel; }
bool m_simpleModel
Definition: FWMagField.h:56

◆ operator=()

const FWMagField& FWMagField::operator= ( const FWMagField )
delete

◆ resetFieldEstimate()

void FWMagField::resetFieldEstimate ( ) const

Definition at line 135 of file FWMagField.cc.

References m_guessValHist, m_numberOfFieldEstimates, m_numberOfFieldIsOnEstimates, and m_updateFieldEstimate.

Referenced by CmsShowMain::fileChangedSlot().

135  {
136  m_guessValHist->Reset();
137  m_guessValHist->SetAxisRange(-4, 4);
140  m_updateFieldEstimate = true;
141 }
int m_numberOfFieldEstimates
Definition: FWMagField.h:61
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:60
bool m_updateFieldEstimate
Definition: FWMagField.h:62
TH1F * m_guessValHist
Definition: FWMagField.h:59

◆ setFFFieldMag()

void FWMagField::setFFFieldMag ( float  mag)

Definition at line 190 of file FWMagField.cc.

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

Referenced by FWFFLooper::beginRun().

190  {
191  // AMT this is a workaround for seting FF in FFLooper
192  // Correct imeplementation is having a base class of FWMagField amd do implementation for FF and FWLite version
193 
194  m_source = kEvent;
195  m_eventField = mag;
196 }
ESource m_source
Definition: FWMagField.h:51
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
float m_eventField
Definition: FWMagField.h:53

◆ setReverseState()

void FWMagField::setReverseState ( bool  state)
inline

Definition at line 34 of file FWMagField.h.

References m_reverse.

◆ setSimpleModel()

void FWMagField::setSimpleModel ( bool  simpleModel)
inline

Definition at line 36 of file FWMagField.h.

References m_simpleModel.

36 { m_simpleModel = simpleModel; }
bool m_simpleModel
Definition: FWMagField.h:56

◆ setSource()

void FWMagField::setSource ( ESource  x)
inline

Definition at line 30 of file FWMagField.h.

References m_source, and x.

30 { m_source = x; }
ESource m_source
Definition: FWMagField.h:51

◆ setUserField()

void FWMagField::setUserField ( float  b)
inline

Definition at line 28 of file FWMagField.h.

References b, and m_userField.

28 { m_userField = b; }
float m_userField
Definition: FWMagField.h:52
double b
Definition: hdecay.h:118

Member Data Documentation

◆ m_eventField

float FWMagField::m_eventField
private

Definition at line 53 of file FWMagField.h.

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

◆ m_guessedField

float FWMagField::m_guessedField
mutableprivate

Definition at line 63 of file FWMagField.h.

Referenced by GetFieldMag().

◆ m_guessValHist

TH1F* FWMagField::m_guessValHist
mutableprivate

Definition at line 59 of file FWMagField.h.

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

◆ m_numberOfFieldEstimates

int FWMagField::m_numberOfFieldEstimates
mutableprivate

Definition at line 61 of file FWMagField.h.

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

◆ m_numberOfFieldIsOnEstimates

int FWMagField::m_numberOfFieldIsOnEstimates
mutableprivate

Definition at line 60 of file FWMagField.h.

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

◆ m_reverse

bool FWMagField::m_reverse
private

Definition at line 55 of file FWMagField.h.

Referenced by GetField(), isReverse(), and setReverseState().

◆ m_simpleModel

bool FWMagField::m_simpleModel
private

Definition at line 56 of file FWMagField.h.

Referenced by GetField(), isSimpleModel(), and setSimpleModel().

◆ m_source

ESource FWMagField::m_source
private

Definition at line 51 of file FWMagField.h.

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

◆ m_updateFieldEstimate

bool FWMagField::m_updateFieldEstimate
mutableprivate

Definition at line 62 of file FWMagField.h.

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

◆ m_userField

float FWMagField::m_userField
private

Definition at line 52 of file FWMagField.h.

Referenced by GetFieldMag(), getUserField(), and setUserField().