[d1e6379] | 1 | /** \class TrackSmearing
|
---|
| 2 | *
|
---|
| 3 | * Performs d0, dZ, p, Theta, Phi smearing of tracks.
|
---|
| 4 | *
|
---|
| 5 | *
|
---|
| 6 | *
|
---|
| 7 | * \author A. Hart, M. Selvaggi
|
---|
| 8 | *
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | #include "modules/TrackSmearing.h"
|
---|
| 12 |
|
---|
| 13 | #include "classes/DelphesClasses.h"
|
---|
| 14 | #include "classes/DelphesFactory.h"
|
---|
| 15 | #include "classes/DelphesFormula.h"
|
---|
| 16 |
|
---|
| 17 | #include "ExRootAnalysis/ExRootResult.h"
|
---|
| 18 | #include "ExRootAnalysis/ExRootFilter.h"
|
---|
| 19 | #include "ExRootAnalysis/ExRootClassifier.h"
|
---|
| 20 |
|
---|
| 21 | #include "TMath.h"
|
---|
| 22 | #include "TString.h"
|
---|
| 23 | #include "TFormula.h"
|
---|
| 24 | #include "TRandom3.h"
|
---|
| 25 | #include "TObjArray.h"
|
---|
| 26 | #include "TDatabasePDG.h"
|
---|
| 27 | #include "TLorentzVector.h"
|
---|
| 28 | #include "TFile.h"
|
---|
| 29 | #include "TProfile2D.h"
|
---|
| 30 |
|
---|
| 31 | #include <algorithm>
|
---|
| 32 | #include <stdexcept>
|
---|
| 33 | #include <iostream>
|
---|
| 34 | #include <sstream>
|
---|
| 35 |
|
---|
| 36 | using namespace std;
|
---|
| 37 |
|
---|
| 38 | //------------------------------------------------------------------------------
|
---|
| 39 |
|
---|
| 40 | TrackSmearing::TrackSmearing() :
|
---|
| 41 | fD0Formula(0), fDZFormula(0), fPFormula(0), fCtgThetaFormula(0), fPhiFormula(0), fItInputArray(0)
|
---|
| 42 | {
|
---|
| 43 | fD0Formula = new DelphesFormula;
|
---|
| 44 | fDZFormula = new DelphesFormula;
|
---|
| 45 | fPFormula = new DelphesFormula;
|
---|
| 46 | fCtgThetaFormula = new DelphesFormula;
|
---|
| 47 | fPhiFormula = new DelphesFormula;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | //------------------------------------------------------------------------------
|
---|
| 51 |
|
---|
| 52 | TrackSmearing::~TrackSmearing()
|
---|
| 53 | {
|
---|
| 54 | if(fD0Formula) delete fD0Formula;
|
---|
| 55 | if(fDZFormula) delete fDZFormula;
|
---|
| 56 | if(fPFormula) delete fPFormula;
|
---|
| 57 | if(fCtgThetaFormula) delete fCtgThetaFormula;
|
---|
| 58 | if(fPhiFormula) delete fPhiFormula;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | //------------------------------------------------------------------------------
|
---|
| 62 |
|
---|
| 63 | void TrackSmearing::Init()
|
---|
| 64 | {
|
---|
| 65 | // read resolution formula
|
---|
| 66 |
|
---|
| 67 | // !!! IF WE WANT TO KEEP ROOT INPUT !!!
|
---|
| 68 | if (string (GetString("D0ResolutionFormula", "0.0")) != "0.0")
|
---|
| 69 | {
|
---|
| 70 | fD0Formula->Compile(GetString("D0ResolutionFormula", "0.0"));
|
---|
| 71 | fUseD0Formula = true;
|
---|
| 72 | }
|
---|
| 73 | else
|
---|
| 74 | {
|
---|
| 75 | fD0ResolutionFile = GetString("D0ResolutionFile", "errors.root");
|
---|
| 76 | fD0ResolutionHist = GetString("D0ResolutionHist", "d0");
|
---|
| 77 | fUseD0Formula = false;
|
---|
| 78 | }
|
---|
| 79 | if (string (GetString("DZResolutionFormula", "0.0")) != "0.0")
|
---|
| 80 | {
|
---|
| 81 | fDZFormula->Compile(GetString("DZResolutionFormula", "0.0"));
|
---|
| 82 | fUseDZFormula = true;
|
---|
| 83 | }
|
---|
| 84 | else
|
---|
| 85 | {
|
---|
| 86 | fDZResolutionFile = GetString("DZResolutionFile", "errors.root");
|
---|
| 87 | fDZResolutionHist = GetString("DZResolutionHist", "dz");
|
---|
| 88 | fUseDZFormula = false;
|
---|
| 89 | }
|
---|
| 90 | if (string (GetString("PResolutionFormula", "0.0")) != "0.0")
|
---|
| 91 | {
|
---|
| 92 | fPFormula->Compile(GetString("PResolutionFormula", "0.0"));
|
---|
| 93 | fUsePFormula = true;
|
---|
| 94 | }
|
---|
| 95 | else
|
---|
| 96 | {
|
---|
| 97 | fPResolutionFile = GetString("PResolutionFile", "errors.root");
|
---|
| 98 | fPResolutionHist = GetString("PResolutionHist", "p");
|
---|
| 99 | fUsePFormula = false;
|
---|
| 100 | }
|
---|
| 101 | if (string (GetString("CtgThetaResolutionFormula", "0.0")) != "0.0")
|
---|
| 102 | {
|
---|
| 103 | fCtgThetaFormula->Compile(GetString("CtgThetaResolutionFormula", "0.0"));
|
---|
| 104 | fUseCtgThetaFormula = true;
|
---|
| 105 | }
|
---|
| 106 | else
|
---|
| 107 | {
|
---|
| 108 | fCtgThetaResolutionFile = GetString("CtgThetaResolutionFile", "errors.root");
|
---|
| 109 | fCtgThetaResolutionHist = GetString("CtgThetaResolutionHist", "ctgTheta");
|
---|
| 110 | fUseCtgThetaFormula = false;
|
---|
| 111 | }
|
---|
| 112 | if (string (GetString("PhiResolutionFormula", "0.0")) != "0.0")
|
---|
| 113 | {
|
---|
| 114 | fPhiFormula->Compile(GetString("PhiResolutionFormula", "0.0"));
|
---|
| 115 | fUsePhiFormula = true;
|
---|
| 116 | }
|
---|
| 117 | else
|
---|
| 118 | {
|
---|
| 119 | fPhiResolutionFile = GetString("PhiResolutionFile", "errors.root");
|
---|
| 120 | fPhiResolutionHist = GetString("PhiResolutionHist", "phi");
|
---|
| 121 | fUsePhiFormula = false;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | fApplyToPileUp = GetBool("ApplyToPileUp", true);
|
---|
| 125 |
|
---|
| 126 | // import input array
|
---|
| 127 |
|
---|
| 128 | fInputArray = ImportArray(GetString("InputArray", "ParticlePropagator/stableParticles"));
|
---|
| 129 | fItInputArray = fInputArray->MakeIterator();
|
---|
| 130 |
|
---|
| 131 | fBeamSpotInputArray = ImportArray(GetString("BeamSpotInputArray", "BeamSpotFilter/beamSpotParticle"));
|
---|
| 132 |
|
---|
| 133 | // create output array
|
---|
| 134 |
|
---|
| 135 | fOutputArray = ExportArray(GetString("OutputArray", "stableParticles"));
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | //------------------------------------------------------------------------------
|
---|
| 139 |
|
---|
| 140 | void TrackSmearing::Finish()
|
---|
| 141 | {
|
---|
| 142 | if(fItInputArray) delete fItInputArray;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | //------------------------------------------------------------------------------
|
---|
| 146 |
|
---|
| 147 | void TrackSmearing::Process()
|
---|
| 148 | {
|
---|
| 149 | Int_t iCandidate = 0;
|
---|
| 150 | TLorentzVector beamSpotPosition;
|
---|
| 151 | Candidate *candidate, *mother;
|
---|
| 152 | Double_t pt, eta, d0, d0Error, trueD0, dz, dzError, trueDZ, p, pError, trueP, ctgTheta, ctgThetaError, trueCtgTheta, phi, phiError, truePhi;
|
---|
| 153 | Double_t x, y, z, t, px, py, pz, theta;
|
---|
| 154 | TProfile2D *d0ErrorHist = NULL,
|
---|
| 155 | *dzErrorHist = NULL,
|
---|
| 156 | *pErrorHist = NULL,
|
---|
| 157 | *ctgThetaErrorHist = NULL,
|
---|
| 158 | *phiErrorHist = NULL;
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | if (!fBeamSpotInputArray->GetSize () || !fBeamSpotInputArray->At(0))
|
---|
| 162 | beamSpotPosition.SetXYZT(0.0, 0.0, 0.0, 0.0);
|
---|
| 163 | else
|
---|
| 164 | {
|
---|
| 165 | Candidate &beamSpotCandidate = *((Candidate *) fBeamSpotInputArray->At (0));
|
---|
| 166 | beamSpotPosition = beamSpotCandidate.Position;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 | if (!fUseD0Formula)
|
---|
| 171 | {
|
---|
| 172 | TFile *fin = TFile::Open (fD0ResolutionFile.c_str ());
|
---|
| 173 | d0ErrorHist = (TProfile2D *) fin->Get (fD0ResolutionHist.c_str ());
|
---|
| 174 | d0ErrorHist->SetDirectory (0);
|
---|
| 175 | fin->Close ();
|
---|
| 176 | }
|
---|
| 177 | if (!fUseDZFormula)
|
---|
| 178 | {
|
---|
| 179 | TFile *fin = TFile::Open (fDZResolutionFile.c_str ());
|
---|
| 180 | dzErrorHist = (TProfile2D *) fin->Get (fDZResolutionHist.c_str ());
|
---|
| 181 | dzErrorHist->SetDirectory (0);
|
---|
| 182 | fin->Close ();
|
---|
| 183 | }
|
---|
| 184 | if (!fUsePFormula)
|
---|
| 185 | {
|
---|
| 186 | TFile *fin = TFile::Open (fPResolutionFile.c_str ());
|
---|
| 187 | pErrorHist = (TProfile2D *) fin->Get (fPResolutionHist.c_str ());
|
---|
| 188 | pErrorHist->SetDirectory (0);
|
---|
| 189 | fin->Close ();
|
---|
| 190 | }
|
---|
| 191 | if (!fUseCtgThetaFormula)
|
---|
| 192 | {
|
---|
| 193 | TFile *fin = TFile::Open (fCtgThetaResolutionFile.c_str ());
|
---|
| 194 | ctgThetaErrorHist = (TProfile2D *) fin->Get (fCtgThetaResolutionHist.c_str ());
|
---|
| 195 | ctgThetaErrorHist->SetDirectory (0);
|
---|
| 196 | fin->Close ();
|
---|
| 197 | }
|
---|
| 198 | if (!fUsePhiFormula)
|
---|
| 199 | {
|
---|
| 200 | TFile *fin = TFile::Open (fPhiResolutionFile.c_str ());
|
---|
| 201 | phiErrorHist = (TProfile2D *) fin->Get (fPhiResolutionHist.c_str ());
|
---|
| 202 | phiErrorHist->SetDirectory (0);
|
---|
| 203 | fin->Close ();
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | fItInputArray->Reset();
|
---|
| 207 | while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
|
---|
| 208 | {
|
---|
| 209 |
|
---|
| 210 | const TLorentzVector &momentum = candidate->Momentum;
|
---|
| 211 | const TLorentzVector &position = candidate->InitialPosition;
|
---|
| 212 |
|
---|
| 213 | pt = momentum.Pt();
|
---|
| 214 | eta = momentum.Eta();
|
---|
| 215 |
|
---|
| 216 | d0 = trueD0 = candidate->D0;
|
---|
| 217 | dz = trueDZ = candidate->DZ;
|
---|
| 218 | p = trueP = candidate->P;
|
---|
| 219 | ctgTheta = trueCtgTheta = candidate->CtgTheta;
|
---|
| 220 | phi = truePhi = candidate->Phi;
|
---|
| 221 |
|
---|
| 222 | if (fUseD0Formula)
|
---|
| 223 | d0Error = fD0Formula->Eval(pt, eta);
|
---|
| 224 | else
|
---|
| 225 | {
|
---|
| 226 | Int_t xbin, ybin;
|
---|
| 227 |
|
---|
| 228 | xbin = pt < d0ErrorHist->GetXaxis ()->GetXmax () ? d0ErrorHist->GetXaxis ()->FindBin (pt)
|
---|
| 229 | : d0ErrorHist->GetXaxis ()->GetBinCenter (d0ErrorHist->GetXaxis ()->GetNbins ());
|
---|
| 230 | ybin = d0ErrorHist->GetYaxis ()->FindBin (TMath::Abs (eta));
|
---|
| 231 | d0Error = d0ErrorHist->GetBinContent (xbin, ybin);
|
---|
| 232 | if (!d0Error)
|
---|
| 233 | d0Error = -1.0;
|
---|
| 234 | }
|
---|
| 235 | if (d0Error < 0.0)
|
---|
| 236 | continue;
|
---|
| 237 |
|
---|
| 238 | if (fUseDZFormula)
|
---|
| 239 | dzError = fDZFormula->Eval(pt, eta);
|
---|
| 240 | else
|
---|
| 241 | {
|
---|
| 242 | Int_t xbin, ybin;
|
---|
| 243 |
|
---|
| 244 | xbin = pt < dzErrorHist->GetXaxis ()->GetXmax () ? dzErrorHist->GetXaxis ()->FindBin (pt)
|
---|
| 245 | : dzErrorHist->GetXaxis ()->GetBinCenter (dzErrorHist->GetXaxis ()->GetNbins ());
|
---|
| 246 | ybin = dzErrorHist->GetYaxis ()->FindBin (TMath::Abs (eta));
|
---|
| 247 | dzError = dzErrorHist->GetBinContent (xbin, ybin);
|
---|
| 248 | if (!dzError)
|
---|
| 249 | dzError = -1.0;
|
---|
| 250 | }
|
---|
| 251 | if (dzError < 0.0)
|
---|
| 252 | continue;
|
---|
| 253 |
|
---|
| 254 | if (fUsePFormula)
|
---|
| 255 | pError = fPFormula->Eval(pt, eta) * p;
|
---|
| 256 | else
|
---|
| 257 | {
|
---|
| 258 | Int_t xbin, ybin;
|
---|
| 259 |
|
---|
| 260 | xbin = pt < pErrorHist->GetXaxis ()->GetXmax () ? pErrorHist->GetXaxis ()->FindBin (pt)
|
---|
| 261 | : pErrorHist->GetXaxis ()->GetBinCenter (pErrorHist->GetXaxis ()->GetNbins ());
|
---|
| 262 | ybin = pErrorHist->GetYaxis ()->FindBin (TMath::Abs (eta));
|
---|
| 263 | pError = pErrorHist->GetBinContent (xbin, ybin) * p;
|
---|
| 264 | if (!pError)
|
---|
| 265 | pError = -1.0;
|
---|
| 266 | }
|
---|
| 267 | if (pError < 0.0)
|
---|
| 268 | continue;
|
---|
| 269 |
|
---|
| 270 | if (fUseCtgThetaFormula)
|
---|
| 271 | ctgThetaError = fCtgThetaFormula->Eval(pt, eta);
|
---|
| 272 | else
|
---|
| 273 | {
|
---|
| 274 | Int_t xbin, ybin;
|
---|
| 275 |
|
---|
| 276 | xbin = pt < ctgThetaErrorHist->GetXaxis ()->GetXmax () ? ctgThetaErrorHist->GetXaxis ()->FindBin (pt)
|
---|
| 277 | : ctgThetaErrorHist->GetXaxis ()->GetBinCenter (ctgThetaErrorHist->GetXaxis ()->GetNbins ());
|
---|
| 278 | ybin = ctgThetaErrorHist->GetYaxis ()->FindBin (TMath::Abs (eta));
|
---|
| 279 | ctgThetaError = ctgThetaErrorHist->GetBinContent (xbin, ybin);
|
---|
| 280 | if (!ctgThetaError)
|
---|
| 281 | ctgThetaError = -1.0;
|
---|
| 282 | }
|
---|
| 283 | if (ctgThetaError < 0.0)
|
---|
| 284 | continue;
|
---|
| 285 |
|
---|
| 286 | if (fUsePhiFormula)
|
---|
| 287 | phiError = fPhiFormula->Eval(pt, eta);
|
---|
| 288 | else
|
---|
| 289 | {
|
---|
| 290 | Int_t xbin, ybin;
|
---|
| 291 |
|
---|
| 292 | xbin = pt < phiErrorHist->GetXaxis ()->GetXmax () ? phiErrorHist->GetXaxis ()->FindBin (pt)
|
---|
| 293 | : phiErrorHist->GetXaxis ()->GetBinCenter (phiErrorHist->GetXaxis ()->GetNbins ());
|
---|
| 294 | ybin = phiErrorHist->GetYaxis ()->FindBin (TMath::Abs (eta));
|
---|
| 295 | phiError = phiErrorHist->GetBinContent (xbin, ybin);
|
---|
| 296 | if (!phiError)
|
---|
| 297 | phiError = -1.0;
|
---|
| 298 | }
|
---|
| 299 | if (phiError < 0.0)
|
---|
| 300 | continue;
|
---|
| 301 |
|
---|
| 302 | if (fApplyToPileUp || !candidate->IsPU)
|
---|
| 303 | {
|
---|
| 304 | d0 = gRandom->Gaus(d0, d0Error);
|
---|
| 305 | dz = gRandom->Gaus(dz, dzError);
|
---|
| 306 | p = gRandom->Gaus(p, pError);
|
---|
| 307 | ctgTheta = gRandom->Gaus(ctgTheta, ctgThetaError);
|
---|
| 308 | phi = gRandom->Gaus(phi, phiError);
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | if(p < 0.0) continue;
|
---|
| 312 | while (phi > TMath::Pi ()) phi -= TMath::TwoPi ();
|
---|
| 313 | while (phi <= -TMath::Pi ()) phi += TMath::TwoPi ();
|
---|
| 314 |
|
---|
| 315 | mother = candidate;
|
---|
| 316 | candidate = static_cast<Candidate*>(candidate->Clone());
|
---|
| 317 | candidate->D0 = d0;
|
---|
| 318 | candidate->DZ = dz;
|
---|
| 319 | candidate->P = p;
|
---|
| 320 | candidate->CtgTheta = ctgTheta;
|
---|
| 321 | candidate->Phi = phi;
|
---|
| 322 |
|
---|
| 323 | theta = TMath::ACos(ctgTheta / TMath::Sqrt (1.0 + ctgTheta * ctgTheta));
|
---|
| 324 | candidate->Momentum.SetPx (p * TMath::Cos (phi) * TMath::Sin (theta));
|
---|
| 325 | candidate->Momentum.SetPy (p * TMath::Sin (phi) * TMath::Sin (theta));
|
---|
| 326 | candidate->Momentum.SetPz (p * TMath::Cos (theta));
|
---|
| 327 | candidate->Momentum.SetE (candidate->Momentum.Pt () * TMath::CosH (eta));
|
---|
| 328 | candidate->PT = candidate->Momentum.Pt ();
|
---|
| 329 |
|
---|
| 330 | x = position.X ();
|
---|
| 331 | y = position.Y ();
|
---|
| 332 | z = position.Z ();
|
---|
| 333 | t = position.T ();
|
---|
| 334 | px = candidate->Momentum.Px ();
|
---|
| 335 | py = candidate->Momentum.Py ();
|
---|
| 336 | pz = candidate->Momentum.Pz ();
|
---|
| 337 | pt = candidate->Momentum.Pt ();
|
---|
| 338 |
|
---|
[6e91f77] | 339 | // -- solve for delta: d0' = ( (x+delta)*py' - (y+delta)*px' )/pt'
|
---|
[d1e6379] | 340 |
|
---|
| 341 | candidate->InitialPosition.SetX (x + ((px * y - py * x + d0 * pt) / (py - px)));
|
---|
| 342 | candidate->InitialPosition.SetY (y + ((px * y - py * x + d0 * pt) / (py - px)));
|
---|
| 343 | x = candidate->InitialPosition.X ();
|
---|
| 344 | y = candidate->InitialPosition.Y ();
|
---|
| 345 | candidate->InitialPosition.SetZ (z + ((pz * (px * (x - beamSpotPosition.X ()) + py * (y - beamSpotPosition.Y ())) + pt * pt * (dz - z)) / (pt * pt)));
|
---|
| 346 | candidate->InitialPosition.SetT (t);
|
---|
| 347 |
|
---|
| 348 | if (fApplyToPileUp || !candidate->IsPU)
|
---|
| 349 | {
|
---|
| 350 | candidate->ErrorD0 = d0Error;
|
---|
| 351 | candidate->ErrorDZ = dzError;
|
---|
| 352 | candidate->ErrorP = pError;
|
---|
| 353 | candidate->ErrorCtgTheta = ctgThetaError;
|
---|
| 354 | candidate->ErrorPhi = phiError;
|
---|
| 355 | candidate->ErrorPT = ptError (p, ctgTheta, pError, ctgThetaError);
|
---|
| 356 | candidate->TrackResolution = pError;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | candidate->AddCandidate(mother);
|
---|
| 360 | fOutputArray->Add(candidate);
|
---|
| 361 |
|
---|
| 362 | iCandidate++;
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | Double_t TrackSmearing::ptError (const Double_t p, const Double_t ctgTheta, const Double_t dP, const Double_t dCtgTheta)
|
---|
| 367 | {
|
---|
| 368 | Double_t a, b;
|
---|
| 369 | a = (p * p * ctgTheta * ctgTheta * dCtgTheta * dCtgTheta) / ((ctgTheta * ctgTheta + 1) * (ctgTheta * ctgTheta + 1) * (ctgTheta * ctgTheta + 1));
|
---|
| 370 | b = (dP * dP) / (ctgTheta * ctgTheta + 1);
|
---|
| 371 | return sqrt (a + b);
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | //------------------------------------------------------------------------------
|
---|