FairRoot/PandaRoot
PndEmcMakeCorr.cxx
Go to the documentation of this file.
1 //--------------------------------------------------------------------------
2 // File and Version Information:
3 // $Id:$
4 //
5 // Description:
6 // Class PndEmcMakeCorr
7 // Do an energy and theta corrections
8 // (at the moment for photons, 4.02.2010)
9 //
10 // Author List:
11 // A. Biegun
12 // M. Babai
13 //------------------------------------------------------------------------
14 //
15 //-----------------------
16 // This Class's Header --
17 //-----------------------
18 #include "PndEmcMakeCorr.h"
19 #include "PndEmcCorrection.h"
20 
21 //-------------------------------
22 // Collaborating Class Headers --
23 //-------------------------------
24 #include "PndEmcStructure.h"
25 #include "PndEmcDataTypes.h"
26 
27 #include "PndEmcMapper.h"
28 #include "PndEmcDigiPar.h"
29 #include "PndEmcRecoPar.h"
30 #include "PndEmcDigi.h"
31 #include "PndEmcCluster.h"
32 #include "PndEmcBump.h"
33 
34 #include "FairRootManager.h"
35 #include "FairRunAna.h"
36 #include "FairRuntimeDb.h"
37 
38 //#include "TClonesArray.h"
39 //#include "TObject.h"
40 //#include "TH2.h"
41 //#include "TVector3.h"
42 
43 #include <algorithm>
44 #include <iostream>
45 
46 using std::cout;
47 using std::endl;
48 
49 //----------------
50 // Constructors --
51 //----------------
52 PndEmcMakeCorr::PndEmcMakeCorr(Int_t , TString transportModel, TString clusterType):
53 f(new TFile()), f0(new TFile()), f1(new TFile()), f2(new TFile()), f3(new TFile()), fClusterIndex(-1), fClusterArray(0), fClusterArrayCorr(0), fDigiPar(new PndEmcDigiPar()), fRecoPar(new PndEmcRecoPar()), fVerbose(0), fStoreClustersCorr(kTRUE), fModel(transportModel), fClusterType(clusterType) // verbose //[R.K.03/2017] unused variable(s)
54 {
55  cout<<"PndEmcMakeCorr constructor: "<<fClusterType<<endl;
56 }
57 
58 //--------------
59 // Destructor --
60 //--------------
62 {
63  delete fClusterArray;
64  delete fClusterArrayCorr;
65  delete fDigiPar;
66  delete fRecoPar;
67 
68  f->Close();
69  f0->Close();
70  f1->Close();
71  f2->Close();
72  f3->Close();
73  delete f;
74  delete f0;
75  delete f1;
76  delete f2;
77  delete f3;
78 }
79 
80 // ----- Public method Intialize ---------------------------------------
81 InitStatus PndEmcMakeCorr::Init() {
82 
83  // Get RootManager
84  FairRootManager* ioman = FairRootManager::Instance();
85  if ( ! ioman ){
86  cout << "-E- PndEmcMakeCorr::Init: "
87  << "RootManager not instantiated!" << endl;
88  return kFATAL;
89  }
90 
91  // Get input array - Clusters
92  fClusterArray = dynamic_cast<TClonesArray *> (ioman->GetObject(fClusterType));
93  cout<<""<<endl;
94  cout << "-------------> fClusterType is: ***** "<<fClusterType<<" *****"<<endl;
95  if ( ! fClusterArray ) {
96  cout << "-W- PndEmcMakeCorr::Init: "
97  << "No "<<fClusterType<<" array!"
98  << endl;
99  return kERROR;
100  }
101 
102  // Create and register output array
103  fClusterArrayCorr = new TClonesArray("PndEmcCorrection");
104 
105  TString corName;
106  corName = fClusterType+"Corr";
107  ioman->Register(corName,"Emc",fClusterArrayCorr,GetPersistency());
108 
109  // Read 2-dim histograms with shifts: GetMean()
110  // of reconstructed clusters compared to MC clusters
111  cout<<"Used transportModel is " <<fModel <<endl;//" & Particle " <<fPartId<<endl;
112 
113  TString work = getenv("VMCWORKDIR");
114  TString work1[4];
115  work += "/macro/params/";
116  cout<<"directory is:: "<<work<<endl;
117 
118  for (Int_t i=0; i<4; i++){
119  fPartName[0] = "gamma";
120  fPartName[1] = "electron";
121  fPartName[2] = "pion";
122  fPartName[3] = "other";
123 
124  corrFileName[i] = fPartName[i] + "_en_th_corr_"+ fModel+".root";
125  work1[i] += work + corrFileName[i];
126 
127  //cout<<" "<<endl;
128  //cout<<"name of "<< i <<" particle is: "<<fPartName[i]<<endl;
129  //cout<<" & path is: "<<work1[i]<<endl;
130  }
131  cout<<" "<<endl;
132  cout<<"== PLEASE CHECK if the correction map exists for an appropriate PARTICLE & TRANSPORT MODEL!!! "<<endl;
133  cout<<"============================================================================================= "<<endl;
134  cout<<""<<endl;
135 
136  for(int i=0; i< 4; i++){
137 
138  char buffer[10];
139  int myInteger = i;
140  sprintf(buffer, "%i", myInteger);
141 
142  f+=myInteger;
143  f= new TFile(work1[i],"READ");
144  cout<< "File "<<f->GetName() << " is read"<<endl;
145 
146  // *** GetMean() from: E_cluster/E_MC & Theta_MC-Theta_Cluster
147  //
148  // Target EMC
149  nameEn[i] = "hisEnergyDelta";
150  nameTh[i] = "hisThetaDiff";
151  hEn[i] = (TH2F*) f->Get(nameEn[i]);
152  hTh[i] = (TH2F*) f->Get(nameTh[i]);
153 
154  // Shashlyk
155  nameEn5[i] = "hisEnergy5Delta";
156  nameTh5[i] = "hisTheta5Diff";
157  hEn5[i] = (TH2F*) f->Get(nameEn5[i]);
158  hTh5[i] = (TH2F*) f->Get(nameTh5[i]);
159 
160  //cout<<"hists: Target EMC "<<hEn[i]->GetName()<<"\t"<<hTh[i]->GetName()<<endl;
161  //cout<<"hists: Shashlyk "<<hEn5[i]->GetName()<<"\t"<<hTh5[i]->GetName()<<endl;
162  }
163 
164  return kSUCCESS;
165 }
166 
167 //-------------
168 // Methods --
169 //-------------
170 Int_t
171 PndEmcMakeCorr::FindTheBin(TH2* lookup_table, Float_t value_x, Float_t value_y, Int_t &bin_x, Int_t &bin_y)
172 {
173  bin_x = lookup_table->GetXaxis()->FindBin(value_x);
174  bin_y = lookup_table->GetYaxis()->FindBin(value_y);
175 
176  if ((bin_x < 1) || (bin_x > lookup_table->GetXaxis()->GetNbins()))
177  {
178  bin_x = -1; bin_y = -1;
179  return -1;
180  }
181 
182  if ((bin_y < 1) || (bin_y > lookup_table->GetYaxis()->GetNbins()))
183  {
184  bin_x = -1; bin_y = -1;
185  return -2;
186  }
187 
188  return 0; // Success
189 }
190 
191 Double_t
192 PndEmcMakeCorr::GetValueInZ(TH2 *lookup_table, Float_t value_x, Float_t value_y, Bool_t use_interpolation)
193 {
194  // We own the EmcLocMaxInfo objects. Delete from last time.
195  // Clean-up res, We need an empty set to store the results.
196 
197  if (use_interpolation)
198  {
199  //cout<<"use_interpolation = kTRUE "<<endl;
200  //
201  // Use the interpolarion routine of ROOT:
202  // Interpolate approximates the value via bilinear
203  // interpolation based on the four nearest bin centers
204  // see Wikipedia, Bilinear Interpolation
205  // Andy Mastbaum 10/8/2008
206  // vaguely based on R.Raja 6-Sep-2008
207  //
208  //cout<<"value_x = "<< value_x <<", value_y = "<<value_y <<endl;
209 
210  return (lookup_table->Interpolate(value_x,value_y));
211  }
212  else
213  {
214  //cout<<"use_interpolation = kFALSE "<<endl;
215  Int_t binx, biny, retval;
216 
217  retval = FindTheBin(lookup_table, value_x, value_y, binx, biny);
218  if (retval)
219  {
220  cout << "<E> Error in FindTheBin, check your table and input values!!!!: " << retval << endl;
221  return 0;
222  }
223 
224  return (lookup_table->GetBinContent(binx,biny));
225  }
226  return 0;
227 }
228 
229 void PndEmcMakeCorr::Exec(Option_t*)
230 {
231  // Reset output array(s)
232  if ( ! fClusterArrayCorr ) Fatal("Exec", "No Corrected Cluster Array");
233  fClusterArrayCorr->Delete();
234 
235  // Variables for Energy & Theta Cluster's Corrections
236  Bool_t use_interpolation=kTRUE;
237  Double_t valzEn[4], valzTh[4], ThCorr[4], EnCorr[4];//ThCorrRad[4], //[R.K.03/2017] unused variable
238  //Int_t ndigi; //[R.K.03/2017] unused variable
239  //Int_t particle[5]; //[R.K. 01/2017] unused variable?
240  Int_t chosenModule =0;
241 
242  // Loop over Clusters to make the energy and theta correction
243  // by dividing and adding the GetMean() values from lookup table
244  Int_t clustLength = fClusterArray->GetEntriesFast();
245  //cout <<"clustLength " <<clustLength<<endl;
246 
247  for (Int_t iCluster=0; iCluster<clustLength; iCluster++)
248  {
249 
250  PndEmcCluster* theCluster;
251 
252  if (fClusterType.Contains("EmcCluster")) {
253 
254  //PndEmcCluster* theCluster;
255  theCluster = (PndEmcCluster*) fClusterArray->At(iCluster);
256  //cout<<"Cluster was taken from ---> "<<fClusterType<<endl;
257  //cout<<"theCluster ---> "<<theCluster->energy()<<endl;
258 
259  } else if (fClusterType.Contains("EmcBump")) {
260 
261  //PndEmcBump* theCluster;
262  theCluster = (PndEmcBump*) fClusterArray->At(iCluster);
263  //cout<<"Cluster was taken from ---> "<<fClusterType<<endl;
264  //cout<<"Bump ---> "<<theCluster->energy()<<endl;
265 
266  }else{
267  cout<<"None of the Cluster object is taken !!!"<<endl;
268  }
269 
270  // Check the ID of a crystal, get module number from it and put into a map
271  std::map<Int_t,Int_t> digiMap=theCluster->MemberDigiMap();
272  std::map<Int_t,Int_t>::iterator iter;
273  //ndigi=digiMap.size(); //[R.K.03/2017] unused variable
274 
275  Int_t ID, module;
276  std::map<int, int> counting;
277  std::map<int, int>::iterator iCounting;
278  Int_t oldCounting = 0;
279 
280  if(digiMap.size() != 0)
281  {
282  for(iter=digiMap.begin(); iter != digiMap.end(); ++iter)
283  {
284  ID = iter->first;
285  module = ID/100000000;
286  counting[module]++;
287  }
288  }
289 
290  // Get an EMC module in which most of the digits are
291  for(iCounting=counting.begin(); iCounting!=counting.end(); iCounting++)
292  {
293  if((*iCounting).second > oldCounting)
294  {
295  chosenModule = (*iCounting).first;
296  oldCounting = (*iCounting).second;
297  }
298  }
299 
300  Double_t energy=theCluster->energy();
301  TVector3 position=theCluster->where();
302  Double_t theta=position.Theta()*(180./TMath::Pi());
303 
304  //cout << " "<<endl;
305  //cout << "$$$$$ iCluster "<<iCluster<<endl;
306 
307  //Different types of particles: 1=gamma, 2=electron, 3=pion, 4=other
308  for (Int_t i=0; i<4; i++)
309  {
310  if (chosenModule==5){ // separate map for Shaslyk
311 
312  valzEn[i] = GetValueInZ( hEn5[i], energy, theta, use_interpolation);
313  valzTh[i] = GetValueInZ( hTh5[i], energy, theta, use_interpolation);
314 
315  ThCorr[i] = (valzTh[i]+theta);
316  //ThCorrRad[i] = ThCorr[i]*(TMath::Pi()/180.); // DegToRad //[R.K.03/2017] unused variable
317 
318  EnCorr[i] = energy/valzEn[i];
319 
320  /*cout << "*** EMC Module: "<< chosenModule
321  <<", Theta= "<<theta <<", valzTh= "<<valzTh[i] <<", ThCorr="<<ThCorr[i]
322  <<", Energy= "<<energy <<", valzEn= "<<valzEn[i] <<", EnCorr="<<EnCorr[i]<<endl;
323  */
324  }else{ // separate map for Target EMC
325  if (theta <6.) continue; // Avoid the edges for FwEndCap and Shashlyk
326 
327  valzTh[i] = GetValueInZ( hTh[i], energy, theta, use_interpolation);
328  valzEn[i] = GetValueInZ( hEn[i], energy, theta, use_interpolation);
329 
330  ThCorr[i] = (valzTh[i]+theta);
331  //ThCorrRad[i] = ThCorr[i]*(TMath::Pi()/180.); //[R.K.03/2017] unused variable
332 
333  EnCorr[i] = energy/valzEn[i];
334 
335  /*cout << "*** EMC Module: "<< chosenModule
336  <<", Theta= "<<theta <<", valzTh= "<<valzTh[i] <<", ThCorr="<<ThCorr[i]
337  <<", Energy= "<<energy <<", valzEn= "<<valzEn[i] <<", EnCorr="<<EnCorr[i] <<endl;
338  */
339  }
340  } // End of corrections for 4 different particles
341 
342  new((*fClusterArrayCorr)[iCluster]) PndEmcCorrection(chosenModule, EnCorr[0], EnCorr[1], EnCorr[2], EnCorr[3], ThCorr[0], ThCorr[1], ThCorr[2], ThCorr[3], valzEn[0], valzEn[1], valzEn[2], valzEn[3], valzTh[0], valzTh[1], valzTh[2], valzTh[3]);
343 
344  } // End of the loop over Clusters
345 }
346 
348 
349  // Get run and runtime database
350  FairRun* run = FairRun::Instance();
351  if ( ! run ) Fatal("SetParContainers", "No analysis run");
352 
353  FairRuntimeDb* db = run->GetRuntimeDb();
354  if ( ! db ) Fatal("SetParContainers", "No runtime database");
355 
356  // Get Emc digitisation parameter container
357  fDigiPar = (PndEmcDigiPar*) db->getContainer("PndEmcDigiPar");
358 
359  // Get Emc reconstruction parameter container
360  fRecoPar = (PndEmcRecoPar*) db->getContainer("PndEmcRecoPar");
361 }
362 
364 {
366  return;
367 }
368 
370 
TH2F * hEn5[4]
int fVerbose
Definition: poormantracks.C:24
virtual InitStatus Init()
Int_t run
Definition: autocutx.C:47
TVector3 where() const
Int_t i
Definition: run_full.C:25
TF1 * f1
Definition: reco_analys2.C:50
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
PndEmcMakeCorr(Int_t verbose=0, TString transportModel="TGeant3", TString clusterType="EmcBump")
Bool_t fStoreClustersCorr
TString fPartName[4]
TString nameTh5[4]
PndEmcRecoPar * fRecoPar
TClonesArray * fClusterArrayCorr
TString corrFileName[4]
Double_t GetValueInZ(TH2 *lookup_table, Float_t value_x, Float_t value_y, Bool_t use_interpolation=kFALSE)
TFile * f3
Double_t
parameter set of Emc digitisation
Definition: PndEmcDigiPar.h:12
TFile * f
Definition: bump_analys.C:12
a cluster (group of neighboring crystals) of hit emc crystals
Definition: PndEmcCluster.h:29
const std::map< Int_t, Int_t > & MemberDigiMap() const
Definition: PndEmcCluster.h:43
TString nameEn5[4]
TString fClusterType
TString nameEn[4]
virtual void SetParContainers()
TFile * f2
virtual ~PndEmcMakeCorr()
virtual Double_t energy() const
ClassImp(PndAnaContFact)
PndEmcDigiPar * fDigiPar
Int_t FindTheBin(TH2 *lookup_table, Float_t value_x, Float_t value_y, Int_t &bin_x, Int_t &bin_y)
Double_t Pi
TString nameTh[4]
void SetStorageOfData(Bool_t val)
represents a reconstructed (splitted) emc cluster
Definition: PndEmcBump.h:34
Parameter set for Emc Reco.
Definition: PndEmcRecoPar.h:12
virtual void Exec(Option_t *opt)
Double_t energy
Definition: plot_dirc.C:15
TClonesArray * fClusterArray
TH2F * hTh5[4]