Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DCustomAction_dirc_tree.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DCustomAction_dirc_tree.cc
4 //
5 
7 
8 
9 void DCustomAction_dirc_tree::Initialize(JEventLoop* locEventLoop)
10 {
11  DIRC_TRUTH_BARHIT = false;
12  if(gPARMS->Exists("DIRC:TRUTH_BARHIT"))
13  gPARMS->GetParameter("DIRC:TRUTH_BARHIT",DIRC_TRUTH_BARHIT);
14 
15  // get PID algos
16  const DParticleID* locParticleID = NULL;
17  locEventLoop->GetSingle(locParticleID);
18  dParticleID = locParticleID;
19 
20  locEventLoop->GetSingle(dDIRCLut);
21  locEventLoop->GetSingle(dAnalysisUtilities);
22 
23  // get DIRC geometry
24  vector<const DDIRCGeometry*> locDIRCGeometry;
25  locEventLoop->Get(locDIRCGeometry);
26  dDIRCGeometry = locDIRCGeometry[0];
27 
28  // set PID for different passes in debuging histograms
29  dFinalStatePIDs.push_back(Positron);
30  dFinalStatePIDs.push_back(PiPlus);
31  dFinalStatePIDs.push_back(KPlus);
32  dFinalStatePIDs.push_back(Proton);
33 
34  japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
35 
36  string locOutputFileName = "hd_root.root";
37  if(gPARMS->Exists("OUTPUT_FILENAME"))
38  gPARMS->GetParameter("OUTPUT_FILENAME", locOutputFileName);
39 
40  //go to file
41  TFile* locFile = (TFile*)gROOT->FindObject(locOutputFileName.c_str());
42  if(locFile != NULL)
43  locFile->cd("");
44  else
45  gDirectory->Cd("/");
46 
47  TObject* locTree = gDirectory->Get("dirc");
48  if(locTree == NULL)
49  fTree = new TTree("dirc", "dirc tree");
50  else
51  fTree = static_cast<TTree*>(locTree);
52 
53  fcEvent = new TClonesArray("DrcEvent");
54  fTree->Branch("DrcEvent",&fcEvent,256000,2);
55 
56  japp->RootUnLock(); //RELEASE ROOT LOCK!!
57 
58 }
59 
60 bool DCustomAction_dirc_tree::Perform_Action(JEventLoop* locEventLoop, const DParticleCombo* locParticleCombo)
61 {
62 
63  const DDetectorMatches* locDetectorMatches = NULL;
64  locEventLoop->GetSingle(locDetectorMatches);
65  DDetectorMatches locDetectorMatch = (DDetectorMatches)locDetectorMatches[0];
66 
67  // truth information on tracks hitting DIRC bar (for comparison)
68  vector<const DDIRCTruthBarHit*> locDIRCBarHits;
69  locEventLoop->Get(locDIRCBarHits);
70 
71  vector<const DDIRCPmtHit*> locDIRCPmtHits;
72  locEventLoop->Get(locDIRCPmtHits);
73 
74  // Get selected particle from reaction for DIRC analysis
75  const DParticleComboStep* locParticleComboStep = locParticleCombo->Get_ParticleComboStep(dParticleComboStepIndex);
76 
77  TClonesArray& cevt = *fcEvent;
78  cevt.Clear();
79 
80  for(unsigned int parti=0; parti<locParticleComboStep->Get_NumFinalParticles(); parti++){
81 
82  auto locParticle = Get_UseKinFitResultsFlag() ? locParticleComboStep->Get_FinalParticle(parti) : locParticleComboStep->Get_FinalParticle_Measured(parti);
83 
84  // Get track
85  const DChargedTrack* locChargedTrack = static_cast<const DChargedTrack*>(locParticleComboStep->Get_FinalParticle_SourceObject(parti));
86  const DChargedTrackHypothesis* locChargedTrackHypothesis = locChargedTrack->Get_Hypothesis(locParticle->PID());
87  const DTrackTimeBased* locTrackTimeBased = locChargedTrackHypothesis->Get_TrackTimeBased();
88 
89  // require well reconstructed tracks for initial studies
90  int locDCHits = locTrackTimeBased->Ndof + 5;
91  double locTheta = locTrackTimeBased->momentum().Theta()*180/TMath::Pi();
92  double locP = locParticle->lorentzMomentum().Vect().Mag();
93 
94  if(locDCHits < 15 || locTheta < 1.0 || locTheta > 12.0 || locP > 12.0)
95  continue;
96 
97  // require has good match to TOF hit for cleaner sample
98  shared_ptr<const DTOFHitMatchParams> locTOFHitMatchParams;
99  bool foundTOF = dParticleID->Get_BestTOFMatchParams(locTrackTimeBased, locDetectorMatches, locTOFHitMatchParams);
100  if(!foundTOF || locTOFHitMatchParams->dDeltaXToHit > 10.0 || locTOFHitMatchParams->dDeltaYToHit > 10.0)
101  continue;
102 
103  Particle_t locPID = locTrackTimeBased->PID();
104 
105  // get DIRC match parameters (contains LUT information)
106  shared_ptr<const DDIRCMatchParams> locDIRCMatchParams;
107  bool foundDIRC = dParticleID->Get_DIRCMatchParams(locTrackTimeBased, locDetectorMatches, locDIRCMatchParams);
108 
109  if(foundDIRC){
110 
111  DVector3 posInBar = locDIRCMatchParams->dExtrapolatedPos;
112  DVector3 momInBar = locDIRCMatchParams->dExtrapolatedMom;
113  double locExtrapolatedTime = locDIRCMatchParams->dExtrapolatedTime;
114  int locBar = dDIRCGeometry->GetBar(posInBar.Y());
115 
116  fEvent = new DrcEvent();
117  fEvent->SetType(0);
118  fEvent->SetMomentum(TVector3(momInBar.X(),momInBar.Y(),momInBar.Z()));
119  fEvent->SetPdg(PDGtype(locPID));
120  fEvent->SetTime(locExtrapolatedTime);
121  fEvent->SetParent(0);
122  fEvent->SetId(locBar);// bar id where the particle hit the detector
123  fEvent->SetPosition(TVector3(posInBar.X(), posInBar.Y(), posInBar.Z()));
124  DrcHit hit;
125 
126  for(const auto dhit : locDIRCPmtHits){
127  int ch=dhit->ch;
128  int pmt=ch/64;
129  int pix=ch%64;
130 
131  hit.SetChannel(ch);
132  hit.SetPmtId(pmt);
133  hit.SetPixelId(pix);
134  hit.SetLeadTime(dhit->t);
135  hit.SetTotTime(dhit->tot);
136  fEvent->AddHit(hit);
137  }
138 
139  if(fEvent->GetHitSize()>0) new (cevt[ cevt.GetEntriesFast()]) DrcEvent(*fEvent);
140  }
141  }
142 
143  japp->RootWriteLock();
144  if(cevt.GetEntriesFast()>0) fTree->Fill();
145  japp->RootUnLock();
146 
147  return true;
148 }
void SetTime(Double_t val)
void SetPixelId(Int_t val)
const DKinematicData * Get_FinalParticle_Measured(size_t locFinalParticleIndex) const
TVector3 DVector3
Definition: DVector3.h:14
void SetId(Int_t val)
void SetLeadTime(Double_t val)
const DTrackTimeBased * Get_TrackTimeBased(void) const
void SetType(Int_t val)
bool Get_DIRCMatchParams(const DTrackingData *locTrack, const DDetectorMatches *locDetectorMatches, shared_ptr< const DDIRCMatchParams > &locBestMatchParams) const
const DParticleID * dParticleID
static int PDGtype(Particle_t p)
void SetPmtId(Int_t val)
const DChargedTrackHypothesis * Get_Hypothesis(Particle_t locPID) const
Definition: DChargedTrack.h:59
void AddHit(DrcHit hit)
bool Get_UseKinFitResultsFlag(void) const
JApplication * japp
void SetParent(Int_t val)
bool Get_BestTOFMatchParams(const DTrackingData *locTrack, const DDetectorMatches *locDetectorMatches, shared_ptr< const DTOFHitMatchParams > &locBestMatchParams) const
const DAnalysisUtilities * dAnalysisUtilities
void SetMomentum(TVector3 val)
size_t Get_NumFinalParticles(void) const
deque< Particle_t > dFinalStatePIDs
void SetChannel(Int_t val)
int Ndof
Number of degrees of freedom in the fit.
const JObject * Get_FinalParticle_SourceObject(size_t locFinalParticleIndex) const
const DDIRCGeometry * dDIRCGeometry
void Initialize(JEventLoop *locEventLoop)
const DVector3 & momentum(void) const
void SetPosition(TVector3 val)
void SetTotTime(Double_t val)
void SetPdg(Int_t val)
const DParticleComboStep * Get_ParticleComboStep(size_t locStepIndex) const
bool Perform_Action(JEventLoop *locEventLoop, const DParticleCombo *locParticleCombo)
const DKinematicData * Get_FinalParticle(size_t locFinalParticleIndex) const
Int_t GetHitSize() const
Particle_t PID(void) const
int GetBar(float y) const
Particle_t
Definition: particleType.h:12