CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Alignment/SurveyAnalysis/plugins/SurveyDataConverter.cc

Go to the documentation of this file.
00001 
00002 // Framework
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 #include "Alignment/CommonAlignment/interface/AlignableModifier.h"
00008 #include "Alignment/TrackerAlignment/interface/TrackerAlignment.h"
00009 #include "Alignment/TrackerAlignment/interface/TrackerScenarioBuilder.h"
00010 #include "Alignment/CommonAlignment/interface/Alignable.h" 
00011 
00012 #include "Alignment/SurveyAnalysis/plugins/SurveyDataConverter.h"
00013 
00014 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00015 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00016 
00017 //__________________________________________________________________________________________________
00018 SurveyDataConverter::SurveyDataConverter(const edm::ParameterSet& iConfig) :
00019   theParameterSet( iConfig )
00020 {  
00021 }
00022 
00023 //__________________________________________________________________________________________________
00024 void SurveyDataConverter::analyze( const edm::Event& iEvent, const edm::EventSetup& iSetup )
00025 {
00026   //Retrieve tracker topology from geometry
00027   edm::ESHandle<TrackerTopology> tTopoHandle;
00028   iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
00029   const TrackerTopology* const tTopo = tTopoHandle.product();
00030   
00031   edm::LogInfo("SurveyDataConverter") << "Analyzer called";
00032   applyfineinfo = theParameterSet.getParameter<bool>("applyFineInfo");
00033   applycoarseinfo = theParameterSet.getParameter<bool>("applyCoarseInfo");
00034   adderrors = theParameterSet.getParameter<bool>("applyErrors");
00035 
00036   // Read in the information from the text files
00037   edm::ParameterSet textFiles = theParameterSet.getParameter<edm::ParameterSet>( "textFileNames" );
00038 
00039   std::string textFileNames[NFILES]; 
00040   std::string fileType[NFILES];    
00041   textFileNames[0] = textFiles.getUntrackedParameter<std::string>("forTIB","NONE");  
00042   fileType[0] = "TIB";
00043   textFileNames[1] = textFiles.getUntrackedParameter<std::string>("forTID","NONE");
00044   fileType[1] = "TID";
00045 
00046   SurveyDataReader dataReader;
00047   for (int ii=0 ; ii<NFILES ;ii++) {
00048     if ( textFileNames[ii] == "NONE" )
00049       throw cms::Exception("BadConfig") << fileType[ii] << " input file not found in configuration";
00050     dataReader.readFile( textFileNames[ii], fileType[ii], tTopo );
00051   }
00052 
00053   // Get info and map
00054   const MapType& mapIdToInfo = dataReader.detIdMap();
00055   std::cout << "DATA HAS BEEN READ INTO THE MAP" << std::endl;
00056   std::cout << "DATA HAS BEEN CONVERTED IN ALIGNABLE COORDINATES" << std::endl;  
00057 
00058   TrackerAlignment tr_align( iSetup );
00059   if (applycoarseinfo) this->applyCoarseSurveyInfo(tr_align); 
00060   if (applyfineinfo) this->applyFineSurveyInfo(tr_align, mapIdToInfo);
00061   if (adderrors) this->applyAPEs(tr_align);
00062   tr_align.saveToDB();
00063 }
00064 
00065 //___________________________________
00066 //
00067 void SurveyDataConverter::applyFineSurveyInfo( TrackerAlignment& tr_align, const MapType& map ){
00068 
00069   std::cout << "Apply fine info: " << std::endl;
00070         
00071   for ( MapType::const_iterator it = map.begin(); it != map.end(); it++){
00072 
00073     const align::Scalars& align_params = (it)->second; 
00074       
00075     align::Scalars translations; 
00076     translations.push_back(align_params[0]);  
00077     translations.push_back(align_params[1]);  
00078     translations.push_back(align_params[2]); 
00079 
00080     align::RotationType bRotation(align_params[6], align_params[9], align_params[3],
00081                                   align_params[7], align_params[10], align_params[4],
00082                                   align_params[8], align_params[11], align_params[5]);
00083 
00084     align::RotationType fRotation(align_params[15], align_params[18], align_params[12],
00085                                   align_params[16], align_params[19], align_params[13],
00086                                   align_params[17], align_params[20], align_params[14]);
00087 
00088     // Use "false" for debugging only
00089     tr_align.moveAlignableTIBTIDs((it)->first, translations, bRotation, fRotation, true);
00090   }
00091 }
00092 
00093 //___________________________________
00094 //
00095 void SurveyDataConverter::applyCoarseSurveyInfo( TrackerAlignment& tr_align ){
00096         
00097   std::cout << "Apply coarse info: " << std::endl;
00098   MisalignScenario = theParameterSet.getParameter<edm::ParameterSet>( "MisalignmentScenario" );
00099 
00100   TrackerScenarioBuilder scenarioBuilder( tr_align.getAlignableTracker() );
00101   scenarioBuilder.applyScenario( MisalignScenario );
00102   
00103 }
00104 
00105 //___________________________________
00106 //
00107 void SurveyDataConverter::applyAPEs( TrackerAlignment& tr_align ) {
00108         
00109   std::cout << "Apply APEs: " << std::endl;
00110   // Neglect sensor-on-module mounting precision (10 um)
00111   // Irrelevant given other sizes ..
00112   std::vector<double> TIBerrors = theParameterSet.getParameter< std::vector<double> >("TIBerrors");
00113   std::vector<double> TOBerrors = theParameterSet.getParameter< std::vector<double> >("TOBerrors");
00114   std::vector<double> TIDerrors = theParameterSet.getParameter< std::vector<double> >("TIDerrors"); 
00115   std::vector<double> TECerrors = theParameterSet.getParameter< std::vector<double> >("TECerrors"); 
00116         
00117   if (TIBerrors.size() < 3 || TOBerrors.size() < 4 || TIDerrors.size() < 4 || TECerrors.size() < 4) {
00118     std::cout << "APE info not valid : please check test/run-converter.cfg" << std::endl;
00119     return;
00120   }
00121          
00122   AlignableModifier* theModifier = new AlignableModifier();
00123   AlignableTracker* theAlignableTracker = tr_align.getAlignableTracker() ; 
00124   align::Alignables::const_iterator iter;
00125 
00126   // TIB
00127   const align::Alignables& theTIBhb = theAlignableTracker->innerHalfBarrels();
00128   for (iter = theTIBhb.begin(); iter != theTIBhb.end(); ++iter ) 
00129     { theModifier->addAlignmentPositionErrorLocal( *iter, TIBerrors.at(0), 
00130                                                    TIBerrors.at(0), TIBerrors.at(0) ); }
00131   const align::Alignables& theTIBlayers = theAlignableTracker->innerBarrelLayers();
00132   for (iter = theTIBlayers.begin(); iter != theTIBlayers.end(); ++iter)
00133     { theModifier->addAlignmentPositionErrorLocal( *iter, TIBerrors.at(1), 
00134                                                    TIBerrors.at(1), TIBerrors.at(1) ); }
00135   const align::Alignables& theTIBgd = theAlignableTracker->innerBarrelGeomDets();
00136   for (iter = theTIBgd.begin(); iter != theTIBgd.end(); ++iter ) 
00137     { theModifier->addAlignmentPositionErrorLocal( *iter, TIBerrors.at(2), 
00138                                                    TIBerrors.at(2), TIBerrors.at(2) ); }
00139 
00140   // TOB
00141   const align::Alignables& theTOBhb = theAlignableTracker->outerHalfBarrels();
00142   for (iter = theTOBhb.begin(); iter != theTOBhb.end(); ++iter )
00143     { theModifier->addAlignmentPositionErrorLocal( *iter, TOBerrors.at(0), 
00144                                                    TOBerrors.at(0), TOBerrors.at(1) ); }
00145   const align::Alignables& theTOBrods = theAlignableTracker->outerBarrelRods();
00146   for (iter = theTOBrods.begin(); iter != theTOBrods.end(); ++iter ) 
00147     { theModifier->addAlignmentPositionErrorLocal( *iter, TOBerrors.at(2), 
00148                                                    TOBerrors.at(2), TOBerrors.at(2) ); }
00149   const align::Alignables& theTOBgd = theAlignableTracker->outerBarrelGeomDets();
00150   for (iter = theTOBgd.begin(); iter != theTOBgd.end(); ++iter )
00151     { theModifier->addAlignmentPositionErrorLocal( *iter, TOBerrors.at(3), 
00152                                                    TOBerrors.at(3), TOBerrors.at(3) ); }
00153 
00154   // TID
00155   const align::Alignables& theTIDs = theAlignableTracker->TIDs();
00156   for (iter = theTIDs.begin(); iter != theTIDs.end(); ++iter ) 
00157     { theModifier->addAlignmentPositionErrorLocal( *iter, TIDerrors.at(0), 
00158                                                    TIDerrors.at(0), TIDerrors.at(0) ); }
00159   const align::Alignables& theTIDdiscs = theAlignableTracker->TIDLayers();
00160   for (iter = theTIDdiscs.begin(); iter != theTIDdiscs.end(); ++iter )
00161     { theModifier->addAlignmentPositionErrorLocal( *iter, TIDerrors.at(1), 
00162                                                    TIDerrors.at(1), TIDerrors.at(1) ); }
00163   const align::Alignables& theTIDrings = theAlignableTracker->TIDRings();
00164   for (iter = theTIDrings.begin(); iter != theTIDrings.end(); ++iter )
00165     { theModifier->addAlignmentPositionErrorLocal( *iter, TIDerrors.at(2), 
00166                                                    TIDerrors.at(2), TIDerrors.at(2) ); } 
00167   const align::Alignables& theTIDgd = theAlignableTracker->TIDGeomDets();
00168   for (iter = theTIDgd.begin(); iter != theTIDgd.end(); ++iter )
00169     { theModifier->addAlignmentPositionErrorLocal( *iter, TIDerrors.at(3), 
00170                                                    TIDerrors.at(3), TIDerrors.at(3) ); } 
00171 
00172   // TEC
00173   const align::Alignables& theTECs = theAlignableTracker->endCaps();
00174   for (iter = theTECs.begin(); iter != theTECs.end(); ++iter ) 
00175     { theModifier->addAlignmentPositionErrorLocal( *iter, TECerrors.at(0), 
00176                                                    TECerrors.at(0), TECerrors.at(0) ); } 
00177   const align::Alignables& theTECdiscs = theAlignableTracker->endcapLayers();
00178   for (iter = theTECdiscs.begin(); iter != theTECdiscs.end(); ++iter )
00179     { theModifier->addAlignmentPositionErrorLocal( *iter, TECerrors.at(1), 
00180                                                    TECerrors.at(1), TECerrors.at(1) ); } 
00181   const align::Alignables& theTECpetals = theAlignableTracker->endcapPetals();
00182   for (iter = theTECpetals.begin(); iter != theTECpetals.end(); ++iter ) 
00183     { theModifier->addAlignmentPositionErrorLocal( *iter, TECerrors.at(2), 
00184                                                    TECerrors.at(2), TECerrors.at(2) ); }   
00185   const align::Alignables& theTECgd = theAlignableTracker->endcapGeomDets();
00186   for (iter = theTECgd.begin(); iter != theTECgd.end(); ++iter )
00187     { theModifier->addAlignmentPositionErrorLocal( *iter, TECerrors.at(3), 
00188                                                    TECerrors.at(3), TECerrors.at(3) ); }   
00189 }
00190 
00191 DEFINE_FWK_MODULE(SurveyDataConverter);
00192