[62cc8f5] | 1 | /*
|
---|
| 2 | * Delphes: a framework for fast simulation of a generic collider experiment
|
---|
| 3 | * Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
|
---|
| 4 | *
|
---|
| 5 | * This program is free software: you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 8 | * (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | /** \class EICPIDDetector
|
---|
| 20 | *
|
---|
| 21 | * Applies complex photon Id. Reconstructed photon candidtes are first separated into matched and non-matched to gen particles.
|
---|
| 22 | * Non-matched pass the "fake" efficiency. Matched photons get further splitted into isolated and non-isolated (user can choose criterion for isolation)
|
---|
| 23 | * Isolated photons pass the "prompt" efficiency while the non-isolated pass the "non-prompt" efficiency
|
---|
| 24 | *
|
---|
| 25 | * \author M. Selvaggi CERN
|
---|
| 26 | *
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #include "modules/EICPIDDetector.h"
|
---|
| 30 |
|
---|
| 31 | #include "classes/DelphesClasses.h"
|
---|
| 32 | #include "classes/DelphesFactory.h"
|
---|
| 33 | #include "classes/DelphesFormula.h"
|
---|
| 34 |
|
---|
| 35 | #include "ExRootAnalysis/ExRootClassifier.h"
|
---|
| 36 | #include "ExRootAnalysis/ExRootFilter.h"
|
---|
| 37 | #include "ExRootAnalysis/ExRootResult.h"
|
---|
| 38 |
|
---|
| 39 | #include "TDatabasePDG.h"
|
---|
| 40 | #include "TFormula.h"
|
---|
| 41 | #include "TLorentzVector.h"
|
---|
| 42 | #include "TMath.h"
|
---|
| 43 | #include "TObjArray.h"
|
---|
| 44 | #include "TRandom3.h"
|
---|
| 45 | #include "TString.h"
|
---|
| 46 | #include "Math/PdfFuncMathCore.h"
|
---|
| 47 | #include "Math/ProbFuncMathCore.h"
|
---|
| 48 |
|
---|
| 49 | #include "pid/barrelDIRC/src/barrelDirc.h"
|
---|
| 50 | #include "pid/quintRICH/src/CF4rich.h"
|
---|
| 51 | #include "pid/mRICH/src/mRICH.h"
|
---|
| 52 | #include "pid/tofBarrel/src/tofBarrel.h"
|
---|
| 53 |
|
---|
| 54 | #include <algorithm>
|
---|
| 55 | #include <iostream>
|
---|
| 56 | #include <sstream>
|
---|
| 57 | #include <stdexcept>
|
---|
| 58 |
|
---|
| 59 | using namespace std;
|
---|
| 60 |
|
---|
| 61 | //------------------------------------------------------------------------------
|
---|
| 62 |
|
---|
| 63 | EICPIDDetector::EICPIDDetector() :
|
---|
| 64 | fItInputArray(0)
|
---|
| 65 | {
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | //------------------------------------------------------------------------------
|
---|
| 69 |
|
---|
| 70 | EICPIDDetector::~EICPIDDetector()
|
---|
| 71 | {
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | //------------------------------------------------------------------------------
|
---|
| 75 |
|
---|
| 76 | void EICPIDDetector::Init()
|
---|
| 77 | {
|
---|
| 78 |
|
---|
| 79 | // import input arrays
|
---|
| 80 | fInputArray = ImportArray(GetString("InputArray", "ParticlePropagator/stableParticles"));
|
---|
| 81 | fItInputArray = fInputArray->MakeIterator();
|
---|
| 82 |
|
---|
| 83 | // PID Pair to be assessed
|
---|
| 84 | ExRootConfParam param;
|
---|
| 85 | Int_t size;
|
---|
| 86 | param = GetParam("Hypotheses");
|
---|
| 87 | size = param.GetSize();
|
---|
| 88 |
|
---|
| 89 | fHypo = static_cast<PID::type>(0);
|
---|
| 90 | if (size == 2) {
|
---|
| 91 | fPDG1 = abs(param[0].GetInt());
|
---|
| 92 | fPDG2 = abs(param[1].GetInt());
|
---|
| 93 |
|
---|
| 94 | if (fPDG1 == 321) {
|
---|
| 95 | if (fPDG2 == 211) {
|
---|
| 96 | fHypo = PID::pi_k;
|
---|
| 97 | } else if (fPDG2 == 2212) {
|
---|
| 98 | fHypo = PID::k_p;
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | } else {
|
---|
| 103 | // Bad parameter - do something intelligent here.
|
---|
| 104 | std::cout << "Unable to retrieve Particle ID hypothesis pair." << std::endl;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | fDetectorName = std::string(GetString("DetectorName", "barrelDirc"));
|
---|
| 109 |
|
---|
| 110 | // Common PID Detector parameters
|
---|
| 111 | fTrackResolution = GetDouble("TrackResolution", 0.5); // mrad
|
---|
| 112 | fTimeResolution = GetDouble("TimeResolution", 0.1); //ns
|
---|
| 113 | fDetectorLength = GetDouble("DetectorLength", 1500); // mm
|
---|
| 114 | fetaLow = GetDouble("EtaLow", -8.0);
|
---|
| 115 | fetaHigh = GetDouble("EtaHigh", 8.0);
|
---|
| 116 |
|
---|
| 117 | // Barrel DIRC Parameters
|
---|
| 118 | fQE = GetDouble("QuantumEfficiency", 0.0); // 0 = 27% for barrelDirc, 1 = 22% for barrelDirc
|
---|
| 119 |
|
---|
| 120 | // mRICH Parameters
|
---|
| 121 | fPixelSize = GetDouble("PixelSize", 1.0); // 1.0 mm
|
---|
| 122 |
|
---|
| 123 | // CF4RICH Parameters
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 | // Build the detector object
|
---|
| 127 | if (fDetectorName == "barrelDirc") {
|
---|
| 128 | fPIDDetector = new barrelDirc(fTrackResolution,fTimeResolution,fQE,fetaLow,fetaHigh);
|
---|
| 129 | }
|
---|
| 130 | else if (fDetectorName == "mRICH") {
|
---|
| 131 | fPIDDetector = new mRICH(fTrackResolution,fTimeResolution, fPixelSize);
|
---|
| 132 | //fPIDDetector = new mRICH(0.00175, 1, 3);
|
---|
| 133 | }
|
---|
| 134 | else if (fDetectorName == "CF4rich") {
|
---|
| 135 | fPIDDetector = new CF4rich(fDetectorLength/10, fetaLow, fetaHigh, fPixelSize, fTrackResolution);
|
---|
| 136 | }
|
---|
| 137 | else if (fDetectorName == "tofBarrel") {
|
---|
| 138 | fPIDDetector = new tofBarrel(100, fetaLow, fetaHigh, 10);
|
---|
| 139 | } else {
|
---|
| 140 | std::cout << "No valid EIC PID Detector technology was specified!" << std::endl;
|
---|
| 141 | assert(1==0);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | fPIDDetector->description();
|
---|
| 145 |
|
---|
| 146 | // create output array
|
---|
| 147 | fOutputArray = ExportArray(GetString("OutputArray", "tracks"));
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | //------------------------------------------------------------------------------
|
---|
| 151 |
|
---|
| 152 | void EICPIDDetector::Finish()
|
---|
| 153 | {
|
---|
| 154 | if(fItInputArray) delete fItInputArray;
|
---|
| 155 | if(fPIDDetector) delete fPIDDetector;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | //------------------------------------------------------------------------------
|
---|
| 159 |
|
---|
| 160 | void EICPIDDetector::Process()
|
---|
| 161 | {
|
---|
| 162 | Candidate *candidate, *mother;
|
---|
| 163 | Double_t pt, eta;
|
---|
| 164 | Int_t true_id;
|
---|
| 165 |
|
---|
| 166 | fItInputArray->Reset();
|
---|
| 167 | while((candidate = static_cast<Candidate *>(fItInputArray->Next())))
|
---|
| 168 | {
|
---|
| 169 |
|
---|
| 170 | mother = candidate;
|
---|
| 171 | candidate = static_cast<Candidate *>(candidate->Clone());
|
---|
| 172 | candidate->AddCandidate(mother);
|
---|
| 173 |
|
---|
| 174 | const TLorentzVector &candidateMomentum = candidate->Momentum;
|
---|
| 175 | eta = candidateMomentum.Eta();
|
---|
| 176 | pt = candidateMomentum.Pt();
|
---|
| 177 | true_id = candidate->PID;
|
---|
| 178 |
|
---|
| 179 | Float_t p = pt * TMath::CosH(eta);
|
---|
| 180 |
|
---|
| 181 | // Obtain the number of sigma separation for a given hypothesis pair for this track
|
---|
| 182 | Bool_t valid = fPIDDetector->valid(eta, p);
|
---|
| 183 |
|
---|
| 184 | Double_t nsigma = -1.0;
|
---|
| 185 |
|
---|
| 186 | if (valid) {
|
---|
| 187 | nsigma = fPIDDetector->numSigma(eta, p, fHypo);
|
---|
| 188 |
|
---|
| 189 | // Assume that Nsigma_Hypo1 = N_sigma_Hypo2, so that Nsigma_HypoX = Nsigma/Sqrt(2).
|
---|
| 190 | nsigma = nsigma/TMath::Sqrt(2.0);
|
---|
| 191 | //std::cout << std::scientific << "EICDetector nsigma = " << nsigma << std::fixed << std::endl;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | int pid_reco = 0;
|
---|
| 197 | int pid_true = TMath::Abs(candidate->PID);
|
---|
| 198 | if (!valid || TMath::IsNaN(nsigma) || !TMath::Finite(nsigma)) {
|
---|
| 199 | pid_reco = 0;
|
---|
| 200 | } else {
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 | // Use accept/reject to assign a PID-detector identity to this track
|
---|
| 204 | Double_t probability = 0.0;
|
---|
| 205 | if (TMath::Abs(true_id) == fPDG1) {
|
---|
| 206 | // We are selecting FOR this hypothesis, so use the core of a Gaussian as the probability
|
---|
| 207 | probability = 1.0 - ROOT::Math::gaussian_pdf(nsigma);
|
---|
| 208 | } else if (TMath::Abs(true_id) == fPDG2) {
|
---|
| 209 | // We are trying to reject these using this detector, so the one-sided tail of the Gaussian probability applies
|
---|
| 210 | probability = 1.0 - ROOT::Math::normal_cdf(nsigma);
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | // std::cout << "True ID = " << true_id << ", |eta| = " << TMath::Abs(eta) << ", p = " << pt*TMath::CosH(eta)
|
---|
| 214 | // <<", nsigma = " << std::scientific << nsigma << ", probability = " << std::fixed
|
---|
| 215 | // << std::scientific << probability << std::fixed << std::endl;
|
---|
| 216 |
|
---|
| 217 | // Create a PID value that is the concatenation of two 16-bit numbers.
|
---|
| 218 | // The lowest 16 bits are the reconstructed PID
|
---|
| 219 | // The highest 16 bits are the truth PID
|
---|
| 220 | // Bitmasking and shifting can be used to get these separately.
|
---|
| 221 | // For example, do the following to get the ... :
|
---|
| 222 | //
|
---|
| 223 | // * True PID: (Track.PID & 0xffff0000) >> 16) (Mask-select the highest 16 bits and shift right by 16 bits.
|
---|
| 224 | // * Reco PID: (Track.PID & 0xffff) (Mask-select the lowest 16 bits)
|
---|
| 225 | if (gRandom->Uniform(0, 1) < probability) {
|
---|
| 226 | candidate = static_cast<Candidate *>(candidate->Clone());
|
---|
| 227 | pid_reco = TMath::Abs(fPDG1);
|
---|
| 228 | pid_true = TMath::Abs(candidate->PID);
|
---|
| 229 | } else {
|
---|
| 230 | pid_reco = TMath::Abs(fPDG2);
|
---|
| 231 | pid_true = TMath::Abs(candidate->PID);
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 | int pid_all = pid_reco + (pid_true << 16);
|
---|
| 235 | candidate->PID = pid_all;
|
---|
| 236 | fOutputArray->Add(candidate);
|
---|
| 237 | }
|
---|
| 238 | }
|
---|