Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:13:03

0001 #ifndef _EpFinder
0002 #define _EpFinder
0003 
0004 class TVector3;
0005 class TFile;
0006 class TProfile;
0007 class TProfile2D;
0008 
0009 #include "TH2D.h"
0010 #include "TVector3.h"
0011 #include "EpInfo.h"
0012 #include <vector>
0013 #include <utility>
0014 
0015 /*************************************
0016  * \author Mike Lisa
0017  * \date 23 June 2018
0018  * 
0019  * adjusted for sPHENIX by J. Lajoie 
0020  * 24 August 2019
0021  *
0022  * \description:
0023  * Finds the Event Plane (EP) and EP-related quantities.
0024  * Also creates correction files and applies them.
0025  * Also calculates resolution
0026  *
0027  * There is a lot of EP-related information.  Raw, phi-weighted, shifted, etc.
0028  * 1st, 2nd, nth order.  Q-vector and Psi.  Even if the user does not request
0029  * all of these things, it is convenient and not so wasteful to simply calculate
0030  * them all at once.  Therefore, the user is presented with a large object of
0031  * type StEpdEpInfo.  This avoids "calculate-it-on-the-fly" which can be wasteful
0032  * if the user requests more than one thing, as well as "has-it-already-been-calculated?"
0033  * ambiguities.
0034  *
0035  *   A word about "EventType": the correction factors and other things about the event
0036  * plane can depend on centrality, vertex position, etc.  This code will apply the
0037  * corrections separately for different "EventTypes".  It is up to the user to decide
0038  * what this denotes.  All I care about is that when you send me an event, you tell
0039  * me the EventTypeId, which is just an integer.  The rest is up to you (as it should be :).
0040  *   For many (most?) people, this will just be a centrality index.
0041  *
0042  * This class will do "phi-weighting" and "shifting" corrections, but it needs
0043  *  some information to do it.  It will generate such information itself, but
0044  *  here is what you need to do, if you are starting from scratch:
0045  * 1) With whatever multiplicity/Vz/whatever event cuts you are going to analyze, and
0046  *    on whatever dataset, run your code that calls this class.  This will produce
0047  *    a file called EpFinderCorrectionHistograms_OUTPUT.root in the cwd.
0048  *    --> mv EpFinderCorrectionHistograms_OUTPUT.root EpFinderCorrectionHistos_INPUT.root
0049  *    That takes care of the Phi-weighting
0050  * 2) Repeat the above step (including the rename of the file, overwriting the old one).
0051  *      That takes care of the shifting weights.
0052  * 3) You are good to go.
0053  *
0054  *
0055  * ------------------------------------------
0056  * This class creates some histograms and uses some histograms.  Since I use GetBinContent()
0057  *  to extract values from the histograms, the binning is important.  I try to keep things
0058  *  consistent, but let me explain.
0059  *
0060  * 1) Phi Weighting.  Used by EpFinder and created by EpFinder.
0061  *    This code creates a histogram with the root name 
0062  *    "PhiWeight"
0063  *    x-axis and y-axis are USER DEFINED IN THE EpFinder constructor. 
0064  *    The user has no direct interaction with this histogram.
0065  *
0066  * 2) Shifting correction.  Used by EpFinder and created by EpFinder.
0067  *    This implements equation (6) of arxiv:nucl-ex/9805001
0068  *    The histogram names are
0069  *     - Form("EpdShiftdPsi%d_sin",ew,order)   
0070  *     - Form("EpdShiftdPsi%d_cos",ew,order)   
0071  *     - Form("EpdShiftFullEventPsi%d_sin",order)
0072  *     - Form("EpdShiftFullEventPsi%d_cos",order)
0073  *    In these histograms, order is "n" (as in n=2 for second-order EP)
0074  *    x-axis is "i" from equation (6) above.  As in <cos(n*i*Psi_n)>
0075  *       There are _EpTermsMax bins running from 0.5 to _EPtermsMax+0.5, so there should be no confusion with this axis.
0076  *    y-axis is EventTypeId, the *user-defined* EventType bin number.
0077  *--------->>>>>>>>>>>>>>>>>> And at this point I must make a demand of the user <<<<<<<<<<<<<<<<<<<
0078  *    When the user instantiates an EpFinder object, he specifies nEventTypeBins, the number of EventType bins he will use.
0079  *       >>>> The user MUST number these bins 0,1,2,3,4,...(nEventTypeBins-1) when he interacts with this class <<<<
0080  *       (If he wants to use a different convention in his code, that's fine, but when talking to EpFinder, use 0..(nEventTypeBins-1)
0081  *    The y-axis then has nEventTypeBins bins, going from -0.5 to nEventTypeBins-0.5
0082  *
0083  *************************************/
0084 
0085 #define _EpTermsMax 6
0086 
0087 // This is the structure for passing hit information into EpFinder:
0088 // nMip : hit weight (energy of number of MIPs, etc.)
0089 // ix   : detector index in x (user defined)
0090 // iy   : detector index in y (user defined)
0091 // samePhi : pointer is vector of index (ix,iy) pairs for decetor elements in the same phi bin as this hit (NULL is OK)
0092 //
0093 // ix, iy are USER DEFINED and their range is set in the EpFinder constructor. ix,iy and samePhi are used in the phi weighting correction determination. 
0094 
0095 typedef struct{
0096 
0097   float nMip; 
0098   double phi;   
0099   int ix; 
0100   int iy; 
0101   std::vector<std::pair<int,int>> *samePhi; 
0102   
0103 } EpHit; 
0104 
0105 
0106 class EpFinder{
0107  public:
0108 
0109   /// Constructor.  Initializes values and reads correction file, if it exists.
0110   /// This file is actually PRODUCED by the code in an earlier run.  The user must rename
0111   /// the file EpFinderCorrectionHistograms_OUTPUT.root if he wants to use it.
0112   /// \param CorrectionFileName    Full name of the .root file with correction histograms.
0113   /// \param nEventTypeBins        Number of EventType bins that the user is using.  Up to the user to have a consistent usage, here and in analysis.
0114   /// \param pbinsx, pbinsy        Number of detector index bins for phi correction
0115   EpFinder(int nEventTypeBins=10, char const* OutFileName="EpFinderCorrectionHistograms_OUTPUT.root", char const* CorrectionFileName="EpFinderCorrectionHistograms_INPUT.root", 
0116        int pbinsx=1, int pbinsy=1);
0117   ~EpFinder(){/* no-op */};
0118 
0119   /// sets the threshold, in units of nMIP, for determining tile weights
0120   ///   TileWeight = (EpdHit->nMIP()>thresh)?((EpdHit->nMIP()>MAX)?MAX:EpdHit->nMIP()):0;
0121   /// \param thresh       threshold.  If epdHit->nMIP() is less than thresh, then weight is zero
0122   void SetnMipThreshold(double thresh){mThresh=thresh;};
0123 
0124   /// sets the maximum weight, in units of nMIP, for determining tile weights
0125   ///   TileWeight = (EpdHit->nMIP()>thresh)?((EpdHit->nMIP()>MAX)?MAX:EpdHit->nMIP()):0;
0126   /// \param MAX          maximum tile weight.  If epdHit->nMIP()>MAX then weight=MAX
0127   void SetMaxTileWeight(double MAX){mMax=MAX;};
0128 
0129   /// call this method at the end of your run to output correction histograms to a file (you can choose to use these or not)
0130   ///   and to calculate EP resolutions
0131   void Finish();
0132 
0133   /// returns all information about the EP.  A large object of type StEpdEpInfo is returned, so you don't
0134   ///  have to call the EpFinder over and over again for various information
0135   /// \param EpdHits      Epd Hits in a TClones array.  Will be decoded as StEpdHit, StMuEpdHit, or StPicoEpdHit as dictated by mFormatUsed
0136   /// \param primVertex   primary vertex position for this event
0137   /// \param EventTypeID user-defined integer specifying EventType of the event.  User must use same convention in correction histograms and weights
0138   EpInfo Results(std::vector<EpHit> *EpdHits, int EventTypeID);
0139 
0140   /// Returns a big string that tells in text what the settings were.
0141   /// This is for your convenience and is of course optional.  I like
0142   /// to put a concatenation of such Reports into a text file, so I
0143   /// "autodocument" what were the settings for a given run
0144   TString Report();
0145 
0146 
0147  private:
0148 
0149   bool OrderOutsideRange(int order);         // just makes sure order is between 1 and _EpOrderMax
0150 
0151   double GetPsiInRange(double Qx, double Qy, int order);
0152 
0153   int mNumberOfEventTypeBins;                // user-defined.  Default is 10.  Used for correction histograms
0154 
0155   // tile weight = (0 if ADC< thresh), (MAX if ADC>MAX); (ADC otherwise).
0156   double mThresh;                            // default is 0.3
0157   double mMax;                               // default is 2.0
0158 
0159   TProfile* mAveCosDeltaPsi[_EpOrderMax];        // average of cos(Psi_{East,n}-Psi_{West,n}) using phi-weighted and shifted EPs
0160 
0161   TFile* mCorrectionInputFile;
0162   TFile* mCorrectionOutputFile;
0163 
0164   //  these are shift correction factors that we MAKE now and write out
0165   TProfile2D* mEpShiftOutput_sin[_EpOrderMax];   
0166   TProfile2D* mEpShiftOutput_cos[_EpOrderMax];    
0167   //  these are shift correction factors that we made before, and USE now
0168   TProfile2D* mEpShiftInput_sin[_EpOrderMax];     
0169   TProfile2D* mEpShiftInput_cos[_EpOrderMax];     
0170   //   these are the phi weights
0171   TH2D* mPhiWeightInput;
0172   TH2D* mPhiWeightOutput;
0173   TH2D* mPhiAveraged;
0174 
0175 };
0176 
0177 #endif