119{
121
122 std::cout << std::endl;
123 std::cout << std::endl;
124 std::cout << "--- CaloHadDMCoeffMinim::process() --- " << std::endl;
125
126 if(
m_isTestbeam) std::cout <<
"Processing TESTBEAM data" << std::endl;
127
129 std::cout << "Using weighting proportional to E_calib" << std::endl;
132 std::cout << "Using weighting proportional to log(E_calib)" << std::endl;
135 std::cout << "Using weighting proportional to 1/N_Clus_E_calib>0" << std::endl;
137 } else {
138 std::cout << "Using constant weighting" << std::endl;
140 }
141
144
145 m_data->fChain->SetBranchStatus(
"*",0);
146 m_data->fChain->SetBranchStatus(
"mc_ener",1);
147 m_data->fChain->SetBranchStatus(
"mc_eta",1);
148 m_data->fChain->SetBranchStatus(
"mc_phi",1);
149 m_data->fChain->SetBranchStatus(
"mc_pdg",1);
150 m_data->fChain->SetBranchStatus(
"ncls",1);
151 m_data->fChain->SetBranchStatus(
"cls_eta",1);
152 m_data->fChain->SetBranchStatus(
"cls_phi",1);
153 m_data->fChain->SetBranchStatus(
"cls_lambda",1);
154 m_data->fChain->SetBranchStatus(
"cls_calib_emfrac",1);
155 m_data->fChain->SetBranchStatus(
"cls_engcalib",1);
156 m_data->fChain->SetBranchStatus(
"engClusSumCalib",1);
157 m_data->fChain->SetBranchStatus(
"cls_ener_unw",1);
158 m_data->fChain->SetBranchStatus(
"narea",1);
159
160 m_data->fChain->SetBranchStatus(
"cls_dmener",1);
161 m_data->fChain->SetBranchStatus(
"cls_smpener_unw",1);
162
163
164
165 if( !
m_data->GetEntries() ) {
166 std::cout << "CaloHadDMCoeffMinim::process -> Error! No entries in DeadMaterialTree." << std::endl;
167 return nullptr;
168 }
169
172 std::cout << "CaloHadDMCoeffFit::process -> Error! Different numbers of areas for DM definition" << std::endl;
173 std::cout <<
"m_data->m_narea:" <<
m_data->m_narea <<
" m_HadDMCoeff->getSizeAreaSet():" <<
m_HadDMCoeff->getSizeAreaSet() << std::endl;
174 return nullptr;
175 }
176
177
178
180 std::cout <<
"CaloHadDMCoeffMinim::process() -> Info. Preparing for '" << dmArea->
getTitle() <<
" index:" <<
m_area_index
181 <<
" npars:" << dmArea->
getNpars() <<
", for minimization:" <<
m_validNames.size() << std::endl;
183 std::cout << "CaloHadDMCoeffMinim::process() -> FATAL! Number of parameters for dead material area is different from number of mininuit pars." << std::endl;
185 }
186
187
188
189
190
191
192 std::cout << "CaloHadDMCoeffMinim::process() -> Info. Step 2 - making cluster set..." << std::endl;
195 int nGoodEvents = 0;
196 for(
int i_ev=0;
m_data->GetEntry(i_ev)>0;i_ev++) {
197
198
199
200 if(i_ev%20000==0) std::cout <<
" i_ev: " << i_ev <<
" (" << nGoodEvents <<
") '" <<
static_cast<TChain *
>(
m_data->fChain)->GetFile()->GetName() <<
"'" << std::endl;
201
202 double EnergyResolution;
203 if( abs(
m_data->m_mc_pdg) == 211) {
205 } else {
206
208 }
209
210
211 if(isSingleParticle) {
212 bool GoodClusterFound(false);
214 HepLorentzVector hlv_pion(1,0,0,1);
216 for(
int i_cls=0; i_cls<
m_data->m_ncls; i_cls++){
217 HepLorentzVector hlv_cls(1,0,0,1);
218 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]);
219 double r = hlv_pion.angle(hlv_cls.vect());
221 && (*
m_data->m_cls_engcalib)[i_cls] > 20.0*
MeV
222
223 ) {
224 GoodClusterFound = true;
225 break;
226 }
227 }
228 }
229 if(!GoodClusterFound) continue;
230 }
231
232 if(
m_data->m_engClusSumCalib <=0.0)
continue;
233
234 for(
int i_cls=0; i_cls<
m_data->m_ncls; i_cls++){
236 || (*
m_data->m_cls_engcalib)[i_cls] < 20.0*
MeV
237 ) continue;
238 std::vector<float> vars;
239 m_data->PackClusterVars(i_cls, vars);
241
243 auto ev = std::make_unique<MinimSample>();
244
247 if(
ev->edmtrue<0)
ev->edmtrue=0.0;
248 if(
m_data->m_cls_smpener_unw) {
249 ev->clsm_smp_energy_unw.resize((*
m_data->m_cls_smpener_unw)[i_cls].size());
250 for(
unsigned int i_smp=0; i_smp<(*
m_data->m_cls_smpener_unw)[i_cls].size(); i_smp++){
251 ev->clsm_smp_energy_unw[i_smp] = (*
m_data->m_cls_smpener_unw)[i_cls][i_smp];
252 }
253 }
254
255 double clus_weight = 1.0;
257 clus_weight = (*
m_data->m_cls_engcalib)[i_cls]/
m_data->m_engClusSumCalib;
258 }
259 ev->weight = clus_weight;
260
261
262 ev->sigma2 = EnergyResolution*EnergyResolution;
265 }
266 }
267
268 nGoodEvents++;
269 }
270
271
272
273
274
275 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;
276 for(
int i_data=0; i_data<dmArea->
getLength(); i_data++) {
278 mb.Start(
"minuitperf");
285 }
286 }
287
288 std::vector<int > indexes;
290 std::cout << "==============================================================================" << std::endl;
291 std::cout << "run " << i_data
301 << std::endl;
302
303
306
314 }else{
315
321 }
322
323
325 bool fixIt = true;
327 if(name ==
par.name) {
328 fixIt = false;
329 break;
330 }
331 }
333 }
334
335 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
338 }
339
340
342
343 TVirtualFitter::SetDefaultFitter("Minuit");
344 TVirtualFitter * minuit = TVirtualFitter::Fitter(
nullptr,
m_minimPars.size());
345 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
347 minuit->SetParameter(i_par,
par->name.c_str(),
par->initVal,
par->initErr,
par->lowerLim,
par->upperLim);
348 if(
par->fixIt ) minuit->FixParameter(i_par);
349 }
352 double arglist[100];
353 arglist[0] = 0;
354
355 minuit->ExecuteCommand("SET PRINT",arglist,2);
356
357 arglist[0] = 2000;
358 arglist[1] = 0.001;
359
360 minuit->ExecuteCommand("MIGRAD",arglist,2);
361
362
363 std::cout << "Minuit results:" << std::endl;
364 for(
unsigned int i_par=0; i_par<
m_minimPars.size(); i_par++){
365 m_minimPars[i_par].value = minuit->GetParameter(i_par);
366 m_minimPars[i_par].error = minuit->GetParError(i_par);
367 std::cout <<
" i_par:" << i_par <<
" '" <<
m_minimPars[i_par].name <<
"' val:" << minuit->GetParameter(i_par) <<
" err:" << minuit->GetParError(i_par) << std::endl;
368 }
369 delete minuit;
370 }
371
373 mb.Stop(
"minuitperf");
374 std::cout <<
"CPU: " <<
mb.GetCpuTime(
"minuitperf") << std::endl;
375 }
376
377
378
379
380
381 std::cout << "CaloHadDMCoeffMinim::process() -> Info. Making output coefficients set " << std::endl;
382 CaloLocalHadCoeff *newHadDMCoeff =
new CaloLocalHadCoeff(*
m_HadDMCoeff);
383 for (std::pair<
const int, std::vector<MinimPar > >& p :
m_minimResults) {
385
389 std::cout << std::format("{:.3f} ", static_cast<double>(iBin));
390 for(
unsigned int i_par = 0; i_par<
m_minimPars.size(); i_par++){
393 std::cout << std::format("({} {:.3f} {:.3f}) ",
397 }
398 std::cout << std::endl;
399
401 std::vector<int > indexes;
406 if( (fabs(
eta)>2.9 && fabs(
eta)<3.15)) {
407
408
409 pars[CaloSampling::EME2] *= 0.98;
410 }
411 if( fabs(
eta) > 3.25) {
412
413
414 pars[CaloSampling::FCAL0] *= 0.95;
415 }
416 }
417 }
418
419 newHadDMCoeff->
setCoeff(iBin, pars);
420 }
421
422 return newHadDMCoeff;
423}
Scalar eta() const
pseudorapidity method
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