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
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 #include <iostream>
00088 #include <map>
00089 #include <cmath>
00090 #include <TMath.h>
00091 #include <TFile.h>
00092 #include <TTree.h>
00093 #include <TH1.h>
00094 #include <TDOMParser.h>
00095 #include <TXMLDocument.h>
00096 #include "TUnfoldBinningXML.h"
00097
00098 using namespace std;
00099
00100
00101 void testUnfold7b()
00102 {
00103
00104 TH1::SetDefaultSumw2();
00105
00106
00107
00108
00109 TFile *outputFile=new TFile("testUnfold7_histograms.root","recreate");
00110
00111
00112
00113
00114
00115 TUnfoldBinning *fineBinningRoot,*coarseBinningRoot;
00116
00117 outputFile->cd();
00118
00119
00120
00121 TDOMParser parser;
00122 Int_t error=parser.ParseFile("testUnfold7binning.xml");
00123 if(error) {
00124 cout<<"error="<<error<<" from TDOMParser\n";
00125 cout<<"==============================================================\n";
00126 cout<<"Maybe the file testUnfold7binning.xml is missing?\n";
00127 cout<<"The content of the file is included in the comments section\n";
00128 cout<<"of this macro \"testUnfold7b.C\"\n";
00129 cout<<"==============================================================\n";
00130 }
00131 TXMLDocument const *XMLdocument=parser.GetXMLDocument();
00132 fineBinningRoot=
00133 TUnfoldBinningXML::ImportXML(XMLdocument,"fine");
00134 coarseBinningRoot=
00135 TUnfoldBinningXML::ImportXML(XMLdocument,"coarse");
00136
00137
00138 fineBinningRoot->Write();
00139 coarseBinningRoot->Write();
00140
00141 if(fineBinningRoot) {
00142 fineBinningRoot->PrintStream(cout);
00143 } else {
00144 cout<<"could not read 'detector' binning\n";
00145 }
00146 if(coarseBinningRoot) {
00147 coarseBinningRoot->PrintStream(cout);
00148 } else {
00149 cout<<"could not read 'generator' binning\n";
00150 }
00151
00152 TUnfoldBinning const *fineBinning=fineBinningRoot;
00153 TUnfoldBinning const *coarseBinning=coarseBinningRoot;
00154
00155
00156
00157
00158
00159 Float_t ptRec[3],ptGen[3],weight;
00160 Int_t isTriggered,isSignal;
00161
00162 outputFile->cd();
00163
00164 TH1 *histDataRecF=fineBinning->CreateHistogram("histDataRecF");
00165 TH1 *histDataRecC=coarseBinning->CreateHistogram("histDataRecC");
00166 TH1 *histDataBgrF=fineBinning->CreateHistogram("histDataBgrF");
00167 TH1 *histDataBgrC=coarseBinning->CreateHistogram("histDataBgrC");
00168 TH1 *histDataGen=coarseBinning->CreateHistogram("histDataGen");
00169
00170 TFile *dataFile=new TFile("testUnfold7_data.root");
00171 TTree *dataTree=(TTree *) dataFile->Get("data");
00172
00173 if(!dataTree) {
00174 cout<<"could not read 'data' tree\n";
00175 }
00176
00177 dataTree->ResetBranchAddresses();
00178 dataTree->SetBranchAddress("ptrec",ptRec);
00179
00180
00181 dataTree->SetBranchAddress("istriggered",&isTriggered);
00182
00183 dataTree->SetBranchAddress("ptgen",ptGen);
00184 dataTree->SetBranchAddress("issignal",&isSignal);
00185 dataTree->SetBranchStatus("*",1);
00186
00187 cout<<"loop over data events\n";
00188
00189 #define VAR_REC (ptRec[2])
00190 #define VAR_GEN (ptGen[2])
00191
00192 for(Int_t ievent=0;ievent<dataTree->GetEntriesFast();ievent++) {
00193 if(dataTree->GetEntry(ievent)<=0) break;
00194
00195 if(isTriggered) {
00196 int binF=fineBinning->GetGlobalBinNumber(VAR_REC);
00197 int binC=coarseBinning->GetGlobalBinNumber(VAR_REC);
00198 histDataRecF->Fill(binF);
00199 histDataRecC->Fill(binC);
00200 if(!isSignal) {
00201 histDataBgrF->Fill(binF);
00202 histDataBgrC->Fill(binC);
00203 }
00204 }
00205
00206 if(isSignal) {
00207 int binGen=coarseBinning->GetGlobalBinNumber(VAR_GEN);
00208 histDataGen->Fill(binGen);
00209 }
00210 }
00211
00212 delete dataTree;
00213 delete dataFile;
00214
00215
00216
00217
00218
00219 outputFile->cd();
00220
00221 TH2 *histMcsigGenRecF=TUnfoldBinning::CreateHistogramOfMigrations
00222 (coarseBinning,fineBinning,"histMcsigGenRecF");
00223 TH2 *histMcsigGenRecC=TUnfoldBinning::CreateHistogramOfMigrations
00224 (coarseBinning,coarseBinning,"histMcsigGenRecC");
00225 TH1 *histMcsigRecF=fineBinning->CreateHistogram("histMcsigRecF");
00226 TH1 *histMcsigRecC=coarseBinning->CreateHistogram("histMcsigRecC");
00227 TH1 *histMcsigGen=coarseBinning->CreateHistogram("histMcsigGen");
00228
00229 TFile *signalFile=new TFile("testUnfold7_signal.root");
00230 TTree *signalTree=(TTree *) signalFile->Get("signal");
00231
00232 if(!signalTree) {
00233 cout<<"could not read 'signal' tree\n";
00234 }
00235
00236 signalTree->ResetBranchAddresses();
00237 signalTree->SetBranchAddress("ptrec",&ptRec);
00238
00239 signalTree->SetBranchAddress("istriggered",&isTriggered);
00240 signalTree->SetBranchAddress("ptgen",&ptGen);
00241 signalTree->SetBranchAddress("weight",&weight);
00242 signalTree->SetBranchStatus("*",1);
00243
00244 cout<<"loop over MC signal events\n";
00245
00246 for(Int_t ievent=0;ievent<signalTree->GetEntriesFast();ievent++) {
00247 if(signalTree->GetEntry(ievent)<=0) break;
00248
00249 int binC=0,binF=0;
00250 if(isTriggered) {
00251 binF=fineBinning->GetGlobalBinNumber(VAR_REC);
00252 binC=coarseBinning->GetGlobalBinNumber(VAR_REC);
00253 }
00254 int binGen=coarseBinning->GetGlobalBinNumber(VAR_GEN);
00255 histMcsigGenRecF->Fill(binGen,binF,weight);
00256 histMcsigGenRecC->Fill(binGen,binC,weight);
00257 histMcsigRecF->Fill(binF,weight);
00258 histMcsigRecC->Fill(binC,weight);
00259 histMcsigGen->Fill(binGen,weight);
00260 }
00261
00262 delete signalTree;
00263 delete signalFile;
00264
00265 outputFile->cd();
00266
00267 TH1 *histMcbgrRecF=fineBinning->CreateHistogram("histMcbgrRecF");
00268 TH1 *histMcbgrRecC=coarseBinning->CreateHistogram("histMcbgrRecC");
00269
00270 TFile *bgrFile=new TFile("testUnfold7_background.root");
00271 TTree *bgrTree=(TTree *) bgrFile->Get("background");
00272
00273 if(!bgrTree) {
00274 cout<<"could not read 'background' tree\n";
00275 }
00276
00277 bgrTree->ResetBranchAddresses();
00278 bgrTree->SetBranchAddress("ptrec",&ptRec);
00279
00280 bgrTree->SetBranchAddress("istriggered",&isTriggered);
00281 bgrTree->SetBranchAddress("weight",&weight);
00282 bgrTree->SetBranchStatus("*",1);
00283
00284 cout<<"loop over MC background events\n";
00285
00286 for(Int_t ievent=0;ievent<bgrTree->GetEntriesFast();ievent++) {
00287 if(bgrTree->GetEntry(ievent)<=0) break;
00288
00289
00290
00291 if(isTriggered) {
00292 int binF=fineBinning->GetGlobalBinNumber(VAR_REC);
00293 int binC=coarseBinning->GetGlobalBinNumber(VAR_REC);
00294 histMcbgrRecF->Fill(binF,weight);
00295 histMcbgrRecC->Fill(binC,weight);
00296 }
00297 }
00298
00299 delete bgrTree;
00300 delete bgrFile;
00301
00302 outputFile->Write();
00303 delete outputFile;
00304
00305 }