CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripBaselineAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripBaselineAnalyzer
4 // Class: SiStripBaselineAnalyzer
5 //
13 //
14 // Original Author: Ivan Amos Cali
15 // Created: Mon Jul 28 14:10:52 CEST 2008
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <iostream>
23 
24 // user include files
28 
36 
41 
44 
48 
52 
54 
55 //ROOT inclusion
56 #include "TROOT.h"
57 #include "TFile.h"
58 #include "TNtuple.h"
59 #include "TMath.h"
60 #include "TCanvas.h"
61 #include "TH1F.h"
62 #include "TH2F.h"
63 #include "TProfile.h"
64 #include "TList.h"
65 #include "TString.h"
66 #include "TStyle.h"
67 #include "TGraph.h"
68 #include "TMultiGraph.h"
69 #include "THStack.h"
70 
71 
72 //
73 // class decleration
74 //
75 
77  public:
80 
81 
82  private:
83  virtual void beginJob() override ;
84  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
85  virtual void endJob() override ;
86 
87  std::auto_ptr<SiStripPedestalsSubtractor> subtractorPed_;
89  std::vector<int> pedestals;
90  uint32_t peds_cache_id;
91 
96  bool plotAPVCM_;
98 
103 
105 
107 
109  TH1F* h1Baseline_;
110  TH1F* h1Clusters_;
111  TH1F* h1APVCM_;
112  TH1F* h1Pedestals_;
113 
114  TCanvas* Canvas_;
115  std::vector<TH1F> vProcessedRawDigiHisto_;
116  std::vector<TH1F> vBaselineHisto_;
117  std::vector<TH1F> vBaselinePointsHisto_;
118  std::vector<TH1F> vClusterHisto_;
119 
121  uint16_t actualModule_;
122 };
123 
124 
126 
127  srcBaseline_ = conf.getParameter<edm::InputTag>( "srcBaseline" );
128  srcBaselinePoints_ = conf.getParameter<edm::InputTag>( "srcBaselinePoints" );
129  srcProcessedRawDigi_ = conf.getParameter<edm::InputTag>( "srcProcessedRawDigi" );
130  srcAPVCM_ = conf.getParameter<edm::InputTag>( "srcAPVCM" );
132  nModuletoDisplay_ = conf.getParameter<uint32_t>( "nModuletoDisplay" );
133  plotClusters_ = conf.getParameter<bool>( "plotClusters" );
134  plotBaseline_ = conf.getParameter<bool>( "plotBaseline" );
135  plotBaselinePoints_ = conf.getParameter<bool>( "plotBaselinePoints" );
136  plotRawDigi_ = conf.getParameter<bool>( "plotRawDigi" );
137  plotAPVCM_ = conf.getParameter<bool>( "plotAPVCM" );
138  plotPedestals_ = conf.getParameter<bool>( "plotPedestals" );
139 
140  h1BadAPVperEvent_ = fs_->make<TH1F>("BadAPV/Event","BadAPV/Event", 2001, -0.5, 2000.5);
141  h1BadAPVperEvent_->SetXTitle("# Modules with Bad APVs");
142  h1BadAPVperEvent_->SetYTitle("Entries");
143  h1BadAPVperEvent_->SetLineWidth(2);
144  h1BadAPVperEvent_->SetLineStyle(2);
145 
146  h1APVCM_ = fs_->make<TH1F>("APV CM","APV CM", 2048, -1023.5, 1023.5);
147  h1APVCM_->SetXTitle("APV CM [adc]");
148  h1APVCM_->SetYTitle("Entries");
149  h1APVCM_->SetLineWidth(2);
150  h1APVCM_->SetLineStyle(2);
151 
152  h1Pedestals_ = fs_->make<TH1F>("Pedestals","Pedestals", 2048, -1023.5, 1023.5);
153  h1Pedestals_->SetXTitle("Pedestals [adc]");
154  h1Pedestals_->SetYTitle("Entries");
155  h1Pedestals_->SetLineWidth(2);
156  h1Pedestals_->SetLineStyle(2);
157 
158 
159 
160 }
161 
162 
164 {
165 
166 
167 
168 }
169 
170 void
172 {
173  using namespace edm;
174  if(plotPedestals_&&actualModule_ ==0){
175  uint32_t p_cache_id = es.get<SiStripPedestalsRcd>().cacheIdentifier();
176  if(p_cache_id != peds_cache_id) {
178  peds_cache_id = p_cache_id;
179  }
180 
181 
182  std::vector<uint32_t> detIdV;
183  pedestalsHandle->getDetIds(detIdV);
184 
185  for(uint32_t i=0; i < detIdV.size(); ++i){
186  pedestals.clear();
187  SiStripPedestals::Range pedestalsRange = pedestalsHandle->getRange(detIdV[i]);
188  pedestals.resize((pedestalsRange.second- pedestalsRange.first)*8/10);
189  pedestalsHandle->allPeds(pedestals, pedestalsRange);
190  for(uint32_t it=0; it < pedestals.size(); ++it) h1Pedestals_->Fill(pedestals[it]);
191  }
192  }
193 
194  if(plotAPVCM_){
196  edm::InputTag CMLabel("siStripZeroSuppression:APVCM");
197  e.getByLabel(srcAPVCM_,moduleCM);
198 
199  edm::DetSetVector<SiStripProcessedRawDigi>::const_iterator itCMDetSetV =moduleCM->begin();
200  for (; itCMDetSetV != moduleCM->end(); ++itCMDetSetV){
202  for(;itCM != itCMDetSetV->end(); ++itCM) h1APVCM_->Fill(itCM->adc());
203  }
204  }
205 
206  if(!plotRawDigi_) return;
207  subtractorPed_->init(es);
208 
209 
210 
212  e.getByLabel(srcProcessedRawDigi_,moduleRawDigi);
213 
215  if(plotBaseline_) e.getByLabel(srcBaseline_, moduleBaseline);
216 
217  edm::Handle<edm::DetSetVector<SiStripDigi> > moduleBaselinePoints;
218  if(plotBaselinePoints_) e.getByLabel(srcBaseline_, moduleBaselinePoints);
219 
221  if(plotClusters_){
222  edm::InputTag clusLabel("siStripClusters");
223  e.getByLabel(clusLabel, clusters);
224  }
225 
226  char detIds[20];
227  char evs[20];
228  char runs[20];
229 
230 
231  TFileDirectory sdProcessedRawDigis_= fs_->mkdir("ProcessedRawDigis");
232  TFileDirectory sdBaseline_= fs_->mkdir("Baseline");
233  TFileDirectory sdBaselinePoints_= fs_->mkdir("BaselinePoints");
234  TFileDirectory sdClusters_= fs_->mkdir("Clusters");
235 
236 
238  if(plotBaseline_) itDSBaseline = moduleBaseline->begin();
239  edm::DetSetVector<SiStripRawDigi>::const_iterator itRawDigis = moduleRawDigi->begin();
240 
241  uint32_t NBabAPVs = moduleRawDigi->size();
242  std::cout<< "Number of module with HIP in this event: " << NBabAPVs << std::endl;
243  h1BadAPVperEvent_->Fill(NBabAPVs);
244 
245  for (; itRawDigis != moduleRawDigi->end(); ++itRawDigis) {
246  if(actualModule_ > nModuletoDisplay_) return;
247  uint32_t detId = itRawDigis->id;
248 
249  if(plotBaseline_){
250  //std::cout << "bas id: " << itDSBaseline->id << " raw id: " << detId << std::endl;
251  if(itDSBaseline->id != detId){
252  std::cout << "Collections out of Synch. Something of fishy is going on ;-)" << std::endl;
253  return;
254  }
255  }
256 
257 
258  actualModule_++;
259  edm::RunNumber_t const run = e.id().run();
260  edm::EventNumber_t const event = e.id().event();
261  //std::cout << "processing module N: " << actualModule_<< " detId: " << detId << " event: "<< event << std::endl;
262 
263 
264 
265  edm::DetSet<SiStripRawDigi>::const_iterator itRaw = itRawDigis->begin();
266  bool restAPV[6] = {0,0,0,0,0,0};
267  int strip =0, totADC=0;
268  int minAPVRes = 7, maxAPVRes = -1;
269  for(;itRaw != itRawDigis->end(); ++itRaw, ++strip){
270  float adc = itRaw->adc();
271  totADC+= adc;
272  if(strip%127 ==0){
273  //std::cout << "totADC " << totADC << std::endl;
274  int APV = strip/128;
275  if(totADC!= 0){
276  restAPV[APV] = true;
277  totADC =0;
278  if(APV>maxAPVRes) maxAPVRes = APV;
279  if(APV<minAPVRes) minAPVRes = APV;
280  }
281  }
282  }
283 
284  uint16_t bins =768;
285  float minx = -0.5, maxx=767.5;
286  if(minAPVRes !=7){
287  minx = minAPVRes * 128 -0.5;
288  maxx = maxAPVRes * 128 + 127.5;
289  bins = maxx-minx;
290  }
291 
292  sprintf(detIds,"%ul", detId);
293  sprintf(evs,"%llu", event);
294  sprintf(runs,"%u", run);
295  char* dHistoName = Form("Id:%s_run:%s_ev:%s",detIds, runs, evs);
296  h1ProcessedRawDigis_ = sdProcessedRawDigis_.make<TH1F>(dHistoName,dHistoName, bins, minx, maxx);
297 
298  if(plotBaseline_){
299  h1Baseline_ = sdBaseline_.make<TH1F>(dHistoName,dHistoName, bins, minx, maxx);
300  h1Baseline_->SetXTitle("strip#");
301  h1Baseline_->SetYTitle("ADC");
302  h1Baseline_->SetMaximum(1024.);
303  h1Baseline_->SetMinimum(-300.);
304  h1Baseline_->SetLineWidth(2);
305  h1Baseline_->SetLineStyle(2);
306  h1Baseline_->SetLineColor(2);
307  }
308 
309  if(plotClusters_){
310  h1Clusters_ = sdClusters_.make<TH1F>(dHistoName,dHistoName, bins, minx, maxx);
311 
312  h1Clusters_->SetXTitle("strip#");
313  h1Clusters_->SetYTitle("ADC");
314  h1Clusters_->SetMaximum(1024.);
315  h1Clusters_->SetMinimum(-300.);
316  h1Clusters_->SetLineWidth(2);
317  h1Clusters_->SetLineStyle(2);
318  h1Clusters_->SetLineColor(3);
319  }
320 
321  h1ProcessedRawDigis_->SetXTitle("strip#");
322  h1ProcessedRawDigis_->SetYTitle("ADC");
323  h1ProcessedRawDigis_->SetMaximum(1024.);
324  h1ProcessedRawDigis_->SetMinimum(-300.);
325  h1ProcessedRawDigis_->SetLineWidth(2);
326 
327  std::vector<int16_t> ProcessedRawDigis(itRawDigis->size());
328  subtractorPed_->subtract( *itRawDigis, ProcessedRawDigis);
329 
331  if(plotBaseline_) itBaseline = itDSBaseline->begin();
332  std::vector<int16_t>::const_iterator itProcessedRawDigis;
333 
334  strip =0;
335  for(itProcessedRawDigis = ProcessedRawDigis.begin();itProcessedRawDigis != ProcessedRawDigis.end(); ++itProcessedRawDigis){
336  if(restAPV[strip/128]){
337  float adc = *itProcessedRawDigis;
338  h1ProcessedRawDigis_->Fill(strip, adc);
339  if(plotBaseline_){
340  h1Baseline_->Fill(strip, itBaseline->adc());
341  ++itBaseline;
342  }
343  }
344  ++strip;
345  }
346 
347  if(plotBaseline_) ++itDSBaseline;
348  if(plotClusters_){
350  for ( ; itClusters != clusters->end(); ++itClusters ){
351  for ( edmNew::DetSet<SiStripCluster>::const_iterator clus = itClusters->begin(); clus != itClusters->end(); ++clus){
352  if(itClusters->id() == detId){
353  int firststrip = clus->firstStrip();
354  //std::cout << "Found cluster in detId " << detId << " " << firststrip << " " << clus->amplitudes().size() << " -----------------------------------------------" << std::endl;
355  strip=0;
356  for( auto itAmpl = clus->amplitudes().begin(); itAmpl != clus->amplitudes().end(); ++itAmpl){
357  h1Clusters_->Fill(firststrip+strip, *itAmpl);
358  ++strip;
359  }
360  }
361  }
362  }
363  }
364  }
365 
366 }
367 
368 
369 // ------------ method called once each job just before starting event loop ------------
371 {
372 
373 
374 actualModule_ =0;
375 
376 
377 }
378 
379 // ------------ method called once each job just after ending the event loop ------------
380 void
382 
383 }
384 
385 //define this as a plug-in
387 
int adc(sample_type sample)
get the ADC sample (12 bits)
RunNumber_t run() const
Definition: EventID.h:39
iterator end()
Definition: DetSet.h:60
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
int i
Definition: DBlmapReader.cc:9
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) const
virtual void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
unsigned long long EventNumber_t
std::vector< TH1F > vBaselineHisto_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
data_type const * const_iterator
Definition: DetSetNew.h:30
std::pair< ContainerIterator, ContainerIterator > Range
virtual void beginJob() override
id_type id(size_t cell) const
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
tuple runs
Definition: gather_cfg.py:87
SiStripBaselineAnalyzer(const edm::ParameterSet &)
std::vector< TH1F > vBaselinePointsHisto_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
edm::Service< TFileService > fs_
std::vector< TH1F > vClusterHisto_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:365
tuple conf
Definition: dbtoconf.py:185
iterator begin()
Definition: DetSet.h:59
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
const T & get() const
Definition: EventSetup.h:55
edm::EventID id() const
Definition: EventBase.h:60
std::vector< TH1F > vProcessedRawDigiHisto_
tuple cout
Definition: gather_cfg.py:121
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:350
unsigned int RunNumber_t
edm::ESHandle< SiStripPedestals > pedestalsHandle
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:108
std::auto_ptr< SiStripPedestalsSubtractor > subtractorPed_
const_iterator begin(bool update=false) const
static std::auto_ptr< SiStripPedestalsSubtractor > create_SubtractorPed(const edm::ParameterSet &)