FairRoot/PandaRoot
PndEmcMapper.cxx
Go to the documentation of this file.
1 // Description:
3 // EMC Mapper class. Map crystal index (fDetectorId) to two coordinate index.
4 //
5 // Author List:
6 // Dima Melnychuk
7 // 27/04/2007 Stefano Spataro (encoding for the Fwd Endcup)
8 //
10 
11 #include "PndEmcMapper.h"
12 #include "PndEmcTwoCoordIndex.h"
13 
14 #include <iostream>
15 #include <fstream>
16 
17 using namespace std;
18 
21 
22 PndEmcMapper::PndEmcMapper(): fIntTwoCoordMap()
23 {
24 }
25 void PndEmcMapper::Init(Int_t mapVersion)
26 {
27  if (mapVersion==0)
28  {
29  cout<<"Emc mapper version 0 does not exist"<<endl;
30  }
31  else if (mapVersion!=fMapVersion)
32  {
33  fMapVersion=mapVersion;
34  switch (mapVersion) {
35  case 1:
40  break;
41  case 2:
46  break;
47  case 3:
52  break;
53  case 4:
55  break;
56  case 5:
58  break;
59  case 6:
61  break;
62  case 7:
64  break;
65  case 8: // old backward emc mappping (geom. version 2008)
67  break;
68  case 9: // old barrel emc mapping
73  break;
74  default :
75  cout<<"Emc Mapper version "<<mapVersion<<" is not defined"<<endl;
76  }
77  }
78 }
79 
81 {
82  if (_instance == 0) {
83  cout<<"Emc mapper should be initialised first with PndEmcMapper::Init()"<<endl;
84  return 0;
85  }
86  return _instance;
87 }
88 
90 {
91  std::map<Int_t,PndEmcTwoCoordIndex* > newMapp = newMapper->GetTciMap();
92 
93  fIntTwoCoordMap.insert(newMapp.begin(),newMapp.end());
94 }
95 
96 // ----- Destructor -----------------------------------
98 {
99  delete _instance;
100  for(std::map<Int_t,PndEmcTwoCoordIndex* >::iterator iter = fIntTwoCoordMap.begin();
101  iter != fIntTwoCoordMap.end(); ++iter){
102  delete (*iter).second;
103  }
104  fIntTwoCoordMap.clear();
105 }
106 // --------------------------------------------------------
107 
109 {
110  PndEmcTwoCoordIndex *_tci;
111  Int_t iTheta, iPhi, detId, detId_tmp, iX, iY;
112  iTheta = iPhi = detId = detId_tmp =iX = iY = 0;
113  // Crys 1-5000; copyNo 1-20; nRow 1-100, nMod 1-2
114  // 72(iTheta)x160(iPhi) for barrel part
115  // index iTheta from 1 (backward part) till 72 (forward)
116  for (Int_t module=1; module<=2; module++)
117  {
118  if (module ==2)
119  {
120  for (Int_t row=1; row<=29;row++)
121  for (Int_t crystal=1; crystal<=10;crystal++)
122  for (Int_t copy=1; copy<=16;copy++)
123  {
124  if ((copy==1 || copy==9) && (crystal>=4 && crystal<=6) && (row<=3)) continue;
125  iPhi=(11-crystal)+(copy-1)*10;
126  iTheta=-row+30;
127 
128  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
129  _tci=new PndEmcTwoCoordIndex(iTheta,iPhi,detId);
130  fIntTwoCoordMap[detId]=_tci;
131  }
132  }
133  else if (module ==1)
134  {
135  for (Int_t row=1; row<=43;row++)
136  for (Int_t crystal=1; crystal<=10;crystal++)
137  for (Int_t copy=1; copy<=16;copy++)
138  {
139  iPhi=(11-crystal)+(copy-1)*10;
140  iTheta=row+29;
141 
142  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
143  _tci=new PndEmcTwoCoordIndex(iTheta,iPhi,detId);
144  fIntTwoCoordMap[detId]=_tci;
145  }
146  }
147  }
148 }
149 
151 {
152  PndEmcTwoCoordIndex *_tci;
153  Int_t iTheta, iPhi, detId, detId_tmp, iX, iY;
154  iTheta = iPhi = detId = detId_tmp =iX = iY = 0;
155  // Crys 1-5000; copyNo 1-20; nRow 1-100, nMod 1-2
156  // 72(iTheta)x160(iPhi) for barrel part
157  // index iTheta from 1 (backward part) till 72 (forward)
158  for (Int_t module = 1; module <= 2; module++) {
159  if (module == 2) {
160  for (Int_t row = 1; row <= 28; row++) {
161  for (Int_t crystal = 1; crystal <= 10; crystal++) {
162  for (Int_t copy = 1; copy <= 16; copy++) {
163  if ((copy==1 || copy==9) && (crystal>=3 && crystal<=8) && (row<=3)) continue;
164  iPhi = (11-crystal)+(copy-1)*10;
165  iTheta = -row + 29;
166 
167  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
168  _tci = new PndEmcTwoCoordIndex(iTheta, iPhi, detId);
169  fIntTwoCoordMap[detId] = _tci;
170  }
171  }
172  }
173  }
174  if (module == 1) {
175  for (Int_t row = 1; row <= 43; row++) {
176  for (Int_t crystal = 1; crystal <= 10; crystal++) {
177  for (Int_t copy=1; copy<=16;copy++) {
178  if ((copy==1 || copy==9) && (crystal>=3 && crystal<=8) && (row<=3)) continue;
179  iPhi = (11-crystal)+(copy-1)*10;
180  iTheta = row + 28;
181 
182  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
183  _tci = new PndEmcTwoCoordIndex(iTheta,iPhi,detId);
184  fIntTwoCoordMap[detId] = _tci;
185  }
186  }
187  }
188  } // if module
189  }
190 }
191 
193 {
194  PndEmcTwoCoordIndex *_tci;
195  Int_t detId, detId_tmp, iX, iY; //iTheta,iPhi, //[R.K. 01/2017] unused variable
196  detId = detId_tmp =iX = iY = 0; //iTheta = iPhi = //[R.K. 01/2017] unused variable
197 
198  Int_t module =3;
199  for (Int_t row=1; row<=40;row++)
200  for (Int_t crystal=1; crystal<=40;crystal++)
201  for (Int_t copy=1; copy<=4;copy++)
202  {
203  if (copy==1) { iX = -row+1; iY = crystal; }
204  if (copy==2) { iX = -row+1; iY = -crystal+1; }
205  if (copy==3) { iX = row; iY = -crystal+1; }
206  if (copy==4) { iX = row; iY = crystal; }
207 
208  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
209 
210  _tci=new PndEmcTwoCoordIndex(iX+250,iY+250,detId);
211  fIntTwoCoordMap[detId]=_tci;
212  }
213 }
214 
216 {
217  PndEmcTwoCoordIndex *_tci;
218  Int_t detId, detId_tmp, iX, iY; //iTheta,iPhi, //[R.K. 01/2017] unused variable
219  detId = detId_tmp =iX = iY = 0; //iTheta = iPhi = //[R.K. 01/2017] unused variable
220 
221  Int_t module =3;
222  for (Int_t row=1; row<=36;row++)
223  for (Int_t crystal=1; crystal<=36;crystal++)
224  for (Int_t copy=1; copy<=4;copy++)
225  {
226  if (copy==1) { iX = -row+1; iY = crystal; }
227  if (copy==2) { iX = -row+1; iY = -crystal+1; }
228  if (copy==3) { iX = row; iY = -crystal+1; }
229  if (copy==4) { iX = row; iY = crystal; }
230 
231  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
232 
233  _tci=new PndEmcTwoCoordIndex(iX+250,iY+250,detId);
234  fIntTwoCoordMap[detId]=_tci;
235  }
236 }
237 
239 {
240  PndEmcTwoCoordIndex *_tci;
241  Int_t detId, detId_tmp, iX, iY; //iTheta, iPhi, //[R.K. 01/2017] unused variable
242  detId = detId_tmp =iX = iY = 0; //iTheta = iPhi = //[R.K. 01/2017] unused variable
243 
244  Int_t module =3;
245  for (Int_t row = -37; row <= 37; row++)
246  for (Int_t col = -36; col <= 36; col++)
247  if (row != 0 && col != 0)//in copy numbering of the crystals in the geometry root file, there's no CrystalCol=0 or CrystalRow=0
248  {
249  detId = module*100000000 + (row+37)*1000000 + (col+36);
250 
251  iX = -col; //the minus sign before 'iX' is introduced, since the geometry of FwEndCap gets rotated by 180 deg around the y-axis in PndEmc.cxx
252  iY = row;
253  if (iX >0) // these two if conditions are introduced here to make the mapping down here (_tci) a continuous pattern
254  iX -= 1;
255  if (iY >0)
256  iY -= 1;
257  _tci=new PndEmcTwoCoordIndex(iX+250,iY+250,detId);
258 
259  fIntTwoCoordMap[detId]=_tci;
260  }
261 }
262 
264 {
265  PndEmcTwoCoordIndex *_tci;
266  Int_t detId, detId_tmp, iX, iY; //iTheta, iPhi, //[R.K. 01/2017] unused variable
267  detId = detId_tmp =iX = iY = 0; //iTheta = iPhi = //[R.K. 01/2017] unused variable
268  Int_t module =4;
269  for (Int_t row=1; row<=18;row++)
270  for (Int_t crystal=1; crystal<=18;crystal++)
271  for (Int_t copy=1; copy<=4;copy++)
272  {
273  if (copy==1) { iX = -row+1; iY = crystal; }
274  if (copy==2) { iX = -row+1; iY = -crystal+1; }
275  if (copy==3) { iX = row; iY = -crystal+1; }
276  if (copy==4) { iX = row; iY = crystal; }
277 
278  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
279 
280  _tci=new PndEmcTwoCoordIndex(iX+350,iY+350,detId);
281  fIntTwoCoordMap[detId]=_tci;
282  }
283 }
284 
286 {
287  // *** for testing of BwEndCap ONLY --> from "emc_module4_*.root" file ***
288  // 26.02.2009
289  PndEmcTwoCoordIndex *_tci;
290  Int_t detId, detId_tmp, iX, iY; //iTheta,iPhi, //[R.K. 01/2017] unused variable
291  detId = detId_tmp =iX = iY = 0; //iTheta = iPhi = //[R.K. 01/2017] unused variable
292 
293  Int_t module=4;
294  for (Int_t row=1; row<=16;row++)
295  for (Int_t crystal=1; crystal<=16;crystal++)
296  for (Int_t copy=1; copy<=4;copy++)
297  {
298  if (copy==1) { iX = -row+1; iY = crystal; }
299  if (copy==2) { iX = -row+1; iY = -crystal+1; }
300  if (copy==3) { iX = row; iY = -crystal+1; }
301  if (copy==4) { iX = row; iY = crystal; }
302 
303  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
304  _tci=new PndEmcTwoCoordIndex(iX+350,iY+350,detId);
305  fIntTwoCoordMap[detId]=_tci;
306  }
307 }
308 
310 {
311  // *** 2017 version of the BwEndCap geometry ***
312  PndEmcTwoCoordIndex *_tci;
313  Int_t detId, iX, iY, iXrel, iYrel, rowc;
314  detId = iX = iY = iXrel = iYrel = rowc = 0;
315 
316  Int_t module=4;
317 
318  for (Int_t row=0; row<10;row++){ //-- loop over submodules in one quarter (called row to keep
319  //-- nomenclature of PndEmcStructure)
320  for (Int_t crystal=0; crystal<16;crystal++){ //-- loop over crystals in one submodule
321 
322  if( row < 6 ){ // side submodules
323 
324  iXrel = 4*(row%3) + (crystal%4) - 6;
325  iYrel = -4*(row/3) - (crystal/4) + 14;
326 
327  } else { // corner submodules
328  rowc = row - 6;
329 
330  iXrel = 4*(rowc%2) + (crystal%4) + 6;
331  iYrel = -4*(rowc/2) - (crystal/4) + 13;
332 
333  }
334 
335  for (Int_t copy=0; copy<4;copy++){ //-- loop over quarters
336 
337  if (copy==0) { iX = iXrel ; iY = iYrel ; }
338  if (copy==1) { iX = -iYrel-1; iY = iXrel ; }
339  if (copy==2) { iX = -iXrel-1; iY = -iYrel-1; }
340  if (copy==3) { iX = iYrel ; iY = -iXrel-1; }
341 
342  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
343  _tci=new PndEmcTwoCoordIndex(iX+351,iY+351,detId);
344  fIntTwoCoordMap[detId]=_tci;
345  }
346  }
347  }
348 }
349 
350 
351 
353 {
354  PndEmcTwoCoordIndex *_tci;
355  Int_t detId, detId_tmp, iX, iY; //iTheta,iPhi, //[R.K. 01/2017] unused variable
356  detId = detId_tmp =iX = iY = 0; //iTheta = iPhi = //[R.K. 01/2017] unused variable
357  Int_t module =5;
358 
359  for (Int_t row=1; row<=14;row++)
360  for (Int_t crystal=1; crystal<=7;crystal++)
361  for (Int_t copy=1; copy<=4;copy++)
362  {
363  if (copy==1) { iX = -row+1; iY = crystal; }
364  if (copy==2) { iX = -row+1; iY = -crystal+1; }
365  if (copy==3) { iX = row; iY = -crystal+1; }
366  if (copy==4) { iX = row; iY = crystal; }
367 
368  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
369 
370  _tci=new PndEmcTwoCoordIndex(iX+450,iY+450,detId);
371  fIntTwoCoordMap[detId]=_tci;
372  }
373 }
374 
376 {
377  // *** for testing of Fsc ONLY --> from "emc_module5_*.root" file ***
378  // 20.04.2010
379  PndEmcTwoCoordIndex *_tci;
380  Int_t detId, detId_tmp, iX, iY; //iTheta, iPhi, //[R.K. 01/2017] unused variable
381  detId = detId_tmp =iX = iY = 0; //iTheta = iPhi = //[R.K. 01/2017] unused variable
382 
383  Int_t module=5;
384  for (Int_t row=1; row<=28;row++)
385  for (Int_t crystal=1; crystal<=54;crystal++)
386  {
387  Int_t copy = 1;
388  iX = row;
389  iY = crystal;
390  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
391  _tci=new PndEmcTwoCoordIndex(iX+450,iY+450,detId);
392  fIntTwoCoordMap[detId]=_tci;
393  }
394 }
395 
397 {
398  PndEmcTwoCoordIndex *_tci;
399  Int_t detId, detId_tmp, iX, iY; //iTheta,iPhi, //[R.K. 01/2017] unused variable
400  detId = detId_tmp =iX = iY = 0; //iTheta = iPhi = //[R.K. 01/2017] unused variable
401  Int_t module =6;
402  for (Int_t row=1; row<=5;row++)
403  for (Int_t crystal=1; crystal<=5;crystal++)
404  {
405  Int_t copy = 1;
406  iX = row;
407  iY = crystal;
408 
409  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
410 
411  _tci=new PndEmcTwoCoordIndex(iX+550,iY+550,detId);
412  fIntTwoCoordMap[detId]=_tci;
413  }
414 
415 }
416 
418  //Proto60
419  //18.01.10
420  PndEmcTwoCoordIndex *_tci;
421  Int_t detId = 0;
422  Int_t module = 7;
423  Int_t copy = 1;
424  for(Int_t row=1; row<=6; row ++)
425  for(Int_t crystal=1;crystal<=10;crystal++)
426  {
427  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
428  _tci = new PndEmcTwoCoordIndex(row+1000,crystal+1000,detId);
429  fIntTwoCoordMap[detId]=_tci;
430  }
431 }
432 
434 {
436  return tci;
437 }
438 
439 
440 
441 const std::map<Int_t,PndEmcTwoCoordIndex* >& PndEmcMapper::GetTciMap()
442 {
443  return fIntTwoCoordMap;
444 }
445 
446 Int_t PndEmcMapper::GetDetId(Int_t iTheta,Int_t iPhi)
447 {
448  Int_t module,row,copy,crystal,detId;
449  module = row = copy = crystal = detId = 0;
450  if (iTheta<=29)
451  {
452  module=2;
453  row=30-iTheta;
454  copy=(iPhi-1)/10+1;
455  crystal=10 - (iPhi-1)%10;
456  }
457  else if ((iTheta>29)&&(iTheta<73))
458  {
459  module=1;
460  row=iTheta-29;
461  copy=(iPhi-1)/10+1;
462  crystal=10 - (iPhi-1)%10;
463  }
464 
466  if (iTheta>200 && iTheta<300)
467  {
468  module=3;
469  copy = 0;
470  if (iTheta<250 && iPhi>=250) {
471  row = (iPhi-250)+1+37;
472  crystal = -(iTheta-250)+36;
473  }
474  else if (iTheta<250 && iPhi<250) {
475  row = (iPhi-250)+37;
476  crystal = -(iTheta-250)+36;
477  }
478  else if (iTheta>=250 && iPhi>=250) {
479  row = (iPhi-250)+1+37;
480  crystal = -(iTheta-250+1)+36;
481  }
482  else if (iTheta>=250 && iPhi<250) {
483  row = (iPhi-250)+37;
484  crystal = -(iTheta-250+1)+36;
485  }
486  }
488 
489  if ((iTheta>300)&&(iTheta<400))
490  {
491  module=4;
492  if ((iTheta<=350)&& (iPhi>350))
493  {
494  copy = 1; row = 1-(iTheta-350); crystal = iPhi-350;
495  }
496  if ((iTheta<=350)&& (iPhi<=350))
497  {
498  copy = 2; row = 1-(iTheta-350); crystal = 1-(iPhi-350);
499  }
500  if ((iTheta>350)&& (iPhi<=350))
501  {
502  copy = 3; row = (iTheta-350); crystal = 1-(iPhi-350);
503  }
504  if ((iTheta>350)&& (iPhi>350))
505  {
506  copy = 4; row = (iTheta-350); crystal = iPhi-350;
507  }
508  }
509  if ((iTheta>400)&&(iTheta<500))
510  {
511  module=5;
512  if ((iTheta<=450)&& (iPhi>450))
513  {
514  copy = 1; row = 1-(iTheta-450); crystal = iPhi-450;
515  }
516  if ((iTheta<=450)&& (iPhi<=450))
517  {
518  copy = 2; row = 1-(iTheta-450); crystal = 1-(iPhi-450);
519  }
520  if ((iTheta>450)&& (iPhi<=450))
521  {
522  copy = 3; row = (iTheta-450); crystal = 1-(iPhi-450);
523  }
524  if ((iTheta>450)&& (iPhi>450))
525  {
526  copy = 4; row = (iTheta-450); crystal = iPhi-450;
527  }
528  }
529  if ((iTheta>500)&&(iTheta<600))
530  {
531  module=6;
532  copy = 1;
533  row = iTheta-550;
534  crystal = iPhi-550;
535  }
536 
537  detId = module*100000000 + row*1000000 + copy*10000 + crystal;
538 
539  return detId;
540 }
541 
int row
Definition: anaLmdDigi.C:67
const std::map< Int_t, PndEmcTwoCoordIndex * > & GetTciMap()
int col
Definition: anaLmdDigi.C:67
stores crystal index coordinates (x,y) or (theta,phi)
PndEmcTwoCoordIndex * GetTCI(Int_t DetectorId)
Emc geometry mapper.
Definition: PndEmcMapper.h:22
static Int_t fMapVersion
Definition: PndEmcMapper.h:45
std::map< Int_t, PndEmcTwoCoordIndex * > fIntTwoCoordMap
Definition: PndEmcMapper.h:40
static void Init(Int_t MapVersion)
void Add(PndEmcMapper *)
Int_t GetDetId(Int_t iTheta, Int_t iPhi)
static PndEmcMapper * _instance
Definition: PndEmcMapper.h:44
virtual ~PndEmcMapper()
ClassImp(PndAnaContFact)
static PndEmcMapper * Instance()