CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DQM/EcalPreshowerMonitorModule/src/ESTimingTask.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include <fstream>
00003 #include <iostream>
00004 
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 #include "FWCore/Framework/interface/Frameworkfwd.h"
00009 #include "FWCore/ParameterSet/interface/FileInPath.h"
00010 #include "DataFormats/DetId/interface/DetId.h"
00011 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00012 #include "DataFormats/EcalDigi/interface/ESDataFrame.h"
00013 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00014 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00015 #include "CondFormats/DataRecord/interface/ESGainRcd.h"
00016 #include "DQMServices/Core/interface/MonitorElement.h"
00017 #include "DQMServices/Core/interface/DQMStore.h"
00018 #include "DQM/EcalPreshowerMonitorModule/interface/ESTimingTask.h"
00019 
00020 #include "TStyle.h"
00021 #include "TH2F.h"
00022 #include "TMath.h"
00023 #include "TGraph.h"
00024 
00025 using namespace cms;
00026 using namespace edm;
00027 using namespace std;
00028 
00029 // fit function
00030 double fitf(double *x, double *par) {
00031 
00032   double wc = par[2];
00033   double n  = par[3]; // n-1 (in fact)
00034   double v1 = pow(wc/n*(x[0]-par[1]), n);
00035   double v2 = TMath::Exp(n-wc*(x[0]-par[1]));
00036   double v  = par[0]*v1*v2;
00037 
00038   if (x[0] < par[1]) v = 0;
00039 
00040   return v;
00041 }
00042 
00043 ESTimingTask::ESTimingTask(const edm::ParameterSet& ps) {
00044 
00045   rechitlabel_ = ps.getParameter<InputTag>("RecHitLabel");
00046   digilabel_   = ps.getParameter<InputTag>("DigiLabel");
00047   prefixME_    = ps.getUntrackedParameter<string>("prefixME", "EcalPreshower"); 
00048   
00049   dqmStore_     = Service<DQMStore>().operator->();
00050   eCount_ = 0;
00051 
00052   fit_ = new TF1("fitShape", fitf, -200, 200, 4);
00053   fit_->SetParameters(50, 10, 0, 0);
00054   
00055   //Histogram init  
00056   for (int i = 0; i < 2; ++i)
00057     for (int j = 0; j < 2; ++j) 
00058       hTiming_[i][j] = 0;
00059  
00060   dqmStore_->setCurrentFolder(prefixME_ + "/ESTimingTask");
00061   
00062   //Booking Histograms
00063   //Notice: Change ESRenderPlugin under DQM/RenderPlugins/src if you change this histogram name.
00064   char histo[200];
00065   for (int i=0 ; i<2; ++i) 
00066     for (int j=0 ; j<2; ++j) {
00067       int iz = (i==0)? 1:-1;
00068       sprintf(histo, "ES Timing Z %d P %d", iz, j+1);
00069       hTiming_[i][j] = dqmStore_->book1D(histo, histo, 81, -20.5, 20.5);
00070       hTiming_[i][j]->setAxisTitle("ES Timing (ns)", 1);
00071     }
00072 
00073   sprintf(histo, "ES 2D Timing");
00074   h2DTiming_ = dqmStore_->book2D(histo, histo, 81, -20.5, 20.5, 81, -20.5, 20.5);
00075   h2DTiming_->setAxisTitle("ES- Timing (ns)", 1);
00076   h2DTiming_->setAxisTitle("ES+ Timing (ns)", 2);
00077 
00078   htESP_ = new TH1F("htESP", "Timing ES+", 81, -20.5, 20.5);
00079   htESM_ = new TH1F("htESM", "Timing ES-", 81, -20.5, 20.5);
00080 }
00081 
00082 ESTimingTask::~ESTimingTask() {
00083   delete htESP_;
00084   delete htESM_;
00085 }
00086 
00087 void ESTimingTask::beginJob(void) {
00088 }
00089 
00090 void ESTimingTask::endJob() {
00091 }
00092 
00093 void ESTimingTask::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
00094   
00095   set(iSetup);
00096 
00097   runNum_ = e.id().run();
00098   eCount_++;
00099   
00100   htESP_->Reset();
00101   htESM_->Reset();
00102   
00103   //Digis
00104   int zside, plane, ix, iy, is;
00105   double adc[3];
00106   //  double para[10];
00107   //double tx[3] = {-5., 20., 45.};
00108   Handle<ESDigiCollection> digis;
00109   if ( e.getByLabel(digilabel_, digis) ) {
00110     
00111     for (ESDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr) {
00112       
00113       ESDataFrame dataframe = (*digiItr);
00114       ESDetId id = dataframe.id();
00115       
00116       zside = id.zside();
00117       plane = id.plane();
00118       ix = id.six();
00119       iy = id.siy();
00120       is = id.strip();
00121       
00122       //if (zside==1 && plane==1 && ix==15 && iy==6) continue;       
00123       if (zside==1 && plane==1 && ix==7 && iy==28) continue;       
00124       if (zside==1 && plane==1 && ix==24 && iy==9 && is==21) continue;       
00125       if (zside==-1 && plane==2 && ix==35 && iy==17 && is==23) continue;       
00126       
00127       int i = (zside==1)? 0:1;
00128       int j = plane-1;
00129       
00130       for (int k=0; k<dataframe.size(); ++k) 
00131         adc[k] = dataframe.sample(k).adc();
00132       
00133       double status = 0;
00134       if (adc[1] < 200) status = 1;
00135       if (fabs(adc[0]) > 10) status = 1;
00136       if (adc[1] < 0 || adc[2] < 0) status = 1;
00137       if (adc[0] > adc[1] || adc[0] > adc[2]) status = 1;
00138       if (adc[2] > adc[1]) status = 1;  
00139       
00140       if (int(status) == 0) {
00141 
00142         double A1 = adc[1];
00143         double A2 = adc[2];
00144         double DeltaT = 25.;
00145         double aaa = (A2 > 0 && A1 > 0) ? log(A2/A1)/n_ : 20.; // if A1=0, t0=20
00146         double bbb = wc_/n_*DeltaT;
00147         double ccc= exp(aaa+bbb);
00148 
00149         double t0 = (2.-ccc)/(1.-ccc) * DeltaT - 5;
00150         hTiming_[i][j]->Fill(t0);
00151         //cout<<"t0 : "<<t0<<endl;
00152         /*
00153         TGraph *gr = new TGraph(3, tx, adc);
00154         fit_->SetParameters(50, 10, wc_, n_);
00155         fit_->FixParameter(2, wc_);
00156         fit_->FixParameter(3, n_);
00157         fit_->Print();
00158         gr->Fit("fitShape", "MQ");
00159         fit_->GetParameters(para); 
00160         delete gr;
00161         //hTiming_[i][j]->Fill(para[1]);
00162         */
00163         //cout<<"ADC : "<<zside<<" "<<plane<<" "<<ix<<" "<<iy<<" "<<is<<" "<<adc[0]<<" "<<adc[1]<<" "<<adc[2]<<" "<<para[1]<<" "<<wc_<<" "<<n_<<endl;
00164 
00165         if (zside == 1) htESP_->Fill(t0);
00166         else if (zside == -1) htESM_->Fill(t0);
00167       }
00168       
00169     }
00170   } else {
00171     LogWarning("ESTimingTask") << digilabel_ << " not available";
00172   }
00173   
00174   if (htESP_->GetEntries() > 0 && htESM_->GetEntries() > 0)
00175     h2DTiming_->Fill(htESM_->GetMean(), htESP_->GetMean());
00176   
00177 }
00178 
00179 void ESTimingTask::set(const edm::EventSetup& es) {
00180 
00181  
00182   es.get<ESGainRcd>().get(esgain_);
00183   const ESGain *gain = esgain_.product();
00184   
00185   int ESGain = (int) gain->getESGain();
00186 
00187   if (ESGain == 1) { // LG
00188     wc_ = 0.0837264;
00189     n_  = 2.016;
00190   } else { // HG
00191     wc_ = 0.07291;
00192     n_  = 1.798; 
00193   }
00194 
00195   //cout<<"gain : "<<ESGain<<endl;
00196   //cout<<wc_<<" "<<n_<<endl;
00197  
00198 }
00199 
00200 //define this as a plug-in
00201 DEFINE_FWK_MODULE(ESTimingTask);