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 
53 //ROOT inclusion
54 #include "TROOT.h"
55 #include "TFile.h"
56 #include "TNtuple.h"
57 #include "TMath.h"
58 #include "TCanvas.h"
59 #include "TH1F.h"
60 #include "TH2F.h"
61 #include "TProfile.h"
62 #include "TList.h"
63 #include "TString.h"
64 #include "TStyle.h"
65 #include "TGraph.h"
66 #include "TMultiGraph.h"
67 #include "THStack.h"
68 
69 
70 //
71 // class decleration
72 //
73 
75  public:
78 
79 
80  private:
81  virtual void beginJob() override ;
82  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
83  virtual void endJob() override ;
84 
85  std::auto_ptr<SiStripPedestalsSubtractor> subtractorPed_;
87  std::vector<int> pedestals;
88  uint32_t peds_cache_id;
89 
94  bool plotAPVCM_;
96 
101 
103 
105 
107  TH1F* h1Baseline_;
108  TH1F* h1Clusters_;
109  TH1F* h1APVCM_;
110  TH1F* h1Pedestals_;
111 
112  TCanvas* Canvas_;
113  std::vector<TH1F> vProcessedRawDigiHisto_;
114  std::vector<TH1F> vBaselineHisto_;
115  std::vector<TH1F> vBaselinePointsHisto_;
116  std::vector<TH1F> vClusterHisto_;
117 
119  uint16_t actualModule_;
120 };
121 
122 
124 
125  srcBaseline_ = conf.getParameter<edm::InputTag>( "srcBaseline" );
126  srcBaselinePoints_ = conf.getParameter<edm::InputTag>( "srcBaselinePoints" );
127  srcProcessedRawDigi_ = conf.getParameter<edm::InputTag>( "srcProcessedRawDigi" );
128  srcAPVCM_ = conf.getParameter<edm::InputTag>( "srcAPVCM" );
130  nModuletoDisplay_ = conf.getParameter<uint32_t>( "nModuletoDisplay" );
131  plotClusters_ = conf.getParameter<bool>( "plotClusters" );
132  plotBaseline_ = conf.getParameter<bool>( "plotBaseline" );
133  plotBaselinePoints_ = conf.getParameter<bool>( "plotBaselinePoints" );
134  plotRawDigi_ = conf.getParameter<bool>( "plotRawDigi" );
135  plotAPVCM_ = conf.getParameter<bool>( "plotAPVCM" );
136  plotPedestals_ = conf.getParameter<bool>( "plotPedestals" );
137 
138  h1BadAPVperEvent_ = fs_->make<TH1F>("BadAPV/Event","BadAPV/Event", 2001, -0.5, 2000.5);
139  h1BadAPVperEvent_->SetXTitle("# Modules with Bad APVs");
140  h1BadAPVperEvent_->SetYTitle("Entries");
141  h1BadAPVperEvent_->SetLineWidth(2);
142  h1BadAPVperEvent_->SetLineStyle(2);
143 
144  h1APVCM_ = fs_->make<TH1F>("APV CM","APV CM", 2048, -1023.5, 1023.5);
145  h1APVCM_->SetXTitle("APV CM [adc]");
146  h1APVCM_->SetYTitle("Entries");
147  h1APVCM_->SetLineWidth(2);
148  h1APVCM_->SetLineStyle(2);
149 
150  h1Pedestals_ = fs_->make<TH1F>("Pedestals","Pedestals", 2048, -1023.5, 1023.5);
151  h1Pedestals_->SetXTitle("Pedestals [adc]");
152  h1Pedestals_->SetYTitle("Entries");
153  h1Pedestals_->SetLineWidth(2);
154  h1Pedestals_->SetLineStyle(2);
155 
156 
157 
158 }
159 
160 
162 {
163 
164 
165 
166 }
167 
168 void
170 {
171  using namespace edm;
172  if(plotPedestals_&&actualModule_ ==0){
173  uint32_t p_cache_id = es.get<SiStripPedestalsRcd>().cacheIdentifier();
174  if(p_cache_id != peds_cache_id) {
176  peds_cache_id = p_cache_id;
177  }
178 
179 
180  std::vector<uint32_t> detIdV;
181  pedestalsHandle->getDetIds(detIdV);
182 
183  for(uint32_t i=0; i < detIdV.size(); ++i){
184  pedestals.clear();
185  SiStripPedestals::Range pedestalsRange = pedestalsHandle->getRange(detIdV[i]);
186  pedestals.resize((pedestalsRange.second- pedestalsRange.first)*8/10);
187  pedestalsHandle->allPeds(pedestals, pedestalsRange);
188  for(uint32_t it=0; it < pedestals.size(); ++it) h1Pedestals_->Fill(pedestals[it]);
189  }
190  }
191 
192  if(plotAPVCM_){
194  edm::InputTag CMLabel("siStripZeroSuppression:APVCM");
195  e.getByLabel(srcAPVCM_,moduleCM);
196 
197  edm::DetSetVector<SiStripProcessedRawDigi>::const_iterator itCMDetSetV =moduleCM->begin();
198  for (; itCMDetSetV != moduleCM->end(); ++itCMDetSetV){
200  for(;itCM != itCMDetSetV->end(); ++itCM) h1APVCM_->Fill(itCM->adc());
201  }
202  }
203 
204  if(!plotRawDigi_) return;
205  subtractorPed_->init(es);
206 
207 
208 
210  e.getByLabel(srcProcessedRawDigi_,moduleRawDigi);
211 
213  if(plotBaseline_) e.getByLabel(srcBaseline_, moduleBaseline);
214 
215  edm::Handle<edm::DetSetVector<SiStripDigi> > moduleBaselinePoints;
216  if(plotBaselinePoints_) e.getByLabel(srcBaseline_, moduleBaselinePoints);
217 
219  if(plotClusters_){
220  edm::InputTag clusLabel("siStripClusters");
221  e.getByLabel(clusLabel, clusters);
222  }
223 
224  char detIds[20];
225  char evs[20];
226  char runs[20];
227 
228 
229  TFileDirectory sdProcessedRawDigis_= fs_->mkdir("ProcessedRawDigis");
230  TFileDirectory sdBaseline_= fs_->mkdir("Baseline");
231  TFileDirectory sdBaselinePoints_= fs_->mkdir("BaselinePoints");
232  TFileDirectory sdClusters_= fs_->mkdir("Clusters");
233 
234 
236  if(plotBaseline_) itDSBaseline = moduleBaseline->begin();
237  edm::DetSetVector<SiStripRawDigi>::const_iterator itRawDigis = moduleRawDigi->begin();
238 
239  uint32_t NBabAPVs = moduleRawDigi->size();
240  std::cout<< "Number of module with HIP in this event: " << NBabAPVs << std::endl;
241  h1BadAPVperEvent_->Fill(NBabAPVs);
242 
243  for (; itRawDigis != moduleRawDigi->end(); ++itRawDigis) {
244  if(actualModule_ > nModuletoDisplay_) return;
245  uint32_t detId = itRawDigis->id;
246 
247  if(plotBaseline_){
248  //std::cout << "bas id: " << itDSBaseline->id << " raw id: " << detId << std::endl;
249  if(itDSBaseline->id != detId){
250  std::cout << "Collections out of Synch. Something of fishy is going on ;-)" << std::endl;
251  return;
252  }
253  }
254 
255 
256  actualModule_++;
257  uint32_t event = e.id().event();
258  uint32_t run = e.id().run();
259  //std::cout << "processing module N: " << actualModule_<< " detId: " << detId << " event: "<< event << std::endl;
260 
261 
262 
263  edm::DetSet<SiStripRawDigi>::const_iterator itRaw = itRawDigis->begin();
264  bool restAPV[6] = {0,0,0,0,0,0};
265  int strip =0, totADC=0;
266  int minAPVRes = 7, maxAPVRes = -1;
267  for(;itRaw != itRawDigis->end(); ++itRaw, ++strip){
268  float adc = itRaw->adc();
269  totADC+= adc;
270  if(strip%127 ==0){
271  //std::cout << "totADC " << totADC << std::endl;
272  int APV = strip/128;
273  if(totADC!= 0){
274  restAPV[APV] = true;
275  totADC =0;
276  if(APV>maxAPVRes) maxAPVRes = APV;
277  if(APV<minAPVRes) minAPVRes = APV;
278  }
279  }
280  }
281 
282  uint16_t bins =768;
283  float minx = -0.5, maxx=767.5;
284  if(minAPVRes !=7){
285  minx = minAPVRes * 128 -0.5;
286  maxx = maxAPVRes * 128 + 127.5;
287  bins = maxx-minx;
288  }
289 
290  sprintf(detIds,"%ul", detId);
291  sprintf(evs,"%ul", event);
292  sprintf(runs,"%ul", run);
293  char* dHistoName = Form("Id:%s_run:%s_ev:%s",detIds, runs, evs);
294  h1ProcessedRawDigis_ = sdProcessedRawDigis_.make<TH1F>(dHistoName,dHistoName, bins, minx, maxx);
295 
296  if(plotBaseline_){
297  h1Baseline_ = sdBaseline_.make<TH1F>(dHistoName,dHistoName, bins, minx, maxx);
298  h1Baseline_->SetXTitle("strip#");
299  h1Baseline_->SetYTitle("ADC");
300  h1Baseline_->SetMaximum(1024.);
301  h1Baseline_->SetMinimum(-300.);
302  h1Baseline_->SetLineWidth(2);
303  h1Baseline_->SetLineStyle(2);
304  h1Baseline_->SetLineColor(2);
305  }
306 
307  if(plotClusters_){
308  h1Clusters_ = sdClusters_.make<TH1F>(dHistoName,dHistoName, bins, minx, maxx);
309 
310  h1Clusters_->SetXTitle("strip#");
311  h1Clusters_->SetYTitle("ADC");
312  h1Clusters_->SetMaximum(1024.);
313  h1Clusters_->SetMinimum(-300.);
314  h1Clusters_->SetLineWidth(2);
315  h1Clusters_->SetLineStyle(2);
316  h1Clusters_->SetLineColor(3);
317  }
318 
319  h1ProcessedRawDigis_->SetXTitle("strip#");
320  h1ProcessedRawDigis_->SetYTitle("ADC");
321  h1ProcessedRawDigis_->SetMaximum(1024.);
322  h1ProcessedRawDigis_->SetMinimum(-300.);
323  h1ProcessedRawDigis_->SetLineWidth(2);
324 
325  std::vector<int16_t> ProcessedRawDigis(itRawDigis->size());
326  subtractorPed_->subtract( *itRawDigis, ProcessedRawDigis);
327 
329  if(plotBaseline_) itBaseline = itDSBaseline->begin();
330  std::vector<int16_t>::const_iterator itProcessedRawDigis;
331 
332  strip =0;
333  for(itProcessedRawDigis = ProcessedRawDigis.begin();itProcessedRawDigis != ProcessedRawDigis.end(); ++itProcessedRawDigis){
334  if(restAPV[strip/128]){
335  float adc = *itProcessedRawDigis;
336  h1ProcessedRawDigis_->Fill(strip, adc);
337  if(plotBaseline_){
338  h1Baseline_->Fill(strip, itBaseline->adc());
339  ++itBaseline;
340  }
341  }
342  ++strip;
343  }
344 
345  if(plotBaseline_) ++itDSBaseline;
346  if(plotClusters_){
348  for ( ; itClusters != clusters->end(); ++itClusters ){
349  for ( edmNew::DetSet<SiStripCluster>::const_iterator clus = itClusters->begin(); clus != itClusters->end(); ++clus){
350  if(itClusters->id() == detId){
351  int firststrip = clus->firstStrip();
352  //std::cout << "Found cluster in detId " << detId << " " << firststrip << " " << clus->amplitudes().size() << " -----------------------------------------------" << std::endl;
353  strip=0;
354  for( std::vector<uint8_t>::const_iterator itAmpl = clus->amplitudes().begin(); itAmpl != clus->amplitudes().end(); ++itAmpl){
355  h1Clusters_->Fill(firststrip+strip, *itAmpl);
356  ++strip;
357  }
358  }
359  }
360  }
361  }
362  }
363 
364 }
365 
366 
367 // ------------ method called once each job just before starting event loop ------------
369 {
370 
371 
372 actualModule_ =0;
373 
374 
375 }
376 
377 // ------------ method called once each job just after ending the event loop ------------
378 void
380 
381 }
382 
383 //define this as a plug-in
385 
int adc(sample_type sample)
get the ADC sample (12 bits)
RunNumber_t run() const
Definition: EventID.h:42
iterator end()
Definition: DetSet.h:60
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
virtual void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:390
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:356
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:56
const_iterator end(bool update=true) const
std::vector< TH1F > vProcessedRawDigiHisto_
tuple cout
Definition: gather_cfg.py:121
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:341
edm::ESHandle< SiStripPedestals > pedestalsHandle
const_iterator begin(bool update=true) const
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:106
std::auto_ptr< SiStripPedestalsSubtractor > subtractorPed_
static std::auto_ptr< SiStripPedestalsSubtractor > create_SubtractorPed(const edm::ParameterSet &)