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