Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:06:28

0001 /** \file GlobalHitsProdHist.cc
0002  *
0003  *  See header file for description of class
0004  *
0005  *  \author M. Strang SUNY-Buffalo
0006  */
0007 
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0010 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0011 #include "Validation/GlobalHits/interface/GlobalHitsProdHist.h"
0012 
0013 GlobalHitsProdHist::GlobalHitsProdHist(const edm::ParameterSet &iPSet)
0014     : fName(""),
0015       verbosity(0),
0016       frequency(0),
0017       vtxunit(0),
0018       getAllProvenances(false),
0019       printProvenanceInfo(false),
0020       G4VtxSrc_Token_(consumes<edm::SimVertexContainer>((iPSet.getParameter<edm::InputTag>("G4VtxSrc")))),
0021       G4TrkSrc_Token_(consumes<edm::SimTrackContainer>(iPSet.getParameter<edm::InputTag>("G4TrkSrc"))),
0022       tGeomToken_(esConsumes()),
0023       cscGeomToken_(esConsumes()),
0024       dtGeomToken_(esConsumes()),
0025       rpcGeomToken_(esConsumes()),
0026       caloGeomToken_(esConsumes()),
0027       count(0) {
0028   std::string MsgLoggerCat = "GlobalHitsProdHist_GlobalHitsProdHist";
0029 
0030   // get information from parameter set
0031   fName = iPSet.getUntrackedParameter<std::string>("Name");
0032   verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
0033   frequency = iPSet.getUntrackedParameter<int>("Frequency");
0034   vtxunit = iPSet.getUntrackedParameter<int>("VtxUnit");
0035   edm::ParameterSet m_Prov = iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
0036   getAllProvenances = m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
0037   printProvenanceInfo = m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
0038 
0039   // get Labels to use to extract information
0040   PxlBrlLowSrc_ = iPSet.getParameter<edm::InputTag>("PxlBrlLowSrc");
0041   PxlBrlHighSrc_ = iPSet.getParameter<edm::InputTag>("PxlBrlHighSrc");
0042   PxlFwdLowSrc_ = iPSet.getParameter<edm::InputTag>("PxlFwdLowSrc");
0043   PxlFwdHighSrc_ = iPSet.getParameter<edm::InputTag>("PxlFwdHighSrc");
0044 
0045   SiTIBLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTIBLowSrc");
0046   SiTIBHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTIBHighSrc");
0047   SiTOBLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTOBLowSrc");
0048   SiTOBHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTOBHighSrc");
0049   SiTIDLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTIDLowSrc");
0050   SiTIDHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTIDHighSrc");
0051   SiTECLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTECLowSrc");
0052   SiTECHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTECHighSrc");
0053 
0054   MuonCscSrc_ = iPSet.getParameter<edm::InputTag>("MuonCscSrc");
0055   MuonDtSrc_ = iPSet.getParameter<edm::InputTag>("MuonDtSrc");
0056   MuonRpcSrc_ = iPSet.getParameter<edm::InputTag>("MuonRpcSrc");
0057 
0058   ECalEBSrc_ = iPSet.getParameter<edm::InputTag>("ECalEBSrc");
0059   ECalEESrc_ = iPSet.getParameter<edm::InputTag>("ECalEESrc");
0060   ECalESSrc_ = iPSet.getParameter<edm::InputTag>("ECalESSrc");
0061 
0062   HCalSrc_ = iPSet.getParameter<edm::InputTag>("HCalSrc");
0063 
0064   // use value of first digit to determine default output level (inclusive)
0065   // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
0066   verbosity %= 10;
0067 
0068   // print out Parameter Set information being used
0069   if (verbosity >= 0) {
0070     edm::LogInfo(MsgLoggerCat)
0071         << "\n===============================\n"
0072         << "Initialized as EDProducer with parameter values:\n"
0073         << "    Name          = " << fName << "\n"
0074         << "    Verbosity     = " << verbosity << "\n"
0075         << "    Frequency     = " << frequency << "\n"
0076         << "    VtxUnit       = " << vtxunit << "\n"
0077         << "    GetProv       = " << getAllProvenances << "\n"
0078         << "    PrintProv     = " << printProvenanceInfo << "\n"
0079         << "    PxlBrlLowSrc  = " << PxlBrlLowSrc_.label() << ":" << PxlBrlLowSrc_.instance() << "\n"
0080         << "    PxlBrlHighSrc = " << PxlBrlHighSrc_.label() << ":" << PxlBrlHighSrc_.instance() << "\n"
0081         << "    PxlFwdLowSrc  = " << PxlFwdLowSrc_.label() << ":" << PxlBrlLowSrc_.instance() << "\n"
0082         << "    PxlFwdHighSrc = " << PxlFwdHighSrc_.label() << ":" << PxlBrlHighSrc_.instance() << "\n"
0083         << "    SiTIBLowSrc   = " << SiTIBLowSrc_.label() << ":" << SiTIBLowSrc_.instance() << "\n"
0084         << "    SiTIBHighSrc  = " << SiTIBHighSrc_.label() << ":" << SiTIBHighSrc_.instance() << "\n"
0085         << "    SiTOBLowSrc   = " << SiTOBLowSrc_.label() << ":" << SiTOBLowSrc_.instance() << "\n"
0086         << "    SiTOBHighSrc  = " << SiTOBHighSrc_.label() << ":" << SiTOBHighSrc_.instance() << "\n"
0087         << "    SiTIDLowSrc   = " << SiTIDLowSrc_.label() << ":" << SiTIDLowSrc_.instance() << "\n"
0088         << "    SiTIDHighSrc  = " << SiTIDHighSrc_.label() << ":" << SiTIDHighSrc_.instance() << "\n"
0089         << "    SiTECLowSrc   = " << SiTECLowSrc_.label() << ":" << SiTECLowSrc_.instance() << "\n"
0090         << "    SiTECHighSrc  = " << SiTECHighSrc_.label() << ":" << SiTECHighSrc_.instance() << "\n"
0091         << "    MuonCscSrc    = " << MuonCscSrc_.label() << ":" << MuonCscSrc_.instance() << "\n"
0092         << "    MuonDtSrc     = " << MuonDtSrc_.label() << ":" << MuonDtSrc_.instance() << "\n"
0093         << "    MuonRpcSrc    = " << MuonRpcSrc_.label() << ":" << MuonRpcSrc_.instance() << "\n"
0094         << "    ECalEBSrc     = " << ECalEBSrc_.label() << ":" << ECalEBSrc_.instance() << "\n"
0095         << "    ECalEESrc     = " << ECalEESrc_.label() << ":" << ECalEESrc_.instance() << "\n"
0096         << "    ECalESSrc     = " << ECalESSrc_.label() << ":" << ECalESSrc_.instance() << "\n"
0097         << "    HCalSrc       = " << HCalSrc_.label() << ":" << HCalSrc_.instance() << "\n"
0098         << "===============================\n";
0099   }
0100 
0101   // create histograms
0102   Char_t hname[200];
0103   Char_t htitle[200];
0104 
0105   // MCGeant
0106   sprintf(hname, "hMCRGP1");
0107   histName_.push_back(hname);
0108   sprintf(htitle, "RawGenParticles");
0109   hMCRGP[0] = new TH1F(hname, htitle, 100, 0., 5000.);
0110   sprintf(hname, "hMCRGP2");
0111   histName_.push_back(hname);
0112   hMCRGP[1] = new TH1F(hname, htitle, 100, 0., 500.);
0113   for (Int_t i = 0; i < 2; ++i) {
0114     hMCRGP[i]->GetXaxis()->SetTitle("Number of Raw Generated Particles");
0115     hMCRGP[i]->GetYaxis()->SetTitle("Count");
0116     histMap_[hMCRGP[i]->GetName()] = hMCRGP[i];
0117   }
0118 
0119   sprintf(hname, "hMCG4Vtx1");
0120   histName_.push_back(hname);
0121   sprintf(htitle, "G4 Vertices");
0122   hMCG4Vtx[0] = new TH1F(hname, htitle, 100, 0., 50000.);
0123   sprintf(hname, "hMCG4Vtx2");
0124   histName_.push_back(hname);
0125   hMCG4Vtx[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0126   for (Int_t i = 0; i < 2; ++i) {
0127     hMCG4Vtx[i]->GetXaxis()->SetTitle("Number of Vertices");
0128     hMCG4Vtx[i]->GetYaxis()->SetTitle("Count");
0129     histMap_[hMCG4Vtx[i]->GetName()] = hMCG4Vtx[i];
0130   }
0131 
0132   sprintf(hname, "hMCG4Trk1");
0133   histName_.push_back(hname);
0134   sprintf(htitle, "G4 Tracks");
0135   hMCG4Trk[0] = new TH1F(hname, htitle, 150, 0., 15000.);
0136   sprintf(hname, "hMCG4Trk2");
0137   histName_.push_back(hname);
0138   hMCG4Trk[1] = new TH1F(hname, htitle, 150, -0.5, 99.5);
0139   for (Int_t i = 0; i < 2; ++i) {
0140     hMCG4Trk[i]->GetXaxis()->SetTitle("Number of Tracks");
0141     hMCG4Trk[i]->GetYaxis()->SetTitle("Count");
0142     histMap_[hMCG4Trk[i]->GetName()] = hMCG4Trk[i];
0143   }
0144 
0145   sprintf(hname, "hGeantVtxX1");
0146   histName_.push_back(hname);
0147   sprintf(htitle, "Geant vertex x/micrometer");
0148   hGeantVtxX[0] = new TH1F(hname, htitle, 100, -8000000., 8000000.);
0149   sprintf(hname, "hGeantVtxX2");
0150   histName_.push_back(hname);
0151   hGeantVtxX[1] = new TH1F(hname, htitle, 100, -50., 50.);
0152   for (Int_t i = 0; i < 2; ++i) {
0153     hGeantVtxX[i]->GetXaxis()->SetTitle("x of Vertex (um)");
0154     hGeantVtxX[i]->GetYaxis()->SetTitle("Count");
0155     histMap_[hGeantVtxX[i]->GetName()] = hGeantVtxX[i];
0156   }
0157 
0158   sprintf(hname, "hGeantVtxY1");
0159   histName_.push_back(hname);
0160   sprintf(htitle, "Geant vertex y/micrometer");
0161   hGeantVtxY[0] = new TH1F(hname, htitle, 100, -8000000, 8000000.);
0162   sprintf(hname, "hGeantVtxY2");
0163   histName_.push_back(hname);
0164   hGeantVtxY[1] = new TH1F(hname, htitle, 100, -50., 50.);
0165   for (Int_t i = 0; i < 2; ++i) {
0166     hGeantVtxY[i]->GetXaxis()->SetTitle("y of Vertex (um)");
0167     hGeantVtxY[i]->GetYaxis()->SetTitle("Count");
0168     histMap_[hGeantVtxY[i]->GetName()] = hGeantVtxY[i];
0169   }
0170 
0171   sprintf(hname, "hGeantVtxZ1");
0172   histName_.push_back(hname);
0173   sprintf(htitle, "Geant vertex z/millimeter");
0174   hGeantVtxZ[0] = new TH1F(hname, htitle, 100, -11000., 11000.);
0175   sprintf(hname, "hGeantVtxZ2");
0176   histName_.push_back(hname);
0177   hGeantVtxZ[1] = new TH1F(hname, htitle, 100, -250., 250.);
0178   for (Int_t i = 0; i < 2; ++i) {
0179     hGeantVtxZ[i]->GetXaxis()->SetTitle("z of Vertex (mm)");
0180     hGeantVtxZ[i]->GetYaxis()->SetTitle("Count");
0181     histMap_[hGeantVtxZ[i]->GetName()] = hGeantVtxZ[i];
0182   }
0183 
0184   sprintf(hname, "hGeantTrkPt");
0185   histName_.push_back(hname);
0186   sprintf(htitle, "Geant track pt/GeV");
0187   hGeantTrkPt = new TH1F(hname, htitle, 100, 0., 200.);
0188   hGeantTrkPt->GetXaxis()->SetTitle("pT of Track (GeV)");
0189   hGeantTrkPt->GetYaxis()->SetTitle("Count");
0190   histMap_[hGeantTrkPt->GetName()] = hGeantTrkPt;
0191 
0192   sprintf(hname, "hGeantTrkE");
0193   histName_.push_back(hname);
0194   sprintf(htitle, "Geant track E/GeV");
0195   hGeantTrkE = new TH1F(hname, htitle, 100, 0., 5000.);
0196   hGeantTrkE->GetXaxis()->SetTitle("E of Track (GeV)");
0197   hGeantTrkE->GetYaxis()->SetTitle("Count");
0198   histMap_[hGeantTrkE->GetName()] = hGeantTrkE;
0199 
0200   // ECal
0201   sprintf(hname, "hCaloEcal1");
0202   histName_.push_back(hname);
0203   sprintf(htitle, "Ecal hits");
0204   hCaloEcal[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0205   sprintf(hname, "hCaloEcal2");
0206   histName_.push_back(hname);
0207   hCaloEcal[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0208 
0209   sprintf(hname, "hCaloEcalE1");
0210   histName_.push_back(hname);
0211   sprintf(htitle, "Ecal hits, energy/GeV");
0212   hCaloEcalE[0] = new TH1F(hname, htitle, 100, 0., 10.);
0213   sprintf(hname, "hCaloEcalE2");
0214   histName_.push_back(hname);
0215   hCaloEcalE[1] = new TH1F(hname, htitle, 100, 0., 0.1);
0216 
0217   sprintf(hname, "hCaloEcalToF1");
0218   histName_.push_back(hname);
0219   sprintf(htitle, "Ecal hits, ToF/ns");
0220   hCaloEcalToF[0] = new TH1F(hname, htitle, 100, 0., 1000.);
0221   sprintf(hname, "hCaloEcalToF2");
0222   histName_.push_back(hname);
0223   hCaloEcalToF[1] = new TH1F(hname, htitle, 100, 0., 100.);
0224 
0225   for (Int_t i = 0; i < 2; ++i) {
0226     hCaloEcal[i]->GetXaxis()->SetTitle("Number of Hits");
0227     hCaloEcal[i]->GetYaxis()->SetTitle("Count");
0228     histMap_[hCaloEcal[i]->GetName()] = hCaloEcal[i];
0229     hCaloEcalE[i]->GetXaxis()->SetTitle("Energy of Hits (GeV)");
0230     hCaloEcalE[i]->GetYaxis()->SetTitle("Count");
0231     histMap_[hCaloEcalE[i]->GetName()] = hCaloEcalE[i];
0232     hCaloEcalToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0233     hCaloEcalToF[i]->GetYaxis()->SetTitle("Count");
0234     histMap_[hCaloEcalToF[i]->GetName()] = hCaloEcalToF[i];
0235   }
0236 
0237   sprintf(hname, "hCaloEcalPhi");
0238   histName_.push_back(hname);
0239   sprintf(htitle, "Ecal hits, phi/rad");
0240   hCaloEcalPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0241   hCaloEcalPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0242   hCaloEcalPhi->GetYaxis()->SetTitle("Count");
0243   histMap_[hCaloEcalPhi->GetName()] = hCaloEcalPhi;
0244 
0245   sprintf(hname, "hCaloEcalEta");
0246   histName_.push_back(hname);
0247   sprintf(htitle, "Ecal hits, eta");
0248   hCaloEcalEta = new TH1F(hname, htitle, 100, -5.5, 5.5);
0249   hCaloEcalEta->GetXaxis()->SetTitle("Eta of Hits");
0250   hCaloEcalEta->GetYaxis()->SetTitle("Count");
0251   histMap_[hCaloEcalEta->GetName()] = hCaloEcalEta;
0252 
0253   sprintf(hname, "hCaloPreSh1");
0254   histName_.push_back(hname);
0255   sprintf(htitle, "PreSh hits");
0256   hCaloPreSh[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0257   sprintf(hname, "hCaloPreSh2");
0258   histName_.push_back(hname);
0259   hCaloPreSh[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0260 
0261   sprintf(hname, "hCaloPreShE1");
0262   histName_.push_back(hname);
0263   sprintf(htitle, "PreSh hits, energy/GeV");
0264   hCaloPreShE[0] = new TH1F(hname, htitle, 100, 0., 10.);
0265   sprintf(hname, "hCaloPreShE2");
0266   histName_.push_back(hname);
0267   hCaloPreShE[1] = new TH1F(hname, htitle, 100, 0., 0.1);
0268 
0269   sprintf(hname, "hCaloPreShToF1");
0270   histName_.push_back(hname);
0271   sprintf(htitle, "PreSh hits, ToF/ns");
0272   hCaloPreShToF[0] = new TH1F(hname, htitle, 100, 0., 1000.);
0273   sprintf(hname, "hCaloPreShToF2");
0274   histName_.push_back(hname);
0275   hCaloPreShToF[1] = new TH1F(hname, htitle, 100, 0., 100.);
0276 
0277   for (Int_t i = 0; i < 2; ++i) {
0278     hCaloPreSh[i]->GetXaxis()->SetTitle("Number of Hits");
0279     hCaloPreSh[i]->GetYaxis()->SetTitle("Count");
0280     histMap_[hCaloPreSh[i]->GetName()] = hCaloPreSh[i];
0281     hCaloPreShE[i]->GetXaxis()->SetTitle("Energy of Hits (GeV)");
0282     hCaloPreShE[i]->GetYaxis()->SetTitle("Count");
0283     histMap_[hCaloPreShE[i]->GetName()] = hCaloPreShE[i];
0284     hCaloPreShToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0285     hCaloPreShToF[i]->GetYaxis()->SetTitle("Count");
0286     histMap_[hCaloPreShToF[i]->GetName()] = hCaloPreShToF[i];
0287   }
0288 
0289   sprintf(hname, "hCaloPreShPhi");
0290   histName_.push_back(hname);
0291   sprintf(htitle, "PreSh hits, phi/rad");
0292   hCaloPreShPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0293   hCaloPreShPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0294   hCaloPreShPhi->GetYaxis()->SetTitle("Count");
0295   histMap_[hCaloPreShPhi->GetName()] = hCaloPreShPhi;
0296 
0297   sprintf(hname, "hCaloPreShEta");
0298   histName_.push_back(hname);
0299   sprintf(htitle, "PreSh hits, eta");
0300   hCaloPreShEta = new TH1F(hname, htitle, 100, -5.5, 5.5);
0301   hCaloPreShEta->GetXaxis()->SetTitle("Eta of Hits");
0302   hCaloPreShEta->GetYaxis()->SetTitle("Count");
0303   histMap_[hCaloPreShEta->GetName()] = hCaloPreShEta;
0304 
0305   // Hcal
0306   sprintf(hname, "hCaloHcal1");
0307   histName_.push_back(hname);
0308   sprintf(htitle, "Hcal hits");
0309   hCaloHcal[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0310   sprintf(hname, "hCaloHcal2");
0311   histName_.push_back(hname);
0312   hCaloHcal[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0313 
0314   sprintf(hname, "hCaloHcalE1");
0315   histName_.push_back(hname);
0316   sprintf(htitle, "Hcal hits, energy/GeV");
0317   hCaloHcalE[0] = new TH1F(hname, htitle, 100, 0., 10.);
0318   sprintf(hname, "hCaloHcalE2");
0319   histName_.push_back(hname);
0320   hCaloHcalE[1] = new TH1F(hname, htitle, 100, 0., 0.1);
0321 
0322   sprintf(hname, "hCaloHcalToF1");
0323   histName_.push_back(hname);
0324   sprintf(htitle, "Hcal hits, ToF/ns");
0325   hCaloHcalToF[0] = new TH1F(hname, htitle, 100, 0., 1000.);
0326   sprintf(hname, "hCaloHcalToF2");
0327   histName_.push_back(hname);
0328   hCaloHcalToF[1] = new TH1F(hname, htitle, 100, 0., 100.);
0329 
0330   for (Int_t i = 0; i < 2; ++i) {
0331     hCaloHcal[i]->GetXaxis()->SetTitle("Number of Hits");
0332     hCaloHcal[i]->GetYaxis()->SetTitle("Count");
0333     histMap_[hCaloHcal[i]->GetName()] = hCaloHcal[i];
0334     hCaloHcalE[i]->GetXaxis()->SetTitle("Energy of Hits (GeV)");
0335     hCaloHcalE[i]->GetYaxis()->SetTitle("Count");
0336     histMap_[hCaloHcalE[i]->GetName()] = hCaloHcalE[i];
0337     hCaloHcalToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0338     hCaloHcalToF[i]->GetYaxis()->SetTitle("Count");
0339     histMap_[hCaloHcalToF[i]->GetName()] = hCaloHcalToF[i];
0340   }
0341 
0342   sprintf(hname, "hCaloHcalPhi");
0343   histName_.push_back(hname);
0344   sprintf(htitle, "Hcal hits, phi/rad");
0345   hCaloHcalPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0346   hCaloHcalPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0347   hCaloHcalPhi->GetYaxis()->SetTitle("Count");
0348   histMap_[hCaloHcalPhi->GetName()] = hCaloHcalPhi;
0349 
0350   sprintf(hname, "hCaloHcalEta");
0351   histName_.push_back(hname);
0352   sprintf(htitle, "Hcal hits, eta");
0353   hCaloHcalEta = new TH1F(hname, htitle, 100, -5.5, 5.5);
0354   hCaloHcalEta->GetXaxis()->SetTitle("Eta of Hits");
0355   hCaloHcalEta->GetYaxis()->SetTitle("Count");
0356   histMap_[hCaloHcalEta->GetName()] = hCaloHcalEta;
0357 
0358   // tracker
0359   sprintf(hname, "hTrackerPx1");
0360   histName_.push_back(hname);
0361   sprintf(htitle, "Pixel hits");
0362   hTrackerPx[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0363   sprintf(hname, "hTrackerPx2");
0364   histName_.push_back(hname);
0365   hTrackerPx[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0366   for (Int_t i = 0; i < 2; ++i) {
0367     hTrackerPx[i]->GetXaxis()->SetTitle("Number of Pixel Hits");
0368     hTrackerPx[i]->GetYaxis()->SetTitle("Count");
0369     histMap_[hTrackerPx[i]->GetName()] = hTrackerPx[i];
0370   }
0371 
0372   sprintf(hname, "hTrackerPxPhi");
0373   histName_.push_back(hname);
0374   sprintf(htitle, "Pixel hits phi/rad");
0375   hTrackerPxPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0376   hTrackerPxPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0377   hTrackerPxPhi->GetYaxis()->SetTitle("Count");
0378   histMap_[hTrackerPxPhi->GetName()] = hTrackerPxPhi;
0379 
0380   sprintf(hname, "hTrackerPxEta");
0381   histName_.push_back(hname);
0382   sprintf(htitle, "Pixel hits eta");
0383   hTrackerPxEta = new TH1F(hname, htitle, 100, -3.5, 3.5);
0384   hTrackerPxEta->GetXaxis()->SetTitle("Eta of Hits");
0385   hTrackerPxEta->GetYaxis()->SetTitle("Count");
0386   histMap_[hTrackerPxEta->GetName()] = hTrackerPxEta;
0387 
0388   sprintf(hname, "hTrackerPxBToF");
0389   histName_.push_back(hname);
0390   sprintf(htitle, "Pixel barrel hits, ToF/ns");
0391   hTrackerPxBToF = new TH1F(hname, htitle, 100, 0., 40.);
0392   hTrackerPxBToF->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0393   hTrackerPxBToF->GetYaxis()->SetTitle("Count");
0394   histMap_[hTrackerPxBToF->GetName()] = hTrackerPxBToF;
0395 
0396   sprintf(hname, "hTrackerPxBR");
0397   histName_.push_back(hname);
0398   sprintf(htitle, "Pixel barrel hits, R/cm");
0399   hTrackerPxBR = new TH1F(hname, htitle, 100, 0., 50.);
0400   hTrackerPxBR->GetXaxis()->SetTitle("R of Hits (cm)");
0401   hTrackerPxBR->GetYaxis()->SetTitle("Count");
0402   histMap_[hTrackerPxBR->GetName()] = hTrackerPxBR;
0403 
0404   sprintf(hname, "hTrackerPxFToF");
0405   histName_.push_back(hname);
0406   sprintf(htitle, "Pixel forward hits, ToF/ns");
0407   hTrackerPxFToF = new TH1F(hname, htitle, 100, 0., 50.);
0408   hTrackerPxFToF->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0409   hTrackerPxFToF->GetYaxis()->SetTitle("Count");
0410   histMap_[hTrackerPxFToF->GetName()] = hTrackerPxFToF;
0411 
0412   sprintf(hname, "hTrackerPxFZ");
0413   histName_.push_back(hname);
0414   sprintf(htitle, "Pixel forward hits, Z/cm");
0415   hTrackerPxFZ = new TH1F(hname, htitle, 200, -100., 100.);
0416   hTrackerPxFZ->GetXaxis()->SetTitle("Z of Hits (cm)");
0417   hTrackerPxFZ->GetYaxis()->SetTitle("Count");
0418   histMap_[hTrackerPxFZ->GetName()] = hTrackerPxFZ;
0419 
0420   sprintf(hname, "hTrackerSi1");
0421   histName_.push_back(hname);
0422   sprintf(htitle, "Silicon hits");
0423   hTrackerSi[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0424   sprintf(hname, "hTrackerSi2");
0425   histName_.push_back(hname);
0426   hTrackerSi[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0427   for (Int_t i = 0; i < 2; ++i) {
0428     hTrackerSi[i]->GetXaxis()->SetTitle("Number of Silicon Hits");
0429     hTrackerSi[i]->GetYaxis()->SetTitle("Count");
0430     histMap_[hTrackerSi[i]->GetName()] = hTrackerSi[i];
0431   }
0432 
0433   sprintf(hname, "hTrackerSiPhi");
0434   histName_.push_back(hname);
0435   sprintf(htitle, "Silicon hits phi/rad");
0436   hTrackerSiPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0437   hTrackerSiPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0438   hTrackerSiPhi->GetYaxis()->SetTitle("Count");
0439   histMap_[hTrackerSiPhi->GetName()] = hTrackerSiPhi;
0440 
0441   sprintf(hname, "hTrackerSiEta");
0442   histName_.push_back(hname);
0443   sprintf(htitle, "Silicon hits eta");
0444   hTrackerSiEta = new TH1F(hname, htitle, 100, -3.5, 3.5);
0445   hTrackerSiEta->GetXaxis()->SetTitle("Eta of Hits");
0446   hTrackerSiEta->GetYaxis()->SetTitle("Count");
0447   histMap_[hTrackerSiEta->GetName()] = hTrackerSiEta;
0448 
0449   sprintf(hname, "hTrackerSiBToF");
0450   histName_.push_back(hname);
0451   sprintf(htitle, "Silicon barrel hits, ToF/ns");
0452   hTrackerSiBToF = new TH1F(hname, htitle, 100, 0., 50.);
0453   hTrackerSiBToF->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0454   hTrackerSiBToF->GetYaxis()->SetTitle("Count");
0455   histMap_[hTrackerSiBToF->GetName()] = hTrackerSiBToF;
0456 
0457   sprintf(hname, "hTrackerSiBR");
0458   histName_.push_back(hname);
0459   sprintf(htitle, "Silicon barrel hits, R/cm");
0460   hTrackerSiBR = new TH1F(hname, htitle, 100, 0., 200.);
0461   hTrackerSiBR->GetXaxis()->SetTitle("R of Hits (cm)");
0462   hTrackerSiBR->GetYaxis()->SetTitle("Count");
0463   histMap_[hTrackerSiBR->GetName()] = hTrackerSiBR;
0464 
0465   sprintf(hname, "hTrackerSiFToF");
0466   histName_.push_back(hname);
0467   sprintf(htitle, "Silicon forward hits, ToF/ns");
0468   hTrackerSiFToF = new TH1F(hname, htitle, 100, 0., 75.);
0469   hTrackerSiFToF->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0470   hTrackerSiFToF->GetYaxis()->SetTitle("Count");
0471   histMap_[hTrackerSiFToF->GetName()] = hTrackerSiFToF;
0472 
0473   sprintf(hname, "hTrackerSiFZ");
0474   histName_.push_back(hname);
0475   sprintf(htitle, "Silicon forward hits, Z/cm");
0476   hTrackerSiFZ = new TH1F(hname, htitle, 200, -300., 300.);
0477   hTrackerSiFZ->GetXaxis()->SetTitle("Z of Hits (cm)");
0478   hTrackerSiFZ->GetYaxis()->SetTitle("Count");
0479   histMap_[hTrackerSiFZ->GetName()] = hTrackerSiFZ;
0480 
0481   // muon
0482   sprintf(hname, "hMuon1");
0483   histName_.push_back(hname);
0484   sprintf(htitle, "Muon hits");
0485   hMuon[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0486   sprintf(hname, "hMuon2");
0487   histName_.push_back(hname);
0488   hMuon[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0489   for (Int_t i = 0; i < 2; ++i) {
0490     hMuon[i]->GetXaxis()->SetTitle("Number of Muon Hits");
0491     hMuon[i]->GetYaxis()->SetTitle("Count");
0492     histMap_[hMuon[i]->GetName()] = hMuon[i];
0493   }
0494 
0495   sprintf(hname, "hMuonPhi");
0496   histName_.push_back(hname);
0497   sprintf(htitle, "Muon hits phi/rad");
0498   hMuonPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0499   hMuonPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0500   hMuonPhi->GetYaxis()->SetTitle("Count");
0501   histMap_[hMuonPhi->GetName()] = hMuonPhi;
0502 
0503   sprintf(hname, "hMuonEta");
0504   histName_.push_back(hname);
0505   sprintf(htitle, "Muon hits eta");
0506   hMuonEta = new TH1F(hname, htitle, 100, -3.5, 3.5);
0507   hMuonEta->GetXaxis()->SetTitle("Eta of Hits");
0508   hMuonEta->GetYaxis()->SetTitle("Count");
0509   histMap_[hMuonEta->GetName()] = hMuonEta;
0510 
0511   sprintf(hname, "hMuonCscToF1");
0512   histName_.push_back(hname);
0513   sprintf(htitle, "Muon CSC hits, ToF/ns");
0514   hMuonCscToF[0] = new TH1F(hname, htitle, 100, 0., 250.);
0515   sprintf(hname, "hMuonCscToF2");
0516   histName_.push_back(hname);
0517   hMuonCscToF[1] = new TH1F(hname, htitle, 100, 0., 50.);
0518   for (Int_t i = 0; i < 2; ++i) {
0519     hMuonCscToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0520     hMuonCscToF[i]->GetYaxis()->SetTitle("Count");
0521     histMap_[hMuonCscToF[i]->GetName()] = hMuonCscToF[i];
0522   }
0523 
0524   sprintf(hname, "hMuonCscZ");
0525   histName_.push_back(hname);
0526   sprintf(htitle, "Muon CSC hits, Z/cm");
0527   hMuonCscZ = new TH1F(hname, htitle, 200, -1500., 1500.);
0528   hMuonCscZ->GetXaxis()->SetTitle("Z of Hits (cm)");
0529   hMuonCscZ->GetYaxis()->SetTitle("Count");
0530   histMap_[hMuonCscZ->GetName()] = hMuonCscZ;
0531 
0532   sprintf(hname, "hMuonDtToF1");
0533   histName_.push_back(hname);
0534   sprintf(htitle, "Muon DT hits, ToF/ns");
0535   hMuonDtToF[0] = new TH1F(hname, htitle, 100, 0., 250.);
0536   sprintf(hname, "hMuonDtToF2");
0537   histName_.push_back(hname);
0538   hMuonDtToF[1] = new TH1F(hname, htitle, 100, 0., 50.);
0539   for (Int_t i = 0; i < 2; ++i) {
0540     hMuonDtToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0541     hMuonDtToF[i]->GetYaxis()->SetTitle("Count");
0542     histMap_[hMuonDtToF[i]->GetName()] = hMuonDtToF[i];
0543   }
0544 
0545   sprintf(hname, "hMuonDtR");
0546   histName_.push_back(hname);
0547   sprintf(htitle, "Muon DT hits, R/cm");
0548   hMuonDtR = new TH1F(hname, htitle, 100, 0., 1500.);
0549   hMuonDtR->GetXaxis()->SetTitle("R of Hits (cm)");
0550   hMuonDtR->GetYaxis()->SetTitle("Count");
0551   histMap_[hMuonDtR->GetName()] = hMuonDtR;
0552 
0553   sprintf(hname, "hMuonRpcFToF1");
0554   histName_.push_back(hname);
0555   sprintf(htitle, "Muon RPC forward hits, ToF/ns");
0556   hMuonRpcFToF[0] = new TH1F(hname, htitle, 100, 0., 250.);
0557   sprintf(hname, "hMuonRpcFToF2");
0558   histName_.push_back(hname);
0559   hMuonRpcFToF[1] = new TH1F(hname, htitle, 100, 0., 50.);
0560   for (Int_t i = 0; i < 2; ++i) {
0561     hMuonRpcFToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0562     hMuonRpcFToF[i]->GetYaxis()->SetTitle("Count");
0563     histMap_[hMuonRpcFToF[i]->GetName()] = hMuonRpcFToF[i];
0564   }
0565 
0566   sprintf(hname, "hMuonRpcFZ");
0567   histName_.push_back(hname);
0568   sprintf(htitle, "Muon RPC forward hits, Z/cm");
0569   hMuonRpcFZ = new TH1F(hname, htitle, 201, -1500., 1500.);
0570   hMuonRpcFZ->GetXaxis()->SetTitle("Z of Hits (cm)");
0571   hMuonRpcFZ->GetYaxis()->SetTitle("Count");
0572   histMap_[hMuonRpcFZ->GetName()] = hMuonRpcFZ;
0573 
0574   sprintf(hname, "hMuonRpcBToF1");
0575   histName_.push_back(hname);
0576   sprintf(htitle, "Muon RPC barrel hits, ToF/ns");
0577   hMuonRpcBToF[0] = new TH1F(hname, htitle, 100, 0., 250.);
0578   sprintf(hname, "hMuonRpcBToF2");
0579   histName_.push_back(hname);
0580   hMuonRpcBToF[1] = new TH1F(hname, htitle, 100, 0., 50.);
0581   for (Int_t i = 0; i < 2; ++i) {
0582     hMuonRpcBToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0583     hMuonRpcBToF[i]->GetYaxis()->SetTitle("Count");
0584     histMap_[hMuonRpcBToF[i]->GetName()] = hMuonRpcBToF[i];
0585   }
0586 
0587   sprintf(hname, "hMuonRpcBR");
0588   histName_.push_back(hname);
0589   sprintf(htitle, "Muon RPC barrel hits, R/cm");
0590   hMuonRpcBR = new TH1F(hname, htitle, 100, 0., 1500.);
0591   hMuonRpcBR->GetXaxis()->SetTitle("R of Hits (cm)");
0592   hMuonRpcBR->GetYaxis()->SetTitle("Count");
0593   histMap_[hMuonRpcBR->GetName()] = hMuonRpcBR;
0594 
0595   // create persistent objects
0596   for (std::size_t i = 0; i < histName_.size(); ++i) {
0597     produces<TH1F, edm::Transition::EndRun>(histName_[i]).setBranchAlias(histName_[i]);
0598   }
0599 }
0600 
0601 GlobalHitsProdHist::~GlobalHitsProdHist() {}
0602 
0603 void GlobalHitsProdHist::beginJob() { return; }
0604 
0605 void GlobalHitsProdHist::endJob() {
0606   std::string MsgLoggerCat = "GlobalHitsProdHist_endJob";
0607   if (verbosity >= 0)
0608     edm::LogInfo(MsgLoggerCat) << "Terminating having processed " << count << " events.";
0609   return;
0610 }
0611 
0612 void GlobalHitsProdHist::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0613   std::string MsgLoggerCat = "GlobalHitsProdHist_produce";
0614 
0615   // keep track of number of events processed
0616   ++count;
0617 
0618   // get event id information
0619   edm::RunNumber_t nrun = iEvent.id().run();
0620   edm::EventNumber_t nevt = iEvent.id().event();
0621 
0622   if (verbosity > 0) {
0623     edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << ", event " << nevt << " (" << count << " events total)";
0624   } else if (verbosity == 0) {
0625     if (nevt % frequency == 0 || nevt == 1) {
0626       edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << ", event " << nevt << " (" << count
0627                                  << " events total)";
0628     }
0629   }
0630 
0631   // look at information available in the event
0632   if (getAllProvenances) {
0633     std::vector<const edm::StableProvenance *> AllProv;
0634     iEvent.getAllStableProvenance(AllProv);
0635 
0636     if (verbosity >= 0)
0637       edm::LogInfo(MsgLoggerCat) << "Number of Provenances = " << AllProv.size();
0638 
0639     if (printProvenanceInfo && (verbosity >= 0)) {
0640       TString eventout("\nProvenance info:\n");
0641 
0642       for (unsigned int i = 0; i < AllProv.size(); ++i) {
0643         eventout += "\n       ******************************";
0644         eventout += "\n       Module       : ";
0645         eventout += AllProv[i]->moduleLabel();
0646         eventout += "\n       ProductID    : ";
0647         eventout += AllProv[i]->productID().id();
0648         eventout += "\n       ClassName    : ";
0649         eventout += AllProv[i]->className();
0650         eventout += "\n       InstanceName : ";
0651         eventout += AllProv[i]->productInstanceName();
0652         eventout += "\n       BranchName   : ";
0653         eventout += AllProv[i]->branchName();
0654       }
0655       eventout += "\n       ******************************\n";
0656       edm::LogInfo(MsgLoggerCat) << eventout << "\n";
0657       printProvenanceInfo = false;
0658     }
0659     getAllProvenances = false;
0660   }
0661 
0662   // call fill functions
0663   // gather G4MC information from event
0664   fillG4MC(iEvent);
0665   // gather Tracker information from event
0666   fillTrk(iEvent, iSetup);
0667   // gather muon information from event
0668   fillMuon(iEvent, iSetup);
0669   // gather Ecal information from event
0670   fillECal(iEvent, iSetup);
0671   // gather Hcal information from event
0672   fillHCal(iEvent, iSetup);
0673 
0674   if (verbosity > 0)
0675     edm::LogInfo(MsgLoggerCat) << "Done gathering data from event.";
0676 
0677   return;
0678 }
0679 
0680 void GlobalHitsProdHist::endRunProduce(edm::Run &iRun, const edm::EventSetup &iSetup) {
0681   std::string MsgLoggerCat = "GlobalHitsProdHist_endRun";
0682 
0683   TString eventout;
0684   TString eventoutw;
0685   bool warning = false;
0686 
0687   if (verbosity > 0)
0688     edm::LogInfo(MsgLoggerCat) << "\nStoring histograms.";
0689 
0690   // store persistent objects
0691   std::map<std::string, TH1F *>::iterator iter;
0692   for (std::size_t i = 0; i < histName_.size(); ++i) {
0693     iter = histMap_.find(histName_[i]);
0694     if (iter != histMap_.end()) {
0695       std::unique_ptr<TH1F> hist1D(iter->second);
0696       eventout += "\n Storing histogram " + histName_[i];
0697       iRun.put(std::move(hist1D), histName_[i]);
0698     } else {
0699       warning = true;
0700       eventoutw += "\n Unable to find histogram with name " + histName_[i];
0701     }
0702   }
0703 
0704   if (verbosity > 0) {
0705     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
0706     if (warning)
0707       edm::LogWarning(MsgLoggerCat) << eventoutw << "\n";
0708   }
0709   return;
0710 }
0711 
0712 //==================fill and store functions================================
0713 void GlobalHitsProdHist::fillG4MC(edm::Event &iEvent) {
0714   std::string MsgLoggerCat = "GlobalHitsProdHist_fillG4MC";
0715 
0716   TString eventout;
0717   if (verbosity > 0)
0718     eventout = "\nGathering info:";
0719 
0720   //////////////////////
0721   // get MC information
0722   /////////////////////
0723   edm::Handle<edm::HepMCProduct> HepMCEvt;
0724   std::vector<edm::Handle<edm::HepMCProduct>> AllHepMCEvt;
0725 
0726   //iEvent.getManyByType(AllHepMCEvt);
0727   throw cms::Exception("UnsupportedFunction") << "GlobalHitsProdHist::fillG4MC: "
0728                                               << "getManyByType has not been supported by the Framework since 2015. "
0729                                               << "This module has been broken since then. Maybe it should be deleted. "
0730                                               << "Another possibility is to upgrade to use GetterOfProducts instead.";
0731 
0732   // loop through products and extract VtxSmearing if available. Any of them
0733   // should have the information needed
0734   for (unsigned int i = 0; i < AllHepMCEvt.size(); ++i) {
0735     HepMCEvt = AllHepMCEvt[i];
0736     if ((HepMCEvt.provenance()->branchDescription()).moduleLabel() == "generatorSmeared")
0737       break;
0738   }
0739 
0740   if (!HepMCEvt.isValid()) {
0741     edm::LogWarning(MsgLoggerCat) << "Unable to find HepMCProduct in event!";
0742     return;
0743   } else {
0744     eventout += "\n          Using HepMCProduct: ";
0745     eventout += (HepMCEvt.provenance()->branchDescription()).moduleLabel();
0746   }
0747   const HepMC::GenEvent *MCEvt = HepMCEvt->GetEvent();
0748   nRawGenPart = MCEvt->particles_size();
0749 
0750   if (verbosity > 1) {
0751     eventout += "\n          Number of Raw Particles collected:......... ";
0752     eventout += nRawGenPart;
0753   }
0754 
0755   if (hMCRGP[0])
0756     hMCRGP[0]->Fill((float)nRawGenPart);
0757   if (hMCRGP[1])
0758     hMCRGP[1]->Fill((float)nRawGenPart);
0759 
0760   ////////////////////////////
0761   // get G4Vertex information
0762   ////////////////////////////
0763   // convert unit stored in SimVertex to mm
0764   float unit = 0.;
0765   if (vtxunit == 0)
0766     unit = 1.;  // already in mm
0767   if (vtxunit == 1)
0768     unit = 10.;  // stored in cm, convert to mm
0769 
0770   edm::Handle<edm::SimVertexContainer> G4VtxContainer;
0771   iEvent.getByToken(G4VtxSrc_Token_, G4VtxContainer);
0772   if (!G4VtxContainer.isValid()) {
0773     edm::LogWarning(MsgLoggerCat) << "Unable to find SimVertex in event!";
0774     return;
0775   }
0776   int i = 0;
0777   edm::SimVertexContainer::const_iterator itVtx;
0778   for (itVtx = G4VtxContainer->begin(); itVtx != G4VtxContainer->end(); ++itVtx) {
0779     ++i;
0780 
0781     const math::XYZTLorentzVector G4Vtx1(
0782         itVtx->position().x(), itVtx->position().y(), itVtx->position().z(), itVtx->position().e());
0783 
0784     double G4Vtx[4];
0785     G4Vtx1.GetCoordinates(G4Vtx);
0786 
0787     if (hGeantVtxX[0])
0788       hGeantVtxX[0]->Fill((G4Vtx[0] * unit) / micrometer);
0789     if (hGeantVtxX[1])
0790       hGeantVtxX[1]->Fill((G4Vtx[0] * unit) / micrometer);
0791 
0792     if (hGeantVtxY[0])
0793       hGeantVtxY[0]->Fill((G4Vtx[1] * unit) / micrometer);
0794     if (hGeantVtxY[1])
0795       hGeantVtxY[1]->Fill((G4Vtx[1] * unit) / micrometer);
0796 
0797     if (hGeantVtxZ[0])
0798       hGeantVtxZ[0]->Fill((G4Vtx[2] * unit) / millimeter);
0799     if (hGeantVtxZ[1])
0800       hGeantVtxZ[1]->Fill((G4Vtx[2] * unit) / millimeter);
0801   }
0802 
0803   if (verbosity > 1) {
0804     eventout += "\n          Number of G4Vertices collected:............ ";
0805     eventout += i;
0806   }
0807 
0808   if (hMCG4Vtx[0])
0809     hMCG4Vtx[0]->Fill((float)i);
0810   if (hMCG4Vtx[1])
0811     hMCG4Vtx[1]->Fill((float)i);
0812 
0813   ///////////////////////////
0814   // get G4Track information
0815   ///////////////////////////
0816   edm::Handle<edm::SimTrackContainer> G4TrkContainer;
0817   iEvent.getByToken(G4TrkSrc_Token_, G4TrkContainer);
0818   if (!G4TrkContainer.isValid()) {
0819     edm::LogWarning(MsgLoggerCat) << "Unable to find SimTrack in event!";
0820     return;
0821   }
0822   i = 0;
0823   edm::SimTrackContainer::const_iterator itTrk;
0824   for (itTrk = G4TrkContainer->begin(); itTrk != G4TrkContainer->end(); ++itTrk) {
0825     ++i;
0826 
0827     const math::XYZTLorentzVector G4Trk1(
0828         itTrk->momentum().x(), itTrk->momentum().y(), itTrk->momentum().z(), itTrk->momentum().e());
0829     double G4Trk[4];
0830     G4Trk1.GetCoordinates(G4Trk);
0831 
0832     if (hGeantTrkPt)
0833       hGeantTrkPt->Fill(sqrt(G4Trk[0] * G4Trk[0] + G4Trk[1] * G4Trk[1]));
0834     if (hGeantTrkE)
0835       hGeantTrkE->Fill(G4Trk[3]);
0836   }
0837 
0838   if (verbosity > 1) {
0839     eventout += "\n          Number of G4Tracks collected:.............. ";
0840     eventout += i;
0841   }
0842 
0843   if (hMCG4Trk[0])
0844     hMCG4Trk[0]->Fill((float)i);
0845   if (hMCG4Trk[1])
0846     hMCG4Trk[1]->Fill((float)i);
0847 
0848   if (verbosity > 0)
0849     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
0850 
0851   return;
0852 }
0853 
0854 void GlobalHitsProdHist::fillTrk(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0855   nPxlHits = 0;
0856   std::string MsgLoggerCat = "GlobalHitsProdHist_fillTrk";
0857 
0858   TString eventout;
0859   if (verbosity > 0)
0860     eventout = "\nGathering info:";
0861 
0862   // access the tracker geometry
0863   const auto &theTrackerGeometry = iSetup.getHandle(tGeomToken_);
0864   if (!theTrackerGeometry.isValid()) {
0865     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerDigiGeometryRecord in event!";
0866     return;
0867   }
0868   const TrackerGeometry &theTracker(*theTrackerGeometry);
0869 
0870   // iterator to access containers
0871   edm::PSimHitContainer::const_iterator itHit;
0872 
0873   ///////////////////////////////
0874   // get Pixel Barrel information
0875   ///////////////////////////////
0876   edm::PSimHitContainer thePxlBrlHits;
0877   // extract low container
0878   edm::Handle<edm::PSimHitContainer> PxlBrlLowContainer;
0879   iEvent.getByToken(PxlBrlLowSrc_Token_, PxlBrlLowContainer);
0880   if (!PxlBrlLowContainer.isValid()) {
0881     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsPixelBarrelLowTof in event!";
0882     return;
0883   }
0884   // extract high container
0885   edm::Handle<edm::PSimHitContainer> PxlBrlHighContainer;
0886   iEvent.getByToken(PxlBrlHighSrc_Token_, PxlBrlHighContainer);
0887   if (!PxlBrlHighContainer.isValid()) {
0888     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsPixelBarrelHighTof in event!";
0889     return;
0890   }
0891   // place both containers into new container
0892   thePxlBrlHits.insert(thePxlBrlHits.end(), PxlBrlLowContainer->begin(), PxlBrlLowContainer->end());
0893   thePxlBrlHits.insert(thePxlBrlHits.end(), PxlBrlHighContainer->begin(), PxlBrlHighContainer->end());
0894 
0895   // cycle through new container
0896   int i = 0, j = 0;
0897   for (itHit = thePxlBrlHits.begin(); itHit != thePxlBrlHits.end(); ++itHit) {
0898     ++i;
0899 
0900     // create a DetId from the detUnitId
0901     DetId theDetUnitId(itHit->detUnitId());
0902     int detector = theDetUnitId.det();
0903     int subdetector = theDetUnitId.subdetId();
0904 
0905     // check that expected detector is returned
0906     if ((detector == dTrk) && (subdetector == sdPxlBrl)) {
0907       // get the GeomDetUnit from the geometry using theDetUnitID
0908       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
0909 
0910       if (!theDet) {
0911         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from PxlBrlHits for Hit " << i;
0912         continue;
0913       }
0914 
0915       ++j;
0916 
0917       // get the Surface of the hit (knows how to go from local <-> global)
0918       const BoundPlane &bSurface = theDet->surface();
0919 
0920       if (hTrackerPxBToF)
0921         hTrackerPxBToF->Fill(itHit->tof());
0922       if (hTrackerPxBR)
0923         hTrackerPxBR->Fill(bSurface.toGlobal(itHit->localPosition()).perp());
0924       if (hTrackerPxPhi)
0925         hTrackerPxPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
0926       if (hTrackerPxEta)
0927         hTrackerPxEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
0928 
0929     } else {
0930       edm::LogWarning(MsgLoggerCat) << "PxlBrl PSimHit " << i << " is expected to be (det,subdet) = (" << dTrk << ","
0931                                     << sdPxlBrl << "); value returned is: (" << detector << "," << subdetector << ")";
0932       continue;
0933     }  // end detector type check
0934   }    // end loop through PxlBrl Hits
0935 
0936   if (verbosity > 1) {
0937     eventout += "\n          Number of Pixel Barrel Hits collected:..... ";
0938     eventout += j;
0939   }
0940 
0941   nPxlHits += j;
0942 
0943   /////////////////////////////////
0944   // get Pixel Forward information
0945   ////////////////////////////////
0946   edm::PSimHitContainer thePxlFwdHits;
0947   // extract low container
0948   edm::Handle<edm::PSimHitContainer> PxlFwdLowContainer;
0949   iEvent.getByToken(PxlFwdLowSrc_Token_, PxlFwdLowContainer);
0950   if (!PxlFwdLowContainer.isValid()) {
0951     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsPixelEndcapLowTof in event!";
0952     return;
0953   }
0954   // extract high container
0955   edm::Handle<edm::PSimHitContainer> PxlFwdHighContainer;
0956   iEvent.getByToken(PxlFwdHighSrc_Token_, PxlFwdHighContainer);
0957   if (!PxlFwdHighContainer.isValid()) {
0958     edm::LogWarning("GlobalHitsProdHist_fillTrk") << "Unable to find TrackerHitsPixelEndcapHighTof in event!";
0959     return;
0960   }
0961   // place both containers into new container
0962   thePxlFwdHits.insert(thePxlFwdHits.end(), PxlFwdLowContainer->begin(), PxlFwdLowContainer->end());
0963   thePxlFwdHits.insert(thePxlFwdHits.end(), PxlFwdHighContainer->begin(), PxlFwdHighContainer->end());
0964 
0965   // cycle through new container
0966   i = 0;
0967   j = 0;
0968   for (itHit = thePxlFwdHits.begin(); itHit != thePxlFwdHits.end(); ++itHit) {
0969     ++i;
0970 
0971     // create a DetId from the detUnitId
0972     DetId theDetUnitId(itHit->detUnitId());
0973     int detector = theDetUnitId.det();
0974     int subdetector = theDetUnitId.subdetId();
0975 
0976     // check that expected detector is returned
0977     if ((detector == dTrk) && (subdetector == sdPxlFwd)) {
0978       // get the GeomDetUnit from the geometry using theDetUnitID
0979       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
0980 
0981       if (!theDet) {
0982         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from PxlFwdHits for Hit " << i;
0983         ;
0984         continue;
0985       }
0986 
0987       ++j;
0988 
0989       // get the Surface of the hit (knows how to go from local <-> global)
0990       const BoundPlane &bSurface = theDet->surface();
0991 
0992       if (hTrackerPxFToF)
0993         hTrackerPxFToF->Fill(itHit->tof());
0994       if (hTrackerPxFZ)
0995         hTrackerPxFZ->Fill(bSurface.toGlobal(itHit->localPosition()).z());
0996       if (hTrackerPxPhi)
0997         hTrackerPxPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
0998       if (hTrackerPxEta)
0999         hTrackerPxEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1000 
1001     } else {
1002       edm::LogWarning(MsgLoggerCat) << "PxlFwd PSimHit " << i << " is expected to be (det,subdet) = (" << dTrk << ","
1003                                     << sdPxlFwd << "); value returned is: (" << detector << "," << subdetector << ")";
1004       continue;
1005     }  // end detector type check
1006   }    // end loop through PxlFwd Hits
1007 
1008   if (verbosity > 1) {
1009     eventout += "\n          Number of Pixel Forward Hits collected:.... ";
1010     eventout += j;
1011   }
1012 
1013   nPxlHits += j;
1014 
1015   if (hTrackerPx[0])
1016     hTrackerPx[0]->Fill((float)nPxlHits);
1017   if (hTrackerPx[1])
1018     hTrackerPx[1]->Fill((float)nPxlHits);
1019 
1020   ///////////////////////////////////
1021   // get Silicon Barrel information
1022   //////////////////////////////////
1023   nSiHits = 0;
1024   edm::PSimHitContainer theSiBrlHits;
1025   // extract TIB low container
1026   edm::Handle<edm::PSimHitContainer> SiTIBLowContainer;
1027   iEvent.getByToken(SiTIBLowSrc_Token_, SiTIBLowContainer);
1028   if (!SiTIBLowContainer.isValid()) {
1029     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTIBLowTof in event!";
1030     return;
1031   }
1032   // extract TIB high container
1033   edm::Handle<edm::PSimHitContainer> SiTIBHighContainer;
1034   iEvent.getByToken(SiTIBHighSrc_Token_, SiTIBHighContainer);
1035   if (!SiTIBHighContainer.isValid()) {
1036     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTIBHighTof in event!";
1037     return;
1038   }
1039   // extract TOB low container
1040   edm::Handle<edm::PSimHitContainer> SiTOBLowContainer;
1041   iEvent.getByToken(SiTOBLowSrc_Token_, SiTOBLowContainer);
1042   if (!SiTOBLowContainer.isValid()) {
1043     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTOBLowTof in event!";
1044     return;
1045   }
1046   // extract TOB high container
1047   edm::Handle<edm::PSimHitContainer> SiTOBHighContainer;
1048   iEvent.getByToken(SiTOBHighSrc_Token_, SiTOBHighContainer);
1049   if (!SiTOBHighContainer.isValid()) {
1050     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTOBHighTof in event!";
1051     return;
1052   }
1053   // place all containers into new container
1054   theSiBrlHits.insert(theSiBrlHits.end(), SiTIBLowContainer->begin(), SiTIBLowContainer->end());
1055   theSiBrlHits.insert(theSiBrlHits.end(), SiTIBHighContainer->begin(), SiTIBHighContainer->end());
1056   theSiBrlHits.insert(theSiBrlHits.end(), SiTOBLowContainer->begin(), SiTOBLowContainer->end());
1057   theSiBrlHits.insert(theSiBrlHits.end(), SiTOBHighContainer->begin(), SiTOBHighContainer->end());
1058 
1059   // cycle through new container
1060   i = 0;
1061   j = 0;
1062   for (itHit = theSiBrlHits.begin(); itHit != theSiBrlHits.end(); ++itHit) {
1063     ++i;
1064 
1065     // create a DetId from the detUnitId
1066     DetId theDetUnitId(itHit->detUnitId());
1067     int detector = theDetUnitId.det();
1068     int subdetector = theDetUnitId.subdetId();
1069 
1070     // check that expected detector is returned
1071     if ((detector == dTrk) && ((subdetector == sdSiTIB) || (subdetector == sdSiTOB))) {
1072       // get the GeomDetUnit from the geometry using theDetUnitID
1073       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
1074 
1075       if (!theDet) {
1076         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from SiBrlHits for Hit " << i;
1077         continue;
1078       }
1079 
1080       ++j;
1081 
1082       // get the Surface of the hit (knows how to go from local <-> global)
1083       const BoundPlane &bSurface = theDet->surface();
1084 
1085       if (hTrackerSiBToF)
1086         hTrackerSiBToF->Fill(itHit->tof());
1087       if (hTrackerSiBR)
1088         hTrackerSiBR->Fill(bSurface.toGlobal(itHit->localPosition()).perp());
1089       if (hTrackerSiPhi)
1090         hTrackerSiPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1091       if (hTrackerSiEta)
1092         hTrackerSiEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1093 
1094     } else {
1095       edm::LogWarning(MsgLoggerCat) << "SiBrl PSimHit " << i << " is expected to be (det,subdet) = (" << dTrk << ","
1096                                     << sdSiTIB << " || " << sdSiTOB << "); value returned is: (" << detector << ","
1097                                     << subdetector << ")";
1098       continue;
1099     }  // end detector type check
1100   }    // end loop through SiBrl Hits
1101 
1102   if (verbosity > 1) {
1103     eventout += "\n          Number of Silicon Barrel Hits collected:... ";
1104     eventout += j;
1105   }
1106 
1107   nSiHits += j;
1108 
1109   ///////////////////////////////////
1110   // get Silicon Forward information
1111   ///////////////////////////////////
1112   edm::PSimHitContainer theSiFwdHits;
1113   // extract TID low container
1114   edm::Handle<edm::PSimHitContainer> SiTIDLowContainer;
1115   iEvent.getByToken(SiTIDLowSrc_Token_, SiTIDLowContainer);
1116   if (!SiTIDLowContainer.isValid()) {
1117     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTIDLowTof in event!";
1118     return;
1119   }
1120   // extract TID high container
1121   edm::Handle<edm::PSimHitContainer> SiTIDHighContainer;
1122   iEvent.getByToken(SiTIDHighSrc_Token_, SiTIDHighContainer);
1123   if (!SiTIDHighContainer.isValid()) {
1124     edm::LogWarning("GlobalHitsProdHist_fillTrk") << "Unable to find TrackerHitsTIDHighTof in event!";
1125     return;
1126   }
1127   // extract TEC low container
1128   edm::Handle<edm::PSimHitContainer> SiTECLowContainer;
1129   iEvent.getByToken(SiTECLowSrc_Token_, SiTECLowContainer);
1130   if (!SiTECLowContainer.isValid()) {
1131     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTECLowTof in event!";
1132     return;
1133   }
1134   // extract TEC high container
1135   edm::Handle<edm::PSimHitContainer> SiTECHighContainer;
1136   iEvent.getByToken(SiTECHighSrc_Token_, SiTECHighContainer);
1137   if (!SiTECHighContainer.isValid()) {
1138     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTECHighTof in event!";
1139     return;
1140   }
1141   // place all containers into new container
1142   theSiFwdHits.insert(theSiFwdHits.end(), SiTIDLowContainer->begin(), SiTIDLowContainer->end());
1143   theSiFwdHits.insert(theSiFwdHits.end(), SiTIDHighContainer->begin(), SiTIDHighContainer->end());
1144   theSiFwdHits.insert(theSiFwdHits.end(), SiTECLowContainer->begin(), SiTECLowContainer->end());
1145   theSiFwdHits.insert(theSiFwdHits.end(), SiTECHighContainer->begin(), SiTECHighContainer->end());
1146 
1147   // cycle through container
1148   i = 0;
1149   j = 0;
1150   for (itHit = theSiFwdHits.begin(); itHit != theSiFwdHits.end(); ++itHit) {
1151     ++i;
1152 
1153     // create a DetId from the detUnitId
1154     DetId theDetUnitId(itHit->detUnitId());
1155     int detector = theDetUnitId.det();
1156     int subdetector = theDetUnitId.subdetId();
1157 
1158     // check that expected detector is returned
1159     if ((detector == dTrk) && ((subdetector == sdSiTID) || (subdetector == sdSiTEC))) {
1160       // get the GeomDetUnit from the geometry using theDetUnitID
1161       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
1162 
1163       if (!theDet) {
1164         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from SiFwdHits Hit " << i;
1165         return;
1166       }
1167 
1168       ++j;
1169 
1170       // get the Surface of the hit (knows how to go from local <-> global)
1171       const BoundPlane &bSurface = theDet->surface();
1172 
1173       if (hTrackerSiFToF)
1174         hTrackerSiFToF->Fill(itHit->tof());
1175       if (hTrackerSiFZ)
1176         hTrackerSiFZ->Fill(bSurface.toGlobal(itHit->localPosition()).z());
1177       if (hTrackerSiPhi)
1178         hTrackerSiPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1179       if (hTrackerSiEta)
1180         hTrackerSiEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1181 
1182     } else {
1183       edm::LogWarning(MsgLoggerCat) << "SiFwd PSimHit " << i << " is expected to be (det,subdet) = (" << dTrk << ","
1184                                     << sdSiTOB << " || " << sdSiTEC << "); value returned is: (" << detector << ","
1185                                     << subdetector << ")";
1186       continue;
1187     }  // end check detector type
1188   }    // end loop through SiFwd Hits
1189 
1190   if (verbosity > 1) {
1191     eventout += "\n          Number of Silicon Forward Hits collected:.. ";
1192     eventout += j;
1193   }
1194 
1195   nSiHits += j;
1196 
1197   if (hTrackerSi[0])
1198     hTrackerSi[0]->Fill((float)nSiHits);
1199   if (hTrackerSi[1])
1200     hTrackerSi[1]->Fill((float)nSiHits);
1201 
1202   if (verbosity > 0)
1203     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1204 
1205   return;
1206 }
1207 
1208 void GlobalHitsProdHist::fillMuon(edm::Event &iEvent, const edm::EventSetup &iSetup) {
1209   nMuonHits = 0;
1210   std::string MsgLoggerCat = "GlobalHitsProdHist_fillMuon";
1211 
1212   TString eventout;
1213   if (verbosity > 0)
1214     eventout = "\nGathering info:";
1215 
1216   // iterator to access containers
1217   edm::PSimHitContainer::const_iterator itHit;
1218 
1219   ///////////////////////
1220   // access the CSC Muon
1221   ///////////////////////
1222   // access the CSC Muon geometry
1223   const auto &theCSCGeometry = iSetup.getHandle(cscGeomToken_);
1224   if (!theCSCGeometry.isValid()) {
1225     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonGeometryRecord for the CSCGeometry in event!";
1226     return;
1227   }
1228   const CSCGeometry &theCSCMuon(*theCSCGeometry);
1229 
1230   // get Muon CSC information
1231   edm::Handle<edm::PSimHitContainer> MuonCSCContainer;
1232   iEvent.getByToken(MuonCscSrc_Token_, MuonCSCContainer);
1233   if (!MuonCSCContainer.isValid()) {
1234     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonCSCHits in event!";
1235     return;
1236   }
1237 
1238   // cycle through container
1239   int i = 0, j = 0;
1240   for (itHit = MuonCSCContainer->begin(); itHit != MuonCSCContainer->end(); ++itHit) {
1241     ++i;
1242 
1243     // create a DetId from the detUnitId
1244     DetId theDetUnitId(itHit->detUnitId());
1245     int detector = theDetUnitId.det();
1246     int subdetector = theDetUnitId.subdetId();
1247 
1248     // check that expected detector is returned
1249     if ((detector == dMuon) && (subdetector == sdMuonCSC)) {
1250       // get the GeomDetUnit from the geometry using theDetUnitID
1251       const GeomDetUnit *theDet = theCSCMuon.idToDetUnit(theDetUnitId);
1252 
1253       if (!theDet) {
1254         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from theCSCMuon for hit " << i;
1255         continue;
1256       }
1257 
1258       ++j;
1259 
1260       // get the Surface of the hit (knows how to go from local <-> global)
1261       const BoundPlane &bSurface = theDet->surface();
1262 
1263       if (hMuonCscToF[0])
1264         hMuonCscToF[0]->Fill(itHit->tof());
1265       if (hMuonCscToF[1])
1266         hMuonCscToF[1]->Fill(itHit->tof());
1267       if (hMuonCscZ)
1268         hMuonCscZ->Fill(bSurface.toGlobal(itHit->localPosition()).z());
1269       if (hMuonPhi)
1270         hMuonPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1271       if (hMuonEta)
1272         hMuonEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1273 
1274     } else {
1275       edm::LogWarning(MsgLoggerCat) << "MuonCsc PSimHit " << i << " is expected to be (det,subdet) = (" << dMuon << ","
1276                                     << sdMuonCSC << "); value returned is: (" << detector << "," << subdetector << ")";
1277       continue;
1278     }  // end detector type check
1279   }    // end loop through CSC Hits
1280 
1281   if (verbosity > 1) {
1282     eventout += "\n          Number of CSC muon Hits collected:......... ";
1283     eventout += j;
1284   }
1285 
1286   nMuonHits += j;
1287 
1288   /////////////////////
1289   // access the DT Muon
1290   /////////////////////
1291   // access the DT Muon geometry
1292   const auto &theDTGeometry = iSetup.getHandle(dtGeomToken_);
1293   if (!theDTGeometry.isValid()) {
1294     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonGeometryRecord for the DTGeometry in event!";
1295     return;
1296   }
1297   const DTGeometry &theDTMuon(*theDTGeometry);
1298 
1299   // get Muon DT information
1300   edm::Handle<edm::PSimHitContainer> MuonDtContainer;
1301   iEvent.getByToken(MuonDtSrc_Token_, MuonDtContainer);
1302   if (!MuonDtContainer.isValid()) {
1303     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonDTHits in event!";
1304     return;
1305   }
1306 
1307   // cycle through container
1308   i = 0, j = 0;
1309   for (itHit = MuonDtContainer->begin(); itHit != MuonDtContainer->end(); ++itHit) {
1310     ++i;
1311 
1312     // create a DetId from the detUnitId
1313     DetId theDetUnitId(itHit->detUnitId());
1314     int detector = theDetUnitId.det();
1315     int subdetector = theDetUnitId.subdetId();
1316 
1317     // check that expected detector is returned
1318     if ((detector == dMuon) && (subdetector == sdMuonDT)) {
1319       // CSC uses wires and layers rather than the full detID
1320       // get the wireId
1321       DTWireId wireId(itHit->detUnitId());
1322 
1323       // get the DTLayer from the geometry using the wireID
1324       const DTLayer *theDet = theDTMuon.layer(wireId.layerId());
1325 
1326       if (!theDet) {
1327         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from theDtMuon for hit " << i;
1328         continue;
1329       }
1330 
1331       ++j;
1332 
1333       // get the Surface of the hit (knows how to go from local <-> global)
1334       const BoundPlane &bSurface = theDet->surface();
1335 
1336       if (hMuonDtToF[0])
1337         hMuonDtToF[0]->Fill(itHit->tof());
1338       if (hMuonDtToF[1])
1339         hMuonDtToF[1]->Fill(itHit->tof());
1340       if (hMuonDtR)
1341         hMuonDtR->Fill(bSurface.toGlobal(itHit->localPosition()).perp());
1342       if (hMuonPhi)
1343         hMuonPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1344       if (hMuonEta)
1345         hMuonEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1346 
1347     } else {
1348       edm::LogWarning(MsgLoggerCat) << "MuonDt PSimHit " << i << " is expected to be (det,subdet) = (" << dMuon << ","
1349                                     << sdMuonDT << "); value returned is: (" << detector << "," << subdetector << ")";
1350       continue;
1351     }  // end detector type check
1352   }    // end loop through DT Hits
1353 
1354   if (verbosity > 1) {
1355     eventout += "\n          Number of DT muon Hits collected:.......... ";
1356     eventout += j;
1357   }
1358 
1359   nMuonHits += j;
1360 
1361   // int RPCBrl = 0, RPCFwd = 0;
1362   ///////////////////////
1363   // access the RPC Muon
1364   ///////////////////////
1365   // access the RPC Muon geometry
1366   const auto &theRPCGeometry = iSetup.getHandle(rpcGeomToken_);
1367   if (!theRPCGeometry.isValid()) {
1368     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonGeometryRecord for the RPCGeometry in event!";
1369     return;
1370   }
1371   const RPCGeometry &theRPCMuon(*theRPCGeometry);
1372 
1373   // get Muon RPC information
1374   edm::Handle<edm::PSimHitContainer> MuonRPCContainer;
1375   iEvent.getByToken(MuonRpcSrc_Token_, MuonRPCContainer);
1376   if (!MuonRPCContainer.isValid()) {
1377     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonRPCHits in event!";
1378     return;
1379   }
1380 
1381   // cycle through container
1382   i = 0, j = 0;
1383   int RPCBrl = 0, RPCFwd = 0;
1384   for (itHit = MuonRPCContainer->begin(); itHit != MuonRPCContainer->end(); ++itHit) {
1385     ++i;
1386 
1387     // create a DetID from the detUnitId
1388     DetId theDetUnitId(itHit->detUnitId());
1389     int detector = theDetUnitId.det();
1390     int subdetector = theDetUnitId.subdetId();
1391 
1392     // check that expected detector is returned
1393     if ((detector == dMuon) && (subdetector == sdMuonRPC)) {
1394       // get an RPCDetID from the detUnitID
1395       RPCDetId RPCId(itHit->detUnitId());
1396 
1397       // find the region of the RPC hit
1398       int region = RPCId.region();
1399 
1400       // get the GeomDetUnit from the geometry using the RPCDetId
1401       const GeomDetUnit *theDet = theRPCMuon.idToDetUnit(theDetUnitId);
1402 
1403       if (!theDet) {
1404         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from theRPCMuon for hit " << i;
1405         continue;
1406       }
1407 
1408       ++j;
1409 
1410       // get the Surface of the hit (knows how to go from local <-> global)
1411       const BoundPlane &bSurface = theDet->surface();
1412 
1413       // gather necessary information
1414       if ((region == sdMuonRPCRgnFwdp) || (region == sdMuonRPCRgnFwdn)) {
1415         ++RPCFwd;
1416 
1417         if (hMuonRpcFToF[0])
1418           hMuonRpcFToF[0]->Fill(itHit->tof());
1419         if (hMuonRpcFToF[1])
1420           hMuonRpcFToF[1]->Fill(itHit->tof());
1421         if (hMuonRpcFZ)
1422           hMuonRpcFZ->Fill(bSurface.toGlobal(itHit->localPosition()).z());
1423         if (hMuonPhi)
1424           hMuonPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1425         if (hMuonEta)
1426           hMuonEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1427 
1428       } else if (region == sdMuonRPCRgnBrl) {
1429         ++RPCBrl;
1430 
1431         if (hMuonRpcBToF[0])
1432           hMuonRpcBToF[0]->Fill(itHit->tof());
1433         if (hMuonRpcBToF[1])
1434           hMuonRpcBToF[1]->Fill(itHit->tof());
1435         if (hMuonRpcBR)
1436           hMuonRpcBR->Fill(bSurface.toGlobal(itHit->localPosition()).perp());
1437         if (hMuonPhi)
1438           hMuonPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1439         if (hMuonEta)
1440           hMuonEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1441 
1442       } else {
1443         edm::LogWarning(MsgLoggerCat) << "Invalid region for RPC Muon hit" << i;
1444         continue;
1445       }  // end check of region
1446     } else {
1447       edm::LogWarning(MsgLoggerCat) << "MuonRpc PSimHit " << i << " is expected to be (det,subdet) = (" << dMuon << ","
1448                                     << sdMuonRPC << "); value returned is: (" << detector << "," << subdetector << ")";
1449       continue;
1450     }  // end detector type check
1451   }    // end loop through RPC Hits
1452 
1453   if (verbosity > 1) {
1454     eventout += "\n          Number of RPC muon Hits collected:......... ";
1455     eventout += j;
1456     eventout += "\n                    RPC Barrel muon Hits:............ ";
1457     eventout += RPCBrl;
1458     eventout += "\n                    RPC Forward muon Hits:........... ";
1459     eventout += RPCFwd;
1460   }
1461 
1462   nMuonHits += j;
1463 
1464   if (hMuon[0])
1465     hMuon[0]->Fill((float)nMuonHits);
1466   if (hMuon[1])
1467     hMuon[1]->Fill((float)nMuonHits);
1468 
1469   if (verbosity > 0)
1470     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1471 
1472   return;
1473 }
1474 
1475 void GlobalHitsProdHist::fillECal(edm::Event &iEvent, const edm::EventSetup &iSetup) {
1476   std::string MsgLoggerCat = "GlobalHitsProdHist_fillECal";
1477 
1478   TString eventout;
1479   if (verbosity > 0)
1480     eventout = "\nGathering info:";
1481 
1482   // access the calorimeter geometry
1483   const auto &theCaloGeometry = iSetup.getHandle(caloGeomToken_);
1484   if (!theCaloGeometry.isValid()) {
1485     edm::LogWarning(MsgLoggerCat) << "Unable to find CaloGeometryRecord in event!";
1486     return;
1487   }
1488   const CaloGeometry &theCalo(*theCaloGeometry);
1489 
1490   // iterator to access containers
1491   edm::PCaloHitContainer::const_iterator itHit;
1492 
1493   ///////////////////////////////
1494   // get  ECal information
1495   ///////////////////////////////
1496   edm::PCaloHitContainer theECalHits;
1497   // extract EB container
1498   edm::Handle<edm::PCaloHitContainer> EBContainer;
1499   iEvent.getByToken(ECalEBSrc_Token_, EBContainer);
1500   if (!EBContainer.isValid()) {
1501     edm::LogWarning(MsgLoggerCat) << "Unable to find EcalHitsEB in event!";
1502     return;
1503   }
1504   // extract EE container
1505   edm::Handle<edm::PCaloHitContainer> EEContainer;
1506   iEvent.getByToken(ECalEESrc_Token_, EEContainer);
1507   if (!EEContainer.isValid()) {
1508     edm::LogWarning(MsgLoggerCat) << "Unable to find EcalHitsEE in event!";
1509     return;
1510   }
1511   // place both containers into new container
1512   theECalHits.insert(theECalHits.end(), EBContainer->begin(), EBContainer->end());
1513   theECalHits.insert(theECalHits.end(), EEContainer->begin(), EEContainer->end());
1514 
1515   // cycle through new container
1516   int i = 0, j = 0;
1517   for (itHit = theECalHits.begin(); itHit != theECalHits.end(); ++itHit) {
1518     ++i;
1519 
1520     // create a DetId from the detUnitId
1521     DetId theDetUnitId(itHit->id());
1522     int detector = theDetUnitId.det();
1523     int subdetector = theDetUnitId.subdetId();
1524 
1525     // check that expected detector is returned
1526     if ((detector == dEcal) && ((subdetector == sdEcalBrl) || (subdetector == sdEcalFwd))) {
1527       // get the Cell geometry
1528       auto theDet = (theCalo.getSubdetectorGeometry(theDetUnitId))->getGeometry(theDetUnitId);
1529 
1530       if (!theDet) {
1531         edm::LogWarning(MsgLoggerCat) << "Unable to get CaloCellGeometry from ECalHits for Hit " << i;
1532         continue;
1533       }
1534 
1535       ++j;
1536 
1537       // get the global position of the cell
1538       const GlobalPoint &globalposition = theDet->getPosition();
1539 
1540       if (hCaloEcalE[0])
1541         hCaloEcalE[0]->Fill(itHit->energy());
1542       if (hCaloEcalE[1])
1543         hCaloEcalE[1]->Fill(itHit->energy());
1544       if (hCaloEcalToF[0])
1545         hCaloEcalToF[0]->Fill(itHit->time());
1546       if (hCaloEcalToF[1])
1547         hCaloEcalToF[1]->Fill(itHit->time());
1548       if (hCaloEcalPhi)
1549         hCaloEcalPhi->Fill(globalposition.phi());
1550       if (hCaloEcalEta)
1551         hCaloEcalEta->Fill(globalposition.eta());
1552 
1553     } else {
1554       edm::LogWarning(MsgLoggerCat) << "ECal PCaloHit " << i << " is expected to be (det,subdet) = (" << dEcal << ","
1555                                     << sdEcalBrl << " || " << sdEcalFwd << "); value returned is: (" << detector << ","
1556                                     << subdetector << ")";
1557       continue;
1558     }  // end detector type check
1559   }    // end loop through ECal Hits
1560 
1561   if (verbosity > 1) {
1562     eventout += "\n          Number of ECal Hits collected:............. ";
1563     eventout += j;
1564   }
1565 
1566   if (hCaloEcal[0])
1567     hCaloEcal[0]->Fill((float)j);
1568   if (hCaloEcal[1])
1569     hCaloEcal[1]->Fill((float)j);
1570 
1571   ////////////////////////////
1572   // Get Preshower information
1573   ////////////////////////////
1574   // extract PreShower container
1575   edm::Handle<edm::PCaloHitContainer> PreShContainer;
1576   iEvent.getByToken(ECalESSrc_Token_, PreShContainer);
1577   if (!PreShContainer.isValid()) {
1578     edm::LogWarning(MsgLoggerCat) << "Unable to find EcalHitsES in event!";
1579     return;
1580   }
1581 
1582   // cycle through container
1583   i = 0, j = 0;
1584   for (itHit = PreShContainer->begin(); itHit != PreShContainer->end(); ++itHit) {
1585     ++i;
1586 
1587     // create a DetId from the detUnitId
1588     DetId theDetUnitId(itHit->id());
1589     int detector = theDetUnitId.det();
1590     int subdetector = theDetUnitId.subdetId();
1591 
1592     // check that expected detector is returned
1593     if ((detector == dEcal) && (subdetector == sdEcalPS)) {
1594       // get the Cell geometry
1595       auto theDet = (theCalo.getSubdetectorGeometry(theDetUnitId))->getGeometry(theDetUnitId);
1596 
1597       if (!theDet) {
1598         edm::LogWarning(MsgLoggerCat) << "Unable to get CaloCellGeometry from PreShContainer for Hit " << i;
1599         continue;
1600       }
1601 
1602       ++j;
1603 
1604       // get the global position of the cell
1605       const GlobalPoint &globalposition = theDet->getPosition();
1606 
1607       if (hCaloPreShE[0])
1608         hCaloPreShE[0]->Fill(itHit->energy());
1609       if (hCaloPreShE[1])
1610         hCaloPreShE[1]->Fill(itHit->energy());
1611       if (hCaloPreShToF[0])
1612         hCaloPreShToF[0]->Fill(itHit->time());
1613       if (hCaloPreShToF[1])
1614         hCaloPreShToF[1]->Fill(itHit->time());
1615       if (hCaloPreShPhi)
1616         hCaloPreShPhi->Fill(globalposition.phi());
1617       if (hCaloPreShEta)
1618         hCaloPreShEta->Fill(globalposition.eta());
1619 
1620     } else {
1621       edm::LogWarning(MsgLoggerCat) << "PreSh PCaloHit " << i << " is expected to be (det,subdet) = (" << dEcal << ","
1622                                     << sdEcalPS << "); value returned is: (" << detector << "," << subdetector << ")";
1623       continue;
1624     }  // end detector type check
1625   }    // end loop through PreShower Hits
1626 
1627   if (verbosity > 1) {
1628     eventout += "\n          Number of PreSh Hits collected:............ ";
1629     eventout += j;
1630   }
1631 
1632   if (hCaloPreSh[0])
1633     hCaloPreSh[0]->Fill((float)j);
1634   if (hCaloPreSh[1])
1635     hCaloPreSh[1]->Fill((float)j);
1636 
1637   if (verbosity > 0)
1638     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1639 
1640   return;
1641 }
1642 
1643 void GlobalHitsProdHist::fillHCal(edm::Event &iEvent, const edm::EventSetup &iSetup) {
1644   std::string MsgLoggerCat = "GlobalHitsProdHist_fillHCal";
1645 
1646   TString eventout;
1647   if (verbosity > 0)
1648     eventout = "\nGathering info:";
1649 
1650   // access the calorimeter geometry
1651   const auto &theCaloGeometry = iSetup.getHandle(caloGeomToken_);
1652   if (!theCaloGeometry.isValid()) {
1653     edm::LogWarning(MsgLoggerCat) << "Unable to find CaloGeometryRecord in event!";
1654     return;
1655   }
1656   const CaloGeometry &theCalo(*theCaloGeometry);
1657 
1658   // iterator to access containers
1659   edm::PCaloHitContainer::const_iterator itHit;
1660 
1661   ///////////////////////////////
1662   // get  HCal information
1663   ///////////////////////////////
1664   // extract HCal container
1665   edm::Handle<edm::PCaloHitContainer> HCalContainer;
1666   iEvent.getByToken(HCalSrc_Token_, HCalContainer);
1667   if (!HCalContainer.isValid()) {
1668     edm::LogWarning(MsgLoggerCat) << "Unable to find HCalHits in event!";
1669     return;
1670   }
1671 
1672   // cycle through container
1673   int i = 0, j = 0;
1674   for (itHit = HCalContainer->begin(); itHit != HCalContainer->end(); ++itHit) {
1675     ++i;
1676 
1677     // create a DetId from the detUnitId
1678     DetId theDetUnitId(itHit->id());
1679     int detector = theDetUnitId.det();
1680     int subdetector = theDetUnitId.subdetId();
1681 
1682     // check that expected detector is returned
1683     if ((detector == dHcal) && ((subdetector == sdHcalBrl) || (subdetector == sdHcalEC) || (subdetector == sdHcalOut) ||
1684                                 (subdetector == sdHcalFwd))) {
1685       // get the Cell geometry
1686       const HcalGeometry *theDet = dynamic_cast<const HcalGeometry *>(theCalo.getSubdetectorGeometry(theDetUnitId));
1687 
1688       if (!theDet) {
1689         edm::LogWarning(MsgLoggerCat) << "Unable to get HcalGeometry from HCalContainer for Hit " << i;
1690         continue;
1691       }
1692 
1693       ++j;
1694 
1695       // get the global position of the cell
1696       const GlobalPoint &globalposition = theDet->getPosition(theDetUnitId);
1697 
1698       if (hCaloHcalE[0])
1699         hCaloHcalE[0]->Fill(itHit->energy());
1700       if (hCaloHcalE[1])
1701         hCaloHcalE[1]->Fill(itHit->energy());
1702       if (hCaloHcalToF[0])
1703         hCaloHcalToF[0]->Fill(itHit->time());
1704       if (hCaloHcalToF[1])
1705         hCaloHcalToF[1]->Fill(itHit->time());
1706       if (hCaloHcalPhi)
1707         hCaloHcalPhi->Fill(globalposition.phi());
1708       if (hCaloHcalEta)
1709         hCaloHcalEta->Fill(globalposition.eta());
1710 
1711     } else {
1712       edm::LogWarning(MsgLoggerCat) << "HCal PCaloHit " << i << " is expected to be (det,subdet) = (" << dHcal << ","
1713                                     << sdHcalBrl << " || " << sdHcalEC << " || " << sdHcalOut << " || " << sdHcalFwd
1714                                     << "); value returned is: (" << detector << "," << subdetector << ")";
1715       continue;
1716     }  // end detector type check
1717   }    // end loop through HCal Hits
1718 
1719   if (verbosity > 1) {
1720     eventout += "\n          Number of HCal Hits collected:............. ";
1721     eventout += j;
1722   }
1723 
1724   if (hCaloHcal[0])
1725     hCaloHcal[0]->Fill((float)j);
1726   if (hCaloHcal[1])
1727     hCaloHcal[1]->Fill((float)j);
1728 
1729   if (verbosity > 0)
1730     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1731 
1732   return;
1733 }