CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESTimingTask.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <fstream>
3 #include <iostream>
4 
18 
19 #include "TStyle.h"
20 #include "TH2F.h"
21 #include "TMath.h"
22 #include "TGraph.h"
23 
24 using namespace cms;
25 using namespace edm;
26 using namespace std;
27 
28 // fit function
29 double fitf(double *x, double *par) {
30 
31  double wc = par[2];
32  double n = par[3]; // n-1 (in fact)
33  double v1 = pow(wc/n*(x[0]-par[1]), n);
34  double v2 = TMath::Exp(n-wc*(x[0]-par[1]));
35  double v = par[0]*v1*v2;
36 
37  if (x[0] < par[1]) v = 0;
38 
39  return v;
40 }
41 
43 
44  digilabel_ = consumes<ESDigiCollection>(ps.getParameter<InputTag>("DigiLabel"));
45  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "EcalPreshower");
46 
47  dqmStore_ = Service<DQMStore>().operator->();
48  eCount_ = 0;
49 
50  fit_ = new TF1("fitShape", fitf, -200, 200, 4);
51  fit_->SetParameters(50, 10, 0, 0);
52 
53  //Histogram init
54  for (int i = 0; i < 2; ++i)
55  for (int j = 0; j < 2; ++j)
56  hTiming_[i][j] = 0;
57 
58  dqmStore_->setCurrentFolder(prefixME_ + "/ESTimingTask");
59 
60  //Booking Histograms
61  //Notice: Change ESRenderPlugin under DQM/RenderPlugins/src if you change this histogram name.
62  char histo[200];
63  for (int i=0 ; i<2; ++i)
64  for (int j=0 ; j<2; ++j) {
65  int iz = (i==0)? 1:-1;
66  sprintf(histo, "ES Timing Z %d P %d", iz, j+1);
67  hTiming_[i][j] = dqmStore_->book1D(histo, histo, 81, -20.5, 20.5);
68  hTiming_[i][j]->setAxisTitle("ES Timing (ns)", 1);
69  }
70 
71  sprintf(histo, "ES 2D Timing");
72  h2DTiming_ = dqmStore_->book2D(histo, histo, 81, -20.5, 20.5, 81, -20.5, 20.5);
73  h2DTiming_->setAxisTitle("ES- Timing (ns)", 1);
74  h2DTiming_->setAxisTitle("ES+ Timing (ns)", 2);
75 
76  htESP_ = new TH1F("htESP", "Timing ES+", 81, -20.5, 20.5);
77  htESM_ = new TH1F("htESM", "Timing ES-", 81, -20.5, 20.5);
78 }
79 
81  delete htESP_;
82  delete htESM_;
83 }
84 
86 }
87 
89 }
90 
91 void ESTimingTask::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
92 
93  set(iSetup);
94 
95  runNum_ = e.id().run();
96  eCount_++;
97 
98  htESP_->Reset();
99  htESM_->Reset();
100 
101  //Digis
102  int zside, plane, ix, iy, is;
103  double adc[3];
104  // double para[10];
105  //double tx[3] = {-5., 20., 45.};
107  if ( e.getByToken(digilabel_, digis) ) {
108 
109  for (ESDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr) {
110 
111  ESDataFrame dataframe = (*digiItr);
112  ESDetId id = dataframe.id();
113 
114  zside = id.zside();
115  plane = id.plane();
116  ix = id.six();
117  iy = id.siy();
118  is = id.strip();
119 
120  //if (zside==1 && plane==1 && ix==15 && iy==6) continue;
121  if (zside==1 && plane==1 && ix==7 && iy==28) continue;
122  if (zside==1 && plane==1 && ix==24 && iy==9 && is==21) continue;
123  if (zside==-1 && plane==2 && ix==35 && iy==17 && is==23) continue;
124 
125  int i = (zside==1)? 0:1;
126  int j = plane-1;
127 
128  for (int k=0; k<dataframe.size(); ++k)
129  adc[k] = dataframe.sample(k).adc();
130 
131  double status = 0;
132  if (adc[1] < 200) status = 1;
133  if (fabs(adc[0]) > 10) status = 1;
134  if (adc[1] < 0 || adc[2] < 0) status = 1;
135  if (adc[0] > adc[1] || adc[0] > adc[2]) status = 1;
136  if (adc[2] > adc[1]) status = 1;
137 
138  if (int(status) == 0) {
139 
140  double A1 = adc[1];
141  double A2 = adc[2];
142  double DeltaT = 25.;
143  double aaa = (A2 > 0 && A1 > 0) ? log(A2/A1)/n_ : 20.; // if A1=0, t0=20
144  double bbb = wc_/n_*DeltaT;
145  double ccc= exp(aaa+bbb);
146 
147  double t0 = (2.-ccc)/(1.-ccc) * DeltaT - 5;
148  hTiming_[i][j]->Fill(t0);
149  //cout<<"t0 : "<<t0<<endl;
150  /*
151  TGraph *gr = new TGraph(3, tx, adc);
152  fit_->SetParameters(50, 10, wc_, n_);
153  fit_->FixParameter(2, wc_);
154  fit_->FixParameter(3, n_);
155  fit_->Print();
156  gr->Fit("fitShape", "MQ");
157  fit_->GetParameters(para);
158  delete gr;
159  //hTiming_[i][j]->Fill(para[1]);
160  */
161  //cout<<"ADC : "<<zside<<" "<<plane<<" "<<ix<<" "<<iy<<" "<<is<<" "<<adc[0]<<" "<<adc[1]<<" "<<adc[2]<<" "<<para[1]<<" "<<wc_<<" "<<n_<<endl;
162 
163  if (zside == 1) htESP_->Fill(t0);
164  else if (zside == -1) htESM_->Fill(t0);
165  }
166 
167  }
168  } else {
169  LogWarning("ESTimingTask") << "DigiCollection not available";
170  }
171 
172  if (htESP_->GetEntries() > 0 && htESM_->GetEntries() > 0)
173  h2DTiming_->Fill(htESM_->GetMean(), htESP_->GetMean());
174 
175 }
176 
178 
179 
180  es.get<ESGainRcd>().get(esgain_);
181  const ESGain *gain = esgain_.product();
182 
183  int ESGain = (int) gain->getESGain();
184 
185  if (ESGain == 1) { // LG
186  wc_ = 0.0837264;
187  n_ = 2.016;
188  } else { // HG
189  wc_ = 0.07291;
190  n_ = 1.798;
191  }
192 
193  //cout<<"gain : "<<ESGain<<endl;
194  //cout<<wc_<<" "<<n_<<endl;
195 
196 }
197 
198 //define this as a plug-in
int adc(sample_type sample)
get the ADC sample (12 bits)
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
virtual void beginJob(void)
Definition: ESTimingTask.cc:85
double fitf(double *x, double *par)
Definition: ESTimingTask.cc:29
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
Definition: ESGain.h:5
const ESDetId & id() const
Definition: ESDataFrame.h:21
void set(const edm::EventSetup &es)
int size() const
Definition: ESDataFrame.h:23
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: ESTimingTask.cc:91
virtual ~ESTimingTask()
Definition: ESTimingTask.cc:80
const ESSample & sample(int i) const
Definition: ESDataFrame.h:26
int j
Definition: DBlmapReader.cc:9
int zside() const
Definition: ESDetId.h:44
int k[5][pyjets_maxn]
DEFINE_FWK_MODULE(CaloMETProducer)
float getESGain() const
Definition: ESGain.h:11
const T & get() const
Definition: EventSetup.h:55
edm::EventID id() const
Definition: EventBase.h:56
virtual void endJob(void)
Definition: ESTimingTask.cc:88
int adc() const
get the ADC sample (singed 16 bits)
Definition: ESSample.h:18
Definition: DDAxes.h:10
tuple status
Definition: ntuplemaker.py:245
ESTimingTask(const edm::ParameterSet &ps)
Definition: ESTimingTask.cc:42
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40