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