CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TestMuonCaloCleaner.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TestMuonCaloCleaner
4 // Class: TestMuonCaloCleaner
5 //
6 
7 // system include files
8 #include <memory>
9 
10 // user include files
13 
16 
18 
21 
23 
27 
31 
34 
35 #include "TTree.h"
36 #include "TFile.h"
37 #include "TH2F.h"
38 
39 
40 #include <boost/foreach.hpp>
41 
43 
44 
45 //
46 // class declaration
47 //
48 
50  public:
51  explicit TestMuonCaloCleaner(const edm::ParameterSet&);
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 
57  private:
58  virtual void beginJob() ;
59  virtual void analyze(const edm::Event&, const edm::EventSetup&);
60  virtual void endJob() ;
61 
62  virtual void beginRun(edm::Run const&, edm::EventSetup const&);
63  virtual void endRun(edm::Run const&, edm::EventSetup const&);
64  virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
65  virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
69  int charge_;
70 
71  std::string getKey(const DetId & det);
72  std::vector<std::string> getAllKeys();
73 
74 
75  typedef std::map<int, std::string > TMyMainMap;
76  typedef std::map<int, std::map<int, std::string> > TMySubMap;
77  typedef std::map<std::string, TH2F * > THistoMap;
78 
79 
82 
83 
84  // ----------member data ---------------------------
85 };
86 
87 //
88 // constants, enums and typedefs
89 //
90 
91 //
92 // static data member definitions
93 //
94 
95 //
96 // constructors and destructor
97 //
99  colLen_(iConfig.getParameter<edm::InputTag>("colLen")),
100  colDep_(iConfig.getParameter<edm::InputTag>("colDep")),
101  _inputCol(iConfig.getParameter<edm::InputTag>("selectedMuons")),
102  charge_(iConfig.getParameter<int>("charge"))
103 {
104 
105  detMap_[DetId::Hcal]="Hcal";
106  detMap_[DetId::Ecal]="Ecal";
107 
108  subDetMap_[DetId::Ecal][EcalBarrel]="EcalBarrel";
109  subDetMap_[DetId::Ecal][EcalEndcap]="EcalEndcap";
110  subDetMap_[DetId::Ecal][EcalPreshower ]="EcalPreshower";
111  subDetMap_[DetId::Ecal][EcalTriggerTower]="EcalTriggerTower";
112  subDetMap_[DetId::Ecal][EcalLaserPnDiode]="EcalLaserPnDiode";
113 
114  subDetMap_[DetId::Hcal][HcalEmpty]="HcalEmpty";
115  subDetMap_[DetId::Hcal][HcalBarrel]="HcalBarrel";
116  subDetMap_[DetId::Hcal][HcalEndcap]="HcalEndcap";
117  subDetMap_[DetId::Hcal][HcalOuter]="HcalOuter";
118  subDetMap_[DetId::Hcal][HcalForward]="HcalForward";
119  subDetMap_[DetId::Hcal][HcalTriggerTower]="HcalTriggerTower";
120  subDetMap_[DetId::Hcal][HcalOther]="HcalOther";
121 
122 
123 }
124 
125 
126 void
128 {
129 
130  //std::cout << "------------------------------\n";
132  iEvent.getByLabel(_inputCol, muonsHandle);
133 
134  const reco::Muon * myMu = 0;
135  BOOST_FOREACH(const reco::Muon & mu, *muonsHandle){
136  if (!mu.isGlobalMuon()) continue;
137  if (mu.charge()!= charge_) continue;
138  myMu = &mu;
139  break;
140  }
141 
142  if (myMu==0){
143  // std::cout << " XXX TestMuonCaloCleaner says whoooops" << std::endl;
144  return;
145  }
146 
147  typedef std::map<unsigned int,float> TMyCol;
148  edm::Handle< TMyCol > hLenghts;
149  edm::Handle< TMyCol > hDeposits;
150 
151 
152  iEvent.getByLabel(colLen_,hLenghts);
153  iEvent.getByLabel(colDep_,hDeposits);
154 
155  unsigned int selectedDet = 0;
156 
157  BOOST_FOREACH(const TMyCol::value_type & entry, *hLenghts){
158  DetId det(entry.first);
159  float len = entry.second;
160  float val = 0;
161  std::string name =getKey(det);
162  if (hDeposits->find(entry.first) != hDeposits->end())
163  val = (hDeposits->find(entry.first))->second;
164  else if (name == "H_Ecal_EcalEndcap") {
165  //std::cout << " nm " << name << std::endl;
166  selectedDet = entry.first;
167  }
168 
169  const bool fDebug = false;
170  if(fDebug)
171  std::cout << "XX " << name << " " << det.rawId() << " " << len << " " << val << std::endl;
172  }
173 
174  if (selectedDet != 0) {
175  //std::cout << "TT"<<std::endl;
177  iEvent.getByLabel(edm::InputTag( "ecalRecHit", "EcalRecHitsEE"), hEErh );
178 
179  BOOST_FOREACH(const EcalRecHit & rh, *hEErh){
180 
181  //std::cout << " " << rh.energy() << std::endl;
182  //DetId det(selectedDet);
183 
184  if ( selectedDet == rh.id().rawId() ) {
185  std::cout << selectedDet << " " << rh.energy() << std::endl;
186  }
187  }
188 
189  }
190 }
191 
192 
194  return "H_"+detMap_[det.det()]+"_"+subDetMap_[det.det()][det.subdetId()];
195 }
196 
197 std::vector<std::string> TestMuonCaloCleaner::getAllKeys(){
198  std::vector<std::string> ret;
199  ret.push_back("H__");
200  BOOST_FOREACH(TMyMainMap::value_type & entry, detMap_){
201  BOOST_FOREACH(TMySubMap::mapped_type::value_type & subEntry, subDetMap_[entry.first]){
202  std::string name = "H_"+entry.second+"_"+subEntry.second;
203  //std::cout << "XX " << name << std::endl;
204  ret.push_back(name);
205  }
206 
207  }
208 
209  return ret;
210 }
211 
213 {
214 
215  // do anything here that needs to be done at desctruction time
216  // (e.g. close files, deallocate resources etc.)
217 
218 }
219 
220 
221 //
222 // member functions
223 //
224 
225 // ------------ method called for each event ------------
226 
227 
228 // ------------ method called once each job just before starting event loop ------------
229 void
231 {
232 }
233 
234 // ------------ method called once each job just after ending the event loop ------------
235 void
237 {
238 
239 }
240 
241 // ------------ method called when starting to processes a run ------------
242 void
244 {
245 }
246 
247 // ------------ method called when ending the processing of a run ------------
248 void
250 {
251 }
252 
253 // ------------ method called when starting to processes a luminosity block ------------
254 void
256 {
257 }
258 
259 // ------------ method called when ending the processing of a luminosity block ------------
260 void
262 {
263 }
264 
265 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
266 void
268  //The following says we do not know what parameters are allowed so do no validation
269  // Please change this to state exactly what you do use, even if it is no parameters
271  desc.setUnknown();
272  descriptions.addDefault(desc);
273 }
274 
275 //define this as a plug-in
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< std::string > getAllKeys()
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool isGlobalMuon() const
Definition: Muon.h:218
std::map< int, std::map< int, std::string > > TMySubMap
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
TestMuonCaloCleaner(const edm::ParameterSet &)
std::string getKey(const DetId &det)
float energy() const
Definition: EcalRecHit.h:68
const int mu
Definition: Constants.h:22
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Container::value_type value_type
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: DetId.h:18
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
DetId id() const
get the id
Definition: EcalRecHit.h:76
virtual int charge() const GCC11_FINAL
electric charge
virtual void endRun(edm::Run const &, edm::EventSetup const &)
std::map< std::string, TH2F * > THistoMap
std::map< int, std::string > TMyMainMap
tuple cout
Definition: gather_cfg.py:121
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
Definition: Run.h:41