CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecAnalyzerMinbias.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <string>
4 #include <iostream>
5 #include <fstream>
6 #include <sstream>
7 #include <vector>
8 #include <map>
9 
10 // user include files
27 
28 #include "TH1F.h"
29 #include "TFile.h"
30 #include "TTree.h"
31 
32 //#define debugLog
33 
34 // class declaration
36 
37 public:
38  explicit RecAnalyzerMinbias(const edm::ParameterSet&);
40  virtual void analyze(const edm::Event&, const edm::EventSetup&);
41  virtual void beginJob() ;
42  virtual void endJob() ;
43 
44 private:
46  const HcalRespCorrs*, int);
47 
48  // ----------member data ---------------------------
49  char name[700], hf_name[700], title[700], hf_title[700];
52  TFile* hOutputFile ;
53  TTree* myTree;
54  std::vector<TH1D *> histo;
55  std::vector<unsigned int> hcalID;
56 
57  // Root tree members
58  double rnnum, rnnumber;
61  struct myInfo{
63  void MyInfo() {
64  theMB0 = theMB1 = theMB2 = theMB3 = theMB4 = runcheck = 0;
65  }
66  };
67  std::map<std::pair<int,HcalDetId>,myInfo> myMap;
71 };
72 
73 // constructors and destructor
75 
76  // get name of output file with histogramms
77  fOutputFileName = iConfig.getUntrackedParameter<std::string>("HistOutFile");
78  theRecalib = iConfig.getParameter<bool>("Recalib");
79  ignoreL1 = iConfig.getUntrackedParameter<bool>("IgnoreL1", false);
80  std::vector<int> ieta = iConfig.getUntrackedParameter<std::vector<int>>("HcalIeta");
81  std::vector<int> iphi = iConfig.getUntrackedParameter<std::vector<int>>("HcalIphi");
82  std::vector<int> depth= iConfig.getUntrackedParameter<std::vector<int>>("HcalDepth");
83 
84  // get token names of modules, producing object collections
85  tok_hbherecoMB_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInputMB"));
86  tok_hfrecoMB_ = consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hfInputMB"));
87  tok_hltL1GtMap_ = consumes<L1GlobalTriggerObjectMapRecord>(edm::InputTag("hltL1GtObjectMap"));
88 
89 #ifdef DebugLog
90  std::cout << "Output File: " << fOutputFileName << " Flags (ReCalib): "
91  << theRecalib << " (IgnoreL1): " << ignoreL1 << " with "
92  << ieta.size() << " detId for full histogram" << std::endl;
93 #endif
94  for (unsigned int k=0; k<ieta.size(); ++k) {
95  HcalSubdetector subd = ((std::abs(ieta[k]) > 29) ? HcalForward :
96  (std::abs(ieta[k]) > 16) ? HcalEndcap :
97  ((std::abs(ieta[k]) == 16) && (depth[k] == 3)) ? HcalEndcap :
98  (depth[k] == 4) ? HcalOuter : HcalBarrel);
99  unsigned int id = (HcalDetId(subd,ieta[k],iphi[k],depth[k])).rawId();
100  hcalID.push_back(id);
101 #ifdef DebugLog
102  std::cout << "DetId[" << k << "] " << HcalDetId(id) << std::endl;
103 #endif
104  }
105 }
106 
108 
110  std::string hc[5] = {"Empty", "HB", "HE", "HO", "HF"};
111  for (unsigned int i=0; i<hcalID.size(); i++) {
112  HcalDetId id = HcalDetId(hcalID[i]);
113  int subdet = id.subdetId();
114  sprintf (name, "%s%d_%d_%d", hc[subdet].c_str(), id.ieta(), id.iphi(), id.depth());
115  sprintf (title, "Energy Distribution for %s ieta %d iphi %d depth %d", hc[subdet].c_str(), id.ieta(), id.iphi(), id.depth());
116  double xmin = (subdet == 4) ? -10 : -1;
117  double xmax = (subdet == 4) ? 90 : 9;
118  TH1D* hh = new TH1D(name, title, 50, xmin, xmax);
119  histo.push_back(hh);
120  };
121 
122  hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
123  myTree = new TTree("RecJet","RecJet Tree");
124  myTree->Branch("cells", &cells, "cells/I");
125  myTree->Branch("mysubd", &mysubd, "mysubd/I");
126  myTree->Branch("depth", &depth, "depth/I");
127  myTree->Branch("ieta", &ieta, "ieta/I");
128  myTree->Branch("iphi", &iphi, "iphi/I");
129  myTree->Branch("mom0_MB", &mom0_MB, "mom0_MB/F");
130  myTree->Branch("mom1_MB", &mom1_MB, "mom1_MB/F");
131  myTree->Branch("mom2_MB", &mom2_MB, "mom2_MB/F");
132  myTree->Branch("mom3_MB", &mom2_MB, "mom3_MB/F");
133  myTree->Branch("mom4_MB", &mom4_MB, "mom4_MB/F");
134  myTree->Branch("trigbit", &trigbit, "trigbit/I");
135  myTree->Branch("rnnumber", &rnnumber, "rnnumber/D");
136  myMap.clear();
137  return ;
138 }
139 
140 // EndJob
141 //
142 
144  cells = 0;
145  for (std::map<std::pair<int,HcalDetId>,myInfo>::const_iterator itr=myMap.begin(); itr != myMap.end(); ++itr) {
146 #ifdef debugLog
147  std::cout << "Fired trigger bit number " << itr->first.first << std::endl;
148 #endif
149  myInfo info = itr->second;
150  if (info.theMB0 > 0) {
151  mom0_MB = info.theMB0;
152  mom1_MB = info.theMB1;
153  mom2_MB = info.theMB2;
154  mom3_MB = info.theMB3;
155  mom4_MB = info.theMB4;
156  rnnumber = info.runcheck;
157  trigbit = itr->first.first;
158  mysubd = itr->first.second.subdet();
159  depth = itr->first.second.depth();
160  iphi = itr->first.second.iphi();
161  ieta = itr->first.second.ieta();
162 #ifdef debugLog
163  std::cout << " Result= " << trigbit << " " << mysubd << " " << ieta
164  << " " << iphi << " mom0 " << mom0_MB << " mom1 " << mom1_MB
165  << " mom2 " << mom2_MB << " mom3 " << mom3_MB << " mom4 "
166  << mom4_MB << std::endl;
167 #endif
168  myTree->Fill();
169  cells++;
170  }
171  }
172 #ifdef debugLog
173  std::cout << "cells" << " " << cells << std::endl;
174 #endif
175 
176 
177  hOutputFile->Write();
178  hOutputFile->cd();
179  for(unsigned int i = 0; i<histo.size(); i++){
180  histo[i]->Write();
181  }
182  myTree->Write();
183  hOutputFile->Close() ;
184 }
185 
186 //
187 // member functions
188 //
189 // ------------ method called to produce the data ------------
190 
192 
193  rnnum = (float)iEvent.run();
194  const HcalRespCorrs* myRecalib=0;
195  if (theRecalib ) {
196  edm::ESHandle <HcalRespCorrs> recalibCorrs;
197  iSetup.get<HcalRespCorrsRcd>().get("recalibrate",recalibCorrs);
198  myRecalib = recalibCorrs.product();
199  } // theRecalib
200 
202  iEvent.getByToken(tok_hbherecoMB_, hbheMB);
203  if (!hbheMB.isValid()) {
204  edm::LogInfo("AnalyzerMB") << "HcalCalibAlgos: Error! can't get hbhe product!";
205  return ;
206  }
207  const HBHERecHitCollection HithbheMB = *(hbheMB.product());
208 #ifdef debugLog
209  std::cout << "HBHE MB size of collection " << HithbheMB.size() << std::endl;
210 #endif
211  if (HithbheMB.size() < 5100) {
212  edm::LogWarning("AnalyzerMB") << "HBHE problem " << rnnum << " size "
213  << HithbheMB.size();
214  return;
215  }
216 
218  iEvent.getByToken(tok_hfrecoMB_, hfMB);
219  if (!hfMB.isValid()) {
220  edm::LogInfo("AnalyzerMB") << "HcalCalibAlgos: Error! can't get hbhe product!";
221  return ;
222  }
223  const HFRecHitCollection HithfMB = *(hfMB.product());
224 #ifdef debugLog
225  std::cout << "HF MB size of collection " << HithfMB.size() << std::endl;
226 #endif
227  if (HithfMB.size() < 1700) {
228  edm::LogWarning("AnalyzerMB") << "HF problem " << rnnum << " size "
229  << HithfMB.size();
230  return;
231  }
232 
233  if (ignoreL1) {
234  analyzeHcal(HithbheMB, HithfMB, myRecalib, 1);
235  } else {
237  iEvent.getByToken(tok_hltL1GtMap_, gtObjectMapRecord);
238  if (gtObjectMapRecord.isValid()) {
239  const std::vector<L1GlobalTriggerObjectMap>& objMapVec = gtObjectMapRecord->gtObjectMap();
240  bool ok(false);
241  for (std::vector<L1GlobalTriggerObjectMap>::const_iterator itMap = objMapVec.begin();
242  itMap != objMapVec.end(); ++itMap) {
243  bool resultGt = (*itMap).algoGtlResult();
244  if (resultGt) {
245  int algoBit = (*itMap).algoBitNumber();
246  analyzeHcal(HithbheMB, HithfMB, myRecalib, algoBit);
247  ok = true;
248  }
249  }
250  if (!ok) {
251 #ifdef debugLog
252  std::cout << "No passed L1 Trigger found" << std::endl;
253 #endif
254  }
255  }
256  }
257 }
258 
260  const HFRecHitCollection & HithfMB,
261  const HcalRespCorrs* myRecalib,
262  int algoBit) {
263  // Signal part for HB HE
264  for (HBHERecHitCollection::const_iterator hbheItr=HithbheMB.begin();
265  hbheItr!=HithbheMB.end(); hbheItr++) {
266  // Recalibration of energy
267  float icalconst=1.;
268  DetId mydetid = hbheItr->id().rawId();
269  if (theRecalib) icalconst = myRecalib->getValues(mydetid)->getValue();
270  HBHERecHit aHit(hbheItr->id(),hbheItr->energy()*icalconst,hbheItr->time());
271  double energyhit = aHit.energy();
272  DetId id = (*hbheItr).detid();
273  HcalDetId hid = HcalDetId(id);
274 
275  for (unsigned int i = 0; i < hcalID.size(); i++) {
276  if (hcalID[i] == id.rawId()) {
277  histo[i]->Fill(energyhit);
278  break;
279  }
280  }
281  std::map<std::pair<int,HcalDetId>,myInfo>::iterator itr1 = myMap.find(std::pair<int,HcalDetId>(algoBit,hid));
282  if (itr1 == myMap.end()) {
283  myInfo info;
284  myMap[std::pair<int,HcalDetId>(algoBit,hid)] = info;
285  itr1 = myMap.find(std::pair<int,HcalDetId>(algoBit,hid));
286  }
287  itr1->second.theMB0++;
288  itr1->second.theMB1 += energyhit;
289  itr1->second.theMB2 += (energyhit*energyhit);
290  itr1->second.theMB3 += (energyhit*energyhit*energyhit);
291  itr1->second.theMB4 += (energyhit*energyhit*energyhit*energyhit);
292  itr1->second.runcheck = rnnum;
293  } // HBHE_MB
294 
295  // Signal part for HF
296  for (HFRecHitCollection::const_iterator hfItr=HithfMB.begin();
297  hfItr!=HithfMB.end(); hfItr++) {
298  // Recalibration of energy
299  float icalconst=1.;
300  DetId mydetid = hfItr->id().rawId();
301  if (theRecalib) icalconst = myRecalib->getValues(mydetid)->getValue();
302  HFRecHit aHit(hfItr->id(),hfItr->energy()*icalconst,hfItr->time());
303 
304  double energyhit = aHit.energy();
305  DetId id = (*hfItr).detid();
306  HcalDetId hid = HcalDetId(id);
307  for (unsigned int i = 0; i < hcalID.size(); i++) {
308  if (hcalID[i] == id.rawId()) {
309  histo[i]->Fill(energyhit);
310  break;
311  }
312  }
313  //
314  // Remove PMT hits
315  //
316  if (fabs(energyhit) > 40.) continue;
317  std::map<std::pair<int,HcalDetId>,myInfo>::iterator itr1 = myMap.find(std::pair<int,HcalDetId>(algoBit,hid));
318  if (itr1 == myMap.end()) {
319  myInfo info;
320  myMap[std::pair<int,HcalDetId>(algoBit,hid)] = info;
321  itr1 = myMap.find(std::pair<int,HcalDetId>(algoBit,hid));
322  }
323  itr1->second.theMB0++;
324  itr1->second.theMB1 += energyhit;
325  itr1->second.theMB2 += (energyhit*energyhit);
326  itr1->second.theMB3 += (energyhit*energyhit*energyhit);
327  itr1->second.theMB4 += (energyhit*energyhit*energyhit*energyhit);
328  itr1->second.runcheck = rnnum;
329  }
330 }
331 
332 //define this as a plug-in
std::vector< unsigned int > hcalID
T getParameter(std::string const &) const
RecAnalyzerMinbias(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
static const TGPicture * info(bool iBackgroundIsBlack)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< HBHERecHit >::const_iterator const_iterator
virtual void analyze(const edm::Event &, const edm::EventSetup &)
const Item * getValues(DetId fId, bool throwOnFail=true) const
return((rh^lh)&mask)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int iEvent
Definition: GenABIO.cc:230
float energy() const
Definition: CaloRecHit.h:17
std::map< std::pair< int, HcalDetId >, myInfo > myMap
edm::EDGetTokenT< HFRecHitCollection > tok_hfrecoMB_
RunNumber_t run() const
Definition: Event.h:85
void analyzeHcal(const HBHERecHitCollection &, const HFRecHitCollection &, const HcalRespCorrs *, int)
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:75
const_iterator end() const
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< HBHERecHitCollection > tok_hbherecoMB_
float getValue() const
Definition: HcalRespCorr.h:20
size_type size() const
susybsm::HSCParticleCollection hc
Definition: classes.h:25
tuple cout
Definition: gather_cfg.py:121
edm::EDGetTokenT< L1GlobalTriggerObjectMapRecord > tok_hltL1GtMap_
std::vector< TH1D * > histo
const_iterator begin() const