CMS 3D CMS Logo

PixelResolutionHistograms.cc
Go to the documentation of this file.
1 //
2 // The implementation of the PixelResolutinHistograms.cc class. Please
3 // look at PixelResolutionHistograms.h header file for the interface.
4 //
5 //------------------------------------------------------------------------------
6 
7 // The switch, undefined in CMSSW release, and defined by standalone compilation script:
8 
9 
10 #ifdef SI_PIXEL_TEMPLATE_STANDALONE
11 //
12 //--- Stand-alone: Include a the header file from the local directory, as well as
13 // dummy implementations of SimpleHistogramGenerator, LogInfo, LogError and LogDebug...
14 //
16 //
17 class TH1F;
18 class TH2F;
20 public:
21  SimpleHistogramGenerator(TH1F * hist) : hist_(hist) {};
22 private:
23  TH1F * hist_; // we don't own it
24 };
25 #define LOGDEBUG std::cout
26 #define LOGERROR std::cout
27 #define LOGINFO std::cout
28 //
29 #else
30 //--- We're inside a CMSSW release: Include the real thing.
31 //
36 //
37 #define LOGDEBUG LogDebug("")
38 #define LOGERROR edm::LogError("Error")
39 #define LOGINFO edm::LogInfo("Info")
40 //
41 #endif
42 
43 
44 
45 
46 // Generic C stuff
47 #include <cmath>
48 #include <iostream>
49 #include <string>
50 
51 // ROOT
52 #include <TFile.h>
53 #include <TH1F.h>
54 #include <TH2F.h>
55 
56 // Global definitions
57 const float cmtomicron = 10000.0;
58 
59 
60 //------------------------------------------------------------------------------
61 // Constructor: Books the FastSim Histograms, given the input parameters
62 // which are provided as arguments. These variables are then const inside
63 // the class. (That is, once we make the histograms, we can't change the
64 // definition of the binning.)
65 //------------------------------------------------------------------------------
67 PixelResolutionHistograms( std::string filename, // ROOT file for histograms
68  std::string rootdir, // Subdirectory in the file, "" if none
69  std::string descTitle, // Descriptive title
70  unsigned int detType, // Where we are... (&&& do we need this?)
71  double cotbetaBinWidth,
72  double cotbetaLowEdge,
73  int cotbetaBins,
74  double cotalphaBinWidth,
75  double cotalphaLowEdge,
76  int cotalphaBins) //,
77  //int qbinWidth,
78  //int qbins )
79  : weOwnHistograms_(true), // we'll be making some histos
80  detType_ ( detType ),
81  cotbetaBinWidth_ ( cotbetaBinWidth ),
82  cotbetaLowEdge_ ( cotbetaLowEdge ),
83  cotbetaBins_ ( cotbetaBins ),
84  cotalphaBinWidth_ ( cotalphaBinWidth ),
85  cotalphaLowEdge_ ( cotalphaLowEdge ),
86  cotalphaBins_ ( cotalphaBins ),
87  qbinWidth_ ( 1 ),
88  qbins_ ( 4 ),
89  binningHisto_(nullptr),
90  resMultiPixelXHist_(), resSinglePixelXHist_(), // all to nullptr
91  resMultiPixelYHist_(), resSinglePixelYHist_(), // all to nullptr
92  qbinHist_(), // all to nullptr
93  file_(nullptr),
94  status_(0),
95  resMultiPixelXGen_(), resSinglePixelXGen_(),
96  resMultiPixelYGen_(), resSinglePixelYGen_(),
97  qbinGen_()
98 {
99 
100  file_ = std::make_unique<TFile>( filename.c_str(), "RECREATE" );
101  //Resolution binning
102  // const double cotbetaBinWidth = 1.0;
103  // const double cotbetaLowEdge = -11.5 ;
104  // const int cotbetaBins = 23;
105  // const double cotalphaBinWidth = 0.08 ;
106  // const double cotalphaLowEdge = -0.36 ;
107  // const int cotalphaBins = 9;
108  // const int qbinWidth = 1;
109  // const int qbins = 4;
110 
111  // Dummy 2D histogram to store binning:
112  binningHisto_ = new TH2F( "ResHistoBinning", descTitle.c_str(),
113  cotbetaBins, cotbetaLowEdge, cotbetaLowEdge + cotbetaBins*cotbetaBinWidth,
114  cotalphaBins, cotalphaLowEdge, cotalphaLowEdge + cotalphaBins*cotalphaBinWidth );
115 
116  // Store detType in the underflow bin
117  binningHisto_->SetBinContent(0, 0, detType_);
118 
119  // All other histograms:
120  Char_t histo[200];
121  Char_t title[200];
122  //
123  //--- Histograms for clusters with multiple pixels hit in a given direction.
124  //
125  for( int ii=0; ii<cotbetaBins_; ii++ ) {
126  for( int jj=0; jj<cotalphaBins_; jj++ ) {
127  for( int kk=0; kk<qbins_; kk++ ) {
128  //
129  sprintf( histo, "hx%d1%02d%d%d", detType_, ii+1, jj+1, kk+1 ); //information of bits of histogram names
130  //--- First bit 1/0 barrel/forward, second 1/0 multi/single, cotbeta, cotalpha, qbins
131  sprintf( title, "cotbeta %.1f-%.1f cotalpha %.2f-%.2f qbin %d npixel>1 X",
132  cotbetaLowEdge_ + ii*cotbetaBinWidth_ , cotbetaLowEdge_ + (ii+1)*cotbetaBinWidth_,
133  cotalphaLowEdge_ +jj*cotalphaBinWidth_, cotalphaLowEdge_ +(jj+1)*cotalphaBinWidth_,
134  kk+1 );
135  //
136  resMultiPixelXHist_ [ ii ][ jj ][ kk ] = new TH1F(histo, title, 1000, -0.05, 0.05);
137 
138  sprintf( histo, "hy%d1%02d%d%d", detType_, ii+1, jj+1, kk+1 );
139  sprintf( title, "cotbeta %.1f-%.1f cotalpha %.2f-%.2f qbin %d npixel>1 Y",
140  cotbetaLowEdge_ + ii*cotbetaBinWidth_ , cotbetaLowEdge_ + (ii+1)*cotbetaBinWidth_,
141  cotalphaLowEdge_ +jj*cotalphaBinWidth_, cotalphaLowEdge_ +(jj+1)*cotalphaBinWidth_,
142  kk+1 );
143  //
144  resMultiPixelYHist_ [ ii ][ jj ][ kk ] = new TH1F(histo, title, 1000, -0.05, 0.05);
145  }
146  }
147  }
148 
149 
150  //
151  //--- Histograms for clusters where only a single pixel was hit in a given direction.
152  //
153  for( int ii=0; ii<cotbetaBins_; ii++) {
154  for( int jj=0; jj<cotalphaBins_; jj++) {
155 
156  sprintf( histo, "hx%d0%02d%d", detType_, ii+1, jj+1 ); //information of bits of histogram names
157  //first bit 1/0 barrel/forward, second 1/0 multi/single, cotbeta, cotalpha
158  sprintf( title, "cotbeta %.1f-%.1f cotalpha %.2f-%.2f npixel=1 X",
159  cotbetaLowEdge_ + ii*cotbetaBinWidth_ , cotbetaLowEdge_ + (ii+1)*cotbetaBinWidth_,
160  cotalphaLowEdge_ +jj*cotalphaBinWidth_, cotalphaLowEdge_ +(jj+1)*cotalphaBinWidth_ );
161  //
162  resSinglePixelXHist_ [ ii ][ jj ] = new TH1F(histo, title, 1000, -0.05, 0.05);
163 
164  sprintf( histo, "hy%d0%02d%d", detType_, ii+1, jj+1 );
165  sprintf( title, "cotbeta %.1f-%.1f cotalpha %.2f-%.2f npixel=1 Y",
166  cotbetaLowEdge_ + ii*cotbetaBinWidth_ , cotbetaLowEdge_ + (ii+1)*cotbetaBinWidth_,
167  cotalphaLowEdge_ +jj*cotalphaBinWidth_, cotalphaLowEdge_ +(jj+1)*cotalphaBinWidth_ );
168  //
169  resSinglePixelYHist_ [ ii ][ jj ] = new TH1F(histo, title, 1000, -0.05, 0.05);
170 
171  sprintf( histo, "hqbin%d%02d%d", detType_, ii+1, jj+1 );
172  sprintf( title, "cotbeta %.1f-%.1f cotalpha %.2f-%.2f qbin",
173  cotbetaLowEdge_ + ii*cotbetaBinWidth_ , cotbetaLowEdge_ + (ii+1)*cotbetaBinWidth_,
174  cotalphaLowEdge_ +jj*cotalphaBinWidth_, cotalphaLowEdge_ +(jj+1)*cotalphaBinWidth_ );
175  //
176  qbinHist_ [ ii ][ jj ] = new TH1F(histo, title, 4, -0.49, 3.51);
177 
178  }
179  }
180 
181 }
182 
183 
184 
185 //------------------------------------------------------------------------------
186 // Another constructor: load the histograms from one file.
187 // filename = full path to filename
188 // rootdir = ROOT directory inside the file
189 //
190 // The other parameters are the same (needed later) and must correspond
191 // to the histograms we are loading from the file.
192 //------------------------------------------------------------------------------
195  std::string rootdir,
196  int detType,
197  bool ignore_multi,
198  bool ignore_single,
199  bool ignore_qBin )
200  : weOwnHistograms_(false), // resolution histograms are owned by the ROOT file
201  detType_ (-1),
202  cotbetaBinWidth_ (0),
203  cotbetaLowEdge_ (0),
204  cotbetaBins_ (0),
205  cotalphaBinWidth_ (0),
206  cotalphaLowEdge_ (0),
207  cotalphaBins_ (0),
208  qbinWidth_ (1),
209  qbins_ (4),
211  resMultiPixelXHist_(), resSinglePixelXHist_(), // all to nullptr
212  resMultiPixelYHist_(), resSinglePixelYHist_(), // all to nullptr
213  qbinHist_(), // all to nullptr
214  file_(nullptr),
215  status_(0),
218  qbinGen_()
219 {
220  Char_t histo[200]; // the name of the histogram
221  Char_t title[200]; // histo title, for debugging and sanity checking (compare inside file)
222  TH1F * tmphist = nullptr; // cache for histo pointer
223 
224  //--- Open the file for reading.
225  file_ = std::make_unique<TFile>( filename.c_str() ,"READ");
226  if ( !file_ ) {
227  status_ = 1;
228  LOGERROR << "PixelResolutionHistograms:: Error, file " << filename << " not found.";
229  return; // PixelTemplateSmearerBase will throw an exception upon our return.
230  }
231 
232  //--- The dummy 2D histogram with the binning of cot\beta and cot\alpha:
233  binningHisto_ = (TH2F*) file_->Get( Form( "%s%s" , rootdir.c_str(), "ResHistoBinning" ) );
234  if ( !binningHisto_ ) {
235  status_ = 11;
236  LOGERROR << "PixelResolutionHistograms:: Error, binning histogrram ResHistoBinning not found.";
237  return; // PixelTemplateSmearerBase will throw an exception upon our return.
238  }
239 
240  if ( detType == -1 ) {
241  //--- Fish out detType from the underflow bin:
242  detType_ = binningHisto_->GetBinContent(0, 0);
243  }
244  else {
245  detType_ = detType; // constructor's argument overrides what's in ResHistoBinning histogram.
246  }
247 
248  //--- Now we fill the binning variables:
249  cotbetaAxis_ = binningHisto_->GetXaxis();
250  cotbetaBinWidth_ = binningHisto_->GetXaxis()->GetBinWidth(1); // assume all same width
251  cotbetaLowEdge_ = binningHisto_->GetXaxis()->GetXmin(); // low edge of the first bin
252  cotbetaBins_ = binningHisto_->GetXaxis()->GetNbins();
253  cotalphaAxis_ = binningHisto_->GetYaxis();
254  cotalphaBinWidth_ = binningHisto_->GetYaxis()->GetBinWidth(1); // assume all same width;
255  cotalphaLowEdge_ = binningHisto_->GetYaxis()->GetXmin(); // low edge of the first bin;
256  cotalphaBins_ = binningHisto_->GetYaxis()->GetNbins();
257 
258  //--- We want the following information to show up in *every* log file!
259  // LOGINFO << std::endl
260  std::cout << std::endl
261  << "Loading pixel resolution file = " << filename << std::endl
262  << " cotBeta[" << cotbetaLowEdge_ <<","<< cotbetaBinWidth_ <<","<< cotbetaBins_ << "]" << std::endl
263  << " cotAlpha[" << cotalphaLowEdge_ <<","<< cotalphaBinWidth_ <<","<< cotalphaBins_ << "]"
264  << std::endl;
265 
266 
267  if ( !ignore_multi ) {
268  //
269  //--- Histograms for clusters with multiple pixels hit in a given direction.
270  //
271  for( int ii=0; ii<cotbetaBins_; ii++ ) {
272  for( int jj=0; jj<cotalphaBins_; jj++ ) {
273  for( int kk=0; kk<qbins_; kk++ ) {
274  //
275  sprintf( histo, "hx%d1%02d%d%d", detType_, ii+1, jj+1, kk+1 ); //information of bits of histogram names
276  //--- First bit 1/0 barrel/forward, second 1/0 multi/single, cotbeta, cotalpha, qbins
277  sprintf( title, "cotbeta %.1f-%.1f cotalpha %.2f-%.2f qbin %d npixel>1 X",
278  cotbetaLowEdge_ + ii*cotbetaBinWidth_ , cotbetaLowEdge_ + (ii+1)*cotbetaBinWidth_,
279  cotalphaLowEdge_ +jj*cotalphaBinWidth_, cotalphaLowEdge_ +(jj+1)*cotalphaBinWidth_,
280  kk+1 );
281  //
282  tmphist = (TH1F*) file_->Get( Form( "%s%s" , rootdir.c_str(), histo ) );
283  if ( !tmphist ) {
284  status_ = 2;
285  LOGERROR << "Failed to find histogram=" << std::string( histo );
286  return;
287  }
288  LOGDEBUG << "Found histo " << std::string(histo)
289  << " with title = " << std::string( tmphist->GetTitle() ) << std::endl;
290  if ( tmphist->GetEntries() < 5 ) {
291  LOGINFO << "Histogram " << std::string(histo) << " has only " << tmphist->GetEntries()
292  << " entries. Trouble ahead." << std::endl;
293  }
294  resMultiPixelXHist_ [ ii ][ jj ][ kk ] = tmphist;
295  resMultiPixelXGen_ [ ii ][ jj ][ kk ] = new SimpleHistogramGenerator( tmphist );
296 
297 
298  sprintf( histo, "hy%d1%02d%d%d", detType_, ii+1, jj+1, kk+1 );
299  sprintf( title, "cotbeta %.1f-%.1f cotalpha %.2f-%.2f qbin %d npixel>1 Y",
300  cotbetaLowEdge_ + ii*cotbetaBinWidth_ , cotbetaLowEdge_ + (ii+1)*cotbetaBinWidth_,
301  cotalphaLowEdge_ +jj*cotalphaBinWidth_, cotalphaLowEdge_ +(jj+1)*cotalphaBinWidth_,
302  kk+1 );
303  //
304  tmphist = (TH1F*) file_->Get( Form( "%s%s" , rootdir.c_str(), histo ) );
305  if ( !tmphist ) {
306  status_ = 3;
307  LOGERROR << "Failed to find histogram=" << std::string( histo );
308  return;
309  }
310  LOGDEBUG << "Found histo " << std::string(histo)
311  << " with title = " << std::string( tmphist->GetTitle() ) << std::endl;
312  if ( tmphist->GetEntries() < 5 ) {
313  LOGINFO << "Histogram " << std::string(histo) << " has only " << tmphist->GetEntries()
314  << " entries. Trouble ahead." << std::endl;
315  }
316  resMultiPixelYHist_ [ ii ][ jj ][ kk ] = tmphist;
317  resMultiPixelYGen_ [ ii ][ jj ][ kk ] = new SimpleHistogramGenerator( tmphist );
318  }
319  }
320  }
321  //
322  } // if (not ignore multi)
323 
324 
325  //
326  //--- Histograms for clusters where only a single pixel was hit in a given direction.
327  //
328  for( int ii=0; ii<cotbetaBins_; ii++) {
329  for( int jj=0; jj<cotalphaBins_; jj++) {
330 
331  //--- Single pixel, along X.
332  //
333  sprintf( histo, "hx%d0%02d%d", detType_, ii+1, jj+1 ); //information of bits of histogram names
334  //--- First bit 1/0 barrel/forward, second 1/0 multi/single, cotbeta, cotalpha
335  sprintf( title, "cotbeta %.1f-%.1f cotalpha %.2f-%.2f npixel=1 X",
336  cotbetaLowEdge_ + ii*cotbetaBinWidth_ , cotbetaLowEdge_ + (ii+1)*cotbetaBinWidth_,
337  cotalphaLowEdge_ +jj*cotalphaBinWidth_, cotalphaLowEdge_ +(jj+1)*cotalphaBinWidth_ );
338  //
339  tmphist = (TH1F*) file_->Get( Form( "%s%s" , rootdir.c_str(), histo ) );
340  if ( !tmphist ) {
341  if ( !ignore_single ) {
342  LOGERROR << "Failed to find histogram=" << std::string( histo );
343  status_ = 4;
344  return;
345  }
346  }
347  else {
348  LOGDEBUG << "Found histo " << std::string(histo)
349  << " with title = " << std::string( tmphist->GetTitle() ) << std::endl;
350  LOGDEBUG << "Found histo with title = " << std::string( tmphist->GetTitle() ) << std::endl;
351  if ( tmphist->GetEntries() < 5 ) {
352  LOGINFO << "Histogram " << std::string(histo) << " has only " << tmphist->GetEntries()
353  << " entries. Trouble ahead." << std::endl;
354  }
355  resSinglePixelXHist_ [ ii ][ jj ] = tmphist;
356  resSinglePixelXGen_ [ ii ][ jj ] = new SimpleHistogramGenerator( tmphist );
357  }
358 
359 
360  //--- Single pixel, along Y.
361  //
362  sprintf( histo, "hy%d0%02d%d", detType_, ii+1, jj+1 );
363  sprintf( title, "cotbeta %.1f-%.1f cotalpha %.2f-%.2f npixel=1 Y",
364  cotbetaLowEdge_ + ii*cotbetaBinWidth_ , cotbetaLowEdge_ + (ii+1)*cotbetaBinWidth_,
365  cotalphaLowEdge_ +jj*cotalphaBinWidth_, cotalphaLowEdge_ +(jj+1)*cotalphaBinWidth_ );
366  //
367  tmphist = (TH1F*) file_->Get( Form( "%s%s" , rootdir.c_str(), histo ) );
368  if ( !tmphist ) {
369  if ( !ignore_single ) {
370  LOGERROR << "Failed to find histogram=" << std::string( histo );
371  status_ = 5;
372  return;
373  }
374  }
375  else {
376  LOGDEBUG << "Found histo " << std::string(histo)
377  << " with title = " << std::string( tmphist->GetTitle() ) << std::endl;
378  if ( tmphist->GetEntries() < 5 ) {
379  LOGINFO << "Histogram " << std::string(histo) << " has only " << tmphist->GetEntries()
380  << " entries. Trouble ahead." << std::endl;
381  }
382  resSinglePixelYHist_ [ ii ][ jj ] = tmphist;
383  resSinglePixelYGen_ [ ii ][ jj ] = new SimpleHistogramGenerator( tmphist );
384  }
385 
386 
387  //--- qBin distribution, for this (cotbeta, cotalpha) bin.
388  //
389  sprintf( histo, "hqbin%d%02d%d", detType_, ii+1, jj+1 );
390  sprintf( title, "cotbeta %.1f-%.1f cotalpha %.2f-%.2f qbin",
391  cotbetaLowEdge_ + ii*cotbetaBinWidth_ , cotbetaLowEdge_ + (ii+1)*cotbetaBinWidth_,
392  cotalphaLowEdge_ +jj*cotalphaBinWidth_, cotalphaLowEdge_ +(jj+1)*cotalphaBinWidth_ );
393  //
394  tmphist = (TH1F*) file_->Get( Form( "%s%s" , rootdir.c_str(), histo ) );
395  if ( !tmphist ) {
396  if ( !ignore_qBin ) {
397  LOGERROR << "Failed to find histogram=" << std::string( histo );
398  status_ = 6;
399  return;
400  }
401  }
402  else {
403  LOGDEBUG << "Found histo " << std::string(histo)
404  << " with title = " << std::string( tmphist->GetTitle() ) << std::endl;
405  if ( tmphist->GetEntries() < 5 ) {
406  LOGINFO << "Histogram " << std::string(histo) << " has only " << tmphist->GetEntries()
407  << " entries. Trouble ahead." << std::endl;
408  }
409  qbinHist_ [ ii ][ jj ] = tmphist;
410  qbinGen_ [ ii ][ jj ] = new SimpleHistogramGenerator( tmphist );
411  }
412 
413 
414  }
415  }
416 }
417 
418 
419 
420 
421 //------------------------------------------------------------------------------
422 // Destructor. Use file_ pointer to tell whether we loaded the histograms
423 // from a file (and do not own them), or we built them ourselves and thus need
424 // to delete them.
425 //------------------------------------------------------------------------------
427 {
428  //--- Delete histograms, but only if we own them. If
429  //--- they came from a file, let them be.
430  //
431  if ( ! weOwnHistograms_ ) {
432  //--- Read the histograms from the TFile, the file will take care of them.
433  file_->Close();
436  }
437  else {
438  //--- We made the histograms, so first write them inthe output ROOT file and close it.
439  LOGINFO
440  << "PixelResHistoStore: Writing the histograms to the output file. " // << filename
441  << std::endl;
442  file_->Write();
443  file_->Close();
444 
445  // ROOT file has the ownership, and once the file is closed,
446  // all of these guys are deleted. So, we don't need to do anything.
447  } // else
448 
449 
450 
451  //--- Delete FastSim generators. (It's safe to delete a nullptr.)
452  for( int ii=0; ii<cotbetaBins_; ii++ ) {
453  for( int jj=0; jj<cotalphaBins_; jj++ ) {
454  for( int kk=0; kk<qbins_; kk++ ) {
455  delete resMultiPixelXGen_ [ ii ][ jj ][ kk ];
456  delete resMultiPixelYGen_ [ ii ][ jj ][ kk ];
457  }
458  }
459  }
460  for( int ii=0; ii<cotbetaBins_; ii++ ) {
461  for( int jj=0; jj<cotalphaBins_; jj++ ) {
462  delete resSinglePixelXGen_ [ ii ][ jj ];
463  delete resSinglePixelYGen_ [ ii ][ jj ];
464  delete qbinGen_ [ ii ][ jj ];
465  }
466  }
467 
468 }
469 
470 
471 
472 
473 
474 
475 //------------------------------------------------------------------------------
476 // Fills the appropriate FastSim histograms.
477 // Returns 0 if the relevant histogram(s) were found and filled, 1 if not.
478 //------------------------------------------------------------------------------
479 int
481 Fill( double dx, double dy, double cotalpha, double cotbeta,
482  int qbin, int nxpix, int nypix )
483 {
484  int icotalpha, icotbeta, iqbin ;
485  icotalpha = (int)floor( (cotalpha - cotalphaLowEdge_)/cotalphaBinWidth_ ) ;
486  icotbeta = (int)floor( (cotbeta - cotbetaLowEdge_) /cotbetaBinWidth_ ) ;
487  iqbin = qbin > 2 ? 3 : qbin;
488  if( icotalpha >= 0 && icotalpha < cotalphaBins_ && icotbeta >= 0 && icotbeta < cotbetaBins_ ) {
489  qbinHist_[icotbeta][icotalpha]->Fill((double)iqbin);
490  if( nxpix == 1 )
491  resSinglePixelXHist_[icotbeta][icotalpha]->Fill(dx/cmtomicron);
492  else
493  resMultiPixelXHist_[icotbeta][icotalpha][iqbin]->Fill(dx/cmtomicron);
494  if( nypix == 1 )
495  resSinglePixelYHist_[icotbeta][icotalpha]->Fill(dy/cmtomicron);
496  else
497  resMultiPixelYHist_[icotbeta][icotalpha][iqbin]->Fill(dy/cmtomicron);
498  }
499 
500  return 0;
501 }
502 
503 
504 //------------------------------------------------------------------------------
505 // Return the histogram generator for resolution in X. A generator contains
506 // both the histogram and knows how to throw a random number off it. It is
507 // called from FastSim (from PixelTemplateSmearerBase).
508 // If cotalpha or cotbeta are outside of the range, return the end of the range.
509 //------------------------------------------------------------------------------
512 getGeneratorX( double cotalpha, double cotbeta, int qbin, bool single )
513 {
514  int icotalpha, icotbeta, iqbin ;
515  icotalpha = (int)floor( (cotalpha - cotalphaLowEdge_) / cotalphaBinWidth_ ) ;
516  icotbeta = (int)floor( (cotbeta - cotbetaLowEdge_) / cotbetaBinWidth_ ) ;
517  iqbin = qbin > 2 ? 3 : qbin; // if (qbin>2) then = 3, else return qbin
518  //
519  //if( icotalpha >= 0 && icotalpha < cotalphaBins_ && icotbeta >= 0 && icotbeta < cotbetaBins_ ) {
520 
521  if (icotalpha < 0)
522  icotalpha = 0;
523  if (icotalpha >= cotalphaBins_)
524  icotalpha = cotalphaBins_ - 1;
525 
526  if (icotbeta < 0)
527  icotbeta = 0;
528  if (icotbeta >= cotbetaBins_)
529  icotbeta = cotbetaBins_ - 1;
530 
531  // At this point we are sure to return *some bin* from the 3D histogram
532 
533  if( single )
534  return resSinglePixelXGen_[icotbeta][icotalpha];
535  else
536  return resMultiPixelXGen_[icotbeta][icotalpha][iqbin];
537 
538  // }
539  //else
540  //return nullptr;
541 }
542 
543 //------------------------------------------------------------------------------
544 // Return the histogram generator for resolution in Y. A generator contains
545 // both the histogram and knows how to throw a random number off it. It is
546 // called from FastSim (from PixelTemplateSmearerBase).
547 // If cotalpha or cotbeta are outside of the range, return the end of the range.
548 //------------------------------------------------------------------------------
551 getGeneratorY( double cotalpha, double cotbeta, int qbin, bool single )
552 {
553  int icotalpha, icotbeta, iqbin ;
554  icotalpha = (int)floor( (cotalpha - cotalphaLowEdge_) / cotalphaBinWidth_ ) ;
555  icotbeta = (int)floor( (cotbeta - cotbetaLowEdge_) / cotbetaBinWidth_ ) ;
556  iqbin = qbin > 2 ? 3 : qbin; // if (qbin>2) then = 3, else return qbin
557  //
558  //if( icotalpha >= 0 && icotalpha < cotalphaBins_ && icotbeta >= 0 && icotbeta < cotbetaBins_ ) {
559 
560  if (icotalpha < 0)
561  icotalpha = 0;
562  if (icotalpha >= cotalphaBins_)
563  icotalpha = cotalphaBins_ - 1;
564 
565  if (icotbeta < 0)
566  icotbeta = 0;
567  if (icotbeta >= cotbetaBins_)
568  icotbeta = cotbetaBins_ - 1;
569 
570  // At this point we are sure to return *some bin* from the 3D histogram
571 
572  if( single )
573  return resSinglePixelYGen_[icotbeta][icotalpha];
574  else
575  return resMultiPixelYGen_[icotbeta][icotalpha][iqbin];
576 
577  //}
578  //else
579  //return nullptr;
580 }
TH1F * resSinglePixelYHist_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX]
TH1F * resMultiPixelYHist_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX][QBIN_HIST_MAX]
TH1F * resSinglePixelXHist_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX]
SimpleHistogramGenerator * qbinGen_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX]
const SimpleHistogramGenerator * getGeneratorX(double cotalpha, double cotbeta, int qbin, bool singlex)
const SimpleHistogramGenerator * getGeneratorY(double cotalpha, double cotbeta, int qbin, bool singley)
TH1F * qbinHist_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX]
std::unique_ptr< TFile > file_
const float cmtomicron
SimpleHistogramGenerator * resMultiPixelYGen_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX][QBIN_HIST_MAX]
SimpleHistogramGenerator * resMultiPixelXGen_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX][QBIN_HIST_MAX]
#define LOGDEBUG
int Fill(double dx, double dy, double cotalpha, double cotbeta, int qbin, int nxpix, int nypix)
#define nullptr
TH1F * resMultiPixelXHist_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX][QBIN_HIST_MAX]
SimpleHistogramGenerator * resSinglePixelYGen_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX]
#define LOGINFO
#define LOGERROR
ii
Definition: cuy.py:590
PixelResolutionHistograms(std::string filename, std::string rootdir, std::string descTitle, unsigned int detType, double cotbetaBinWidth, double cotbetaLowEdge, int cotbetaBins, double cotalphaBinWidth, double cotalphaLowEdge, int cotalphaBins)
SimpleHistogramGenerator * resSinglePixelXGen_[COTBETA_HIST_MAX][COTALPHA_HIST_MAX]