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 // $Id: EcalURecHitHists.cc,v 1.5 2010/01/04 15:07:40 ferriff Exp $
17 //
18 //
19 
21 
22 using namespace cms;
23 using namespace edm;
24 using namespace std;
25 
26 //
27 // constants, enums and typedefs
28 //
29 
30 //
31 // static data member definitions
32 //
33 
34 //
35 // constructors and destructor
36 //
38  EBUncalibratedRecHitCollection_ (iConfig.getParameter<edm::InputTag>("EBUncalibratedRecHitCollection")),
39  EEUncalibratedRecHitCollection_ (iConfig.getParameter<edm::InputTag>("EEUncalibratedRecHitCollection")),
40  runNum_(-1),
41  histRangeMax_ (iConfig.getUntrackedParameter<double>("histogramMaxRange",200.0)),
42  histRangeMin_ (iConfig.getUntrackedParameter<double>("histogramMinRange",-10.0)),
43  fileName_ (iConfig.getUntrackedParameter<std::string>("fileName", std::string("ecalURechHitHists")))
44 {
45  vector<int> listDefaults;
46  listDefaults.push_back(-1);
47 
48  maskedChannels_ = iConfig.getUntrackedParameter<vector<int> >("maskedChannels", listDefaults);
49  maskedFEDs_ = iConfig.getUntrackedParameter<vector<int> >("maskedFEDs", listDefaults);
50 
51  vector<string> defaultMaskedEBs;
52  defaultMaskedEBs.push_back("none");
53  maskedEBs_ = iConfig.getUntrackedParameter<vector<string> >("maskedEBs",defaultMaskedEBs);
54 
55  fedMap_ = new EcalFedMap();
56  string title1 = "Uncalib Rec Hits (ADC counts)";
57  string name1 = "URecHitsAllFEDs";
58  int numBins = (int)round(histRangeMax_-histRangeMin_)+1;
59  allFedsHist_ = new TH1F(name1.c_str(),title1.c_str(),numBins,histRangeMin_,histRangeMax_);
60  title1 = "Jitter for all FEDs";
61  name1 = "JitterAllFEDs";
62  allFedsTimingHist_ = new TH1F(name1.c_str(),title1.c_str(),14,-7,7);
63 
64  // load up the maskedFED list with the proper FEDids
65  if(maskedFEDs_[0]==-1)
66  {
67  //if "actual" EB id given, then convert to FEDid and put in listFEDs_
68  if(maskedEBs_[0] != "none")
69  {
70  maskedFEDs_.clear();
71  for(vector<string>::const_iterator ebItr = maskedEBs_.begin(); ebItr != maskedEBs_.end(); ++ebItr)
72  {
73  maskedFEDs_.push_back(fedMap_->getFedFromSlice(*ebItr));
74  }
75  }
76  }
77 }
78 
79 
81 {
82 }
83 
84 
85 //
86 // member functions
87 //
88 
89 // ------------ method called to for each event ------------
90 void
92 {
93  int ievt = iEvent.id().event();
96 
98  LogDebug("EcalURecHitHists") << "event " << ievt << " hits collection size " << EBhits->size();
99 
101  LogDebug("EcalURecHitHists") << "event " << ievt << " hits collection size " << EEhits->size();
102 
103  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EBhits->begin(); hitItr != EBhits->end(); ++hitItr)
104  {
105  EcalUncalibratedRecHit hit = (*hitItr);
106  EBDetId ebDet = hit.id();
107  int ic = ebDet.ic();
108  int hashedIndex = ebDet.hashedIndex();
110  int FEDid = 600+elecId.dccId();
111  float ampli = hit.amplitude();
112 
113  vector<int>::iterator result;
114  result = find(maskedFEDs_.begin(), maskedFEDs_.end(), FEDid);
115  if(result != maskedFEDs_.end())
116  {
117  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for FED " << FEDid << " ; amplitude " << ampli;
118  continue;
119  }
120 
121  result = find(maskedChannels_.begin(), maskedChannels_.end(), hashedIndex);
122  if (result != maskedChannels_.end())
123  {
124  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for channel: " << ic << " with amplitude " << ampli ;
125  continue;
126  }
127 
128  // fill the proper hist
129  TH1F* uRecHist = FEDsAndHists_[FEDid];
130  TH1F* timingHist = FEDsAndTimingHists_[FEDid];
131  if(uRecHist==0)
132  {
133  initHists(FEDid);
134  uRecHist = FEDsAndHists_[FEDid];
135  timingHist = FEDsAndTimingHists_[FEDid];
136  }
137 
138  uRecHist->Fill(ampli);
139  allFedsHist_->Fill(ampli);
140  timingHist->Fill(hit.jitter());
141  allFedsTimingHist_->Fill(hit.jitter());
142  }
143 
144  // Again for the endcap
145  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EEhits->begin(); hitItr != EEhits->end(); ++hitItr)
146  {
147  EcalUncalibratedRecHit hit = (*hitItr);
148  EEDetId eeDet = hit.id();
149  int ic = eeDet.ic();
150  int hashedIndex = eeDet.hashedIndex();
152  int FEDid = 600+elecId.dccId();
153  float ampli = hit.amplitude();
154 
155  vector<int>::iterator result;
156  result = find(maskedFEDs_.begin(), maskedFEDs_.end(), FEDid);
157  if(result != maskedFEDs_.end())
158  {
159  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for FED " << FEDid << " ; amplitude " << ampli;
160  continue;
161  }
162 
163  result = find(maskedChannels_.begin(), maskedChannels_.end(), hashedIndex);
164  if (result != maskedChannels_.end())
165  {
166  LogWarning("EcalURecHitHists") << "skipping uncalRecHit for channel: " << ic << " with amplitude " << ampli ;
167  continue;
168  }
169 
170  // fill the proper hist
171  TH1F* uRecHist = FEDsAndHists_[FEDid];
172  TH1F* timingHist = FEDsAndTimingHists_[FEDid];
173  if(uRecHist==0)
174  {
175  initHists(FEDid);
176  uRecHist = FEDsAndHists_[FEDid];
177  timingHist = FEDsAndTimingHists_[FEDid];
178  }
179 
180  uRecHist->Fill(ampli);
181  allFedsHist_->Fill(ampli);
182  timingHist->Fill(hit.jitter());
183  allFedsTimingHist_->Fill(hit.jitter());
184  }
185 
186  if(runNum_==-1)
187  {
188  runNum_ = iEvent.id().run();
189  }
190 }
191 
192 
193 // insert the hist map into the map keyed by FED number
195 {
196  using namespace std;
197 
198  string FEDid = intToString(FED);
199  string title1 = "Uncalib Rec Hits (ADC counts) for ";
200  title1.append(fedMap_->getSliceFromFed(FED));
201  string name1 = "URecHitsFED";
202  name1.append(intToString(FED));
203  int numBins = (int)round(histRangeMax_-histRangeMin_)+1;
204  TH1F* hist = new TH1F(name1.c_str(),title1.c_str(), numBins, histRangeMin_, histRangeMax_);
205  FEDsAndHists_[FED] = hist;
206  FEDsAndHists_[FED]->SetDirectory(0);
207 
208  title1 = "Jitter for ";
209  title1.append(fedMap_->getSliceFromFed(FED));
210  name1 = "JitterFED";
211  name1.append(intToString(FED));
212  TH1F* timingHist = new TH1F(name1.c_str(),title1.c_str(),14,-7,7);
213  FEDsAndTimingHists_[FED] = timingHist;
214  FEDsAndTimingHists_[FED]->SetDirectory(0);
215 }
216 
217 // ------------ method called once each job just before starting event loop ------------
218 void
220 {
222  c.get<EcalMappingRcd>().get(elecHandle);
223  ecalElectronicsMap_ = elecHandle.product();
224 }
225 
226 // ------------ method called once each job just after ending the event loop ------------
227 void
229 {
230  using namespace std;
231  fileName_ += "-"+intToString(runNum_)+".graph.root";
232 
233  TFile root_file_(fileName_.c_str() , "RECREATE");
234 
235  for(map<int,TH1F*>::const_iterator itr = FEDsAndHists_.begin();
236  itr != FEDsAndHists_.end(); ++itr)
237  {
238  string dir = fedMap_->getSliceFromFed(itr->first);
239  TDirectory* FEDdir = gDirectory->mkdir(dir.c_str());
240  FEDdir->cd();
241 
242  TH1F* hist = itr->second;
243  if(hist!=0)
244  hist->Write();
245  else
246  {
247  cerr << "EcalPedHists: Error: This shouldn't happen!" << endl;
248  }
249  // Write out timing hist
250  hist = FEDsAndTimingHists_[itr->first];
251  if(hist!=0)
252  hist->Write();
253  else
254  {
255  cerr << "EcalPedHists: Error: This shouldn't happen!" << endl;
256  }
257  root_file_.cd();
258  }
259  allFedsHist_->Write();
260  allFedsTimingHist_->Write();
261  root_file_.Close();
262 
263  std::string channels;
264  for(std::vector<int>::const_iterator itr = maskedChannels_.begin();
265  itr != maskedChannels_.end(); ++itr)
266  {
267  channels+=intToString(*itr);
268  channels+=",";
269  }
270 
271  LogWarning("EcalMipGraphs") << "Masked channels are: " << channels << " and that is all!";
272 }
273 
274 
276 {
277  using namespace std;
278  ostringstream myStream;
279  myStream << num << flush;
280  return(myStream.str()); //returns the string form of the stringstream object
281 }
282 
#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:73
int ic() const
Definition: EEDetId.cc:340
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< 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: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:243
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:356
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:94
std::map< int, TH1F * > FEDsAndHists_
EcalURecHitHists(const edm::ParameterSet &)
int hashedIndex() const
Definition: EEDetId.h:177
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
long long int num
Definition: procUtils.cc:71
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:33