CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalBarrelDigisValidation.cc
Go to the documentation of this file.
1 /*
2  * \file EcalBarrelDigisValidation.cc
3  *
4  * \author F. Cossutti
5  *
6 */
7 
11 
12 using namespace cms;
13 using namespace edm;
14 using namespace std;
15 
17  EBdigiCollection_(consumes<EBDigiCollection>(ps.getParameter<edm::InputTag>("EBdigiCollection")))
18 {
19 
20  // verbosity switch
21  verbose_ = ps.getUntrackedParameter<bool>("verbose", false);
22 
23  dbe_ = 0;
24 
25  // get hold of back-end interface
26  dbe_ = Service<DQMStore>().operator->();
27 
28  if ( dbe_ ) {
29  if ( verbose_ ) {
30  dbe_->setVerbose(1);
31  } else {
32  dbe_->setVerbose(0);
33  }
34  }
35 
36  if ( dbe_ ) {
37  if ( verbose_ ) dbe_->showDirStructure();
38  }
39 
40  gainConv_[1] = 1.;
41  gainConv_[2] = 2.;
42  gainConv_[3] = 12.;
43  gainConv_[0] = 12.; // saturated channels
44  barrelADCtoGeV_ = 0.035;
45  endcapADCtoGeV_ = 0.06;
46 
48 
50 
52 
53  for (int i = 0; i < 10 ; i++ ) {
54  meEBDigiADCAnalog_[i] = 0;
55  meEBDigiADCgS_[i] = 0;
56  meEBDigiADCg1_[i] = 0;
57  meEBDigiADCg6_[i] = 0;
58  meEBDigiADCg12_[i] = 0;
59  meEBDigiGain_[i] = 0;
60  }
61 
62  meEBPedestal_ = 0;
63 
65 
67 
69 
70  Char_t histo[200];
71 
72 
73  if ( dbe_ ) {
74  dbe_->setCurrentFolder("EcalDigisV/EcalDigiTask");
75 
76  sprintf (histo, "EcalDigiTask Barrel occupancy" ) ;
77  meEBDigiOccupancy_ = dbe_->book2D(histo, histo, 360, 0., 360., 170, -85., 85.);
78 
79  sprintf (histo, "EcalDigiTask Barrel digis multiplicity" ) ;
80  meEBDigiMultiplicity_ = dbe_->book1D(histo, histo, 612, 0., 61200);
81 
82  sprintf (histo, "EcalDigiTask Barrel global pulse shape" ) ;
83  meEBDigiADCGlobal_ = dbe_->bookProfile(histo, histo, 10, 0, 10, 10000, 0., 1000.) ;
84 
85  for (int i = 0; i < 10 ; i++ ) {
86 
87  sprintf (histo, "EcalDigiTask Barrel analog pulse %02d", i+1) ;
88  meEBDigiADCAnalog_[i] = dbe_->book1D(histo, histo, 4000, 0., 400.);
89 
90  sprintf (histo, "EcalDigiTask Barrel ADC pulse %02d Gain 0 - Saturated", i+1) ;
91  meEBDigiADCgS_[i] = dbe_->book1D(histo, histo, 4096, -0.5, 4095.5);
92 
93  sprintf (histo, "EcalDigiTask Barrel ADC pulse %02d Gain 1", i+1) ;
94  meEBDigiADCg1_[i] = dbe_->book1D(histo, histo, 4096, -0.5, 4095.5);
95 
96  sprintf (histo, "EcalDigiTask Barrel ADC pulse %02d Gain 6", i+1) ;
97  meEBDigiADCg6_[i] = dbe_->book1D(histo, histo, 4096, -0.5, 4095.5);
98 
99  sprintf (histo, "EcalDigiTask Barrel ADC pulse %02d Gain 12", i+1) ;
100  meEBDigiADCg12_[i] = dbe_->book1D(histo, histo, 4096, -0.5, 4095.5);
101 
102  sprintf (histo, "EcalDigiTask Barrel gain pulse %02d", i+1) ;
103  meEBDigiGain_[i] = dbe_->book1D(histo, histo, 4, 0, 4);
104 
105  }
106 
107  sprintf (histo, "EcalDigiTask Barrel pedestal for pre-sample" ) ;
108  meEBPedestal_ = dbe_->book1D(histo, histo, 4096, -0.5, 4095.5) ;
109 
110  sprintf (histo, "EcalDigiTask Barrel maximum position gt 100 ADC" ) ;
111  meEBMaximumgt100ADC_ = dbe_->book1D(histo, histo, 10, 0., 10.) ;
112 
113  sprintf (histo, "EcalDigiTask Barrel maximum position gt 10 ADC" ) ;
114  meEBMaximumgt10ADC_ = dbe_->book1D(histo, histo, 10, 0., 10.) ;
115 
116  sprintf (histo, "EcalDigiTask Barrel ADC counts after gain switch" ) ;
117  meEBnADCafterSwitch_ = dbe_->book1D(histo, histo, 10, 0., 10.) ;
118 
119  }
120 
121 }
122 
124 
125 }
126 
128 
130 
131 }
132 
134 
135 }
136 
138 
139  //LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();
140 
141  Handle<EBDigiCollection> EcalDigiEB;
142 
143  e.getByToken( EBdigiCollection_ , EcalDigiEB );
144 
145  //Return if no Barrel data
146  if( !EcalDigiEB.isValid() ) return;
147 
148  // BARREL
149 
150  // loop over Digis
151 
152  const EBDigiCollection * barrelDigi = EcalDigiEB.product () ;
153 
154  std::vector<double> ebAnalogSignal ;
155  std::vector<double> ebADCCounts ;
156  std::vector<double> ebADCGains ;
157  ebAnalogSignal.reserve(EBDataFrame::MAXSAMPLES);
158  ebADCCounts.reserve(EBDataFrame::MAXSAMPLES);
159  ebADCGains.reserve(EBDataFrame::MAXSAMPLES);
160 
161  int nDigis = 0;
162 
163  for (unsigned int digis=0; digis<EcalDigiEB->size(); ++digis)
164  {
165 
166  EBDataFrame ebdf = (*barrelDigi)[digis];
167  int nrSamples = ebdf.size();
168 
169  EBDetId ebid = ebdf.id () ;
170 
171  nDigis++;
172  if (meEBDigiOccupancy_) meEBDigiOccupancy_->Fill( ebid.iphi(), ebid.ieta() );
173 
174  double Emax = 0. ;
175  int Pmax = 0 ;
176  double pedestalPreSample = 0.;
177  double pedestalPreSampleAnalog = 0.;
178  int countsAfterGainSwitch = -1;
179  double higherGain = 1.;
180  int higherGainSample = 0;
181 
182  for (int sample = 0 ; sample < nrSamples; ++sample) {
183  ebAnalogSignal[sample] = 0.;
184  ebADCCounts[sample] = 0.;
185  ebADCGains[sample] = 0.;
186  }
187 
188  for (int sample = 0 ; sample < nrSamples; ++sample)
189  {
190  EcalMGPASample thisSample = ebdf[sample];
191 
192  ebADCCounts[sample] = (thisSample.adc());
193  ebADCGains[sample] = (thisSample.gainId());
194  ebAnalogSignal[sample] = (ebADCCounts[sample]*gainConv_[(int)ebADCGains[sample]]*barrelADCtoGeV_);
195 
196  if (Emax < ebAnalogSignal[sample] ) {
197  Emax = ebAnalogSignal[sample] ;
198  Pmax = sample ;
199  }
200 
201  if ( sample < 3 ) {
202  pedestalPreSample += ebADCCounts[sample] ;
203  pedestalPreSampleAnalog += ebADCCounts[sample]*gainConv_[(int)ebADCGains[sample]]*barrelADCtoGeV_ ;
204  }
205 
206  if ( sample > 0 && ( ((ebADCGains[sample] > ebADCGains[sample-1]) && (ebADCGains[sample-1]!=0)) || (countsAfterGainSwitch<0 && ebADCGains[sample]==0)) ) {
207  higherGain = ebADCGains[sample];
208  higherGainSample = sample;
209  countsAfterGainSwitch = 1;
210  }
211 
212  if ( (higherGain > 1 && (higherGainSample != sample) && (ebADCGains[sample] == higherGain)) || (higherGain==3 && (higherGainSample != sample) && (ebADCGains[sample]==0)) || (higherGain==0 && (higherGainSample != sample) && ((ebADCGains[sample] == 3) || (ebADCGains[sample]==0))) ) { countsAfterGainSwitch++ ; }
213  }
214 
215  pedestalPreSample /= 3. ;
216  pedestalPreSampleAnalog /= 3. ;
217 
218  LogDebug("DigiInfo") << "Barrel Digi for EBDetId = " << ebid.rawId() << " eta,phi " << ebid.ieta() << " " << ebid.iphi() ;
219  for ( int i = 0; i < 10 ; i++ ) {
220  LogDebug("DigiInfo") << "sample " << i << " ADC = " << ebADCCounts[i] << " gain = " << ebADCGains[i] << " Analog = " << ebAnalogSignal[i];
221  }
222  LogDebug("DigiInfo") << "Maximum energy = " << Emax << " in sample " << Pmax << " Pedestal from pre-sample = " << pedestalPreSampleAnalog;
223  if ( countsAfterGainSwitch > 0 ) LogDebug("DigiInfo") << "Counts after switch " << countsAfterGainSwitch;
224 
225  if ( countsAfterGainSwitch > 0 && countsAfterGainSwitch < 5 ) {
226  edm::LogWarning("DigiWarning") << "Wrong number of counts after gain switch before next switch! " << countsAfterGainSwitch ;
227  for ( int i = 0; i < 10 ; i++ ) {
228  edm::LogWarning("DigiWarning") << "sample " << i << " ADC = " << ebADCCounts[i] << " gain = " << ebADCGains[i] << " Analog = " << ebAnalogSignal[i];
229  }
230  }
231 
232  for ( int i = 0 ; i < 10 ; i++ ) {
233  if (meEBDigiADCGlobal_ && (Emax-pedestalPreSampleAnalog*gainConv_[(int)ebADCGains[Pmax]]) > 100.*barrelADCtoGeV_) meEBDigiADCGlobal_->Fill( i , ebAnalogSignal[i] ) ;
234  if (meEBDigiADCAnalog_[i]) meEBDigiADCAnalog_[i]->Fill( ebAnalogSignal[i] ) ;
235 
236  if ( ebADCGains[i] == 0) {
237  if (meEBDigiADCgS_[i]) meEBDigiADCgS_[i]->Fill( ebADCCounts[i] ) ;
238  }
239  else if ( ebADCGains[i] == 3 ) {
240  if (meEBDigiADCg1_[i]) meEBDigiADCg1_[i]->Fill( ebADCCounts[i] ) ;
241  }
242  else if ( ebADCGains[i] == 2 ) {
243  if (meEBDigiADCg6_[i]) meEBDigiADCg6_[i]->Fill( ebADCCounts[i] ) ;
244  }
245  else if ( ebADCGains[i] == 1 ) {
246  if (meEBDigiADCg12_[i]) meEBDigiADCg12_[i]->Fill( ebADCCounts[i] ) ;
247  }
248  if (meEBDigiGain_[i]) meEBDigiGain_[i]->Fill( ebADCGains[i] ) ;
249  }
250 
251  if (meEBPedestal_) meEBPedestal_->Fill ( pedestalPreSample ) ;
252  if (meEBMaximumgt10ADC_ && (Emax-pedestalPreSampleAnalog*gainConv_[(int)ebADCGains[Pmax]]) > 10.*barrelADCtoGeV_) meEBMaximumgt10ADC_->Fill( Pmax ) ;
253  if (meEBMaximumgt100ADC_ && (Emax-pedestalPreSampleAnalog*gainConv_[(int)ebADCGains[Pmax]]) > 100.*barrelADCtoGeV_) meEBMaximumgt100ADC_->Fill( Pmax ) ;
254  if (meEBnADCafterSwitch_) meEBnADCafterSwitch_->Fill( countsAfterGainSwitch ) ;
255 
256  }
257 
259 
260 }
261 
263  {
264 
265  // ADC -> GeV Scale
267  eventSetup.get<EcalADCToGeVConstantRcd>().get(pAgc);
268  const EcalADCToGeVConstant* agc = pAgc.product();
269 
270  EcalMGPAGainRatio * defaultRatios = new EcalMGPAGainRatio();
271 
272  gainConv_[1] = 1.;
273  gainConv_[2] = defaultRatios->gain12Over6() ;
274  gainConv_[3] = gainConv_[2]*(defaultRatios->gain6Over1()) ;
275  gainConv_[0] = gainConv_[2]*(defaultRatios->gain6Over1()) ;
276 
277  LogDebug("EcalDigi") << " Gains conversions: " << "\n" << " g0 = " << gainConv_[0] << "\n" << " g1 = " << gainConv_[1] << "\n" << " g2 = " << gainConv_[2] << "\n" << " g3 = " << gainConv_[3];
278 
279  delete defaultRatios;
280 
281  const double barrelADCtoGeV_ = agc->getEBValue();
282  LogDebug("EcalDigi") << " Barrel GeV/ADC = " << barrelADCtoGeV_;
283  const double endcapADCtoGeV_ = agc->getEEValue();
284  LogDebug("EcalDigi") << " Endcap GeV/ADC = " << endcapADCtoGeV_;
285 
286 }
287 
288 
#define LogDebug(id)
void analyze(edm::Event const &e, edm::EventSetup const &c)
Analyze.
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::map< int, double, std::less< int > > gainConv_
key_type id() const
Definition: EBDataFrame.h:31
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
MonitorElement * meEBDigiADCAnalog_[10]
int gainId() const
get the gainId (2 bits)
int size() const
Definition: EcalDataFrame.h:26
void beginRun(edm::Run const &, edm::EventSetup const &c)
void Fill(long long x)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
void checkCalibrations(edm::EventSetup const &c)
edm::EDGetTokenT< EBDigiCollection > EBdigiCollection_
EcalBarrelDigisValidation(const edm::ParameterSet &ps)
Constructor.
float gain6Over1() const
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
bool isValid() const
Definition: HandleBase.h:76
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
float gain12Over6() const
T const * product() const
Definition: Handle.h:81
MonitorElement * meEBDigiADCg12_[10]
static const int MAXSAMPLES
Definition: EcalDataFrame.h:48
Definition: Run.h:41
int adc() const
get the ADC sample (12 bits)