File indexing completed on 2025-08-05 08:13:29
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "AnaMvtxTelescopeHits.h"
0010
0011 #include <phool/getClass.h>
0012 #include <phool/phool.h>
0013 #include <phool/PHCompositeNode.h>
0014 #include <phool/PHIODataNode.h>
0015 #include <phool/PHNodeIterator.h>
0016
0017 #include <phgeom/PHGeomUtility.h>
0018
0019 #include <fun4all/Fun4AllServer.h>
0020 #include <fun4all/Fun4AllReturnCodes.h>
0021 #include <fun4all/PHTFileServer.h>
0022
0023 #include <g4main/PHG4TruthInfoContainer.h>
0024 #include <g4main/PHG4Particle.h>
0025 #include <g4main/PHG4Hit.h>
0026 #include <g4main/PHG4HitContainer.h>
0027
0028 #include <g4hough/SvtxCluster.h>
0029 #include <g4hough/SvtxClusterMap.h>
0030 #include <g4hough/SvtxHitMap.h>
0031 #include <g4hough/SvtxTrack.h>
0032 #include <g4hough/SvtxVertex.h>
0033 #include <g4hough/SvtxTrackMap.h>
0034 #include <g4hough/SvtxVertexMap.h>
0035
0036 #include <g4jets/JetMap.h>
0037 #include <g4jets/Jet.h>
0038
0039 #include <g4detectors/PHG4CellContainer.h>
0040 #include <g4detectors/PHG4CylinderGeomContainer.h>
0041 #include <g4detectors/PHG4Cell.h>
0042 #include <g4detectors/PHG4CylinderGeom_MAPS.h>
0043 #include <g4detectors/PHG4CylinderGeom_Siladders.h>
0044
0045 #include <phgenfit/Fitter.h>
0046 #include <phgenfit/PlanarMeasurement.h>
0047 #include <phgenfit/Track.h>
0048 #include <phgenfit/SpacepointMeasurement.h>
0049
0050
0051 #include <GenFit/FieldManager.h>
0052 #include <GenFit/GFRaveConverters.h>
0053 #include <GenFit/GFRaveVertex.h>
0054 #include <GenFit/GFRaveVertexFactory.h>
0055 #include <GenFit/MeasuredStateOnPlane.h>
0056 #include <GenFit/RKTrackRep.h>
0057 #include <GenFit/StateOnPlane.h>
0058 #include <GenFit/Track.h>
0059
0060
0061 #include <rave/Version.h>
0062 #include <rave/Track.h>
0063 #include <rave/VertexFactory.h>
0064 #include <rave/ConstantMagneticField.h>
0065
0066 #include <phhepmc/PHHepMCGenEvent.h>
0067 #include <HepMC/GenEvent.h>
0068 #include <HepMC/GenVertex.h>
0069
0070 #include <HFJetTruthGeneration/HFJetDefs.h>
0071
0072 #include "TTree.h"
0073 #include "TFile.h"
0074 #include "TLorentzVector.h"
0075 #include "TH1.h"
0076 #include "TH2.h"
0077 #include "TVectorD.h"
0078 #include "TMatrixD.h"
0079 #include "TDecompSVD.h"
0080
0081
0082 #include <iostream>
0083 #include <map>
0084 #include <utility>
0085 #include <vector>
0086 #include <memory>
0087
0088
0089
0090 #define LogDebug(exp) std::cout<<"DEBUG: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<"\n"
0091 #define LogError(exp) std::cout<<"ERROR: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<"\n"
0092 #define LogWarning(exp) std::cout<<"WARNING: " <<__FILE__<<": "<<__LINE__<<": "<< exp <<"\n"
0093
0094
0095 AnaMvtxTelescopeHits::AnaMvtxTelescopeHits(const std::string &name,
0096 const std::string &ofName) :
0097 SubsysReco(name),
0098 _clustermap(NULL),
0099 _foutname(ofName),
0100 _f(NULL)
0101 {
0102
0103 hlayer = NULL;
0104 for (int il = 0; il < 4; il++)
0105 {
0106 hsize_phi[il] = NULL;
0107 hsize_z[il] = NULL;
0108 hphiz[il] = NULL;
0109 hdphi[il] = NULL;
0110 hdz[il] = NULL;
0111 }
0112 }
0113
0114 int AnaMvtxTelescopeHits::Init(PHCompositeNode *topNode)
0115 {
0116
0117
0118 _f = new TFile(_foutname.c_str(), "RECREATE");
0119
0120
0121 hlayer = new TH1D("hlayer", ";layer", 6, -0.5, 5.5);
0122
0123 for (int il = 0; il < 4; il++)
0124 {
0125 hsize_phi[il] = new TH1D(Form("hsize_phi_l%i", il),
0126 ";cluster size #phi [cm]",
0127 100, 0, 0.1);
0128
0129 hsize_z[il] = new TH1D(Form("hsize_z_l%i", il),
0130 ";cluster size z [cm]",
0131 100, 0, 0.1);
0132
0133 hphiz[il] = new TH2D(Form("hphiz_l%i", il),
0134 ";z [cm]; #phi",
0135 1000, -10, 10,
0136 100, -0.1, 0.1);
0137
0138 hdphi[il] = new TH1D(Form("hdphi_l%i", il),
0139 "; d#phi [#mum]",
0140 2000, -100, 100);
0141
0142 hdz[il] = new TH1D(Form("hdz_l%i", il),
0143 "; dz [#mum]",
0144 2000, -100, 100);
0145 }
0146
0147
0148
0149 return 0;
0150
0151 }
0152
0153 int AnaMvtxTelescopeHits::InitRun(PHCompositeNode *topNode)
0154 {
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 _ievent = -1;
0169
0170
0171 return 0;
0172
0173 }
0174
0175 int AnaMvtxTelescopeHits::process_event(PHCompositeNode *topNode)
0176 {
0177
0178 if ( verbosity > VERBOSITY_MORE )
0179 std::cout << "AnaMvtxTelescopeHits::process_event()" << std::endl;
0180
0181
0182 _ievent++;
0183
0184
0185
0186
0187 int retval = GetNodes(topNode);
0188 if ( retval != Fun4AllReturnCodes::EVENT_OK )
0189 return retval;
0190
0191 if ( verbosity > VERBOSITY_MORE )
0192 {
0193 std::cout << "-- evnt:" << _ievent << std::endl;
0194 std::cout << "-- Nclus:" << _clustermap->size() << std::endl;
0195 }
0196
0197
0198
0199
0200
0201
0202 if ( verbosity > VERBOSITY_MORE )
0203 std::cout << "-- Looping over clusters" << std::endl;
0204
0205 LyrClusMap _mmap_lyr_clus;
0206
0207 for (SvtxClusterMap::Iter iter = _clustermap->begin();
0208 iter != _clustermap->end();
0209 ++iter)
0210 {
0211 SvtxCluster *clus = iter->second;
0212
0213 hlayer->Fill(clus->get_layer());
0214
0215 unsigned int lyr = clus->get_layer();
0216 if (lyr < 0 || lyr > 3)
0217 continue;
0218 hsize_phi[lyr]->Fill(clus->get_phi_size());
0219 hsize_z[lyr]->Fill(clus->get_z_size());
0220
0221 double phi = TMath::ATan2(clus->get_y(), clus->get_x());
0222 hphiz[lyr]->Fill(clus->get_z(), phi);
0223
0224
0225 _mmap_lyr_clus.insert(std::make_pair(lyr, clus));
0226 }
0227
0228 if ( verbosity > VERBOSITY_MORE )
0229 std::cout << "-- _mmap_lyr_clus.size():" << _mmap_lyr_clus.size() << std::endl;
0230
0231
0232
0233
0234
0235 if ( verbosity > VERBOSITY_MORE )
0236 std::cout << "-- Performing simple tracking" << std::endl;
0237
0238
0239 LyrClusMap::iterator lyr0_itr;
0240 LyrClusMap::iterator lyr_itr;
0241 LyrClusMap::iterator lyr3_itr;
0242 for ( lyr0_itr = _mmap_lyr_clus.lower_bound(0);
0243 lyr0_itr != _mmap_lyr_clus.upper_bound(0);
0244 ++lyr0_itr)
0245 {
0246 SvtxCluster* clus0 = lyr0_itr->second;
0247
0248 if ( !clus0 )
0249 {
0250 std::cout << "WARNING: clus0 not found" << std::endl;
0251 continue;
0252 }
0253
0254
0255 double r0 = TMath::Sqrt(TMath::Power(clus0->get_x(), 2) + TMath::Power(clus0->get_y(), 2));
0256 double p0 = TMath::ATan2(clus0->get_y(), clus0->get_x());
0257 double z0 = clus0->get_z();
0258
0259 if ( verbosity > VERBOSITY_MORE )
0260 {
0261 std::cout << "-- clus0:(" << r0 << ", " << p0 << ", " << z0 << ")" << std::endl;
0262 }
0263
0264
0265 for ( lyr3_itr = _mmap_lyr_clus.lower_bound(3);
0266 lyr3_itr != _mmap_lyr_clus.upper_bound(3);
0267 ++lyr3_itr)
0268 {
0269 SvtxCluster* clus3 = lyr3_itr->second;
0270
0271 if ( !clus3 )
0272 {
0273 std::cout << "WARNING: clus3 not found" << std::endl;
0274 continue;
0275 }
0276
0277
0278 double r3 = TMath::Sqrt(TMath::Power(clus3->get_x(), 2) + TMath::Power(clus3->get_y(), 2));
0279 double p3 = TMath::ATan2(clus3->get_y(), clus3->get_x());
0280 double z3 = clus3->get_z();
0281
0282
0283 double mpr = CalcSlope(r0, p0, r3, p3);
0284 double bpr = CalcIntecept(r0, p0, mpr);
0285
0286
0287 double mzr = CalcSlope(r0, z0, r3, z3);
0288 double bzr = CalcIntecept(r0, z0, mzr);
0289
0290
0291 if ( verbosity > VERBOSITY_MORE )
0292 {
0293 std::cout << "-- clus3:(" << r3 << ", " << p3 << ", " << z3 << ")" << std::endl;
0294 std::cout << "-- mpr:" << mpr << " bpr:" << bpr << std::endl;
0295 std::cout << "-- mzr:" << mzr << " bzr:" << bzr << std::endl;
0296 }
0297
0298
0299
0300
0301 for (int ilyr = 1; ilyr <= 2; ilyr++)
0302 {
0303 for ( lyr_itr = _mmap_lyr_clus.lower_bound(ilyr);
0304 lyr_itr != _mmap_lyr_clus.upper_bound(ilyr);
0305 ++lyr_itr)
0306 {
0307 SvtxCluster* clus = lyr_itr->second;
0308
0309 if ( !clus )
0310 continue;
0311
0312
0313 double r = TMath::Sqrt(TMath::Power(clus->get_x(), 2) + TMath::Power(clus->get_y(), 2));
0314 double phi = TMath::ATan2(clus->get_y(), clus->get_x());
0315 double z = clus->get_z();
0316
0317
0318 double phi_proj = CalcProjection(r, mpr, bpr);
0319 double z_proj = CalcProjection(r, mzr, bzr);
0320
0321
0322 double dphi = (phi_proj - phi) * 1e4;
0323 double dz = (z_proj - z) * 1e4;
0324
0325 if ( !hdphi[ilyr] || !hdz[ilyr] )
0326 {
0327 std::cout << "WARNING!! can't find hdphi or hdz for lyr:" << ilyr << std::endl;
0328 }
0329 else
0330 {
0331 hdphi[ilyr]->Fill(dphi);
0332 hdz[ilyr]->Fill(dz);
0333 }
0334
0335 if ( verbosity > VERBOSITY_MORE )
0336 {
0337 std::cout << "------------------" << std::endl;
0338 std::cout << "-- clus" << clus->get_layer() << ":(" << r3 << ", " << p3 << ", " << z3 << ")" << std::endl;
0339 std::cout << "-- proj:(" << phi_proj << ", " << z_proj << ")" << std::endl;
0340 std::cout << "-- dphi [micron]: " << dphi << std::endl;
0341 std::cout << "-- dz [micron]: " << dz << std::endl;
0342 std::cout << "------------------" << std::endl;
0343 }
0344
0345 }
0346 }
0347
0348 }
0349
0350 }
0351
0352
0353 if ( verbosity > VERBOSITY_MORE )
0354 std::cout << "-- Done simple tracking" << std::endl;
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379 return 0;
0380
0381 }
0382
0383 int AnaMvtxTelescopeHits::End(PHCompositeNode * topNode)
0384 {
0385 _f->Write();
0386 _f->Close();
0387
0388 return 0;
0389 }
0390
0391
0392
0393
0394 int AnaMvtxTelescopeHits::GetNodes(PHCompositeNode * topNode)
0395 {
0396
0397
0398 _clustermap = findNode::getClass<SvtxClusterMap>(topNode, "SvtxClusterMap");
0399 if (!_clustermap && _ievent < 2) {
0400 std::cout << PHWHERE << " SvtxClusterMap node not found on node tree"
0401 << std::endl;
0402 return Fun4AllReturnCodes::ABORTEVENT;
0403 }
0404
0405 return Fun4AllReturnCodes::EVENT_OK;
0406
0407 }
0408
0409
0410
0411
0412 double
0413 AnaMvtxTelescopeHits::CalcSlope(double x0, double y0, double x1, double y1)
0414 {
0415 return (y1 - y0) / (x1 - x0);
0416 }
0417
0418
0419
0420
0421 double
0422 AnaMvtxTelescopeHits::CalcIntecept(double x0, double y0, double m)
0423 {
0424 return y0 - x0 * m;
0425 }
0426
0427
0428
0429
0430 double
0431 AnaMvtxTelescopeHits::CalcProjection(double x, double m, double b)
0432 {
0433 return m * x + b;
0434 }
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589