CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
MuonAlignmentFromReference Class Reference

#include <Alignment/MuonAlignmentFromReference/interface/MuonAlignmentFromReference.h>

Inheritance diagram for MuonAlignmentFromReference:
AlignmentAlgorithmBase

Public Member Functions

void initialize (const edm::EventSetup &iSetup, AlignableTracker *alignableTracker, AlignableMuon *alignableMuon, AlignableExtras *extras, AlignmentParameterStore *alignmentParameterStore) override
 Call at beginning of job (must be implemented in derived class) More...
 
 MuonAlignmentFromReference (const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
 
void processMuonResidualsFromTrack (MuonResidualsFromTrack &mrft)
 
void run (const edm::EventSetup &iSetup, const EventInfo &eventInfo) override
 Run the algorithm (must be implemented in derived class) More...
 
void startNewLoop () override
 
void terminate (const edm::EventSetup &iSetup) override
 Call at end of each loop (must be implemented in derived class) More...
 
 ~MuonAlignmentFromReference () override
 
- Public Member Functions inherited from AlignmentAlgorithmBase
virtual bool addCalibrations (const Calibrations &)
 
bool addCalibrations (const CalibrationsOwner &cals)
 
 AlignmentAlgorithmBase (const edm::ParameterSet &, const edm::ConsumesCollector &)
 Constructor. More...
 
virtual void beginLuminosityBlock (const edm::EventSetup &setup)
 called at begin of luminosity block (no lumi block info passed yet) More...
 
virtual void beginRun (const edm::Run &, const edm::EventSetup &, bool changed)
 called at begin of run More...
 
virtual void endLuminosityBlock (const edm::EventSetup &setup)
 called at end of luminosity block (no lumi block info passed yet) More...
 
virtual void endRun (const EndRunInfo &runInfo, const edm::EventSetup &setup)
 called at end of run - order of arguments like in EDProducer etc. More...
 
virtual bool processesEvents ()
 Returns whether algorithm proccesses events in current configuration. More...
 
virtual bool setParametersForRunRange (const RunRange &rr)
 
virtual bool storeAlignments ()
 Returns whether algorithm produced results to be stored. More...
 
virtual bool supportsCalibrations ()
 
virtual void terminate ()
 Called at end of job (must be implemented in derived class) More...
 
virtual ~AlignmentAlgorithmBase ()
 Destructor. More...
 

Private Member Functions

void bookNtuple ()
 
std::string chamberPrettyNameFromId (unsigned int idx)
 
void correctBField ()
 
void eraseNotSelectedResiduals ()
 
void fiducialCuts ()
 
void fillNtuple ()
 
void fitAndAlign ()
 
int number (std::string s)
 
bool numeric (std::string s)
 
void parseReference (align::Alignables &reference, const align::Alignables &all_DT_chambers, const align::Alignables &all_CSC_chambers)
 
void readTmpFiles ()
 
void selectResidualsPeaks ()
 
void writeTmpFiles ()
 

Private Attributes

AlignableNavigatorm_alignableNavigator
 
align::Alignables m_alignables
 
AlignmentParameterStorem_alignmentParameterStore
 
bool m_allowTIDTEC
 
int m_BFieldCorrection
 
const MuonResidualsFromTrack::BuilderToken m_builderToken
 
bool m_combineME11
 
long m_counter_csc
 
long m_counter_cscaligning
 
long m_counter_cschits
 
long m_counter_cscvalid
 
long m_counter_events
 
long m_counter_minchambers
 
long m_counter_resslopey
 
long m_counter_station123
 
long m_counter_station123aligning
 
long m_counter_station123dt13hits
 
long m_counter_station123dt2hits
 
long m_counter_station123valid
 
long m_counter_station4
 
long m_counter_station4aligning
 
long m_counter_station4hits
 
long m_counter_station4valid
 
long m_counter_totchambers
 
long m_counter_trackdxy
 
long m_counter_trackerchi2
 
long m_counter_trackerhits
 
long m_counter_trackertidtec
 
long m_counter_trackmomentum
 
long m_counter_tracks
 
bool m_createNtuple
 
const edm::ESGetToken< CSCGeometry, MuonGeometryRecordm_cscGeometryToken
 
bool m_debug
 
const edm::ESGetToken< DetIdAssociator, DetIdAssociatorRecordm_DetIdToken
 
bool m_doAlignment
 
bool m_doCSC
 
bool m_doDT
 
std::map< unsigned int, MuonResidualsTwoBin * > m_fitterOrder
 
std::map< Alignable *, MuonResidualsTwoBin * > m_fitters
 
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecordm_globTackingToken
 
std::vector< unsigned int > m_indexes
 
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecordm_MagFieldToken
 
double m_maxDxy
 
double m_maxResSlopeY
 
double m_maxTrackerRedChi2
 
double m_maxTrackP
 
double m_maxTrackPt
 
std::map< Alignable *, Alignable * > m_me11map
 
int m_minAlignmentHits
 
int m_minCSCHits
 
int m_minDT13Hits
 
int m_minDT2Hits
 
int m_minNCrossedChambers
 
int m_minTrackerHits
 
double m_minTrackP
 
double m_minTrackPt
 
edm::InputTag m_muonCollectionTag
 
double m_peakNSigma
 
const edm::ESGetToken< Propagator, TrackingComponentsRecordm_propToken
 
std::vector< std::string > m_readTemporaryFiles
 
std::vector< std::string > m_reference
 
std::string m_reportFileName
 
std::string m_residualsModel
 
int m_strategy
 
MuonResidualsFitter::MuonAlignmentTreeRow m_tree_row
 
TTree * m_ttree
 
bool m_twoBin
 
std::string m_useResiduals
 
bool m_weightAlignment
 
std::string m_writeTemporaryFile
 

Additional Inherited Members

- Public Types inherited from AlignmentAlgorithmBase
typedef std::pair< const Trajectory *, const reco::Track * > ConstTrajTrackPair
 
typedef std::vector< ConstTrajTrackPairConstTrajTrackPairCollection
 
using RunNumber = align::RunNumber
 
using RunRange = align::RunRange
 

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 74 of file MuonAlignmentFromReference.cc.

Constructor & Destructor Documentation

◆ MuonAlignmentFromReference()

MuonAlignmentFromReference::MuonAlignmentFromReference ( const edm::ParameterSet cfg,
edm::ConsumesCollector iC 
)

Definition at line 196 of file MuonAlignmentFromReference.cc.

References bookNtuple(), compareTotals::fs, m_counter_csc, m_counter_cscaligning, m_counter_cschits, m_counter_cscvalid, m_counter_events, m_counter_minchambers, m_counter_resslopey, m_counter_station123, m_counter_station123aligning, m_counter_station123dt13hits, m_counter_station123dt2hits, m_counter_station123valid, m_counter_station4, m_counter_station4aligning, m_counter_station4hits, m_counter_station4valid, m_counter_totchambers, m_counter_trackdxy, m_counter_trackerchi2, m_counter_trackerhits, m_counter_trackertidtec, m_counter_trackmomentum, m_counter_tracks, m_createNtuple, m_debug, m_doAlignment, and m_ttree.

201  m_propToken(iC.esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))),
202  m_DetIdToken(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))),
204  m_muonCollectionTag(cfg.getParameter<edm::InputTag>("muonCollectionTag")),
205  m_reference(cfg.getParameter<std::vector<std::string> >("reference")),
206  m_minTrackPt(cfg.getParameter<double>("minTrackPt")),
207  m_maxTrackPt(cfg.getParameter<double>("maxTrackPt")),
208  m_minTrackP(cfg.getParameter<double>("minTrackP")),
209  m_maxTrackP(cfg.getParameter<double>("maxTrackP")),
210  m_maxDxy(cfg.getParameter<double>("maxDxy")),
211  m_minTrackerHits(cfg.getParameter<int>("minTrackerHits")),
212  m_maxTrackerRedChi2(cfg.getParameter<double>("maxTrackerRedChi2")),
213  m_allowTIDTEC(cfg.getParameter<bool>("allowTIDTEC")),
214  m_minNCrossedChambers(cfg.getParameter<int>("minNCrossedChambers")),
215  m_minDT13Hits(cfg.getParameter<int>("minDT13Hits")),
216  m_minDT2Hits(cfg.getParameter<int>("minDT2Hits")),
217  m_minCSCHits(cfg.getParameter<int>("minCSCHits")),
218  m_writeTemporaryFile(cfg.getParameter<std::string>("writeTemporaryFile")),
219  m_readTemporaryFiles(cfg.getParameter<std::vector<std::string> >("readTemporaryFiles")),
220  m_doAlignment(cfg.getParameter<bool>("doAlignment")),
221  m_strategy(cfg.getParameter<int>("strategy")),
222  m_residualsModel(cfg.getParameter<std::string>("residualsModel")),
223  m_minAlignmentHits(cfg.getParameter<int>("minAlignmentHits")),
224  m_twoBin(cfg.getParameter<bool>("twoBin")),
225  m_combineME11(cfg.getParameter<bool>("combineME11")),
226  m_weightAlignment(cfg.getParameter<bool>("weightAlignment")),
227  m_reportFileName(cfg.getParameter<std::string>("reportFileName")),
228  m_maxResSlopeY(cfg.getParameter<double>("maxResSlopeY")),
229  m_createNtuple(cfg.getParameter<bool>("createNtuple")),
230  m_peakNSigma(cfg.getParameter<double>("peakNSigma")),
231  m_BFieldCorrection(cfg.getParameter<int>("bFieldCorrection")),
232  m_doDT(cfg.getParameter<bool>("doDT")),
233  m_doCSC(cfg.getParameter<bool>("doCSC")),
234  m_useResiduals(cfg.getParameter<std::string>("useResiduals")) {
235  // alignment requires a TFile to provide plots to check the fit output
236  // just filling the residuals lists does not
237  // but we don't want to wait until the end of the job to find out that the TFile is missing
238  if (m_doAlignment || m_createNtuple) {
240  TFile& tfile = fs->file();
241  tfile.ls();
242  }
243 
244  m_ttree = nullptr;
245  if (m_createNtuple)
246  bookNtuple();
247 
248  m_counter_events = 0;
249  m_counter_tracks = 0;
251  m_counter_trackdxy = 0;
262  m_counter_station4 = 0;
266  m_counter_csc = 0;
267  m_counter_cscvalid = 0;
268  m_counter_cschits = 0;
271 
272  m_debug = false;
273 }
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > m_MagFieldToken
const edm::ESGetToken< DetIdAssociator, DetIdAssociatorRecord > m_DetIdToken
static edm::ESInputTag builderESInputTag()
const MuonResidualsFromTrack::BuilderToken m_builderToken
Definition: tfile.py:1
const edm::ESGetToken< Propagator, TrackingComponentsRecord > m_propToken
const edm::ESGetToken< CSCGeometry, MuonGeometryRecord > m_cscGeometryToken
AlignmentAlgorithmBase(const edm::ParameterSet &, const edm::ConsumesCollector &)
Constructor.
std::vector< std::string > m_reference
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > m_globTackingToken
std::vector< std::string > m_readTemporaryFiles

◆ ~MuonAlignmentFromReference()

MuonAlignmentFromReference::~MuonAlignmentFromReference ( )
override

Definition at line 275 of file MuonAlignmentFromReference.cc.

References m_alignableNavigator.

275 { delete m_alignableNavigator; }

Member Function Documentation

◆ bookNtuple()

void MuonAlignmentFromReference::bookNtuple ( )
private

Definition at line 277 of file MuonAlignmentFromReference.cc.

References MuonResidualsFitter::MuonAlignmentTreeRow::angle_x, MuonResidualsFitter::MuonAlignmentTreeRow::angle_y, compareTotals::fs, MuonResidualsFitter::MuonAlignmentTreeRow::is_dt, MuonResidualsFitter::MuonAlignmentTreeRow::is_plus, m_tree_row, m_ttree, MuonResidualsFitter::MuonAlignmentTreeRow::pos_x, MuonResidualsFitter::MuonAlignmentTreeRow::pos_y, MuonResidualsFitter::MuonAlignmentTreeRow::pt, MuonResidualsFitter::MuonAlignmentTreeRow::pz, MuonResidualsFitter::MuonAlignmentTreeRow::q, MuonResidualsFitter::MuonAlignmentTreeRow::res_slope_x, MuonResidualsFitter::MuonAlignmentTreeRow::res_slope_y, MuonResidualsFitter::MuonAlignmentTreeRow::res_x, MuonResidualsFitter::MuonAlignmentTreeRow::res_y, MuonResidualsFitter::MuonAlignmentTreeRow::ring_wheel, MuonResidualsFitter::MuonAlignmentTreeRow::sector, MuonResidualsFitter::MuonAlignmentTreeRow::select, and MuonResidualsFitter::MuonAlignmentTreeRow::station.

Referenced by MuonAlignmentFromReference().

277  {
279  m_ttree = fs->make<TTree>("mual_ttree", "mual_ttree");
280  m_ttree->Branch("is_plus", &m_tree_row.is_plus, "is_plus/O");
281  m_ttree->Branch("is_dt", &m_tree_row.is_dt, "is_dt/O");
282  m_ttree->Branch("station", &m_tree_row.station, "station/b");
283  m_ttree->Branch("ring_wheel", &m_tree_row.ring_wheel, "ring_wheel/B");
284  m_ttree->Branch("sector", &m_tree_row.sector, "sector/b");
285  m_ttree->Branch("res_x", &m_tree_row.res_x, "res_x/F");
286  m_ttree->Branch("res_y", &m_tree_row.res_y, "res_y/F");
287  m_ttree->Branch("res_slope_x", &m_tree_row.res_slope_x, "res_slope_x/F");
288  m_ttree->Branch("res_slope_y", &m_tree_row.res_slope_y, "res_slope_y/F");
289  m_ttree->Branch("pos_x", &m_tree_row.pos_x, "pos_x/F");
290  m_ttree->Branch("pos_y", &m_tree_row.pos_y, "pos_y/F");
291  m_ttree->Branch("angle_x", &m_tree_row.angle_x, "angle_x/F");
292  m_ttree->Branch("angle_y", &m_tree_row.angle_y, "angle_y/F");
293  m_ttree->Branch("pz", &m_tree_row.pz, "pz/F");
294  m_ttree->Branch("pt", &m_tree_row.pt, "pt/F");
295  m_ttree->Branch("q", &m_tree_row.q, "q/B");
296  m_ttree->Branch("select", &m_tree_row.select, "select/O");
297  //m_ttree->Branch("",&m_tree_row.,"/");
298 }
MuonResidualsFitter::MuonAlignmentTreeRow m_tree_row

◆ chamberPrettyNameFromId()

std::string MuonAlignmentFromReference::chamberPrettyNameFromId ( unsigned int  idx)
private

Definition at line 1756 of file MuonAlignmentFromReference.cc.

References CSCDetId::chamber(), MuonSubdetId::CSC, MuonSubdetId::DT, CSCDetId::endcap(), l1ctLayer2EG_cff::id, heavyIonCSV_trainingSettings::idx, CSCDetId::ring(), DTChamberId::sector(), DTChamberId::station(), CSCDetId::station(), AlCaHLTBitMon_QueryRunRegistry::string, and DTChamberId::wheel().

Referenced by correctBField(), eraseNotSelectedResiduals(), fiducialCuts(), and selectResidualsPeaks().

1756  {
1757  DetId id(idx);
1758  char cname[40];
1759  if (id.subdetId() == MuonSubdetId::DT) {
1760  DTChamberId chamberId(id.rawId());
1761  sprintf(cname, "MB%+d/%d/%02d", chamberId.wheel(), chamberId.station(), chamberId.sector());
1762  } else if (id.subdetId() == MuonSubdetId::CSC) {
1763  CSCDetId chamberId(id.rawId());
1764  sprintf(cname,
1765  "ME%s%d/%d/%02d",
1766  (chamberId.endcap() == 1 ? "+" : "-"),
1767  chamberId.station(),
1768  chamberId.ring(),
1769  chamberId.chamber());
1770  }
1771  return std::string(cname);
1772 }
Definition: DetId.h:17
static constexpr int DT
Definition: MuonSubdetId.h:11
static constexpr int CSC
Definition: MuonSubdetId.h:12

◆ correctBField()

void MuonAlignmentFromReference::correctBField ( )
private

Definition at line 1658 of file MuonAlignmentFromReference.cc.

References chamberPrettyNameFromId(), MuonResidualsTwoBin::correctBField(), gather_cfg::cout, m_debug, m_fitterOrder, and m_indexes.

Referenced by terminate().

1658  {
1659  bool m_debug = false;
1660 
1661  for (std::vector<unsigned int>::const_iterator index = m_indexes.begin(); index != m_indexes.end(); ++index) {
1662  if (m_debug)
1663  std::cout << "correcting B in " << chamberPrettyNameFromId(*index) << std::endl;
1665  fitter->correctBField();
1666  }
1667 }
std::vector< unsigned int > m_indexes
std::string chamberPrettyNameFromId(unsigned int idx)
std::map< unsigned int, MuonResidualsTwoBin * > m_fitterOrder

◆ eraseNotSelectedResiduals()

void MuonAlignmentFromReference::eraseNotSelectedResiduals ( )
private

Definition at line 1678 of file MuonAlignmentFromReference.cc.

References chamberPrettyNameFromId(), gather_cfg::cout, MuonResidualsTwoBin::eraseNotSelectedResiduals(), m_debug, m_fitterOrder, and m_indexes.

Referenced by terminate().

1678  {
1679  for (std::vector<unsigned int>::const_iterator index = m_indexes.begin(); index != m_indexes.end(); ++index) {
1680  if (m_debug)
1681  std::cout << "erasing in " << chamberPrettyNameFromId(*index) << std::endl;
1683  fitter->eraseNotSelectedResiduals();
1684  }
1685 }
std::vector< unsigned int > m_indexes
std::string chamberPrettyNameFromId(unsigned int idx)
std::map< unsigned int, MuonResidualsTwoBin * > m_fitterOrder

◆ fiducialCuts()

void MuonAlignmentFromReference::fiducialCuts ( )
private

Definition at line 1669 of file MuonAlignmentFromReference.cc.

References chamberPrettyNameFromId(), gather_cfg::cout, MuonResidualsTwoBin::fiducialCuts(), m_debug, m_fitterOrder, and m_indexes.

Referenced by terminate().

1669  {
1670  for (std::vector<unsigned int>::const_iterator index = m_indexes.begin(); index != m_indexes.end(); ++index) {
1671  if (m_debug)
1672  std::cout << "applying fiducial cuts in " << chamberPrettyNameFromId(*index) << std::endl;
1674  fitter->fiducialCuts();
1675  }
1676 }
std::vector< unsigned int > m_indexes
std::string chamberPrettyNameFromId(unsigned int idx)
std::map< unsigned int, MuonResidualsTwoBin * > m_fitterOrder

◆ fillNtuple()

void MuonAlignmentFromReference::fillNtuple ( )
private

Definition at line 1774 of file MuonAlignmentFromReference.cc.

References MuonResidualsFitter::MuonAlignmentTreeRow::angle_x, MuonResidualsFitter::MuonAlignmentTreeRow::angle_y, cms::cuda::assert(), relativeConstraints::chamber, MuonSubdetId::CSC, DetId::det(), MuonSubdetId::DT, makeMuonMisalignmentScenario::endcap, l1ctLayer2EG_cff::id, MuonResidualsFitter::MuonAlignmentTreeRow::is_dt, MuonResidualsFitter::MuonAlignmentTreeRow::is_plus, MuonResidualsFitter::k5DOF, MuonResidualsFitter::k6DOF, MuonResidualsFitter::k6DOFrphi, MuonResiduals5DOFFitter::kAngleX, MuonResiduals6DOFFitter::kAngleX, MuonResiduals5DOFFitter::kAngleY, MuonResiduals6DOFFitter::kAngleY, MuonResiduals5DOFFitter::kCharge, MuonResiduals6DOFFitter::kCharge, MuonResiduals5DOFFitter::kPositionX, MuonResiduals6DOFFitter::kPositionX, MuonResiduals5DOFFitter::kPositionY, MuonResiduals6DOFFitter::kPositionY, MuonResiduals5DOFFitter::kPt, MuonResiduals6DOFFitter::kPt, MuonResiduals5DOFFitter::kPz, MuonResiduals6DOFFitter::kPz, MuonResiduals5DOFFitter::kResid, MuonResiduals6DOFFitter::kResidX, MuonResiduals6DOFFitter::kResidY, MuonResiduals5DOFFitter::kResSlope, MuonResiduals6DOFFitter::kResSlopeX, MuonResiduals6DOFFitter::kResSlopeY, m_fitterOrder, m_indexes, m_tree_row, m_ttree, DetId::Muon, MuonResidualsFitter::MuonAlignmentTreeRow::pos_x, MuonResidualsFitter::MuonAlignmentTreeRow::pos_y, MuonResidualsFitter::MuonAlignmentTreeRow::pt, MuonResidualsFitter::MuonAlignmentTreeRow::pz, MuonResidualsFitter::MuonAlignmentTreeRow::q, MuonResidualsFitter::MuonAlignmentTreeRow::res_slope_x, MuonResidualsFitter::MuonAlignmentTreeRow::res_slope_y, MuonResidualsFitter::MuonAlignmentTreeRow::res_x, MuonResidualsFitter::MuonAlignmentTreeRow::res_y, MuonResidualsTwoBin::residualsPos_begin(), MuonResidualsTwoBin::residualsPos_end(), MuonResidualsTwoBin::residualsPos_ok_begin(), relativeConstraints::ring, MuonResidualsFitter::MuonAlignmentTreeRow::ring_wheel, hgcalTBTopologyTester_cfi::sector, MuonResidualsFitter::MuonAlignmentTreeRow::sector, MuonResidualsFitter::MuonAlignmentTreeRow::select, relativeConstraints::station, MuonResidualsFitter::MuonAlignmentTreeRow::station, DetId::subdetId(), MuonResidualsTwoBin::type(), and makeMuonMisalignmentScenario::wheel.

Referenced by terminate().

1774  {
1775  // WARNING: does not support two bin option!!!
1776 
1777  for (std::vector<unsigned int>::const_iterator index = m_indexes.begin(); index != m_indexes.end(); ++index) {
1778  DetId detid(*index);
1779  if (detid.det() != DetId::Muon || !(detid.subdetId() == MuonSubdetId::DT || detid.subdetId() == MuonSubdetId::CSC))
1780  assert(false);
1781 
1782  if (detid.subdetId() == MuonSubdetId::DT) {
1783  m_tree_row.is_dt = (Bool_t) true;
1784  DTChamberId id(*index);
1785  m_tree_row.is_plus = (Bool_t) true;
1786  m_tree_row.station = (UChar_t)id.station();
1787  m_tree_row.ring_wheel = (Char_t)id.wheel();
1788  m_tree_row.sector = (UChar_t)id.sector();
1789  } else {
1790  m_tree_row.is_dt = (Bool_t) false;
1791  CSCDetId id(*index);
1792  m_tree_row.is_plus = (Bool_t)(id.endcap() == 1);
1793  m_tree_row.station = (UChar_t)id.station();
1794  m_tree_row.ring_wheel = (Char_t)id.ring();
1795  m_tree_row.sector = (UChar_t)id.chamber();
1796  }
1797 
1799 
1800  std::vector<double*>::const_iterator residual = fitter->residualsPos_begin();
1801  std::vector<bool>::const_iterator residual_ok = fitter->residualsPos_ok_begin();
1802  for (; residual != fitter->residualsPos_end(); ++residual, ++residual_ok) {
1803  if (fitter->type() == MuonResidualsFitter::k5DOF || fitter->type() == MuonResidualsFitter::k6DOFrphi) {
1804  m_tree_row.res_x = (Float_t)(*residual)[MuonResiduals5DOFFitter::kResid];
1805  m_tree_row.res_y = (Float_t)0.;
1807  m_tree_row.res_slope_y = (Float_t)0.;
1808  m_tree_row.pos_x = (Float_t)(*residual)[MuonResiduals5DOFFitter::kPositionX];
1809  m_tree_row.pos_y = (Float_t)(*residual)[MuonResiduals5DOFFitter::kPositionY];
1810  m_tree_row.angle_x = (Float_t)(*residual)[MuonResiduals5DOFFitter::kAngleX];
1811  m_tree_row.angle_y = (Float_t)(*residual)[MuonResiduals5DOFFitter::kAngleY];
1812  m_tree_row.pz = (Float_t)(*residual)[MuonResiduals5DOFFitter::kPz];
1813  m_tree_row.pt = (Float_t)(*residual)[MuonResiduals5DOFFitter::kPt];
1814  m_tree_row.q = (Char_t)(*residual)[MuonResiduals5DOFFitter::kCharge];
1815  m_tree_row.select = (Bool_t)*residual_ok;
1816  } else if (fitter->type() == MuonResidualsFitter::k6DOF) {
1817  m_tree_row.res_x = (Float_t)(*residual)[MuonResiduals6DOFFitter::kResidX];
1818  m_tree_row.res_y = (Float_t)(*residual)[MuonResiduals6DOFFitter::kResidY];
1821  m_tree_row.pos_x = (Float_t)(*residual)[MuonResiduals6DOFFitter::kPositionX];
1822  m_tree_row.pos_y = (Float_t)(*residual)[MuonResiduals6DOFFitter::kPositionY];
1823  m_tree_row.angle_x = (Float_t)(*residual)[MuonResiduals6DOFFitter::kAngleX];
1824  m_tree_row.angle_y = (Float_t)(*residual)[MuonResiduals6DOFFitter::kAngleY];
1825  m_tree_row.pz = (Float_t)(*residual)[MuonResiduals6DOFFitter::kPz];
1826  m_tree_row.pt = (Float_t)(*residual)[MuonResiduals6DOFFitter::kPt];
1827  m_tree_row.q = (Char_t)(*residual)[MuonResiduals6DOFFitter::kCharge];
1828  m_tree_row.select = (Bool_t)*residual_ok;
1829  } else
1830  assert(false);
1831 
1832  m_ttree->Fill();
1833  }
1834  }
1835 }
std::vector< bool >::const_iterator residualsPos_ok_begin() const
assert(be >=bs)
MuonResidualsFitter::MuonAlignmentTreeRow m_tree_row
std::vector< unsigned int > m_indexes
std::map< unsigned int, MuonResidualsTwoBin * > m_fitterOrder
Definition: DetId.h:17
std::vector< double * >::const_iterator residualsPos_begin() const
std::vector< double * >::const_iterator residualsPos_end() const
static constexpr int DT
Definition: MuonSubdetId.h:11
static constexpr int CSC
Definition: MuonSubdetId.h:12

◆ fitAndAlign()

void MuonAlignmentFromReference::fitAndAlign ( )
private

Definition at line 835 of file MuonAlignmentFromReference.cc.

References AlignmentParameterStore::applyParameters(), cms::cuda::assert(), CSCDetId::chamber(), AlignmentParameters::cloneFromSelected(), gather_cfg::cout, MuonSubdetId::CSC, MuonSubdetId::DT, CSCDetId::endcap(), mps_fire::i, MuonResidualsFitter::k5DOF, MuonResidualsFitter::k6DOF, MuonResidualsFitter::k6DOFrphi, MuonResiduals5DOFFitter::kAlignPhiX, MuonResiduals6DOFFitter::kAlignPhiX, MuonResiduals6DOFrphiFitter::kAlignPhiX, MuonResiduals5DOFFitter::kAlignPhiY, MuonResiduals6DOFFitter::kAlignPhiY, MuonResiduals6DOFrphiFitter::kAlignPhiY, MuonResiduals5DOFFitter::kAlignPhiZ, MuonResiduals6DOFFitter::kAlignPhiZ, MuonResiduals6DOFrphiFitter::kAlignPhiZ, MuonResiduals5DOFFitter::kAlignX, MuonResiduals6DOFFitter::kAlignX, MuonResiduals6DOFrphiFitter::kAlignX, MuonResiduals6DOFFitter::kAlignY, MuonResiduals6DOFrphiFitter::kAlignY, MuonResiduals5DOFFitter::kAlignZ, MuonResiduals6DOFFitter::kAlignZ, MuonResiduals6DOFrphiFitter::kAlignZ, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPureGaussian, MuonResidualsFitter::kPureGaussian2D, MuonResiduals6DOFrphiFitter::kRedChi2, MuonResiduals5DOFFitter::kRedChi2, MuonResiduals6DOFFitter::kRedChi2, MuonResiduals5DOFFitter::kResid, MuonResiduals6DOFrphiFitter::kResid, MuonResiduals5DOFFitter::kResidGamma, MuonResiduals6DOFrphiFitter::kResidGamma, MuonResiduals5DOFFitter::kResidSigma, MuonResiduals6DOFrphiFitter::kResidSigma, MuonResiduals6DOFFitter::kResidX, MuonResiduals6DOFFitter::kResidXGamma, MuonResiduals6DOFFitter::kResidXSigma, MuonResiduals6DOFFitter::kResidY, MuonResiduals6DOFFitter::kResidYGamma, MuonResiduals6DOFFitter::kResidYSigma, MuonResiduals6DOFrphiFitter::kResSlope, MuonResiduals5DOFFitter::kResSlope, MuonResiduals5DOFFitter::kResSlopeGamma, MuonResiduals6DOFrphiFitter::kResSlopeGamma, MuonResiduals5DOFFitter::kResSlopeSigma, MuonResiduals6DOFrphiFitter::kResSlopeSigma, MuonResiduals6DOFFitter::kResSlopeX, MuonResiduals6DOFFitter::kResSlopeXGamma, MuonResiduals6DOFFitter::kResSlopeXSigma, MuonResiduals6DOFFitter::kResSlopeY, MuonResiduals6DOFFitter::kResSlopeYGamma, MuonResiduals6DOFFitter::kResSlopeYSigma, m_alignables, m_alignmentParameterStore, m_combineME11, m_debug, m_fitters, m_me11map, m_minAlignmentHits, m_reportFileName, TFileService::mkdir(), submitPVValidationJobs::params, edmIntegrityCheck::report, CSCDetId::ring(), DTChamberId::sector(), collectionMerger::selector, AlignmentParameterStore::setAlignmentPositionError(), DTChamberId::station(), CSCDetId::station(), AlCaHLTBitMon_QueryRunRegistry::string, and DTChamberId::wheel().

Referenced by terminate().

835  {
836  bool m_debug = false;
837 
838  edm::Service<TFileService> tfileService;
839  TFileDirectory rootDirectory(tfileService->mkdir("MuonAlignmentFromReference"));
840 
841  std::ofstream report;
842  bool writeReport = (m_reportFileName != std::string(""));
843  if (writeReport) {
844  report.open(m_reportFileName.c_str());
845  report << "nan = None; NAN = None" << std::endl;
846  report << "nan = 0" << std::endl;
847  report << "reports = []" << std::endl;
848  report << "class ValErr:" << std::endl
849  << " def __init__(self, value, error, antisym):" << std::endl
850  << " self.value, self.error, self.antisym = value, error, antisym" << std::endl
851  << "" << std::endl
852  << " def __repr__(self):" << std::endl
853  << " if self.antisym == 0.:" << std::endl
854  << " return \"%g +- %g\" % (self.value, self.error)" << std::endl
855  << " else:" << std::endl
856  << " return \"%g +- %g ~ %g\" % (self.value, self.error, self.antisym)" << std::endl
857  << "" << std::endl
858  << "class Report:" << std::endl
859  << " def __init__(self, chamberId, postal_address, name):" << std::endl
860  << " self.chamberId, self.postal_address, self.name = chamberId, postal_address, name" << std::endl
861  << " self.status = \"NOFIT\"" << std::endl
862  << " self.fittype = None" << std::endl
863  << "" << std::endl
864  << " def add_parameters(self, deltax, deltay, deltaz, deltaphix, deltaphiy, deltaphiz, loglikelihood, "
865  "numsegments, sumofweights, redchi2):"
866  << std::endl
867  << " self.status = \"PASS\"" << std::endl
868  << " self.deltax, self.deltay, self.deltaz, self.deltaphix, self.deltaphiy, self.deltaphiz = deltax, "
869  "deltay, deltaz, deltaphix, deltaphiy, deltaphiz"
870  << std::endl
871  << " self.loglikelihood, self.numsegments, self.sumofweights, self.redchi2 = loglikelihood, "
872  "numsegments, sumofweights, redchi2"
873  << std::endl
874  << "" << std::endl
875  << " def add_stats(self, median_x, median_y, median_dxdz, median_dydz, mean30_x, mean30_y, mean20_dxdz, "
876  "mean50_dydz, mean15_x, mean15_y, mean10_dxdz, mean25_dydz, wmean30_x, wmean30_y, wmean20_dxdz, "
877  "wmean50_dydz, wmean15_x, wmean15_y, wmean10_dxdz, wmean25_dydz, stdev30_x, stdev30_y, stdev20_dxdz, "
878  "stdev50_dydz, stdev15_x, stdev15_y, stdev10_dxdz, stdev25_dydz):"
879  << std::endl
880  << " self.median_x, self.median_y, self.median_dxdz, self.median_dydz, self.mean30_x, self.mean30_y, "
881  "self.mean20_dxdz, self.mean50_dydz, self.mean15_x, self.mean15_y, self.mean10_dxdz, self.mean25_dydz, "
882  "self.wmean30_x, self.wmean30_y, self.wmean20_dxdz, self.wmean50_dydz, self.wmean15_x, self.wmean15_y, "
883  "self.wmean10_dxdz, self.wmean25_dydz, self.stdev30_x, self.stdev30_y, self.stdev20_dxdz, "
884  "self.stdev50_dydz, self.stdev15_x, self.stdev15_y, self.stdev10_dxdz, self.stdev25_dydz = median_x, "
885  "median_y, median_dxdz, median_dydz, mean30_x, mean30_y, mean20_dxdz, mean50_dydz, mean15_x, mean15_y, "
886  "mean10_dxdz, mean25_dydz, wmean30_x, wmean30_y, wmean20_dxdz, wmean50_dydz, wmean15_x, wmean15_y, "
887  "wmean10_dxdz, wmean25_dydz, stdev30_x, stdev30_y, stdev20_dxdz, stdev50_dydz, stdev15_x, stdev15_y, "
888  "stdev10_dxdz, stdev25_dydz"
889  << std::endl
890  << "" << std::endl
891  << " def __repr__(self):" << std::endl
892  << " return \"<Report %s %s %s>\" % (self.postal_address[0], \" \".join(map(str, "
893  "self.postal_address[1:])), self.status)"
894  << std::endl
895  << std::endl;
896  }
897 
898  if (m_debug)
899  std::cout << "***** just after report.open" << std::endl;
900 
901  for (const auto& ali : m_alignables) {
902  if (m_debug)
903  std::cout << "***** Start loop over alignables" << std::endl;
904 
905  std::vector<bool> selector = ali->alignmentParameters()->selector();
906  bool align_x = selector[0];
907  bool align_y = selector[1];
908  bool align_z = selector[2];
909  bool align_phix = selector[3];
910  bool align_phiy = selector[4];
911  bool align_phiz = selector[5];
912  int numParams = ((align_x ? 1 : 0) + (align_y ? 1 : 0) + (align_z ? 1 : 0) + (align_phix ? 1 : 0) +
913  (align_phiy ? 1 : 0) + (align_phiz ? 1 : 0));
914 
915  // map from 0-5 to the index of params, above
916  std::vector<int> paramIndex;
917  int paramIndex_counter = -1;
918  if (align_x)
919  paramIndex_counter++;
920  paramIndex.push_back(paramIndex_counter);
921  if (align_y)
922  paramIndex_counter++;
923  paramIndex.push_back(paramIndex_counter);
924  if (align_z)
925  paramIndex_counter++;
926  paramIndex.push_back(paramIndex_counter);
927  if (align_phix)
928  paramIndex_counter++;
929  paramIndex.push_back(paramIndex_counter);
930  if (align_phiy)
931  paramIndex_counter++;
932  paramIndex.push_back(paramIndex_counter);
933  if (align_phiz)
934  paramIndex_counter++;
935  paramIndex.push_back(paramIndex_counter);
936 
937  DetId id = ali->geomDetId();
938 
939  auto thisali = ali;
940  if (m_combineME11 && id.subdetId() == MuonSubdetId::CSC) {
941  CSCDetId cscid(id.rawId());
942  if (cscid.station() == 1 && cscid.ring() == 4)
943  thisali = m_me11map[ali];
944  }
945 
946  if (m_debug)
947  std::cout << "***** loop over alignables 1" << std::endl;
948 
949  char cname[40];
950  char wheel_label[][2] = {"A", "B", "C", "D", "E"};
951 
952  if (id.subdetId() == MuonSubdetId::DT) {
953  DTChamberId chamberId(id.rawId());
954 
955  //if ( ! ( (chamberId.station()==1&&chamberId.wheel()==0) || (chamberId.station()==4&&chamberId.wheel()==2) ) ) continue;
956 
957  sprintf(cname, "MBwh%sst%dsec%02d", wheel_label[chamberId.wheel() + 2], chamberId.station(), chamberId.sector());
958  if (writeReport) {
959  report << "reports.append(Report(" << id.rawId() << ", (\"DT\", " << chamberId.wheel() << ", "
960  << chamberId.station() << ", " << chamberId.sector() << "), \"" << cname << "\"))" << std::endl;
961  }
962  } else if (id.subdetId() == MuonSubdetId::CSC) {
963  CSCDetId chamberId(id.rawId());
964  sprintf(cname,
965  "ME%s%d%d_%02d",
966  (chamberId.endcap() == 1 ? "p" : "m"),
967  chamberId.station(),
968  chamberId.ring(),
969  chamberId.chamber());
970 
971  //if ( chamberId.chamber()>6 || chamberId.endcap()==2 || ! ( (chamberId.station()==2&&chamberId.ring()==1) || (chamberId.station()==3&&chamberId.ring()==2) ) ) continue;
972 
973  if (writeReport) {
974  report << "reports.append(Report(" << id.rawId() << ", (\"CSC\", " << chamberId.endcap() << ", "
975  << chamberId.station() << ", " << chamberId.ring() << ", " << chamberId.chamber() << "), \"" << cname
976  << "\"))" << std::endl;
977  }
978  }
979 
980  if (m_debug)
981  std::cout << "***** loop over alignables 2" << std::endl;
982 
983  //if(! ( strcmp(cname,"MBwhCst3sec12")==0 || strcmp(cname,"MBwhCst3sec06")==0)) continue;
984 
985  std::map<Alignable*, MuonResidualsTwoBin*>::const_iterator fitter = m_fitters.find(thisali);
986 
987  if (m_debug)
988  std::cout << "***** loop over alignables 3" << std::endl;
989 
990  if (fitter != m_fitters.end()) {
991  //if (fitter->second->type() != MuonResidualsFitter::k6DOFrphi) continue;
992 
993  TStopwatch stop_watch;
994  stop_watch.Start();
995 
996  // MINUIT is verbose in std::cout anyway
997  if (m_debug)
998  std::cout << "============================================================================================="
999  << std::endl;
1000  if (m_debug)
1001  std::cout << "Fitting " << cname << std::endl;
1002 
1003  if (writeReport) {
1004  report << "reports[-1].posNum = " << fitter->second->numResidualsPos() << std::endl;
1005  report << "reports[-1].negNum = " << fitter->second->numResidualsNeg() << std::endl;
1006  }
1007 
1008  if (fitter->second->type() == MuonResidualsFitter::k5DOF) {
1009  if (!align_x)
1010  fitter->second->fix(MuonResiduals5DOFFitter::kAlignX);
1011  if (!align_z)
1012  fitter->second->fix(MuonResiduals5DOFFitter::kAlignZ);
1013  if (!align_phix)
1014  fitter->second->fix(MuonResiduals5DOFFitter::kAlignPhiX);
1015  if (!align_phiy)
1016  fitter->second->fix(MuonResiduals5DOFFitter::kAlignPhiY);
1017  if (!align_phiz)
1018  fitter->second->fix(MuonResiduals5DOFFitter::kAlignPhiZ);
1019  } else if (fitter->second->type() == MuonResidualsFitter::k6DOF) {
1020  if (!align_x)
1021  fitter->second->fix(MuonResiduals6DOFFitter::kAlignX);
1022  if (!align_y)
1023  fitter->second->fix(MuonResiduals6DOFFitter::kAlignY);
1024  if (!align_z)
1025  fitter->second->fix(MuonResiduals6DOFFitter::kAlignZ);
1026  if (!align_phix)
1027  fitter->second->fix(MuonResiduals6DOFFitter::kAlignPhiX);
1028  if (!align_phiy)
1029  fitter->second->fix(MuonResiduals6DOFFitter::kAlignPhiY);
1030  if (!align_phiz)
1031  fitter->second->fix(MuonResiduals6DOFFitter::kAlignPhiZ);
1032  } else if (fitter->second->type() == MuonResidualsFitter::k6DOFrphi) {
1033  if (!align_x)
1034  fitter->second->fix(MuonResiduals6DOFrphiFitter::kAlignX);
1035  if (!align_y)
1036  fitter->second->fix(MuonResiduals6DOFrphiFitter::kAlignY);
1037  if (!align_z)
1038  fitter->second->fix(MuonResiduals6DOFrphiFitter::kAlignZ);
1039  if (!align_phix)
1040  fitter->second->fix(MuonResiduals6DOFrphiFitter::kAlignPhiX);
1041  if (!align_phiy)
1042  fitter->second->fix(MuonResiduals6DOFrphiFitter::kAlignPhiY);
1043  if (!align_phiz)
1044  fitter->second->fix(MuonResiduals6DOFrphiFitter::kAlignPhiZ);
1045  } else
1046  assert(false);
1047 
1048  if (m_debug)
1049  std::cout << "***** loop over alignables 4" << std::endl;
1050 
1051  AlgebraicVector params(numParams);
1052  AlgebraicSymMatrix cov(numParams);
1053 
1054  if (fitter->second->numsegments() >= m_minAlignmentHits) {
1055  if (m_debug)
1056  std::cout << "***** loop over alignables 5" << std::endl;
1057 
1058  bool successful_fit = fitter->second->fit(thisali);
1059 
1060  if (m_debug)
1061  std::cout << "***** loop over alignables 6 " << fitter->second->type() << std::endl;
1062 
1063  double loglikelihood = fitter->second->loglikelihood();
1064  double numsegments = fitter->second->numsegments();
1065  double sumofweights = fitter->second->sumofweights();
1066  double redchi2 = fitter->second->plot(cname, &rootDirectory, thisali);
1067 
1068  if (fitter->second->type() == MuonResidualsFitter::k5DOF) {
1069  if (m_debug)
1070  std::cout << "***** loop over alignables k5DOF" << std::endl;
1071 
1072  double deltax_value = fitter->second->value(MuonResiduals5DOFFitter::kAlignX);
1073  double deltax_error = fitter->second->errorerror(MuonResiduals5DOFFitter::kAlignX);
1074  double deltax_antisym = fitter->second->antisym(MuonResiduals5DOFFitter::kAlignX);
1075 
1076  double deltaz_value = fitter->second->value(MuonResiduals5DOFFitter::kAlignZ);
1077  double deltaz_error = fitter->second->errorerror(MuonResiduals5DOFFitter::kAlignZ);
1078  double deltaz_antisym = fitter->second->antisym(MuonResiduals5DOFFitter::kAlignZ);
1079 
1080  double deltaphix_value = fitter->second->value(MuonResiduals5DOFFitter::kAlignPhiX);
1081  double deltaphix_error = fitter->second->errorerror(MuonResiduals5DOFFitter::kAlignPhiX);
1082  double deltaphix_antisym = fitter->second->antisym(MuonResiduals5DOFFitter::kAlignPhiX);
1083 
1084  double deltaphiy_value = fitter->second->value(MuonResiduals5DOFFitter::kAlignPhiY);
1085  double deltaphiy_error = fitter->second->errorerror(MuonResiduals5DOFFitter::kAlignPhiY);
1086  double deltaphiy_antisym = fitter->second->antisym(MuonResiduals5DOFFitter::kAlignPhiY);
1087 
1088  double deltaphiz_value = fitter->second->value(MuonResiduals5DOFFitter::kAlignPhiZ);
1089  double deltaphiz_error = fitter->second->errorerror(MuonResiduals5DOFFitter::kAlignPhiZ);
1090  double deltaphiz_antisym = fitter->second->antisym(MuonResiduals5DOFFitter::kAlignPhiZ);
1091 
1092  double sigmaresid_value = fitter->second->value(MuonResiduals5DOFFitter::kResidSigma);
1093  double sigmaresid_error = fitter->second->errorerror(MuonResiduals5DOFFitter::kResidSigma);
1094  double sigmaresid_antisym = fitter->second->antisym(MuonResiduals5DOFFitter::kResidSigma);
1095 
1096  double sigmaresslope_value = fitter->second->value(MuonResiduals5DOFFitter::kResSlopeSigma);
1097  double sigmaresslope_error = fitter->second->errorerror(MuonResiduals5DOFFitter::kResSlopeSigma);
1098  double sigmaresslope_antisym = fitter->second->antisym(MuonResiduals5DOFFitter::kResSlopeSigma);
1099 
1100  double gammaresid_value, gammaresid_error, gammaresid_antisym, gammaresslope_value, gammaresslope_error,
1101  gammaresslope_antisym;
1102  gammaresid_value = gammaresid_error = gammaresid_antisym = gammaresslope_value = gammaresslope_error =
1103  gammaresslope_antisym = 0.;
1104 
1105  if (fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian &&
1106  fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian2D &&
1107  fitter->second->residualsModel() != MuonResidualsFitter::kGaussPowerTails) {
1108  gammaresid_value = fitter->second->value(MuonResiduals5DOFFitter::kResidGamma);
1109  gammaresid_error = fitter->second->errorerror(MuonResiduals5DOFFitter::kResidGamma);
1110  gammaresid_antisym = fitter->second->antisym(MuonResiduals5DOFFitter::kResidGamma);
1111 
1112  gammaresslope_value = fitter->second->value(MuonResiduals5DOFFitter::kResSlopeGamma);
1113  gammaresslope_error = fitter->second->errorerror(MuonResiduals5DOFFitter::kResSlopeGamma);
1114  gammaresslope_antisym = fitter->second->antisym(MuonResiduals5DOFFitter::kResSlopeGamma);
1115  }
1116 
1117  if (writeReport) {
1118  report << "reports[-1].fittype = \"5DOF\"" << std::endl;
1119  report << "reports[-1].add_parameters(ValErr(" << deltax_value << ", " << deltax_error << ", "
1120  << deltax_antisym << "), \\" << std::endl
1121  << " None, \\" << std::endl
1122  << " ValErr(" << deltaz_value << ", " << deltaz_error << ", "
1123  << deltaz_antisym << "), \\" << std::endl
1124  << " ValErr(" << deltaphix_value << ", " << deltaphix_error << ", "
1125  << deltaphix_antisym << "), \\" << std::endl
1126  << " ValErr(" << deltaphiy_value << ", " << deltaphiy_error << ", "
1127  << deltaphiy_antisym << "), \\" << std::endl
1128  << " ValErr(" << deltaphiz_value << ", " << deltaphiz_error << ", "
1129  << deltaphiz_antisym << "), \\" << std::endl
1130  << " " << loglikelihood << ", " << numsegments << ", " << sumofweights
1131  << ", " << redchi2 << ")" << std::endl;
1132  report << "reports[-1].sigmaresid = ValErr(" << sigmaresid_value << ", " << sigmaresid_error << ", "
1133  << sigmaresid_antisym << ")" << std::endl;
1134  report << "reports[-1].sigmaresslope = ValErr(" << sigmaresslope_value << ", " << sigmaresslope_error
1135  << ", " << sigmaresslope_antisym << ")" << std::endl;
1136  if (fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian &&
1137  fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian2D &&
1138  fitter->second->residualsModel() != MuonResidualsFitter::kGaussPowerTails) {
1139  report << "reports[-1].gammaresid = ValErr(" << gammaresid_value << ", " << gammaresid_error << ", "
1140  << gammaresid_antisym << ")" << std::endl;
1141  report << "reports[-1].gammaresslope = ValErr(" << gammaresslope_value << ", " << gammaresslope_error
1142  << ", " << gammaresslope_antisym << ")" << std::endl;
1143  }
1144 
1145  report << "reports[-1].add_stats(" << fitter->second->median(MuonResiduals5DOFFitter::kResid) << ", "
1146  << "None, " << fitter->second->median(MuonResiduals5DOFFitter::kResSlope) << ", "
1147  << "None, " << fitter->second->mean(MuonResiduals5DOFFitter::kResid, 30.) << ", "
1148  << "None, " << fitter->second->mean(MuonResiduals5DOFFitter::kResSlope, 20.) << ", "
1149  << "None, " << fitter->second->mean(MuonResiduals5DOFFitter::kResid, 15.) << ", "
1150  << "None, " << fitter->second->mean(MuonResiduals5DOFFitter::kResSlope, 10.) << ", "
1151  << "None, "
1153  << ", "
1154  << "None, "
1156  << ", "
1157  << "None, "
1159  << ", "
1160  << "None, "
1162  << ", "
1163  << "None, " << fitter->second->stdev(MuonResiduals5DOFFitter::kResid, 30.) << ", "
1164  << "None, " << fitter->second->stdev(MuonResiduals5DOFFitter::kResSlope, 20.) << ", "
1165  << "None, " << fitter->second->stdev(MuonResiduals5DOFFitter::kResid, 15.) << ", "
1166  << "None, " << fitter->second->stdev(MuonResiduals5DOFFitter::kResSlope, 10.) << ", "
1167  << "None)" << std::endl;
1168 
1169  std::stringstream namesimple_x, namesimple_dxdz, nameweighted_x, nameweighted_dxdz;
1170  namesimple_x << cname << "_simple_x";
1171  namesimple_dxdz << cname << "_simple_dxdz";
1172  nameweighted_x << cname << "_weighted_x";
1173  nameweighted_dxdz << cname << "_weighted_dxdz";
1174 
1175  fitter->second->plotsimple(namesimple_x.str(), &rootDirectory, MuonResiduals5DOFFitter::kResid, 10.);
1176  fitter->second->plotsimple(
1177  namesimple_dxdz.str(), &rootDirectory, MuonResiduals5DOFFitter::kResSlope, 1000.);
1178 
1179  fitter->second->plotweighted(nameweighted_x.str(),
1180  &rootDirectory,
1183  10.);
1184  fitter->second->plotweighted(nameweighted_dxdz.str(),
1185  &rootDirectory,
1188  1000.);
1189  }
1190 
1191  if (successful_fit) {
1192  if (align_x)
1193  params[paramIndex[0]] = deltax_value;
1194  if (align_z)
1195  params[paramIndex[2]] = deltaz_value;
1196  if (align_phix)
1197  params[paramIndex[3]] = deltaphix_value;
1198  if (align_phiy)
1199  params[paramIndex[4]] = deltaphiy_value;
1200  if (align_phiz)
1201  params[paramIndex[5]] = deltaphiz_value;
1202  }
1203  } // end if 5DOF
1204 
1205  else if (fitter->second->type() == MuonResidualsFitter::k6DOF) {
1206  if (m_debug)
1207  std::cout << "***** loop over alignables k6DOF" << std::endl;
1208 
1209  double deltax_value = fitter->second->value(MuonResiduals6DOFFitter::kAlignX);
1210  double deltax_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kAlignX);
1211  double deltax_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kAlignX);
1212 
1213  double deltay_value = fitter->second->value(MuonResiduals6DOFFitter::kAlignY);
1214  double deltay_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kAlignY);
1215  double deltay_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kAlignY);
1216 
1217  double deltaz_value = fitter->second->value(MuonResiduals6DOFFitter::kAlignZ);
1218  double deltaz_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kAlignZ);
1219  double deltaz_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kAlignZ);
1220 
1221  double deltaphix_value = fitter->second->value(MuonResiduals6DOFFitter::kAlignPhiX);
1222  double deltaphix_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kAlignPhiX);
1223  double deltaphix_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kAlignPhiX);
1224 
1225  double deltaphiy_value = fitter->second->value(MuonResiduals6DOFFitter::kAlignPhiY);
1226  double deltaphiy_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kAlignPhiY);
1227  double deltaphiy_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kAlignPhiY);
1228 
1229  double deltaphiz_value = fitter->second->value(MuonResiduals6DOFFitter::kAlignPhiZ);
1230  double deltaphiz_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kAlignPhiZ);
1231  double deltaphiz_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kAlignPhiZ);
1232 
1233  double sigmax_value = fitter->second->value(MuonResiduals6DOFFitter::kResidXSigma);
1234  double sigmax_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kResidXSigma);
1235  double sigmax_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kResidXSigma);
1236 
1237  double sigmay_value = fitter->second->value(MuonResiduals6DOFFitter::kResidYSigma);
1238  double sigmay_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kResidYSigma);
1239  double sigmay_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kResidYSigma);
1240 
1241  double sigmadxdz_value = fitter->second->value(MuonResiduals6DOFFitter::kResSlopeXSigma);
1242  double sigmadxdz_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kResSlopeXSigma);
1243  double sigmadxdz_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kResSlopeXSigma);
1244 
1245  double sigmadydz_value = fitter->second->value(MuonResiduals6DOFFitter::kResSlopeYSigma);
1246  double sigmadydz_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kResSlopeYSigma);
1247  double sigmadydz_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kResSlopeYSigma);
1248 
1249  double gammax_value, gammax_error, gammax_antisym, gammay_value, gammay_error, gammay_antisym,
1250  gammadxdz_value, gammadxdz_error, gammadxdz_antisym, gammadydz_value, gammadydz_error, gammadydz_antisym;
1251  gammax_value = gammax_error = gammax_antisym = gammay_value = gammay_error = gammay_antisym =
1252  gammadxdz_value = gammadxdz_error = gammadxdz_antisym = gammadydz_value = gammadydz_error =
1253  gammadydz_antisym = 0.;
1254  if (fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian &&
1255  fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian2D &&
1256  fitter->second->residualsModel() != MuonResidualsFitter::kGaussPowerTails) {
1257  gammax_value = fitter->second->value(MuonResiduals6DOFFitter::kResidXGamma);
1258  gammax_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kResidXGamma);
1259  gammax_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kResidXGamma);
1260 
1261  gammay_value = fitter->second->value(MuonResiduals6DOFFitter::kResidYGamma);
1262  gammay_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kResidYGamma);
1263  gammay_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kResidYGamma);
1264 
1265  gammadxdz_value = fitter->second->value(MuonResiduals6DOFFitter::kResSlopeXGamma);
1266  gammadxdz_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kResSlopeXGamma);
1267  gammadxdz_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kResSlopeXGamma);
1268 
1269  gammadydz_value = fitter->second->value(MuonResiduals6DOFFitter::kResSlopeYGamma);
1270  gammadydz_error = fitter->second->errorerror(MuonResiduals6DOFFitter::kResSlopeYGamma);
1271  gammadydz_antisym = fitter->second->antisym(MuonResiduals6DOFFitter::kResSlopeYGamma);
1272  }
1273 
1274  if (writeReport) {
1275  report << "reports[-1].fittype = \"6DOF\"" << std::endl;
1276  report << "reports[-1].add_parameters(ValErr(" << deltax_value << ", " << deltax_error << ", "
1277  << deltax_antisym << "), \\" << std::endl
1278  << " ValErr(" << deltay_value << ", " << deltay_error << ", "
1279  << deltay_antisym << "), \\" << std::endl
1280  << " ValErr(" << deltaz_value << ", " << deltaz_error << ", "
1281  << deltaz_antisym << "), \\" << std::endl
1282  << " ValErr(" << deltaphix_value << ", " << deltaphix_error << ", "
1283  << deltaphix_antisym << "), \\" << std::endl
1284  << " ValErr(" << deltaphiy_value << ", " << deltaphiy_error << ", "
1285  << deltaphiy_antisym << "), \\" << std::endl
1286  << " ValErr(" << deltaphiz_value << ", " << deltaphiz_error << ", "
1287  << deltaphiz_antisym << "), \\" << std::endl
1288  << " " << loglikelihood << ", " << numsegments << ", " << sumofweights
1289  << ", " << redchi2 << ")" << std::endl;
1290  report << "reports[-1].sigmax = ValErr(" << sigmax_value << ", " << sigmax_error << ", " << sigmax_antisym
1291  << ")" << std::endl;
1292  report << "reports[-1].sigmay = ValErr(" << sigmay_value << ", " << sigmay_error << ", " << sigmay_antisym
1293  << ")" << std::endl;
1294  report << "reports[-1].sigmadxdz = ValErr(" << sigmadxdz_value << ", " << sigmadxdz_error << ", "
1295  << sigmadxdz_antisym << ")" << std::endl;
1296  report << "reports[-1].sigmadydz = ValErr(" << sigmadydz_value << ", " << sigmadydz_error << ", "
1297  << sigmadydz_antisym << ")" << std::endl;
1298  if (fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian &&
1299  fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian2D &&
1300  fitter->second->residualsModel() != MuonResidualsFitter::kGaussPowerTails) {
1301  report << "reports[-1].gammax = ValErr(" << gammax_value << ", " << gammax_error << ", " << gammax_antisym
1302  << ")" << std::endl;
1303  report << "reports[-1].gammay = ValErr(" << gammay_value << ", " << gammay_error << ", " << gammay_antisym
1304  << ")" << std::endl;
1305  report << "reports[-1].gammadxdz = ValErr(" << gammadxdz_value << ", " << gammadxdz_error << ", "
1306  << gammadxdz_antisym << ")" << std::endl;
1307  report << "reports[-1].gammadydz = ValErr(" << gammadydz_value << ", " << gammadydz_error << ", "
1308  << gammadydz_antisym << ")" << std::endl;
1309  }
1310 
1311  report << "reports[-1].add_stats(" << fitter->second->median(MuonResiduals6DOFFitter::kResidX) << ", "
1312  << fitter->second->median(MuonResiduals6DOFFitter::kResidY) << ", "
1313  << fitter->second->median(MuonResiduals6DOFFitter::kResSlopeX) << ", "
1314  << fitter->second->median(MuonResiduals6DOFFitter::kResSlopeY) << ", "
1315  << fitter->second->mean(MuonResiduals6DOFFitter::kResidX, 30.) << ", "
1316  << fitter->second->mean(MuonResiduals6DOFFitter::kResidY, 30.) << ", "
1317  << fitter->second->mean(MuonResiduals6DOFFitter::kResSlopeX, 20.) << ", "
1318  << fitter->second->mean(MuonResiduals6DOFFitter::kResSlopeY, 50.) << ", "
1319  << fitter->second->mean(MuonResiduals6DOFFitter::kResidX, 15.) << ", "
1320  << fitter->second->mean(MuonResiduals6DOFFitter::kResidY, 15.) << ", "
1321  << fitter->second->mean(MuonResiduals6DOFFitter::kResSlopeX, 10.) << ", "
1322  << fitter->second->mean(MuonResiduals6DOFFitter::kResSlopeY, 25.) << ", "
1324  << ", "
1326  << ", "
1328  << ", "
1330  << ", "
1332  << ", "
1334  << ", "
1336  << ", "
1338  << ", " << fitter->second->stdev(MuonResiduals6DOFFitter::kResidX, 30.) << ", "
1339  << fitter->second->stdev(MuonResiduals6DOFFitter::kResidY, 30.) << ", "
1340  << fitter->second->stdev(MuonResiduals6DOFFitter::kResSlopeX, 20.) << ", "
1341  << fitter->second->stdev(MuonResiduals6DOFFitter::kResSlopeY, 50.) << ", "
1342  << fitter->second->stdev(MuonResiduals6DOFFitter::kResidX, 15.) << ", "
1343  << fitter->second->stdev(MuonResiduals6DOFFitter::kResidY, 15.) << ", "
1344  << fitter->second->stdev(MuonResiduals6DOFFitter::kResSlopeX, 10.) << ", "
1345  << fitter->second->stdev(MuonResiduals6DOFFitter::kResSlopeY, 25.) << ")" << std::endl;
1346 
1347  std::stringstream namesimple_x, namesimple_y, namesimple_dxdz, namesimple_dydz, nameweighted_x,
1348  nameweighted_y, nameweighted_dxdz, nameweighted_dydz;
1349  namesimple_x << cname << "_simple_x";
1350  namesimple_y << cname << "_simple_y";
1351  namesimple_dxdz << cname << "_simple_dxdz";
1352  namesimple_dydz << cname << "_simple_dydz";
1353  nameweighted_x << cname << "_weighted_x";
1354  nameweighted_y << cname << "_weighted_y";
1355  nameweighted_dxdz << cname << "_weighted_dxdz";
1356  nameweighted_dydz << cname << "_weighted_dydz";
1357 
1358  fitter->second->plotsimple(namesimple_x.str(), &rootDirectory, MuonResiduals6DOFFitter::kResidX, 10.);
1359  fitter->second->plotsimple(namesimple_y.str(), &rootDirectory, MuonResiduals6DOFFitter::kResidY, 10.);
1360  fitter->second->plotsimple(
1361  namesimple_dxdz.str(), &rootDirectory, MuonResiduals6DOFFitter::kResSlopeX, 1000.);
1362  fitter->second->plotsimple(
1363  namesimple_dydz.str(), &rootDirectory, MuonResiduals6DOFFitter::kResSlopeY, 1000.);
1364 
1365  fitter->second->plotweighted(nameweighted_x.str(),
1366  &rootDirectory,
1369  10.);
1370  fitter->second->plotweighted(nameweighted_y.str(),
1371  &rootDirectory,
1374  10.);
1375  fitter->second->plotweighted(nameweighted_dxdz.str(),
1376  &rootDirectory,
1379  1000.);
1380  fitter->second->plotweighted(nameweighted_dydz.str(),
1381  &rootDirectory,
1384  1000.);
1385  }
1386 
1387  if (successful_fit) {
1388  if (align_x)
1389  params[paramIndex[0]] = deltax_value;
1390  if (align_y)
1391  params[paramIndex[1]] = deltay_value;
1392  if (align_z)
1393  params[paramIndex[2]] = deltaz_value;
1394  if (align_phix)
1395  params[paramIndex[3]] = deltaphix_value;
1396  if (align_phiy)
1397  params[paramIndex[4]] = deltaphiy_value;
1398  if (align_phiz)
1399  params[paramIndex[5]] = deltaphiz_value;
1400  }
1401  } // end if 6DOF
1402 
1403  else if (fitter->second->type() == MuonResidualsFitter::k6DOFrphi) {
1404  if (m_debug)
1405  std::cout << "***** loop over alignables k6DOFrphi" << std::endl;
1406 
1407  double deltax_value = fitter->second->value(MuonResiduals6DOFrphiFitter::kAlignX);
1408  double deltax_error = fitter->second->errorerror(MuonResiduals6DOFrphiFitter::kAlignX);
1409  double deltax_antisym = fitter->second->antisym(MuonResiduals6DOFrphiFitter::kAlignX);
1410 
1411  double deltay_value = fitter->second->value(MuonResiduals6DOFrphiFitter::kAlignY);
1412  double deltay_error = fitter->second->errorerror(MuonResiduals6DOFrphiFitter::kAlignY);
1413  double deltay_antisym = fitter->second->antisym(MuonResiduals6DOFrphiFitter::kAlignY);
1414 
1415  double deltaz_value = fitter->second->value(MuonResiduals6DOFrphiFitter::kAlignZ);
1416  double deltaz_error = fitter->second->errorerror(MuonResiduals6DOFrphiFitter::kAlignZ);
1417  double deltaz_antisym = fitter->second->antisym(MuonResiduals6DOFrphiFitter::kAlignZ);
1418 
1419  double deltaphix_value = fitter->second->value(MuonResiduals6DOFrphiFitter::kAlignPhiX);
1420  double deltaphix_error = fitter->second->errorerror(MuonResiduals6DOFrphiFitter::kAlignPhiX);
1421  double deltaphix_antisym = fitter->second->antisym(MuonResiduals6DOFrphiFitter::kAlignPhiX);
1422 
1423  double deltaphiy_value = fitter->second->value(MuonResiduals6DOFrphiFitter::kAlignPhiY);
1424  double deltaphiy_error = fitter->second->errorerror(MuonResiduals6DOFrphiFitter::kAlignPhiY);
1425  double deltaphiy_antisym = fitter->second->antisym(MuonResiduals6DOFrphiFitter::kAlignPhiY);
1426 
1427  double deltaphiz_value = fitter->second->value(MuonResiduals6DOFrphiFitter::kAlignPhiZ);
1428  double deltaphiz_error = fitter->second->errorerror(MuonResiduals6DOFrphiFitter::kAlignPhiZ);
1429  double deltaphiz_antisym = fitter->second->antisym(MuonResiduals6DOFrphiFitter::kAlignPhiZ);
1430 
1431  double sigmaresid_value = fitter->second->value(MuonResiduals6DOFrphiFitter::kResidSigma);
1432  double sigmaresid_error = fitter->second->errorerror(MuonResiduals6DOFrphiFitter::kResidSigma);
1433  double sigmaresid_antisym = fitter->second->antisym(MuonResiduals6DOFrphiFitter::kResidSigma);
1434 
1435  double sigmaresslope_value = fitter->second->value(MuonResiduals6DOFrphiFitter::kResSlopeSigma);
1436  double sigmaresslope_error = fitter->second->errorerror(MuonResiduals6DOFrphiFitter::kResSlopeSigma);
1437  double sigmaresslope_antisym = fitter->second->antisym(MuonResiduals6DOFrphiFitter::kResSlopeSigma);
1438 
1439  double gammaresid_value, gammaresid_error, gammaresid_antisym, gammaresslope_value, gammaresslope_error,
1440  gammaresslope_antisym;
1441  gammaresid_value = gammaresid_error = gammaresid_antisym = gammaresslope_value = gammaresslope_error =
1442  gammaresslope_antisym = 0.;
1443  if (fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian &&
1444  fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian2D &&
1445  fitter->second->residualsModel() != MuonResidualsFitter::kGaussPowerTails) {
1446  gammaresid_value = fitter->second->value(MuonResiduals6DOFrphiFitter::kResidGamma);
1447  gammaresid_error = fitter->second->errorerror(MuonResiduals6DOFrphiFitter::kResidGamma);
1448  gammaresid_antisym = fitter->second->antisym(MuonResiduals6DOFrphiFitter::kResidGamma);
1449 
1450  gammaresslope_value = fitter->second->value(MuonResiduals6DOFrphiFitter::kResSlopeGamma);
1451  gammaresslope_error = fitter->second->errorerror(MuonResiduals6DOFrphiFitter::kResSlopeGamma);
1452  gammaresslope_antisym = fitter->second->antisym(MuonResiduals6DOFrphiFitter::kResSlopeGamma);
1453  }
1454 
1455  if (writeReport) {
1456  report << "reports[-1].fittype = \"6DOFrphi\"" << std::endl;
1457  report << "reports[-1].add_parameters(ValErr(" << deltax_value << ", " << deltax_error << ", "
1458  << deltax_antisym << "), \\" << std::endl
1459  << " ValErr(" << deltay_value << ", " << deltay_error << ", "
1460  << deltay_antisym << "), \\" << std::endl
1461  << " ValErr(" << deltaz_value << ", " << deltaz_error << ", "
1462  << deltaz_antisym << "), \\" << std::endl
1463  << " ValErr(" << deltaphix_value << ", " << deltaphix_error << ", "
1464  << deltaphix_antisym << "), \\" << std::endl
1465  << " ValErr(" << deltaphiy_value << ", " << deltaphiy_error << ", "
1466  << deltaphiy_antisym << "), \\" << std::endl
1467  << " ValErr(" << deltaphiz_value << ", " << deltaphiz_error << ", "
1468  << deltaphiz_antisym << "), \\" << std::endl
1469  << " " << loglikelihood << ", " << numsegments << ", " << sumofweights
1470  << ", " << redchi2 << ")" << std::endl;
1471  report << "reports[-1].sigmaresid = ValErr(" << sigmaresid_value << ", " << sigmaresid_error << ", "
1472  << sigmaresid_antisym << ")" << std::endl;
1473  report << "reports[-1].sigmaresslope = ValErr(" << sigmaresslope_value << ", " << sigmaresslope_error
1474  << ", " << sigmaresslope_antisym << ")" << std::endl;
1475  if (fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian &&
1476  fitter->second->residualsModel() != MuonResidualsFitter::kPureGaussian2D &&
1477  fitter->second->residualsModel() != MuonResidualsFitter::kGaussPowerTails) {
1478  report << "reports[-1].gammaresid = ValErr(" << gammaresid_value << ", " << gammaresid_error << ", "
1479  << gammaresid_antisym << ")" << std::endl;
1480  report << "reports[-1].gammaresslope = ValErr(" << gammaresslope_value << ", " << gammaresslope_error
1481  << ", " << gammaresslope_antisym << ")" << std::endl;
1482  }
1483 
1484  report << "reports[-1].add_stats(" << fitter->second->median(MuonResiduals6DOFrphiFitter::kResid) << ", "
1485  << "None, " << fitter->second->median(MuonResiduals6DOFrphiFitter::kResSlope) << ", "
1486  << "None, " << fitter->second->mean(MuonResiduals6DOFrphiFitter::kResid, 30.) << ", "
1487  << "None, " << fitter->second->mean(MuonResiduals6DOFrphiFitter::kResSlope, 20.) << ", "
1488  << "None, " << fitter->second->mean(MuonResiduals6DOFrphiFitter::kResid, 15.) << ", "
1489  << "None, " << fitter->second->mean(MuonResiduals6DOFrphiFitter::kResSlope, 10.) << ", "
1490  << "None, "
1491  << fitter->second->wmean(
1493  << ", "
1494  << "None, "
1495  << fitter->second->wmean(
1497  << ", "
1498  << "None, "
1499  << fitter->second->wmean(
1501  << ", "
1502  << "None, "
1503  << fitter->second->wmean(
1505  << ", "
1506  << "None, " << fitter->second->stdev(MuonResiduals6DOFrphiFitter::kResid, 30.) << ", "
1507  << "None, " << fitter->second->stdev(MuonResiduals6DOFrphiFitter::kResSlope, 20.) << ", "
1508  << "None, " << fitter->second->stdev(MuonResiduals6DOFrphiFitter::kResid, 15.) << ", "
1509  << "None, " << fitter->second->stdev(MuonResiduals6DOFrphiFitter::kResSlope, 10.) << ", "
1510  << "None)" << std::endl;
1511 
1512  std::stringstream namesimple_x, namesimple_dxdz, nameweighted_x, nameweighted_dxdz;
1513  namesimple_x << cname << "_simple_x";
1514  namesimple_dxdz << cname << "_simple_dxdz";
1515  nameweighted_x << cname << "_weighted_x";
1516  nameweighted_dxdz << cname << "_weighted_dxdz";
1517 
1518  fitter->second->plotsimple(namesimple_x.str(), &rootDirectory, MuonResiduals6DOFrphiFitter::kResid, 10.);
1519  fitter->second->plotsimple(
1520  namesimple_dxdz.str(), &rootDirectory, MuonResiduals6DOFrphiFitter::kResSlope, 1000.);
1521 
1522  fitter->second->plotweighted(nameweighted_x.str(),
1523  &rootDirectory,
1526  10.);
1527  fitter->second->plotweighted(nameweighted_dxdz.str(),
1528  &rootDirectory,
1531  1000.);
1532  }
1533 
1534  if (successful_fit) {
1535  if (align_x)
1536  params[paramIndex[0]] = deltax_value;
1537  if (align_y)
1538  params[paramIndex[1]] = deltay_value;
1539  if (align_z)
1540  params[paramIndex[2]] = deltaz_value;
1541  if (align_phix)
1542  params[paramIndex[3]] = deltaphix_value;
1543  if (align_phiy)
1544  params[paramIndex[4]] = deltaphiy_value;
1545  if (align_phiz)
1546  params[paramIndex[5]] = deltaphiz_value;
1547  }
1548  } // end if 6DOFrphi
1549 
1550  if (successful_fit) {
1551  align::Alignables oneortwo;
1552  oneortwo.push_back(ali);
1553  if (thisali != ali)
1554  oneortwo.push_back(thisali);
1556  } else {
1557  if (m_debug)
1558  std::cout << "MINUIT fit failed!" << std::endl;
1559  if (writeReport) {
1560  report << "reports[-1].status = \"MINUITFAIL\"" << std::endl;
1561  }
1562 
1563  for (int i = 0; i < numParams; i++)
1564  cov[i][i] = 1000.;
1565 
1566  align::Alignables oneortwo;
1567  oneortwo.push_back(ali);
1568  if (thisali != ali)
1569  oneortwo.push_back(thisali);
1571  }
1572  } else { // too few hits
1573  if (m_debug)
1574  std::cout << "Too few hits!" << std::endl;
1575  if (writeReport) {
1576  report << "reports[-1].status = \"TOOFEWHITS\"" << std::endl;
1577  }
1578 
1579  for (int i = 0; i < numParams; i++)
1580  cov[i][i] = 1000.;
1581 
1582  align::Alignables oneortwo;
1583  oneortwo.push_back(ali);
1584  if (thisali != ali)
1585  oneortwo.push_back(thisali);
1587  }
1588 
1589  AlignmentParameters* parnew = ali->alignmentParameters()->cloneFromSelected(params, cov);
1590  ali->setAlignmentParameters(parnew);
1592  ali->alignmentParameters()->setValid(true);
1593 
1594  if (m_debug)
1595  std::cout << cname << " fittime= " << stop_watch.CpuTime() << " sec" << std::endl;
1596  } // end we have a fitter for this alignable
1597 
1598  if (writeReport)
1599  report << std::endl;
1600 
1601  } // end loop over alignables
1602 
1603  if (writeReport)
1604  report.close();
1605 }
void setAlignmentPositionError(const align::Alignables &alivec, double valshift, double valrot)
Set Alignment position error.
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
assert(be >=bs)
AlignmentParameterStore * m_alignmentParameterStore
std::map< Alignable *, MuonResidualsTwoBin * > m_fitters
Definition: DetId.h:17
CLHEP::HepVector AlgebraicVector
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
std::map< Alignable *, Alignable * > m_me11map
CLHEP::HepSymMatrix AlgebraicSymMatrix
static constexpr int DT
Definition: MuonSubdetId.h:11
virtual AlignmentParameters * cloneFromSelected(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
static constexpr int CSC
Definition: MuonSubdetId.h:12

◆ initialize()

void MuonAlignmentFromReference::initialize ( const edm::EventSetup setup,
AlignableTracker tracker,
AlignableMuon muon,
AlignableExtras extras,
AlignmentParameterStore store 
)
overridevirtual

Call at beginning of job (must be implemented in derived class)

Implements AlignmentAlgorithmBase.

Definition at line 308 of file MuonAlignmentFromReference.cc.

References align::AlignableCSCChamber, align::AlignableDTChamber, AlignmentParameterStore::alignables(), relativeConstraints::chamber, AlignableMuon::CSCChambers(), AlignableMuon::DTChambers(), makeMuonMisalignmentScenario::endcap, Exception, edm::EventSetup::getData(), l1ctLayer2EG_cff::id, MuonResidualsFitter::k0010, MuonResidualsFitter::k1000, MuonResidualsFitter::k1010, MuonResidualsFitter::k1100, MuonResidualsFitter::k1110, MuonResidualsFitter::k1111, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, MuonResidualsFitter::kPureGaussian2D, MuonResidualsFitter::kROOTVoigt, m_alignableNavigator, m_alignables, m_alignmentParameterStore, m_combineME11, m_cscGeometryToken, m_fitterOrder, m_fitters, m_indexes, m_me11map, m_minAlignmentHits, m_reference, m_residualsModel, m_strategy, m_twoBin, m_useResiduals, m_weightAlignment, parseReference(), DetId::rawId(), RecoTauValidation_cfi::reference, align_cfg::residualsModel, AlignmentParameterStore::setAlignmentPositionError(), jetUpdater_cfi::sort, relativeConstraints::station, AlCaHLTBitMon_QueryRunRegistry::string, and align_cfg::useResiduals.

312  {
313  if (alignableMuon == nullptr)
314  throw cms::Exception("MuonAlignmentFromReference") << "doMuon must be set to True" << std::endl;
315 
316  m_alignableNavigator = new AlignableNavigator(alignableMuon);
317  m_alignmentParameterStore = alignmentParameterStore;
319 
320  int residualsModel;
321  if (m_residualsModel == std::string("pureGaussian"))
323  else if (m_residualsModel == std::string("pureGaussian2D"))
325  else if (m_residualsModel == std::string("powerLawTails"))
327  else if (m_residualsModel == std::string("ROOTVoigt"))
329  else if (m_residualsModel == std::string("GaussPowerTails"))
331  else
332  throw cms::Exception("MuonAlignmentFromReference")
333  << "unrecognized residualsModel: \"" << m_residualsModel << "\"" << std::endl;
334 
335  int useResiduals;
336  if (m_useResiduals == std::string("1111"))
338  else if (m_useResiduals == std::string("1110"))
340  else if (m_useResiduals == std::string("1100"))
342  else if (m_useResiduals == std::string("1000"))
344  else if (m_useResiduals == std::string("1010"))
346  else if (m_useResiduals == std::string("0010"))
348  else
349  throw cms::Exception("MuonAlignmentFromReference")
350  << "unrecognized useResiduals: \"" << m_useResiduals << "\"" << std::endl;
351 
352  const CSCGeometry* cscGeometry = &iSetup.getData(m_cscGeometryToken);
353 
354  // set up the MuonResidualsFitters (which also collect residuals for fitting)
355  m_me11map.clear();
356  m_fitters.clear();
357  m_indexes.clear();
358  m_fitterOrder.clear();
359 
360  for (const auto& ali : m_alignables) {
361  bool made_fitter = false;
362 
363  // fitters for DT
364  if (ali->alignableObjectId() == align::AlignableDTChamber) {
365  DTChamberId id(ali->geomDetId().rawId());
366 
367  if (id.station() == 4) {
368  m_fitters[ali] = new MuonResidualsTwoBin(
369  m_twoBin,
372  made_fitter = true;
373  } else {
374  m_fitters[ali] = new MuonResidualsTwoBin(
375  m_twoBin,
378  made_fitter = true;
379  }
380  }
381 
382  // fitters for CSC
383  else if (ali->alignableObjectId() == align::AlignableCSCChamber) {
384  auto thisali = ali;
385  CSCDetId id(ali->geomDetId().rawId());
386 
387  // take care of ME1/1a
388  if (m_combineME11 && id.station() == 1 && id.ring() == 4) {
389  CSCDetId pairid(id.endcap(), 1, 1, id.chamber());
390 
391  for (const auto& ali2 : m_alignables) {
392  if (ali2->alignableObjectId() == align::AlignableCSCChamber && ali2->geomDetId().rawId() == pairid.rawId()) {
393  thisali = ali2;
394  break;
395  }
396  }
397  m_me11map[ali] = thisali; // points from each ME1/4 chamber to the corresponding ME1/1 chamber
398  }
399 
400  if (thisali == ali) // don't make fitters for ME1/4; they get taken care of in ME1/1
401  {
402  m_fitters[ali] = new MuonResidualsTwoBin(
403  m_twoBin,
408  made_fitter = true;
409  }
410  }
411 
412  else {
413  throw cms::Exception("MuonAlignmentFromReference")
414  << "only DTChambers and CSCChambers can be aligned with this module" << std::endl;
415  }
416 
417  if (made_fitter) {
418  m_fitters[ali]->setStrategy(m_strategy);
419 
420  int index = ali->geomDetId().rawId();
421  m_indexes.push_back(index);
422  m_fitterOrder[index] = m_fitters[ali];
423  }
424  } // end loop over chambers chosen for alignment
425 
426  // cannonical order of fitters in the file
427  std::sort(m_indexes.begin(), m_indexes.end());
428 
429  // de-weight all chambers but the reference
430  const auto& all_DT_chambers = alignableMuon->DTChambers();
431  const auto& all_CSC_chambers = alignableMuon->CSCChambers();
433  if (!m_reference.empty())
434  parseReference(reference, all_DT_chambers, all_CSC_chambers);
435 
436  alignmentParameterStore->setAlignmentPositionError(all_DT_chambers, 100000000., 0.);
437  alignmentParameterStore->setAlignmentPositionError(all_CSC_chambers, 100000000., 0.);
438  alignmentParameterStore->setAlignmentPositionError(reference, 0., 0.);
439 }
residualsModel
Definition: align_cfg.py:34
const align::Alignables & alignables(void) const
get all alignables
AlignmentParameterStore * m_alignmentParameterStore
std::vector< unsigned int > m_indexes
void parseReference(align::Alignables &reference, const align::Alignables &all_DT_chambers, const align::Alignables &all_CSC_chambers)
const edm::ESGetToken< CSCGeometry, MuonGeometryRecord > m_cscGeometryToken
std::map< unsigned int, MuonResidualsTwoBin * > m_fitterOrder
std::vector< std::string > m_reference
std::map< Alignable *, MuonResidualsTwoBin * > m_fitters
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
std::map< Alignable *, Alignable * > m_me11map

◆ number()

int MuonAlignmentFromReference::number ( std::string  s)
private

Definition at line 302 of file MuonAlignmentFromReference.cc.

References cms::cuda::assert(), numeric(), and alignCSCRings::s.

Referenced by parseReference().

302  {
303  if (!numeric(s))
304  assert(false);
305  return atoi(s.c_str());
306 }
assert(be >=bs)

◆ numeric()

bool MuonAlignmentFromReference::numeric ( std::string  s)
private

Definition at line 300 of file MuonAlignmentFromReference.cc.

References alignCSCRings::s.

Referenced by number(), and parseReference().

300 { return s.length() == 1 && std::isdigit(s[0]); }

◆ parseReference()

void MuonAlignmentFromReference::parseReference ( align::Alignables reference,
const align::Alignables all_DT_chambers,
const align::Alignables all_CSC_chambers 
)
private

Definition at line 1837 of file MuonAlignmentFromReference.cc.

References funct::abs(), Reference_intrackfit_cff::barrel, relativeConstraints::chamber, makeMuonMisalignmentScenario::endcap, Exception, l1ctLayer2EG_cff::id, m_reference, Skims_PA_cff::name, number(), numeric(), reco::HaloData::plus, RecoTauValidation_cfi::reference, relativeConstraints::ring, hgcalTBTopologyTester_cfi::sector, relativeConstraints::station, AlCaHLTBitMon_QueryRunRegistry::string, dtNoiseDBValidation_cfg::trial, and makeMuonMisalignmentScenario::wheel.

Referenced by initialize().

1839  {
1840  std::map<Alignable*, bool> already_seen;
1841 
1842  for (std::vector<std::string>::const_iterator name = m_reference.begin(); name != m_reference.end(); ++name) {
1843  bool parsing_error = false;
1844 
1845  bool barrel = (name->substr(0, 2) == std::string("MB"));
1846  bool endcap = (name->substr(0, 2) == std::string("ME"));
1847  if (!barrel && !endcap)
1848  parsing_error = true;
1849 
1850  if (!parsing_error && barrel) {
1851  int index = 2;
1852  if (name->substr(index, 1) == std::string(" "))
1853  index++;
1854 
1855  bool plus = true;
1856  if (name->substr(index, 1) == std::string("+")) {
1857  plus = true;
1858  index++;
1859  } else if (name->substr(index, 1) == std::string("-")) {
1860  plus = false;
1861  index++;
1862  } else if (numeric(name->substr(index, 1))) {
1863  } else
1864  parsing_error = true;
1865 
1866  int wheel = 0;
1867  bool wheel_digit = false;
1868  while (!parsing_error && numeric(name->substr(index, 1))) {
1869  wheel *= 10;
1870  wheel += number(name->substr(index, 1));
1871  wheel_digit = true;
1872  index++;
1873  }
1874  if (!plus)
1875  wheel *= -1;
1876  if (!wheel_digit)
1877  parsing_error = true;
1878 
1879  if (name->substr(index, 1) != std::string(" "))
1880  parsing_error = true;
1881  index++;
1882 
1883  int station = 0;
1884  bool station_digit = false;
1885  while (!parsing_error && numeric(name->substr(index, 1))) {
1886  station *= 10;
1887  station += number(name->substr(index, 1));
1888  station_digit = true;
1889  index++;
1890  }
1891  if (!station_digit)
1892  parsing_error = true;
1893 
1894  if (name->substr(index, 1) != std::string(" "))
1895  parsing_error = true;
1896  index++;
1897 
1898  int sector = 0;
1899  bool sector_digit = false;
1900  while (!parsing_error && numeric(name->substr(index, 1))) {
1901  sector *= 10;
1902  sector += number(name->substr(index, 1));
1903  sector_digit = true;
1904  index++;
1905  }
1906  if (!sector_digit)
1907  parsing_error = true;
1908 
1909  if (!parsing_error) {
1910  bool no_such_chamber = false;
1911 
1912  if (wheel < -2 || wheel > 2)
1913  no_such_chamber = true;
1914  if (station < 1 || station > 4)
1915  no_such_chamber = true;
1916  if (station == 4 && (sector < 1 || sector > 14))
1917  no_such_chamber = true;
1918  if (station < 4 && (sector < 1 || sector > 12))
1919  no_such_chamber = true;
1920 
1921  if (no_such_chamber)
1922  throw cms::Exception("MuonAlignmentFromReference")
1923  << "reference chamber doesn't exist: " << (*name) << std::endl;
1924 
1926  for (const auto& ali : all_DT_chambers) {
1927  if (ali->geomDetId().rawId() == id.rawId()) {
1928  std::map<Alignable*, bool>::const_iterator trial = already_seen.find(ali);
1929  if (trial == already_seen.end()) {
1930  reference.push_back(ali);
1931  already_seen[ali] = true;
1932  }
1933  }
1934  }
1935  } // if (!parsing_error)
1936  }
1937 
1938  if (!parsing_error && endcap) {
1939  int index = 2;
1940  if (name->substr(index, 1) == std::string(" "))
1941  index++;
1942 
1943  bool plus = true;
1944  if (name->substr(index, 1) == std::string("+")) {
1945  plus = true;
1946  index++;
1947  } else if (name->substr(index, 1) == std::string("-")) {
1948  plus = false;
1949  index++;
1950  } else if (numeric(name->substr(index, 1))) {
1951  } else
1952  parsing_error = true;
1953 
1954  int station = 0;
1955  bool station_digit = false;
1956  while (!parsing_error && numeric(name->substr(index, 1))) {
1957  station *= 10;
1958  station += number(name->substr(index, 1));
1959  station_digit = true;
1960  index++;
1961  }
1962  if (!plus)
1963  station *= -1;
1964  if (!station_digit)
1965  parsing_error = true;
1966 
1967  if (name->substr(index, 1) != std::string("/"))
1968  parsing_error = true;
1969  index++;
1970 
1971  int ring = 0;
1972  bool ring_digit = false;
1973  while (!parsing_error && numeric(name->substr(index, 1))) {
1974  ring *= 10;
1975  ring += number(name->substr(index, 1));
1976  ring_digit = true;
1977  index++;
1978  }
1979  if (!ring_digit)
1980  parsing_error = true;
1981 
1982  if (name->substr(index, 1) != std::string(" "))
1983  parsing_error = true;
1984  index++;
1985 
1986  int chamber = 0;
1987  bool chamber_digit = false;
1988  while (!parsing_error && numeric(name->substr(index, 1))) {
1989  chamber *= 10;
1990  chamber += number(name->substr(index, 1));
1991  chamber_digit = true;
1992  index++;
1993  }
1994  if (!chamber_digit)
1995  parsing_error = true;
1996 
1997  if (!parsing_error) {
1998  bool no_such_chamber = false;
1999 
2000  int endcap = (station > 0 ? 1 : 2);
2001  station = abs(station);
2002  if (station < 1 || station > 4)
2003  no_such_chamber = true;
2004  if (station == 1 && (ring < 1 || ring > 4))
2005  no_such_chamber = true;
2006  if (station > 1 && (ring < 1 || ring > 2))
2007  no_such_chamber = true;
2008  if (station == 1 && (chamber < 1 || chamber > 36))
2009  no_such_chamber = true;
2010  if (station > 1 && ring == 1 && (chamber < 1 || chamber > 18))
2011  no_such_chamber = true;
2012  if (station > 1 && ring == 2 && (chamber < 1 || chamber > 36))
2013  no_such_chamber = true;
2014 
2015  if (no_such_chamber)
2016  throw cms::Exception("MuonAlignmentFromReference")
2017  << "reference chamber doesn't exist: " << (*name) << std::endl;
2018 
2020  for (const auto& ali : all_CSC_chambers) {
2021  if (ali->geomDetId().rawId() == id.rawId()) {
2022  std::map<Alignable*, bool>::const_iterator trial = already_seen.find(ali);
2023  if (trial == already_seen.end()) {
2024  reference.push_back(ali);
2025  already_seen[ali] = true;
2026  }
2027  }
2028  }
2029  } // if (!parsing_error)
2030  } // endcap
2031 
2032  if (parsing_error)
2033  throw cms::Exception("MuonAlignmentFromReference")
2034  << "reference chamber name is malformed: " << (*name) << std::endl;
2035  }
2036 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< std::string > m_reference

◆ processMuonResidualsFromTrack()

void MuonAlignmentFromReference::processMuonResidualsFromTrack ( MuonResidualsFromTrack mrft)

Definition at line 529 of file MuonAlignmentFromReference.cc.

References cms::cuda::assert(), MuonChamberResidual::chamberAlignable(), MuonResidualsFromTrack::chamberIds(), MuonResidualsFromTrack::chamberResidual(), MuonChamberResidual::Chambl(), MuonChamberResidual::ChambW(), ALCARECOTkAlJpsiMuMu_cff::charge, reco::TrackBase::charge(), MuonChamberResidual::chi2(), MuonResidualsFromTrack::contains_TIDTEC(), gather_cfg::cout, MuonSubdetId::CSC, MuonSubdetId::DT, Alignable::geomDetId(), MuonResidualsFromTrack::getTrack(), l1ctLayer2EG_cff::id, MuonResiduals6DOFrphiFitter::kAngleX, MuonResiduals5DOFFitter::kAngleX, MuonResiduals6DOFFitter::kAngleX, MuonResiduals6DOFrphiFitter::kAngleY, MuonResiduals5DOFFitter::kAngleY, MuonResiduals6DOFFitter::kAngleY, MuonResiduals5DOFFitter::kChambl, MuonResiduals6DOFFitter::kChambl, MuonResiduals5DOFFitter::kChambW, MuonResiduals6DOFFitter::kChambW, MuonResiduals6DOFrphiFitter::kCharge, MuonResiduals5DOFFitter::kCharge, MuonResiduals6DOFFitter::kCharge, MuonChamberResidual::kCSC, MuonChamberResidual::kDT13, MuonChamberResidual::kDT2, MuonResiduals6DOFrphiFitter::kNData, MuonResiduals5DOFFitter::kNData, MuonResiduals6DOFFitter::kNData, MuonResiduals6DOFrphiFitter::kPositionX, MuonResiduals5DOFFitter::kPositionX, MuonResiduals6DOFFitter::kPositionX, MuonResiduals6DOFrphiFitter::kPositionY, MuonResiduals5DOFFitter::kPositionY, MuonResiduals6DOFFitter::kPositionY, MuonResiduals6DOFrphiFitter::kPt, MuonResiduals5DOFFitter::kPt, MuonResiduals6DOFFitter::kPt, MuonResiduals6DOFrphiFitter::kPz, MuonResiduals5DOFFitter::kPz, MuonResiduals6DOFFitter::kPz, MuonResiduals6DOFrphiFitter::kRedChi2, MuonResiduals5DOFFitter::kRedChi2, MuonResiduals6DOFFitter::kRedChi2, MuonResiduals5DOFFitter::kResid, MuonResiduals6DOFrphiFitter::kResid, MuonResiduals6DOFFitter::kResidX, MuonResiduals6DOFFitter::kResidY, MuonResiduals5DOFFitter::kResSlope, MuonResiduals6DOFrphiFitter::kResSlope, MuonResiduals6DOFFitter::kResSlopeX, MuonResiduals6DOFFitter::kResSlopeY, MuonResiduals5DOFFitter::kSector, MuonResiduals6DOFFitter::kSector, MuonResiduals5DOFFitter::kStation, MuonResiduals6DOFFitter::kStation, MuonResiduals5DOFFitter::kWheel, MuonResiduals6DOFFitter::kWheel, m_allowTIDTEC, m_combineME11, m_counter_csc, m_counter_cscaligning, m_counter_cschits, m_counter_cscvalid, m_counter_minchambers, m_counter_resslopey, m_counter_station123, m_counter_station123aligning, m_counter_station123dt13hits, m_counter_station123dt2hits, m_counter_station123valid, m_counter_station4, m_counter_station4aligning, m_counter_station4hits, m_counter_station4valid, m_counter_totchambers, m_counter_trackerchi2, m_counter_trackerhits, m_counter_trackertidtec, m_debug, m_doCSC, m_doDT, m_fitters, m_maxResSlopeY, m_maxTrackerRedChi2, m_me11map, m_minCSCHits, m_minDT13Hits, m_minDT2Hits, m_minNCrossedChambers, m_minTrackerHits, DetId::Muon, MuonChamberResidual::ndof(), MuonResidualsFromTrack::normalizedChi2(), MuonChamberResidual::numHits(), reco::TrackBase::pt(), reco::TrackBase::pz(), DetId::rawId(), MuonChamberResidual::residual(), MuonChamberResidual::resslope(), hgcalTBTopologyTester_cfi::sector, relativeConstraints::station, MuonChamberResidual::trackdxdz(), MuonChamberResidual::trackdydz(), MuonResidualsFromTrack::trackerNumHits(), MuonChamberResidual::trackx(), MuonChamberResidual::tracky(), and makeMuonMisalignmentScenario::wheel.

Referenced by run().

529  {
530  // std::cout << "minTrackerHits: " << mrft.trackerNumHits() << std::endl;
531  if (mrft.trackerNumHits() >= m_minTrackerHits) {
533  // std::cout << "mrft.normalizedChi2(): " << mrft.normalizedChi2() << std::endl;
534 
535  if (mrft.normalizedChi2() < m_maxTrackerRedChi2) {
537  if (m_allowTIDTEC || !mrft.contains_TIDTEC()) {
539 
540  std::vector<DetId> chamberIds = mrft.chamberIds();
541 
542  if ((int)chamberIds.size() >= m_minNCrossedChambers) {
544 
545  char charge = (mrft.getTrack()->charge() > 0 ? 1 : -1);
546 
547  for (std::vector<DetId>::const_iterator chamberId = chamberIds.begin(); chamberId != chamberIds.end();
548  ++chamberId) {
549  if (chamberId->det() != DetId::Muon)
550  continue;
552 
553  // DT station 1,2,3
554  if (m_doDT && chamberId->subdetId() == MuonSubdetId::DT && DTChamberId(chamberId->rawId()).station() != 4) {
557 
559  if (dt13 != nullptr && dt2 != nullptr) {
561  if (dt13->numHits() >= m_minDT13Hits) {
563  if (dt2->numHits() >= m_minDT2Hits) {
565  std::map<Alignable*, MuonResidualsTwoBin*>::const_iterator fitter =
566  m_fitters.find(dt13->chamberAlignable());
567  if (fitter != m_fitters.end()) {
569  if (fabs(dt2->resslope()) < m_maxResSlopeY && (dt2->chi2() / double(dt2->ndof())) < 2.0) {
571  double* residdata = new double[MuonResiduals6DOFFitter::kNData];
572  residdata[MuonResiduals6DOFFitter::kResidX] = dt13->residual();
573  residdata[MuonResiduals6DOFFitter::kResidY] = dt2->residual();
574  residdata[MuonResiduals6DOFFitter::kResSlopeX] = dt13->resslope();
575  residdata[MuonResiduals6DOFFitter::kResSlopeY] = dt2->resslope();
576  residdata[MuonResiduals6DOFFitter::kPositionX] = dt13->trackx();
577  residdata[MuonResiduals6DOFFitter::kPositionY] = dt13->tracky();
578  residdata[MuonResiduals6DOFFitter::kAngleX] = dt13->trackdxdz();
579  residdata[MuonResiduals6DOFFitter::kAngleY] = dt13->trackdydz();
581  (dt13->chi2() + dt2->chi2()) / double(dt13->ndof() + dt2->ndof());
582  residdata[MuonResiduals6DOFFitter::kPz] = mrft.getTrack()->pz();
583  residdata[MuonResiduals6DOFFitter::kPt] = mrft.getTrack()->pt();
584  residdata[MuonResiduals6DOFFitter::kCharge] = mrft.getTrack()->charge();
585  residdata[MuonResiduals6DOFFitter::kStation] = DTChamberId(chamberId->rawId()).station();
586  residdata[MuonResiduals6DOFFitter::kWheel] = DTChamberId(chamberId->rawId()).wheel();
587  residdata[MuonResiduals6DOFFitter::kSector] = DTChamberId(chamberId->rawId()).sector();
588  residdata[MuonResiduals6DOFFitter::kChambW] = dt13->ChambW();
589  residdata[MuonResiduals6DOFFitter::kChambl] = dt13->Chambl();
590 
591  if (m_debug) {
592  std::cout << "processMuonResidualsFromTrack 6DOF dt13->residual() " << dt13->residual()
593  << std::endl;
594  std::cout << " dt2->residual() " << dt2->residual()
595  << std::endl;
596  std::cout << " dt13->resslope() " << dt13->resslope()
597  << std::endl;
598  std::cout << " dt2->resslope() " << dt2->resslope()
599  << std::endl;
600  std::cout << " dt13->trackx() " << dt13->trackx()
601  << std::endl;
602  std::cout << " dt13->tracky() " << dt13->tracky()
603  << std::endl;
604  std::cout << " dt13->trackdxdz() " << dt13->trackdxdz()
605  << std::endl;
606  std::cout << " dt13->trackdydz() " << dt13->trackdydz()
607  << std::endl;
608  }
609 
610  fitter->second->fill(charge, residdata);
611  // the MuonResidualsFitter will delete the array when it is destroyed
612  }
613  }
614  }
615  }
616  }
617  }
618 
619  // DT 4th station
620  else if (m_doDT && chamberId->subdetId() == MuonSubdetId::DT &&
621  DTChamberId(chamberId->rawId()).station() == 4) {
623 
625  if (dt13 != nullptr) {
627  if (dt13->numHits() >= m_minDT13Hits) {
629 
630  std::map<Alignable*, MuonResidualsTwoBin*>::const_iterator fitter =
631  m_fitters.find(dt13->chamberAlignable());
632  if (fitter != m_fitters.end()) {
634 
635  double* residdata = new double[MuonResiduals5DOFFitter::kNData];
636  residdata[MuonResiduals5DOFFitter::kResid] = dt13->residual();
637  residdata[MuonResiduals5DOFFitter::kResSlope] = dt13->resslope();
638  residdata[MuonResiduals5DOFFitter::kPositionX] = dt13->trackx();
639  residdata[MuonResiduals5DOFFitter::kPositionY] = dt13->tracky();
640  residdata[MuonResiduals5DOFFitter::kAngleX] = dt13->trackdxdz();
641  residdata[MuonResiduals5DOFFitter::kAngleY] = dt13->trackdydz();
642  residdata[MuonResiduals5DOFFitter::kRedChi2] = dt13->chi2() / double(dt13->ndof());
643  residdata[MuonResiduals5DOFFitter::kPz] = mrft.getTrack()->pz();
644  residdata[MuonResiduals5DOFFitter::kPt] = mrft.getTrack()->pt();
645  residdata[MuonResiduals5DOFFitter::kCharge] = mrft.getTrack()->charge();
646  residdata[MuonResiduals5DOFFitter::kStation] = DTChamberId(chamberId->rawId()).station();
647  residdata[MuonResiduals5DOFFitter::kWheel] = DTChamberId(chamberId->rawId()).wheel();
648  residdata[MuonResiduals5DOFFitter::kSector] = DTChamberId(chamberId->rawId()).sector();
649  residdata[MuonResiduals5DOFFitter::kChambW] = dt13->ChambW();
650  residdata[MuonResiduals5DOFFitter::kChambl] = dt13->Chambl();
651 
652  if (m_debug) {
653  std::cout << "processMuonResidualsFromTrack 5DOF dt13->residual() " << dt13->residual()
654  << std::endl;
655  std::cout << " dt13->resslope() " << dt13->resslope()
656  << std::endl;
657  std::cout << " dt13->trackx() " << dt13->trackx()
658  << std::endl;
659  std::cout << " dt13->tracky() " << dt13->tracky()
660  << std::endl;
661  std::cout << " dt13->trackdxdz() " << dt13->trackdxdz()
662  << std::endl;
663  std::cout << " dt13->trackdydz() " << dt13->trackdydz()
664  << std::endl;
665  }
666 
667  fitter->second->fill(charge, residdata);
668  // the MuonResidualsFitter will delete the array when it is destroyed
669  }
670  }
671  }
672  } // end DT 4th station
673 
674  // CSC
675  else if (m_doCSC && chamberId->subdetId() == MuonSubdetId::CSC) {
677  m_counter_csc++;
678  if (csc != nullptr) {
680  if (csc->numHits() >= m_minCSCHits) {
682  Alignable* ali = csc->chamberAlignable();
683 
684  CSCDetId id(ali->geomDetId().rawId());
685  if (m_combineME11 && id.station() == 1 && id.ring() == 4)
686  ali = m_me11map[ali];
687 
688  std::map<Alignable*, MuonResidualsTwoBin*>::const_iterator fitter = m_fitters.find(ali);
689  if (fitter != m_fitters.end()) {
691  double* residdata = new double[MuonResiduals6DOFrphiFitter::kNData];
692  residdata[MuonResiduals6DOFrphiFitter::kResid] = csc->residual();
693  residdata[MuonResiduals6DOFrphiFitter::kResSlope] = csc->resslope();
694  residdata[MuonResiduals6DOFrphiFitter::kPositionX] = csc->trackx();
695  residdata[MuonResiduals6DOFrphiFitter::kPositionY] = csc->tracky();
696  residdata[MuonResiduals6DOFrphiFitter::kAngleX] = csc->trackdxdz();
697  residdata[MuonResiduals6DOFrphiFitter::kAngleY] = csc->trackdydz();
698  residdata[MuonResiduals6DOFrphiFitter::kRedChi2] = csc->chi2() / double(csc->ndof());
699  residdata[MuonResiduals6DOFrphiFitter::kPz] = mrft.getTrack()->pz();
700  residdata[MuonResiduals6DOFrphiFitter::kPt] = mrft.getTrack()->pt();
702 
703  if (m_debug) {
704  std::cout << "processMuonResidualsFromTrack 6DOFrphi csc->residual() " << csc->residual()
705  << std::endl;
706  std::cout << " csc->resslope() " << csc->resslope()
707  << std::endl;
708  std::cout << " csc->trackx() " << csc->trackx()
709  << std::endl;
710  std::cout << " csc->tracky() " << csc->tracky()
711  << std::endl;
712  std::cout << " csc->trackdxdz() " << csc->trackdxdz()
713  << std::endl;
714  std::cout << " csc->trackdydz() " << csc->trackdydz()
715  << std::endl;
716  }
717 
718  fitter->second->fill(charge, residdata);
719  // the MuonResidualsFitter will delete the array when it is destroyed
720  }
721  }
722  }
723  } // end CSC
724 
725  else if (m_doDT && m_doCSC)
726  assert(false);
727 
728  } // end loop over chamberIds
729  } // # crossed muon chambers ok
730  } // endcap tracker ok
731  } // chi2 ok
732  } // trackerNumHits ok
733 }
double trackdydz() const
assert(be >=bs)
double pt() const
track transverse momentum
Definition: TrackBase.h:637
int charge() const
track electric charge
Definition: TrackBase.h:596
const reco::Track * getTrack()
std::map< Alignable *, MuonResidualsTwoBin * > m_fitters
Definition: L1Track.h:19
const std::vector< DetId > chamberIds() const
const DetId & geomDetId() const
Definition: Alignable.h:177
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:646
std::map< Alignable *, Alignable * > m_me11map
AlignableDetOrUnitPtr chamberAlignable() const
static constexpr int DT
Definition: MuonSubdetId.h:11
static constexpr int CSC
Definition: MuonSubdetId.h:12
double trackdxdz() const
MuonChamberResidual * chamberResidual(DetId chamberId, int type)

◆ readTmpFiles()

void MuonAlignmentFromReference::readTmpFiles ( )
private

Definition at line 1607 of file MuonAlignmentFromReference.cc.

References Exception, geometryDiff::file, MillePedeFileConverter_cfg::fileName, mps_fire::i, m_fitterOrder, m_indexes, m_readTemporaryFiles, MuonResidualsTwoBin::read(), and findQualityFiles::size.

Referenced by terminate().

1607  {
1608  for (std::vector<std::string>::const_iterator fileName = m_readTemporaryFiles.begin();
1609  fileName != m_readTemporaryFiles.end();
1610  ++fileName) {
1611  FILE* file;
1612  int size;
1613  file = fopen((*fileName).c_str(), "r");
1614  if (file == nullptr)
1615  throw cms::Exception("MuonAlignmentFromReference")
1616  << "file \"" << *fileName << "\" can't be opened (doesn't exist?)" << std::endl;
1617 
1618  fread(&size, sizeof(int), 1, file);
1619  if (int(m_indexes.size()) != size)
1620  throw cms::Exception("MuonAlignmentFromReference")
1621  << "file \"" << *fileName << "\" has " << size << " fitters, but this job has " << m_indexes.size()
1622  << " fitters (probably corresponds to the wrong alignment job)" << std::endl;
1623 
1624  int i = 0;
1625  for (std::vector<unsigned int>::const_iterator index = m_indexes.begin(); index != m_indexes.end(); ++index, ++i) {
1627  unsigned int index_toread;
1628  fread(&index_toread, sizeof(unsigned int), 1, file);
1629  if (*index != index_toread)
1630  throw cms::Exception("MuonAlignmentFromReference")
1631  << "file \"" << *fileName << "\" has index " << index_toread << " at position " << i
1632  << ", but this job is expecting " << *index << " (probably corresponds to the wrong alignment job)"
1633  << std::endl;
1634  fitter->read(file, i);
1635  }
1636 
1637  fclose(file);
1638  }
1639 }
size
Write out results.
std::vector< unsigned int > m_indexes
std::map< unsigned int, MuonResidualsTwoBin * > m_fitterOrder
void read(FILE *file, int which=0)
std::vector< std::string > m_readTemporaryFiles

◆ run()

void MuonAlignmentFromReference::run ( const edm::EventSetup setup,
const EventInfo eventInfo 
)
overridevirtual

Run the algorithm (must be implemented in derived class)

Implements AlignmentAlgorithmBase.

Definition at line 441 of file MuonAlignmentFromReference.cc.

References gather_cfg::cout, dumpTauVariables_cfi::eventInfo, edm::EventSetup::getData(), edm::EventSetup::getHandle(), edm::InputTag::label(), m_alignableNavigator, m_builderToken, m_counter_events, m_counter_trackdxy, m_counter_trackmomentum, m_counter_tracks, m_debug, m_DetIdToken, m_globTackingToken, m_MagFieldToken, m_maxDxy, m_maxTrackP, m_maxTrackPt, m_minTrackP, m_muonCollectionTag, m_propToken, HLT_2023v12_cff::magneticField, HLT_2023v12_cff::muonDetIdAssociator, processMuonResidualsFromTrack(), DiDispStaMuonMonitor_cfi::pt, and HLT_2023v12_cff::track.

Referenced by DTWorkflow.DTWorkflow::all(), Types.EventID::cppID(), Types.LuminosityBlockID::cppID(), and o2olib.O2OTool::execute().

441  {
442  if (m_debug)
443  std::cout << "****** EVENT START *******" << std::endl;
445 
446  const GlobalTrackingGeometry* globalGeometry = &iSetup.getData(m_globTackingToken);
447  const MagneticField* magneticField = &iSetup.getData(m_MagFieldToken);
448  const Propagator* prop = &iSetup.getData(m_propToken);
449  const DetIdAssociator* muonDetIdAssociator = &iSetup.getData(m_DetIdToken);
450  auto builder = iSetup.getHandle(m_builderToken);
451 
452  if (m_muonCollectionTag.label().empty()) // use trajectories
453  {
454  if (m_debug)
455  std::cout << "JUST BEFORE LOOP OVER trajTrackPairs" << std::endl;
456  // const ConstTrajTrackPairCollection &trajtracks = eventInfo.trajTrackPairs_; // trajTrackPairs_ now private
457  const ConstTrajTrackPairCollection& trajtracks = eventInfo.trajTrackPairs();
458 
459  for (ConstTrajTrackPairCollection::const_iterator trajtrack = trajtracks.begin(); trajtrack != trajtracks.end();
460  ++trajtrack) {
462 
463  const Trajectory* traj = (*trajtrack).first;
464  const reco::Track* track = (*trajtrack).second;
465 
466  if (m_minTrackPt < track->pt() && track->pt() < m_maxTrackPt && m_minTrackP < track->p() &&
467  track->p() < m_maxTrackP) {
469 
470  if (fabs(track->dxy(eventInfo.beamSpot().position())) < m_maxDxy) {
472  if (m_debug)
473  std::cout << "JUST BEFORE muonResidualsFromTrack" << std::endl;
474  MuonResidualsFromTrack muonResidualsFromTrack(builder,
476  globalGeometry,
478  prop,
479  traj,
480  track,
482  1000.);
483  if (m_debug)
484  std::cout << "JUST AFTER muonResidualsFromTrack" << std::endl;
485 
486  if (m_debug)
487  std::cout << "JUST BEFORE PROCESS" << std::endl;
488  processMuonResidualsFromTrack(muonResidualsFromTrack);
489  if (m_debug)
490  std::cout << "JUST AFTER PROCESS" << std::endl;
491  }
492  } // end if track p is within range
493  } // end if track pT is within range
494  if (m_debug)
495  std::cout << "JUST AFTER LOOP OVER trajTrackPairs" << std::endl;
496 
497  } else // use muons
498  {
499  /*
500  for (reco::MuonCollection::const_iterator muon = eventInfo.muonCollection_->begin(); muon != eventInfo.muonCollection_->end(); ++muon)
501  {
502  if ( !(muon->isTrackerMuon() && muon->innerTrack().isNonnull() ) ) continue;
503 
504  m_counter_tracks++;
505 
506  if (m_minTrackPt < muon->pt() && muon->pt() < m_maxTrackPt && m_minTrackP < muon->p() && muon->p() < m_maxTrackP)
507  {
508  m_counter_trackmomentum++;
509 
510  if (fabs(muon->innerTrack()->dxy(eventInfo.beamSpot_.position())) < m_maxDxy)
511  {
512  m_counter_trackdxy++;
513 
514  //std::cout<<" *** will make MuonResidualsFromTrack ***"<<std::endl;
515  MuonResidualsFromTrack muonResidualsFromTrack(globalGeometry, &(*muon), m_alignableNavigator, 100.);
516  //std::cout<<" *** have made MuonResidualsFromTrack ***"<<std::endl;
517 
518  //std::cout<<" trk eta="<<muon->eta()<<" ndof="<<muon->innerTrack()->ndof()<<" nchi2="<<muon->innerTrack()->normalizedChi2()
519  // <<" muresnchi2="<<muonResidualsFromTrack.normalizedChi2()<<" muresnhits="<<muonResidualsFromTrack.trackerNumHits()<<std::endl;
520 
521  processMuonResidualsFromTrack(muonResidualsFromTrack);
522  } // end if track p is within range
523  } // end if track pT is within range
524  } // end loop over tracks
525  */
526  }
527 }
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > m_MagFieldToken
const edm::ESGetToken< DetIdAssociator, DetIdAssociatorRecord > m_DetIdToken
std::string const & label() const
Definition: InputTag.h:36
void processMuonResidualsFromTrack(MuonResidualsFromTrack &mrft)
const MuonResidualsFromTrack::BuilderToken m_builderToken
const edm::ESGetToken< Propagator, TrackingComponentsRecord > m_propToken
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > m_globTackingToken
eventInfo
add run, event number and lumi section
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection

◆ selectResidualsPeaks()

void MuonAlignmentFromReference::selectResidualsPeaks ( )
private

Definition at line 1687 of file MuonAlignmentFromReference.cc.

References cms::cuda::assert(), chamberPrettyNameFromId(), gather_cfg::cout, MuonResidualsFitter::k0010, MuonResidualsFitter::k1010, MuonResidualsFitter::k1100, MuonResidualsFitter::k1110, MuonResidualsFitter::k1111, MuonResidualsFitter::k5DOF, MuonResidualsFitter::k6DOF, MuonResidualsFitter::k6DOFrphi, MuonResiduals5DOFFitter::kResid, MuonResiduals6DOFrphiFitter::kResid, MuonResiduals6DOFFitter::kResidX, MuonResiduals6DOFFitter::kResidY, MuonResiduals6DOFrphiFitter::kResSlope, MuonResiduals5DOFFitter::kResSlope, MuonResiduals6DOFFitter::kResSlopeX, MuonResiduals6DOFFitter::kResSlopeY, m_debug, m_fitterOrder, m_indexes, m_peakNSigma, MuonResidualsTwoBin::selectPeakResiduals(), MuonResidualsTwoBin::type(), and MuonResidualsTwoBin::useRes().

Referenced by terminate().

1687  {
1688  // should not be called with negative peakNSigma
1689  assert(m_peakNSigma > 0.);
1690 
1691  for (std::vector<unsigned int>::const_iterator index = m_indexes.begin(); index != m_indexes.end(); ++index) {
1693 
1694  int nvar = 2;
1695  int vars_index[10] = {0, 1};
1696  if (fitter->type() == MuonResidualsFitter::k5DOF) {
1697  if (fitter->useRes() == MuonResidualsFitter::k1111 || fitter->useRes() == MuonResidualsFitter::k1110 ||
1698  fitter->useRes() == MuonResidualsFitter::k1010) {
1699  nvar = 2;
1700  vars_index[0] = MuonResiduals5DOFFitter::kResid;
1701  vars_index[1] = MuonResiduals5DOFFitter::kResSlope;
1702  } else if (fitter->useRes() == MuonResidualsFitter::k1100) {
1703  nvar = 1;
1704  vars_index[0] = MuonResiduals5DOFFitter::kResid;
1705  } else if (fitter->useRes() == MuonResidualsFitter::k0010) {
1706  nvar = 1;
1707  vars_index[0] = MuonResiduals5DOFFitter::kResSlope;
1708  }
1709  } else if (fitter->type() == MuonResidualsFitter::k6DOF) {
1710  if (fitter->useRes() == MuonResidualsFitter::k1111) {
1711  nvar = 4;
1712  vars_index[0] = MuonResiduals6DOFFitter::kResidX;
1713  vars_index[1] = MuonResiduals6DOFFitter::kResidY;
1714  vars_index[2] = MuonResiduals6DOFFitter::kResSlopeX;
1715  vars_index[3] = MuonResiduals6DOFFitter::kResSlopeY;
1716  } else if (fitter->useRes() == MuonResidualsFitter::k1110) {
1717  nvar = 3;
1718  vars_index[0] = MuonResiduals6DOFFitter::kResidX;
1719  vars_index[1] = MuonResiduals6DOFFitter::kResidY;
1720  vars_index[2] = MuonResiduals6DOFFitter::kResSlopeX;
1721  } else if (fitter->useRes() == MuonResidualsFitter::k1010) {
1722  nvar = 2;
1723  vars_index[0] = MuonResiduals6DOFFitter::kResidX;
1724  vars_index[2] = MuonResiduals6DOFFitter::kResSlopeX;
1725  } else if (fitter->useRes() == MuonResidualsFitter::k1100) {
1726  nvar = 2;
1727  vars_index[0] = MuonResiduals6DOFFitter::kResidX;
1728  vars_index[1] = MuonResiduals6DOFFitter::kResidY;
1729  } else if (fitter->useRes() == MuonResidualsFitter::k0010) {
1730  nvar = 1;
1731  vars_index[0] = MuonResiduals6DOFFitter::kResSlopeX;
1732  }
1733  } else if (fitter->type() == MuonResidualsFitter::k6DOFrphi) {
1734  if (fitter->useRes() == MuonResidualsFitter::k1111 || fitter->useRes() == MuonResidualsFitter::k1110 ||
1735  fitter->useRes() == MuonResidualsFitter::k1010) {
1736  nvar = 2;
1737  vars_index[0] = MuonResiduals6DOFrphiFitter::kResid;
1739  } else if (fitter->useRes() == MuonResidualsFitter::k1100) {
1740  nvar = 1;
1741  vars_index[0] = MuonResiduals6DOFrphiFitter::kResid;
1742  } else if (fitter->useRes() == MuonResidualsFitter::k0010) {
1743  nvar = 1;
1745  }
1746  } else
1747  assert(false);
1748 
1749  if (m_debug)
1750  std::cout << "selecting in " << chamberPrettyNameFromId(*index) << std::endl;
1751 
1752  fitter->selectPeakResiduals(m_peakNSigma, nvar, vars_index);
1753  }
1754 }
assert(be >=bs)
std::vector< unsigned int > m_indexes
std::string chamberPrettyNameFromId(unsigned int idx)
std::map< unsigned int, MuonResidualsTwoBin * > m_fitterOrder
void selectPeakResiduals(double nsigma, int nvar, int *vars)

◆ startNewLoop()

void MuonAlignmentFromReference::startNewLoop ( void  )
inlineoverridevirtual

Called at start of loop, default implementation is dummy for non-iterative algorithms

Reimplemented from AlignmentAlgorithmBase.

Definition at line 85 of file MuonAlignmentFromReference.cc.

85 {};

◆ terminate()

void MuonAlignmentFromReference::terminate ( const edm::EventSetup iSetup)
overridevirtual

Call at end of each loop (must be implemented in derived class)

Implements AlignmentAlgorithmBase.

Definition at line 735 of file MuonAlignmentFromReference.cc.

References correctBField(), gather_cfg::cout, eraseNotSelectedResiduals(), fiducialCuts(), fillNtuple(), fitAndAlign(), m_BFieldCorrection, m_counter_csc, m_counter_cscaligning, m_counter_cschits, m_counter_cscvalid, m_counter_events, m_counter_minchambers, m_counter_resslopey, m_counter_station123, m_counter_station123aligning, m_counter_station123dt13hits, m_counter_station123dt2hits, m_counter_station123valid, m_counter_station4, m_counter_station4aligning, m_counter_station4hits, m_counter_station4valid, m_counter_totchambers, m_counter_trackdxy, m_counter_trackerchi2, m_counter_trackerhits, m_counter_trackertidtec, m_counter_trackmomentum, m_counter_tracks, m_createNtuple, m_debug, m_doAlignment, m_doCSC, m_peakNSigma, m_readTemporaryFiles, m_writeTemporaryFile, readTmpFiles(), selectResidualsPeaks(), AlCaHLTBitMon_QueryRunRegistry::string, and writeTmpFiles().

735  {
736  bool m_debug = false;
737 
738  // one-time print-out
739  std::cout << "Counters:" << std::endl
740  << "COUNT{ events: " << m_counter_events << " }" << std::endl
741  << "COUNT{ tracks: " << m_counter_tracks << " }" << std::endl
742  << "COUNT{ trackppt: " << m_counter_trackmomentum << " }" << std::endl
743  << "COUNT{ trackdxy: " << m_counter_trackdxy << " }" << std::endl
744  << "COUNT{ trackerhits: " << m_counter_trackerhits << " }" << std::endl
745  << "COUNT{ trackerchi2: " << m_counter_trackerchi2 << " }" << std::endl
746  << "COUNT{ trackertidtec: " << m_counter_trackertidtec << " }" << std::endl
747  << "COUNT{ minnchambers: " << m_counter_minchambers << " }" << std::endl
748  << "COUNT{ totchambers: " << m_counter_totchambers << " }" << std::endl
749  << "COUNT{ station123: " << m_counter_station123 << " }" << std::endl
750  << "COUNT{ station123valid: " << m_counter_station123valid << " }" << std::endl
751  << "COUNT{ station123dt13hits: " << m_counter_station123dt13hits << " }" << std::endl
752  << "COUNT{ station123dt2hits: " << m_counter_station123dt2hits << " }" << std::endl
753  << "COUNT{ station123aligning: " << m_counter_station123aligning << " }" << std::endl
754  << "COUNT{ resslopey: " << m_counter_resslopey << " }" << std::endl
755  << "COUNT{ station4: " << m_counter_station4 << " }" << std::endl
756  << "COUNT{ station4valid: " << m_counter_station4valid << " }" << std::endl
757  << "COUNT{ station4hits: " << m_counter_station4hits << " }" << std::endl
758  << "COUNT{ station4aligning: " << m_counter_station4aligning << " }" << std::endl
759  << "COUNT{ csc: " << m_counter_csc << " }" << std::endl
760  << "COUNT{ cscvalid: " << m_counter_cscvalid << " }" << std::endl
761  << "COUNT{ cschits: " << m_counter_cschits << " }" << std::endl
762  << "COUNT{ cscaligning: " << m_counter_cscaligning << " }" << std::endl
763  << "That's all!" << std::endl;
764 
765  TStopwatch stop_watch;
766 
767  // collect temporary files
768  if (!m_readTemporaryFiles.empty()) {
769  stop_watch.Start();
770  readTmpFiles();
771  if (m_debug)
772  std::cout << "readTmpFiles took " << stop_watch.CpuTime() << " sec" << std::endl;
773  stop_watch.Stop();
774  }
775 
776  // select residuals peaks and discard tails if peakNSigma>0 (only while doing alignment)
777  if (m_peakNSigma > 0. && m_doAlignment) {
778  stop_watch.Start();
780  if (m_debug)
781  std::cout << "selectResidualsPeaks took " << stop_watch.CpuTime() << " sec" << std::endl;
782  stop_watch.Stop();
783  }
784 
785  if (m_BFieldCorrection > 0 && m_doAlignment) {
786  stop_watch.Start();
787  correctBField();
788  if (m_debug)
789  std::cout << "correctBField took " << stop_watch.CpuTime() << " sec" << std::endl;
790  stop_watch.Stop();
791  }
792 
793  if (m_doAlignment && !m_doCSC) // for now apply fiducial cuts to DT only
794  {
795  stop_watch.Start();
796  fiducialCuts();
797  if (m_debug)
798  std::cout << "fiducialCuts took " << stop_watch.CpuTime() << " sec" << std::endl;
799  stop_watch.Stop();
800  }
801 
802  // optionally, create an nutuple for easy debugging
803  if (m_createNtuple) {
804  stop_watch.Start();
805  fillNtuple();
806  if (m_debug)
807  std::cout << "fillNtuple took " << stop_watch.CpuTime() << " sec" << std::endl;
808  stop_watch.Stop();
809  }
810 
811  if (m_doAlignment) {
812  stop_watch.Start();
814  if (m_debug)
815  std::cout << "eraseNotSelectedResiduals took " << stop_watch.CpuTime() << " sec" << std::endl;
816  stop_watch.Stop();
817  }
818 
819  // fit and align (time-consuming, so the user can turn it off if in a residuals-gathering job)
820  if (m_doAlignment) {
821  stop_watch.Start();
822  fitAndAlign();
823  if (m_debug)
824  std::cout << "fitAndAlign took " << stop_watch.CpuTime() << " sec" << std::endl;
825  stop_watch.Stop();
826  }
827 
828  // write out the pseudontuples for a later job to collect
830  writeTmpFiles();
831  if (m_debug)
832  std::cout << "end: MuonAlignmentFromReference::terminate()" << std::endl;
833 }
std::vector< std::string > m_readTemporaryFiles

◆ writeTmpFiles()

void MuonAlignmentFromReference::writeTmpFiles ( )
private

Definition at line 1641 of file MuonAlignmentFromReference.cc.

References geometryDiff::file, mps_fire::i, m_fitterOrder, m_indexes, m_writeTemporaryFile, findQualityFiles::size, and MuonResidualsTwoBin::write().

Referenced by terminate().

1641  {
1642  FILE* file;
1643  file = fopen(m_writeTemporaryFile.c_str(), "w");
1644  int size = m_indexes.size();
1645  fwrite(&size, sizeof(int), 1, file);
1646 
1647  int i = 0;
1648  for (std::vector<unsigned int>::const_iterator index = m_indexes.begin(); index != m_indexes.end(); ++index, ++i) {
1650  unsigned int index_towrite = *index;
1651  fwrite(&index_towrite, sizeof(unsigned int), 1, file);
1652  fitter->write(file, i);
1653  }
1654 
1655  fclose(file);
1656 }
size
Write out results.
std::vector< unsigned int > m_indexes
void write(FILE *file, int which=0)
std::map< unsigned int, MuonResidualsTwoBin * > m_fitterOrder

Member Data Documentation

◆ m_alignableNavigator

AlignableNavigator* MuonAlignmentFromReference::m_alignableNavigator
private

Definition at line 155 of file MuonAlignmentFromReference.cc.

Referenced by initialize(), run(), and ~MuonAlignmentFromReference().

◆ m_alignables

align::Alignables MuonAlignmentFromReference::m_alignables
private

Definition at line 157 of file MuonAlignmentFromReference.cc.

Referenced by fitAndAlign(), and initialize().

◆ m_alignmentParameterStore

AlignmentParameterStore* MuonAlignmentFromReference::m_alignmentParameterStore
private

Definition at line 156 of file MuonAlignmentFromReference.cc.

Referenced by fitAndAlign(), and initialize().

◆ m_allowTIDTEC

bool MuonAlignmentFromReference::m_allowTIDTEC
private

Definition at line 131 of file MuonAlignmentFromReference.cc.

Referenced by processMuonResidualsFromTrack().

◆ m_BFieldCorrection

int MuonAlignmentFromReference::m_BFieldCorrection
private

Definition at line 149 of file MuonAlignmentFromReference.cc.

Referenced by terminate().

◆ m_builderToken

const MuonResidualsFromTrack::BuilderToken MuonAlignmentFromReference::m_builderToken
private

Definition at line 119 of file MuonAlignmentFromReference.cc.

Referenced by run().

◆ m_combineME11

bool MuonAlignmentFromReference::m_combineME11
private

◆ m_counter_csc

long MuonAlignmentFromReference::m_counter_csc
private

◆ m_counter_cscaligning

long MuonAlignmentFromReference::m_counter_cscaligning
private

◆ m_counter_cschits

long MuonAlignmentFromReference::m_counter_cschits
private

◆ m_counter_cscvalid

long MuonAlignmentFromReference::m_counter_cscvalid
private

◆ m_counter_events

long MuonAlignmentFromReference::m_counter_events
private

Definition at line 164 of file MuonAlignmentFromReference.cc.

Referenced by MuonAlignmentFromReference(), run(), and terminate().

◆ m_counter_minchambers

long MuonAlignmentFromReference::m_counter_minchambers
private

◆ m_counter_resslopey

long MuonAlignmentFromReference::m_counter_resslopey
private

◆ m_counter_station123

long MuonAlignmentFromReference::m_counter_station123
private

◆ m_counter_station123aligning

long MuonAlignmentFromReference::m_counter_station123aligning
private

◆ m_counter_station123dt13hits

long MuonAlignmentFromReference::m_counter_station123dt13hits
private

◆ m_counter_station123dt2hits

long MuonAlignmentFromReference::m_counter_station123dt2hits
private

◆ m_counter_station123valid

long MuonAlignmentFromReference::m_counter_station123valid
private

◆ m_counter_station4

long MuonAlignmentFromReference::m_counter_station4
private

◆ m_counter_station4aligning

long MuonAlignmentFromReference::m_counter_station4aligning
private

◆ m_counter_station4hits

long MuonAlignmentFromReference::m_counter_station4hits
private

◆ m_counter_station4valid

long MuonAlignmentFromReference::m_counter_station4valid
private

◆ m_counter_totchambers

long MuonAlignmentFromReference::m_counter_totchambers
private

◆ m_counter_trackdxy

long MuonAlignmentFromReference::m_counter_trackdxy
private

Definition at line 167 of file MuonAlignmentFromReference.cc.

Referenced by MuonAlignmentFromReference(), run(), and terminate().

◆ m_counter_trackerchi2

long MuonAlignmentFromReference::m_counter_trackerchi2
private

◆ m_counter_trackerhits

long MuonAlignmentFromReference::m_counter_trackerhits
private

◆ m_counter_trackertidtec

long MuonAlignmentFromReference::m_counter_trackertidtec
private

◆ m_counter_trackmomentum

long MuonAlignmentFromReference::m_counter_trackmomentum
private

Definition at line 166 of file MuonAlignmentFromReference.cc.

Referenced by MuonAlignmentFromReference(), run(), and terminate().

◆ m_counter_tracks

long MuonAlignmentFromReference::m_counter_tracks
private

Definition at line 165 of file MuonAlignmentFromReference.cc.

Referenced by MuonAlignmentFromReference(), run(), and terminate().

◆ m_createNtuple

bool MuonAlignmentFromReference::m_createNtuple
private

Definition at line 147 of file MuonAlignmentFromReference.cc.

Referenced by MuonAlignmentFromReference(), and terminate().

◆ m_cscGeometryToken

const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> MuonAlignmentFromReference::m_cscGeometryToken
private

Definition at line 114 of file MuonAlignmentFromReference.cc.

Referenced by initialize().

◆ m_debug

bool MuonAlignmentFromReference::m_debug
private

◆ m_DetIdToken

const edm::ESGetToken<DetIdAssociator, DetIdAssociatorRecord> MuonAlignmentFromReference::m_DetIdToken
private

Definition at line 118 of file MuonAlignmentFromReference.cc.

Referenced by run().

◆ m_doAlignment

bool MuonAlignmentFromReference::m_doAlignment
private

Definition at line 138 of file MuonAlignmentFromReference.cc.

Referenced by MuonAlignmentFromReference(), and terminate().

◆ m_doCSC

bool MuonAlignmentFromReference::m_doCSC
private

Definition at line 151 of file MuonAlignmentFromReference.cc.

Referenced by processMuonResidualsFromTrack(), and terminate().

◆ m_doDT

bool MuonAlignmentFromReference::m_doDT
private

Definition at line 150 of file MuonAlignmentFromReference.cc.

Referenced by processMuonResidualsFromTrack().

◆ m_fitterOrder

std::map<unsigned int, MuonResidualsTwoBin*> MuonAlignmentFromReference::m_fitterOrder
private

◆ m_fitters

std::map<Alignable*, MuonResidualsTwoBin*> MuonAlignmentFromReference::m_fitters
private

◆ m_globTackingToken

const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> MuonAlignmentFromReference::m_globTackingToken
private

Definition at line 115 of file MuonAlignmentFromReference.cc.

Referenced by run().

◆ m_indexes

std::vector<unsigned int> MuonAlignmentFromReference::m_indexes
private

◆ m_MagFieldToken

const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> MuonAlignmentFromReference::m_MagFieldToken
private

Definition at line 116 of file MuonAlignmentFromReference.cc.

Referenced by run().

◆ m_maxDxy

double MuonAlignmentFromReference::m_maxDxy
private

Definition at line 128 of file MuonAlignmentFromReference.cc.

Referenced by run().

◆ m_maxResSlopeY

double MuonAlignmentFromReference::m_maxResSlopeY
private

Definition at line 146 of file MuonAlignmentFromReference.cc.

Referenced by processMuonResidualsFromTrack().

◆ m_maxTrackerRedChi2

double MuonAlignmentFromReference::m_maxTrackerRedChi2
private

Definition at line 130 of file MuonAlignmentFromReference.cc.

Referenced by processMuonResidualsFromTrack().

◆ m_maxTrackP

double MuonAlignmentFromReference::m_maxTrackP
private

Definition at line 127 of file MuonAlignmentFromReference.cc.

Referenced by run().

◆ m_maxTrackPt

double MuonAlignmentFromReference::m_maxTrackPt
private

Definition at line 125 of file MuonAlignmentFromReference.cc.

Referenced by run().

◆ m_me11map

std::map<Alignable*, Alignable*> MuonAlignmentFromReference::m_me11map
private

◆ m_minAlignmentHits

int MuonAlignmentFromReference::m_minAlignmentHits
private

Definition at line 141 of file MuonAlignmentFromReference.cc.

Referenced by fitAndAlign(), and initialize().

◆ m_minCSCHits

int MuonAlignmentFromReference::m_minCSCHits
private

Definition at line 135 of file MuonAlignmentFromReference.cc.

Referenced by processMuonResidualsFromTrack().

◆ m_minDT13Hits

int MuonAlignmentFromReference::m_minDT13Hits
private

Definition at line 133 of file MuonAlignmentFromReference.cc.

Referenced by processMuonResidualsFromTrack().

◆ m_minDT2Hits

int MuonAlignmentFromReference::m_minDT2Hits
private

Definition at line 134 of file MuonAlignmentFromReference.cc.

Referenced by processMuonResidualsFromTrack().

◆ m_minNCrossedChambers

int MuonAlignmentFromReference::m_minNCrossedChambers
private

Definition at line 132 of file MuonAlignmentFromReference.cc.

Referenced by processMuonResidualsFromTrack().

◆ m_minTrackerHits

int MuonAlignmentFromReference::m_minTrackerHits
private

Definition at line 129 of file MuonAlignmentFromReference.cc.

Referenced by processMuonResidualsFromTrack().

◆ m_minTrackP

double MuonAlignmentFromReference::m_minTrackP
private

Definition at line 126 of file MuonAlignmentFromReference.cc.

Referenced by run().

◆ m_minTrackPt

double MuonAlignmentFromReference::m_minTrackPt
private

Definition at line 124 of file MuonAlignmentFromReference.cc.

◆ m_muonCollectionTag

edm::InputTag MuonAlignmentFromReference::m_muonCollectionTag
private

Definition at line 122 of file MuonAlignmentFromReference.cc.

Referenced by run().

◆ m_peakNSigma

double MuonAlignmentFromReference::m_peakNSigma
private

Definition at line 148 of file MuonAlignmentFromReference.cc.

Referenced by selectResidualsPeaks(), and terminate().

◆ m_propToken

const edm::ESGetToken<Propagator, TrackingComponentsRecord> MuonAlignmentFromReference::m_propToken
private

Definition at line 117 of file MuonAlignmentFromReference.cc.

Referenced by run().

◆ m_readTemporaryFiles

std::vector<std::string> MuonAlignmentFromReference::m_readTemporaryFiles
private

Definition at line 137 of file MuonAlignmentFromReference.cc.

Referenced by readTmpFiles(), and terminate().

◆ m_reference

std::vector<std::string> MuonAlignmentFromReference::m_reference
private

Definition at line 123 of file MuonAlignmentFromReference.cc.

Referenced by initialize(), and parseReference().

◆ m_reportFileName

std::string MuonAlignmentFromReference::m_reportFileName
private

Definition at line 145 of file MuonAlignmentFromReference.cc.

Referenced by fitAndAlign().

◆ m_residualsModel

std::string MuonAlignmentFromReference::m_residualsModel
private

Definition at line 140 of file MuonAlignmentFromReference.cc.

Referenced by initialize().

◆ m_strategy

int MuonAlignmentFromReference::m_strategy
private

Definition at line 139 of file MuonAlignmentFromReference.cc.

Referenced by initialize().

◆ m_tree_row

MuonResidualsFitter::MuonAlignmentTreeRow MuonAlignmentFromReference::m_tree_row
private

Definition at line 191 of file MuonAlignmentFromReference.cc.

Referenced by bookNtuple(), and fillNtuple().

◆ m_ttree

TTree* MuonAlignmentFromReference::m_ttree
private

◆ m_twoBin

bool MuonAlignmentFromReference::m_twoBin
private

Definition at line 142 of file MuonAlignmentFromReference.cc.

Referenced by initialize().

◆ m_useResiduals

std::string MuonAlignmentFromReference::m_useResiduals
private

Definition at line 152 of file MuonAlignmentFromReference.cc.

Referenced by initialize().

◆ m_weightAlignment

bool MuonAlignmentFromReference::m_weightAlignment
private

Definition at line 144 of file MuonAlignmentFromReference.cc.

Referenced by initialize().

◆ m_writeTemporaryFile

std::string MuonAlignmentFromReference::m_writeTemporaryFile
private

Definition at line 136 of file MuonAlignmentFromReference.cc.

Referenced by terminate(), and writeTmpFiles().