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