Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-04 02:03:03

0001 #ifndef HISTOGRAMS_H
0002 #define HISTOGRAMS_H
0003 
0004 /** \class Histograms
0005  *  Classes for histograms handling.
0006  *
0007  *  \author R. Bellan - INFN Torino
0008  */
0009 #include "TFile.h"
0010 #include "TH1F.h"
0011 #include "TH2F.h"
0012 #include "TH3F.h"
0013 #include "TString.h"
0014 
0015 #include <iostream>
0016 #include <string>
0017 
0018 #include "DataFormats/GeometryVector/interface/Pi.h"
0019 
0020 namespace hist_helper {
0021   struct no_deleter {
0022     void operator()(void *) const {}
0023   };
0024   template <typename T>
0025   std::shared_ptr<T> make_non_owning(T *iT) {
0026     return std::shared_ptr<T>(iT, no_deleter());
0027   }
0028 
0029   template <typename T>
0030   std::shared_ptr<T> make_non_owning_cast(TObject *iT) {
0031     return std::shared_ptr<T>(dynamic_cast<T *>(iT), no_deleter());
0032   }
0033 }  // namespace hist_helper
0034 
0035 class hDigis {
0036 public:
0037   hDigis(std::string name_) {
0038     TString N = name_.c_str();
0039     name = N;
0040     // booking degli istogrammi unidimensionali
0041     hMuonDigis = std::make_shared<TH1F>(N + "_hMuonDigis", "number of muon digis", 20, 0., 20.);
0042     hMuonTimeDigis = std::make_shared<TH1F>(N + "_hMuonTimeDigis", "Muon digis time box", 2048, 0., 1600.);
0043     //    control = std::make_shared<TH1F> (N+"_control", "control", 2048, 0.,
0044     //    1600.);
0045     // 2D
0046     hMuonTimeDigis_vs_theta = std::make_shared<TH2F>(
0047         N + "_hMuonTimeDigis_vs_theta", "Muon digis time box vs theta", 120, -60, 60, 960, 0., 1500.);
0048     hMuonTimeDigis_vs_theta_RZ = std::make_shared<TH2F>(
0049         N + "_hMuonTimeDigis_vs_theta_RZ", "Muon digis time box vs theta only RZ SL", 120, -60, 60, 960, 0., 1500.);
0050     hMuonTimeDigis_vs_theta_RPhi = std::make_shared<TH2F>(
0051         N + "_hMuonTimeDigis_vs_theta_RPhi", "Muon digis time box vs theta only RPhi SL", 120, -60, 60, 960, 0., 1500.);
0052   }
0053 
0054   virtual ~hDigis() {
0055     //     delete hMuonDigis;
0056     //     delete hMuonTimeDigis;
0057     //     delete hMuonTimeDigis_vs_theta;
0058     //     delete hMuonTimeDigis_vs_theta_RZ;
0059     //     delete hMuonTimeDigis_vs_theta_RPhi;
0060   }
0061 
0062   hDigis(std::string name_, TFile *file) {
0063     name = name_.c_str();
0064     // per lettura da file degli istogrammi
0065     // 1D
0066     hMuonDigis = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_MuonDigis"));
0067     hMuonTimeDigis = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_MuonTimeDigis"));
0068     //  control = hist_helper::make_non_owning_cast<TH1F>(
0069     //  file->Get(name+"_control"));
0070     // 2D
0071     hMuonTimeDigis_vs_theta = hist_helper::make_non_owning_cast<TH2F>(file->Get(name + "_MuonTimeDigis_vs_theta"));
0072     hMuonTimeDigis_vs_theta_RZ =
0073         hist_helper::make_non_owning_cast<TH2F>(file->Get(name + "_MuonTimeDigis_vs_theta_RZ"));
0074     hMuonTimeDigis_vs_theta_RPhi =
0075         hist_helper::make_non_owning_cast<TH2F>(file->Get(name + "_MuonTimeDigis_vs_theta_RPhi"));
0076   }
0077 
0078   void Write() {
0079     // 1D
0080     hMuonDigis->Write();
0081     hMuonTimeDigis->Write();
0082 
0083     // 2D
0084     hMuonTimeDigis_vs_theta->Write();
0085     hMuonTimeDigis_vs_theta_RZ->Write();
0086     hMuonTimeDigis_vs_theta_RPhi->Write();
0087   }
0088 
0089   //  void Fill(double ndigi, double time,double theta){
0090   void Fill(double time, double theta, int sltype) {
0091     hMuonTimeDigis->Fill(time);
0092     hMuonTimeDigis_vs_theta->Fill(theta, time);
0093     if (sltype == 2)
0094       hMuonTimeDigis_vs_theta_RZ->Fill(theta, time);
0095     else
0096       hMuonTimeDigis_vs_theta_RPhi->Fill(theta, time);
0097   }
0098 
0099   void FillnDigis(int nDigis) { hMuonDigis->Fill(nDigis); }
0100 
0101   void Asymmetry() {
0102     std::cout << "[" << name << "] theta asymmetry: " << TH2asymmetry(hMuonTimeDigis_vs_theta.get()) << std::endl;
0103     std::cout << "[" << name << "] theta_RZ asymmetry: " << TH2asymmetry(hMuonTimeDigis_vs_theta_RZ.get()) << std::endl;
0104     std::cout << "[" << name << "] theta_RPhi asymmetry: " << TH2asymmetry(hMuonTimeDigis_vs_theta_RPhi.get())
0105               << std::endl;
0106   }
0107 
0108 private:
0109   double TH2asymmetry(TH2F *H) {
0110     double sx = H->Integral(0, 60, 0, 960);
0111     double dx = H->Integral(60, 120, 0, 960);
0112     double asym = (sx - dx) / (sx + dx);
0113     return asym;
0114   }
0115 
0116 public:
0117   // 1D
0118   std::shared_ptr<TH1F> hMuonDigis;
0119   std::shared_ptr<TH1F> hMuonTimeDigis;
0120   // 2D
0121   std::shared_ptr<TH2F> hMuonTimeDigis_vs_theta;
0122   std::shared_ptr<TH2F> hMuonTimeDigis_vs_theta_RZ;
0123   std::shared_ptr<TH2F> hMuonTimeDigis_vs_theta_RPhi;
0124 
0125 private:
0126   TString name;
0127 };
0128 
0129 class hHits {
0130 public:
0131   hHits(std::string name_) {
0132     TString N = name_.c_str();
0133     name = N;
0134     // booking degli istogrammi unidimensionali
0135     hHitType = std::make_shared<TH1F>(N + "_HitType", "Hit Type distribution for " + N, 20, -5, 15);
0136     hDeltaZ = std::make_shared<TH1F>(N + "_DeltaZ", "z_{exit} - z_{entry} distribution for " + N, 100, -1.2, 1.2);
0137     hDeltaY = std::make_shared<TH1F>(N + "_DeltaY", "y_{exit} - y_{entry} distribution for " + N, 100, -1.2, 1.2);
0138     hDeltaX = std::make_shared<TH1F>(N + "_DeltaX", "x_{exit} - x_{entry} distribution for " + N, 100, -1.2, 1.2);
0139     hZentry = std::make_shared<TH1F>(N + "_Zentry", "z_{entry} distribution for " + N, 500, -0.6, 0.6);
0140     hZexit = std::make_shared<TH1F>(N + "_Zexit", "z_{exit} distribution for " + N, 500, -0.6, 0.6);
0141     hXentry = std::make_shared<TH1F>(N + "_Xentry", "x_{entry} distribution for " + N, 500, -0.6, 0.6);
0142     hXexit = std::make_shared<TH1F>(N + "_Xexit", "x_{exit} distribution for " + N, 500, -0.6, 0.6);
0143     hYentry = std::make_shared<TH1F>(N + "_Yentry", "y_{entry} distribution for " + N, 500, -0.6, 0.6);
0144     hYexit = std::make_shared<TH1F>(N + "_Yexit", "y_{exit} distribution for " + N, 500, -0.6, 0.6);
0145     hHitMomentum = std::make_shared<TH1F>(N + "_HitMomentum", "Momentum distribution for " + N, 100, 0, 100);
0146     hAbsZEntry =
0147         std::make_shared<TH1F>(N + "_AbsZEntry",
0148                                "|z| distribution for " + N + " entry points in the horizontal planes of the cell",
0149                                100,
0150                                0.57,
0151                                0.58);
0152     hAbsZExit =
0153         std::make_shared<TH1F>(N + "_AbsZExit",
0154                                "|z| distribution for " + N + " exit points in the horizontal planes of the cell",
0155                                100,
0156                                0.57,
0157                                0.58);
0158     hAbsXEntry =
0159         std::make_shared<TH1F>(N + "_AbsXEntry",
0160                                "|x| distribution for " + N + " entry points in the vertical planes of the cell",
0161                                100,
0162                                2.045,
0163                                2.055);
0164     hAbsXExit = std::make_shared<TH1F>(N + "_AbsXExit",
0165                                        "|x| distribution for " + N + " exit points in the vertical planes of the cell",
0166                                        100,
0167                                        2.04,
0168                                        2.06);
0169     hAbsYEntry = std::make_shared<TH1F>(
0170         N + "_AbsYEntry", "|y| distribution for " + N + " entry points in the vertical planes of the cell", 100, 0, 150);
0171     hAbsYExit = std::make_shared<TH1F>(
0172         N + "_AbsYExit", "|y| distribution for " + N + " exit points in the vertical planes of the cell", 100, 0, 150);
0173     hSagittaGeom = std::make_shared<TH1F>(N + "_SagittaGeom", "Geometric Sagitta distribution for " + N, 100, 0, .01);
0174     hSagittaMag =
0175         std::make_shared<TH1F>(N + "_SagittaMag", "Sagitta from magnetic bendig distribution, for " + N, 100, 0, .06);
0176     hSagittaPVSType = std::make_shared<TH2F>(N + "_SagittaPVSType", "Sagitta P VS hit type", 14, 0, 14, 100, 0, .01);
0177     hSagittaBVSType = std::make_shared<TH2F>(N + "_SagittaBVSType", "Sagitta B VS hit type", 14, 0, 14, 100, 0, .06);
0178     hPathVSType = std::make_shared<TH2F>(N + "_PathVSType", "Path VS hit type", 14, 0, 14, 840, 0, 4.2);
0179     hPathXVSType = std::make_shared<TH2F>(N + "_PathXVSType", "X Path VS hit type", 14, 0, 14, 840, 0, 4.2);
0180     hProcessType = std::make_shared<TH1F>(N + "_ProcessType", "Process Type", 17, 0, 17);
0181     hProcessVsHitType =
0182         std::make_shared<TH2F>(N + "_ProcessVsHitType", "Process Type Vs Hit Type", 14, 0, 14, 17, 0, 17);
0183     hPathVsProcess = std::make_shared<TH2F>(N + "_PathVsProcess", "Path vs Process Type", 14, 0, 14, 840, 0, 4.2);
0184     hPathXVsProcess =
0185         std::make_shared<TH2F>(N + "_PathXVsProcess", "Path along X vs Process Type", 14, 0, 14, 840, 0, 4.2);
0186 
0187     h3DPathXVsProcessVsType = std::make_shared<TH3F>(
0188         N + "_h3DPathXVsProcessVsType", "Path along X vs Process Type and hit type", 14, 0, 14, 17, 0, 17, 840, 0, 4.2);
0189     h3DPathVsProcessVsType = std::make_shared<TH3F>(
0190         N + "_h3DPathVsProcessVsType", "Path vs Process Type and hit type", 14, 0, 14, 17, 0, 17, 840, 0, 4.2);
0191     h3DXexitVsProcessVsType = std::make_shared<TH3F>(
0192         N + "_h3DXexitVsProcessVsType", "X exit vs Process Type and hit type", 14, 0, 14, 17, 0, 17, 500, -0.6, 0.6);
0193 
0194     hHitTOF = std::make_shared<TH1F>(N + "_HitTOF", "Hit TOF distribution for " + N, 1000, 1e4, 1e8);
0195   }
0196 
0197   virtual ~hHits() {
0198     //     delete hHitType;
0199     //     delete hZentry;
0200     //     delete hZexit;
0201     //     delete hXentry;
0202     //     delete hXexit;
0203     //     delete hYentry;
0204     //     delete hYexit;
0205     //     delete hDeltaZ;
0206     //     delete hDeltaY;
0207     //     delete hDeltaX;
0208     //     delete hAbsZEntry;
0209     //     delete hAbsZExit;
0210     //     delete hAbsXEntry;
0211     //     delete hAbsXExit;
0212     //     delete hAbsYEntry;
0213     //     delete hAbsYExit;
0214     //     delete hHitMomentum;
0215     //     delete hSagittaGeom;
0216     //     delete hSagittaMag;
0217     //     delete hSagittaPVSType;
0218     //     delete hSagittaBVSType;
0219     //     delete hPathVSType;
0220     //     delete hPathXVSType;
0221     //     delete hProcessType;
0222     //     delete hProcessVsHitType;
0223     //     delete hPathVsProcess;
0224     //     delete hPathXVsProcess;
0225 
0226     //     delete h3DPathXVsProcessVsType;
0227     //     delete h3DPathVsProcessVsType;
0228     //     delete h3DXexitVsProcessVsType;
0229   }
0230 
0231   hHits(std::string name_, TFile *file) {
0232     name = name_.c_str();
0233     // per lettura da file degli istogrammi
0234     // 1D
0235     hHitType = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_HitType"));
0236     hDeltaZ = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_DeltaZ"));
0237     hDeltaY = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_DeltaY"));
0238     hDeltaX = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_DeltaX"));
0239     hZentry = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Zentry"));
0240     hZexit = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Zexit"));
0241     hXentry = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Xentry"));
0242     hXexit = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Xexit"));
0243     hYentry = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Yentry"));
0244     hYexit = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Yexit"));
0245     hHitMomentum = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_HitMomentum"));
0246     hAbsZEntry = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_AbsZEntry"));
0247     hAbsZExit = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_AbsZExit"));
0248     hAbsXEntry = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_AbsXEntry"));
0249     hAbsXExit = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_AbsXExit"));
0250     hAbsYEntry = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_AbsYEntry"));
0251     hAbsYExit = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_AbsYExit"));
0252     hSagittaGeom = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_SagittaGeom"));
0253     hSagittaMag = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_SagittaMag"));
0254     hSagittaPVSType = hist_helper::make_non_owning_cast<TH2F>(file->Get(name + "_SagittaPVSType"));
0255     hSagittaBVSType = hist_helper::make_non_owning_cast<TH2F>(file->Get(name + "_SagittaBVSType"));
0256     hPathVSType = hist_helper::make_non_owning_cast<TH2F>(file->Get(name + "_PathVSType"));
0257     hPathXVSType = hist_helper::make_non_owning_cast<TH2F>(file->Get(name + "_PathXVSType"));
0258     hProcessType = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_ProcessType"));
0259     hProcessVsHitType = hist_helper::make_non_owning_cast<TH2F>(file->Get(name + "_ProcessVsHitType"));
0260     hPathVsProcess = hist_helper::make_non_owning_cast<TH2F>(file->Get(name + "_PathVsProcess"));
0261     hPathXVsProcess = hist_helper::make_non_owning_cast<TH2F>(file->Get(name + "_PathXVsProcess"));
0262     h3DPathXVsProcessVsType = hist_helper::make_non_owning_cast<TH3F>(file->Get(name + "_h3DPathXVsProcessVsType"));
0263     h3DPathVsProcessVsType = hist_helper::make_non_owning_cast<TH3F>(file->Get(name + "_h3DPathVsProcessVsType"));
0264     h3DXexitVsProcessVsType = hist_helper::make_non_owning_cast<TH3F>(file->Get(name + "_h3DXexitVsProcessVsType"));
0265   }
0266 
0267   void Write() {
0268     hHitType->Write();
0269     hZentry->Write();
0270     hZexit->Write();
0271     hXentry->Write();
0272     hXexit->Write();
0273     hYentry->Write();
0274     hYexit->Write();
0275     hDeltaZ->Write();
0276     hDeltaY->Write();
0277     hDeltaX->Write();
0278     hAbsZEntry->Write();
0279     hAbsZExit->Write();
0280     hAbsXEntry->Write();
0281     hAbsXExit->Write();
0282     hAbsYEntry->Write();
0283     hAbsYExit->Write();
0284     hHitMomentum->Write();
0285     hSagittaGeom->Write();
0286     hSagittaMag->Write();
0287     hSagittaPVSType->Write();
0288     hSagittaBVSType->Write();
0289     hPathVSType->Write();
0290     hPathXVSType->Write();
0291     hProcessType->Write();
0292     hProcessVsHitType->Write();
0293     hPathVsProcess->Write();
0294     hPathXVsProcess->Write();
0295     h3DPathXVsProcessVsType->Write();
0296     h3DPathVsProcessVsType->Write();
0297     h3DXexitVsProcessVsType->Write();
0298     hHitTOF->Write();
0299   }
0300 
0301   void FillTOF(double tof) { hHitTOF->Fill(tof); }
0302 
0303   void Fill(double xEntry,
0304             double xExit,
0305             double entryPy,
0306             double exitPy,
0307             double entryPz,
0308             double exitPz,
0309             double path,
0310             double path_x,
0311             int hitType,
0312             float processType,
0313             double pAbs) {  //,double wire_length){
0314 
0315     hHitType->Fill(hitType);
0316     hZentry->Fill(entryPz);
0317     hZexit->Fill(exitPz);
0318 
0319     hXentry->Fill(xEntry);
0320     hXexit->Fill(xExit);
0321     hYentry->Fill(entryPy);
0322     hYexit->Fill(exitPy);
0323 
0324     hDeltaZ->Fill(exitPz - entryPz);
0325     hDeltaY->Fill(exitPy - entryPy);
0326     hDeltaX->Fill(xExit - xEntry);
0327 
0328     hHitMomentum->Fill(pAbs);
0329 
0330     hAbsZEntry->Fill(fabs(entryPz));
0331     hAbsZExit->Fill(fabs(exitPz));
0332 
0333     if (fabs(entryPz) < 0.573) {
0334       hAbsXEntry->Fill(fabs(xEntry));
0335     }
0336 
0337     if (fabs(exitPz) < 0.573) {
0338       hAbsXExit->Fill(fabs(xExit));
0339     }
0340 
0341     //  hAbsYEntry->Fill(wire_length/2.-fabs(entryPy));
0342     // hAbsYExit->Fill(wire_length/2.-fabs(exitPy));
0343 
0344     hPathVSType->Fill(hitType, path);
0345     hPathXVSType->Fill(hitType, path_x);
0346     hProcessType->Fill(processType);
0347     hProcessVsHitType->Fill(hitType, processType);
0348     hPathVsProcess->Fill(processType, path);
0349     hPathXVsProcess->Fill(processType, path_x);
0350 
0351     h3DPathXVsProcessVsType->Fill(processType, hitType, path_x);
0352     h3DPathVsProcessVsType->Fill(processType, hitType, path);
0353     h3DXexitVsProcessVsType->Fill(processType, hitType, xExit);
0354   }
0355 
0356   void FillSagittas(double SG, double SM, int hitType) {
0357     hSagittaGeom->Fill(SG);
0358     hSagittaMag->Fill(SM);
0359     hSagittaPVSType->Fill(hitType, SG);
0360     hSagittaBVSType->Fill(hitType, SM);
0361   }
0362 
0363 public:
0364   std::shared_ptr<TH1F> hHitType;
0365   std::shared_ptr<TH1F> hZentry;
0366   std::shared_ptr<TH1F> hZexit;
0367   std::shared_ptr<TH1F> hXentry;
0368   std::shared_ptr<TH1F> hXexit;
0369   std::shared_ptr<TH1F> hYentry;
0370   std::shared_ptr<TH1F> hYexit;
0371   std::shared_ptr<TH1F> hDeltaZ;
0372   std::shared_ptr<TH1F> hDeltaY;
0373   std::shared_ptr<TH1F> hDeltaX;
0374   std::shared_ptr<TH1F> hAbsZEntry;
0375   std::shared_ptr<TH1F> hAbsZExit;
0376   std::shared_ptr<TH1F> hAbsXEntry;
0377   std::shared_ptr<TH1F> hAbsXExit;
0378   std::shared_ptr<TH1F> hAbsYEntry;
0379   std::shared_ptr<TH1F> hAbsYExit;
0380   std::shared_ptr<TH1F> hHitMomentum;
0381   std::shared_ptr<TH1F> hSagittaGeom;
0382   std::shared_ptr<TH1F> hSagittaMag;
0383   std::shared_ptr<TH2F> hSagittaPVSType;
0384   std::shared_ptr<TH2F> hSagittaBVSType;
0385   std::shared_ptr<TH2F> hPathVSType;
0386   std::shared_ptr<TH2F> hPathXVSType;
0387   std::shared_ptr<TH1F> hProcessType;
0388   std::shared_ptr<TH2F> hProcessVsHitType;
0389   std::shared_ptr<TH2F> hPathVsProcess;
0390   std::shared_ptr<TH2F> hPathXVsProcess;
0391   std::shared_ptr<TH3F> h3DPathXVsProcessVsType;
0392   std::shared_ptr<TH3F> h3DPathVsProcessVsType;
0393   std::shared_ptr<TH3F> h3DXexitVsProcessVsType;
0394   std::shared_ptr<TH1F> hHitTOF;
0395 
0396 private:
0397   TString name;
0398 };
0399 
0400 class hDeltaR {
0401 public:
0402   hDeltaR(std::string name_) {
0403     TString N = name_.c_str();
0404     name = N;
0405     // booking degli istogrammi unidimensionali
0406     hZentry = std::make_shared<TH1F>(N + "_Zentry", "z_{entry} distribution", 120, -0.6, 0.6);
0407     hXentry = std::make_shared<TH1F>(N + "_Xentry", "x_{entry} distribution", 120, -4.2, 4.2);
0408     hYentry = std::make_shared<TH1F>(N + "_Yentry", "y_{entry} distribution", 120, -400, 400);
0409     hHitMomentum = std::make_shared<TH1F>(N + "_HitMomentum", "Momentum distribution", 100, 0, .2);
0410     hHitEnergyLoss =
0411         std::make_shared<TH1F>(N + "_HitEnergyLoss", "Energy Loss distribution", 75, 0, 100);  // in keV--> x10^6
0412     hSagittaMag = std::make_shared<TH1F>(N + "_SagittaMag", "Sagitta from magnetic bendig", 120, 0, .04);
0413     hPath = std::make_shared<TH1F>(N + "_Path", "Path", 200, 0, 4.2);
0414     hPathX = std::make_shared<TH1F>(N + "_PathX", "X Path", 200, 0, 4.2);
0415     hZoomPath = std::make_shared<TH1F>(N + "_ZoomPath", "Path", 200, 0, .1);
0416     hZoomPathX = std::make_shared<TH1F>(N + "_ZoomPathX", "X Path", 200, 0, .1);
0417     hType = std::make_shared<TH1F>(N + "_Type", "Delta type 3-electron 2-positron", 4, 0, 4);
0418   }
0419 
0420   virtual ~hDeltaR() {
0421     //     delete hType;
0422     //     delete hZentry;
0423     //     delete hXentry;
0424     //     delete hYentry;
0425     //     delete hHitMomentum;
0426     //     delete hHitEnergyLoss;
0427     //     delete hSagittaMag;
0428     //     delete hPath;
0429     //     delete hPathX;
0430     //     delete hZoomPath;
0431     //     delete hZoomPathX;
0432   }
0433 
0434   hDeltaR(std::string name_, TFile *file) {
0435     name = name_.c_str();
0436     // per lettura da file degli istogrammi
0437     // 1D
0438     hType = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Type"));
0439     hZentry = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Zentry"));
0440     hXentry = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Xentry"));
0441     hYentry = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Yentry"));
0442     hHitMomentum = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_HitMomentum"));
0443     hHitMomentum = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_HitEnergyLoss"));
0444     hSagittaMag = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_SagittaMag"));
0445     hPath = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_Path"));
0446     hPathX = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_PathX"));
0447     hZoomPath = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_ZoomPath"));
0448     hZoomPathX = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_ZoomPathX"));
0449   }
0450 
0451   void Write() {
0452     hType->Write();
0453     hZentry->Write();
0454     hXentry->Write();
0455     hYentry->Write();
0456     hHitMomentum->Write();
0457     hSagittaMag->Write();
0458     hPath->Write();
0459     hPathX->Write();
0460     hZoomPath->Write();
0461     hZoomPathX->Write();
0462   }
0463 
0464   void Fill(double xEntry,
0465             double yEntry,
0466             double zEntry,
0467             double path,
0468             double path_x,
0469             double SM,
0470             double pAbs,
0471             double En,
0472             int type) {
0473     hZentry->Fill(zEntry);
0474     hXentry->Fill(xEntry);
0475     hYentry->Fill(yEntry);
0476 
0477     hHitMomentum->Fill(pAbs);
0478     hHitEnergyLoss->Fill(En * 1e6);
0479 
0480     hPath->Fill(path);
0481     hPathX->Fill(path_x);
0482     if (path <= .1)
0483       hZoomPath->Fill(path);
0484     if (path_x <= .1)
0485       hZoomPathX->Fill(path_x);
0486 
0487     hSagittaMag->Fill(SM);
0488     hType->Fill(type);
0489   }
0490 
0491 public:
0492   std::shared_ptr<TH1F> hType;
0493   std::shared_ptr<TH1F> hZentry;
0494   std::shared_ptr<TH1F> hXentry;
0495   std::shared_ptr<TH1F> hYentry;
0496   std::shared_ptr<TH1F> hHitMomentum;
0497   std::shared_ptr<TH1F> hHitEnergyLoss;
0498   std::shared_ptr<TH1F> hSagittaMag;
0499   std::shared_ptr<TH1F> hPath;
0500   std::shared_ptr<TH1F> hPathX;
0501   std::shared_ptr<TH1F> hZoomPath;
0502   std::shared_ptr<TH1F> hZoomPathX;
0503 
0504 private:
0505   TString name;
0506 };
0507 
0508 class hParam {
0509 public:
0510   hParam(std::string name_) {
0511     TString N = name_.c_str();
0512     name = N;
0513     // booking degli istogrammi unidimensionali
0514     HitParam_X = std::make_shared<TH1F>(
0515         N + "_HitParam_X", "Distribution of theta for parameterization cases in Rphi layers", 100, -2.1, 2.1);
0516     HitParam_Theta = std::make_shared<TH1F>(
0517         N + "_HitParam_Theta", "Distribution of theta for parameterization cases in Rphi layers", 100, -180., 180.);
0518     HitParam_Bwire = std::make_shared<TH1F>(
0519         N + "_HitParam_Bwire", "Distribution of bwire for parameterization cases in Rz layers", 100, -0.5, 0.5);
0520     HitParam_Bnorm = std::make_shared<TH1F>(
0521         N + "_HitParam_Bnorm", "Distribution of bnorm for parameterization cases in Rphi layers", 100, -1, 1);
0522   }
0523 
0524   virtual ~hParam() {
0525     //   delete HitParam_X;
0526     //   delete HitParam_Theta;
0527     //   delete HitParam_Bwire;
0528     //   delete HitParam_Bnorm;
0529   }
0530 
0531   hParam(std::string name_, TFile *file) {
0532     name = name_.c_str();
0533     // per lettura da file degli istogrammi
0534     // 1D
0535     HitParam_X = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_HitParam_X"));
0536     HitParam_Theta = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_HitParam_Theta"));
0537     HitParam_Bwire = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_HitParam_Bwire"));
0538     HitParam_Bnorm = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_HitParam_Bnorm"));
0539   }
0540 
0541   void Fill(double x, double theta, double Bwire, double Bnorm) {
0542     HitParam_X->Fill(x);
0543     HitParam_Theta->Fill(theta);
0544     HitParam_Bwire->Fill(Bwire);
0545     HitParam_Bnorm->Fill(Bnorm);
0546   }
0547 
0548   void Write() {
0549     HitParam_X->Write();
0550     HitParam_Theta->Write();
0551     HitParam_Bwire->Write();
0552     HitParam_Bnorm->Write();
0553   }
0554 
0555 public:
0556   std::shared_ptr<TH1F> HitParam_X;
0557   std::shared_ptr<TH1F> HitParam_Theta;
0558   std::shared_ptr<TH1F> HitParam_Bwire;
0559   std::shared_ptr<TH1F> HitParam_Bnorm;
0560 
0561 private:
0562   TString name;
0563 };
0564 
0565 class hMuonStat {
0566 public:
0567   hMuonStat(std::string name_) {
0568     TString N = name_.c_str();
0569     name = N;
0570     // booking degli istogrammi unidimensionali
0571     hMuonNumber = std::make_shared<TH1F>("hMuon" + N, "Muon hits ", 200, 0., 200.);
0572     hMuonVsEta = std::make_shared<TH1F>("hMuon" + N + "VsEta", "Muon " + N + " vs eta", 100, -1.2, 1.2);
0573     hMuonVsPhi = std::make_shared<TH1F>("hMuon" + N + "VsPhi", "Muon " + N + " vs phi", 100, -Geom::pi(), +Geom::pi());
0574   }
0575 
0576   hMuonStat(std::string name_, TFile *file) {
0577     name = name_.c_str();
0578     // per lettura da file degli istogrammi
0579     // 1D
0580     hMuonNumber = hist_helper::make_non_owning_cast<TH1F>(file->Get("hMuon" + name));
0581     hMuonVsEta = hist_helper::make_non_owning_cast<TH1F>(file->Get("hMuon" + name + "VsEta"));
0582     hMuonVsPhi = hist_helper::make_non_owning_cast<TH1F>(file->Get("hMuon" + name + "VsPhi"));
0583   }
0584 
0585   ~hMuonStat() {
0586     //       delete hMuonNumber;
0587     //       delete hMuonVsEta;
0588     //       delete hMuonVsPhi;
0589   }
0590   void Write() {
0591     hMuonNumber->Write();
0592     hMuonVsEta->Write();
0593     hMuonVsPhi->Write();
0594   }
0595 
0596   void Fill(int hits, double eta, double phi) {
0597     hMuonNumber->Fill(hits);
0598     hMuonVsEta->Fill(eta, hits);
0599     hMuonVsPhi->Fill(phi, hits);
0600   }
0601 
0602 public:
0603   std::shared_ptr<TH1F> hMuonNumber;
0604   std::shared_ptr<TH1F> hMuonVsEta;
0605   std::shared_ptr<TH1F> hMuonVsPhi;
0606 
0607 private:
0608   TString name;
0609 };
0610 
0611 class hTOF {
0612 public:
0613   hTOF(std::string name) {
0614     TString N = name.c_str();
0615 
0616     hTOF_true = std::make_shared<TH1F>(N + "_TOF_true", "TOF true", 200, 10., 35.);
0617     hTOF_hitPos = std::make_shared<TH1F>(N + "_TOF_hitPos", "TOF assumed, hit pos", 200, 10., 35.);
0618     hTOF_WC = std::make_shared<TH1F>(N + "_TOF_WC", "TOF assumed, wire center", 200, 10., 35.);
0619 
0620     hDeltaTOF_hitPos = std::make_shared<TH1F>(N + "_DeltaTOF_hitPos", "TOF assumed, hit pos", 200, -5., 5.);
0621     hDeltaTOF_WC = std::make_shared<TH1F>(N + "_DelataTOF_WC", "TOF assumed, wire center", 200, -5., 5.);
0622   }
0623 
0624   hTOF(std::string name_, TFile *file) {
0625     name = name_.c_str();
0626     hTOF_true = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_TOF_true"));
0627     hTOF_hitPos = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_TOF_hitPos"));
0628     hTOF_WC = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_TOF_WC"));
0629     hDeltaTOF_hitPos = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_DeltaTOF_hitPos"));
0630     hDeltaTOF_WC = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_DeltaTOF_WC"));
0631   }
0632 
0633   ~hTOF() {
0634     //     delete hTOF_true;
0635     //     delete hTOF_hitPos;
0636     //     delete hTOF_WC;
0637     //     delete hDeltaTOF_hitPos;
0638     //     delete hDeltaTOF_WC;
0639   }
0640 
0641   void Fill(float tof, float TOF_WC, float TOF_hitPos) {
0642     hTOF_hitPos->Fill(TOF_hitPos);
0643     hTOF_WC->Fill(TOF_WC);
0644     hTOF_true->Fill(tof);
0645     hDeltaTOF_hitPos->Fill(tof - TOF_hitPos);
0646     hDeltaTOF_WC->Fill(tof - TOF_WC);
0647   }
0648 
0649   void Write() {
0650     hTOF_true->Write();
0651     hTOF_hitPos->Write();
0652     hTOF_WC->Write();
0653     hDeltaTOF_hitPos->Write();
0654     hDeltaTOF_WC->Write();
0655   }
0656 
0657 public:
0658   std::shared_ptr<TH1F> hTOF_true;
0659   std::shared_ptr<TH1F> hTOF_hitPos;
0660   std::shared_ptr<TH1F> hTOF_WC;
0661   std::shared_ptr<TH1F> hDeltaTOF_hitPos;
0662   std::shared_ptr<TH1F> hDeltaTOF_WC;
0663 
0664 private:
0665   TString name;
0666 };
0667 
0668 class hTDelay {
0669 public:
0670   hTDelay(std::string name) {
0671     TString N = name.c_str();
0672 
0673     hTDelay_true = std::make_shared<TH1F>(N + "_TDelay_true", "Delay (true)", 100, 0., 15.);
0674     hTDelay_WC = std::make_shared<TH1F>(N + "_TDelay_WC", "Delay (assumed, wire center)", 100, 0., 15.);
0675 
0676     hTDelay_hitpos = std::make_shared<TH1F>(N + "_TDelay_hitpos", "Delay (assumed, hit pos)", 100, 0., 15.);
0677 
0678     hDeltaTDelay_WC = std::make_shared<TH1F>(N + "_dTDelay_WC", "Delay true - WC", 150, -15, 15.);
0679     hDeltaTDelay_hitpos = std::make_shared<TH1F>(N + "_dTDelay_hitpos", "Delay true - hitpos", 150, -15, 15.);
0680   }
0681 
0682   hTDelay(std::string name_, TFile *file) {
0683     name = name_.c_str();
0684     hTDelay_true = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_TDelay_true"));
0685     hTDelay_WC = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_TDelay_WC"));
0686     hTDelay_hitpos = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_TDelay_hitpos"));
0687     hDeltaTDelay_WC = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_DeltaTDelay_WC"));
0688     hDeltaTDelay_hitpos = hist_helper::make_non_owning_cast<TH1F>(file->Get(name + "_DeltaTDelay_hitpos"));
0689   }
0690   ~hTDelay() {
0691     //     delete hTDelay_true;
0692     //     delete hTDelay_WC;
0693     //     delete hTDelay_hitpos;
0694     //     delete hDeltaTDelay_WC;
0695     //     delete hDeltaTDelay_hitpos;
0696   }
0697 
0698   void Fill(float t_True, float t_WC, float t_hitpos) {
0699     hTDelay_true->Fill(t_True);
0700     hTDelay_WC->Fill(t_WC);
0701     hTDelay_hitpos->Fill(t_hitpos);
0702     hDeltaTDelay_WC->Fill(t_WC - t_True);
0703     hDeltaTDelay_hitpos->Fill(t_hitpos - t_True);
0704   }
0705 
0706   void Write() {
0707     hTDelay_true->Write();
0708     hTDelay_WC->Write();
0709     hTDelay_hitpos->Write();
0710     hDeltaTDelay_WC->Write();
0711     hDeltaTDelay_hitpos->Write();
0712   }
0713 
0714 public:
0715   std::shared_ptr<TH1F> hTDelay_true;
0716   std::shared_ptr<TH1F> hTDelay_WC;
0717   std::shared_ptr<TH1F> hTDelay_hitpos;
0718   std::shared_ptr<TH1F> hDeltaTDelay_WC;
0719   std::shared_ptr<TH1F> hDeltaTDelay_hitpos;
0720 
0721 private:
0722   TString name;
0723 };
0724 
0725 template <class hTime>
0726 class hTimes {
0727 public:
0728   hTimes(std::string name) {
0729     RZ = std::make_shared<hTime>(name + "_RZ");
0730     RPhi = std::make_shared<hTime>(name + "_RPhi");
0731     W0 = std::make_shared<hTime>(name + "_Wheel0");
0732     W1 = std::make_shared<hTime>(name + "_Wheel1");
0733     W2 = std::make_shared<hTime>(name + "_Wheel2");
0734   }
0735 
0736   hTimes(std::string name_, TFile *file) {
0737     name = name_.c_str();
0738 
0739     RZ = hist_helper::make_non_owning_cast<hTime>(file->Get(name + "_RZ"));
0740     RPhi = hist_helper::make_non_owning_cast<hTime>(file->Get(name + "_RPhi"));
0741     W0 = hist_helper::make_non_owning_cast<hTime>(file->Get(name + "_Wheel0"));
0742     W1 = hist_helper::make_non_owning_cast<hTime>(file->Get(name + "_Wheel1"));
0743     W2 = hist_helper::make_non_owning_cast<hTime>(file->Get(name + "_Wheel2"));
0744   }
0745 
0746   ~hTimes() {
0747     //     delete RZ;
0748     //     delete RPhi;
0749     //     delete W0;
0750     //     delete W1;
0751     //     delete W2;
0752   }
0753 
0754   void Fill(float t_True, float t_WC, float t_hitpos, int wheel_type, int sltype) {
0755     if (sltype == 2)
0756       RZ->Fill(t_True, t_WC, t_hitpos);
0757     else
0758       RPhi->Fill(t_True, t_WC, t_hitpos);
0759     WheelHistos(wheel_type)->Fill(t_True, t_WC, t_hitpos);
0760   }
0761 
0762   void Write() {
0763     RZ->Write();
0764     RPhi->Write();
0765     W0->Write();
0766     W1->Write();
0767     W2->Write();
0768   }
0769 
0770   hTime *WheelHistos(int wheel) {
0771     switch (abs(wheel)) {
0772       case 0:
0773         return W0;
0774 
0775       case 1:
0776         return W1;
0777 
0778       case 2:
0779         return W2;
0780 
0781       default:
0782         return NULL;
0783     }
0784   }
0785 
0786 private:
0787   std::shared_ptr<hTime> RZ;
0788   std::shared_ptr<hTime> RPhi;
0789   std::shared_ptr<hTime> W0;
0790   std::shared_ptr<hTime> W1;
0791   std::shared_ptr<hTime> W2;
0792 
0793 private:
0794   TString name;
0795 };
0796 
0797 #endif