File indexing completed on 2024-04-06 11:57:23
0001 #include <fstream>
0002
0003 #include "Alignment/MuonAlignment/interface/MuonAlignment.h"
0004 #include "Alignment/SurveyAnalysis/interface/DTSurvey.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "Alignment/SurveyAnalysis/plugins/DTSurveyConvert.h"
0008
0009 DTSurveyConvert::DTSurveyConvert(const edm::ParameterSet &iConfig)
0010 : muonGeoToken_(esConsumes()),
0011 dtGeomToken_(esConsumes()),
0012 cscGeomToken_(esConsumes()),
0013 gemGeomToken_(esConsumes()) {
0014
0015 nameWheel_m2 = iConfig.getUntrackedParameter<std::string>("nameWheel_m2");
0016 nameWheel_m1 = iConfig.getUntrackedParameter<std::string>("nameWheel_m1");
0017 nameWheel_0 = iConfig.getUntrackedParameter<std::string>("nameWheel_0");
0018 nameWheel_p1 = iConfig.getUntrackedParameter<std::string>("nameWheel_p1");
0019 nameWheel_p2 = iConfig.getUntrackedParameter<std::string>("nameWheel_p2");
0020
0021 nameChambers_m2 = iConfig.getUntrackedParameter<std::string>("nameChambers_m2");
0022 nameChambers_m1 = iConfig.getUntrackedParameter<std::string>("nameChambers_m1");
0023 nameChambers_0 = iConfig.getUntrackedParameter<std::string>("nameChambers_0");
0024 nameChambers_p1 = iConfig.getUntrackedParameter<std::string>("nameChambers_p1");
0025 nameChambers_p2 = iConfig.getUntrackedParameter<std::string>("nameChambers_p2");
0026
0027 wheel_m2 = iConfig.getUntrackedParameter<bool>("wheel_m2");
0028 wheel_m1 = iConfig.getUntrackedParameter<bool>("wheel_m1");
0029 wheel_0 = iConfig.getUntrackedParameter<bool>("wheel_0");
0030 wheel_p1 = iConfig.getUntrackedParameter<bool>("wheel_p1");
0031 wheel_p2 = iConfig.getUntrackedParameter<bool>("wheel_p2");
0032
0033 outputFileName = iConfig.getUntrackedParameter<std::string>("OutputTextFile");
0034 WriteToDB = iConfig.getUntrackedParameter<bool>("writeToDB");
0035 }
0036
0037
0038 void DTSurveyConvert::analyze(const edm::Event &, const edm::EventSetup &iSetup) {
0039 const DTGeometry *pDD = &iSetup.getData(muonGeoToken_);
0040
0041 std::ofstream outFile(outputFileName.c_str());
0042
0043 if (wheel_m2 == true) {
0044 DTSurvey *wheel = new DTSurvey(nameWheel_m2, nameChambers_m2, -2);
0045 wheel->ReadChambers(pDD);
0046 wheel->CalculateChambers();
0047 outFile << *wheel;
0048 wheelList.push_back(wheel);
0049 }
0050 if (wheel_m1 == true) {
0051 DTSurvey *wheel = new DTSurvey(nameWheel_m1, nameChambers_m1, -1);
0052 wheel->ReadChambers(pDD);
0053 wheel->CalculateChambers();
0054 outFile << *wheel;
0055 wheelList.push_back(wheel);
0056 }
0057 if (wheel_0 == true) {
0058 DTSurvey *wheel = new DTSurvey(nameWheel_0, nameChambers_0, 0);
0059 wheel->ReadChambers(pDD);
0060 wheel->CalculateChambers();
0061 outFile << *wheel;
0062 wheelList.push_back(wheel);
0063 }
0064 if (wheel_p1 == true) {
0065 DTSurvey *wheel = new DTSurvey(nameWheel_p1, nameChambers_p1, 1);
0066 wheel->ReadChambers(pDD);
0067 wheel->CalculateChambers();
0068 outFile << *wheel;
0069 wheelList.push_back(wheel);
0070 }
0071 if (wheel_p2 == true) {
0072 DTSurvey *wheel = new DTSurvey(nameWheel_p2, nameChambers_p2, 2);
0073 wheel->ReadChambers(pDD);
0074 wheel->CalculateChambers();
0075 outFile << *wheel;
0076 wheelList.push_back(wheel);
0077 }
0078 outFile.close();
0079
0080 if (WriteToDB == true) {
0081
0082 const DTGeometry *dtGeometry = &iSetup.getData(dtGeomToken_);
0083 const CSCGeometry *cscGeometry = &iSetup.getData(cscGeomToken_);
0084 const GEMGeometry *gemGeometry = &iSetup.getData(gemGeomToken_);
0085
0086 MuonAlignment align(&*dtGeometry, &*cscGeometry, &*gemGeometry);
0087 std::ifstream inFile(outputFileName.c_str());
0088 while (!inFile.eof()) {
0089 float dx, dy, dz, sigma_dx, sigma_dy, sigma_dz;
0090 float alpha, beta, gamma, sigma_alpha, sigma_beta, sigma_gamma;
0091 inFile >> dx >> sigma_dx >> dy >> sigma_dy >> dz >> sigma_dz >> alpha >> sigma_alpha >> beta >> sigma_beta >>
0092 gamma >> sigma_gamma;
0093 if (inFile.eof())
0094 break;
0095 std::vector<float> displacement;
0096 displacement.push_back(dx);
0097 displacement.push_back(dy);
0098 displacement.push_back(dz);
0099 displacement.push_back(-alpha);
0100 displacement.push_back(-beta);
0101 displacement.push_back(-gamma);
0102 }
0103 inFile.close();
0104 align.saveToDB();
0105 }
0106 }
0107
0108 DEFINE_FWK_MODULE(DTSurveyConvert);