CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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"))
7 {
8 
9  pixelClusters_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<edm::InputTag>("pixelClusters"));
10  stripClusters_ = 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){
16 
18  for(int iN = 0; iN < ClusterSummary::NVALIDENUMS; ++iN)
19  if(ClusterSummary::subDetNames[iN] == iS)
20  subdet = ClusterSummary::CMSTracker(iN);
21  if(subdet == ClusterSummary::NVALIDENUMS) throw cms::Exception( "No standard selection: ") << iS;
22 
24  if(subdet > maxEnum) maxEnum = subdet;
25  if(verbose)moduleNames.push_back(ClusterSummary::subDetNames[subdet]);
26  }
27 
28 
29  std::vector<edm::ParameterSet> wantedusersubdets_ps = iConfig.getParameter<std::vector<edm::ParameterSet> >("wantedUserSubDets");
30  for(const auto& iS : wantedusersubdets_ps){
31  ClusterSummary::CMSTracker subdet = (ClusterSummary::CMSTracker)iS.getParameter<unsigned int>("detSelection");
32  std::string detname = iS.getParameter<std::string>("detLabel");
33  std::vector<std::string> selection = iS.getParameter<std::vector<std::string> >("selection");
34 
35  if(subdet <= ClusterSummary::NVALIDENUMS) throw cms::Exception( "Already predefined selection: ") << subdet;
36  if(subdet >= ClusterSummary::NTRACKERENUMS) throw cms::Exception( "Selection is out of range: ") << subdet;
37 
38  selectors.push_back(ModuleSelection(DetIdSelector(selection),subdet));
39  if(subdet > maxEnum) maxEnum = subdet;
40  if(verbose)moduleNames.push_back(detname);
41  }
42 
43  cCluster = ClusterSummary(maxEnum + 1);
44  produces<ClusterSummary>().setBranchAlias("trackerClusterSummary");
45 }
46 
47 void
49 {
50  using namespace edm;
51  cCluster.reset();
52  std::vector<bool> selectedVector(selectors.size(),false);
53 
54  auto getSelections = [&] (const uint32_t detid ){
55  for(unsigned int iS = 0; iS < selectors.size(); ++iS)
56  selectedVector[iS] = selectors[iS].first.isSelected(detid);
57  };
58  auto fillSelections = [&] (const int clusterSize, const float clusterCharge ){
59  for(unsigned int iS = 0; iS < selectors.size(); ++iS){
60  if(!selectedVector[iS]) continue;
61  const ClusterSummary::CMSTracker module = selectors[iS].second;
62  cCluster.addNClusByIndex (module, 1 );
63  cCluster.addClusSizeByIndex (module, clusterSize );
64  cCluster.addClusChargeByIndex(module, clusterCharge );
65  }
66  };
67 
68  //===================++++++++++++========================
69  // For SiStrips
70  //===================++++++++++++========================
71  if (doStrips){
73  iEvent.getByToken(stripClusters_, stripClusters);
74  edmNew::DetSetVector<SiStripCluster>::const_iterator itClusters=stripClusters->begin();
75  for(;itClusters!=stripClusters->end();++itClusters){
76  getSelections(itClusters->id());
77  for(edmNew::DetSet<SiStripCluster>::const_iterator cluster=itClusters->begin(); cluster!=itClusters->end();++cluster){
78  const ClusterVariables Summaryinfo(*cluster);
79  fillSelections(Summaryinfo.clusterSize(),Summaryinfo.charge());
80  }
81  }
82  }
83 
84  //===================++++++++++++========================
85  // For SiPixels
86  //===================++++++++++++========================
87  if (doPixels){
89  iEvent.getByToken(pixelClusters_, pixelClusters);
90  edmNew::DetSetVector<SiPixelCluster>::const_iterator itClusters=pixelClusters->begin();
91  for(;itClusters!=pixelClusters->end();++itClusters){
92  getSelections(itClusters->id());
93  for(edmNew::DetSet<SiPixelCluster>::const_iterator cluster=itClusters->begin(); cluster!=itClusters->end();++cluster){
94  fillSelections(cluster->size(),float(cluster->charge())/1000.);
95  }
96  }
97  }
98 
99  //===================+++++++++++++========================
100  // Fill Producer
101  //===================+++++++++++++========================
102  if(verbose){
103  for(const auto& iS : selectors){
104  const ClusterSummary::CMSTracker module = iS.second;
105  edm::LogInfo("ClusterSummaryProducer") << "n" << moduleNames[module] <<", avg size, avg charge = "
106  << cCluster.getNClusByIndex (module ) << ", "
107  << cCluster.getClusSizeByIndex (module )/cCluster.getNClusByIndex(module ) << ", "
109  << std::endl;
110  }
111  std::cout << "-------------------------------------------------------" << std::endl;
112  }
113 
114  //Put the filled class into the producer
115  std::auto_ptr<ClusterSummary> result(new ClusterSummary (0) );
116  //Cleanup empty selections
117  result->copyNonEmpty(cCluster);
118  iEvent.put( result );
119 }
120 
121 
122 void
124 {
125  if(!verbose) return;
126  edm::LogInfo("ClusterSummaryProducer") << "+++++++++++++++++++++++++++++++ " << std::endl << "Getting info on " ;
127  for (const auto& iS : moduleNames ) { edm::LogInfo("ClusterSummaryProducer") << iS<< " " ;}
128  edm::LogInfo("ClusterSummaryProducer") << std::endl;
129 }
130 
131 
135 
136 
T getParameter(std::string const &) const
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) const
std::vector< std::string > moduleNames
edm::EDGetTokenT< edmNew::DetSetVector< SiStripCluster > > stripClusters_
void addClusChargeByIndex(const int mod, const float val)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
void addClusSizeByIndex(const int mod, const int val)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static const std::vector< std::string > subDetNames
virtual void produce(edm::Event &, const edm::EventSetup &) override
selection
main part
Definition: corrVsCorr.py:98
data_type const * const_iterator
Definition: DetSetNew.h:30
id_type id(size_t cell) const
ClusterSummaryProducer(const edm::ParameterSet &)
int getClusSizeByIndex(const int mod) const
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
int getNClusByIndex(const int mod) const
uint16_t charge() const
tuple result
Definition: query.py:137
virtual void beginStream(edm::StreamID) override
std::pair< DetIdSelector, ClusterSummary::CMSTracker > ModuleSelection
float getClusChargeByIndex(const int mod) const
static const std::vector< std::vector< std::string > > subDetSelections
tuple cout
Definition: gather_cfg.py:121
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClusters_
const unsigned clusterSize() const
Definition: vlib.h:208
void addNClusByIndex(const int mod, const int val)
const_iterator begin(bool update=false) const