CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:32:23 2009 for CMSSW by  doxygen 1.5.4