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