CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AnaMuonCaloCleaner.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: AnaMuonCaloCleaner
4 // Class: AnaMuonCaloCleaner
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 AnaMuonCaloCleaner(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 
83 
84  typedef std::map<std::string, TTree * > TTreeMap;
85  typedef std::map<std::string, std::map<std::string, float> > TTreeTempStorageMap;
88 
89  // ----------member data ---------------------------
90 };
91 
92 //
93 // constants, enums and typedefs
94 //
95 
96 //
97 // static data member definitions
98 //
99 
100 //
101 // constructors and destructor
102 //
104  colLen_(iConfig.getParameter<edm::InputTag>("colLen")),
105  colDep_(iConfig.getParameter<edm::InputTag>("colDep")),
106  _inputCol(iConfig.getParameter<edm::InputTag>("selectedMuons")),
107  charge_(iConfig.getParameter<int>("charge"))
108 {
109 
110  detMap_[DetId::Hcal]="Hcal";
111  detMap_[DetId::Ecal]="Ecal";
112 
113  subDetMap_[DetId::Ecal][EcalBarrel]="EcalBarrel";
114  subDetMap_[DetId::Ecal][EcalEndcap]="EcalEndcap";
115  subDetMap_[DetId::Ecal][EcalPreshower ]="EcalPreshower";
116  subDetMap_[DetId::Ecal][EcalTriggerTower]="EcalTriggerTower";
117  subDetMap_[DetId::Ecal][EcalLaserPnDiode]="EcalLaserPnDiode";
118 
119  subDetMap_[DetId::Hcal][HcalEmpty]="HcalEmpty";
120  subDetMap_[DetId::Hcal][HcalBarrel]="HcalBarrel";
121  subDetMap_[DetId::Hcal][HcalEndcap]="HcalEndcap";
122  subDetMap_[DetId::Hcal][HcalOuter]="HcalOuter";
123  subDetMap_[DetId::Hcal][HcalForward]="HcalForward";
124  subDetMap_[DetId::Hcal][HcalTriggerTower]="HcalTriggerTower";
125  subDetMap_[DetId::Hcal][HcalOther]="HcalOther";
126 
127 
128  std::vector<std::string> keys = getAllKeys();
130  BOOST_FOREACH(std::string & name, keys){
131  histoMap_[name]=fs->make<TH2F>( name.c_str() , name.c_str(), 1000, 0., 200., 1000, 0, 20. );
132  std::string treeName = "tree_" +name ;
133  treeMap_[name]=fs->make<TTree>( treeName.c_str() , treeName.c_str());
134 
135  treeStorageMap_[name]["pt"] = -999;
136  treeStorageMap_[name]["p"] = -999;
137  treeStorageMap_[name]["eta"] = -999;
138  treeStorageMap_[name]["phi"] = -999;
139  treeStorageMap_[name]["len"] = -999;
140  treeStorageMap_[name]["val"] = -999;
141  treeStorageMap_[name]["charge"] = -999;
142 
143  BOOST_FOREACH(TTreeTempStorageMap::mapped_type::value_type & entry, treeStorageMap_[name] ){
144  treeMap_[name]->Branch(entry.first.c_str(), &entry.second);
145  }
146  }
147 
148  // TTreeMap treeMap_;
149  //TTreeTempStorageMap treeStorageMap_;
150 }
151 
152 
153 void
155 {
156 
157  //std::cout << "------------------------------\n";
159  iEvent.getByLabel(_inputCol, muonsHandle);
160 
161  const reco::Muon * myMu = 0;
162  BOOST_FOREACH(const reco::Muon & mu, *muonsHandle){
163  if (!mu.isGlobalMuon()) continue;
164  if (mu.charge()!= charge_) continue;
165  myMu = &mu;
166  break;
167  }
168 
169  if (myMu==0){
170  // std::cout << " XXX AnaMuonCaloCleaner says whoooops" << std::endl;
171  return;
172  }
173 
174  typedef std::map<unsigned int,float> TMyCol;
175  edm::Handle< TMyCol > hLenghts;
176  edm::Handle< TMyCol > hDeposits;
177 
178 
179  iEvent.getByLabel(colLen_,hLenghts);
180  iEvent.getByLabel(colDep_,hDeposits);
181 
182 
183  BOOST_FOREACH(const TMyCol::value_type & entry, *hLenghts){
184  DetId det(entry.first);
185  float len = entry.second;
186  float val = 0;
187  std::string name =getKey(det);
188  if (hDeposits->find(entry.first) != hDeposits->end())
189  val = (hDeposits->find(entry.first))->second;
190  //else
191  // std::cout << "Whoops! empty "<< len << " " << name << std::endl;
192 
193  //std::cout << "XX " << name << " " << det.rawId() << " " << len << " " << val << std::endl;
194  histoMap_[name]->Fill(len,val);
195  treeStorageMap_[name]["pt"] = myMu->pt();
196  treeStorageMap_[name]["p"] = myMu->p();
197  treeStorageMap_[name]["eta"] = myMu->eta();
198  treeStorageMap_[name]["phi"] = myMu->phi();
199  treeStorageMap_[name]["len"] = len;
200  treeStorageMap_[name]["val"] = val;
201  treeStorageMap_[name]["charge"] = myMu->charge();
202  treeMap_[name]->Fill();
203  }
204 
205  // edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit> > "ecalRecHit" "EcalRecHitsEE" "HLT" EcalRecHitsSorted_ecalRecHit_EcalRecHitsEE_HLT
206 
207 
208 
209 }
210 
211 
213  return "H_"+detMap_[det.det()]+"_"+subDetMap_[det.det()][det.subdetId()];
214 }
215 
216 std::vector<std::string> AnaMuonCaloCleaner::getAllKeys(){
217  std::vector<std::string> ret;
218  ret.push_back("H__");
219  BOOST_FOREACH(TMyMainMap::value_type & entry, detMap_){
220  BOOST_FOREACH(TMySubMap::mapped_type::value_type & subEntry, subDetMap_[entry.first]){
221  std::string name = "H_"+entry.second+"_"+subEntry.second;
222  //std::cout << "XX " << name << std::endl;
223  ret.push_back(name);
224  }
225 
226  }
227 
228  return ret;
229 }
230 
232 {
233 
234  // do anything here that needs to be done at desctruction time
235  // (e.g. close files, deallocate resources etc.)
236 
237 }
238 
239 
240 //
241 // member functions
242 //
243 
244 // ------------ method called for each event ------------
245 
246 
247 // ------------ method called once each job just before starting event loop ------------
248 void
250 {
251 }
252 
253 // ------------ method called once each job just after ending the event loop ------------
254 void
256 {
257 
258 }
259 
260 // ------------ method called when starting to processes a run ------------
261 void
263 {
264 }
265 
266 // ------------ method called when ending the processing of a run ------------
267 void
269 {
270 }
271 
272 // ------------ method called when starting to processes a luminosity block ------------
273 void
275 {
276 }
277 
278 // ------------ method called when ending the processing of a luminosity block ------------
279 void
281 {
282 }
283 
284 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
285 void
287  //The following says we do not know what parameters are allowed so do no validation
288  // Please change this to state exactly what you do use, even if it is no parameters
290  desc.setUnknown();
291  descriptions.addDefault(desc);
292 }
293 
294 //define this as a plug-in
std::map< std::string, TH2F * > THistoMap
virtual double p() const GCC11_FINAL
magnitude of momentum vector
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
AnaMuonCaloCleaner(const edm::ParameterSet &)
virtual void endRun(edm::Run const &, edm::EventSetup const &)
bool isGlobalMuon() const
Definition: Muon.h:218
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
U second(std::pair< T, U > const &p)
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
int iEvent
Definition: GenABIO.cc:243
void addDefault(ParameterSetDescription const &psetDescription)
std::string getKey(const DetId &det)
std::vector< std::string > getAllKeys()
virtual void analyze(const edm::Event &, const edm::EventSetup &)
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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
Definition: DetId.h:18
std::map< std::string, std::map< std::string, float > > TTreeTempStorageMap
virtual int charge() const GCC11_FINAL
electric charge
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
std::map< std::string, TTree * > TTreeMap
std::map< int, std::string > TMyMainMap
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
virtual float pt() const GCC11_FINAL
transverse momentum
TTreeTempStorageMap treeStorageMap_
std::map< int, std::map< int, std::string > > TMySubMap
Definition: Run.h:41