FairRoot/PandaRoot
PndFtsSignalOverlap.cxx
Go to the documentation of this file.
1 #include "PndFtsSignalOverlap.h"
2 
3 #include "PndFtsHit.h"
4 #include "PndFtsHitInfo.h"
5 #include "PndFtsPoint.h"
6 #include "PndFtsTube.h"
7 #include "PndFtsMapCreator.h"
8 
9 #include "FairRootManager.h"
10 #include "FairRunAna.h"
11 #include "FairRuntimeDb.h"
12 
13 #include "TClonesArray.h"
14 #include "TVector3.h"
15 #include "TMath.h"
16 #include "TParticlePDG.h"
17 
18 #include <iostream>
19 #include <cmath>
20 #include <vector>
21 #include <iterator>
22 #include <algorithm>
23 
24 using namespace std;
25 
26 
27 // ----- Default constructor -------------------------------------------
29  fVerbose = 0;
30  fOriginalHitArray = NULL;
31 }
32 
33 PndFtsSignalOverlap::PndFtsSignalOverlap(TClonesArray * OriginalHitArray) {
34  fVerbose = 0;
35  fOriginalHitArray = OriginalHitArray;
36 }
37 // -------------------------------------------------------------------------
38 
39 PndFtsSignalOverlap::PndFtsSignalOverlap(Int_t , TClonesArray * OriginalHitArray) { // verbose //[R.K.03/2017] unused variable(s)
40  fVerbose = 0;
41  fOriginalHitArray = OriginalHitArray;
42 }
43 // -------------------------------------------------------------------------
44 
45 
46 // ----- Destructor ----------------------------------------------------
48  delete fOriginalHitArray;
49 }
50 
51 // -------------------------------------------------------------------------
53 
54  if(fOriginalHitArray == NULL) return kFALSE;
55  if(OverlapHitArray == NULL) return kFALSE;
56  fOverlapHitArray = OverlapHitArray;
57  fOverlapHitArray->Clear();
58 
59  // vector of the firing tubes
60  std::vector<int> firingtubes;
61  std::vector<int>::iterator it;
62 
63  // maps tubeID to hitID (the hitID of the chosen signal)
64  std::map<int, int> maptubetohit;
65 
66  Int_t nhits = fOriginalHitArray->GetEntriesFast();
67 
68  for(int ihit = 0; ihit < nhits; ihit++) {
69  PndFtsHit *hit = (PndFtsHit *) fOriginalHitArray->At(ihit);
70  if(!hit) continue;
71 
72  // get which tube it is
73  Int_t tubeid = hit->GetTubeID();
74 
75  // has the tube already fired?
76  it = find(firingtubes.begin(), firingtubes.end(), tubeid);
77 
78  // if not, add it to the firing tubes and map
79  if(it == firingtubes.end()) {
80  firingtubes.push_back(tubeid);
81  maptubetohit[tubeid] = ihit; // CHECK
82  }
83  else {
84  // geet the old hit
85  int oldhitid = maptubetohit[tubeid]; // CHECK
86  PndFtsHit *oldhit = (PndFtsHit *) fOriginalHitArray->At(oldhitid);
87  if(!oldhit) continue;
88  double thisiso = hit->GetIsochrone();
89  double oldiso = oldhit->GetIsochrone();
90 
91  // this this hit comes first, replace it in map
92  if(thisiso < oldiso) {
93  maptubetohit[tubeid] = ihit; // CHECK
94  }
95  // else do nothing
96  }
97  }
98 
99  // copy to output only the hits in the map
100  for(size_t itube = 0; itube < firingtubes.size(); itube++) {
101  int tubeid = firingtubes[itube];
102  int hitid = maptubetohit[tubeid];
103  Bool_t wrote = WriteToOutputHit(hitid);
104  if(wrote == kFALSE) cout << "error in writing hit " << hitid << endl;
105  }
106 
107  return kTRUE;
108 }
109 
111  PndFtsHit *hit = (PndFtsHit *) fOriginalHitArray->At(hitid);
112  if(!hit) return kFALSE;
113  TClonesArray& clref = *fOverlapHitArray;
114  Int_t size = clref.GetEntriesFast();
115  PndFtsHit *hitnew = new(clref[size]) PndFtsHit();
116  *hitnew = *hit;
117  hitnew->SetDetectorID(hit->GetDetectorID());
118 
119 
120  return kTRUE;
121 }
122 
123 
int fVerbose
Definition: poormantracks.C:24
Bool_t OverlapSimultaneousSignals(TClonesArray *OverlapHitArray)
ClassImp(PndFtsSignalOverlap)
Int_t GetTubeID() const
Definition: PndFtsHit.h:70
Double_t GetIsochrone() const
Definition: PndFtsHit.h:57
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
Bool_t WriteToOutputHit(Int_t hitid)