CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/SUSYBSMAnalysis/HSCP/src/HSCPTreeBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HSCPTreeBuilder
00004 // Class:      HSCPTreeBuilder
00005 // 
00013 //
00014 // Original Author:  Loic QUERTENMONT
00015 //         Created:  Thu Mar 11 12:19:07 CEST 2010
00016 // $Id: HSCPTreeBuilder.cc,v 1.7 2010/12/16 17:08:25 querten Exp $
00017 //
00018 
00019 
00020 #include <memory>
00021 #include <cmath>
00022 
00023 #include "FWCore/Framework/interface/Frameworkfwd.h"
00024 #include "FWCore/Framework/interface/EDFilter.h"
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "FWCore/Framework/interface/MakerMacros.h"
00027 #include "FWCore/Framework/interface/ESHandle.h"
00028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030 #include "FWCore/Utilities/interface/Exception.h"
00031 
00032 #include "DataFormats/TrackReco/interface/DeDxData.h"
00033 
00034 #include <MagneticField/Engine/interface/MagneticField.h>
00035 #include <MagneticField/Records/interface/IdealMagneticFieldRecord.h>
00036 
00037 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00038 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00039 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00040 #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h"
00041 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
00042 
00043 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00044 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00045 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00046 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00047 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00048 #include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
00049 
00050 #include "DataFormats/SiStripCluster/interface/SiStripClusterCollection.h"
00051 
00052 #include "DataFormats/MuonReco/interface/Muon.h"
00053 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00054 
00055 #include "DataFormats/TrackReco/interface/Track.h"
00056 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00057 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00058 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00059 #include "DataFormats/SiStripDetId/interface/SiStripSubStructure.h"
00060 #include "DataFormats/DetId/interface/DetId.h"
00061 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00062 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00063 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00064 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00065 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00066 
00067 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00068 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00069 
00070 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00071 
00072 #include "FWCore/ServiceRegistry/interface/Service.h"
00073 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00074 
00075 
00076 #include "DataFormats/Common/interface/TriggerResults.h"
00077 #include "FWCore/Common/interface/TriggerNames.h"
00078 #include "FWCore/Framework/interface/TriggerNamesService.h"
00079 
00080 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00081 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00082 
00083 #include "CommonTools/UtilAlgos/interface/DeltaR.h"
00084 
00085 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskTechTrigRcd.h"
00086 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
00087 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
00088 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00089 
00090 #include "DataFormats/VertexReco/interface/Vertex.h"
00091 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00092 
00093 #include "DataFormats/MuonReco/interface/MuonTimeExtra.h"
00094 #include "DataFormats/MuonReco/interface/MuonTimeExtraMap.h"
00095 
00096 #include "AnalysisDataFormats/SUSYBSMObjects/interface/HSCParticle.h"
00097 
00098 
00099 #include "TFile.h"
00100 #include "TObjString.h"
00101 #include "TString.h"
00102 #include "TH1F.h"
00103 #include "TH2F.h"
00104 #include "TProfile.h"
00105 #include "TF1.h"
00106 #include "TTree.h"
00107 #include "TROOT.h"
00108 
00109 #include <ext/hash_map>
00110 
00111 
00112 using namespace edm;
00113 using namespace reco;
00114 using namespace std;
00115 using namespace __gnu_cxx;
00116 
00117 #define MAX_VERTICES 1000
00118 #define MAX_HSCPS    10000
00119 #define MAX_GENS     10000
00120 #define MAX_ECALCRYS 10
00121 
00122 class HSCPTreeBuilder : public edm::EDFilter {
00123         public:
00124                 explicit HSCPTreeBuilder(const edm::ParameterSet&);
00125                 ~HSCPTreeBuilder();
00126 
00127 
00128         private:
00129                 virtual void beginJob() ;
00130                 virtual bool filter(edm::Event&, const edm::EventSetup&);
00131                 virtual void endJob() ;
00132                 int ClosestMuonIndex(reco::TrackRef track, std::vector<reco::MuonRef>);
00133 
00134                 const edm::EventSetup* iSetup_;
00135                 const edm::Event*      iEvent_;
00136 
00137                 edm::Service<TFileService> tfs;
00138                 InputTag       m_HSCPsTag;
00139                 bool           reccordVertexInfo;
00140                 bool           reccordGenInfo;
00141 
00142                 TTree*         MyTree;
00143                 bool           Event_triggerL1Bits[192];
00144                 bool           Event_triggerHLTBits[128];
00145                 bool           Event_technicalBits[64];
00146                 unsigned int   Event_EventNumber;
00147                 unsigned int   Event_RunNumber;
00148                 unsigned int   Event_LumiSection;
00149                 unsigned int   Event_BXCrossing;
00150                 unsigned int   Event_Orbit;
00151                 unsigned int   Event_Store;
00152                 unsigned int   Event_Time;
00153                 bool           Event_PhysicsDeclared;
00154                 float          Event_BField;
00155 
00156                 unsigned int   NVertices;
00157                 float          Vertex_x           [MAX_VERTICES];
00158                 float          Vertex_y           [MAX_VERTICES];
00159                 float          Vertex_z           [MAX_VERTICES];
00160                 float          Vertex_x_err       [MAX_VERTICES];
00161                 float          Vertex_y_err       [MAX_VERTICES];
00162                 float          Vertex_z_err       [MAX_VERTICES];
00163                 int            Vertex_TrackSize   [MAX_VERTICES];
00164                 float          Vertex_chi2        [MAX_VERTICES];
00165                 float          Vertex_ndof        [MAX_VERTICES];
00166                 bool           Vertex_isFake      [MAX_VERTICES];
00167 
00168                 unsigned int   NHSCPs;
00169                 bool           Hscp_hasTrack      [MAX_HSCPS];
00170                 bool           Hscp_hasMuon       [MAX_HSCPS];
00171                 bool           Hscp_hasRpc        [MAX_HSCPS];
00172                 bool           Hscp_hasCalo       [MAX_HSCPS];
00173                 int            Hscp_type          [MAX_HSCPS];
00174                 unsigned int   Track_NOH          [MAX_HSCPS];
00175                 float          Track_p            [MAX_HSCPS];
00176                 float          Track_pt           [MAX_HSCPS];
00177                 float          Track_pt_err       [MAX_HSCPS];
00178                 float          Track_chi2         [MAX_HSCPS];
00179                 unsigned int   Track_ndof         [MAX_HSCPS];
00180                 float          Track_eta          [MAX_HSCPS];  
00181                 float          Track_eta_err      [MAX_HSCPS];
00182                 float          Track_phi          [MAX_HSCPS];
00183                 float          Track_phi_err      [MAX_HSCPS];
00184                 float          Track_dz           [MAX_HSCPS];
00185                 float          Track_d0           [MAX_HSCPS];
00186                 int            Track_quality      [MAX_HSCPS];
00187                 int            Track_charge       [MAX_HSCPS];
00188                 float          Track_dEdxE1       [MAX_HSCPS];
00189                 float          Track_dEdxE1_NOS   [MAX_HSCPS];
00190                 unsigned int   Track_dEdxE1_NOM   [MAX_HSCPS];
00191                 float          Track_dEdxE2       [MAX_HSCPS];
00192                 float          Track_dEdxE2_NOS   [MAX_HSCPS];
00193                 unsigned int   Track_dEdxE2_NOM   [MAX_HSCPS];
00194                 float          Track_dEdxE3       [MAX_HSCPS];
00195                 float          Track_dEdxE3_NOS   [MAX_HSCPS];
00196                 unsigned int   Track_dEdxE3_NOM   [MAX_HSCPS];
00197                 float          Track_dEdxD1       [MAX_HSCPS];
00198                 float          Track_dEdxD1_NOS   [MAX_HSCPS];
00199                 unsigned int   Track_dEdxD1_NOM   [MAX_HSCPS];
00200                 float          Track_dEdxD2       [MAX_HSCPS]; 
00201                 float          Track_dEdxD2_NOS   [MAX_HSCPS];
00202                 unsigned int   Track_dEdxD2_NOM   [MAX_HSCPS];
00203                 float          Track_dEdxD3       [MAX_HSCPS];
00204                 float          Track_dEdxD3_NOS   [MAX_HSCPS];
00205                 unsigned int   Track_dEdxD3_NOM   [MAX_HSCPS];
00206                 float          Muon_p             [MAX_HSCPS];
00207                 float          Muon_pt            [MAX_HSCPS];
00208                 float          Muon_eta           [MAX_HSCPS];
00209                 float          Muon_phi           [MAX_HSCPS];
00210                 int            Muon_type          [MAX_HSCPS];
00211                 bool           Muon_qualityValid  [MAX_HSCPS];
00212                 int            Muon_charge        [MAX_HSCPS];
00213                 float          Muon_dt_IBeta      [MAX_HSCPS];
00214                 float          Muon_dt_IBeta_err  [MAX_HSCPS];
00215                 float          Muon_dt_fIBeta     [MAX_HSCPS];
00216                 float          Muon_dt_fIBeta_err [MAX_HSCPS];
00217                 int            Muon_dt_ndof       [MAX_HSCPS];
00218                 float          Muon_csc_IBeta     [MAX_HSCPS];
00219                 float          Muon_csc_IBeta_err [MAX_HSCPS];
00220                 float          Muon_csc_fIBeta    [MAX_HSCPS];
00221                 float          Muon_csc_fIBeta_err[MAX_HSCPS];
00222                 int            Muon_csc_ndof      [MAX_HSCPS];
00223                 float          Muon_cb_IBeta      [MAX_HSCPS];
00224                 float          Muon_cb_IBeta_err  [MAX_HSCPS];
00225                 float          Muon_cb_fIBeta     [MAX_HSCPS];
00226                 float          Muon_cb_fIBeta_err [MAX_HSCPS];
00227                 int            Muon_cb_ndof       [MAX_HSCPS];          
00228                 float          Rpc_beta           [MAX_HSCPS];
00229 
00230                 float          Calo_ecal_crossedE         [MAX_HSCPS];
00231                 float          Calo_ecal_beta             [MAX_HSCPS];
00232                 float          Calo_ecal_beta_err         [MAX_HSCPS];
00233                 float          Calo_ecal_invBeta_err      [MAX_HSCPS];
00234                 float          Calo_ecal_dEdx             [MAX_HSCPS];
00235                 float          Calo_ecal_time             [MAX_HSCPS];
00236                 float          Calo_ecal_time_err         [MAX_HSCPS];
00237                 int            Calo_ecal_numCrysCrossed   [MAX_HSCPS];
00238                 float          Calo_ecal_swissCrossKs     [MAX_HSCPS][MAX_ECALCRYS];
00239                 float          Calo_ecal_e1OverE9s        [MAX_HSCPS][MAX_ECALCRYS];
00240                 float          Calo_ecal_trackLengths     [MAX_HSCPS][MAX_ECALCRYS];
00241                 float          Calo_ecal_trackExitEtas    [MAX_HSCPS][MAX_ECALCRYS];
00242                 float          Calo_ecal_trackExitPhis    [MAX_HSCPS][MAX_ECALCRYS];
00243                 float          Calo_ecal_energies         [MAX_HSCPS][MAX_ECALCRYS];
00244                 float          Calo_ecal_outOfTimeEnergies[MAX_HSCPS][MAX_ECALCRYS];
00245                 float          Calo_ecal_chi2s            [MAX_HSCPS][MAX_ECALCRYS];
00246                 float          Calo_ecal_outOfTimeChi2s   [MAX_HSCPS][MAX_ECALCRYS];
00247                 float          Calo_ecal_times            [MAX_HSCPS][MAX_ECALCRYS];
00248                 float          Calo_ecal_timeErrors       [MAX_HSCPS][MAX_ECALCRYS];
00249                 unsigned int   Calo_ecal_detIds           [MAX_HSCPS][MAX_ECALCRYS];
00250 
00251                 unsigned int   NGens;
00252                 int            Gen_pdgId          [MAX_GENS];
00253                 float          Gen_charge         [MAX_GENS];
00254                 float          Gen_p              [MAX_GENS];
00255                 float          Gen_px             [MAX_GENS];
00256                 float          Gen_py             [MAX_GENS];
00257                 float          Gen_pz             [MAX_GENS];
00258                 float          Gen_pt             [MAX_GENS];
00259                 float          Gen_eta            [MAX_GENS];
00260                 float          Gen_phi            [MAX_GENS];
00261                 float          Gen_beta           [MAX_GENS];
00262                 float          Gen_mass           [MAX_GENS];
00263 };
00264 
00265 HSCPTreeBuilder::HSCPTreeBuilder(const edm::ParameterSet& iConfig)
00266 {
00267    m_HSCPsTag          = iConfig.getParameter<InputTag>              ("HSCParticles");
00268 
00269    reccordVertexInfo   = iConfig.getUntrackedParameter<bool>    ("reccordVertexInfo"  ,  true );
00270    reccordGenInfo      = iConfig.getUntrackedParameter<bool>    ("reccordGenInfo"     ,  false );
00271 
00272    std::cout << "######################################################" << endl;
00273    std::cout << "      USE OF THE HSCPTreeBuilder is deprecated!       " << endl;
00274    std::cout << "better to use the HSCParticle Producer and then FWLite" << endl;
00275    std::cout << "######################################################" << endl;
00276 
00277 }
00278 
00279 
00280 HSCPTreeBuilder::~HSCPTreeBuilder()
00281 {
00282 }
00283 
00284 void
00285 HSCPTreeBuilder::beginJob()
00286 {
00287    TTree::SetMaxTreeSize(1000*Long64_t(2000000000)); // authorize Trees up to 2 Terabytes
00288    MyTree = tfs->make<TTree> ("HscpTree","HscpTree");
00289 
00290    MyTree->Branch("Event_EventNumber"       ,&Event_EventNumber     ,"Event_EventNumber/i");
00291    MyTree->Branch("Event_RunNumber"         ,&Event_RunNumber       ,"Event_RunNumber/i");
00292    MyTree->Branch("Event_LumiSection"       ,&Event_LumiSection     ,"Event_LumiSection/i");
00293    MyTree->Branch("Event_BXCrossing"        ,&Event_BXCrossing      ,"Event_BXCrossing/i");
00294    MyTree->Branch("Event_Orbit"             ,&Event_Orbit           ,"Event_Orbit/i");
00295    MyTree->Branch("Event_Store"             ,&Event_Store           ,"Event_Store/i");
00296    MyTree->Branch("Event_Time"              ,&Event_Time            ,"Event_Time/i");
00297    MyTree->Branch("Event_PhysicsDeclared"   ,&Event_PhysicsDeclared ,"Event_PhysicsDeclared/O");
00298    MyTree->Branch("Event_technicalBits"     ,Event_technicalBits    ,"Event_technicalBits[64]/O");
00299    MyTree->Branch("Event_triggerL1Bits"     ,Event_triggerL1Bits    ,"Event_triggerL1Bits[192]/O");
00300    MyTree->Branch("Event_triggerHLTBits"    ,Event_triggerHLTBits   ,"Event_triggerHLTBits[128]/O");
00301    MyTree->Branch("Event_BField"            ,&Event_BField          ,"Event_BField/F");
00302 
00303    if(reccordVertexInfo){
00304    MyTree->Branch("NVertices"       ,&NVertices      ,"NVertices/I");
00305    MyTree->Branch("Vertex_x"        ,Vertex_x        ,"Vertex_x[NVertices]/F");
00306    MyTree->Branch("Vertex_y"        ,Vertex_y        ,"Vertex_y[NVertices]/F");
00307    MyTree->Branch("Vertex_z"        ,Vertex_z        ,"Vertex_z[NVertices]/F");
00308    MyTree->Branch("Vertex_x_err"    ,Vertex_x_err    ,"Vertex_x_err[NVertices]/F");
00309    MyTree->Branch("Vertex_y_err"    ,Vertex_y_err    ,"Vertex_y_err[NVertices]/F");
00310    MyTree->Branch("Vertex_z_err"    ,Vertex_z_err    ,"Vertex_z_err[NVertices]/F");
00311    MyTree->Branch("Vertex_TrackSize",Vertex_TrackSize,"Vertex_TrackSize[NVertices]/I");
00312    MyTree->Branch("Vertex_chi2"     ,Vertex_chi2     ,"Vertex_chi2[NVertices]/F");
00313    MyTree->Branch("Vertex_ndof"     ,Vertex_ndof     ,"Vertex_ndof[NVertices]/F");
00314    MyTree->Branch("Vertex_isFake"   ,Vertex_isFake   ,"Vertex_isFake[NVertices]/O");
00315    }
00316 
00317    MyTree->Branch("NHSCPs"             ,&NHSCPs            ,"NHSCPs/I");
00318    MyTree->Branch("Hscp_hasTrack"      ,Hscp_hasTrack      ,"Hscp_hasTrack[NHSCPs]/O");
00319    MyTree->Branch("Hscp_hasMuon"       ,Hscp_hasMuon       ,"Hscp_hasMuon[NHSCPs]/O");
00320    MyTree->Branch("Hscp_hasRpc"        ,Hscp_hasRpc        ,"Hscp_hasRpc[NHSCPs]/O");
00321    MyTree->Branch("Hscp_hasCalo"       ,Hscp_hasCalo       ,"Hscp_hasCalo[NHSCPs]/O");
00322    MyTree->Branch("Hscp_type"          ,Hscp_type          ,"Hscp_type[NHSCPs]/I");
00323    MyTree->Branch("Track_NOH"          ,Track_NOH          ,"Track_NOH[NHSCPs]/I");
00324    MyTree->Branch("Track_p"            ,Track_p            ,"Track_p[NHSCPs]/F");
00325    MyTree->Branch("Track_pt"           ,Track_pt           ,"Track_pt[NHSCPs]/F");
00326    MyTree->Branch("Track_pt_err"       ,Track_pt_err       ,"Track_pt_err[NHSCPs]/F");
00327    MyTree->Branch("Track_chi2"         ,Track_chi2         ,"Track_chi2[NHSCPs]/F");
00328    MyTree->Branch("Track_ndof"         ,Track_ndof         ,"Track_ndof[NHSCPs]/F");
00329    MyTree->Branch("Track_eta"          ,Track_eta          ,"Track_eta[NHSCPs]/F");
00330    MyTree->Branch("Track_eta_err"      ,Track_eta_err      ,"Track_eta_err[NHSCPs]/F");
00331    MyTree->Branch("Track_phi"          ,Track_phi          ,"Track_phi[NHSCPs]/F");
00332    MyTree->Branch("Track_phi_err"      ,Track_phi_err      ,"Track_phi_err[NHSCPs]/F");
00333    MyTree->Branch("Track_d0"           ,Track_d0           ,"Track_d0[NHSCPs]/F");
00334    MyTree->Branch("Track_dz"           ,Track_dz           ,"Track_dz[NHSCPs]/F");
00335    MyTree->Branch("Track_quality"      ,Track_quality      ,"Track_quality[NHSCPs]/I");
00336    MyTree->Branch("Track_charge"       ,Track_charge       ,"Track_charge[NHSCPs]/I");
00337    MyTree->Branch("Track_dEdxE1"       ,Track_dEdxE1       ,"Track_dEdxE1[NHSCPs]/F");
00338    MyTree->Branch("Track_dEdxE1_NOS"   ,Track_dEdxE1_NOS   ,"Track_dEdxE1_NOS[NHSCPs]/F");
00339    MyTree->Branch("Track_dEdxE1_NOM"   ,Track_dEdxE1_NOM   ,"Track_dEdxE1_NOM[NHSCPs]/I");
00340    MyTree->Branch("Track_dEdxE2"       ,Track_dEdxE2       ,"Track_dEdxE2[NHSCPs]/F");
00341    MyTree->Branch("Track_dEdxE2_NOS"   ,Track_dEdxE2_NOS   ,"Track_dEdxE2_NOS[NHSCPs]/F");
00342    MyTree->Branch("Track_dEdxE2_NOM"   ,Track_dEdxE2_NOM   ,"Track_dEdxE2_NOM[NHSCPs]/I");
00343    MyTree->Branch("Track_dEdxE3"       ,Track_dEdxE3       ,"Track_dEdxE3[NHSCPs]/F");
00344    MyTree->Branch("Track_dEdxE3_NOS"   ,Track_dEdxE3_NOS   ,"Track_dEdxE3_NOS[NHSCPs]/F");
00345    MyTree->Branch("Track_dEdxE3_NOM"   ,Track_dEdxE3_NOM   ,"Track_dEdxE3_NOM[NHSCPs]/I");
00346    MyTree->Branch("Track_dEdxD1"       ,Track_dEdxD1       ,"Track_dEdxD1[NHSCPs]/F");
00347    MyTree->Branch("Track_dEdxD1_NOS"   ,Track_dEdxD1_NOS   ,"Track_dEdxD1_NOS[NHSCPs]/F");
00348    MyTree->Branch("Track_dEdxD1_NOM"   ,Track_dEdxD1_NOM   ,"Track_dEdxD1_NOM[NHSCPs]/I");
00349    MyTree->Branch("Track_dEdxD2"       ,Track_dEdxD2       ,"Track_dEdxD2[NHSCPs]/F");
00350    MyTree->Branch("Track_dEdxD2_NOS"   ,Track_dEdxD2_NOS   ,"Track_dEdxD2_NOS[NHSCPs]/F");
00351    MyTree->Branch("Track_dEdxD2_NOM"   ,Track_dEdxD2_NOM   ,"Track_dEdxD2_NOM[NHSCPs]/I");
00352    MyTree->Branch("Track_dEdxD3"       ,Track_dEdxD3       ,"Track_dEdxD3[NHSCPs]/F");
00353    MyTree->Branch("Track_dEdxD3_NOS"   ,Track_dEdxD3_NOS   ,"Track_dEdxD3_NOS[NHSCPs]/F");
00354    MyTree->Branch("Track_dEdxD3_NOM"   ,Track_dEdxD3_NOM   ,"Track_dEdxD3_NOM[NHSCPs]/I");
00355    MyTree->Branch("Muon_p"             ,Muon_p             ,"Muon_p[NHSCPs]/F");
00356    MyTree->Branch("Muon_pt"            ,Muon_pt            ,"Muon_pt[NHSCPs]/F");
00357    MyTree->Branch("Muon_eta"           ,Muon_eta           ,"Muon_eta[NHSCPs]/F");
00358    MyTree->Branch("Muon_phi"           ,Muon_phi           ,"Muon_phi[NHSCPs]/F");
00359    MyTree->Branch("Muon_type"          ,Muon_type          ,"Muon_type[NHSCPs]/i");
00360    MyTree->Branch("Muon_qualityValid"  ,Muon_qualityValid  ,"Muon_qualityValid[NHSCPs]/O");
00361    MyTree->Branch("Muon_charge"        ,Muon_charge        ,"Muon_charge[NHSCPs]/i");
00362    MyTree->Branch("Muon_dt_IBeta"      ,Muon_dt_IBeta      ,"Muon_dt_IBeta[NHSCPs]/F");
00363    MyTree->Branch("Muon_dt_IBeta_err"  ,Muon_dt_IBeta_err  ,"Muon_dt_IBeta_err[NHSCPs]/F");
00364    MyTree->Branch("Muon_dt_fIBeta"     ,Muon_dt_fIBeta     ,"Muon_dt_fIBeta[NHSCPs]/F");
00365    MyTree->Branch("Muon_dt_fIBeta_err" ,Muon_dt_fIBeta_err ,"Muon_dt_fIBeta_err[NHSCPs]/F");
00366    MyTree->Branch("Muon_dt_ndof"       ,Muon_dt_ndof       ,"Muon_dt_ndof[NHSCPs]/I");
00367    MyTree->Branch("Muon_csc_IBeta"     ,Muon_csc_IBeta     ,"Muon_csc_IBeta[NHSCPs]/F");
00368    MyTree->Branch("Muon_csc_IBeta_err" ,Muon_csc_IBeta_err ,"Muon_csc_IBeta_err[NHSCPs]/F");
00369    MyTree->Branch("Muon_csc_fIBeta"    ,Muon_csc_fIBeta    ,"Muon_csc_fIBeta[NHSCPs]/F");
00370    MyTree->Branch("Muon_csc_fIBeta_err",Muon_csc_fIBeta_err,"Muon_csc_fIBeta_err[NHSCPs]/F");
00371    MyTree->Branch("Muon_csc_ndof"      ,Muon_csc_ndof      ,"Muon_csc_ndof[NHSCPs]/I");
00372    MyTree->Branch("Muon_cb_IBeta"      ,Muon_cb_IBeta      ,"Muon_cb_IBeta[NHSCPs]/F");
00373    MyTree->Branch("Muon_cb_IBeta_err"  ,Muon_cb_IBeta_err  ,"Muon_cb_IBeta_err[NHSCPs]/F");
00374    MyTree->Branch("Muon_cb_fIBeta"     ,Muon_cb_fIBeta     ,"Muon_cb_fIBeta[NHSCPs]/F");
00375    MyTree->Branch("Muon_cb_fIBeta_err" ,Muon_cb_fIBeta_err ,"Muon_cb_fIBeta_err[NHSCPs]/F");
00376    MyTree->Branch("Muon_cb_ndof"       ,Muon_cb_ndof       ,"Muon_cb_ndof[NHSCPs]/I");
00377 
00378    MyTree->Branch("Rpc_beta"           ,Rpc_beta           ,"Rpc_beta[NHSCPs]/F");
00379 
00380    MyTree->Branch("Calo_ecal_crossedE"         ,Calo_ecal_crossedE      ,"Calo_ecal_crossedE[NHSCPs]/F");
00381    MyTree->Branch("Calo_ecal_beta"             ,Calo_ecal_beta          ,"Calo_ecal_beta[NHSCPs]/F");
00382    MyTree->Branch("Calo_ecal_beta_err"         ,Calo_ecal_beta_err      ,"Calo_ecal_beta_err[NHSCPs]/F");
00383    MyTree->Branch("Calo_ecal_invBeta_err"      ,Calo_ecal_invBeta_err   ,"Calo_ecal_invBeta_err[NHSCPs]/F");
00384    MyTree->Branch("Calo_ecal_dEdx"             ,Calo_ecal_dEdx          ,"Calo_ecal_dEdx[NHSCPs]/F");
00385    MyTree->Branch("Calo_ecal_time"             ,Calo_ecal_time          ,"Calo_ecal_time[NHSCPs]/F");
00386    MyTree->Branch("Calo_ecal_time_err"         ,Calo_ecal_time_err      ,"Calo_ecal_time_err[NHSCPs]/F");
00387    MyTree->Branch("Calo_ecal_numCrysCrossed"   ,Calo_ecal_numCrysCrossed,"Calo_ecal_numCrysCrossed[NHSCPs]/I");
00388    MyTree->Branch("Calo_ecal_swissCrossKs"     ,Calo_ecal_swissCrossKs  ,"Calo_ecal_swissCrossKs[NHSCPs][10]/F");
00389    MyTree->Branch("Calo_ecal_e1OverE9s"        ,Calo_ecal_e1OverE9s     ,"Calo_ecal_e1OverE9s[NHSCPs][10]/F");
00390    MyTree->Branch("Calo_ecal_trackLengths"     ,Calo_ecal_trackLengths  ,"Calo_ecal_trackLengths[NHSCPs][10]/F");
00391    MyTree->Branch("Calo_ecal_trackExitEtas"    ,Calo_ecal_trackExitEtas ,"Calo_ecal_trackExitEtas[NHSCPs][10]/F");
00392    MyTree->Branch("Calo_ecal_trackExitPhis"    ,Calo_ecal_trackExitPhis ,"Calo_ecal_trackExitPhis[NHSCPs][10]/F");
00393    MyTree->Branch("Calo_ecal_energies"         ,Calo_ecal_energies      ,"Calo_ecal_energies[NHSCPs][10]/F");
00394    MyTree->Branch("Calo_ecal_outOfTimeEnergies",Calo_ecal_outOfTimeEnergies      ,"Calo_ecal_outOfTimeEnergies[NHSCPs][10]/F");
00395    MyTree->Branch("Calo_ecal_chi2s"            ,Calo_ecal_chi2s      ,"Calo_ecal_chi2s[NHSCPs][10]/F");
00396    MyTree->Branch("Calo_ecal_outOfTimeChi2s"   ,Calo_ecal_outOfTimeChi2s      ,"Calo_ecal_outOfTimeChi2s[NHSCPs][10]/F");
00397    MyTree->Branch("Calo_ecal_times"            ,Calo_ecal_times         ,"Calo_ecal_times[NHSCPs][10]/F");
00398    MyTree->Branch("Calo_ecal_timeErrors"       ,Calo_ecal_timeErrors    ,"Calo_ecal_timeErrors[NHSCPs][10]/F");
00399    MyTree->Branch("Calo_ecal_detIds"           ,Calo_ecal_detIds        ,"Calo_ecal_detIds[NHSCPs][10]/I");
00400 
00401    if(reccordGenInfo){
00402    MyTree->Branch("NGens"              ,&NGens             ,"NGens/I");
00403    MyTree->Branch("Gen_pdgId"          ,Gen_pdgId          ,"Gen_pdgId[NGens]/i");
00404    MyTree->Branch("Gen_charge"         ,Gen_charge         ,"Gen_charge[NGens]/F");
00405    MyTree->Branch("Gen_p"              ,Gen_p              ,"Gen_p[NGens]/F");
00406    MyTree->Branch("Gen_px"             ,Gen_px             ,"Gen_px[NGens]/F");
00407    MyTree->Branch("Gen_py"             ,Gen_py             ,"Gen_py[NGens]/F");
00408    MyTree->Branch("Gen_pz"             ,Gen_pz             ,"Gen_pz[NGens]/F");
00409    MyTree->Branch("Gen_pt"             ,Gen_pt             ,"Gen_pt[NGens]/F");
00410    MyTree->Branch("Gen_eta"            ,Gen_eta            ,"Gen_eta[NGens]/F");
00411    MyTree->Branch("Gen_phi"            ,Gen_phi            ,"Gen_phi[NGens]/F");
00412    MyTree->Branch("Gen_beta"           ,Gen_beta           ,"Gen_beta[NGens]/F");
00413    MyTree->Branch("Gen_mass"           ,Gen_mass           ,"Gen_mass[NGens]/F");
00414    }
00415 
00416 }
00417 
00418 void
00419 HSCPTreeBuilder::endJob() 
00420 {
00421 }
00422 
00423 
00424 
00425 bool
00426 HSCPTreeBuilder::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00427 {
00428    bool debug = false;
00429    if (debug) cout << "I'm in HSCPTreeBuilder::analyze!" << endl;
00430 
00431 
00432    Event_EventNumber     = iEvent.id().event();
00433    Event_RunNumber       = iEvent.id().run();
00434    Event_LumiSection     = iEvent.eventAuxiliary().luminosityBlock();
00435    Event_BXCrossing      = iEvent.eventAuxiliary().bunchCrossing();
00436    Event_Orbit           = iEvent.eventAuxiliary().orbitNumber();
00437    Event_Store           = iEvent.eventAuxiliary().storeNumber();
00438    Event_Time            = iEvent.eventAuxiliary().time().value();
00439 
00440    // BField part:
00441    ESHandle<MagneticField> MF;
00442    iSetup.get<IdealMagneticFieldRecord>().get(MF);
00443    const MagneticField* theMagneticField = MF.product();
00444    Event_BField = fabs(theMagneticField->inTesla(GlobalPoint(0,0,0)).z());
00445 
00446    // L1 TRIGGER part:
00447    edm::Handle<L1GlobalTriggerReadoutRecord> h_gtReadoutRecord;
00448    iEvent.getByLabel("gtDigis", h_gtReadoutRecord);
00449    L1GtFdlWord fdlWord = h_gtReadoutRecord->gtFdlWord();
00450    TechnicalTriggerWord L1technical = fdlWord.gtTechnicalTriggerWord();
00451    Event_PhysicsDeclared = h_gtReadoutRecord->gtFdlWord().physicsDeclared();
00452    for (unsigned int i = 0; i <  64; ++i){ Event_technicalBits [i] = L1technical[i]; }
00453    DecisionWord L1decision = fdlWord.gtDecisionWord();
00454    for (unsigned int i = 0; i < 128; ++i){ Event_triggerL1Bits [i] = L1decision[i]; }
00455    DecisionWordExtended L1decisionE = fdlWord.gtDecisionWordExtended();
00456    for (unsigned int i = 0; i < 64; ++i){ Event_triggerL1Bits [128+i] = L1decisionE[i]; }
00457 
00458    // HLT TRIGGER part:
00459    edm::Handle<edm::TriggerResults> trh;
00460    iEvent.getByLabel("TriggerResults", trh);
00461    for(unsigned int i=0;i<trh->size() && i<128;++i){Event_triggerHLTBits[i] = trh->at(i).accept();}
00462 
00463    edm::Handle<reco::VertexCollection> recoVertexHandle;
00464    iEvent.getByLabel("offlinePrimaryVertices", recoVertexHandle);
00465    reco::VertexCollection recoVertex = *recoVertexHandle;
00466 
00467    if(reccordVertexInfo){
00468    NVertices = 0;
00469    for(unsigned int i=0;i<recoVertex.size();i++){
00470       Vertex_x        [NVertices] = recoVertex[i].x();
00471       Vertex_y        [NVertices] = recoVertex[i].y();
00472       Vertex_z        [NVertices] = recoVertex[i].z();
00473       Vertex_x_err    [NVertices] = recoVertex[i].xError();
00474       Vertex_y_err    [NVertices] = recoVertex[i].yError();
00475       Vertex_z_err    [NVertices] = recoVertex[i].zError();
00476       Vertex_TrackSize[NVertices] = recoVertex[i].tracksSize();
00477       Vertex_chi2     [NVertices] = recoVertex[i].chi2();
00478       Vertex_ndof     [NVertices] = recoVertex[i].ndof();
00479       Vertex_isFake   [NVertices] = recoVertex[i].isFake();
00480       NVertices++; 
00481    }
00482    }
00483 
00484    // Source Collection
00485    edm::Handle<susybsm::HSCParticleCollection > HSCPCollectionHandle;
00486    iEvent.getByLabel(m_HSCPsTag, HSCPCollectionHandle);
00487    susybsm::HSCParticleCollection HSCPCollection = *HSCPCollectionHandle.product();
00488 
00489    NHSCPs=0;
00490    for(unsigned int i=0; i<HSCPCollection.size();i++){
00491       susybsm::HSCParticle hscp = HSCPCollection[i]; 
00492       reco::MuonRef  muon  = hscp.muonRef();
00493       reco::TrackRef track = hscp.trackRef();;
00494 
00495        Hscp_hasTrack        [NHSCPs] = hscp.hasTrackRef();
00496        Hscp_hasMuon         [NHSCPs] = hscp.hasMuonRef();
00497        Hscp_hasRpc          [NHSCPs] = hscp.hasRpcInfo();
00498        Hscp_hasCalo         [NHSCPs] = hscp.hasCaloInfo();
00499        Hscp_type            [NHSCPs] = hscp.type();
00500 
00501       if(track.isNonnull() && Hscp_hasTrack){
00502          Track_p            [NHSCPs] = track->p();
00503          Track_pt           [NHSCPs] = track->pt();
00504          Track_pt_err       [NHSCPs] = track->ptError();
00505          Track_eta          [NHSCPs] = track->eta();
00506          Track_eta_err      [NHSCPs] = track->etaError();
00507          Track_phi          [NHSCPs] = track->phi();
00508          Track_phi_err      [NHSCPs] = track->phiError();
00509          Track_NOH          [NHSCPs] = track->found();
00510          Track_chi2         [NHSCPs] = track->chi2();
00511          Track_ndof         [NHSCPs] = track->ndof();
00512          Track_d0           [NHSCPs] = -1.0f * track->dxy(recoVertex[0].position());
00513          Track_dz           [NHSCPs] = -1.0f * track->dz (recoVertex[0].position());
00514          Track_quality      [NHSCPs] = track->qualityMask();
00515          Track_charge       [NHSCPs] = track->charge(); 
00516 /*         Track_dEdxE1       [NHSCPs] = hscp.dedxEstimator1().dEdx();
00517          Track_dEdxE1_NOM   [NHSCPs] = hscp.dedxEstimator1().numberOfMeasurements();
00518          Track_dEdxE1_NOS   [NHSCPs] = hscp.dedxEstimator1().numberOfSaturatedMeasurements();
00519          Track_dEdxE2       [NHSCPs] = hscp.dedxEstimator2().dEdx();
00520          Track_dEdxE2_NOM   [NHSCPs] = hscp.dedxEstimator2().numberOfMeasurements();
00521          Track_dEdxE2_NOS   [NHSCPs] = hscp.dedxEstimator2().numberOfSaturatedMeasurements();
00522          Track_dEdxE3       [NHSCPs] = hscp.dedxEstimator3().dEdx();
00523          Track_dEdxE3_NOM   [NHSCPs] = hscp.dedxEstimator3().numberOfMeasurements();
00524          Track_dEdxE3_NOS   [NHSCPs] = hscp.dedxEstimator3().numberOfSaturatedMeasurements();
00525          Track_dEdxD1       [NHSCPs] = hscp.dedxDiscriminator1().dEdx();
00526          Track_dEdxD1_NOM   [NHSCPs] = hscp.dedxDiscriminator1().numberOfMeasurements();
00527          Track_dEdxD1_NOS   [NHSCPs] = hscp.dedxDiscriminator1().numberOfSaturatedMeasurements();
00528          Track_dEdxD2       [NHSCPs] = hscp.dedxDiscriminator2().dEdx();
00529          Track_dEdxD2_NOM   [NHSCPs] = hscp.dedxDiscriminator2().numberOfMeasurements();
00530          Track_dEdxD2_NOS   [NHSCPs] = hscp.dedxDiscriminator2().numberOfSaturatedMeasurements();
00531          Track_dEdxD3       [NHSCPs] = hscp.dedxDiscriminator3().dEdx();
00532          Track_dEdxD3_NOM   [NHSCPs] = hscp.dedxDiscriminator3().numberOfMeasurements();
00533          Track_dEdxD3_NOS   [NHSCPs] = hscp.dedxDiscriminator3().numberOfSaturatedMeasurements();
00534 */
00535       }
00536 
00537       if(muon.isNonnull() && Hscp_hasMuon){
00538          Muon_p             [NHSCPs] = muon->p();
00539          Muon_pt            [NHSCPs] = muon->pt();
00540          Muon_eta           [NHSCPs] = muon->eta();
00541          Muon_phi           [NHSCPs] = muon->phi();
00542          Muon_type          [NHSCPs] = muon->type();
00543          Muon_qualityValid  [NHSCPs] = muon->isQualityValid();
00544          Muon_charge        [NHSCPs] = muon->charge();
00545 /*         Muon_dt_IBeta      [NHSCPs] = hscp.muonTimeDt().inverseBeta();
00546          Muon_dt_IBeta_err  [NHSCPs] = hscp.muonTimeDt().inverseBetaErr();
00547          Muon_dt_fIBeta     [NHSCPs] = hscp.muonTimeDt().freeInverseBeta();
00548          Muon_dt_fIBeta_err [NHSCPs] = hscp.muonTimeDt().freeInverseBetaErr();
00549          Muon_dt_ndof       [NHSCPs] = hscp.muonTimeDt().nDof();
00550          Muon_csc_IBeta     [NHSCPs] = hscp.muonTimeCsc().inverseBeta();
00551          Muon_csc_IBeta_err [NHSCPs] = hscp.muonTimeCsc().inverseBetaErr();
00552          Muon_csc_fIBeta    [NHSCPs] = hscp.muonTimeCsc().freeInverseBeta();
00553          Muon_csc_fIBeta_err[NHSCPs] = hscp.muonTimeCsc().freeInverseBetaErr();
00554          Muon_csc_ndof      [NHSCPs] = hscp.muonTimeCsc().nDof();
00555          Muon_cb_IBeta      [NHSCPs] = hscp.muonTimeCombined().inverseBeta();
00556          Muon_cb_IBeta_err  [NHSCPs] = hscp.muonTimeCombined().inverseBetaErr();
00557          Muon_cb_fIBeta     [NHSCPs] = hscp.muonTimeCombined().freeInverseBeta();
00558          Muon_cb_fIBeta_err [NHSCPs] = hscp.muonTimeCombined().freeInverseBetaErr();
00559          Muon_cb_ndof       [NHSCPs] = hscp.muonTimeCombined().nDof();
00560 */
00561       }
00562 
00563       if(hscp.hasCaloInfo()){
00564 //         Calo_ecal_crossedE      [NHSCPs] = hscp.calo().ecalCrossedEnergy;
00565 //         Calo_ecal_beta          [NHSCPs] = hscp.calo().ecalBeta;
00566 //         Calo_ecal_beta_err      [NHSCPs] = hscp.calo().ecalBetaError;
00567 //         Calo_ecal_invBeta_err   [NHSCPs] = hscp.calo().ecalInvBetaError;
00568 //         Calo_ecal_dEdx          [NHSCPs] = hscp.calo().ecalDeDx;
00569 //         Calo_ecal_time          [NHSCPs] = hscp.calo().ecalTime;
00570 //         Calo_ecal_time_err      [NHSCPs] = hscp.calo().ecalTimeError;
00571 //         Calo_ecal_numCrysCrossed[NHSCPs] = hscp.calo().ecalCrysCrossed;
00572 /*         for(int i=0; i < Calo_ecal_numCrysCrossed[NHSCPs] && i < MAX_ECALCRYS; ++i)
00573          {
00574            Calo_ecal_swissCrossKs     [NHSCPs][i] = hscp.calo().ecalSwissCrossKs[i];
00575            Calo_ecal_e1OverE9s        [NHSCPs][i] = hscp.calo().ecalE1OverE9s[i];
00576            Calo_ecal_trackLengths     [NHSCPs][i] = hscp.calo().ecalTrackLengths[i];
00577            GlobalPoint exitPosition = hscp.calo().ecalTrackExitPositions[i];
00578            Calo_ecal_trackExitEtas    [NHSCPs][i] = exitPosition.eta();
00579            Calo_ecal_trackExitPhis    [NHSCPs][i] = exitPosition.phi();
00580            Calo_ecal_energies         [NHSCPs][i] = hscp.calo().ecalEnergies[i];
00581            Calo_ecal_outOfTimeEnergies[NHSCPs][i] = hscp.calo().ecalOutOfTimeEnergies[i];
00582            Calo_ecal_chi2s            [NHSCPs][i] = hscp.calo().ecalChi2s[i];
00583            Calo_ecal_outOfTimeChi2s   [NHSCPs][i] = hscp.calo().ecalOutOfTimeChi2s[i];
00584            Calo_ecal_times            [NHSCPs][i] = hscp.calo().ecalTimes[i];
00585            Calo_ecal_timeErrors       [NHSCPs][i] = hscp.calo().ecalTimeErrors[i];
00586            Calo_ecal_detIds           [NHSCPs][i] = hscp.calo().ecalDetIds[i];
00587          }
00588 */
00589       }
00590 
00591       if(Hscp_hasRpc){
00592          Rpc_beta           [NHSCPs] = hscp.rpc().beta;
00593       }
00594 
00595       NHSCPs++;
00596    }
00597    
00598 
00599    if(reccordGenInfo){
00600    Handle<GenParticleCollection> genParticles;
00601    iEvent.getByLabel("genParticles", genParticles);
00602    NGens=0;
00603    for(unsigned int i=0;i<genParticles->size();i++){
00604      const GenParticle & part = (*genParticles)[i];
00605      if(part.status()!=1)continue;
00606      if(part.pt()<5)continue;
00607 //     if(fabs(part.pdgId())<1000000) continue;
00608 
00609         Gen_pdgId [NGens]     = part.pdgId();
00610         Gen_charge[NGens]     = part.charge();
00611         Gen_p     [NGens]     = part.p();
00612         Gen_px    [NGens]     = part.px();
00613         Gen_py    [NGens]     = part.py();
00614         Gen_pz    [NGens]     = part.pz();
00615         Gen_pt    [NGens]     = part.pt();
00616         Gen_eta   [NGens]     = part.eta();
00617         Gen_phi   [NGens]     = part.phi();
00618         Gen_beta  [NGens]     = part.p()/part.energy();
00619         Gen_mass  [NGens]     = part.mass();
00620         NGens++;
00621      }     
00622   }
00623    
00624 
00625    MyTree->Fill();
00626    return true;
00627 }
00628 
00629 //define this as a plug-in
00630 DEFINE_FWK_MODULE(HSCPTreeBuilder);
00631 
00632 
00633 
00634 
00635 
00636 
00637 
00638 
00639 
00640