test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ClusterAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ClusterAnalyzer
4 // Class: ClusterAnalyzer
5 //
13 //
14 // Original Author: Michael Segala
15 // Created: Wed Feb 23 17:36:23 CST 2011
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
27 
30 
32 #include "TTree.h"
35 #include <TH1.h>
36 #include <TFile.h>
38 
39 
40 //
41 // class declaration
42 //
43 
44 class ClusterSummary;
45 
46 
47 using namespace std;
48 
50  public:
51  explicit ClusterAnalyzer(const edm::ParameterSet&);
52  ~ClusterAnalyzer();
53 
54 
55  private:
56  virtual void beginJob() override ;
57  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
58 
59 
60  // ----------member data ---------------------------
61 
63 
64  std::map<int, std::string> enumModules_;
65  std::map< std::string, TH1D* > histos1D_;
66 
67  std::vector<int> modules_;
68 
69  std::vector<int> nType_;
70  std::vector<double> clusterSize_;
71  std::vector<double> clusterCharge_;
72 
73  std::vector<std::string> v_moduleTypes;
74  std::vector<std::string> v_variables;
75 
76  std::vector< std::vector<double> > genericVariables_;
77 
78  bool _firstPass;
80  std::vector<string> maps;
81 
82  bool _verbose;
83 
88 
89  bool doStrips;
90  bool doPixels;
91 };
92 
93 
95 {
96 
97  token = consumes<ClusterSummary>(iConfig.getParameter<edm::InputTag>("clusterSum"));
98 
99  _firstPass = true;
100  _verbose = true; //set to true to see the event by event summary info
101 
102 }
103 
104 
106 
107 void
109 {
110  using namespace edm;
111 
112 
114  iEvent.getByToken( token, class_);
115 
116  if (_firstPass){
117 
118  modules_ . clear();
119  modules_ = class_ -> GetUserModules();
120 
121  // Provenance Information
122  const Provenance& prov = iEvent.getProvenance(class_.id());
123  const edm::ParameterSet& pSet = parameterSet(prov);
124 
125  ProvInfo = "";
126  ProvInfo_vars = "";
127  ProvInfoPixels = "";
128  ProvInfoPixels_vars = "";
129 
130  std::string ProvString = "";
131  std::string VarString = "";
132 
133  doStrips = pSet.getParameter<bool>("doStrips");
134  doPixels = pSet.getParameter<bool>("doPixels");
135 
136  if (doStrips){
137  ProvInfo = pSet.getParameter<string>("stripModule");
138  cout << "From provenance infomation the selected strip modules are = "<< ProvInfo << endl;
139  ProvInfo_vars = pSet.getParameter<string>("stripVariables");
140  cout << "From provenance infomation the avaliable strip variables are = "<< ProvInfo_vars << endl;
141 
142  }
143  if (doPixels){
144  ProvInfoPixels = pSet.getParameter<string>("pixelModule");
145  cout << "From provenance infomation the selected pixel modules are = "<< ProvInfoPixels << endl;
146  ProvInfoPixels_vars = pSet.getParameter<string>("pixelVariables");
147  cout << "From provenance infomation the avaliable pixel variables are = "<< ProvInfoPixels_vars << endl;
148  }
149 
150 
151  if (doStrips && doPixels) {
152  ProvString = ProvInfo + "," + ProvInfoPixels;
153  VarString = ProvInfo_vars + "," + ProvInfoPixels_vars;
154  }
155  else if (doStrips && !doPixels) {
156  ProvString = ProvInfo;
157  VarString = ProvInfo_vars;
158  }
159  else if (!doStrips && doPixels) {
160  ProvString = ProvInfoPixels;
161  VarString = ProvInfoPixels_vars;
162  }
163 
164  // Define the Modules to get the summary info out of
165  v_moduleTypes = class_ -> DecodeProvInfo( ProvString );
166  v_variables = class_ -> DecodeProvInfo( VarString );
167 
168  }
169 
170  class_ -> SetUserContent( v_variables );
171 
172  genericVariables_ = class_ -> GetGenericVariable();
173 
174  //cout << class_ -> GetGenericVariable("cHits", ClusterSummary::TIB) << endl;
175 
176  if ( _firstPass ){ //only do on the first event
177 
178  // Loop over all the modules to create a Map of Histograms to fill
179  int n = 0;
180  for ( vector<int>::const_iterator mod = modules_ . begin(); mod != modules_ . end(); mod++ ){
181 
182  //cout << "Creating histograms for " << *mod << endl;
183  cout << "Creating histograms for " << v_moduleTypes.at(n) << endl;
184 
185  std::string tmpstr = v_moduleTypes.at(n);
186 
187  histos1D_[ (tmpstr + "nclusters").c_str() ] = fs->make< TH1D >( (tmpstr + "nclusters").c_str() , (tmpstr + "nclusters").c_str() , 1000 , 0 , 3000 );
188  histos1D_[ (tmpstr + "nclusters").c_str() ]->SetXTitle( ("number of Clusters in " + tmpstr).c_str() );
189 
190  histos1D_[ (tmpstr + "avgCharge").c_str() ] = fs->make< TH1D >( (tmpstr + "avgCharge").c_str() , (tmpstr + "avgCharge").c_str() , 500 , 0 , 1000 );
191  histos1D_[ (tmpstr + "avgCharge").c_str() ]->SetXTitle( ("average cluster charge in " + tmpstr).c_str() );
192 
193  histos1D_[ (tmpstr + "avgSize").c_str() ] = fs->make< TH1D >( (tmpstr + "avgSize").c_str() , (tmpstr + "avgSize").c_str() , 30 , 0 , 10 );
194  histos1D_[ (tmpstr + "avgSize").c_str() ]->SetXTitle( ("average cluster size in " + tmpstr).c_str() );
195 
196  maps.push_back( (tmpstr + "nclusters").c_str() );
197  maps.push_back( (tmpstr + "avgSize").c_str() );
198  maps.push_back( (tmpstr + "avgCharge").c_str() );
199 
200  ++n;
201 
202  }
203 
204  _firstPass = false;
205 
206  }
207 
208  int n = 0;
209  for ( vector<int>::const_iterator mod = modules_ . begin(); mod != modules_ . end(); mod++ ){
210 
211  std::string tmpstr = v_moduleTypes.at(n);
212 
213  //Trick to see if it comes from a strip or pixel variable. If the first digit is < 6 then it is from the strips.
214  int mod_tmp = *mod;
215  while (mod_tmp > 9 ){
216  mod_tmp /= 10;
217  }
218 
219  if ( mod_tmp < 5 ){
220 
221  histos1D_[ (tmpstr + "nclusters").c_str() ] -> Fill( class_ -> GetGenericVariable("cHits", *mod) );
222  histos1D_[ (tmpstr + "avgSize").c_str() ] -> Fill( class_ -> GetGenericVariable("cSize", *mod) /class_ -> GetGenericVariable("cHits", *mod) );
223  histos1D_[ (tmpstr + "avgCharge").c_str() ] -> Fill( class_ -> GetGenericVariable("cCharge", *mod)/class_ -> GetGenericVariable("cHits", *mod) );
224 
225  cout << "n"<<tmpstr <<", avg size, avg charge = "<< class_ -> GetGenericVariable( "cHits",*mod );
226  cout << ", "<< class_ -> GetGenericVariable( "cSize",*mod ) /class_ -> GetGenericVariable( "cHits",*mod );
227  cout << ", "<< class_ -> GetGenericVariable( "cCharge",*mod )/class_ -> GetGenericVariable( "cHits",*mod ) << endl;
228 
229  }
230  else{
231  histos1D_[ (tmpstr + "nclusters").c_str() ] -> Fill( class_ -> GetGenericVariable("pHits", *mod) );
232  histos1D_[ (tmpstr + "avgSize").c_str() ] -> Fill( class_ -> GetGenericVariable("pSize", *mod)/class_ -> GetGenericVariable("pHits", *mod) );
233  histos1D_[ (tmpstr + "avgCharge").c_str() ] -> Fill( class_ -> GetGenericVariable("pCharge", *mod)/class_ -> GetGenericVariable("pHits", *mod) );
234 
235  cout << "n"<<tmpstr <<", avg size, avg charge = "<< class_ -> GetGenericVariable( "pHits",*mod );
236  cout << ", "<< class_ -> GetGenericVariable( "pSize",*mod ) /class_ -> GetGenericVariable( "pHits",*mod );
237  cout << ", "<< class_ -> GetGenericVariable( "pCharge",*mod )/class_ -> GetGenericVariable( "pHits",*mod ) << endl;
238 
239  }
240 
241  ++n;
242 
243  }
244 
245  cout << "-------------------------------------------------------" << endl;
246 
247 
248 }
249 
250 
251 // ------------ method called once each job just before starting event loop ------------
252 void
254 
255 //define this as a plug-in
T getParameter(std::string const &) const
std::string ProvInfoPixels_vars
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::string ProvInfo_vars
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< string > maps
std::map< int, std::string > enumModules_
virtual void beginJob() override
void beginJob()
Definition: Breakpoints.cc:15
int iEvent
Definition: GenABIO.cc:230
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
std::string ProvInfo
std::vector< int > modules_
#define end
Definition: vmac.h:37
std::vector< double > clusterCharge_
edm::Service< TFileService > fs
std::vector< std::string > v_moduleTypes
std::vector< std::string > v_variables
ClusterAnalyzer(const edm::ParameterSet &)
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
#define begin
Definition: vmac.h:30
std::vector< std::vector< double > > genericVariables_
std::map< std::string, TH1D * > histos1D_
std::vector< int > nType_
tuple cout
Definition: gather_cfg.py:121
std::string ProvInfoPixels
std::vector< double > clusterSize_
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:76
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
edm::EDGetTokenT< ClusterSummary > token