Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-01-21 00:19:05

0001 
0002 #ifndef LaserAlignment_LaserAlignment_H
0003 #define LaserAlignment_LaserAlignment_H
0004 
0005 /** \class LaserAlignment
0006  *  Main reconstruction module for the Laser Alignment System
0007  *
0008  *  $Date: 2012/12/26 20:34:44 $
0009  *  $Revision: 1.32 $
0010  *  \author Maarten Thomas
0011  *  \author Jan Olzem
0012  */
0013 
0014 #include <sstream>
0015 #include <iostream>
0016 #include <cmath>
0017 
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/one/EDProducer.h"
0020 #include "FWCore/Framework/interface/ESHandle.h"
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/ServiceRegistry/interface/Service.h"
0025 
0026 #include "DataFormats/Common/interface/DetSetVector.h"
0027 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0028 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0029 #include "DataFormats/DetId/interface/DetId.h"
0030 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0031 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0032 
0033 #include "DataFormats/GeometryCommonDetAlgo/interface/ErrorFrameTransformer.h"
0034 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0035 #include "DataFormats/Alignment/interface/SiStripLaserRecHit2D.h"
0036 #include "DataFormats/Alignment/interface/TkLasBeam.h"
0037 
0038 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
0039 #include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
0040 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
0041 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0042 
0043 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0044 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
0045 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0046 #include "Geometry/CommonTopologies/interface/StripTopology.h"
0047 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0048 #include "Geometry/CommonTopologies/interface/GeometryAligner.h"
0049 
0050 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0051 
0052 #include "Alignment/LaserAlignment/interface/LASGlobalData.h"
0053 #include "Alignment/LaserAlignment/interface/LASGlobalLoop.h"
0054 #include "Alignment/LaserAlignment/interface/LASModuleProfile.h"
0055 #include "Alignment/LaserAlignment/interface/LASProfileJudge.h"
0056 #include "Alignment/LaserAlignment/interface/LASBarrelAlgorithm.h"
0057 #include "Alignment/LaserAlignment/interface/LASAlignmentTubeAlgorithm.h"
0058 #include "Alignment/LaserAlignment/interface/LASEndcapAlgorithm.h"
0059 #include "Alignment/LaserAlignment/interface/LASPeakFinder.h"
0060 #include "Alignment/LaserAlignment/interface/LASCoordinateSet.h"
0061 #include "Alignment/LaserAlignment/interface/LASGeometryUpdater.h"
0062 #include "Alignment/LaserAlignment/interface/LASConstants.h"
0063 
0064 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0065 
0066 #include "TH1.h"
0067 #include "TFile.h"
0068 #include "TF1.h"
0069 
0070 ///
0071 ///
0072 ///
0073 class LaserAlignment : public edm::one::EDProducer<edm::EndRunProducer> {
0074 public:
0075   explicit LaserAlignment(edm::ParameterSet const& theConf);
0076   ~LaserAlignment() override;
0077   void beginJob() override;
0078   void produce(edm::Event&, edm::EventSetup const&) override;
0079   void endJob() override;
0080   void endRunProduce(edm::Run&, const edm::EventSetup&) override;
0081 
0082   /// for debugging & testing only, will disappear..
0083   void testRoutine(void);
0084 
0085 private:
0086   /// fill profiles from SiStrip(Raw)Digi container
0087   void fillDataProfiles(edm::Event const&, edm::EventSetup const&);
0088 
0089   /// fill pedestals from dbase
0090   void fillPedestalProfiles(edm::ESHandle<SiStripPedestals>&);
0091 
0092   /// decide whether TEC or AT beams have fired
0093   bool isTECBeam(void);
0094   bool isATBeam(void);
0095 
0096   /// returns the nominal beam position (strips) in TOB for the profileJudge
0097   double getTIBTOBNominalBeamOffset(unsigned int, unsigned int, unsigned int);
0098 
0099   /// returns the nominal beam position (strips) in TEC (AT) for the profileJudge
0100   double getTEC2TECNominalBeamOffset(unsigned int, unsigned int, unsigned int);
0101 
0102   /// fill hard coded detIds
0103   void fillDetectorId(void);
0104 
0105   /// convert an angle in the [-pi,pi] range to the [0,2*pi] range
0106   double ConvertAngle(double);
0107 
0108   /// fills a LASGlobalData<LASCoordinateSet> with nominal module positions
0109   void CalculateNominalCoordinates(void);
0110 
0111   /// for debugging only, will disappear
0112   void DumpPosFileSet(LASGlobalData<LASCoordinateSet>&);
0113 
0114   /// for debugging only, will disappear
0115   void DumpStripFileSet(LASGlobalData<std::pair<float, float> >&);
0116 
0117   /// for debugging only, will disappear
0118   void DumpHitmaps(LASGlobalData<int>&);
0119 
0120   /// apply endcap correction to masked modules in TEC
0121   void ApplyEndcapMaskingCorrections(LASGlobalData<LASCoordinateSet>&,
0122                                      LASGlobalData<LASCoordinateSet>&,
0123                                      LASEndcapAlignmentParameterSet&);
0124 
0125   /// same for alignment tube modules
0126   void ApplyATMaskingCorrections(LASGlobalData<LASCoordinateSet>&,
0127                                  LASGlobalData<LASCoordinateSet>&,
0128                                  LASBarrelAlignmentParameterSet&);
0129 
0130   /// Tokens for ESconsumes
0131   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0132   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0133   const edm::ESGetToken<GeometricDet, IdealGeometryRecord> geomDetToken_;
0134   const edm::ESGetToken<PTrackerParameters, PTrackerParametersRcd> ptpToken_;
0135   const edm::ESGetToken<Alignments, GlobalPositionRcd> gprToken_;
0136   const edm::ESGetToken<SiStripPedestals, SiStripPedestalsRcd> stripPedestalsToken_;
0137 
0138   /// counter for the total number of events processed
0139   int theEvents;
0140 
0141   /// config switch
0142   bool theDoPedestalSubtraction;
0143 
0144   /// config switch
0145   bool theUseMinuitAlgorithm;
0146 
0147   /// config switch
0148   bool theApplyBeamKinkCorrections;
0149 
0150   /// config parameter
0151   double peakFinderThreshold;
0152 
0153   /// config switch
0154   bool enableJudgeZeroFilter;
0155 
0156   /// config parameters for the LASProfileJudge
0157   unsigned int judgeOverdriveThreshold;
0158 
0159   /// config switch
0160   bool updateFromInputGeometry;
0161 
0162   /// config switch
0163   bool misalignedByRefGeometry;
0164 
0165   /// config switch
0166   bool theStoreToDB;
0167 
0168   // digi producer
0169   std::vector<edm::ParameterSet> theDigiProducersList;
0170 
0171   /// config switch
0172   bool theSaveHistograms;
0173 
0174   /// config parameter (histograms file compression level)
0175   int theCompression;
0176 
0177   /// config parameter (histograms file output name)
0178   std::string theFileName;
0179 
0180   /// config parameters
0181   std::vector<unsigned int> theMaskTecModules;
0182   std::vector<unsigned int> theMaskAtModules;
0183 
0184   /// config switch
0185   bool theSetNominalStrips;
0186 
0187   // this object can judge if
0188   // a LASModuleProfile is usable for position measurement
0189   LASProfileJudge judge;
0190 
0191   // colection of constants
0192   LASConstants theLasConstants;
0193 
0194   // the detector ids for all the modules
0195   LASGlobalData<unsigned int> detectorId;
0196 
0197   // the detector ids for the doubly hit modules in the TECs
0198   std::vector<unsigned int> tecDoubleHitDetId;
0199 
0200   // all the 474 profiles for the pedestals
0201   LASGlobalData<LASModuleProfile> pedestalProfiles;
0202 
0203   /// data profiles for the current event
0204   LASGlobalData<LASModuleProfile> currentDataProfiles;
0205 
0206   // summed data profiles
0207   LASGlobalData<LASModuleProfile> collectedDataProfiles;
0208 
0209   // 474 names for retrieving data from the branches
0210   LASGlobalData<std::string> theProfileNames;
0211 
0212   // number of accepted profiles for each module
0213   LASGlobalData<int> numberOfAcceptedProfiles;
0214 
0215   // hit map for the current event (int=0,1)
0216   // which is needed for branching into AT or TEC mode
0217   LASGlobalData<int> isAcceptedProfile;
0218 
0219   // histograms for the summed profiles;
0220   // these are needed for the fitting procedure (done by ROOT)
0221   LASGlobalData<TH1D*> summedHistograms;
0222 
0223   // container for nominal module positions
0224   LASGlobalData<LASCoordinateSet> nominalCoordinates;
0225 
0226   // a class for easy looping over LASGlobalData objects,
0227   // avoids nested for-statements
0228   LASGlobalLoop moduleLoop;
0229 
0230   /// Tree stuff
0231   TFile* theFile;
0232   TDirectory* singleModulesDir;
0233 
0234   /// tracker geometry;
0235   edm::ESHandle<GeometricDet> gD;
0236   edm::ESHandle<TrackerGeometry> theTrackerGeometry;
0237   edm::ESHandle<Alignments> theGlobalPositionRcd;
0238 
0239   AlignableTracker* theAlignableTracker;
0240 
0241   std::string theAlignRecordName, theErrorRecordName;
0242 
0243   bool firstEvent_;
0244 };
0245 #endif