CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
CocoaAnalyzer Class Reference
Inheritance diagram for CocoaAnalyzer:
edm::one::EDAnalyzer< edm::one::SharedResources > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c) override
 
void beginJob () override
 
 CocoaAnalyzer (edm::ParameterSet const &p)
 
 CocoaAnalyzer (int i)
 
 ~CocoaAnalyzer () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::SharedResources >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const noexcept
 
bool wantsStreamRuns () const noexcept
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void correctAllOpticalAlignments (std::vector< OpticalAlignInfo > &allDBOpticalAlignments)
 
void correctOpticalAlignmentParameter (OpticalAlignParam &myXMLParam, const OpticalAlignParam &myDBParam)
 
std::vector< OpticalAlignInforeadCalibrationDB (const edm::EventSetup &evts)
 
void readXMLFile (const edm::EventSetup &evts)
 
void runCocoa ()
 

Private Attributes

edm::ESGetToken< cms::DDCompactView, IdealGeometryRecordddcvToken
 
OpticalAlignMeasurements measList_
 
OpticalAlignments oaList_
 
edm::ESGetToken< OpticalAlignments, OpticalAlignmentsRcdoptAliToken
 
std::string theCocoaDaqRootFileName_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 29 of file CocoaAnalyzer.cc.

Constructor & Destructor Documentation

◆ CocoaAnalyzer() [1/2]

CocoaAnalyzer::CocoaAnalyzer ( edm::ParameterSet const &  p)
explicit

Definition at line 55 of file CocoaAnalyzer.cc.

References GlobalOptionMgr::getInstance(), Data_TkAlMinBias_Run2018C_PromptReco_v3_cff::maxEvents, muonDTDigis_cfi::pset, GlobalOptionMgr::setDefaultGlobalOptions(), GlobalOptionMgr::setGlobalOption(), AlCaHLTBitMon_QueryRunRegistry::string, and theCocoaDaqRootFileName_.

56  theCocoaDaqRootFileName_ = pset.getParameter<std::string>("cocoaDaqRootFile");
57  int maxEvents = pset.getParameter<int32_t>("maxEvents");
60  GlobalOptionMgr::getInstance()->setGlobalOption("writeDBAlign", 1);
61  GlobalOptionMgr::getInstance()->setGlobalOption("writeDBOptAlign", 1);
62  usesResource("CocoaAnalyzer");
63 }
std::string theCocoaDaqRootFileName_
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > ddcvToken
static GlobalOptionMgr * getInstance()
edm::ESGetToken< OpticalAlignments, OpticalAlignmentsRcd > optAliToken
void setGlobalOption(const ALIstring go, const ALIdouble val, ALIFileIn &filein)
void setDefaultGlobalOptions()
Set the list of default global options.

◆ CocoaAnalyzer() [2/2]

CocoaAnalyzer::CocoaAnalyzer ( int  i)
inlineexplicit

Definition at line 32 of file CocoaAnalyzer.cc.

32 {}

◆ ~CocoaAnalyzer()

CocoaAnalyzer::~CocoaAnalyzer ( )
inlineoverride

Definition at line 33 of file CocoaAnalyzer.cc.

33 {}

Member Function Documentation

◆ analyze()

void CocoaAnalyzer::analyze ( const edm::Event e,
const edm::EventSetup c 
)
overridevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 67 of file CocoaAnalyzer.cc.

References correctAllOpticalAlignments(), readCalibrationDB(), readXMLFile(), runCocoa(), and ALIUtils::setDebugVerbosity().

67  {
69 
70  // Get ideal geometry description + measurements for simulation.
71  readXMLFile(evts);
72 
73  // Correct ideal geometry with data from DB.
74  std::vector<OpticalAlignInfo> oaListCalib = readCalibrationDB(evts);
75  correctAllOpticalAlignments(oaListCalib);
76 
77  // Run the least-squared fit and store results in DB.
78  runCocoa();
79 }
void readXMLFile(const edm::EventSetup &evts)
void correctAllOpticalAlignments(std::vector< OpticalAlignInfo > &allDBOpticalAlignments)
std::vector< OpticalAlignInfo > readCalibrationDB(const edm::EventSetup &evts)
static void setDebugVerbosity(ALIint val)
Definition: ALIUtils.h:38

◆ beginJob()

void CocoaAnalyzer::beginJob ( )
overridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 65 of file CocoaAnalyzer.cc.

65 {}

◆ correctAllOpticalAlignments()

void CocoaAnalyzer::correctAllOpticalAlignments ( std::vector< OpticalAlignInfo > &  allDBOpticalAlignments)
private

Definition at line 472 of file CocoaAnalyzer.cc.

References correctOpticalAlignmentParameter(), ALIUtils::debug, oaList_, and OpticalAlignments::opticalAlignments_.

Referenced by analyze().

472  {
473  if (ALIUtils::debug >= 3) {
474  edm::LogInfo("Alignment") << "$$$ CocoaAnalyzer::correctAllOpticalAlignments: ";
475  }
476 
477  for (const auto& myDBInfo : allDBOpticalAlignments) {
478  if (ALIUtils::debug >= 5) {
479  edm::LogInfo("Alignment") << "CocoaAnalyzer::findOpticalAlignInfoXML: Looking for OAI " << myDBInfo.name_;
480  }
481 
482  std::vector<OpticalAlignInfo>& allXMLOpticalAlignments = oaList_.opticalAlignments_;
483  const auto& myXMLInfo = std::find_if(
484  allXMLOpticalAlignments.begin(), allXMLOpticalAlignments.end(), [&](const auto& myXMLInfoCandidate) {
485  return myXMLInfoCandidate.name_ == myDBInfo.name_;
486  });
487 
488  if (myXMLInfo != allXMLOpticalAlignments.end()) {
489  if (ALIUtils::debug >= 4) {
490  edm::LogInfo("Alignment") << "CocoaAnalyzer::findOpticalAlignInfoXML: OAI found " << myXMLInfo->name_;
491  edm::LogInfo("Alignment")
492  << "CocoaAnalyzer::correctAllOpticalAlignments: correcting data from XML with DB info.";
493  }
494  correctOpticalAlignmentParameter(myXMLInfo->x_, myDBInfo.x_);
495  correctOpticalAlignmentParameter(myXMLInfo->y_, myDBInfo.y_);
496  correctOpticalAlignmentParameter(myXMLInfo->z_, myDBInfo.z_);
497  correctOpticalAlignmentParameter(myXMLInfo->angx_, myDBInfo.angx_);
498  correctOpticalAlignmentParameter(myXMLInfo->angy_, myDBInfo.angy_);
499  correctOpticalAlignmentParameter(myXMLInfo->angz_, myDBInfo.angz_);
500 
501  // Also correct extra entries
502  const std::vector<OpticalAlignParam>& allDBExtraEntries = myDBInfo.extraEntries_;
503  std::vector<OpticalAlignParam>& allXMLExtraEntries = myXMLInfo->extraEntries_;
504  for (const auto& myDBExtraEntry : allDBExtraEntries) {
505  const auto& myXMLExtraEntry = std::find_if(
506  allXMLExtraEntries.begin(), allXMLExtraEntries.end(), [&](const auto& myXMLExtraEntryCandidate) {
507  return myXMLExtraEntryCandidate.name_ == myDBExtraEntry.name_;
508  });
509 
510  if (myXMLExtraEntry != allXMLExtraEntries.end()) {
511  correctOpticalAlignmentParameter(*myXMLExtraEntry, myDBExtraEntry);
512  } else {
513  if (myDBExtraEntry.name_ != "None") {
514  if (ALIUtils::debug >= 2) {
515  edm::LogError("Alignment")
516  << "CocoaAnalyzer::correctAllOpticalAlignments: extra entry read from DB is not present in XML "
517  << myDBExtraEntry << " in object " << myDBInfo;
518  }
519  }
520  }
521  }
522 
523  if (ALIUtils::debug >= 5) {
524  edm::LogInfo("Alignment") << "CocoaAnalyzer::correctAllOpticalAlignments: corrected OpticalAlingInfo "
525  << oaList_;
526  }
527  } else {
528  if (ALIUtils::debug >= 2) {
529  edm::LogError("Alignment") << "CocoaAnalyzer::correctAllOpticalAlignments: OpticalAlignInfo read from DB "
530  << myDBInfo << " is not present in XML.";
531  }
532  }
533  }
534 }
static ALIint debug
Definition: ALIUtils.h:34
Log< level::Error, false > LogError
std::vector< OpticalAlignInfo > opticalAlignments_
Log< level::Info, false > LogInfo
void correctOpticalAlignmentParameter(OpticalAlignParam &myXMLParam, const OpticalAlignParam &myDBParam)
OpticalAlignments oaList_

◆ correctOpticalAlignmentParameter()

void CocoaAnalyzer::correctOpticalAlignmentParameter ( OpticalAlignParam myXMLParam,
const OpticalAlignParam myDBParam 
)
private

Definition at line 539 of file CocoaAnalyzer.cc.

References ALIUtils::debug, OpticalAlignParam::dimType(), visualization-live-secondInstance_cfg::m, AlCaHLTBitMon_QueryRunRegistry::string, and OpticalAlignParam::value_.

Referenced by correctAllOpticalAlignments().

540  {
541  if (myDBParam.value_ != -9.999E9) {
542  const std::string& type = myDBParam.dimType();
543  double dimFactor = 1.;
544 
545  if (type == "centre" || type == "length") {
546  dimFactor = 1. / dd4hep::m; // in DB values are stored in dd4hep unit
547  } else if (type == "angles" || type == "angle" || type == "nodim") {
548  dimFactor = 1.;
549  } else {
550  edm::LogError("Alignment") << "Incorrect OpticalAlignParam type = " << type;
551  }
552 
553  const double correctedValue = myDBParam.value_ * dimFactor;
554  if (ALIUtils::debug >= 4) {
555  edm::LogInfo("Alignment") << "CocoaAnalyzer::correctOpticalAlignmentParameter old value= " << myXMLParam.value_
556  << " new value= " << correctedValue;
557  }
558  myXMLParam.value_ = correctedValue;
559  }
560 }
static ALIint debug
Definition: ALIUtils.h:34
Log< level::Error, false > LogError
Log< level::Info, false > LogInfo
std::string dimType() const

◆ readCalibrationDB()

std::vector< OpticalAlignInfo > CocoaAnalyzer::readCalibrationDB ( const edm::EventSetup evts)
private

Definition at line 449 of file CocoaAnalyzer.cc.

References ALIUtils::debug, edm::EventSetup::getData(), optAliToken, and OpticalAlignments::opticalAlignments_.

Referenced by analyze().

449  {
450  if (ALIUtils::debug >= 3) {
451  edm::LogInfo("Alignment") << "$$$ CocoaAnalyzer::readCalibrationDB: ";
452  }
453 
454  using namespace edm::eventsetup;
455  const OpticalAlignments* pObjs = &evts.getData(optAliToken);
456  const std::vector<OpticalAlignInfo>& infoFromDB = pObjs->opticalAlignments_;
457 
458  if (ALIUtils::debug >= 5) {
459  edm::LogInfo("Alignment") << "CocoaAnalyzer::readCalibrationDB: Number of OpticalAlignInfo READ "
460  << infoFromDB.size();
461  for (const auto& myInfoFromDB : infoFromDB) {
462  edm::LogInfo("Alignment") << "CocoaAnalyzer::readCalibrationDB: OpticalAlignInfo READ " << myInfoFromDB;
463  }
464  }
465 
466  return infoFromDB;
467 }
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
static ALIint debug
Definition: ALIUtils.h:34
std::vector< OpticalAlignInfo > opticalAlignments_
edm::ESGetToken< OpticalAlignments, OpticalAlignmentsRcd > optAliToken
Log< level::Info, false > LogInfo

◆ readXMLFile()

void CocoaAnalyzer::readXMLFile ( const edm::EventSetup evts)
private

Definition at line 86 of file CocoaAnalyzer.cc.

References OpticalAlignInfo::angx_, OpticalAlignInfo::angy_, OpticalAlignInfo::angz_, OpticalAlignMeasurementInfo::clear(), OpticalAlignParam::clear(), OpticalAlignInfo::clear(), ddcvToken, ALIUtils::debug, cms::DDCompactView::detector(), OpticalAlignParam::dim_type_, OpticalAlignParam::error_, OpticalAlignInfo::extraEntries_, cms::DDFilteredView::firstChild(), ALIUtils::getRotationAnglesFromMatrix(), edm::EventSetup::getTransientHandle(), mps_fire::i, testProducerWithPsetDescEmpty_cfi::i2, OpticalAlignMeasurementInfo::ID_, OpticalAlignInfo::ID_, OpticalAlignMeasurementInfo::isSimulatedValue_, visualization-live-secondInstance_cfg::m, measList_, OpticalAlignMeasurementInfo::measObjectNames_, cms::DDFilteredView::mergedSpecifics(), Skims_PA_cff::name, OpticalAlignMeasurementInfo::name_, OpticalAlignParam::name_, OpticalAlignInfo::name_, names, oaList_, OpticalAlignMeasurements::oaMeasurements_, OpticalAlignments::opticalAlignments_, OpticalAlignInfo::parentName_, cms::DDFilteredView::path(), quality, OpticalAlignParam::quality_, makeMuonMisalignmentScenario::rot, cms::DDCompactView::specpars(), AlCaHLTBitMon_QueryRunRegistry::string, OpticalAlignMeasurementInfo::type_, OpticalAlignInfo::type_, OpticalAlignParam::value_, contentValuesCheck::values, OpticalAlignMeasurementInfo::values_, cms::DDFilteredView::volume(), cms::DDDetector::worldVolume(), OpticalAlignInfo::x_, geometryCSVtoXML::xx, geometryCSVtoXML::xy, geometryCSVtoXML::xz, OpticalAlignInfo::y_, geometryCSVtoXML::yy, geometryCSVtoXML::yz, OpticalAlignInfo::z_, and geometryCSVtoXML::zz.

Referenced by analyze().

86  {
88  const cms::DDDetector* mySystem = myCompactView->detector();
89 
90  if (mySystem) {
91  // Always store world volume first.
92  const dd4hep::Volume& worldVolume = mySystem->worldVolume();
93 
94  if (ALIUtils::debug >= 3) {
95  edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML: world object = " << worldVolume.name();
96  }
97 
98  OpticalAlignInfo worldInfo;
99  worldInfo.ID_ = 0;
100  worldInfo.name_ = worldVolume.name();
101  worldInfo.type_ = "system";
102  worldInfo.parentName_ = "";
103  worldInfo.x_.value_ = 0.;
104  worldInfo.x_.error_ = 0.;
105  worldInfo.x_.quality_ = 0;
106  worldInfo.y_.value_ = 0.;
107  worldInfo.y_.error_ = 0.;
108  worldInfo.y_.quality_ = 0;
109  worldInfo.z_.value_ = 0.;
110  worldInfo.z_.error_ = 0.;
111  worldInfo.z_.quality_ = 0;
112  worldInfo.angx_.value_ = 0.;
113  worldInfo.angx_.error_ = 0.;
114  worldInfo.angx_.quality_ = 0;
115  worldInfo.angy_.value_ = 0.;
116  worldInfo.angy_.error_ = 0.;
117  worldInfo.angy_.quality_ = 0;
118  worldInfo.angz_.value_ = 0.;
119  worldInfo.angz_.error_ = 0.;
120  worldInfo.angz_.quality_ = 0;
121  oaList_.opticalAlignments_.emplace_back(worldInfo);
122 
123  // This gathers all the 'SpecPar' sections from the loaded XMLs.
124  // NB: Definition of a SpecPar section:
125  // It is a block in the XML file(s), containing paths to specific volumes,
126  // and ALLOWING THE ASSOCIATION OF SPECIFIC PARAMETERS AND VALUES TO THESE VOLUMES.
127  const cms::DDSpecParRegistry& allSpecParSections = myCompactView->specpars();
128 
129  // CREATION OF A COCOA FILTERED VIEW
130  // Creation of the dd4hep-based filtered view.
131  // NB: not filtered yet!
132  cms::DDFilteredView myFilteredView(mySystem, worldVolume);
133  // Declare a container which will gather all the filtered SpecPar sections.
134  cms::DDSpecParRefs cocoaParameterSpecParSections;
135  // Define a COCOA filter
136  const std::string cocoaParameterAttribute = "COCOA";
137  const std::string cocoaParameterValue = "COCOA";
138  // All the COCOA SpecPar sections are filtered from allSpecParSections,
139  // and assigned to cocoaParameterSpecParSections.
140  allSpecParSections.filter(cocoaParameterSpecParSections, cocoaParameterAttribute, cocoaParameterValue);
141  // This finally allows to filter the filtered view, with the COCOA filter.
142  // This means that we now have, in myFilteredView, all volumes whose paths were selected:
143  // ie all volumes with "COCOA" parameter and value in a SpecPar section from a loaded XML.
144  myFilteredView.mergedSpecifics(cocoaParameterSpecParSections);
145 
146  // Loop on parts
147  int nObjects = 0;
148  bool doCOCOA = myFilteredView.firstChild();
149 
150  // Loop on all COCOA volumes from filtered view
151  while (doCOCOA) {
152  ++nObjects;
153 
154  OpticalAlignInfo oaInfo;
155  OpticalAlignParam oaParam;
157 
158  // Current volume
159  const dd4hep::PlacedVolume& myPlacedVolume = myFilteredView.volume();
160  const std::string& name = myPlacedVolume.name();
161  const std::string& nodePath = myFilteredView.path();
162  oaInfo.name_ = nodePath;
163 
164  // Parent name
165  oaInfo.parentName_ = nodePath.substr(0, nodePath.rfind('/', nodePath.length()));
166 
167  if (ALIUtils::debug >= 4) {
168  edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML reading object " << name;
169  edm::LogInfo("Alignment") << " @@ Name built= " << oaInfo.name_ << " short_name= " << name
170  << " parent= " << oaInfo.parentName_;
171  }
172 
173  // TRANSLATIONS
174 
175  // A) GET TRANSLATIONS FROM DDETECTOR.
176  // Directly get translation from parent to child volume
177  const dd4hep::Direction& transl = myPlacedVolume.position();
178 
179  if (ALIUtils::debug >= 4) {
180  edm::LogInfo("Alignment") << "Local translation in dd4hep units = " << transl;
181  }
182 
183  // B) READ INFO FROM XMLS
184  // X
185  oaInfo.x_.name_ = "X";
186  oaInfo.x_.dim_type_ = "centre";
187  oaInfo.x_.value_ = transl.x() / dd4hep::m; // COCOA units are m
188  oaInfo.x_.error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
189  nodePath,
190  "centre_X_sigma",
191  0) /
192  dd4hep::m; // COCOA units are m
193  oaInfo.x_.quality_ = static_cast<int>(
194  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_X_quality", 0));
195  // Y
196  oaInfo.y_.name_ = "Y";
197  oaInfo.y_.dim_type_ = "centre";
198  oaInfo.y_.value_ = transl.y() / dd4hep::m; // COCOA units are m
199  oaInfo.y_.error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
200  nodePath,
201  "centre_Y_sigma",
202  0) /
203  dd4hep::m; // COCOA units are m
204  oaInfo.y_.quality_ = static_cast<int>(
205  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_Y_quality", 0));
206  // Z
207  oaInfo.z_.name_ = "Z";
208  oaInfo.z_.dim_type_ = "centre";
209  oaInfo.z_.value_ = transl.z() / dd4hep::m; // COCOA units are m
210  oaInfo.z_.error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
211  nodePath,
212  "centre_Z_sigma",
213  0) /
214  dd4hep::m; // COCOA units are m
215  oaInfo.z_.quality_ = static_cast<int>(
216  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_Z_quality", 0));
217 
218  // ROTATIONS
219 
220  // A) GET ROTATIONS FROM DDETECTOR.
221 
222  // Unlike in the initial code, here we manage to directly get the rotation matrix placement
223  // of the child in parent, EXPRESSED IN THE PARENT FRAME OF REFERENCE.
224  // Hence the (ugly) initial block of code is replaced by just 2 lines.
225  // PlacedVolume::matrix() returns the rotation matrix IN THE PARENT FRAME OF REFERENCE.
226  // NB: Not using DDFilteredView::rotation(),
227  // because it returns the rotation matrix IN THE WORLD FRAME OF REFERENCE.
228  const TGeoHMatrix parentToChild = myPlacedVolume.matrix();
229  // COCOA convention is FROM CHILD TO PARENT
230  const TGeoHMatrix& childToParent = parentToChild.Inverse();
231 
232  // Convert it to CLHEP::Matrix
233  // Below is not my code, below block is untouched (apart from bug fix).
234  // I would just directly use childToParent...
235  const Double_t* rot = childToParent.GetRotationMatrix();
236  const double xx = rot[0];
237  const double xy = rot[1];
238  const double xz = rot[2];
239  const double yx = rot[3];
240  const double yy = rot[4];
241  const double yz = rot[5];
242  const double zx = rot[6];
243  const double zy = rot[7];
244  const double zz = rot[8];
245  if (ALIUtils::debug >= 4) {
246  edm::LogInfo("Alignment") << "Local rotation = ";
247  edm::LogInfo("Alignment") << xx << " " << xy << " " << xz;
248  edm::LogInfo("Alignment") << yx << " " << yy << " " << yz;
249  edm::LogInfo("Alignment") << zx << " " << zy << " " << zz;
250  }
251  const CLHEP::Hep3Vector colX(xx, yx, zx);
252  const CLHEP::Hep3Vector colY(xy, yy, zy);
253  const CLHEP::Hep3Vector colZ(xz, yz, zz);
254  const CLHEP::HepRotation rotclhep(colX, colY, colZ);
255  const std::vector<double>& angles = ALIUtils::getRotationAnglesFromMatrix(rotclhep, 0., 0., 0.);
256 
257  // B) READ INFO FROM XMLS
258  // X
259  oaInfo.angx_.name_ = "X";
260  oaInfo.angx_.dim_type_ = "angles";
261  oaInfo.angx_.value_ =
262  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_value", 0);
263  oaInfo.angx_.error_ =
264  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_sigma", 0);
265  oaInfo.angx_.quality_ = static_cast<int>(
266  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_quality", 0));
267  // Y
268  oaInfo.angy_.name_ = "Y";
269  oaInfo.angy_.dim_type_ = "angles";
270  oaInfo.angy_.value_ =
271  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_value", 0);
272  oaInfo.angy_.error_ =
273  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_sigma", 0);
274  oaInfo.angy_.quality_ = static_cast<int>(
275  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_quality", 0));
276  // Z
277  oaInfo.angz_.name_ = "Z";
278  oaInfo.angz_.dim_type_ = "angles";
279  oaInfo.angz_.value_ =
280  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_value", 0);
281  oaInfo.angz_.error_ =
282  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_sigma", 0);
283  oaInfo.angz_.quality_ = static_cast<int>(
284  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_quality", 0));
285 
286  oaInfo.type_ =
287  cms::getParameterValueFromSpecParSections<std::string>(allSpecParSections, nodePath, "cocoa_type", 0);
288 
289  oaInfo.ID_ = static_cast<int>(
290  cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "cmssw_ID", 0));
291 
292  if (ALIUtils::debug >= 4) {
293  edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML OBJECT " << oaInfo.name_ << " pos/angles read ";
294  }
295 
296  // Check that rotations match with values from XMLs.
297  // Same, that ugly code is not mine ;p
298  if (fabs(oaInfo.angx_.value_ - angles[0]) > 1.E-9 || fabs(oaInfo.angy_.value_ - angles[1]) > 1.E-9 ||
299  fabs(oaInfo.angz_.value_ - angles[2]) > 1.E-9) {
300  edm::LogError("Alignment") << " WRONG ANGLE IN OBJECT " << oaInfo.name_ << oaInfo.angx_.value_ << " =? "
301  << angles[0] << oaInfo.angy_.value_ << " =? " << angles[1] << oaInfo.angz_.value_
302  << " =? " << angles[2];
303  }
304 
305  // EXTRA PARAM ENTRIES (FROM XMLS)
306  // Here initial code to define the containers was fully removed, this is much more compact.
307  const std::vector<std::string>& names =
308  cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "extra_entry");
309  const std::vector<std::string>& dims =
310  cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "dimType");
311  const std::vector<double>& values =
312  cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "value");
313  const std::vector<double>& errors =
314  cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "sigma");
315  const std::vector<double>& quality =
316  cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "quality");
317 
318  if (ALIUtils::debug >= 4) {
319  edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML: Fill extra entries with read parameters ";
320  }
321 
322  if (names.size() == dims.size() && dims.size() == values.size() && values.size() == errors.size() &&
323  errors.size() == quality.size()) {
324  for (size_t i = 0; i < names.size(); ++i) {
325  double dimFactor = 1.;
326  const std::string& type = dims[i];
327  if (type == "centre" || type == "length") {
328  dimFactor =
329  1. / dd4hep::m; // was converted to dd4hep unit with getParameterValueFromSpecPar, COCOA unit is m
330  } else if (type == "angles" || type == "angle" || type == "nodim") {
331  dimFactor = 1.;
332  }
333  oaParam.value_ = values[i] * dimFactor;
334  oaParam.error_ = errors[i] * dimFactor;
335  oaParam.quality_ = static_cast<int>(quality[i]);
336  oaParam.name_ = names[i];
337  oaParam.dim_type_ = dims[i];
338  oaInfo.extraEntries_.emplace_back(oaParam);
339  oaParam.clear();
340  }
341 
342  oaList_.opticalAlignments_.emplace_back(oaInfo);
343  } else {
344  edm::LogInfo("Alignment") << "WARNING FOR NOW: sizes of extra parameters (names, dimType, value, quality) do"
345  << " not match! Did not add " << nObjects << " item to OpticalAlignments.";
346  }
347 
348  // MEASUREMENTS (FROM XMLS)
349  const std::vector<std::string>& measNames =
350  cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "meas_name");
351  const std::vector<std::string>& measTypes =
352  cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "meas_type");
353 
354  std::map<std::string, std::vector<std::string>> measObjectNames;
355  std::map<std::string, std::vector<std::string>> measParamNames;
356  std::map<std::string, std::vector<double>> measParamValues;
357  std::map<std::string, std::vector<double>> measParamSigmas;
358  std::map<std::string, std::vector<double>> measIsSimulatedValue;
359  for (const auto& name : measNames) {
360  measObjectNames[name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
361  allSpecParSections, nodePath, "meas_object_name_" + name);
362  measParamNames[name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
363  allSpecParSections, nodePath, "meas_value_name_" + name);
364  measParamValues[name] =
365  cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "meas_value_" + name);
366  measParamSigmas[name] =
367  cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "meas_sigma_" + name);
368  measIsSimulatedValue[name] = cms::getAllParameterValuesFromSpecParSections<double>(
369  allSpecParSections, nodePath, "meas_is_simulated_value_" + name);
370  }
371 
372  if (ALIUtils::debug >= 4) {
373  edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML: Fill measurements with read parameters ";
374  }
375 
376  if (measNames.size() == measTypes.size()) {
377  for (size_t i = 0; i < measNames.size(); ++i) {
378  oaMeas.ID_ = i;
379  oaMeas.name_ = measNames[i];
380  oaMeas.type_ = measTypes[i];
381  oaMeas.measObjectNames_ = measObjectNames[oaMeas.name_];
382  if (measParamNames.size() == measParamValues.size() && measParamValues.size() == measParamSigmas.size()) {
383  for (size_t i2 = 0; i2 < measParamNames[oaMeas.name_].size(); i2++) {
384  oaParam.name_ = measParamNames[oaMeas.name_][i2];
385  oaParam.value_ = measParamValues[oaMeas.name_][i2];
386  oaParam.error_ = measParamSigmas[oaMeas.name_][i2];
387  oaParam.quality_ = 2;
388  if (oaMeas.type_ == "SENSOR2D" || oaMeas.type_ == "COPS" || oaMeas.type_ == "DISTANCEMETER" ||
389  oaMeas.type_ == "DISTANCEMETER!DIM" || oaMeas.type_ == "DISTANCEMETER3DIM") {
390  oaParam.dim_type_ = "length";
391  } else if (oaMeas.type_ == "TILTMETER") {
392  oaParam.dim_type_ = "angle";
393  } else {
394  edm::LogError("Alignment") << "CocoaAnalyzer::readXMLFile. Invalid measurement type: " << oaMeas.type_;
395  }
396 
397  oaMeas.values_.emplace_back(oaParam);
398  oaMeas.isSimulatedValue_.emplace_back(measIsSimulatedValue[oaMeas.name_][i2]);
399  if (ALIUtils::debug >= 5) {
400  edm::LogInfo("Alignment") << oaMeas.name_ << " copying issimu "
401  << oaMeas.isSimulatedValue_[oaMeas.isSimulatedValue_.size() - 1] << " = "
402  << measIsSimulatedValue[oaMeas.name_][i2];
403  }
404  oaParam.clear();
405  }
406  } else {
407  if (ALIUtils::debug >= 2) {
408  edm::LogWarning("Alignment") << "WARNING FOR NOW: sizes of measurement parameters (name, value, sigma) do"
409  << " not match! for measurement " << oaMeas.name_
410  << " !Did not fill parameters for this measurement ";
411  }
412  }
413  measList_.oaMeasurements_.emplace_back(oaMeas);
414  if (ALIUtils::debug >= 5) {
415  edm::LogInfo("Alignment") << "CocoaAnalyser: MEASUREMENT " << oaMeas.name_ << " extra entries read "
416  << oaMeas;
417  }
418  oaMeas.clear();
419  }
420 
421  } else {
422  if (ALIUtils::debug >= 2) {
423  edm::LogWarning("Alignment") << "WARNING FOR NOW: sizes of measurements (names, types do"
424  << " not match! Did not add " << nObjects << " item to XXXMeasurements";
425  }
426  }
427 
428  oaInfo.clear();
429  doCOCOA = myFilteredView.firstChild();
430  } // while (doCOCOA)
431 
432  if (ALIUtils::debug >= 3) {
433  edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML: Finished building " << nObjects + 1
434  << " OpticalAlignInfo objects"
435  << " and " << measList_.oaMeasurements_.size()
436  << " OpticalAlignMeasurementInfo objects ";
437  }
438  if (ALIUtils::debug >= 5) {
439  edm::LogInfo("Alignment") << " @@@@@@ OpticalAlignments " << oaList_;
440  edm::LogInfo("Alignment") << " @@@@@@ OpticalMeasurements " << measList_;
441  }
442  }
443 }
std::string parentName_
OpticalAlignParam x_
dd4hep::SpecParRefs DDSpecParRefs
Definition: DDCompactView.h:29
static std::vector< double > getRotationAnglesFromMatrix(const CLHEP::HepRotation &rmLocal, double origAngleX, double origAngleY, double origAngleZ)
Definition: ALIUtils.cc:549
std::vector< std::string > measObjectNames_
const cms::DDDetector * detector() const
Definition: DDCompactView.h:34
static ALIint debug
Definition: ALIUtils.h:34
DDSpecParRegistry const & specpars() const
Definition: DDCompactView.h:35
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > ddcvToken
Log< level::Error, false > LogError
const std::string names[nVars_]
dd4hep::SpecParRegistry DDSpecParRegistry
Definition: DDCompactView.h:28
string quality
OpticalAlignParam angx_
OpticalAlignParam y_
std::vector< OpticalAlignInfo > opticalAlignments_
dd4hep::PlacedVolume PlacedVolume
std::vector< OpticalAlignMeasurementInfo > oaMeasurements_
dd4hep::Volume Volume
OpticalAlignParam angz_
Log< level::Info, false > LogInfo
OpticalAlignParam z_
dd4hep::Volume worldVolume() const
Handle to the world volume containing everything.
Definition: DDDetector.cc:67
std::vector< OpticalAlignParam > extraEntries_
OpticalAlignMeasurements measList_
OpticalAlignParam angy_
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:141
std::vector< OpticalAlignParam > values_
Definition: errors.py:1
Log< level::Warning, false > LogWarning
std::string dim_type_
OpticalAlignments oaList_
unsigned int ID_

◆ runCocoa()

void CocoaAnalyzer::runCocoa ( )
private

Definition at line 565 of file CocoaAnalyzer.cc.

References ALIUtils::debug, ALIFileOut::getInstance(), Fit::getInstance(), Model::getInstance(), measList_, ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi::model, oaList_, ALIUtils::report, Model::ReportFName(), and Fit::startFit().

Referenced by analyze().

565  {
566  if (ALIUtils::debug >= 3) {
567  edm::LogInfo("Alignment") << "$$$ CocoaAnalyzer::runCocoa: ";
568  }
569 
570  // Geometry model built from XML file (corrected with values from DB)
572  model.BuildSystemDescriptionFromOA(oaList_);
573 
574  if (ALIUtils::debug >= 3) {
575  edm::LogInfo("Alignment") << "$$ CocoaAnalyzer::runCocoa: geometry built ";
576  }
577 
578  // Build measurements
579  model.BuildMeasurementsFromOA(measList_);
580 
581  if (ALIUtils::debug >= 3) {
582  edm::LogInfo("Alignment") << "$$ CocoaAnalyzer::runCocoa: measurements built ";
583  }
584 
585  // Do fit and store results in DB
587  Fit::startFit();
588 
589  if (ALIUtils::debug >= 0)
590  edm::LogInfo("Alignment") << "............ program ended OK";
591  if (ALIUtils::report >= 1) {
593  fileout << "............ program ended OK";
594  }
595 }
static ALIint debug
Definition: ALIUtils.h:34
static ALIstring & ReportFName()
the name of the report File
Definition: Model.h:99
static Fit & getInstance()
Definition: Fit.cc:69
static Model & getInstance()
-------— Gets the only instance of this class
Definition: Model.cc:80
Definition: Model.h:54
Log< level::Info, false > LogInfo
static void startFit()
Definition: Fit.cc:103
static ALIint report
Definition: ALIUtils.h:33
OpticalAlignMeasurements measList_
static ALIFileOut & getInstance(const ALIstring &filename)
Definition: ALIFileOut.cc:18
OpticalAlignments oaList_

Member Data Documentation

◆ ddcvToken

edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> CocoaAnalyzer::ddcvToken
private

Definition at line 49 of file CocoaAnalyzer.cc.

Referenced by readXMLFile().

◆ measList_

OpticalAlignMeasurements CocoaAnalyzer::measList_
private

Definition at line 51 of file CocoaAnalyzer.cc.

Referenced by readXMLFile(), and runCocoa().

◆ oaList_

OpticalAlignments CocoaAnalyzer::oaList_
private

Definition at line 50 of file CocoaAnalyzer.cc.

Referenced by correctAllOpticalAlignments(), readXMLFile(), and runCocoa().

◆ optAliToken

edm::ESGetToken<OpticalAlignments, OpticalAlignmentsRcd> CocoaAnalyzer::optAliToken
private

Definition at line 48 of file CocoaAnalyzer.cc.

Referenced by readCalibrationDB().

◆ theCocoaDaqRootFileName_

std::string CocoaAnalyzer::theCocoaDaqRootFileName_
private

Definition at line 52 of file CocoaAnalyzer.cc.

Referenced by CocoaAnalyzer().