3434// double getCorr(entry): Entry # (in the file) dependent correction
3535// bool absent(entry) : if correction factor absent
3636// bool present(entry): or present (relevant for ML motivated)
37+ // double getPhiCorr(unsigned int id): correction factor from phi
38+ // symmery studies
39+ // double getPhiCorrs(int run, unsigned int id): era-dependent correction
40+ // factor from phi symmetry studies
41+ // *infile* is the name of the input file
42+ // *flag* can have a value between 0:5 specifying the type of correction
43+ // 5 for run-dependent correctons using results from several phi
44+ // symmetry studies; 4 for using results from one phi-symmetry
45+ // study; 3 for pileup correction using machine learning method;
46+ // 2 for overall response corrections; 1 for depth dependence
47+ // corrections; 0 for raddam corrections)
3748// CalibSelectRBX(rbxFile, debug)
3849// A class for selecting a given set of Read Out Box's and provides
3950// bool isItRBX(detId): if it/they is in the chosen RBXs
4253// A class for either rejecting duplicate entries or giving depth
4354// dependent weight. flag is 0 for keeping a list of duplicate
4455// emtries; 1 is to keep depth dependent weight for each ieta;
45- // 2 is to keep a list of ieta, iphi for channels to be selected.
56+ // 2 is to keep a list of ieta, iphi for channels to be selected;
57+ // 3 is to read the gain correction file
4658// bool isDuplicate(entry): if it is a duplicate entry
4759// double getWeight(ieta, depth): get the dependent weight
4860// bool select(int ieta, int iphi): channels to be selected
61+ // double getCorr(int run, int ieta, int depth): correction factor
62+ // to modify the rechit energy due to change in gain fctor
4963// void CalibCorrTest(infile, flag)
5064// Tests a file which contains correction factors used by CalibCorr
65+ // if *flag* is >= 0; for negative values it initializes CalibDuplicate
66+ // with -flag and *debug* = tue
5167// void CalibCorrScale(infile, oufile, scale)
5268// Scales all contents of correction factors by "scale" from "infile"
5369// to "outfile"
@@ -591,16 +607,19 @@ public:
591607 double getCorr (const Long64_t & entry );
592608 double getTrueCorr (const Long64_t & entry );
593609 double getPhiCorr (unsigned int id );
610+ double getPhiCorrs (int run , unsigned int id );
594611 bool absent (const Long64_t & entry );
595612 bool absent () { return (good_ == 0 ); }
596613 bool present (const Long64_t & entry );
597614
598615private :
616+ unsigned int runId (const int & run );
599617 unsigned int readCorrRun (const char * infile );
600618 unsigned int readCorrDepth (const char * infile );
601619 unsigned int readCorrResp (const char * infile );
602620 unsigned int readCorrPU (const char * infile );
603621 unsigned int readCorrPhi (const char * infile );
622+ unsigned int readCorrPhis (const char * infile );
604623 unsigned int getDetIdHE (int ieta , int iphi , int depth );
605624 unsigned int getDetId (int subdet , int ieta , int iphi , int depth );
606625 unsigned int correctDetId (const unsigned int & detId );
@@ -613,6 +632,8 @@ private:
613632 std ::map < Long64_t , double > cfactors_ ;
614633 std ::vector < int > runlow_ ;
615634 std ::map < unsigned int , double > corrPhiSym_ ;
635+ std ::vector < std ::pair < int , int > > runs_ , ids_ ;
636+ std ::map < std ::pair < unsigned int , unsigned int > , double > corrPhiSyms_ ;
616637};
617638
618639class CalibSelectRBX {
@@ -636,15 +657,22 @@ public:
636657
637658 bool isDuplicate (long entry );
638659 double getWeight (const unsigned int );
639- bool doCorr () { return ((flag_ == 1 ) && ok_ ); }
660+ bool doCorr () { return (((flag_ == 1 ) || (flag_ == 3 )) && ok_ ); }
661+ bool doCorr (int flag ) { return ((flag_ == flag ) && ok_ ); }
640662 bool select (int ieta , int iphi );
663+ double getCorr (int run , int ieta , int depth );
641664
642665private :
666+ bool readCorrFactor (const char * fName );
667+ unsigned int runId (const int & run );
668+
643669 int flag_ ;
644670 double debug_ , ok_ ;
645671 std ::vector < Long64_t > entries_ ;
646672 std ::map < int , std ::vector < double > > weights_ ;
647673 std ::vector < std ::pair < int , int > > etaphi_ ;
674+ std ::vector < std ::pair < int , int > > runs_ , ids_ ;
675+ std ::map < std ::pair < int , int > , std ::vector < double > > corrs_ ;
648676};
649677
650678CalibCorrFactor ::CalibCorrFactor (const char * infile , int useScale , double scale , bool etamax , bool marina , bool debug )
@@ -758,6 +786,8 @@ CalibCorr::CalibCorr(const char* infile, int flag, bool debug) : flag_(flag), de
758786 good_ = readCorrPU (infile );
759787 else if (flag == 4 )
760788 good_ = readCorrPhi (infile );
789+ else if (flag == 5 )
790+ good_ = readCorrPhis (infile );
761791 else
762792 good_ = readCorrRun (infile );
763793}
@@ -776,9 +806,9 @@ float CalibCorr::getCorr(int run, unsigned int id) {
776806 if (itr != corrFacResp_ .end ())
777807 cfac = itr -> second ;
778808 } else if (flag_ == 4 ) {
779- std :: map < unsigned int , double > :: iterator itr = corrPhiSym_ . find (idx );
780- if (itr != corrPhiSym_ . end ())
781- cfac = itr -> second ;
809+ cfac = getPhiCorr (idx );
810+ } else if (flag_ == 5 ) {
811+ cfac = getPhiCorrs ( run , idx ) ;
782812 } else {
783813 int ip (- 1 );
784814 for (unsigned int k = 0 ; k < runlow_ .size (); ++ k ) {
@@ -842,6 +872,24 @@ double CalibCorr::getPhiCorr(unsigned int idx) {
842872 return cfac ;
843873}
844874
875+ double CalibCorr ::getPhiCorrs (int run , unsigned int idx ) {
876+ double cfac (1.0 );
877+ if (good_ == 0 )
878+ return cfac ;
879+ unsigned int runid = runId (run );
880+ std ::map < std ::pair < unsigned int , unsigned int > , double > ::iterator itr =
881+ corrPhiSyms_ .find (std ::pair < unsigned int , unsigned int > (runid , idx ));
882+ if (itr != corrPhiSyms_ .end ())
883+ cfac = itr -> second ;
884+ if (debug_ ) {
885+ int subdet , zside , ieta , iphi , depth ;
886+ unpackDetId (idx , subdet , zside , ieta , iphi , depth );
887+ std ::cout << "Run " << run << " ID " << runid << ":" << std ::hex << idx << std ::dec << " (Sub " << subdet << " eta "
888+ << zside * ieta << " phi " << iphi << " depth " << depth << ") Factor " << cfac << std ::endl ;
889+ }
890+ return cfac ;
891+ }
892+
845893bool CalibCorr ::absent (const Long64_t & entry ) { return (cfactors_ .find (entry ) == cfactors_ .end ()); }
846894
847895bool CalibCorr ::present (const Long64_t & entry ) { return (cfactors_ .find (entry ) != cfactors_ .end ()); }
@@ -1057,6 +1105,82 @@ unsigned int CalibCorr::readCorrPhi(const char* infile) {
10571105 return good ;
10581106}
10591107
1108+ unsigned int CalibCorr ::readCorrPhis (const char * infile0 ) {
1109+ std ::cout << "Enters readCorrPhis for " << infile0 << std ::endl ;
1110+ unsigned int all (0 ), good (0 );
1111+ std ::ifstream fIn (infile0 );
1112+ if (!fIn .good ()) {
1113+ std ::cout << "Cannot open file " << infile0 << std ::endl ;
1114+ } else {
1115+ char buffer0 [1024 ];
1116+ while (fIn .getline (buffer0 , 1024 )) {
1117+ std ::string bufferString0 (buffer0 );
1118+ if (bufferString0 .substr (0 , 1 ) == "#" ) {
1119+ continue ; //ignore other comments
1120+ } else {
1121+ std ::vector < std ::string > item = splitString (bufferString0 );
1122+ if (item .size () > 2 ) {
1123+ int run1 = std ::atoi (item [0 ].c_str ());
1124+ int run2 = std ::atoi (item [1 ].c_str ());
1125+ std ::string infile (item [2 ]);
1126+ unsigned int runid = runs_ .size ();
1127+ runs_ .push_back (std ::pair < int , int > (run1 , run2 ));
1128+ std ::ifstream fInput (infile .c_str ());
1129+ if (!fInput .good ()) {
1130+ std ::cout << "Cannot open file " << infile << std ::endl ;
1131+ } else {
1132+ char buffer [1024 ];
1133+ while (fInput .getline (buffer , 1024 )) {
1134+ ++ all ;
1135+ std ::string bufferString (buffer );
1136+ if (bufferString .substr (0 , 1 ) == "#" ) {
1137+ continue ; //ignore other comments
1138+ } else {
1139+ std ::vector < std ::string > items = splitString (bufferString );
1140+ if (items .size () < 5 ) {
1141+ std ::cout << "Ignore line: " << buffer << " Size " << items .size ();
1142+ for (unsigned int k = 0 ; k < items .size (); ++ k )
1143+ std ::cout << " [" << k << "] : " << items [k ];
1144+ std ::cout << std ::endl ;
1145+ } else {
1146+ ++ good ;
1147+ int subdet = std ::atoi (items [0 ].c_str ());
1148+ int ieta = std ::atoi (items [1 ].c_str ());
1149+ int iphi = std ::atoi (items [2 ].c_str ());
1150+ int depth = std ::atoi (items [3 ].c_str ());
1151+ double corrf = std ::atof (items [4 ].c_str ());
1152+ unsigned int id = packDetId (subdet , ieta , iphi , depth );
1153+ corrPhiSyms_ [std ::pair < int , int > (runid , id )] = corrf ;
1154+ if (debug_ )
1155+ std ::cout << "ID " << runid << ":" << std ::hex << id << std ::dec << ":" << id << " (subdet "
1156+ << subdet << " eta " << ieta << " phi " << iphi << " depth " << depth << ") "
1157+ << corrPhiSym_ [id ] << std ::endl ;
1158+ }
1159+ }
1160+ }
1161+ fInput .close ();
1162+ }
1163+ }
1164+ }
1165+ }
1166+ fIn .close ();
1167+ std ::cout << "Reads total of " << all << " and " << good << " good records of phi-symmetry factors from "
1168+ << runs_ .size () << " files as given in " << infile0 << std ::endl ;
1169+ }
1170+ return good ;
1171+ }
1172+
1173+ unsigned int CalibCorr ::runId (const int & run ) {
1174+ unsigned int id (runs_ .size ());
1175+ for (unsigned int k = 0 ; k < runs_ .size (); ++ k ) {
1176+ if ((run >= runs_ [k ].first ) && (run <= runs_ [k ].second )) {
1177+ id = k ;
1178+ break ;
1179+ }
1180+ }
1181+ return id ;
1182+ }
1183+
10601184unsigned int CalibCorr ::getDetIdHE (int ieta , int iphi , int depth ) { return getDetId (2 , ieta , iphi , depth ); }
10611185
10621186unsigned int CalibCorr ::getDetId (int subdet , int ieta , int iphi , int depth ) {
@@ -1256,6 +1380,8 @@ CalibDuplicate::CalibDuplicate(const char* fname, int flag, bool debug) : flag_(
12561380 ok_ = true;
12571381 }
12581382 }
1383+ } else if (flag_ == 3 ) {
1384+ ok_ = readCorrFactor (fname );
12591385 } else {
12601386 flag_ = 2 ;
12611387 if (strcmp (fname , "" ) != 0 ) {
@@ -1330,16 +1456,87 @@ bool CalibDuplicate::select(int ieta, int iphi) {
13301456 return flag ;
13311457}
13321458
1459+ double CalibDuplicate ::getCorr (int run , int ieta , int depth ) {
1460+ std ::map < std ::pair < int , int > , std ::vector < double > > ::const_iterator itr =
1461+ corrs_ .find (std ::pair < int , int > (ieta , depth ));
1462+ double corr (1.0 );
1463+ if (itr != corrs_ .end ()) {
1464+ unsigned int irun = runId (run );
1465+ corr = (itr -> second )[irun ];
1466+ }
1467+ return corr ;
1468+ }
1469+
1470+ bool CalibDuplicate ::readCorrFactor (const char * infile ) {
1471+ bool flag (false );
1472+ std ::ifstream fInput (infile );
1473+ if (!fInput .good ()) {
1474+ std ::cout << "CalibDuplicate::readCorrFactor:Cannot open file " << infile << std ::endl ;
1475+ } else {
1476+ int nrun , neta ;
1477+ fInput >> nrun >> neta ;
1478+ int indx , run1 , run2 ;
1479+ for (int k = 0 ; k < nrun ; ++ k ) {
1480+ fInput >> indx >> run1 >> run2 ;
1481+ runs_ .push_back (std ::pair < int , int > (run1 , run2 ));
1482+ }
1483+ int eta , depth ;
1484+ double corr ;
1485+ for (int k = 0 ; k < neta ; ++ k ) {
1486+ fInput >> eta >> depth ;
1487+ std ::vector < double > corrs ;
1488+ for (int i = 0 ; i < nrun ; ++ i ) {
1489+ fInput >> corr ;
1490+ corrs .push_back (corr );
1491+ }
1492+ corrs_ [std ::pair < int , int > (eta , depth )] = corrs ;
1493+ }
1494+ fInput .close ();
1495+ std ::cout << "CalibDuplicate::readCorrFactor:Reads information of " << runs_ .size () << " runs and " << corrs_ .size ()
1496+ << " channels from " << infile << std ::endl ;
1497+ flag = true;
1498+ if (debug_ ) {
1499+ for (unsigned int k = 0 ; k < runs_ .size (); ++ k )
1500+ std ::cout << "Run range[" << k << "] " << runs_ [k ].first << ":" << runs_ [k ].second << std ::endl ;
1501+ std ::map < std ::pair < int , int > , std ::vector < double > > ::const_iterator itr ;
1502+ for (itr = corrs_ .begin (); itr != corrs_ .end (); ++ itr ) {
1503+ std ::cout << "eta:depth [" << (itr -> first ).first << ":" << (itr -> first ).second << "]" ;
1504+ for (unsigned int i = 0 ; i < (itr -> second ).size (); ++ i )
1505+ std ::cout << " " << (itr -> second )[i ];
1506+ std ::cout << std ::endl ;
1507+ }
1508+ }
1509+ }
1510+ return flag ;
1511+ }
1512+
1513+ unsigned int CalibDuplicate ::runId (const int & run ) {
1514+ unsigned int id (runs_ .size ());
1515+ for (unsigned int k = 0 ; k < runs_ .size (); ++ k ) {
1516+ if ((run >= runs_ [k ].first ) && (run <= runs_ [k ].second )) {
1517+ id = k ;
1518+ break ;
1519+ }
1520+ }
1521+ return id ;
1522+ }
1523+
13331524void CalibCorrTest (const char * infile , int flag ) {
1334- CalibCorr * c1 = new CalibCorr (infile , flag , true);
1335- for (int ieta = 1 ; ieta < 29 ; ++ ieta ) {
1336- int subdet = (ieta > 16 ) ? 2 : 1 ;
1337- int depth = (ieta > 16 ) ? 2 : 1 ;
1338- unsigned int id1 = ((4 << 28 ) | ((subdet & 0x7 ) << 25 ));
1339- id1 |= ((0x1000000 ) | ((depth & 0xF ) << 20 ) | (ieta << 10 ) | 1 );
1340- c1 -> getCorr (0 , id1 );
1341- id1 |= (0x80000 );
1342- c1 -> getCorr (0 , id1 );
1525+ if (flag >= 0 ) {
1526+ CalibCorr * c1 = new CalibCorr (infile , flag , true);
1527+ for (int ieta = 1 ; ieta < 29 ; ++ ieta ) {
1528+ int subdet = (ieta > 16 ) ? 2 : 1 ;
1529+ int depth = (ieta > 16 ) ? 2 : 1 ;
1530+ unsigned int id1 = ((4 << 28 ) | ((subdet & 0x7 ) << 25 ));
1531+ id1 |= ((0x1000000 ) | ((depth & 0xF ) << 20 ) | (ieta << 10 ) | 1 );
1532+ c1 -> getCorr (0 , id1 );
1533+ id1 |= (0x80000 );
1534+ c1 -> getCorr (0 , id1 );
1535+ }
1536+ delete c1 ;
1537+ } else {
1538+ CalibDuplicate * c1 = new CalibDuplicate (infile , - flag , true);
1539+ delete c1 ;
13431540 }
13441541}
13451542
0 commit comments