Hi everyone, I am having a problem with hadd trying to merge some TH1.
I have attached the root file that I am using.
The files contain 2 TH1:
GenEle/pt
HGCalCluTkGenMatch/GenEle/pt
Trying to sum the histograms in the two files I obtain something weird:
For GenEle/pt the final hist seems to be correct
For HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt the output file contains the sum of HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt of the first file and GenEle/pt of the second file
The command used is just
hadd hadd.root ./EEstudy_DoubleElectronsPU0_131Xv3Tc_0.root ./EEstudy_DoubleElectronsPU0_131Xv3Tc_1.root
Am i doing something wrong?
EEstudy_DoubleElectronsPU0_131Xv3Tc_0.root (14.7 KB)
EEstudy_DoubleElectronsPU0_131Xv3Tc_1.root (14.7 KB)
hadd.root (6.0 KB)
Info:
------------------------------------------------------------------
| Welcome to ROOT 6.32.04 https://root.cern |
| (c) 1995-2024, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for linuxx8664gcc on Aug 30 2024, 19:16:07 |
| From heads/master@tags/v6-32-04 |
| With c++ (GCC) 14.2.1 20240805 |
| Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
couet
September 18, 2024, 10:44am
2
Welcome to the ROOT forum
I am not sure but slash ( /
) in the histograms names might confuse hadd
.
Sorry, the slashes are not in the histogram name, HGCalCluTkGenMatch and GenEle are the names of the folders that contain the TH1. The name of the TH1 is just pt
couet
September 18, 2024, 11:56am
4
I ran your example and displayed the 3 files in //:
Is it what you observe too ? the right most plot is the sum of the left on and the middle on. looks the first bin on the sum is too high. Am I right ?
Yes, exactly.
If you count the bin entries you will see that the right-most plot is the sum of the left-most plot and the histogram GenEle/pt of the file opened in the middle TBrowser
couet
September 18, 2024, 12:25pm
6
Not even I see that:
the first bin of the left most plot is 46
the first bin of histogram GenEle/pt of the file opened in the middle TBrowser is 246
the first bin of the right most plots is 250
46 + 246 > 250 …
Well, that’s visual. May be it should be confirmed with GetBinContent
void check(){
TFile file0 ("EEstudy_DoubleElectronsPU0_131Xv3Tc_0.root");
TFile file1 ("EEstudy_DoubleElectronsPU0_131Xv3Tc_1.root");
TFile hadd ("hadd.root");
auto h0 = (TH1D*) file0.Get("HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt");
auto h1 = (TH1D*) file1.Get("GenEle/pt");
auto hout=(TH1D*) hadd.Get("HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt");
for(int i=0; i<100; i++){
cout << "Bin: " << i << " File0: " << h0->GetBinContent(i) << " File1: " << h1->GetBinContent(i) << " Sum: " << h0->GetBinContent(i)+h1->GetBinContent(i) << " FileOut: " << hout->GetBinContent(i) << endl;
};
}
Output:
Bin: 0 File0: 0 File1: 0 Sum: 0 FileOut: 0
Bin: 1 File0: 0 File1: 0 Sum: 0 FileOut: 0
Bin: 2 File0: 0 File1: 0 Sum: 0 FileOut: 0
Bin: 3 File0: 4 File1: 246 Sum: 250 FileOut: 250
Bin: 4 File0: 45 File1: 216 Sum: 261 FileOut: 261
Bin: 5 File0: 73 File1: 256 Sum: 329 FileOut: 329
Bin: 6 File0: 95 File1: 250 Sum: 345 FileOut: 345
Bin: 7 File0: 121 File1: 280 Sum: 401 FileOut: 401
Bin: 8 File0: 141 File1: 240 Sum: 381 FileOut: 381
Bin: 9 File0: 136 File1: 224 Sum: 360 FileOut: 360
Bin: 10 File0: 146 File1: 206 Sum: 352 FileOut: 352
Bin: 11 File0: 186 File1: 274 Sum: 460 FileOut: 460
Bin: 12 File0: 182 File1: 202 Sum: 384 FileOut: 384
Bin: 13 File0: 214 File1: 220 Sum: 434 FileOut: 434
Bin: 14 File0: 186 File1: 228 Sum: 414 FileOut: 414
Bin: 15 File0: 192 File1: 252 Sum: 444 FileOut: 444
Bin: 16 File0: 214 File1: 242 Sum: 456 FileOut: 456
Bin: 17 File0: 176 File1: 206 Sum: 382 FileOut: 382
Bin: 18 File0: 203 File1: 252 Sum: 455 FileOut: 455
Bin: 19 File0: 177 File1: 258 Sum: 435 FileOut: 435
Bin: 20 File0: 194 File1: 214 Sum: 408 FileOut: 408
Bin: 21 File0: 198 File1: 232 Sum: 430 FileOut: 430
Bin: 22 File0: 174 File1: 190 Sum: 364 FileOut: 364
Bin: 23 File0: 195 File1: 220 Sum: 415 FileOut: 415
Bin: 24 File0: 149 File1: 226 Sum: 375 FileOut: 375
Bin: 25 File0: 173 File1: 218 Sum: 391 FileOut: 391
Bin: 26 File0: 217 File1: 226 Sum: 443 FileOut: 443
Bin: 27 File0: 221 File1: 226 Sum: 447 FileOut: 447
Bin: 28 File0: 215 File1: 216 Sum: 431 FileOut: 431
Bin: 29 File0: 215 File1: 230 Sum: 445 FileOut: 445
Bin: 30 File0: 211 File1: 248 Sum: 459 FileOut: 459
Bin: 31 File0: 198 File1: 202 Sum: 400 FileOut: 400
Bin: 32 File0: 231 File1: 196 Sum: 427 FileOut: 427
Bin: 33 File0: 210 File1: 206 Sum: 416 FileOut: 416
Bin: 34 File0: 226 File1: 274 Sum: 500 FileOut: 500
Bin: 35 File0: 186 File1: 246 Sum: 432 FileOut: 432
Bin: 36 File0: 217 File1: 238 Sum: 455 FileOut: 455
Bin: 37 File0: 208 File1: 182 Sum: 390 FileOut: 390
Bin: 38 File0: 168 File1: 244 Sum: 412 FileOut: 412
Bin: 39 File0: 191 File1: 198 Sum: 389 FileOut: 389
Bin: 40 File0: 197 File1: 228 Sum: 425 FileOut: 425
Bin: 41 File0: 225 File1: 242 Sum: 467 FileOut: 467
Bin: 42 File0: 202 File1: 226 Sum: 428 FileOut: 428
Bin: 43 File0: 212 File1: 234 Sum: 446 FileOut: 446
Bin: 44 File0: 232 File1: 266 Sum: 498 FileOut: 498
Bin: 45 File0: 233 File1: 246 Sum: 479 FileOut: 479
Bin: 46 File0: 193 File1: 248 Sum: 441 FileOut: 441
Bin: 47 File0: 204 File1: 228 Sum: 432 FileOut: 432
Bin: 48 File0: 209 File1: 258 Sum: 467 FileOut: 467
Bin: 49 File0: 165 File1: 220 Sum: 385 FileOut: 385
Bin: 50 File0: 187 File1: 208 Sum: 395 FileOut: 395
Bin: 51 File0: 213 File1: 222 Sum: 435 FileOut: 435
Bin: 52 File0: 208 File1: 260 Sum: 468 FileOut: 468
Bin: 53 File0: 203 File1: 208 Sum: 411 FileOut: 411
Bin: 54 File0: 236 File1: 232 Sum: 468 FileOut: 468
Bin: 55 File0: 219 File1: 240 Sum: 459 FileOut: 459
Bin: 56 File0: 237 File1: 246 Sum: 483 FileOut: 483
Bin: 57 File0: 204 File1: 204 Sum: 408 FileOut: 408
Bin: 58 File0: 208 File1: 244 Sum: 452 FileOut: 452
Bin: 59 File0: 219 File1: 224 Sum: 443 FileOut: 443
Bin: 60 File0: 228 File1: 226 Sum: 454 FileOut: 454
Bin: 61 File0: 228 File1: 234 Sum: 462 FileOut: 462
Bin: 62 File0: 191 File1: 224 Sum: 415 FileOut: 415
Bin: 63 File0: 229 File1: 238 Sum: 467 FileOut: 467
Bin: 64 File0: 231 File1: 212 Sum: 443 FileOut: 443
Bin: 65 File0: 201 File1: 212 Sum: 413 FileOut: 413
Bin: 66 File0: 217 File1: 240 Sum: 457 FileOut: 457
Bin: 67 File0: 227 File1: 240 Sum: 467 FileOut: 467
Bin: 68 File0: 195 File1: 256 Sum: 451 FileOut: 451
Bin: 69 File0: 245 File1: 222 Sum: 467 FileOut: 467
Bin: 70 File0: 200 File1: 260 Sum: 460 FileOut: 460
Bin: 71 File0: 199 File1: 214 Sum: 413 FileOut: 413
Bin: 72 File0: 221 File1: 258 Sum: 479 FileOut: 479
Bin: 73 File0: 220 File1: 234 Sum: 454 FileOut: 454
Bin: 74 File0: 222 File1: 218 Sum: 440 FileOut: 440
Bin: 75 File0: 239 File1: 218 Sum: 457 FileOut: 457
Bin: 76 File0: 218 File1: 264 Sum: 482 FileOut: 482
Bin: 77 File0: 234 File1: 234 Sum: 468 FileOut: 468
Bin: 78 File0: 202 File1: 242 Sum: 444 FileOut: 444
Bin: 79 File0: 168 File1: 220 Sum: 388 FileOut: 388
Bin: 80 File0: 250 File1: 214 Sum: 464 FileOut: 464
Bin: 81 File0: 176 File1: 240 Sum: 416 FileOut: 416
Bin: 82 File0: 219 File1: 228 Sum: 447 FileOut: 447
Bin: 83 File0: 202 File1: 226 Sum: 428 FileOut: 428
Bin: 84 File0: 200 File1: 248 Sum: 448 FileOut: 448
Bin: 85 File0: 200 File1: 224 Sum: 424 FileOut: 424
Bin: 86 File0: 214 File1: 212 Sum: 426 FileOut: 426
Bin: 87 File0: 185 File1: 240 Sum: 425 FileOut: 425
Bin: 88 File0: 217 File1: 222 Sum: 439 FileOut: 439
Bin: 89 File0: 207 File1: 208 Sum: 415 FileOut: 415
Bin: 90 File0: 216 File1: 212 Sum: 428 FileOut: 428
Bin: 91 File0: 236 File1: 248 Sum: 484 FileOut: 484
Bin: 92 File0: 171 File1: 236 Sum: 407 FileOut: 407
Bin: 93 File0: 226 File1: 244 Sum: 470 FileOut: 470
Bin: 94 File0: 219 File1: 208 Sum: 427 FileOut: 427
Bin: 95 File0: 176 File1: 226 Sum: 402 FileOut: 402
Bin: 96 File0: 242 File1: 236 Sum: 478 FileOut: 478
Bin: 97 File0: 228 File1: 262 Sum: 490 FileOut: 490
Bin: 98 File0: 208 File1: 240 Sum: 448 FileOut: 448
Bin: 99 File0: 228 File1: 266 Sum: 494 FileOut: 494
couet
September 18, 2024, 1:28pm
8
so it seems fine ? (Sum = FileOut
for all bins).
Sum is equal to FileOut for all bins but the problem is that I am summing the
HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt TH1 from the first file and GenEle/pt from the second file.
Hadd is summing different histograms from different folders
auto h0 = (TH1D*) file0.Get("HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt");
auto h1 = (TH1D*) file1.Get("GenEle/pt");
auto hout=(TH1D*) hadd.Get("HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt");
This is what it should be
void sum(){
TFile file0 ("EEstudy_DoubleElectronsPU0_131Xv3Tc_0.root");
TFile file1 ("EEstudy_DoubleElectronsPU0_131Xv3Tc_1.root");
TFile hadd ("hadd.root");
auto h0 = (TH1D*) file0.Get("HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt");
auto h1 = (TH1D*) file1.Get("HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt");
auto hout=(TH1D*) hadd.Get("HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt");
for(int i=0; i<100; i++){
cout << "Bin: " << i << " File0: " << h0->GetBinContent(i) << " File1: " << h1->GetBinContent(i) << " Sum: " << h0->GetBinContent(i)+h1->GetBinContent(i) << " FileOut: " << hout->GetBinContent(i) << endl;
};
}
Now h0 and h1 are the same histogram ( HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt
) from different files.
The sum column is the expected result, the FileOut is the hadd result
Output:
Bin: 0 File0: 0 File1: 0 Sum: 0 FileOut: 0
Bin: 1 File0: 0 File1: 0 Sum: 0 FileOut: 0
Bin: 2 File0: 0 File1: 0 Sum: 0 FileOut: 0
Bin: 3 File0: 4 File1: 11 Sum: 15 FileOut: 250
Bin: 4 File0: 45 File1: 50 Sum: 95 FileOut: 261
Bin: 5 File0: 73 File1: 82 Sum: 155 FileOut: 329
Bin: 6 File0: 95 File1: 115 Sum: 210 FileOut: 345
Bin: 7 File0: 121 File1: 158 Sum: 279 FileOut: 401
Bin: 8 File0: 141 File1: 152 Sum: 293 FileOut: 381
Bin: 9 File0: 136 File1: 155 Sum: 291 FileOut: 360
Bin: 10 File0: 146 File1: 141 Sum: 287 FileOut: 352
Bin: 11 File0: 186 File1: 186 Sum: 372 FileOut: 460
Bin: 12 File0: 182 File1: 148 Sum: 330 FileOut: 384
Bin: 13 File0: 214 File1: 164 Sum: 378 FileOut: 434
Bin: 14 File0: 186 File1: 165 Sum: 351 FileOut: 414
Bin: 15 File0: 192 File1: 203 Sum: 395 FileOut: 444
Bin: 16 File0: 214 File1: 196 Sum: 410 FileOut: 456
Bin: 17 File0: 176 File1: 159 Sum: 335 FileOut: 382
Bin: 18 File0: 203 File1: 208 Sum: 411 FileOut: 455
Bin: 19 File0: 177 File1: 212 Sum: 389 FileOut: 435
Bin: 20 File0: 194 File1: 163 Sum: 357 FileOut: 408
Bin: 21 File0: 198 File1: 190 Sum: 388 FileOut: 430
Bin: 22 File0: 174 File1: 156 Sum: 330 FileOut: 364
Bin: 23 File0: 195 File1: 185 Sum: 380 FileOut: 415
Bin: 24 File0: 149 File1: 199 Sum: 348 FileOut: 375
Bin: 25 File0: 173 File1: 184 Sum: 357 FileOut: 391
Bin: 26 File0: 217 File1: 196 Sum: 413 FileOut: 443
Bin: 27 File0: 221 File1: 181 Sum: 402 FileOut: 447
Bin: 28 File0: 215 File1: 183 Sum: 398 FileOut: 431
Bin: 29 File0: 215 File1: 193 Sum: 408 FileOut: 445
Bin: 30 File0: 211 File1: 208 Sum: 419 FileOut: 459
Bin: 31 File0: 198 File1: 175 Sum: 373 FileOut: 400
Bin: 32 File0: 231 File1: 170 Sum: 401 FileOut: 427
Bin: 33 File0: 210 File1: 178 Sum: 388 FileOut: 416
Bin: 34 File0: 226 File1: 245 Sum: 471 FileOut: 500
Bin: 35 File0: 186 File1: 217 Sum: 403 FileOut: 432
Bin: 36 File0: 217 File1: 218 Sum: 435 FileOut: 455
Bin: 37 File0: 208 File1: 161 Sum: 369 FileOut: 390
Bin: 38 File0: 168 File1: 211 Sum: 379 FileOut: 412
Bin: 39 File0: 191 File1: 172 Sum: 363 FileOut: 389
Bin: 40 File0: 197 File1: 203 Sum: 400 FileOut: 425
Bin: 41 File0: 225 File1: 201 Sum: 426 FileOut: 467
Bin: 42 File0: 202 File1: 194 Sum: 396 FileOut: 428
Bin: 43 File0: 212 File1: 204 Sum: 416 FileOut: 446
Bin: 44 File0: 232 File1: 240 Sum: 472 FileOut: 498
Bin: 45 File0: 233 File1: 217 Sum: 450 FileOut: 479
Bin: 46 File0: 193 File1: 221 Sum: 414 FileOut: 441
Bin: 47 File0: 204 File1: 207 Sum: 411 FileOut: 432
Bin: 48 File0: 209 File1: 217 Sum: 426 FileOut: 467
Bin: 49 File0: 165 File1: 193 Sum: 358 FileOut: 385
Bin: 50 File0: 187 File1: 194 Sum: 381 FileOut: 395
Bin: 51 File0: 213 File1: 193 Sum: 406 FileOut: 435
Bin: 52 File0: 208 File1: 234 Sum: 442 FileOut: 468
Bin: 53 File0: 203 File1: 180 Sum: 383 FileOut: 411
Bin: 54 File0: 236 File1: 201 Sum: 437 FileOut: 468
Bin: 55 File0: 219 File1: 218 Sum: 437 FileOut: 459
Bin: 56 File0: 237 File1: 231 Sum: 468 FileOut: 483
Bin: 57 File0: 204 File1: 183 Sum: 387 FileOut: 408
Bin: 58 File0: 208 File1: 215 Sum: 423 FileOut: 452
Bin: 59 File0: 219 File1: 198 Sum: 417 FileOut: 443
Bin: 60 File0: 228 File1: 207 Sum: 435 FileOut: 454
Bin: 61 File0: 228 File1: 208 Sum: 436 FileOut: 462
Bin: 62 File0: 191 File1: 206 Sum: 397 FileOut: 415
Bin: 63 File0: 229 File1: 210 Sum: 439 FileOut: 467
Bin: 64 File0: 231 File1: 193 Sum: 424 FileOut: 443
Bin: 65 File0: 201 File1: 186 Sum: 387 FileOut: 413
Bin: 66 File0: 217 File1: 208 Sum: 425 FileOut: 457
Bin: 67 File0: 227 File1: 226 Sum: 453 FileOut: 467
Bin: 68 File0: 195 File1: 226 Sum: 421 FileOut: 451
Bin: 69 File0: 245 File1: 202 Sum: 447 FileOut: 467
Bin: 70 File0: 200 File1: 244 Sum: 444 FileOut: 460
Bin: 71 File0: 199 File1: 195 Sum: 394 FileOut: 413
Bin: 72 File0: 221 File1: 237 Sum: 458 FileOut: 479
Bin: 73 File0: 220 File1: 206 Sum: 426 FileOut: 454
Bin: 74 File0: 222 File1: 199 Sum: 421 FileOut: 440
Bin: 75 File0: 239 File1: 197 Sum: 436 FileOut: 457
Bin: 76 File0: 218 File1: 234 Sum: 452 FileOut: 482
Bin: 77 File0: 234 File1: 218 Sum: 452 FileOut: 468
Bin: 78 File0: 202 File1: 225 Sum: 427 FileOut: 444
Bin: 79 File0: 168 File1: 202 Sum: 370 FileOut: 388
Bin: 80 File0: 250 File1: 198 Sum: 448 FileOut: 464
Bin: 81 File0: 176 File1: 219 Sum: 395 FileOut: 416
Bin: 82 File0: 219 File1: 210 Sum: 429 FileOut: 447
Bin: 83 File0: 202 File1: 212 Sum: 414 FileOut: 428
Bin: 84 File0: 200 File1: 230 Sum: 430 FileOut: 448
Bin: 85 File0: 200 File1: 216 Sum: 416 FileOut: 424
Bin: 86 File0: 214 File1: 195 Sum: 409 FileOut: 426
Bin: 87 File0: 185 File1: 222 Sum: 407 FileOut: 425
Bin: 88 File0: 217 File1: 207 Sum: 424 FileOut: 439
Bin: 89 File0: 207 File1: 181 Sum: 388 FileOut: 415
Bin: 90 File0: 216 File1: 199 Sum: 415 FileOut: 428
Bin: 91 File0: 236 File1: 230 Sum: 466 FileOut: 484
Bin: 92 File0: 171 File1: 220 Sum: 391 FileOut: 407
Bin: 93 File0: 226 File1: 227 Sum: 453 FileOut: 470
Bin: 94 File0: 219 File1: 191 Sum: 410 FileOut: 427
Bin: 95 File0: 176 File1: 204 Sum: 380 FileOut: 402
Bin: 96 File0: 242 File1: 218 Sum: 460 FileOut: 478
Bin: 97 File0: 228 File1: 236 Sum: 464 FileOut: 490
Bin: 98 File0: 208 File1: 227 Sum: 435 FileOut: 448
Bin: 99 File0: 228 File1: 250 Sum: 478 FileOut: 494
Should I open an issue on github?
couet
September 19, 2024, 9:58am
13
Yes, with the reproducer. As a workaround would it be possible to see if changing the name of the histogram in HGCalCluTkGenMatchSelected/HGCalCluGenMatch/GenEle/pt
make it works ?
system
Closed
October 3, 2024, 9:59am
14
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.