344{
345
346
347
349 int t_barrel_ec,t_pos_neg,t_emhad;
350 int t_FT,t_SL,t_CH,t_sampling,t_caloindex;
351 int t_Etai,t_Phii;
352 float t_Etaf,t_Phif,t_Eta_Rawf,t_Phi_Rawf,t_x,t_y,t_z;
353 ULong64_t t_onlid,t_offlid;
354 ULong64_t t_ttid;
355 std::vector<int>* t_hvid = nullptr;
356 TFile
ifile(inputtreefile);
357 TTree* idtree = (TTree*)
ifile.Get(
"LarId");
358 idtree->SetBranchAddress("BEC",&t_barrel_ec);
359 idtree->SetBranchAddress("Region",&t_pos_neg);
360 idtree->SetBranchAddress("EmHad",&t_emhad);
361 idtree->SetBranchAddress("FT",&t_FT);
362 idtree->SetBranchAddress("SL",&t_SL);
363 idtree->SetBranchAddress("CH",&t_CH);
364 idtree->SetBranchAddress("Sampling",&t_sampling);
365 idtree->SetBranchAddress("Partition",&t_caloindex);
366 idtree->SetBranchAddress("I_Eta",&t_Etai);
367 idtree->SetBranchAddress("I_Phi",&t_Phii);
368 idtree->SetBranchAddress("F_Eta",&t_Etaf);
369 idtree->SetBranchAddress("F_Phi",&t_Phif);
370 idtree->SetBranchAddress("R_Eta",&t_Eta_Rawf);
371 idtree->SetBranchAddress("R_Phi",&t_Phi_Rawf);
372 idtree->SetBranchAddress("X",&t_x);
373 idtree->SetBranchAddress("Y",&t_y);
374 idtree->SetBranchAddress("Z",&t_z);
375 idtree->SetBranchAddress("onlid",&t_onlid);
376 idtree->SetBranchAddress("offlid",&t_offlid);
377 idtree->SetBranchAddress("ttid",&t_ttid);
378 idtree->SetBranchAddress("hvid",&t_hvid);
379
380
381
382 TFile fdqm(inputhistfile);
383 const Char_t* Pattern = "run_%d/CaloMonitoring/LArCellMon_NoTrigSel/2d_Occupancy/CellOccupancyVsEtaPhi_%s_4Sigma";
388 h2[
i] = (
TH2F*)fdqm.Get(name);
389 if(!h2[i]){ printf(
"LArIdTranslatorHelper::MakeTranslatorMapping : Could not read input histograms.\n");
exit(-1); }
390 }
391
392
393 Int_t ix,iy,nbinsx,nbinsy;
397 nbinsx = h2[
i]->GetXaxis()->GetNbins();
398 nbinsy = h2[
i]->GetYaxis()->GetNbins();
399 std::vector<double>
xbins (nbinsx+1);
400 for(ix=0;ix<nbinsx;ix++){
401 xbins[ix] = h2[
i]->GetXaxis()->GetBinLowEdge(ix+1);
402 }
403 xbins[nbinsx] = h2[
i]->GetXaxis()->GetBinUpEdge(nbinsx);
404 std::vector<double>
ybins (nbinsy+1);
405 for(iy=0;iy<nbinsy;iy++){
406 ybins[iy] = h2[
i]->GetYaxis()->GetBinLowEdge(iy+1);
407 }
408 ybins[nbinsy] = h2[
i]->GetYaxis()->GetBinUpEdge(nbinsy);
409
414 h2map[
i][
j] = std::make_unique<TH2I>(name,
"",nbinsx,
xbins.data(),nbinsy,
ybins.data());
416 h2count[
i][
j].reset (
static_cast<TH2I*
>(h2map[i][j]->Clone(name)));
417
418 for(ix=0;ix<nbinsx;ix++){
419 for(iy=0;iy<nbinsy;iy++) h2map[i][j]->SetBinContent(ix+1,iy+1,-1);
420 }
421 }
422 }
423
424 Int_t barrel_ec,region,emhad;
429 std::vector<int>*
hvid =
nullptr;
431
432
433 TFile
file(
"LarIdTree_new.root",
"RECREATE");
434 TTree
tree(
"LarId",
"Channel IDs");
435 tree.Branch(
"BEC",&barrel_ec);
436 tree.Branch(
"Region",®ion);
437 tree.Branch(
"EmHad",&emhad);
438 tree.Branch(
"FT",&FT);
439 tree.Branch(
"SL",&SL);
440 tree.Branch(
"CH",&CH);
441 tree.Branch(
"Sampling",&Sampling);
442 tree.Branch(
"Partition",&Partition);
443 tree.Branch(
"I_Eta",&iEta);
444 tree.Branch(
"I_Phi",&iPhi);
447 tree.Branch(
"R_Eta",&Eta_Raw);
448 tree.Branch(
"R_Phi",&Phi_Raw);
459
460
461 Int_t nchannels = 0;
462 Double_t emb1PhiGran =
M_PI/32.0;
463 Int_t dupl = 0,dupl2 = 0;
464 Int_t empt = 0;
465 Int_t ntotal = 0;
466 Int_t phishifts = 0;
467
468
469 for(Int_t iline = 0 ; iline < idtree->GetEntries() ; iline++){
470 idtree->GetEntry(iline);
471
472
473 barrel_ec = t_barrel_ec;
474 region = t_pos_neg;
475 emhad = t_emhad;
477 SL = t_SL;
478 CH = t_CH;
479 Sampling = t_sampling;
488 Eta_Raw = t_Eta_Rawf;
489 Phi_Raw = t_Phi_Rawf;
494
495
497
498 Double_t celleta = Eta_Raw;
499 Double_t cellphi = Phi_Raw;
500 Double_t phiMod = 0;
501
503 printf(
"LArIdTranslatorHelper::MakeTranslatorMapping : Supplied index out of range: %d, [%d,%d]. Skipped entry %d.\n",Partition,0,
m_nPartitionLayers-1,iline);
504 continue;
505 }
506
507
508
509
510 if(Partition==1 || Partition==5){
511 if( ((Eta_Raw > 1.4) && (Eta_Raw < 1.475)) || ((Eta_Raw < -1.4) && (Eta_Raw > -1.475))) {
512
513
514 phiMod = std::fmod( std::fabs(Phi_Raw),emb1PhiGran);
515 celleta = Eta_Raw + (phiMod * 0.2551) - 0.0125;
516 }
517 }
518
519
521 binetadqm = h2[
j]->GetXaxis()->FindBin(celleta);
523
524
525 Bool_t success = 0;
526 Double_t lodiff,updiff;
527
535 success=1;
536 }
537
538
539 if(emhad>=1){
540 lodiff = cellphi-h2map[
j][0]->GetYaxis()->GetBinLowEdge(
binphidqm1);
541 updiff = cellphi-h2map[
j][0]->GetYaxis()->GetBinUpEdge(
binphidqm1);
542 Bool_t loedge = (std::fabs(lodiff) < 1
e-5) ? 1 : 0;
543 Bool_t upedge = (std::fabs(updiff) < 1
e-5) ? 1 : 0;
544
545 if(loedge || upedge){
547 phishifts++;
548
549
550 if(upedge){
559 success=1;
560 } else success = 0;
561 } else if(loedge){
570 success=1;
571 } else success = 0;
572 } else success = 0;
573 }
574 if(success) dupl+=1;
575 }
576 }
577
578
580
581 if(!success){
582 printf("LArIdTranslatorHelper::MakeTranslatorMapping : Orphan at %s %d %d (ft/sl/ch: %d %d %d) : eta,phi = %+.2f,%+.2f with bins [%+.2f,%+.2f] [%+.2f,%+.2f]. Prevented overwrite on ft/ch/sl %d %d %d\n",
584 h2map[j][0]->GetXaxis()->GetBinLowEdge(
binetadqm),h2map[j][0]->GetXaxis()->GetBinUpEdge(
binetadqm),
585 h2map[j][0]->GetYaxis()->GetBinLowEdge(
binphidqm1),h2map[j][0]->GetYaxis()->GetBinUpEdge(
binphidqm1),
589 );
590 }
591
592
594 nchannels+=1;
595 }
596
597
598
600 nbinsx = h2map[
i][0]->GetXaxis()->GetNbins();
601 nbinsy = h2map[
i][0]->GetYaxis()->GetNbins();
602 ntotal += nbinsx*nbinsy;
603 for(ix=0;ix<nbinsx;ix++){
604 for(iy=0;iy<nbinsy;iy++){
605 if(h2count[i][0]->GetBinContent(ix+1,iy+1)>1){
606 printf(
"LArIdTranslatorHelper::MakeTranslatorMapping : Duplicate at %s %d %d (last ft/sl/ch: %d %d %d) : [%+.4f,%+.4f] [%+.4f,%+.4f]\n",
m_PartitionLayers[i].c_str(),ix+1,iy+1,(
int)h2map[i][0]->GetBinContent(ix+1,iy+1),(
int)h2map[i][1]->GetBinContent(ix+1,iy+1),(
int)h2map[i][2]->GetBinContent(ix+1,iy+1),h2map[i][0]->GetXaxis()->GetBinLowEdge(ix+1),h2map[i][0]->GetXaxis()->GetBinUpEdge(ix+1),h2map[i][0]->GetYaxis()->GetBinLowEdge(iy+1),h2map[i][0]->GetYaxis()->GetBinUpEdge(iy+1));
607 dupl2+=1;
608 }
609
610 if(h2count[i][0]->GetBinContent(ix+1,iy+1)==0) empt+=1;
611 }
612 }
613 }
614
615
620
621 printf("-------------------------------------------------------------------\n");
622 printf("LArIdTranslatorHelper::MakeTranslatorMapping: Summary:\n");
623 printf("Info for %d channels (%d entries read).\n",nchannels,(int)idtree->GetEntries());
624 printf("There were %d duplicates, %d empty, %d (%d) phi-shifted (HEC-FCAL), %d physical.\n",dupl2,empt,dupl,phishifts,ntotal-empt-dupl);
625 printf("-------------------------------------------------------------------\n");
626
628 return;
629}
setScale setgFexType iEta
int run(int argc, char *argv[])