FairRoot/PandaRoot
PndMvdCreateDefaultApvMap.cxx
Go to the documentation of this file.
1 //-------------------------------------------------------//
2 // Class PndMvdCreateDefaultApvMap //
3 // //
4 // Creates a default Frontend number mapping file //
5 // //
6 // Created 16.02.2010 //
7 // Author: Ralf Kliemt //
8 // ralf.kliemt{at}hiskp.uni-bonn.de //
9 //-------------------------------------------------------//
10 
12 
13 #include <iostream>
14 #include <fstream>
15 
16 #include "FairRun.h"
17 #include "FairRuntimeDb.h"
18 #include "PndMvdContFact.h"
19 #include "TObjString.h"
20 #include "TObjArray.h"
21 #include "TGeoMatrix.h"
22 
24 
25 // Constructor
27  fSortedMapping(),
28  fCurrentDigiPar(NULL),
29  fDigiParameterList(new TList()),
30  fFeCount(0),
31  fFakeCount(0)
32 {
33 }
34 
35 // Destructor
37 {
39 }
40 
41 
42 // Setup
44 {
45  FairRun* ana = FairRun::Instance();
46  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
47  PndMvdContFact* themvdcontfact = (PndMvdContFact*)rtdb->getContFactory("PndMvdContFact");
48  TList* theContNames = themvdcontfact->GetDigiParNames();
49  Info("SetParContainers()","The container names list contains %i entries",theContNames->GetEntries());
50  TIter cfIter(theContNames);
51  while (TObjString* contname = (TObjString*)cfIter()) {
52  TString parsetname = contname->String();
53  if(parsetname.BeginsWith("MVDStripDigiPar")){
54  PndSdsStripDigiPar* digipar = (PndSdsStripDigiPar*)(rtdb->getContainer(parsetname.Data()));
55  fDigiParameterList->Add(digipar);
56  Info("SetParContainers()","Add container %s",parsetname.Data());
57  }
58  }
59 }
60 
62 {
63  // Check for all necessary framework i/o
64  if(!gGeoManager) {
65  Error("Init","Cannot find a valid GeoManager");
66  return kERROR;
67  }
68  return kSUCCESS;
69 }
70 
71 // The main function
73 {
74  Info("CreateFile","Output file name is %s",outFileName.Data());
75  std::ofstream outfile(outFileName.Data(),std::ofstream::out);
76 
77  TString oldpath = gGeoManager->GetPath();
78  gGeoManager->CdTop();
79  if( ! oldpath.BeginsWith(gGeoManager->GetPath()) ) oldpath = gGeoManager->GetPath();
81  gGeoManager->cd(oldpath.Data());
82 
83  // loop over sorted mapping and write to file
84  for(std::map<Double_t, std::vector<Map_Entry> >::iterator
85  iter=fSortedMapping.begin(); iter!=fSortedMapping.end();iter++)
86  {
87  std::vector<Map_Entry> entryset = iter->second;
88  for(std::vector<Map_Entry>::iterator
89  iter2=entryset.begin(); iter2!=entryset.end();iter2++)
90  {
91  Map_Entry anEntry = *iter2;
92  TString detpath = anEntry.first;
93  std::pair<Int_t,Int_t> aPair = anEntry.second;
94  Int_t feSoft = aPair.first;
95  Int_t feHard = aPair.second;
96  outfile << feHard << " " << feSoft << " " << detpath << std::endl;
97  std::cout << feHard << " " << feSoft << " " << detpath << std::endl;
98  }
99  }
100 
101  outfile.close();
102  return kTRUE;
103 }
104 
106 {
107  // this volume should be an assambly
108  TGeoNode* node = gGeoManager->GetCurrentNode();
109  //TGeoVolume* vol = node->GetVolume();
110  if(node->GetNdaughters() > 0)
111  { // iterate to daughters
112  for (Int_t Nod=0; Nod<node->GetNdaughters();Nod++) {
113  gGeoManager->CdDown(Nod);
114  WriteExpandNode();
115  gGeoManager->CdUp();
116  }
117  } else { // no daughter nodes
118  TString detpath=gGeoManager->GetPath();
119  // some checks
120  if(!detpath.Contains("Strip")) return;
121  if(!SelectSensorParams(detpath)) return;
122  // Chosen sorting parameter: z Position of the node.
123  // TODO: Is it done correctly like this?
124  TGeoTranslation* tran = (TGeoTranslation*)node->GetMatrix();
125  Double_t sortparam = (tran->GetTranslation())[2];
126  Int_t feSens = fCurrentDigiPar->GetNrTopFE() + fCurrentDigiPar->GetNrBotFE();
127  for(Int_t fe =0;fe<feSens;fe++)
128  { // write to mapping
129  Int_t feNr;
130  // count only real-world existing frontends, others are -1
132  fFakeCount--; // decrease first, starting at -1!
133  feNr = fFakeCount; // handle the single sided sensors with a fake bittom side
134  }else{
135  feNr=fFeCount;
136  fFeCount++; // increase later, starting at 0
137  }
138  std::pair<Int_t,Int_t> apair(fe,feNr);
139  Map_Entry anEntry(detpath,apair);
140  (fSortedMapping[sortparam]).push_back(anEntry);
141  }
142  }
143  return;
144 }
145 
146 
147 
149 {
150  TIter parsetiter(fDigiParameterList);
151  while ( PndSdsStripDigiPar* digipar = (PndSdsStripDigiPar*)parsetiter() )
152  {
153  const char* sensortype = digipar->GetSensType();
154  if(detpath.Contains(sensortype)) {
155  fCurrentDigiPar = digipar;
156  Info("SelectSensorParams","Found a parameter set for %s", detpath.Data());
157  return kTRUE;
158  }
159  }
160  // no suiting object found
161  Error("SelectSensorParams","Detector name does not contain a valid parameter name. DetName : %s",detpath.Data());
162  return kFALSE;
163 }
164 
165 
166 //TString PndMvdCreateDefaultApvMap::FindNodePath(TGeoNode* node)
167 //{
168 // // Find a nodes full path by going there in the gGeoManager
169 // // With many volumes this becomes surely slow.
170 // const char* oldpath = gGeoManager->GetPath();
171 // gGeoManager->CdTop(); // dive down from top node
172 // DiveDownToNode(node);
173 // TString pathname = gGeoManager->GetPath();
174 // gGeoManager->cd(oldpath);
175 // return pathname;
176 //}
177 //
178 //void PndMvdCreateDefaultApvMap::DiveDownToNode(TGeoNode* node)
179 //{
180 // // cd gGeoManager from the current node to a given node
181 // TGeoNode *currentNode = gGeoManager->GetCurrentNode();
182 // if (currentNode == node) return;
183 // for (Int_t iNod=0; iNod<currentNode->GetNdaughters();iNod++)
184 // {
185 // gGeoManager->CdDown(iNod);
186 // DiveDownToNode(node);
187 // if (gGeoManager->GetCurrentNode() == node) return;
188 // gGeoManager->CdUp();
189 // }
190 //}
191 
192 
193 
194 
195 
PndTransMap * map
Definition: sim_emc_apd.C:99
labels push_back("electron")
std::map< Double_t, std::vector< Map_Entry > > fSortedMapping
TGeoManager * gGeoManager
std::pair< TString, std::pair< Int_t, Int_t > > Map_Entry
Bool_t CreateFile(TString outFile)
TList * GetDigiParNames()
Double_t
Digitization Parameter Class for MVD-Strip part.
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
PndSdsStripDigiPar * fCurrentDigiPar
TFile * out
Definition: reco_muo.C:20
int fe
Definition: anaLmdDigi.C:67
ClassImp(PndAnaContFact)
Int_t GetNrTopFE() const
Int_t GetNrBotFE() const
TString outfile
Bool_t SelectSensorParams(TString detname)