Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:33:28

0001 #ifndef CalibCalorimetry_EcalLaserAnalyzer_EcalLaserAnalyzer2_h
0002 #define CalibCalorimetry_EcalLaserAnalyzer_EcalLaserAnalyzer2_h
0003 // $Id: EcalLaserAnalyzer2.h
0004 
0005 #include <memory>
0006 
0007 #include <vector>
0008 #include <map>
0009 
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0011 
0012 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0013 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
0014 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0015 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
0016 
0017 class TFile;
0018 class TTree;
0019 class TProfile;
0020 class TPNCor;
0021 class TPN;
0022 class TAPD;
0023 class TMom;
0024 class TAPDPulse;
0025 class TPNPulse;
0026 class TMem;
0027 
0028 // Define geometrical constants
0029 // NOT the same for "EB" and "EE"
0030 //
0031 //     "EB"       "EE"
0032 //
0033 //      0          0
0034 //   1     2    1     2
0035 //   3     4
0036 //   5     6
0037 //   7     8
0038 //
0039 //
0040 
0041 // "EB" geometry
0042 #define NCRYSEB 1700  // Number of crystals per EB supermodule
0043 #define NMODEB 9      // Number of EB submodules
0044 #define NPNPERMOD 2   // Number of PN per module
0045 
0046 // "EE" geometry
0047 #define NCRYSEE 830  // Number of crystals per EE supermodule
0048 #define NMODEE 21    // Number of EE submodules
0049 
0050 #define NSIDES 2    // Number of sides
0051 #define NREFCHAN 2  // Ref number for APDB
0052 #define NSAMPSHAPES 250
0053 
0054 class EcalLaserAnalyzer2 : public edm::one::EDAnalyzer<> {
0055 public:
0056   explicit EcalLaserAnalyzer2(const edm::ParameterSet &iConfig);
0057   ~EcalLaserAnalyzer2() override;
0058 
0059   void analyze(const edm::Event &e, const edm::EventSetup &c) override;
0060   void beginJob() override;
0061   void endJob() override;
0062 
0063   void setGeomEB(int etaG, int phiG, int module, int tower, int strip, int xtal, int apdRefTT, int channel, int lmr);
0064   void setGeomEE(
0065       int etaG, int phiG, int iX, int iY, int iZ, int module, int tower, int ch, int apdRefTT, int channel, int lmr);
0066 
0067   enum VarCol { iBlue, iRed, nColor };
0068 
0069 private:
0070   int iEvent;
0071 
0072   const std::string eventHeaderCollection_;
0073   const std::string eventHeaderProducer_;
0074   const std::string digiCollection_;
0075   const std::string digiProducer_;
0076   const std::string digiPNCollection_;
0077 
0078   const edm::EDGetTokenT<EcalRawDataCollection> rawDataToken_;
0079   edm::EDGetTokenT<EBDigiCollection> ebDigiToken_;
0080   edm::EDGetTokenT<EEDigiCollection> eeDigiToken_;
0081   const edm::EDGetTokenT<EcalPnDiodeDigiCollection> pnDiodeDigiToken_;
0082   const edm::ESGetToken<EcalElectronicsMapping, EcalMappingRcd> mappingToken_;
0083 
0084   // Framework parameters
0085 
0086   const unsigned int _nsamples;
0087   unsigned int _presample;
0088   const unsigned int _firstsample;
0089   const unsigned int _lastsample;
0090   const unsigned int _nsamplesPN;
0091   const unsigned int _presamplePN;
0092   const unsigned int _firstsamplePN;
0093   const unsigned int _lastsamplePN;
0094   const unsigned int _timingcutlow;
0095   const unsigned int _timingcuthigh;
0096   const unsigned int _timingquallow;
0097   const unsigned int _timingqualhigh;
0098   const double _ratiomincutlow;
0099   const double _ratiomincuthigh;
0100   const double _ratiomaxcutlow;
0101   const double _presamplecut;
0102   const unsigned int _niter;
0103   const double _noise;
0104   const std::string _ecalPart;
0105   const bool _saveshapes;
0106   const bool _docorpn;
0107   const int _fedid;
0108   const bool _saveallevents;
0109   const double _qualpercent;
0110   const int _debug;
0111 
0112   TAPDPulse *APDPulse;
0113   TPNPulse *PNPulse;
0114   TMem *Mem;
0115   TMom *Delta01;
0116   TMom *Delta12;
0117 
0118   const std::string resdir_;
0119   const std::string elecfile_;
0120   const std::string pncorfile_;
0121 
0122   // Output file names
0123 
0124   std::string shapefile;
0125   std::string matfile;
0126   std::string ADCfile;
0127   std::string APDfile;
0128   std::string resfile;
0129 
0130   //  Define geometrical constants
0131   //  Default values correspond to "EB" geometry (1700 crystals)
0132 
0133   unsigned int nCrys;
0134   unsigned int nPNPerMod;
0135   unsigned int nRefChan;
0136   unsigned int nRefTrees;
0137   unsigned int nMod;
0138   unsigned int nSides;
0139 
0140   unsigned int nSamplesShapes;
0141 
0142   bool IsMatacqOK;
0143 
0144   // Identify run type
0145 
0146   int runType;
0147   int runNum;
0148 
0149   // Identify channel
0150 
0151   int towerID;
0152   int channelID;
0153   int fedID;
0154   int dccID;
0155   int side;
0156   int lightside;
0157   int iZ;
0158 
0159   // Count Laser Events
0160   int laserEvents;
0161 
0162   std::vector<int> colors;
0163   std::map<int, int> channelMapEE;
0164   std::vector<int> dccMEM;
0165   std::vector<int> modules;
0166   std::map<int, unsigned int> apdRefMap[2];
0167 
0168   // PN linearity corrections
0169 
0170   TPNCor *pnCorrector;
0171 
0172   // get the shapes for amplitude determination
0173 
0174   bool getShapes();
0175 
0176   // Temporary root files and trees
0177 
0178   TFile *ADCFile;
0179   TTree *ADCtrees[NCRYSEB];
0180 
0181   TFile *APDFile;
0182   TTree *APDtrees[NCRYSEB];
0183   TTree *RefAPDtrees[NREFCHAN][NMODEE];
0184 
0185   TFile *resFile;
0186   TTree *restrees[nColor];
0187   TTree *respntrees[nColor];
0188 
0189   TFile *ShapeFile;
0190   TProfile *PulseShape;
0191 
0192   // Declaration of leaves types for temporary trees
0193 
0194   int phi, eta;
0195   int event;
0196   int color;
0197   double adc[10];
0198   int adcG[10];
0199   double pn0, pn1;
0200   double pn[50];
0201   int pnG[50];
0202   double apdAmpl;
0203   double apdAmplA;
0204   double apdAmplB;
0205   double apdTime;
0206   double pnAmpl;
0207 
0208   int eventref;
0209   int colorref;
0210 
0211   double *adcNoPed;
0212   double *pnNoPed;
0213 
0214   // declare TPN stuff
0215   TPN *PNFirstAnal[NMODEB][NPNPERMOD][nColor];
0216   TPN *PNAnal[NMODEB][NPNPERMOD][nColor];
0217 
0218   // declare TAPD stuff
0219   TAPD *APDFirstAnal[NCRYSEB][nColor];
0220   TAPD *APDAnal[NCRYSEB][nColor];
0221 
0222   int IsThereDataADC[NCRYSEB][nColor];
0223 
0224   // Declaration of shapes
0225 
0226   std::vector<double> shapesVec;
0227   double shapes[NSAMPSHAPES];
0228   double shapeCorrection;
0229   bool isMatacqOK;
0230   bool isSPRFine;
0231 
0232   // Declaration of leaves types for results tree
0233 
0234   int pnID, moduleID, flag;
0235   int channelIteratorEE;
0236 
0237   double APD[6], Time[6], PN[6], APDoPN[6], APDoPNA[6], APDoPNB[6], APDoAPDA[6], APDoAPDB[6], PNoPN[6], PNoPNA[6],
0238       PNoPNB[6], ShapeCor;
0239   // [0]=mean, [1]=rms, [2]=L3, [3]=nevt, [4]=min, [5]=max
0240 
0241   double adcMean[NCRYSEB][10];
0242   int adcC[NCRYSEB];
0243 
0244   int iEta[NCRYSEB], iPhi[NCRYSEB];
0245   unsigned int iModule[NCRYSEB];
0246   int iTowerID[NCRYSEB], iChannelID[NCRYSEB], idccID[NCRYSEB], iside[NCRYSEB];
0247   unsigned int firstChanMod[NMODEE];
0248   unsigned int isFirstChanModFilled[NMODEE];
0249 
0250   // Quality Checks variables and flags
0251 
0252   int nEvtBadGain[NCRYSEB];
0253   int nEvtBadTiming[NCRYSEB];
0254   int nEvtTot[NCRYSEB];
0255 
0256   bool wasGainOK[NCRYSEB];
0257   bool wasTimingOK[NCRYSEB];
0258 
0259   bool isGainOK;
0260   bool isTimingOK;
0261 };
0262 #endif