CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LumiReWeighting.cc
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_interface_LumiReWeighting_cc
2 #define PhysicsTools_Utilities_interface_LumiReWeighting_cc
3 
4 
20 #include "TRandom1.h"
21 #include "TRandom2.h"
22 #include "TRandom3.h"
23 #include "TStopwatch.h"
24 #include "TH1.h"
25 #include "TFile.h"
26 #include <string>
27 #include <algorithm>
28 #include <boost/shared_ptr.hpp>
35 
36 using namespace edm;
37 
38 LumiReWeighting::LumiReWeighting( std::string generatedFile,
39  std::string dataFile,
40  std::string GenHistName = "pileup",
41  std::string DataHistName = "pileup" ) :
42  generatedFileName_( generatedFile),
43  dataFileName_ ( dataFile ),
44  GenHistName_ ( GenHistName ),
45  DataHistName_ ( DataHistName )
46  {
47  generatedFile_ = boost::shared_ptr<TFile>( new TFile(generatedFileName_.c_str()) ); //MC distribution
48  dataFile_ = boost::shared_ptr<TFile>( new TFile(dataFileName_.c_str()) ); //Data distribution
49 
50  Data_distr_ = boost::shared_ptr<TH1>( (static_cast<TH1*>(dataFile_->Get( DataHistName_.c_str() )->Clone() )) );
51  MC_distr_ = boost::shared_ptr<TH1>( (static_cast<TH1*>(generatedFile_->Get( GenHistName_.c_str() )->Clone() )) );
52 
53  // MC * data/MC = data, so the weights are data/MC:
54 
55  // normalize both histograms first
56 
57  Data_distr_->Scale( 1.0/ Data_distr_->Integral() );
58  MC_distr_->Scale( 1.0/ MC_distr_->Integral() );
59 
60  weights_ = boost::shared_ptr<TH1>( static_cast<TH1*>(Data_distr_->Clone()) );
61 
62  weights_->SetName("lumiWeights");
63 
64  TH1* den = dynamic_cast<TH1*>(MC_distr_->Clone());
65 
66  //den->Scale(1.0/ den->Integral());
67 
68  weights_->Divide( den ); // so now the average weight should be 1.0
69 
70  std::cout << " Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
71 
72  int NBins = weights_->GetNbinsX();
73 
74  for(int ibin = 1; ibin<NBins+1; ++ibin){
75  std::cout << " " << ibin-1 << " " << weights_->GetBinContent(ibin) << std::endl;
76  }
77 
78 
80 
81  FirstWarning_ = true;
82  OldLumiSection_ = -1;
83 }
84 
85 LumiReWeighting::LumiReWeighting( std::vector< float > MC_distr, std::vector< float > Lumi_distr) {
86  // no histograms for input: use vectors
87 
88  // now, make histograms out of them:
89 
90  // first, check they are the same size...
91 
92  if( MC_distr.size() != Lumi_distr.size() ){
93 
94  std::cerr <<"ERROR: LumiReWeighting: input vectors have different sizes. Quitting... \n";
95  return;
96 
97  }
98 
99  Int_t NBins = MC_distr.size();
100 
101  MC_distr_ = boost::shared_ptr<TH1> ( new TH1F("MC_distr","MC dist",NBins,-0.5, float(NBins)-0.5) );
102  Data_distr_ = boost::shared_ptr<TH1> ( new TH1F("Data_distr","Data dist",NBins,-0.5, float(NBins)-0.5) );
103 
104  weights_ = boost::shared_ptr<TH1> ( new TH1F("luminumer","luminumer",NBins,-0.5, float(NBins)-0.5) );
105  TH1* den = new TH1F("lumidenom","lumidenom",NBins,-0.5, float(NBins)-0.5) ;
106 
107  for(int ibin = 1; ibin<NBins+1; ++ibin ) {
108  weights_->SetBinContent(ibin, Lumi_distr[ibin-1]);
109  Data_distr_->SetBinContent(ibin, Lumi_distr[ibin-1]);
110  den->SetBinContent(ibin,MC_distr[ibin-1]);
111  MC_distr_->SetBinContent(ibin,MC_distr[ibin-1]);
112  }
113 
114  // check integrals, make sure things are normalized
115 
116  float deltaH = weights_->Integral();
117  if(fabs(1.0 - deltaH) > 0.02 ) { //*OOPS*...
118  weights_->Scale( 1.0/ weights_->Integral() );
119  Data_distr_->Scale( 1.0/ Data_distr_->Integral() );
120  }
121  float deltaMC = den->Integral();
122  if(fabs(1.0 - deltaMC) > 0.02 ) {
123  den->Scale(1.0/ den->Integral());
124  MC_distr_->Scale(1.0/ MC_distr_->Integral());
125  }
126 
127  weights_->Divide( den ); // so now the average weight should be 1.0
128 
129  std::cout << " Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
130 
131  for(int ibin = 1; ibin<NBins+1; ++ibin){
132  std::cout << " " << ibin-1 << " " << weights_->GetBinContent(ibin) << std::endl;
133  }
134 
135  weightOOT_init();
136 
137  FirstWarning_ = true;
138  OldLumiSection_ = -1;
139 }
140 
141 double LumiReWeighting::weight( int npv ) {
142  int bin = weights_->GetXaxis()->FindBin( npv );
143  return weights_->GetBinContent( bin );
144 }
145 
146 double LumiReWeighting::weight( float npv ) {
147  int bin = weights_->GetXaxis()->FindBin( npv );
148  return weights_->GetBinContent( bin );
149 }
150 
151 
152 
153 // This version of weight does all of the work for you, assuming you want to re-weight
154 // using the true number of interactions in the in-time beam crossing.
155 
156 
158 
159  // find provenance of event objects, just to check at the job beginning if there might be an issue
160 
161  if(FirstWarning_) {
162 
163  edm::ReleaseVersion TargetRelease = edm::ReleaseVersion("\"CMSSW_4_2_2_patch2\"");
165  edm::ProcessHistory::const_iterator PHist_iter = PHist.begin();
166 
167  for(; PHist_iter<PHist.end() ;++PHist_iter) {
168  edm::ProcessConfiguration PConf = *(PHist_iter);
169  edm::ReleaseVersion Release = PConf.releaseVersion() ;
170  const std::string Process = PConf.processName();
171 
172  if((Process=="HLT") && (Release==TargetRelease)) {
173  std::cout << " **** Warning! You are using in-time-only pileup reweighting for Release " << Release << " **** " << std::endl;
174  std::cout << " **** There is a weightOOT() function available if needed **** " << std::endl;
175  }
176  }
177  // SetFirstFalse();
178  FirstWarning_ = false;
179  }
180 
181  // get pileup summary information
182 
184  e.getByLabel(edm::InputTag("addPileupInfo"), PupInfo);
185 
186  std::vector<PileupSummaryInfo>::const_iterator PVI;
187 
188  int npv = -1;
189  for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
190 
191  int BX = PVI->getBunchCrossing();
192 
193  if(BX == 0) {
194  npv = PVI->getPU_NumInteractions();
195  continue;
196  }
197 
198  }
199 
200  if(npv < 0) std::cerr << " no in-time beam crossing found\n! " ;
201 
202  return weight(npv);
203 
204 }
205 
207 
208  // The following are poisson distributions with different means, where the maximum
209  // of the function has been normalized to weight 1.0
210  // These are used to reweight the out-of-time pileup to match the in-time distribution.
211  // The total event weight is the product of the in-time weight, the out-of-time weight,
212  // and a residual correction to fix the distortions caused by the fact that the out-of-time
213  // distribution is not flat.
214 
215  static double weight_24[25] = {
216  0,
217  0,
218  0,
219  0,
220  2.46277e-06,
221  2.95532e-05,
222  0.000104668,
223  0.000401431,
224  0.00130034,
225  0.00342202,
226  0.00818132,
227  0.0175534,
228  0.035784,
229  0.0650836,
230  0.112232,
231  0.178699,
232  0.268934,
233  0.380868,
234  0.507505,
235  0.640922,
236  0.768551,
237  0.877829,
238  0.958624,
239  0.99939,
240  1
241  };
242 
243  static double weight_23[25] = {
244  0,
245  1.20628e-06,
246  1.20628e-06,
247  2.41255e-06,
248  1.20628e-05,
249  6.39326e-05,
250  0.000252112,
251  0.000862487,
252  0.00244995,
253  0.00616527,
254  0.0140821,
255  0.0293342,
256  0.0564501,
257  0.100602,
258  0.164479,
259  0.252659,
260  0.36268,
261  0.491427,
262  0.627979,
263  0.75918,
264  0.873185,
265  0.957934,
266  0.999381,
267  1,
268  0.957738
269  };
270 
271  static double weight_22[25] = {
272  0,
273  0,
274  0,
275  5.88636e-06,
276  3.0609e-05,
277  0.000143627,
278  0.000561558,
279  0.00173059,
280  0.00460078,
281  0.0110616,
282  0.0238974,
283  0.0475406,
284  0.0875077,
285  0.148682,
286  0.235752,
287  0.343591,
288  0.473146,
289  0.611897,
290  0.748345,
291  0.865978,
292  0.953199,
293  0.997848,
294  1,
295  0.954245,
296  0.873688
297  };
298 
299  static double weight_21[25] = {
300  0,
301  0,
302  1.15381e-06,
303  8.07665e-06,
304  7.1536e-05,
305  0.000280375,
306  0.00107189,
307  0.00327104,
308  0.00809396,
309  0.0190978,
310  0.0401894,
311  0.0761028,
312  0.13472,
313  0.216315,
314  0.324649,
315  0.455125,
316  0.598241,
317  0.739215,
318  0.861866,
319  0.953911,
320  0.998918,
321  1,
322  0.956683,
323  0.872272,
324  0.76399
325  };
326 
327 
328  static double weight_20[25] = {
329  0,
330  0,
331  1.12532e-06,
332  2.58822e-05,
333  0.000145166,
334  0.000633552,
335  0.00215048,
336  0.00592816,
337  0.0145605,
338  0.0328367,
339  0.0652649,
340  0.11893,
341  0.19803,
342  0.305525,
343  0.436588,
344  0.581566,
345  0.727048,
346  0.8534,
347  0.949419,
348  0.999785,
349  1,
350  0.953008,
351  0.865689,
352  0.753288,
353  0.62765
354  };
355  static double weight_19[25] = {
356  0,
357  0,
358  1.20714e-05,
359  5.92596e-05,
360  0.000364337,
361  0.00124994,
362  0.00403953,
363  0.0108149,
364  0.025824,
365  0.0544969,
366  0.103567,
367  0.17936,
368  0.283532,
369  0.416091,
370  0.562078,
371  0.714714,
372  0.846523,
373  0.947875,
374  1,
375  0.999448,
376  0.951404,
377  0.859717,
378  0.742319,
379  0.613601,
380  0.48552
381  };
382 
383  static double weight_18[25] = {
384  0,
385  3.20101e-06,
386  2.88091e-05,
387  0.000164319,
388  0.000719161,
389  0.00250106,
390  0.00773685,
391  0.0197513,
392  0.0443693,
393  0.0885998,
394  0.159891,
395  0.262607,
396  0.392327,
397  0.543125,
398  0.69924,
399  0.837474,
400  0.943486,
401  0.998029,
402  1,
403  0.945937,
404  0.851807,
405  0.729309,
406  0.596332,
407  0.467818,
408  0.350434
409  };
410 
411 
412  static double weight_17[25] = {
413  1.03634e-06,
414  7.25437e-06,
415  4.97443e-05,
416  0.000340956,
417  0.00148715,
418  0.00501485,
419  0.0143067,
420  0.034679,
421  0.0742009,
422  0.140287,
423  0.238288,
424  0.369416,
425  0.521637,
426  0.682368,
427  0.828634,
428  0.939655,
429  1,
430  0.996829,
431  0.94062,
432  0.841575,
433  0.716664,
434  0.582053,
435  0.449595,
436  0.331336,
437  0.234332
438  };
439 
440 
441  static double weight_16[25] = {
442  4.03159e-06,
443  2.41895e-05,
444  0.000141106,
445  0.00081942,
446  0.00314565,
447  0.00990662,
448  0.026293,
449  0.0603881,
450  0.120973,
451  0.214532,
452  0.343708,
453  0.501141,
454  0.665978,
455  0.820107,
456  0.938149,
457  1,
458  0.99941,
459  0.940768,
460  0.837813,
461  0.703086,
462  0.564023,
463  0.42928,
464  0.312515,
465  0.216251,
466  0.14561
467  };
468 
469 
470  static double weight_15[25] = {
471  9.76084e-07,
472  5.07564e-05,
473  0.000303562,
474  0.00174036,
475  0.00617959,
476  0.0188579,
477  0.047465,
478  0.101656,
479  0.189492,
480  0.315673,
481  0.474383,
482  0.646828,
483  0.809462,
484  0.934107,
485  0.998874,
486  1,
487  0.936163,
488  0.827473,
489  0.689675,
490  0.544384,
491  0.40907,
492  0.290648,
493  0.198861,
494  0.12951,
495  0.0808051
496  };
497 
498 
499  static double weight_14[25] = {
500  1.13288e-05,
501  0.000124617,
502  0.000753365,
503  0.00345056,
504  0.0123909,
505  0.0352712,
506  0.0825463,
507  0.16413,
508  0.287213,
509  0.44615,
510  0.625826,
511  0.796365,
512  0.930624,
513  0.999958,
514  1,
515  0.934414,
516  0.816456,
517  0.672939,
518  0.523033,
519  0.386068,
520  0.269824,
521  0.180342,
522  0.114669,
523  0.0698288,
524  0.0406496
525  };
526 
527 
528  static double weight_13[25] = {
529  2.54296e-05,
530  0.000261561,
531  0.00167018,
532  0.00748083,
533  0.0241308,
534  0.0636801,
535  0.138222,
536  0.255814,
537  0.414275,
538  0.600244,
539  0.779958,
540  0.92256,
541  0.999155,
542  1,
543  0.927126,
544  0.804504,
545  0.651803,
546  0.497534,
547  0.35976,
548  0.245834,
549  0.160904,
550  0.0991589,
551  0.0585434,
552  0.0332437,
553  0.0180159
554  };
555 
556  static double weight_12[25] = {
557  5.85742e-05,
558  0.000627706,
559  0.00386677,
560  0.0154068,
561  0.0465892,
562  0.111683,
563  0.222487,
564  0.381677,
565  0.5719,
566  0.765001,
567  0.915916,
568  1,
569  0.999717,
570  0.921443,
571  0.791958,
572  0.632344,
573  0.475195,
574  0.334982,
575  0.223666,
576  0.141781,
577  0.0851538,
578  0.048433,
579  0.0263287,
580  0.0133969,
581  0.00696683
582  };
583 
584 
585  static double weight_11[25] = {
586  0.00015238,
587  0.00156064,
588  0.00846044,
589  0.0310939,
590  0.0856225,
591  0.187589,
592  0.343579,
593  0.541892,
594  0.74224,
595  0.909269,
596  0.998711,
597  1,
598  0.916889,
599  0.77485,
600  0.608819,
601  0.447016,
602  0.307375,
603  0.198444,
604  0.121208,
605  0.070222,
606  0.0386492,
607  0.0201108,
608  0.0100922,
609  0.00484937,
610  0.00222458
611  };
612 
613  static double weight_10[25] = {
614  0.000393044,
615  0.00367001,
616  0.0179474,
617  0.060389,
618  0.151477,
619  0.302077,
620  0.503113,
621  0.720373,
622  0.899568,
623  1,
624  0.997739,
625  0.909409,
626  0.75728,
627  0.582031,
628  0.415322,
629  0.277663,
630  0.174147,
631  0.102154,
632  0.0566719,
633  0.0298642,
634  0.0147751,
635  0.00710995,
636  0.00319628,
637  0.00140601,
638  0.000568796
639  };
640 
641 
642  static double weight_9[25] = {
643  0.00093396,
644  0.00854448,
645  0.0380306,
646  0.113181,
647  0.256614,
648  0.460894,
649  0.690242,
650  0.888781,
651  1,
652  0.998756,
653  0.899872,
654  0.735642,
655  0.552532,
656  0.382726,
657  0.246114,
658  0.147497,
659  0.0825541,
660  0.0441199,
661  0.0218157,
662  0.0103578,
663  0.00462959,
664  0.0019142,
665  0.000771598,
666  0.000295893,
667  0.000111529
668  };
669 
670 
671  static double weight_8[25] = {
672  0.00240233,
673  0.0192688,
674  0.0768653,
675  0.205008,
676  0.410958,
677  0.65758,
678  0.875657,
679  0.999886,
680  1,
681  0.889476,
682  0.711446,
683  0.517781,
684  0.345774,
685  0.212028,
686  0.121208,
687  0.0644629,
688  0.0324928,
689  0.0152492,
690  0.00673527,
691  0.0028547,
692  0.00117213,
693  0.000440177,
694  0.000168471,
695  5.80689e-05,
696  1.93563e-05
697  };
698 
699  static double weight_7[25] = {
700  0.00617233,
701  0.0428714,
702  0.150018,
703  0.350317,
704  0.612535,
705  0.856525,
706  0.999923,
707  1,
708  0.87544,
709  0.679383,
710  0.478345,
711  0.303378,
712  0.176923,
713  0.0950103,
714  0.0476253,
715  0.0222211,
716  0.00972738,
717  0.00392962,
718  0.0015258,
719  0.000559168,
720  0.000183928,
721  6.77983e-05,
722  1.67818e-05,
723  7.38398e-06,
724  6.71271e-07
725  };
726 
727  static double weight_6[25] = {
728  0.0154465,
729  0.0923472,
730  0.277322,
731  0.55552,
732  0.833099,
733  0.999035,
734  1,
735  0.855183,
736  0.641976,
737  0.428277,
738  0.256804,
739  0.139798,
740  0.0700072,
741  0.0321586,
742  0.0137971,
743  0.00544756,
744  0.00202316,
745  0.000766228,
746  0.000259348,
747  8.45836e-05,
748  1.80362e-05,
749  8.70713e-06,
750  3.73163e-06,
751  6.21938e-07,
752  0
753  };
754 
755 
756  static double weight_5[25] = {
757  0.0382845,
758  0.191122,
759  0.478782,
760  0.797314,
761  1,
762  0.997148,
763  0.831144,
764  0.59461,
765  0.371293,
766  0.205903,
767  0.103102,
768  0.0471424,
769  0.0194997,
770  0.00749415,
771  0.00273709,
772  0.000879189,
773  0.000286049,
774  0.000102364,
775  1.70606e-05,
776  3.98081e-06,
777  2.27475e-06,
778  0,
779  0,
780  0,
781  0
782  };
783 
784 
785  static double weight_4[25] = {
786  0.0941305,
787  0.373824,
788  0.750094,
789  1,
790  0.997698,
791  0.800956,
792  0.532306,
793  0.304597,
794  0.152207,
795  0.0676275,
796  0.0270646,
797  0.00975365,
798  0.00326077,
799  0.00101071,
800  0.000301781,
801  7.41664e-05,
802  1.58563e-05,
803  3.58045e-06,
804  1.02299e-06,
805  0,
806  5.11493e-07,
807  0,
808  0,
809  0,
810  0
811  };
812 
813 
814  static double weight_3[25] = {
815  0.222714,
816  0.667015,
817  1,
818  0.999208,
819  0.750609,
820  0.449854,
821  0.224968,
822  0.0965185,
823  0.0361225,
824  0.012084,
825  0.00359618,
826  0.000977166,
827  0.000239269,
828  6.29422e-05,
829  1.16064e-05,
830  1.78559e-06,
831  0,
832  4.46398e-07,
833  0,
834  0,
835  0,
836  0,
837  0,
838  0,
839  0
840  };
841 
842  static double weight_2[25] = {
843  0.499541,
844  0.999607,
845  1,
846  0.666607,
847  0.333301,
848  0.13279,
849  0.0441871,
850  0.0127455,
851  0.00318434,
852  0.00071752,
853  0.000132204,
854  2.69578e-05,
855  5.16999e-06,
856  2.21571e-06,
857  0,
858  0,
859  0,
860  0,
861  0,
862  0,
863  0,
864  0,
865  0,
866  0,
867  0
868  };
869 
870  static double weight_1[25] = {
871  0.999165,
872  1,
873  0.499996,
874  0.166868,
875  0.0414266,
876  0.00831053,
877  0.00137472,
878  0.000198911,
879  2.66302e-05,
880  2.44563e-06,
881  2.71737e-07,
882  2.71737e-07,
883  0,
884  0,
885  0,
886  0,
887  0,
888  0,
889  0,
890  0,
891  0,
892  0,
893  0,
894  0,
895  0
896  };
897 
898  static double weight_0[25] = {
899  1,
900  0,
901  0,
902  0,
903  0,
904  0,
905  0,
906  0,
907  0,
908  0,
909  0,
910  0,
911  0,
912  0,
913  0,
914  0,
915  0,
916  0,
917  0,
918  0,
919  0,
920  0,
921  0,
922  0,
923  0
924  };
925 
926  //WeightOOTPU_ = {0};
927 
928  double* WeightPtr = 0;
929 
930  for(int iint = 0; iint<25; ++iint){
931  if(iint ==0) WeightPtr = weight_0;
932  if(iint ==1) WeightPtr = weight_1;
933  if(iint ==2) WeightPtr = weight_2;
934  if(iint ==3) WeightPtr = weight_3;
935  if(iint ==4) WeightPtr = weight_4;
936  if(iint ==5) WeightPtr = weight_5;
937  if(iint ==6) WeightPtr = weight_6;
938  if(iint ==7) WeightPtr = weight_7;
939  if(iint ==8) WeightPtr = weight_8;
940  if(iint ==9) WeightPtr = weight_9;
941  if(iint ==10) WeightPtr = weight_10;
942  if(iint ==11) WeightPtr = weight_11;
943  if(iint ==12) WeightPtr = weight_12;
944  if(iint ==13) WeightPtr = weight_13;
945  if(iint ==14) WeightPtr = weight_14;
946  if(iint ==15) WeightPtr = weight_15;
947  if(iint ==16) WeightPtr = weight_16;
948  if(iint ==17) WeightPtr = weight_17;
949  if(iint ==18) WeightPtr = weight_18;
950  if(iint ==19) WeightPtr = weight_19;
951  if(iint ==20) WeightPtr = weight_20;
952  if(iint ==21) WeightPtr = weight_21;
953  if(iint ==22) WeightPtr = weight_22;
954  if(iint ==23) WeightPtr = weight_23;
955  if(iint ==24) WeightPtr = weight_24;
956 
957  for(int ibin = 0; ibin<25; ++ibin){
958  WeightOOTPU_[iint][ibin] = *(WeightPtr+ibin);
959  }
960  }
961 
962 }
963 
964 // Use this routine to re-weight out-of-time pileup to match the in-time distribution
965 // As of May 2011, CMS is only sensitive to a bunch that is 50ns "late", which corresponds to
966 // BunchCrossing +1. So, we use that here for re-weighting.
967 
969 
970 
971  static double Correct_Weights2011[25] = { // residual correction to match lumi spectrum
972  5.30031,
973  2.07903,
974  1.40729,
975  1.27687,
976  1.0702,
977  0.902094,
978  0.902345,
979  0.931449,
980  0.78202,
981  0.824686,
982  0.837735,
983  0.910261,
984  1.01394,
985  1.1599,
986  1.12778,
987  1.58423,
988  1.78868,
989  1.58296,
990  2.3291,
991  3.86641,
992  0,
993  0,
994  0,
995  0,
996  0
997  };
998 
999  //int Run = e.run();
1000  int LumiSection = e.luminosityBlock();
1001 
1002  // do some caching here, attempt to catch file boundaries
1003 
1004  if(LumiSection != OldLumiSection_) {
1005 
1006  Reweight_4_2_2p2_ = false;
1007 
1008  static edm::ReleaseVersion TargetRelease = edm::ReleaseVersion("\"CMSSW_4_2_2_patch2\"");
1009  edm::ProcessHistory PHist = e.processHistory();
1010  edm::ProcessHistory::const_iterator PHist_iter = PHist.begin();
1011 
1012  // check to see if we need to do the special out-of-time poisson weighting for CMSSW_4_2_2_patch2 MC:
1013 
1014  for(; PHist_iter<PHist.end() ;++PHist_iter) {
1015  edm::ProcessConfiguration PConf = *(PHist_iter);
1016  edm::ReleaseVersion Release = PConf.releaseVersion() ;
1017  const std::string Process = PConf.processName();
1018 
1019  if((Process=="HLT") && (Release==TargetRelease)) {
1020 
1021  Reweight_4_2_2p2_ = true;
1022 
1023  if(FirstWarning_) {
1024 
1025  std::cout << " **** Warning: Out-of-time pileup reweighting appropriate for Release " << Release << " **** " << std::endl;
1026  std::cout << " **** will be applied **** " << std::endl;
1027 
1028  FirstWarning_ = false;
1029  }
1030  }
1031  }
1032  OldLumiSection_ = LumiSection;
1033  }
1034 
1035  // find the pileup summary information
1036 
1038  e.getByLabel(edm::InputTag("addPileupInfo"), PupInfo);
1039 
1040  std::vector<PileupSummaryInfo>::const_iterator PVI;
1041 
1042  int npv = -1;
1043  int npv50ns = -1;
1044 
1045  for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
1046 
1047  int BX = PVI->getBunchCrossing();
1048 
1049  if(BX == 0) {
1050  npv = PVI->getPU_NumInteractions();
1051  }
1052 
1053  if(BX == 1) {
1054  npv50ns = PVI->getPU_NumInteractions();
1055  }
1056 
1057  }
1058 
1059  // Note: for the "uncorrelated" out-of-time pileup, reweighting is only done on the 50ns
1060  // "late" bunch (BX=+1), since that is basically the only one that matters in terms of
1061  // energy deposition.
1062 
1063  if(npv < 0) {
1064  std::cerr << " no in-time beam crossing found\n! " ;
1065  std::cerr << " Returning event weight=0\n! ";
1066  return 0.;
1067  }
1068  if(npv50ns < 0) {
1069  std::cerr << " no out-of-time beam crossing found\n! " ;
1070  std::cerr << " Returning event weight=0\n! ";
1071  return 0.;
1072  }
1073 
1074  int bin = weights_->GetXaxis()->FindBin( npv );
1075 
1076  double inTimeWeight = weights_->GetBinContent( bin );
1077 
1078  double TotalWeight = 1.0;
1079 
1080  if(Reweight_4_2_2p2_) {
1081  TotalWeight = inTimeWeight * WeightOOTPU_[bin-1][npv50ns] * Correct_Weights2011[bin-1];
1082  }
1083  else {
1084  TotalWeight = inTimeWeight;
1085  }
1086 
1087  return TotalWeight;
1088 
1089 }
1090 
1091 #endif
collection_type::const_iterator const_iterator
const_iterator begin() const
double WeightOOTPU_[25][25]
int iint
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
boost::shared_ptr< TH1 > MC_distr_
std::string const & processName() const
double weight(int npv)
double weightOOT(const edm::EventBase &e)
boost::shared_ptr< TFile > dataFile_
boost::shared_ptr< TFile > generatedFile_
virtual ProcessHistory const & processHistory() const =0
ReleaseVersion const & releaseVersion() const
boost::shared_ptr< TH1 > Data_distr_
std::string ReleaseVersion
Definition: ReleaseVersion.h:7
const_iterator end() const
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:86
boost::shared_ptr< TH1 > weights_
tuple cout
Definition: gather_cfg.py:121
std::string generatedFileName_