FairRoot/PandaRoot
PndTrkSttHitList.cxx
Go to the documentation of this file.
1 //
2 // PndTrkSttHitList.cxx
3 //
4 //
5 // authors: Lia Lavezzi - INFN Pavia (2012)
6 //
7 
8 #include "PndTrkSttHitList.h"
9 
10 #include "PndDetectorList.h"
11 #include "PndTrkParameters.h"
12 #include "PndSttTube.h"
13 
14 #include "TClonesArray.h"
15 
16 #include <iostream>
17 
18 
19 using namespace std;
20 
21 // ------------------ instance ----------------------------------
23 
25 {
26  if(!fInstance) cout << "NO PndTrkSttHitList: you must fill it BEFORE doing what you are doing!" << endl;
27  return fInstance;
28 }
29 
31  if(fInstance) cout << "you are instanciating a PndTrkSttHitList, but you already did it, what are you doing?" << endl;
32  fInstance = this;
33  return fInstance;
34 }
35 
37  hitmap.clear();
38  hitmap2.clear();
39  hitmap3.clear();
40 }
41 
42 PndTrkSttHitList::PndTrkSttHitList(TClonesArray *tubearray) : PndTrkHitList(), fTubeArray(tubearray) {
43  hitmap.clear();
44  hitmap2.clear();
45  hitmap3.clear();
46 }
47 
49 fInstance = 0;
50 }
51 
52 // void PndTrkSttHitList::AddHit(Int_t hitid, Int_t detid, PndSttHit *hit) {
53 void PndTrkSttHitList::AddHit(Int_t hitid, Int_t detid, FairHit *hit) {
54  TVector3 position;
55 // hit->Position(position);
56 
57  int tubeID = ((PndSttHit*) hit)->GetTubeID();
58  PndSttTube *tube = (PndSttTube* ) fTubeArray->At(tubeID);
59  Int_t iregion = -1;
60  position = tube->GetPosition();
61  // parallel
62  if(tube->GetWireDirection() == TVector3(0., 0., 1.)) {
63  // x < 0
64  if(tube->GetPosition().X() < 0) {
65  if(tube->GetPosition().Perp() < SKEWLIMIT) iregion = INNER_LEFT; // 3
66  else iregion = OUTER_LEFT; // 7
67  }
68  // x > 0
69  else {
70  if(tube->GetPosition().Perp() < SKEWLIMIT) iregion = INNER_RIGHT; // 2
71  else iregion = OUTER_RIGHT; // 6
72  }
73  }
74  // skewed tubes
75  else {
76  // x < 0
77  if(tube->GetPosition().X() < 0) iregion = SKEW_LEFT; // 5
78  // x > 0
79  else iregion = SKEW_RIGHT; // 4
80 
81  // cout << "tubeID " << tubeID << " " << iregion << endl;
82  // position.Print();
83  // tube->GetWireDirection().Print();
84  }
85 
86  PndTrkHitList::AddHit(hitid, detid, 0, iregion, tubeID, position, ((PndSttHit *) hit)->GetIsochrone()); // CHECK iregion
87 
88 
89  std::map< int , int > ::iterator it;
90  int isec = tube->GetSectorID();
91  hitmap.insert( std::pair<int , int > (isec, hitlist.size() - 1));
92  int ilay = tube->GetLayerID();
93  hitmap2.insert( std::pair<int , int > (ilay, hitlist.size() - 1));
94 // cout << "ISEC " << isec << " ILAY " << ilay << endl;
95  int iglo = FromSecLayToGlo(isec, ilay);
96  hitmap3.insert( std::pair<int , int > (iglo, hitlist.size() - 1)); // CHECK
97 
98 
99 
100 }
101 
104 
105  std::map< int , int > ::iterator it;
106  int tubeID = hit->GetTubeID();
107  PndSttTube *tube = (PndSttTube* ) fTubeArray->At(tubeID);
108  int isec = tube->GetSectorID();
109  hitmap.insert( std::pair<int , int > (isec, hitlist.size() - 1));
110  int ilay = tube->GetLayerID();
111  hitmap2.insert( std::pair<int , int > (ilay, hitlist.size() - 1));
112  // cout << "ISEC " << isec << " ILAY " << ilay << endl;
113  int iglo = FromSecLayToGlo(isec, ilay);
114  hitmap3.insert( std::pair<int , int > (iglo, hitlist.size() - 1)); // CHECK
115 
116 
117 
118 }
119 
120 
121 
122 
123 // ---------------------- LAYERS ----------------------
125 
126  for(int ilay = 0; ilay < 24; ilay++) {
127  cout << "LAYER " << ilay << ": ";
128 
129 
130  std::pair < std::multimap< int, int >::iterator, std::multimap < int, int >::iterator> ret;
131  ret = hitmap2.equal_range(ilay);
132  for (std::multimap< int, int >::iterator it = ret.first; it != ret.second; ++it)
133  std::cout << ' ' << it->second;
134  cout << endl;
135  }
136 }
137 
139  std::vector< PndTrkHit* > listofhits = GetHitListFromLayer(ilay);
140  cout << "Layer " << ilay << ": ";
141  for (size_t ihit = 0; ihit < listofhits.size(); ihit++) cout << " " << (listofhits.at(ihit))->GetHitID();
142  cout << endl;
143 }
144 
145 void PndTrkSttHitList::DrawLayer(int ilay, Color_t color) {
146  std::vector< PndTrkHit* > listofhits = GetHitListFromLayer(ilay);
147 
148  for (size_t ihit = 0; ihit < listofhits.size(); ihit++) (listofhits.at(ihit))->Draw(color);
149 }
150 
152 // cout << "GET NOF HITS IN LAYER" << endl;
153 
154 // std::multimap< int, int >::iterator itr = hitmap2.begin();
155 // while(itr != hitmap2.end() ) {
156 // std::pair < int , int > thispair = *itr;
157 // cout << thispair.first << " " << thispair.second << endl;
158 // itr++;
159 // }
160 
161  std::pair < std::multimap< int, int >::iterator, std::multimap < int, int >::iterator> ret;
162  ret = hitmap2.equal_range(ilay);
163  int counter = 0;
164  for (std::multimap< int, int >::iterator it = ret.first; it != ret.second; ++it) counter++; // CHECK
165  return counter;
166 
167 
168 }
169 
170 std::vector< PndTrkHit* > PndTrkSttHitList::GetHitListFromLayer(int ilay) {
171 
172  std::vector< PndTrkHit* > thislayer;
173 
174  std::pair < std::multimap< int, int >::iterator, std::multimap < int, int >::iterator> ret;
175  ret = hitmap2.equal_range(ilay);
176  for (std::multimap< int, int >::iterator it = ret.first; it != ret.second; ++it) {
177  PndTrkHit *hit = &hitlist[it->second];
178  // cout << "hit " << hit->GetHitID() << endl;
179  thislayer.push_back(hit);
180  }
181  return thislayer;
182 }
183 
185  std::vector< PndTrkHit* > listofhits = GetHitListFromSector(ilay);
186  return listofhits.at(ihit);
187 }
188 
189 
190 // ---------------------- SECTORS -------------------------
192 
193  for(int isec = 0; isec < 6; isec++) {
194  cout << "SECTOR " << isec << ": ";
195 
196 
197  std::pair < std::multimap< int, int >::iterator, std::multimap < int, int >::iterator> ret;
198  ret = hitmap.equal_range(isec);
199  for (std::multimap< int, int >::iterator it = ret.first; it != ret.second; ++it)
200  std::cout << ' ' << it->second;
201  cout << endl;
202  }
203 
204 
205 }
206 
208  std::vector< PndTrkHit* > listofhits = GetHitListFromSector(isec);
209  cout << "Sector " << isec << ": ";
210  for (size_t ihit = 0; ihit < listofhits.size(); ihit++) cout << " " << (listofhits.at(ihit))->GetHitID();
211  cout << endl;
212 }
213 
214 void PndTrkSttHitList::DrawSector(int isec, Color_t color) {
215 
216  std::vector< PndTrkHit* > listofhits = GetHitListFromSector(isec);
217  for (size_t ihit = 0; ihit < listofhits.size(); ihit++) (listofhits.at(ihit))->Draw(color);
218 }
219 
221  std::pair < std::multimap< int, int >::iterator, std::multimap < int, int >::iterator> ret;
222  ret = hitmap.equal_range(isec);
223  int counter = 0;
224  for (std::multimap< int, int >::iterator it = ret.first; it != ret.second; ++it) counter++; // CHECK
225  return counter;
226 
227 
228 }
229 
230 
231 
232 std::vector< PndTrkHit* > PndTrkSttHitList::GetHitListFromSector(int isec) {
233 
234  std::vector< PndTrkHit* > thissector;
235 
236  std::pair < std::multimap< int, int >::iterator, std::multimap < int, int >::iterator> ret;
237  ret = hitmap.equal_range(isec);
238  for (std::multimap< int, int >::iterator it = ret.first; it != ret.second; ++it) {
239  PndTrkHit *hit = &hitlist[it->second];
240  // cout << "hit " << hit->GetHitID() << endl;
241  thissector.push_back(hit);
242  }
243  return thissector;
244 }
245 
247  std::vector< PndTrkHit* > listofhits = GetHitListFromSector(isec);
248  return listofhits.at(ihit);
249 }
250 
251 // ---------------------- GLOBALS -------------------------
252 
254 
255  int nmaxglo = FromSecLayToGlo(6, 25); // CHECK
256  for(int iglo = 0; iglo < nmaxglo; iglo++) {
257  int ilay, isec;
258 
259  FromGloToSecLay(iglo, isec, ilay);
260  cout << "SECTOR " << isec << ", LAYER " << ilay << ": ";
261 
262 
263  std::pair < std::multimap< int, int >::iterator, std::multimap < int, int >::iterator> ret;
264  ret = hitmap3.equal_range(iglo);
265  for (std::multimap< int, int >::iterator it = ret.first; it != ret.second; ++it)
266  std::cout << ' ' << it->second;
267  cout << endl;
268  }
269 
270 
271 }
272 
274  std::vector< PndTrkHit* > listofhits = GetHitListFromSectorAndLayer(isec, ilay);
275  cout << "Sector " << isec << ", Layer " << ilay << ": ";
276 
277  for (size_t ihit = 0; ihit < listofhits.size(); ihit++) cout << " " << (listofhits.at(ihit))->GetHitID();
278  cout << endl;
279 }
280 
281 void PndTrkSttHitList::DrawSectorAndLayer(int isec, int ilay, Color_t color) {
282 
283  std::vector< PndTrkHit* > listofhits = GetHitListFromSectorAndLayer(isec, ilay);
284  for (size_t ihit = 0; ihit < listofhits.size(); ihit++) (listofhits.at(ihit))->Draw(color);
285 }
286 
288  std::pair < std::multimap< int, int >::iterator, std::multimap < int, int >::iterator> ret;
289  int iglo = FromSecLayToGlo(isec, ilay);
290  ret = hitmap3.equal_range(iglo);
291  int counter = 0;
292  for (std::multimap< int, int >::iterator it = ret.first; it != ret.second; ++it) counter++; // CHECK
293  return counter;
294 
295 
296 }
297 
298 
299 
300 std::vector< PndTrkHit* > PndTrkSttHitList::GetHitListFromSectorAndLayer(int isec, int ilay) {
301 
302  std::vector< PndTrkHit* > thissecandlay;
303 
304  std::pair < std::multimap< int, int >::iterator, std::multimap < int, int >::iterator> ret;
305  int iglo = FromSecLayToGlo(isec, ilay);
306  ret = hitmap3.equal_range(iglo);
307  for (std::multimap< int, int >::iterator it = ret.first; it != ret.second; ++it) {
308  PndTrkHit *hit = &hitlist[it->second];
309  // cout << "hit " << hit->GetHitID() << endl;
310  thissecandlay.push_back(hit);
311  }
312  return thissecandlay;
313 }
314 
316  std::vector< PndTrkHit* > listofhits = GetHitListFromSectorAndLayer(isec, ilay);
317  return listofhits.at(ihit);
318 }
319 
320 
322 
323  int nofsectors = 6;
324  return isec + ilay * nofsectors; // CHECK
325 }
326 
327 
328 void PndTrkSttHitList::FromGloToSecLay(int iglo, int &isec, int &ilay) {
329  int nofsectors = 6;
330  ilay = iglo / nofsectors;
331  isec = iglo - ilay * nofsectors;
332 }
333 
334 std::vector< PndTrkHit* > PndTrkSttHitList::GetHitList() {
335 
336  std::vector< PndTrkHit* > thislist;
337 
338  for (size_t ihit = 0; ihit < hitlist.size() ; ihit++) {
339  PndTrkHit *hit = &hitlist[ihit];
340  thislist.push_back(hit);
341  }
342  return thislist;
343 }
344 
346 
#define SKEW_RIGHT
static PndTrkSttHitList * fInstance
void DrawLayer(int ilay, Color_t color)
PndTrkSttHitList * Instanciate()
std::vector< PndTrkHit * > GetHitList()
PndTrkHit * GetHitFromLayer(int ihit, int ilay)
std::multimap< int, int > hitmap2
PndTrkHit * GetHitFromSectorAndLayer(int ihit, int isec, int ilay)
int GetNofHitsInSector(int isec)
PndTrkHit * GetHitFromSector(int ihit, int isec)
void FromGloToSecLay(int iglo, int &isec, int &ilay)
#define INNER_LEFT
std::vector< PndTrkHit > hitlist
Definition: PndTrkHitList.h:59
std::vector< PndTrkHit * > GetHitListFromLayer(int ilay)
#define SKEW_LEFT
std::vector< PndTrkHit * > GetHitListFromSector(int isec)
int GetLayerID()
Definition: PndSttTube.cxx:128
int isec
Definition: f_Init.h:19
std::multimap< int, int > hitmap3
int counter
Definition: ZeeAnalysis.C:59
void Draw(Color_t color=kBlack)
TVector3 GetPosition()
Definition: PndSttTube.cxx:87
void PrintSector(int isec)
#define INNER_RIGHT
int GetNofHitsInLayer(int ilay)
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
void AddHit(Int_t hitID, Int_t detID, Bool_t used, Int_t iregion, TVector3 &pos)
std::multimap< int, int > hitmap
#define SKEWLIMIT
ClassImp(PndAnaContFact)
void PrintSectorAndLayer(int isec, int ilay)
TClonesArray * fTubeArray
static PndTrkSttHitList * Instance()
int GetNofHitsInSectorAndLayer(int isec, int ilay)
void AddHit(Int_t hitid, Int_t detid, FairHit *hit)
void DrawSectorAndLayer(int isec, int ilay, Color_t color=kBlack)
#define OUTER_RIGHT
int GetSectorID()
Definition: PndSttTube.cxx:124
Int_t GetTubeID()
Definition: PndTrkHit.h:61
TVector3 GetWireDirection()
Definition: PndSttTube.cxx:107
std::vector< PndTrkHit * > GetHitListFromSectorAndLayer(int isec, int ilay)
void PrintLayer(int ilay)
Int_t FromSecLayToGlo(int isec, int ilay)
#define OUTER_LEFT
void DrawSector(int isec, Color_t color=kBlack)