Skip to content

Commit

Permalink
Merge pull request #30507 from ghugo83/cocoa_to_dd4hep
Browse files Browse the repository at this point in the history
Port COCOA to rely on DD4hep
  • Loading branch information
cmsbuild committed Jul 8, 2020
2 parents 61d0273 + 7af821c commit d7f103c
Show file tree
Hide file tree
Showing 13 changed files with 1,194 additions and 387 deletions.
7 changes: 7 additions & 0 deletions Alignment/CocoaApplication/BuildFile.xml
@@ -0,0 +1,7 @@
<use name="clhep"/>
<use name="root"/>
<use name="dd4hep"/>
<use name="Alignment/CocoaFit"/>
<use name="CondCore/DBOutputService"/>
<use name="DetectorDescription/DDCMS"/>
<flags EDM_PLUGIN="1"/>
47 changes: 47 additions & 0 deletions Alignment/CocoaApplication/README.md
@@ -0,0 +1,47 @@
# **CMS Object-oriented Code for Optical Alignment**


## General COCOA documentation

General documentation is at [1].
COCOA website is at [2].
Notably, a user guide can be found at [3].

[1] https://cds.cern.ch/record/1047121/files/p193.pdf
[2] http://cmsdoc.cern.ch/cms/MUON/alignment/software/COCOA/doc/cocoa.html
[3] http://cmsdoc.cern.ch/cms/MUON/alignment/software/COCOA/doc/tex/users_guide.ps



## Run COCOA
This shows how to:
- Run the COCOA simulation of an optical alignment system (described in .txt or XML format, with adjustments from DB description);
- Run the least-squared fit on the alignment system;
- Store results back into DB.

### Input XML file
An XML file describing the optical alignment system of interest needs to be provided as input to COCOA.

Such an XML file can be generated from a .txt description, by an independent cocoa application in `Alignment/CocoaApplication/bin`.
For example, one can generate an XML optical alignment system description, by simply doing the following:

cd Alignment/CocoaApplication/bin
cocoa simple2D.txt

### Input DB OpticalAlignmentsRcd
For testing purposes, an example input DB `OpticalAlignmentsRcd` can now be found at `Alignment/CocoaApplication/test/OpticalAlignments.db`.
It was generated by adding the following, in `CocoaAnalyzer::analyze`, after `readXMLFile` returns:

Model& model = Model::getInstance();
model.BuildSystemDescriptionFromOA(oaList_);
CocoaDBMgr::getInstance()->DumpCocoaResults();
Of course, in practice, one would actually just need to call the OpticalAlignmentsRcd of interest to the desired alignment study.

### Run COCOA
One can now just do:

cd Alignment/CocoaApplication/test
cmsRun cocoaAnalyzer_cfg.py
This will perform the least-squared fit, and store all results in `Alignment/CocoaApplication/test/OpticalAlignments.db`.
The `OpticalAlignmentsRcd` obtained after fit, is stored with `OpticalAlignmentsRcdOutput` tag.
It should also be possible to use the feature of dumping the results into ROOT format.
43 changes: 43 additions & 0 deletions Alignment/CocoaApplication/interface/CocoaAnalyzer.h
@@ -0,0 +1,43 @@
#ifndef ALIGNMENT_COCOA_APPLICATION_COCOA_ANALYZER_H
#define ALIGNMENT_COCOA_APPLICATION_COCOA_ANALYZER_H

#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h"
#include "CondFormats/OptAlignObjects/interface/OpticalAlignments.h"
#include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurements.h"

class CocoaAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit CocoaAnalyzer(edm::ParameterSet const& p);
explicit CocoaAnalyzer(int i) {}
~CocoaAnalyzer() override {}

void beginJob() override;
void analyze(const edm::Event& e, const edm::EventSetup& c) override;

private:
void readXMLFile(const edm::EventSetup& evts);

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

void runCocoa();

template <typename T>
std::vector<T> getAllParameterValuesFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections,
const std::string& nodePath,
const std::string& parameterName);
template <typename T>
T getParameterValueFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections,
const std::string& nodePath,
const std::string& parameterName,
const unsigned int parameterValueIndex);

private:
OpticalAlignments oaList_;
OpticalAlignMeasurements measList_;
std::string theCocoaDaqRootFileName_;
};

#endif

0 comments on commit d7f103c

Please sign in to comment.