CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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_ (iConfig.getParameter<edm::InputTag>("EBUncalibratedRecHitCollection")),
34 EBDigis_ (iConfig.getParameter<edm::InputTag>("EBDigiCollection")),
35 EEUncalibratedRecHitCollection_ (iConfig.getParameter<edm::InputTag>("EEUncalibratedRecHitCollection")),
36 EEDigis_ (iConfig.getParameter<edm::InputTag>("EEDigiCollection")),
37 ampCut_ (iConfig.getUntrackedParameter<int>("AmplitudeCutADC", 13)),
38 rootFilename_ (iConfig.getUntrackedParameter<std::string>("rootFilename","pulseShapeGrapher"))
39 {
40  //now do what ever initialization is needed
41 
42  std::vector<int> listDefaults;
43  listDefaults.push_back(-1);
44  listChannels_ = iConfig.getUntrackedParameter<std::vector<int> >("listChannels", listDefaults);
45 
46  for(std::vector<int>::const_iterator itr = listChannels_.begin(); itr != listChannels_.end(); ++itr)
47  {
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 
82 {
83 
84  // do anything here that needs to be done at desctruction time
85  // (e.g. close files, deallocate resources etc.)
86 
87 }
88 
89 
90 //
91 // member functions
92 //
93 
94 // ------------ method called to for each event ------------
95 void
97 {
98  using namespace edm;
99  using namespace std;
100 
101  int numHitsWithActivity = 0;
102 
103  //int eventNum = iEvent.id().event();
104  //vector<EcalUncalibratedRecHit> sampleHitsPastCut;
105 
110  //cout << "event: " << eventNum << " sample hits collection size: " << sampleHits->size() << endl;
111  //Handle<EcalUncalibratedRecHitCollection> fittedHits;
112  //iEvent.getByLabel(FittedUncalibratedRecHitCollection_, fittedHits);
113  Handle<EBDigiCollection> EBdigis;
114  iEvent.getByLabel(EBDigis_, EBdigis);
115  Handle<EEDigiCollection> EEdigis;
116  iEvent.getByLabel(EEDigis_, EEdigis);
117  //cout << "event: " << eventNum << " digi collection size: " << digis->size() << endl;
118 
119  auto_ptr<EcalElectronicsMapping> ecalElectronicsMap(new EcalElectronicsMapping);
120 
121  // Loop over the hits
122  for(EcalUncalibratedRecHitCollection::const_iterator hitItr = EBHits->begin(); hitItr != EBHits->end(); ++hitItr)
123  {
124  EcalUncalibratedRecHit hit = (*hitItr);
125  float amplitude = hit.amplitude();
126  EBDetId hitDetId = hit.id();
127 
128  // Get the Fedid
129  EcalElectronicsId elecId = ecalElectronicsMap->getElectronicsId(hitDetId);
130  int FEDid = 600+elecId.dccId();
131  string SMname = fedMap_->getSliceFromFed(FEDid);
132 
133  vector<int>::const_iterator itr = listChannels_.begin();
134  while(itr != listChannels_.end() && (*itr) != hitDetId.hashedIndex())
135  {
136  itr++;
137  }
138  if(itr==listChannels_.end())
139  continue;
140 
141  ampHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
142  //cout << "Cry hash:" << hitDetId.hashedIndex() << " amplitude: " << amplitude << endl;
143  if(amplitude < ampCut_)
144  continue;
145 
146  cutAmpHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
147  numHitsWithActivity++;
148  EBDigiCollection::const_iterator digiItr= EBdigis->begin();
149  while(digiItr != EBdigis->end() && digiItr->id() != hitItr->id())
150  {
151  digiItr++;
152  }
153  if(digiItr == EBdigis->end())
154  continue;
155 
156  double sampleADC[10];
157  EBDataFrame df(*digiItr);
158  double pedestal = 200;
159 
160  if(df.sample(0).gainId()!=1 || df.sample(1).gainId()!=1) continue; //goes to the next digi
161  else {
162  sampleADC[0] = df.sample(0).adc();
163  sampleADC[1] = df.sample(1).adc();
164  pedestal = (double)(sampleADC[0]+sampleADC[1])/(double)2;
165  }
166 
167  for (int i=0; (unsigned int)i< digiItr->size(); ++i ) {
168  EBDataFrame df(*digiItr);
169  double gain = 12.;
170  if(df.sample(i).gainId()==1)
171  gain = 1.;
172  else if(df.sample(i).gainId()==2)
173  gain = 2.;
174  sampleADC[i] = pedestal+(df.sample(i).adc()-pedestal)*gain;
175  }
176 
177  //cout << "1) maxsample amp:" << maxSampleAmp << " maxSampleIndex:" << maxSampleIndex << endl;
178  for(int i=0; i<10;++i)
179  {
180  //cout << "Filling hist for:" << hitDetId.hashedIndex() << " with sample:" << i
181  //<< " amp:" <<(float)(df.sample(i).adc()-baseline)/(maxSampleAmp-baseline) << endl;
182  //cout << "ADC of sample:" << df.sample(i).adc() << " baseline:" << baseline << " maxSampleAmp:"
183  //<< maxSampleAmp << endl << endl;
184  pulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]-pedestal)/amplitude);
185  rawPulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]));
186  }
187  firstSampleHistMap_[hitDetId.hashedIndex()]->Fill(sampleADC[0]);
188  }
189 
190  // Now do the same for the EE hits
191  for(EcalUncalibratedRecHitCollection::const_iterator hitItr = EEHits->begin(); hitItr != EEHits->end(); ++hitItr)
192  {
193  EcalUncalibratedRecHit hit = (*hitItr);
194  float amplitude = hit.amplitude();
195  EEDetId hitDetId = hit.id();
196 
197  // Get the Fedid
198  EcalElectronicsId elecId = ecalElectronicsMap->getElectronicsId(hitDetId);
199  int FEDid = 600+elecId.dccId();
200  string SMname = fedMap_->getSliceFromFed(FEDid);
201 
202  vector<int>::const_iterator itr = listChannels_.begin();
203  while(itr != listChannels_.end() && (*itr) != hitDetId.hashedIndex())
204  {
205  itr++;
206  }
207  if(itr==listChannels_.end())
208  continue;
209 
210  ampHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
211  //cout << "Cry hash:" << hitDetId.hashedIndex() << " amplitude: " << amplitude << endl;
212  if(amplitude < ampCut_)
213  continue;
214 
215  cutAmpHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
216  numHitsWithActivity++;
217  EEDigiCollection::const_iterator digiItr= EEdigis->begin();
218  while(digiItr != EEdigis->end() && digiItr->id() != hitItr->id())
219  {
220  digiItr++;
221  }
222  if(digiItr == EEdigis->end())
223  continue;
224 
225  double sampleADC[10];
226  EEDataFrame df(*digiItr);
227  double pedestal = 200;
228 
229  if(df.sample(0).gainId()!=1 || df.sample(1).gainId()!=1) continue; //goes to the next digi
230  else {
231  sampleADC[0] = df.sample(0).adc();
232  sampleADC[1] = df.sample(1).adc();
233  pedestal = (double)(sampleADC[0]+sampleADC[1])/(double)2;
234  }
235 
236  for (int i=0; (unsigned int)i< digiItr->size(); ++i ) {
237  EEDataFrame df(*digiItr);
238  double gain = 12.;
239  if(df.sample(i).gainId()==1)
240  gain = 1.;
241  else if(df.sample(i).gainId()==2)
242  gain = 2.;
243  sampleADC[i] = pedestal+(df.sample(i).adc()-pedestal)*gain;
244  }
245 
246  //cout << "1) maxsample amp:" << maxSampleAmp << " maxSampleIndex:" << maxSampleIndex << endl;
247  for(int i=0; i<10;++i)
248  {
249  //cout << "Filling hist for:" << hitDetId.hashedIndex() << " with sample:" << i
250  //<< " amp:" <<(float)(df.sample(i).adc()-baseline)/(maxSampleAmp-baseline) << endl;
251  //cout << "ADC of sample:" << df.sample(i).adc() << " baseline:" << baseline << " maxSampleAmp:"
252  //<< maxSampleAmp << endl << endl;
253  pulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]-pedestal)/amplitude);
254  rawPulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]));
255  }
256  firstSampleHistMap_[hitDetId.hashedIndex()]->Fill(sampleADC[0]);
257  }
258 }
259 
260 
261 // ------------ method called once each job just after ending the event loop ------------
262 void
264 
265  rootFilename_+=".root";
266  file_ = new TFile(rootFilename_.c_str(),"RECREATE");
267  TH1::AddDirectory(false);
268 
269  for(std::vector<int>::const_iterator itr = listChannels_.begin(); itr != listChannels_.end(); ++itr)
270  {
271  ampHistMap_[*itr]->Write();
272  cutAmpHistMap_[*itr]->Write();
273  firstSampleHistMap_[*itr]->Write();
274 
275  rawPulseShapeHistMap_[*itr]->Write();
276  TProfile* t2 = (TProfile*) (rawPulseShapeHistMap_[*itr]->ProfileX());
277  t2->Write();
278  //TODO: fix the normalization so these are correct
279  //pulseShapeHistMap_[*itr]->Write();
280  //TProfile* t1 = (TProfile*) (pulseShapeHistMap_[*itr]->ProfileX());
281  //t1->Write();
282  }
283 
284 
285  file_->Write();
286  file_->Close();
287 }
288 
290 {
291  using namespace std;
292  ostringstream myStream;
293  myStream << num << flush;
294  return(myStream.str()); //returns the string form of the stringstream object
295 }
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:86
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
edm::InputTag EBUncalibratedRecHitCollection_
std::vector< EcalUncalibratedRecHit >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
edm::InputTag EEUncalibratedRecHitCollection_
int gainId() const
get the gainId (2 bits)
EcalPulseShapeGrapher(const edm::ParameterSet &)
std::string getSliceFromFed(int)
Definition: EcalFedMap.cc:93
std::vector< int > listChannels_
int iEvent
Definition: GenABIO.cc:230
std::map< int, TH1F * > ampHistMap_
std::map< int, TH2F * > rawPulseShapeHistMap_
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
int hashedIndex() const
Definition: EEDetId.h:182
std::map< int, TH1F * > firstSampleHistMap_
std::map< int, TH1F * > cutAmpHistMap_
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::map< int, TH2F * > pulseShapeHistMap_
tuple size
Write out results.
int adc() const
get the ADC sample (12 bits)