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 
91  const Handle<EBDigiCollection>& EBdigis = iEvent.getHandle(EBDigis_);
92  const Handle<EEDigiCollection>& EEdigis = iEvent.getHandle(EEDigis_);
93 
94  unique_ptr<EcalElectronicsMapping> ecalElectronicsMap(new EcalElectronicsMapping);
95 
96  // Loop over the hits
97  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EBHits->begin(); hitItr != EBHits->end(); ++hitItr) {
98  EcalUncalibratedRecHit hit = (*hitItr);
99  float amplitude = hit.amplitude();
100  EBDetId hitDetId = hit.id();
101 
102  // Get the Fedid
103  EcalElectronicsId elecId = ecalElectronicsMap->getElectronicsId(hitDetId);
104  int FEDid = 600 + elecId.dccId();
105  string SMname = fedMap_->getSliceFromFed(FEDid);
106 
107  vector<int>::const_iterator itr = listChannels_.begin();
108  while (itr != listChannels_.end() && (*itr) != hitDetId.hashedIndex()) {
109  itr++;
110  }
111  if (itr == listChannels_.end())
112  continue;
113 
114  ampHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
115  if (amplitude < ampCut_)
116  continue;
117 
118  cutAmpHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
119  EBDigiCollection::const_iterator digiItr = EBdigis->begin();
120  while (digiItr != EBdigis->end() && digiItr->id() != hitItr->id()) {
121  digiItr++;
122  }
123  if (digiItr == EBdigis->end())
124  continue;
125 
126  double sampleADC[10];
127  EBDataFrame df(*digiItr);
128  double pedestal = 200;
129 
130  if (df.sample(0).gainId() != 1 || df.sample(1).gainId() != 1)
131  continue; //goes to the next digi
132  else {
133  sampleADC[0] = df.sample(0).adc();
134  sampleADC[1] = df.sample(1).adc();
135  pedestal = (double)(sampleADC[0] + sampleADC[1]) / (double)2;
136  }
137 
138  for (int i = 0; (unsigned int)i < digiItr->size(); ++i) {
139  EBDataFrame df(*digiItr);
140  double gain = 12.;
141  if (df.sample(i).gainId() == 1)
142  gain = 1.;
143  else if (df.sample(i).gainId() == 2)
144  gain = 2.;
145  sampleADC[i] = pedestal + (df.sample(i).adc() - pedestal) * gain;
146  }
147 
148  for (int i = 0; i < 10; ++i) {
149  pulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i] - pedestal) / amplitude);
150  rawPulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]));
151  }
152  firstSampleHistMap_[hitDetId.hashedIndex()]->Fill(sampleADC[0]);
153  }
154 
155  // Now do the same for the EE hits
156  for (EcalUncalibratedRecHitCollection::const_iterator hitItr = EEHits->begin(); hitItr != EEHits->end(); ++hitItr) {
157  EcalUncalibratedRecHit hit = (*hitItr);
158  float amplitude = hit.amplitude();
159  EEDetId hitDetId = hit.id();
160 
161  // Get the Fedid
162  EcalElectronicsId elecId = ecalElectronicsMap->getElectronicsId(hitDetId);
163  int FEDid = 600 + elecId.dccId();
164  string SMname = fedMap_->getSliceFromFed(FEDid);
165 
166  vector<int>::const_iterator itr = listChannels_.begin();
167  while (itr != listChannels_.end() && (*itr) != hitDetId.hashedIndex()) {
168  itr++;
169  }
170  if (itr == listChannels_.end())
171  continue;
172 
173  ampHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
174  if (amplitude < ampCut_)
175  continue;
176 
177  cutAmpHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
178  EEDigiCollection::const_iterator digiItr = EEdigis->begin();
179  while (digiItr != EEdigis->end() && digiItr->id() != hitItr->id()) {
180  digiItr++;
181  }
182  if (digiItr == EEdigis->end())
183  continue;
184 
185  double sampleADC[10];
186  EEDataFrame df(*digiItr);
187  double pedestal = 200;
188 
189  if (df.sample(0).gainId() != 1 || df.sample(1).gainId() != 1)
190  continue; //goes to the next digi
191  else {
192  sampleADC[0] = df.sample(0).adc();
193  sampleADC[1] = df.sample(1).adc();
194  pedestal = (double)(sampleADC[0] + sampleADC[1]) / (double)2;
195  }
196 
197  for (int i = 0; (unsigned int)i < digiItr->size(); ++i) {
198  EEDataFrame df(*digiItr);
199  double gain = 12.;
200  if (df.sample(i).gainId() == 1)
201  gain = 1.;
202  else if (df.sample(i).gainId() == 2)
203  gain = 2.;
204  sampleADC[i] = pedestal + (df.sample(i).adc() - pedestal) * gain;
205  }
206 
207  for (int i = 0; i < 10; ++i) {
208  pulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i] - pedestal) / amplitude);
209  rawPulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]));
210  }
211  firstSampleHistMap_[hitDetId.hashedIndex()]->Fill(sampleADC[0]);
212  }
213 }
214 
215 // ------------ method called once each job just after ending the event loop ------------
217  rootFilename_ += ".root";
218  file_ = new TFile(rootFilename_.c_str(), "RECREATE");
219  TH1::AddDirectory(false);
220 
221  for (std::vector<int>::const_iterator itr = listChannels_.begin(); itr != listChannels_.end(); ++itr) {
222  ampHistMap_[*itr]->Write();
223  cutAmpHistMap_[*itr]->Write();
224  firstSampleHistMap_[*itr]->Write();
225 
226  rawPulseShapeHistMap_[*itr]->Write();
227  TProfile* t2 = (TProfile*)(rawPulseShapeHistMap_[*itr]->ProfileX());
228  t2->Write();
229  //TODO: fix the normalization so these are correct
230  }
231 
232  file_->Write();
233  file_->Close();
234 }
235 
237  using namespace std;
238  ostringstream myStream;
239  myStream << num << flush;
240  return (myStream.str()); //returns the string form of the stringstream object
241 }
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_