28 {
29
30 string inputFiles;
31 string detectorFile;
32 string outFile;
33 int Neighbours;
34 bool overwriteDetector;
35
36 try {
43 zap(argc,argv);
44 }
45 catch(const exception &error) {
46 ERROR(error.what() << endl);
47 }
48
52
56
57 TFile in(inputFiles.c_str() , "read");
58 string hist_str;
59 string hist_name;
60
61 string outFile_root = outFile+".root";
62 string outFile_csv = outFile+".csv";
63 string outFile_det = outFile+"_det.csv";
64
65 TFile output(outFile_root.c_str(),"RECREATE");
66 cout << " Writing histograms to: " << outFile_root << endl;
67 output.cd();
68
69 ofstream out_csv(outFile_csv.c_str());
70 cout << " Writing fitting data to: " << outFile_csv << endl;
71 out_csv << "String,Ref_floor,Tgt_floor,T0,Error" << endl;
72
73
77
78 map_type vmap;
79 for(
int j = 1;
j<=num_of_strings;
j++){
80 vmap.insert( make_pair(
j,base_vector) );
81 }
82
83 for(JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module){
84 int string_no = moduleRouter.getModule( module->getID() ).getString();
85 int tgt_floor = moduleRouter.getModule( module->getID() ).getFloor();
86
89
90 for( int i = 1; i <= Neighbours; i++){
91 int ref_floor = tgt_floor - i;
92
93 if(ref_floor < 1){ continue; }
94
96
97 if( in.GetListOfKeys()->Contains(hist_str.c_str()) ){
98 TH2D* h2D;
99 in.GetObject( hist_str.c_str(), h2D );
100
101
102 int bin = c.getIndex(tgt_floor - 1, ref_floor - 1 ) + 1;
103
104 hist_name =
"S"+hist_str+
"F"+
to_string(ref_floor)+
"_S"+hist_str+
"F"+
to_string(tgt_floor);
105 TH1D* h1D = h2D->ProjectionY( hist_name.c_str(), bin, bin );
106 if( h1D->GetEntries() < 1 ){ continue; }
107
109 T0s.push_back( fitresult->Parameter(1) );
110 Errors.push_back( fitresult->ParError(1) );
111
112
113 out_csv << string_no << "," << ref_floor << "," << tgt_floor << "," << fitresult->Parameter(1) << "," << fitresult->ParError(1) << endl;
114
115 if(!outFile.empty()){
116 h1D->Write();
117 }
118 }
119 }
120
121
122 double weighted_T0 = 0;
123 double Weight;
124 double Sum_of_Weight = 0;
125 for( size_t i = 0, max = T0s.size(); i != max; ++i ){
126 Weight = 1/Errors[i];
127 weighted_T0 += T0s[i]*Weight;
128 Sum_of_Weight += Weight;
129 }
130 if(Sum_of_Weight != 0){
131 weighted_T0 /= Sum_of_Weight;
132 }
133
134
135 map_type::iterator map_iterator = vmap.find(string_no);
136 map_iterator->second[tgt_floor-1] = weighted_T0;
137 }
138 out_csv.close();
139
140
141 for(
int j = 1;
j<=num_of_strings;
j++){
142 map_type::iterator map_iterator = vmap.find(
j);
143
144 int n = map_iterator->second.size();
145 double average =
accumulate( map_iterator->second.begin(), map_iterator->second.end(), 0.0)/
n;
146
147 for(
int j = 0;
j<
n;
j++ ){
148 map_iterator->second[
j] = map_iterator->second[
j] - average;
149 }
150 }
151
152 ofstream out_det(outFile_det.c_str());
153 cout << " Writing det changes to: " << outFile_det << endl;
154 out_det << "String,Floor,T0" << endl;
155
156
157 for(JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module){
158 int string_no = moduleRouter.getModule( module->getID() ).getString();
159 int tgt_floor = moduleRouter.getModule( module->getID() ).getFloor();
160
161 map_type::iterator map_iterator = vmap.find(string_no);
162 double weighted_T0 = map_iterator->second[tgt_floor-1];
163
164 if(overwriteDetector){
166 module->getPMT(pmt).addT0(weighted_T0);
167 }
168 }
169 out_det << string_no << "," << tgt_floor << "," << weighted_T0 << endl;
170 }
171 out_det.close();
172
173 if(overwriteDetector){
174 cout << " Overwriting the detectorfile" << endl;
177 }
178}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Router for direct addressing of module data in detector data structure.
Utility class to parse command line options.
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
static const JStringCounter getNumberOfStrings
Function object to count unique strings.
std::string to_string(const T &value)
Convert value to string.
TFitResultPtr Fit(TH1D *h)
bool comparepair(const pair_type &A, const pair_type &B)
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
std::map< int, range_type > map_type