CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DetectorDescription/OnlineDBLoader/bin/stubs/RotationForOnline.cc

Go to the documentation of this file.
00001 //
00002 // Original Author:  Jie Chen
00003 //         Created:  Mon Apr  9 11:36:53 CDT 2007
00004 // $Id: RotationForOnline.cc,v 1.7 2010/03/25 21:55:36 case Exp $
00005 //
00006 //
00007 
00008 
00009 // system include files
00010 #include <memory>
00011 
00012 // user include files
00013 #include "FWCore/Framework/interface/EDAnalyzer.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/Framework/interface/ESTransientHandle.h"
00016 #include <FWCore/Framework/interface/ESHandle.h>
00017 #include "FWCore/Framework/interface/MakerMacros.h"
00018 
00019 #include <DetectorDescription/Core/interface/DDCompactView.h>
00020 #include <DetectorDescription/Core/interface/DDValue.h>
00021 #include "DetectorDescription/Core/interface/DDName.h"
00022 #include <Geometry/Records/interface/IdealGeometryRecord.h>
00023 
00024 
00025 #include <iostream>
00026 #include <istream>
00027 #include <fstream>
00028 #include <string>
00029 
00030 
00031 
00032 //
00033 // class decleration
00034 //
00035 
00036 class RotationForOnline : public edm::EDAnalyzer {
00037    public:
00038       explicit RotationForOnline(const edm::ParameterSet&);
00039       ~RotationForOnline();
00040       virtual void beginRun(const edm::Run&, const edm::EventSetup&) ;
00041       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00042       virtual void endJob() ;
00043 
00044 
00045    private:
00046 
00047       // ----------member data ---------------------------
00048 };
00049 
00050 //
00051 // constants, enums and typedefs
00052 //
00053  
00054 //
00055 // static data member definitions
00056 //
00057 
00058 //
00059 // constructors and destructor
00060 //
00061 RotationForOnline::RotationForOnline(const edm::ParameterSet& iConfig)
00062 {
00063    //now do what ever initialization is needed
00064 
00065 }
00066 
00067 
00068 RotationForOnline::~RotationForOnline()
00069 {
00070  
00071    // do anything here that needs to be done at desctruction time
00072    // (e.g. close files, deallocate resources etc.)
00073 
00074 }
00075 
00076 
00077 //
00078 // member functions
00079 //
00080 
00081 // ------------ method called to for each event  ------------
00082 void
00083 RotationForOnline::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00084 {
00085   std::cout << "analyze does nothing" << std::endl;
00086 }
00087 
00088 
00089 // ------------ method called once each job just before starting event loop  ------------
00090 void 
00091 RotationForOnline::beginRun(const edm::Run&, const edm::EventSetup& iSetup)
00092 {
00093   // set tolerance for "near zero"
00094   double tolerance= 1.0e-3;
00095   std::string rotationFileName("ROTATIONS.dat");
00096   std::ofstream rotationOS(rotationFileName.c_str());
00097   std::cout << "RotationForOnline Analyzer..." << std::endl;
00098 
00099 
00100   edm::ESTransientHandle<DDCompactView> pDD;
00101 
00102   iSetup.get<IdealGeometryRecord>().get( "", pDD );
00103   DDRotationMatrix ident;
00104 
00105   DDRotation::iterator<DDRotation> rit(DDRotation::begin()), red(DDRotation::end());
00106   for (; rit != red; ++rit) {
00107     if (! rit->isDefined().second) continue;
00108     //    if ( rit->matrix()->isIdentity() ) continue;
00109     if ( *(rit->matrix()) == ident ) continue;
00110     const DDRotation& rota = *rit;
00111     bool reflection = false;
00112 
00113     DD3Vector x, y, z;
00114     rit->matrix()->GetComponents(x, y, z);
00115     if ( (1.0 + (x.Cross(y)).Dot(z)) <= tolerance ) {
00116       reflection = true;
00117     }
00118  
00119     rotationOS<< *(rota.isDefined().first); //rota name
00120     double thetaX, phiX, thetaY, phiY, thetaZ, phiZ;
00121 
00122     thetaX = std::acos(x.z());
00123     phiX = ( x.y() == 0 && x.x() == 0.0) ? 0.0 : std::atan2(x.y(), x.x());
00124 
00125     thetaY = std::acos(y.z());
00126     phiY = ( y.y() == 0 && y.x() == 0.0) ? 0.0 : std::atan2(y.y(), y.x());
00127 
00128     thetaZ = std::acos(z.z());
00129     phiZ = ( z.y() == 0 && z.x() == 0.0) ? 0.0 : std::atan2(z.y(), z.x());
00130 
00131     rotationOS<< "," << thetaX
00132               << "," << phiX
00133               << "," << thetaY
00134               << "," << phiY
00135               << "," << thetaZ
00136               << "," << phiZ
00137               << "," << (int)reflection
00138               <<std::endl;
00139   } 
00140 
00141   rotationOS.close();
00142 
00143 }
00144 
00145 // ------------ method called once each job just after ending the event loop  ------------
00146 void 
00147 RotationForOnline::endJob() {
00148 }
00149 
00150 //define this as a plug-in
00151 DEFINE_FWK_MODULE(RotationForOnline);