CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ()
 
virtual TEveVector GetField (Float_t x, Float_t y, Float_t z) const
 
virtual Float_t GetMaxFieldMag () const
 
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 setReverseState (bool state)
 
void setSimpleModel (bool simpleModel)
 
void setSource (ESource x)
 
void setUserField (float b)
 
virtual ~FWMagField ()
 

Private Member Functions

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

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(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 }
int m_numberOfFieldEstimates
Definition: FWMagField.h:62
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:61
bool m_simpleModel
Definition: FWMagField.h:57
float m_guessedField
Definition: FWMagField.h:64
bool m_reverse
Definition: FWMagField.h:56
bool m_updateFieldEstimate
Definition: FWMagField.h:63
TH1F * m_guessValHist
Definition: FWMagField.h:60
ESource m_source
Definition: FWMagField.h:52
float m_userField
Definition: FWMagField.h:53
float m_eventField
Definition: FWMagField.h:54
FWMagField::~FWMagField ( )
virtual

Definition at line 32 of file FWMagField.cc.

References m_guessValHist.

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

Member Function Documentation

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

Definition at line 172 of file FWMagField.cc.

References event(), fwLog, fwlite::Run::getByLabel(), fwlite::Event::getRun(), i, edm::HandleBase::isValid(), fwlog::kDebug, 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  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 }
int i
Definition: DBlmapReader.cc:9
fwlite::Run const & getRun() const
Definition: Event.cc:543
ESource m_source
Definition: FWMagField.h:52
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:75
#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:219
float m_eventField
Definition: FWMagField.h:54
TEveVector FWMagField::GetField ( Float_t  x,
Float_t  y,
Float_t  z 
) const
virtual

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:57
bool m_reverse
Definition: FWMagField.h:56
T sqrt(T t)
Definition: SSEVec.h:48
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:62
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:61
float m_guessedField
Definition: FWMagField.h:64
bool m_updateFieldEstimate
Definition: FWMagField.h:63
TH1F * m_guessValHist
Definition: FWMagField.h:60
ESource m_source
Definition: FWMagField.h:52
float m_userField
Definition: FWMagField.h:53
float m_eventField
Definition: FWMagField.h:54
Float_t FWMagField::GetMaxFieldMag ( ) const
virtual

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
float FWMagField::getUserField ( ) const
inline

Definition at line 31 of file FWMagField.h.

References m_userField.

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

Definition at line 155 of file FWMagField.cc.

References m_guessValHist, and m_updateFieldEstimate.

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

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:63
TH1F * m_guessValHist
Definition: FWMagField.h:60
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:62
int m_numberOfFieldIsOnEstimates
Definition: FWMagField.h:61
bool m_updateFieldEstimate
Definition: FWMagField.h:63
bool FWMagField::isReverse ( ) const
inline

Definition at line 37 of file FWMagField.h.

References m_reverse.

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

Definition at line 39 of file FWMagField.h.

References m_simpleModel.

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

Definition at line 162 of file FWMagField.cc.

References m_guessValHist, m_numberOfFieldEstimates, m_numberOfFieldIsOnEstimates, and m_updateFieldEstimate.

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

Definition at line 36 of file FWMagField.h.

References m_reverse.

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

Definition at line 38 of file FWMagField.h.

References m_simpleModel.

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

Definition at line 32 of file FWMagField.h.

References m_source, and x.

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

Definition at line 30 of file FWMagField.h.

References b, and m_userField.

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

Member Data Documentation

float FWMagField::m_eventField
private

Definition at line 54 of file FWMagField.h.

Referenced by checkFieldInfo(), and GetFieldMag().

float FWMagField::m_guessedField
mutableprivate

Definition at line 64 of file FWMagField.h.

Referenced by GetFieldMag().

TH1F* FWMagField::m_guessValHist
mutableprivate

Definition at line 60 of file FWMagField.h.

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

int FWMagField::m_numberOfFieldEstimates
mutableprivate

Definition at line 62 of file FWMagField.h.

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

int FWMagField::m_numberOfFieldIsOnEstimates
mutableprivate

Definition at line 61 of file FWMagField.h.

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

bool FWMagField::m_reverse
private

Definition at line 56 of file FWMagField.h.

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

bool FWMagField::m_simpleModel
private

Definition at line 57 of file FWMagField.h.

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

ESource FWMagField::m_source
private

Definition at line 52 of file FWMagField.h.

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

bool FWMagField::m_updateFieldEstimate
mutableprivate

Definition at line 63 of file FWMagField.h.

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

float FWMagField::m_userField
private

Definition at line 53 of file FWMagField.h.

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