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,22 @@ 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 = corrPhiSyms_ .find (std ::pair < unsigned int , unsigned int > (runid , idx ));
881+ if (itr != corrPhiSyms_ .end ())
882+ cfac = itr -> second ;
883+ if (debug_ ) {
884+ int subdet , zside , ieta , iphi , depth ;
885+ unpackDetId (idx , subdet , zside , ieta , iphi , depth );
886+ std ::cout << "Run " << run << " ID " << runid << ":" << std ::hex << idx << std ::dec << " (Sub " << subdet << " eta " << zside * ieta << " phi " << iphi << " depth " << depth << ") Factor " << cfac << std ::endl ;
887+ }
888+ return cfac ;
889+ }
890+
845891bool CalibCorr ::absent (const Long64_t & entry ) { return (cfactors_ .find (entry ) == cfactors_ .end ()); }
846892
847893bool CalibCorr ::present (const Long64_t & entry ) { return (cfactors_ .find (entry ) != cfactors_ .end ()); }
@@ -1057,6 +1103,79 @@ unsigned int CalibCorr::readCorrPhi(const char* infile) {
10571103 return good ;
10581104}
10591105
1106+ unsigned int CalibCorr ::readCorrPhis (const char * infile0 ) {
1107+ std ::cout << "Enters readCorrPhis for " << infile0 << std ::endl ;
1108+ unsigned int all (0 ), good (0 );
1109+ std ::ifstream fIn (infile0 );
1110+ if (!fIn .good ()) {
1111+ std ::cout << "Cannot open file " << infile0 << std ::endl ;
1112+ } else {
1113+ char buffer0 [1024 ];
1114+ while (fIn .getline (buffer0 , 1024 )) {
1115+ std ::string bufferString0 (buffer0 );
1116+ if (bufferString0 .substr (0 , 1 ) == "#" ) {
1117+ continue ; //ignore other comments
1118+ } else {
1119+ std ::vector < std ::string > item = splitString (bufferString0 );
1120+ if (item .size () > 2 ) {
1121+ int run1 = std ::atoi (item [0 ].c_str ());
1122+ int run2 = std ::atoi (item [1 ].c_str ());
1123+ std ::string infile (item [2 ]);
1124+ unsigned int runid = runs_ .size ();
1125+ runs_ .push_back (std ::pair < int , int > (run1 , run2 ));
1126+ std ::ifstream fInput (infile .c_str ());
1127+ if (!fInput .good ()) {
1128+ std ::cout << "Cannot open file " << infile << std ::endl ;
1129+ } else {
1130+ char buffer [1024 ];
1131+ while (fInput .getline (buffer , 1024 )) {
1132+ ++ all ;
1133+ std ::string bufferString (buffer );
1134+ if (bufferString .substr (0 , 1 ) == "#" ) {
1135+ continue ; //ignore other comments
1136+ } else {
1137+ std ::vector < std ::string > items = splitString (bufferString );
1138+ if (items .size () < 5 ) {
1139+ std ::cout << "Ignore line: " << buffer << " Size " << items .size ();
1140+ for (unsigned int k = 0 ; k < items .size (); ++ k )
1141+ std ::cout << " [" << k << "] : " << items [k ];
1142+ std ::cout << std ::endl ;
1143+ } else {
1144+ ++ good ;
1145+ int subdet = std ::atoi (items [0 ].c_str ());
1146+ int ieta = std ::atoi (items [1 ].c_str ());
1147+ int iphi = std ::atoi (items [2 ].c_str ());
1148+ int depth = std ::atoi (items [3 ].c_str ());
1149+ double corrf = std ::atof (items [4 ].c_str ());
1150+ unsigned int id = packDetId (subdet , ieta , iphi , depth );
1151+ corrPhiSyms_ [std ::pair < int , int > (runid , id )] = corrf ;
1152+ if (debug_ )
1153+ std ::cout << "ID " << runid << ":" << std ::hex << id << std ::dec << ":" << id << " (subdet " << subdet << " eta " << ieta << " phi " << iphi << " depth " << depth << ") " << corrPhiSym_ [id ] << std ::endl ;
1154+ }
1155+ }
1156+ }
1157+ fInput .close ();
1158+ }
1159+ }
1160+ }
1161+ }
1162+ fIn .close ();
1163+ std ::cout << "Reads total of " << all << " and " << good << " good records of phi-symmetry factors from " << runs_ .size () << " files as given in " << infile0 << std ::endl ;
1164+ }
1165+ return good ;
1166+ }
1167+
1168+ unsigned int CalibCorr ::runId (const int & run ) {
1169+ unsigned int id (runs_ .size ());
1170+ for (unsigned int k = 0 ; k < runs_ .size (); ++ k ) {
1171+ if ((run >= runs_ [k ].first ) && (run <= runs_ [k ].second )) {
1172+ id = k ;
1173+ break ;
1174+ }
1175+ }
1176+ return id ;
1177+ }
1178+
10601179unsigned int CalibCorr ::getDetIdHE (int ieta , int iphi , int depth ) { return getDetId (2 , ieta , iphi , depth ); }
10611180
10621181unsigned int CalibCorr ::getDetId (int subdet , int ieta , int iphi , int depth ) {
@@ -1256,6 +1375,8 @@ CalibDuplicate::CalibDuplicate(const char* fname, int flag, bool debug) : flag_(
12561375 ok_ = true;
12571376 }
12581377 }
1378+ } else if (flag_ == 3 ) {
1379+ ok_ = readCorrFactor (fname );
12591380 } else {
12601381 flag_ = 2 ;
12611382 if (strcmp (fname , "" ) != 0 ) {
@@ -1330,17 +1451,87 @@ bool CalibDuplicate::select(int ieta, int iphi) {
13301451 return flag ;
13311452}
13321453
1454+ double CalibDuplicate ::getCorr (int run , int ieta , int depth ) {
1455+ std ::map < std ::pair < int , int > , std ::vector < double > > ::const_iterator itr = corrs_ .find (std ::pair < int , int > (ieta , depth ));
1456+ double corr (1.0 );
1457+ if (itr != corrs_ .end ()) {
1458+ unsigned int irun = runId (run );
1459+ corr = (itr -> second )[irun ];
1460+ }
1461+ return corr ;
1462+ }
1463+
1464+ bool CalibDuplicate ::readCorrFactor (const char * infile ) {
1465+ bool flag (false );
1466+ std ::ifstream fInput (infile );
1467+ if (!fInput .good ()) {
1468+ std ::cout << "CalibDuplicate::readCorrFactor:Cannot open file " << infile << std ::endl ;
1469+ } else {
1470+ int nrun , neta ;
1471+ fInput >> nrun >> neta ;
1472+ int indx , run1 , run2 ;
1473+ for (int k = 0 ; k < nrun ; ++ k ) {
1474+ fInput >> indx >> run1 >> run2 ;
1475+ runs_ .push_back (std ::pair < int , int > (run1 , run2 ));
1476+ }
1477+ int eta , depth ;
1478+ double corr ;
1479+ for (int k = 0 ; k < neta ; ++ k ) {
1480+ fInput >> eta >> depth ;
1481+ std ::vector < double > corrs ;
1482+ for (int i = 0 ; i < nrun ; ++ i ) {
1483+ fInput >> corr ;
1484+ corrs .push_back (corr );
1485+ }
1486+ corrs_ [std ::pair < int , int > (eta , depth )] = corrs ;
1487+ }
1488+ fInput .close ();
1489+ std ::cout << "CalibDuplicate::readCorrFactor:Reads information of " << runs_ .size () << " runs and " << corrs_ .size () << " channels from " << infile << std ::endl ;
1490+ flag = true;
1491+ if (debug_ ) {
1492+ for (unsigned int k = 0 ; k < runs_ .size (); ++ k )
1493+ std ::cout << "Run range[" << k << "] " << runs_ [k ].first << ":" << runs_ [k ].second << std ::endl ;
1494+ std ::map < std ::pair < int , int > , std ::vector < double > > ::const_iterator itr ;
1495+ for (itr = corrs_ .begin (); itr != corrs_ .end (); ++ itr ) {
1496+ std ::cout << "eta:depth [" << (itr -> first ).first << ":" << (itr -> first ).second << "]" ;
1497+ for (unsigned int i = 0 ; i < (itr -> second ).size (); ++ i )
1498+ std ::cout << " " << (itr -> second )[i ];
1499+ std ::cout << std ::endl ;
1500+ }
1501+ }
1502+ }
1503+ return flag ;
1504+ }
1505+
1506+ unsigned int CalibDuplicate ::runId (const int & run ) {
1507+ unsigned int id (runs_ .size ());
1508+ for (unsigned int k = 0 ; k < runs_ .size (); ++ k ) {
1509+ if ((run >= runs_ [k ].first ) && (run <= runs_ [k ].second )) {
1510+ id = k ;
1511+ break ;
1512+ }
1513+ }
1514+ return id ;
1515+ }
1516+
13331517void 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 );
1518+ if (flag >= 0 ) {
1519+ CalibCorr * c1 = new CalibCorr (infile , flag , true);
1520+ for (int ieta = 1 ; ieta < 29 ; ++ ieta ) {
1521+ int subdet = (ieta > 16 ) ? 2 : 1 ;
1522+ int depth = (ieta > 16 ) ? 2 : 1 ;
1523+ unsigned int id1 = ((4 << 28 ) | ((subdet & 0x7 ) << 25 ));
1524+ id1 |= ((0x1000000 ) | ((depth & 0xF ) << 20 ) | (ieta << 10 ) | 1 );
1525+ c1 -> getCorr (0 , id1 );
1526+ id1 |= (0x80000 );
1527+ c1 -> getCorr (0 , id1 );
1528+ }
1529+ delete c1 ;
1530+ } else {
1531+ CalibDuplicate * c1 = new CalibDuplicate (infile , - flag , true);
1532+ delete c1 ;
13431533 }
1534+
13441535}
13451536
13461537unsigned int stringTest (const std ::string & str ) {
0 commit comments