00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "Validation/MuonIsolation/interface/MuIsoValidation.h"
00033
00034
00035 #include <memory>
00036 #include <string>
00037 #include <typeinfo>
00038 #include <utility>
00039
00040
00041 #include "TH1.h"
00042 #include "TH2.h"
00043 #include "TProfile.h"
00044
00045
00046 #include "FWCore/Framework/interface/MakerMacros.h"
00047 #include "FWCore/Framework/interface/Event.h"
00048 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00049
00050
00051 #include "DataFormats/TrackReco/interface/Track.h"
00052
00053
00054 using std::vector;
00055 using std::pair;
00056 using std::string;
00057
00058
00059
00060
00061
00062
00063 MuIsoValidation::MuIsoValidation(const edm::ParameterSet& iConfig)
00064 {
00065
00066
00067 requireCombinedMuon = iConfig.getUntrackedParameter<bool>("requireCombinedMuon");
00068 dirName = iConfig.getParameter<std::string>("directory");
00069
00070
00071
00072
00073
00074 Muon_Tag = iConfig.getUntrackedParameter<edm::InputTag>("Global_Muon_Label");
00075
00076
00077 nEvents = 0;
00078 nIncMuons = 0;
00079 nCombinedMuons = 0;
00080
00081 InitStatics();
00082
00083
00084 dbe = 0;
00085 dbe = edm::Service<DQMStore>().operator->();
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 h_1D.resize (NUM_VARS);
00100 cd_plots.resize(NUM_VARS);
00101
00102 p_2D.resize(NUM_VARS, vector<MonitorElement*>(NUM_VARS));
00103
00104 dbe->cd();
00105 }
00106
00107
00108
00109
00110 MuIsoValidation::~MuIsoValidation(){
00111
00112
00113
00114 }
00115
00116
00117
00118
00119 void MuIsoValidation::InitStatics(){
00120
00121
00122 S_BIN_WIDTH = 1.0;
00123 L_BIN_WIDTH = 2.0;
00124 LOG_BINNING_ENABLED = 1;
00125 NUM_LOG_BINS = 15;
00126 LOG_BINNING_RATIO = 1.1;
00127
00128
00129
00130
00131 title_sam = "";
00132 title_cone = "";
00133
00134
00135 title_cd = "C.D. of ";
00136
00137
00138 main_titles.resize(NUM_VARS);
00139 axis_titles.resize(NUM_VARS);
00140 names.resize(NUM_VARS);
00141 param.resize(NUM_VARS, vector<double>(3) );
00142 isContinuous.resize(NUM_VARS);
00143
00144
00145 main_titles[0 ] = "Total Tracker Momentum";
00146 main_titles[1 ] = "Total EM Cal Energy";
00147 main_titles[2 ] = "Total Had Cal Energy";
00148 main_titles[3 ] = "Total HO Cal Energy";
00149 main_titles[4 ] = "Number of Tracker Tracks";
00150 main_titles[5 ] = "Number of Jets around Muon";
00151 main_titles[6 ] = "Tracker p_{T} within veto cone";
00152 main_titles[7 ] = "EM E_{T} within veto cone";
00153 main_titles[8 ] = "Had E_{T} within veto cone";
00154 main_titles[9 ] = "HO E_{T} within veto cone";
00155 main_titles[10] = "Muon p_{T}";
00156 main_titles[11] = "Muon #eta";
00157 main_titles[12] = "Muon #phi";
00158 main_titles[13] = "Average Momentum per Track ";
00159 main_titles[14] = "Weighted Energy";
00160
00161
00162 axis_titles[0 ] = "#Sigma p_{T} (GeV)";
00163 axis_titles[1 ] = "#Sigma E_{T}^{EM} (GeV)";
00164 axis_titles[2 ] = "#Sigma E_{T}^{Had} (GeV)";
00165 axis_titles[3 ] = "#Sigma E_{T}^{HO} (GeV)";
00166 axis_titles[4 ] = "N_{Tracks}";
00167 axis_titles[5 ] = "N_{Jets}";
00168 axis_titles[6 ] = "#Sigma p_{T,veto} (GeV)";
00169 axis_titles[7 ] = "#Sigma E_{T,veto}^{EM} (GeV)";
00170 axis_titles[8 ] = "#Sigma E_{T,veto}^{Had} (GeV)";
00171 axis_titles[9 ] = "#Sigma E_{T,veto}^{HO} (GeV)";
00172 axis_titles[10] = "p_{T,#mu} (GeV)";
00173 axis_titles[11] = "#eta_{#mu}";
00174 axis_titles[12] = "#phi_{#mu}";
00175 axis_titles[13] = "#Sigma p_{T} / N_{Tracks} (GeV)";
00176 axis_titles[14] = "(1.5) X #Sigma E_{T}^{EM} + #Sigma E_{T}^{Had}";
00177
00178
00179 names[0 ] = "sumPt";
00180 names[1 ] = "emEt";
00181 names[2 ] = "hadEt";
00182 names[3 ] = "hoEt";
00183 names[4 ] = "nTracks";
00184 names[5 ] = "nJets";
00185 names[6 ] = "trackerVetoPt";
00186 names[7 ] = "emVetoEt";
00187 names[8 ] = "hadVetoEt";
00188 names[9 ] = "hoVetoEt";
00189 names[10] = "muonPt";
00190 names[11] = "muonEta";
00191 names[12] = "muonPhi";
00192 names[13] = "avgPt";
00193 names[14] = "weightedEt";
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 param[0 ][0]= (int)( 20.0/S_BIN_WIDTH); param[0 ][1]= 0.0; param[0 ][2]= param[0 ][0]*S_BIN_WIDTH;
00204 param[1 ][0]= (int)( 20.0/S_BIN_WIDTH); param[1 ][1]= 0.0; param[1 ][2]= param[1 ][0]*S_BIN_WIDTH;
00205 param[2 ][0]= (int)( 20.0/S_BIN_WIDTH); param[2 ][1]= 0.0; param[2 ][2]= param[2 ][0]*S_BIN_WIDTH;
00206 param[3 ][0]= 20; param[3 ][1]= 0.0; param[3 ][2]= 2.0;
00207 param[4 ][0]= 16; param[4 ][1]= -0.5; param[4 ][2]= param[4 ][0]-0.5;
00208 param[5 ][0]= 4; param[5 ][1]= -0.5; param[5 ][2]= param[5 ][0]-0.5;
00209 param[6 ][0]= (int)( 40.0/S_BIN_WIDTH); param[6 ][1]= 0.0; param[6 ][2]= param[6 ][0]*S_BIN_WIDTH;
00210 param[7 ][0]= 20; param[7 ][1]= 0.0; param[7 ][2]= 10.0;
00211 param[8 ][0]= (int)( 20.0/S_BIN_WIDTH); param[8 ][1]= 0.0; param[8 ][2]= param[8 ][0]*S_BIN_WIDTH;
00212 param[9 ][0]= 20; param[9 ][1]= 0.0; param[9 ][2]= 5.0;
00213 param[10][0]= (int)( 40.0/S_BIN_WIDTH); param[10][1]= 0.0; param[10][2]= param[10][0]*S_BIN_WIDTH;
00214 param[11][0]= 24; param[11][1]= -2.4; param[11][2]= 2.4;
00215 param[12][0]= 32; param[12][1]= -3.2; param[12][2]= 3.2;
00216 param[13][0]= (int)( 15.0/S_BIN_WIDTH); param[13][1]= 0.0; param[13][2]= param[13][0]*S_BIN_WIDTH;
00217 param[14][0]= (int)( 20.0/S_BIN_WIDTH); param[14][1]= 0.0; param[14][2]= param[14][0]*S_BIN_WIDTH;
00218
00219
00220
00221 isContinuous[0 ] = 1;
00222 isContinuous[1 ] = 1;
00223 isContinuous[2 ] = 1;
00224 isContinuous[3 ] = 1;
00225 isContinuous[4 ] = 0;
00226 isContinuous[5 ] = 0;
00227 isContinuous[6 ] = 1;
00228 isContinuous[7 ] = 1;
00229 isContinuous[8 ] = 1;
00230 isContinuous[9 ] = 1;
00231 isContinuous[10] = 1;
00232 isContinuous[11] = 1;
00233 isContinuous[12] = 1;
00234 isContinuous[13] = 1;
00235 isContinuous[14] = 1;
00236
00237 }
00238
00239
00240
00241 void MuIsoValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){
00242
00243 ++nEvents;
00244 edm::LogInfo("Tutorial") << "\nInvestigating event #" << nEvents<<"\n";
00245
00246
00247 edm::Handle<edm::View<reco::Muon> > muonsHandle;
00248 iEvent.getByLabel(Muon_Tag, muonsHandle);
00249
00250
00251 edm::LogInfo("Tutorial") << "Number of Muons: " << muonsHandle->size();
00252 theMuonData = muonsHandle->size();
00253 h_nMuons->Fill(theMuonData);
00254
00255
00256 uint iMuon=0;
00257 dbe->setCurrentFolder(dirName.c_str());
00258 for (MuonIterator muon = muonsHandle->begin(); muon != muonsHandle->end(); ++muon, ++iMuon ) {
00259 ++nIncMuons;
00260 if (requireCombinedMuon) {
00261 if (muon->combinedMuon().isNull()) continue;
00262 }
00263 ++nCombinedMuons;
00264 RecordData(muon);
00265 FillHistos();
00266 }
00267 dbe->cd();
00268
00269 }
00270
00271
00272 void MuIsoValidation::RecordData(MuonIterator muon){
00273
00274
00275 theData[0] = muon->isolationR03().sumPt;
00276 theData[1] = muon->isolationR03().emEt;
00277 theData[2] = muon->isolationR03().hadEt;
00278 theData[3] = muon->isolationR03().hoEt;
00279
00280 theData[4] = muon->isolationR03().nTracks;
00281 theData[5] = muon->isolationR03().nJets;
00282 theData[6] = muon->isolationR03().trackerVetoPt;
00283 theData[7] = muon->isolationR03().emVetoEt;
00284 theData[8] = muon->isolationR03().hadVetoEt;
00285 theData[9] = muon->isolationR03().hoVetoEt;
00286
00287 theData[10] = muon->pt();
00288 theData[11] = muon->eta();
00289 theData[12] = muon->phi();
00290
00291
00292 if (theData[4] != 0) theData[13] = (double)theData[0] / (double)theData[4];
00293 else theData[13] = -99;
00294
00295 theData[14] = 1.5 * theData[1] + theData[2];
00296
00297 }
00298
00299
00300 void
00301 MuIsoValidation::beginJob()
00302 {
00303
00304 edm::LogInfo("Tutorial") << "\n#########################################\n\n"
00305 << "Lets get started! "
00306 << "\n\n#########################################\n";
00307 dbe->setCurrentFolder(dirName.c_str());
00308 InitHistos();
00309 dbe->cd();
00310
00311 }
00312
00313
00314 void
00315 MuIsoValidation::endJob() {
00316
00317
00318 if( dbe )
00319 {
00320
00321 if (! dbe->get(dirName+"/nMuons")) return;
00322 }
00323 else
00324 return;
00325
00326 edm::LogInfo("Tutorial") << "\n#########################################\n\n"
00327 << "Total Number of Events: " << nEvents
00328 << "\nTotal Number of Muons: " << nIncMuons
00329 << "\n\n#########################################\n"
00330 << "\nInitializing Histograms...\n";
00331
00332 edm::LogInfo("Tutorial") << "\nIntializing Finished. Filling...\n";
00333 NormalizeHistos();
00334 edm::LogInfo("Tutorial") << "\nFilled. Saving...\n";
00335
00336 edm::LogInfo("Tutorial") << "\nSaved. Peace, homie, I'm out.\n";
00337
00338 }
00339
00340 void MuIsoValidation::InitHistos(){
00341
00342
00343 h_nMuons = dbe->book1D("nMuons", title_sam + "Number of Muons", 20, 0., 20.);
00344 h_nMuons->setAxisTitle("Number of Muons",XAXIS);
00345 h_nMuons->setAxisTitle("Fraction of Events",YAXIS);
00346
00347
00348
00349 for(int var = 0; var < NUM_VARS; var++){
00350 h_1D[var] = dbe->book1D(
00351 names[var],
00352 title_sam + main_titles[var] + title_cone,
00353 (int)param[var][0],
00354 param[var][1],
00355 param[var][2]
00356 );
00357 cd_plots[var] = dbe->book1D(
00358 names[var] + "_cd",
00359 title_sam + title_cd + main_titles[var] + title_cone,
00360 (int)param[var][0],
00361 param[var][1],
00362 param[var][2]
00363 );
00364
00365 h_1D[var]->setAxisTitle(axis_titles[var],XAXIS);
00366 h_1D[var]->setAxisTitle("Fraction of Muons",YAXIS);
00367 GetTH1FromMonitorElement(h_1D[var])->Sumw2();
00368
00369 cd_plots[var]->setAxisTitle(axis_titles[var],XAXIS);
00370 cd_plots[var]->setAxisTitle("Fraction of Muons",YAXIS);
00371 GetTH1FromMonitorElement(cd_plots[var])->Sumw2();
00372
00373 }
00374
00375
00376 for(int var1 = 0; var1 < NUM_VARS; var1++){
00377 for(int var2 = 0; var2 < NUM_VARS; var2++){
00378 if(var1 == var2) continue;
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394 p_2D[var1][var2] = dbe->bookProfile(
00395 names[var1] + "_" + names[var2],
00396 title_sam + main_titles[var2] + " <vs> " + main_titles[var1] + title_cone,
00397 (int)param[var1][0],
00398 param[var1][1],
00399 param[var1][2],
00400 (int)param[var2][0],
00401 param[var2][1],
00402 param[var2][2],
00403 " "
00404 );
00405
00406 if(LOG_BINNING_ENABLED && isContinuous[var1]){
00407 Double_t * bin_edges = new Double_t[NUM_LOG_BINS+1];
00408
00409 MakeLogBinsForProfile(bin_edges, param[var1][1], param[var1][2]);
00410 GetTProfileFromMonitorElement(p_2D[var1][var2])->
00411 SetBins(NUM_LOG_BINS, bin_edges);
00412 delete[] bin_edges;
00413 }
00414
00415
00416
00417
00418
00419 p_2D[var1][var2]->setAxisTitle(axis_titles[var1],XAXIS);
00420 p_2D[var1][var2]->setAxisTitle(axis_titles[var2],YAXIS);
00421
00422 }
00423 }
00424
00425
00426
00427
00428
00429
00430
00431
00432 p_2D[4][9]->setAxisRange(0.5,15.5,XAXIS);
00433
00434 }
00435
00436 void MuIsoValidation::MakeLogBinsForProfile(Double_t* bin_edges, const double min,
00437 const double max){
00438
00439 const double &r = LOG_BINNING_RATIO;
00440 const int &nbins = NUM_LOG_BINS;
00441
00442 const double first_bin_width = (r > 1.0) ?
00443 (max - min)*(1-r)/(1-pow(r,nbins)) :
00444 (max - min)/nbins;
00445
00446 bin_edges[0] = min;
00447 bin_edges[1] = min + first_bin_width;
00448 for(int n = 2; n<nbins; ++n){
00449 bin_edges[n] = bin_edges[n-1] + (bin_edges[n-1] - bin_edges[n-2])*r;
00450 }
00451 bin_edges[nbins] = max;
00452 }
00453
00454 void MuIsoValidation::NormalizeHistos() {
00455 for(int var=0; var<NUM_VARS; var++){
00456
00457
00458
00459
00460 double entries = GetTH1FromMonitorElement(h_1D[var])->GetEntries();
00461 if (entries==0)continue;
00462 int n_max = int(param[var][0])+1;
00463 for(int n=1; n<=n_max; ++n){
00464 cd_plots[var]->setBinContent(n, cd_plots[var]->getBinContent(n) + cd_plots[var]->getBinContent(n-1));
00465 }
00466
00467 if (requireCombinedMuon) {
00468 GetTH1FromMonitorElement(h_1D[var])->Scale(1./entries);
00469 GetTH1FromMonitorElement(cd_plots[var])->Scale(1./entries);
00470 }
00471 else {
00472 GetTH1FromMonitorElement(h_1D[var])->Scale(1./entries);
00473 GetTH1FromMonitorElement(cd_plots[var])->Scale(1./entries);
00474 }
00475 }
00476 }
00477
00478 void MuIsoValidation::FillHistos() {
00479
00480 int overFlowBin;
00481 double overFlow = 0;
00482
00483
00484 for(int var=0; var<NUM_VARS; var++){
00485 h_1D[var]->Fill(theData[var]);
00486 cd_plots[var]->Fill(theData[var]);
00487 if (theData[var] > param[var][2]) {
00488
00489 overFlowBin = (int) param[var][0] + 1;
00490 overFlow = GetTH1FromMonitorElement(h_1D[var])->GetBinContent(overFlowBin);
00491 GetTH1FromMonitorElement(h_1D[var])->SetBinContent(overFlowBin, overFlow + 1);
00492 }
00493 }
00494
00495
00496 for(int var1=0; var1<NUM_VARS; ++var1){
00497 for(int var2=0; var2<NUM_VARS; ++var2){
00498 if(var1 == var2) continue;
00499
00500
00501 p_2D[var1][var2]->Fill(theData[var1], theData[var2]);
00502 }
00503 }
00504 }
00505
00506 TH1* MuIsoValidation::GetTH1FromMonitorElement(MonitorElement* me) {
00507 return me->getTH1();
00508 }
00509
00510 TH2* MuIsoValidation::GetTH2FromMonitorElement(MonitorElement* me) {
00511 return me->getTH2F();
00512 }
00513
00514 TProfile* MuIsoValidation::GetTProfileFromMonitorElement(MonitorElement* me) {
00515 return me->getTProfile();
00516 }
00517
00518
00519
00520 DEFINE_FWK_MODULE(MuIsoValidation);