Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:55

0001 #ifndef __SimTracker_SiPhase2Digitizer_PixelTestBeamValidation_h
0002 #define __SimTracker_SiPhase2Digitizer_PixelTestBeamValidation_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    SimTracker/SiPhase2Digitizer
0007 // Class:      PixelTestBeamValidation
0008 //
0009 /**\class PixelTestBeamValidation PixelTestBeamValidation.cc
0010  
0011   Description: Access Digi collection and creates histograms accumulating
0012                data from the module to different pixel cells, 1x1 cell, 
0013                2x2 cell, etc..
0014 
0015 */
0016 // Author:  J.Duarte-Campderros (IFCA)
0017 // Created: 2019-10-02
0018 
0019 // DQM
0020 #include "DQMServices/Core/interface/DQMStore.h"
0021 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0022 
0023 // CMSSW framework
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 
0028 // CMSSW Data formats
0029 #include "DataFormats/Common/interface/DetSetVector.h"
0030 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
0031 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0032 #include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h"
0033 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0034 #include "DataFormats/DetId/interface/DetId.h"
0035 
0036 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0037 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0038 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0039 
0040 // system
0041 #include <string>
0042 #include <set>
0043 #include <vector>
0044 #include <map>
0045 #include <functional>
0046 #include <cstdint>
0047 
0048 //class MonitorElement;
0049 class GeomDet;
0050 class PSimHit;
0051 class PixelGeomDetUnit;
0052 
0053 class PixelTestBeamValidation : public DQMEDAnalyzer {
0054 public:
0055   explicit PixelTestBeamValidation(const edm::ParameterSet &);
0056   ~PixelTestBeamValidation() override;
0057 
0058   void dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override;
0059   void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override;
0060   void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override;
0061 
0062 private:
0063   // GeomDet units belonging to the tracker pixel system (Barrel and endcap)
0064   bool isPixelSystem_(const GeomDet *detunit) const;
0065 
0066   // The detector unit associated to a list of histograms
0067   // Barrel_Layer / Endcap_Layer_side: Need 3 numbers
0068   int meUnit_(bool isBarrel, int layer, int side) const;
0069 
0070   // Get the pixel digi found at that channel for a given subdetector unit
0071   const PixelDigi &get_digi_from_channel_(int ch, const edm::DetSetVector<PixelDigi>::const_iterator &itdigis);
0072 
0073   // Get the sim track with trackId for given subdetector unit
0074   const SimTrack *get_simtrack_from_id_(unsigned int tid, const edm::SimTrackContainer *simtracks);
0075 
0076   // Get the set of simhits created by a track
0077   const std::vector<const PSimHit *> get_simhits_from_trackid_(
0078       unsigned int tid, unsigned int detid_raw, const std::vector<const edm::PSimHitContainer *> &psimhits);
0079 
0080   // Helper container to memoize the SimHits created by a track (Id) per event
0081   // This should be cleared at the begining of the event
0082   // Note that the PSimHit needs to store the pointer, as the
0083   // memoizer functions present ar
0084   std::map<unsigned int, std::map<unsigned int, std::vector<const PSimHit *>>> m_tId_det_simhits_;
0085 
0086   // Transform a given measurement points into the i-cell pixel frame
0087   const std::pair<double, double> pixel_cell_transformation_(const std::pair<double, double> &pos,
0088                                                              unsigned int icell,
0089                                                              const std::pair<double, double> &pitch);
0090   const std::pair<double, double> pixel_cell_transformation_(const MeasurementPoint &pos,
0091                                                              unsigned int icell,
0092                                                              const std::pair<double, double> &pitch);
0093 
0094   // Check if the given local position is close enough to the given channel,
0095   // the "tolerance" argument is quantifying 'close enough' in a square
0096   //bool channel_iluminated_by_(const MeasurementPoint & localpos,int channel, double tolerance) const;
0097   bool channel_iluminated_by_(const PSimHit &localpos, int channel, const PixelGeomDetUnit *tkDet);
0098 
0099   // The list of channels illuminated by the PSimHit
0100   std::set<int> get_illuminated_channels_(const PSimHit &ps,
0101                                           const DetId &detid,
0102                                           const edm::DetSetVector<PixelDigiSimLink> *simdigis);
0103 
0104   // The list of pixels illuminated by the PSimHit
0105   std::set<std::pair<int, int>> get_illuminated_pixels_(const PSimHit &ps, const PixelGeomDetUnit *tkDetUnit);
0106 
0107   // General function container to decide if a hit has to be processed or not
0108   // depending the user request (check constructor and _check_input_angles method
0109   // for implementation details, as the real algorithm is created in there)
0110   std::function<bool(const PSimHit *)> use_this_track_;
0111 
0112   // The actual algorithm to check if a track entered a detector
0113   // within a given angles (to be used by use_this_track_ if needed, not
0114   // intended to be directly called)
0115   bool _check_input_angles_(const PSimHit *ps);
0116 
0117   // Helper member ot track the list of pixels illuminated by
0118   // the PSimHit (see definition of illuminate in get_illuminated_pixels_)
0119   std::map<std::uintptr_t, std::set<std::pair<int, int>>> m_illuminated_pixels_;
0120 
0121   // Histograms:
0122   // HElper setup functions
0123   MonitorElement *setupH1D_(DQMStore::IBooker &ibooker, const std::string &histoname, const std::string &title);
0124   MonitorElement *setupH2D_(DQMStore::IBooker &ibooker, const std::string &histoname, const std::string &title);
0125   MonitorElement *setupH2D_(DQMStore::IBooker &ibooker,
0126                             const std::string &histoname,
0127                             const std::string &title,
0128                             const std::pair<double, double> &xranges,
0129                             const std::pair<double, double> &yranges);
0130   MonitorElement *setupProf2D_(DQMStore::IBooker &ibooker,
0131                                const std::string &histoname,
0132                                const std::string &title,
0133                                const std::pair<double, double> &xranges,
0134                                const std::pair<double, double> &yranges);
0135   // Whole CMS histos
0136   MonitorElement *vME_track_XYMap_;
0137   MonitorElement *vME_track_RZMap_;
0138   MonitorElement *vME_digi_XYMap_;
0139   MonitorElement *vME_digi_RZMap_;
0140   // Per detector unit plots
0141   std::map<int, MonitorElement *> vME_clsize1D_;
0142   std::map<int, MonitorElement *> vME_clsize1Dx_;
0143   std::map<int, MonitorElement *> vME_clsize1Dy_;
0144   std::map<int, MonitorElement *> vME_charge1D_;
0145   std::map<int, MonitorElement *> vME_charge_elec1D_;
0146   std::map<int, MonitorElement *> vME_track_dxdz_;
0147   std::map<int, MonitorElement *> vME_track_dydz_;
0148   std::map<int, MonitorElement *> vME_track_dxdzAngle_;
0149   std::map<int, MonitorElement *> vME_track_dydzAngle_;
0150   std::map<int, MonitorElement *> vME_dx1D_;
0151   std::map<int, MonitorElement *> vME_dy1D_;
0152   std::map<int, MonitorElement *> vME_dxy2D_;
0153   std::map<int, MonitorElement *> vME_digi_charge1D_;
0154   std::map<int, MonitorElement *> vME_digi_chargeElec1D_;
0155   std::map<int, MonitorElement *> vME_sim_cluster_charge_;
0156   // --- cell histograms per subdector , each element on the
0157   //     vector 0: total, 1: 1x1, 2: 2x2, (3: 3x3, 4: 4x4)?
0158   std::map<int, std::vector<MonitorElement *>> vME_pshpos_cell_;
0159   std::map<int, std::vector<MonitorElement *>> vME_position_cell_;
0160   std::map<int, std::vector<MonitorElement *>> vME_eff_cell_;
0161   std::map<int, std::vector<MonitorElement *>> vME_clsize_cell_;
0162   std::map<int, std::vector<MonitorElement *>> vME_charge_cell_;
0163   std::map<int, std::vector<MonitorElement *>> vME_charge_elec_cell_;
0164   std::map<int, std::vector<MonitorElement *>> vME_dx_cell_;
0165   std::map<int, std::vector<MonitorElement *>> vME_dy_cell_;
0166 
0167   // Map to take care of common and tedious
0168   //const std::vector<std::map<int,std::vector<MonitorElement *>>*> helperMap_;
0169 
0170   // Configuration
0171   edm::ParameterSet config_;
0172   // Geometry to use
0173   std::string geomType_;
0174 
0175   // The threshold and the conversion between ToT to electrons (Be carefull, this should
0176   // be using the same value used in the digitization module)
0177   double thresholdInElectrons_;
0178   double electronsPerADC_;
0179   double electronsAtToT0_;
0180   // The tracks entry angle to accept (if any)
0181   std::vector<double> tracksEntryAngleX_;
0182   std::vector<double> tracksEntryAngleY_;
0183   // The actual angles already parsed (0- x aix, 1- y axis)
0184   std::map<unsigned int, std::pair<double, double>> active_entry_angles_;
0185 
0186   //std::vector<double> phiValues;
0187   // EDM token for the input collections
0188   std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> simHitTokens_;
0189   const edm::EDGetTokenT<edm::DetSetVector<PixelDigi>> digiToken_;
0190   const edm::EDGetTokenT<edm::DetSetVector<PixelDigiSimLink>> digiSimLinkToken_;
0191   const edm::EDGetTokenT<edm::SimTrackContainer> simTrackToken_;
0192   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0193   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0194   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoBToken_;
0195   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomBToken_;
0196 };
0197 #endif