[2] | 1 |
|
---|
| 2 | #include <iostream>
|
---|
| 3 | #include <map>
|
---|
| 4 |
|
---|
| 5 | #include "TChain.h"
|
---|
| 6 | #include "TString.h"
|
---|
| 7 | #include "TApplication.h"
|
---|
| 8 |
|
---|
| 9 | #include "TH2.h"
|
---|
| 10 | #include "THStack.h"
|
---|
| 11 | #include "TLegend.h"
|
---|
| 12 | #include "TPaveText.h"
|
---|
| 13 | #include "TLorentzVector.h"
|
---|
| 14 |
|
---|
| 15 | #include "ExRootAnalysis/ExRootClasses.h"
|
---|
| 16 |
|
---|
| 17 | #include "ExRootAnalysis/ExRootConfReader.h"
|
---|
| 18 | #include "ExRootAnalysis/ExRootTreeReader.h"
|
---|
| 19 | #include "ExRootAnalysis/ExRootTreeWriter.h"
|
---|
| 20 | #include "ExRootAnalysis/ExRootTreeBranch.h"
|
---|
| 21 | #include "ExRootAnalysis/ExRootClassifier.h"
|
---|
| 22 | #include "ExRootAnalysis/ExRootUtilities.h"
|
---|
| 23 | #include "ExRootAnalysis/ExRootFilter.h"
|
---|
| 24 | #include "ExRootAnalysis/ExRootResult.h"
|
---|
| 25 |
|
---|
| 26 | using namespace std;
|
---|
| 27 |
|
---|
| 28 | //------------------------------------------------------------------------------
|
---|
| 29 |
|
---|
| 30 | class TParticleClassifier: public ExRootClassifier
|
---|
| 31 | {
|
---|
| 32 | public:
|
---|
| 33 | TParticleClassifier() {}
|
---|
| 34 |
|
---|
| 35 | void AddParticleID(Int_t category, Int_t pid)
|
---|
| 36 | {
|
---|
| 37 | fMap[pid] = category;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | Int_t GetCategory(TObject *object) const
|
---|
| 41 | {
|
---|
| 42 | ExRootGenParticle *particle = (ExRootGenParticle*) object;
|
---|
| 43 | Int_t pid = particle->PID;
|
---|
| 44 | std::map<Int_t, Int_t>::const_iterator itMap = fMap.find(pid);
|
---|
| 45 | return itMap != fMap.end() ? itMap->second : -1;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | private:
|
---|
| 49 | std::map<Int_t, Int_t> fMap;
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 | //------------------------------------------------------------------------------
|
---|
| 53 |
|
---|
| 54 | struct MyPlots
|
---|
| 55 | {
|
---|
| 56 | TH1 *fParticlePT;
|
---|
| 57 | TH1 *fJetPT[2];
|
---|
| 58 | TH1 *fMissingET;
|
---|
| 59 | TH1 *fElectronPT;
|
---|
| 60 | };
|
---|
| 61 |
|
---|
| 62 | //------------------------------------------------------------------------------
|
---|
| 63 |
|
---|
| 64 | void BookHistograms(ExRootResult *result, MyPlots *plots, Int_t classIndex)
|
---|
| 65 | {
|
---|
| 66 | THStack *stack;
|
---|
| 67 | TLegend *legend;
|
---|
| 68 | TPaveText *comment;
|
---|
| 69 |
|
---|
| 70 | // book 1 histogram for (PT(track) - PT(particle))/(PT(track) + PT(particle))
|
---|
| 71 |
|
---|
| 72 | plots->fParticlePT = result->AddHist1D("particle_pt",
|
---|
| 73 | "particle P_{T}",
|
---|
| 74 | "particle P_{T}, GeV/c",
|
---|
| 75 | "number of particles", 50, 0.0, 100.0);
|
---|
| 76 |
|
---|
| 77 | // book 2 histograms for PT of 1st and 2nd leading jets
|
---|
| 78 |
|
---|
| 79 | plots->fJetPT[0] = result->AddHist1D("jet_pt_0", "leading jet P_{T}",
|
---|
| 80 | "jet P_{T}, GeV/c", "number of jets",
|
---|
| 81 | 50, 0.0, 100.0);
|
---|
| 82 |
|
---|
| 83 | plots->fJetPT[1] = result->AddHist1D("jet_pt_1", "2nd leading jet P_{T}",
|
---|
| 84 | "jet P_{T}, GeV/c", "number of jets",
|
---|
| 85 | 50, 0.0, 100.0);
|
---|
| 86 |
|
---|
| 87 | plots->fJetPT[0]->SetLineColor(kRed);
|
---|
| 88 | plots->fJetPT[1]->SetLineColor(kBlue);
|
---|
| 89 |
|
---|
| 90 | // book 1 stack of 2 histograms
|
---|
| 91 |
|
---|
| 92 | stack = result->AddHistStack("jet_pt_all", "1st and 2nd jets P_{T}");
|
---|
| 93 | stack->Add(plots->fJetPT[0]);
|
---|
| 94 | stack->Add(plots->fJetPT[1]);
|
---|
| 95 |
|
---|
| 96 | // book legend for stack of 2 histograms
|
---|
| 97 |
|
---|
| 98 | legend = result->AddLegend(0.72, 0.86, 0.98, 0.98);
|
---|
| 99 | legend->AddEntry(plots->fJetPT[0], "leading jet", "l");
|
---|
| 100 | legend->AddEntry(plots->fJetPT[1], "second jet", "l");
|
---|
| 101 |
|
---|
| 102 | // attach legend to stack (legend will be printed over stack in .eps file)
|
---|
| 103 |
|
---|
| 104 | result->Attach(stack, legend);
|
---|
| 105 |
|
---|
| 106 | // book more histograms
|
---|
| 107 |
|
---|
| 108 | plots->fMissingET = result->AddHist1D("missing_et", "Missing E_{T}",
|
---|
| 109 | "Missing E_{T}, GeV",
|
---|
| 110 | "number of events",
|
---|
| 111 | 60, 0.0, 30.0);
|
---|
| 112 |
|
---|
| 113 | plots->fElectronPT = result->AddHist1D("electron_pt", "electron P_{T}",
|
---|
| 114 | "electron P_{T}, GeV/c",
|
---|
| 115 | "number of electrons",
|
---|
| 116 | 50, 0.0, 100.0);
|
---|
| 117 |
|
---|
| 118 | // book general comment
|
---|
| 119 |
|
---|
| 120 | comment = result->AddComment(0.54, 0.72, 0.98, 0.98);
|
---|
| 121 | comment->AddText("demonstration plot");
|
---|
| 122 | comment->AddText("produced by Example.C");
|
---|
| 123 |
|
---|
| 124 | // attach comment to single histograms
|
---|
| 125 |
|
---|
| 126 | result->Attach(plots->fParticlePT, comment);
|
---|
| 127 | result->Attach(plots->fJetPT[0], comment);
|
---|
| 128 | result->Attach(plots->fJetPT[1], comment);
|
---|
| 129 | result->Attach(plots->fMissingET, comment);
|
---|
| 130 | result->Attach(plots->fElectronPT, comment);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | //------------------------------------------------------------------------------
|
---|
| 134 |
|
---|
| 135 | void AnalyseEvents(ExRootTreeReader *treeReader, TParticleClassifier *classifier, MyPlots *plots)
|
---|
| 136 | {
|
---|
| 137 | TClonesArray *branchGenParticle = treeReader->UseBranch("GenParticle");
|
---|
| 138 |
|
---|
| 139 | ExRootGenParticle *particle;
|
---|
| 140 |
|
---|
| 141 | ExRootFilter *filterGenParticle = new ExRootFilter(branchGenParticle);
|
---|
| 142 |
|
---|
| 143 | const TObjArray *particles;
|
---|
| 144 |
|
---|
| 145 | Long64_t entry;
|
---|
| 146 | Int_t particleIndex, classIndex;
|
---|
| 147 |
|
---|
| 148 | // Loop over all events
|
---|
| 149 | while(treeReader->ReadEntry(entry++))
|
---|
| 150 | {
|
---|
| 151 | if(entry % 1000 == 0) cout << "event " << entry << endl;
|
---|
| 152 |
|
---|
| 153 | filterGenParticle->Reset();
|
---|
| 154 |
|
---|
| 155 | // Loop over all classes
|
---|
| 156 | for(classIndex = 0; classIndex < 1; ++classIndex)
|
---|
| 157 | {
|
---|
| 158 | particles = filterGenParticle->GetSubArray(classifier, classIndex);
|
---|
| 159 |
|
---|
| 160 | if(!particles) continue;
|
---|
| 161 |
|
---|
| 162 | // sort particles by PT
|
---|
| 163 | ExRootGenParticle::fgCompare = TComparePT<ExRootGenParticle>::Instance();
|
---|
| 164 | particles->Sort();
|
---|
| 165 |
|
---|
| 166 | TIter itParticles(particles);
|
---|
| 167 |
|
---|
| 168 | // Loop over all generated particles
|
---|
| 169 | counterParticle = 0;
|
---|
| 170 | itParticles.Reset();
|
---|
| 171 | while(particle = (ExRootGenParticle*) itParticles.Next())
|
---|
| 172 | {
|
---|
| 173 | ++counterParticle;
|
---|
| 174 | if(counterParticle > plots->counterMax)
|
---|
| 175 | {
|
---|
| 176 | BookHistograms(classIndex);
|
---|
| 177 | }
|
---|
| 178 | plots->fParticlePT->Fill(particle->PT);
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | delete filterGenParticle;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | //------------------------------------------------------------------------------
|
---|
| 187 |
|
---|
| 188 | void PrintHistograms(ExRootResult *result, MyPlots *plots)
|
---|
| 189 | {
|
---|
| 190 | result->Print();
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | //------------------------------------------------------------------------------
|
---|
| 194 |
|
---|
| 195 | int main(int argc, char *argv[])
|
---|
| 196 | {
|
---|
| 197 |
|
---|
| 198 | int appargc = 2;
|
---|
| 199 | char *appName = "JetsSim";
|
---|
| 200 | char *appargv[] = {appName, "-b"};
|
---|
| 201 | TApplication app(appName, &appargc, appargv);
|
---|
| 202 |
|
---|
| 203 | if(argc != 2)
|
---|
| 204 | {
|
---|
| 205 | cout << " Usage: " << argv[0] << " input_file" << endl;
|
---|
| 206 | cout << " input_file - configuration file in Tcl format." << endl;
|
---|
| 207 | return 1;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | TString inputFile(argv[1]);
|
---|
| 211 |
|
---|
| 212 | ExRootConfReader *confReader = new ExRootConfReader();
|
---|
| 213 |
|
---|
| 214 | confReader->ReadFile(inputFile);
|
---|
| 215 |
|
---|
| 216 | TObjArray *chains = new TObjArray();
|
---|
| 217 | chains->SetOwner();
|
---|
| 218 |
|
---|
| 219 | ExRootConfParam param = confReader->GetParam("::InputCollection");
|
---|
| 220 | TString name;
|
---|
| 221 | Long_t i, sizeChains, sizeClasses, sizeParticles;
|
---|
| 222 | TChain *chain, *firstChain;
|
---|
| 223 | sizeChains = param.GetSize();
|
---|
| 224 | for(i = 0; i < sizeChains; ++i)
|
---|
| 225 | {
|
---|
| 226 | chain = new TChain("", "");
|
---|
| 227 | chains->Add(chain);
|
---|
| 228 | name = param[i][0].GetString();
|
---|
| 229 | chain->SetName(name);
|
---|
| 230 | FillChain(chain, param[i][1].GetString());
|
---|
| 231 | if(i == 0)
|
---|
| 232 | {
|
---|
| 233 | firstChain = chain;
|
---|
| 234 | }
|
---|
| 235 | else
|
---|
| 236 | {
|
---|
| 237 | firstChain->AddFriend(chain, name + i);
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | TParticleClassifier *classifier = new TParticleClassifier();
|
---|
| 242 |
|
---|
| 243 | param = confReader->GetParam("::ParticleClasses");
|
---|
| 244 | sizeClasses = param.GetSize();
|
---|
| 245 | for(i = 0; i < sizeClasses; ++i)
|
---|
| 246 | {
|
---|
| 247 | name = param[i][0].GetString();
|
---|
| 248 |
|
---|
| 249 | sizeParticles = param[i][1].GetSize();
|
---|
| 250 | for(j = 0; j < sizeParticles; ++j)
|
---|
| 251 | {
|
---|
| 252 | pid = param[i][1][j].GetInt();
|
---|
| 253 | classifierGenParticle->AddParticleID(i, pid);
|
---|
| 254 | }
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | ExRootTreeReader *treeReader = new ExRootTreeReader(chain);
|
---|
| 258 | ExRootResult *result = new ExRootResult();
|
---|
| 259 |
|
---|
| 260 | MyPlots *plots = new MyPlots();
|
---|
| 261 |
|
---|
| 262 | BookHistograms(result, plots);
|
---|
| 263 |
|
---|
| 264 | AnalyseEvents(treeReader, classifier, plots);
|
---|
| 265 |
|
---|
| 266 | PrintHistograms(result, plots);
|
---|
| 267 |
|
---|
| 268 | cout << "** Exiting..." << endl;
|
---|
| 269 |
|
---|
| 270 | delete plots;
|
---|
| 271 | delete result;
|
---|
| 272 | delete treeReader;
|
---|
| 273 | delete classifierGenParticle;
|
---|
| 274 | delete chains;
|
---|
| 275 | delete confReader;
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | //------------------------------------------------------------------------------
|
---|
| 279 |
|
---|