CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  ebUncalibRecHitsToken_(consumes<EcalUncalibratedRecHitCollection>(ebUncalibratedRecHitCollection_)),
40  eeUncalibRecHitsToken_(consumes<EcalUncalibratedRecHitCollection>(eeUncalibratedRecHitCollection_)),
41  ecalMappingToken_(esConsumes<edm::Transition::BeginRun>()),
42  runNum_(-1),
43  histRangeMax_(iConfig.getUntrackedParameter<double>("histogramMaxRange", 200.0)),
44  histRangeMin_(iConfig.getUntrackedParameter<double>("histogramMinRange", -10.0)),
45  fileName_(iConfig.getUntrackedParameter<std::string>("fileName", std::string("ecalURechHitHists"))) {
46  vector<int> listDefaults;
47  listDefaults.push_back(-1);
48 
49  maskedChannels_ = iConfig.getUntrackedParameter<vector<int> >("maskedChannels", listDefaults);
50  maskedFEDs_ = iConfig.getUntrackedParameter<vector<int> >("maskedFEDs", listDefaults);
51 
52  vector<string> defaultMaskedEBs;
53  defaultMaskedEBs.push_back("none");
54  maskedEBs_ = iConfig.getUntrackedParameter<vector<string> >("maskedEBs", defaultMaskedEBs);
55 
56  fedMap_ = new EcalFedMap();
57  string title1 = "Uncalib Rec Hits (ADC counts)";
58  string name1 = "URecHitsAllFEDs";
59  int numBins = (int)round(histRangeMax_ - histRangeMin_) + 1;
60  allFedsHist_ = new TH1F(name1.c_str(), title1.c_str(), numBins, histRangeMin_, histRangeMax_);
61  title1 = "Jitter for all FEDs";
62  name1 = "JitterAllFEDs";
63  allFedsTimingHist_ = new TH1F(name1.c_str(), title1.c_str(), 14, -7, 7);
64 
65  // load up the maskedFED list with the proper FEDids
66  if (maskedFEDs_[0] == -1) {
67  //if "actual" EB id given, then convert to FEDid and put in listFEDs_
68  if (maskedEBs_[0] != "none") {
69  maskedFEDs_.clear();
70  for (vector<string>::const_iterator ebItr = maskedEBs_.begin(); ebItr != maskedEBs_.end(); ++ebItr) {
71  maskedFEDs_.push_back(fedMap_->getFedFromSlice(*ebItr));
72  }
73  }
74  }
75 }
76 
78 
79 //
80 // member functions
81 //
82 
83 // ------------ method called to for each event ------------
85  int ievt = iEvent.id().event();
88 
89  iEvent.getByToken(ebUncalibRecHitsToken_, EBhits);
90  LogDebug("EcalURecHitHists") << "event " << ievt << " hits collection size " << EBhits->size();
91 
92  iEvent.getByToken(eeUncalibRecHitsToken_, EEhits);
93  LogDebug("EcalURecHitHists") << "event " << ievt << " hits collection size " << EEhits->size();
94 
95  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EBhits->begin(); hitItr != EBhits->end(); ++hitItr) {
96  EcalUncalibratedRecHit hit = (*hitItr);
97  EBDetId ebDet = hit.id();
98  int ic = ebDet.ic();
99  int hashedIndex = ebDet.hashedIndex();
101  int FEDid = 600 + elecId.dccId();
102  float ampli = hit.amplitude();
103 
104  vector<int>::iterator result;
105  result = find(maskedFEDs_.begin(), maskedFEDs_.end(), FEDid);
106  if (result != maskedFEDs_.end()) {
107  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for FED " << FEDid << " ; amplitude " << ampli;
108  continue;
109  }
110 
111  result = find(maskedChannels_.begin(), maskedChannels_.end(), hashedIndex);
112  if (result != maskedChannels_.end()) {
113  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for channel: " << ic << " with amplitude " << ampli;
114  continue;
115  }
116 
117  // fill the proper hist
118  TH1F* uRecHist = FEDsAndHists_[FEDid];
119  TH1F* timingHist = FEDsAndTimingHists_[FEDid];
120  if (uRecHist == nullptr) {
121  initHists(FEDid);
122  uRecHist = FEDsAndHists_[FEDid];
123  timingHist = FEDsAndTimingHists_[FEDid];
124  }
125 
126  uRecHist->Fill(ampli);
127  allFedsHist_->Fill(ampli);
128  timingHist->Fill(hit.jitter());
129  allFedsTimingHist_->Fill(hit.jitter());
130  }
131 
132  // Again for the endcap
133  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EEhits->begin(); hitItr != EEhits->end(); ++hitItr) {
134  EcalUncalibratedRecHit hit = (*hitItr);
135  EEDetId eeDet = hit.id();
136  int ic = eeDet.ic();
137  int hashedIndex = eeDet.hashedIndex();
139  int FEDid = 600 + elecId.dccId();
140  float ampli = hit.amplitude();
141 
142  vector<int>::iterator result;
143  result = find(maskedFEDs_.begin(), maskedFEDs_.end(), FEDid);
144  if (result != maskedFEDs_.end()) {
145  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for FED " << FEDid << " ; amplitude " << ampli;
146  continue;
147  }
148 
149  result = find(maskedChannels_.begin(), maskedChannels_.end(), hashedIndex);
150  if (result != maskedChannels_.end()) {
151  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for channel: " << ic << " with amplitude " << ampli;
152  continue;
153  }
154 
155  // fill the proper hist
156  TH1F* uRecHist = FEDsAndHists_[FEDid];
157  TH1F* timingHist = FEDsAndTimingHists_[FEDid];
158  if (uRecHist == nullptr) {
159  initHists(FEDid);
160  uRecHist = FEDsAndHists_[FEDid];
161  timingHist = FEDsAndTimingHists_[FEDid];
162  }
163 
164  uRecHist->Fill(ampli);
165  allFedsHist_->Fill(ampli);
166  timingHist->Fill(hit.jitter());
167  allFedsTimingHist_->Fill(hit.jitter());
168  }
169 
170  if (runNum_ == -1) {
171  runNum_ = iEvent.id().run();
172  }
173 }
174 
175 // insert the hist map into the map keyed by FED number
177  using namespace std;
178 
179  string FEDid = intToString(FED);
180  string title1 = "Uncalib Rec Hits (ADC counts) for ";
181  title1.append(fedMap_->getSliceFromFed(FED));
182  string name1 = "URecHitsFED";
183  name1.append(intToString(FED));
184  int numBins = (int)round(histRangeMax_ - histRangeMin_) + 1;
185  TH1F* hist = new TH1F(name1.c_str(), title1.c_str(), numBins, histRangeMin_, histRangeMax_);
186  FEDsAndHists_[FED] = hist;
187  FEDsAndHists_[FED]->SetDirectory(nullptr);
188 
189  title1 = "Jitter for ";
190  title1.append(fedMap_->getSliceFromFed(FED));
191  name1 = "JitterFED";
192  name1.append(intToString(FED));
193  TH1F* timingHist = new TH1F(name1.c_str(), title1.c_str(), 14, -7, 7);
194  FEDsAndTimingHists_[FED] = timingHist;
195  FEDsAndTimingHists_[FED]->SetDirectory(nullptr);
196 }
197 
198 // ------------ method called once each job just before starting event loop ------------
201 }
202 
204 
205 // ------------ method called once each job just after ending the event loop ------------
207  using namespace std;
208  fileName_ += "-" + intToString(runNum_) + ".graph.root";
209 
210  TFile root_file_(fileName_.c_str(), "RECREATE");
211 
212  for (map<int, TH1F*>::const_iterator itr = FEDsAndHists_.begin(); itr != FEDsAndHists_.end(); ++itr) {
213  string dir = fedMap_->getSliceFromFed(itr->first);
214  TDirectory* FEDdir = gDirectory->mkdir(dir.c_str());
215  FEDdir->cd();
216 
217  TH1F* hist = itr->second;
218  if (hist != nullptr)
219  hist->Write();
220  else {
221  cerr << "EcalPedHists: Error: This shouldn't happen!" << endl;
222  }
223  // Write out timing hist
224  hist = FEDsAndTimingHists_[itr->first];
225  if (hist != nullptr)
226  hist->Write();
227  else {
228  cerr << "EcalPedHists: Error: This shouldn't happen!" << endl;
229  }
230  root_file_.cd();
231  }
232  allFedsHist_->Write();
233  allFedsTimingHist_->Write();
234  root_file_.Close();
235 
236  std::string channels;
237  for (std::vector<int>::const_iterator itr = maskedChannels_.begin(); itr != maskedChannels_.end(); ++itr) {
238  channels += intToString(*itr);
239  channels += ",";
240  }
241 
242  LogWarning("EcalMipGraphs") << "Masked channels are: " << channels << " and that is all!";
243 }
244 
246  using namespace std;
247  ostringstream myStream;
248  myStream << num << flush;
249  return (myStream.str()); //returns the string form of the stringstream object
250 }
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
const edm::EventSetup & c
int ic() const
Definition: EEDetId.cc:245
std::string fileName_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
const edm::EDGetTokenT< EcalUncalibratedRecHitCollection > eeUncalibRecHitsToken_
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
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const double histRangeMax_
const edm::EDGetTokenT< EcalUncalibratedRecHitCollection > ebUncalibRecHitsToken_
void endJob() override
tuple result
Definition: mps_fire.py:311
std::string getSliceFromFed(int)
Definition: EcalFedMap.cc:86
bool getData(T &iHolder) const
Definition: EventSetup.h:122
int hashedIndex(int ieta, int iphi)
Definition: EcalPyUtils.cc:36
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
int iEvent
Definition: GenABIO.cc:224
void endRun(edm::Run const &, edm::EventSetup const &) override
void analyze(edm::Event const &, edm::EventSetup const &) override
const edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > ecalMappingToken_
Transition
Definition: Transition.h:12
std::map< int, TH1F * > FEDsAndHists_
std::map< int, TH1F * > FEDsAndTimingHists_
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:41
__shared__ Hist hist
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
std::vector< int > maskedFEDs_
EcalFedMap * fedMap_
~EcalURecHitHists() override
std::string intToString(int num)
Log< level::Warning, false > LogWarning
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const double histRangeMin_
Definition: Run.h:45
#define LogDebug(id)