Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-17 22:33:35

0001 /** \file
0002  *  A simple program to print field value.
0003  *
0004  *  \author N. Amapane - CERN
0005  */
0006 
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 
0013 #include "MagneticField/Engine/interface/MagneticField.h"
0014 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0015 
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 
0019 //#include "DataFormats/GeometryVector/interface/Pi.h"
0020 //#include "DataFormats/GeometryVector/interface/CoordinateSets.h"
0021 
0022 #include <iostream>
0023 #include <string>
0024 #include <sstream>
0025 #include <iostream>
0026 #include <fstream>
0027 
0028 using namespace edm;
0029 using namespace Geom;
0030 using namespace std;
0031 
0032 class queryField : public edm::one::EDAnalyzer<> {
0033 public:
0034   queryField(const edm::ParameterSet&) : m_fieldToken(esConsumes()) {}
0035 
0036   ~queryField() override {}
0037 
0038   void analyze(const edm::Event& event, const edm::EventSetup& setup) final {
0039     auto const& field = setup.getData(m_fieldToken);
0040 
0041     cout << "Field Nominal Value: " << field.nominalValue() << endl;
0042 
0043     double x, y, z;
0044 
0045     while (1) {
0046       cout << "Enter X Y Z (cm): ";
0047 
0048       if (!(cin >> x >> y >> z))
0049         exit(0);
0050 
0051       GlobalPoint g(x, y, z);
0052 
0053       cout << "At R=" << g.perp() << " phi=" << g.phi() << " B=" << field.inTesla(g) << endl;
0054     }
0055   }
0056 
0057 private:
0058   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> m_fieldToken;
0059 };
0060 
0061 DEFINE_FWK_MODULE(queryField);