Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-27 18:27:36

0001 #include "Validation/MuonGEMDigis/plugins/GEMCoPadDigiValidation.h"
0002 
0003 GEMCoPadDigiValidation::GEMCoPadDigiValidation(const edm::ParameterSet& pset)
0004     : GEMBaseValidation(pset, "GEMCoPadDigiValidation") {
0005   const auto& copad_pset = pset.getParameterSet("gemCoPadDigi");
0006 
0007   const auto& copad_tag = copad_pset.getParameter<edm::InputTag>("inputTag");
0008   copad_token_ = consumes<GEMCoPadDigiCollection>(copad_tag);
0009   geomToken_ = esConsumes<GEMGeometry, MuonGeometryRecord>();
0010   geomTokenBeginRun_ = esConsumes<GEMGeometry, MuonGeometryRecord, edm::Transition::BeginRun>();
0011 
0012   gem_bx_min_ = copad_pset.getParameter<int>("minBX");
0013   gem_bx_max_ = copad_pset.getParameter<int>("maxBX");
0014 }
0015 
0016 void GEMCoPadDigiValidation::bookHistograms(DQMStore::IBooker& booker,
0017                                             edm::Run const& run,
0018                                             edm::EventSetup const& setup) {
0019   const auto& gemH = setup.getHandle(geomTokenBeginRun_);
0020   if (!gemH.isValid()) {
0021     edm::LogError(kLogCategory_) << "Failed to initialize GEM geometry.";
0022     return;
0023   }
0024   const GEMGeometry* gem = gemH.product();
0025 
0026   // NOTE Occupancy
0027   booker.setCurrentFolder("GEM/CoPad");
0028 
0029   for (const auto& region : gem->regions()) {
0030     Int_t region_id = region->region();
0031 
0032     if (detail_plot_)
0033       me_detail_occ_zr_[region_id] = bookZROccupancy(booker, region_id, "copad", "CoPad");
0034 
0035     for (const auto& station : region->stations()) {
0036       Int_t station_id = station->station();
0037       const auto& superChamberVec = station->superChambers();
0038       if (superChamberVec.empty() || superChamberVec[0] == nullptr) {
0039         edm::LogError(kLogCategory_) << "Super chambers missing or null for region = " << region_id
0040                                      << " and station = " << station_id;
0041         continue;
0042       }
0043       const auto& chamberVec = superChamberVec[0]->chambers();
0044       if (chamberVec.empty() || chamberVec[0] == nullptr) {
0045         edm::LogError(kLogCategory_) << "Chambers missing or null for region, station, super chamber = (" << region_id
0046                                      << ", " << station_id << ", " << superChamberVec[0]->id() << ")";
0047         continue;
0048       }
0049       const auto& etaPartitionVec = chamberVec[0]->etaPartitions();
0050       if (etaPartitionVec.empty() || etaPartitionVec[0] == nullptr) {
0051         edm::LogError(kLogCategory_) << "Eta partition missing or null for region, station, super chamber, chamber = ("
0052                                      << region_id << ", " << station_id << ", " << superChamberVec[0]->id() << ", "
0053                                      << chamberVec[0]->id() << ")";
0054         continue;
0055       }
0056       Int_t num_pads = etaPartitionVec[0]->npads();
0057       ME2IdsKey key2{region_id, station_id};
0058 
0059       if (detail_plot_) {
0060         me_detail_occ_xy_[key2] = bookXYOccupancy(booker, key2, "copad", "CoPad");
0061 
0062         me_detail_occ_phi_pad_[key2] = bookHist2D(booker,
0063                                                   key2,
0064                                                   "copad_occ_phi_pad",
0065                                                   "CoPad Occupancy",
0066                                                   280,
0067                                                   -M_PI,
0068                                                   M_PI,
0069                                                   num_pads / 2,
0070                                                   0,
0071                                                   num_pads,
0072                                                   "#phi [rad]",
0073                                                   "Pad number");
0074 
0075         me_detail_occ_pad_[key2] = bookHist1D(
0076             booker, key2, "copad_occ_pad", "CoPad Ocupancy per pad number", num_pads, 0.5, num_pads + 0.5, "Pad number");
0077 
0078         me_detail_occ_det_[key2] = bookDetectorOccupancy(booker, key2, station, "copad", "CoPad");
0079       }
0080     }  // station loop
0081   }    // region loop
0082 
0083   // NOTE Bunch Crossing
0084   if (detail_plot_) {
0085     for (const auto& region : gem->regions()) {
0086       Int_t region_id = region->region();
0087       for (const auto& station : region->stations()) {
0088         Int_t station_id = station->station();
0089         ME2IdsKey key2{region_id, station_id};
0090 
0091         me_detail_bx_[key2] =
0092             bookHist1D(booker, key2, "copad_bx", "CoPad Bunch Crossing", 5, -2.5, 2.5, "Bunch crossing");
0093       }  // station loop
0094     }    // region loop
0095   }      // detail plot
0096 }
0097 
0098 GEMCoPadDigiValidation::~GEMCoPadDigiValidation() {}
0099 
0100 void GEMCoPadDigiValidation::analyze(const edm::Event& event, const edm::EventSetup& setup) {
0101   const auto& gemH = setup.getHandle(geomToken_);
0102   if (!gemH.isValid()) {
0103     edm::LogError(kLogCategory_) << "Failed to initialize GEM geometry.";
0104     return;
0105   }
0106   const GEMGeometry* gem = gemH.product();
0107 
0108   edm::Handle<GEMCoPadDigiCollection> copad_collection;
0109   event.getByToken(copad_token_, copad_collection);
0110   if (not copad_collection.isValid()) {
0111     edm::LogError(kLogCategory_) << "Cannot get pads by token." << std::endl;
0112     return;
0113   }
0114 
0115   // GEMCoPadDigiCollection::DigiRangeIterator
0116   for (const auto& copad_pair : *copad_collection) {
0117     GEMDetId gemid = copad_pair.first;
0118     const auto& range = copad_pair.second;
0119 
0120     Int_t region_id = gemid.region();
0121     Int_t station_id = gemid.station();
0122     Int_t ring_id = gemid.ring();
0123     Int_t layer_id = gemid.layer();
0124     Int_t chamber_id = gemid.chamber();
0125     Int_t num_layers = gemid.nlayers();
0126 
0127     ME2IdsKey key2{region_id, station_id};
0128 
0129     for (auto digi = range.first; digi != range.second; ++digi) {
0130       // GEM copads are stored per super chamber!
0131       // layer_id = 0, roll_id = 0
0132       GEMDetId super_chamber_id{region_id, ring_id, station_id, 0, chamber_id, 0};
0133       Int_t roll_id = (*digi).roll();
0134 
0135       const GeomDet* geom_det = gem->idToDet(super_chamber_id);
0136       if (geom_det == nullptr) {
0137         edm::LogError(kLogCategory_) << super_chamber_id << " : This detId cannot be "
0138                                      << "loaded from GEMGeometry // Original" << gemid << " station : " << station_id
0139                                      << std::endl
0140                                      << "Getting DetId failed. Discard this gem copad hit." << std::endl;
0141         continue;
0142       }
0143 
0144       const BoundPlane& surface = geom_det->surface();
0145       const GEMSuperChamber* super_chamber = gem->superChamber(super_chamber_id);
0146       if (super_chamber == nullptr) {
0147         edm::LogError(kLogCategory_) << "Super chamber is null for super chamber ID = " << super_chamber_id;
0148         continue;
0149       }
0150       Int_t pad1 = digi->pad(1);
0151       Int_t pad2 = digi->pad(2);
0152       Int_t bx1 = digi->bx(1);
0153       Int_t bx2 = digi->bx(2);
0154 
0155       // Filtered using BX
0156       if (bx1 < gem_bx_min_ or bx1 > gem_bx_max_)
0157         continue;
0158       if (bx2 < gem_bx_min_ or bx2 > gem_bx_max_)
0159         continue;
0160 
0161       const Int_t padArray[] = {pad1, pad2};
0162       LocalPoint lpArray[2];
0163       int ptCounter = 0;
0164       for (; ptCounter < 2; ++ptCounter) {
0165         const GEMChamber* const chamber = super_chamber->chamber(ptCounter + 1);  // Fetch chambers 1 and 2
0166         if (chamber == nullptr) {
0167           edm::LogError(kLogCategory_) << "Chamber " << (ptCounter + 1)
0168                                        << " is null for super chamber = " << super_chamber_id;
0169           break;
0170         }
0171         const GEMEtaPartition* const etaPartition = chamber->etaPartition(roll_id);
0172         if (etaPartition == nullptr) {
0173           edm::LogError(kLogCategory_) << "Eta partition " << roll_id << " is null for chamber, super chamber = ("
0174                                        << (ptCounter + 1) << ", " << super_chamber_id << ")";
0175           break;
0176         }
0177         lpArray[ptCounter] = etaPartition->centreOfPad(padArray[ptCounter]);
0178       }                     // end for
0179       if (ptCounter < 2) {  // Broke out of "for" loop
0180         edm::LogError(kLogCategory_) << "Skipping a digi due to bad chamber " << (ptCounter + 1);
0181         continue;
0182       }
0183       const GlobalPoint& gp1 = surface.toGlobal(lpArray[0]);
0184       const GlobalPoint& gp2 = surface.toGlobal(lpArray[1]);
0185 
0186       Float_t g_r1 = gp1.perp();
0187       Float_t g_r2 = gp2.perp();
0188 
0189       Float_t g_z1 = gp1.z();
0190       Float_t g_z2 = gp2.z();
0191 
0192       Float_t g_phi = gp1.phi();
0193       Float_t g_x = gp1.x();
0194       Float_t g_y = gp1.y();
0195 
0196       // Fill normal plots.
0197 
0198       Int_t bin_x = getDetOccBinX(num_layers, chamber_id, layer_id);
0199 
0200       // Fill detail plots.
0201       if (detail_plot_) {
0202         me_detail_occ_zr_[region_id]->Fill(std::fabs(g_z1), g_r1);
0203         me_detail_occ_zr_[region_id]->Fill(std::fabs(g_z2), g_r2);
0204         me_detail_occ_xy_[key2]->Fill(g_x, g_y);
0205         me_detail_occ_det_[key2]->Fill(bin_x, roll_id);
0206         me_detail_occ_det_[key2]->Fill(bin_x + 1, roll_id);
0207         me_detail_occ_phi_pad_[key2]->Fill(g_phi, pad1);
0208         me_detail_occ_pad_[key2]->Fill(pad1);
0209         me_detail_bx_[key2]->Fill(bx1);
0210         me_detail_bx_[key2]->Fill(bx2);
0211       }  // detail_plot_
0212     }    // loop over digis
0213   }      // loop over range iters
0214 }