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 // $Id: EcalPulseShapeGrapher.cc,v 1.2 2010/01/04 15:07:40 ferriff Exp $
17 //
18 //
19 
21 
22 //
23 // constants, enums and typedefs
24 //
25 
26 //
27 // static data member definitions
28 //
29 
30 //
31 // constructors and destructor
32 //
34 EBUncalibratedRecHitCollection_ (iConfig.getParameter<edm::InputTag>("EBUncalibratedRecHitCollection")),
35 EBDigis_ (iConfig.getParameter<edm::InputTag>("EBDigiCollection")),
36 EEUncalibratedRecHitCollection_ (iConfig.getParameter<edm::InputTag>("EEUncalibratedRecHitCollection")),
37 EEDigis_ (iConfig.getParameter<edm::InputTag>("EEDigiCollection")),
38 ampCut_ (iConfig.getUntrackedParameter<int>("AmplitudeCutADC", 13)),
39 rootFilename_ (iConfig.getUntrackedParameter<std::string>("rootFilename","pulseShapeGrapher"))
40 {
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  {
49  std::string title = "Amplitude of cry "+intToString(*itr);
50  std::string name = "ampOfCry"+intToString(*itr);
51  ampHistMap_[*itr] = new TH1F(name.c_str(),title.c_str(),100,0,100);
52  ampHistMap_[*itr]->GetXaxis()->SetTitle("ADC");
53 
54  title = "Amplitude (over 13 ADC) of cry "+intToString(*itr);
55  name = "cutAmpOfCry"+intToString(*itr);
56  cutAmpHistMap_[*itr] = new TH1F(name.c_str(),title.c_str(),100,0,100);
57  cutAmpHistMap_[*itr]->GetXaxis()->SetTitle("ADC");
58 
59  title = "Pulse shape of cry "+intToString(*itr);
60  name = "PulseShapeCry"+intToString(*itr);
61  pulseShapeHistMap_[*itr] = new TH2F(name.c_str(),title.c_str(),10,0,10,220,-20,2);
62  pulseShapeHistMap_[*itr]->GetXaxis()->SetTitle("sample");
63 
64  title = "Raw Pulse shape of cry "+intToString(*itr);
65  name = "RawPulseShapeCry"+intToString(*itr);
66  rawPulseShapeHistMap_[*itr] = new TH2F(name.c_str(),title.c_str(),10,0,10,500,0,500);
67  rawPulseShapeHistMap_[*itr]->GetXaxis()->SetTitle("sample");
68 
69  title = "Amplitude of first sample, cry "+intToString(*itr);
70  name = "AmpOfFirstSampleCry"+intToString(*itr);
71  firstSampleHistMap_[*itr] = new TH1F(name.c_str(),title.c_str(),300,100,400);
72  firstSampleHistMap_[*itr]->GetXaxis()->SetTitle("ADC");
73  }
74 
75  fedMap_ = new EcalFedMap();
76 
77  for (int i=0; i<10; i++)
78  abscissa[i] = i;
79 }
80 
81 
83 {
84 
85  // do anything here that needs to be done at desctruction time
86  // (e.g. close files, deallocate resources etc.)
87 
88 }
89 
90 
91 //
92 // member functions
93 //
94 
95 // ------------ method called to for each event ------------
96 void
98 {
99  using namespace edm;
100  using namespace std;
101 
102  int numHitsWithActivity = 0;
103 
104  //int eventNum = iEvent.id().event();
105  //vector<EcalUncalibratedRecHit> sampleHitsPastCut;
106 
111  //cout << "event: " << eventNum << " sample hits collection size: " << sampleHits->size() << endl;
112  //Handle<EcalUncalibratedRecHitCollection> fittedHits;
113  //iEvent.getByLabel(FittedUncalibratedRecHitCollection_, fittedHits);
114  Handle<EBDigiCollection> EBdigis;
115  iEvent.getByLabel(EBDigis_, EBdigis);
116  Handle<EEDigiCollection> EEdigis;
117  iEvent.getByLabel(EEDigis_, EEdigis);
118  //cout << "event: " << eventNum << " digi collection size: " << digis->size() << endl;
119 
120  auto_ptr<EcalElectronicsMapping> ecalElectronicsMap(new EcalElectronicsMapping);
121 
122  // Loop over the hits
123  for(EcalUncalibratedRecHitCollection::const_iterator hitItr = EBHits->begin(); hitItr != EBHits->end(); ++hitItr)
124  {
125  EcalUncalibratedRecHit hit = (*hitItr);
126  float amplitude = hit.amplitude();
127  EBDetId hitDetId = hit.id();
128 
129  // Get the Fedid
130  EcalElectronicsId elecId = ecalElectronicsMap->getElectronicsId(hitDetId);
131  int FEDid = 600+elecId.dccId();
132  string SMname = fedMap_->getSliceFromFed(FEDid);
133 
134  vector<int>::const_iterator itr = listChannels_.begin();
135  while(itr != listChannels_.end() && (*itr) != hitDetId.hashedIndex())
136  {
137  itr++;
138  }
139  if(itr==listChannels_.end())
140  continue;
141 
142  ampHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
143  //cout << "Cry hash:" << hitDetId.hashedIndex() << " amplitude: " << amplitude << endl;
144  if(amplitude < ampCut_)
145  continue;
146 
147  cutAmpHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
148  numHitsWithActivity++;
149  EBDigiCollection::const_iterator digiItr= EBdigis->begin();
150  while(digiItr != EBdigis->end() && digiItr->id() != hitItr->id())
151  {
152  digiItr++;
153  }
154  if(digiItr == EBdigis->end())
155  continue;
156 
157  double sampleADC[10];
158  EBDataFrame df(*digiItr);
159  double pedestal = 200;
160 
161  if(df.sample(0).gainId()!=1 || df.sample(1).gainId()!=1) continue; //goes to the next digi
162  else {
163  sampleADC[0] = df.sample(0).adc();
164  sampleADC[1] = df.sample(1).adc();
165  pedestal = (double)(sampleADC[0]+sampleADC[1])/(double)2;
166  }
167 
168  for (int i=0; (unsigned int)i< digiItr->size(); ++i ) {
169  EBDataFrame df(*digiItr);
170  double gain = 12.;
171  if(df.sample(i).gainId()==1)
172  gain = 1.;
173  else if(df.sample(i).gainId()==2)
174  gain = 2.;
175  sampleADC[i] = pedestal+(df.sample(i).adc()-pedestal)*gain;
176  }
177 
178  //cout << "1) maxsample amp:" << maxSampleAmp << " maxSampleIndex:" << maxSampleIndex << endl;
179  for(int i=0; i<10;++i)
180  {
181  //cout << "Filling hist for:" << hitDetId.hashedIndex() << " with sample:" << i
182  //<< " amp:" <<(float)(df.sample(i).adc()-baseline)/(maxSampleAmp-baseline) << endl;
183  //cout << "ADC of sample:" << df.sample(i).adc() << " baseline:" << baseline << " maxSampleAmp:"
184  //<< maxSampleAmp << endl << endl;
185  pulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]-pedestal)/amplitude);
186  rawPulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]));
187  }
188  firstSampleHistMap_[hitDetId.hashedIndex()]->Fill(sampleADC[0]);
189  }
190 
191  // Now do the same for the EE hits
192  for(EcalUncalibratedRecHitCollection::const_iterator hitItr = EEHits->begin(); hitItr != EEHits->end(); ++hitItr)
193  {
194  EcalUncalibratedRecHit hit = (*hitItr);
195  float amplitude = hit.amplitude();
196  EEDetId hitDetId = hit.id();
197 
198  // Get the Fedid
199  EcalElectronicsId elecId = ecalElectronicsMap->getElectronicsId(hitDetId);
200  int FEDid = 600+elecId.dccId();
201  string SMname = fedMap_->getSliceFromFed(FEDid);
202 
203  vector<int>::const_iterator itr = listChannels_.begin();
204  while(itr != listChannels_.end() && (*itr) != hitDetId.hashedIndex())
205  {
206  itr++;
207  }
208  if(itr==listChannels_.end())
209  continue;
210 
211  ampHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
212  //cout << "Cry hash:" << hitDetId.hashedIndex() << " amplitude: " << amplitude << endl;
213  if(amplitude < ampCut_)
214  continue;
215 
216  cutAmpHistMap_[hitDetId.hashedIndex()]->Fill(amplitude);
217  numHitsWithActivity++;
218  EEDigiCollection::const_iterator digiItr= EEdigis->begin();
219  while(digiItr != EEdigis->end() && digiItr->id() != hitItr->id())
220  {
221  digiItr++;
222  }
223  if(digiItr == EEdigis->end())
224  continue;
225 
226  double sampleADC[10];
227  EEDataFrame df(*digiItr);
228  double pedestal = 200;
229 
230  if(df.sample(0).gainId()!=1 || df.sample(1).gainId()!=1) continue; //goes to the next digi
231  else {
232  sampleADC[0] = df.sample(0).adc();
233  sampleADC[1] = df.sample(1).adc();
234  pedestal = (double)(sampleADC[0]+sampleADC[1])/(double)2;
235  }
236 
237  for (int i=0; (unsigned int)i< digiItr->size(); ++i ) {
238  EEDataFrame df(*digiItr);
239  double gain = 12.;
240  if(df.sample(i).gainId()==1)
241  gain = 1.;
242  else if(df.sample(i).gainId()==2)
243  gain = 2.;
244  sampleADC[i] = pedestal+(df.sample(i).adc()-pedestal)*gain;
245  }
246 
247  //cout << "1) maxsample amp:" << maxSampleAmp << " maxSampleIndex:" << maxSampleIndex << endl;
248  for(int i=0; i<10;++i)
249  {
250  //cout << "Filling hist for:" << hitDetId.hashedIndex() << " with sample:" << i
251  //<< " amp:" <<(float)(df.sample(i).adc()-baseline)/(maxSampleAmp-baseline) << endl;
252  //cout << "ADC of sample:" << df.sample(i).adc() << " baseline:" << baseline << " maxSampleAmp:"
253  //<< maxSampleAmp << endl << endl;
254  pulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]-pedestal)/amplitude);
255  rawPulseShapeHistMap_[hitDetId.hashedIndex()]->Fill(i, (float)(sampleADC[i]));
256  }
257  firstSampleHistMap_[hitDetId.hashedIndex()]->Fill(sampleADC[0]);
258  }
259 }
260 
261 
262 // ------------ method called once each job just after ending the event loop ------------
263 void
265 
266  rootFilename_+=".root";
267  file_ = new TFile(rootFilename_.c_str(),"RECREATE");
268  TH1::AddDirectory(false);
269 
270  for(std::vector<int>::const_iterator itr = listChannels_.begin(); itr != listChannels_.end(); ++itr)
271  {
272  ampHistMap_[*itr]->Write();
273  cutAmpHistMap_[*itr]->Write();
274  firstSampleHistMap_[*itr]->Write();
275 
276  rawPulseShapeHistMap_[*itr]->Write();
277  TProfile* t2 = (TProfile*) (rawPulseShapeHistMap_[*itr]->ProfileX());
278  t2->Write();
279  //TODO: fix the normalization so these are correct
280  //pulseShapeHistMap_[*itr]->Write();
281  //TProfile* t1 = (TProfile*) (pulseShapeHistMap_[*itr]->ProfileX());
282  //t1->Write();
283  }
284 
285 
286  file_->Write();
287  file_->Close();
288 }
289 
291 {
292  using namespace std;
293  ostringstream myStream;
294  myStream << num << flush;
295  return(myStream.str()); //returns the string form of the stringstream object
296 }
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:87
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< T >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:30
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:243
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:18
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:361
int hashedIndex() const
Definition: EEDetId.h:183
long long int num
Definition: procUtils.cc:71
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)