CMS 3D CMS Logo

ClusterSummaryProducer.cc
Go to the documentation of this file.
2 
4  : doStrips(iConfig.getParameter<bool>("doStrips")),
5  doPixels(iConfig.getParameter<bool>("doPixels")),
6  verbose(iConfig.getParameter<bool>("verbose")) {
8  consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<edm::InputTag>("pixelClusters"));
10  consumes<edmNew::DetSetVector<SiStripCluster> >(iConfig.getParameter<edm::InputTag>("stripClusters"));
11 
13 
14  std::vector<std::string> wantedsubdets = iConfig.getParameter<std::vector<std::string> >("wantedSubDets");
15  for (const auto& iS : wantedsubdets) {
17  for (int iN = 0; iN < ClusterSummary::NVALIDENUMS; ++iN)
18  if (ClusterSummary::subDetNames[iN] == iS)
19  subdet = ClusterSummary::CMSTracker(iN);
20  if (subdet == ClusterSummary::NVALIDENUMS)
21  throw cms::Exception("No standard selection: ") << iS;
22 
24  if (subdet > maxEnum)
25  maxEnum = subdet;
26  if (verbose)
27  moduleNames.push_back(ClusterSummary::subDetNames[subdet]);
28  }
29 
30  std::vector<edm::ParameterSet> wantedusersubdets_ps =
31  iConfig.getParameter<std::vector<edm::ParameterSet> >("wantedUserSubDets");
32  for (const auto& iS : wantedusersubdets_ps) {
33  ClusterSummary::CMSTracker subdet = (ClusterSummary::CMSTracker)iS.getParameter<unsigned int>("detSelection");
34  std::string detname = iS.getParameter<std::string>("detLabel");
35  std::vector<std::string> selection = iS.getParameter<std::vector<std::string> >("selection");
36 
37  if (subdet <= ClusterSummary::NVALIDENUMS)
38  throw cms::Exception("Already predefined selection: ") << subdet;
39  if (subdet >= ClusterSummary::NTRACKERENUMS)
40  throw cms::Exception("Selection is out of range: ") << subdet;
41 
42  selectors.push_back(ModuleSelection(DetIdSelector(selection), subdet));
43  if (subdet > maxEnum)
44  maxEnum = subdet;
45  if (verbose)
46  moduleNames.push_back(detname);
47  }
48 
49  cCluster = ClusterSummary(maxEnum + 1);
50  produces<ClusterSummary>().setBranchAlias("trackerClusterSummary");
51 }
52 
54  using namespace edm;
55  cCluster.reset();
56  std::vector<bool> selectedVector(selectors.size(), false);
57 
58  auto getSelections = [&](const uint32_t detid) {
59  for (unsigned int iS = 0; iS < selectors.size(); ++iS)
60  selectedVector[iS] = selectors[iS].first.isSelected(detid);
61  };
62  auto fillSelections = [&](const int clusterSize, const float clusterCharge) {
63  for (unsigned int iS = 0; iS < selectors.size(); ++iS) {
64  if (!selectedVector[iS])
65  continue;
66  const ClusterSummary::CMSTracker module = selectors[iS].second;
69  cCluster.addClusChargeByIndex(module, clusterCharge);
70  }
71  };
72 
73  //===================++++++++++++========================
74  // For SiStrips
75  //===================++++++++++++========================
76  if (doStrips) {
78  iEvent.getByToken(stripClusters_, stripClusters);
80  for (; itClusters != stripClusters->end(); ++itClusters) {
81  getSelections(itClusters->id());
82  for (edmNew::DetSet<SiStripCluster>::const_iterator cluster = itClusters->begin(); cluster != itClusters->end();
83  ++cluster) {
84  const ClusterVariables Summaryinfo(*cluster);
85  fillSelections(Summaryinfo.clusterSize(), Summaryinfo.charge());
86  }
87  }
88  }
89 
90  //===================++++++++++++========================
91  // For SiPixels
92  //===================++++++++++++========================
93  if (doPixels) {
95  iEvent.getByToken(pixelClusters_, pixelClusters);
97  for (; itClusters != pixelClusters->end(); ++itClusters) {
98  getSelections(itClusters->id());
99  for (edmNew::DetSet<SiPixelCluster>::const_iterator cluster = itClusters->begin(); cluster != itClusters->end();
100  ++cluster) {
101  fillSelections(cluster->size(), float(cluster->charge()) / 1000.);
102  }
103  }
104  }
105 
106  //===================+++++++++++++========================
107  // Fill Producer
108  //===================+++++++++++++========================
109  if (verbose) {
110  for (const auto& iS : selectors) {
111  const ClusterSummary::CMSTracker module = iS.second;
112  if (cCluster.getNClusByIndex(module) != 0) {
113  edm::LogInfo("ClusterSummaryProducer")
114  << "n" << moduleNames[module] << ", avg size, avg charge = " << cCluster.getNClusByIndex(module) << ", "
117  } else {
118  edm::LogInfo("ClusterSummaryProducer")
119  << "n" << moduleNames[module] << ", avg size, avg charge = " << cCluster.getNClusByIndex(module) << ", "
120  << "0"
121  << ", "
122  << "0" << std::endl;
123  }
124  edm::LogInfo("ClusterSummaryProducer") << "-------------------------------------------------------" << std::endl;
125  }
126  }
127 
128  //Put the filled class into the producer
129  auto result = std::make_unique<ClusterSummary>();
130  //Cleanup empty selections
131  result->copyNonEmpty(cCluster);
132  iEvent.put(std::move(result));
133 }
134 
136  if (!verbose)
137  return;
138  edm::LogInfo("ClusterSummaryProducer") << "+++++++++++++++++++++++++++++++ " << std::endl << "Getting info on ";
139  for (const auto& iS : moduleNames) {
140  edm::LogInfo("ClusterSummaryProducer") << iS << " ";
141  }
142  edm::LogInfo("ClusterSummaryProducer") << std::endl;
143 }
144 
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
float getClusChargeByIndex(const int mod) const
std::vector< std::string > moduleNames
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > stripClusters_
void addClusChargeByIndex(const int mod, const float val)
bool verbose
void addClusSizeByIndex(const int mod, const int val)
static const std::vector< std::string > subDetNames
void produce(edm::Event &, const edm::EventSetup &) override
selection
main part
Definition: corrVsCorr.py:100
data_type const * const_iterator
Definition: DetSetNew.h:31
ClusterSummaryProducer(const edm::ParameterSet &)
const_iterator end(bool update=false) const
int iEvent
Definition: GenABIO.cc:224
int getNClusByIndex(const int mod) const
uint16_t charge() const
id_type id(size_t cell) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Info, false > LogInfo
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator begin(bool update=false) const
void beginStream(edm::StreamID) override
static const std::vector< std::vector< std::string > > subDetSelections
HLT enums.
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClusters_
int getClusSizeByIndex(const int mod) const
void addNClusByIndex(const int mod, const int val)
def move(src, dest)
Definition: eostools.py:511
const unsigned clusterSize() const
std::pair< DetIdSelector, ClusterSummary::CMSTracker > ModuleSelection