Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:54

0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "Validation/MuonME0Validation/interface/ME0HitsValidation.h"
0003 #include <TMath.h>
0004 
0005 ME0HitsValidation::ME0HitsValidation(const edm::ParameterSet &cfg) : ME0BaseValidation(cfg) {
0006   InputTagToken_ = consumes<edm::PSimHitContainer>(cfg.getParameter<edm::InputTag>("simInputLabel"));
0007 }
0008 
0009 void ME0HitsValidation::bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &Run, edm::EventSetup const &iSetup) {
0010   LogDebug("MuonME0HitsValidation") << "Info : Loading Geometry information\n";
0011   ibooker.setCurrentFolder("MuonME0HitsV/ME0HitsTask");
0012 
0013   unsigned int nregion = 2;
0014 
0015   edm::LogInfo("MuonME0HitsValidation") << "+++ Info : # of region : " << nregion << std::endl;
0016 
0017   LogDebug("MuonME0HitsValidation") << "+++ Info : finish to get geometry information from ES.\n";
0018 
0019   for (unsigned int region_num = 0; region_num < nregion; region_num++) {
0020     me0_sh_tot_zr[region_num] = BookHistZR(ibooker, "me0_sh", "SimHit", region_num);
0021     for (unsigned int layer_num = 0; layer_num < 6; layer_num++) {
0022       me0_sh_zr[region_num][layer_num] = BookHistZR(ibooker, "me0_sh", "SimHit", region_num, layer_num);
0023       me0_sh_xy[region_num][layer_num] = BookHistXY(ibooker, "me0_sh", "SimHit", region_num, layer_num);
0024       std::string hist_name_for_tof =
0025           std::string("me0_sh_tof_r") + regionLabel[region_num] + "_l" + layerLabel[layer_num];
0026       std::string hist_name_for_tofMu =
0027           std::string("me0_sh_tofMuon_r") + regionLabel[region_num] + "_l" + layerLabel[layer_num];
0028       std::string hist_name_for_eloss =
0029           std::string("me0_sh_energyloss_r") + regionLabel[region_num] + "_l" + layerLabel[layer_num];
0030       std::string hist_name_for_elossMu =
0031           std::string("me0_sh_energylossMuon_r") + regionLabel[region_num] + "_l" + layerLabel[layer_num];
0032       std::string hist_label_for_xy = "SimHit occupancy : region" + regionLabel[region_num] + " layer " +
0033                                       layerLabel[layer_num] + " ; globalX [cm]; globalY[cm]";
0034       std::string hist_label_for_tof = "SimHit TOF : region" + regionLabel[region_num] + " layer " +
0035                                        layerLabel[layer_num] + " " + " ; Time of flight [ns] ; entries";
0036       std::string hist_label_for_tofMu = "SimHit TOF(Muon only) : region" + regionLabel[region_num] + " layer " +
0037                                          layerLabel[layer_num] + " " + " ; Time of flight [ns] ; entries";
0038       std::string hist_label_for_eloss = "SimHit energy loss : region" + regionLabel[region_num] + " layer " +
0039                                          layerLabel[layer_num] + " " + " ; Energy loss [eV] ; entries";
0040       std::string hist_label_for_elossMu = "SimHit energy loss(Muon only) : region" + regionLabel[region_num] +
0041                                            " layer " + layerLabel[layer_num] + " " + " ; Energy loss [eV] ; entries";
0042 
0043       double tof_min, tof_max;
0044       tof_min = 10;
0045       tof_max = 30;
0046       me0_sh_tof[region_num][layer_num] =
0047           ibooker.book1D(hist_name_for_tof.c_str(), hist_label_for_tof.c_str(), 40, tof_min, tof_max);
0048       me0_sh_tofMu[region_num][layer_num] =
0049           ibooker.book1D(hist_name_for_tofMu.c_str(), hist_label_for_tofMu.c_str(), 40, tof_min, tof_max);
0050       me0_sh_eloss[region_num][layer_num] =
0051           ibooker.book1D(hist_name_for_eloss.c_str(), hist_label_for_eloss.c_str(), 60, 0., 6000.);
0052       me0_sh_elossMu[region_num][layer_num] =
0053           ibooker.book1D(hist_name_for_elossMu.c_str(), hist_label_for_elossMu.c_str(), 60, 0., 6000.);
0054     }
0055   }
0056 }
0057 
0058 ME0HitsValidation::~ME0HitsValidation() {}
0059 
0060 void ME0HitsValidation::analyze(const edm::Event &e, const edm::EventSetup &iSetup) {
0061   const ME0Geometry *ME0Geometry_ = &iSetup.getData(geomToken_);
0062 
0063   edm::Handle<edm::PSimHitContainer> ME0Hits;
0064   e.getByToken(InputTagToken_, ME0Hits);
0065   if (!ME0Hits.isValid()) {
0066     edm::LogError("ME0HitsValidation") << "Cannot get ME0Hits by Token simInputTagToken";
0067     return;
0068   }
0069 
0070   Float_t timeOfFlightMuon = 0.;
0071   Float_t energyLossMuon = 0;
0072 
0073   for (auto hits = ME0Hits->begin(); hits != ME0Hits->end(); hits++) {
0074     const ME0DetId id(hits->detUnitId());
0075     Int_t region = id.region();
0076     Int_t layer = id.layer();
0077 
0078     // Int_t even_odd = id.chamber()%2;
0079     if (ME0Geometry_->idToDet(hits->detUnitId()) == nullptr) {
0080       edm::LogInfo("ME0HitsValidation") << "simHit did not matched with GEMGeometry." << std::endl;
0081       continue;
0082     }
0083 
0084     const LocalPoint hitLP(hits->localPosition());
0085 
0086     const GlobalPoint hitGP(ME0Geometry_->idToDet(hits->detUnitId())->surface().toGlobal(hitLP));
0087     Float_t g_r = hitGP.perp();
0088     Float_t g_x = hitGP.x();
0089     Float_t g_y = hitGP.y();
0090     Float_t g_z = hitGP.z();
0091     Float_t energyLoss = hits->energyLoss();
0092     Float_t timeOfFlight = hits->timeOfFlight();
0093 
0094     if (abs(hits->particleType()) == 13) {
0095       timeOfFlightMuon = hits->timeOfFlight();
0096       energyLossMuon = hits->energyLoss();
0097       // fill histos for Muons only
0098       me0_sh_tofMu[(int)(region / 2. + 0.5)][layer - 1]->Fill(timeOfFlightMuon);
0099       me0_sh_elossMu[(int)(region / 2. + 0.5)][layer - 1]->Fill(energyLossMuon * 1.e9);
0100     }
0101 
0102     me0_sh_zr[(int)(region / 2. + 0.5)][layer - 1]->Fill(g_z, g_r);
0103     me0_sh_tot_zr[(int)(region / 2. + 0.5)]->Fill(g_z, g_r);
0104     me0_sh_xy[(int)(region / 2. + 0.5)][layer - 1]->Fill(g_x, g_y);
0105     me0_sh_tof[(int)(region / 2. + 0.5)][layer - 1]->Fill(timeOfFlight);
0106     me0_sh_eloss[(int)(region / 2. + 0.5)][layer - 1]->Fill(energyLoss * 1.e9);
0107   }
0108 }