FairRoot/PandaRoot
PndMdtClusterTask.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndMdtClusterTask source file -----
3 // ----- Created 04/04/11 by S.Spataro -----
4 // -------------------------------------------------------------------------
5 
6 #include "PndMdtClusterTask.h"
7 
8 #include "PndMdtCluster.h"
9 #include "PndMdtDigi.h"
10 
11 #include "FairRootManager.h"
12 #include "FairDetector.h"
13 #include "FairRun.h"
14 #include "FairRuntimeDb.h"
15 
16 #include "TClonesArray.h"
17 
18 #include <iostream>
19 
20 using std::cout;
21 using std::endl;
22 
23 // ----- Default constructor -------------------------------------------
25  PndPersistencyTask("MDT Cluster Task")
26 {
27  SetPersistency(kTRUE);
28 }
29 // -------------------------------------------------------------------------
30 
31 // ----- Destructor ----------------------------------------------------
33 // -------------------------------------------------------------------------
34 
35 
36 
37 // ----- Public method Init --------------------------------------------
39 
40  cout << "-I- PndMdtClusterTask::Init: "
41  << "INITIALIZATION *********************" << endl;
42 
43  //FairRun* sim = FairRun::Instance(); //[R.K. 01/2017] unused variable?
44  //FairRuntimeDb* rtdb=sim->GetRuntimeDb(); //[R.K. 01/2017] unused variable?
45 
46  // Get RootManager
47  FairRootManager* ioman = FairRootManager::Instance();
48  if ( ! ioman ) {
49  cout << "-E- PndMdtClusterTask::Init: "
50  << "RootManager not instantiated!" << endl;
51  return kFATAL;
52  }
53 
54  // Get input array
55  fBoxIArray = (TClonesArray*) ioman->GetObject("MdtDigiBox");
56  if ( ! fBoxIArray ) {
57  cout << "-W- PndMdtClusterTask::Init: "
58  << "No MdtDigiBox array!" << endl;
59  return kERROR;
60  }
61 
62  fStripIArray = (TClonesArray*) ioman->GetObject("MdtDigiStrip");
63  if ( ! fStripIArray ) {
64  cout << "-W- PndMdtClusterTask::Init: "
65  << "No MdtDigiStrip array!" << endl;
66  return kERROR;
67  }
68 
69 
70  // Create and register output array
71  fBoxOArray = new TClonesArray("PndMdtCluster");
72  fStripOArray = new TClonesArray("PndMdtCluster");
73  ioman->Register("MdtBoxCluster","Mdt",fBoxOArray,GetPersistency());
74  ioman->Register("MdtStripCluster","Mdt",fStripOArray,GetPersistency());
75 
76  cout << "-I- PndMdtClusterTask: Intialization successfull" << endl;
77 
78  return kSUCCESS;
79 
80 }
81 // -------------------------------------------------------------------------
82 
83 
84 
85 // ----- Public method Exec --------------------------------------------
86 void PndMdtClusterTask::Exec(Option_t*) {
87 
88  // Reset output array
89  fBoxOArray->Delete();
90  fStripOArray->Delete();
91 
92  if (!MdtMapping()) return;
93 
94  if (mapBox.size()>0)
95  {
96  map<Int_t, Int_t>::const_iterator box_iter;
97  map<Int_t, Int_t>::const_iterator find_iter;
98  for (box_iter=mapBox.begin();box_iter!=mapBox.end();++box_iter) // layer loop
99  {
100  std::vector<Int_t> boxList; //list of digis
101  boxList.push_back((*box_iter).first);
102 
103  Int_t nn = 1;
104  while (1)
105  {
106  find_iter = mapBox.find((*box_iter).first+nn);
107  if (find_iter==mapBox.end()) break; // if no close box
108  boxList.push_back((*box_iter).first+nn);
109  mapBox.erase ((*box_iter).first+nn); // delete already used cells
110  nn++;
111  }
112  PndMdtCluster *boxClu = AddClusterBox(boxList);
113  boxClu->SetLinks(FairMultiLinkedData("MdtDigiBox", boxList));
114  }
115 
116  } // end of box loop
117 
118  if (mapStrip.size()>0)
119  {
120  map<Int_t, Int_t>::const_iterator strip_iter;
121  map<Int_t, Int_t>::const_iterator find_iter;
122  for (strip_iter=mapStrip.begin();strip_iter!=mapStrip.end();++strip_iter) // layer loop
123  {
124  std::vector<Int_t> stripList; //list of digis
125  stripList.push_back((*strip_iter).first);
126 
127  Int_t nn = 1;
128  while (1)
129  {
130  find_iter = mapStrip.find((*strip_iter).first+nn);
131  if (find_iter==mapStrip.end()) break; // if no close strip
132  stripList.push_back((*strip_iter).first+nn);
133  mapStrip.erase ((*strip_iter).first+nn); // delete already used cells
134  nn++;
135  }
136  PndMdtCluster *stripClu = AddClusterStrip(stripList);
137  stripClu->SetLinks(FairMultiLinkedData("MdtDigiStrip", stripList));
138  }
139 
140  } // end of strip loop
141 
142 }
143 
144 // ----- Private method MdtMapping --------------------------------------------
146 {
147  // Reset output array
148  Int_t nBox = fBoxIArray->GetEntriesFast();
149  Int_t nStrip = fStripIArray->GetEntriesFast();
150  if (nBox==0 || nStrip==0) return kFALSE;
151 
152  Reset();
153  PndMdtDigi *mdtDigi = NULL;
154  // Mapping BOX digis per layer
155  for (Int_t iDigi=0; iDigi<nBox; iDigi++)
156  {
157  mdtDigi = (PndMdtDigi*) fBoxIArray->At(iDigi);
158  // each box has 8 cells. let's change the detId to have continuity
159  Int_t newDetectorID = mdtDigi->GetWire() + 8*mdtDigi->GetBox() + 1000*mdtDigi->GetLayerID() + 100000*mdtDigi->GetSector() + 1000000*mdtDigi->GetModule();
160  mapBox[newDetectorID] = iDigi;
161  }
162 
163  // Mapping STRIP digis per layer
164  for (Int_t iDigi=0; iDigi<nStrip; iDigi++)
165  {
166  mdtDigi = (PndMdtDigi*) fStripIArray->At(iDigi);
167  // strips are continuous in detId
168  mapStrip[mdtDigi->GetDetectorID()] = iDigi;
169  }
170 
171  return kTRUE;
172 }
173 
174 // ----- Private method Reset --------------------------------------------
176  // reset maps
177  mapBox.clear();
178  mapStrip.clear();
179 }
180 
181 
182 // -------------------------------------------------------------------------
183 
184 // ----- Private method AddCluster --------------------------------------------
185 PndMdtCluster* PndMdtClusterTask::AddClusterBox(std::vector<Int_t> digiList)
186 {
187  // It fills the PndMdtCluster category
188  TClonesArray& clref = *fBoxOArray;
189  Int_t size = clref.GetEntriesFast();
190  return new(clref[size]) PndMdtCluster(digiList);
191 }
192 // ----
193 
194 
195 // ----- Private method AddCluster --------------------------------------------
197 {
198  // It fills the PndMdtCluster category
199 
200  TClonesArray& clref = *fStripOArray;
201  Int_t size = clref.GetEntriesFast();
202  return new(clref[size]) PndMdtCluster(digiList);
203 }
204 // ----
205 
206 
PndMdtCluster * AddClusterStrip(std::vector< Int_t > digiList)
TClonesArray * fStripOArray
virtual InitStatus Init()
map< Int_t, Int_t > mapStrip
void SetPersistency(Bool_t val=kTRUE)
virtual void Exec(Option_t *opt)
Short_t GetWire() const
Definition: PndMdtDigi.h:46
TClonesArray * fBoxOArray
Short_t GetBox() const
Definition: PndMdtDigi.h:45
PndMdtCluster * AddClusterBox(std::vector< Int_t > digiList)
Short_t GetLayerID() const
Definition: PndMdtDigi.h:44
TClonesArray * fStripIArray
TClonesArray * fBoxIArray
ClassImp(PndAnaContFact)
Int_t GetDetectorID() const
Definition: PndMdtDigi.h:40
Short_t GetSector() const
Definition: PndMdtDigi.h:42
Short_t GetModule() const
Definition: PndMdtDigi.h:41
map< Int_t, Int_t > mapBox