CMS 3D CMS Logo

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