Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-19 07:40:50

0001 #pragma once
0002 #ifndef COMMONHELPERFUNCTIONS_H
0003 #define COMMONHELPERFUNCTIONS_H
0004 
0005   #include <iostream>
0006   #include <fstream>
0007   #include "TString.h"
0008   #include "TObjString.h"
0009   #include <vector>
0010   #include <map>
0011   #include <utility>
0012 
0013   #include <cstdint>
0014   #include <string>
0015   
0016   struct Layer{
0017     Layer(): nCells(0), energy(0.), avX(0.), avY(0.) {}
0018     double nCells;
0019     double energy;
0020     double avX;
0021     double avY;
0022   } ;
0023 
0024   inline int GetMaxLayer(std::map<int,Layer> layers){
0025     int maxLayer      = -1;
0026     double maxELayer  = 0;
0027     std::map<int, Layer>::iterator ithLayer;
0028     for(ithLayer=layers.begin(); ithLayer!=layers.end(); ++ithLayer){
0029       if (maxELayer < ithLayer->second.energy ){
0030         maxELayer = ithLayer->second.energy;
0031         maxLayer  = ithLayer->first;
0032       }
0033     }
0034     return maxLayer;
0035   }
0036   inline double GetAverageLayer(std::map<int,Layer> layers){
0037     double avLayer    = 0;
0038     double totE  = 0;
0039     std::map<int, Layer>::iterator ithLayer;
0040     for(ithLayer=layers.begin(); ithLayer!=layers.end(); ++ithLayer){
0041       avLayer +=   ithLayer->first*ithLayer->second.energy;
0042       totE    += ithLayer->second.energy;
0043     }
0044     avLayer = avLayer/totE;
0045     return avLayer;
0046   }
0047   
0048   inline double GetXAverage(std::map<int,Layer> layers, int layerMax = -100){
0049     double avLayer    = 0;
0050     double totE  = 0;
0051     std::map<int, Layer>::iterator ithLayer;
0052     for(ithLayer=layers.begin(); ithLayer!=layers.end(); ++ithLayer){
0053       if ((layerMax != -100) && (ithLayer->first > layerMax) )
0054         continue;
0055       avLayer += ithLayer->second.avX*ithLayer->second.energy;
0056       totE    += ithLayer->second.energy;
0057     }
0058     avLayer = avLayer/totE;
0059     return avLayer;
0060   }
0061 
0062   inline double GetYAverage(std::map<int,Layer> layers, int layerMax = -100){
0063     double avLayer    = 0;
0064     double totE  = 0;
0065     std::map<int, Layer>::iterator ithLayer;
0066     for(ithLayer=layers.begin(); ithLayer!=layers.end(); ++ithLayer){
0067       if ( (layerMax !=-100) && (ithLayer->first > layerMax) )
0068         continue;
0069       avLayer += ithLayer->second.avY*ithLayer->second.energy;
0070       totE    += ithLayer->second.energy;
0071     }
0072     avLayer = avLayer/totE;
0073     return avLayer;
0074   }
0075   
0076   struct RunInfo{
0077     RunInfo(): runNr(0), species(""), pdg(0), energy(0), vop(0), vbr(0), lgSet(0), hgSet(0), posX(0), posY(0), shapetime(0), assemblyNr(0), year(-1), month(-1), detector(""), readout(""), facility(""), beamline(""), samples(0), trigDelay(0), trigDead(0), phase(0), nFPGA(0), nASIC(0), rf(12), cf(10), cc(12), cfcomp(10), temp(20.), injMode(0), injDAC(0) {}
0078     int runNr;
0079     TString species;
0080     int pdg;
0081     float energy;
0082     float vop;
0083     float vbr;
0084     int lgSet;
0085     int hgSet;
0086     float posX;
0087     float posY;
0088     float shapetime;
0089     int assemblyNr;
0090     int year;
0091     int month;
0092     TString detector;
0093     TString readout;
0094     TString facility;
0095     TString beamline;
0096     int samples;
0097     int trigDelay;
0098     int trigDead;
0099     int phase;
0100     int nFPGA;
0101     int nASIC;
0102     int rf;
0103     int cf;
0104     int cc; 
0105     int cfcomp;
0106     float temp;
0107     int injMode;  // 0: low, 1: high, 2:2.5V
0108     double injDAC;
0109   } ;
0110 
0111   TString GetStringFromRunInfo(RunInfo, Int_t);
0112 
0113   //__________________________________________________________________________________________________________
0114   //__________________ Read run infos from text file _________________________________________________________
0115   //__________________________________________________________________________________________________________    
0116   // specialData: 0 - std. TB, 1 - SPE data ORNL
0117   inline std::map<int,RunInfo> readRunInfosFromFile(TString runListFileName, int debug, int specialData = 0 ){
0118     std::map<int,RunInfo> runs;
0119     //std::cout << "INFO: You have given the following run list file: " << runListFileName.Data() << std::endl;
0120     std::ifstream runListFile;
0121     runListFile.open(runListFileName,std::ios_base::in);
0122     if (!runListFile) {
0123       std::cout << "ERROR:  runlist file " << runListFileName.Data() << " not found!" << std::endl;
0124       return runs;
0125     }
0126 
0127     TString facility="";
0128     TString beamline="";
0129     TString readout="";
0130     TString detector="LFHCal";
0131     int year = -1;
0132     int month = -1;
0133     for( TString tempLine; tempLine.ReadLine(runListFile, kTRUE); ) {
0134       // check if line should be considered
0135       if (tempLine.BeginsWith("%") || tempLine.BeginsWith("#")){
0136         continue;
0137       }
0138       if (debug > 1) std::cout << tempLine.Data() << std::endl;
0139       
0140       TObjArray *tempArr2  = tempLine.Tokenize(" ");
0141       if(tempArr2->GetEntries()>0){
0142         if (tempLine.BeginsWith("year")){
0143           year=((TString)((TObjString*)tempArr2->At(1))->GetString()).Atoi();
0144           continue;
0145         } else if (tempLine.BeginsWith("month")){
0146           month=((TString)((TObjString*)tempArr2->At(1))->GetString()).Atoi();
0147           continue;
0148         } else if (tempLine.BeginsWith("readout")){
0149           readout=((TString)((TObjString*)tempArr2->At(1))->GetString());
0150           continue;
0151         } else if (tempLine.BeginsWith("facility")){
0152           facility=((TString)((TObjString*)tempArr2->At(1))->GetString());
0153           continue;
0154         } else if (tempLine.BeginsWith("beam-line")){ 
0155           beamline=((TString)((TObjString*)tempArr2->At(1))->GetString());
0156           continue;
0157         } else if (tempLine.BeginsWith("detector")){ 
0158           detector=((TString)((TObjString*)tempArr2->At(1))->GetString());
0159           continue;
0160         }
0161       }
0162       
0163       // Separate the string according to tabulators
0164       TObjArray *tempArr  = tempLine.Tokenize(",");
0165       if(tempArr->GetEntries()<1){
0166         if (debug > 1) std::cout << "nothing to be done" << std::endl;
0167         delete tempArr;
0168         continue;
0169       } 
0170 
0171       // Put them to the correct variables    
0172       RunInfo tempRun;
0173       tempRun.detector= detector;
0174       tempRun.facility= facility;
0175       tempRun.beamline= beamline;
0176       tempRun.readout = readout;
0177       tempRun.year    = year; 
0178       tempRun.month    = month; 
0179       
0180       // normal run 
0181       if (beamline.CompareTo("injection") != 0){
0182         tempRun.runNr    = ((TString)((TObjString*)tempArr->At(0))->GetString()).Atoi();
0183         tempRun.species  =  (TString)((TObjString*)tempArr->At(1))->GetString();
0184         tempRun.pdg      = ((TString)((TObjString*)tempArr->At(2))->GetString()).Atoi();
0185         tempRun.energy   = ((TString)((TObjString*)tempArr->At(3))->GetString()).Atof();
0186         tempRun.vop      = ((TString)((TObjString*)tempArr->At(4))->GetString()).Atof();
0187         tempRun.vbr      = ((TString)((TObjString*)tempArr->At(5))->GetString()).Atof();
0188         tempRun.temp      = -1.; // set default (might be overwritten)
0189         
0190         if (readout.CompareTo("CAEN") == 0){
0191           tempRun.hgSet    = ((TString)((TObjString*)tempArr->At(6))->GetString()).Atoi();
0192           tempRun.lgSet    = ((TString)((TObjString*)tempArr->At(7))->GetString()).Atoi();
0193           if (tempArr->GetEntries() > 10 & tempRun.year < 2024){
0194             tempRun.shapetime = ((TString)((TObjString*)tempArr->At(10))->GetString()).Atof();
0195           } else {
0196             tempRun.temp      = ((TString)((TObjString*)tempArr->At(10))->GetString()).Atof();
0197             tempRun.shapetime = ((TString)((TObjString*)tempArr->At(11))->GetString()).Atof();
0198           }
0199         } else {
0200           tempRun.trigDelay = ((TString)((TObjString*)tempArr->At(6))->GetString()).Atoi();
0201           tempRun.samples   = ((TString)((TObjString*)tempArr->At(7))->GetString()).Atoi();
0202           tempRun.trigDead  = ((TString)((TObjString*)tempArr->At(10))->GetString()).Atoi();
0203           tempRun.phase     = ((TString)((TObjString*)tempArr->At(11))->GetString()).Atoi();
0204           tempRun.nFPGA     = ((TString)((TObjString*)tempArr->At(12))->GetString()).Atoi();
0205           tempRun.nASIC     = ((TString)((TObjString*)tempArr->At(13))->GetString()).Atoi();
0206         }
0207         tempRun.posX    = ((TString)((TObjString*)tempArr->At(8))->GetString()).Atoi();
0208         tempRun.posY    = ((TString)((TObjString*)tempArr->At(9))->GetString()).Atoi();
0209         if (specialData == 1) tempRun.assemblyNr = ((TString)((TObjString*)tempArr->At(10))->GetString()).Atoi();
0210         
0211         if (tempRun.year > 2025){
0212           tempRun.temp      = ((TString)((TObjString*)tempArr->At(14))->GetString()).Atof();
0213           tempRun.rf        = ((TString)((TObjString*)tempArr->At(15))->GetString()).Atoi();
0214           tempRun.cf        = ((TString)((TObjString*)tempArr->At(16))->GetString()).Atoi();
0215           tempRun.cc        = ((TString)((TObjString*)tempArr->At(17))->GetString()).Atoi();
0216           tempRun.cfcomp    = ((TString)((TObjString*)tempArr->At(18))->GetString()).Atoi();
0217         } else {
0218           tempRun.rf        = 12;
0219           tempRun.cf        = 10;
0220           tempRun.cc        = 12;
0221           tempRun.cfcomp    = 10;
0222         }
0223         
0224         tempRun.injMode   = -1;
0225         tempRun.injDAC    = -1;
0226        
0227         if (debug > 1) std::cout << "Run " << tempRun.runNr << "\t species: " << tempRun.species << "\t energy: "  << tempRun.energy << "\t Vop: " << tempRun.vop << "\t Vov: " << tempRun.vop-tempRun.vbr << "\t Xbeam: " << tempRun.posX<< "\t Ybeam: " << tempRun.posY << "\t shaping time: " << tempRun.shapetime << std::endl;
0228   
0229       // injection tests
0230       } else {
0231         tempRun.runNr    = ((TString)((TObjString*)tempArr->At(0))->GetString()).Atoi();
0232         tempRun.species  =  (TString)((TObjString*)tempArr->At(1))->GetString();
0233         tempRun.pdg      = 0;
0234         tempRun.energy   = 0.;
0235         tempRun.vop      = ((TString)((TObjString*)tempArr->At(2))->GetString()).Atof();
0236         tempRun.vbr      = ((TString)((TObjString*)tempArr->At(3))->GetString()).Atof();
0237         tempRun.posX     = 0.;
0238         tempRun.posY     = 0.;
0239         tempRun.samples   = ((TString)((TObjString*)tempArr->At(4))->GetString()).Atoi();
0240         tempRun.trigDelay = 0;
0241         tempRun.trigDead  = ((TString)((TObjString*)tempArr->At(5))->GetString()).Atoi();
0242         tempRun.phase     = ((TString)((TObjString*)tempArr->At(6))->GetString()).Atoi();
0243         tempRun.nFPGA     = ((TString)((TObjString*)tempArr->At(7))->GetString()).Atoi();
0244         tempRun.nASIC     = ((TString)((TObjString*)tempArr->At(8))->GetString()).Atoi();
0245         tempRun.rf        = ((TString)((TObjString*)tempArr->At(9))->GetString()).Atoi();
0246         tempRun.cf        = ((TString)((TObjString*)tempArr->At(10))->GetString()).Atoi();
0247         tempRun.cc        = ((TString)((TObjString*)tempArr->At(11))->GetString()).Atoi();
0248         tempRun.cfcomp    = ((TString)((TObjString*)tempArr->At(12))->GetString()).Atoi();
0249         tempRun.temp      = 20.;
0250         tempRun.injMode   = ((TString)((TObjString*)tempArr->At(13))->GetString()).Atoi();
0251         tempRun.injDAC    = ((TString)((TObjString*)tempArr->At(14))->GetString()).Atoi();
0252         if (debug > 1) std::cout << "Run " << tempRun.runNr << "\t type: " << tempRun.species << "\t Vop: " << tempRun.vop << "\t Vov: " << tempRun.vop-tempRun.vbr << "\t RF: " << tempRun.rf <<"\t CF: " << tempRun.cf<< "\t CC: " << tempRun.cc<< "\t CFcomp: "<< tempRun.cfcomp<< "\t inj mode: " << tempRun.injMode<< "\t inj value: "<< tempRun.injDAC<< std::endl;
0253       }
0254       runs[tempRun.runNr]=tempRun;
0255     }
0256     std::cout << year << "-" << month << "\t:\t" << facility.Data() << "-" << beamline.Data() << "\t Readout: " << readout.Data() << std::endl;
0257     std::cout << "registered " << runs.size() << " runs from  "<< runListFileName.Data() << std::endl;
0258     
0259     return runs;
0260   };
0261 
0262   inline int GetSpeciesIntFromRunInfo(RunInfo currRunInfo){
0263       if (currRunInfo.species.Contains("cosmics")){
0264           return  0; // cosmics
0265       } else if (currRunInfo.species.CompareTo("g") == 0){
0266           return  1; // gamma
0267       } else if (currRunInfo.species.Contains("muon") || currRunInfo.species.Contains("Muon") || currRunInfo.species.CompareTo("mu-") == 0){
0268           return  2; // muon
0269       } else if (currRunInfo.species.Contains("Electron") || currRunInfo.species.Contains("electron") || currRunInfo.species.CompareTo("e-") == 0 ){
0270           return  3; // electron
0271       } else if (currRunInfo.species.Contains("Positron") || currRunInfo.species.Contains("positron") || currRunInfo.species.CompareTo("e+") == 0 ){
0272           return  6; // positron
0273       } else if (currRunInfo.species.Contains("Pion") || currRunInfo.species.Contains("pion") || currRunInfo.species.CompareTo("pi-") == 0 || currRunInfo.species.CompareTo("pi+") == 0 ){
0274           return  4; // pion
0275       } else if (currRunInfo.species.Contains("Hadron") || currRunInfo.species.Contains("hadron") || currRunInfo.species.CompareTo("h+") == 0 || currRunInfo.species.CompareTo("h-") == 0 ){
0276           return  5; // hadron/proton
0277       }
0278       
0279       return -1;
0280   }
0281 
0282   inline TString GetSpeciesStringFromPDG(int pdg){
0283     switch (pdg){
0284       case 0:
0285         return "ped";
0286       case 11:
0287         return "e^{-}";
0288       case -11:
0289         return "e^{+}";
0290       case 13:
0291         return "#mu^{-}";
0292       case -13:
0293         return "#mu^{+}";
0294       case 211:
0295         return "#pi^{+}";
0296       case -211:
0297         return "#pi^{-}";
0298       case 2212:
0299         return "p";
0300       case -2212:
0301         return "#bar{p}";
0302       default: 
0303         return "";
0304     }
0305   }
0306     
0307   inline Double_t ReturnMipPlotRangeDepVov(double Vov, bool isHG, ReadOut::Type type){
0308     if (type == ReadOut::Type::Caen){
0309       if (isHG){
0310         if (Vov < 2)
0311           return 550.;
0312         else if (Vov < 3)
0313           return 750.;
0314         else if (Vov < 4)
0315           return 950.;
0316         else if (Vov < 5)
0317           return 1150.;
0318         else
0319           return 1350.;
0320       } else {
0321         if (Vov < 2)
0322           return 85.;
0323         else if (Vov < 3)
0324           return 105.;
0325         else if (Vov < 4)
0326           return 125.;
0327         else if (Vov < 5)
0328           return 145.;
0329         else
0330           return 165.;      
0331       }
0332     } else {
0333       return 250.;
0334     }
0335   }
0336 
0337   inline Double_t ReturnMipMinPlotRangeDepVov(double Vov, bool isHG, ReadOut::Type type){
0338     if (type == ReadOut::Type::Caen){
0339       if (isHG){
0340         return -100;
0341       } else {
0342         return -100;
0343       }
0344     } else {
0345       return -25.;
0346     }
0347   }
0348   
0349   inline Double_t ReturnRFValue(int rf, int debug = 0){
0350     if (debug) std::cout << "RF:  " << rf ;
0351     Double_t rfOhm = 0;
0352     Double_t ohmBit[4]  = {80., 40., 20., 10.}; // documentation version SiPM H2GCROC3b
0353     // Double_t ohmBit[4]  = {100., 66.66, 50., 25.}; // documentation version 1_4
0354     if ((rf - 8) >= 0){
0355       rfOhm = rfOhm+1/ohmBit[3];
0356       rf = rf-8;
0357     }  
0358     if ((rf - 4) >= 0){
0359       rfOhm = rfOhm+1/ohmBit[2];
0360       rf = rf-4;
0361     }  
0362     if ((rf - 2) >= 0){
0363       rfOhm = rfOhm+1/ohmBit[1];
0364       rf = rf-2;
0365     }  
0366     if ((rf - 1) == 0){
0367       rfOhm = rfOhm+1/ohmBit[0];
0368       rf = rf-1;
0369     }
0370     if (debug) std::cout << "\t" << rfOhm << " kOhm" << std::endl;
0371     return 1./rfOhm;
0372   }
0373   
0374   inline Double_t ReturnCFValue(int cf, int debug = 0){
0375     if (debug) std::cout << "CF:  " << cf ;
0376     Double_t cffF = 0;
0377     if ((cf - 8) >= 0){
0378       cffF = cffF+400;
0379       cf = cf-8;
0380     }  
0381     if ((cf - 4) >= 0){
0382       cffF = cffF+200;
0383       cf = cf-4;
0384     }  
0385     if ((cf - 2) >= 0){
0386       cffF = cffF+100;
0387       cf = cf-2;
0388     }  
0389     if ((cf - 1) == 0){
0390       cffF = cffF+50;
0391       cf = cf-1;
0392     }
0393     if (debug) std::cout << "\t" << cffF << " fF" << std::endl;
0394     return cffF;
0395   }
0396   
0397   inline Double_t ReturnCFCompValue(int cf, int debug = 0){
0398     if (debug) std::cout << "CFComp:  " << cf ;
0399     Double_t cffF = 0;
0400     if ((cf - 8) >= 0){
0401       cffF = cffF+400;
0402       cf = cf-8;
0403     }  
0404     if ((cf - 4) >= 0){
0405       cffF = cffF+200;
0406       cf = cf-4;
0407     }  
0408     if ((cf - 2) >= 0){
0409       cffF = cffF+100;
0410       cf = cf-2;
0411     }  
0412     if ((cf - 1) == 0){
0413       cffF = cffF+50;
0414       cf = cf-1;
0415     }
0416     if (debug) std::cout << "\t" << cffF << " fF" << std::endl;
0417     return cffF;
0418   }
0419   
0420   inline Double_t ReturnCCValue(int cc, int debug = 0){
0421     if (debug) std::cout << "CC:  " << cc ;
0422     Double_t ccVal = 0;
0423     if ((cc - 8) >= 0){
0424       ccVal = ccVal+0.2;
0425       cc = cc-8;
0426     }  
0427     if ((cc - 4) >= 0){
0428       ccVal = ccVal+0.1;
0429       cc = cc-4;
0430     }  
0431     if ((cc - 2) >= 0){
0432       ccVal = ccVal+0.05;
0433       cc = cc-2;
0434     }  
0435     if ((cc - 1) == 0){
0436       ccVal = ccVal+0.025;
0437       cc = cc-1;
0438     }
0439     if (debug) std::cout << "\t" << ccVal  << std::endl;
0440     return ccVal;
0441   }
0442   
0443   inline double GetInjectionfCEquivalent(double dac, int range){
0444     if (range == 0){
0445       return dac*500./4095;  //maximum injected charge 500fC, max dac = 4095
0446     } else if (range == 1){
0447       return dac*8000./4095;  //maximum injected charge 8000fC, max dac = 4095
0448     }
0449     return -1;
0450   }
0451   
0452   inline TString GetLabelHGCROCSettings(RunInfo currRunInfo){
0453     TString label = "";
0454     if (currRunInfo.rf > -10000.)
0455       label = Form("%sRF=%.1fk#Omega ",label.Data() , ReturnRFValue(currRunInfo.rf));
0456     if (currRunInfo.cf > -10000.)
0457       label = Form("%sCF=%.1ffF ",label.Data() , ReturnCFValue(currRunInfo.cf));
0458     if (currRunInfo.cfcomp > -10000.)
0459       label = Form("%sCF_{comp}=%.1ffF ",label.Data() , ReturnCFCompValue(currRunInfo.cfcomp));
0460     if (currRunInfo.cc > -10000.)
0461       label = Form("%sCC=%.3f",label.Data() , ReturnCCValue(currRunInfo.cc));
0462     return label;
0463   }
0464   inline TString GetLabelHGCROCSettingsCF(RunInfo currRunInfo){
0465     TString label = "";
0466     if (currRunInfo.cf > -10000.)
0467       label = Form("%sCF=%.1ffF ",label.Data() , ReturnCFValue(currRunInfo.cf));
0468     if (currRunInfo.cfcomp > -10000.)
0469       label = Form("%sCF_{comp}=%.1ffF",label.Data() , ReturnCFCompValue(currRunInfo.cfcomp));
0470     return label;
0471   }
0472   
0473   inline TString GetLabelHGCROCSettingsRFCC(RunInfo currRunInfo){
0474     TString label = "";
0475     if (currRunInfo.rf > -10000.)
0476       label = Form("%sRF=%.1fk#Omega ",label.Data() , ReturnRFValue(currRunInfo.rf));
0477     if (currRunInfo.cc > -10000.)
0478       label = Form("%sCC=%.3f",label.Data() , ReturnCCValue(currRunInfo.cc));
0479     return label;
0480   }
0481   
0482   inline TString GetLabelVoltageTemp(RunInfo currRunInfo){
0483     TString label = "";
0484     if (currRunInfo.vop > -10000.)
0485       label = Form("%sV_{op}=%.1f V ",label.Data() , currRunInfo.vop);
0486     if (currRunInfo.temp > -10000.)
0487       label = Form("%s T=%.1f C",label.Data() , currRunInfo.temp);
0488     if (currRunInfo.energy > -10000. && currRunInfo.species.Contains("laser"))
0489       label = Form("%s I_{laser}=%.0f",label.Data() , currRunInfo.energy);
0490     else if (currRunInfo.energy > -10000.)
0491       label = Form("%s E=%.1f GeV",label.Data() , currRunInfo.energy);
0492     
0493     return label;
0494   }
0495   
0496 
0497   inline void PrintSettingsRunInfo(RunInfo currRunInfo){
0498     TString label = "";
0499     if (currRunInfo.injDAC > -1)
0500       label = Form("%sinj=%.1ffC ", label.Data(), GetInjectionfCEquivalent(currRunInfo.injDAC,currRunInfo.injMode));
0501     if (currRunInfo.rf > -1)
0502       label = Form("%sRF=%.1fk#Omega ",label.Data() , ReturnRFValue(currRunInfo.rf));
0503     if (currRunInfo.cc > -1)
0504       label = Form("%sCC=%.3f ",label.Data() , ReturnCCValue(currRunInfo.cc));
0505     if (currRunInfo.cfcomp > -1)
0506       label = Form("%sCF_{comp}=%.1ffF ",label.Data() , ReturnCFCompValue(currRunInfo.cfcomp));
0507     if (currRunInfo.cf > -1)
0508       label = Form("%sCF=%.1ffF ",label.Data() , ReturnCFValue(currRunInfo.cf));
0509     std::cout<< label.Data() << std::endl;
0510     return;
0511   }
0512 
0513   inline RunInfo GetCommonRunInfoFromList( std::vector<RunInfo> runList, Int_t option = -1){
0514     
0515     bool isSameVoltage    = true;
0516     double commonVoltage  = runList.at(0).vop;
0517     bool isSameRF         = true;
0518     bool isSameCF         = true;
0519     bool isSameCFcomp     = true;
0520     bool isSameCC         = true;
0521     bool isSameInj        = true;
0522     bool isSameTemp       = true;
0523     bool isSameE          = true;
0524     double commonRF       = runList.at(0).rf;
0525     double commonCF       = runList.at(0).cf;
0526     double commonCFcomp   = runList.at(0).cfcomp;
0527     double commonCC       = runList.at(0).cc;
0528     double commonInj      = (double)GetInjectionfCEquivalent(runList.at(0).injDAC, runList.at(0).injMode); 
0529     double commonTemp     = runList.at(0).temp;
0530     double commonE        = runList.at(0).energy;
0531 
0532     std::cout << runList.at(0).runNr << "\t"<<  commonVoltage << "\t" << commonE << "\t"<< commonTemp << "\t Sett: "<< commonRF << "\t" << commonCF << "\t"<< commonCC << "\t" << commonCFcomp << "\tinj:"<< commonInj << std::endl;
0533     
0534     for (Int_t r = 1; r< (int)runList.size(); r++){
0535       if (commonVoltage != runList.at(r).vop)   isSameVoltage = false;
0536       if (commonRF != runList.at(r).rf)         isSameRF      = false;
0537       if (commonCF != runList.at(r).cf)         isSameCF      = false;
0538       if (commonCFcomp != runList.at(r).cfcomp)    isSameCFcomp  = false;
0539       if (commonCC != runList.at(r).cc)         isSameCC      = false;
0540       double currentInj = (double)GetInjectionfCEquivalent(runList.at(r).injDAC, runList.at(r).injMode);
0541       if (commonInj != currentInj)              isSameInj     = false;
0542       if (commonE   != runList.at(r).energy)    isSameE       = false;
0543       if (commonTemp   != runList.at(r).temp)   isSameTemp    = false;
0544       std::cout << runList.at(r).runNr << "\t" <<  runList.at(r).vop << "\t" << runList.at(r).energy << "\t"<< runList.at(r).temp << "\t Sett: "<< runList.at(r).rf << "\t" << runList.at(r).cf << "\t"<<  runList.at(r).cc << "\t" << runList.at(r).cfcomp << "\tinj:"<< currentInj << std::endl;
0545     }
0546     
0547     std::cout << "Show all common settings" << std::endl;
0548     std::cout << "Common Voltage: "<< isSameVoltage << "\t"  << commonVoltage
0549               << "\t RF: " << isSameRF << "\t"  << commonRF
0550               << "\t CF: " << isSameCF << "\t"  << commonCF 
0551               << "\t CFcomp: " << isSameCFcomp << "\t"  << commonCFcomp 
0552               << "\t CC: " << isSameCC << "\t"  << commonCC 
0553               << "\t E: " << isSameE << "\t"  << commonE 
0554               << "\t T: " << isSameTemp << "\t"  << commonTemp 
0555               << "\t Inj: " << isSameInj << "\t"  << commonInj 
0556               << std::endl;
0557     
0558     RunInfo commonRunInfo;
0559     commonRunInfo.nFPGA       = runList.at(0).nFPGA;
0560     commonRunInfo.nASIC       = runList.at(0).nASIC;
0561     commonRunInfo.pdg         = runList.at(0).pdg;
0562     commonRunInfo.species     = runList.at(0).species;
0563     commonRunInfo.detector    = runList.at(0).detector;
0564     commonRunInfo.beamline    = runList.at(0).beamline;
0565     commonRunInfo.facility    = runList.at(0).facility;
0566     commonRunInfo.readout     = runList.at(0).readout;
0567     commonRunInfo.month       = runList.at(0).month;
0568     commonRunInfo.year        = runList.at(0).year;
0569     commonRunInfo.samples     = runList.at(0).samples;
0570     commonRunInfo.vbr         = runList.at(0).vbr;
0571   
0572     if (isSameRF)
0573       commonRunInfo.rf        = commonRF;
0574     else 
0575       commonRunInfo.rf        = -10000.;
0576     if (isSameCF)
0577       commonRunInfo.cf        = commonCF;
0578     else 
0579       commonRunInfo.cf        = -10000.;
0580     if (isSameCFcomp)
0581       commonRunInfo.cfcomp    = commonCFcomp;
0582     else 
0583       commonRunInfo.cfcomp    = -10000.;
0584     if (isSameCC)
0585       commonRunInfo.cc        = commonCC;
0586     else 
0587       commonRunInfo.cc        = -10000.;
0588     if (isSameVoltage)
0589       commonRunInfo.vop       = commonVoltage;
0590     else 
0591       commonRunInfo.vop       = -10000.;
0592     
0593     if (isSameInj)
0594       commonRunInfo.injDAC    = commonInj;
0595     else 
0596       commonRunInfo.injDAC    = -10000.;
0597     
0598     if (isSameE)
0599       commonRunInfo.energy    = commonE;
0600     else 
0601       commonRunInfo.energy    = -10000.;
0602 
0603     if (isSameTemp)
0604       commonRunInfo.temp    = commonTemp;
0605     else 
0606       commonRunInfo.temp    = -10000.;
0607 
0608     return commonRunInfo;
0609     
0610   }
0611 
0612   inline Int_t GetNSameSettings(RunInfo currRunInfo){
0613     Int_t nSameSettings = 0;
0614     if (currRunInfo.species.Contains("injection")){
0615       if (currRunInfo.rf > -10000.) nSameSettings++;
0616       if (currRunInfo.cf > -10000.) nSameSettings++;
0617       if (currRunInfo.cfcomp > -10000.) nSameSettings++;
0618       if (currRunInfo.cc > -10000.) nSameSettings++;
0619       if (currRunInfo.vop > -10000.) nSameSettings++;
0620       if (currRunInfo.injDAC > -10000.) nSameSettings++;
0621       if (currRunInfo.energy > -10000.) nSameSettings++;
0622     } else if (currRunInfo.species.Contains("laser")){
0623       if (currRunInfo.energy > -10000.) nSameSettings++;
0624       if (currRunInfo.temp > -10000.) nSameSettings++;
0625       if (currRunInfo.vop > -10000.) nSameSettings++;
0626     }
0627     return nSameSettings;
0628   }
0629 
0630   
0631   inline TString GetHeaderLegendCommonRunObject (RunInfo currRunInfo, int nSameSettings, double &width, int &columns, double labelScale  ){
0632     TString header = "";
0633     if (currRunInfo.species.Contains("injection")){
0634       if (nSameSettings == 6){
0635           // width = 0.9;
0636           // std::cout <<  currRunInfo.rf << "\t" << currRunInfo.cf << "\t" << currRunInfo.cfcomp << "\t" << currRunInfo.cc << "\t" << currRunInfo.vop << "\t" << currRunInfo.energy << std::endl;
0637           if (currRunInfo.rf < -9999) header = "RF (k#Omega)";
0638           if (currRunInfo.cf < -9999) header = "CF (fF)";
0639           if (currRunInfo.cfcomp < -9999) header = "CF_{comp} (fF)";
0640           if (currRunInfo.cc < -9999)  header = "CC";
0641           if (currRunInfo.vop < -9999)  header = "V_{op} (V)";
0642           if (currRunInfo.injDAC < -9999)  header = "inj (fC)";
0643           if (currRunInfo.energy < -9999)  header = "E ";
0644       } else if (nSameSettings == 5){
0645           // width = 0.9;
0646           columns = 2;
0647           labelScale = 0.6;
0648           // std::cout <<  currRunInfo.rf << "\t" << currRunInfo.cf << "\t" << currRunInfo.cfcomp << "\t" << currRunInfo.cc << "\t" << currRunInfo.vop << "\t" << currRunInfo.energy << std::endl;
0649           if (currRunInfo.rf < -9999)       header = "RF (k#Omega) ";
0650           if (currRunInfo.cf < -9999)       header = header+"CF (fF) ";
0651           if (currRunInfo.cfcomp < -9999)   header = header+"CF_{comp} (fF) ";
0652           if (currRunInfo.cc < -9999)       header = header+"CC ";
0653           if (currRunInfo.vop < -9999)      header = header+"V_{op} (V) ";
0654           if (currRunInfo.injDAC < -9999)   header = header+"inj (fC) ";      
0655           if (currRunInfo.energy < -9999)   header = header+"E  ";      
0656       }
0657     } else if (currRunInfo.species.Contains("laser")){
0658       if (currRunInfo.energy < -9999)       header = header+"Laser Intensity  ";
0659       if (currRunInfo.temp < -9999)         header = header+"Temperature (#circ C) ";
0660     }
0661     return header;
0662   }
0663   
0664   
0665   // // Function to generate the CRC-32 lookup table at runtime (or compile time with C++11 constexpr)
0666   // void generate_crc32_table(uint32_t(&table)[256]) {
0667   //     uint32_t polynomial = 0x104C11DB7; // Common CRC-32 polynomial
0668   //     for (uint32_t i = 0; i < 256; i++) {
0669   //         uint32_t c = i;
0670   //         for (size_t j = 0; j < 8; j++) {
0671   //             if (c & 1) {
0672   //                 c = polynomial ^ (c >> 1);
0673   //             } else {
0674   //                 c >>= 1;
0675   //             }
0676   //         }
0677   //         table[i] = c;
0678   //     }
0679   // }
0680   // 
0681   // // Function to calculate the CRC-32 checksum for a buffer
0682   // uint32_t calculate_crc32(const uint8_t* data, size_t length) {
0683   //     uint32_t crc = 0x0;           // Initial value (standard for HGCROC)
0684   //     // uint32_t crc = 0xFFFFFFFF; // Initial value (standard for CRC-32)
0685   //     uint32_t table[256];
0686   //     generate_crc32_table(table);
0687   // 
0688   //     for (size_t i = 0; i < length; ++i) {
0689   //         crc = table[(crc ^ data[i]) & 0xFF] ^ (crc >> 8);
0690   //     }
0691   // 
0692   //     return crc ^ 0xFFFFFFFF; // Final XOR (standard for CRC-32)
0693   // }  
0694 
0695   // Usage CRC
0696   // std::string message = "123456789"; // Standard test string for CRC-32 check value
0697   // The expected CRC-32 result for this string is 0xCBF43926
0698   //  uint32_t checksum = calculate_crc32(reinterpret_cast<const uint8_t*>(message.c_str()), message.length());
0699   //  std::cout << "CRC-32 Checksum: 0x" << std::hex << std::uppercase << checksum << std::endl;
0700 
0701   
0702 #endif