CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Alignment/SurveyAnalysis/plugins/DTSurveyConvert.cc

Go to the documentation of this file.
00001 #include <fstream>
00002 
00003 #include "Alignment/MuonAlignment/interface/MuonAlignment.h"
00004 #include "Alignment/SurveyAnalysis/interface/DTSurvey.h"
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 // #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00010 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00011 
00012 #include "Alignment/SurveyAnalysis/plugins/DTSurveyConvert.h"
00013 
00014 DTSurveyConvert::DTSurveyConvert(const edm::ParameterSet& iConfig)
00015 {
00016    //now do what ever initialization is needed
00017    nameWheel_m2 = iConfig.getUntrackedParameter<std::string>("nameWheel_m2");
00018    nameWheel_m1 = iConfig.getUntrackedParameter<std::string>("nameWheel_m1");
00019    nameWheel_0 = iConfig.getUntrackedParameter<std::string>("nameWheel_0");
00020    nameWheel_p1 = iConfig.getUntrackedParameter<std::string>("nameWheel_p1");
00021    nameWheel_p2 = iConfig.getUntrackedParameter<std::string>("nameWheel_p2");
00022    
00023    nameChambers_m2 = iConfig.getUntrackedParameter<std::string>("nameChambers_m2");
00024    nameChambers_m1 = iConfig.getUntrackedParameter<std::string>("nameChambers_m1");
00025    nameChambers_0 = iConfig.getUntrackedParameter<std::string>("nameChambers_0");
00026    nameChambers_p1 = iConfig.getUntrackedParameter<std::string>("nameChambers_p1");
00027    nameChambers_p2 = iConfig.getUntrackedParameter<std::string>("nameChambers_p2");
00028 
00029    wheel_m2 = iConfig.getUntrackedParameter<bool>("wheel_m2");
00030    wheel_m1 = iConfig.getUntrackedParameter<bool>("wheel_m1");
00031    wheel_0 = iConfig.getUntrackedParameter<bool>("wheel_0");
00032    wheel_p1 = iConfig.getUntrackedParameter<bool>("wheel_p1");
00033    wheel_p2 = iConfig.getUntrackedParameter<bool>("wheel_p2");
00034 
00035    outputFileName = iConfig.getUntrackedParameter<std::string>("OutputTextFile");
00036    WriteToDB = iConfig.getUntrackedParameter<bool>("writeToDB");
00037   
00038 }
00039 
00040 // ------------ method called to for each event  ------------
00041 void
00042 DTSurveyConvert::analyze(const edm::Event&, const edm::EventSetup& iSetup)
00043 {
00044 
00045   edm::ESHandle<DTGeometry> pDD;
00046   iSetup.get<MuonGeometryRecord>().get( pDD );
00047  
00048   std::ofstream outFile(outputFileName.c_str());
00049   
00050   if (wheel_m2 == true) {
00051     DTSurvey *wheel = new DTSurvey(nameWheel_m2, nameChambers_m2, -2);
00052     wheel->ReadChambers(pDD);
00053     wheel->CalculateChambers();
00054     outFile << *wheel; 
00055     wheelList.push_back(wheel);
00056   } 
00057   if (wheel_m1 == true) {
00058     DTSurvey *wheel = new DTSurvey(nameWheel_m1, nameChambers_m1, -1);
00059     wheel->ReadChambers(pDD);
00060     wheel->CalculateChambers();
00061     outFile << *wheel; 
00062     wheelList.push_back(wheel);
00063   } 
00064   if (wheel_0 == true) {
00065     DTSurvey *wheel = new DTSurvey(nameWheel_0, nameChambers_0, 0);
00066     wheel->ReadChambers(pDD);
00067     wheel->CalculateChambers();
00068     outFile << *wheel; 
00069     wheelList.push_back(wheel);
00070   } 
00071   if (wheel_p1 == true) {
00072     DTSurvey *wheel = new DTSurvey(nameWheel_p1, nameChambers_p1, 1);
00073     wheel->ReadChambers(pDD);
00074     wheel->CalculateChambers();
00075     outFile << *wheel; 
00076     wheelList.push_back(wheel);
00077   } 
00078   if(wheel_p2 == true) {
00079     DTSurvey *wheel = new DTSurvey(nameWheel_p2, nameChambers_p2, 2);
00080     wheel->ReadChambers(pDD);
00081     wheel->CalculateChambers();
00082     outFile << *wheel; 
00083     wheelList.push_back(wheel);
00084   }
00085   outFile.close();
00086 }
00087 
00088 // ------------ method called once each job just after ending the event loop  ------------
00089 void 
00090 DTSurveyConvert::endJob(const edm::EventSetup& eventSetup) {
00091   if(WriteToDB == true) {
00092     // Instantiate the helper class
00093     MuonAlignment align( eventSetup );
00094     std::ifstream inFile(outputFileName.c_str());
00095     while(!inFile.eof()) {
00096       float dx, dy, dz, sigma_dx, sigma_dy, sigma_dz;
00097       float alpha, beta, gamma, sigma_alpha, sigma_beta, sigma_gamma;
00098       inFile >> dx >> sigma_dx >> dy >> sigma_dy >> dz >> sigma_dz
00099              >> alpha >> sigma_alpha >> beta >> sigma_beta >> gamma >> sigma_gamma; 
00100       if(inFile.eof()) break;
00101       std::vector<float> displacement;
00102       displacement.push_back(dx);
00103       displacement.push_back(dy);
00104       displacement.push_back(dz);
00105       displacement.push_back(-alpha);
00106       displacement.push_back(-beta);
00107       displacement.push_back(-gamma);
00108     }
00109     inFile.close();
00110     align.saveToDB();
00111   }
00112 }
00113 
00114 DEFINE_FWK_MODULE(DTSurveyConvert);