CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalMipGraphs.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalMipGraphs
4 // Class: EcalMipGraphs
5 //
13 //
14 // Original Author: Seth COOPER
15 // Created: Th Nov 22 5:46:22 CEST 2007
16 // $Id: EcalMipGraphs.cc,v 1.12 2010/10/20 10:02:00 elmer Exp $
17 //
18 //
19 
22 #include "TCanvas.h"
23 #include <utility>
24 #include <string>
25 #include <vector>
26 
27 using namespace edm;
28 using namespace std;
29 
30 //
31 // constants, enums and typedefs
32 //
33 
34 //
35 // static data member definitions
36 //
37 float EcalMipGraphs::gainRatio[3] = { 1., 2. , 12. };
39 
40 //
41 // constructors and destructor
42 //
44  EBRecHitCollection_ (iConfig.getParameter<edm::InputTag>("EcalRecHitCollectionEB")),
45  EERecHitCollection_ (iConfig.getParameter<edm::InputTag>("EcalRecHitCollectionEE")),
46  EBDigis_ (iConfig.getParameter<edm::InputTag>("EBDigiCollection")),
47  EEDigis_ (iConfig.getParameter<edm::InputTag>("EEDigiCollection")),
48  headerProducer_ (iConfig.getParameter<edm::InputTag> ("headerProducer")),
49  runNum_(-1),
50  side_ (iConfig.getUntrackedParameter<int>("side", 3)),
51  threshold_ (iConfig.getUntrackedParameter<double>("amplitudeThreshold", 12.0)),
52  minTimingAmp_ (iConfig.getUntrackedParameter<double>("minimumTimingAmplitude", 0.100))
53 {
54  vector<int> listDefaults;
55  listDefaults.push_back(-1);
56 
57  maskedChannels_ = iConfig.getUntrackedParameter<vector<int> >("maskedChannels", listDefaults);
58  maskedFEDs_ = iConfig.getUntrackedParameter<vector<int> >("maskedFEDs", listDefaults);
59  seedCrys_ = iConfig.getUntrackedParameter<vector<int> >("seedCrys",vector<int>());
60 
61  vector<string> defaultMaskedEBs;
62  defaultMaskedEBs.push_back("none");
63  maskedEBs_ = iConfig.getUntrackedParameter<vector<string> >("maskedEBs",defaultMaskedEBs);
64 
65  fedMap_ = new EcalFedMap();
66 
67  string title1 = "Jitter for all FEDs";
68  string name1 = "JitterAllFEDs";
69  allFedsTimingHist_ = fileService->make<TH1F>(name1.c_str(),title1.c_str(),150,-7,7);
70 
71  // load up the maskedFED list with the proper FEDids
72  if(maskedFEDs_[0]==-1)
73  {
74  //if "actual" EB id given, then convert to FEDid and put in listFEDs_
75  if(maskedEBs_[0] != "none")
76  {
77  maskedFEDs_.clear();
78  for(vector<string>::const_iterator ebItr = maskedEBs_.begin(); ebItr != maskedEBs_.end(); ++ebItr)
79  {
80  maskedFEDs_.push_back(fedMap_->getFedFromSlice(*ebItr));
81  }
82  }
83  }
84 
85  for (int i=0; i<10; i++)
86  abscissa[i] = i;
87 
88  naiveEvtNum_ = 0;
89 
90 }
91 
92 
94 {
95 }
96 
97 
98 //
99 // member functions
100 //
101 
102 // ------------ method called to for each event ------------
103 void
105 {
106 
107  // get the headers
108  // (one header for each supermodule)
110  iEvent.getByLabel(headerProducer_, DCCHeaders);
111 
112  for (EcalRawDataCollection::const_iterator headerItr= DCCHeaders->begin();
113  headerItr != DCCHeaders->end ();
114  ++headerItr)
115  {
116  FEDsAndDCCHeaders_[headerItr->id()+600] = *headerItr;
117  }
118 
119  int ievt = iEvent.id().event();
120  naiveEvtNum_++;
121 
122  if(runNum_==-1)
123  {
124  runNum_ = iEvent.id().run();
125  canvasNames_ = fileService->make<TTree>("canvasNames","Names of written canvases");
126  names = new std::vector<string>();
127  canvasNames_->Branch("names","vector<string>",&names);
128  }
129 
130  //We only want the 3x3's for this event...
131  listEBChannels.clear();
132  listEEChannels.clear();
135  ESHandle<CaloTopology> caloTopo;
136  iSetup.get<CaloTopologyRecord>().get(caloTopo);
137  iEvent.getByLabel(EBRecHitCollection_, EBhits);
138  iEvent.getByLabel(EERecHitCollection_, EEhits);
139  // Now, retrieve the crystal digi from the event
142  //debug
143  //LogWarning("EcalMipGraphs") << "event " << ievt << " EBhits collection size " << EBhits->size();
144  //LogWarning("EcalMipGraphs") << "event " << ievt << " EEhits collection size " << EEhits->size();
145 
146  selectHits(EBhits, ievt, caloTopo);
147  selectHits(EEhits, ievt, caloTopo);
148 
149 }
150 
151 
152 TGraph* EcalMipGraphs::selectDigi(DetId thisDet, int ievt)
153 {
154  int emptyY[10];
155  for (int i=0; i<10; i++)
156  emptyY[i] = 0;
157  TGraph* emptyGraph = fileService->make<TGraph>(10, abscissa, emptyY);
158  emptyGraph->SetTitle("NOT ECAL");
159 
160  //If the DetId is not from Ecal, return
161  if(thisDet.det() != DetId::Ecal)
162  return emptyGraph;
163 
164  emptyGraph->SetTitle("NO DIGIS");
165  //find digi we need -- can't get find() to work; need DataFrame(DetId det) to work?
167  int FEDid = 600+elecId.dccId();
168  bool isBarrel = true;
169  if(FEDid < 610 || FEDid > 645)
170  isBarrel = false;
171  int cryIndex = isBarrel ? ((EBDetId)thisDet).hashedIndex() : getEEIndex(elecId);
172  int ic = isBarrel ? ((EBDetId)thisDet).ic() : cryIndex;
173 
174  string sliceName = fedMap_->getSliceFromFed(FEDid);
175  EcalDataFrame df;
176  if(isBarrel)
177  {
179  while(digiItr != EBdigisHandle->end() && ((*digiItr).id() != (EBDetId)thisDet))
180  {
181  ++digiItr;
182  }
183  if(digiItr==EBdigisHandle->end())
184  {
185  //LogWarning("EcalMipGraphs") << "Cannot find digi for ic:" << ic
186  // << " FED:" << FEDid << " evt:" << naiveEvtNum_;
187  return emptyGraph;
188  }
189  else
190  df = *digiItr;
191  }
192  else
193  {
195  while(digiItr != EEdigisHandle->end() && ((*digiItr).id() != (EEDetId)thisDet))
196  {
197  ++digiItr;
198  }
199  if(digiItr==EEdigisHandle->end())
200  {
201  //LogWarning("EcalMipGraphs") << "Cannot find digi for ic:" << ic
202  // << " FED:" << FEDid << " evt:" << naiveEvtNum_;
203  return emptyGraph;
204  }
205  else df = *digiItr;
206  }
207 
208  int gainId = FEDsAndDCCHeaders_[FEDid].getMgpaGain();
209  int gainHuman;
210  if (gainId ==1) gainHuman =12;
211  else if (gainId ==2) gainHuman =6;
212  else if (gainId ==3) gainHuman =1;
213  else gainHuman =-1;
214 
215  double pedestal = 200;
216 
217  emptyGraph->SetTitle("FIRST TWO SAMPLES NOT GAIN12");
218  if(df.sample(0).gainId()!=1 || df.sample(1).gainId()!=1) return emptyGraph; //goes to the next digi
219  else {
220  ordinate[0] = df.sample(0).adc();
221  ordinate[1] = df.sample(1).adc();
222  pedestal = (double)(ordinate[0]+ordinate[1])/(double)2;
223  }
224 
225 
226  for (int i=0; i < df.size(); ++i ) {
227  if (df.sample(i).gainId() != 0)
228  ordinate[i] = (int)(pedestal+(df.sample(i).adc()-pedestal)*gainRatio[df.sample(i).gainId()-1]);
229  else
230  ordinate[i] = 49152; //Saturation of gain1
231  }
232 
233  TGraph* oneGraph = fileService->make<TGraph>(10, abscissa, ordinate);
234  string name = "Graph_ev" + intToString(naiveEvtNum_) + "_ic" + intToString(ic)
235  + "_FED" + intToString(FEDid);
236  string gainString = (gainId==1) ? "Free" : intToString(gainHuman);
237  string title = "Event" + intToString(naiveEvtNum_) + "_lv1a" + intToString(ievt) +
238  "_ic" + intToString(ic) + "_" + sliceName + "_gain" + gainString;
239 
240  float energy = 0;
241  map<int,float>::const_iterator itr;
242  itr = crysAndAmplitudesMap_.find(cryIndex);
243  if(itr!=crysAndAmplitudesMap_.end())
244  {
245  //edm::LogWarning("EcalMipGraphs")<< "itr->second(ampli)="<< itr->second;
246  energy = (float) itr->second;
247  }
248  //else
249  //edm::LogWarning("EcalMipGraphs") << "cry " << ic << "not found in ampMap";
250 
251  title+="_Energy"+floatToString(round(energy*1000));
252 
253  oneGraph->SetTitle(title.c_str());
254  oneGraph->SetName(name.c_str());
255  oneGraph->GetXaxis()->SetTitle("sample");
256  oneGraph->GetYaxis()->SetTitle("ADC");
257  return oneGraph;
258 }
259 
261  int ievt, ESHandle<CaloTopology> caloTopo)
262 {
263  for (EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr)
264  {
265  EcalRecHit hit = (*hitItr);
266  DetId det = hit.id();
268  int FEDid = 600+elecId.dccId();
269  bool isBarrel = true;
270  if(FEDid < 610 || FEDid > 645)
271  isBarrel = false;
272  int cryIndex = isBarrel ? ((EBDetId)det).hashedIndex() : ((EEDetId)det).hashedIndex();
273  int ic = isBarrel ? ((EBDetId)det).ic() : getEEIndex(elecId);
274 
275  float ampli = hit.energy();
276 
277  vector<int>::iterator result;
278  result = find(maskedFEDs_.begin(), maskedFEDs_.end(), FEDid);
279  if(result != maskedFEDs_.end())
280  {
281  //LogWarning("EcalMipGraphs") << "skipping uncalRecHit for FED " << FEDid << " ; amplitude " << ampli;
282  continue;
283  }
284  result = find(maskedChannels_.begin(), maskedChannels_.end(), cryIndex);
285  if (result != maskedChannels_.end())
286  {
287  //LogWarning("EcalMipGraphs") << "skipping uncalRecHit for channel: " << cryIndex << " in fed: " << FEDid << " with amplitude " << ampli ;
288  continue;
289  }
290  bool cryIsInList = false;
291  result = find(seedCrys_.begin(), seedCrys_.end(), cryIndex);
292  if (result != seedCrys_.end())
293  cryIsInList = true;
294 
295  // Either we must have a user-requested cry (in which case there is no amplitude selection)
296  // Or we pick all crys that pass the amplitude cut (in which case there is no fixed crystal selection)
297  if(cryIsInList || (seedCrys_.empty() && ampli > threshold_))
298  {
299  // We have a winner!
300  crysAndAmplitudesMap_[cryIndex] = ampli;
301  string name = "Event" + intToString(naiveEvtNum_) + "_ic" + intToString(ic)
302  + "_FED" + intToString(FEDid);
303  string title = "Digis";
304  string seed = "ic" + intToString(ic) + "_FED" + intToString(FEDid);
305  int freq=1;
306  pair<map<string,int>::iterator,bool> pair = seedFrequencyMap_.insert(make_pair(seed,freq));
307  if(!pair.second)
308  {
309  ++(pair.first->second);
310  }
311 
312  TCanvas can(name.c_str(),title.c_str(),200,50,900,900);
313  can.Divide(side_,side_);
314  TGraph* myGraph;
315  int canvasNum = 1;
316 
317  CaloNavigator<DetId> cursor = CaloNavigator<DetId>(det,caloTopo->getSubdetectorTopology(det));
318  //Now put each graph in one by one
319  for(int j=side_/2; j>=-side_/2; --j)
320  {
321  for(int i=-side_/2; i<=side_/2; ++i)
322  {
323  cursor.home();
324  cursor.offsetBy(i,j);
325  can.cd(canvasNum);
326  myGraph = selectDigi(*cursor,ievt);
327  myGraph->Draw("A*");
328  canvasNum++;
329  }
330  }
331  can.Write();
332  names->push_back(name);
333  }
334 
335  TH1F* timingHist = FEDsAndTimingHists_[FEDid];
336  if(timingHist==0)
337  {
338  initHists(FEDid);
339  timingHist = FEDsAndTimingHists_[FEDid];
340  }
341  if(ampli > minTimingAmp_)
342  {
343  timingHist->Fill(hit.time());
344  allFedsTimingHist_->Fill(hit.time());
345  }
346  }
347 }
348 
350 {
351  int FEDid = 600+elecId.dccId();
352  return 10000*FEDid+100*elecId.towerId()+5*(elecId.stripId()-1)+elecId.xtalId();
353 }
354 
355 // insert the hist map into the map keyed by FED number
357 {
358  using namespace std;
359 
360  string title1 = "Jitter for ";
361  title1.append(fedMap_->getSliceFromFed(FED));
362  string name1 = "JitterFED";
363  name1.append(intToString(FED));
364  TH1F* timingHist = fileService->make<TH1F>(name1.c_str(),title1.c_str(),150,-7,7);
365  FEDsAndTimingHists_[FED] = timingHist;
366 }
367 
368 // ------------ method called once each job just before starting event loop ------------
369 void
371 {
373  c.get< EcalMappingRcd >().get(handle);
374  ecalElectronicsMap_ = handle.product();
375 }
376 
377 // ------------ method called once each job just after ending the event loop ------------
378 void
380 {
381  canvasNames_->Fill();
382 
383  string frequencies = "";
384  for(std::map<std::string,int>::const_iterator itr = seedFrequencyMap_.begin();
385  itr != seedFrequencyMap_.end(); ++itr)
386  {
387  if(itr->second > 1)
388  {
389  frequencies+=itr->first;
390  frequencies+=" Frequency: ";
391  frequencies+=intToString(itr->second);
392  frequencies+="\n";
393  }
394  }
395  LogWarning("EcalMipGraphs") << "Found seeds with frequency > 1: " << "\n\n" << frequencies;
396 
397  std::string channels;
398  for(std::vector<int>::const_iterator itr = maskedChannels_.begin();
399  itr != maskedChannels_.end(); ++itr)
400  {
401  channels+=intToString(*itr);
402  channels+=",";
403  }
404 
405  std::string feds;
406  for(std::vector<int>::const_iterator itr = maskedFEDs_.begin();
407  itr != maskedFEDs_.end(); ++itr)
408  {
409  feds+=intToString(*itr);
410  feds+=",";
411  }
412 
413  LogWarning("EcalMipGraphs") << "Masked channels are: " << channels;
414  LogWarning("EcalMipGraphs") << "Masked FEDs are: " << feds << " and that is all!";
415 }
416 
417 
419 {
420  using namespace std;
421  ostringstream myStream;
422  myStream << num << flush;
423  return(myStream.str()); //returns the string form of the stringstream object
424 }
425 
427 {
428  using namespace std;
429  ostringstream myStream;
430  myStream << num << flush;
431  return(myStream.str()); //returns the string form of the stringstream object
432 }
RunNumber_t run() const
Definition: EventID.h:42
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::string floatToString(float num)
std::vector< int > maskedFEDs_
int xtalId() const
get the channel id
int getEEIndex(EcalElectronicsId elecId)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
void initHists(int)
void home() const
move the navigator back to the starting point
edm::InputTag headerProducer_
Definition: EcalMipGraphs.h:87
int gainId(sample_type sample)
get the gainId (2 bits)
virtual void analyze(edm::Event const &, edm::EventSetup const &)
int stripId() const
get the tower id
EcalFedMap * fedMap_
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
std::map< int, EcalDCCHeaderBlock > FEDsAndDCCHeaders_
std::vector< T >::const_iterator const_iterator
std::string intToString(int num)
edm::InputTag EERecHitCollection_
Definition: EcalMipGraphs.h:84
std::vector< std::string > maskedEBs_
TTree * canvasNames_
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:30
int towerId() const
get the tower id
const EcalElectronicsMapping * ecalElectronicsMap_
static edm::Service< TFileService > fileService
int abscissa[10]
float time() const
Definition: CaloRecHit.h:21
std::map< int, float > crysAndAmplitudesMap_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int gainId() const
get the gainId (2 bits)
edm::InputTag EEDigis_
Definition: EcalMipGraphs.h:86
int size() const
Definition: EcalDataFrame.h:27
std::set< EEDetId > listEEChannels
Definition: EcalMipGraphs.h:98
double threshold_
Definition: EcalMipGraphs.h:94
std::string getSliceFromFed(int)
Definition: EcalFedMap.cc:93
EcalMipGraphs(const edm::ParameterSet &)
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
std::set< EBDetId > listEBChannels
Definition: EcalMipGraphs.h:97
int iEvent
Definition: GenABIO.cc:243
void selectHits(edm::Handle< EcalRecHitCollection > hits, int ievt, edm::ESHandle< CaloTopology > caloTopo)
float energy() const
Definition: CaloRecHit.h:19
edm::InputTag EBRecHitCollection_
Definition: EcalMipGraphs.h:83
virtual T offsetBy(int deltaX, int deltaY) const
Free movement of arbitray steps.
tuple result
Definition: query.py:137
std::map< int, TH1F * > FEDsAndTimingHists_
int ordinate[10]
tuple handle
Definition: patZpeak.py:22
int j
Definition: DBlmapReader.cc:9
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
TGraph * selectDigi(DetId det, int ievt)
Definition: DetId.h:20
std::vector< int > seedCrys_
std::vector< int > maskedChannels_
DetId id() const
get the id
Definition: EcalRecHit.h:76
edm::Handle< EEDigiCollection > EEdigisHandle
Definition: EcalMipGraphs.h:90
std::vector< std::string > * names
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
long long int num
Definition: procUtils.cc:71
edm::EventID id() const
Definition: EventBase.h:56
double minTimingAmp_
Definition: EcalMipGraphs.h:95
T * make() const
make new ROOT object
virtual void endJob()
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
static float gainRatio[3]
TH1F * allFedsTimingHist_
std::map< std::string, int > seedFrequencyMap_
edm::Handle< EBDigiCollection > EBdigisHandle
Definition: EcalMipGraphs.h:89
Definition: Run.h:33
int adc() const
get the ADC sample (12 bits)
edm::InputTag EBDigis_
Definition: EcalMipGraphs.h:85