345{
346
347
348
350 int t_barrel_ec,t_pos_neg,t_emhad;
351 int t_FT,t_SL,t_CH,t_sampling,t_caloindex;
352 int t_Etai,t_Phii;
353 float t_Etaf,t_Phif,t_Eta_Rawf,t_Phi_Rawf,t_x,t_y,t_z;
354 ULong64_t t_onlid,t_offlid;
355 ULong64_t t_ttid;
356 std::vector<int>* t_hvid = nullptr;
357 TFile*
ifile =
new TFile(inputtreefile);
358 TTree* idtree = (TTree*)
ifile->Get(
"LarId");
359 idtree->SetBranchAddress("BEC",&t_barrel_ec);
360 idtree->SetBranchAddress("Region",&t_pos_neg);
361 idtree->SetBranchAddress("EmHad",&t_emhad);
362 idtree->SetBranchAddress("FT",&t_FT);
363 idtree->SetBranchAddress("SL",&t_SL);
364 idtree->SetBranchAddress("CH",&t_CH);
365 idtree->SetBranchAddress("Sampling",&t_sampling);
366 idtree->SetBranchAddress("Partition",&t_caloindex);
367 idtree->SetBranchAddress("I_Eta",&t_Etai);
368 idtree->SetBranchAddress("I_Phi",&t_Phii);
369 idtree->SetBranchAddress("F_Eta",&t_Etaf);
370 idtree->SetBranchAddress("F_Phi",&t_Phif);
371 idtree->SetBranchAddress("R_Eta",&t_Eta_Rawf);
372 idtree->SetBranchAddress("R_Phi",&t_Phi_Rawf);
373 idtree->SetBranchAddress("X",&t_x);
374 idtree->SetBranchAddress("Y",&t_y);
375 idtree->SetBranchAddress("Z",&t_z);
376 idtree->SetBranchAddress("onlid",&t_onlid);
377 idtree->SetBranchAddress("offlid",&t_offlid);
378 idtree->SetBranchAddress("ttid",&t_ttid);
379 idtree->SetBranchAddress("hvid",&t_hvid);
380
381
382
383 TFile* fdqm = new TFile(inputhistfile);
384 const Char_t* Pattern = "run_%d/CaloMonitoring/LArCellMon_NoTrigSel/2d_Occupancy/CellOccupancyVsEtaPhi_%s_4Sigma";
389 h2[
i] = (
TH2F*)fdqm->Get(name);
390 if(!h2[i]){ printf(
"LArIdTranslatorHelper::MakeTranslatorMapping : Could not read input histograms.\n");
exit(-1); }
391 }
392
393
394 Int_t ix,iy,nbinsx,nbinsy;
399 nbinsx = h2[
i]->GetXaxis()->GetNbins();
400 nbinsy = h2[
i]->GetYaxis()->GetNbins();
401 xbins =
new Double_t[nbinsx+1];
402 for(ix=0;ix<nbinsx;ix++){
403 xbins[ix] = h2[
i]->GetXaxis()->GetBinLowEdge(ix+1);
404 }
405 xbins[nbinsx] = h2[
i]->GetXaxis()->GetBinUpEdge(nbinsx);
406 ybins =
new Double_t[nbinsy+1];
407 for(iy=0;iy<nbinsy;iy++){
408 ybins[iy] = h2[
i]->GetYaxis()->GetBinLowEdge(iy+1);
409 }
410 ybins[nbinsy] = h2[
i]->GetYaxis()->GetBinUpEdge(nbinsy);
411
416 h2map[
i][j] =
new TH2I(name,
"",nbinsx,xbins,nbinsy,ybins);
418 h2count[
i][j] = (TH2I*)h2map[i][j]->Clone(name);
419
420 for(ix=0;ix<nbinsx;ix++){
421 for(iy=0;iy<nbinsy;iy++) h2map[i][j]->SetBinContent(ix+1,iy+1,-1);
422 }
423 }
426 }
427
428 Int_t barrel_ec,region,emhad;
433 std::vector<int>*
hvid =
nullptr;
435
436
437 TFile*
file =
new TFile(
"LarIdTree_new.root",
"RECREATE");
438 TTree*
tree =
new TTree(
"LarId",
"Channel IDs");
439 tree->Branch(
"BEC",&barrel_ec);
440 tree->Branch(
"Region",®ion);
441 tree->Branch(
"EmHad",&emhad);
442 tree->Branch(
"FT",&FT);
443 tree->Branch(
"SL",&SL);
444 tree->Branch(
"CH",&CH);
445 tree->Branch(
"Sampling",&Sampling);
446 tree->Branch(
"Partition",&Partition);
447 tree->Branch(
"I_Eta",&iEta);
448 tree->Branch(
"I_Phi",&iPhi);
451 tree->Branch(
"R_Eta",&Eta_Raw);
452 tree->Branch(
"R_Phi",&Phi_Raw);
453 tree->Branch(
"X",&
x);
454 tree->Branch(
"Y",&
y);
455 tree->Branch(
"Z",&
z);
463
464
465 Int_t nchannels = 0;
466 Double_t emb1PhiGran =
M_PI/(Double_t)32;
467 Int_t dupl = 0,dupl2 = 0;
468 Int_t empt = 0;
469 Int_t ntotal = 0;
470 Int_t phishifts = 0;
471
472
473 for(Int_t iline = 0 ; iline < idtree->GetEntries() ; iline++){
474 idtree->GetEntry(iline);
475
476
477 barrel_ec = t_barrel_ec;
478 region = t_pos_neg;
479 emhad = t_emhad;
481 SL = t_SL;
482 CH = t_CH;
483 Sampling = t_sampling;
492 Eta_Raw = t_Eta_Rawf;
493 Phi_Raw = t_Phi_Rawf;
498
499
501
502 Double_t celleta = Eta_Raw;
503 Double_t cellphi = Phi_Raw;
504 Double_t phiMod = 0;
505
507 printf(
"LArIdTranslatorHelper::MakeTranslatorMapping : Supplied index out of range: %d, [%d,%d]. Skipped entry %d.\n",Partition,0,
m_nPartitionLayers-1,iline);
508 continue;
509 }
510
511
512
513
514 if(Partition==1 || Partition==5){
515 if( ((Eta_Raw > 1.4) && (Eta_Raw < 1.475)) || ((Eta_Raw < -1.4) && (Eta_Raw > -1.475))) {
516
517
518 phiMod = fmod( fabs(Phi_Raw),emb1PhiGran);
519 celleta = Eta_Raw + (phiMod * 0.2551) - 0.0125;
520 }
521 }
522
523
525 binetadqm = h2[j]->GetXaxis()->FindBin(celleta);
526 binphidqm1 = h2[j]->GetYaxis()->FindBin(cellphi);
527
528
529 Bool_t success = 0;
530 Double_t lodiff,updiff;
531
539 success=1;
540 }
541
542
543 if(emhad>=1){
544 lodiff = cellphi-h2map[j][0]->GetYaxis()->GetBinLowEdge(
binphidqm1);
545 updiff = cellphi-h2map[j][0]->GetYaxis()->GetBinUpEdge(
binphidqm1);
546 Bool_t loedge = (fabs(lodiff) < 1
e-5) ? 1 : 0;
547 Bool_t upedge = (fabs(updiff) < 1
e-5) ? 1 : 0;
548
549 if(loedge || upedge){
551 phishifts++;
552
553
554 if(upedge){
563 success=1;
564 } else success = 0;
565 } else if(loedge){
574 success=1;
575 } else success = 0;
576 } else success = 0;
577 }
578 if(success) dupl+=1;
579 }
580 }
581
582
584
585 if(!success){
586 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",
588 h2map[j][0]->GetXaxis()->GetBinLowEdge(
binetadqm),h2map[j][0]->GetXaxis()->GetBinUpEdge(
binetadqm),
589 h2map[j][0]->GetYaxis()->GetBinLowEdge(
binphidqm1),h2map[j][0]->GetYaxis()->GetBinUpEdge(
binphidqm1),
593 );
594 }
595
596
598 nchannels+=1;
599 }
600
601
602
604 nbinsx = h2map[
i][0]->GetXaxis()->GetNbins();
605 nbinsy = h2map[
i][0]->GetYaxis()->GetNbins();
606 ntotal += nbinsx*nbinsy;
607 for(ix=0;ix<nbinsx;ix++){
608 for(iy=0;iy<nbinsy;iy++){
609 if(h2count[i][0]->GetBinContent(ix+1,iy+1)>1){
610 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));
611 dupl2+=1;
612 }
613
614 if(h2count[i][0]->GetBinContent(ix+1,iy+1)==0) empt+=1;
615 }
616 }
617 }
618
619
625
626 printf("-------------------------------------------------------------------\n");
627 printf("LArIdTranslatorHelper::MakeTranslatorMapping: Summary:\n");
628 printf("Info for %d channels (%d entries read).\n",nchannels,(int)idtree->GetEntries());
629 printf("There were %d duplicates, %d empty, %d (%d) phi-shifted (HEC-FCAL), %d physical.\n",dupl2,empt,dupl,phishifts,ntotal-empt-dupl);
630 printf("-------------------------------------------------------------------\n");
631
635 delete h2count[
i][j];
637 }
640 }
641 delete[] h2count;
642 delete[] h2map;
643 delete[] h2;
644 delete fdqm;
646 return;
647}
setScale setgFexType iEta