CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronStudy.cc
Go to the documentation of this file.
12 
13 #include <algorithm>
14 
16 
17  sourceLabel = ps.getUntrackedParameter<std::string>("SourceLabel","generator");
18  g4Label = ps.getUntrackedParameter<std::string>("ModuleLabel","g4SimHits");
19  hitLabEB= ps.getUntrackedParameter<std::string>("EBCollection","EcalHitsEB");
20  hitLabEE= ps.getUntrackedParameter<std::string>("EECollection","EcalHitsEE");
21 
22 
23  tok_EBhit_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label,hitLabEB));
24  tok_EEhit_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label,hitLabEE));
25  tok_simTk_ = consumes<edm::SimTrackContainer>(edm::InputTag(g4Label));
26  tok_simVtx_ = consumes<edm::SimVertexContainer>(edm::InputTag(g4Label));
27 
28  hotZone = ps.getUntrackedParameter<int>("HotZone",0);
29  verbose = ps.getUntrackedParameter<int>("Verbosity",0);
30  edm::LogInfo("ElectronStudy") << "Module Label: " << g4Label << " Hits: "
31  << hitLabEB << ", " << hitLabEE;
32 
33  double tempPBins[NPBins+1] = { 0.0, 10.0, 20.0, 40.0, 60.0,
34  100.0, 500.0, 1000.0, 10000.0};
35  double tempEta[NEtaBins+1] = {0.0, 1.2, 1.6, 3.0};
36 
37  for (int i=0; i<NPBins+1; i++) pBins[i] = tempPBins[i];
38  for(int i=0; i<NEtaBins+1; i++) etaBins[i] = tempEta[i];
39 
41  if ( !tfile.isAvailable() ) {
42  edm::LogInfo("ElectronStudy") << "TFileService unavailable: no histograms";
43  histos = false;
44  } else {
45  char name[20], title[200], cpbin[30], cebin[30];
46  histos = true;
47  for (unsigned int i=0; i<NPBins+1; ++i) {
48  if (i == 0) sprintf (cpbin, " All p");
49  else sprintf (cpbin, " p (%6.0f:%6.0f)", pBins[i-1], pBins[i]);
50  for (unsigned int j=0; j<NEtaBins+1; ++j) {
51  if (j == 0) sprintf (cebin, " All #eta");
52  else sprintf (cebin, " #eta (%4.1f:%4.1f)", etaBins[j-1], etaBins[j]);
53  sprintf (name, "R1%d%d", i, j);
54  sprintf (title,"E1/E9 for %s%s", cpbin, cebin);
55  histoR1[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
56  histoR1[i][j]->GetXaxis()->SetTitle(title);
57  histoR1[i][j]->GetYaxis()->SetTitle("Tracks");
58  sprintf (name, "R2%d%d", i, j);
59  sprintf (title,"E1/E25 for %s%s", cpbin, cebin);
60  histoR2[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
61  histoR2[i][j]->GetXaxis()->SetTitle(title);
62  histoR2[i][j]->GetYaxis()->SetTitle("Tracks");
63  sprintf (name, "R3%d%d", i, j);
64  sprintf (title,"E9/E25 for %s%s", cpbin, cebin);
65  histoR3[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
66  histoR3[i][j]->GetXaxis()->SetTitle(title);
67  histoR3[i][j]->GetYaxis()->SetTitle("Tracks");
68  sprintf (name, "E1x1%d%d", i, j);
69  sprintf (title,"E1/P for %s%s", cpbin, cebin);
70  histoE1x1[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
71  histoE1x1[i][j]->GetXaxis()->SetTitle(title);
72  histoE1x1[i][j]->GetYaxis()->SetTitle("Tracks");
73  sprintf (name, "E3x3%d%d", i, j);
74  sprintf (title,"E9/P for %s%s", cpbin, cebin);
75  histoE3x3[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
76  histoE3x3[i][j]->GetXaxis()->SetTitle(title);
77  histoE3x3[i][j]->GetYaxis()->SetTitle("Tracks");
78  sprintf (name, "E5x5%d%d", i, j);
79  sprintf (title,"E25/P for %s%s", cpbin, cebin);
80  histoE5x5[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
81  histoE5x5[i][j]->GetXaxis()->SetTitle(title);
82  histoE5x5[i][j]->GetYaxis()->SetTitle("Tracks");
83  }
84  }
85  }
86 }
87 
89 
90  if (verbose > 1) std::cout << "Run = " << iEvent.id().run() << " Event = "
91  << iEvent.id().event() << std::endl;
92 
93  // get Geometry, B-field, Topology
95  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
96  const MagneticField* bField = bFieldH.product();
97 
99  iSetup.get<CaloGeometryRecord>().get(pG);
100  const CaloGeometry* geo = pG.product();
101 
102  edm::ESHandle<CaloTopology> theCaloTopology;
103  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
104  const CaloTopology* caloTopology = theCaloTopology.product();
105 
106  // get PCaloHits for ecal barrel
108  iEvent.getByToken(tok_EBhit_,caloHitEB);
109 
110  // get PCaloHits for ecal endcap
112  iEvent.getByToken(tok_EEhit_,caloHitEE);
113 
114  // get sim tracks
116  iEvent.getByToken(tok_simTk_, SimTk);
117 
118  // get sim vertices
120  iEvent.getByToken(tok_simVtx_, SimVtx);
121 
122  if (verbose>0)
123  std::cout << "ElectronStudy: hits valid[EB]: " << caloHitEB.isValid()
124  << " valid[EE]: " << caloHitEE.isValid() << std::endl;
125 
126  if (caloHitEB.isValid() && caloHitEE.isValid()) {
127  unsigned int indx;
128  if (verbose>2) {
129  edm::PCaloHitContainer::const_iterator ihit;
130  for (ihit=caloHitEB->begin(),indx=0; ihit!=caloHitEB->end(); ihit++,indx++) {
131  EBDetId id = ihit->id();
132  std::cout << "Hit[" << indx << "] " << id << " E " << ihit->energy()
133  << " T " << ihit->time() << std::endl;
134  }
135  for (ihit=caloHitEE->begin(),indx=0; ihit!=caloHitEE->end(); ihit++,indx++) {
136  EEDetId id = ihit->id();
137  std::cout << "Hit[" << indx << "] " << id << " E " << ihit->energy()
138  << " T " << ihit->time() << std::endl;
139  }
140  }
141  edm::SimTrackContainer::const_iterator simTrkItr=SimTk->begin();
142  for (indx=0; simTrkItr!= SimTk->end(); simTrkItr++,indx++) {
143  if (verbose>0) std::cout << "ElectronStudy: Track[" << indx << "] ID "
144  << simTrkItr->trackId() << " type "
145  << simTrkItr->type() << " charge "
146  << simTrkItr->charge() << " p "
147  << simTrkItr->momentum()<< " Generator Index "
148  << simTrkItr->genpartIndex() << " vertex "
149  << simTrkItr->vertIndex() << std::endl;
150  if (std::abs(simTrkItr->type()) == 11 && simTrkItr->vertIndex() != -1) {
151  int thisTrk = simTrkItr->trackId();
152  spr::propagatedTrackDirection trkD = spr::propagateCALO(thisTrk, SimTk, SimVtx, geo, bField, (verbose>1));
153  if (trkD.okECAL) {
154  const DetId isoCell = trkD.detIdECAL;
155  DetId hotCell = isoCell;
156  if (hotZone > 0) hotCell = spr::hotCrystal(isoCell, caloHitEB, caloHitEE, geo, caloTopology, hotZone, hotZone, -500.0, 500.0, (verbose>1));
157  double e1x1 = spr::eECALmatrix(hotCell, caloHitEB, caloHitEE, geo, caloTopology, 0, 0, -100.0, -100.0,-500.0, 500.0, (verbose>2));
158  double e3x3 = spr::eECALmatrix(hotCell, caloHitEB, caloHitEE, geo, caloTopology, 1, 1, -100.0, -100.0,-500.0, 500.0, (verbose>2));
159  double e5x5 = spr::eECALmatrix(hotCell, caloHitEB, caloHitEE, geo, caloTopology, 2, 2, -100.0, -100.0,-500.0, 500.0, (verbose>2));
160  double p = simTrkItr->momentum().P();
161  double eta = std::abs(simTrkItr->momentum().eta());
162  int etaBin=-1, momBin=-1;
163  for (int ieta=0; ieta<NEtaBins; ieta++) {
164  if (eta>etaBins[ieta] && eta<etaBins[ieta+1] ) etaBin = ieta+1;
165  }
166  for (int ipt=0; ipt<NPBins; ipt++) {
167  if (p>pBins[ipt] && p<pBins[ipt+1] ) momBin = ipt+1;
168  }
169  double r1=-1, r2=-1, r3=-1;
170  if (e3x3 > 0) r1 = e1x1/e3x3;
171  if (e5x5 > 0) {r2 = e1x1/e5x5; r3 = e3x3/e5x5;}
172  if (verbose>0) {
173  std::cout << "ElectronStudy: p " << p << " [" << momBin << "] eta "
174  << eta << " [" << etaBin << "]";
175  if (isoCell.subdetId() == EcalBarrel) {
176  EBDetId id = isoCell;
177  std::cout << " Cell 0x" << std::hex << isoCell() << std::dec
178  << " " << id;
179  } else if (isoCell.subdetId() == EcalEndcap) {
180  EEDetId id = isoCell;
181  std::cout << " Cell 0x" << std::hex << isoCell() << std::dec
182  << " " << id;
183  } else {
184  std::cout << " Cell 0x" << std::hex << isoCell() << std::dec
185  << " Unknown Type";
186  }
187  std::cout << " e1x1 " << e1x1 << "|" << r1 << "|" << r2 << " e3x3 "
188  << e3x3 << "|" << r3 << " e5x5 " << e5x5 << std::endl;
189  }
190  if (histos) {
191  histoR1[0][0]->Fill(r1);
192  histoR2[0][0]->Fill(r2);
193  histoR3[0][0]->Fill(r3);
194  histoE1x1[0][0]->Fill(e1x1/p);
195  histoE3x3[0][0]->Fill(e3x3/p);
196  histoE5x5[0][0]->Fill(e5x5/p);
197  if (momBin>0) {
198  histoR1[momBin][0]->Fill(r1);
199  histoR2[momBin][0]->Fill(r2);
200  histoR3[momBin][0]->Fill(r3);
201  histoE1x1[momBin][0]->Fill(e1x1/p);
202  histoE3x3[momBin][0]->Fill(e3x3/p);
203  histoE5x5[momBin][0]->Fill(e5x5/p);
204  }
205  if (etaBin>0) {
206  histoR1[0][etaBin]->Fill(r1);
207  histoR2[0][etaBin]->Fill(r2);
208  histoR3[0][etaBin]->Fill(r3);
209  histoE1x1[0][etaBin]->Fill(e1x1/p);
210  histoE3x3[0][etaBin]->Fill(e3x3/p);
211  histoE5x5[0][etaBin]->Fill(e5x5/p);
212  if (momBin>0) {
213  histoR1[momBin][etaBin]->Fill(r1);
214  histoR2[momBin][etaBin]->Fill(r2);
215  histoR3[momBin][etaBin]->Fill(r3);
216  histoE1x1[momBin][etaBin]->Fill(e1x1/p);
217  histoE3x3[momBin][etaBin]->Fill(e3x3/p);
218  histoE5x5[momBin][etaBin]->Fill(e5x5/p);
219  }
220  }
221  }
222  }
223  }
224  }
225  }
226 
227 }
228 
229 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
ElectronStudy(const edm::ParameterSet &ps)
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::string hitLabEE
Definition: ElectronStudy.h:53
TH1F * histoR2[NPBins+1][NEtaBins+1]
Definition: ElectronStudy.h:56
edm::EDGetTokenT< edm::SimTrackContainer > tok_simTk_
Definition: ElectronStudy.h:50
std::string g4Label
Definition: ElectronStudy.h:53
std::vector< spr::propagatedTrackID > propagateCALO(edm::Handle< reco::TrackCollection > &trkCollection, const CaloGeometry *geo, const MagneticField *bField, std::string &theTrackQuality, bool debug=false)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string hitLabEB
Definition: ElectronStudy.h:53
TH1F * histoE3x3[NPBins+1][NEtaBins+1]
Definition: ElectronStudy.h:58
TH1F * histoE1x1[NPBins+1][NEtaBins+1]
Definition: ElectronStudy.h:57
edm::EDGetTokenT< edm::SimVertexContainer > tok_simVtx_
Definition: ElectronStudy.h:51
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
T eta() const
void analyze(const edm::Event &e, const edm::EventSetup &c)
int iEvent
Definition: GenABIO.cc:230
static const int NPBins
Definition: ElectronStudy.h:45
bool isAvailable() const
Definition: Service.h:46
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
TH1F * histoR3[NPBins+1][NEtaBins+1]
Definition: ElectronStudy.h:57
bool isValid() const
Definition: HandleBase.h:76
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
double etaBins[NEtaBins+1]
Definition: ElectronStudy.h:46
TH1F * histoR1[NPBins+1][NEtaBins+1]
Definition: ElectronStudy.h:56
edm::EDGetTokenT< edm::PCaloHitContainer > tok_EBhit_
Definition: ElectronStudy.h:48
Definition: DetId.h:18
std::string sourceLabel
Definition: ElectronStudy.h:53
TH1F * histoE5x5[NPBins+1][NEtaBins+1]
Definition: ElectronStudy.h:58
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
DetId hotCrystal(const DetId &detId, edm::Handle< T > &hitsEB, edm::Handle< T > &hitsEE, const CaloGeometry *geo, const CaloTopology *caloTopology, int ieta, int iphi, double tMin=-500, double tMax=500, bool debug=false)
edm::EDGetTokenT< edm::PCaloHitContainer > tok_EEhit_
Definition: ElectronStudy.h:49
double pBins[NPBins+1]
Definition: ElectronStudy.h:46
edm::EventID id() const
Definition: EventBase.h:56
tuple cout
Definition: gather_cfg.py:121
static const int NEtaBins
Definition: ElectronStudy.h:44
double eECALmatrix(const DetId &detId, edm::Handle< T > &hitsEB, edm::Handle< T > &hitsEE, const CaloGeometry *geo, const CaloTopology *caloTopology, int ieta, int iphi, double ebThr=-100, double eeThr=-100, double tMin=-500, double tMax=500, bool debug=false)