er  dev
ERmuSiHitProducer.cxx
1 #include "ERmuSiHitProducer.h"
2 
3 #include <vector>
4 
5 #include "TVector3.h"
6 #include "TGeoMatrix.h"
7 
8 #include "FairRootManager.h"
9 #include "FairRunAna.h"
10 #include "FairRuntimeDb.h"
11 #include<iostream>
12 
13 #include "ERDetectorList.h"
14 #include "ERmuSiPoint.h"
15 
16 Int_t ERmuSiHitProducer::fEvent = 0;
17 // ----------------------------------------------------------------------------
19  : FairTask("ER muSi hit producing scheme")
20 ,fmuSiPoints(NULL)
21 ,fmuSiHits(NULL)
22 {
23 }
24 // ----------------------------------------------------------------------------
25 
26 // ----------------------------------------------------------------------------
28  : FairTask("ER muSi hit producing scheme ", verbose)
29 ,fmuSiPoints(NULL)
30 ,fmuSiHits(NULL)
31 {
32 }
33 // ----------------------------------------------------------------------------
34 
35 // ----------------------------------------------------------------------------
37 {
38 }
39 // ----------------------------------------------------------------------------
40 
41 // ----------------------------------------------------------------------------
42 void ERmuSiHitProducer::SetParContainers()
43 {
44  // Get run and runtime database
45  FairRunAna* run = FairRunAna::Instance();
46  if ( ! run ) Fatal("SetParContainers", "No analysis run");
47 
48  FairRuntimeDb* rtdb = run->GetRuntimeDb();
49  if ( ! rtdb ) Fatal("SetParContainers", "No runtime database");
50 }
51 // ----------------------------------------------------------------------------
52 
53 // ----------------------------------------------------------------------------
55 {
56  // Get input array
57  FairRootManager* ioman = FairRootManager::Instance();
58  if ( ! ioman ) Fatal("Init", "No FairRootManager");
59 
60  fmuSiPoints = (TClonesArray*) ioman->GetObject("muSiPoint");
61  //todo check
62 
63  // Register output array fmuSiHits
64  fmuSiHits = new TClonesArray("ERmuSiHit",1000);
65 
66  ioman->Register("muSiHit", "muSi hits", fmuSiHits, kTRUE);
67 
68  return kSUCCESS;
69 }
70 // -------------------------------------------------------------------------
71 
72 // ----- Public method Exec --------------------------------------------
73 void ERmuSiHitProducer::Exec(Option_t* opt)
74 {
75  std::cout << std::endl;
76  std::cout << "####### EVENT " << fEvent++ << " #####" << std::endl;
77  std::cout << std::endl;
78  std::cout << "ERmuSiHitProducer: "<< std::endl;
79  Reset();
80  //Расскидываем поинты по станциям
81  std::vector<ERmuSiPoint*> PointsByStation[3];
82  for (Int_t iPoint = 0; iPoint < fmuSiPoints->GetEntriesFast(); iPoint++){
83  ERmuSiPoint* point = (ERmuSiPoint*) fmuSiPoints->At(iPoint);
84  PointsByStation[point->Station()].push_back(point);
85  }
86  //Комбинаторно на каждой станции генерируем хиты
87  TVector3 dpos = TVector3(0.01, 0.01, 0.01); //ошибка пока фиксирована
88  TVector3 *pos;
89  for (Int_t iStation =0; iStation < 3; iStation++){
90  for (std::vector<ERmuSiPoint*>::iterator it1 = PointsByStation[iStation].begin(); it1 != PointsByStation[iStation].end(); ++ it1){
91  ERmuSiPoint* point1 = (*it1);
92 
93  pos = new TVector3((point1->GetXIn()+point1->GetXOut())/2.,
94  (point1->GetYIn()+point1->GetYOut())/2.,
95  (point1->GetZIn()+point1->GetZOut())/2.);
96  ERmuSiHit* hit = AddHit(kMUSI, *pos, dpos,point1->Index(), point1->Station());
97  delete pos;
98 
99  for (std::vector<ERmuSiPoint*>::iterator it2 = PointsByStation[iStation].begin(); it2 != PointsByStation[iStation].end(); ++ it2){
100  if (it1 == it2){
101  continue;
102  }
103  ERmuSiPoint* point2 = (*it2);
104 
105  if (iStation == 1){
106  Double_t masterPos[3], localPos[3];
107  masterPos[0] = (point1->GetXIn()+point1->GetXOut())/2.;
108  masterPos[1] = (point2->GetYIn()+point2->GetYOut())/2.;
109  masterPos[2] = (point1->GetZIn()+point1->GetZOut())/2.;
110 
111  TGeoRotation *Rotation = new TGeoRotation();
112  Rotation->RotateX(0.);
113  Rotation->RotateY(0.);
114  Rotation->RotateZ(30.);
115  Rotation->MasterToLocal(masterPos, localPos);
116 
117  pos = new TVector3(localPos[0],localPos[1],localPos[2]);
118  }
119  else{
120  pos = new TVector3((point1->GetXIn()+point1->GetXOut())/2.,
121  (point2->GetYIn()+point2->GetYOut())/2.,
122  (point1->GetZIn()+point1->GetZOut())/2.);
123  }
124 
125  hit = AddHit(kMUSI, *pos, dpos,-1,point1->Station());
126  delete pos;
127  }
128  }
129  }
130  std::cout << "Hits count: " << fmuSiHits->GetEntriesFast() << std::endl;
131 }
132 //----------------------------------------------------------------------------
133 
134 //----------------------------------------------------------------------------
136 {
137  if (fmuSiHits) {
138  fmuSiHits->Delete();
139  }
140 }
141 // ----------------------------------------------------------------------------
142 
143 // ----------------------------------------------------------------------------
145 {
146 
147 }
148 // ----------------------------------------------------------------------------
149 
150 // ----------------------------------------------------------------------------
151 ERmuSiHit* ERmuSiHitProducer::AddHit(Int_t detID, TVector3& pos, TVector3& dpos, Int_t index, Int_t station)
152 {
153  ERmuSiHit *hit = new((*fmuSiHits)[fmuSiHits->GetEntriesFast()])
154  ERmuSiHit(fmuSiHits->GetEntriesFast(),detID, pos, dpos, index, station);
155  return hit;
156 }
157 // ----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
159 ClassImp(ERmuSiHitProducer)
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
TClonesArray * fmuSiPoints