From b95284e2883acb5dd0e9fea846d7f95cde362fd6 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Thu, 14 Feb 2019 21:16:51 +0100 Subject: [PATCH 01/18] Removed module_dup; previously used for no duplicate printout --- .../TrigFTK/TrigFTKSim/src/atlClustering.cxx | 224 ++++++++---------- 1 file changed, 105 insertions(+), 119 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx index cbfc5bbc6f7..c83558a1e68 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx @@ -48,8 +48,8 @@ const bool DEBUG_CLUSTERS = 0; const bool DEBUG_AVERAGE = 0; const bool DEBUG_AVERAGE_SCT = 0; -const bool PRINT_INPUT = 0; // print input data -const bool DEBUG_INPUT = 0; // detail check input +const bool PRINT_INPUT = 0; // print input data +const bool DEBUG_INPUT = 0; // detail check input const bool DEBUG_DECODER = 0; // check decoder output const bool DEBUG_CENTROID = 0; // check centroid calc. @@ -76,8 +76,6 @@ bool GANGED_PATTERN_RECOGNITION; bool SPLIT_BLAYER_MODULES; //bool CLUSTERING_PRINTOUT; -map > module_dup;//ryu added 20160303 - /*! * Function examining whether a hit is in a specific ROD * \param hit the hit to be examined @@ -101,11 +99,11 @@ cluster::~cluster() hitlist.clear(); } -/*! Function which examines whether a hit belongs to an IBL module. +/*! Function which examines whether a hit belongs to an IBL module. * \param hit the hit * \return true if the hit is on an IBL module, false otherwide */ -bool hitOnIBLmodule(const FTKRawHit &hit) +bool hitOnIBLmodule(const FTKRawHit &hit) { int BarrelEndCap = hit.getBarrelEC(); int layer = hit.getLayer(); @@ -117,12 +115,12 @@ bool hitOnIBLmodule(const FTKRawHit &hit) /** * This class creates a hit whose coordinates are relative to the Front-End chip - * of the module that it belongs to. It is used for the correct ordering of the hits - * in the FTK_IM hit decoder. + * of the module that it belongs to. It is used for the correct ordering of the hits + * in the FTK_IM hit decoder. */ class FTK_FECoordsHit { public: - /** + /** * Create an FTK_Hit_FECoords from an FTKRawHit * \param h FTKRawHit to be processed */ @@ -161,12 +159,12 @@ class FTK_FECoordsHit { /** * This class creates a hit whose coordinates are relative to the hit's position * in the cluster. It is used to calculate if a cluster is split and for - * printing out the test vectors. + * printing out the test vectors. */ class FTK_ClusterCoordHit { public: - /** + /** * Create an FTK_Hit_FECoords from an FTKRawHit * \param h FTKRawHit to be processed * \param seed the central hit of the cluster @@ -216,16 +214,16 @@ double eta(FTKRawHit &hit) { } /*! - * Function examining whether a cluster is split. + * Function examining whether a cluster is split. * \param clu the cluster to be examined * \return true if the cluster is split, false otherwise - */ + */ bool isSplitCluster(const cluster& clu) { //FTK_ClusterCoordHit seed = FTK_ClusterCoordHit(*clu.seed, clu.seed); hitVector::const_iterator it = clu.hitlist.begin(); for (it = clu.hitlist.begin(); it != clu.hitlist.end(); it++) { - if (clu.seed == NULL) + if (clu.seed == NULL) return false; FTK_ClusterCoordHit chit = FTK_ClusterCoordHit(**it , clu.seed); if ((chit.ccol >= GRID_COL_MAX - 1) || (chit.crow >= (GRID_ROW_MAX - 1)) || ( chit.crow <= 0)) @@ -237,7 +235,7 @@ bool isSplitCluster(const cluster& clu) void printDebugInfo(FTKRawHit hits) { - cout << dec + cout << dec << "HitType " << hits.getHitType() << " BarrelEC " << hits.getBarrelEC() << " Layer " << hits.getLayer() @@ -339,10 +337,6 @@ void printCentroidList(clustersByModuleMap clustersByModule) int idHash = hitToModuleId(*hit); int isPixel = hit->getIsPixel(); - if(module_dup[isPixel][idHash]==0) // dupli checker ryu 20160303 - module_dup[isPixel][idHash]++; - else continue; // ryu - if (hitSelector(*hit)) { if(isIBLmodule){// for IBL bool FE0_exist = false; @@ -350,7 +344,7 @@ void printCentroidList(clustersByModuleMap clustersByModule) if(hit->getEtaStrip() < 80){ FE0_exist = true; - + b = cl->end() - 1; int nhit_inCluster = (*b).hitlist.size(); hit = (*b).hitlist[nhit_inCluster-1]; @@ -407,10 +401,6 @@ void printDecoderOutput(hitVector* currentHits, bool isIBLmodule) if(hitSelector(**hit)){ - if(module_dup[(**hit).getIsPixel()][hitToModuleId(**hit)]==0) // dupli checker ryu 20160303 - module_dup[(**hit).getIsPixel()][hitToModuleId(**hit)]++; - else return; // ryu - if(DEBUG_DECODER) printDebugInfo(**hit); if(isIBLmodule){ // for IBL @@ -447,7 +437,7 @@ void printDecoderOutput(hitVector* currentHits, bool isIBLmodule) << " row: " << (*hit)->getPhiSide() << " tot: " << (*hit)->getTot() << endl; - } + } } //hit loop printf("0x40000000\n"); @@ -490,10 +480,6 @@ void printInputData(hitVector* currentHits, bool isIBLmodule){ } // if(hitSelector(**hit)){ - if(module_dup[(**hit).getIsPixel()][hitToModuleId(**hit)]==0) // dupli checker ryu 20160303 - module_dup[(**hit).getIsPixel()][hitToModuleId(**hit)]++; - else return; // ryu - if(DEBUG_INPUT) printDebugInfo(**hit); if(isIBLmodule){ // for IBL @@ -538,7 +524,7 @@ void printInputData(hitVector* currentHits, bool isIBLmodule){ << " row: " << (*hit)->getPhiSide() << " tot: " << (*hit)->getTot() << endl; - } + } } } // hit loop @@ -546,7 +532,7 @@ void printInputData(hitVector* currentHits, bool isIBLmodule){ } #ifdef BOUNDING_BOX -void calcBoundingBox(cluster& clu) +void calcBoundingBox(cluster& clu) { int col_min = (clu.hitlist[0])->getEtaStrip(); int col_max = (clu.hitlist[0])->getEtaStrip(); @@ -569,10 +555,10 @@ void calcBoundingBox(cluster& clu) /*! * Function printing the hit details - * \param hit the hit + * \param hit the hit * \return void */ -void printHit(const FTKRawHit &hit) +void printHit(const FTKRawHit &hit) { std::cout << "DEBUG_HITS: " << " isPixel=" << hit.getIsPixel() @@ -598,9 +584,9 @@ void printHit(const FTKRawHit &hit) /*! * Function examining whether the a given row has ganged pixels * \param the row to be examined - * \return true + * \return true */ -bool pixelRowIsGanged(const int row) +bool pixelRowIsGanged(const int row) { switch (row) { case 153: @@ -619,9 +605,9 @@ bool pixelRowIsGanged(const int row) } /*! - * Function calculating the module id in which the hit belongs to. - * The default mode for now is to check the Identifier Hash of the hit. - * \param hit the hit + * Function calculating the module id in which the hit belongs to. + * The default mode for now is to check the Identifier Hash of the hit. + * \param hit the hit * \return the module id * */ @@ -722,7 +708,7 @@ int hitToModuleId(const FTKRawHit &hit) { * It crashes if hits are the same. * \param hit1 the first hit * \param hit2 the second hit - * \return true if hits are next to each other, false otherwise. + * \return true if hits are next to each other, false otherwise. */ bool neighborhood(const FTKRawHit &hit1, const FTKRawHit &hit2) { @@ -936,10 +922,10 @@ bool isKilled(const cluster &clu, const hitVector &connectedHits) { return false; } -/*! - * Function calculating the central position of the cluster (i.e. the centroid) for all possible +/*! + * Function calculating the central position of the cluster (i.e. the centroid) for all possible * scenarios (SCT, Pixel, IBL). During the execution of this function, the - * following variables are set for each cluster: X, Y, Z, + * following variables are set for each cluster: X, Y, Z, * * \param cluster the cluster whose average is going to be calculated * \return void @@ -981,9 +967,9 @@ void averageCluster(cluster &clu) { int rowMax = 0; int colMin = 99999; //int(2*(design->length()/design->etaPitch()))+1; int colMax = 0; - int qRowMin = 0; + int qRowMin = 0; int qRowMax = 0; - int qColMin = 0; + int qColMin = 0; int qColMax = 0; if (DEBUG_AVERAGE) @@ -994,17 +980,17 @@ void averageCluster(cluster &clu) { /// precalculate values for case PIXEL_CLUSTERING_MODE>0 int BarrelEndCap = first->getBarrelEC(); - //Calculate the active layer. Start with the layer of the hit. In case + //Calculate the active layer. Start with the layer of the hit. In case // always count IBL as layer0 and BLayer as layer1 int layer = first->getLayer(); bool isIBLmodule = hitOnIBLmodule(*first); bool isIBL_Planar = false; bool isPixelmodule = !isIBLmodule; if (FTKSetup::getFTKSetup().getIBLMode()==0) - layer++; + layer++; float radius = ftk::clustering::radii[layer]; - //Default values for a pixel module. They are modified for IBL. + //Default values for a pixel module. They are modified for IBL. float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; float numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInPixelModule; @@ -1183,7 +1169,7 @@ void averageCluster(cluster &clu) { << " -> "; } - //Modifications have to be made to include 3d modules + //Modifications have to be made to include 3d modules int orig_col = col; col *= pixYScaleFactor; // use units of 25um col += pixYScaleFactor/2; // add half a pixel to align to pixel center @@ -1247,13 +1233,13 @@ void averageCluster(cluster &clu) { if (eta < etaMin) etaMin = eta; if (phi > phiMax) phiMax = phi; if (phi < phiMin) phiMin = phi; - // if ((*p)->getEtaStrip() > etaMax) + // if ((*p)->getEtaStrip() > etaMax) // etaMax = (*p)->getEtaStrip(); - // if ((*p)->getEtaStrip() < etaMin) + // if ((*p)->getEtaStrip() < etaMin) // etaMin = (*p)->getEtaStrip(); - // if ((*p)->getPhiSide() > phiMax) + // if ((*p)->getPhiSide() > phiMax) // phiMax = (*p)->getPhiSide(); - // if ((*p)->getPhiSide() < phiMin) + // if ((*p)->getPhiSide() < phiMin) // phiMin = (*p)->getPhiSide(); if (DEBUG_AVERAGE) printHit(**p); @@ -1271,66 +1257,66 @@ void averageCluster(cluster &clu) { // if(colMin == pixYScaleFactor && colMin != colMax) eta_average = (colMin + colMax) / 2. - 1.; // if(colMax == 1626 && colMin != colMax) eta_average = (colMin + colMax) / 2. - 1.; - // New Implementation - + // New Implementation + if (PIXEL_CLUSTERING_MODE == PIXEL_CLUSTERING_HARDWARE) { float etaRow = -1; float etaCol = -1; - if(qRowMin+qRowMax > 0) + if(qRowMin+qRowMax > 0) etaRow = qRowMax/float(qRowMin+qRowMax); - if(qColMin+qColMax > 0) + if(qColMin+qColMax > 0) etaCol = qColMax/float(qColMin+qColMax); - /// double test = 0; - int etaRow32 = 0; - int etaCol32 =0; - etaRow32 = lround(etaRow*32); + /// double test = 0; + int etaRow32 = 0; + int etaCol32 =0; + etaRow32 = lround(etaRow*32); etaCol32 = lround(etaCol*32); - int m_posStrategy = 1; + int m_posStrategy = 1; if(m_posStrategy == 1 && !hasGanged && etaRow>0 && etaCol > 0){ - if (BarrelEndCap==0) { - phi_average+= lround((getDeltaX1A(clu)+(getDeltaX2A(clu))*etaRow32)/1024.); // >>10; - + if (BarrelEndCap==0) { + phi_average+= lround((getDeltaX1A(clu)+(getDeltaX2A(clu))*etaRow32)/1024.); // >>10; + if ( (etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) > 0){ if ( sensorThickness*((etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius)>etaPitch) { - /// test = etaPitch; + /// test = etaPitch; eta_average+= pixYScaleFactor*(etaCol-0.5); - eta_average = lround(eta_average); - } + eta_average = lround(eta_average); + } else - eta_average+= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); + eta_average+= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); } - else{ + else{ if ( sensorThickness*(-1*(etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius)>etaPitch) { - /// test = etaPitch; + /// test = etaPitch; eta_average+= pixYScaleFactor*(etaCol-0.5); - eta_average = lround(eta_average); + eta_average = lround(eta_average); } - else + else eta_average-= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); } - + } - + else{ - phi_average += lround((getDeltaXEC1A(clu)+getDeltaXEC2A(clu)*etaRow32)/1024.); - eta_average += lround((getDeltaYEC1A(clu)+getDeltaYEC2A(clu)*etaCol32)/1024.); - + phi_average += lround((getDeltaXEC1A(clu)+getDeltaXEC2A(clu)*etaRow32)/1024.); + eta_average += lround((getDeltaYEC1A(clu)+getDeltaYEC2A(clu)*etaCol32)/1024.); + } - + } } - - - + + + //Correction to the eta_average and phi_average used for - //PIXEL_CLUSTERING_MODE 1 and 100 + //PIXEL_CLUSTERING_MODE 1 and 100 if (PIXEL_CLUSTERING_MODE <= PIXEL_CLUSTERING_MIXED) { float pixelEstimateCotTheta = -9999.; - /* The next lines calculate CotTheta of a hypothetic track starting from ATLAS (0,0,0) + /* The next lines calculate CotTheta of a hypothetic track starting from ATLAS (0,0,0) * and crossing the center of the bounding box of the cluster. * The Z global position is estimated as: module Z position + cluster Z position within the module. - * The radius is a fixed costant depending on the layer. It could be better estimated accounting + * The radius is a fixed costant depending on the layer. It could be better estimated accounting * also for the rphi position within the module. */ pixelEstimateCotTheta = (etaModule+(rowMin+rowMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius; @@ -1342,9 +1328,9 @@ void averageCluster(cluster &clu) { // Two pixels may have tot=0 (very rarely, hopefully) float etaRow = -1; float etaCol = -1; - if(qRowMin+qRowMax > 0) + if(qRowMin+qRowMax > 0) etaRow = qRowMax/float(qRowMin+qRowMax); - if(qColMin+qColMax > 0) + if(qColMin+qColMax > 0) etaCol = qColMax/float(qColMin+qColMax); // Charge interpolation. Very rough guess (one can do better with @@ -1355,7 +1341,7 @@ void averageCluster(cluster &clu) { if (BarrelEndCap==0) { //pixelID.is_barrel(elementID)){ deltax = 30*ftk::micrometer*(sensorThickness/(250*ftk::micrometer)); deltay = sensorThickness*fabs(pixelEstimateCotTheta); - if(deltay > etaPitch ){ + if(deltay > etaPitch ){ deltay = etaPitch; } } else { @@ -1364,8 +1350,8 @@ void averageCluster(cluster &clu) { } // Width of the region of charge sharing. For disks assume normal incidence: delta is small, due to diffusion - // of drifting charges in silicon. For barrel, assume 10 deg. incidence in Rphi, in z compute from pseudorapidity - // This may be improved with better parameterization, but it is probably better to use candidate track information + // of drifting charges in silicon. For barrel, assume 10 deg. incidence in Rphi, in z compute from pseudorapidity + // This may be improved with better parameterization, but it is probably better to use candidate track information // later in reconstruction. TL // Values are made dependent on the sensor thickness to accomodate // different sensors layout. AA // Point3D globalPos = element->globalPosition(centroid); @@ -1374,7 +1360,7 @@ void averageCluster(cluster &clu) { if(m_posStrategy == 1 && !hasGanged && etaRow>0 && etaCol > 0){ phi_average += pixXScaleFactor*deltax*(etaRow-0.5)/ftk::phiPitch; eta_average += pixYScaleFactor*deltay*(etaCol-0.5)/etaPitch; - } + } } if (phi_average<0) { @@ -1388,7 +1374,7 @@ void averageCluster(cluster &clu) { if (BarrelEndCap!=0) phi_average += ftk::clustering::pixelEndCapRPhiCorrection*pixXScaleFactor; //if (isIBLmodule) phi_average += ftk::clustering::pixelIblRPhiCorrection*pixXScaleFactor; //temp Yoshi 2016.10.07 - + // av.setEtaWidth(etaMax-etaMin+1); // duplicate!! needless // av.setPhiWidth(phiMax-phiMin+1); @@ -1410,7 +1396,7 @@ void averageCluster(cluster &clu) { //// rescale full module length 152*400um to the range 0-144 //// here 1 units is 400*19/18um (i.e. average 400/600um pixel length) //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfPixelModuleIn400umPixels/pixYScaleFactor; - //} else if (isIBLmodule && FTKSetup::getFTKSetup().getIBLMode()==1) { + //} else if (isIBLmodule && FTKSetup::getFTKSetup().getIBLMode()==1) { //// rescale from 25um units to 250um (1 "normal" IBL pixel) unit //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfIblModuleIn250umPixels/pixYScaleFactor; //} @@ -1515,7 +1501,7 @@ void realisticPixelDecoder(hitVector* ¤tHits, bool isIBLmodule) //Keisuke } currentHits->clear(); - + while(!lifo.empty() && !fifo.empty()){ if ((*lifo.top()).getEtaStrip() <= (*fifo.front()).getEtaStrip()) { currentHits->push_back(lifo.top()); @@ -1557,7 +1543,7 @@ void realisticPixelDecoder(hitVector* ¤tHits, bool isIBLmodule) //Keisuke while(!fifo.empty()){ currentHits->push_back(fifo.front()); - fifo.pop(); + fifo.pop(); } while(!lifo.empty()) { @@ -1574,7 +1560,7 @@ void realisticPixelDecoder(hitVector* ¤tHits, bool isIBLmodule) //Keisuke currentHits->push_back(lifo_planar.top()); lifo_planar.pop(); } - }// if isIBLmodule + }// if isIBLmodule } @@ -1641,7 +1627,7 @@ FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hi /*! * Function responsible for hit clustering and the subsequent centroid - * calculation + * calculation * \param hits hits which will be clustered * \return void */ @@ -1727,7 +1713,7 @@ void atlClusteringLNF(vector &hits) cluList *currentClusters = new cluList(); // instantiate cluster list clustersByModule[modId] = currentClusters; - //The ideal clustering is going to be used in the following cases: + //The ideal clustering is going to be used in the following cases: //1. PIXEL_CLUSTERING_MODE is less than 100 (PIXEL_CLUSTERING_MIXED) //2. The module is not a pixel module @@ -1736,7 +1722,7 @@ void atlClusteringLNF(vector &hits) //if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || !firstHit.getIsPixel() || isIBLmodule) { makeClustersLNF(currentHits, currentClusters); // use ideal clustering } - else { // PIXEL_CLUSTERING_MODE >= 100 and pixel module + else { // PIXEL_CLUSTERING_MODE >= 100 and pixel module //realisticPixelDecoder(currentHits); realisticPixelDecoder(currentHits, isIBLmodule); @@ -1867,7 +1853,7 @@ void atlClusteringLNF(vector &hits) /*! * Function examining if a hit is ganged. In case the hit belongs to a pixel * module and at a row with ganged pixels, the phi coordinate of the pixel is - * returned. It always returns 0 if the hit belongs to an IBL module. + * returned. It always returns 0 if the hit belongs to an IBL module. * \param hit hit to be examined * \return The phi coordinate of the hit if the hit is ganged, 0 otherwise */ @@ -1924,7 +1910,7 @@ int gangedPartner(const FTKRawHit &hit) { } return -1; } - + double getDeltaX1A(cluster &clu){ FTKRawHit *first = *(clu.hitlist.begin()); bool isIBLmodule = hitOnIBLmodule(*first); @@ -1934,33 +1920,33 @@ double getDeltaX1A(cluster &clu){ sensorThickness = ftk::sensorThicknessIbl; } return lround(-(32*32*(30*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)/2.)); - + } double getDeltaX2A(cluster &clu){ FTKRawHit *first = *(clu.hitlist.begin()); bool isIBLmodule = hitOnIBLmodule(*first); float sensorThickness = ftk::sensorThicknessPixel; - float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; + float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; if (isIBLmodule) { sensorThickness = ftk::sensorThicknessIbl; } - return lround(32*(30*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)); + return lround(32*(30*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)); } int getDeltaXEC1A(cluster &clu){ FTKRawHit *first = *(clu.hitlist.begin()); bool isIBLmodule = hitOnIBLmodule(*first); float sensorThickness = ftk::sensorThicknessPixel; - float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; + float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; if (isIBLmodule) { sensorThickness = ftk::sensorThicknessIbl; } - return lround(- (32*32*(10*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)/2.)); + return lround(- (32*32*(10*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)/2.)); } int getDeltaXEC2A(cluster &clu){ FTKRawHit *first = *(clu.hitlist.begin()); bool isIBLmodule = hitOnIBLmodule(*first); float sensorThickness = ftk::sensorThicknessPixel; - float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; + float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; if (isIBLmodule) { sensorThickness = ftk::sensorThicknessIbl; } @@ -1971,19 +1957,19 @@ int getDeltaYEC1A(cluster &clu){ bool isIBLmodule = hitOnIBLmodule(*first); float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; - float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; + float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; if (isIBLmodule) { sensorThickness = ftk::sensorThicknessIbl; etaPitch = ftk::etaPitchIbl; } - return lround(- (32*32*(10*ftk::micrometer*pixYScaleFactor*(sensorThickness/(250*ftk::micrometer))/etaPitch)/2.)); + return lround(- (32*32*(10*ftk::micrometer*pixYScaleFactor*(sensorThickness/(250*ftk::micrometer))/etaPitch)/2.)); } int getDeltaYEC2A(cluster &clu){ FTKRawHit *first = *(clu.hitlist.begin()); bool isIBLmodule = hitOnIBLmodule(*first); float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; - float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; + float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; if (isIBLmodule) { sensorThickness = ftk::sensorThicknessIbl; etaPitch = ftk::etaPitchIbl; @@ -1995,7 +1981,7 @@ int getDeltaY1A(cluster &clu){ int layer = first->getLayer(); bool isIBLmodule = hitOnIBLmodule(*first); if (FTKSetup::getFTKSetup().getIBLMode()==0) - layer++; + layer++; float radius = ftk::clustering::radii[layer]; float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; @@ -2008,16 +1994,16 @@ int getDeltaY1A(cluster &clu){ pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-8; etaPitch = ftk::etaPitchIbl; - - } - return lround ( - 32*32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch/2. ) + lround( 32*32*2* pixYScaleFactor*sensorThickness*moduleActiveLength/radius /etaPitch/2/2); + + } + return lround ( - 32*32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch/2. ) + lround( 32*32*2* pixYScaleFactor*sensorThickness*moduleActiveLength/radius /etaPitch/2/2); } int getDeltaY2A(cluster &clu){ FTKRawHit *first = *(clu.hitlist.begin()); int layer = first->getLayer(); bool isIBLmodule = hitOnIBLmodule(*first); if (FTKSetup::getFTKSetup().getIBLMode()==0) - layer++; + layer++; float radius = ftk::clustering::radii[layer]; float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; @@ -2031,7 +2017,7 @@ int getDeltaY2A(cluster &clu){ etaModule = first->getEtaModule()-8; etaPitch = ftk::etaPitchIbl; } - return lround (32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch) + lround ( - 32*2* pixYScaleFactor*sensorThickness* moduleActiveLength/radius /etaPitch/2.); + return lround (32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch) + lround ( - 32*2* pixYScaleFactor*sensorThickness* moduleActiveLength/radius /etaPitch/2.); } int getDeltaY1B(cluster &clu){ @@ -2039,7 +2025,7 @@ int getDeltaY1B(cluster &clu){ int layer = first->getLayer(); bool isIBLmodule = hitOnIBLmodule(*first); if (FTKSetup::getFTKSetup().getIBLMode()==0) - layer++; + layer++; float radius = ftk::clustering::radii[layer]; float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; @@ -2058,7 +2044,7 @@ int getDeltaY2B(cluster &clu){ int layer = first->getLayer(); bool isIBLmodule = hitOnIBLmodule(*first); if (FTKSetup::getFTKSetup().getIBLMode()==0) - layer++; + layer++; float radius = ftk::clustering::radii[layer]; float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; @@ -2070,5 +2056,5 @@ int getDeltaY2B(cluster &clu){ moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors etaPitch = ftk::etaPitchIbl; } - return lround (32 * sensorThickness/numberOfEtaPixelsInModule *moduleActiveLength/radius/etaPitch ) ; -} + return lround (32 * sensorThickness/numberOfEtaPixelsInModule *moduleActiveLength/radius/etaPitch ) ; +} -- GitLab From 04827d4063f1f9eba02e55270e8d1e8188f98015 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Wed, 20 Feb 2019 16:01:19 +0100 Subject: [PATCH 02/18] Indentation; Removed hitSelector, use hitToModuleId instead --- .../TrigFTK/TrigFTKSim/src/atlClustering.cxx | 1788 ++++++++--------- 1 file changed, 871 insertions(+), 917 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx index c83558a1e68..63da9bab328 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx @@ -76,24 +76,6 @@ bool GANGED_PATTERN_RECOGNITION; bool SPLIT_BLAYER_MODULES; //bool CLUSTERING_PRINTOUT; -/*! - * Function examining whether a hit is in a specific ROD - * \param hit the hit to be examined - * \return true if the hit belongs in the ROD, false otherwise - */ -bool hitSelector(const FTKRawHit &/*hit*/) { - return true; - //if (hit.getHitType() == PIXEL && hit.getBarrelEC() == 0 && hit.getLayer()== 1) { - //if (hit.getPhiModule() == 13 && (hit.getEtaModule() <= 0)) { - //return true; - //} - //} - //else { - //return false; - //} - //return false; -} - cluster::~cluster() { hitlist.clear(); @@ -119,7 +101,7 @@ bool hitOnIBLmodule(const FTKRawHit &hit) * in the FTK_IM hit decoder. */ class FTK_FECoordsHit { - public: +public: /** * Create an FTK_Hit_FECoords from an FTKRawHit * \param h FTKRawHit to be processed @@ -128,26 +110,26 @@ class FTK_FECoordsHit { tot = hit->getTot(); int acol = hit->getEtaStrip(); int arow = hit->getPhiSide(); - if(!hitOnIBLmodule(*hit)){ - if (arow < ftk::clustering::rowsInFEChipPerPixelModuleRow) { - fe = ftk::clustering::feChipsInRowPixel + acol/ftk::clustering::colsInFEChipPerPixelModuleRow; - lrow = arow; - lcol = acol%ftk::clustering::colsInFEChipPerPixelModuleRow; - } else { - fe = (ftk::clustering::feChipsInRowPixel - 1) - acol/ftk::clustering::colsInFEChipPerPixelModuleRow; //-1 because we start counting from 0 - lrow = (ftk::numberOfPhiPixelsInPixelModule - 1) - arow; //We start counting from 0 - lcol = (ftk::clustering::colsInFEChipPerPixelModuleRow - 1) - acol%ftk::clustering::colsInFEChipPerPixelModuleRow; //Start counting from 0 - } - }else{ - if (acol < ftk::clustering::colsInFEChipPerIblModuleRow) { - fe = 0; - lcol = acol; - } else { - fe = 1; - lcol = acol-80; - } - lrow = (ftk::clustering::rowsInFEChipPerIblModuleRow - 1) - arow; - } + if(!hitOnIBLmodule(*hit)){ + if (arow < ftk::clustering::rowsInFEChipPerPixelModuleRow) { + fe = ftk::clustering::feChipsInRowPixel + acol/ftk::clustering::colsInFEChipPerPixelModuleRow; + lrow = arow; + lcol = acol%ftk::clustering::colsInFEChipPerPixelModuleRow; + } else { + fe = (ftk::clustering::feChipsInRowPixel - 1) - acol/ftk::clustering::colsInFEChipPerPixelModuleRow; //-1 because we start counting from 0 + lrow = (ftk::numberOfPhiPixelsInPixelModule - 1) - arow; //We start counting from 0 + lcol = (ftk::clustering::colsInFEChipPerPixelModuleRow - 1) - acol%ftk::clustering::colsInFEChipPerPixelModuleRow; //Start counting from 0 + } + }else{ + if (acol < ftk::clustering::colsInFEChipPerIblModuleRow) { + fe = 0; + lcol = acol; + } else { + fe = 1; + lcol = acol-80; + } + lrow = (ftk::clustering::rowsInFEChipPerIblModuleRow - 1) - arow; + } } int fe; ///< The FE chip of the hit @@ -163,7 +145,7 @@ class FTK_FECoordsHit { */ class FTK_ClusterCoordHit { - public: +public: /** * Create an FTK_Hit_FECoords from an FTKRawHit * \param h FTKRawHit to be processed @@ -227,7 +209,7 @@ bool isSplitCluster(const cluster& clu) return false; FTK_ClusterCoordHit chit = FTK_ClusterCoordHit(**it , clu.seed); if ((chit.ccol >= GRID_COL_MAX - 1) || (chit.crow >= (GRID_ROW_MAX - 1)) || ( chit.crow <= 0)) - return true; + return true; } return false; @@ -235,14 +217,14 @@ bool isSplitCluster(const cluster& clu) void printDebugInfo(FTKRawHit hits) { - cout << dec - << "HitType " << hits.getHitType() - << " BarrelEC " << hits.getBarrelEC() - << " Layer " << hits.getLayer() - << " IdHash " << hits.getIdentifierHash() - << " PhiModule " << hits.getPhiModule() - << " EtaModule " << hits.getEtaModule() - << endl; + cout << dec + << "HitType " << hits.getHitType() + << " BarrelEC " << hits.getBarrelEC() + << " Layer " << hits.getLayer() + << " IdHash " << hits.getIdentifierHash() + << " PhiModule " << hits.getPhiModule() + << " EtaModule " << hits.getEtaModule() + << endl; } //#if defined(CLUSTERING_PRINTOUT) || defined(CENTROID_PRINTOUT) || defined(DECODER_INPUT) @@ -302,25 +284,11 @@ void printClusterList(clustersByModuleMap clustersByModule) cluList* cl = (*p).second; cluList::iterator b = cl->begin(); FTKRawHit* hit = (*b).hitlist[0]; - // if (!(hit)->getIsPixel() || hitOnIBLmodule(*hit)) { - // //continue ; - // } - if (hitSelector(*hit)) { - printf("0x200000%02d\n", hitToModuleId(*hit)); - for (; b != cl->end(); b++) { - printClu(*b); - //printf("CENTROID: %.8X X: %d Y: %d\n", (*b).clusterEquiv.getHWWord(), (*b).clusterEquiv.getRowCoordinate(), (*b).clusterEquiv.getColumnCoordinate()); - } - printf("0x40000000\n"); + printf("0x200000%02d\n", hitToModuleId(*hit)); + for (; b != cl->end(); b++) { + printClu(*b); } - // Yoshi 2016.09.29 - // cout << "isIBLmodule/CluList is " << hitOnIBLmodule(*hit) << endl; - // printf("0x200000%02d\n", hitToModuleId(*hit)); - // for (; b != cl->end(); b++) { - // printClu(*b); - // //printf("CENTROID: %.8X X: %d Y: %d\n", (*b).clusterEquiv.getHWWord(), (*b).clusterEquiv.getRowCoordinate(), (*b).clusterEquiv.getColumnCoordinate()); - // } - // printf("0x40000000\n"); + printf("0x40000000\n"); } } @@ -333,57 +301,55 @@ void printCentroidList(clustersByModuleMap clustersByModule) cluList::iterator b = cl->begin(); FTKRawHit* hit = (*b).hitlist[0]; - bool isIBLmodule = hitOnIBLmodule(*hit); - int idHash = hitToModuleId(*hit); - int isPixel = hit->getIsPixel(); - - if (hitSelector(*hit)) { - if(isIBLmodule){// for IBL - bool FE0_exist = false; - bool FE1_exist = false; - - if(hit->getEtaStrip() < 80){ - FE0_exist = true; - - b = cl->end() - 1; - int nhit_inCluster = (*b).hitlist.size(); - hit = (*b).hitlist[nhit_inCluster-1]; - if(hit->getEtaStrip() >= 80) - FE1_exist = true; - }else{ - FE1_exist = true; - } - - b = cl->begin(); - hit = (*b).hitlist[0]; - - if(FE1_exist == false && FE0_exist == true) - printf("0x08%.7x\n", idHash); - else - printf("0x08%.7x\n", idHash-1); - } else { - printf("0x8%.7x\n", hitToModuleId(*hit)); - } - for (; b != cl->end(); b++) { - //printToFile(outcentroid, (*b).clusterEquiv.getHWWord()); - printf("0x%.8X ",(*b).clusterEquiv.getHWWord()); - //std::cout << (*b).clusterEquiv.getTot() << " " << (*b).clusterEquiv.getEtaStrip() << " " << (*b).clusterEquiv.getPhiSide() << std::endl; - if (DEBUG_CENTROID) printDebugInfo(*hit); + bool isIBLmodule = hitOnIBLmodule(*hit); + int idHash = hitToModuleId(*hit); + int isPixel = hit->getIsPixel(); + + if(isIBLmodule){// for IBL + bool FE0_exist = false; + bool FE1_exist = false; + + if(hit->getEtaStrip() < 80){ + FE0_exist = true; + + b = cl->end() - 1; + int nhit_inCluster = (*b).hitlist.size(); + hit = (*b).hitlist[nhit_inCluster-1]; + if(hit->getEtaStrip() >= 80) + FE1_exist = true; + }else{ + FE1_exist = true; } - printf("0x40000000\n"); + + b = cl->begin(); + hit = (*b).hitlist[0]; + + if(FE1_exist == false && FE0_exist == true) + printf("0x08%.7x\n", idHash); + else + printf("0x08%.7x\n", idHash-1); + } else { + printf("0x8%.7x\n", hitToModuleId(*hit)); } + for (; b != cl->end(); b++) { + //printToFile(outcentroid, (*b).clusterEquiv.getHWWord()); + printf("0x%.8X ",(*b).clusterEquiv.getHWWord()); + //std::cout << (*b).clusterEquiv.getTot() << " " << (*b).clusterEquiv.getEtaStrip() << " " << (*b).clusterEquiv.getPhiSide() << std::endl; + if (DEBUG_CENTROID) printDebugInfo(*hit); + } + printf("0x40000000\n"); } } bool sortWords(const FTKRawHit* i, const FTKRawHit* j) { - int firstCol = i->getEtaStrip() + 1; - int secondCol = j->getEtaStrip() + 1; - int firstRow = 335 - i->getPhiSide(); // Keisuke 20170314, start from 0 - int secondRow = 335 - j->getPhiSide(); // Keisuke 20170314, start from 0 + int firstCol = i->getEtaStrip() + 1; + int secondCol = j->getEtaStrip() + 1; + int firstRow = 335 - i->getPhiSide(); // Keisuke 20170314, start from 0 + int secondRow = 335 - j->getPhiSide(); // Keisuke 20170314, start from 0 - if(firstCol != secondCol) return firstCol < secondCol; - else return firstRow > secondRow; + if(firstCol != secondCol) return firstCol < secondCol; + else return firstRow > secondRow; } @@ -395,140 +361,135 @@ void printDecoderOutput(hitVector* currentHits, bool isIBLmodule) int idHash = hitToModuleId(**hit); if(isIBLmodule){ // Keisuke 20170215 - stable_sort(sortHits->begin(), sortHits->end(), sortWords); - idHash = hitToModuleId(**sortHits->begin()); + stable_sort(sortHits->begin(), sortHits->end(), sortWords); + idHash = hitToModuleId(**sortHits->begin()); } - if(hitSelector(**hit)){ - - if(DEBUG_DECODER) printDebugInfo(**hit); - - if(isIBLmodule){ // for IBL - printf("0x8%.7x\n", idHash); - //stable_sort(sortHits->begin(), sortHits->end(), sortWords); - - for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ - int tempCol = (*it)->getEtaStrip(); - // if(tempCol >= 80) tempCol = tempCol - 80; // Yoshi 2016.11.18 - int tempRow = 335 - (*it)->getPhiSide(); // Keisuke 20170314, start from 0 - int tempTot = (*it)->getTot(); - int outputData = ( (tempTot << 20) | (tempCol << 12) | tempRow ); - printf("0x0%.7X",outputData); - - if(!DEBUG_DECODER) cout << endl; - else{ - cout << " IBL HIT" - << " col: " << setfill('0') << setw(3) << tempCol - << " row: " << setfill('0') << setw(3) << tempRow - << " tot: " << setfill('0') << setw(2) << tempTot - << endl; - } - } - - }else{ // for Pixel - printf("0x8%.7x\n", hitToModuleId(**hit)); - for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { - printf("0x0%.2X%.2X%.3X",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); - //std::cout << (*hit)->getTot() << " " << (*hit)->getEtaStrip() << " " << (*hit)->getPhiSide() << std::endl; - if(!DEBUG_DECODER) cout << endl; - else{ - cout << " Pixel HIT" - << " col: " << (*hit)->getEtaStrip() - << " row: " << (*hit)->getPhiSide() - << " tot: " << (*hit)->getTot() - << endl; - } - - } //hit loop - printf("0x40000000\n"); - } - }// module check + if(DEBUG_DECODER) printDebugInfo(**hit); + + if(isIBLmodule){ // for IBL + printf("0x8%.7x\n", idHash); + //stable_sort(sortHits->begin(), sortHits->end(), sortWords); + + for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ + int tempCol = (*it)->getEtaStrip(); + // if(tempCol >= 80) tempCol = tempCol - 80; // Yoshi 2016.11.18 + int tempRow = 335 - (*it)->getPhiSide(); // Keisuke 20170314, start from 0 + int tempTot = (*it)->getTot(); + int outputData = ( (tempTot << 20) | (tempCol << 12) | tempRow ); + printf("0x0%.7X",outputData); + + if(!DEBUG_DECODER) cout << endl; + else{ + cout << " IBL HIT" + << " col: " << setfill('0') << setw(3) << tempCol + << " row: " << setfill('0') << setw(3) << tempRow + << " tot: " << setfill('0') << setw(2) << tempTot + << endl; + } + } + + }else{ // for Pixel + printf("0x8%.7x\n", hitToModuleId(**hit)); + for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { + printf("0x0%.2X%.2X%.3X",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); + //std::cout << (*hit)->getTot() << " " << (*hit)->getEtaStrip() << " " << (*hit)->getPhiSide() << std::endl; + if(!DEBUG_DECODER) cout << endl; + else{ + cout << " Pixel HIT" + << " col: " << (*hit)->getEtaStrip() + << " row: " << (*hit)->getPhiSide() + << " tot: " << (*hit)->getTot() + << endl; + } + + } //hit loop + printf("0x40000000\n"); + } } #endif bool sortInput(const FTKRawHit* i, const FTKRawHit* j) { - int firstCol = i->getEtaStrip() + 1; - int secondCol = j->getEtaStrip() + 1; - int firstRow = 335 - i->getPhiSide(); // Keisuke 20170314, start from 0 - int secondRow = 335 - j->getPhiSide(); // Keisuke 20170314, start from 0 - int firstFE = (firstCol <= 80) ? 0 : 1; - int secondFE = (secondCol <= 80) ? 0 : 1; - - if(firstCol >= 81) firstCol = firstCol - 80; - if(secondCol >= 81) secondCol = secondCol - 80; - - if (firstFE != secondFE) return firstFE > secondFE; - else{ - if(firstCol <= 40 || secondCol <= 40){ - if(firstCol != secondCol) return firstCol < secondCol; - else return firstRow < secondRow; - } else { - if(firstCol != secondCol) return firstCol > secondCol; - else return firstRow < secondRow; + int firstCol = i->getEtaStrip() + 1; + int secondCol = j->getEtaStrip() + 1; + int firstRow = 335 - i->getPhiSide(); // Keisuke 20170314, start from 0 + int secondRow = 335 - j->getPhiSide(); // Keisuke 20170314, start from 0 + int firstFE = (firstCol <= 80) ? 0 : 1; + int secondFE = (secondCol <= 80) ? 0 : 1; + + if(firstCol >= 81) firstCol = firstCol - 80; + if(secondCol >= 81) secondCol = secondCol - 80; + + if (firstFE != secondFE) return firstFE > secondFE; + else{ + if(firstCol <= 40 || secondCol <= 40){ + if(firstCol != secondCol) return firstCol < secondCol; + else return firstRow < secondRow; + } else { + if(firstCol != secondCol) return firstCol > secondCol; + else return firstRow < secondRow; + } } - } } void printInputData(hitVector* currentHits, bool isIBLmodule){ - hitVector::iterator hit = currentHits->begin(); - hitVector *sortHits = currentHits; - int idHash = hitToModuleId(**hit) + 8; - if(isIBLmodule){ - stable_sort(sortHits->begin(), sortHits->end(), sortInput); - idHash = hitToModuleId(**sortHits->begin()) + 8; - } - // if(hitSelector(**hit)){ - - if(DEBUG_INPUT) printDebugInfo(**hit); - - if(isIBLmodule){ // for IBL - printf("0x03%.1x000000\n", idHash); - - //stable_sort(sortHits->begin(), sortHits->end(), sortInput); - - for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ - int tempCol = (*it)->getEtaStrip() + 1; - if((idHash == 0x8 || idHash == 0xa) && tempCol <= 80){ - printf("0x05%.1x400000\n", idHash); - idHash = idHash + 1; - printf("0x03%.1x000000\n", idHash); - } - if(tempCol >= 81) tempCol = tempCol - 80; // for generate real input - int tempRow = 335 - (*it)->getPhiSide(); // Keisuke 20170314, start from 0 - int tempTot = (*it)->getTot(); - int outputData = ((idHash << 24) | (tempTot << 20) | (tempCol << 9) | tempRow ); - printf("0x09%.7x",outputData); - - if(!DEBUG_INPUT) cout << endl; - else{ - cout << " IBL HIT" - << " col: " << setfill('0') << setw(3) << tempCol - << " row: " << setfill('0') << setw(3) << tempRow - << " tot: " << setfill('0') << setw(2) << tempTot - << endl; - } + hitVector::iterator hit = currentHits->begin(); + hitVector *sortHits = currentHits; + int idHash = hitToModuleId(**hit) + 8; + if(isIBLmodule){ + stable_sort(sortHits->begin(), sortHits->end(), sortInput); + idHash = hitToModuleId(**sortHits->begin()) + 8; } + if(DEBUG_INPUT) printDebugInfo(**hit); - }else{ // for Pixel + if(isIBLmodule){ // for IBL + printf("0x03%.1x000000\n", idHash); - printf("0x08%.7x\n", idHash); + //stable_sort(sortHits->begin(), sortHits->end(), sortInput); - for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { - printf("0x00%.2x%.2x%.3x ",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); + for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ + int tempCol = (*it)->getEtaStrip() + 1; + if((idHash == 0x8 || idHash == 0xa) && tempCol <= 80){ + printf("0x05%.1x400000\n", idHash); + idHash = idHash + 1; + printf("0x03%.1x000000\n", idHash); + } + if(tempCol >= 81) tempCol = tempCol - 80; // for generate real input + int tempRow = 335 - (*it)->getPhiSide(); // Keisuke 20170314, start from 0 + int tempTot = (*it)->getTot(); + int outputData = ((idHash << 24) | (tempTot << 20) | (tempCol << 9) | tempRow ); + printf("0x09%.7x",outputData); + + if(!DEBUG_INPUT) cout << endl; + else{ + cout << " IBL HIT" + << " col: " << setfill('0') << setw(3) << tempCol + << " row: " << setfill('0') << setw(3) << tempRow + << " tot: " << setfill('0') << setw(2) << tempTot + << endl; + } + } - if(!DEBUG_DECODER) cout << endl; - else{ - cout << " Pixel HIT" - << " col: " << (*hit)->getEtaStrip() - << " row: " << (*hit)->getPhiSide() - << " tot: " << (*hit)->getTot() - << endl; - } - } - } // hit loop + }else{ // for Pixel + + printf("0x08%.7x\n", idHash); + + for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { + printf("0x00%.2x%.2x%.3x ",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); + + if(!DEBUG_DECODER) cout << endl; + else{ + cout << " Pixel HIT" + << " col: " << (*hit)->getEtaStrip() + << " row: " << (*hit)->getPhiSide() + << " tot: " << (*hit)->getTot() + << endl; + } + } + } // hit loop - printf("0x05%.1x400000\n", idHash); + printf("0x05%.1x400000\n", idHash); } #ifdef BOUNDING_BOX @@ -561,24 +522,24 @@ void calcBoundingBox(cluster& clu) void printHit(const FTKRawHit &hit) { std::cout << "DEBUG_HITS: " - << " isPixel=" << hit.getIsPixel() - << " barrel_ec=" << hit.getBarrelEC() - << " layer_disk=" << hit.getLayer() - << " phi_module=" << hit.getPhiModule() - << " eta_module=" << hit.getEtaModule() - << " pi_side=" << hit.getPhiSide() - << " ei_strip=" << hit.getEtaStrip() - << " n_strips=" << hit.getNStrips() - << " deltaPhi=" << hit.getDeltaPhi() - << " deltaEta=" << hit.getDeltaEta() - << " ( x=" << hit.getX() - << " y=" << hit.getY() - << " z=" << hit.getZ() - << " eventindex=" << hit.getEventIndex() - << " barcode=" << hit.getBarcode() - << " bar_pt=" << hit.getBarcodePt() - << " parentage_mask=" << hit.getParentageMask() - << " )\n"; + << " isPixel=" << hit.getIsPixel() + << " barrel_ec=" << hit.getBarrelEC() + << " layer_disk=" << hit.getLayer() + << " phi_module=" << hit.getPhiModule() + << " eta_module=" << hit.getEtaModule() + << " pi_side=" << hit.getPhiSide() + << " ei_strip=" << hit.getEtaStrip() + << " n_strips=" << hit.getNStrips() + << " deltaPhi=" << hit.getDeltaPhi() + << " deltaEta=" << hit.getDeltaEta() + << " ( x=" << hit.getX() + << " y=" << hit.getY() + << " z=" << hit.getZ() + << " eventindex=" << hit.getEventIndex() + << " barcode=" << hit.getBarcode() + << " bar_pt=" << hit.getBarcodePt() + << " parentage_mask=" << hit.getParentageMask() + << " )\n"; } /*! @@ -589,15 +550,15 @@ void printHit(const FTKRawHit &hit) bool pixelRowIsGanged(const int row) { switch (row) { - case 153: - case 155: - case 157: - case 159: - case 168: - case 170: - case 172: - case 174: - return row; // pixel ganged found (readout channel) + case 153: + case 155: + case 157: + case 159: + case 168: + case 170: + case 172: + case 174: + return row; // pixel ganged found (readout channel) } if (160<=row && row<=167) return row; // pixel ganged found (non readout channel) @@ -666,25 +627,25 @@ int hitToModuleId(const FTKRawHit &hit) { unsigned int ilayer = 0; switch (hit.getHitType()) { - case PIXEL: - ilayer = hit.getLayer(); - if (FTKSetup::getFTKSetup().getIBLMode()>=1) { - assert(ilayer=1) { + assert(ilayer=10 && ilayer=10 && ilayerpush_back(clu); if (0) std::cout << "DEBUG_makeCluster:" - << " index=" << index - << " cluSize=" << cluSize - << " Nclusters=" << currentClusters->size() - << "\n"; + << " index=" << index + << " cluSize=" << cluSize + << " Nclusters=" << currentClusters->size() + << "\n"; index++; } } @@ -915,7 +876,7 @@ bool isKilled(const cluster &clu, const hitVector &connectedHits) { for (c=(hv).begin(); c!=(hv).end(); ++c) { assert( hitIsGanged(**c) ); // all connected hits should be ganged ! if ( (*c)->getPhiSide() == (*p)->getPhiSide() - && (*c)->getEtaStrip() == (*p)->getEtaStrip() ) return true; + && (*c)->getEtaStrip() == (*p)->getEtaStrip() ) return true; } } // loop over hits in cluster @@ -974,7 +935,7 @@ void averageCluster(cluster &clu) { if (DEBUG_AVERAGE) std::cout << "DEBUG_AVERAGE: isPixel=" << av.getIsPixel() - << ", nHits=" << nHits<< "\n"; + << ", nHits=" << nHits<< "\n"; hitVector::iterator p; /// precalculate values for case PIXEL_CLUSTERING_MODE>0 @@ -1011,103 +972,61 @@ void averageCluster(cluster &clu) { pixYScaleFactor = ftk::clustering::yScaleFactorIbl; ///getEtaModule()-8; - isIBL_Planar = (first->getEtaModule() >= -6 && first->getEtaModule() <= 5 ? true : false); - if(!isIBL_Planar && IBL3D_REALISTIC){ // 3D - sensorThickness = 230*ftk::micrometer; // 3D - moduleActiveLength = 80*250; // 3D - numberOfEtaPixelsInModule = 80; // 3D - } + isIBL_Planar = (first->getEtaModule() >= -6 && first->getEtaModule() <= 5 ? true : false); + if(!isIBL_Planar && IBL3D_REALISTIC){ // 3D + sensorThickness = 230*ftk::micrometer; // 3D + moduleActiveLength = 80*250; // 3D + numberOfEtaPixelsInModule = 80; // 3D + } } bool hasGanged = false; switch (av.getHitType()) { - case SCT: { - int firstStrip = 99999; - int lastStrip = -99999; - av.setPhiSide(first->getPhiSide()); - for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { - av.addX((*p)->getX()); - av.addY((*p)->getY()); - av.addZ((*p)->getZ()); - if ((*p)->getEtaStrip() < firstStrip) - firstStrip = (*p)->getEtaStrip(); - if ((*p)->getEtaStrip()+(*p)->getNStrips()-1 > lastStrip) - lastStrip = (*p)->getEtaStrip() + (*p)->getNStrips() - 1; - av.addEtaStrip((*p)->getEtaStrip()); - if (DEBUG_AVERAGE_SCT) // && clu.hitlist.size()>1) - printHit(**p); - } - float stripNumberFloat = (firstStrip*1.+lastStrip)/2; - //(av.getEtaStrip()*1.)/nHits; - av.setEtaStrip( (int) stripNumberFloat ); - av.setDeltaPhi( stripNumberFloat - (int) stripNumberFloat ); - // The convention used for SCT is that we are providing as output - // the cluster center minus half a strip (i.e. use the left edge of strip for a single strip cluster) - // where output = av.setEtaStrip + av.setDeltaPhi - av.setStripCoordinate(firstStrip+lastStrip); - av.setColumnCoordinate( 0 ); - av.setDeltaEta(0); - av.setNStrips(lastStrip+1-firstStrip); - av.setEtaWidth(1); - //std::cout << " strip " << std::endl; - av.setPhiWidth(lastStrip+1-firstStrip); - if (DEBUG_AVERAGE_SCT) { // && clu.hitlist.size()>1) { - std::cout << "SCT AVERAGE: "; - printHit(av); - std::cout << std::endl; - } - break; // end of SCT - } - case PIXEL: { - av.setPhiSide(0); // eta is reset a few lines above - - // HHHHH Different Clustering mode HHHHH - - if (PIXEL_CLUSTERING_MODE == 0) { - for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { //loop over hits in cluster - assert(av.getLayer()==(*p)->getLayer() && av.getPhiModule()==(*p)->getPhiModule() && av.getEtaModule()==(*p)->getEtaModule() ); - if (SAVE_CLUSTER_CONTENT) { // if enabled the cluster also stores also the single channels - FTKRawHit tmpch = *(*p); - // set the barcode of the single channel, this may allow a very refined debugging of - // the cluster content accounting for the single barcode of each channel - MultiTruth mt; - MultiTruth::Barcode uniquecode(tmpch.getEventIndex(),tmpch.getBarcode()); - mt.maximize(uniquecode,tmpch.getBarcodePt()); - tmpch.setTruth(mt); - av.addChannel(tmpch); - } - av.addX((*p)->getX()); - av.addY((*p)->getY()); - av.addZ((*p)->getZ()); - av.addPhiSide((*p)->getPhiSide()); // phi index - // pixels are counted starting from 0 (left edge) and not 0.5 (center position) - // if only pixel 0 is hit the output value will be 0 and not 0.5 (pixel center) - av.addEtaStrip((*p)->getEtaStrip()); // eta index - } - tmp = (int)round((av.getEtaStrip()*1.)/nHits); - av.setDeltaEta((av.getEtaStrip()*1.)/nHits-tmp); - av.setEtaStrip(tmp); - tmp = (int)round((av.getPhiSide()*1.)/nHits); - av.setDeltaPhi((av.getPhiSide()*1.)/nHits-tmp); - av.setPhiSide(tmp); - break; - } + case SCT: { + int firstStrip = 99999; + int lastStrip = -99999; + av.setPhiSide(first->getPhiSide()); + for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { + av.addX((*p)->getX()); + av.addY((*p)->getY()); + av.addZ((*p)->getZ()); + if ((*p)->getEtaStrip() < firstStrip) + firstStrip = (*p)->getEtaStrip(); + if ((*p)->getEtaStrip()+(*p)->getNStrips()-1 > lastStrip) + lastStrip = (*p)->getEtaStrip() + (*p)->getNStrips() - 1; + av.addEtaStrip((*p)->getEtaStrip()); + if (DEBUG_AVERAGE_SCT) // && clu.hitlist.size()>1) + printHit(**p); + } + float stripNumberFloat = (firstStrip*1.+lastStrip)/2; + //(av.getEtaStrip()*1.)/nHits; + av.setEtaStrip( (int) stripNumberFloat ); + av.setDeltaPhi( stripNumberFloat - (int) stripNumberFloat ); + // The convention used for SCT is that we are providing as output + // the cluster center minus half a strip (i.e. use the left edge of strip for a single strip cluster) + // where output = av.setEtaStrip + av.setDeltaPhi + av.setStripCoordinate(firstStrip+lastStrip); + av.setColumnCoordinate( 0 ); + av.setDeltaEta(0); + av.setNStrips(lastStrip+1-firstStrip); + av.setEtaWidth(1); + //std::cout << " strip " << std::endl; + av.setPhiWidth(lastStrip+1-firstStrip); + if (DEBUG_AVERAGE_SCT) { // && clu.hitlist.size()>1) { + std::cout << "SCT AVERAGE: "; + printHit(av); + std::cout << std::endl; + } + break; // end of SCT + } + case PIXEL: { + av.setPhiSide(0); // eta is reset a few lines above - // HHHHH above HHHHH + // HHHHH Different Clustering mode HHHHH - /* For PIXEL_CLUSTERING_MODE > 0 - * calculate cluster center following code at line 701 of - * https://svnweb.cern.ch/trac/atlasoff/browser/InnerDetector/InDetRecTools/SiClusterizationTool/trunk/src/MergedPixelsTool.cxx#L701 - * I.e. m_posStrategy == 1 - * I.e. use charge imbalance between the two outer most ros (columns) to calculate the centroid - * In this code I'll use etaTrack instead of pixel eta for simplicity - */ - - //std::cout << "CNTRD: CALCULATE CLUSTER" << std::endl; + if (PIXEL_CLUSTERING_MODE == 0) { for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { //loop over hits in cluster - //std::cout << "CNTRD: HIT " << (*p)->getEtaStrip() << " " << (*p)->getPhiSide() << " " << (*p)->getTot() << std::endl; assert(av.getLayer()==(*p)->getLayer() && av.getPhiModule()==(*p)->getPhiModule() && av.getEtaModule()==(*p)->getEtaModule() ); - if (SAVE_CLUSTER_CONTENT) { // if enabled the cluster also stores also the single channels FTKRawHit tmpch = *(*p); // set the barcode of the single channel, this may allow a very refined debugging of @@ -1118,305 +1037,347 @@ void averageCluster(cluster &clu) { tmpch.setTruth(mt); av.addChannel(tmpch); } - av.addX((*p)->getX()); av.addY((*p)->getY()); av.addZ((*p)->getZ()); + av.addPhiSide((*p)->getPhiSide()); // phi index + // pixels are counted starting from 0 (left edge) and not 0.5 (center position) + // if only pixel 0 is hit the output value will be 0 and not 0.5 (pixel center) + av.addEtaStrip((*p)->getEtaStrip()); // eta index + } + tmp = (int)round((av.getEtaStrip()*1.)/nHits); + av.setDeltaEta((av.getEtaStrip()*1.)/nHits-tmp); + av.setEtaStrip(tmp); + tmp = (int)round((av.getPhiSide()*1.)/nHits); + av.setDeltaPhi((av.getPhiSide()*1.)/nHits-tmp); + av.setPhiSide(tmp); + break; + } - int row = (*p)->getPhiSide(); - int col = (*p)->getEtaStrip(); - int tot = (*p)->getTot(); // ToT for pixels - if (!isIBLmodule && pixelRowIsGanged(row)) - hasGanged = true; - - if (isPixelmodule) { - // account for 600um pixels in the centroid calculation - // will use units of 100um and the convert to normal pixel units below - // will also indicate the center of the pixel instead of the left edge - // considering center of pixel along eta (left (or top if you prefer) edge along phi) - // each FE number is worth 19*400um pixels (400um*16 + 600um*2) - // multiply FE column by 4 to convert to 100um units - int FEnumber = col/ftk::clustering::colsInFEChipPerPixelModuleRow; - int FEcolumn = col%ftk::clustering::colsInFEChipPerPixelModuleRow; - - if(DEBUG_CENTROID && hitSelector(**p)){ - printf("0x00%.2X%.2X%.3X", tot, col, row); - cout << " Pix HIT" - << " FE: " << setfill('0') << setw(2) << FEnumber - << " col: " << setfill('0') << setw(3) << col - << " row: " << setfill('0') << setw(3) << row - << " tot: " << setfill('0') << setw(2) << tot - << " -> "; - } - - col = FEnumber*(ftk::clustering::colsInFEChipPerPixelModuleRow+1) + FEcolumn; - col *= pixYScaleFactor; - col += pixYScaleFactor/2; // add half a pixel to align to pixel center (assume normal 400um pixel) - col += pixYScaleFactor/2; // assume 1<=FEcolumn<=16 add half a pixel coming from 600um pixel in FEcolumn==0 - if (FEcolumn==0) col -= pixYScaleFactor/4; // correct position for first column in FE chip - if (FEcolumn==(ftk::clustering::colsInFEChipPerPixelModuleRow-1)) col += pixYScaleFactor/4; // correct position for last column in FE chip - } else if (isIBLmodule) { // IBL case - row = 335 - (*p)->getPhiSide(); // inverse row coordinates // Yoshi 2016.10.28 // JAA updated 17.3.13 - - // if(col >= 80) col = col - 80; // Yoshi 2016.11.18 - - if(DEBUG_CENTROID && hitSelector(**p)){ - printf("0x00%.2X%.2X%.3X", tot, col, row); - cout << " IBL HIT" - << " col: " << setfill('0') << setw(3) << col - << " row: " << setfill('0') << setw(3) << row - << " tot: " << setfill('0') << setw(2) << tot - << " -> "; - } - - //Modifications have to be made to include 3d modules - int orig_col = col; - col *= pixYScaleFactor; // use units of 25um - col += pixYScaleFactor/2; // add half a pixel to align to pixel center - if((isIBL_Planar && IBL3D_REALISTIC) || !IBL3D_REALISTIC){ - if (orig_col==0) col += pixYScaleFactor/2; // add half pixel (500um pixel in col0) - if (orig_col>0) col += pixYScaleFactor; // add a pixel (500um pixel in col0) - - // for 3D modules only - // if (orig_col==79) col += pixYScaleFactor*5/10; // add 5/10 of pixel i.e. 100um (500um pixel in col79) - - // for planar modules only - if (orig_col==79) col += pixYScaleFactor*4/10; // add 4/10 of pixel i.e. 100um (450um pixel in col79) - if (orig_col==80) col += pixYScaleFactor*12/10; // add 12/10 of pixel i.e. 300um (450um pixel in col79 and col80) - if (orig_col>80) col += pixYScaleFactor*16/10; // add 16/10 of pixel i.e. 400um (450um pixel in col79 and col80) - if (orig_col==159) col += pixYScaleFactor/2; // add half pixel (500um pixel in col159) - } - } - row *= pixXScaleFactor; - - // comment 2017.01.30 - // if(isIBLmodule) row += pixXScaleFactor/2; // applied Manolis' update - - if(DEBUG_CENTROID && hitSelector(**p)){ - printf("0x00%.2X%.3X%.3X", tot, col, row); - cout << " Norm." - << " col: " << setfill('0') << setw(3) << col - << " row: " << setfill('0') << setw(4) << row - << " tot: " << setfill('0') << setw(2) << tot - << endl; - } - - if (row == rowMin) qRowMin += tot; - if (row < rowMin){ - rowMin = row; - qRowMin = tot; - } + // HHHHH above HHHHH + + /* For PIXEL_CLUSTERING_MODE > 0 + * calculate cluster center following code at line 701 of + * https://svnweb.cern.ch/trac/atlasoff/browser/InnerDetector/InDetRecTools/SiClusterizationTool/trunk/src/MergedPixelsTool.cxx#L701 + * I.e. m_posStrategy == 1 + * I.e. use charge imbalance between the two outer most ros (columns) to calculate the centroid + * In this code I'll use etaTrack instead of pixel eta for simplicity + */ + + //std::cout << "CNTRD: CALCULATE CLUSTER" << std::endl; + for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { //loop over hits in cluster + //std::cout << "CNTRD: HIT " << (*p)->getEtaStrip() << " " << (*p)->getPhiSide() << " " << (*p)->getTot() << std::endl; + assert(av.getLayer()==(*p)->getLayer() && av.getPhiModule()==(*p)->getPhiModule() && av.getEtaModule()==(*p)->getEtaModule() ); + + if (SAVE_CLUSTER_CONTENT) { // if enabled the cluster also stores also the single channels + FTKRawHit tmpch = *(*p); + // set the barcode of the single channel, this may allow a very refined debugging of + // the cluster content accounting for the single barcode of each channel + MultiTruth mt; + MultiTruth::Barcode uniquecode(tmpch.getEventIndex(),tmpch.getBarcode()); + mt.maximize(uniquecode,tmpch.getBarcodePt()); + tmpch.setTruth(mt); + av.addChannel(tmpch); + } - if (row == rowMax) qRowMax += tot; - if (row > rowMax){ - rowMax = row; - qRowMax = tot; + av.addX((*p)->getX()); + av.addY((*p)->getY()); + av.addZ((*p)->getZ()); + + int row = (*p)->getPhiSide(); + int col = (*p)->getEtaStrip(); + int tot = (*p)->getTot(); // ToT for pixels + if (!isIBLmodule && pixelRowIsGanged(row)) + hasGanged = true; + + if (isPixelmodule) { + // account for 600um pixels in the centroid calculation + // will use units of 100um and the convert to normal pixel units below + // will also indicate the center of the pixel instead of the left edge + // considering center of pixel along eta (left (or top if you prefer) edge along phi) + // each FE number is worth 19*400um pixels (400um*16 + 600um*2) + // multiply FE column by 4 to convert to 100um units + int FEnumber = col/ftk::clustering::colsInFEChipPerPixelModuleRow; + int FEcolumn = col%ftk::clustering::colsInFEChipPerPixelModuleRow; + + if(DEBUG_CENTROID){ + printf("0x00%.2X%.2X%.3X", tot, col, row); + cout << " Pix HIT" + << " FE: " << setfill('0') << setw(2) << FEnumber + << " col: " << setfill('0') << setw(3) << col + << " row: " << setfill('0') << setw(3) << row + << " tot: " << setfill('0') << setw(2) << tot + << " -> "; } - if (col == colMin) qColMin += tot; - if (col < colMin){ - colMin = col; - qColMin = tot; + col = FEnumber*(ftk::clustering::colsInFEChipPerPixelModuleRow+1) + FEcolumn; + col *= pixYScaleFactor; + col += pixYScaleFactor/2; // add half a pixel to align to pixel center (assume normal 400um pixel) + col += pixYScaleFactor/2; // assume 1<=FEcolumn<=16 add half a pixel coming from 600um pixel in FEcolumn==0 + if (FEcolumn==0) col -= pixYScaleFactor/4; // correct position for first column in FE chip + if (FEcolumn==(ftk::clustering::colsInFEChipPerPixelModuleRow-1)) col += pixYScaleFactor/4; // correct position for last column in FE chip + } else if (isIBLmodule) { // IBL case + row = 335 - (*p)->getPhiSide(); // inverse row coordinates // Yoshi 2016.10.28 // JAA updated 17.3.13 + + // if(col >= 80) col = col - 80; // Yoshi 2016.11.18 + + if(DEBUG_CENTROID){ + printf("0x00%.2X%.2X%.3X", tot, col, row); + cout << " IBL HIT" + << " col: " << setfill('0') << setw(3) << col + << " row: " << setfill('0') << setw(3) << row + << " tot: " << setfill('0') << setw(2) << tot + << " -> "; } - if (col == colMax) qColMax += tot; - if (col > colMax){ - colMax = col; - qColMax = tot; + //Modifications have to be made to include 3d modules + int orig_col = col; + col *= pixYScaleFactor; // use units of 25um + col += pixYScaleFactor/2; // add half a pixel to align to pixel center + if((isIBL_Planar && IBL3D_REALISTIC) || !IBL3D_REALISTIC){ + if (orig_col==0) col += pixYScaleFactor/2; // add half pixel (500um pixel in col0) + if (orig_col>0) col += pixYScaleFactor; // add a pixel (500um pixel in col0) + + // for 3D modules only + // if (orig_col==79) col += pixYScaleFactor*5/10; // add 5/10 of pixel i.e. 100um (500um pixel in col79) + + // for planar modules only + if (orig_col==79) col += pixYScaleFactor*4/10; // add 4/10 of pixel i.e. 100um (450um pixel in col79) + if (orig_col==80) col += pixYScaleFactor*12/10; // add 12/10 of pixel i.e. 300um (450um pixel in col79 and col80) + if (orig_col>80) col += pixYScaleFactor*16/10; // add 16/10 of pixel i.e. 400um (450um pixel in col79 and col80) + if (orig_col==159) col += pixYScaleFactor/2; // add half pixel (500um pixel in col159) } + } + row *= pixXScaleFactor; + + // comment 2017.01.30 + // if(isIBLmodule) row += pixXScaleFactor/2; // applied Manolis' update + + if(DEBUG_CENTROID){ + printf("0x00%.2X%.3X%.3X", tot, col, row); + cout << " Norm." + << " col: " << setfill('0') << setw(3) << col + << " row: " << setfill('0') << setw(4) << row + << " tot: " << setfill('0') << setw(2) << tot + << endl; + } - int phi = 335 - (*p)->getPhiSide(); // ROW // JAA updated 13 March 2017 to remove +1 as above - // int phi = (*p)->getPhiSide(); // ROW - int eta = (*p)->getEtaStrip(); // COLUMN - - if (eta > etaMax) etaMax = eta; - if (eta < etaMin) etaMin = eta; - if (phi > phiMax) phiMax = phi; - if (phi < phiMin) phiMin = phi; - // if ((*p)->getEtaStrip() > etaMax) - // etaMax = (*p)->getEtaStrip(); - // if ((*p)->getEtaStrip() < etaMin) - // etaMin = (*p)->getEtaStrip(); - // if ((*p)->getPhiSide() > phiMax) - // phiMax = (*p)->getPhiSide(); - // if ((*p)->getPhiSide() < phiMin) - // phiMin = (*p)->getPhiSide(); - if (DEBUG_AVERAGE) - printHit(**p); - av.addTot(first->getTot()); // sum ToT for pixel clusters + if (row == rowMin) qRowMin += tot; + if (row < rowMin){ + rowMin = row; + qRowMin = tot; } - av.setEtaWidth(etaMax-etaMin+1); - av.setPhiWidth(phiMax-phiMin+1); - - // calculate eta index and eta delta - double eta_average, phi_average; - eta_average = (colMin + colMax) / 2.; - phi_average = (rowMin + rowMax) / 2.; - - // Yoshi added 2017.02.01 - // if(colMin == pixYScaleFactor && colMin != colMax) eta_average = (colMin + colMax) / 2. - 1.; - // if(colMax == 1626 && colMin != colMax) eta_average = (colMin + colMax) / 2. - 1.; - - // New Implementation - - if (PIXEL_CLUSTERING_MODE == PIXEL_CLUSTERING_HARDWARE) { - float etaRow = -1; - float etaCol = -1; - if(qRowMin+qRowMax > 0) - etaRow = qRowMax/float(qRowMin+qRowMax); - if(qColMin+qColMax > 0) - etaCol = qColMax/float(qColMin+qColMax); - /// double test = 0; - int etaRow32 = 0; - int etaCol32 =0; - etaRow32 = lround(etaRow*32); - etaCol32 = lround(etaCol*32); - int m_posStrategy = 1; - if(m_posStrategy == 1 && !hasGanged && etaRow>0 && etaCol > 0){ - if (BarrelEndCap==0) { - phi_average+= lround((getDeltaX1A(clu)+(getDeltaX2A(clu))*etaRow32)/1024.); // >>10; - - if ( (etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) > 0){ - if ( sensorThickness*((etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius)>etaPitch) { - /// test = etaPitch; - eta_average+= pixYScaleFactor*(etaCol-0.5); - eta_average = lround(eta_average); - } - else - eta_average+= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); - } - else{ - if ( sensorThickness*(-1*(etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius)>etaPitch) { - /// test = etaPitch; - eta_average+= pixYScaleFactor*(etaCol-0.5); - eta_average = lround(eta_average); - } - else - eta_average-= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); - } - - } - - else{ - phi_average += lround((getDeltaXEC1A(clu)+getDeltaXEC2A(clu)*etaRow32)/1024.); - eta_average += lround((getDeltaYEC1A(clu)+getDeltaYEC2A(clu)*etaCol32)/1024.); - - } - - } - } - - - - //Correction to the eta_average and phi_average used for - //PIXEL_CLUSTERING_MODE 1 and 100 - if (PIXEL_CLUSTERING_MODE <= PIXEL_CLUSTERING_MIXED) { - float pixelEstimateCotTheta = -9999.; - - /* The next lines calculate CotTheta of a hypothetic track starting from ATLAS (0,0,0) - * and crossing the center of the bounding box of the cluster. - * The Z global position is estimated as: module Z position + cluster Z position within the module. - * The radius is a fixed costant depending on the layer. It could be better estimated accounting - * also for the rphi position within the module. - */ - pixelEstimateCotTheta = (etaModule+(rowMin+rowMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius; - if (PIXEL_CLUSTERING_MODE>=PIXEL_CLUSTERING_IDEAL_APRIL_2014_FIX) /* Fixing an error in the formula */ - pixelEstimateCotTheta = (etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius; + if (row == rowMax) qRowMax += tot; + if (row > rowMax){ + rowMax = row; + qRowMax = tot; + } + + if (col == colMin) qColMin += tot; + if (col < colMin){ + colMin = col; + qColMin = tot; + } + + if (col == colMax) qColMax += tot; + if (col > colMax){ + colMax = col; + qColMax = tot; + } + + int phi = 335 - (*p)->getPhiSide(); // ROW // JAA updated 13 March 2017 to remove +1 as above + // int phi = (*p)->getPhiSide(); // ROW + int eta = (*p)->getEtaStrip(); // COLUMN + + if (eta > etaMax) etaMax = eta; + if (eta < etaMin) etaMin = eta; + if (phi > phiMax) phiMax = phi; + if (phi < phiMin) phiMin = phi; + // if ((*p)->getEtaStrip() > etaMax) + // etaMax = (*p)->getEtaStrip(); + // if ((*p)->getEtaStrip() < etaMin) + // etaMin = (*p)->getEtaStrip(); + // if ((*p)->getPhiSide() > phiMax) + // phiMax = (*p)->getPhiSide(); + // if ((*p)->getPhiSide() < phiMin) + // phiMin = (*p)->getPhiSide(); + if (DEBUG_AVERAGE) + printHit(**p); + av.addTot(first->getTot()); // sum ToT for pixel clusters + } + av.setEtaWidth(etaMax-etaMin+1); + av.setPhiWidth(phiMax-phiMin+1); + + // calculate eta index and eta delta + double eta_average, phi_average; + eta_average = (colMin + colMax) / 2.; + phi_average = (rowMin + rowMax) / 2.; + + // Yoshi added 2017.02.01 + // if(colMin == pixYScaleFactor && colMin != colMax) eta_average = (colMin + colMax) / 2. - 1.; + // if(colMax == 1626 && colMin != colMax) eta_average = (colMin + colMax) / 2. - 1.; + + // New Implementation + + if (PIXEL_CLUSTERING_MODE == PIXEL_CLUSTERING_HARDWARE) { + float etaRow = -1; + float etaCol = -1; + if(qRowMin+qRowMax > 0) + etaRow = qRowMax/float(qRowMin+qRowMax); + if(qColMin+qColMax > 0) + etaCol = qColMax/float(qColMin+qColMax); + /// double test = 0; + int etaRow32 = 0; + int etaCol32 =0; + etaRow32 = lround(etaRow*32); + etaCol32 = lround(etaCol*32); + int m_posStrategy = 1; + if(m_posStrategy == 1 && !hasGanged && etaRow>0 && etaCol > 0){ + if (BarrelEndCap==0) { + phi_average+= lround((getDeltaX1A(clu)+(getDeltaX2A(clu))*etaRow32)/1024.); // >>10; + + if ( (etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) > 0){ + if ( sensorThickness*((etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius)>etaPitch) { + /// test = etaPitch; + eta_average+= pixYScaleFactor*(etaCol-0.5); + eta_average = lround(eta_average); + } + else + eta_average+= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); + } + else{ + if ( sensorThickness*(-1*(etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius)>etaPitch) { + /// test = etaPitch; + eta_average+= pixYScaleFactor*(etaCol-0.5); + eta_average = lround(eta_average); + } + else + eta_average-= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); + } - // Compute eta for charge interpolation correction (if required) - // Two pixels may have tot=0 (very rarely, hopefully) - float etaRow = -1; - float etaCol = -1; - if(qRowMin+qRowMax > 0) - etaRow = qRowMax/float(qRowMin+qRowMax); - if(qColMin+qColMax > 0) - etaCol = qColMax/float(qColMin+qColMax); - - // Charge interpolation. Very rough guess (one can do better with - // candidate track information later) TL - // bool hasGanged = av.getIncludesGanged(); - float deltax = 0; - float deltay = 0; - if (BarrelEndCap==0) { //pixelID.is_barrel(elementID)){ - deltax = 30*ftk::micrometer*(sensorThickness/(250*ftk::micrometer)); - deltay = sensorThickness*fabs(pixelEstimateCotTheta); - if(deltay > etaPitch ){ - deltay = etaPitch; - } - } else { - deltax = 10*ftk::micrometer*sqrt(sensorThickness/(250*ftk::micrometer)); - deltay = 10*ftk::micrometer*sqrt(sensorThickness/(250*ftk::micrometer)); } - // Width of the region of charge sharing. For disks assume normal incidence: delta is small, due to diffusion - // of drifting charges in silicon. For barrel, assume 10 deg. incidence in Rphi, in z compute from pseudorapidity - // This may be improved with better parameterization, but it is probably better to use candidate track information - // later in reconstruction. TL - // Values are made dependent on the sensor thickness to accomodate // different sensors layout. AA - // Point3D globalPos = element->globalPosition(centroid); - // InDetDD::SiLocalPosition totCorrection(0,0,0); - int m_posStrategy = 1; //Same as m_posStrategy == 1 in InDetRecTools/SiClusterizationTool/trunk/src/MergedPixelsTool.cxx#L701 - if(m_posStrategy == 1 && !hasGanged && etaRow>0 && etaCol > 0){ - phi_average += pixXScaleFactor*deltax*(etaRow-0.5)/ftk::phiPitch; - eta_average += pixYScaleFactor*deltay*(etaCol-0.5)/etaPitch; + else{ + phi_average += lround((getDeltaXEC1A(clu)+getDeltaXEC2A(clu)*etaRow32)/1024.); + eta_average += lround((getDeltaYEC1A(clu)+getDeltaYEC2A(clu)*etaCol32)/1024.); + } + } + } - if (phi_average<0) { - assert(phi_average<0); - phi_average = 0; + + + //Correction to the eta_average and phi_average used for + //PIXEL_CLUSTERING_MODE 1 and 100 + if (PIXEL_CLUSTERING_MODE <= PIXEL_CLUSTERING_MIXED) { + float pixelEstimateCotTheta = -9999.; + + /* The next lines calculate CotTheta of a hypothetic track starting from ATLAS (0,0,0) + * and crossing the center of the bounding box of the cluster. + * The Z global position is estimated as: module Z position + cluster Z position within the module. + * The radius is a fixed costant depending on the layer. It could be better estimated accounting + * also for the rphi position within the module. + */ + pixelEstimateCotTheta = (etaModule+(rowMin+rowMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius; + if (PIXEL_CLUSTERING_MODE>=PIXEL_CLUSTERING_IDEAL_APRIL_2014_FIX) /* Fixing an error in the formula */ + pixelEstimateCotTheta = (etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius; + + + // Compute eta for charge interpolation correction (if required) + // Two pixels may have tot=0 (very rarely, hopefully) + float etaRow = -1; + float etaCol = -1; + if(qRowMin+qRowMax > 0) + etaRow = qRowMax/float(qRowMin+qRowMax); + if(qColMin+qColMax > 0) + etaCol = qColMax/float(qColMin+qColMax); + + // Charge interpolation. Very rough guess (one can do better with + // candidate track information later) TL + // bool hasGanged = av.getIncludesGanged(); + float deltax = 0; + float deltay = 0; + if (BarrelEndCap==0) { //pixelID.is_barrel(elementID)){ + deltax = 30*ftk::micrometer*(sensorThickness/(250*ftk::micrometer)); + deltay = sensorThickness*fabs(pixelEstimateCotTheta); + if(deltay > etaPitch ){ + deltay = etaPitch; + } + } else { + deltax = 10*ftk::micrometer*sqrt(sensorThickness/(250*ftk::micrometer)); + deltay = 10*ftk::micrometer*sqrt(sensorThickness/(250*ftk::micrometer)); } - if (eta_average<0) { - assert(eta_average<0); - eta_average = 0; + + // Width of the region of charge sharing. For disks assume normal incidence: delta is small, due to diffusion + // of drifting charges in silicon. For barrel, assume 10 deg. incidence in Rphi, in z compute from pseudorapidity + // This may be improved with better parameterization, but it is probably better to use candidate track information + // later in reconstruction. TL + // Values are made dependent on the sensor thickness to accomodate // different sensors layout. AA + // Point3D globalPos = element->globalPosition(centroid); + // InDetDD::SiLocalPosition totCorrection(0,0,0); + int m_posStrategy = 1; //Same as m_posStrategy == 1 in InDetRecTools/SiClusterizationTool/trunk/src/MergedPixelsTool.cxx#L701 + if(m_posStrategy == 1 && !hasGanged && etaRow>0 && etaCol > 0){ + phi_average += pixXScaleFactor*deltax*(etaRow-0.5)/ftk::phiPitch; + eta_average += pixYScaleFactor*deltay*(etaCol-0.5)/etaPitch; } + } - if (BarrelEndCap!=0) phi_average += ftk::clustering::pixelEndCapRPhiCorrection*pixXScaleFactor; - //if (isIBLmodule) phi_average += ftk::clustering::pixelIblRPhiCorrection*pixXScaleFactor; //temp Yoshi 2016.10.07 + if (phi_average<0) { + assert(phi_average<0); + phi_average = 0; + } + if (eta_average<0) { + assert(eta_average<0); + eta_average = 0; + } - // av.setEtaWidth(etaMax-etaMin+1); // duplicate!! needless - // av.setPhiWidth(phiMax-phiMin+1); + if (BarrelEndCap!=0) phi_average += ftk::clustering::pixelEndCapRPhiCorrection*pixXScaleFactor; + //if (isIBLmodule) phi_average += ftk::clustering::pixelIblRPhiCorrection*pixXScaleFactor; //temp Yoshi 2016.10.07 - //if (PIXEL_CLUSTERING_MODE == PIXEL_CLUSTERING_HARDWARE) { - av.setRowCoordinate( lround(phi_average) ); - //} else av.setRowCoordinate( lround(phi_average*pixXScaleFactor) ); - av.setColumnCoordinate( lround(eta_average) ); - av.setSplit(false); + // av.setEtaWidth(etaMax-etaMin+1); // duplicate!! needless + // av.setPhiWidth(phiMax-phiMin+1); - // HHHHH Yoshi 2017.01.10 HHHHH - if (PIXEL_CLUSTERING_MODE >= PIXEL_CLUSTERING_MIXED && isSplitCluster(clu)) { - //if (PIXEL_CLUSTERING_MODE >= PIXEL_CLUSTERING_MIXED && !isIBLmodule && isSplitCluster(clu)) { - av.setSplit(true); - } + //if (PIXEL_CLUSTERING_MODE == PIXEL_CLUSTERING_HARDWARE) { + av.setRowCoordinate( lround(phi_average) ); + //} else av.setRowCoordinate( lround(phi_average*pixXScaleFactor) ); + av.setColumnCoordinate( lround(eta_average) ); + av.setSplit(false); - eta_average*=numberOfEtaPixelsInModule/lengthOfPixelModuleInUmPixels/pixYScaleFactor; - phi_average/=pixXScaleFactor; // Keisuke 20170314, bug fix of row coordinate range - //if (isPixelmodule) { - //// rescale full module length 152*400um to the range 0-144 - //// here 1 units is 400*19/18um (i.e. average 400/600um pixel length) - //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfPixelModuleIn400umPixels/pixYScaleFactor; - //} else if (isIBLmodule && FTKSetup::getFTKSetup().getIBLMode()==1) { - //// rescale from 25um units to 250um (1 "normal" IBL pixel) unit - //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfIblModuleIn250umPixels/pixYScaleFactor; - //} - //else if (isIBLmodule && FTKSetup::getFTKSetup().getIBLMode()==2) - //// rescale from 25um units to 250um (1 "normal" IBL pixel) unit - //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfIblModuleIn250umPixels/pixYScaleFactor; - //} - - double delta; - delta = eta_average - (int) eta_average; - av.setDeltaEta(delta); - av.setEtaStrip( (int) eta_average ); - delta = phi_average - (int) phi_average; - av.setDeltaPhi(delta); - av.setPhiSide( (int) phi_average ); - - break; // end of PIXEL + // HHHHH Yoshi 2017.01.10 HHHHH + if (PIXEL_CLUSTERING_MODE >= PIXEL_CLUSTERING_MIXED && isSplitCluster(clu)) { + //if (PIXEL_CLUSTERING_MODE >= PIXEL_CLUSTERING_MIXED && !isIBLmodule && isSplitCluster(clu)) { + av.setSplit(true); } - default: - assert(0); // should not get here! + + eta_average*=numberOfEtaPixelsInModule/lengthOfPixelModuleInUmPixels/pixYScaleFactor; + phi_average/=pixXScaleFactor; // Keisuke 20170314, bug fix of row coordinate range + //if (isPixelmodule) { + //// rescale full module length 152*400um to the range 0-144 + //// here 1 units is 400*19/18um (i.e. average 400/600um pixel length) + //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfPixelModuleIn400umPixels/pixYScaleFactor; + //} else if (isIBLmodule && FTKSetup::getFTKSetup().getIBLMode()==1) { + //// rescale from 25um units to 250um (1 "normal" IBL pixel) unit + //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfIblModuleIn250umPixels/pixYScaleFactor; + //} + //else if (isIBLmodule && FTKSetup::getFTKSetup().getIBLMode()==2) + //// rescale from 25um units to 250um (1 "normal" IBL pixel) unit + //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfIblModuleIn250umPixels/pixYScaleFactor; + //} + + double delta; + delta = eta_average - (int) eta_average; + av.setDeltaEta(delta); + av.setEtaStrip( (int) eta_average ); + delta = phi_average - (int) phi_average; + av.setDeltaPhi(delta); + av.setPhiSide( (int) phi_average ); + + break; // end of PIXEL + } + default: + assert(0); // should not get here! } // end of switch // finally divide by nHits @@ -1435,7 +1396,7 @@ void averageCluster(cluster &clu) { mt.maximize( *((*ihit)->getTruth()) ); } else { MultiTruth::Barcode uniquecode((*ihit)->getEventIndex(), - (*ihit)->getBarcode()); + (*ihit)->getBarcode()); mt.maximize(uniquecode,(*ihit)->getBarcodePt()); } } // end record truth for each raw channel in the cluster @@ -1492,74 +1453,74 @@ void realisticPixelDecoder(hitVector* ¤tHits, bool isIBLmodule) //Keisuke if(!isIBLmodule){ if (currentHits->size() > 1) - std::stable_sort(currentHits->begin(), currentHits->end(), sortbyFE); + std::stable_sort(currentHits->begin(), currentHits->end(), sortbyFE); - for(hit = currentHits->begin(); hit != currentHits->end(); hit++) { - if ((*hit)->getPhiSide() <= 163) - fifo.push(*hit); - else lifo.push(*hit); - } + for(hit = currentHits->begin(); hit != currentHits->end(); hit++) { + if ((*hit)->getPhiSide() <= 163) + fifo.push(*hit); + else lifo.push(*hit); + } - currentHits->clear(); + currentHits->clear(); - while(!lifo.empty() && !fifo.empty()){ - if ((*lifo.top()).getEtaStrip() <= (*fifo.front()).getEtaStrip()) { + while(!lifo.empty() && !fifo.empty()){ + if ((*lifo.top()).getEtaStrip() <= (*fifo.front()).getEtaStrip()) { + currentHits->push_back(lifo.top()); + lifo.pop(); + } + else { + currentHits->push_back(fifo.front()); + fifo.pop(); + } + } + + while(!lifo.empty()) { currentHits->push_back(lifo.top()); lifo.pop(); - } - else { + } + while(!fifo.empty()) { currentHits->push_back(fifo.front()); fifo.pop(); - } - } - - while(!lifo.empty()) { - currentHits->push_back(lifo.top()); - lifo.pop(); - } - while(!fifo.empty()) { - currentHits->push_back(fifo.front()); - fifo.pop(); - } + } }else{ - std::stack lifo_planar; - std::queue fifo_planar; - - if (currentHits->size() > 1) - std::stable_sort(currentHits->begin(), currentHits->end(), sortInput); - - for(hit = currentHits->begin(); hit != currentHits->end(); hit++) { - if ((*hit)->getEtaStrip() < 40) - fifo.push(*hit); - else if ((*hit)->getEtaStrip() >= 40 && (*hit)->getEtaStrip() < 80) - lifo.push(*hit); - else if ((*hit)->getEtaStrip() >= 80 && (*hit)->getEtaStrip() < 120) - fifo_planar.push(*hit); - else if ((*hit)->getEtaStrip() >= 120 && (*hit)->getEtaStrip() < 160) - lifo_planar.push(*hit); - } - - currentHits->clear(); - - while(!fifo.empty()){ - currentHits->push_back(fifo.front()); - fifo.pop(); - } - - while(!lifo.empty()) { - currentHits->push_back(lifo.top()); - lifo.pop(); - } - - while(!fifo_planar.empty()) { - currentHits->push_back(fifo_planar.front()); - fifo_planar.pop(); - } - - while(!lifo_planar.empty()) { - currentHits->push_back(lifo_planar.top()); - lifo_planar.pop(); - } + std::stack lifo_planar; + std::queue fifo_planar; + + if (currentHits->size() > 1) + std::stable_sort(currentHits->begin(), currentHits->end(), sortInput); + + for(hit = currentHits->begin(); hit != currentHits->end(); hit++) { + if ((*hit)->getEtaStrip() < 40) + fifo.push(*hit); + else if ((*hit)->getEtaStrip() >= 40 && (*hit)->getEtaStrip() < 80) + lifo.push(*hit); + else if ((*hit)->getEtaStrip() >= 80 && (*hit)->getEtaStrip() < 120) + fifo_planar.push(*hit); + else if ((*hit)->getEtaStrip() >= 120 && (*hit)->getEtaStrip() < 160) + lifo_planar.push(*hit); + } + + currentHits->clear(); + + while(!fifo.empty()){ + currentHits->push_back(fifo.front()); + fifo.pop(); + } + + while(!lifo.empty()) { + currentHits->push_back(lifo.top()); + lifo.pop(); + } + + while(!fifo_planar.empty()) { + currentHits->push_back(fifo_planar.front()); + fifo_planar.pop(); + } + + while(!lifo_planar.empty()) { + currentHits->push_back(lifo_planar.top()); + lifo_planar.pop(); + } }// if isIBLmodule } @@ -1578,11 +1539,11 @@ FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hi if ((*cbi)->getEtaStrip() < seed->getEtaStrip()) seed = *cbi; else if ((*cbi)->getEtaStrip() == seed->getEtaStrip()) { - //if ((*cbi)->getPhiSide() < seed->getPhiSide()) - if ((*cbi)->getPhiSide() < seed->getPhiSide() && !isIBLmodule) //Keisuke 20170215 + //if ((*cbi)->getPhiSide() < seed->getPhiSide()) + if ((*cbi)->getPhiSide() < seed->getPhiSide() && !isIBLmodule) //Keisuke 20170215 + seed = *cbi; + else if ((*cbi)->getPhiSide() > seed->getPhiSide() && isIBLmodule) seed = *cbi; - else if ((*cbi)->getPhiSide() > seed->getPhiSide() && isIBLmodule) - seed = *cbi; } } } @@ -1653,13 +1614,6 @@ void atlClusteringLNF(vector &hits) for(unsigned int i = 0; i < hits.size(); i++) { int modId = hitToModuleId(hits[i]); - // if(PRINT_INPUT && hitSelector(hits[i])){ - // if(tempModId != modId) printInputData(hits, sortHits, i); - // else sortHits.push_back(hits[i]); - - // tempModId = modId; - // } - if (modId>=0) { hitsByModule[modId].push_back( &(hits[i]) ); if (DUPLICATE_GANGED && hitIsGanged(hits[i])) { @@ -1699,14 +1653,14 @@ void atlClusteringLNF(vector &hits) FTKRawHit &firstHit = **(currentHits->begin()); int modId = hitToModuleId( firstHit ); - bool isIBLmodule = hitOnIBLmodule(firstHit); // Yoshi 2016.09.29 + bool isIBLmodule = hitOnIBLmodule(firstHit); // Yoshi 2016.09.29 - if(PRINT_INPUT) - printInputData(currentHits, isIBLmodule); + if(PRINT_INPUT) + printInputData(currentHits, isIBLmodule); #if defined(DECODER_OUTPUT) - printDecoderOutput(currentHits, isIBLmodule); - //printDecoderOutput(currentHits); + printDecoderOutput(currentHits, isIBLmodule); + //printDecoderOutput(currentHits); #endif //bool isIBLmodule = hitOnIBLmodule(firstHit); //bool isIBLmodule = FTKSetup::getFTKSetup().getIBLMode()!=0 && firstHit.getLayer()==0; @@ -1717,21 +1671,21 @@ void atlClusteringLNF(vector &hits) //1. PIXEL_CLUSTERING_MODE is less than 100 (PIXEL_CLUSTERING_MIXED) //2. The module is not a pixel module - // HHHHH Yoshi 2017.01.10 HHHHH + // HHHHH Yoshi 2017.01.10 HHHHH if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || !firstHit.getIsPixel()) { - //if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || !firstHit.getIsPixel() || isIBLmodule) { + //if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || !firstHit.getIsPixel() || isIBLmodule) { makeClustersLNF(currentHits, currentClusters); // use ideal clustering } else { // PIXEL_CLUSTERING_MODE >= 100 and pixel module - //realisticPixelDecoder(currentHits); - realisticPixelDecoder(currentHits, isIBLmodule); + //realisticPixelDecoder(currentHits); + realisticPixelDecoder(currentHits, isIBLmodule); boost::circular_buffer circular_buffer (256); hitVector gridhits; hitVector fifo = *currentHits; while (!fifo.empty() || !circular_buffer.empty()) { - //FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits); - FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits, isIBLmodule); + //FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits); + FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits, isIBLmodule); makeClusterFromSeed(&gridhits, currentClusters, seed); for(hitVector::iterator hsi = gridhits.begin(); hsi != gridhits.end(); hsi++) { @@ -1744,10 +1698,10 @@ void atlClusteringLNF(vector &hits) if (DEBUG_CLUSTERS) { std::cout << "DEBUG_CLUSTERS:" - << " modId=" << modId - << " HitListSize=" << currentHits->size() - << " ClusterListSize=" << currentClusters->size() - << "\n"; + << " modId=" << modId + << " HitListSize=" << currentHits->size() + << " ClusterListSize=" << currentClusters->size() + << "\n"; } } // end of loop over modules @@ -1872,189 +1826,189 @@ int hitIsGanged(const FTKRawHit &hit) { int gangedPartner(const FTKRawHit &hit) { if (hit.getIsPixel()) { switch (hit.getPhiSide()) { - case 153: - return 160; - case 160: - return 153; - case 155: - return 161; - case 161: - return 155; - case 157: - return 162; - case 162: - return 157; - case 159: - return 163; - case 163: - return 159; - case 168: - return 164; - case 164: - return 168; - case 170: - return 165; - case 165: - return 170; - case 172: - return 166; - case 166: - return 172; - case 174: - return 167; - case 167: - return 174; - default: - return hit.getPhiSide(); + case 153: + return 160; + case 160: + return 153; + case 155: + return 161; + case 161: + return 155; + case 157: + return 162; + case 162: + return 157; + case 159: + return 163; + case 163: + return 159; + case 168: + return 164; + case 164: + return 168; + case 170: + return 165; + case 165: + return 170; + case 172: + return 166; + case 166: + return 172; + case 174: + return 167; + case 167: + return 174; + default: + return hit.getPhiSide(); } } return -1; } double getDeltaX1A(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); - bool isIBLmodule = hitOnIBLmodule(*first); - float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; ///getLayer(); - bool isIBLmodule = hitOnIBLmodule(*first); - if (FTKSetup::getFTKSetup().getIBLMode()==0) - layer++; - float radius = ftk::clustering::radii[layer]; - float sensorThickness = ftk::sensorThicknessPixel; - float etaPitch = ftk::etaPitchPixel; - float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; - float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-6; - if (isIBLmodule) { - sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; - moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors - pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-8; - etaPitch = ftk::etaPitchIbl; - - } - return lround ( - 32*32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch/2. ) + lround( 32*32*2* pixYScaleFactor*sensorThickness*moduleActiveLength/radius /etaPitch/2/2); + FTKRawHit *first = *(clu.hitlist.begin()); + int layer = first->getLayer(); + bool isIBLmodule = hitOnIBLmodule(*first); + if (FTKSetup::getFTKSetup().getIBLMode()==0) + layer++; + float radius = ftk::clustering::radii[layer]; + float sensorThickness = ftk::sensorThicknessPixel; + float etaPitch = ftk::etaPitchPixel; + float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; + float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-6; + if (isIBLmodule) { + sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; + moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors + pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-8; + etaPitch = ftk::etaPitchIbl; + + } + return lround ( - 32*32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch/2. ) + lround( 32*32*2* pixYScaleFactor*sensorThickness*moduleActiveLength/radius /etaPitch/2/2); } int getDeltaY2A(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); - int layer = first->getLayer(); - bool isIBLmodule = hitOnIBLmodule(*first); - if (FTKSetup::getFTKSetup().getIBLMode()==0) - layer++; - float radius = ftk::clustering::radii[layer]; - float sensorThickness = ftk::sensorThicknessPixel; - float etaPitch = ftk::etaPitchPixel; - float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; - float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-6; - if (isIBLmodule) { - sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; - moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors - pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-8; - etaPitch = ftk::etaPitchIbl; - } - return lround (32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch) + lround ( - 32*2* pixYScaleFactor*sensorThickness* moduleActiveLength/radius /etaPitch/2.); + FTKRawHit *first = *(clu.hitlist.begin()); + int layer = first->getLayer(); + bool isIBLmodule = hitOnIBLmodule(*first); + if (FTKSetup::getFTKSetup().getIBLMode()==0) + layer++; + float radius = ftk::clustering::radii[layer]; + float sensorThickness = ftk::sensorThicknessPixel; + float etaPitch = ftk::etaPitchPixel; + float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; + float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-6; + if (isIBLmodule) { + sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; + moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors + pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-8; + etaPitch = ftk::etaPitchIbl; + } + return lround (32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch) + lround ( - 32*2* pixYScaleFactor*sensorThickness* moduleActiveLength/radius /etaPitch/2.); } int getDeltaY1B(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); - int layer = first->getLayer(); - bool isIBLmodule = hitOnIBLmodule(*first); - if (FTKSetup::getFTKSetup().getIBLMode()==0) - layer++; - float radius = ftk::clustering::radii[layer]; - float sensorThickness = ftk::sensorThicknessPixel; - float etaPitch = ftk::etaPitchPixel; - float numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInPixelModule; - float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; - if (isIBLmodule) { - sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; - numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInIblModule; - moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors - etaPitch = ftk::etaPitchIbl; - } - return lround ( - 32*32* sensorThickness/numberOfEtaPixelsInModule *moduleActiveLength/radius /etaPitch/2); + FTKRawHit *first = *(clu.hitlist.begin()); + int layer = first->getLayer(); + bool isIBLmodule = hitOnIBLmodule(*first); + if (FTKSetup::getFTKSetup().getIBLMode()==0) + layer++; + float radius = ftk::clustering::radii[layer]; + float sensorThickness = ftk::sensorThicknessPixel; + float etaPitch = ftk::etaPitchPixel; + float numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInPixelModule; + float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; + if (isIBLmodule) { + sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; + numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInIblModule; + moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors + etaPitch = ftk::etaPitchIbl; + } + return lround ( - 32*32* sensorThickness/numberOfEtaPixelsInModule *moduleActiveLength/radius /etaPitch/2); } int getDeltaY2B(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); - int layer = first->getLayer(); - bool isIBLmodule = hitOnIBLmodule(*first); - if (FTKSetup::getFTKSetup().getIBLMode()==0) - layer++; - float radius = ftk::clustering::radii[layer]; - float sensorThickness = ftk::sensorThicknessPixel; - float etaPitch = ftk::etaPitchPixel; - float numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInPixelModule; - float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; - if (isIBLmodule) { - sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; - numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInIblModule; - moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors - etaPitch = ftk::etaPitchIbl; - } - return lround (32 * sensorThickness/numberOfEtaPixelsInModule *moduleActiveLength/radius/etaPitch ) ; + FTKRawHit *first = *(clu.hitlist.begin()); + int layer = first->getLayer(); + bool isIBLmodule = hitOnIBLmodule(*first); + if (FTKSetup::getFTKSetup().getIBLMode()==0) + layer++; + float radius = ftk::clustering::radii[layer]; + float sensorThickness = ftk::sensorThicknessPixel; + float etaPitch = ftk::etaPitchPixel; + float numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInPixelModule; + float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; + if (isIBLmodule) { + sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; + numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInIblModule; + moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors + etaPitch = ftk::etaPitchIbl; + } + return lround (32 * sensorThickness/numberOfEtaPixelsInModule *moduleActiveLength/radius/etaPitch ) ; } -- GitLab From f9e3a58a19387a6d1991cbc8726c0c0e7f666dbe Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Wed, 20 Feb 2019 16:04:52 +0100 Subject: [PATCH 03/18] Remove unused functions eta, not useful ifdef debug statements --- .../TrigFTK/TrigFTKSim/src/atlClustering.cxx | 46 ------------------- 1 file changed, 46 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx index 63da9bab328..b37c5f2b033 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx @@ -35,7 +35,6 @@ using ftk::ENDCAP; using ftk::POSEC; using ftk::NEGEC; -//#define VERBOSE_DEBUG_CLUST //#define DEBUG_HITS //#define DECODER_INPUT 0 //#define DECODER_OUTPUT 0 @@ -180,21 +179,6 @@ bool sortbyFE (const FTKRawHit* i,const FTKRawHit* j) { } -double eta(double px, double py, double pz) { - double theta = atan( sqrt(px*px+py*py)/pz ); - if (theta<0) theta += 3.1415; - - // std::cout << "px=" << px << " py=" << py << " pz=" << pz - // << " theta=" << theta << " eta=" << - log( tan (theta/2) ) << "\n"; - - return - log( tan (theta/2) ); -} - -double eta(FTKRawHit &hit) { - // eta of hit position - return eta(hit.getX(), hit.getY(), hit.getZ()); -} - /*! * Function examining whether a cluster is split. * \param clu the cluster to be examined @@ -1630,13 +1614,6 @@ void atlClusteringLNF(vector &hits) } } -#ifdef HAVE_ROOT - if(ROOTOUTCLU) rootOutput_clu_moduleStat(hitsByModule); -#endif -#ifdef VERBOSE_DEBUG_CLUST - std::cout << "Ready to do clusters\n"; -#endif - /* * Second: build the list of clusters */ @@ -1709,10 +1686,6 @@ void atlClusteringLNF(vector &hits) // cout << "0x2E0F00000" << endl; // #endif -#ifdef VERBOSE_DEBUG_CLUST - std::cout << "Clusters made\n"; -#endif - #if defined(CLUSTERING_PRINTOUT) printClusterList(clustersByModule); #endif @@ -1745,17 +1718,6 @@ void atlClusteringLNF(vector &hits) } } -#ifdef VERBOSE_DEBUG_CLUST - std::cout << "Ready to call rootOutput_clu_moduleClusterStat\n"; -#endif -#ifdef HAVE_ROOT - if(ROOTOUTCLU) rootOutput_clu_moduleClusterStat(clustersByModule, hitsByModuleFrozen, event); -#endif - -#ifdef VERBOSE_DEBUG_CLUST - std::cout << "Averages made\n"; -#endif - #if defined(CENTROID_PRINTOUT) printCentroidList(clustersByModule); #endif @@ -1787,10 +1749,6 @@ void atlClusteringLNF(vector &hits) } assert( (hitCounter+deletedGangedClusters) == nTotClu ); -#ifdef VERBOSE_DEBUG_CLUST - std::cout << "Added clusters to the event hit list\n"; -#endif - /* * Fifth: free memory (could optimize and do this in previous step) */ @@ -1798,10 +1756,6 @@ void atlClusteringLNF(vector &hits) // The atlhit data from event is allocated and destroyed outside this function. // clustersByModuleMap is automatically deleted. clustersByModule.clear(); - -#ifdef VERBOSE_DEBUG_CLUST - std::cout << "Deleted cluster structure\n\n"; -#endif } /*! -- GitLab From bd61445f4d7887c166f2058c1341720f3751e27c Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Thu, 21 Feb 2019 17:38:38 +0100 Subject: [PATCH 04/18] Removed isIBLmodule check from places where it's not needed --- .../TrigFTK/TrigFTKSim/src/atlClustering.cxx | 92 +++++-------------- 1 file changed, 22 insertions(+), 70 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx index b37c5f2b033..aedc8519ae2 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx @@ -338,7 +338,7 @@ bool sortWords(const FTKRawHit* i, const FTKRawHit* j) } //void printDecoderOutput(hitVector* currentHits) -void printDecoderOutput(hitVector* currentHits, bool isIBLmodule) +void printDecoderOutput(hitVector* currentHits) { hitVector::iterator hit = currentHits->begin(); hitVector *sortHits = currentHits; @@ -353,7 +353,6 @@ void printDecoderOutput(hitVector* currentHits, bool isIBLmodule) if(isIBLmodule){ // for IBL printf("0x8%.7x\n", idHash); - //stable_sort(sortHits->begin(), sortHits->end(), sortWords); for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ int tempCol = (*it)->getEtaStrip(); @@ -417,8 +416,9 @@ bool sortInput(const FTKRawHit* i, const FTKRawHit* j) } } -void printInputData(hitVector* currentHits, bool isIBLmodule){ +void printInputData(hitVector* currentHits){ hitVector::iterator hit = currentHits->begin(); + bool isIBLmodule = hitOnIBLmodule(**hit); hitVector *sortHits = currentHits; int idHash = hitToModuleId(**hit) + 8; if(isIBLmodule){ @@ -1412,30 +1412,14 @@ void atlClusteringBlayer(vector &hits) { } } - - -//void realisticPixelDecoder(hitVector* ¤tHits) -void realisticPixelDecoder(hitVector* ¤tHits, bool isIBLmodule) //Keisuke 20170215 +void realisticPixelDecoder(hitVector* ¤tHits) { hitVector::iterator hit = currentHits->begin(); -#if defined(DECODER_INPUT) - printf("0x8%.7x\n", hitToModuleId(*hit)); - std::cout << "HitType: " << (*hit)->getHitType() << " Barrel-EC: " << (*hit)->getBarrelEC() << " Layer: " << (*hit)->getLayer() << " PhiModule:" << (*hit)->getPhiModule() << " EtaModule: " << (*hit)->getEtaModule() << std::endl; - //for (hit = currentHits->begin(); hit!= currentHits->end(); hit++) { - //fe_hit fehit = fe_hit((*hit)); - //printf("0x08%.1X%.2X%.2X%.2X -- %d %d %d", fehit.fe, fehit.tot, fehit.lcol, fehit.lrow , fehit.tot, fehit.lcol, fehit.lrow); - //std::cout << " hitType " << (*hit)->getHitType() << " BEC " << (*hit)->getBarrelEC() << " layer " << (*hit)->getLayer() << " phimod " << (*hit)->getPhiModule() << " etamod " << (*hit)->getEtaModule() << std::endl; - //} -#endif - - // if (currentHits->size() > 1) - // std::stable_sort(currentHits->begin(), currentHits->end(), sortbyFE); - std::stack lifo; std::queue fifo; - if(!isIBLmodule){ + if((*hit)->getIsPixel()){ if (currentHits->size() > 1) std::stable_sort(currentHits->begin(), currentHits->end(), sortbyFE); @@ -1510,8 +1494,7 @@ void realisticPixelDecoder(hitVector* ¤tHits, bool isIBLmodule) //Keisuke } -//FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits) -FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits, bool isIBLmodule) +FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits) { //seed is set from cb if there are hits and from //fifo if the seed is empty. @@ -1519,11 +1502,11 @@ FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hi if (cb.size() != 0) { boost::circular_buffer::iterator cbi = cb.begin(); seed = *cbi; + bool isIBLmodule = hitOnIBLmodule(*seed); for( cbi = cb.begin(); cbi != cb.end(); cbi++){ if ((*cbi)->getEtaStrip() < seed->getEtaStrip()) seed = *cbi; else if ((*cbi)->getEtaStrip() == seed->getEtaStrip()) { - //if ((*cbi)->getPhiSide() < seed->getPhiSide()) if ((*cbi)->getPhiSide() < seed->getPhiSide() && !isIBLmodule) //Keisuke 20170215 seed = *cbi; else if ((*cbi)->getPhiSide() > seed->getPhiSide() && isIBLmodule) @@ -1592,25 +1575,17 @@ void atlClusteringLNF(vector &hits) /* * First: organize raw hits by module */ - vector sortHits; - int tempModId = 999999; - for(unsigned int i = 0; i < hits.size(); i++) { int modId = hitToModuleId(hits[i]); - - if (modId>=0) { - hitsByModule[modId].push_back( &(hits[i]) ); - if (DUPLICATE_GANGED && hitIsGanged(hits[i])) { - //use the copy constructor instead of manually assigning each - //variable, as was done previously. the usage here is the - //whole point of having a copy constructor! - gangedPixelList.push_back( hits[i] ); - FTKRawHit &lastPointer = gangedPixelList.back(); - lastPointer.setPhiSide(gangedPartner( hits[i] )); - hitsByModule[modId].push_back( &lastPointer ); - } - } else { - assert(0); // should not need this any more + hitsByModule[modId].push_back( &(hits[i]) ); + if (DUPLICATE_GANGED && hitIsGanged(hits[i])) { + //use the copy constructor instead of manually assigning each + //variable, as was done previously. the usage here is the + //whole point of having a copy constructor! + gangedPixelList.push_back( hits[i] ); + FTKRawHit &lastPointer = gangedPixelList.back(); + lastPointer.setPhiSide(gangedPartner( hits[i] )); + hitsByModule[modId].push_back( &lastPointer ); } } @@ -1620,49 +1595,30 @@ void atlClusteringLNF(vector &hits) clustersByModuleMap clustersByModule; ///< store clusters by module hitsByModuleFrozen = hitsByModule; ///< keep hits structure hitsByModuleMap::iterator p; - - // #if defined(DECODER_OUTPUT) // control word (begin) // Yoshi 2016.10.01 - // cout << "0x1B0F00000" << endl; - // #endif - for (p = hitsByModule.begin(); p!=hitsByModule.end(); ++p) { // loop over modules hitVector *currentHits = & (p->second); FTKRawHit &firstHit = **(currentHits->begin()); int modId = hitToModuleId( firstHit ); - bool isIBLmodule = hitOnIBLmodule(firstHit); // Yoshi 2016.09.29 - - if(PRINT_INPUT) - printInputData(currentHits, isIBLmodule); - -#if defined(DECODER_OUTPUT) - printDecoderOutput(currentHits, isIBLmodule); - //printDecoderOutput(currentHits); -#endif - //bool isIBLmodule = hitOnIBLmodule(firstHit); - //bool isIBLmodule = FTKSetup::getFTKSetup().getIBLMode()!=0 && firstHit.getLayer()==0; + // if(PRINT_INPUT) + // printInputData(currentHits); cluList *currentClusters = new cluList(); // instantiate cluster list clustersByModule[modId] = currentClusters; //The ideal clustering is going to be used in the following cases: //1. PIXEL_CLUSTERING_MODE is less than 100 (PIXEL_CLUSTERING_MIXED) //2. The module is not a pixel module - - // HHHHH Yoshi 2017.01.10 HHHHH - if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || !firstHit.getIsPixel()) { - //if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || !firstHit.getIsPixel() || isIBLmodule) { + if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || firstHit.getIsSCT()) { makeClustersLNF(currentHits, currentClusters); // use ideal clustering } - else { // PIXEL_CLUSTERING_MODE >= 100 and pixel module - //realisticPixelDecoder(currentHits); - realisticPixelDecoder(currentHits, isIBLmodule); + else { // PIXEL_CLUSTERING_MODE >= 100 + realisticPixelDecoder(currentHits); boost::circular_buffer circular_buffer (256); hitVector gridhits; hitVector fifo = *currentHits; while (!fifo.empty() || !circular_buffer.empty()) { - //FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits); - FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits, isIBLmodule); + FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits); makeClusterFromSeed(&gridhits, currentClusters, seed); for(hitVector::iterator hsi = gridhits.begin(); hsi != gridhits.end(); hsi++) { @@ -1682,10 +1638,6 @@ void atlClusteringLNF(vector &hits) } } // end of loop over modules - // #if defined(DECODER_OUTPUT) // control word (end) // Yoshi 2016.10.01 - // cout << "0x2E0F00000" << endl; - // #endif - #if defined(CLUSTERING_PRINTOUT) printClusterList(clustersByModule); #endif -- GitLab From 2d5642ed86f5e9f122621c54478a6e08d27b35f4 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Sun, 24 Feb 2019 14:07:50 +0000 Subject: [PATCH 05/18] Revert "Removed isIBLmodule check from places where it's not needed" This reverts commit bd61445f4d7887c166f2058c1341720f3751e27c --- .../TrigFTK/TrigFTKSim/src/atlClustering.cxx | 92 ++++++++++++++----- 1 file changed, 70 insertions(+), 22 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx index aedc8519ae2..b37c5f2b033 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx @@ -338,7 +338,7 @@ bool sortWords(const FTKRawHit* i, const FTKRawHit* j) } //void printDecoderOutput(hitVector* currentHits) -void printDecoderOutput(hitVector* currentHits) +void printDecoderOutput(hitVector* currentHits, bool isIBLmodule) { hitVector::iterator hit = currentHits->begin(); hitVector *sortHits = currentHits; @@ -353,6 +353,7 @@ void printDecoderOutput(hitVector* currentHits) if(isIBLmodule){ // for IBL printf("0x8%.7x\n", idHash); + //stable_sort(sortHits->begin(), sortHits->end(), sortWords); for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ int tempCol = (*it)->getEtaStrip(); @@ -416,9 +417,8 @@ bool sortInput(const FTKRawHit* i, const FTKRawHit* j) } } -void printInputData(hitVector* currentHits){ +void printInputData(hitVector* currentHits, bool isIBLmodule){ hitVector::iterator hit = currentHits->begin(); - bool isIBLmodule = hitOnIBLmodule(**hit); hitVector *sortHits = currentHits; int idHash = hitToModuleId(**hit) + 8; if(isIBLmodule){ @@ -1412,14 +1412,30 @@ void atlClusteringBlayer(vector &hits) { } } -void realisticPixelDecoder(hitVector* ¤tHits) + + +//void realisticPixelDecoder(hitVector* ¤tHits) +void realisticPixelDecoder(hitVector* ¤tHits, bool isIBLmodule) //Keisuke 20170215 { hitVector::iterator hit = currentHits->begin(); +#if defined(DECODER_INPUT) + printf("0x8%.7x\n", hitToModuleId(*hit)); + std::cout << "HitType: " << (*hit)->getHitType() << " Barrel-EC: " << (*hit)->getBarrelEC() << " Layer: " << (*hit)->getLayer() << " PhiModule:" << (*hit)->getPhiModule() << " EtaModule: " << (*hit)->getEtaModule() << std::endl; + //for (hit = currentHits->begin(); hit!= currentHits->end(); hit++) { + //fe_hit fehit = fe_hit((*hit)); + //printf("0x08%.1X%.2X%.2X%.2X -- %d %d %d", fehit.fe, fehit.tot, fehit.lcol, fehit.lrow , fehit.tot, fehit.lcol, fehit.lrow); + //std::cout << " hitType " << (*hit)->getHitType() << " BEC " << (*hit)->getBarrelEC() << " layer " << (*hit)->getLayer() << " phimod " << (*hit)->getPhiModule() << " etamod " << (*hit)->getEtaModule() << std::endl; + //} +#endif + + // if (currentHits->size() > 1) + // std::stable_sort(currentHits->begin(), currentHits->end(), sortbyFE); + std::stack lifo; std::queue fifo; - if((*hit)->getIsPixel()){ + if(!isIBLmodule){ if (currentHits->size() > 1) std::stable_sort(currentHits->begin(), currentHits->end(), sortbyFE); @@ -1494,7 +1510,8 @@ void realisticPixelDecoder(hitVector* ¤tHits) } -FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits) +//FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits) +FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits, bool isIBLmodule) { //seed is set from cb if there are hits and from //fifo if the seed is empty. @@ -1502,11 +1519,11 @@ FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hi if (cb.size() != 0) { boost::circular_buffer::iterator cbi = cb.begin(); seed = *cbi; - bool isIBLmodule = hitOnIBLmodule(*seed); for( cbi = cb.begin(); cbi != cb.end(); cbi++){ if ((*cbi)->getEtaStrip() < seed->getEtaStrip()) seed = *cbi; else if ((*cbi)->getEtaStrip() == seed->getEtaStrip()) { + //if ((*cbi)->getPhiSide() < seed->getPhiSide()) if ((*cbi)->getPhiSide() < seed->getPhiSide() && !isIBLmodule) //Keisuke 20170215 seed = *cbi; else if ((*cbi)->getPhiSide() > seed->getPhiSide() && isIBLmodule) @@ -1575,17 +1592,25 @@ void atlClusteringLNF(vector &hits) /* * First: organize raw hits by module */ + vector sortHits; + int tempModId = 999999; + for(unsigned int i = 0; i < hits.size(); i++) { int modId = hitToModuleId(hits[i]); - hitsByModule[modId].push_back( &(hits[i]) ); - if (DUPLICATE_GANGED && hitIsGanged(hits[i])) { - //use the copy constructor instead of manually assigning each - //variable, as was done previously. the usage here is the - //whole point of having a copy constructor! - gangedPixelList.push_back( hits[i] ); - FTKRawHit &lastPointer = gangedPixelList.back(); - lastPointer.setPhiSide(gangedPartner( hits[i] )); - hitsByModule[modId].push_back( &lastPointer ); + + if (modId>=0) { + hitsByModule[modId].push_back( &(hits[i]) ); + if (DUPLICATE_GANGED && hitIsGanged(hits[i])) { + //use the copy constructor instead of manually assigning each + //variable, as was done previously. the usage here is the + //whole point of having a copy constructor! + gangedPixelList.push_back( hits[i] ); + FTKRawHit &lastPointer = gangedPixelList.back(); + lastPointer.setPhiSide(gangedPartner( hits[i] )); + hitsByModule[modId].push_back( &lastPointer ); + } + } else { + assert(0); // should not need this any more } } @@ -1595,30 +1620,49 @@ void atlClusteringLNF(vector &hits) clustersByModuleMap clustersByModule; ///< store clusters by module hitsByModuleFrozen = hitsByModule; ///< keep hits structure hitsByModuleMap::iterator p; + + // #if defined(DECODER_OUTPUT) // control word (begin) // Yoshi 2016.10.01 + // cout << "0x1B0F00000" << endl; + // #endif + for (p = hitsByModule.begin(); p!=hitsByModule.end(); ++p) { // loop over modules hitVector *currentHits = & (p->second); FTKRawHit &firstHit = **(currentHits->begin()); int modId = hitToModuleId( firstHit ); - // if(PRINT_INPUT) - // printInputData(currentHits); + bool isIBLmodule = hitOnIBLmodule(firstHit); // Yoshi 2016.09.29 + + if(PRINT_INPUT) + printInputData(currentHits, isIBLmodule); + +#if defined(DECODER_OUTPUT) + printDecoderOutput(currentHits, isIBLmodule); + //printDecoderOutput(currentHits); +#endif + //bool isIBLmodule = hitOnIBLmodule(firstHit); + //bool isIBLmodule = FTKSetup::getFTKSetup().getIBLMode()!=0 && firstHit.getLayer()==0; cluList *currentClusters = new cluList(); // instantiate cluster list clustersByModule[modId] = currentClusters; //The ideal clustering is going to be used in the following cases: //1. PIXEL_CLUSTERING_MODE is less than 100 (PIXEL_CLUSTERING_MIXED) //2. The module is not a pixel module - if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || firstHit.getIsSCT()) { + + // HHHHH Yoshi 2017.01.10 HHHHH + if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || !firstHit.getIsPixel()) { + //if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || !firstHit.getIsPixel() || isIBLmodule) { makeClustersLNF(currentHits, currentClusters); // use ideal clustering } - else { // PIXEL_CLUSTERING_MODE >= 100 - realisticPixelDecoder(currentHits); + else { // PIXEL_CLUSTERING_MODE >= 100 and pixel module + //realisticPixelDecoder(currentHits); + realisticPixelDecoder(currentHits, isIBLmodule); boost::circular_buffer circular_buffer (256); hitVector gridhits; hitVector fifo = *currentHits; while (!fifo.empty() || !circular_buffer.empty()) { - FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits); + //FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits); + FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits, isIBLmodule); makeClusterFromSeed(&gridhits, currentClusters, seed); for(hitVector::iterator hsi = gridhits.begin(); hsi != gridhits.end(); hsi++) { @@ -1638,6 +1682,10 @@ void atlClusteringLNF(vector &hits) } } // end of loop over modules + // #if defined(DECODER_OUTPUT) // control word (end) // Yoshi 2016.10.01 + // cout << "0x2E0F00000" << endl; + // #endif + #if defined(CLUSTERING_PRINTOUT) printClusterList(clustersByModule); #endif -- GitLab From d8c8b0f51ab9534962ad70a0c67776baee150569 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Sun, 24 Feb 2019 16:30:14 +0100 Subject: [PATCH 06/18] Removed isIBLmodule check from places where it's not needed; more unused code removal --- .../TrigFTK/TrigFTKSim/TrigFTKSim/ftkdefs.h | 4 +- .../TrigFTK/TrigFTKSim/src/atlClustering.cxx | 241 ++++-------------- 2 files changed, 51 insertions(+), 194 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/ftkdefs.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/ftkdefs.h index a9cc7f6e0a5..4d56548e402 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/ftkdefs.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/ftkdefs.h @@ -55,7 +55,7 @@ namespace ftk { const float numberOfPhiPixelsInIblModule = 336.; ///< Number of rows in an IBL module /** - * \namespace ftk::clustering + * \namespace ftk::clustering * \brief Default values used for the centroid calculation of a cluster. */ namespace clustering { @@ -65,7 +65,7 @@ namespace ftk { const float xScaleFactorIbl = 8.; ///end(); b++) { - //printToFile(outcentroid, (*b).clusterEquiv.getHWWord()); printf("0x%.8X ",(*b).clusterEquiv.getHWWord()); - //std::cout << (*b).clusterEquiv.getTot() << " " << (*b).clusterEquiv.getEtaStrip() << " " << (*b).clusterEquiv.getPhiSide() << std::endl; + //std::cout << (*b).clusterEquiv.getTot() << " " + // << (*b).clusterEquiv.getEtaStrip() << " " + // << (*b).clusterEquiv.getPhiSide() << std::endl; if (DEBUG_CENTROID) printDebugInfo(*hit); } printf("0x40000000\n"); @@ -417,8 +412,9 @@ bool sortInput(const FTKRawHit* i, const FTKRawHit* j) } } -void printInputData(hitVector* currentHits, bool isIBLmodule){ +void printInputData(hitVector* currentHits){ hitVector::iterator hit = currentHits->begin(); + bool isIBLmodule = hitOnIBLmodule(**hit); hitVector *sortHits = currentHits; int idHash = hitToModuleId(**hit) + 8; if(isIBLmodule){ @@ -476,28 +472,6 @@ void printInputData(hitVector* currentHits, bool isIBLmodule){ printf("0x05%.1x400000\n", idHash); } -#ifdef BOUNDING_BOX -void calcBoundingBox(cluster& clu) -{ - int col_min = (clu.hitlist[0])->getEtaStrip(); - int col_max = (clu.hitlist[0])->getEtaStrip(); - int row_min = (clu.hitlist[0])->getPhiSide(); - int row_max = (clu.hitlist[0])->getPhiSide(); - - hitVector::iterator hit; - for (hit = clu.hitlist.begin(); hit != clu.hitlist.end(); hit++) { - - if ((*hit)->getEtaStrip() < col_min) col_min = (*hit)->getEtaStrip(); - else if ((*hit)->getEtaStrip() > col_max) col_max = (*hit)->getEtaStrip(); - - if ((*hit)->getPhiSide() < row_min) row_min = (*hit)->getPhiSide(); - else if ((*hit)->getPhiSide() > row_max) row_max = (*hit)->getPhiSide(); - } - std::cout << "BOUNDING_BOX" << col_max - col_min + 1 << " " << row_max - row_min + 1<< std::endl; -} -#endif - - /*! * Function printing the hit details * \param hit the hit @@ -556,11 +530,8 @@ bool pixelRowIsGanged(const int row) * \return the module id * */ -int hitToModuleId(const FTKRawHit &hit) { - - if (DEBUG_HITS) - printHit(hit); - +int hitToModuleId(const FTKRawHit &hit) +{ //Default mode, return the Identifier Hash of the hit if (hit.getIdentifierHash() > 0 && hit.getHitType() == PIXEL) { return hit.getIdentifierHash(); @@ -599,12 +570,7 @@ int hitToModuleId(const FTKRawHit &hit) { ieta = MAX_BARREL_ETA+3+hit.getEtaModule(); } - // if (FTKSetup::getFTKSetup().getIBLMode()==1){ - // assert(ieta16), and the +2 is for ibl (6->8), remove the +2 for 11L ibl - // } - // else { assert(ietabegin(), currentHits->end(), seed); if (position != currentHits->end()) { @@ -791,14 +746,11 @@ void makeClusterFromSeed(hitVector *currentHits, cluList *currentClusters, FTKRa clu.isKilled = false; if (currentHits->size() > 0) buildUpCluster(currentHits, clu); currentClusters->push_back(clu); - -#ifdef BOUNDING_BOX - calcBoundingBox(clu); -#endif } -bool gangedHitHasNeighborhood(const FTKRawHit &hit, const cluster &clu, hitVector &connectedHits) { +bool gangedHitHasNeighborhood(const FTKRawHit &hit, const cluster &clu, hitVector &connectedHits) +{ bool hasNeighborhood = false; int phi = hitIsGanged(hit); // std::cout << "phi: " << phi << std::endl; @@ -826,7 +778,8 @@ bool gangedHitHasNeighborhood(const FTKRawHit &hit, const cluster &clu, hitVecto return hasNeighborhood; } -bool findConnectedGanged(cluster &clu, hitVector &connectedHits) { +bool findConnectedGanged(cluster &clu, hitVector &connectedHits) +{ assert(clu.hitlist.size()>0); // sanity check hitVector::iterator p; @@ -840,7 +793,8 @@ bool findConnectedGanged(cluster &clu, hitVector &connectedHits) { return hasNeighborhood; } -bool cluIsGanged(const cluster &clu) { +bool cluIsGanged(const cluster &clu) +{ hitVector hv = clu.hitlist; hitVector::iterator p; for (p=hv.begin(); p!=hv.end(); ++p) { @@ -850,7 +804,8 @@ bool cluIsGanged(const cluster &clu) { return false; } -bool isKilled(const cluster &clu, const hitVector &connectedHits) { +bool isKilled(const cluster &clu, const hitVector &connectedHits) +{ hitVector tmphv = clu.hitlist; hitVector::iterator p; for (p=tmphv.begin(); p!=tmphv.end(); ++p) { @@ -875,7 +830,8 @@ bool isKilled(const cluster &clu, const hitVector &connectedHits) { * \param cluster the cluster whose average is going to be calculated * \return void */ -void averageCluster(cluster &clu) { +void averageCluster(cluster &clu) +{ const unsigned int &nHits = clu.hitlist.size(); assert(nHits>0); // sanity check @@ -929,7 +885,6 @@ void averageCluster(cluster &clu) { // always count IBL as layer0 and BLayer as layer1 int layer = first->getLayer(); bool isIBLmodule = hitOnIBLmodule(*first); - bool isIBL_Planar = false; bool isPixelmodule = !isIBLmodule; if (FTKSetup::getFTKSetup().getIBLMode()==0) layer++; @@ -956,11 +911,10 @@ void averageCluster(cluster &clu) { pixYScaleFactor = ftk::clustering::yScaleFactorIbl; ///getEtaModule()-8; - isIBL_Planar = (first->getEtaModule() >= -6 && first->getEtaModule() <= 5 ? true : false); - if(!isIBL_Planar && IBL3D_REALISTIC){ // 3D - sensorThickness = 230*ftk::micrometer; // 3D - moduleActiveLength = 80*250; // 3D - numberOfEtaPixelsInModule = 80; // 3D + if( first->getModuleType() == ftk::MODULETYPE_IBL3D && IBL3D_REALISTIC ) { + sensorThickness = 230*ftk::micrometer; + moduleActiveLength = 80*250; + numberOfEtaPixelsInModule = ftk::clustering::colsInFEChipPerIblModuleRow; } } bool hasGanged = false; @@ -1006,8 +960,6 @@ void averageCluster(cluster &clu) { case PIXEL: { av.setPhiSide(0); // eta is reset a few lines above - // HHHHH Different Clustering mode HHHHH - if (PIXEL_CLUSTERING_MODE == 0) { for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { //loop over hits in cluster assert(av.getLayer()==(*p)->getLayer() && av.getPhiModule()==(*p)->getPhiModule() && av.getEtaModule()==(*p)->getEtaModule() ); @@ -1038,8 +990,6 @@ void averageCluster(cluster &clu) { break; } - // HHHHH above HHHHH - /* For PIXEL_CLUSTERING_MODE > 0 * calculate cluster center following code at line 701 of * https://svnweb.cern.ch/trac/atlasoff/browser/InnerDetector/InDetRecTools/SiClusterizationTool/trunk/src/MergedPixelsTool.cxx#L701 @@ -1118,7 +1068,7 @@ void averageCluster(cluster &clu) { int orig_col = col; col *= pixYScaleFactor; // use units of 25um col += pixYScaleFactor/2; // add half a pixel to align to pixel center - if((isIBL_Planar && IBL3D_REALISTIC) || !IBL3D_REALISTIC){ + if(((*p)->getModuleType() == ftk::MODULETYPE_IBL3D && IBL3D_REALISTIC) || !IBL3D_REALISTIC){ if (orig_col==0) col += pixYScaleFactor/2; // add half pixel (500um pixel in col0) if (orig_col>0) col += pixYScaleFactor; // add a pixel (500um pixel in col0) @@ -1178,14 +1128,6 @@ void averageCluster(cluster &clu) { if (eta < etaMin) etaMin = eta; if (phi > phiMax) phiMax = phi; if (phi < phiMin) phiMin = phi; - // if ((*p)->getEtaStrip() > etaMax) - // etaMax = (*p)->getEtaStrip(); - // if ((*p)->getEtaStrip() < etaMin) - // etaMin = (*p)->getEtaStrip(); - // if ((*p)->getPhiSide() > phiMax) - // phiMax = (*p)->getPhiSide(); - // if ((*p)->getPhiSide() < phiMin) - // phiMin = (*p)->getPhiSide(); if (DEBUG_AVERAGE) printHit(**p); av.addTot(first->getTot()); // sum ToT for pixel clusters @@ -1198,12 +1140,6 @@ void averageCluster(cluster &clu) { eta_average = (colMin + colMax) / 2.; phi_average = (rowMin + rowMax) / 2.; - // Yoshi added 2017.02.01 - // if(colMin == pixYScaleFactor && colMin != colMax) eta_average = (colMin + colMax) / 2. - 1.; - // if(colMax == 1626 && colMin != colMax) eta_average = (colMin + colMax) / 2. - 1.; - - // New Implementation - if (PIXEL_CLUSTERING_MODE == PIXEL_CLUSTERING_HARDWARE) { float etaRow = -1; float etaCol = -1; @@ -1250,9 +1186,6 @@ void averageCluster(cluster &clu) { } } - - - //Correction to the eta_average and phi_average used for //PIXEL_CLUSTERING_MODE 1 and 100 if (PIXEL_CLUSTERING_MODE <= PIXEL_CLUSTERING_MIXED) { @@ -1318,37 +1251,14 @@ void averageCluster(cluster &clu) { } if (BarrelEndCap!=0) phi_average += ftk::clustering::pixelEndCapRPhiCorrection*pixXScaleFactor; - //if (isIBLmodule) phi_average += ftk::clustering::pixelIblRPhiCorrection*pixXScaleFactor; //temp Yoshi 2016.10.07 - - // av.setEtaWidth(etaMax-etaMin+1); // duplicate!! needless - // av.setPhiWidth(phiMax-phiMin+1); - - //if (PIXEL_CLUSTERING_MODE == PIXEL_CLUSTERING_HARDWARE) { av.setRowCoordinate( lround(phi_average) ); - //} else av.setRowCoordinate( lround(phi_average*pixXScaleFactor) ); av.setColumnCoordinate( lround(eta_average) ); av.setSplit(false); - - // HHHHH Yoshi 2017.01.10 HHHHH - if (PIXEL_CLUSTERING_MODE >= PIXEL_CLUSTERING_MIXED && isSplitCluster(clu)) { - //if (PIXEL_CLUSTERING_MODE >= PIXEL_CLUSTERING_MIXED && !isIBLmodule && isSplitCluster(clu)) { + if (PIXEL_CLUSTERING_MODE >= PIXEL_CLUSTERING_MIXED && isSplitCluster(clu)) av.setSplit(true); - } eta_average*=numberOfEtaPixelsInModule/lengthOfPixelModuleInUmPixels/pixYScaleFactor; - phi_average/=pixXScaleFactor; // Keisuke 20170314, bug fix of row coordinate range - //if (isPixelmodule) { - //// rescale full module length 152*400um to the range 0-144 - //// here 1 units is 400*19/18um (i.e. average 400/600um pixel length) - //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfPixelModuleIn400umPixels/pixYScaleFactor; - //} else if (isIBLmodule && FTKSetup::getFTKSetup().getIBLMode()==1) { - //// rescale from 25um units to 250um (1 "normal" IBL pixel) unit - //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfIblModuleIn250umPixels/pixYScaleFactor; - //} - //else if (isIBLmodule && FTKSetup::getFTKSetup().getIBLMode()==2) - //// rescale from 25um units to 250um (1 "normal" IBL pixel) unit - //eta_average*=numberOfEtaPixelsInModule/ftk::lengthOfIblModuleIn250umPixels/pixYScaleFactor; - //} + phi_average/=pixXScaleFactor; double delta; delta = eta_average - (int) eta_average; @@ -1414,28 +1324,14 @@ void atlClusteringBlayer(vector &hits) { -//void realisticPixelDecoder(hitVector* ¤tHits) -void realisticPixelDecoder(hitVector* ¤tHits, bool isIBLmodule) //Keisuke 20170215 +void realisticPixelDecoder(hitVector* ¤tHits) { hitVector::iterator hit = currentHits->begin(); -#if defined(DECODER_INPUT) - printf("0x8%.7x\n", hitToModuleId(*hit)); - std::cout << "HitType: " << (*hit)->getHitType() << " Barrel-EC: " << (*hit)->getBarrelEC() << " Layer: " << (*hit)->getLayer() << " PhiModule:" << (*hit)->getPhiModule() << " EtaModule: " << (*hit)->getEtaModule() << std::endl; - //for (hit = currentHits->begin(); hit!= currentHits->end(); hit++) { - //fe_hit fehit = fe_hit((*hit)); - //printf("0x08%.1X%.2X%.2X%.2X -- %d %d %d", fehit.fe, fehit.tot, fehit.lcol, fehit.lrow , fehit.tot, fehit.lcol, fehit.lrow); - //std::cout << " hitType " << (*hit)->getHitType() << " BEC " << (*hit)->getBarrelEC() << " layer " << (*hit)->getLayer() << " phimod " << (*hit)->getPhiModule() << " etamod " << (*hit)->getEtaModule() << std::endl; - //} -#endif - - // if (currentHits->size() > 1) - // std::stable_sort(currentHits->begin(), currentHits->end(), sortbyFE); - std::stack lifo; std::queue fifo; - if(!isIBLmodule){ + if((*hit)->getIsPixel()){ if (currentHits->size() > 1) std::stable_sort(currentHits->begin(), currentHits->end(), sortbyFE); @@ -1505,17 +1401,16 @@ void realisticPixelDecoder(hitVector* ¤tHits, bool isIBLmodule) //Keisuke currentHits->push_back(lifo_planar.top()); lifo_planar.pop(); } - }// if isIBLmodule - + } } -//FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits) -FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits, bool isIBLmodule) +FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits) { //seed is set from cb if there are hits and from //fifo if the seed is empty. FTKRawHit* seed = fifo.front(); + bool isIBLmodule = hitOnIBLmodule(*seed); if (cb.size() != 0) { boost::circular_buffer::iterator cbi = cb.begin(); seed = *cbi; @@ -1582,7 +1477,6 @@ void atlClusteringLNF(vector &hits) * make clusters in every module */ hitsByModuleMap hitsByModule; ///< store hits by module - hitsByModuleMap hitsByModuleFrozen; ///< store hits by module // Temporary storage for duplicate copy of ganged pixels // Automatically deleted at the end of this function @@ -1592,25 +1486,18 @@ void atlClusteringLNF(vector &hits) /* * First: organize raw hits by module */ - vector sortHits; - int tempModId = 999999; - for(unsigned int i = 0; i < hits.size(); i++) { int modId = hitToModuleId(hits[i]); - - if (modId>=0) { - hitsByModule[modId].push_back( &(hits[i]) ); - if (DUPLICATE_GANGED && hitIsGanged(hits[i])) { - //use the copy constructor instead of manually assigning each - //variable, as was done previously. the usage here is the - //whole point of having a copy constructor! - gangedPixelList.push_back( hits[i] ); - FTKRawHit &lastPointer = gangedPixelList.back(); - lastPointer.setPhiSide(gangedPartner( hits[i] )); - hitsByModule[modId].push_back( &lastPointer ); - } - } else { - assert(0); // should not need this any more + if (modId<0) assert(0); + hitsByModule[modId].push_back( &(hits[i]) ); + if (DUPLICATE_GANGED && hitIsGanged(hits[i])) { + //use the copy constructor instead of manually assigning each + //variable, as was done previously. the usage here is the + //whole point of having a copy constructor! + gangedPixelList.push_back( hits[i] ); + FTKRawHit &lastPointer = gangedPixelList.back(); + lastPointer.setPhiSide(gangedPartner( hits[i] )); + hitsByModule[modId].push_back( &lastPointer ); } } @@ -1618,51 +1505,33 @@ void atlClusteringLNF(vector &hits) * Second: build the list of clusters */ clustersByModuleMap clustersByModule; ///< store clusters by module - hitsByModuleFrozen = hitsByModule; ///< keep hits structure hitsByModuleMap::iterator p; - - // #if defined(DECODER_OUTPUT) // control word (begin) // Yoshi 2016.10.01 - // cout << "0x1B0F00000" << endl; - // #endif - for (p = hitsByModule.begin(); p!=hitsByModule.end(); ++p) { // loop over modules hitVector *currentHits = & (p->second); FTKRawHit &firstHit = **(currentHits->begin()); int modId = hitToModuleId( firstHit ); - - bool isIBLmodule = hitOnIBLmodule(firstHit); // Yoshi 2016.09.29 + std::cout << std::hex << "Type: " << firstHit.getModuleType() << " hashId:" << firstHit.getIdentifierHash() << " modId:" << hitToModuleId(firstHit) << std::dec << std::endl; if(PRINT_INPUT) - printInputData(currentHits, isIBLmodule); + printInputData(currentHits); -#if defined(DECODER_OUTPUT) - printDecoderOutput(currentHits, isIBLmodule); - //printDecoderOutput(currentHits); -#endif - //bool isIBLmodule = hitOnIBLmodule(firstHit); - //bool isIBLmodule = FTKSetup::getFTKSetup().getIBLMode()!=0 && firstHit.getLayer()==0; cluList *currentClusters = new cluList(); // instantiate cluster list clustersByModule[modId] = currentClusters; //The ideal clustering is going to be used in the following cases: //1. PIXEL_CLUSTERING_MODE is less than 100 (PIXEL_CLUSTERING_MIXED) //2. The module is not a pixel module - - // HHHHH Yoshi 2017.01.10 HHHHH - if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || !firstHit.getIsPixel()) { - //if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || !firstHit.getIsPixel() || isIBLmodule) { + if (PIXEL_CLUSTERING_MODE < PIXEL_CLUSTERING_MIXED || firstHit.getIsSCT()) { makeClustersLNF(currentHits, currentClusters); // use ideal clustering } else { // PIXEL_CLUSTERING_MODE >= 100 and pixel module - //realisticPixelDecoder(currentHits); - realisticPixelDecoder(currentHits, isIBLmodule); + realisticPixelDecoder(currentHits); boost::circular_buffer circular_buffer (256); hitVector gridhits; hitVector fifo = *currentHits; while (!fifo.empty() || !circular_buffer.empty()) { - //FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits); - FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits, isIBLmodule); + FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits); makeClusterFromSeed(&gridhits, currentClusters, seed); for(hitVector::iterator hsi = gridhits.begin(); hsi != gridhits.end(); hsi++) { @@ -1672,20 +1541,8 @@ void atlClusteringLNF(vector &hits) gridhits.clear(); } } - - if (DEBUG_CLUSTERS) { - std::cout << "DEBUG_CLUSTERS:" - << " modId=" << modId - << " HitListSize=" << currentHits->size() - << " ClusterListSize=" << currentClusters->size() - << "\n"; - } } // end of loop over modules - // #if defined(DECODER_OUTPUT) // control word (end) // Yoshi 2016.10.01 - // cout << "0x2E0F00000" << endl; - // #endif - #if defined(CLUSTERING_PRINTOUT) printClusterList(clustersByModule); #endif -- GitLab From 6c44c733bc601b0cecbaf16550b0280f228544dc Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Tue, 26 Feb 2019 18:01:14 +0100 Subject: [PATCH 07/18] Added FTKClusteringEngine class; Lots of updates --- Trigger/TrigFTK/TrigFTKSim/CMakeLists.txt | 3 +- .../TrigFTKSim/FTKClusteringEngine.h | 106 ++ .../TrigFTKSim/FTKClusteringPrintout.h | 29 + .../TrigFTKSim/TrigFTKSim/FTKDataInput.h | 6 +- .../TrigFTKSim/TrigFTKSim/FTK_RawInput.h | 2 +- .../TrigFTKSim/src/FTKClusteringEngine.cxx | 1443 +++++++++++++++++ .../TrigFTKSim/src/FTKClusteringPrintout.cxx | 268 +++ .../TrigFTK/TrigFTKSim/src/FTKDataInput.cxx | 547 ++++--- .../TrigFTK/TrigFTKSim/src/FTK_RawInput.cxx | 2 +- .../TrigFTKSim/src/FTK_RegionalRawInput.cxx | 35 +- .../TrigFTK/TrigFTKSim/src/atlClustering.cxx | 138 +- 11 files changed, 2172 insertions(+), 407 deletions(-) create mode 100644 Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h create mode 100644 Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h create mode 100644 Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx create mode 100644 Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx diff --git a/Trigger/TrigFTK/TrigFTKSim/CMakeLists.txt b/Trigger/TrigFTK/TrigFTKSim/CMakeLists.txt index 5678a531d0f..ba797e253d0 100644 --- a/Trigger/TrigFTK/TrigFTKSim/CMakeLists.txt +++ b/Trigger/TrigFTK/TrigFTKSim/CMakeLists.txt @@ -76,7 +76,8 @@ atlas_add_library( TrigFTKSimLib src/FTKSetup.cxx src/PatternBank.cxx src/FTK_AMBank.cxx - src/atlClustering.cxx + src/FTKClusteringPrintout.cxx + src/FTKClusteringEngine.cxx src/FTKRoadFileOutput.cxx src/FTKConstantBank.cxx src/FTKTrackInput.cxx diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h new file mode 100644 index 00000000000..0906073ce0e --- /dev/null +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h @@ -0,0 +1,106 @@ +/* + Copyright (C) 2019 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef FTKCLUSTERINGENGINE_H +#define FTKCLUSTERINGENGINE_H + +#include "TrigFTKSim/ftktypes.h" +#include "TrigFTKSim/FTKClusteringPrintout.h" + +#define GRID_ROW_MAX 21 +#define GRID_COL_MAX 8 +#define hitRowInGrid(gridCntRow, hit) ((hit->getPhiSide() <= gridCntRow + GRID_ROW_MAX/2) && \ + (hit->getPhiSide() >= gridCntRow - GRID_ROW_MAX / 2))? true : false +#define hitColInGrid(gridStrCol, hit) (hit->getEtaStrip() < gridStrCol + GRID_COL_MAX)? true : false + +#include +#include +#include +#include + +class FTKRawHit_cmp { + public: + bool operator() (const FTKRawHit *hit1, const FTKRawHit *hit2) const; +}; + + +typedef std::vector hitVector; +typedef std::map hitsByModuleMap; + + +class cluster { + public: + hitVector hitlist; // list of hits that make the cluster + FTKRawHit clusterEquiv; // hit equivalent to the cluster + FTKRawHit* seed; // hit equivalent to the cluster + bool isSafe; // confirmed by ganged pattern recognition + bool isKilled; // ganged pattern recognition suggest to remove this cluster + + ~cluster(); +}; + + +typedef std::vector cluList; +typedef std::map clustersByModuleMap; + +class FTKClusteringEngine +{ +private: + FTKClusteringPrintout cp; + + const int PIXEL_CLUSTERING_IDEAL=1; + const int PIXEL_CLUSTERING_IDEAL_APRIL_2014_FIX=2; + const int PIXEL_CLUSTERING_MIXED=100; + const int PIXEL_CLUSTERING_REALISTIC=101; + const int PIXEL_CLUSTERING_HARDWARE = 200; + + bool saveClusterContent; + bool diagClustering; + bool sctClustering; + bool ibl3DRealistic; //If this boolean is "true", you can get the same IBL 3D centorid as the FTK_IM FW. + bool duplicateGanged; + bool gangedPatternRecognition; + bool splitBlayerModules; + int pixelClusteringMode; + + static bool sortbyFE (const FTKRawHit* i,const FTKRawHit* j); + static bool sortInput(const FTKRawHit* i, const FTKRawHit* j); + bool isSplitCluster(const cluster& clu); + bool hitOnIBLmodule(const FTKRawHit &hit); + int hitToModuleId(const FTKRawHit &hit); + + bool neighborhood(const FTKRawHit &hit1, const FTKRawHit &hit2); + int buildUpCluster(hitVector *currentHits, cluster &clu); + void makeClustersLNF(hitVector *currentHits, cluList *currentClusters); + void makeClusterFromSeed(hitVector *currentHits, cluList *currentClusters, FTKRawHit* &seed); + void averageCluster(cluster &clu); + + bool pixelRowIsGanged(const int row); + int gangedPartner(const FTKRawHit &); + int hitIsGanged(const FTKRawHit &); + bool gangedHitHasNeighborhood(const FTKRawHit &hit, const cluster &clu, hitVector &connectedHits); + bool findConnectedGanged(cluster &clu, hitVector &connectedHits); + bool isKilled(const cluster &clu, const hitVector &connectedHits); + void realisticPixelDecoder(hitVector* ¤tHits); + FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits); + double getDeltaX1A(cluster &); + double getDeltaX2A(cluster &); + int getDeltaXEC1A(cluster &); + int getDeltaXEC2A(cluster &); + int getDeltaYEC1A(cluster &); + int getDeltaYEC2A(cluster &); + int getDeltaY1A(cluster &); + int getDeltaY2A(cluster &); + int getDeltaY1B(cluster &); + int getDeltaY2B(cluster &); + +public: + FTKClusteringEngine(); + FTKClusteringEngine(bool saveClusterContent, bool diagClustering, bool sctClustering, bool ibl3DRealistic, + bool duplicateGanged, bool gangedPatternRecognition, bool splitBlayerModules, int pixelClusteringMode); + void atlClusteringBlayer(std::vector &); + void atlClusteringLNF(std::vector &); +}; + +#endif // FTKCLUSTERINGENGINE_H diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h new file mode 100644 index 00000000000..1f08f6446cd --- /dev/null +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h @@ -0,0 +1,29 @@ +#ifndef FTKCLUSTERINGPRINTOUT_H +#define FTKCLUSTERINGPRINTOUT_H + +#include "TrigFTKSim/FTKRawHit.h" +#include "TrigFTKSim/ftkdefs.h" +#include +class cluster; + +typedef std::vector hitVector; +typedef std::map hitsByModuleMap; +typedef std::vector cluList; +typedef std::map clustersByModuleMap; + +class FTKClusteringPrintout +{ + +public: + FTKClusteringPrintout(); + void printHit(const FTKRawHit &hit); + + void printInputData(hitVector* currentHits); + void printDecoderOutput(hitVector* currentHits); + void printClusterList(clustersByModuleMap clustersByModule); + void printCentroidList(clustersByModuleMap clustersByModule); + + +}; + +#endif diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKDataInput.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKDataInput.h index 67aa0ece810..8098fd55e53 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKDataInput.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKDataInput.h @@ -15,6 +15,7 @@ #include "TrigFTKSim/FTKRoad.h" #include "TrigFTKSim/FTKRoadInput.h" #include "TrigFTKSim/FTKTrack.h" +#include "TrigFTKSim/FTKClusteringEngine.h" #include "StoreGate/StoreGateSvc.h" #include @@ -50,7 +51,7 @@ protected: StoreGateSvc* m_storeGate; StoreGateSvc* m_detStore; StoreGateSvc* m_evtStore; - + std::vector m_original_hits; // global list of raw hits std::vector **m_original_reghits; // local list of hits, RMAP applied std::vector m_truth_track; // list of raw hits @@ -89,6 +90,9 @@ protected: // These roads are stored in FTKRoadStream in root output of road_merger FTKRoadInput **m_roadinput; + //Class handling the clustering process + FTKClusteringEngine* clusteringEngine; + // Additional information for Naoki's studies int m_nao_nhits_tot; // total number of hits per event int m_nao_nclus_tot; // total number of hits per event diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RawInput.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RawInput.h index bbbc3c29611..5bc2359abbd 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RawInput.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RawInput.h @@ -26,7 +26,7 @@ class FTK_RawInput : public FTKDataInput long int m_ntruth_tracks; // number of truth tracks int nextFile(); - + public: FTK_RawInput(const FTKPlaneMap *pmap, const FTKPlaneMap *pmap_unused = 0x0); FTK_RawInput(const FTK_RawInput& v); diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx new file mode 100644 index 00000000000..c6315db8aed --- /dev/null +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx @@ -0,0 +1,1443 @@ +/* + Copyright (C) 2019 CERN for the benefit of the ATLAS collaboration +*/ + +#include "TrigFTKSim/FTKClusteringEngine.h" +#include "TrigFTKSim/FTKClusteringPrintout.h" +#include "TrigFTKSim/FTKSetup.h" +#include "TrigFTKSim/FTKPMap.h" +#include "TrigFTKSim/MultiTruth.h" +#include "TrigFTKSim/ftkdefs.h" + +#include +#include +#include +#include +#include +#include + +using namespace std; + +//#define DEBUG_HITS +//#define DECODER_INPUT 0 +#define DECODER_OUTPUT 0 +//#define CLUSTERING_PRINTOUT 0 +//#define CENTROID_PRINTOUT 0 +//#define BOUNDING_BOX + +const bool DEBUG_HITS = 0; +const bool DEBUG_CLUSTERS = 0; +const bool DEBUG_AVERAGE = 0; +const bool DEBUG_AVERAGE_SCT = 0; + +const bool PRINT_INPUT = 0; // print input data +const bool DEBUG_INPUT = 0; // detail check input +const bool DEBUG_DECODER = 1; // check decoder output +const bool DEBUG_CENTROID = 0; // check centroid calc. + +cluster::~cluster() +{ + hitlist.clear(); +} + + +/*! Function which examines whether a hit belongs to an IBL module. + * \param hit the hit + * \return true if the hit is on an IBL module, false otherwide + */ +bool FTKClusteringEngine::hitOnIBLmodule(const FTKRawHit &hit) +{ + return (hit.getModuleType() == ftk::MODULETYPE_IBL3D || hit.getModuleType() == ftk::MODULETYPE_IBL_PLANAR); +} + + +/** + * This class creates a hit whose coordinates are relative to the Front-End chip + * of the module that it belongs to. It is used for the correct ordering of the hits + * in the FTK_IM hit decoder. + */ +class FTK_FECoordsHit { +public: + /** + * Create an FTK_Hit_FECoords from an FTKRawHit + * \param h FTKRawHit to be processed + */ + FTK_FECoordsHit(const FTKRawHit* hit) { + tot = hit->getTot(); + int acol = hit->getEtaStrip(); + int arow = hit->getPhiSide(); + bool isIBLmodule = (hit->getModuleType() == ftk::MODULETYPE_IBL_PLANAR || hit->getModuleType() == ftk::MODULETYPE_IBL3D); + if(!isIBLmodule){ + if (arow < ftk::clustering::rowsInFEChipPerPixelModuleRow) { + fe = ftk::clustering::feChipsInRowPixel + acol/ftk::clustering::colsInFEChipPerPixelModuleRow; + lrow = arow; + lcol = acol%ftk::clustering::colsInFEChipPerPixelModuleRow; + } else { + fe = (ftk::clustering::feChipsInRowPixel - 1) - acol/ftk::clustering::colsInFEChipPerPixelModuleRow; //-1 because we start counting from 0 + lrow = (ftk::numberOfPhiPixelsInPixelModule - 1) - arow; //We start counting from 0 + lcol = (ftk::clustering::colsInFEChipPerPixelModuleRow - 1) - acol%ftk::clustering::colsInFEChipPerPixelModuleRow; //Start counting from 0 + } + }else{ + if (acol < ftk::clustering::colsInFEChipPerIblModuleRow) { + fe = 0; + lcol = acol; + } else { + fe = 1; + lcol = acol-80; + } + lrow = (ftk::clustering::rowsInFEChipPerIblModuleRow - 1) - arow; + } + } + + int fe; ///< The FE chip of the hit + int tot; ///< ToT of the hit + int lcol; ///< Column of the hit expressed in FE coordinates + int lrow; ///< Row of the hit expressed in FE coordinates +}; + +/** + * This class creates a hit whose coordinates are relative to the hit's position + * in the cluster. It is used to calculate if a cluster is split and for + * printing out the test vectors. + */ +class FTK_ClusterCoordHit +{ +public: + /** + * Create an FTK_Hit_FECoords from an FTKRawHit + * \param h FTKRawHit to be processed + * \param seed the central hit of the cluster + */ + FTK_ClusterCoordHit(const FTKRawHit &h, const FTKRawHit* seed) { + tot = h.getTot(); + crow = h.getPhiSide() - (seed->getPhiSide() - 10); + if (seed->getEtaStrip() %2 != 0) ccol = h.getEtaStrip() - (seed->getEtaStrip() - 1); + else ccol = h.getEtaStrip() - (seed->getEtaStrip()); + } + int tot; ///< ToT of the hit in the cluster + int ccol; ///< Column of the hit in the cluster + int crow; ///< Row of the hit in the cluster +}; + + +bool FTKClusteringEngine::sortbyFE (const FTKRawHit* i,const FTKRawHit* j) +{ + if (i->getHitType() == ftk::SCT || j->getHitType() == ftk::SCT) + return false; + + FTK_FECoordsHit lhit1(i); + FTK_FECoordsHit lhit2(j); + + if (lhit1.fe != lhit2.fe) return lhit1.fe <= lhit2.fe; + else if (lhit1.fe == lhit2.fe) { + if (lhit1.lcol/2 != lhit2.lcol/2) return lhit1.lcol/2 <= lhit2.lcol/2; + else if (lhit1.lcol/2 == lhit2.lcol/2) return lhit1.lrow < lhit2.lrow; + } + + return false; +} + +bool FTKClusteringEngine::sortInput(const FTKRawHit* i, const FTKRawHit* j) +{ + int firstCol = i->getEtaStrip() + 1; + int secondCol = j->getEtaStrip() + 1; + int firstRow = 335 - i->getPhiSide(); // Keisuke 20170314, start from 0 + int secondRow = 335 - j->getPhiSide(); // Keisuke 20170314, start from 0 + int firstFE = (firstCol <= 80) ? 0 : 1; + int secondFE = (secondCol <= 80) ? 0 : 1; + + if(firstCol >= 81) firstCol = firstCol - 80; + if(secondCol >= 81) secondCol = secondCol - 80; + + if (firstFE != secondFE) return firstFE > secondFE; + else{ + if(firstCol <= 40 || secondCol <= 40){ + if(firstCol != secondCol) return firstCol < secondCol; + else return firstRow < secondRow; + } else { + if(firstCol != secondCol) return firstCol > secondCol; + else return firstRow < secondRow; + } + } +} + +/*! + * Function examining whether a cluster is split. + * \param clu the cluster to be examined + * \return true if the cluster is split, false otherwise + */ +bool FTKClusteringEngine::isSplitCluster(const cluster& clu) +{ + //FTK_ClusterCoordHit seed = FTK_ClusterCoordHit(*clu.seed, clu.seed); + hitVector::const_iterator it = clu.hitlist.begin(); + for (it = clu.hitlist.begin(); it != clu.hitlist.end(); it++) { + if (clu.seed == NULL) + return false; + FTK_ClusterCoordHit chit = FTK_ClusterCoordHit(**it , clu.seed); + if ((chit.ccol >= GRID_COL_MAX - 1) || (chit.crow >= (GRID_ROW_MAX - 1)) || ( chit.crow <= 0)) + return true; + } + + return false; +} + +/*! + * Function examining whether the a given row has ganged pixels + * \param the row to be examined + * \return true + */ +bool FTKClusteringEngine::pixelRowIsGanged(const int row) +{ + switch (row) { + case 153: + case 155: + case 157: + case 159: + case 168: + case 170: + case 172: + case 174: + return row; // pixel ganged found (readout channel) + } + if (160<=row && row<=167) + return row; // pixel ganged found (non readout channel) + return false; +} + +/*! + * Function calculating the module id in which the hit belongs to. + * The default mode for now is to check the Identifier Hash of the hit. + * \param hit the hit + * \return the module id + * + */ +int FTKClusteringEngine::hitToModuleId(const FTKRawHit &hit) +{ + return hit.getHitType() == ftk::PIXEL ? hit.getIdentifierHash() : 0x8000 + hit.getIdentifierHash(); +} + +/*! + * Check (and define) if two hits are next to each other + * For the time being it accepts only pair of hits from the same module and same SCT side. + * It crashes if hits are the same. + * \param hit1 the first hit + * \param hit2 the second hit + * \return true if hits are next to each other, false otherwise. + */ +bool FTKClusteringEngine::neighborhood(const FTKRawHit &hit1, const FTKRawHit &hit2) +{ + + // 1st check same module + if (hit1.getBarrelEC() != hit2.getBarrelEC() || hit1.getHitType() != hit2.getHitType() || + hit1.getLayer() != hit2.getLayer() || hit1.getEtaModule() != hit2.getEtaModule() || + hit1.getPhiModule() != hit2.getPhiModule()) { // if module is NOT the same + assert(0); // temporary check + return false; + } + + switch (hit1.getHitType()) { + case ftk::SCT: + if (!sctClustering) + return false; + + if (hit1.getPhiSide() != hit2.getPhiSide()) { // if different side + assert(0); // temporary check + return false; + } + assert(hit1.getEtaStrip() != hit2.getEtaStrip()); // sanity check + if (hit1.getEtaStrip() == hit2.getEtaStrip()+hit2.getNStrips() + || hit1.getEtaStrip()+hit1.getNStrips() == hit2.getEtaStrip()) + return true; + return false; + + case ftk::PIXEL: + assert(hit1.getEtaStrip() != hit2.getEtaStrip() || hit1.getPhiSide() != hit2.getPhiSide()); // sanity check + /* need a common edge, i.e. contiguity along diagonal is not enough (see below) */ + if ( (hit1.getEtaStrip() == hit2.getEtaStrip()+1 || hit1.getEtaStrip()+1 == hit2.getEtaStrip()) + && hit1.getPhiSide() == hit2.getPhiSide()) return true; + if ( (hit1.getPhiSide() == hit2.getPhiSide()+1 || hit1.getPhiSide()+1 == hit2.getPhiSide()) + && hit1.getEtaStrip() == hit2.getEtaStrip()) return true; + + + if (diagClustering) { /* Accept contiguity along diagonal as well */ + if ( (hit1.getEtaStrip() == hit2.getEtaStrip()+1 || hit1.getEtaStrip()+1 == hit2.getEtaStrip()) + && (hit1.getPhiSide() == hit2.getPhiSide()+1 || hit1.getPhiSide()+1 == hit2.getPhiSide()) ) + return true; + } + + return false; + } + assert(0); // should not get here! + return false; +} + + + +int FTKClusteringEngine::buildUpCluster(hitVector *currentHits, cluster &clu) +{ + /* + * Recursively adds hits to a given cluster. + * Returns number of hits in final cluster. + * If no cluster is given (or empty cluster) make a cluster out of the 1st hit. + */ + assert(currentHits->size()>0); // need at least one hit! + + hitVector::iterator hitP; + if (clu.hitlist.size()==0) { // if cluster is empty + hitP = currentHits->begin(); + clu.hitlist.push_back(*hitP); + currentHits->erase(hitP); + + // FlagAK - dirty fix to disable clustering on 1st layer + // if( (*hitP).getLayer()==0 && (*hitP).getIsPixel() ) { + // return clu->hitlist.size(); + // } + + } + + /* Now we have a non empty cluster */ + bool newHitsAdded = false; + int distanceis = clu.hitlist.size(); + hitVector::iterator hitCluP; // hits in cluster + //for (hitCluP=clu.hitlist.begin(); hitCluP!=clu.hitlist.end(); ++hitCluP) { // loop over hits in cluster + for(int i = 0; i < distanceis; i++) { + FTKRawHit* hit = clu.hitlist.at(i); + for (hitP=currentHits->begin(); hitP!=currentHits->end();) { // loop over hits in module + //if (neighborhood(**hitCluP, **hitP)) { // if hits are neighborhood + if (neighborhood(*hit, **hitP)) { // if hits are neighborhood + // add hit to cluster + clu.hitlist.push_back(*hitP); + //hitCluP = clu.hitlist.begin(); + currentHits->erase(hitP); + distanceis++; + hitP=currentHits->begin(); // if a hit is erased then restart the loop + newHitsAdded = true; + } else { + ++hitP; // if hit is not a neighborhood then go to next hit + } + } // end of loop over hits in module + } // end of loop over hits in cluster + + // if at least one hit was added, check for more neighborhood hits + if (newHitsAdded && currentHits->size()) buildUpCluster(currentHits, clu); + return clu.hitlist.size(); +} + + +/* + * Group all hits from one module into clusters + */ +void FTKClusteringEngine::makeClustersLNF(hitVector *currentHits, cluList *currentClusters) +{ + int index=0; + while (currentHits->size()) { // as long as we have hits + cluster clu; + clu.isSafe = false; // initialitaion + clu.isKilled = false; // initialitaion + int cluSize = buildUpCluster(currentHits, clu); + currentClusters->push_back(clu); + if (0) + std::cout << "DEBUG_makeCluster:" + << " index=" << index + << " cluSize=" << cluSize + << " Nclusters=" << currentClusters->size() + << "\n"; + index++; + } +} + + +void FTKClusteringEngine::makeClusterFromSeed(hitVector *currentHits, cluList *currentClusters, FTKRawHit* &seed) +{ + //erase seed fom currentHits + hitVector::iterator position = std::find(currentHits->begin(), currentHits->end(), seed); + if (position != currentHits->end()) { + currentHits->erase(position); + } + + cluster clu; + clu.seed = seed; + clu.hitlist.push_back(seed); + clu.isSafe = false; + clu.isKilled = false; + if (currentHits->size() > 0) buildUpCluster(currentHits, clu); + currentClusters->push_back(clu); +} + + +bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const cluster &clu, hitVector &connectedHits) +{ + bool hasNeighborhood = false; + int phi = hitIsGanged(hit); + // std::cout << "phi: " << phi << std::endl; + if (phi) { // check hit is ganged + int eta = hit.getEtaStrip(); + hitVector hv = clu.hitlist; + hitVector::iterator pp; + for (pp=hv.begin(); pp!=hv.end(); ++pp) { + if ( eta != (*pp)->getEtaStrip() ) continue; + if ( abs(phi - (*pp)->getPhiSide() ) != 1 ) continue; + hasNeighborhood = true; + FTKRawHit *tmpHit = new FTKRawHit(); + tmpHit->setHitType( ftk::PIXEL ); + tmpHit->setModuleType( hit.getModuleType()); + tmpHit->setEtaStrip( eta ); + tmpHit->setLayer( hit.getLayer() ); + tmpHit->setPhiSide( gangedPartner(hit) ); + if ( !hitIsGanged(*tmpHit) ) { + cp.printHit(*tmpHit); + assert(0); + } + connectedHits.push_back( tmpHit ); // store connected hit pointer + } // end of nested loop over hits + } //end of "if (phi)" + return hasNeighborhood; +} + +bool FTKClusteringEngine::findConnectedGanged(cluster &clu, hitVector &connectedHits) +{ + assert(clu.hitlist.size()>0); // sanity check + + hitVector::iterator p; + bool hasNeighborhood = false; + for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { + if ( gangedHitHasNeighborhood(**p, clu, connectedHits) ) { + hasNeighborhood = true; + } + } // end of first loop over hits + + return hasNeighborhood; +} + +bool FTKClusteringEngine::isKilled(const cluster &clu, const hitVector &connectedHits) +{ + hitVector tmphv = clu.hitlist; + hitVector::iterator p; + for (p=tmphv.begin(); p!=tmphv.end(); ++p) { + if ( !hitIsGanged(**p) ) continue; + hitVector hv = connectedHits; + hitVector::iterator c; + for (c=(hv).begin(); c!=(hv).end(); ++c) { + assert( hitIsGanged(**c) ); // all connected hits should be ganged ! + if ( (*c)->getPhiSide() == (*p)->getPhiSide() + && (*c)->getEtaStrip() == (*p)->getEtaStrip() ) return true; + } + } // loop over hits in cluster + + return false; +} + +/*! + * Function calculating the central position of the cluster (i.e. the centroid) for all possible + * scenarios (SCT, Pixel, IBL). During the execution of this function, the + * following variables are set for each cluster: X, Y, Z, + * + * \param cluster the cluster whose average is going to be calculated + * \return void + */ +void FTKClusteringEngine::averageCluster(cluster &clu) +{ + const unsigned int &nHits = clu.hitlist.size(); + assert(nHits>0); // sanity check + + FTKRawHit &av = clu.clusterEquiv; ///< get pointer to clusterEquivalent + FTKRawHit *first = *(clu.hitlist.begin()); ///< get 1st hit + + /// reset values for clusterEquivalent (alias av) + av.reset(); + av.setX(0); + av.setY(0); + av.setZ(0); + av.setIdentifierHash(first->getIdentifierHash()); + av.setHitType(first->getHitType()); + av.setModuleType(first->getModuleType()); + av.setBarrelEC(first->getBarrelEC()); + av.setLayer(first->getLayer()); + av.setPhiModule(first->getPhiModule()); + av.setEtaModule(first->getEtaModule()); + av.setEtaStrip(0); + av.setNStrips(0); + av.setEtaWidth(0); + av.setPhiWidth(0); + av.setIncludesGanged(false); + + int tmp; + int etaMax = -1; + int etaMin = 4000; + int phiMax = -1; + int phiMin = 4000; + int rowMin = 99999; //int(2*(design->width()/design->phiPitch()))+1;; + int rowMax = 0; + int colMin = 99999; //int(2*(design->length()/design->etaPitch()))+1; + int colMax = 0; + int qRowMin = 0; + int qRowMax = 0; + int qColMin = 0; + int qColMax = 0; + + if (DEBUG_AVERAGE) + std::cout << "DEBUG_AVERAGE: isPixel=" << av.getIsPixel() + << ", nHits=" << nHits<< "\n"; + + hitVector::iterator p; + /// precalculate values for case pixelClusteringMode>0 + int BarrelEndCap = first->getBarrelEC(); + + //Calculate the active layer. Start with the layer of the hit. In case + // always count IBL as layer0 and BLayer as layer1 + int layer = first->getLayer(); + bool isIBLmodule = hitOnIBLmodule(*first); + bool isPixelmodule = !isIBLmodule; + if (FTKSetup::getFTKSetup().getIBLMode()==0) + layer++; + float radius = ftk::clustering::radii[layer]; + + //Default values for a pixel module. They are modified for IBL. + float sensorThickness = ftk::sensorThicknessPixel; + float etaPitch = ftk::etaPitchPixel; + float numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInPixelModule; + float lengthOfPixelModuleInUmPixels = ftk::lengthOfPixelModuleIn400umPixels; + float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; + // FlagAA: 2015-01-29 making default the units of 6.25um for r-phi coordinates + float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-6; + // FlagAA 2013-07-31: IBL code assumes fully planar geometry as in mc12+IBL + // This will change for the real detector!!! + if (isIBLmodule) { + sensorThickness = ftk::sensorThicknessIbl; + etaPitch = ftk::etaPitchIbl; + numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInIblModule; + lengthOfPixelModuleInUmPixels = ftk::lengthOfIblModuleIn250umPixels; + moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors + pixYScaleFactor = ftk::clustering::yScaleFactorIbl; ///getEtaModule()-8; + if( first->getModuleType() == ftk::MODULETYPE_IBL3D && ibl3DRealistic ) { + sensorThickness = 230*ftk::micrometer; + moduleActiveLength = 80*250; + numberOfEtaPixelsInModule = ftk::clustering::colsInFEChipPerIblModuleRow; + } + } + bool hasGanged = false; + + switch (av.getHitType()) { + case ftk::SCT: { + int firstStrip = 99999; + int lastStrip = -99999; + av.setPhiSide(first->getPhiSide()); + for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { + av.addX((*p)->getX()); + av.addY((*p)->getY()); + av.addZ((*p)->getZ()); + if ((*p)->getEtaStrip() < firstStrip) + firstStrip = (*p)->getEtaStrip(); + if ((*p)->getEtaStrip()+(*p)->getNStrips()-1 > lastStrip) + lastStrip = (*p)->getEtaStrip() + (*p)->getNStrips() - 1; + av.addEtaStrip((*p)->getEtaStrip()); + if (DEBUG_AVERAGE_SCT) // && clu.hitlist.size()>1) + cp.printHit(**p); + } + float stripNumberFloat = (firstStrip*1.+lastStrip)/2; + //(av.getEtaStrip()*1.)/nHits; + av.setEtaStrip( (int) stripNumberFloat ); + av.setDeltaPhi( stripNumberFloat - (int) stripNumberFloat ); + // The convention used for SCT is that we are providing as output + // the cluster center minus half a strip (i.e. use the left edge of strip for a single strip cluster) + // where output = av.setEtaStrip + av.setDeltaPhi + av.setStripCoordinate(firstStrip+lastStrip); + av.setColumnCoordinate( 0 ); + av.setDeltaEta(0); + av.setNStrips(lastStrip+1-firstStrip); + av.setEtaWidth(1); + //std::cout << " strip " << std::endl; + av.setPhiWidth(lastStrip+1-firstStrip); + if (DEBUG_AVERAGE_SCT) { // && clu.hitlist.size()>1) { + std::cout << "SCT AVERAGE: "; + cp.printHit(av); + std::cout << std::endl; + } + break; // end of SCT + } + case ftk::PIXEL: { + av.setPhiSide(0); // eta is reset a few lines above + + if (pixelClusteringMode == 0) { + for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { //loop over hits in cluster + assert(av.getLayer()==(*p)->getLayer() && av.getPhiModule()==(*p)->getPhiModule() && av.getEtaModule()==(*p)->getEtaModule() ); + if (saveClusterContent) { // if enabled the cluster also stores also the single channels + FTKRawHit tmpch = *(*p); + // set the barcode of the single channel, this may allow a very refined debugging of + // the cluster content accounting for the single barcode of each channel + MultiTruth mt; + MultiTruth::Barcode uniquecode(tmpch.getEventIndex(),tmpch.getBarcode()); + mt.maximize(uniquecode,tmpch.getBarcodePt()); + tmpch.setTruth(mt); + av.addChannel(tmpch); + } + av.addX((*p)->getX()); + av.addY((*p)->getY()); + av.addZ((*p)->getZ()); + av.addPhiSide((*p)->getPhiSide()); // phi index + // pixels are counted starting from 0 (left edge) and not 0.5 (center position) + // if only pixel 0 is hit the output value will be 0 and not 0.5 (pixel center) + av.addEtaStrip((*p)->getEtaStrip()); // eta index + } + tmp = (int)round((av.getEtaStrip()*1.)/nHits); + av.setDeltaEta((av.getEtaStrip()*1.)/nHits-tmp); + av.setEtaStrip(tmp); + tmp = (int)round((av.getPhiSide()*1.)/nHits); + av.setDeltaPhi((av.getPhiSide()*1.)/nHits-tmp); + av.setPhiSide(tmp); + break; + } + + /* For pixelClusteringMode > 0 + * calculate cluster center following code at line 701 of + * https://svnweb.cern.ch/trac/atlasoff/browser/InnerDetector/InDetRecTools/SiClusterizationTool/trunk/src/MergedPixelsTool.cxx#L701 + * I.e. m_posStrategy == 1 + * I.e. use charge imbalance between the two outer most ros (columns) to calculate the centroid + * In this code I'll use etaTrack instead of pixel eta for simplicity + */ + + for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { //loop over hits in cluster + + if (saveClusterContent) { // if enabled the cluster also stores also the single channels + FTKRawHit tmpch = *(*p); + // set the barcode of the single channel, this may allow a very refined debugging of + // the cluster content accounting for the single barcode of each channel + MultiTruth mt; + MultiTruth::Barcode uniquecode(tmpch.getEventIndex(),tmpch.getBarcode()); + mt.maximize(uniquecode,tmpch.getBarcodePt()); + tmpch.setTruth(mt); + av.addChannel(tmpch); + } + + av.addX((*p)->getX()); + av.addY((*p)->getY()); + av.addZ((*p)->getZ()); + + int row = (*p)->getPhiSide(); + int col = (*p)->getEtaStrip(); + int tot = (*p)->getTot(); // ToT for pixels + if (!isIBLmodule && pixelRowIsGanged(row)) + hasGanged = true; + + if (isPixelmodule) { + // account for 600um pixels in the centroid calculation + // will use units of 100um and the convert to normal pixel units below + // will also indicate the center of the pixel instead of the left edge + // considering center of pixel along eta (left (or top if you prefer) edge along phi) + // each FE number is worth 19*400um pixels (400um*16 + 600um*2) + // multiply FE column by 4 to convert to 100um units + int FEnumber = col/ftk::clustering::colsInFEChipPerPixelModuleRow; + int FEcolumn = col%ftk::clustering::colsInFEChipPerPixelModuleRow; + + if(DEBUG_CENTROID){ + printf("0x00%.2X%.2X%.3X", tot, col, row); + cout << " Pix HIT" + << " FE: " << setfill('0') << setw(2) << FEnumber + << " col: " << setfill('0') << setw(3) << col + << " row: " << setfill('0') << setw(3) << row + << " tot: " << setfill('0') << setw(2) << tot + << " -> "; + } + + col = FEnumber*(ftk::clustering::colsInFEChipPerPixelModuleRow+1) + FEcolumn; + col *= pixYScaleFactor; + col += pixYScaleFactor/2; // add half a pixel to align to pixel center (assume normal 400um pixel) + col += pixYScaleFactor/2; // assume 1<=FEcolumn<=16 add half a pixel coming from 600um pixel in FEcolumn==0 + if (FEcolumn==0) col -= pixYScaleFactor/4; // correct position for first column in FE chip + if (FEcolumn==(ftk::clustering::colsInFEChipPerPixelModuleRow-1)) col += pixYScaleFactor/4; // correct position for last column in FE chip + } else if (isIBLmodule) { // IBL case + row = 335 - (*p)->getPhiSide(); // inverse row coordinates // Yoshi 2016.10.28 // JAA updated 17.3.13 + + if(DEBUG_CENTROID){ + printf("0x00%.2X%.2X%.3X", tot, col, row); + cout << " IBL HIT" + << " col: " << setfill('0') << setw(3) << col + << " row: " << setfill('0') << setw(3) << row + << " tot: " << setfill('0') << setw(2) << tot + << " -> "; + } + + //Modifications have to be made to include 3d modules + int orig_col = col; + col *= pixYScaleFactor; // use units of 25um + col += pixYScaleFactor/2; // add half a pixel to align to pixel center + if(((*p)->getModuleType() == ftk::MODULETYPE_IBL3D && ibl3DRealistic) || !ibl3DRealistic){ + if (orig_col==0) col += pixYScaleFactor/2; // add half pixel (500um pixel in col0) + if (orig_col>0) col += pixYScaleFactor; // add a pixel (500um pixel in col0) + + // for 3D modules only + // if (orig_col==79) col += pixYScaleFactor*5/10; // add 5/10 of pixel i.e. 100um (500um pixel in col79) + + // for planar modules only + if (orig_col==79) col += pixYScaleFactor*4/10; // add 4/10 of pixel i.e. 100um (450um pixel in col79) + if (orig_col==80) col += pixYScaleFactor*12/10; // add 12/10 of pixel i.e. 300um (450um pixel in col79 and col80) + if (orig_col>80) col += pixYScaleFactor*16/10; // add 16/10 of pixel i.e. 400um (450um pixel in col79 and col80) + if (orig_col==159) col += pixYScaleFactor/2; // add half pixel (500um pixel in col159) + } + } + row *= pixXScaleFactor; + + // comment 2017.01.30 + // if(isIBLmodule) row += pixXScaleFactor/2; // applied Manolis' update + + if(DEBUG_CENTROID){ + printf("0x00%.2X%.3X%.3X", tot, col, row); + cout << " Norm." + << " col: " << setfill('0') << setw(3) << col + << " row: " << setfill('0') << setw(4) << row + << " tot: " << setfill('0') << setw(2) << tot + << endl; + } + + if (row == rowMin) qRowMin += tot; + if (row < rowMin){ + rowMin = row; + qRowMin = tot; + } + + if (row == rowMax) qRowMax += tot; + if (row > rowMax){ + rowMax = row; + qRowMax = tot; + } + + if (col == colMin) qColMin += tot; + if (col < colMin){ + colMin = col; + qColMin = tot; + } + + if (col == colMax) qColMax += tot; + if (col > colMax){ + colMax = col; + qColMax = tot; + } + + int phi = 335 - (*p)->getPhiSide(); // ROW // JAA updated 13 March 2017 to remove +1 as above + // int phi = (*p)->getPhiSide(); // ROW + int eta = (*p)->getEtaStrip(); // COLUMN + + if (eta > etaMax) etaMax = eta; + if (eta < etaMin) etaMin = eta; + if (phi > phiMax) phiMax = phi; + if (phi < phiMin) phiMin = phi; + if (DEBUG_AVERAGE) + cp.printHit(**p); + av.addTot(first->getTot()); // sum ToT for pixel clusters + } + av.setEtaWidth(etaMax-etaMin+1); + av.setPhiWidth(phiMax-phiMin+1); + + // calculate eta index and eta delta + double eta_average, phi_average; + eta_average = (colMin + colMax) / 2.; + phi_average = (rowMin + rowMax) / 2.; + + if (pixelClusteringMode == PIXEL_CLUSTERING_HARDWARE) { + float etaRow = -1; + float etaCol = -1; + if(qRowMin+qRowMax > 0) + etaRow = qRowMax/float(qRowMin+qRowMax); + if(qColMin+qColMax > 0) + etaCol = qColMax/float(qColMin+qColMax); + /// double test = 0; + int etaRow32 = 0; + int etaCol32 =0; + etaRow32 = lround(etaRow*32); + etaCol32 = lround(etaCol*32); + int m_posStrategy = 1; + if(m_posStrategy == 1 && !hasGanged && etaRow>0 && etaCol > 0){ + if (BarrelEndCap==0) { + phi_average+= lround((getDeltaX1A(clu)+(getDeltaX2A(clu))*etaRow32)/1024.); // >>10; + + if ( (etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) > 0){ + if ( sensorThickness*((etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius)>etaPitch) { + /// test = etaPitch; + eta_average+= pixYScaleFactor*(etaCol-0.5); + eta_average = lround(eta_average); + } + else + eta_average+= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); + } + else{ + if ( sensorThickness*(-1*(etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius)>etaPitch) { + /// test = etaPitch; + eta_average+= pixYScaleFactor*(etaCol-0.5); + eta_average = lround(eta_average); + } + else + eta_average-= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); + } + + } + + else{ + phi_average += lround((getDeltaXEC1A(clu)+getDeltaXEC2A(clu)*etaRow32)/1024.); + eta_average += lround((getDeltaYEC1A(clu)+getDeltaYEC2A(clu)*etaCol32)/1024.); + + } + + } + } + //Correction to the eta_average and phi_average used for + //pixelClusteringMode 1 and 100 + if (pixelClusteringMode <= PIXEL_CLUSTERING_MIXED) { + float pixelEstimateCotTheta = -9999.; + + /* The next lines calculate CotTheta of a hypothetic track starting from ATLAS (0,0,0) + * and crossing the center of the bounding box of the cluster. + * The Z global position is estimated as: module Z position + cluster Z position within the module. + * The radius is a fixed costant depending on the layer. It could be better estimated accounting + * also for the rphi position within the module. + */ + pixelEstimateCotTheta = (etaModule+(rowMin+rowMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius; + if (pixelClusteringMode>=PIXEL_CLUSTERING_IDEAL_APRIL_2014_FIX) /* Fixing an error in the formula */ + pixelEstimateCotTheta = (etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius; + + + // Compute eta for charge interpolation correction (if required) + // Two pixels may have tot=0 (very rarely, hopefully) + float etaRow = -1; + float etaCol = -1; + if(qRowMin+qRowMax > 0) + etaRow = qRowMax/float(qRowMin+qRowMax); + if(qColMin+qColMax > 0) + etaCol = qColMax/float(qColMin+qColMax); + + // Charge interpolation. Very rough guess (one can do better with + // candidate track information later) TL + // bool hasGanged = av.getIncludesGanged(); + float deltax = 0; + float deltay = 0; + if (BarrelEndCap==0) { //pixelID.is_barrel(elementID)){ + deltax = 30*ftk::micrometer*(sensorThickness/(250*ftk::micrometer)); + deltay = sensorThickness*fabs(pixelEstimateCotTheta); + if(deltay > etaPitch ){ + deltay = etaPitch; + } + } else { + deltax = 10*ftk::micrometer*sqrt(sensorThickness/(250*ftk::micrometer)); + deltay = 10*ftk::micrometer*sqrt(sensorThickness/(250*ftk::micrometer)); + } + + // Width of the region of charge sharing. For disks assume normal incidence: delta is small, due to diffusion + // of drifting charges in silicon. For barrel, assume 10 deg. incidence in Rphi, in z compute from pseudorapidity + // This may be improved with better parameterization, but it is probably better to use candidate track information + // later in reconstruction. TL + // Values are made dependent on the sensor thickness to accomodate // different sensors layout. AA + // Point3D globalPos = element->globalPosition(centroid); + // InDetDD::SiLocalPosition totCorrection(0,0,0); + int m_posStrategy = 1; //Same as m_posStrategy == 1 in InDetRecTools/SiClusterizationTool/trunk/src/MergedPixelsTool.cxx#L701 + if(m_posStrategy == 1 && !hasGanged && etaRow>0 && etaCol > 0){ + phi_average += pixXScaleFactor*deltax*(etaRow-0.5)/ftk::phiPitch; + eta_average += pixYScaleFactor*deltay*(etaCol-0.5)/etaPitch; + } + } + + if (phi_average<0) { + assert(phi_average<0); + phi_average = 0; + } + if (eta_average<0) { + assert(eta_average<0); + eta_average = 0; + } + + if (BarrelEndCap!=0) phi_average += ftk::clustering::pixelEndCapRPhiCorrection*pixXScaleFactor; + av.setRowCoordinate( lround(phi_average) ); + av.setColumnCoordinate( lround(eta_average) ); + av.setSplit(false); + if (pixelClusteringMode >= PIXEL_CLUSTERING_MIXED && isSplitCluster(clu)) + av.setSplit(true); + + eta_average*=numberOfEtaPixelsInModule/lengthOfPixelModuleInUmPixels/pixYScaleFactor; + phi_average/=pixXScaleFactor; + + double delta; + delta = eta_average - (int) eta_average; + av.setDeltaEta(delta); + av.setEtaStrip( (int) eta_average ); + delta = phi_average - (int) phi_average; + av.setDeltaPhi(delta); + av.setPhiSide( (int) phi_average ); + + break; // end of PIXEL + } + default: + assert(0); // should not get here! + } // end of switch + + // finally divide by nHits + av.divX(nHits); + av.divY(nHits); + av.divZ(nHits); + + // AB - perform geant parent matching and store with the cluster + // data. this involves passing all raw hits associated with the + // cluster to a MultiTruth which will be stored with the hit + // when it is converted to an FTKHit. + MultiTruth mt; + for( hitVector::iterator ihit=clu.hitlist.begin(), fhit=clu.hitlist.end(); ihit!=fhit; ++ihit ) { + // record highest pt contribution to the combination (cluster) + if( (*ihit)->getTruth() ) { + mt.maximize( *((*ihit)->getTruth()) ); + } else { + MultiTruth::Barcode uniquecode((*ihit)->getEventIndex(), + (*ihit)->getBarcode()); + mt.maximize(uniquecode,(*ihit)->getBarcodePt()); + } + } // end record truth for each raw channel in the cluster + clu.clusterEquiv.setTruth(mt); + + if (DEBUG_AVERAGE) { + std::cout << " AVERAGE IS:\n"; + cp.printHit(av); + std::cout << "\n\n"; + } +} + +void FTKClusteringEngine::atlClusteringBlayer(vector &hits) { + /* + * Split blayer modules in half along phi + * this effectively makes 22*2=44 modules along phi! + */ + if(!splitBlayerModules) return; + for(unsigned int i = 0; i < hits.size(); i++) { +#define HIT hits[i] + // AK BLAYER : change # modules in barrel blayer from 22 to 44: + if(HIT.getIsPixel() && HIT.getBarrelEC()==ftk::BARREL && HIT.getLayer()==0) { + HIT.setPhiModule(HIT.getPhiModule()*2); + // mid-module sector division: assume SS=20 or 10. + // Then the division is right at SS boundary + if(HIT.getPhiSide()>159) HIT.setPhiModule(HIT.getPhiModule()+1); // HARDCODED (328/2 rounded to SS=16) + } +#undef HIT + } +} + + + +void FTKClusteringEngine::realisticPixelDecoder(hitVector* ¤tHits) +{ + hitVector::iterator hit = currentHits->begin(); + + std::stack lifo; + std::queue fifo; + + if((*hit)->getIsPixel()){ + if (currentHits->size() > 1) + std::stable_sort(currentHits->begin(), currentHits->end(), sortbyFE); + + for(hit = currentHits->begin(); hit != currentHits->end(); hit++) { + if ((*hit)->getPhiSide() <= 163) + fifo.push(*hit); + else lifo.push(*hit); + } + + currentHits->clear(); + + while(!lifo.empty() && !fifo.empty()){ + if ((*lifo.top()).getEtaStrip() <= (*fifo.front()).getEtaStrip()) { + currentHits->push_back(lifo.top()); + lifo.pop(); + } + else { + currentHits->push_back(fifo.front()); + fifo.pop(); + } + } + + while(!lifo.empty()) { + currentHits->push_back(lifo.top()); + lifo.pop(); + } + while(!fifo.empty()) { + currentHits->push_back(fifo.front()); + fifo.pop(); + } + }else{ + std::stack lifo_planar; + std::queue fifo_planar; + + if (currentHits->size() > 1) + std::stable_sort(currentHits->begin(), currentHits->end(), sortInput); + + for(hit = currentHits->begin(); hit != currentHits->end(); hit++) { + if ((*hit)->getEtaStrip() < 40) + fifo.push(*hit); + else if ((*hit)->getEtaStrip() >= 40 && (*hit)->getEtaStrip() < 80) + lifo.push(*hit); + else if ((*hit)->getEtaStrip() >= 80 && (*hit)->getEtaStrip() < 120) + fifo_planar.push(*hit); + else if ((*hit)->getEtaStrip() >= 120 && (*hit)->getEtaStrip() < 160) + lifo_planar.push(*hit); + } + + currentHits->clear(); + + while(!fifo.empty()){ + currentHits->push_back(fifo.front()); + fifo.pop(); + } + + while(!lifo.empty()) { + currentHits->push_back(lifo.top()); + lifo.pop(); + } + + while(!fifo_planar.empty()) { + currentHits->push_back(fifo_planar.front()); + fifo_planar.pop(); + } + + while(!lifo_planar.empty()) { + currentHits->push_back(lifo_planar.top()); + lifo_planar.pop(); + } + } + + std::cout << "GOING TO DECODER" << std::endl; + cp.printDecoderOutput(currentHits); +} + + +FTKRawHit* FTKClusteringEngine::gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits) +{ + //seed is set from cb if there are hits and from + //fifo if the seed is empty. + FTKRawHit* seed = fifo.front(); + bool isIBLmodule = hitOnIBLmodule(*seed); + if (cb.size() != 0) { + boost::circular_buffer::iterator cbi = cb.begin(); + seed = *cbi; + for( cbi = cb.begin(); cbi != cb.end(); cbi++){ + if ((*cbi)->getEtaStrip() < seed->getEtaStrip()) + seed = *cbi; + else if ((*cbi)->getEtaStrip() == seed->getEtaStrip()) { + //if ((*cbi)->getPhiSide() < seed->getPhiSide()) + if ((*cbi)->getPhiSide() < seed->getPhiSide() && !isIBLmodule) //Keisuke 20170215 + seed = *cbi; + else if ((*cbi)->getPhiSide() > seed->getPhiSide() && isIBLmodule) + seed = *cbi; + } + } + } + + //step 2: set grid window limits + int gridStrCol ; + if (seed->getEtaStrip() % 2 != 0) gridStrCol = seed->getEtaStrip() - 1; + else gridStrCol = seed->getEtaStrip(); + int gridCntRow = seed->getPhiSide(); + + //step 3: put hits from cb to the grid window + int dist = distance(cb.begin(), cb.end()); + for(int i = 0; i < dist; i++) { + FTKRawHit* h = cb.front(); + if (!hitColInGrid(gridStrCol, h)) { + cb.pop_front(); + continue; + } + if (hitRowInGrid(gridCntRow, h)) + gridhits.push_back(h); + else + cb.push_back(h); + cb.pop_front(); + } + + //step 4: put hits from fifo to the grid window + hitVector::iterator fifo_it = fifo.begin(); + while (fifo_it != fifo.end()) { + FTKRawHit* hit = *fifo_it; + if (!hitColInGrid(gridStrCol, hit)) + break; + if (hitRowInGrid(gridCntRow, hit)) + gridhits.push_back(hit); + else + cb.push_back(hit); + fifo.erase(fifo_it); + } + + return seed; +} + + +/*! + * Function responsible for hit clustering and the subsequent centroid + * calculation + * \param hits hits which will be clustered + * \return void + */ +void FTKClusteringEngine::atlClusteringLNF(vector &hits) +{ + /* + * make clusters in every module + */ + hitsByModuleMap hitsByModule; ///< store hits by module + + // Temporary storage for duplicate copy of ganged pixels + // Automatically deleted at the end of this function + std::vector gangedPixelList; + gangedPixelList.reserve(hits.size()); // reserve memory in excess + + /* + * First: organize raw hits by module + */ + for(unsigned int i = 0; i < hits.size(); i++) { + int modId = hitToModuleId(hits[i]); + if (modId<0) assert(0); + hitsByModule[modId].push_back( &(hits[i]) ); + if (duplicateGanged && hitIsGanged(hits[i])) { + //use the copy constructor instead of manually assigning each + //variable, as was done previously. the usage here is the + //whole point of having a copy constructor! + gangedPixelList.push_back( hits[i] ); + FTKRawHit &lastPointer = gangedPixelList.back(); + lastPointer.setPhiSide(gangedPartner( hits[i] )); + hitsByModule[modId].push_back( &lastPointer ); + } + } + + /* + * Second: build the list of clusters + */ + clustersByModuleMap clustersByModule; ///< store clusters by module + hitsByModuleMap::iterator p; + for (auto& module: hitsByModule) { // loop over modules + hitVector *currentHits = & (module.second); + FTKRawHit &firstHit = **(currentHits->begin()); + int modId = module.first; + + cluList *currentClusters = new cluList(); // instantiate cluster list + clustersByModule[modId] = currentClusters; + + //The ideal clustering is going to be used in the following cases: + //1. pixelClusteringMode is less than 100 (PIXEL_CLUSTERING_MIXED) + //2. The module is not a pixel module + if (pixelClusteringMode < PIXEL_CLUSTERING_MIXED || firstHit.getIsSCT()) { + makeClustersLNF(currentHits, currentClusters); // use ideal clustering + } + else { // pixelClusteringMode >= 100 and pixel module + realisticPixelDecoder(currentHits); + + boost::circular_buffer circular_buffer (256); + hitVector gridhits; + hitVector fifo = *currentHits; + while (!fifo.empty() || !circular_buffer.empty()) { + FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits); + makeClusterFromSeed(&gridhits, currentClusters, seed); + + for(hitVector::iterator hsi = gridhits.begin(); hsi != gridhits.end(); hsi++) { + circular_buffer.push_back(*hsi); + } + + gridhits.clear(); + } + } + } // end of loop over modules + +#if defined(CLUSTERING_PRINTOUT) + cp.printClusterList(clustersByModule); +#endif + + /* + * Third: take the "average" of each cluster + */ + int nTotClu = 0; + clustersByModuleMap::iterator cluModP; // loop over modules + for (cluModP=clustersByModule.begin(); cluModP!=clustersByModule.end(); cluModP++) { + hitVector connectedHits; // list of ganged hits that are connected to a confirmed ganged hit + cluList::iterator cluP; + for (cluP=cluModP->second->begin(); cluP!=cluModP->second->end(); cluP++) { + // do pattern recognition in the ganged region + if ( (*cluP->hitlist.begin())->getIsPixel() && findConnectedGanged(*cluP, connectedHits) ) // set isSafe + cluP->isSafe = true; + } + + for (cluP=cluModP->second->begin(); cluP!=cluModP->second->end(); cluP++) { + if ( (*cluP->hitlist.begin())->getIsPixel() && isKilled(*cluP, connectedHits) ) // set isKilled + cluP->isKilled = true; + averageCluster(*cluP); // use floating-point average + nTotClu++; // count all clusters + } + + // delete connected hits + hitVector::iterator connectedP; + for (connectedP = connectedHits.begin(); connectedP!=connectedHits.end(); ++connectedP) { + delete *connectedP; + } + } + + + +#if defined(CENTROID_PRINTOUT) + cp.printCentroidList(clustersByModule); +#endif + + /* + * Fourth: put clusters/hits back in the event hit list + */ + hits.clear(); + + int hitCounter=0; + int deletedGangedClusters=0; + for (auto& cluModP: clustersByModule) { + cluList::iterator cluP; + for (cluP=cluModP.second->begin(); cluP!=cluModP.second->end(); cluP++) { + // kill clusters with ganged hits according to ganged pattern recognition + if ( gangedPatternRecognition && cluP->isKilled && !cluP->isSafe ) { + // AA 2009-07-07 removing the "isSafe" protection does not change + // number of combinations to fit for single muon events + deletedGangedClusters++; + continue; + } + + // store hit by value + FTKRawHit cluEquiv = (*cluP).clusterEquiv; + hits.push_back(cluEquiv); + ++hitCounter; + } + delete cluModP.second; + } + assert( (hitCounter+deletedGangedClusters) == nTotClu ); + + /* + * Fifth: free memory (could optimize and do this in previous step) + */ + + // The atlhit data from event is allocated and destroyed outside this function. + // clustersByModuleMap is automatically deleted. + clustersByModule.clear(); +} + +/*! + * Function examining if a hit is ganged. In case the hit belongs to a pixel + * module and at a row with ganged pixels, the phi coordinate of the pixel is + * returned. It always returns 0 if the hit belongs to an IBL module. + * \param hit hit to be examined + * \return The phi coordinate of the hit if the hit is ganged, 0 otherwise + */ +int FTKClusteringEngine::hitIsGanged(const FTKRawHit &hit) { + if (FTKSetup::getFTKSetup().getIBLMode()>=1 && hit.getLayer()==0) + return 0; // FlagAA: IBL is never ganged + if (hit.getIsPixel()) { + int phi = hit.getPhiSide(); + if (pixelRowIsGanged(phi)) + return phi; + } + return 0; +} + + +int FTKClusteringEngine::gangedPartner(const FTKRawHit &hit) { + if (hit.getIsPixel()) { + switch (hit.getPhiSide()) { + case 153: + return 160; + case 160: + return 153; + case 155: + return 161; + case 161: + return 155; + case 157: + return 162; + case 162: + return 157; + case 159: + return 163; + case 163: + return 159; + case 168: + return 164; + case 164: + return 168; + case 170: + return 165; + case 165: + return 170; + case 172: + return 166; + case 166: + return 172; + case 174: + return 167; + case 167: + return 174; + default: + return hit.getPhiSide(); + } + } + return -1; +} + +double FTKClusteringEngine::getDeltaX1A(cluster &clu){ + FTKRawHit *first = *(clu.hitlist.begin()); + bool isIBLmodule = hitOnIBLmodule(*first); + float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; ///getLayer(); + bool isIBLmodule = hitOnIBLmodule(*first); + if (FTKSetup::getFTKSetup().getIBLMode()==0) + layer++; + float radius = ftk::clustering::radii[layer]; + float sensorThickness = ftk::sensorThicknessPixel; + float etaPitch = ftk::etaPitchPixel; + float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; + float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-6; + if (isIBLmodule) { + sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; + moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors + pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-8; + etaPitch = ftk::etaPitchIbl; + + } + return lround ( - 32*32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch/2. ) + lround( 32*32*2* pixYScaleFactor*sensorThickness*moduleActiveLength/radius /etaPitch/2/2); +} +int FTKClusteringEngine::getDeltaY2A(cluster &clu){ + FTKRawHit *first = *(clu.hitlist.begin()); + int layer = first->getLayer(); + bool isIBLmodule = hitOnIBLmodule(*first); + if (FTKSetup::getFTKSetup().getIBLMode()==0) + layer++; + float radius = ftk::clustering::radii[layer]; + float sensorThickness = ftk::sensorThicknessPixel; + float etaPitch = ftk::etaPitchPixel; + float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; + float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-6; + if (isIBLmodule) { + sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; + moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors + pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-8; + etaPitch = ftk::etaPitchIbl; + } + return lround (32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch) + lround ( - 32*2* pixYScaleFactor*sensorThickness* moduleActiveLength/radius /etaPitch/2.); +} + +int FTKClusteringEngine::getDeltaY1B(cluster &clu){ + FTKRawHit *first = *(clu.hitlist.begin()); + int layer = first->getLayer(); + bool isIBLmodule = hitOnIBLmodule(*first); + if (FTKSetup::getFTKSetup().getIBLMode()==0) + layer++; + float radius = ftk::clustering::radii[layer]; + float sensorThickness = ftk::sensorThicknessPixel; + float etaPitch = ftk::etaPitchPixel; + float numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInPixelModule; + float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; + if (isIBLmodule) { + sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; + numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInIblModule; + moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors + etaPitch = ftk::etaPitchIbl; + } + return lround ( - 32*32* sensorThickness/numberOfEtaPixelsInModule *moduleActiveLength/radius /etaPitch/2); +} + + +int FTKClusteringEngine::getDeltaY2B(cluster &clu){ + FTKRawHit *first = *(clu.hitlist.begin()); + int layer = first->getLayer(); + bool isIBLmodule = hitOnIBLmodule(*first); + if (FTKSetup::getFTKSetup().getIBLMode()==0) + layer++; + float radius = ftk::clustering::radii[layer]; + float sensorThickness = ftk::sensorThicknessPixel; + float etaPitch = ftk::etaPitchPixel; + float numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInPixelModule; + float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; + if (isIBLmodule) { + sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; + numberOfEtaPixelsInModule = ftk::numberOfEtaPixelsInIblModule; + moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors + etaPitch = ftk::etaPitchIbl; + } + return lround (32 * sensorThickness/numberOfEtaPixelsInModule *moduleActiveLength/radius/etaPitch ) ; +} + +FTKClusteringEngine::FTKClusteringEngine(bool saveClusterContent, bool diagClustering, + bool sctClustering, bool ibl3DRealistic, + bool duplicateGanged, bool gangedPatternRecognition, + bool splitBlayerModules, int pixelClusteringMode) : + saveClusterContent(saveClusterContent), + diagClustering(diagClustering), + sctClustering(sctClustering), + ibl3DRealistic(ibl3DRealistic), + duplicateGanged(duplicateGanged), + gangedPatternRecognition(gangedPatternRecognition), + splitBlayerModules(splitBlayerModules), + pixelClusteringMode(pixelClusteringMode) +{ + +} + + diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx new file mode 100644 index 00000000000..36c408ad3f5 --- /dev/null +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx @@ -0,0 +1,268 @@ +#include "TrigFTKSim/FTKClusteringPrintout.h" +#include "src/FTKClusteringEngine.cxx" +#include + +/*! + * Function printing the hit details + * \param hit the hit + * \return void + */ +void printHit(const FTKRawHit &hit) +{ + std::cout << "DEBUG_HITS: " + << " isPixel=" << hit.getIsPixel() + << " barrel_ec=" << hit.getBarrelEC() + << " layer_disk=" << hit.getLayer() + << " phi_module=" << hit.getPhiModule() + << " eta_module=" << hit.getEtaModule() + << " pi_side=" << hit.getPhiSide() + << " ei_strip=" << hit.getEtaStrip() + << " n_strips=" << hit.getNStrips() + << " deltaPhi=" << hit.getDeltaPhi() + << " deltaEta=" << hit.getDeltaEta() + << " ( x=" << hit.getX() + << " y=" << hit.getY() + << " z=" << hit.getZ() + << " eventindex=" << hit.getEventIndex() + << " barcode=" << hit.getBarcode() + << " bar_pt=" << hit.getBarcodePt() + << " parentage_mask=" << hit.getParentageMask() + << " )\n"; +} + + +bool clusterSort (const FTK_ClusterCoordHit &i, const FTK_ClusterCoordHit &j) +{ + // reverse the hits on the first row if they are above the seed + if (i.ccol == 0 && j.ccol == 0 && i.crow <= 10 && j.crow <= 10) + return j.crow <= i.crow; + else if (i.ccol == j.ccol) + return i.crow <= j.crow; + else + return i.ccol <= j.ccol; +} + +void printClu(const cluster &clu) +{ + hitVector hs = clu.hitlist; + hitVector::iterator hit = hs.begin(); + + vector tmp; + for (hit = hs.begin(); hit != hs.end(); hit++) { + tmp.push_back(FTK_ClusterCoordHit(**hit, clu.seed)); + } + + //sort and print the vector. + if (tmp.size() > 1) std::stable_sort(tmp.begin(), tmp.end(), clusterSort); + + for(vector::iterator hit1 = tmp.begin(); hit1 != tmp.end(); hit1++) { + printf("0000%.2X%.2X%.3X\n",(*hit1).tot, (*hit1).ccol, (*hit1).crow); + //printf("0000%.2X%.2X%.3X",(*hit1).tot, (*hit1).ccol, (*hit1).crow); + //printf(" tot: %d col: %d row: %d\n",(*hit1).tot, (*hit1).ccol, (*hit1).crow); + } + + //TO ENABLE AGAIN! + int boundary = 2; + // if (isSplitCluster(clu)) + // boundary = 3; + + if (clu.seed->getEtaStrip() %2 != 0) { + printf("000%d00%.2X%.3X\n",boundary, clu.seed->getEtaStrip() - 1, clu.seed->getPhiSide()); + + //printf("000%d00%.2X%.3X",boundary, clu.seed->getEtaStrip() - 1, clu.seed->getPhiSide()); + //printf(" split: %d col: %d row: %d\n",boundary, clu.seed->getEtaStrip() - 1, clu.seed->getPhiSide()); + } + else { + printf("000%d00%.2X%.3X\n",boundary, clu.seed->getEtaStrip(), clu.seed->getPhiSide()); + //printf("000%d00%.2X%.3X",boundary, clu.seed->getEtaStrip(), clu.seed->getPhiSide()); + //printf(" split: %d col: %d row: %d\n",boundary, clu.seed->getEtaStrip(), clu.seed->getPhiSide()); + } +} + +void printClusterList(clustersByModuleMap clustersByModule) +{ + clustersByModuleMap::iterator p; + for (p = clustersByModule.begin(); p!=clustersByModule.end(); ++p) { // loop over modules + cluList* cl = (*p).second; + cluList::iterator b = cl->begin(); + FTKRawHit* hit = (*b).hitlist[0]; + printf("0x200000%02d\n", (*hit).getIdentifierHash()); + for (; b != cl->end(); b++) { + printClu(*b); + } + printf("0x40000000\n"); + } +} + + +void printCentroidList(clustersByModuleMap clustersByModule) +{ + clustersByModuleMap::iterator p; + for (p = clustersByModule.begin(); p!=clustersByModule.end(); ++p) { // loop over modules + cluList* cl = (*p).second; + cluList::iterator b = cl->begin(); + FTKRawHit* hit = (*b).hitlist[0]; + + bool isIBLmodule = ((*hit).getModuleType() == ftk::MODULETYPE_IBL3D || (*hit).getModuleType() == ftk::MODULETYPE_IBL_PLANAR); + int idHash = hit->getIdentifierHash(); + int isPixel = hit->getIsPixel(); + + if(isIBLmodule){// for IBL + bool FE0_exist = false; + bool FE1_exist = false; + + if(hit->getEtaStrip() < 80){ + FE0_exist = true; + + b = cl->end() - 1; + int nhit_inCluster = (*b).hitlist.size(); + hit = (*b).hitlist[nhit_inCluster-1]; + if(hit->getEtaStrip() >= 80) + FE1_exist = true; + }else{ + FE1_exist = true; + } + + b = cl->begin(); + hit = (*b).hitlist[0]; + + if(FE1_exist == false && FE0_exist == true) + printf("0x08%.7x\n", idHash); + else + printf("0x08%.7x\n", idHash-1); + } else { + printf("0x8%.7x\n", hit->getIdentifierHash()); + } + for (; b != cl->end(); b++) { + printf("0x%.8X ",(*b).clusterEquiv.getHWWord()); + //std::cout << (*b).clusterEquiv.getTot() << " " + // << (*b).clusterEquiv.getEtaStrip() << " " + // << (*b).clusterEquiv.getPhiSide() << std::endl; + if (DEBUG_CENTROID) printHit(*hit); + } + printf("0x40000000\n"); + } +} + +bool sortWords(const FTKRawHit* i, const FTKRawHit* j) +{ + int firstCol = i->getEtaStrip() + 1; + int secondCol = j->getEtaStrip() + 1; + int firstRow = 335 - i->getPhiSide(); // Keisuke 20170314, start from 0 + int secondRow = 335 - j->getPhiSide(); // Keisuke 20170314, start from 0 + + if(firstCol != secondCol) return firstCol < secondCol; + else return firstRow > secondRow; + +} + +void printDecoderOutput(hitVector* currentHits) +{ + hitVector::iterator hit = currentHits->begin(); + hitVector *sortHits = currentHits; + int idHash = (**hit).getIdentifierHash(); + bool isIBLmodule = ((**hit).getModuleType() == ftk::MODULETYPE_IBL3D || (**hit).getModuleType() == ftk::MODULETYPE_IBL_PLANAR); + + if(isIBLmodule){ // Keisuke 20170215 + stable_sort(sortHits->begin(), sortHits->end(), sortWords); + idHash = (**sortHits->begin()).getIdentifierHash(); + } + + std::cout << "Found in Decoder" << std::hex << idHash << std::dec <begin(), sortHits->end(), sortWords); + + for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ + int tempCol = (*it)->getEtaStrip(); + // if(tempCol >= 80) tempCol = tempCol - 80; // Yoshi 2016.11.18 + int tempRow = 335 - (*it)->getPhiSide(); // Keisuke 20170314, start from 0 + int tempTot = (*it)->getTot(); + int outputData = ( (tempTot << 20) | (tempCol << 12) | tempRow ); + printf("0x0%.7X",outputData); + + if(!DEBUG_DECODER) cout << endl; + else{ + cout << " IBL HIT" + << " col: " << setfill('0') << setw(3) << tempCol + << " row: " << setfill('0') << setw(3) << tempRow + << " tot: " << setfill('0') << setw(2) << tempTot + << endl; + } + } + + }else{ // for Pixel + printf("0x8%.7x\n", (**hit).getIdentifierHash()); + for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { + printf("0x0%.2X%.2X%.3X",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); + if(!DEBUG_DECODER) cout << endl; + else{ + cout << " Pixel HIT" + << " col: " << (*hit)->getEtaStrip() + << " row: " << (*hit)->getPhiSide() + << " tot: " << (*hit)->getTot() + << endl; + } + + } //hit loop + printf("0x40000000\n"); + } +} + +void printInputData(hitVector* currentHits) +{ + hitVector::iterator hit = currentHits->begin(); + bool isIBLmodule = ((**hit).getModuleType() == ftk::MODULETYPE_IBL3D || (**hit).getModuleType() == ftk::MODULETYPE_IBL_PLANAR); + hitVector *sortHits = currentHits; + int idHash = (**hit).getIdentifierHash() + 8; + if(DEBUG_INPUT) printHit(**hit); + + if(isIBLmodule){ // for IBL + idHash = (**sortHits->begin()).getIdentifierHash() + 8; + printf("0x03%.1x000000\n", idHash); + + for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ + int tempCol = (*it)->getEtaStrip() + 1; + if((idHash == 0x8 || idHash == 0xa) && tempCol <= 80){ + printf("0x05%.1x400000\n", idHash); + idHash = idHash + 1; + printf("0x03%.1x000000\n", idHash); + } + if(tempCol >= 81) tempCol = tempCol - 80; // for generate real input + int tempRow = 335 - (*it)->getPhiSide(); // Keisuke 20170314, start from 0 + int tempTot = (*it)->getTot(); + int outputData = ((idHash << 24) | (tempTot << 20) | (tempCol << 9) | tempRow ); + printf("0x09%.7x",outputData); + + if(!DEBUG_INPUT) cout << endl; + else{ + cout << " IBL HIT" + << " col: " << setfill('0') << setw(3) << tempCol + << " row: " << setfill('0') << setw(3) << tempRow + << " tot: " << setfill('0') << setw(2) << tempTot + << endl; + } + } + + }else{ // for Pixel + + printf("0x08%.7x\n", idHash); + + for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { + printf("0x00%.2x%.2x%.3x ",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); + + if(!DEBUG_DECODER) cout << endl; + else{ + cout << " Pixel HIT" + << " col: " << (*hit)->getEtaStrip() + << " row: " << (*hit)->getPhiSide() + << " tot: " << (*hit)->getTot() + << endl; + } + } + } // hit loop + + printf("0x05%.1x400000\n", idHash); +} + + diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx index 4774973c9e5..534d6506a99 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx @@ -6,7 +6,7 @@ #include "TrigFTKSim/FTKRawHit.h" #include "TrigFTKSim/FTKSetup.h" #include "TrigFTKSim/FTKSplitEncoder.h" -#include "TrigFTKSim/atlClustering.h" +#include "TrigFTKSim/FTKClusteringEngine.h" #include "xAODTracking/TrackParticleContainer.h" #include @@ -14,36 +14,36 @@ using namespace std; FTKDataInput::FTKDataInput() : - m_nevent(-1), m_pmap(0x0), m_pmap_unused(0x0), - m_reghits(0x0), m_run_number(0ul), m_event_number(0ul) , - m_original_reghits(0), m_nplanes(0), m_nregions(0), m_nsubregions(0), - m_ncoords(0), m_region(-1), m_subregion(-1), - m_Clustering(true), m_SaveClusterContent(false), - m_DiagClustering(true), m_SctClustering(false), m_PixelClusteringMode(0), m_Ibl3DRealistic(false), m_DuplicateGanged(true), - m_GangedPatternRecognition(false), - m_SplitBlayerModules(false), - m_init(false), m_save_unused(false), m_read_clusters(false), - m_trackinput(0), m_roadinput(0), // cy road - m_nao_nhits_tot(0), m_nao_nclus_tot(0), m_firstEventFTK(-1), - m_goodRegions(0), - m_regional(false) + m_nevent(-1), m_pmap(0x0), m_pmap_unused(0x0), + m_reghits(0x0), m_run_number(0ul), m_event_number(0ul) , + m_original_reghits(0), m_nplanes(0), m_nregions(0), m_nsubregions(0), + m_ncoords(0), m_region(-1), m_subregion(-1), + m_Clustering(true), m_SaveClusterContent(false), + m_DiagClustering(true), m_SctClustering(false), m_PixelClusteringMode(0), m_Ibl3DRealistic(false), m_DuplicateGanged(true), + m_GangedPatternRecognition(false), + m_SplitBlayerModules(false), + m_init(false), m_save_unused(false), m_read_clusters(false), + m_trackinput(0), m_roadinput(0), // cy road + m_nao_nhits_tot(0), m_nao_nclus_tot(0), m_firstEventFTK(-1), + m_goodRegions(0), + m_regional(false) {;} FTKDataInput::FTKDataInput(const FTKPlaneMap *pmap, const FTKPlaneMap *pmap_unused) : - m_nevent(-1), m_pmap(pmap), m_pmap_unused(pmap_unused), - m_reghits(0x0), m_run_number(0ul), m_event_number(0ul) , - m_original_reghits(0), - m_nplanes(m_pmap->getNPlanes()), m_nregions(0), m_nsubregions(0), - m_ncoords(0), m_region(-1), m_subregion(-1), - m_Clustering(true), m_SaveClusterContent(false), - m_DiagClustering(true), m_SctClustering(false), m_PixelClusteringMode(0), m_Ibl3DRealistic(false), m_DuplicateGanged(true), - m_GangedPatternRecognition(false), - m_SplitBlayerModules(false), - m_init(false), m_save_unused(false), m_read_clusters(false), - m_trackinput(0), m_roadinput(0), // cy road - m_nao_nhits_tot(0), m_nao_nclus_tot(0), m_firstEventFTK(-1), - m_goodRegions(0), - m_regional(false) + m_nevent(-1), m_pmap(pmap), m_pmap_unused(pmap_unused), + m_reghits(0x0), m_run_number(0ul), m_event_number(0ul) , + m_original_reghits(0), + m_nplanes(m_pmap->getNPlanes()), m_nregions(0), m_nsubregions(0), + m_ncoords(0), m_region(-1), m_subregion(-1), + m_Clustering(true), m_SaveClusterContent(false), + m_DiagClustering(true), m_SctClustering(false), m_PixelClusteringMode(0), m_Ibl3DRealistic(false), m_DuplicateGanged(true), + m_GangedPatternRecognition(false), + m_SplitBlayerModules(false), + m_init(false), m_save_unused(false), m_read_clusters(false), + m_trackinput(0), m_roadinput(0), // cy road + m_nao_nhits_tot(0), m_nao_nclus_tot(0), m_firstEventFTK(-1), + m_goodRegions(0), + m_regional(false) {;} FTKDataInput::~FTKDataInput() @@ -54,274 +54,273 @@ FTKDataInput::~FTKDataInput() value is accepted */ void FTKDataInput::setPlaneMaps(const FTKPlaneMap *pmap, const FTKPlaneMap *pmap_unused) { - m_pmap = pmap; - m_nplanes = pmap->getNPlanes(); - m_pmap_unused = pmap_unused; + m_pmap = pmap; + m_nplanes = pmap->getNPlanes(); + m_pmap_unused = pmap_unused; } /** initilize clustering settings (bad: using global variables!) */ -void FTKDataInput::initClustering() +void FTKDataInput::initClustering() { - SAVE_CLUSTER_CONTENT = m_SaveClusterContent; - DIAG_CLUSTERING = m_DiagClustering; - SCT_CLUSTERING = m_SctClustering; - PIXEL_CLUSTERING_MODE = m_PixelClusteringMode; - IBL3D_REALISTIC = m_Ibl3DRealistic; - DUPLICATE_GANGED = m_DuplicateGanged; - GANGED_PATTERN_RECOGNITION = m_GangedPatternRecognition; - SPLIT_BLAYER_MODULES = m_SplitBlayerModules; - // - // new clustering class and pass options + // new clustering class and pass options + clusteringEngine = new FTKClusteringEngine(m_SaveClusterContent, + m_DiagClustering, + m_SctClustering, + m_Ibl3DRealistic, + m_DuplicateGanged, + m_GangedPatternRecognition, + m_SplitBlayerModules, + m_PixelClusteringMode); } /** Process the event:cluster raw hits and convert them to FTKHits */ void FTKDataInput::processEvent(bool clearOrig) { - // reset statistics - m_nao_nhits_tot=0; - m_nao_nclus_tot=0; - - // reset hit list - m_hits.clear(); - m_hits_unused.clear(); - - if (m_regional) { - // process only the important regions and exit - for (int ireg=0;ireg!=m_nregions;++ireg) { - if (m_goodRegions[ireg]) processRegion(ireg, clearOrig); + // reset statistics + m_nao_nhits_tot=0; + m_nao_nclus_tot=0; + + // reset hit list + m_hits.clear(); + m_hits_unused.clear(); + + if (m_regional) { + // process only the important regions and exit + for (int ireg=0;ireg!=m_nregions;++ireg) { + if (m_goodRegions[ireg]) processRegion(ireg, clearOrig); + } + + // exit + return; } - // exit - return; - } - - if(FTKSetup::getDBG()) { - cout << "DBG: Original hits = " << m_original_hits.size() << endl; - } - m_nao_nhits_tot = m_original_hits.size(); - - if (!m_read_clusters) { - // if raw channels are read the clustering algorithm can be applyied (default) - if (m_Clustering ) { - atlClusteringLNF(m_original_hits); - atlClusteringBlayer(m_original_hits); // split blayer modules in half, if requested - } - else { - // If the clustering it is not executed the FTKRawHit.m_truth field has to be fixed - vector::iterator ihit = m_original_hits.begin(); - vector::const_iterator ihit_end = m_original_hits.end(); - for (;ihit!=ihit_end;++ihit) { // loop over the raw hits - FTKRawHit &curhit = *ihit; - MultiTruth mt; - MultiTruth::Barcode uniquecode(curhit.getEventIndex(),curhit.getBarcode()); - mt.maximize(uniquecode,curhit.getBarcodePt()); - curhit.setTruth(mt); - } // end hit - } - } - - if(FTKSetup::getDBG()) { - cout << "DBG: Clustered hits = " << m_original_hits.size() << endl; - } - m_nao_nclus_tot = m_original_hits.size(); - - // read SCTtrk values (Constantinos case) and push SCTtrk hits into hits vector: - // Note that it assumes the raw data input and root track input are fully in sync! - if(m_trackinput && m_roadinput) { - for(int i=0;inextEvent(); - if(res<0) { - FTKSetup::PrintMessage(ftk::sevr,"SCTtrk input ran out before hit input"); - } - res = m_roadinput[i]->nextEvent(); - if(res<0) { - FTKSetup::PrintMessage(ftk::sevr,"SCTtrk road input ran out before hit input"); - } - const FTKTrack *cur_track = m_trackinput[i]->nextTrack(m_region); - while (cur_track) { - FTKRawHit tmphit(cur_track,m_pmap->getSCTtrkPlane()); - m_original_hits.push_back(tmphit); - cur_track = m_trackinput[i]->nextTrack(m_region); - } - } - } - - // filter the hit end convert input hit format into FTKHit - vector::iterator irawhit = m_original_hits.begin(); - FTKSetup &ftkset = FTKSetup::getFTKSetup(); - - // create one list for each plane to order the hits - list *planelist = new list[m_nplanes]; - - for (;irawhit!=m_original_hits.end();++irawhit) { // loop over clusters - FTKRawHit &rawhit = *irawhit; - - // check if end-cap hits should be accepted - if (rawhit.getBarrelEC()!=0 && ftkset.getBarrelOnly() == true) { - // skip this hit - continue; - } - // check if SCT hits should be accepted - if(rawhit.getIsSCT() && ftkset.getSCTtrkMode()) { - // skip this hit - continue; - } - if (m_pmap->getMap(rawhit.getHitType(),rawhit.getBarrelEC()!=0,rawhit.getLayer()).getPlane() != -1) { - // accept this hit - FTKHit tmphit = rawhit.getFTKHit(m_pmap); - assert(rawhit.getTruth()); - tmphit.setTruth(*(rawhit.getTruth())); // AB - attach truth data to the FTKHit. - planelist[tmphit.getPlane()].push_front(tmphit); + if(FTKSetup::getDBG()) { + cout << "DBG: Original hits = " << m_original_hits.size() << endl; } - else if (m_save_unused) { - // accept this hit - FTKHit tmphit = rawhit.getFTKHit(m_pmap_unused); - assert(rawhit.getTruth()); - tmphit.setTruth(*(rawhit.getTruth())); // AB - attach truth data to the FTKHit. - m_hits_unused.push_back(tmphit); + m_nao_nhits_tot = m_original_hits.size(); + + if (!m_read_clusters) { + // if raw channels are read the clustering algorithm can be applyied (default) + if (m_Clustering ) { + clusteringEngine.atlClusteringLNF(m_original_hits); + clusteringEngine.atlClusteringBlayer(m_original_hits); // split blayer modules in half, if requested + } + else { + // If the clustering it is not executed the FTKRawHit.m_truth field has to be fixed + vector::iterator ihit = m_original_hits.begin(); + vector::const_iterator ihit_end = m_original_hits.end(); + for (;ihit!=ihit_end;++ihit) { // loop over the raw hits + FTKRawHit &curhit = *ihit; + MultiTruth mt; + MultiTruth::Barcode uniquecode(curhit.getEventIndex(),curhit.getBarcode()); + mt.maximize(uniquecode,curhit.getBarcodePt()); + curhit.setTruth(mt); + } // end hit + } } - } // end loop over clusters - for (int ipl=0;ipl::iterator tmphit = planelist[ipl].begin(); - for (;tmphit!=planelist[ipl].end();++tmphit) { - m_hits.push_back(*tmphit); + if(FTKSetup::getDBG()) { + cout << "DBG: Clustered hits = " << m_original_hits.size() << endl; + } + m_nao_nclus_tot = m_original_hits.size(); + + // read SCTtrk values (Constantinos case) and push SCTtrk hits into hits vector: + // Note that it assumes the raw data input and root track input are fully in sync! + if(m_trackinput && m_roadinput) { + for(int i=0;inextEvent(); + if(res<0) { + FTKSetup::PrintMessage(ftk::sevr,"SCTtrk input ran out before hit input"); + } + res = m_roadinput[i]->nextEvent(); + if(res<0) { + FTKSetup::PrintMessage(ftk::sevr,"SCTtrk road input ran out before hit input"); + } + const FTKTrack *cur_track = m_trackinput[i]->nextTrack(m_region); + while (cur_track) { + FTKRawHit tmphit(cur_track,m_pmap->getSCTtrkPlane()); + m_original_hits.push_back(tmphit); + cur_track = m_trackinput[i]->nextTrack(m_region); + } + } } - } // end loop over the planes - - // clear raw hits since we don't need them anymore - if(clearOrig) - m_original_hits.clear(); - delete [] planelist; + // filter the hit end convert input hit format into FTKHit + vector::iterator irawhit = m_original_hits.begin(); + FTKSetup &ftkset = FTKSetup::getFTKSetup(); + + // create one list for each plane to order the hits + list *planelist = new list[m_nplanes]; + + for (;irawhit!=m_original_hits.end();++irawhit) { // loop over clusters + FTKRawHit &rawhit = *irawhit; + + // check if end-cap hits should be accepted + if (rawhit.getBarrelEC()!=0 && ftkset.getBarrelOnly() == true) { + // skip this hit + continue; + } + // check if SCT hits should be accepted + if(rawhit.getIsSCT() && ftkset.getSCTtrkMode()) { + // skip this hit + continue; + } + if (m_pmap->getMap(rawhit.getHitType(),rawhit.getBarrelEC()!=0,rawhit.getLayer()).getPlane() != -1) { + // accept this hit + FTKHit tmphit = rawhit.getFTKHit(m_pmap); + assert(rawhit.getTruth()); + tmphit.setTruth(*(rawhit.getTruth())); // AB - attach truth data to the FTKHit. + planelist[tmphit.getPlane()].push_front(tmphit); + } + else if (m_save_unused) { + // accept this hit + FTKHit tmphit = rawhit.getFTKHit(m_pmap_unused); + assert(rawhit.getTruth()); + tmphit.setTruth(*(rawhit.getTruth())); // AB - attach truth data to the FTKHit. + m_hits_unused.push_back(tmphit); + } + } // end loop over clusters + + for (int ipl=0;ipl::iterator tmphit = planelist[ipl].begin(); + for (;tmphit!=planelist[ipl].end();++tmphit) { + m_hits.push_back(*tmphit); + } + } // end loop over the planes + + // clear raw hits since we don't need them anymore + if(clearOrig) + m_original_hits.clear(); + + delete [] planelist; } void FTKDataInput::processRegion(int curreg, bool clearOrig) { - - if (m_read_FTKhits_directly) { - vector &curhits = m_reghits[curreg]; - vector &curhits_read = *(m_reghits_read[curreg]); - curhits.clear(); - vector::iterator ihit = curhits_read.begin(); - for(; ihit!=curhits_read.end(); ++ihit){ - FTKHit tmphit = **ihit; - curhits.push_back(tmphit); - } - - } - else { - // set the reference the list used by the current region - vector &currawhits = *(m_original_reghits[curreg]); - vector &curhits = m_reghits[curreg]; - - // reset hit list - curhits.clear(); - - - if(FTKSetup::getDBG()) { - cout << "DBG: Original hits = " << currawhits.size() << endl; - } - m_nao_nhits_tot += currawhits.size(); - - if (!m_read_clusters) { - // if raw channels are read the clustering algorithm can be applyied (default) - if (m_Clustering ) { - atlClusteringLNF(currawhits); - atlClusteringBlayer(currawhits); // split blayer modules in half, if requested - } - else { - // If the clustering it is not executed the FTKRawHit.m_truth field has to be fixed - vector::iterator ihit = currawhits.begin(); - vector::const_iterator ihit_end = currawhits.end(); - for (;ihit!=ihit_end;++ihit) { // loop over the raw hits - FTKRawHit &curhit = *ihit; - MultiTruth mt; - MultiTruth::Barcode uniquecode(curhit.getEventIndex(),curhit.getBarcode()); - mt.maximize(uniquecode,curhit.getBarcodePt()); - curhit.setTruth(mt); - } // end hit - } - } - - if(FTKSetup::getDBG()) { - cout << "DBG: Clustered hits = " << m_original_hits.size() << endl; - } - m_nao_nclus_tot += currawhits.size(); - - // read SCTtrk values (Constantinos case) and push SCTtrk hits into hits vector: - // Note that it assumes the raw data input and root track input are fully in sync! - if(m_trackinput && m_roadinput) { - // for now, only read tracks from "current" region - int res = m_trackinput[curreg]->nextEvent(); - if(res<0) { - FTKSetup::PrintMessage(ftk::sevr,"SCTtrk input ran out before hit input"); - } - res = m_roadinput[curreg]->nextEvent(); - if(res<0) { - FTKSetup::PrintMessage(ftk::sevr,"SCTtrk road input ran out before hit input"); - } - const FTKTrack *cur_track = m_trackinput[curreg]->nextTrack(m_region); - while (cur_track) { - FTKRawHit tmphit(cur_track,m_pmap->getSCTtrkPlane()); - m_original_hits.push_back(tmphit); - cur_track = m_trackinput[curreg]->nextTrack(m_region); - } - } - - // filter the hit end convert input hit format into FTKHit - vector::iterator irawhit = currawhits.begin(); - FTKSetup &ftkset = FTKSetup::getFTKSetup(); - - // create one list for each plane to order the hits - list *planelist = new list[m_nplanes]; - - for (;irawhit!=currawhits.end();++irawhit) { // loop over clusters - FTKRawHit &rawhit = *irawhit; - - // check if end-cap hits should be accepted - if (rawhit.getBarrelEC()!=0 && ftkset.getBarrelOnly() == true) { - // skip this hit - continue; - } - // check if SCT hits should be accepted - if(rawhit.getIsSCT() && ftkset.getSCTtrkMode()) { - // skip this hit - continue; - } - if (m_pmap->getMap(rawhit.getHitType(),rawhit.getBarrelEC()!=0,rawhit.getLayer()).getPlane() != -1) { - // accept this hit - FTKHit tmphit = rawhit.getFTKHit(m_pmap); - if(rawhit.getTruth()!=nullptr) - tmphit.setTruth(*(rawhit.getTruth())); // AB - attach truth data to the FTKHit. - planelist[tmphit.getPlane()].push_front(tmphit); - } - else if (m_save_unused) { - // accept this hit - FTKHit tmphit = rawhit.getFTKHit(m_pmap_unused); - if(rawhit.getTruth()!=nullptr) - tmphit.setTruth(*(rawhit.getTruth())); // AB - attach truth data to the FTKHit. - m_hits_unused.push_back(tmphit); - } - } // end loop over clusters - - for (int ipl=0;ipl::iterator tmphit = planelist[ipl].begin(); - for (;tmphit!=planelist[ipl].end();++tmphit) { - curhits.push_back(*tmphit); - } - } // end loop over the planes - - // clear raw hits since we don't need them anymore - if(clearOrig) - currawhits.clear(); - - delete [] planelist; - } + + if (m_read_FTKhits_directly) { + vector &curhits = m_reghits[curreg]; + vector &curhits_read = *(m_reghits_read[curreg]); + curhits.clear(); + vector::iterator ihit = curhits_read.begin(); + for(; ihit!=curhits_read.end(); ++ihit){ + FTKHit tmphit = **ihit; + curhits.push_back(tmphit); + } + + } + else { + // set the reference the list used by the current region + vector &currawhits = *(m_original_reghits[curreg]); + vector &curhits = m_reghits[curreg]; + + // reset hit list + curhits.clear(); + + + if(FTKSetup::getDBG()) { + cout << "DBG: Original hits = " << currawhits.size() << endl; + } + m_nao_nhits_tot += currawhits.size(); + + if (!m_read_clusters) { + // if raw channels are read the clustering algorithm can be applyied (default) + if (m_Clustering ) { + clusteringEngine.atlClusteringLNF(currawhits); + clusteringEngine.atlClusteringBlayer(currawhits); // split blayer modules in half, if requested + } + else { + // If the clustering it is not executed the FTKRawHit.m_truth field has to be fixed + vector::iterator ihit = currawhits.begin(); + vector::const_iterator ihit_end = currawhits.end(); + for (;ihit!=ihit_end;++ihit) { // loop over the raw hits + FTKRawHit &curhit = *ihit; + MultiTruth mt; + MultiTruth::Barcode uniquecode(curhit.getEventIndex(),curhit.getBarcode()); + mt.maximize(uniquecode,curhit.getBarcodePt()); + curhit.setTruth(mt); + } // end hit + } + } + + if(FTKSetup::getDBG()) { + cout << "DBG: Clustered hits = " << m_original_hits.size() << endl; + } + m_nao_nclus_tot += currawhits.size(); + + // read SCTtrk values (Constantinos case) and push SCTtrk hits into hits vector: + // Note that it assumes the raw data input and root track input are fully in sync! + if(m_trackinput && m_roadinput) { + // for now, only read tracks from "current" region + int res = m_trackinput[curreg]->nextEvent(); + if(res<0) { + FTKSetup::PrintMessage(ftk::sevr,"SCTtrk input ran out before hit input"); + } + res = m_roadinput[curreg]->nextEvent(); + if(res<0) { + FTKSetup::PrintMessage(ftk::sevr,"SCTtrk road input ran out before hit input"); + } + const FTKTrack *cur_track = m_trackinput[curreg]->nextTrack(m_region); + while (cur_track) { + FTKRawHit tmphit(cur_track,m_pmap->getSCTtrkPlane()); + m_original_hits.push_back(tmphit); + cur_track = m_trackinput[curreg]->nextTrack(m_region); + } + } + + // filter the hit end convert input hit format into FTKHit + vector::iterator irawhit = currawhits.begin(); + FTKSetup &ftkset = FTKSetup::getFTKSetup(); + + // create one list for each plane to order the hits + list *planelist = new list[m_nplanes]; + + for (;irawhit!=currawhits.end();++irawhit) { // loop over clusters + FTKRawHit &rawhit = *irawhit; + + // check if end-cap hits should be accepted + if (rawhit.getBarrelEC()!=0 && ftkset.getBarrelOnly() == true) { + // skip this hit + continue; + } + // check if SCT hits should be accepted + if(rawhit.getIsSCT() && ftkset.getSCTtrkMode()) { + // skip this hit + continue; + } + if (m_pmap->getMap(rawhit.getHitType(),rawhit.getBarrelEC()!=0,rawhit.getLayer()).getPlane() != -1) { + // accept this hit + FTKHit tmphit = rawhit.getFTKHit(m_pmap); + if(rawhit.getTruth()!=nullptr) + tmphit.setTruth(*(rawhit.getTruth())); // AB - attach truth data to the FTKHit. + planelist[tmphit.getPlane()].push_front(tmphit); + } + else if (m_save_unused) { + // accept this hit + FTKHit tmphit = rawhit.getFTKHit(m_pmap_unused); + if(rawhit.getTruth()!=nullptr) + tmphit.setTruth(*(rawhit.getTruth())); // AB - attach truth data to the FTKHit. + m_hits_unused.push_back(tmphit); + } + } // end loop over clusters + + for (int ipl=0;ipl::iterator tmphit = planelist[ipl].begin(); + for (;tmphit!=planelist[ipl].end();++tmphit) { + curhits.push_back(*tmphit); + } + } // end loop over the planes + + // clear raw hits since we don't need them anymore + if(clearOrig) + currawhits.clear(); + + delete [] planelist; + } } diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTK_RawInput.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTK_RawInput.cxx index 8124777d6a5..1fb5e1ba9a4 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTK_RawInput.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTK_RawInput.cxx @@ -7,7 +7,7 @@ #include "TrigFTKSim/FTKSetup.h" #include "TrigFTKSim/FTKRoadFileInput.h" #include "TrigFTKSim/FTK_RawInput.h" -#include "TrigFTKSim/atlClustering.h" +#include "TrigFTKSim/FTKClusteringEngine.h" #include "TrigFTKSim/MultiTruth.h" #include "TrigFTKSim/PatternBank.h" diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTK_RegionalRawInput.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTK_RegionalRawInput.cxx index 36fd63e0883..16148a36913 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTK_RegionalRawInput.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTK_RegionalRawInput.cxx @@ -7,7 +7,6 @@ #include "TrigFTKSim/FTKSetup.h" #include "TrigFTKSim/FTKRoadFileInput.h" #include "TrigFTKSim/FTK_RegionalRawInput.h" -#include "TrigFTKSim/atlClustering.h" #include "TrigFTKSim/MultiTruth.h" #include "TrigFTKSim/PatternBank.h" @@ -32,7 +31,7 @@ using namespace std; FTK_RegionalRawInput::FTK_RegionalRawInput(const FTKPlaneMap *pmap, const FTKPlaneMap *pmap_unused,bool readTruthTracks) : FTKDataInput(pmap,pmap_unused), m_curfile(0x0), - m_hittree(0), m_hittree_branch(0), m_evtnum(0), m_evtnumE(0), m_evtinfo(0), m_trackstree(0), + m_hittree(0), m_hittree_branch(0), m_evtnum(0), m_evtnumE(0), m_evtinfo(0), m_trackstree(0), m_glob_event(0), m_ntruth_tracks(0),m_readTruthTracks(readTruthTracks),m_truthTracksTree(0) { m_regional = true; @@ -40,17 +39,17 @@ FTK_RegionalRawInput::FTK_RegionalRawInput(const FTKPlaneMap *pmap, const FTKPla FTK_RegionalRawInput::FTK_RegionalRawInput(const FTK_RegionalRawInput& v) : FTKDataInput(v), - m_curfile(v.m_curfile), - m_hittree(0), m_hittree_branch(0), m_evtnum(0), m_evtnumE(0), m_evtinfo(0), m_trackstree(0), + m_curfile(v.m_curfile), + m_hittree(0), m_hittree_branch(0), m_evtnum(0), m_evtnumE(0), m_evtinfo(0), m_trackstree(0), m_glob_event(v.m_glob_event), m_ntruth_tracks(0),m_readTruthTracks(v.m_readTruthTracks),m_truthTracksTree(0) -{ +{ m_regional = true; } FTK_RegionalRawInput::~FTK_RegionalRawInput() { if(m_trackinput) { - for(int i=0;iaddFile(path); + return m_roadinput[bank]->addFile(path); } /** @@ -154,7 +153,7 @@ int FTK_RegionalRawInput::addRoadFile(int bank, const char *path) { */ int FTK_RegionalRawInput::addRoadFilesList(int bank, const char *listpath) { cout << "in addFilesList_rd" << endl; - if(!m_roadinput || !m_roadinput[bank]) + if(!m_roadinput || !m_roadinput[bank]) { return -1; } @@ -170,13 +169,13 @@ const char* FTK_RegionalRawInput::getCurrentRoadFileName(int bank) { } -/** this method move to the next file in the list and +/** this method move to the next file in the list and reset the related flag */ int FTK_RegionalRawInput::nextFile() { if (m_read_FTKhits_directly) FTKSetup::PrintMessageFmt(ftk::info,"Reading hits in directly as FTKHits, skipping FTKRawHits.\n"); - if (!m_init) { + if (!m_init) { m_current_path = m_files_path.begin(); m_init = true; } @@ -239,7 +238,7 @@ int FTK_RegionalRawInput::nextFile() return 0; } } - + FTKSetup::PrintMessage(ftk::warn,"End of files list reached\n"); return -1; } @@ -247,7 +246,7 @@ int FTK_RegionalRawInput::nextFile() /** initilize the input */ int FTK_RegionalRawInput::init(bool *goodRegions) { - // setup clustering + // setup clustering initClustering(); // set the region to read and the ones to be skipped @@ -255,7 +254,7 @@ int FTK_RegionalRawInput::init(bool *goodRegions) for (int ireg=0;ireg!=m_nregions;++ireg) { m_goodRegions[ireg] = goodRegions[ireg]; } - + // prepare the objects read the file m_hittree_branch = new TBranch*[m_nregions]; m_original_reghits = new vector*[m_nregions]; @@ -322,7 +321,7 @@ int FTK_RegionalRawInput::readData() { int res(0); do { - if (m_evtnum==m_evtnumE) { + if (m_evtnum==m_evtnumE) { // reached last event go to the next file if (nextFile()==-1) { // read failed, attempt to use the next file @@ -330,7 +329,7 @@ int FTK_RegionalRawInput::readData() { } res = 1; } - + for (int ireg=0;ireg!=m_nregions;++ireg) { if (!m_goodRegions[ireg]) continue; // read the hits related to this tower diff --git a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx index b4626ced304..37114c81754 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/atlClustering.cxx @@ -17,6 +17,7 @@ #include "TrigFTKSim/FTKPMap.h" #include "TrigFTKSim/MultiTruth.h" #include "TrigFTKSim/ftkdefs.h" +#include "TrigFTKSim/FTKClusteringPrintout.h" #include #include @@ -37,7 +38,7 @@ using ftk::NEGEC; //#define DEBUG_HITS //#define DECODER_INPUT 0 -//#define DECODER_OUTPUT 0 +#define DECODER_OUTPUT 0 //#define CLUSTERING_PRINTOUT 0 //#define CENTROID_PRINTOUT 0 //#define BOUNDING_BOX @@ -49,7 +50,7 @@ const bool DEBUG_AVERAGE_SCT = 0; const bool PRINT_INPUT = 0; // print input data const bool DEBUG_INPUT = 0; // detail check input -const bool DEBUG_DECODER = 0; // check decoder output +const bool DEBUG_DECODER = 1; // check decoder output const bool DEBUG_CENTROID = 0; // check centroid calc. const unsigned int MOD_ID_PHI_VAL = 1; @@ -332,20 +333,19 @@ bool sortWords(const FTKRawHit* i, const FTKRawHit* j) } -//void printDecoderOutput(hitVector* currentHits) -void printDecoderOutput(hitVector* currentHits, bool isIBLmodule) +void printDecoderOutput(hitVector* currentHits) { hitVector::iterator hit = currentHits->begin(); hitVector *sortHits = currentHits; int idHash = hitToModuleId(**hit); + bool isIBLmodule = hitOnIBLmodule(**hit); if(isIBLmodule){ // Keisuke 20170215 stable_sort(sortHits->begin(), sortHits->end(), sortWords); idHash = hitToModuleId(**sortHits->begin()); } - if(DEBUG_DECODER) printDebugInfo(**hit); - + std::cout << "Found in Decoder" << std::hex << idHash << std::dec <begin(), sortHits->end(), sortWords); @@ -372,7 +372,6 @@ void printDecoderOutput(hitVector* currentHits, bool isIBLmodule) printf("0x8%.7x\n", hitToModuleId(**hit)); for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { printf("0x0%.2X%.2X%.3X",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); - //std::cout << (*hit)->getTot() << " " << (*hit)->getEtaStrip() << " " << (*hit)->getPhiSide() << std::endl; if(!DEBUG_DECODER) cout << endl; else{ cout << " Pixel HIT" @@ -532,77 +531,7 @@ bool pixelRowIsGanged(const int row) */ int hitToModuleId(const FTKRawHit &hit) { - //Default mode, return the Identifier Hash of the hit - if (hit.getIdentifierHash() > 0 && hit.getHitType() == PIXEL) { - return hit.getIdentifierHash(); - } - else if (hit.getIdentifierHash() > 0 && hit.getHitType() == SCT) { - return 0x8000 + hit.getIdentifierHash(); - } - - unsigned int ieta = 0; - if (FTKSetup::getFTKSetup().getIBLMode()==1){ - assert(hit.getEtaModule()>=-8 && hit.getEtaModule()<=8); // cy for ibl - } - else if (FTKSetup::getFTKSetup().getIBLMode()==2){ - assert(hit.getEtaModule()>=-10 && hit.getEtaModule()<=10); // version with 3D sensors - } - else{ - assert(hit.getEtaModule()>=-6 && hit.getEtaModule()<=6); - } - - if (FTKSetup::getFTKSetup().getIBLMode()==1 && hit.getBarrelEC() == ftk::BARREL && hit.getLayer() == 0 && hit.getIsPixel() == 1) { // for ibl - // eta index should range -8 to 8 for ibl - ieta = 8 + hit.getEtaModule(); // cy was 6 - } else if (FTKSetup::getFTKSetup().getIBLMode()==2 && hit.getBarrelEC() == ftk::BARREL && hit.getLayer() == 0 && hit.getIsPixel() == 1) { // for ibl - // eta index should range -8 to 8 for ibl - ieta = 10 + hit.getEtaModule(); // cy was 6 - } else if (hit.getBarrelEC() == BARREL){ - // eta index should range -6 to 6 for barrel - ieta = 6 + hit.getEtaModule(); // cy was 6 - } else { - // eta index should range 0 to 2 for endcaps (just 0 for pixels) - assert(hit.getEtaModule()>=0 && hit.getEtaModule()<3); - // removed dependency on getIBLMode because it is not needed - if (hit.getBarrelEC() == POSEC) - ieta = MAX_BARREL_ETA+hit.getEtaModule(); - if (hit.getBarrelEC() == NEGEC) - ieta = MAX_BARREL_ETA+3+hit.getEtaModule(); - } - - assert(ieta=1) { - assert(ilayer=10 && ilayersize()) { // as long as we have hits cluster clu; @@ -731,6 +660,7 @@ void makeClustersLNF(hitVector *currentHits, cluList *currentClusters) } } + void makeClusterFromSeed(hitVector *currentHits, cluList *currentClusters, FTKRawHit* &seed) { //erase seed fom currentHits @@ -793,17 +723,6 @@ bool findConnectedGanged(cluster &clu, hitVector &connectedHits) return hasNeighborhood; } -bool cluIsGanged(const cluster &clu) -{ - hitVector hv = clu.hitlist; - hitVector::iterator p; - for (p=hv.begin(); p!=hv.end(); ++p) { - if ( hitIsGanged(**p) ) return true; - } - - return false; -} - bool isKilled(const cluster &clu, const hitVector &connectedHits) { hitVector tmphv = clu.hitlist; @@ -837,8 +756,6 @@ void averageCluster(cluster &clu) FTKRawHit &av = clu.clusterEquiv; ///< get pointer to clusterEquivalent FTKRawHit *first = *(clu.hitlist.begin()); ///< get 1st hit - // cluster cluSplit = clu; // Yoshi 2016.11.24 - // FTKRawHit &avSplit = cluSplit.clusterEquiv; ///< get pointer to clusterEquivalent /// reset values for clusterEquivalent (alias av) av.reset(); @@ -855,7 +772,6 @@ void averageCluster(cluster &clu) av.setEtaStrip(0); av.setNStrips(0); av.setEtaWidth(0); - //printf("zeroing from %.8X %d %d\n", av.getHWWord(), av.getEtaWidth(), av.getPhiWidth()); av.setPhiWidth(0); av.setIncludesGanged(false); @@ -998,10 +914,7 @@ void averageCluster(cluster &clu) * In this code I'll use etaTrack instead of pixel eta for simplicity */ - //std::cout << "CNTRD: CALCULATE CLUSTER" << std::endl; for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { //loop over hits in cluster - //std::cout << "CNTRD: HIT " << (*p)->getEtaStrip() << " " << (*p)->getPhiSide() << " " << (*p)->getTot() << std::endl; - assert(av.getLayer()==(*p)->getLayer() && av.getPhiModule()==(*p)->getPhiModule() && av.getEtaModule()==(*p)->getEtaModule() ); if (SAVE_CLUSTER_CONTENT) { // if enabled the cluster also stores also the single channels FTKRawHit tmpch = *(*p); @@ -1053,8 +966,6 @@ void averageCluster(cluster &clu) } else if (isIBLmodule) { // IBL case row = 335 - (*p)->getPhiSide(); // inverse row coordinates // Yoshi 2016.10.28 // JAA updated 17.3.13 - // if(col >= 80) col = col - 80; // Yoshi 2016.11.18 - if(DEBUG_CENTROID){ printf("0x00%.2X%.2X%.3X", tot, col, row); cout << " IBL HIT" @@ -1402,6 +1313,9 @@ void realisticPixelDecoder(hitVector* ¤tHits) lifo_planar.pop(); } } + + std::cout << "GOING TO DECODER" << std::endl; + printDecoderOutput(currentHits); } @@ -1491,7 +1405,7 @@ void atlClusteringLNF(vector &hits) if (modId<0) assert(0); hitsByModule[modId].push_back( &(hits[i]) ); if (DUPLICATE_GANGED && hitIsGanged(hits[i])) { - //use the copy constructor instead of manually assigning each + //use the copy constructor instead of manually assigning each //variable, as was done previously. the usage here is the //whole point of having a copy constructor! gangedPixelList.push_back( hits[i] ); @@ -1501,23 +1415,23 @@ void atlClusteringLNF(vector &hits) } } + test(); /* * Second: build the list of clusters */ clustersByModuleMap clustersByModule; ///< store clusters by module hitsByModuleMap::iterator p; - for (p = hitsByModule.begin(); p!=hitsByModule.end(); ++p) { // loop over modules - hitVector *currentHits = & (p->second); + for (auto& module: hitsByModule) { // loop over modules + hitVector *currentHits = & (module.second); FTKRawHit &firstHit = **(currentHits->begin()); - int modId = hitToModuleId( firstHit ); - std::cout << std::hex << "Type: " << firstHit.getModuleType() << " hashId:" << firstHit.getIdentifierHash() << " modId:" << hitToModuleId(firstHit) << std::dec << std::endl; - - if(PRINT_INPUT) - printInputData(currentHits); + int modId = module.first; cluList *currentClusters = new cluList(); // instantiate cluster list clustersByModule[modId] = currentClusters; + std::cout << "InputData " << std::hex << modId << std::dec << endl; + printInputData(currentHits); + //The ideal clustering is going to be used in the following cases: //1. PIXEL_CLUSTERING_MODE is less than 100 (PIXEL_CLUSTERING_MIXED) //2. The module is not a pixel module @@ -1575,6 +1489,8 @@ void atlClusteringLNF(vector &hits) } } + + #if defined(CENTROID_PRINTOUT) printCentroidList(clustersByModule); #endif @@ -1586,9 +1502,9 @@ void atlClusteringLNF(vector &hits) int hitCounter=0; int deletedGangedClusters=0; - for (cluModP=clustersByModule.begin(); cluModP!=clustersByModule.end(); cluModP++) { + for (auto& cluModP: clustersByModule) { cluList::iterator cluP; - for (cluP=cluModP->second->begin(); cluP!=cluModP->second->end(); cluP++) { + for (cluP=cluModP.second->begin(); cluP!=cluModP.second->end(); cluP++) { // kill clusters with ganged hits according to ganged pattern recognition if ( GANGED_PATTERN_RECOGNITION && cluP->isKilled && !cluP->isSafe ) { // AA 2009-07-07 removing the "isSafe" protection does not change @@ -1602,7 +1518,7 @@ void atlClusteringLNF(vector &hits) hits.push_back(cluEquiv); ++hitCounter; } - delete cluModP->second; + delete cluModP.second; } assert( (hitCounter+deletedGangedClusters) == nTotClu ); -- GitLab From 8146bd36e1557bc7df064606736150fdfa3d9dd5 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Tue, 26 Feb 2019 19:48:05 +0100 Subject: [PATCH 08/18] Modifications to make it compile --- .../FastTrackSimWrap/FTKRegionalWrapper.h | 2 + .../src/FTKRegionalWrapper.cxx | 2127 +++++++++-------- .../TrigFTKSim/FTKClusteringEngine.h | 70 + .../TrigFTKSim/FTKClusteringPrintout.h | 2 +- .../TrigFTKSim/src/FTKClusteringEngine.cxx | 78 +- .../TrigFTKSim/src/FTKClusteringPrintout.cxx | 75 +- .../TrigFTK/TrigFTKSim/src/FTKDataInput.cxx | 8 +- 7 files changed, 1188 insertions(+), 1174 deletions(-) diff --git a/Trigger/TrigFTK/FastTrackSimWrap/FastTrackSimWrap/FTKRegionalWrapper.h b/Trigger/TrigFTK/FastTrackSimWrap/FastTrackSimWrap/FTKRegionalWrapper.h index 4c1241b1057..ea828c17a5b 100644 --- a/Trigger/TrigFTK/FastTrackSimWrap/FastTrackSimWrap/FTKRegionalWrapper.h +++ b/Trigger/TrigFTK/FastTrackSimWrap/FastTrackSimWrap/FTKRegionalWrapper.h @@ -70,6 +70,8 @@ private: const InDetDD::SiDetectorManager* m_PIX_mgr; const InDetDD::SiDetectorManager* m_SCT_mgr; + FTKClusteringEngine* clusteringEngine; + // variables to manage the distribution of the hits int m_IBLMode; // global FTK setup variable to handle IBL diff --git a/Trigger/TrigFTK/FastTrackSimWrap/src/FTKRegionalWrapper.cxx b/Trigger/TrigFTK/FastTrackSimWrap/src/FTKRegionalWrapper.cxx index 9a4f017495b..cabab68a2f2 100644 --- a/Trigger/TrigFTK/FastTrackSimWrap/src/FTKRegionalWrapper.cxx +++ b/Trigger/TrigFTK/FastTrackSimWrap/src/FTKRegionalWrapper.cxx @@ -5,7 +5,7 @@ #include "xAODTracking/TrackParticleContainer.h" #include "FastTrackSimWrap/FTKRegionalWrapper.h" #include "TrigFTKSim/FTKDataInput.h" -#include "TrigFTKSim/atlClustering.h" +#include "TrigFTKSim/FTKClusteringEngine.h" #include "TrkTruthData/PRD_MultiTruthCollection.h" @@ -25,909 +25,910 @@ #include "SCT_Cabling/SCT_SerialNumber.h" #include -#include +#include FTKRegionalWrapper::FTKRegionalWrapper (const std::string& name, ISvcLocator* pSvcLocator) : - AthAlgorithm(name, pSvcLocator), - m_hitInputTool("FTK_SGHitInput/FTK_SGHitInput"), - m_clusterConverterTool("TrigFTKClusterConverterTool"), - m_pix_cabling_svc("PixelCablingSvc", name), - m_sct_cabling_svc("SCT_CablingSvc", name), - m_storeGate(0), - m_detStore( 0 ), - m_evtStore(0 ), - m_pixelId(0), - m_sctId(0), - m_idHelper(0), - m_PIX_mgr(0), - m_SCT_mgr(0), - m_IBLMode(0), - m_fixEndcapL0(false), - m_ITkMode(false), - m_pmap_path(""), - m_pmap(0x0), - m_rmap_path(""), - m_rmap(0x0), - m_ntowers(0), - m_nplanes(12), - m_SaveRawHits(true), - m_SaveHits(false), - m_SavePerPlane(false), - m_DumpTestVectors(false), - m_EmulateDF(false), - m_Clustering(false), - m_SaveClusterContent(false), - m_DiagClustering(true), - m_SctClustering(false), - m_PixelClusteringMode(1), - m_Ibl3DRealistic(false), - m_DuplicateGanged(true), - m_GangedPatternRecognition(false), - m_WriteClustersToESD(false), - m_getOffline(false), - m_offlineName("InDetTrackParticles"), - m_outpath("ftksim_smartwrapper.root"), - m_outfile(0x0), - m_hittree(0x0), - m_hittree_perplane(0), - m_original_hits(0), - m_logical_hits(0), - m_original_hits_per_plane(0), - m_logical_hits_per_plane(0), - m_evtinfo(0), - m_run_number(0), - m_event_number(0), - m_trackstree(0), - m_identifierHashList(0x0), + AthAlgorithm(name, pSvcLocator), + m_hitInputTool("FTK_SGHitInput/FTK_SGHitInput"), + m_clusterConverterTool("TrigFTKClusterConverterTool"), + m_pix_cabling_svc("PixelCablingSvc", name), + m_sct_cabling_svc("SCT_CablingSvc", name), + m_storeGate(0), + m_detStore( 0 ), + m_evtStore(0 ), + m_pixelId(0), + m_sctId(0), + m_idHelper(0), + m_PIX_mgr(0), + m_SCT_mgr(0), + m_IBLMode(0), + m_fixEndcapL0(false), + m_ITkMode(false), + m_pmap_path(""), + m_pmap(0x0), + m_rmap_path(""), + m_rmap(0x0), + m_ntowers(0), + m_nplanes(12), + m_SaveRawHits(true), + m_SaveHits(false), + m_SavePerPlane(false), + m_DumpTestVectors(false), + m_EmulateDF(false), + m_Clustering(false), + m_SaveClusterContent(false), + m_DiagClustering(true), + m_SctClustering(false), + m_PixelClusteringMode(1), + m_Ibl3DRealistic(false), + m_DuplicateGanged(true), + m_GangedPatternRecognition(false), + m_WriteClustersToESD(false), + m_getOffline(false), + m_offlineName("InDetTrackParticles"), + m_outpath("ftksim_smartwrapper.root"), + m_outfile(0x0), + m_hittree(0x0), + m_hittree_perplane(0), + m_original_hits(0), + m_logical_hits(0), + m_original_hits_per_plane(0), + m_logical_hits_per_plane(0), + m_evtinfo(0), + m_run_number(0), + m_event_number(0), + m_trackstree(0), + m_identifierHashList(0x0), // m_pix_rodIdlist({0x130011, 0x111510, 0x111508, 0x112414, 0x130015, 0x111716, 0x112416}), //old ROD list for consistency. to be removed soon. // m_sct_rodIdlist({0x220005, 0x210005, 0x220007}), - //run II configuration for towers 44 & 45 (DF Crate 3 slot 9) - //m_pix_rodIdlist({0x140160, 0x130007, 0x112508, 0x111816, 0x140170, 0x130015,0x112414}), - //m_sct_rodIdlist({0x21010d, 0x21010c, 0x21010e,0x21010f}), - - //run 1 configuration for towers 44 & 45 (DF Crate 3 slot 9) - //m_pix_rodIdlist({0x130007, 0x111510, 0x111816, 0x111508,0x112414}), - //m_sct_rodIdlist({0x21010a, 0x210000}), - - //AUX test vector configuration for tower 44 & 45 (DF Crate 3 slot 9) - //m_pix_rodIdlist({0x130007, 0x112510, 0x111816, 0x112508,0x112414}), - //m_sct_rodIdlist({0x21010a, 0x210000}), - - // m_pix_rodIdlist({0x130007, 0x111510, 0x111816, 0x111508,0x112414,0x1400a3,0x130010,0x130011,0x112508,0x112510}), - // m_sct_rodIdlist({0x21010a, 0x210000, 0x210109}), - - m_pix_rodIdlist({0x112414, 0x140170, 0x111816, 0x112411, 0x112416, 0x140140, 0x140180, 0x130011}), - m_sct_rodIdlist({0x210000, 0x210109, 0x210108, 0x230100, 0x220000, 0x220109, 0x22010a, 0x21010a}), - - m_spix_rodIdlist({"0x112414", "0x140170", "0x111816", "0x112411", "0x112416", "0x140140", "0x140180", "0x130011"}), - m_ssct_rodIdlist({"0x210000", "0x210109", "0x210108", "0x230100", "0x220000", "0x220109", "0x22010a", "0x21010a"}), - - m_FTKPxlClu_CollName("FTK_Pixel_Clusters"), - m_FTKPxlCluContainer(0x0), - m_FTKSCTClu_CollName("FTK_SCT_Cluster"), - m_FTKSCTCluContainer(0x0), - m_ftkPixelTruthName("PRD_MultiTruthPixel_FTK"), - m_ftkSctTruthName("PRD_MultiTruthSCT_FTK"), - m_mcTruthName("TruthEvent"), - m_L1ID_to_save(std::vector()), - offline_locX(nullptr), - offline_locY(nullptr), - offline_isPixel(nullptr), - offline_isBarrel(nullptr), - offline_layer(nullptr), - offline_clustID(nullptr), - offline_trackNumber(nullptr), - offline_pt(nullptr), - offline_eta(nullptr), - offline_phi(nullptr), - m_offline_cluster_tree(nullptr) + //run II configuration for towers 44 & 45 (DF Crate 3 slot 9) + //m_pix_rodIdlist({0x140160, 0x130007, 0x112508, 0x111816, 0x140170, 0x130015,0x112414}), + //m_sct_rodIdlist({0x21010d, 0x21010c, 0x21010e,0x21010f}), + + //run 1 configuration for towers 44 & 45 (DF Crate 3 slot 9) + //m_pix_rodIdlist({0x130007, 0x111510, 0x111816, 0x111508,0x112414}), + //m_sct_rodIdlist({0x21010a, 0x210000}), + + //AUX test vector configuration for tower 44 & 45 (DF Crate 3 slot 9) + //m_pix_rodIdlist({0x130007, 0x112510, 0x111816, 0x112508,0x112414}), + //m_sct_rodIdlist({0x21010a, 0x210000}), + + // m_pix_rodIdlist({0x130007, 0x111510, 0x111816, 0x111508,0x112414,0x1400a3,0x130010,0x130011,0x112508,0x112510}), + // m_sct_rodIdlist({0x21010a, 0x210000, 0x210109}), + + m_pix_rodIdlist({0x112414, 0x140170, 0x111816, 0x112411, 0x112416, 0x140140, 0x140180, 0x130011}), + m_sct_rodIdlist({0x210000, 0x210109, 0x210108, 0x230100, 0x220000, 0x220109, 0x22010a, 0x21010a}), + + m_spix_rodIdlist({"0x112414", "0x140170", "0x111816", "0x112411", "0x112416", "0x140140", "0x140180", "0x130011"}), + m_ssct_rodIdlist({"0x210000", "0x210109", "0x210108", "0x230100", "0x220000", "0x220109", "0x22010a", "0x21010a"}), + + m_FTKPxlClu_CollName("FTK_Pixel_Clusters"), + m_FTKPxlCluContainer(0x0), + m_FTKSCTClu_CollName("FTK_SCT_Cluster"), + m_FTKSCTCluContainer(0x0), + m_ftkPixelTruthName("PRD_MultiTruthPixel_FTK"), + m_ftkSctTruthName("PRD_MultiTruthSCT_FTK"), + m_mcTruthName("TruthEvent"), + m_L1ID_to_save(std::vector()), + offline_locX(nullptr), + offline_locY(nullptr), + offline_isPixel(nullptr), + offline_isBarrel(nullptr), + offline_layer(nullptr), + offline_clustID(nullptr), + offline_trackNumber(nullptr), + offline_pt(nullptr), + offline_eta(nullptr), + offline_phi(nullptr), + m_offline_cluster_tree(nullptr) { - - declareProperty("TrigFTKClusterConverterTool", m_clusterConverterTool); - declareProperty("RMapPath",m_rmap_path); - declareProperty("PMapPath",m_pmap_path); - declareProperty("OutFileName",m_outpath); - declareProperty("HitInputTool",m_hitInputTool); - declareProperty("IBLMode",m_IBLMode); - declareProperty("FixEndcapL0", m_fixEndcapL0); - declareProperty("ITkMode",m_ITkMode); - declareProperty("PixelCablingSvc", m_pix_cabling_svc); - declareProperty("ISCT_CablingSvc",m_sct_cabling_svc); - - // hit type options - declareProperty("SaveRawHits",m_SaveRawHits); - declareProperty("SaveHits",m_SaveHits); - - // special options for test vector production - declareProperty("SavePerPlane",m_SavePerPlane); - declareProperty("DumpTestVectors",m_DumpTestVectors); - - declareProperty("GetOffline",m_getOffline); - declareProperty("OfflineName",m_offlineName); - - // clustering options - declareProperty("Clustering",m_Clustering); - declareProperty("SaveClusterContent",m_SaveClusterContent); - declareProperty("DiagClustering",m_DiagClustering); - declareProperty("SctClustering",m_SctClustering); - declareProperty("PixelClusteringMode",m_PixelClusteringMode); - declareProperty("Ibl3DRealistic",m_Ibl3DRealistic); - declareProperty("DuplicateGanged",m_DuplicateGanged); - declareProperty("GangedPatternRecognition",m_GangedPatternRecognition); - - - //output for PseduoTracking - declareProperty("WriteClustersToESD",m_WriteClustersToESD); - declareProperty("FTKPixelClustersCollName",m_FTKPxlClu_CollName,"FTK pixel clusters collection"); - declareProperty("FTKSCTClusterCollName",m_FTKSCTClu_CollName,"FTK SCT clusters collection"); - - //for DF board emulation - declareProperty("EmulateDF",m_EmulateDF); - declareProperty("pixRodIds", m_spix_rodIdlist); - declareProperty("sctRodIds", m_ssct_rodIdlist); - declareProperty("L1IDToSave", m_L1ID_to_save); + + declareProperty("TrigFTKClusterConverterTool", m_clusterConverterTool); + declareProperty("RMapPath",m_rmap_path); + declareProperty("PMapPath",m_pmap_path); + declareProperty("OutFileName",m_outpath); + declareProperty("HitInputTool",m_hitInputTool); + declareProperty("IBLMode",m_IBLMode); + declareProperty("FixEndcapL0", m_fixEndcapL0); + declareProperty("ITkMode",m_ITkMode); + declareProperty("PixelCablingSvc", m_pix_cabling_svc); + declareProperty("ISCT_CablingSvc",m_sct_cabling_svc); + + // hit type options + declareProperty("SaveRawHits",m_SaveRawHits); + declareProperty("SaveHits",m_SaveHits); + + // special options for test vector production + declareProperty("SavePerPlane",m_SavePerPlane); + declareProperty("DumpTestVectors",m_DumpTestVectors); + + declareProperty("GetOffline",m_getOffline); + declareProperty("OfflineName",m_offlineName); + + // clustering options + declareProperty("Clustering",m_Clustering); + declareProperty("SaveClusterContent",m_SaveClusterContent); + declareProperty("DiagClustering",m_DiagClustering); + declareProperty("SctClustering",m_SctClustering); + declareProperty("PixelClusteringMode",m_PixelClusteringMode); + declareProperty("Ibl3DRealistic",m_Ibl3DRealistic); + declareProperty("DuplicateGanged",m_DuplicateGanged); + declareProperty("GangedPatternRecognition",m_GangedPatternRecognition); + + + //output for PseduoTracking + declareProperty("WriteClustersToESD",m_WriteClustersToESD); + declareProperty("FTKPixelClustersCollName",m_FTKPxlClu_CollName,"FTK pixel clusters collection"); + declareProperty("FTKSCTClusterCollName",m_FTKSCTClu_CollName,"FTK SCT clusters collection"); + + //for DF board emulation + declareProperty("EmulateDF",m_EmulateDF); + declareProperty("pixRodIds", m_spix_rodIdlist); + declareProperty("sctRodIds", m_ssct_rodIdlist); + declareProperty("L1IDToSave", m_L1ID_to_save); } FTKRegionalWrapper::~FTKRegionalWrapper () { - if (m_rmap) delete m_rmap; + if (m_rmap) delete m_rmap; } StatusCode FTKRegionalWrapper::initialize() { - MsgStream log(msgSvc(), name()); - log << MSG::INFO << "FTKRegionalWrapper::initialize()" << endmsg; - - // FTK library global setup variables - FTKSetup::getFTKSetup().setIBLMode(m_IBLMode); - FTKSetup::getFTKSetup().setfixEndcapL0(m_fixEndcapL0); - FTKSetup::getFTKSetup().setITkMode(m_ITkMode); - - log << MSG::INFO << "Read the logical layer definitions" << endmsg; - // Look for the main plane-map - if (m_pmap_path.empty()) { - log << MSG::FATAL << "Main plane map definition missing" << endmsg; - return StatusCode::FAILURE; - } - else { - m_pmap = new FTKPlaneMap(m_pmap_path.c_str()); - if (!(*m_pmap)) { - log << MSG::FATAL << "Error using plane map: " << m_pmap_path << endmsg; - return StatusCode::FAILURE; + MsgStream log(msgSvc(), name()); + log << MSG::INFO << "FTKRegionalWrapper::initialize()" << endmsg; + + // FTK library global setup variables + FTKSetup::getFTKSetup().setIBLMode(m_IBLMode); + FTKSetup::getFTKSetup().setfixEndcapL0(m_fixEndcapL0); + FTKSetup::getFTKSetup().setITkMode(m_ITkMode); + + log << MSG::INFO << "Read the logical layer definitions" << endmsg; + // Look for the main plane-map + if (m_pmap_path.empty()) { + log << MSG::FATAL << "Main plane map definition missing" << endmsg; + return StatusCode::FAILURE; + } + else { + m_pmap = new FTKPlaneMap(m_pmap_path.c_str()); + if (!(*m_pmap)) { + log << MSG::FATAL << "Error using plane map: " << m_pmap_path << endmsg; + return StatusCode::FAILURE; + } + } + + // initialize the tower/region map + log << MSG::INFO << "Creating region map" << endmsg; + m_rmap = new FTKRegionMap(m_pmap, m_rmap_path.c_str()); + if (!(*m_rmap)) { + log << MSG::FATAL << "Error creating region map from: " << m_rmap_path.c_str() << endmsg; + return StatusCode::FAILURE; + } + + StatusCode schit = m_hitInputTool.retrieve(); + if (schit.isFailure()) { + log << MSG::FATAL << "Could not retrieve FTK_SGHitInput tool" << endmsg; + return StatusCode::FAILURE; + } + else { + log << MSG::INFO << "Setting FTK_SGHitInput tool" << endmsg; + // set the pmap address to FTKDataInput to use in processEvent + m_hitInputTool->reference()->setPlaneMaps(m_pmap,0x0); } - } - - // initialize the tower/region map - log << MSG::INFO << "Creating region map" << endmsg; - m_rmap = new FTKRegionMap(m_pmap, m_rmap_path.c_str()); - if (!(*m_rmap)) { - log << MSG::FATAL << "Error creating region map from: " << m_rmap_path.c_str() << endmsg; - return StatusCode::FAILURE; - } - - StatusCode schit = m_hitInputTool.retrieve(); - if (schit.isFailure()) { - log << MSG::FATAL << "Could not retrieve FTK_SGHitInput tool" << endmsg; - return StatusCode::FAILURE; - } - else { - log << MSG::INFO << "Setting FTK_SGHitInput tool" << endmsg; - // set the pmap address to FTKDataInput to use in processEvent - m_hitInputTool->reference()->setPlaneMaps(m_pmap,0x0); - } - - // Get the cluster converter tool - if (m_clusterConverterTool.retrieve().isFailure() ) { - log << MSG::ERROR << "Failed to retrieve tool " << m_clusterConverterTool << endmsg; - return StatusCode::FAILURE; - } - - // Retrieve pixel cabling service - if( m_ITkMode ) { - // Pixel Cabling database not ready - // Ignore this error but make sure everything that uses the cabling database is off - log << MSG::WARNING << "ITkMode is set to True --> not loading Pixel Cabling Svc" << endmsg; - if( m_DumpTestVectors || m_EmulateDF ) { - log << MSG::FATAL << "PixelCabling not initialized so m_DumpTestVectors and m_EmulateDF must both be set to false!" << endmsg; - return StatusCode::FAILURE; + + // Get the cluster converter tool + if (m_clusterConverterTool.retrieve().isFailure() ) { + log << MSG::ERROR << "Failed to retrieve tool " << m_clusterConverterTool << endmsg; + return StatusCode::FAILURE; + } + + // Retrieve pixel cabling service + if( m_ITkMode ) { + // Pixel Cabling database not ready + // Ignore this error but make sure everything that uses the cabling database is off + log << MSG::WARNING << "ITkMode is set to True --> not loading Pixel Cabling Svc" << endmsg; + if( m_DumpTestVectors || m_EmulateDF ) { + log << MSG::FATAL << "PixelCabling not initialized so m_DumpTestVectors and m_EmulateDF must both be set to false!" << endmsg; + return StatusCode::FAILURE; + } + } else if (m_pix_cabling_svc.retrieve().isFailure()) { + log << MSG::FATAL << "Failed to retrieve tool " << m_pix_cabling_svc << endmsg; + return StatusCode::FAILURE; + } else { + log << MSG::INFO << "Retrieved tool " << m_pix_cabling_svc << endmsg; } - } else if (m_pix_cabling_svc.retrieve().isFailure()) { - log << MSG::FATAL << "Failed to retrieve tool " << m_pix_cabling_svc << endmsg; - return StatusCode::FAILURE; - } else { - log << MSG::INFO << "Retrieved tool " << m_pix_cabling_svc << endmsg; - } - - // Retrieve sct cabling service - if( m_ITkMode ) { - // SCT Cabling database not ready - // Ignore this error but make sure everything that uses the cabling database is off - log << MSG::WARNING << "ITkMode is set to True --> not loading SCT Cabling Svc" << endmsg; - if( m_DumpTestVectors || m_EmulateDF ) { - log << MSG::FATAL << "SCT_Cabling not initialized so m_DumpTestVectors and m_EmulateDF must both be set to false!" << endmsg; - return StatusCode::FAILURE; + + // Retrieve sct cabling service + if( m_ITkMode ) { + // SCT Cabling database not ready + // Ignore this error but make sure everything that uses the cabling database is off + log << MSG::WARNING << "ITkMode is set to True --> not loading SCT Cabling Svc" << endmsg; + if( m_DumpTestVectors || m_EmulateDF ) { + log << MSG::FATAL << "SCT_Cabling not initialized so m_DumpTestVectors and m_EmulateDF must both be set to false!" << endmsg; + return StatusCode::FAILURE; + } + } else if (m_sct_cabling_svc.retrieve().isFailure()) { + log << MSG::FATAL << "Failed to retrieve tool " << m_sct_cabling_svc << endmsg; + return StatusCode::FAILURE; + } else { + log << MSG::INFO << "Retrieved tool " << m_sct_cabling_svc << endmsg; } - } else if (m_sct_cabling_svc.retrieve().isFailure()) { - log << MSG::FATAL << "Failed to retrieve tool " << m_sct_cabling_svc << endmsg; - return StatusCode::FAILURE; - } else { - log << MSG::INFO << "Retrieved tool " << m_sct_cabling_svc << endmsg; - } - - if (!m_SaveRawHits && !m_SaveHits) { - log << MSG::FATAL << "At least one hit format has to be saved: FTKRawHit or FTKHit" << endl; - return StatusCode::FAILURE; - } - - // This part retrieves the neccessary pixel/SCT Id helpers. They are intialized by the StoreGateSvc - if( service("StoreGateSvc", m_storeGate).isFailure() ) { - log << MSG::FATAL << "StoreGate service not found" << endmsg; - return StatusCode::FAILURE; - } - if( service("DetectorStore",m_detStore).isFailure() ) { - log << MSG::FATAL <<"DetectorStore service not found" << endmsg; - return StatusCode::FAILURE; - } - // if( service("EventStore",m_evtStore).isFailure() ) { - // log << MSG::FATAL <<"EventStore service not found" << endmsg; - // return StatusCode::FAILURE; - // } - if( m_detStore->retrieve(m_pixelId, "PixelID").isFailure() ) { - log << MSG::ERROR << "Unable to retrieve Pixel helper from DetectorStore" << endmsg; - return StatusCode::FAILURE; - } - if( m_detStore->retrieve(m_sctId, "SCT_ID").isFailure() ) { - log << MSG::ERROR << "Unable to retrieve Pixel helper from DetectorStore" << endmsg; - return StatusCode::FAILURE; - } - if( m_detStore->retrieve(m_idHelper, "AtlasID").isFailure() ) { - log << MSG::ERROR << "Unable to retrieve AtlasDetector helper from DetectorStore" << endmsg; - return StatusCode::FAILURE; - } - - if( m_detStore->retrieve(m_PIX_mgr, "Pixel").isFailure() ) { - log << MSG::ERROR << "Unable to retrieve Pixel manager from DetectorStore" << endmsg; - return StatusCode::FAILURE; - } - - if( m_detStore->retrieve(m_SCT_mgr, "SCT").isFailure() ) { - log << MSG::ERROR << "Unable to retrieve SCT manager from DetectorStore" << endmsg; - return StatusCode::FAILURE; - } - - - // Write clusters in InDetCluster format to ESD for use in Pseudotracking - if (m_WriteClustersToESD){ - StatusCode sc = service("StoreGateSvc", m_storeGate); - // Creating collection for pixel clusters - m_FTKPxlCluContainer = new InDet::PixelClusterContainer(m_pixelId->wafer_hash_max()); - m_FTKPxlCluContainer->addRef(); - sc = m_storeGate->record(m_FTKPxlCluContainer,m_FTKPxlClu_CollName); - if (sc.isFailure()) { - log << MSG::FATAL << "Error registering the FTK pixel container in the SG" << endmsg; - return StatusCode::FAILURE; + + if (!m_SaveRawHits && !m_SaveHits) { + log << MSG::FATAL << "At least one hit format has to be saved: FTKRawHit or FTKHit" << endl; + return StatusCode::FAILURE; } - - // Generic format link for the pixel clusters - const InDet::SiClusterContainer *symSiContainerPxl(0x0); - sc = m_storeGate->symLink(m_FTKPxlCluContainer,symSiContainerPxl); - if (sc.isFailure()) { - log << MSG::FATAL << "Error creating the sym-link to the Pixel clusters" << endmsg; - return StatusCode::FAILURE; + + // This part retrieves the neccessary pixel/SCT Id helpers. They are intialized by the StoreGateSvc + if( service("StoreGateSvc", m_storeGate).isFailure() ) { + log << MSG::FATAL << "StoreGate service not found" << endmsg; + return StatusCode::FAILURE; } - - // Creating collection for the SCT clusters - m_FTKSCTCluContainer = new InDet::SCT_ClusterContainer(m_sctId->wafer_hash_max()); - m_FTKSCTCluContainer->addRef(); - sc = m_storeGate->record(m_FTKSCTCluContainer,m_FTKSCTClu_CollName); - if (sc.isFailure()) { - log << MSG::FATAL << "Error registering the FTK SCT container in the SG" << endmsg; - return StatusCode::FAILURE; + if( service("DetectorStore",m_detStore).isFailure() ) { + log << MSG::FATAL <<"DetectorStore service not found" << endmsg; + return StatusCode::FAILURE; } - // Generic format link for the pixel clusters - const InDet::SiClusterContainer *symSiContainerSCT(0x0); - sc = m_storeGate->symLink(m_FTKSCTCluContainer,symSiContainerSCT); - if (sc.isFailure()) { - log << MSG::FATAL << "Error creating the sym-link to the SCT clusters" << endmsg; - return StatusCode::FAILURE; + // if( service("EventStore",m_evtStore).isFailure() ) { + // log << MSG::FATAL <<"EventStore service not found" << endmsg; + // return StatusCode::FAILURE; + // } + if( m_detStore->retrieve(m_pixelId, "PixelID").isFailure() ) { + log << MSG::ERROR << "Unable to retrieve Pixel helper from DetectorStore" << endmsg; + return StatusCode::FAILURE; } - - // getting sct truth - if(!m_storeGate->contains(m_ftkSctTruthName)) { - m_ftkSctTruth = new PRD_MultiTruthCollection; - StatusCode sc=m_storeGate->record(m_ftkSctTruth,m_ftkSctTruthName); - if(sc.isFailure()) { - ATH_MSG_WARNING("SCT FTK Truth Container " << m_ftkSctTruthName - <<" cannot be recorded in StoreGate !"); - } - else { - ATH_MSG_DEBUG("SCT FTK Truth Container " << m_ftkSctTruthName - << " is recorded in StoreGate"); - } - } - //getting pixel truth - if(!m_storeGate->contains(m_ftkPixelTruthName)) { - m_ftkPixelTruth = new PRD_MultiTruthCollection; - StatusCode sc=m_storeGate->record(m_ftkPixelTruth,m_ftkPixelTruthName); - if(sc.isFailure()) { - ATH_MSG_WARNING("Pixel FTK Truth Container " << m_ftkPixelTruthName - <<" cannot be recorded in StoreGate !"); - } - else { - ATH_MSG_DEBUG("Pixel FTK Truth Container " << m_ftkPixelTruthName - << " is recorded in StoreGate"); - } - } - } - - - /* initialize the clustering global variables, decalred in TrigFTKSim/atlClusteringLNF.h */ - SAVE_CLUSTER_CONTENT = m_SaveClusterContent; - DIAG_CLUSTERING = m_DiagClustering; - SCT_CLUSTERING = m_SctClustering; - PIXEL_CLUSTERING_MODE = m_PixelClusteringMode; - IBL3D_REALISTIC = m_Ibl3DRealistic; - DUPLICATE_GANGED = m_DuplicateGanged; - GANGED_PATTERN_RECOGNITION = m_GangedPatternRecognition; - - - //Dump to the log output the RODs used in the emulation - if(m_EmulateDF){ - - ATH_MSG_DEBUG("Printing full map via m_pix_cabling_svc->get_idMap_offrob(); "); - std::map< Identifier, uint32_t> offmap = m_pix_cabling_svc->get_idMap_offrob(); - for (auto mit = offmap.begin(); mit != offmap.end(); mit++){ - //uint id = mit->first; - ATH_MSG_DEBUG("Pixel offline map hashID to RobId "<first<<" "<second<retrieve(m_sctId, "SCT_ID").isFailure() ) { + log << MSG::ERROR << "Unable to retrieve Pixel helper from DetectorStore" << endmsg; + return StatusCode::FAILURE; } - ATH_MSG_DEBUG("Printing full SCT map via m_sct_cabling_svc->getAllRods()"); - std::vector sctVector; - m_sct_cabling_svc->getAllRods(sctVector); - ATH_MSG_DEBUG("Printing full SCT map via m_sct_cabling_svc->getAllRods() "<getHashesForRod(m_identifierHashList,*mit ); - ATH_MSG_DEBUG("Retrieved "<>std::hex>>val; - - m_pix_rodIdlist.push_back(val); - - ATH_MSG_DEBUG("Going to test against the following Pix RODIDs "<< MSG::hex - << val < offlineIdHashList; - m_pix_cabling_svc->getOfflineList(offlineIdHashList, m_pix_cabling_svc->getRobId(val)); - ATH_MSG_DEBUG("Trying m_pix_cabling_svc->getOfflineList(offlineIdHashList, m_pix_cabling_svc->getRobId("<wafer_id( *oit ); - int barrel_ec = m_pixelId->barrel_ec(id); - int layer_disk = m_pixelId->layer_disk(id); - int phi_module = m_pixelId->phi_module(id); - int eta_module = m_pixelId->eta_module(id); - - ATH_MSG_DEBUG("hashId "<<*oit<<"for rodID "<retrieve(m_idHelper, "AtlasID").isFailure() ) { + log << MSG::ERROR << "Unable to retrieve AtlasDetector helper from DetectorStore" << endmsg; + return StatusCode::FAILURE; } - m_sct_rodIdlist.clear(); - for (auto it = m_ssct_rodIdlist.begin(); it < m_ssct_rodIdlist.end(); it++){ - std::stringstream str; - str<<(*it); - int val; - str>>std::hex>>val; - m_sct_rodIdlist.push_back(val); - - ATH_MSG_DEBUG("Going to test against the following SCT RODIDs "<< MSG::hex - << val <retrieve(m_PIX_mgr, "Pixel").isFailure() ) { + log << MSG::ERROR << "Unable to retrieve Pixel manager from DetectorStore" << endmsg; + return StatusCode::FAILURE; } - - } + if( m_detStore->retrieve(m_SCT_mgr, "SCT").isFailure() ) { + log << MSG::ERROR << "Unable to retrieve SCT manager from DetectorStore" << endmsg; + return StatusCode::FAILURE; + } - return StatusCode::SUCCESS; -} -StatusCode FTKRegionalWrapper::initOutputFile() { - /* - * prepare the output structure to store the hits and the other information - */ - - MsgStream log(msgSvc(), name()); - log << MSG::INFO << "FTKRegionalWrapper::initOutputFile()" << endmsg; - - - // create the output files - log << MSG::INFO << "Creating output file: " << m_outpath << endmsg; - m_outfile = TFile::Open(m_outpath.c_str(),"recreate"); - - - // create a TTree to store the truth tracks - m_trackstree = new TTree("truthtracks","Truth tracks"); - // add the branch related to the truth tracks - m_trackstree->Branch("TruthTracks",&m_truth_tracks); - - - // create a TTree to store event information - m_evtinfo = new TTree("evtinfo","Events info"); - m_evtinfo->Branch("RunNumber",&m_run_number,"RunNumber/I"); - m_evtinfo->Branch("EventNumber",&m_event_number,"EventNumber/I"); - - m_evtinfo->Branch("LB",&m_LB,"LB/I"); - m_evtinfo->Branch("BCID",&m_BCID,"BCID/I"); - m_evtinfo->Branch("ExtendedLevel1ID",&m_extendedLevel1ID,"ExtendedLevel1ID/i"); - m_evtinfo->Branch("Level1TriggerType",&m_level1TriggerType,"Level1TriggerType/i"); - m_evtinfo->Branch("Level1TriggerInfo",&m_level1TriggerInfo); - m_evtinfo->Branch("AverageInteractionsPerCrossing",&m_averageInteractionsPerCrossing,"AverageInteractionsPerCrossing/F"); - m_evtinfo->Branch("ActualInteractionsPerCrossing",&m_actualInteractionsPerCrossing,"ActualInteractionsPerCrossing/F"); - - // create and populate the TTree - m_hittree = new TTree("ftkhits","Raw hits for the FTK simulation"); - m_hittree_perplane = new TTree("ftkhits_perplane","Raw hits for the FTK simulation"); - - - if (m_getOffline) { - offline_locX = new std::vector; - offline_locY = new std::vector; - offline_isPixel = new std::vector; - offline_isBarrel = new std::vector; - offline_layer = new std::vector; - offline_clustID = new std::vector; - offline_trackNumber = new std::vector; - offline_pt = new std::vector; - offline_eta = new std::vector; - offline_phi = new std::vector; - - m_offline_cluster_tree = new TTree("offline_cluster_tree","offline_cluster_tree"); - m_offline_cluster_tree->Branch("offline_locX",&offline_locX); - m_offline_cluster_tree->Branch("offline_locY",&offline_locY); - m_offline_cluster_tree->Branch("offline_is_Pixel",&offline_isPixel); - m_offline_cluster_tree->Branch("offline_is_Barrel",&offline_isBarrel); - m_offline_cluster_tree->Branch("offline_layer",&offline_layer); - m_offline_cluster_tree->Branch("offline_clustID",&offline_clustID); - - m_offline_cluster_tree->Branch("offline_trackNumber",&offline_trackNumber); - m_offline_cluster_tree->Branch("offline_pt",&offline_pt); - m_offline_cluster_tree->Branch("offline_eta",&offline_eta); - m_offline_cluster_tree->Branch("offline_phi",&offline_phi); - } - - - // prepare a branch for each tower - m_ntowers = m_rmap->getNumRegions(); - - if (m_SaveRawHits) { // Save FTKRawHit data - m_original_hits = new vector[m_ntowers]; - if (m_SavePerPlane) { m_original_hits_per_plane = new vector*[m_ntowers]; } - - for (int ireg=0;ireg!=m_ntowers;++ireg) { // towers loop - m_hittree->Branch(Form("RawHits%d.",ireg),&m_original_hits[ireg], 32000, 1); - - if (m_SavePerPlane) { - m_original_hits_per_plane[ireg] = new vector[m_nplanes]; - for (int iplane=0;iplane!=m_nplanes;++iplane) { // planes loop - m_hittree_perplane->Branch(Form("RawHits_t%d_p%d.",ireg,iplane),&m_original_hits_per_plane[ireg][iplane],32000, 1); + // Write clusters in InDetCluster format to ESD for use in Pseudotracking + if (m_WriteClustersToESD){ + StatusCode sc = service("StoreGateSvc", m_storeGate); + // Creating collection for pixel clusters + m_FTKPxlCluContainer = new InDet::PixelClusterContainer(m_pixelId->wafer_hash_max()); + m_FTKPxlCluContainer->addRef(); + sc = m_storeGate->record(m_FTKPxlCluContainer,m_FTKPxlClu_CollName); + if (sc.isFailure()) { + log << MSG::FATAL << "Error registering the FTK pixel container in the SG" << endmsg; + return StatusCode::FAILURE; } - } - } // end towers loop - } - - if (m_SaveHits) { - m_logical_hits = new vector[m_ntowers]; - if (m_SavePerPlane) { m_logical_hits_per_plane = new vector*[m_ntowers]; } - - for (int ireg=0;ireg!=m_ntowers;++ireg) { // towers loop - m_hittree->Branch(Form("Hits%d.",ireg),&m_logical_hits[ireg], 32000, 1); - - if (m_SavePerPlane) { - m_logical_hits_per_plane[ireg] = new vector[m_nplanes]; - for (int iplane=0;iplane!=m_nplanes;++iplane) { // planes loop - m_hittree_perplane->Branch(Form("Hits_t%d_p%d.",ireg,iplane), &m_logical_hits_per_plane[ireg][iplane],32000, 1); + + // Generic format link for the pixel clusters + const InDet::SiClusterContainer *symSiContainerPxl(0x0); + sc = m_storeGate->symLink(m_FTKPxlCluContainer,symSiContainerPxl); + if (sc.isFailure()) { + log << MSG::FATAL << "Error creating the sym-link to the Pixel clusters" << endmsg; + return StatusCode::FAILURE; } - } - } // end towers loop - } - return StatusCode::SUCCESS; -} -StatusCode FTKRegionalWrapper::execute() -{ + // Creating collection for the SCT clusters + m_FTKSCTCluContainer = new InDet::SCT_ClusterContainer(m_sctId->wafer_hash_max()); + m_FTKSCTCluContainer->addRef(); + sc = m_storeGate->record(m_FTKSCTCluContainer,m_FTKSCTClu_CollName); + if (sc.isFailure()) { + log << MSG::FATAL << "Error registering the FTK SCT container in the SG" << endmsg; + return StatusCode::FAILURE; + } + // Generic format link for the pixel clusters + const InDet::SiClusterContainer *symSiContainerSCT(0x0); + sc = m_storeGate->symLink(m_FTKSCTCluContainer,symSiContainerSCT); + if (sc.isFailure()) { + log << MSG::FATAL << "Error creating the sym-link to the SCT clusters" << endmsg; + return StatusCode::FAILURE; + } - // moved here for compatibilty with multithreaded athena - if (m_outfile == 0) { - StatusCode sc = initOutputFile(); - if(sc.isFailure()) { - ATH_MSG_WARNING("Did not initialize output file and trees correctly!"); - } - } - - // retrieve the pointer to the datainput object - FTKDataInput *datainput = m_hitInputTool->reference(); - - // reset the branches - for (int ireg=0;ireg!=m_ntowers;++ireg) { - if (m_SaveRawHits) m_original_hits[ireg].clear(); - if (m_SaveHits) m_logical_hits[ireg].clear(); - - if (m_SavePerPlane) { - for (int iplane=0;iplane!=m_nplanes;++iplane) { // planes loop - if (m_SaveRawHits) m_original_hits_per_plane[ireg][iplane].clear(); - if (m_SaveHits) m_logical_hits_per_plane[ireg][iplane].clear(); - } + // getting sct truth + if(!m_storeGate->contains(m_ftkSctTruthName)) { + m_ftkSctTruth = new PRD_MultiTruthCollection; + StatusCode sc=m_storeGate->record(m_ftkSctTruth,m_ftkSctTruthName); + if(sc.isFailure()) { + ATH_MSG_WARNING("SCT FTK Truth Container " << m_ftkSctTruthName + <<" cannot be recorded in StoreGate !"); + } + else { + ATH_MSG_DEBUG("SCT FTK Truth Container " << m_ftkSctTruthName + << " is recorded in StoreGate"); + } + } + //getting pixel truth + if(!m_storeGate->contains(m_ftkPixelTruthName)) { + m_ftkPixelTruth = new PRD_MultiTruthCollection; + StatusCode sc=m_storeGate->record(m_ftkPixelTruth,m_ftkPixelTruthName); + if(sc.isFailure()) { + ATH_MSG_WARNING("Pixel FTK Truth Container " << m_ftkPixelTruthName + <<" cannot be recorded in StoreGate !"); + } + else { + ATH_MSG_DEBUG("Pixel FTK Truth Container " << m_ftkPixelTruthName + << " is recorded in StoreGate"); + } + } } - } - - if (m_getOffline) { - offline_locX->clear(); - offline_locY->clear(); - offline_isPixel->clear(); - offline_isBarrel->clear(); - offline_layer->clear(); - offline_clustID->clear(); - offline_trackNumber->clear(); - offline_pt->clear(); - offline_eta->clear(); - offline_phi->clear(); - } - - // ask to read the data in the current event - datainput->readData(); - - // get the event information - m_run_number = datainput->runNumber(); // event's run number - m_event_number = datainput->eventNumber(); // event number - m_LB = datainput->LB(); - m_BCID = datainput->BCID(); - m_averageInteractionsPerCrossing = datainput->averageInteractionsPerCrossing(); - m_actualInteractionsPerCrossing = datainput->actualInteractionsPerCrossing(); - m_level1TriggerType = datainput->level1TriggerType(); - m_level1TriggerInfo = datainput->level1TriggerInfo(); - m_extendedLevel1ID = datainput->extendedLevel1ID(); - - if (std::find(m_L1ID_to_save.begin(), m_L1ID_to_save.end(), m_level1TriggerType) == m_L1ID_to_save.end() - && m_L1ID_to_save.size() != 0) - return StatusCode::SUCCESS; - m_evtinfo->Fill(); - // retrieve the original list of hits, the list is copied because the clustering will change it - vector fulllist; - bool dumpedSCT = false; + //Initialize the clustering engine + clusteringEngine = new FTKClusteringEngine(m_SaveClusterContent, + m_DiagClustering, + m_SctClustering, + m_Ibl3DRealistic, + m_DuplicateGanged, + m_GangedPatternRecognition, + false, //splitBlayerModule + m_PixelClusteringMode); + - //if DF emulation is requested then first check if hits are in DF Rods before doing clustering or writing to file - if(m_EmulateDF){ + //Dump to the log output the RODs used in the emulation + if(m_EmulateDF){ - //get list of original hits - vector templist = datainput->getOriginalHits(); + ATH_MSG_DEBUG("Printing full map via m_pix_cabling_svc->get_idMap_offrob(); "); + std::map< Identifier, uint32_t> offmap = m_pix_cabling_svc->get_idMap_offrob(); + for (auto mit = offmap.begin(); mit != offmap.end(); mit++){ + //uint id = mit->first; + ATH_MSG_DEBUG("Pixel offline map hashID to RobId "<first<<" "<second<getAllRods()"); + std::vector sctVector; + m_sct_cabling_svc->getAllRods(sctVector); + ATH_MSG_DEBUG("Printing full SCT map via m_sct_cabling_svc->getAllRods() "<getHashesForRod(m_identifierHashList,*mit ); + ATH_MSG_DEBUG("Retrieved "<::const_iterator ihit = templist.begin(); - vector::const_iterator ihitE = templist.end(); + m_pix_rodIdlist.clear(); + + for (auto it = m_spix_rodIdlist.begin(); it < m_spix_rodIdlist.end(); it++){ + std::stringstream str; + str<<(*it); + int val; + str>>std::hex>>val; + + m_pix_rodIdlist.push_back(val); + + ATH_MSG_DEBUG("Going to test against the following Pix RODIDs "<< MSG::hex + << val < offlineIdHashList; + m_pix_cabling_svc->getOfflineList(offlineIdHashList, m_pix_cabling_svc->getRobId(val)); + ATH_MSG_DEBUG("Trying m_pix_cabling_svc->getOfflineList(offlineIdHashList, m_pix_cabling_svc->getRobId("<wafer_id( *oit ); + int barrel_ec = m_pixelId->barrel_ec(id); + int layer_disk = m_pixelId->layer_disk(id); + int phi_module = m_pixelId->phi_module(id); + int eta_module = m_pixelId->eta_module(id); + + ATH_MSG_DEBUG("hashId "<<*oit<<"for rodID "<>std::hex>>val; + m_sct_rodIdlist.push_back(val); + + ATH_MSG_DEBUG("Going to test against the following SCT RODIDs "<< MSG::hex + << val <getRobIdFromHash(modHash); - - if (dumpedSCT == false){ - ATH_MSG_VERBOSE("Dumping SCT Rod List "); - for (auto its = m_sct_rodIdlist.begin(); its < m_sct_rodIdlist.end(); ++its) - ATH_MSG_VERBOSE(MSG::hex <<*its<wafer_id(modHash); - - //then get the corresponding RobId - uint32_t robid = m_pix_cabling_svc->getRobId(dehashedId); - - //then try to find in rob list - auto it = find(m_pix_rodIdlist.begin(), m_pix_rodIdlist.end(), robid); - - ATH_MSG_VERBOSE("Trying to find pixel "<< MSG::hex <getOriginalHits(); - } - - ATH_MSG_VERBOSE("Going to run on "<< fulllist.size()<<" hits"); - - // if the clustering is requested it has to be done before the hits are distributed - if (m_Clustering ) { - atlClusteringLNF(fulllist); - vector::iterator ihit = fulllist.begin(); - vector::iterator ihitE = fulllist.end(); - for (;ihit!=ihitE;++ihit) { // hit loop - FTKRawHit &currawhit = *ihit; - - // now we add truth info back in since we did clustering here! - MultiTruth mt; - if( currawhit.getTruth() ) { - mt.maximize( *(currawhit.getTruth())); - } else { - MultiTruth::Barcode uniquecode(currawhit.getEventIndex(), - currawhit.getBarcode()); - mt.maximize(uniquecode,currawhit.getBarcodePt()); - } - MultiTruth::Barcode tbarcode; - MultiTruth::Weight tfrac; - const bool ok = mt.best(tbarcode,tfrac); - Int_t index(-1), barcode(0); - if( ok ) { - index = tbarcode.first; - barcode = tbarcode.second; - } - currawhit.setEventIndex(index); - currawhit.setBarcode(barcode); } - } - if (m_getOffline) { - const xAOD::TrackParticleContainer *offlineTracks = nullptr; - if(m_storeGate->retrieve(offlineTracks,m_offlineName).isFailure()) { - ATH_MSG_ERROR("Failed to retrieve Offline Tracks " << m_offlineName); - return StatusCode::FAILURE; + + return StatusCode::SUCCESS; +} + +StatusCode FTKRegionalWrapper::initOutputFile() { + /* + * prepare the output structure to store the hits and the other information + */ + + MsgStream log(msgSvc(), name()); + log << MSG::INFO << "FTKRegionalWrapper::initOutputFile()" << endmsg; + + + // create the output files + log << MSG::INFO << "Creating output file: " << m_outpath << endmsg; + m_outfile = TFile::Open(m_outpath.c_str(),"recreate"); + + + // create a TTree to store the truth tracks + m_trackstree = new TTree("truthtracks","Truth tracks"); + // add the branch related to the truth tracks + m_trackstree->Branch("TruthTracks",&m_truth_tracks); + + + // create a TTree to store event information + m_evtinfo = new TTree("evtinfo","Events info"); + m_evtinfo->Branch("RunNumber",&m_run_number,"RunNumber/I"); + m_evtinfo->Branch("EventNumber",&m_event_number,"EventNumber/I"); + + m_evtinfo->Branch("LB",&m_LB,"LB/I"); + m_evtinfo->Branch("BCID",&m_BCID,"BCID/I"); + m_evtinfo->Branch("ExtendedLevel1ID",&m_extendedLevel1ID,"ExtendedLevel1ID/i"); + m_evtinfo->Branch("Level1TriggerType",&m_level1TriggerType,"Level1TriggerType/i"); + m_evtinfo->Branch("Level1TriggerInfo",&m_level1TriggerInfo); + m_evtinfo->Branch("AverageInteractionsPerCrossing",&m_averageInteractionsPerCrossing,"AverageInteractionsPerCrossing/F"); + m_evtinfo->Branch("ActualInteractionsPerCrossing",&m_actualInteractionsPerCrossing,"ActualInteractionsPerCrossing/F"); + + // create and populate the TTree + m_hittree = new TTree("ftkhits","Raw hits for the FTK simulation"); + m_hittree_perplane = new TTree("ftkhits_perplane","Raw hits for the FTK simulation"); + + + if (m_getOffline) { + offline_locX = new std::vector; + offline_locY = new std::vector; + offline_isPixel = new std::vector; + offline_isBarrel = new std::vector; + offline_layer = new std::vector; + offline_clustID = new std::vector; + offline_trackNumber = new std::vector; + offline_pt = new std::vector; + offline_eta = new std::vector; + offline_phi = new std::vector; + + m_offline_cluster_tree = new TTree("offline_cluster_tree","offline_cluster_tree"); + m_offline_cluster_tree->Branch("offline_locX",&offline_locX); + m_offline_cluster_tree->Branch("offline_locY",&offline_locY); + m_offline_cluster_tree->Branch("offline_is_Pixel",&offline_isPixel); + m_offline_cluster_tree->Branch("offline_is_Barrel",&offline_isBarrel); + m_offline_cluster_tree->Branch("offline_layer",&offline_layer); + m_offline_cluster_tree->Branch("offline_clustID",&offline_clustID); + + m_offline_cluster_tree->Branch("offline_trackNumber",&offline_trackNumber); + m_offline_cluster_tree->Branch("offline_pt",&offline_pt); + m_offline_cluster_tree->Branch("offline_eta",&offline_eta); + m_offline_cluster_tree->Branch("offline_phi",&offline_phi); } - if(offlineTracks->size()!=0){ - auto track_it = offlineTracks->begin(); - auto last_track = offlineTracks->end(); - for (int iTrk=0 ; track_it!= last_track; track_it++, iTrk++){ - auto track = (*track_it)->track(); - offline_pt->push_back((*track_it)->pt()*(*track_it)->charge()); - offline_eta->push_back((*track_it)->eta()); - offline_phi->push_back((*track_it)->phi()); - const DataVector* trackStates=track->trackStateOnSurfaces(); - if(!trackStates) ATH_MSG_ERROR("trackStatesOnSurface troubles"); - DataVector::const_iterator it=trackStates->begin(); - DataVector::const_iterator it_end=trackStates->end(); - if (!(*it)) { - ATH_MSG_WARNING("TrackStateOnSurface == Null" << endl); - continue; - } - for (; it!=it_end; it++) { - const Trk::TrackStateOnSurface* tsos=(*it); - if (tsos == 0) continue; - if ((*it)->type(Trk::TrackStateOnSurface::Measurement) ){ - const Trk::MeasurementBase *measurement = (*it)->measurementOnTrack(); - if( (*it)->trackParameters() !=0 && - (*it)->trackParameters()->associatedSurface().associatedDetectorElement() != nullptr && - (*it)->trackParameters()->associatedSurface().associatedDetectorElement()->identify() !=0 - ){ - const Trk::RIO_OnTrack* hit = dynamic_cast (measurement); - const Identifier & hitId = hit->identify(); - - if (m_idHelper->is_pixel(hitId)) { - offline_isPixel->push_back(true); - offline_isBarrel->push_back(m_pixelId->is_barrel(hitId)); - const InDetDD::SiDetectorElement* sielement = m_PIX_mgr->getDetectorElement(hitId); - offline_clustID->push_back(sielement->identifyHash()); - offline_trackNumber->push_back(iTrk); - offline_layer->push_back(m_pixelId->layer_disk(hitId)); - offline_locX->push_back((float)measurement->localParameters()[Trk::locX]); - offline_locY->push_back((float)measurement->localParameters()[Trk::locY]); - } - else if (m_idHelper->is_sct(hitId)) { - offline_isPixel->push_back(false); - offline_isBarrel->push_back(m_sctId->is_barrel(hitId)); - const InDetDD::SiDetectorElement* sielement = m_SCT_mgr->getDetectorElement(hitId); - offline_clustID->push_back(sielement->identifyHash()); - offline_trackNumber->push_back(iTrk); - offline_layer->push_back(m_sctId->layer_disk(hitId)); - offline_locX->push_back((float)measurement->localParameters()[Trk::locX]); - offline_locY->push_back(-99999.9); - } - } - } - } - } + + + // prepare a branch for each tower + m_ntowers = m_rmap->getNumRegions(); + + if (m_SaveRawHits) { // Save FTKRawHit data + m_original_hits = new vector[m_ntowers]; + if (m_SavePerPlane) { m_original_hits_per_plane = new vector*[m_ntowers]; } + + for (int ireg=0;ireg!=m_ntowers;++ireg) { // towers loop + m_hittree->Branch(Form("RawHits%d.",ireg),&m_original_hits[ireg], 32000, 1); + + if (m_SavePerPlane) { + m_original_hits_per_plane[ireg] = new vector[m_nplanes]; + for (int iplane=0;iplane!=m_nplanes;++iplane) { // planes loop + m_hittree_perplane->Branch(Form("RawHits_t%d_p%d.",ireg,iplane),&m_original_hits_per_plane[ireg][iplane],32000, 1); + } + } + } // end towers loop } - } - - //get all the containers to write clusters - if(m_WriteClustersToESD){ - if(!m_storeGate->contains(m_ftkSctTruthName)) { - m_ftkSctTruth = new PRD_MultiTruthCollection; - - StatusCode sc=m_storeGate->record(m_ftkSctTruth,m_ftkSctTruthName,false); - if(sc.isFailure()) { - ATH_MSG_WARNING("SCT FTK Truth Container " << m_ftkSctTruthName - <<" cannot be re-recorded in StoreGate !"); - } - } - - if(!m_storeGate->contains(m_ftkPixelTruthName)) { - m_ftkPixelTruth = new PRD_MultiTruthCollection; - - StatusCode sc=m_storeGate->record(m_ftkPixelTruth,m_ftkPixelTruthName,false); - if(sc.isFailure()) { - ATH_MSG_WARNING("SCT FTK Truth Container " << m_ftkPixelTruthName - <<" cannot be re-recorded in StoreGate !"); - } - } - - - // Check the FTK pixel container - if (!m_storeGate->contains(m_FTKPxlClu_CollName)) { - m_FTKPxlCluContainer->cleanup(); - if (m_storeGate->record(m_FTKPxlCluContainer,m_FTKPxlClu_CollName,false).isFailure()) { - return StatusCode::FAILURE; - } + + if (m_SaveHits) { + m_logical_hits = new vector[m_ntowers]; + if (m_SavePerPlane) { m_logical_hits_per_plane = new vector*[m_ntowers]; } + + for (int ireg=0;ireg!=m_ntowers;++ireg) { // towers loop + m_hittree->Branch(Form("Hits%d.",ireg),&m_logical_hits[ireg], 32000, 1); + + if (m_SavePerPlane) { + m_logical_hits_per_plane[ireg] = new vector[m_nplanes]; + for (int iplane=0;iplane!=m_nplanes;++iplane) { // planes loop + m_hittree_perplane->Branch(Form("Hits_t%d_p%d.",ireg,iplane), &m_logical_hits_per_plane[ireg][iplane],32000, 1); + } + } + } // end towers loop } - - // check the FTK SCT container - if (!m_storeGate->contains(m_FTKSCTClu_CollName)) { - m_FTKSCTCluContainer->cleanup(); - if (m_storeGate->record(m_FTKSCTCluContainer,m_FTKSCTClu_CollName,false).isFailure()) { - return StatusCode::FAILURE; - } + return StatusCode::SUCCESS; +} + +StatusCode FTKRegionalWrapper::execute() +{ + + // moved here for compatibilty with multithreaded athena + if (m_outfile == 0) { + StatusCode sc = initOutputFile(); + if(sc.isFailure()) { + ATH_MSG_WARNING("Did not initialize output file and trees correctly!"); + } } - } + // retrieve the pointer to the datainput object + FTKDataInput *datainput = m_hitInputTool->reference(); + // reset the branches + for (int ireg=0;ireg!=m_ntowers;++ireg) { + if (m_SaveRawHits) m_original_hits[ireg].clear(); + if (m_SaveHits) m_logical_hits[ireg].clear(); + if (m_SavePerPlane) { + for (int iplane=0;iplane!=m_nplanes;++iplane) { // planes loop + if (m_SaveRawHits) m_original_hits_per_plane[ireg][iplane].clear(); + if (m_SaveHits) m_logical_hits_per_plane[ireg][iplane].clear(); + } + } + } - // prepare to iterate on the input files - vector::const_iterator ihit = fulllist.begin(); - vector::const_iterator ihitE = fulllist.end(); + if (m_getOffline) { + offline_locX->clear(); + offline_locY->clear(); + offline_isPixel->clear(); + offline_isBarrel->clear(); + offline_layer->clear(); + offline_clustID->clear(); + offline_trackNumber->clear(); + offline_pt->clear(); + offline_eta->clear(); + offline_phi->clear(); + } - for (;ihit!=ihitE;++ihit) { // hit loop - const FTKRawHit &currawhit = *ihit; + // ask to read the data in the current event + datainput->readData(); + + // get the event information + m_run_number = datainput->runNumber(); // event's run number + m_event_number = datainput->eventNumber(); // event number + m_LB = datainput->LB(); + m_BCID = datainput->BCID(); + m_averageInteractionsPerCrossing = datainput->averageInteractionsPerCrossing(); + m_actualInteractionsPerCrossing = datainput->actualInteractionsPerCrossing(); + m_level1TriggerType = datainput->level1TriggerType(); + m_level1TriggerInfo = datainput->level1TriggerInfo(); + m_extendedLevel1ID = datainput->extendedLevel1ID(); + + if (std::find(m_L1ID_to_save.begin(), m_L1ID_to_save.end(), m_level1TriggerType) == m_L1ID_to_save.end() + && m_L1ID_to_save.size() != 0) + return StatusCode::SUCCESS; + + m_evtinfo->Fill(); + // retrieve the original list of hits, the list is copied because the clustering will change it + vector fulllist; + + bool dumpedSCT = false; + + //if DF emulation is requested then first check if hits are in DF Rods before doing clustering or writing to file + if(m_EmulateDF){ + + //get list of original hits + vector templist = datainput->getOriginalHits(); + + vector::const_iterator ihit = templist.begin(); + vector::const_iterator ihitE = templist.end(); + + for (;ihit!=ihitE;++ihit) { // hit loop + const FTKRawHit &currawhit = *ihit; + + //first get the hit's Module identifier hash + uint32_t modHash = currawhit.getIdentifierHash(); + + + if (currawhit.getIsSCT()){ + + ATH_MSG_VERBOSE("Processing SCT hit"); + //SCT + + //then get the corresponding RobId + uint32_t robid = m_sct_cabling_svc->getRobIdFromHash(modHash); + + if (dumpedSCT == false){ + ATH_MSG_VERBOSE("Dumping SCT Rod List "); + for (auto its = m_sct_rodIdlist.begin(); its < m_sct_rodIdlist.end(); ++its) + ATH_MSG_VERBOSE(MSG::hex <<*its<wafer_id(modHash); + + //then get the corresponding RobId + uint32_t robid = m_pix_cabling_svc->getRobId(dehashedId); + + //then try to find in rob list + auto it = find(m_pix_rodIdlist.begin(), m_pix_rodIdlist.end(), robid); + + ATH_MSG_VERBOSE("Trying to find pixel "<< MSG::hex <getOriginalHits(); + } - if( m_ITkMode ) { - // In the ITk geometry, some of the plane IDs are -1 if the layers are not yet being used. - // This causes the code in this hit loop to crash. As a workaround for the moment, we currently - // skip over hits in layers that are not included in the FTK geometry, with plane = -1 - if( m_pmap->getMap( currawhit.getHitType() , !(currawhit.getBarrelEC()==0) , currawhit.getLayer() ).getPlane() == -1 ) - continue; + ATH_MSG_VERBOSE("Going to run on "<< fulllist.size()<<" hits"); + + // if the clustering is requested it has to be done before the hits are distributed + if (m_Clustering ) { + clusteringEngine->atlClusteringLNF(fulllist); + vector::iterator ihit = fulllist.begin(); + vector::iterator ihitE = fulllist.end(); + for (;ihit!=ihitE;++ihit) { // hit loop + FTKRawHit &currawhit = *ihit; + + // now we add truth info back in since we did clustering here! + MultiTruth mt; + if( currawhit.getTruth() ) { + mt.maximize( *(currawhit.getTruth())); + } else { + MultiTruth::Barcode uniquecode(currawhit.getEventIndex(), + currawhit.getBarcode()); + mt.maximize(uniquecode,currawhit.getBarcodePt()); + } + MultiTruth::Barcode tbarcode; + MultiTruth::Weight tfrac; + const bool ok = mt.best(tbarcode,tfrac); + Int_t index(-1), barcode(0); + if( ok ) { + index = tbarcode.first; + barcode = tbarcode.second; + } + currawhit.setEventIndex(index); + currawhit.setBarcode(barcode); + } } - - //cout << "Hit " << currawhit.getHitType() << ": " << currawhit.getEventIndex() << " " << currawhit.getBarcode() << endl; - // calculate the equivalent hit - FTKHit hitref = currawhit.getFTKHit(m_pmap); - if (m_Clustering ) { - assert(currawhit.getTruth()); - hitref.setTruth(*(currawhit.getTruth())); + + if (m_getOffline) { + const xAOD::TrackParticleContainer *offlineTracks = nullptr; + if(m_storeGate->retrieve(offlineTracks,m_offlineName).isFailure()) { + ATH_MSG_ERROR("Failed to retrieve Offline Tracks " << m_offlineName); + return StatusCode::FAILURE; + } + if(offlineTracks->size()!=0){ + auto track_it = offlineTracks->begin(); + auto last_track = offlineTracks->end(); + for (int iTrk=0 ; track_it!= last_track; track_it++, iTrk++){ + auto track = (*track_it)->track(); + offline_pt->push_back((*track_it)->pt()*(*track_it)->charge()); + offline_eta->push_back((*track_it)->eta()); + offline_phi->push_back((*track_it)->phi()); + const DataVector* trackStates=track->trackStateOnSurfaces(); + if(!trackStates) ATH_MSG_ERROR("trackStatesOnSurface troubles"); + DataVector::const_iterator it=trackStates->begin(); + DataVector::const_iterator it_end=trackStates->end(); + if (!(*it)) { + ATH_MSG_WARNING("TrackStateOnSurface == Null" << endl); + continue; + } + for (; it!=it_end; it++) { + const Trk::TrackStateOnSurface* tsos=(*it); + if (tsos == 0) continue; + if ((*it)->type(Trk::TrackStateOnSurface::Measurement) ){ + const Trk::MeasurementBase *measurement = (*it)->measurementOnTrack(); + if( (*it)->trackParameters() !=0 && + (*it)->trackParameters()->associatedSurface().associatedDetectorElement() != nullptr && + (*it)->trackParameters()->associatedSurface().associatedDetectorElement()->identify() !=0 + ){ + const Trk::RIO_OnTrack* hit = dynamic_cast (measurement); + const Identifier & hitId = hit->identify(); + + if (m_idHelper->is_pixel(hitId)) { + offline_isPixel->push_back(true); + offline_isBarrel->push_back(m_pixelId->is_barrel(hitId)); + const InDetDD::SiDetectorElement* sielement = m_PIX_mgr->getDetectorElement(hitId); + offline_clustID->push_back(sielement->identifyHash()); + offline_trackNumber->push_back(iTrk); + offline_layer->push_back(m_pixelId->layer_disk(hitId)); + offline_locX->push_back((float)measurement->localParameters()[Trk::locX]); + offline_locY->push_back((float)measurement->localParameters()[Trk::locY]); + } + else if (m_idHelper->is_sct(hitId)) { + offline_isPixel->push_back(false); + offline_isBarrel->push_back(m_sctId->is_barrel(hitId)); + const InDetDD::SiDetectorElement* sielement = m_SCT_mgr->getDetectorElement(hitId); + offline_clustID->push_back(sielement->identifyHash()); + offline_trackNumber->push_back(iTrk); + offline_layer->push_back(m_sctId->layer_disk(hitId)); + offline_locX->push_back((float)measurement->localParameters()[Trk::locX]); + offline_locY->push_back(-99999.9); + } + } + } + } + } + } } - + + //get all the containers to write clusters if(m_WriteClustersToESD){ - int dim = hitref.getDim(); - switch (dim) { - case 0: { - //missing hit - just ignore this for the time being - } - break; - case 1: { - InDet::SCT_Cluster* pSctCL = m_clusterConverterTool->createSCT_Cluster(hitref.getIdentifierHash(), hitref.getCoord(0), hitref.getNStrips() ); //createSCT_Cluster(h); - - if(pSctCL!=NULL) { - InDet::SCT_ClusterCollection* pColl = m_clusterConverterTool->getCollection(m_FTKSCTCluContainer, hitref.getIdentifierHash()); - if(pColl!=NULL) { - pSctCL->setHashAndIndex(pColl->identifyHash(), pColl->size()); - pColl->push_back(pSctCL); - const MultiTruth& t = hitref.getTruth(); - m_clusterConverterTool->createSCT_Truth(pSctCL->identify(), t, m_ftkSctTruth, m_mcEventCollection, m_storeGate, m_mcTruthName); - } - } - } - break; - case 2: { - InDet::PixelCluster* pPixCL = m_clusterConverterTool->createPixelCluster(hitref.getIdentifierHash(), hitref.getCoord(0), hitref.getCoord(1), hitref.getEtaWidth(), hitref.getPhiWidth(), hitref.getCoord(1)); //need to fix trkPerigee->eta()); - - if(pPixCL!=NULL) { - InDet::PixelClusterCollection* pColl = m_clusterConverterTool->getCollection(m_FTKPxlCluContainer, hitref.getIdentifierHash()); - if(pColl!=NULL) { - pPixCL->setHashAndIndex(pColl->identifyHash(), pColl->size()); - pColl->push_back(pPixCL); - const MultiTruth& t = hitref.getTruth(); - m_clusterConverterTool->createPixelTruth(pPixCL->identify(), t, m_ftkPixelTruth, m_mcEventCollection, m_storeGate, m_mcTruthName); - } - } - } - break; - } + if(!m_storeGate->contains(m_ftkSctTruthName)) { + m_ftkSctTruth = new PRD_MultiTruthCollection; + + StatusCode sc=m_storeGate->record(m_ftkSctTruth,m_ftkSctTruthName,false); + if(sc.isFailure()) { + ATH_MSG_WARNING("SCT FTK Truth Container " << m_ftkSctTruthName + <<" cannot be re-recorded in StoreGate !"); + } + } + + if(!m_storeGate->contains(m_ftkPixelTruthName)) { + m_ftkPixelTruth = new PRD_MultiTruthCollection; + + StatusCode sc=m_storeGate->record(m_ftkPixelTruth,m_ftkPixelTruthName,false); + if(sc.isFailure()) { + ATH_MSG_WARNING("SCT FTK Truth Container " << m_ftkPixelTruthName + <<" cannot be re-recorded in StoreGate !"); + } + } + + + // Check the FTK pixel container + if (!m_storeGate->contains(m_FTKPxlClu_CollName)) { + m_FTKPxlCluContainer->cleanup(); + if (m_storeGate->record(m_FTKPxlCluContainer,m_FTKPxlClu_CollName,false).isFailure()) { + return StatusCode::FAILURE; + } + } + + // check the FTK SCT container + if (!m_storeGate->contains(m_FTKSCTClu_CollName)) { + m_FTKSCTCluContainer->cleanup(); + if (m_storeGate->record(m_FTKSCTCluContainer,m_FTKSCTClu_CollName,false).isFailure()) { + return StatusCode::FAILURE; + } + } } - // get plane id - const int plane = hitref.getPlane(); - - // check the region - for (int ireg=0;ireg!=m_ntowers;++ireg) { - - if (m_rmap->isHitInRegion(hitref,ireg)) { - // if the equivalent hit is compatible with this tower the hit is saved - if (m_SaveRawHits) m_original_hits[ireg].push_back(currawhit); - if (m_SaveHits) m_logical_hits[ireg].push_back(hitref); - if (m_SavePerPlane) { - if (m_SaveRawHits) - m_original_hits_per_plane[ireg][plane].push_back(currawhit); - if (m_SaveHits) - m_logical_hits_per_plane[ireg][plane].push_back(hitref); - } - } + + // prepare to iterate on the input files + vector::const_iterator ihit = fulllist.begin(); + vector::const_iterator ihitE = fulllist.end(); + + for (;ihit!=ihitE;++ihit) { // hit loop + const FTKRawHit &currawhit = *ihit; + + if( m_ITkMode ) { + // In the ITk geometry, some of the plane IDs are -1 if the layers are not yet being used. + // This causes the code in this hit loop to crash. As a workaround for the moment, we currently + // skip over hits in layers that are not included in the FTK geometry, with plane = -1 + if( m_pmap->getMap( currawhit.getHitType() , !(currawhit.getBarrelEC()==0) , currawhit.getLayer() ).getPlane() == -1 ) + continue; + } + + //cout << "Hit " << currawhit.getHitType() << ": " << currawhit.getEventIndex() << " " << currawhit.getBarcode() << endl; + // calculate the equivalent hit + FTKHit hitref = currawhit.getFTKHit(m_pmap); + if (m_Clustering ) { + assert(currawhit.getTruth()); + hitref.setTruth(*(currawhit.getTruth())); + } + + if(m_WriteClustersToESD){ + int dim = hitref.getDim(); + switch (dim) { + case 0: { + //missing hit - just ignore this for the time being + } + break; + case 1: { + InDet::SCT_Cluster* pSctCL = m_clusterConverterTool->createSCT_Cluster(hitref.getIdentifierHash(), hitref.getCoord(0), hitref.getNStrips() ); //createSCT_Cluster(h); + + if(pSctCL!=NULL) { + InDet::SCT_ClusterCollection* pColl = m_clusterConverterTool->getCollection(m_FTKSCTCluContainer, hitref.getIdentifierHash()); + if(pColl!=NULL) { + pSctCL->setHashAndIndex(pColl->identifyHash(), pColl->size()); + pColl->push_back(pSctCL); + const MultiTruth& t = hitref.getTruth(); + m_clusterConverterTool->createSCT_Truth(pSctCL->identify(), t, m_ftkSctTruth, m_mcEventCollection, m_storeGate, m_mcTruthName); + } + } + } + break; + case 2: { + InDet::PixelCluster* pPixCL = m_clusterConverterTool->createPixelCluster(hitref.getIdentifierHash(), hitref.getCoord(0), hitref.getCoord(1), hitref.getEtaWidth(), hitref.getPhiWidth(), hitref.getCoord(1)); //need to fix trkPerigee->eta()); + + if(pPixCL!=NULL) { + InDet::PixelClusterCollection* pColl = m_clusterConverterTool->getCollection(m_FTKPxlCluContainer, hitref.getIdentifierHash()); + if(pColl!=NULL) { + pPixCL->setHashAndIndex(pColl->identifyHash(), pColl->size()); + pColl->push_back(pPixCL); + const MultiTruth& t = hitref.getTruth(); + m_clusterConverterTool->createPixelTruth(pPixCL->identify(), t, m_ftkPixelTruth, m_mcEventCollection, m_storeGate, m_mcTruthName); + } + } + } + break; + } + } + + + // get plane id + const int plane = hitref.getPlane(); + + // check the region + for (int ireg=0;ireg!=m_ntowers;++ireg) { + + if (m_rmap->isHitInRegion(hitref,ireg)) { + // if the equivalent hit is compatible with this tower the hit is saved + if (m_SaveRawHits) m_original_hits[ireg].push_back(currawhit); + if (m_SaveHits) m_logical_hits[ireg].push_back(hitref); + + if (m_SavePerPlane) { + if (m_SaveRawHits) + m_original_hits_per_plane[ireg][plane].push_back(currawhit); + if (m_SaveHits) + m_logical_hits_per_plane[ireg][plane].push_back(hitref); + } + } + } + } // end hit loop + + + // fill the branches + m_hittree->Fill(); + + if (m_getOffline) m_offline_cluster_tree->Fill(); + + if (m_SavePerPlane) { m_hittree_perplane->Fill(); } + + // get the list of the truth tracks + m_truth_tracks.clear(); + const vector &truthtracks = datainput->getTruthTrack(); + m_truth_tracks.insert(m_truth_tracks.end(),truthtracks.begin(),truthtracks.end()); + // Write the tracks + m_trackstree->Fill(); + if (m_DumpTestVectors) { + // Dumps the data, needed to be placed here in order to make sure that StoreGateSvc has loaded + dumpFTKTestVectors(m_pmap,m_rmap); } - } // end hit loop - - - // fill the branches - m_hittree->Fill(); - - if (m_getOffline) m_offline_cluster_tree->Fill(); - - if (m_SavePerPlane) { m_hittree_perplane->Fill(); } - - // get the list of the truth tracks - m_truth_tracks.clear(); - const vector &truthtracks = datainput->getTruthTrack(); - m_truth_tracks.insert(m_truth_tracks.end(),truthtracks.begin(),truthtracks.end()); - // Write the tracks - m_trackstree->Fill(); - if (m_DumpTestVectors) { - // Dumps the data, needed to be placed here in order to make sure that StoreGateSvc has loaded - dumpFTKTestVectors(m_pmap,m_rmap); - } - - return StatusCode::SUCCESS; + + return StatusCode::SUCCESS; } //-------------------------------------------------------------------------------------------------------------------------- @@ -935,120 +936,120 @@ StatusCode FTKRegionalWrapper::execute() bool FTKRegionalWrapper::dumpFTKTestVectors(FTKPlaneMap *pmap, FTKRegionMap *rmap) { - MsgStream log(msgSvc(), name()); + MsgStream log(msgSvc(), name()); - // Some dummy loop variables + // Some dummy loop variables uint64_t onlineId ; IdentifierHash hashId; Identifier id; - stringstream ss ; + stringstream ss ; int m_hitTyp; //------------------------ Do PIXEL RODIDs first ------------------------------ // Note PIXEL RODs are input vector::iterator m_rodit = m_pix_rodIdlist.begin(); vector::iterator m_rodit_e = m_pix_rodIdlist.end(); m_hitTyp = 1; // pixel - + for (; m_rodit!=m_rodit_e; m_rodit++){ - // Create file for output, format: LUT_0xABCDFGH.txt - ss << "LUT_"; - ss.setf(ios::showbase); - ss << hex << *m_rodit; - ss.unsetf(ios::showbase); - ss << ".txt"; - ofstream myfile(ss.str() ); - myfile.setf(ios::right | ios::showbase); - - if ( myfile.is_open() ) { - for (int m_link = 0; m_link < 128;m_link++){ // Loop over all modules - // Retrieve onlineId = m_link+ROD - onlineId = m_pix_cabling_svc->getOnlineIdFromRobId((*m_rodit),m_link) ; - hashId = m_pix_cabling_svc->getOfflineIdHash(onlineId); - - if (hashId <=999999){ // Adjust for correct output format incase of invalid hashId // TODO: add a proper cutoff! - - id = m_pixelId->wafer_id( hashId ); - int barrel_ec = m_pixelId->barrel_ec(id); - int layer_disk = m_pixelId->layer_disk(id); - int phi_module = m_pixelId->phi_module(id); - int eta_module = m_pixelId->eta_module(id); - int eta_module_min = m_pixelId->eta_module_min(id); - int eta_module_max = m_pixelId->eta_module_max(id); - int eta_index = m_pixelId->eta_index(id); - int eta_index_max = m_pixelId->eta_index_max(id); - - // Get Plane information - FTKPlaneSection &pinfo = pmap->getMap(m_hitTyp,!(barrel_ec==0),layer_disk); - - // Get tower information - FTKRawHit dummy; - - dummy.setBarrelEC(barrel_ec); - dummy.setLayer(layer_disk); - dummy.setPhiModule(phi_module); - dummy.setEtaModule(eta_module); - - stringstream towerList; - FTKHit hitref = dummy.getFTKHit(pmap); - int nTowers = 0; - int towerId; - for (towerId = 0; towerId<64;towerId++){ // Loop over all 64 eta-phi towers - if (rmap->isHitInRegion(hitref,towerId)){ - towerList << towerId << ", "; - nTowers++; - } - } - - - // Dump data to file: - // Comment out lines below to adjust output ( - // Linknumber | OnlineID | HashID | Plane | #Towers| TowerList| - myfile << dec << setprecision(4) << m_link << '\t' - << hex << onlineId << '\t' - << dec << hashId << '\t' - << dec << pinfo.getPlane() << '\t' - << dec << nTowers << '\t'; - - - // Dump TowerList - myfile.unsetf(ios::right | ios::showbase); - myfile << setw(20) << towerList.str() << '\t'; - towerList.str( string() ) ; - - myfile.setf(ios::right | ios::showbase); - - // Dump the extend table - myfile << "#" << '\t' - << m_hitTyp << '\t' - << barrel_ec << '\t' - << layer_disk << '\t' - << phi_module << '\t' - << eta_module << '\t' - << eta_module_min << '\t' - << eta_module_max << '\t' - << eta_index << '\t' - << eta_index_max << '\t' - << endl; - - } - else{ - myfile << '\t' << '\t' << '\t' <getOnlineIdFromRobId((*m_rodit),m_link) ; + hashId = m_pix_cabling_svc->getOfflineIdHash(onlineId); + + if (hashId <=999999){ // Adjust for correct output format incase of invalid hashId // TODO: add a proper cutoff! + + id = m_pixelId->wafer_id( hashId ); + int barrel_ec = m_pixelId->barrel_ec(id); + int layer_disk = m_pixelId->layer_disk(id); + int phi_module = m_pixelId->phi_module(id); + int eta_module = m_pixelId->eta_module(id); + int eta_module_min = m_pixelId->eta_module_min(id); + int eta_module_max = m_pixelId->eta_module_max(id); + int eta_index = m_pixelId->eta_index(id); + int eta_index_max = m_pixelId->eta_index_max(id); + + // Get Plane information + FTKPlaneSection &pinfo = pmap->getMap(m_hitTyp,!(barrel_ec==0),layer_disk); + + // Get tower information + FTKRawHit dummy; + + dummy.setBarrelEC(barrel_ec); + dummy.setLayer(layer_disk); + dummy.setPhiModule(phi_module); + dummy.setEtaModule(eta_module); + + stringstream towerList; + FTKHit hitref = dummy.getFTKHit(pmap); + int nTowers = 0; + int towerId; + for (towerId = 0; towerId<64;towerId++){ // Loop over all 64 eta-phi towers + if (rmap->isHitInRegion(hitref,towerId)){ + towerList << towerId << ", "; + nTowers++; + } + } + + + // Dump data to file: + // Comment out lines below to adjust output ( + // Linknumber | OnlineID | HashID | Plane | #Towers| TowerList| + myfile << dec << setprecision(4) << m_link << '\t' + << hex << onlineId << '\t' + << dec << hashId << '\t' + << dec << pinfo.getPlane() << '\t' + << dec << nTowers << '\t'; + + + // Dump TowerList + myfile.unsetf(ios::right | ios::showbase); + myfile << setw(20) << towerList.str() << '\t'; + towerList.str( string() ) ; + + myfile.setf(ios::right | ios::showbase); + + // Dump the extend table + myfile << "#" << '\t' + << m_hitTyp << '\t' + << barrel_ec << '\t' + << layer_disk << '\t' + << phi_module << '\t' + << eta_module << '\t' + << eta_module_min << '\t' + << eta_module_max << '\t' + << eta_index << '\t' + << eta_index_max << '\t' + << endl; + + } + else{ + myfile << '\t' << '\t' << '\t' < sctrods; @@ -1058,112 +1059,112 @@ bool FTKRegionalWrapper::dumpFTKTestVectors(FTKPlaneMap *pmap, FTKRegionMap *rma id = 0; for (; rodit != rodit_e ; rodit++){ - // Create file for output, format: LUT_0xABCDFGH.txt - ss << "LUT_"; - ss.setf(ios::showbase); - ss << hex << *rodit; - ss.unsetf(ios::showbase); - ss << ".txt"; - ofstream myfile(ss.str() ); - myfile.setf( ios::right | ios::showbase); - - if (myfile.is_open() ) { - - // Retrive hashlist - m_sct_cabling_svc->getHashesForRod(m_identifierHashList,*rodit ); - - // Some dumping variables - vector::const_iterator hashit = m_identifierHashList.begin(); - vector::const_iterator hashit_e = m_identifierHashList.end(); - SCT_OnlineId m_sct_onlineId; - - for (; hashit != hashit_e; ++hashit){ // TODO: Check for invalid onlineId && hashId numbers (?) - - // Retrieve OnlineId - m_sct_onlineId = m_sct_cabling_svc->getOnlineIdFromHash( *hashit ); - if (m_sct_onlineId.rod() == (*rodit)){ // Check for correct rodId - - myfile.setf(ios::right | ios::showbase); - id = m_sctId->wafer_id( *hashit); - - int barrel_ec = m_sctId->barrel_ec(id); - int layer_disk = m_sctId->layer_disk(id); - int phi_module = m_sctId->phi_module(id); - int phi_module_max = m_sctId->phi_module_max(id); - int eta_module = m_sctId->eta_module(id) ; - int eta_module_min = m_sctId->eta_module_min(id) ; - int eta_module_max = m_sctId->eta_module_max(id) ; - int side = m_sctId->side(id); - int strip = m_sctId->strip(id); - - // Get plane information - FTKPlaneSection &pinfo = pmap->getMap(m_hitTyp,!(barrel_ec==0),layer_disk); - - // Get tower information - FTKRawHit dummy; - dummy.setBarrelEC(barrel_ec); - dummy.setLayer(layer_disk); - dummy.setPhiModule(phi_module); - dummy.setEtaModule(eta_module); - - stringstream towerList; - int towerId; - int nTowers = 0; - FTKHit hitref = dummy.getFTKHit(pmap); - for (towerId = 0; towerId<64;towerId++){ // Looping over all 64 eta-phi towers - if (rmap->isHitInRegion(hitref,towerId)){ - towerList << towerId << ", "; - nTowers++; - } - } - - - - // Dump data to file: - // Comment out lines below to adjust output - // Linknumber | OnlineID | HashID | Plane | #Towers | TowerList - myfile << dec << m_sct_onlineId.fibre() << '\t' - << hex << m_sct_onlineId << '\t' - << dec << *hashit << '\t' - << dec << pinfo.getPlane() << '\t' - << dec << nTowers << '\t'; - - // Dump TowerList - - myfile.unsetf(ios::right | ios::showbase); - myfile << setw(20) << towerList.str() << '\t'; - towerList.str( string() ); - myfile.setf(ios::right | ios::showbase); - - // Dump Extended table - myfile << "#" << '\t' - << m_hitTyp << '\t' - << barrel_ec << '\t' - << layer_disk << '\t' - << phi_module << '\t' - << phi_module_max << '\t' - << eta_module << '\t' - << eta_module_min << '\t' - << eta_module_max << '\t' - << side << '\t' - << strip << '\t' - << endl; - } - } - - } - else { - log << MSG::ERROR << "Couldn't open file to store online-/offlinehashid" << endmsg; - return false; - } - // Clear the stringstream and close file - ss.str( string() ); - myfile.close(); + // Create file for output, format: LUT_0xABCDFGH.txt + ss << "LUT_"; + ss.setf(ios::showbase); + ss << hex << *rodit; + ss.unsetf(ios::showbase); + ss << ".txt"; + ofstream myfile(ss.str() ); + myfile.setf( ios::right | ios::showbase); + + if (myfile.is_open() ) { + + // Retrive hashlist + m_sct_cabling_svc->getHashesForRod(m_identifierHashList,*rodit ); + + // Some dumping variables + vector::const_iterator hashit = m_identifierHashList.begin(); + vector::const_iterator hashit_e = m_identifierHashList.end(); + SCT_OnlineId m_sct_onlineId; + + for (; hashit != hashit_e; ++hashit){ // TODO: Check for invalid onlineId && hashId numbers (?) + + // Retrieve OnlineId + m_sct_onlineId = m_sct_cabling_svc->getOnlineIdFromHash( *hashit ); + if (m_sct_onlineId.rod() == (*rodit)){ // Check for correct rodId + + myfile.setf(ios::right | ios::showbase); + id = m_sctId->wafer_id( *hashit); + + int barrel_ec = m_sctId->barrel_ec(id); + int layer_disk = m_sctId->layer_disk(id); + int phi_module = m_sctId->phi_module(id); + int phi_module_max = m_sctId->phi_module_max(id); + int eta_module = m_sctId->eta_module(id) ; + int eta_module_min = m_sctId->eta_module_min(id) ; + int eta_module_max = m_sctId->eta_module_max(id) ; + int side = m_sctId->side(id); + int strip = m_sctId->strip(id); + + // Get plane information + FTKPlaneSection &pinfo = pmap->getMap(m_hitTyp,!(barrel_ec==0),layer_disk); + + // Get tower information + FTKRawHit dummy; + dummy.setBarrelEC(barrel_ec); + dummy.setLayer(layer_disk); + dummy.setPhiModule(phi_module); + dummy.setEtaModule(eta_module); + + stringstream towerList; + int towerId; + int nTowers = 0; + FTKHit hitref = dummy.getFTKHit(pmap); + for (towerId = 0; towerId<64;towerId++){ // Looping over all 64 eta-phi towers + if (rmap->isHitInRegion(hitref,towerId)){ + towerList << towerId << ", "; + nTowers++; + } + } + + + + // Dump data to file: + // Comment out lines below to adjust output + // Linknumber | OnlineID | HashID | Plane | #Towers | TowerList + myfile << dec << m_sct_onlineId.fibre() << '\t' + << hex << m_sct_onlineId << '\t' + << dec << *hashit << '\t' + << dec << pinfo.getPlane() << '\t' + << dec << nTowers << '\t'; + + // Dump TowerList + + myfile.unsetf(ios::right | ios::showbase); + myfile << setw(20) << towerList.str() << '\t'; + towerList.str( string() ); + myfile.setf(ios::right | ios::showbase); + + // Dump Extended table + myfile << "#" << '\t' + << m_hitTyp << '\t' + << barrel_ec << '\t' + << layer_disk << '\t' + << phi_module << '\t' + << phi_module_max << '\t' + << eta_module << '\t' + << eta_module_min << '\t' + << eta_module_max << '\t' + << side << '\t' + << strip << '\t' + << endl; + } + } + + } + else { + log << MSG::ERROR << "Couldn't open file to store online-/offlinehashid" << endmsg; + return false; + } + // Clear the stringstream and close file + ss.str( string() ); + myfile.close(); } log << MSG::INFO << "Dumped FTKTestvectors" << endmsg; return true; - + } //-------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------- @@ -1172,19 +1173,19 @@ bool FTKRegionalWrapper::dumpFTKTestVectors(FTKPlaneMap *pmap, FTKRegionMap *rma StatusCode FTKRegionalWrapper::finalize() { - // the cluster container has to be explictly released - if(m_WriteClustersToESD){ - m_FTKPxlCluContainer->cleanup(); - m_FTKPxlCluContainer->release(); - m_FTKSCTCluContainer->cleanup(); - m_FTKSCTCluContainer->release(); - } - - // close the output files, but check that it exists (for athenaMP) - if (m_outfile) { - m_outfile->Write(); - m_outfile->Close(); - } - - return StatusCode::SUCCESS; + // the cluster container has to be explictly released + if(m_WriteClustersToESD){ + m_FTKPxlCluContainer->cleanup(); + m_FTKPxlCluContainer->release(); + m_FTKSCTCluContainer->cleanup(); + m_FTKSCTCluContainer->release(); + } + + // close the output files, but check that it exists (for athenaMP) + if (m_outfile) { + m_outfile->Write(); + m_outfile->Close(); + } + + return StatusCode::SUCCESS; } diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h index 0906073ce0e..faf3ae1797a 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h @@ -44,6 +44,76 @@ class cluster { typedef std::vector cluList; typedef std::map clustersByModuleMap; +/** + * This class creates a hit whose coordinates are relative to the Front-End chip + * of the module that it belongs to. It is used for the correct ordering of the hits + * in the FTK_IM hit decoder. + */ +class FTK_FECoordsHit { +public: + /** + * Create an FTK_Hit_FECoords from an FTKRawHit + * \param h FTKRawHit to be processed + */ + FTK_FECoordsHit(const FTKRawHit* hit) { + tot = hit->getTot(); + int acol = hit->getEtaStrip(); + int arow = hit->getPhiSide(); + bool isIBLmodule = (hit->getModuleType() == ftk::MODULETYPE_IBL_PLANAR || hit->getModuleType() == ftk::MODULETYPE_IBL3D); + if(!isIBLmodule){ + if (arow < ftk::clustering::rowsInFEChipPerPixelModuleRow) { + fe = ftk::clustering::feChipsInRowPixel + acol/ftk::clustering::colsInFEChipPerPixelModuleRow; + lrow = arow; + lcol = acol%ftk::clustering::colsInFEChipPerPixelModuleRow; + } else { + fe = (ftk::clustering::feChipsInRowPixel - 1) - acol/ftk::clustering::colsInFEChipPerPixelModuleRow; //-1 because we start counting from 0 + lrow = (ftk::numberOfPhiPixelsInPixelModule - 1) - arow; //We start counting from 0 + lcol = (ftk::clustering::colsInFEChipPerPixelModuleRow - 1) - acol%ftk::clustering::colsInFEChipPerPixelModuleRow; //Start counting from 0 + } + }else{ + if (acol < ftk::clustering::colsInFEChipPerIblModuleRow) { + fe = 0; + lcol = acol; + } else { + fe = 1; + lcol = acol-80; + } + lrow = (ftk::clustering::rowsInFEChipPerIblModuleRow - 1) - arow; + } + } + + int fe; ///< The FE chip of the hit + int tot; ///< ToT of the hit + int lcol; ///< Column of the hit expressed in FE coordinates + int lrow; ///< Row of the hit expressed in FE coordinates +}; + +/** + * This class creates a hit whose coordinates are relative to the hit's position + * in the cluster. It is used to calculate if a cluster is split and for + * printing out the test vectors. + */ +class FTK_ClusterCoordHit +{ +public: + /** + * Create an FTK_Hit_FECoords from an FTKRawHit + * \param h FTKRawHit to be processed + * \param seed the central hit of the cluster + */ + FTK_ClusterCoordHit(const FTKRawHit &h, const FTKRawHit* seed) { + tot = h.getTot(); + crow = h.getPhiSide() - (seed->getPhiSide() - 10); + if (seed->getEtaStrip() %2 != 0) ccol = h.getEtaStrip() - (seed->getEtaStrip() - 1); + else ccol = h.getEtaStrip() - (seed->getEtaStrip()); + } + int tot; ///< ToT of the hit in the cluster + int ccol; ///< Column of the hit in the cluster + int crow; ///< Row of the hit in the cluster +}; + + + class FTKClusteringEngine { private: diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h index 1f08f6446cd..b82b99bbc7e 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h @@ -15,7 +15,7 @@ class FTKClusteringPrintout { public: - FTKClusteringPrintout(); + FTKClusteringPrintout cp(); void printHit(const FTKRawHit &hit); void printInputData(hitVector* currentHits); diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx index c6315db8aed..58b9c7b81be 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx @@ -3,7 +3,6 @@ */ #include "TrigFTKSim/FTKClusteringEngine.h" -#include "TrigFTKSim/FTKClusteringPrintout.h" #include "TrigFTKSim/FTKSetup.h" #include "TrigFTKSim/FTKPMap.h" #include "TrigFTKSim/MultiTruth.h" @@ -51,75 +50,6 @@ bool FTKClusteringEngine::hitOnIBLmodule(const FTKRawHit &hit) } -/** - * This class creates a hit whose coordinates are relative to the Front-End chip - * of the module that it belongs to. It is used for the correct ordering of the hits - * in the FTK_IM hit decoder. - */ -class FTK_FECoordsHit { -public: - /** - * Create an FTK_Hit_FECoords from an FTKRawHit - * \param h FTKRawHit to be processed - */ - FTK_FECoordsHit(const FTKRawHit* hit) { - tot = hit->getTot(); - int acol = hit->getEtaStrip(); - int arow = hit->getPhiSide(); - bool isIBLmodule = (hit->getModuleType() == ftk::MODULETYPE_IBL_PLANAR || hit->getModuleType() == ftk::MODULETYPE_IBL3D); - if(!isIBLmodule){ - if (arow < ftk::clustering::rowsInFEChipPerPixelModuleRow) { - fe = ftk::clustering::feChipsInRowPixel + acol/ftk::clustering::colsInFEChipPerPixelModuleRow; - lrow = arow; - lcol = acol%ftk::clustering::colsInFEChipPerPixelModuleRow; - } else { - fe = (ftk::clustering::feChipsInRowPixel - 1) - acol/ftk::clustering::colsInFEChipPerPixelModuleRow; //-1 because we start counting from 0 - lrow = (ftk::numberOfPhiPixelsInPixelModule - 1) - arow; //We start counting from 0 - lcol = (ftk::clustering::colsInFEChipPerPixelModuleRow - 1) - acol%ftk::clustering::colsInFEChipPerPixelModuleRow; //Start counting from 0 - } - }else{ - if (acol < ftk::clustering::colsInFEChipPerIblModuleRow) { - fe = 0; - lcol = acol; - } else { - fe = 1; - lcol = acol-80; - } - lrow = (ftk::clustering::rowsInFEChipPerIblModuleRow - 1) - arow; - } - } - - int fe; ///< The FE chip of the hit - int tot; ///< ToT of the hit - int lcol; ///< Column of the hit expressed in FE coordinates - int lrow; ///< Row of the hit expressed in FE coordinates -}; - -/** - * This class creates a hit whose coordinates are relative to the hit's position - * in the cluster. It is used to calculate if a cluster is split and for - * printing out the test vectors. - */ -class FTK_ClusterCoordHit -{ -public: - /** - * Create an FTK_Hit_FECoords from an FTKRawHit - * \param h FTKRawHit to be processed - * \param seed the central hit of the cluster - */ - FTK_ClusterCoordHit(const FTKRawHit &h, const FTKRawHit* seed) { - tot = h.getTot(); - crow = h.getPhiSide() - (seed->getPhiSide() - 10); - if (seed->getEtaStrip() %2 != 0) ccol = h.getEtaStrip() - (seed->getEtaStrip() - 1); - else ccol = h.getEtaStrip() - (seed->getEtaStrip()); - } - int tot; ///< ToT of the hit in the cluster - int ccol; ///< Column of the hit in the cluster - int crow; ///< Row of the hit in the cluster -}; - - bool FTKClusteringEngine::sortbyFE (const FTKRawHit* i,const FTKRawHit* j) { if (i->getHitType() == ftk::SCT || j->getHitType() == ftk::SCT) @@ -384,10 +314,6 @@ bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const c tmpHit->setEtaStrip( eta ); tmpHit->setLayer( hit.getLayer() ); tmpHit->setPhiSide( gangedPartner(hit) ); - if ( !hitIsGanged(*tmpHit) ) { - cp.printHit(*tmpHit); - assert(0); - } connectedHits.push_back( tmpHit ); // store connected hit pointer } // end of nested loop over hits } //end of "if (phi)" @@ -1000,8 +926,8 @@ void FTKClusteringEngine::realisticPixelDecoder(hitVector* ¤tHits) } } - std::cout << "GOING TO DECODER" << std::endl; - cp.printDecoderOutput(currentHits); + // std::cout << "GOING TO DECODER" << std::endl; + // cp.printDecoderOutput(currentHits); } diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx index 36c408ad3f5..8570e44284a 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx @@ -1,6 +1,24 @@ #include "TrigFTKSim/FTKClusteringPrintout.h" -#include "src/FTKClusteringEngine.cxx" +#include "TrigFTKSim/FTKClusteringEngine.h" #include +#include + +//#define DEBUG_HITS +//#define DECODER_INPUT 0 +#define DECODER_OUTPUT 0 +//#define CLUSTERING_PRINTOUT 0 +//#define CENTROID_PRINTOUT 0 +//#define BOUNDING_BOX + +const bool DEBUG_HITS = 0; +const bool DEBUG_CLUSTERS = 0; +const bool DEBUG_AVERAGE = 0; +const bool DEBUG_AVERAGE_SCT = 0; + +const bool PRINT_INPUT = 0; // print input data +const bool DEBUG_INPUT = 0; // detail check input +const bool DEBUG_DECODER = 1; // check decoder output +const bool DEBUG_CENTROID = 0; // check centroid calc. /*! * Function printing the hit details @@ -47,7 +65,7 @@ void printClu(const cluster &clu) hitVector hs = clu.hitlist; hitVector::iterator hit = hs.begin(); - vector tmp; + std::vector tmp; for (hit = hs.begin(); hit != hs.end(); hit++) { tmp.push_back(FTK_ClusterCoordHit(**hit, clu.seed)); } @@ -55,7 +73,7 @@ void printClu(const cluster &clu) //sort and print the vector. if (tmp.size() > 1) std::stable_sort(tmp.begin(), tmp.end(), clusterSort); - for(vector::iterator hit1 = tmp.begin(); hit1 != tmp.end(); hit1++) { + for(std::vector::iterator hit1 = tmp.begin(); hit1 != tmp.end(); hit1++) { printf("0000%.2X%.2X%.3X\n",(*hit1).tot, (*hit1).ccol, (*hit1).crow); //printf("0000%.2X%.2X%.3X",(*hit1).tot, (*hit1).ccol, (*hit1).crow); //printf(" tot: %d col: %d row: %d\n",(*hit1).tot, (*hit1).ccol, (*hit1).crow); @@ -105,7 +123,6 @@ void printCentroidList(clustersByModuleMap clustersByModule) bool isIBLmodule = ((*hit).getModuleType() == ftk::MODULETYPE_IBL3D || (*hit).getModuleType() == ftk::MODULETYPE_IBL_PLANAR); int idHash = hit->getIdentifierHash(); - int isPixel = hit->getIsPixel(); if(isIBLmodule){// for IBL bool FE0_exist = false; @@ -181,13 +198,13 @@ void printDecoderOutput(hitVector* currentHits) int outputData = ( (tempTot << 20) | (tempCol << 12) | tempRow ); printf("0x0%.7X",outputData); - if(!DEBUG_DECODER) cout << endl; + if(!DEBUG_DECODER) std::cout << std::endl; else{ - cout << " IBL HIT" - << " col: " << setfill('0') << setw(3) << tempCol - << " row: " << setfill('0') << setw(3) << tempRow - << " tot: " << setfill('0') << setw(2) << tempTot - << endl; + std::cout << " IBL HIT" + << " col: " << std::setfill('0') << std::setw(3) << tempCol + << " row: " << std::setfill('0') << std::setw(3) << tempRow + << " tot: " << std::setfill('0') << std::setw(2) << tempTot + << std::endl; } } @@ -195,13 +212,13 @@ void printDecoderOutput(hitVector* currentHits) printf("0x8%.7x\n", (**hit).getIdentifierHash()); for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { printf("0x0%.2X%.2X%.3X",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); - if(!DEBUG_DECODER) cout << endl; + if(!DEBUG_DECODER) std::cout << std::endl; else{ - cout << " Pixel HIT" - << " col: " << (*hit)->getEtaStrip() - << " row: " << (*hit)->getPhiSide() - << " tot: " << (*hit)->getTot() - << endl; + std::cout << " Pixel HIT" + << " col: " << (*hit)->getEtaStrip() + << " row: " << (*hit)->getPhiSide() + << " tot: " << (*hit)->getTot() + << std::endl; } } //hit loop @@ -234,13 +251,13 @@ void printInputData(hitVector* currentHits) int outputData = ((idHash << 24) | (tempTot << 20) | (tempCol << 9) | tempRow ); printf("0x09%.7x",outputData); - if(!DEBUG_INPUT) cout << endl; + if(!DEBUG_INPUT) std::cout << std::endl; else{ - cout << " IBL HIT" - << " col: " << setfill('0') << setw(3) << tempCol - << " row: " << setfill('0') << setw(3) << tempRow - << " tot: " << setfill('0') << setw(2) << tempTot - << endl; + std::cout << " IBL HIT" + << " col: " << std::setfill('0') << std::setw(3) << tempCol + << " row: " << std::setfill('0') << std::setw(3) << tempRow + << " tot: " << std::setfill('0') << std::setw(2) << tempTot + << std::endl; } } @@ -251,18 +268,16 @@ void printInputData(hitVector* currentHits) for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { printf("0x00%.2x%.2x%.3x ",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); - if(!DEBUG_DECODER) cout << endl; + if(!DEBUG_DECODER) std::cout << std::endl; else{ - cout << " Pixel HIT" - << " col: " << (*hit)->getEtaStrip() - << " row: " << (*hit)->getPhiSide() - << " tot: " << (*hit)->getTot() - << endl; + std::cout << " Pixel HIT" + << " col: " << (*hit)->getEtaStrip() + << " row: " << (*hit)->getPhiSide() + << " tot: " << (*hit)->getTot() + << std::endl; } } } // hit loop printf("0x05%.1x400000\n", idHash); } - - diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx index 534d6506a99..90a5096c7d0 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx @@ -105,8 +105,8 @@ void FTKDataInput::processEvent(bool clearOrig) if (!m_read_clusters) { // if raw channels are read the clustering algorithm can be applyied (default) if (m_Clustering ) { - clusteringEngine.atlClusteringLNF(m_original_hits); - clusteringEngine.atlClusteringBlayer(m_original_hits); // split blayer modules in half, if requested + clusteringEngine->atlClusteringLNF(m_original_hits); + clusteringEngine->atlClusteringBlayer(m_original_hits); // split blayer modules in half, if requested } else { // If the clustering it is not executed the FTKRawHit.m_truth field has to be fixed @@ -232,8 +232,8 @@ void FTKDataInput::processRegion(int curreg, bool clearOrig) if (!m_read_clusters) { // if raw channels are read the clustering algorithm can be applyied (default) if (m_Clustering ) { - clusteringEngine.atlClusteringLNF(currawhits); - clusteringEngine.atlClusteringBlayer(currawhits); // split blayer modules in half, if requested + clusteringEngine->atlClusteringLNF(currawhits); + clusteringEngine->atlClusteringBlayer(currawhits); // split blayer modules in half, if requested } else { // If the clustering it is not executed the FTKRawHit.m_truth field has to be fixed -- GitLab From 2b9470a206d751ab83a8c9f2d027348f86e9b187 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Wed, 6 Mar 2019 12:27:15 +0100 Subject: [PATCH 09/18] Moved hitVector and cluLust to use unique_ptr; doesn't yet run properly --- .../TrigFTKSim/FTKClusteringEngine.h | 66 +- .../TrigFTKSim/FTKClusteringPrintout.h | 13 +- .../TrigFTKSim/src/FTKClusteringEngine.cxx | 611 ++++++++---------- .../TrigFTKSim/src/FTKClusteringPrintout.cxx | 349 +++++----- 4 files changed, 480 insertions(+), 559 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h index faf3ae1797a..aa7e9a047c8 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h @@ -17,32 +17,33 @@ #include #include #include +#include #include -class FTKRawHit_cmp { - public: - bool operator() (const FTKRawHit *hit1, const FTKRawHit *hit2) const; -}; +/* class FTKRawHit_cmp { */ +/* public: */ +/* bool operator() (const FTKRawHit *hit1, const FTKRawHit *hit2) const; */ +/* }; */ -typedef std::vector hitVector; +typedef std::vector> hitVector; typedef std::map hitsByModuleMap; class cluster { - public: - hitVector hitlist; // list of hits that make the cluster - FTKRawHit clusterEquiv; // hit equivalent to the cluster - FTKRawHit* seed; // hit equivalent to the cluster - bool isSafe; // confirmed by ganged pattern recognition - bool isKilled; // ganged pattern recognition suggest to remove this cluster +public: + hitVector hitlist; //< list of hits that make the cluster + FTKRawHit clusterEquiv; //< hit equivalent to the cluster + FTKRawHit seed; //< The first hit, which is used to start the cluster in PCM > 100 + bool isSafe; // confirmed by ganged pattern recognition + bool isKilled; // ganged pattern recognition suggest to remove this cluster ~cluster(); }; -typedef std::vector cluList; -typedef std::map clustersByModuleMap; +typedef std::vector> cluList; +typedef std::map clustersByModuleMap; /** * This class creates a hit whose coordinates are relative to the Front-End chip @@ -55,11 +56,11 @@ public: * Create an FTK_Hit_FECoords from an FTKRawHit * \param h FTKRawHit to be processed */ - FTK_FECoordsHit(const FTKRawHit* hit) { - tot = hit->getTot(); - int acol = hit->getEtaStrip(); - int arow = hit->getPhiSide(); - bool isIBLmodule = (hit->getModuleType() == ftk::MODULETYPE_IBL_PLANAR || hit->getModuleType() == ftk::MODULETYPE_IBL3D); + FTK_FECoordsHit(const FTKRawHit& hit) { + tot = hit.getTot(); + int acol = hit.getEtaStrip(); + int arow = hit.getPhiSide(); + bool isIBLmodule = (hit.getModuleType() == ftk::MODULETYPE_IBL_PLANAR || hit.getModuleType() == ftk::MODULETYPE_IBL3D); if(!isIBLmodule){ if (arow < ftk::clustering::rowsInFEChipPerPixelModuleRow) { fe = ftk::clustering::feChipsInRowPixel + acol/ftk::clustering::colsInFEChipPerPixelModuleRow; @@ -101,11 +102,11 @@ public: * \param h FTKRawHit to be processed * \param seed the central hit of the cluster */ - FTK_ClusterCoordHit(const FTKRawHit &h, const FTKRawHit* seed) { + FTK_ClusterCoordHit(const FTKRawHit &h, const FTKRawHit& seed) { tot = h.getTot(); - crow = h.getPhiSide() - (seed->getPhiSide() - 10); - if (seed->getEtaStrip() %2 != 0) ccol = h.getEtaStrip() - (seed->getEtaStrip() - 1); - else ccol = h.getEtaStrip() - (seed->getEtaStrip()); + crow = h.getPhiSide() - (seed.getPhiSide() - 10); + if (seed.getEtaStrip() %2 != 0) ccol = h.getEtaStrip() - (seed.getEtaStrip() - 1); + else ccol = h.getEtaStrip() - (seed.getEtaStrip()); } int tot; ///< ToT of the hit in the cluster int ccol; ///< Column of the hit in the cluster @@ -123,7 +124,7 @@ private: const int PIXEL_CLUSTERING_IDEAL_APRIL_2014_FIX=2; const int PIXEL_CLUSTERING_MIXED=100; const int PIXEL_CLUSTERING_REALISTIC=101; - const int PIXEL_CLUSTERING_HARDWARE = 200; + const int PIXEL_CLUSTERING_HARDWARE = 200; bool saveClusterContent; bool diagClustering; @@ -134,16 +135,21 @@ private: bool splitBlayerModules; int pixelClusteringMode; - static bool sortbyFE (const FTKRawHit* i,const FTKRawHit* j); - static bool sortInput(const FTKRawHit* i, const FTKRawHit* j); + static bool sortPixelInput (const std::unique_ptr& i, const std::unique_ptr& j); + static bool sortIBLInput(const std::unique_ptr& i, const std::unique_ptr& j); bool isSplitCluster(const cluster& clu); bool hitOnIBLmodule(const FTKRawHit &hit); int hitToModuleId(const FTKRawHit &hit); + void realisticPixelDecoder(hitVector& currentHits); + void realisticIBLDecoder(hitVector& currentHits); + + bool neighborhood(const FTKRawHit &hit1, const FTKRawHit &hit2); - int buildUpCluster(hitVector *currentHits, cluster &clu); - void makeClustersLNF(hitVector *currentHits, cluList *currentClusters); - void makeClusterFromSeed(hitVector *currentHits, cluList *currentClusters, FTKRawHit* &seed); + int buildUpCluster(hitVector& currentHits, cluster& clu); + void makeClustersLNF(hitVector& currentHits, cluList& currentClusters); + void makeClustersGridWindow(hitVector& currentHits, cluList& currentClusters); + void makeClusterFromSeed(hitVector& currentHits, cluList& currentClusters, FTKRawHit& seed); void averageCluster(cluster &clu); bool pixelRowIsGanged(const int row); @@ -152,8 +158,8 @@ private: bool gangedHitHasNeighborhood(const FTKRawHit &hit, const cluster &clu, hitVector &connectedHits); bool findConnectedGanged(cluster &clu, hitVector &connectedHits); bool isKilled(const cluster &clu, const hitVector &connectedHits); - void realisticPixelDecoder(hitVector* ¤tHits); - FTKRawHit* gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits); + FTKRawHit gridAUTH( boost::circular_buffer> &cb, + hitVector &fifo, hitVector &gridhits); double getDeltaX1A(cluster &); double getDeltaX2A(cluster &); int getDeltaXEC1A(cluster &); diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h index b82b99bbc7e..952a237b1ed 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h @@ -4,12 +4,13 @@ #include "TrigFTKSim/FTKRawHit.h" #include "TrigFTKSim/ftkdefs.h" #include +#include class cluster; -typedef std::vector hitVector; +typedef std::vector> hitVector; typedef std::map hitsByModuleMap; -typedef std::vector cluList; -typedef std::map clustersByModuleMap; +typedef std::vector> cluList; +typedef std::map clustersByModuleMap; class FTKClusteringPrintout { @@ -17,9 +18,9 @@ class FTKClusteringPrintout public: FTKClusteringPrintout cp(); void printHit(const FTKRawHit &hit); - - void printInputData(hitVector* currentHits); - void printDecoderOutput(hitVector* currentHits); + void printClu(const cluster &clu); + void printInputData(const hitVector& currentHits); + void printDecoderOutput(const hitVector& currentHits); void printClusterList(clustersByModuleMap clustersByModule); void printCentroidList(clustersByModuleMap clustersByModule); diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx index 58b9c7b81be..622f55bb976 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx @@ -50,13 +50,11 @@ bool FTKClusteringEngine::hitOnIBLmodule(const FTKRawHit &hit) } -bool FTKClusteringEngine::sortbyFE (const FTKRawHit* i,const FTKRawHit* j) +bool FTKClusteringEngine::sortPixelInput (const std::unique_ptr& i, const std::unique_ptr& j) { - if (i->getHitType() == ftk::SCT || j->getHitType() == ftk::SCT) - return false; - FTK_FECoordsHit lhit1(i); - FTK_FECoordsHit lhit2(j); + FTK_FECoordsHit lhit1(*(i.get())); + FTK_FECoordsHit lhit2(*(j.get())); if (lhit1.fe != lhit2.fe) return lhit1.fe <= lhit2.fe; else if (lhit1.fe == lhit2.fe) { @@ -67,7 +65,7 @@ bool FTKClusteringEngine::sortbyFE (const FTKRawHit* i,const FTKRawHit* j) return false; } -bool FTKClusteringEngine::sortInput(const FTKRawHit* i, const FTKRawHit* j) +bool FTKClusteringEngine::sortIBLInput(const std::unique_ptr& i, const std::unique_ptr& j) { int firstCol = i->getEtaStrip() + 1; int secondCol = j->getEtaStrip() + 1; @@ -89,6 +87,7 @@ bool FTKClusteringEngine::sortInput(const FTKRawHit* i, const FTKRawHit* j) else return firstRow < secondRow; } } + return false; } /*! @@ -98,12 +97,11 @@ bool FTKClusteringEngine::sortInput(const FTKRawHit* i, const FTKRawHit* j) */ bool FTKClusteringEngine::isSplitCluster(const cluster& clu) { - //FTK_ClusterCoordHit seed = FTK_ClusterCoordHit(*clu.seed, clu.seed); - hitVector::const_iterator it = clu.hitlist.begin(); - for (it = clu.hitlist.begin(); it != clu.hitlist.end(); it++) { - if (clu.seed == NULL) - return false; - FTK_ClusterCoordHit chit = FTK_ClusterCoordHit(**it , clu.seed); + for (auto& hit: clu.hitlist) { + // if (clu.seed == NULL) + // return false; + FTKRawHit h = clu.seed; + FTK_ClusterCoordHit chit = FTK_ClusterCoordHit(*hit , h); if ((chit.ccol >= GRID_COL_MAX - 1) || (chit.crow >= (GRID_ROW_MAX - 1)) || ( chit.crow <= 0)) return true; } @@ -146,6 +144,7 @@ int FTKClusteringEngine::hitToModuleId(const FTKRawHit &hit) return hit.getHitType() == ftk::PIXEL ? hit.getIdentifierHash() : 0x8000 + hit.getIdentifierHash(); } + /*! * Check (and define) if two hits are next to each other * For the time being it accepts only pair of hits from the same module and same SCT side. @@ -158,10 +157,8 @@ bool FTKClusteringEngine::neighborhood(const FTKRawHit &hit1, const FTKRawHit &h { // 1st check same module - if (hit1.getBarrelEC() != hit2.getBarrelEC() || hit1.getHitType() != hit2.getHitType() || - hit1.getLayer() != hit2.getLayer() || hit1.getEtaModule() != hit2.getEtaModule() || - hit1.getPhiModule() != hit2.getPhiModule()) { // if module is NOT the same - assert(0); // temporary check + if (hit1.getIdentifierHash() != hit2.getIdentifierHash()) { + std::cout << "CHECK AGAIN, SOMETHING'S WRONG" << std::endl; return false; } @@ -169,19 +166,12 @@ bool FTKClusteringEngine::neighborhood(const FTKRawHit &hit1, const FTKRawHit &h case ftk::SCT: if (!sctClustering) return false; - - if (hit1.getPhiSide() != hit2.getPhiSide()) { // if different side - assert(0); // temporary check - return false; - } - assert(hit1.getEtaStrip() != hit2.getEtaStrip()); // sanity check if (hit1.getEtaStrip() == hit2.getEtaStrip()+hit2.getNStrips() || hit1.getEtaStrip()+hit1.getNStrips() == hit2.getEtaStrip()) return true; return false; case ftk::PIXEL: - assert(hit1.getEtaStrip() != hit2.getEtaStrip() || hit1.getPhiSide() != hit2.getPhiSide()); // sanity check /* need a common edge, i.e. contiguity along diagonal is not enough (see below) */ if ( (hit1.getEtaStrip() == hit2.getEtaStrip()+1 || hit1.getEtaStrip()+1 == hit2.getEtaStrip()) && hit1.getPhiSide() == hit2.getPhiSide()) return true; @@ -197,101 +187,90 @@ bool FTKClusteringEngine::neighborhood(const FTKRawHit &hit1, const FTKRawHit &h return false; } - assert(0); // should not get here! return false; } - -int FTKClusteringEngine::buildUpCluster(hitVector *currentHits, cluster &clu) +// /* +// * Recursively adds hits to a given cluster. +// * Returns number of hits in final cluster. +// * If no cluster is given (or empty cluster) make a cluster out of the 1st hit. +// */ +int FTKClusteringEngine::buildUpCluster(hitVector& currentHits, cluster& clu) { - /* - * Recursively adds hits to a given cluster. - * Returns number of hits in final cluster. - * If no cluster is given (or empty cluster) make a cluster out of the 1st hit. - */ - assert(currentHits->size()>0); // need at least one hit! - - hitVector::iterator hitP; - if (clu.hitlist.size()==0) { // if cluster is empty - hitP = currentHits->begin(); - clu.hitlist.push_back(*hitP); - currentHits->erase(hitP); - - // FlagAK - dirty fix to disable clustering on 1st layer - // if( (*hitP).getLayer()==0 && (*hitP).getIsPixel() ) { - // return clu->hitlist.size(); - // } - - } + if (clu.hitlist.size()==0) + clu.hitlist.push_back(std::move(currentHits.front())); /* Now we have a non empty cluster */ bool newHitsAdded = false; int distanceis = clu.hitlist.size(); - hitVector::iterator hitCluP; // hits in cluster - //for (hitCluP=clu.hitlist.begin(); hitCluP!=clu.hitlist.end(); ++hitCluP) { // loop over hits in cluster + + hitVector::iterator hitP; for(int i = 0; i < distanceis; i++) { - FTKRawHit* hit = clu.hitlist.at(i); - for (hitP=currentHits->begin(); hitP!=currentHits->end();) { // loop over hits in module - //if (neighborhood(**hitCluP, **hitP)) { // if hits are neighborhood + FTKRawHit* hit = clu.hitlist.at(i).get(); + for (hitP = currentHits.begin(); hitP != currentHits.end(); ) { // loop over hits in module if (neighborhood(*hit, **hitP)) { // if hits are neighborhood - // add hit to cluster - clu.hitlist.push_back(*hitP); - //hitCluP = clu.hitlist.begin(); - currentHits->erase(hitP); + clu.hitlist.push_back(std::move(*hitP)); distanceis++; - hitP=currentHits->begin(); // if a hit is erased then restart the loop + hitP = currentHits.begin(); // if a hit is erased then restart the loop newHitsAdded = true; } else { ++hitP; // if hit is not a neighborhood then go to next hit } - } // end of loop over hits in module - } // end of loop over hits in cluster + } + } - // if at least one hit was added, check for more neighborhood hits - if (newHitsAdded && currentHits->size()) buildUpCluster(currentHits, clu); - return clu.hitlist.size(); + // // if at least one hit was added, check for more neighborhood hits + if (newHitsAdded && currentHits.size()) buildUpCluster(currentHits, clu); + return clu.hitlist.size(); } /* * Group all hits from one module into clusters */ -void FTKClusteringEngine::makeClustersLNF(hitVector *currentHits, cluList *currentClusters) +void FTKClusteringEngine::makeClustersLNF(hitVector& currentHits, cluList& currentClusters) { - int index=0; - while (currentHits->size()) { // as long as we have hits - cluster clu; - clu.isSafe = false; // initialitaion - clu.isKilled = false; // initialitaion - int cluSize = buildUpCluster(currentHits, clu); - currentClusters->push_back(clu); - if (0) - std::cout << "DEBUG_makeCluster:" - << " index=" << index - << " cluSize=" << cluSize - << " Nclusters=" << currentClusters->size() - << "\n"; - index++; + while (currentHits.size()) { // as long as we have hits + auto clu = std::make_unique(); + clu->isSafe = false; + clu->isKilled = false; + int cluSize = buildUpCluster(currentHits, *clu.get()); + currentClusters.push_back(std::move(clu)); } } - -void FTKClusteringEngine::makeClusterFromSeed(hitVector *currentHits, cluList *currentClusters, FTKRawHit* &seed) +void FTKClusteringEngine::makeClustersGridWindow(hitVector& fifo, cluList& currentClusters) { - //erase seed fom currentHits - hitVector::iterator position = std::find(currentHits->begin(), currentHits->end(), seed); - if (position != currentHits->end()) { - currentHits->erase(position); + boost::circular_buffer> circular_buffer (256); + hitVector gridhits; + while (!fifo.empty() || !circular_buffer.empty()) { + FTKRawHit seed = gridAUTH(circular_buffer, fifo, gridhits); + makeClusterFromSeed(gridhits, currentClusters, seed); + + for(hitVector::iterator hsi = gridhits.begin(); hsi != gridhits.end(); hsi++) { + circular_buffer.push_back(std::move (*hsi)); + } + + gridhits.clear(); } +} + +void FTKClusteringEngine::makeClusterFromSeed(hitVector& currentHits, cluList& currentClusters, FTKRawHit &seed) +{ + // hitVector::iterator position = std::find(currentHits.begin(), currentHits.end(), seed); + // if (position != currentHits.end()) { + // currentHits.erase(position); + // } cluster clu; clu.seed = seed; - clu.hitlist.push_back(seed); + // clu.hitlist.push_back(std::move(seed)); clu.isSafe = false; clu.isKilled = false; - if (currentHits->size() > 0) buildUpCluster(currentHits, clu); - currentClusters->push_back(clu); + if (currentHits.size() > 0) + buildUpCluster(currentHits, clu); + // currentClusters.push_back(std::make_unique(clu)); } @@ -302,19 +281,19 @@ bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const c // std::cout << "phi: " << phi << std::endl; if (phi) { // check hit is ganged int eta = hit.getEtaStrip(); - hitVector hv = clu.hitlist; - hitVector::iterator pp; - for (pp=hv.begin(); pp!=hv.end(); ++pp) { - if ( eta != (*pp)->getEtaStrip() ) continue; - if ( abs(phi - (*pp)->getPhiSide() ) != 1 ) continue; + for (auto& pp: clu.hitlist) { + if ( eta != (*pp).getEtaStrip() ) + continue; + if ( abs(phi - (*pp).getPhiSide() ) != 1 ) + continue; hasNeighborhood = true; - FTKRawHit *tmpHit = new FTKRawHit(); + std::unique_ptr tmpHit; tmpHit->setHitType( ftk::PIXEL ); tmpHit->setModuleType( hit.getModuleType()); tmpHit->setEtaStrip( eta ); tmpHit->setLayer( hit.getLayer() ); tmpHit->setPhiSide( gangedPartner(hit) ); - connectedHits.push_back( tmpHit ); // store connected hit pointer + connectedHits.push_back( std::move(tmpHit) ); // store connected hit pointer } // end of nested loop over hits } //end of "if (phi)" return hasNeighborhood; @@ -322,31 +301,24 @@ bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const c bool FTKClusteringEngine::findConnectedGanged(cluster &clu, hitVector &connectedHits) { - assert(clu.hitlist.size()>0); // sanity check - - hitVector::iterator p; bool hasNeighborhood = false; - for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { - if ( gangedHitHasNeighborhood(**p, clu, connectedHits) ) { + for (auto& hit: clu.hitlist) { + if ( gangedHitHasNeighborhood(*hit, clu, connectedHits) ) { hasNeighborhood = true; } - } // end of first loop over hits + } return hasNeighborhood; } bool FTKClusteringEngine::isKilled(const cluster &clu, const hitVector &connectedHits) { - hitVector tmphv = clu.hitlist; - hitVector::iterator p; - for (p=tmphv.begin(); p!=tmphv.end(); ++p) { - if ( !hitIsGanged(**p) ) continue; - hitVector hv = connectedHits; - hitVector::iterator c; - for (c=(hv).begin(); c!=(hv).end(); ++c) { - assert( hitIsGanged(**c) ); // all connected hits should be ganged ! - if ( (*c)->getPhiSide() == (*p)->getPhiSide() - && (*c)->getEtaStrip() == (*p)->getEtaStrip() ) return true; + for (auto& hit: clu.hitlist) { + if ( !hitIsGanged(*hit) ) continue; + for (auto& chit: connectedHits) { + if ( (*chit).getPhiSide() == (*hit).getPhiSide() + && (*chit).getEtaStrip() == (*hit).getEtaStrip() ) + return true; } } // loop over hits in cluster @@ -367,20 +339,20 @@ void FTKClusteringEngine::averageCluster(cluster &clu) assert(nHits>0); // sanity check FTKRawHit &av = clu.clusterEquiv; ///< get pointer to clusterEquivalent - FTKRawHit *first = *(clu.hitlist.begin()); ///< get 1st hit + FTKRawHit first = *(clu.hitlist.front()); ///< get 1st hit /// reset values for clusterEquivalent (alias av) av.reset(); av.setX(0); av.setY(0); av.setZ(0); - av.setIdentifierHash(first->getIdentifierHash()); - av.setHitType(first->getHitType()); - av.setModuleType(first->getModuleType()); - av.setBarrelEC(first->getBarrelEC()); - av.setLayer(first->getLayer()); - av.setPhiModule(first->getPhiModule()); - av.setEtaModule(first->getEtaModule()); + av.setIdentifierHash(first.getIdentifierHash()); + av.setHitType(first.getHitType()); + av.setModuleType(first.getModuleType()); + av.setBarrelEC(first.getBarrelEC()); + av.setLayer(first.getLayer()); + av.setPhiModule(first.getPhiModule()); + av.setEtaModule(first.getEtaModule()); av.setEtaStrip(0); av.setNStrips(0); av.setEtaWidth(0); @@ -407,12 +379,12 @@ void FTKClusteringEngine::averageCluster(cluster &clu) hitVector::iterator p; /// precalculate values for case pixelClusteringMode>0 - int BarrelEndCap = first->getBarrelEC(); + int BarrelEndCap = first.getBarrelEC(); //Calculate the active layer. Start with the layer of the hit. In case // always count IBL as layer0 and BLayer as layer1 - int layer = first->getLayer(); - bool isIBLmodule = hitOnIBLmodule(*first); + int layer = first.getLayer(); + bool isIBLmodule = hitOnIBLmodule(first); bool isPixelmodule = !isIBLmodule; if (FTKSetup::getFTKSetup().getIBLMode()==0) layer++; @@ -427,7 +399,7 @@ void FTKClusteringEngine::averageCluster(cluster &clu) // FlagAA: 2015-01-29 making default the units of 6.25um for r-phi coordinates float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-6; + float etaModule = first.getEtaModule()-6; // FlagAA 2013-07-31: IBL code assumes fully planar geometry as in mc12+IBL // This will change for the real detector!!! if (isIBLmodule) { @@ -438,8 +410,8 @@ void FTKClusteringEngine::averageCluster(cluster &clu) moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors pixYScaleFactor = ftk::clustering::yScaleFactorIbl; ///getEtaModule()-8; - if( first->getModuleType() == ftk::MODULETYPE_IBL3D && ibl3DRealistic ) { + etaModule = first.getEtaModule()-8; + if( first.getModuleType() == ftk::MODULETYPE_IBL3D && ibl3DRealistic ) { sensorThickness = 230*ftk::micrometer; moduleActiveLength = 80*250; numberOfEtaPixelsInModule = ftk::clustering::colsInFEChipPerIblModuleRow; @@ -451,7 +423,7 @@ void FTKClusteringEngine::averageCluster(cluster &clu) case ftk::SCT: { int firstStrip = 99999; int lastStrip = -99999; - av.setPhiSide(first->getPhiSide()); + av.setPhiSide(first.getPhiSide()); for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { av.addX((*p)->getX()); av.addY((*p)->getY()); @@ -653,7 +625,7 @@ void FTKClusteringEngine::averageCluster(cluster &clu) if (phi < phiMin) phiMin = phi; if (DEBUG_AVERAGE) cp.printHit(**p); - av.addTot(first->getTot()); // sum ToT for pixel clusters + av.addTot(first.getTot()); // sum ToT for pixel clusters } av.setEtaWidth(etaMax-etaMin+1); av.setPhiWidth(phiMax-phiMin+1); @@ -846,151 +818,149 @@ void FTKClusteringEngine::atlClusteringBlayer(vector &hits) { } +void FTKClusteringEngine::realisticIBLDecoder(hitVector ¤tHits) +{ + +} -void FTKClusteringEngine::realisticPixelDecoder(hitVector* ¤tHits) +void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) { - hitVector::iterator hit = currentHits->begin(); + hitVector::iterator hit = currentHits.begin(); - std::stack lifo; - std::queue fifo; + std::stack> lifo; + std::queue> fifo; if((*hit)->getIsPixel()){ - if (currentHits->size() > 1) - std::stable_sort(currentHits->begin(), currentHits->end(), sortbyFE); - - for(hit = currentHits->begin(); hit != currentHits->end(); hit++) { - if ((*hit)->getPhiSide() <= 163) - fifo.push(*hit); - else lifo.push(*hit); + if (currentHits.size() > 1) + std::stable_sort(currentHits.begin(), currentHits.end(), sortPixelInput); + + for(auto& hit: currentHits) { + if ((*hit).getPhiSide() < ftk::clustering::rowsInFEChipPerPixelModuleRow) + fifo.push( std::move(hit) ); + else + lifo.push( std::move(hit) ); } - currentHits->clear(); + currentHits.clear(); while(!lifo.empty() && !fifo.empty()){ if ((*lifo.top()).getEtaStrip() <= (*fifo.front()).getEtaStrip()) { - currentHits->push_back(lifo.top()); - lifo.pop(); + currentHits.push_back( std::move(lifo.top()) ); } else { - currentHits->push_back(fifo.front()); - fifo.pop(); + currentHits.push_back( std::move(fifo.front()) ); } } while(!lifo.empty()) { - currentHits->push_back(lifo.top()); - lifo.pop(); + currentHits.push_back( std::move(lifo.top()) ); } while(!fifo.empty()) { - currentHits->push_back(fifo.front()); - fifo.pop(); + currentHits.push_back( std::move(fifo.front()) ); } }else{ - std::stack lifo_planar; - std::queue fifo_planar; - - if (currentHits->size() > 1) - std::stable_sort(currentHits->begin(), currentHits->end(), sortInput); - - for(hit = currentHits->begin(); hit != currentHits->end(); hit++) { - if ((*hit)->getEtaStrip() < 40) - fifo.push(*hit); - else if ((*hit)->getEtaStrip() >= 40 && (*hit)->getEtaStrip() < 80) - lifo.push(*hit); - else if ((*hit)->getEtaStrip() >= 80 && (*hit)->getEtaStrip() < 120) - fifo_planar.push(*hit); - else if ((*hit)->getEtaStrip() >= 120 && (*hit)->getEtaStrip() < 160) - lifo_planar.push(*hit); - } + std::stack> lifo_planar; + std::queue> fifo_planar; + + if (currentHits.size() > 1) + std::stable_sort(currentHits.begin(), currentHits.end(), sortIBLInput); + + for(auto& hit: currentHits) { + if ((*hit).getEtaStrip() < ftk::clustering::colsInFEChipPerIblModuleRow/2) + fifo.push(std::move(hit)); + else if ((*hit).getEtaStrip() >= ftk::clustering::colsInFEChipPerIblModuleRow/2 + && (*hit).getEtaStrip() < ftk::clustering::colsInFEChipPerIblModuleRow) + lifo.push(std::move(hit)); + else if ((*hit).getEtaStrip() >= ftk::clustering::colsInFEChipPerIblModuleRow + && (*hit).getEtaStrip() < ftk::clustering::colsInFEChipPerIblModuleRow * 3/2) + fifo_planar.push(std::move(hit)); + else if ((*hit).getEtaStrip() >= ftk::clustering::colsInFEChipPerIblModuleRow * 3/2 + && (*hit).getEtaStrip() < 2 * ftk::clustering::colsInFEChipPerIblModuleRow) + lifo_planar.push(std::move(hit)); + } - currentHits->clear(); + currentHits.clear(); while(!fifo.empty()){ - currentHits->push_back(fifo.front()); - fifo.pop(); + currentHits.push_back( std::move(fifo.front()) ); } while(!lifo.empty()) { - currentHits->push_back(lifo.top()); - lifo.pop(); + currentHits.push_back(std::move (lifo.top()) ); } while(!fifo_planar.empty()) { - currentHits->push_back(fifo_planar.front()); - fifo_planar.pop(); + currentHits.push_back(std::move(fifo_planar.front()) ); } while(!lifo_planar.empty()) { - currentHits->push_back(lifo_planar.top()); - lifo_planar.pop(); + currentHits.push_back(std::move(lifo_planar.top()) ); } } - - // std::cout << "GOING TO DECODER" << std::endl; - // cp.printDecoderOutput(currentHits); } -FTKRawHit* FTKClusteringEngine::gridAUTH( boost::circular_buffer &cb, hitVector &fifo, hitVector &gridhits) +FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer> &cb, + hitVector &fifo, hitVector &gridhits) { - //seed is set from cb if there are hits and from - //fifo if the seed is empty. - FTKRawHit* seed = fifo.front(); - bool isIBLmodule = hitOnIBLmodule(*seed); - if (cb.size() != 0) { - boost::circular_buffer::iterator cbi = cb.begin(); - seed = *cbi; - for( cbi = cb.begin(); cbi != cb.end(); cbi++){ - if ((*cbi)->getEtaStrip() < seed->getEtaStrip()) - seed = *cbi; - else if ((*cbi)->getEtaStrip() == seed->getEtaStrip()) { - //if ((*cbi)->getPhiSide() < seed->getPhiSide()) - if ((*cbi)->getPhiSide() < seed->getPhiSide() && !isIBLmodule) //Keisuke 20170215 - seed = *cbi; - else if ((*cbi)->getPhiSide() > seed->getPhiSide() && isIBLmodule) - seed = *cbi; + // //seed is set from cb if there are hits and from + // //fifo if the seed is empty. + std::unique_ptr seed; + bool isIBLmodule = hitOnIBLmodule(*(seed.get())); + if (cb.size() == 0) + seed = std::move(fifo.front()); + else if (cb.size() != 0) { + seed = std::move(cb.front()); + for(auto& cbi: cb) { + if ((*cbi).getEtaStrip() < (*seed).getEtaStrip()) + seed.swap(cbi); + else if ((*cbi).getEtaStrip() == (*seed).getEtaStrip()) { + if ((*cbi).getPhiSide() < (*seed).getPhiSide() && !isIBLmodule) //Keisuke 20170215 + seed.swap(cbi); + else if ((*cbi).getPhiSide() > (*seed).getPhiSide() && isIBLmodule) + seed.swap(cbi); } } } - //step 2: set grid window limits + // //step 2: set grid window limits int gridStrCol ; - if (seed->getEtaStrip() % 2 != 0) gridStrCol = seed->getEtaStrip() - 1; - else gridStrCol = seed->getEtaStrip(); - int gridCntRow = seed->getPhiSide(); + if ((*seed).getEtaStrip() % 2 != 0) + gridStrCol = (*seed).getEtaStrip() - 1; + else + gridStrCol = (*seed).getEtaStrip(); + int gridCntRow = (*seed).getPhiSide(); - //step 3: put hits from cb to the grid window + // //step 3: put hits from cb to the grid window int dist = distance(cb.begin(), cb.end()); for(int i = 0; i < dist; i++) { - FTKRawHit* h = cb.front(); - if (!hitColInGrid(gridStrCol, h)) { + // FTKRawHit* h = cb.front(); + if (!hitColInGrid(gridStrCol, cb.front())) { cb.pop_front(); continue; } - if (hitRowInGrid(gridCntRow, h)) - gridhits.push_back(h); + if (hitRowInGrid(gridCntRow, cb.front())) + gridhits.push_back(std::move(cb.front())); else - cb.push_back(h); - cb.pop_front(); + cb.push_back(std::move(cb.front())); + // cb.pop_front(); } //step 4: put hits from fifo to the grid window - hitVector::iterator fifo_it = fifo.begin(); - while (fifo_it != fifo.end()) { - FTKRawHit* hit = *fifo_it; + for (auto& hit: fifo) { if (!hitColInGrid(gridStrCol, hit)) break; if (hitRowInGrid(gridCntRow, hit)) - gridhits.push_back(hit); + gridhits.push_back(std::move(hit)); else - cb.push_back(hit); - fifo.erase(fifo_it); + cb.push_back(std::move(hit)); } - return seed; + return *seed.get(); } + /*! * Function responsible for hit clustering and the subsequent centroid * calculation @@ -1000,143 +970,128 @@ FTKRawHit* FTKClusteringEngine::gridAUTH( boost::circular_buffer &cb void FTKClusteringEngine::atlClusteringLNF(vector &hits) { /* - * make clusters in every module + * Step 1: Organize the hits by the module they belong to. Furthermore, the + * ganged hits are duplicated, if requested. The copy constructor is used, + * instead of manually assigning each variable. */ hitsByModuleMap hitsByModule; ///< store hits by module - - // Temporary storage for duplicate copy of ganged pixels - // Automatically deleted at the end of this function - std::vector gangedPixelList; + std::vector gangedPixelList; ///< vector of ganged pixels gangedPixelList.reserve(hits.size()); // reserve memory in excess - /* - * First: organize raw hits by module - */ - for(unsigned int i = 0; i < hits.size(); i++) { - int modId = hitToModuleId(hits[i]); + for(const auto& hit: hits) { + int modId = hitToModuleId(hit); if (modId<0) assert(0); - hitsByModule[modId].push_back( &(hits[i]) ); - if (duplicateGanged && hitIsGanged(hits[i])) { - //use the copy constructor instead of manually assigning each - //variable, as was done previously. the usage here is the - //whole point of having a copy constructor! - gangedPixelList.push_back( hits[i] ); - FTKRawHit &lastPointer = gangedPixelList.back(); - lastPointer.setPhiSide(gangedPartner( hits[i] )); - hitsByModule[modId].push_back( &lastPointer ); + hitsByModule[modId].push_back( std::make_unique(hit) ); + if (duplicateGanged && hitIsGanged(hit)) { + gangedPixelList.push_back( hit ); + FTKRawHit& lastPointer = gangedPixelList.back(); + lastPointer.setPhiSide(gangedPartner( hit )); + hitsByModule[modId].push_back( std::make_unique(lastPointer) ); } } + /* - * Second: build the list of clusters + * Step 2: build the list of clusters. + * The ideal clustering is going to be used in the following cases: + * 1. pixelClusteringMode is less than 100 (PIXEL_CLUSTERING_MIXED) + * 2. The module is not a pixel module */ clustersByModuleMap clustersByModule; ///< store clusters by module - hitsByModuleMap::iterator p; for (auto& module: hitsByModule) { // loop over modules - hitVector *currentHits = & (module.second); - FTKRawHit &firstHit = **(currentHits->begin()); int modId = module.first; + hitVector currentHits = std::move (module.second); + FTKRawHit* firstHit = (module.second.front()).get(); - cluList *currentClusters = new cluList(); // instantiate cluster list - clustersByModule[modId] = currentClusters; + cluList currentClusters; // instantiate cluster list - //The ideal clustering is going to be used in the following cases: - //1. pixelClusteringMode is less than 100 (PIXEL_CLUSTERING_MIXED) - //2. The module is not a pixel module - if (pixelClusteringMode < PIXEL_CLUSTERING_MIXED || firstHit.getIsSCT()) { + if (firstHit->getIsSCT()){ makeClustersLNF(currentHits, currentClusters); // use ideal clustering - } - else { // pixelClusteringMode >= 100 and pixel module - realisticPixelDecoder(currentHits); - - boost::circular_buffer circular_buffer (256); - hitVector gridhits; - hitVector fifo = *currentHits; - while (!fifo.empty() || !circular_buffer.empty()) { - FTKRawHit* seed = gridAUTH(circular_buffer, fifo, gridhits); - makeClusterFromSeed(&gridhits, currentClusters, seed); - - for(hitVector::iterator hsi = gridhits.begin(); hsi != gridhits.end(); hsi++) { - circular_buffer.push_back(*hsi); - } - gridhits.clear(); - } } - } // end of loop over modules - -#if defined(CLUSTERING_PRINTOUT) - cp.printClusterList(clustersByModule); -#endif - - /* - * Third: take the "average" of each cluster - */ - int nTotClu = 0; - clustersByModuleMap::iterator cluModP; // loop over modules - for (cluModP=clustersByModule.begin(); cluModP!=clustersByModule.end(); cluModP++) { - hitVector connectedHits; // list of ganged hits that are connected to a confirmed ganged hit - cluList::iterator cluP; - for (cluP=cluModP->second->begin(); cluP!=cluModP->second->end(); cluP++) { - // do pattern recognition in the ganged region - if ( (*cluP->hitlist.begin())->getIsPixel() && findConnectedGanged(*cluP, connectedHits) ) // set isSafe - cluP->isSafe = true; - } - - for (cluP=cluModP->second->begin(); cluP!=cluModP->second->end(); cluP++) { - if ( (*cluP->hitlist.begin())->getIsPixel() && isKilled(*cluP, connectedHits) ) // set isKilled - cluP->isKilled = true; - averageCluster(*cluP); // use floating-point average - nTotClu++; // count all clusters - } - - // delete connected hits - hitVector::iterator connectedP; - for (connectedP = connectedHits.begin(); connectedP!=connectedHits.end(); ++connectedP) { - delete *connectedP; - } - } - - - -#if defined(CENTROID_PRINTOUT) - cp.printCentroidList(clustersByModule); -#endif - - /* - * Fourth: put clusters/hits back in the event hit list - */ - hits.clear(); - - int hitCounter=0; - int deletedGangedClusters=0; - for (auto& cluModP: clustersByModule) { - cluList::iterator cluP; - for (cluP=cluModP.second->begin(); cluP!=cluModP.second->end(); cluP++) { - // kill clusters with ganged hits according to ganged pattern recognition - if ( gangedPatternRecognition && cluP->isKilled && !cluP->isSafe ) { - // AA 2009-07-07 removing the "isSafe" protection does not change - // number of combinations to fit for single muon events - deletedGangedClusters++; - continue; + else if(firstHit->getIsPixel()) { + //First, perform the clustering + if (pixelClusteringMode < PIXEL_CLUSTERING_MIXED) { + makeClustersLNF(currentHits, currentClusters); + } + else if (pixelClusteringMode >= PIXEL_CLUSTERING_MIXED) { + realisticPixelDecoder(currentHits); + makeClustersGridWindow(currentHits, currentClusters); } - // store hit by value - FTKRawHit cluEquiv = (*cluP).clusterEquiv; - hits.push_back(cluEquiv); - ++hitCounter; } - delete cluModP.second; + + clustersByModule[modId] = std::move( currentClusters ) ; } - assert( (hitCounter+deletedGangedClusters) == nTotClu ); /* - * Fifth: free memory (could optimize and do this in previous step) + * Third: take the "average" of each cluster */ - - // The atlhit data from event is allocated and destroyed outside this function. - // clustersByModuleMap is automatically deleted. - clustersByModule.clear(); +// int nTotClu = 0; +// clustersByModuleMap::iterator cluModP; // loop over modules +// for (cluModP=clustersByModule.begin(); cluModP!=clustersByModule.end(); cluModP++) { +// hitVector connectedHits; // list of ganged hits that are connected to a confirmed ganged hit +// cluList::iterator cluP; +// for (cluP=cluModP->second->begin(); cluP!=cluModP->second->end(); cluP++) { +// // do pattern recognition in the ganged region +// if ( (*cluP->hitlist.begin())->getIsPixel() && findConnectedGanged(*cluP, connectedHits) ) // set isSafe +// cluP->isSafe = true; +// } + +// for (cluP=cluModP->second->begin(); cluP!=cluModP->second->end(); cluP++) { +// if ( (*cluP->hitlist.begin())->getIsPixel() && isKilled(*cluP, connectedHits) ) // set isKilled +// cluP->isKilled = true; +// averageCluster(*cluP); // use floating-point average +// nTotClu++; // count all clusters +// } + +// // delete connected hits +// // hitVector::iterator connectedP; +// // for (connectedP = connectedHits.begin(); connectedP!=connectedHits.end(); ++connectedP) { +// // delete (*connectedP; +// // } +// } + + + +// #if defined(CENTROID_PRINTOUT) +// cp.printCentroidList(clustersByModule); +// #endif + +// /* +// * Fourth: put clusters/hits back in the event hit list +// */ +// hits.clear(); + +// int hitCounter=0; +// int deletedGangedClusters=0; +// for (auto& cluModP: clustersByModule) { +// cluList::iterator cluP; +// for (cluP=cluModP.second->begin(); cluP!=cluModP.second->end(); cluP++) { +// // kill clusters with ganged hits according to ganged pattern recognition +// if ( gangedPatternRecognition && cluP->isKilled && !cluP->isSafe ) { +// // AA 2009-07-07 removing the "isSafe" protection does not change +// // number of combinations to fit for single muon events +// deletedGangedClusters++; +// continue; +// } + +// // store hit by value +// FTKRawHit cluEquiv = (*cluP).clusterEquiv; +// hits.push_back(cluEquiv); +// ++hitCounter; +// } +// delete cluModP.second; +// } +// assert( (hitCounter+deletedGangedClusters) == nTotClu ); + +// /* +// * Fifth: free memory (could optimize and do this in previous step) +// */ + +// // The atlhit data from event is allocated and destroyed outside this function. +// // clustersByModuleMap is automatically deleted. +// clustersByModule.clear(); } /*! @@ -1201,7 +1156,7 @@ int FTKClusteringEngine::gangedPartner(const FTKRawHit &hit) { } double FTKClusteringEngine::getDeltaX1A(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); + std::unique_ptr first = std::move(*(clu.hitlist.begin())); bool isIBLmodule = hitOnIBLmodule(*first); float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; /// first = std::move(*(clu.hitlist.begin())); bool isIBLmodule = hitOnIBLmodule(*first); float sensorThickness = ftk::sensorThicknessPixel; float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; @@ -1222,7 +1177,7 @@ double FTKClusteringEngine::getDeltaX2A(cluster &clu){ return lround(32*(30*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)); } int FTKClusteringEngine::getDeltaXEC1A(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); + std::unique_ptr first = std::move(*(clu.hitlist.begin())); bool isIBLmodule = hitOnIBLmodule(*first); float sensorThickness = ftk::sensorThicknessPixel; float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; @@ -1232,7 +1187,7 @@ int FTKClusteringEngine::getDeltaXEC1A(cluster &clu){ return lround(- (32*32*(10*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)/2.)); } int FTKClusteringEngine::getDeltaXEC2A(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); + std::unique_ptr first = std::move(*(clu.hitlist.begin())); bool isIBLmodule = hitOnIBLmodule(*first); float sensorThickness = ftk::sensorThicknessPixel; float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; @@ -1242,7 +1197,7 @@ int FTKClusteringEngine::getDeltaXEC2A(cluster &clu){ return lround(32*(10*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)); } int FTKClusteringEngine::getDeltaYEC1A(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); + std::unique_ptr first = std::move(*(clu.hitlist.begin())); bool isIBLmodule = hitOnIBLmodule(*first); float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; @@ -1254,7 +1209,7 @@ int FTKClusteringEngine::getDeltaYEC1A(cluster &clu){ return lround(- (32*32*(10*ftk::micrometer*pixYScaleFactor*(sensorThickness/(250*ftk::micrometer))/etaPitch)/2.)); } int FTKClusteringEngine::getDeltaYEC2A(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); + std::unique_ptr first = std::move(*(clu.hitlist.begin())); bool isIBLmodule = hitOnIBLmodule(*first); float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; @@ -1266,7 +1221,7 @@ int FTKClusteringEngine::getDeltaYEC2A(cluster &clu){ return lround(32*(10*ftk::micrometer*pixYScaleFactor*(sensorThickness/(250*ftk::micrometer))/etaPitch)); } int FTKClusteringEngine::getDeltaY1A(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); + std::unique_ptr first = std::move(*(clu.hitlist.begin())); int layer = first->getLayer(); bool isIBLmodule = hitOnIBLmodule(*first); if (FTKSetup::getFTKSetup().getIBLMode()==0) @@ -1288,7 +1243,7 @@ int FTKClusteringEngine::getDeltaY1A(cluster &clu){ return lround ( - 32*32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch/2. ) + lround( 32*32*2* pixYScaleFactor*sensorThickness*moduleActiveLength/radius /etaPitch/2/2); } int FTKClusteringEngine::getDeltaY2A(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); + std::unique_ptr first = std::move(*(clu.hitlist.begin())); int layer = first->getLayer(); bool isIBLmodule = hitOnIBLmodule(*first); if (FTKSetup::getFTKSetup().getIBLMode()==0) @@ -1310,7 +1265,7 @@ int FTKClusteringEngine::getDeltaY2A(cluster &clu){ } int FTKClusteringEngine::getDeltaY1B(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); + std::unique_ptr first = std::move(*(clu.hitlist.begin())); int layer = first->getLayer(); bool isIBLmodule = hitOnIBLmodule(*first); if (FTKSetup::getFTKSetup().getIBLMode()==0) @@ -1331,7 +1286,7 @@ int FTKClusteringEngine::getDeltaY1B(cluster &clu){ int FTKClusteringEngine::getDeltaY2B(cluster &clu){ - FTKRawHit *first = *(clu.hitlist.begin()); + std::unique_ptr first = std::move(*(clu.hitlist.begin())); int layer = first->getLayer(); bool isIBLmodule = hitOnIBLmodule(*first); if (FTKSetup::getFTKSetup().getIBLMode()==0) diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx index 8570e44284a..e5b833e65e4 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx @@ -38,9 +38,6 @@ void printHit(const FTKRawHit &hit) << " n_strips=" << hit.getNStrips() << " deltaPhi=" << hit.getDeltaPhi() << " deltaEta=" << hit.getDeltaEta() - << " ( x=" << hit.getX() - << " y=" << hit.getY() - << " z=" << hit.getZ() << " eventindex=" << hit.getEventIndex() << " barcode=" << hit.getBarcode() << " bar_pt=" << hit.getBarcodePt() @@ -60,105 +57,104 @@ bool clusterSort (const FTK_ClusterCoordHit &i, const FTK_ClusterCoordHit &j) return i.ccol <= j.ccol; } -void printClu(const cluster &clu) +void FTKClusteringPrintout::printClu(const cluster &clu) { - hitVector hs = clu.hitlist; - hitVector::iterator hit = hs.begin(); - - std::vector tmp; - for (hit = hs.begin(); hit != hs.end(); hit++) { - tmp.push_back(FTK_ClusterCoordHit(**hit, clu.seed)); - } - - //sort and print the vector. - if (tmp.size() > 1) std::stable_sort(tmp.begin(), tmp.end(), clusterSort); - - for(std::vector::iterator hit1 = tmp.begin(); hit1 != tmp.end(); hit1++) { - printf("0000%.2X%.2X%.3X\n",(*hit1).tot, (*hit1).ccol, (*hit1).crow); - //printf("0000%.2X%.2X%.3X",(*hit1).tot, (*hit1).ccol, (*hit1).crow); - //printf(" tot: %d col: %d row: %d\n",(*hit1).tot, (*hit1).ccol, (*hit1).crow); - } - - //TO ENABLE AGAIN! - int boundary = 2; - // if (isSplitCluster(clu)) - // boundary = 3; - - if (clu.seed->getEtaStrip() %2 != 0) { - printf("000%d00%.2X%.3X\n",boundary, clu.seed->getEtaStrip() - 1, clu.seed->getPhiSide()); - - //printf("000%d00%.2X%.3X",boundary, clu.seed->getEtaStrip() - 1, clu.seed->getPhiSide()); - //printf(" split: %d col: %d row: %d\n",boundary, clu.seed->getEtaStrip() - 1, clu.seed->getPhiSide()); - } - else { - printf("000%d00%.2X%.3X\n",boundary, clu.seed->getEtaStrip(), clu.seed->getPhiSide()); - //printf("000%d00%.2X%.3X",boundary, clu.seed->getEtaStrip(), clu.seed->getPhiSide()); - //printf(" split: %d col: %d row: %d\n",boundary, clu.seed->getEtaStrip(), clu.seed->getPhiSide()); - } + // hitVector hs = clu.hitlist; + // hitVector::iterator hit = hs.begin(); + + // std::vector tmp; + // for (hit = hs.begin(); hit != hs.end(); hit++) { + // tmp.push_back(FTK_ClusterCoordHit(*hit, clu.seed)); + // } + + // //sort and print the vector. + // if (tmp.size() > 1) std::stable_sort(tmp.begin(), tmp.end(), clusterSort); + + // for(std::vector::iterator hit1 = tmp.begin(); hit1 != tmp.end(); hit1++) { + // // printf("0000%.2X%.2X%.3X\n",(*hit1).tot, (*hit1).ccol, (*hit1).crow); + // printf("0000%.2X%.2X%.3X",(*hit1).tot, (*hit1).ccol, (*hit1).crow); + // printf(" tot: %d col: %d row: %d\n",(*hit1).tot, (*hit1).ccol, (*hit1).crow); + // } + + // //TO ENABLE AGAIN! + // int boundary = 2; + // // if (isSplitCluster(clu)) + // // boundary = 3; + + // if (clu.seed.getEtaStrip() %2 != 0) { + // // printf("000%d00%.2X%.3X\n",boundary, clu.seed.getEtaStrip() - 1, clu.seed.getPhiSide()); + + // printf("000%d00%.2X%.3X",boundary, clu.seed.getEtaStrip() - 1, clu.seed.getPhiSide()); + // printf(" split: %d col: %d row: %d\n",boundary, clu.seed.getEtaStrip() - 1, clu.seed.getPhiSide()); + // } + // else { + // // printf("000%d00%.2X%.3X\n",boundary, clu.seed.getEtaStrip(), clu.seed.getPhiSide()); + // printf("000%d00%.2X%.3X",boundary, clu.seed.getEtaStrip(), clu.seed.getPhiSide()); + // printf(" split: %d col: %d row: %d\n",boundary, clu.seed.getEtaStrip(), clu.seed.getPhiSide()); + // } } void printClusterList(clustersByModuleMap clustersByModule) { - clustersByModuleMap::iterator p; - for (p = clustersByModule.begin(); p!=clustersByModule.end(); ++p) { // loop over modules - cluList* cl = (*p).second; - cluList::iterator b = cl->begin(); - FTKRawHit* hit = (*b).hitlist[0]; - printf("0x200000%02d\n", (*hit).getIdentifierHash()); - for (; b != cl->end(); b++) { - printClu(*b); - } - printf("0x40000000\n"); - } + // for (auto& cl: clustersByModule) { // loop over modules + // cluList cl = cl.second; + // cluList::iterator b = cl.begin(); + // FTKRawHit* hit = (*b).hitlist[0]; + // printf("0x200000%02d\n", (*hit).getIdentifierHash()); + // for (; b != cl->end(); b++) { + // printClu(*b); + // } + // printf("0x40000000\n"); + // } } void printCentroidList(clustersByModuleMap clustersByModule) { - clustersByModuleMap::iterator p; - for (p = clustersByModule.begin(); p!=clustersByModule.end(); ++p) { // loop over modules - cluList* cl = (*p).second; - cluList::iterator b = cl->begin(); - FTKRawHit* hit = (*b).hitlist[0]; - - bool isIBLmodule = ((*hit).getModuleType() == ftk::MODULETYPE_IBL3D || (*hit).getModuleType() == ftk::MODULETYPE_IBL_PLANAR); - int idHash = hit->getIdentifierHash(); - - if(isIBLmodule){// for IBL - bool FE0_exist = false; - bool FE1_exist = false; - - if(hit->getEtaStrip() < 80){ - FE0_exist = true; - - b = cl->end() - 1; - int nhit_inCluster = (*b).hitlist.size(); - hit = (*b).hitlist[nhit_inCluster-1]; - if(hit->getEtaStrip() >= 80) - FE1_exist = true; - }else{ - FE1_exist = true; - } - - b = cl->begin(); - hit = (*b).hitlist[0]; - - if(FE1_exist == false && FE0_exist == true) - printf("0x08%.7x\n", idHash); - else - printf("0x08%.7x\n", idHash-1); - } else { - printf("0x8%.7x\n", hit->getIdentifierHash()); - } - for (; b != cl->end(); b++) { - printf("0x%.8X ",(*b).clusterEquiv.getHWWord()); - //std::cout << (*b).clusterEquiv.getTot() << " " - // << (*b).clusterEquiv.getEtaStrip() << " " - // << (*b).clusterEquiv.getPhiSide() << std::endl; - if (DEBUG_CENTROID) printHit(*hit); - } - printf("0x40000000\n"); - } + // clustersByModuleMap::iterator p; + // for (p = clustersByModule.begin(); p!=clustersByModule.end(); ++p) { // loop over modules + // cluList* cl = (*p).second; + // cluList::iterator b = cl->begin(); + // FTKRawHit* hit = (*b).hitlist[0]; + + // bool isIBLmodule = ((*hit).getModuleType() == ftk::MODULETYPE_IBL3D || (*hit).getModuleType() == ftk::MODULETYPE_IBL_PLANAR); + // int idHash = hit->getIdentifierHash(); + + // if(isIBLmodule){// for IBL + // bool FE0_exist = false; + // bool FE1_exist = false; + + // if(hit->getEtaStrip() < 80){ + // FE0_exist = true; + + // b = cl->end() - 1; + // int nhit_inCluster = (*b).hitlist.size(); + // hit = (*b).hitlist[nhit_inCluster-1]; + // if(hit->getEtaStrip() >= 80) + // FE1_exist = true; + // }else{ + // FE1_exist = true; + // } + + // b = cl->begin(); + // hit = (*b).hitlist[0]; + + // if(FE1_exist == false && FE0_exist == true) + // printf("0x08%.7x\n", idHash); + // else + // printf("0x08%.7x\n", idHash-1); + // } else { + // printf("0x8%.7x\n", hit->getIdentifierHash()); + // } + // for (; b != cl->end(); b++) { + // printf("0x%.8X ",(*b).clusterEquiv.getHWWord()); + // //std::cout << (*b).clusterEquiv.getTot() << " " + // // << (*b).clusterEquiv.getEtaStrip() << " " + // // << (*b).clusterEquiv.getPhiSide() << std::endl; + // if (DEBUG_CENTROID) printHit(*hit); + // } + // printf("0x40000000\n"); + // } } bool sortWords(const FTKRawHit* i, const FTKRawHit* j) @@ -173,111 +169,74 @@ bool sortWords(const FTKRawHit* i, const FTKRawHit* j) } -void printDecoderOutput(hitVector* currentHits) +void FTKClusteringPrintout::printDecoderOutput(const hitVector& currentHits) { - hitVector::iterator hit = currentHits->begin(); - hitVector *sortHits = currentHits; - int idHash = (**hit).getIdentifierHash(); - bool isIBLmodule = ((**hit).getModuleType() == ftk::MODULETYPE_IBL3D || (**hit).getModuleType() == ftk::MODULETYPE_IBL_PLANAR); - - if(isIBLmodule){ // Keisuke 20170215 - stable_sort(sortHits->begin(), sortHits->end(), sortWords); - idHash = (**sortHits->begin()).getIdentifierHash(); - } - - std::cout << "Found in Decoder" << std::hex << idHash << std::dec <begin(), sortHits->end(), sortWords); - - for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ - int tempCol = (*it)->getEtaStrip(); - // if(tempCol >= 80) tempCol = tempCol - 80; // Yoshi 2016.11.18 - int tempRow = 335 - (*it)->getPhiSide(); // Keisuke 20170314, start from 0 - int tempTot = (*it)->getTot(); - int outputData = ( (tempTot << 20) | (tempCol << 12) | tempRow ); - printf("0x0%.7X",outputData); - - if(!DEBUG_DECODER) std::cout << std::endl; - else{ - std::cout << " IBL HIT" - << " col: " << std::setfill('0') << std::setw(3) << tempCol - << " row: " << std::setfill('0') << std::setw(3) << tempRow - << " tot: " << std::setfill('0') << std::setw(2) << tempTot - << std::endl; - } - } - - }else{ // for Pixel - printf("0x8%.7x\n", (**hit).getIdentifierHash()); - for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { - printf("0x0%.2X%.2X%.3X",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); - if(!DEBUG_DECODER) std::cout << std::endl; - else{ - std::cout << " Pixel HIT" - << " col: " << (*hit)->getEtaStrip() - << " row: " << (*hit)->getPhiSide() - << " tot: " << (*hit)->getTot() - << std::endl; - } - - } //hit loop - printf("0x40000000\n"); - } + // hitVector::iterator hit = currentHits->begin(); + // hitVector *sortHits = currentHits; + // int idHash = (*hit).getIdentifierHash(); + // bool isIBLmodule = ((**hit).getModuleType() == ftk::MODULETYPE_IBL3D || (**hit).getModuleType() == ftk::MODULETYPE_IBL_PLANAR); + + // if(isIBLmodule){ // Keisuke 20170215 + // stable_sort(sortHits->begin(), sortHits->end(), sortWords); + // idHash = (*sortHits->begin()).getIdentifierHash(); + // } + + // std::cout << "Found in Decoder" << std::hex << idHash << std::dec <begin(), sortHits->end(), sortWords); + + // for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ + // int tempCol = (*it)->getEtaStrip(); + // // if(tempCol >= 80) tempCol = tempCol - 80; // Yoshi 2016.11.18 + // int tempRow = 335 - (*it)->getPhiSide(); // Keisuke 20170314, start from 0 + // int tempTot = (*it)->getTot(); + // int outputData = ( (tempTot << 20) | (tempCol << 12) | tempRow ); + // printf("0x0%.7X",outputData); + + // if(!DEBUG_DECODER) std::cout << std::endl; + // else{ + // std::cout << " IBL HIT" + // << " col: " << std::setfill('0') << std::setw(3) << tempCol + // << " row: " << std::setfill('0') << std::setw(3) << tempRow + // << " tot: " << std::setfill('0') << std::setw(2) << tempTot + // << std::endl; + // } + // } + + // }else{ // for Pixel + // printf("0x8%.7x\n", (**hit).getIdentifierHash()); + // for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { + // printf("0x0%.2X%.2X%.3X",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); + // if(!DEBUG_DECODER) std::cout << std::endl; + // else{ + // std::cout << " Pixel HIT" + // << " col: " << (*hit)->getEtaStrip() + // << " row: " << (*hit)->getPhiSide() + // << " tot: " << (*hit)->getTot() + // << std::endl; + // } + + // } //hit loop + // printf("0x40000000\n"); + // } } -void printInputData(hitVector* currentHits) +void FTKClusteringPrintout::printInputData(const hitVector& currentHits) { - hitVector::iterator hit = currentHits->begin(); - bool isIBLmodule = ((**hit).getModuleType() == ftk::MODULETYPE_IBL3D || (**hit).getModuleType() == ftk::MODULETYPE_IBL_PLANAR); - hitVector *sortHits = currentHits; - int idHash = (**hit).getIdentifierHash() + 8; - if(DEBUG_INPUT) printHit(**hit); - - if(isIBLmodule){ // for IBL - idHash = (**sortHits->begin()).getIdentifierHash() + 8; - printf("0x03%.1x000000\n", idHash); - - for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ - int tempCol = (*it)->getEtaStrip() + 1; - if((idHash == 0x8 || idHash == 0xa) && tempCol <= 80){ - printf("0x05%.1x400000\n", idHash); - idHash = idHash + 1; - printf("0x03%.1x000000\n", idHash); - } - if(tempCol >= 81) tempCol = tempCol - 80; // for generate real input - int tempRow = 335 - (*it)->getPhiSide(); // Keisuke 20170314, start from 0 - int tempTot = (*it)->getTot(); - int outputData = ((idHash << 24) | (tempTot << 20) | (tempCol << 9) | tempRow ); - printf("0x09%.7x",outputData); - - if(!DEBUG_INPUT) std::cout << std::endl; - else{ - std::cout << " IBL HIT" - << " col: " << std::setfill('0') << std::setw(3) << tempCol - << " row: " << std::setfill('0') << std::setw(3) << tempRow - << " tot: " << std::setfill('0') << std::setw(2) << tempTot - << std::endl; - } - } - - }else{ // for Pixel - - printf("0x08%.7x\n", idHash); - - for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { - printf("0x00%.2x%.2x%.3x ",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); - - if(!DEBUG_DECODER) std::cout << std::endl; - else{ - std::cout << " Pixel HIT" - << " col: " << (*hit)->getEtaStrip() - << " row: " << (*hit)->getPhiSide() - << " tot: " << (*hit)->getTot() - << std::endl; - } - } - } // hit loop - - printf("0x05%.1x400000\n", idHash); + // FTKRawHit h = currentHits.front(); + // bool isIBLmodule = (h.getModuleType() == ftk::MODULETYPE_IBL3D || h.getModuleType() == ftk::MODULETYPE_IBL_PLANAR); + // hitVector sortHits = currentHits; + // int idHash = h.getIdentifierHash() + 8; + + // printf("0x08%.7x MODULE\n", idHash); + + // for(const auto& hit: currentHits) { + // printf("0x00%.2x%.2x%.3x ",hit.getTot(), hit.getEtaStrip(), hit.getPhiSide()); + // std::cout << " Pixel HIT" + // << " col: " << hit.getEtaStrip() + // << " row: " << hit.getPhiSide() + // << " tot: " << hit.getTot() + // << std::endl; + // } } -- GitLab From 72f172daeb84e6402d9347f8b04976a3269ad453 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Mon, 11 Mar 2019 18:26:01 +0100 Subject: [PATCH 10/18] Code compiles; segfaults up to averageCluster fixed --- .../TrigFTKSim/FTKClusteringEngine.h | 32 +- .../TrigFTKSim/src/FTKClusteringEngine.cxx | 586 ++++++++++-------- .../TrigFTKSim/src/FTKClusteringPrintout.cxx | 29 +- 3 files changed, 344 insertions(+), 303 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h index aa7e9a047c8..26b27bf1031 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h @@ -137,39 +137,37 @@ private: static bool sortPixelInput (const std::unique_ptr& i, const std::unique_ptr& j); static bool sortIBLInput(const std::unique_ptr& i, const std::unique_ptr& j); - bool isSplitCluster(const cluster& clu); + bool isSplitCluster(const std::unique_ptr& clu); bool hitOnIBLmodule(const FTKRawHit &hit); int hitToModuleId(const FTKRawHit &hit); void realisticPixelDecoder(hitVector& currentHits); - void realisticIBLDecoder(hitVector& currentHits); - bool neighborhood(const FTKRawHit &hit1, const FTKRawHit &hit2); int buildUpCluster(hitVector& currentHits, cluster& clu); void makeClustersLNF(hitVector& currentHits, cluList& currentClusters); void makeClustersGridWindow(hitVector& currentHits, cluList& currentClusters); void makeClusterFromSeed(hitVector& currentHits, cluList& currentClusters, FTKRawHit& seed); - void averageCluster(cluster &clu); + void averageCluster(std::unique_ptr& clu); bool pixelRowIsGanged(const int row); int gangedPartner(const FTKRawHit &); int hitIsGanged(const FTKRawHit &); - bool gangedHitHasNeighborhood(const FTKRawHit &hit, const cluster &clu, hitVector &connectedHits); - bool findConnectedGanged(cluster &clu, hitVector &connectedHits); - bool isKilled(const cluster &clu, const hitVector &connectedHits); + bool gangedHitHasNeighborhood(const FTKRawHit &hit, const std::unique_ptr &clu, hitVector &connectedHits); + bool findConnectedGanged(const std::unique_ptr &clu, hitVector &connectedHits); + bool isKilled(const std::unique_ptr &clu, const hitVector &connectedHits); FTKRawHit gridAUTH( boost::circular_buffer> &cb, hitVector &fifo, hitVector &gridhits); - double getDeltaX1A(cluster &); - double getDeltaX2A(cluster &); - int getDeltaXEC1A(cluster &); - int getDeltaXEC2A(cluster &); - int getDeltaYEC1A(cluster &); - int getDeltaYEC2A(cluster &); - int getDeltaY1A(cluster &); - int getDeltaY2A(cluster &); - int getDeltaY1B(cluster &); - int getDeltaY2B(cluster &); + double getDeltaX1A(const std::unique_ptr& clu); + double getDeltaX2A(const std::unique_ptr& clu); + int getDeltaXEC1A(const std::unique_ptr& clu); + int getDeltaXEC2A(const std::unique_ptr& clu); + int getDeltaYEC1A(const std::unique_ptr& clu); + int getDeltaYEC2A(const std::unique_ptr& clu); + int getDeltaY1A(const std::unique_ptr& clu); + int getDeltaY2A(const std::unique_ptr& clu); + int getDeltaY1B(const std::unique_ptr& clu); + int getDeltaY2B(const std::unique_ptr& clu); public: FTKClusteringEngine(); diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx index 622f55bb976..57774e5f042 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx @@ -17,17 +17,13 @@ using namespace std; -//#define DEBUG_HITS //#define DECODER_INPUT 0 #define DECODER_OUTPUT 0 //#define CLUSTERING_PRINTOUT 0 //#define CENTROID_PRINTOUT 0 //#define BOUNDING_BOX -const bool DEBUG_HITS = 0; const bool DEBUG_CLUSTERS = 0; -const bool DEBUG_AVERAGE = 0; -const bool DEBUG_AVERAGE_SCT = 0; const bool PRINT_INPUT = 0; // print input data const bool DEBUG_INPUT = 0; // detail check input @@ -40,6 +36,22 @@ cluster::~cluster() } +FTKClusteringEngine::FTKClusteringEngine(bool saveClusterContent, bool diagClustering, + bool sctClustering, bool ibl3DRealistic, + bool duplicateGanged, bool gangedPatternRecognition, + bool splitBlayerModules, int pixelClusteringMode) : + saveClusterContent(saveClusterContent), + diagClustering(diagClustering), + sctClustering(sctClustering), + ibl3DRealistic(ibl3DRealistic), + duplicateGanged(duplicateGanged), + gangedPatternRecognition(gangedPatternRecognition), + splitBlayerModules(splitBlayerModules), + pixelClusteringMode(pixelClusteringMode) +{ + +} + /*! Function which examines whether a hit belongs to an IBL module. * \param hit the hit * \return true if the hit is on an IBL module, false otherwide @@ -95,13 +107,12 @@ bool FTKClusteringEngine::sortIBLInput(const std::unique_ptr& i, cons * \param clu the cluster to be examined * \return true if the cluster is split, false otherwise */ -bool FTKClusteringEngine::isSplitCluster(const cluster& clu) +bool FTKClusteringEngine::isSplitCluster(const std::unique_ptr& clu) { - for (auto& hit: clu.hitlist) { + for (auto& hit: clu->hitlist) { // if (clu.seed == NULL) // return false; - FTKRawHit h = clu.seed; - FTK_ClusterCoordHit chit = FTK_ClusterCoordHit(*hit , h); + FTK_ClusterCoordHit chit = FTK_ClusterCoordHit(*hit , clu->seed); if ((chit.ccol >= GRID_COL_MAX - 1) || (chit.crow >= (GRID_ROW_MAX - 1)) || ( chit.crow <= 0)) return true; } @@ -157,13 +168,16 @@ bool FTKClusteringEngine::neighborhood(const FTKRawHit &hit1, const FTKRawHit &h { // 1st check same module + std::cout << "FTKClusteringEngine::neighborhood Start" << std::endl; if (hit1.getIdentifierHash() != hit2.getIdentifierHash()) { std::cout << "CHECK AGAIN, SOMETHING'S WRONG" << std::endl; return false; } + std::cout << "Hit type is" << hit1.getHitType() << std::endl; switch (hit1.getHitType()) { case ftk::SCT: + std::cout << "FTKClusteringEngine::neighborhood SCT case" << std::endl; if (!sctClustering) return false; if (hit1.getEtaStrip() == hit2.getEtaStrip()+hit2.getNStrips() @@ -172,9 +186,13 @@ bool FTKClusteringEngine::neighborhood(const FTKRawHit &hit1, const FTKRawHit &h return false; case ftk::PIXEL: + std::cout << "FTKClusteringEngine::neighborhood Pixel case:" << std::endl; + std::cout << "hit1: " << hit1.getEtaStrip() << " " << hit1.getPhiSide() << std::endl; + std::cout << "hit2: " << hit2.getEtaStrip() << " " << hit2.getPhiSide() << std::endl; /* need a common edge, i.e. contiguity along diagonal is not enough (see below) */ if ( (hit1.getEtaStrip() == hit2.getEtaStrip()+1 || hit1.getEtaStrip()+1 == hit2.getEtaStrip()) - && hit1.getPhiSide() == hit2.getPhiSide()) return true; + && hit1.getPhiSide() == hit2.getPhiSide()) + return true; if ( (hit1.getPhiSide() == hit2.getPhiSide()+1 || hit1.getPhiSide()+1 == hit2.getPhiSide()) && hit1.getEtaStrip() == hit2.getEtaStrip()) return true; @@ -198,19 +216,24 @@ bool FTKClusteringEngine::neighborhood(const FTKRawHit &hit1, const FTKRawHit &h // */ int FTKClusteringEngine::buildUpCluster(hitVector& currentHits, cluster& clu) { - if (clu.hitlist.size()==0) + std::cout << "FTKClusteringEngine::buildUpCluster Start: currentHits size: " << currentHits.size() << " cluster size: " << clu.hitlist.size() << std::endl; + if (clu.hitlist.size()==0) { clu.hitlist.push_back(std::move(currentHits.front())); + currentHits.erase(currentHits.begin()); + } /* Now we have a non empty cluster */ bool newHitsAdded = false; int distanceis = clu.hitlist.size(); + std::cout << "FTKClusteringEngine::buildUpCluster Before loop: currentHits size: " << currentHits.size() << " cluster size: " << clu.hitlist.size() << std::endl; hitVector::iterator hitP; for(int i = 0; i < distanceis; i++) { - FTKRawHit* hit = clu.hitlist.at(i).get(); + std::unique_ptr hit = std::make_unique(*clu.hitlist.at(i)); for (hitP = currentHits.begin(); hitP != currentHits.end(); ) { // loop over hits in module if (neighborhood(*hit, **hitP)) { // if hits are neighborhood clu.hitlist.push_back(std::move(*hitP)); + currentHits.erase(hitP); distanceis++; hitP = currentHits.begin(); // if a hit is erased then restart the loop newHitsAdded = true; @@ -221,8 +244,10 @@ int FTKClusteringEngine::buildUpCluster(hitVector& currentHits, cluster& clu) } // // if at least one hit was added, check for more neighborhood hits - if (newHitsAdded && currentHits.size()) buildUpCluster(currentHits, clu); - return clu.hitlist.size(); + if (newHitsAdded && currentHits.size()) + buildUpCluster(currentHits, clu); + std::cout << "FTKClusteringEngine::buildUpCluster Return" << std::endl; + return clu.hitlist.size(); } @@ -232,16 +257,51 @@ int FTKClusteringEngine::buildUpCluster(hitVector& currentHits, cluster& clu) void FTKClusteringEngine::makeClustersLNF(hitVector& currentHits, cluList& currentClusters) { while (currentHits.size()) { // as long as we have hits - auto clu = std::make_unique(); + std::cout << "FTKClusteringEngine::makeClustersLNF" << std::endl; + std::unique_ptr clu = std::make_unique(); clu->isSafe = false; clu->isKilled = false; - int cluSize = buildUpCluster(currentHits, *clu.get()); + buildUpCluster(currentHits, *clu.get()); currentClusters.push_back(std::move(clu)); } } + +/*! + * Function creating a cluster around a given hit (the seed). + * It starts by removing the seed from currentHits. + * \return void + */ +void FTKClusteringEngine::makeClusterFromSeed(hitVector& currentHits, cluList& currentClusters, FTKRawHit &seed) +{ + std::cout << "makeClusterFromSeed: Start with currentHits:" << currentHits.size() << std::endl; + std::cout << "makeClusterFromSeed: Seed is " << seed.getEtaStrip() << " " << seed.getPhiSide() << " " << seed.getTot() << std::endl; + // for (const auto& hit: currentHits) { + // if (hit == nullptr) + // std::cout << "we got a null"; + // else + // std::cout << "makeClusterFromSeed: Hitlist contains: " << hit.get()->getEtaStrip() << " " << hit.get()->getPhiSide() << " "<< hit.get()->getTot() << std::endl; + // } + + if (currentHits.size() > 0) + currentHits.erase(std::find_if(currentHits.begin(), currentHits.end(), + [&](const std::unique_ptr& chit) { return seed.getEtaStrip() == (chit.get())->getEtaStrip() && seed.getPhiSide() == (chit.get())->getPhiSide() && seed.getTot() == (chit.get())->getTot();})); + + std::unique_ptr clu = std::make_unique(); + clu->seed = seed; + clu->hitlist.push_back(std::move(std::make_unique(seed))); + std::cout << "makeClusterFromSeed: new cluster hitlist size: " << clu->hitlist.size() << std::endl; + clu->isSafe = false; + clu->isKilled = false; + buildUpCluster(currentHits, *clu.get()); + std::cout << "makeClusterFromSeed: CurrentClusters size is " << currentClusters.size() << std::endl; + currentClusters.push_back(std::move(clu)); +} + + void FTKClusteringEngine::makeClustersGridWindow(hitVector& fifo, cluList& currentClusters) { + std::cout << " makeClusters fifo size: " << fifo.size() << std::endl; boost::circular_buffer> circular_buffer (256); hitVector gridhits; while (!fifo.empty() || !circular_buffer.empty()) { @@ -256,32 +316,14 @@ void FTKClusteringEngine::makeClustersGridWindow(hitVector& fifo, cluList& curre } } -void FTKClusteringEngine::makeClusterFromSeed(hitVector& currentHits, cluList& currentClusters, FTKRawHit &seed) -{ - // hitVector::iterator position = std::find(currentHits.begin(), currentHits.end(), seed); - // if (position != currentHits.end()) { - // currentHits.erase(position); - // } - cluster clu; - clu.seed = seed; - // clu.hitlist.push_back(std::move(seed)); - clu.isSafe = false; - clu.isKilled = false; - if (currentHits.size() > 0) - buildUpCluster(currentHits, clu); - // currentClusters.push_back(std::make_unique(clu)); -} - - -bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const cluster &clu, hitVector &connectedHits) +bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const std::unique_ptr &clu, hitVector &connectedHits) { bool hasNeighborhood = false; int phi = hitIsGanged(hit); - // std::cout << "phi: " << phi << std::endl; if (phi) { // check hit is ganged int eta = hit.getEtaStrip(); - for (auto& pp: clu.hitlist) { + for (auto& pp: clu->hitlist) { if ( eta != (*pp).getEtaStrip() ) continue; if ( abs(phi - (*pp).getPhiSide() ) != 1 ) @@ -299,10 +341,10 @@ bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const c return hasNeighborhood; } -bool FTKClusteringEngine::findConnectedGanged(cluster &clu, hitVector &connectedHits) +bool FTKClusteringEngine::findConnectedGanged(const std::unique_ptr &clu, hitVector &connectedHits) { bool hasNeighborhood = false; - for (auto& hit: clu.hitlist) { + for (auto& hit: clu->hitlist) { if ( gangedHitHasNeighborhood(*hit, clu, connectedHits) ) { hasNeighborhood = true; } @@ -311,9 +353,9 @@ bool FTKClusteringEngine::findConnectedGanged(cluster &clu, hitVector &connected return hasNeighborhood; } -bool FTKClusteringEngine::isKilled(const cluster &clu, const hitVector &connectedHits) +bool FTKClusteringEngine::isKilled(const std::unique_ptr& clu, const hitVector &connectedHits) { - for (auto& hit: clu.hitlist) { + for (auto& hit: clu->hitlist) { if ( !hitIsGanged(*hit) ) continue; for (auto& chit: connectedHits) { if ( (*chit).getPhiSide() == (*hit).getPhiSide() @@ -333,13 +375,14 @@ bool FTKClusteringEngine::isKilled(const cluster &clu, const hitVector &connecte * \param cluster the cluster whose average is going to be calculated * \return void */ -void FTKClusteringEngine::averageCluster(cluster &clu) +void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) { - const unsigned int &nHits = clu.hitlist.size(); + std::cout << "FTKClusteringEngine::averageCluster Start" << std::endl; + const unsigned int &nHits = clu->hitlist.size(); assert(nHits>0); // sanity check - FTKRawHit &av = clu.clusterEquiv; ///< get pointer to clusterEquivalent - FTKRawHit first = *(clu.hitlist.front()); ///< get 1st hit + FTKRawHit &av = clu->clusterEquiv; ///< get pointer to clusterEquivalent + FTKRawHit first = *(clu->hitlist.front()); ///< get 1st hit /// reset values for clusterEquivalent (alias av) av.reset(); @@ -373,10 +416,6 @@ void FTKClusteringEngine::averageCluster(cluster &clu) int qColMin = 0; int qColMax = 0; - if (DEBUG_AVERAGE) - std::cout << "DEBUG_AVERAGE: isPixel=" << av.getIsPixel() - << ", nHits=" << nHits<< "\n"; - hitVector::iterator p; /// precalculate values for case pixelClusteringMode>0 int BarrelEndCap = first.getBarrelEC(); @@ -419,22 +458,22 @@ void FTKClusteringEngine::averageCluster(cluster &clu) } bool hasGanged = false; + std::cout << "FTKClusteringEngine::averageCluster Switching hit type" << std::endl; switch (av.getHitType()) { case ftk::SCT: { + std::cout << "FTKClusteringEngine::averageCluster SCT case" << std::endl; int firstStrip = 99999; int lastStrip = -99999; av.setPhiSide(first.getPhiSide()); - for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { - av.addX((*p)->getX()); - av.addY((*p)->getY()); - av.addZ((*p)->getZ()); - if ((*p)->getEtaStrip() < firstStrip) - firstStrip = (*p)->getEtaStrip(); - if ((*p)->getEtaStrip()+(*p)->getNStrips()-1 > lastStrip) - lastStrip = (*p)->getEtaStrip() + (*p)->getNStrips() - 1; - av.addEtaStrip((*p)->getEtaStrip()); - if (DEBUG_AVERAGE_SCT) // && clu.hitlist.size()>1) - cp.printHit(**p); + for (const auto &hit: clu->hitlist) { + av.addX(hit->getX()); + av.addY(hit->getY()); + av.addZ(hit->getZ()); + if (hit->getEtaStrip() < firstStrip) + firstStrip = hit->getEtaStrip(); + if (hit->getEtaStrip()+hit->getNStrips()-1 > lastStrip) + lastStrip = hit->getEtaStrip() + hit->getNStrips() - 1; + av.addEtaStrip(hit->getEtaStrip()); } float stripNumberFloat = (firstStrip*1.+lastStrip)/2; //(av.getEtaStrip()*1.)/nHits; @@ -450,21 +489,16 @@ void FTKClusteringEngine::averageCluster(cluster &clu) av.setEtaWidth(1); //std::cout << " strip " << std::endl; av.setPhiWidth(lastStrip+1-firstStrip); - if (DEBUG_AVERAGE_SCT) { // && clu.hitlist.size()>1) { - std::cout << "SCT AVERAGE: "; - cp.printHit(av); - std::cout << std::endl; - } break; // end of SCT } case ftk::PIXEL: { + std::cout << "FTKClusteringEngine::averageCluster Pixel/IBL case" << std::endl; av.setPhiSide(0); // eta is reset a few lines above if (pixelClusteringMode == 0) { - for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { //loop over hits in cluster - assert(av.getLayer()==(*p)->getLayer() && av.getPhiModule()==(*p)->getPhiModule() && av.getEtaModule()==(*p)->getEtaModule() ); + for (const auto& hit: clu->hitlist) { //loop over hits in cluster if (saveClusterContent) { // if enabled the cluster also stores also the single channels - FTKRawHit tmpch = *(*p); + FTKRawHit tmpch = *hit; // set the barcode of the single channel, this may allow a very refined debugging of // the cluster content accounting for the single barcode of each channel MultiTruth mt; @@ -473,13 +507,13 @@ void FTKClusteringEngine::averageCluster(cluster &clu) tmpch.setTruth(mt); av.addChannel(tmpch); } - av.addX((*p)->getX()); - av.addY((*p)->getY()); - av.addZ((*p)->getZ()); - av.addPhiSide((*p)->getPhiSide()); // phi index + av.addX(hit->getX()); + av.addY(hit->getY()); + av.addZ(hit->getZ()); + av.addPhiSide(hit->getPhiSide()); // phi index // pixels are counted starting from 0 (left edge) and not 0.5 (center position) // if only pixel 0 is hit the output value will be 0 and not 0.5 (pixel center) - av.addEtaStrip((*p)->getEtaStrip()); // eta index + av.addEtaStrip(hit->getEtaStrip()); // eta index } tmp = (int)round((av.getEtaStrip()*1.)/nHits); av.setDeltaEta((av.getEtaStrip()*1.)/nHits-tmp); @@ -498,10 +532,12 @@ void FTKClusteringEngine::averageCluster(cluster &clu) * In this code I'll use etaTrack instead of pixel eta for simplicity */ - for (p=clu.hitlist.begin(); p!=clu.hitlist.end(); ++p) { //loop over hits in cluster + std::cout << "FTKClusteringEngine::averageCluster hit loop" << std::endl; + for (auto& hit: clu->hitlist) { //loop over hits in cluster + std::cout << "Hit: " << hit->getEtaStrip() << " " << hit->getPhiSide() << std::endl; if (saveClusterContent) { // if enabled the cluster also stores also the single channels - FTKRawHit tmpch = *(*p); + FTKRawHit tmpch = *hit; // set the barcode of the single channel, this may allow a very refined debugging of // the cluster content accounting for the single barcode of each channel MultiTruth mt; @@ -511,13 +547,13 @@ void FTKClusteringEngine::averageCluster(cluster &clu) av.addChannel(tmpch); } - av.addX((*p)->getX()); - av.addY((*p)->getY()); - av.addZ((*p)->getZ()); + av.addX((*hit).getX()); + av.addY((*hit).getY()); + av.addZ((*hit).getZ()); - int row = (*p)->getPhiSide(); - int col = (*p)->getEtaStrip(); - int tot = (*p)->getTot(); // ToT for pixels + int row = (*hit).getPhiSide(); + int col = (*hit).getEtaStrip(); + int tot = (*hit).getTot(); // ToT for pixels if (!isIBLmodule && pixelRowIsGanged(row)) hasGanged = true; @@ -531,16 +567,6 @@ void FTKClusteringEngine::averageCluster(cluster &clu) int FEnumber = col/ftk::clustering::colsInFEChipPerPixelModuleRow; int FEcolumn = col%ftk::clustering::colsInFEChipPerPixelModuleRow; - if(DEBUG_CENTROID){ - printf("0x00%.2X%.2X%.3X", tot, col, row); - cout << " Pix HIT" - << " FE: " << setfill('0') << setw(2) << FEnumber - << " col: " << setfill('0') << setw(3) << col - << " row: " << setfill('0') << setw(3) << row - << " tot: " << setfill('0') << setw(2) << tot - << " -> "; - } - col = FEnumber*(ftk::clustering::colsInFEChipPerPixelModuleRow+1) + FEcolumn; col *= pixYScaleFactor; col += pixYScaleFactor/2; // add half a pixel to align to pixel center (assume normal 400um pixel) @@ -550,20 +576,11 @@ void FTKClusteringEngine::averageCluster(cluster &clu) } else if (isIBLmodule) { // IBL case row = 335 - (*p)->getPhiSide(); // inverse row coordinates // Yoshi 2016.10.28 // JAA updated 17.3.13 - if(DEBUG_CENTROID){ - printf("0x00%.2X%.2X%.3X", tot, col, row); - cout << " IBL HIT" - << " col: " << setfill('0') << setw(3) << col - << " row: " << setfill('0') << setw(3) << row - << " tot: " << setfill('0') << setw(2) << tot - << " -> "; - } - //Modifications have to be made to include 3d modules int orig_col = col; col *= pixYScaleFactor; // use units of 25um col += pixYScaleFactor/2; // add half a pixel to align to pixel center - if(((*p)->getModuleType() == ftk::MODULETYPE_IBL3D && ibl3DRealistic) || !ibl3DRealistic){ + if((hit->getModuleType() == ftk::MODULETYPE_IBL3D && ibl3DRealistic) || !ibl3DRealistic){ if (orig_col==0) col += pixYScaleFactor/2; // add half pixel (500um pixel in col0) if (orig_col>0) col += pixYScaleFactor; // add a pixel (500um pixel in col0) @@ -579,18 +596,6 @@ void FTKClusteringEngine::averageCluster(cluster &clu) } row *= pixXScaleFactor; - // comment 2017.01.30 - // if(isIBLmodule) row += pixXScaleFactor/2; // applied Manolis' update - - if(DEBUG_CENTROID){ - printf("0x00%.2X%.3X%.3X", tot, col, row); - cout << " Norm." - << " col: " << setfill('0') << setw(3) << col - << " row: " << setfill('0') << setw(4) << row - << " tot: " << setfill('0') << setw(2) << tot - << endl; - } - if (row == rowMin) qRowMin += tot; if (row < rowMin){ rowMin = row; @@ -615,16 +620,14 @@ void FTKClusteringEngine::averageCluster(cluster &clu) qColMax = tot; } - int phi = 335 - (*p)->getPhiSide(); // ROW // JAA updated 13 March 2017 to remove +1 as above + int phi = 335 - hit->getPhiSide(); // ROW // JAA updated 13 March 2017 to remove +1 as above // int phi = (*p)->getPhiSide(); // ROW - int eta = (*p)->getEtaStrip(); // COLUMN + int eta = hit->getEtaStrip(); // COLUMN if (eta > etaMax) etaMax = eta; if (eta < etaMin) etaMin = eta; if (phi > phiMax) phiMax = phi; if (phi < phiMin) phiMin = phi; - if (DEBUG_AVERAGE) - cp.printHit(**p); av.addTot(first.getTot()); // sum ToT for pixel clusters } av.setEtaWidth(etaMax-etaMin+1); @@ -779,7 +782,7 @@ void FTKClusteringEngine::averageCluster(cluster &clu) // cluster to a MultiTruth which will be stored with the hit // when it is converted to an FTKHit. MultiTruth mt; - for( hitVector::iterator ihit=clu.hitlist.begin(), fhit=clu.hitlist.end(); ihit!=fhit; ++ihit ) { + for( hitVector::iterator ihit=clu->hitlist.begin(), fhit=clu->hitlist.end(); ihit!=fhit; ++ihit ) { // record highest pt contribution to the combination (cluster) if( (*ihit)->getTruth() ) { mt.maximize( *((*ihit)->getTruth()) ); @@ -789,13 +792,7 @@ void FTKClusteringEngine::averageCluster(cluster &clu) mt.maximize(uniquecode,(*ihit)->getBarcodePt()); } } // end record truth for each raw channel in the cluster - clu.clusterEquiv.setTruth(mt); - - if (DEBUG_AVERAGE) { - std::cout << " AVERAGE IS:\n"; - cp.printHit(av); - std::cout << "\n\n"; - } + clu->clusterEquiv.setTruth(mt); } void FTKClusteringEngine::atlClusteringBlayer(vector &hits) { @@ -818,47 +815,62 @@ void FTKClusteringEngine::atlClusteringBlayer(vector &hits) { } -void FTKClusteringEngine::realisticIBLDecoder(hitVector ¤tHits) -{ - -} - void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) { - hitVector::iterator hit = currentHits.begin(); + hitVector::iterator hit1 = currentHits.begin(); std::stack> lifo; std::queue> fifo; - if((*hit)->getIsPixel()){ + if((*hit1)->getIsPixel()){ + std::cout << "Into the decoder" << std::endl; if (currentHits.size() > 1) std::stable_sort(currentHits.begin(), currentHits.end(), sortPixelInput); + std::cout << "After reordering"<< std::endl; + cp.printInputData(currentHits); for(auto& hit: currentHits) { - if ((*hit).getPhiSide() < ftk::clustering::rowsInFEChipPerPixelModuleRow) + if ((*hit).getPhiSide() < ftk::clustering::rowsInFEChipPerPixelModuleRow) { fifo.push( std::move(hit) ); - else + std::cout << "fifo push CH size: " << currentHits.size() << " " << fifo.size() << std::endl; + } + else { lifo.push( std::move(hit) ); + std::cout << "lifo push CH size: " << currentHits.size() << " " << lifo.size() << std::endl; + } } currentHits.clear(); + std::cout << "done with CH size" << currentHits.size() << std::endl; while(!lifo.empty() && !fifo.empty()){ - if ((*lifo.top()).getEtaStrip() <= (*fifo.front()).getEtaStrip()) { + std::cout << (*lifo.top()).getEtaStrip() << " " << (*fifo.front()).getEtaStrip() << std::endl; + if ((lifo.top().get())->getEtaStrip() <= (fifo.front().get())->getEtaStrip()) { + std::cout << "hoho" << std::endl; currentHits.push_back( std::move(lifo.top()) ); + lifo.pop(); } else { - currentHits.push_back( std::move(fifo.front()) ); + std::cout << "haha" << std::endl; + // std::cout << "CH size" << currentHits.size() << std::endl; + // std::cout << "Hit is valid:" << (fifo.front().get())->getEtaStrip() << std::endl; + // std::unique_ptr h = std::move(fifo.front()); + currentHits.push_back(std::move(fifo.front())); + fifo.pop(); } } + std::cout << "done with lifos and fifos" << std::endl; while(!lifo.empty()) { currentHits.push_back( std::move(lifo.top()) ); + lifo.pop(); } while(!fifo.empty()) { currentHits.push_back( std::move(fifo.front()) ); + fifo.pop(); } - }else{ + std::cout << "and done with the decoder " << currentHits.size() << std::endl; + } else { std::stack> lifo_planar; std::queue> fifo_planar; @@ -883,18 +895,22 @@ void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) while(!fifo.empty()){ currentHits.push_back( std::move(fifo.front()) ); + fifo.pop(); } while(!lifo.empty()) { currentHits.push_back(std::move (lifo.top()) ); + lifo.pop(); } while(!fifo_planar.empty()) { currentHits.push_back(std::move(fifo_planar.front()) ); + fifo_planar.pop(); } while(!lifo_planar.empty()) { currentHits.push_back(std::move(lifo_planar.top()) ); + lifo_planar.pop(); } } } @@ -903,14 +919,22 @@ void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer> &cb, hitVector &fifo, hitVector &gridhits) { - // //seed is set from cb if there are hits and from - // //fifo if the seed is empty. + //seed is set from cb if there are hits and from + //fifo if the seed is empty. + std::cout << "FTKClusteringEngine::gridAUTH fifo size: " << fifo.size() << " cb size:" << cb.size() << std::endl; + for (auto& hit: fifo) { + if (hit == nullptr) + std::cout << "null...." << std::endl; + } std::unique_ptr seed; - bool isIBLmodule = hitOnIBLmodule(*(seed.get())); - if (cb.size() == 0) - seed = std::move(fifo.front()); + if (cb.size() == 0){ + std::cout << "let's set the seed" << std::endl; + seed = std::make_unique(*fifo.front()); + } else if (cb.size() != 0) { - seed = std::move(cb.front()); + std::cout << " let's set from cb" << std::endl; + seed = std::make_unique(*cb.front()); + bool isIBLmodule = hitOnIBLmodule(*(seed.get())); for(auto& cbi: cb) { if ((*cbi).getEtaStrip() < (*seed).getEtaStrip()) seed.swap(cbi); @@ -923,6 +947,10 @@ FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer &hits) } } + std::cout << "hits sorted with size " << hitsByModule.size() << std::endl; /* * Step 2: build the list of clusters. @@ -1000,23 +1044,28 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) clustersByModuleMap clustersByModule; ///< store clusters by module for (auto& module: hitsByModule) { // loop over modules int modId = module.first; - hitVector currentHits = std::move (module.second); - FTKRawHit* firstHit = (module.second.front()).get(); + hitVector currentHits = std::move(module.second); + cp.printInputData(currentHits); + std::cout << "size is " << currentHits.size() << std::endl; + FTKRawHit firstHit = *(currentHits.front()).get(); cluList currentClusters; // instantiate cluster list - if (firstHit->getIsSCT()){ + if (firstHit.getIsSCT()){ makeClustersLNF(currentHits, currentClusters); // use ideal clustering } - else if(firstHit->getIsPixel()) { + else if(firstHit.getIsPixel()) { //First, perform the clustering if (pixelClusteringMode < PIXEL_CLUSTERING_MIXED) { makeClustersLNF(currentHits, currentClusters); } else if (pixelClusteringMode >= PIXEL_CLUSTERING_MIXED) { + std::cout << "PIXEL, going to decoder" << std::endl; realisticPixelDecoder(currentHits); + std::cout << "PIXEL, intermeddiate" << std::endl; makeClustersGridWindow(currentHits, currentClusters); + std::cout << "PIXEL, finished clustering" << std::endl; } } @@ -1024,74 +1073,67 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) clustersByModule[modId] = std::move( currentClusters ) ; } + std::cout << " atlClusteringLNF: Clustering Done, going to Centroid Calculation" << std::endl; /* * Third: take the "average" of each cluster */ -// int nTotClu = 0; -// clustersByModuleMap::iterator cluModP; // loop over modules -// for (cluModP=clustersByModule.begin(); cluModP!=clustersByModule.end(); cluModP++) { -// hitVector connectedHits; // list of ganged hits that are connected to a confirmed ganged hit -// cluList::iterator cluP; -// for (cluP=cluModP->second->begin(); cluP!=cluModP->second->end(); cluP++) { -// // do pattern recognition in the ganged region -// if ( (*cluP->hitlist.begin())->getIsPixel() && findConnectedGanged(*cluP, connectedHits) ) // set isSafe -// cluP->isSafe = true; -// } - -// for (cluP=cluModP->second->begin(); cluP!=cluModP->second->end(); cluP++) { -// if ( (*cluP->hitlist.begin())->getIsPixel() && isKilled(*cluP, connectedHits) ) // set isKilled -// cluP->isKilled = true; -// averageCluster(*cluP); // use floating-point average -// nTotClu++; // count all clusters -// } - -// // delete connected hits -// // hitVector::iterator connectedP; -// // for (connectedP = connectedHits.begin(); connectedP!=connectedHits.end(); ++connectedP) { -// // delete (*connectedP; -// // } -// } - - - -// #if defined(CENTROID_PRINTOUT) -// cp.printCentroidList(clustersByModule); -// #endif - -// /* -// * Fourth: put clusters/hits back in the event hit list -// */ -// hits.clear(); - -// int hitCounter=0; -// int deletedGangedClusters=0; -// for (auto& cluModP: clustersByModule) { -// cluList::iterator cluP; -// for (cluP=cluModP.second->begin(); cluP!=cluModP.second->end(); cluP++) { -// // kill clusters with ganged hits according to ganged pattern recognition -// if ( gangedPatternRecognition && cluP->isKilled && !cluP->isSafe ) { -// // AA 2009-07-07 removing the "isSafe" protection does not change -// // number of combinations to fit for single muon events -// deletedGangedClusters++; -// continue; -// } - -// // store hit by value -// FTKRawHit cluEquiv = (*cluP).clusterEquiv; -// hits.push_back(cluEquiv); -// ++hitCounter; -// } -// delete cluModP.second; -// } -// assert( (hitCounter+deletedGangedClusters) == nTotClu ); - -// /* -// * Fifth: free memory (could optimize and do this in previous step) -// */ - -// // The atlhit data from event is allocated and destroyed outside this function. -// // clustersByModuleMap is automatically deleted. -// clustersByModule.clear(); + int nTotClu = 0; + clustersByModuleMap::iterator cluModP; // loop over modules + for (auto& module: clustersByModule) { + hitVector connectedHits; // list of ganged hits that are connected to a confirmed ganged hit + for (auto& clu: module.second) { + // do pattern recognition in the ganged region + if ( (clu->hitlist.front())->getIsPixel() && findConnectedGanged(clu, connectedHits) ) // set isSafe + clu->isSafe = true; + } + + for (auto& clu: module.second) { + if ( (clu->hitlist.front())->getIsPixel() && isKilled(clu, connectedHits) ) // set isKilled + clu->isKilled = true; + averageCluster(clu); + nTotClu++; // count all clusters + } + + // delete connected hits + // hitVector::iterator connectedP; + // for (connectedP = connectedHits.begin(); connectedP!=connectedHits.end(); ++connectedP) { + // delete (*connectedP); + // } + } + + /* + * Fourth: put clusters/hits back in the event hit list + */ + hits.clear(); + + int hitCounter=0; + int deletedGangedClusters=0; + for (auto& module: clustersByModule) { + for (const auto& clu: module.second) { + // // kill clusters with ganged hits according to ganged pattern recognition + if ( gangedPatternRecognition && clu->isKilled && !clu->isSafe ) { + // // AA 2009-07-07 removing the "isSafe" protection does not change + // // number of combinations to fit for single muon events + deletedGangedClusters++; + continue; + } + + // store hit by value + FTKRawHit cluEquiv = clu->clusterEquiv; + hits.push_back(cluEquiv); + ++hitCounter; + } + // delete module.second; + } + assert( (hitCounter+deletedGangedClusters) == nTotClu ); + + /* + * Fifth: free memory (could optimize and do this in previous step) + */ + + // The atlhit data from event is allocated and destroyed outside this function. + // clustersByModuleMap is automatically deleted. + clustersByModule.clear(); } /*! @@ -1155,9 +1197,10 @@ int FTKClusteringEngine::gangedPartner(const FTKRawHit &hit) { return -1; } -double FTKClusteringEngine::getDeltaX1A(cluster &clu){ - std::unique_ptr first = std::move(*(clu.hitlist.begin())); - bool isIBLmodule = hitOnIBLmodule(*first); +double FTKClusteringEngine::getDeltaX1A(const std::unique_ptr& clu) +{ + FTKRawHit first = *(clu->hitlist.front()); + bool isIBLmodule = hitOnIBLmodule(first); float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; /// first = std::move(*(clu.hitlist.begin())); - bool isIBLmodule = hitOnIBLmodule(*first); + + +double FTKClusteringEngine::getDeltaX2A(const std::unique_ptr& clu) +{ + FTKRawHit first = *(clu->hitlist.front()); + bool isIBLmodule = hitOnIBLmodule(first); float sensorThickness = ftk::sensorThicknessPixel; float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; if (isIBLmodule) { @@ -1176,9 +1222,12 @@ double FTKClusteringEngine::getDeltaX2A(cluster &clu){ } return lround(32*(30*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)); } -int FTKClusteringEngine::getDeltaXEC1A(cluster &clu){ - std::unique_ptr first = std::move(*(clu.hitlist.begin())); - bool isIBLmodule = hitOnIBLmodule(*first); + + +int FTKClusteringEngine::getDeltaXEC1A(const std::unique_ptr& clu) +{ + FTKRawHit first = *(clu->hitlist.front()); + bool isIBLmodule = hitOnIBLmodule(first); float sensorThickness = ftk::sensorThicknessPixel; float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; if (isIBLmodule) { @@ -1186,9 +1235,12 @@ int FTKClusteringEngine::getDeltaXEC1A(cluster &clu){ } return lround(- (32*32*(10*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)/2.)); } -int FTKClusteringEngine::getDeltaXEC2A(cluster &clu){ - std::unique_ptr first = std::move(*(clu.hitlist.begin())); - bool isIBLmodule = hitOnIBLmodule(*first); + + +int FTKClusteringEngine::getDeltaXEC2A(const std::unique_ptr& clu) +{ + FTKRawHit first = *(clu->hitlist.front()); + bool isIBLmodule = hitOnIBLmodule(first); float sensorThickness = ftk::sensorThicknessPixel; float pixXScaleFactor = ftk::clustering::xScaleFactorPixel; if (isIBLmodule) { @@ -1196,9 +1248,12 @@ int FTKClusteringEngine::getDeltaXEC2A(cluster &clu){ } return lround(32*(10*ftk::micrometer*pixXScaleFactor*(sensorThickness/(250*ftk::micrometer))/ftk::phiPitch)); } -int FTKClusteringEngine::getDeltaYEC1A(cluster &clu){ - std::unique_ptr first = std::move(*(clu.hitlist.begin())); - bool isIBLmodule = hitOnIBLmodule(*first); + + +int FTKClusteringEngine::getDeltaYEC1A(const std::unique_ptr& clu) +{ + FTKRawHit first = *(clu->hitlist.front()); + bool isIBLmodule = hitOnIBLmodule(first); float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; @@ -1208,9 +1263,12 @@ int FTKClusteringEngine::getDeltaYEC1A(cluster &clu){ } return lround(- (32*32*(10*ftk::micrometer*pixYScaleFactor*(sensorThickness/(250*ftk::micrometer))/etaPitch)/2.)); } -int FTKClusteringEngine::getDeltaYEC2A(cluster &clu){ - std::unique_ptr first = std::move(*(clu.hitlist.begin())); - bool isIBLmodule = hitOnIBLmodule(*first); + + +int FTKClusteringEngine::getDeltaYEC2A(const std::unique_ptr& clu) +{ + FTKRawHit first = *(clu->hitlist.front()); + bool isIBLmodule = hitOnIBLmodule(first); float sensorThickness = ftk::sensorThicknessPixel; float etaPitch = ftk::etaPitchPixel; float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; @@ -1220,10 +1278,13 @@ int FTKClusteringEngine::getDeltaYEC2A(cluster &clu){ } return lround(32*(10*ftk::micrometer*pixYScaleFactor*(sensorThickness/(250*ftk::micrometer))/etaPitch)); } -int FTKClusteringEngine::getDeltaY1A(cluster &clu){ - std::unique_ptr first = std::move(*(clu.hitlist.begin())); - int layer = first->getLayer(); - bool isIBLmodule = hitOnIBLmodule(*first); + + +int FTKClusteringEngine::getDeltaY1A(const std::unique_ptr& clu) +{ + FTKRawHit first = *(clu->hitlist.front()); + int layer = first.getLayer(); + bool isIBLmodule = hitOnIBLmodule(first); if (FTKSetup::getFTKSetup().getIBLMode()==0) layer++; float radius = ftk::clustering::radii[layer]; @@ -1231,21 +1292,21 @@ int FTKClusteringEngine::getDeltaY1A(cluster &clu){ float etaPitch = ftk::etaPitchPixel; float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-6; + float etaModule = first.getEtaModule()-6; if (isIBLmodule) { sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-8; + etaModule = first.getEtaModule()-8; etaPitch = ftk::etaPitchIbl; } return lround ( - 32*32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch/2. ) + lround( 32*32*2* pixYScaleFactor*sensorThickness*moduleActiveLength/radius /etaPitch/2/2); } -int FTKClusteringEngine::getDeltaY2A(cluster &clu){ - std::unique_ptr first = std::move(*(clu.hitlist.begin())); - int layer = first->getLayer(); - bool isIBLmodule = hitOnIBLmodule(*first); +int FTKClusteringEngine::getDeltaY2A(const std::unique_ptr& clu){ + FTKRawHit first = *(clu->hitlist.front()); + int layer = first.getLayer(); + bool isIBLmodule = hitOnIBLmodule(first); if (FTKSetup::getFTKSetup().getIBLMode()==0) layer++; float radius = ftk::clustering::radii[layer]; @@ -1253,21 +1314,21 @@ int FTKClusteringEngine::getDeltaY2A(cluster &clu){ float etaPitch = ftk::etaPitchPixel; float moduleActiveLength = ftk::lengthOfPixelModuleIn400umPixels*ftk::etaPitchPixel/ftk::micrometer; float pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-6; + float etaModule = first.getEtaModule()-6; if (isIBLmodule) { sensorThickness = ftk::sensorThicknessIbl;etaPitch = ftk::etaPitchIbl; moduleActiveLength = ftk::lengthOfIblModuleIn250umPixels*ftk::etaPitchIbl/ftk::micrometer; // planar sensors pixYScaleFactor = ftk::clustering::yScaleFactorPixel; ///getEtaModule()-8; + etaModule = first.getEtaModule()-8; etaPitch = ftk::etaPitchIbl; } return lround (32*2* pixYScaleFactor*sensorThickness* etaModule*moduleActiveLength/radius /etaPitch) + lround ( - 32*2* pixYScaleFactor*sensorThickness* moduleActiveLength/radius /etaPitch/2.); } -int FTKClusteringEngine::getDeltaY1B(cluster &clu){ - std::unique_ptr first = std::move(*(clu.hitlist.begin())); - int layer = first->getLayer(); - bool isIBLmodule = hitOnIBLmodule(*first); +int FTKClusteringEngine::getDeltaY1B(const std::unique_ptr& clu){ + FTKRawHit first = *(clu->hitlist.front()); + int layer = first.getLayer(); + bool isIBLmodule = hitOnIBLmodule(first); if (FTKSetup::getFTKSetup().getIBLMode()==0) layer++; float radius = ftk::clustering::radii[layer]; @@ -1285,10 +1346,11 @@ int FTKClusteringEngine::getDeltaY1B(cluster &clu){ } -int FTKClusteringEngine::getDeltaY2B(cluster &clu){ - std::unique_ptr first = std::move(*(clu.hitlist.begin())); - int layer = first->getLayer(); - bool isIBLmodule = hitOnIBLmodule(*first); +int FTKClusteringEngine::getDeltaY2B(const std::unique_ptr& clu) +{ + FTKRawHit first = *(clu->hitlist.front()); + int layer = first.getLayer(); + bool isIBLmodule = hitOnIBLmodule(first); if (FTKSetup::getFTKSetup().getIBLMode()==0) layer++; float radius = ftk::clustering::radii[layer]; @@ -1304,21 +1366,3 @@ int FTKClusteringEngine::getDeltaY2B(cluster &clu){ } return lround (32 * sensorThickness/numberOfEtaPixelsInModule *moduleActiveLength/radius/etaPitch ) ; } - -FTKClusteringEngine::FTKClusteringEngine(bool saveClusterContent, bool diagClustering, - bool sctClustering, bool ibl3DRealistic, - bool duplicateGanged, bool gangedPatternRecognition, - bool splitBlayerModules, int pixelClusteringMode) : - saveClusterContent(saveClusterContent), - diagClustering(diagClustering), - sctClustering(sctClustering), - ibl3DRealistic(ibl3DRealistic), - duplicateGanged(duplicateGanged), - gangedPatternRecognition(gangedPatternRecognition), - splitBlayerModules(splitBlayerModules), - pixelClusteringMode(pixelClusteringMode) -{ - -} - - diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx index e5b833e65e4..4f29060f1a8 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx @@ -224,19 +224,18 @@ void FTKClusteringPrintout::printDecoderOutput(const hitVector& currentHits) void FTKClusteringPrintout::printInputData(const hitVector& currentHits) { - // FTKRawHit h = currentHits.front(); - // bool isIBLmodule = (h.getModuleType() == ftk::MODULETYPE_IBL3D || h.getModuleType() == ftk::MODULETYPE_IBL_PLANAR); - // hitVector sortHits = currentHits; - // int idHash = h.getIdentifierHash() + 8; - - // printf("0x08%.7x MODULE\n", idHash); - - // for(const auto& hit: currentHits) { - // printf("0x00%.2x%.2x%.3x ",hit.getTot(), hit.getEtaStrip(), hit.getPhiSide()); - // std::cout << " Pixel HIT" - // << " col: " << hit.getEtaStrip() - // << " row: " << hit.getPhiSide() - // << " tot: " << hit.getTot() - // << std::endl; - // } + FTKRawHit h = *(currentHits.front()).get(); + bool isIBLmodule = (h.getModuleType() == ftk::MODULETYPE_IBL3D || h.getModuleType() == ftk::MODULETYPE_IBL_PLANAR); + int idHash = h.getIdentifierHash() + 8; + + printf("0x08%.7x Module, isIBL: %d\n", idHash, isIBLmodule); + for(const auto& hit: currentHits) { + FTKRawHit h = *hit.get(); + printf("0x00%.2x%.2x%.3x ", h.getTot(), h.getEtaStrip(), h.getPhiSide()); + std::cout << " HIT" + << " col: " << h.getEtaStrip() + << " row: " << h.getPhiSide() + << " tot: " << h.getTot() + << std::endl; + } } -- GitLab From b40010af12c39c48eba75d6e6b42914685b794d0 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Tue, 12 Mar 2019 12:24:09 +0100 Subject: [PATCH 11/18] Fixed all segfaults; Some bit accuracy problems remain --- .../TrigFTKSim/FTKClusteringEngine.h | 3 +- .../TrigFTKSim/src/FTKClusteringEngine.cxx | 99 ++++++++++++++----- 2 files changed, 74 insertions(+), 28 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h index 26b27bf1031..efb3d5d5ddf 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h @@ -7,6 +7,7 @@ #include "TrigFTKSim/ftktypes.h" #include "TrigFTKSim/FTKClusteringPrintout.h" +#include "TrigFTKSim/FTKLogging.h" #define GRID_ROW_MAX 21 #define GRID_COL_MAX 8 @@ -115,7 +116,7 @@ public: -class FTKClusteringEngine +class FTKClusteringEngine : FTKLogging { private: FTKClusteringPrintout cp; diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx index 57774e5f042..eb7ac242a0d 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx @@ -40,6 +40,7 @@ FTKClusteringEngine::FTKClusteringEngine(bool saveClusterContent, bool diagClust bool sctClustering, bool ibl3DRealistic, bool duplicateGanged, bool gangedPatternRecognition, bool splitBlayerModules, int pixelClusteringMode) : + FTKLogging("FTKClusteringEngine"), saveClusterContent(saveClusterContent), diagClustering(diagClustering), sctClustering(sctClustering), @@ -319,17 +320,20 @@ void FTKClusteringEngine::makeClustersGridWindow(hitVector& fifo, cluList& curre bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const std::unique_ptr &clu, hitVector &connectedHits) { + Info("gangedHitHasNeighborhood") << "Start" << std::endl; bool hasNeighborhood = false; int phi = hitIsGanged(hit); if (phi) { // check hit is ganged int eta = hit.getEtaStrip(); - for (auto& pp: clu->hitlist) { - if ( eta != (*pp).getEtaStrip() ) + for (auto& chit: clu->hitlist) { + Info("gangedHitHasNeighborhood") << "Hit " << chit->getEtaStrip() << " " << chit->getPhiSide() << std::endl; + if ( eta != chit->getEtaStrip() ) continue; - if ( abs(phi - (*pp).getPhiSide() ) != 1 ) + if ( abs(phi - chit->getPhiSide() ) != 1 ) continue; hasNeighborhood = true; - std::unique_ptr tmpHit; + std::unique_ptr tmpHit = std::make_unique(); + Info("gangedHitHasNeighborhood") << "Made new hit" << std::endl; tmpHit->setHitType( ftk::PIXEL ); tmpHit->setModuleType( hit.getModuleType()); tmpHit->setEtaStrip( eta ); @@ -338,33 +342,39 @@ bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const s connectedHits.push_back( std::move(tmpHit) ); // store connected hit pointer } // end of nested loop over hits } //end of "if (phi)" + Info("gangedHitHasNeighborhood") << "Returning" << std::endl; return hasNeighborhood; } bool FTKClusteringEngine::findConnectedGanged(const std::unique_ptr &clu, hitVector &connectedHits) { + Info("findConnectedGanged") << "Start" << std::endl; bool hasNeighborhood = false; for (auto& hit: clu->hitlist) { + Info("findConnectedGanged") << "Hit" << std::endl; if ( gangedHitHasNeighborhood(*hit, clu, connectedHits) ) { hasNeighborhood = true; } } + Info("findConnectedGanged") << "Returning" << std::endl; return hasNeighborhood; } bool FTKClusteringEngine::isKilled(const std::unique_ptr& clu, const hitVector &connectedHits) { + std::cout << "FTKClusteringEngine::isKilled check" << std::endl; + bool isKilled = false; for (auto& hit: clu->hitlist) { if ( !hitIsGanged(*hit) ) continue; for (auto& chit: connectedHits) { if ( (*chit).getPhiSide() == (*hit).getPhiSide() && (*chit).getEtaStrip() == (*hit).getEtaStrip() ) - return true; + isKilled = true; } } // loop over hits in cluster - return false; + return isKilled; } /*! @@ -532,7 +542,7 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) * In this code I'll use etaTrack instead of pixel eta for simplicity */ - std::cout << "FTKClusteringEngine::averageCluster hit loop" << std::endl; + Info("averageCluster") << "hit loop" << std::endl; for (auto& hit: clu->hitlist) { //loop over hits in cluster std::cout << "Hit: " << hit->getEtaStrip() << " " << hit->getPhiSide() << std::endl; @@ -547,16 +557,17 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) av.addChannel(tmpch); } - av.addX((*hit).getX()); - av.addY((*hit).getY()); - av.addZ((*hit).getZ()); + av.addX(hit->getX()); + av.addY(hit->getY()); + av.addZ(hit->getZ()); - int row = (*hit).getPhiSide(); - int col = (*hit).getEtaStrip(); - int tot = (*hit).getTot(); // ToT for pixels + int row = hit->getPhiSide(); + int col = hit->getEtaStrip(); + int tot = hit->getTot(); // ToT for pixels if (!isIBLmodule && pixelRowIsGanged(row)) hasGanged = true; + std::cout << "Calculate col" << std::endl; if (isPixelmodule) { // account for 600um pixels in the centroid calculation // will use units of 100um and the convert to normal pixel units below @@ -574,7 +585,7 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) if (FEcolumn==0) col -= pixYScaleFactor/4; // correct position for first column in FE chip if (FEcolumn==(ftk::clustering::colsInFEChipPerPixelModuleRow-1)) col += pixYScaleFactor/4; // correct position for last column in FE chip } else if (isIBLmodule) { // IBL case - row = 335 - (*p)->getPhiSide(); // inverse row coordinates // Yoshi 2016.10.28 // JAA updated 17.3.13 + row = 335 - hit->getPhiSide(); // inverse row coordinates // Yoshi 2016.10.28 // JAA updated 17.3.13 //Modifications have to be made to include 3d modules int orig_col = col; @@ -620,6 +631,7 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) qColMax = tot; } + std::cout << "Invert row " << std::endl; int phi = 335 - hit->getPhiSide(); // ROW // JAA updated 13 March 2017 to remove +1 as above // int phi = (*p)->getPhiSide(); // ROW int eta = hit->getEtaStrip(); // COLUMN @@ -629,7 +641,9 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) if (phi > phiMax) phiMax = phi; if (phi < phiMin) phiMin = phi; av.addTot(first.getTot()); // sum ToT for pixel clusters + std::cout << "Hit done" << std::endl; } + std::cout << "Moved to av" << std::endl; av.setEtaWidth(etaMax-etaMin+1); av.setPhiWidth(phiMax-phiMin+1); @@ -656,22 +670,27 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) phi_average+= lround((getDeltaX1A(clu)+(getDeltaX2A(clu))*etaRow32)/1024.); // >>10; if ( (etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) > 0){ - if ( sensorThickness*((etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius)>etaPitch) { + if ( sensorThickness*((etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) + * moduleActiveLength / radius)>etaPitch) { /// test = etaPitch; eta_average+= pixYScaleFactor*(etaCol-0.5); eta_average = lround(eta_average); } else - eta_average+= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); + eta_average+= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + + getDeltaY1B(clu)*(colMin+colMax) + + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); } else{ - if ( sensorThickness*(-1*(etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius)>etaPitch) { - /// test = etaPitch; - eta_average+= pixYScaleFactor*(etaCol-0.5); + if ( sensorThickness*(-1*(etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) + * moduleActiveLength / radius)>etaPitch) { + eta_average += pixYScaleFactor*(etaCol - 0.5); eta_average = lround(eta_average); } else - eta_average-= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + getDeltaY1B(clu)*(colMin+colMax) + getDeltaY2B(clu)*etaCol32*(colMin+colMax))/2048.); + eta_average -= lround((getDeltaY1A(clu)+getDeltaY2A(clu)*etaCol32 + + getDeltaY1B(clu)*(colMin+colMax) + + getDeltaY2B(clu)*etaCol32*(colMin+colMax)) / 2048.); } } @@ -695,9 +714,11 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) * The radius is a fixed costant depending on the layer. It could be better estimated accounting * also for the rphi position within the module. */ - pixelEstimateCotTheta = (etaModule+(rowMin+rowMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius; + pixelEstimateCotTheta = (etaModule+(rowMin+rowMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) + * moduleActiveLength / radius; if (pixelClusteringMode>=PIXEL_CLUSTERING_IDEAL_APRIL_2014_FIX) /* Fixing an error in the formula */ - pixelEstimateCotTheta = (etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) * moduleActiveLength / radius; + pixelEstimateCotTheta = (etaModule+(colMin+colMax)/2./pixYScaleFactor/numberOfEtaPixelsInModule-0.5) + * moduleActiveLength / radius; // Compute eta for charge interpolation correction (if required) @@ -748,15 +769,16 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) eta_average = 0; } - if (BarrelEndCap!=0) phi_average += ftk::clustering::pixelEndCapRPhiCorrection*pixXScaleFactor; + if (BarrelEndCap != 0) + phi_average += ftk::clustering::pixelEndCapRPhiCorrection*pixXScaleFactor; av.setRowCoordinate( lround(phi_average) ); av.setColumnCoordinate( lround(eta_average) ); av.setSplit(false); if (pixelClusteringMode >= PIXEL_CLUSTERING_MIXED && isSplitCluster(clu)) av.setSplit(true); - eta_average*=numberOfEtaPixelsInModule/lengthOfPixelModuleInUmPixels/pixYScaleFactor; - phi_average/=pixXScaleFactor; + eta_average *= numberOfEtaPixelsInModule/lengthOfPixelModuleInUmPixels/pixYScaleFactor; + phi_average /= pixXScaleFactor; double delta; delta = eta_average - (int) eta_average; @@ -769,8 +791,9 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) break; // end of PIXEL } default: - assert(0); // should not get here! + break; } // end of switch + std::cout << "FTKClusteringEngine::averageCluster Set multitruth" << std::endl; // finally divide by nHits av.divX(nHits); @@ -793,6 +816,7 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) } } // end record truth for each raw channel in the cluster clu->clusterEquiv.setTruth(mt); + std::cout << "FTKClusteringEngine::averageCluster End" << std::endl; } void FTKClusteringEngine::atlClusteringBlayer(vector &hits) { @@ -1073,25 +1097,44 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) clustersByModule[modId] = std::move( currentClusters ) ; } - std::cout << " atlClusteringLNF: Clustering Done, going to Centroid Calculation" << std::endl; + std::cout << "atlClusteringLNF: Clustering Done, going to Centroid Calculation" << std::endl; /* * Third: take the "average" of each cluster */ + std::cout << clustersByModule.size() << std::endl; + for (auto& module: clustersByModule) { + Info("atlClusteringLNF") << "info Number of clusters: " << module.second.size() << std::endl; + for (auto& clu:module.second) { + std::cout << "Cluster start" << std::endl; + if (clu == nullptr) { + std::cout << "PROBLEM RE" << std::endl; + } + for (auto& hit:clu->hitlist){ + std::cout << "Hit:" << hit->getEtaStrip() << " " << hit->getPhiSide() << std::endl; + } + + } + } + int nTotClu = 0; clustersByModuleMap::iterator cluModP; // loop over modules for (auto& module: clustersByModule) { + Info("atlClusteringLNF") << "Loop of calculating average cluster..." << std::endl; hitVector connectedHits; // list of ganged hits that are connected to a confirmed ganged hit for (auto& clu: module.second) { + Info("atlClusteringLNF") << "Going for isSafe" << std::endl; // do pattern recognition in the ganged region if ( (clu->hitlist.front())->getIsPixel() && findConnectedGanged(clu, connectedHits) ) // set isSafe clu->isSafe = true; } + Info("atlClusteringLNF") << "isSafe done" << std::endl; for (auto& clu: module.second) { if ( (clu->hitlist.front())->getIsPixel() && isKilled(clu, connectedHits) ) // set isKilled clu->isKilled = true; averageCluster(clu); nTotClu++; // count all clusters + Info("atlClusteringLNF") << "Calculating cluster done" << std::endl; } // delete connected hits @@ -1099,7 +1142,9 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) // for (connectedP = connectedHits.begin(); connectedP!=connectedHits.end(); ++connectedP) { // delete (*connectedP); // } + Info("atlClusteringLNF") << "Loop of calculating average cluster done..." << std::endl; } + Info("atlClusteringLNF") << "AverageCluster Done" << std::endl; /* * Fourth: put clusters/hits back in the event hit list -- GitLab From f7b4e065b79fe982c11eb1f72da53528220724d6 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Tue, 12 Mar 2019 16:08:54 +0100 Subject: [PATCH 12/18] Removed (most) useless printout statements --- .../TrigFTKSim/FTKClusteringPrintout.h | 3 +- .../TrigFTKSim/src/FTKClusteringEngine.cxx | 150 +++--------------- .../TrigFTKSim/src/FTKClusteringPrintout.cxx | 99 +++--------- 3 files changed, 41 insertions(+), 211 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h index 952a237b1ed..b593133125b 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h @@ -19,8 +19,7 @@ public: FTKClusteringPrintout cp(); void printHit(const FTKRawHit &hit); void printClu(const cluster &clu); - void printInputData(const hitVector& currentHits); - void printDecoderOutput(const hitVector& currentHits); + void printHitlist(const hitVector& currentHits); void printClusterList(clustersByModuleMap clustersByModule); void printCentroidList(clustersByModuleMap clustersByModule); diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx index eb7ac242a0d..d1441eecbc1 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx @@ -9,7 +9,6 @@ #include "TrigFTKSim/ftkdefs.h" #include -#include #include #include #include @@ -167,18 +166,14 @@ int FTKClusteringEngine::hitToModuleId(const FTKRawHit &hit) */ bool FTKClusteringEngine::neighborhood(const FTKRawHit &hit1, const FTKRawHit &hit2) { - // 1st check same module - std::cout << "FTKClusteringEngine::neighborhood Start" << std::endl; if (hit1.getIdentifierHash() != hit2.getIdentifierHash()) { - std::cout << "CHECK AGAIN, SOMETHING'S WRONG" << std::endl; + Error("neighborhood") << "Hits do not belong in the same cluster" << std::endl; return false; } - std::cout << "Hit type is" << hit1.getHitType() << std::endl; switch (hit1.getHitType()) { case ftk::SCT: - std::cout << "FTKClusteringEngine::neighborhood SCT case" << std::endl; if (!sctClustering) return false; if (hit1.getEtaStrip() == hit2.getEtaStrip()+hit2.getNStrips() @@ -187,9 +182,6 @@ bool FTKClusteringEngine::neighborhood(const FTKRawHit &hit1, const FTKRawHit &h return false; case ftk::PIXEL: - std::cout << "FTKClusteringEngine::neighborhood Pixel case:" << std::endl; - std::cout << "hit1: " << hit1.getEtaStrip() << " " << hit1.getPhiSide() << std::endl; - std::cout << "hit2: " << hit2.getEtaStrip() << " " << hit2.getPhiSide() << std::endl; /* need a common edge, i.e. contiguity along diagonal is not enough (see below) */ if ( (hit1.getEtaStrip() == hit2.getEtaStrip()+1 || hit1.getEtaStrip()+1 == hit2.getEtaStrip()) && hit1.getPhiSide() == hit2.getPhiSide()) @@ -210,14 +202,13 @@ bool FTKClusteringEngine::neighborhood(const FTKRawHit &hit1, const FTKRawHit &h } -// /* -// * Recursively adds hits to a given cluster. -// * Returns number of hits in final cluster. -// * If no cluster is given (or empty cluster) make a cluster out of the 1st hit. -// */ +/* + * Recursively adds hits to a given cluster. + * Returns number of hits in final cluster. + * If no cluster is given (or empty cluster) make a cluster out of the 1st hit. + */ int FTKClusteringEngine::buildUpCluster(hitVector& currentHits, cluster& clu) { - std::cout << "FTKClusteringEngine::buildUpCluster Start: currentHits size: " << currentHits.size() << " cluster size: " << clu.hitlist.size() << std::endl; if (clu.hitlist.size()==0) { clu.hitlist.push_back(std::move(currentHits.front())); currentHits.erase(currentHits.begin()); @@ -226,8 +217,6 @@ int FTKClusteringEngine::buildUpCluster(hitVector& currentHits, cluster& clu) /* Now we have a non empty cluster */ bool newHitsAdded = false; int distanceis = clu.hitlist.size(); - - std::cout << "FTKClusteringEngine::buildUpCluster Before loop: currentHits size: " << currentHits.size() << " cluster size: " << clu.hitlist.size() << std::endl; hitVector::iterator hitP; for(int i = 0; i < distanceis; i++) { std::unique_ptr hit = std::make_unique(*clu.hitlist.at(i)); @@ -247,7 +236,6 @@ int FTKClusteringEngine::buildUpCluster(hitVector& currentHits, cluster& clu) // // if at least one hit was added, check for more neighborhood hits if (newHitsAdded && currentHits.size()) buildUpCluster(currentHits, clu); - std::cout << "FTKClusteringEngine::buildUpCluster Return" << std::endl; return clu.hitlist.size(); } @@ -258,7 +246,6 @@ int FTKClusteringEngine::buildUpCluster(hitVector& currentHits, cluster& clu) void FTKClusteringEngine::makeClustersLNF(hitVector& currentHits, cluList& currentClusters) { while (currentHits.size()) { // as long as we have hits - std::cout << "FTKClusteringEngine::makeClustersLNF" << std::endl; std::unique_ptr clu = std::make_unique(); clu->isSafe = false; clu->isKilled = false; @@ -275,34 +262,25 @@ void FTKClusteringEngine::makeClustersLNF(hitVector& currentHits, cluList& curre */ void FTKClusteringEngine::makeClusterFromSeed(hitVector& currentHits, cluList& currentClusters, FTKRawHit &seed) { - std::cout << "makeClusterFromSeed: Start with currentHits:" << currentHits.size() << std::endl; - std::cout << "makeClusterFromSeed: Seed is " << seed.getEtaStrip() << " " << seed.getPhiSide() << " " << seed.getTot() << std::endl; - // for (const auto& hit: currentHits) { - // if (hit == nullptr) - // std::cout << "we got a null"; - // else - // std::cout << "makeClusterFromSeed: Hitlist contains: " << hit.get()->getEtaStrip() << " " << hit.get()->getPhiSide() << " "<< hit.get()->getTot() << std::endl; - // } - if (currentHits.size() > 0) currentHits.erase(std::find_if(currentHits.begin(), currentHits.end(), - [&](const std::unique_ptr& chit) { return seed.getEtaStrip() == (chit.get())->getEtaStrip() && seed.getPhiSide() == (chit.get())->getPhiSide() && seed.getTot() == (chit.get())->getTot();})); + [&](const std::unique_ptr& chit) { + return seed.getEtaStrip() == (chit.get())->getEtaStrip() + && seed.getPhiSide() == (chit.get())->getPhiSide() + && seed.getTot() == (chit.get())->getTot();})); std::unique_ptr clu = std::make_unique(); clu->seed = seed; clu->hitlist.push_back(std::move(std::make_unique(seed))); - std::cout << "makeClusterFromSeed: new cluster hitlist size: " << clu->hitlist.size() << std::endl; clu->isSafe = false; clu->isKilled = false; buildUpCluster(currentHits, *clu.get()); - std::cout << "makeClusterFromSeed: CurrentClusters size is " << currentClusters.size() << std::endl; currentClusters.push_back(std::move(clu)); } void FTKClusteringEngine::makeClustersGridWindow(hitVector& fifo, cluList& currentClusters) { - std::cout << " makeClusters fifo size: " << fifo.size() << std::endl; boost::circular_buffer> circular_buffer (256); hitVector gridhits; while (!fifo.empty() || !circular_buffer.empty()) { @@ -320,20 +298,17 @@ void FTKClusteringEngine::makeClustersGridWindow(hitVector& fifo, cluList& curre bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const std::unique_ptr &clu, hitVector &connectedHits) { - Info("gangedHitHasNeighborhood") << "Start" << std::endl; bool hasNeighborhood = false; int phi = hitIsGanged(hit); if (phi) { // check hit is ganged int eta = hit.getEtaStrip(); for (auto& chit: clu->hitlist) { - Info("gangedHitHasNeighborhood") << "Hit " << chit->getEtaStrip() << " " << chit->getPhiSide() << std::endl; if ( eta != chit->getEtaStrip() ) continue; if ( abs(phi - chit->getPhiSide() ) != 1 ) continue; hasNeighborhood = true; std::unique_ptr tmpHit = std::make_unique(); - Info("gangedHitHasNeighborhood") << "Made new hit" << std::endl; tmpHit->setHitType( ftk::PIXEL ); tmpHit->setModuleType( hit.getModuleType()); tmpHit->setEtaStrip( eta ); @@ -342,28 +317,24 @@ bool FTKClusteringEngine::gangedHitHasNeighborhood(const FTKRawHit &hit, const s connectedHits.push_back( std::move(tmpHit) ); // store connected hit pointer } // end of nested loop over hits } //end of "if (phi)" - Info("gangedHitHasNeighborhood") << "Returning" << std::endl; return hasNeighborhood; } bool FTKClusteringEngine::findConnectedGanged(const std::unique_ptr &clu, hitVector &connectedHits) { - Info("findConnectedGanged") << "Start" << std::endl; bool hasNeighborhood = false; for (auto& hit: clu->hitlist) { - Info("findConnectedGanged") << "Hit" << std::endl; if ( gangedHitHasNeighborhood(*hit, clu, connectedHits) ) { hasNeighborhood = true; + break; } } - Info("findConnectedGanged") << "Returning" << std::endl; return hasNeighborhood; } bool FTKClusteringEngine::isKilled(const std::unique_ptr& clu, const hitVector &connectedHits) { - std::cout << "FTKClusteringEngine::isKilled check" << std::endl; bool isKilled = false; for (auto& hit: clu->hitlist) { if ( !hitIsGanged(*hit) ) continue; @@ -387,9 +358,7 @@ bool FTKClusteringEngine::isKilled(const std::unique_ptr& clu, const hi */ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) { - std::cout << "FTKClusteringEngine::averageCluster Start" << std::endl; const unsigned int &nHits = clu->hitlist.size(); - assert(nHits>0); // sanity check FTKRawHit &av = clu->clusterEquiv; ///< get pointer to clusterEquivalent FTKRawHit first = *(clu->hitlist.front()); ///< get 1st hit @@ -468,10 +437,8 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) } bool hasGanged = false; - std::cout << "FTKClusteringEngine::averageCluster Switching hit type" << std::endl; switch (av.getHitType()) { case ftk::SCT: { - std::cout << "FTKClusteringEngine::averageCluster SCT case" << std::endl; int firstStrip = 99999; int lastStrip = -99999; av.setPhiSide(first.getPhiSide()); @@ -497,12 +464,10 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) av.setDeltaEta(0); av.setNStrips(lastStrip+1-firstStrip); av.setEtaWidth(1); - //std::cout << " strip " << std::endl; av.setPhiWidth(lastStrip+1-firstStrip); break; // end of SCT } case ftk::PIXEL: { - std::cout << "FTKClusteringEngine::averageCluster Pixel/IBL case" << std::endl; av.setPhiSide(0); // eta is reset a few lines above if (pixelClusteringMode == 0) { @@ -542,10 +507,7 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) * In this code I'll use etaTrack instead of pixel eta for simplicity */ - Info("averageCluster") << "hit loop" << std::endl; for (auto& hit: clu->hitlist) { //loop over hits in cluster - std::cout << "Hit: " << hit->getEtaStrip() << " " << hit->getPhiSide() << std::endl; - if (saveClusterContent) { // if enabled the cluster also stores also the single channels FTKRawHit tmpch = *hit; // set the barcode of the single channel, this may allow a very refined debugging of @@ -567,7 +529,6 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) if (!isIBLmodule && pixelRowIsGanged(row)) hasGanged = true; - std::cout << "Calculate col" << std::endl; if (isPixelmodule) { // account for 600um pixels in the centroid calculation // will use units of 100um and the convert to normal pixel units below @@ -631,7 +592,6 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) qColMax = tot; } - std::cout << "Invert row " << std::endl; int phi = 335 - hit->getPhiSide(); // ROW // JAA updated 13 March 2017 to remove +1 as above // int phi = (*p)->getPhiSide(); // ROW int eta = hit->getEtaStrip(); // COLUMN @@ -641,9 +601,7 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) if (phi > phiMax) phiMax = phi; if (phi < phiMin) phiMin = phi; av.addTot(first.getTot()); // sum ToT for pixel clusters - std::cout << "Hit done" << std::endl; } - std::cout << "Moved to av" << std::endl; av.setEtaWidth(etaMax-etaMin+1); av.setPhiWidth(phiMax-phiMin+1); @@ -761,11 +719,11 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) } if (phi_average<0) { - assert(phi_average<0); + Error("averageCluster") << "phi_average < 0" << std::endl; phi_average = 0; } if (eta_average<0) { - assert(eta_average<0); + Error("averageCluster") << "eta_average < 0" << std::endl; eta_average = 0; } @@ -793,7 +751,6 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) default: break; } // end of switch - std::cout << "FTKClusteringEngine::averageCluster Set multitruth" << std::endl; // finally divide by nHits av.divX(nHits); @@ -816,7 +773,6 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) } } // end record truth for each raw channel in the cluster clu->clusterEquiv.setTruth(mt); - std::cout << "FTKClusteringEngine::averageCluster End" << std::endl; } void FTKClusteringEngine::atlClusteringBlayer(vector &hits) { @@ -841,49 +797,34 @@ void FTKClusteringEngine::atlClusteringBlayer(vector &hits) { void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) { - hitVector::iterator hit1 = currentHits.begin(); - std::stack> lifo; std::queue> fifo; - if((*hit1)->getIsPixel()){ - std::cout << "Into the decoder" << std::endl; + if(currentHits.front()->getIsPixel()){ if (currentHits.size() > 1) std::stable_sort(currentHits.begin(), currentHits.end(), sortPixelInput); - std::cout << "After reordering"<< std::endl; - cp.printInputData(currentHits); for(auto& hit: currentHits) { if ((*hit).getPhiSide() < ftk::clustering::rowsInFEChipPerPixelModuleRow) { fifo.push( std::move(hit) ); - std::cout << "fifo push CH size: " << currentHits.size() << " " << fifo.size() << std::endl; } else { lifo.push( std::move(hit) ); - std::cout << "lifo push CH size: " << currentHits.size() << " " << lifo.size() << std::endl; } } currentHits.clear(); - std::cout << "done with CH size" << currentHits.size() << std::endl; while(!lifo.empty() && !fifo.empty()){ - std::cout << (*lifo.top()).getEtaStrip() << " " << (*fifo.front()).getEtaStrip() << std::endl; if ((lifo.top().get())->getEtaStrip() <= (fifo.front().get())->getEtaStrip()) { - std::cout << "hoho" << std::endl; currentHits.push_back( std::move(lifo.top()) ); lifo.pop(); } else { - std::cout << "haha" << std::endl; - // std::cout << "CH size" << currentHits.size() << std::endl; - // std::cout << "Hit is valid:" << (fifo.front().get())->getEtaStrip() << std::endl; - // std::unique_ptr h = std::move(fifo.front()); currentHits.push_back(std::move(fifo.front())); fifo.pop(); } } - std::cout << "done with lifos and fifos" << std::endl; while(!lifo.empty()) { currentHits.push_back( std::move(lifo.top()) ); @@ -893,7 +834,6 @@ void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) currentHits.push_back( std::move(fifo.front()) ); fifo.pop(); } - std::cout << "and done with the decoder " << currentHits.size() << std::endl; } else { std::stack> lifo_planar; std::queue> fifo_planar; @@ -937,6 +877,9 @@ void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) lifo_planar.pop(); } } + + Info("realisticPixelDecoder") << "Decorer output for Module " << currentHits.front()->getIdentifierHash() << std::endl; + cp.printHitlist(currentHits); } @@ -945,18 +888,11 @@ FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer seed; if (cb.size() == 0){ - std::cout << "let's set the seed" << std::endl; seed = std::make_unique(*fifo.front()); } else if (cb.size() != 0) { - std::cout << " let's set from cb" << std::endl; seed = std::make_unique(*cb.front()); bool isIBLmodule = hitOnIBLmodule(*(seed.get())); for(auto& cbi: cb) { @@ -970,11 +906,6 @@ FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer &hits) for(const auto& hit: hits) { int modId = hitToModuleId(hit); - if (modId<0) assert(0); + if (modId<0) + Error("atlClusteringLNF") << "modId < 0" << std::endl; hitsByModule[modId].push_back( std::make_unique(hit) ); if (duplicateGanged && hitIsGanged(hit)) { gangedPixelList.push_back( hit ); @@ -1057,8 +977,6 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) } } - std::cout << "hits sorted with size " << hitsByModule.size() << std::endl; - /* * Step 2: build the list of clusters. * The ideal clustering is going to be used in the following cases: @@ -1069,27 +987,20 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) for (auto& module: hitsByModule) { // loop over modules int modId = module.first; hitVector currentHits = std::move(module.second); - cp.printInputData(currentHits); - std::cout << "size is " << currentHits.size() << std::endl; FTKRawHit firstHit = *(currentHits.front()).get(); cluList currentClusters; // instantiate cluster list if (firstHit.getIsSCT()){ makeClustersLNF(currentHits, currentClusters); // use ideal clustering - } else if(firstHit.getIsPixel()) { - //First, perform the clustering if (pixelClusteringMode < PIXEL_CLUSTERING_MIXED) { makeClustersLNF(currentHits, currentClusters); } else if (pixelClusteringMode >= PIXEL_CLUSTERING_MIXED) { - std::cout << "PIXEL, going to decoder" << std::endl; realisticPixelDecoder(currentHits); - std::cout << "PIXEL, intermeddiate" << std::endl; makeClustersGridWindow(currentHits, currentClusters); - std::cout << "PIXEL, finished clustering" << std::endl; } } @@ -1097,44 +1008,24 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) clustersByModule[modId] = std::move( currentClusters ) ; } - std::cout << "atlClusteringLNF: Clustering Done, going to Centroid Calculation" << std::endl; /* * Third: take the "average" of each cluster */ - std::cout << clustersByModule.size() << std::endl; - for (auto& module: clustersByModule) { - Info("atlClusteringLNF") << "info Number of clusters: " << module.second.size() << std::endl; - for (auto& clu:module.second) { - std::cout << "Cluster start" << std::endl; - if (clu == nullptr) { - std::cout << "PROBLEM RE" << std::endl; - } - for (auto& hit:clu->hitlist){ - std::cout << "Hit:" << hit->getEtaStrip() << " " << hit->getPhiSide() << std::endl; - } - - } - } - int nTotClu = 0; clustersByModuleMap::iterator cluModP; // loop over modules for (auto& module: clustersByModule) { - Info("atlClusteringLNF") << "Loop of calculating average cluster..." << std::endl; hitVector connectedHits; // list of ganged hits that are connected to a confirmed ganged hit for (auto& clu: module.second) { - Info("atlClusteringLNF") << "Going for isSafe" << std::endl; // do pattern recognition in the ganged region if ( (clu->hitlist.front())->getIsPixel() && findConnectedGanged(clu, connectedHits) ) // set isSafe clu->isSafe = true; } - Info("atlClusteringLNF") << "isSafe done" << std::endl; for (auto& clu: module.second) { if ( (clu->hitlist.front())->getIsPixel() && isKilled(clu, connectedHits) ) // set isKilled clu->isKilled = true; averageCluster(clu); nTotClu++; // count all clusters - Info("atlClusteringLNF") << "Calculating cluster done" << std::endl; } // delete connected hits @@ -1142,9 +1033,7 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) // for (connectedP = connectedHits.begin(); connectedP!=connectedHits.end(); ++connectedP) { // delete (*connectedP); // } - Info("atlClusteringLNF") << "Loop of calculating average cluster done..." << std::endl; } - Info("atlClusteringLNF") << "AverageCluster Done" << std::endl; /* * Fourth: put clusters/hits back in the event hit list @@ -1170,7 +1059,6 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) } // delete module.second; } - assert( (hitCounter+deletedGangedClusters) == nTotClu ); /* * Fifth: free memory (could optimize and do this in previous step) diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx index 4f29060f1a8..267cf03b0b4 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx @@ -25,19 +25,19 @@ const bool DEBUG_CENTROID = 0; // check centroid calc. * \param hit the hit * \return void */ -void printHit(const FTKRawHit &hit) +void FTKClusteringPrintout::printHit(const FTKRawHit &hit) { std::cout << "DEBUG_HITS: " - << " isPixel=" << hit.getIsPixel() - << " barrel_ec=" << hit.getBarrelEC() - << " layer_disk=" << hit.getLayer() - << " phi_module=" << hit.getPhiModule() - << " eta_module=" << hit.getEtaModule() - << " pi_side=" << hit.getPhiSide() - << " ei_strip=" << hit.getEtaStrip() - << " n_strips=" << hit.getNStrips() - << " deltaPhi=" << hit.getDeltaPhi() - << " deltaEta=" << hit.getDeltaEta() + << " isPixel=" << hit.getIsPixel() + << " barrel_ec=" << hit.getBarrelEC() + << " layer_disk=" << hit.getLayer() + << " phi_module=" << hit.getPhiModule() + << " eta_module=" << hit.getEtaModule() + << " pi_side=" << hit.getPhiSide() + << " ei_strip=" << hit.getEtaStrip() + << " n_strips=" << hit.getNStrips() + << " deltaPhi=" << hit.getDeltaPhi() + << " deltaEta=" << hit.getDeltaEta() << " eventindex=" << hit.getEventIndex() << " barcode=" << hit.getBarcode() << " bar_pt=" << hit.getBarcodePt() @@ -169,73 +169,16 @@ bool sortWords(const FTKRawHit* i, const FTKRawHit* j) } -void FTKClusteringPrintout::printDecoderOutput(const hitVector& currentHits) +void FTKClusteringPrintout::printHitlist(const hitVector& hitlist) { - // hitVector::iterator hit = currentHits->begin(); - // hitVector *sortHits = currentHits; - // int idHash = (*hit).getIdentifierHash(); - // bool isIBLmodule = ((**hit).getModuleType() == ftk::MODULETYPE_IBL3D || (**hit).getModuleType() == ftk::MODULETYPE_IBL_PLANAR); - - // if(isIBLmodule){ // Keisuke 20170215 - // stable_sort(sortHits->begin(), sortHits->end(), sortWords); - // idHash = (*sortHits->begin()).getIdentifierHash(); - // } - - // std::cout << "Found in Decoder" << std::hex << idHash << std::dec <begin(), sortHits->end(), sortWords); - - // for(hitVector::iterator it = sortHits->begin(); it != sortHits->end(); ++it){ - // int tempCol = (*it)->getEtaStrip(); - // // if(tempCol >= 80) tempCol = tempCol - 80; // Yoshi 2016.11.18 - // int tempRow = 335 - (*it)->getPhiSide(); // Keisuke 20170314, start from 0 - // int tempTot = (*it)->getTot(); - // int outputData = ( (tempTot << 20) | (tempCol << 12) | tempRow ); - // printf("0x0%.7X",outputData); - - // if(!DEBUG_DECODER) std::cout << std::endl; - // else{ - // std::cout << " IBL HIT" - // << " col: " << std::setfill('0') << std::setw(3) << tempCol - // << " row: " << std::setfill('0') << std::setw(3) << tempRow - // << " tot: " << std::setfill('0') << std::setw(2) << tempTot - // << std::endl; - // } - // } - - // }else{ // for Pixel - // printf("0x8%.7x\n", (**hit).getIdentifierHash()); - // for(hit = currentHits->begin(); hit!= currentHits->end(); hit++) { - // printf("0x0%.2X%.2X%.3X",(*hit)->getTot(), (*hit)->getEtaStrip(), (*hit)->getPhiSide()); - // if(!DEBUG_DECODER) std::cout << std::endl; - // else{ - // std::cout << " Pixel HIT" - // << " col: " << (*hit)->getEtaStrip() - // << " row: " << (*hit)->getPhiSide() - // << " tot: " << (*hit)->getTot() - // << std::endl; - // } - - // } //hit loop - // printf("0x40000000\n"); - // } -} - -void FTKClusteringPrintout::printInputData(const hitVector& currentHits) -{ - FTKRawHit h = *(currentHits.front()).get(); - bool isIBLmodule = (h.getModuleType() == ftk::MODULETYPE_IBL3D || h.getModuleType() == ftk::MODULETYPE_IBL_PLANAR); - int idHash = h.getIdentifierHash() + 8; - - printf("0x08%.7x Module, isIBL: %d\n", idHash, isIBLmodule); - for(const auto& hit: currentHits) { - FTKRawHit h = *hit.get(); - printf("0x00%.2x%.2x%.3x ", h.getTot(), h.getEtaStrip(), h.getPhiSide()); - std::cout << " HIT" - << " col: " << h.getEtaStrip() - << " row: " << h.getPhiSide() - << " tot: " << h.getTot() - << std::endl; + // FTKRawHit h = *(currentHits.front()).get(); + // bool isIBLmodule = (h.getModuleType() == ftk::MODULETYPE_IBL3D || h.getModuleType() == ftk::MODULETYPE_IBL_PLANAR); + // int idHash = h.getIdentifierHash() + 8; + + printf("0x08%.7x Module: %d\n", (hitlist.front()->getIdentifierHash())); + for(const auto& hit: hitlist) { + printf("0x00%.2x%.2x%.3x\n", hit->getTot(), hit->getEtaStrip(), hit->getPhiSide()); + printHit(*(hit.get())); } } + -- GitLab From d6599ee058ace2588b722ddd3e353de2be86eaae Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Mon, 18 Mar 2019 12:47:12 +0100 Subject: [PATCH 13/18] Pixel & SCT are bit accurate --- .../TrigFTKSim/FTKClusteringEngine.h | 31 ----- .../TrigFTKSim/FTKClusteringPrintout.h | 34 ++++- .../TrigFTKSim/src/FTKClusteringEngine.cxx | 118 +++++++++++++----- .../TrigFTKSim/src/FTKClusteringPrintout.cxx | 63 +++++----- 4 files changed, 144 insertions(+), 102 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h index efb3d5d5ddf..e6ec1d0690d 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h @@ -21,12 +21,6 @@ #include #include -/* class FTKRawHit_cmp { */ -/* public: */ -/* bool operator() (const FTKRawHit *hit1, const FTKRawHit *hit2) const; */ -/* }; */ - - typedef std::vector> hitVector; typedef std::map hitsByModuleMap; @@ -90,31 +84,6 @@ public: int lrow; ///< Row of the hit expressed in FE coordinates }; -/** - * This class creates a hit whose coordinates are relative to the hit's position - * in the cluster. It is used to calculate if a cluster is split and for - * printing out the test vectors. - */ -class FTK_ClusterCoordHit -{ -public: - /** - * Create an FTK_Hit_FECoords from an FTKRawHit - * \param h FTKRawHit to be processed - * \param seed the central hit of the cluster - */ - FTK_ClusterCoordHit(const FTKRawHit &h, const FTKRawHit& seed) { - tot = h.getTot(); - crow = h.getPhiSide() - (seed.getPhiSide() - 10); - if (seed.getEtaStrip() %2 != 0) ccol = h.getEtaStrip() - (seed.getEtaStrip() - 1); - else ccol = h.getEtaStrip() - (seed.getEtaStrip()); - } - int tot; ///< ToT of the hit in the cluster - int ccol; ///< Column of the hit in the cluster - int crow; ///< Row of the hit in the cluster -}; - - class FTKClusteringEngine : FTKLogging { diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h index b593133125b..39807588c64 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringPrintout.h @@ -12,16 +12,44 @@ typedef std::map hitsByModuleMap; typedef std::vector> cluList; typedef std::map clustersByModuleMap; +/** + * This class creates a hit whose coordinates are relative to the hit's position + * in the cluster. It is used to calculate if a cluster is split and for + * printing out the test vectors. + */ +class FTK_ClusterCoordHit +{ +public: + /** + * Create an FTK_Hit_FECoords from an FTKRawHit + * \param h FTKRawHit to be processed + * \param seed the central hit of the cluster + */ + FTK_ClusterCoordHit(const FTKRawHit &h, const FTKRawHit& seed) { + tot = h.getTot(); + crow = h.getPhiSide() - (seed.getPhiSide() - 10); + if (seed.getEtaStrip() %2 != 0) ccol = h.getEtaStrip() - (seed.getEtaStrip() - 1); + else ccol = h.getEtaStrip() - (seed.getEtaStrip()); + } + int tot; ///< ToT of the hit in the cluster + int ccol; ///< Column of the hit in the cluster + int crow; ///< Row of the hit in the cluster +}; + + + class FTKClusteringPrintout { public: FTKClusteringPrintout cp(); - void printHit(const FTKRawHit &hit); - void printClu(const cluster &clu); void printHitlist(const hitVector& currentHits); - void printClusterList(clustersByModuleMap clustersByModule); void printCentroidList(clustersByModuleMap clustersByModule); + void printClusterList(clustersByModuleMap clustersByModule); + void printCluster(const std::unique_ptr &clu); + void printHit(const FTKRawHit &hit); +private: + bool clusterSort (const FTK_ClusterCoordHit &i, const FTK_ClusterCoordHit &j); }; diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx index d1441eecbc1..c718dafc8bb 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx @@ -14,21 +14,6 @@ #include #include -using namespace std; - -//#define DECODER_INPUT 0 -#define DECODER_OUTPUT 0 -//#define CLUSTERING_PRINTOUT 0 -//#define CENTROID_PRINTOUT 0 -//#define BOUNDING_BOX - -const bool DEBUG_CLUSTERS = 0; - -const bool PRINT_INPUT = 0; // print input data -const bool DEBUG_INPUT = 0; // detail check input -const bool DEBUG_DECODER = 1; // check decoder output -const bool DEBUG_CENTROID = 0; // check centroid calc. - cluster::~cluster() { hitlist.clear(); @@ -269,6 +254,7 @@ void FTKClusteringEngine::makeClusterFromSeed(hitVector& currentHits, cluList& c && seed.getPhiSide() == (chit.get())->getPhiSide() && seed.getTot() == (chit.get())->getTot();})); + Info("makeClusterFromSeed") << "Removed a hit - new size "<< currentHits.size() << "hits" << std::endl; std::unique_ptr clu = std::make_unique(); clu->seed = seed; clu->hitlist.push_back(std::move(std::make_unique(seed))); @@ -285,14 +271,22 @@ void FTKClusteringEngine::makeClustersGridWindow(hitVector& fifo, cluList& curre hitVector gridhits; while (!fifo.empty() || !circular_buffer.empty()) { FTKRawHit seed = gridAUTH(circular_buffer, fifo, gridhits); + Info("makeClustersGridWindow") << "Seed set at " << std::dec + << seed.getTot() << " " << seed.getEtaStrip() + << " " << seed.getPhiSide() << std::endl; + Info("makeClustersGridWindow") << "gridhits: " << gridhits.size() + << " circular_buffer: " << circular_buffer.size() << std::endl; makeClusterFromSeed(gridhits, currentClusters, seed); - for(hitVector::iterator hsi = gridhits.begin(); hsi != gridhits.end(); hsi++) { - circular_buffer.push_back(std::move (*hsi)); + for(auto& hit: gridhits) { + circular_buffer.push_back(std::move (hit)); } gridhits.clear(); + Info("makeClustersGridWindow") << "gridhits: " << gridhits.size() + << " circular_buffer: " << circular_buffer.size() << std::endl; } + Info("makeClustersGridWindow") << "Number of clusters made: " << currentClusters.size() << std::endl; } @@ -775,7 +769,7 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) clu->clusterEquiv.setTruth(mt); } -void FTKClusteringEngine::atlClusteringBlayer(vector &hits) { +void FTKClusteringEngine::atlClusteringBlayer(std::vector &hits) { /* * Split blayer modules in half along phi * this effectively makes 22*2=44 modules along phi! @@ -878,14 +872,33 @@ void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) } } - Info("realisticPixelDecoder") << "Decorer output for Module " << currentHits.front()->getIdentifierHash() << std::endl; + Info("realisticPixelDecoder") << "Decorer output for Module " << std::hex + << currentHits.front()->getIdentifierHash() + << std::dec << std::endl; cp.printHitlist(currentHits); } +void printCB(boost::circular_buffer> &cb) +{ + for (auto& hit: cb) + std::cout << "CB contents: " << hit->getEtaStrip() << " " << hit->getPhiSide() << " " << hit->getTot() << std::endl; + std::cout << " --__--" << std::endl; +} FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer> &cb, hitVector &fifo, hitVector &gridhits) { + + for (const auto&hit: fifo) { + if (hit == nullptr) + Warning("gridAUTH") << "Null hit in fifo!" << std::endl; + else + Info("gridAUTH") << "fifo contents:" << hit.get()->getEtaStrip() << " " << hit.get()->getPhiSide() << std::endl; + } + + Info("gridAUTH") << "fifo: " << fifo.size() + << " circular_buffer: " << cb.size() + << " gridhits: " << gridhits.size() << std::endl; //seed is set from cb if there are hits and from //fifo if the seed is empty. std::unique_ptr seed; @@ -897,15 +910,19 @@ FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer(*cbi); else if ((*cbi).getEtaStrip() == (*seed).getEtaStrip()) { - if ((*cbi).getPhiSide() < (*seed).getPhiSide() && !isIBLmodule) //Keisuke 20170215 - seed.swap(cbi); + if ((*cbi).getPhiSide() < (*seed).getPhiSide() && !isIBLmodule) + seed = std::make_unique(*cbi); else if ((*cbi).getPhiSide() > (*seed).getPhiSide() && isIBLmodule) - seed.swap(cbi); + seed = std::make_unique(*cbi); } } } + + Info("gridAUTH") << "Seed set at " << seed->getEtaStrip() << " " << seed->getPhiSide() << std::endl; + printCB(cb); + // //step 2: set grid window limits int gridStrCol ; if ((*seed).getEtaStrip() % 2 != 0) @@ -914,34 +931,61 @@ FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffergetEtaStrip() + << " " << cb.front().get()->getPhiSide() + << " " << cb.front().get()->getTot() << std::endl; if (!hitColInGrid(gridStrCol, cb.front())) { + Info("gridAUTH") << "column outside grid, go on" << std::endl; cb.pop_front(); continue; } - if (hitRowInGrid(gridCntRow, cb.front())) + if (hitRowInGrid(gridCntRow, cb.front())) { + Info("gridAUTH") << "hit pushed to gridhits" << std::endl; gridhits.push_back(std::move(cb.front())); - else + } + else { + Info("gridAUTH") << "hit pushed again to cb" << std::endl; cb.push_back(std::move(cb.front())); + } cb.pop_front(); } + Info("gridAUTH") << "fifo: " << fifo.size() + << " circular_buffer: " << cb.size() + << " gridhits: " << gridhits.size() << std::endl; + + Info("gridAUTH") << "Transferring hits from fifo to the grid window" << std::endl; //step 4: put hits from fifo to the grid window - for (auto& hit: fifo) { - if (!hitColInGrid(gridStrCol, hit)) { + std::vector>::iterator hit = fifo.begin(); + while (hit != fifo.end()) { + if (!hitColInGrid(gridStrCol, (*hit).get() )) { break; } - if (hitRowInGrid(gridCntRow, hit)) { - gridhits.push_back(std::move(hit)); + if (hitRowInGrid(gridCntRow, (*hit).get())) { + gridhits.push_back(std::move(*hit)); } else { - cb.push_back(std::move(hit)); + Info("gridAUTH") << "Pushed to CB:" << (*hit)->getEtaStrip() + << " " << (*hit)->getPhiSide() + << " " << (*hit)->getTot() + << std::endl; + cb.push_back(std::move(*hit)); } + fifo.erase(hit); } - fifo.clear(); - + Info("gridAUTH") << "fifo: " << fifo.size() + << " circular_buffer: " << cb.size() + << " gridhits: " << gridhits.size() << std::endl; return *seed.get(); } @@ -953,7 +997,7 @@ FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer &hits) +void FTKClusteringEngine::atlClusteringLNF(std::vector &hits) { /* * Step 1: Organize the hits by the module they belong to. Furthermore, the @@ -999,7 +1043,9 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) makeClustersLNF(currentHits, currentClusters); } else if (pixelClusteringMode >= PIXEL_CLUSTERING_MIXED) { + Info("atlClusteringLNF") << std::hex << "Module " << modId << " clustering start" << std::dec << std::endl; realisticPixelDecoder(currentHits); + Info("atlClusteringLNF") << std::hex << "Module " << modId << " decoder done" << std::dec << std::endl; makeClustersGridWindow(currentHits, currentClusters); } @@ -1012,9 +1058,10 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) * Third: take the "average" of each cluster */ int nTotClu = 0; - clustersByModuleMap::iterator cluModP; // loop over modules for (auto& module: clustersByModule) { hitVector connectedHits; // list of ganged hits that are connected to a confirmed ganged hit + Info("atlClusteringBlayer") << "Module " << std::hex << module.first + << " has " << std::dec << module.second.size() << " hits" << std::endl; for (auto& clu: module.second) { // do pattern recognition in the ganged region if ( (clu->hitlist.front())->getIsPixel() && findConnectedGanged(clu, connectedHits) ) // set isSafe @@ -1035,6 +1082,9 @@ void FTKClusteringEngine::atlClusteringLNF(vector &hits) // } } + // Info("atlClusteringLNF") << "Printing centroids" << std::endl; + // cp.printCentroidList(clustersByModule); + /* * Fourth: put clusters/hits back in the event hit list */ diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx index 267cf03b0b4..3552b477e3d 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx @@ -27,26 +27,27 @@ const bool DEBUG_CENTROID = 0; // check centroid calc. */ void FTKClusteringPrintout::printHit(const FTKRawHit &hit) { - std::cout << "DEBUG_HITS: " + std::cout << " Hit details: " << " isPixel=" << hit.getIsPixel() << " barrel_ec=" << hit.getBarrelEC() << " layer_disk=" << hit.getLayer() - << " phi_module=" << hit.getPhiModule() - << " eta_module=" << hit.getEtaModule() - << " pi_side=" << hit.getPhiSide() + // << " phi_module=" << hit.getPhiModule() + // << " eta_module=" << hit.getEtaModule() << " ei_strip=" << hit.getEtaStrip() + << " pi_side=" << hit.getPhiSide() + << " tot" << hit.getTot() << " n_strips=" << hit.getNStrips() - << " deltaPhi=" << hit.getDeltaPhi() - << " deltaEta=" << hit.getDeltaEta() - << " eventindex=" << hit.getEventIndex() - << " barcode=" << hit.getBarcode() - << " bar_pt=" << hit.getBarcodePt() - << " parentage_mask=" << hit.getParentageMask() - << " )\n"; + // << " deltaPhi=" << hit.getDeltaPhi() + // << " deltaEta=" << hit.getDeltaEta() + // << " eventindex=" << hit.getEventIndex() + // << " barcode=" << hit.getBarcode() + // << " bar_pt=" << hit.getBarcodePt() + // << " parentage_mask=" << hit.getParentageMask() + << "\n"; } -bool clusterSort (const FTK_ClusterCoordHit &i, const FTK_ClusterCoordHit &j) +bool FTKClusteringPrintout::clusterSort (const FTK_ClusterCoordHit &i, const FTK_ClusterCoordHit &j) { // reverse the hits on the first row if they are above the seed if (i.ccol == 0 && j.ccol == 0 && i.crow <= 10 && j.crow <= 10) @@ -57,18 +58,16 @@ bool clusterSort (const FTK_ClusterCoordHit &i, const FTK_ClusterCoordHit &j) return i.ccol <= j.ccol; } -void FTKClusteringPrintout::printClu(const cluster &clu) +void FTKClusteringPrintout::printCluster(const std::unique_ptr &clu) { - // hitVector hs = clu.hitlist; - // hitVector::iterator hit = hs.begin(); - - // std::vector tmp; - // for (hit = hs.begin(); hit != hs.end(); hit++) { - // tmp.push_back(FTK_ClusterCoordHit(*hit, clu.seed)); - // } + std::vector tmp; + for (auto &hit: clu->hitlist) { + tmp.push_back(FTK_ClusterCoordHit(*hit, clu->seed)); + } // //sort and print the vector. - // if (tmp.size() > 1) std::stable_sort(tmp.begin(), tmp.end(), clusterSort); + // if (tmp.size() > 1) + // std::stable_sort(tmp.begin(), tmp.end(), clusterSort); // for(std::vector::iterator hit1 = tmp.begin(); hit1 != tmp.end(); hit1++) { // // printf("0000%.2X%.2X%.3X\n",(*hit1).tot, (*hit1).ccol, (*hit1).crow); @@ -94,22 +93,18 @@ void FTKClusteringPrintout::printClu(const cluster &clu) // } } -void printClusterList(clustersByModuleMap clustersByModule) +void FTKClusteringPrintout::printClusterList(clustersByModuleMap clustersByModule) { - // for (auto& cl: clustersByModule) { // loop over modules - // cluList cl = cl.second; - // cluList::iterator b = cl.begin(); - // FTKRawHit* hit = (*b).hitlist[0]; - // printf("0x200000%02d\n", (*hit).getIdentifierHash()); - // for (; b != cl->end(); b++) { - // printClu(*b); - // } + for (auto& module: clustersByModule) { // loop over modules + for (auto &cluster: module.second) { + printCluster(cluster); + } // printf("0x40000000\n"); - // } + } } -void printCentroidList(clustersByModuleMap clustersByModule) +void FTKClusteringPrintout::printCentroidList(clustersByModuleMap clustersByModule) { // clustersByModuleMap::iterator p; // for (p = clustersByModule.begin(); p!=clustersByModule.end(); ++p) { // loop over modules @@ -175,9 +170,9 @@ void FTKClusteringPrintout::printHitlist(const hitVector& hitlist) // bool isIBLmodule = (h.getModuleType() == ftk::MODULETYPE_IBL3D || h.getModuleType() == ftk::MODULETYPE_IBL_PLANAR); // int idHash = h.getIdentifierHash() + 8; - printf("0x08%.7x Module: %d\n", (hitlist.front()->getIdentifierHash())); + printf("0x08%.7x\n", (hitlist.front()->getIdentifierHash())); for(const auto& hit: hitlist) { - printf("0x00%.2x%.2x%.3x\n", hit->getTot(), hit->getEtaStrip(), hit->getPhiSide()); + printf("0x00%.2x%.2x%.3x", hit->getTot(), hit->getEtaStrip(), hit->getPhiSide()); printHit(*(hit.get())); } } -- GitLab From 8a3db4c17e80942c21270289d64a2e8df5d8c8fe Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Mon, 18 Mar 2019 18:23:12 +0100 Subject: [PATCH 14/18] all module types bit accurate --- .../TrigFTKSim/src/FTKClusteringEngine.cxx | 65 ++++++++++--------- .../TrigFTKSim/src/FTKClusteringPrintout.cxx | 6 +- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx index c718dafc8bb..54cb2c84ef4 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx @@ -64,24 +64,28 @@ bool FTKClusteringEngine::sortPixelInput (const std::unique_ptr& i, c bool FTKClusteringEngine::sortIBLInput(const std::unique_ptr& i, const std::unique_ptr& j) { - int firstCol = i->getEtaStrip() + 1; - int secondCol = j->getEtaStrip() + 1; - int firstRow = 335 - i->getPhiSide(); // Keisuke 20170314, start from 0 - int secondRow = 335 - j->getPhiSide(); // Keisuke 20170314, start from 0 - int firstFE = (firstCol <= 80) ? 0 : 1; - int secondFE = (secondCol <= 80) ? 0 : 1; + int firstCol = i->getEtaStrip(); + int secondCol = j->getEtaStrip(); + int firstRow = i->getPhiSide(); // Keisuke 20170314, start from 0 + int secondRow = j->getPhiSide(); // Keisuke 20170314, start from 0 + int firstFE = (firstCol < 80) ? 0 : 1; + int secondFE = (secondCol < 80) ? 0 : 1; - if(firstCol >= 81) firstCol = firstCol - 80; - if(secondCol >= 81) secondCol = secondCol - 80; + if(firstCol >= 80) firstCol = firstCol - 79; + if(secondCol >= 80) secondCol = secondCol - 79; if (firstFE != secondFE) return firstFE > secondFE; else{ - if(firstCol <= 40 || secondCol <= 40){ - if(firstCol != secondCol) return firstCol < secondCol; - else return firstRow < secondRow; + if(firstCol < 40 || secondCol < 40){ + if(firstCol != secondCol) + return firstCol < secondCol; + else + return firstRow < secondRow; } else { - if(firstCol != secondCol) return firstCol > secondCol; - else return firstRow < secondRow; + if(firstCol != secondCol) + return firstCol > secondCol; + else + return firstRow < secondRow; } } return false; @@ -95,8 +99,6 @@ bool FTKClusteringEngine::sortIBLInput(const std::unique_ptr& i, cons bool FTKClusteringEngine::isSplitCluster(const std::unique_ptr& clu) { for (auto& hit: clu->hitlist) { - // if (clu.seed == NULL) - // return false; FTK_ClusterCoordHit chit = FTK_ClusterCoordHit(*hit , clu->seed); if ((chit.ccol >= GRID_COL_MAX - 1) || (chit.crow >= (GRID_ROW_MAX - 1)) || ( chit.crow <= 0)) return true; @@ -271,11 +273,6 @@ void FTKClusteringEngine::makeClustersGridWindow(hitVector& fifo, cluList& curre hitVector gridhits; while (!fifo.empty() || !circular_buffer.empty()) { FTKRawHit seed = gridAUTH(circular_buffer, fifo, gridhits); - Info("makeClustersGridWindow") << "Seed set at " << std::dec - << seed.getTot() << " " << seed.getEtaStrip() - << " " << seed.getPhiSide() << std::endl; - Info("makeClustersGridWindow") << "gridhits: " << gridhits.size() - << " circular_buffer: " << circular_buffer.size() << std::endl; makeClusterFromSeed(gridhits, currentClusters, seed); for(auto& hit: gridhits) { @@ -283,8 +280,6 @@ void FTKClusteringEngine::makeClustersGridWindow(hitVector& fifo, cluList& curre } gridhits.clear(); - Info("makeClustersGridWindow") << "gridhits: " << gridhits.size() - << " circular_buffer: " << circular_buffer.size() << std::endl; } Info("makeClustersGridWindow") << "Number of clusters made: " << currentClusters.size() << std::endl; } @@ -540,8 +535,6 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) if (FEcolumn==0) col -= pixYScaleFactor/4; // correct position for first column in FE chip if (FEcolumn==(ftk::clustering::colsInFEChipPerPixelModuleRow-1)) col += pixYScaleFactor/4; // correct position for last column in FE chip } else if (isIBLmodule) { // IBL case - row = 335 - hit->getPhiSide(); // inverse row coordinates // Yoshi 2016.10.28 // JAA updated 17.3.13 - //Modifications have to be made to include 3d modules int orig_col = col; col *= pixYScaleFactor; // use units of 25um @@ -586,7 +579,7 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) qColMax = tot; } - int phi = 335 - hit->getPhiSide(); // ROW // JAA updated 13 March 2017 to remove +1 as above + int phi = hit->getPhiSide(); // ROW // JAA updated 13 March 2017 to remove +1 as above // int phi = (*p)->getPhiSide(); // ROW int eta = hit->getEtaStrip(); // COLUMN @@ -793,8 +786,11 @@ void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) { std::stack> lifo; std::queue> fifo; + bool getIsIBL = hitOnIBLmodule(*currentHits.front()); + if (getIsIBL) + std::cout << "yep, ibl module" << std::endl; - if(currentHits.front()->getIsPixel()){ + if(!getIsIBL) { if (currentHits.size() > 1) std::stable_sort(currentHits.begin(), currentHits.end(), sortPixelInput); @@ -832,6 +828,14 @@ void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) std::stack> lifo_planar; std::queue> fifo_planar; + //invert row coordinates + for(auto& hit: currentHits) { + std::unique_ptr h = std::make_unique(*hit); + h->setPhiSide( 335 - (*hit).getPhiSide() ); + h->setEtaStrip( (*hit).getEtaStrip()) ; + hit.swap(h); + } + if (currentHits.size() > 1) std::stable_sort(currentHits.begin(), currentHits.end(), sortIBLInput); @@ -908,14 +912,15 @@ FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer(*cb.front()); bool isIBLmodule = hitOnIBLmodule(*(seed.get())); + Info("gridAUTH") << "isIBLmodule " << isIBLmodule << std::endl; for(auto& cbi: cb) { if ((*cbi).getEtaStrip() < (*seed).getEtaStrip()) seed = std::make_unique(*cbi); else if ((*cbi).getEtaStrip() == (*seed).getEtaStrip()) { - if ((*cbi).getPhiSide() < (*seed).getPhiSide() && !isIBLmodule) - seed = std::make_unique(*cbi); - else if ((*cbi).getPhiSide() > (*seed).getPhiSide() && isIBLmodule) + if ((*cbi).getPhiSide() < (*seed).getPhiSide() ) seed = std::make_unique(*cbi); + // else if ((*cbi).getPhiSide() > (*seed).getPhiSide() && isIBLmodule) + // seed = std::make_unique(*cbi); } } } @@ -1060,7 +1065,7 @@ void FTKClusteringEngine::atlClusteringLNF(std::vector &hits) int nTotClu = 0; for (auto& module: clustersByModule) { hitVector connectedHits; // list of ganged hits that are connected to a confirmed ganged hit - Info("atlClusteringBlayer") << "Module " << std::hex << module.first + Info("atlClusteringLNF") << "Module " << std::hex << module.first << " has " << std::dec << module.second.size() << " hits" << std::endl; for (auto& clu: module.second) { // do pattern recognition in the ganged region diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx index 3552b477e3d..6288a488e77 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringPrintout.cxx @@ -33,9 +33,9 @@ void FTKClusteringPrintout::printHit(const FTKRawHit &hit) << " layer_disk=" << hit.getLayer() // << " phi_module=" << hit.getPhiModule() // << " eta_module=" << hit.getEtaModule() - << " ei_strip=" << hit.getEtaStrip() - << " pi_side=" << hit.getPhiSide() - << " tot" << hit.getTot() + << " eta_strip=" << hit.getEtaStrip() + << " phi_side=" << hit.getPhiSide() + << " tot=" << hit.getTot() << " n_strips=" << hit.getNStrips() // << " deltaPhi=" << hit.getDeltaPhi() // << " deltaEta=" << hit.getDeltaEta() -- GitLab From 7e219ac7b07c2ad62088901164079d770fc13080 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Tue, 19 Mar 2019 10:28:05 +0100 Subject: [PATCH 15/18] small improvements --- .../TrigFTKSim/FTKClusteringEngine.h | 7 +- .../TrigFTKSim/src/FTKClusteringEngine.cxx | 139 +++++------------- 2 files changed, 39 insertions(+), 107 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h index e6ec1d0690d..bd4789765c8 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKClusteringEngine.h @@ -15,6 +15,7 @@ (hit->getPhiSide() >= gridCntRow - GRID_ROW_MAX / 2))? true : false #define hitColInGrid(gridStrCol, hit) (hit->getEtaStrip() < gridStrCol + GRID_COL_MAX)? true : false +#include #include #include #include @@ -22,7 +23,7 @@ #include typedef std::vector> hitVector; -typedef std::map hitsByModuleMap; +typedef std::map hitsByModuleMap; class cluster { @@ -38,7 +39,7 @@ public: typedef std::vector> cluList; -typedef std::map clustersByModuleMap; +typedef std::map clustersByModuleMap; /** * This class creates a hit whose coordinates are relative to the Front-End chip @@ -109,7 +110,7 @@ private: static bool sortIBLInput(const std::unique_ptr& i, const std::unique_ptr& j); bool isSplitCluster(const std::unique_ptr& clu); bool hitOnIBLmodule(const FTKRawHit &hit); - int hitToModuleId(const FTKRawHit &hit); + uint32_t getModuleId(const FTKRawHit &hit); void realisticPixelDecoder(hitVector& currentHits); diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx index 54cb2c84ef4..1074196314f 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx @@ -107,29 +107,6 @@ bool FTKClusteringEngine::isSplitCluster(const std::unique_ptr& clu) return false; } -/*! - * Function examining whether the a given row has ganged pixels - * \param the row to be examined - * \return true - */ -bool FTKClusteringEngine::pixelRowIsGanged(const int row) -{ - switch (row) { - case 153: - case 155: - case 157: - case 159: - case 168: - case 170: - case 172: - case 174: - return row; // pixel ganged found (readout channel) - } - if (160<=row && row<=167) - return row; // pixel ganged found (non readout channel) - return false; -} - /*! * Function calculating the module id in which the hit belongs to. * The default mode for now is to check the Identifier Hash of the hit. @@ -137,7 +114,7 @@ bool FTKClusteringEngine::pixelRowIsGanged(const int row) * \return the module id * */ -int FTKClusteringEngine::hitToModuleId(const FTKRawHit &hit) +uint32_t FTKClusteringEngine::getModuleId(const FTKRawHit &hit) { return hit.getHitType() == ftk::PIXEL ? hit.getIdentifierHash() : 0x8000 + hit.getIdentifierHash(); } @@ -256,7 +233,6 @@ void FTKClusteringEngine::makeClusterFromSeed(hitVector& currentHits, cluList& c && seed.getPhiSide() == (chit.get())->getPhiSide() && seed.getTot() == (chit.get())->getTot();})); - Info("makeClusterFromSeed") << "Removed a hit - new size "<< currentHits.size() << "hits" << std::endl; std::unique_ptr clu = std::make_unique(); clu->seed = seed; clu->hitlist.push_back(std::move(std::make_unique(seed))); @@ -281,7 +257,6 @@ void FTKClusteringEngine::makeClustersGridWindow(hitVector& fifo, cluList& curre gridhits.clear(); } - Info("makeClustersGridWindow") << "Number of clusters made: " << currentClusters.size() << std::endl; } @@ -876,33 +851,13 @@ void FTKClusteringEngine::realisticPixelDecoder(hitVector ¤tHits) } } - Info("realisticPixelDecoder") << "Decorer output for Module " << std::hex - << currentHits.front()->getIdentifierHash() - << std::dec << std::endl; - cp.printHitlist(currentHits); -} - -void printCB(boost::circular_buffer> &cb) -{ - for (auto& hit: cb) - std::cout << "CB contents: " << hit->getEtaStrip() << " " << hit->getPhiSide() << " " << hit->getTot() << std::endl; - std::cout << " --__--" << std::endl; + // cp.printHitlist(currentHits); } FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer> &cb, hitVector &fifo, hitVector &gridhits) { - for (const auto&hit: fifo) { - if (hit == nullptr) - Warning("gridAUTH") << "Null hit in fifo!" << std::endl; - else - Info("gridAUTH") << "fifo contents:" << hit.get()->getEtaStrip() << " " << hit.get()->getPhiSide() << std::endl; - } - - Info("gridAUTH") << "fifo: " << fifo.size() - << " circular_buffer: " << cb.size() - << " gridhits: " << gridhits.size() << std::endl; //seed is set from cb if there are hits and from //fifo if the seed is empty. std::unique_ptr seed; @@ -911,65 +866,36 @@ FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffer(*cb.front()); - bool isIBLmodule = hitOnIBLmodule(*(seed.get())); - Info("gridAUTH") << "isIBLmodule " << isIBLmodule << std::endl; for(auto& cbi: cb) { if ((*cbi).getEtaStrip() < (*seed).getEtaStrip()) seed = std::make_unique(*cbi); else if ((*cbi).getEtaStrip() == (*seed).getEtaStrip()) { if ((*cbi).getPhiSide() < (*seed).getPhiSide() ) seed = std::make_unique(*cbi); - // else if ((*cbi).getPhiSide() > (*seed).getPhiSide() && isIBLmodule) - // seed = std::make_unique(*cbi); } } } - Info("gridAUTH") << "Seed set at " << seed->getEtaStrip() << " " << seed->getPhiSide() << std::endl; - printCB(cb); - - // //step 2: set grid window limits - int gridStrCol ; - if ((*seed).getEtaStrip() % 2 != 0) - gridStrCol = (*seed).getEtaStrip() - 1; - else - gridStrCol = (*seed).getEtaStrip(); + //step 2: set grid window limits + int gridStrCol = ((*seed).getEtaStrip() % 2 != 0) ? (*seed).getEtaStrip() - 1 : (*seed).getEtaStrip(); int gridCntRow = (*seed).getPhiSide(); - Info("gridAUTH") << "gridStrCol:" << gridStrCol << " gridCntRow:" << gridCntRow << std::endl; - Info("gridAUTH") << "fifo: " << fifo.size() - << " circular_buffer: " << cb.size() - << " gridhits: " << gridhits.size() << std::endl; - - // //step 3: put hits from cb to the grid window + //step 3: put hits from cb to the grid window int dist = distance(cb.begin(), cb.end()); - Info("gridAUTH") << "Transferring hits from cb to the grid window" << std::endl; for(int i = 0; i < dist; i++) { - printCB(cb); - Info("gridAUTH") << "ch hit: " << cb.front().get()->getEtaStrip() - << " " << cb.front().get()->getPhiSide() - << " " << cb.front().get()->getTot() << std::endl; if (!hitColInGrid(gridStrCol, cb.front())) { - Info("gridAUTH") << "column outside grid, go on" << std::endl; cb.pop_front(); continue; } if (hitRowInGrid(gridCntRow, cb.front())) { - Info("gridAUTH") << "hit pushed to gridhits" << std::endl; gridhits.push_back(std::move(cb.front())); } else { - Info("gridAUTH") << "hit pushed again to cb" << std::endl; cb.push_back(std::move(cb.front())); } cb.pop_front(); } - Info("gridAUTH") << "fifo: " << fifo.size() - << " circular_buffer: " << cb.size() - << " gridhits: " << gridhits.size() << std::endl; - - Info("gridAUTH") << "Transferring hits from fifo to the grid window" << std::endl; //step 4: put hits from fifo to the grid window std::vector>::iterator hit = fifo.begin(); while (hit != fifo.end()) { @@ -980,17 +906,11 @@ FTKRawHit FTKClusteringEngine::gridAUTH(boost::circular_buffergetEtaStrip() - << " " << (*hit)->getPhiSide() - << " " << (*hit)->getTot() - << std::endl; cb.push_back(std::move(*hit)); } fifo.erase(hit); } - Info("gridAUTH") << "fifo: " << fifo.size() - << " circular_buffer: " << cb.size() - << " gridhits: " << gridhits.size() << std::endl; + return *seed.get(); } @@ -1014,7 +934,7 @@ void FTKClusteringEngine::atlClusteringLNF(std::vector &hits) gangedPixelList.reserve(hits.size()); // reserve memory in excess for(const auto& hit: hits) { - int modId = hitToModuleId(hit); + int modId = getModuleId(hit); if (modId<0) Error("atlClusteringLNF") << "modId < 0" << std::endl; hitsByModule[modId].push_back( std::make_unique(hit) ); @@ -1036,21 +956,18 @@ void FTKClusteringEngine::atlClusteringLNF(std::vector &hits) for (auto& module: hitsByModule) { // loop over modules int modId = module.first; hitVector currentHits = std::move(module.second); - FTKRawHit firstHit = *(currentHits.front()).get(); cluList currentClusters; // instantiate cluster list - if (firstHit.getIsSCT()){ + if (currentHits.front()->getIsSCT()){ makeClustersLNF(currentHits, currentClusters); // use ideal clustering } - else if(firstHit.getIsPixel()) { + else if(currentHits.front()->getIsPixel()) { if (pixelClusteringMode < PIXEL_CLUSTERING_MIXED) { makeClustersLNF(currentHits, currentClusters); } else if (pixelClusteringMode >= PIXEL_CLUSTERING_MIXED) { - Info("atlClusteringLNF") << std::hex << "Module " << modId << " clustering start" << std::dec << std::endl; realisticPixelDecoder(currentHits); - Info("atlClusteringLNF") << std::hex << "Module " << modId << " decoder done" << std::dec << std::endl; makeClustersGridWindow(currentHits, currentClusters); } @@ -1065,8 +982,6 @@ void FTKClusteringEngine::atlClusteringLNF(std::vector &hits) int nTotClu = 0; for (auto& module: clustersByModule) { hitVector connectedHits; // list of ganged hits that are connected to a confirmed ganged hit - Info("atlClusteringLNF") << "Module " << std::hex << module.first - << " has " << std::dec << module.second.size() << " hits" << std::endl; for (auto& clu: module.second) { // do pattern recognition in the ganged region if ( (clu->hitlist.front())->getIsPixel() && findConnectedGanged(clu, connectedHits) ) // set isSafe @@ -1079,17 +994,8 @@ void FTKClusteringEngine::atlClusteringLNF(std::vector &hits) averageCluster(clu); nTotClu++; // count all clusters } - - // delete connected hits - // hitVector::iterator connectedP; - // for (connectedP = connectedHits.begin(); connectedP!=connectedHits.end(); ++connectedP) { - // delete (*connectedP); - // } } - // Info("atlClusteringLNF") << "Printing centroids" << std::endl; - // cp.printCentroidList(clustersByModule); - /* * Fourth: put clusters/hits back in the event hit list */ @@ -1118,12 +1024,12 @@ void FTKClusteringEngine::atlClusteringLNF(std::vector &hits) /* * Fifth: free memory (could optimize and do this in previous step) */ - // The atlhit data from event is allocated and destroyed outside this function. // clustersByModuleMap is automatically deleted. clustersByModule.clear(); } + /*! * Function examining if a hit is ganged. In case the hit belongs to a pixel * module and at a row with ganged pixels, the phi coordinate of the pixel is @@ -1185,6 +1091,31 @@ int FTKClusteringEngine::gangedPartner(const FTKRawHit &hit) { return -1; } + +/*! + * Function examining whether the a given row has ganged pixels + * \param the row to be examined + * \return true + */ +bool FTKClusteringEngine::pixelRowIsGanged(const int row) +{ + switch (row) { + case 153: + case 155: + case 157: + case 159: + case 168: + case 170: + case 172: + case 174: + return row; // pixel ganged found (readout channel) + } + if (160<=row && row<=167) + return row; // pixel ganged found (non readout channel) + return false; +} + + double FTKClusteringEngine::getDeltaX1A(const std::unique_ptr& clu) { FTKRawHit first = *(clu->hitlist.front()); -- GitLab From 77c6435e01b21624925218c1d6b5b5d5c04d00c4 Mon Sep 17 00:00:00 2001 From: Stamatios Gkaitatzis Date: Wed, 20 Mar 2019 12:53:44 +0100 Subject: [PATCH 16/18] Removed STTtrk, x, y, z functions from FTKRawHit --- .../TrigFTK/TrigFTKSim/TrigFTKSim/FTKPMap.h | 194 +- .../TrigFTK/TrigFTKSim/TrigFTKSim/FTKRawHit.h | 42 +- .../TrigFTKSim/TrigFTKSim/FTKRoadFinderAlgo.h | 297 ++- .../TrigFTKSim/TrigFTKSim/FTKRoadOutput.h | 1 - .../TrigFTKSim/TrigFTKSim/FTKRoadStream.h | 330 ++- .../TrigFTK/TrigFTKSim/TrigFTKSim/FTKSetup.h | 165 +- .../TrigFTKSim/FTKTrackFitterAlgo.h | 194 +- .../TrigFTKSim/TrigFTKSim/FTK_RoadMarketIO.h | 1 - .../TrigFTKSim/FTK_RoadMarketTool.h | 70 +- .../TrigFTKSim/FTK_RoadMarketToolI.h | 30 +- .../TrigFTKSim/TrigFTKSim/RoadFinder.h | 100 +- .../TrigFTK/TrigFTKSim/TrigFTKSim/ftkdefs.h | 3 +- .../TrigFTKSim/src/FTKClusteringEngine.cxx | 46 - .../TrigFTK/TrigFTKSim/src/FTKDataInput.cxx | 70 +- .../TrigFTK/TrigFTKSim/src/FTKMergerAlgo.cxx | 1 - Trigger/TrigFTK/TrigFTKSim/src/FTKPMap.cxx | 1750 ++++++++------- Trigger/TrigFTK/TrigFTKSim/src/FTKRawHit.cxx | 692 +++--- .../TrigFTKSim/src/FTKRoadFileOutput.cxx | 5 - .../TrigFTKSim/src/FTKRoadFinderAlgo.cxx | 1077 +++++---- .../TrigFTK/TrigFTKSim/src/FTKRoadStream.cxx | 844 ++++---- Trigger/TrigFTK/TrigFTKSim/src/FTKSetup.cxx | 340 +-- .../TrigFTKSim/src/FTKTrackFitterAlgo.cxx | 1056 +++++---- .../TrigFTKSim/src/FTK_RoadMarketIO.cxx | 6 - .../TrigFTK/TrigFTKSim/src/FTK_SGHitInput.cxx | 1917 ++++++++--------- Trigger/TrigFTK/TrigFTKSim/src/RoadFinder.cxx | 657 ++---- .../TrigFTK/TrigFTKSim/src/TrackFitter.cxx | 1786 ++++++++------- 26 files changed, 5570 insertions(+), 6104 deletions(-) diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKPMap.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKPMap.h index 325a1b68e63..ff32ed0ac05 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKPMap.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKPMap.h @@ -15,19 +15,19 @@ class */ class FTKPlaneSection { private: - int m_plane; // plane ID - int m_section; // section ID + int m_plane; // plane ID + int m_section; // section ID public: - FTKPlaneSection(); - FTKPlaneSection(int, int); - virtual ~FTKPlaneSection() {;} + FTKPlaneSection(); + FTKPlaneSection(int, int); + virtual ~FTKPlaneSection() {;} - int getPlane() const { return m_plane; } - int getSection() const { return m_section; } + int getPlane() const { return m_plane; } + int getSection() const { return m_section; } - void setPlane(int v) { m_plane = v; } - void setSection(int v) { m_section = v; } + void setPlane(int v) { m_plane = v; } + void setSection(int v) { m_section = v; } }; @@ -40,45 +40,45 @@ public: */ class FTKModuleInfo { private: - int m_isEndcap; /* 0 = barrel, 1 = endcap */ - int m_layer; /**< physical layer number */ - int m_pdisk; /**< actual physical disk; signed, 1-indexed disk number, barrel is zero */ - int m_nphi; /**< max phi index */ - int m_neta; /**< max eta index */ - int m_nfi; /**< max par index */ // cy addition - phi for SCTtrk - int m_ncott; /**< max par index */ // cy addition - int m_ncurv; /**< max par index */ // cy addition - int m_nste; - int m_ndimension; + int m_isEndcap; /* 0 = barrel, 1 = endcap */ + int m_layer; /**< physical layer number */ + int m_pdisk; /**< actual physical disk; signed, 1-indexed disk number, barrel is zero */ + int m_nphi; /**< max phi index */ + int m_neta; /**< max eta index */ + int m_nfi; /**< max par index */ // cy addition - phi for SCTtrk + int m_ncott; /**< max par index */ // cy addition + int m_ncurv; /**< max par index */ // cy addition + int m_nste; + int m_ndimension; public: - FTKModuleInfo(); - FTKModuleInfo(int isEndcap,int layer,int pdisk, - int nphi,int neta,int nfi,int ncott,int ncurv,int nste,int ndimension); - virtual ~FTKModuleInfo() {;} - - int getIsEndcap() const { return m_isEndcap; } - int getLayer() const { return m_layer; } - int getPDisk() const { return m_pdisk; } - int getNumPhi() const { return m_nphi; } - int getNumEta() const { return m_neta; } - int getNumFi() const { return m_nfi; } - int getNumCott() const { return m_ncott; } - int getNumCurv() const { return m_ncurv; } - int getNSte() const { return m_nste; } - int getNDimension() const { return m_ndimension; } - - void setIsEndcap(int v) { m_isEndcap = v; } - void setLayer(int v) { m_layer = v; } - void setPDisk(int v) { m_pdisk = v; } - void setNumPhi(int v) { m_nphi = v; } - void setNumEta(int v) { m_neta = v; } - void setNumFi(int v) { m_nfi = v; } - void setNumCott(int v) { m_ncott = v; } - void setNumCurv(int v) { m_ncurv = v; } - void setNSte(int v) { m_nste = v; } - void setNDimension(int v) { m_ndimension = v; } + FTKModuleInfo(); + FTKModuleInfo(int isEndcap,int layer,int pdisk, + int nphi,int neta,int nfi,int ncott,int ncurv,int nste,int ndimension); + virtual ~FTKModuleInfo() {;} + + int getIsEndcap() const { return m_isEndcap; } + int getLayer() const { return m_layer; } + int getPDisk() const { return m_pdisk; } + int getNumPhi() const { return m_nphi; } + int getNumEta() const { return m_neta; } + int getNumFi() const { return m_nfi; } + int getNumCott() const { return m_ncott; } + int getNumCurv() const { return m_ncurv; } + int getNSte() const { return m_nste; } + int getNDimension() const { return m_ndimension; } + + void setIsEndcap(int v) { m_isEndcap = v; } + void setLayer(int v) { m_layer = v; } + void setPDisk(int v) { m_pdisk = v; } + void setNumPhi(int v) { m_nphi = v; } + void setNumEta(int v) { m_neta = v; } + void setNumFi(int v) { m_ncott = v; } + void setNumCott(int v) { m_ncott = v; } + void setNumCurv(int v) { m_ncurv = v; } + void setNSte(int v) { m_nste = v; } + void setNDimension(int v) { m_ndimension = v; } }; @@ -86,75 +86,73 @@ public: used by FTK */ class FTKPlaneMap { private: - std::string m_path; // coniguration file path - int m_nplanes; // number of used detector planes - //int m_nlayers; // number of detector layers - int m_rlayers; // - int m_totaldim; // dimension of the coordinates - int *m_planeType; // SCT / PIXEL / SCTtrk - int *m_isZ; // legacy (unused) - int *m_planePair; - bool m_enablePlanePair; // if true the SCT pairing is activated, effect on getPlanePair(int) method - int *m_idim[2]; - int *m_nsections; // number of sections in the used planes - /* First index: PIXEL/SCT/SCTtrk - * Second index: BARREL/ENDCAP - * returns a pair: (plane,section) - */ - FTKPlaneSection *m_map[ftk::NHITTYPES][2]; - FTKModuleInfo **m_planes; // used modules information - bool m_isok; // false if there were error during configuration + std::string m_path; // coniguration file path + int m_nplanes; // number of used detector planes + //int m_nlayers; // number of detector layers + int m_rlayers; // + int m_totaldim; // dimension of the coordinates + int *m_planeType; // SCT / PIXEL + int *m_isZ; // legacy (unused) + int *m_planePair; + bool m_enablePlanePair; // if true the SCT pairing is activated, effect on getPlanePair(int) method + int *m_idim[2]; + int *m_nsections; // number of sections in the used planes + /* First index: PIXEL/SCT/SCT + * Second index: BARREL/ENDCAP + * returns a pair: (plane,section) + */ + FTKPlaneSection *m_map[ftk::NHITTYPES][2]; + FTKModuleInfo **m_planes; // used modules information + bool m_isok; // false if there were error during configuration protected: - static const TString s_dirname; - static int GetConst(TDirectory* file, TString ConstName); + static const TString s_dirname; + static int GetConst(TDirectory* file, TString ConstName); public: - FTKPlaneMap(const char *); - FTKPlaneMap(TDirectory* file); //!< used for instantiation from root file - ~FTKPlaneMap(); - - // interface to rootfile - void WriteMapToRootFile(TDirectory* dir); - static FTKPlaneMap* GetPMapFromRootFile(TDirectory* file); - static int GetNPlanes(TDirectory* file); - static int GetChecksum(TDirectory* file); - static int GetTotalDim(TDirectory* file); - - int CalcChecksum() const; - void DumpPMap() const; + FTKPlaneMap(const char *); + FTKPlaneMap(TDirectory* file); //!< used for instantiation from root file + ~FTKPlaneMap(); + + // interface to rootfile + void WriteMapToRootFile(TDirectory* dir); + static FTKPlaneMap* GetPMapFromRootFile(TDirectory* file); + static int GetNPlanes(TDirectory* file); + static int GetChecksum(TDirectory* file); + static int GetTotalDim(TDirectory* file); + + int CalcChecksum() const; + void DumpPMap() const; - const char *getPath() const { return m_path.c_str(); } + const char *getPath() const { return m_path.c_str(); } - int getNPlanes() const { return m_nplanes; } - void setNPlanes(int v) { m_nplanes = v; } + int getNPlanes() const { return m_nplanes; } + void setNPlanes(int v) { m_nplanes = v; } - int getNSections(int pos) const { return m_nsections[pos]; } + int getNSections(int pos) const { return m_nsections[pos]; } - int getRLayers() const { return m_rlayers; } - void setRLayers(int v) { m_rlayers = v; } + int getRLayers() const { return m_rlayers; } + void setRLayers(int v) { m_rlayers = v; } - int isSCT(int pl) const { return m_planeType[pl]==ftk::SCT; } - int isPixel(int pl) const { return m_planeType[pl]==ftk::PIXEL; } - int isSCTtrk(int pl) const { return m_planeType[pl]==ftk::SCTtrk; } - int getSCTtrkPlane() const; + int isSCT(int pl) const { return m_planeType[pl]==ftk::SCT; } + int isPixel(int pl) const { return m_planeType[pl]==ftk::PIXEL; } - int getDim(int pl, int id) const { return m_idim[id][pl]; } - int getTotalDim() const { return m_totaldim; } - int getPlanePair(int pl) const { return m_enablePlanePair ? m_planePair[pl] : pl; } + int getDim(int pl, int id) const { return m_idim[id][pl]; } + int getTotalDim() const { return m_totaldim; } + int getPlanePair(int pl) const { return m_enablePlanePair ? m_planePair[pl] : pl; } - bool getEnablePlanePair() const { return m_enablePlanePair; } - void setEnablePlanePair(const bool state) { m_enablePlanePair = state; } + bool getEnablePlanePair() const { return m_enablePlanePair; } + void setEnablePlanePair(const bool state) { m_enablePlanePair = state; } - FTKModuleInfo &getPlane(int plane, int section) const + FTKModuleInfo &getPlane(int plane, int section) const { return m_planes[plane][section]; } - FTKPlaneSection& getMap(int type, int section, int layer) const + FTKPlaneSection& getMap(int type, int section, int layer) const { return m_map[type][section][layer]; } - bool getIsOK() const { return m_isok;} - bool operator!() - {return !m_isok; } + bool getIsOK() const { return m_isok;} + bool operator!() + {return !m_isok; } }; #endif // FTKPMAP_H diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRawHit.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRawHit.h index f00fd372ec4..cd8b128b184 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRawHit.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRawHit.h @@ -27,10 +27,7 @@ class MultiTruth; */ class FTKRawHit : public TObject { private: - float m_x; - float m_y; - float m_z; /** Hit position in global coordinates */ - int m_hitType; /** Flag to know if the module belongs to Pixel or SCT or SCTtrk */ + int m_hitType; /** Flag to know if the module belongs to Pixel or SCT */ int m_moduleType; /** Flag that indicates the module type */ unsigned int m_IdentifierHash; // Athena identifier hash int m_barrel_ec; /** and if it's on barrel or endcaps, default values below */ @@ -76,18 +73,11 @@ public: void reset(); - void addX(float v) { m_x += v; } - void addY(float v) { m_y += v; } - void addZ(float v) { m_z += v; } void addPhiSide(int v) { m_pi_side += v; } void addEtaStrip(int v) { m_ei_strip += v; } void addNStrips(int v) { m_n_strips += v; } void addTot(int v) { m_n_strips += v; } - void divX(float v) { m_x /= v; } - void divY(float v) { m_y /= v; } - void divZ(float v) { m_z /= v; } - void setHitType(int v) { m_hitType = v; } void setModuleType(int v) { m_moduleType = v; } @@ -102,7 +92,7 @@ public: void setTot(int v) { m_n_strips = v; } /*! - * Function setting the column width in m_hw_word for pixel + * Function setting the column width in m_hw_word for pixel * @param v the new column width * @return void */ @@ -113,7 +103,7 @@ public: } /*! - * Function setting the row width in m_hw_word for pixel + * Function setting the row width in m_hw_word for pixel * @param v the new row width * @return void */ @@ -126,7 +116,7 @@ public: else m_hw_word = (m_hw_word&~mask) | ((7 << phi_width_bit) & mask); m_phiWidth = v; } - + /*! * Function setting the split cluster flag in m_hw_word * @param b split cluster flag @@ -138,28 +128,25 @@ public: } /*! - * Function setting the row coordinate in m_hw_word for pixel + * Function setting the row coordinate in m_hw_word for pixel * @param v the new row coordinate * @return void */ void setRowCoordinate(int v) { m_hw_word = (m_hw_word&~row_coord_mask) | ((v << row_coord_bit)&row_coord_mask); } /*! - * Function setting the column coordinate in m_hw_word for pixel + * Function setting the column coordinate in m_hw_word for pixel * @param v the new column coordinate * @return void */ void setColumnCoordinate(int v) { m_hw_word = (m_hw_word&~column_coord_mask) | ((v << column_coord_bit)&column_coord_mask); } /*! - * Function setting the column coordinate in m_hw_word for pixel + * Function setting the column coordinate in m_hw_word for pixel * @param v the new column coordinate * @return void */ void setStripCoordinate(int v) { m_hw_word = (m_hw_word &~ strip_coord_mask) | ((v << 0) & strip_coord_mask); } - void setX(float v) { m_x = v; } - void setY(float v) { m_y = v; } - void setZ(float v) { m_z = v; } void setDeltaPhi(float v) { m_dPhi = v; } void setDeltaEta(float v) { m_dEta = v; } void setIncludesGanged(bool b) { m_includesGangedHits = b; } @@ -170,7 +157,6 @@ public: int getIsPixel() const { return m_hitType==ftk::PIXEL; } int getIsSCT() const { return m_hitType==ftk::SCT; } - int getIsSCTtrk() const { return m_hitType==ftk::SCTtrk; } unsigned int getIdentifierHash() const { return m_IdentifierHash; } int getBarrelEC() const { return m_barrel_ec; } int getLayer() const { return m_layer_disk; } @@ -187,9 +173,6 @@ public: int getColumnCoordinate() const { return (m_hw_word & column_coord_mask) >> column_coord_bit; } bool getSplit() const { return (m_hw_word & split_mask) >> split_bit; } unsigned int getHWWord() const { return m_hw_word; } - float getX() const { return m_x; } - float getY() const { return m_y; } - float getZ() const { return m_z; } float getDeltaPhi() const { return m_dPhi; } float getDeltaEta() const { return m_dEta; } bool getIncludesGanged() const { return m_includesGangedHits; } @@ -208,15 +191,6 @@ public: FTKHit getFTKHit(const FTKPlaneMap *) const; - // special accessors for SCTTRK case: - // reuse existing variables to store 8L road and track info - int getBankID() const { return m_n_strips; } - int getRoadID() const { return m_phiWidth; } - int getTrackID() const { return m_etaWidth; } - void setBankID(int v) { m_n_strips = v; } - void setRoadID(int v) { m_phiWidth = v; } - void setTrackID(int v) { m_etaWidth = v; } - void addChannel(const FTKRawHit &hit) { m_channels.push_back(hit); } unsigned int getNChannels() const { return m_channels.size(); } const FTKRawHit& getChannel(unsigned int pos) const { return m_channels[pos]; } @@ -248,7 +222,7 @@ public: const float SCT_row_scaling = 2.; const float PIX_row_scaling = 8.; - const float PIX_column_scaling = + const float PIX_column_scaling = (16*ftk::lengthOfPixelModuleIn400umPixels)/ftk::numberOfEtaPixelsInPixelModule; // (16*19)/18); const float IBL_planar_row_scaling = 8.; const float IBL_planar_column_scaling = diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadFinderAlgo.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadFinderAlgo.h index a7a2e2c99b1..7d7abd12ca5 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadFinderAlgo.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadFinderAlgo.h @@ -22,166 +22,153 @@ ///////////////////////////////////////////////////////////////////////////// class FTKRoadFinderAlgo: public AthAlgorithm, FTKLogger { public: - FTKRoadFinderAlgo (const std::string& name, ISvcLocator* pSvcLocator); - virtual ~FTKRoadFinderAlgo (); - StatusCode initialize(); - StatusCode execute(); - StatusCode finalize(); + FTKRoadFinderAlgo (const std::string& name, ISvcLocator* pSvcLocator); + virtual ~FTKRoadFinderAlgo (); + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); - protected: - // to forward messages from FTKLogging to athena - virtual void PostMessage(void); +protected: + // to forward messages from FTKLogging to athena + virtual void PostMessage(void); private: - RoadFinder m_rfobj; // instance of the RoadFinder object - - ToolHandle m_hitInputTool; // input handler - ToolHandle m_roadOutputTool; // road output handler - ToolHandle m_roadMarketTool; // road output handler - - // Number of regions/banks - int m_nbanks; - int m_nsubregions; - - int m_verbosity; - bool m_BarrelOnly; - bool m_EnableFTKSim; - int m_MaxMissingPlanes; - int m_RoadWarrior; - int m_KeepRemoved; - - int m_MaxMissingSCTPairs; // increase the number of missing SCT modules, enable the transition region fix - bool m_RestrictSctPairModule; // restrict SCT pairs modules in the transition region - bool m_RestrictSctPairLayer; // restrict SCT layers in the transition region - - int m_IBLMode; // Enable the use of IBL - bool m_fixEndcapL0; //fix for endcap L0 in clustering - - bool m_ITkMode; // Use ITk geometry - - double m_ss_offset_fraction; - - int m_PixelClusteringMode; // clustering mode: 0 left edge, 1 center (also use ToT and correct for different lenght of pixels) - bool m_Ibl3DRealistic; //If true, use HWlike clustering in IBL 3D mod - int m_DuplicateGanged; // duplicate ganged pixels to remove efficiency loss - int m_GangedPatternRecognition; // pattern recognition to remove duplicates - int m_SctClustering; // SCT clustering: 0 disabled, 1 enabled - bool m_read_clusters; //Read Clusters from FTKIP File? Default is false - bool m_clustering; //Perform clustering? Default is true - - bool m_SCTTrkMode; - std::string m_scttrk_tracklist; - std::string m_scttrk_roadlist; - std::string m_scttrk_sectormap_path; - int m_scttrk_nlayers; - int m_scttrk_nsubs; - int m_scttrk_lastlayer; - - // set the use of the TSP DB banks - bool m_useTSPBank; - bool m_useCompressedBank; - // if the TSP bank is used it is possible to ask a specific level - int m_BankLevel; - // set if the TSP simulation is performed, 0 not used - int m_doTSPSim; - // minimum TSP coverage, if >1 the way the AM bank is built change - int m_minTSPCoverage; - /* set a variable to decide if the number of patterns has to be - done at TSP level (0) or at AM level. When the AM level is used - the pattern bank can stop when the number is reached (1) or untill - the number is not exceeded (2) */ - int m_setAMSize; - - // decide splitting strategy for AM patterns with DC bits - // default=0: no splitting - // >0 : split AM patterns and optimize DC usage - int m_setAMSplit; - - //max number of AM patterns after split, default=-1: no limits - int m_maxAMAfterSplit; - - //minimum threshold for DVol/DNPatt for split; default=0 - int m_minDVolOverDNPatt; - - - // store the variable if the TSP bank cache has to be saved - bool m_doMakeCache; - // path of the output file - std::string m_CachePath; - - // save all found roads if >0 - int m_SaveAllRoads; - - // store all ss not just in roads - bool m_StoreAllSS; - - // Plane map pointer, to be set during the initialization - FTKPlaneMap *m_pmap; - FTKPlaneMap *m_pmap_unused; - // region map used in this session - FTKRegionMap *m_rmap; - FTKRegionMap *m_rmap_unused; - int m_CUR_REGION; - // Super-strip map, this object transform an hit in a SS index - FTKSSMap *m_ssmap; - FTKSSMap *m_ssmap_unused; - FTKSSMap *m_ssmap_tsp; - // require presence of first layer (pixel B-layer) - bool m_require_first; - // lists containing output of 8L run - std::string scttrk_tracklist; - std::string scttrk_roadlist; - // 4L,8L -> 11L lookup map - FTKSectorMap *m_scttrk_sectormap; - - // HW-like SS encoding falg - unsigned int m_HWModeSS; - - std::string m_pmap_path; - std::string m_pmapunused_path; - std::string m_rmap_path; - std::string m_rmapunused_path; - std::string m_ssmap_path; - std::string m_ssmapunused_path; - std::string m_ssmaptsp_path; - std::string m_badmap_path; - std::string m_badmap_path2; - - std::string m_modulelut_path; // LUT to map global ID in local IDs for HWModeSS=2 - std::string m_modulelut2nd_path; // LUT to map global ID in local IDs for HWMo - - bool m_CachedBank; - std::vector m_patternbankpath; - std::vector m_bankregion; - std::vector m_banksubreg; - std::vector m_bankpatterns; - - bool m_InputFromWrapper; - bool m_RegionalWrapper; - std::vector m_wrapperpaths; - - bool m_doroadfile; - std::string m_roadfilepath; - std::string m_roadfilesdir; - bool m_roadmarket; - bool m_saveroads; - - bool m_useMinimalAMIN; // flag to propagate to the FTK_AMBank to set the match method - - int m_SectorAsPatterns; // flag to propagate the use of a list of sectors as pattern bank - - int m_DCMatchMethod; // flag to propagate to the FTKTSPMap classes - - bool m_AutoDisable; // possibility to avoid internal algorithm execution in particular confitions - - // read FTKHits directly from file - bool m_read_FTKhits_directly; - - int m_firstEventFTK; // first event to run over - - int m_AMcompressionMode; // compression mode for AM bank + RoadFinder m_rfobj; // instance of the RoadFinder object + + ToolHandle m_hitInputTool; // input handler + ToolHandle m_roadOutputTool; // road output handler + ToolHandle m_roadMarketTool; // road output handler + + // Number of regions/banks + int m_nbanks; + int m_nsubregions; + + int m_verbosity; + bool m_BarrelOnly; + bool m_EnableFTKSim; + int m_MaxMissingPlanes; + int m_RoadWarrior; + int m_KeepRemoved; + + int m_MaxMissingSCTPairs; // increase the number of missing SCT modules, enable the transition region fix + bool m_RestrictSctPairModule; // restrict SCT pairs modules in the transition region + bool m_RestrictSctPairLayer; // restrict SCT layers in the transition region + + int m_IBLMode; // Enable the use of IBL + bool m_fixEndcapL0; //fix for endcap L0 in clustering + + bool m_ITkMode; // Use ITk geometry + + double m_ss_offset_fraction; + + int m_PixelClusteringMode; // clustering mode: 0 left edge, 1 center (also use ToT and correct for different lenght of pixels) + bool m_Ibl3DRealistic; //If true, use HWlike clustering in IBL 3D mod + int m_DuplicateGanged; // duplicate ganged pixels to remove efficiency loss + int m_GangedPatternRecognition; // pattern recognition to remove duplicates + int m_SctClustering; // SCT clustering: 0 disabled, 1 enabled + bool m_read_clusters; //Read Clusters from FTKIP File? Default is false + bool m_clustering; //Perform clustering? Default is true + + // set the use of the TSP DB banks + bool m_useTSPBank; + bool m_useCompressedBank; + // if the TSP bank is used it is possible to ask a specific level + int m_BankLevel; + // set if the TSP simulation is performed, 0 not used + int m_doTSPSim; + // minimum TSP coverage, if >1 the way the AM bank is built change + int m_minTSPCoverage; + /* set a variable to decide if the number of patterns has to be + done at TSP level (0) or at AM level. When the AM level is used + the pattern bank can stop when the number is reached (1) or untill + the number is not exceeded (2) */ + int m_setAMSize; + + // decide splitting strategy for AM patterns with DC bits + // default=0: no splitting + // >0 : split AM patterns and optimize DC usage + int m_setAMSplit; + + //max number of AM patterns after split, default=-1: no limits + int m_maxAMAfterSplit; + + //minimum threshold for DVol/DNPatt for split; default=0 + int m_minDVolOverDNPatt; + + + // store the variable if the TSP bank cache has to be saved + bool m_doMakeCache; + // path of the output file + std::string m_CachePath; + + // save all found roads if >0 + int m_SaveAllRoads; + + // store all ss not just in roads + bool m_StoreAllSS; + + // Plane map pointer, to be set during the initialization + FTKPlaneMap *m_pmap; + FTKPlaneMap *m_pmap_unused; + // region map used in this session + FTKRegionMap *m_rmap; + FTKRegionMap *m_rmap_unused; + int m_CUR_REGION; + // Super-strip map, this object transform an hit in a SS index + FTKSSMap *m_ssmap; + FTKSSMap *m_ssmap_unused; + FTKSSMap *m_ssmap_tsp; + // require presence of first layer (pixel B-layer) + bool m_require_first; + + // HW-like SS encoding falg + unsigned int m_HWModeSS; + + std::string m_pmap_path; + std::string m_pmapunused_path; + std::string m_rmap_path; + std::string m_rmapunused_path; + std::string m_ssmap_path; + std::string m_ssmapunused_path; + std::string m_ssmaptsp_path; + std::string m_badmap_path; + std::string m_badmap_path2; + + std::string m_modulelut_path; // LUT to map global ID in local IDs for HWModeSS=2 + std::string m_modulelut2nd_path; // LUT to map global ID in local IDs for HWMo + + bool m_CachedBank; + std::vector m_patternbankpath; + std::vector m_bankregion; + std::vector m_banksubreg; + std::vector m_bankpatterns; + + bool m_InputFromWrapper; + bool m_RegionalWrapper; + std::vector m_wrapperpaths; + + bool m_doroadfile; + std::string m_roadfilepath; + std::string m_roadfilesdir; + bool m_roadmarket; + bool m_saveroads; + + bool m_useMinimalAMIN; // flag to propagate to the FTK_AMBank to set the match method + + int m_SectorAsPatterns; // flag to propagate the use of a list of sectors as pattern bank + + int m_DCMatchMethod; // flag to propagate to the FTKTSPMap classes + + bool m_AutoDisable; // possibility to avoid internal algorithm execution in particular confitions + + // read FTKHits directly from file + bool m_read_FTKhits_directly; + + int m_firstEventFTK; // first event to run over + + int m_AMcompressionMode; // compression mode for AM bank }; #endif // FTKRoadFinderAlgo_h diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadOutput.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadOutput.h index dec9213f8cb..aa5dfe1a66d 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadOutput.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadOutput.h @@ -39,7 +39,6 @@ class FTKRoadOutput { virtual void setEventNumber(const unsigned int&,const unsigned long&) = 0; virtual void addRoad(int, const FTKRoad&) = 0; - virtual void inc4LRoad(int, const int& val=1) = 0; virtual void addSS(int,int, int,const FTKSS&) = 0; virtual void addSSPlane(int, int,const std::map&) = 0; virtual void addUnusedSSMap(int, const std::map >&) = 0; diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadStream.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadStream.h index 6001eeb2641..4fcbbc73823 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadStream.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKRoadStream.h @@ -26,179 +26,175 @@ typedef std::map FTKUnusedSS_map_t; class FTKRoadStream { private: - unsigned long m_run_number; // run number - unsigned long m_event_number; // event number - - int m_nroads; // number of roads in m_roads TClonesArray - int m_nroads_4L; // 4-Layer SCTTrk roads - TClonesArray *m_roads; //-> clones array of roads - - int m_nroads_tot; // totoal number of found roads - int m_nroads_good; // total number of accepted roads - int m_nroads_maj; // total number of found majority-roads - int m_nroads_maj_good; // total number of accepted majority-roads - - std::vector< std::map > m_ssmaps; // hits, divided by plane - std::map< int, std::map > m_ssmaps_unused; // unused hits, divided by plane - - std::map< std::pair, int > m_roadIdMap; //! Not saved on disk. - // Used to optimize the findRoad function. - - // Additional information for Naoki's studies - private: - int m_nao_nhits_tot; // total number of hits per event - int m_nao_nclus_tot; // total number of hits per event - std::vector m_nao_nclus; // number of clusters routed into current region [nplanes] - std::vector m_nao_nclus_road; // number of clusters routed into current region [nplanes] in roads, allowing for duplicates - std::vector m_nao_nss; // number of superstrips going into AM [nplanes] - int m_nao_nroads_am; // number of roads out of AM - int m_nao_nroads_am_complete; // number of roads out of AM, complete no missing hits - int m_nao_nroads_am_misspix; // number of roads out of AM, missing at least one pixel hit - int m_nao_nroads_am_misssct; // number of roads out of AM, missing at least one sct hit - int m_nao_nroads_mod; // number of roads (extra counter for split arch) - int m_nao_nroads_rw; // number of roads after roadwarrior - public: - void naoSetNhitsTot(int val) { m_nao_nhits_tot=val; } - void naoSetNclusTot(int val) { m_nao_nclus_tot=val; } - void naoSetNclus(const std::vector& val) { m_nao_nclus=val; } - void naoSetNclus_road(const std::vector& val) { m_nao_nclus_road=val; } - void naoSetNss(const std::vector& val) { m_nao_nss=val; } - void naoAddNclus(const std::vector& val) { - assert(val.size()==m_nao_nclus.size()); - std::transform(val.begin(),val.end(),m_nao_nclus.begin(),m_nao_nclus.begin(),std::plus()); - } - void naoAddNclus_road(const std::vector& val) { - assert(val.size()==m_nao_nclus_road.size()); - std::transform(val.begin(),val.end(),m_nao_nclus_road.begin(),m_nao_nclus_road.begin(),std::plus()); - } - void naoAddNss(const std::vector& val) { - assert(val.size()==m_nao_nss.size()); - std::transform(val.begin(),val.end(),m_nao_nss.begin(),m_nao_nss.begin(),std::plus()); - } - void naoSetNroadsAM(int val) { m_nao_nroads_am=val; } - void naoSetNroadsAMComplete(int val) { m_nao_nroads_am_complete=val; } - void naoSetNroadsAMMissPix(int val) { m_nao_nroads_am_misspix=val; } - void naoSetNroadsAMMissSCT(int val) { m_nao_nroads_am_misssct=val; } - void naoSetNroadsMOD(int val) { m_nao_nroads_mod=val; } - void naoSetNroadsRW(int val) { m_nao_nroads_rw=val; } - void naoAddNroadsAM(int val) { m_nao_nroads_am+=val; } - void naoAddNroadsAMComplete(int val) { m_nao_nroads_am_complete+=val; } - void naoAddNroadsAMMissPix(int val) { m_nao_nroads_am_misspix+=val; } - void naoAddNroadsAMMissSCT(int val) { m_nao_nroads_am_misssct+=val; } - void naoAddNroadsMOD(int val) { m_nao_nroads_mod+=val; } - void naoAddNroadsRW(int val) { m_nao_nroads_rw+=val; } - - int naoGetNhitsTot() const { return m_nao_nhits_tot; } - int naoGetNclusTot() const { return m_nao_nclus_tot; } - int naoGetNclus(unsigned int pl) const { return m_nao_nclus.size()>pl ? m_nao_nclus[pl] : -1; } - int naoGetNclus_road(unsigned int pl) const { return m_nao_nclus_road.size()>pl ? m_nao_nclus_road[pl] : -1; } - int naoGetNss(unsigned int pl) const { return m_nao_nss.size()>pl ? m_nao_nss[pl] : -1; } - const std::vector& naoGetNclus() { return m_nao_nclus; } - const std::vector& naoGetNclus_road() { return m_nao_nclus_road; } - const std::vector& naoGetNss() { return m_nao_nss; } - int naoGetNroadsAM() const { return m_nao_nroads_am; } - int naoGetNroadsAMComplete() const { return m_nao_nroads_am_complete; } - int naoGetNroadsAMMissPix() const { return m_nao_nroads_am_misspix; } - int naoGetNroadsAMMissSCT() const { return m_nao_nroads_am_misssct; } - int naoGetNroadsMOD() const { return m_nao_nroads_mod; } - int naoGetNroadsRW() const { return m_nao_nroads_rw; } - - - long int *m_evtidx; //! - long int *m_barcode; //! - float *m_frac; //! - + unsigned long m_run_number; // run number + unsigned long m_event_number; // event number + + int m_nroads; // number of roads in m_roads TClonesArray + TClonesArray *m_roads; //-> clones array of roads + + int m_nroads_tot; // totoal number of found roads + int m_nroads_good; // total number of accepted roads + int m_nroads_maj; // total number of found majority-roads + int m_nroads_maj_good; // total number of accepted majority-roads + + std::vector< std::map > m_ssmaps; // hits, divided by plane + std::map< int, std::map > m_ssmaps_unused; // unused hits, divided by plane + + std::map< std::pair, int > m_roadIdMap; //! Not saved on disk. + // Used to optimize the findRoad function. + + // Additional information for Naoki's studies +private: + int m_nao_nhits_tot; // total number of hits per event + int m_nao_nclus_tot; // total number of hits per event + std::vector m_nao_nclus; // number of clusters routed into current region [nplanes] + std::vector m_nao_nclus_road; // number of clusters routed into current region [nplanes] in roads, allowing for duplicates + std::vector m_nao_nss; // number of superstrips going into AM [nplanes] + int m_nao_nroads_am; // number of roads out of AM + int m_nao_nroads_am_complete; // number of roads out of AM, complete no missing hits + int m_nao_nroads_am_misspix; // number of roads out of AM, missing at least one pixel hit + int m_nao_nroads_am_misssct; // number of roads out of AM, missing at least one sct hit + int m_nao_nroads_mod; // number of roads (extra counter for split arch) + int m_nao_nroads_rw; // number of roads after roadwarrior +public: + void naoSetNhitsTot(int val) { m_nao_nhits_tot=val; } + void naoSetNclusTot(int val) { m_nao_nclus_tot=val; } + void naoSetNclus(const std::vector& val) { m_nao_nclus=val; } + void naoSetNclus_road(const std::vector& val) { m_nao_nclus_road=val; } + void naoSetNss(const std::vector& val) { m_nao_nss=val; } + void naoAddNclus(const std::vector& val) { + assert(val.size()==m_nao_nclus.size()); + std::transform(val.begin(),val.end(),m_nao_nclus.begin(),m_nao_nclus.begin(),std::plus()); + } + void naoAddNclus_road(const std::vector& val) { + assert(val.size()==m_nao_nclus_road.size()); + std::transform(val.begin(),val.end(),m_nao_nclus_road.begin(),m_nao_nclus_road.begin(),std::plus()); + } + void naoAddNss(const std::vector& val) { + assert(val.size()==m_nao_nss.size()); + std::transform(val.begin(),val.end(),m_nao_nss.begin(),m_nao_nss.begin(),std::plus()); + } + void naoSetNroadsAM(int val) { m_nao_nroads_am=val; } + void naoSetNroadsAMComplete(int val) { m_nao_nroads_am_complete=val; } + void naoSetNroadsAMMissPix(int val) { m_nao_nroads_am_misspix=val; } + void naoSetNroadsAMMissSCT(int val) { m_nao_nroads_am_misssct=val; } + void naoSetNroadsMOD(int val) { m_nao_nroads_mod=val; } + void naoSetNroadsRW(int val) { m_nao_nroads_rw=val; } + void naoAddNroadsAM(int val) { m_nao_nroads_am+=val; } + void naoAddNroadsAMComplete(int val) { m_nao_nroads_am_complete+=val; } + void naoAddNroadsAMMissPix(int val) { m_nao_nroads_am_misspix+=val; } + void naoAddNroadsAMMissSCT(int val) { m_nao_nroads_am_misssct+=val; } + void naoAddNroadsMOD(int val) { m_nao_nroads_mod+=val; } + void naoAddNroadsRW(int val) { m_nao_nroads_rw+=val; } + + int naoGetNhitsTot() const { return m_nao_nhits_tot; } + int naoGetNclusTot() const { return m_nao_nclus_tot; } + int naoGetNclus(unsigned int pl) const { return m_nao_nclus.size()>pl ? m_nao_nclus[pl] : -1; } + int naoGetNclus_road(unsigned int pl) const { return m_nao_nclus_road.size()>pl ? m_nao_nclus_road[pl] : -1; } + int naoGetNss(unsigned int pl) const { return m_nao_nss.size()>pl ? m_nao_nss[pl] : -1; } + const std::vector& naoGetNclus() { return m_nao_nclus; } + const std::vector& naoGetNclus_road() { return m_nao_nclus_road; } + const std::vector& naoGetNss() { return m_nao_nss; } + int naoGetNroadsAM() const { return m_nao_nroads_am; } + int naoGetNroadsAMComplete() const { return m_nao_nroads_am_complete; } + int naoGetNroadsAMMissPix() const { return m_nao_nroads_am_misspix; } + int naoGetNroadsAMMissSCT() const { return m_nao_nroads_am_misssct; } + int naoGetNroadsMOD() const { return m_nao_nroads_mod; } + int naoGetNroadsRW() const { return m_nao_nroads_rw; } + + + long int *m_evtidx; //! + long int *m_barcode; //! + float *m_frac; //! + public: - FTKRoadStream(); - virtual ~FTKRoadStream(); - - void init(int); - - unsigned long runNumber() const { return m_run_number; } - unsigned long eventNumber() const { return m_event_number; } - void setRunNumber(const unsigned long& val) { m_run_number = val; } - void setEventNumber(const unsigned long& val) { m_event_number = val; } - - int getNPlanes() const { return m_ssmaps.size(); } - - void clear(); - - FTKRoad* addRoad(const FTKRoad&); - void inc4LRoad(const int& val=1) { m_nroads_4L+=val; } // Increment 4L road counter - int getN4LRoads() const { return m_nroads_4L; } // Get 4L roads - - int getNRoads() const { return m_nroads; } - - void sortRoads(); - - void addSS(int,const int,const FTKSS&); - FTKSS& getSS(int pl, int id) { return m_ssmaps[pl][id]; } - void addSSPlane(int pl,const std::map& res) { m_ssmaps[pl] = res; } - const std::map& getSSPlane(int pl) const { return m_ssmaps[pl]; } - const FTKSS_container_t& getSSContainer() const { return m_ssmaps; } - - void addUnusedSS(int,const int,const FTKSS&); - void addUnusedSSMap(const std::map< int, std::map >& ssmap) { m_ssmaps_unused = ssmap; } - const FTKUnusedSS_map_t& getUnusedSSMap() const { return m_ssmaps_unused; } - const FTKSS& getUnusedSS(int pl, int id) const; - FTKRoad *getRoad(int) const; - int findRoad(int,int); - void removeRoad(int); - void optimize(); - void buildRoadMap(); - - int getNSS(int pl) const { return m_ssmaps[pl].size(); } - - void attachHits(int); - void detachHits(int); - - void Print(bool printCoords=false); - - FTKRoadKDTree *buildKDTree(); - - int computeUnusedSegmentsTruthList(); - int getNUnusedPlanes() const { return m_ssmaps_unused.size(); } - long int getEventIndex(int idx) const { return m_evtidx[idx];} - long int getBarcode(int idx ) const { return m_barcode[idx]; } - float getBarcodeFrac(int idx) const { return m_frac[idx]; } - - - /** this class helps to loop over the roads, its goal is - to simplify the method used to loop on complex output - made using the variable resolution strips. In this case - this iterator is alway on an usable road, properly - prepared to be used in track_fitter algorithms */ - class FTKRoadCursor : public TObject { - public: - FTKRoadCursor(); - FTKRoadCursor(FTKRoadStream*, FTKRoad*,int,bool); - FTKRoadCursor(const FTKRoadCursor&); - ~FTKRoadCursor(); - - FTKRoad* operator()(); - FTKRoad* getRoad() { return (*this)(); } - - private: - FTKRoadStream *m_stream; // streamer object - FTKRoad *m_road; // managed road - int m_position; // position in the streamer class - bool m_first; //c true if the road is - - }; + FTKRoadStream(); + virtual ~FTKRoadStream(); + + void init(int); + + unsigned long runNumber() const { return m_run_number; } + unsigned long eventNumber() const { return m_event_number; } + void setRunNumber(const unsigned long& val) { m_run_number = val; } + void setEventNumber(const unsigned long& val) { m_event_number = val; } + + int getNPlanes() const { return m_ssmaps.size(); } + + void clear(); + + FTKRoad* addRoad(const FTKRoad&); + int getNRoads() const { return m_nroads; } + + void sortRoads(); + + void addSS(int,const int,const FTKSS&); + FTKSS& getSS(int pl, int id) { return m_ssmaps[pl][id]; } + void addSSPlane(int pl,const std::map& res) { m_ssmaps[pl] = res; } + const std::map& getSSPlane(int pl) const { return m_ssmaps[pl]; } + const FTKSS_container_t& getSSContainer() const { return m_ssmaps; } + + void addUnusedSS(int,const int,const FTKSS&); + void addUnusedSSMap(const std::map< int, std::map >& ssmap) { m_ssmaps_unused = ssmap; } + const FTKUnusedSS_map_t& getUnusedSSMap() const { return m_ssmaps_unused; } + const FTKSS& getUnusedSS(int pl, int id) const; + FTKRoad *getRoad(int) const; + int findRoad(int,int); + void removeRoad(int); + void optimize(); + void buildRoadMap(); + + int getNSS(int pl) const { return m_ssmaps[pl].size(); } + + void attachHits(int); + void detachHits(int); + + void Print(bool printCoords=false); + + FTKRoadKDTree *buildKDTree(); + + int computeUnusedSegmentsTruthList(); + int getNUnusedPlanes() const { return m_ssmaps_unused.size(); } + long int getEventIndex(int idx) const { return m_evtidx[idx];} + long int getBarcode(int idx ) const { return m_barcode[idx]; } + float getBarcodeFrac(int idx) const { return m_frac[idx]; } + + + /** this class helps to loop over the roads, its goal is + to simplify the method used to loop on complex output + made using the variable resolution strips. In this case + this iterator is alway on an usable road, properly + prepared to be used in track_fitter algorithms */ + class FTKRoadCursor : public TObject { + public: + FTKRoadCursor(); + FTKRoadCursor(FTKRoadStream*, FTKRoad*,int,bool); + FTKRoadCursor(const FTKRoadCursor&); + ~FTKRoadCursor(); + + FTKRoad* operator()(); + FTKRoad* getRoad() { return (*this)(); } + + private: + FTKRoadStream *m_stream; // streamer object + FTKRoad *m_road; // managed road + int m_position; // position in the streamer class + bool m_first; //c true if the road is + + }; private: - std::list m_fit_list; //! list of the road to fit - std::list::iterator m_fit_iter; //! current road + std::list m_fit_list; //! list of the road to fit + std::list::iterator m_fit_iter; //! current road - void expandSubRoads(FTKRoad*,FTKRoad*,int,bool); -public: + void expandSubRoads(FTKRoad*,FTKRoad*,int,bool); +public: - unsigned prepareFitList(); // make the list end return the begin - FTKRoad* fetchRoad(); // get the current road and point to the next - void rewindFitList() { m_fit_iter = m_fit_list.begin(); } + unsigned prepareFitList(); // make the list end return the begin + FTKRoad* fetchRoad(); // get the current road and point to the next + void rewindFitList() { m_fit_iter = m_fit_list.begin(); } - ClassDef(FTKRoadStream,12) -}; + ClassDef(FTKRoadStream,12) + }; #endif // FTKROADSTREAM_H diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKSetup.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKSetup.h index b8181ed3675..661439457f1 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKSetup.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKSetup.h @@ -20,147 +20,142 @@ /** define an exception class for a generic FTK error */ class FTKException : public std::runtime_error { public: - FTKException(const std::string &descr) : std::runtime_error(descr) {} +FTKException(const std::string &descr) : std::runtime_error(descr) {} }; - + class FTKSetup { private: - static FTKSetup m_instance; // singleton instance for the FTK setup + static FTKSetup m_instance; // singleton instance for the FTK setup #ifndef FTK_STANDALONE - static MsgStream *m_log; + static MsgStream *m_log; #endif - int m_pid; // current process PID - - struct timeval m_starttime; // time at the start + int m_pid; // current process PID - bool m_BarrelOnly; // true if the EndCap data are not processed + struct timeval m_starttime; // time at the start - bool m_SCTtrkMode; // if using PIXEL + SCTtrk configuration (Constantinos's 2nd stage) + bool m_BarrelOnly; // true if the EndCap data are not processed - int m_IBLMode; // if using IBL configuration + int m_IBLMode; // if using IBL configuration - bool m_ITkMode; // use ITk geometry + bool m_ITkMode; // use ITk geometry - int m_verbosity; /// verbosity level + int m_verbosity; /// verbosity level - int m_tot_events; // number of event to process + int m_tot_events; // number of event to process - int m_EnableFTKSim; // !=0 if FTK simulation is enabled + int m_EnableFTKSim; // !=0 if FTK simulation is enabled - int m_RawMode; // When 1 (always) the incoming data are raw hits + int m_RawMode; // When 1 (always) the incoming data are raw hits - int m_SectorsAsPatterns; // the field chages the SS calculation to the module ID, meaning that the sectors are used in place of patterns + int m_SectorsAsPatterns; // the field chages the SS calculation to the module ID, meaning that the sectors are used in place of patterns - int m_MaxMissingPlanes; // maximum number of missing planes + int m_MaxMissingPlanes; // maximum number of missing planes - unsigned m_MaskLayers; // a binary mask that set which layers are always discarded + unsigned m_MaskLayers; // a binary mask that set which layers are always discarded - int m_RoadWarrior; // a variable to check if the RW is enabled + int m_RoadWarrior; // a variable to check if the RW is enabled - int m_KeepRemoved; // it's true if the RW rejeceted tracks are just falgged + int m_KeepRemoved; // it's true if the RW rejeceted tracks are just falgged - unsigned int m_HWModeSS; // check the format of the SS-ID: 0 is global, 1 is local (tower based), 2 is local compressed + unsigned int m_HWModeSS; // check the format of the SS-ID: 0 is global, 1 is local (tower based), 2 is local compressed - int m_event; // current event + int m_event; // current event - int m_MaxMissingSctPairs; // maximum number of missing SCT pairs - // Note that each missing pair will count - // as ONE missing plane for the purpose of - // m_MaxMissingPlanes + int m_MaxMissingSctPairs; // maximum number of missing SCT pairs + // Note that each missing pair will count + // as ONE missing plane for the purpose of + // m_MaxMissingPlanes - bool m_restrictSctPairLayer; // Require a missing SCT pair to be in - // the outer layers + bool m_restrictSctPairLayer; // Require a missing SCT pair to be in + // the outer layers - bool m_restrictSctPairModule; // Require the outer missing SCT pair - // to correspond to the barrel-disk - // transition region. Implies the - // previous setting is true. + bool m_restrictSctPairModule; // Require the outer missing SCT pair + // to correspond to the barrel-disk + // transition region. Implies the + // previous setting is true. - int m_usage_ncalls; // counter of the statistic calls + int m_usage_ncalls; // counter of the statistic calls - bool m_fixEndcapL0; //fix for endcap L0 in clustering + bool m_fixEndcapL0; //fix for endcap L0 in clustering - FTKSetup(); // private constructor + FTKSetup(); // private constructor public: - ~FTKSetup(); // class destructor + ~FTKSetup(); // class destructor + + int getVerbosity() const { return m_verbosity; } + void setVerbosity(int v) { m_verbosity = v; } - int getVerbosity() const { return m_verbosity; } - void setVerbosity(int v) { m_verbosity = v; } + int getTotEvents() const { return m_tot_events; } + void setTotEvents(int v) { m_tot_events = v; } - int getTotEvents() const { return m_tot_events; } - void setTotEvents(int v) { m_tot_events = v; } + void usageStat(const char *header=0); - void usageStat(const char *header=0); + void setBarrelOnly(bool v) { m_BarrelOnly = v; } + bool getBarrelOnly() const { return m_BarrelOnly; } - void setBarrelOnly(bool v) { m_BarrelOnly = v; } - bool getBarrelOnly() const { return m_BarrelOnly; } + void setIBLMode(int v) { m_IBLMode = v; } + int getIBLMode() const { return m_IBLMode; } - void setSCTtrkMode(bool v) { m_SCTtrkMode = v; } - bool getSCTtrkMode() const { return m_SCTtrkMode; } + void setfixEndcapL0(bool v) {m_fixEndcapL0 = v;} + bool getfixEndcapL0() const { return m_fixEndcapL0;} - void setIBLMode(int v) { m_IBLMode = v; } - int getIBLMode() const { return m_IBLMode; } + void setITkMode(bool v) { m_ITkMode = v; } + bool getITkMode() const { return m_ITkMode; } - void setfixEndcapL0(bool v) {m_fixEndcapL0 = v;} - bool getfixEndcapL0() const { return m_fixEndcapL0;} + void setEnableFTKSim(int v) { m_EnableFTKSim = v; } + int getEnableFTKSim() const { return m_EnableFTKSim; } - void setITkMode(bool v) { m_ITkMode = v; } - bool getITkMode() const { return m_ITkMode; } - - void setEnableFTKSim(int v) { m_EnableFTKSim = v; } - int getEnableFTKSim() const { return m_EnableFTKSim; } + void setRawMode(int v) { m_RawMode = v; } + int getRawMode() const { return m_RawMode; } - void setRawMode(int v) { m_RawMode = v; } - int getRawMode() const { return m_RawMode; } + void setMaxMissingPlanes(int v) { m_MaxMissingPlanes = v; } + int getMaxMissingPlanes() const { return m_MaxMissingPlanes; } - void setMaxMissingPlanes(int v) { m_MaxMissingPlanes = v; } - int getMaxMissingPlanes() const { return m_MaxMissingPlanes; } + void setMaskLayers(unsigned v) { m_MaskLayers = v; } + unsigned getMaskLayers() const { return m_MaskLayers; } - void setMaskLayers(unsigned v) { m_MaskLayers = v; } - unsigned getMaskLayers() const { return m_MaskLayers; } + void setMaxMissingSctPairs(int v) { m_MaxMissingSctPairs = v; } + int getMaxMissingSctPairs() const { return m_MaxMissingSctPairs; } - void setMaxMissingSctPairs(int v) { m_MaxMissingSctPairs = v; } - int getMaxMissingSctPairs() const { return m_MaxMissingSctPairs; } + void setRestrictSctPairLayer(bool v) { m_restrictSctPairLayer = v; } + bool getRestrictSctPairLayer() const { return m_restrictSctPairLayer; } - void setRestrictSctPairLayer(bool v) { m_restrictSctPairLayer = v; } - bool getRestrictSctPairLayer() const { return m_restrictSctPairLayer; } + void setRestrictSctPairModule(bool v) { m_restrictSctPairModule = v; } + bool getRestrictSctPairModule() const { return m_restrictSctPairModule; } - void setRestrictSctPairModule(bool v) { m_restrictSctPairModule = v; } - bool getRestrictSctPairModule() const { return m_restrictSctPairModule; } + void setRoadWarrior(int v) { m_RoadWarrior = v; } + int getRoadWarrior() const { return m_RoadWarrior; } - void setRoadWarrior(int v) { m_RoadWarrior = v; } - int getRoadWarrior() const { return m_RoadWarrior; } + void setKeepRemoved(int v) { m_KeepRemoved = v; } + int getKeepRemoved() const { return m_KeepRemoved; } - void setKeepRemoved(int v) { m_KeepRemoved = v; } - int getKeepRemoved() const { return m_KeepRemoved; } + void setSectorsAsPatterns(int v) { m_SectorsAsPatterns = v; } + int getSectorsAsPatterns() const { return m_SectorsAsPatterns; } - void setSectorsAsPatterns(int v) { m_SectorsAsPatterns = v; } - int getSectorsAsPatterns() const { return m_SectorsAsPatterns; } + void setHWModeSS(unsigned int val) { m_HWModeSS = val; } + const unsigned int &getHWModeSS() { return m_HWModeSS; } - void setHWModeSS(unsigned int val) { m_HWModeSS = val; } - const unsigned int &getHWModeSS() { return m_HWModeSS; } - - // Message printing operator - static void PrintMessage(ftk::message_level_t, const char *); - static void PrintMessageFmt(ftk::message_level_t, const char *,...); + // Message printing operator + static void PrintMessage(ftk::message_level_t, const char *); + static void PrintMessageFmt(ftk::message_level_t, const char *,...); - // Print extra debug info (global info for Naoki simulation) - static int getDBG() {return false; } + // Print extra debug info (global info for Naoki simulation) + static int getDBG() {return false; } - /** return the reference to the unique instance of FTKSetup - class */ - static FTKSetup& getFTKSetup() { return m_instance; } + /** return the reference to the unique instance of FTKSetup + class */ + static FTKSetup& getFTKSetup() { return m_instance; } #ifndef FTK_STANDALONE - static MsgStream *getMsgStream() { return m_log; } - static void setMsgStream(MsgStream *stream) { m_log = stream; } + static MsgStream *getMsgStream() { return m_log; } + static void setMsgStream(MsgStream *stream) { m_log = stream; } #endif }; #endif // FTKSETUP_H diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKTrackFitterAlgo.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKTrackFitterAlgo.h index 4a9e3c0dc36..615220c552f 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKTrackFitterAlgo.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTKTrackFitterAlgo.h @@ -23,107 +23,105 @@ ///////////////////////////////////////////////////////////////////////////// class FTKTrackFitterAlgo: public AthAlgorithm { public: - FTKTrackFitterAlgo (const std::string& name, ISvcLocator* pSvcLocator); - virtual ~FTKTrackFitterAlgo (); - StatusCode initialize(); - StatusCode execute(); - StatusCode finalize(); + FTKTrackFitterAlgo (const std::string& name, ISvcLocator* pSvcLocator); + virtual ~FTKTrackFitterAlgo (); + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); private: - TrackFitter * m_tfpobj; // instance of the TrackFitter object - - ToolHandle m_roadMarketTool; // road input handler - ToolHandle m_trackOutputTool; // track output handler - ToolHandle m_trackOutputTool_pre_hw; // track output handler - - // Second stage fitter flag - bool m_SecondStageFit; - - // enable the use of IBL - int m_IBLMode; - - bool m_fixEndcapL0; //fix for endcap L0 in clustering - - - // use ITk geometry - bool m_ITkMode; - - // Number of regions/banks - int m_nbanks; - int m_nsubregions; - int m_verbosity; - - // for set parameter - int m_chi2cut; - int m_chi2cut_maj; - int m_chi2cut_vetmaj; - int m_chi2dofcutAux; - int m_chi2dofcutSSB; - - bool m_doAuxFW; - - int m_HitWarrior; - bool m_AuxDoctor; - int m_KeepRejected; - int m_FitRemoved; - int m_DoMajority; - int m_OnePerRoad; - int m_HWNDiff; - int m_MaxNcomb; - int m_MaxNhitsPerPlane; - int m_MaxTrkout; - int m_NoRecoveryNHits; - - bool m_SCTTrkMode; - - std::string m_loadHWConf_path; - - // second stage fit specific properties - int m_SSF_TFMode; - bool m_SSF_multiconn; - int m_SSF_maxnconn; - bool m_SSF_allow_extramiss; - int m_SSF_check_TR_by; - float m_SSF_TR_min_eta; - float m_SSF_TR_max_eta; - - bool m_save_1stStageTrks; - bool m_save_StepByStepTrks; - - //output - bool m_doTrackFile; - bool m_addRoads; - std::string m_trackfilepath; - std::string m_trackfilename; - - // Plane map pointer, to be set during the initialization - FTKPlaneMap *m_pmap; - std::string m_pmap_path; - FTKPlaneMap *m_pmap_complete; - std::string m_pmapcomplete_path; - FTKPlaneMap *m_pmap_unused; - std::string m_pmapunused_path; - std::string m_modulelut2nd_path; // LUT to map global ID in local IDs for HWModeSS=2 - - std::vector m_fitconstantspath; - std::vector m_fit711constantspath; - std::vector m_sectorpath; - std::vector m_bankregion; - std::vector m_banksubregion; - - FTKRegionMap *m_rmap; - FTKRegionMap *m_rmap_unused; - FTKSSMap *m_ssmap; - FTKSSMap *m_ssmap_unused; - - std::string m_rmap_path; - std::string m_ssmap_path; - std::string m_ssmapunused_path; - - bool m_AutoDisable; - bool m_PrintSSBConstants; - double m_dTIBL; // dT (in K) for IBL compared to reference. For use in correcting for IBL bowing in x(phi) direction + TrackFitter * m_tfpobj; // instance of the TrackFitter object + + ToolHandle m_roadMarketTool; // road input handler + ToolHandle m_trackOutputTool; // track output handler + ToolHandle m_trackOutputTool_pre_hw; // track output handler + + // Second stage fitter flag + bool m_SecondStageFit; + + // enable the use of IBL + int m_IBLMode; + + bool m_fixEndcapL0; //fix for endcap L0 in clustering + + + // use ITk geometry + bool m_ITkMode; + + // Number of regions/banks + int m_nbanks; + int m_nsubregions; + int m_verbosity; + + // for set parameter + int m_chi2cut; + int m_chi2cut_maj; + int m_chi2cut_vetmaj; + int m_chi2dofcutAux; + int m_chi2dofcutSSB; + + bool m_doAuxFW; + + int m_HitWarrior; + bool m_AuxDoctor; + int m_KeepRejected; + int m_FitRemoved; + int m_DoMajority; + int m_OnePerRoad; + int m_HWNDiff; + int m_MaxNcomb; + int m_MaxNhitsPerPlane; + int m_MaxTrkout; + int m_NoRecoveryNHits; + + std::string m_loadHWConf_path; + + // second stage fit specific properties + int m_SSF_TFMode; + bool m_SSF_multiconn; + int m_SSF_maxnconn; + bool m_SSF_allow_extramiss; + int m_SSF_check_TR_by; + float m_SSF_TR_min_eta; + float m_SSF_TR_max_eta; + + bool m_save_1stStageTrks; + bool m_save_StepByStepTrks; + + //output + bool m_doTrackFile; + bool m_addRoads; + std::string m_trackfilepath; + std::string m_trackfilename; + + // Plane map pointer, to be set during the initialization + FTKPlaneMap *m_pmap; + std::string m_pmap_path; + FTKPlaneMap *m_pmap_complete; + std::string m_pmapcomplete_path; + FTKPlaneMap *m_pmap_unused; + std::string m_pmapunused_path; + std::string m_modulelut2nd_path; // LUT to map global ID in local IDs for HWModeSS=2 + + std::vector m_fitconstantspath; + std::vector m_fit711constantspath; + std::vector m_sectorpath; + std::vector m_bankregion; + std::vector m_banksubregion; + + FTKRegionMap *m_rmap; + FTKRegionMap *m_rmap_unused; + FTKSSMap *m_ssmap; + FTKSSMap *m_ssmap_unused; + + std::string m_rmap_path; + std::string m_ssmap_path; + std::string m_ssmapunused_path; + + bool m_AutoDisable; + bool m_PrintSSBConstants; + double m_dTIBL; // dT (in K) for IBL compared to reference. For use in correcting for IBL bowing in x(phi) direction }; #endif // FTKTrackFitterAlgo_h diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketIO.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketIO.h index b11dacde344..710120d07ee 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketIO.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketIO.h @@ -78,7 +78,6 @@ public: const unsigned long &evtnum); virtual void addRoad(int, const FTKRoad&); - virtual void inc4LRoad(int, const int& val=1); virtual void addSS(int,int, int,const FTKSS&); virtual void addSSPlane(int, int,const std::map&); virtual void addUnusedSSMap(int, const std::map >&); diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketTool.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketTool.h index d1c1aac7223..179b4efc5a8 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketTool.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketTool.h @@ -31,60 +31,60 @@ road finder to the track fitter without the use of the SG */ class FTK_RoadMarketTool : virtual public FTK_RoadMarketToolI, public AthAlgTool { private: - int m_nbanks; + int m_nbanks; - FTKRoadStream **m_data; + FTKRoadStream **m_data; - FTK_RoadMarketOutput m_roadoutput; - FTK_RoadMarketInput m_roadinput; + FTK_RoadMarketOutput m_roadoutput; + FTK_RoadMarketInput m_roadinput; - RoadFinder* m_roadFinder; - TrackFitter* m_trackFitter; + RoadFinder* m_roadFinder; + TrackFitter* m_trackFitter; - mutable MsgStream m_log; + mutable MsgStream m_log; - bool m_SaveRoads; // if True the roads are saved in the SG - TTree *m_tree; // externally controlled TTree where the roads can be stored - int m_bufsize; // standard buffer size for the roads - std::string m_bnamefmt; // Format string for the branches: def "FTKRoadsStream%d." - std::vector m_goodreg; // integer representing the regions where output is expected + bool m_SaveRoads; // if True the roads are saved in the SG + TTree *m_tree; // externally controlled TTree where the roads can be stored + int m_bufsize; // standard buffer size for the roads + std::string m_bnamefmt; // Format string for the branches: def "FTKRoadsStream%d." + std::vector m_goodreg; // integer representing the regions where output is expected public: - FTK_RoadMarketTool(const std::string&, const std::string&, const IInterface*); - virtual ~FTK_RoadMarketTool(); + FTK_RoadMarketTool(const std::string&, const std::string&, const IInterface*); + virtual ~FTK_RoadMarketTool(); - StatusCode initialize(); - StatusCode finalize(); + StatusCode initialize(); + StatusCode finalize(); - bool SaveRoads() const { return m_SaveRoads; } - void SaveRoads(bool flag) { m_SaveRoads = flag; } + bool SaveRoads() const { return m_SaveRoads; } + void SaveRoads(bool flag) { m_SaveRoads = flag; } - virtual void ConnectRoads(TTree*,const char*,const std::vector&, int bufsize=0); + virtual void ConnectRoads(TTree*,const char*,const std::vector&, int bufsize=0); - virtual FTKRoadOutput* outputReference() { return &m_roadoutput;} - virtual FTKRoadInput* inputReference() { return &m_roadinput;} + virtual FTKRoadOutput* outputReference() { return &m_roadoutput;} + virtual FTKRoadInput* inputReference() { return &m_roadinput;} - virtual RoadFinder* roadFinderReference() { return m_roadFinder; } - virtual void setRoadFinderReference(RoadFinder* roadfinder) { m_roadFinder = roadfinder; } + virtual RoadFinder* roadFinderReference() { return m_roadFinder; } + virtual void setRoadFinderReference(RoadFinder* roadfinder) { m_roadFinder = roadfinder; } - virtual TrackFitter* trackFitterReference() { return m_trackFitter; } - virtual void setTrackFitterReference(TrackFitter* trackFitter) { m_trackFitter = trackFitter; } + virtual TrackFitter* trackFitterReference() { return m_trackFitter; } + virtual void setTrackFitterReference(TrackFitter* trackFitter) { m_trackFitter = trackFitter; } - void initRoads(); + void initRoads(); - void setNBanks(int nbanks); - int getNBanks() const { return m_nbanks; } + void setNBanks(int nbanks); + int getNBanks() const { return m_nbanks; } - FTKRoadStream* getStream(int id) { return m_data[id]; } + FTKRoadStream* getStream(int id) { return m_data[id]; } - unsigned long runNumber(const unsigned int& ibank) const { return( (m_data && (m_data[ibank])) ? (m_data[ibank])->runNumber() : 0 ); } - unsigned long eventNumber(const unsigned int& ibank) const { return( (m_data && (m_data[ibank])) ? (m_data[ibank])->eventNumber() : 0 ); } - void setRunNumber(const unsigned int& ibank,const unsigned long& val) { if( m_data && (m_data[ibank]) ) { (m_data[ibank])->setRunNumber(val); } } - void setEventNumber(const unsigned int& ibank,const unsigned long& val) { if( m_data && (m_data[ibank]) ) { (m_data[ibank])->setEventNumber(val); } } + unsigned long runNumber(const unsigned int& ibank) const { return( (m_data && (m_data[ibank])) ? (m_data[ibank])->runNumber() : 0 ); } + unsigned long eventNumber(const unsigned int& ibank) const { return( (m_data && (m_data[ibank])) ? (m_data[ibank])->eventNumber() : 0 ); } + void setRunNumber(const unsigned int& ibank,const unsigned long& val) { if( m_data && (m_data[ibank]) ) { (m_data[ibank])->setRunNumber(val); } } + void setEventNumber(const unsigned int& ibank,const unsigned long& val) { if( m_data && (m_data[ibank]) ) { (m_data[ibank])->setEventNumber(val); } } - void clearRoads(); - void prepareFits(); + void clearRoads(); + void prepareFits(); }; #endif // FTK_RoadMarketTool_H diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketToolI.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketToolI.h index 98f288d9e68..3ba13dd1aae 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketToolI.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/FTK_RoadMarketToolI.h @@ -17,25 +17,25 @@ class RoadFinder; class TrackFitter; class TTree; -class FTK_RoadMarketToolI : virtual public IAlgTool -{ - public: - /** access to tool interface */ - static const InterfaceID& interfaceID(); - - //functions that can be accessed by a tool handle - virtual FTKRoadOutput* outputReference()=0; // get the reference to the FTKDataInput object - virtual FTKRoadInput* inputReference()=0; // get the reference to the FTKDataInput object - virtual void ConnectRoads(TTree*,const char *,const std::vector&, int bs=0)=0; - virtual RoadFinder* roadFinderReference()=0; - virtual void setRoadFinderReference(RoadFinder* roadfinder) = 0; - virtual TrackFitter* trackFitterReference()=0; - virtual void setTrackFitterReference(TrackFitter* trackfitter) = 0; +class FTK_RoadMarketToolI : virtual public IAlgTool +{ +public: + /** access to tool interface */ + static const InterfaceID& interfaceID(); + + //functions that can be accessed by a tool handle + virtual FTKRoadOutput* outputReference()=0; // get the reference to the FTKDataInput object + virtual FTKRoadInput* inputReference()=0; // get the reference to the FTKDataInput object + virtual void ConnectRoads(TTree*,const char *,const std::vector&, int bs=0)=0; + virtual RoadFinder* roadFinderReference()=0; + virtual void setRoadFinderReference(RoadFinder* roadfinder) = 0; + virtual TrackFitter* trackFitterReference()=0; + virtual void setTrackFitterReference(TrackFitter* trackfitter) = 0; }; inline const InterfaceID& FTK_RoadMarketToolI::interfaceID() { - return IID_FTK_RoadMarketToolI; + return IID_FTK_RoadMarketToolI; } #endif // FTK_SGROADOUTPUTI_H diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/RoadFinder.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/RoadFinder.h index 635787e3a5e..d4727039f57 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/RoadFinder.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/RoadFinder.h @@ -19,85 +19,69 @@ class FTK_AMsimulation_base; class RoadFinder { private: - int m_verbosity; + int m_verbosity; - FTKDataInput *m_datainput; // generic pointer to read input data - - FTKRoadOutput *m_roadoutput; // generic pointer to write road results + FTKDataInput *m_datainput; // generic pointer to read input data - int m_nbanks; // number of banks in this configuration - int m_nsubs; // # of subregions (gets from ${M}) - int m_sub; // current subregion + FTKRoadOutput *m_roadoutput; // generic pointer to write road results - FTK_AMsimulation_base **m_banks; // array with the AM banks + int m_nbanks; // number of banks in this configuration + int m_nsubs; // # of subregions (gets from ${M}) + int m_sub; // current subregion - bool *m_goodRegion; // array with a flag to check which region are really simulated + FTK_AMsimulation_base **m_banks; // array with the AM banks - int m_roadwarrior; // road warrior level, 0 off + bool *m_goodRegion; // array with a flag to check which region are really simulated - // resources needed for PIX+SCTtrk mode - int m_SCTtrk_nlayers; - int m_SCTtrk_nsubs; - int m_SCTtrk_lastlayer; - int m_SCTtrk_maxMissingPlanes; - FTKSectorMap *m_sector_map; + int m_roadwarrior; // road warrior level, 0 off - bool m_SSsearch_unused; // group hits in unused layers in SSs + // resources needed for PIX+SCTtrk mode + FTKSectorMap *m_sector_map; + + bool m_SSsearch_unused; // group hits in unused layers in SSs public: - RoadFinder(); - ~RoadFinder(); + RoadFinder(); + ~RoadFinder(); - void init(); - void end(); + void init(); + void end(); - void setVerbosity(int v) { m_verbosity = v; } - int getVerbosity() { return m_verbosity; } + void setVerbosity(int v) { m_verbosity = v; } + int getVerbosity() { return m_verbosity; } - // set the data input module using an abstract class - void setDataInputModule(FTKDataInput *module) + // set the data input module using an abstract class + void setDataInputModule(FTKDataInput *module) { m_datainput = module; } - FTKDataInput* getDataInputModule() - { return m_datainput; } - - void setRoadOutputModule(FTKRoadOutput *module) - { m_roadoutput = module; } - - FTKRoadOutput* getRoadOutputModule() - { return m_roadoutput; } - - void setNBanks(int); - int getNBanks() const { return m_nbanks; } - - void setAMBank(int, FTK_AMsimulation_base*); - FTK_AMsimulation_base* getAMBank(int id) { - return m_banks[id]; - } + FTKDataInput* getDataInputModule() + { return m_datainput; } - void setSCTtrkNlayers(int v) { m_SCTtrk_nlayers = v; } - int getSCTtrkNlayers() const { return m_SCTtrk_nlayers; } + void setRoadOutputModule(FTKRoadOutput *module) + { m_roadoutput = module; } - void setSCTtrkNsubs(int v) { m_SCTtrk_nsubs = v; } - int getSCTtrkNsubs() const { return m_SCTtrk_nsubs; } + FTKRoadOutput* getRoadOutputModule() + { return m_roadoutput; } - void setNsubregions(int v) { m_nsubs = v; } - int getNsubregions() const { return m_nsubs; } + void setNBanks(int); + int getNBanks() const { return m_nbanks; } - void setSubregion(int v) { m_sub = v; } - int getSubregion() const { return m_sub; } + void setAMBank(int, FTK_AMsimulation_base*); + FTK_AMsimulation_base* getAMBank(int id) { + return m_banks[id]; + } - void setSCTtrkLastLayer(int v) { m_SCTtrk_lastlayer = v; } - int getSCTtrkLastLayer() const { return m_SCTtrk_lastlayer; } + void setNsubregions(int v) { m_nsubs = v; } + int getNsubregions() const { return m_nsubs; } - void setSCTtrkMaxMissingPlanes(int v) { m_SCTtrk_maxMissingPlanes = v; } - int getSCTtrkMaxMissingPlanes() const { return m_SCTtrk_maxMissingPlanes; } + void setSubregion(int v) { m_sub = v; } + int getSubregion() const { return m_sub; } - void setSectorMap(FTKSectorMap *s) { m_sector_map = s; } - int applySectorMap(int, int); + void setSectorMap(FTKSectorMap *s) { m_sector_map = s; } + int applySectorMap(int, int); - void setSSSearchUnused(bool flag) { m_SSsearch_unused = flag; } - bool getSSSearchUnused() const { return m_SSsearch_unused; } + void setSSSearchUnused(bool flag) { m_SSsearch_unused = flag; } + bool getSSSearchUnused() const { return m_SSsearch_unused; } - int nextEvent(); // elaborate the following event + int nextEvent(); // elaborate the following event }; #endif // ROADFINDER_H diff --git a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/ftkdefs.h b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/ftkdefs.h index 4d56548e402..ee35461f98d 100644 --- a/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/ftkdefs.h +++ b/Trigger/TrigFTK/TrigFTKSim/TrigFTKSim/ftkdefs.h @@ -17,13 +17,12 @@ * \brief FTK default values. */ namespace ftk { - const int NHITTYPES(3); ///< Number of coordinate types: PIXEL, SCT, SCTTrk + const int NHITTYPES(2); ///< Number of coordinate types: PIXEL, SCT const int MAXPLANES(20); const int NOASSIGNED(-999); const int PIXEL(1); const int SCT(0); - const int SCTtrk(2); const int BARREL(0); const int ENDCAP(1); const int POSEC(2); diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx index 1074196314f..8138e58f461 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKClusteringEngine.cxx @@ -322,16 +322,11 @@ bool FTKClusteringEngine::isKilled(const std::unique_ptr& clu, const hi */ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) { - const unsigned int &nHits = clu->hitlist.size(); - FTKRawHit &av = clu->clusterEquiv; ///< get pointer to clusterEquivalent FTKRawHit first = *(clu->hitlist.front()); ///< get 1st hit /// reset values for clusterEquivalent (alias av) av.reset(); - av.setX(0); - av.setY(0); - av.setZ(0); av.setIdentifierHash(first.getIdentifierHash()); av.setHitType(first.getHitType()); av.setModuleType(first.getModuleType()); @@ -407,9 +402,6 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) int lastStrip = -99999; av.setPhiSide(first.getPhiSide()); for (const auto &hit: clu->hitlist) { - av.addX(hit->getX()); - av.addY(hit->getY()); - av.addZ(hit->getZ()); if (hit->getEtaStrip() < firstStrip) firstStrip = hit->getEtaStrip(); if (hit->getEtaStrip()+hit->getNStrips()-1 > lastStrip) @@ -434,35 +426,6 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) case ftk::PIXEL: { av.setPhiSide(0); // eta is reset a few lines above - if (pixelClusteringMode == 0) { - for (const auto& hit: clu->hitlist) { //loop over hits in cluster - if (saveClusterContent) { // if enabled the cluster also stores also the single channels - FTKRawHit tmpch = *hit; - // set the barcode of the single channel, this may allow a very refined debugging of - // the cluster content accounting for the single barcode of each channel - MultiTruth mt; - MultiTruth::Barcode uniquecode(tmpch.getEventIndex(),tmpch.getBarcode()); - mt.maximize(uniquecode,tmpch.getBarcodePt()); - tmpch.setTruth(mt); - av.addChannel(tmpch); - } - av.addX(hit->getX()); - av.addY(hit->getY()); - av.addZ(hit->getZ()); - av.addPhiSide(hit->getPhiSide()); // phi index - // pixels are counted starting from 0 (left edge) and not 0.5 (center position) - // if only pixel 0 is hit the output value will be 0 and not 0.5 (pixel center) - av.addEtaStrip(hit->getEtaStrip()); // eta index - } - tmp = (int)round((av.getEtaStrip()*1.)/nHits); - av.setDeltaEta((av.getEtaStrip()*1.)/nHits-tmp); - av.setEtaStrip(tmp); - tmp = (int)round((av.getPhiSide()*1.)/nHits); - av.setDeltaPhi((av.getPhiSide()*1.)/nHits-tmp); - av.setPhiSide(tmp); - break; - } - /* For pixelClusteringMode > 0 * calculate cluster center following code at line 701 of * https://svnweb.cern.ch/trac/atlasoff/browser/InnerDetector/InDetRecTools/SiClusterizationTool/trunk/src/MergedPixelsTool.cxx#L701 @@ -483,10 +446,6 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) av.addChannel(tmpch); } - av.addX(hit->getX()); - av.addY(hit->getY()); - av.addZ(hit->getZ()); - int row = hit->getPhiSide(); int col = hit->getEtaStrip(); int tot = hit->getTot(); // ToT for pixels @@ -714,11 +673,6 @@ void FTKClusteringEngine::averageCluster(std::unique_ptr& clu) break; } // end of switch - // finally divide by nHits - av.divX(nHits); - av.divY(nHits); - av.divZ(nHits); - // AB - perform geant parent matching and store with the cluster // data. this involves passing all raw hits associated with the // cluster to a MultiTruth which will be stored with the hit diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx index 90a5096c7d0..25bf6ca4eee 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKDataInput.cxx @@ -129,26 +129,26 @@ void FTKDataInput::processEvent(bool clearOrig) // read SCTtrk values (Constantinos case) and push SCTtrk hits into hits vector: // Note that it assumes the raw data input and root track input are fully in sync! - if(m_trackinput && m_roadinput) { - for(int i=0;inextEvent(); - if(res<0) { - FTKSetup::PrintMessage(ftk::sevr,"SCTtrk input ran out before hit input"); - } - res = m_roadinput[i]->nextEvent(); - if(res<0) { - FTKSetup::PrintMessage(ftk::sevr,"SCTtrk road input ran out before hit input"); - } - const FTKTrack *cur_track = m_trackinput[i]->nextTrack(m_region); - while (cur_track) { - FTKRawHit tmphit(cur_track,m_pmap->getSCTtrkPlane()); - m_original_hits.push_back(tmphit); - cur_track = m_trackinput[i]->nextTrack(m_region); - } - } - } + // if(m_trackinput && m_roadinput) { + // for(int i=0;inextEvent(); + // if(res<0) { + // FTKSetup::PrintMessage(ftk::sevr,"SCTtrk input ran out before hit input"); + // } + // res = m_roadinput[i]->nextEvent(); + // if(res<0) { + // FTKSetup::PrintMessage(ftk::sevr,"SCTtrk road input ran out before hit input"); + // } + // const FTKTrack *cur_track = m_trackinput[i]->nextTrack(m_region); + // while (cur_track) { + // FTKRawHit tmphit(cur_track,m_pmap->getSCTtrkPlane()); + // m_original_hits.push_back(tmphit); + // cur_track = m_trackinput[i]->nextTrack(m_region); + // } + // } + // } // filter the hit end convert input hit format into FTKHit vector::iterator irawhit = m_original_hits.begin(); @@ -165,11 +165,6 @@ void FTKDataInput::processEvent(bool clearOrig) // skip this hit continue; } - // check if SCT hits should be accepted - if(rawhit.getIsSCT() && ftkset.getSCTtrkMode()) { - // skip this hit - continue; - } if (m_pmap->getMap(rawhit.getHitType(),rawhit.getBarrelEC()!=0,rawhit.getLayer()).getPlane() != -1) { // accept this hit FTKHit tmphit = rawhit.getFTKHit(m_pmap); @@ -254,26 +249,6 @@ void FTKDataInput::processRegion(int curreg, bool clearOrig) } m_nao_nclus_tot += currawhits.size(); - // read SCTtrk values (Constantinos case) and push SCTtrk hits into hits vector: - // Note that it assumes the raw data input and root track input are fully in sync! - if(m_trackinput && m_roadinput) { - // for now, only read tracks from "current" region - int res = m_trackinput[curreg]->nextEvent(); - if(res<0) { - FTKSetup::PrintMessage(ftk::sevr,"SCTtrk input ran out before hit input"); - } - res = m_roadinput[curreg]->nextEvent(); - if(res<0) { - FTKSetup::PrintMessage(ftk::sevr,"SCTtrk road input ran out before hit input"); - } - const FTKTrack *cur_track = m_trackinput[curreg]->nextTrack(m_region); - while (cur_track) { - FTKRawHit tmphit(cur_track,m_pmap->getSCTtrkPlane()); - m_original_hits.push_back(tmphit); - cur_track = m_trackinput[curreg]->nextTrack(m_region); - } - } - // filter the hit end convert input hit format into FTKHit vector::iterator irawhit = currawhits.begin(); FTKSetup &ftkset = FTKSetup::getFTKSetup(); @@ -289,11 +264,6 @@ void FTKDataInput::processRegion(int curreg, bool clearOrig) // skip this hit continue; } - // check if SCT hits should be accepted - if(rawhit.getIsSCT() && ftkset.getSCTtrkMode()) { - // skip this hit - continue; - } if (m_pmap->getMap(rawhit.getHitType(),rawhit.getBarrelEC()!=0,rawhit.getLayer()).getPlane() != -1) { // accept this hit FTKHit tmphit = rawhit.getFTKHit(m_pmap); diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKMergerAlgo.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKMergerAlgo.cxx index 933f6760994..75fcda6405f 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKMergerAlgo.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKMergerAlgo.cxx @@ -2464,7 +2464,6 @@ StatusCode FTKMergerAlgo::merge_roads(FTKRoadStream * &newbank,FTKRoadStream **o // the sub-region ID is hidden in this formula sub*100+reg new_road->setBankID(/*100*isr*ENCODE_SUBREGION+*/cur_road->getBankID()); } - newbank->inc4LRoad(oldbanks[isr]->getN4LRoads()); // add the SS for all the layers const FTKSS_container_t &strips_cont = oldbanks[isr]->getSSContainer(); int cont_nplanes = strips_cont.size(); diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKPMap.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKPMap.cxx index dd2c96fa950..dc46317ed77 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKPMap.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKPMap.cxx @@ -18,35 +18,35 @@ using namespace std; using namespace ftk; FTKPlaneSection::FTKPlaneSection() - : m_plane(-1), m_section(0) + : m_plane(-1), m_section(0) { - // nothing to do + // nothing to do } FTKPlaneSection::FTKPlaneSection(int plane, int section) - : m_plane(plane), m_section(section) + : m_plane(plane), m_section(section) { - // nothing to do + // nothing to do } FTKModuleInfo::FTKModuleInfo() : - m_isEndcap(0), m_layer(-1), m_pdisk(0), m_nphi(-1), - m_neta(-1), - m_nfi(0), m_ncott(0), m_ncurv(0), - m_nste(0), m_ndimension(0) + m_isEndcap(0), m_layer(-1), m_pdisk(0), m_nphi(-1), + m_neta(-1), + m_nfi(0), m_ncott(0), m_ncurv(0), + m_nste(0), m_ndimension(0) { - // nothing to do here + // nothing to do here } FTKModuleInfo::FTKModuleInfo(int isEndcap,int layer,int pdisk, - int nphi,int neta,int nfi,int ncott,int ncurv,int nste,int ndimension) : - m_isEndcap(isEndcap), m_layer(layer), m_pdisk(pdisk), m_nphi(nphi), m_neta (neta), - m_nfi(nfi), m_ncott(ncott) ,m_ncurv(ncurv) ,m_nste(nste), m_ndimension(ndimension) + int nphi,int neta,int nfi,int ncott,int ncurv,int nste,int ndimension) : + m_isEndcap(isEndcap), m_layer(layer), m_pdisk(pdisk), m_nphi(nphi), m_neta (neta), + m_nfi(nfi), m_ncott(ncott) ,m_ncurv(ncurv) ,m_nste(nste), m_ndimension(ndimension) { - // + // } @@ -54,155 +54,148 @@ const TString FTKPlaneMap::s_dirname = "PlaneMap"; FTKPlaneMap::FTKPlaneMap(const char *fname) : - m_path(fname), m_nplanes(0), // m_nlayers(0), - m_rlayers(0), - m_totaldim(0), m_planeType(0), - m_isZ(0), - m_planePair(0), - m_enablePlanePair(false), - m_nsections(0), - m_isok(false) + m_path(fname), m_nplanes(0), // m_nlayers(0), + m_rlayers(0), + m_totaldim(0), m_planeType(0), + m_isZ(0), + m_planePair(0), + m_enablePlanePair(false), + m_nsections(0), + m_isok(false) { - //! Default constructor - FTKSetup &ftkset = FTKSetup::getFTKSetup(); - m_idim[0] = 0; m_idim[1] = 0; - m_planes = 0x0; - - // cmDebug was a variable used in the old version, here - // redefined as a boolean true if the FTK verbosity level - // is greater than 1 - bool cmDebug = ftkset.getVerbosity()>1 ? true : false; - - // pmap file pointer - FILE *fpmap = fopen(fname,"r"); - if (!fpmap) { - cerr << "*** error reading pmap file: " << fname << endl; - return; - } - - - /* the code to read PMAP file is taken from the original - F pmap_rd.c. */ - - // store the maximum ID of an unused plane, - // needed to size the m_planes_unused - int max_plane_id(-1); - - int used_plane_dim[ftk::MAXPLANES]; - int used_plane_sections[ftk::MAXPLANES]; - int section; - char line[100]; - int npixel=0, npixelEC=0, nSCT=0, nSCTEC=0, ntot, isEC, i, pd, plane, nphi, neta, nste, ndimension; - int nSCTtrk=0, nfi, ncott, ncurv; // cy addition - char buf1[20]; - char buf2[20]; - - if (cmDebug) { - FTKSetup::PrintMessageFmt(warn,"In pmap_rd, barrelOnly = %d",ftkset.getBarrelOnly()); - } - - // zeroes the counters - for (int j=0; j < ftk::MAXPLANES; j++) { - used_plane_dim[j] = 0; - used_plane_sections[j] = 0; - } - - /* check for correct file format */ - if (fgets(line,100,fpmap)!=NULL) { - if (cmDebug) printf("%s\n",line); - sscanf(line,"%d %19s %19s",&npixel,buf1,buf2); - if (cmDebug) printf("%s %s\n",buf1,buf2); - if (strcmp(buf2,"barrel")) { - // pre end-cap extension format - FTKSetup::PrintMessage(ftk::sevr,"In pmap_rd, old pmap file format (before endcap extension) is no longer supported"); + //! Default constructor + FTKSetup &ftkset = FTKSetup::getFTKSetup(); + m_idim[0] = 0; m_idim[1] = 0; + m_planes = 0x0; + + // cmDebug was a variable used in the old version, here + // redefined as a boolean true if the FTK verbosity level + // is greater than 1 + bool cmDebug = ftkset.getVerbosity()>1 ? true : false; + + // pmap file pointer + FILE *fpmap = fopen(fname,"r"); + if (!fpmap) { + cerr << "*** error reading pmap file: " << fname << endl; + return; } - } else { - FTKSetup::PrintMessage(ftk::sevr,"In pmap_rd, pmap file empty?"); - } - // after the check return at the begin - rewind(fpmap); - - if (cmDebug) FTKSetup::PrintMessage(info,"getting pmap size, new format\n"); - - /* - * retrive the information on the number of pixel and SCT layers - */ - - if(fgets(line,100,fpmap)==NULL) - FTKSetup::PrintMessage(sevr,"pmap_rd: Reading of pmap file failed."); - sscanf(line,"%d pixel barrel",&npixel); - if(fgets(line,100,fpmap)==NULL) - FTKSetup::PrintMessage(sevr,"pmap_rd: Reading of pmap file failed."); - sscanf(line,"%d pixel endcap",&npixelEC); - - // Check if we have SCTtrk or real SCT planes: - if(fgets(line,100,fpmap)==NULL) - FTKSetup::PrintMessage(sevr,"pmap_rd: Reading of pmap file failed."); - if (strstr(line,"SCTtrk")) { - sscanf(line,"%d SCTtrk",&nSCTtrk); - } - else { - nSCTtrk=0; - sscanf(line,"%d SCT barrel",&nSCT); + + + /* the code to read PMAP file is taken from the original + F pmap_rd.c. */ + + // store the maximum ID of an unused plane, + // needed to size the m_planes_unused + int max_plane_id(-1); + + int used_plane_dim[ftk::MAXPLANES]; + int used_plane_sections[ftk::MAXPLANES]; + int section; + char line[100]; + int npixel=0, npixelEC=0, nSCT=0, nSCTEC=0, ntot, isEC, i, pd, plane, nphi, neta, nste, ndimension; + int ncott, ncurv; // cy addition + char buf1[20]; + char buf2[20]; + + if (cmDebug) { + FTKSetup::PrintMessageFmt(warn,"In pmap_rd, barrelOnly = %d",ftkset.getBarrelOnly()); + } + + // zeroes the counters + for (int j=0; j < ftk::MAXPLANES; j++) { + used_plane_dim[j] = 0; + used_plane_sections[j] = 0; + } + + /* check for correct file format */ + if (fgets(line,100,fpmap)!=NULL) { + if (cmDebug) printf("%s\n",line); + sscanf(line,"%d %19s %19s",&npixel,buf1,buf2); + if (cmDebug) printf("%s %s\n",buf1,buf2); + if (strcmp(buf2,"barrel")) { + // pre end-cap extension format + FTKSetup::PrintMessage(ftk::sevr,"In pmap_rd, old pmap file format (before endcap extension) is no longer supported"); + } + } else { + FTKSetup::PrintMessage(ftk::sevr,"In pmap_rd, pmap file empty?"); + } + // after the check return at the begin + rewind(fpmap); + + if (cmDebug) FTKSetup::PrintMessage(info,"getting pmap size, new format\n"); + + /* + * retrieve the information on the number of pixel and SCT layers + */ + if(fgets(line,100,fpmap)==NULL) - FTKSetup::PrintMessage(sevr,"pmap_rd: Reading of pmap file failed."); - sscanf(line,"%d SCT endcap",&nSCTEC); - } - - // fix the total number of layers to setup - ntot=nSCTtrk+nSCT+nSCTEC+npixel+npixelEC; - - if (cmDebug) FTKSetup::PrintMessage(debg,"Allocating pmap...\n"); - /* Allocation of map. This way we also defaults all to plane 0 - * because of calloc behaviour. - */ - m_map[PIXEL][BARREL] = new FTKPlaneSection[npixel]; - if (!m_map[PIXEL][BARREL]) - FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap pixel barrel failed."); - - m_map[PIXEL][ENDCAP] = new FTKPlaneSection[npixelEC]; - if (!m_map[PIXEL][ENDCAP]) - FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap pixel endcap failed."); - - m_map[SCTtrk][BARREL] = new FTKPlaneSection[nSCTtrk]; - if (!m_map[SCTtrk][BARREL]) - FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap SCTtrk barrel failed."); - - m_map[SCT][BARREL] = new FTKPlaneSection[nSCT]; - if (!m_map[SCT][BARREL]) - FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap SCT barrel failed."); - m_map[SCT][ENDCAP] = new FTKPlaneSection[nSCTEC]; - if (!m_map[SCT][ENDCAP]) - FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap SCT endcap failed."); - if (cmDebug) FTKSetup::PrintMessage(debg,"\t\t...done\n"); - - printf("=== Layer Configuration ===\n"); - - while(fgets(line,100,fpmap)!=NULL) { // first read loop - switch(line[0]) { - - case 'p': - - /* read */ - sscanf(line,"pixel %d %d %d dim %d plane %d",&isEC,&pd,&i,&ndimension,&plane); - - - /* print */ - if(plane!=-1 ) { - if (plane>max_plane_id) max_plane_id = plane; - if (!isEC) - printf("Pixel barrel: i = %d, NofLogPlane = %d section %d ndim %d\n", - i, plane, used_plane_sections[plane],ndimension); - else - printf("Pixel endcap: i = %d, NofLogPlane = %d section %d ndim %d\n", - i, plane, used_plane_sections[plane],ndimension); - } + FTKSetup::PrintMessage(sevr,"pmap_rd: Reading of pmap file failed."); + sscanf(line,"%d pixel barrel",&npixel); - /* store to map */ - m_map[PIXEL][isEC][i].setPlane(plane); - if (plane != -1) - m_map[PIXEL][isEC][i].setSection(used_plane_sections[plane]); - m_rlayers++; + if(fgets(line,100,fpmap)==NULL) + FTKSetup::PrintMessage(sevr,"pmap_rd: Reading of pmap file failed."); + sscanf(line,"%d pixel endcap",&npixelEC); + + // Check if we have SCTtrk or real SCT planes: + if(fgets(line,100,fpmap)==NULL) + FTKSetup::PrintMessage(sevr,"pmap_rd: Reading of pmap file failed."); + + sscanf(line,"%d SCT barrel",&nSCT); + if(fgets(line,100,fpmap)==NULL) + FTKSetup::PrintMessage(sevr,"pmap_rd: Reading of pmap file failed."); + sscanf(line,"%d SCT endcap",&nSCTEC); + // } + + // fix the total number of layers to setup + ntot=nSCT+nSCTEC+npixel+npixelEC; + + if (cmDebug) FTKSetup::PrintMessage(debg,"Allocating pmap...\n"); + /* Allocation of map. This way we also defaults all to plane 0 + * because of calloc behaviour. + */ + m_map[PIXEL][BARREL] = new FTKPlaneSection[npixel]; + if (!m_map[PIXEL][BARREL]) + FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap pixel barrel failed."); + + m_map[PIXEL][ENDCAP] = new FTKPlaneSection[npixelEC]; + if (!m_map[PIXEL][ENDCAP]) + FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap pixel endcap failed."); + + m_map[SCT][BARREL] = new FTKPlaneSection[nSCT]; + if (!m_map[SCT][BARREL]) + FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap SCT barrel failed."); + m_map[SCT][ENDCAP] = new FTKPlaneSection[nSCTEC]; + if (!m_map[SCT][ENDCAP]) + FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap SCT endcap failed."); + if (cmDebug) FTKSetup::PrintMessage(debg,"\t\t...done\n"); + + printf("=== Layer Configuration ===\n"); + + while(fgets(line,100,fpmap)!=NULL) { // first read loop + switch(line[0]) { + + case 'p': + + /* read */ + sscanf(line,"pixel %d %d %d dim %d plane %d",&isEC,&pd,&i,&ndimension,&plane); + + + /* print */ + if(plane!=-1 ) { + if (plane>max_plane_id) max_plane_id = plane; + if (!isEC) + printf("Pixel barrel: i = %d, NofLogPlane = %d section %d ndim %d\n", + i, plane, used_plane_sections[plane],ndimension); + else + printf("Pixel endcap: i = %d, NofLogPlane = %d section %d ndim %d\n", + i, plane, used_plane_sections[plane],ndimension); + } + + /* store to map */ + m_map[PIXEL][isEC][i].setPlane(plane); + if (plane != -1) + m_map[PIXEL][isEC][i].setSection(used_plane_sections[plane]); + m_rlayers++; /* if (cmDebug) { * printf("Read back plane %d section %d", @@ -212,529 +205,491 @@ FTKPlaneMap::FTKPlaneMap(const char *fname) : * } */ - /* count number of modules, record dimension, used plane number */ - if (plane < ftk::MAXPLANES) { - if (plane != -1) { - used_plane_dim[plane] = ndimension; - used_plane_sections[plane]++; - } - } else { - FTKSetup::PrintMessage(sevr,"pmap_rd: Logical plane above maximum allowed."); - } + /* count number of modules, record dimension, used plane number */ + if (plane < ftk::MAXPLANES) { + if (plane != -1) { + used_plane_dim[plane] = ndimension; + used_plane_sections[plane]++; + } + } else { + FTKSetup::PrintMessage(sevr,"pmap_rd: Logical plane above maximum allowed."); + } + + break; + + case 'S': + + /* read */ + std::cout << " Reading the file" << std::endl; + sscanf(line,"SCT %d %d %d dim %d stereo %d plane %d",&isEC,&pd,&i,&ndimension,&nste,&plane); + + /* print */ + if(plane!=-1) { + if (plane>max_plane_id) + max_plane_id = plane; + if (!isEC) + printf("SCT barrel: i = %d, NofLogPlane = %d section %d \n", + i, plane, used_plane_sections[plane]); + else + printf("SCT endcap: i = %d, NofLogPlane = %d section %d \n", + i, plane, used_plane_sections[plane]); + } + + std::cout << " store to map" << std::endl; + /* store to map */ + m_map[SCT][isEC][i].setPlane(plane); + if (plane != -1) + m_map[SCT][isEC][i].setSection(used_plane_sections[plane]); + m_rlayers++; + + std::cout << "maxplanes:" << ftk::MAXPLANES << std::endl; + /* count number of modules, record dimension, used plane number */ + if (plane < ftk::MAXPLANES) { + if(plane != -1) { + used_plane_dim[plane] = ndimension; + used_plane_sections[plane]++; + } + } else { + FTKSetup::PrintMessage(sevr,"pmap_rd: Logical plane above maximum allowed."); + } + break; + + default: + FTKSetup::PrintMessageFmt(sevr,"pmap_rd: Bad file format: %s",line); + break; + } + } // end first read loop + + if (cmDebug) FTKSetup::PrintMessage(debg,"First pmap file read done\n"); + + /* decode used_plane_dim to infer number of valid logical planes and their dimension */ + m_nplanes = max_plane_id+1; + + for (int j = 0; j < ftk::MAXPLANES; j++) { + if (used_plane_dim[j]) { + m_totaldim += used_plane_dim[j]; + } + } - break; - - case 'S': - - /* read */ - if(nSCTtrk==0) - sscanf(line,"SCT %d %d %d dim %d stereo %d plane %d",&isEC,&pd,&i,&ndimension,&nste,&plane); - else - { - sscanf(line,"SCTtrk %d dim %d plane %d phi %d cott %d curv %d",&i,&ndimension,&plane, &nfi,&ncott,&ncurv); - isEC=0; - pd=-1; - } - - - /* print */ - if(plane!=-1) { - if (plane>max_plane_id) max_plane_id = plane; - if(nSCTtrk==0) { - if (!isEC) - printf("SCT barrel: i = %d, NofLogPlane = %d section %d \n", - i, plane, used_plane_sections[plane]); - else - printf("SCT endcap: i = %d, NofLogPlane = %d section %d \n", - i, plane, used_plane_sections[plane]); - } - else - printf("SCTtrk: i = %d, NofLogPlane = %d section %d ndim %d\n", - i, plane, used_plane_sections[plane],ndimension); - } - /* store to map */ - if(nSCTtrk==0) { - m_map[SCT][isEC][i].setPlane(plane); - if (plane != -1) - m_map[SCT][isEC][i].setSection(used_plane_sections[plane]); - } - else { - m_map[SCTtrk][isEC][i].setPlane(plane); - if (plane != -1) - m_map[SCTtrk][isEC][i].setSection(used_plane_sections[plane]); - } - m_rlayers++; - - /* count number of modules, record dimension, used plane number */ - if (plane < ftk::MAXPLANES) { - if(plane != -1) { - used_plane_dim[plane] = ndimension; - used_plane_sections[plane]++; - } - } else { - FTKSetup::PrintMessage(sevr,"pmap_rd: Logical plane above maximum allowed."); - } - break; - - default: - FTKSetup::PrintMessageFmt(sevr,"pmap_rd: Bad file format: %s",line); - break; + // allocate the array to store the number of used sections + m_nsections = new int[ftk::MAXPLANES]; + if ((m_nsections = (int *)calloc(ftk::MAXPLANES,sizeof(int))) == NULL) + FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap nsections failed."); + for (int j = 0; j < ftk::MAXPLANES; j++) { + m_nsections[j] = 0; // initialize the value + if (used_plane_dim[j]) { + m_nsections[j] = used_plane_sections[j]; + if (cmDebug) printf("Plane %d has %d sections\n",j,m_nsections[j]); + } } - } // end first read loop - if (cmDebug) FTKSetup::PrintMessage(debg,"First pmap file read done\n"); - /* decode used_plane_dim to infer number of valid logical planes and their dimension */ - m_nplanes = max_plane_id+1; + /* Need to rewire this to accomodate multiple physical sections per plane */ + /* with the inclusion of the endcap, it is no longer a 1<->1 mapping */ + /* Now: 2d array, multiple sections per plane. */ + + if (cmDebug) FTKSetup::PrintMessage(debg,"Allocating moduleInfo array...\n"); + + if(!(m_planes = new FTKModuleInfo*[m_nplanes])) + FTKSetup::PrintMessage(sevr,"pmap_rd: Failed to alloc plane details space 1"); + + for (int j = 0; j < m_nplanes; j++) { + if(!(m_planes[j] = new FTKModuleInfo[m_nsections[j]])) + FTKSetup::PrintMessage(sevr,"pmap_rd: Failed to alloc plane details space 2"); + } - for (int j = 0; j < ftk::MAXPLANES; j++) { - if (used_plane_dim[j]) { - m_totaldim += used_plane_dim[j]; + + if (cmDebug) { + FTKSetup::PrintMessage(debg,"\t\t...done\n"); + printf("Building isZ, idim maps, m_totaldim = %d, ntot = %d\n",m_totaldim,ntot); + FTKSetup::PrintMessage(debg,"\n"); } - } - - - // allocate the array to store the number of used sections - m_nsections = new int[ftk::MAXPLANES]; - if ((m_nsections = (int *)calloc(ftk::MAXPLANES,sizeof(int))) == NULL) - FTKSetup::PrintMessage(sevr,"pmap_rd: Allocation of pmap nsections failed."); - for (int j = 0; j < ftk::MAXPLANES; j++) { - m_nsections[j] = 0; // initialize the value - if (used_plane_dim[j]) { - m_nsections[j] = used_plane_sections[j]; - if (cmDebug) printf("Plane %d has %d sections\n",j,m_nsections[j]); + + m_isZ = new int[m_totaldim]; + m_planePair = new int[m_nplanes]; + m_planeType = new int[m_nplanes]; + m_idim[0] = new int[m_nplanes]; + m_idim[1] = new int[m_nplanes]; + for(int l=0;l1 mapping */ - /* Now: 2d array, multiple sections per plane. */ - - if (cmDebug) FTKSetup::PrintMessage(debg,"Allocating moduleInfo array...\n"); - - if(!(m_planes = new FTKModuleInfo*[m_nplanes])) - FTKSetup::PrintMessage(sevr,"pmap_rd: Failed to alloc plane details space 1"); - - for (int j = 0; j < m_nplanes; j++) { - if(!(m_planes[j] = new FTKModuleInfo[m_nsections[j]])) - FTKSetup::PrintMessage(sevr,"pmap_rd: Failed to alloc plane details space 2"); - } - - - if (cmDebug) { - FTKSetup::PrintMessage(debg,"\t\t...done\n"); - printf("Building isZ, idim maps, m_totaldim = %d, ntot = %d\n",m_totaldim,ntot); - FTKSetup::PrintMessage(debg,"\n"); - } - - m_isZ = new int[m_totaldim]; - m_planePair = new int[m_nplanes]; - m_planeType = new int[m_nplanes]; - m_idim[0] = new int[m_nplanes]; - m_idim[1] = new int[m_nplanes]; - for(int l=0;l 4) { + // printf("\t\tisZ[j+l] = l: isZ[%d+%d] = %d\n",jcoord,l,l); + // printf("\t\tidim[l][k] = j+l idim[%d][%d] = %d\n",l,kcoord,jcoord+l); + // } + } + jcoord += ndimension; + kcoord += 1; + } + } + continue; + + case 'S': + /* read */ + sscanf(line,"SCT %d %d %d dim %d stereo %d plane %d phi %d eta %d",&isEC,&pd,&i,&ndimension,&nste,&plane, &nphi,&neta); + if (cmDebug) { + printf("SCT module isEC %d, ndim %d, plane %d, phi %d, eta %d", + isEC,ndimension,plane,nphi,neta); + FTKSetup::PrintMessage(debg,"\n"); + } + + /* store */ + if(plane != -1) { // used plane block + section = used_plane_sections[plane]++; + m_planes[plane][section].setIsEndcap(isEC); + m_planes[plane][section].setPDisk(pd); + m_planes[plane][section].setNumEta(neta); + m_planes[plane][section].setNumPhi(nphi); + m_planes[plane][section].setNSte(nste); + m_planes[plane][section].setNumFi(-1); + m_planes[plane][section].setNumCott(-1); + m_planes[plane][section].setNumCurv(-1); + m_planes[plane][section].setNDimension(ndimension); + m_planes[plane][section].setLayer(i); + // FlagAK: if coordinate ordering changes, this code must be changed + m_planeType[plane]=ftk::SCT; + // corrinne says: only count barrel (want information per plane), note + // that this requires all parts of a plane to have the same structure + if (!isEC) { + for(int l=0;l 4) { + // printf("isZ[j+l] = l: isZ[%d+%d] = %d\n",jcoord,l,l); + // printf("idim[l][k] = j+l idim[%d][%d] = %d\n",l,kcoord,jcoord+l); + // } + } + jcoord += ndimension; + kcoord += 1; + } + } // end used plane block + continue; + + default: + FTKSetup::PrintMessageFmt(sevr,"pmap_rd: Bad file format: %s",line); + } + } - /* read */ - sscanf(line,"pixel %d %d %d dim %d plane %d phi %d eta %d",&isEC,&pd,&i,&ndimension,&plane,&nphi,&neta); + if (cmDebug) { + DumpPMap(); + //FTKSetup::PrintMessage(debg,"\n\n"); + } - if (cmDebug) { - printf("Pixel module isEC %d, ndim %d, plane %d, phi %d, eta %d", - isEC,ndimension,plane,nphi,neta); - FTKSetup::PrintMessage(debg,"\n"); - } + // set the m_planePair array. When the 1st SCT plane is found + // it tests the following, if is a different configuration sets the + // pair to next, if is the same doesn't set any connection + for (int ip=0;ip!=m_nplanes;++ip) { + // default -1 value for non-SCT planes + if (m_planeType[ip]!=ftk::SCT) { + m_planePair[ip] = -1; + } + else { + if (ip==m_nplanes-1) { + // if reach the last element this is unpaired by definition + m_planePair[ip] = ip; + continue; + } + + if (m_planeType[ip+1]!=ftk::NOASSIGNED) { + // the PMAP can have discontinuities, ensure this is not the case + // if this layer and the next have a different orientation + // make the connection + if (m_planes[ip][0].getNSte()!=m_planes[ip+1][0].getNSte()) { + m_planePair[ip ] = ip+1; + m_planePair[ip+1] = ip; + ++ip; // move to the next unpaired SCT layer + } + else { + // this to not broke the FTK_AMBank::informationBank() behaviour, + // that assumes pairs of R-phi and stereo layers + m_planePair[ip] = ip; + } + } + else { + // no connection is possible also if the next layer is not assigned + m_planePair[ip] = ip; + } + } - /* store */ - if(plane != -1) { // Plane -1 is ignored, this way we have plane mask - section = used_plane_sections[plane]++; - m_planes[plane][section].setIsEndcap(isEC); - m_planes[plane][section].setPDisk(pd); - m_planes[plane][section].setNumEta(neta); - m_planes[plane][section].setNumPhi(nphi); - m_planes[plane][section].setNSte(-1); - m_planes[plane][section].setNumFi(-1); - m_planes[plane][section].setNumCott(-1); - m_planes[plane][section].setNumCurv(-1); - m_planes[plane][section].setNDimension(ndimension); - m_planes[plane][section].setLayer(i); - // FlagAK: if coordinate ordering changes, this code must be changed - // corrinne says: only count barrel (want information per plane), note - // that this requires all parts of a plane to have the same structure - m_planeType[plane]=ftk::PIXEL; - if (!isEC) { - for(int l=0;l 4) { - // printf("\t\tisZ[j+l] = l: isZ[%d+%d] = %d\n",jcoord,l,l); - // printf("\t\tidim[l][k] = j+l idim[%d][%d] = %d\n",l,kcoord,jcoord+l); - // } - } - jcoord += ndimension; - kcoord += 1; - } - } - continue; - - case 'S': - /* read */ - if(nSCTtrk==0) - sscanf(line,"SCT %d %d %d dim %d stereo %d plane %d phi %d eta %d",&isEC,&pd,&i,&ndimension,&nste,&plane, &nphi,&neta); - else{ - sscanf(line,"SCTtrk %d dim %d plane %d phi %d cott %d curv %d",&i,&ndimension,&plane, &nfi,&ncott,&ncurv); - isEC=0; - pd=-1; - } - if (cmDebug) { - printf("SCT module isEC %d, ndim %d, plane %d, phi %d, eta %d", - isEC,ndimension,plane,nphi,neta); - FTKSetup::PrintMessage(debg,"\n"); - } - /* store */ - if(plane != -1) { // used plane block - section = used_plane_sections[plane]++; - m_planes[plane][section].setIsEndcap(isEC); - m_planes[plane][section].setPDisk(pd); - if(nSCTtrk==0) { // default SCT block - m_planes[plane][section].setNumEta(neta); - m_planes[plane][section].setNumPhi(nphi); - m_planes[plane][section].setNSte(nste); - m_planes[plane][section].setNumFi(-1); - m_planes[plane][section].setNumCott(-1); - m_planes[plane][section].setNumCurv(-1); - } // end default SCT block - else { // SCTtrk block - m_planes[plane][section].setNumEta(-1); - m_planes[plane][section].setNumPhi(-1); - m_planes[plane][section].setNumFi(nfi); - m_planes[plane][section].setNumCott(ncott); - m_planes[plane][section].setNumCurv(ncurv); - m_planes[plane][section].setNSte(-2); - } // end SCTtrk block - m_planes[plane][section].setNDimension(ndimension); - m_planes[plane][section].setLayer(i); - // FlagAK: if coordinate ordering changes, this code must be changed - if(nSCTtrk==0) - m_planeType[plane]=ftk::SCT; - else - m_planeType[plane]=ftk::SCTtrk; - // corrinne says: only count barrel (want information per plane), note - // that this requires all parts of a plane to have the same structure - if (!isEC) { - for(int l=0;l 4) { - // printf("isZ[j+l] = l: isZ[%d+%d] = %d\n",jcoord,l,l); - // printf("idim[l][k] = j+l idim[%d][%d] = %d\n",l,kcoord,jcoord+l); - // } - } - jcoord += ndimension; - kcoord += 1; - } - } // end used plane block - continue; - - default: - FTKSetup::PrintMessageFmt(sevr,"pmap_rd: Bad file format: %s",line); } - } - - if (cmDebug) { - DumpPMap(); - //FTKSetup::PrintMessage(debg,"\n\n"); - } - - if(nSCTtrk==0){ - // set the m_planePair array. When the 1st SCT plane is found - // it tests the following, if is a different configuration sets the - // pair to next, if is the same doesn't set any connection - for (int ip=0;ip!=m_nplanes;++ip) { - // default -1 value for non-SCT planes - if (m_planeType[ip]!=ftk::SCT) { - m_planePair[ip] = -1; + fclose(fpmap); + m_isok = true; +} + +FTKPlaneMap::FTKPlaneMap(TDirectory* file) { + //! Read pmap class from root file + //! return NULL if reading failed. + //! check validity also using m_isok + + //cout<<"Instantiate PlaneMap from root file."<cd(s_dirname) ) { + cerr << "Error in FTKPlaneMap::FTKPlaneMap. No PlaneMap found in root-file. "<< endl; + return; } - else { - if (ip==m_nplanes-1) { - // if reach the last element this is unpaired by definition - m_planePair[ip] = ip; - continue; - } - if (m_planeType[ip+1]!=ftk::NOASSIGNED) { - // the PMAP can have discontinuities, ensure this is not the case - // if this layer and the next have a different orientation - // make the connection - if (m_planes[ip][0].getNSte()!=m_planes[ip+1][0].getNSte()) { - m_planePair[ip ] = ip+1; - m_planePair[ip+1] = ip; - ++ip; // move to the next unpaired SCT layer - } - else { - // this to not broke the FTK_AMBank::informationBank() behaviour, - // that assumes pairs of R-phi and stereo layers - m_planePair[ip] = ip; - } - } - else { - // no connection is possible also if the next layer is not assigned - m_planePair[ip] = ip; - } + m_path = gDirectory->GetTitle(); + //cout<<"PathName: "<Get("Planes"); + TTree* tree = (TTree*)gDirectory->Get("PlaneConstants"); + TTree* tConst = (TTree*)gDirectory->Get("Constants"); + if ( !tplane || !tree || !tConst ) { + cerr << "Error in FTKPlaneMap::FTKPlaneMap. Could not find trees. "<< endl; + cerr << " tree('Planes') "<GetBranch("nplanes")->SetAddress(&m_nplanes); + tConst->GetBranch("rlayers")->SetAddress(&m_rlayers); + tConst->GetBranch("totaldim")->SetAddress(&m_totaldim); + tConst->GetBranch("enablePlanePair")->SetAddress(&m_enablePlanePair); + tConst->GetBranch("Checksum")->SetAddress(&chksum); + // read constants + tConst->GetEntry(0); + // cout<<"nplanes "<GetEntries() != m_nplanes ) cerr<<"Error in FTKPlaneMap::FTKPlaneMap. Inconsistent nplanes."<GetBranch("isZ")->SetAddress(&isZ); + tree->GetBranch("planePair")->SetAddress(&planePair); + tree->GetBranch("planeType")->SetAddress(&planeType); + tree->GetBranch("idim_0")->SetAddress(&idim[0]); + tree->GetBranch("idim_1")->SetAddress(&idim[1]); + tree->GetBranch("nsections")->SetAddress(&nsections); + + m_planeType = new int[m_nplanes]; // SCT / PIXEL + m_isZ = new int[m_totaldim]; // legacy (unused) + m_planePair = new int[m_nplanes]; + m_idim[0]= new int[m_nplanes]; + m_idim[1]= new int[m_nplanes]; + m_nsections = new int[ftk::MAXPLANES]; // number of sections in the used planes + for ( int i = 0 ; i < ftk::MAXPLANES ; i++ ) m_nsections[i]=0; + + for ( int j = 0 ; jGetEntry(j); + m_planeType[j] = planeType; + m_isZ[j] = isZ; + m_planePair[j] = planePair; + m_idim[0][j] = idim[0]; + m_idim[1][j] = idim[1]; + m_nsections[j] = nsections; + } - } - } - fclose(fpmap); - m_isok = true; -} + int iplane,isection; + int isEndcap,layer,pdisk,nphi,neta,nfi,ncott,ncurv,nste,ndimension; + int mapSection,mapPlane,mapPlaneType,mapEC,mapItype; + tplane->GetBranch("iplane")->SetAddress(&iplane); + tplane->GetBranch("isection")->SetAddress(&isection); + + tplane->GetBranch("isEndcap")->SetAddress(&isEndcap); + tplane->GetBranch("layer")->SetAddress(&layer); + tplane->GetBranch("pdisk")->SetAddress(&pdisk); + tplane->GetBranch("nphi")->SetAddress(&nphi); + tplane->GetBranch("neta")->SetAddress(&neta); + tplane->GetBranch("nfi")->SetAddress(&nfi); + tplane->GetBranch("ncott")->SetAddress(&ncott); + tplane->GetBranch("ncurv")->SetAddress(&ncurv); + tplane->GetBranch("nste")->SetAddress(&nste); + tplane->GetBranch("ndimension")->SetAddress(&ndimension); + + tplane->GetBranch("mapSection")->SetAddress(&mapSection); + tplane->GetBranch("mapPlane")->SetAddress(&mapPlane); + tplane->GetBranch("mapPlaneType")->SetAddress(&mapPlaneType); + tplane->GetBranch("mapEC")->SetAddress(&mapEC); + tplane->GetBranch("mapItype")->SetAddress(&mapItype); + + const int nmax = 34; + //m_map = new FTKPlaneSection**[ftk::NHITTYPES]; + for ( int i = 0 ; i < ftk::NHITTYPES ; i++ ){ + //m_map[i] = new FTKPlaneSection*[2]; + for ( int j = 0 ; j < 2 ; j++ ) { + //FTKPlaneSection *m_map[ftk::NHITTYPES][2]; + m_map[i][j] = new FTKPlaneSection[nmax]; + } + } -FTKPlaneMap::FTKPlaneMap(TDirectory* file) { - //! Read pmap class from root file - //! return NULL if reading failed. - //! check validity also using m_isok - - //cout<<"Instantiate PlaneMap from root file."<cd(s_dirname) ) { - cerr << "Error in FTKPlaneMap::FTKPlaneMap. No PlaneMap found in root-file. "<< endl; - return; - } - - m_path = gDirectory->GetTitle(); - //cout<<"PathName: "<Get("Planes"); - TTree* tree = (TTree*)gDirectory->Get("PlaneConstants"); - TTree* tConst = (TTree*)gDirectory->Get("Constants"); - if ( !tplane || !tree || !tConst ) { - cerr << "Error in FTKPlaneMap::FTKPlaneMap. Could not find trees. "<< endl; - cerr << " tree('Planes') "<GetBranch("nplanes")->SetAddress(&m_nplanes); - tConst->GetBranch("rlayers")->SetAddress(&m_rlayers); - tConst->GetBranch("totaldim")->SetAddress(&m_totaldim); - tConst->GetBranch("enablePlanePair")->SetAddress(&m_enablePlanePair); - tConst->GetBranch("Checksum")->SetAddress(&chksum); - // read constants - tConst->GetEntry(0); - // cout<<"nplanes "<GetEntries() != m_nplanes ) cerr<<"Error in FTKPlaneMap::FTKPlaneMap. Inconsistent nplanes."<GetBranch("isZ")->SetAddress(&isZ); - tree->GetBranch("planePair")->SetAddress(&planePair); - tree->GetBranch("planeType")->SetAddress(&planeType); - tree->GetBranch("idim_0")->SetAddress(&idim[0]); - tree->GetBranch("idim_1")->SetAddress(&idim[1]); - tree->GetBranch("nsections")->SetAddress(&nsections); - - m_planeType = new int[m_nplanes]; // SCT / PIXEL / SCTtrk - m_isZ = new int[m_totaldim]; // legacy (unused) - m_planePair = new int[m_nplanes]; - m_idim[0]= new int[m_nplanes]; - m_idim[1]= new int[m_nplanes]; - m_nsections = new int[ftk::MAXPLANES]; // number of sections in the used planes - for ( int i = 0 ; i < ftk::MAXPLANES ; i++ ) m_nsections[i]=0; - - for ( int j = 0 ; jGetEntry(j); - m_planeType[j] = planeType; - m_isZ[j] = isZ; - m_planePair[j] = planePair; - m_idim[0][j] = idim[0]; - m_idim[1][j] = idim[1]; - m_nsections[j] = nsections; - } - - int iplane,isection; - int isEndcap,layer,pdisk,nphi,neta,nfi,ncott,ncurv,nste,ndimension; - int mapSection,mapPlane,mapPlaneType,mapEC,mapItype; - tplane->GetBranch("iplane")->SetAddress(&iplane); - tplane->GetBranch("isection")->SetAddress(&isection); - - tplane->GetBranch("isEndcap")->SetAddress(&isEndcap); - tplane->GetBranch("layer")->SetAddress(&layer); - tplane->GetBranch("pdisk")->SetAddress(&pdisk); - tplane->GetBranch("nphi")->SetAddress(&nphi); - tplane->GetBranch("neta")->SetAddress(&neta); - tplane->GetBranch("nfi")->SetAddress(&nfi); - tplane->GetBranch("ncott")->SetAddress(&ncott); - tplane->GetBranch("ncurv")->SetAddress(&ncurv); - tplane->GetBranch("nste")->SetAddress(&nste); - tplane->GetBranch("ndimension")->SetAddress(&ndimension); - - tplane->GetBranch("mapSection")->SetAddress(&mapSection); - tplane->GetBranch("mapPlane")->SetAddress(&mapPlane); - tplane->GetBranch("mapPlaneType")->SetAddress(&mapPlaneType); - tplane->GetBranch("mapEC")->SetAddress(&mapEC); - tplane->GetBranch("mapItype")->SetAddress(&mapItype); - - const int nmax = 34; - //m_map = new FTKPlaneSection**[ftk::NHITTYPES]; - for ( int i = 0 ; i < ftk::NHITTYPES ; i++ ){ - //m_map[i] = new FTKPlaneSection*[2]; - for ( int j = 0 ; j < 2 ; j++ ) { - //FTKPlaneSection *m_map[ftk::NHITTYPES][2]; - m_map[i][j] = new FTKPlaneSection[nmax]; - } - } - - - - // map, planes - int nev=0; - m_planes = new FTKModuleInfo*[m_nplanes]; - for (int j = 0; j < m_nplanes; j++) { - tplane->GetEntry(nev++); - //cout <<"j="<GetEntry(nev++); - if ( k!= isection || j!= iplane ) { - cerr << "Error reading PlaneMap."<cd(); // go back - - if ( chksum != CalcChecksum() ) { - cerr<<"FTKPMap::FTKPMap. Error. Checksum after reading is not consistent with Checksum stored in file."<GetEntry(nev++); + //cout <<"j="<GetEntry(nev++); + if ( k!= isection || j!= iplane ) { + cerr << "Error reading PlaneMap."<cd(); // go back + + if ( chksum != CalcChecksum() ) { + cerr<<"FTKPMap::FTKPMap. Error. Checksum after reading is not consistent with Checksum stored in file."< vec; - - // fill vec with member variables - vec.push_back((double)m_nplanes); - vec.push_back((double)m_rlayers); - vec.push_back((double)m_totaldim); - vec.push_back((double)m_enablePlanePair); - - // plane, map, m_planes - // m_plane, m_map - for (int j = 0; j < m_nplanes; j++) { - for (int k = 0; k < m_nsections[j]; k++) { - vec.push_back((double)j); - vec.push_back((double)k); - vec.push_back((double)m_planes[j][k].getIsEndcap()); - vec.push_back((double)m_planes[j][k].getLayer()); - vec.push_back((double)m_planes[j][k].getPDisk()); - vec.push_back((double)m_planes[j][k].getNumPhi()); - vec.push_back((double)m_planes[j][k].getNumEta()); - vec.push_back((double)m_planes[j][k].getNumFi()); - vec.push_back((double)m_planes[j][k].getNumCott()); - vec.push_back((double)m_planes[j][k].getNumCurv()); - vec.push_back((double)m_planes[j][k].getNSte()); - vec.push_back((double)m_planes[j][k].getNDimension()); - // m_map - vec.push_back((double)m_map[m_planes[j][k].getNSte() == -1][m_planes[j][k].getIsEndcap()][m_planes[j][k].getLayer()].getPlane() ); - vec.push_back((double)m_map[m_planes[j][k].getNSte() == -1][m_planes[j][k].getIsEndcap()][m_planes[j][k].getLayer()].getSection()); - vec.push_back((double)m_planes[j][k].getNSte() == -1); - vec.push_back((double)m_planes[j][k].getIsEndcap()); - vec.push_back((double)m_planes[j][k].getLayer()); - } - } - - for ( int i = 0 ; i vec; + + // fill vec with member variables + vec.push_back((double)m_nplanes); + vec.push_back((double)m_rlayers); + vec.push_back((double)m_totaldim); + vec.push_back((double)m_enablePlanePair); + + // plane, map, m_planes + // m_plane, m_map + for (int j = 0; j < m_nplanes; j++) { + for (int k = 0; k < m_nsections[j]; k++) { + vec.push_back((double)j); + vec.push_back((double)k); + vec.push_back((double)m_planes[j][k].getIsEndcap()); + vec.push_back((double)m_planes[j][k].getLayer()); + vec.push_back((double)m_planes[j][k].getPDisk()); + vec.push_back((double)m_planes[j][k].getNumPhi()); + vec.push_back((double)m_planes[j][k].getNumEta()); + vec.push_back((double)m_planes[j][k].getNumFi()); + vec.push_back((double)m_planes[j][k].getNumCott()); + vec.push_back((double)m_planes[j][k].getNumCurv()); + vec.push_back((double)m_planes[j][k].getNSte()); + vec.push_back((double)m_planes[j][k].getNDimension()); + // m_map + vec.push_back((double)m_map[m_planes[j][k].getNSte() == -1][m_planes[j][k].getIsEndcap()][m_planes[j][k].getLayer()].getPlane() ); + vec.push_back((double)m_map[m_planes[j][k].getNSte() == -1][m_planes[j][k].getIsEndcap()][m_planes[j][k].getLayer()].getSection()); + vec.push_back((double)m_planes[j][k].getNSte() == -1); + vec.push_back((double)m_planes[j][k].getIsEndcap()); + vec.push_back((double)m_planes[j][k].getLayer()); + } + } + + for ( int i = 0 ; icd(s_dirname) ) { - cerr << "Error in FTKPlaneMap::GetNPlanes. No PlaneMap found in root-file. "<< endl; - return -1; - } - - TTree* tConst = (TTree*)gDirectory->Get("Constants"); - if ( !tConst ) { - cerr << "Error in FTKPlaneMap::GetNPlanes. Could not find trees. "<< endl; - cerr << " tree('Constants') "<GetBranch(ConstName); - br->SetAddress(&ret); - br->GetEntry(0); - thisdir->cd(); - return ret; + // get nplanes from root file + // if error: return -1 + TDirectory* thisdir = gDirectory; + + + if ( !file->cd(s_dirname) ) { + cerr << "Error in FTKPlaneMap::GetNPlanes. No PlaneMap found in root-file. "<< endl; + return -1; + } + + TTree* tConst = (TTree*)gDirectory->Get("Constants"); + if ( !tConst ) { + cerr << "Error in FTKPlaneMap::GetNPlanes. Could not find trees. "<< endl; + cerr << " tree('Constants') "<GetBranch(ConstName); + br->SetAddress(&ret); + br->GetEntry(0); + thisdir->cd(); + return ret; } int FTKPlaneMap::GetNPlanes(TDirectory* file){ - // get nplanes from root file - // if error: return -1 - return GetConst(file,"nplanes"); + // get nplanes from root file + // if error: return -1 + return GetConst(file,"nplanes"); } int FTKPlaneMap::GetTotalDim(TDirectory* file){ - // get totaldim from root file - // if error: return -1 - return GetConst(file,"totaldim"); + // get totaldim from root file + // if error: return -1 + return GetConst(file,"totaldim"); } int FTKPlaneMap::GetChecksum(TDirectory* file){ - // get totaldim from root file - // if error: return -1 - return GetConst(file,"Checksum"); + // get totaldim from root file + // if error: return -1 + return GetConst(file,"Checksum"); } FTKPlaneMap* FTKPlaneMap::GetPMapFromRootFile(TDirectory* file){ - //! Read pmap class from root file - //! return NULL if reading failed. - //! check validity also using m_isok - - TDirectory* thisdir = gDirectory; - FTKPlaneMap* ret = new FTKPlaneMap(file); - - if ( !ret->getIsOK() ) { - cerr <<"FTKPlaneMap::GetPMapFromRootFile. Error. PlaneMap seems not to be ok (isok==false). Returning nullptr."<cd(); // go back - return ret; + //! Read pmap class from root file + //! return NULL if reading failed. + //! check validity also using m_isok + + TDirectory* thisdir = gDirectory; + FTKPlaneMap* ret = new FTKPlaneMap(file); + + if ( !ret->getIsOK() ) { + cerr <<"FTKPlaneMap::GetPMapFromRootFile. Error. PlaneMap seems not to be ok (isok==false). Returning nullptr."<cd(); // go back + return ret; } void FTKPlaneMap::WriteMapToRootFile(TDirectory* dir) { - //! Write PMap to root file - //! PMap is stored in TDirectory* pmap - //! name: "PMap" - //! title: - //! PMap is again readable using ReadMapFromRootFile() - - //cout<<"Writing PlaneMap to root file."<GetKey(s_dirname) ) { - if ( FTKPlaneMap::GetChecksum(dir) == CalcChecksum() ) { - cout<<"Info. Identical PlaneMap already written to disk. Skipping writing."<GetTitle() << endl; - cerr << " PlaneMap title: "<GetKey(s_dirname)->GetTitle()<mkdir(s_dirname,title); - pmapdir->cd(); - - /* - // write PMap content - cout<<"ftk::NHITTYPES="<WriteObject(&m_planes[j][k],objname); - - printf("\t\t\t(physical layer %d / %d, map gives back plane %d section %d): \n", - m_planes[j][k].getPDisk(), - m_planes[j][k].getLayer(), - m_map[m_planes[j][k].getNSte() == -1][m_planes[j][k].getIsEndcap()][m_planes[j][k].getLayer()].getPlane(), - m_map[m_planes[j][k].getNSte() == -1][m_planes[j][k].getIsEndcap()][m_planes[j][k].getLayer()].getSection()); - - int a = m_planes[j][k].getNSte() == -1; //ftk::NHITTypes - int b = m_planes[j][k].getIsEndcap(); // EC or not - int c = m_planes[j][k].getLayer(); - TString mapname = Form("map_%d_%d_%d",a,b,c); - cout<<" * Writing m_map: "<WriteObject(&m_map[a][b][c],mapname); - } - } - */ - - //cout<<"Writing planes into tree."<WriteObject(&m_planes[j][k],objname); - tplane.Fill(); - } - } - - - //cout<<"Writing plane constants."<Write(); - - // goback - thisdir->cd(); -} + //! Write PMap to root file + //! PMap is stored in TDirectory* pmap + //! name: "PMap" + //! title: + //! PMap is again readable using ReadMapFromRootFile() + + //cout<<"Writing PlaneMap to root file."<GetKey(s_dirname) ) { + if ( FTKPlaneMap::GetChecksum(dir) == CalcChecksum() ) { + cout<<"Info. Identical PlaneMap already written to disk. Skipping writing."<GetTitle() << endl; + cerr << " PlaneMap title: "<GetKey(s_dirname)->GetTitle()<mkdir(s_dirname,title); + pmapdir->cd(); -FTKPlaneMap::~FTKPlaneMap() -{ - delete [] m_planeType; - delete [] m_isZ; - delete [] m_planePair; - delete [] m_idim[0]; - delete [] m_idim[1]; - delete [] m_nsections; - delete [] m_map[PIXEL][BARREL]; - delete [] m_map[PIXEL][ENDCAP]; - delete [] m_map[SCTtrk][BARREL]; - delete [] m_map[SCT][BARREL]; - delete [] m_map[SCT][ENDCAP]; - - for (int ip=0;ip!=m_nplanes;++ip) delete [] m_planes[ip]; - delete [] m_planes; + /* + // write PMap content + cout<<"ftk::NHITTYPES="<WriteObject(&m_planes[j][k],objname); + + printf("\t\t\t(physical layer %d / %d, map gives back plane %d section %d): \n", + m_planes[j][k].getPDisk(), + m_planes[j][k].getLayer(), + m_map[m_planes[j][k].getNSte() == -1][m_planes[j][k].getIsEndcap()][m_planes[j][k].getLayer()].getPlane(), + m_map[m_planes[j][k].getNSte() == -1][m_planes[j][k].getIsEndcap()][m_planes[j][k].getLayer()].getSection()); + + int a = m_planes[j][k].getNSte() == -1; //ftk::NHITTypes + int b = m_planes[j][k].getIsEndcap(); // EC or not + int c = m_planes[j][k].getLayer(); + TString mapname = Form("map_%d_%d_%d",a,b,c); + cout<<" * Writing m_map: "<WriteObject(&m_map[a][b][c],mapname); + } + } + */ + + //cout<<"Writing planes into tree."<WriteObject(&m_planes[j][k],objname); + tplane.Fill(); + } + } + + + //cout<<"Writing plane constants."<Write(); + + // goback + thisdir->cd(); } -int FTKPlaneMap::getSCTtrkPlane() const { - for(int pl=m_nplanes-1; pl>=0; pl--) { - if(isSCTtrk(pl)) return pl; - } - return -1; +FTKPlaneMap::~FTKPlaneMap() +{ + delete [] m_planeType; + delete [] m_isZ; + delete [] m_planePair; + delete [] m_idim[0]; + delete [] m_idim[1]; + delete [] m_nsections; + delete [] m_map[PIXEL][BARREL]; + delete [] m_map[PIXEL][ENDCAP]; + delete [] m_map[SCT][BARREL]; + delete [] m_map[SCT][ENDCAP]; + + for (int ip=0;ip!=m_nplanes;++ip) delete [] m_planes[ip]; + delete [] m_planes; } diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKRawHit.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKRawHit.cxx index 8a6253405b7..776b2a3726f 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKRawHit.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKRawHit.cxx @@ -6,7 +6,6 @@ #include "TrigFTKSim/FTKHit.h" #include "TrigFTKSim/FTKSplitEncoder.h" #include "TrigFTKSim/FTKSetup.h" -// needed to read SCTtrk tracks (Constantinos case) #include "TrigFTKSim/FTKTrackInput.h" #include "TrigFTKSim/FTKRoad.h" #include "TrigFTKSim/FTKRoadInput.h" @@ -17,309 +16,282 @@ using namespace std; FTKRawHit::FTKRawHit() - : TObject(), m_truth(nullptr), m_channels() + : TObject(), m_truth(nullptr), m_channels() { - // nothing to do - reset(); -} - -/* Special constructor for SCTtrk hits*/ -FTKRawHit::FTKRawHit(const FTKTrack* trk, int) : - TObject(), m_truth(nullptr), m_channels() -{ - reset(); - m_x = trk->getPhi(); - m_y = trk->getCotTheta(); - m_z = trk->getHalfInvPt(); - m_hitType = ftk::SCTtrk; - m_moduleType = ftk::MODULETYPE_INVALID; // set to invalid until it is correctly set - m_layer_disk = 0; // for the scttrk case - // store information about 8L SCT road and track into unused variables: - setBankID(trk->getBankID()); - setRoadID(trk->getRoadID()); - setTrackID(trk->getTrackID()); - // dummy truth, will be replaced by 8L truth - m_truth = new MultiTruth(); + // nothing to do + reset(); } FTKRawHit::FTKRawHit(const FTKRawHit &cpy) : - TObject(cpy), - m_x(cpy.m_x), m_y(cpy.m_y), m_z(cpy.m_z), - m_hitType(cpy.m_hitType), - m_moduleType(cpy.m_moduleType), - m_IdentifierHash(cpy.m_IdentifierHash), - m_barrel_ec(cpy.m_barrel_ec), - m_layer_disk(cpy.m_layer_disk), - m_phi_module(cpy.m_phi_module), - m_eta_module(cpy.m_eta_module), - m_pi_side(cpy.m_pi_side), - m_ei_strip(cpy.m_ei_strip), - m_n_strips(cpy.m_n_strips), - m_etaWidth(cpy.m_etaWidth), - m_phiWidth(cpy.m_phiWidth), - m_dPhi(cpy.m_dPhi), - m_dEta(cpy.m_dEta), - m_hw_word(cpy.m_hw_word), - m_includesGangedHits(cpy.m_includesGangedHits), - m_eventindex(cpy.m_eventindex), - m_barcode(cpy.m_barcode), - m_barcode_pt(cpy.m_barcode_pt), - m_parentage_mask(cpy.m_parentage_mask), - m_channels(cpy.m_channels) + TObject(cpy), + m_hitType(cpy.m_hitType), + m_moduleType(cpy.m_moduleType), + m_IdentifierHash(cpy.m_IdentifierHash), + m_barrel_ec(cpy.m_barrel_ec), + m_layer_disk(cpy.m_layer_disk), + m_phi_module(cpy.m_phi_module), + m_eta_module(cpy.m_eta_module), + m_pi_side(cpy.m_pi_side), + m_ei_strip(cpy.m_ei_strip), + m_n_strips(cpy.m_n_strips), + m_etaWidth(cpy.m_etaWidth), + m_phiWidth(cpy.m_phiWidth), + m_dPhi(cpy.m_dPhi), + m_dEta(cpy.m_dEta), + m_hw_word(cpy.m_hw_word), + m_includesGangedHits(cpy.m_includesGangedHits), + m_eventindex(cpy.m_eventindex), + m_barcode(cpy.m_barcode), + m_barcode_pt(cpy.m_barcode_pt), + m_parentage_mask(cpy.m_parentage_mask), + m_channels(cpy.m_channels) { - if (cpy.m_truth) - m_truth = new MultiTruth(*(cpy.m_truth)); - else - m_truth = nullptr; + if (cpy.m_truth) + m_truth = new MultiTruth(*(cpy.m_truth)); + else + m_truth = nullptr; } FTKRawHit::~FTKRawHit() { - if (m_truth) delete m_truth; + if (m_truth) delete m_truth; } // shallow copy - MultiTruth did not used to be copied, but is now! FTKRawHit& FTKRawHit::operator=(const FTKRawHit &cpy) { #ifdef PROTECT_SA // speedup - if (this != &cpy) + if (this != &cpy) #endif { - m_x = cpy.m_x; m_y = cpy.m_y; m_z = cpy.m_z; - m_hitType = cpy.m_hitType; - m_moduleType = cpy.m_moduleType; - m_IdentifierHash = cpy.m_IdentifierHash; - m_barrel_ec = cpy.m_barrel_ec; - m_layer_disk = cpy.m_layer_disk; - m_phi_module = cpy.m_phi_module; - m_eta_module = cpy.m_eta_module; - m_pi_side = cpy.m_pi_side; - m_ei_strip = cpy.m_ei_strip; - m_n_strips = cpy.m_n_strips; - m_etaWidth = cpy.m_etaWidth; - m_phiWidth = cpy.m_phiWidth; - m_dPhi = cpy.m_dPhi; - m_dEta = cpy.m_dEta; - m_includesGangedHits = cpy.m_includesGangedHits; - m_eventindex = cpy.m_eventindex; - m_barcode = cpy.m_barcode; - m_barcode_pt = cpy.m_barcode_pt; - m_parentage_mask = cpy.m_parentage_mask; - m_hw_word = cpy.m_hw_word; - m_truth = nullptr; - m_channels.assign(cpy.m_channels.begin(),cpy.m_channels.end()); - if (cpy.m_truth) - m_truth = new MultiTruth(*(cpy.m_truth)); - /// + m_hitType = cpy.m_hitType; + m_moduleType = cpy.m_moduleType; + m_IdentifierHash = cpy.m_IdentifierHash; + m_barrel_ec = cpy.m_barrel_ec; + m_layer_disk = cpy.m_layer_disk; + m_phi_module = cpy.m_phi_module; + m_eta_module = cpy.m_eta_module; + m_pi_side = cpy.m_pi_side; + m_ei_strip = cpy.m_ei_strip; + m_n_strips = cpy.m_n_strips; + m_etaWidth = cpy.m_etaWidth; + m_phiWidth = cpy.m_phiWidth; + m_dPhi = cpy.m_dPhi; + m_dEta = cpy.m_dEta; + m_includesGangedHits = cpy.m_includesGangedHits; + m_eventindex = cpy.m_eventindex; + m_barcode = cpy.m_barcode; + m_barcode_pt = cpy.m_barcode_pt; + m_parentage_mask = cpy.m_parentage_mask; + m_hw_word = cpy.m_hw_word; + m_truth = nullptr; + m_channels.assign(cpy.m_channels.begin(),cpy.m_channels.end()); + if (cpy.m_truth) + m_truth = new MultiTruth(*(cpy.m_truth)); + /// } - return *this; + return *this; } void FTKRawHit::reset() { - m_x = 0.; - m_y = 0.; - m_z = 0.; - m_hitType = 0; - m_moduleType = ftk::MODULETYPE_INVALID; - m_IdentifierHash = 0; - m_barrel_ec = 0; - m_layer_disk = 0; - m_phi_module = 0; - m_eta_module = 0; - m_pi_side = 0; - m_ei_strip = 0; - m_n_strips = 0; - m_etaWidth = 0; - m_phiWidth = 0; - m_dPhi = 0.; - m_dEta = 0.; - m_includesGangedHits = false; - m_barcode = -1; - m_eventindex = -1; - m_barcode_pt = 0.; - m_parentage_mask = 0; - m_hw_word = 0; - if( m_truth ) { - delete m_truth; - m_truth = 0; - } - m_channels.clear(); + m_hitType = 0; + m_moduleType = ftk::MODULETYPE_INVALID; + m_IdentifierHash = 0; + m_barrel_ec = 0; + m_layer_disk = 0; + m_phi_module = 0; + m_eta_module = 0; + m_pi_side = 0; + m_ei_strip = 0; + m_n_strips = 0; + m_etaWidth = 0; + m_phiWidth = 0; + m_dPhi = 0.; + m_dEta = 0.; + m_includesGangedHits = false; + m_barcode = -1; + m_eventindex = -1; + m_barcode_pt = 0.; + m_parentage_mask = 0; + m_hw_word = 0; + if( m_truth ) { + delete m_truth; + m_truth = 0; + } + m_channels.clear(); } ostream &operator<<(std::ostream& out,const FTKRawHit& hit) { - out << "S" << "\t" << hit.m_x << "\t" << hit.m_y << "\t" << hit.m_z << "\t"; - out << hit.m_hitType << "\t" << hit.m_barrel_ec << "\t" << hit.m_layer_disk << "\t"; - out << hit.m_phi_module << "\t" << hit.m_eta_module << "\t"; - out << hit.m_pi_side << "\t" << hit.m_ei_strip << "\t" << hit.m_n_strips; - return out; + out << "S" << "\t" << hit.m_hitType << "\t" << hit.m_barrel_ec << "\t"; + out << hit.m_layer_disk << "\t"; + out << hit.m_phi_module << "\t" << hit.m_eta_module << "\t"; + out << hit.m_pi_side << "\t" << hit.m_ei_strip << "\t" << hit.m_n_strips; + return out; } istream& operator>>(istream &input, FTKRawHit &hit) { - int dummy; - - input >> hit.m_x >> hit.m_y >> hit.m_z; - input >> hit.m_hitType >> hit.m_barrel_ec; - input >> hit.m_layer_disk >> hit.m_phi_module >> hit.m_eta_module; - input >> hit.m_pi_side >> hit.m_ei_strip; - input >> hit.m_n_strips; - if (!input) { - // is a very old format w/o the number of consecutive strips - hit.m_n_strips = 1; - } else { - // June 2009 format: remaining fields are the UniqueBarcode and the highest pt contributing to the channel, in that order. - // August 2009 format: remaing fields are event_index, barcode, highest pt, parentage mask. - streampos position = input.tellg(); - input >> hit.m_barcode; - if( input ) { - // is not an old format w/o geant truth info - input >> hit.m_barcode_pt; - // Check for August 2009 - input >> dummy; - if( input ) { - // August 2009 - need to go back and re-read - input.seekg(position); - input >> hit.m_eventindex; - input >> hit.m_barcode; - input >> hit.m_barcode_pt; - input >> hit.m_parentage_mask; - } - else { - // June 2009 -- set barcode and event index to new format. - hit.m_eventindex = hit.m_barcode/100000; - hit.m_barcode %= 100000; - hit.m_parentage_mask = 0; - } + int dummy; + + input >> hit.m_hitType >> hit.m_barrel_ec; + input >> hit.m_layer_disk >> hit.m_phi_module >> hit.m_eta_module; + input >> hit.m_pi_side >> hit.m_ei_strip; + input >> hit.m_n_strips; + if (!input) { + // is a very old format w/o the number of consecutive strips + hit.m_n_strips = 1; + } else { + // June 2009 format: remaining fields are the UniqueBarcode and the highest pt contributing to the channel, in that order. + // August 2009 format: remaing fields are event_index, barcode, highest pt, parentage mask. + streampos position = input.tellg(); + input >> hit.m_barcode; + if( input ) { + // is not an old format w/o geant truth info + input >> hit.m_barcode_pt; + // Check for August 2009 + input >> dummy; + if( input ) { + // August 2009 - need to go back and re-read + input.seekg(position); + input >> hit.m_eventindex; + input >> hit.m_barcode; + input >> hit.m_barcode_pt; + input >> hit.m_parentage_mask; + } + else { + // June 2009 -- set barcode and event index to new format. + hit.m_eventindex = hit.m_barcode/100000; + hit.m_barcode %= 100000; + hit.m_parentage_mask = 0; + } + } } - } input >> hit.m_IdentifierHash; - // change the layer id according the FTK use - hit.normalizeLayerID(); + // change the layer id according the FTK use + hit.normalizeLayerID(); - return input; + return input; } istream& clusterP( istream &input , FTKRawHit &hit ) { - // added March, 2012 - - input >> hit.m_x >> hit.m_y >> hit.m_z; - hit.setHitType(ftk::PIXEL); - hit.setModuleType(ftk::MODULETYPE_PIXEL); - input >> hit.m_barrel_ec; - input >> hit.m_layer_disk; - input >> hit.m_phi_module >> hit.m_eta_module; - input >> hit.m_pi_side >> hit.m_ei_strip; - - input >> hit.m_dPhi >> hit.m_dEta; - // The wrapper is filled with m_pi_side + dPhi, for example, so correct back... - hit.m_dPhi -= hit.m_pi_side; - hit.m_dEta -= hit.m_ei_strip; - - input >> hit.m_phiWidth >> hit.m_etaWidth; - - input >> hit.m_n_strips; - input >> hit.m_eventindex; - input >> hit.m_barcode; - input >> hit.m_barcode_pt; - input >> hit.m_parentage_mask; - - // Since clustering is already done, there should only be 1 barcode per "hit". - // Instead of doing anything too complicated for m_truth, we can just store the one barcode. - //hit.m_truth = new MultiTruth( std::make_pair(hit.m_barcode,hit.m_eventindex) ); - hit.m_truth = new MultiTruth( std::make_pair(hit.m_eventindex,hit.m_barcode) ); - - // change the layer id according the FTK use - hit.normalizeLayerID(); - - return input; + // added March, 2012 + + hit.setHitType(ftk::PIXEL); + hit.setModuleType(ftk::MODULETYPE_PIXEL); + input >> hit.m_barrel_ec; + input >> hit.m_layer_disk; + input >> hit.m_phi_module >> hit.m_eta_module; + input >> hit.m_pi_side >> hit.m_ei_strip; + + input >> hit.m_dPhi >> hit.m_dEta; + // The wrapper is filled with m_pi_side + dPhi, for example, so correct back... + hit.m_dPhi -= hit.m_pi_side; + hit.m_dEta -= hit.m_ei_strip; + + input >> hit.m_phiWidth >> hit.m_etaWidth; + + input >> hit.m_n_strips; + input >> hit.m_eventindex; + input >> hit.m_barcode; + input >> hit.m_barcode_pt; + input >> hit.m_parentage_mask; + + // Since clustering is already done, there should only be 1 barcode per "hit". + // Instead of doing anything too complicated for m_truth, we can just store the one barcode. + //hit.m_truth = new MultiTruth( std::make_pair(hit.m_barcode,hit.m_eventindex) ); + hit.m_truth = new MultiTruth( std::make_pair(hit.m_eventindex,hit.m_barcode) ); + + // change the layer id according the FTK use + hit.normalizeLayerID(); + + return input; } istream& clusterC( istream &input , FTKRawHit &hit ) { - // added March, 2012 - - input >> hit.m_x >> hit.m_y >> hit.m_z; - input >> hit.m_hitType; - input >> hit.m_barrel_ec; - input >> hit.m_layer_disk; - input >> hit.m_phi_module >> hit.m_eta_module; - input >> hit.m_pi_side >> hit.m_ei_strip; - - input >> hit.m_dPhi; - // The wrapper is filled with m_pi_side + dPhi, so correct back... - hit.m_dPhi -= hit.m_ei_strip; - - input >> hit.m_n_strips; - if( hit.m_n_strips < 1 ) { FTKSetup::PrintMessageFmt(ftk::sevr,"Found a C line (SCT cluster) in wrapper with n_strips < 1 (%d)\n",hit.m_n_strips); } - input >> hit.m_eventindex; - input >> hit.m_barcode; - input >> hit.m_barcode_pt; - input >> hit.m_parentage_mask; - - // Since clustering is already done, there should only be 1 barcode per "hit". - // Instead of doing anything too complicated for m_truth, we can just store the one barcode. - //hit.m_truth = new MultiTruth( std::make_pair(hit.m_barcode,hit.m_eventindex) ); - hit.m_truth = new MultiTruth( std::make_pair(hit.m_eventindex,hit.m_barcode) ); - - // change the layer id according the FTK use - hit.normalizeLayerID(); - - return input; + // added March, 2012 + + input >> hit.m_hitType; + input >> hit.m_barrel_ec; + input >> hit.m_layer_disk; + input >> hit.m_phi_module >> hit.m_eta_module; + input >> hit.m_pi_side >> hit.m_ei_strip; + + input >> hit.m_dPhi; + // The wrapper is filled with m_pi_side + dPhi, so correct back... + hit.m_dPhi -= hit.m_ei_strip; + + input >> hit.m_n_strips; + if( hit.m_n_strips < 1 ) { FTKSetup::PrintMessageFmt(ftk::sevr,"Found a C line (SCT cluster) in wrapper with n_strips < 1 (%d)\n",hit.m_n_strips); } + input >> hit.m_eventindex; + input >> hit.m_barcode; + input >> hit.m_barcode_pt; + input >> hit.m_parentage_mask; + + // Since clustering is already done, there should only be 1 barcode per "hit". + // Instead of doing anything too complicated for m_truth, we can just store the one barcode. + //hit.m_truth = new MultiTruth( std::make_pair(hit.m_barcode,hit.m_eventindex) ); + hit.m_truth = new MultiTruth( std::make_pair(hit.m_eventindex,hit.m_barcode) ); + + // change the layer id according the FTK use + hit.normalizeLayerID(); + + return input; } /** This function change the layer id, how it comes from the atlas numbering method, from the id used in FTK pmap. This method update the m_layer_disk field for the SCT, doesn't affect the pixels - */ +*/ void FTKRawHit::normalizeLayerID() { - if (m_hitType != ftk::SCT ) { - return; - } - else if( FTKSetup::getFTKSetup().getITkMode() ) { - m_layer_disk = (2*m_layer_disk) + m_pi_side; - } - else if (m_barrel_ec == 0){ // is barrel - if (m_layer_disk==0 && m_pi_side == 1) m_layer_disk = 0; - else if(m_layer_disk==0 && m_pi_side == 0) m_layer_disk = 1; - else if(m_layer_disk==1 && m_pi_side == 0) m_layer_disk = 2; - else if(m_layer_disk==1 && m_pi_side == 1) m_layer_disk = 3; - else if(m_layer_disk==2 && m_pi_side == 1) m_layer_disk = 4; - else if(m_layer_disk==2 && m_pi_side == 0) m_layer_disk = 5; - else if(m_layer_disk==3 && m_pi_side == 0) m_layer_disk = 6; - else if(m_layer_disk==3 && m_pi_side == 1) m_layer_disk = 7; - - } - else { - /* this is complicated. */ - /* First, figure out if we're on the inside or outside in z, and inner or outer ring */ - int outside = 0; - int inner_ring = 0; - if (m_eta_module > 0) inner_ring = 1; - if ((m_eta_module == 0 || m_eta_module == 2) && m_pi_side == 1) outside = 1; - if (m_eta_module == 1 && m_pi_side == 0) outside = 1; - - /* disk 8 flipped: special case */ - if (m_layer_disk == 8 && m_pi_side == 1) outside = 0; - if (m_layer_disk == 8 && m_pi_side == 0) outside = 1; - - /* split the disks up by inner/outer, and by side */ - m_layer_disk = 4*m_layer_disk + 2*inner_ring + outside; - - /* aaaaand fix eta index */ - if (inner_ring) m_eta_module = m_eta_module - 1; - - if (FTKSetup::getFTKSetup().getVerbosity() > 3) { - printf("Converted disk %d eta %d side %d to split disk %d eta %d\n", - m_layer_disk, m_eta_module, m_pi_side, - m_layer_disk, m_eta_module); + if (m_hitType != ftk::SCT ) { + return; + } + else if( FTKSetup::getFTKSetup().getITkMode() ) { + m_layer_disk = (2*m_layer_disk) + m_pi_side; + } + else if (m_barrel_ec == 0){ // is barrel + if (m_layer_disk==0 && m_pi_side == 1) m_layer_disk = 0; + else if(m_layer_disk==0 && m_pi_side == 0) m_layer_disk = 1; + else if(m_layer_disk==1 && m_pi_side == 0) m_layer_disk = 2; + else if(m_layer_disk==1 && m_pi_side == 1) m_layer_disk = 3; + else if(m_layer_disk==2 && m_pi_side == 1) m_layer_disk = 4; + else if(m_layer_disk==2 && m_pi_side == 0) m_layer_disk = 5; + else if(m_layer_disk==3 && m_pi_side == 0) m_layer_disk = 6; + else if(m_layer_disk==3 && m_pi_side == 1) m_layer_disk = 7; + + } + else { + /* this is complicated. */ + /* First, figure out if we're on the inside or outside in z, and inner or outer ring */ + int outside = 0; + int inner_ring = 0; + if (m_eta_module > 0) inner_ring = 1; + if ((m_eta_module == 0 || m_eta_module == 2) && m_pi_side == 1) outside = 1; + if (m_eta_module == 1 && m_pi_side == 0) outside = 1; + + /* disk 8 flipped: special case */ + if (m_layer_disk == 8 && m_pi_side == 1) outside = 0; + if (m_layer_disk == 8 && m_pi_side == 0) outside = 1; + + /* split the disks up by inner/outer, and by side */ + m_layer_disk = 4*m_layer_disk + 2*inner_ring + outside; + + /* aaaaand fix eta index */ + if (inner_ring) m_eta_module = m_eta_module - 1; + + if (FTKSetup::getFTKSetup().getVerbosity() > 3) { + printf("Converted disk %d eta %d side %d to split disk %d eta %d\n", + m_layer_disk, m_eta_module, m_pi_side, + m_layer_disk, m_eta_module); + } } - } } @@ -327,133 +299,103 @@ void FTKRawHit::normalizeLayerID() the information needed to be linked in the ATLAS geometry, to the simple hit codified in the mode internally used by the AM */ FTKHit FTKRawHit::getFTKHit(const FTKPlaneMap *pmap) const { - // retrieve layer info from the pmap - FTKPlaneSection &pinfo = pmap->getMap(m_hitType,!(m_barrel_ec==0),m_layer_disk); - int plane = pinfo.getPlane(); - int section = pinfo.getSection(); - int sector; - - if( FTKSetup::getFTKSetup().getITkMode() ) { - // Working at least for SCT barrel - // Ranges from dumping detector info -- - // phi_modules in [0,..,72] - // eta_modules in [-56,..,56] - // m_barrel_ec in [-2,0,2] (C-side,B,A-side) - sector = (m_phi_module*100000) + ((m_eta_module+60)*100) + ((m_barrel_ec+2)*10) + section; - } - else if (m_barrel_ec) { - // is in the end-caps - int ieta = m_eta_module; - const int NEGEC (-2); - int code = (ieta+1)*20 + (m_barrel_ec == NEGEC)*10 + section; - sector = m_phi_module*1000+code; - } - else if (FTKSetup::getFTKSetup().getIBLMode()==1 && m_layer_disk==0 && m_hitType==ftk::PIXEL && m_barrel_ec==0 ){ - // this is an IBL module, without 3d sensors, only possible case up to the TDAQ TDR - sector = m_phi_module*1000+m_eta_module+8; // ibl was 6 - } - else if (FTKSetup::getFTKSetup().getIBLMode()==2 && m_layer_disk==0 && m_hitType==ftk::PIXEL && m_barrel_ec==0 ){ - // this is an IBL module with 3d sensors, 20 modules in total instead of 16 - sector = m_phi_module*1000+m_eta_module+10; - } - else { - // is a generic module of the barrel region - sector = m_phi_module*1000+m_eta_module+6; - } - - // retrieve information - int ndim = pmap->getPlane(plane,section).getNDimension(); - FTKHit reshit(ndim); - reshit.setITkMode( FTKSetup::getFTKSetup().getITkMode() ); - reshit.setIdentifierHash(getIdentifierHash()); - reshit.setPlane(plane); - reshit.setSector(sector); - reshit.setHwWord(m_hw_word); - if (m_moduleType == ftk::MODULETYPE_SCT){ - reshit.setScalingCoordToHWCoord(0,SCT_row_scaling); - reshit.setScalingCoordToHWCoord(1,0); - } - else if (m_moduleType == ftk::MODULETYPE_PIXEL) { - reshit.setScalingCoordToHWCoord(0,PIX_row_scaling); - reshit.setScalingCoordToHWCoord(1,PIX_column_scaling); - } - else if (m_moduleType == ftk::MODULETYPE_IBL_PLANAR) { - reshit.setScalingCoordToHWCoord(0,IBL_planar_row_scaling); - reshit.setScalingCoordToHWCoord(1,IBL_planar_column_scaling); - } - else if (m_moduleType == ftk::MODULETYPE_IBL3D) { - reshit.setScalingCoordToHWCoord(0,IBL_3D_row_scaling); - reshit.setScalingCoordToHWCoord(1,IBL_3D_column_scaling); - } - else {// don't think i should be here! - reshit.setScalingCoordToHWCoord(0,0); - reshit.setScalingCoordToHWCoord(1,0); - } - - switch (m_hitType) { - case ftk::PIXEL: - reshit.setEtaWidth(getEtaWidth()); - reshit.setPhiWidth(getPhiWidth()); - reshit.getCoord().setIncludesGanged(getIncludesGanged()); - reshit.setNStrips(getNStrips()); - reshit[0] = m_pi_side+m_dPhi; - reshit[1] = m_ei_strip+m_dEta; - break; - case ftk::SCT: - // reshit[0] = m_ei_strip+(m_n_strips-1.)/2.; - reshit[0] = m_ei_strip+m_dPhi; - reshit.setNStrips(getNStrips()); - reshit.setEtaWidth(getEtaWidth()); - reshit.setPhiWidth(getPhiWidth()); - break; - case ftk::SCTtrk: - // cy to adjust 8L track pars if they exceed thresholds - double mod_x = ( m_x > ftk::PI ? ftk::PI : (m_x < -ftk::PI ? -ftk::PI : m_x) ); - double mod_y = ( m_y > ftk::COTTMAX ? ftk::COTTMAX : (m_y < -ftk::COTTMAX ? -ftk::COTTMAX : m_y) ); - double mod_z = ( m_z > ftk::CURVMAX ? ftk::CURVMAX : (m_z < -ftk::CURVMAX ? -ftk::CURVMAX : m_z) ); - - // FlagAK: changed all int() conversions to floor() - this is needed for FTKSSMap to correctly guess module offset - int phiMod=static_cast(floor(mod_x/(2*ftk::PI)*(pmap->getPlane(plane,section).getNumFi()))); - if(phiMod < 0) phiMod+=pmap->getPlane(plane,section).getNumFi(); - -#ifdef SPLIT_OLDCTHETA - int cottMod=static_cast(floor((ftk::COTTMAX+mod_y)/(2*ftk::COTTMAX)*(pmap->getPlane(plane,section).getNumCott()))); -#else - // for cot(theta), we now use a hardooded table - see FTKSplitEncoder.{h,cxx} - int cottMod=FTKSplitEncoder::get().cthetaIndex(mod_y); -#endif - - int curvMod=static_cast(floor((ftk::CURVMAX+mod_z)/(2*ftk::CURVMAX)*(pmap->getPlane(plane,section).getNumCurv()))); + // retrieve layer info from the pmap + FTKPlaneSection &pinfo = pmap->getMap(m_hitType,!(m_barrel_ec==0),m_layer_disk); + int plane = pinfo.getPlane(); + int section = pinfo.getSection(); + int sector; + + if( FTKSetup::getFTKSetup().getITkMode() ) { + // Working at least for SCT barrel + // Ranges from dumping detector info -- + // phi_modules in [0,..,72] + // eta_modules in [-56,..,56] + // m_barrel_ec in [-2,0,2] (C-side,B,A-side) + sector = (m_phi_module*100000) + ((m_eta_module+60)*100) + ((m_barrel_ec+2)*10) + section; + } + else if (m_barrel_ec) { + // is in the end-caps + int ieta = m_eta_module; + const int NEGEC (-2); + int code = (ieta+1)*20 + (m_barrel_ec == NEGEC)*10 + section; + sector = m_phi_module*1000+code; + } + else if (FTKSetup::getFTKSetup().getIBLMode()==1 && m_layer_disk==0 && m_hitType==ftk::PIXEL && m_barrel_ec==0 ){ + // this is an IBL module, without 3d sensors, only possible case up to the TDAQ TDR + sector = m_phi_module*1000+m_eta_module+8; // ibl was 6 + } + else if (FTKSetup::getFTKSetup().getIBLMode()==2 && m_layer_disk==0 && m_hitType==ftk::PIXEL && m_barrel_ec==0 ){ + // this is an IBL module with 3d sensors, 20 modules in total instead of 16 + sector = m_phi_module*1000+m_eta_module+10; + } + else { + // is a generic module of the barrel region + sector = m_phi_module*1000+m_eta_module+6; + } - sector = phiMod*10000+cottMod*100+curvMod; - //cout << "mod_x: " << mod_x << "\tphiMod: " << phiMod << endl; // cy debug - //cout << "sector: " << sector << "\tplane: " << plane << endl; // cy debug + // retrieve information + int ndim = pmap->getPlane(plane,section).getNDimension(); + FTKHit reshit(ndim); + reshit.setITkMode( FTKSetup::getFTKSetup().getITkMode() ); + reshit.setIdentifierHash(getIdentifierHash()); + reshit.setPlane(plane); reshit.setSector(sector); - reshit.setBankID(getBankID()); - reshit.setRoadID(getRoadID()); - reshit.setTrackID(getTrackID()); - reshit[0] = mod_x; - reshit[1] = mod_y; - reshit[2] = mod_z; - break; - } - - // convert also the eventual channels - vector::const_iterator ichannel = m_channels.begin(); - vector::const_iterator ichannel_end = m_channels.end(); - for (;ichannel!=ichannel_end;++ichannel) { - reshit.addChannel((*ichannel).getFTKHit(pmap)); - } - - return reshit; + reshit.setHwWord(m_hw_word); + if (m_moduleType == ftk::MODULETYPE_SCT){ + reshit.setScalingCoordToHWCoord(0,SCT_row_scaling); + reshit.setScalingCoordToHWCoord(1,0); + } + else if (m_moduleType == ftk::MODULETYPE_PIXEL) { + reshit.setScalingCoordToHWCoord(0,PIX_row_scaling); + reshit.setScalingCoordToHWCoord(1,PIX_column_scaling); + } + else if (m_moduleType == ftk::MODULETYPE_IBL_PLANAR) { + reshit.setScalingCoordToHWCoord(0,IBL_planar_row_scaling); + reshit.setScalingCoordToHWCoord(1,IBL_planar_column_scaling); + } + else if (m_moduleType == ftk::MODULETYPE_IBL3D) { + reshit.setScalingCoordToHWCoord(0,IBL_3D_row_scaling); + reshit.setScalingCoordToHWCoord(1,IBL_3D_column_scaling); + } + else {// don't think i should be here! + reshit.setScalingCoordToHWCoord(0,0); + reshit.setScalingCoordToHWCoord(1,0); + } + + switch (m_hitType) { + case ftk::PIXEL: + reshit.setEtaWidth(getEtaWidth()); + reshit.setPhiWidth(getPhiWidth()); + reshit.getCoord().setIncludesGanged(getIncludesGanged()); + reshit.setNStrips(getNStrips()); + reshit[0] = m_pi_side+m_dPhi; + reshit[1] = m_ei_strip+m_dEta; + break; + case ftk::SCT: + // reshit[0] = m_ei_strip+(m_n_strips-1.)/2.; + reshit[0] = m_ei_strip+m_dPhi; + reshit.setNStrips(getNStrips()); + reshit.setEtaWidth(getEtaWidth()); + reshit.setPhiWidth(getPhiWidth()); + break; + } + + // convert also the eventual channels + vector::const_iterator ichannel = m_channels.begin(); + vector::const_iterator ichannel_end = m_channels.end(); + for (;ichannel!=ichannel_end;++ichannel) { + reshit.addChannel((*ichannel).getFTKHit(pmap)); + } + + return reshit; } void FTKRawHit::setTruth(const MultiTruth& v) { - if(m_truth) { - *m_truth = v; - } else { - m_truth = new MultiTruth(v); - } + if(m_truth) { + *m_truth = v; + } else { + m_truth = new MultiTruth(v); + } } diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadFileOutput.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadFileOutput.cxx index 4a547abd676..ac67bbdab53 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadFileOutput.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadFileOutput.cxx @@ -18,11 +18,6 @@ void FTKRoadFileOutput::addRoad(int BankID, const FTKRoad &road) m_data[BankID]->addRoad(road); } -void FTKRoadFileOutput::inc4LRoad(int BankID,const int& val) -{ - m_data[BankID]->inc4LRoad(val); -} - /** add a SS, with the hits list, in the bank. The SS is connect at least to one road */ void FTKRoadFileOutput::addSS(int BankID, int plane, diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadFinderAlgo.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadFinderAlgo.cxx index 2de7adcda8d..30c266e9ece 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadFinderAlgo.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadFinderAlgo.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #include "TrigFTKSim/FTKRoadFinderAlgo.h" @@ -23,590 +23,580 @@ using namespace std; ///////////////////////////////////////////////////////////////////////////// FTKRoadFinderAlgo::FTKRoadFinderAlgo(const std::string& name, ISvcLocator* pSvcLocator) : - AthAlgorithm(name, pSvcLocator), - m_rfobj(), - m_hitInputTool("FTK_SGHitInput/FTK_SGHitInput"), - m_roadOutputTool("FTK_SGRoadOutput/FTK_SGRoadOutput"), - m_roadMarketTool("FTK_RoadMarketTool/FTK_RoadMarketTool"), - m_nbanks(0), m_nsubregions(1), - m_verbosity(0), - m_BarrelOnly(false), m_EnableFTKSim(true), - m_MaxMissingPlanes(1), m_RoadWarrior(0), m_KeepRemoved(0), - m_MaxMissingSCTPairs(0), m_RestrictSctPairModule(false), m_RestrictSctPairLayer(false), - m_IBLMode(0), m_fixEndcapL0(false), - m_ITkMode(false), - m_ss_offset_fraction(0), - m_PixelClusteringMode(0), - m_Ibl3DRealistic(false), - m_DuplicateGanged(1), - m_GangedPatternRecognition(0), - m_SctClustering(0), - m_read_clusters(false), - m_clustering(true), - m_SCTTrkMode(false), m_scttrk_tracklist(""), - m_scttrk_roadlist(""), m_scttrk_sectormap_path(""), - m_scttrk_nlayers(0), m_scttrk_nsubs(0), m_scttrk_lastlayer(0), - m_useTSPBank(0), m_useCompressedBank(0), - m_BankLevel(1), m_doTSPSim(0), m_minTSPCoverage(0), - m_setAMSize(0), m_setAMSplit(0), m_maxAMAfterSplit(-1), m_minDVolOverDNPatt(0), - m_doMakeCache(0), m_CachePath("bankcache.root"), - m_SaveAllRoads(0), m_StoreAllSS(0), - m_pmap(0x0), m_pmap_unused(0x0), - m_rmap(0x0), m_rmap_unused(0x0), m_CUR_REGION(-1), - m_ssmap(0x0), m_ssmap_unused(0x0), m_ssmap_tsp(0x0), - m_require_first(false), - m_scttrk_sectormap(0x0), - m_HWModeSS(0), - m_pmap_path(), m_pmapunused_path(), - m_rmap_path(), m_rmapunused_path(), - m_ssmap_path(), m_ssmapunused_path(), m_ssmaptsp_path(), m_badmap_path(),m_badmap_path2(), - m_modulelut_path(), - m_modulelut2nd_path(), - m_CachedBank(false), - m_InputFromWrapper(true), m_RegionalWrapper(false), - m_doroadfile(false), m_roadfilepath("ftkroads.root"), - m_roadfilesdir("."), - m_roadmarket(true), - m_saveroads(true), - m_useMinimalAMIN(false), - m_SectorAsPatterns(0), - m_DCMatchMethod(0), - m_AutoDisable(false), - m_read_FTKhits_directly(false), - m_firstEventFTK(-1), - m_AMcompressionMode(0) + AthAlgorithm(name, pSvcLocator), + m_rfobj(), + m_hitInputTool("FTK_SGHitInput/FTK_SGHitInput"), + m_roadOutputTool("FTK_SGRoadOutput/FTK_SGRoadOutput"), + m_roadMarketTool("FTK_RoadMarketTool/FTK_RoadMarketTool"), + m_nbanks(0), m_nsubregions(1), + m_verbosity(0), + m_BarrelOnly(false), m_EnableFTKSim(true), + m_MaxMissingPlanes(1), m_RoadWarrior(0), m_KeepRemoved(0), + m_MaxMissingSCTPairs(0), m_RestrictSctPairModule(false), m_RestrictSctPairLayer(false), + m_IBLMode(0), m_fixEndcapL0(false), + m_ITkMode(false), + m_ss_offset_fraction(0), + m_PixelClusteringMode(0), + m_Ibl3DRealistic(false), + m_DuplicateGanged(1), + m_GangedPatternRecognition(0), + m_SctClustering(0), + m_read_clusters(false), + m_clustering(true), + m_useTSPBank(0), m_useCompressedBank(0), + m_BankLevel(1), m_doTSPSim(0), m_minTSPCoverage(0), + m_setAMSize(0), m_setAMSplit(0), m_maxAMAfterSplit(-1), m_minDVolOverDNPatt(0), + m_doMakeCache(0), m_CachePath("bankcache.root"), + m_SaveAllRoads(0), m_StoreAllSS(0), + m_pmap(0x0), m_pmap_unused(0x0), + m_rmap(0x0), m_rmap_unused(0x0), m_CUR_REGION(-1), + m_ssmap(0x0), m_ssmap_unused(0x0), m_ssmap_tsp(0x0), + m_require_first(false), + m_HWModeSS(0), + m_pmap_path(), m_pmapunused_path(), + m_rmap_path(), m_rmapunused_path(), + m_ssmap_path(), m_ssmapunused_path(), m_ssmaptsp_path(), m_badmap_path(),m_badmap_path2(), + m_modulelut_path(), + m_modulelut2nd_path(), + m_CachedBank(false), + m_InputFromWrapper(true), m_RegionalWrapper(false), + m_doroadfile(false), m_roadfilepath("ftkroads.root"), + m_roadfilesdir("."), + m_roadmarket(true), + m_saveroads(true), + m_useMinimalAMIN(false), + m_SectorAsPatterns(0), + m_DCMatchMethod(0), + m_AutoDisable(false), + m_read_FTKhits_directly(false), + m_firstEventFTK(-1), + m_AMcompressionMode(0) { - // number of banks - declareProperty("NBanks",m_nbanks); - declareProperty("NSubRegions",m_nsubregions); - declareProperty("BarrelOnly",m_BarrelOnly); - declareProperty("MaxMissingPlanes",m_MaxMissingPlanes); - - declareProperty("pmap_path",m_pmap_path); - declareProperty("pmapunused_path",m_pmapunused_path); - declareProperty("rmap_path",m_rmap_path); - declareProperty("rmapunused_path",m_rmapunused_path); - declareProperty("ssmap_path",m_ssmap_path); - declareProperty("ssmapunused_path",m_ssmapunused_path); - declareProperty("ssmaptsp_path",m_ssmaptsp_path); - declareProperty("badmap_path",m_badmap_path); - declareProperty("badmap_path_for_hit",m_badmap_path2); - - declareProperty("ModuleLUTPath",m_modulelut_path); - declareProperty("ModuleLUTPath2nd",m_modulelut2nd_path); - - declareProperty("IBLMode",m_IBLMode); - declareProperty("FixEndCapL0",m_fixEndcapL0, "Fix endcap L0 clustering"); - declareProperty("ITkMode",m_ITkMode); - - declareProperty("PixelClusteringMode",m_PixelClusteringMode,"Pixel clustering correction: 0 simple default, 1 channel center and linear ToT interpolation and account for different pixel lengths"); - declareProperty("Ibl3DRealistic",m_Ibl3DRealistic,"Do IBL 3D realistic(HWlike) clustering? Default is false"); - declareProperty("DuplicateGanged",m_DuplicateGanged,"Duplicate ganged pixels so we don't lose efficiency"); - declareProperty("GangedPatternReco", m_GangedPatternRecognition,"Pattern recognition to partially remove duplication"); - declareProperty("SctClustering",m_SctClustering,"Enable SCT clustering: 0 disabled, 1 enabled"); - declareProperty("ReadClusters",m_read_clusters,"Read Clusters from FTKIP File? Default is false"); - declareProperty("Clustering",m_clustering,"Perform clustering? Default is true"); - - declareProperty("CachedBank",m_CachedBank); - declareProperty("patternbankpath",m_patternbankpath,"Array with bank paths"); - declareProperty("bankregion",m_bankregion,"Array of region IDs"); - declareProperty("banksubregion",m_banksubreg,"Array of sub-region IDs"); - declareProperty("bankpatterns",m_bankpatterns,"Max patterns for each bank, -1 means all patterns"); - - declareProperty("UseTSPBank",m_useTSPBank,"If true the AM bank is the DB format"); - declareProperty("UseCompressedBank",m_useCompressedBank,"If true the AM bank is the compressed format"); - declareProperty("TSPSimulationLevel",m_doTSPSim,"Level of the TSP simulation: 0 AM, 1 DC, 2 TSP"); - declareProperty("DBBankLevel",m_BankLevel,"ID of the bank, if simulation level is 0"); - declareProperty("TSPMinCoverage",m_minTSPCoverage,"Minimum coverage of the TSP patterns"); - declareProperty("SetAMSize",m_setAMSize,"If 1 or 2 the flag in a TSP simulation decide to set the AM size"); - declareProperty("SetAMSplit",m_setAMSplit,"default=0: use normal DC bits; if >0 optimize DC bits usage"); - declareProperty("MaxAMAfterSplit", m_maxAMAfterSplit, "max number of AM patterns after split, default=-1: no limits"); - declareProperty("MinDVolOverDNPatt", m_minDVolOverDNPatt, "minimum threshold for DVol/DNPatt for split; default=0"); - declareProperty("RoadWarrior",m_RoadWarrior); - declareProperty("MakeCache",m_doMakeCache,"Enable the cache creation for the TSP bank"); - declareProperty("CachePath",m_CachePath,"Path of the cache file"); - declareProperty("InputFromWrapper",m_InputFromWrapper,"Use the standalone input file format, a.k.a. wrapper files"); - declareProperty("RegionalWrapper", m_RegionalWrapper, "Use wrapper files with regions applied"); - declareProperty("WrapperFiles",m_wrapperpaths,"Paths of the input files in the wrapper format"); - declareProperty("DoRoadFile",m_doroadfile,"Enable the extrnal road output file"); - declareProperty("RoadFile",m_roadfilepath,"Path of the road output file, old format"); - declareProperty("RoadFilesDir",m_roadfilesdir,"Path of the road output directory, old format"); - declareProperty("RoadMarket",m_roadmarket,"Enable the road exchange tool"); - declareProperty("SaveRoads",m_saveroads,"If true (default) the output roads are saved into the SG"); - - declareProperty("UseMinimalAMIN",m_useMinimalAMIN); - declareProperty("StoreAllSS",m_StoreAllSS,"If true, store all SS, not just in roads"); - declareProperty("HWModeSS",m_HWModeSS,"Enable the HW-like encoding for the SS"); - declareProperty("ReadFTKHits",m_read_FTKhits_directly,"Read FTKHits directly rather than FTKRawHits"); - - declareProperty("MaxMissingSCTPairs",m_MaxMissingSCTPairs,"Increase the number of missing SCT modules, enable the transition region fix"); - declareProperty("RestrictSctPairModule",m_RestrictSctPairModule, "Restrict SCT pairs modules in the transition region"); - declareProperty("RestrictSctPairLayer",m_RestrictSctPairLayer,"Restrict SCT layers in the transition region"); - - declareProperty("SectorsAsPatterns",m_SectorAsPatterns,"When 1 allows to use a list of sectors as pattern bank"); - - declareProperty("DCMatchMethod",m_DCMatchMethod,"Set the DC matching method: 0 through TSP SS organization, 1 direct"); - - declareProperty("FirstEventFTK",m_firstEventFTK,"First event to run over"); - declareProperty("AMcompressionMode",m_AMcompressionMode,"compression mode for AM bank"); + // number of banks + declareProperty("NBanks",m_nbanks); + declareProperty("NSubRegions",m_nsubregions); + declareProperty("BarrelOnly",m_BarrelOnly); + declareProperty("MaxMissingPlanes",m_MaxMissingPlanes); + + declareProperty("pmap_path",m_pmap_path); + declareProperty("pmapunused_path",m_pmapunused_path); + declareProperty("rmap_path",m_rmap_path); + declareProperty("rmapunused_path",m_rmapunused_path); + declareProperty("ssmap_path",m_ssmap_path); + declareProperty("ssmapunused_path",m_ssmapunused_path); + declareProperty("ssmaptsp_path",m_ssmaptsp_path); + declareProperty("badmap_path",m_badmap_path); + declareProperty("badmap_path_for_hit",m_badmap_path2); + + declareProperty("ModuleLUTPath",m_modulelut_path); + declareProperty("ModuleLUTPath2nd",m_modulelut2nd_path); + + declareProperty("IBLMode",m_IBLMode); + declareProperty("FixEndCapL0",m_fixEndcapL0, "Fix endcap L0 clustering"); + declareProperty("ITkMode",m_ITkMode); + + declareProperty("PixelClusteringMode",m_PixelClusteringMode,"Pixel clustering correction: 0 simple default, 1 channel center and linear ToT interpolation and account for different pixel lengths"); + declareProperty("Ibl3DRealistic",m_Ibl3DRealistic,"Do IBL 3D realistic(HWlike) clustering? Default is false"); + declareProperty("DuplicateGanged",m_DuplicateGanged,"Duplicate ganged pixels so we don't lose efficiency"); + declareProperty("GangedPatternReco", m_GangedPatternRecognition,"Pattern recognition to partially remove duplication"); + declareProperty("SctClustering",m_SctClustering,"Enable SCT clustering: 0 disabled, 1 enabled"); + declareProperty("ReadClusters",m_read_clusters,"Read Clusters from FTKIP File? Default is false"); + declareProperty("Clustering",m_clustering,"Perform clustering? Default is true"); + + declareProperty("CachedBank",m_CachedBank); + declareProperty("patternbankpath",m_patternbankpath,"Array with bank paths"); + declareProperty("bankregion",m_bankregion,"Array of region IDs"); + declareProperty("banksubregion",m_banksubreg,"Array of sub-region IDs"); + declareProperty("bankpatterns",m_bankpatterns,"Max patterns for each bank, -1 means all patterns"); + + declareProperty("UseTSPBank",m_useTSPBank,"If true the AM bank is the DB format"); + declareProperty("UseCompressedBank",m_useCompressedBank,"If true the AM bank is the compressed format"); + declareProperty("TSPSimulationLevel",m_doTSPSim,"Level of the TSP simulation: 0 AM, 1 DC, 2 TSP"); + declareProperty("DBBankLevel",m_BankLevel,"ID of the bank, if simulation level is 0"); + declareProperty("TSPMinCoverage",m_minTSPCoverage,"Minimum coverage of the TSP patterns"); + declareProperty("SetAMSize",m_setAMSize,"If 1 or 2 the flag in a TSP simulation decide to set the AM size"); + declareProperty("SetAMSplit",m_setAMSplit,"default=0: use normal DC bits; if >0 optimize DC bits usage"); + declareProperty("MaxAMAfterSplit", m_maxAMAfterSplit, "max number of AM patterns after split, default=-1: no limits"); + declareProperty("MinDVolOverDNPatt", m_minDVolOverDNPatt, "minimum threshold for DVol/DNPatt for split; default=0"); + declareProperty("RoadWarrior",m_RoadWarrior); + declareProperty("MakeCache",m_doMakeCache,"Enable the cache creation for the TSP bank"); + declareProperty("CachePath",m_CachePath,"Path of the cache file"); + declareProperty("InputFromWrapper",m_InputFromWrapper,"Use the standalone input file format, a.k.a. wrapper files"); + declareProperty("RegionalWrapper", m_RegionalWrapper, "Use wrapper files with regions applied"); + declareProperty("WrapperFiles",m_wrapperpaths,"Paths of the input files in the wrapper format"); + declareProperty("DoRoadFile",m_doroadfile,"Enable the extrnal road output file"); + declareProperty("RoadFile",m_roadfilepath,"Path of the road output file, old format"); + declareProperty("RoadFilesDir",m_roadfilesdir,"Path of the road output directory, old format"); + declareProperty("RoadMarket",m_roadmarket,"Enable the road exchange tool"); + declareProperty("SaveRoads",m_saveroads,"If true (default) the output roads are saved into the SG"); + + declareProperty("UseMinimalAMIN",m_useMinimalAMIN); + declareProperty("StoreAllSS",m_StoreAllSS,"If true, store all SS, not just in roads"); + declareProperty("HWModeSS",m_HWModeSS,"Enable the HW-like encoding for the SS"); + declareProperty("ReadFTKHits",m_read_FTKhits_directly,"Read FTKHits directly rather than FTKRawHits"); + + declareProperty("MaxMissingSCTPairs",m_MaxMissingSCTPairs,"Increase the number of missing SCT modules, enable the transition region fix"); + declareProperty("RestrictSctPairModule",m_RestrictSctPairModule, "Restrict SCT pairs modules in the transition region"); + declareProperty("RestrictSctPairLayer",m_RestrictSctPairLayer,"Restrict SCT layers in the transition region"); + + declareProperty("SectorsAsPatterns",m_SectorAsPatterns,"When 1 allows to use a list of sectors as pattern bank"); + + declareProperty("DCMatchMethod",m_DCMatchMethod,"Set the DC matching method: 0 through TSP SS organization, 1 direct"); + + declareProperty("FirstEventFTK",m_firstEventFTK,"First event to run over"); + declareProperty("AMcompressionMode",m_AMcompressionMode,"compression mode for AM bank"); } FTKRoadFinderAlgo::~FTKRoadFinderAlgo() { - if (m_ssmap) delete m_ssmap; - if (m_ssmap_unused) delete m_ssmap_unused; - if (m_ssmap_tsp) delete m_ssmap_tsp; - if (m_rmap) delete m_rmap; - if (m_rmap_unused) delete m_rmap_unused; - if (m_pmap) delete m_pmap; - if (m_pmap_unused) delete m_pmap_unused; - - // the objects derived from the standalone simulation has to be destroyed byt the algorithm itself, no Athena algorithm will take care of that - if (m_InputFromWrapper) delete m_rfobj.getDataInputModule(); - if (m_doroadfile) delete m_rfobj.getRoadOutputModule(); + if (m_ssmap) delete m_ssmap; + if (m_ssmap_unused) delete m_ssmap_unused; + if (m_ssmap_tsp) delete m_ssmap_tsp; + if (m_rmap) delete m_rmap; + if (m_rmap_unused) delete m_rmap_unused; + if (m_pmap) delete m_pmap; + if (m_pmap_unused) delete m_pmap_unused; + + // the objects derived from the standalone simulation has to be destroyed byt the algorithm itself, no Athena algorithm will take care of that + if (m_InputFromWrapper) delete m_rfobj.getDataInputModule(); + if (m_doroadfile) delete m_rfobj.getRoadOutputModule(); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * StatusCode FTKRoadFinderAlgo::initialize(){ - // get the reference to the central standalone instance - FTKSetup &ftkset = FTKSetup::getFTKSetup(); - - MsgStream log(msgSvc(), name()); - FTKSetup::getFTKSetup().setMsgStream(&log); - FTKLogger::SetLogger(this); - - log << MSG::INFO << "FTKRoadFinderAlgo::initialize()" << endmsg; - - - ftkset.setSectorsAsPatterns(m_SectorAsPatterns); - if (m_SectorAsPatterns) { - log << MSG::INFO << "SectorsAsPatterns mode enabled with value " << m_SectorAsPatterns << endmsg; - } - - log << MSG::INFO << "IBL mode value: " << m_IBLMode << endmsg; - ftkset.setIBLMode(m_IBLMode); - - log << MSG::INFO << "Fix EndcapL0 value: " << m_fixEndcapL0 << endmsg; - ftkset.setfixEndcapL0(m_fixEndcapL0); - - log << MSG::INFO << "ITk mode value: " << m_ITkMode << endmsg; - ftkset.setITkMode(m_ITkMode); - - log << MSG::INFO << "HWModeSS value: " << m_HWModeSS << endmsg; - ftkset.setHWModeSS(m_HWModeSS); - - log << MSG::INFO << "Read the logical layer definitions" << endmsg; - // Look for the main plane-map - if (m_pmap_path.empty()) { - log << MSG::FATAL << "Main plane map definition missing" << endmsg; - return StatusCode::FAILURE; - } - else { - m_pmap = new FTKPlaneMap(m_pmap_path.c_str()); - if (!(*m_pmap)) { - log << MSG::FATAL << "Error using plane map: " << m_pmap_path << endmsg; - return StatusCode::FAILURE; - } - } - - if (!m_pmapunused_path.empty()) { - log << MSG::INFO << "Read the logical layer definitions for the unused layers" << endmsg; - m_pmap_unused = new FTKPlaneMap(m_pmapunused_path.c_str()); - if (!(*m_pmap_unused)) { - log << MSG::FATAL << "Error using plane map: " << m_pmap_path << endmsg; - return StatusCode::FAILURE; + // get the reference to the central standalone instance + FTKSetup &ftkset = FTKSetup::getFTKSetup(); + + MsgStream log(msgSvc(), name()); + FTKSetup::getFTKSetup().setMsgStream(&log); + FTKLogger::SetLogger(this); + + log << MSG::INFO << "FTKRoadFinderAlgo::initialize()" << endmsg; + + + ftkset.setSectorsAsPatterns(m_SectorAsPatterns); + if (m_SectorAsPatterns) { + log << MSG::INFO << "SectorsAsPatterns mode enabled with value " << m_SectorAsPatterns << endmsg; } - } - - - // Create the region map objects - if (m_rmap_path.empty()) { - log << MSG::FATAL << "Region map file needed" << endmsg; - return StatusCode::FAILURE; - } - - log << MSG::INFO << "Creating region map" << endmsg; - m_rmap = new FTKRegionMap(m_pmap, m_rmap_path.c_str()); - if (!(*m_rmap)) { - log << MSG::FATAL << "Error creating region map from: " << m_rmap_path.c_str() << endmsg; - return StatusCode::FAILURE; - } - - //In case the HWModeSS=2 the LUT to map global->local module ID is required - if (m_HWModeSS==2) { - if (m_modulelut_path.empty()) { - log << MSG::FATAL << "A module LUT is required when HW SS calculation is required" << m_rmap_path.c_str() << endmsg; - return StatusCode::FAILURE; + log << MSG::INFO << "IBL mode value: " << m_IBLMode << endmsg; + ftkset.setIBLMode(m_IBLMode); + + log << MSG::INFO << "Fix EndcapL0 value: " << m_fixEndcapL0 << endmsg; + ftkset.setfixEndcapL0(m_fixEndcapL0); + + log << MSG::INFO << "ITk mode value: " << m_ITkMode << endmsg; + ftkset.setITkMode(m_ITkMode); + + log << MSG::INFO << "HWModeSS value: " << m_HWModeSS << endmsg; + ftkset.setHWModeSS(m_HWModeSS); + + log << MSG::INFO << "Read the logical layer definitions" << endmsg; + // Look for the main plane-map + if (m_pmap_path.empty()) { + log << MSG::FATAL << "Main plane map definition missing" << endmsg; + return StatusCode::FAILURE; } else { - log << MSG::INFO << "Loading module map from: " << m_modulelut_path << endmsg; - m_rmap->loadModuleIDLUT(m_modulelut_path.c_str()); + m_pmap = new FTKPlaneMap(m_pmap_path.c_str()); + if (!(*m_pmap)) { + log << MSG::FATAL << "Error using plane map: " << m_pmap_path << endmsg; + return StatusCode::FAILURE; + } } - } - if (m_pmap_unused) { - log << MSG::INFO << "Creating region map for the unused layers" << endmsg; - m_rmap_unused = new FTKRegionMap(m_pmap_unused, m_rmap_path.c_str()); - if (m_HWModeSS==2) { - if (m_modulelut2nd_path.empty()) { - log << MSG::FATAL << "A module LUT is required when HW SS calculation is required" << m_rmap_path.c_str() << endmsg; - return StatusCode::FAILURE; - } - else { - log << MSG::INFO << "Loading module map from: " << m_modulelut2nd_path << endmsg; - m_rmap_unused->loadModuleIDLUT(m_modulelut2nd_path.c_str()); - } - } - } - - - log << MSG::INFO << "Read SS configurations" << endmsg; - log << MSG::INFO << "Read AM SS configuration" << endmsg; - m_ssmap = new FTKSSMap(m_rmap, m_ssmap_path.c_str(), false); - if (!m_ssmapunused_path.empty()) { - log << MSG::INFO << "Read SS configuration for layer not used in AM" << endmsg; - m_ssmap_unused = new FTKSSMap(m_rmap_unused, m_ssmapunused_path.c_str(), false); - } - if (!m_ssmaptsp_path.empty()) { - log << MSG::INFO << "Read SS configuration for TSP/DC" << endmsg; - m_ssmap_tsp = new FTKSSMap(m_rmap, m_ssmaptsp_path.c_str(), false); - } - - - // select how the input is obtained - if (!m_InputFromWrapper) { - // Use the SG to retrieve the hits, this also means other Athena tools can be used - StatusCode schit = m_hitInputTool.retrieve(); - if (schit.isFailure()) { - log << MSG::FATAL << "Could not retrieve FTK_SGHitInput tool" << endmsg; - return StatusCode::FAILURE; + if (!m_pmapunused_path.empty()) { + log << MSG::INFO << "Read the logical layer definitions for the unused layers" << endmsg; + m_pmap_unused = new FTKPlaneMap(m_pmapunused_path.c_str()); + if (!(*m_pmap_unused)) { + log << MSG::FATAL << "Error using plane map: " << m_pmap_path << endmsg; + return StatusCode::FAILURE; + } + } - else { - log << MSG::INFO << "Setting FTK_SGHitInput tool" << endmsg; - // set the pmap address to FTKDataInput to use in processEvent - m_hitInputTool->reference()->setPlaneMaps(m_pmap,m_pmap_unused); + + + // Create the region map objects + if (m_rmap_path.empty()) { + log << MSG::FATAL << "Region map file needed" << endmsg; + return StatusCode::FAILURE; } - m_hitInputTool->reference()->setFirstEvent(m_firstEventFTK); - m_rfobj.setDataInputModule(m_hitInputTool->reference()); - - } - else if (m_RegionalWrapper) { - // the input comes from a wrapper file's format, prepare the standlone like input - log << MSG::INFO << "Setting FTK_RegionalRawInput as input module" << endmsg; - FTK_RegionalRawInput *ftkrawinput = new FTK_RegionalRawInput(m_pmap,m_pmap_unused,false); - - // Tell input whether hits will be in raw format or not - ftkrawinput->setReadFTKHits(m_read_FTKhits_directly); - - if (m_pmap_unused) { - // enable all the flags used for the 2nd stage fitting - ftkrawinput->setSaveUnused(!m_ITkMode); - m_rfobj.setSSSearchUnused(!m_ITkMode); + + log << MSG::INFO << "Creating region map" << endmsg; + m_rmap = new FTKRegionMap(m_pmap, m_rmap_path.c_str()); + if (!(*m_rmap)) { + log << MSG::FATAL << "Error creating region map from: " << m_rmap_path.c_str() << endmsg; + return StatusCode::FAILURE; } - // add the input files - log << MSG::INFO << "Loading " << m_wrapperpaths.size() << " files" << endmsg; - for (unsigned ifile=0;ifile!=m_wrapperpaths.size();++ifile) { - log << MSG::INFO << "Loading " << m_wrapperpaths[ifile] << endmsg; - ftkrawinput->addFile(m_wrapperpaths[ifile].c_str()); + //In case the HWModeSS=2 the LUT to map global->local module ID is required + if (m_HWModeSS==2) { + if (m_modulelut_path.empty()) { + log << MSG::FATAL << "A module LUT is required when HW SS calculation is required" << m_rmap_path.c_str() << endmsg; + return StatusCode::FAILURE; + } + else { + log << MSG::INFO << "Loading module map from: " << m_modulelut_path << endmsg; + m_rmap->loadModuleIDLUT(m_modulelut_path.c_str()); + } } - ftkrawinput->setFirstEvent(m_firstEventFTK); - m_rfobj.setDataInputModule(ftkrawinput); - } - else { - // the input comes from a wrapper file's format, prepare the standlone like input - log << MSG::INFO << "Setting FTK_RawInput as input module" << endmsg; - FTK_RawInput *ftkrawinput = new FTK_RawInput(m_pmap,m_pmap_unused); + if (m_pmap_unused) { - // enable all the flags used for the 2nd stage fitting - ftkrawinput->setSaveUnused(true); - m_rfobj.setSSSearchUnused(true); + log << MSG::INFO << "Creating region map for the unused layers" << endmsg; + m_rmap_unused = new FTKRegionMap(m_pmap_unused, m_rmap_path.c_str()); + if (m_HWModeSS==2) { + if (m_modulelut2nd_path.empty()) { + log << MSG::FATAL << "A module LUT is required when HW SS calculation is required" << m_rmap_path.c_str() << endmsg; + return StatusCode::FAILURE; + } + else { + log << MSG::INFO << "Loading module map from: " << m_modulelut2nd_path << endmsg; + m_rmap_unused->loadModuleIDLUT(m_modulelut2nd_path.c_str()); + } + } } - // add the input files - log << MSG::INFO << "Loading " << m_wrapperpaths.size() << " files" << endmsg; - for (unsigned ifile=0;ifile!=m_wrapperpaths.size();++ifile) { - log << MSG::INFO << "Loading " << m_wrapperpaths[ifile] << endmsg; - ftkrawinput->addFile(m_wrapperpaths[ifile].c_str()); + + log << MSG::INFO << "Read SS configurations" << endmsg; + log << MSG::INFO << "Read AM SS configuration" << endmsg; + m_ssmap = new FTKSSMap(m_rmap, m_ssmap_path.c_str(), false); + if (!m_ssmapunused_path.empty()) { + log << MSG::INFO << "Read SS configuration for layer not used in AM" << endmsg; + m_ssmap_unused = new FTKSSMap(m_rmap_unused, m_ssmapunused_path.c_str(), false); } - ftkrawinput->setFirstEvent(m_firstEventFTK); - m_rfobj.setDataInputModule(ftkrawinput); - } - - // Set options related to the input: clustering or other features - m_rfobj.getDataInputModule()->setPixelClusteringMode(m_PixelClusteringMode); - m_rfobj.getDataInputModule()->setIbl3DRealistic(m_Ibl3DRealistic); - m_rfobj.getDataInputModule()->setSctClustering(m_SctClustering); - m_rfobj.getDataInputModule()->setDuplicateGanged(m_DuplicateGanged); - m_rfobj.getDataInputModule()->setGangedPatternRecognition(m_GangedPatternRecognition); - - m_rfobj.getDataInputModule()->setReadClusters(m_read_clusters); - m_rfobj.getDataInputModule()->setClustering(m_clustering); - - - // Set Option (temporaly way for checking standalone ver. -> should change to better way) // - ftkset.setBarrelOnly(m_BarrelOnly); - ftkset.setRawMode(!m_pmap_unused ? 1 : 2); - ftkset.setEnableFTKSim(m_EnableFTKSim); - ftkset.setMaxMissingPlanes(m_MaxMissingPlanes); - - // Transition region fix. Works allowing extra missing modules - ftkset.setMaxMissingSctPairs(m_MaxMissingSCTPairs); - if (m_RestrictSctPairModule) { - // Asking missing extra module implies missing extra layer - ftkset.setRestrictSctPairModule(1); - ftkset.setRestrictSctPairLayer(1); - } - else { - // possible to have not synched flags - ftkset.setRestrictSctPairModule(0); - ftkset.setRestrictSctPairLayer(m_RestrictSctPairLayer ? 1 : 0); - } - - ftkset.setRoadWarrior(m_RoadWarrior); - m_pmap->setEnablePlanePair(0); - - ftkset.setKeepRemoved(m_KeepRemoved); - ftkset.setVerbosity(m_verbosity); - - if (m_roadmarket ) { // enable the tool to exchange the roads with the FTKTrackFitterAlgo - // ensure other colliding options are not true - if (m_doroadfile) { - log << MSG::WARNING << "Use of FTK_RoadMarketTool disable the road file" << endmsg; - m_doroadfile = false; + if (!m_ssmaptsp_path.empty()) { + log << MSG::INFO << "Read SS configuration for TSP/DC" << endmsg; + m_ssmap_tsp = new FTKSSMap(m_rmap, m_ssmaptsp_path.c_str(), false); } - StatusCode scmrk = m_roadMarketTool.retrieve(); - if (scmrk.isFailure()) { - log << MSG::FATAL << "Could not retrieve FTK_RoadMarketTool" << endmsg; - return StatusCode::FAILURE; + + // select how the input is obtained + if (!m_InputFromWrapper) { + // Use the SG to retrieve the hits, this also means other Athena tools can be used + StatusCode schit = m_hitInputTool.retrieve(); + if (schit.isFailure()) { + log << MSG::FATAL << "Could not retrieve FTK_SGHitInput tool" << endmsg; + return StatusCode::FAILURE; + } + else { + log << MSG::INFO << "Setting FTK_SGHitInput tool" << endmsg; + // set the pmap address to FTKDataInput to use in processEvent + m_hitInputTool->reference()->setPlaneMaps(m_pmap,m_pmap_unused); + } + m_hitInputTool->reference()->setFirstEvent(m_firstEventFTK); + m_rfobj.setDataInputModule(m_hitInputTool->reference()); + + } + else if (m_RegionalWrapper) { + // the input comes from a wrapper file's format, prepare the standlone like input + log << MSG::INFO << "Setting FTK_RegionalRawInput as input module" << endmsg; + FTK_RegionalRawInput *ftkrawinput = new FTK_RegionalRawInput(m_pmap,m_pmap_unused,false); + + // Tell input whether hits will be in raw format or not + ftkrawinput->setReadFTKHits(m_read_FTKhits_directly); + + if (m_pmap_unused) { + // enable all the flags used for the 2nd stage fitting + ftkrawinput->setSaveUnused(!m_ITkMode); + m_rfobj.setSSSearchUnused(!m_ITkMode); + } + + // add the input files + log << MSG::INFO << "Loading " << m_wrapperpaths.size() << " files" << endmsg; + for (unsigned ifile=0;ifile!=m_wrapperpaths.size();++ifile) { + log << MSG::INFO << "Loading " << m_wrapperpaths[ifile] << endmsg; + ftkrawinput->addFile(m_wrapperpaths[ifile].c_str()); + } + ftkrawinput->setFirstEvent(m_firstEventFTK); + m_rfobj.setDataInputModule(ftkrawinput); } else { - log << MSG::INFO << "Setting FTK_RoadMarketTool" << endmsg; + // the input comes from a wrapper file's format, prepare the standlone like input + log << MSG::INFO << "Setting FTK_RawInput as input module" << endmsg; + FTK_RawInput *ftkrawinput = new FTK_RawInput(m_pmap,m_pmap_unused); + if (m_pmap_unused) { + // enable all the flags used for the 2nd stage fitting + ftkrawinput->setSaveUnused(true); + m_rfobj.setSSSearchUnused(true); + } + + // add the input files + log << MSG::INFO << "Loading " << m_wrapperpaths.size() << " files" << endmsg; + for (unsigned ifile=0;ifile!=m_wrapperpaths.size();++ifile) { + log << MSG::INFO << "Loading " << m_wrapperpaths[ifile] << endmsg; + ftkrawinput->addFile(m_wrapperpaths[ifile].c_str()); + } + ftkrawinput->setFirstEvent(m_firstEventFTK); + m_rfobj.setDataInputModule(ftkrawinput); } - log << MSG::INFO << "Roads are not saved but only kept in memory and moved to the track fitter" << endmsg; - FTKRoadOutput *ftkoutmodule = m_roadMarketTool->outputReference(); - //m_roadMarketTool->SaveRoads(m_saveroads); - m_rfobj.setRoadOutputModule(ftkoutmodule); - m_roadMarketTool->setRoadFinderReference(&m_rfobj); - } - else if (!m_doroadfile && m_saveroads) { // enable the Athena tool for the road output - StatusCode scout = m_roadOutputTool.retrieve(); - if (scout.isFailure()) { - log << MSG::FATAL << "Could not retrieve FTK_SGRoadOutput tool" << endmsg; - return StatusCode::FAILURE; + // Set options related to the input: clustering or other features + m_rfobj.getDataInputModule()->setPixelClusteringMode(m_PixelClusteringMode); + m_rfobj.getDataInputModule()->setIbl3DRealistic(m_Ibl3DRealistic); + m_rfobj.getDataInputModule()->setSctClustering(m_SctClustering); + m_rfobj.getDataInputModule()->setDuplicateGanged(m_DuplicateGanged); + m_rfobj.getDataInputModule()->setGangedPatternRecognition(m_GangedPatternRecognition); + + m_rfobj.getDataInputModule()->setReadClusters(m_read_clusters); + m_rfobj.getDataInputModule()->setClustering(m_clustering); + + + // Set Option (temporaly way for checking standalone ver. -> should change to better way) // + ftkset.setBarrelOnly(m_BarrelOnly); + ftkset.setRawMode(!m_pmap_unused ? 1 : 2); + ftkset.setEnableFTKSim(m_EnableFTKSim); + ftkset.setMaxMissingPlanes(m_MaxMissingPlanes); + + // Transition region fix. Works allowing extra missing modules + ftkset.setMaxMissingSctPairs(m_MaxMissingSCTPairs); + if (m_RestrictSctPairModule) { + // Asking missing extra module implies missing extra layer + ftkset.setRestrictSctPairModule(1); + ftkset.setRestrictSctPairLayer(1); } else { - log << MSG::INFO << "Setting FTK_SGRoadOutput tool" << endmsg; + // possible to have not synched flags + ftkset.setRestrictSctPairModule(0); + ftkset.setRestrictSctPairLayer(m_RestrictSctPairLayer ? 1 : 0); } - log << MSG::INFO << "Write the AM simulation results into the SG" << endmsg; - // prepare an object that interact with the SG to save the found roads - FTKRoadOutput *ftkoutmodule = m_roadOutputTool->reference(); - m_rfobj.setRoadOutputModule(ftkoutmodule); - } - // create the road output module, module have to be created before the setNBanks call - else if (m_doroadfile) { - // Make an external output file, compatible with the - // standalone version, to store the found roads - FTKRoadFileOutput *ftkoutmodule = new FTKRoadFileOutput(); - if (m_InputFromWrapper) { - log << MSG::INFO << "Write the AM simulation results in an external directory: " << m_roadfilesdir << endmsg; - // if the input format is composed by wrapper files the multi-out option is on - ftkoutmodule->setMultiOut(true); - ftkoutmodule->setOutDir(m_roadfilesdir.c_str()); // test name -> should be changed for any root file name we want + ftkset.setRoadWarrior(m_RoadWarrior); + m_pmap->setEnablePlanePair(0); + + ftkset.setKeepRemoved(m_KeepRemoved); + ftkset.setVerbosity(m_verbosity); + + if (m_roadmarket ) { // enable the tool to exchange the roads with the FTKTrackFitterAlgo + // ensure other colliding options are not true + if (m_doroadfile) { + log << MSG::WARNING << "Use of FTK_RoadMarketTool disable the road file" << endmsg; + m_doroadfile = false; + } + + StatusCode scmrk = m_roadMarketTool.retrieve(); + if (scmrk.isFailure()) { + log << MSG::FATAL << "Could not retrieve FTK_RoadMarketTool" << endmsg; + return StatusCode::FAILURE; + } + else { + log << MSG::INFO << "Setting FTK_RoadMarketTool" << endmsg; + } + + log << MSG::INFO << "Roads are not saved but only kept in memory and moved to the track fitter" << endmsg; + FTKRoadOutput *ftkoutmodule = m_roadMarketTool->outputReference(); + //m_roadMarketTool->SaveRoads(m_saveroads); + m_rfobj.setRoadOutputModule(ftkoutmodule); + m_roadMarketTool->setRoadFinderReference(&m_rfobj); } - else { - log << MSG::INFO << "Write the AM simulation results in an external file: " << m_roadfilepath << endmsg; - ftkoutmodule->setMultiOut(false); - ftkoutmodule->setFileName(m_roadfilepath.c_str()); // test name -> should be changed for any root file name we want + else if (!m_doroadfile && m_saveroads) { // enable the Athena tool for the road output + StatusCode scout = m_roadOutputTool.retrieve(); + if (scout.isFailure()) { + log << MSG::FATAL << "Could not retrieve FTK_SGRoadOutput tool" << endmsg; + return StatusCode::FAILURE; + } + else { + log << MSG::INFO << "Setting FTK_SGRoadOutput tool" << endmsg; + } + + log << MSG::INFO << "Write the AM simulation results into the SG" << endmsg; + // prepare an object that interact with the SG to save the found roads + FTKRoadOutput *ftkoutmodule = m_roadOutputTool->reference(); + m_rfobj.setRoadOutputModule(ftkoutmodule); } - m_rfobj.setRoadOutputModule(ftkoutmodule); - } - else { - log << MSG::FATAL << "At least an output method has to be specified" << endmsg; - return StatusCode::FAILURE; - } - - log << MSG::INFO << "Load banks" << endmsg; - - // Set the bank segmentation - m_rfobj.setNBanks(m_nbanks); - m_rfobj.setNsubregions(m_nsubregions); - - // get the bank files and information from the JO - unsigned int nbanks = m_patternbankpath.size(); - log << MSG::INFO << "Loading " << nbanks << " banks" << endmsg; - if (nbanks!=m_bankregion.size() || nbanks!=m_bankpatterns.size() || nbanks!=m_banksubreg.size()) { - log << MSG::FATAL << "Different array property length in bank definitions: " << nbanks << ' ' << m_bankregion.size() << ' ' << m_bankpatterns.size() << endmsg; - return StatusCode::FAILURE; - } - - for (unsigned int ib=0;ib!=nbanks;++ib) { // configuration banks loop - FTK_AMsimulation_base *curbank; - int regid(m_bankregion[ib]); - int subid(m_banksubreg[ib]); - - if (m_useTSPBank) { - // configura a TSP ready bank - FTKTSPBank *tspbank = new FTKTSPBank(regid,subid); - tspbank->setSimulateTSP(m_doTSPSim); - tspbank->setSSMapTSP(m_ssmap_tsp); - tspbank->setTSPMinCoverage(m_minTSPCoverage); - tspbank->setMakeCache(m_doMakeCache); - tspbank->setCachePath(m_CachePath.c_str()); - tspbank->setAMSize(m_setAMSize); - tspbank->setAMSplit(m_setAMSplit); - tspbank->setMaxAMAfterSplit(m_maxAMAfterSplit); - tspbank->setMinDVolOverDNPatt(m_minDVolOverDNPatt); - tspbank->setDCMatchMethod(m_DCMatchMethod); - curbank = tspbank; - } else if(m_useCompressedBank) { - FTK_CompressedAMBank *compressedBank= - new FTK_CompressedAMBank(regid,subid); - compressedBank->setSSMapTSP(m_ssmap_tsp); - curbank=compressedBank; - compressedBank->setCompressionScheme(m_AMcompressionMode); - } else { - // configure a base AM bank - curbank = new FTK_AMBank(regid,subid); + // create the road output module, module have to be created before the setNBanks call + else if (m_doroadfile) { + // Make an external output file, compatible with the + // standalone version, to store the found roads + FTKRoadFileOutput *ftkoutmodule = new FTKRoadFileOutput(); + if (m_InputFromWrapper) { + log << MSG::INFO << "Write the AM simulation results in an external directory: " << m_roadfilesdir << endmsg; + // if the input format is composed by wrapper files the multi-out option is on + ftkoutmodule->setMultiOut(true); + ftkoutmodule->setOutDir(m_roadfilesdir.c_str()); // test name -> should be changed for any root file name we want + } + else { + log << MSG::INFO << "Write the AM simulation results in an external file: " << m_roadfilepath << endmsg; + ftkoutmodule->setMultiOut(false); + ftkoutmodule->setFileName(m_roadfilepath.c_str()); // test name -> should be changed for any root file name we want + } + m_rfobj.setRoadOutputModule(ftkoutmodule); + } + else { + log << MSG::FATAL << "At least an output method has to be specified" << endmsg; + return StatusCode::FAILURE; } + log << MSG::INFO << "Load banks" << endmsg; - /* if this is set in a TSP simulation also the roads rejected - by the DC mechanism or by the TSP are recorded. In this case - the number of hits is correctly updated to the number of verified - layers */ - curbank->setSaveAllRoads(m_SaveAllRoads); - curbank->setStoreAllSS(m_StoreAllSS); - curbank->setRequireFirst(m_require_first); - curbank->setUseMinimalAMIN(m_useMinimalAMIN); - - // additional adjustments for SCTtrk mode - if (ftkset.getSCTtrkMode()) { - // always require SCTtrk layer in AM matching - curbank->setRequireLast(true); - } + // Set the bank segmentation + m_rfobj.setNBanks(m_nbanks); + m_rfobj.setNsubregions(m_nsubregions); - m_ssmap->setOffsetFraction(m_ss_offset_fraction); - curbank->setSSMap(m_ssmap); - curbank->setSSMapUnused(m_ssmap_unused); - - // set the bad module map path - curbank->setBadSSMapPath(m_badmap_path); - curbank->setBadSSMapPath2(m_badmap_path2); - - // set the reference to the current bank - const string &bankpath = m_patternbankpath[ib]; - - string bankext(""); - - // extract the extension removing eventual trailing number, often added by grid, e.g. file.root.3 - unsigned exlen(0); // start from 0 - for (unsigned ipos=bankpath.size();ipos!=0;--ipos) { // reverse loop over the bank name - if (bankpath[ipos-1]=='.') { - if (exlen>1) { - bankext = bankpath.substr(ipos,exlen); - - log << "Extension: " << bankext << flush; - - // check if this is compatible with a number - bool isValidExt(false); - - for (unsigned jpos=0;jpos!=exlen;++jpos) { - if (! isdigit(bankext[jpos])) { - isValidExt = true; - break; - } - } - - // true if at least 1 character is not a digit - if (isValidExt) { - break; - } - else { - log << " INVALID" << endmsg; - } - } - - bankext = ""; // reset extension - exlen = 0; // the fragment doesn't represent a valid extension, move further - ipos -= 1; // skip one step - } - - // increment the size of the sub-string - exlen += 1; - } // end reverse loop over the bank name - - if (bankext == string("db")) { - if (curbank->readDBBank(bankpath.c_str(), m_bankpatterns[ib], m_BankLevel) < 0) { - delete curbank; - return StatusCode::FAILURE; - } - } else if (bankext == string("root") && !m_CachedBank) { - // use the ROOT routine - if (curbank->readROOTBank(bankpath.c_str(), m_bankpatterns[ib]) < 0 ) { - // error reading the file - delete curbank; - return StatusCode::FAILURE; - } - } else if (bankext == string("root") && m_CachedBank) { - // use the ROOT routine - if (curbank->readROOTBankCache(bankpath.c_str()) < 0) { - // error reading the file - delete curbank; - return StatusCode::FAILURE; - } - } else { - // if the previous check failed try with ASCII file - if (curbank->readASCIIBank(bankpath.c_str(), m_bankpatterns[ib]) < 0) { - // error reading the file - delete curbank; - return StatusCode::FAILURE; - } + // get the bank files and information from the JO + unsigned int nbanks = m_patternbankpath.size(); + log << MSG::INFO << "Loading " << nbanks << " banks" << endmsg; + if (nbanks!=m_bankregion.size() || nbanks!=m_bankpatterns.size() || nbanks!=m_banksubreg.size()) { + log << MSG::FATAL << "Different array property length in bank definitions: " << nbanks << ' ' << m_bankregion.size() << ' ' << m_bankpatterns.size() << endmsg; + return StatusCode::FAILURE; } - // Set the bank this region - m_rfobj.setAMBank(regid, curbank); - } // end configuration banks loop - - log << MSG::INFO << "Initialize the RoadFinder parameters" << endmsg; - m_rfobj.init(); // initialize roadfinder object - - //if (sc.isFailure()) { - // log << MSG::FATAL << "Unexpected problem during the initialization stage" << endmsg; - // return StatusCode::FAILURE; - //} + for (unsigned int ib=0;ib!=nbanks;++ib) { // configuration banks loop + FTK_AMsimulation_base *curbank; + int regid(m_bankregion[ib]); + int subid(m_banksubreg[ib]); + + if (m_useTSPBank) { + // configura a TSP ready bank + FTKTSPBank *tspbank = new FTKTSPBank(regid,subid); + tspbank->setSimulateTSP(m_doTSPSim); + tspbank->setSSMapTSP(m_ssmap_tsp); + tspbank->setTSPMinCoverage(m_minTSPCoverage); + tspbank->setMakeCache(m_doMakeCache); + tspbank->setCachePath(m_CachePath.c_str()); + tspbank->setAMSize(m_setAMSize); + tspbank->setAMSplit(m_setAMSplit); + tspbank->setMaxAMAfterSplit(m_maxAMAfterSplit); + tspbank->setMinDVolOverDNPatt(m_minDVolOverDNPatt); + tspbank->setDCMatchMethod(m_DCMatchMethod); + curbank = tspbank; + } else if(m_useCompressedBank) { + FTK_CompressedAMBank *compressedBank= + new FTK_CompressedAMBank(regid,subid); + compressedBank->setSSMapTSP(m_ssmap_tsp); + curbank=compressedBank; + compressedBank->setCompressionScheme(m_AMcompressionMode); + } else { + // configure a base AM bank + curbank = new FTK_AMBank(regid,subid); + } + + + /* if this is set in a TSP simulation also the roads rejected + by the DC mechanism or by the TSP are recorded. In this case + the number of hits is correctly updated to the number of verified + layers */ + curbank->setSaveAllRoads(m_SaveAllRoads); + curbank->setStoreAllSS(m_StoreAllSS); + curbank->setRequireFirst(m_require_first); + curbank->setUseMinimalAMIN(m_useMinimalAMIN); + + m_ssmap->setOffsetFraction(m_ss_offset_fraction); + curbank->setSSMap(m_ssmap); + curbank->setSSMapUnused(m_ssmap_unused); + + // set the bad module map path + curbank->setBadSSMapPath(m_badmap_path); + curbank->setBadSSMapPath2(m_badmap_path2); + + // set the reference to the current bank + const string &bankpath = m_patternbankpath[ib]; + + string bankext(""); + + // extract the extension removing eventual trailing number, often added by grid, e.g. file.root.3 + unsigned exlen(0); // start from 0 + for (unsigned ipos=bankpath.size();ipos!=0;--ipos) { // reverse loop over the bank name + if (bankpath[ipos-1]=='.') { + if (exlen>1) { + bankext = bankpath.substr(ipos,exlen); + + log << "Extension: " << bankext << flush; + + // check if this is compatible with a number + bool isValidExt(false); + + for (unsigned jpos=0;jpos!=exlen;++jpos) { + if (! isdigit(bankext[jpos])) { + isValidExt = true; + break; + } + } + + // true if at least 1 character is not a digit + if (isValidExt) { + break; + } + else { + log << " INVALID" << endmsg; + } + } + + bankext = ""; // reset extension + exlen = 0; // the fragment doesn't represent a valid extension, move further + ipos -= 1; // skip one step + } + + // increment the size of the sub-string + exlen += 1; + } // end reverse loop over the bank name + + if (bankext == string("db")) { + if (curbank->readDBBank(bankpath.c_str(), m_bankpatterns[ib], m_BankLevel) < 0) { + delete curbank; + return StatusCode::FAILURE; + } + } else if (bankext == string("root") && !m_CachedBank) { + // use the ROOT routine + if (curbank->readROOTBank(bankpath.c_str(), m_bankpatterns[ib]) < 0 ) { + // error reading the file + delete curbank; + return StatusCode::FAILURE; + } + } else if (bankext == string("root") && m_CachedBank) { + // use the ROOT routine + if (curbank->readROOTBankCache(bankpath.c_str()) < 0) { + // error reading the file + delete curbank; + return StatusCode::FAILURE; + } + } else { + // if the previous check failed try with ASCII file + if (curbank->readASCIIBank(bankpath.c_str(), m_bankpatterns[ib]) < 0) { + // error reading the file + delete curbank; + return StatusCode::FAILURE; + } + } + + // Set the bank this region + m_rfobj.setAMBank(regid, curbank); + } // end configuration banks loop + + log << MSG::INFO << "Initialize the RoadFinder parameters" << endmsg; + m_rfobj.init(); // initialize roadfinder object + + //if (sc.isFailure()) { + // log << MSG::FATAL << "Unexpected problem during the initialization stage" << endmsg; + // return StatusCode::FAILURE; + //} - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * StatusCode FTKRoadFinderAlgo::execute() { - - MsgStream log(msgSvc(), name()); - FTKSetup::getFTKSetup().setMsgStream(&log); - FTKLogger::SetLogger(this); - - log << MSG::INFO << "FTKRoadFinderAlgo::execute() start" << endmsg; - - if (m_AutoDisable) { - // if AutoDisable feature is found all the execution driven by road-finder - log << MSG::INFO << "FTKRoadFinderAlgo auto-disable mode, nothing to do" << endmsg; - } - else { - int res = m_rfobj.nextEvent(); - if (res<0) { - log << MSG::WARNING << "No more events to process" << endmsg; - // when all the event are evaluated the auto-disable is enabled - m_AutoDisable = true; + + MsgStream log(msgSvc(), name()); + FTKSetup::getFTKSetup().setMsgStream(&log); + FTKLogger::SetLogger(this); + + log << MSG::INFO << "FTKRoadFinderAlgo::execute() start" << endmsg; + + if (m_AutoDisable) { + // if AutoDisable feature is found all the execution driven by road-finder + log << MSG::INFO << "FTKRoadFinderAlgo auto-disable mode, nothing to do" << endmsg; } - } - - log << MSG::INFO << "FTKRoadFinderAlgo::execute() end" << endmsg; - return StatusCode::SUCCESS; + else { + int res = m_rfobj.nextEvent(); + if (res<0) { + log << MSG::WARNING << "No more events to process" << endmsg; + // when all the event are evaluated the auto-disable is enabled + m_AutoDisable = true; + } + } + + log << MSG::INFO << "FTKRoadFinderAlgo::execute() end" << endmsg; + return StatusCode::SUCCESS; } @@ -629,11 +619,10 @@ StatusCode FTKRoadFinderAlgo::finalize() { } void FTKRoadFinderAlgo::PostMessage() { - int fType=getLoggerMsgType(); - if(fType==0) ATH_MSG_FATAL(getLoggerMsg()); - else if(fType==1) ATH_MSG_ERROR(getLoggerMsg()); - else if(fType==2) ATH_MSG_WARNING(getLoggerMsg()); - else if(fType==3) ATH_MSG_INFO(getLoggerMsg()); - else if(fType==4) ATH_MSG_DEBUG(getLoggerMsg()); + int fType=getLoggerMsgType(); + if(fType==0) ATH_MSG_FATAL(getLoggerMsg()); + else if(fType==1) ATH_MSG_ERROR(getLoggerMsg()); + else if(fType==2) ATH_MSG_WARNING(getLoggerMsg()); + else if(fType==3) ATH_MSG_INFO(getLoggerMsg()); + else if(fType==4) ATH_MSG_DEBUG(getLoggerMsg()); } - diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadStream.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadStream.cxx index 7ed0fbacf51..b3d6428ce20 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadStream.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKRoadStream.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #include "TrigFTKSim/FTKRoadStream.h" @@ -10,157 +10,159 @@ using namespace std; FTKRoadStream:: FTKRoadStream() : - m_run_number(0ul), m_event_number(0ul), - m_nroads(0), m_nroads_4L(0), - m_nroads_tot(0), m_nroads_good(), m_nroads_maj(0), m_nroads_maj_good(0), - m_ssmaps(), - m_nao_nhits_tot(0), m_nao_nclus_tot(0), - m_nao_nroads_am(0), m_nao_nroads_am_complete(0), m_nao_nroads_am_misspix(0), m_nao_nroads_am_misssct(0), - m_nao_nroads_mod(0), m_nao_nroads_rw(0), - m_evtidx(0x0), m_barcode(0x0), m_frac(0x0), - m_fit_list() + m_run_number(0ul), m_event_number(0ul), + m_nroads(0), + m_nroads_tot(0), m_nroads_good(), m_nroads_maj(0), m_nroads_maj_good(0), + m_ssmaps(), + m_nao_nhits_tot(0), m_nao_nclus_tot(0), + m_nao_nroads_am(0), m_nao_nroads_am_complete(0), m_nao_nroads_am_misspix(0), m_nao_nroads_am_misssct(0), + m_nao_nroads_mod(0), m_nao_nroads_rw(0), + m_evtidx(0x0), m_barcode(0x0), m_frac(0x0), + m_fit_list() { - m_roads = new TClonesArray( "FTKRoad" ,10000); + m_roads = new TClonesArray( "FTKRoad" ,10000); } FTKRoadStream:: ~FTKRoadStream() { - delete m_roads; + delete m_roads; } /** initialize the ssmaps */ void FTKRoadStream::init( int nplanes) { - m_ssmaps.clear(); - m_ssmaps.reserve(nplanes); - for ( int i=0;i!=nplanes;++i) - m_ssmaps.push_back(map< int ,FTKSS>()); + m_ssmaps.clear(); + m_ssmaps.reserve(nplanes); + for ( int i=0;i!=nplanes;++i) + m_ssmaps.push_back(map< int ,FTKSS>()); } void FTKRoadStream::clear() { - m_run_number = 0ul; - m_event_number = 0ul; + m_run_number = 0ul; + m_event_number = 0ul; - m_nroads = 0; - m_nroads_4L = 0; - m_roads->Delete(); + m_nroads = 0; + m_roads->Delete(); - vector< map< int,FTKSS> >::iterator imap = m_ssmaps.begin(); - for (;imap!=m_ssmaps.end();++imap) { - (*imap).clear(); - } - - m_ssmaps_unused.clear(); + vector< map< int,FTKSS> >::iterator imap = m_ssmaps.begin(); + for (;imap!=m_ssmaps.end();++imap) { + (*imap).clear(); + } + + m_ssmaps_unused.clear(); - m_roadIdMap.clear(); + m_roadIdMap.clear(); } -FTKRoad* FTKRoadStream:: addRoad( const FTKRoad &road) +FTKRoad* FTKRoadStream::addRoad( const FTKRoad &road) { - // create a new element into the clones array - FTKRoad* returnme = new ((*m_roads)[m_nroads++]) FTKRoad(road); - m_roadIdMap[std::make_pair< int, int>(road.getRoadID(),road.getBankID())] = m_nroads-1; - return returnme; + // create a new element into the clones array + FTKRoad* returnme = new ((*m_roads)[m_nroads++]) FTKRoad(road); + m_roadIdMap[std::make_pair< int, int>(road.getRoadID(),road.getBankID())] = m_nroads-1; + return returnme; } -FTKRoad* FTKRoadStream:: getRoad( int ipos) const + +FTKRoad* FTKRoadStream::getRoad( int ipos) const { - assert(ipos>=0); - if (ipos>=m_nroads) return 0; - else return (FTKRoad*)m_roads->At(ipos); + assert(ipos>=0); + if (ipos>=m_nroads) return 0; + else return (FTKRoad*)m_roads->At(ipos); } + /** this method sorts the roads according the ordering method used in the FTK_AMBank::road_warrior(). - */ +*/ void FTKRoadStream::sortRoads() { - m_roads->Sort(); - buildRoadMap(); + m_roads->Sort(); + buildRoadMap(); } /** remove a road, by position, from the list of the roads */ void FTKRoadStream::removeRoad( int pos) { - assert(pos>=0); - FTKRoad* tmproad = (FTKRoad*)m_roads->At(pos); - if( tmproad && m_roadIdMap.size() ) { - std::map< std::pair< int ,int >, int >::iterator it = m_roadIdMap.find( std::make_pair(tmproad->getRoadID(),tmproad->getBankID())); - if( it != m_roadIdMap.end() ) - m_roadIdMap.erase(it); - } - m_roads->RemoveAt(pos); + assert(pos>=0); + FTKRoad* tmproad = (FTKRoad*)m_roads->At(pos); + if( tmproad && m_roadIdMap.size() ) { + std::map< std::pair< int ,int >, int >::iterator it = m_roadIdMap.find( std::make_pair(tmproad->getRoadID(),tmproad->getBankID())); + if( it != m_roadIdMap.end() ) + m_roadIdMap.erase(it); + } + m_roads->RemoveAt(pos); } /** compress the TClonesArray to keep the occupancy low */ void FTKRoadStream::optimize() { - m_roads->Compress(); - m_nroads = m_roads->GetEntries(); - buildRoadMap(); -} + m_roads->Compress(); + m_nroads = m_roads->GetEntries(); + buildRoadMap(); +} /** this method, passing a road ID and a bank ID, return the ID of the corresponding road. If it doesn't exist return -1 */ int FTKRoadStream::findRoad( int roadid, int bankid) { - if( !m_roadIdMap.size() ) - buildRoadMap(); + if( !m_roadIdMap.size() ) + buildRoadMap(); - std::map< std::pair< int, int>, int >::iterator it = m_roadIdMap.find( std::make_pair(roadid,bankid)); - if( it != m_roadIdMap.end() ) - return it->second; - else - return -1; + std::map< std::pair< int, int>, int >::iterator it = m_roadIdMap.find( std::make_pair(roadid,bankid)); + if( it != m_roadIdMap.end() ) + return it->second; + else + return -1; } + void FTKRoadStream::addSS( int plane,const int ssid, const FTKSS &ss) { - // map for this plane - map< int,FTKSS> &imap = m_ssmaps[plane]; - // find this ss is in the bank - map< int,FTKSS>::iterator item = imap.find(ssid); - if (item==imap.end()) { // not found - imap[ssid] = ss; - } - else { - // add a counter of the connected roads - // TODO - } + // map for this plane + map< int,FTKSS> &imap = m_ssmaps[plane]; + // find this ss is in the bank + map< int,FTKSS>::iterator item = imap.find(ssid); + if (item==imap.end()) { // not found + imap[ssid] = ss; + } + else { + // add a counter of the connected roads + // TODO + } } void FTKRoadStream::addUnusedSS( int plane,const int ssid, const FTKSS &ss) { - // search if the plane is in the list - map< int, map< int ,FTKSS> >::iterator issmap = m_ssmaps_unused.find(plane); - if (issmap == m_ssmaps_unused.end()) { - // first SS for this plane, create the map for this plane - m_ssmaps_unused[plane] = map< int ,FTKSS>(); - issmap = m_ssmaps_unused.find(plane); - } - - // map for this plane - map< int,FTKSS> &imap = (*issmap).second; - - // find this ss is in the bank - map< int,FTKSS>::iterator item = imap.find(ssid); - if (item==imap.end()) { // not found - imap[ssid] = ss; - } - else { - // add a counter of the connected roads - // TODO - } + // search if the plane is in the list + map< int, map< int ,FTKSS> >::iterator issmap = m_ssmaps_unused.find(plane); + if (issmap == m_ssmaps_unused.end()) { + // first SS for this plane, create the map for this plane + m_ssmaps_unused[plane] = map< int ,FTKSS>(); + issmap = m_ssmaps_unused.find(plane); + } + + // map for this plane + map< int,FTKSS> &imap = (*issmap).second; + + // find this ss is in the bank + map< int,FTKSS>::iterator item = imap.find(ssid); + if (item==imap.end()) { // not found + imap[ssid] = ss; + } + else { + // add a counter of the connected roads + // TODO + } } @@ -168,60 +170,60 @@ void FTKRoadStream::addUnusedSS( int plane,const int ssid, const FTKSS &ss) and hits found in one event for a given bank */ void FTKRoadStream::Print( bool printCoords) { - cout << "*** Run/Event " << m_run_number << "/" << m_event_number << " ***" << endl; - - cout << "*** Roads: ***" << endl; - for ( int ir=0;ir(m_roads->At(ir)); - if (tmpr) cout << (*tmpr) << endl; - } - cout << endl; - - cout << "*** Super-Strips ***" << endl; - vector< map< int,FTKSS> >::iterator ipl = m_ssmaps.begin(); - if (ipl==m_ssmaps.end()&&m_nroads>0) { - cerr << "*** no roads found" << endl; - } - - for ( int npl=0;ipl!=m_ssmaps.end();++ipl,++npl) { // plane loop - map< int ,FTKSS>::iterator item = (*ipl).begin(); - cout << "Layer " << setw(2) << npl << ": "; - for(;item!=(*ipl).end();++item) { // hits loop - cout << setw(9) << (*item).first; - // print coordinates in each superstrip - if (printCoords) { - std::cout << "{" ; - const std::vector& hits = (*item).second.getHits(); - for (unsigned int ii=0;ii >::iterator iupl = m_ssmaps_unused.begin(); - for ( int npl=0;iupl!=m_ssmaps_unused.end();++iupl,++npl) { // plane loop - map< int ,FTKSS>::iterator item = (*iupl).second.begin(); - cout << "Ignored Layer " << setw(2) << (*iupl).first << '(' << npl << "): "; - for(;item!=(*iupl).second.end();++item) { // hits loop - cout << setw(9) << (*item).first; - // print coordinates in each superstrip - if (printCoords) { - std::cout << "{" ; - const std::vector& hits = (*item).second.getHits(); - for (unsigned int ii=0;ii(m_roads->At(ir)); + if (tmpr) cout << (*tmpr) << endl; + } + cout << endl; + + cout << "*** Super-Strips ***" << endl; + vector< map< int,FTKSS> >::iterator ipl = m_ssmaps.begin(); + if (ipl==m_ssmaps.end()&&m_nroads>0) { + cerr << "*** no roads found" << endl; + } + + for ( int npl=0;ipl!=m_ssmaps.end();++ipl,++npl) { // plane loop + map< int ,FTKSS>::iterator item = (*ipl).begin(); + cout << "Layer " << setw(2) << npl << ": "; + for(;item!=(*ipl).end();++item) { // hits loop + cout << setw(9) << (*item).first; + // print coordinates in each superstrip + if (printCoords) { + std::cout << "{" ; + const std::vector& hits = (*item).second.getHits(); + for (unsigned int ii=0;ii >::iterator iupl = m_ssmaps_unused.begin(); + for ( int npl=0;iupl!=m_ssmaps_unused.end();++iupl,++npl) { // plane loop + map< int ,FTKSS>::iterator item = (*iupl).second.begin(); + cout << "Ignored Layer " << setw(2) << (*iupl).first << '(' << npl << "): "; + for(;item!=(*iupl).second.end();++item) { // hits loop + cout << setw(9) << (*item).first; + // print coordinates in each superstrip + if (printCoords) { + std::cout << "{" ; + const std::vector& hits = (*item).second.getHits(); + for (unsigned int ii=0;iiprepareHits(); - - if (curroad->getDCMatchMode()>0) { - - // offset of the bitmask, required to read the DC mask - unsigned int maskoffset(0); - - // retrive the DC information, obtain for all the layers - unsigned int dcmask = curroad->getDCBitmask(); - - for ( int ipl=0;ipl!=curroad->getNPlanes();++ipl) { // plane loop - // number of DC bits for this layer - unsigned int ndcbits = curroad->getHLID(ipl); - - if (!curroad->hasHitOnLayer(ipl)) { - maskoffset += ndcbits; - continue; - } - - vector hits; - int basessid = curroad->getSSID(ipl); // base full resolution SS for this layer - - // extract DC mask for this layer, reading only the related bits - unsigned int localdcmask = dcmask>>maskoffset & (~(~0<>ibit)&1) nuseddcbits += 1; - } - - // number of combination of SS to read, it is a power of 2 - unsigned int ncombs(1<>ibit)&1) { - // if this is one of the bits masked by the DC, - // copy the given bit content of the combination into the ssid - ssid |= ((icomb>>activepos)&1)<prepareHits(); + + if (curroad->getDCMatchMode()>0) { + + // offset of the bitmask, required to read the DC mask + unsigned int maskoffset(0); + + // retrive the DC information, obtain for all the layers + unsigned int dcmask = curroad->getDCBitmask(); + + for ( int ipl=0;ipl!=curroad->getNPlanes();++ipl) { // plane loop + // number of DC bits for this layer + unsigned int ndcbits = curroad->getHLID(ipl); + + if (!curroad->hasHitOnLayer(ipl)) { + maskoffset += ndcbits; + continue; + } + + vector hits; + int basessid = curroad->getSSID(ipl); // base full resolution SS for this layer + + // extract DC mask for this layer, reading only the related bits + unsigned int localdcmask = dcmask>>maskoffset & (~(~0<>ibit)&1) nuseddcbits += 1; + } + + // number of combination of SS to read, it is a power of 2 + unsigned int ncombs(1<>ibit)&1) { + // if this is one of the bits masked by the DC, + // copy the given bit content of the combination into the ssid + ssid |= ((icomb>>activepos)&1)<getPatternID() << ", " << ipl << " " << basessid << ", " << localdcmask << ", " << ssid << " "; + cout << "# " << curroad->getPatternID() << ", " << ipl << " " << basessid << ", " << localdcmask << ", " << ssid << " "; #endif - // check the SSID and retrieve the hits for the current layer of this road - map< int ,FTKSS>::iterator iss = m_ssmaps[ipl].find(ssid); - if (iss!=m_ssmaps[ipl].end()) { - // hash hits, copy the hits into the current list of hits - // reference the base SS related to the AM level road - FTKSS &curss = (*iss).second; + // check the SSID and retrieve the hits for the current layer of this road + map< int ,FTKSS>::iterator iss = m_ssmaps[ipl].find(ssid); + if (iss!=m_ssmaps[ipl].end()) { + // hash hits, copy the hits into the current list of hits + // reference the base SS related to the AM level road + FTKSS &curss = (*iss).second; #if 0 - cout << 1 << endl; + cout << 1 << endl; #endif - /* copy the hits in this SS in the current roads */ - hits.insert(hits.end(),curss.getHits().begin(),curss.getHits().end()); - } + /* copy the hits in this SS in the current roads */ + hits.insert(hits.end(),curss.getHits().begin(),curss.getHits().end()); + } #if 0 - else { - cout << 0 << endl; - } + else { + cout << 0 << endl; + } #endif - } // end loop over the bit combinations - - static int msgcounter(0); - if (hits.empty()&&msgcounter<100) { - msgcounter += 1; - cerr << "*** No hits found for road while expected in layer " << ipl <<", SSID=" << basessid << ", DC=" << localdcmask << ", Patt# " << curroad->getPatternID() << endl; - } - curroad->addHits(ipl,hits); - - // increment the mask offset going to the next layer - maskoffset += ndcbits; - } // end plane loop - } - else { // no DC matching - for ( int ipl=0;ipl!=curroad->getNPlanes();++ipl) { // plane loop - int ssid = curroad->getSSID(ipl); - - // do we expect hits in this layer? - map< int ,FTKSS>::iterator iss = m_ssmaps[ipl].find(ssid); - // these conditions aren't identical in CM architecture: - // 4L roadwarrior may set a bitmask even though ss container has hits in this plane! - if (iss==m_ssmaps[ipl].end() || curroad->hasHitOnLayer(ipl)== false ) { - // not found - continue ; - } - - - // reference the base SS related to the AM level road - FTKSS &curss = (*iss).second; - - /* copy the hits in this SS in the current roads */ - curss.copyHitsToRoad(curroad,ipl); - } // end plane loop - } + } // end loop over the bit combinations + + static int msgcounter(0); + if (hits.empty()&&msgcounter<100) { + msgcounter += 1; + cerr << "*** No hits found for road while expected in layer " << ipl <<", SSID=" << basessid << ", DC=" << localdcmask << ", Patt# " << curroad->getPatternID() << endl; + } + curroad->addHits(ipl,hits); + + // increment the mask offset going to the next layer + maskoffset += ndcbits; + } // end plane loop + } + else { // no DC matching + for ( int ipl=0;ipl!=curroad->getNPlanes();++ipl) { // plane loop + int ssid = curroad->getSSID(ipl); + + // do we expect hits in this layer? + map< int ,FTKSS>::iterator iss = m_ssmaps[ipl].find(ssid); + // these conditions aren't identical in CM architecture: + // 4L roadwarrior may set a bitmask even though ss container has hits in this plane! + if (iss==m_ssmaps[ipl].end() || curroad->hasHitOnLayer(ipl)== false ) { + // not found + continue ; + } + + + // reference the base SS related to the AM level road + FTKSS &curss = (*iss).second; + + /* copy the hits in this SS in the current roads */ + curss.copyHitsToRoad(curroad,ipl); + } // end plane loop + } } @@ -344,57 +346,57 @@ void FTKRoadStream::attachHits( int roadid) composed using attachHits() method */ void FTKRoadStream::detachHits( int ipos) { - FTKRoad *curroad = getRoad(ipos); - assert(curroad); - curroad->clearHits(); + FTKRoad *curroad = getRoad(ipos); + assert(curroad); + curroad->clearHits(); } /** build the kd Tree */ FTKRoadKDTree *FTKRoadStream:: buildKDTree() { - - // if the list of the road is empty return 0 - if (m_nroads==0) return 0; - // the first road is the head node - FTKRoad *head = getRoad(0); - FTKRoadKDTree *kd_tree = new FTKRoadKDTree(head->getNPlanes(),head,0); + // if the list of the road is empty return 0 + if (m_nroads==0) return 0; - for ( int iroad=1;iroad!=m_nroads;++iroad) { - kd_tree->addNode(getRoad(iroad),iroad); - } + // the first road is the head node + FTKRoad *head = getRoad(0); + FTKRoadKDTree *kd_tree = new FTKRoadKDTree(head->getNPlanes(),head,0); - return kd_tree; + for ( int iroad=1;iroad!=m_nroads;++iroad) { + kd_tree->addNode(getRoad(iroad),iroad); + } + + return kd_tree; } void FTKRoadStream::buildRoadMap() { - m_roadIdMap.clear(); - for ( int iroad =0;iroad!=m_nroads;++iroad) { // loop over the roads - FTKRoad *cur_road = getRoad(iroad); + m_roadIdMap.clear(); + for ( int iroad =0;iroad!=m_nroads;++iroad) { // loop over the roads + FTKRoad *cur_road = getRoad(iroad); - if (!cur_road) continue ; // a null pointer is possible - m_roadIdMap[std::make_pair(cur_road->getRoadID(),cur_road->getBankID())] = iroad; - } + if (!cur_road) continue ; // a null pointer is possible + m_roadIdMap[std::make_pair(cur_road->getRoadID(),cur_road->getBankID())] = iroad; + } } const FTKSS& FTKRoadStream::getUnusedSS( int pl, int id) const { - static FTKSS empty; - - // search for the plane - map< int , map< int ,FTKSS> >::const_iterator iussplane = m_ssmaps_unused.find(pl); - if (iussplane!=m_ssmaps_unused.end()) { - // search for the SS id - map< int,FTKSS>::const_iterator iuss = (*iussplane).second.find(id); - if (iuss!=(*iussplane).second.end()) { - return (*iuss).second; + static FTKSS empty; + + // search for the plane + map< int , map< int ,FTKSS> >::const_iterator iussplane = m_ssmaps_unused.find(pl); + if (iussplane!=m_ssmaps_unused.end()) { + // search for the SS id + map< int,FTKSS>::const_iterator iuss = (*iussplane).second.find(id); + if (iuss!=(*iussplane).second.end()) { + return (*iuss).second; + } } - } - return empty; + return empty; } @@ -405,132 +407,132 @@ const FTKSS& FTKRoadStream::getUnusedSS( int pl, int id) const combination */ int FTKRoadStream::computeUnusedSegmentsTruthList() { - // get the number of unused planes with hits - int nuplanes = getNUnusedPlanes(); - - // cut the streams with less than 3 unused layer with hits - if (nuplanes<3) return 0; - - // iterators to loop to fill the combinations - int *plid = new int [nuplanes]; - vector *hitlist = new vector[nuplanes]; - vector::const_iterator *startlist = new vector::const_iterator[nuplanes]; - vector::const_iterator *position = new vector::const_iterator[nuplanes]; - vector::const_iterator *endlist = new vector::const_iterator[nuplanes]; - - - std::map< int, std::map< int ,FTKSS> >::const_iterator iuplane = m_ssmaps_unused.begin(); - std::map< int, std::map< int ,FTKSS> >::const_iterator iuplane_end = m_ssmaps_unused.end(); - - - // compute the number of combinations - int ncombs(1); - int ip(0); - for (;iuplane!=iuplane_end;++iuplane,++ip) { - plid[ip] = (*iuplane).first; - std::map< int,FTKSS>::const_iterator iss = (*iuplane).second.begin(); - std::map< int,FTKSS>::const_iterator iss_end = (*iuplane).second.end(); - for (;iss!=iss_end;++iss) { - const FTKSS &ss = (*iss).second; - hitlist[ip].insert(hitlist[ip].end(), - ss.getHits().begin(),ss.getHits().end()); + // get the number of unused planes with hits + int nuplanes = getNUnusedPlanes(); + + // cut the streams with less than 3 unused layer with hits + if (nuplanes<3) return 0; + + // iterators to loop to fill the combinations + int *plid = new int [nuplanes]; + vector *hitlist = new vector[nuplanes]; + vector::const_iterator *startlist = new vector::const_iterator[nuplanes]; + vector::const_iterator *position = new vector::const_iterator[nuplanes]; + vector::const_iterator *endlist = new vector::const_iterator[nuplanes]; + + + std::map< int, std::map< int ,FTKSS> >::const_iterator iuplane = m_ssmaps_unused.begin(); + std::map< int, std::map< int ,FTKSS> >::const_iterator iuplane_end = m_ssmaps_unused.end(); + + + // compute the number of combinations + int ncombs(1); + int ip(0); + for (;iuplane!=iuplane_end;++iuplane,++ip) { + plid[ip] = (*iuplane).first; + std::map< int,FTKSS>::const_iterator iss = (*iuplane).second.begin(); + std::map< int,FTKSS>::const_iterator iss_end = (*iuplane).second.end(); + for (;iss!=iss_end;++iss) { + const FTKSS &ss = (*iss).second; + hitlist[ip].insert(hitlist[ip].end(), + ss.getHits().begin(),ss.getHits().end()); + } + startlist[ip] = position[ip] = hitlist[ip].begin(); + endlist[ip] = hitlist[ip].end(); + if (hitlist[ip].size()>0) + ncombs *= hitlist[ip].size(); } - startlist[ip] = position[ip] = hitlist[ip].begin(); - endlist[ip] = hitlist[ip].end(); - if (hitlist[ip].size()>0) - ncombs *= hitlist[ip].size(); - } - - if (m_evtidx) { - delete [] m_evtidx; - delete [] m_barcode; - delete [] m_frac; - } - m_evtidx = new long int [ncombs]; - m_barcode = new long int [ncombs]; - m_frac = new float[ncombs]; - - for ( int icomb=0;icomb!=ncombs;++icomb) { // combination loop - vector tmpmtv(nuplanes); - - for ( int iup=0;iup!=nuplanes;++iup) { // plane loop - // get the truth for the current hit - MultiTruth this_mt( (*position[iup]).getTruth() ); - // equalize multiple truths - this_mt.assign_equal_normalization(); - // add in the temporary list - tmpmtv.push_back(this_mt); - } // end plane loop - // build the final truth accumating the partial results - MultiTruth mt( std::accumulate(tmpmtv.begin(),tmpmtv.end(),MultiTruth(),MultiTruth::AddAccumulator()) ); - - MultiTruth::Barcode tbarcode; - MultiTruth::Weight tfrac(0); - mt.best(tbarcode,tfrac); - m_evtidx[icomb] = tbarcode.first; - m_barcode[icomb] = tbarcode.second; - m_frac[icomb] = tfrac; - - /* compose the next combination */ - for ( int iup=0;iup!=nuplanes;++iup) { - if (startlist[iup]==endlist[iup]) // empty hit - continue ; - - // move to the next - ++position[iup]; - if (position[iup]!=endlist[iup]) { - // possible combination - break ; - } - else { - // restart on this plane, move the next plane - position[iup] = startlist[iup]; - } + if (m_evtidx) { + delete [] m_evtidx; + delete [] m_barcode; + delete [] m_frac; } - } // end combination loop + m_evtidx = new long int [ncombs]; + m_barcode = new long int [ncombs]; + m_frac = new float[ncombs]; + + for ( int icomb=0;icomb!=ncombs;++icomb) { // combination loop + vector tmpmtv(nuplanes); + + for ( int iup=0;iup!=nuplanes;++iup) { // plane loop + // get the truth for the current hit + MultiTruth this_mt( (*position[iup]).getTruth() ); + // equalize multiple truths + this_mt.assign_equal_normalization(); + // add in the temporary list + tmpmtv.push_back(this_mt); + } // end plane loop + + // build the final truth accumating the partial results + MultiTruth mt( std::accumulate(tmpmtv.begin(),tmpmtv.end(),MultiTruth(),MultiTruth::AddAccumulator()) ); + + MultiTruth::Barcode tbarcode; + MultiTruth::Weight tfrac(0); + mt.best(tbarcode,tfrac); + m_evtidx[icomb] = tbarcode.first; + m_barcode[icomb] = tbarcode.second; + m_frac[icomb] = tfrac; + + /* compose the next combination */ + for ( int iup=0;iup!=nuplanes;++iup) { + if (startlist[iup]==endlist[iup]) // empty hit + continue ; + + // move to the next + ++position[iup]; + if (position[iup]!=endlist[iup]) { + // possible combination + break ; + } + else { + // restart on this plane, move the next plane + position[iup] = startlist[iup]; + } + } + } // end combination loop - delete [] plid; - delete [] hitlist; - delete [] startlist; - delete [] position; - delete [] endlist; + delete [] plid; + delete [] hitlist; + delete [] startlist; + delete [] position; + delete [] endlist; - return ncombs; + return ncombs; } FTKRoadStream::FTKRoadCursor:: FTKRoadCursor() : - TObject(), m_stream(0x0), m_road(0x0), m_position(-1), m_first( false ) + TObject(), m_stream(0x0), m_road(0x0), m_position(-1), m_first( false ) {} /** method used to iteratote in the road */ FTKRoadStream::FTKRoadCursor:: FTKRoadCursor(FTKRoadStream *stream, - FTKRoad *road, int pos, - bool init) : - TObject(), m_stream(stream), m_road(road), m_position(pos), m_first(init) + FTKRoad *road, int pos, + bool init) : + TObject(), m_stream(stream), m_road(road), m_position(pos), m_first(init) { - // nothing to do + // nothing to do } FTKRoadStream::FTKRoadCursor:: ~FTKRoadCursor() {} FTKRoadStream::FTKRoadCursor:: FTKRoadCursor( const FTKRoadCursor ©) : - TObject(copy), - m_stream(copy.m_stream), - m_road(copy.m_road), m_position(copy.m_position), - m_first(copy.m_first) + TObject(copy), + m_stream(copy.m_stream), + m_road(copy.m_road), m_position(copy.m_position), + m_first(copy.m_first) {} FTKRoad* FTKRoadStream::FTKRoadCursor:: operator()() { - if (m_first) { - if (m_position>0) m_stream->detachHits(m_position-1); - m_stream->attachHits(m_position); - } - return m_road; + if (m_first) { + if (m_position>0) m_stream->detachHits(m_position-1); + m_stream->attachHits(m_position); + } + return m_road; } @@ -539,46 +541,46 @@ FTKRoad* FTKRoadStream::FTKRoadCursor:: operator()() the fitting */ unsigned FTKRoadStream::prepareFitList() { - // initize the list - m_fit_list.clear(); + // initize the list + m_fit_list.clear(); - for ( int iroad=0;iroad!=m_nroads;++iroad) { // AM road loop - // get the pointer the AM road at this position - FTKRoad *curAMRoad = getRoad(iroad); - curAMRoad->setAMRoad(curAMRoad); // reflecting + for ( int iroad=0;iroad!=m_nroads;++iroad) { // AM road loop + // get the pointer the AM road at this position + FTKRoad *curAMRoad = getRoad(iroad); + curAMRoad->setAMRoad(curAMRoad); // reflecting - if (curAMRoad->getNSubRoads()==0) { - // add the AM road to the list - m_fit_list.push_back(FTKRoadCursor( this ,curAMRoad,iroad, true)); - } - else { - // if there are sub-roads search for the first at the lowest level - expandSubRoads(curAMRoad,curAMRoad,iroad, true ); - } - } // end AM road loop + if (curAMRoad->getNSubRoads()==0) { + // add the AM road to the list + m_fit_list.push_back(FTKRoadCursor( this ,curAMRoad,iroad, true)); + } + else { + // if there are sub-roads search for the first at the lowest level + expandSubRoads(curAMRoad,curAMRoad,iroad, true ); + } + } // end AM road loop - // initialize the iterator - m_fit_iter = m_fit_list.begin(); + // initialize the iterator + m_fit_iter = m_fit_list.begin(); - // return the begin iterator - return m_fit_list.size(); + // return the begin iterator + return m_fit_list.size(); } /** return the current road and move the cursor to the next road */ FTKRoad* FTKRoadStream:: fetchRoad() { - FTKRoad *res = 0x0; - if (m_fit_iter!=m_fit_list.end()) { - res = (*m_fit_iter)(); - ++m_fit_iter; - } - else if (m_nroads>0) { - // clean the last road, if there are roads - detachHits(m_nroads-1); - } - - return res; + FTKRoad *res = 0x0; + if (m_fit_iter!=m_fit_list.end()) { + res = (*m_fit_iter)(); + ++m_fit_iter; + } + else if (m_nroads>0) { + // clean the last road, if there are roads + detachHits(m_nroads-1); + } + + return res; } @@ -587,21 +589,21 @@ FTKRoad* FTKRoadStream:: fetchRoad() void FTKRoadStream::expandSubRoads(FTKRoad *AMroad, FTKRoad *uproad, int position, bool _first) { - // true if the road is the one that has to populate the hits for the group - bool first(_first); + // true if the road is the one that has to populate the hits for the group + bool first(_first); - for ( int iroad=0;iroad!=uproad->getNSubRoads();++iroad) { // sub-roads loop - FTKRoad *curroad = uproad->getSubRoad(iroad); - // set the AM road temporary field - curroad->setAMRoad(AMroad); + for ( int iroad=0;iroad!=uproad->getNSubRoads();++iroad) { // sub-roads loop + FTKRoad *curroad = uproad->getSubRoad(iroad); + // set the AM road temporary field + curroad->setAMRoad(AMroad); - if (curroad->getNSubRoads()==0) { - m_fit_list.push_back(FTKRoadCursor( this ,curroad,position,first)); - first = false ; - } - else { - expandSubRoads(AMroad,curroad,position,first); - first = false ; - } - } // end sub-roads loop + if (curroad->getNSubRoads()==0) { + m_fit_list.push_back(FTKRoadCursor( this ,curroad,position,first)); + first = false ; + } + else { + expandSubRoads(AMroad,curroad,position,first); + first = false ; + } + } // end sub-roads loop } diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKSetup.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKSetup.cxx index 06be1e69f3b..ff040d83b76 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKSetup.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKSetup.cxx @@ -22,24 +22,24 @@ MsgStream* FTKSetup::m_log(0x0); FTKSetup::FTKSetup() : - m_BarrelOnly(0), m_SCTtrkMode(0), m_IBLMode(0), m_ITkMode(false), m_verbosity(0), - m_tot_events(0), m_EnableFTKSim(0), m_RawMode(1), - m_SectorsAsPatterns(0), - m_MaxMissingPlanes(1), m_MaskLayers(0), m_RoadWarrior(1), - m_KeepRemoved(0), m_HWModeSS(0), m_event(-1), m_MaxMissingSctPairs(0), - m_restrictSctPairLayer(0), m_restrictSctPairModule(0), - m_usage_ncalls(0),m_fixEndcapL0(false) + m_BarrelOnly(0), m_IBLMode(0), m_ITkMode(false), m_verbosity(0), + m_tot_events(0), m_EnableFTKSim(0), m_RawMode(1), + m_SectorsAsPatterns(0), + m_MaxMissingPlanes(1), m_MaskLayers(0), m_RoadWarrior(1), + m_KeepRemoved(0), m_HWModeSS(0), m_event(-1), m_MaxMissingSctPairs(0), + m_restrictSctPairLayer(0), m_restrictSctPairModule(0), + m_usage_ncalls(0),m_fixEndcapL0(false) { - //m_pid = getpid(); - //cout << "FTK Framework created (PID " << m_pid << ")" << endl; - //gettimeofday(&m_starttime,0); - //cout << "Start time " << m_starttime.tv_sec << " sec" << endl; + //m_pid = getpid(); + //cout << "FTK Framework created (PID " << m_pid << ")" << endl; + //gettimeofday(&m_starttime,0); + //cout << "Start time " << m_starttime.tv_sec << " sec" << endl; } FTKSetup::~FTKSetup() { - // todo + // todo } /** this method print a message with the usage statistic of the @@ -47,137 +47,137 @@ FTKSetup::~FTKSetup() and their results can depend by the kernel configuration */ void FTKSetup::usageStat(const char *header /* =0 */) { - // collect all the information from the proc file - ostringstream pcpuname; - pcpuname << "/proc/" << m_pid << "/stat" << ends; - ifstream cpuinfo(pcpuname.str().c_str()); - // prepare the variables to completely parse /proc/[pid]/stat file - int pid; - cpuinfo >> pid; - string command; - cpuinfo >> command; - char state; - cpuinfo >> state; - int ppid; - cpuinfo >> ppid; - int pgrp; - cpuinfo >> pgrp; - int session; - cpuinfo >> session; - int terminal; - cpuinfo >> terminal; - int tpgid; - cpuinfo >> tpgid; - unsigned int flags; - cpuinfo >> flags; - unsigned long int minflt; - cpuinfo >> minflt; - unsigned long int cminflt; - cpuinfo >> cminflt; - unsigned long int maxflt; - cpuinfo >> maxflt; - unsigned long int cmaxflt; - cpuinfo >> cmaxflt; - unsigned long int utime; - cpuinfo >> utime; - unsigned long int stime; - cpuinfo >> stime; - long int cutime; - cpuinfo >> cutime; - long int cstime; - cpuinfo >> cstime; - long int priority; - cpuinfo >> priority; - long int nice; - cpuinfo >> nice; - long int num_threads; - cpuinfo >> num_threads; - long int itrealvalue; - cpuinfo >> itrealvalue; - long long int starttime; - cpuinfo >> starttime; - unsigned long long int vsize; - cpuinfo >> vsize; - unsigned long long int rss; - cpuinfo >> rss; - unsigned long long int rsslim; - cpuinfo >> rsslim; - unsigned long int startcode; - cpuinfo >> startcode; - unsigned long int endcode; - cpuinfo >> endcode; - unsigned long int startstack; - cpuinfo >> startstack; - unsigned long int kstkesp; - cpuinfo >> kstkesp; - unsigned long int kstkeip; - cpuinfo >> kstkeip; - unsigned long int signal; - cpuinfo >> signal; - unsigned long int blocked; - cpuinfo >> blocked; - unsigned long int sigignore; - cpuinfo >> sigignore; - unsigned long int sigcatch; - cpuinfo >> sigcatch; - unsigned long int wchan; - cpuinfo >> wchan; - unsigned long int nswap; - cpuinfo >> nswap; - unsigned long int cnswap; - cpuinfo >> cnswap; - int exit_signal; - cpuinfo >> exit_signal; - int processor; - cpuinfo >> processor; - unsigned int rt_priority; - cpuinfo >> rt_priority; - unsigned int policy; - cpuinfo >> policy; - unsigned long long int delayacct; - cpuinfo >> delayacct; - unsigned long int guest_time; - cpuinfo >> guest_time; - long int cguest_time; - cpuinfo >> cguest_time; - cpuinfo.close(); - - // get the current time - struct timeval curtime; - gettimeofday(&curtime,0); - - /* evaluate the time needed - PS there is a possible issue if time is changed during the - execution, i.e. if an ntpd server is used but is not - a relevand problem */ - int realsec = curtime.tv_sec-m_starttime.tv_sec; - // the microsendo as converted to be compatible with the proc units (1/100) - int realcsec = (curtime.tv_usec-m_starttime.tv_usec)/10000; - - ++m_usage_ncalls; - - // Comment out to make Coverity happy - // if (!cpuinfo&0) { - // cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Error occurred reading the file statistic, skipped" << endl; - // return; - // } - - cerr << endl; - if (header) { - cerr << "USG[" << setw(2) << m_usage_ncalls << "]::" << header << endl; - } - - const unsigned long int MBunit = 1048576; - cerr << "USG[" << setw(2) << m_usage_ncalls << "]::State " << state << endl; - cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Usr Time " << utime/100. << " sec"<< endl; - cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Sys Time " << stime/100. << " sec"<< endl; - cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Real Time " << realsec+0.01*realcsec << " sec" << endl; - if (realsec>1) - cerr << "USG[" << setw(2) << m_usage_ncalls << "]::CPU eff " << static_cast(utime+stime)/realsec << " %" << endl; - cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Vir Mem " << vsize/MBunit << " MB" << endl; - cerr << "USG[" << setw(2) << m_usage_ncalls << "]::RSS Mem " << rss/MBunit << " MB" << endl; - cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Max Mem " << rsslim/MBunit << " MB" << endl;; - cerr << endl; + // collect all the information from the proc file + ostringstream pcpuname; + pcpuname << "/proc/" << m_pid << "/stat" << ends; + ifstream cpuinfo(pcpuname.str().c_str()); + // prepare the variables to completely parse /proc/[pid]/stat file + int pid; + cpuinfo >> pid; + string command; + cpuinfo >> command; + char state; + cpuinfo >> state; + int ppid; + cpuinfo >> ppid; + int pgrp; + cpuinfo >> pgrp; + int session; + cpuinfo >> session; + int terminal; + cpuinfo >> terminal; + int tpgid; + cpuinfo >> tpgid; + unsigned int flags; + cpuinfo >> flags; + unsigned long int minflt; + cpuinfo >> minflt; + unsigned long int cminflt; + cpuinfo >> cminflt; + unsigned long int maxflt; + cpuinfo >> maxflt; + unsigned long int cmaxflt; + cpuinfo >> cmaxflt; + unsigned long int utime; + cpuinfo >> utime; + unsigned long int stime; + cpuinfo >> stime; + long int cutime; + cpuinfo >> cutime; + long int cstime; + cpuinfo >> cstime; + long int priority; + cpuinfo >> priority; + long int nice; + cpuinfo >> nice; + long int num_threads; + cpuinfo >> num_threads; + long int itrealvalue; + cpuinfo >> itrealvalue; + long long int starttime; + cpuinfo >> starttime; + unsigned long long int vsize; + cpuinfo >> vsize; + unsigned long long int rss; + cpuinfo >> rss; + unsigned long long int rsslim; + cpuinfo >> rsslim; + unsigned long int startcode; + cpuinfo >> startcode; + unsigned long int endcode; + cpuinfo >> endcode; + unsigned long int startstack; + cpuinfo >> startstack; + unsigned long int kstkesp; + cpuinfo >> kstkesp; + unsigned long int kstkeip; + cpuinfo >> kstkeip; + unsigned long int signal; + cpuinfo >> signal; + unsigned long int blocked; + cpuinfo >> blocked; + unsigned long int sigignore; + cpuinfo >> sigignore; + unsigned long int sigcatch; + cpuinfo >> sigcatch; + unsigned long int wchan; + cpuinfo >> wchan; + unsigned long int nswap; + cpuinfo >> nswap; + unsigned long int cnswap; + cpuinfo >> cnswap; + int exit_signal; + cpuinfo >> exit_signal; + int processor; + cpuinfo >> processor; + unsigned int rt_priority; + cpuinfo >> rt_priority; + unsigned int policy; + cpuinfo >> policy; + unsigned long long int delayacct; + cpuinfo >> delayacct; + unsigned long int guest_time; + cpuinfo >> guest_time; + long int cguest_time; + cpuinfo >> cguest_time; + cpuinfo.close(); + + // get the current time + struct timeval curtime; + gettimeofday(&curtime,0); + + /* evaluate the time needed + PS there is a possible issue if time is changed during the + execution, i.e. if an ntpd server is used but is not + a relevand problem */ + int realsec = curtime.tv_sec-m_starttime.tv_sec; + // the microsendo as converted to be compatible with the proc units (1/100) + int realcsec = (curtime.tv_usec-m_starttime.tv_usec)/10000; + + ++m_usage_ncalls; + + // Comment out to make Coverity happy + // if (!cpuinfo&0) { + // cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Error occurred reading the file statistic, skipped" << endl; + // return; + // } + + cerr << endl; + if (header) { + cerr << "USG[" << setw(2) << m_usage_ncalls << "]::" << header << endl; + } + + const unsigned long int MBunit = 1048576; + cerr << "USG[" << setw(2) << m_usage_ncalls << "]::State " << state << endl; + cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Usr Time " << utime/100. << " sec"<< endl; + cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Sys Time " << stime/100. << " sec"<< endl; + cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Real Time " << realsec+0.01*realcsec << " sec" << endl; + if (realsec>1) + cerr << "USG[" << setw(2) << m_usage_ncalls << "]::CPU eff " << static_cast(utime+stime)/realsec << " %" << endl; + cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Vir Mem " << vsize/MBunit << " MB" << endl; + cerr << "USG[" << setw(2) << m_usage_ncalls << "]::RSS Mem " << rss/MBunit << " MB" << endl; + cerr << "USG[" << setw(2) << m_usage_ncalls << "]::Max Mem " << rsslim/MBunit << " MB" << endl;; + cerr << endl; } @@ -186,26 +186,26 @@ void FTKSetup::usageStat(const char *header /* =0 */) void FTKSetup::PrintMessage(ftk::message_level_t level, const char *msg) { #ifndef FTK_STANDALONE - if(m_log) { - if (level == ftk::debg) - *m_log << MSG::DEBUG; - else if (level == ftk::warn) - *m_log << MSG::WARNING; - else if (level == ftk::sevr) - *m_log << MSG::FATAL; - else - *m_log << MSG::INFO; - - *m_log << msg << endmsg; - } else { - cout << "(level="<=ftk::sevr) { - throw FTKException(msg); - } + if (level>=ftk::sevr) { + throw FTKException(msg); + } } @@ -213,13 +213,13 @@ void FTKSetup::PrintMessage(ftk::message_level_t level, const char *msg) the error level is over a given threshold */ void FTKSetup::PrintMessageFmt(ftk::message_level_t level, const char *msg,...) { - va_list va; - va_start(va,msg); - vprintf(msg,va); - va_end(va); - fflush(stdout); - - if (level>=ftk::sevr) { - throw FTKException("Runtime error, message provided on stdout"); - } + va_list va; + va_start(va,msg); + vprintf(msg,va); + va_end(va); + fflush(stdout); + + if (level>=ftk::sevr) { + throw FTKException("Runtime error, message provided on stdout"); + } } diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTKTrackFitterAlgo.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTKTrackFitterAlgo.cxx index 1ba04d238f3..9236afcf7b1 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTKTrackFitterAlgo.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTKTrackFitterAlgo.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #include "TrigFTKSim/FTKTrackFitterAlgo.h" @@ -22,592 +22,590 @@ ///////////////////////////////////////////////////////////////////////////// FTKTrackFitterAlgo::FTKTrackFitterAlgo(const std::string& name, ISvcLocator* pSvcLocator) : - AthAlgorithm(name, pSvcLocator), - m_tfpobj(0x0), - m_roadMarketTool("FTK_RoadMarketTool/FTK_RoadMarketTool"), - m_trackOutputTool("FTK_SGTrackOutput/FTK_SGTrackOutput"), - m_trackOutputTool_pre_hw("FTK_SGTrackOutput/FTK_SGTrackOutput_pre_hw"), - m_SecondStageFit(false), - m_IBLMode(0), m_fixEndcapL0(false), - m_ITkMode(false), - m_nbanks(0), m_nsubregions(1), - m_verbosity(0), - m_chi2cut(17), - m_chi2cut_maj(14), - m_chi2cut_vetmaj(-1), - m_chi2dofcutAux(4), - m_chi2dofcutSSB(4), - m_doAuxFW(false), - m_HitWarrior(2), - m_AuxDoctor(false), - m_KeepRejected(0), - m_FitRemoved(0), - m_DoMajority(1), - m_OnePerRoad(0), - m_HWNDiff(3), - m_MaxNcomb(10000), - m_MaxNhitsPerPlane(-1), - m_MaxTrkout(2000000), - m_NoRecoveryNHits(-1), - m_SCTTrkMode(false), - m_loadHWConf_path(""), - m_SSF_TFMode(1), - m_SSF_multiconn(0), - m_SSF_maxnconn(999), - m_SSF_allow_extramiss(0), - m_SSF_check_TR_by(1), - m_SSF_TR_min_eta(1.0), - m_SSF_TR_max_eta(1.4), - m_save_1stStageTrks(false), - m_save_StepByStepTrks(false), - m_doTrackFile(false), - m_addRoads(false), - m_trackfilepath("./"), - m_trackfilename("ftktracks.root"), - m_pmap(0x0),m_pmap_path(),m_pmap_complete(0x0),m_pmapcomplete_path(),m_pmap_unused(0x0),m_pmapunused_path(), - m_modulelut2nd_path(), - m_rmap(0x0), m_rmap_unused(0x0), - m_ssmap(0x0), m_ssmap_unused(0x0), - m_rmap_path(), m_ssmap_path(), m_ssmapunused_path(), - m_AutoDisable(false), - m_PrintSSBConstants(false), - m_dTIBL(-999999) + AthAlgorithm(name, pSvcLocator), + m_tfpobj(0x0), + m_roadMarketTool("FTK_RoadMarketTool/FTK_RoadMarketTool"), + m_trackOutputTool("FTK_SGTrackOutput/FTK_SGTrackOutput"), + m_trackOutputTool_pre_hw("FTK_SGTrackOutput/FTK_SGTrackOutput_pre_hw"), + m_SecondStageFit(false), + m_IBLMode(0), m_fixEndcapL0(false), + m_ITkMode(false), + m_nbanks(0), m_nsubregions(1), + m_verbosity(0), + m_chi2cut(17), + m_chi2cut_maj(14), + m_chi2cut_vetmaj(-1), + m_chi2dofcutAux(4), + m_chi2dofcutSSB(4), + m_doAuxFW(false), + m_HitWarrior(2), + m_AuxDoctor(false), + m_KeepRejected(0), + m_FitRemoved(0), + m_DoMajority(1), + m_OnePerRoad(0), + m_HWNDiff(3), + m_MaxNcomb(10000), + m_MaxNhitsPerPlane(-1), + m_MaxTrkout(2000000), + m_NoRecoveryNHits(-1), + m_loadHWConf_path(""), + m_SSF_TFMode(1), + m_SSF_multiconn(0), + m_SSF_maxnconn(999), + m_SSF_allow_extramiss(0), + m_SSF_check_TR_by(1), + m_SSF_TR_min_eta(1.0), + m_SSF_TR_max_eta(1.4), + m_save_1stStageTrks(false), + m_save_StepByStepTrks(false), + m_doTrackFile(false), + m_addRoads(false), + m_trackfilepath("./"), + m_trackfilename("ftktracks.root"), + m_pmap(0x0),m_pmap_path(),m_pmap_complete(0x0),m_pmapcomplete_path(),m_pmap_unused(0x0),m_pmapunused_path(), + m_modulelut2nd_path(), + m_rmap(0x0), m_rmap_unused(0x0), + m_ssmap(0x0), m_ssmap_unused(0x0), + m_rmap_path(), m_ssmap_path(), m_ssmapunused_path(), + m_AutoDisable(false), + m_PrintSSBConstants(false), + m_dTIBL(-999999) { - declareProperty("SecondStageFit",m_SecondStageFit,"Enable the second-stage fitter code"); - declareProperty("IBLMode",m_IBLMode,"Switch on the IBL layer"); - declareProperty("FixEndCapL0",m_fixEndcapL0, "Fix endcap L0 clustering"); - declareProperty("ITkMode",m_ITkMode,"Use ITk geometry, for Phase-II studies"); - declareProperty("NBanks",m_nbanks); // number of banks - declareProperty("NSubRegions",m_nsubregions); - declareProperty("Chi2Cut",m_chi2cut); - declareProperty("Chi2Cut_Maj",m_chi2cut_maj); - declareProperty("Chi2Cut_VetoMaj",m_chi2cut_vetmaj); - declareProperty("Chi2DofCutAux",m_chi2dofcutAux); - declareProperty("Chi2DofCutSSB",m_chi2dofcutSSB); - declareProperty("doAuxFW", m_doAuxFW); - declareProperty("HitWarrior", m_HitWarrior); - declareProperty("AuxDoctor", m_AuxDoctor); - declareProperty("KeepRejected", m_KeepRejected); - declareProperty("FitRemoved", m_FitRemoved); - declareProperty("DoMajority",m_DoMajority); - declareProperty("OnePerRoad",m_OnePerRoad); - declareProperty("HWNDiff", m_HWNDiff); - declareProperty("MaxNcomb", m_MaxNcomb); - declareProperty("MaxNhitsPerPlane", m_MaxNhitsPerPlane); - declareProperty("MaxTrkout", m_MaxTrkout); - declareProperty("NoRecoveryNHits",m_NoRecoveryNHits); - declareProperty("SCTTrkMode",m_SCTTrkMode); - declareProperty("loadHWConf_path", m_loadHWConf_path); - declareProperty("pmap_path",m_pmap_path); - declareProperty("pmapcomplete_path",m_pmapcomplete_path); - declareProperty("pmapunused_path",m_pmapunused_path); - declareProperty("ModuleLUTPath2nd",m_modulelut2nd_path); - declareProperty("fitconstantspath",m_fitconstantspath,"Array with bank paths"); - declareProperty("fit711constantspath",m_fit711constantspath,"Array with bank paths for 11L"); - declareProperty("sectorpath", m_sectorpath,"Array with sector paths for 11L"); - declareProperty("bankregion",m_bankregion,"Array of regions"); - declareProperty("banksubregion",m_banksubregion,"Array of subregions"); - declareProperty("doTrackFile",m_doTrackFile,"If true the old format file is generated"); - declareProperty("addRoads",m_addRoads); - declareProperty("TrackFileName",m_trackfilename,"Name of the track output file, old format"); - declareProperty("OutDir",m_trackfilepath,"Path of the track output file, old format"); - declareProperty("rmap_path",m_rmap_path); - declareProperty("ssmap_path",m_ssmap_path); - declareProperty("ssmapunused_path",m_ssmapunused_path); - declareProperty("TRACKFITTER_MODE",m_SSF_TFMode); - declareProperty("Save1stStageTrks",m_save_1stStageTrks); - declareProperty("SaveStepByStepTrks",m_save_StepByStepTrks); - declareProperty("SSFMultiConnection",m_SSF_multiconn); - declareProperty("SSFNConnections",m_SSF_maxnconn); - declareProperty("SSFAllowExtraMiss",m_SSF_allow_extramiss); - declareProperty("SSFTRDefn",m_SSF_check_TR_by); - declareProperty("SSFTRMinEta",m_SSF_TR_min_eta); - declareProperty("SSFTRMaxEta",m_SSF_TR_max_eta); - declareProperty("PrintSSBConstants",m_PrintSSBConstants,"Enable SSB constants printing"); - declareProperty("dTIBL",m_dTIBL); + declareProperty("SecondStageFit",m_SecondStageFit,"Enable the second-stage fitter code"); + declareProperty("IBLMode",m_IBLMode,"Switch on the IBL layer"); + declareProperty("FixEndCapL0",m_fixEndcapL0, "Fix endcap L0 clustering"); + declareProperty("ITkMode",m_ITkMode,"Use ITk geometry, for Phase-II studies"); + declareProperty("NBanks",m_nbanks); // number of banks + declareProperty("NSubRegions",m_nsubregions); + declareProperty("Chi2Cut",m_chi2cut); + declareProperty("Chi2Cut_Maj",m_chi2cut_maj); + declareProperty("Chi2Cut_VetoMaj",m_chi2cut_vetmaj); + declareProperty("Chi2DofCutAux",m_chi2dofcutAux); + declareProperty("Chi2DofCutSSB",m_chi2dofcutSSB); + declareProperty("doAuxFW", m_doAuxFW); + declareProperty("HitWarrior", m_HitWarrior); + declareProperty("AuxDoctor", m_AuxDoctor); + declareProperty("KeepRejected", m_KeepRejected); + declareProperty("FitRemoved", m_FitRemoved); + declareProperty("DoMajority",m_DoMajority); + declareProperty("OnePerRoad",m_OnePerRoad); + declareProperty("HWNDiff", m_HWNDiff); + declareProperty("MaxNcomb", m_MaxNcomb); + declareProperty("MaxNhitsPerPlane", m_MaxNhitsPerPlane); + declareProperty("MaxTrkout", m_MaxTrkout); + declareProperty("NoRecoveryNHits",m_NoRecoveryNHits); + declareProperty("loadHWConf_path", m_loadHWConf_path); + declareProperty("pmap_path",m_pmap_path); + declareProperty("pmapcomplete_path",m_pmapcomplete_path); + declareProperty("pmapunused_path",m_pmapunused_path); + declareProperty("ModuleLUTPath2nd",m_modulelut2nd_path); + declareProperty("fitconstantspath",m_fitconstantspath,"Array with bank paths"); + declareProperty("fit711constantspath",m_fit711constantspath,"Array with bank paths for 11L"); + declareProperty("sectorpath", m_sectorpath,"Array with sector paths for 11L"); + declareProperty("bankregion",m_bankregion,"Array of regions"); + declareProperty("banksubregion",m_banksubregion,"Array of subregions"); + declareProperty("doTrackFile",m_doTrackFile,"If true the old format file is generated"); + declareProperty("addRoads",m_addRoads); + declareProperty("TrackFileName",m_trackfilename,"Name of the track output file, old format"); + declareProperty("OutDir",m_trackfilepath,"Path of the track output file, old format"); + declareProperty("rmap_path",m_rmap_path); + declareProperty("ssmap_path",m_ssmap_path); + declareProperty("ssmapunused_path",m_ssmapunused_path); + declareProperty("TRACKFITTER_MODE",m_SSF_TFMode); + declareProperty("Save1stStageTrks",m_save_1stStageTrks); + declareProperty("SaveStepByStepTrks",m_save_StepByStepTrks); + declareProperty("SSFMultiConnection",m_SSF_multiconn); + declareProperty("SSFNConnections",m_SSF_maxnconn); + declareProperty("SSFAllowExtraMiss",m_SSF_allow_extramiss); + declareProperty("SSFTRDefn",m_SSF_check_TR_by); + declareProperty("SSFTRMinEta",m_SSF_TR_min_eta); + declareProperty("SSFTRMaxEta",m_SSF_TR_max_eta); + declareProperty("PrintSSBConstants",m_PrintSSBConstants,"Enable SSB constants printing"); + declareProperty("dTIBL",m_dTIBL); } FTKTrackFitterAlgo::~FTKTrackFitterAlgo() { - // destroy configuration - if (m_ssmap) delete m_ssmap; - if (m_ssmap_unused) delete m_ssmap_unused; - if (m_rmap) delete m_rmap; - if (m_rmap_unused) delete m_rmap_unused; - if (m_pmap) delete m_pmap; - if (m_pmap_unused) delete m_pmap_unused; - if (m_pmap_complete) delete m_pmap_complete; - if (m_tfpobj) delete m_tfpobj; + // destroy configuration + if (m_ssmap) delete m_ssmap; + if (m_ssmap_unused) delete m_ssmap_unused; + if (m_rmap) delete m_rmap; + if (m_rmap_unused) delete m_rmap_unused; + if (m_pmap) delete m_pmap; + if (m_pmap_unused) delete m_pmap_unused; + if (m_pmap_complete) delete m_pmap_complete; + if (m_tfpobj) delete m_tfpobj; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * StatusCode FTKTrackFitterAlgo::initialize(){ - MsgStream log(msgSvc(), name()); - FTKSetup::getFTKSetup().setMsgStream(&log); - log << MSG::INFO << "FTKTrackFitterAlgo::initialize()" << endmsg; - - log << MSG::INFO << "IBLMode value: " << m_IBLMode << endmsg; - FTKSetup::getFTKSetup().setIBLMode(m_IBLMode); - - log << MSG::INFO << "Fix EndcapL0 value: " << m_fixEndcapL0 << endmsg; - FTKSetup::getFTKSetup().setfixEndcapL0(m_fixEndcapL0); - - log << MSG::INFO << "ITkMode value: " << m_ITkMode << endmsg; - FTKSetup::getFTKSetup().setITkMode(m_ITkMode); - - if (m_SecondStageFit) - m_tfpobj = new TrackFitter711; - else - m_tfpobj = new TrackFitter; - - // Look for the main plane-map and set plane map - log << MSG::INFO << "Read the logical layer definitions" << endmsg; - if (m_pmap_path.empty()) { - log << MSG::FATAL << "Main plane map definition missing" << endmsg; - return StatusCode::FAILURE; - } - else { - m_pmap = new FTKPlaneMap(m_pmap_path.c_str()); - if (!(*m_pmap)) { - log << MSG::FATAL << "Error using plane map: " << m_pmap_path << endmsg; - return StatusCode::FAILURE; - } - } + MsgStream log(msgSvc(), name()); + FTKSetup::getFTKSetup().setMsgStream(&log); + log << MSG::INFO << "FTKTrackFitterAlgo::initialize()" << endmsg; + + log << MSG::INFO << "IBLMode value: " << m_IBLMode << endmsg; + FTKSetup::getFTKSetup().setIBLMode(m_IBLMode); + + log << MSG::INFO << "Fix EndcapL0 value: " << m_fixEndcapL0 << endmsg; + FTKSetup::getFTKSetup().setfixEndcapL0(m_fixEndcapL0); - // Look for the unused plane-map - - if(m_SecondStageFit){ + log << MSG::INFO << "ITkMode value: " << m_ITkMode << endmsg; + FTKSetup::getFTKSetup().setITkMode(m_ITkMode); - if (m_pmapunused_path.empty()) { - log << MSG::FATAL << "Unused plane map definition missing" << endmsg; - return StatusCode::FAILURE; + if (m_SecondStageFit) + m_tfpobj = new TrackFitter711; + else + m_tfpobj = new TrackFitter; + + // Look for the main plane-map and set plane map + log << MSG::INFO << "Read the logical layer definitions" << endmsg; + if (m_pmap_path.empty()) { + log << MSG::FATAL << "Main plane map definition missing" << endmsg; + return StatusCode::FAILURE; } else { - m_pmap_unused = new FTKPlaneMap(m_pmapunused_path.c_str()); - if (!(*m_pmap_unused)) { - log << MSG::FATAL << "Error using plane map: " << m_pmapunused_path << endmsg; - return StatusCode::FAILURE; - } + m_pmap = new FTKPlaneMap(m_pmap_path.c_str()); + if (!(*m_pmap)) { + log << MSG::FATAL << "Error using plane map: " << m_pmap_path << endmsg; + return StatusCode::FAILURE; + } } + // Look for the unused plane-map - } + if(m_SecondStageFit){ + if (m_pmapunused_path.empty()) { + log << MSG::FATAL << "Unused plane map definition missing" << endmsg; + return StatusCode::FAILURE; + } + else { + m_pmap_unused = new FTKPlaneMap(m_pmapunused_path.c_str()); + if (!(*m_pmap_unused)) { + log << MSG::FATAL << "Error using plane map: " << m_pmapunused_path << endmsg; + return StatusCode::FAILURE; + } + } - log << MSG::INFO << "Read the pattern matching PMAP file: " << m_pmap_path << endmsg; - log << MSG::INFO << "Read the unused PMAP file: " << m_pmapunused_path << endmsg; - log << MSG::INFO << "Read the final PMAP file: " << m_pmapcomplete_path << endmsg; - log << MSG::INFO << "Read the tower-map file: " << m_rmap_path << endmsg; - log << MSG::INFO << "Read the SS definition file : " << m_ssmap_path << endmsg; - log << MSG::INFO << "Read the extrapolation window definition: " << m_ssmapunused_path << endmsg; + } + log << MSG::INFO << "Read the pattern matching PMAP file: " << m_pmap_path << endmsg; + log << MSG::INFO << "Read the unused PMAP file: " << m_pmapunused_path << endmsg; + log << MSG::INFO << "Read the final PMAP file: " << m_pmapcomplete_path << endmsg; + + log << MSG::INFO << "Read the tower-map file: " << m_rmap_path << endmsg; + log << MSG::INFO << "Read the SS definition file : " << m_ssmap_path << endmsg; + log << MSG::INFO << "Read the extrapolation window definition: " << m_ssmapunused_path << endmsg; - if (m_SecondStageFit){ - log << MSG::INFO << "Read the 11lL pmap file" << endmsg; - if (m_pmapcomplete_path.empty()) { - log << MSG::FATAL << "11L plane map definition missing" << endmsg; - return StatusCode::FAILURE; - } - else { - m_pmap_complete = new FTKPlaneMap(m_pmapcomplete_path.c_str()); - if (!(*m_pmap_complete)) { - log << MSG::FATAL << "Error using 11L plane map: " << m_pmapcomplete_path << endmsg; - return StatusCode::FAILURE; - } - } - // Create the region map objects - if (m_rmap_path.empty()) { - log << MSG::FATAL << "Region map file needed" << endmsg; - return StatusCode::FAILURE; + + if (m_SecondStageFit){ + log << MSG::INFO << "Read the 11lL pmap file" << endmsg; + if (m_pmapcomplete_path.empty()) { + log << MSG::FATAL << "11L plane map definition missing" << endmsg; + return StatusCode::FAILURE; + } + else { + m_pmap_complete = new FTKPlaneMap(m_pmapcomplete_path.c_str()); + if (!(*m_pmap_complete)) { + log << MSG::FATAL << "Error using 11L plane map: " << m_pmapcomplete_path << endmsg; + return StatusCode::FAILURE; + } + } + + // Create the region map objects + if (m_rmap_path.empty()) { + log << MSG::FATAL << "Region map file needed" << endmsg; + return StatusCode::FAILURE; + } + + log << MSG::INFO << "Creating region map" << endmsg; + m_rmap = new FTKRegionMap(m_pmap, m_rmap_path.c_str()); + if (!(*m_rmap)) { + log << MSG::FATAL << "Error creating region map from: " << m_rmap_path.c_str() << endmsg; + return StatusCode::FAILURE; + } + + + if (m_pmap_complete) { + log << MSG::INFO << "Creating region map for the unused layers" << endmsg; + m_rmap_unused = new FTKRegionMap(m_pmap_complete, m_rmap_path.c_str()); + if( FTKSetup::getFTKSetup().getHWModeSS()==2) { + if (m_modulelut2nd_path.empty()) { + log << MSG::FATAL << "A module LUT is required when HW SS calculation is required" << m_modulelut2nd_path << endmsg; + return StatusCode::FAILURE; + } + else { + log << MSG::INFO << "Loading module map from: " << m_modulelut2nd_path << endmsg; + m_rmap_unused->loadModuleIDLUT(m_modulelut2nd_path.c_str()); //"/afs/cern.ch/work/v/vcavalie/HWMODE2/InstallArea/share/ftk_configuration/map_files/raw_12LiblHW_32.moduleidmap"); + } + } + } + + + log << MSG::INFO << "Read SS configurations" << endmsg; + log << MSG::INFO << "Read AM SS configuration" << endmsg; + m_ssmap = new FTKSSMap(m_rmap, m_ssmap_path.c_str(), false); + if (!m_ssmapunused_path.empty()) { + log << MSG::INFO << "Read SS configuration for layer not used in AM" << endmsg; + m_ssmap_unused = new FTKSSMap(m_rmap_unused, m_ssmapunused_path.c_str(), false); + } + + dynamic_cast(m_tfpobj)->setPlaneMapIncomplete(m_pmap); + dynamic_cast(m_tfpobj)->setPlaneMap(m_pmap_complete); + dynamic_cast(m_tfpobj)->setSSMapIncomplete(m_ssmap); + dynamic_cast(m_tfpobj)->setSSMapComplete(m_ssmap_unused); } - - log << MSG::INFO << "Creating region map" << endmsg; - m_rmap = new FTKRegionMap(m_pmap, m_rmap_path.c_str()); - if (!(*m_rmap)) { - log << MSG::FATAL << "Error creating region map from: " << m_rmap_path.c_str() << endmsg; - return StatusCode::FAILURE; + else{ + m_tfpobj->setPlaneMap(m_pmap); } - if (m_pmap_complete) { - log << MSG::INFO << "Creating region map for the unused layers" << endmsg; - m_rmap_unused = new FTKRegionMap(m_pmap_complete, m_rmap_path.c_str()); - if( FTKSetup::getFTKSetup().getHWModeSS()==2) { - if (m_modulelut2nd_path.empty()) { - log << MSG::FATAL << "A module LUT is required when HW SS calculation is required" << m_modulelut2nd_path << endmsg; - return StatusCode::FAILURE; - } - else { - log << MSG::INFO << "Loading module map from: " << m_modulelut2nd_path << endmsg; - m_rmap_unused->loadModuleIDLUT(m_modulelut2nd_path.c_str()); //"/afs/cern.ch/work/v/vcavalie/HWMODE2/InstallArea/share/ftk_configuration/map_files/raw_12LiblHW_32.moduleidmap"); - } - } + + // set Road Input Module + //-- case 1 : input from I/O -- + FTKRoadInput *ftkinputmodule = m_roadMarketTool->inputReference(); + m_roadMarketTool->setTrackFitterReference(m_tfpobj); + m_tfpobj->setRoadInputModule(ftkinputmodule); + + // set Track Output Module + if (m_doTrackFile) { + log << MSG::INFO << "Write the TF simulation results in an external file: " << m_trackfilename.c_str() << endmsg; + log << MSG::INFO << "Output Directory :" << m_trackfilepath.c_str() << endmsg; // should be impremented -> each region output 0/xxx0.root ,1/xxx1.root,2,3... + FTKTrackFileOutput *ftkouttrackmodule = new FTKTrackFileOutput(); + /// FTKTrackFileOutput *ftkouttrackmodule_pre_hw = new FTKTrackFileOutput(); + ftkouttrackmodule->setMultiOut(false); + ftkouttrackmodule->setOutDir(m_trackfilepath.c_str()); + ftkouttrackmodule->setFileName(m_trackfilename.c_str()); + ftkouttrackmodule->setBranchFormat("FTKTracksStream%d."); + + + std::size_t replace_index = m_trackfilename.find(".root"); + + // string pre_hw_trackfilename = m_trackfilename; + // if (replace_index != std::string::npos) pre_hw_trackfilename.insert(replace_index, "_pre_hw"); + // ftkouttrackmodule_pre_hw->setMultiOut(false); + // ftkouttrackmodule_pre_hw->setOutDir(m_trackfilepath.c_str()); + // ftkouttrackmodule_pre_hw->setFileName(pre_hw_trackfilename.c_str()); + // ftkouttrackmodule_pre_hw->setBranchFormat("FTKTracksStream%d."); + + m_tfpobj->setTrackOutputModule(ftkouttrackmodule); + // m_tfpobj->setTrackOutputModulePreHW(ftkouttrackmodule_pre_hw); } + else { + StatusCode sc = m_trackOutputTool.retrieve(); + if (sc.isFailure()) { + log << MSG::FATAL << "Could not retrieve FTK_SGTrackOutput tool" << endmsg; + return StatusCode::FAILURE; + } + else { + log << MSG::INFO << "Setting FTK_SGTrackOutput tool" << endmsg; + } + + m_tfpobj->setTrackOutputModule(m_trackOutputTool->reference()); + + // sc = m_trackOutputTool_pre_hw.retrieve(); + // if (sc.isFailure()) { + // log << MSG::FATAL << "Could not retrieve FTK_SGTrackOutput_pre_hw tool" << endmsg; + // return StatusCode::FAILURE; + // } + // else { + // log << MSG::INFO << "Setting FTK_SGTrackOutput_pre_hw tool" << endmsg; + // } + + // m_tfpobj->setTrackOutputModulePreHW(m_trackOutputTool_pre_hw->reference()); + } + - log << MSG::INFO << "Read SS configurations" << endmsg; - log << MSG::INFO << "Read AM SS configuration" << endmsg; - m_ssmap = new FTKSSMap(m_rmap, m_ssmap_path.c_str(), false); - if (!m_ssmapunused_path.empty()) { - log << MSG::INFO << "Read SS configuration for layer not used in AM" << endmsg; - m_ssmap_unused = new FTKSSMap(m_rmap_unused, m_ssmapunused_path.c_str(), false); - } - - dynamic_cast(m_tfpobj)->setPlaneMapIncomplete(m_pmap); - dynamic_cast(m_tfpobj)->setPlaneMap(m_pmap_complete); - dynamic_cast(m_tfpobj)->setSSMapIncomplete(m_ssmap); - dynamic_cast(m_tfpobj)->setSSMapComplete(m_ssmap_unused); - } - else{ - m_tfpobj->setPlaneMap(m_pmap); - } - - - - // set Road Input Module - //-- case 1 : input from I/O -- - FTKRoadInput *ftkinputmodule = m_roadMarketTool->inputReference(); - m_roadMarketTool->setTrackFitterReference(m_tfpobj); - m_tfpobj->setRoadInputModule(ftkinputmodule); - - // set Track Output Module - if (m_doTrackFile) { - log << MSG::INFO << "Write the TF simulation results in an external file: " << m_trackfilename.c_str() << endmsg; - log << MSG::INFO << "Output Directory :" << m_trackfilepath.c_str() << endmsg; // should be impremented -> each region output 0/xxx0.root ,1/xxx1.root,2,3... - FTKTrackFileOutput *ftkouttrackmodule = new FTKTrackFileOutput(); - /// FTKTrackFileOutput *ftkouttrackmodule_pre_hw = new FTKTrackFileOutput(); - ftkouttrackmodule->setMultiOut(false); - ftkouttrackmodule->setOutDir(m_trackfilepath.c_str()); - ftkouttrackmodule->setFileName(m_trackfilename.c_str()); - ftkouttrackmodule->setBranchFormat("FTKTracksStream%d."); - - - std::size_t replace_index = m_trackfilename.find(".root"); - - // string pre_hw_trackfilename = m_trackfilename; - // if (replace_index != std::string::npos) pre_hw_trackfilename.insert(replace_index, "_pre_hw"); - // ftkouttrackmodule_pre_hw->setMultiOut(false); - // ftkouttrackmodule_pre_hw->setOutDir(m_trackfilepath.c_str()); - // ftkouttrackmodule_pre_hw->setFileName(pre_hw_trackfilename.c_str()); - // ftkouttrackmodule_pre_hw->setBranchFormat("FTKTracksStream%d."); - - m_tfpobj->setTrackOutputModule(ftkouttrackmodule); - // m_tfpobj->setTrackOutputModulePreHW(ftkouttrackmodule_pre_hw); - } - else { - StatusCode sc = m_trackOutputTool.retrieve(); - if (sc.isFailure()) { - log << MSG::FATAL << "Could not retrieve FTK_SGTrackOutput tool" << endmsg; - return StatusCode::FAILURE; + // set path Hit Warrior configulation + log << MSG::INFO << "Load Hit Warrior Configulation " << endmsg; + if (m_loadHWConf_path.empty()) { + log << MSG::FATAL << "HW Conf definition missing" << endmsg; + return StatusCode::FAILURE; } else { - log << MSG::INFO << "Setting FTK_SGTrackOutput tool" << endmsg; + + if (m_SecondStageFit){ + dynamic_cast(m_tfpobj)->setNCoordsPlanes(m_pmap->getTotalDim(),m_pmap->getNPlanes(),m_pmap_complete->getTotalDim(),m_pmap_complete->getNPlanes()); + }else{ + (m_tfpobj)->setNCoordsPlanes(m_pmap->getTotalDim(),m_pmap->getNPlanes()); + } + log << MSG::INFO << "Load Hit Warrior Configulation " << endmsg; + m_tfpobj->loadHWConf(m_loadHWConf_path.c_str()); } - m_tfpobj->setTrackOutputModule(m_trackOutputTool->reference()); - - // sc = m_trackOutputTool_pre_hw.retrieve(); - // if (sc.isFailure()) { - // log << MSG::FATAL << "Could not retrieve FTK_SGTrackOutput_pre_hw tool" << endmsg; - // return StatusCode::FAILURE; - // } - // else { - // log << MSG::INFO << "Setting FTK_SGTrackOutput_pre_hw tool" << endmsg; - // } - - // m_tfpobj->setTrackOutputModulePreHW(m_trackOutputTool_pre_hw->reference()); - } - - - - // set path Hit Warrior configulation - log << MSG::INFO << "Load Hit Warrior Configulation " << endmsg; - if (m_loadHWConf_path.empty()) { - log << MSG::FATAL << "HW Conf definition missing" << endmsg; - return StatusCode::FAILURE; - } - else { + + + + // set parameter object to TrackFitter + m_tfpobj->setChi2Cut(m_chi2cut); + m_tfpobj->setHitWarrior(m_HitWarrior); + m_tfpobj->setAuxDoctor(m_AuxDoctor); + m_tfpobj->setChi2Cut_maj(m_chi2cut_maj); + m_tfpobj->setChi2Cut_vetomaj(m_chi2cut_vetmaj); + m_tfpobj->setChi2DofCutAux(m_chi2dofcutAux); + m_tfpobj->setChi2DofCutSSB(m_chi2dofcutSSB); + m_tfpobj->setKeepRejected(m_KeepRejected); + m_tfpobj->setFitRemoved(m_FitRemoved); + m_tfpobj->setHWNDiff(m_HWNDiff); + m_tfpobj->setMaxNcomb(m_MaxNcomb); + m_tfpobj->setMaxNhitsPerPlane(m_MaxNhitsPerPlane); + m_tfpobj->setMaxTrkout(m_MaxTrkout); + + m_tfpobj->setRequireFirst(0); + m_tfpobj->setOnePerRoad(m_OnePerRoad); + + if (m_save_StepByStepTrks) m_tfpobj->setSaveStepByStepTracks(true); + else m_tfpobj->setSaveStepByStepTracks(false); + + //std::cout << "chi2cut " << m_tfpobj->getChi2Cut() << std::endl; + //std::cout << "hitwarr " << m_tfpobj->getHitWarrior() << std::endl; + //std::cout << "chi2cutmaj " << m_tfpobj->getChi2Cut_maj() << std::endl; + //std::cout << "chi2cutvetomaj " << m_tfpobj->getChi2Cut_vetomaj() << std::endl; + //std::cout << "chi2dofcut " << m_tfpobj->getChi2DofCut() << std::endl; + //std::cout << "hwndiff " << m_tfpobj->getHWNDiff() << std::endl; + //std::cout << "MaxNComb " << m_MaxNcomb << std::endl; + //std::cout << "MaxTrkout " << m_MaxTrkout << std::endl; + //std::cout << "fitremoved " << m_tfpobj->getFitRemoved() << std::endl; + + //std::cout << "chi2cut " << m_tfpobj->getChi2Cut() << std::endl; + //std::cout << "hitwarr " << m_tfpobj->getHitWarrior() << std::endl; + //std::cout << "chi2cutmaj " << m_tfpobj->getChi2Cut_maj() << std::endl; + //std::cout << "chi2cutvetomaj " << m_tfpobj->getChi2Cut_vetomaj() << std::endl; + //std::cout << "chi2dofcut " << m_tfpobj->getChi2DofCut() << std::endl; + //std::cout << "hwndiff " << m_HWNDiff << std::endl; + //std::cout << "MaxNComb " << m_MaxNcomb << std::endl; + //std::cout << "MaxTrkout " << m_MaxTrkout << std::endl; + //std::cout << "fitremoved " << m_tfpobj->getFitRemoved() << std::endl; + + + + //--- should add below options ---// + //m_tfpobj->setNorecoveryNhits(0); + //m_tfpobj->setOnePerRoad(0); + //m_tfpobj->setDoMajority(0); + //m_tfpobj->setRequireFirst(0); + + m_tfpobj->setNorecoveryNhits(m_NoRecoveryNHits); + + if(m_SecondStageFit ){ + + // TrackFitter711 *realTF = dynamic_cast(m_tfpobj); + + if (m_SSF_TFMode == 3) + dynamic_cast(m_tfpobj)->setSuperExtrapolateMode(true); + else + dynamic_cast(m_tfpobj)->setSuperExtrapolateMode(false); + if (m_save_1stStageTrks) + dynamic_cast(m_tfpobj)->setSaveIncompleteTracks(true); + else + dynamic_cast(m_tfpobj)->setSaveIncompleteTracks(false); + + dynamic_cast(m_tfpobj)->setUseSectorDB(true); + dynamic_cast(m_tfpobj)->setUseMultipleConn(m_SSF_multiconn); + dynamic_cast(m_tfpobj)->setUseNConn(m_SSF_maxnconn); + dynamic_cast(m_tfpobj)->setAllowExtraMissInSuperExp(m_SSF_allow_extramiss); + dynamic_cast(m_tfpobj)->setCheckTRby(m_SSF_check_TR_by); + dynamic_cast(m_tfpobj)->setTransitionRegionMinEta(m_SSF_TR_min_eta); + dynamic_cast(m_tfpobj)->setTransitionRegionMaxEta(m_SSF_TR_max_eta); + + log << MSG::INFO << "SSF allow miss = " << m_SSF_allow_extramiss << endmsg; + log << MSG::INFO << "SSF check TR by = " << m_SSF_check_TR_by << endmsg; + log << MSG::INFO << "SSF TR min eta = " << m_SSF_TR_min_eta << endmsg; + log << MSG::INFO << "SSF TR max eta = " << m_SSF_TR_max_eta << endmsg; + + //std::cout << "m_SSF_multiconn: " << m_SSF_multiconn << std::endl; + //std::cout << "m_SSF_maxconn: " << m_SSF_maxnconn << std::endl; + } + // set banks in case of region selection// + m_tfpobj->prepareBanks(m_nbanks,m_nsubregions); //Set the below function ... to set the region Number + + if(m_fitconstantspath.size()==0){ + log << MSG::FATAL << "No Bank for input" << endmsg; + return StatusCode::FAILURE; + } if (m_SecondStageFit){ - dynamic_cast(m_tfpobj)->setNCoordsPlanes(m_pmap->getTotalDim(),m_pmap->getNPlanes(),m_pmap_complete->getTotalDim(),m_pmap_complete->getNPlanes()); - }else{ - (m_tfpobj)->setNCoordsPlanes(m_pmap->getTotalDim(),m_pmap->getNPlanes()); + if(m_fit711constantspath.size()==0){ + log << MSG::FATAL << "No 11 L Bank for input" << endmsg; + return StatusCode::FAILURE; + } + } - log << MSG::INFO << "Load Hit Warrior Configulation " << endmsg; - m_tfpobj->loadHWConf(m_loadHWConf_path.c_str()); - } - - - - - // set parameter object to TrackFitter - m_tfpobj->setChi2Cut(m_chi2cut); - m_tfpobj->setHitWarrior(m_HitWarrior); - m_tfpobj->setAuxDoctor(m_AuxDoctor); - m_tfpobj->setChi2Cut_maj(m_chi2cut_maj); - m_tfpobj->setChi2Cut_vetomaj(m_chi2cut_vetmaj); - m_tfpobj->setChi2DofCutAux(m_chi2dofcutAux); - m_tfpobj->setChi2DofCutSSB(m_chi2dofcutSSB); - m_tfpobj->setKeepRejected(m_KeepRejected); - m_tfpobj->setFitRemoved(m_FitRemoved); - m_tfpobj->setHWNDiff(m_HWNDiff); - m_tfpobj->setMaxNcomb(m_MaxNcomb); - m_tfpobj->setMaxNhitsPerPlane(m_MaxNhitsPerPlane); - m_tfpobj->setMaxTrkout(m_MaxTrkout); - - m_tfpobj->setRequireFirst(0); - m_tfpobj->setOnePerRoad(m_OnePerRoad); - - if (m_save_StepByStepTrks) m_tfpobj->setSaveStepByStepTracks(true); - else m_tfpobj->setSaveStepByStepTracks(false); - - //std::cout << "chi2cut " << m_tfpobj->getChi2Cut() << std::endl; - //std::cout << "hitwarr " << m_tfpobj->getHitWarrior() << std::endl; - //std::cout << "chi2cutmaj " << m_tfpobj->getChi2Cut_maj() << std::endl; - //std::cout << "chi2cutvetomaj " << m_tfpobj->getChi2Cut_vetomaj() << std::endl; - //std::cout << "chi2dofcut " << m_tfpobj->getChi2DofCut() << std::endl; - //std::cout << "hwndiff " << m_tfpobj->getHWNDiff() << std::endl; - //std::cout << "MaxNComb " << m_MaxNcomb << std::endl; - //std::cout << "MaxTrkout " << m_MaxTrkout << std::endl; - //std::cout << "fitremoved " << m_tfpobj->getFitRemoved() << std::endl; - - //std::cout << "chi2cut " << m_tfpobj->getChi2Cut() << std::endl; - //std::cout << "hitwarr " << m_tfpobj->getHitWarrior() << std::endl; - //std::cout << "chi2cutmaj " << m_tfpobj->getChi2Cut_maj() << std::endl; - //std::cout << "chi2cutvetomaj " << m_tfpobj->getChi2Cut_vetomaj() << std::endl; - //std::cout << "chi2dofcut " << m_tfpobj->getChi2DofCut() << std::endl; - //std::cout << "hwndiff " << m_HWNDiff << std::endl; - //std::cout << "MaxNComb " << m_MaxNcomb << std::endl; - //std::cout << "MaxTrkout " << m_MaxTrkout << std::endl; - //std::cout << "fitremoved " << m_tfpobj->getFitRemoved() << std::endl; - - - - //--- should add below options ---// - //m_tfpobj->setNorecoveryNhits(0); - //m_tfpobj->setOnePerRoad(0); - //m_tfpobj->setDoMajority(0); - //m_tfpobj->setRequireFirst(0); - - m_tfpobj->setNorecoveryNhits(m_NoRecoveryNHits); - - if(m_SecondStageFit ){ - - // TrackFitter711 *realTF = dynamic_cast(m_tfpobj); - - if (m_SSF_TFMode == 3) - dynamic_cast(m_tfpobj)->setSuperExtrapolateMode(true); - else - dynamic_cast(m_tfpobj)->setSuperExtrapolateMode(false); - if (m_save_1stStageTrks) - dynamic_cast(m_tfpobj)->setSaveIncompleteTracks(true); - else - dynamic_cast(m_tfpobj)->setSaveIncompleteTracks(false); - - dynamic_cast(m_tfpobj)->setUseSectorDB(true); - dynamic_cast(m_tfpobj)->setUseMultipleConn(m_SSF_multiconn); - dynamic_cast(m_tfpobj)->setUseNConn(m_SSF_maxnconn); - dynamic_cast(m_tfpobj)->setAllowExtraMissInSuperExp(m_SSF_allow_extramiss); - dynamic_cast(m_tfpobj)->setCheckTRby(m_SSF_check_TR_by); - dynamic_cast(m_tfpobj)->setTransitionRegionMinEta(m_SSF_TR_min_eta); - dynamic_cast(m_tfpobj)->setTransitionRegionMaxEta(m_SSF_TR_max_eta); - - log << MSG::INFO << "SSF allow miss = " << m_SSF_allow_extramiss << endmsg; - log << MSG::INFO << "SSF check TR by = " << m_SSF_check_TR_by << endmsg; - log << MSG::INFO << "SSF TR min eta = " << m_SSF_TR_min_eta << endmsg; - log << MSG::INFO << "SSF TR max eta = " << m_SSF_TR_max_eta << endmsg; - - //std::cout << "m_SSF_multiconn: " << m_SSF_multiconn << std::endl; - //std::cout << "m_SSF_maxconn: " << m_SSF_maxnconn << std::endl; - } - // set banks in case of region selection// - m_tfpobj->prepareBanks(m_nbanks,m_nsubregions); //Set the below function ... to set the region Number - - if(m_fitconstantspath.size()==0){ - log << MSG::FATAL << "No Bank for input" << endmsg; - return StatusCode::FAILURE; - } - - if (m_SecondStageFit){ - if(m_fit711constantspath.size()==0){ - log << MSG::FATAL << "No 11 L Bank for input" << endmsg; - return StatusCode::FAILURE; + + if (m_nbanks!=m_tfpobj->getNumRegions() || m_nsubregions!=m_tfpobj->getNumSubRegions() ) { + log << MSG::FATAL << "Wrong set Region or Subregion in TrackFitter" << endmsg; + return StatusCode::FAILURE; + } + + + unsigned int nbanks = m_fitconstantspath.size(); + + if(nbanks!=m_bankregion.size() || nbanks!=m_banksubregion.size()){ + log << MSG::FATAL << "Different array property length in bank definitions" << endmsg; + return StatusCode::FAILURE; } - } - if (m_nbanks!=m_tfpobj->getNumRegions() || m_nsubregions!=m_tfpobj->getNumSubRegions() ) { - log << MSG::FATAL << "Wrong set Region or Subregion in TrackFitter" << endmsg; - return StatusCode::FAILURE; - } + for(unsigned int ibank=0;ibank!=nbanks;++ibank){ + + int ir = m_bankregion[ibank]; + int is = m_banksubregion[ibank]; + const string &bankpath8L = m_fitconstantspath[ibank]; + + log << MSG::INFO << "*** set bank *** region:" << ir << "\t subregions:" << is << "\t bank path:" << bankpath8L.c_str() << endmsg; + if(m_SecondStageFit){ + const string &bankpath11L = m_fit711constantspath[ibank]; + const string §orpath_s = m_sectorpath[ibank]; + log << MSG::INFO << "*** set bank *** region:" << ir << "\t subregions:" << is << "\t bank path:" << bankpath11L.c_str() << endmsg; - unsigned int nbanks = m_fitconstantspath.size(); + FTKConstantBank* bank8 = new FTKConstantBank(dynamic_cast(m_tfpobj)->getNCoordsIncomplete(),bankpath8L.c_str()); + bank8->doAuxFW(m_doAuxFW); - if(nbanks!=m_bankregion.size() || nbanks!=m_banksubregion.size()){ - log << MSG::FATAL << "Different array property length in bank definitions" << endmsg; - return StatusCode::FAILURE; - } + FTKConstantBank* bank11 = new FTKConstantBank(dynamic_cast(m_tfpobj)->getNCoordsComplete(),bankpath11L.c_str()); + FTKSector711DB * sector= new FTKSector711DB(bank8->getNSectors(),m_pmap_complete->getNPlanes()-m_pmap->getNPlanes(),sectorpath_s.c_str()); + dynamic_cast(m_tfpobj)->setBank(ir,is,bank11,bank8, sector); + bank11->setdTIBL(m_dTIBL); + if(m_PrintSSBConstants){ + log << MSG::INFO << "*** Printing EXP and TF constants in a txt file ****" << endreq; - for(unsigned int ibank=0;ibank!=nbanks;++ibank){ - - int ir = m_bankregion[ibank]; - int is = m_banksubregion[ibank]; - const string &bankpath8L = m_fitconstantspath[ibank]; - - log << MSG::INFO << "*** set bank *** region:" << ir << "\t subregions:" << is << "\t bank path:" << bankpath8L.c_str() << endmsg; - if(m_SecondStageFit){ - const string &bankpath11L = m_fit711constantspath[ibank]; - const string §orpath_s = m_sectorpath[ibank]; - log << MSG::INFO << "*** set bank *** region:" << ir << "\t subregions:" << is << "\t bank path:" << bankpath11L.c_str() << endmsg; - - FTKConstantBank* bank8 = new FTKConstantBank(dynamic_cast(m_tfpobj)->getNCoordsIncomplete(),bankpath8L.c_str()); - bank8->doAuxFW(m_doAuxFW); - - FTKConstantBank* bank11 = new FTKConstantBank(dynamic_cast(m_tfpobj)->getNCoordsComplete(),bankpath11L.c_str()); - FTKSector711DB * sector= new FTKSector711DB(bank8->getNSectors(),m_pmap_complete->getNPlanes()-m_pmap->getNPlanes(),sectorpath_s.c_str()); - dynamic_cast(m_tfpobj)->setBank(ir,is,bank11,bank8, sector); - bank11->setdTIBL(m_dTIBL); - - if(m_PrintSSBConstants){ - - log << MSG::INFO << "*** Printing EXP and TF constants in a txt file ****" << endreq; - - ofstream myfile; - myfile.open (Form("EXPConstants_reg%d.txt",ir)); - - ofstream myfileTF; - myfileTF.open (Form("TFConstants_reg%d.txt",ir)); - - std::vector > vecOfMapSecID; - std::vector > vecOfMapNconn; - vecOfMapSecID.clear(); - vecOfMapNconn.clear(); - - log << MSG::INFO << "*** Reading the connection file and mapping 8L -> 12L " << endreq; - vector> moduleIDvec; - moduleIDvec.clear(); - - Int_t Max_1stStage_sectors = 16383; - Int_t applied_sector_max = bank8->getNSectors() > Max_1stStage_sectors ? Max_1stStage_sectors : bank8->getNSectors(); - for(Int_t isec=0;isecgetNSimilarSectors(isec) == 0 )break; - - for(Int_t Nconn=0; Nconn< (int)sector->getNSimilarSectors(isec); Nconn++){ - if(Nconn >3 ) break; - Int_t TwelveLsecid = sector->getSimilarSecID(isec,Nconn); - std::map Map_secid_Nconn; - Map_secid_Nconn[TwelveLsecid] = isec; - std::map Map_temp; - Map_temp[TwelveLsecid] = (int)sector->getNSimilarSectors(isec) ; - vecOfMapNconn.push_back(Map_temp); - vecOfMapSecID.push_back(Map_secid_Nconn); - vector module_temp; - module_temp.clear(); - for (int ip=0; ip!=(m_pmap_complete->getNPlanes()-m_pmap->getNPlanes()); ++ip) { - module_temp.push_back(sector->getSimilarStereoIDs(isec,Nconn)[ip]); - } - moduleIDvec.push_back(module_temp); - } - } - - for(Int_t isec=0;isecgetNSectors();isec++){ - bank11->printTFConstant(isec,myfileTF); - Int_t temp = -9; - Int_t counter=-1; - Int_t index =-9; - - for(Int_t Nconn=0; Nconn<(int)vecOfMapSecID.size(); Nconn++){ - std::map &mymap= vecOfMapSecID[Nconn]; - std::map &mymap_Nconn= vecOfMapNconn[Nconn]; - std::map::iterator it; - for (std::map::iterator it=mymap.begin(); it!=mymap.end(); ++it){ - Int_t count_Nconn = mymap_Nconn.find(isec)->second ; - if(count_Nconn >4)count_Nconn =4; - if(it->second != temp) index=-1; - if(index <0){ - temp = it->second; - index = 1; - counter =-1; - } - if(it->second == temp && index>=0) counter++; - - if (it->first == isec){ - bank11->printExtrapolationConstant(isec,moduleIDvec[Nconn],it->second,counter,count_Nconn, myfile); - break; - } - } - } - } - - myfile.close(); - myfileTF.close(); - - - } + ofstream myfile; + myfile.open (Form("EXPConstants_reg%d.txt",ir)); + + ofstream myfileTF; + myfileTF.open (Form("TFConstants_reg%d.txt",ir)); + + std::vector > vecOfMapSecID; + std::vector > vecOfMapNconn; + vecOfMapSecID.clear(); + vecOfMapNconn.clear(); + + log << MSG::INFO << "*** Reading the connection file and mapping 8L -> 12L " << endreq; + vector> moduleIDvec; + moduleIDvec.clear(); + + Int_t Max_1stStage_sectors = 16383; + Int_t applied_sector_max = bank8->getNSectors() > Max_1stStage_sectors ? Max_1stStage_sectors : bank8->getNSectors(); + for(Int_t isec=0;isecgetNSimilarSectors(isec) == 0 )break; + + for(Int_t Nconn=0; Nconn< (int)sector->getNSimilarSectors(isec); Nconn++){ + if(Nconn >3 ) break; + Int_t TwelveLsecid = sector->getSimilarSecID(isec,Nconn); + std::map Map_secid_Nconn; + Map_secid_Nconn[TwelveLsecid] = isec; + std::map Map_temp; + Map_temp[TwelveLsecid] = (int)sector->getNSimilarSectors(isec) ; + vecOfMapNconn.push_back(Map_temp); + vecOfMapSecID.push_back(Map_secid_Nconn); + vector module_temp; + module_temp.clear(); + for (int ip=0; ip!=(m_pmap_complete->getNPlanes()-m_pmap->getNPlanes()); ++ip) { + module_temp.push_back(sector->getSimilarStereoIDs(isec,Nconn)[ip]); + } + moduleIDvec.push_back(module_temp); + } + } + + for(Int_t isec=0;isecgetNSectors();isec++){ + bank11->printTFConstant(isec,myfileTF); + Int_t temp = -9; + Int_t counter=-1; + Int_t index =-9; + + for(Int_t Nconn=0; Nconn<(int)vecOfMapSecID.size(); Nconn++){ + std::map &mymap= vecOfMapSecID[Nconn]; + std::map &mymap_Nconn= vecOfMapNconn[Nconn]; + std::map::iterator it; + for (std::map::iterator it=mymap.begin(); it!=mymap.end(); ++it){ + Int_t count_Nconn = mymap_Nconn.find(isec)->second ; + if(count_Nconn >4)count_Nconn =4; + if(it->second != temp) index=-1; + if(index <0){ + temp = it->second; + index = 1; + counter =-1; + } + if(it->second == temp && index>=0) counter++; + + if (it->first == isec){ + bank11->printExtrapolationConstant(isec,moduleIDvec[Nconn],it->second,counter,count_Nconn, myfile); + break; + } + } + } + } + + myfile.close(); + myfileTF.close(); + } + + + + } + else{ + FTKConstantBank* bank8 = new FTKConstantBank(m_tfpobj->getNCoords(),bankpath8L.c_str()); + bank8->doAuxFW(m_doAuxFW); + m_tfpobj->setBank(ir,is,bank8); + + } } - else{ - FTKConstantBank* bank8 = new FTKConstantBank(m_tfpobj->getNCoords(),bankpath8L.c_str()); - bank8->doAuxFW(m_doAuxFW); - m_tfpobj->setBank(ir,is,bank8); + + + m_tfpobj->init(); + + /* if combined file with tracks and roads has been requested the roads + can be connected at this time */ + if (m_doTrackFile && m_addRoads) { + // produce a combined outptu file with both roads and tracks in different branches + log << MSG::INFO << "The FTK roads will be added" << endmsg; + FTKTrackFileOutput *ftkouttrackmodule = dynamic_cast(m_tfpobj->getTrackOutputModule()); + m_roadMarketTool->ConnectRoads(ftkouttrackmodule->getTree(),"FTKRoadsStream%d.",m_bankregion); + + // FTKTrackFileOutput *ftkouttrackmodule_pre_hw = dynamic_cast(m_tfpobj->getTrackOutputModulePreHW()); + // m_roadMarketTool->ConnectRoads(ftkouttrackmodule_pre_hw->getTree(),"FTKRoadsStream%d.",m_bankregion); } - - } - - - m_tfpobj->init(); - - /* if combined file with tracks and roads has been requested the roads - can be connected at this time */ - if (m_doTrackFile && m_addRoads) { - // produce a combined outptu file with both roads and tracks in different branches - log << MSG::INFO << "The FTK roads will be added" << endmsg; - FTKTrackFileOutput *ftkouttrackmodule = dynamic_cast(m_tfpobj->getTrackOutputModule()); - m_roadMarketTool->ConnectRoads(ftkouttrackmodule->getTree(),"FTKRoadsStream%d.",m_bankregion); - - // FTKTrackFileOutput *ftkouttrackmodule_pre_hw = dynamic_cast(m_tfpobj->getTrackOutputModulePreHW()); - // m_roadMarketTool->ConnectRoads(ftkouttrackmodule_pre_hw->getTree(),"FTKRoadsStream%d.",m_bankregion); - - } - - return StatusCode::SUCCESS; + + return StatusCode::SUCCESS; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * StatusCode FTKTrackFitterAlgo::execute() { - MsgStream log(msgSvc(), name()); - FTKSetup::getFTKSetup().setMsgStream(&log); - - log << MSG::INFO << "FTKTrackFitterAlgo::execute() start" << endmsg; - - if (m_AutoDisable) { - // if AutoDisable feature is found all the execution driven by road-finder - log << MSG::INFO << "FTKRoadFinderAlgo auto-disable mode, nothing to do" << endmsg; - } - else { - // elaborate the next event - int res = m_tfpobj->nextEvent(); - - if (res<0) { - // make transparent the current algorithm - m_AutoDisable = true; - } - } - - log << MSG::INFO << "FTKTrackFitterAlgo::execute() end" << endmsg; - return StatusCode::SUCCESS; + MsgStream log(msgSvc(), name()); + FTKSetup::getFTKSetup().setMsgStream(&log); + + log << MSG::INFO << "FTKTrackFitterAlgo::execute() start" << endmsg; + + if (m_AutoDisable) { + // if AutoDisable feature is found all the execution driven by road-finder + log << MSG::INFO << "FTKRoadFinderAlgo auto-disable mode, nothing to do" << endmsg; + } + else { + // elaborate the next event + int res = m_tfpobj->nextEvent(); + + if (res<0) { + // make transparent the current algorithm + m_AutoDisable = true; + } + } + + log << MSG::INFO << "FTKTrackFitterAlgo::execute() end" << endmsg; + return StatusCode::SUCCESS; } diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTK_RoadMarketIO.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTK_RoadMarketIO.cxx index d3bab31b624..4dd15fb8dea 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTK_RoadMarketIO.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTK_RoadMarketIO.cxx @@ -187,12 +187,6 @@ void FTK_RoadMarketOutput::addRoad(int BankID, const FTKRoad &road) } -void FTK_RoadMarketOutput::inc4LRoad(int BankID, const int& val) -{ - m_market->getStream(BankID)->inc4LRoad(val); -} - - void FTK_RoadMarketOutput::addSS(int BankID, int plane, int ssid, const FTKSS &ssobj) { m_market->getStream(BankID)->addSS(plane,ssid,ssobj); diff --git a/Trigger/TrigFTK/TrigFTKSim/src/FTK_SGHitInput.cxx b/Trigger/TrigFTK/TrigFTKSim/src/FTK_SGHitInput.cxx index 4e3ddd2a089..7ddd903133b 100644 --- a/Trigger/TrigFTK/TrigFTKSim/src/FTK_SGHitInput.cxx +++ b/Trigger/TrigFTK/TrigFTKSim/src/FTK_SGHitInput.cxx @@ -51,49 +51,49 @@ using namespace std; FTK_SGHitInput::FTK_SGHitInput(const std::string& algname, const std::string &name, const IInterface *ifc) : - AthAlgTool(algname,name,ifc), - FTKDataInput(), - m_log( msgSvc() , name ), - m_truthToTrack( "Trk::TruthToTrack/InDetTruthToTrack" ), - m_extrapolator( "Trk::Extrapolator/AtlasExtrapolator" ), - m_beamSpotSvc( "BeamCondSvc" , name ), - m_pixelClustersName( "PixelClusters" ), - m_sctClustersName( "SCT_Clusters" ), - m_pixelSpacePointsName( "PixelSpacePoints" ), - m_sctSpacePointsName( "SCT_SpacePoints" ), - m_maxEta(3.3), - m_minPt(.8*CLHEP::GeV), - m_outFileNameRawHits( "ftksim_raw_hits.dat.bz2" ), - m_readTruthTracks(false), - m_UseNominalOrigin(false), - m_dooutFileRawHits(false), - ofl(), - oflraw() + AthAlgTool(algname,name,ifc), + FTKDataInput(), + m_log( msgSvc() , name ), + m_truthToTrack( "Trk::TruthToTrack/InDetTruthToTrack" ), + m_extrapolator( "Trk::Extrapolator/AtlasExtrapolator" ), + m_beamSpotSvc( "BeamCondSvc" , name ), + m_pixelClustersName( "PixelClusters" ), + m_sctClustersName( "SCT_Clusters" ), + m_pixelSpacePointsName( "PixelSpacePoints" ), + m_sctSpacePointsName( "SCT_SpacePoints" ), + m_maxEta(3.3), + m_minPt(.8*CLHEP::GeV), + m_outFileNameRawHits( "ftksim_raw_hits.dat.bz2" ), + m_readTruthTracks(false), + m_UseNominalOrigin(false), + m_dooutFileRawHits(false), + ofl(), + oflraw() { - declareInterface(this); - - declareProperty("maxEta", m_maxEta); - declareProperty("minPt", m_minPt); - declareProperty("pixelClustersName", m_pixelClustersName); - declareProperty("SCT_ClustersName", m_sctClustersName); - declareProperty("overlapSpacePointsName", m_overlapSpacePointsName); - declareProperty("pixelSpacePointsName", m_pixelSpacePointsName); - declareProperty("sctSpacePointsName", m_sctSpacePointsName); - declareProperty("OutFileNameRawHits", m_outFileNameRawHits); - declareProperty("dumpHitsOnTracks", m_dumpHitsOnTracks); - declareProperty("dumpSpacePoints", m_dumpSpacePoints); - declareProperty("dumpTruthIntersections", m_dumpTruthIntersections); - declareProperty("tracksTruthName" , m_tracksTruthName); - declareProperty("TruthToTrackTool" , m_truthToTrack); - declareProperty("Extrapolator" , m_extrapolator); - declareProperty("BeamCondSvc" , m_beamSpotSvc); - declareProperty("useOfflineTrackSelectorTool" , m_useOfflineTrackSelectorTool); - declareProperty("outputBeamSpotToWrapper" , m_outputBeamSpotToWrapper); - declareProperty("useSimpleCuts" , m_useSimpleCuts); - declareProperty("logBeamSpotOutput" , m_logBeamSpotOutput); - declareProperty("DoOutFileRawHits" , m_dooutFileRawHits); - declareProperty("ReadTruthTracks", m_readTruthTracks); - declareProperty("UseNominalOrigin", m_UseNominalOrigin); + declareInterface(this); + + declareProperty("maxEta", m_maxEta); + declareProperty("minPt", m_minPt); + declareProperty("pixelClustersName", m_pixelClustersName); + declareProperty("SCT_ClustersName", m_sctClustersName); + declareProperty("overlapSpacePointsName", m_overlapSpacePointsName); + declareProperty("pixelSpacePointsName", m_pixelSpacePointsName); + declareProperty("sctSpacePointsName", m_sctSpacePointsName); + declareProperty("OutFileNameRawHits", m_outFileNameRawHits); + declareProperty("dumpHitsOnTracks", m_dumpHitsOnTracks); + declareProperty("dumpSpacePoints", m_dumpSpacePoints); + declareProperty("dumpTruthIntersections", m_dumpTruthIntersections); + declareProperty("tracksTruthName" , m_tracksTruthName); + declareProperty("TruthToTrackTool" , m_truthToTrack); + declareProperty("Extrapolator" , m_extrapolator); + declareProperty("BeamCondSvc" , m_beamSpotSvc); + declareProperty("useOfflineTrackSelectorTool" , m_useOfflineTrackSelectorTool); + declareProperty("outputBeamSpotToWrapper" , m_outputBeamSpotToWrapper); + declareProperty("useSimpleCuts" , m_useSimpleCuts); + declareProperty("logBeamSpotOutput" , m_logBeamSpotOutput); + declareProperty("DoOutFileRawHits" , m_dooutFileRawHits); + declareProperty("ReadTruthTracks", m_readTruthTracks); + declareProperty("UseNominalOrigin", m_UseNominalOrigin); } @@ -102,177 +102,177 @@ FTK_SGHitInput::FTK_SGHitInput(const std::string& algname, const std::string &na // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * StatusCode FTK_SGHitInput::initialize(){ - m_log << MSG::INFO << "FTK_SGHitInput::initialize()" << endmsg; - - if( service("StoreGateSvc", m_storeGate).isFailure() ) { - m_log << MSG::FATAL << "StoreGate service not found" << endmsg; - return StatusCode::FAILURE; - } - - if( m_truthToTrack.retrieve().isFailure() ) { - m_log << MSG::FATAL << m_truthToTrack << " truth to track tool not found" << endmsg; - return StatusCode::FAILURE; - } else { - m_log << MSG::INFO << m_truthToTrack << " retrieved" << endmsg; - } - - if( m_extrapolator.retrieve().isFailure() ) { - m_log << MSG::FATAL << m_extrapolator << " extrapolator tool not found" << endmsg; - return StatusCode::FAILURE; - } else { - m_log << MSG::INFO << m_extrapolator << " retrieved" << endmsg; - } - - if( m_beamSpotSvc.retrieve().isFailure() ) { - m_log << MSG::FATAL << m_beamSpotSvc << " beam spot service not found" << endmsg; - return StatusCode::FAILURE; - } else { - m_log << MSG::INFO << m_beamSpotSvc << " retrieved" << endmsg; - } - - if( service("DetectorStore",m_detStore).isFailure() ) { - m_log << MSG::FATAL <<"DetectorStore service not found" << endmsg; - return StatusCode::FAILURE; - } - - IPartPropSvc* partPropSvc = 0; - if( service("PartPropSvc", partPropSvc, true).isFailure() ) { - m_log << MSG::FATAL << "particle properties service unavailable" << endmsg; - return StatusCode::FAILURE; - } - m_particleDataTable = partPropSvc->PDT(); - - // ID helpers - m_idHelper = new AtlasDetectorID; - const IdDictManager* idDictMgr( 0 ); - if( m_detStore->retrieve(idDictMgr, "IdDict").isFailure() || !idDictMgr ) { - m_log << MSG::ERROR << "Could not get IdDictManager !" << endmsg; - return StatusCode::FAILURE; - } - if( m_detStore->retrieve(m_PIX_mgr, "Pixel").isFailure() ) { - m_log << MSG::ERROR << "Unable to retrieve Pixel manager from DetectorStore" << endmsg; - return StatusCode::FAILURE; - } - if( m_detStore->retrieve(m_pixelId, "PixelID").isFailure() ) { - m_log << MSG::ERROR << "Unable to retrieve Pixel helper from DetectorStore" << endmsg; - return StatusCode::FAILURE; - } - if( m_detStore->retrieve(m_SCT_mgr, "SCT").isFailure() ) { - m_log << MSG::ERROR << "Unable to retrieve SCT manager from DetectorStore" << endmsg; - return StatusCode::FAILURE; - } - if( m_detStore->retrieve(m_sctId, "SCT_ID").isFailure() ) { - m_log << MSG::ERROR << "Unable to retrieve SCT helper from DetectorStore" << endmsg; - return StatusCode::FAILURE; - } - - // open output to .bz2 using streams for debug // - if(m_dooutFileRawHits) { - oflraw.reset( new boost::iostreams::filtering_ostream ); - if( !oflraw ) { return StatusCode::FAILURE; } - if( boost::algorithm::icontains(m_outFileNameRawHits,".bz2" ) ) { - boost::iostreams::bzip2_params params; - params.block_size = 9; - oflraw->push( boost::iostreams::bzip2_compressor(params) ); + m_log << MSG::INFO << "FTK_SGHitInput::initialize()" << endmsg; + + if( service("StoreGateSvc", m_storeGate).isFailure() ) { + m_log << MSG::FATAL << "StoreGate service not found" << endmsg; + return StatusCode::FAILURE; + } + + if( m_truthToTrack.retrieve().isFailure() ) { + m_log << MSG::FATAL << m_truthToTrack << " truth to track tool not found" << endmsg; + return StatusCode::FAILURE; + } else { + m_log << MSG::INFO << m_truthToTrack << " retrieved" << endmsg; + } + + if( m_extrapolator.retrieve().isFailure() ) { + m_log << MSG::FATAL << m_extrapolator << " extrapolator tool not found" << endmsg; + return StatusCode::FAILURE; + } else { + m_log << MSG::INFO << m_extrapolator << " retrieved" << endmsg; + } + + if( m_beamSpotSvc.retrieve().isFailure() ) { + m_log << MSG::FATAL << m_beamSpotSvc << " beam spot service not found" << endmsg; + return StatusCode::FAILURE; + } else { + m_log << MSG::INFO << m_beamSpotSvc << " retrieved" << endmsg; + } + + if( service("DetectorStore",m_detStore).isFailure() ) { + m_log << MSG::FATAL <<"DetectorStore service not found" << endmsg; + return StatusCode::FAILURE; + } + + IPartPropSvc* partPropSvc = 0; + if( service("PartPropSvc", partPropSvc, true).isFailure() ) { + m_log << MSG::FATAL << "particle properties service unavailable" << endmsg; + return StatusCode::FAILURE; + } + m_particleDataTable = partPropSvc->PDT(); + + // ID helpers + m_idHelper = new AtlasDetectorID; + const IdDictManager* idDictMgr( 0 ); + if( m_detStore->retrieve(idDictMgr, "IdDict").isFailure() || !idDictMgr ) { + m_log << MSG::ERROR << "Could not get IdDictManager !" << endmsg; + return StatusCode::FAILURE; + } + if( m_detStore->retrieve(m_PIX_mgr, "Pixel").isFailure() ) { + m_log << MSG::ERROR << "Unable to retrieve Pixel manager from DetectorStore" << endmsg; + return StatusCode::FAILURE; + } + if( m_detStore->retrieve(m_pixelId, "PixelID").isFailure() ) { + m_log << MSG::ERROR << "Unable to retrieve Pixel helper from DetectorStore" << endmsg; + return StatusCode::FAILURE; + } + if( m_detStore->retrieve(m_SCT_mgr, "SCT").isFailure() ) { + m_log << MSG::ERROR << "Unable to retrieve SCT manager from DetectorStore" << endmsg; + return StatusCode::FAILURE; + } + if( m_detStore->retrieve(m_sctId, "SCT_ID").isFailure() ) { + m_log << MSG::ERROR << "Unable to retrieve SCT helper from DetectorStore" << endmsg; + return StatusCode::FAILURE; + } + + // open output to .bz2 using streams for debug // + if(m_dooutFileRawHits) { + oflraw.reset( new boost::iostreams::filtering_ostream ); + if( !oflraw ) { return StatusCode::FAILURE; } + if( boost::algorithm::icontains(m_outFileNameRawHits,".bz2" ) ) { + boost::iostreams::bzip2_params params; + params.block_size = 9; + oflraw->push( boost::iostreams::bzip2_compressor(params) ); + } + oflraw->push( boost::iostreams::file_sink(m_outFileNameRawHits)); // open the file } - oflraw->push( boost::iostreams::file_sink(m_outFileNameRawHits)); // open the file - } - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } StatusCode FTK_SGHitInput::finalize(){ - MsgStream log(msgSvc(), name()); - m_log << MSG::INFO << "finalized" << endmsg; + MsgStream log(msgSvc(), name()); + m_log << MSG::INFO << "finalized" << endmsg; - if( m_idHelper ) { delete m_idHelper; } + if( m_idHelper ) { delete m_idHelper; } - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } /** initilize for the input */ int FTK_SGHitInput::init(bool*) { - // setup clustering - initClustering(); - return 0; + // setup clustering + initClustering(); + return 0; } /** This function get from the SG the inner detector raw hits - and prepares them for FTK simulation */ + and prepares them for FTK simulation */ int FTK_SGHitInput::readData() { - int res(0); // result of the hit gathering - - // reset internal containers - m_original_hits.clear(); - - const EventInfo* eventInfo(0); - if( m_storeGate->retrieve(eventInfo).isFailure() ) { - m_log << MSG::ERROR << "Could not retrieve event info" << endmsg; - return -1; - } - const EventID* eventID( eventInfo->event_ID() ); - //defult is DEBUG - m_log << MSG::INFO - << "entered execution for run " << eventID->run_number() - << " event " << eventID->event_number() - << endmsg; - - const TriggerInfo *triggerInfo(eventInfo->trigger_info()); - - //Filled to variable / start event - setRunNumber(eventID->run_number()); - setEventNumber(eventID->event_number()); - setLB(eventID->lumi_block()); - setBCID(eventID->bunch_crossing_id()); - setaverageInteractionsPerCrossing(eventInfo->averageInteractionsPerCrossing()); - setactualInteractionsPerCrossing(eventInfo->actualInteractionsPerCrossing()); - setextendedLevel1ID(triggerInfo->extendedLevel1ID() ); - - setlevel1TriggerType(triggerInfo->level1TriggerType () ); - setlevel1TriggerInfo(triggerInfo->level1TriggerInfo ()); - - if(m_dooutFileRawHits){ - (*oflraw) << "R\t" << eventID->run_number()<<'\n'; - (*oflraw) << "F\t" << eventID->event_number()<<'\n'; - } - - - - HitIndexMap hitIndexMap; // keep running index event-unique to each hit - HitIndexMap pixelClusterIndexMap; - // get pixel and sct cluster containers - if( m_storeGate->retrieve(m_pixelContainer, m_pixelClustersName).isFailure() ) { - m_log << MSG::WARNING << "unable to retrieve the PixelCluster container " << m_pixelClustersName << endmsg; - } - if( m_storeGate->retrieve(m_sctContainer, m_sctClustersName).isFailure() ) { - m_log << MSG::WARNING << "unable to retrieve the SCT_Cluster container " << m_sctClustersName << endmsg; - } - - - // dump raw silicon data - m_log << MSG::INFO << "Dump raw silicon data" << endmsg; - read_raw_silicon( hitIndexMap, pixelClusterIndexMap ); - - // *** add other variables in the future (ex) SpacePoint etc... see Dump.cxx *** // - // dump truth tracks - if(m_readTruthTracks) { - m_log << MSG::INFO << "Dump truth tracks" << endmsg; - m_truth_track.clear(); - read_truth_tracks(); - } - // event footer - if(m_dooutFileRawHits)(*oflraw) << "L\t" << eventID->event_number()<<'\n'; - - - - return res; + int res(0); // result of the hit gathering + + // reset internal containers + m_original_hits.clear(); + + const EventInfo* eventInfo(0); + if( m_storeGate->retrieve(eventInfo).isFailure() ) { + m_log << MSG::ERROR << "Could not retrieve event info" << endmsg; + return -1; + } + const EventID* eventID( eventInfo->event_ID() ); + //defult is DEBUG + m_log << MSG::INFO + << "entered execution for run " << eventID->run_number() + << " event " << eventID->event_number() + << endmsg; + + const TriggerInfo *triggerInfo(eventInfo->trigger_info()); + + //Filled to variable / start event + setRunNumber(eventID->run_number()); + setEventNumber(eventID->event_number()); + setLB(eventID->lumi_block()); + setBCID(eventID->bunch_crossing_id()); + setaverageInteractionsPerCrossing(eventInfo->averageInteractionsPerCrossing()); + setactualInteractionsPerCrossing(eventInfo->actualInteractionsPerCrossing()); + setextendedLevel1ID(triggerInfo->extendedLevel1ID() ); + + setlevel1TriggerType(triggerInfo->level1TriggerType () ); + setlevel1TriggerInfo(triggerInfo->level1TriggerInfo ()); + + if(m_dooutFileRawHits){ + (*oflraw) << "R\t" << eventID->run_number()<<'\n'; + (*oflraw) << "F\t" << eventID->event_number()<<'\n'; + } + + + + HitIndexMap hitIndexMap; // keep running index event-unique to each hit + HitIndexMap pixelClusterIndexMap; + // get pixel and sct cluster containers + if( m_storeGate->retrieve(m_pixelContainer, m_pixelClustersName).isFailure() ) { + m_log << MSG::WARNING << "unable to retrieve the PixelCluster container " << m_pixelClustersName << endmsg; + } + if( m_storeGate->retrieve(m_sctContainer, m_sctClustersName).isFailure() ) { + m_log << MSG::WARNING << "unable to retrieve the SCT_Cluster container " << m_sctClustersName << endmsg; + } + + + // dump raw silicon data + m_log << MSG::INFO << "Dump raw silicon data" << endmsg; + read_raw_silicon( hitIndexMap, pixelClusterIndexMap ); + + // *** add other variables in the future (ex) SpacePoint etc... see Dump.cxx *** // + // dump truth tracks + if(m_readTruthTracks) { + m_log << MSG::INFO << "Dump truth tracks" << endmsg; + m_truth_track.clear(); + read_truth_tracks(); + } + // event footer + if(m_dooutFileRawHits)(*oflraw) << "L\t" << eventID->event_number()<<'\n'; + + + + return res; } @@ -281,546 +281,540 @@ int FTK_SGHitInput::readData() void FTK_SGHitInput::read_raw_silicon( HitIndexMap& hitIndexMap, HitIndexMap& pixelClusterIndexMap ) // const cannot make variables push back to DataInput { - using namespace std; - unsigned int hitIndex = 0u; - unsigned int pixelClusterIndex=0; - const DataHandle pixel_rdocontainer_iter; - const InDetSimDataCollection* pixelSimDataMap(0); - const bool have_pixel_sdo = m_storeGate->retrieve(pixelSimDataMap, "PixelSDO_Map").isSuccess(); - if (!have_pixel_sdo) { - m_log << MSG::WARNING << "Missing Pixel SDO Map" << endmsg; - } - else { - m_log << MSG::INFO << "Found Pixel SDO Map" << endmsg; - } - - // push back the hit information to DataInput for HitList , copy from RawInput.cxx - FTKRawHit tmpSGhit; - //tmporary debug to output variables to text file for developer. - - - if( m_storeGate->retrieve(pixel_rdocontainer_iter, "PixelRDOs").isSuccess() ) { - pixel_rdocontainer_iter->clID(); // anything to dereference the DataHandle - for( PixelRDO_Container::const_iterator iColl=pixel_rdocontainer_iter->begin(), fColl=pixel_rdocontainer_iter->end(); iColl!=fColl; ++iColl ) { - const InDetRawDataCollection* pixel_rdoCollection(*iColl); - if( !pixel_rdoCollection ) { continue; } - const int size = pixel_rdoCollection->size(); - m_log << MSG::DEBUG << "Pixel InDetRawDataCollection found with " << size << " RDOs" << endmsg; - // loop on all RDOs - for( DataVector::const_iterator iRDO=pixel_rdoCollection->begin(), fRDO=pixel_rdoCollection->end(); iRDO!=fRDO; ++iRDO ) { - Identifier rdoId = (*iRDO)->identify(); - // get the det element from the det element collection - const InDetDD::SiDetectorElement* sielement = m_PIX_mgr->getDetectorElement(rdoId); assert( sielement); - const InDetDD::SiLocalPosition localPos = sielement->localPositionOfCell(rdoId); - const InDetDD::SiLocalPosition rawPos = sielement->rawLocalPositionOfCell(rdoId); - const Amg::Vector3D gPos( sielement->globalPosition(localPos) ); - // update map between pixel identifier and event-unique hit index. - // ganged pixels (nCells==2) get two entries. - hitIndexMap[rdoId] = hitIndex; - const int nCells = sielement->numberOfConnectedCells( sielement->cellIdOfPosition(rawPos) ); - if( nCells==2 ) { - const InDetDD::SiCellId firstCell = sielement->cellIdOfPosition(rawPos); - const InDetDD::SiCellId tmpCell = sielement->connectedCell(firstCell,1); - const Identifier tmpId = sielement->identifierFromCellId(tmpCell); - hitIndexMap[tmpId] = hitIndex; // add second entry for ganged pixel ID - } - // if there is simulation truth available, try to retrieve the "most likely" barcode for this pixel. - const HepMC::GenParticle* best_parent = 0; - ParentBitmask parent_mask; - HepMcParticleLink::ExtendedBarCode best_extcode; - if( have_pixel_sdo && pixelSimDataMap ) { - InDetSimDataCollection::const_iterator iter( pixelSimDataMap->find(rdoId) ); - // this might be the ganged pixel copy. - if( nCells>1 && iter==pixelSimDataMap->end() ) { - InDetDD::SiReadoutCellId SiRC( m_pixelId->phi_index(rdoId), m_pixelId->eta_index(rdoId) ); - for( int ii=0; iiend(); ++ii ) { - iter = pixelSimDataMap->find(sielement->identifierFromCellId(sielement->design().connectedCell(SiRC,ii))); - } - } // end search for correct ganged pixel - // if SDO found for this pixel, associate the particle. otherwise leave unassociated. - if( iter!=pixelSimDataMap->end() ) { - const InDetSimData& sdo( iter->second ); - const std::vector& deposits( sdo.getdeposits() ); - for( std::vector::const_iterator iDep=deposits.begin(), fDep=deposits.end(); iDep!=fDep; ++iDep ) { - const HepMcParticleLink& particleLink( iDep->first ); - //const InDetSimData::Deposit::second_type qdep( iDep->second ); // energy(charge) contributed by this particle - // RDO's without SDO's are delta rays or detector noise. - if( !particleLink.isValid() ) { continue; } - const HepMC::GenParticle* particle( particleLink ); - const float genEta=particle->momentum().pseudoRapidity(); - const float genPt=particle->momentum().perp(); // MeV - // reject unstable particles - if( particle->status()%1000!=1 ) { continue; } - // reject secondaries and low pT (<400 MeV) pileup - if( particle->barcode()>100000 || particle->barcode()==0 ) { continue; } - // reject far forward particles - if( fabs(genEta)>m_maxEta ) { continue; } - // "best_parent" is the highest pt particle - if( !best_parent || best_parent->momentum().perp()=1000. ) { - // bcs_pt1gev.insert( HepMcParticleLink::ExtendedBarCode( particleLink.barcode() , particleLink.eventIndex() ) ); - // } - // // check whether or not parent is a b - // { - // typedef pair Parent; - // vector parents; - // parents.push_back( Parent(particle,0) ); - // while( !parents.empty() ) { - // const HepMC::GenParticle* p = parents.back().first; - // const unsigned int level = parents.back().second; - // if( std::abs(p->pdg_id())==5 ) { - // bcs_bjet.insert( HepMcParticleLink::ExtendedBarCode( particleLink.barcode() , particleLink.eventIndex() ) ); - // break; - // } - // parents.pop_back(); - // if( !(p->production_vertex()) ) { continue; } - // for( HepMC::GenVertex::particle_iterator i=p->production_vertex()->particles_begin(HepMC::parents), f=p->production_vertex()->particles_end(HepMC::parents); i!=f; ++i ) { - // parents.push_back( Parent(*i,level+1) ); - // } - // } - // } - parent_mask |= construct_truth_bitmap( particle ); - // check SDO - } // end for each contributing particle - } // end if truth found for this pixel - } // end if pixel truth available - ++hitIndex; - - //output// - if(m_dooutFileRawHits){ //bz2 file - (*oflraw) << "S\t" - << setw(14) << setprecision(10) - << gPos.x() << '\t' - << setw(14) << setprecision(10) - << gPos.y() << '\t' - << setw(14) << setprecision(10) - << gPos.z() << '\t' - << 1 << '\t' // 1 pixel 0 sct - << m_pixelId->barrel_ec(rdoId) << '\t' - << m_pixelId->layer_disk(rdoId) << '\t' - << m_pixelId->phi_module(rdoId) << '\t' - << m_pixelId->eta_module(rdoId) << '\t' - << m_pixelId->phi_index(rdoId) << '\t' - << m_pixelId->eta_index(rdoId) << '\t' - << (*iRDO)->getToT() << '\t' - << (long)(best_parent ? best_extcode.eventIndex() : std::numeric_limits::max()) << '\t' - << (long)(best_parent ? best_extcode.barcode() : std::numeric_limits::max()) << '\t' - << setprecision(5) << static_cast(std::ceil(best_parent ? best_parent->momentum().perp() : 0.)) << '\t' // particle pt in MeV - << parent_mask.to_ulong() << '\t' - << endl; - } - // push back the hit information to DataInput for HitList , copy from RawInput.cxx - tmpSGhit.reset(); - tmpSGhit.setX(gPos.x()); - tmpSGhit.setY(gPos.y()); - tmpSGhit.setZ(gPos.z()); - tmpSGhit.setHitType(ftk::PIXEL); - - bool isIBL = (m_pixelId->barrel_ec(rdoId) == 0 && m_pixelId->layer_disk(rdoId) == 0) ? true : false; - bool isIBL3D = (isIBL && FTKSetup::getFTKSetup().getIBLMode() == 2 && - (m_pixelId->eta_module(rdoId) <= -7 || m_pixelId->eta_module(rdoId) >= 6)) ? true : false; - - if (isIBL3D) - tmpSGhit.setModuleType(ftk::MODULETYPE_IBL3D); - else if (isIBL) - tmpSGhit.setModuleType(ftk::MODULETYPE_IBL_PLANAR); - else - tmpSGhit.setModuleType(ftk::MODULETYPE_PIXEL); - - tmpSGhit.setIdentifierHash(sielement->identifyHash()); - tmpSGhit.setBarrelEC(m_pixelId->barrel_ec(rdoId)); - tmpSGhit.setLayer( m_pixelId->layer_disk(rdoId)); - tmpSGhit.setPhiModule(m_pixelId->phi_module(rdoId)); - tmpSGhit.setEtaModule(m_pixelId->eta_module(rdoId)); - tmpSGhit.setPhiSide(m_pixelId->phi_index(rdoId)); - tmpSGhit.setEtaStrip(m_pixelId->eta_index(rdoId)); - tmpSGhit.setNStrips((*iRDO)->getToT()); - tmpSGhit.setEventIndex((long)(best_parent ? best_extcode.eventIndex() : std::numeric_limits::max())); - tmpSGhit.setBarcode((long)(best_parent ? best_extcode.barcode() : std::numeric_limits::max())); - tmpSGhit.setBarcodePt( static_cast(std::ceil(best_parent ? best_parent->momentum().perp() : 0.)) ); - tmpSGhit.setParentageMask(parent_mask.to_ulong()); - tmpSGhit.normalizeLayerID(); // Change layer info from atlas geo to FTK geo - //cout << "DBGBC Pxl " << tmpSGhit.getEventIndex() << ", " << tmpSGhit.getBarcode() << endl; - if (abs(m_pixelId->barrel_ec(rdoId)) != 4) // JAAA skip diamonds! - m_original_hits.push_back(tmpSGhit); - } // end for each RDO in the collection - } // for each pixel RDO collection - // dump all pixel RDO's and SDO's for debugging purposes - if( false ) { - for( PixelRDO_Container::const_iterator iColl=pixel_rdocontainer_iter->begin(), fColl=pixel_rdocontainer_iter->end(); iColl!=fColl; ++iColl ) { - const InDetRawDataCollection* pixel_rdoCollection(*iColl); - if( !pixel_rdoCollection ) { continue; } - for( DataVector::const_iterator iRDO=pixel_rdoCollection->begin(), fRDO=pixel_rdoCollection->end(); iRDO!=fRDO; ++iRDO ) { - Identifier rdoId = (*iRDO)->identify(); - // get the det element from the det element collection - const InDetDD::SiDetectorElement* sielement = m_PIX_mgr->getDetectorElement(rdoId); assert( sielement); - const InDetDD::SiLocalPosition localPos = sielement->localPositionOfCell(rdoId); - const InDetDD::SiLocalPosition rawPos = sielement->rawLocalPositionOfCell(rdoId); - const Amg::Vector3D gPos( sielement->globalPosition(localPos) ); - if(m_dooutFileRawHits){ - (*oflraw) << "# S\t" - << setw(14) << setprecision(10) - << gPos.x() << '\t' - << setw(14) << setprecision(10) - << gPos.y() << '\t' - << setw(14) << setprecision(10) - << gPos.z() << '\t' - << 1 << '\t' // 1 pixel 0 sct - << m_pixelId->barrel_ec(rdoId) << '\t' - << m_pixelId->layer_disk(rdoId) << '\t' - << m_pixelId->phi_module(rdoId) << '\t' - << m_pixelId->eta_module(rdoId) << '\t' - << m_pixelId->phi_index(rdoId) << '\t' - << m_pixelId->eta_index(rdoId) << '\t' - << (*iRDO)->getToT() << '\t' - << endl; - } - } // end for each pixel RDO - } // end for each pixel RDO collection - // dump SDO's - if( have_pixel_sdo && pixelSimDataMap ) { - for( InDetSimDataCollection::const_iterator i=pixelSimDataMap->begin(), f=pixelSimDataMap->end(); i!=f; ++i ) { - const Identifier sdoId( i->first ); - const InDetSimData& sdo( i->second ); - const vector& deposits( sdo.getdeposits() ); - (*oflraw) << "# s" - << " " << m_pixelId->barrel_ec(sdoId) - << " " << m_pixelId->layer_disk(sdoId) - << " " << m_pixelId->phi_module(sdoId) - << " " << m_pixelId->eta_module(sdoId) - << " " << m_pixelId->phi_index(sdoId) - << " " << m_pixelId->eta_index(sdoId) - << " " << PixelSimHelper::isNoise( sdo ) - << " " << PixelSimHelper::isBelowThreshold( sdo ) - << " " << PixelSimHelper::isDisabled( sdo ) - << " " << PixelSimHelper::hasBadTOT( sdo ) - << " " << deposits.size() - << endl; - for( vector::const_iterator iDep=deposits.begin(), fDep=deposits.end(); iDep!=fDep; ++iDep ) { - const HepMcParticleLink& particleLink( iDep->first ); - const InDetSimData::Deposit::second_type qdep( iDep->second ); // energy(charge) contributed by this particle - (*oflraw) << "# s q " << qdep << " " << particleLink.isValid() << " " - << (particleLink.isValid() ? particleLink.eventIndex() : -1) - << (particleLink.isValid() ? particleLink.barcode() : -1) - << endl; - } // end for each deposit in SDO - } // end for each pixel SDO - } // if have sdo info - } // end dump RDO's and SDO's for debugging purposes - } // dump raw pixel data - const InDetSimDataCollection* sctSimDataMap(0); - const bool have_sct_sdo = m_storeGate->retrieve(sctSimDataMap, "SCT_SDO_Map").isSuccess(); - if (!have_sct_sdo) { - m_log << MSG::WARNING << "Missing SCT SDO Map" << endmsg; - } - else { - m_log << MSG::INFO << "Found SCT SDO Map" << endmsg; - } - - const DataHandle sct_rdocontainer_iter; - if( m_storeGate->retrieve(sct_rdocontainer_iter, "SCT_RDOs").isSuccess() ) { - sct_rdocontainer_iter->clID(); // anything to dereference the DataHandle - for( SCT_RDO_Container::const_iterator iColl=sct_rdocontainer_iter->begin(), fColl=sct_rdocontainer_iter->end(); iColl!=fColl; ++iColl ) { - const InDetRawDataCollection* SCT_Collection(*iColl); - if( !SCT_Collection ) { continue; } - const int size = SCT_Collection->size(); - m_log << MSG::DEBUG << "SCT InDetRawDataCollection found with " << size << " RDOs" << endmsg; - for( DataVector::const_iterator iRDO=SCT_Collection->begin(), fRDO=SCT_Collection->end(); iRDO!=fRDO; ++iRDO ) { - const Identifier rdoId = (*iRDO)->identify(); - // get the det element from the det element collection - const InDetDD::SiDetectorElement* sielement = m_SCT_mgr->getDetectorElement(rdoId); - const InDetDD::SCT_ModuleSideDesign& design = dynamic_cast(sielement->design()); - const InDetDD::SiLocalPosition localPos = design.positionFromStrip(m_sctId->strip(rdoId)); - const Amg::Vector3D gPos = sielement->globalPosition(localPos); - hitIndexMap[rdoId] = hitIndex; - ++hitIndex; - // if there is simulation truth available, try to retrieve the - // "most likely" barcode for this strip. - const HepMC::GenParticle* best_parent = 0; - ParentBitmask parent_mask; - HepMcParticleLink::ExtendedBarCode best_extcode; - if( have_sct_sdo && sctSimDataMap ) { - InDetSimDataCollection::const_iterator iter( sctSimDataMap->find(rdoId) ); - // if SDO found for this pixel, associate the particle - if( iter!=sctSimDataMap->end() ) { - const InDetSimData& sdo( iter->second ); - const std::vector& deposits( sdo.getdeposits() ); - for( std::vector::const_iterator iDep=deposits.begin(), fDep=deposits.end(); iDep!=fDep; ++iDep ) { - const HepMcParticleLink& particleLink( iDep->first ); - // const InDetSimData::Deposit::second_type qdep( iDep->second ); // energy(charge) contributed by this particle - // RDO's without SDO's are delta rays or detector noise. - if( !particleLink.isValid() ) { continue; } - const HepMC::GenParticle* particle( particleLink ); - const float genEta=particle->momentum().pseudoRapidity(); - const float genPt=particle->momentum().perp(); // MeV - // reject unstable particles - if( particle->status()%1000!=1 ) { continue; } - // reject secondaries and low pt (<400 MeV) pileup truth - if( particle->barcode()>100000 || particle->barcode()==0 ) { continue; } - // reject far forward particles - if( fabs(genEta)>m_maxEta ) { continue; } - // "best_parent" is the highest pt particle - if( !best_parent || best_parent->momentum().perp()=1000. ) { - // bcs_pt1gev.insert( HepMcParticleLink::ExtendedBarCode( particleLink.barcode() , particleLink.eventIndex() ) ); - // } - // { - // typedef pair Parent; - // vector parents; - // parents.push_back( Parent(particle,0) ); - // while( !parents.empty() ) { - // const HepMC::GenParticle* p = parents.back().first; - // const unsigned int level = parents.back().second; - // if( std::abs(p->pdg_id())==5 ) { - // bcs_bjet.insert( HepMcParticleLink::ExtendedBarCode( particleLink.barcode() , particleLink.eventIndex() ) ); - // break; - // } - // parents.pop_back(); - // if( !(p->production_vertex()) ) { continue; } - // for( HepMC::GenVertex::particle_iterator i=p->production_vertex()->particles_begin(HepMC::parents), f=p->production_vertex()->particles_end(HepMC::parents); i!=f; ++i ) { - // parents.push_back( Parent(*i,level+1) ); - // } - // } - // } - parent_mask |= construct_truth_bitmap( particle ); - } // end for each contributing particle - } // end if truth found for this strip - } // end if sct truth available - if(m_dooutFileRawHits){ - (*oflraw) << "S\t" - << setw(14) << setprecision(10) - << gPos.x() << '\t' - << setw(14) << setprecision(10) - << gPos.y() << '\t' - << setw(14) << setprecision(10) - << gPos.z() << '\t' - << 0 << '\t' // 1 pixel 0 sct - << m_sctId->barrel_ec(rdoId) << '\t' - << m_sctId->layer_disk(rdoId) << '\t' - << m_sctId->phi_module(rdoId) << '\t' - << m_sctId->eta_module(rdoId) << '\t' - << m_sctId->side(rdoId) << '\t' - << m_sctId->strip(rdoId) << '\t' - << (*iRDO)->getGroupSize() << '\t' - << (long)(best_parent ? best_extcode.eventIndex() : std::numeric_limits::max()) << '\t' - << (long)(best_parent ? best_extcode.barcode() : std::numeric_limits::max()) << '\t' - << setprecision(5) << static_cast(std::ceil(best_parent ? best_parent->momentum().perp() : 0.)) << '\t' // particle pt in MeV - << parent_mask.to_ulong() << '\t' - << '\n'; + using namespace std; + unsigned int hitIndex = 0u; + unsigned int pixelClusterIndex=0; + const DataHandle pixel_rdocontainer_iter; + const InDetSimDataCollection* pixelSimDataMap(0); + const bool have_pixel_sdo = m_storeGate->retrieve(pixelSimDataMap, "PixelSDO_Map").isSuccess(); + if (!have_pixel_sdo) { + m_log << MSG::WARNING << "Missing Pixel SDO Map" << endmsg; + } + else { + m_log << MSG::INFO << "Found Pixel SDO Map" << endmsg; + } + + // push back the hit information to DataInput for HitList , copy from RawInput.cxx + FTKRawHit tmpSGhit; + //tmporary debug to output variables to text file for developer. + + + if( m_storeGate->retrieve(pixel_rdocontainer_iter, "PixelRDOs").isSuccess() ) { + pixel_rdocontainer_iter->clID(); // anything to dereference the DataHandle + for( PixelRDO_Container::const_iterator iColl=pixel_rdocontainer_iter->begin(), fColl=pixel_rdocontainer_iter->end(); iColl!=fColl; ++iColl ) { + const InDetRawDataCollection* pixel_rdoCollection(*iColl); + if( !pixel_rdoCollection ) { continue; } + const int size = pixel_rdoCollection->size(); + m_log << MSG::DEBUG << "Pixel InDetRawDataCollection found with " << size << " RDOs" << endmsg; + // loop on all RDOs + for( DataVector::const_iterator iRDO=pixel_rdoCollection->begin(), fRDO=pixel_rdoCollection->end(); iRDO!=fRDO; ++iRDO ) { + Identifier rdoId = (*iRDO)->identify(); + // get the det element from the det element collection + const InDetDD::SiDetectorElement* sielement = m_PIX_mgr->getDetectorElement(rdoId); assert( sielement); + const InDetDD::SiLocalPosition localPos = sielement->localPositionOfCell(rdoId); + const InDetDD::SiLocalPosition rawPos = sielement->rawLocalPositionOfCell(rdoId); + const Amg::Vector3D gPos( sielement->globalPosition(localPos) ); + // update map between pixel identifier and event-unique hit index. + // ganged pixels (nCells==2) get two entries. + hitIndexMap[rdoId] = hitIndex; + const int nCells = sielement->numberOfConnectedCells( sielement->cellIdOfPosition(rawPos) ); + if( nCells==2 ) { + const InDetDD::SiCellId firstCell = sielement->cellIdOfPosition(rawPos); + const InDetDD::SiCellId tmpCell = sielement->connectedCell(firstCell,1); + const Identifier tmpId = sielement->identifierFromCellId(tmpCell); + hitIndexMap[tmpId] = hitIndex; // add second entry for ganged pixel ID + } + // if there is simulation truth available, try to retrieve the "most likely" barcode for this pixel. + const HepMC::GenParticle* best_parent = 0; + ParentBitmask parent_mask; + HepMcParticleLink::ExtendedBarCode best_extcode; + if( have_pixel_sdo && pixelSimDataMap ) { + InDetSimDataCollection::const_iterator iter( pixelSimDataMap->find(rdoId) ); + // this might be the ganged pixel copy. + if( nCells>1 && iter==pixelSimDataMap->end() ) { + InDetDD::SiReadoutCellId SiRC( m_pixelId->phi_index(rdoId), m_pixelId->eta_index(rdoId) ); + for( int ii=0; iiend(); ++ii ) { + iter = pixelSimDataMap->find(sielement->identifierFromCellId(sielement->design().connectedCell(SiRC,ii))); + } + } // end search for correct ganged pixel + // if SDO found for this pixel, associate the particle. otherwise leave unassociated. + if( iter!=pixelSimDataMap->end() ) { + const InDetSimData& sdo( iter->second ); + const std::vector& deposits( sdo.getdeposits() ); + for( std::vector::const_iterator iDep=deposits.begin(), fDep=deposits.end(); iDep!=fDep; ++iDep ) { + const HepMcParticleLink& particleLink( iDep->first ); + //const InDetSimData::Deposit::second_type qdep( iDep->second ); // energy(charge) contributed by this particle + // RDO's without SDO's are delta rays or detector noise. + if( !particleLink.isValid() ) { continue; } + const HepMC::GenParticle* particle( particleLink ); + const float genEta=particle->momentum().pseudoRapidity(); + const float genPt=particle->momentum().perp(); // MeV + // reject unstable particles + if( particle->status()%1000!=1 ) { continue; } + // reject secondaries and low pT (<400 MeV) pileup + if( particle->barcode()>100000 || particle->barcode()==0 ) { continue; } + // reject far forward particles + if( fabs(genEta)>m_maxEta ) { continue; } + // "best_parent" is the highest pt particle + if( !best_parent || best_parent->momentum().perp()=1000. ) { + // bcs_pt1gev.insert( HepMcParticleLink::ExtendedBarCode( particleLink.barcode() , particleLink.eventIndex() ) ); + // } + // // check whether or not parent is a b + // { + // typedef pair Parent; + // vector parents; + // parents.push_back( Parent(particle,0) ); + // while( !parents.empty() ) { + // const HepMC::GenParticle* p = parents.back().first; + // const unsigned int level = parents.back().second; + // if( std::abs(p->pdg_id())==5 ) { + // bcs_bjet.insert( HepMcParticleLink::ExtendedBarCode( particleLink.barcode() , particleLink.eventIndex() ) ); + // break; + // } + // parents.pop_back(); + // if( !(p->production_vertex()) ) { continue; } + // for( HepMC::GenVertex::particle_iterator i=p->production_vertex()->particles_begin(HepMC::parents), f=p->production_vertex()->particles_end(HepMC::parents); i!=f; ++i ) { + // parents.push_back( Parent(*i,level+1) ); + // } + // } + // } + parent_mask |= construct_truth_bitmap( particle ); + // check SDO + } // end for each contributing particle + } // end if truth found for this pixel + } // end if pixel truth available + ++hitIndex; + + //output// + if(m_dooutFileRawHits){ //bz2 file + (*oflraw) << "S\t" + << setw(14) << setprecision(10) + << gPos.x() << '\t' + << setw(14) << setprecision(10) + << gPos.y() << '\t' + << setw(14) << setprecision(10) + << gPos.z() << '\t' + << 1 << '\t' // 1 pixel 0 sct + << m_pixelId->barrel_ec(rdoId) << '\t' + << m_pixelId->layer_disk(rdoId) << '\t' + << m_pixelId->phi_module(rdoId) << '\t' + << m_pixelId->eta_module(rdoId) << '\t' + << m_pixelId->phi_index(rdoId) << '\t' + << m_pixelId->eta_index(rdoId) << '\t' + << (*iRDO)->getToT() << '\t' + << (long)(best_parent ? best_extcode.eventIndex() : std::numeric_limits::max()) << '\t' + << (long)(best_parent ? best_extcode.barcode() : std::numeric_limits::max()) << '\t' + << setprecision(5) << static_cast(std::ceil(best_parent ? best_parent->momentum().perp() : 0.)) << '\t' // particle pt in MeV + << parent_mask.to_ulong() << '\t' + << endl; + } + // push back the hit information to DataInput for HitList , copy from RawInput.cxx + tmpSGhit.reset(); + tmpSGhit.setHitType(ftk::PIXEL); + + bool isIBL = (m_pixelId->barrel_ec(rdoId) == 0 && m_pixelId->layer_disk(rdoId) == 0) ? true : false; + bool isIBL3D = (isIBL && FTKSetup::getFTKSetup().getIBLMode() == 2 && + (m_pixelId->eta_module(rdoId) <= -7 || m_pixelId->eta_module(rdoId) >= 6)) ? true : false; + + if (isIBL3D) + tmpSGhit.setModuleType(ftk::MODULETYPE_IBL3D); + else if (isIBL) + tmpSGhit.setModuleType(ftk::MODULETYPE_IBL_PLANAR); + else + tmpSGhit.setModuleType(ftk::MODULETYPE_PIXEL); + + tmpSGhit.setIdentifierHash(sielement->identifyHash()); + tmpSGhit.setBarrelEC(m_pixelId->barrel_ec(rdoId)); + tmpSGhit.setLayer( m_pixelId->layer_disk(rdoId)); + tmpSGhit.setPhiModule(m_pixelId->phi_module(rdoId)); + tmpSGhit.setEtaModule(m_pixelId->eta_module(rdoId)); + tmpSGhit.setPhiSide(m_pixelId->phi_index(rdoId)); + tmpSGhit.setEtaStrip(m_pixelId->eta_index(rdoId)); + tmpSGhit.setNStrips((*iRDO)->getToT()); + tmpSGhit.setEventIndex((long)(best_parent ? best_extcode.eventIndex() : std::numeric_limits::max())); + tmpSGhit.setBarcode((long)(best_parent ? best_extcode.barcode() : std::numeric_limits::max())); + tmpSGhit.setBarcodePt( static_cast(std::ceil(best_parent ? best_parent->momentum().perp() : 0.)) ); + tmpSGhit.setParentageMask(parent_mask.to_ulong()); + tmpSGhit.normalizeLayerID(); // Change layer info from atlas geo to FTK geo + //cout << "DBGBC Pxl " << tmpSGhit.getEventIndex() << ", " << tmpSGhit.getBarcode() << endl; + if (abs(m_pixelId->barrel_ec(rdoId)) != 4) // JAAA skip diamonds! + m_original_hits.push_back(tmpSGhit); + } // end for each RDO in the collection + } // for each pixel RDO collection + // dump all pixel RDO's and SDO's for debugging purposes + if( false ) { + for( PixelRDO_Container::const_iterator iColl=pixel_rdocontainer_iter->begin(), fColl=pixel_rdocontainer_iter->end(); iColl!=fColl; ++iColl ) { + const InDetRawDataCollection* pixel_rdoCollection(*iColl); + if( !pixel_rdoCollection ) { continue; } + for( DataVector::const_iterator iRDO=pixel_rdoCollection->begin(), fRDO=pixel_rdoCollection->end(); iRDO!=fRDO; ++iRDO ) { + Identifier rdoId = (*iRDO)->identify(); + // get the det element from the det element collection + const InDetDD::SiDetectorElement* sielement = m_PIX_mgr->getDetectorElement(rdoId); assert( sielement); + const InDetDD::SiLocalPosition localPos = sielement->localPositionOfCell(rdoId); + const InDetDD::SiLocalPosition rawPos = sielement->rawLocalPositionOfCell(rdoId); + const Amg::Vector3D gPos( sielement->globalPosition(localPos) ); + if(m_dooutFileRawHits){ + (*oflraw) << "# S\t" + << setw(14) << setprecision(10) + << gPos.x() << '\t' + << setw(14) << setprecision(10) + << gPos.y() << '\t' + << setw(14) << setprecision(10) + << gPos.z() << '\t' + << 1 << '\t' // 1 pixel 0 sct + << m_pixelId->barrel_ec(rdoId) << '\t' + << m_pixelId->layer_disk(rdoId) << '\t' + << m_pixelId->phi_module(rdoId) << '\t' + << m_pixelId->eta_module(rdoId) << '\t' + << m_pixelId->phi_index(rdoId) << '\t' + << m_pixelId->eta_index(rdoId) << '\t' + << (*iRDO)->getToT() << '\t' + << endl; + } + } // end for each pixel RDO + } // end for each pixel RDO collection + // dump SDO's + if( have_pixel_sdo && pixelSimDataMap ) { + for( InDetSimDataCollection::const_iterator i=pixelSimDataMap->begin(), f=pixelSimDataMap->end(); i!=f; ++i ) { + const Identifier sdoId( i->first ); + const InDetSimData& sdo( i->second ); + const vector& deposits( sdo.getdeposits() ); + (*oflraw) << "# s" + << " " << m_pixelId->barrel_ec(sdoId) + << " " << m_pixelId->layer_disk(sdoId) + << " " << m_pixelId->phi_module(sdoId) + << " " << m_pixelId->eta_module(sdoId) + << " " << m_pixelId->phi_index(sdoId) + << " " << m_pixelId->eta_index(sdoId) + << " " << PixelSimHelper::isNoise( sdo ) + << " " << PixelSimHelper::isBelowThreshold( sdo ) + << " " << PixelSimHelper::isDisabled( sdo ) + << " " << PixelSimHelper::hasBadTOT( sdo ) + << " " << deposits.size() + << endl; + for( vector::const_iterator iDep=deposits.begin(), fDep=deposits.end(); iDep!=fDep; ++iDep ) { + const HepMcParticleLink& particleLink( iDep->first ); + const InDetSimData::Deposit::second_type qdep( iDep->second ); // energy(charge) contributed by this particle + (*oflraw) << "# s q " << qdep << " " << particleLink.isValid() << " " + << (particleLink.isValid() ? particleLink.eventIndex() : -1) + << (particleLink.isValid() ? particleLink.barcode() : -1) + << endl; + } // end for each deposit in SDO + } // end for each pixel SDO + } // if have sdo info + } // end dump RDO's and SDO's for debugging purposes + } // dump raw pixel data + const InDetSimDataCollection* sctSimDataMap(0); + const bool have_sct_sdo = m_storeGate->retrieve(sctSimDataMap, "SCT_SDO_Map").isSuccess(); + if (!have_sct_sdo) { + m_log << MSG::WARNING << "Missing SCT SDO Map" << endmsg; + } + else { + m_log << MSG::INFO << "Found SCT SDO Map" << endmsg; + } + + const DataHandle sct_rdocontainer_iter; + if( m_storeGate->retrieve(sct_rdocontainer_iter, "SCT_RDOs").isSuccess() ) { + sct_rdocontainer_iter->clID(); // anything to dereference the DataHandle + for( SCT_RDO_Container::const_iterator iColl=sct_rdocontainer_iter->begin(), fColl=sct_rdocontainer_iter->end(); iColl!=fColl; ++iColl ) { + const InDetRawDataCollection* SCT_Collection(*iColl); + if( !SCT_Collection ) { continue; } + const int size = SCT_Collection->size(); + m_log << MSG::DEBUG << "SCT InDetRawDataCollection found with " << size << " RDOs" << endmsg; + for( DataVector::const_iterator iRDO=SCT_Collection->begin(), fRDO=SCT_Collection->end(); iRDO!=fRDO; ++iRDO ) { + const Identifier rdoId = (*iRDO)->identify(); + // get the det element from the det element collection + const InDetDD::SiDetectorElement* sielement = m_SCT_mgr->getDetectorElement(rdoId); + const InDetDD::SCT_ModuleSideDesign& design = dynamic_cast(sielement->design()); + const InDetDD::SiLocalPosition localPos = design.positionFromStrip(m_sctId->strip(rdoId)); + const Amg::Vector3D gPos = sielement->globalPosition(localPos); + hitIndexMap[rdoId] = hitIndex; + ++hitIndex; + // if there is simulation truth available, try to retrieve the + // "most likely" barcode for this strip. + const HepMC::GenParticle* best_parent = 0; + ParentBitmask parent_mask; + HepMcParticleLink::ExtendedBarCode best_extcode; + if( have_sct_sdo && sctSimDataMap ) { + InDetSimDataCollection::const_iterator iter( sctSimDataMap->find(rdoId) ); + // if SDO found for this pixel, associate the particle + if( iter!=sctSimDataMap->end() ) { + const InDetSimData& sdo( iter->second ); + const std::vector& deposits( sdo.getdeposits() ); + for( std::vector::const_iterator iDep=deposits.begin(), fDep=deposits.end(); iDep!=fDep; ++iDep ) { + const HepMcParticleLink& particleLink( iDep->first ); + // const InDetSimData::Deposit::second_type qdep( iDep->second ); // energy(charge) contributed by this particle + // RDO's without SDO's are delta rays or detector noise. + if( !particleLink.isValid() ) { continue; } + const HepMC::GenParticle* particle( particleLink ); + const float genEta=particle->momentum().pseudoRapidity(); + const float genPt=particle->momentum().perp(); // MeV + // reject unstable particles + if( particle->status()%1000!=1 ) { continue; } + // reject secondaries and low pt (<400 MeV) pileup truth + if( particle->barcode()>100000 || particle->barcode()==0 ) { continue; } + // reject far forward particles + if( fabs(genEta)>m_maxEta ) { continue; } + // "best_parent" is the highest pt particle + if( !best_parent || best_parent->momentum().perp()=1000. ) { + // bcs_pt1gev.insert( HepMcParticleLink::ExtendedBarCode( particleLink.barcode() , particleLink.eventIndex() ) ); + // } + // { + // typedef pair Parent; + // vector parents; + // parents.push_back( Parent(particle,0) ); + // while( !parents.empty() ) { + // const HepMC::GenParticle* p = parents.back().first; + // const unsigned int level = parents.back().second; + // if( std::abs(p->pdg_id())==5 ) { + // bcs_bjet.insert( HepMcParticleLink::ExtendedBarCode( particleLink.barcode() , particleLink.eventIndex() ) ); + // break; + // } + // parents.pop_back(); + // if( !(p->production_vertex()) ) { continue; } + // for( HepMC::GenVertex::particle_iterator i=p->production_vertex()->particles_begin(HepMC::parents), f=p->production_vertex()->particles_end(HepMC::parents); i!=f; ++i ) { + // parents.push_back( Parent(*i,level+1) ); + // } + // } + // } + parent_mask |= construct_truth_bitmap( particle ); + } // end for each contributing particle + } // end if truth found for this strip + } // end if sct truth available + if(m_dooutFileRawHits){ + (*oflraw) << "S\t" + << setw(14) << setprecision(10) + << gPos.x() << '\t' + << setw(14) << setprecision(10) + << gPos.y() << '\t' + << setw(14) << setprecision(10) + << gPos.z() << '\t' + << 0 << '\t' // 1 pixel 0 sct + << m_sctId->barrel_ec(rdoId) << '\t' + << m_sctId->layer_disk(rdoId) << '\t' + << m_sctId->phi_module(rdoId) << '\t' + << m_sctId->eta_module(rdoId) << '\t' + << m_sctId->side(rdoId) << '\t' + << m_sctId->strip(rdoId) << '\t' + << (*iRDO)->getGroupSize() << '\t' + << (long)(best_parent ? best_extcode.eventIndex() : std::numeric_limits::max()) << '\t' + << (long)(best_parent ? best_extcode.barcode() : std::numeric_limits::max()) << '\t' + << setprecision(5) << static_cast(std::ceil(best_parent ? best_parent->momentum().perp() : 0.)) << '\t' // particle pt in MeV + << parent_mask.to_ulong() << '\t' + << '\n'; + } + // push back the hit information to DataInput for HitList , copy from RawInput.cxx + tmpSGhit.reset(); + tmpSGhit.setHitType(ftk::SCT); + tmpSGhit.setModuleType(ftk::MODULETYPE_SCT); + tmpSGhit.setIdentifierHash(sielement->identifyHash()); + tmpSGhit.setBarrelEC(m_sctId->barrel_ec(rdoId)); + tmpSGhit.setLayer(m_sctId->layer_disk(rdoId)); + tmpSGhit.setPhiModule(m_sctId->phi_module(rdoId)); + tmpSGhit.setEtaModule(m_sctId->eta_module(rdoId)); + tmpSGhit.setPhiSide(m_sctId->side(rdoId)); + tmpSGhit.setEtaStrip(m_sctId->strip(rdoId)); + tmpSGhit.setNStrips((*iRDO)->getGroupSize()); + tmpSGhit.setEventIndex((long)(best_parent ? best_extcode.eventIndex() : std::numeric_limits::max())); + tmpSGhit.setBarcode((long)(best_parent ? best_extcode.barcode() : std::numeric_limits::max())); + tmpSGhit.setBarcodePt( static_cast(std::ceil(best_parent ? best_parent->momentum().perp() : 0.)) ); + tmpSGhit.setParentageMask(parent_mask.to_ulong()); + tmpSGhit.normalizeLayerID(); // Change layer info from atlas geo to FTK geo + //cout << "DBGBC SCT " << tmpSGhit.getEventIndex() << ", " << tmpSGhit.getBarcode() << endl; + m_original_hits.push_back(tmpSGhit); + } // end for each RDO in the strip collection + } // end for each strip RDO collection + // dump all RDO's and SDO's for a given event, for debugging purposes + if( false ) { + // dump SCT RDO's + for( SCT_RDO_Container::const_iterator iColl=sct_rdocontainer_iter->begin(), fColl=sct_rdocontainer_iter->end(); iColl!=fColl; ++iColl ) { + const InDetRawDataCollection* SCT_Collection(*iColl); + if( !SCT_Collection ) { continue; } + const int size = SCT_Collection->size(); + m_log << MSG::DEBUG << "SCT InDetRawDataCollection found with " << size << " RDOs" << endmsg; + for( DataVector::const_iterator iRDO=SCT_Collection->begin(), fRDO=SCT_Collection->end(); iRDO!=fRDO; ++iRDO ) { + const Identifier rdoId = (*iRDO)->identify(); + const InDetDD::SiDetectorElement* sielement = m_SCT_mgr->getDetectorElement(rdoId); + const InDetDD::SCT_ModuleSideDesign& design = dynamic_cast(sielement->design()); + const InDetDD::SiLocalPosition localPos = design.positionFromStrip(m_sctId->strip(rdoId)); + const Amg::Vector3D gPos = sielement->globalPosition(localPos); + + if(m_dooutFileRawHits){ + (*oflraw) << "# S\t" + << setw(14) << setprecision(10) + << gPos.x() << '\t' + << setw(14) << setprecision(10) + << gPos.y() << '\t' + << setw(14) << setprecision(10) + << gPos.z() << '\t' + << 0 << '\t' // 1 pixel 0 sct + << m_sctId->barrel_ec(rdoId) << '\t' + << m_sctId->layer_disk(rdoId) << '\t' + << m_sctId->phi_module(rdoId) << '\t' + << m_sctId->eta_module(rdoId) << '\t' + << m_sctId->side(rdoId) << '\t' + << m_sctId->strip(rdoId) << '\t' + << (*iRDO)->getGroupSize() << '\t' + << endl; + } + } // end for each SCT rdo + } // end for each SCT rdo collection + // dump SCT SDO's + if( have_sct_sdo && sctSimDataMap ) { + for( InDetSimDataCollection::const_iterator i=sctSimDataMap->begin(), f=sctSimDataMap->end(); i!=f; ++i ) { + const Identifier sdoId( i->first ); + const InDetSimData& sdo( i->second ); + const vector& deposits( sdo.getdeposits() ); + if(m_dooutFileRawHits){ + (*oflraw) << "# s" + << " " << m_sctId->barrel_ec(sdoId) + << " " << m_sctId->layer_disk(sdoId) + << " " << m_sctId->phi_module(sdoId) + << " " << m_sctId->eta_module(sdoId) + << " " << m_sctId->side(sdoId) + << " " << m_sctId->strip(sdoId) + << " " << SCT_SimHelper::isNoise( sdo ) + << " " << SCT_SimHelper::isBelowThreshold( sdo ) + << " " << SCT_SimHelper::isDisabled( sdo ) + << " " << deposits.size() + << endl; + } + for( vector::const_iterator iDep=deposits.begin(), fDep=deposits.end(); iDep!=fDep; ++iDep ) { + const HepMcParticleLink& particleLink( iDep->first ); + const InDetSimData::Deposit::second_type qdep( iDep->second ); // energy(charge) contributed by this particle + if(m_dooutFileRawHits){ + (*oflraw) << "# s q " << qdep << " " << particleLink.isValid() << " " + << (particleLink.isValid() ? particleLink.eventIndex() : -1) + << (particleLink.isValid() ? particleLink.barcode() : -1) + << endl; + } + } // end for each deposit associated with this SDO + } // end for each SCT SDO + } // end if SDO's available, dump them + } // end dump all RDO's and SDO's for a given event + } // end dump raw SCT data + + // FlagJT dump pixel clusters. They're in m_pixelContainer + m_pixelContainer->clID(); // anything to dereference the DataHandle + for( InDet::SiClusterContainer::const_iterator iColl=m_pixelContainer->begin(), fColl=m_pixelContainer->end(); iColl!=fColl; ++iColl ) { + const InDet::SiClusterCollection* pixelClusterCollection(*iColl); + if( !pixelClusterCollection ) { + m_log << MSG::DEBUG << "pixelClusterCollection not available!" << endmsg; + continue; } - // push back the hit information to DataInput for HitList , copy from RawInput.cxx - tmpSGhit.reset(); - tmpSGhit.setX(gPos.x()); - tmpSGhit.setY(gPos.y()); - tmpSGhit.setZ(gPos.z()); - tmpSGhit.setHitType(ftk::SCT); - tmpSGhit.setModuleType(ftk::MODULETYPE_SCT); - tmpSGhit.setIdentifierHash(sielement->identifyHash()); - tmpSGhit.setBarrelEC(m_sctId->barrel_ec(rdoId)); - tmpSGhit.setLayer(m_sctId->layer_disk(rdoId)); - tmpSGhit.setPhiModule(m_sctId->phi_module(rdoId)); - tmpSGhit.setEtaModule(m_sctId->eta_module(rdoId)); - tmpSGhit.setPhiSide(m_sctId->side(rdoId)); - tmpSGhit.setEtaStrip(m_sctId->strip(rdoId)); - tmpSGhit.setNStrips((*iRDO)->getGroupSize()); - tmpSGhit.setEventIndex((long)(best_parent ? best_extcode.eventIndex() : std::numeric_limits::max())); - tmpSGhit.setBarcode((long)(best_parent ? best_extcode.barcode() : std::numeric_limits::max())); - tmpSGhit.setBarcodePt( static_cast(std::ceil(best_parent ? best_parent->momentum().perp() : 0.)) ); - tmpSGhit.setParentageMask(parent_mask.to_ulong()); - tmpSGhit.normalizeLayerID(); // Change layer info from atlas geo to FTK geo - //cout << "DBGBC SCT " << tmpSGhit.getEventIndex() << ", " << tmpSGhit.getBarcode() << endl; - m_original_hits.push_back(tmpSGhit); - } // end for each RDO in the strip collection - } // end for each strip RDO collection - // dump all RDO's and SDO's for a given event, for debugging purposes - if( false ) { - // dump SCT RDO's - for( SCT_RDO_Container::const_iterator iColl=sct_rdocontainer_iter->begin(), fColl=sct_rdocontainer_iter->end(); iColl!=fColl; ++iColl ) { - const InDetRawDataCollection* SCT_Collection(*iColl); - if( !SCT_Collection ) { continue; } - const int size = SCT_Collection->size(); - m_log << MSG::DEBUG << "SCT InDetRawDataCollection found with " << size << " RDOs" << endmsg; - for( DataVector::const_iterator iRDO=SCT_Collection->begin(), fRDO=SCT_Collection->end(); iRDO!=fRDO; ++iRDO ) { - const Identifier rdoId = (*iRDO)->identify(); - const InDetDD::SiDetectorElement* sielement = m_SCT_mgr->getDetectorElement(rdoId); - const InDetDD::SCT_ModuleSideDesign& design = dynamic_cast(sielement->design()); - const InDetDD::SiLocalPosition localPos = design.positionFromStrip(m_sctId->strip(rdoId)); - const Amg::Vector3D gPos = sielement->globalPosition(localPos); - - if(m_dooutFileRawHits){ - (*oflraw) << "# S\t" - << setw(14) << setprecision(10) - << gPos.x() << '\t' - << setw(14) << setprecision(10) - << gPos.y() << '\t' - << setw(14) << setprecision(10) - << gPos.z() << '\t' - << 0 << '\t' // 1 pixel 0 sct - << m_sctId->barrel_ec(rdoId) << '\t' - << m_sctId->layer_disk(rdoId) << '\t' - << m_sctId->phi_module(rdoId) << '\t' - << m_sctId->eta_module(rdoId) << '\t' - << m_sctId->side(rdoId) << '\t' - << m_sctId->strip(rdoId) << '\t' - << (*iRDO)->getGroupSize() << '\t' - << endl; - } - } // end for each SCT rdo - } // end for each SCT rdo collection - // dump SCT SDO's - if( have_sct_sdo && sctSimDataMap ) { - for( InDetSimDataCollection::const_iterator i=sctSimDataMap->begin(), f=sctSimDataMap->end(); i!=f; ++i ) { - const Identifier sdoId( i->first ); - const InDetSimData& sdo( i->second ); - const vector& deposits( sdo.getdeposits() ); - if(m_dooutFileRawHits){ - (*oflraw) << "# s" - << " " << m_sctId->barrel_ec(sdoId) - << " " << m_sctId->layer_disk(sdoId) - << " " << m_sctId->phi_module(sdoId) - << " " << m_sctId->eta_module(sdoId) - << " " << m_sctId->side(sdoId) - << " " << m_sctId->strip(sdoId) - << " " << SCT_SimHelper::isNoise( sdo ) - << " " << SCT_SimHelper::isBelowThreshold( sdo ) - << " " << SCT_SimHelper::isDisabled( sdo ) - << " " << deposits.size() - << endl; - } - for( vector::const_iterator iDep=deposits.begin(), fDep=deposits.end(); iDep!=fDep; ++iDep ) { - const HepMcParticleLink& particleLink( iDep->first ); - const InDetSimData::Deposit::second_type qdep( iDep->second ); // energy(charge) contributed by this particle + const int size = pixelClusterCollection->size(); + m_log << MSG::DEBUG << "PixelClusterCollection found with " << size << " clusters" << endmsg; + + for( DataVector::const_iterator iCluster=pixelClusterCollection->begin(), fCluster=pixelClusterCollection->end(); iCluster!=fCluster; ++iCluster ) { + Identifier theId = (*iCluster)->identify(); + const Amg::Vector3D gPos = (*iCluster)->globalPosition(); + + // if there is simulation truth available, try to retrieve the "most likely" barcode for this pixel cluster. + const HepMC::GenParticle* best_parent = 0; + ParentBitmask parent_mask; + HepMcParticleLink::ExtendedBarCode best_extcode; + if( have_pixel_sdo && pixelSimDataMap ) { + for( std::vector::const_iterator rdoIter = (*iCluster)->rdoList().begin(); + rdoIter != (*iCluster)->rdoList().end(); rdoIter++ ) { + const InDetDD::SiDetectorElement* sielement = m_PIX_mgr->getDetectorElement(*rdoIter); + assert( sielement); + const InDetDD::SiLocalPosition rawPos = sielement->rawLocalPositionOfCell(*rdoIter); + const int nCells = sielement->numberOfConnectedCells( sielement->cellIdOfPosition(rawPos) ); + InDetSimDataCollection::const_iterator iter( pixelSimDataMap->find(*rdoIter) ); + // this might be the ganged pixel copy. + if( nCells>1 && iter==pixelSimDataMap->end() ) { + InDetDD::SiReadoutCellId SiRC( m_pixelId->phi_index(*rdoIter), m_pixelId->eta_index(*rdoIter) ); + for( int ii=0; iiend(); ++ii ) { + iter = pixelSimDataMap->find(sielement->identifierFromCellId(sielement->design().connectedCell(SiRC,ii))); + } + } // end search for correct ganged pixel + // if SDO found for this pixel, associate the particle. otherwise leave unassociated. + if( iter!=pixelSimDataMap->end() ) { + const InDetSimData& sdo( iter->second ); + const std::vector& deposits( sdo.getdeposits() ); + for( std::vector::const_iterator iDep=deposits.begin(), fDep=deposits.end(); iDep!=fDep; ++iDep ) { + const HepMcParticleLink& particleLink( iDep->first ); + //const InDetSimData::Deposit::second_type qdep( iDep->second ); // energy(charge) contributed by this particle + // RDO's without SDO's are delta rays or detector noise. + if( !particleLink.isValid() ) { continue; } + const HepMC::GenParticle* particle( particleLink ); + const float genEta=particle->momentum().pseudoRapidity(); + const float genPt=particle->momentum().perp(); // MeV + // reject unstable particles + if( particle->status()%1000!=1 ) { continue; } + // reject secondaries and low pT (<400 MeV) pileup + if( particle->barcode()>100000 || particle->barcode()==0 ) { continue; } + // reject far forward particles + if( fabs(genEta)>m_maxEta ) { continue; } + // "best_parent" is the highest pt particle + if( !best_parent || best_parent->momentum().perp()barrel_ec(theId) << '\t' + << m_pixelId->layer_disk(theId) << '\t' + << m_pixelId->phi_module(theId) << '\t' + << m_pixelId->eta_module(theId) << '\t' + << m_pixelId->phi_index(theId) << '\t' + << m_pixelId->eta_index(theId) << '\t' + // Cluster width: + << (*iCluster)->width().colRow().x() << '\t' // width in phi? + << (*iCluster)->width().colRow().y() << '\t' // width in eta? + << (*iCluster)->rdoList().size() << '\t' // number of pixels in cluster + // Cluster truth + << (long)(best_parent ? best_extcode.eventIndex() : -1) << '\t' + << (long)(best_parent ? best_extcode.barcode() : -1) << '\t' + << setprecision(5) << static_cast(std::ceil(best_parent ? best_parent->momentum().perp() : 0.)) << '\t' // particle pt in MeV + << parent_mask.to_ulong() + << endl; } - } // end for each deposit associated with this SDO - } // end for each SCT SDO - } // end if SDO's available, dump them - } // end dump all RDO's and SDO's for a given event - } // end dump raw SCT data - - // FlagJT dump pixel clusters. They're in m_pixelContainer - m_pixelContainer->clID(); // anything to dereference the DataHandle - for( InDet::SiClusterContainer::const_iterator iColl=m_pixelContainer->begin(), fColl=m_pixelContainer->end(); iColl!=fColl; ++iColl ) { - const InDet::SiClusterCollection* pixelClusterCollection(*iColl); - if( !pixelClusterCollection ) { - m_log << MSG::DEBUG << "pixelClusterCollection not available!" << endmsg; - continue; - } - const int size = pixelClusterCollection->size(); - m_log << MSG::DEBUG << "PixelClusterCollection found with " << size << " clusters" << endmsg; - - for( DataVector::const_iterator iCluster=pixelClusterCollection->begin(), fCluster=pixelClusterCollection->end(); iCluster!=fCluster; ++iCluster ) { - Identifier theId = (*iCluster)->identify(); - const Amg::Vector3D gPos = (*iCluster)->globalPosition(); - - // if there is simulation truth available, try to retrieve the "most likely" barcode for this pixel cluster. - const HepMC::GenParticle* best_parent = 0; - ParentBitmask parent_mask; - HepMcParticleLink::ExtendedBarCode best_extcode; - if( have_pixel_sdo && pixelSimDataMap ) { - for( std::vector::const_iterator rdoIter = (*iCluster)->rdoList().begin(); - rdoIter != (*iCluster)->rdoList().end(); rdoIter++ ) { - const InDetDD::SiDetectorElement* sielement = m_PIX_mgr->getDetectorElement(*rdoIter); - assert( sielement); - const InDetDD::SiLocalPosition rawPos = sielement->rawLocalPositionOfCell(*rdoIter); - const int nCells = sielement->numberOfConnectedCells( sielement->cellIdOfPosition(rawPos) ); - InDetSimDataCollection::const_iterator iter( pixelSimDataMap->find(*rdoIter) ); - // this might be the ganged pixel copy. - if( nCells>1 && iter==pixelSimDataMap->end() ) { - InDetDD::SiReadoutCellId SiRC( m_pixelId->phi_index(*rdoIter), m_pixelId->eta_index(*rdoIter) ); - for( int ii=0; iiend(); ++ii ) { - iter = pixelSimDataMap->find(sielement->identifierFromCellId(sielement->design().connectedCell(SiRC,ii))); - } - } // end search for correct ganged pixel - // if SDO found for this pixel, associate the particle. otherwise leave unassociated. - if( iter!=pixelSimDataMap->end() ) { - const InDetSimData& sdo( iter->second ); - const std::vector& deposits( sdo.getdeposits() ); - for( std::vector::const_iterator iDep=deposits.begin(), fDep=deposits.end(); iDep!=fDep; ++iDep ) { - const HepMcParticleLink& particleLink( iDep->first ); - //const InDetSimData::Deposit::second_type qdep( iDep->second ); // energy(charge) contributed by this particle - // RDO's without SDO's are delta rays or detector noise. - if( !particleLink.isValid() ) { continue; } - const HepMC::GenParticle* particle( particleLink ); - const float genEta=particle->momentum().pseudoRapidity(); - const float genPt=particle->momentum().perp(); // MeV - // reject unstable particles - if( particle->status()%1000!=1 ) { continue; } - // reject secondaries and low pT (<400 MeV) pileup - if( particle->barcode()>100000 || particle->barcode()==0 ) { continue; } - // reject far forward particles - if( fabs(genEta)>m_maxEta ) { continue; } - // "best_parent" is the highest pt particle - if( !best_parent || best_parent->momentum().perp()barrel_ec(theId) << '\t' - << m_pixelId->layer_disk(theId) << '\t' - << m_pixelId->phi_module(theId) << '\t' - << m_pixelId->eta_module(theId) << '\t' - << m_pixelId->phi_index(theId) << '\t' - << m_pixelId->eta_index(theId) << '\t' - // Cluster width: - << (*iCluster)->width().colRow().x() << '\t' // width in phi? - << (*iCluster)->width().colRow().y() << '\t' // width in eta? - << (*iCluster)->rdoList().size() << '\t' // number of pixels in cluster - // Cluster truth - << (long)(best_parent ? best_extcode.eventIndex() : -1) << '\t' - << (long)(best_parent ? best_extcode.barcode() : -1) << '\t' - << setprecision(5) << static_cast(std::ceil(best_parent ? best_parent->momentum().perp() : 0.)) << '\t' // particle pt in MeV - << parent_mask.to_ulong() - << endl; - } - pixelClusterIndexMap[theId] = pixelClusterIndex; - pixelClusterIndex++; - } // End loop over pixel clusters - } // End loop over pixel cluster collection - - // dump the statistics - // cout << boost::format("truth parent stats: nch = %|6d| %|6d| %|6d| %|6d| %|6d| fmt = %|5g| fmtp = %|5g| fmtp1 = %|5g| fmb = %|5g|") - // % nchannels - // % nchannels_single_barcodes - // % nchannels_single_barcodes_primary - // % nchannels_single_barcodes_pt1gev - // % nchannels_single_barcodes_bjet - // % (nchannels>0ul ? nchannels_multiple_barcodes/static_cast(nchannels) : 0.) - // % (nchannels>0ul ? nchannels_multiple_barcodes_primary/static_cast(nchannels) : 0.) - // % (nchannels>0ul ? nchannels_multiple_barcodes_pt1gev/static_cast(nchannels) : 0.) - // % (nchannels>0ul ? nchannels_multiple_barcodes_bjet/static_cast(nchannels) : 0.) - // << endl; + pixelClusterIndexMap[theId] = pixelClusterIndex; + pixelClusterIndex++; + } // End loop over pixel clusters + } // End loop over pixel cluster collection + + // dump the statistics + // cout << boost::format("truth parent stats: nch = %|6d| %|6d| %|6d| %|6d| %|6d| fmt = %|5g| fmtp = %|5g| fmtp1 = %|5g| fmb = %|5g|") + // % nchannels + // % nchannels_single_barcodes + // % nchannels_single_barcodes_primary + // % nchannels_single_barcodes_pt1gev + // % nchannels_single_barcodes_bjet + // % (nchannels>0ul ? nchannels_multiple_barcodes/static_cast(nchannels) : 0.) + // % (nchannels>0ul ? nchannels_multiple_barcodes_primary/static_cast(nchannels) : 0.) + // % (nchannels>0ul ? nchannels_multiple_barcodes_pt1gev/static_cast(nchannels) : 0.) + // % (nchannels>0ul ? nchannels_multiple_barcodes_bjet/static_cast(nchannels) : 0.) + // << endl; @@ -829,248 +823,245 @@ FTK_SGHitInput::read_raw_silicon( HitIndexMap& hitIndexMap, HitIndexMap& pixelCl const FTK_SGHitInput::ParentBitmask FTK_SGHitInput::construct_truth_bitmap( const HepMC::GenParticle* particle ) const { - ParentBitmask result; - result.reset(); - typedef pair Parent; - vector parents; - parents.push_back( Parent(particle,0) ); - while( !parents.empty() ) { - const HepMC::GenParticle* p = parents.back().first; - const unsigned int level = parents.back().second; - if( std::abs(p->pdg_id())==15 ) { result.set( TAU_PARENT_BIT , 1 ); } - if( std::abs(p->pdg_id())==5 ) { result.set( B_PARENT_BIT , 1 ); } - if( std::abs(p->pdg_id())==211 ) { result.set( PION_PARENT_BIT , 1 ); } - if( std::abs(p->pdg_id())==211 && level<=1 ) { result.set( PION_IMMEDIATE_PARENT_BIT , 1 ); } - if( result.count()==NBITS ) { break; } - parents.pop_back(); - if( !(p->production_vertex()) ) { continue; } - for( HepMC::GenVertex::particle_iterator i=p->production_vertex()->particles_begin(HepMC::parents), f=p->production_vertex()->particles_end(HepMC::parents); i!=f; ++i ) { - parents.push_back( Parent(*i,level+1) ); + ParentBitmask result; + result.reset(); + typedef pair Parent; + vector parents; + parents.push_back( Parent(particle,0) ); + while( !parents.empty() ) { + const HepMC::GenParticle* p = parents.back().first; + const unsigned int level = parents.back().second; + if( std::abs(p->pdg_id())==15 ) { result.set( TAU_PARENT_BIT , 1 ); } + if( std::abs(p->pdg_id())==5 ) { result.set( B_PARENT_BIT , 1 ); } + if( std::abs(p->pdg_id())==211 ) { result.set( PION_PARENT_BIT , 1 ); } + if( std::abs(p->pdg_id())==211 && level<=1 ) { result.set( PION_IMMEDIATE_PARENT_BIT , 1 ); } + if( result.count()==NBITS ) { break; } + parents.pop_back(); + if( !(p->production_vertex()) ) { continue; } + for( HepMC::GenVertex::particle_iterator i=p->production_vertex()->particles_begin(HepMC::parents), f=p->production_vertex()->particles_end(HepMC::parents); i!=f; ++i ) { + parents.push_back( Parent(*i,level+1) ); + } } - } - return result; + return result; } void FTK_SGHitInput::read_truth_tracks() { - FTKTruthTrack tmpSGTrack; - - // retrieve truth tracks from athena - const McEventCollection* SimTracks = 0; - if( m_storeGate->retrieve(SimTracks,"TruthEvent").isFailure() ) { - string key = "G4Truth"; - if( m_storeGate->retrieve(SimTracks,key).isFailure() ) { - key = ""; - if( m_storeGate->retrieve(SimTracks,key).isFailure() ) { - m_log << MSG::DEBUG << "could not find the McEventCollection"<< endmsg; - return; - } - } - } - // for debugging the calculation of d0_corr - bool showd0corrSuccess = true; - - // dump each truth track - - for( unsigned int ievt=0, fevt=(SimTracks ? SimTracks->size() : 0u); ievt!=fevt; ++ievt ) { - const HepMC::GenEvent* genEvent = SimTracks->at( ievt ); - // retrieve the primary interaction vertex here. for now, use the dummy origin. - HepGeom::Point3D primaryVtx(0.,0.,0.); - // the event should have signal process vertex unless it was generated as single particles. - // if it exists, use it for the primary vertex. - if( genEvent->signal_process_vertex() ) { - primaryVtx.set( genEvent->signal_process_vertex()->point3d().x(), - genEvent->signal_process_vertex()->point3d().y(), - genEvent->signal_process_vertex()->point3d().z() ); - m_log << MSG::DEBUG <<"using signal process vertex for eventIndex " << ievt << ":" - << primaryVtx.x() << "\t" << primaryVtx.y() << "\t" << primaryVtx.z() - <retrieve(SimTracks,"TruthEvent").isFailure() ) { + string key = "G4Truth"; + if( m_storeGate->retrieve(SimTracks,key).isFailure() ) { + key = ""; + if( m_storeGate->retrieve(SimTracks,key).isFailure() ) { + m_log << MSG::DEBUG << "could not find the McEventCollection"<< endmsg; + return; + } + } } + // for debugging the calculation of d0_corr + bool showd0corrSuccess = true; + + // dump each truth track + + for( unsigned int ievt=0, fevt=(SimTracks ? SimTracks->size() : 0u); ievt!=fevt; ++ievt ) { + const HepMC::GenEvent* genEvent = SimTracks->at( ievt ); + // retrieve the primary interaction vertex here. for now, use the dummy origin. + HepGeom::Point3D primaryVtx(0.,0.,0.); + // the event should have signal process vertex unless it was generated as single particles. + // if it exists, use it for the primary vertex. + if( genEvent->signal_process_vertex() ) { + primaryVtx.set( genEvent->signal_process_vertex()->point3d().x(), + genEvent->signal_process_vertex()->point3d().y(), + genEvent->signal_process_vertex()->point3d().z() ); + m_log << MSG::DEBUG <<"using signal process vertex for eventIndex " << ievt << ":" + << primaryVtx.x() << "\t" << primaryVtx.y() << "\t" << primaryVtx.z() + <particles_begin(), ft=genEvent->particles_end(); it!=ft; ++it ) { - - - const HepMC::GenParticle* const particle( *it ); - const int pdgcode = particle->pdg_id(); - // reject generated particles without a production vertex. - if( !particle->production_vertex() ) { continue; } - // reject neutral or unstable particles - const HepPDT::ParticleData* pd = m_particleDataTable->particle(abs(pdgcode)); - if( !pd ) { continue; } - // const float charge = pd->charge(); - /// const float charge = (pdgcode > 0) ? -1. : +1.; - float charge = pd->charge(); - if (pdgcode < 0) charge *= -1.; // since we took absolute value above - - if( std::abs(charge)<0.5 ) { continue; } - if( particle->status()%1000!=1 ) { continue; } - // retrieve some particle kinematics - //const float genPt = particle->momentum().perp()/1000.; // convert to pt in GeV. - //const float genEta = particle->momentum().pseudoRapidity(); - // reject non-fiducial particles - //if( (genPt*1000.) < m_minPt ) { continue; } // controled by TrigFTKBankGen - - //if( std::abs(genEta) > m_maxEta ) { continue; } controled by TrigFTKBankGen - - // new truth-to-track tool - const Amg::Vector3D momentum( particle->momentum().px(), particle->momentum().py(), particle->momentum().pz()); - const Amg::Vector3D position( particle->production_vertex()->position().x(), particle->production_vertex()->position().y(), particle->production_vertex()->position().z()); - const Trk::CurvilinearParameters cParameters( position, momentum, charge); - - Trk::PerigeeSurface persf; - if (m_UseNominalOrigin) { - Amg::Vector3D origin(0,0,0); - persf = Trk::PerigeeSurface(origin); - } - else { - persf = m_beamSpotSvc->beamPos(); - } - - const Trk::TrackParameters* tP = m_extrapolator->extrapolate(cParameters, persf, Trk::anyDirection, false); - - const double m_track_truth_d0 = tP ? tP->parameters()[Trk::d0] : 999.; - const double m_track_truth_phi = tP ? tP->parameters()[Trk::phi] : 999.; - const double m_track_truth_p = (tP && fabs(tP->parameters()[Trk::qOverP]) > 1.e-8) ? - tP->charge()/tP->parameters()[Trk::qOverP] : 10E7; - const double m_track_truth_x0 = tP ? tP->position().x() : 999.; - const double m_track_truth_y0 = tP ? tP->position().y() : 999.; - //const double m_track_truth_z0 = tP ? tP->position().z() : 999.; - const double m_track_truth_z0 = tP ? tP->parameters()[Trk::z0] : 999.; - const double m_track_truth_q = tP ? tP->charge() : 0.; - const double m_track_truth_sinphi = tP ? std::sin(tP->parameters()[Trk::phi]) : -1.; - const double m_track_truth_cosphi = tP ? std::cos(tP->parameters()[Trk::phi]) : -1.; - const double m_track_truth_sintheta = tP ? std::sin(tP->parameters()[Trk::theta]) : -1.; - const double m_track_truth_costheta = tP ? std::cos(tP->parameters()[Trk::theta]) : -1.; - double truth_d0corr = m_track_truth_d0-( primaryVtx.y()*cos(m_track_truth_phi)-primaryVtx.x()*sin(m_track_truth_phi) ); - - // old truth-to-track tool: retrieve truth track parameters at perigee - // boost::scoped_ptr generatedTrackPerigee( m_truthToTrack->makePerigeeParameters(particle) ); - // const double m_track_truth_d0 = generatedTrackPerigee ? generatedTrackPerigee->parameters()[Trk::d0] : 999.; - // const double m_track_truth_phi = generatedTrackPerigee ? generatedTrackPerigee->parameters()[Trk::phi0] : 999.; - // const double m_track_truth_p = (generatedTrackPerigee && generatedTrackPerigee->parameters()[Trk::qOverP] != 0.) ? - // generatedTrackPerigee->charge()/generatedTrackPerigee->parameters()[Trk::qOverP] : 10E7; - // const double m_track_truth_x0 = generatedTrackPerigee ? generatedTrackPerigee->position().x() : 999.; - // const double m_track_truth_y0 = generatedTrackPerigee ? generatedTrackPerigee->position().y() : 999.; - // const double m_track_truth_z0 = generatedTrackPerigee ? generatedTrackPerigee->position().z() : 999.; - // const double m_track_truth_q = generatedTrackPerigee ? generatedTrackPerigee->charge() : 0.; - // const double m_track_truth_sinphi = generatedTrackPerigee ? std::sin(generatedTrackPerigee->parameters()[Trk::phi0]) : -1.; - // const double m_track_truth_cosphi = generatedTrackPerigee ? std::cos(generatedTrackPerigee->parameters()[Trk::phi0]) : -1.; - // const double m_track_truth_sintheta = generatedTrackPerigee ? std::sin(generatedTrackPerigee->parameters()[Trk::theta]) : -1.; - // const double m_track_truth_costheta = generatedTrackPerigee ? std::cos(generatedTrackPerigee->parameters()[Trk::theta]) : -1.; - // double truth_d0corr = m_track_truth_d0-( primaryVtx.y()*cos(m_track_truth_phi)-primaryVtx.x()*sin(m_track_truth_phi) ); - double truth_zvertex = 0.; - - if ( !m_useSimpleCuts ) { // determine d0_corr based on beam position from BeamCondSvc - //toshi/// truth_d0corr = m_track_truth_d0-( m_beamCondSvc->beamPos().y()*cos(m_track_truth_phi)-m_beamCondSvc->beamPos().x()*sin(m_track_truth_phi) ); - //toshi//truth_zvertex = m_beamCondSvc->beamPos().z(); - if ( showd0corrSuccess ) { - m_log << MSG::DEBUG << "Beamspot from BeamCondSvc used to determine cuts in dump_truth()"<< endmsg; - showd0corrSuccess = false; - } - } - const HepGeom::Point3D startVertex(particle->production_vertex()->point3d().x(), particle->production_vertex()->point3d().y(), particle->production_vertex()->point3d().z()); - // categorize particle (prompt, secondary, etc.) based on InDetPerformanceRTT/detector paper criteria. - bool isPrimary = true; - bool isDetPaperCut = true; - if( std::abs(truth_d0corr)>2. ) { isPrimary=false;} - if( particle->barcode()>100000 || particle->barcode()==0 ) { isPrimary=false;} - isDetPaperCut=isPrimary; - // debug line for production_vertex variable - if( false ) { m_log << MSG::DEBUG << "z correction -- bool particle->production_vertex() = " << particle->production_vertex()<< endmsg; } - // - if( isPrimary && particle->production_vertex() ) { - const HepGeom::Point3D startVertex(particle->production_vertex()->point3d().x(), particle->production_vertex()->point3d().y(), particle->production_vertex()->point3d().z()); - if( std::abs(startVertex.z() - truth_zvertex)>100. ) { isPrimary=false;} - // debug z vertex correction - if( false ) { m_log << MSG::DEBUG << "z correction -- startVertex.z() = " << startVertex.z() << " , truth_zvertex = "<< truth_zvertex<< endmsg; } - //double flight_length = -1.; - if( particle->end_vertex() ) { - HepGeom::Point3D endVertex(particle->end_vertex()->point3d().x(), particle->end_vertex()->point3d().y(), particle->end_vertex()->point3d().z()); - if( endVertex.perp()<400. && std::abs(endVertex.z())<2300. ) { isPrimary=false; } - //flight_length = startVertex.distance( endVertex ); - } - } else { - isPrimary = false; - } - isDetPaperCut=isPrimary; - // print truth track info and geant matching for highest figure-of-merit track - int irecmatch = -1; - float precmatch = 0.; - HepMcParticleLink::ExtendedBarCode extBarcode2( particle->barcode(), ievt ); - /*if( !_ttrProbMap.empty() ) { - TruthToRecoProbMap::const_iterator barcode=_ttrProbMap.find(extBarcode2); - if( barcode!=_ttrProbMap.end() ) { - vector probs; - transform( _ttrProbMap.lower_bound(extBarcode2) , _ttrProbMap.upper_bound(extBarcode2) , back_inserter(probs) , - boost::bind(&TruthToRecoProbMap::value_type::second,_1) ); - vector::const_iterator imax = max_element(probs.begin(),probs.end()); - assert( imax!=probs.end() ); - precmatch = *imax; - TruthToRecoTrackMap::const_iterator ibestrec = _ttrTrackMap.find( extBarcode2 ); - assert( ibestrec!=_ttrTrackMap.end() ); - irecmatch = ibestrec->second; - } - }*///toshi comment out - ParentBitmask parent_mask( construct_truth_bitmap( particle ) ); - if(m_dooutFileRawHits){ - (*oflraw) << setiosflags(ios::scientific) << "T\t" - << setw(14) << setprecision(10) << m_track_truth_x0 << '\t' - << setw(14) << setprecision(10) << m_track_truth_y0 << '\t' - << setw(14) << setprecision(10) << m_track_truth_z0 << '\t' - << setw(14) << setprecision(10) << m_track_truth_d0 << '\t' - << setw(14) << setprecision(10) << primaryVtx.z() << '\t' - << (int)m_track_truth_q << '\t' - << setw(14) << setprecision(10) << m_track_truth_p*(m_track_truth_cosphi*m_track_truth_sintheta) << '\t' - << setw(14) << setprecision(10) << m_track_truth_p*(m_track_truth_sinphi*m_track_truth_sintheta) << '\t' - << setw(14) << setprecision(10) << m_track_truth_p*(m_track_truth_costheta) << '\t' - << pdgcode << '\t' - << setw(14) << (int)irecmatch << '\t' - << setw(14) << setprecision(10) << precmatch << '\t' - << extBarcode2.eventIndex() << '\t' - << extBarcode2.barcode() << '\t' - << parent_mask.to_ulong() << '\t' - << isDetPaperCut << '\t' - << resetiosflags(ios::scientific) << '\n'; - } - //get truth track info - - tmpSGTrack.setX(m_track_truth_x0); - tmpSGTrack.setY(m_track_truth_y0); - tmpSGTrack.setZ(m_track_truth_z0); - tmpSGTrack.setD0(m_track_truth_d0); - tmpSGTrack.setVtxZ(primaryVtx.z()); - tmpSGTrack.setQ(m_track_truth_q); - tmpSGTrack.setPX(m_track_truth_p*(m_track_truth_cosphi*m_track_truth_sintheta)); - tmpSGTrack.setPY(m_track_truth_p*(m_track_truth_sinphi*m_track_truth_sintheta)); - tmpSGTrack.setPZ(m_track_truth_p*m_track_truth_costheta); - tmpSGTrack.setPDGCode(pdgcode); - tmpSGTrack.setBarcode(extBarcode2.barcode()); - tmpSGTrack.setEventIndex(extBarcode2.eventIndex()); - m_truth_track.push_back(tmpSGTrack); - - - if( false && particle->production_vertex() && (particle->momentum().perp()/1000.)>10. && - particle->status()%1000==1 && std::abs(charge)>0.5 ) { - using boost::format; - const HepMC::GenParticle* tau_parent = 0; - vector parents; - parents.push_back( particle ); - while( !parents.empty() ) { - const HepMC::GenParticle* p = parents.back(); - if( std::abs(p->pdg_id())==15 ) { tau_parent = p; break; } - parents.pop_back(); - if( !(p->production_vertex()) ) { continue; } - copy( p->production_vertex()->particles_begin(HepMC::parents) , p->production_vertex()->particles_end(HepMC::parents) , back_inserter(parents) ); - } - unsigned int nprongs = 0; -