120{
122
123 std::cout << std::endl;
124 std::cout << std::endl;
125 std::cout << "--- CaloHadDMCoeffMinim::process() --- " << std::endl;
126
127 if(
m_isTestbeam) std::cout <<
"Processing TESTBEAM data" << std::endl;
128
130 std::cout << "Using weighting proportional to E_calib" << std::endl;
133 std::cout << "Using weighting proportional to log(E_calib)" << std::endl;
136 std::cout << "Using weighting proportional to 1/N_Clus_E_calib>0" << std::endl;
138 } else {
139 std::cout << "Using constant weighting" << std::endl;
141 }
142
145
146 m_data->fChain->SetBranchStatus(
"*",0);
147 m_data->fChain->SetBranchStatus(
"mc_ener",1);
148 m_data->fChain->SetBranchStatus(
"mc_eta",1);
149 m_data->fChain->SetBranchStatus(
"mc_phi",1);
150 m_data->fChain->SetBranchStatus(
"mc_pdg",1);
151 m_data->fChain->SetBranchStatus(
"ncls",1);
152 m_data->fChain->SetBranchStatus(
"cls_eta",1);
153 m_data->fChain->SetBranchStatus(
"cls_phi",1);
154 m_data->fChain->SetBranchStatus(
"cls_lambda",1);
155 m_data->fChain->SetBranchStatus(
"cls_calib_emfrac",1);
156 m_data->fChain->SetBranchStatus(
"cls_engcalib",1);
157 m_data->fChain->SetBranchStatus(
"engClusSumCalib",1);
158 m_data->fChain->SetBranchStatus(
"cls_ener_unw",1);
159 m_data->fChain->SetBranchStatus(
"narea",1);
160
161 m_data->fChain->SetBranchStatus(
"cls_dmener",1);
162 m_data->fChain->SetBranchStatus(
"cls_smpener_unw",1);
163
164
165
166 if( !
m_data->GetEntries() ) {
167 std::cout << "CaloHadDMCoeffMinim::process -> Error! No entries in DeadMaterialTree." << std::endl;
168 return nullptr;
169 }
170
173 std::cout << "CaloHadDMCoeffFit::process -> Error! Different numbers of areas for DM definition" << std::endl;
174 std::cout <<
"m_data->m_narea:" <<
m_data->m_narea <<
" m_HadDMCoeff->getSizeAreaSet():" <<
m_HadDMCoeff->getSizeAreaSet() << std::endl;
175 return nullptr;
176 }
177
178
179
181 std::cout <<
"CaloHadDMCoeffMinim::process() -> Info. Preparing for '" << dmArea->
getTitle() <<
" index:" <<
m_area_index
182 <<
" npars:" << dmArea->
getNpars() <<
", for minimization:" <<
m_validNames.size() << std::endl;
184 std::cout << "CaloHadDMCoeffMinim::process() -> FATAL! Number of parameters for dead material area is different from number of mininuit pars." << std::endl;
186 }
187
188
189
190
191
192
193 std::cout << "CaloHadDMCoeffMinim::process() -> Info. Step 2 - making cluster set..." << std::endl;
196 int nGoodEvents = 0;
197 for(
int i_ev=0;
m_data->GetEntry(i_ev)>0;i_ev++) {
198
199
200
201 if(i_ev%20000==0) std::cout <<
" i_ev: " << i_ev <<
" (" << nGoodEvents <<
") '" <<
static_cast<TChain *
>(
m_data->fChain)->GetFile()->GetName() <<
"'" << std::endl;
202
203 double EnergyResolution;
204 if( abs(
m_data->m_mc_pdg) == 211) {
206 } else {
207
209 }
210
211
212 if(isSingleParticle) {
213 bool GoodClusterFound(false);
215 HepLorentzVector hlv_pion(1,0,0,1);
217 for(
int i_cls=0; i_cls<
m_data->m_ncls; i_cls++){
218 HepLorentzVector hlv_cls(1,0,0,1);
219 hlv_cls.setREtaPhi(1./cosh( (*
m_data->m_cls_eta)[i_cls] ), (*
m_data->m_cls_eta)[i_cls], (*
m_data->m_cls_phi)[i_cls]);
220 double r = hlv_pion.angle(hlv_cls.vect());
222 && (*
m_data->m_cls_engcalib)[i_cls] > 20.0*MeV
223
224 ) {
225 GoodClusterFound = true;
226 break;
227 }
228 }
229 }
230 if(!GoodClusterFound) continue;
231 }
232
233 if(
m_data->m_engClusSumCalib <=0.0)
continue;
234
235 for(
int i_cls=0; i_cls<
m_data->m_ncls; i_cls++){
237 || (*
m_data->m_cls_engcalib)[i_cls] < 20.0*MeV
238 ) continue;
239 std::vector<float> vars;
240 m_data->PackClusterVars(i_cls, vars);
242
244 auto ev = std::make_unique<MinimSample>();
245
248 if(
ev->edmtrue<0)
ev->edmtrue=0.0;
249 if(
m_data->m_cls_smpener_unw) {
250 ev->clsm_smp_energy_unw.resize((*
m_data->m_cls_smpener_unw)[i_cls].size());
251 for(
unsigned int i_smp=0; i_smp<(*
m_data->m_cls_smpener_unw)[i_cls].size(); i_smp++){
252 ev->clsm_smp_energy_unw[i_smp] = (*
m_data->m_cls_smpener_unw)[i_cls][i_smp];
253 }
254 }
255
256 double clus_weight = 1.0;
258 clus_weight = (*
m_data->m_cls_engcalib)[i_cls]/
m_data->m_engClusSumCalib;
259 }
260 ev->weight = clus_weight;
261
262
263 ev->sigma2 = EnergyResolution*EnergyResolution;
266 }
267 }
268
269 nGoodEvents++;
270 }
271
272
273
274
275
276 std::cout <<
"CaloHadDMCoeffMinim::process() -> Info. Starting minimization, m_minimSample.size(): " <<
m_minimSample.size() <<
"( " <<
float(
m_minimSample.size())*(26.0/1
e+06) <<
" Mb)"<< std::endl;
277 for(
int i_data=0; i_data<dmArea->
getLength(); i_data++) {
279 mb.Start(
"minuitperf");
286 }
287 }
288
289 std::vector<int > indexes;
291 std::cout << "==============================================================================" << std::endl;
292 std::cout << "run " << i_data
302 << std::endl;
303
304
307
315 }else{
316
322 }
323
324
326 bool fixIt = true;
328 if(name ==
par.name) {
329 fixIt = false;
330 break;
331 }
332 }
334 }
335
336 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
339 }
340
341
343
344 TVirtualFitter::SetDefaultFitter("Minuit");
345 TVirtualFitter * minuit = TVirtualFitter::Fitter(
nullptr,
m_minimPars.size());
346 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
348 minuit->SetParameter(i_par,
par->name.c_str(),
par->initVal,
par->initErr,
par->lowerLim,
par->upperLim);
349 if(
par->fixIt ) minuit->FixParameter(i_par);
350 }
353 double arglist[100];
354 arglist[0] = 0;
355
356 minuit->ExecuteCommand("SET PRINT",arglist,2);
357
358 arglist[0] = 2000;
359 arglist[1] = 0.001;
360
361 minuit->ExecuteCommand("MIGRAD",arglist,2);
362
363
364 std::cout << "Minuit results:" << std::endl;
365 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
366 m_minimPars[i_par].value = minuit->GetParameter(i_par);
367 m_minimPars[i_par].error = minuit->GetParError(i_par);
368 std::cout <<
" i_par:" << i_par <<
" '" <<
m_minimPars[i_par].name <<
"' val:" << minuit->GetParameter(i_par) <<
" err:" << minuit->GetParError(i_par) << std::endl;
369 }
370 delete minuit;
371 }
372
374 mb.Stop(
"minuitperf");
375 std::cout <<
"CPU: " <<
mb.GetCpuTime(
"minuitperf") << std::endl;
376 }
377
378
379
380
381
382 std::cout << "CaloHadDMCoeffMinim::process() -> Info. Making output coefficients set " << std::endl;
383 CaloLocalHadCoeff *newHadDMCoeff =
new CaloLocalHadCoeff(*
m_HadDMCoeff);
384 for (std::pair<
const int, std::vector<MinimPar > >& p :
m_minimResults) {
386
390 boost::io::ios_base_all_saver coutsave (std::cout);
391 std::cout << std::fixed << std::setprecision(3) << iBin << " ";
392 for(
unsigned int i_par = 0; i_par<
m_minimPars.size(); i_par++){
396 }
397 std::cout << std::endl;
398
400 std::vector<int > indexes;
405 if( (fabs(
eta)>2.9 && fabs(
eta)<3.15)) {
406
407
408 pars[CaloSampling::EME2] *= 0.98;
409 }
410 if( fabs(
eta) > 3.25) {
411
412
413 pars[CaloSampling::FCAL0] *= 0.95;
414 }
415 }
416 }
417
418 newHadDMCoeff->
setCoeff(iBin, pars);
419 }
420
421 return newHadDMCoeff;
422}
Scalar eta() const
pseudorapidity method
constexpr int pow(int base, int exp) noexcept
std::vector< std::string > m_validNames
static void fcnWrapper(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
int getLength() const
return area length
const std::string & getTitle() const
return name
int getNpars() const
return number of parameters
void setCoeff(const int iBin, const LocalHadCoeff &theCoeff)
set new data
std::vector< float > LocalHadCoeff
Correction parameters for one general bin.
static double angle_mollier_factor(double x)
const double mb
1mb to cm2