er  dev
ERNDTrackFinder.cxx
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #include "ERNDTrackFinder.h"
10 
11 #include "FairLogger.h"
12 
13 #include "ERBeamDetTrack.h"
14 #include "ERNDDigi.h"
15 
16 ERNDTrackFinder::ERNDTrackFinder()
17  : ERTask("ER ND track finder")
18 {
19  fAvailibleRunManagers.push_back("ERRunAna");
20  fAvailibleRunManagers.push_back("FairRunAna");
21 }
22 
23 InitStatus ERNDTrackFinder::Init() {
24  if (ERTask::Init() != kSUCCESS)
25  return kFATAL;
26  FairRootManager* ioman = FairRootManager::Instance();
27  if ( ! ioman ) Fatal("Init", "No FairRootManager");
28  fNDDigis = (TClonesArray*) ioman->GetObject("NDDigi");
29  if (!fNDDigis) Fatal("Init", "Can`t find collection NDDigi!");
30  fNDTracks = new TClonesArray("ERNDTrack",1000);
31  ioman->Register("NDTrack", "ND track", fNDTracks, kTRUE);
32  fSetup = ERNDSetup::Instance();
33  if (!fUserTargetVertexIsSet) {
34  fBeamDetTrack = (TClonesArray*) ioman->GetObject("BeamDetTrack");
35  if (!fBeamDetTrack) {
36  LOG(DEBUG) << "ERNDTrackFinder: target point not initialized by user "
37  << "(by means of SetTargetVertex()) and there is no ERBeamDetTrack branch"
38  <<FairLogger::endl;
39  return kFATAL;
40  }
41  }
42  fSetup->ReadGeoParamsFromParContainer();
43  return kSUCCESS;
44 }
45 
46 void ERNDTrackFinder::Exec(Option_t* opt) {
47  Reset();
48  if (!fUserTargetVertexIsSet) {
49  ERBeamDetTrack* trackFromMWPC = (ERBeamDetTrack*)fBeamDetTrack->At(0);
50  if (!trackFromMWPC) {
51  //fRun->MarkFill(kFALSE);
52  return ;
53  }
54  fTargetVertex = TVector3(trackFromMWPC->GetTargetX(), trackFromMWPC->GetTargetY(),
55  trackFromMWPC->GetTargetZ());
56  }
57  for (Int_t iDigi(0); iDigi < fNDDigis->GetEntriesFast(); iDigi++) {
58  const auto* digi = static_cast<ERNDDigi*>(fNDDigis->At(iDigi));
59  AddTrack(fSetup->Pos(digi->Channel()), fTargetVertex, digi->Edep(), digi->Time(), digi->TAC());
60  }
61 }
62 
64  fNDTracks->Clear();
65 }
66 
67 void ERNDTrackFinder::SetTargetVertex(const TVector3& vertex) {
68  fTargetVertex = vertex;
69  fUserTargetVertexIsSet = true;
70 }
71 
72 ERNDTrack* ERNDTrackFinder::AddTrack(const TVector3& detectorVertex,
73  const TVector3& targetVertex,
74  float edep, float time, float tac) {
75  return new((*fNDTracks)[fNDTracks->GetEntriesFast()])
76  ERNDTrack(detectorVertex, targetVertex, edep, time, tac);
77 }
virtual InitStatus Init()
virtual InitStatus Init()
Definition: ERTask.cxx:31
virtual void Reset()
Base abstract class for all tasks in er.
Definition: ERTask.h:27