CMS 3D CMS Logo

EcalPulseShapeGrapher.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalPulseShapeGrapher
4 // Class: EcalPulseShapeGrapher
5 //
13 //
14 // Original Author: Seth Cooper
15 // Created: Tue Feb 5 11:35:45 CST 2008
16 //
17 //
18 
20 
21 //
22 // constants, enums and typedefs
23 //
24 
25 //
26 // static data member definitions
27 //
28 
29 //
30 // constructors and destructor
31 //
33  : EBUncalibratedRecHitCollection_(consumes<EcalUncalibratedRecHitCollection>(
34  iConfig.getParameter<edm::InputTag>("EBUncalibratedRecHitCollection"))),
35  EBDigis_(consumes<EBDigiCollection>(iConfig.getParameter<edm::InputTag>("EBDigiCollection"))),
36  EEUncalibratedRecHitCollection_(consumes<EcalUncalibratedRecHitCollection>(
37  iConfig.getParameter<edm::InputTag>("EEUncalibratedRecHitCollection"))),
38  EEDigis_(consumes<EEDigiCollection>(iConfig.getParameter<edm::InputTag>("EEDigiCollection"))),
39  ampCut_(iConfig.getUntrackedParameter<int>("AmplitudeCutADC", 13)),
40  rootFilename_(iConfig.getUntrackedParameter<std::string>("rootFilename", "pulseShapeGrapher")) {
41  //now do what ever initialization is needed
42 
43  std::vector<int> listDefaults;
44  listDefaults.push_back(-1);
45  listChannels_ = iConfig.getUntrackedParameter<std::vector<int> >("listChannels", listDefaults);
46 
47  for (std::vector<int>::const_iterator itr = listChannels_.begin(); itr != listChannels_.end(); ++itr) {
48  std::string title = "Amplitude of cry " + intToString(*itr);
49  std::string name = "ampOfCry" + intToString(*itr);
50  ampHistMap_[*itr] = new TH1F(name.c_str(), title.c_str(), 100, 0, 100);
51  ampHistMap_[*itr]->GetXaxis()->SetTitle("ADC");
52 
53  title = "Amplitude (over 13 ADC) of cry " + intToString(*itr);
54  name = "cutAmpOfCry" + intToString(*itr);
55  cutAmpHistMap_[*itr] = new TH1F(name.c_str(), title.c_str(), 100, 0, 100);
56  cutAmpHistMap_[*itr]->GetXaxis()->SetTitle("ADC");
57 
58  title = "Pulse shape of cry " + intToString(*itr);
59  name = "PulseShapeCry" + intToString(*itr);
60  pulseShapeHistMap_[*itr] = new TH2F(name.c_str(), title.c_str(), 10, 0, 10, 220, -20, 2);
61  pulseShapeHistMap_[*itr]->GetXaxis()->SetTitle("sample");
62 
63  title = "Raw Pulse shape of cry " + intToString(*itr);
64  name = "RawPulseShapeCry" + intToString(*itr);
65  rawPulseShapeHistMap_[*itr] = new TH2F(name.c_str(), title.c_str(), 10, 0, 10, 500, 0, 500);
66  rawPulseShapeHistMap_[*itr]->GetXaxis()->SetTitle("sample");
67 
68  title = "Amplitude of first sample, cry " + intToString(*itr);
69  name = "AmpOfFirstSampleCry" + intToString(*itr);
70  firstSampleHistMap_[*itr] = new TH1F(name.c_str(), title.c_str(), 300, 100, 400);
71  firstSampleHistMap_[*itr]->GetXaxis()->SetTitle("ADC");
72  }
73 
74  fedMap_ = new EcalFedMap();
75 
76  for (int i = 0; i < 10; i++)
77  abscissa[i] = i;
78 }
79 
80 //
81 // member functions
82 //
83 
84 // ------------ method called to for each event ------------
86  using namespace edm;
87  using namespace std;
88 
89  int numHitsWithActivity = 0;
90 
93  const Handle<EBDigiCollection>& EBdigis = iEvent.getHandle(EBDigis_);
94  const Handle<EEDigiCollection>& EEdigis = iEvent.getHandle(EEDigis_);
95 
96  unique_ptr<EcalElectronicsMapping> ecalElectronicsMap(new EcalElectronicsMapping);
97 
98  // Loop over the hits
99  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EBHits->begin(); hitItr != EBHits->end(); ++hitItr) {
100  EcalUncalibratedRecHit hit = (*hitItr);
101  float amplitude = hit.amplitude();
102  EBDetId hitDetId = hit.id();
103 
104  // Get the Fedid
105  EcalElectronicsId elecId = ecalElectronicsMap->getElectronicsId(hitDetId);
106  int FEDid = 600 + elecId.dccId();
107  string SMname = fedMap_->getSliceFromFed(FEDid);
108 
109  vector<int>::const_iterator itr = listChannels_.begin();
110  while (itr != listChannels_.end() && (*itr) != hitDetId.hashedIndex()) {
111  itr++;
112  }
113  if (itr == listChannels_.end())
114  continue;
115 
116  ampHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
117  if (amplitude < ampCut_)
118  continue;
119 
120  cutAmpHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
121  numHitsWithActivity++;
122  EBDigiCollection::const_iterator digiItr = EBdigis->begin();
123  while (digiItr != EBdigis->end() && digiItr->id() != hitItr->id()) {
124  digiItr++;
125  }
126  if (digiItr == EBdigis->end())
127  continue;
128 
129  double sampleADC[10];
130  EBDataFrame df(*digiItr);
131  double pedestal = 200;
132 
133  if (df.sample(0).gainId() != 1 || df.sample(1).gainId() != 1)
134  continue; //goes to the next digi
135  else {
136  sampleADC[0] = df.sample(0).adc();
137  sampleADC[1] = df.sample(1).adc();
138  pedestal = (double)(sampleADC[0] + sampleADC[1]) / (double)2;
139  }
140 
141  for (int i = 0; (unsigned int)i < digiItr->size(); ++i) {
142  EBDataFrame df(*digiItr);
143  double gain = 12.;
144  if (df.sample(i).gainId() == 1)
145  gain = 1.;
146  else if (df.sample(i).gainId() == 2)
147  gain = 2.;
148  sampleADC[i] = pedestal + (df.sample(i).adc() - pedestal) * gain;
149  }
150 
151  for (int i = 0; i < 10; ++i) {
152  pulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i] - pedestal) / amplitude);
153  rawPulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]));
154  }
155  firstSampleHistMap_[hitDetId.hashedIndex()]->Fill(sampleADC[0]);
156  }
157 
158  // Now do the same for the EE hits
159  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EEHits->begin(); hitItr != EEHits->end(); ++hitItr) {
160  EcalUncalibratedRecHit hit = (*hitItr);
161  float amplitude = hit.amplitude();
162  EEDetId hitDetId = hit.id();
163 
164  // Get the Fedid
165  EcalElectronicsId elecId = ecalElectronicsMap->getElectronicsId(hitDetId);
166  int FEDid = 600 + elecId.dccId();
167  string SMname = fedMap_->getSliceFromFed(FEDid);
168 
169  vector<int>::const_iterator itr = listChannels_.begin();
170  while (itr != listChannels_.end() && (*itr) != hitDetId.hashedIndex()) {
171  itr++;
172  }
173  if (itr == listChannels_.end())
174  continue;
175 
176  ampHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
177  if (amplitude < ampCut_)
178  continue;
179 
180  cutAmpHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
181  numHitsWithActivity++;
182  EEDigiCollection::const_iterator digiItr = EEdigis->begin();
183  while (digiItr != EEdigis->end() && digiItr->id() != hitItr->id()) {
184  digiItr++;
185  }
186  if (digiItr == EEdigis->end())
187  continue;
188 
189  double sampleADC[10];
190  EEDataFrame df(*digiItr);
191  double pedestal = 200;
192 
193  if (df.sample(0).gainId() != 1 || df.sample(1).gainId() != 1)
194  continue; //goes to the next digi
195  else {
196  sampleADC[0] = df.sample(0).adc();
197  sampleADC[1] = df.sample(1).adc();
198  pedestal = (double)(sampleADC[0] + sampleADC[1]) / (double)2;
199  }
200 
201  for (int i = 0; (unsigned int)i < digiItr->size(); ++i) {
202  EEDataFrame df(*digiItr);
203  double gain = 12.;
204  if (df.sample(i).gainId() == 1)
205  gain = 1.;
206  else if (df.sample(i).gainId() == 2)
207  gain = 2.;
208  sampleADC[i] = pedestal + (df.sample(i).adc() - pedestal) * gain;
209  }
210 
211  for (int i = 0; i < 10; ++i) {
212  pulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i] - pedestal) / amplitude);
213  rawPulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]));
214  }
215  firstSampleHistMap_[hitDetId.hashedIndex()]->Fill(sampleADC[0]);
216  }
217 }
218 
219 // ------------ method called once each job just after ending the event loop ------------
221  rootFilename_ += ".root";
222  file_ = new TFile(rootFilename_.c_str(), "RECREATE");
223  TH1::AddDirectory(false);
224 
225  for (std::vector<int>::const_iterator itr = listChannels_.begin(); itr != listChannels_.end(); ++itr) {
226  ampHistMap_[*itr]->Write();
227  cutAmpHistMap_[*itr]->Write();
228  firstSampleHistMap_[*itr]->Write();
229 
230  rawPulseShapeHistMap_[*itr]->Write();
231  TProfile* t2 = (TProfile*)(rawPulseShapeHistMap_[*itr]->ProfileX());
232  t2->Write();
233  //TODO: fix the normalization so these are correct
234  }
235 
236  file_->Write();
237  file_->Close();
238 }
239 
241  using namespace std;
242  ostringstream myStream;
243  myStream << num << flush;
244  return (myStream.str()); //returns the string form of the stringstream object
245 }
size
Write out results.
std::map< int, TH1F * > ampHistMap_
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
std::vector< T >::const_iterator const_iterator
std::map< int, TH1F * > cutAmpHistMap_
EcalPulseShapeGrapher(const edm::ParameterSet &)
std::string getSliceFromFed(int)
Definition: EcalFedMap.cc:86
T getUntrackedParameter(std::string const &, T const &) const
std::vector< int > listChannels_
int iEvent
Definition: GenABIO.cc:224
const_iterator begin() const
const edm::EDGetTokenT< EcalUncalibratedRecHitCollection > EEUncalibratedRecHitCollection_
const edm::EDGetTokenT< EEDigiCollection > EEDigis_
std::map< int, TH1F * > firstSampleHistMap_
const_iterator end() const
unsigned int id
const_iterator end() const
std::map< int, TH2F * > pulseShapeHistMap_
const_iterator begin() const
The iterator returned can not safely be used across threads.
std::map< int, TH2F * > rawPulseShapeHistMap_
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
HLT enums.
const edm::EDGetTokenT< EcalUncalibratedRecHitCollection > EBUncalibratedRecHitCollection_
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:82
int hashedIndex() const
Definition: EEDetId.h:183
void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< EBDigiCollection > EBDigis_