Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-20 10:41:38

0001 /*
0002  * Package:     CommonAlignmentProducer
0003  * Class  :     AlignmentMonitorMuonSystemMap1D
0004  *
0005  * Original Author:  Jim Pivarski
0006  *         Created:  Mon Nov 12 13:30:14 CST 2007
0007  *
0008  * $Id: AlignmentMonitorMuonSystemMap1D.cc,v 1.5 2011/04/15 23:09:37 khotilov Exp $
0009  */
0010 
0011 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorPluginFactory.h"
0012 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h"
0013 #include "Alignment/MuonAlignmentAlgorithms/interface/MuonResidualsFromTrack.h"
0014 
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/Utilities/interface/InputTag.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/ServiceRegistry/interface/Service.h"
0020 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0021 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0022 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0023 
0024 #include "TH1F.h"
0025 #include "TH2F.h"
0026 
0027 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0028 #include "TrackingTools/Records/interface/DetIdAssociatorRecord.h"
0029 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0030 #include "TrackingTools/TrackAssociator/interface/DetIdAssociator.h"
0031 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0032 #include "MagneticField/Engine/interface/MagneticField.h"
0033 
0034 class AlignmentMonitorMuonSystemMap1D : public AlignmentMonitorBase {
0035 public:
0036   AlignmentMonitorMuonSystemMap1D(const edm::ParameterSet &cfg, edm::ConsumesCollector iC);
0037   ~AlignmentMonitorMuonSystemMap1D() override {}
0038 
0039   void book() override;
0040 
0041   void event(const edm::Event &iEvent,
0042              const edm::EventSetup &iSetup,
0043              const ConstTrajTrackPairCollection &iTrajTracks) override;
0044   void processMuonResidualsFromTrack(MuonResidualsFromTrack &mrft, const edm::Event &iEvent);
0045 
0046   void afterAlignment() override;
0047 
0048 private:
0049   // es token
0050   const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> m_esTokenGBTGeom;
0051   const edm::ESGetToken<DetIdAssociator, DetIdAssociatorRecord> m_esTokenDetId;
0052   const edm::ESGetToken<Propagator, TrackingComponentsRecord> m_esTokenProp;
0053   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> m_esTokenMF;
0054   const MuonResidualsFromTrack::BuilderToken m_esTokenBuilder;
0055 
0056   // parameters
0057   edm::InputTag m_muonCollectionTag;
0058   double m_minTrackPt;
0059   double m_maxTrackPt;
0060   double m_minTrackP;
0061   double m_maxTrackP;
0062   double m_maxDxy;
0063   int m_minTrackerHits;
0064   double m_maxTrackerRedChi2;
0065   bool m_allowTIDTEC;
0066   int m_minNCrossedChambers;
0067   int m_minDT13Hits;
0068   int m_minDT2Hits;
0069   int m_minCSCHits;
0070   bool m_doDT;
0071   bool m_doCSC;
0072   bool m_useStubPosition;
0073   bool m_createNtuple;
0074 
0075   // counter
0076   long m_counter_event;
0077   long m_counter_track;
0078   long m_counter_trackmoment;
0079   long m_counter_trackdxy;
0080   long m_counter_trackokay;
0081   long m_counter_dt;
0082   long m_counter_13numhits;
0083   long m_counter_2numhits;
0084   long m_counter_csc;
0085   long m_counter_cscnumhits;
0086 
0087   // histogram helper
0088   class MuonSystemMapPlot1D {
0089   public:
0090     MuonSystemMapPlot1D(std::string name,
0091                         AlignmentMonitorMuonSystemMap1D *module,
0092                         int bins,
0093                         double low,
0094                         double high,
0095                         bool xy,
0096                         bool add_1d);
0097 
0098     void fill_x_1d(double residx, double chi2, int dof);
0099     void fill_x(char charge, double abscissa, double residx, double chi2, int dof);
0100     void fill_y(char charge, double abscissa, double residy, double chi2, int dof);
0101     void fill_dxdz(char charge, double abscissa, double slopex, double chi2, int dof);
0102     void fill_dydz(char charge, double abscissa, double slopey, double chi2, int dof);
0103 
0104   private:
0105     std::string m_name;
0106     int m_bins;
0107     bool m_xy;
0108     bool m_1d;
0109     TH1F *m_x_1d;
0110     TH2F *m_x_2d, *m_y_2d, *m_dxdz_2d, *m_dydz_2d;
0111   };
0112 
0113   MuonSystemMapPlot1D *m_DTvsz_station[4][14];   // [station][sector]
0114   MuonSystemMapPlot1D *m_CSCvsr_me[2][4][36];    // [endcap][station][chamber]
0115   MuonSystemMapPlot1D *m_DTvsphi_station[4][5];  // [station][wheel]
0116   MuonSystemMapPlot1D *m_CSCvsphi_me[2][4][3];   // [endcap][station][ring]
0117 
0118   std::vector<MuonSystemMapPlot1D *> m_plots;
0119 
0120   std::string num02d(int num);
0121 
0122   // optional debug ntuple
0123   TTree *m_cscnt;
0124 
0125   struct MyCSCDetId {
0126     void init(CSCDetId &id) {
0127       e = id.endcap();
0128       s = id.station();
0129       r = id.ring();
0130       c = id.chamber();
0131       t = id.iChamberType();
0132     }
0133     Short_t e, s, r, c;
0134     Short_t t;  // type 1-10: ME1/a,1/b,1/2,1/3,2/1...4/2
0135   };
0136   MyCSCDetId m_id;
0137 
0138   struct MyTrack {
0139     Int_t q;
0140     Float_t pt, pz;
0141   };
0142   MyTrack m_tr;
0143 
0144   struct MyResidual {
0145     Float_t res, slope, rho, phi, z;
0146   };
0147   MyResidual m_re;
0148 
0149   UInt_t m_run;
0150 };
0151 
0152 AlignmentMonitorMuonSystemMap1D::AlignmentMonitorMuonSystemMap1D(const edm::ParameterSet &cfg,
0153                                                                  edm::ConsumesCollector iC)
0154     : AlignmentMonitorBase(cfg, iC, "AlignmentMonitorMuonSystemMap1D"),
0155       m_esTokenGBTGeom(iC.esConsumes()),
0156       m_esTokenDetId(iC.esConsumes(edm::ESInputTag("", "MuonDetIdAssociator"))),
0157       m_esTokenProp(iC.esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))),
0158       m_esTokenMF(iC.esConsumes()),
0159       m_esTokenBuilder(iC.esConsumes(MuonResidualsFromTrack::builderESInputTag())),
0160       m_muonCollectionTag(cfg.getParameter<edm::InputTag>("muonCollectionTag")),
0161       m_minTrackPt(cfg.getParameter<double>("minTrackPt")),
0162       m_maxTrackPt(cfg.getParameter<double>("maxTrackPt")),
0163       m_minTrackP(cfg.getParameter<double>("minTrackP")),
0164       m_maxTrackP(cfg.getParameter<double>("maxTrackP")),
0165       m_maxDxy(cfg.getParameter<double>("maxDxy")),
0166       m_minTrackerHits(cfg.getParameter<int>("minTrackerHits")),
0167       m_maxTrackerRedChi2(cfg.getParameter<double>("maxTrackerRedChi2")),
0168       m_allowTIDTEC(cfg.getParameter<bool>("allowTIDTEC")),
0169       m_minNCrossedChambers(cfg.getParameter<int>("minNCrossedChambers")),
0170       m_minDT13Hits(cfg.getParameter<int>("minDT13Hits")),
0171       m_minDT2Hits(cfg.getParameter<int>("minDT2Hits")),
0172       m_minCSCHits(cfg.getParameter<int>("minCSCHits")),
0173       m_doDT(cfg.getParameter<bool>("doDT")),
0174       m_doCSC(cfg.getParameter<bool>("doCSC")),
0175       m_useStubPosition(cfg.getParameter<bool>("useStubPosition")),
0176       m_createNtuple(cfg.getParameter<bool>("createNtuple")) {
0177   if (m_createNtuple) {
0178     edm::Service<TFileService> fs;
0179     m_cscnt = fs->make<TTree>("mualNtuple", "mualNtuple");
0180     m_cscnt->Branch("id", &m_id.e, "e/S:s:r:c:t");
0181     m_cscnt->Branch("tr", &m_tr.q, "q/I:pt/F:pz");
0182     m_cscnt->Branch("re", &m_re.res, "res/F:slope:rho:phi:z");
0183     m_cscnt->Branch("run", &m_run, "run/i");
0184   }
0185 }
0186 
0187 std::string AlignmentMonitorMuonSystemMap1D::num02d(int num) {
0188   assert(num >= 0 && num < 100);
0189   char tmp[4];
0190   sprintf(tmp, "%02d", num);
0191   return std::string(tmp);
0192 }
0193 
0194 void AlignmentMonitorMuonSystemMap1D::book() {
0195   std::string wheel_label[5] = {"A", "B", "C", "D", "E"};
0196 
0197   for (unsigned char station = 1; station <= 4; station++) {
0198     std::string s_station = std::to_string(station);
0199 
0200     bool do_y = true;
0201     if (station == 4)
0202       do_y = false;
0203 
0204     // *** DT ***
0205     if (m_doDT)
0206       for (int sector = 1; sector <= 14; sector++) {
0207         if ((station < 4 && sector <= 12) || station == 4) {
0208           m_DTvsz_station[station - 1][sector - 1] = new MuonSystemMapPlot1D(
0209               "DTvsz_st" + s_station + "sec" + num02d(sector), this, 60, -660., 660., do_y, false);
0210           m_plots.push_back(m_DTvsz_station[station - 1][sector - 1]);
0211         }
0212       }
0213 
0214     if (m_doDT)
0215       for (int wheel = -2; wheel <= 2; wheel++) {
0216         m_DTvsphi_station[station - 1][wheel + 2] = new MuonSystemMapPlot1D(
0217             "DTvsphi_st" + s_station + "wh" + wheel_label[wheel + 2], this, 180, -M_PI, M_PI, do_y, false);
0218         m_plots.push_back(m_DTvsphi_station[station - 1][wheel + 2]);
0219       }
0220 
0221     // *** CSC ***
0222     if (m_doCSC)
0223       for (int endcap = 1; endcap <= 2; endcap++) {
0224         std::string s_endcap("m");
0225         if (endcap == 1)
0226           s_endcap = "p";
0227 
0228         for (int chamber = 1; chamber <= 36; chamber++) {
0229           m_CSCvsr_me[endcap - 1][station - 1][chamber - 1] = new MuonSystemMapPlot1D(
0230               "CSCvsr_me" + s_endcap + s_station + "ch" + num02d(chamber), this, 60, 100., 700., false, false);
0231           m_plots.push_back(m_CSCvsr_me[endcap - 1][station - 1][chamber - 1]);
0232         }
0233 
0234         for (int ring = 1; ring <= 3; ring++)  // the ME1/a (ring4) is not independent from ME1/b (ring1)
0235         {
0236           std::string s_ring = std::to_string(ring);
0237           if ((station > 1 && ring <= 2) || station == 1) {
0238             m_CSCvsphi_me[endcap - 1][station - 1][ring - 1] =
0239                 new MuonSystemMapPlot1D("CSCvsphi_me" + s_endcap + s_station + s_ring,
0240                                         this,
0241                                         180,
0242                                         -M_PI / 180. * 5.,
0243                                         M_PI * (2. - 5. / 180.),
0244                                         false,
0245                                         true);
0246             m_plots.push_back(m_CSCvsphi_me[endcap - 1][station - 1][ring - 1]);
0247           }
0248         }
0249       }  // endcaps
0250   }      // stations
0251 
0252   m_counter_event = 0;
0253   m_counter_track = 0;
0254   m_counter_trackmoment = 0;
0255   m_counter_trackdxy = 0;
0256   m_counter_trackokay = 0;
0257   m_counter_dt = 0;
0258   m_counter_13numhits = 0;
0259   m_counter_2numhits = 0;
0260   m_counter_csc = 0;
0261   m_counter_cscnumhits = 0;
0262 }
0263 
0264 void AlignmentMonitorMuonSystemMap1D::event(const edm::Event &iEvent,
0265                                             const edm::EventSetup &iSetup,
0266                                             const ConstTrajTrackPairCollection &trajtracks) {
0267   m_counter_event++;
0268 
0269   edm::Handle<reco::BeamSpot> beamSpot;
0270   iEvent.getByLabel(m_beamSpotTag, beamSpot);
0271 
0272   const GlobalTrackingGeometry *globalGeometry = &iSetup.getData(m_esTokenGBTGeom);
0273   const DetIdAssociator *muonDetIdAssociator_ = &iSetup.getData(m_esTokenDetId);
0274   const Propagator *prop = &iSetup.getData(m_esTokenProp);
0275   const MagneticField *magneticField = &iSetup.getData(m_esTokenMF);
0276   auto builder = iSetup.getHandle(m_esTokenBuilder);
0277 
0278   if (m_muonCollectionTag.label().empty())  // use trajectories
0279   {
0280     for (ConstTrajTrackPairCollection::const_iterator trajtrack = trajtracks.begin(); trajtrack != trajtracks.end();
0281          ++trajtrack) {
0282       m_counter_track++;
0283       const Trajectory *traj = (*trajtrack).first;
0284       const reco::Track *track = (*trajtrack).second;
0285 
0286       if (m_minTrackPt < track->pt() && track->pt() < m_maxTrackPt && m_minTrackP < track->p() &&
0287           track->p() < m_maxTrackP) {
0288         m_counter_trackmoment++;
0289         if (fabs(track->dxy(beamSpot->position())) < m_maxDxy) {
0290           m_counter_trackdxy++;
0291 
0292           MuonResidualsFromTrack muonResidualsFromTrack(
0293               builder, magneticField, globalGeometry, muonDetIdAssociator_, prop, traj, track, pNavigator(), 1000.);
0294           processMuonResidualsFromTrack(muonResidualsFromTrack, iEvent);
0295         }
0296       }  // end if track has acceptable momentum
0297     }    // end loop over tracks
0298   } else {
0299     edm::Handle<reco::MuonCollection> muons;
0300     iEvent.getByLabel(m_muonCollectionTag, muons);
0301 
0302     for (reco::MuonCollection::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
0303       if (!(muon->isTrackerMuon() && muon->innerTrack().isNonnull()))
0304         continue;
0305 
0306       m_counter_track++;
0307 
0308       if (m_minTrackPt < muon->pt() && muon->pt() < m_maxTrackPt && m_minTrackP < muon->p() &&
0309           muon->p() < m_maxTrackP) {
0310         m_counter_trackmoment++;
0311         if (fabs(muon->innerTrack()->dxy(beamSpot->position())) < m_maxDxy) {
0312           m_counter_trackdxy++;
0313 
0314           MuonResidualsFromTrack muonResidualsFromTrack(globalGeometry, &(*muon), pNavigator(), 100.);
0315           processMuonResidualsFromTrack(muonResidualsFromTrack, iEvent);
0316         }
0317       }
0318     }
0319   }
0320 }
0321 
0322 void AlignmentMonitorMuonSystemMap1D::processMuonResidualsFromTrack(MuonResidualsFromTrack &mrft,
0323                                                                     const edm::Event &iEvent) {
0324   if (mrft.trackerNumHits() < m_minTrackerHits)
0325     return;
0326   if (!m_allowTIDTEC && mrft.contains_TIDTEC())
0327     return;
0328   if (mrft.normalizedChi2() > m_maxTrackerRedChi2)
0329     return;
0330 
0331   int nMuChambers = 0;
0332   std::vector<DetId> chamberIds = mrft.chamberIds();
0333   for (unsigned ch = 0; ch < chamberIds.size(); ch++)
0334     if (chamberIds[ch].det() == DetId::Muon)
0335       nMuChambers++;
0336   if (nMuChambers < m_minNCrossedChambers)
0337     return;
0338 
0339   char charge = (mrft.getTrack()->charge() > 0 ? 1 : -1);
0340   // double qoverpt = track->charge() / track->pt();
0341   // double qoverpz = track->charge() / track->pz();
0342 
0343   m_counter_trackokay++;
0344 
0345   for (std::vector<DetId>::const_iterator chamberId = chamberIds.begin(); chamberId != chamberIds.end(); ++chamberId) {
0346     if (chamberId->det() != DetId::Muon)
0347       continue;
0348 
0349     if (m_doDT && chamberId->subdetId() == MuonSubdetId::DT) {
0350       MuonChamberResidual *dt13 = mrft.chamberResidual(*chamberId, MuonChamberResidual::kDT13);
0351       MuonChamberResidual *dt2 = mrft.chamberResidual(*chamberId, MuonChamberResidual::kDT2);
0352       DTChamberId id(chamberId->rawId());
0353 
0354       m_counter_dt++;
0355 
0356       if (id.station() < 4 && dt13 != nullptr && dt13->numHits() >= m_minDT13Hits && dt2 != nullptr &&
0357           dt2->numHits() >= m_minDT2Hits && (dt2->chi2() / double(dt2->ndof())) < 2.0) {
0358         m_counter_13numhits++;
0359 
0360         double residual = dt13->global_residual();
0361         double resslope = dt13->global_resslope();
0362         double chi2 = dt13->chi2();
0363         int dof = dt13->ndof();
0364 
0365         align::GlobalPoint gpos;
0366         if (m_useStubPosition)
0367           gpos = dt13->global_stubpos();
0368         else
0369           gpos = dt13->global_trackpos();
0370         double phi = atan2(gpos.y(), gpos.x());
0371         double z = gpos.z();
0372 
0373         assert(1 <= id.sector() && id.sector() <= 14);
0374 
0375         m_DTvsz_station[id.station() - 1][id.sector() - 1]->fill_x(charge, z, residual, chi2, dof);
0376         m_DTvsz_station[id.station() - 1][id.sector() - 1]->fill_dxdz(charge, z, resslope, chi2, dof);
0377         m_DTvsphi_station[id.station() - 1][id.wheel() + 2]->fill_x(charge, phi, residual, chi2, dof);
0378         m_DTvsphi_station[id.station() - 1][id.wheel() + 2]->fill_dxdz(charge, phi, resslope, chi2, dof);
0379 
0380         m_counter_2numhits++;
0381 
0382         residual = dt2->global_residual();
0383         resslope = dt2->global_resslope();
0384         chi2 = dt2->chi2();
0385         dof = dt2->ndof();
0386 
0387         if (m_useStubPosition)
0388           gpos = dt2->global_stubpos();
0389         else
0390           gpos = dt2->global_trackpos();
0391         phi = atan2(gpos.y(), gpos.x());
0392         z = gpos.z();
0393 
0394         assert(1 <= id.sector() && id.sector() <= 14);
0395 
0396         m_DTvsz_station[id.station() - 1][id.sector() - 1]->fill_y(charge, z, residual, chi2, dof);
0397         m_DTvsz_station[id.station() - 1][id.sector() - 1]->fill_dydz(charge, z, resslope, chi2, dof);
0398         m_DTvsphi_station[id.station() - 1][id.wheel() + 2]->fill_y(charge, phi, residual, chi2, dof);
0399         m_DTvsphi_station[id.station() - 1][id.wheel() + 2]->fill_dydz(charge, phi, resslope, chi2, dof);
0400       }
0401 
0402       if (id.station() == 4 && dt13 != nullptr && dt13->numHits() >= m_minDT13Hits) {
0403         m_counter_13numhits++;
0404 
0405         double residual = dt13->global_residual();
0406         double resslope = dt13->global_resslope();
0407         double chi2 = dt13->chi2();
0408         int dof = dt13->ndof();
0409 
0410         align::GlobalPoint gpos;
0411         if (m_useStubPosition)
0412           gpos = dt13->global_stubpos();
0413         else
0414           gpos = dt13->global_trackpos();
0415         double phi = atan2(gpos.y(), gpos.x());
0416         double z = gpos.z();
0417 
0418         assert(1 <= id.sector() && id.sector() <= 14);
0419 
0420         m_DTvsz_station[id.station() - 1][id.sector() - 1]->fill_x(charge, z, residual, chi2, dof);
0421         m_DTvsz_station[id.station() - 1][id.sector() - 1]->fill_dxdz(charge, z, resslope, chi2, dof);
0422         m_DTvsphi_station[id.station() - 1][id.wheel() + 2]->fill_x(charge, phi, residual, chi2, dof);
0423         m_DTvsphi_station[id.station() - 1][id.wheel() + 2]->fill_dxdz(charge, phi, resslope, chi2, dof);
0424       }
0425     }
0426 
0427     else if (m_doCSC && chamberId->subdetId() == MuonSubdetId::CSC) {
0428       MuonChamberResidual *csc = mrft.chamberResidual(*chamberId, MuonChamberResidual::kCSC);
0429       CSCDetId id(chamberId->rawId());
0430 
0431       int ring = id.ring();
0432       if (id.ring() == 4)
0433         ring = 1;  // combine ME1/a + ME1/b
0434 
0435       m_counter_csc++;
0436 
0437       if (csc != nullptr && csc->numHits() >= m_minCSCHits) {
0438         m_counter_cscnumhits++;
0439 
0440         double residual = csc->global_residual();
0441         double resslope = csc->global_resslope();
0442         double chi2 = csc->chi2();
0443         int dof = csc->ndof();
0444 
0445         align::GlobalPoint gpos;
0446         if (m_useStubPosition)
0447           gpos = csc->global_stubpos();
0448         else
0449           gpos = csc->global_trackpos();
0450         double phi = atan2(gpos.y(), gpos.x());
0451         // start phi from -5deg
0452         if (phi < -M_PI / 180. * 5.)
0453           phi += 2. * M_PI;
0454         double R = sqrt(pow(gpos.x(), 2) + pow(gpos.y(), 2));
0455 
0456         int chamber = id.chamber() - 1;
0457         if (id.station() > 1 && ring == 1)
0458           chamber *= 2;
0459 
0460         assert(1 <= id.endcap() && id.endcap() <= 2 && 0 <= chamber && chamber <= 35);
0461 
0462         if (R > 0.)
0463           m_CSCvsphi_me[id.endcap() - 1][id.station() - 1][ring - 1]->fill_x_1d(residual / R, chi2, dof);
0464 
0465         m_CSCvsr_me[id.endcap() - 1][id.station() - 1][chamber]->fill_x(charge, R, residual, chi2, dof);
0466         m_CSCvsr_me[id.endcap() - 1][id.station() - 1][chamber]->fill_dxdz(charge, R, resslope, chi2, dof);
0467         m_CSCvsphi_me[id.endcap() - 1][id.station() - 1][ring - 1]->fill_x(charge, phi, residual, chi2, dof);
0468         m_CSCvsphi_me[id.endcap() - 1][id.station() - 1][ring - 1]->fill_dxdz(charge, phi, resslope, chi2, dof);
0469 
0470         if (m_createNtuple && chi2 > 0.)  //  &&  TMath::Prob(chi2, dof) < 0.95)
0471         {
0472           m_id.init(id);
0473           m_tr.q = charge;
0474           m_tr.pt = mrft.getTrack()->pt();
0475           m_tr.pz = mrft.getTrack()->pz();
0476           m_re.res = residual;
0477           m_re.slope = resslope;
0478           m_re.rho = R;
0479           m_re.phi = phi;
0480           m_re.z = gpos.z();
0481           m_run = iEvent.id().run();
0482           m_cscnt->Fill();
0483         }
0484       }
0485     }
0486 
0487     //else { assert(false); }
0488   }  // end loop over chambers
0489 }
0490 
0491 void AlignmentMonitorMuonSystemMap1D::afterAlignment() {
0492   std::cout << "AlignmentMonitorMuonSystemMap1D counters:" << std::endl;
0493   std::cout << " monitor m_counter_event      = " << m_counter_event << std::endl;
0494   std::cout << " monitor m_counter_track      = " << m_counter_track << std::endl;
0495   std::cout << " monitor m_counter_trackppt   = " << m_counter_trackmoment << std::endl;
0496   std::cout << " monitor m_counter_trackdxy   = " << m_counter_trackdxy << std::endl;
0497   std::cout << " monitor m_counter_trackokay  = " << m_counter_trackokay << std::endl;
0498   std::cout << " monitor m_counter_dt         = " << m_counter_dt << std::endl;
0499   std::cout << " monitor m_counter_13numhits  = " << m_counter_13numhits << std::endl;
0500   std::cout << " monitor m_counter_2numhits   = " << m_counter_2numhits << std::endl;
0501   std::cout << " monitor m_counter_csc        = " << m_counter_csc << std::endl;
0502   std::cout << " monitor m_counter_cscnumhits = " << m_counter_cscnumhits << std::endl;
0503 }
0504 
0505 AlignmentMonitorMuonSystemMap1D::MuonSystemMapPlot1D::MuonSystemMapPlot1D(
0506     std::string name, AlignmentMonitorMuonSystemMap1D *module, int bins, double low, double high, bool xy, bool add_1d)
0507     : m_name(name), m_bins(bins), m_xy(xy), m_1d(add_1d) {
0508   m_x_2d = m_y_2d = m_dxdz_2d = m_dydz_2d = nullptr;
0509   std::stringstream name_x_2d, name_y_2d, name_dxdz_2d, name_dydz_2d;
0510   name_x_2d << m_name << "_x_2d";
0511   name_y_2d << m_name << "_y_2d";
0512   name_dxdz_2d << m_name << "_dxdz_2d";
0513   name_dydz_2d << m_name << "_dydz_2d";
0514 
0515   const int nbins = 200;
0516   const double window = 100.;
0517 
0518   m_x_2d = module->book2D("/iterN/", name_x_2d.str(), "", m_bins, low, high, nbins, -window, window);
0519   if (m_xy)
0520     m_y_2d = module->book2D("/iterN/", name_y_2d.str(), "", m_bins, low, high, nbins, -window, window);
0521   m_dxdz_2d = module->book2D("/iterN/", name_dxdz_2d.str(), "", m_bins, low, high, nbins, -window, window);
0522   if (m_xy)
0523     m_dydz_2d = module->book2D("/iterN/", name_dydz_2d.str(), "", m_bins, low, high, nbins, -window, window);
0524 
0525   m_x_1d = nullptr;
0526   if (m_1d) {
0527     std::stringstream name_x_1d;  //, name_y_1d, name_dxdz_1d, name_dydz_1d;
0528     name_x_1d << m_name << "_x_1d";
0529     m_x_1d = module->book1D("/iterN/", name_x_1d.str(), "", nbins, -window, window);
0530   }
0531 }
0532 
0533 void AlignmentMonitorMuonSystemMap1D::MuonSystemMapPlot1D::fill_x_1d(double residx, double chi2, int dof) {
0534   if (m_1d && chi2 > 0.) {
0535     // assume that residx was in radians
0536     double residual = residx * 1000.;
0537     m_x_1d->Fill(residual);
0538   }
0539 }
0540 
0541 void AlignmentMonitorMuonSystemMap1D::MuonSystemMapPlot1D::fill_x(
0542     char charge, double abscissa, double residx, double chi2, int dof) {
0543   if (chi2 > 0.) {
0544     double residual = residx * 10.;
0545     //double weight = dof / chi2;
0546     m_x_2d->Fill(abscissa, residual);
0547   }
0548 }
0549 
0550 void AlignmentMonitorMuonSystemMap1D::MuonSystemMapPlot1D::fill_y(
0551     char charge, double abscissa, double residy, double chi2, int dof) {
0552   if (m_xy && chi2 > 0.) {
0553     double residual = residy * 10.;
0554     //double weight = dof / chi2;
0555     m_y_2d->Fill(abscissa, residual);
0556   }
0557 }
0558 
0559 void AlignmentMonitorMuonSystemMap1D::MuonSystemMapPlot1D::fill_dxdz(
0560     char charge, double abscissa, double slopex, double chi2, int dof) {
0561   if (chi2 > 0.) {
0562     double residual = slopex * 1000.;
0563     //double weight = dof / chi2;
0564     m_dxdz_2d->Fill(abscissa, residual);
0565   }
0566 }
0567 
0568 void AlignmentMonitorMuonSystemMap1D::MuonSystemMapPlot1D::fill_dydz(
0569     char charge, double abscissa, double slopey, double chi2, int dof) {
0570   if (m_xy && chi2 > 0.) {
0571     double residual = slopey * 1000.;
0572     //double weight = dof / chi2;
0573     m_dydz_2d->Fill(abscissa, residual);
0574   }
0575 }
0576 
0577 DEFINE_EDM_PLUGIN(AlignmentMonitorPluginFactory, AlignmentMonitorMuonSystemMap1D, "AlignmentMonitorMuonSystemMap1D");