DQMHOAlCaRecoStream

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
// -*- C++ -*-
//
// Package:    DQMHOAlCaRecoStream
// Class:      DQMHOAlCaRecoStream
//
/**\class DQMHOAlCaRecoStream DQMHOAlCaRecoStream.cc
 DQMOffline/DQMHOAlCaRecoStream/src/DQMHOAlCaRecoStream.cc

 Description: <one line class summary>

 Implementation:
     <Notes on implementation>
*/
//
// Original Author:  Gobinda Majumder
//         Created:  Mon Mar  2 12:33:08 CET 2009
//
//

// system include files
#include <string>

// user include files
#include "DataFormats/HcalCalibObjects/interface/HOCalibVariables.h"

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "DQMServices/Core/interface/DQMEDAnalyzer.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "FWCore/ServiceRegistry/interface/Service.h"

//
// class decleration
//

class DQMHOAlCaRecoStream : public DQMEDAnalyzer {
public:
  explicit DQMHOAlCaRecoStream(const edm::ParameterSet &);
  ~DQMHOAlCaRecoStream() override;

private:
  void analyze(const edm::Event &, const edm::EventSetup &) override;
  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;

  // ----------member data ---------------------------

  MonitorElement *hMuonMultipl;
  MonitorElement *hMuonMom;
  MonitorElement *hMuonEta;
  MonitorElement *hMuonPhi;

  MonitorElement *hDirCosine;
  MonitorElement *hHOTime;

  MonitorElement *hSigRing[5];
  MonitorElement *hPedRing[5];
  MonitorElement *hSignal3x3[9];

  int Nevents;
  int Nmuons;

  std::string theRootFileName;
  std::string folderName_;
  double m_sigmaValue;

  double m_lowRadPosInMuch;
  double m_highRadPosInMuch;

  int m_nbins;
  double m_lowEdge;
  double m_highEdge;

  bool saveToFile_;
  edm::EDGetTokenT<HOCalibVariableCollection> hoCalibVariableCollectionTag;
};

//
// constructors and destructor
//
DQMHOAlCaRecoStream::DQMHOAlCaRecoStream(const edm::ParameterSet &iConfig)
    : hoCalibVariableCollectionTag(
          consumes<HOCalibVariableCollection>(iConfig.getParameter<edm::InputTag>("hoCalibVariableCollectionTag"))) {
  // now do what ever initialization is needed

  theRootFileName = iConfig.getUntrackedParameter<std::string>("RootFileName", "tmp.root");
  folderName_ = iConfig.getUntrackedParameter<std::string>("folderName");
  m_sigmaValue = iConfig.getUntrackedParameter<double>("sigmaval", 0.2);
  m_lowRadPosInMuch = iConfig.getUntrackedParameter<double>("lowradposinmuch", 400.0);
  m_highRadPosInMuch = iConfig.getUntrackedParameter<double>("highradposinmuch", 480.0);
  m_lowEdge = iConfig.getUntrackedParameter<double>("lowedge", -2.0);
  m_highEdge = iConfig.getUntrackedParameter<double>("highedge", 6.0);
  m_nbins = iConfig.getUntrackedParameter<int>("nbins", 40);
  saveToFile_ = iConfig.getUntrackedParameter<bool>("saveToFile", false);
}

DQMHOAlCaRecoStream::~DQMHOAlCaRecoStream() {
  // do anything here that needs to be done at desctruction time
  // (e.g. close files, deallocate resources etc.)
}

//
// member functions
//

// ------------ method called to for each event  ------------
void DQMHOAlCaRecoStream::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
  Nevents++;

  edm::Handle<HOCalibVariableCollection> HOCalib;
  bool isCosMu = true;

  iEvent.getByToken(hoCalibVariableCollectionTag, HOCalib);

  if (!HOCalib.isValid()) {
    LogDebug("") << "DQMHOAlCaRecoStream:: Error! can't get HOCalib product!" << std::endl;
    return;
  }

  if (isCosMu) {
    hMuonMultipl->Fill((*HOCalib).size(), 1.);
    if (!(*HOCalib).empty()) {
      for (HOCalibVariableCollection::const_iterator hoC = (*HOCalib).begin(); hoC != (*HOCalib).end(); hoC++) {
        // OK!!!!
        float okt = 2.;
        double okx = std::pow((*hoC).trkvx, okt) + std::pow((*hoC).trkvy, okt);
        ///////
        double dr = std::pow(okx, 0.5);
        if (dr < m_lowRadPosInMuch || dr > m_highRadPosInMuch)
          continue;

        if ((*hoC).isect < 0)
          continue;
        if (fabs((*hoC).trkth - acos(-1.) / 2) < 0.000001)
          continue;
        int ieta = int((std::abs((*hoC).isect) % 10000) / 100.) - 30;

        if (std::abs(ieta) >= 16)
          continue;

        Nmuons++;

        hMuonMom->Fill((*hoC).trkmm, 1.0);
        hMuonEta->Fill(-log(tan((*hoC).trkth / 2.0)), 1.0);
        hMuonPhi->Fill((*hoC).trkph, 1.0);
        hDirCosine->Fill((*hoC).hoang, 1.0);
        hHOTime->Fill((*hoC).htime, 1.0);

        double energy = (*hoC).hosig[4];
        double pedval = (*hoC).hocro;
        int iring = 0;
        if (ieta >= -15 && ieta <= -11) {
          iring = -2;
        } else if (ieta >= -10 && ieta <= -5) {
          iring = -1;
        } else if (ieta >= 5 && ieta <= 10) {
          iring = 1;
        } else if (ieta >= 11 && ieta <= 15) {
          iring = 2;
        }

        hSigRing[iring + 2]->Fill(energy, 1.0);
        hPedRing[iring + 2]->Fill(pedval, 1.0);

        for (int k = 0; k < 9; k++) {
          hSignal3x3[k]->Fill((*hoC).hosig[k]);
        }
      }  // for (HOCalibVariableCollection::const_iterator hoC=(*HOCalib).begin()
    }  // if ((*HOCalib).size() >0 ) {
  }  // if (isCosMu) {
}

// ------------ method called once each job just before starting event loop
// ------------
void DQMHOAlCaRecoStream::bookHistograms(DQMStore::IBooker &ibooker,
                                         edm::Run const &irun,
                                         edm::EventSetup const &isetup) {
  ibooker.setCurrentFolder(folderName_);

  char title[200];
  char name[200];

  hMuonMom = ibooker.book1D("hMuonMom", "Muon momentum (GeV)", 50, -100, 100);
  hMuonMom->setAxisTitle("Muon momentum (GeV)", 1);

  hMuonEta = ibooker.book1D("hMuonEta", "Pseudo-rapidity of muon", 50, -1.5, 1.5);
  hMuonEta->setAxisTitle("Pseudo-rapidity of muon", 1);

  hMuonPhi = ibooker.book1D("hMuonPhi", "Azimuthal angle of muon", 24, -acos(-1), acos(-1));
  hMuonPhi->setAxisTitle("Azimuthal angle of muon", 1);

  hMuonMultipl = ibooker.book1D("hMuonMultipl", "Muon Multiplicity", 10, 0.5, 10.5);
  hMuonMultipl->setAxisTitle("Muon Multiplicity", 1);

  hDirCosine = ibooker.book1D("hDirCosine", "Direction Cosine of muon at HO tower", 50, -1., 1.);
  hDirCosine->setAxisTitle("Direction Cosine of muon at HO tower", 1);

  hHOTime = ibooker.book1D("hHOTime", "HO time distribution", 60, -20, 100.);
  hHOTime->setAxisTitle("HO time distribution", 1);

  for (int i = 0; i < 5; i++) {
    sprintf(name, "hSigRing_%i", i - 2);
    sprintf(title, "HO signal in Ring_%i", i - 2);
    hSigRing[i] = ibooker.book1D(name, title, m_nbins, m_lowEdge, m_highEdge);
    hSigRing[i]->setAxisTitle(title, 1);

    sprintf(name, "hPedRing_%i", i - 2);
    sprintf(title, "HO Pedestal in Ring_%i", i - 2);
    hPedRing[i] = ibooker.book1D(name, title, m_nbins, m_lowEdge, m_highEdge);
    hPedRing[i]->setAxisTitle(title, 1);
  }

  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      int k = 3 * (i + 1) + j + 1;

      sprintf(title, "hSignal3x3_deta%i_dphi%i", i, j);
      hSignal3x3[k] = ibooker.book1D(title, title, m_nbins, m_lowEdge, m_highEdge);
      hSignal3x3[k]->setAxisTitle(title, 1);
    }
  }

  Nevents = 0;
  Nmuons = 0;
}

DEFINE_FWK_MODULE(DQMHOAlCaRecoStream);