FairRoot/PandaRoot
PndEmcFileCrystalCalibrator.cxx
Go to the documentation of this file.
1 //---------------------------------------------------------
2 // Description:
3 // File Calibrator for Emc Crystals.
4 //
5 // Christian Hammann
6 // 31.7.2012
7 
8 //---------------------------------------------------------
9 
11 #include <fstream>
12 #include <iostream>
13 #include "TObjArray.h"
14 
15 
16 using std::endl;
17 using std::ifstream;
18 using std::map;
19 
21 };
22 
23 PndEmcFileCrystalCalibrator::PndEmcFileCrystalCalibrator(const char *CalFileName):PndEmcAbsCrystalCalibrator(),fCalFileName(CalFileName){
24 };
25 
27  fCalFileName = CalFileName;
28 };
29 
31  ifstream in(fCalFileName,ifstream::in);
32 // in.open(fCalibrationFileName);
33  if (!in.good()) {
34  std::cerr << "Cannot open calibration file!" << endl;
35  return kFALSE;
36  }
37 
38  char buf[255];
39  while (in.getline(buf, 255)) {
40  TString tmp = buf;
41  TObjArray *tokens = tmp.Tokenize(" \t;");
42  if(tokens->GetEntries()<2){
43  continue;
44  }
45  tmp=tokens->UncheckedAt(0)->GetName();
46  TString tmp2 = tokens->UncheckedAt(1)->GetName();
47  if(tmp.IsDigit() && tmp2.IsFloat()){
48  fCalibrationMap.insert(std::pair<Long_t,Double_t>(tmp.Atoi(),tmp2.Atof()));
49 
50  }
51  if(tokens->GetEntries()<3){
52  continue;
53  }
54  tmp2 = tokens->UncheckedAt(2)->GetName();
55  if(tmp.IsDigit() && tmp2.IsFloat()){
56  fGainMap.insert(std::pair<Long_t,Double_t>(tmp.Atoi(),tmp2.Atof()));
57 
58  }
59  if(tokens->GetEntries()<4){
60  continue;
61  }
62  tmp2 = tokens->UncheckedAt(3)->GetName();
63  if(tmp.IsDigit() && tmp2.IsFloat()){
64  fOverflowMap.insert(std::pair<Long_t,Double_t>(tmp.Atoi(),tmp2.Atof()));
65 
66  }
67  delete tokens;
68 
69 
70  }
71  if(fVerbose >1){
72  std::cout << "calibration values:" << std::endl;
73  map<Long_t,Double_t>::iterator it;
74  map<Long_t,Double_t>::iterator it2;
75  Long_t detid;
76  for ( it=fCalibrationMap.begin() ; it != fCalibrationMap.end(); it++ ){
77  detid = (*it).first;
78  std::cout << detid << "\t" << (*it).second << "\t";
79  it2=fGainMap.find(detid);
80  if(it2!=fGainMap.end()){
81  std::cout << (*it2).second << "\t";
82  }
83  it2=fOverflowMap.find(detid);
84  if(it2!=fOverflowMap.end()){
85  std::cout << (*it2).second;
86  }
87  std::cout << endl;
88  }
89  }
90  return kTRUE;
91 };
92 
94  map<Long_t,Double_t>::iterator it;
95  if(SignalNr==0){
96  it = fOverflowMap.find(detId);
97  if(it!=fOverflowMap.end()){
98  if(Energy > it->second){
99  return kCALOVERFLOW;
100  }
101  }
102  }
103 
104  it = fCalibrationMap.find(detId);
105  if(it!=fCalibrationMap.end()){
106  Energy*=it->second;
107  }else{
108  return kCALMISSING;
109  }
110 
111  if(SignalNr==1){
112  it=fGainMap.find(detId);
113  if(it!=fGainMap.end()){
114  Energy*=it->second;
115  }
116  }
117 
118  return kCALOK;
119 };
120 
Class to use a textfile for Calibration.
PndTransMap * map
Definition: sim_emc_apd.C:99
virtual CalibrationStatus_t Calibrate(Double_t &Energy, Long_t detId, Int_t SignalNr=1)
Apply CrystalCalibration to Energy of Crystal derId.
std::map< Long_t, Double_t > fCalibrationMap
std::map< Long_t, Double_t > fOverflowMap
Double_t
ClassImp(PndAnaContFact)
void SetCalibrationFile(const char *CalFileName)
Set calibration file.
std::map< Long_t, Double_t > fGainMap
Abstract interface for a emc calibrator.