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

Member Enumeration Documentation

◆ ESource

Enumerator
kNone 
kEvent 
kUser 

Definition at line 18 of file FWMagField.h.

18 { kNone, kEvent, kUser };

Constructor & Destructor Documentation

◆ FWMagField() [1/2]

FWMagField::FWMagField ( )

Definition at line 11 of file FWMagField.cc.

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 }

References m_guessValHist.

◆ ~FWMagField()

FWMagField::~FWMagField ( )
override

Definition at line 30 of file FWMagField.cc.

30 { delete m_guessValHist; }

References m_guessValHist.

◆ FWMagField() [2/2]

FWMagField::FWMagField ( const FWMagField )
privatedelete

Member Function Documentation

◆ checkFieldInfo()

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

Definition at line 144 of file FWMagField.cc.

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 }

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

◆ GetField()

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

Definition at line 34 of file FWMagField.cc.

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 }

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

◆ GetFieldMag()

Float_t FWMagField::GetFieldMag ( ) const
private

Definition at line 73 of file FWMagField.cc.

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 }

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().

◆ GetMaxFieldMag()

Float_t FWMagField::GetMaxFieldMag ( ) const
override

Definition at line 111 of file FWMagField.cc.

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 }

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

◆ getSource()

ESource FWMagField::getSource ( ) const
inline

◆ getUserField()

float FWMagField::getUserField ( ) const
inline

Definition at line 29 of file FWMagField.h.

29 { return m_userField; }

References m_userField.

◆ guessField()

void FWMagField::guessField ( float  estimate) const

Definition at line 129 of file FWMagField.cc.

129  {
130  // fwLog(filedDebug) << "FWMagField::guessField "<< val << std::endl;
131  m_guessValHist->Fill(val);
132  m_updateFieldEstimate = true;
133 }

References m_guessValHist, m_updateFieldEstimate, and heppy_batch::val.

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

◆ guessFieldIsOn()

void FWMagField::guessFieldIsOn ( bool  guess) const

Definition at line 122 of file FWMagField.cc.

122  {
123  if (isOn)
126  m_updateFieldEstimate = true;
127 }

References m_numberOfFieldEstimates, m_numberOfFieldIsOnEstimates, and m_updateFieldEstimate.

Referenced by FWMuonBuilder::calculateField().

◆ isReverse()

bool FWMagField::isReverse ( ) const
inline

Definition at line 35 of file FWMagField.h.

35 { return m_reverse; }

References m_reverse.

◆ isSimpleModel()

bool FWMagField::isSimpleModel ( ) const
inline

Definition at line 37 of file FWMagField.h.

37 { return m_simpleModel; }

References m_simpleModel.

◆ operator=()

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

◆ resetFieldEstimate()

void FWMagField::resetFieldEstimate ( ) const

Definition at line 135 of file FWMagField.cc.

135  {
136  m_guessValHist->Reset();
137  m_guessValHist->SetAxisRange(-4, 4);
140  m_updateFieldEstimate = true;
141 }

References m_guessValHist, m_numberOfFieldEstimates, m_numberOfFieldIsOnEstimates, and m_updateFieldEstimate.

Referenced by CmsShowMain::fileChangedSlot().

◆ setFFFieldMag()

void FWMagField::setFFFieldMag ( float  mag)

Definition at line 190 of file FWMagField.cc.

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 }

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

Referenced by FWFFLooper::beginRun().

◆ setReverseState()

void FWMagField::setReverseState ( bool  state)
inline

Definition at line 34 of file FWMagField.h.

34 { m_reverse = state; }

References m_reverse.

◆ setSimpleModel()

void FWMagField::setSimpleModel ( bool  simpleModel)
inline

Definition at line 36 of file FWMagField.h.

36 { m_simpleModel = simpleModel; }

References m_simpleModel.

◆ setSource()

void FWMagField::setSource ( ESource  x)
inline

Definition at line 30 of file FWMagField.h.

30 { m_source = x; }

References m_source, and x.

◆ setUserField()

void FWMagField::setUserField ( float  b)
inline

Definition at line 28 of file FWMagField.h.

28 { m_userField = b; }

References b, and m_userField.

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().

FWMagField::m_userField
float m_userField
Definition: FWMagField.h:52
DDAxes::y
FWMagField::GetFieldMag
Float_t GetFieldMag() const
Definition: FWMagField.cc:73
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
mps_fire.i
i
Definition: mps_fire.py:355
FWMagField::kNone
Definition: FWMagField.h:18
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
fwlite::Run::getByLabel
bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const override
Definition: Run.cc:184
DDAxes::x
fwlite::Event::getRun
fwlite::Run const & getRun() const
Definition: Event.cc:496
edm::Handle
Definition: AssociativeIterator.h:50
FWMagField::m_eventField
float m_eventField
Definition: FWMagField.h:53
FWMagField::m_numberOfFieldEstimates
int m_numberOfFieldEstimates
Definition: FWMagField.h:61
Abs
T Abs(T a)
Definition: MathUtil.h:49
edm::ConditionsInRunBlock::BAvgCurrent
float BAvgCurrent
Definition: ConditionsInEdm.h:27
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DDAxes::z
topElectronID_cff.dcsTag
dcsTag
Definition: topElectronID_cff.py:11
b
double b
Definition: hdecay.h:118
FWMagField::kEvent
Definition: FWMagField.h:18
Max
T Max(T a, T b)
Definition: MathUtil.h:44
res
Definition: Electron.h:6
FWMagField::m_numberOfFieldIsOnEstimates
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:60
FWMagField::m_simpleModel
bool m_simpleModel
Definition: FWMagField.h:56
FWMagField::m_guessedField
float m_guessedField
Definition: FWMagField.h:63
mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:127
heppy_batch.val
val
Definition: heppy_batch.py:351
FWMagField::m_source
ESource m_source
Definition: FWMagField.h:51
fwlite::Event
Definition: Event.h:87
fwlog::kDebug
Definition: fwLog.h:35
FWMagField::m_updateFieldEstimate
bool m_updateFieldEstimate
Definition: FWMagField.h:62
cms::Exception
Definition: Exception.h:70
FWMagField::kUser
Definition: FWMagField.h:18
FWMagField::m_reverse
bool m_reverse
Definition: FWMagField.h:55
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
dttmaxenums::R
Definition: DTTMax.h:29
edm::InputTag
Definition: InputTag.h:15
FWMagField::m_guessValHist
TH1F * m_guessValHist
Definition: FWMagField.h:59