Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:24

0001 /** \class SurveyInputDummy
0002  *
0003  *  For uploading some random survey values and pseudo-dummy errors to DB.
0004  *
0005  *  If randomizeValue is true, the survey value of a structure in a level
0006  *  is randomly selected from a Gaussian distribution of mean given by the
0007  *  ideal geometry and width = "value" (e.g. width = 5e-4 for a Panel).
0008  *  
0009  *  The covariance matrix for all structures of a level will be diagonal
0010  *  given by value^2 * identity.
0011  *
0012  *  \author Chung Khim Lae
0013  */
0014 
0015 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
0016 #include "Alignment/CommonAlignment/interface/StructureType.h"
0017 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
0018 #include "Alignment/SurveyAnalysis/interface/SurveyInputBase.h"
0019 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0020 #include "FWCore/Framework/interface/ESHandle.h"
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0024 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0025 #include "TRandom3.h"
0026 
0027 #include <map>
0028 
0029 class SurveyInputDummy : public SurveyInputBase {
0030 public:
0031   SurveyInputDummy(const edm::ParameterSet&);
0032 
0033   /// Read ideal tracker geometry from DB
0034   virtual void analyze(const edm::Event&, const edm::EventSetup&);
0035 
0036 private:
0037   /// Add survey info to an alignable
0038   void addSurveyInfo(Alignable*);
0039 
0040   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0041   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0042   const bool theRandomizeValue;  // randomize survey values if true
0043 
0044   std::map<align::StructureType, double> theErrors;
0045 };
0046 
0047 SurveyInputDummy::SurveyInputDummy(const edm::ParameterSet& cfg)
0048     : tTopoToken_(esConsumes()),
0049       tkGeomToken_(esConsumes()),
0050       theRandomizeValue(cfg.getParameter<bool>("randomizeValue")) {
0051   typedef std::vector<edm::ParameterSet> ParameterSets;
0052 
0053   const ParameterSets& errors = cfg.getParameter<ParameterSets>("errors");
0054 
0055   unsigned int nError = errors.size();
0056 
0057   // FIXME: - currently defaulting to RunI as this was the previous behaviour
0058   //        - check this, when resurrecting this code in the future
0059   AlignableObjectId alignableObjectId{AlignableObjectId::Geometry::General};
0060 
0061   for (unsigned int i = 0; i < nError; ++i) {
0062     const edm::ParameterSet& error = errors[i];
0063 
0064     theErrors[alignableObjectId.stringToId(error.getParameter<std::string>("level"))] =
0065         error.getParameter<double>("value");
0066   }
0067 }
0068 
0069 void SurveyInputDummy::analyze(const edm::Event&, const edm::EventSetup& setup) {
0070   if (theFirstEvent) {
0071     //Retrieve tracker topology from geometry
0072     const TrackerTopology* const tTopo = &setup.getData(tTopoToken_);
0073     const TrackerGeometry* tracker = &setup.getData(tkGeomToken_);
0074 
0075     Alignable* ali = new AlignableTracker(tracker, tTopo);
0076 
0077     addSurveyInfo(ali);
0078     addComponent(ali);
0079 
0080     theFirstEvent = false;
0081   }
0082 }
0083 
0084 void SurveyInputDummy::addSurveyInfo(Alignable* ali) {
0085   static TRandom3 rand;
0086 
0087   const align::Alignables& comp = ali->components();
0088 
0089   unsigned int nComp = comp.size();
0090 
0091   for (unsigned int i = 0; i < nComp; ++i)
0092     addSurveyInfo(comp[i]);
0093 
0094   align::ErrorMatrix cov;  // default 0
0095 
0096   std::map<align::StructureType, double>::const_iterator e = theErrors.find(ali->alignableObjectId());
0097 
0098   if (theErrors.end() != e) {
0099     double error = e->second;
0100 
0101     if (theRandomizeValue) {
0102       double x = rand.Gaus(0., error);
0103       double y = rand.Gaus(0., error);
0104       double z = rand.Gaus(0., error);
0105       double a = rand.Gaus(0., error);
0106       double b = rand.Gaus(0., error);
0107       double g = rand.Gaus(0., error);
0108 
0109       align::EulerAngles angles(3);
0110 
0111       angles(1) = a;
0112       angles(2) = b;
0113       angles(3) = g;
0114 
0115       ali->move(ali->surface().toGlobal(align::LocalVector(x, y, z)));
0116       ali->rotateInLocalFrame(align::toMatrix(angles));
0117     }
0118 
0119     cov = ROOT::Math::SMatrixIdentity();
0120     cov *= error * error;
0121   }
0122 
0123   ali->setSurvey(new SurveyDet(ali->surface(), cov));
0124 }
0125 
0126 #include "FWCore/Framework/interface/MakerMacros.h"
0127 DEFINE_FWK_MODULE(SurveyInputDummy);