Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:39:11

0001 #ifndef Alignment_HIPAlignmentAlgorithm_HIPAlignmentAlgorithm_h
0002 #define Alignment_HIPAlignmentAlgorithm_HIPAlignmentAlgorithm_h
0003 
0004 #include <vector>
0005 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentAlgorithmBase.h"
0006 #include "Alignment/CommonAlignment/interface/Alignable.h"
0007 #include "Alignment/CommonAlignment/interface/AlignableDetOrUnitPtr.h"
0008 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
0009 #include "Alignment/CommonAlignment/interface/AlignableNavigator.h"
0010 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentIORoot.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/Framework/interface/ConsumesCollector.h"
0013 #include "Riostream.h"
0014 
0015 #include "DataFormats/Alignment/interface/AlignmentClusterFlag.h"
0016 #include "DataFormats/Alignment/interface/AliClusterValueMap.h"
0017 #include "Utilities/General/interface/ClassName.h"
0018 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
0019 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
0020 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
0021 
0022 #include "Geometry/CommonTopologies/interface/SurfaceDeformation.h"
0023 #include "Geometry/CommonTopologies/interface/SurfaceDeformationFactory.h"
0024 
0025 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0026 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0027 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0028 
0029 #include "Alignment/HIPAlignmentAlgorithm/interface/HIPMonitorConfig.h"
0030 #include "Alignment/HIPAlignmentAlgorithm/interface/HIPAlignableSpecificParameters.h"
0031 #include "TFormula.h"
0032 
0033 class TFile;
0034 class TTree;
0035 
0036 class HIPAlignmentAlgorithm : public AlignmentAlgorithmBase {
0037 public:
0038   /// Constructor
0039   HIPAlignmentAlgorithm(const edm::ParameterSet& cfg, edm::ConsumesCollector& iC);
0040 
0041   /// Destructor
0042   ~HIPAlignmentAlgorithm() override{};
0043 
0044   /// Call at beginning of job
0045   void initialize(const edm::EventSetup& setup,
0046                   AlignableTracker* tracker,
0047                   AlignableMuon* muon,
0048                   AlignableExtras* extras,
0049                   AlignmentParameterStore* store) override;
0050 
0051   /// Call at end of job
0052   void terminate(const edm::EventSetup& setup) override;
0053 
0054   /// Called at start of new loop
0055   void startNewLoop(void) override;
0056 
0057   /// Run the algorithm
0058   void run(const edm::EventSetup& setup, const EventInfo& eventInfo) override;
0059 
0060 private:
0061   bool processHit1D(const AlignableDetOrUnitPtr& alidet,
0062                     const Alignable* ali,
0063                     const HIPAlignableSpecificParameters* alispecifics,
0064                     const TrajectoryStateOnSurface& tsos,
0065                     const TrackingRecHit* hit,
0066                     double hitwt);
0067 
0068   bool processHit2D(const AlignableDetOrUnitPtr& alidet,
0069                     const Alignable* ali,
0070                     const HIPAlignableSpecificParameters* alispecifics,
0071                     const TrajectoryStateOnSurface& tsos,
0072                     const TrackingRecHit* hit,
0073                     double hitwt);
0074 
0075   int readIterationFile(std::string filename);
0076   void writeIterationFile(std::string filename, int iter);
0077   void setAlignmentPositionError(void);
0078   double calcAPE(double* par, int iter, int function);
0079   void bookRoot(void);
0080   void fillAlignablesMonitor(const edm::EventSetup& setup);
0081   bool calcParameters(Alignable* ali, int setDet, double start, double step);
0082   void collector(void);
0083   void collectMonitorTrees(const std::vector<std::string>& filenames);
0084 
0085   HIPAlignableSpecificParameters* findAlignableSpecs(const Alignable* ali);
0086 
0087   // private data members
0088   const edm::ESGetToken<TrackerTopology, IdealGeometryRecord> topoToken_;
0089   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken2_;
0090 
0091   std::unique_ptr<AlignableObjectId> alignableObjectId_;
0092   AlignmentParameterStore* theAlignmentParameterStore;
0093   align::Alignables theAlignables;
0094   std::unique_ptr<AlignableNavigator> theAlignableDetAccessor;
0095 
0096   AlignmentIORoot theIO;
0097   int ioerr;
0098   int theIteration;
0099 
0100   // steering parameters
0101 
0102   // verbosity flag
0103   const bool verbose;
0104   // Monitor configuration
0105   HIPMonitorConfig theMonitorConfig;
0106   const bool doTrackHitMonitoring;
0107   // names of IO root files
0108   std::string outfile2, outpath, suvarfilecore, suvarfile, sparameterfile;
0109   std::string struefile, smisalignedfile, salignedfile, siterationfile, ssurveyfile;
0110 
0111   bool themultiIOV;
0112   std::vector<unsigned> theIOVrangeSet;
0113 
0114   // alignment position error parameters
0115   bool theApplyAPE;
0116   std::vector<edm::ParameterSet> theAPEParameterSet;
0117   std::vector<std::pair<align::Alignables, std::vector<double> > > theAPEParameters;
0118 
0119   // Default alignment specifications
0120   // - min number of hits on alignable to calc parameters
0121   // - max allowed rel error on parameter (else not used)
0122   // - max allowed pull (residual / uncertainty) on a hit used in alignment
0123   HIPAlignableSpecificParameters defaultAlignableSpecs;
0124 
0125   bool theApplyCutsPerComponent;
0126   std::vector<edm::ParameterSet> theCutsPerComponent;
0127   std::vector<HIPAlignableSpecificParameters> theAlignableSpecifics;
0128 
0129   // collector mode (parallel processing)
0130   bool isCollector;
0131   int theCollectorNJobs;
0132   std::string theCollectorPath;
0133   int theDataGroup;  // The data type specified in the cfg
0134   bool trackPs, trackWt, IsCollision, uniEta, rewgtPerAli;
0135   std::string uniEtaFormula;
0136   double Scale, cos_cut, col_cut;
0137   std::vector<double> SetScanDet;
0138 
0139   std::unique_ptr<TFormula> theEtaFormula;
0140 
0141   const std::vector<std::string> surveyResiduals_;
0142   std::vector<align::StructureType> theLevels;  // for survey residuals
0143 
0144   // root tree variables
0145   TFile* theTrackHitMonitorIORootFile;
0146   TTree* theTrackMonitorTree;  // event-wise tree
0147   TTree* theHitMonitorTree;    // hit-wise tree
0148   TFile* theAlignablesMonitorIORootFile;
0149   TTree* theAlignablesMonitorTree;  // alignable-wise tree
0150   TFile* theSurveyIORootFile;
0151   TTree* theSurveyTree;  // survey tree
0152 
0153   // common variables for monitor trees
0154   int m_datatype;
0155 
0156   // variables for alignable-wise tree
0157   align::ID m2_Id;
0158   align::StructureType m2_ObjId;
0159   int m2_Nhit, m2_Type, m2_Layer;
0160   int m2_datatype;
0161   float m2_Xpos, m2_Ypos, m2_Zpos;
0162   SurfaceDeformationFactory::Type m2_dtype;
0163   unsigned int m2_nsurfdef;
0164   std::vector<float> m2_surfDef;
0165 
0166   // variables for survey tree
0167   align::ID m3_Id;
0168   align::StructureType m3_ObjId;
0169   float m3_par[6];
0170 };
0171 
0172 #endif