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