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