diff --git a/Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h b/Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h index c8b00c391d43e..714f316b805f5 100644 --- a/Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h +++ b/Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h @@ -27,6 +27,7 @@ #include "Alignment/MuonAlignment/interface/AlignableMuon.h" #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Run.h" #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h" #include "DataFormats/TrackReco/interface/Track.h" @@ -54,6 +55,9 @@ class AlignmentMonitorBase { /// Called at beginning of job: don't reimplement void beginOfJob(AlignableTracker *pTracker, AlignableMuon *pMuon, AlignmentParameterStore *pStore); + /// Called at beginning of run: don't reimplement + void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup); + /// Called at beginning of loop: don't reimplement void startingNewLoop(); @@ -73,6 +77,9 @@ class AlignmentMonitorBase { /// Book or retrieve histograms; MUST be reimplemented virtual void book() = 0; + /// Called at beginning of run (by "beginRun()"): may be reimplemented + virtual void runBegin(const edm::Run &iRun, const edm::EventSetup &iSetup) {} + /// Called for each event (by "run()"): may be reimplemented virtual void event(const edm::Event &iEvent, const edm::EventSetup &iSetup, diff --git a/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorMuonSystemMap1D.cc b/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorMuonSystemMap1D.cc index b000400e1a38e..744d7bbce1b45 100644 --- a/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorMuonSystemMap1D.cc +++ b/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorMuonSystemMap1D.cc @@ -40,6 +40,8 @@ class AlignmentMonitorMuonSystemMap1D : public AlignmentMonitorBase { void book() override; + void runBegin(const edm::Run &iRun, const edm::EventSetup &iSetup) override; + void event(const edm::Event &iEvent, const edm::EventSetup &iSetup, const ConstTrajTrackPairCollection &iTrajTracks) override; @@ -51,6 +53,7 @@ class AlignmentMonitorMuonSystemMap1D : public AlignmentMonitorBase { // es token const edm::ESGetToken m_esTokenGBTGeom; const edm::ESGetToken m_esTokenDetId; + const DetIdAssociator *m_muonDetIdAssociator = nullptr; const edm::ESGetToken m_esTokenProp; const edm::ESGetToken m_esTokenMF; const MuonResidualsFromTrack::BuilderToken m_esTokenBuilder; @@ -157,7 +160,7 @@ AlignmentMonitorMuonSystemMap1D::AlignmentMonitorMuonSystemMap1D(const edm::Para edm::ConsumesCollector iC) : AlignmentMonitorBase(cfg, iC, "AlignmentMonitorMuonSystemMap1D"), m_esTokenGBTGeom(iC.esConsumes()), - m_esTokenDetId(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))), + m_esTokenDetId(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))), m_esTokenProp(iC.esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))), m_esTokenMF(iC.esConsumes()), m_esTokenBuilder(iC.esConsumes(MuonResidualsFromTrack::builderESInputTag())), @@ -220,6 +223,10 @@ std::string AlignmentMonitorMuonSystemMap1D::num02d(int num) { return std::string(tmp); } +void AlignmentMonitorMuonSystemMap1D::runBegin(const edm::Run &iRun, const edm::EventSetup &iSetup) { + m_muonDetIdAssociator = &iSetup.getData(m_esTokenDetId); +} + void AlignmentMonitorMuonSystemMap1D::book() { std::string wheel_label[5] = {"A", "B", "C", "D", "E"}; @@ -298,7 +305,7 @@ void AlignmentMonitorMuonSystemMap1D::event(const edm::Event &iEvent, const edm::Handle &beamSpot = iEvent.getHandle(bsToken_); const GlobalTrackingGeometry *globalGeometry = &iSetup.getData(m_esTokenGBTGeom); - const DetIdAssociator *muonDetIdAssociator_ = &iSetup.getData(m_esTokenDetId); + const DetIdAssociator *muonDetIdAssociator_ = m_muonDetIdAssociator; const Propagator *prop = &iSetup.getData(m_esTokenProp); const MagneticField *magneticField = &iSetup.getData(m_esTokenMF); auto builder = iSetup.getHandle(m_esTokenBuilder); diff --git a/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorMuonVsCurvature.cc b/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorMuonVsCurvature.cc index c4a0ca2dae97e..6129ea3f581b6 100644 --- a/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorMuonVsCurvature.cc +++ b/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorMuonVsCurvature.cc @@ -38,6 +38,8 @@ class AlignmentMonitorMuonVsCurvature : public AlignmentMonitorBase { void book() override; + void runBegin(const edm::Run &iRun, const edm::EventSetup &iSetup) override; + void event(const edm::Event &iEvent, const edm::EventSetup &iSetup, const ConstTrajTrackPairCollection &iTrajTracks) override; @@ -47,6 +49,7 @@ class AlignmentMonitorMuonVsCurvature : public AlignmentMonitorBase { // es token const edm::ESGetToken m_esTokenGBTGeom; const edm::ESGetToken m_esTokenDetId; + const DetIdAssociator *m_muonDetIdAssociator = nullptr; const edm::ESGetToken m_esTokenProp; const edm::ESGetToken m_esTokenMF; const MuonResidualsFromTrack::BuilderToken m_esTokenBuilder; @@ -89,7 +92,7 @@ AlignmentMonitorMuonVsCurvature::AlignmentMonitorMuonVsCurvature(const edm::Para edm::ConsumesCollector iC) : AlignmentMonitorBase(cfg, iC, "AlignmentMonitorMuonVsCurvature"), m_esTokenGBTGeom(iC.esConsumes()), - m_esTokenDetId(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))), + m_esTokenDetId(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))), m_esTokenProp(iC.esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))), m_esTokenMF(iC.esConsumes()), m_esTokenBuilder(iC.esConsumes(MuonResidualsFromTrack::builderESInputTag())), @@ -111,6 +114,10 @@ AlignmentMonitorMuonVsCurvature::AlignmentMonitorMuonVsCurvature(const edm::Para bsToken_(iC.consumes(m_beamSpotTag)), muonToken_(iC.consumes(m_muonCollectionTag)) {} +void AlignmentMonitorMuonVsCurvature::runBegin(const edm::Run &iRun, const edm::EventSetup &iSetup) { + m_muonDetIdAssociator = &iSetup.getData(m_esTokenDetId); +} + void AlignmentMonitorMuonVsCurvature::book() { // DT std::string wheelname[5] = {"wheelm2_", "wheelm1_", "wheelz_", "wheelp1_", "wheelp2_"}; @@ -204,7 +211,7 @@ void AlignmentMonitorMuonVsCurvature::event(const edm::Event &iEvent, const edm::Handle &beamSpot = iEvent.getHandle(bsToken_); const GlobalTrackingGeometry *globalGeometry = &iSetup.getData(m_esTokenGBTGeom); - const DetIdAssociator *muonDetIdAssociator_ = &iSetup.getData(m_esTokenDetId); + const DetIdAssociator *muonDetIdAssociator_ = m_muonDetIdAssociator; const Propagator *prop = &iSetup.getData(m_esTokenProp); const MagneticField *magneticField = &iSetup.getData(m_esTokenMF); auto builder = iSetup.getHandle(m_esTokenBuilder); diff --git a/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorSegmentDifferences.cc b/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorSegmentDifferences.cc index 379b6713e62fb..89217ffae8091 100644 --- a/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorSegmentDifferences.cc +++ b/Alignment/CommonAlignmentMonitor/plugins/AlignmentMonitorSegmentDifferences.cc @@ -38,6 +38,8 @@ class AlignmentMonitorSegmentDifferences : public AlignmentMonitorBase { void book() override; + void runBegin(const edm::Run &iRun, const edm::EventSetup &iSetup) override; + void event(const edm::Event &iEvent, const edm::EventSetup &iSetup, const ConstTrajTrackPairCollection &iTrajTracks) override; @@ -47,6 +49,7 @@ class AlignmentMonitorSegmentDifferences : public AlignmentMonitorBase { // es token const edm::ESGetToken m_esTokenGBTGeom; const edm::ESGetToken m_esTokenDetId; + const DetIdAssociator *m_muonDetIdAssociator = nullptr; const edm::ESGetToken m_esTokenProp; const edm::ESGetToken m_esTokenMF; const MuonResidualsFromTrack::BuilderToken m_esTokenBuilder; @@ -122,7 +125,7 @@ AlignmentMonitorSegmentDifferences::AlignmentMonitorSegmentDifferences(const edm edm::ConsumesCollector iC) : AlignmentMonitorBase(cfg, iC, "AlignmentMonitorSegmentDifferences"), m_esTokenGBTGeom(iC.esConsumes()), - m_esTokenDetId(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))), + m_esTokenDetId(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))), m_esTokenProp(iC.esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))), m_esTokenMF(iC.esConsumes()), m_esTokenBuilder(iC.esConsumes(MuonResidualsFromTrack::builderESInputTag())), @@ -142,6 +145,10 @@ AlignmentMonitorSegmentDifferences::AlignmentMonitorSegmentDifferences(const edm bsToken_(iC.consumes(m_beamSpotTag)), muonToken_(iC.consumes(m_muonCollectionTag)) {} +void AlignmentMonitorSegmentDifferences::runBegin(const edm::Run &iRun, const edm::EventSetup &iSetup) { + m_muonDetIdAssociator = &iSetup.getData(m_esTokenDetId); +} + void AlignmentMonitorSegmentDifferences::book() { char name[225], pos[228], neg[228]; @@ -379,7 +386,7 @@ void AlignmentMonitorSegmentDifferences::event(const edm::Event &iEvent, const edm::Handle &beamSpot = iEvent.getHandle(bsToken_); const GlobalTrackingGeometry *globalGeometry = &iSetup.getData(m_esTokenGBTGeom); - const DetIdAssociator *muonDetIdAssociator_ = &iSetup.getData(m_esTokenDetId); + const DetIdAssociator *muonDetIdAssociator_ = m_muonDetIdAssociator; const Propagator *prop = &iSetup.getData(m_esTokenProp); const MagneticField *magneticField = &iSetup.getData(m_esTokenMF); auto builder = iSetup.getHandle(m_esTokenBuilder); diff --git a/Alignment/CommonAlignmentMonitor/src/AlignmentMonitorBase.cc b/Alignment/CommonAlignmentMonitor/src/AlignmentMonitorBase.cc index d4427b55515ba..8814a125f4614 100644 --- a/Alignment/CommonAlignmentMonitor/src/AlignmentMonitorBase.cc +++ b/Alignment/CommonAlignmentMonitor/src/AlignmentMonitorBase.cc @@ -44,6 +44,8 @@ void AlignmentMonitorBase::beginOfJob(AlignableTracker *pTracker, mp_navigator = new AlignableNavigator(pTracker, pMuon); } +void AlignmentMonitorBase::beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) { runBegin(iRun, iSetup); } + void AlignmentMonitorBase::startingNewLoop() { m_iteration++; diff --git a/Alignment/CommonAlignmentProducer/src/AlignmentProducerBase.cc b/Alignment/CommonAlignmentProducer/src/AlignmentProducerBase.cc index 6ad94af7fe247..d65a1cf7ccd6e 100644 --- a/Alignment/CommonAlignmentProducer/src/AlignmentProducerBase.cc +++ b/Alignment/CommonAlignmentProducer/src/AlignmentProducerBase.cc @@ -242,6 +242,9 @@ void AlignmentProducerBase::beginRunImpl(const edm::Run& run, const edm::EventSe for (const auto& iCal : calibrations_) iCal->beginRun(run, setup); + for (const auto& monitor : monitors_) + monitor->beginRun(run, setup); + //store the first run analyzed to be used for setting the IOV (for PCL) if (firstRun_ > static_cast(run.id().run())) { firstRun_ = static_cast(run.id().run()); diff --git a/Alignment/MuonAlignmentAlgorithms/interface/CSCTTree.h b/Alignment/MuonAlignmentAlgorithms/interface/CSCTTree.h new file mode 100644 index 0000000000000..d2304833a330c --- /dev/null +++ b/Alignment/MuonAlignmentAlgorithms/interface/CSCTTree.h @@ -0,0 +1,84 @@ +#ifndef Alignment_MuonAlignmentAlgorithms_CSCTTree_H +#define Alignment_MuonAlignmentAlgorithms_CSCTTree_H + +#include +#include +#define BADVAL -999.0 + +typedef struct CSCLayerData { + UChar_t endcap; + UChar_t station; + UChar_t ring; + UChar_t chamber; + + UInt_t nlayers; + UInt_t nDT; + UInt_t nCSC; + UInt_t nTracker; + + Int_t charge; + Int_t nEvent; + + Float_t pt; + Float_t pz; + Float_t eta; + Float_t phi; + + Float_t v_hitx[6], v_hity[6]; + Float_t v_resx[6], v_resy[6]; + + // not in ttree, but for other purposes + Bool_t doFill; + std::string cutType; + + CSCLayerData() { + charge = 0; + endcap = 0; + station = 0; + ring = 0; + chamber = 0; + nlayers = 0; + nDT = 0; + nCSC = 0; + nTracker = 0; + pt = BADVAL; + pz = BADVAL; + eta = BADVAL; + phi = BADVAL; + doFill = false; + cutType = ""; + for (int i = 0; i < 6; i++) { + v_hitx[i] = BADVAL; + v_hity[i] = BADVAL; + v_resx[i] = BADVAL; + v_resy[i] = BADVAL; + } + } + + CSCLayerData& operator=(CSCLayerData x) { + charge = x.charge; + endcap = x.endcap; + ring = x.ring; + chamber = x.chamber; + nlayers = x.nlayers; + nDT = x.nDT; + nCSC = x.nCSC; + nTracker = x.nTracker; + pt = x.pt; + pz = x.pz; + eta = x.eta; + phi = x.phi; + doFill = x.doFill; + cutType = x.cutType; + + for (int i = 0; i < 6; i++) { + v_hitx[i] = x.v_hitx[i]; + v_hity[i] = x.v_hity[i]; + v_resx[i] = x.v_resx[i]; + v_resy[i] = x.v_resy[i]; + } + return *this; + } +} CSCLayerData; + +#endif diff --git a/Alignment/MuonAlignmentAlgorithms/interface/DTTTree.h b/Alignment/MuonAlignmentAlgorithms/interface/DTTTree.h new file mode 100644 index 0000000000000..647d955d3be9c --- /dev/null +++ b/Alignment/MuonAlignmentAlgorithms/interface/DTTTree.h @@ -0,0 +1,68 @@ +#ifndef Alignment_MuonAlignmentAlgorithms_DTTTree_H +#define Alignment_MuonAlignmentAlgorithms_DTTTree_H + +#include +#include +#define BADVAL -999.0 + +typedef struct DTLayerData { + UChar_t wheel; + UChar_t station; + UChar_t sector; + + UInt_t nlayers; + UInt_t nDT; + UInt_t nCSC; + UInt_t nTracker; + + Int_t charge; + Int_t nEvent; + + Float_t pt; + Float_t pz; + Float_t eta; + Float_t phi; + + Float_t v_hitx[8], v_hity[4]; + Float_t v_trackx[8], v_tracky[4], v_tracky_x_layer[8]; + + Bool_t doFill; + std::string cutType; + + DTLayerData() { + charge = 0; + wheel = 0; + station = 0; + sector = 0; + nlayers = 0; + nDT = 0; + nCSC = 0; + nTracker = 0; + pt = BADVAL; + pz = BADVAL; + eta = BADVAL; + phi = BADVAL; + doFill = false; + cutType = ""; + } + + DTLayerData& operator=(DTLayerData x) { + charge = x.charge; + wheel = x.wheel; + station = x.station; + sector = x.sector; + nlayers = x.nlayers; + nDT = x.nDT; + nCSC = x.nCSC; + nTracker = x.nTracker; + pt = x.pt; + pz = x.pz; + eta = x.eta; + phi = x.phi; + doFill = x.doFill; + cutType = x.cutType; + return *this; + } +} DTLayerData; + +#endif diff --git a/Alignment/MuonAlignmentAlgorithms/interface/FlatOccupancy.h b/Alignment/MuonAlignmentAlgorithms/interface/FlatOccupancy.h new file mode 100644 index 0000000000000..db78542ff091f --- /dev/null +++ b/Alignment/MuonAlignmentAlgorithms/interface/FlatOccupancy.h @@ -0,0 +1,76 @@ +#ifndef Alignment_MuonAlignmentAlgorithms_FlatOccupancy_H +#define Alignment_MuonAlignmentAlgorithms_FlatOccupancy_H + +#include +#include +#include +#include +#include +#include + +class FlatOccupancy { +public: + FlatOccupancy(); + ~FlatOccupancy(); + void LoadWeigths(TString FileName); + float GiveCorrection(int Wheel, int Station, int Sector, float positionX, float positionY); + +private: + std::map Occup_weights; + bool map_created; +}; + +inline FlatOccupancy::FlatOccupancy() { map_created = false; } +inline FlatOccupancy::~FlatOccupancy() {} + +inline void FlatOccupancy::LoadWeigths(TString FileName) { + if (FileName != "") { + TFile *f = new TFile(FileName.Data()); + if (f) { + std::cout << "Constructing FlatOccupancy using file: " << FileName << std::endl; + map_created = true; + for (int nW = -2; nW <= 2; nW++) { + std::string wheel = std::to_string(nW); + for (int nSt = 1; nSt <= 4; nSt++) { + std::string stat = std::to_string(nSt); + for (int nSe = 1; nSe <= 14; nSe++) { + if (nSt < 4 && (nSe == 13 || nSe == 14)) + continue; + std::string sect = std::to_string(nSe); + TString name = "Occupancy_XYweight_" + wheel + "_" + stat + "_" + sect; + TH1F *h1 = (TH1F *)f->Get(name.Data()); + if (h1) { + std::cout << "Init Weights for: " << name << std::endl; + Occup_weights[name] = h1; + } else + std::cout << "Warning!!! " << name << " not found in " << FileName << std::endl; + } + } + } + std::cout << "Weights applied!" << std::endl; + } else { + std::cout << "Warning!!! " << FileName << " not found! Weights to have flat occupancy will nor be created." + << std::endl; + map_created = false; + } + } else { + std::cout << "Warning!!! FileName is empty. Weights to have flat occupancy will nor be created." << std::endl; + map_created = false; + } +} + +inline float FlatOccupancy::GiveCorrection(int Wheel, int Station, int Sector, float positionX, float positionY) { + TString Name = + "Occupancy_XYweight_" + std::to_string(Wheel) + "_" + std::to_string(Station) + "_" + std::to_string(Sector); + int BinX = floor((positionX + 210) / 4.2) + 1; //Assuming the histrograms are from -210 to 210 with 100 bins + int BinY = floor((positionY + 210) / 4.2) + 1; //Assuming the histrograms are from -210 to 210 with 100 bins + if (map_created) { + auto it = Occup_weights.find(Name); + if (it != Occup_weights.end() && it->second) { + return it->second->GetBinContent(BinX, BinY); + } + } + return 1.; +} + +#endif diff --git a/Alignment/MuonAlignmentAlgorithms/interface/MuonInfoTuple.h b/Alignment/MuonAlignmentAlgorithms/interface/MuonInfoTuple.h new file mode 100644 index 0000000000000..da7b61915ad0d --- /dev/null +++ b/Alignment/MuonAlignmentAlgorithms/interface/MuonInfoTuple.h @@ -0,0 +1,84 @@ +#ifndef Alignment_MuonAlignmentAlgorithms_MuonInfoTuple_H +#define Alignment_MuonAlignmentAlgorithms_MuonInfoTuple_H + +/* $Date$ + * $Revision: 1.3 $ + * \author Luca Scodellaro + */ + +#define MAX_HIT 60 +#define MAX_HIT_CHAM 14 +#define MAX_SEGMENT 5 + +typedef struct { + int nhits; + float xc[MAX_HIT]; + float yc[MAX_HIT]; + float zc[MAX_HIT]; + float erx[MAX_HIT]; + int wh[MAX_HIT]; + int st[MAX_HIT]; + int sr[MAX_HIT]; + int sl[MAX_HIT]; + int la[MAX_HIT]; +} Info1D; + +typedef struct { + float p, pt, eta, phi, charge; + int nhits[MAX_SEGMENT]; + int nseg; + float xSl[MAX_SEGMENT]; + float dxdzSl[MAX_SEGMENT]; + float exSl[MAX_SEGMENT]; + float edxdzSl[MAX_SEGMENT]; + float exdxdzSl[MAX_SEGMENT]; + float ySl[MAX_SEGMENT]; + float dydzSl[MAX_SEGMENT]; + float eySl[MAX_SEGMENT]; + float edydzSl[MAX_SEGMENT]; + float eydydzSl[MAX_SEGMENT]; + float xSlSL1[MAX_SEGMENT]; + float dxdzSlSL1[MAX_SEGMENT]; + float exSlSL1[MAX_SEGMENT]; + float edxdzSlSL1[MAX_SEGMENT]; + float exdxdzSlSL1[MAX_SEGMENT]; + float xSL1SL3[MAX_SEGMENT]; + float xSlSL3[MAX_SEGMENT]; + float dxdzSlSL3[MAX_SEGMENT]; + float exSlSL3[MAX_SEGMENT]; + float edxdzSlSL3[MAX_SEGMENT]; + float exdxdzSlSL3[MAX_SEGMENT]; + float xSL3SL1[MAX_SEGMENT]; + float xc[MAX_SEGMENT][MAX_HIT_CHAM]; + float yc[MAX_SEGMENT][MAX_HIT_CHAM]; + float zc[MAX_SEGMENT][MAX_HIT_CHAM]; + float xcp[MAX_SEGMENT][MAX_HIT_CHAM]; + float ycp[MAX_SEGMENT][MAX_HIT_CHAM]; + float zcp[MAX_SEGMENT][MAX_HIT_CHAM]; + float ex[MAX_SEGMENT][MAX_HIT_CHAM]; + int wh[MAX_SEGMENT]; + int st[MAX_SEGMENT]; + int sr[MAX_SEGMENT]; + int sl[MAX_SEGMENT][MAX_HIT_CHAM]; + int la[MAX_SEGMENT][MAX_HIT_CHAM]; +} Residual1DHit; + +typedef struct { + int wh, st, se; + float dx, dz, alpha, beta, gamma, dy; + float ex, ez, ealpha, ebeta, egamma, ey; + float corr_xz, corr_xalpha, corr_xbeta, corr_xgamma, corr_xy; + float corr_zalpha, corr_zbeta, corr_zgamma, corr_zy; + float corr_alphabeta, corr_alphagamma, corr_alphay; + float corr_betagamma, corr_betay; + float corr_gammay; +} DTSegmentResult; + +typedef struct { + int wh, st, se; + float cov[60][60]; + int sl[12], la[12]; + float dx[12], dy[12], dz[12], alpha[12], beta[12], gamma[12]; +} DTHitResult; + +#endif diff --git a/Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals5DOFFitter.h b/Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals5DOFFitter.h index 66e7db9d2ce8e..2c2d183812af9 100644 --- a/Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals5DOFFitter.h +++ b/Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals5DOFFitter.h @@ -3,7 +3,7 @@ /** \class MuonResiduals5DOFFitter * $Date: Fri Apr 17 15:29:54 CDT 2009 - * $Revision: 1.5 $ + * $Revision: 1.5 $ * \author J. Pivarski - Texas A&M University */ @@ -47,6 +47,7 @@ class MuonResiduals5DOFFitter : public MuonResidualsFitter { kSector, kChambW, kChambl, + kWeightOccupancy, kNData }; diff --git a/Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals6DOFFitter.h b/Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals6DOFFitter.h index b5f1b14288ac7..603c44e1dca36 100644 --- a/Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals6DOFFitter.h +++ b/Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals6DOFFitter.h @@ -3,7 +3,7 @@ /** \class MuonResiduals6DOFFitter * $Date: Thu Apr 16 14:20:58 CDT 2009 - * $Revision: 1.5 $ + * $Revision: 1.5 $ * \author J. Pivarski - Texas A&M University */ @@ -55,6 +55,7 @@ class MuonResiduals6DOFFitter : public MuonResidualsFitter { kSector, kChambW, kChambl, + kWeightOccupancy, kNData }; diff --git a/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFitter.h b/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFitter.h index de44aa6f4fe3f..bf0b33cc28d58 100644 --- a/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFitter.h +++ b/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFitter.h @@ -106,6 +106,7 @@ class MuonResidualsFitter { Float_t pz; Float_t pt; Char_t q; + Float_t OccuWeight; Bool_t select; }; @@ -195,13 +196,9 @@ class MuonResidualsFitter { void selectPeakResiduals_simple(double nsigma, int nvar, int *vars); void selectPeakResiduals(double nsigma, int nvar, int *vars); - // void fiducialCuts(double xMin = -1000, double xMax = 1000, double yMin = -1000, double yMax = 1000, bool fidcut1=true); // "No fiducial cut" - // void fiducialCuts(double xMin = -80.0, double xMax = 80.0, double yMin = -80.0, double yMax = 80.0, bool fidcut1=true); // "old" fiducial cut - void fiducialCuts(double xMin = -80.0, - double xMax = 80.0, - double yMin = -80.0, - double yMax = 80.0, - bool fidcut1 = false); // "new" fiducial cut + void fiducialCuts(unsigned int idx); + float getRadiusFromMap(std::vector vec) { return m_RadiousOfCSC[vec]; } + std::vector GetSigmaValues(std::string chmaber_id); virtual void correctBField() = 0; virtual void correctBField(int idx_momentum, int idx_q); @@ -218,9 +215,11 @@ class MuonResidualsFitter { std::vector &start, std::vector &step, std::vector &low, - std::vector &high); + std::vector &high, + std::string chamber_id); virtual void inform(TMinuit *tMinuit) = 0; + std::map, float> m_RadiousOfCSC; int m_residualsModel; int m_minHits; int m_useResiduals; diff --git a/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFromTrack.h b/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFromTrack.h index 6591fe053b39e..0737266b3e669 100644 --- a/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFromTrack.h +++ b/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFromTrack.h @@ -43,11 +43,14 @@ #include "TMatrixDSym.h" #include "TMatrixD.h" +#include "TTree.h" #include #include #include "Alignment/MuonAlignmentAlgorithms/interface/MuonChamberResidual.h" +#include "Alignment/MuonAlignmentAlgorithms/interface/DTTTree.h" +#include "Alignment/MuonAlignmentAlgorithms/interface/CSCTTree.h" class MuonResidualsFromTrack { public: @@ -63,7 +66,13 @@ class MuonResidualsFromTrack { const Trajectory *traj, const reco::Track *recoTrack, AlignableNavigator *navigator, - double maxResidual); + double maxResidual, + bool fillLayerPlotDT = false, + bool fillLayerPlotCSC = false, + struct DTLayerData *layerData_DT = nullptr, + TTree *layerTree_DT = nullptr, + struct CSCLayerData *layerData_CSC = nullptr, + TTree *layerTree_CSC = nullptr); // residuals from tracker muons MuonResidualsFromTrack(edm::ESHandle globalGeometry, @@ -105,7 +114,13 @@ class MuonResidualsFromTrack { const Trajectory *traj, const reco::Track *recoTrack, AlignableNavigator *navigator, - double maxResidual); + double maxResidual, + bool fillLayerPlotDT, + bool fillLayerPlotCSC, + struct DTLayerData *layerData_DT, + TTree *layerTree_DT, + struct CSCLayerData *layerData_CSC, + TTree *layerTree_CSC); TrajectoryStateCombiner m_tsoscomb; diff --git a/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsTwoBin.h b/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsTwoBin.h index bc1b2917a4594..48e203d0f87d2 100644 --- a/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsTwoBin.h +++ b/Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsTwoBin.h @@ -42,6 +42,7 @@ class MuonResidualsTwoBin { return m_pos->type(); }; int useRes() const { return m_pos->useRes(); }; + TMatrixDSym CovMatr() const { return m_pos->covarianceMatrix(); }; void fix(int parNum, bool value = true) { m_pos->fix(parNum, value); @@ -242,7 +243,7 @@ class MuonResidualsTwoBin { //if (m_twoBin) m_neg->correctBField(); }; - void fiducialCuts() { m_pos->fiducialCuts(); }; + void fiducialCuts(unsigned int idx) { m_pos->fiducialCuts(idx); }; void eraseNotSelectedResiduals() { if (m_twoBin) { diff --git a/Alignment/MuonAlignmentAlgorithms/interface/SegmentToTrackAssociator.h b/Alignment/MuonAlignmentAlgorithms/interface/SegmentToTrackAssociator.h index 2e21eb37c3df1..158e3fbc47608 100644 --- a/Alignment/MuonAlignmentAlgorithms/interface/SegmentToTrackAssociator.h +++ b/Alignment/MuonAlignmentAlgorithms/interface/SegmentToTrackAssociator.h @@ -26,6 +26,8 @@ #include "Geometry/CommonTopologies/interface/GlobalTrackingGeometry.h" namespace edm { + class ParameterSet; + class Event; class EventSetup; } // namespace edm diff --git a/Alignment/MuonAlignmentAlgorithms/plugins/MuonAlignmentFromReference.cc b/Alignment/MuonAlignmentAlgorithms/plugins/MuonAlignmentFromReference.cc index 96488987cbe46..e0a2604a7fdc0 100644 --- a/Alignment/MuonAlignmentAlgorithms/plugins/MuonAlignmentFromReference.cc +++ b/Alignment/MuonAlignmentAlgorithms/plugins/MuonAlignmentFromReference.cc @@ -15,6 +15,7 @@ Description: // Created: Sat Jan 24 16:20:28 CST 2009 // $Id: MuonAlignmentFromReference.cc,v 1.39 2011/10/13 00:03:12 khotilov Exp $ +#include "DataFormats/MuonDetId/interface/MuonSubdetId.h" #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentAlgorithmBase.h" #include "FWCore/Framework/interface/Event.h" @@ -38,6 +39,7 @@ Description: #include "DataFormats/MuonDetId/interface/MuonSubdetId.h" #include "DataFormats/MuonDetId/interface/DTChamberId.h" +#include "DataFormats/MuonDetId/interface/CSCDetId.h" #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/BeamSpot/interface/BeamSpot.h" @@ -63,6 +65,12 @@ Description: #include "Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals6DOFrphiFitter.h" #include "Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsTwoBin.h" +#include "Alignment/MuonAlignmentAlgorithms/interface/DTTTree.h" +#include "Alignment/MuonAlignmentAlgorithms/interface/CSCTTree.h" +#include "Alignment/MuonAlignmentAlgorithms/interface/FlatOccupancy.h" + +#include "TrackingTools/Records/interface/DetIdAssociatorRecord.h" + #include "TFile.h" #include "TTree.h" #include "TStopwatch.h" @@ -74,7 +82,6 @@ Description: class MuonAlignmentFromReference : public AlignmentAlgorithmBase { public: MuonAlignmentFromReference(const edm::ParameterSet& cfg, edm::ConsumesCollector& iC); - ~MuonAlignmentFromReference() override; void initialize(const edm::EventSetup& iSetup, AlignableTracker* alignableTracker, @@ -116,8 +123,10 @@ class MuonAlignmentFromReference : public AlignmentAlgorithmBase { const edm::ESGetToken m_MagFieldToken; const edm::ESGetToken m_propToken; const edm::ESGetToken m_DetIdToken; + const DetIdAssociator* m_muonDetIdAssociator = nullptr; const MuonResidualsFromTrack::BuilderToken m_builderToken; + FlatOccupancy myOccupancyMap; // configutarion paramenters: edm::InputTag m_muonCollectionTag; std::vector m_reference; @@ -151,8 +160,12 @@ class MuonAlignmentFromReference : public AlignmentAlgorithmBase { bool m_doCSC; std::string m_useResiduals; + //Layer Plots + bool m_createLayerNtuple_DT; + bool m_createLayerNtuple_CSC; + // utility objects - AlignableNavigator* m_alignableNavigator; + std::unique_ptr m_alignableNavigator; AlignmentParameterStore* m_alignmentParameterStore; align::Alignables m_alignables; std::map m_me11map; @@ -187,8 +200,15 @@ class MuonAlignmentFromReference : public AlignmentAlgorithmBase { // debug ntuple void bookNtuple(); + void bookNtupleLayers_DT(); + void bookNtupleLayers_CSC(); + TTree* m_ttree; + TTree* m_ttree_DT_layers; + TTree* m_ttree_CSC_layers; MuonResidualsFitter::MuonAlignmentTreeRow m_tree_row; + DTLayerData layerData_DT; + CSCLayerData layerData_CSC; bool m_debug; }; @@ -199,7 +219,7 @@ MuonAlignmentFromReference::MuonAlignmentFromReference(const edm::ParameterSet& m_globTackingToken(iC.esConsumes()), m_MagFieldToken(iC.esConsumes()), m_propToken(iC.esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))), - m_DetIdToken(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))), + m_DetIdToken(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))), m_builderToken(iC.esConsumes(MuonResidualsFromTrack::builderESInputTag())), m_muonCollectionTag(cfg.getParameter("muonCollectionTag")), m_reference(cfg.getParameter >("reference")), @@ -231,7 +251,9 @@ MuonAlignmentFromReference::MuonAlignmentFromReference(const edm::ParameterSet& m_BFieldCorrection(cfg.getParameter("bFieldCorrection")), m_doDT(cfg.getParameter("doDT")), m_doCSC(cfg.getParameter("doCSC")), - m_useResiduals(cfg.getParameter("useResiduals")) { + m_useResiduals(cfg.getParameter("useResiduals")), + m_createLayerNtuple_DT(cfg.getParameter("createLayerNtupleDT")), + m_createLayerNtuple_CSC(cfg.getParameter("createLayerNtupleCSC")) { // alignment requires a TFile to provide plots to check the fit output // just filling the residuals lists does not // but we don't want to wait until the end of the job to find out that the TFile is missing @@ -244,6 +266,17 @@ MuonAlignmentFromReference::MuonAlignmentFromReference(const edm::ParameterSet& m_ttree = nullptr; if (m_createNtuple) bookNtuple(); + //Layer Ntuples + m_ttree_DT_layers = nullptr; //By default the TTree is nullptr + m_ttree_CSC_layers = nullptr; //By default the TTree is nullptr + if (m_createLayerNtuple_DT) { + layerData_DT.doFill = true; + bookNtupleLayers_DT(); + } + if (m_createLayerNtuple_CSC) { + layerData_CSC.doFill = true; + bookNtupleLayers_CSC(); + } m_counter_events = 0; m_counter_tracks = 0; @@ -269,11 +302,11 @@ MuonAlignmentFromReference::MuonAlignmentFromReference(const edm::ParameterSet& m_counter_cscaligning = 0; m_counter_resslopey = 0; + myOccupancyMap.LoadWeigths( + ""); //Place a root file containing the weight map for the 250 DTs as a function of X and Y, if you want flat occupancy (and decomment the weight part in MuonResidualsXDOFFitter.cc). m_debug = false; } -MuonAlignmentFromReference::~MuonAlignmentFromReference() { delete m_alignableNavigator; } - void MuonAlignmentFromReference::bookNtuple() { edm::Service fs; m_ttree = fs->make("mual_ttree", "mual_ttree"); @@ -293,10 +326,64 @@ void MuonAlignmentFromReference::bookNtuple() { m_ttree->Branch("pz", &m_tree_row.pz, "pz/F"); m_ttree->Branch("pt", &m_tree_row.pt, "pt/F"); m_ttree->Branch("q", &m_tree_row.q, "q/B"); + m_ttree->Branch("OccuWeight", &m_tree_row.OccuWeight, "OccuWeight/F"); m_ttree->Branch("select", &m_tree_row.select, "select/O"); //m_ttree->Branch("",&m_tree_row.,"/"); } +void MuonAlignmentFromReference::bookNtupleLayers_DT() { + edm::Service fs; + m_ttree_DT_layers = fs->make("dt_layer_ttree", "dt_layer_ttree"); + m_ttree_DT_layers->Branch("charge", &(layerData_DT.charge), "charge/i"); + m_ttree_DT_layers->Branch("nEvent", &(layerData_DT.nEvent), "nEvent/i"); + m_ttree_DT_layers->Branch("nlayers", &(layerData_DT.nlayers), "nlayers/i"); + m_ttree_DT_layers->Branch("nDT", &(layerData_DT.nDT), "nDT/i"); + m_ttree_DT_layers->Branch("nCSC", &(layerData_DT.nDT), "nCSC/i"); + m_ttree_DT_layers->Branch("nTracker", &(layerData_DT.nTracker), "nTracker/i"); + + m_ttree_DT_layers->Branch("wheel", &(layerData_DT.wheel), "wheel/b"); + m_ttree_DT_layers->Branch("station", &(layerData_DT.station), "station/b"); + m_ttree_DT_layers->Branch("sector", &(layerData_DT.sector), "sector/b"); + + m_ttree_DT_layers->Branch("pt", &(layerData_DT.pt), "pt/F"); + m_ttree_DT_layers->Branch("pz", &(layerData_DT.pz), "pz/F"); + m_ttree_DT_layers->Branch("eta", &(layerData_DT.eta), "eta/F"); + m_ttree_DT_layers->Branch("phi", &(layerData_DT.phi), "phi/F"); + + m_ttree_DT_layers->Branch("hit_x", &(layerData_DT.v_hitx), "hit_x[8]/F"); + m_ttree_DT_layers->Branch("hit_y", &(layerData_DT.v_hity), "hit_y[4]/F"); + m_ttree_DT_layers->Branch("track_x", &(layerData_DT.v_trackx), "track_x[8]/F"); + m_ttree_DT_layers->Branch("track_y", &(layerData_DT.v_tracky), "track_y[4]/F"); + m_ttree_DT_layers->Branch("track_y_x_layer", &(layerData_DT.v_tracky_x_layer), "track_y_x_layer[4]/F"); +} + +void MuonAlignmentFromReference::bookNtupleLayers_CSC() { + edm::Service fs; + m_ttree_CSC_layers = fs->make("csc_layer_ttree", "csc_layer_ttree"); + m_ttree_CSC_layers->Branch("charge", &(layerData_CSC.charge), "charge/i"); + m_ttree_CSC_layers->Branch("nEvent", &(layerData_CSC.nEvent), "nEvent/i"); + m_ttree_CSC_layers->Branch("nlayers", &(layerData_CSC.nlayers), "nlayers/i"); + + m_ttree_CSC_layers->Branch("nDT", &(layerData_CSC.nDT), "nDT/i"); + m_ttree_CSC_layers->Branch("nCSC", &(layerData_CSC.nCSC), "nCSC/i"); + m_ttree_CSC_layers->Branch("nTracker", &(layerData_CSC.nTracker), "nTracker/i"); + + m_ttree_CSC_layers->Branch("endcap", &(layerData_CSC.endcap), "endcap/b"); + m_ttree_CSC_layers->Branch("station", &(layerData_CSC.station), "station/b"); + m_ttree_CSC_layers->Branch("ring", &(layerData_CSC.ring), "ring/b"); + m_ttree_CSC_layers->Branch("chamber", &(layerData_CSC.chamber), "chamber/b"); + + m_ttree_CSC_layers->Branch("pt", &(layerData_CSC.pt), "pt/F"); + m_ttree_CSC_layers->Branch("pz", &(layerData_CSC.pz), "pz/F"); + m_ttree_CSC_layers->Branch("eta", &(layerData_CSC.eta), "eta/F"); + m_ttree_CSC_layers->Branch("phi", &(layerData_CSC.phi), "phi/F"); + + m_ttree_CSC_layers->Branch("hit_x", &(layerData_CSC.v_hitx), "hit_x[6]/F"); + m_ttree_CSC_layers->Branch("hit_y", &(layerData_CSC.v_hity), "hit_y[6]/F"); + m_ttree_CSC_layers->Branch("res_x", &(layerData_CSC.v_resx), "res_x[6]/F"); + m_ttree_CSC_layers->Branch("res_y", &(layerData_CSC.v_resy), "res_y[6]/F"); +} + bool MuonAlignmentFromReference::numeric(std::string s) { return s.length() == 1 && std::isdigit(s[0]); } int MuonAlignmentFromReference::number(std::string s) { @@ -313,7 +400,7 @@ void MuonAlignmentFromReference::initialize(const edm::EventSetup& iSetup, if (alignableMuon == nullptr) throw cms::Exception("MuonAlignmentFromReference") << "doMuon must be set to True" << std::endl; - m_alignableNavigator = new AlignableNavigator(alignableMuon); + m_alignableNavigator = std::make_unique(alignableMuon); m_alignmentParameterStore = alignmentParameterStore; m_alignables = m_alignmentParameterStore->alignables(); @@ -350,6 +437,7 @@ void MuonAlignmentFromReference::initialize(const edm::EventSetup& iSetup, << "unrecognized useResiduals: \"" << m_useResiduals << "\"" << std::endl; const CSCGeometry* cscGeometry = &iSetup.getData(m_cscGeometryToken); + m_muonDetIdAssociator = &iSetup.getData(m_DetIdToken); // set up the MuonResidualsFitters (which also collect residuals for fitting) m_me11map.clear(); @@ -446,7 +534,7 @@ void MuonAlignmentFromReference::run(const edm::EventSetup& iSetup, const EventI const GlobalTrackingGeometry* globalGeometry = &iSetup.getData(m_globTackingToken); const MagneticField* magneticField = &iSetup.getData(m_MagFieldToken); const Propagator* prop = &iSetup.getData(m_propToken); - const DetIdAssociator* muonDetIdAssociator = &iSetup.getData(m_DetIdToken); + const DetIdAssociator* muonDetIdAssociator = m_muonDetIdAssociator; auto builder = iSetup.getHandle(m_builderToken); if (m_muonCollectionTag.label().empty()) // use trajectories @@ -478,8 +566,14 @@ void MuonAlignmentFromReference::run(const edm::EventSetup& iSetup, const EventI prop, traj, track, - m_alignableNavigator, - 1000.); + m_alignableNavigator.get(), + 1000., + m_createLayerNtuple_DT, + m_createLayerNtuple_CSC, + &layerData_DT, + m_ttree_DT_layers, + &layerData_CSC, + m_ttree_CSC_layers); if (m_debug) std::cout << "JUST AFTER muonResidualsFromTrack" << std::endl; @@ -496,6 +590,7 @@ void MuonAlignmentFromReference::run(const edm::EventSetup& iSetup, const EventI } else // use muons { + edm::LogWarning("MuonAlignmentFromReference") << "WARNING! You are not using Trajectories."; /* for (reco::MuonCollection::const_iterator muon = eventInfo.muonCollection_->begin(); muon != eventInfo.muonCollection_->end(); ++muon) { @@ -587,7 +682,12 @@ void MuonAlignmentFromReference::processMuonResidualsFromTrack(MuonResidualsFrom residdata[MuonResiduals6DOFFitter::kSector] = DTChamberId(chamberId->rawId()).sector(); residdata[MuonResiduals6DOFFitter::kChambW] = dt13->ChambW(); residdata[MuonResiduals6DOFFitter::kChambl] = dt13->Chambl(); - + residdata[MuonResiduals6DOFFitter::kWeightOccupancy] = + myOccupancyMap.GiveCorrection(DTChamberId(chamberId->rawId()).wheel(), + DTChamberId(chamberId->rawId()).station(), + DTChamberId(chamberId->rawId()).sector(), + dt13->trackx(), + dt13->tracky()); if (m_debug) { std::cout << "processMuonResidualsFromTrack 6DOF dt13->residual() " << dt13->residual() << std::endl; @@ -648,6 +748,12 @@ void MuonAlignmentFromReference::processMuonResidualsFromTrack(MuonResidualsFrom residdata[MuonResiduals5DOFFitter::kSector] = DTChamberId(chamberId->rawId()).sector(); residdata[MuonResiduals5DOFFitter::kChambW] = dt13->ChambW(); residdata[MuonResiduals5DOFFitter::kChambl] = dt13->Chambl(); + residdata[MuonResiduals5DOFFitter::kWeightOccupancy] = + myOccupancyMap.GiveCorrection(DTChamberId(chamberId->rawId()).wheel(), + DTChamberId(chamberId->rawId()).station(), + DTChamberId(chamberId->rawId()).sector(), + dt13->trackx(), + dt13->tracky()); if (m_debug) { std::cout << "processMuonResidualsFromTrack 5DOF dt13->residual() " << dt13->residual() @@ -909,6 +1015,24 @@ void MuonAlignmentFromReference::fitAndAlign() { bool align_phix = selector[3]; bool align_phiy = selector[4]; bool align_phiz = selector[5]; + DetId id_check = ali->geomDetId(); + //If it is sector 4,13,10,14 of station4 in DT I will not align phiY, because these sectors are non pointing and their redisual is biased. + bool WannaUsenoPHIY = false; + if (id_check.subdetId() == MuonSubdetId::DT) { + DTChamberId chamberId_check(id_check.rawId()); + if (chamberId_check.station() == 4 && (chamberId_check.sector() == 10 || chamberId_check.sector() == 13 || + chamberId_check.sector() == 4 || chamberId_check.sector() == 14)) + WannaUsenoPHIY = true; + } + // In ME1/3 aligning Y give a large spread on Y. So we fix Y. + bool WannaUsenoY = false; + if (id_check.subdetId() == MuonSubdetId::CSC) { + CSCDetId chamberId_check(id_check.rawId()); + if (chamberId_check.station() == 1 && chamberId_check.ring() == 3) + WannaUsenoY = true; + } + + //Counting the parameters int numParams = ((align_x ? 1 : 0) + (align_y ? 1 : 0) + (align_z ? 1 : 0) + (align_phix ? 1 : 0) + (align_phiy ? 1 : 0) + (align_phiz ? 1 : 0)); @@ -937,6 +1061,7 @@ void MuonAlignmentFromReference::fitAndAlign() { DetId id = ali->geomDetId(); auto thisali = ali; + // ME 1/1 and ME 1/4 are the same chambers but are divided. here you are fitting them as a single chamber. if (m_combineME11 && id.subdetId() == MuonSubdetId::CSC) { CSCDetId cscid(id.rawId()); if (cscid.station() == 1 && cscid.ring() == 4) @@ -1012,7 +1137,8 @@ void MuonAlignmentFromReference::fitAndAlign() { fitter->second->fix(MuonResiduals5DOFFitter::kAlignZ); if (!align_phix) fitter->second->fix(MuonResiduals5DOFFitter::kAlignPhiX); - if (!align_phiy) + // Not aligning PhiY in BAD sectors (station 4 sectro 3 4 10 14) + if (!align_phiy || WannaUsenoPHIY) fitter->second->fix(MuonResiduals5DOFFitter::kAlignPhiY); if (!align_phiz) fitter->second->fix(MuonResiduals5DOFFitter::kAlignPhiZ); @@ -1032,7 +1158,7 @@ void MuonAlignmentFromReference::fitAndAlign() { } else if (fitter->second->type() == MuonResidualsFitter::k6DOFrphi) { if (!align_x) fitter->second->fix(MuonResiduals6DOFrphiFitter::kAlignX); - if (!align_y) + if (!align_y || WannaUsenoY) fitter->second->fix(MuonResiduals6DOFrphiFitter::kAlignY); if (!align_z) fitter->second->fix(MuonResiduals6DOFrphiFitter::kAlignZ); @@ -1166,6 +1292,15 @@ void MuonAlignmentFromReference::fitAndAlign() { << "None, " << fitter->second->stdev(MuonResiduals5DOFFitter::kResSlope, 10.) << ", " << "None)" << std::endl; + report << "reports[-1].CovMatrix = ["; + for (int ii = 0; ii < 64; ii++) { + if (ii != 63) + report << "'" << fitter->second->CovMatr().GetMatrixArray()[ii] << "',"; + else + report << "'" << fitter->second->CovMatr().GetMatrixArray()[ii] << "'"; + } + report << "]" << std::endl; + std::stringstream namesimple_x, namesimple_dxdz, nameweighted_x, nameweighted_dxdz; namesimple_x << cname << "_simple_x"; namesimple_dxdz << cname << "_simple_dxdz"; @@ -1344,6 +1479,15 @@ void MuonAlignmentFromReference::fitAndAlign() { << fitter->second->stdev(MuonResiduals6DOFFitter::kResSlopeX, 10.) << ", " << fitter->second->stdev(MuonResiduals6DOFFitter::kResSlopeY, 25.) << ")" << std::endl; + report << "reports[-1].CovMatrix = ["; + for (int ii = 0; ii < 144; ii++) { + if (ii != 143) + report << "'" << fitter->second->CovMatr().GetMatrixArray()[ii] << "',"; + else + report << "'" << fitter->second->CovMatr().GetMatrixArray()[ii] << "'"; + } + report << "]" << std::endl; + std::stringstream namesimple_x, namesimple_y, namesimple_dxdz, namesimple_dydz, nameweighted_x, nameweighted_y, nameweighted_dxdz, nameweighted_dydz; namesimple_x << cname << "_simple_x"; @@ -1509,6 +1653,15 @@ void MuonAlignmentFromReference::fitAndAlign() { << "None, " << fitter->second->stdev(MuonResiduals6DOFrphiFitter::kResSlope, 10.) << ", " << "None)" << std::endl; + report << "reports[-1].CovMatrix = ["; + for (int ii = 0; ii < 81; ii++) { + if (ii != 143) + report << "'" << fitter->second->CovMatr().GetMatrixArray()[ii] << "',"; + else + report << "'" << fitter->second->CovMatr().GetMatrixArray()[ii] << "'"; + } + report << "]" << std::endl; + std::stringstream namesimple_x, namesimple_dxdz, nameweighted_x, nameweighted_dxdz; namesimple_x << cname << "_simple_x"; namesimple_dxdz << cname << "_simple_dxdz"; @@ -1680,7 +1833,7 @@ void MuonAlignmentFromReference::fiducialCuts() { if (m_debug) std::cout << "applying fiducial cuts in " << chamberPrettyNameFromId(*index) << std::endl; MuonResidualsTwoBin* fitter = m_fitterOrder[*index]; - fitter->fiducialCuts(); + fitter->fiducialCuts(*index); } } @@ -1821,6 +1974,9 @@ void MuonAlignmentFromReference::fillNtuple() { m_tree_row.pz = (Float_t)(*residual)[MuonResiduals5DOFFitter::kPz]; m_tree_row.pt = (Float_t)(*residual)[MuonResiduals5DOFFitter::kPt]; m_tree_row.q = (Char_t)(*residual)[MuonResiduals5DOFFitter::kCharge]; + m_tree_row.OccuWeight = (fitter->type() == MuonResidualsFitter::k5DOF) + ? (Float_t)(*residual)[MuonResiduals5DOFFitter::kWeightOccupancy] + : -1.; // for CSC you do not have this element in the array m_tree_row.select = (Bool_t)*residual_ok; } else if (fitter->type() == MuonResidualsFitter::k6DOF) { m_tree_row.res_x = (Float_t)(*residual)[MuonResiduals6DOFFitter::kResidX]; @@ -1834,6 +1990,7 @@ void MuonAlignmentFromReference::fillNtuple() { m_tree_row.pz = (Float_t)(*residual)[MuonResiduals6DOFFitter::kPz]; m_tree_row.pt = (Float_t)(*residual)[MuonResiduals6DOFFitter::kPt]; m_tree_row.q = (Char_t)(*residual)[MuonResiduals6DOFFitter::kCharge]; + m_tree_row.OccuWeight = (Float_t)(*residual)[MuonResiduals6DOFFitter::kWeightOccupancy]; m_tree_row.select = (Bool_t)*residual_ok; } else assert(false); diff --git a/Alignment/MuonAlignmentAlgorithms/python/CSCOverlapsAlignmentAlgorithm_cfi.py b/Alignment/MuonAlignmentAlgorithms/python/CSCOverlapsAlignmentAlgorithm_cfi.py index 3f9cc48a3fe8b..ba958ac14bd51 100644 --- a/Alignment/MuonAlignmentAlgorithms/python/CSCOverlapsAlignmentAlgorithm_cfi.py +++ b/Alignment/MuonAlignmentAlgorithms/python/CSCOverlapsAlignmentAlgorithm_cfi.py @@ -39,6 +39,7 @@ MuonRecHitBuilder = cms.string("MuonRecHitBuilder"), RefitDirection = cms.string("alongMomentum"), RefitRPCHits = cms.bool(False), + RefitMuonHits = cms.bool(True), Propagator = cms.string("SteppingHelixPropagatorAny")), fitters = Alignment.MuonAlignmentAlgorithms.CSCOverlapsAlignmentAlgorithm_ringfitters_cff.fitters, diff --git a/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentFromReference_cff.py b/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentFromReference_cff.py index daf91ddb2569d..e90b76fb0db3d 100644 --- a/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentFromReference_cff.py +++ b/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentFromReference_cff.py @@ -14,9 +14,10 @@ MuonAlignmentFromReferenceGlobalMuonRefit = globalMuons.clone() MuonAlignmentFromReferenceGlobalMuonRefit.Tracks = cms.InputTag("ALCARECOMuAlCalIsolatedMu:GlobalMuon") MuonAlignmentFromReferenceGlobalMuonRefit.TrackTransformer.RefitRPCHits = cms.bool(False) +MuonAlignmentFromReferenceGlobalMuonRefit.TrackTransformer.RefitMuonHits = cms.bool(False) ### Track refitter for global cosmic muons -from TrackingTools.TrackRefitter.globalCosmicMuonTrajectories_cff import * +# from TrackingTools.TrackRefitter.globalCosmicMuonTrajectories_cff import * #MuonAlignmentFromReferenceGlobalCosmicRefit = globalCosmicMuons.clone() #MuonAlignmentFromReferenceGlobalCosmicRefit.Tracks = cms.InputTag("ALCARECOMuAlGlobalCosmics:GlobalMuon") #MuonAlignmentFromReferenceGlobalCosmicRefit.TrackTransformer.RefitRPCHits = cms.bool(False) @@ -52,16 +53,20 @@ MuonAlignmentFromReferenceTFileService = cms.Service("TFileService", fileName = cms.string("MuonAlignmentFromReference.root")) ### Input geometry database +from CondCore.CondDB.CondDB_cfi import * +CondDBSetup = CondDB.clone() +CondDBSetup.__delattr__('connect') looper.applyDbAlignment = cms.untracked.bool(True) -from CondCore.DBCommon.CondDBSetup_cfi import * + MuonAlignmentFromReferenceInputDB = cms.ESSource("PoolDBESSource", CondDBSetup, connect = cms.string("sqlite_file:MuonAlignmentFromReference_inputdb.db"), toGet = cms.VPSet(cms.PSet(record = cms.string("DTAlignmentRcd"), tag = cms.string("DTAlignmentRcd")), cms.PSet(record = cms.string("DTAlignmentErrorExtendedRcd"), tag = cms.string("DTAlignmentErrorExtendedRcd")), cms.PSet(record = cms.string("CSCAlignmentRcd"), tag = cms.string("CSCAlignmentRcd")), - cms.PSet(record = cms.string("CSCAlignmentErrorExtendedRcd"), tag = cms.string("CSCAlignmentErrorExtendedRcd")))) -es_prefer_MuonAlignmentFromReferenceInputDB = cms.ESPrefer("PoolDBESSource", "MuonAlignmentFromReferenceInputDB") + cms.PSet(record = cms.string("CSCAlignmentErrorExtendedRcd"), tag = cms.string("CSCAlignmentErrorExtendedRcd")), + cms.PSet(record = cms.string("GEMAlignmentRcd"), tag = cms.string("GEMAlignmentRcd")), + cms.PSet(record = cms.string("GEMAlignmentErrorExtendedRcd"), tag = cms.string("GEMAlignmentErrorExtendedRcd")))) ### Output geometry database looper.saveToDB = cms.bool(True) @@ -72,4 +77,6 @@ toPut = cms.VPSet(cms.PSet(record = cms.string("DTAlignmentRcd"), tag = cms.string("DTAlignmentRcd")), cms.PSet(record = cms.string("DTAlignmentErrorExtendedRcd"), tag = cms.string("DTAlignmentErrorExtendedRcd")), cms.PSet(record = cms.string("CSCAlignmentRcd"), tag = cms.string("CSCAlignmentRcd")), - cms.PSet(record = cms.string("CSCAlignmentErrorExtendedRcd"), tag = cms.string("CSCAlignmentErrorExtendedRcd")))) + cms.PSet(record = cms.string("CSCAlignmentErrorExtendedRcd"), tag = cms.string("CSCAlignmentErrorExtendedRcd")), + cms.PSet(record = cms.string("GEMAlignmentRcd"), tag = cms.string("GEMAlignmentRcd")), + cms.PSet(record = cms.string("GEMAlignmentErrorExtendedRcd"), tag = cms.string("GEMAlignmentErrorExtendedRcd")))) diff --git a/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentFromReference_cfi.py b/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentFromReference_cfi.py index 37772d66aa2c0..faf532a75dbfe 100644 --- a/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentFromReference_cfi.py +++ b/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentFromReference_cfi.py @@ -41,12 +41,15 @@ reportFileName = cms.string("MuonAlignmentFromReference_report.py"), # Python-formatted output maxResSlopeY = cms.double(10.), - + createNtuple = cms.bool(False), - + peakNSigma = cms.double(-1.), bFieldCorrection = cms.int32(1), - + doDT = cms.bool(True), - doCSC = cms.bool(True) + doCSC = cms.bool(True), + + createLayerNtupleDT = cms.bool(False), + createLayerNtupleCSC = cms.bool(False) ) diff --git a/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentPreFilter_cfi.py b/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentPreFilter_cfi.py new file mode 100644 index 0000000000000..6f9df92288bf3 --- /dev/null +++ b/Alignment/MuonAlignmentAlgorithms/python/MuonAlignmentPreFilter_cfi.py @@ -0,0 +1,13 @@ +import FWCore.ParameterSet.Config as cms + +MuonAlignmentPreFilter = cms.EDFilter("MuonAlignmentPreFilter", + tracksTag = cms.InputTag("ALCARECOMuAlCalIsolatedMu:GlobalMuon"), + minTrackPt = cms.double(20.), + minTrackP = cms.double(0.), + minTrackerHits = cms.int32(10), + minDTHits = cms.int32(6), + minCSCHits = cms.int32(4), + allowTIDTEC = cms.bool(True), + minTrackEta = cms.double(-2.4), + maxTrackEta = cms.double(2.4) +) diff --git a/Alignment/MuonAlignmentAlgorithms/python/align_cfg.py b/Alignment/MuonAlignmentAlgorithms/python/align_cfg.py index ba263b4ba9d7f..9e65d6b00febf 100644 --- a/Alignment/MuonAlignmentAlgorithms/python/align_cfg.py +++ b/Alignment/MuonAlignmentAlgorithms/python/align_cfg.py @@ -34,6 +34,7 @@ residualsModel = os.environ["ALIGNMENT_RESIDUALSMODEL"] peakNSigma = float(os.environ["ALIGNMENT_PEAKNSIGMA"]) useResiduals = os.environ["ALIGNMENT_USERESIDUALS"] +is_MC = (os.environ["ALIGNMENT_ISMC"] == "True") # optionally do selective DT or CSC alignment doDT = True @@ -54,9 +55,10 @@ if envNtuple is not None: if envNtuple=='True': createAlignNtuple = True - -process = cms.Process("ALIGN") -process.source = cms.Source("EmptySource") +from Configuration.Eras.Era_Run3_cff import Run3 +process = cms.Process("ALIGN", Run3) +runnumber = int(os.environ.get("ALIGNMENT_RUNNUMBER", "1")) +process.source = cms.Source("EmptySource", firstRun=cms.untracked.uint32(runnumber)) process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1)) process.load("Configuration.StandardSequences.Reconstruction_cff") @@ -68,7 +70,7 @@ firstValid = cms.vuint32( 1 ) ) -process.load("Configuration.Geometry.GeometryIdeal_cff") +process.load('Configuration.StandardSequences.GeometryRecoDB_cff') process.load("Configuration.StandardSequences.MagneticField_cff") process.load("Alignment.MuonAlignmentAlgorithms.MuonAlignmentFromReference_cff") @@ -103,38 +105,40 @@ process.MuonAlignmentFromReferenceInputDB.connect = cms.string("sqlite_file:%s" % inputdb) process.MuonAlignmentFromReferenceInputDB.toGet = cms.VPSet(cms.PSet(record = cms.string("DTAlignmentRcd"), tag = cms.string("DTAlignmentRcd")), cms.PSet(record = cms.string("CSCAlignmentRcd"), tag = cms.string("CSCAlignmentRcd"))) - -if trackerconnect != "": - from CondCore.DBCommon.CondDBSetup_cfi import * - process.TrackerAlignmentInputDB = cms.ESSource("PoolDBESSource", - CondDBSetup, - connect = cms.string(trackerconnect), - toGet = cms.VPSet(cms.PSet(record = cms.string("TrackerAlignmentRcd"), tag = cms.string(trackeralignment)))) - process.es_prefer_TrackerAlignmentInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentInputDB") - -if trackerAPEconnect != "": - from CondCore.DBCommon.CondDBSetup_cfi import * - process.TrackerAlignmentErrorInputDB = cms.ESSource("PoolDBESSource", - CondDBSetup, - connect = cms.string(trackerAPEconnect), - toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerAlignmentErrorExtendedRcd"), tag = cms.string(trackerAPE))))) - process.es_prefer_TrackerAlignmentErrorInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentErrorInputDB") - -if trackerBowsconnect != "": - from CondCore.DBCommon.CondDBSetup_cfi import * - process.TrackerSurfaceDeformationInputDB = cms.ESSource("PoolDBESSource", - CondDBSetup, - connect = cms.string(trackerBowsconnect), - toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerSurfaceDeformationRcd"), tag = cms.string(trackerBows))))) - process.es_prefer_TrackerSurfaceDeformationInputDB = cms.ESPrefer("PoolDBESSource", "TrackerSurfaceDeformationInputDB") +process.es_prefer_MuonAlignmentFromReferenceInputDB = cms.ESPrefer( + "PoolDBESSource", "MuonAlignmentFromReferenceInputDB") + +from CondCore.CondDB.CondDB_cfi import * +CondDBSetup = CondDB.clone() +CondDBSetup.__delattr__('connect') +if is_MC: + if trackerconnect != "": + process.TrackerAlignmentInputDB = cms.ESSource("PoolDBESSource", + CondDBSetup, + connect = cms.string(trackerconnect), + toGet = cms.VPSet(cms.PSet(record = cms.string("TrackerAlignmentRcd"), tag = cms.string(trackeralignment)))) + process.es_prefer_TrackerAlignmentInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentInputDB") + + if trackerAPEconnect != "": + process.TrackerAlignmentErrorInputDB = cms.ESSource("PoolDBESSource", + CondDBSetup, + connect = cms.string(trackerAPEconnect), + toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerAlignmentErrorExtendedRcd"), tag = cms.string(trackerAPE))))) + process.es_prefer_TrackerAlignmentErrorInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentErrorInputDB") + + if trackerBowsconnect != "": + process.TrackerSurfaceDeformationInputDB = cms.ESSource("PoolDBESSource", + CondDBSetup, + connect = cms.string(trackerBowsconnect), + toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerSurfaceDeformationRcd"), tag = cms.string(trackerBows))))) + process.es_prefer_TrackerSurfaceDeformationInputDB = cms.ESPrefer("PoolDBESSource", "TrackerSurfaceDeformationInputDB") if gprcdconnect != "": - from CondCore.DBCommon.CondDBSetup_cfi import * - process.GlobalPositionInputDB = cms.ESSource("PoolDBESSource", - CondDBSetup, - connect = cms.string(gprcdconnect), - toGet = cms.VPSet(cms.PSet(record = cms.string("GlobalPositionRcd"), tag = cms.string(gprcd)))) - process.es_prefer_GlobalPositionInputDB = cms.ESPrefer("PoolDBESSource", "GlobalPositionInputDB") + process.GlobalPositionInputDB = cms.ESSource("PoolDBESSource", + CondDBSetup, + connect = cms.string(gprcdconnect), + toGet = cms.VPSet(cms.PSet(record = cms.string("GlobalPositionRcd"), tag = cms.string(gprcd)))) + process.es_prefer_GlobalPositionInputDB = cms.ESPrefer("PoolDBESSource", "GlobalPositionInputDB") process.looper.saveToDB = True process.looper.saveApeToDB = True diff --git a/Alignment/MuonAlignmentAlgorithms/python/gather_cfg.py b/Alignment/MuonAlignmentAlgorithms/python/gather_cfg.py index 1d309fe237867..4ff892e656dfd 100644 --- a/Alignment/MuonAlignmentAlgorithms/python/gather_cfg.py +++ b/Alignment/MuonAlignmentAlgorithms/python/gather_cfg.py @@ -1,16 +1,6 @@ import os import FWCore.ParameterSet.Config as cms -# for json support -try: # FUTURE: Python 2.6, prior to 2.6 requires simplejson - import json -except: - try: - import simplejson as json - except: - print("Please use lxplus or set an environment (for example crab) with json lib available") - sys.exit(1) - inputfiles = os.environ["ALIGNMENT_INPUTFILES"].split(" ") iteration = int(os.environ["ALIGNMENT_ITERATION"]) jobnumber = int(os.environ["ALIGNMENT_JOBNUMBER"]) @@ -51,8 +41,13 @@ muonCollectionTag = os.environ["ALIGNMENT_MUONCOLLECTIONTAG"] maxDxy = float(os.environ["ALIGNMENT_MAXDXY"]) minNCrossedChambers = int(os.environ["ALIGNMENT_MINNCROSSEDCHAMBERS"]) +T0_Corr = (os.environ["ALIGNMENT_T0CORR"] == "True") +is_Alcareco = (os.environ["ALIGNMENT_ISALCARECO"] == "True") +is_MC = (os.environ["ALIGNMENT_ISMC"] == "True") +createLayerNtupleDT = (os.environ["ALIGNMENT_STORELAYERDT"] == "True") +createLayerNtupleCSC = (os.environ["ALIGNMENT_STORELAYERCSC"] == "True") -# optionally: create ntuples along with tmp files +# optionally: create ntuples along with tmp files createAlignNtuple = False envNtuple = os.getenv("ALIGNMENT_CREATEALIGNNTUPLE") if envNtuple is not None: @@ -77,28 +72,8 @@ doDT = False doCSC = True -# optionally use JSON file for good limi mask -good_lumis = [] -json_file = os.getenv("ALIGNMENT_JSON") -#json_file = 'Cert_136035-144114_7TeV_StreamExpress_Collisions10_JSON.txt' -if json_file is not None and json_file != '': - jsonfile=file(json_file, 'r') - jsondict = json.load(jsonfile) - runs = sorted(jsondict.keys()) - for run in runs: - blocks = sorted(jsondict[run]) - prevblock = [-2,-2] - for lsrange in blocks: - if lsrange[0] == prevblock[1]+1: - #print "Run: ",run,"- This lumi starts at ", lsrange[0], " previous ended at ", prevblock[1]+1, " so I should merge" - prevblock[1] = lsrange[1] - good_lumis[-1] = str("%s:%s-%s:%s" % (run, prevblock[0], run, prevblock[1])) - else: - good_lumis.append(str("%s:%s-%s:%s" % (run, lsrange[0], run, lsrange[1]))) - prevblock = lsrange - - -process = cms.Process("GATHER") +from Configuration.Eras.Era_Run3_cff import Run3 +process = cms.Process("GATHER", Run3) process.load("Geometry.MuonNumbering.muonNumberingInitialization_cfi") process.load("Geometry.DTGeometry.dtGeometry_cfi") @@ -107,41 +82,36 @@ process.load("Geometry.CommonTopologies.bareGlobalTrackingGeometry_cfi") #add TrackDetectorAssociator lookup maps to the EventSetup -process.load("TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff") -from TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff import * -from TrackingTools.TrackAssociator.default_cfi import * +process.load("TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff") +from TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff import * +from TrackingTools.TrackAssociator.default_cfi import * process.load("Configuration.StandardSequences.Reconstruction_cff") +process.load('TrackingTools.TransientTrack.TransientTrackBuilder_cfi') -process.MuonNumberingInitialization = cms.ESProducer("MuonNumberingInitialization") -process.MuonNumberingRecord = cms.ESSource( "EmptyESSource", - recordName = cms.string( "MuonNumberingRecord" ), - iovIsRunNotTime = cms.bool( True ), - firstValid = cms.vuint32( 1 ) -) - -process.load("Configuration.StandardSequences.GeometryDB_cff") -process.load('Configuration.StandardSequences.MagneticField_cff') - -if len(good_lumis)>0: - process.source = cms.Source("PoolSource", - fileNames = cms.untracked.vstring(*inputfiles), - skipEvents = cms.untracked.uint32(skipEvents), - lumisToProcess = cms.untracked.VLuminosityBlockRange(*good_lumis)) +if is_MC: + process.load('Configuration.StandardSequences.SimIdeal_cff') + process.load('Configuration.StandardSequences.GeometryRecoDB_cff') else: - process.source = cms.Source("PoolSource", - fileNames = cms.untracked.vstring(*inputfiles), - skipEvents = cms.untracked.uint32(skipEvents)) + process.load('Configuration.StandardSequences.GeometryRecoDB_cff') +process.load('Configuration.StandardSequences.MagneticField_AutoFromDBCurrent_cff') +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring(*inputfiles), + skipEvents = cms.untracked.uint32(skipEvents)) +json_file = os.getenv("ALIGNMENT_JSON") +if len(json_file) > 0: + import FWCore.PythonUtilities.LumiList as LumiList + process.source.lumisToProcess = LumiList.LumiList(filename = json_file).getVLuminosityBlockRange() process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(maxEvents)) #process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) ) -process.MessageLogger = cms.Service("MessageLogger", - destinations = cms.untracked.vstring("cout"), - cout = cms.untracked.PSet(threshold = cms.untracked.string("ERROR"), - ERROR = cms.untracked.PSet(limit = cms.untracked.int32(10)))) +# process.MessageLogger = cms.Service("MessageLogger", +# destinations = cms.untracked.vstring("cout"), +# cout = cms.untracked.PSet(threshold = cms.untracked.string("ERROR"), +# ERROR = cms.untracked.PSet(limit = cms.untracked.int32(10)))) process.load("Alignment.MuonAlignmentAlgorithms.MuonAlignmentFromReference_cff") process.looper.ParameterBuilder.Selector.alignParams = cms.vstring("MuonDTChambers,%s,stations123" % station123params, "MuonDTChambers,%s,station4" % station4params, "MuonCSCChambers,%s" % cscparams) @@ -168,6 +138,8 @@ process.looper.algoConfig.minDT13Hits = 7 process.looper.algoConfig.doDT = doDT process.looper.algoConfig.doCSC = doCSC +process.looper.algoConfig.createLayerNtupleDT = createLayerNtupleDT +process.looper.algoConfig.createLayerNtupleCSC = createLayerNtupleCSC process.looper.monitorConfig = cms.PSet(monitors = cms.untracked.vstring()) @@ -229,6 +201,7 @@ process.looper.monitorConfig.AlignmentMonitorMuonVsCurvature.doCSC = doCSC process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") +print(f'Using global tag: {globaltag}') process.GlobalTag.globaltag = cms.string(globaltag) process.looper.applyDbAlignment = True process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi") @@ -239,21 +212,44 @@ process.MuonAlignmentPreFilter.minTrackerHits = minTrackerHits process.MuonAlignmentPreFilter.allowTIDTEC = allowTIDTEC +##T0 Correction on DT need GlobalMuons to be reconstructed +if T0_Corr: + process.load("RecoLocalMuon.Configuration.RecoLocalMuon_cff") + process.load("RecoMuon.MuonSeedGenerator.ancientMuonSeed_cfi") + process.load("RecoMuon.StandAloneMuonProducer.standAloneMuons_cfi") + process.load("RecoMuon.GlobalMuonProducer.globalMuons_cfi") + if is_Alcareco: + process.globalMuons.TrackerCollectionLabel = cms.InputTag("ALCARECOMuAlCalIsolatedMuGeneralTracks") + else: + process.globalMuons.TrackerCollectionLabel = cms.InputTag("generalTracks") + process.Mymuonlocalreco = cms.Sequence(process.dt4DSegments * process.ancientMuonSeed * process.standAloneMuons * process.globalMuons ) + process.dt4DSegments.Reco4DAlgoConfig.performT0SegCorrection = cms.bool(True) + + if iscosmics: process.MuonAlignmentPreFilter.tracksTag = cms.InputTag("ALCARECOMuAlGlobalCosmics:GlobalMuon") if preFilter: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentPreFilter * process.MuonAlignmentFromReferenceGlobalCosmicRefit) else: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentFromReferenceGlobalCosmicRefit) process.looper.tjTkAssociationMapTag = cms.InputTag("MuonAlignmentFromReferenceGlobalCosmicRefit:Refitted") else: - #process.MuonAlignmentPreFilter.tracksTag = cms.InputTag("ALCARECOMuAlCalIsolatedMu:GlobalMuon") - process.MuonAlignmentPreFilter.tracksTag = cms.InputTag("globalMuons") + if is_Alcareco: + process.MuonAlignmentPreFilter.tracksTag = cms.InputTag("ALCARECOMuAlCalIsolatedMu:GlobalMuon") + process.MuonAlignmentFromReferenceGlobalMuonRefit.Tracks = cms.InputTag("ALCARECOMuAlCalIsolatedMu:GlobalMuon") + else: + process.MuonAlignmentPreFilter.tracksTag = cms.InputTag("globalMuons") + process.MuonAlignmentFromReferenceGlobalMuonRefit.Tracks = cms.InputTag("globalMuons") process.MuonAlignmentFromReferenceGlobalMuonRefit.Tracks = cms.InputTag("globalMuons") - if preFilter: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentPreFilter * process.MuonAlignmentFromReferenceGlobalMuonRefit) - else: process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentFromReferenceGlobalMuonRefit) + if preFilter: + process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentPreFilter * process.MuonAlignmentFromReferenceGlobalMuonRefit) + else: + if T0_Corr: + process.Path = cms.Path(process.offlineBeamSpot * process.Mymuonlocalreco * process.MuonAlignmentFromReferenceGlobalMuonRefit) + else: + process.Path = cms.Path(process.offlineBeamSpot * process.MuonAlignmentFromReferenceGlobalMuonRefit) process.looper.tjTkAssociationMapTag = cms.InputTag("MuonAlignmentFromReferenceGlobalMuonRefit:Refitted") -if len(muonCollectionTag) > 0: # use Tracker Muons +if len(muonCollectionTag) > 0: # use Tracker Muons process.Path = cms.Path(process.offlineBeamSpot * process.newmuons) @@ -261,73 +257,58 @@ process.MuonAlignmentFromReferenceInputDB.toGet = cms.VPSet(cms.PSet(record = cms.string("DTAlignmentRcd"), tag = cms.string("DTAlignmentRcd")), cms.PSet(record = cms.string("CSCAlignmentRcd"), tag = cms.string("CSCAlignmentRcd"))) -if trackerconnect != "": - from CondCore.DBCommon.CondDBSetup_cfi import * - process.TrackerAlignmentInputDB = cms.ESSource("PoolDBESSource", - CondDBSetup, - connect = cms.string(trackerconnect), - toGet = cms.VPSet(cms.PSet(record = cms.string("TrackerAlignmentRcd"), tag = cms.string(trackeralignment)))) - process.es_prefer_TrackerAlignmentInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentInputDB") - -if trackerAPEconnect != "": - from CondCore.DBCommon.CondDBSetup_cfi import * - process.TrackerAlignmentErrorInputDB = cms.ESSource("PoolDBESSource", - CondDBSetup, - connect = cms.string(trackerAPEconnect), - toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerAlignmentErrorExtendedRcd"), tag = cms.string(trackerAPE))))) - process.es_prefer_TrackerAlignmentErrorInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentErrorInputDB") - -if trackerBowsconnect != "": - from CondCore.DBCommon.CondDBSetup_cfi import * - process.TrackerSurfaceDeformationInputDB = cms.ESSource("PoolDBESSource", - CondDBSetup, - connect = cms.string(trackerBowsconnect), - toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerSurfaceDeformationRcd"), tag = cms.string(trackerBows))))) - process.es_prefer_TrackerSurfaceDeformationInputDB = cms.ESPrefer("PoolDBESSource", "TrackerSurfaceDeformationInputDB") - +process.es_prefer_MuonAlignmentFromReferenceInputDB = cms.ESPrefer( + "PoolDBESSource", "MuonAlignmentFromReferenceInputDB") + +from CondCore.CondDB.CondDB_cfi import * +CondDBSetup = CondDB.clone() +CondDBSetup.__delattr__('connect') +if is_MC: + if trackerconnect != "": + process.TrackerAlignmentInputDB = cms.ESSource("PoolDBESSource", + CondDBSetup, + connect = cms.string(trackerconnect), + toGet = cms.VPSet(cms.PSet(record = cms.string("TrackerAlignmentRcd"), tag = cms.string(trackeralignment)))) + process.es_prefer_TrackerAlignmentInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentInputDB") + + if trackerAPEconnect != "": + process.TrackerAlignmentErrorInputDB = cms.ESSource("PoolDBESSource", + CondDBSetup, + connect = cms.string(trackerAPEconnect), + toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerAlignmentErrorExtendedRcd"), tag = cms.string(trackerAPE))))) + process.es_prefer_TrackerAlignmentErrorInputDB = cms.ESPrefer("PoolDBESSource", "TrackerAlignmentErrorInputDB") + + if trackerBowsconnect != "": + process.TrackerSurfaceDeformationInputDB = cms.ESSource("PoolDBESSource", + CondDBSetup, + connect = cms.string(trackerBowsconnect), + toGet = cms.VPSet(cms.PSet(cms.PSet(record = cms.string("TrackerSurfaceDeformationRcd"), tag = cms.string(trackerBows))))) + process.es_prefer_TrackerSurfaceDeformationInputDB = cms.ESPrefer("PoolDBESSource", "TrackerSurfaceDeformationInputDB") +#else: #beginning 2016-rereco (ALL in 80X_dataRun2_2016LegacyRepro_Candidate_v0) +# process.GlobalTag.toGet = cms.VPSet( +# cms.PSet(record = cms.string("TrackerAlignmentRcd"), +# tag = cms.string("TrackerAlignment_EOY16_sm1959"), +# connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS') +# ), +### cms.PSet(record = cms.string("TrackerAlignmentErrorExtendedRcd"), +### tag = cms.string("TrackerAlignmentExtendedErrors_MP_Run2016B"), +### connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS') +### ), +# cms.PSet(record = cms.string("SiPixelTemplateDBObjectRcd"), +# tag = cms.string("SiPixelTemplateDBObject_38T_v10_offline"), +# connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS') +# ), +# cms.PSet(record = cms.string("TrackerSurfaceDeformationRcd"), +# tag = cms.string("TrackerSurfaceDeformations_EOY16_mp2269"), +# connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS') +# ) +# ) if gprcdconnect != "": - from CondCore.DBCommon.CondDBSetup_cfi import * - process.GlobalPositionInputDB = cms.ESSource("PoolDBESSource", - CondDBSetup, - connect = cms.string(gprcdconnect), - toGet = cms.VPSet(cms.PSet(record = cms.string("GlobalPositionRcd"), tag = cms.string(gprcd)))) - process.es_prefer_GlobalPositionInputDB = cms.ESPrefer("PoolDBESSource", "GlobalPositionInputDB") - - -## the following was needed for Nov 2010 alignment to pick up new lorentz angle and strip conditions for tracker -#process.poolDBESSourceLA = cms.ESSource("PoolDBESSource", -# BlobStreamerName = cms.untracked.string('TBufferBlobStreamingService'), -# DBParameters = cms.PSet( -# messageLevel = cms.untracked.int32(0), -# authenticationPath = cms.untracked.string('.') -# #messageLevel = cms.untracked.int32(2), -# #authenticationPath = cms.untracked.string('/path/to/authentication') -# ), -# timetype = cms.untracked.string('runnumber'), -# connect = cms.string('frontier://PromptProd/CMS_COND_31X_STRIP'), -# toGet = cms.VPSet(cms.PSet( -# record = cms.string('SiStripLorentzAngleRcd'), -# tag = cms.string('SiStripLorentzAngle_GR10_v2_offline') -# )) -#) -#process.es_prefer_LA = cms.ESPrefer('PoolDBESSource','poolDBESSourceLA') -# -#process.poolDBESSourceBP = cms.ESSource("PoolDBESSource", -# BlobStreamerName = cms.untracked.string('TBufferBlobStreamingService'), -# DBParameters = cms.PSet( -# messageLevel = cms.untracked.int32(0), -# authenticationPath = cms.untracked.string('.') -# #messageLevel = cms.untracked.int32(2), -# #authenticationPath = cms.untracked.string('/path/to/authentication') -# ), -# timetype = cms.untracked.string('runnumber'), -# connect = cms.string('frontier://PromptProd/CMS_COND_31X_STRIP'), -# toGet = cms.VPSet(cms.PSet( -# record = cms.string('SiStripConfObjectRcd'), -# tag = cms.string('SiStripShiftAndCrosstalk_GR10_v2_offline') -# )) -#) -#process.es_prefer_BP = cms.ESPrefer('PoolDBESSource','poolDBESSourceBP') + process.GlobalPositionInputDB = cms.ESSource("PoolDBESSource", + CondDBSetup, + connect = cms.string(gprcdconnect), + toGet = cms.VPSet(cms.PSet(record = cms.string("GlobalPositionRcd"), tag = cms.string(gprcd)))) + process.es_prefer_GlobalPositionInputDB = cms.ESPrefer("PoolDBESSource", "GlobalPositionInputDB") process.looper.saveToDB = False @@ -335,3 +316,21 @@ del process.PoolDBOutputService process.TFileService = cms.Service("TFileService", fileName = cms.string("plotting%03d.root" % jobnumber)) + +maxEvts = process.maxEvents.input.value() +if maxEvts > 10000 or maxEvts < 0: + process.MessageLogger.cerr.FwkReport.reportEvery = 1000 +elif maxEvts > 10: + process.MessageLogger.cerr.FwkReport.reportEvery = maxEvts//10 + +# process.MessageLogger.cerr.threshold = "DEBUG" +# process.MessageLogger.cerr.INFO = cms.untracked.PSet( +# limit = cms.untracked.int32(-1) # -1 = unlimited +# ) +# process.MessageLogger.cerr.default = cms.untracked.PSet( +# limit = cms.untracked.int32(-1) # -1 = unlimited +# ) + +# process.Tracer = cms.Service("Tracer") + +# print(process.dumpPython()) diff --git a/Alignment/MuonAlignmentAlgorithms/scripts/alignmentValidation.py b/Alignment/MuonAlignmentAlgorithms/scripts/alignmentValidation.py index de94251351de6..ff445f39f76e8 100755 --- a/Alignment/MuonAlignmentAlgorithms/scripts/alignmentValidation.py +++ b/Alignment/MuonAlignmentAlgorithms/scripts/alignmentValidation.py @@ -6,7 +6,10 @@ from mutypes import * -execfile("plotscripts.py") +# execfile("plotscripts.py") +exec(open("./plotscripts.py").read()) +# from plotscripts import * +print("plotscripts.py loaded") ROOT.gROOT.SetBatch(1); @@ -297,7 +300,7 @@ def isFileUnderDir(dir_name, file_name): # to time saving of plots -def saveAs(nm): +def saveAs(nm): t1 = time.time() ddt[15] += 1 c1.SaveAs(nm) @@ -377,7 +380,7 @@ def doMapPlotsDT(dt_basedir, tfiles_plotting): of x, y, dxdz, dydz vs. z (y and dydz only for stations 1-3) made for all stations - Interface: may be arranged into station(1 .. 4) map + Interface: may be arranged into station(1 .. 4) map It could be incorporated into an EXTENDED general DT chambers map (extended by adding an identifier "ALL" in column1 for wheel number).""" @@ -436,7 +439,7 @@ def doMapPlotsDT(dt_basedir, tfiles_plotting): label = "DTvsz_st%ssecALL" % (station[1]) htitle = "station %s" % (station[1]) - print(label, end=' ') + print(label, end=' ') mapplot(tfiles_plotting, label, "x", window=10., title=htitle, peaksbins=2) c1.SaveAs(pdir+'map_DTvsz_all_x.png') mapplot(tfiles_plotting, label, "dxdz", window=10., title=htitle, peaksbins=2) @@ -546,7 +549,7 @@ def doCurvaturePlotsDT(dt_basedir, tfiles_plotting): station 1 only! sector in "01", ..., "12" - "param" may be one of + "param" may be one of "deltax" (Delta x position residuals), "deltadxdz" (Delta (dx/dz) angular residuals), "curverr" (Delta x * d(Delta q/pT)/d(Delta x) = Delta q/pT in the absence of misalignment) - not necessary @@ -696,7 +699,7 @@ def doSegDiffPlotsCSC(csc_basedir, tfiles_plotting, iter_reports): rphi vs qpt, rphi for positive, rphi for negative ("csc_resid") drphidz vs qpt, drphidz for positive, drphidz for negative ("csc_slope") done for ME1-ME2, ME2-ME3, and ME3-ME4 stations combinations with - endcap "m" or "p" + endcap "m" or "p" ring 1 or 2 chamber 1-18 (r1) or 1-36 (r2) note: there's no ME3-ME4 plots for R2 @@ -717,10 +720,10 @@ def doSegDiffPlotsCSC(csc_basedir, tfiles_plotting, iter_reports): qcount += 1 schamber = "%02d" % ichamber pdir = csc_basedir+'/'+iendcap[0]+'/'+istation[1]+'/'+iring[1]+'/'+schamber+'/' - segdiff(tfiles_plotting, "csc_resid", dstations, + segdiff(tfiles_plotting, "csc_resid", dstations, endcap=iendcap[1], ring=int(iring[1]), chamber=ichamber, window=15.) c1.SaveAs(pdir + 'segdif_csc_resid.png') - segdiff(tfiles_plotting, "csc_slope", dstations, + segdiff(tfiles_plotting, "csc_slope", dstations, endcap=iendcap[1], ring=int(iring[1]), chamber=ichamber, window=15.) c1.SaveAs(pdir + 'segdif_csc_slope.png') @@ -731,9 +734,9 @@ def doSegDiffPlotsCSC(csc_basedir, tfiles_plotting, iter_reports): dxdz vs phi of pair ("csc_slope") contains plots for two (or one for ME4-ME3) rings done for ME1-ME2, ME2-ME3, and ME3-ME4 stations combinations with - endcap "m" or "p" - - Interface: could be accessed by clicking on ME station boxes, but only for stations 2-4 + endcap "m" or "p" + + Interface: could be accessed by clicking on ME station boxes, but only for stations 2-4 (e.g., station 2 would provide ME1-ME2 plots).""" qcount = 0 @@ -909,7 +912,7 @@ def createCanvasToIDList(fname="canvas2id_list.js"): def idsForFile(dir_name, file_name): '''Recursively looks for file named file_name under dir_name directory - and fill the list with dir names converted to IDs + and fill the list with dir names converted to IDs ''' id_list = [] for f in os.listdir(dir_name): @@ -921,7 +924,7 @@ def idsForFile(dir_name, file_name): elif os.path.isdir(dirfile): #print "Accessing directory:", dirfile ids = idsForFile(dirfile, file_name) - if (len(ids)>0): + if (len(ids)>0): id_list.extend(ids) return id_list @@ -973,7 +976,7 @@ def dirToID(d): if os.access(fname+".root",os.F_OK): iter1_tfile = ROOT.TFile(fname+".root") if os.access(fname+"_report.py",os.F_OK): - execfile(fname+"_report.py") + exec(open(fname+"_report.py").read()) iter1_reports = reports fname = options.inputDir+'/'+options.iN+'/'+iNprefix @@ -993,7 +996,7 @@ def dirToID(d): if os.access(fname+".root",os.F_OK): iterN_tfile = ROOT.TFile(fname+".root") if os.access(fname+"_report.py",os.F_OK): - execfile(fname+"_report.py") + exec(open(fname+"_report.py").read()) iterN_reports = reports if DO_MAP: diff --git a/Alignment/MuonAlignmentAlgorithms/scripts/createJobs.py b/Alignment/MuonAlignmentAlgorithms/scripts/createJobs.py deleted file mode 100755 index 0a457f99e6e18..0000000000000 --- a/Alignment/MuonAlignmentAlgorithms/scripts/createJobs.py +++ /dev/null @@ -1,756 +0,0 @@ -#! /usr/bin/env python3 - -from builtins import range -import os, sys, optparse, math - -copyargs = sys.argv[:] -for i in range(len(copyargs)): - if copyargs[i] == "": - copyargs[i] = "\"\"" - if copyargs[i].find(" ") != -1: - copyargs[i] = "\"%s\"" % copyargs[i] -commandline = " ".join(copyargs) - -prog = sys.argv[0] - -usage = """./%(prog)s DIRNAME ITERATIONS INITIALGEOM INPUTFILES [options] - -Creates (overwrites) a directory for each of the iterations and creates (overwrites) -submitJobs.sh with the submission sequence and dependencies. - -DIRNAME directories will be named DIRNAME01, DIRNAME02, etc. -ITERATIONS number of iterations -INITIALGEOM SQLite file containing muon geometry with tag names - DTAlignmentRcd, DTAlignmentErrorExtendedRcd, CSCAlignmentRcd, CSCAlignmentErrorExtendedRcd -INPUTFILES Python file defining 'fileNames', a list of input files as - strings (create with findQualityFiles.py)""" % vars() - -parser = optparse.OptionParser(usage) -parser.add_option("-j", "--jobs", - help="approximate number of \"gather\" subjobs", - type="int", - default=50, - dest="subjobs") -parser.add_option("-s", "--submitJobs", - help="alternate name of submitJobs.sh script (please include .sh extension); a file with this name will be OVERWRITTEN", - type="string", - default="submitJobs.sh", - dest="submitJobs") -parser.add_option("-b", "--big", - help="if invoked, subjobs will also be run on cmscaf1nd", - action="store_true", - dest="big") -parser.add_option("-u", "--user_mail", - help="if invoked, send mail to a specified email destination. If \"-u\" is not present, the default destination LSB_MAILTO in lsf.conf will be used", - type="string", - dest="user_mail") -parser.add_option("--mapplots", - help="if invoked, draw \"map plots\"", - action="store_true", - dest="mapplots") -parser.add_option("--segdiffplots", - help="if invoked, draw \"segment-difference plots\"", - action="store_true", - dest="segdiffplots") -parser.add_option("--curvatureplots", - help="if invoked, draw \"curvature plots\"", - action="store_true", - dest="curvatureplots") -parser.add_option("--globalTag", - help="GlobalTag for alignment/calibration conditions (typically all conditions except muon and tracker alignment)", - type="string", - default="CRAFT0831X_V1::All", - dest="globaltag") -parser.add_option("--trackerconnect", - help="connect string for tracker alignment (frontier://FrontierProd/CMS_COND_310X_ALIGN or sqlite_file:...)", - type="string", - default="", - dest="trackerconnect") -parser.add_option("--trackeralignment", - help="name of TrackerAlignmentRcd tag", - type="string", - default="Alignments", - dest="trackeralignment") -parser.add_option("--trackerAPEconnect", - help="connect string for tracker APEs (frontier://... or sqlite_file:...)", - type="string", - default="", - dest="trackerAPEconnect") -parser.add_option("--trackerAPE", - help="name of TrackerAlignmentErrorExtendedRcd tag (tracker APEs)", - type="string", - default="AlignmentErrorsExtended", - dest="trackerAPE") -parser.add_option("--trackerBowsconnect", - help="connect string for tracker Surface Deformations (frontier://... or sqlite_file:...)", - type="string", - default="", - dest="trackerBowsconnect") -parser.add_option("--trackerBows", - help="name of TrackerSurfaceDeformationRcd tag", - type="string", - default="TrackerSurfaceDeformations", - dest="trackerBows") -parser.add_option("--gprcdconnect", - help="connect string for GlobalPositionRcd (frontier://... or sqlite_file:...)", - type="string", - default="", - dest="gprcdconnect") -parser.add_option("--gprcd", - help="name of GlobalPositionRcd tag", - type="string", - default="GlobalPosition", - dest="gprcd") -parser.add_option("--iscosmics", - help="if invoked, use cosmic track refitter instead of the standard one", - action="store_true", - dest="iscosmics") -parser.add_option("--station123params", - help="alignable parameters for DT stations 1, 2, 3 (see SWGuideAlignmentAlgorithms#Selection_of_what_to_align)", - type="string", - default="111111", - dest="station123params") -parser.add_option("--station4params", - help="alignable parameters for DT station 4", - type="string", - default="100011", - dest="station4params") -parser.add_option("--cscparams", - help="alignable parameters for CSC chambers", - type="string", - default="100011", - dest="cscparams") -parser.add_option("--minTrackPt", - help="minimum allowed track transverse momentum (in GeV)", - type="string", - default="0", - dest="minTrackPt") -parser.add_option("--maxTrackPt", - help="maximum allowed track transverse momentum (in GeV)", - type="string", - default="1000", - dest="maxTrackPt") -parser.add_option("--minTrackP", - help="minimum allowed track momentum (in GeV)", - type="string", - default="0", - dest="minTrackP") -parser.add_option("--maxTrackP", - help="maximum allowed track momentum (in GeV)", - type="string", - default="10000", - dest="maxTrackP") -parser.add_option("--minTrackerHits", - help="minimum number of tracker hits", - type="int", - default=15, - dest="minTrackerHits") -parser.add_option("--maxTrackerRedChi2", - help="maximum tracker chi^2 per degrees of freedom", - type="string", - default="10", - dest="maxTrackerRedChi2") -parser.add_option("--notAllowTIDTEC", - help="if invoked, do not allow tracks that pass through the tracker's TID||TEC region (not recommended)", - action="store_true", - dest="notAllowTIDTEC") -parser.add_option("--twoBin", - help="if invoked, apply the \"two-bin method\" to control charge-antisymmetric errors", - action="store_true", - dest="twoBin") -parser.add_option("--weightAlignment", - help="if invoked, segments will be weighted by ndf/chi^2 in the alignment", - action="store_true", - dest="weightAlignment") -parser.add_option("--minAlignmentSegments", - help="minimum number of segments required to align a chamber", - type="int", - default=5, - dest="minAlignmentHits") -parser.add_option("--notCombineME11", - help="if invoced, treat ME1/1a and ME1/1b as separate objects", - action="store_true", - dest="notCombineME11") -parser.add_option("--maxEvents", - help="maximum number of events", - type="string", - default="-1", - dest="maxEvents") -parser.add_option("--skipEvents", - help="number of events to be skipped", - type="string", - default="0", - dest="skipEvents") -parser.add_option("--validationLabel", - help="if given nonempty string RUNLABEL, diagnostics and creation of plots will be run in the end of the last iteration; the RUNLABEL will be used to mark a run; the results will be put into a RUNLABEL_DATESTAMP.tgz tarball", - type="string", - default="", - dest="validationLabel") -parser.add_option("--maxResSlopeY", - help="maximum residual slope y component", - type="string", - default="10", - dest="maxResSlopeY") -parser.add_option("--motionPolicyNSigma", - help="minimum nsigma(deltax) position displacement in order to move a chamber for the final alignment result; default NSIGMA=3", - type="int", - default=3, - dest="motionPolicyNSigma") -parser.add_option("--noCleanUp", - help="if invoked, temporary plotting???.root and *.tmp files would not be removed at the end of each align job", - action="store_true", - dest="noCleanUp") -parser.add_option("--noCSC", - help="if invoked, CSC endcap chambers would not be processed", - action="store_true", - dest="noCSC") -parser.add_option("--noDT", - help="if invoked, DT barrel chambers would not be processed", - action="store_true", - dest="noDT") -parser.add_option("--createMapNtuple", - help="if invoked while mapplots are switched on, a special ntuple would be created", - action="store_true", - dest="createMapNtuple") -parser.add_option("--inputInBlocks", - help="if invoked, assume that INPUTFILES provides a list of files already groupped into job blocks, -j has no effect in that case", - action="store_true", - dest="inputInBlocks") -parser.add_option("--json", - help="If present with JSON file as argument, use JSON file for good lumi mask. "+\ - "The latest JSON file is available at /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions11/7TeV/Prompt/", - type="string", - default="", - dest="json") -parser.add_option("--createAlignNtuple", - help="if invoked, debug ntuples with residuals would be created during gather jobs", - action="store_true", - dest="createAlignNtuple") -parser.add_option("--residualsModel", - help="functional residuals model. Possible vaslues: pureGaussian2D (default), pureGaussian, GaussPowerTails, ROOTVoigt, powerLawTails", - type="string", - default="pureGaussian2D", - dest="residualsModel") -parser.add_option("--useResiduals", - help="select residuals to use, possible values: 1111, 1110, 1100, 1010, 0010 that correspond to x y dxdz dydz residuals", - type="string", - default="1110", - dest="useResiduals") -parser.add_option("--peakNSigma", - help="if >0, only residuals peaks within n-sigma multidimentional ellipsoid would be considered in the alignment fit", - type="string", - default="-1.", - dest="peakNSigma") -parser.add_option("--preFilter", - help="if invoked, MuonAlignmentPreFilter module would be invoked in the Path's beginning. Can significantly speed up gather jobs.", - action="store_true", - dest="preFilter") -parser.add_option("--muonCollectionTag", - help="If empty, use trajectories. If not empty, it's InputTag of muons collection to use in tracker muons based approach, e.g., 'newmuons' or 'muons'", - type="string", - default="", - dest="muonCollectionTag") -parser.add_option("--maxDxy", - help="maximum track impact parameter with relation to beamline", - type="string", - default="1000.", - dest="maxDxy") -parser.add_option("--minNCrossedChambers", - help="minimum number of muon chambers that a track is required to cross", - type="string", - default="3", - dest="minNCrossedChambers") -parser.add_option("--extraPlots", - help="produce additional plots with geometry, reports differences, and corrections visulizations", - action="store_true", - dest="extraPlots") - -if len(sys.argv) < 5: - raise SystemError("Too few arguments.\n\n"+parser.format_help()) - -DIRNAME = sys.argv[1] -ITERATIONS = int(sys.argv[2]) -INITIALGEOM = sys.argv[3] -INPUTFILES = sys.argv[4] - -options, args = parser.parse_args(sys.argv[5:]) -user_mail = options.user_mail -mapplots_ingeneral = options.mapplots -segdiffplots_ingeneral = options.segdiffplots -curvatureplots_ingeneral = options.curvatureplots -globaltag = options.globaltag -trackerconnect = options.trackerconnect -trackeralignment = options.trackeralignment -trackerAPEconnect = options.trackerAPEconnect -trackerAPE = options.trackerAPE -trackerBowsconnect = options.trackerBowsconnect -trackerBows = options.trackerBows -gprcdconnect = options.gprcdconnect -gprcd = options.gprcd -iscosmics = str(options.iscosmics) -station123params = options.station123params -station4params = options.station4params -cscparams = options.cscparams -muonCollectionTag = options.muonCollectionTag -minTrackPt = options.minTrackPt -maxTrackPt = options.maxTrackPt -minTrackP = options.minTrackP -maxTrackP = options.maxTrackP -maxDxy = options.maxDxy -minTrackerHits = str(options.minTrackerHits) -maxTrackerRedChi2 = options.maxTrackerRedChi2 -minNCrossedChambers = options.minNCrossedChambers -allowTIDTEC = str(not options.notAllowTIDTEC) -twoBin = str(options.twoBin) -weightAlignment = str(options.weightAlignment) -minAlignmentHits = str(options.minAlignmentHits) -combineME11 = str(not options.notCombineME11) -maxEvents = options.maxEvents -skipEvents = options.skipEvents -validationLabel = options.validationLabel -maxResSlopeY = options.maxResSlopeY -theNSigma = options.motionPolicyNSigma -residualsModel = options.residualsModel -peakNSigma = options.peakNSigma -preFilter = not not options.preFilter -extraPlots = options.extraPlots -useResiduals = options.useResiduals - - -#print "check: ", allowTIDTEC, combineME11, preFilter - -doCleanUp = not options.noCleanUp -createMapNtuple = not not options.createMapNtuple -createAlignNtuple = not not options.createAlignNtuple - -doCSC = True -if options.noCSC: doCSC = False -doDT = True -if options.noDT: doDT = False -if options.noCSC and options.noDT: - print("cannot do --noCSC and --noDT at the same time!") - sys.exit() - -json_file = options.json - -fileNames=[] -fileNamesBlocks=[] -execfile(INPUTFILES) -njobs = options.subjobs -if (options.inputInBlocks): - njobs = len(fileNamesBlocks) - if njobs==0: - print("while --inputInBlocks is specified, the INPUTFILES has no blocks!") - sys.exit() - -stepsize = int(math.ceil(1.*len(fileNames)/options.subjobs)) - -pwd = str(os.getcwd()) - -copytrackerdb = "" -if trackerconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerconnect[12:] -if trackerAPEconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerAPEconnect[12:] -if trackerBowsconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerBowsconnect[12:] -if gprcdconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % gprcdconnect[12:] - - -##################################################################### -# step 0: convert initial geometry to xml -INITIALXML = INITIALGEOM + '.xml' -if INITIALGEOM[-3:]=='.db': - INITIALXML = INITIALGEOM[:-3] + '.xml' -print("Converting",INITIALGEOM,"to",INITIALXML," ...will be done in several seconds...") -print("./Alignment/MuonAlignmentAlgorithms/scripts/convertSQLiteXML.py %s %s --gprcdconnect %s --gprcd %s" % (INITIALGEOM,INITIALXML,gprcdconnect,gprcd)) -exit_code = os.system("./Alignment/MuonAlignmentAlgorithms/scripts/convertSQLiteXML.py %s %s --gprcdconnect %s --gprcd %s" % (INITIALGEOM,INITIALXML,gprcdconnect,gprcd)) -if exit_code>0: - print("problem: conversion exited with code:", exit_code) - sys.exit() - -##################################################################### - -def writeGatherCfg(fname, my_vars): - file(fname, "w").write("""#/bin/sh -# %(commandline)s - -export ALIGNMENT_CAFDIR=`pwd` - -cd %(pwd)s -eval `scramv1 run -sh` -export ALIGNMENT_AFSDIR=`pwd` - -export ALIGNMENT_INPUTFILES='%(inputfiles)s' -export ALIGNMENT_ITERATION=%(iteration)d -export ALIGNMENT_JOBNUMBER=%(jobnumber)d -export ALIGNMENT_MAPPLOTS=%(mapplots)s -export ALIGNMENT_SEGDIFFPLOTS=%(segdiffplots)s -export ALIGNMENT_CURVATUREPLOTS=%(curvatureplots)s -export ALIGNMENT_GLOBALTAG=%(globaltag)s -export ALIGNMENT_INPUTDB=%(inputdb)s -export ALIGNMENT_TRACKERCONNECT=%(trackerconnect)s -export ALIGNMENT_TRACKERALIGNMENT=%(trackeralignment)s -export ALIGNMENT_TRACKERAPECONNECT=%(trackerAPEconnect)s -export ALIGNMENT_TRACKERAPE=%(trackerAPE)s -export ALIGNMENT_TRACKERBOWSCONNECT=%(trackerBowsconnect)s -export ALIGNMENT_TRACKERBOWS=%(trackerBows)s -export ALIGNMENT_GPRCDCONNECT=%(gprcdconnect)s -export ALIGNMENT_GPRCD=%(gprcd)s -export ALIGNMENT_ISCOSMICS=%(iscosmics)s -export ALIGNMENT_STATION123PARAMS=%(station123params)s -export ALIGNMENT_STATION4PARAMS=%(station4params)s -export ALIGNMENT_CSCPARAMS=%(cscparams)s -export ALIGNMENT_MUONCOLLECTIONTAG=%(muonCollectionTag)s -export ALIGNMENT_MINTRACKPT=%(minTrackPt)s -export ALIGNMENT_MAXTRACKPT=%(maxTrackPt)s -export ALIGNMENT_MINTRACKP=%(minTrackP)s -export ALIGNMENT_MAXTRACKP=%(maxTrackP)s -export ALIGNMENT_MAXDXY=%(maxDxy)s -export ALIGNMENT_MINTRACKERHITS=%(minTrackerHits)s -export ALIGNMENT_MAXTRACKERREDCHI2=%(maxTrackerRedChi2)s -export ALIGNMENT_MINNCROSSEDCHAMBERS=%(minNCrossedChambers)s -export ALIGNMENT_ALLOWTIDTEC=%(allowTIDTEC)s -export ALIGNMENT_TWOBIN=%(twoBin)s -export ALIGNMENT_WEIGHTALIGNMENT=%(weightAlignment)s -export ALIGNMENT_MINALIGNMENTHITS=%(minAlignmentHits)s -export ALIGNMENT_COMBINEME11=%(combineME11)s -export ALIGNMENT_MAXEVENTS=%(maxEvents)s -export ALIGNMENT_SKIPEVENTS=%(skipEvents)s -export ALIGNMENT_MAXRESSLOPEY=%(maxResSlopeY)s -export ALIGNMENT_DO_DT=%(doDT)s -export ALIGNMENT_DO_CSC=%(doCSC)s -export ALIGNMENT_JSON=%(json_file)s -export ALIGNMENT_CREATEMAPNTUPLE=%(createMapNtuple)s -#export ALIGNMENT_CREATEALIGNNTUPLE=%(createAlignNtuple)s -export ALIGNMENT_PREFILTER=%(preFilter)s - - -if [ \"zzz$ALIGNMENT_JSON\" != \"zzz\" ]; then - cp -f $ALIGNMENT_JSON $ALIGNMENT_CAFDIR/ -fi - -cp -f %(directory)sgather_cfg.py %(inputdbdir)s%(inputdb)s %(copytrackerdb)s $ALIGNMENT_CAFDIR/ -cd $ALIGNMENT_CAFDIR/ -ls -l -cmsRun gather_cfg.py -ls -l -cp -f *.tmp %(copyplots)s $ALIGNMENT_AFSDIR/%(directory)s -""" % my_vars) - -##################################################################### - -def writeAlignCfg(fname, my_vars): - file("%salign.sh" % directory, "w").write("""#!/bin/sh -# %(commandline)s - -export ALIGNMENT_CAFDIR=`pwd` - -cd %(pwd)s -eval `scramv1 run -sh` -export ALIGNMENT_AFSDIR=`pwd` -export ALIGNMENT_INPUTDB=%(inputdb)s -export ALIGNMENT_ITERATION=%(iteration)d -export ALIGNMENT_GLOBALTAG=%(globaltag)s -export ALIGNMENT_TRACKERCONNECT=%(trackerconnect)s -export ALIGNMENT_TRACKERALIGNMENT=%(trackeralignment)s -export ALIGNMENT_TRACKERAPECONNECT=%(trackerAPEconnect)s -export ALIGNMENT_TRACKERAPE=%(trackerAPE)s -export ALIGNMENT_TRACKERBOWSCONNECT=%(trackerBowsconnect)s -export ALIGNMENT_TRACKERBOWS=%(trackerBows)s -export ALIGNMENT_GPRCDCONNECT=%(gprcdconnect)s -export ALIGNMENT_GPRCD=%(gprcd)s -export ALIGNMENT_ISCOSMICS=%(iscosmics)s -export ALIGNMENT_STATION123PARAMS=%(station123params)s -export ALIGNMENT_STATION4PARAMS=%(station4params)s -export ALIGNMENT_CSCPARAMS=%(cscparams)s -export ALIGNMENT_MINTRACKPT=%(minTrackPt)s -export ALIGNMENT_MAXTRACKPT=%(maxTrackPt)s -export ALIGNMENT_MINTRACKP=%(minTrackP)s -export ALIGNMENT_MAXTRACKP=%(maxTrackP)s -export ALIGNMENT_MINTRACKERHITS=%(minTrackerHits)s -export ALIGNMENT_MAXTRACKERREDCHI2=%(maxTrackerRedChi2)s -export ALIGNMENT_ALLOWTIDTEC=%(allowTIDTEC)s -export ALIGNMENT_TWOBIN=%(twoBin)s -export ALIGNMENT_WEIGHTALIGNMENT=%(weightAlignment)s -export ALIGNMENT_MINALIGNMENTHITS=%(minAlignmentHits)s -export ALIGNMENT_COMBINEME11=%(combineME11)s -export ALIGNMENT_MAXRESSLOPEY=%(maxResSlopeY)s -export ALIGNMENT_CLEANUP=%(doCleanUp)s -export ALIGNMENT_CREATEALIGNNTUPLE=%(createAlignNtuple)s -export ALIGNMENT_RESIDUALSMODEL=%(residualsModel)s -export ALIGNMENT_PEAKNSIGMA=%(peakNSigma)s -export ALIGNMENT_USERESIDUALS=%(useResiduals)s - -cp -f %(directory)salign_cfg.py %(inputdbdir)s%(inputdb)s %(directory)s*.tmp %(copytrackerdb)s $ALIGNMENT_CAFDIR/ - -export ALIGNMENT_PLOTTINGTMP=`find %(directory)splotting0*.root -maxdepth 1 -size +0 -print 2> /dev/null` - -# if it's 1st or last iteration, combine _plotting.root files into one: -if [ \"$ALIGNMENT_ITERATION\" != \"111\" ] || [ \"$ALIGNMENT_ITERATION\" == \"%(ITERATIONS)s\" ]; then - #nfiles=$(ls %(directory)splotting0*.root 2> /dev/null | wc -l) - if [ \"zzz$ALIGNMENT_PLOTTINGTMP\" != \"zzz\" ]; then - hadd -f1 %(directory)s%(director)s_plotting.root %(directory)splotting0*.root - #if [ $? == 0 ] && [ \"$ALIGNMENT_CLEANUP\" == \"True\" ]; then rm %(directory)splotting0*.root; fi - fi -fi - -if [ \"$ALIGNMENT_CLEANUP\" == \"True\" ] && [ \"zzz$ALIGNMENT_PLOTTINGTMP\" != \"zzz\" ]; then - rm $ALIGNMENT_PLOTTINGTMP -fi - -cd $ALIGNMENT_CAFDIR/ -export ALIGNMENT_ALIGNMENTTMP=`find alignment*.tmp -maxdepth 1 -size +1k -print 2> /dev/null` -ls -l - -cmsRun align_cfg.py -cp -f MuonAlignmentFromReference_report.py $ALIGNMENT_AFSDIR/%(directory)s%(director)s_report.py -cp -f MuonAlignmentFromReference_outputdb.db $ALIGNMENT_AFSDIR/%(directory)s%(director)s.db -cp -f MuonAlignmentFromReference_plotting.root $ALIGNMENT_AFSDIR/%(directory)s%(director)s.root - -cd $ALIGNMENT_AFSDIR -./Alignment/MuonAlignmentAlgorithms/scripts/convertSQLiteXML.py %(directory)s%(director)s.db %(directory)s%(director)s.xml --noLayers --gprcdconnect $ALIGNMENT_GPRCDCONNECT --gprcd $ALIGNMENT_GPRCD - -export ALIGNMENT_ALIGNMENTTMP=`find %(directory)salignment*.tmp -maxdepth 1 -size +1k -print 2> /dev/null` -if [ \"$ALIGNMENT_CLEANUP\" == \"True\" ] && [ \"zzz$ALIGNMENT_ALIGNMENTTMP\" != \"zzz\" ]; then - rm $ALIGNMENT_ALIGNMENTTMP - echo " " -fi - -# if it's not 1st or last iteration, do some clean up: -if [ \"$ALIGNMENT_ITERATION\" != \"1\" ] && [ \"$ALIGNMENT_ITERATION\" != \"%(ITERATIONS)s\" ]; then - if [ \"$ALIGNMENT_CLEANUP\" == \"True\" ] && [ -e %(directory)s%(director)s.root ]; then - rm %(directory)s%(director)s.root - fi -fi - -# if it's last iteration, apply chamber motion policy -if [ \"$ALIGNMENT_ITERATION\" == \"%(ITERATIONS)s\" ]; then - # convert this iteration's geometry into detailed xml - ./Alignment/MuonAlignmentAlgorithms/scripts/convertSQLiteXML.py %(directory)s%(director)s.db %(directory)s%(director)s_extra.xml --gprcdconnect $ALIGNMENT_GPRCDCONNECT --gprcd $ALIGNMENT_GPRCD - # perform motion policy - ./Alignment/MuonAlignmentAlgorithms/scripts/motionPolicyChamber.py \ - %(INITIALXML)s %(directory)s%(director)s_extra.xml \ - %(directory)s%(director)s_report.py \ - %(directory)s%(director)s_final.xml \ - --nsigma %(theNSigma)s - # convert the resulting xml into the final sqlite geometry - ./Alignment/MuonAlignmentAlgorithms/scripts/convertSQLiteXML.py %(directory)s%(director)s_final.xml %(directory)s%(director)s_final.db --gprcdconnect $ALIGNMENT_GPRCDCONNECT --gprcd $ALIGNMENT_GPRCD -fi - -""" % my_vars) - -##################################################################### - -def writeValidationCfg(fname, my_vars): - file(fname, "w").write("""#!/bin/sh -# %(commandline)s - -export ALIGNMENT_CAFDIR=`pwd` -mkdir files -mkdir out - -cd %(pwd)s -eval `scramv1 run -sh` -ALIGNMENT_AFSDIR=`pwd` -ALIGNMENT_ITERATION=%(iteration)d -ALIGNMENT_MAPPLOTS=None -ALIGNMENT_SEGDIFFPLOTS=None -ALIGNMENT_CURVATUREPLOTS=None -ALIGNMENT_EXTRAPLOTS=%(extraPlots)s -export ALIGNMENT_GPRCDCONNECT=%(gprcdconnect)s -export ALIGNMENT_GPRCD=%(gprcd)s -export ALIGNMENT_DO_DT=%(doDT)s -export ALIGNMENT_DO_CSC=%(doCSC)s - - -# copy the scripts to CAFDIR -cd Alignment/MuonAlignmentAlgorithms/scripts/ -cp -f plotscripts.py $ALIGNMENT_CAFDIR/ -cp -f mutypes.py $ALIGNMENT_CAFDIR/ -cp -f alignmentValidation.py $ALIGNMENT_CAFDIR/ -cp -f phiedges_fitfunctions.C $ALIGNMENT_CAFDIR/ -cp -f createTree.py $ALIGNMENT_CAFDIR/ -cp -f signConventions.py $ALIGNMENT_CAFDIR/ -cp -f convertSQLiteXML.py $ALIGNMENT_CAFDIR/ -cp -f wrapperExtraPlots.sh $ALIGNMENT_CAFDIR/ -cd - -cp Alignment/MuonAlignmentAlgorithms/test/browser/tree* $ALIGNMENT_CAFDIR/out/ - -# copy the results to CAFDIR -cp -f %(directory1)s%(director1)s_report.py $ALIGNMENT_CAFDIR/files/ -cp -f %(directory)s%(director)s_report.py $ALIGNMENT_CAFDIR/files/ -cp -f %(directory1)s%(director1)s.root $ALIGNMENT_CAFDIR/files/ -cp -f %(directory)s%(director)s.root $ALIGNMENT_CAFDIR/files/ -if [ -e %(directory1)s%(director1)s_plotting.root ] && [ -e %(directory)s%(director)s_plotting.root ]; then - cp -f %(directory1)s%(director1)s_plotting.root $ALIGNMENT_CAFDIR/files/ - cp -f %(directory)s%(director)s_plotting.root $ALIGNMENT_CAFDIR/files/ - ALIGNMENT_MAPPLOTS=%(mapplots)s - ALIGNMENT_SEGDIFFPLOTS=%(segdiffplots)s - ALIGNMENT_CURVATUREPLOTS=%(curvatureplots)s -fi - -dtcsc="" -if [ $ALIGNMENT_DO_DT == \"True\" ]; then - dtcsc="--dt" -fi -if [ $ALIGNMENT_DO_CSC == \"True\" ]; then - dtcsc="${dtcsc} --csc" -fi - - -cd $ALIGNMENT_CAFDIR/ -echo \" ### Start running ###\" -date - -# do fits and median plots first -./alignmentValidation.py -l %(validationLabel)s -i $ALIGNMENT_CAFDIR --i1 files --iN files --i1prefix %(director1)s --iNprefix %(director)s -o $ALIGNMENT_CAFDIR/out --createDirSructure --dt --csc --fit --median - -if [ $ALIGNMENT_MAPPLOTS == \"True\" ]; then - ./alignmentValidation.py -l %(validationLabel)s -i $ALIGNMENT_CAFDIR --i1 files --iN files --i1prefix %(director1)s --iNprefix %(director)s -o $ALIGNMENT_CAFDIR/out $dtcsc --map -fi - -if [ $ALIGNMENT_SEGDIFFPLOTS == \"True\" ]; then - ./alignmentValidation.py -l %(validationLabel)s -i $ALIGNMENT_CAFDIR --i1 files --iN files --i1prefix %(director1)s --iNprefix %(director)s -o $ALIGNMENT_CAFDIR/out $dtcsc --segdiff -fi - -if [ $ALIGNMENT_CURVATUREPLOTS == \"True\" ]; then - ./alignmentValidation.py -l %(validationLabel)s -i $ALIGNMENT_CAFDIR --i1 files --iN files --i1prefix %(director1)s --iNprefix %(director)s -o $ALIGNMENT_CAFDIR/out $dtcsc --curvature -fi - -if [ $ALIGNMENT_EXTRAPLOTS == \"True\" ]; then - if [ \"zzz%(copytrackerdb)s\" != \"zzz\" ]; then - cp -f $ALIGNMENT_AFSDIR/%(copytrackerdb)s $ALIGNMENT_CAFDIR/ - fi - cp $ALIGNMENT_AFSDIR/inertGlobalPositionRcd.db . - ./convertSQLiteXML.py $ALIGNMENT_AFSDIR/%(INITIALGEOM)s g0.xml --noLayers --gprcdconnect $ALIGNMENT_GPRCDCONNECT --gprcd $ALIGNMENT_GPRCD - ./wrapperExtraPlots.sh -n $ALIGNMENT_ITERATION -i $ALIGNMENT_AFSDIR -0 g0.xml -z -w %(station123params)s %(dir_no_)s - mkdir out/extra - cd %(dir_no_)s - mv MB ../out/extra/ - mv ME ../out/extra/ - cd - -fi - -# run simple diagnostic -./alignmentValidation.py -l %(validationLabel)s -i $ALIGNMENT_CAFDIR --i1 files --iN files --i1prefix %(director1)s --iNprefix %(director)s -o $ALIGNMENT_CAFDIR/out --dt --csc --diagnostic - -# fill the tree browser structure: -./createTree.py -i $ALIGNMENT_CAFDIR/out - -timestamp=`date \"+%%y-%%m-%%d %%H:%%M:%%S\"` -echo \"%(validationLabel)s.plots (${timestamp})\" > out/label.txt - -ls -l out/ -timestamp=`date +%%Y%%m%%d%%H%%M%%S` -tar czf %(validationLabel)s_${timestamp}.tgz out -cp -f %(validationLabel)s_${timestamp}.tgz $ALIGNMENT_AFSDIR/ - -""" % my_vars) - - -##################################################################### - -#SUPER_SPECIAL_XY_AND_DXDZ_ITERATIONS = True -SUPER_SPECIAL_XY_AND_DXDZ_ITERATIONS = False - -bsubfile = ["#!/bin/sh", ""] -bsubnames = [] -last_align = None -directory = "" - -for iteration in range(1, ITERATIONS+1): - if iteration == 1: - inputdb = INITIALGEOM - inputdbdir = directory[:] - else: - inputdb = director + ".db" - inputdbdir = directory[:] - - directory = "%s%02d/" % (DIRNAME, iteration) - director = directory[:-1] - - dir_no_ = DIRNAME - if DIRNAME[-1]=='_': dir_no_ = DIRNAME[:-1] - - os.system("rm -rf %s; mkdir %s" % (directory, directory)) - os.system("cp Alignment/MuonAlignmentAlgorithms/python/gather_cfg.py %s" % directory) - os.system("cp Alignment/MuonAlignmentAlgorithms/python/align_cfg.py %s" % directory) - - bsubfile.append("cd %s" % directory) - - mapplots = False - if mapplots_ingeneral and (iteration == 1 or iteration == 3 or iteration == 5 or iteration == 7 or iteration == 9 or iteration == ITERATIONS): mapplots = True - segdiffplots = False - if segdiffplots_ingeneral and (iteration == 1 or iteration == ITERATIONS): segdiffplots = True - curvatureplots = False - if curvatureplots_ingeneral and (iteration == 1 or iteration == ITERATIONS): curvatureplots = True - - ### gather.sh runners for njobs - for jobnumber in range(njobs): - if not options.inputInBlocks: - inputfiles = " ".join(fileNames[jobnumber*stepsize:(jobnumber+1)*stepsize]) - else: - inputfiles = " ".join(fileNamesBlocks[jobnumber]) - - if mapplots or segdiffplots or curvatureplots: copyplots = "plotting*.root" - else: copyplots = "" - - if len(inputfiles) > 0: - gather_fileName = "%sgather%03d.sh" % (directory, jobnumber) - writeGatherCfg(gather_fileName, vars()) - os.system("chmod +x %s" % gather_fileName) - bsubfile.append("echo %sgather%03d.sh" % (directory, jobnumber)) - - if last_align is None: waiter = "" - else: waiter = "-w \"ended(%s)\"" % last_align - if options.big: queue = "cmscaf1nd" - else: queue = "cmscaf1nh" - - bsubfile.append("bsub -R \"type==SLC6_64\" -q %s -J \"%s_gather%03d\" -u youremail.tamu.edu %s gather%03d.sh" % (queue, director, jobnumber, waiter, jobnumber)) - - bsubnames.append("ended(%s_gather%03d)" % (director, jobnumber)) - - - ### align.sh - if SUPER_SPECIAL_XY_AND_DXDZ_ITERATIONS: - if ( iteration == 1 or iteration == 3 or iteration == 5 or iteration == 7 or iteration == 9): - tmp = station123params, station123params, useResiduals - station123params, station123params, useResiduals = "000010", "000010", "0010" - writeAlignCfg("%salign.sh" % directory, vars()) - station123params, station123params, useResiduals = tmp - elif ( iteration == 2 or iteration == 4 or iteration == 6 or iteration == 8 or iteration == 10): - tmp = station123params, station123params, useResiduals - station123params, station123params, useResiduals = "110001", "100001", "1100" - writeAlignCfg("%salign.sh" % directory, vars()) - station123params, station123params, useResiduals = tmp - else: - writeAlignCfg("%salign.sh" % directory, vars()) - - os.system("chmod +x %salign.sh" % directory) - - bsubfile.append("echo %salign.sh" % directory) - if user_mail: bsubfile.append("bsub -R \"type==SLC6_64\" -q cmscaf1nd -J \"%s_align\" -u %s -w \"%s\" align.sh" % (director, user_mail, " && ".join(bsubnames))) - else: bsubfile.append("bsub -R \"type==SLC6_64\" -q cmscaf1nd -J \"%s_align\" -w \"%s\" align.sh" % (director, " && ".join(bsubnames))) - - #bsubfile.append("cd ..") - bsubnames = [] - last_align = "%s_align" % director - - - ### after the last iteration (optionally) do diagnostics run - if len(validationLabel) and iteration == ITERATIONS: - # do we have plotting files created? - directory1 = "%s01/" % DIRNAME - director1 = directory1[:-1] - - writeValidationCfg("%svalidation.sh" % directory, vars()) - os.system("chmod +x %svalidation.sh" % directory) - - bsubfile.append("echo %svalidation.sh" % directory) - if user_mail: bsubfile.append("bsub -R \"type==SLC6_64\" -q cmscaf1nd -J \"%s_validation\" -u %s -w \"ended(%s)\" validation.sh" % (director, user_mail, last_align)) - else: bsubfile.append("bsub -R \"type==SLC6_64\" -q cmscaf1nd -J \"%s_validation\" -w \"ended(%s)\" validation.sh" % (director, last_align)) - - bsubfile.append("cd ..") - bsubfile.append("") - - -file(options.submitJobs, "w").write("\n".join(bsubfile)) -os.system("chmod +x %s" % options.submitJobs) diff --git a/Alignment/MuonAlignmentAlgorithms/scripts/createTree.py b/Alignment/MuonAlignmentAlgorithms/scripts/createTree.py index 68e1ad723aa47..493ef0d1772c8 100755 --- a/Alignment/MuonAlignmentAlgorithms/scripts/createTree.py +++ b/Alignment/MuonAlignmentAlgorithms/scripts/createTree.py @@ -10,7 +10,7 @@ except ImportError: import simplejson as json -from mutypes import * +from mutypes import * import pprint pp = pprint.PrettyPrinter(indent=2) @@ -33,6 +33,7 @@ "map_CSCvsphi_x.png" : "map of rphi residual vs phi", "map_CSCvsr_dxdz.png" : "map of d(rphi)/dz residual vs r", "map_CSCvsr_x.png" : "map of rphi residual vs r", +"map_CSCvsr_all_dxdz.png" : "map of d(rphi)/dz residual vs r (all)", "segdifphi_x_dt_csc_resid.png" : "segdiff DT-CSC in x residuals vs phi", "segdifphi_dt13_resid.png" : "segdiff in x residuals vs phi", "segdifphi_dt13_slope.png" : "segdiff in dxdz residuals vs phi", @@ -117,8 +118,8 @@ def parseDir(dir,label,it1="",itN=""): """it1 and itN are the first and the last iterations' directory names - dir is some directory with the results from for the LAST - iteration, so it must contain a itN substring + dir is some directory with the results from for the LAST + iteration, so it must contain a itN substring label is a label for tree's folder for this directory""" if len(itN)>0 and dir.find(itN)==-1: print("directory ", dir, "has no ", itN, " in it!!") @@ -127,16 +128,18 @@ def parseDir(dir,label,it1="",itN=""): files = sorted(os.listdir(dir)) for f in files: if re.match(".+\.png", f): + # Get title from dictionary or use filename as default + title = NAME_TO_TITLE.get(f, f.replace('.png', '').replace('_', ' ')) if len(it1)>0 and len(itN)>0: lnN = [itN,dir+'/'+f] dir1 = dir.replace(itN,it1) if not os.access(dir1+'/'+f,os.F_OK): print("WARNING: no ",dir1+'/'+f," file found!!!") ln1 = [it1,dir1+'/'+f] - ln = [NAME_TO_TITLE[f],dir+'/'+f,ln1,lnN] + ln = [title,dir+'/'+f,ln1,lnN] res.append(ln) else: - ln = [NAME_TO_TITLE[f],dir+'/'+f] + ln = [title,dir+'/'+f] #print ln res.append(ln) #pp.pprint(res) @@ -155,7 +158,7 @@ def parseDir(dir,label,it1="",itN=""): tree_level3 = parseDir(dd,wheel[0],iteration1,iterationN) for station in wheel[2]: dd = dt_basedir + wheel[0]+'/'+station[1] - print(dd) + print(dd) tree_level4 = parseDir(dd,station[0],iteration1,iterationN) for sector in range(1,station[2]+1): ssector = "%02d" % sector diff --git a/Alignment/MuonAlignmentAlgorithms/src/MuonDT13ChamberResidual.cc b/Alignment/MuonAlignmentAlgorithms/src/MuonDT13ChamberResidual.cc index 055bc60018f00..88f22e3fd139f 100644 --- a/Alignment/MuonAlignmentAlgorithms/src/MuonDT13ChamberResidual.cc +++ b/Alignment/MuonAlignmentAlgorithms/src/MuonDT13ChamberResidual.cc @@ -82,7 +82,7 @@ void MuonDT13ChamberResidual::addResidual(edm::ESHandle prop, m_hity_1 += weight; m_hity_x += weight * layerHitPos; m_hity_y += weight * hitChamberPos.y(); - m_hity_xx += weight * layerHitPos * layerPosition; + m_hity_xx += weight * layerHitPos * layerHitPos; m_hity_xy += weight * layerHitPos * hitChamberPos.y(); m_localIDs.push_back(id); diff --git a/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals1DOFFitter.cc b/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals1DOFFitter.cc index 2998355fb6ba9..e4f3e4637adb4 100644 --- a/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals1DOFFitter.cc +++ b/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals1DOFFitter.cc @@ -148,7 +148,8 @@ bool MuonResiduals1DOFFitter::fit(Alignable *ali) { high.push_back(0.); } - return dofit(&MuonResiduals1DOFFitter_FCN, num, name, start, step, low, high); + std::string chamber_id = "NULL"; + return dofit(&MuonResiduals1DOFFitter_FCN, num, name, start, step, low, high, chamber_id); } double MuonResiduals1DOFFitter::plot(std::string name, TFileDirectory *dir, Alignable *ali) { diff --git a/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals5DOFFitter.cc b/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals5DOFFitter.cc index 6401eb04d49e8..591952917764b 100644 --- a/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals5DOFFitter.cc +++ b/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals5DOFFitter.cc @@ -6,6 +6,8 @@ #include "Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals5DOFFitter.h" #endif +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/MuonDetId/interface/DTChamberId.h" #include "TH2F.h" #include "TMath.h" #include "TTree.h" @@ -111,7 +113,9 @@ void MuonResiduals5DOFFitter_FCN(int &npar, double *gin, double &fval, double *p double weight = (1. / redchi2) * number_of_hits / sum_of_weights; if (!weight_alignment) weight = 1.; - + weight *= (*resiter) + [MuonResiduals5DOFFitter:: + kWeightOccupancy]; //Weights to have flat occupancy for now (are set to 1 if the weigth-constructor has not the path to the root file with weights) if (!weight_alignment || TMath::Prob(redchi2 * 8, 8) < 0.99) // no spikes allowed { if (fitter->residualsModel() == MuonResidualsFitter::kPureGaussian) { @@ -249,7 +253,10 @@ bool MuonResiduals5DOFFitter::fit(Alignable *ali) { high.push_back(highs[idx[i]]); } - return dofit(&MuonResiduals5DOFFitter_FCN, num, name, start, step, low, high); + DTChamberId myid(ali->geomDetId().rawId()); + int wheel = myid.wheel(), station = myid.station(), sector = myid.sector(); + std::string chamber_id = std::to_string(wheel) + "_" + std::to_string(station) + "_" + std::to_string(sector); + return dofit(&MuonResiduals5DOFFitter_FCN, num, name, start, step, low, high, chamber_id); } double MuonResiduals5DOFFitter::plot(std::string name, TFileDirectory *dir, Alignable *ali) { diff --git a/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals6DOFFitter.cc b/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals6DOFFitter.cc index 206aab50f2722..8a9afb1e8b377 100644 --- a/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals6DOFFitter.cc +++ b/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals6DOFFitter.cc @@ -5,6 +5,8 @@ #else #include "Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals6DOFFitter.h" #endif +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/MuonDetId/interface/DTChamberId.h" #include "TH2F.h" #include "TMath.h" @@ -181,6 +183,9 @@ void MuonResiduals6DOFFitter_FCN(int &npar, double *gin, double &fval, double *p double weight = (1. / redchi2) * number_of_hits / sum_of_weights; if (!weight_alignment) weight = 1.; + weight *= (*resiter) + [MuonResiduals6DOFFitter:: + kWeightOccupancy]; //Weights to have flat occupancy for now (are set to 1 if the weigth-constructor has not the path to the root file with weights) if (!weight_alignment || TMath::Prob(redchi2 * 12, 12) < 0.99) // no spikes allowed { @@ -437,7 +442,10 @@ bool MuonResiduals6DOFFitter::fit(Alignable *ali) { high.push_back(highs[idx[i]]); } - return dofit(&MuonResiduals6DOFFitter_FCN, num, name, start, step, low, high); + DTChamberId myid(ali->geomDetId().rawId()); + int wheel = myid.wheel(), station = myid.station(), sector = myid.sector(); + std::string chamber_id = std::to_string(wheel) + "_" + std::to_string(station) + "_" + std::to_string(sector); + return dofit(&MuonResiduals6DOFFitter_FCN, num, name, start, step, low, high, chamber_id); } double MuonResiduals6DOFFitter::plot(std::string name, TFileDirectory *dir, Alignable *ali) { diff --git a/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals6DOFrphiFitter.cc b/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals6DOFrphiFitter.cc index 3a86cf231f62b..ceb964c3e5e49 100644 --- a/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals6DOFrphiFitter.cc +++ b/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals6DOFrphiFitter.cc @@ -158,7 +158,7 @@ void MuonResiduals6DOFrphiFitter_FCN(int &npar, double *gin, double &fval, doubl fitter->useRes() == MuonResidualsFitter::k1010) { fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma); fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma); - } else if (fitter->useRes() == MuonResidualsFitter::k1100) { + } else if (fitter->useRes() == MuonResidualsFitter::k1100 || fitter->useRes() == MuonResidualsFitter::k1000) { fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma); } else if (fitter->useRes() == MuonResidualsFitter::k0010) { fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma); @@ -168,7 +168,7 @@ void MuonResiduals6DOFrphiFitter_FCN(int &npar, double *gin, double &fval, doubl fitter->useRes() == MuonResidualsFitter::k1010) { fval += -weight * MuonResidualsFitter_logPureGaussian2D( residual, resslope, residpeak, resslopepeak, residsigma, resslopesigma, alpha); - } else if (fitter->useRes() == MuonResidualsFitter::k1100) { + } else if (fitter->useRes() == MuonResidualsFitter::k1100 || fitter->useRes() == MuonResidualsFitter::k1000) { fval += -weight * MuonResidualsFitter_logPureGaussian(residual, residpeak, residsigma); } else if (fitter->useRes() == MuonResidualsFitter::k0010) { fval += -weight * MuonResidualsFitter_logPureGaussian(resslope, resslopepeak, resslopesigma); @@ -216,11 +216,7 @@ bool MuonResiduals6DOFrphiFitter::fit(Alignable *ali) { //cscGeometry = m_cscGeometry; //cscDetId = CSCDetId(ali->geomDetId().rawId()); -#ifndef STANDALONE_FITTER csc_R = sqrt(pow(ali->globalPosition().x(), 2) + pow(ali->globalPosition().y(), 2)); -#else - csc_R = 200; // not important what number it is, as we usually not use the DOF where it matters -#endif initialize_table(); // if not already initialized sumofweights(); @@ -228,7 +224,8 @@ bool MuonResiduals6DOFrphiFitter::fit(Alignable *ali) { double res_std = 0.5; double resslope_std = 0.002; - int nums[10] = {kAlignX, + int nums[11] = {kAlignX, + kAlignY, kAlignZ, kAlignPhiX, kAlignPhiY, @@ -238,7 +235,8 @@ bool MuonResiduals6DOFrphiFitter::fit(Alignable *ali) { kAlpha, kResidGamma, kResSlopeGamma}; - std::string names[10] = {"AlignX", + std::string names[11] = {"AlignX", + "AlignY", "AlignZ", "AlignPhiX", "AlignPhiY", @@ -248,18 +246,39 @@ bool MuonResiduals6DOFrphiFitter::fit(Alignable *ali) { "Alpha", "ResidGamma", "ResSlopeGamma"}; - double starts[10] = {0., 0., 0., 0., 0., res_std, resslope_std, 0., 0.1 * res_std, 0.1 * resslope_std}; - double steps[10] = { - 0.1, 0.1, 0.001, 0.001, 0.001, 0.001 * res_std, 0.001 * resslope_std, 0.001, 0.01 * res_std, 0.01 * resslope_std}; - double lows[10] = {0., 0., 0., 0., 0., 0., 0., -1., 0., 0.}; - double highs[10] = {0., 0., 0., 0., 0., 10., 0.1, 1., 0., 0.}; - - std::vector num(nums, nums + 5); - std::vector name(names, names + 5); - std::vector start(starts, starts + 5); - std::vector step(steps, steps + 5); - std::vector low(lows, lows + 5); - std::vector high(highs, highs + 5); + double starts[11] = {0., 0., 0., 0., 0., 0., res_std, resslope_std, 0., 0.1 * res_std, 0.1 * resslope_std}; + double steps[11] = {0.1, + 0.1, + 0.1, + 0.001, + 0.001, + 0.001, + 0.001 * res_std, + 0.001 * resslope_std, + 0.001, + 0.01 * res_std, + 0.01 * resslope_std}; + double lows[11] = {0., 0., 0., 0., 0., 0., 0., 0., -1., 0., 0.}; + double highs[11] = {0., 0., 0., 0., 0., 0., 10., 0.1, 1., 0., 0.}; + // adjust the default initial values with possible custom ones: + for (std::map::iterator it = m_parNum2InitValue.begin(); it != m_parNum2InitValue.end(); ++it) { + int parNum = it->first; + int idx = -1; + for (int i = 0; i < 11; ++i) + if (nums[i] == parNum) { + idx = i; + break; + } + assert(idx >= 0); + starts[idx] = it->second; + } + + std::vector num(nums, nums + 6); + std::vector name(names, names + 6); + std::vector start(starts, starts + 6); + std::vector step(steps, steps + 6); + std::vector low(lows, lows + 6); + std::vector high(highs, highs + 6); bool add_alpha = (residualsModel() == kPureGaussian2D); bool add_gamma = (residualsModel() == kROOTVoigt || residualsModel() == kPowerLawTails); @@ -267,24 +286,24 @@ bool MuonResiduals6DOFrphiFitter::fit(Alignable *ali) { int idx[4], ni = 0; if (useRes() == k1111 || useRes() == k1110 || useRes() == k1010) { for (ni = 0; ni < 2; ni++) - idx[ni] = ni + 5; + idx[ni] = ni + 6; if (add_alpha) - idx[ni++] = 7; + idx[ni++] = 8; else if (add_gamma) for (; ni < 4; ni++) - idx[ni] = ni + 6; + idx[ni] = ni + 7; if (!add_alpha) fix(kAlpha); - } else if (useRes() == k1100) { - idx[ni++] = 5; + } else if (useRes() == k1100 || useRes() == k1000) { + idx[ni++] = 6; if (add_gamma) - idx[ni++] = 8; + idx[ni++] = 9; fix(kResSlopeSigma); fix(kAlpha); } else if (useRes() == k0010) { - idx[ni++] = 6; + idx[ni++] = 7; if (add_gamma) - idx[ni++] = 9; + idx[ni++] = 10; fix(kResidSigma); fix(kAlpha); } @@ -297,7 +316,8 @@ bool MuonResiduals6DOFrphiFitter::fit(Alignable *ali) { high.push_back(highs[idx[i]]); } - return dofit(&MuonResiduals6DOFrphiFitter_FCN, num, name, start, step, low, high); + std::string chamber_id = "NULL"; + return dofit(&MuonResiduals6DOFrphiFitter_FCN, num, name, start, step, low, high, chamber_id); } double MuonResiduals6DOFrphiFitter::plot(std::string name, TFileDirectory *dir, Alignable *ali) { diff --git a/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsAngleFitter.cc b/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsAngleFitter.cc index 8cf67310050ef..dd8697d0b5780 100644 --- a/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsAngleFitter.cc +++ b/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsAngleFitter.cc @@ -132,7 +132,8 @@ bool MuonResidualsAngleFitter::fit(Alignable *ali) { high.push_back(0.); } - return dofit(&MuonResidualsAngleFitter_FCN, parNum, parName, start, step, low, high); + std::string chamber_id = "NULL"; + return dofit(&MuonResidualsAngleFitter_FCN, parNum, parName, start, step, low, high, chamber_id); } double MuonResidualsAngleFitter::plot(std::string name, TFileDirectory *dir, Alignable *ali) { diff --git a/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsBfieldAngleFitter.cc b/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsBfieldAngleFitter.cc index bef402a2ec677..d1a333be27fdb 100644 --- a/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsBfieldAngleFitter.cc +++ b/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsBfieldAngleFitter.cc @@ -139,7 +139,8 @@ bool MuonResidualsBfieldAngleFitter::fit(Alignable *ali) { high.push_back(0.); } - return dofit(&MuonResidualsBfieldAngleFitter_FCN, parNum, parName, start, step, low, high); + std::string chamber_id = "NULL"; + return dofit(&MuonResidualsBfieldAngleFitter_FCN, parNum, parName, start, step, low, high, chamber_id); } double MuonResidualsBfieldAngleFitter::plot(std::string name, TFileDirectory *dir, Alignable *ali) { diff --git a/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsFitter.cc b/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsFitter.cc index 9562d1a63dd71..ff595b4ef0e10 100644 --- a/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsFitter.cc +++ b/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsFitter.cc @@ -5,13 +5,21 @@ #else #include "Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFitter.h" #endif +#include "Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals6DOFrphiFitter.h" +#include "DataFormats/MuonDetId/interface/MuonSubdetId.h" +#include "DataFormats/MuonDetId/interface/CSCDetId.h" +#include "DataFormats/MuonDetId/interface/DTChamberId.h" #include #include #include "TMath.h" #include "TH1.h" #include "TF1.h" +#include "TVector2.h" #include "TRobustEstimator.h" +#include "Math/MinimizerOptions.h" +#include +#include // all global variables begin with "MuonResidualsFitter_" to avoid // namespace clashes (that is, they do what would ordinarily be done @@ -160,6 +168,19 @@ MuonResidualsFitter::MuonResidualsFitter(int residualsModel, int minHits, int us if (m_residualsModel != kPureGaussian && m_residualsModel != kPowerLawTails && m_residualsModel != kROOTVoigt && m_residualsModel != kGaussPowerTails && m_residualsModel != kPureGaussian2D) throw cms::Exception("MuonResidualsFitter") << "unrecognized residualsModel"; + //Reading external file containing CSC geometry + std::ifstream infile("/afs/cern.ch/cms/CAF/CMSALCA/ALCA_MUONALIGN/MuonGeometries/muonGeometry_DESIGN_Global.txt"); + float endcap, station, ring, chamber, DX, DY, tmp1, tmp2, tmp3, tmp4; + while (infile >> endcap >> station >> ring >> chamber >> DX >> DY >> tmp1 >> tmp2 >> tmp3 >> tmp4) { + std::vector vec; + vec.clear(); + vec.push_back(endcap); + vec.push_back(station); + vec.push_back(ring); + vec.push_back(chamber); + m_RadiousOfCSC[vec] = sqrt(DX * DX + DY * DY); + vec.clear(); + } } MuonResidualsFitter::~MuonResidualsFitter() { @@ -275,7 +296,9 @@ bool MuonResidualsFitter::dofit(void (*fcn)(int &, double *, double &, double *, std::vector &start, std::vector &step, std::vector &low, - std::vector &high) { + std::vector &high, + std::string chamber_id) { + //ROOT::Math::MinimizerOptions::SetDefaultErrorDef(0.5); //Alternative way to say Minuit you have a Log-likelihood MuonResidualsFitterFitInfo *fitinfo = new MuonResidualsFitterFitInfo(this); MuonResidualsFitter_TMinuit = new TMinuit(npar()); @@ -292,12 +315,23 @@ bool MuonResidualsFitter::dofit(void (*fcn)(int &, double *, double &, double *, std::vector::const_iterator ilow = low.begin(); std::vector::const_iterator ihigh = high.begin(); - //MuonResidualsFitter_TMinuit->SetPrintLevel(-1); + // Created as a test to fix sigmaX and sigmaY to post-fit values (also a change in MuonAlignmentAlgorithms/plugins/MuonAlignmentFromReference.cc) + /*std::vector sigmas_value; sigmas_value.clear(); sigmas_value = GetSigmaValues(chamber_id); + double sigX=sigmas_value[0]; double sigY=sigmas_value[1]; + double sigX_I=sigX-0.001, sigX_F=sigX+0.001; + double sigY_I=sigY-0.001, sigY_F=sigY+0.001;*/ for (; iNum != parNum.end(); ++iNum, ++iName, ++istart, ++istep, ++ilow, ++ihigh) { MuonResidualsFitter_TMinuit->DefineParameter(*iNum, iName->c_str(), *istart, *istep, *ilow, *ihigh); if (fixed(*iNum)) MuonResidualsFitter_TMinuit->FixParameter(*iNum); + /*if( std::strcmp(iName->c_str(),"ResidXSigma")==0 || std::strcmp(iName->c_str(),"ResidYSigma")==0 || std::strcmp(iName->c_str(),"ResidSigma")==0 ){ + int ierflg; + if(std::strcmp(iName->c_str(),"ResidXSigma")==0 ) MuonResidualsFitter_TMinuit->mnparm(6, iName->c_str(), sigX, 0.0001, sigX_I, sigX_F, ierflg); + if(std::strcmp(iName->c_str(),"ResidYSigma")==0) MuonResidualsFitter_TMinuit->mnparm(7, iName->c_str(), sigY, 0.0001, sigY_I, sigY_F, ierflg); + if(std::strcmp(iName->c_str(),"ResidSigma")==0 ) MuonResidualsFitter_TMinuit->mnparm(5, iName->c_str(), sigX, 0.0001, sigX_I, sigX_F, ierflg); + MuonResidualsFitter_TMinuit->FixParameter(*iNum); + }*/ } double arglist[10]; @@ -357,6 +391,7 @@ bool MuonResidualsFitter::dofit(void (*fcn)(int &, double *, double &, double *, arglist[i] = 0.; ierflg = 0; MuonResidualsFitter_TMinuit->mnexcm("HESSE", arglist, 0, ierflg); + //MuonResidualsFitter_TMinuit->mnexcm("MINOS", arglist, 0, ierflg); //For non paraboloid Likelihood, but it was checked that errors are similar } // read-out the results @@ -716,56 +751,49 @@ void MuonResidualsFitter::selectPeakResiduals_simple(double nsigma, int nvar, in << (size_t)std::count(m_residuals_ok.begin(), m_residuals_ok.end(), true) << std::endl; } -void MuonResidualsFitter::fiducialCuts(double xMin, double xMax, double yMin, double yMax, bool fidcut1) { - int iResidual = -1; - - int n_station = 9999; - int n_wheel = 9999; - int n_sector = 9999; - - double positionX = 9999.; - double positionY = 9999.; - - double chambw = 9999.; - double chambl = 9999.; - - for (std::vector::const_iterator r = residuals_begin(); r != residuals_end(); ++r) { - iResidual++; - if (!m_residuals_ok[iResidual]) - continue; - - if ((*r)[15] > - 0.0001) { // this value is greater than zero (chamber width) for 6DOFs stations 1,2,3 better to change for type()!!! - n_station = (*r)[12]; - n_wheel = (*r)[13]; - n_sector = (*r)[14]; - positionX = (*r)[4]; - positionY = (*r)[5]; - chambw = (*r)[15]; - chambl = (*r)[16]; - } else { // in case of 5DOF residual the residual object index is different - n_station = (*r)[10]; - n_wheel = (*r)[11]; - n_sector = (*r)[12]; - positionX = (*r)[2]; - positionY = (*r)[3]; - chambw = (*r)[13]; - chambl = (*r)[14]; - } - - if (fidcut1) { // this is the standard fiducial cut used so far 80x80 cm in x,y - if (positionX >= xMax || positionX <= xMin) - m_residuals_ok[iResidual] = false; - if (positionY >= yMax || positionY <= yMin) - m_residuals_ok[iResidual] = false; - } - - // Implementation of new fiducial cut +void MuonResidualsFitter::fiducialCuts(unsigned int idx) { + DetId id(idx); + if (id.subdetId() == MuonSubdetId::DT) { + int iResidual = -1; + + int n_station = 9999; + int n_wheel = 9999; + int n_sector = 9999; + + double positionX = 9999.; + double positionY = 9999.; + + double chambw = 9999.; + double chambl = 9999.; + + for (std::vector::const_iterator r = residuals_begin(); r != residuals_end(); ++r) { + iResidual++; + + if ((*r)[10] > + 14) { // Since you don't know if you are in station 1,2,3 or 4 (the index is different) you look at the 150th one. In MuonResiduals5DOFFitter.h is the sector, in MuonResiduals6DOFFitter.h is the Pt (always bigger than 15 GeV) + n_station = (*r)[12]; + n_wheel = (*r)[13]; + n_sector = (*r)[14]; + positionX = (*r)[4]; + positionY = (*r)[5]; + chambw = (*r)[15]; + chambl = (*r)[16]; + } else { // This is sttaion 4 *5 (DOF). In case of 5DOF residual the residual object index is different (MuonAlignmentAlgorithms/interface/MuonResiduals5DOFFitter.h) + n_station = (*r)[10]; + n_wheel = (*r)[11]; + n_sector = (*r)[12]; + positionX = (*r)[2]; + positionY = (*r)[3]; + chambw = (*r)[13]; + chambl = (*r)[14]; + } + if (!m_residuals_ok[iResidual]) + continue; - double dtrkchamx = (chambw / 2.) - positionX; // variables to cut tracks on the edge of the chambers - double dtrkchamy = (chambl / 2.) - positionY; + // Implementation of new fiducial cut + double dtrkchamx = (chambw / 2.) - positionX; // variables to cut tracks on the edge of the chambers + double dtrkchamy = (chambl / 2.) - positionY; - if (!fidcut1) { if (n_station == 4) { if ((n_wheel == -1 && n_sector == 3) || (n_wheel == 1 && @@ -816,6 +844,62 @@ void MuonResidualsFitter::fiducialCuts(double xMin, double xMax, double yMin, do } } } + } //end !m_doCSC + //Fid cuts for CSC + else if (id.subdetId() == MuonSubdetId::CSC) { + CSCDetId chamberId(id.rawId()); + std::vector ChamberInfo; + ChamberInfo.clear(); + ChamberInfo.push_back(chamberId.endcap()); + ChamberInfo.push_back(chamberId.station()); + ChamberInfo.push_back(chamberId.ring()); + ChamberInfo.push_back(chamberId.chamber()); + float Radi = getRadiusFromMap(ChamberInfo); + TVector2 Radius(0, fabs(Radi)); + //Cut is different if chamber is 20 or 10 degrees width + float Fiducial_cut = 1., SizeInDegree = 10.; + if (chamberId.station() == 1 || (chamberId.station() != 1 && chamberId.ring() == 2)) + SizeInDegree = 5.; + int iResidual = -1; + for (std::vector::const_iterator r = residuals_begin(); r != residuals_end(); ++r) { + iResidual++; + if (!m_residuals_ok[iResidual]) + continue; + TVector2 LocalPoint((*r)[MuonResiduals6DOFrphiFitter::kPositionX], (*r)[MuonResiduals6DOFrphiFitter::kPositionY]); + LocalPoint += Radius; + float phi_rad = (3.14159265 / 2.) - LocalPoint.Phi(); //Angle to which I want to apply the fid. cut + float phi_deg = 180 * (phi_rad) / 3.14159265; //Angle in degree. + //Actual cut for borders + if (chamberId.station() == 1 && chamberId.ring() == 3) + // Fiducial_cut = 1.7; + Fiducial_cut = 2.7; + else + // Fiducial_cut = 1; + Fiducial_cut = 2; + if (fabs(phi_deg) > (SizeInDegree - Fiducial_cut)) + m_residuals_ok[iResidual] = false; + //Actual cut for local Y + float Y_pos = (*r)[MuonResiduals6DOFrphiFitter::kPositionY]; + if (chamberId.station() == 1 && chamberId.ring() == 1 && (Y_pos < -65 || Y_pos > 65)) + m_residuals_ok[iResidual] = false; //Need to add the gap between 1/1 and 1/4 + // if(chamberId.station()==1 && chamberId.ring()==1 && (Y_pos>-34 && Y_pos<-29) ) m_residuals_ok[iResidual] = false; //Gap between 1/1 and 1/4 should be removed? No all chambers have gaps + if (chamberId.station() == 1 && chamberId.ring() == 2 && (Y_pos < -80 || Y_pos > 80)) + m_residuals_ok[iResidual] = false; + if (chamberId.station() == 1 && chamberId.ring() == 3 && (Y_pos < -75 || Y_pos > 70)) + m_residuals_ok[iResidual] = false; + if (chamberId.station() == 2 && chamberId.ring() == 1 && (Y_pos < -80 || Y_pos > 90)) + m_residuals_ok[iResidual] = false; + if (chamberId.station() == 2 && chamberId.ring() == 2 && (Y_pos < -150 || Y_pos > 150)) + m_residuals_ok[iResidual] = false; + if (chamberId.station() == 3 && chamberId.ring() == 1 && (Y_pos < -70 || Y_pos > 80)) + m_residuals_ok[iResidual] = false; + if (chamberId.station() == 3 && chamberId.ring() == 2 && (Y_pos < -150 || Y_pos > 150)) + m_residuals_ok[iResidual] = false; + if (chamberId.station() == 4 && chamberId.ring() == 1 && (Y_pos < -60 || Y_pos > 70)) + m_residuals_ok[iResidual] = false; + if (chamberId.station() == 4 && chamberId.ring() == 2 && (Y_pos < -150 || Y_pos > 150)) + m_residuals_ok[iResidual] = false; + } } } @@ -907,3 +991,33 @@ void MuonResidualsFitter::eraseNotSelectedResiduals() { std::cout << "residuals size after eraseNotSelectedResiduals =" << m_residuals.size() << " ok size=" << m_residuals_ok.size() << std::endl; } + +// Not used. Created as a test to fix sigmaX and sigmaY to post-fit values (also a change in MuonAlignmentAlgorithms/plugins/MuonAlignmentFromReference.cc) +std::vector MuonResidualsFitter::GetSigmaValues(std::string chmaber_id) { + std::vector sigmas; + sigmas.clear(); + std::string whole_line; + // This file should contain the sigmaX and signaY post-fit values. Each line is a DT chamber and it is like: -2_1_11 0.705242 1.05453 (chamber ID, sigmaX, sigmaY). Only sigmaX in station 4. + std::ifstream infile( + "/afs/cern.ch/work/l/lpernie/MuonAlign/WD/CMSSW_8_0_24/src/FIXING_sigmas/" + "mc_DT-1100-111111_CMSSW_8_0_24_GTasym_45M_8TeV_misall_03_sigmas.txt"); + while (std::getline(infile, whole_line)) { + std::vector v_whole_line; + v_whole_line.clear(); + std::istringstream iss(whole_line); + std::string word; + while (getline(iss, word, ' ')) { + v_whole_line.push_back(word); + } + v_whole_line.push_back("-999."); + if (v_whole_line[0] == chmaber_id) { + float fl_sigmaX = std::stof(v_whole_line[1]); + float fl_sigmaY = std::stof(v_whole_line[2]); + sigmas.push_back(fl_sigmaX); + sigmas.push_back(fl_sigmaY); + return sigmas; + } + } + std::cout << "WARNING! CHAMBER NOT FOUND!" << std::endl; + return sigmas; +} diff --git a/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsFromTrack.cc b/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsFromTrack.cc index 1555b03911c7e..49ac0c6a7b791 100644 --- a/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsFromTrack.cc +++ b/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsFromTrack.cc @@ -1,5 +1,5 @@ /* - * $Id: $ + * $Id: $ */ #include "Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFromTrack.h" @@ -29,7 +29,13 @@ MuonResidualsFromTrack::MuonResidualsFromTrack(edm::ESHandle trackerRecHitBuilder, @@ -50,7 +62,13 @@ void MuonResidualsFromTrack::init(edm::ESHandle const Trajectory* traj, const reco::Track* recoTrack, AlignableNavigator* navigator, - double maxResidual) { + double maxResidual, + bool fillLayerPlotDT, + bool fillLayerPlotCSC, + struct DTLayerData* layerData_DT, + TTree* layerTree_DT, + struct CSCLayerData* layerData_CSC, + TTree* layerTree_CSC) { bool m_debug = false; if (m_debug) { @@ -63,7 +81,24 @@ void MuonResidualsFromTrack::init(edm::ESHandle reco::TransientTrack track(*m_recoTrack, &*magneticField, globalGeometry); TransientTrackingRecHit::ConstRecHitContainer recHitsForRefit; + + if (fillLayerPlotDT) { + layerData_DT->eta = m_recoTrack->eta(); + layerData_DT->phi = m_recoTrack->phi(); + layerData_DT->pz = m_recoTrack->pz(); + layerData_DT->pt = m_recoTrack->pt(); + layerData_DT->charge = m_recoTrack->charge(); + } + if (fillLayerPlotCSC) { + layerData_CSC->eta = m_recoTrack->eta(); + layerData_CSC->phi = m_recoTrack->phi(); + layerData_CSC->pz = m_recoTrack->pz(); + layerData_CSC->pt = m_recoTrack->pt(); + layerData_CSC->charge = m_recoTrack->charge(); + } + int iT = 0, iM = 0; + int iCSC = 0, iDT = 0; for (auto const& hit : m_recoTrack->recHits()) { if (hit->isValid()) { DetId hitId = hit->geographicalId(); @@ -84,11 +119,13 @@ void MuonResidualsFromTrack::init(edm::ESHandle << " is found. We do not add muon hits to refit. Dimension: " << hit->dimension() << std::endl; if (hitId.subdetId() == MuonSubdetId::DT) { const DTChamberId chamberId(hitId.rawId()); + iDT++; if (m_debug) std::cout << "Muon Hit in DT wheel " << chamberId.wheel() << " station " << chamberId.station() << " sector " << chamberId.sector() << "." << std::endl; } else if (hitId.subdetId() == MuonSubdetId::CSC) { const CSCDetId cscDetId(hitId.rawId()); + iCSC++; if (m_debug) std::cout << "Muon hit in CSC endcap " << cscDetId.endcap() << " station " << cscDetId.station() << " ring " << cscDetId.ring() << " chamber " << cscDetId.chamber() << "." << std::endl; @@ -104,6 +141,17 @@ void MuonResidualsFromTrack::init(edm::ESHandle } } + if (fillLayerPlotDT) { + layerData_DT->nTracker = iT; + layerData_DT->nCSC = iCSC; + layerData_DT->nDT = iDT; + } + if (fillLayerPlotCSC) { + layerData_CSC->nTracker = iT; + layerData_CSC->nCSC = iCSC; + layerData_CSC->nDT = iDT; + } + // TrackTransformer trackTransformer(); // std::vector vTrackerTrajectory = trackTransformer.transform(track, recHitsForReFit); // std::cout << "Tracker trajectories size " << vTrackerTrajectory.size() << std::endl; @@ -376,13 +424,28 @@ void MuonResidualsFromTrack::init(edm::ESHandle double chamber_width = geomDet->surface().bounds().width(); double chamber_length = geomDet->surface().bounds().length(); + if (fillLayerPlotDT) { + layerData_DT->wheel = chamberId.wheel(); + layerData_DT->station = chamberId.station(); + layerData_DT->sector = chamberId.sector(); + } if (hit2->dimension() > 1) { // std::vector vDTSeg2D = hit2->recHits(); std::vector vDTSeg2D = hit2->recHits(); if (m_debug) std::cout << " vDTSeg2D size: " << vDTSeg2D.size() << std::endl; - + int nLayers_DT = 0; + if (fillLayerPlotDT) { + for (int i = 0; i < 8; i++) { + layerData_DT->v_hitx[i] = -999.; + layerData_DT->v_trackx[i] = -999.; + } + for (int i = 0; i < 4; i++) { + layerData_DT->v_hity[i] = -999.; + layerData_DT->v_tracky[i] = -999.; + } + } // for ( std::vector::const_iterator itDTSeg2D = vDTSeg2D.begin(); // itDTSeg2D != vDTSeg2D.end(); // ++itDTSeg2D ) { @@ -470,9 +533,24 @@ void MuonResidualsFromTrack::init(edm::ESHandle m_dt13[chamberId]->addResidual(prop, &extrapolation, hit, chamber_width, chamber_length); } // residualDT13IsAdded = true; + if (fillLayerPlotDT) { + layerData_DT->v_hitx[layerId.layer() + 2 * (superLayerId.superlayer() - 1) - 1] = + hit->localPosition().x(); + if (extrapolation.isValid()) { + layerData_DT->v_trackx[layerId.layer() + 2 * (superLayerId.superlayer() - 1) - 1] = + extrapolation.localPosition().x(); + layerData_DT->v_tracky_x_layer[layerId.layer() + 2 * (superLayerId.superlayer() - 1) - 1] = + extrapolation.localPosition().y(); + } + } + nLayers_DT++; } } } + if (fillLayerPlotDT) { + layerData_DT->nlayers = nLayers_DT; + layerTree_DT->Fill(); + } } // std::cout << "Extrapolate last Tracker TSOS to muon hit" << std::endl; @@ -503,13 +581,27 @@ void MuonResidualsFromTrack::init(edm::ESHandle if (m_debug) std::cout << "Muon hit in CSC endcap " << cscDetId2.endcap() << " station " << cscDetId2.station() << " ring " << cscDetId2.ring() << " chamber " << cscDetId2.chamber() << "." << std::endl; - + if (fillLayerPlotCSC) { + layerData_CSC->endcap = cscDetId2.endcap(); + layerData_CSC->station = cscDetId2.station(); + layerData_CSC->ring = cscDetId2.ring(); + layerData_CSC->chamber = cscDetId2.chamber(); + } if (hit2->dimension() == 4) { // std::vector vCSCHits2D = hit2->recHits(); std::vector vCSCHits2D = hit2->recHits(); if (m_debug) std::cout << " vCSCHits2D size: " << vCSCHits2D.size() << std::endl; if (vCSCHits2D.size() >= 5) { + int nLayers = 0; + if (fillLayerPlotCSC) { + for (int i = 0; i < 6; i++) { + layerData_CSC->v_hitx[i] = -999.; + layerData_CSC->v_hity[i] = -999.; + layerData_CSC->v_resx[i] = -999.; + layerData_CSC->v_resy[i] = -999.; + } + } // for ( std::vector::const_iterator itCSCHits2D = vCSCHits2D.begin(); // itCSCHits2D != vCSCHits2D.end(); // ++itCSCHits2D ) { @@ -589,10 +681,24 @@ void MuonResidualsFromTrack::init(edm::ESHandle } m_csc[chamberId]->addResidual(prop, &extrapolation, hit, 250.0, 250.0); } + if (fillLayerPlotCSC) { + layerData_CSC->v_hitx[cscDetId.layer() - 1] = hit->localPosition().x(); + layerData_CSC->v_hity[cscDetId.layer() - 1] = hit->localPosition().y(); + if (extrapolation.isValid()) { + layerData_CSC->v_resx[cscDetId.layer() - 1] = + extrapolation.localPosition().x() - hit->localPosition().x(); + layerData_CSC->v_resy[cscDetId.layer() - 1] = + extrapolation.localPosition().y() - hit->localPosition().y(); + } + nLayers++; + } } + if (fillLayerPlotCSC) + layerData_CSC->nlayers = nLayers; } } - + if (fillLayerPlotCSC) + layerTree_CSC->Fill(); } else if (hitId2.subdetId() == MuonSubdetId::RPC) { if (m_debug) std::cout << "Muon Hit in RPC" << std::endl; diff --git a/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsPositionFitter.cc b/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsPositionFitter.cc index 38af11279ff51..a81173cc02804 100644 --- a/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsPositionFitter.cc +++ b/Alignment/MuonAlignmentAlgorithms/src/MuonResidualsPositionFitter.cc @@ -141,7 +141,8 @@ bool MuonResidualsPositionFitter::fit(Alignable *ali) { high.push_back(0.); } - return dofit(&MuonResidualsPositionFitter_FCN, parNum, parName, start, step, low, high); + std::string chamber_id = "NULL"; + return dofit(&MuonResidualsPositionFitter_FCN, parNum, parName, start, step, low, high, chamber_id); } double MuonResidualsPositionFitter::plot(std::string name, TFileDirectory *dir, Alignable *ali) { diff --git a/Alignment/MuonAlignmentAlgorithms/test/test_CSCOverlapsAlignmentAlgorithm_cfg.py b/Alignment/MuonAlignmentAlgorithms/test/test_CSCOverlapsAlignmentAlgorithm_cfg.py index 4e3434c1172c4..62baabb03cc2a 100644 --- a/Alignment/MuonAlignmentAlgorithms/test/test_CSCOverlapsAlignmentAlgorithm_cfg.py +++ b/Alignment/MuonAlignmentAlgorithms/test/test_CSCOverlapsAlignmentAlgorithm_cfg.py @@ -40,6 +40,7 @@ MuonRecHitBuilder = cms.string("MuonRecHitBuilder"), RefitDirection = cms.string("alongMomentum"), RefitRPCHits = cms.bool(False), + RefitMuonHits = cms.bool(True), Propagator = cms.string("SteppingHelixPropagatorAny")), mode = cms.string("phipos"), diff --git a/DQM/TrackingMonitor/python/trackingRecoMaterialAnalyzer_cfi.py b/DQM/TrackingMonitor/python/trackingRecoMaterialAnalyzer_cfi.py index c5fdd6ba83b27..02ffe52f98ccb 100644 --- a/DQM/TrackingMonitor/python/trackingRecoMaterialAnalyzer_cfi.py +++ b/DQM/TrackingMonitor/python/trackingRecoMaterialAnalyzer_cfi.py @@ -14,6 +14,7 @@ MTDRecHitBuilder = cms.string('MTDRecHitBuilder'), RefitDirection = cms.string('alongMomentum'), RefitRPCHits = cms.bool(True), + RefitMuonHits = cms.bool(True), Propagator = cms.string('SmartPropagatorAnyRKOpposite'), #Propagators PropagatorAlong = cms.string("RungeKuttaTrackerPropagator"), diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 651b3b40edf13..62e778ab7844e 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -691,7 +691,8 @@ void TrackExtenderWithMTDT::fillDescriptions(edm::Configuration "KFSmootherForRefitInsideOut", "PropagatorWithMaterialForMTD", "alongMomentum", - true, + true, // refitRPCHits + true, // refitMuonHits "WithTrackAngle", "MuonRecHitBuilder", "MTDRecHitBuilder"); diff --git a/RecoMuon/GlobalTrackingTools/python/GlobalTrajectoryBuilderCommon_cff.py b/RecoMuon/GlobalTrackingTools/python/GlobalTrajectoryBuilderCommon_cff.py index ce28bf73694dc..6edcac8215b49 100644 --- a/RecoMuon/GlobalTrackingTools/python/GlobalTrajectoryBuilderCommon_cff.py +++ b/RecoMuon/GlobalTrackingTools/python/GlobalTrajectoryBuilderCommon_cff.py @@ -22,6 +22,7 @@ MTDRecHitBuilder = cms.string('MTDRecHitBuilder'), RefitDirection = cms.string('alongMomentum'), RefitRPCHits = cms.bool(True), + RefitMuonHits = cms.bool(True), DoPredictionsOnly = cms.bool(False) ), PtCut = cms.double(1.0), diff --git a/RecoMuon/L3MuonProducer/plugins/L3MuonProducer.cc b/RecoMuon/L3MuonProducer/plugins/L3MuonProducer.cc index d7ed7237a563f..e75f514fd7bad 100644 --- a/RecoMuon/L3MuonProducer/plugins/L3MuonProducer.cc +++ b/RecoMuon/L3MuonProducer/plugins/L3MuonProducer.cc @@ -284,6 +284,7 @@ void L3MuonProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptio "hltESPSmartPropagatorAny", // propagator "insideOut", // refit direction true, // refit rpc hits + true, // refit muon hits "hltESPTTRHBWithTrackAngle", // tracker rechit builder "hltESPMuonTransientTrackingRecHitBuilder" // muon rechit builder ); diff --git a/RecoMuon/MuonIdentification/python/TrackerKinkFinder_cfi.py b/RecoMuon/MuonIdentification/python/TrackerKinkFinder_cfi.py index a0c86ac1d4cbf..8651a1cfa6c37 100644 --- a/RecoMuon/MuonIdentification/python/TrackerKinkFinder_cfi.py +++ b/RecoMuon/MuonIdentification/python/TrackerKinkFinder_cfi.py @@ -15,6 +15,7 @@ MTDRecHitBuilder = cms.string('MTDRecHitBuilder'), RefitDirection = cms.string('alongMomentum'), RefitRPCHits = cms.bool(True), + RefitMuonHits = cms.bool(True), Propagator = cms.string('SmartPropagatorAnyRKOpposite'), ) ) diff --git a/RecoTracker/SpecialSeedGenerators/python/inOutSeedsFromTrackerMuons_cfi.py b/RecoTracker/SpecialSeedGenerators/python/inOutSeedsFromTrackerMuons_cfi.py index 31989b0c9c1aa..db09badc59bef 100644 --- a/RecoTracker/SpecialSeedGenerators/python/inOutSeedsFromTrackerMuons_cfi.py +++ b/RecoTracker/SpecialSeedGenerators/python/inOutSeedsFromTrackerMuons_cfi.py @@ -19,5 +19,6 @@ MTDRecHitBuilder = cms.string('MTDRecHitBuilder'), RefitDirection = cms.string('alongMomentum'), RefitRPCHits = cms.bool(True), + RefitMuonHits = cms.bool(True), Propagator = cms.string('SmartPropagatorAnyRKOpposite'), ) diff --git a/TrackingTools/TrackRefitter/interface/TrackTransformer.h b/TrackingTools/TrackRefitter/interface/TrackTransformer.h index 97411a7145ba8..751f3b94a27db 100644 --- a/TrackingTools/TrackRefitter/interface/TrackTransformer.h +++ b/TrackingTools/TrackRefitter/interface/TrackTransformer.h @@ -61,6 +61,7 @@ class TrackTransformer final : public TrackTransformerBase { const std::string& propagator = "SmartPropagatorAnyRK", const std::string& refitDirection = "alongMomentum", bool refitRPCHits = true, + bool refitMuonHits = true, const std::string& trackerRecHitBuilder = "WithTrackAngle", const std::string& muonRecHitBuilder = "MuonRecHitBuilder", const std::string& mtdRecHitBuilder = "MTDRecHitBuilder"); @@ -98,7 +99,7 @@ class TrackTransformer final : public TrackTransformerBase { unsigned long long theCacheId_TRH = 0; - const bool theRPCInTheFit; + const bool theRPCInTheFit, theMuonInTheFit; const bool theDoPredictionsOnly; const RefitDirection theRefitDirection; diff --git a/TrackingTools/TrackRefitter/python/cosmicMuonTrajectories_cff.py b/TrackingTools/TrackRefitter/python/cosmicMuonTrajectories_cff.py index b99b4668ada29..b62c35b3581e7 100644 --- a/TrackingTools/TrackRefitter/python/cosmicMuonTrajectories_cff.py +++ b/TrackingTools/TrackRefitter/python/cosmicMuonTrajectories_cff.py @@ -27,7 +27,8 @@ TrackerRecHitBuilder = cms.string('WithTrackAngle'), MuonRecHitBuilder = cms.string('MuonRecHitBuilder'), MTDRecHitBuilder = cms.string('MTDRecHitBuilder'), - RefitRPCHits = cms.bool(True) + RefitRPCHits = cms.bool(True), + RefitMuonHits = cms.bool(True) ) ) diff --git a/TrackingTools/TrackRefitter/python/ctfWithMaterialTrajectoriesP5_cff.py b/TrackingTools/TrackRefitter/python/ctfWithMaterialTrajectoriesP5_cff.py index f1bacc12fd7c8..a9815f54ce705 100644 --- a/TrackingTools/TrackRefitter/python/ctfWithMaterialTrajectoriesP5_cff.py +++ b/TrackingTools/TrackRefitter/python/ctfWithMaterialTrajectoriesP5_cff.py @@ -25,6 +25,7 @@ MTDRecHitBuilder = cms.string('MTDRecHitBuilder'), RefitDirection = cms.string('alongMomentum'), RefitRPCHits = cms.bool(True), + RefitMuonHits = cms.bool(True), Propagator = cms.string('SmartPropagatorAnyRK') ) ) diff --git a/TrackingTools/TrackRefitter/python/ctfWithMaterialTrajectories_cff.py b/TrackingTools/TrackRefitter/python/ctfWithMaterialTrajectories_cff.py index b7defea421c43..953c8bbd38b36 100644 --- a/TrackingTools/TrackRefitter/python/ctfWithMaterialTrajectories_cff.py +++ b/TrackingTools/TrackRefitter/python/ctfWithMaterialTrajectories_cff.py @@ -25,6 +25,7 @@ MTDRecHitBuilder = cms.string('MTDRecHitBuilder'), RefitDirection = cms.string('alongMomentum'), RefitRPCHits = cms.bool(True), + RefitMuonHits = cms.bool(True), Propagator = cms.string('SmartPropagatorAnyRKOpposite') ) ) diff --git a/TrackingTools/TrackRefitter/python/globalCosmicMuonTrajectories_cff.py b/TrackingTools/TrackRefitter/python/globalCosmicMuonTrajectories_cff.py index 1387de9e7ac2a..c67a4ce5bd004 100644 --- a/TrackingTools/TrackRefitter/python/globalCosmicMuonTrajectories_cff.py +++ b/TrackingTools/TrackRefitter/python/globalCosmicMuonTrajectories_cff.py @@ -21,6 +21,7 @@ MuonRecHitBuilder = cms.string('MuonRecHitBuilder'), MTDRecHitBuilder = cms.string('MTDRecHitBuilder'), RefitRPCHits = cms.bool(True), + RefitMuonHits = cms.bool(True), # muon station to be skipped //also kills RPCs in that station SkipStationDT = cms.int32(-999), SkipStationCSC = cms.int32(-999), diff --git a/TrackingTools/TrackRefitter/python/globalMuonTrajectories_cff.py b/TrackingTools/TrackRefitter/python/globalMuonTrajectories_cff.py index 27073dbd5b7ba..4daffc174ce03 100644 --- a/TrackingTools/TrackRefitter/python/globalMuonTrajectories_cff.py +++ b/TrackingTools/TrackRefitter/python/globalMuonTrajectories_cff.py @@ -25,6 +25,7 @@ MTDRecHitBuilder = cms.string('MTDRecHitBuilder'), RefitDirection = cms.string('alongMomentum'), RefitRPCHits = cms.bool(True), + RefitMuonHits = cms.bool(True), Propagator = cms.string('SmartPropagatorAnyRKOpposite') ) ) diff --git a/TrackingTools/TrackRefitter/python/standAloneMuonTrajectories_cff.py b/TrackingTools/TrackRefitter/python/standAloneMuonTrajectories_cff.py index f88313bf4c898..78b5430c2504e 100644 --- a/TrackingTools/TrackRefitter/python/standAloneMuonTrajectories_cff.py +++ b/TrackingTools/TrackRefitter/python/standAloneMuonTrajectories_cff.py @@ -25,6 +25,7 @@ MTDRecHitBuilder = cms.string('MTDRecHitBuilder'), RefitDirection = cms.string('alongMomentum'), RefitRPCHits = cms.bool(True), + RefitMuonHits = cms.bool(True), Propagator = cms.string('SmartPropagatorAnyRKOpposite') ) ) diff --git a/TrackingTools/TrackRefitter/src/TrackTransformer.cc b/TrackingTools/TrackRefitter/src/TrackTransformer.cc index c1140b671e46b..c596763a8642b 100644 --- a/TrackingTools/TrackRefitter/src/TrackTransformer.cc +++ b/TrackingTools/TrackRefitter/src/TrackTransformer.cc @@ -31,6 +31,7 @@ using namespace edm; /// Constructor TrackTransformer::TrackTransformer(const ParameterSet& parameterSet, edm::ConsumesCollector& iC) : theRPCInTheFit(parameterSet.getParameter("RefitRPCHits")), + theMuonInTheFit(parameterSet.getParameter("RefitMuonHits")), theDoPredictionsOnly(parameterSet.getParameter("DoPredictionsOnly")), theRefitDirection(parameterSet.getParameter("RefitDirection")), theFitterName(parameterSet.getParameter("Fitter")), @@ -59,6 +60,7 @@ void TrackTransformer::fillPSetDescription(edm::ParameterSetDescription& desc, const std::string& propagator, const std::string& refitDirection, bool refitRPCHits, + bool refitMuonHits, const std::string& trackerRecHitBuilder, const std::string& muonRecHitBuilder, const std::string& mtdRecHitBuilder) { @@ -68,6 +70,7 @@ void TrackTransformer::fillPSetDescription(edm::ParameterSetDescription& desc, desc.add("Propagator", propagator); desc.add("RefitDirection", refitDirection); desc.add("RefitRPCHits", refitRPCHits); + desc.add("RefitMuonHits", refitMuonHits); desc.add("TrackerRecHitBuilder", trackerRecHitBuilder); desc.add("MuonRecHitBuilder", muonRecHitBuilder); desc.add("MTDRecHitBuilder", mtdRecHitBuilder); @@ -114,6 +117,10 @@ TransientTrackingRecHit::ConstRecHitContainer TrackTransformer::getTransientRecH if ((*hit)->geographicalId().det() == DetId::Tracker) { result.emplace_back((**hit).cloneForFit(*tkbuilder->geometry()->idToDet((**hit).geographicalId()))); } else if ((*hit)->geographicalId().det() == DetId::Muon) { + if (!theMuonInTheFit) { + LogTrace("Reco|TrackingTools|TrackTransformer") << "Muon Rec Hit discarged"; + continue; + } if ((*hit)->geographicalId().subdetId() == 3 && !theRPCInTheFit) { LogTrace("Reco|TrackingTools|TrackTransformer") << "RPC Rec Hit discarged"; continue;