12 #include <unordered_map>
15 #include "TLorentzVector.h"
16 #include "TLorentzRotation.h"
28 #include "TGraphErrors.h"
30 #include "RooNumIntConfig.h"
31 #include "RooRealIntegral.h"
37 using namespace RooFit;
40 TString
inputdir_7TeV =
"/work-zfs/lhc/ianderso/hep/CJLST/140519/PRODFSR";
41 TString
inputdir_8TeV =
"/work-zfs/lhc/ianderso/hep/CJLST/140519b/PRODFSR_8TeV";
45 template<
typename T>
void addByLowest(std::vector<T>& valArray, T val,
bool unique){
46 bool inserted =
false;
48 for (
typename std::vector<T>::iterator it = valArray.begin(); it<valArray.end(); it++){
56 for (
typename std::vector<T>::iterator it = valArray.begin(); it<valArray.end(); it++){
59 valArray.insert(it, val);
64 if (!inserted) valArray.push_back(val);
67 template<
typename T,
typename U>
void addByLowest(std::vector<std::pair<T, U>>& valArray, T val, U index){
68 bool inserted =
false;
69 for (
typename std::vector<std::pair<T, U>>::iterator it = valArray.begin(); it<valArray.end(); it++){
70 if ((*it).first>=val){
72 if ((*it).second!=index) valArray.insert(it, std::pair<T, U>(val, index));
76 if (!inserted) valArray.push_back(std::pair<T, U>(val, index));
79 template<
typename T>
void appendVector(std::vector<T>& a, std::vector<T>& b){ a.insert(a.end(), b.begin(), b.end()); }
82 for (
unsigned int v=0; v<list.size(); v++){
83 if (list.at(v)==var)
return true;
89 size_t posEq = rawoption.find(delimiter);
90 if (posEq!=string::npos){
92 value=rawoption.substr(posEq+1);
93 wish.erase(wish.begin()+posEq, wish.end());
101 string suboption=rawoption, result=rawoption;
104 splitOption(suboption, result, remnant, delimiter);
105 if (result!=
"" && !
checkListVariable(splitoptions, result)) splitoptions.push_back(result);
108 if (remnant!=
"") splitoptions.push_back(remnant);
120 void addEvent(
float mass,
float me,
float me2,
float weight=1){
121 masses.push_back(mass);
122 mevals.push_back(
me);
123 me2vals.push_back(me2);
124 weights.push_back(weight);
127 if (masses.size()==0)
return;
129 vector<int> take_out;
130 vector<pair<float, int>> me_entry[2];
131 for (
unsigned int ev=0;
ev<masses.size();
ev++){
132 addByLowest<float, int>(me_entry[0], mevals.at(
ev),
ev);
133 addByLowest<float, int>(me_entry[1], me2vals.at(
ev),
ev);
135 for (
unsigned int im=0; im<2; im++){
136 int at99p8ev = (float(me_entry[im].size()))*0.998;
137 if (at99p8ev==(
int)me_entry[im].size()) at99p8ev--;
138 int bin=me_entry[im].size()-1;
139 while (bin>at99p8ev){
141 me_entry[im].at(at99p8ev).first*2.<me_entry[im].at(bin).first
142 ) addByLowest<int>(take_out, me_entry[im].at(bin).second,
true);
146 for (
int bin=take_out.size()-1; bin>=0; bin--){
147 int t_ev = take_out.at(bin);
148 cout <<
"Discarding event " << events.at(t_ev) << endl;
149 vector<int>::iterator itev;
150 vector<float>::iterator it;
151 itev=events.begin()+t_ev; events.erase(itev);
152 it=masses.begin()+t_ev; masses.erase(it);
153 it=mevals.begin()+t_ev; mevals.erase(it);
154 it=me2vals.begin()+t_ev; me2vals.erase(it);
155 it=weights.begin()+t_ev; weights.erase(it);
159 if (masses.size()==0)
return;
161 vector<pair<float, int>> weight_entry;
162 for (
unsigned int ev=0;
ev<masses.size();
ev++) addByLowest<float, int>(weight_entry, weights.at(
ev),
ev);
163 int bin=weight_entry.size()-1;
165 int at99p0ev = (float(weight_entry.size()))*0.99;
166 if (at99p0ev==(
int)weight_entry.size()) at99p0ev--;
167 float threshold = weight_entry.at(at99p0ev).first;
168 while (bin>at99p0ev){
170 threshold*2.<weight_entry.at(bin).first
172 weights.at(weight_entry.at(bin).second) = pow(threshold, 2)/weight_entry.at(bin).first;
173 cout <<
"Adjusting weight for event " << bin << endl;
178 for (
unsigned int ev=0;
ev<weights.size();
ev++){
179 sum[0] += weights.at(
ev);
182 for (
unsigned int ev=0;
ev<weights.size();
ev++) weights.at(
ev) *= sum[1]/sum[0];
184 for (
unsigned int ev=0;
ev<weights.size();
ev++){
185 if (weights.at(
ev)<=refth)
continue;
186 weights.at(
ev) = pow(refth, 2)/weights.at(
ev);
200 cerr <<
"Size of the following elements are not the same:" << endl;
201 cerr <<
"\t- Events: " << other.
events.size() << endl;
202 cerr <<
"\t- Masses: " << other.
masses.size() << endl;
203 cerr <<
"\t- MEs: " << other.
mevals.size() << endl;
204 cerr <<
"\t- MEs (2): " << other.
me2vals.size() << endl;
205 cerr <<
"\t- Weights: " << other.
weights.size() << endl;
208 events.push_back(other.
events.at(
ev));
216 string strtmp = samplename.Data();
217 std::size_t extpos = strtmp.find(
".root");
218 if (extpos!=string::npos) strtmp.erase(extpos, 5);
219 vector<string> strsplit;
221 if (strsplit.size()>1){
222 string strmass = strsplit.at(1);
225 strmass = strsplit.at(0);
226 mass = std::stod(strmass);
230 TTree*
findTree(vector<TTree*> treeList,
int evid){
232 for (
unsigned int t=0; t<treeList.size(); t++){
233 TTree* tree = treeList.at(t);
234 int nevts = tree->GetEntries();
235 if (
ev<nevts)
return tree;
237 if (
ev<0) cerr <<
"findTree::ERROR: Could not find the event " << evid << endl;
243 for (
unsigned int t=0; t<treeList.size(); t++){
244 TTree* tree = treeList.at(t);
245 if (tree==0) cerr <<
"Something went wrong in getEntry. Tree = " << tree << endl;
246 int nevts = tree->GetEntries();
247 if (
ev<nevts){ tree->GetEntry(
ev);
break; }
249 if (
ev<0) cerr <<
"findTree::ERROR: Could not find the event " << evid << endl;
254 vector<TString> samples;
255 if (strsample==
"JJVBF"){
257 samples.push_back(
"HZZ4lTree_VBFH116.root");
258 samples.push_back(
"HZZ4lTree_VBFH117.root");
259 samples.push_back(
"HZZ4lTree_VBFH118.root");
260 samples.push_back(
"HZZ4lTree_VBFH119.root");
261 samples.push_back(
"HZZ4lTree_VBFH120.root");
262 samples.push_back(
"HZZ4lTree_VBFH121.root");
263 samples.push_back(
"HZZ4lTree_VBFH122.root");
264 samples.push_back(
"HZZ4lTree_VBFH123.root");
265 samples.push_back(
"HZZ4lTree_VBFH124.root");
266 samples.push_back(
"HZZ4lTree_VBFH125.root");
267 samples.push_back(
"HZZ4lTree_VBFH126.root");
268 samples.push_back(
"HZZ4lTree_VBFH127.root");
269 samples.push_back(
"HZZ4lTree_VBFH128.root");
270 samples.push_back(
"HZZ4lTree_VBFH129.root");
271 samples.push_back(
"HZZ4lTree_VBFH130.root");
272 samples.push_back(
"HZZ4lTree_VBFH135.root");
273 samples.push_back(
"HZZ4lTree_VBFH140.root");
274 samples.push_back(
"HZZ4lTree_VBFH145.root");
275 samples.push_back(
"HZZ4lTree_VBFH150.root");
276 samples.push_back(
"HZZ4lTree_VBFH160.root");
277 samples.push_back(
"HZZ4lTree_VBFH170.root");
278 samples.push_back(
"HZZ4lTree_VBFH180.root");
279 samples.push_back(
"HZZ4lTree_VBFH190.root");
280 samples.push_back(
"HZZ4lTree_powheg15VBFH200.root");
281 samples.push_back(
"HZZ4lTree_powheg15VBFH225.root");
282 samples.push_back(
"HZZ4lTree_powheg15VBFH250.root");
283 samples.push_back(
"HZZ4lTree_powheg15VBFH275.root");
284 samples.push_back(
"HZZ4lTree_powheg15VBFH300.root");
285 samples.push_back(
"HZZ4lTree_powheg15VBFH350.root");
286 samples.push_back(
"HZZ4lTree_powheg15VBFH400.root");
287 samples.push_back(
"HZZ4lTree_powheg15VBFH450.root");
288 samples.push_back(
"HZZ4lTree_powheg15VBFH500.root");
289 samples.push_back(
"HZZ4lTree_powheg15VBFH550.root");
290 samples.push_back(
"HZZ4lTree_powheg15VBFH600.root");
291 samples.push_back(
"HZZ4lTree_powheg15VBFH650.root");
292 samples.push_back(
"HZZ4lTree_powheg15VBFH700.root");
293 samples.push_back(
"HZZ4lTree_powheg15VBFH750.root");
294 samples.push_back(
"HZZ4lTree_powheg15VBFH800.root");
295 samples.push_back(
"HZZ4lTree_powheg15VBFH850.root");
296 samples.push_back(
"HZZ4lTree_powheg15VBFH900.root");
297 samples.push_back(
"HZZ4lTree_powheg15VBFH950.root");
298 samples.push_back(
"HZZ4lTree_powheg15VBFH1000.root");
301 samples.push_back(
"VBFH115");
302 samples.push_back(
"VBFH120");
303 samples.push_back(
"VBFH124");
304 samples.push_back(
"VBFH125");
305 samples.push_back(
"VBFH126");
306 samples.push_back(
"VBFH130");
307 samples.push_back(
"VBFH135");
308 samples.push_back(
"VBFH140");
309 samples.push_back(
"VBFH145");
310 samples.push_back(
"VBFH150");
311 samples.push_back(
"VBFH155");
312 samples.push_back(
"VBFH160");
313 samples.push_back(
"VBFH165");
314 samples.push_back(
"VBFH170");
315 samples.push_back(
"VBFH175");
316 samples.push_back(
"VBFH180");
317 samples.push_back(
"VBFH190");
318 samples.push_back(
"VBFH200");
319 samples.push_back(
"VBFH210");
320 samples.push_back(
"VBFH230");
321 samples.push_back(
"VBFH250");
322 samples.push_back(
"VBFH270");
323 samples.push_back(
"VBFH300");
324 samples.push_back(
"VBFH350");
325 samples.push_back(
"VBFH400");
326 samples.push_back(
"VBFH450");
327 samples.push_back(
"VBFH500");
328 samples.push_back(
"VBFH550");
329 samples.push_back(
"VBFH600");
330 samples.push_back(
"VBFH700");
331 samples.push_back(
"VBFH750");
332 samples.push_back(
"VBFH800");
333 samples.push_back(
"VBFH900");
334 samples.push_back(
"VBFH1000");
335 samples.push_back(
"VBFH1500");
336 samples.push_back(
"VBFH2000");
337 samples.push_back(
"VBFH2500");
338 samples.push_back(
"VBFH3000");
341 else if (strsample==
"WH"){
343 samples.push_back(
"HZZ4lTree_WH110.root");
344 samples.push_back(
"HZZ4lTree_WH115.root");
345 samples.push_back(
"HZZ4lTree_WH120.root");
346 samples.push_back(
"HZZ4lTree_WH125.root");
347 samples.push_back(
"HZZ4lTree_WH126.root");
348 samples.push_back(
"HZZ4lTree_WH130.root");
349 samples.push_back(
"HZZ4lTree_WH140.root");
350 samples.push_back(
"HZZ4lTree_WH150.root");
351 samples.push_back(
"HZZ4lTree_WH160.root");
352 samples.push_back(
"HZZ4lTree_WH180.root");
353 samples.push_back(
"HZZ4lTree_WH200.root");
356 samples.push_back(
"WminusH115");
357 samples.push_back(
"WminusH120");
358 samples.push_back(
"WminusH124");
359 samples.push_back(
"WminusH125");
360 samples.push_back(
"WminusH126");
361 samples.push_back(
"WminusH130");
362 samples.push_back(
"WminusH135");
363 samples.push_back(
"WminusH140");
364 samples.push_back(
"WminusH145");
365 samples.push_back(
"WminusH150");
366 samples.push_back(
"WminusH155");
367 samples.push_back(
"WminusH160");
368 samples.push_back(
"WminusH165");
369 samples.push_back(
"WminusH170");
370 samples.push_back(
"WminusH175");
371 samples.push_back(
"WminusH180");
372 samples.push_back(
"WminusH190");
373 samples.push_back(
"WminusH200");
374 samples.push_back(
"WminusH210");
375 samples.push_back(
"WminusH230");
376 samples.push_back(
"WminusH250");
377 samples.push_back(
"WminusH270");
378 samples.push_back(
"WminusH300");
379 samples.push_back(
"WminusH350");
380 samples.push_back(
"WminusH400");
381 samples.push_back(
"WminusH450");
382 samples.push_back(
"WminusH500");
383 samples.push_back(
"WminusH550");
384 samples.push_back(
"WminusH600");
385 samples.push_back(
"WminusH700");
386 samples.push_back(
"WminusH750");
387 samples.push_back(
"WminusH800");
388 samples.push_back(
"WminusH900");
389 samples.push_back(
"WminusH1000");
390 samples.push_back(
"WminusH1500");
391 samples.push_back(
"WminusH2000");
392 samples.push_back(
"WminusH2500");
393 samples.push_back(
"WminusH3000");
394 samples.push_back(
"WplusH115");
395 samples.push_back(
"WplusH120");
396 samples.push_back(
"WplusH124");
397 samples.push_back(
"WplusH125");
398 samples.push_back(
"WplusH126");
399 samples.push_back(
"WplusH130");
400 samples.push_back(
"WplusH135");
401 samples.push_back(
"WplusH140");
402 samples.push_back(
"WplusH145");
403 samples.push_back(
"WplusH150");
404 samples.push_back(
"WplusH155");
405 samples.push_back(
"WplusH160");
406 samples.push_back(
"WplusH165");
407 samples.push_back(
"WplusH170");
408 samples.push_back(
"WplusH175");
409 samples.push_back(
"WplusH180");
410 samples.push_back(
"WplusH190");
411 samples.push_back(
"WplusH200");
412 samples.push_back(
"WplusH210");
413 samples.push_back(
"WplusH230");
414 samples.push_back(
"WplusH250");
415 samples.push_back(
"WplusH270");
416 samples.push_back(
"WplusH300");
417 samples.push_back(
"WplusH350");
418 samples.push_back(
"WplusH400");
419 samples.push_back(
"WplusH450");
420 samples.push_back(
"WplusH500");
421 samples.push_back(
"WplusH550");
422 samples.push_back(
"WplusH600");
423 samples.push_back(
"WplusH700");
424 samples.push_back(
"WplusH750");
425 samples.push_back(
"WplusH800");
426 samples.push_back(
"WplusH900");
427 samples.push_back(
"WplusH1000");
428 samples.push_back(
"WplusH1500");
429 samples.push_back(
"WplusH2000");
430 samples.push_back(
"WplusH2500");
431 samples.push_back(
"WplusH3000");
434 else if (strsample==
"ZH"){
436 samples.push_back(
"HZZ4lTree_ZH110.root");
437 samples.push_back(
"HZZ4lTree_ZH115.root");
438 samples.push_back(
"HZZ4lTree_ZH120.root");
439 samples.push_back(
"HZZ4lTree_ZH125.root");
440 samples.push_back(
"HZZ4lTree_ZH126.root");
441 samples.push_back(
"HZZ4lTree_ZH130.root");
442 samples.push_back(
"HZZ4lTree_ZH140.root");
443 samples.push_back(
"HZZ4lTree_ZH150.root");
444 samples.push_back(
"HZZ4lTree_ZH160.root");
445 samples.push_back(
"HZZ4lTree_ZH180.root");
446 samples.push_back(
"HZZ4lTree_ZH200.root");
449 samples.push_back(
"ZH115");
450 samples.push_back(
"ZH120");
451 samples.push_back(
"ZH124");
452 samples.push_back(
"ZH125");
453 samples.push_back(
"ZH126");
454 samples.push_back(
"ZH130");
455 samples.push_back(
"ZH135");
456 samples.push_back(
"ZH140");
457 samples.push_back(
"ZH145");
458 samples.push_back(
"ZH150");
459 samples.push_back(
"ZH155");
460 samples.push_back(
"ZH160");
461 samples.push_back(
"ZH165");
462 samples.push_back(
"ZH170");
463 samples.push_back(
"ZH175");
464 samples.push_back(
"ZH180");
465 samples.push_back(
"ZH190");
466 samples.push_back(
"ZH200");
467 samples.push_back(
"ZH210");
468 samples.push_back(
"ZH230");
469 samples.push_back(
"ZH250");
470 samples.push_back(
"ZH270");
471 samples.push_back(
"ZH300");
472 samples.push_back(
"ZH350");
473 samples.push_back(
"ZH400");
474 samples.push_back(
"ZH450");
475 samples.push_back(
"ZH500");
476 samples.push_back(
"ZH550");
477 samples.push_back(
"ZH600");
478 samples.push_back(
"ZH700");
479 samples.push_back(
"ZH750");
480 samples.push_back(
"ZH800");
481 samples.push_back(
"ZH900");
482 samples.push_back(
"ZH1000");
483 samples.push_back(
"ZH1500");
484 samples.push_back(
"ZH2000");
485 samples.push_back(
"ZH2500");
486 samples.push_back(
"ZH3000");
489 else if (strsample==
"JJQCD"){
491 samples.push_back(
"HZZ4lTree_minloH90.root");
492 samples.push_back(
"HZZ4lTree_minloH95.root");
493 samples.push_back(
"HZZ4lTree_minloH100.root");
494 samples.push_back(
"HZZ4lTree_minloH105.root");
495 samples.push_back(
"HZZ4lTree_minloH110.root");
496 samples.push_back(
"HZZ4lTree_minloH115.root");
497 samples.push_back(
"HZZ4lTree_minloH120.root");
498 samples.push_back(
"HZZ4lTree_minloH124.root");
499 samples.push_back(
"HZZ4lTree_minloH125.root");
500 samples.push_back(
"HZZ4lTree_minloH126.root");
501 samples.push_back(
"HZZ4lTree_minloH130.root");
502 samples.push_back(
"HZZ4lTree_minloH135.root");
503 samples.push_back(
"HZZ4lTree_minloH140.root");
504 samples.push_back(
"HZZ4lTree_minloH145.root");
505 samples.push_back(
"HZZ4lTree_minloH150.root");
506 samples.push_back(
"HZZ4lTree_minloH155.root");
507 samples.push_back(
"HZZ4lTree_minloH160.root");
508 samples.push_back(
"HZZ4lTree_minloH170.root");
509 samples.push_back(
"HZZ4lTree_minloH180.root");
510 samples.push_back(
"HZZ4lTree_minloH190.root");
511 samples.push_back(
"HZZ4lTree_minloH200.root");
512 samples.push_back(
"HZZ4lTree_minloH250.root");
513 samples.push_back(
"HZZ4lTree_minloH300.root");
514 samples.push_back(
"HZZ4lTree_minloH350.root");
515 samples.push_back(
"HZZ4lTree_minloH400.root");
516 samples.push_back(
"HZZ4lTree_minloH450.root");
517 samples.push_back(
"HZZ4lTree_minloH500.root");
518 samples.push_back(
"HZZ4lTree_minloH550.root");
519 samples.push_back(
"HZZ4lTree_minloH600.root");
520 samples.push_back(
"HZZ4lTree_minloH650.root");
521 samples.push_back(
"HZZ4lTree_minloH700.root");
522 samples.push_back(
"HZZ4lTree_minloH750.root");
523 samples.push_back(
"HZZ4lTree_minloH800.root");
524 samples.push_back(
"HZZ4lTree_minloH850.root");
525 samples.push_back(
"HZZ4lTree_minloH900.root");
526 samples.push_back(
"HZZ4lTree_minloH950.root");
527 samples.push_back(
"HZZ4lTree_minloH1000.root");
530 samples.push_back(
"ggH115");
531 samples.push_back(
"ggH120");
532 samples.push_back(
"ggH124");
533 samples.push_back(
"ggH125");
534 samples.push_back(
"ggH126");
535 samples.push_back(
"ggH130");
536 samples.push_back(
"ggH135");
537 samples.push_back(
"ggH140");
538 samples.push_back(
"ggH145");
539 samples.push_back(
"ggH150");
540 samples.push_back(
"ggH155");
541 samples.push_back(
"ggH160");
542 samples.push_back(
"ggH165");
543 samples.push_back(
"ggH170");
544 samples.push_back(
"ggH175");
545 samples.push_back(
"ggH180");
546 samples.push_back(
"ggH190");
547 samples.push_back(
"ggH200");
548 samples.push_back(
"ggH210");
549 samples.push_back(
"ggH230");
550 samples.push_back(
"ggH250");
551 samples.push_back(
"ggH270");
552 samples.push_back(
"ggH300");
553 samples.push_back(
"ggH350");
554 samples.push_back(
"ggH400");
555 samples.push_back(
"ggH450");
556 samples.push_back(
"ggH500");
557 samples.push_back(
"ggH550");
558 samples.push_back(
"ggH600");
559 samples.push_back(
"ggH700");
560 samples.push_back(
"ggH750");
561 samples.push_back(
"ggH800");
562 samples.push_back(
"ggH900");
563 samples.push_back(
"ggH1000");
564 samples.push_back(
"ggH1500");
565 samples.push_back(
"ggH2000");
566 samples.push_back(
"ggH2500");
567 samples.push_back(
"ggH3000");
570 else if (strsample==
"gg_Sig_JHUGen"){
572 samples.push_back(
"HZZ4lTree_jhuGenV4-H91.2.root");
573 samples.push_back(
"HZZ4lTree_powheg15jhuGenV3-0PMH125.6.root");
578 else if (strsample==
"gg_Sig_MCFM"){
580 samples.push_back(
"HZZ4lTree_ggTo4mu_SMH-MCFM67_H125.6.root");
581 samples.push_back(
"HZZ4lTree_ggTo4e_SMH-MCFM67_H125.6.root");
582 samples.push_back(
"HZZ4lTree_ggTo2e2mu_SMH-MCFM67_H125.6.root");
585 samples.push_back(
"ggTo4mu_0PMH125_MCFM701");
586 samples.push_back(
"ggTo4e_0PMH125_MCFM701");
587 samples.push_back(
"ggTo2e2mu_0PMH125_MCFM701");
588 samples.push_back(
"ggTo2e2tau_0PMH125_MCFM701");
589 samples.push_back(
"ggTo2mu2tau_0PMH125_MCFM701");
590 samples.push_back(
"ggTo4tau_0PMH125_MCFM701");
593 else if (strsample==
"gg_Bkg_MCFM"){
595 samples.push_back(
"HZZ4lTree_ggTo2e2mu_Contin-MCFM67.root");
596 samples.push_back(
"HZZ4lTree_ggTo4mu_Contin-MCFM67.root");
597 samples.push_back(
"HZZ4lTree_ggTo4e_Contin-MCFM67.root");
600 samples.push_back(
"ggTo4mu_Contin_MCFM701");
601 samples.push_back(
"ggTo4e_Contin_MCFM701");
602 samples.push_back(
"ggTo2e2mu_Contin_MCFM701");
603 samples.push_back(
"ggTo2e2tau_Contin_MCFM701");
604 samples.push_back(
"ggTo2mu2tau_Contin_MCFM701");
605 samples.push_back(
"ggTo4tau_Contin_MCFM701");
608 else if (strsample==
"gg_Sig_ggVV"){
610 samples.push_back(
"HZZ4lTree_ggTo2l2l_H125.6.root");
611 samples.push_back(
"HZZ4lTree_ggTo4l_H125.6.root");
616 else if (strsample==
"gg_Bkg_ggVV"){
618 samples.push_back(
"HZZ4lTree_ggTo4l_Continuum.root");
619 samples.push_back(
"HZZ4lTree_ggZZ4l.root");
620 samples.push_back(
"HZZ4lTree_ggTo2l2l_Continuum.root");
621 samples.push_back(
"HZZ4lTree_ggZZ2l2l.root");
626 else if (strsample==
"VV_Sig_MCFM"){
630 samples.push_back(
"VBFTo2e2muJJ_0PMH125_phantom128");
631 samples.push_back(
"VBFTo4muJJ_0PMH125_phantom128");
632 samples.push_back(
"VBFTo4eJJ_0PMH125_phantom128");
635 else if (strsample==
"VV_Bkg_MCFM"){
639 samples.push_back(
"VBFTo2e2muJJ_Contin_phantom128");
640 samples.push_back(
"VBFTo4muJJ_Contin_phantom128");
641 samples.push_back(
"VBFTo4eJJ_Contin_phantom128");
644 else if (strsample==
"qq_Bkg"){
646 samples.push_back(
"HZZ4lTree_ZZTo2e2mu.root");
647 samples.push_back(
"HZZ4lTree_ZZTo2e2tau.root");
648 samples.push_back(
"HZZ4lTree_ZZTo2mu2tau.root");
649 samples.push_back(
"HZZ4lTree_ZZTo4mu.root");
650 samples.push_back(
"HZZ4lTree_ZZTo4e.root");
651 samples.push_back(
"HZZ4lTree_ZZTo4tau.root");
652 samples.push_back(
"HZZ4lTree_ZZ95-160To2e2mu.root");
653 samples.push_back(
"HZZ4lTree_ZZ95-160To2e2tau.root");
654 samples.push_back(
"HZZ4lTree_ZZ95-160To2mu2tau.root");
655 samples.push_back(
"HZZ4lTree_ZZ95-160To4mu.root");
656 samples.push_back(
"HZZ4lTree_ZZ95-160To4e.root");
657 samples.push_back(
"HZZ4lTree_ZZ95-160To4tau.root");
660 samples.push_back(
"ZZTo4l");
661 samples.push_back(
"ZZTo4l_ext");
676 TString TREE_NAME =
"SelectedTree";
677 bool writeFinalTree=
true;
680 Mela mela(erg_tev, mPOLE, verbosity);
691 std::vector<double>* JetPt=0;
692 std::vector<double>* JetEta=0;
693 std::vector<double>* JetPhi=0;
694 std::vector<double>* JetMass=0;
695 std::vector<double> myJetPt;
696 std::vector<double> myJetEta;
697 std::vector<double> myJetPhi;
698 std::vector<double> myJetMass;
703 float jetptetaphimass[2][4];
705 float mesq_conserveDifermMass=0;
706 float mesq_jetPtoEScale=0;
708 float m1 = 91.471450;
709 float m2 = 12.139782;
710 float h1 = 0.2682896;
711 float h2 = 0.1679779;
712 float phi = 1.5969792;
713 float hs = -0.727181;
714 float phi1 = 1.8828257;
715 float ZZPt, ZZPhi, ZZEta;
716 int LepID[4]={ 13, -13, 11, -11 };
717 short Z1Flav, Z2Flav;
719 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
727 vector<TFile*> finputList;
728 vector<TTree*> treeList;
731 for (
int is=0; is<(
int)strSamples.size(); is++){
732 for (
int ic=0; ic<3; ic++){
733 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples[is]).Data());
734 TFile* finput = TFile::Open(cinput,
"read");
735 cout <<
"Opening file " << cinput <<
"..." << endl;
738 if (finput->IsOpen() && !finput->IsZombie()){
739 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
740 tree = (TTree*)finput->Get(TREE_NAME);
742 cout << TREE_NAME <<
" is found." << endl;
743 tree->SetBranchStatus(
"*", 0);
744 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
745 tree->SetBranchStatus(
"ZZPt", 1); tree->SetBranchAddress(
"ZZPt", &ZZPt);
746 tree->SetBranchStatus(
"ZZEta", 1); tree->SetBranchAddress(
"ZZEta", &ZZEta);
747 tree->SetBranchStatus(
"ZZPhi", 1); tree->SetBranchAddress(
"ZZPhi", &ZZPhi);
748 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
749 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
750 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
751 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
752 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
753 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
754 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
755 tree->SetBranchStatus(
"NJets30", 1); tree->SetBranchAddress(
"NJets30", &NJets30);
756 tree->SetBranchStatus(
"JetPt", 1); tree->SetBranchAddress(
"JetPt", &JetPt);
757 tree->SetBranchStatus(
"JetEta", 1); tree->SetBranchAddress(
"JetEta", &JetEta);
758 tree->SetBranchStatus(
"JetPhi", 1); tree->SetBranchAddress(
"JetPhi", &JetPhi);
759 tree->SetBranchStatus(
"JetMass", 1); tree->SetBranchAddress(
"JetMass", &JetMass);
761 nEntries += tree->GetEntries();
762 treeList.push_back(tree);
763 finputList.push_back(finput);
765 else finput->Close();
767 else if (finput->IsOpen()) finput->Close();
772 const int nSamples = treeList.size();
774 cout <<
"NEntries = " << nEntries <<
" over " << treeList.size() <<
" trees." << endl;
776 vector<pair<float, int>> index;
777 unsigned int ev_acc=0;
778 for (
int ev=0;
ev<nEntries;
ev++){
780 if (NJets30<2)
continue;
781 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
786 float firstVal=index.at(0).first;
787 float lastVal=index.at(index.size()-1).first;
788 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
789 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
790 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
793 int nbins = index.size()/divisor;
794 const int nbins_th=10;
795 while (nbins<nbins_th){
796 if (divisor>1000) divisor -= 1000;
797 else if (divisor>100) divisor -= 100;
799 nbins=index.size()/divisor;
801 cout <<
"nbins=" << nbins << endl;
802 if (nbins<3) cerr <<
"Not enough bins!" << endl;
803 vector<ExtBin> binList;
804 float* binning =
new float[nbins+1];
806 binning[nbins]=supremum;
807 int ev_stepsize = index.size()/nbins;
808 cout <<
"Event step size: " << ev_stepsize << endl;
809 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
810 for (
int ix=1; ix<nbins; ix++){
811 binning[ix]=(index[ix*ev_stepsize-1].first+index[ix*ev_stepsize].first)*0.5;
813 tmpbin.
binlow = binning[ix-1];
815 for (
int bin=0; bin<ev_stepsize; bin++) tmpbin.
events.push_back(index[(ix-1)*ev_stepsize+bin].second);
816 binList.push_back(tmpbin);
817 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
820 tmpbin.
binlow = binning[nbins-1];
821 tmpbin.
binhigh = binning[nbins];
822 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index.size(); bin++) tmpbin.
events.push_back(index[bin].second);
823 binList.push_back(tmpbin);
824 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
825 cout <<
"Bin list has the following bins:" << endl;
826 for (
unsigned int ib=0; ib<binList.size(); ib++){
827 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
830 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
832 TProfile* hvar =
new TProfile(
"candMass",
"", nbins, binning); hvar->Sumw2();
833 TProfile* hmesq_conserveDifermMass =
new TProfile(
"P_ConserveDifermionMass",
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
834 TProfile* hmesq_jetPtoEScale =
new TProfile(
"P_MomentumToEnergy",
"", nbins, binning); hmesq_jetPtoEScale->Sumw2();
838 newtree =
new TTree(
"FinalTree",
"");
839 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
840 newtree->Branch(
"mesq_jetPtoEScale", &mesq_jetPtoEScale);
841 newtree->Branch(
"ZZMass", &mzz);
846 for (
unsigned int bin=0; bin<binList.size(); bin++){
847 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
848 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
849 int getEv = binList.at(bin).events.at(
ev);
851 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
852 if (JetPt->size()<2 || JetEta->size()<2 || JetPhi->size()<2 || JetMass->size()<2){
853 cerr <<
"Jet array sizes are less than Njets!" << endl;
857 TLorentzVector jet[2], higgs;
858 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(jetptetaphimass[ij][0], jetptetaphimass[ij][1], jetptetaphimass[ij][2], jetptetaphimass[ij][3]);
859 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
860 TVector3 boostH = higgs.BoostVector();
866 TLorentzVector pDaughters[4];
867 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
868 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); pDaughters[ip].Boost(boostH); }
876 mela.computeProdP(mesq_conserveDifermMass,
false);
878 mela.computeProdP(mesq_jetPtoEScale,
false);
881 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
883 isnan(mesq_jetPtoEScale) || isinf(mesq_jetPtoEScale)
886 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, mesq_jetPtoEScale);
888 mela.resetInputEvent();
891 binList.at(bin).sift(); binList.at(bin).adjustWeights();
893 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
894 mzz = binList.at(bin).masses.at(
ev);
895 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
896 mesq_jetPtoEScale = binList.at(bin).me2vals.at(
ev);
897 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
898 hmesq_jetPtoEScale->Fill(mzz, mesq_jetPtoEScale);
899 hvar->Fill(mzz, mzz);
900 if (writeFinalTree) newtree->Fill();
904 double* xexyey[2][4];
905 for (
int inorm=0; inorm<2; inorm++){
906 for (
int ix=0; ix<4; ix++) xexyey[inorm][ix] =
new double[nbins];
907 for (
int bin=0; bin<nbins; bin++){
908 xexyey[inorm][0][bin] = hvar->GetBinContent(bin+1);
909 xexyey[inorm][1][bin] = hvar->GetBinError(bin+1);
911 if (inorm==0)
cout <<
"Bin " << bin <<
" x-center: " << xexyey[inorm][0][bin] <<
" +- " << xexyey[inorm][1][bin] << endl;
914 xexyey[inorm][2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
915 xexyey[inorm][3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
918 xexyey[inorm][2][bin] = hmesq_jetPtoEScale->GetBinContent(bin+1);
919 xexyey[inorm][3][bin] = hmesq_jetPtoEScale->GetBinError(bin+1);
921 xexyey[inorm][3][bin] = log10(xexyey[inorm][3][bin])/xexyey[inorm][2][bin];
922 xexyey[inorm][2][bin] = log10(xexyey[inorm][2][bin]);
926 for (
int inorm=0; inorm<2; inorm++){
927 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[inorm][0], xexyey[inorm][2], xexyey[inorm][1], xexyey[inorm][3]);
928 if (inorm==0) tg->SetName(
"tg_P_ConserveDifermionMass");
929 else tg->SetName(
"tg_P_MomentumToEnergy");
930 foutput->WriteTObject(tg);
934 for (
int inorm=0; inorm<2; inorm++){
935 for (
int ix=0; ix<4; ix++)
delete[] xexyey[inorm][ix];
937 foutput->WriteTObject(hmesq_jetPtoEScale);
938 foutput->WriteTObject(hmesq_conserveDifermMass);
939 foutput->WriteTObject(hvar);
940 if (writeFinalTree) foutput->WriteTObject(newtree);
941 if (writeFinalTree)
delete newtree;
942 delete hmesq_conserveDifermMass;
943 delete hmesq_jetPtoEScale;
947 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
968 TString TREE_NAME =
"SelectedTree";
969 bool writeFinalTree=
true;
972 Mela mela(erg_tev, mPOLE, verbosity);
983 std::vector<double>* JetPt=0;
984 std::vector<double>* JetEta=0;
985 std::vector<double>* JetPhi=0;
986 std::vector<double>* JetMass=0;
987 std::vector<double> myJetPt;
988 std::vector<double> myJetEta;
989 std::vector<double> myJetPhi;
990 std::vector<double> myJetMass;
995 float jetptetaphimass[2][4];
997 float mesq_conserveDifermMass=0;
998 float mesq_jetPtoEScale=0;
1000 float m1 = 91.471450;
1001 float m2 = 12.139782;
1002 float h1 = 0.2682896;
1003 float h2 = 0.1679779;
1004 float phi = 1.5969792;
1005 float hs = -0.727181;
1006 float phi1 = 1.8828257;
1007 float ZZPt, ZZPhi, ZZEta;
1008 int LepID[4]={ 13, -13, 11, -11 };
1009 short Z1Flav, Z2Flav;
1011 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
1012 TString cinput_main;
1019 vector<TFile*> finputList;
1020 vector<TTree*> treeList;
1023 for (
int is=0; is<(
int)strSamples.size(); is++){
1024 for (
int ic=0; ic<3; ic++){
1025 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples[is]).Data());
1026 TFile* finput = TFile::Open(cinput,
"read");
1027 cout <<
"Opening file " << cinput <<
"..." << endl;
1030 if (finput->IsOpen() && !finput->IsZombie()){
1031 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
1032 tree = (TTree*)finput->Get(TREE_NAME);
1034 cout << TREE_NAME <<
" is found." << endl;
1035 tree->SetBranchStatus(
"*", 0);
1036 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
1037 tree->SetBranchStatus(
"ZZPt", 1); tree->SetBranchAddress(
"ZZPt", &ZZPt);
1038 tree->SetBranchStatus(
"ZZEta", 1); tree->SetBranchAddress(
"ZZEta", &ZZEta);
1039 tree->SetBranchStatus(
"ZZPhi", 1); tree->SetBranchAddress(
"ZZPhi", &ZZPhi);
1040 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
1041 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
1042 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
1043 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
1044 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
1045 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
1046 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
1047 tree->SetBranchStatus(
"NJets30", 1); tree->SetBranchAddress(
"NJets30", &NJets30);
1048 tree->SetBranchStatus(
"JetPt", 1); tree->SetBranchAddress(
"JetPt", &JetPt);
1049 tree->SetBranchStatus(
"JetEta", 1); tree->SetBranchAddress(
"JetEta", &JetEta);
1050 tree->SetBranchStatus(
"JetPhi", 1); tree->SetBranchAddress(
"JetPhi", &JetPhi);
1051 tree->SetBranchStatus(
"JetMass", 1); tree->SetBranchAddress(
"JetMass", &JetMass);
1053 nEntries += tree->GetEntries();
1054 treeList.push_back(tree);
1055 finputList.push_back(finput);
1057 else finput->Close();
1059 else if (finput->IsOpen()) finput->Close();
1064 const int nSamples = treeList.size();
1066 cout <<
"NEntries = " << nEntries <<
" over " << treeList.size() <<
" trees." << endl;
1068 vector<pair<float, int>> index;
1069 unsigned int ev_acc=0;
1070 for (
int ev=0;
ev<nEntries;
ev++){
1072 if (NJets30<2)
continue;
1073 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
1078 float firstVal=index.at(0).first;
1079 float lastVal=index.at(index.size()-1).first;
1080 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
1081 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
1082 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
1084 float divisor=85000;
1085 int nbins = index.size()/divisor;
1086 const int nbins_th=10;
1087 while (nbins<nbins_th){
1088 if (divisor>1000) divisor -= 1000;
1089 else if (divisor>100) divisor -= 100;
1091 nbins=index.size()/divisor;
1093 cout <<
"nbins=" << nbins << endl;
1094 if (nbins<3) cerr <<
"Not enough bins!" << endl;
1095 vector<ExtBin> binList;
1096 float* binning =
new float[nbins+1];
1098 binning[nbins]=supremum;
1099 int ev_stepsize = index.size()/nbins;
1100 cout <<
"Event step size: " << ev_stepsize << endl;
1101 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
1102 for (
int ix=1; ix<nbins; ix++){
1103 binning[ix]=(index[ix*ev_stepsize-1].first+index[ix*ev_stepsize].first)*0.5;
1105 tmpbin.
binlow = binning[ix-1];
1107 for (
int bin=0; bin<ev_stepsize; bin++) tmpbin.
events.push_back(index[(ix-1)*ev_stepsize+bin].second);
1108 binList.push_back(tmpbin);
1109 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
1112 tmpbin.
binlow = binning[nbins-1];
1113 tmpbin.
binhigh = binning[nbins];
1114 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index.size(); bin++) tmpbin.
events.push_back(index[bin].second);
1115 binList.push_back(tmpbin);
1116 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
1117 cout <<
"Bin list has the following bins:" << endl;
1118 for (
unsigned int ib=0; ib<binList.size(); ib++){
1119 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
1122 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
1124 TProfile* hvar =
new TProfile(
"candMass",
"", nbins, binning); hvar->Sumw2();
1125 TProfile* hmesq_conserveDifermMass =
new TProfile(
"P_ConserveDifermionMass",
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
1126 TProfile* hmesq_jetPtoEScale =
new TProfile(
"P_MomentumToEnergy",
"", nbins, binning); hmesq_jetPtoEScale->Sumw2();
1129 if (writeFinalTree){
1130 newtree =
new TTree(
"FinalTree",
"");
1131 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
1132 newtree->Branch(
"mesq_jetPtoEScale", &mesq_jetPtoEScale);
1133 newtree->Branch(
"ZZMass", &mzz);
1138 for (
unsigned int bin=0; bin<binList.size(); bin++){
1139 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
1140 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
1141 int getEv = binList.at(bin).events.at(
ev);
1143 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
1144 if (JetPt->size()<2 || JetEta->size()<2 || JetPhi->size()<2 || JetMass->size()<2){
1145 cerr <<
"Jet array sizes are less than Njets!" << endl;
1149 TLorentzVector jet[2], higgs;
1150 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(jetptetaphimass[ij][0], jetptetaphimass[ij][1], jetptetaphimass[ij][2], jetptetaphimass[ij][3]);
1151 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
1152 TVector3 boostH = higgs.BoostVector();
1158 TLorentzVector pDaughters[4];
1159 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
1160 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); pDaughters[ip].Boost(boostH); }
1170 mela.computeProdP(mesq_conserveDifermMass,
false);
1171 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
1172 mesq_conserveDifermMass /= pow(alphasVal, 4);
1175 mela.computeProdP(mesq_jetPtoEScale,
false);
1176 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
1177 mesq_jetPtoEScale /= pow(alphasVal, 4);
1180 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
1182 isnan(mesq_jetPtoEScale) || isinf(mesq_jetPtoEScale)
1185 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, mesq_jetPtoEScale);
1187 mela.resetInputEvent();
1190 binList.at(bin).sift(); binList.at(bin).adjustWeights();
1192 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
1193 mzz = binList.at(bin).masses.at(
ev);
1194 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
1195 mesq_jetPtoEScale = binList.at(bin).me2vals.at(
ev);
1196 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
1197 hmesq_jetPtoEScale->Fill(mzz, mesq_jetPtoEScale);
1198 hvar->Fill(mzz, mzz);
1199 if (writeFinalTree) newtree->Fill();
1203 double* xexyey[2][4];
1204 for (
int inorm=0; inorm<2; inorm++){
1205 for (
int ix=0; ix<4; ix++) xexyey[inorm][ix] =
new double[nbins];
1206 for (
int bin=0; bin<nbins; bin++){
1207 xexyey[inorm][0][bin] = hvar->GetBinContent(bin+1);
1208 xexyey[inorm][1][bin] = hvar->GetBinError(bin+1);
1210 if (inorm==0)
cout <<
"Bin " << bin <<
" x-center: " << xexyey[inorm][0][bin] <<
" +- " << xexyey[inorm][1][bin] << endl;
1213 xexyey[inorm][2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
1214 xexyey[inorm][3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
1217 xexyey[inorm][2][bin] = hmesq_jetPtoEScale->GetBinContent(bin+1);
1218 xexyey[inorm][3][bin] = hmesq_jetPtoEScale->GetBinError(bin+1);
1220 xexyey[inorm][3][bin] = log10(xexyey[inorm][3][bin])/xexyey[inorm][2][bin];
1221 xexyey[inorm][2][bin] = log10(xexyey[inorm][2][bin]);
1225 for (
int inorm=0; inorm<2; inorm++){
1226 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[inorm][0], xexyey[inorm][2], xexyey[inorm][1], xexyey[inorm][3]);
1227 if (inorm==0) tg->SetName(
"tg_P_ConserveDifermionMass");
1228 else tg->SetName(
"tg_P_MomentumToEnergy");
1229 foutput->WriteTObject(tg);
1233 for (
int inorm=0; inorm<2; inorm++){
1234 for (
int ix=0; ix<4; ix++)
delete[] xexyey[inorm][ix];
1236 foutput->WriteTObject(hmesq_jetPtoEScale);
1237 foutput->WriteTObject(hmesq_conserveDifermMass);
1238 foutput->WriteTObject(hvar);
1239 if (writeFinalTree) foutput->WriteTObject(newtree);
1240 if (writeFinalTree)
delete newtree;
1241 delete hmesq_conserveDifermMass;
1242 delete hmesq_jetPtoEScale;
1246 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
1265 TString TREE_NAME =
"SelectedTree";
1266 bool writeFinalTree=
true;
1269 Mela mela(erg_tev, mPOLE, verbosity);
1280 std::vector<double>* JetPt=0;
1281 std::vector<double>* JetEta=0;
1282 std::vector<double>* JetPhi=0;
1283 std::vector<double>* JetMass=0;
1284 std::vector<double> myJetPt;
1285 std::vector<double> myJetEta;
1286 std::vector<double> myJetPhi;
1287 std::vector<double> myJetMass;
1291 TBranch* bJetMass=0;
1292 float jetptetaphimass[2][4];
1294 float mesq_conserveDifermMass=0;
1295 float mesq_jetPtoEScale=0;
1297 float m1 = 91.471450;
1298 float m2 = 12.139782;
1299 float h1 = 0.2682896;
1300 float h2 = 0.1679779;
1301 float phi = 1.5969792;
1302 float hs = -0.727181;
1303 float phi1 = 1.8828257;
1304 float ZZPt, ZZPhi, ZZEta;
1305 int LepID[4]={ 13, -13, 11, -11 };
1306 short Z1Flav, Z2Flav;
1308 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
1309 TString cinput_main;
1316 vector<TFile*> finputList;
1317 vector<TTree*> treeList;
1320 for (
int is=0; is<(
int)strSamples.size(); is++){
1321 for (
int ic=0; ic<3; ic++){
1322 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples[is]).Data());
1323 TFile* finput = TFile::Open(cinput,
"read");
1324 cout <<
"Opening file " << cinput <<
"..." << endl;
1327 if (finput->IsOpen() && !finput->IsZombie()){
1328 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
1329 tree = (TTree*)finput->Get(TREE_NAME);
1331 cout << TREE_NAME <<
" is found." << endl;
1332 tree->SetBranchStatus(
"*", 0);
1333 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
1334 tree->SetBranchStatus(
"ZZPt", 1); tree->SetBranchAddress(
"ZZPt", &ZZPt);
1335 tree->SetBranchStatus(
"ZZEta", 1); tree->SetBranchAddress(
"ZZEta", &ZZEta);
1336 tree->SetBranchStatus(
"ZZPhi", 1); tree->SetBranchAddress(
"ZZPhi", &ZZPhi);
1337 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
1338 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
1339 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
1340 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
1341 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
1342 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
1343 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
1344 tree->SetBranchStatus(
"NJets30", 1); tree->SetBranchAddress(
"NJets30", &NJets30);
1345 tree->SetBranchStatus(
"JetPt", 1); tree->SetBranchAddress(
"JetPt", &JetPt);
1346 tree->SetBranchStatus(
"JetEta", 1); tree->SetBranchAddress(
"JetEta", &JetEta);
1347 tree->SetBranchStatus(
"JetPhi", 1); tree->SetBranchAddress(
"JetPhi", &JetPhi);
1348 tree->SetBranchStatus(
"JetMass", 1); tree->SetBranchAddress(
"JetMass", &JetMass);
1350 nEntries += tree->GetEntries();
1351 treeList.push_back(tree);
1352 finputList.push_back(finput);
1354 else finput->Close();
1356 else if (finput->IsOpen()) finput->Close();
1361 const int nSamples = treeList.size();
1363 cout <<
"NEntries = " << nEntries <<
" over " << treeList.size() <<
" trees." << endl;
1365 vector<pair<float, int>> index;
1366 unsigned int ev_acc=0;
1367 for (
int ev=0;
ev<nEntries;
ev++){
1369 if (NJets30!=1)
continue;
1370 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
1375 float firstVal=index.at(0).first;
1376 float lastVal=index.at(index.size()-1).first;
1377 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
1378 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
1379 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
1381 float divisor=85000;
1382 int nbins = index.size()/divisor;
1383 const int nbins_th=10;
1384 while (nbins<nbins_th){
1385 if (divisor>1000) divisor -= 1000;
1386 else if (divisor>100) divisor -= 100;
1388 nbins=index.size()/divisor;
1390 cout <<
"nbins=" << nbins << endl;
1391 if (nbins<3) cerr <<
"Not enough bins!" << endl;
1392 vector<ExtBin> binList;
1393 float* binning =
new float[nbins+1];
1395 binning[nbins]=supremum;
1396 int ev_stepsize = index.size()/nbins;
1397 cout <<
"Event step size: " << ev_stepsize << endl;
1398 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
1399 for (
int ix=1; ix<nbins; ix++){
1400 binning[ix]=(index[ix*ev_stepsize-1].first+index[ix*ev_stepsize].first)*0.5;
1402 tmpbin.
binlow = binning[ix-1];
1404 for (
int bin=0; bin<ev_stepsize; bin++) tmpbin.
events.push_back(index[(ix-1)*ev_stepsize+bin].second);
1405 binList.push_back(tmpbin);
1406 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
1409 tmpbin.
binlow = binning[nbins-1];
1410 tmpbin.
binhigh = binning[nbins];
1411 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index.size(); bin++) tmpbin.
events.push_back(index[bin].second);
1412 binList.push_back(tmpbin);
1413 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
1414 cout <<
"Bin list has the following bins:" << endl;
1415 for (
unsigned int ib=0; ib<binList.size(); ib++){
1416 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
1419 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
1421 TProfile* hvar =
new TProfile(
"candMass",
"", nbins, binning); hvar->Sumw2();
1422 TProfile* hmesq_conserveDifermMass =
new TProfile(
"P_ConserveDifermionMass",
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
1423 TProfile* hmesq_jetPtoEScale =
new TProfile(
"P_MomentumToEnergy",
"", nbins, binning); hmesq_jetPtoEScale->Sumw2();
1426 if (writeFinalTree){
1427 newtree =
new TTree(
"FinalTree",
"");
1428 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
1429 newtree->Branch(
"mesq_jetPtoEScale", &mesq_jetPtoEScale);
1430 newtree->Branch(
"ZZMass", &mzz);
1435 for (
unsigned int bin=0; bin<binList.size(); bin++){
1436 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
1437 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
1438 int getEv = binList.at(bin).events.at(
ev);
1440 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
1441 if (JetPt->size()<1 || JetEta->size()<1 || JetPhi->size()<1 || JetMass->size()<1){
1442 cerr <<
"Jet array sizes are less than Njets!" << endl;
1446 TLorentzVector jet, higgs;
1447 jet.SetPtEtaPhiM(JetPt->at(0), JetEta->at(0), JetPhi->at(0), JetMass->at(0));
1448 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
1449 TVector3 boostH = higgs.BoostVector();
1454 TLorentzVector pDaughters[4];
1455 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
1456 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); pDaughters[ip].Boost(boostH); }
1466 mela.computeProdP(mesq_conserveDifermMass,
false);
1467 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
1468 mesq_conserveDifermMass /= pow(alphasVal, 3);
1471 mela.computeProdP(mesq_jetPtoEScale,
false);
1472 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
1473 mesq_jetPtoEScale /= pow(alphasVal, 3);
1476 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
1478 isnan(mesq_jetPtoEScale) || isinf(mesq_jetPtoEScale)
1481 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, mesq_jetPtoEScale);
1483 mela.resetInputEvent();
1486 binList.at(bin).sift(); binList.at(bin).adjustWeights();
1488 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
1489 mzz = binList.at(bin).masses.at(
ev);
1490 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
1491 mesq_jetPtoEScale = binList.at(bin).me2vals.at(
ev);
1492 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
1493 hmesq_jetPtoEScale->Fill(mzz, mesq_jetPtoEScale);
1494 hvar->Fill(mzz, mzz);
1495 if (writeFinalTree) newtree->Fill();
1499 double* xexyey[2][4];
1500 for (
int inorm=0; inorm<2; inorm++){
1501 for (
int ix=0; ix<4; ix++) xexyey[inorm][ix] =
new double[nbins];
1502 for (
int bin=0; bin<nbins; bin++){
1503 xexyey[inorm][0][bin] = hvar->GetBinContent(bin+1);
1504 xexyey[inorm][1][bin] = hvar->GetBinError(bin+1);
1506 if (inorm==0)
cout <<
"Bin " << bin <<
" x-center: " << xexyey[inorm][0][bin] <<
" +- " << xexyey[inorm][1][bin] << endl;
1509 xexyey[inorm][2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
1510 xexyey[inorm][3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
1513 xexyey[inorm][2][bin] = hmesq_jetPtoEScale->GetBinContent(bin+1);
1514 xexyey[inorm][3][bin] = hmesq_jetPtoEScale->GetBinError(bin+1);
1516 xexyey[inorm][3][bin] = log10(xexyey[inorm][3][bin])/xexyey[inorm][2][bin];
1517 xexyey[inorm][2][bin] = log10(xexyey[inorm][2][bin]);
1521 for (
int inorm=0; inorm<2; inorm++){
1522 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[inorm][0], xexyey[inorm][2], xexyey[inorm][1], xexyey[inorm][3]);
1523 if (inorm==0) tg->SetName(
"tg_P_ConserveDifermionMass");
1524 else tg->SetName(
"tg_P_MomentumToEnergy");
1525 foutput->WriteTObject(tg);
1529 for (
int inorm=0; inorm<2; inorm++){
1530 for (
int ix=0; ix<4; ix++)
delete[] xexyey[inorm][ix];
1532 foutput->WriteTObject(hmesq_jetPtoEScale);
1533 foutput->WriteTObject(hmesq_conserveDifermMass);
1534 foutput->WriteTObject(hvar);
1535 if (writeFinalTree) foutput->WriteTObject(newtree);
1536 if (writeFinalTree)
delete newtree;
1537 delete hmesq_conserveDifermMass;
1538 delete hmesq_jetPtoEScale;
1542 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
1569 TString TREE_NAME =
"ZZTree/candTree";
1570 TString COUNTERS_NAME =
"ZZTree/Counters";
1571 bool writeFinalTree=
true;
1582 Mela mela(erg_tev, mPOLE, verbosity);
1584 std::vector<short>* LepLepId=0;
1585 std::vector<float>* LepPt=0;
1586 std::vector<float>* LepEta=0;
1587 std::vector<float>* LepPhi=0;
1590 std::vector<float>* JetPt=0;
1591 std::vector<float>* JetEta=0;
1592 std::vector<float>* JetPhi=0;
1593 std::vector<float>* JetMass=0;
1594 std::vector<float> myJetPt;
1595 std::vector<float> myJetEta;
1596 std::vector<float> myJetPhi;
1597 std::vector<float> myJetMass;
1599 float mesq_calc=0., cconst_calc=1.;
1600 float mesq_conserveDifermMass=0;
1601 float mesq_jetPtoEScale=0;
1603 float m1 = 91.471450;
1604 float m2 = 12.139782;
1605 float h1 = 0.2682896;
1606 float h2 = 0.1679779;
1607 float phi = 1.5969792;
1608 float hs = -0.727181;
1609 float phi1 = 1.8828257;
1610 float ZZPt, ZZPhi, ZZEta;
1611 float genHEPMCweight;
1614 TString cinput_main;
1620 unordered_map<TTree*, pair<float, float>> nGenMap;
1621 vector<TFile*> finputList;
1622 vector<TTree*> treeList;
1624 for (
unsigned int is=0; is<strSamples.size(); is++){
1625 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples[is]).Data());
1626 TFile* finput = TFile::Open(cinput,
"read");
1627 cout <<
"Opening file " << cinput <<
"..." << endl;
1630 if (finput->IsOpen() && !finput->IsZombie()){
1631 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
1632 tree = (TTree*)finput->Get(TREE_NAME);
1634 cout << TREE_NAME <<
" is found." << endl;
1635 if (!recalculate && tree->GetBranchStatus(
"pConst_JJVBF_SIG_ghv1_1_JHUGen_JECNominal")==0) recalculate=
true;
1636 tree->SetBranchStatus(
"*", 0);
1637 tree->SetBranchStatus(
"genHEPMCweight", 1); tree->SetBranchAddress(
"genHEPMCweight", &genHEPMCweight);
1638 tree->SetBranchStatus(
"nCleanedJetsPt30", 1); tree->SetBranchAddress(
"nCleanedJetsPt30", &NJets30);
1639 tree->SetBranchStatus(
"JetPt", 1); tree->SetBranchAddress(
"JetPt", &JetPt);
1640 tree->SetBranchStatus(
"JetEta", 1); tree->SetBranchAddress(
"JetEta", &JetEta);
1641 tree->SetBranchStatus(
"JetPhi", 1); tree->SetBranchAddress(
"JetPhi", &JetPhi);
1642 tree->SetBranchStatus(
"JetMass", 1); tree->SetBranchAddress(
"JetMass", &JetMass);
1643 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
1644 tree->SetBranchStatus(
"ZZPt", 1); tree->SetBranchAddress(
"ZZPt", &ZZPt);
1645 tree->SetBranchStatus(
"ZZEta", 1); tree->SetBranchAddress(
"ZZEta", &ZZEta);
1646 tree->SetBranchStatus(
"ZZPhi", 1); tree->SetBranchAddress(
"ZZPhi", &ZZPhi);
1647 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
1648 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
1649 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
1650 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
1651 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
1652 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
1653 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
1654 tree->SetBranchStatus(
"LepLepId", 1); tree->SetBranchAddress(
"LepLepId", &LepLepId);
1655 tree->SetBranchStatus(
"LepPt", 1); tree->SetBranchAddress(
"LepPt", &LepPt);
1656 tree->SetBranchStatus(
"LepEta", 1); tree->SetBranchAddress(
"LepEta", &LepEta);
1657 tree->SetBranchStatus(
"LepPhi", 1); tree->SetBranchAddress(
"LepPhi", &LepPhi);
1659 tree->SetBranchStatus(
"p_JJVBF_SIG_ghv1_1_JHUGen_JECNominal", 1);
1660 tree->SetBranchAddress(
"p_JJVBF_SIG_ghv1_1_JHUGen_JECNominal", &mesq_calc);
1661 tree->SetBranchStatus(
"pConst_JJVBF_SIG_ghv1_1_JHUGen_JECNominal", 1);
1662 tree->SetBranchAddress(
"pConst_JJVBF_SIG_ghv1_1_JHUGen_JECNominal", &cconst_calc);
1665 TH1F* htmp = (TH1F*)finput->Get(COUNTERS_NAME);
1666 pair<float, float> nsum(htmp->GetBinContent(1), htmp->GetBinContent(41));
1669 nEntries += tree->GetEntries();
1670 treeList.push_back(tree);
1671 finputList.push_back(finput);
1673 else if (finput->IsOpen()) finput->Close();
1677 cout <<
"NEntries = " << nEntries << endl;
1679 vector<pair<float, int>> index;
1680 unsigned int ev_acc=0;
1681 for (
int ev=0;
ev<nEntries;
ev++){
1683 if (NJets30<2)
continue;
1684 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
1689 float firstVal=index.at(0).first;
1690 float lastVal=index.at(index.size()-1).first;
1691 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
1692 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
1693 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
1695 float divisor=85000;
1696 int nbins = index.size()/divisor;
1697 const int nbins_th=10;
1698 while (nbins<nbins_th){
1699 if (divisor>1000) divisor -= 1000;
1700 else if (divisor>100) divisor -= 100;
1702 nbins=index.size()/divisor;
1704 cout <<
"nbins=" << nbins << endl;
1705 if (nbins<3) cerr <<
"Not enough bins!" << endl;
1706 vector<ExtBin> binList;
1707 float* binning =
new float[nbins+1];
1709 binning[nbins]=supremum;
1710 int ev_stepsize = index.size()/nbins;
1711 cout <<
"Event step size: " << ev_stepsize << endl;
1712 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
1713 for (
int ix=1; ix<nbins; ix++){
1714 binning[ix]=(index[ix*ev_stepsize-1].first+index[ix*ev_stepsize].first)*0.5;
1716 tmpbin.
binlow = binning[ix-1];
1718 for (
int bin=0; bin<ev_stepsize; bin++) tmpbin.
events.push_back(index[(ix-1)*ev_stepsize+bin].second);
1719 binList.push_back(tmpbin);
1720 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
1723 tmpbin.
binlow = binning[nbins-1];
1724 tmpbin.
binhigh = binning[nbins];
1725 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index.size(); bin++) tmpbin.
events.push_back(index[bin].second);
1726 binList.push_back(tmpbin);
1727 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
1728 cout <<
"Bin list has the following bins:" << endl;
1729 for (
unsigned int ib=0; ib<binList.size(); ib++){
1730 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
1739 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
1741 TProfile* hvar =
new TProfile(
"candMass",
"", nbins, binning); hvar->Sumw2();
1742 TProfile* hmesq_conserveDifermMass =
new TProfile(
"P_ConserveDifermionMass",
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
1743 TProfile* hmesq_jetPtoEScale =
new TProfile(
"P_MomentumToEnergy",
"", nbins, binning); hmesq_jetPtoEScale->Sumw2();
1747 if (writeFinalTree){
1748 newtree =
new TTree(
"FinalTree",
"");
1749 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
1750 newtree->Branch(
"mesq_jetPtoEScale", &mesq_jetPtoEScale);
1751 newtree->Branch(
"ZZMass", &mzz);
1756 for (
unsigned int bin=0; bin<binList.size(); bin++){
1757 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
1758 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
1759 int getEv = binList.at(bin).events.at(
ev);
1761 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
1762 if (JetPt->size()<2 || JetEta->size()<2 || JetPhi->size()<2 || JetMass->size()<2){
1763 cerr <<
"Jet array sizes are less than Njets!" << endl;
1766 TTree* tree =
findTree(treeList, getEv);
1767 wgt = fabs(genHEPMCweight*nGenMap[tree].first/nGenMap[tree].
second);
1769 TLorentzVector jet[2], higgs;
1770 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(JetPt->at(ij), JetEta->at(ij), JetPhi->at(ij), JetMass->at(ij));
1771 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
1772 TVector3 boostH = higgs.BoostVector();
1779 for (
int id=0;
id<4;
id++){
1781 if (abs(LepLepId->at(
id))==13) mass = 0.105658;
1782 else if (abs(LepLepId->at(
id))==11) mass = 0.000511;
1783 TLorentzVector pDaughter;
1784 pDaughter.SetPtEtaPhiM(LepPt->at(
id), LepEta->at(
id), LepPhi->at(
id), mass);
1793 mela.computeProdP(mesq_conserveDifermMass,
false);
1796 mesq_calc /= cconst_calc;
1797 mesq_conserveDifermMass=mesq_calc;
1800 mela.computeProdP(mesq_jetPtoEScale,
false);
1803 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
1805 isnan(mesq_jetPtoEScale) || isinf(mesq_jetPtoEScale)
1808 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, mesq_jetPtoEScale, wgt);
1810 mela.resetInputEvent();
1813 binList.at(bin).sift(); binList.at(bin).adjustWeights();
1815 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
1816 mzz = binList.at(bin).masses.at(
ev);
1817 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
1818 mesq_jetPtoEScale = binList.at(bin).me2vals.at(
ev);
1819 wgt = binList.at(bin).weights.at(
ev);
1820 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass, wgt);
1821 hmesq_jetPtoEScale->Fill(mzz, mesq_jetPtoEScale, wgt);
1822 hvar->Fill(mzz, mzz, wgt);
1823 if (writeFinalTree) newtree->Fill();
1827 double* xexyey[2][4];
1828 for (
int inorm=0; inorm<2; inorm++){
1829 for (
int ix=0; ix<4; ix++) xexyey[inorm][ix] =
new double[nbins];
1830 for (
int bin=0; bin<nbins; bin++){
1831 xexyey[inorm][0][bin] = hvar->GetBinContent(bin+1);
1832 xexyey[inorm][1][bin] = hvar->GetBinError(bin+1);
1834 if (inorm==0)
cout <<
"Bin " << bin <<
" x-center: " << xexyey[inorm][0][bin] <<
" +- " << xexyey[inorm][1][bin] << endl;
1837 xexyey[inorm][2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
1838 xexyey[inorm][3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
1841 xexyey[inorm][2][bin] = hmesq_jetPtoEScale->GetBinContent(bin+1);
1842 xexyey[inorm][3][bin] = hmesq_jetPtoEScale->GetBinError(bin+1);
1844 xexyey[inorm][3][bin] = log10(xexyey[inorm][3][bin])/xexyey[inorm][2][bin];
1845 xexyey[inorm][2][bin] = log10(xexyey[inorm][2][bin]);
1849 for (
int inorm=0; inorm<2; inorm++){
1850 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[inorm][0], xexyey[inorm][2], xexyey[inorm][1], xexyey[inorm][3]);
1851 if (inorm==0) tg->SetName(
"tg_P_ConserveDifermionMass");
1852 else tg->SetName(
"tg_P_MomentumToEnergy");
1853 foutput->WriteTObject(tg);
1857 for (
int inorm=0; inorm<2; inorm++){
1858 for (
int ix=0; ix<4; ix++)
delete[] xexyey[inorm][ix];
1860 foutput->WriteTObject(hmesq_jetPtoEScale);
1861 foutput->WriteTObject(hmesq_conserveDifermMass);
1862 foutput->WriteTObject(hvar);
1863 if (writeFinalTree) foutput->WriteTObject(newtree);
1864 if (writeFinalTree)
delete newtree;
1865 delete hmesq_conserveDifermMass;
1866 delete hmesq_jetPtoEScale;
1870 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
1878 TString TREE_NAME =
"ZZTree/candTree";
1879 TString COUNTERS_NAME =
"ZZTree/Counters";
1880 bool writeFinalTree=
true;
1891 Mela mela(erg_tev, mPOLE, verbosity);
1893 std::vector<short>* LepLepId=0;
1894 std::vector<float>* LepPt=0;
1895 std::vector<float>* LepEta=0;
1896 std::vector<float>* LepPhi=0;
1899 std::vector<float>* JetPt=0;
1900 std::vector<float>* JetEta=0;
1901 std::vector<float>* JetPhi=0;
1902 std::vector<float>* JetMass=0;
1903 std::vector<float> myJetPt;
1904 std::vector<float> myJetEta;
1905 std::vector<float> myJetPhi;
1906 std::vector<float> myJetMass;
1908 float mesq_calc=0., cconst_calc=1.;
1909 float mesq_conserveDifermMass=0;
1910 float mesq_jetPtoEScale=0;
1912 float m1 = 91.471450;
1913 float m2 = 12.139782;
1914 float h1 = 0.2682896;
1915 float h2 = 0.1679779;
1916 float phi = 1.5969792;
1917 float hs = -0.727181;
1918 float phi1 = 1.8828257;
1919 float ZZPt, ZZPhi, ZZEta;
1920 float genHEPMCweight;
1923 TString cinput_main;
1929 unordered_map<TTree*, pair<float, float>> nGenMap;
1930 vector<TFile*> finputList;
1931 vector<TTree*> treeList;
1933 for (
unsigned int is=0; is<strSamples.size(); is++){
1934 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples[is]).Data());
1935 TFile* finput = TFile::Open(cinput,
"read");
1936 cout <<
"Opening file " << cinput <<
"..." << endl;
1939 if (finput->IsOpen() && !finput->IsZombie()){
1940 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
1941 tree = (TTree*)finput->Get(TREE_NAME);
1943 cout << TREE_NAME <<
" is found." << endl;
1944 if (!recalculate && tree->GetBranchStatus(
"pConst_JJQCD_SIG_ghg2_1_JHUGen_JECNominal")==0) recalculate=
true;
1945 tree->SetBranchStatus(
"*", 0);
1946 tree->SetBranchStatus(
"genHEPMCweight", 1); tree->SetBranchAddress(
"genHEPMCweight", &genHEPMCweight);
1947 tree->SetBranchStatus(
"nCleanedJetsPt30", 1); tree->SetBranchAddress(
"nCleanedJetsPt30", &NJets30);
1948 tree->SetBranchStatus(
"JetPt", 1); tree->SetBranchAddress(
"JetPt", &JetPt);
1949 tree->SetBranchStatus(
"JetEta", 1); tree->SetBranchAddress(
"JetEta", &JetEta);
1950 tree->SetBranchStatus(
"JetPhi", 1); tree->SetBranchAddress(
"JetPhi", &JetPhi);
1951 tree->SetBranchStatus(
"JetMass", 1); tree->SetBranchAddress(
"JetMass", &JetMass);
1952 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
1953 tree->SetBranchStatus(
"ZZPt", 1); tree->SetBranchAddress(
"ZZPt", &ZZPt);
1954 tree->SetBranchStatus(
"ZZEta", 1); tree->SetBranchAddress(
"ZZEta", &ZZEta);
1955 tree->SetBranchStatus(
"ZZPhi", 1); tree->SetBranchAddress(
"ZZPhi", &ZZPhi);
1956 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
1957 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
1958 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
1959 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
1960 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
1961 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
1962 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
1963 tree->SetBranchStatus(
"LepLepId", 1); tree->SetBranchAddress(
"LepLepId", &LepLepId);
1964 tree->SetBranchStatus(
"LepPt", 1); tree->SetBranchAddress(
"LepPt", &LepPt);
1965 tree->SetBranchStatus(
"LepEta", 1); tree->SetBranchAddress(
"LepEta", &LepEta);
1966 tree->SetBranchStatus(
"LepPhi", 1); tree->SetBranchAddress(
"LepPhi", &LepPhi);
1968 tree->SetBranchStatus(
"p_JJQCD_SIG_ghg2_1_JHUGen_JECNominal", 1);
1969 tree->SetBranchAddress(
"p_JJQCD_SIG_ghg2_1_JHUGen_JECNominal", &mesq_calc);
1970 tree->SetBranchStatus(
"pConst_JJQCD_SIG_ghg2_1_JHUGen_JECNominal", 1);
1971 tree->SetBranchAddress(
"pConst_JJQCD_SIG_ghg2_1_JHUGen_JECNominal", &cconst_calc);
1974 TH1F* htmp = (TH1F*)finput->Get(COUNTERS_NAME);
1975 pair<float, float> nsum(htmp->GetBinContent(1), htmp->GetBinContent(41));
1978 nEntries += tree->GetEntries();
1979 treeList.push_back(tree);
1980 finputList.push_back(finput);
1982 else if (finput->IsOpen()) finput->Close();
1986 cout <<
"NEntries = " << nEntries << endl;
1988 vector<pair<float, int>> index;
1989 unsigned int ev_acc=0;
1990 for (
int ev=0;
ev<nEntries;
ev++){
1992 if (NJets30<2)
continue;
1993 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
1998 float firstVal=index.at(0).first;
1999 float lastVal=index.at(index.size()-1).first;
2000 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
2001 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
2002 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
2004 float divisor=85000;
2005 int nbins = index.size()/divisor;
2006 const int nbins_th=10;
2007 while (nbins<nbins_th){
2008 if (divisor>1000) divisor -= 1000;
2009 else if (divisor>100) divisor -= 100;
2011 nbins=index.size()/divisor;
2013 cout <<
"nbins=" << nbins << endl;
2014 if (nbins<3) cerr <<
"Not enough bins!" << endl;
2015 vector<ExtBin> binList;
2016 float* binning =
new float[nbins+1];
2018 binning[nbins]=supremum;
2019 int ev_stepsize = index.size()/nbins;
2020 cout <<
"Event step size: " << ev_stepsize << endl;
2021 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
2022 for (
int ix=1; ix<nbins; ix++){
2023 binning[ix]=(index[ix*ev_stepsize-1].first+index[ix*ev_stepsize].first)*0.5;
2025 tmpbin.
binlow = binning[ix-1];
2027 for (
int bin=0; bin<ev_stepsize; bin++) tmpbin.
events.push_back(index[(ix-1)*ev_stepsize+bin].second);
2028 binList.push_back(tmpbin);
2029 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
2032 tmpbin.
binlow = binning[nbins-1];
2033 tmpbin.
binhigh = binning[nbins];
2034 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index.size(); bin++) tmpbin.
events.push_back(index[bin].second);
2035 binList.push_back(tmpbin);
2036 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
2037 cout <<
"Bin list has the following bins:" << endl;
2038 for (
unsigned int ib=0; ib<binList.size(); ib++){
2039 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
2048 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
2050 TProfile* hvar =
new TProfile(
"candMass",
"", nbins, binning); hvar->Sumw2();
2051 TProfile* hmesq_conserveDifermMass =
new TProfile(
"P_ConserveDifermionMass",
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
2052 TProfile* hmesq_jetPtoEScale =
new TProfile(
"P_MomentumToEnergy",
"", nbins, binning); hmesq_jetPtoEScale->Sumw2();
2056 if (writeFinalTree){
2057 newtree =
new TTree(
"FinalTree",
"");
2058 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
2059 newtree->Branch(
"mesq_jetPtoEScale", &mesq_jetPtoEScale);
2060 newtree->Branch(
"ZZMass", &mzz);
2065 for (
unsigned int bin=0; bin<binList.size(); bin++){
2066 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
2067 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
2068 int getEv = binList.at(bin).events.at(
ev);
2070 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
2071 if (JetPt->size()<2 || JetEta->size()<2 || JetPhi->size()<2 || JetMass->size()<2){
2072 cerr <<
"Jet array sizes are less than Njets!" << endl;
2075 TTree* tree =
findTree(treeList, getEv);
2076 wgt = fabs(genHEPMCweight*nGenMap[tree].first/nGenMap[tree].
second);
2078 TLorentzVector jet[2], higgs;
2079 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(JetPt->at(ij), JetEta->at(ij), JetPhi->at(ij), JetMass->at(ij));
2080 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
2081 TVector3 boostH = higgs.BoostVector();
2088 for (
int id=0;
id<4;
id++){
2090 if (abs(LepLepId->at(
id))==13) mass = 0.105658;
2091 else if (abs(LepLepId->at(
id))==11) mass = 0.000511;
2092 TLorentzVector pDaughter;
2093 pDaughter.SetPtEtaPhiM(LepPt->at(
id), LepEta->at(
id), LepPhi->at(
id), mass);
2103 mela.computeProdP(mesq_conserveDifermMass,
false);
2104 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
2105 mesq_conserveDifermMass /= pow(alphasVal, 4);
2108 mesq_calc /= cconst_calc;
2109 mesq_conserveDifermMass=mesq_calc;
2112 mela.computeProdP(mesq_jetPtoEScale,
false);
2113 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
2114 mesq_jetPtoEScale /= pow(alphasVal, 4);
2117 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
2119 isnan(mesq_jetPtoEScale) || isinf(mesq_jetPtoEScale)
2122 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, mesq_jetPtoEScale, wgt);
2124 mela.resetInputEvent();
2127 binList.at(bin).sift(); binList.at(bin).adjustWeights();
2129 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
2130 mzz = binList.at(bin).masses.at(
ev);
2131 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
2132 mesq_jetPtoEScale = binList.at(bin).me2vals.at(
ev);
2133 wgt = binList.at(bin).weights.at(
ev);
2134 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass, wgt);
2135 hmesq_jetPtoEScale->Fill(mzz, mesq_jetPtoEScale, wgt);
2136 hvar->Fill(mzz, mzz, wgt);
2137 if (writeFinalTree) newtree->Fill();
2141 double* xexyey[2][4];
2142 for (
int inorm=0; inorm<2; inorm++){
2143 for (
int ix=0; ix<4; ix++) xexyey[inorm][ix] =
new double[nbins];
2144 for (
int bin=0; bin<nbins; bin++){
2145 xexyey[inorm][0][bin] = hvar->GetBinContent(bin+1);
2146 xexyey[inorm][1][bin] = hvar->GetBinError(bin+1);
2148 if (inorm==0)
cout <<
"Bin " << bin <<
" x-center: " << xexyey[inorm][0][bin] <<
" +- " << xexyey[inorm][1][bin] << endl;
2151 xexyey[inorm][2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
2152 xexyey[inorm][3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
2155 xexyey[inorm][2][bin] = hmesq_jetPtoEScale->GetBinContent(bin+1);
2156 xexyey[inorm][3][bin] = hmesq_jetPtoEScale->GetBinError(bin+1);
2158 xexyey[inorm][3][bin] = log10(xexyey[inorm][3][bin])/xexyey[inorm][2][bin];
2159 xexyey[inorm][2][bin] = log10(xexyey[inorm][2][bin]);
2163 for (
int inorm=0; inorm<2; inorm++){
2164 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[inorm][0], xexyey[inorm][2], xexyey[inorm][1], xexyey[inorm][3]);
2165 if (inorm==0) tg->SetName(
"tg_P_ConserveDifermionMass");
2166 else tg->SetName(
"tg_P_MomentumToEnergy");
2167 foutput->WriteTObject(tg);
2171 for (
int inorm=0; inorm<2; inorm++){
2172 for (
int ix=0; ix<4; ix++)
delete[] xexyey[inorm][ix];
2174 foutput->WriteTObject(hmesq_jetPtoEScale);
2175 foutput->WriteTObject(hmesq_conserveDifermMass);
2176 foutput->WriteTObject(hvar);
2177 if (writeFinalTree) foutput->WriteTObject(newtree);
2178 if (writeFinalTree)
delete newtree;
2179 delete hmesq_conserveDifermMass;
2180 delete hmesq_jetPtoEScale;
2184 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
2192 TString TREE_NAME =
"ZZTree/candTree";
2193 TString COUNTERS_NAME =
"ZZTree/Counters";
2194 bool writeFinalTree=
true;
2205 Mela mela(erg_tev, mPOLE, verbosity);
2207 std::vector<short>* LepLepId=0;
2208 std::vector<float>* LepPt=0;
2209 std::vector<float>* LepEta=0;
2210 std::vector<float>* LepPhi=0;
2213 std::vector<float>* JetPt=0;
2214 std::vector<float>* JetEta=0;
2215 std::vector<float>* JetPhi=0;
2216 std::vector<float>* JetMass=0;
2217 std::vector<float> myJetPt;
2218 std::vector<float> myJetEta;
2219 std::vector<float> myJetPhi;
2220 std::vector<float> myJetMass;
2222 float mesq_calc=0., cconst_calc=1.;
2223 float mesq_conserveDifermMass=0;
2224 float mesq_jetPtoEScale=0;
2226 float m1 = 91.471450;
2227 float m2 = 12.139782;
2228 float h1 = 0.2682896;
2229 float h2 = 0.1679779;
2230 float phi = 1.5969792;
2231 float hs = -0.727181;
2232 float phi1 = 1.8828257;
2233 float ZZPt, ZZPhi, ZZEta;
2234 float genHEPMCweight;
2237 TString cinput_main;
2243 unordered_map<TTree*, pair<float, float>> nGenMap;
2244 vector<TFile*> finputList;
2245 vector<TTree*> treeList;
2247 for (
unsigned int is=0; is<strSamples.size(); is++){
2248 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples[is]).Data());
2249 TFile* finput = TFile::Open(cinput,
"read");
2250 cout <<
"Opening file " << cinput <<
"..." << endl;
2253 if (finput->IsOpen() && !finput->IsZombie()){
2254 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
2255 tree = (TTree*)finput->Get(TREE_NAME);
2257 cout << TREE_NAME <<
" is found." << endl;
2258 if (!recalculate && tree->GetBranchStatus(
"pConst_JQCD_SIG_ghg2_1_JHUGen_JECNominal")==0) recalculate=
true;
2259 tree->SetBranchStatus(
"*", 0);
2260 tree->SetBranchStatus(
"genHEPMCweight", 1); tree->SetBranchAddress(
"genHEPMCweight", &genHEPMCweight);
2261 tree->SetBranchStatus(
"nCleanedJetsPt30", 1); tree->SetBranchAddress(
"nCleanedJetsPt30", &NJets30);
2262 tree->SetBranchStatus(
"JetPt", 1); tree->SetBranchAddress(
"JetPt", &JetPt);
2263 tree->SetBranchStatus(
"JetEta", 1); tree->SetBranchAddress(
"JetEta", &JetEta);
2264 tree->SetBranchStatus(
"JetPhi", 1); tree->SetBranchAddress(
"JetPhi", &JetPhi);
2265 tree->SetBranchStatus(
"JetMass", 1); tree->SetBranchAddress(
"JetMass", &JetMass);
2266 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
2267 tree->SetBranchStatus(
"ZZPt", 1); tree->SetBranchAddress(
"ZZPt", &ZZPt);
2268 tree->SetBranchStatus(
"ZZEta", 1); tree->SetBranchAddress(
"ZZEta", &ZZEta);
2269 tree->SetBranchStatus(
"ZZPhi", 1); tree->SetBranchAddress(
"ZZPhi", &ZZPhi);
2270 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
2271 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
2272 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
2273 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
2274 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
2275 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
2276 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
2277 tree->SetBranchStatus(
"LepLepId", 1); tree->SetBranchAddress(
"LepLepId", &LepLepId);
2278 tree->SetBranchStatus(
"LepPt", 1); tree->SetBranchAddress(
"LepPt", &LepPt);
2279 tree->SetBranchStatus(
"LepEta", 1); tree->SetBranchAddress(
"LepEta", &LepEta);
2280 tree->SetBranchStatus(
"LepPhi", 1); tree->SetBranchAddress(
"LepPhi", &LepPhi);
2282 tree->SetBranchStatus(
"p_JQCD_SIG_ghg2_1_JHUGen_JECNominal", 1);
2283 tree->SetBranchAddress(
"p_JQCD_SIG_ghg2_1_JHUGen_JECNominal", &mesq_calc);
2284 tree->SetBranchStatus(
"pConst_JQCD_SIG_ghg2_1_JHUGen_JECNominal", 1);
2285 tree->SetBranchAddress(
"pConst_JQCD_SIG_ghg2_1_JHUGen_JECNominal", &cconst_calc);
2288 TH1F* htmp = (TH1F*)finput->Get(COUNTERS_NAME);
2289 pair<float, float> nsum(htmp->GetBinContent(1), htmp->GetBinContent(41));
2292 nEntries += tree->GetEntries();
2293 treeList.push_back(tree);
2294 finputList.push_back(finput);
2296 else if (finput->IsOpen()) finput->Close();
2300 cout <<
"NEntries = " << nEntries << endl;
2302 vector<pair<float, int>> index;
2303 unsigned int ev_acc=0;
2304 for (
int ev=0;
ev<nEntries;
ev++){
2306 if (NJets30!=1)
continue;
2307 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
2312 float firstVal=index.at(0).first;
2313 float lastVal=index.at(index.size()-1).first;
2314 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
2315 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
2316 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
2318 float divisor=85000;
2319 int nbins = index.size()/divisor;
2320 const int nbins_th=10;
2321 while (nbins<nbins_th){
2322 if (divisor>1000) divisor -= 1000;
2323 else if (divisor>100) divisor -= 100;
2325 nbins=index.size()/divisor;
2327 cout <<
"nbins=" << nbins << endl;
2328 if (nbins<3) cerr <<
"Not enough bins!" << endl;
2329 vector<ExtBin> binList;
2330 float* binning =
new float[nbins+1];
2332 binning[nbins]=supremum;
2333 int ev_stepsize = index.size()/nbins;
2334 cout <<
"Event step size: " << ev_stepsize << endl;
2335 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
2336 for (
int ix=1; ix<nbins; ix++){
2337 binning[ix]=(index[ix*ev_stepsize-1].first+index[ix*ev_stepsize].first)*0.5;
2339 tmpbin.
binlow = binning[ix-1];
2341 for (
int bin=0; bin<ev_stepsize; bin++) tmpbin.
events.push_back(index[(ix-1)*ev_stepsize+bin].second);
2342 binList.push_back(tmpbin);
2343 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
2346 tmpbin.
binlow = binning[nbins-1];
2347 tmpbin.
binhigh = binning[nbins];
2348 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index.size(); bin++) tmpbin.
events.push_back(index[bin].second);
2349 binList.push_back(tmpbin);
2350 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
2351 cout <<
"Bin list has the following bins:" << endl;
2352 for (
unsigned int ib=0; ib<binList.size(); ib++){
2353 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
2355 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
2357 TProfile* hvar =
new TProfile(
"candMass",
"", nbins, binning); hvar->Sumw2();
2358 TProfile* hmesq_conserveDifermMass =
new TProfile(
"P_ConserveDifermionMass",
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
2359 TProfile* hmesq_jetPtoEScale =
new TProfile(
"P_MomentumToEnergy",
"", nbins, binning); hmesq_jetPtoEScale->Sumw2();
2363 if (writeFinalTree){
2364 newtree =
new TTree(
"FinalTree",
"");
2365 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
2366 newtree->Branch(
"mesq_jetPtoEScale", &mesq_jetPtoEScale);
2367 newtree->Branch(
"ZZMass", &mzz);
2372 for (
unsigned int bin=0; bin<binList.size(); bin++){
2373 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
2374 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
2375 int getEv = binList.at(bin).events.at(
ev);
2377 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
2378 if (JetPt->size()<1 || JetEta->size()<1 || JetPhi->size()<1 || JetMass->size()<1){
2379 cerr <<
"Jet array sizes are less than Njets!" << endl;
2382 TTree* tree =
findTree(treeList, getEv);
2383 wgt = fabs(genHEPMCweight*nGenMap[tree].first/nGenMap[tree].
second);
2385 TLorentzVector jet, higgs;
2386 jet.SetPtEtaPhiM(JetPt->at(0), JetEta->at(0), JetPhi->at(0), JetMass->at(0));
2387 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
2388 TVector3 boostH = higgs.BoostVector();
2394 for (
int id=0;
id<4;
id++){
2396 if (abs(LepLepId->at(
id))==13) mass = 0.105658;
2397 else if (abs(LepLepId->at(
id))==11) mass = 0.000511;
2398 TLorentzVector pDaughter;
2399 pDaughter.SetPtEtaPhiM(LepPt->at(
id), LepEta->at(
id), LepPhi->at(
id), mass);
2409 mela.computeProdP(mesq_conserveDifermMass,
false);
2410 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
2411 mesq_conserveDifermMass /= pow(alphasVal, 3);
2414 mesq_calc /= cconst_calc;
2415 mesq_conserveDifermMass=mesq_calc;
2418 mela.computeProdP(mesq_jetPtoEScale,
false);
2419 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
2420 mesq_jetPtoEScale /= pow(alphasVal, 3);
2423 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
2425 isnan(mesq_jetPtoEScale) || isinf(mesq_jetPtoEScale)
2428 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, mesq_jetPtoEScale, wgt);
2430 mela.resetInputEvent();
2433 binList.at(bin).sift(); binList.at(bin).adjustWeights();
2435 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
2436 mzz = binList.at(bin).masses.at(
ev);
2437 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
2438 mesq_jetPtoEScale = binList.at(bin).me2vals.at(
ev);
2439 wgt = binList.at(bin).weights.at(
ev);
2440 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass, wgt);
2441 hmesq_jetPtoEScale->Fill(mzz, mesq_jetPtoEScale, wgt);
2442 hvar->Fill(mzz, mzz, wgt);
2443 if (writeFinalTree) newtree->Fill();
2447 double* xexyey[2][4];
2448 for (
int inorm=0; inorm<2; inorm++){
2449 for (
int ix=0; ix<4; ix++) xexyey[inorm][ix] =
new double[nbins];
2450 for (
int bin=0; bin<nbins; bin++){
2451 xexyey[inorm][0][bin] = hvar->GetBinContent(bin+1);
2452 xexyey[inorm][1][bin] = hvar->GetBinError(bin+1);
2454 if (inorm==0)
cout <<
"Bin " << bin <<
" x-center: " << xexyey[inorm][0][bin] <<
" +- " << xexyey[inorm][1][bin] << endl;
2457 xexyey[inorm][2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
2458 xexyey[inorm][3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
2461 xexyey[inorm][2][bin] = hmesq_jetPtoEScale->GetBinContent(bin+1);
2462 xexyey[inorm][3][bin] = hmesq_jetPtoEScale->GetBinError(bin+1);
2464 xexyey[inorm][3][bin] = log10(xexyey[inorm][3][bin])/xexyey[inorm][2][bin];
2465 xexyey[inorm][2][bin] = log10(xexyey[inorm][2][bin]);
2469 for (
int inorm=0; inorm<2; inorm++){
2470 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[inorm][0], xexyey[inorm][2], xexyey[inorm][1], xexyey[inorm][3]);
2471 if (inorm==0) tg->SetName(
"tg_P_ConserveDifermionMass");
2472 else tg->SetName(
"tg_P_MomentumToEnergy");
2473 foutput->WriteTObject(tg);
2477 for (
int inorm=0; inorm<2; inorm++){
2478 for (
int ix=0; ix<4; ix++)
delete[] xexyey[inorm][ix];
2480 foutput->WriteTObject(hmesq_jetPtoEScale);
2481 foutput->WriteTObject(hmesq_conserveDifermMass);
2482 foutput->WriteTObject(hvar);
2483 if (writeFinalTree) foutput->WriteTObject(newtree);
2484 if (writeFinalTree)
delete newtree;
2485 delete hmesq_conserveDifermMass;
2486 delete hmesq_jetPtoEScale;
2490 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
2501 if (!(strprod ==
"Had_ZH" || strprod ==
"Had_WH"))
return;
2504 TString TREE_NAME =
"ZZTree/candTree";
2505 TString COUNTERS_NAME =
"ZZTree/Counters";
2506 bool writeFinalTree=
true;
2515 TString strsamples=
"";
2517 if (strprod ==
"Had_ZH") strsamples=
"ZH";
2518 else if (strprod ==
"Had_WH") strsamples=
"WH";
2526 Mela mela(erg_tev, mPOLE, verbosity);
2528 std::vector<short>* LepLepId=0;
2529 std::vector<float>* LepPt=0;
2530 std::vector<float>* LepEta=0;
2531 std::vector<float>* LepPhi=0;
2534 std::vector<float>* JetPt=0;
2535 std::vector<float>* JetEta=0;
2536 std::vector<float>* JetPhi=0;
2537 std::vector<float>* JetMass=0;
2538 std::vector<float> myJetPt;
2539 std::vector<float> myJetEta;
2540 std::vector<float> myJetPhi;
2541 std::vector<float> myJetMass;
2543 float mesq_calc=0., cconst_calc=1., pmavjj=1.;
2544 float mesq_conserveDifermMass=0;
2546 float m1 = 91.471450;
2547 float m2 = 12.139782;
2548 float h1 = 0.2682896;
2549 float h2 = 0.1679779;
2550 float phi = 1.5969792;
2551 float hs = -0.727181;
2552 float phi1 = 1.8828257;
2553 float ZZPt, ZZPhi, ZZEta;
2554 short Z1Flav, Z2Flav;
2555 float genxsec=0, genBR=0, ngen=0, genHEPMCweight=0;
2559 bool recomputePmavjj=
false;
2560 TString strrewgtbranch=
"";
2561 TString strrecalcbranch=
"";
2562 TString strrecalcconstbranch=
"";
2563 TString strpmavjjbranch=
"";
2565 TString cinput_main;
2573 unordered_map<TTree*, pair<float, float>> nGenMap;
2574 unordered_map<TTree*, float> mass_map;
2575 unordered_map<float, vector<TTree*>> mass_sample_map;
2577 vector<TFile*> finputList;
2578 vector<TTree*> treeList;
2580 for (
unsigned int is=0; is<strSamples.size(); is++){
2581 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples[is]).Data());
2582 TFile* finput = TFile::Open(cinput,
"read");
2583 cout <<
"Opening file " << cinput <<
"..." << endl;
2586 if (finput->IsOpen() && !finput->IsZombie()){
2587 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
2588 tree = (TTree*)finput->Get(TREE_NAME);
2590 cout << TREE_NAME <<
" is found." << endl;
2592 if (
prod==
TVar::Had_ZH && tree->GetBranchStatus(
"pConst_HadZH_SIG_ghz1_1_JHUGen_JECNominal")!=0){
2593 strrecalcbranch =
"p_HadZH_SIG_ghz1_1_JHUGen_JECNominal";
2594 strrecalcconstbranch =
"pConst_HadZH_SIG_ghz1_1_JHUGen_JECNominal";
2596 else if (
prod==
TVar::Had_WH && tree->GetBranchStatus(
"pConst_HadWH_SIG_ghw1_1_JHUGen_JECNominal")!=0){
2597 strrecalcbranch =
"p_HadWH_SIG_ghw1_1_JHUGen_JECNominal";
2598 strrecalcconstbranch =
"pConst_HadWH_SIG_ghw1_1_JHUGen_JECNominal";
2600 else recalculate=
true;
2601 if (
prod==
TVar::Had_ZH && tree->GetBranchStatus(
"p_HadZH_mavjj_JECNominal")!=0) strpmavjjbranch=
"p_HadZH_mavjj_JECNominal";
2602 else if (
prod==
TVar::Had_WH && tree->GetBranchStatus(
"p_HadWH_mavjj_JECNominal")!=0) strpmavjjbranch=
"p_HadWH_mavjj_JECNominal";
2603 else recomputePmavjj=
true;
2605 tree->SetBranchStatus(
"*", 0);
2606 tree->SetBranchStatus(
"genxsec", 1); tree->SetBranchAddress(
"genxsec", &genxsec); tree->SetBranchStatus(
"genBR", 1); tree->SetBranchAddress(
"genBR", &genBR);
2607 tree->SetBranchStatus(
"genHEPMCweight", 1); tree->SetBranchAddress(
"genHEPMCweight", &genHEPMCweight);
2608 tree->SetBranchStatus(
"nCleanedJetsPt30", 1); tree->SetBranchAddress(
"nCleanedJetsPt30", &NJets30);
2609 tree->SetBranchStatus(
"JetPt", 1); tree->SetBranchAddress(
"JetPt", &JetPt);
2610 tree->SetBranchStatus(
"JetEta", 1); tree->SetBranchAddress(
"JetEta", &JetEta);
2611 tree->SetBranchStatus(
"JetPhi", 1); tree->SetBranchAddress(
"JetPhi", &JetPhi);
2612 tree->SetBranchStatus(
"JetMass", 1); tree->SetBranchAddress(
"JetMass", &JetMass);
2613 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
2614 tree->SetBranchStatus(
"ZZPt", 1); tree->SetBranchAddress(
"ZZPt", &ZZPt);
2615 tree->SetBranchStatus(
"ZZEta", 1); tree->SetBranchAddress(
"ZZEta", &ZZEta);
2616 tree->SetBranchStatus(
"ZZPhi", 1); tree->SetBranchAddress(
"ZZPhi", &ZZPhi);
2617 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
2618 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
2619 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
2620 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
2621 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
2622 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
2623 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
2624 tree->SetBranchStatus(
"LepLepId", 1); tree->SetBranchAddress(
"LepLepId", &LepLepId);
2625 tree->SetBranchStatus(
"LepPt", 1); tree->SetBranchAddress(
"LepPt", &LepPt);
2626 tree->SetBranchStatus(
"LepEta", 1); tree->SetBranchAddress(
"LepEta", &LepEta);
2627 tree->SetBranchStatus(
"LepPhi", 1); tree->SetBranchAddress(
"LepPhi", &LepPhi);
2628 tree->SetBranchStatus(
"Z1Flav", 1); tree->SetBranchAddress(
"Z1Flav", &Z1Flav);
2629 tree->SetBranchStatus(
"Z2Flav", 1); tree->SetBranchAddress(
"Z2Flav", &Z2Flav);
2631 tree->SetBranchStatus(strrecalcbranch, 1); tree->SetBranchAddress(strrecalcbranch, &mesq_calc);
2632 tree->SetBranchStatus(strrecalcconstbranch, 1); tree->SetBranchAddress(strrecalcconstbranch, &cconst_calc);
2633 cout <<
"Extracting ME from " << strrecalcbranch <<
" and const from " << strrecalcconstbranch << endl;
2635 else cout <<
"Recalculating the ME" << endl;
2636 if (!recomputePmavjj && strpmavjjbranch!=
""){
2637 tree->SetBranchStatus(strpmavjjbranch, 1);
2638 tree->SetBranchAddress(strpmavjjbranch, &pmavjj);
2639 cout <<
"Extracting P_V(mJJ) from " << strpmavjjbranch << endl;
2641 else if (recomputePmavjj)
cout <<
"Recomputing P_V(mJJ)" << endl;
2642 else cout <<
"No valid P_V(mJJ)" << endl;
2644 cout <<
"Cross section = " << genxsec*genBR << endl;
2646 TH1F* htmp = (TH1F*)finput->Get(COUNTERS_NAME);
2647 pair<float, float> nsum(htmp->GetBinContent(1), htmp->GetBinContent(41));
2650 nEntries += tree->GetEntries();
2651 treeList.push_back(tree);
2652 finputList.push_back(finput);
2655 cout <<
"Pole mass = " << polemass << endl;
2656 mass_map[tree]=polemass;
2657 if (mass_sample_map.find(polemass)==mass_sample_map.end()){
2658 cout <<
"Inserting new pole mass sample array" << endl;
2659 vector<TTree*> dumarr;
2660 mass_sample_map[polemass] = dumarr;
2662 mass_sample_map[polemass].push_back(tree);
2664 else finput->Close();
2666 else if (finput->IsOpen()) finput->Close();
2669 cout <<
"NEntries = " << nEntries << endl;
2671 for (
auto it = mass_sample_map.begin(); it != mass_sample_map.end(); ++it){
2674 for (
unsigned int ix=0; ix<it->second.size(); ix++){
2675 it->second.at(ix)->GetEntry(0);
2676 sum_ngen += nGenMap[it->second.at(ix)].first;
2677 sum_xsec += genxsec*genBR;
2679 float overallWeight = sum_ngen/sum_xsec;
2680 for (
unsigned int ix=0; ix<it->second.size(); ix++){
2681 cout <<
"Sum Hep MC weights in tree " << ix <<
" / " << it->second.size() <<
" was " << nGenMap[it->second.at(ix)].second <<
" over " << nGenMap[it->second.at(ix)].first <<
" total gen. events." << endl;
2682 nGenMap[it->second.at(ix)].first = overallWeight/nGenMap[it->second.at(ix)].second;
2683 cout <<
"Event scale for tree " << ix <<
" / " << it->second.size() <<
" at pole mass " << it->first <<
" = " << nGenMap[it->second.at(ix)].first << endl;
2687 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
2689 vector<pair<float, int>> index;
2690 unsigned int ev_acc=0;
2691 for (
int ev=0;
ev<nEntries;
ev++){
2693 bool doProcess=NJets30>=2;
2694 if (!doProcess)
continue;
2695 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
2696 unsigned int ic = (Z1Flav*Z2Flav==pow(13, 4))*0 + (Z1Flav*Z2Flav==pow(11, 4))*1 + (Z1Flav*Z2Flav==pow(11*13, 2))*2;
2701 float firstVal=index.at(0).first;
2702 float lastVal=index.at(index.size()-1).first;
2703 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
2704 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
2705 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
2707 float divisor=30000;
2710 int nbins = index.size()/divisor;
2711 const int nbins_th=8;
2712 while (nbins<nbins_th){
2713 if (divisor>1000) divisor -= 1000;
2714 else if (divisor>100) divisor -= 100;
2716 nbins=index.size()/divisor;
2718 cout <<
"nbins=" << nbins << endl;
2719 if (nbins<3) cerr <<
"Not enough bins!" << endl;
2720 vector<ExtBin> binList;
2721 float* binning =
new float[nbins+1];
2723 binning[nbins]=supremum;
2724 int ev_stepsize = index.size()/nbins;
2725 cout <<
"Event step size: " << ev_stepsize << endl;
2726 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
2727 for (
int ix=1; ix<nbins; ix++){
2728 binning[ix]=(index[ix*ev_stepsize-1].first+index[ix*ev_stepsize].first)*0.5;
2730 tmpbin.
binlow = binning[ix-1];
2732 for (
int bin=0; bin<ev_stepsize; bin++) tmpbin.
events.push_back(index[(ix-1)*ev_stepsize+bin].second);
2733 binList.push_back(tmpbin);
2734 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
2737 tmpbin.
binlow = binning[nbins-1];
2738 tmpbin.
binhigh = binning[nbins];
2739 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index.size(); bin++) tmpbin.
events.push_back(index[bin].second);
2740 binList.push_back(tmpbin);
2741 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
2742 cout <<
"Bin list has the following bins:" << endl;
2743 for (
unsigned int ib=0; ib<binList.size(); ib++){
2744 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
2747 TProfile* hvar =
new TProfile(
"candMass",
"", nbins, binning); hvar->Sumw2();
2748 TProfile* hmesq_conserveDifermMass =
new TProfile(
"P_ConserveDifermionMass",
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
2751 if (writeFinalTree){
2752 newtree =
new TTree(
"FinalTree",
"");
2753 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
2754 newtree->Branch(
"ZZMass", &mzz);
2755 newtree->Branch(
"weight", &wgt);
2760 double aL1=0, aR1=0, aL2=0, aR2=0;
2764 for (
unsigned int bin=0; bin<binList.size(); bin++){
2765 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
2766 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
2767 int getEv = binList.at(bin).events.at(
ev);
2769 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
2770 if (JetPt->size()<2 || JetEta->size()<2 || JetPhi->size()<2 || JetMass->size()<2){
2771 cerr <<
"Jet array sizes are less than Njets!" << endl;
2774 TTree* tree =
findTree(treeList, getEv);
2775 wgt = fabs(genxsec*genBR*genHEPMCweight*nGenMap[tree].first*rewgt);
2777 TLorentzVector jet[2], higgs;
2778 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(JetPt->at(ij), JetEta->at(ij), JetPhi->at(ij), JetMass->at(ij));
2779 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
2780 TVector3 boostH = higgs.BoostVector();
2787 for (
int id=0;
id<4;
id++){
2789 if (abs(LepLepId->at(
id))==13) mass = 0.105658;
2790 else if (abs(LepLepId->at(
id))==11) mass = 0.000511;
2791 TLorentzVector pDaughter;
2792 pDaughter.SetPtEtaPhiM(LepPt->at(
id), LepEta->at(
id), LepPhi->at(
id), mass);
2800 double propagatorV=1;
2801 if (recalculate || ev_acc==0){
2803 mela.computeProdP(mesq_conserveDifermMass,
false);
2805 mesq_calc /= cconst_calc;
2806 mesq_conserveDifermMass=mesq_calc;
2808 mh = mass_map[tree];
2809 gah =
mela.getHiggsWidthAtPoleMass(mh);
2812 mela.getIORecord()->getHiggsMassWidth(mh, gah, 0);
2814 mela.getIORecord()->getVDaughterCouplings(aL1, aR1, 0);
2815 mela.getIORecord()->getVDaughterCouplings(aL2, aR2, 1);
2817 mv =
mela.getPrimaryMass(23);
2818 gav =
mela.getPrimaryWidth(23);
2821 mv =
mela.getPrimaryMass(24);
2822 gav =
mela.getPrimaryWidth(24);
2826 mesq_calc /= cconst_calc;
2827 mesq_conserveDifermMass=mesq_calc;
2829 propagator = 1./(pow(pow(mzz, 2)-pow(mh, 2), 2) + pow(mh*gah, 2));
2832 double mjj = (jet[0] + jet[1]).M();
2833 propagatorV = 1./(pow(pow(mjj, 2)-pow(mv, 2), 2) + pow(mv*gav, 2));
2834 mesq_conserveDifermMass /= propagatorV;
2836 if (recomputePmavjj)
mela.computeDijetConvBW(pmavjj,
false);
2837 mesq_conserveDifermMass *= pmavjj;
2840 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
2843 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, 0, wgt);
2845 mela.resetInputEvent();
2849 binList.at(bin).sift(); binList.at(bin).adjustWeights(10);
2851 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
2852 mzz = binList.at(bin).masses.at(
ev);
2853 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
2854 wgt = binList.at(bin).weights.at(
ev);
2855 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
2856 hvar->Fill(mzz, mzz);
2857 if (writeFinalTree) newtree->Fill();
2860 cout <<
"Total events accumulated: " << ev_acc << endl;
2863 for (
int ix=0; ix<4; ix++) xexyey[ix] =
new double[nbins];
2864 for (
int bin=0; bin<nbins; bin++){
2865 xexyey[0][bin] = hvar->GetBinContent(bin+1);
2866 xexyey[1][bin] = hvar->GetBinError(bin+1);
2868 cout <<
"Bin " << bin <<
" x-center: " << xexyey[0][bin] <<
" +- " << xexyey[1][bin] << endl;
2870 xexyey[2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
2871 xexyey[3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
2872 xexyey[3][bin] = log10(xexyey[3][bin])/xexyey[2][bin];
2873 xexyey[2][bin] = log10(xexyey[2][bin]);
2876 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
2877 tg->SetName(Form(
"tg_%s", hmesq_conserveDifermMass->GetName()));
2878 foutput->WriteTObject(tg);
2881 for (
int ix=0; ix<4; ix++)
delete[] xexyey[ix];
2883 foutput->WriteTObject(hmesq_conserveDifermMass);
2884 foutput->WriteTObject(hvar);
2885 if (writeFinalTree) foutput->WriteTObject(newtree);
2886 if (writeFinalTree)
delete newtree;
2887 delete hmesq_conserveDifermMass;
2892 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
2904 if (!(strprod ==
"Had_ZH_S" || strprod ==
"Had_WH_S" || strprod ==
"JJVBF_S"))
return;
2907 TString TREE_NAME =
"ZZTree/candTree";
2908 TString COUNTERS_NAME =
"ZZTree/Counters";
2909 bool writeFinalTree=
true;
2919 if (strprod ==
"Had_ZH_S") strsamples=
"ZH";
2920 else if (strprod ==
"Had_WH_S") strsamples=
"WH";
2921 else if (strprod ==
"JJVBF_S") strsamples=
"JJVBF";
2927 Mela mela(erg_tev, mPOLE, verbosity);
2929 std::vector<short>* LepLepId=0;
2930 std::vector<float>* LepPt=0;
2931 std::vector<float>* LepEta=0;
2932 std::vector<float>* LepPhi=0;
2935 std::vector<float>* JetPt=0;
2936 std::vector<float>* JetEta=0;
2937 std::vector<float>* JetPhi=0;
2938 std::vector<float>* JetMass=0;
2939 std::vector<float> myJetPt;
2940 std::vector<float> myJetEta;
2941 std::vector<float> myJetPhi;
2942 std::vector<float> myJetMass;
2944 float mesq_calc=0., cconst_calc=1., pmavjj=1.;
2945 float mesq_conserveDifermMass=0;
2947 float m1 = 91.471450;
2948 float m2 = 12.139782;
2949 float h1 = 0.2682896;
2950 float h2 = 0.1679779;
2951 float phi = 1.5969792;
2952 float hs = -0.727181;
2953 float phi1 = 1.8828257;
2954 float ZZPt, ZZPhi, ZZEta;
2955 short Z1Flav, Z2Flav;
2956 float genxsec=0, genBR=0, ngen=0, genHEPMCweight=0;
2960 bool recomputePmavjj=
false;
2961 TString strrewgtbranch=
"";
2962 TString strrecalcbranch=
"";
2963 TString strrecalcconstbranch=
"";
2964 TString strpmavjjbranch=
"";
2966 TString cinput_main;
2970 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
2973 unordered_map<TTree*, pair<float, float>> nGenMap;
2974 unordered_map<TTree*, float> mass_map;
2975 unordered_map<float, vector<TTree*>> mass_sample_map;
2977 vector<TFile*> finputList;
2978 vector<TTree*> treeList;
2980 for (
unsigned int is=0; is<strSamples.size(); is++){
2981 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples[is]).Data());
2982 TFile* finput = TFile::Open(cinput,
"read");
2983 cout <<
"Opening file " << cinput <<
"..." << endl;
2986 if (finput->IsOpen() && !finput->IsZombie()){
2987 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
2988 tree = (TTree*)finput->Get(TREE_NAME);
2990 cout << TREE_NAME <<
" is found." << endl;
2992 if (
prod==
TVar::Had_ZH_S && tree->GetBranchStatus(
"pConst_HadZH_S_SIG_ghz1_1_MCFM_JECNominal")!=0){
2993 strrecalcbranch =
"p_HadZH_S_SIG_ghz1_1_MCFM_JECNominal";
2994 strrecalcconstbranch =
"pConst_HadZH_S_SIG_ghz1_1_MCFM_JECNominal";
2996 else if (
prod==
TVar::Had_WH_S && tree->GetBranchStatus(
"pConst_HadWH_S_SIG_ghv1_1_MCFM_JECNominal")!=0){
2997 strrecalcbranch =
"p_HadWH_S_SIG_ghv1_1_MCFM_JECNominal";
2998 strrecalcconstbranch =
"pConst_HadWH_S_SIG_ghv1_1_MCFM_JECNominal";
3000 else if (
prod==
TVar::JJVBF_S && tree->GetBranchStatus(
"pConst_JJVBF_S_SIG_ghv1_1_MCFM_JECNominal")!=0){
3001 strrecalcbranch =
"p_JJVBF_S_SIG_ghv1_1_MCFM_JECNominal";
3002 strrecalcconstbranch =
"pConst_JJVBF_S_SIG_ghv1_1_MCFM_JECNominal";
3004 else recalculate=
true;
3005 if (
prod==
TVar::Had_ZH_S && tree->GetBranchStatus(
"p_HadZH_mavjj_JECNominal")!=0) strpmavjjbranch=
"p_HadZH_mavjj_JECNominal";
3006 else if (
prod==
TVar::Had_WH_S && tree->GetBranchStatus(
"p_HadWH_mavjj_JECNominal")!=0) strpmavjjbranch=
"p_HadWH_mavjj_JECNominal";
3009 tree->SetBranchStatus(
"*", 0);
3010 tree->SetBranchStatus(
"genxsec", 1); tree->SetBranchAddress(
"genxsec", &genxsec); tree->SetBranchStatus(
"genBR", 1); tree->SetBranchAddress(
"genBR", &genBR);
3011 tree->SetBranchStatus(
"genHEPMCweight", 1); tree->SetBranchAddress(
"genHEPMCweight", &genHEPMCweight);
3012 tree->SetBranchStatus(
"nCleanedJetsPt30", 1); tree->SetBranchAddress(
"nCleanedJetsPt30", &NJets30);
3013 tree->SetBranchStatus(
"JetPt", 1); tree->SetBranchAddress(
"JetPt", &JetPt);
3014 tree->SetBranchStatus(
"JetEta", 1); tree->SetBranchAddress(
"JetEta", &JetEta);
3015 tree->SetBranchStatus(
"JetPhi", 1); tree->SetBranchAddress(
"JetPhi", &JetPhi);
3016 tree->SetBranchStatus(
"JetMass", 1); tree->SetBranchAddress(
"JetMass", &JetMass);
3017 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
3018 tree->SetBranchStatus(
"ZZPt", 1); tree->SetBranchAddress(
"ZZPt", &ZZPt);
3019 tree->SetBranchStatus(
"ZZEta", 1); tree->SetBranchAddress(
"ZZEta", &ZZEta);
3020 tree->SetBranchStatus(
"ZZPhi", 1); tree->SetBranchAddress(
"ZZPhi", &ZZPhi);
3021 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
3022 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
3023 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
3024 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
3025 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
3026 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
3027 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
3028 tree->SetBranchStatus(
"LepLepId", 1); tree->SetBranchAddress(
"LepLepId", &LepLepId);
3029 tree->SetBranchStatus(
"LepPt", 1); tree->SetBranchAddress(
"LepPt", &LepPt);
3030 tree->SetBranchStatus(
"LepEta", 1); tree->SetBranchAddress(
"LepEta", &LepEta);
3031 tree->SetBranchStatus(
"LepPhi", 1); tree->SetBranchAddress(
"LepPhi", &LepPhi);
3032 tree->SetBranchStatus(
"Z1Flav", 1); tree->SetBranchAddress(
"Z1Flav", &Z1Flav);
3033 tree->SetBranchStatus(
"Z2Flav", 1); tree->SetBranchAddress(
"Z2Flav", &Z2Flav);
3035 tree->SetBranchStatus(strrecalcbranch, 1); tree->SetBranchAddress(strrecalcbranch, &mesq_calc);
3036 tree->SetBranchStatus(strrecalcconstbranch, 1); tree->SetBranchAddress(strrecalcconstbranch, &cconst_calc);
3037 cout <<
"Extracting ME from " << strrecalcbranch <<
" and const from " << strrecalcconstbranch << endl;
3039 else cout <<
"Recalculating the ME" << endl;
3040 if (!recomputePmavjj && strpmavjjbranch!=
""){
3041 tree->SetBranchStatus(strpmavjjbranch, 1);
3042 tree->SetBranchAddress(strpmavjjbranch, &pmavjj);
3043 cout <<
"Extracting P_V(mJJ) from " << strpmavjjbranch << endl;
3045 else if (recomputePmavjj)
cout <<
"Recomputing P_V(mJJ)" << endl;
3046 else cout <<
"No valid P_V(mJJ)" << endl;
3049 cout <<
"Cross section = " << genxsec*genBR << endl;
3051 TH1F* htmp = (TH1F*)finput->Get(COUNTERS_NAME);
3052 pair<float, float> nsum(htmp->GetBinContent(1), htmp->GetBinContent(41));
3055 nEntries += tree->GetEntries();
3056 treeList.push_back(tree);
3057 finputList.push_back(finput);
3060 cout <<
"Pole mass = " << polemass << endl;
3061 mass_map[tree]=polemass;
3062 if (mass_sample_map.find(polemass)==mass_sample_map.end()){
3063 cout <<
"Inserting new pole mass sample array" << endl;
3064 vector<TTree*> dumarr;
3065 mass_sample_map[polemass] = dumarr;
3067 mass_sample_map[polemass].push_back(tree);
3069 else finput->Close();
3071 else if (finput->IsOpen()) finput->Close();
3074 cout <<
"NEntries = " << nEntries << endl;
3076 for (
auto it = mass_sample_map.begin(); it != mass_sample_map.end(); ++it){
3079 for (
unsigned int ix=0; ix<it->second.size(); ix++){
3080 it->second.at(ix)->GetEntry(0);
3081 sum_ngen += nGenMap[it->second.at(ix)].first;
3082 sum_xsec += genxsec*genBR;
3084 float overallWeight = sum_ngen/sum_xsec;
3085 for (
unsigned int ix=0; ix<it->second.size(); ix++){
3086 cout <<
"Sum Hep MC weights in tree " << ix <<
" / " << it->second.size() <<
" was " << nGenMap[it->second.at(ix)].second <<
" over " << nGenMap[it->second.at(ix)].first <<
" total gen. events." << endl;
3087 nGenMap[it->second.at(ix)].first = overallWeight/nGenMap[it->second.at(ix)].second;
3088 cout <<
"Event scale for tree " << ix <<
" / " << it->second.size() <<
" at pole mass " << it->first <<
" = " << nGenMap[it->second.at(ix)].first << endl;
3092 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
3094 vector<pair<float, int>> index[3];
3095 unsigned int ev_acc=0;
3096 for (
int ev=0;
ev<nEntries;
ev++){
3100 Z1Flav*Z2Flav==pow(13, 4)
3102 Z1Flav*Z2Flav==pow(11, 4)
3104 Z1Flav*Z2Flav==pow(11*13, 2)
3107 if (!doProcess)
continue;
3108 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
3109 unsigned int ic = (Z1Flav*Z2Flav==pow(13, 4))*0 + (Z1Flav*Z2Flav==pow(11, 4))*1 + (Z1Flav*Z2Flav==pow(11*13, 2))*2;
3115 for (
unsigned int ic=0; ic<3; ic++){
3116 float firstVal=index[ic].at(0).first;
3117 float lastVal=index[ic].at(index[ic].size()-1).first;
3118 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
3119 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
3120 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
3122 float divisor=15000;
3124 int nbins = index[ic].size()/divisor;
3125 const int nbins_th=10;
3126 while (nbins<nbins_th){
3127 if (divisor>1000) divisor -= 1000;
3128 else if (divisor>100) divisor -= 100;
3130 nbins=index[ic].size()/divisor;
3132 cout <<
"nbins=" << nbins << endl;
3133 if (nbins<3) cerr <<
"Not enough bins!" << endl;
3134 vector<ExtBin> binList;
3135 float* binning =
new float[nbins+1];
3137 binning[nbins]=supremum;
3138 int ev_stepsize = index[ic].size()/nbins;
3139 cout <<
"Event step size: " << ev_stepsize << endl;
3140 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
3141 for (
int ix=1; ix<nbins; ix++){
3142 binning[ix]=(index[ic][ix*ev_stepsize-1].first+index[ic][ix*ev_stepsize].first)*0.5;
3144 tmpbin.
binlow = binning[ix-1];
3146 for (
int bin=0; bin<ev_stepsize; bin++) tmpbin.
events.push_back(index[ic][(ix-1)*ev_stepsize+bin].second);
3147 binList.push_back(tmpbin);
3148 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ic][ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
3151 tmpbin.
binlow = binning[nbins-1];
3152 tmpbin.
binhigh = binning[nbins];
3153 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index[ic].size(); bin++) tmpbin.
events.push_back(index[ic][bin].second);
3154 binList.push_back(tmpbin);
3155 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
3156 cout <<
"Bin list has the following bins:" << endl;
3157 for (
unsigned int ib=0; ib<binList.size(); ib++){
3158 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
3161 TProfile* hvar =
new TProfile(Form(
"candMass_%s", strchannel[ic].Data()),
"", nbins, binning); hvar->Sumw2();
3162 TProfile* hmesq_conserveDifermMass =
new TProfile(Form(
"P_ConserveDifermionMass_%s", strchannel[ic].Data()),
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
3165 if (writeFinalTree){
3166 newtree =
new TTree(Form(
"FinalTree_%s", strchannel[ic].Data()),
"");
3167 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
3168 newtree->Branch(
"ZZMass", &mzz);
3169 newtree->Branch(
"weight", &wgt);
3174 double aL1=0, aR1=0, aL2=0, aR2=0;
3177 unsigned int ev_acc=0;
3178 for (
unsigned int bin=0; bin<binList.size(); bin++){
3179 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
3180 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
3181 int getEv = binList.at(bin).events.at(
ev);
3183 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
3184 if (JetPt->size()<2 || JetEta->size()<2 || JetPhi->size()<2 || JetMass->size()<2){
3185 cerr <<
"Jet array sizes are less than Njets!" << endl;
3188 TTree* tree =
findTree(treeList, getEv);
3189 wgt = fabs(genxsec*genBR*genHEPMCweight*nGenMap[tree].first*rewgt);
3191 TLorentzVector jet[2], higgs;
3192 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(JetPt->at(ij), JetEta->at(ij), JetPhi->at(ij), JetMass->at(ij));
3193 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
3194 TVector3 boostH = higgs.BoostVector();
3201 for (
int id=0;
id<4;
id++){
3203 if (abs(LepLepId->at(
id))==13) mass = 0.105658;
3204 else if (abs(LepLepId->at(
id))==11) mass = 0.000511;
3205 TLorentzVector pDaughter;
3206 pDaughter.SetPtEtaPhiM(LepPt->at(
id), LepEta->at(
id), LepPhi->at(
id), mass);
3214 double propagatorV=1;
3215 if (recalculate || ev_acc==0){
3217 mela.computeProdP(mesq_conserveDifermMass,
false);
3219 mesq_calc /= cconst_calc;
3220 mesq_conserveDifermMass=mesq_calc;
3223 gah =
mela.getHiggsWidthAtPoleMass(mh);
3226 mela.getIORecord()->getHiggsMassWidth(mh, gah, 0);
3228 mela.getIORecord()->getVDaughterCouplings(aL1, aR1, 0);
3229 mela.getIORecord()->getVDaughterCouplings(aL2, aR2, 1);
3231 mv =
mela.getPrimaryMass(23);
3232 gav =
mela.getPrimaryWidth(23);
3235 mv =
mela.getPrimaryMass(24);
3236 gav =
mela.getPrimaryWidth(24);
3240 mesq_calc /= cconst_calc;
3241 mesq_conserveDifermMass=mesq_calc;
3243 propagator = 1./(pow(pow(mzz, 2)-pow(mh, 2), 2) + pow(mh*gah, 2));
3245 if (fabs(aL1)>0. || fabs(aR1)>0.) mesq_conserveDifermMass /= pow(aL1, 2)+pow(aR1, 2);
3246 if (fabs(aL2)>0. || fabs(aR2)>0.) mesq_conserveDifermMass /= pow(aL2, 2)+pow(aR2, 2);
3248 double mjj = (jet[0] + jet[1]).M();
3249 propagatorV = 1./(pow(pow(mjj, 2)-pow(mv, 2), 2) + pow(mv*gav, 2));
3250 mesq_conserveDifermMass /= propagatorV;
3251 if (recomputePmavjj){
3253 mela.computeDijetConvBW(pmavjj,
false);
3255 mesq_conserveDifermMass *= pmavjj;
3259 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
3262 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, 0, wgt);
3264 mela.resetInputEvent();
3268 binList.at(bin).sift(); binList.at(bin).adjustWeights(10);
3270 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
3271 mzz = binList.at(bin).masses.at(
ev);
3272 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
3273 wgt = binList.at(bin).weights.at(
ev);
3274 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
3275 hvar->Fill(mzz, mzz);
3276 if (writeFinalTree) newtree->Fill();
3279 cout <<
"Total events accumulated: " << ev_acc << endl;
3282 for (
int ix=0; ix<4; ix++) xexyey[ix] =
new double[nbins];
3283 for (
int bin=0; bin<nbins; bin++){
3284 xexyey[0][bin] = hvar->GetBinContent(bin+1);
3285 xexyey[1][bin] = hvar->GetBinError(bin+1);
3287 cout <<
"Bin " << bin <<
" x-center: " << xexyey[0][bin] <<
" +- " << xexyey[1][bin] << endl;
3289 xexyey[2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
3290 xexyey[3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
3291 xexyey[3][bin] = log10(xexyey[3][bin])/xexyey[2][bin];
3292 xexyey[2][bin] = log10(xexyey[2][bin]);
3295 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
3296 tg->SetName(Form(
"tg_%s", hmesq_conserveDifermMass->GetName()));
3297 foutput->WriteTObject(tg);
3300 for (
int ix=0; ix<4; ix++)
delete[] xexyey[ix];
3302 foutput->WriteTObject(hmesq_conserveDifermMass);
3303 foutput->WriteTObject(hvar);
3304 if (writeFinalTree) foutput->WriteTObject(newtree);
3305 if (writeFinalTree)
delete newtree;
3306 delete hmesq_conserveDifermMass;
3311 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
3322 if (!(strprod ==
"Had_ZH" || strprod ==
"Had_WH" || strprod ==
"JJVBF"))
return;
3325 TString TREE_NAME =
"ZZTree/candTree";
3326 TString COUNTERS_NAME =
"ZZTree/Counters";
3327 bool writeFinalTree=
true;
3337 if (strprod ==
"Had_ZH") strsamples=
"ZH";
3338 else if (strprod ==
"Had_WH") strsamples=
"WH";
3339 else if (strprod ==
"JJVBF") strsamples=
"JJVBF";
3345 Mela mela(erg_tev, mPOLE, verbosity);
3347 std::vector<short>* LepLepId=0;
3348 std::vector<float>* LepPt=0;
3349 std::vector<float>* LepEta=0;
3350 std::vector<float>* LepPhi=0;
3353 std::vector<float>* JetPt=0;
3354 std::vector<float>* JetEta=0;
3355 std::vector<float>* JetPhi=0;
3356 std::vector<float>* JetMass=0;
3357 std::vector<float> myJetPt;
3358 std::vector<float> myJetEta;
3359 std::vector<float> myJetPhi;
3360 std::vector<float> myJetMass;
3363 std::vector<float>* LHEMotherPz=0;
3364 std::vector<float>* LHEMotherE=0;
3365 std::vector<short>* LHEMotherId=0;
3366 std::vector<float>* LHEDaughterPt=0;
3367 std::vector<float>* LHEDaughterEta=0;
3368 std::vector<float>* LHEDaughterPhi=0;
3369 std::vector<float>* LHEDaughterMass=0;
3370 std::vector<short>* LHEDaughterId=0;
3371 std::vector<float>* LHEAssociatedParticlePt=0;
3372 std::vector<float>* LHEAssociatedParticleEta=0;
3373 std::vector<float>* LHEAssociatedParticlePhi=0;
3374 std::vector<float>* LHEAssociatedParticleMass=0;
3375 std::vector<short>* LHEAssociatedParticleId=0;
3377 float mesq_calc=0., cconst_calc=1., pmavjj=1.;
3378 float mesq_conserveDifermMass=0;
3380 float m1 = 91.471450;
3381 float m2 = 12.139782;
3382 float h1 = 0.2682896;
3383 float h2 = 0.1679779;
3384 float phi = 1.5969792;
3385 float hs = -0.727181;
3386 float phi1 = 1.8828257;
3387 float ZZPt, ZZPhi, ZZEta;
3388 short Z1Flav, Z2Flav;
3389 float genxsec=0, genBR=0, ngen=0, genHEPMCweight=0;
3393 bool recomputePmavjj=
false;
3394 TString strrewgtbranch=
"";
3395 TString strrecalcbranch=
"";
3396 TString strrecalcconstbranch=
"";
3397 TString strpmavjjbranch=
"";
3399 TString cinput_main;
3403 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
3406 unordered_map<TTree*, pair<float, float>> nGenMap;
3407 unordered_map<TTree*, float> mass_map;
3408 unordered_map<float, vector<TTree*>> mass_sample_map;
3410 vector<TFile*> finputList;
3411 vector<TTree*> treeList;
3413 for (
unsigned int is=0; is<strSamples.size(); is++){
3414 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples[is]).Data());
3415 TFile* finput = TFile::Open(cinput,
"read");
3416 cout <<
"Opening file " << cinput <<
"..." << endl;
3419 if (finput->IsOpen() && !finput->IsZombie()){
3420 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
3421 tree = (TTree*)finput->Get(TREE_NAME);
3423 cout << TREE_NAME <<
" is found." << endl;
3425 if (
prod==
TVar::Had_ZH && tree->GetBranchStatus(
"pConst_HadZH_BKG_MCFM_JECNominal")!=0){
3426 strrecalcbranch =
"p_HadZH_BKG_MCFM_JECNominal";
3427 strrecalcconstbranch =
"pConst_HadZH_BKG_MCFM_JECNominal";
3429 else if (
prod==
TVar::Had_WH && tree->GetBranchStatus(
"pConst_HadWH_BKG_MCFM_JECNominal")!=0){
3430 strrecalcbranch =
"p_HadWH_BKG_MCFM_JECNominal";
3431 strrecalcconstbranch =
"pConst_HadWH_BKG_MCFM_JECNominal";
3433 else if (
prod==
TVar::JJVBF && tree->GetBranchStatus(
"pConst_JJVBF_BKG_MCFM_JECNominal")!=0){
3434 strrecalcbranch =
"p_JJVBF_BKG_MCFM_JECNominal";
3435 strrecalcconstbranch =
"pConst_JJVBF_BKG_MCFM_JECNominal";
3437 else recalculate=
true;
3438 if (
prod==
TVar::Had_ZH && tree->GetBranchStatus(
"p_HadZH_mavjj_JECNominal")!=0) strpmavjjbranch=
"p_HadZH_mavjj_JECNominal";
3439 else if (
prod==
TVar::Had_WH && tree->GetBranchStatus(
"p_HadWH_mavjj_JECNominal")!=0) strpmavjjbranch=
"p_HadWH_mavjj_JECNominal";
3442 if (tree->GetBranchStatus(
"p_Gen_JJEW_BKG_MCFM")!=0) strrewgtbranch =
"p_Gen_JJEW_BKG_MCFM";
3443 tree->SetBranchStatus(
"*", 0);
3444 tree->SetBranchStatus(
"genxsec", 1); tree->SetBranchAddress(
"genxsec", &genxsec); tree->SetBranchStatus(
"genBR", 1); tree->SetBranchAddress(
"genBR", &genBR);
3445 tree->SetBranchStatus(
"genHEPMCweight", 1); tree->SetBranchAddress(
"genHEPMCweight", &genHEPMCweight);
3446 tree->SetBranchStatus(
"GenHMass", 1); tree->SetBranchAddress(
"GenHMass", &GenHMass);
3447 tree->SetBranchStatus(
"nCleanedJetsPt30", 1); tree->SetBranchAddress(
"nCleanedJetsPt30", &NJets30);
3448 tree->SetBranchStatus(
"JetPt", 1); tree->SetBranchAddress(
"JetPt", &JetPt);
3449 tree->SetBranchStatus(
"JetEta", 1); tree->SetBranchAddress(
"JetEta", &JetEta);
3450 tree->SetBranchStatus(
"JetPhi", 1); tree->SetBranchAddress(
"JetPhi", &JetPhi);
3451 tree->SetBranchStatus(
"JetMass", 1); tree->SetBranchAddress(
"JetMass", &JetMass);
3452 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
3453 tree->SetBranchStatus(
"ZZPt", 1); tree->SetBranchAddress(
"ZZPt", &ZZPt);
3454 tree->SetBranchStatus(
"ZZEta", 1); tree->SetBranchAddress(
"ZZEta", &ZZEta);
3455 tree->SetBranchStatus(
"ZZPhi", 1); tree->SetBranchAddress(
"ZZPhi", &ZZPhi);
3456 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
3457 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
3458 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
3459 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
3460 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
3461 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
3462 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
3463 tree->SetBranchStatus(
"LepLepId", 1); tree->SetBranchAddress(
"LepLepId", &LepLepId);
3464 tree->SetBranchStatus(
"LepPt", 1); tree->SetBranchAddress(
"LepPt", &LepPt);
3465 tree->SetBranchStatus(
"LepEta", 1); tree->SetBranchAddress(
"LepEta", &LepEta);
3466 tree->SetBranchStatus(
"LepPhi", 1); tree->SetBranchAddress(
"LepPhi", &LepPhi);
3467 tree->SetBranchStatus(
"Z1Flav", 1); tree->SetBranchAddress(
"Z1Flav", &Z1Flav);
3468 tree->SetBranchStatus(
"Z2Flav", 1); tree->SetBranchAddress(
"Z2Flav", &Z2Flav);
3470 if (strrewgtbranch!=
""){
3471 tree->SetBranchStatus(strrewgtbranch, 1); tree->SetBranchAddress(strrewgtbranch, &rewgt);
3472 cout <<
"Reweighting is read from branch " << strrewgtbranch << endl;
3476 cout <<
"Reweighting needs to be computed." << endl;
3477 cerr <<
"NOT YET IMPLEMENTED!" << endl;
3481 tree->SetBranchStatus(strrecalcbranch, 1); tree->SetBranchAddress(strrecalcbranch, &mesq_calc);
3482 tree->SetBranchStatus(strrecalcconstbranch, 1); tree->SetBranchAddress(strrecalcconstbranch, &cconst_calc);
3483 cout <<
"Extracting ME from " << strrecalcbranch <<
" and const from " << strrecalcconstbranch << endl;
3485 else cout <<
"Recalculating the ME" << endl;
3486 if (!recomputePmavjj && strpmavjjbranch!=
""){
3487 tree->SetBranchStatus(strpmavjjbranch, 1);
3488 tree->SetBranchAddress(strpmavjjbranch, &pmavjj);
3489 cout <<
"Extracting P_V(mJJ) from " << strpmavjjbranch << endl;
3491 else if (recomputePmavjj)
cout <<
"Recomputing P_V(mJJ)" << endl;
3492 else cout <<
"No valid P_V(mJJ)" << endl;
3494 tree->SetBranchStatus(
"LHEMotherPz", 1); tree->SetBranchAddress(
"LHEMotherPz", &LHEMotherPz);
3495 tree->SetBranchStatus(
"LHEMotherE", 1); tree->SetBranchAddress(
"LHEMotherE", &LHEMotherE);
3496 tree->SetBranchStatus(
"LHEMotherId", 1); tree->SetBranchAddress(
"LHEMotherId", &LHEMotherId);
3498 tree->SetBranchStatus(
"LHEDaughterPt", 1); tree->SetBranchAddress(
"LHEDaughterPt", &LHEDaughterPt);
3499 tree->SetBranchStatus(
"LHEDaughterEta", 1); tree->SetBranchAddress(
"LHEDaughterEta", &LHEDaughterEta);
3500 tree->SetBranchStatus(
"LHEDaughterPhi", 1); tree->SetBranchAddress(
"LHEDaughterPhi", &LHEDaughterPhi);
3501 tree->SetBranchStatus(
"LHEDaughterMass", 1); tree->SetBranchAddress(
"LHEDaughterMass", &LHEDaughterMass);
3502 tree->SetBranchStatus(
"LHEDaughterId", 1); tree->SetBranchAddress(
"LHEDaughterId", &LHEDaughterId);
3504 tree->SetBranchStatus(
"LHEAssociatedParticlePt", 1); tree->SetBranchAddress(
"LHEAssociatedParticlePt", &LHEAssociatedParticlePt);
3505 tree->SetBranchStatus(
"LHEAssociatedParticleEta", 1); tree->SetBranchAddress(
"LHEAssociatedParticleEta", &LHEAssociatedParticleEta);
3506 tree->SetBranchStatus(
"LHEAssociatedParticlePhi", 1); tree->SetBranchAddress(
"LHEAssociatedParticlePhi", &LHEAssociatedParticlePhi);
3507 tree->SetBranchStatus(
"LHEAssociatedParticleMass", 1); tree->SetBranchAddress(
"LHEAssociatedParticleMass", &LHEAssociatedParticleMass);
3508 tree->SetBranchStatus(
"LHEAssociatedParticleId", 1); tree->SetBranchAddress(
"LHEAssociatedParticleId", &LHEAssociatedParticleId);
3511 cout <<
"Cross section = " << genxsec*genBR << endl;
3513 TH1F* htmp = (TH1F*)finput->Get(COUNTERS_NAME);
3514 pair<float, float> nsum(htmp->GetBinContent(1), htmp->GetBinContent(41));
3517 nEntries += tree->GetEntries();
3518 treeList.push_back(tree);
3519 finputList.push_back(finput);
3522 cout <<
"Pole mass = " << polemass << endl;
3523 mass_map[tree]=polemass;
3524 if (mass_sample_map.find(polemass)==mass_sample_map.end()){
3525 cout <<
"Inserting new pole mass sample array" << endl;
3526 vector<TTree*> dumarr;
3527 mass_sample_map[polemass] = dumarr;
3529 mass_sample_map[polemass].push_back(tree);
3531 else finput->Close();
3533 else if (finput->IsOpen()) finput->Close();
3536 cout <<
"NEntries = " << nEntries << endl;
3538 for (
auto it = mass_sample_map.begin(); it != mass_sample_map.end(); ++it){
3541 for (
unsigned int ix=0; ix<it->second.size(); ix++){
3542 it->second.at(ix)->GetEntry(0);
3543 sum_ngen += nGenMap[it->second.at(ix)].first;
3544 sum_xsec += genxsec*genBR;
3546 float overallWeight = sum_ngen/sum_xsec;
3547 for (
unsigned int ix=0; ix<it->second.size(); ix++){
3548 cout <<
"Sum Hep MC weights in tree " << ix <<
" / " << it->second.size() <<
" was " << nGenMap[it->second.at(ix)].second <<
" over " << nGenMap[it->second.at(ix)].first <<
" total gen. events." << endl;
3549 nGenMap[it->second.at(ix)].first = overallWeight/nGenMap[it->second.at(ix)].second;
3550 cout <<
"Event scale for tree " << ix <<
" / " << it->second.size() <<
" at pole mass " << it->first <<
" = " << nGenMap[it->second.at(ix)].first << endl;
3554 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
3556 vector<pair<float, int>> index[3];
3557 unsigned int ev_acc=0;
3558 for (
int ev=0;
ev<nEntries;
ev++){
3562 Z1Flav*Z2Flav==pow(13, 4)
3564 Z1Flav*Z2Flav==pow(11, 4)
3566 Z1Flav*Z2Flav==pow(11*13, 2)
3569 if (!doProcess)
continue;
3570 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
3571 unsigned int ic = (Z1Flav*Z2Flav==pow(13, 4))*0 + (Z1Flav*Z2Flav==pow(11, 4))*1 + (Z1Flav*Z2Flav==pow(11*13, 2))*2;
3577 for (
unsigned int ic=0; ic<3; ic++){
3578 float firstVal=index[ic].at(0).first;
3579 float lastVal=index[ic].at(index[ic].size()-1).first;
3580 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
3581 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
3582 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
3584 float divisor=25000*(ic==2)+40000*(ic<2);
3587 int nbins = index[ic].size()/divisor;
3590 while (nbins<nbins_th){
3591 if (divisor>1000) divisor -= 1000;
3592 else if (divisor>100) divisor -= 100;
3594 nbins=index[ic].size()/divisor;
3596 cout <<
"nbins=" << nbins << endl;
3597 if (nbins<3) cerr <<
"Not enough bins!" << endl;
3598 vector<ExtBin> binList;
3599 float* binning =
new float[nbins+1];
3601 binning[nbins]=supremum;
3602 int ev_stepsize = index[ic].size()/nbins;
3603 cout <<
"Event step size: " << ev_stepsize << endl;
3604 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
3605 for (
int ix=1; ix<nbins; ix++){
3606 binning[ix]=(index[ic][ix*ev_stepsize-1].first+index[ic][ix*ev_stepsize].first)*0.5;
3608 tmpbin.
binlow = binning[ix-1];
3610 for (
int bin=0; bin<ev_stepsize; bin++) tmpbin.
events.push_back(index[ic][(ix-1)*ev_stepsize+bin].second);
3611 binList.push_back(tmpbin);
3612 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ic][ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
3615 tmpbin.
binlow = binning[nbins-1];
3616 tmpbin.
binhigh = binning[nbins];
3617 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index[ic].size(); bin++) tmpbin.
events.push_back(index[ic][bin].second);
3618 binList.push_back(tmpbin);
3619 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
3620 cout <<
"Bin list has the following bins:" << endl;
3621 for (
unsigned int ib=0; ib<binList.size(); ib++){
3622 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
3625 TProfile* hvar =
new TProfile(Form(
"candMass_%s", strchannel[ic].Data()),
"", nbins, binning); hvar->Sumw2();
3626 TProfile* hmesq_conserveDifermMass =
new TProfile(Form(
"P_ConserveDifermionMass_%s", strchannel[ic].Data()),
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
3629 if (writeFinalTree){
3630 newtree =
new TTree(Form(
"FinalTree_%s", strchannel[ic].Data()),
"");
3631 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
3632 newtree->Branch(
"ZZMass", &mzz);
3633 newtree->Branch(
"weight", &wgt);
3638 double aL1=0, aR1=0, aL2=0, aR2=0;
3640 unsigned int ev_acc=0;
3641 for (
unsigned int bin=0; bin<binList.size(); bin++){
3642 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
3643 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
3644 int getEv = binList.at(bin).events.at(
ev);
3646 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
3647 if (JetPt->size()<2 || JetEta->size()<2 || JetPhi->size()<2 || JetMass->size()<2){
3648 cerr <<
"Jet array sizes are less than Njets!" << endl;
3651 TTree* tree =
findTree(treeList, getEv);
3656 float& samplePoleMass = mass_map[tree];
3657 float samplePoleWidth = 0;
3658 if (samplePoleMass>0.){
3659 samplePoleWidth =
mela.getHiggsWidthAtPoleMass(samplePoleMass);
3660 rewgt /= pow(pow(GenHMass, 2)-pow(samplePoleMass, 2), 2) + pow(samplePoleMass*samplePoleWidth, 2);
3663 wgt = fabs(genxsec*genBR*genHEPMCweight*nGenMap[tree].first*rewgt);
3665 TLorentzVector jet[2], higgs;
3666 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(JetPt->at(ij), JetEta->at(ij), JetPhi->at(ij), JetMass->at(ij));
3667 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
3668 TVector3 boostH = higgs.BoostVector();
3675 for (
int id=0;
id<4;
id++){
3677 if (abs(LepLepId->at(
id))==13) mass = 0.105658;
3678 else if (abs(LepLepId->at(
id))==11) mass = 0.000511;
3679 TLorentzVector pDaughter;
3680 pDaughter.SetPtEtaPhiM(LepPt->at(
id), LepEta->at(
id), LepPhi->at(
id), mass);
3687 double propagatorV=1;
3688 if (recalculate || ev_acc==0){
3690 mela.computeProdP(mesq_conserveDifermMass,
false);
3692 mesq_calc /= cconst_calc;
3693 mesq_conserveDifermMass=mesq_calc;
3695 mela.getIORecord()->getVDaughterCouplings(aL1, aR1, 0);
3696 mela.getIORecord()->getVDaughterCouplings(aL2, aR2, 1);
3698 mv =
mela.getPrimaryMass(23);
3699 gav =
mela.getPrimaryWidth(23);
3702 mv =
mela.getPrimaryMass(24);
3703 gav =
mela.getPrimaryWidth(24);
3707 mesq_calc /= cconst_calc;
3708 mesq_conserveDifermMass=mesq_calc;
3710 if (fabs(aL1)>0. || fabs(aR1)>0.) mesq_conserveDifermMass /= pow(aL1, 2)+pow(aR1, 2);
3711 if (fabs(aL2)>0. || fabs(aR2)>0.) mesq_conserveDifermMass /= pow(aL2, 2)+pow(aR2, 2);
3713 double mjj = (jet[0] + jet[1]).M();
3714 propagatorV = 1./(pow(pow(mjj, 2)-pow(mv, 2), 2) + pow(mv*gav, 2));
3715 mesq_conserveDifermMass /= propagatorV;
3716 if (recomputePmavjj){
3718 mela.computeDijetConvBW(pmavjj,
false);
3720 mesq_conserveDifermMass *= pmavjj;
3724 mz =
mela.getPrimaryMass(23);
3725 gaz =
mela.getPrimaryWidth(23);
3726 if (fabs(mzz-
mz)<=4.*gaz){
3727 double sh = pow(mzz, 2);
3728 double shdn = pow(
mz-4.*gaz, 2);
3729 double shup = pow(
mz+4.*gaz, 2);
3730 double prop_sh = 1./(pow(sh-pow(
mz, 2), 2) + pow(
mz*gaz, 2));
3731 double prop_shdn = 1./(pow(shdn-pow(
mz, 2), 2) + pow(
mz*gaz, 2));
3732 double prop_shup = 1./(pow(shup-pow(
mz, 2), 2) + pow(
mz*gaz, 2));
3733 double fsh = (sh-shdn)/(shup-shdn);
3734 propagator = prop_sh / (prop_shdn*(1.-fsh) + prop_shup*fsh);
3739 mela.resetInputEvent();
3746 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
3749 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, 0, wgt);
3751 mela.resetInputEvent();
3755 binList.at(bin).sift(); binList.at(bin).adjustWeights(10);
3757 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
3758 mzz = binList.at(bin).masses.at(
ev);
3759 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
3760 wgt = binList.at(bin).weights.at(
ev);
3761 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
3762 hvar->Fill(mzz, mzz);
3763 if (writeFinalTree) newtree->Fill();
3766 cout <<
"Total events accumulated: " << ev_acc << endl;
3769 for (
int ix=0; ix<4; ix++) xexyey[ix] =
new double[nbins];
3770 for (
int bin=0; bin<nbins; bin++){
3771 xexyey[0][bin] = hvar->GetBinContent(bin+1);
3772 xexyey[1][bin] = hvar->GetBinError(bin+1);
3774 cout <<
"Bin " << bin <<
" x-center: " << xexyey[0][bin] <<
" +- " << xexyey[1][bin] << endl;
3776 xexyey[2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
3777 xexyey[3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
3778 xexyey[3][bin] = log10(xexyey[3][bin])/xexyey[2][bin];
3779 xexyey[2][bin] = log10(xexyey[2][bin]);
3782 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
3783 tg->SetName(Form(
"tg_%s", hmesq_conserveDifermMass->GetName()));
3784 foutput->WriteTObject(tg);
3787 for (
int ix=0; ix<4; ix++)
delete[] xexyey[ix];
3789 foutput->WriteTObject(hmesq_conserveDifermMass);
3790 foutput->WriteTObject(hvar);
3791 if (writeFinalTree) foutput->WriteTObject(newtree);
3792 if (writeFinalTree)
delete newtree;
3793 delete hmesq_conserveDifermMass;
3798 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
3810 TString TREE_NAME =
"ZZTree/candTree";
3811 TString COUNTERS_NAME =
"ZZTree/Counters";
3812 bool writeFinalTree=
true;
3823 Mela mela(erg_tev, mPOLE, verbosity);
3825 std::vector<short>* LepLepId=0;
3826 std::vector<float>* LepPt=0;
3827 std::vector<float>* LepEta=0;
3828 std::vector<float>* LepPhi=0;
3831 std::vector<float>* JetPt=0;
3832 std::vector<float>* JetEta=0;
3833 std::vector<float>* JetPhi=0;
3834 std::vector<float>* JetMass=0;
3835 std::vector<float> myJetPt;
3836 std::vector<float> myJetEta;
3837 std::vector<float> myJetPhi;
3838 std::vector<float> myJetMass;
3840 float mesq_calc=0., cconst_calc=1.;
3841 float mesq_conserveDifermMass=0;
3843 float m1 = 91.471450;
3844 float m2 = 12.139782;
3845 float h1 = 0.2682896;
3846 float h2 = 0.1679779;
3847 float phi = 1.5969792;
3848 float hs = -0.727181;
3849 float phi1 = 1.8828257;
3850 float ZZPt, ZZPhi, ZZEta;
3851 short Z1Flav, Z2Flav;
3852 float genxsec=0, genBR=0, ngen=0, genHEPMCweight=0;
3855 TString cinput_main;
3859 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
3863 unordered_map<TTree*, pair<float, float>> nGenMap;
3864 unordered_map<float, vector<TTree*>> mass_sample_map;
3866 vector<TFile*> finputList;
3867 vector<TTree*> treeList;
3869 for (
unsigned int is=0; is<strSamples.size(); is++){
3870 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples[is]).Data());
3871 TFile* finput = TFile::Open(cinput,
"read");
3872 cout <<
"Opening file " << cinput <<
"..." << endl;
3875 if (finput->IsOpen() && !finput->IsZombie()){
3876 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
3877 tree = (TTree*)finput->Get(TREE_NAME);
3879 cout << TREE_NAME <<
" is found." << endl;
3880 if (!recalculate && tree->GetBranchStatus(
"pConst_JJQCD_BKG_MCFM_JECNominal")==0) recalculate=
true;
3881 tree->SetBranchStatus(
"*", 0);
3882 tree->SetBranchStatus(
"genxsec", 1); tree->SetBranchAddress(
"genxsec", &genxsec); tree->SetBranchStatus(
"genBR", 1); tree->SetBranchAddress(
"genBR", &genBR);
3883 tree->SetBranchStatus(
"genHEPMCweight", 1); tree->SetBranchAddress(
"genHEPMCweight", &genHEPMCweight);
3884 tree->SetBranchStatus(
"nCleanedJetsPt30", 1); tree->SetBranchAddress(
"nCleanedJetsPt30", &NJets30);
3885 tree->SetBranchStatus(
"JetPt", 1); tree->SetBranchAddress(
"JetPt", &JetPt);
3886 tree->SetBranchStatus(
"JetEta", 1); tree->SetBranchAddress(
"JetEta", &JetEta);
3887 tree->SetBranchStatus(
"JetPhi", 1); tree->SetBranchAddress(
"JetPhi", &JetPhi);
3888 tree->SetBranchStatus(
"JetMass", 1); tree->SetBranchAddress(
"JetMass", &JetMass);
3889 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
3890 tree->SetBranchStatus(
"ZZPt", 1); tree->SetBranchAddress(
"ZZPt", &ZZPt);
3891 tree->SetBranchStatus(
"ZZEta", 1); tree->SetBranchAddress(
"ZZEta", &ZZEta);
3892 tree->SetBranchStatus(
"ZZPhi", 1); tree->SetBranchAddress(
"ZZPhi", &ZZPhi);
3893 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
3894 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
3895 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
3896 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
3897 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
3898 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
3899 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
3900 tree->SetBranchStatus(
"LepLepId", 1); tree->SetBranchAddress(
"LepLepId", &LepLepId);
3901 tree->SetBranchStatus(
"LepPt", 1); tree->SetBranchAddress(
"LepPt", &LepPt);
3902 tree->SetBranchStatus(
"LepEta", 1); tree->SetBranchAddress(
"LepEta", &LepEta);
3903 tree->SetBranchStatus(
"LepPhi", 1); tree->SetBranchAddress(
"LepPhi", &LepPhi);
3904 tree->SetBranchStatus(
"Z1Flav", 1); tree->SetBranchAddress(
"Z1Flav", &Z1Flav);
3905 tree->SetBranchStatus(
"Z2Flav", 1); tree->SetBranchAddress(
"Z2Flav", &Z2Flav);
3907 tree->SetBranchStatus(
"p_JJQCD_BKG_MCFM_JECNominal", 1);
3908 tree->SetBranchAddress(
"p_JJQCD_BKG_MCFM_JECNominal", &mesq_calc);
3909 tree->SetBranchStatus(
"pConst_JJQCD_BKG_MCFM_JECNominal", 1);
3910 tree->SetBranchAddress(
"pConst_JJQCD_BKG_MCFM_JECNominal", &cconst_calc);
3912 else cout <<
"ME needs to be recalculated!" << endl;
3914 cout <<
"Cross section = " << genxsec*genBR << endl;
3916 TH1F* htmp = (TH1F*)finput->Get(COUNTERS_NAME);
3917 pair<float, float> nsum(htmp->GetBinContent(1), htmp->GetBinContent(41));
3920 nEntries += tree->GetEntries();
3921 treeList.push_back(tree);
3922 finputList.push_back(finput);
3925 cout <<
"Pole mass = " << polemass << endl;
3926 if (mass_sample_map.find(polemass)==mass_sample_map.end()){
3927 cout <<
"Inserting new pole mass sample array" << endl;
3928 vector<TTree*> dumarr;
3929 mass_sample_map[polemass] = dumarr;
3931 mass_sample_map[polemass].push_back(tree);
3933 else if (finput->IsOpen()) finput->Close();
3937 cout <<
"NEntries = " << nEntries << endl;
3939 for (
auto it = mass_sample_map.begin(); it != mass_sample_map.end(); ++it){
3942 for (
unsigned int ix=0; ix<it->second.size(); ix++){
3943 it->second.at(ix)->GetEntry(0);
3944 sum_ngen += nGenMap[it->second.at(ix)].first;
3945 sum_xsec += genxsec*genBR;
3947 float overallWeight = sum_ngen/sum_xsec;
3948 for (
unsigned int ix=0; ix<it->second.size(); ix++){
3949 cout <<
"Sum Hep MC weights in tree " << ix <<
" / " << it->second.size() <<
" was " << nGenMap[it->second.at(ix)].second <<
" over " << nGenMap[it->second.at(ix)].first <<
" total gen. events." << endl;
3950 nGenMap[it->second.at(ix)].first = overallWeight/nGenMap[it->second.at(ix)].second;
3951 cout <<
"Event scale for tree " << ix <<
" / " << it->second.size() <<
" at pole mass " << it->first <<
" = " << nGenMap[it->second.at(ix)].first << endl;
3955 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
3957 vector<pair<float, int>> index[3];
3958 unsigned int ev_acc=0;
3959 for (
int ev=0;
ev<nEntries;
ev++){
3963 Z1Flav*Z2Flav==pow(13, 4)
3965 Z1Flav*Z2Flav==pow(11, 4)
3967 Z1Flav*Z2Flav==pow(11*13, 2)
3970 if (!doProcess)
continue;
3971 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
3972 unsigned int ic = (Z1Flav*Z2Flav==pow(13, 4))*0 + (Z1Flav*Z2Flav==pow(11, 4))*1 + (Z1Flav*Z2Flav==pow(11*13, 2))*2;
3978 for (
unsigned int ic=0; ic<3; ic++){
3979 float firstVal=index[ic].at(0).first;
3980 float lastVal=index[ic].at(index[ic].size()-1).first;
3981 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
3982 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
3983 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
3985 float divisor=10000;
3986 int nbins = index[ic].size()/divisor;
3987 const int nbins_th=8;
3988 while (nbins<nbins_th){
3989 if (divisor>1000) divisor -= 1000;
3990 else if (divisor>100) divisor -= 100;
3992 nbins=index[ic].size()/divisor;
3994 cout <<
"nbins=" << nbins << endl;
3995 if (nbins<3) cerr <<
"Not enough bins!" << endl;
3996 vector<ExtBin> binList;
3997 float* binning =
new float[nbins+1];
3999 binning[nbins]=supremum;
4000 int ev_stepsize = index[ic].size()/nbins;
4001 cout <<
"Event step size: " << ev_stepsize << endl;
4002 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
4003 for (
int ix=1; ix<nbins; ix++){
4004 binning[ix]=(index[ic][ix*ev_stepsize-1].first+index[ic][ix*ev_stepsize].first)*0.5;
4006 tmpbin.
binlow = binning[ix-1];
4008 for (
int bin=0; bin<ev_stepsize; bin++) tmpbin.
events.push_back(index[ic][(ix-1)*ev_stepsize+bin].second);
4009 binList.push_back(tmpbin);
4010 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ic][ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
4013 tmpbin.
binlow = binning[nbins-1];
4014 tmpbin.
binhigh = binning[nbins];
4015 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index[ic].size(); bin++) tmpbin.
events.push_back(index[ic][bin].second);
4016 binList.push_back(tmpbin);
4017 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
4018 cout <<
"Bin list has the following bins:" << endl;
4019 for (
unsigned int ib=0; ib<binList.size(); ib++){
4020 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
4023 TProfile* hvar =
new TProfile(Form(
"candMass_%s", strchannel[ic].Data()),
"", nbins, binning); hvar->Sumw2();
4024 TProfile* hmesq_conserveDifermMass =
new TProfile(Form(
"P_ConserveDifermionMass_%s", strchannel[ic].Data()),
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
4027 if (writeFinalTree){
4028 newtree =
new TTree(Form(
"FinalTree_%s", strchannel[ic].Data()),
"");
4029 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
4030 newtree->Branch(
"ZZMass", &mzz);
4031 newtree->Branch(
"weight", &wgt);
4036 double aL1=0, aR1=0, aL2=0, aR2=0;
4038 unsigned int ev_acc=0;
4039 for (
unsigned int bin=0; bin<binList.size(); bin++){
4040 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
4041 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
4042 int getEv = binList.at(bin).events.at(
ev);
4044 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
4045 if (JetPt->size()<2 || JetEta->size()<2 || JetPhi->size()<2 || JetMass->size()<2){
4046 cerr <<
"Jet array sizes are less than Njets!" << endl;
4049 TTree* tree =
findTree(treeList, getEv);
4050 wgt = fabs(genxsec*genBR*genHEPMCweight*nGenMap[tree].first);
4052 TLorentzVector jet[2], higgs;
4053 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(JetPt->at(ij), JetEta->at(ij), JetPhi->at(ij), JetMass->at(ij));
4054 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
4055 TVector3 boostH = higgs.BoostVector();
4062 for (
int id=0;
id<4;
id++){
4064 if (abs(LepLepId->at(
id))==13) mass = 0.105658;
4065 else if (abs(LepLepId->at(
id))==11) mass = 0.000511;
4066 TLorentzVector pDaughter;
4067 pDaughter.SetPtEtaPhiM(LepPt->at(
id), LepEta->at(
id), LepPhi->at(
id), mass);
4074 if (recalculate || ev_acc==0){
4076 mela.computeProdP(mesq_conserveDifermMass,
false);
4078 mesq_calc /= cconst_calc;
4079 mesq_conserveDifermMass=mesq_calc;
4081 mela.getIORecord()->getVDaughterCouplings(aL1, aR1, 0);
4082 mela.getIORecord()->getVDaughterCouplings(aL2, aR2, 1);
4083 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
4084 if (ev_acc==0 && !recalculate){
4085 cout <<
"\taL1, aR1, aL2, aR2 = " << aL1 <<
" , " << aR1 <<
" , " << aL2 <<
" , " << aR2 << endl;
4086 cout <<
"\talphaS(mZ) = " << alphasVal << endl;
4090 mesq_calc /= cconst_calc;
4091 mesq_conserveDifermMass=mesq_calc;
4093 if (fabs(aL1)>0. || fabs(aR1)>0.) mesq_conserveDifermMass /= pow(aL1, 2)+pow(aR1, 2);
4094 if (fabs(aL2)>0. || fabs(aR2)>0.) mesq_conserveDifermMass /= pow(aL2, 2)+pow(aR2, 2);
4095 mesq_conserveDifermMass /= pow(alphasVal, 2);
4098 mz =
mela.getPrimaryMass(23);
4099 gaz =
mela.getPrimaryWidth(23);
4100 if (fabs(mzz-
mz)<=4.*gaz){
4101 double sh = pow(mzz, 2);
4102 double shdn = pow(
mz-4.*gaz, 2);
4103 double shup = pow(
mz+4.*gaz, 2);
4104 double prop_sh = 1./(pow(sh-pow(
mz, 2), 2) + pow(
mz*gaz, 2));
4105 double prop_shdn = 1./(pow(shdn-pow(
mz, 2), 2) + pow(
mz*gaz, 2));
4106 double prop_shup = 1./(pow(shup-pow(
mz, 2), 2) + pow(
mz*gaz, 2));
4107 double fsh = (sh-shdn)/(shup-shdn);
4108 propagator = prop_sh / (prop_shdn*(1.-fsh) + prop_shup*fsh);
4114 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
4117 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, 0, wgt);
4119 mela.resetInputEvent();
4123 binList.at(bin).sift(); binList.at(bin).adjustWeights(-1);
4125 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
4126 mzz = binList.at(bin).masses.at(
ev);
4127 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
4128 wgt = binList.at(bin).weights.at(
ev);
4129 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
4130 hvar->Fill(mzz, mzz);
4131 if (writeFinalTree) newtree->Fill();
4136 for (
int ix=0; ix<4; ix++) xexyey[ix] =
new double[nbins];
4137 for (
int bin=0; bin<nbins; bin++){
4138 xexyey[0][bin] = hvar->GetBinContent(bin+1);
4139 xexyey[1][bin] = hvar->GetBinError(bin+1);
4141 cout <<
"Bin " << bin <<
" x-center: " << xexyey[0][bin] <<
" +- " << xexyey[1][bin] << endl;
4143 xexyey[2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
4144 xexyey[3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
4145 xexyey[3][bin] = log10(xexyey[3][bin])/xexyey[2][bin];
4146 xexyey[2][bin] = log10(xexyey[2][bin]);
4149 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
4150 tg->SetName(Form(
"tg_%s", hmesq_conserveDifermMass->GetName()));
4151 foutput->WriteTObject(tg);
4154 for (
int ix=0; ix<4; ix++)
delete[] xexyey[ix];
4156 foutput->WriteTObject(hmesq_conserveDifermMass);
4157 foutput->WriteTObject(hvar);
4158 if (writeFinalTree) foutput->WriteTObject(newtree);
4159 if (writeFinalTree)
delete newtree;
4160 delete hmesq_conserveDifermMass;
4165 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
4174 const bool writeFinalTree=
false;
4175 const TString strMEBranchname =
"p_ZZINDEPENDENT_SIG_ghz1_1_JHUGen";
4176 const TString strConstBranchname =
"pConst_ZZINDEPENDENT_SIG_ghz1_1_JHUGen";
4179 Mela mela(erg_tev, mPOLE, verbosity);
4189 std::vector<short>* LepLepId=0;
4190 std::vector<float>* LepPt=0;
4191 std::vector<float>* LepEta=0;
4192 std::vector<float>* LepPhi=0;
4194 float mesq_calc=0., cconst_calc=1.;
4195 float mesq_conserveDifermMass=0;
4197 float m1 = 91.471450;
4198 float m2 = 12.139782;
4199 float h1 = 0.2682896;
4200 float h2 = 0.1679779;
4201 float phi = 1.5969792;
4202 float hs = -0.727181;
4203 float phi1 = 1.8828257;
4204 float ZZPt, ZZPhi, ZZEta;
4205 short Z1Flav, Z2Flav;
4208 vector<pair<float, int>> index[3];
4209 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
4210 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s.root", strme.Data(), strprod.Data(), strproc.Data()),
"recreate");
4212 vector<TString> dumappend;
4215 appendVector<TString>(strSamples_13TeV, dumappend);
4217 appendVector<TString>(strSamples_13TeV, dumappend);
4219 appendVector<TString>(strSamples_13TeV, dumappend);
4221 appendVector<TString>(strSamples_13TeV, dumappend);
4225 appendVector<TString>(strSamples_8TeV, dumappend);
4227 appendVector<TString>(strSamples_8TeV, dumappend);
4229 appendVector<TString>(strSamples_8TeV, dumappend);
4231 appendVector<TString>(strSamples_8TeV, dumappend);
4235 appendVector<TString>(strSamples_7TeV, dumappend);
4237 appendVector<TString>(strSamples_7TeV, dumappend);
4239 appendVector<TString>(strSamples_7TeV, dumappend);
4241 appendVector<TString>(strSamples_7TeV, dumappend);
4243 vector<TFile*> finputList;
4244 vector<TTree*> treeList;
4246 TString cinput_main;
4248 TREE_NAME =
"ZZTree/candTree";
4251 for (
int is=0; is<(
int)strSamples_13TeV.size(); is++){
4252 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples_13TeV[is]).Data());
4253 TFile* finput = TFile::Open(cinput,
"read");
4254 cout <<
"Opening file " << cinput <<
"..." << endl;
4257 if (finput->IsOpen() && !finput->IsZombie()){
4258 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
4259 tree = (TTree*)finput->Get(TREE_NAME);
4261 cout << TREE_NAME <<
" is found." << endl;
4263 bool doRecalculate = recalculate;
4264 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0) doRecalculate =
true;
4265 tree->SetBranchStatus(
"*", 0);
4266 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
4267 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
4268 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
4269 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
4270 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
4271 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
4272 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
4273 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
4274 tree->SetBranchStatus(
"Z1Flav", 1); tree->SetBranchAddress(
"Z1Flav", &Z1Flav);
4275 tree->SetBranchStatus(
"Z2Flav", 1); tree->SetBranchAddress(
"Z2Flav", &Z2Flav);
4276 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0){
4277 tree->SetBranchStatus(strMEBranchname, 1); tree->SetBranchAddress(strMEBranchname, &mesq_calc);
4278 tree->SetBranchStatus(strConstBranchname, 1); tree->SetBranchAddress(strConstBranchname, &cconst_calc);
4280 nEntries += tree->GetEntries();
4281 treeList.push_back(tree);
4282 finputList.push_back(finput);
4284 else finput->Close();
4286 else if (finput->IsOpen()) finput->Close();
4290 for (
int ic=0; ic<3; ic++){
4291 TREE_NAME =
"SelectedTree";
4294 for (
int is=0; is<(
int)strSamples_8TeV.size(); is++){
4295 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples_8TeV[is]).Data());
4296 TFile* finput = TFile::Open(cinput,
"read");
4297 cout <<
"Opening file " << cinput <<
"..." << endl;
4300 if (finput->IsOpen() && !finput->IsZombie()){
4301 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
4302 tree = (TTree*)finput->Get(TREE_NAME);
4304 cout << TREE_NAME <<
" is found." << endl;
4305 tree->SetBranchStatus(
"*", 0);
4306 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
4307 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
4308 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
4309 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
4310 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
4311 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
4312 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
4313 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
4314 tree->SetBranchStatus(
"Z1ids", 1); tree->SetBranchAddress(
"Z1ids", &Z1Flav);
4315 tree->SetBranchStatus(
"Z2ids", 1); tree->SetBranchAddress(
"Z2ids", &Z2Flav);
4316 nEntries += tree->GetEntries();
4317 treeList.push_back(tree);
4318 finputList.push_back(finput);
4320 else finput->Close();
4322 else if (finput->IsOpen()) finput->Close();
4327 for (
int is=0; is<(
int)strSamples_7TeV.size(); is++){
4328 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples_7TeV[is]).Data());
4329 TFile* finput = TFile::Open(cinput,
"read");
4330 cout <<
"Opening file " << cinput <<
"..." << endl;
4333 if (finput->IsOpen() && !finput->IsZombie()){
4334 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
4335 tree = (TTree*)finput->Get(TREE_NAME);
4337 cout << TREE_NAME <<
" is found." << endl;
4338 tree->SetBranchStatus(
"*", 0);
4339 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
4340 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
4341 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
4342 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
4343 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
4344 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
4345 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
4346 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
4347 tree->SetBranchStatus(
"Z1ids", 1); tree->SetBranchAddress(
"Z1ids", &Z1Flav);
4348 tree->SetBranchStatus(
"Z2ids", 1); tree->SetBranchAddress(
"Z2ids", &Z2Flav);
4349 nEntries += tree->GetEntries();
4350 treeList.push_back(tree);
4351 finputList.push_back(finput);
4353 else finput->Close();
4355 else if (finput->IsOpen()) finput->Close();
4360 cout <<
"NEntries = " << nEntries <<
" over " << treeList.size() <<
" trees." << endl;
4362 unsigned int ev_acc=0;
4363 for (
int ev=0;
ev<nEntries;
ev++){
4367 Z1Flav*Z2Flav==pow(13, 4)
4369 Z1Flav*Z2Flav==pow(11, 4)
4371 Z1Flav*Z2Flav==pow(11*13, 2)
4374 if (!doProcess)
continue;
4375 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
4376 unsigned int ic = (Z1Flav*Z2Flav==pow(13, 4))*0 + (Z1Flav*Z2Flav==pow(11, 4))*1 + (Z1Flav*Z2Flav==pow(11*13, 2))*2;
4380 cout <<
"Number of valid entries: " << ev_acc << endl;
4382 for (
unsigned int ic=0; ic<3; ic++){
4383 float firstVal=index[ic].at(0).first;
4384 float lastVal=index[ic].at(index[ic].size()-1).first;
4385 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
4386 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
4387 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
4389 float divisor=95000;
4390 int nbins = index[ic].size()/divisor;
4391 const int nbins_th=10;
4392 while (nbins<nbins_th){
4393 if (divisor>1000) divisor -= 1000;
4394 else if (divisor>100) divisor -= 100;
4396 nbins=index[ic].size()/divisor;
4398 cout <<
"nbins=" << nbins << endl;
4399 if (nbins<3) cerr <<
"Not enough bins!" << endl;
4400 vector<ExtBin> binList;
4401 float* binning =
new float[nbins+1];
4403 binning[nbins]=supremum;
4404 int ev_stepsize = index[ic].size()/nbins;
4405 cout <<
"Event step size: " << ev_stepsize << endl;
4406 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
4407 for (
int ix=1; ix<nbins; ix++){
4408 binning[ix]=(index[ic][ix*ev_stepsize-1].first+index[ic][ix*ev_stepsize].first)*0.5;
4410 tmpbin.
binlow = binning[ix-1]; tmpbin.
binhigh = binning[ix];
4411 for (
int bin=0; bin<ev_stepsize; bin++){
4412 int evid = index[ic][(ix-1)*ev_stepsize+bin].
second;
4413 tmpbin.
events.push_back(evid);
4415 binList.push_back(tmpbin);
4416 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ic][ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
4419 tmpbin.
binlow = binning[nbins-1]; tmpbin.
binhigh = binning[nbins];
4420 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index[ic].size(); bin++){
4421 int evid = index[ic][bin].second;
4422 tmpbin.
events.push_back(evid);
4424 binList.push_back(tmpbin);
4425 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
4426 cout <<
"Bin list has the following bins:" << endl;
4427 for (
unsigned int ib=0; ib<binList.size(); ib++){
4428 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
4433 TProfile* hvar =
new TProfile(Form(
"candMass_%s", strchannel[ic].Data()),
"", nbins, binning); hvar->Sumw2();
4434 TProfile* hmesq_conserveDifermMass =
new TProfile(Form(
"P_ConserveDifermionMass_%s", strchannel[ic].Data()),
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
4437 if (writeFinalTree){
4438 newtree =
new TTree(Form(
"FinalTree_%s", strchannel[ic].Data()),
"");
4439 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
4440 newtree->Branch(
"ZZMass", &mzz);
4462 double aL1=0, aR1=0, aL2=0, aR2=0;
4464 for (
unsigned int bin=0; bin<binList.size(); bin++){
4465 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
4466 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
4467 int getEv = binList.at(bin).events.at(
ev);
4469 TTree* tree =
findTree(treeList, getEv);
4471 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
4473 TLorentzVector pDaughters[4];
4474 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
4475 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); }
4483 bool hasConst = (tree->GetBranchStatus(strConstBranchname)==1);
4484 bool doCalc=(!hasConst || ctr==0);
4486 mela.computeP(mesq_conserveDifermMass,
false);
4487 if (hasConst) mesq_conserveDifermMass = mesq_calc / cconst_calc;
4489 mela.getIORecord()->getVDaughterCouplings(aL1, aR1, 0);
4490 mela.getIORecord()->getVDaughterCouplings(aL2, aR2, 1);
4492 else mesq_conserveDifermMass = mesq_calc / cconst_calc;
4494 if (fabs(aL1)>0. || fabs(aR1)>0.) mesq_conserveDifermMass /= pow(aL1, 2)+pow(aR1, 2);
4495 if (fabs(aL2)>0. || fabs(aR2)>0.) mesq_conserveDifermMass /= pow(aL2, 2)+pow(aR2, 2);
4498 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
4501 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, 0);
4503 mela.resetInputEvent();
4507 binList.at(bin).sift(); binList.at(bin).adjustWeights();
4509 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
4510 mzz = binList.at(bin).masses.at(
ev);
4511 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
4512 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
4513 hvar->Fill(mzz, mzz);
4514 if (writeFinalTree) newtree->Fill();
4519 for (
int ix=0; ix<4; ix++) xexyey[ix] =
new double[nbins];
4520 for (
int bin=0; bin<nbins; bin++){
4521 xexyey[0][bin] = hvar->GetBinContent(bin+1);
4522 xexyey[1][bin] = hvar->GetBinError(bin+1);
4524 cout <<
"Bin " << bin <<
" x-center: " << xexyey[0][bin] <<
" +- " << xexyey[1][bin] << endl;
4525 xexyey[2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
4526 xexyey[3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
4527 xexyey[3][bin] = log10(xexyey[3][bin])/xexyey[2][bin];
4528 xexyey[2][bin] = log10(xexyey[2][bin]);
4531 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
4532 tg->SetName(Form(
"tg_%s", hmesq_conserveDifermMass->GetName()));
4533 foutput->WriteTObject(tg);
4536 for (
int ix=0; ix<4; ix++)
delete[] xexyey[ix];
4537 foutput->WriteTObject(hmesq_conserveDifermMass);
4538 foutput->WriteTObject(hvar);
4539 if (writeFinalTree) foutput->WriteTObject(newtree);
4540 if (writeFinalTree)
delete newtree;
4541 delete hmesq_conserveDifermMass;
4545 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
4559 const bool writeFinalTree=
false;
4560 const TString strMEBranchname =
"p_GG_SIG_ghg2_1_ghz1_1_JHUGen";
4561 const TString strConstBranchname =
"pConst_GG_SIG_ghg2_1_ghz1_1_JHUGen";
4564 Mela mela(erg_tev, mPOLE, verbosity);
4574 std::vector<short>* LepLepId=0;
4575 std::vector<float>* LepPt=0;
4576 std::vector<float>* LepEta=0;
4577 std::vector<float>* LepPhi=0;
4579 float mesq_calc=0., cconst_calc=1.;
4580 float mesq_conserveDifermMass=0;
4582 float m1 = 91.471450;
4583 float m2 = 12.139782;
4584 float h1 = 0.2682896;
4585 float h2 = 0.1679779;
4586 float phi = 1.5969792;
4587 float hs = -0.727181;
4588 float phi1 = 1.8828257;
4589 float ZZPt, ZZPhi, ZZEta;
4590 short Z1Flav, Z2Flav;
4593 vector<pair<float, int>> index[3];
4594 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
4595 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s.root", strme.Data(), strprod.Data(), strproc.Data()),
"recreate");
4597 vector<TString> dumappend;
4600 appendVector<TString>(strSamples_13TeV, dumappend);
4602 appendVector<TString>(strSamples_13TeV, dumappend);
4604 appendVector<TString>(strSamples_13TeV, dumappend);
4606 appendVector<TString>(strSamples_13TeV, dumappend);
4610 appendVector<TString>(strSamples_8TeV, dumappend);
4612 appendVector<TString>(strSamples_8TeV, dumappend);
4614 appendVector<TString>(strSamples_8TeV, dumappend);
4616 appendVector<TString>(strSamples_8TeV, dumappend);
4620 appendVector<TString>(strSamples_7TeV, dumappend);
4622 appendVector<TString>(strSamples_7TeV, dumappend);
4624 appendVector<TString>(strSamples_7TeV, dumappend);
4626 appendVector<TString>(strSamples_7TeV, dumappend);
4628 vector<TFile*> finputList;
4629 vector<TTree*> treeList;
4631 TString cinput_main;
4633 TREE_NAME =
"ZZTree/candTree";
4636 for (
int is=0; is<(
int)strSamples_13TeV.size(); is++){
4637 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples_13TeV[is]).Data());
4638 TFile* finput = TFile::Open(cinput,
"read");
4639 cout <<
"Opening file " << cinput <<
"..." << endl;
4642 if (finput->IsOpen() && !finput->IsZombie()){
4643 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
4644 tree = (TTree*)finput->Get(TREE_NAME);
4646 cout << TREE_NAME <<
" is found." << endl;
4648 bool doRecalculate = recalculate;
4649 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0) doRecalculate =
true;
4650 tree->SetBranchStatus(
"*", 0);
4651 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
4652 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
4653 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
4654 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
4655 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
4656 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
4657 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
4658 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
4659 tree->SetBranchStatus(
"Z1Flav", 1); tree->SetBranchAddress(
"Z1Flav", &Z1Flav);
4660 tree->SetBranchStatus(
"Z2Flav", 1); tree->SetBranchAddress(
"Z2Flav", &Z2Flav);
4661 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0){
4662 tree->SetBranchStatus(strMEBranchname, 1); tree->SetBranchAddress(strMEBranchname, &mesq_calc);
4663 tree->SetBranchStatus(strConstBranchname, 1); tree->SetBranchAddress(strConstBranchname, &cconst_calc);
4665 nEntries += tree->GetEntries();
4666 treeList.push_back(tree);
4667 finputList.push_back(finput);
4669 else finput->Close();
4671 else if (finput->IsOpen()) finput->Close();
4675 for (
int ic=0; ic<3; ic++){
4676 TREE_NAME =
"SelectedTree";
4679 for (
int is=0; is<(
int)strSamples_8TeV.size(); is++){
4680 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples_8TeV[is]).Data());
4681 TFile* finput = TFile::Open(cinput,
"read");
4682 cout <<
"Opening file " << cinput <<
"..." << endl;
4685 if (finput->IsOpen() && !finput->IsZombie()){
4686 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
4687 tree = (TTree*)finput->Get(TREE_NAME);
4689 cout << TREE_NAME <<
" is found." << endl;
4690 tree->SetBranchStatus(
"*", 0);
4691 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
4692 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
4693 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
4694 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
4695 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
4696 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
4697 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
4698 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
4699 tree->SetBranchStatus(
"Z1ids", 1); tree->SetBranchAddress(
"Z1ids", &Z1Flav);
4700 tree->SetBranchStatus(
"Z2ids", 1); tree->SetBranchAddress(
"Z2ids", &Z2Flav);
4701 nEntries += tree->GetEntries();
4702 treeList.push_back(tree);
4703 finputList.push_back(finput);
4705 else finput->Close();
4707 else if (finput->IsOpen()) finput->Close();
4712 for (
int is=0; is<(
int)strSamples_7TeV.size(); is++){
4713 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples_7TeV[is]).Data());
4714 TFile* finput = TFile::Open(cinput,
"read");
4715 cout <<
"Opening file " << cinput <<
"..." << endl;
4718 if (finput->IsOpen() && !finput->IsZombie()){
4719 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
4720 tree = (TTree*)finput->Get(TREE_NAME);
4722 cout << TREE_NAME <<
" is found." << endl;
4723 tree->SetBranchStatus(
"*", 0);
4724 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
4725 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
4726 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
4727 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
4728 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
4729 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
4730 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
4731 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
4732 tree->SetBranchStatus(
"Z1ids", 1); tree->SetBranchAddress(
"Z1ids", &Z1Flav);
4733 tree->SetBranchStatus(
"Z2ids", 1); tree->SetBranchAddress(
"Z2ids", &Z2Flav);
4734 nEntries += tree->GetEntries();
4735 treeList.push_back(tree);
4736 finputList.push_back(finput);
4738 else finput->Close();
4740 else if (finput->IsOpen()) finput->Close();
4745 cout <<
"NEntries = " << nEntries <<
" over " << treeList.size() <<
" trees." << endl;
4747 unsigned int ev_acc=0;
4748 for (
int ev=0;
ev<nEntries;
ev++){
4752 Z1Flav*Z2Flav==pow(13, 4)
4754 Z1Flav*Z2Flav==pow(11, 4)
4756 Z1Flav*Z2Flav==pow(11*13, 2)
4759 if (!doProcess)
continue;
4760 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
4761 unsigned int ic = (Z1Flav*Z2Flav==pow(13, 4))*0 + (Z1Flav*Z2Flav==pow(11, 4))*1 + (Z1Flav*Z2Flav==pow(11*13, 2))*2;
4765 cout <<
"Number of valid entries: " << ev_acc << endl;
4767 for (
unsigned int ic=0; ic<3; ic++){
4768 float firstVal=index[ic].at(0).first;
4769 float lastVal=index[ic].at(index[ic].size()-1).first;
4770 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
4771 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
4772 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
4774 float divisor=95000;
4775 int nbins = index[ic].size()/divisor;
4776 const int nbins_th=10;
4777 while (nbins<nbins_th){
4778 if (divisor>1000) divisor -= 1000;
4779 else if (divisor>100) divisor -= 100;
4781 nbins=index[ic].size()/divisor;
4783 cout <<
"nbins=" << nbins << endl;
4784 if (nbins<3) cerr <<
"Not enough bins!" << endl;
4785 vector<ExtBin> binList;
4786 float* binning =
new float[nbins+1];
4788 binning[nbins]=supremum;
4789 int ev_stepsize = index[ic].size()/nbins;
4790 cout <<
"Event step size: " << ev_stepsize << endl;
4791 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
4792 for (
int ix=1; ix<nbins; ix++){
4793 binning[ix]=(index[ic][ix*ev_stepsize-1].first+index[ic][ix*ev_stepsize].first)*0.5;
4795 tmpbin.
binlow = binning[ix-1]; tmpbin.
binhigh = binning[ix];
4796 for (
int bin=0; bin<ev_stepsize; bin++){
4797 int evid = index[ic][(ix-1)*ev_stepsize+bin].
second;
4798 tmpbin.
events.push_back(evid);
4800 binList.push_back(tmpbin);
4801 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ic][ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
4804 tmpbin.
binlow = binning[nbins-1]; tmpbin.
binhigh = binning[nbins];
4805 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index[ic].size(); bin++){
4806 int evid = index[ic][bin].second;
4807 tmpbin.
events.push_back(evid);
4809 binList.push_back(tmpbin);
4810 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
4811 cout <<
"Bin list has the following bins:" << endl;
4812 for (
unsigned int ib=0; ib<binList.size(); ib++){
4813 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
4818 TProfile* hvar =
new TProfile(Form(
"candMass_%s", strchannel[ic].Data()),
"", nbins, binning); hvar->Sumw2();
4819 TProfile* hmesq_conserveDifermMass =
new TProfile(Form(
"P_ConserveDifermionMass_%s", strchannel[ic].Data()),
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
4822 if (writeFinalTree){
4823 newtree =
new TTree(Form(
"FinalTree_%s", strchannel[ic].Data()),
"");
4824 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
4825 newtree->Branch(
"ZZMass", &mzz);
4847 double alphasVal=0, mh=0, gah=0, aL1=0, aR1=0, aL2=0, aR2=0;
4849 for (
unsigned int bin=0; bin<binList.size(); bin++){
4850 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
4851 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
4852 int getEv = binList.at(bin).events.at(
ev);
4854 TTree* tree =
findTree(treeList, getEv);
4856 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
4858 TLorentzVector pDaughters[4];
4859 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
4860 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); }
4868 bool hasConst = (tree->GetBranchStatus(strConstBranchname)==1);
4869 bool doCalc=(!hasConst || ctr==0);
4871 mela.computeP(mesq_conserveDifermMass,
false);
4872 if (hasConst) mesq_conserveDifermMass = mesq_calc / cconst_calc;
4874 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
4875 mela.getIORecord()->getVDaughterCouplings(aL1, aR1, 0);
4876 mela.getIORecord()->getVDaughterCouplings(aL2, aR2, 1);
4877 mela.getIORecord()->getHiggsMassWidth(mh, gah, 0);
4880 mesq_conserveDifermMass = mesq_calc / cconst_calc;
4882 gah =
mela.getHiggsWidthAtPoleMass(mh);
4885 double propagator = 1./(pow(pow(mzz, 2)-pow(mh, 2), 2) + pow(mh*gah, 2));
4887 mesq_conserveDifermMass /= pow(alphasVal, 2);
4888 if (fabs(aL1)>0. || fabs(aR1)>0.) mesq_conserveDifermMass /= pow(aL1, 2)+pow(aR1, 2);
4889 if (fabs(aL2)>0. || fabs(aR2)>0.) mesq_conserveDifermMass /= pow(aL2, 2)+pow(aR2, 2);
4892 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
4895 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, 0);
4897 mela.resetInputEvent();
4901 binList.at(bin).sift(); binList.at(bin).adjustWeights();
4903 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
4904 mzz = binList.at(bin).masses.at(
ev);
4905 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
4906 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
4907 hvar->Fill(mzz, mzz);
4908 if (writeFinalTree) newtree->Fill();
4913 for (
int ix=0; ix<4; ix++) xexyey[ix] =
new double[nbins];
4914 for (
int bin=0; bin<nbins; bin++){
4915 xexyey[0][bin] = hvar->GetBinContent(bin+1);
4916 xexyey[1][bin] = hvar->GetBinError(bin+1);
4918 cout <<
"Bin " << bin <<
" x-center: " << xexyey[0][bin] <<
" +- " << xexyey[1][bin] << endl;
4919 xexyey[2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
4920 xexyey[3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
4921 xexyey[3][bin] = log10(xexyey[3][bin])/xexyey[2][bin];
4922 xexyey[2][bin] = log10(xexyey[2][bin]);
4926 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
4927 tg->SetName(Form(
"tg_%s", hmesq_conserveDifermMass->GetName()));
4928 foutput->WriteTObject(tg);
4931 for (
int ix=0; ix<4; ix++)
delete[] xexyey[ix];
4932 foutput->WriteTObject(hmesq_conserveDifermMass);
4933 foutput->WriteTObject(hvar);
4934 if (writeFinalTree) foutput->WriteTObject(newtree);
4935 if (writeFinalTree)
delete newtree;
4936 delete hmesq_conserveDifermMass;
4940 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
4954 const bool writeFinalTree=
false;
4955 const TString strMEBranchname =
"p_GG_SIG_kappaTopBot_1_ghz1_1_MCFM";
4956 const TString strConstBranchname =
"pConst_GG_SIG_kappaTopBot_1_ghz1_1_MCFM";
4959 Mela mela(erg_tev, mPOLE, verbosity);
4969 std::vector<short>* LepLepId=0;
4970 std::vector<float>* LepPt=0;
4971 std::vector<float>* LepEta=0;
4972 std::vector<float>* LepPhi=0;
4974 float mesq_calc=0., cconst_calc=1.;
4975 float mesq_conserveDifermMass=0;
4977 float m1 = 91.471450;
4978 float m2 = 12.139782;
4979 float h1 = 0.2682896;
4980 float h2 = 0.1679779;
4981 float phi = 1.5969792;
4982 float hs = -0.727181;
4983 float phi1 = 1.8828257;
4984 float ZZPt, ZZPhi, ZZEta;
4985 short Z1Flav, Z2Flav;
4988 vector<pair<float, int>> index[3];
4989 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
4990 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s.root", strme.Data(), strprod.Data(), strproc.Data()),
"recreate");
4992 vector<TString> dumappend;
4995 appendVector<TString>(strSamples_13TeV, dumappend);
4997 appendVector<TString>(strSamples_13TeV, dumappend);
4999 appendVector<TString>(strSamples_13TeV, dumappend);
5001 appendVector<TString>(strSamples_13TeV, dumappend);
5005 appendVector<TString>(strSamples_8TeV, dumappend);
5007 appendVector<TString>(strSamples_8TeV, dumappend);
5009 appendVector<TString>(strSamples_8TeV, dumappend);
5011 appendVector<TString>(strSamples_8TeV, dumappend);
5015 appendVector<TString>(strSamples_7TeV, dumappend);
5017 appendVector<TString>(strSamples_7TeV, dumappend);
5019 appendVector<TString>(strSamples_7TeV, dumappend);
5021 appendVector<TString>(strSamples_7TeV, dumappend);
5023 vector<TFile*> finputList;
5024 vector<TTree*> treeList;
5026 TString cinput_main;
5028 TREE_NAME =
"ZZTree/candTree";
5031 for (
int is=0; is<(
int)strSamples_13TeV.size(); is++){
5032 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples_13TeV[is]).Data());
5033 TFile* finput = TFile::Open(cinput,
"read");
5034 cout <<
"Opening file " << cinput <<
"..." << endl;
5037 if (finput->IsOpen() && !finput->IsZombie()){
5038 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
5039 tree = (TTree*)finput->Get(TREE_NAME);
5041 cout << TREE_NAME <<
" is found." << endl;
5043 bool doRecalculate = recalculate;
5044 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0) doRecalculate =
true;
5045 tree->SetBranchStatus(
"*", 0);
5046 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
5047 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
5048 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
5049 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
5050 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
5051 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
5052 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
5053 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
5054 tree->SetBranchStatus(
"Z1Flav", 1); tree->SetBranchAddress(
"Z1Flav", &Z1Flav);
5055 tree->SetBranchStatus(
"Z2Flav", 1); tree->SetBranchAddress(
"Z2Flav", &Z2Flav);
5056 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0){
5057 tree->SetBranchStatus(strMEBranchname, 1); tree->SetBranchAddress(strMEBranchname, &mesq_calc);
5058 tree->SetBranchStatus(strConstBranchname, 1); tree->SetBranchAddress(strConstBranchname, &cconst_calc);
5060 nEntries += tree->GetEntries();
5061 treeList.push_back(tree);
5062 finputList.push_back(finput);
5064 else finput->Close();
5066 else if (finput->IsOpen()) finput->Close();
5070 for (
int ic=0; ic<3; ic++){
5071 TREE_NAME =
"SelectedTree";
5074 for (
int is=0; is<(
int)strSamples_8TeV.size(); is++){
5075 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples_8TeV[is]).Data());
5076 TFile* finput = TFile::Open(cinput,
"read");
5077 cout <<
"Opening file " << cinput <<
"..." << endl;
5080 if (finput->IsOpen() && !finput->IsZombie()){
5081 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
5082 tree = (TTree*)finput->Get(TREE_NAME);
5084 cout << TREE_NAME <<
" is found." << endl;
5085 tree->SetBranchStatus(
"*", 0);
5086 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
5087 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
5088 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
5089 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
5090 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
5091 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
5092 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
5093 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
5094 tree->SetBranchStatus(
"Z1ids", 1); tree->SetBranchAddress(
"Z1ids", &Z1Flav);
5095 tree->SetBranchStatus(
"Z2ids", 1); tree->SetBranchAddress(
"Z2ids", &Z2Flav);
5096 nEntries += tree->GetEntries();
5097 treeList.push_back(tree);
5098 finputList.push_back(finput);
5100 else finput->Close();
5102 else if (finput->IsOpen()) finput->Close();
5107 for (
int is=0; is<(
int)strSamples_7TeV.size(); is++){
5108 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples_7TeV[is]).Data());
5109 TFile* finput = TFile::Open(cinput,
"read");
5110 cout <<
"Opening file " << cinput <<
"..." << endl;
5113 if (finput->IsOpen() && !finput->IsZombie()){
5114 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
5115 tree = (TTree*)finput->Get(TREE_NAME);
5117 cout << TREE_NAME <<
" is found." << endl;
5118 tree->SetBranchStatus(
"*", 0);
5119 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
5120 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
5121 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
5122 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
5123 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
5124 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
5125 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
5126 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
5127 tree->SetBranchStatus(
"Z1ids", 1); tree->SetBranchAddress(
"Z1ids", &Z1Flav);
5128 tree->SetBranchStatus(
"Z2ids", 1); tree->SetBranchAddress(
"Z2ids", &Z2Flav);
5129 nEntries += tree->GetEntries();
5130 treeList.push_back(tree);
5131 finputList.push_back(finput);
5133 else finput->Close();
5135 else if (finput->IsOpen()) finput->Close();
5140 cout <<
"NEntries = " << nEntries <<
" over " << treeList.size() <<
" trees." << endl;
5142 unsigned int ev_acc=0;
5143 for (
int ev=0;
ev<nEntries;
ev++){
5147 Z1Flav*Z2Flav==pow(13, 4)
5149 Z1Flav*Z2Flav==pow(11, 4)
5151 Z1Flav*Z2Flav==pow(11*13, 2)
5154 if (!doProcess)
continue;
5155 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
5156 unsigned int ic = (Z1Flav*Z2Flav==pow(13, 4))*0 + (Z1Flav*Z2Flav==pow(11, 4))*1 + (Z1Flav*Z2Flav==pow(11*13, 2))*2;
5160 cout <<
"Number of valid entries: " << ev_acc << endl;
5162 for (
unsigned int ic=0; ic<3; ic++){
5163 float firstVal=index[ic].at(0).first;
5164 float lastVal=index[ic].at(index[ic].size()-1).first;
5165 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
5166 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
5167 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
5169 float divisor=95000;
5170 int nbins = index[ic].size()/divisor;
5171 const int nbins_th=10;
5172 while (nbins<nbins_th){
5173 if (divisor>1000) divisor -= 1000;
5174 else if (divisor>100) divisor -= 100;
5176 nbins=index[ic].size()/divisor;
5178 cout <<
"nbins=" << nbins << endl;
5179 if (nbins<3) cerr <<
"Not enough bins!" << endl;
5180 vector<ExtBin> binList;
5181 float* binning =
new float[nbins+1];
5183 binning[nbins]=supremum;
5184 int ev_stepsize = index[ic].size()/nbins;
5185 cout <<
"Event step size: " << ev_stepsize << endl;
5186 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
5187 for (
int ix=1; ix<nbins; ix++){
5188 binning[ix]=(index[ic][ix*ev_stepsize-1].first+index[ic][ix*ev_stepsize].first)*0.5;
5190 tmpbin.
binlow = binning[ix-1]; tmpbin.
binhigh = binning[ix];
5191 for (
int bin=0; bin<ev_stepsize; bin++){
5192 int evid = index[ic][(ix-1)*ev_stepsize+bin].
second;
5193 tmpbin.
events.push_back(evid);
5195 binList.push_back(tmpbin);
5196 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ic][ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
5199 tmpbin.
binlow = binning[nbins-1]; tmpbin.
binhigh = binning[nbins];
5200 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index[ic].size(); bin++){
5201 int evid = index[ic][bin].second;
5202 tmpbin.
events.push_back(evid);
5204 binList.push_back(tmpbin);
5205 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
5206 cout <<
"Bin list has the following bins:" << endl;
5207 for (
unsigned int ib=0; ib<binList.size(); ib++){
5208 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
5213 TProfile* hvar =
new TProfile(Form(
"candMass_%s", strchannel[ic].Data()),
"", nbins, binning); hvar->Sumw2();
5214 TProfile* hmesq_conserveDifermMass =
new TProfile(Form(
"P_ConserveDifermionMass_%s", strchannel[ic].Data()),
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
5217 if (writeFinalTree){
5218 newtree =
new TTree(Form(
"FinalTree_%s", strchannel[ic].Data()),
"");
5219 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
5220 newtree->Branch(
"ZZMass", &mzz);
5242 double alphasVal=0, mh=0, gah=0, aL1=0, aR1=0, aL2=0, aR2=0;
5244 for (
unsigned int bin=0; bin<binList.size(); bin++){
5245 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
5246 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
5247 int getEv = binList.at(bin).events.at(
ev);
5249 TTree* tree =
findTree(treeList, getEv);
5251 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
5253 TLorentzVector pDaughters[4];
5254 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
5255 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); }
5263 bool hasConst = (tree->GetBranchStatus(strConstBranchname)==1);
5264 bool doCalc=(!hasConst || ctr==0);
5266 mela.computeP(mesq_conserveDifermMass,
false);
5267 if (hasConst) mesq_conserveDifermMass = mesq_calc / cconst_calc;
5269 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
5270 mela.getIORecord()->getVDaughterCouplings(aL1, aR1, 0);
5271 mela.getIORecord()->getVDaughterCouplings(aL2, aR2, 1);
5272 mela.getIORecord()->getHiggsMassWidth(mh, gah, 0);
5274 else mesq_conserveDifermMass = mesq_calc / cconst_calc;
5276 double propagator = 1./(pow(pow(mzz, 2)-pow(mh, 2), 2) + pow(mh*gah, 2));
5278 mesq_conserveDifermMass /= pow(alphasVal, 2);
5279 if (fabs(aL1)>0. || fabs(aR1)>0.) mesq_conserveDifermMass /= pow(aL1, 2)+pow(aR1, 2);
5280 if (fabs(aL2)>0. || fabs(aR2)>0.) mesq_conserveDifermMass /= pow(aL2, 2)+pow(aR2, 2);
5283 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
5286 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, 0);
5288 mela.resetInputEvent();
5292 binList.at(bin).sift(); binList.at(bin).adjustWeights();
5294 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
5295 mzz = binList.at(bin).masses.at(
ev);
5296 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
5297 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
5298 hvar->Fill(mzz, mzz);
5299 if (writeFinalTree) newtree->Fill();
5304 for (
int ix=0; ix<4; ix++) xexyey[ix] =
new double[nbins];
5305 for (
int bin=0; bin<nbins; bin++){
5306 xexyey[0][bin] = hvar->GetBinContent(bin+1);
5307 xexyey[1][bin] = hvar->GetBinError(bin+1);
5309 cout <<
"Bin " << bin <<
" x-center: " << xexyey[0][bin] <<
" +- " << xexyey[1][bin] << endl;
5310 xexyey[2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
5311 xexyey[3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
5312 xexyey[3][bin] = log10(xexyey[3][bin])/xexyey[2][bin];
5313 xexyey[2][bin] = log10(xexyey[2][bin]);
5317 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
5318 tg->SetName(Form(
"tg_%s", hmesq_conserveDifermMass->GetName()));
5319 foutput->WriteTObject(tg);
5322 for (
int ix=0; ix<4; ix++)
delete[] xexyey[ix];
5323 foutput->WriteTObject(hmesq_conserveDifermMass);
5324 foutput->WriteTObject(hvar);
5325 if (writeFinalTree) foutput->WriteTObject(newtree);
5326 if (writeFinalTree)
delete newtree;
5327 delete hmesq_conserveDifermMass;
5331 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
5344 const bool writeFinalTree=
true;
5345 const TString strMEBranchname =
"p_GG_BKG_MCFM";
5346 const TString strConstBranchname =
"pConst_GG_BKG_MCFM";
5349 Mela mela(erg_tev, mPOLE, verbosity);
5359 std::vector<short>* LepLepId=0;
5360 std::vector<float>* LepPt=0;
5361 std::vector<float>* LepEta=0;
5362 std::vector<float>* LepPhi=0;
5364 float mesq_calc=0., cconst_calc=1.;
5365 float mesq_conserveDifermMass=0;
5367 float m1 = 91.471450;
5368 float m2 = 12.139782;
5369 float h1 = 0.2682896;
5370 float h2 = 0.1679779;
5371 float phi = 1.5969792;
5372 float hs = -0.727181;
5373 float phi1 = 1.8828257;
5374 float ZZPt, ZZPhi, ZZEta;
5377 short Z1Flav, Z2Flav;
5381 vector<pair<float, int>> index[3];
5382 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
5383 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s.root", strme.Data(), strprod.Data(), strproc.Data()),
"recreate");
5385 vector<TString> dumappend;
5388 appendVector<TString>(strSamples_13TeV, dumappend);
5392 appendVector<TString>(strSamples_8TeV, dumappend);
5396 appendVector<TString>(strSamples_7TeV, dumappend);
5399 unordered_map<TTree*, pair<float, float>> samplePoleMasses;
5403 appendVector<TString>(strSamples_weighted_13TeV, dumappend);
5405 appendVector<TString>(strSamples_weighted_13TeV, dumappend);
5407 appendVector<TString>(strSamples_weighted_13TeV, dumappend);
5409 vector<TFile*> finputList;
5410 vector<TTree*> treeList;
5412 TString cinput_main;
5414 TREE_NAME =
"ZZTree/candTree";
5417 for (
int is=0; is<(
int)strSamples_weighted_13TeV.size(); is++){
5418 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples_weighted_13TeV[is]).Data());
5419 TFile* finput = TFile::Open(cinput,
"read");
5420 cout <<
"Opening file " << cinput <<
"..." << endl;
5423 if (finput->IsOpen() && !finput->IsZombie()){
5424 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
5425 tree = (TTree*)finput->Get(TREE_NAME);
5427 cout << TREE_NAME <<
" is found." << endl;
5428 if (tree->GetBranchStatus(
"p_Gen_GG_BKG_MCFM")==1){
5429 bool doRecalculate = recalculate;
5430 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0) doRecalculate =
true;
5431 tree->SetBranchStatus(
"*", 0);
5432 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
5433 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
5434 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
5435 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
5436 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
5437 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
5438 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
5439 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
5440 tree->SetBranchStatus(
"Z1Flav", 1); tree->SetBranchAddress(
"Z1Flav", &Z1Flav);
5441 tree->SetBranchStatus(
"Z2Flav", 1); tree->SetBranchAddress(
"Z2Flav", &Z2Flav);
5442 tree->SetBranchStatus(
"p_Gen_GG_BKG_MCFM", 1); tree->SetBranchAddress(
"p_Gen_GG_BKG_MCFM", &wgt);
5443 tree->SetBranchStatus(
"GenHMass", 1); tree->SetBranchAddress(
"GenHMass", &GenHMass);
5444 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0){
5445 tree->SetBranchStatus(strMEBranchname, 1); tree->SetBranchAddress(strMEBranchname, &mesq_calc);
5446 tree->SetBranchStatus(strConstBranchname, 1); tree->SetBranchAddress(strConstBranchname, &cconst_calc);
5448 nEntries += tree->GetEntries();
5449 treeList.push_back(tree);
5450 finputList.push_back(finput);
5452 float polemass =
findPoleMass(strSamples_weighted_13TeV[is]);
5453 float polewidth =
mela.getHiggsWidthAtPoleMass(polemass);
5454 cout << strSamples_weighted_13TeV[is] <<
" pole mass = " << polemass <<
", pole width = " << polewidth << endl;
5455 samplePoleMasses[tree] = pair<float, float>(polemass, polewidth);
5458 cerr << TREE_NAME <<
" in " << cinput <<
" does not have weight p_Gen_GG_BKG_MCFM." << endl;
5462 else finput->Close();
5464 else if (finput->IsOpen()) finput->Close();
5468 TREE_NAME =
"ZZTree/candTree";
5471 for (
int is=0; is<(
int)strSamples_13TeV.size(); is++){
5472 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples_13TeV[is]).Data());
5473 TFile* finput = TFile::Open(cinput,
"read");
5474 cout <<
"Opening file " << cinput <<
"..." << endl;
5477 if (finput->IsOpen() && !finput->IsZombie()){
5478 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
5479 tree = (TTree*)finput->Get(TREE_NAME);
5481 cout << TREE_NAME <<
" is found." << endl;
5482 bool doRecalculate = recalculate;
5483 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0) doRecalculate =
true;
5484 tree->SetBranchStatus(
"*", 0);
5485 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
5486 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
5487 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
5488 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
5489 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
5490 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
5491 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
5492 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
5493 tree->SetBranchStatus(
"Z1Flav", 1); tree->SetBranchAddress(
"Z1Flav", &Z1Flav);
5494 tree->SetBranchStatus(
"Z2Flav", 1); tree->SetBranchAddress(
"Z2Flav", &Z2Flav);
5495 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0){
5496 tree->SetBranchStatus(strMEBranchname, 1); tree->SetBranchAddress(strMEBranchname, &mesq_calc);
5497 tree->SetBranchStatus(strConstBranchname, 1); tree->SetBranchAddress(strConstBranchname, &cconst_calc);
5499 nEntries += tree->GetEntries();
5500 treeList.push_back(tree);
5501 finputList.push_back(finput);
5503 else finput->Close();
5505 else if (finput->IsOpen()) finput->Close();
5509 TREE_NAME =
"SelectedTree";
5510 for (
int ic=0; ic<3; ic++){
5513 for (
int is=0; is<(
int)strSamples_8TeV.size(); is++){
5514 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples_8TeV[is]).Data());
5515 TFile* finput = TFile::Open(cinput,
"read");
5516 cout <<
"Opening file " << cinput <<
"..." << endl;
5519 if (finput->IsOpen() && !finput->IsZombie()){
5520 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
5521 tree = (TTree*)finput->Get(TREE_NAME);
5523 cout << TREE_NAME <<
" is found." << endl;
5524 tree->SetBranchStatus(
"*", 0);
5525 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
5526 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
5527 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
5528 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
5529 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
5530 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
5531 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
5532 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
5533 tree->SetBranchStatus(
"Z1ids", 1); tree->SetBranchAddress(
"Z1ids", &Z1Flav);
5534 tree->SetBranchStatus(
"Z2ids", 1); tree->SetBranchAddress(
"Z2ids", &Z2Flav);
5535 nEntries += tree->GetEntries();
5536 treeList.push_back(tree);
5537 finputList.push_back(finput);
5539 else finput->Close();
5541 else if (finput->IsOpen()) finput->Close();
5546 for (
int is=0; is<(
int)strSamples_7TeV.size(); is++){
5547 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples_7TeV[is]).Data());
5548 TFile* finput = TFile::Open(cinput,
"read");
5549 cout <<
"Opening file " << cinput <<
"..." << endl;
5552 if (finput->IsOpen() && !finput->IsZombie()){
5553 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
5554 tree = (TTree*)finput->Get(TREE_NAME);
5556 cout << TREE_NAME <<
" is found." << endl;
5557 tree->SetBranchStatus(
"*", 0);
5558 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
5559 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
5560 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
5561 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
5562 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
5563 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
5564 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
5565 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
5566 tree->SetBranchStatus(
"Z1ids", 1); tree->SetBranchAddress(
"Z1ids", &Z1Flav);
5567 tree->SetBranchStatus(
"Z2ids", 1); tree->SetBranchAddress(
"Z2ids", &Z2Flav);
5568 nEntries += tree->GetEntries();
5569 treeList.push_back(tree);
5570 finputList.push_back(finput);
5572 else finput->Close();
5574 else if (finput->IsOpen()) finput->Close();
5579 cout <<
"NEntries = " << nEntries <<
" over " << treeList.size() <<
" trees." << endl;
5581 unsigned int ev_acc=0;
5582 for (
int ev=0;
ev<nEntries;
ev++){
5586 Z1Flav*Z2Flav==pow(13, 4)
5588 Z1Flav*Z2Flav==pow(11, 4)
5590 Z1Flav*Z2Flav==pow(11*13, 2)
5593 if (!doProcess)
continue;
5594 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
5595 unsigned int ic = (Z1Flav*Z2Flav==pow(13, 4))*0 + (Z1Flav*Z2Flav==pow(11, 4))*1 + (Z1Flav*Z2Flav==pow(11*13, 2))*2;
5599 cout <<
"Number of valid entries: " << ev_acc << endl;
5601 for (
unsigned int ic=0; ic<3; ic++){
5602 float firstVal=index[ic].at(0).first;
5603 float lastVal=index[ic].at(index[ic].size()-1).first;
5604 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
5605 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
5606 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
5608 float divisor=100000;
5609 if (ic!=2) divisor=130000;
5610 int nbins = index[ic].size()/divisor;
5611 const int nbins_th=10;
5612 while (nbins<nbins_th){
5613 if (divisor>1000) divisor -= 1000;
5614 else if (divisor>100) divisor -= 100;
5616 nbins=index[ic].size()/divisor;
5618 cout <<
"nbins=" << nbins << endl;
5619 if (nbins<3) cerr <<
"Not enough bins!" << endl;
5620 vector<ExtBin> binList;
5621 vector<ExtBin> weightedBinList;
5622 float* binning =
new float[nbins+1];
5624 binning[nbins]=supremum;
5625 int ev_stepsize = index[ic].size()/nbins;
5626 cout <<
"Event step size: " << ev_stepsize << endl;
5627 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
5628 for (
int ix=1; ix<nbins; ix++){
5629 binning[ix]=(index[ic][ix*ev_stepsize-1].first+index[ic][ix*ev_stepsize].first)*0.5;
5630 ExtBin tmpbin, tmpbin_weighted;
5631 tmpbin.
binlow = binning[ix-1]; tmpbin.
binhigh = binning[ix];
5632 tmpbin_weighted.
binlow = binning[ix-1]; tmpbin_weighted.
binhigh = binning[ix];
5633 for (
int bin=0; bin<ev_stepsize; bin++){
5634 int evid = index[ic][(ix-1)*ev_stepsize+bin].
second;
5635 TTree* tree =
findTree(treeList, evid);
5636 if (tree->GetBranchStatus(
"p_Gen_GG_BKG_MCFM")==1) tmpbin_weighted.
events.push_back(evid);
5637 else tmpbin.
events.push_back(evid);
5639 binList.push_back(tmpbin);
5640 weightedBinList.push_back(tmpbin_weighted);
5641 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ic][ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
5643 ExtBin tmpbin, tmpbin_weighted;
5644 tmpbin.
binlow = binning[nbins-1]; tmpbin.
binhigh = binning[nbins];
5645 tmpbin_weighted.
binlow = binning[nbins-1]; tmpbin_weighted.
binhigh = binning[nbins];
5646 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index[ic].size(); bin++){
5647 int evid = index[ic][bin].second;
5648 TTree* tree =
findTree(treeList, evid);
5649 if (tree->GetBranchStatus(
"p_Gen_GG_BKG_MCFM")==1) tmpbin_weighted.
events.push_back(evid);
5650 else tmpbin.
events.push_back(evid);
5652 binList.push_back(tmpbin);
5653 weightedBinList.push_back(tmpbin_weighted);
5654 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
5655 cout <<
"Bin list has the following bins:" << endl;
5656 for (
unsigned int ib=0; ib<binList.size(); ib++){
5657 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
5661 TProfile* hvar =
new TProfile(Form(
"candMass_%s", strchannel[ic].Data()),
"", nbins, binning); hvar->Sumw2();
5662 TProfile* hmesq_conserveDifermMass =
new TProfile(Form(
"P_ConserveDifermionMass_%s", strchannel[ic].Data()),
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
5665 if (writeFinalTree){
5666 newtree =
new TTree(Form(
"FinalTree_%s", strchannel[ic].Data()),
"");
5667 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
5668 newtree->Branch(
"ZZMass", &mzz);
5669 newtree->Branch(
"weight", &wgt);
5670 newtree->Branch(
"isWeighted", &useWeighted);
5692 double alphasVal=0, aL1=0, aR1=0, aL2=0, aR2=0;
5694 for (
unsigned int bin=0; bin<binList.size(); bin++){
5695 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
5696 unsigned int nweighted = weightedBinList.at(bin).events.size();
5697 unsigned int nunweighted = binList.at(bin).events.size();
5698 unsigned int ntotal = nweighted + nunweighted;
5699 for (
unsigned int ev = 0;
ev < ntotal;
ev++){
5701 bool isweighted = (
ev<nweighted);
5702 if (isweighted) getEv = weightedBinList.at(bin).events.at(
ev);
5703 else getEv = binList.at(bin).events.at(
ev-nweighted);
5706 TTree* tree =
findTree(treeList, getEv);
5708 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
5710 TLorentzVector pDaughters[4];
5711 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
5712 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); }
5720 bool hasConst = (tree->GetBranchStatus(strConstBranchname)==1);
5721 bool doCalc=(!hasConst || ctr==0);
5723 mela.computeP(mesq_conserveDifermMass,
false);
5724 if (hasConst) mesq_conserveDifermMass = mesq_calc / cconst_calc;
5726 alphasVal =
mela.getIORecord()->getAlphaSatMZ();
5727 mela.getIORecord()->getVDaughterCouplings(aL1, aR1, 0);
5728 mela.getIORecord()->getVDaughterCouplings(aL2, aR2, 1);
5730 else mesq_conserveDifermMass = mesq_calc / cconst_calc;
5732 mesq_conserveDifermMass /= pow(alphasVal, 2);
5733 if (fabs(aL1)>0. || fabs(aR1)>0.) mesq_conserveDifermMass /= pow(aL1, 2)+pow(aR1, 2);
5734 if (fabs(aL2)>0. || fabs(aR2)>0.) mesq_conserveDifermMass /= pow(aL2, 2)+pow(aR2, 2);
5737 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
5742 float mh = samplePoleMasses[tree].first;
5743 float gh = samplePoleMasses[tree].second;
5744 float prop = 1./(pow(pow(GenHMass, 2) - pow(mh, 2), 2) + pow(mh*gh, 2));
5746 weightedBinList.at(bin).addEvent(mzz, mesq_conserveDifermMass, 0, wgt);
5748 else binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, 0, 1.);
5751 mela.resetInputEvent();
5755 cout <<
"Adjusting weights in weighted samples" << endl;
5756 weightedBinList.at(bin).adjustWeights();
5757 cout <<
"Merging event info. from weighted samples" << endl;
5758 binList.at(bin).mergeBin(weightedBinList.at(bin));
5759 cout <<
"Sifting" << endl;
5760 binList.at(bin).sift();
5762 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
5763 mzz = binList.at(bin).masses.at(
ev);
5764 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
5765 wgt = binList.at(bin).weights.at(
ev);
5766 useWeighted = (wgt!=1.);
5767 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass, wgt);
5768 hvar->Fill(mzz, mzz, wgt);
5769 if (writeFinalTree) newtree->Fill();
5774 for (
int ix=0; ix<4; ix++) xexyey[ix] =
new double[nbins];
5775 for (
int bin=0; bin<nbins; bin++){
5776 xexyey[0][bin] = hvar->GetBinContent(bin+1);
5777 xexyey[1][bin] = hvar->GetBinError(bin+1);
5779 cout <<
"Bin " << bin <<
" x-center: " << xexyey[0][bin] <<
" +- " << xexyey[1][bin] << endl;
5780 xexyey[2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
5781 xexyey[3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
5782 xexyey[3][bin] = log10(xexyey[3][bin])/xexyey[2][bin];
5783 xexyey[2][bin] = log10(xexyey[2][bin]);
5787 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
5788 tg->SetName(Form(
"tg_%s", hmesq_conserveDifermMass->GetName()));
5789 foutput->WriteTObject(tg);
5792 for (
int ix=0; ix<4; ix++)
delete[] xexyey[ix];
5793 foutput->WriteTObject(hmesq_conserveDifermMass);
5794 foutput->WriteTObject(hvar);
5795 if (writeFinalTree) foutput->WriteTObject(newtree);
5796 if (writeFinalTree)
delete newtree;
5797 delete hmesq_conserveDifermMass;
5801 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
5813 const bool writeFinalTree=
true;
5814 const TString strMEBranchname =
"p_QQB_BKG_MCFM";
5815 const TString strConstBranchname =
"pConst_QQB_BKG_MCFM";
5818 Mela mela(erg_tev, mPOLE, verbosity);
5828 std::vector<short>* LepLepId=0;
5829 std::vector<float>* LepPt=0;
5830 std::vector<float>* LepEta=0;
5831 std::vector<float>* LepPhi=0;
5833 float mesq_calc=0., cconst_calc=1.;
5834 float mesq_conserveDifermMass=0;
5836 float m1 = 91.471450;
5837 float m2 = 12.139782;
5838 float h1 = 0.2682896;
5839 float h2 = 0.1679779;
5840 float phi = 1.5969792;
5841 float hs = -0.727181;
5842 float phi1 = 1.8828257;
5843 float ZZPt, ZZPhi, ZZEta;
5844 short Z1Flav, Z2Flav;
5847 vector<pair<float, int>> index[3];
5848 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
5849 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s.root", strme.Data(), strprod.Data(), strproc.Data()),
"recreate");
5855 vector<TFile*> finputList;
5856 vector<TTree*> treeList;
5858 TString cinput_main;
5860 TREE_NAME =
"ZZTree/candTree";
5863 for (
int is=0; is<(
int)strSamples_13TeV.size(); is++){
5864 TString cinput = Form(
"%s/%s/ZZ4lAnalysis.root", cinput_main.Data(), (strSamples_13TeV[is]).Data());
5865 TFile* finput = TFile::Open(cinput,
"read");
5866 cout <<
"Opening file " << cinput <<
"..." << endl;
5869 if (finput->IsOpen() && !finput->IsZombie()){
5870 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
5871 tree = (TTree*)finput->Get(TREE_NAME);
5873 cout << TREE_NAME <<
" is found with " << tree->GetEntries() <<
" events." << endl;
5874 bool doRecalculate = recalculate;
5875 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0) doRecalculate =
true;
5876 tree->SetBranchStatus(
"*", 0);
5877 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
5878 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
5879 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
5880 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
5881 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
5882 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
5883 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
5884 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
5885 tree->SetBranchStatus(
"Z1Flav", 1); tree->SetBranchAddress(
"Z1Flav", &Z1Flav);
5886 tree->SetBranchStatus(
"Z2Flav", 1); tree->SetBranchAddress(
"Z2Flav", &Z2Flav);
5887 if (!doRecalculate && tree->GetBranchStatus(strConstBranchname)==0){
5888 tree->SetBranchStatus(strMEBranchname, 1); tree->SetBranchAddress(strMEBranchname, &mesq_calc);
5889 tree->SetBranchStatus(strConstBranchname, 1); tree->SetBranchAddress(strConstBranchname, &cconst_calc);
5891 nEntries += tree->GetEntries();
5892 treeList.push_back(tree);
5893 finputList.push_back(finput);
5895 else finput->Close();
5897 else if (finput->IsOpen()) finput->Close();
5901 for (
int ic=0; ic<3; ic++){
5902 TREE_NAME =
"SelectedTree";
5905 for (
int is=0; is<(
int)strSamples_8TeV.size(); is++){
5906 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples_8TeV[is]).Data());
5907 TFile* finput = TFile::Open(cinput,
"read");
5908 cout <<
"Opening file " << cinput <<
"..." << endl;
5911 if (finput->IsOpen() && !finput->IsZombie()){
5912 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
5913 tree = (TTree*)finput->Get(TREE_NAME);
5915 cout << TREE_NAME <<
" is found with " << tree->GetEntries() <<
" events." << endl;
5916 tree->SetBranchStatus(
"*", 0);
5917 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
5918 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
5919 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
5920 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
5921 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
5922 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
5923 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
5924 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
5925 tree->SetBranchStatus(
"Z1ids", 1); tree->SetBranchAddress(
"Z1ids", &Z1Flav);
5926 tree->SetBranchStatus(
"Z2ids", 1); tree->SetBranchAddress(
"Z2ids", &Z2Flav);
5927 nEntries += tree->GetEntries();
5928 treeList.push_back(tree);
5929 finputList.push_back(finput);
5931 else finput->Close();
5933 else if (finput->IsOpen()) finput->Close();
5938 for (
int is=0; is<(
int)strSamples_7TeV.size(); is++){
5939 TString cinput = Form(
"%s/%s/%s", cinput_main.Data(), strchannel[ic].Data(), (strSamples_7TeV[is]).Data());
5940 TFile* finput = TFile::Open(cinput,
"read");
5941 cout <<
"Opening file " << cinput <<
"..." << endl;
5944 if (finput->IsOpen() && !finput->IsZombie()){
5945 cout << cinput <<
" opened. Extracting tree " << TREE_NAME <<
"..." << endl;
5946 tree = (TTree*)finput->Get(TREE_NAME);
5948 cout << TREE_NAME <<
" is found with " << tree->GetEntries() <<
" events." << endl;
5949 tree->SetBranchStatus(
"*", 0);
5950 tree->SetBranchStatus(
"ZZMass", 1); tree->SetBranchAddress(
"ZZMass", &mzz);
5951 tree->SetBranchStatus(
"Z1Mass", 1); tree->SetBranchAddress(
"Z1Mass", &m1);
5952 tree->SetBranchStatus(
"Z2Mass", 1); tree->SetBranchAddress(
"Z2Mass", &m2);
5953 tree->SetBranchStatus(
"helcosthetaZ1", 1); tree->SetBranchAddress(
"helcosthetaZ1", &h1);
5954 tree->SetBranchStatus(
"helcosthetaZ2", 1); tree->SetBranchAddress(
"helcosthetaZ2", &h2);
5955 tree->SetBranchStatus(
"helphi", 1); tree->SetBranchAddress(
"helphi", &phi);
5956 tree->SetBranchStatus(
"costhetastar", 1); tree->SetBranchAddress(
"costhetastar", &hs);
5957 tree->SetBranchStatus(
"phistarZ1", 1); tree->SetBranchAddress(
"phistarZ1", &phi1);
5958 tree->SetBranchStatus(
"Z1ids", 1); tree->SetBranchAddress(
"Z1ids", &Z1Flav);
5959 tree->SetBranchStatus(
"Z2ids", 1); tree->SetBranchAddress(
"Z2ids", &Z2Flav);
5960 nEntries += tree->GetEntries();
5961 treeList.push_back(tree);
5962 finputList.push_back(finput);
5964 else finput->Close();
5966 else if (finput->IsOpen()) finput->Close();
5971 cout <<
"NEntries = " << nEntries <<
" over " << treeList.size() <<
" trees." << endl;
5973 unsigned int ev_acc=0;
5974 for (
int ev=0;
ev<nEntries;
ev++){
5978 Z1Flav*Z2Flav==pow(13, 4)
5980 Z1Flav*Z2Flav==pow(11, 4)
5982 Z1Flav*Z2Flav==pow(11*13, 2)
5985 if (!doProcess)
continue;
5986 if (ev_acc%10000==0)
cout <<
"Pre-processing event " <<
ev << endl;
5987 unsigned int ic = (Z1Flav*Z2Flav==pow(13, 4))*0 + (Z1Flav*Z2Flav==pow(11, 4))*1 + (Z1Flav*Z2Flav==pow(11*13, 2))*2;
5991 cout <<
"Number of valid entries: " << ev_acc << endl;
5993 for (
unsigned int ic=0; ic<3; ic++){
5994 float firstVal=index[ic].at(0).first;
5995 float lastVal=index[ic].at(index[ic].size()-1).first;
5996 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
5997 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
5998 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
6000 float divisor=55000;
6001 int nbins = index[ic].size()/divisor;
6002 const int nbins_th=10;
6003 while (nbins<nbins_th){
6004 if (divisor>1000) divisor -= 1000;
6005 else if (divisor>100) divisor -= 100;
6007 nbins=index[ic].size()/divisor;
6009 cout <<
"nbins=" << nbins << endl;
6010 if (nbins<3) cerr <<
"Not enough bins!" << endl;
6011 vector<ExtBin> binList;
6012 float* binning =
new float[nbins+1];
6014 binning[nbins]=supremum;
6015 int ev_stepsize = index[ic].size()/nbins;
6016 cout <<
"Event step size: " << ev_stepsize << endl;
6017 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
6018 for (
int ix=1; ix<nbins; ix++){
6019 binning[ix]=(index[ic][ix*ev_stepsize-1].first+index[ic][ix*ev_stepsize].first)*0.5;
6021 tmpbin.
binlow = binning[ix-1]; tmpbin.
binhigh = binning[ix];
6022 for (
int bin=0; bin<ev_stepsize; bin++){
6023 int evid = index[ic][(ix-1)*ev_stepsize+bin].
second;
6024 tmpbin.
events.push_back(evid);
6026 binList.push_back(tmpbin);
6027 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " << index[ic][ix*ev_stepsize].second <<
", step " << ix*ev_stepsize <<
"]" << endl;
6030 tmpbin.
binlow = binning[nbins-1]; tmpbin.
binhigh = binning[nbins];
6031 for (
unsigned int bin=(nbins-1)*ev_stepsize; bin<index[ic].size(); bin++){
6032 int evid = index[ic][bin].second;
6033 tmpbin.
events.push_back(evid);
6035 binList.push_back(tmpbin);
6036 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
6037 cout <<
"Bin list has the following bins:" << endl;
6038 for (
unsigned int ib=0; ib<binList.size(); ib++){
6039 cout << ib <<
" / " << binList.size() <<
": [" << binList.at(ib).binlow <<
"," << binList.at(ib).binhigh <<
"]" << endl;
6044 TProfile* hvar =
new TProfile(Form(
"candMass_%s", strchannel[ic].Data()),
"", nbins, binning); hvar->Sumw2();
6045 TProfile* hmesq_conserveDifermMass =
new TProfile(Form(
"P_ConserveDifermionMass_%s", strchannel[ic].Data()),
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
6048 if (writeFinalTree){
6049 newtree =
new TTree(Form(
"FinalTree_%s", strchannel[ic].Data()),
"");
6050 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
6051 newtree->Branch(
"ZZMass", &mzz);
6073 double aL1=0, aR1=0, aL2=0, aR2=0,
mz=0, gaz=0;
6075 for (
unsigned int bin=0; bin<binList.size(); bin++){
6076 cout <<
"Bin " << bin <<
" is now being scrutinized..." << endl;
6077 for (
unsigned int ev = 0;
ev < binList.at(bin).events.size();
ev++){
6078 int getEv = binList.at(bin).events.at(
ev);
6080 TTree* tree =
findTree(treeList, getEv);
6082 if (
ev%1000==0)
cout <<
"Doing event " << getEv << endl;
6084 TLorentzVector pDaughters[4];
6085 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
6086 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); }
6094 bool hasConst = (tree->GetBranchStatus(strConstBranchname)==1);
6095 bool doCalc=(!hasConst || ctr==0);
6097 mela.computeP(mesq_conserveDifermMass,
false);
6098 if (hasConst) mesq_conserveDifermMass = mesq_calc / cconst_calc;
6100 mela.getIORecord()->getVDaughterCouplings(aL1, aR1, 0);
6101 mela.getIORecord()->getVDaughterCouplings(aL2, aR2, 1);
6102 mz =
mela.getPrimaryMass(23);
6103 gaz =
mela.getPrimaryWidth(23);
6105 else mesq_conserveDifermMass = mesq_calc / cconst_calc;
6108 if (fabs(aL1)>0. || fabs(aR1)>0.) mesq_conserveDifermMass /= pow(aL1, 2)+pow(aR1, 2);
6109 if (fabs(aL2)>0. || fabs(aR2)>0.) mesq_conserveDifermMass /= pow(aL2, 2)+pow(aR2, 2);
6110 if (fabs(mzz-
mz)<=4.*gaz){
6111 double sh = pow(mzz, 2);
6112 double shdn = pow(
mz-4.*gaz, 2);
6113 double shup = pow(
mz+4.*gaz, 2);
6114 double prop_sh = 1./(pow(sh-pow(
mz, 2), 2) + pow(
mz*gaz, 2));
6115 double prop_shdn = 1./(pow(shdn-pow(
mz, 2), 2) + pow(
mz*gaz, 2));
6116 double prop_shup = 1./(pow(shup-pow(
mz, 2), 2) + pow(
mz*gaz, 2));
6117 double fsh = (sh-shdn)/(shup-shdn);
6118 propagator = prop_sh / (prop_shdn*(1.-fsh) + prop_shup*fsh);
6124 isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)
6127 if (doFill) binList.at(bin).addEvent(mzz, mesq_conserveDifermMass, 0);
6129 mela.resetInputEvent();
6133 binList.at(bin).sift(); binList.at(bin).adjustWeights();
6135 for (
unsigned int ev=0;
ev<binList.at(bin).masses.size();
ev++){
6136 mzz = binList.at(bin).masses.at(
ev);
6137 mesq_conserveDifermMass = binList.at(bin).mevals.at(
ev);
6138 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
6139 hvar->Fill(mzz, mzz);
6140 if (writeFinalTree) newtree->Fill();
6145 for (
int ix=0; ix<4; ix++) xexyey[ix] =
new double[nbins];
6146 for (
int bin=0; bin<nbins; bin++){
6147 xexyey[0][bin] = hvar->GetBinContent(bin+1);
6148 xexyey[1][bin] = hvar->GetBinError(bin+1);
6150 cout <<
"Bin " << bin <<
" x-center: " << xexyey[0][bin] <<
" +- " << xexyey[1][bin] << endl;
6151 xexyey[2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
6152 xexyey[3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
6153 xexyey[3][bin] = log10(xexyey[3][bin])/xexyey[2][bin];
6154 xexyey[2][bin] = log10(xexyey[2][bin]);
6158 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
6159 tg->SetName(Form(
"tg_%s", hmesq_conserveDifermMass->GetName()));
6160 foutput->WriteTObject(tg);
6163 for (
int ix=0; ix<4; ix++)
delete[] xexyey[ix];
6164 foutput->WriteTObject(hmesq_conserveDifermMass);
6165 foutput->WriteTObject(hvar);
6166 if (writeFinalTree) foutput->WriteTObject(newtree);
6167 if (writeFinalTree)
delete newtree;
6168 delete hmesq_conserveDifermMass;
6172 for (
unsigned int f=0;
f<finputList.size();
f++) finputList.at(
f)->Close();
6177 const int erg_tev=13;
6178 const float mPOLE=125.;
6181 Mela mela(erg_tev, mPOLE, verbosity);
6194 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s.root", strme.Data(), strprod.Data(), strproc.Data()),
"recreate");
6196 cout <<
"Acquiring Mela measurables and pdf..." << endl;
6198 const double xrange[2]={ max(57., (
double)((
int)(m1_low+m2_low+0.5))), 15000. };
6199 vector<double> masses;
6200 double massmin=xrange[0];
6201 double mass=massmin;
6202 while (mass<=xrange[1]){
6203 masses.push_back(mass);
6205 if (mass<90.) massinc=1;
6206 else if (mass<122.) massinc=4;
6207 else if (mass<194.) massinc=2;
6208 else if (mass<200.) massinc=3;
6209 else if (mass<600.) massinc=20.;
6210 else if (mass<1500.) massinc=100.;
6211 else if (mass<3000.) massinc=250.;
6212 else if (mass<10000.) massinc=500.;
6216 const unsigned int npoints=masses.size();
6217 ((RooRealVar*)measurables.
m12)->setRange(xrange[0], xrange[1]);
6218 ((RooRealVar*)measurables.
m1)->setRange(m1_low, 120); ((RooRealVar*)measurables.
m1)->setVal(m1_low);
6219 ((RooRealVar*)measurables.
m2)->setRange(m2_low, 120); ((RooRealVar*)measurables.
m2)->setVal(m2_low);
6221 for (
int i=0; i<2; i++) xy[i] =
new double[npoints];
6223 mela.upFrac_rrv->setVal(1.);
6224 mela.upFrac_rrv->setConstant(
true);
6226 RooAbsPdf* pdf =
mela.qqZZmodel;
6228 pdf->defaultIntegratorConfig()->method1D().setLabel(
"RooAdaptiveGaussKronrodIntegrator1D");
6229 pdf->defaultIntegratorConfig()->getConfigSection(
"RooAdaptiveGaussKronrodIntegrator1D").setRealValue(
"maxSeg", 100);;
6230 pdf->defaultIntegratorConfig()->method2D().setLabel(
"RooAdaptiveGaussKronrodIntegrator2D");
6231 pdf->defaultIntegratorConfig()->getConfigSection(
"RooAdaptiveGaussKronrodIntegrator2D").setRealValue(
"maxSeg", 100);;
6232 pdf->defaultIntegratorConfig()->methodND().setLabel(
"RooAdaptiveGaussKronrodIntegratorND");
6233 pdf->defaultIntegratorConfig()->getConfigSection(
"RooAdaptiveGaussKronrodIntegratorND").setRealValue(
"maxSeg", 100);;
6234 pdf->defaultIntegratorConfig()->setEpsAbs(1e-5);
6235 pdf->defaultIntegratorConfig()->setEpsRel(1e-5);
6237 cout <<
"Computing pdf integral as a function of " << measurables.
m12->GetName() << endl;
6238 RooRealIntegral* pdfInt =
new RooRealIntegral(
6241 *measurables.
h1, *measurables.
h2, *measurables.
Phi,
6242 *measurables.
hs, *measurables.
Phi1,
6243 *measurables.
m1, *measurables.
m2
6248 for (
unsigned int ix=0; ix<npoints; ix++){
6249 xy[0][ix]=masses.at(ix);
6250 ((RooRealVar*)measurables.
m12)->setVal(xy[0][ix]);
6251 xy[1][ix]=pdfInt->getVal();
6252 cout <<
"pdfInt(" << xy[0][ix] <<
") = " << xy[1][ix] << endl;
6253 xy[1][ix] = log10(xy[1][ix]);
6255 TGraph* tg =
new TGraph(npoints, xy[0], xy[1]);
6256 tg->SetName(
"tg_anaPdfInt");
6258 foutput->WriteTObject(tg);
6261 for (
int i=0; i<2; i++)
delete[] xy[i];
6267 const int erg_tev=13;
6268 const float mPOLE=125.;
6271 Mela mela(erg_tev, mPOLE, verbosity);
6284 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s.root", strme.Data(), strprod.Data(), strproc.Data()),
"recreate");
6286 cout <<
"Acquiring Mela measurables and pdf..." << endl;
6288 const double xrange[2]={ max(57., (
double)((
int)(m1_low+m2_low+0.5))), 15000. };
6289 vector<double> masses;
6290 double massmin=xrange[0];
6291 double mass=massmin;
6292 while (mass<=xrange[1]){
6293 masses.push_back(mass);
6295 if (mass<90.) massinc=1;
6296 else if (mass<194.) massinc=2;
6297 else if (mass<200.) massinc=3;
6298 else if (mass<600.) massinc=20.;
6299 else if (mass<1500.) massinc=100.;
6300 else if (mass<3000.) massinc=250.;
6301 else if (mass<10000.) massinc=500.;
6305 const unsigned int npoints=masses.size();
6306 ((RooRealVar*)measurables.
m12)->setRange(xrange[0], xrange[1]);
6307 ((RooRealVar*)measurables.
m1)->setRange(m1_low, 120); ((RooRealVar*)measurables.
m1)->setVal(m1_low);
6308 ((RooRealVar*)measurables.
m2)->setRange(m2_low, 120); ((RooRealVar*)measurables.
m2)->setVal(m2_low);
6310 for (
int i=0; i<2; i++) xy[i] =
new double[npoints];
6312 mela.upFrac_rrv->setVal(1.);
6313 mela.upFrac_rrv->setConstant(
true);
6315 RooAbsPdf* pdf =
mela.ggSpin0Model->getPDF();
6316 pdf->defaultIntegratorConfig()->method1D().setLabel(
"RooAdaptiveGaussKronrodIntegrator1D");
6317 pdf->defaultIntegratorConfig()->getConfigSection(
"RooAdaptiveGaussKronrodIntegrator1D").setRealValue(
"maxSeg", 100);;
6318 pdf->defaultIntegratorConfig()->method2D().setLabel(
"RooAdaptiveGaussKronrodIntegrator2D");
6319 pdf->defaultIntegratorConfig()->getConfigSection(
"RooAdaptiveGaussKronrodIntegrator2D").setRealValue(
"maxSeg", 100);;
6320 pdf->defaultIntegratorConfig()->methodND().setLabel(
"RooAdaptiveGaussKronrodIntegratorND");
6321 pdf->defaultIntegratorConfig()->getConfigSection(
"RooAdaptiveGaussKronrodIntegratorND").setRealValue(
"maxSeg", 100);;
6322 pdf->defaultIntegratorConfig()->setEpsAbs(1e-5);
6323 pdf->defaultIntegratorConfig()->setEpsRel(1e-5);
6325 cout <<
"Computing pdf integral as a function of " << measurables.
m12->GetName() << endl;
6326 RooRealIntegral* pdfInt =
new RooRealIntegral(
6329 *measurables.
h1, *measurables.
h2, *measurables.
Phi,
6330 *measurables.
hs, *measurables.
Phi1,
6331 *measurables.
m1, *measurables.
m2
6336 for (
unsigned int ix=0; ix<npoints; ix++){
6337 xy[0][ix]=masses.at(ix);
6338 ((RooRealVar*)measurables.
m12)->setVal(xy[0][ix]);
6339 xy[1][ix]=pdfInt->getVal();
6340 cout <<
"pdfInt(" << xy[0][ix] <<
") = " << xy[1][ix] << endl;
6341 xy[1][ix] = log10(xy[1][ix]);
6343 TGraph* tg =
new TGraph(npoints, xy[0], xy[1]);
6344 tg->SetName(
"tg_anaPdfInt");
6346 foutput->WriteTObject(tg);
6349 for (
int i=0; i<2; i++)
delete[] xy[i];
6355 if (!(strprod ==
"Had_ZH" || strprod ==
"Had_WH"))
return;
6361 Mela mela(erg_tev, mPOLE, verbosity);
6374 mVPOLE=
mela.getPrimaryMass(23);
6379 mVPOLE=
mela.getPrimaryMass(24);
6386 cout <<
"Acquiring measurables and pdf..." << endl;
6387 const double xrange[2]={ 57,
sqrts*1000.-1. };
6388 RooRealVar* m12 =
new RooRealVar(
"m12",
"m_{H} (GeV)", mPOLE, xrange[0], xrange[1]);
6389 RooRealVar* m1 =
new RooRealVar(
"m1",
"m1", 460, (mVPOLE)-10.,
sqrts*1000.);
6390 RooRealVar* m2 =
new RooRealVar(
"m2",
"m2", mVPOLE, mVPOLE-0.05, mVPOLE+0.05);
6391 RooRealVar* h1 =
new RooRealVar(
"h1",
"cos#theta_{V*}", -1, 1);
6392 RooRealVar* h2 =
new RooRealVar(
"h2",
"cos#theta_{V}", -1, 1);
6393 RooRealVar* Phi1 =
new RooRealVar(
"Phi1",
"#Phi_{V*}", -TMath::Pi(), TMath::Pi());
6394 RooRealVar* hs =
new RooRealVar(
"hs",
"cos#theta^{*}", -1, 1);
6395 RooRealVar* Phi =
new RooRealVar(
"Phi",
"#Phi", -TMath::Pi(), TMath::Pi());
6396 RooRealVar* Y =
new RooRealVar(
"Y",
"Y", 0, -4, 4);
6399 measurables.
h1 = h1;
6400 measurables.
h2 = h2;
6401 measurables.
Phi = Phi;
6402 measurables.
m1 = m1;
6403 measurables.
m2 = m2;
6404 measurables.
m12 = m12;
6405 measurables.
hs = hs;
6406 measurables.
Phi1 = Phi1;
6410 cout <<
"m2 is fixed to " << measurables.
m2->getVal() << endl;
6412 RooRealVar* g1List[8][2];
6413 RooRealVar* g2List[8][2];
6415 RooRealVar* g4List[8][2];
6416 for (
int gg=0; gg<8; gg++){
6417 for (
int im=0; im<2; im++){
6424 g1List[0][0]->setVal(1);
6426 TFile* foutput = TFile::Open(Form(
"pAvgLinToLog_%s_%s_%s_%iTeV.root", strme.Data(), strprod.Data(), strproc.Data(),
sqrts),
"recreate");
6428 m12->setConstant(
false);
6429 vector<double> masses;
6430 double massmin=xrange[0];
6431 double mass=massmin;
6432 while (mass<=xrange[1]){
6433 masses.push_back(mass);
6435 if (mass<90.) massinc=1;
6436 else if (mass<194.) massinc=2;
6437 else if (mass<200.) massinc=3;
6438 else if (mass<600.) massinc=20.;
6439 else if (mass<1500.) massinc=100.;
6440 else if (mass<3000.) massinc=250.;
6441 else if (mass<10000.) massinc=500.;
6445 const unsigned int npoints=masses.size();
6446 m12->setRange(xrange[0], xrange[1]);
6449 for (
int i=0; i<2; i++) xy[i] =
new double[npoints];
6451 RooAbsPdf* pdf = fac.
getPDF();
6463 cout <<
"Computing pdf integral as a function of " << measurables.
m12->GetName() << endl;
6464 for (
unsigned int ix=0; ix<npoints; ix++){
6465 xy[0][ix]=masses.at(ix);
6466 m12->setVal(xy[0][ix]);
6467 ((RooRealVar*)fac.
parameters.
mX)->setVal(m12->getVal());
6470 float m1_low = xy[0][ix] + measurables.
m2->getVal();
6471 m1->setRange(m1_low, 1000.*
sqrts);
6472 m1->setVal((m1->getMin()+m1->getMax())/2.);
6473 cout <<
"m1 min, max, val = " << m1->getMin() <<
" " << m1->getMax() <<
" " << m1->getVal() << endl;
6475 RooRealIntegral* pdfInt =
new RooRealIntegral(
6478 *measurables.
h1, *measurables.
h2, *measurables.
Phi,
6479 *measurables.
hs, *measurables.
Phi1
6485 if (ix==0) pdfInt->Print(
"v");
6486 xy[1][ix]=pdfInt->getVal();
6489 cout <<
"pdfInt(" << xy[0][ix] <<
") = " << xy[1][ix] << endl;
6490 xy[1][ix] = log10(xy[1][ix]);
6492 TGraph* tg =
new TGraph(npoints, xy[0], xy[1]);
6493 tg->SetName(
"tg_anaPdfInt");
6495 foutput->WriteTObject(tg);
6497 for (
int i=0; i<2; i++)
delete[] xy[i];
6520 TString TREE_NAME =
"ZZTree/candTree";
6521 const bool writeFinalTree=
false;
6524 Mela mela(erg_tev, mPOLE, verbosity);
6526 float mesq_conserveDifermMass=0;
6535 vector<float>* mzz_array=0;
6536 vector<float>* m1_array=0;
6537 vector<float>* m2_array=0;
6538 vector<float>* h1_array=0;
6539 vector<float>* h2_array=0;
6540 vector<float>* phi_array=0;
6541 vector<float>* hs_array=0;
6542 vector<float>* phi1_array=0;
6543 vector<short>* ZZsel=0;
6544 vector<short>* ZZCandType=0;
6545 int LepID[4]={ 0, 0, 11, -11 };
6547 TString cinput_main =
"/scratch0/hep/usarical/CJLST/LHC_13TeV/2l2q/";
6548 const int nSamples = 2;
6549 TString strSamples[nSamples]={
6550 "ZZ2l2qAnalysis_DY2JetsToLL.root",
6551 "ZZ2l2qAnalysis_DYJetsToLL.root"
6554 TFile* foutput =
new TFile(
"pAvgLinToLog_MCFM_JJQCD_bkgZJets_13TeV_2l2q.root",
"recreate");
6557 TChain* tree =
new TChain(TREE_NAME,
"");
6558 for (
int is=0; is<nSamples; is++) tree->Add(Form(
"%s/%s", cinput_main.Data(), (strSamples[is]).Data()));
6559 tree->SetBranchAddress(
"ZZCandType", &ZZCandType);
6560 tree->SetBranchAddress(
"ZZsel", &ZZsel);
6561 tree->SetBranchAddress(
"ZZMass", &mzz_array);
6562 tree->SetBranchAddress(
"Z1Mass", &m1_array);
6563 tree->SetBranchAddress(
"Z2Mass", &m2_array);
6564 tree->SetBranchAddress(
"helcosthetaZ1", &h1_array);
6565 tree->SetBranchAddress(
"helcosthetaZ2", &h2_array);
6566 tree->SetBranchAddress(
"helphi", &phi_array);
6567 tree->SetBranchAddress(
"costhetastar", &hs_array);
6568 tree->SetBranchAddress(
"phistarZ1", &phi1_array);
6570 int nTotalEntries = tree->GetEntries();
6572 TTree* tmptree =
new TTree(
"IntermediateTree",
"");
6573 tmptree->Branch(
"ZZMass", &mzz);
6574 tmptree->Branch(
"Z1Mass", &m1);
6575 tmptree->Branch(
"Z2Mass", &m2);
6576 tmptree->Branch(
"helcosthetaZ1", &h1);
6577 tmptree->Branch(
"helcosthetaZ2", &h2);
6578 tmptree->Branch(
"helphi", &phi);
6579 tmptree->Branch(
"costhetastar", &hs);
6580 tmptree->Branch(
"phistarZ1", &phi1);
6583 cout <<
"Nrawentries = " << nTotalEntries << endl;
6584 for (
int ev = 0;
ev < nTotalEntries;
ev++){
6586 for (
unsigned int j=0; j < ZZsel->size(); j++){
6587 if (ZZsel->at(j)>=90 && (ZZCandType->at(j)==2 || ZZCandType->at(j)==1)){
6588 if (ctr%100==0)
cout <<
"Event " << ctr <<
" being recorded at actual event " <<
ev <<
"." << endl;
6589 mzz=mzz_array->at(j);
6595 phi=phi_array->at(j);
6596 phi1=phi1_array->at(j);
6603 nTotalEntries=tmptree->GetEntries();
6604 cout <<
"Ntotalentries = " << nTotalEntries << endl;
6606 TTree* tmptree2 =
new TTree(
"IntermediateTree2",
"");
6607 tmptree2->Branch(
"ZZMass", &mzz);
6608 tmptree2->Branch(
"Z1Mass", &m1);
6609 tmptree2->Branch(
"Z2Mass", &m2);
6610 tmptree2->Branch(
"helcosthetaZ1", &h1);
6611 tmptree2->Branch(
"helcosthetaZ2", &h2);
6612 tmptree2->Branch(
"helphi", &phi);
6613 tmptree2->Branch(
"costhetastar", &hs);
6614 tmptree2->Branch(
"phistarZ1", &phi1);
6616 TRandom3 randomthrow(1234567);
6617 double portion_to_keep = 1;
6618 if (nTotalEntries>1000000) portion_to_keep = 9.95e5/nTotalEntries;
6619 for (
int ev = 0;
ev < nTotalEntries;
ev++){
6620 tmptree->GetEntry(
ev);
6621 double rndnum = randomthrow.Uniform();
6622 if (rndnum<=portion_to_keep) tmptree2->Fill();
6627 const int nEntries = tmptree->GetEntries();
6628 if (nEntries>=1000000){
6629 cerr <<
"TMath::Sort will experience problems. Aborting!" << endl;
6634 int* index =
new int[nEntries];
6635 tmptree->Draw(
"ZZMass",
"",
"goff");
6636 TMath::Sort(nEntries, tmptree->GetV1(), index,
false);
6638 tmptree->GetEntry(index[0]);
6640 tmptree->GetEntry(index[nEntries-1]);
6642 float infimum = (float)((
int)firstVal); infimum -= (float)(((
int)infimum)%10);
6643 float supremum = (float)((
int)(lastVal+0.5)); supremum += (float)(10-((
int)supremum)%10);
6644 cout <<
"Nentries = " << nEntries <<
" | mzz = " << firstVal <<
" - " << lastVal <<
"(" << infimum <<
", " << supremum <<
")" << endl;
6649 if (divisor>1000) divisor -= 1000;
6650 else if (divisor>100) divisor -= 100;
6652 nbins=nEntries/divisor+1;
6654 cout <<
"nbins=" << nbins << endl;
6655 if (nbins<3) cerr <<
"Not enough bins!" << endl;
6656 float* binning =
new float[nbins+1];
6658 binning[nbins]=supremum;
6659 int ev_stepsize = nEntries/nbins;
6660 cout <<
"Event step size: " << ev_stepsize << endl;
6661 cout <<
"Boundary (" << 0 <<
") = " << binning[0] << endl;
6662 for (
int ix=1; ix<nbins; ix++){
6663 int ev = index[ix*ev_stepsize];
6664 tmptree->GetEntry(
ev);
6666 ev = index[ix*ev_stepsize-1];
6668 binning[ix]=(bhigh+blow)*0.5;
6669 cout <<
"Boundary (" << ix <<
")= " << binning[ix] <<
" [event " <<
ev <<
", step " << ix*ev_stepsize <<
"]" << endl;
6671 cout <<
"Boundary (" << nbins <<
") = " << binning[nbins] << endl;
6675 TProfile* hvar =
new TProfile(
"candMass",
"", nbins, binning); hvar->Sumw2();
6676 TProfile* hmesq_conserveDifermMass =
new TProfile(
"P_ConserveDifermionMass",
"", nbins, binning); hmesq_conserveDifermMass->Sumw2();
6679 if (writeFinalTree){
6680 newtree =
new TTree(
"FinalTree",
"");
6681 newtree->Branch(
"mesq_conserveDifermMass", &mesq_conserveDifermMass);
6682 newtree->Branch(
"ZZMass", &mzz);
6687 for (
int ev = 0;
ev < nEntries;
ev++){
6688 tmptree->GetEntry(
ev);
6689 if (
ev%10000==0)
cout <<
"Doing event " <<
ev << endl;
6691 TLorentzVector pDaughters[4];
6692 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
6693 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); }
6703 mela.computeP(mesq_conserveDifermMass,
false);
6704 double aL1, aR1, aL2, aR2;
6705 mela.getIORecord()->getVDaughterCouplings(aL1, aR1, 0);
6706 mela.getIORecord()->getVDaughterCouplings(aL2, aR2, 1);
6707 if (fabs(aL1)>0. || fabs(aR1)>0.) mesq_conserveDifermMass /= pow(aL1, 2)+pow(aR1, 2);
6708 if (fabs(aL2)>0. || fabs(aR2)>0.) mesq_conserveDifermMass /= pow(aL2, 2)+pow(aR2, 2);
6709 cout <<
"aL1: " << aL1 <<
'\t';
6710 cout <<
"aR1: " << aR1 <<
'\t';
6711 cout <<
"aL2: " << aL2 <<
'\t';
6712 cout <<
"aR2: " << aR2 << endl;
6714 if (
isnan(mesq_conserveDifermMass) || isinf(mesq_conserveDifermMass)) doFill=
false;
6717 hmesq_conserveDifermMass->Fill(mzz, mesq_conserveDifermMass);
6718 hvar->Fill(mzz, mzz);
6721 if (writeFinalTree) newtree->Fill();
6722 mela.resetInputEvent();
6726 for (
int ix=0; ix<4; ix++) xexyey[ix] =
new double[nbins];
6727 for (
int bin=0; bin<nbins; bin++){
6728 xexyey[0][bin] = hvar->GetBinContent(bin+1);
6729 xexyey[1][bin] = hvar->GetBinError(bin+1);
6731 cout <<
"Bin " << bin <<
" x-center: " << xexyey[0][bin] <<
" +- " << xexyey[1][bin] << endl;
6732 xexyey[2][bin] = hmesq_conserveDifermMass->GetBinContent(bin+1);
6733 xexyey[3][bin] = hmesq_conserveDifermMass->GetBinError(bin+1);
6734 xexyey[3][bin] = log10(xexyey[3][bin])/xexyey[2][bin];
6735 xexyey[2][bin] = log10(xexyey[2][bin]);
6739 TGraphErrors* tg =
new TGraphErrors(nbins, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
6740 tg->SetName(Form(
"tg_%s", hmesq_conserveDifermMass->GetName()));
6741 foutput->WriteTObject(tg);
6744 for (
int ix=0; ix<4; ix++)
delete[] xexyey[ix];
6745 foutput->WriteTObject(hmesq_conserveDifermMass);
6746 foutput->WriteTObject(hvar);
6747 if (writeFinalTree) foutput->WriteTObject(newtree);
6748 if (writeFinalTree)
delete newtree;
6749 delete hmesq_conserveDifermMass;
6760 unsigned int nbins = tg->GetN();
6765 TSpline3* spline =
new TSpline3(
"spline", tg,
"b2e2", 0, 0);
6766 spline->SetName(Form(
"sp_%s", tg->GetName()));
6767 if (dfirst!=0) *dfirst = spline->Derivative(xy[0][0]);
6768 if (dlast!=0) *dlast = spline->Derivative(xy[0][nbins-1]);
6776 unsigned int nbins = tg->GetN();
6781 double derivative_first = (xy[1][1]-xy[1][0])/(xy[0][1]-xy[0][0]);
6782 double derivative_last = (xy[1][nbins-1]-xy[1][nbins-2])/(xy[0][nbins-1]-xy[0][nbins-2]);
6784 if (faithfulLow && faithfulHigh) spline =
new TSpline3(
"spline", tg,
"b1e1", derivative_first, derivative_last);
6785 else if (!faithfulLow && faithfulHigh) spline =
new TSpline3(
"spline", tg,
"b2e1", 0, derivative_last);
6786 else if (faithfulLow && !faithfulHigh) spline =
new TSpline3(
"spline", tg,
"b1e2", derivative_first, 0);
6787 else return nullptr;
6788 spline->SetName(Form(
"sp_%s", tg->GetName()));
6789 if (dfirst!=0) *dfirst = spline->Derivative(xy[0][0]);
6790 if (dlast!=0) *dlast = spline->Derivative(xy[0][nbins-1]);
6796 unsigned int nbins = tg->GetN();
6801 double derivative_first = (xy[1][1]-xy[1][0])/(xy[0][1]-xy[0][0]);
6802 double derivative_last = (xy[1][nbins-1]-xy[1][nbins-2])/(xy[0][nbins-1]-xy[0][nbins-2]);
6803 TSpline5* spline =
new TSpline5(
"spline", tg,
"b1e1", derivative_first, derivative_last);
6804 spline->SetName(Form(
"sp_%s", tg->GetName()));
6805 if (dfirst!=0) *dfirst=derivative_first;
6806 if (dlast!=0) *dlast=derivative_last;
6810 double xmin = sp->GetXmin();
6811 double xmax = sp->GetXmax();
6812 const int nbins=500;
6813 double xyval[2][nbins+1];
6814 double interval = (xmax-
xmin)/nbins;
6815 for (
int ix=0; ix<=nbins; ix++){
6816 xyval[0][ix] =
xmin + ix*interval;
6817 xyval[1][ix] = sp->Eval(xyval[0][ix]);
6819 double dfirst = sp->Derivative(
xmin);
6820 double dlast = sp->Derivative(xmax);
6821 TSpline3* sp_new =
new TSpline3(
"spline", xyval[0], xyval[1], nbins+1,
"b1e1", dfirst, dlast);
6822 sp_new->SetName(sp->GetName());
6823 sp_new->SetTitle(sp->GetTitle());
6830 if (useLowBound) x = sp->GetXmin();
6831 else x = sp->GetXmax();
6838 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
6839 else fcnName = Form(
"highFcn_%s", sp->GetName());
6840 TF1* fcn =
new TF1(fcnName,
"[0]",
xmin, xmax);
6841 fcn->SetParameter(0, a0);
6849 if (useLowBound) x = sp->GetXmin();
6850 else x = sp->GetXmax();
6852 s = sp->Derivative(x);
6859 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
6860 else fcnName = Form(
"highFcn_%s", sp->GetName());
6861 TF1* fcn =
new TF1(fcnName,
"[0]+[1]*exp(x)",
xmin, xmax);
6862 fcn->SetParameter(0, a0);
6863 fcn->SetParameter(1,
a1);
6871 if (useLowBound) x = sp->GetXmin();
6872 else x = sp->GetXmax();
6874 s = sp->Derivative(x);
6881 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
6882 else fcnName = Form(
"highFcn_%s", sp->GetName());
6883 TF1* fcn =
new TF1(fcnName,
"[0]+[1]/x",
xmin, xmax);
6884 fcn->SetParameter(0, a0);
6885 fcn->SetParameter(1,
a1);
6893 if (useLowBound) x = sp->GetXmin();
6894 else x = sp->GetXmax();
6896 s = sp->Derivative(x);
6899 a0 = -y*pow(x, 2)-s*pow(x, 3);
6900 a1 = -2.*y*x-s*pow(x, 2);
6903 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
6904 else fcnName = Form(
"highFcn_%s", sp->GetName());
6905 TF1* fcn =
new TF1(fcnName,
"[0]/x/x-[1]/x",
xmin, xmax);
6906 fcn->SetParameter(0, a0);
6907 fcn->SetParameter(1,
a1);
6915 if (useLowBound) x = sp->GetXmin();
6916 else x = sp->GetXmax();
6918 s = sp->Derivative(x);
6921 double disc = 1.+8.*x*s;
6923 a1 = x/4.*(1.+sqrt(disc));
6924 a0 = y-
a1/x+pow(
a1/x, 2);
6925 cout << x <<
'\t' << a0 <<
'\t' <<
a1 <<
'\t' << s <<
'\t' << y << endl;
6928 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
6929 else fcnName = Form(
"highFcn_%s", sp->GetName());
6930 TF1* fcn =
new TF1(fcnName,
"[0]+[1]/x-pow([1]/x, 2)",
xmin, xmax);
6931 fcn->SetParameter(0, a0);
6932 fcn->SetParameter(1,
a1);
6941 if (useLowBound) x = sp->GetXmin();
6942 else x = sp->GetXmax();
6944 s = sp->Derivative(x);
6951 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
6952 else fcnName = Form(
"highFcn_%s", sp->GetName());
6953 TF1* fcn =
new TF1(fcnName,
"[0]+[1]*x",
xmin, xmax);
6954 fcn->SetParameter(0, a0);
6955 fcn->SetParameter(1,
a1);
6973 s = sp->Derivative(x);
6974 sh = sp->Derivative(xh);
6978 a2 = d*pow(x, 4)/6.;
6979 a1 = s+2.*
a2/pow(x, 3);
6980 a0 = y-
a1*x-
a2/pow(x, 2);
6983 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
6984 else fcnName = Form(
"highFcn_%s", sp->GetName());
6985 TF1* fcn =
new TF1(fcnName,
"[0]+[1]*x+[2]/pow(x, 2)",
xmin, xmax);
6986 fcn->SetParameter(0, a0);
6987 fcn->SetParameter(1,
a1);
6988 fcn->SetParameter(2,
a2);
7006 s = sp->Derivative(x);
7007 sh = sp->Derivative(xh);
7013 a0 = y-
a1*x-
a2*pow(x, 2);
7016 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
7017 else fcnName = Form(
"highFcn_%s", sp->GetName());
7018 TF1* fcn =
new TF1(fcnName,
"[0]+[1]*x+[2]*pow(x, 2)",
xmin, xmax);
7019 fcn->SetParameter(0, a0);
7020 fcn->SetParameter(1,
a1);
7021 fcn->SetParameter(2,
a2);
7027 TGraph*
getPatch_a0a1(TSpline3* sp, TSpline3* sppatch,
double xmin,
double xmax,
bool useLowBound,
bool forceOutput=
true){
7029 double y_patch, s_patch;
7030 if (useLowBound) x = sp->GetXmin();
7031 else x = sp->GetXmax();
7033 s = sp->Derivative(x);
7034 y_patch = sppatch->Eval(x);
7035 s_patch = sppatch->Derivative(x);
7041 int n = (xmax-
xmin+0.5);
7042 cout <<
"Patcher n: " << n << endl;
7043 double xwidth = (xmax-
xmin)/n;
7045 for (
unsigned int i=0; i<2; i++) xy[i]=
new double[n+1];
7046 for (
int ip=0; ip<=n; ip++){
7047 double xval =
xmin+xwidth*ip;
7048 double yval = sppatch->Eval(xval);
7054 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
7055 else fcnName = Form(
"highFcn_%s", sp->GetName());
7056 TGraph* fcn =
new TGraph(n+1, xy[0], xy[1]);
7057 fcn->SetName(fcnName);
7059 for (
unsigned int i=0; i<2; i++)
delete[] xy[i];
7066 if (useLowBound) x = sp->GetXmin();
7067 else x = sp->GetXmax();
7069 s = sp->Derivative(x);
7070 y -= sppatch->Eval(x);
7071 s -= sppatch->Derivative(x);
7077 cout <<
"getPatch_a0plusa1overX: Checking if patch will flip: " << endl;
7079 if (useLowBound) xext = x;
7081 if (1.-
a1/pow(xext, 2)/sppatch->Derivative(xext)<0.){
7082 cout <<
"Sign flips at " << xext << endl;
7083 if (!forceOutput)
return 0;
7085 else cout <<
"Sign does not flip at " << xext << endl;
7087 int n = (xmax-
xmin+0.5);
7088 cout <<
"Patcher n: " << n << endl;
7089 double xwidth = (xmax-
xmin)/n;
7091 for (
unsigned int i=0; i<2; i++) xy[i]=
new double[n+1];
7092 for (
int ip=0; ip<=n; ip++){
7093 double xval =
xmin+xwidth*ip;
7094 if (xval==0.) xval += xwidth*0.5;
7095 double yval = sppatch->Eval(xval);
7096 yval += (a0+
a1/xval);
7101 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
7102 else fcnName = Form(
"highFcn_%s", sp->GetName());
7103 TGraph* fcn =
new TGraph(n+1, xy[0], xy[1]);
7104 fcn->SetName(fcnName);
7106 for (
unsigned int i=0; i<2; i++)
delete[] xy[i];
7113 if (useLowBound) x = sp->GetXmin();
7114 else x = sp->GetXmax();
7116 s = sp->Derivative(x);
7117 y -= sppatch->Eval(x);
7118 s -= sppatch->Derivative(x);
7124 cout <<
"getPatch_a0plusa1timesX: Checking if patch will flip: " << endl;
7126 if (useLowBound) xext = x;
7128 if (1.+
a1/sppatch->Derivative(xext)<0.){
7129 cout <<
"Sign flips at " << xext << endl;
7130 if (!forceOutput)
return 0;
7132 else cout <<
"Sign does not flip at " << xext << endl;
7134 int n = (xmax-
xmin+0.5);
7135 cout <<
"Patcher n: " << n << endl;
7136 double xwidth = (xmax-
xmin)/n;
7138 for (
unsigned int i=0; i<2; i++) xy[i]=
new double[n+1];
7139 for (
int ip=0; ip<=n; ip++){
7140 double xval =
xmin+xwidth*ip;
7141 double yval = sppatch->Eval(xval);
7142 yval += (a0+
a1*xval);
7147 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
7148 else fcnName = Form(
"highFcn_%s", sp->GetName());
7149 TGraph* fcn =
new TGraph(n+1, xy[0], xy[1]);
7150 fcn->SetName(fcnName);
7152 for (
unsigned int i=0; i<2; i++)
delete[] xy[i];
7159 if (useLowBound) x = sp->GetXmin();
7160 else x = sp->GetXmax();
7162 s = sp->Derivative(x);
7163 y -= sppatch->Eval(x);
7164 s -= sppatch->Derivative(x);
7170 int n = (xmax-
xmin+0.5);
7171 cout <<
"Patcher n: " << n << endl;
7172 double xwidth = (xmax-
xmin)/n;
7174 for (
unsigned int i=0; i<2; i++) xy[i]=
new double[n+1];
7175 for (
int ip=0; ip<=n; ip++){
7176 double xval =
xmin+xwidth*ip;
7177 double yval = sppatch->Eval(xval);
7178 yval += (a0*exp(
a1*xval));
7183 if (useLowBound) fcnName = Form(
"lowFcn_%s", sp->GetName());
7184 else fcnName = Form(
"highFcn_%s", sp->GetName());
7185 TGraph* fcn =
new TGraph(n+1, xy[0], xy[1]);
7186 fcn->SetName(fcnName);
7188 for (
unsigned int i=0; i<2; i++)
delete[] xy[i];
7193 void regularizeSlice(TGraphErrors* tgSlice, std::vector<double>* fixedX=0,
double omitbelow=0.,
int nIter_=-1,
double threshold_ = -1){
7194 unsigned int nbins_slice = tgSlice->GetN();
7195 double* xexyey_slice[4]={
7202 double* xexyey_linear[4];
7203 for (
unsigned int ix=0; ix<4; ix++){
7204 xexyey_linear[ix] =
new double[nbins_slice];
7205 for (
unsigned int iy=0; iy<nbins_slice; iy++){
7206 if (ix<2) xexyey_linear[ix][iy] = xexyey_slice[ix][iy];
7207 else if (ix==3) xexyey_linear[ix][iy] = exp(xexyey_slice[ix][iy]);
7208 else xexyey_linear[ix][iy] = xexyey_slice[ix][iy]*xexyey_linear[ix-1][iy];
7211 TGraphErrors* tgSlice_linear =
new TGraphErrors(nbins_slice, xexyey_linear[0], xexyey_linear[2], xexyey_linear[1], xexyey_linear[3]);
7212 double integral_in=tgSlice_linear->Integral();
7213 delete tgSlice_linear;
7214 for (
unsigned int ix=0; ix<4; ix++)
delete[] xexyey_linear[ix];
7217 double* xexyey_mod[4];
7218 for (
unsigned int ix=0; ix<4; ix++){
7219 xexyey_mod[ix] =
new double[nbins_slice];
7220 for (
unsigned int iy=0; iy<nbins_slice; iy++) xexyey_mod[ix][iy] = xexyey_slice[ix][iy];
7222 unsigned int bin_first = 2, bin_last = nbins_slice-1;
7224 std::vector<int> fixedBins;
7226 for (
unsigned int ifx=0; ifx<fixedX->size(); ifx++){
7227 double requestedVal = fixedX->at(ifx);
7228 double distance=1e15;
7230 for (
unsigned int bin=0; bin<nbins_slice; bin++){
if (distance>fabs(xexyey_mod[0][bin]-requestedVal)){ bin_to_fix = bin; distance = fabs(xexyey_mod[0][bin]-requestedVal); } }
7231 if (bin_to_fix>=0) fixedBins.push_back(bin_to_fix);
7232 cout <<
"Requested to fix bin " << bin_to_fix << endl;
7236 for (
unsigned int bin=0; bin<nbins_slice; bin++){
7237 if (xexyey_mod[0][bin]<omitbelow) fixedBins.push_back(bin);
7238 cout <<
"Requested to fix bin " << bin << endl;
7245 int nIter = (nIter_<0 ? 1000 : nIter_);
7246 for (
int it=0; it<nIter; it++){
7247 double threshold = (threshold_<0. ? 0.01 : threshold_);
7248 for (
unsigned int binIt = bin_first; binIt<=bin_last; binIt++){
7250 for (
unsigned int ifx=0; ifx<fixedBins.size(); ifx++){
7251 if ((
int)(binIt-1)==fixedBins.at(ifx)){ doFix=
true;
break; }
7253 if (doFix)
continue;
7256 int nbins_second = nbins_slice-1;
7257 xx_second =
new double[nbins_second];
7258 yy_second =
new double[nbins_second];
7259 for (
unsigned int bin = 1; bin<=nbins_slice; bin++){
7260 if (bin==binIt)
continue;
7261 xx_second[ctr] = xexyey_mod[0][bin-1];
7262 yy_second[ctr] = xexyey_mod[2][bin-1];
7266 TGraph* interpolator =
new TGraph(nbins_second, xx_second, yy_second);
7267 double derivative_first = (yy_second[1]-yy_second[0])/(xx_second[1]-xx_second[0]);
7268 double derivative_last = (yy_second[nbins_second-1]-yy_second[nbins_second-2])/(xx_second[nbins_second-1]-xx_second[nbins_second-2]);
7269 TSpline3* spline =
new TSpline3(
"spline", interpolator,
"b1e1", derivative_first, derivative_last);
7271 double center = xexyey_mod[0][binIt-1];
7272 double val = spline->Eval(center);
7273 if (fabs(xexyey_mod[2][binIt-1]-val)>threshold*val) xexyey_mod[2][binIt-1]=val;
7276 delete interpolator;
7283 for (
unsigned int ix=0; ix<4; ix++){
7284 xexyey_linear[ix] =
new double[nbins_slice];
7285 for (
unsigned int iy=0; iy<nbins_slice; iy++){
7286 if (ix<2) xexyey_linear[ix][iy] = xexyey_mod[ix][iy];
7287 else if (ix==3) xexyey_linear[ix][iy] = exp(xexyey_mod[ix][iy]);
7288 else xexyey_linear[ix][iy] = xexyey_mod[ix][iy]*xexyey_linear[ix-1][iy];
7291 tgSlice_linear =
new TGraphErrors(nbins_slice, xexyey_linear[0], xexyey_linear[2], xexyey_linear[1], xexyey_linear[3]);
7292 double integral_out=tgSlice_linear->Integral();
7293 delete tgSlice_linear;
7294 for (
unsigned int ix=0; ix<4; ix++)
delete[] xexyey_linear[ix];
7296 double scale = integral_out / integral_in;
7297 for (
unsigned int iy=0; iy<nbins_slice; iy++){
7298 xexyey_slice[2][iy] = xexyey_mod[2][iy]*
scale;
7299 xexyey_slice[3][iy] *= xexyey_mod[2][iy]/xexyey_slice[2][iy];
7302 for (
unsigned int ix=0; ix<4; ix++)
delete[] xexyey_mod[ix];
7306 const unsigned int nbins_slice = tgSlice->GetN();
7307 double* xexyey_slice[4]={
7314 double xexyey[4][nbins_slice];
7316 for (
unsigned int iy=0; iy<nbins_slice; iy++){
7317 if (xexyey_slice[0][iy]<=xmax && xexyey_slice[0][iy]>=
xmin){
7318 cout <<
"Point to remove with X: " << xexyey_slice[0][iy] << endl;
7321 for (
unsigned int ix=0; ix<4; ix++) xexyey[ix][ctr] = xexyey_slice[ix][iy];
7322 cout <<
"Point " << ctr <<
" X: " << xexyey[0][ctr] << endl;
7325 cout <<
"removePointsBetween: " <<
"Starting number of points " << nbins_slice <<
" final number " << ctr << endl;
7326 TGraphErrors* tgSlice_new =
new TGraphErrors(ctr, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
7327 tgSlice_new->SetName(tgSlice->GetName());
7328 tgSlice_new->SetTitle(tgSlice->GetTitle());
7333 const unsigned int nbins_slice = tgSlice->GetN();
7334 double* xexyey_slice[4]={
7341 double xexyey[4][nbins_slice];
7342 unsigned int lowbin=0, highbin=0;
7343 for (
unsigned int iy=0; iy<nbins_slice; iy++){
7344 if (xexyey_slice[0][iy]<
xmin) lowbin=iy;
7345 if (xexyey_slice[0][iy]>xmax){ highbin=iy;
break; }
7347 cout <<
"Low bin " << lowbin <<
" at " << xexyey_slice[0][lowbin] << endl;
7348 cout <<
"High bin " << highbin <<
" at " << xexyey_slice[0][highbin] << endl;
7350 for (
unsigned int iy=0; iy<nbins_slice; iy++){
7351 if (xexyey_slice[0][iy]<=xmax && xexyey_slice[0][iy]>=
xmin){
7352 for (
unsigned int ix=0; ix<4; ix++){
7353 double xlow = xexyey_slice[0][lowbin];
7354 double xhigh = xexyey_slice[0][highbin];
7355 double ylow = xexyey_slice[ix][lowbin];
7356 double yhigh = xexyey_slice[ix][highbin];
7358 if (ix==0) val = xexyey_slice[0][iy];
7359 else if (ix==2) val = ylow + (yhigh-ylow)/(xhigh-xlow)*(xexyey_slice[0][iy]-xlow);
7360 else val = xexyey_slice[ix][iy]*(xexyey[ix-1][iy]/xexyey_slice[ix-1][iy]);
7361 xexyey[ix][iy] = val;
7365 for (
unsigned int ix=0; ix<4; ix++) xexyey[ix][iy] = xexyey_slice[ix][iy];
7367 cout <<
"Point " << iy <<
" X: " << xexyey[0][iy] << endl;
7369 TGraphErrors* tgSlice_new =
new TGraphErrors(nbins_slice, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
7370 tgSlice_new->SetName(tgSlice->GetName());
7371 tgSlice_new->SetTitle(tgSlice->GetTitle());
7375 void addPoint(TGraphErrors*& tg,
double x,
double y,
double ex,
double ey){
7376 TString strname = tg->GetName();
7377 TString strtitle = tg->GetTitle();
7378 TString strxtitle = tg->GetXaxis()->GetTitle();
7379 TString strytitle = tg->GetYaxis()->GetTitle();
7381 vector<double> xarray;
7382 vector<double> yarray;
7383 vector<double> exarray;
7384 vector<double> eyarray;
7385 xarray.push_back(x);
7386 yarray.push_back(y);
7387 exarray.push_back(ex);
7388 eyarray.push_back(ey);
7389 for (
int ip=0; ip<tg->GetN(); ip++){
7390 if (tg->GetX()[ip]!=x){
7391 xarray.push_back(tg->GetX()[ip]);
7392 yarray.push_back(tg->GetY()[ip]);
7393 exarray.push_back(tg->GetEX()[ip]);
7394 eyarray.push_back(tg->GetEY()[ip]);
7397 vector<pair<double, int>> xorder;
7398 for (
unsigned int ip=0; ip<xarray.size(); ip++) addByLowest<double, int>(xorder, xarray.at(ip), ip);
7401 for (
unsigned int i=0; i<4; i++) xynew[i] =
new double[xorder.size()];
7402 for (
unsigned int ip=0; ip<xarray.size(); ip++){
7403 unsigned int pos = xorder[ip].second;
7404 xynew[0][ip] = xarray[pos];
7405 xynew[1][ip] = yarray[pos];
7406 xynew[2][ip] = exarray[pos];
7407 xynew[3][ip] = eyarray[pos];
7412 tg =
new TGraphErrors(xorder.size(), xynew[0], xynew[1], xynew[2], xynew[3]);
7413 tg->SetName(strname);
7414 tg->SetTitle(strtitle);
7415 tg->GetXaxis()->SetTitle(strxtitle);
7416 tg->GetYaxis()->SetTitle(strytitle);
7417 for (
unsigned int i=0; i<4; i++)
delete[] xynew[i];
7420 TGraphErrors*
addPoint(TGraphErrors* tgSlice,
double x){
7421 const unsigned int nbins_slice = tgSlice->GetN();
7422 double* xexyey_slice[4]={
7429 double xexyey[4][nbins_slice+1];
7430 unsigned int lowbin=0, highbin=0;
7431 for (
unsigned int iy=0; iy<nbins_slice; iy++){
7432 if (xexyey_slice[0][iy]<x) lowbin=iy;
7433 if (xexyey_slice[0][iy]>x){ highbin=iy;
break; }
7435 cout <<
"Low bin " << lowbin <<
" at " << xexyey_slice[0][lowbin] << endl;
7436 cout <<
"High bin " << highbin <<
" at " << xexyey_slice[0][highbin] << endl;
7439 for (
unsigned int iy=0; iy<nbins_slice; iy++){
7440 for (
unsigned int ix=0; ix<4; ix++) xexyey[ix][ctr] = xexyey_slice[ix][iy];
7443 for (
unsigned int ix=0; ix<4; ix++){
7444 double ylow = xexyey_slice[ix][lowbin];
7445 double yhigh = xexyey_slice[ix][highbin];
7446 double val = (yhigh+ylow)*0.5;
7447 xexyey[ix][ctr] = val;
7452 TGraphErrors* tgSlice_new =
new TGraphErrors(ctr, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
7453 tgSlice_new->SetName(tgSlice->GetName());
7454 tgSlice_new->SetTitle(tgSlice->GetTitle());
7459 const unsigned int nbins_slice = tgSlice->GetN();
7460 double* xexyey_slice[4]={
7467 double xexyey[4][nbins_slice+1];
7468 unsigned int lowbin=abin, highbin=abin+1;
7469 cout <<
"Low bin " << lowbin <<
" at " << xexyey_slice[0][lowbin] << endl;
7470 cout <<
"High bin " << highbin <<
" at " << xexyey_slice[0][highbin] << endl;
7473 for (
unsigned int iy=0; iy<nbins_slice; iy++){
7474 for (
unsigned int ix=0; ix<4; ix++) xexyey[ix][ctr] = xexyey_slice[ix][iy];
7477 for (
unsigned int ix=0; ix<4; ix++){
7478 double ylow = xexyey_slice[ix][lowbin];
7479 double yhigh = xexyey_slice[ix][highbin];
7480 double val = (yhigh+ylow)*0.5;
7481 xexyey[ix][ctr] = val;
7484 cout <<
"Adding additional point at " << xexyey[0][ctr-1] <<
'\t' << xexyey[2][ctr-1] << endl;
7487 TGraphErrors* tgSlice_new =
new TGraphErrors(ctr, xexyey[0], xexyey[2], xexyey[1], xexyey[3]);
7488 tgSlice_new->SetName(tgSlice->GetName());
7489 tgSlice_new->SetTitle(tgSlice->GetTitle());
7501 TGraphErrors*& tg, TTree*& tree, TProfile*& pmass,
7503 float& ZZMass,
float& mesq,
float& weight
7505 cout <<
"Old set of boundaries: " << endl;
7506 for (
int ibin=1; ibin<=pmass->GetNbinsX()+1; ibin++)
cout << pmass->GetXaxis()->GetBinLowEdge(ibin) <<
" ";
7509 int binlow=pmass->GetXaxis()->FindBin(rediv.
xlow);
7510 int binhigh=pmass->GetXaxis()->FindBin(rediv.
xhigh);
7511 float redivlow, redivhigh;
7512 if (binlow==0) binlow=1; redivlow=pmass->GetXaxis()->GetBinLowEdge(binlow);
7513 if (binhigh==0) binhigh=1; redivhigh=pmass->GetXaxis()->GetBinUpEdge(binhigh);
7514 cout <<
"Rebinning between " << redivlow <<
" and " << redivhigh << endl;
7516 vector<float> massvals;
7517 for (
int ev=0;
ev<tree->GetEntries();
ev++){
7519 if (ZZMass<redivlow || ZZMass>=redivhigh)
continue;
7520 massvals.push_back(ZZMass);
7522 std::sort(massvals.begin(), massvals.end());
7523 cout << massvals.size() <<
" events in this range" << endl;
7524 vector<float> xboundaries;
7525 unsigned int nevts_collected=massvals.size();
7528 for (
unsigned int ip=1; ip<rediv.
npoints; ip++)
addByLowest(xboundaries,
float((massvals.at(nevts_collected/rediv.
npoints*ip) + massvals.at(nevts_collected/rediv.
npoints*ip+1))*0.5),
true);
7529 cout <<
"Additional x boundaries: ";
7530 for (
unsigned int ip=0; ip<xboundaries.size(); ip++)
cout << xboundaries.at(ip) <<
" ";
7533 TProfile* hvar =
new TProfile(
"mass",
"", rediv.
npoints, xboundaries.data()); hvar->Sumw2();
7534 TProfile* hmesq =
new TProfile(
"mesq",
"", rediv.
npoints, xboundaries.data()); hmesq->Sumw2();
7535 for (
int ev=0;
ev<tree->GetEntries();
ev++){
7537 if (ZZMass<redivlow || ZZMass>=redivhigh)
continue;
7538 hvar->Fill(ZZMass, ZZMass, weight);
7539 hmesq->Fill(ZZMass, mesq, weight);
7542 { TGraphErrors* tgnew =
removePointsBetween(tg, redivlow, redivhigh);
delete tg; tg=tgnew; }
7543 for (
int ibin=1; ibin<=hvar->GetNbinsX(); ibin++){
7544 double xadd=hvar->GetBinContent(ibin);
7545 double exadd=hvar->GetBinError(ibin);
7546 double yadd=hmesq->GetBinContent(ibin);
7547 double eyadd=hmesq->GetBinError(ibin);
7548 eyadd=log10(eyadd)/yadd;
7550 addPoint(tg, xadd, yadd, exadd, eyadd);
7551 cout <<
"Added point " << xadd <<
", " << yadd <<
" for range [ " << hvar->GetXaxis()->GetBinLowEdge(ibin) <<
", " << hvar->GetXaxis()->GetBinUpEdge(ibin) <<
" ]" << endl;
7556 TString pmassname=pmass->GetName();
7557 TString pmasstitle=pmass->GetTitle();
7558 TString pmassxtitle=pmass->GetXaxis()->GetTitle();
7559 TString pmassytitle=pmass->GetYaxis()->GetTitle();
7560 vector<float> pmassboundaries;
7561 for (
int ibin=1; ibin<=pmass->GetNbinsX()+1; ibin++){
7562 if (ibin>=binlow && ibin<=binhigh+1)
continue;
7563 addByLowest(pmassboundaries,
float(pmass->GetXaxis()->GetBinLowEdge(ibin)),
true);
7565 for (
float& bb:xboundaries)
addByLowest(pmassboundaries, bb,
true);
7566 assert((
int) pmassboundaries.size()==tg->GetN()+1);
7568 pmass =
new TProfile(pmassname, pmasstitle, pmassboundaries.size()-1, pmassboundaries.data());
7569 for (
int ibin=1; ibin<=tg->GetN(); ibin++){
7570 pmass->SetBinContent(ibin, tg->GetX()[ibin-1]);
7571 pmass->SetBinError(ibin, tg->GetEX()[ibin-1]);
7574 cout <<
"New set of boundaries: " << endl;
7575 for (
int ibin=1; ibin<=pmass->GetNbinsX()+1; ibin++)
cout << pmass->GetXaxis()->GetBinLowEdge(ibin) <<
" ";
7583 TF1* (*lowf)(TSpline3*,
double,
double,
bool),
7584 TF1* (*highf)(TSpline3*,
double,
double,
bool),
7586 bool useFaithfulLowSlopes=
false,
7587 bool useFaithfulHighSlopes=
false,
7588 vector<PointRedivision>* redivision=
nullptr
7593 TString strsqrts=
"";
7594 if (
sqrts>0) strsqrts = Form(
"_%iTeV",
sqrts);
7596 TString strappend = Form(
"%s_%s_%s%s", strme.Data(), strprod.Data(), strproc.Data(), strsqrts.Data());
7598 TFile* finput = TFile::Open(Form(
"pAvgLinToLog_%s%s", strappend.Data(),
".root"),
"read");
7599 TFile* foutput = TFile::Open(Form(
"pAvgSmooth_%s%s", strappend.Data(),
".root"),
"recreate");
7600 const unsigned int ngraphs=2;
7601 TString strtg[ngraphs]={
7602 "tg_P_ConserveDifermionMass",
7603 "tg_P_MomentumToEnergy"
7605 const double xmin=0;
7606 const double xmax=(
sqrts>0 ? (double)
sqrts*1000. : 15000.);
7608 for (
unsigned int ig=0; ig<ngraphs; ig++){
7610 TGraphErrors* tgin = 0;
7611 tgin = (TGraphErrors*) finput->Get(strtg[ig]);
7612 if (tgin==0){ cerr << strtg[ig] <<
" does not exist." << endl;
continue; }
7613 TGraphErrors* tg =
new TGraphErrors(*tgin);
7615 TTree* tree = (TTree*) finput->Get(
"FinalTree");
7616 if (!tree) cerr <<
"Final tree does not exist, so cannot apply redivision" << endl;
7618 float ZZMass, weight, mesq;
7619 tree->SetBranchAddress(
"ZZMass", &ZZMass);
7620 tree->SetBranchAddress(
"weight", &weight);
7621 if (ig==0) tree->SetBranchAddress(
"mesq_conserveDifermMass", &mesq);
7622 else tree->SetBranchAddress(
"mesq_jetPtoEScale", &mesq);
7623 TProfile* pmass = (TProfile*) finput->Get(
"candMass");
7628 ZZMass, mesq, weight
7634 foutput->WriteTObject(tg);
7637 double* xx = tg->GetX();
7638 double* ex = tg->GetEX();
7639 double* yy = tg->GetY();
7640 double* ey = tg->GetEY();
7643 double tglow = xx[0];
7644 double tghigh = xx[tg->GetN()-1];
7645 TF1* lowFcn = lowf(sp,
xmin, tglow,
true);
7646 TF1* highFcn = highf(sp, tghigh, xmax,
false);
7647 lowFcn->SetNpx((
int) (tglow-
xmin)*5);
7648 highFcn->SetNpx((
int) (xmax-tghigh)*5);
7650 vector<pair<double, double>> points;
7651 for (
double xval=
xmin; xval<tglow; xval+=1){
7652 double yval = lowFcn->Eval(xval);
7653 addByLowest<double, double>(points, xval, yval);
7655 for (
int ix=0; ix<n; ix++){
7656 addByLowest<double, double>(points, xx[ix], yy[ix]);
7658 int tghigh_int = ((
int) ((tghigh+1.)/100.+0.5))*100;
7659 if (tghigh>=(
double) tghigh_int) tghigh_int+=100;
7660 for (
double xval=tghigh_int; xval<=xmax; xval+=100){
7661 double yval = highFcn->Eval(xval);
7662 addByLowest<double, double>(points, xval, yval);
7665 int nn_new = points.size();
7666 cout <<
"Number of new points: " << nn_new-n << endl;
7668 for (
unsigned int i=0; i<2; i++) xy_new[i] =
new double[nn_new];
7669 for (
int ix=0; ix<nn_new; ix++){
7670 xy_new[0][ix] = points.at(ix).first;
7671 xy_new[1][ix] = points.at(ix).second;
7678 TGraph* tg_updated =
new TGraph(nn_new, xy_new[0], xy_new[1]);
7679 tg_updated->SetName(Form(
"%s_Smooth", tg->GetName()));
7680 foutput->WriteTObject(tg_updated);
7683 foutput->WriteTObject(sp);
7685 TCanvas* ctest =
new TCanvas(Form(
"test_%s", strtg[ig].Data()),
"", 8, 30, 800, 800);
7687 tg->GetXaxis()->SetRangeUser(
xmin, xmax);
7690 ctest->RedrawAxis();
7693 foutput->WriteTObject(ctest);
7694 ctest->SaveAs(Form(
"%s%s", ctest->GetName(),
".pdf"));
7699 for (
unsigned int i=0; i<2; i++)
delete[] xy_new[i];
7709 TF1* (*lowf)(TSpline3*,
double,
double,
bool),
7710 TF1* (*highf)(TSpline3*,
double,
double,
bool),
7712 bool useFaithfulLowSlopes=
false,
7713 bool useFaithfulHighSlopes=
false,
7714 vector<PointRedivision>* redivision=
nullptr
7719 TString strsqrts=
"";
7720 if (
sqrts>0) strsqrts = Form(
"_%iTeV",
sqrts);
7722 TString strappend = Form(
"%s_%s_%s%s", strme.Data(), strprod.Data(), strproc.Data(), strsqrts.Data());
7724 TFile* finput = TFile::Open(Form(
"pAvgLinToLog_%s%s", strappend.Data(),
".root"),
"read");
7725 TFile* foutput = TFile::Open(Form(
"pAvgSmooth_%s%s", strappend.Data(),
".root"),
"recreate");
7726 const unsigned int ngraphs=3;
7727 TString strtg[ngraphs]={
7728 "tg_P_ConserveDifermionMass_4mu",
7729 "tg_P_ConserveDifermionMass_4e",
7730 "tg_P_ConserveDifermionMass_2mu2e"
7732 const double xmin=0;
7733 const double xmax=(
sqrts>0 ? (double)
sqrts*1000. : 15000.);
7735 for (
unsigned int ig=0; ig<ngraphs; ig++){
7737 TGraphErrors* tgin = 0;
7738 tgin = (TGraphErrors*) finput->Get(strtg[ig]);
7739 if (tgin==0){ cerr << strtg[ig] <<
" does not exist." << endl;
continue; }
7740 TGraphErrors* tg =
new TGraphErrors(*tgin);
7743 if (ig==0) tree = (TTree*) finput->Get(
"FinalTree_4mu");
7744 else if (ig==1) tree = (TTree*) finput->Get(
"FinalTree_4e");
7745 else tree = (TTree*) finput->Get(
"FinalTree_2mu2e");
7746 if (!tree) cerr <<
"Final tree does not exist, so cannot apply redivision" << endl;
7748 float ZZMass, weight, mesq;
7749 tree->SetBranchAddress(
"ZZMass", &ZZMass);
7750 tree->SetBranchAddress(
"weight", &weight);
7751 tree->SetBranchAddress(
"mesq_conserveDifermMass", &mesq);
7753 if (ig==0) pmass = (TProfile*) finput->Get(
"candMass_4mu");
7754 else if (ig==1) pmass = (TProfile*) finput->Get(
"candMass_4e");
7755 else pmass = (TProfile*) finput->Get(
"candMass_2mu2e");
7760 ZZMass, mesq, weight
7767 foutput->WriteTObject(tg);
7770 double* xx = tg->GetX();
7771 double* ex = tg->GetEX();
7772 double* yy = tg->GetY();
7773 double* ey = tg->GetEY();
7776 double tglow = xx[0];
7777 double tghigh = xx[tg->GetN()-1];
7778 TF1* lowFcn = lowf(sp,
xmin, tglow,
true);
7779 TF1* highFcn = highf(sp, tghigh, xmax,
false);
7780 lowFcn->SetNpx((
int)(tglow-
xmin)*5);
7781 highFcn->SetNpx((
int)(xmax-tghigh)*5);
7783 vector<pair<double, double>> points;
7784 for (
double xval=
xmin; xval<tglow; xval+=1){
7785 double yval = lowFcn->Eval(xval);
7786 addByLowest<double, double>(points, xval, yval);
7788 for (
int ix=0; ix<n; ix++){
7789 addByLowest<double, double>(points, xx[ix], yy[ix]);
7791 int tghigh_int = ((
int)((tghigh+1.)/100.+0.5))*100;
7792 if (tghigh>=(
double)tghigh_int) tghigh_int+=100;
7793 for (
double xval=tghigh_int; xval<=xmax; xval+=100){
7794 double yval = highFcn->Eval(xval);
7795 addByLowest<double, double>(points, xval, yval);
7798 int nn_new = points.size();
7799 cout <<
"Number of new points: " << nn_new-n << endl;
7801 for (
unsigned int i=0; i<2; i++) xy_new[i] =
new double[nn_new];
7802 for (
int ix=0; ix<nn_new; ix++){
7803 xy_new[0][ix] = points.at(ix).first;
7804 xy_new[1][ix] = points.at(ix).second;
7811 TGraph* tg_updated =
new TGraph(nn_new, xy_new[0], xy_new[1]);
7812 tg_updated->SetName(Form(
"%s_Smooth", tg->GetName()));
7813 foutput->WriteTObject(tg_updated);
7816 foutput->WriteTObject(sp);
7818 TCanvas* ctest =
new TCanvas(Form(
"test_%s", strtg[ig].Data()),
"", 8, 30, 800, 800);
7820 tg->GetXaxis()->SetRangeUser(
xmin, xmax);
7823 ctest->RedrawAxis();
7826 foutput->WriteTObject(ctest);
7827 ctest->SaveAs(Form(
"%s%s", ctest->GetName(),
".pdf"));
7832 for (
unsigned int i=0; i<2; i++)
delete[] xy_new[i];
7842 TString strpatchpath, TString strpatchname,
7843 TGraph* (*lowpatcher)(TSpline3*, TSpline3*,
double,
double,
bool,
bool),
7844 TGraph* (*highpatcher)(TSpline3*, TSpline3*,
double,
double,
bool,
bool),
7846 vector<PointRedivision>* redivision=
nullptr
7851 TString strsqrts=
"";
7852 if (
sqrts>0) strsqrts = Form(
"_%iTeV",
sqrts);
7854 TString strappend = Form(
"%s_%s_%s%s", strme.Data(), strprod.Data(), strproc.Data(), strsqrts.Data());
7856 TFile* finput = TFile::Open(Form(
"pAvgLinToLog_%s%s", strappend.Data(),
".root"),
"read");
7857 TFile* finput_patch = TFile::Open(strpatchpath,
"read");
7858 TFile* foutput = TFile::Open(Form(
"pAvgSmooth_%s%s", strappend.Data(),
".root"),
"recreate");
7859 const unsigned int ngraphs=3;
7860 TString strtg[ngraphs]={
7861 "tg_P_ConserveDifermionMass_4mu",
7862 "tg_P_ConserveDifermionMass_4e",
7863 "tg_P_ConserveDifermionMass_2mu2e"
7866 TGraph* tgpatch = (TGraph*)finput_patch->Get(strpatchname);
7869 const double xmin=max(0., (tgpatch->GetX())[0]);
7870 const double xmax=min((
sqrts>0 ? (
double)
sqrts*1000. : 15000.), (tgpatch->GetX())[tgpatch->GetN()-1]);
7872 for (
unsigned int ig=0; ig<ngraphs; ig++){
7874 TGraphErrors* tgin = 0;
7875 tgin = (TGraphErrors*) finput->Get(strtg[ig]);
7876 if (tgin==0){ cerr << strtg[ig] <<
" does not exist." << endl;
continue; }
7877 TGraphErrors* tg =
new TGraphErrors(*tgin);
7880 if (ig==0) tree = (TTree*) finput->Get(
"FinalTree_4mu");
7881 else if (ig==1) tree = (TTree*) finput->Get(
"FinalTree_4e");
7882 else tree = (TTree*) finput->Get(
"FinalTree_2mu2e");
7883 if (!tree) cerr <<
"Final tree does not exist, so cannot apply redivision" << endl;
7885 float ZZMass, weight, mesq;
7886 tree->SetBranchAddress(
"ZZMass", &ZZMass);
7887 tree->SetBranchAddress(
"weight", &weight);
7888 tree->SetBranchAddress(
"mesq_conserveDifermMass", &mesq);
7890 if (ig==0) pmass = (TProfile*) finput->Get(
"candMass_4mu");
7891 else if (ig==1) pmass = (TProfile*) finput->Get(
"candMass_4e");
7892 else pmass = (TProfile*) finput->Get(
"candMass_2mu2e");
7897 ZZMass, mesq, weight
7904 foutput->WriteTObject(tg);
7907 double* xx = tg->GetX();
7908 double* ex = tg->GetEX();
7909 double* yy = tg->GetY();
7910 double* ey = tg->GetEY();
7913 sp->SetName(Form(
"%s_initial", sp->GetName()));
7914 foutput->WriteTObject(sp);
7915 double tglow = xx[0];
7916 double tghigh = xx[tg->GetN()-1];
7917 cout <<
"Extracting low patch..." << endl;
7918 TGraph* lowGraph = lowpatcher(sp, sppatch,
xmin, tglow,
true,
true);
7919 cout <<
"Extracting high patch..." << endl;
7920 TGraph* highGraph = highpatcher(sp, sppatch, tghigh, xmax,
false,
true);
7921 cout <<
"Converting patches to splines..." << endl;
7925 vector<pair<double, double>> points;
7926 for (
double xval=
xmin; xval<tglow; xval+=1){
7927 double yval = lowFcn->Eval(xval);
7928 addByLowest<double, double>(points, xval, yval);
7930 for (
int ix=0; ix<n; ix++){
7931 addByLowest<double, double>(points, xx[ix], yy[ix]);
7933 int tghigh_int = ((
int)((tghigh+1.)/100.+0.5))*100;
7934 if (tghigh>=(
double)tghigh_int) tghigh_int+=100;
7935 for (
double xval=tghigh_int; xval<=xmax; xval+=100){
7936 double yval = highFcn->Eval(xval);
7937 addByLowest<double, double>(points, xval, yval);
7940 int nn_new = points.size();
7941 cout <<
"Number of new points: " << nn_new-n << endl;
7943 for (
unsigned int i=0; i<2; i++) xy_new[i] =
new double[nn_new];
7944 for (
int ix=0; ix<nn_new; ix++){
7945 xy_new[0][ix] = points.at(ix).first;
7946 xy_new[1][ix] = points.at(ix).second;
7955 TGraph* tg_updated =
new TGraph(nn_new, xy_new[0], xy_new[1]);
7956 tg_updated->SetName(Form(
"%s_Smooth", tg->GetName()));
7957 foutput->WriteTObject(tg_updated);
7960 foutput->WriteTObject(sp);
7962 TCanvas* ctest =
new TCanvas(Form(
"test_%s", strtg[ig].Data()),
"", 8, 30, 800, 800);
7964 tg->GetXaxis()->SetRangeUser(
xmin, xmax);
7967 ctest->RedrawAxis();
7970 foutput->WriteTObject(ctest);
7971 ctest->SaveAs(Form(
"%s%s", ctest->GetName(),
".pdf"));
7976 for (
unsigned int i=0; i<2; i++)
delete[] xy_new[i];
7982 finput_patch->Close();
7988 TString strpatchpath, TString strpatchname,
7989 TString strpatchpath2, TString strpatchname2,
7990 TGraph* (*lowpatcher)(TSpline3*, TSpline3*,
double,
double,
bool,
bool),
7991 TGraph* (*highpatcher)(TSpline3*, TSpline3*,
double,
double,
bool,
bool),
7993 vector<PointRedivision>* redivision=
nullptr
7998 TString strsqrts=
"";
7999 if (
sqrts>0) strsqrts = Form(
"_%iTeV",
sqrts);
8001 TString strappend = Form(
"%s_%s_%s%s", strme.Data(), strprod.Data(), strproc.Data(), strsqrts.Data());
8003 TFile* finput = TFile::Open(Form(
"pAvgLinToLog_%s%s", strappend.Data(),
".root"),
"read");
8004 TFile* finput_patch = TFile::Open(strpatchpath,
"read");
8005 TFile* finput_patch2 = TFile::Open(strpatchpath2,
"read");
8006 TFile* foutput = TFile::Open(Form(
"pAvgSmooth_%s%s", strappend.Data(),
".root"),
"recreate");
8007 const unsigned int ngraphs=3;
8008 TString strtg[ngraphs]={
8009 "tg_P_ConserveDifermionMass_4mu",
8010 "tg_P_ConserveDifermionMass_4e",
8011 "tg_P_ConserveDifermionMass_2mu2e"
8014 TGraph* tgpatch = (TGraph*)finput_patch->Get(strpatchname);
8017 TGraph* tgpatch2 = (TGraph*)finput_patch2->Get(strpatchname2);
8020 const double xmin=max(0., (tgpatch->GetX())[0]);
8021 const double xmax=min((
sqrts>0 ? (
double)
sqrts*1000. : 15000.), (tgpatch->GetX())[tgpatch->GetN()-1]);
8023 for (
unsigned int ig=0; ig<ngraphs; ig++){
8025 TGraphErrors* tgin = 0;
8026 tgin = (TGraphErrors*) finput->Get(strtg[ig]);
8027 if (tgin==0){ cerr << strtg[ig] <<
" does not exist." << endl;
continue; }
8028 TGraphErrors* tg =
new TGraphErrors(*tgin);
8031 if (ig==0) tree = (TTree*) finput->Get(
"FinalTree_4mu");
8032 else if (ig==1) tree = (TTree*) finput->Get(
"FinalTree_4e");
8033 else tree = (TTree*) finput->Get(
"FinalTree_2mu2e");
8034 if (!tree) cerr <<
"Final tree does not exist, so cannot apply redivision" << endl;
8036 float ZZMass, weight, mesq;
8037 tree->SetBranchAddress(
"ZZMass", &ZZMass);
8038 tree->SetBranchAddress(
"weight", &weight);
8039 tree->SetBranchAddress(
"mesq_conserveDifermMass", &mesq);
8041 if (ig==0) pmass = (TProfile*) finput->Get(
"candMass_4mu");
8042 else if (ig==1) pmass = (TProfile*) finput->Get(
"candMass_4e");
8043 else pmass = (TProfile*) finput->Get(
"candMass_2mu2e");
8048 ZZMass, mesq, weight
8055 foutput->WriteTObject(tg);
8058 double* xx = tg->GetX();
8059 double* ex = tg->GetEX();
8060 double* yy = tg->GetY();
8061 double* ey = tg->GetEY();
8064 sp->SetName(Form(
"%s_initial", sp->GetName()));
8065 foutput->WriteTObject(sp);
8066 double tglow = xx[0];
8067 double tghigh = xx[tg->GetN()-1];
8068 cout <<
"Extracting low patch..." << endl;
8069 TGraph* lowGraph = lowpatcher(sp, sppatch,
xmin, tglow,
true,
false);
8070 if (lowGraph==0) lowGraph = lowpatcher(sp, sppatch2,
xmin, tglow,
true,
true);
8071 cout <<
"Extracting high patch..." << endl;
8072 TGraph* highGraph = highpatcher(sp, sppatch, tghigh, xmax,
false,
false);
8073 if (highGraph==0) highGraph = highpatcher(sp, sppatch2, tghigh, xmax,
false,
true);
8074 cout <<
"Converting patches to splines..." << endl;
8078 vector<pair<double, double>> points;
8079 for (
double xval=
xmin; xval<tglow; xval+=1){
8080 double yval = lowFcn->Eval(xval);
8081 addByLowest<double, double>(points, xval, yval);
8083 for (
int ix=0; ix<n; ix++){
8084 addByLowest<double, double>(points, xx[ix], yy[ix]);
8086 int tghigh_int = ((
int)((tghigh+1.)/100.+0.5))*100;
8087 if (tghigh>=(
double)tghigh_int) tghigh_int+=100;
8088 for (
double xval=tghigh_int; xval<=xmax; xval+=100){
8089 double yval = highFcn->Eval(xval);
8090 addByLowest<double, double>(points, xval, yval);
8093 int nn_new = points.size();
8094 cout <<
"Number of new points: " << nn_new-n << endl;
8096 for (
unsigned int i=0; i<2; i++) xy_new[i] =
new double[nn_new];
8097 for (
int ix=0; ix<nn_new; ix++){
8098 xy_new[0][ix] = points.at(ix).first;
8099 xy_new[1][ix] = points.at(ix).second;
8108 TGraph* tg_updated =
new TGraph(nn_new, xy_new[0], xy_new[1]);
8109 tg_updated->SetName(Form(
"%s_Smooth", tg->GetName()));
8110 foutput->WriteTObject(tg_updated);
8113 foutput->WriteTObject(sp);
8115 TCanvas* ctest =
new TCanvas(Form(
"test_%s", strtg[ig].Data()),
"", 8, 30, 800, 800);
8117 tg->GetXaxis()->SetRangeUser(
xmin, xmax);
8120 ctest->RedrawAxis();
8123 foutput->WriteTObject(ctest);
8124 ctest->SaveAs(Form(
"%s%s", ctest->GetName(),
".pdf"));
8129 for (
unsigned int i=0; i<2; i++)
delete[] xy_new[i];
8136 finput_patch2->Close();
8137 finput_patch->Close();
8144 TString strpatchpath, TString strpatchname,
8145 TF1* (*lowf)(TSpline3*,
double,
double,
bool),
8146 TGraph* (*highpatcher)(TSpline3*, TSpline3*,
double,
double,
bool,
bool),
8148 vector<PointRedivision>* redivision=
nullptr
8153 TString strsqrts=
"";
8154 if (
sqrts>0) strsqrts = Form(
"_%iTeV",
sqrts);
8156 TString strappend = Form(
"%s_%s_%s%s", strme.Data(), strprod.Data(), strproc.Data(), strsqrts.Data());
8158 TFile* finput = TFile::Open(Form(
"pAvgLinToLog_%s%s", strappend.Data(),
".root"),
"read");
8159 TFile* finput_patch = TFile::Open(strpatchpath,
"read");
8160 TFile* foutput = TFile::Open(Form(
"pAvgSmooth_%s%s", strappend.Data(),
".root"),
"recreate");
8161 const unsigned int ngraphs=3;
8162 TString strtg[ngraphs]={
8163 "tg_P_ConserveDifermionMass_4mu",
8164 "tg_P_ConserveDifermionMass_4e",
8165 "tg_P_ConserveDifermionMass_2mu2e"
8168 TGraph* tgpatch = (TGraph*)finput_patch->Get(strpatchname);
8171 const double xmin=max(0., (tgpatch->GetX())[0]);
8172 const double xmax=min((
sqrts>0 ? (
double)
sqrts*1000. : 15000.), (tgpatch->GetX())[tgpatch->GetN()-1]);
8174 for (
unsigned int ig=0; ig<ngraphs; ig++){
8176 TGraphErrors* tgin = 0;
8177 tgin = (TGraphErrors*) finput->Get(strtg[ig]);
8178 if (tgin==0){ cerr << strtg[ig] <<
" does not exist." << endl;
continue; }
8179 TGraphErrors* tg =
new TGraphErrors(*tgin);
8182 if (ig==0) tree = (TTree*) finput->Get(
"FinalTree_4mu");
8183 else if (ig==1) tree = (TTree*) finput->Get(
"FinalTree_4e");
8184 else tree = (TTree*) finput->Get(
"FinalTree_2mu2e");
8185 if (!tree) cerr <<
"Final tree does not exist, so cannot apply redivision" << endl;
8187 float ZZMass, weight, mesq;
8188 tree->SetBranchAddress(
"ZZMass", &ZZMass);
8189 tree->SetBranchAddress(
"weight", &weight);
8190 tree->SetBranchAddress(
"mesq_conserveDifermMass", &mesq);
8192 if (ig==0) pmass = (TProfile*) finput->Get(
"candMass_4mu");
8193 else if (ig==1) pmass = (TProfile*) finput->Get(
"candMass_4e");
8194 else pmass = (TProfile*) finput->Get(
"candMass_2mu2e");
8199 ZZMass, mesq, weight
8206 foutput->WriteTObject(tg);
8209 double* xx = tg->GetX();
8210 double* ex = tg->GetEX();
8211 double* yy = tg->GetY();
8212 double* ey = tg->GetEY();
8215 sp->SetName(Form(
"%s_initial", sp->GetName()));
8216 foutput->WriteTObject(sp);
8217 double tglow = xx[0];
8218 double tghigh = xx[tg->GetN()-1];
8219 cout <<
"Extracting high patch..." << endl;
8220 TGraph* highGraph = highpatcher(sp, sppatch, tghigh, xmax,
false,
true);
8221 cout <<
"Converting patches to splines..." << endl;
8224 TF1* lowFcn = lowf(sp,
xmin, tglow,
true);
8225 lowFcn->SetNpx((
int)(tglow-
xmin)*5);
8227 vector<pair<double, double>> points;
8228 for (
double xval=
xmin; xval<tglow; xval+=1){
8229 double yval = lowFcn->Eval(xval);
8230 addByLowest<double, double>(points, xval, yval);
8232 for (
int ix=0; ix<n; ix++){
8233 addByLowest<double, double>(points, xx[ix], yy[ix]);
8235 int tghigh_int = ((
int)((tghigh+1.)/100.+0.5))*100;
8236 if (tghigh>=(
double)tghigh_int) tghigh_int+=100;
8237 for (
double xval=tghigh_int; xval<=xmax; xval+=100){
8238 double yval = highFcn->Eval(xval);
8239 addByLowest<double, double>(points, xval, yval);
8242 int nn_new = points.size();
8243 cout <<
"Number of new points: " << nn_new-n << endl;
8245 for (
unsigned int i=0; i<2; i++) xy_new[i] =
new double[nn_new];
8246 for (
int ix=0; ix<nn_new; ix++){
8247 xy_new[0][ix] = points.at(ix).first;
8248 xy_new[1][ix] = points.at(ix).second;
8256 TGraph* tg_updated =
new TGraph(nn_new, xy_new[0], xy_new[1]);
8257 tg_updated->SetName(Form(
"%s_Smooth", tg->GetName()));
8258 foutput->WriteTObject(tg_updated);
8261 foutput->WriteTObject(sp);
8263 TCanvas* ctest =
new TCanvas(Form(
"test_%s", strtg[ig].Data()),
"", 8, 30, 800, 800);
8265 tg->GetXaxis()->SetRangeUser(
xmin, xmax);
8268 ctest->RedrawAxis();
8271 foutput->WriteTObject(ctest);
8272 ctest->SaveAs(Form(
"%s%s", ctest->GetName(),
".pdf"));
8277 for (
unsigned int i=0; i<2; i++)
delete[] xy_new[i];
8283 finput_patch->Close();
8289 TString strpatchpath, TString strpatchname,
8290 TGraph* (*lowpatcher)(TSpline3*, TSpline3*,
double,
double,
bool,
bool),
8291 TF1* (*highf)(TSpline3*,
double,
double,
bool),
8293 vector<PointRedivision>* redivision=
nullptr
8298 TString strsqrts=
"";
8299 if (
sqrts>0) strsqrts = Form(
"_%iTeV",
sqrts);
8301 TString strappend = Form(
"%s_%s_%s%s", strme.Data(), strprod.Data(), strproc.Data(), strsqrts.Data());
8303 TFile* finput = TFile::Open(Form(
"pAvgLinToLog_%s%s", strappend.Data(),
".root"),
"read");
8304 TFile* finput_patch = TFile::Open(strpatchpath,
"read");
8305 TFile* foutput = TFile::Open(Form(
"pAvgSmooth_%s%s", strappend.Data(),
".root"),
"recreate");
8306 const unsigned int ngraphs=3;
8307 TString strtg[ngraphs]={
8308 "tg_P_ConserveDifermionMass_4mu",
8309 "tg_P_ConserveDifermionMass_4e",
8310 "tg_P_ConserveDifermionMass_2mu2e"
8313 TGraph* tgpatch = (TGraph*)finput_patch->Get(strpatchname);
8316 const double xmin=max(0., (tgpatch->GetX())[0]);
8317 const double xmax=min((
sqrts>0 ? (
double)
sqrts*1000. : 15000.), (tgpatch->GetX())[tgpatch->GetN()-1]);
8319 for (
unsigned int ig=0; ig<ngraphs; ig++){
8321 TGraphErrors* tgin = 0;
8322 tgin = (TGraphErrors*) finput->Get(strtg[ig]);
8323 if (tgin==0){ cerr << strtg[ig] <<
" does not exist." << endl;
continue; }
8324 TGraphErrors* tg =
new TGraphErrors(*tgin);
8327 if (ig==0) tree = (TTree*) finput->Get(
"FinalTree_4mu");
8328 else if (ig==1) tree = (TTree*) finput->Get(
"FinalTree_4e");
8329 else tree = (TTree*) finput->Get(
"FinalTree_2mu2e");
8330 if (!tree) cerr <<
"Final tree does not exist, so cannot apply redivision" << endl;
8332 float ZZMass, weight, mesq;
8333 tree->SetBranchAddress(
"ZZMass", &ZZMass);
8334 tree->SetBranchAddress(
"weight", &weight);
8335 tree->SetBranchAddress(
"mesq_conserveDifermMass", &mesq);
8337 if (ig==0) pmass = (TProfile*) finput->Get(
"candMass_4mu");
8338 else if (ig==1) pmass = (TProfile*) finput->Get(
"candMass_4e");
8339 else pmass = (TProfile*) finput->Get(
"candMass_2mu2e");
8344 ZZMass, mesq, weight
8351 foutput->WriteTObject(tg);
8354 double* xx = tg->GetX();
8355 double* ex = tg->GetEX();
8356 double* yy = tg->GetY();
8357 double* ey = tg->GetEY();
8360 sp->SetName(Form(
"%s_initial", sp->GetName()));
8361 foutput->WriteTObject(sp);
8362 double tglow = xx[0];
8363 double tghigh = xx[tg->GetN()-1];
8364 cout <<
"Extracting low patch..." << endl;
8365 TGraph* lowGraph = lowpatcher(sp, sppatch, tglow, xmax,
true,
true);
8366 cout <<
"Converting patches to splines..." << endl;
8369 TF1* highFcn = highf(sp, tghigh, xmax,
false);
8370 highFcn->SetNpx((
int)(tglow-
xmin)*5);
8372 vector<pair<double, double>> points;
8373 for (
double xval=
xmin; xval<tglow; xval+=1){
8374 double yval = lowFcn->Eval(xval);
8375 addByLowest<double, double>(points, xval, yval);
8377 for (
int ix=0; ix<n; ix++){
8378 addByLowest<double, double>(points, xx[ix], yy[ix]);
8380 int tghigh_int = ((
int)((tghigh+1.)/100.+0.5))*100;
8381 if (tghigh>=(
double)tghigh_int) tghigh_int+=100;
8382 for (
double xval=tghigh_int; xval<=xmax; xval+=100){
8383 double yval = highFcn->Eval(xval);
8384 addByLowest<double, double>(points, xval, yval);
8387 int nn_new = points.size();
8388 cout <<
"Number of new points: " << nn_new-n << endl;
8390 for (
unsigned int i=0; i<2; i++) xy_new[i] =
new double[nn_new];
8391 for (
int ix=0; ix<nn_new; ix++){
8392 xy_new[0][ix] = points.at(ix).first;
8393 xy_new[1][ix] = points.at(ix).second;
8401 TGraph* tg_updated =
new TGraph(nn_new, xy_new[0], xy_new[1]);
8402 tg_updated->SetName(Form(
"%s_Smooth", tg->GetName()));
8403 foutput->WriteTObject(tg_updated);
8406 foutput->WriteTObject(sp);
8408 TCanvas* ctest =
new TCanvas(Form(
"test_%s", strtg[ig].Data()),
"", 8, 30, 800, 800);
8410 tg->GetXaxis()->SetRangeUser(
xmin, xmax);
8413 ctest->RedrawAxis();
8416 foutput->WriteTObject(ctest);
8417 ctest->SaveAs(Form(
"%s%s", ctest->GetName(),
".pdf"));
8422 for (
unsigned int i=0; i<2; i++)
delete[] xy_new[i];
8428 finput_patch->Close();
8434 TFile* finput =
new TFile(Form(
"pAvgLinToLog_MCFM_JJQCD_bkgZJets_%iTeV_2l2q.root",
sqrts),
"read");
8435 TFile* foutput =
new TFile(Form(
"pAvgSmooth_MCFM_JJQCD_bkgZJets_%iTeV_2l2q.root",
sqrts),
"recreate");
8436 const unsigned int ngraphs=1;
8437 TString strtg[ngraphs]={
8438 "tg_P_ConserveDifermionMass"
8441 for (
unsigned int ig=0; ig<ngraphs; ig++){
8443 TGraphErrors* tg = 0;
8444 tg = (TGraphErrors*)finput->Get(strtg[ig].Data());
8445 if (tg==0){ cerr << strtg[ig] <<
" does not exist." << endl;
continue; }
8446 tg->SetName(strtg[ig]);
8448 foutput->WriteTObject(tg);
8449 tg->SetName(Form(
"%s_Smooth", tg->GetName()));
8456 foutput->WriteTObject(tg);
8461 lowFcn->SetNpx(1000);
8462 highFcn->SetNpx(10000);
8464 foutput->WriteTObject(sp);
8465 foutput->WriteTObject(lowFcn);
8466 foutput->WriteTObject(highFcn);
8468 TCanvas* ctest =
new TCanvas(
"test",
"", 8, 30, 800, 800);
8470 tg->GetXaxis()->SetRangeUser(0, 20000);
8473 lowFcn->Draw(
"csame");
8474 highFcn->Draw(
"csame");
8475 ctest->RedrawAxis();
8478 foutput->WriteTObject(ctest);
8530 if (!(strprod ==
"Had_ZH" || strprod ==
"Had_WH"))
return;
8539 vector<PointRedivision> redivs;
8540 redivs.emplace_back(2, 90, 90);
8541 redivs.emplace_back(2, 90, 90);
8542 redivs.emplace_back(2, 90, 90);
8543 redivs.emplace_back(4, 1600, 3000);
8561 "../data/pAvgLinToLog_ANALYTICAL_ZZGG_HSMHiggs.root",
"tg_anaPdfInt",
8575 "../data/pAvgLinToLog_ANALYTICAL_ZZGG_HSMHiggs.root",
"tg_anaPdfInt",
8589 "../data/pAvgLinToLog_ANALYTICAL_ZZGG_HSMHiggs.root",
"tg_anaPdfInt",
8590 "../data/pAvgLinToLog_ANALYTICAL_ZZQQB_bkgZZ.root",
"tg_anaPdfInt",
8604 "../data/pAvgLinToLog_ANALYTICAL_ZZQQB_bkgZZ.root",
"tg_anaPdfInt",
8613 if (!(strprod ==
"Had_ZH_S" || strprod ==
"Had_WH_S" || strprod ==
"JJVBF_S"))
return;
8629 vector<PointRedivision> redivs;
8631 redivs.emplace_back(2, 90, 90);
8632 redivs.emplace_back(2, 90, 90);
8633 redivs.emplace_back(2, 90, 90);
8635 redivs.emplace_back(4, 1600, 3000);
8637 vector<float> redivmultiplesA{ 192.072, 210.622, 243.901, 272.591, 331.305, 392.596, 449.076, 504.783, 565.813, 640.583, 729.157, 822.262, 945.274 };
8638 vector<float> redivmultiplesB{ 195.798, 215.901, 249.163, 286.182, 346.839, 406.022, 464.092, 522.738, 588.661, 672.415, 764.014, 862.423, 1015.89 };
8639 for (
unsigned int irm=0; irm<redivmultiplesA.size()-1; irm++){
8641 float xlow=std::max(redivmultiplesA.at(irm), redivmultiplesB.at(irm))+1e-2;
8642 float xhigh=std::min(redivmultiplesA.at(irm+1), redivmultiplesB.at(irm+1))-1e-2;
8643 redivs.emplace_back(1, xlow, xhigh);
8658 if (!(strprod ==
"Had_ZH" || strprod ==
"Had_WH" || strprod ==
"JJVBF"))
return;
8668 vector<PointRedivision> redivs;
8669 redivs.emplace_back(2, 90, 90);
8670 redivs.emplace_back(2, 90, 90);
8671 redivs.emplace_back(2, 90, 90);
8674 redivs.emplace_back(1, 105, 118);
8675 redivs.emplace_back(1, 120, 125);
8705 "../data/pAvgLinToLog_ANALYTICAL_ZZQQB_bkgZZ.root",
"tg_anaPdfInt",
8716 TString TREE_NAME =
"SelectedTree";
8719 Mela mela(erg_tev, mPOLE, verbosity);
8722 std::vector<double>* JetPt=0;
8723 std::vector<double>* JetEta=0;
8724 std::vector<double>* JetPhi=0;
8725 std::vector<double>* JetMass=0;
8726 std::vector<double> myJetPt;
8727 std::vector<double> myJetEta;
8728 std::vector<double> myJetPhi;
8729 std::vector<double> myJetMass;
8733 TBranch* bJetMass=0;
8734 float jetptetaphimass[2][4];
8737 float m1 = 91.471450;
8738 float m2 = 12.139782;
8739 float h1 = 0.2682896;
8740 float h2 = 0.1679779;
8741 float phi = 1.5969792;
8742 float hs = -0.727181;
8743 float phi1 = 1.8828257;
8744 float ZZPt, ZZPhi, ZZEta;
8745 int LepID[4]={ 13, -13, 11, -11 };
8747 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
8748 TString cinput_main;
8749 if (
sqrts==8) cinput_main =
"/scratch0/hep/ianderso/CJLST/140519/PRODFSR_8TeV";
8750 else if (
sqrts==7) cinput_main =
"/scratch0/hep/ianderso/CJLST/140519/PRODFSR";
8752 const int nSamples_JJVBF = 42;
8753 TString strSamples_JJVBF[nSamples_JJVBF]={
8754 "HZZ4lTree_VBFH116.root",
8755 "HZZ4lTree_VBFH117.root",
8756 "HZZ4lTree_VBFH118.root",
8757 "HZZ4lTree_VBFH119.root",
8758 "HZZ4lTree_VBFH120.root",
8759 "HZZ4lTree_VBFH121.root",
8760 "HZZ4lTree_VBFH122.root",
8761 "HZZ4lTree_VBFH123.root",
8762 "HZZ4lTree_VBFH124.root",
8763 "HZZ4lTree_VBFH125.root",
8764 "HZZ4lTree_VBFH126.root",
8765 "HZZ4lTree_VBFH127.root",
8766 "HZZ4lTree_VBFH128.root",
8767 "HZZ4lTree_VBFH129.root",
8768 "HZZ4lTree_VBFH130.root",
8769 "HZZ4lTree_VBFH135.root",
8770 "HZZ4lTree_VBFH140.root",
8771 "HZZ4lTree_VBFH145.root",
8772 "HZZ4lTree_VBFH150.root",
8773 "HZZ4lTree_VBFH160.root",
8774 "HZZ4lTree_VBFH170.root",
8775 "HZZ4lTree_VBFH180.root",
8776 "HZZ4lTree_VBFH190.root",
8777 "HZZ4lTree_powheg15VBFH200.root",
8778 "HZZ4lTree_powheg15VBFH225.root",
8779 "HZZ4lTree_powheg15VBFH250.root",
8780 "HZZ4lTree_powheg15VBFH275.root",
8781 "HZZ4lTree_powheg15VBFH300.root",
8782 "HZZ4lTree_powheg15VBFH350.root",
8783 "HZZ4lTree_powheg15VBFH400.root",
8784 "HZZ4lTree_powheg15VBFH450.root",
8785 "HZZ4lTree_powheg15VBFH500.root",
8786 "HZZ4lTree_powheg15VBFH550.root",
8787 "HZZ4lTree_powheg15VBFH600.root",
8788 "HZZ4lTree_powheg15VBFH650.root",
8789 "HZZ4lTree_powheg15VBFH700.root",
8790 "HZZ4lTree_powheg15VBFH750.root",
8791 "HZZ4lTree_powheg15VBFH800.root",
8792 "HZZ4lTree_powheg15VBFH850.root",
8793 "HZZ4lTree_powheg15VBFH900.root",
8794 "HZZ4lTree_powheg15VBFH950.root",
8795 "HZZ4lTree_powheg15VBFH1000.root"
8797 const int nSamples_JJQCD = 37;
8798 TString strSamples_JJQCD[nSamples_JJQCD]={
8799 "HZZ4lTree_minloH90.root",
8800 "HZZ4lTree_minloH95.root",
8801 "HZZ4lTree_minloH100.root",
8802 "HZZ4lTree_minloH105.root",
8803 "HZZ4lTree_minloH110.root",
8804 "HZZ4lTree_minloH115.root",
8805 "HZZ4lTree_minloH120.root",
8806 "HZZ4lTree_minloH124.root",
8807 "HZZ4lTree_minloH125.root",
8808 "HZZ4lTree_minloH126.root",
8809 "HZZ4lTree_minloH130.root",
8810 "HZZ4lTree_minloH135.root",
8811 "HZZ4lTree_minloH140.root",
8812 "HZZ4lTree_minloH145.root",
8813 "HZZ4lTree_minloH150.root",
8814 "HZZ4lTree_minloH155.root",
8815 "HZZ4lTree_minloH160.root",
8816 "HZZ4lTree_minloH170.root",
8817 "HZZ4lTree_minloH180.root",
8818 "HZZ4lTree_minloH190.root",
8819 "HZZ4lTree_minloH200.root",
8820 "HZZ4lTree_minloH250.root",
8821 "HZZ4lTree_minloH300.root",
8822 "HZZ4lTree_minloH350.root",
8823 "HZZ4lTree_minloH400.root",
8824 "HZZ4lTree_minloH450.root",
8825 "HZZ4lTree_minloH500.root",
8826 "HZZ4lTree_minloH550.root",
8827 "HZZ4lTree_minloH600.root",
8828 "HZZ4lTree_minloH650.root",
8829 "HZZ4lTree_minloH700.root",
8830 "HZZ4lTree_minloH750.root",
8831 "HZZ4lTree_minloH800.root",
8832 "HZZ4lTree_minloH850.root",
8833 "HZZ4lTree_minloH900.root",
8834 "HZZ4lTree_minloH950.root",
8835 "HZZ4lTree_minloH1000.root"
8839 new TChain(TREE_NAME,
""),
8840 new TChain(TREE_NAME,
"")
8842 for (
int ic=0; ic<3; ic++){
8843 for (
int is=0; is<nSamples_JJVBF; is++) tree[0]->Add(Form(
"%s/%s/%s", cinput_main.Data(), (strchannel[ic]).Data(), (strSamples_JJVBF[is]).Data()));
8844 for (
int is=0; is<nSamples_JJQCD; is++) tree[1]->Add(Form(
"%s/%s/%s", cinput_main.Data(), (strchannel[ic]).Data(), (strSamples_JJQCD[is]).Data()));
8846 for (
int it=0; it<2; it++){
8847 tree[it]->SetBranchAddress(
"NJets30", &NJets30);
8848 tree[it]->SetBranchAddress(
"JetPt", &JetPt, &bJetPt);
8849 tree[it]->SetBranchAddress(
"JetEta", &JetEta, &bJetEta);
8850 tree[it]->SetBranchAddress(
"JetPhi", &JetPhi, &bJetPhi);
8851 tree[it]->SetBranchAddress(
"JetMass", &JetMass, &bJetMass);
8852 tree[it]->SetBranchAddress(
"ZZMass", &mzz);
8853 tree[it]->SetBranchAddress(
"ZZPt", &ZZPt);
8854 tree[it]->SetBranchAddress(
"ZZEta", &ZZEta);
8855 tree[it]->SetBranchAddress(
"ZZPhi", &ZZPhi);
8856 tree[it]->SetBranchAddress(
"Z1Mass", &m1);
8857 tree[it]->SetBranchAddress(
"Z2Mass", &m2);
8858 tree[it]->SetBranchAddress(
"helcosthetaZ1", &h1);
8859 tree[it]->SetBranchAddress(
"helcosthetaZ2", &h2);
8860 tree[it]->SetBranchAddress(
"helphi", &phi);
8861 tree[it]->SetBranchAddress(
"costhetastar", &hs);
8862 tree[it]->SetBranchAddress(
"phistarZ1", &phi1);
8865 TFile* foutput =
new TFile(Form(
"pJHUGen_JJVBF_JJQCD_HSMHiggs_Comparison_%iTeV.root",
sqrts),
"recreate");
8867 TH2F* hJJVBF =
new TH2F(
"JJVBF",
"", 50, 70, 1070, 10, 0, 1);
8868 TH2F* hJJQCD =
new TH2F(
"JJQCD",
"", 50, 70, 1070, 10, 0, 1);
8870 TProfile* prJJVBF =
new TProfile(
"prJJVBF",
"", 50, 70, 1070); prJJVBF->Sumw2();
8871 TProfile* prJJQCD =
new TProfile(
"prJJQCD",
"", 50, 70, 1070); prJJQCD->Sumw2();
8875 int nTotalEntries = tree[0]->GetEntries();
8876 for (
int ev = 0;
ev < nTotalEntries;
ev++){
8877 tree[0]->GetEntry(
ev);
8878 if (
ev%10000==0)
cout <<
"Doing event " <<
ev << endl;
8880 for (
int ij=0; ij<2; ij++){
8881 jetptetaphimass[ij][0]=JetPt->at(ij);
8882 jetptetaphimass[ij][1]=JetEta->at(ij);
8883 jetptetaphimass[ij][2]=JetPhi->at(ij);
8884 jetptetaphimass[ij][3]=JetMass->at(ij);
8887 TLorentzVector jet[2], higgs;
8888 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(jetptetaphimass[ij][0], jetptetaphimass[ij][1], jetptetaphimass[ij][2], jetptetaphimass[ij][3]);
8889 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
8890 TVector3 boostH = higgs.BoostVector();
8896 TLorentzVector pDaughters[4];
8897 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
8898 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); pDaughters[ip].Boost(boostH); }
8903 float mesq_jjvbf=0, mesq_jjqcd=0;
8906 mela.computeProdP(mesq_jjvbf,
true);
8909 mela.computeProdP(mesq_jjqcd,
true);
8910 float kd = mesq_jjvbf/(mesq_jjvbf+0.06*mesq_jjqcd);
8912 hJJVBF->Fill(mzz, kd);
8913 prJJVBF->Fill(mzz, mesq_jjvbf);
8915 mela.resetInputEvent();
8918 nTotalEntries = tree[1]->GetEntries();
8919 for (
int ev = 0;
ev < nTotalEntries;
ev++){
8920 tree[1]->GetEntry(
ev);
8921 if (
ev%10000==0)
cout <<
"Doing event " <<
ev << endl;
8923 for (
int ij=0; ij<2; ij++){
8924 jetptetaphimass[ij][0]=JetPt->at(ij);
8925 jetptetaphimass[ij][1]=JetEta->at(ij);
8926 jetptetaphimass[ij][2]=JetPhi->at(ij);
8927 jetptetaphimass[ij][3]=JetMass->at(ij);
8930 TLorentzVector jet[2], higgs;
8931 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(jetptetaphimass[ij][0], jetptetaphimass[ij][1], jetptetaphimass[ij][2], jetptetaphimass[ij][3]);
8932 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
8933 TVector3 boostH = higgs.BoostVector();
8939 TLorentzVector pDaughters[4];
8940 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
8941 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); pDaughters[ip].Boost(boostH); }
8946 float mesq_jjvbf=0, mesq_jjqcd=0;
8949 mela.computeProdP(mesq_jjvbf,
true);
8952 mela.computeProdP(mesq_jjqcd,
true);
8953 float kd = mesq_jjvbf/(mesq_jjvbf+0.06*mesq_jjqcd);
8955 hJJQCD->Fill(mzz, kd);
8956 prJJQCD->Fill(mzz, mesq_jjqcd);
8958 mela.resetInputEvent();
8962 for (
int ix=1; ix<=hJJVBF->GetNbinsX(); ix++){
8963 double integral = hJJVBF->Integral(ix, ix, 0, hJJVBF->GetNbinsY()+1);
8964 for (
int iy=0; iy<=hJJVBF->GetNbinsY(); iy++){
if (integral!=0.) hJJVBF->SetBinContent(ix, iy, hJJVBF->GetBinContent(ix, iy)/integral); }
8966 for (
int ix=1; ix<=hJJQCD->GetNbinsX(); ix++){
8967 double integral = hJJQCD->Integral(ix, ix, 0, hJJQCD->GetNbinsY()+1);
8968 for (
int iy=0; iy<=hJJQCD->GetNbinsY(); iy++){
if (integral!=0.) hJJQCD->SetBinContent(ix, iy, hJJQCD->GetBinContent(ix, iy)/integral); }
8971 foutput->WriteTObject(hJJVBF);
8972 foutput->WriteTObject(hJJQCD);
8973 foutput->WriteTObject(prJJVBF);
8974 foutput->WriteTObject(prJJQCD);
8976 for (
int it=0; it<2; it++)
delete tree[it];
8982 TString TREE_NAME =
"ZZTree/candTree";
8985 Mela mela(erg_tev, mPOLE, verbosity);
8988 std::vector<float>* JetPt=0;
8989 std::vector<float>* JetEta=0;
8990 std::vector<float>* JetPhi=0;
8991 std::vector<float>* JetMass=0;
8992 std::vector<float> myJetPt;
8993 std::vector<float> myJetEta;
8994 std::vector<float> myJetPhi;
8995 std::vector<float> myJetMass;
8999 TBranch* bJetMass=0;
9000 float jetptetaphimass[2][4];
9003 float m1 = 91.471450;
9004 float m2 = 12.139782;
9005 float h1 = 0.2682896;
9006 float h2 = 0.1679779;
9007 float phi = 1.5969792;
9008 float hs = -0.727181;
9009 float phi1 = 1.8828257;
9010 float ZZPt, ZZPhi, ZZEta;
9011 int LepID[4]={ 13, -13, 11, -11 };
9013 TString cinput_main;
9014 if (
sqrts==13) cinput_main =
"/scratch0/hep/usarical/CJLST/LHC_13TeV/4l/160225";
9016 const int nSamples_JJVBF = 33;
9017 TString strSamples_JJVBF[nSamples_JJVBF]={
9018 "VBFH115/ZZ4lAnalysis.root",
9019 "VBFH120/ZZ4lAnalysis.root",
9020 "VBFH124/ZZ4lAnalysis.root",
9021 "VBFH125/ZZ4lAnalysis.root",
9022 "VBFH126/ZZ4lAnalysis.root",
9023 "VBFH130/ZZ4lAnalysis.root",
9024 "VBFH135/ZZ4lAnalysis.root",
9025 "VBFH140/ZZ4lAnalysis.root",
9026 "VBFH145/ZZ4lAnalysis.root",
9027 "VBFH150/ZZ4lAnalysis.root",
9028 "VBFH155/ZZ4lAnalysis.root",
9029 "VBFH160/ZZ4lAnalysis.root",
9030 "VBFH165/ZZ4lAnalysis.root",
9031 "VBFH170/ZZ4lAnalysis.root",
9032 "VBFH175/ZZ4lAnalysis.root",
9033 "VBFH180/ZZ4lAnalysis.root",
9034 "VBFH190/ZZ4lAnalysis.root",
9035 "VBFH200/ZZ4lAnalysis.root",
9036 "VBFH210/ZZ4lAnalysis.root",
9037 "VBFH230/ZZ4lAnalysis.root",
9038 "VBFH250/ZZ4lAnalysis.root",
9039 "VBFH270/ZZ4lAnalysis.root",
9040 "VBFH300/ZZ4lAnalysis.root",
9041 "VBFH350/ZZ4lAnalysis.root",
9042 "VBFH400/ZZ4lAnalysis.root",
9043 "VBFH450/ZZ4lAnalysis.root",
9044 "VBFH500/ZZ4lAnalysis.root",
9045 "VBFH550/ZZ4lAnalysis.root",
9046 "VBFH600/ZZ4lAnalysis.root",
9047 "VBFH700/ZZ4lAnalysis.root",
9048 "VBFH750/ZZ4lAnalysis.root",
9049 "VBFH800/ZZ4lAnalysis.root",
9050 "VBFH900/ZZ4lAnalysis.root"
9052 const int nSamples_JJQCD = 35;
9053 TString strSamples_JJQCD[nSamples_JJQCD]={
9054 "ggH91_GaZ/ZZ4lAnalysis.root",
9055 "ggH115/ZZ4lAnalysis.root",
9056 "ggH120/ZZ4lAnalysis.root",
9057 "ggH124/ZZ4lAnalysis.root",
9058 "ggH125/ZZ4lAnalysis.root",
9059 "ggH126/ZZ4lAnalysis.root",
9060 "ggH130/ZZ4lAnalysis.root",
9061 "ggH135/ZZ4lAnalysis.root",
9062 "ggH140/ZZ4lAnalysis.root",
9063 "ggH145/ZZ4lAnalysis.root",
9064 "ggH150/ZZ4lAnalysis.root",
9065 "ggH155/ZZ4lAnalysis.root",
9066 "ggH160/ZZ4lAnalysis.root",
9067 "ggH165/ZZ4lAnalysis.root",
9068 "ggH170/ZZ4lAnalysis.root",
9069 "ggH175/ZZ4lAnalysis.root",
9070 "ggH180/ZZ4lAnalysis.root",
9071 "ggH190/ZZ4lAnalysis.root",
9072 "ggH200/ZZ4lAnalysis.root",
9073 "ggH210/ZZ4lAnalysis.root",
9074 "ggH230/ZZ4lAnalysis.root",
9075 "ggH250/ZZ4lAnalysis.root",
9076 "ggH270/ZZ4lAnalysis.root",
9077 "ggH300/ZZ4lAnalysis.root",
9078 "ggH350/ZZ4lAnalysis.root",
9079 "ggH400/ZZ4lAnalysis.root",
9080 "ggH450/ZZ4lAnalysis.root",
9081 "ggH500/ZZ4lAnalysis.root",
9082 "ggH550/ZZ4lAnalysis.root",
9083 "ggH600/ZZ4lAnalysis.root",
9084 "ggH700/ZZ4lAnalysis.root",
9085 "ggH750/ZZ4lAnalysis.root",
9086 "ggH800/ZZ4lAnalysis.root",
9087 "ggH900/ZZ4lAnalysis.root",
9088 "ggH1000/ZZ4lAnalysis.root"
9092 new TChain(TREE_NAME,
""),
9093 new TChain(TREE_NAME,
"")
9095 for (
int is=0; is<nSamples_JJVBF; is++) tree[0]->Add(Form(
"%s/%s", cinput_main.Data(), (strSamples_JJVBF[is]).Data()));
9096 for (
int is=0; is<nSamples_JJQCD; is++) tree[1]->Add(Form(
"%s/%s", cinput_main.Data(), (strSamples_JJQCD[is]).Data()));
9098 for (
int it=0; it<2; it++){
9099 tree[it]->SetBranchAddress(
"nCleanedJetsPt30", &NJets30);
9100 tree[it]->SetBranchAddress(
"JetPt", &JetPt, &bJetPt);
9101 tree[it]->SetBranchAddress(
"JetEta", &JetEta, &bJetEta);
9102 tree[it]->SetBranchAddress(
"JetPhi", &JetPhi, &bJetPhi);
9103 tree[it]->SetBranchAddress(
"JetMass", &JetMass, &bJetMass);
9104 tree[it]->SetBranchAddress(
"ZZMass", &mzz);
9105 tree[it]->SetBranchAddress(
"ZZPt", &ZZPt);
9106 tree[it]->SetBranchAddress(
"ZZEta", &ZZEta);
9107 tree[it]->SetBranchAddress(
"ZZPhi", &ZZPhi);
9108 tree[it]->SetBranchAddress(
"Z1Mass", &m1);
9109 tree[it]->SetBranchAddress(
"Z2Mass", &m2);
9110 tree[it]->SetBranchAddress(
"helcosthetaZ1", &h1);
9111 tree[it]->SetBranchAddress(
"helcosthetaZ2", &h2);
9112 tree[it]->SetBranchAddress(
"helphi", &phi);
9113 tree[it]->SetBranchAddress(
"costhetastar", &hs);
9114 tree[it]->SetBranchAddress(
"phistarZ1", &phi1);
9117 TFile* foutput =
new TFile(Form(
"pJHUGen_JJVBF_JJQCD_HSMHiggs_Comparison_%iTeV.root",
sqrts),
"recreate");
9119 TH2F* hJJVBF =
new TH2F(
"JJVBF",
"", 75, 70, 1570, 10, 0, 1);
9120 TH2F* hJJQCD =
new TH2F(
"JJQCD",
"", 75, 70, 1570, 10, 0, 1);
9122 TProfile* prJJVBF =
new TProfile(
"prJJVBF",
"", 75, 70, 1570); prJJVBF->Sumw2();
9123 TProfile* prJJQCD =
new TProfile(
"prJJQCD",
"", 75, 70, 1570); prJJQCD->Sumw2();
9125 TProfile* prRatioForJJVBF =
new TProfile(
"prRatioForJJVBF",
"", 75, 70, 1570); prRatioForJJVBF->Sumw2();
9126 TProfile* prRatioForJJQCD =
new TProfile(
"prRatioForJJQCD",
"", 75, 70, 1570); prRatioForJJQCD->Sumw2();
9130 int nTotalEntries = tree[0]->GetEntries();
9131 for (
int ev = 0;
ev < nTotalEntries;
ev++){
9132 tree[0]->GetEntry(
ev);
9133 if (
ev%10000==0)
cout <<
"Doing event " <<
ev << endl;
9135 for (
int ij=0; ij<2; ij++){
9136 jetptetaphimass[ij][0]=JetPt->at(ij);
9137 jetptetaphimass[ij][1]=JetEta->at(ij);
9138 jetptetaphimass[ij][2]=JetPhi->at(ij);
9139 jetptetaphimass[ij][3]=JetMass->at(ij);
9142 TLorentzVector jet[2], higgs;
9143 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(jetptetaphimass[ij][0], jetptetaphimass[ij][1], jetptetaphimass[ij][2], jetptetaphimass[ij][3]);
9144 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
9145 TVector3 boostH = higgs.BoostVector();
9151 TLorentzVector pDaughters[4];
9152 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
9153 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); pDaughters[ip].Boost(boostH); }
9158 float mesq_jjvbf=0, mesq_jjqcd=0;
9161 mela.computeProdP(mesq_jjvbf,
true);
9164 mela.computeProdP(mesq_jjqcd,
true);
9165 float kd = mesq_jjvbf/(mesq_jjvbf+0.06*mesq_jjqcd);
9167 hJJVBF->Fill(mzz, kd);
9168 prJJVBF->Fill(mzz, mesq_jjvbf);
9169 if (mesq_jjvbf>0.) prRatioForJJVBF->Fill(mzz, mesq_jjqcd/mesq_jjvbf);
9171 mela.resetInputEvent();
9174 nTotalEntries = tree[1]->GetEntries();
9175 for (
int ev = 0;
ev < nTotalEntries;
ev++){
9176 tree[1]->GetEntry(
ev);
9177 if (
ev%10000==0)
cout <<
"Doing event " <<
ev << endl;
9179 for (
int ij=0; ij<2; ij++){
9180 jetptetaphimass[ij][0]=JetPt->at(ij);
9181 jetptetaphimass[ij][1]=JetEta->at(ij);
9182 jetptetaphimass[ij][2]=JetPhi->at(ij);
9183 jetptetaphimass[ij][3]=JetMass->at(ij);
9186 TLorentzVector jet[2], higgs;
9187 for (
int ij=0; ij<2; ij++) jet[ij].SetPtEtaPhiM(jetptetaphimass[ij][0], jetptetaphimass[ij][1], jetptetaphimass[ij][2], jetptetaphimass[ij][3]);
9188 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
9189 TVector3 boostH = higgs.BoostVector();
9195 TLorentzVector pDaughters[4];
9196 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
9197 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); pDaughters[ip].Boost(boostH); }
9202 float mesq_jjvbf=0, mesq_jjqcd=0;
9205 mela.computeProdP(mesq_jjvbf,
true);
9208 mela.computeProdP(mesq_jjqcd,
true);
9209 float kd = mesq_jjvbf/(mesq_jjvbf+0.06*mesq_jjqcd);
9211 hJJQCD->Fill(mzz, kd);
9212 prJJQCD->Fill(mzz, mesq_jjqcd);
9213 if (mesq_jjvbf>0.) prRatioForJJQCD->Fill(mzz, mesq_jjqcd/mesq_jjvbf);
9215 mela.resetInputEvent();
9219 for (
int ix=1; ix<=hJJVBF->GetNbinsX(); ix++){
9220 double integral = hJJVBF->Integral(ix, ix, 0, hJJVBF->GetNbinsY()+1);
9221 for (
int iy=0; iy<=hJJVBF->GetNbinsY(); iy++){
if (integral!=0.) hJJVBF->SetBinContent(ix, iy, hJJVBF->GetBinContent(ix, iy)/integral); }
9223 for (
int ix=1; ix<=hJJQCD->GetNbinsX(); ix++){
9224 double integral = hJJQCD->Integral(ix, ix, 0, hJJQCD->GetNbinsY()+1);
9225 for (
int iy=0; iy<=hJJQCD->GetNbinsY(); iy++){
if (integral!=0.) hJJQCD->SetBinContent(ix, iy, hJJQCD->GetBinContent(ix, iy)/integral); }
9228 foutput->WriteTObject(hJJVBF);
9229 foutput->WriteTObject(hJJQCD);
9230 foutput->WriteTObject(prJJVBF);
9231 foutput->WriteTObject(prJJQCD);
9232 foutput->WriteTObject(prRatioForJJVBF);
9233 foutput->WriteTObject(prRatioForJJQCD);
9235 for (
int it=0; it<2; it++)
delete tree[it];
9242 TString TREE_NAME =
"SelectedTree";
9245 Mela mela(erg_tev, mPOLE, verbosity);
9248 std::vector<double>* JetPt=0;
9249 std::vector<double>* JetEta=0;
9250 std::vector<double>* JetPhi=0;
9251 std::vector<double>* JetMass=0;
9252 std::vector<double> myJetPt;
9253 std::vector<double> myJetEta;
9254 std::vector<double> myJetPhi;
9255 std::vector<double> myJetMass;
9259 TBranch* bJetMass=0;
9260 float jetptetaphimass[2][4];
9263 float m1 = 91.471450;
9264 float m2 = 12.139782;
9265 float h1 = 0.2682896;
9266 float h2 = 0.1679779;
9267 float phi = 1.5969792;
9268 float hs = -0.727181;
9269 float phi1 = 1.8828257;
9270 float ZZPt, ZZPhi, ZZEta;
9271 int LepID[4]={ 13, -13, 11, -11 };
9274 TChain* tree[nMEs] ={
9275 new TChain(TREE_NAME,
"")
9278 TString strchannel[3]={
"4mu",
"4e",
"2mu2e" };
9279 TString cinput_main;
9280 if (
sqrts==8) cinput_main =
"/scratch0/hep/ianderso/CJLST/140519/PRODFSR_8TeV";
9281 else if (
sqrts==7) cinput_main =
"/scratch0/hep/ianderso/CJLST/140519/PRODFSR";
9283 const int nSamples_JQCD = 37;
9284 TString strSamples_JQCD[nSamples_JQCD]={
9285 "HZZ4lTree_minloH90.root",
9286 "HZZ4lTree_minloH95.root",
9287 "HZZ4lTree_minloH100.root",
9288 "HZZ4lTree_minloH105.root",
9289 "HZZ4lTree_minloH110.root",
9290 "HZZ4lTree_minloH115.root",
9291 "HZZ4lTree_minloH120.root",
9292 "HZZ4lTree_minloH124.root",
9293 "HZZ4lTree_minloH125.root",
9294 "HZZ4lTree_minloH126.root",
9295 "HZZ4lTree_minloH130.root",
9296 "HZZ4lTree_minloH135.root",
9297 "HZZ4lTree_minloH140.root",
9298 "HZZ4lTree_minloH145.root",
9299 "HZZ4lTree_minloH150.root",
9300 "HZZ4lTree_minloH155.root",
9301 "HZZ4lTree_minloH160.root",
9302 "HZZ4lTree_minloH170.root",
9303 "HZZ4lTree_minloH180.root",
9304 "HZZ4lTree_minloH190.root",
9305 "HZZ4lTree_minloH200.root",
9306 "HZZ4lTree_minloH250.root",
9307 "HZZ4lTree_minloH300.root",
9308 "HZZ4lTree_minloH350.root",
9309 "HZZ4lTree_minloH400.root",
9310 "HZZ4lTree_minloH450.root",
9311 "HZZ4lTree_minloH500.root",
9312 "HZZ4lTree_minloH550.root",
9313 "HZZ4lTree_minloH600.root",
9314 "HZZ4lTree_minloH650.root",
9315 "HZZ4lTree_minloH700.root",
9316 "HZZ4lTree_minloH750.root",
9317 "HZZ4lTree_minloH800.root",
9318 "HZZ4lTree_minloH850.root",
9319 "HZZ4lTree_minloH900.root",
9320 "HZZ4lTree_minloH950.root",
9321 "HZZ4lTree_minloH1000.root"
9323 for (
int ic=0; ic<3; ic++){
9324 for (
int is=0; is<nSamples_JQCD; is++) tree[0]->Add(Form(
"%s/%s/%s", cinput_main.Data(), (strchannel[ic]).Data(), (strSamples_JQCD[is]).Data()));
9326 for (
int it=0; it<nMEs; it++){
9327 tree[it]->SetBranchAddress(
"NJets30", &NJets30);
9328 tree[it]->SetBranchAddress(
"JetPt", &JetPt, &bJetPt);
9329 tree[it]->SetBranchAddress(
"JetEta", &JetEta, &bJetEta);
9330 tree[it]->SetBranchAddress(
"JetPhi", &JetPhi, &bJetPhi);
9331 tree[it]->SetBranchAddress(
"JetMass", &JetMass, &bJetMass);
9332 tree[it]->SetBranchAddress(
"ZZMass", &mzz);
9333 tree[it]->SetBranchAddress(
"ZZPt", &ZZPt);
9334 tree[it]->SetBranchAddress(
"ZZEta", &ZZEta);
9335 tree[it]->SetBranchAddress(
"ZZPhi", &ZZPhi);
9336 tree[it]->SetBranchAddress(
"Z1Mass", &m1);
9337 tree[it]->SetBranchAddress(
"Z2Mass", &m2);
9338 tree[it]->SetBranchAddress(
"helcosthetaZ1", &h1);
9339 tree[it]->SetBranchAddress(
"helcosthetaZ2", &h2);
9340 tree[it]->SetBranchAddress(
"helphi", &phi);
9341 tree[it]->SetBranchAddress(
"costhetastar", &hs);
9342 tree[it]->SetBranchAddress(
"phistarZ1", &phi1);
9345 TFile* foutput =
new TFile(Form(
"pJHUGen_JQCD_HSMHiggs_Comparison_%iTeV.root",
sqrts),
"recreate");
9347 TProfile* prJQCD =
new TProfile(
"prJQCD",
"", 75, 70, 1570); prJQCD->Sumw2();
9351 int nTotalEntries = tree[0]->GetEntries();
9352 for (
int ev = 0;
ev < nTotalEntries;
ev++){
9353 tree[0]->GetEntry(
ev);
9354 if (
ev%10000==0)
cout <<
"Doing event " <<
ev << endl;
9356 for (
int ij=0; ij<1; ij++){
9357 jetptetaphimass[ij][0]=JetPt->at(ij);
9358 jetptetaphimass[ij][1]=JetEta->at(ij);
9359 jetptetaphimass[ij][2]=JetPhi->at(ij);
9360 jetptetaphimass[ij][3]=JetMass->at(ij);
9363 TLorentzVector jet[1], higgs;
9364 for (
int ij=0; ij<1; ij++) jet[ij].SetPtEtaPhiM(jetptetaphimass[ij][0], jetptetaphimass[ij][1], jetptetaphimass[ij][2], jetptetaphimass[ij][3]);
9365 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
9366 TVector3 boostH = higgs.BoostVector();
9371 TLorentzVector pDaughters[4];
9372 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
9373 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); pDaughters[ip].Boost(boostH); }
9380 mela.computeProdP(mesq_jqcd,
true);
9382 prJQCD->Fill(mzz, mesq_jqcd);
9384 mela.resetInputEvent();
9388 foutput->WriteTObject(prJQCD);
9390 for (
int it=0; it<nMEs; it++)
delete tree[it];
9396 TString TREE_NAME =
"ZZTree/candTree";
9399 Mela mela(erg_tev, mPOLE, verbosity);
9402 std::vector<float>* JetPt=0;
9403 std::vector<float>* JetEta=0;
9404 std::vector<float>* JetPhi=0;
9405 std::vector<float>* JetMass=0;
9406 std::vector<float> myJetPt;
9407 std::vector<float> myJetEta;
9408 std::vector<float> myJetPhi;
9409 std::vector<float> myJetMass;
9413 TBranch* bJetMass=0;
9414 float jetptetaphimass[2][4];
9417 float m1 = 91.471450;
9418 float m2 = 12.139782;
9419 float h1 = 0.2682896;
9420 float h2 = 0.1679779;
9421 float phi = 1.5969792;
9422 float hs = -0.727181;
9423 float phi1 = 1.8828257;
9424 float ZZPt, ZZPhi, ZZEta;
9425 int LepID[4]={ 13, -13, 11, -11 };
9428 TChain* tree[nMEs] ={
9429 new TChain(TREE_NAME,
"")
9432 TString cinput_main;
9433 if (
sqrts==13) cinput_main =
"/scratch0/hep/usarical/CJLST/LHC_13TeV/4l/160225";
9435 const int nSamples_JQCD = 35;
9436 TString strSamples_JQCD[nSamples_JQCD]={
9437 "ggH91_GaZ/ZZ4lAnalysis.root",
9438 "ggH115/ZZ4lAnalysis.root",
9439 "ggH120/ZZ4lAnalysis.root",
9440 "ggH124/ZZ4lAnalysis.root",
9441 "ggH125/ZZ4lAnalysis.root",
9442 "ggH126/ZZ4lAnalysis.root",
9443 "ggH130/ZZ4lAnalysis.root",
9444 "ggH135/ZZ4lAnalysis.root",
9445 "ggH140/ZZ4lAnalysis.root",
9446 "ggH145/ZZ4lAnalysis.root",
9447 "ggH150/ZZ4lAnalysis.root",
9448 "ggH155/ZZ4lAnalysis.root",
9449 "ggH160/ZZ4lAnalysis.root",
9450 "ggH165/ZZ4lAnalysis.root",
9451 "ggH170/ZZ4lAnalysis.root",
9452 "ggH175/ZZ4lAnalysis.root",
9453 "ggH180/ZZ4lAnalysis.root",
9454 "ggH190/ZZ4lAnalysis.root",
9455 "ggH200/ZZ4lAnalysis.root",
9456 "ggH210/ZZ4lAnalysis.root",
9457 "ggH230/ZZ4lAnalysis.root",
9458 "ggH250/ZZ4lAnalysis.root",
9459 "ggH270/ZZ4lAnalysis.root",
9460 "ggH300/ZZ4lAnalysis.root",
9461 "ggH350/ZZ4lAnalysis.root",
9462 "ggH400/ZZ4lAnalysis.root",
9463 "ggH450/ZZ4lAnalysis.root",
9464 "ggH500/ZZ4lAnalysis.root",
9465 "ggH550/ZZ4lAnalysis.root",
9466 "ggH600/ZZ4lAnalysis.root",
9467 "ggH700/ZZ4lAnalysis.root",
9468 "ggH750/ZZ4lAnalysis.root",
9469 "ggH800/ZZ4lAnalysis.root",
9470 "ggH900/ZZ4lAnalysis.root",
9471 "ggH1000/ZZ4lAnalysis.root"
9473 for (
int is=0; is<nSamples_JQCD; is++) tree[0]->Add(Form(
"%s/%s", cinput_main.Data(), (strSamples_JQCD[is]).Data()));
9474 for (
int it=0; it<nMEs; it++){
9475 tree[it]->SetBranchAddress(
"nCleanedJetsPt30", &NJets30);
9476 tree[it]->SetBranchAddress(
"JetPt", &JetPt, &bJetPt);
9477 tree[it]->SetBranchAddress(
"JetEta", &JetEta, &bJetEta);
9478 tree[it]->SetBranchAddress(
"JetPhi", &JetPhi, &bJetPhi);
9479 tree[it]->SetBranchAddress(
"JetMass", &JetMass, &bJetMass);
9480 tree[it]->SetBranchAddress(
"ZZMass", &mzz);
9481 tree[it]->SetBranchAddress(
"ZZPt", &ZZPt);
9482 tree[it]->SetBranchAddress(
"ZZEta", &ZZEta);
9483 tree[it]->SetBranchAddress(
"ZZPhi", &ZZPhi);
9484 tree[it]->SetBranchAddress(
"Z1Mass", &m1);
9485 tree[it]->SetBranchAddress(
"Z2Mass", &m2);
9486 tree[it]->SetBranchAddress(
"helcosthetaZ1", &h1);
9487 tree[it]->SetBranchAddress(
"helcosthetaZ2", &h2);
9488 tree[it]->SetBranchAddress(
"helphi", &phi);
9489 tree[it]->SetBranchAddress(
"costhetastar", &hs);
9490 tree[it]->SetBranchAddress(
"phistarZ1", &phi1);
9493 TFile* foutput =
new TFile(Form(
"pJHUGen_JQCD_HSMHiggs_Comparison_%iTeV.root",
sqrts),
"recreate");
9495 TProfile* prJQCD =
new TProfile(
"prJQCD",
"", 35, 70, 1575); prJQCD->Sumw2();
9499 int nTotalEntries = tree[0]->GetEntries();
9500 for (
int ev = 0;
ev < nTotalEntries;
ev++){
9501 tree[0]->GetEntry(
ev);
9502 if (
ev%10000==0)
cout <<
"Doing event " <<
ev << endl;
9504 for (
int ij=0; ij<1; ij++){
9505 jetptetaphimass[ij][0]=JetPt->at(ij);
9506 jetptetaphimass[ij][1]=JetEta->at(ij);
9507 jetptetaphimass[ij][2]=JetPhi->at(ij);
9508 jetptetaphimass[ij][3]=JetMass->at(ij);
9511 TLorentzVector jet[1], higgs;
9512 for (
int ij=0; ij<1; ij++) jet[ij].SetPtEtaPhiM(jetptetaphimass[ij][0], jetptetaphimass[ij][1], jetptetaphimass[ij][2], jetptetaphimass[ij][3]);
9513 higgs.SetPtEtaPhiM(ZZPt, ZZEta, ZZPhi, mzz);
9514 TVector3 boostH = higgs.BoostVector();
9519 TLorentzVector pDaughters[4];
9520 std::vector<TLorentzVector> daus =
mela.calculate4Momentum(mzz, m1, m2, acos(hs), acos(h1), acos(h2), phi1, phi);
9521 for (
int ip=0; ip<min(4, (
int)daus.size()); ip++){ pDaughters[ip]=daus.at(ip); pDaughters[ip].Boost(boostH); }
9528 mela.computeProdP(mesq_jqcd,
true);
9530 prJQCD->Fill(mzz, mesq_jqcd);
9532 mela.resetInputEvent();
9536 foutput->WriteTObject(prJQCD);
9538 for (
int it=0; it<nMEs; it++)
delete tree[it];