FairRoot/PandaRoot
PndLmdDigiProducer.cxx
Go to the documentation of this file.
1 /*
2  * PndLmdDigiProducer.cxx
3  *
4  * Created on: Aug 10, 2009
5  * Author: huagen
6  */
7 
8 //the implementation of digiproducer
9 
10 #include "PndLmdDigiProducer.h"
11 #include "PndLmdDigiPara.h"
12 #include "PndLmdDigiStrips.h"
13 #include "PndLmdMCPoint.h"
14 #include "PndLmdCalStrip.h"
15 #include "PndLmdStrips.h"
16 #include "PndLmdGeoHandling.h"
17 
18 #include "TGeoManager.h"
19 #include "FairRun.h"
20 #include "FairRuntimeDb.h"
21 #include "FairGeoNode.h"
22 #include "FairGeoVector.h"
23 #include "PndStringVector.h"
24 #include "FairParamList.h"
25 #include "FairRootManager.h"
26 
27 #include "TClonesArray.h"
28 #include "TVector3.h"
29 
30 #include <iostream>
31 #include <vector>
32 using namespace std;
33 
34 
35 PndLmdDigiProducer::PndLmdDigiProducer() : FairTask("Pnd LMD Digi Producer")
36 {
37  fBranchName = "PndLmdMCPoint";
38 }
39 
40 PndLmdDigiProducer::PndLmdDigiProducer(Int_t k,SensorSegment segment)
41  :FairTask("Pnd LMD Digi Producer")
42 {
43  fBranchName = "PndLmdMCPoint";
44 // fDigiParTrap = digipar;
45  fSegment = segment;
46  }
47 
49  :FairTask("Pnd LMD Digi Producer")
50  {
51  fBranchName = "PndLmdMCPoint";
52  // fDigiParTrap = digipar;
53  fSide = side;
54  }
55 
56 
58 {
59  delete fGeoH;
60  }
61 
63 {
64  FairRun* ana = FairRun::Instance();
65  FairRuntimeDb* rtdb = ana->GetRuntimeDb();
66  fDigiParTrap = (PndLmdDigiPara*)(rtdb->getContainer("LmdStripDigiParaTrap"));
67  //if(!fDigiParTrap) cout<<"The digi parameters has been set to container!"<<endl;
68  //fDigiParTrap->print();
69  }
70 
71 
73 {
75  return kSUCCESS;
76 }
77 
78 //init method for the digiproducer, input/output array, digipar file etc.
80 {
81  FairRun* ana = FairRun::Instance();
82  FairRootManager* ioman = FairRootManager::Instance();
83 
84  fGeoH = new PndLmdGeoHandling(gGeoManager);
85 
86  if(! ioman)
87  {
88  std::cout<<"-E- PndLmdDigiProducer::Init :"
89  <<" The FariRootManager is not initialized!"<<std::endl;
90  return kFATAL;
91  }
92 
93  //input array initialization
94  fPointArray = (TClonesArray*)ioman->GetObject(fBranchName);
95  if(! fPointArray)
96  {
97  std::cout<<"-E- PndLmdDigiProducer::Init :"
98  <<"No PndLmdMCPoint Array"<<std::endl;
99  return kERROR;
100  }
101 
102  //creat and register output array
103  fStripArray = new TClonesArray("PndLmdDigiStrips");
104  ioman->Register("LMDStripDigis","LMD",fStripArray,kTRUE);
105 
106  if(! fDigiParTrap)
107  {
108  std::cout<<"-E- PndLmdDigiProducer::DigiParTrap Container doesn't exist!"<<std::endl;
109  return kERROR;
110  }
111 //print the digipar parameters for check
112  fDigiParTrap->print();
113 
115  cout<<"the digi paras for left segment!"<<endl;
117 
119  cout<<"the digi paras for right segment!"<<endl;
121 
122  std::cout<<"the PndLmdDigiProcuder initialized successfully!"<<std::endl;
123 
124  return kSUCCESS;
125 }
126 
128 {
129  //reset the output array
130  fStripArray->Clear();
131 
132  //define variables
133  PndLmdMCPoint* point = NULL;
134 
135  Int_t nPoint = fPointArray->GetEntriesFast();
136  if(fVerbose>0){
137  std::cout<<"the Nr of points is"<<nPoints<<std::endl;
138  }
139 
140  //loop all points in an event
141  Int_t iStrip = 0;
142  for(Int_t iPoint = 0;iPoint<nPoints;iPoint++)
143  {
144  point = (PndLmdMCPoint*)fPointArray->At(iPoint);
145  if(! point){
146  std::cout<<"No point !"<<std::endl;
147  continue;
148  }
149 
153 
154  //transform the point from global coordinate to local coordinate
155  TVector3 posInL = fGeoH->MasterToLocalId(point->GetEntryPoint(),point->GetDetName());
156  TVector3 posOutL = fGeoH->MasterToLocalId(point->GetExitPoint(),point->GetDetName());
157  //std::cout<<"the point in global coordinate is "<<point->GetEntryPoint().X()<<","<<point->GetEntryPoint().Y()
158  //<<","<<point->GetEntryPoint().Z()<<std::endl;
159  std::cout<<"the Entry point in local coordinate is "<<posInL.X()<<","<<posInL.Y()<<","<<posInL.Z()<<std::endl;
160  std::cout<<"the Exit point in local coordinate is "<<posOutL.X()<<","<<posOutL.Y()<<","<<posOutL.Z()<<std::endl;
161 
162  Double_t eLoss = point->GetEnergyLoss();
163  std::cout<<"the eLoss of this point is: "<<eLoss<<endl;
164 
165  TVector3 pos,pos1 = posInL + posOutL;
166  pos.SetXYZ(pos1.X()/2.,pos1.Y()/2.,pos1.Z()/2.);
167  //for Left segment
168  if(pos.X()>0)
169  {
170  // std::cout<<"Hits on Left segment"<<std::endl;
171 
172  //calculate the cluster strips fired
173  std::vector<PndLmdStrips> leftStrips =
174  fCurrentStripCalLeft->DigiStripFromPoint(posInL.X(),posInL.Y(),posInL.Z(),
175  posOutL.X(),posOutL.Y(),posOutL.Z(),
176  eLoss);
177  if(leftStrips.size()!=0){
178  for(std::vector<PndLmdStrips>::const_iterator kit=leftStrips.begin();kit!=leftStrips.end();++kit)
179  {//register the strips fired
180  AddDigi(iStrip,iPoint,kLMDHitsStrip,point->GetDetName(),
181  fCurrentStripCalLeft->CalFeFromStrip(kit->GetIndex()),
182  fCurrentStripCalLeft->CalChannelFromStrip(kit->GetIndex()),
183  kit->GetCharge());
184  Int_t chan1 = (fCurrentStripCalLeft->CalFeFromStrip(kit->GetIndex()))*(fCurrentDigiPar->GetNrFeChannels())
185  +( fCurrentStripCalLeft->CalChannelFromStrip(kit->GetIndex()));
186 
187  cout<<"the iPoint is: "<<iPoint<<endl;
188  cout<<"the iStrip is :"<<iStrip-1<<endl;
189  cout<<"the channel is :"<<chan1<<endl;
190  cout<<"the information of digis: "<<point->GetDetName()<<","<<kit->GetCharge()<<endl;
191  cout<<endl;
192 
193  }
194  }else std::cout<<"the left segment is empty"<<std::endl;
195 
196  }else{// std::cout<<"Hits on Right segment"<<std::endl;
197  std::vector<PndLmdStrips> rightStrips =
198  fCurrentStripCalRight->DigiStripFromPoint(posInL.X(),posInL.Y(),posInL.Z(),
199  posOutL.X(),posOutL.Y(),posOutL.Z(),
200  eLoss);
201  // cout<<"Call the calStrip class to get digi successfully"<<endl;
202 
203  if(rightStrips.size()!=0){
204  for(std::vector<PndLmdStrips>::const_iterator kit=rightStrips.begin();
205  kit!=rightStrips.end();++kit){
206  //register the strips fired
207  AddDigi(iStrip,iPoint,kLMDHitsStrip,point->GetDetName(),
209  fCurrentStripCalRight->CalChannelFromStrip(kit->GetIndex()),
210  kit->GetCharge());
212  +(fCurrentStripCalLeft->CalChannelFromStrip(kit->GetIndex()));
213 
214 /*
215  new((*fStripArray)[iStrip]) PndLmdDigiStrips(iPoint,kLMDHitsStrip,point->GetDetName(),
216  fCurrentStripCalRight->CalFeFromStrip(kit->GetIndex())+fCurrentDigiPar->GetNrLeftFe(),
217  fCurrentStripCalRight->CalChannelFromStrip(kit->GetIndex()),
218  kit->GetCharge());
219  iStrip++;
220 */
221  // cout<<endl;
222  cout<<"the iPoint is: "<<iPoint<<endl;
223  cout<<"the iStrip is :"<<iStrip-1<<endl;
224  cout<<"the channel is :"<<chan2<<endl;
225  cout<<"the information of digis: "<<point->GetDetName()<<","<<kit->GetCharge()<<endl;
226  cout<<endl;
227 
228  }
229  }else std::cout<<"the right segment is empty"<<std::endl;
230 
231  }//judge the hits on left segment or right segment, then calculate strips
232 
233  }//loop all points for one event
234 
235  // if(fVerbose>0)
236  std::cout<<"-I- PndLmdDigiProducer: "<<nPoints<<" PndLmdMCPoint, "
237  <<iStrip<<" PndLmdDigis"<<std::endl<<std::endl;
238 
239 }//public method for Exec
240 
241 void PndLmdDigiProducer::AddDigi(Int_t &iStrip,Int_t iPoint,Int_t detID,TString detName,
242  Int_t fe, Int_t channel,Double_t charge)
243 {
244  Bool_t found = kFALSE;
245  PndLmdDigiStrips* aDigi= 0;
246  for(Int_t skr=0;skr<iStrip && found==kFALSE;skr++){
247  aDigi = (PndLmdDigiStrips*)fStripArray->At(skr);
248  if(aDigi->GetDetID()==detID,
249  aDigi->GetDetName()==detName,
250  aDigi->GetFe()==fe,
251  aDigi->GetChannel()==channel)
252  {
253  // aDigi->AddCharge(charge);
254  // aDigi->AddIndex(iPoint);
255  found=kTRUE;
256  }
257  }
258 
259  if(found == kFALSE){
260  new((*fStripArray)[iStrip]) PndLmdDigiStrips(iPoint,detID,detName,fe,channel,charge);
261  iStrip++;
262  }
263 }
264 
265 
266 
268 
269 
270 
271 
272 
273 
274 
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285 
TVector3 pos
virtual void Exec(Option_t *opt)
PndLmdCalStrip * fCurrentStripCalLeft
int fVerbose
Definition: poormantracks.C:24
PndLmdDigiPara * fCurrentDigiPar
Int_t GetChannel() const
std::vector< PndLmdStrips > DigiStripFromPoint(Double_t inx, Double_t iny, Double_t inz, Double_t outx, Double_t outy, Double_t outz, Double_t eloss)
TClonesArray * fPointArray
virtual InitStatus Init()
PndLmdGeoHandling * fGeoH
TGeoManager * gGeoManager
Int_t GetDetID() const
SensorSegment fSegment
TString GetDetName() const
void AddDigi(Int_t &iStrip, Int_t iPoint, Int_t detID, TString detName, Int_t fe, Int_t channel, Double_t charge)
Int_t GetFe() const
Double_t
PndLmdCalStrip * fCurrentStripCalRight
Int_t CalFeFromStrip(Int_t stripNr)
PndLmdDigiPara * fDigiParTrap
SensorSide
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
PndLmdCalStrip * fStripCalTrapLeft
virtual void SetParContainers()
Int_t GetNrFeChannels() const
Int_t CalChannelFromStrip(Int_t stripNr)
int fe
Definition: anaLmdDigi.C:67
void print() const
ClassImp(PndAnaContFact)
Int_t GetNrLeftFe() const
TClonesArray * fStripArray
PndLmdCalStrip * fStripCalTrapRight
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72
virtual InitStatus ReInit()