CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLocalTracker/SiStripZeroSuppression/plugins/SiStripBaselineAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripBaselineAnalyzer
00004 // Class:      SiStripBaselineAnalyzer
00005 // 
00013 //
00014 // Original Author:  Ivan Amos Cali
00015 //         Created:  Mon Jul 28 14:10:52 CEST 2008
00016 // $Id: SiStripBaselineAnalyzer.cc,v 1.2 2010/11/14 22:54:37 edwenger Exp $
00017 //
00018 //
00019  
00020 
00021 // system include files
00022 #include <memory>
00023 #include <iostream>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDAnalyzer.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 
00030 #include "FWCore/Framework/interface/Event.h"
00031 #include "FWCore/Framework/interface/MakerMacros.h"
00032 #include "FWCore/Framework/interface/ESHandle.h"
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 #include "DataFormats/Common/interface/DetSet.h"
00035 #include "DataFormats/Common/interface/DetSetVector.h"
00036 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00037 
00038 #include "DataFormats/SiStripDigi/interface/SiStripProcessedRawDigi.h"
00039 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
00040 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00041 #include "DataFormats/SiStripCluster/interface/SiStripClusterCollection.h"
00042 
00043 #include "RecoLocalTracker/SiStripZeroSuppression/interface/SiStripPedestalsSubtractor.h"
00044 #include "RecoLocalTracker/SiStripZeroSuppression/interface/SiStripCommonModeNoiseSubtractor.h"
00045 #include "RecoLocalTracker/SiStripZeroSuppression/interface/SiStripRawProcessingFactory.h"
00046 
00047 //ROOT inclusion
00048 #include "TROOT.h"
00049 #include "TFile.h"
00050 #include "TNtuple.h"
00051 #include "TMath.h"
00052 #include "TCanvas.h"
00053 #include "TH1F.h"
00054 #include "TH2F.h"
00055 #include "TProfile.h"
00056 #include "TList.h"
00057 #include "TString.h"
00058 #include "TStyle.h"
00059 #include "TGraph.h"
00060 #include "TMultiGraph.h"
00061 #include "THStack.h"
00062 
00063 
00064 //
00065 // class decleration
00066 //
00067 
00068 class SiStripBaselineAnalyzer : public edm::EDAnalyzer {
00069    public:
00070       explicit SiStripBaselineAnalyzer(const edm::ParameterSet&);
00071       ~SiStripBaselineAnalyzer();
00072 
00073 
00074    private:
00075       virtual void beginJob() ;
00076       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00077       virtual void endJob() ;
00078       
00079           std::auto_ptr<SiStripPedestalsSubtractor>   subtractorPed_;
00080    
00081           std::string outputFile_;
00082           edm::InputTag srcBaseline_;
00083           edm::InputTag srcProcessedRawDigi_;
00084       
00085           TH1F* h1BadAPVperEvent_;
00086           
00087           TH1F* h1ProcessedRawDigis_;
00088           TH1F* h1Baseline_;
00089           TH1F* h1Clusters_;
00090           
00091           TFile* oFile_;
00092           
00093           TCanvas* Canvas_;
00094           std::vector<TH1F> vProcessedRawDigiHisto_;
00095           std::vector<TH1F> vBaselineHisto_;
00096           std::vector<TH1F> vClusterHisto_;
00097           
00098           uint16_t nModuletoDisplay_;
00099           uint16_t actualModule_;
00100 };
00101 
00102 
00103 SiStripBaselineAnalyzer::SiStripBaselineAnalyzer(const edm::ParameterSet& conf){
00104    
00105   outputFile_ = conf.getUntrackedParameter<std::string>("outputFile", "StripHistos.root");
00106   srcBaseline_ =  conf.getParameter<edm::InputTag>( "srcBaseline" );
00107   srcProcessedRawDigi_ =  conf.getParameter<edm::InputTag>( "srcProcessedRawDigi" );
00108   subtractorPed_ = SiStripRawProcessingFactory::create_SubtractorPed(conf.getParameter<edm::ParameterSet>("Algorithms"));
00109   nModuletoDisplay_ = conf.getParameter<uint32_t>( "nModuletoDisplay_" );
00110   
00111   vProcessedRawDigiHisto_.clear();
00112   vProcessedRawDigiHisto_.reserve(10000);
00113   
00114   vBaselineHisto_.clear();
00115   vBaselineHisto_.reserve(10000);
00116   
00117   vClusterHisto_.clear();
00118   vClusterHisto_.reserve(10000);
00119  
00120   
00121   h1BadAPVperEvent_ = new TH1F("BadAPV/Event","BadAPV/Event", 2001, -0.5, 2000.5);
00122   h1BadAPVperEvent_->SetXTitle("# Modules with Bad APVs");
00123   h1BadAPVperEvent_->SetYTitle("Entries");
00124   h1BadAPVperEvent_->SetLineWidth(2);
00125   h1BadAPVperEvent_->SetLineStyle(2);
00126  
00127 }
00128 
00129 
00130 SiStripBaselineAnalyzer::~SiStripBaselineAnalyzer()
00131 {
00132  
00133    
00134 
00135 }
00136 
00137 void
00138 SiStripBaselineAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& es)
00139 {
00140    using namespace edm;
00141    
00142    
00143    subtractorPed_->init(es);
00144    
00145    edm::Handle<edm::DetSetVector<SiStripProcessedRawDigi> > moduleBaseline;
00146    e.getByLabel(srcBaseline_, moduleBaseline);
00147    
00148    edm::Handle< edm::DetSetVector<SiStripRawDigi> > moduleRawDigi;
00149    e.getByLabel(srcProcessedRawDigi_,moduleRawDigi);
00150 
00151    edm::Handle<edmNew::DetSetVector<SiStripCluster> > clusters;
00152    edm::InputTag clusLabel("siStripClusters");
00153    e.getByLabel(clusLabel, clusters);
00154 
00155    
00156    char detIds[20];
00157    char evs[20];
00158    char runs[20];    
00159     
00160    edm::DetSetVector<SiStripProcessedRawDigi>::const_iterator itDSBaseline = moduleBaseline->begin();
00161    edm::DetSetVector<SiStripRawDigi>::const_iterator itRawDigis = moduleRawDigi->begin();
00162    
00163    uint32_t NBabAPVs = moduleRawDigi->size();     
00164    std::cout<< "Number of module with HIP in this event: " << NBabAPVs << std::endl;
00165    h1BadAPVperEvent_->Fill(NBabAPVs);
00166    
00167    for (; itRawDigis != moduleRawDigi->end(); ++itRawDigis, ++itDSBaseline) {
00168       if(actualModule_ > nModuletoDisplay_) return;
00169       uint32_t detId = itRawDigis->id;
00170           
00171           
00172       if(itDSBaseline->id != detId){
00173                 std::cout << "Collections out of Synch. Something of fishy is going on ;-)" << std::endl;
00174                 return;
00175       }   
00176       
00177           actualModule_++;
00178           uint32_t event = e.id().event();
00179           uint32_t run = e.id().run();
00180           //std::cout << "processing module N: " << actualModule_<< " detId: " << detId << " event: "<< event << std::endl; 
00181           
00182           sprintf(detIds,"%ul", detId);
00183           sprintf(evs,"%ul", event);
00184           sprintf(runs,"%ul", run);
00185           char* dHistoName = Form("Id:%s_run:%s_ev:%s",detIds, runs, evs);
00186           h1ProcessedRawDigis_ = new TH1F(dHistoName,dHistoName, 768, -0.5, 767.5); 
00187           h1Baseline_ = new TH1F(dHistoName,dHistoName, 768, -0.5, 767.5); 
00188       h1Clusters_ = new TH1F(dHistoName,dHistoName, 768, -0.5, 767.5);
00189           
00190           
00191           h1ProcessedRawDigis_->SetXTitle("strip#");  
00192           h1ProcessedRawDigis_->SetYTitle("ADC");
00193           h1ProcessedRawDigis_->SetMaximum(1024.);
00194       h1ProcessedRawDigis_->SetMinimum(-300.);
00195           h1ProcessedRawDigis_->SetLineWidth(2);
00196 
00197    
00198       h1Baseline_->SetXTitle("strip#");
00199       h1Baseline_->SetYTitle("ADC");
00200       h1Baseline_->SetMaximum(1024.);
00201       h1Baseline_->SetMinimum(-300.);
00202       h1Baseline_->SetLineWidth(2);
00203           h1Baseline_->SetLineStyle(2);
00204           h1Baseline_->SetLineColor(2);
00205          
00206           h1Clusters_->SetXTitle("strip#");
00207       h1Clusters_->SetYTitle("ADC");
00208       h1Clusters_->SetMaximum(1024.);
00209       h1Clusters_->SetMinimum(-300.);
00210       h1Clusters_->SetLineWidth(2);
00211           h1Clusters_->SetLineStyle(2);
00212           h1Clusters_->SetLineColor(3);
00213           
00214           edm::DetSet<SiStripProcessedRawDigi>::const_iterator  itBaseline; 
00215           std::vector<int16_t>::const_iterator itProcessedRawDigis;
00216           
00217           
00218           std::vector<int16_t> ProcessedRawDigis(itRawDigis->size());
00219           subtractorPed_->subtract( *itRawDigis, ProcessedRawDigis);
00220           
00221           
00222           int strip =0;
00223       for(itProcessedRawDigis = ProcessedRawDigis.begin(), itBaseline = itDSBaseline->begin();itProcessedRawDigis != ProcessedRawDigis.end(); ++itProcessedRawDigis, ++itBaseline){
00224                 h1ProcessedRawDigis_->Fill(strip, *itProcessedRawDigis);
00225                 h1Baseline_->Fill(strip, itBaseline->adc()); 
00226                 ++strip;
00227       }   
00228           
00229           edmNew::DetSetVector<SiStripCluster>::const_iterator itClusters = clusters->begin();
00230           for ( ; itClusters != clusters->end(); ++itClusters ){
00231                 for ( edmNew::DetSet<SiStripCluster>::const_iterator clus =     itClusters->begin(); clus != itClusters->end(); ++clus){
00232             if(clus->geographicalId() == detId){
00233                                 int firststrip = clus->firstStrip();
00234                     //std::cout << "Found cluster in detId " << detId << " " << firststrip << " " << clus->amplitudes().size() << " -----------------------------------------------" << std::endl;              
00235                         strip=0;
00236                                 for( std::vector<uint8_t>::const_iterator itAmpl = clus->amplitudes().begin(); itAmpl != clus->amplitudes().end(); ++itAmpl){
00237                    h1Clusters_->Fill(firststrip+strip, *itAmpl);
00238                                    ++strip;
00239                                 }
00240                         }              
00241         }
00242           }
00243           
00244           
00245          
00246          vProcessedRawDigiHisto_.push_back(*h1ProcessedRawDigis_);
00247          vBaselineHisto_.push_back(*h1Baseline_);
00248          vClusterHisto_.push_back(*h1Clusters_);
00249          
00250         }
00251                 
00252     
00253 }
00254 
00255 
00256 // ------------ method called once each job just before starting event loop  ------------
00257 void SiStripBaselineAnalyzer::beginJob()
00258 {
00259   
00260   
00261   actualModule_ =0;
00262    
00263  
00264 }
00265 
00266 // ------------ method called once each job just after ending the event loop  ------------
00267 void 
00268 SiStripBaselineAnalyzer::endJob() {
00269     oFile_ = new TFile((const char*)outputFile_.c_str(), "RECREATE");
00270     oFile_->mkdir("ProcessedRawDigis");
00271     oFile_->mkdir("Baseline");
00272         oFile_->mkdir("Clusters");
00273         
00274         
00275     std::vector<TH1F>::iterator itvProcessedRawDigis, itvBaseline, itvClusters; 
00276     itvProcessedRawDigis = vProcessedRawDigiHisto_.begin();
00277     itvBaseline = vBaselineHisto_.begin();
00278     itvClusters = vClusterHisto_.begin();
00279         
00280         oFile_->cd();
00281         h1BadAPVperEvent_->Write();
00282         for(; itvProcessedRawDigis != vProcessedRawDigiHisto_.end(); ++itvProcessedRawDigis, ++itvBaseline, ++itvClusters){
00283             oFile_->cd("ProcessedRawDigis");
00284                 itvProcessedRawDigis->Write();
00285                 oFile_->cd("Baseline");
00286             itvBaseline->Write();
00287                 oFile_->cd("Clusters");
00288                 itvClusters->Write();
00289         }
00290         oFile_->Write();
00291     oFile_->Close();
00292   
00293 }
00294 
00295 //define this as a plug-in
00296 DEFINE_FWK_MODULE(SiStripBaselineAnalyzer);
00297