File indexing completed on 2024-06-26 07:06:28
0001
0002
0003
0004
0005 #include "TTree.h"
0006 #include "TFile.h"
0007 #include <TRandom.h>
0008
0009
0010 #include "dd4pod/Geant4ParticleCollection.h"
0011 #include "dd4pod/TrackerHitCollection.h"
0012
0013
0014 #include "CherenkovEvent.h"
0015 #include "CherenkovDetectorCollection.h"
0016
0017
0018 #define _WAVE_LENGTH_CUTOFF_ (350.0)
0019 #define _AVERAGE_PDE_ ( 0.30)
0020
0021 int main(int argc, char** argv)
0022 {
0023 #if _BACK_
0024
0025 if (argc != 3 && argc != 4) {
0026 printf("usage: %s <root-data-file> <root-config-file> [DNAME]\n", argv[0]);
0027 exit(0);
0028 }
0029
0030
0031 auto fdata = new TFile(argv[1]);
0032 TTree *t = dynamic_cast<TTree*>(fdata->Get("events"));
0033
0034
0035 auto fcfg = new TFile(argv[2]);
0036 CherenkovDetector *detector = 0;
0037 auto geometry = dynamic_cast<CherenkovDetectorCollection*>(fcfg->Get("CherenkovDetectorCollection"));
0038
0039 if (argc == 4)
0040 detector = geometry->GetDetector(argv[3]);
0041 else {
0042
0043 auto &detectors = geometry->GetDetectors();
0044 if (detectors.size() != 1) {
0045 printf("More than one detector in the provided IRT geometry config .root file!\n");
0046 exit(0);
0047 }
0048
0049
0050 detector = (*detectors.begin()).second;
0051 }
0052
0053
0054 if (!detector) {
0055 printf("Was not able to find a valid Cherenkov detector in the provided IRT geometry config .root file!\n");
0056 exit(0);
0057 }
0058
0059
0060
0061 auto gas = detector->GetRadiator("GasVolume");
0062 auto aerogel = detector->GetRadiator("Aerogel");
0063
0064
0065
0066 gas ->m_AverageRefractiveIndex = gas ->n();
0067 aerogel->m_AverageRefractiveIndex = aerogel->n();
0068
0069
0070
0071 aerogel->SetUniformSmearing(0.003);
0072
0073 aerogel->SetTrajectoryBinCount(1);
0074
0075
0076
0077
0078 auto event = new CherenkovEvent();
0079
0080
0081
0082 std::vector<dd4pod::Geant4ParticleData> *tracks = new std::vector<dd4pod::Geant4ParticleData>();
0083 std::vector<dd4pod::TrackerHitData> *hits = new std::vector<dd4pod::TrackerHitData>();
0084 t->SetBranchAddress("mcparticles", &tracks);
0085 {
0086 TString hname; hname.Form("%sHits", detector->GetName());
0087 t->SetBranchAddress(hname, &hits);
0088 }
0089
0090
0091 unsigned false_assignment_stat = 0;
0092 for(int ev=0; ev<t->GetEntries(); ev++) {
0093 t->GetEntry(ev);
0094
0095
0096
0097 for(auto track: *tracks) {
0098
0099 if (track.g4Parent) continue;
0100
0101
0102
0103 std::vector<OpticalPhoton*> photons;
0104 for(auto hit: *hits) {
0105
0106 if (hit.g4ID != track.ID) continue;
0107
0108 #ifdef _WAVE_LENGTH_CUTOFF_
0109 {
0110 auto &p = hit.momentum;
0111 double pmag = sqrt(p.x*p.x + p.y*p.y + p.z*p.z);
0112
0113 if (1239.84/(1E9*pmag) < _WAVE_LENGTH_CUTOFF_) continue;
0114 }
0115 #endif
0116 #ifdef _AVERAGE_PDE_
0117 if (gRandom->Uniform(0.0, 1.0) > _AVERAGE_PDE_) continue;
0118 #endif
0119
0120 auto photon = new OpticalPhoton();
0121
0122 {
0123 auto &x = hit.position;
0124 photon->SetDetectionPosition(TVector3(x.x, x.y, x.z));
0125 }
0126
0127
0128 photon->SetPhotonDetector(detector->m_PhotonDetectors[0]);
0129 photon->SetDetected(true);
0130
0131 photon->SetVolumeCopy(hit.cellID & detector->GetReadoutCellMask());
0132
0133 photons.push_back(photon);
0134 }
0135
0136 auto particle = new ChargedParticle(track.pdgID);
0137 event->AddChargedParticle(particle);
0138
0139 aerogel->ResetLocations();
0140 #if 1
0141
0142 particle->StartRadiatorHistory(std::make_pair(aerogel, new RadiatorHistory()));
0143 {
0144
0145
0146 auto &vtx = track.vs, &p = track.ps;
0147 auto x0 = TVector3(vtx.x, vtx.y, vtx.z), p0 = TVector3(p.x, p.y, p.z), n0 = p0.Unit();
0148
0149
0150 TVector3 from, to;
0151 aerogel->GetFrontSide(0)->GetCrossing(x0, n0, &from);
0152 aerogel->GetRearSide (0)->GetCrossing(x0, n0, &to);
0153
0154
0155 TVector3 nn = (to - from).Unit(); from += (0.010)*nn; to -= (0.010)*nn;
0156
0157 for(unsigned isec=0; isec<6; isec++) {
0158 aerogel->AddLocation(isec, from, p0);
0159 aerogel->AddLocation(isec, to, p0);
0160 }
0161 }
0162
0163
0164 {
0165 CherenkovPID pid;
0166
0167
0168 pid.AddMassHypothesis(0.140);
0169 pid.AddMassHypothesis(0.494);
0170
0171 particle->PIDReconstruction(pid, &photons);
0172 {
0173 auto pion = pid.GetHypothesis(0), kaon = pid.GetHypothesis(1);
0174 double wt0 = pion->GetWeight(aerogel), wt1 = kaon->GetWeight(aerogel);
0175
0176 printf("%10.3f (%10.3f) vs %10.3f (%10.3f) ... %3d %d\n",
0177 wt0, pion->GetNpe(aerogel), wt1, kaon->GetNpe(aerogel), particle->GetPDG(), wt0 > wt1);
0178
0179 if (wt0 <= wt1) false_assignment_stat++;
0180 }
0181 }
0182 #endif
0183 }
0184
0185 event->Reset();
0186 }
0187
0188 printf("%d false out of %lld\n", false_assignment_stat, t->GetEntries());
0189
0190
0191
0192 #endif
0193
0194 return 0;
0195 }