CMS 3D CMS Logo

EcalURecHitHists.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalURecHitHists
4 // Class: EcalURecHitHists
5 //
13 //
14 // Original Author: Seth COOPER
15 // Created: Th Nov 22 5:46:22 CEST 2007
16 //
17 //
18 
20 
21 using namespace cms;
22 using namespace edm;
23 using namespace std;
24 
25 //
26 // constants, enums and typedefs
27 //
28 
29 //
30 // static data member definitions
31 //
32 
33 //
34 // constructors and destructor
35 //
37  : EBUncalibratedRecHitCollection_(iConfig.getParameter<edm::InputTag>("EBUncalibratedRecHitCollection")),
38  EEUncalibratedRecHitCollection_(iConfig.getParameter<edm::InputTag>("EEUncalibratedRecHitCollection")),
39  runNum_(-1),
40  histRangeMax_(iConfig.getUntrackedParameter<double>("histogramMaxRange", 200.0)),
41  histRangeMin_(iConfig.getUntrackedParameter<double>("histogramMinRange", -10.0)),
42  fileName_(iConfig.getUntrackedParameter<std::string>("fileName", std::string("ecalURechHitHists"))) {
43  vector<int> listDefaults;
44  listDefaults.push_back(-1);
45 
46  maskedChannels_ = iConfig.getUntrackedParameter<vector<int> >("maskedChannels", listDefaults);
47  maskedFEDs_ = iConfig.getUntrackedParameter<vector<int> >("maskedFEDs", listDefaults);
48 
49  vector<string> defaultMaskedEBs;
50  defaultMaskedEBs.push_back("none");
51  maskedEBs_ = iConfig.getUntrackedParameter<vector<string> >("maskedEBs", defaultMaskedEBs);
52 
53  fedMap_ = new EcalFedMap();
54  string title1 = "Uncalib Rec Hits (ADC counts)";
55  string name1 = "URecHitsAllFEDs";
56  int numBins = (int)round(histRangeMax_ - histRangeMin_) + 1;
57  allFedsHist_ = new TH1F(name1.c_str(), title1.c_str(), numBins, histRangeMin_, histRangeMax_);
58  title1 = "Jitter for all FEDs";
59  name1 = "JitterAllFEDs";
60  allFedsTimingHist_ = new TH1F(name1.c_str(), title1.c_str(), 14, -7, 7);
61 
62  // load up the maskedFED list with the proper FEDids
63  if (maskedFEDs_[0] == -1) {
64  //if "actual" EB id given, then convert to FEDid and put in listFEDs_
65  if (maskedEBs_[0] != "none") {
66  maskedFEDs_.clear();
67  for (vector<string>::const_iterator ebItr = maskedEBs_.begin(); ebItr != maskedEBs_.end(); ++ebItr) {
68  maskedFEDs_.push_back(fedMap_->getFedFromSlice(*ebItr));
69  }
70  }
71  }
72 }
73 
75 
76 //
77 // member functions
78 //
79 
80 // ------------ method called to for each event ------------
82  int ievt = iEvent.id().event();
85 
87  LogDebug("EcalURecHitHists") << "event " << ievt << " hits collection size " << EBhits->size();
88 
90  LogDebug("EcalURecHitHists") << "event " << ievt << " hits collection size " << EEhits->size();
91 
92  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EBhits->begin(); hitItr != EBhits->end(); ++hitItr) {
93  EcalUncalibratedRecHit hit = (*hitItr);
94  EBDetId ebDet = hit.id();
95  int ic = ebDet.ic();
96  int hashedIndex = ebDet.hashedIndex();
98  int FEDid = 600 + elecId.dccId();
99  float ampli = hit.amplitude();
100 
101  vector<int>::iterator result;
102  result = find(maskedFEDs_.begin(), maskedFEDs_.end(), FEDid);
103  if (result != maskedFEDs_.end()) {
104  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for FED " << FEDid << " ; amplitude " << ampli;
105  continue;
106  }
107 
108  result = find(maskedChannels_.begin(), maskedChannels_.end(), hashedIndex);
109  if (result != maskedChannels_.end()) {
110  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for channel: " << ic << " with amplitude " << ampli;
111  continue;
112  }
113 
114  // fill the proper hist
115  TH1F* uRecHist = FEDsAndHists_[FEDid];
116  TH1F* timingHist = FEDsAndTimingHists_[FEDid];
117  if (uRecHist == nullptr) {
118  initHists(FEDid);
119  uRecHist = FEDsAndHists_[FEDid];
120  timingHist = FEDsAndTimingHists_[FEDid];
121  }
122 
123  uRecHist->Fill(ampli);
124  allFedsHist_->Fill(ampli);
125  timingHist->Fill(hit.jitter());
126  allFedsTimingHist_->Fill(hit.jitter());
127  }
128 
129  // Again for the endcap
130  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EEhits->begin(); hitItr != EEhits->end(); ++hitItr) {
131  EcalUncalibratedRecHit hit = (*hitItr);
132  EEDetId eeDet = hit.id();
133  int ic = eeDet.ic();
134  int hashedIndex = eeDet.hashedIndex();
136  int FEDid = 600 + elecId.dccId();
137  float ampli = hit.amplitude();
138 
139  vector<int>::iterator result;
140  result = find(maskedFEDs_.begin(), maskedFEDs_.end(), FEDid);
141  if (result != maskedFEDs_.end()) {
142  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for FED " << FEDid << " ; amplitude " << ampli;
143  continue;
144  }
145 
146  result = find(maskedChannels_.begin(), maskedChannels_.end(), hashedIndex);
147  if (result != maskedChannels_.end()) {
148  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for channel: " << ic << " with amplitude " << ampli;
149  continue;
150  }
151 
152  // fill the proper hist
153  TH1F* uRecHist = FEDsAndHists_[FEDid];
154  TH1F* timingHist = FEDsAndTimingHists_[FEDid];
155  if (uRecHist == nullptr) {
156  initHists(FEDid);
157  uRecHist = FEDsAndHists_[FEDid];
158  timingHist = FEDsAndTimingHists_[FEDid];
159  }
160 
161  uRecHist->Fill(ampli);
162  allFedsHist_->Fill(ampli);
163  timingHist->Fill(hit.jitter());
164  allFedsTimingHist_->Fill(hit.jitter());
165  }
166 
167  if (runNum_ == -1) {
168  runNum_ = iEvent.id().run();
169  }
170 }
171 
172 // insert the hist map into the map keyed by FED number
174  using namespace std;
175 
176  string FEDid = intToString(FED);
177  string title1 = "Uncalib Rec Hits (ADC counts) for ";
178  title1.append(fedMap_->getSliceFromFed(FED));
179  string name1 = "URecHitsFED";
180  name1.append(intToString(FED));
181  int numBins = (int)round(histRangeMax_ - histRangeMin_) + 1;
182  TH1F* hist = new TH1F(name1.c_str(), title1.c_str(), numBins, histRangeMin_, histRangeMax_);
183  FEDsAndHists_[FED] = hist;
184  FEDsAndHists_[FED]->SetDirectory(nullptr);
185 
186  title1 = "Jitter for ";
187  title1.append(fedMap_->getSliceFromFed(FED));
188  name1 = "JitterFED";
189  name1.append(intToString(FED));
190  TH1F* timingHist = new TH1F(name1.c_str(), title1.c_str(), 14, -7, 7);
191  FEDsAndTimingHists_[FED] = timingHist;
192  FEDsAndTimingHists_[FED]->SetDirectory(nullptr);
193 }
194 
195 // ------------ method called once each job just before starting event loop ------------
198  c.get<EcalMappingRcd>().get(elecHandle);
199  ecalElectronicsMap_ = elecHandle.product();
200 }
201 
202 // ------------ method called once each job just after ending the event loop ------------
204  using namespace std;
205  fileName_ += "-" + intToString(runNum_) + ".graph.root";
206 
207  TFile root_file_(fileName_.c_str(), "RECREATE");
208 
209  for (map<int, TH1F*>::const_iterator itr = FEDsAndHists_.begin(); itr != FEDsAndHists_.end(); ++itr) {
210  string dir = fedMap_->getSliceFromFed(itr->first);
211  TDirectory* FEDdir = gDirectory->mkdir(dir.c_str());
212  FEDdir->cd();
213 
214  TH1F* hist = itr->second;
215  if (hist != nullptr)
216  hist->Write();
217  else {
218  cerr << "EcalPedHists: Error: This shouldn't happen!" << endl;
219  }
220  // Write out timing hist
221  hist = FEDsAndTimingHists_[itr->first];
222  if (hist != nullptr)
223  hist->Write();
224  else {
225  cerr << "EcalPedHists: Error: This shouldn't happen!" << endl;
226  }
227  root_file_.cd();
228  }
229  allFedsHist_->Write();
230  allFedsTimingHist_->Write();
231  root_file_.Close();
232 
234  for (std::vector<int>::const_iterator itr = maskedChannels_.begin(); itr != maskedChannels_.end(); ++itr) {
235  channels += intToString(*itr);
236  channels += ",";
237  }
238 
239  LogWarning("EcalMipGraphs") << "Masked channels are: " << channels << " and that is all!";
240 }
241 
243  using namespace std;
244  ostringstream myStream;
245  myStream << num << flush;
246  return (myStream.str()); //returns the string form of the stringstream object
247 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:38
const EcalElectronicsMapping * ecalElectronicsMap_
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:82
int ic() const
Definition: EEDetId.cc:245
std::string fileName_
edm::InputTag EBUncalibratedRecHitCollection_
void beginRun(edm::Run const &, edm::EventSetup const &) override
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
std::vector< T >::const_iterator const_iterator
edm::InputTag EEUncalibratedRecHitCollection_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void endJob() override
std::string getSliceFromFed(int)
Definition: EcalFedMap.cc:86
int hashedIndex(int ieta, int iphi)
Definition: EcalPyUtils.cc:38
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
int iEvent
Definition: GenABIO.cc:224
void analyze(edm::Event const &, edm::EventSetup const &) override
std::map< int, TH1F * > FEDsAndHists_
std::map< int, TH1F * > FEDsAndTimingHists_
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:41
Namespace of DDCMS conversion namespace.
const_iterator end() const
EcalURecHitHists(const edm::ParameterSet &)
int hashedIndex() const
Definition: EEDetId.h:183
std::vector< int > maskedChannels_
std::vector< std::string > maskedEBs_
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
size_type size() const
std::vector< int > maskedFEDs_
T get() const
Definition: EventSetup.h:73
EcalFedMap * fedMap_
~EcalURecHitHists() override
std::string intToString(int num)
T const * product() const
Definition: ESHandle.h:86
const_iterator begin() const
Definition: Run.h:45