CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBCosmicTask.cc
Go to the documentation of this file.
1 /*
2  * \file EBCosmicTask.cc
3  *
4  * \author G. Della Ricca
5  *
6 */
7 
8 #include <iostream>
9 #include <fstream>
10 
13 
15 
17 
19 
21 
23 
25 
26  init_ = false;
27 
29 
30  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
31 
32  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
33 
34  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
35 
36  EcalRawDataCollection_ = consumes<EcalRawDataCollection>(ps.getParameter<edm::InputTag>("EcalRawDataCollection"));
37  EcalUncalibratedRecHitCollection_ = consumes<EcalUncalibratedRecHitCollection>(ps.getParameter<edm::InputTag>("EcalUncalibratedRecHitCollection"));
38  EcalRecHitCollection_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("EcalRecHitCollection"));
39 
40  threshold_ = 0.12500; // typical muon energy deposit is 250 MeV
41 
42  minJitter_ = -2.0;
43  maxJitter_ = 1.5;
44 
45  for (int i = 0; i < 36; i++) {
46  meSelMap_[i] = 0;
47  meSpectrum_[0][i] = 0;
48  meSpectrum_[1][i] = 0;
49  }
50 
51 }
52 
54 
55 }
56 
58 
59  ievt_ = 0;
60 
61  if ( dqmStore_ ) {
62  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
63  dqmStore_->rmdir(prefixME_ + "/EBCosmicTask");
64  }
65 
66 }
67 
69 
70  Numbers::initGeometry(c, false);
71 
72  if ( ! mergeRuns_ ) this->reset();
73 
74 }
75 
77 
78 }
79 
80 void EBCosmicTask::reset(void) {
81 
82  for (int i = 0; i < 36; i++) {
83  if ( meSelMap_[i] ) meSelMap_[i]->Reset();
84  if ( meSpectrum_[0][i] ) meSpectrum_[0][i]->Reset();
85  if ( meSpectrum_[1][i] ) meSpectrum_[1][i]->Reset();
86  }
87 
88 }
89 
91 
92  init_ = true;
93 
95 
96  if ( dqmStore_ ) {
97  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
98 
99  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Sel");
100  for (int i = 0; i < 36; i++) {
101  name = "EBCT energy sel " + Numbers::sEB(i+1);
102  meSelMap_[i] = dqmStore_->bookProfile2D(name, name, 85, 0., 85., 20, 0., 20., 4096, 0., 4096., "s");
103  meSelMap_[i]->setAxisTitle("ieta", 1);
104  meSelMap_[i]->setAxisTitle("iphi", 2);
105  meSelMap_[i]->setAxisTitle("energy (GeV)", 3);
106  }
107 
108  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Spectrum");
109  for (int i = 0; i < 36; i++) {
110  name = "EBCT 1x1 energy spectrum " + Numbers::sEB(i+1);
111  meSpectrum_[0][i] = dqmStore_->book1D(name, name, 100, 0., 1.5);
112  meSpectrum_[0][i]->setAxisTitle("energy (GeV)", 1);
113  name = "EBCT 3x3 energy spectrum " + Numbers::sEB(i+1);
114  meSpectrum_[1][i] = dqmStore_->book1D(name, name, 100, 0., 1.5);
115  meSpectrum_[1][i]->setAxisTitle("energy (GeV)", 1);
116  }
117 
118  }
119 
120 }
121 
123 
124  if ( ! init_ ) return;
125 
126  if ( dqmStore_ ) {
127  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask");
128 
129  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Cut");
130  for (int i = 0; i < 36; i++) {
131  if ( meCutMap_[i] ) dqmStore_->removeElement( meCutMap_[i]->getName() );
132  meCutMap_[i] = 0;
133  }
134 
135  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Sel");
136  for (int i = 0; i < 36; i++) {
137  if ( meSelMap_[i] ) dqmStore_->removeElement( meSelMap_[i]->getName() );
138  meSelMap_[i] = 0;
139  }
140 
141  dqmStore_->setCurrentFolder(prefixME_ + "/EBCosmicTask/Spectrum");
142  for (int i = 0; i < 36; i++) {
143  if ( meSpectrum_[0][i] ) dqmStore_->removeElement( meSpectrum_[0][i]->getName() );
144  meSpectrum_[0][i] = 0;
145  if ( meSpectrum_[1][i] ) dqmStore_->removeElement( meSpectrum_[1][i]->getName() );
146  meSpectrum_[1][i] = 0;
147  }
148 
149  }
150 
151  init_ = false;
152 
153 }
154 
156 
157  edm::LogInfo("EBCosmicTask") << "analyzed " << ievt_ << " events";
158 
159  if ( enableCleanup_ ) this->cleanup();
160 
161 }
162 
164 
165  bool isData = true;
166  bool enable = false;
167  int runType[36];
168  for (int i=0; i<36; i++) runType[i] = -1;
169 
171 
172  if ( e.getByToken(EcalRawDataCollection_, dcchs) ) {
173 
174  for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
175 
176  if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
177 
178  int ism = Numbers::iSM( *dcchItr, EcalBarrel );
179 
180  runType[ism-1] = dcchItr->getRunType();
181 
182  if ( dcchItr->getRunType() == EcalDCCHeaderBlock::COSMIC ||
183  dcchItr->getRunType() == EcalDCCHeaderBlock::MTCC ||
184  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
185  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
186  dcchItr->getRunType() == EcalDCCHeaderBlock::COSMICS_LOCAL ||
187  dcchItr->getRunType() == EcalDCCHeaderBlock::PHYSICS_LOCAL ) enable = true;
188 
189  }
190 
191  } else {
192 
193  isData = false; enable = true;
194  edm::LogWarning("EBCosmicTask") << "EcalRawDataCollection not available";
195 
196  }
197 
198  if ( ! enable ) return;
199 
200  if ( ! init_ ) this->setup();
201 
202  ievt_++;
203 
205 
206  if ( e.getByToken(EcalRecHitCollection_, hits) ) {
207 
208  int nebh = hits->size();
209  LogDebug("EBCosmicTask") << "event " << ievt_ << " hits collection size " << nebh;
210 
212 
213  if ( ! e.getByToken(EcalUncalibratedRecHitCollection_, uhits) ) {
214  edm::LogWarning("EBCosmicTask") << "EcalUncalibratedRecHitCollection not available";
215  }
216 
217  for ( EcalRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
218 
219  EBDetId id = hitItr->id();
220 
221  int ic = id.ic();
222  int ie = (ic-1)/20 + 1;
223  int ip = (ic-1)%20 + 1;
224 
225  int ism = Numbers::iSM( id );
226 
227  float xie = ie - 0.5;
228  float xip = ip - 0.5;
229 
230  if ( isData ) {
231 
232  if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::COSMIC ||
233  runType[ism-1] == EcalDCCHeaderBlock::MTCC ||
234  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_GLOBAL ||
235  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_GLOBAL ||
236  runType[ism-1] == EcalDCCHeaderBlock::COSMICS_LOCAL ||
237  runType[ism-1] == EcalDCCHeaderBlock::PHYSICS_LOCAL ) ) continue;
238 
239  }
240 
241  float xval = hitItr->energy();
242  if ( xval <= 0. ) xval = 0.0;
243 
244  // look for the seeds
245  float e3x3 = 0.;
246  bool isSeed = true;
247 
248  // evaluate 3x3 matrix around a seed
249  for(int icry=0; icry<9; ++icry) {
250  unsigned int row = icry/3;
251  unsigned int column = icry%3;
252  int icryEta = id.ieta()+column-1;
253  int icryPhi = id.iphi()+row-1;
254  if ( EBDetId::validDetId(icryEta, icryPhi) ) {
255  EBDetId id3x3 = EBDetId(icryEta, icryPhi, EBDetId::ETAPHIMODE);
256  if ( hits->find(id3x3) != hits->end() ) {
257  float neighbourEnergy = hits->find(id3x3)->energy();
258  e3x3 += neighbourEnergy;
259  if ( neighbourEnergy > xval ) isSeed = false;
260  }
261  }
262  }
263 
264  // find the jitter of the seed
265  float jitter = -999.;
266  if ( isSeed ) {
267  if ( uhits.isValid() ) {
268  if ( uhits->find(id) != uhits->end() ) {
269  jitter = uhits->find(id)->jitter();
270  }
271  }
272  }
273 
274  if ( isSeed && e3x3 >= threshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
275  if ( meSelMap_[ism-1] ) meSelMap_[ism-1]->Fill(xie, xip, e3x3);
276  }
277 
278  if ( meSpectrum_[0][ism-1] ) meSpectrum_[0][ism-1]->Fill(xval);
279 
280  if ( isSeed && xval >= threshold_ && jitter > minJitter_ && jitter < maxJitter_ ) {
281  if ( meSpectrum_[1][ism-1] ) meSpectrum_[1][ism-1]->Fill(e3x3);
282  }
283 
284  }
285 
286  } else {
287 
288  edm::LogWarning("EBCosmicTask") << "EcalRecHitCollection not available";
289 
290  }
291 
292 }
293 
#define LogDebug(id)
edm::EDGetTokenT< EcalUncalibratedRecHitCollection > EcalUncalibratedRecHitCollection_
Definition: EBCosmicTask.h:71
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2730
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
Some &quot;id&quot; conversions.
std::string prefixME_
Definition: EBCosmicTask.h:64
static std::string sEB(const unsigned ism)
Definition: Numbers.cc:91
std::vector< EcalDCCHeaderBlock >::const_iterator const_iterator
void setup(void)
Setup.
Definition: EBCosmicTask.cc:90
double threshold_
Definition: EBCosmicTask.h:80
double minJitter_
Definition: EBCosmicTask.h:81
DQMStore * dqmStore_
Definition: EBCosmicTask.h:62
void cleanup(void)
Cleanup.
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:124
void Fill(long long x)
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
Definition: EBCosmicTask.cc:76
void beginJob(void)
BeginJob.
Definition: EBCosmicTask.cc:57
edm::EDGetTokenT< EcalRecHitCollection > EcalRecHitCollection_
Definition: EBCosmicTask.h:72
void removeElement(const std::string &name)
Definition: DQMStore.cc:2772
EBCosmicTask(const edm::ParameterSet &ps)
Constructor.
Definition: EBCosmicTask.cc:24
edm::EDGetTokenT< EcalRawDataCollection > EcalRawDataCollection_
Definition: EBCosmicTask.h:70
void reset(void)
Reset.
Definition: EBCosmicTask.cc:80
MonitorElement * meSelMap_[36]
Definition: EBCosmicTask.h:76
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
MonitorElement * meCutMap_[36]
Definition: EBCosmicTask.h:74
bool isValid() const
Definition: HandleBase.h:76
static const int ETAPHIMODE
Definition: EBDetId.h:166
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
void endJob(void)
EndJob.
static void initGeometry(const edm::EventSetup &setup, bool verbose=false)
Definition: Numbers.cc:47
#define column(...)
Definition: DbCore.h:74
MonitorElement * meSpectrum_[2][36]
Definition: EBCosmicTask.h:78
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
Definition: EBCosmicTask.cc:68
bool enableCleanup_
Definition: EBCosmicTask.h:66
static unsigned iSM(const unsigned ism, const EcalSubdetector subdet)
Definition: Numbers.cc:243
static EcalSubdetector subDet(const EBDetId &id)
Definition: Numbers.cc:142
double maxJitter_
Definition: EBCosmicTask.h:82
virtual ~EBCosmicTask()
Destructor.
Definition: EBCosmicTask.cc:53
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:56
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
Definition: Run.h:41
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1330