CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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  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 {
44  vector<int> listDefaults;
45  listDefaults.push_back(-1);
46 
47  maskedChannels_ = iConfig.getUntrackedParameter<vector<int> >("maskedChannels", listDefaults);
48  maskedFEDs_ = iConfig.getUntrackedParameter<vector<int> >("maskedFEDs", listDefaults);
49 
50  vector<string> defaultMaskedEBs;
51  defaultMaskedEBs.push_back("none");
52  maskedEBs_ = iConfig.getUntrackedParameter<vector<string> >("maskedEBs",defaultMaskedEBs);
53 
54  fedMap_ = new EcalFedMap();
55  string title1 = "Uncalib Rec Hits (ADC counts)";
56  string name1 = "URecHitsAllFEDs";
57  int numBins = (int)round(histRangeMax_-histRangeMin_)+1;
58  allFedsHist_ = new TH1F(name1.c_str(),title1.c_str(),numBins,histRangeMin_,histRangeMax_);
59  title1 = "Jitter for all FEDs";
60  name1 = "JitterAllFEDs";
61  allFedsTimingHist_ = new TH1F(name1.c_str(),title1.c_str(),14,-7,7);
62 
63  // load up the maskedFED list with the proper FEDids
64  if(maskedFEDs_[0]==-1)
65  {
66  //if "actual" EB id given, then convert to FEDid and put in listFEDs_
67  if(maskedEBs_[0] != "none")
68  {
69  maskedFEDs_.clear();
70  for(vector<string>::const_iterator ebItr = maskedEBs_.begin(); ebItr != maskedEBs_.end(); ++ebItr)
71  {
72  maskedFEDs_.push_back(fedMap_->getFedFromSlice(*ebItr));
73  }
74  }
75  }
76 }
77 
78 
80 {
81 }
82 
83 
84 //
85 // member functions
86 //
87 
88 // ------------ method called to for each event ------------
89 void
91 {
92  int ievt = iEvent.id().event();
95 
97  LogDebug("EcalURecHitHists") << "event " << ievt << " hits collection size " << EBhits->size();
98 
100  LogDebug("EcalURecHitHists") << "event " << ievt << " hits collection size " << EEhits->size();
101 
102  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EBhits->begin(); hitItr != EBhits->end(); ++hitItr)
103  {
104  EcalUncalibratedRecHit hit = (*hitItr);
105  EBDetId ebDet = hit.id();
106  int ic = ebDet.ic();
107  int hashedIndex = ebDet.hashedIndex();
109  int FEDid = 600+elecId.dccId();
110  float ampli = hit.amplitude();
111 
112  vector<int>::iterator result;
113  result = find(maskedFEDs_.begin(), maskedFEDs_.end(), FEDid);
114  if(result != maskedFEDs_.end())
115  {
116  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for FED " << FEDid << " ; amplitude " << ampli;
117  continue;
118  }
119 
120  result = find(maskedChannels_.begin(), maskedChannels_.end(), hashedIndex);
121  if (result != maskedChannels_.end())
122  {
123  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for channel: " << ic << " with amplitude " << ampli ;
124  continue;
125  }
126 
127  // fill the proper hist
128  TH1F* uRecHist = FEDsAndHists_[FEDid];
129  TH1F* timingHist = FEDsAndTimingHists_[FEDid];
130  if(uRecHist==0)
131  {
132  initHists(FEDid);
133  uRecHist = FEDsAndHists_[FEDid];
134  timingHist = FEDsAndTimingHists_[FEDid];
135  }
136 
137  uRecHist->Fill(ampli);
138  allFedsHist_->Fill(ampli);
139  timingHist->Fill(hit.jitter());
140  allFedsTimingHist_->Fill(hit.jitter());
141  }
142 
143  // Again for the endcap
144  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EEhits->begin(); hitItr != EEhits->end(); ++hitItr)
145  {
146  EcalUncalibratedRecHit hit = (*hitItr);
147  EEDetId eeDet = hit.id();
148  int ic = eeDet.ic();
149  int hashedIndex = eeDet.hashedIndex();
151  int FEDid = 600+elecId.dccId();
152  float ampli = hit.amplitude();
153 
154  vector<int>::iterator result;
155  result = find(maskedFEDs_.begin(), maskedFEDs_.end(), FEDid);
156  if(result != maskedFEDs_.end())
157  {
158  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for FED " << FEDid << " ; amplitude " << ampli;
159  continue;
160  }
161 
162  result = find(maskedChannels_.begin(), maskedChannels_.end(), hashedIndex);
163  if (result != maskedChannels_.end())
164  {
165  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for channel: " << ic << " with amplitude " << ampli ;
166  continue;
167  }
168 
169  // fill the proper hist
170  TH1F* uRecHist = FEDsAndHists_[FEDid];
171  TH1F* timingHist = FEDsAndTimingHists_[FEDid];
172  if(uRecHist==0)
173  {
174  initHists(FEDid);
175  uRecHist = FEDsAndHists_[FEDid];
176  timingHist = FEDsAndTimingHists_[FEDid];
177  }
178 
179  uRecHist->Fill(ampli);
180  allFedsHist_->Fill(ampli);
181  timingHist->Fill(hit.jitter());
182  allFedsTimingHist_->Fill(hit.jitter());
183  }
184 
185  if(runNum_==-1)
186  {
187  runNum_ = iEvent.id().run();
188  }
189 }
190 
191 
192 // insert the hist map into the map keyed by FED number
194 {
195  using namespace std;
196 
197  string FEDid = intToString(FED);
198  string title1 = "Uncalib Rec Hits (ADC counts) for ";
199  title1.append(fedMap_->getSliceFromFed(FED));
200  string name1 = "URecHitsFED";
201  name1.append(intToString(FED));
202  int numBins = (int)round(histRangeMax_-histRangeMin_)+1;
203  TH1F* hist = new TH1F(name1.c_str(),title1.c_str(), numBins, histRangeMin_, histRangeMax_);
204  FEDsAndHists_[FED] = hist;
205  FEDsAndHists_[FED]->SetDirectory(0);
206 
207  title1 = "Jitter for ";
208  title1.append(fedMap_->getSliceFromFed(FED));
209  name1 = "JitterFED";
210  name1.append(intToString(FED));
211  TH1F* timingHist = new TH1F(name1.c_str(),title1.c_str(),14,-7,7);
212  FEDsAndTimingHists_[FED] = timingHist;
213  FEDsAndTimingHists_[FED]->SetDirectory(0);
214 }
215 
216 // ------------ method called once each job just before starting event loop ------------
217 void
219 {
221  c.get<EcalMappingRcd>().get(elecHandle);
222  ecalElectronicsMap_ = elecHandle.product();
223 }
224 
225 // ------------ method called once each job just after ending the event loop ------------
226 void
228 {
229  using namespace std;
230  fileName_ += "-"+intToString(runNum_)+".graph.root";
231 
232  TFile root_file_(fileName_.c_str() , "RECREATE");
233 
234  for(map<int,TH1F*>::const_iterator itr = FEDsAndHists_.begin();
235  itr != FEDsAndHists_.end(); ++itr)
236  {
237  string dir = fedMap_->getSliceFromFed(itr->first);
238  TDirectory* FEDdir = gDirectory->mkdir(dir.c_str());
239  FEDdir->cd();
240 
241  TH1F* hist = itr->second;
242  if(hist!=0)
243  hist->Write();
244  else
245  {
246  cerr << "EcalPedHists: Error: This shouldn't happen!" << endl;
247  }
248  // Write out timing hist
249  hist = FEDsAndTimingHists_[itr->first];
250  if(hist!=0)
251  hist->Write();
252  else
253  {
254  cerr << "EcalPedHists: Error: This shouldn't happen!" << endl;
255  }
256  root_file_.cd();
257  }
258  allFedsHist_->Write();
259  allFedsTimingHist_->Write();
260  root_file_.Close();
261 
262  std::string channels;
263  for(std::vector<int>::const_iterator itr = maskedChannels_.begin();
264  itr != maskedChannels_.end(); ++itr)
265  {
266  channels+=intToString(*itr);
267  channels+=",";
268  }
269 
270  LogWarning("EcalMipGraphs") << "Masked channels are: " << channels << " and that is all!";
271 }
272 
273 
275 {
276  using namespace std;
277  ostringstream myStream;
278  myStream << num << flush;
279  return(myStream.str()); //returns the string form of the stringstream object
280 }
281 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
virtual void endJob()
const EcalElectronicsMapping * ecalElectronicsMap_
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:86
int ic() const
Definition: EEDetId.cc:324
std::string fileName_
virtual void analyze(edm::Event const &, edm::EventSetup const &)
edm::InputTag EBUncalibratedRecHitCollection_
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
std::vector< EcalUncalibratedRecHit >::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:7
std::string getSliceFromFed(int)
Definition: EcalFedMap.cc:93
int hashedIndex(int ieta, int iphi)
Definition: EcalPyUtils.cc:42
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
int iEvent
Definition: GenABIO.cc:230
tuple result
Definition: query.py:137
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:390
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
std::map< int, TH1F * > FEDsAndHists_
EcalURecHitHists(const edm::ParameterSet &)
int hashedIndex() const
Definition: EEDetId.h:182
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
std::vector< int > maskedChannels_
std::map< int, TH1F * > FEDsAndTimingHists_
std::vector< std::string > maskedEBs_
edm::EventID id() const
Definition: EventBase.h:56
std::vector< int > maskedFEDs_
EcalFedMap * fedMap_
std::string intToString(int num)
dbl *** dir
Definition: mlp_gen.cc:35
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
Definition: Run.h:41